@stubber/form-fields 1.6.3 → 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
  >
@@ -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} />
@@ -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.3",
3
+ "version": "1.6.4",
4
4
  "description": "An automatic form builder based on field specifications",
5
5
  "keywords": [
6
6
  "components",