@bpmn-io/form-js-playground 1.7.1 → 1.7.2

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.
@@ -53323,20 +53323,59 @@
53323
53323
  }, [conditionChecker, condition, expressionContextInfo]);
53324
53324
  }
53325
53325
 
53326
- // parses the options data from the provided form field and form data
53327
- function getOptionsData(formField, formData) {
53326
+ /**
53327
+ * Returns the options data for the provided if they can be simply determined, ignoring expression defined options.
53328
+ *
53329
+ * @param {object} formField
53330
+ * @param {object} formData
53331
+ */
53332
+ function getSimpleOptionsData(formField, formData) {
53328
53333
  const {
53334
+ valuesExpression: optionsExpression,
53329
53335
  valuesKey: optionsKey,
53330
53336
  values: staticOptions
53331
53337
  } = formField;
53338
+ if (optionsExpression) {
53339
+ return null;
53340
+ }
53332
53341
  return optionsKey ? get$1(formData, [optionsKey]) : staticOptions;
53333
53342
  }
53334
53343
 
53335
- // transforms the provided options into a normalized format, trimming invalid options
53344
+ /**
53345
+ * Normalizes the provided options data to a format that can be used by the select components.
53346
+ * If the options data is not valid, it is filtered out.
53347
+ *
53348
+ * @param {any[]} optionsData
53349
+ *
53350
+ * @returns {object[]}
53351
+ */
53336
53352
  function normalizeOptionsData(optionsData) {
53337
53353
  return optionsData.filter(_isAllowedValue).map(_normalizeOption).filter(o => !isNil$1(o));
53338
53354
  }
53339
53355
 
53356
+ /**
53357
+ * Creates an options object with default values if no options are provided.
53358
+ *
53359
+ * @param {object} options
53360
+ *
53361
+ * @returns {object}
53362
+ */
53363
+ function createEmptyOptions(options = {}) {
53364
+ const defaults = {};
53365
+
53366
+ // provide default options if valuesKey and valuesExpression are not set
53367
+ if (!options.valuesKey && !options.valuesExpression) {
53368
+ defaults.values = [{
53369
+ label: 'Value',
53370
+ value: 'value'
53371
+ }];
53372
+ }
53373
+ return {
53374
+ ...defaults,
53375
+ ...options
53376
+ };
53377
+ }
53378
+
53340
53379
  /**
53341
53380
  * Converts the provided option to a normalized format.
53342
53381
  * If the option is not valid, null is returned.
@@ -53387,21 +53426,6 @@
53387
53426
  }
53388
53427
  return _isAllowedPrimitive(value);
53389
53428
  }
53390
- function createEmptyOptions(options = {}) {
53391
- const defaults = {};
53392
-
53393
- // provide default options if valuesKey and valuesExpression are not set
53394
- if (!options.valuesKey && !options.valuesExpression) {
53395
- defaults.values = [{
53396
- label: 'Value',
53397
- value: 'value'
53398
- }];
53399
- }
53400
- return {
53401
- ...defaults,
53402
- ...options
53403
- };
53404
- }
53405
53429
 
53406
53430
  /**
53407
53431
  * Evaluate a string reactively based on the expressionLanguage and form data.
@@ -53421,29 +53445,20 @@
53421
53445
  return value;
53422
53446
  }, [expressionLanguage, expressionContextInfo, value]);
53423
53447
  }
53424
- function usePrevious$1(value, defaultValue = null) {
53425
- const ref = s$1(defaultValue);
53426
- y(() => ref.current = value, [value]);
53427
- return ref.current;
53428
- }
53429
53448
 
53430
53449
  /**
53431
53450
  * A custom hook to manage state changes with deep comparison.
53432
53451
  *
53433
- * @param {any} value - The current value to manage.
53434
- * @param {any} defaultValue - The initial default value for the state.
53435
- * @returns {any} - Returns the current state.
53452
+ * @template T
53453
+ * @param {T} value - The current value to manage.
53454
+ * @returns {T} - Returns the current state.
53436
53455
  */
53437
- function useDeepCompareState(value, defaultValue) {
53438
- const [state, setState] = l$1(defaultValue);
53439
- const previous = usePrevious$1(value, defaultValue);
53440
- const changed = !isEqual$1(previous, value);
53441
- y(() => {
53442
- if (changed) {
53443
- setState(value);
53444
- }
53445
- }, [changed, value]);
53446
- return state;
53456
+ function useDeepCompareMemoize(value) {
53457
+ const ref = s$1();
53458
+ if (!isEqual$1(value, ref.current)) {
53459
+ ref.current = value;
53460
+ }
53461
+ return ref.current;
53447
53462
  }
53448
53463
 
53449
53464
  /**
@@ -53473,15 +53488,10 @@
53473
53488
  valuesKey: optionsKey,
53474
53489
  values: staticOptions
53475
53490
  } = field;
53476
- const [optionsGetter, setOptionsGetter] = l$1({
53477
- options: [],
53478
- error: undefined,
53479
- loadState: LOAD_STATES.LOADING
53480
- });
53481
53491
  const initialData = useService$2('form')._getState().initialData;
53482
53492
  const expressionEvaluation = useExpressionEvaluation(optionsExpression);
53483
- const evaluatedOptions = useDeepCompareState(expressionEvaluation || [], []);
53484
- y(() => {
53493
+ const evaluatedOptions = useDeepCompareMemoize(expressionEvaluation || []);
53494
+ const optionsGetter = d(() => {
53485
53495
  let options = [];
53486
53496
 
53487
53497
  // dynamic options
@@ -53496,18 +53506,16 @@
53496
53506
  options = Array.isArray(staticOptions) ? staticOptions : [];
53497
53507
 
53498
53508
  // expression
53499
- } else if (optionsExpression) {
53500
- if (evaluatedOptions && Array.isArray(evaluatedOptions)) {
53501
- options = evaluatedOptions;
53502
- }
53509
+ } else if (optionsExpression && evaluatedOptions && Array.isArray(evaluatedOptions)) {
53510
+ options = evaluatedOptions;
53511
+
53512
+ // error case
53503
53513
  } else {
53504
- setOptionsGetter(buildErrorState('No options source defined in the form definition'));
53505
- return;
53514
+ return buildErrorState('No options source defined in the form definition');
53506
53515
  }
53507
53516
 
53508
53517
  // normalize data to support primitives and partially defined objects
53509
- options = normalizeOptionsData(options);
53510
- setOptionsGetter(buildLoadedState(options));
53518
+ return buildLoadedState(normalizeOptionsData(options));
53511
53519
  }, [optionsKey, staticOptions, initialData, optionsExpression, evaluatedOptions]);
53512
53520
  return optionsGetter;
53513
53521
  }
@@ -53552,14 +53560,14 @@
53552
53560
  };
53553
53561
  };
53554
53562
 
53555
- /**
53556
- * A custom hook to build up security attributes from form configuration.
53557
- *
53558
- * @param {Object} security - The security configuration.
53559
- * @returns {Array} - Returns a tuple with sandbox and allow attributes.
53563
+ /**
53564
+ * A custom hook to build up security attributes from form configuration.
53565
+ *
53566
+ * @param {Object} security - The security configuration.
53567
+ * @returns {Array} - Returns a tuple with sandbox and allow attributes.
53560
53568
  */
53561
53569
  function useSecurityAttributesMap(security) {
53562
- const securityMemoized = useDeepCompareState(security);
53570
+ const securityMemoized = useDeepCompareMemoize(security);
53563
53571
  const sandbox = d(() => SECURITY_ATTRIBUTES_DEFINITIONS.filter(({
53564
53572
  attribute
53565
53573
  }) => attribute === SANDBOX_ATTRIBUTE).filter(({
@@ -53729,6 +53737,11 @@
53729
53737
  }
53730
53738
  return readonly || false;
53731
53739
  }
53740
+ function usePrevious$1(value, defaultValue = null) {
53741
+ const ref = s$1(defaultValue);
53742
+ y(() => ref.current = value, [value]);
53743
+ return ref.current;
53744
+ }
53732
53745
  function useFlushDebounce(func) {
53733
53746
  const timeoutRef = s$1(null);
53734
53747
  const lastArgsRef = s$1(null);
@@ -53991,8 +54004,16 @@
53991
54004
  data,
53992
54005
  value
53993
54006
  } = options;
54007
+ const {
54008
+ valuesExpression: optionsExpression
54009
+ } = formField;
53994
54010
  try {
53995
- const validValues = normalizeOptionsData(getOptionsData(formField, data)).map(v => v.value);
54011
+ // if options are expression evaluated, we don't need to sanitize the value against the options
54012
+ // and defer to the field's internal validation
54013
+ if (optionsExpression) {
54014
+ return value;
54015
+ }
54016
+ const validValues = normalizeOptionsData(getSimpleOptionsData(formField, data)).map(v => v.value);
53996
54017
  return hasEqualValue(value, validValues) ? value : null;
53997
54018
  } catch (error) {
53998
54019
  // use default value in case of formatting error
@@ -54006,8 +54027,16 @@
54006
54027
  data,
54007
54028
  value
54008
54029
  } = options;
54030
+ const {
54031
+ valuesExpression: optionsExpression
54032
+ } = formField;
54009
54033
  try {
54010
- const validValues = normalizeOptionsData(getOptionsData(formField, data)).map(v => v.value);
54034
+ // if options are expression evaluated, we don't need to sanitize the values against the options
54035
+ // and defer to the field's internal validation
54036
+ if (optionsExpression) {
54037
+ return value;
54038
+ }
54039
+ const validValues = normalizeOptionsData(getSimpleOptionsData(formField, data)).map(v => v.value);
54011
54040
  return value.filter(v => hasEqualValue(v, validValues));
54012
54041
  } catch (error) {
54013
54042
  // use default value in case of formatting error
@@ -54093,7 +54122,7 @@
54093
54122
  onChange,
54094
54123
  values
54095
54124
  } = props;
54096
- const memoizedValues = useDeepCompareState(values, []);
54125
+ const memoizedValues = useDeepCompareMemoize(values || []);
54097
54126
 
54098
54127
  // ensures that the values are always a subset of the possible options
54099
54128
  y(() => {
@@ -54783,7 +54812,7 @@
54783
54812
  const [forceFocusCalendar, setForceFocusCalendar] = l$1(false);
54784
54813
 
54785
54814
  // ensures we render based on date value instead of reference
54786
- const date = useDeepCompareState(dateObject, null);
54815
+ const date = useDeepCompareMemoize(dateObject);
54787
54816
 
54788
54817
  // shorts the date value back to the source
54789
54818
  y(() => {
@@ -56487,8 +56516,8 @@
56487
56516
  'fjs-readonly': readonly
56488
56517
  }),
56489
56518
  children: [e("button", {
56490
- class: "fjs-number-arrow-up",
56491
56519
  type: "button",
56520
+ class: "fjs-number-arrow-up",
56492
56521
  "aria-label": "Increment",
56493
56522
  onClick: () => increment(),
56494
56523
  tabIndex: -1,
@@ -56496,8 +56525,8 @@
56496
56525
  }), e("div", {
56497
56526
  class: "fjs-number-arrow-separator"
56498
56527
  }), e("button", {
56499
- class: "fjs-number-arrow-down",
56500
56528
  type: "button",
56529
+ class: "fjs-number-arrow-down",
56501
56530
  "aria-label": "Decrement",
56502
56531
  onClick: () => decrement(),
56503
56532
  tabIndex: -1,
@@ -57171,7 +57200,7 @@
57171
57200
  } = useOptionsAsync(field);
57172
57201
 
57173
57202
  // ensures we render based on array content instead of reference
57174
- const values = useDeepCompareState(value || [], []);
57203
+ const values = useDeepCompareMemoize(value || []);
57175
57204
  useCleanupMultiSelectValue({
57176
57205
  field,
57177
57206
  loadState,
@@ -59566,18 +59595,18 @@
59566
59595
  'fjs-remove-allowed': repeaterField.allowAddRemove
59567
59596
  }),
59568
59597
  children: [showAdd ? e("button", {
59598
+ type: "button",
59569
59599
  readOnly: readonly,
59570
59600
  disabled: disabled || readonly,
59571
59601
  class: "fjs-repeat-render-add",
59572
- type: "button",
59573
59602
  ref: addButtonRef,
59574
59603
  onClick: onAddItem,
59575
59604
  children: e(d$1, {
59576
59605
  children: [e(AddSvg, {}), " ", 'Add new']
59577
59606
  })
59578
59607
  }) : null, collapseEnabled ? e("button", {
59579
- class: "fjs-repeat-render-collapse",
59580
59608
  type: "button",
59609
+ class: "fjs-repeat-render-collapse",
59581
59610
  onClick: toggle,
59582
59611
  children: isCollapsed ? e(d$1, {
59583
59612
  children: [e(ExpandSvg, {}), " ", `Expand all (${values.length})`]
@@ -59651,8 +59680,8 @@
59651
59680
  })
59652
59681
  })
59653
59682
  }), e("button", {
59654
- class: "fjs-repeat-row-remove",
59655
59683
  type: "button",
59684
+ class: "fjs-repeat-row-remove",
59656
59685
  "aria-label": `Remove list item ${index + 1}`,
59657
59686
  onClick: () => onDeleteItem(index),
59658
59687
  children: e("div", {
@@ -67729,6 +67758,7 @@
67729
67758
  }
67730
67759
  };
67731
67760
  return e("button", {
67761
+ type: "button",
67732
67762
  class: "fjs-palette-field fjs-drag-copy fjs-no-drop",
67733
67763
  "data-field-type": type,
67734
67764
  title: `Create ${getIndefiniteArticle(type)} ${label} element`,
@@ -67820,6 +67850,7 @@
67820
67850
  value: searchTerm,
67821
67851
  onInput: handleInput
67822
67852
  }), searchTerm && e("button", {
67853
+ type: "button",
67823
67854
  title: "Clear content",
67824
67855
  class: "fjs-palette-search-clear",
67825
67856
  onClick: handleClear,
@@ -68564,6 +68595,7 @@
68564
68595
  field: field
68565
68596
  }), e(ContextPad, {
68566
68597
  children: selection.isSelected(field) && field.type !== 'default' ? e("button", {
68598
+ type: "button",
68567
68599
  title: getRemoveButtonTitle(field, formFields),
68568
68600
  class: "fjs-context-pad-item",
68569
68601
  onClick: onRemove,
@@ -75988,7 +76020,7 @@
75988
76020
  getValue,
75989
76021
  id,
75990
76022
  label: 'Disabled',
75991
- tooltip: 'Field cannot be edited by the end-user, and the data is not submitted.',
76023
+ tooltip: 'Field cannot be edited by the end-user, and the data is not submitted. Takes precedence over read only.',
75992
76024
  inline: true,
75993
76025
  setValue
75994
76026
  });
@@ -77835,15 +77867,20 @@
77835
77867
  editField,
77836
77868
  field
77837
77869
  } = props;
77870
+ const {
77871
+ disabled
77872
+ } = field;
77838
77873
  const entries = [];
77839
- entries.push({
77840
- id: 'readonly',
77841
- component: Readonly,
77842
- editField: editField,
77843
- field: field,
77844
- isEdited: isEdited$6,
77845
- isDefaultVisible: field => INPUTS.includes(field.type)
77846
- });
77874
+ if (!disabled) {
77875
+ entries.push({
77876
+ id: 'readonly',
77877
+ component: Readonly,
77878
+ editField: editField,
77879
+ field: field,
77880
+ isEdited: isEdited$6,
77881
+ isDefaultVisible: field => INPUTS.includes(field.type)
77882
+ });
77883
+ }
77847
77884
  return entries;
77848
77885
  }
77849
77886
  function Readonly(props) {
@@ -79707,6 +79744,7 @@
79707
79744
  }), e("div", {
79708
79745
  class: "fjs-pgl-modal-footer",
79709
79746
  children: e("button", {
79747
+ type: "button",
79710
79748
  class: "fjs-pgl-button fjs-pgl-button-default",
79711
79749
  onClick: props.onClose,
79712
79750
  children: "Close"
@@ -81685,6 +81723,7 @@
81685
81723
  name: "Form Definition",
81686
81724
  children: [displayActions && e(Section.HeaderItem, {
81687
81725
  children: e("button", {
81726
+ type: "button",
81688
81727
  class: "fjs-pgl-button",
81689
81728
  title: "Download form definition",
81690
81729
  onClick: handleDownload,
@@ -81692,6 +81731,7 @@
81692
81731
  })
81693
81732
  }), displayActions && e(Section.HeaderItem, {
81694
81733
  children: e("button", {
81734
+ type: "button",
81695
81735
  class: "fjs-pgl-button",
81696
81736
  onClick: showEmbedModal,
81697
81737
  children: "Embed"
package/dist/index.cjs CHANGED
@@ -49,6 +49,7 @@ function Modal(props) {
49
49
  }), jsxRuntime.jsx("div", {
50
50
  class: "fjs-pgl-modal-footer",
51
51
  children: jsxRuntime.jsx("button", {
52
+ type: "button",
52
53
  class: "fjs-pgl-button fjs-pgl-button-default",
53
54
  onClick: props.onClose,
54
55
  children: "Close"
@@ -499,6 +500,7 @@ function PlaygroundRoot(props) {
499
500
  name: "Form Definition",
500
501
  children: [displayActions && jsxRuntime.jsx(Section.HeaderItem, {
501
502
  children: jsxRuntime.jsx("button", {
503
+ type: "button",
502
504
  class: "fjs-pgl-button",
503
505
  title: "Download form definition",
504
506
  onClick: handleDownload,
@@ -506,6 +508,7 @@ function PlaygroundRoot(props) {
506
508
  })
507
509
  }), displayActions && jsxRuntime.jsx(Section.HeaderItem, {
508
510
  children: jsxRuntime.jsx("button", {
511
+ type: "button",
509
512
  class: "fjs-pgl-button",
510
513
  onClick: showEmbedModal,
511
514
  children: "Embed"