@stubber/form-fields 1.6.2 → 1.6.4

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.
@@ -8,7 +8,7 @@ $: type = validation_result?.type;
8
8
 
9
9
  <Label
10
10
  id="message-{$fieldStore.id}"
11
- class="ml-2 text-xs {!$fieldStore.validation_result ? 'invisible' : ''} {type == 'error'
11
+ class="ml-2 truncate text-xs {!$fieldStore.validation_result ? 'invisible' : ''} {type == 'error'
12
12
  ? 'text-red-500'
13
13
  : 'text-muted-foreground'}"
14
14
  >
@@ -130,7 +130,7 @@ $: selectedValue = currency_list.find((c) => c.value === current_details?.curren
130
130
 
131
131
  <FieldLabel {fieldStore} />
132
132
  <div
133
- class="flex-row items-center gap-2 border-input bg-background selection:bg-primary dark:bg-input/30 selection:text-primary-foreground ring-offset-background placeholder:text-muted-foreground shadow-xs flex h-9 w-full min-w-0 rounded-md border px-3 py-1 text-base outline-none transition-[color,box-shadow] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-[invalid]:border-destructive aria-[invalid]:ring-destructive/50 aria-[invalid]:focus-visible:ring-destructive/50"
133
+ class="flex h-9 w-full min-w-0 flex-row items-center gap-2 rounded-md border border-input bg-background px-3 py-1 text-base outline-none ring-offset-background transition-[color,box-shadow] selection:bg-primary selection:text-primary-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid]:border-destructive aria-[invalid]:ring-destructive/50 aria-[invalid]:focus-visible:ring-destructive/50 md:text-sm dark:bg-input/30"
134
134
  >
135
135
  <!-- currency indicator front left -->
136
136
  <div class="pointer-events-none text-gray-500">
@@ -143,7 +143,7 @@ $: selectedValue = currency_list.find((c) => c.value === current_details?.curren
143
143
  {/if}
144
144
  </div>
145
145
  <input
146
- class="w-full focus-within:outline-none bg-transparent"
146
+ class="w-full bg-transparent focus-within:outline-none"
147
147
  use:inputRegexMask={currencyRegex}
148
148
  value={initial_ui_value}
149
149
  inputmode="decimal"
@@ -160,13 +160,13 @@ $: selectedValue = currency_list.find((c) => c.value === current_details?.curren
160
160
  variant="outline"
161
161
  role="combobox"
162
162
  aria-expanded={open}
163
- class="w-28 border-none bg-transparent px-1 justify-between"
163
+ class="w-28 justify-between border-none bg-transparent px-1"
164
164
  >
165
165
  {selectedValue}
166
166
  <i class="fas fa-sort ml-2 h-4 w-4 shrink-0 opacity-50" />
167
167
  </Button>
168
168
  </Popover.Trigger>
169
- <Popover.Content class="p-0 max-h-[50vh] overflow-y-scroll">
169
+ <Popover.Content class="max-h-[50vh] overflow-y-scroll p-0">
170
170
  <Command.Root>
171
171
  <Command.Input placeholder="Search currencies..." />
172
172
  <Command.Empty>No currency found.</Command.Empty>
@@ -115,6 +115,7 @@ function update_value(new_value) {
115
115
  ...cloneDeep(new_value)
116
116
  };
117
117
  update_params_from_value(value.params);
118
+ update_subfields_from_value(value.fields);
118
119
  }
119
120
  }
120
121
  const field_types = Object.keys(fields).map((key) => ({
@@ -224,8 +225,24 @@ function update_params_from_value(new_value) {
224
225
  }
225
226
  function select_field_type(newValue, trigger) {
226
227
  value.fieldtype = newValue;
228
+ field_param_spec = cloneDeep(field_params_spec_lookup[value.fieldtype ?? "unknown"]);
227
229
  closeAndFocusTrigger(trigger);
228
230
  }
231
+ let field_param_spec = cloneDeep(field_params_spec_lookup[value.fieldtype ?? "unknown"]);
232
+ const subfields_store = writable({});
233
+ $: update_subfields($subfields_store.fields);
234
+ function update_subfields(new_subfields) {
235
+ const cloned_new_subfields = cloneDeep(new_subfields);
236
+ if (!isEqual(value.fields, cloned_new_subfields) && !isEmpty(cloned_new_subfields)) {
237
+ value.fields = cloned_new_subfields;
238
+ update_fieldStore(value);
239
+ }
240
+ }
241
+ function update_subfields_from_value(new_value) {
242
+ if (!isEqual(new_value, $subfields_store)) {
243
+ subfields_store.set({ fields: cloneDeep(new_value) || {} });
244
+ }
245
+ }
229
246
  </script>
230
247
 
231
248
  <FieldLabel {fieldStore} />
@@ -238,13 +255,13 @@ function select_field_type(newValue, trigger) {
238
255
  variant="outline"
239
256
  role="combobox"
240
257
  aria-expanded={open}
241
- class="w-full border-input bg-white bg-opacity-[15] ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring flex h-10 rounded-md border px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 justify-between"
258
+ class="flex h-10 w-full justify-between rounded-md border border-input bg-white bg-opacity-[15] px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
242
259
  >
243
260
  {selectedValue}
244
261
  <i class="fas fa-sort ml-2 h-4 w-4 shrink-0 opacity-50" />
245
262
  </Button>
246
263
  </Popover.Trigger>
247
- <Popover.Content class="p-0" sameWidth>
264
+ <Popover.Content class="max-h-[50vh] overflow-y-scroll p-0" sameWidth>
248
265
  <Command.Root>
249
266
  <Command.Input placeholder="Search framework..." />
250
267
  <Command.Empty>No fieldtype found.</Command.Empty>
@@ -281,11 +298,11 @@ function select_field_type(newValue, trigger) {
281
298
  bind:value={value.title}
282
299
  />
283
300
  </div>
284
- <div class="w-full flex items-center space-x-2">
301
+ <div class="flex w-full items-center space-x-2">
285
302
  <Checkbox id="without_value_details" bind:checked={value.without_value_details} />
286
303
  <Label for="without_value_details">Without Value Details</Label>
287
304
  </div>
288
- <div class="w-full flex items-center space-x-2">
305
+ <div class="flex w-full items-center space-x-2">
289
306
  <Checkbox id="hide_label" bind:checked={value.hide_label} />
290
307
  <Label for="hide_label">Hide Label</Label>
291
308
  </div>
@@ -300,8 +317,50 @@ function select_field_type(newValue, trigger) {
300
317
  </Collapsible.Content>
301
318
  </Collapsible.Root>
302
319
  <hr />
320
+ <!-- subfields -->
321
+ {#if value.fieldtype === "section" || value.fieldtype === "multistep"}
322
+ <Collapsible.Root open={false} class="w-full">
323
+ <Collapsible.Trigger asChild let:builder>
324
+ <Button builders={[builder]} variant="ghost" class="w-full justify-between pl-0">
325
+ <Label>Fields</Label>
326
+
327
+ <i class="fa fa-sort" />
328
+ </Button>
329
+ </Collapsible.Trigger>
330
+
331
+ <Collapsible.Content class="flex flex-col gap-y-2 pl-2 pt-2">
332
+ <Form
333
+ form={subfields_store}
334
+ initial_form={{
335
+ spec: {
336
+ fields: {
337
+ fields: {
338
+ hide_label: true,
339
+ fieldtype: "objectbuilder",
340
+ help: "Fields within this section/multistep",
341
+ params: {
342
+ value_field_spec: {
343
+ fieldtype: "fieldbuilder",
344
+ initvalue: {
345
+ has_default: true,
346
+ default: {
347
+ fieldtype: "text",
348
+ },
349
+ },
350
+ },
351
+ },
352
+ },
353
+ },
354
+ },
355
+ }}
356
+ />
357
+ </Collapsible.Content>
358
+ </Collapsible.Root>
359
+ <hr />
360
+ {/if}
361
+
303
362
  <!-- params -->
304
- <Collapsible.Root open={true} class="w-full">
363
+ <Collapsible.Root open={false} class="w-full">
305
364
  <Collapsible.Trigger asChild let:builder>
306
365
  <Button builders={[builder]} variant="ghost" class="w-full justify-between pl-0">
307
366
  <Label>Params</Label>
@@ -311,16 +370,16 @@ function select_field_type(newValue, trigger) {
311
370
  </Collapsible.Trigger>
312
371
 
313
372
  <Collapsible.Content class="flex flex-col gap-y-2 pl-2 pt-2">
314
- <!-- todo this doesnt update when fieldtype changes -->
315
- {@const field_param_spec = field_params_spec_lookup[value.fieldtype ?? "unknown"]}
316
373
  {#if field_param_spec}
317
- <Form
318
- initial_form={field_param_spec}
319
- form={params_store}
320
- attachments={$fieldStore.attachmentsStore}
321
- />
374
+ {#key value.fieldtype}
375
+ <Form
376
+ initial_form={field_param_spec}
377
+ form={params_store}
378
+ attachments={$fieldStore.attachmentsStore}
379
+ />
380
+ {/key}
322
381
  {:else}
323
- <span class="text-muted-foreground text-xs">No params available for this fieldtype.</span>
382
+ <span class="text-xs text-muted-foreground">No params available for this fieldtype.</span>
324
383
  {/if}
325
384
  </Collapsible.Content>
326
385
  </Collapsible.Root>
@@ -367,14 +426,14 @@ function select_field_type(newValue, trigger) {
367
426
 
368
427
  <Collapsible.Content class="flex flex-col gap-y-2 pl-2">
369
428
  <div>
370
- <div class="w-full flex items-center space-x-2">
429
+ <div class="flex w-full items-center space-x-2">
371
430
  <Checkbox id="has_default" bind:checked={value.initvalue.has_default} />
372
431
  <Label for="has_default">Has Default</Label>
373
432
  </div>
374
433
  <JsonEditorBound bind:value={value.initvalue.default} />
375
434
  </div>
376
435
  <div>
377
- <div class="w-full flex items-center space-x-2">
436
+ <div class="flex w-full items-center space-x-2">
378
437
  <Checkbox id="has_override" bind:checked={value.initvalue.has_override} />
379
438
  <Label for="has_override">Has Override</Label>
380
439
  </div>
@@ -400,7 +459,7 @@ function select_field_type(newValue, trigger) {
400
459
 
401
460
  {#if value.conditions && value.conditions.length > 0}
402
461
  {#each value.conditions as condition, index}
403
- <div class="flex items-center space-x-2 w-full">
462
+ <div class="flex w-full items-center space-x-2">
404
463
  <!-- up and down sort buttons -->
405
464
  <div class="flex flex-col items-center">
406
465
  <Button
@@ -455,7 +514,7 @@ function select_field_type(newValue, trigger) {
455
514
 
456
515
  {#if value.validations && value.validations.length > 0}
457
516
  {#each value.validations as validation, index}
458
- <div class="flex items-start space-x-2 w-full">
517
+ <div class="flex w-full items-start space-x-2">
459
518
  <!-- up and down sort buttons -->
460
519
  <div class="flex flex-col items-center">
461
520
  <Button
@@ -475,7 +534,7 @@ function select_field_type(newValue, trigger) {
475
534
  <i class="fa fa-chevron-down" />
476
535
  </Button>
477
536
  </div>
478
- <div class="w-full flex flex-col items-stretch gap-1">
537
+ <div class="flex w-full flex-col items-stretch gap-1">
479
538
  <Select.Root
480
539
  selected={{
481
540
  label: value.validations[index].validationtype,
@@ -2,8 +2,13 @@
2
2
  spec: {
3
3
  fields: {
4
4
  columnDefs: {
5
- fieldtype: "jsoneditor",
6
- help: "Column Definitions as per https://www.ag-grid.com/javascript-data-grid/column-definitions/"
5
+ fieldtype: "arraybuilder",
6
+ params: {
7
+ new_entry_field: {
8
+ fieldtype: "jsoneditor"
9
+ }
10
+ },
11
+ help: "See https://www.ag-grid.com/javascript-data-grid/column-definitions/"
7
12
  }
8
13
  }
9
14
  }
@@ -50,5 +55,5 @@ onMount(() => {
50
55
  </script>
51
56
 
52
57
  <FieldLabel {fieldStore} />
53
- <div bind:this={gridDiv} class="ag-theme-material w-full h-96" />
58
+ <div bind:this={gridDiv} class="ag-theme-material h-96 w-full" />
54
59
  <FieldMessage {fieldStore} />
@@ -121,12 +121,30 @@ const contentField = StateField.define({
121
121
  },
122
122
  update(value, transaction) {
123
123
  if (transaction.docChanged) {
124
- $fieldStore.value = parse_string ? parse_string_value(transaction.newDoc.toString()) : transaction.newDoc.toString();
125
- return transaction.newDoc.toString();
124
+ let new_value = transaction.newDoc.toString();
125
+ if (new_value !== $fieldStore.value) {
126
+ $fieldStore.value = parse_string ? parse_string_value(new_value) : new_value;
127
+ }
128
+ return new_value;
126
129
  }
127
130
  return value;
128
131
  }
129
132
  });
133
+ $: update_editor_content($fieldStore.value);
134
+ function update_editor_content(new_value) {
135
+ if (editor_view) {
136
+ const current_value = editor_view.state.doc.toString();
137
+ if (new_value !== current_value && typeof new_value === "string") {
138
+ editor_view.dispatch({
139
+ changes: {
140
+ from: 0,
141
+ to: current_value.length,
142
+ insert: new_value
143
+ }
144
+ });
145
+ }
146
+ }
147
+ }
130
148
  function fake_handlebars_lang() {
131
149
  const curly_decorator = new MatchDecorator({
132
150
  regexp: /(\{\{[^}]*\}\})|(~~[^\s]*)/g,
@@ -180,43 +198,63 @@ function parse_string_value(value) {
180
198
 
181
199
  <FieldLabel {fieldStore} />
182
200
  {#if !is_object}
183
- <div
184
- use:setup_editor
185
- class=" stubber-cm text-sm {isValid ? 'stubber-valid' : 'stubber-invalid'}"
186
- />
201
+ <div use:setup_editor class="stubber-cm" aria-invalid={!isValid} />
187
202
  {:else}
188
203
  <p class="text-surface-400">The value of this field is not a string.</p>
189
204
  {/if}
190
205
  <FieldMessage {fieldStore} />
191
206
 
207
+ <!-- below styles are basically this tailwind string:
208
+ flex h-9 w-full min-w-0 flex-row items-center gap-2 rounded-md border border-input bg-background px-3 py-1 text-base outline-none ring-offset-background transition-[color,box-shadow] selection:bg-primary selection:text-primary-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid]:border-destructive aria-[invalid]:ring-destructive/50 aria-[invalid]:focus-visible:ring-destructive/50 md:text-sm dark:bg-input/30 -->
209
+
192
210
  <style>
193
211
  .stubber-cm :global(.cm-editor) {
194
- /* Base styles */
195
- background-color: rgba(255, 255, 255, 0.85);
212
+ width: 100%;
213
+ min-width: 0;
196
214
  border-radius: 0.375rem;
215
+ border-width: 1px;
197
216
  --tw-border-opacity: 1;
198
217
  border-color: hsl(var(--input) / var(--tw-border-opacity, 1));
199
- border-width: 1px;
200
- border-style: solid;
201
- width: 100%;
202
- color: rgb(31 41 51);
218
+ --tw-bg-opacity: 1;
219
+ background-color: hsl(var(--background) / var(--tw-bg-opacity, 1));
203
220
 
204
- /* Top inset shadow only */
205
- box-shadow: inset 0px 16px 16px -16px rgba(0, 0, 0, 0.1333);
221
+ font-size: 0.875rem;
222
+ line-height: 1.25rem;
223
+ outline: 2px solid transparent;
224
+ outline-offset: 2px;
225
+ --tw-ring-offset-color: hsl(var(--background) / 1);
226
+ transition-property: color, box-shadow;
227
+ transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
228
+ transition-duration: 150ms;
206
229
  }
207
230
 
208
- .stubber-cm :global(.cm-editor.cm-focused) {
209
- outline: none;
210
- border-width: 1px;
211
- border-color: hsl(var(--input) / var(--tw-border-opacity, 1));
231
+ @media (prefers-color-scheme: dark) {
232
+ .stubber-cm :global(.cm-editor) {
233
+ background-color: hsl(var(--input) / 0.3);
234
+ }
235
+ }
236
+
237
+ .stubber-cm[aria-invalid="true"] :global(.cm-editor) {
238
+ --tw-border-opacity: 1;
239
+ border-color: hsl(var(--destructive) / var(--tw-border-opacity, 1));
240
+ --tw-ring-color: hsl(var(--destructive) / 0.5);
212
241
  }
213
242
 
214
- .stubber-cm.stubber-valid :global(.cm-editor.cm-focused) {
215
- border-color: rgb(170, 170, 170, 0.5);
243
+ .stubber-cm :global(.cm-editor.cm-focused) {
244
+ --tw-border-opacity: 1;
245
+ border-color: hsl(var(--ring) / var(--tw-border-opacity, 1));
246
+ --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
247
+ var(--tw-ring-offset-color);
248
+ --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width))
249
+ var(--tw-ring-color);
250
+ box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
251
+ --tw-ring-color: hsl(var(--ring) / 0.5);
216
252
  }
217
253
 
218
- .stubber-cm.stubber-invalid :global(.cm-editor) {
219
- border-color: rgb(225 45 57);
254
+ .stubber-cm[aria-invalid="true"] :global(.cm-editor.cm-focused) {
255
+ --tw-ring-color: hsl(var(--destructive) / 0.5);
256
+ --tw-border-opacity: 1;
257
+ border-color: hsl(var(--destructive) / var(--tw-border-opacity, 1));
220
258
  }
221
259
 
222
260
  .stubber-cm :global(.cm-editor .cm-scroller) {
@@ -236,6 +274,7 @@ function parse_string_value(value) {
236
274
  }
237
275
 
238
276
  .stubber-cm :global(.cm-editor .cm-placeholder) {
277
+ --tw-text-opacity: 1;
239
278
  color: hsl(var(--muted-foreground) / var(--tw-text-opacity, 1));
240
279
  }
241
280
 
@@ -87,8 +87,8 @@ export const regex_validation = (results, value, validation) => {
87
87
  export const jsonata_validation = async (results, _value, validation, context = {}) => {
88
88
  try {
89
89
  let result = await jsonata(validation.params.jsonata).evaluate(context);
90
- console.log(`jsonata context:`, context);
91
- console.log(`jsonata ${validation.params.jsonata} result:`, result);
90
+ // console.log(`jsonata context:`, context);
91
+ // console.log(`jsonata ${validation.params.jsonata} result:`, result);
92
92
  if (!result) {
93
93
  results.push({
94
94
  message: validation.invalid_message || "This field is invalid.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stubber/form-fields",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "An automatic form builder based on field specifications",
5
5
  "keywords": [
6
6
  "components",
@@ -50,6 +50,7 @@
50
50
  "postcss": "^8.4.28",
51
51
  "prettier": "^2.8.0",
52
52
  "prettier-plugin-svelte": "^2.10.1",
53
+ "prettier-plugin-tailwindcss": "^0.4.1",
53
54
  "publint": "^0.2.2",
54
55
  "socket.io-client": "^4.8.1",
55
56
  "svelte-check": "^3.4.3",
@@ -65,7 +66,7 @@
65
66
  "@codemirror/lang-javascript": "^6.2.4",
66
67
  "@codemirror/state": "^6.5.2",
67
68
  "@codemirror/view": "^6.38.4",
68
- "@stubber/ui": "^1.13.5",
69
+ "@stubber/ui": "^1.13.6",
69
70
  "ag-grid-community": "^31.0.2",
70
71
  "ag-grid-enterprise": "^31.0.2",
71
72
  "codemirror": "^6.0.2",