├── .nvmrc ├── .npmrc ├── .prettierignore ├── .eslintignore ├── .gitignore ├── commitlint.config.js ├── postcss.config.js ├── public ├── favicon.png └── index.html ├── .prettierrc ├── src ├── main.js ├── components │ ├── components.module.js │ ├── Select.svelte │ ├── Input.svelte │ ├── Choice.svelte │ └── Form.svelte ├── utils.js └── App.svelte ├── CHANGELOG.md ├── svelte.config.js ├── tests ├── utils.js ├── Input │ ├── TestApp.svelte │ ├── __snapshots__ │ │ └── Input.spec.js.snap │ └── Input.spec.js └── Form │ ├── TestApp.svelte │ ├── __snapshots__ │ └── Form.spec.js.snap │ └── Form.spec.js ├── babel.config.js ├── jest.config.js ├── .eslintrc.js ├── .github ├── workflows │ ├── release.yml │ └── CI.yml └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── LICENSE ├── rollup.config.js ├── package.json └── README.md /.nvmrc: -------------------------------------------------------------------------------- 1 | lts/* 2 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | scripts-prepend-node-path=true 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | README.md 2 | coverage 3 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | public 2 | dist 3 | coverage 4 | node_modules 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | dist 3 | node_modules 4 | public/bundle.* 5 | coverage 6 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { extends: ['@commitlint/config-conventional'] }; 2 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [require('autoprefixer')], 3 | }; 4 | -------------------------------------------------------------------------------- /public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdauner/sveltejs-forms/HEAD/public/favicon.png -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "singleQuote": true 5 | } 6 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import App from './App.svelte'; 2 | 3 | const app = new App({ 4 | target: document.body, 5 | }); 6 | 7 | export default app; 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | The changelog is automatically updated using 4 | [semantic-release](https://github.com/semantic-release/semantic-release). You 5 | can see it on the [releases page](../../releases). 6 | -------------------------------------------------------------------------------- /svelte.config.js: -------------------------------------------------------------------------------- 1 | const autoPreprocess = require('svelte-preprocess'); 2 | 3 | module.exports = { 4 | preprocess: autoPreprocess({ 5 | postcss: true, 6 | scss: { includePaths: ['src', 'node_modules'] }, 7 | }), 8 | }; 9 | -------------------------------------------------------------------------------- /src/components/components.module.js: -------------------------------------------------------------------------------- 1 | export { default as Form } from './Form.svelte'; 2 | export { default as Input } from './Input.svelte'; 3 | export { default as Select } from './Select.svelte'; 4 | export { default as Choice } from './Choice.svelte'; 5 | -------------------------------------------------------------------------------- /tests/utils.js: -------------------------------------------------------------------------------- 1 | import { render, wait } from '@testing-library/svelte'; 2 | 3 | async function renderAndWait(component, options) { 4 | const renderedComponent = render(component, options); 5 | await wait(); 6 | return renderedComponent; 7 | } 8 | 9 | export { renderAndWait as render }; 10 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Svelte component 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | export function createObjectWithDefaultValue(defaultValue = '') { 2 | return new Proxy( 3 | {}, 4 | { 5 | get: function(object, property) { 6 | return Object.prototype.hasOwnProperty.call(object, property) 7 | ? object[property] 8 | : defaultValue; 9 | }, 10 | } 11 | ); 12 | } 13 | 14 | export function deepCopy(src) { 15 | return JSON.parse(JSON.stringify(src)); 16 | } 17 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | include: ['**/**/*.js', '**/**/*.mjs', '**/**/*.html', '**/**/*.svelte'], 3 | plugins: [ 4 | '@babel/plugin-syntax-dynamic-import', 5 | [ 6 | '@babel/plugin-transform-runtime', 7 | { 8 | useESModules: true, 9 | }, 10 | ], 11 | ], 12 | presets: [ 13 | [ 14 | '@babel/preset-env', 15 | { 16 | targets: { 17 | node: 'current', 18 | }, 19 | }, 20 | ], 21 | ], 22 | ignore: ['node_modules/(?!lodash-es)'], 23 | }; 24 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | transform: { 3 | '^.+\\.m?js$': 'babel-jest', 4 | "^.+\\.svelte$": ["svelte-jester", { "preprocess": true }] 5 | }, 6 | transformIgnorePatterns: [ 7 | '/node_modules/(?!(lodash-es|svelte-writable-derived)).+\\.m?js$', 8 | ], 9 | moduleFileExtensions: ['js', 'svelte', 'mjs'], 10 | roots: ['/tests'], 11 | bail: false, 12 | verbose: false, 13 | collectCoverage: true, 14 | collectCoverageFrom: ['src/components/**/*.{js,svelte}', 'src/utils.js'], 15 | setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'], 16 | }; 17 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | browser: true, 4 | node: true, 5 | es6: true, 6 | 'jest/globals': true, 7 | }, 8 | extends: ['eslint:recommended', 'plugin:jest/recommended', 'prettier'], 9 | overrides: [ 10 | { 11 | files: '*.svelte', 12 | processor: 'svelte3/svelte3', 13 | }, 14 | ], 15 | settings: { 16 | 'svelte3/ignore-styles': attributes => 17 | attributes.lang && attributes.lang.includes('scss'), 18 | }, 19 | rules: { 20 | 'jest/no-test-callback': 0 21 | }, 22 | parserOptions: { 23 | ecmaVersion: 2019, 24 | sourceType: 'module', 25 | }, 26 | plugins: ['svelte3', 'jest'], 27 | }; 28 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | release: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v1 14 | - name: Use Node.js 10.x 15 | uses: actions/setup-node@v1 16 | with: 17 | node-version: 10.x 18 | - name: yarn install, build, and release 19 | run: | 20 | yarn install 21 | yarn run build 22 | yarn run semantic-release 23 | env: 24 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 25 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 26 | GH_TOKEN: ${{ secrets.GH_TOKEN }} 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /tests/Input/TestApp.svelte: -------------------------------------------------------------------------------- 1 | 14 | 15 |
23 | 24 | 25 | 26 |
27 | -------------------------------------------------------------------------------- /.github/workflows/CI.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - master 7 | push: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v1 17 | - name: Use Node.js 10.x 18 | uses: actions/setup-node@v1 19 | with: 20 | node-version: 10.x 21 | - name: yarn install, build, and test 22 | run: | 23 | yarn install 24 | yarn run build 25 | yarn run lint 26 | yarn run prettier 27 | yarn run test 28 | 29 | - name: Codecov 30 | run: bash <(curl -s https://codecov.io/bash) -t $TOKEN -B $REF 31 | env: 32 | CI: true 33 | TOKEN: "${{ secrets.CODECOV_TOKEN }}" 34 | REF: "${{ github.ref }}" 35 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /tests/Form/TestApp.svelte: -------------------------------------------------------------------------------- 1 | 26 | 27 |
35 | 36 | 36 | 41 | {/each} 42 | 43 | {#if get($touched, name) && get($errors, name)} 44 |
{get($errors, name)}
45 | {/if} 46 | 47 | -------------------------------------------------------------------------------- /src/components/Input.svelte: -------------------------------------------------------------------------------- 1 | 25 | 26 |
27 | {#if label} 28 | 29 | {/if} 30 | {#if multiline} 31 |