@bpmn-io/properties-panel 2.1.0 → 2.2.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.
package/dist/index.js CHANGED
@@ -1631,6 +1631,166 @@ function prefixId$6(id) {
1631
1631
  return `bio-properties-panel-${id}`;
1632
1632
  }
1633
1633
 
1634
+ function NumberField(props) {
1635
+ const {
1636
+ debounce,
1637
+ disabled,
1638
+ displayLabel = true,
1639
+ id,
1640
+ inputRef,
1641
+ label,
1642
+ max,
1643
+ min,
1644
+ onInput,
1645
+ step,
1646
+ value = '',
1647
+ onFocus,
1648
+ onBlur
1649
+ } = props;
1650
+ const [localValue, setLocalValue] = hooks.useState(value);
1651
+ const handleInputCallback = hooks.useMemo(() => {
1652
+ return debounce(event => {
1653
+ const {
1654
+ validity,
1655
+ value
1656
+ } = event.target;
1657
+ if (validity.valid) {
1658
+ onInput(value ? parseFloat(value) : undefined);
1659
+ }
1660
+ });
1661
+ }, [onInput, debounce]);
1662
+ const handleInput = e => {
1663
+ handleInputCallback(e);
1664
+ setLocalValue(e.target.value);
1665
+ };
1666
+ hooks.useEffect(() => {
1667
+ if (value === localValue) {
1668
+ return;
1669
+ }
1670
+ setLocalValue(value);
1671
+ }, [value]);
1672
+ return jsxRuntime.jsxs("div", {
1673
+ class: "bio-properties-panel-numberfield",
1674
+ children: [displayLabel && jsxRuntime.jsx("label", {
1675
+ for: prefixId$5(id),
1676
+ class: "bio-properties-panel-label",
1677
+ children: label
1678
+ }), jsxRuntime.jsx("input", {
1679
+ id: prefixId$5(id),
1680
+ ref: inputRef,
1681
+ type: "number",
1682
+ name: id,
1683
+ spellCheck: "false",
1684
+ autoComplete: "off",
1685
+ disabled: disabled,
1686
+ class: "bio-properties-panel-input",
1687
+ max: max,
1688
+ min: min,
1689
+ onInput: handleInput,
1690
+ onFocus: onFocus,
1691
+ onBlur: onBlur,
1692
+ step: step,
1693
+ value: localValue
1694
+ })]
1695
+ });
1696
+ }
1697
+
1698
+ /**
1699
+ * @param {Object} props
1700
+ * @param {Boolean} props.debounce
1701
+ * @param {String} props.description
1702
+ * @param {Boolean} props.disabled
1703
+ * @param {Object} props.element
1704
+ * @param {Function} props.getValue
1705
+ * @param {String} props.id
1706
+ * @param {String} props.label
1707
+ * @param {String} props.max
1708
+ * @param {String} props.min
1709
+ * @param {Function} props.setValue
1710
+ * @param {Function} props.onFocus
1711
+ * @param {Function} props.onBlur
1712
+ * @param {String} props.step
1713
+ * @param {Function} props.validate
1714
+ */
1715
+ function NumberFieldEntry(props) {
1716
+ const {
1717
+ debounce,
1718
+ description,
1719
+ disabled,
1720
+ element,
1721
+ getValue,
1722
+ id,
1723
+ label,
1724
+ max,
1725
+ min,
1726
+ setValue,
1727
+ step,
1728
+ onFocus,
1729
+ onBlur,
1730
+ validate
1731
+ } = props;
1732
+ const [cachedInvalidValue, setCachedInvalidValue] = hooks.useState(null);
1733
+ const globalError = useError(id);
1734
+ const [localError, setLocalError] = hooks.useState(null);
1735
+ let value = getValue(element);
1736
+ const previousValue = usePrevious(value);
1737
+ hooks.useEffect(() => {
1738
+ if (minDash.isFunction(validate)) {
1739
+ const newValidationError = validate(value) || null;
1740
+ setLocalError(newValidationError);
1741
+ }
1742
+ }, [value]);
1743
+ const onInput = newValue => {
1744
+ let newValidationError = null;
1745
+ if (minDash.isFunction(validate)) {
1746
+ newValidationError = validate(newValue) || null;
1747
+ }
1748
+ if (newValidationError) {
1749
+ setCachedInvalidValue(newValue);
1750
+ } else {
1751
+ setValue(newValue);
1752
+ }
1753
+ setLocalError(newValidationError);
1754
+ };
1755
+ if (previousValue === value && localError) {
1756
+ value = cachedInvalidValue;
1757
+ }
1758
+ const error = globalError || localError;
1759
+ return jsxRuntime.jsxs("div", {
1760
+ class: classnames__default["default"]('bio-properties-panel-entry', error ? 'has-error' : ''),
1761
+ "data-entry-id": id,
1762
+ children: [jsxRuntime.jsx(NumberField, {
1763
+ debounce: debounce,
1764
+ disabled: disabled,
1765
+ id: id,
1766
+ label: label,
1767
+ onFocus: onFocus,
1768
+ onBlur: onBlur,
1769
+ onInput: onInput,
1770
+ max: max,
1771
+ min: min,
1772
+ step: step,
1773
+ value: value
1774
+ }, element), error && jsxRuntime.jsx("div", {
1775
+ class: "bio-properties-panel-error",
1776
+ children: error
1777
+ }), jsxRuntime.jsx(Description, {
1778
+ forId: id,
1779
+ element: element,
1780
+ value: description
1781
+ })]
1782
+ });
1783
+ }
1784
+ function isEdited$6(node) {
1785
+ return node && !!node.value;
1786
+ }
1787
+
1788
+ // helpers /////////////////
1789
+
1790
+ function prefixId$5(id) {
1791
+ return `bio-properties-panel-${id}`;
1792
+ }
1793
+
1634
1794
  const noop$1 = () => {};
1635
1795
  function FeelTextfield(props) {
1636
1796
  const {
@@ -1757,7 +1917,7 @@ function FeelTextfield(props) {
1757
1917
  'feel-active': feelActive
1758
1918
  }),
1759
1919
  children: [jsxRuntime.jsxs("label", {
1760
- for: prefixId$5(id),
1920
+ for: prefixId$4(id),
1761
1921
  class: "bio-properties-panel-label",
1762
1922
  onClick: () => setFocus(),
1763
1923
  children: [label, jsxRuntime.jsx(FeelIcon, {
@@ -1774,7 +1934,7 @@ function FeelTextfield(props) {
1774
1934
  disabled: feel !== 'optional' || disabled,
1775
1935
  onClick: handleFeelToggle
1776
1936
  }), feelActive ? jsxRuntime.jsx(CodeEditor, {
1777
- id: prefixId$5(id),
1937
+ id: prefixId$4(id),
1778
1938
  name: id,
1779
1939
  onInput: handleLocalInput,
1780
1940
  disabled: disabled,
@@ -1791,7 +1951,7 @@ function FeelTextfield(props) {
1791
1951
  ...props,
1792
1952
  onInput: handleLocalInput,
1793
1953
  contentAttributes: {
1794
- 'id': prefixId$5(id),
1954
+ 'id': prefixId$4(id),
1795
1955
  'aria-label': label
1796
1956
  },
1797
1957
  value: localValue,
@@ -1829,7 +1989,7 @@ const OptionalFeelInput = compat.forwardRef((props, ref) => {
1829
1989
  }
1830
1990
  };
1831
1991
  return jsxRuntime.jsx("input", {
1832
- id: prefixId$5(id),
1992
+ id: prefixId$4(id),
1833
1993
  type: "text",
1834
1994
  ref: inputRef,
1835
1995
  name: id,
@@ -1843,6 +2003,53 @@ const OptionalFeelInput = compat.forwardRef((props, ref) => {
1843
2003
  value: value || ''
1844
2004
  });
1845
2005
  });
2006
+ const OptionalFeelNumberField = compat.forwardRef((props, ref) => {
2007
+ const {
2008
+ id,
2009
+ debounce,
2010
+ disabled,
2011
+ onInput,
2012
+ value,
2013
+ min,
2014
+ max,
2015
+ step,
2016
+ onFocus,
2017
+ onBlur
2018
+ } = props;
2019
+ const inputRef = hooks.useRef();
2020
+
2021
+ // To be consistent with the FEEL editor, set focus at start of input
2022
+ // this ensures clean editing experience when switching with the keyboard
2023
+ ref.current = {
2024
+ focus: position => {
2025
+ const input = inputRef.current;
2026
+ if (!input) {
2027
+ return;
2028
+ }
2029
+ input.focus();
2030
+ if (typeof position === 'number' && position !== Infinity) {
2031
+ if (position > value.length) {
2032
+ position = value.length;
2033
+ }
2034
+ input.setSelectionRange(position, position);
2035
+ }
2036
+ }
2037
+ };
2038
+ return jsxRuntime.jsx(NumberField, {
2039
+ id: id,
2040
+ debounce: debounce,
2041
+ disabled: disabled,
2042
+ displayLabel: false,
2043
+ inputRef: inputRef,
2044
+ max: max,
2045
+ min: min,
2046
+ onInput: onInput,
2047
+ step: step,
2048
+ value: value,
2049
+ onFocus: onFocus,
2050
+ onBlur: onBlur
2051
+ });
2052
+ });
1846
2053
  const OptionalFeelTextArea = compat.forwardRef((props, ref) => {
1847
2054
  const {
1848
2055
  id,
@@ -1867,7 +2074,7 @@ const OptionalFeelTextArea = compat.forwardRef((props, ref) => {
1867
2074
  }
1868
2075
  };
1869
2076
  return jsxRuntime.jsx("textarea", {
1870
- id: prefixId$5(id),
2077
+ id: prefixId$4(id),
1871
2078
  type: "text",
1872
2079
  ref: inputRef,
1873
2080
  name: id,
@@ -1943,7 +2150,7 @@ const OptionalFeelCheckbox = compat.forwardRef((props, ref) => {
1943
2150
  };
1944
2151
  return jsxRuntime.jsx("input", {
1945
2152
  ref: inputRef,
1946
- id: prefixId$5(id),
2153
+ id: prefixId$4(id),
1947
2154
  name: id,
1948
2155
  onFocus: onFocus,
1949
2156
  onBlur: onBlur,
@@ -2032,11 +2239,13 @@ function FeelEntry(props) {
2032
2239
  return jsxRuntime.jsxs("div", {
2033
2240
  class: classnames__default["default"](props.class, 'bio-properties-panel-entry', error ? 'has-error' : ''),
2034
2241
  "data-entry-id": id,
2035
- children: [jsxRuntime.jsx(FeelTextfield, {
2242
+ children: [preact.createElement(FeelTextfield, {
2243
+ ...props,
2036
2244
  debounce: debounce,
2037
2245
  disabled: disabled,
2038
2246
  feel: feel,
2039
2247
  id: id,
2248
+ key: element,
2040
2249
  label: label,
2041
2250
  onInput: onInput,
2042
2251
  onError: onError,
@@ -2050,7 +2259,7 @@ function FeelEntry(props) {
2050
2259
  variables: variables,
2051
2260
  tooltipContainer: tooltipContainer,
2052
2261
  OptionalComponent: props.OptionalComponent
2053
- }, element), error && jsxRuntime.jsx("div", {
2262
+ }), error && jsxRuntime.jsx("div", {
2054
2263
  class: "bio-properties-panel-error",
2055
2264
  children: error
2056
2265
  }), jsxRuntime.jsx(Description, {
@@ -2061,6 +2270,36 @@ function FeelEntry(props) {
2061
2270
  });
2062
2271
  }
2063
2272
 
2273
+ /**
2274
+ * @param {Object} props
2275
+ * @param {Object} props.element
2276
+ * @param {String} props.id
2277
+ * @param {String} props.description
2278
+ * @param {Boolean} props.debounce
2279
+ * @param {Boolean} props.disabled
2280
+ * @param {String} props.max
2281
+ * @param {String} props.min
2282
+ * @param {String} props.step
2283
+ * @param {Boolean} props.feel
2284
+ * @param {String} props.label
2285
+ * @param {Function} props.getValue
2286
+ * @param {Function} props.setValue
2287
+ * @param {Function} props.tooltipContainer
2288
+ * @param {Function} props.validate
2289
+ * @param {Function} props.show
2290
+ * @param {Function} props.example
2291
+ * @param {Function} props.variables
2292
+ * @param {Function} props.onFocus
2293
+ * @param {Function} props.onBlur
2294
+ */
2295
+ function FeelNumberEntry(props) {
2296
+ return jsxRuntime.jsx(FeelEntry, {
2297
+ class: "bio-properties-panel-feel-number",
2298
+ OptionalComponent: OptionalFeelNumberField,
2299
+ ...props
2300
+ });
2301
+ }
2302
+
2064
2303
  /**
2065
2304
  * @param {Object} props
2066
2305
  * @param {Object} props.element
@@ -2170,7 +2409,7 @@ function FeelTemplatingEntry(props) {
2170
2409
  ...props
2171
2410
  });
2172
2411
  }
2173
- function isEdited$6(node) {
2412
+ function isEdited$5(node) {
2174
2413
  if (!node) {
2175
2414
  return false;
2176
2415
  }
@@ -2182,7 +2421,7 @@ function isEdited$6(node) {
2182
2421
 
2183
2422
  // helpers /////////////////
2184
2423
 
2185
- function prefixId$5(id) {
2424
+ function prefixId$4(id) {
2186
2425
  return `bio-properties-panel-${id}`;
2187
2426
  }
2188
2427
 
@@ -2349,7 +2588,7 @@ function Templating(props) {
2349
2588
  })]
2350
2589
  });
2351
2590
  }
2352
- function isEdited$5(node) {
2591
+ function isEdited$4(node) {
2353
2592
  return node && (!!node.value || node.classList.contains('edited'));
2354
2593
  }
2355
2594
 
@@ -2542,163 +2781,6 @@ function useNewItems(items = [], shouldReset) {
2542
2781
  return previousItems ? items.filter(item => !previousItems.includes(item)) : [];
2543
2782
  }
2544
2783
 
2545
- function NumberField(props) {
2546
- const {
2547
- debounce,
2548
- disabled,
2549
- id,
2550
- label,
2551
- max,
2552
- min,
2553
- onInput,
2554
- step,
2555
- value = '',
2556
- onFocus,
2557
- onBlur
2558
- } = props;
2559
- const [localValue, setLocalValue] = hooks.useState(value);
2560
- const handleInputCallback = hooks.useMemo(() => {
2561
- return debounce(event => {
2562
- const {
2563
- validity,
2564
- value
2565
- } = event.target;
2566
- if (validity.valid) {
2567
- onInput(value ? parseFloat(value) : undefined);
2568
- }
2569
- });
2570
- }, [onInput, debounce]);
2571
- const handleInput = e => {
2572
- handleInputCallback(e);
2573
- setLocalValue(e.target.value);
2574
- };
2575
- hooks.useEffect(() => {
2576
- if (value === localValue) {
2577
- return;
2578
- }
2579
- setLocalValue(value);
2580
- }, [value]);
2581
- return jsxRuntime.jsxs("div", {
2582
- class: "bio-properties-panel-numberfield",
2583
- children: [jsxRuntime.jsx("label", {
2584
- for: prefixId$4(id),
2585
- class: "bio-properties-panel-label",
2586
- children: label
2587
- }), jsxRuntime.jsx("input", {
2588
- id: prefixId$4(id),
2589
- type: "number",
2590
- name: id,
2591
- spellCheck: "false",
2592
- autoComplete: "off",
2593
- disabled: disabled,
2594
- class: "bio-properties-panel-input",
2595
- max: max,
2596
- min: min,
2597
- onInput: handleInput,
2598
- onFocus: onFocus,
2599
- onBlur: onBlur,
2600
- step: step,
2601
- value: localValue
2602
- })]
2603
- });
2604
- }
2605
-
2606
- /**
2607
- * @param {Object} props
2608
- * @param {Boolean} props.debounce
2609
- * @param {String} props.description
2610
- * @param {Boolean} props.disabled
2611
- * @param {Object} props.element
2612
- * @param {Function} props.getValue
2613
- * @param {String} props.id
2614
- * @param {String} props.label
2615
- * @param {String} props.max
2616
- * @param {String} props.min
2617
- * @param {Function} props.setValue
2618
- * @param {Function} props.onFocus
2619
- * @param {Function} props.onBlur
2620
- * @param {String} props.step
2621
- * @param {Function} props.validate
2622
- */
2623
- function NumberFieldEntry(props) {
2624
- const {
2625
- debounce,
2626
- description,
2627
- disabled,
2628
- element,
2629
- getValue,
2630
- id,
2631
- label,
2632
- max,
2633
- min,
2634
- setValue,
2635
- step,
2636
- onFocus,
2637
- onBlur,
2638
- validate
2639
- } = props;
2640
- const [cachedInvalidValue, setCachedInvalidValue] = hooks.useState(null);
2641
- const globalError = useError(id);
2642
- const [localError, setLocalError] = hooks.useState(null);
2643
- let value = getValue(element);
2644
- const previousValue = usePrevious(value);
2645
- hooks.useEffect(() => {
2646
- if (minDash.isFunction(validate)) {
2647
- const newValidationError = validate(value) || null;
2648
- setLocalError(newValidationError);
2649
- }
2650
- }, [value]);
2651
- const onInput = newValue => {
2652
- let newValidationError = null;
2653
- if (minDash.isFunction(validate)) {
2654
- newValidationError = validate(newValue) || null;
2655
- }
2656
- if (newValidationError) {
2657
- setCachedInvalidValue(newValue);
2658
- } else {
2659
- setValue(newValue);
2660
- }
2661
- setLocalError(newValidationError);
2662
- };
2663
- if (previousValue === value && localError) {
2664
- value = cachedInvalidValue;
2665
- }
2666
- const error = globalError || localError;
2667
- return jsxRuntime.jsxs("div", {
2668
- class: classnames__default["default"]('bio-properties-panel-entry', error ? 'has-error' : ''),
2669
- "data-entry-id": id,
2670
- children: [jsxRuntime.jsx(NumberField, {
2671
- debounce: debounce,
2672
- disabled: disabled,
2673
- id: id,
2674
- label: label,
2675
- onFocus: onFocus,
2676
- onBlur: onBlur,
2677
- onInput: onInput,
2678
- max: max,
2679
- min: min,
2680
- step: step,
2681
- value: value
2682
- }, element), error && jsxRuntime.jsx("div", {
2683
- class: "bio-properties-panel-error",
2684
- children: error
2685
- }), jsxRuntime.jsx(Description, {
2686
- forId: id,
2687
- element: element,
2688
- value: description
2689
- })]
2690
- });
2691
- }
2692
- function isEdited$4(node) {
2693
- return node && !!node.value;
2694
- }
2695
-
2696
- // helpers /////////////////
2697
-
2698
- function prefixId$4(id) {
2699
- return `bio-properties-panel-${id}`;
2700
- }
2701
-
2702
2784
  function Select(props) {
2703
2785
  const {
2704
2786
  id,
@@ -3238,6 +3320,7 @@ exports.ExternalLinkIcon = ExternalLinkIcon;
3238
3320
  exports.FeelCheckboxEntry = FeelCheckboxEntry;
3239
3321
  exports.FeelEntry = FeelEntry;
3240
3322
  exports.FeelIcon = FeelIcon$1;
3323
+ exports.FeelNumberEntry = FeelNumberEntry;
3241
3324
  exports.FeelTemplatingEntry = FeelTemplatingEntry;
3242
3325
  exports.FeelTextAreaEntry = FeelTextAreaEntry;
3243
3326
  exports.FeelToggleSwitchEntry = FeelToggleSwitchEntry;
@@ -3259,11 +3342,11 @@ exports.TextAreaEntry = TextAreaEntry;
3259
3342
  exports.TextFieldEntry = TextfieldEntry;
3260
3343
  exports.ToggleSwitchEntry = ToggleSwitchEntry;
3261
3344
  exports.isCheckboxEntryEdited = isEdited$8;
3262
- exports.isFeelEntryEdited = isEdited$6;
3263
- exports.isNumberFieldEntryEdited = isEdited$4;
3345
+ exports.isFeelEntryEdited = isEdited$5;
3346
+ exports.isNumberFieldEntryEdited = isEdited$6;
3264
3347
  exports.isSelectEntryEdited = isEdited$3;
3265
3348
  exports.isSimpleEntryEdited = isEdited$2;
3266
- exports.isTemplatingEntryEdited = isEdited$5;
3349
+ exports.isTemplatingEntryEdited = isEdited$4;
3267
3350
  exports.isTextAreaEntryEdited = isEdited$1;
3268
3351
  exports.isTextFieldEntryEdited = isEdited;
3269
3352
  exports.isToggleSwitchEntryEdited = isEdited$7;