@stubber/form-fields 1.0.0

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 (151) hide show
  1. package/README.md +303 -0
  2. package/dist/Field.svelte +36 -0
  3. package/dist/Field.svelte.d.ts +31 -0
  4. package/dist/Form.svelte +34 -0
  5. package/dist/Form.svelte.d.ts +29 -0
  6. package/dist/NullFieldWrapper.svelte +6 -0
  7. package/dist/NullFieldWrapper.svelte.d.ts +25 -0
  8. package/dist/fields/component_parts/arraybuilder/FieldWrapper.svelte +69 -0
  9. package/dist/fields/component_parts/arraybuilder/FieldWrapper.svelte.d.ts +29 -0
  10. package/dist/fields/component_parts/fieldbuilder/FieldWrapper.svelte +8 -0
  11. package/dist/fields/component_parts/fieldbuilder/FieldWrapper.svelte.d.ts +25 -0
  12. package/dist/fields/components/AgGrid.svelte +53 -0
  13. package/dist/fields/components/AgGrid.svelte.d.ts +18 -0
  14. package/dist/fields/components/Arraybuilder.svelte +101 -0
  15. package/dist/fields/components/Arraybuilder.svelte.d.ts +25 -0
  16. package/dist/fields/components/Checkbox.svelte +100 -0
  17. package/dist/fields/components/Checkbox.svelte.d.ts +23 -0
  18. package/dist/fields/components/CheckboxAutocomplete.svelte +92 -0
  19. package/dist/fields/components/CheckboxAutocomplete.svelte.d.ts +23 -0
  20. package/dist/fields/components/Contactselector.svelte +348 -0
  21. package/dist/fields/components/Contactselector.svelte.d.ts +25 -0
  22. package/dist/fields/components/Currency.svelte +258 -0
  23. package/dist/fields/components/Currency.svelte.d.ts +23 -0
  24. package/dist/fields/components/Dataindication.svelte +35 -0
  25. package/dist/fields/components/Dataindication.svelte.d.ts +23 -0
  26. package/dist/fields/components/Date.svelte +94 -0
  27. package/dist/fields/components/Date.svelte.d.ts +23 -0
  28. package/dist/fields/components/Datetime.svelte +94 -0
  29. package/dist/fields/components/Datetime.svelte.d.ts +23 -0
  30. package/dist/fields/components/Email.svelte +124 -0
  31. package/dist/fields/components/Email.svelte.d.ts +23 -0
  32. package/dist/fields/components/Fieldbuilder.svelte +340 -0
  33. package/dist/fields/components/Fieldbuilder.svelte.d.ts +25 -0
  34. package/dist/fields/components/Fieldsbuilder.svelte +122 -0
  35. package/dist/fields/components/Fieldsbuilder.svelte.d.ts +25 -0
  36. package/dist/fields/components/File.svelte +230 -0
  37. package/dist/fields/components/File.svelte.d.ts +25 -0
  38. package/dist/fields/components/Heading.svelte +17 -0
  39. package/dist/fields/components/Heading.svelte.d.ts +23 -0
  40. package/dist/fields/components/Hidden.svelte +7 -0
  41. package/dist/fields/components/Hidden.svelte.d.ts +23 -0
  42. package/dist/fields/components/Hiddenlocation.svelte +28 -0
  43. package/dist/fields/components/Hiddenlocation.svelte.d.ts +23 -0
  44. package/dist/fields/components/Html.svelte +13 -0
  45. package/dist/fields/components/Html.svelte.d.ts +23 -0
  46. package/dist/fields/components/Jsoneditor.svelte +94 -0
  47. package/dist/fields/components/Jsoneditor.svelte.d.ts +23 -0
  48. package/dist/fields/components/Map.svelte +192 -0
  49. package/dist/fields/components/Map.svelte.d.ts +25 -0
  50. package/dist/fields/components/Multicheckbox.svelte +119 -0
  51. package/dist/fields/components/Multicheckbox.svelte.d.ts +23 -0
  52. package/dist/fields/components/Multistep.svelte +86 -0
  53. package/dist/fields/components/Multistep.svelte.d.ts +25 -0
  54. package/dist/fields/components/Note.svelte +92 -0
  55. package/dist/fields/components/Note.svelte.d.ts +23 -0
  56. package/dist/fields/components/Number.svelte +118 -0
  57. package/dist/fields/components/Number.svelte.d.ts +23 -0
  58. package/dist/fields/components/Objectbuilder.svelte +152 -0
  59. package/dist/fields/components/Objectbuilder.svelte.d.ts +25 -0
  60. package/dist/fields/components/Qrcodescanner.svelte +198 -0
  61. package/dist/fields/components/Qrcodescanner.svelte.d.ts +23 -0
  62. package/dist/fields/components/Radio.svelte +116 -0
  63. package/dist/fields/components/Radio.svelte.d.ts +23 -0
  64. package/dist/fields/components/Renderfield.svelte +58 -0
  65. package/dist/fields/components/Renderfield.svelte.d.ts +25 -0
  66. package/dist/fields/components/Screenrecorder.svelte +277 -0
  67. package/dist/fields/components/Screenrecorder.svelte.d.ts +25 -0
  68. package/dist/fields/components/Screenshot.svelte +270 -0
  69. package/dist/fields/components/Screenshot.svelte.d.ts +25 -0
  70. package/dist/fields/components/Scrollandreaddisplay.svelte +122 -0
  71. package/dist/fields/components/Scrollandreaddisplay.svelte.d.ts +23 -0
  72. package/dist/fields/components/Section.svelte +64 -0
  73. package/dist/fields/components/Section.svelte.d.ts +25 -0
  74. package/dist/fields/components/Select.svelte +229 -0
  75. package/dist/fields/components/Select.svelte.d.ts +23 -0
  76. package/dist/fields/components/Selectresource.svelte +291 -0
  77. package/dist/fields/components/Selectresource.svelte.d.ts +25 -0
  78. package/dist/fields/components/Signature.svelte +153 -0
  79. package/dist/fields/components/Signature.svelte.d.ts +25 -0
  80. package/dist/fields/components/Slider.svelte +101 -0
  81. package/dist/fields/components/Slider.svelte.d.ts +23 -0
  82. package/dist/fields/components/SmartText.svelte +330 -0
  83. package/dist/fields/components/SmartText.svelte.d.ts +23 -0
  84. package/dist/fields/components/Telephone.svelte +153 -0
  85. package/dist/fields/components/Telephone.svelte.d.ts +23 -0
  86. package/dist/fields/components/Text.svelte +106 -0
  87. package/dist/fields/components/Text.svelte.d.ts +23 -0
  88. package/dist/fields/components/Voicenote.svelte +268 -0
  89. package/dist/fields/components/Voicenote.svelte.d.ts +25 -0
  90. package/dist/fields/components/index.d.ts +81 -0
  91. package/dist/fields/components/index.js +82 -0
  92. package/dist/fields/definitions/_all.json +38 -0
  93. package/dist/fields/definitions/_valid_fieldtype.json +220 -0
  94. package/dist/fields/definitions/arraybuilder.json +39 -0
  95. package/dist/fields/definitions/checkbox.json +44 -0
  96. package/dist/fields/definitions/contactselector.json +15 -0
  97. package/dist/fields/definitions/currency.json +42 -0
  98. package/dist/fields/definitions/dataindication.json +16 -0
  99. package/dist/fields/definitions/date.json +16 -0
  100. package/dist/fields/definitions/datetime.json +15 -0
  101. package/dist/fields/definitions/email.json +16 -0
  102. package/dist/fields/definitions/fieldbuilder.json +64 -0
  103. package/dist/fields/definitions/fieldsbuilder.json +38 -0
  104. package/dist/fields/definitions/file.json +42 -0
  105. package/dist/fields/definitions/grid.json +47 -0
  106. package/dist/fields/definitions/heading.json +38 -0
  107. package/dist/fields/definitions/hidden.json +89 -0
  108. package/dist/fields/definitions/hiddenlocation.json +15 -0
  109. package/dist/fields/definitions/html.json +34 -0
  110. package/dist/fields/definitions/index.d.ts +86 -0
  111. package/dist/fields/definitions/index.js +96 -0
  112. package/dist/fields/definitions/jsoneditor.json +33 -0
  113. package/dist/fields/definitions/map.json +36 -0
  114. package/dist/fields/definitions/multicheckbox.json +47 -0
  115. package/dist/fields/definitions/multistep.json +35 -0
  116. package/dist/fields/definitions/note.json +16 -0
  117. package/dist/fields/definitions/number.json +42 -0
  118. package/dist/fields/definitions/objectbuilder.json +39 -0
  119. package/dist/fields/definitions/qrcodescanner.json +16 -0
  120. package/dist/fields/definitions/radio.json +47 -0
  121. package/dist/fields/definitions/renderfield.json +36 -0
  122. package/dist/fields/definitions/richtext.json +16 -0
  123. package/dist/fields/definitions/screenrecorder.json +42 -0
  124. package/dist/fields/definitions/screenshot.json +42 -0
  125. package/dist/fields/definitions/scrollandreaddisplay.json +49 -0
  126. package/dist/fields/definitions/section.json +50 -0
  127. package/dist/fields/definitions/select.json +47 -0
  128. package/dist/fields/definitions/selectresource.json +48 -0
  129. package/dist/fields/definitions/signature.json +16 -0
  130. package/dist/fields/definitions/slider.json +78 -0
  131. package/dist/fields/definitions/smart_text.json +101 -0
  132. package/dist/fields/definitions/telephone.json +16 -0
  133. package/dist/fields/definitions/text.json +35 -0
  134. package/dist/fields/definitions/voicenote.json +43 -0
  135. package/dist/index.d.ts +2 -0
  136. package/dist/index.js +3 -0
  137. package/dist/thirdparty/mapbox/GeoCoder.svelte +10 -0
  138. package/dist/thirdparty/mapbox/GeoCoder.svelte.d.ts +25 -0
  139. package/dist/thirdparty/mapbox/Map.svelte +30 -0
  140. package/dist/thirdparty/mapbox/Map.svelte.d.ts +20 -0
  141. package/dist/thirdparty/mapbox/MapMarker.svelte +13 -0
  142. package/dist/thirdparty/mapbox/MapMarker.svelte.d.ts +31 -0
  143. package/dist/utils/createField.d.ts +6 -0
  144. package/dist/utils/createField.js +33 -0
  145. package/dist/utils/createForm.d.ts +1 -0
  146. package/dist/utils/createForm.js +501 -0
  147. package/dist/utils/index.d.ts +18 -0
  148. package/dist/utils/index.js +126 -0
  149. package/dist/utils/syncing.d.ts +11 -0
  150. package/dist/utils/syncing.js +134 -0
  151. package/package.json +78 -0
package/README.md ADDED
@@ -0,0 +1,303 @@
1
+ # stubber-form-fields-pkg
2
+
3
+ ## Quick start
4
+
5
+ Use this as a quick demo
6
+
7
+ ```
8
+ <script>
9
+ import { Form } from 'stubber-form-fields-pkg';
10
+
11
+ let initial_form = {
12
+ spec: {
13
+ fields: {
14
+ fullname: {
15
+ fieldtype: "text"
16
+ },
17
+ gender: {
18
+ fieldtype: "select",
19
+ params: {
20
+ options: [
21
+ {
22
+ label: "Male",
23
+ value: "male"
24
+ },
25
+ {
26
+ label: "Female",
27
+ value: "female"
28
+ }
29
+ ]
30
+ }
31
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ let form;
37
+
38
+ </script>
39
+
40
+ <Form
41
+ bind:form
42
+ {initial_form}
43
+ />
44
+ ```
45
+
46
+ ## Form
47
+
48
+ - Can render a list of fields
49
+ - All fields in a form have access to the state and data of other fields in the form
50
+ - `initial_form` can be passed as a prop to this component to initialize the stores with some data
51
+ - All props from this component are passed down to child components
52
+
53
+ ### props
54
+
55
+ #### initial_form
56
+
57
+ - Use to initialize the form
58
+
59
+ ```
60
+ {
61
+ "spec": {
62
+ "test": {
63
+ "fieldtype": "text"
64
+ }
65
+ },
66
+ "data": {
67
+ "test": "Hi there"
68
+ }
69
+ }
70
+ ```
71
+
72
+ #### form
73
+
74
+ - use this to bind to the internal store
75
+
76
+ #### field_wrapper
77
+
78
+ - Use to render fields differently
79
+ - Below is the default wrapper as a guideline
80
+
81
+ ```
82
+ <script>
83
+ // fieldWrapper
84
+ export let fieldcomponent;
85
+ </script>
86
+
87
+ <svelte:component this={fieldcomponent} {...$$props} />
88
+ ```
89
+
90
+ #### dependencies
91
+
92
+ - Many fields require extra dependencies that you can pass via this prop
93
+
94
+ ## Concepts
95
+
96
+ There are a few concepts to be aware of when using this library
97
+
98
+ ### Field definition
99
+
100
+ This is the JSON object, primarily as it comes from the template
101
+
102
+ #### common settings
103
+
104
+ - `name`
105
+ - always gets set to the key of the object and cannot be overwritten
106
+ - `fieldtype`
107
+ - sets the field component to render in the form
108
+ - default value is`'text'`
109
+ - `description`
110
+ - use to describe what the field is there for
111
+ - default value is`''`
112
+ - `title`
113
+ - use to set the label of the field
114
+ - default value is a human readable form of `[name]`
115
+ - `hide_label`
116
+ - set to `true` if you don't want the field to show a label
117
+ - default value is`false`
118
+ - `details.keyname`
119
+ - use to set where in `data` to write the field value to
120
+ - default value is `[name]`
121
+ - `details.datapath`
122
+ - use to nest the value deeper inside `data`
123
+ - default value is `''`
124
+ - `initvalue.default`
125
+ - use to set the value of the field if the field value is not yet set
126
+ - `initvalue.override`
127
+ - use to set the value of the field regardless of if the field value is set or not
128
+ - `conditions`
129
+ - use to conditionally render a field
130
+ - array of jsonata expressions that evaluate using the fieldContext
131
+ - default value is `[]`
132
+
133
+ ```
134
+ // example conditions
135
+ [
136
+ "form.data.gender = 'male'"
137
+ ]
138
+ ```
139
+
140
+ - `validations`
141
+ - use to ensure a valid field value
142
+ - default value is `{}`
143
+
144
+ ```
145
+ // example validations
146
+ {
147
+ "is_required_validation": {
148
+ "validationtype": "required",
149
+ "valid_message": "Looks good!",
150
+ "invalid_message": "This field is required"
151
+ },
152
+ "passes_regex_check": {
153
+ "validationtype": "regex",
154
+ "params": {
155
+ "regex": "regex here"
156
+ },
157
+ "invalid_message": "something is wrong"
158
+ },
159
+ "jsonata_check": {
160
+ "validationtype": "jsonata",
161
+ "params": {
162
+ "jsonata": "field.data = 5"
163
+ },
164
+ "invalid_message": "something is wrong"
165
+ }
166
+ }
167
+ ```
168
+
169
+ - `fields`
170
+ - Nest multiple fields under this field
171
+ - `params` is where any field-specific settings are set
172
+
173
+ ### fieldtypes
174
+
175
+ #### arraybuilder
176
+
177
+ - `params.new_entry_field`
178
+ - this is a fieldspec for how new entries are added to the array
179
+ - `details.keyname` and `details.datapath` don't function in the new_entry_field
180
+
181
+ #### checkbox
182
+
183
+ - `params.checkedvalue`
184
+ - this is the value that the field will be set to if the box is checked
185
+ - default value is `true`
186
+ - `params.uncheckedvalue`
187
+ - this is the value that the field will be set to if the box is not checked
188
+ - default value is `false`
189
+
190
+ #### currency
191
+
192
+ - `params.currency`
193
+ - set the currency of the field
194
+ - `params.currency_whitelist`
195
+ - set array of currencies that can be selected
196
+ - `params.currency_blacklist`
197
+ - set array of currencies that cannot be selected
198
+
199
+ #### dataindication
200
+
201
+ #### date
202
+
203
+ #### datetime
204
+
205
+ #### file
206
+
207
+ #### hidden
208
+
209
+ #### jsoneditor
210
+
211
+ - `params.readonly`
212
+ - Shows a non-editable jsoneditor
213
+
214
+ #### map
215
+
216
+ #### multistep
217
+
218
+ #### note
219
+
220
+ #### radio
221
+
222
+ - `params.options`
223
+ - set the options here
224
+
225
+ ```
226
+ [
227
+ {
228
+ "label": "Red"
229
+ },
230
+ {
231
+ "label": "Green",
232
+ "value": "green"
233
+ },
234
+ {
235
+ "label": "Blue",
236
+ "value": {
237
+ "hello": "world"
238
+ }
239
+ }
240
+ ]
241
+ ```
242
+
243
+ #### renderfield
244
+
245
+ - `params.dynamic_fieldspec`
246
+ - Set the fieldspec here with values as jsonata expressions
247
+
248
+ #### richtext
249
+
250
+ #### scrollandreaddisplay
251
+
252
+ - `params.displaytext`
253
+ - Set the text that should be displayed and scrolled through
254
+
255
+ #### section
256
+
257
+ #### select
258
+
259
+ - `params.options`
260
+ - set the select options here
261
+
262
+ ```
263
+ [
264
+ {
265
+ "label": "Red"
266
+ },
267
+ {
268
+ "label": "Green",
269
+ "value": "green"
270
+ },
271
+ {
272
+ "label": "Blue",
273
+ "value": {
274
+ "hello": "world"
275
+ }
276
+ }
277
+ ]
278
+ ```
279
+
280
+ #### signature
281
+
282
+ #### telephone
283
+
284
+ #### text
285
+
286
+ ### Dependencies
287
+
288
+ The dependencies prop is used by certain fields that only function with third party services. All the optional dependencies are listed below.
289
+
290
+ - `file.upload_url`
291
+ - Where files should be uploaded to (e.g. `/api/file-server/upload`)
292
+ - `map.mapboxAccessToken`
293
+ - Access token for mapbox account
294
+ - `map.mapboxStylesheetUrl`
295
+ - Stylesheet url for maps
296
+
297
+ # Publishing
298
+
299
+ - `npm version patch` to bump the version
300
+ - `git push origin master` to push the bumped version
301
+ - `npm run build` to build the package
302
+ - `npm run package` to package the package
303
+ - `npm publish` to publish the package
@@ -0,0 +1,36 @@
1
+ <script>
2
+ import { getContext, onDestroy, onMount } from "svelte";
3
+ import * as utils from "./utils/index.js";
4
+ import _ from "lodash-es";
5
+
6
+ export let form;
7
+ export let initial_field_spec = null;
8
+ export let parent_field = null;
9
+ export let field_wrapper = null;
10
+ export let field = null;
11
+
12
+ const default_field_wrapper = getContext("stubber-form-fields-default-wrapper");
13
+
14
+ let removeField;
15
+ onMount(() => {
16
+ let addResult = form.addField(initial_field_spec, $parent_field?.state?.state_key);
17
+ if (addResult?.state_key) field = utils.createField(addResult?.state_key, form);
18
+ if (addResult?.removeField) removeField = addResult?.removeField;
19
+ });
20
+
21
+ onDestroy(() => {
22
+ if (removeField) removeField();
23
+ });
24
+
25
+ // derive the field wrapper
26
+ $: FieldWrapper = field_wrapper || default_field_wrapper;
27
+
28
+ // get the right svelte component
29
+ $: fieldcomponent = utils.mapFieldToComponent($field?.spec);
30
+ </script>
31
+
32
+ {#if $field?.state?.conditions_passed}
33
+ <div class={$field?.state?.invisible ? "invisible absolute" : ""}>
34
+ <svelte:component this={FieldWrapper} {form} {field} {fieldcomponent} {parent_field} />
35
+ </div>
36
+ {/if}
@@ -0,0 +1,31 @@
1
+ /** @typedef {typeof __propDef.props} FieldProps */
2
+ /** @typedef {typeof __propDef.events} FieldEvents */
3
+ /** @typedef {typeof __propDef.slots} FieldSlots */
4
+ export default class Field extends SvelteComponentTyped<{
5
+ form: any;
6
+ field?: null | undefined;
7
+ parent_field?: null | undefined;
8
+ initial_field_spec?: null | undefined;
9
+ field_wrapper?: null | undefined;
10
+ }, {
11
+ [evt: string]: CustomEvent<any>;
12
+ }, {}> {
13
+ }
14
+ export type FieldProps = typeof __propDef.props;
15
+ export type FieldEvents = typeof __propDef.events;
16
+ export type FieldSlots = typeof __propDef.slots;
17
+ import { SvelteComponentTyped } from "svelte";
18
+ declare const __propDef: {
19
+ props: {
20
+ form: any;
21
+ field?: null | undefined;
22
+ parent_field?: null | undefined;
23
+ initial_field_spec?: null | undefined;
24
+ field_wrapper?: null | undefined;
25
+ };
26
+ events: {
27
+ [evt: string]: CustomEvent<any>;
28
+ };
29
+ slots: {};
30
+ };
31
+ export {};
@@ -0,0 +1,34 @@
1
+ <script>
2
+ import { setContext } from "svelte";
3
+ import * as utils from "./utils/index.js";
4
+ import _ from "lodash-es";
5
+ import Field from "./Field.svelte";
6
+ import NullFieldWrapper from "./NullFieldWrapper.svelte";
7
+ import { deepEqual } from "fast-equals";
8
+
9
+ export let initial_form = {};
10
+ export let form = null;
11
+ export let field_wrapper = null;
12
+ export let dependencies = null;
13
+
14
+ form = utils.createForm({ dependencies, form });
15
+ setContext("stubber-form-fields-default-wrapper", field_wrapper || NullFieldWrapper);
16
+
17
+ let debounceRenderForm = utils.debounce(renderForm, 50);
18
+ $: debounceRenderForm(initial_form);
19
+ function renderForm(v) {
20
+ if (!deepEqual($form?.initial_form, v)) form.initialize(v);
21
+ }
22
+
23
+ $: fields = utils.getFieldsToRender($form?.root_spec?.fields);
24
+ </script>
25
+
26
+ {#if $form?.render_index}
27
+ {#key $form?.render_index}
28
+ {#if fields}
29
+ {#each fields as initial_field_spec (initial_field_spec.__key)}
30
+ <Field {form} {initial_field_spec} />
31
+ {/each}
32
+ {/if}
33
+ {/key}
34
+ {/if}
@@ -0,0 +1,29 @@
1
+ /** @typedef {typeof __propDef.props} FormProps */
2
+ /** @typedef {typeof __propDef.events} FormEvents */
3
+ /** @typedef {typeof __propDef.slots} FormSlots */
4
+ export default class Form extends SvelteComponentTyped<{
5
+ form?: any;
6
+ field_wrapper?: null | undefined;
7
+ initial_form?: {} | undefined;
8
+ dependencies?: null | undefined;
9
+ }, {
10
+ [evt: string]: CustomEvent<any>;
11
+ }, {}> {
12
+ }
13
+ export type FormProps = typeof __propDef.props;
14
+ export type FormEvents = typeof __propDef.events;
15
+ export type FormSlots = typeof __propDef.slots;
16
+ import { SvelteComponentTyped } from "svelte";
17
+ declare const __propDef: {
18
+ props: {
19
+ form?: any;
20
+ field_wrapper?: null | undefined;
21
+ initial_form?: {} | undefined;
22
+ dependencies?: null | undefined;
23
+ };
24
+ events: {
25
+ [evt: string]: CustomEvent<any>;
26
+ };
27
+ slots: {};
28
+ };
29
+ export {};
@@ -0,0 +1,6 @@
1
+ <script>
2
+ // fieldWrapper
3
+ export let fieldcomponent;
4
+ </script>
5
+
6
+ <svelte:component this={fieldcomponent} {...$$props} />
@@ -0,0 +1,25 @@
1
+ /** @typedef {typeof __propDef.props} NullFieldWrapperProps */
2
+ /** @typedef {typeof __propDef.events} NullFieldWrapperEvents */
3
+ /** @typedef {typeof __propDef.slots} NullFieldWrapperSlots */
4
+ export default class NullFieldWrapper extends SvelteComponentTyped<{
5
+ [x: string]: any;
6
+ fieldcomponent: any;
7
+ }, {
8
+ [evt: string]: CustomEvent<any>;
9
+ }, {}> {
10
+ }
11
+ export type NullFieldWrapperProps = typeof __propDef.props;
12
+ export type NullFieldWrapperEvents = typeof __propDef.events;
13
+ export type NullFieldWrapperSlots = typeof __propDef.slots;
14
+ import { SvelteComponentTyped } from "svelte";
15
+ declare const __propDef: {
16
+ props: {
17
+ [x: string]: any;
18
+ fieldcomponent: any;
19
+ };
20
+ events: {
21
+ [evt: string]: CustomEvent<any>;
22
+ };
23
+ slots: {};
24
+ };
25
+ export {};
@@ -0,0 +1,69 @@
1
+ <script>
2
+ import _ from "lodash-es";
3
+
4
+ // fieldWrapper
5
+ export let field;
6
+ export let fieldcomponent;
7
+ export let parent_field;
8
+
9
+ function removeEntry() {
10
+ let field_index = parseInt($field.spec?.__key);
11
+ // update the parent field
12
+ let parent_data = _.cloneDeep($parent_field?.data?.base);
13
+ if (_.isArray(parent_data)) {
14
+ parent_data = parent_data.slice(0, field_index).concat(parent_data.slice(field_index + 1));
15
+ }
16
+
17
+ parent_field.update((p) => {
18
+ let cp = _.cloneDeep(p);
19
+ _.set(cp, "data.base", parent_data);
20
+ return cp;
21
+ });
22
+ }
23
+
24
+ function reorder(is_move_higher) {
25
+ let field_index = parseInt($field.spec?.__key);
26
+ let sibling_index = field_index + (is_move_higher ? 1 : -1);
27
+
28
+ if (sibling_index < 0 || sibling_index >= $parent_field?.data?.base?.length) return;
29
+
30
+ // update the parent field
31
+ let parent_data = _.cloneDeep($parent_field?.data?.base);
32
+ if (_.isArray(parent_data)) {
33
+ let temp = _.cloneDeep(parent_data[field_index]);
34
+ parent_data[field_index] = _.cloneDeep(parent_data[sibling_index]);
35
+ parent_data[sibling_index] = temp;
36
+ }
37
+
38
+ $parent_field.data.base = parent_data;
39
+ }
40
+ </script>
41
+
42
+ <div class="flex items-stretch pb-6">
43
+ <div class="relative flex-grow-0 mr-2">
44
+ <button
45
+ on:click={() => reorder(false)}
46
+ type="button"
47
+ class="flex items-center justify-center text-xl w-8 border border-dashed bg-surface-0 border-surface-300 hover:bg-surface-500 hover:text-surface-0 active:bg-surface-500 active:text-surface-0 active:border-0 rounded-t text-surface-500 h-1/2"
48
+ >
49
+ <i class="fa-regular fa-angle-up" />
50
+ </button>
51
+ <button
52
+ on:click={() => reorder(true)}
53
+ type="button"
54
+ class="flex items-center justify-center text-xl w-8 border border-t-0 border-dashed bg-surface-0 border-surface-300 hover:bg-surface-500 hover:text-surface-0 active:bg-surface-500 active:text-surface-0 active:border-0 rounded-b text-surface-500 h-1/2"
55
+ >
56
+ <i class="fa-regular fa-angle-down" />
57
+ </button>
58
+ </div>
59
+ <div class="flex-grow">
60
+ <svelte:component this={fieldcomponent} {...$$props} field_wrapper={null} />
61
+ </div>
62
+ <button
63
+ on:click={removeEntry}
64
+ type="button"
65
+ class="flex-grow-0 flex items-center justify-center text-xl w-8 ml-2 border border-dashed bg-surface-0 border-danger-300 hover:bg-danger-500 hover:text-surface-0 hover:border-0 active:bg-danger-500 active:text-surface-0 active:border-0 rounded text-danger-500"
66
+ >
67
+ <i class="fa-regular fa-xmark" />
68
+ </button>
69
+ </div>
@@ -0,0 +1,29 @@
1
+ /** @typedef {typeof __propDef.props} FieldWrapperProps */
2
+ /** @typedef {typeof __propDef.events} FieldWrapperEvents */
3
+ /** @typedef {typeof __propDef.slots} FieldWrapperSlots */
4
+ export default class FieldWrapper extends SvelteComponentTyped<{
5
+ [x: string]: any;
6
+ field: any;
7
+ fieldcomponent: any;
8
+ parent_field: any;
9
+ }, {
10
+ [evt: string]: CustomEvent<any>;
11
+ }, {}> {
12
+ }
13
+ export type FieldWrapperProps = typeof __propDef.props;
14
+ export type FieldWrapperEvents = typeof __propDef.events;
15
+ export type FieldWrapperSlots = typeof __propDef.slots;
16
+ import { SvelteComponentTyped } from "svelte";
17
+ declare const __propDef: {
18
+ props: {
19
+ [x: string]: any;
20
+ field: any;
21
+ fieldcomponent: any;
22
+ parent_field: any;
23
+ };
24
+ events: {
25
+ [evt: string]: CustomEvent<any>;
26
+ };
27
+ slots: {};
28
+ };
29
+ export {};
@@ -0,0 +1,8 @@
1
+ <script>
2
+ // fieldWrapper
3
+ export let fieldcomponent;
4
+ </script>
5
+
6
+ <div class="mb-2">
7
+ <svelte:component this={fieldcomponent} {...$$props} />
8
+ </div>
@@ -0,0 +1,25 @@
1
+ /** @typedef {typeof __propDef.props} FieldWrapperProps */
2
+ /** @typedef {typeof __propDef.events} FieldWrapperEvents */
3
+ /** @typedef {typeof __propDef.slots} FieldWrapperSlots */
4
+ export default class FieldWrapper extends SvelteComponentTyped<{
5
+ [x: string]: any;
6
+ fieldcomponent: any;
7
+ }, {
8
+ [evt: string]: CustomEvent<any>;
9
+ }, {}> {
10
+ }
11
+ export type FieldWrapperProps = typeof __propDef.props;
12
+ export type FieldWrapperEvents = typeof __propDef.events;
13
+ export type FieldWrapperSlots = typeof __propDef.slots;
14
+ import { SvelteComponentTyped } from "svelte";
15
+ declare const __propDef: {
16
+ props: {
17
+ [x: string]: any;
18
+ fieldcomponent: any;
19
+ };
20
+ events: {
21
+ [evt: string]: CustomEvent<any>;
22
+ };
23
+ slots: {};
24
+ };
25
+ export {};
@@ -0,0 +1,53 @@
1
+ <script>import { syncStoreToStore } from "../../utils/syncing";
2
+ import { deepEqual } from "fast-equals";
3
+ import _ from "lodash-es";
4
+ import { onMount } from "svelte";
5
+ import { createGrid, GridApi } from "ag-grid-community";
6
+ import "ag-grid-community/styles/ag-grid.css";
7
+ import "ag-grid-community/styles/ag-theme-material.css";
8
+ export let field;
9
+ $:
10
+ state_key = $field.state?.state_key;
11
+ $:
12
+ label = $field.spec?.title;
13
+ $:
14
+ hide_label = $field.spec?.hide_label;
15
+ $:
16
+ isValid = !$field.state?.validation || $field.state?.validation?.valid;
17
+ $:
18
+ validationMessage = $field.state?.validation?.message;
19
+ let gridDiv;
20
+ let gridApi;
21
+ const gridOptions = {
22
+ autoSizeStrategy: {
23
+ type: "fitGridWidth",
24
+ defaultMinWidth: 100
25
+ },
26
+ defaultColDef: {
27
+ suppressMovable: true
28
+ },
29
+ onGridReady: (params) => {
30
+ gridApi = params.api;
31
+ },
32
+ onCellValueChanged: () => {
33
+ let rowData = [];
34
+ gridApi.forEachNode((node) => rowData.push(node.data));
35
+ $field.data.base = rowData;
36
+ },
37
+ // Row Data: The data to be displayed.
38
+ rowData: [],
39
+ // Column Definitions: Defines & controls grid columns.
40
+ columnDefs: []
41
+ };
42
+ onMount(() => {
43
+ let columnDefs = $field.spec?.params?.columnDefs;
44
+ if (columnDefs)
45
+ gridOptions.columnDefs = columnDefs;
46
+ let rowData = $field.data?.base;
47
+ if (Array.isArray(rowData))
48
+ gridOptions.rowData = rowData;
49
+ createGrid(gridDiv, gridOptions);
50
+ });
51
+ </script>
52
+
53
+ <div bind:this={gridDiv} class="ag-theme-material w-full h-96" />
@@ -0,0 +1,18 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import "ag-grid-community/styles/ag-grid.css";
3
+ import "ag-grid-community/styles/ag-theme-material.css";
4
+ declare const __propDef: {
5
+ props: {
6
+ field: any;
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {};
12
+ };
13
+ export type AgGridProps = typeof __propDef.props;
14
+ export type AgGridEvents = typeof __propDef.events;
15
+ export type AgGridSlots = typeof __propDef.slots;
16
+ export default class AgGrid extends SvelteComponentTyped<AgGridProps, AgGridEvents, AgGridSlots> {
17
+ }
18
+ export {};