svelte-json-schema-form 0.0.1-alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/.storybook/main.ts +19 -0
  2. package/.storybook/preview.ts +15 -0
  3. package/.vscode/extensions.json +3 -0
  4. package/LICENSE +21 -0
  5. package/README.md +47 -0
  6. package/package.json +36 -0
  7. package/src/Form.stories.svelte +274 -0
  8. package/src/Form.svelte +121 -0
  9. package/src/components/FormActionButton.svelte +22 -0
  10. package/src/components/FormArrayInput.svelte +92 -0
  11. package/src/components/FormCheckboxInput.svelte +7 -0
  12. package/src/components/FormInputWrapper.svelte +85 -0
  13. package/src/components/FormObjectInput.svelte +22 -0
  14. package/src/components/FormTextInput.svelte +14 -0
  15. package/src/exports.js +21 -0
  16. package/src/formContext.js +3 -0
  17. package/src/formDefaultComponents.js +15 -0
  18. package/src/utils/svelteObjectStore.js +34 -0
  19. package/storybook-static/assets/Color-6VNJS4EI-BwbyGRpv.js +1 -0
  20. package/storybook-static/assets/DocsRenderer-NNNQARDV-Dv5gTx4J.js +401 -0
  21. package/storybook-static/assets/Form.stories-B9d26ABq.js +1 -0
  22. package/storybook-static/assets/Hello.stories-iStloLVx.js +1 -0
  23. package/storybook-static/assets/WithTooltip-V3YHNWJZ-Cu4QOpJO.js +1 -0
  24. package/storybook-static/assets/_commonjsHelpers-Cpj98o6Y.js +1 -0
  25. package/storybook-static/assets/collect-stories-C_xzNuNF.js +1 -0
  26. package/storybook-static/assets/entry-preview-ayMb_JX6.js +5 -0
  27. package/storybook-static/assets/entry-preview-docs-Dn-BUk6f.js +7 -0
  28. package/storybook-static/assets/formatter-SWP5E3XI-BDUqP36L.js +156 -0
  29. package/storybook-static/assets/iframe-COBy1vQP.js +7 -0
  30. package/storybook-static/assets/index-Bdfa_YSh.js +1 -0
  31. package/storybook-static/assets/index-Bw8VTzHM.js +1 -0
  32. package/storybook-static/assets/index-C0DyA3Eb.js +3 -0
  33. package/storybook-static/assets/index-Da9FSDFk.js +1 -0
  34. package/storybook-static/assets/index-DrFu-skq.js +6 -0
  35. package/storybook-static/assets/preview-9J5W8ogQ.js +7 -0
  36. package/storybook-static/assets/preview-BAz7FMXc.js +396 -0
  37. package/storybook-static/assets/preview-BCp7Wgbt.js +27 -0
  38. package/storybook-static/assets/preview-B_0crF9I.js +1 -0
  39. package/storybook-static/assets/preview-BcxrGG1y.js +20 -0
  40. package/storybook-static/assets/preview-CIwosuWp.js +1 -0
  41. package/storybook-static/assets/preview-Cv3rAi2i.js +7 -0
  42. package/storybook-static/assets/preview-D8VCGkL0.js +17 -0
  43. package/storybook-static/assets/preview-Db4Idchh.js +1 -0
  44. package/storybook-static/assets/syntaxhighlighter-B5GMVT5T-CFyDre8b.js +1 -0
  45. package/storybook-static/favicon.svg +7 -0
  46. package/storybook-static/iframe.html +458 -0
  47. package/storybook-static/index.html +135 -0
  48. package/storybook-static/index.json +1 -0
  49. package/storybook-static/project.json +1 -0
  50. package/storybook-static/sb-addons/essentials-actions-2/manager-bundle.js +3 -0
  51. package/storybook-static/sb-addons/essentials-actions-2/manager-bundle.js.LEGAL.txt +0 -0
  52. package/storybook-static/sb-addons/essentials-backgrounds-3/manager-bundle.js +12 -0
  53. package/storybook-static/sb-addons/essentials-backgrounds-3/manager-bundle.js.LEGAL.txt +0 -0
  54. package/storybook-static/sb-addons/essentials-controls-1/manager-bundle.js +63 -0
  55. package/storybook-static/sb-addons/essentials-controls-1/manager-bundle.js.LEGAL.txt +18 -0
  56. package/storybook-static/sb-addons/essentials-measure-6/manager-bundle.js +3 -0
  57. package/storybook-static/sb-addons/essentials-measure-6/manager-bundle.js.LEGAL.txt +0 -0
  58. package/storybook-static/sb-addons/essentials-outline-7/manager-bundle.js +3 -0
  59. package/storybook-static/sb-addons/essentials-outline-7/manager-bundle.js.LEGAL.txt +0 -0
  60. package/storybook-static/sb-addons/essentials-toolbars-5/manager-bundle.js +3 -0
  61. package/storybook-static/sb-addons/essentials-toolbars-5/manager-bundle.js.LEGAL.txt +0 -0
  62. package/storybook-static/sb-addons/essentials-viewport-4/manager-bundle.js +3 -0
  63. package/storybook-static/sb-addons/essentials-viewport-4/manager-bundle.js.LEGAL.txt +0 -0
  64. package/storybook-static/sb-addons/interactions-8/manager-bundle.js +12 -0
  65. package/storybook-static/sb-addons/interactions-8/manager-bundle.js.LEGAL.txt +0 -0
  66. package/storybook-static/sb-addons/links-0/manager-bundle.js +3 -0
  67. package/storybook-static/sb-addons/links-0/manager-bundle.js.LEGAL.txt +0 -0
  68. package/storybook-static/sb-addons/svelte-csf-preset-10/manager-bundle.js +3 -0
  69. package/storybook-static/sb-addons/svelte-csf-preset-10/manager-bundle.js.LEGAL.txt +0 -0
  70. package/storybook-static/sb-addons/svelte-csf-preset-9/manager-bundle.js +3 -0
  71. package/storybook-static/sb-addons/svelte-csf-preset-9/manager-bundle.js.LEGAL.txt +0 -0
  72. package/storybook-static/sb-common-assets/fonts.css +31 -0
  73. package/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
  74. package/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
  75. package/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
  76. package/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
  77. package/storybook-static/sb-manager/WithTooltip-V3YHNWJZ-TRLNWEGW.js +1 -0
  78. package/storybook-static/sb-manager/chunk-4IYAVH3S.js +348 -0
  79. package/storybook-static/sb-manager/chunk-CXYKRFSY.js +9 -0
  80. package/storybook-static/sb-manager/chunk-LVLAH4SI.js +7 -0
  81. package/storybook-static/sb-manager/chunk-VFHDXWEA.js +406 -0
  82. package/storybook-static/sb-manager/chunk-ZEU7PDD3.js +1 -0
  83. package/storybook-static/sb-manager/formatter-SWP5E3XI-7BGIK6BL.js +156 -0
  84. package/storybook-static/sb-manager/globals-module-info.js +1 -0
  85. package/storybook-static/sb-manager/globals.js +1 -0
  86. package/storybook-static/sb-manager/index.js +1 -0
  87. package/storybook-static/sb-manager/runtime.js +1 -0
  88. package/storybook-static/sb-manager/syntaxhighlighter-B5GMVT5T-EA5ASEYD.js +1 -0
  89. package/storybook-static/sb-preview/globals.js +1 -0
  90. package/storybook-static/sb-preview/runtime.js +112 -0
  91. package/storybook-static/stories.json +1 -0
  92. package/svelte.config.js +7 -0
  93. package/tsconfig.json +20 -0
  94. package/tsconfig.node.json +10 -0
  95. package/vite.config.ts +14 -0
@@ -0,0 +1,19 @@
1
+ import type { StorybookConfig } from "@storybook/svelte-vite";
2
+
3
+ const config: StorybookConfig = {
4
+ stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx|svelte)"],
5
+ addons: [
6
+ "@storybook/addon-links",
7
+ "@storybook/addon-essentials",
8
+ "@storybook/addon-interactions",
9
+ "@storybook/addon-svelte-csf"
10
+ ],
11
+ framework: {
12
+ name: "@storybook/svelte-vite",
13
+ options: {},
14
+ },
15
+ docs: {
16
+ autodocs: "tag",
17
+ },
18
+ };
19
+ export default config;
@@ -0,0 +1,15 @@
1
+ import type { Preview } from "@storybook/svelte";
2
+
3
+ const preview: Preview = {
4
+ parameters: {
5
+ actions: { argTypesRegex: "^on[A-Z].*" },
6
+ controls: {
7
+ matchers: {
8
+ color: /(background|color)$/i,
9
+ date: /Date$/i,
10
+ },
11
+ },
12
+ },
13
+ };
14
+
15
+ export default preview;
@@ -0,0 +1,3 @@
1
+ {
2
+ "recommendations": ["svelte.svelte-vscode"]
3
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 John Murphy-Teixidor
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Svelte + TS + Vite
2
+
3
+ This template should help get you started developing with Svelte and TypeScript in Vite.
4
+
5
+ ## Recommended IDE Setup
6
+
7
+ [VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
8
+
9
+ ## Need an official Svelte framework?
10
+
11
+ Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more.
12
+
13
+ ## Technical considerations
14
+
15
+ **Why use this over SvelteKit?**
16
+
17
+ - It brings its own routing solution which might not be preferable for some users.
18
+ - It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app.
19
+
20
+ This template contains as little as possible to get started with Vite + TypeScript + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project.
21
+
22
+ Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate.
23
+
24
+ **Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?**
25
+
26
+ Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information.
27
+
28
+ **Why include `.vscode/extensions.json`?**
29
+
30
+ Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project.
31
+
32
+ **Why enable `allowJs` in the TS template?**
33
+
34
+ While `allowJs: false` would indeed prevent the use of `.js` files in the project, it does not prevent the use of JavaScript syntax in `.svelte` files. In addition, it would force `checkJs: false`, bringing the worst of both worlds: not being able to guarantee the entire codebase is TypeScript, and also having worse typechecking for the existing JavaScript. In addition, there are valid use cases in which a mixed codebase may be relevant.
35
+
36
+ **Why is HMR not preserving my local component state?**
37
+
38
+ HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/rixo/svelte-hmr#svelte-hmr).
39
+
40
+ If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
41
+
42
+ ```ts
43
+ // store.ts
44
+ // An extremely simple external store
45
+ import { writable } from 'svelte/store'
46
+ export default writable(0)
47
+ ```
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "svelte-json-schema-form",
3
+ "private": false,
4
+ "version": "0.0.1-alpha1",
5
+ "type": "module",
6
+ "scripts": {
7
+ "check": "svelte-check --tsconfig ./tsconfig.json",
8
+ "storybook": "storybook dev -p 6006",
9
+ "build-storybook": "storybook build"
10
+ },
11
+ "main": "./src/exports.js",
12
+ "devDependencies": {
13
+ "@storybook/addon-essentials": "^7.6.16",
14
+ "@storybook/addon-interactions": "^7.6.16",
15
+ "@storybook/addon-links": "^7.6.16",
16
+ "@storybook/addon-svelte-csf": "^4.1.1",
17
+ "@storybook/blocks": "^7.6.16",
18
+ "@storybook/svelte": "^7.6.16",
19
+ "@storybook/svelte-vite": "^7.6.16",
20
+ "@storybook/test": "^7.6.16",
21
+ "@sveltejs/vite-plugin-svelte": "^3.0.2",
22
+ "@tsconfig/svelte": "^5.0.2",
23
+ "react": "^18.2.0",
24
+ "react-dom": "^18.2.0",
25
+ "storybook": "^7.6.16",
26
+ "svelte": "^4.2.10",
27
+ "svelte-check": "^3.6.3",
28
+ "tslib": "^2.6.2",
29
+ "typescript": "^5.2.2",
30
+ "unplugin-icons": "^0.18.5",
31
+ "vite": "^5.1.0"
32
+ },
33
+ "dependencies": {
34
+ "json-form-core": "0.0.1-alpha1"
35
+ }
36
+ }
@@ -0,0 +1,274 @@
1
+ <script context="module">
2
+ import {
3
+ Template,
4
+ Story
5
+ } from "@storybook/addon-svelte-csf";
6
+
7
+ import {
8
+ Form
9
+ } from "./exports.js";
10
+
11
+ export const meta = {
12
+ title: "JSONSchemaForm/Form",
13
+ component: Form,
14
+ argTypes: {
15
+ store: {
16
+ control: {
17
+ type: "object"
18
+ },
19
+ defaultValue: {
20
+ value: undefined
21
+ }
22
+ },
23
+ schema: {
24
+ control: {
25
+ type: "object"
26
+ },
27
+ defaultValue: {
28
+ value: {}
29
+ }
30
+ },
31
+ value: {
32
+ control: {
33
+ type: "object"
34
+ },
35
+ defaultValue: {
36
+ value: undefined
37
+ }
38
+ },
39
+ extras: {
40
+ control: {
41
+ type: "object"
42
+ },
43
+ defaultValue: {
44
+ value: {}
45
+ }
46
+ }
47
+ }
48
+ }
49
+ </script>
50
+
51
+ <!-- More on component templates: https://storybook.js.org/docs/svelte/writing-stories/introduction#using-args -->
52
+ <Template let:args>
53
+ <Form {...args} />
54
+ </Template>
55
+
56
+ <!-- More on args: https://storybook.js.org/docs/svelte/writing-stories/args-->
57
+ <Story
58
+ name="Primary"
59
+ args={{
60
+ "schema": {
61
+ "title": "Element",
62
+ "component": "objectInput",
63
+ "properties": {
64
+ "data": {
65
+ "title": "Data",
66
+ "component": "objectInput",
67
+ "properties": {
68
+ "title": {
69
+ "title": "Title",
70
+ "component": "textInput"
71
+ },
72
+ "url": {
73
+ "title": "Image URL",
74
+ "component": "textInput"
75
+ }
76
+ }
77
+ },
78
+ "visual": {
79
+ "title": "Visual",
80
+ "component": "arrayInput",
81
+ "options": {
82
+ "clone": true
83
+ },
84
+ "items": {
85
+ "title": "Data",
86
+ "component": "objectInput",
87
+ "properties": {
88
+ "f1": {
89
+ "title": "Array Obj Field 1",
90
+ "component": "textInput"
91
+ },
92
+ "f2": {
93
+ "title": "Array Obj Field 2",
94
+ "component": "textInput"
95
+ }
96
+ }
97
+ }
98
+ }
99
+ }
100
+ },
101
+ "value": {
102
+ "visual":[
103
+ {
104
+ "f2": "copied into the next item",
105
+ "f1": "this field will be"
106
+ }
107
+ ],
108
+ "data": {
109
+ "url": "xxxxxx"
110
+ }
111
+ },
112
+ "extras": {
113
+ "_extras": {},
114
+ "_children": {
115
+ "visual": {
116
+ "_extras": {},
117
+ "_children": [
118
+ {
119
+ "_children": {
120
+ "f1": {
121
+ "_extras": {"key": "val"}
122
+ }
123
+ }
124
+ }
125
+ ]
126
+ },
127
+ "data": {
128
+ "_extras": {},
129
+ "_children": {
130
+ "url": {
131
+ "_extras": {"key": "val"}
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }}
138
+ />
139
+
140
+ <Story
141
+ name="Biz Grid"
142
+ args={{
143
+ "schema": {
144
+ "component": "objectInput",
145
+ "properties": {
146
+ "visual": {
147
+ "title": "Visual",
148
+ "component": "objectInput",
149
+ "properties": {
150
+ "theme": {
151
+ "title": "Theme",
152
+ "component": "textInput"
153
+ },
154
+ "size": {
155
+ "title": "Size",
156
+ "component": "textInput"
157
+ }
158
+ }
159
+ },
160
+ "data": {
161
+ "title": "Visual",
162
+ "component": "arrayInput",
163
+ "options": {
164
+ "clone": true
165
+ },
166
+ "items": {
167
+ "title": "Data",
168
+ "component": "objectInput",
169
+ "properties": {
170
+ "automatic": {
171
+ "title": "Automatic data?",
172
+ "component": "booleanInput"
173
+ },
174
+ "symbol": {
175
+ "title": "Symbol",
176
+ "component": "textInput"
177
+ },
178
+ "name": {
179
+ "title": "Name (override)",
180
+ "component": "textInput"
181
+ },
182
+ "value": {
183
+ "title": "Value (override)",
184
+ "component": "textInput"
185
+ },
186
+ "net_change": {
187
+ "title": "Net change (override)",
188
+ "component": "textInput"
189
+ },
190
+ "pct_change": {
191
+ "title": "Percent change (override)",
192
+ "component": "textInput"
193
+ },
194
+ "color": {
195
+ "title": "Color (override)",
196
+ "component": "textInput"
197
+ }
198
+ }
199
+ }
200
+ },
201
+
202
+ }
203
+ },
204
+ "value": {
205
+ "visual": {
206
+ "theme": "cnni_quest_means_business_2018",
207
+ "size": "fullscreen"
208
+ }
209
+ ,
210
+ "data": [
211
+ {
212
+ "automatic": true,
213
+ "symbol": "BTCUSD",
214
+ "name": null
215
+ },
216
+ {
217
+ "automatic": true,
218
+ "symbol": "XRPUSD",
219
+ "name": null
220
+ }
221
+ ]
222
+ },
223
+ "extras": {
224
+
225
+ }
226
+ }}
227
+ />
228
+
229
+ <Story
230
+ name="Simple Object"
231
+ args={{
232
+ "schema": {
233
+ "title": "Data",
234
+ "component": "objectInput",
235
+ "properties": {
236
+ "title": {
237
+ "title": "Title",
238
+ "component": "textInput"
239
+ },
240
+ "url": {
241
+ "title": "Image URL",
242
+ "component": "textInput"
243
+ }
244
+ }
245
+ },
246
+ "value": {
247
+ "url": "URL goes here"
248
+ }
249
+ }}
250
+ />
251
+
252
+ <Story
253
+ name="Scalar Value"
254
+ args={{
255
+ "schema": {
256
+ "title": "Title",
257
+ "component": "textInput"
258
+ },
259
+ "value": "URL goes here"
260
+ }}
261
+ />
262
+
263
+ <Story
264
+ name="Button"
265
+ args={{
266
+ "schema": {
267
+ "component": "actionButton",
268
+ "label": "Title",
269
+ "action": "alert",
270
+ "args": "xx"
271
+ },
272
+ "value": "URL goes here"
273
+ }}
274
+ />
@@ -0,0 +1,121 @@
1
+ <script>
2
+ import {
3
+ onMount,
4
+ setContext,
5
+ createEventDispatcher
6
+ } from "svelte";
7
+ import { FormController } from "json-form-core";
8
+ import defaultContext from "./formContext.js";
9
+ import defaultComponents from "./formDefaultComponents.js";
10
+
11
+ export let context = defaultContext;
12
+
13
+ export let logger = undefined; // fallback logger if one is not supplied
14
+
15
+ export let store = undefined; // if undefined, a new one will be created
16
+ export let schema = undefined; // will be applied in store, if not undefined
17
+ export let value = undefined; // will be applied in store, if not undefined
18
+ export let extras = undefined; // will be applied in store, if not undefined
19
+ export let fragments = undefined; // will be applied in store, if not undefined
20
+ export let loadFragments = undefined; // async getter to load fragment configs as they are found
21
+
22
+ export let paths = {};
23
+
24
+ $: {
25
+ console.log("PATHS!", paths);
26
+ }
27
+
28
+ export let components = {}; // svelte input components
29
+
30
+ // TODO set in store, not here
31
+
32
+ const dispatch = createEventDispatcher();
33
+
34
+ export const formController = new FormController({
35
+ store, // if no store is set, it will be created
36
+ schema, // if schema is set, it will be set in the store
37
+ value, // if value is set, it will be set in the store
38
+ extras, // if extras are set, they will be set in the store
39
+ loadFragments,
40
+ paths: paths,
41
+ components: {
42
+ ...defaultComponents,
43
+ ...components
44
+ }
45
+ });
46
+
47
+ // dispatch all events from form controller
48
+ formController.allOn((eventName, ...eventArgs) => {
49
+ dispatch('event', {
50
+ type: eventName,
51
+ args: eventArgs
52
+ });
53
+ });
54
+
55
+ // set components in store when they change
56
+ $: {
57
+ formController.store.set(['components'], {
58
+ ...defaultComponents,
59
+ ...components
60
+ });
61
+ }
62
+
63
+ $: if(logger) {
64
+ formController.logger = logger;
65
+ }
66
+
67
+ // TODO remove this
68
+ $: {
69
+ console.log("STORE VALUE!", JSON.stringify(value));
70
+ }
71
+
72
+ // svelte-compatible read-only store for components
73
+ const componentsStore = {
74
+ subscribe: (callback) => formController.subscribeComponents(callback)
75
+ };
76
+
77
+
78
+
79
+ setContext(context, formController); // make form controller available to all children
80
+
81
+ /*
82
+ // schema, fragments, value
83
+ // TODO subscribe to store as well to set value
84
+ // TODO can this be simpler?
85
+ $: { // values changed
86
+ console.log("SETTING VALUE");
87
+ store.set(['value'], value);
88
+ }
89
+
90
+ $: { // schema changed
91
+ console.log("SETTING SCHEMA");
92
+ store.set(['schema'], schema ?? {});
93
+ }
94
+
95
+ $: { // fragments changed
96
+ store.set(['fragments'], fragments ?? {});
97
+ }
98
+ */
99
+
100
+ onMount(() => {
101
+ console.log("MOUNT", formController);
102
+
103
+ const unsubscribeValue = formController.subscribeValue((storeValue) => {
104
+ console.log("STORE VALUE", storeValue)
105
+ value = storeValue;
106
+ });
107
+
108
+ return () => {
109
+ unsubscribeValue();
110
+ }
111
+ });
112
+
113
+
114
+ </script>
115
+
116
+ <svelte:component
117
+ this={$componentsStore.wrapper}
118
+ formController={formController}
119
+ schemaPathParts={[]}
120
+ valuePathParts={[]}
121
+ />
@@ -0,0 +1,22 @@
1
+ <script>
2
+ export let components;
3
+ export let formController;
4
+ export let formNode;
5
+ export let valuePathParts;
6
+ export let schemaPathParts;
7
+
8
+ export let schema;
9
+ export let value = {};
10
+ export let overrides;
11
+
12
+ const handleButtonClick = () => {
13
+ const emitEventType = typeof schema.emit === 'object'
14
+ ? schema.emit?.type
15
+ : schema.emit; // just the event name
16
+ const emitEventArgs = schema.emit?.args ?? [];
17
+
18
+ formNode.emit(emitEventType, ...emitEventArgs);
19
+ }
20
+ </script>
21
+
22
+ <button on:click={handleButtonClick}>{schema?.label ?? ""}</button>
@@ -0,0 +1,92 @@
1
+ <script>
2
+ export let components;
3
+ export let formController; // TODO remove
4
+ export let formNode;
5
+ export let valuePathParts;
6
+ export let schemaPathParts;
7
+
8
+ export let schema; // form schema
9
+ export let value = []; // values of items in array
10
+ export let extras = undefined; // extras only for the array element
11
+
12
+ // extras tree for children of the array
13
+ $: extrasChildrenStore = {
14
+ subscribe: (callback) => formNode.subscribeExtrasChildren(callback),
15
+ set: (extras) => {
16
+ formNode.extrasChildren = extras;
17
+ }
18
+ }
19
+
20
+ const addItem = () => {
21
+ const newItemIndex = value.length;
22
+
23
+ if(schema.options?.clone && value.length > 0) {
24
+ const cloneItemIndex = value.length - 1;
25
+ const newItemValue = structuredClone(formController.pathGetValue([...valuePathParts, cloneItemIndex]));
26
+ const newItemExtrasTree = structuredClone(formController.pathGetExtrasTree([...valuePathParts, cloneItemIndex]));
27
+
28
+ spliceItems(newItemIndex, 0, {value: newItemValue, extrasTree: newItemExtrasTree});
29
+ }
30
+ else
31
+ spliceItems(newItemIndex, 0, {value: undefined, extrasTree: {}});
32
+ }
33
+
34
+ const deleteItem = (valueIndex) => {
35
+ spliceItems(valueIndex, 1);
36
+ }
37
+
38
+ const moveItem = (itemIndex, newItemIndex) => {
39
+ // remove item from array
40
+ const movedItems = spliceItems(itemIndex, 1); // returns array of removed items (array of 1 item to be moved)
41
+
42
+ // splice item back into array at new position
43
+ spliceItems(newItemIndex, 0, ...movedItems);
44
+ }
45
+
46
+ const spliceItems = (start, deleteCount, ...insertItems) => {
47
+ const values = formController.pathGetValue(valuePathParts) ?? [];
48
+ const extrasTreeChildren = formController.pathGetExtrasChildren(valuePathParts) ?? [];
49
+
50
+ const newValues = [...values];
51
+ const newExtrasTreeChildren = [...extrasTreeChildren];
52
+
53
+ // add values and extras trees
54
+ const removedValues = newValues.splice(start, deleteCount, ...(insertItems.map(insertItem => insertItem.value)));
55
+ const removedExtrasTrees = newExtrasTreeChildren.splice(start, deleteCount, ...(insertItems.map(insertItem => insertItem.extrasTree)));
56
+
57
+ formController.pathSetValue(valuePathParts, newValues);
58
+ formController.pathSetExtrasChildren(valuePathParts, newExtrasTreeChildren);
59
+
60
+ // return items removed in splice
61
+ return removedValues.map((value, index) => {
62
+ return {
63
+ value,
64
+ extrasTree: removedExtrasTrees[index]
65
+ }
66
+ });
67
+ }
68
+ </script>
69
+
70
+ <!-- TODO allow overriding path parts -->
71
+ {#if schema}
72
+ {#each value as itemValue, itemIndex (itemIndex)}
73
+ <svelte:component
74
+ this={components.wrapper}
75
+ value={value[itemIndex]}
76
+ formController={formController}
77
+ schemaPathParts={[...schemaPathParts, 'items']}
78
+ valuePathParts={[...valuePathParts, itemIndex]}
79
+ />
80
+ {#if itemIndex > 0}
81
+ <input type="button" on:click={() => moveItem(itemIndex, itemIndex-1)} value="Move Up" />
82
+ {/if}
83
+ {#if itemIndex < value.length - 1}
84
+ <input type="button" on:click={() => moveItem(itemIndex, itemIndex+1)} value="Move Down" />
85
+ {/if}
86
+ <input type="button" on:click={() => deleteItem(itemIndex)} value="Remove Item" />
87
+ {/each}
88
+
89
+ <hr />
90
+ <input type="button" on:click={addItem} value="Add Item" />
91
+ {/if}
92
+
@@ -0,0 +1,7 @@
1
+ <script>
2
+ export let value = undefined;
3
+ </script>
4
+
5
+ <div style="border: 1px solid #ff0000; padding: 5px;">
6
+ <input type="checkbox" bind:checked={value} />
7
+ </div>