@bpmn-io/properties-panel 1.6.1 → 1.7.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
@@ -9,8 +9,8 @@ var compat = require('../preact/compat');
9
9
  var jsxRuntime = require('../preact/jsx-runtime');
10
10
  var minDom = require('min-dom');
11
11
  var preact = require('../preact');
12
- var FeelEditor = require('@bpmn-io/feel-editor');
13
12
  var feelers = require('feelers');
13
+ var FeelEditor = require('@bpmn-io/feel-editor');
14
14
 
15
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
16
 
@@ -319,15 +319,10 @@ function useLayoutState(path, defaultValue) {
319
319
  setLayoutForKey
320
320
  } = hooks.useContext(LayoutContext);
321
321
  const layoutForKey = getLayoutForKey(path, defaultValue);
322
- const [value, set] = hooks.useState(layoutForKey);
323
- const setState = newValue => {
324
- // (1) set component state
325
- set(newValue);
326
-
327
- // (2) set context
322
+ const setState = hooks.useCallback(newValue => {
328
323
  setLayoutForKey(path, newValue);
329
- };
330
- return [value, setState];
324
+ }, [setLayoutForKey]);
325
+ return [layoutForKey, setState];
331
326
  }
332
327
 
333
328
  /**
@@ -643,15 +638,21 @@ function PropertiesPanel(props) {
643
638
  headerProvider,
644
639
  placeholderProvider,
645
640
  groups,
646
- layoutConfig = {},
641
+ layoutConfig,
647
642
  layoutChanged,
648
- descriptionConfig = {},
643
+ descriptionConfig,
649
644
  descriptionLoaded,
650
645
  eventBus
651
646
  } = props;
652
647
 
653
648
  // set-up layout context
654
649
  const [layout, setLayout] = hooks.useState(createLayout(layoutConfig));
650
+
651
+ // react to external changes in the layout config
652
+ useUpdateEffect(() => {
653
+ const newLayout = createLayout(layoutConfig);
654
+ setLayout(newLayout);
655
+ }, [layoutConfig]);
655
656
  hooks.useEffect(() => {
656
657
  if (typeof layoutChanged === 'function') {
657
658
  layoutChanged(layout);
@@ -673,10 +674,12 @@ function PropertiesPanel(props) {
673
674
  };
674
675
 
675
676
  // set-up description context
676
- const description = createDescriptionContext(descriptionConfig);
677
- if (typeof descriptionLoaded === 'function') {
678
- descriptionLoaded(description);
679
- }
677
+ const description = hooks.useMemo(() => createDescriptionContext(descriptionConfig), [descriptionConfig]);
678
+ hooks.useEffect(() => {
679
+ if (typeof descriptionLoaded === 'function') {
680
+ descriptionLoaded(description);
681
+ }
682
+ }, [description, descriptionLoaded]);
680
683
  const getDescriptionForId = (id, element) => {
681
684
  return description[id] && description[id](element);
682
685
  };
@@ -751,19 +754,38 @@ function PropertiesPanel(props) {
751
754
 
752
755
  // helpers //////////////////
753
756
 
754
- function createLayout(overrides) {
757
+ function createLayout(overrides = {}, defaults = DEFAULT_LAYOUT) {
755
758
  return {
756
- ...DEFAULT_LAYOUT,
759
+ ...defaults,
757
760
  ...overrides
758
761
  };
759
762
  }
760
- function createDescriptionContext(overrides) {
763
+ function createDescriptionContext(overrides = {}) {
761
764
  return {
762
765
  ...DEFAULT_DESCRIPTION,
763
766
  ...overrides
764
767
  };
765
768
  }
766
769
 
770
+ // hooks //////////////////
771
+
772
+ /**
773
+ * This hook behaves like useEffect, but does not trigger on the first render.
774
+ *
775
+ * @param {Function} effect
776
+ * @param {Array} deps
777
+ */
778
+ function useUpdateEffect(effect, deps) {
779
+ const isMounted = hooks.useRef(false);
780
+ hooks.useEffect(() => {
781
+ if (isMounted.current) {
782
+ return effect();
783
+ } else {
784
+ isMounted.current = true;
785
+ }
786
+ }, deps);
787
+ }
788
+
767
789
  function DropdownButton(props) {
768
790
  const {
769
791
  class: className,
@@ -1298,6 +1320,88 @@ const useBufferedFocus$1 = function (editor, ref) {
1298
1320
  }, [editor, buffer]);
1299
1321
  };
1300
1322
  const CodeEditor$1 = compat.forwardRef((props, ref) => {
1323
+ const {
1324
+ onInput,
1325
+ disabled,
1326
+ tooltipContainer,
1327
+ enableGutters,
1328
+ value,
1329
+ onLint = () => {},
1330
+ contentAttributes = {},
1331
+ hostLanguage = null,
1332
+ singleLine = false
1333
+ } = props;
1334
+ const inputRef = hooks.useRef();
1335
+ const [editor, setEditor] = hooks.useState();
1336
+ const [localValue, setLocalValue] = hooks.useState(value || '');
1337
+ useBufferedFocus$1(editor, ref);
1338
+ const handleInput = useStaticCallback(newValue => {
1339
+ onInput(newValue);
1340
+ setLocalValue(newValue);
1341
+ });
1342
+ hooks.useEffect(() => {
1343
+ let editor;
1344
+ editor = new feelers.FeelersEditor({
1345
+ container: inputRef.current,
1346
+ onChange: handleInput,
1347
+ value: localValue,
1348
+ onLint,
1349
+ contentAttributes,
1350
+ tooltipContainer,
1351
+ enableGutters,
1352
+ hostLanguage,
1353
+ singleLine
1354
+ });
1355
+ setEditor(editor);
1356
+ return () => {
1357
+ onLint([]);
1358
+ inputRef.current.innerHTML = '';
1359
+ setEditor(null);
1360
+ };
1361
+ }, []);
1362
+ hooks.useEffect(() => {
1363
+ if (!editor) {
1364
+ return;
1365
+ }
1366
+ if (value === localValue) {
1367
+ return;
1368
+ }
1369
+ editor.setValue(value);
1370
+ setLocalValue(value);
1371
+ }, [value]);
1372
+ const handleClick = () => {
1373
+ ref.current.focus();
1374
+ };
1375
+ return jsxRuntime.jsx("div", {
1376
+ name: props.name,
1377
+ class: classnames__default["default"]('bio-properties-panel-feelers-editor bio-properties-panel-input', localValue ? 'edited' : null, disabled ? 'disabled' : null),
1378
+ ref: inputRef,
1379
+ onClick: handleClick
1380
+ });
1381
+ });
1382
+
1383
+ const useBufferedFocus = function (editor, ref) {
1384
+ const [buffer, setBuffer] = hooks.useState(undefined);
1385
+ ref.current = hooks.useMemo(() => ({
1386
+ focus: offset => {
1387
+ if (editor) {
1388
+ editor.focus(offset);
1389
+ } else {
1390
+ if (typeof offset === 'undefined') {
1391
+ offset = Infinity;
1392
+ }
1393
+ setBuffer(offset);
1394
+ }
1395
+ }
1396
+ }), [editor]);
1397
+ hooks.useEffect(() => {
1398
+ if (typeof buffer !== 'undefined' && editor) {
1399
+ editor.focus(buffer);
1400
+ setBuffer(false);
1401
+ }
1402
+ }, [editor, buffer]);
1403
+ };
1404
+ const CodeEditor = compat.forwardRef((props, ref) => {
1301
1405
  const {
1302
1406
  value,
1303
1407
  onInput,
@@ -1310,7 +1414,7 @@ const CodeEditor$1 = compat.forwardRef((props, ref) => {
1310
1414
  const inputRef = hooks.useRef();
1311
1415
  const [editor, setEditor] = hooks.useState();
1312
1416
  const [localValue, setLocalValue] = hooks.useState(value || '');
1313
- useBufferedFocus$1(editor, ref);
1417
+ useBufferedFocus(editor, ref);
1314
1418
  const handleInput = useStaticCallback(newValue => {
1315
1419
  onInput(newValue);
1316
1420
  setLocalValue(newValue);
@@ -1566,7 +1670,7 @@ function FeelTextfield(props) {
1566
1670
  active: feelActive,
1567
1671
  disabled: feel !== 'optional' || disabled,
1568
1672
  onClick: handleFeelToggle
1569
- }), feelActive ? jsxRuntime.jsx(CodeEditor$1, {
1673
+ }), feelActive ? jsxRuntime.jsx(CodeEditor, {
1570
1674
  id: prefixId$6(id),
1571
1675
  name: id,
1572
1676
  onInput: handleLocalInput,
@@ -1583,6 +1687,9 @@ function FeelTextfield(props) {
1583
1687
  }) : jsxRuntime.jsx(OptionalComponent, {
1584
1688
  ...props,
1585
1689
  onInput: handleLocalInput,
1690
+ contentAttributes: {
1691
+ 'id': prefixId$6(id)
1692
+ },
1586
1693
  value: localValue,
1587
1694
  ref: editorRef
1588
1695
  })]
@@ -1703,6 +1810,8 @@ function FeelEntry(props) {
1703
1810
  getValue,
1704
1811
  setValue,
1705
1812
  tooltipContainer,
1813
+ hostLanguage,
1814
+ singleLine,
1706
1815
  validate,
1707
1816
  show = noop$1,
1708
1817
  example,
@@ -1758,6 +1867,8 @@ function FeelEntry(props) {
1758
1867
  onFocus: onFocus,
1759
1868
  onBlur: onBlur,
1760
1869
  example: example,
1870
+ hostLanguage: hostLanguage,
1871
+ singleLine: singleLine,
1761
1872
  show: show,
1762
1873
  value: value,
1763
1874
  variables: variables,
@@ -1793,13 +1904,42 @@ function FeelEntry(props) {
1793
1904
  * @param {Function} props.onFocus
1794
1905
  * @param {Function} props.onBlur
1795
1906
  */
1796
- function FeelTextArea(props) {
1907
+ function FeelTextAreaEntry(props) {
1797
1908
  return jsxRuntime.jsx(FeelEntry, {
1798
1909
  class: "bio-properties-panel-feel-textarea",
1799
1910
  OptionalComponent: OptionalFeelTextArea,
1800
1911
  ...props
1801
1912
  });
1802
1913
  }
1914
+
1915
+ /**
1916
+ * @param {Object} props
1917
+ * @param {Object} props.element
1918
+ * @param {String} props.id
1919
+ * @param {String} props.description
1920
+ * @param {String} props.hostLanguage
1921
+ * @param {Boolean} props.singleLine
1922
+ * @param {Boolean} props.debounce
1923
+ * @param {Boolean} props.disabled
1924
+ * @param {Boolean} props.feel
1925
+ * @param {String} props.label
1926
+ * @param {Function} props.getValue
1927
+ * @param {Function} props.setValue
1928
+ * @param {Function} props.tooltipContainer
1929
+ * @param {Function} props.validate
1930
+ * @param {Function} props.show
1931
+ * @param {Function} props.example
1932
+ * @param {Function} props.variables
1933
+ * @param {Function} props.onFocus
1934
+ * @param {Function} props.onBlur
1935
+ */
1936
+ function FeelTemplatingEntry(props) {
1937
+ return jsxRuntime.jsx(FeelEntry, {
1938
+ class: "bio-properties-panel-feel-templating",
1939
+ OptionalComponent: CodeEditor$1,
1940
+ ...props
1941
+ });
1942
+ }
1803
1943
  function isEdited$7(node) {
1804
1944
  return node && (!!node.value || node.classList.contains('edited'));
1805
1945
  }
@@ -1810,86 +1950,6 @@ function prefixId$6(id) {
1810
1950
  return `bio-properties-panel-${id}`;
1811
1951
  }
1812
1952
 
1813
- const useBufferedFocus = function (editor, ref) {
1814
- const [buffer, setBuffer] = hooks.useState(undefined);
1815
- ref.current = hooks.useMemo(() => ({
1816
- focus: offset => {
1817
- if (editor) {
1818
- editor.focus(offset);
1819
- } else {
1820
- if (typeof offset === 'undefined') {
1821
- offset = Infinity;
1822
- }
1823
- setBuffer(offset);
1824
- }
1825
- }
1826
- }), [editor]);
1827
- hooks.useEffect(() => {
1828
- if (typeof buffer !== 'undefined' && editor) {
1829
- editor.focus(buffer);
1830
- setBuffer(false);
1831
- }
1832
- }, [editor, buffer]);
1833
- };
1834
- const CodeEditor = compat.forwardRef((props, ref) => {
1835
- const {
1836
- value,
1837
- onInput,
1838
- onLint = () => {},
1839
- contentAttributes = {},
1840
- disabled,
1841
- tooltipContainer,
1842
- useGutters = false,
1843
- darkMode = false
1844
- } = props;
1845
- const inputRef = hooks.useRef();
1846
- const [editor, setEditor] = hooks.useState();
1847
- const [localValue, setLocalValue] = hooks.useState(value || '');
1848
- useBufferedFocus(editor, ref);
1849
- const handleInput = useStaticCallback(newValue => {
1850
- onInput(newValue);
1851
- setLocalValue(newValue);
1852
- });
1853
- hooks.useEffect(() => {
1854
- let editor;
1855
- editor = new feelers.FeelersEditor({
1856
- container: inputRef.current,
1857
- onChange: handleInput,
1858
- onLint: onLint,
1859
- contentAttributes: contentAttributes,
1860
- tooltipContainer: tooltipContainer,
1861
- value: localValue,
1862
- darkMode: darkMode,
1863
- enableGutters: useGutters
1864
- });
1865
- setEditor(editor);
1866
- return () => {
1867
- onLint([]);
1868
- inputRef.current.innerHTML = '';
1869
- setEditor(null);
1870
- };
1871
- }, []);
1872
- hooks.useEffect(() => {
1873
- if (!editor) {
1874
- return;
1875
- }
1876
- if (value === localValue) {
1877
- return;
1878
- }
1879
- editor.setValue(value);
1880
- setLocalValue(value);
1881
- }, [value]);
1882
- const handleClick = () => {
1883
- ref.current.focus();
1884
- };
1885
- return jsxRuntime.jsx("div", {
1886
- name: props.name,
1887
- class: classnames__default["default"]('bio-properties-panel-feelers-editor bio-properties-panel-input', localValue ? 'edited' : null, disabled ? 'disabled' : null),
1888
- ref: inputRef,
1889
- onClick: handleClick
1890
- });
1891
- });
1892
-
1893
1953
  const noop = () => {};
1894
1954
 
1895
1955
  /**
@@ -1906,7 +1966,7 @@ const noop = () => {};
1906
1966
  * @param {Function} props.validate
1907
1967
  * @param {Function} props.show
1908
1968
  */
1909
- function FeelTemplatingEntry(props) {
1969
+ function TemplatingEntry(props) {
1910
1970
  const {
1911
1971
  element,
1912
1972
  id,
@@ -1957,7 +2017,7 @@ function FeelTemplatingEntry(props) {
1957
2017
  return jsxRuntime.jsxs("div", {
1958
2018
  class: classnames__default["default"]('bio-properties-panel-entry', error ? 'has-error' : ''),
1959
2019
  "data-entry-id": id,
1960
- children: [jsxRuntime.jsx(FeelTemplating, {
2020
+ children: [jsxRuntime.jsx(Templating, {
1961
2021
  debounce: debounce,
1962
2022
  disabled: disabled,
1963
2023
  id: id,
@@ -1977,7 +2037,7 @@ function FeelTemplatingEntry(props) {
1977
2037
  })]
1978
2038
  });
1979
2039
  }
1980
- function FeelTemplating(props) {
2040
+ function Templating(props) {
1981
2041
  const {
1982
2042
  debounce,
1983
2043
  id,
@@ -2038,7 +2098,7 @@ function FeelTemplating(props) {
2038
2098
  }), jsxRuntime.jsx("div", {
2039
2099
  class: "bio-properties-panel-feelers-input",
2040
2100
  ref: containerRef,
2041
- children: jsxRuntime.jsx(CodeEditor, {
2101
+ children: jsxRuntime.jsx(CodeEditor$1, {
2042
2102
  name: id,
2043
2103
  onInput: handleInput,
2044
2104
  contentAttributes: {
@@ -2047,7 +2107,6 @@ function FeelTemplating(props) {
2047
2107
  disabled: disabled,
2048
2108
  onLint: handleLint,
2049
2109
  value: localValue,
2050
- useGutters: false,
2051
2110
  ref: editorRef,
2052
2111
  tooltipContainer: tooltipContainer
2053
2112
  })
@@ -3024,7 +3083,7 @@ exports.FeelEntry = FeelEntry;
3024
3083
  exports.FeelOptionalIcon = FeelOptionalIcon;
3025
3084
  exports.FeelRequiredIcon = FeelRequiredIcon;
3026
3085
  exports.FeelTemplatingEntry = FeelTemplatingEntry;
3027
- exports.FeelTextAreaEntry = FeelTextArea;
3086
+ exports.FeelTextAreaEntry = FeelTextAreaEntry;
3028
3087
  exports.Group = Group;
3029
3088
  exports.Header = Header;
3030
3089
  exports.HeaderButton = HeaderButton;
@@ -3038,15 +3097,16 @@ exports.PropertiesPanel = PropertiesPanel;
3038
3097
  exports.PropertiesPanelContext = LayoutContext;
3039
3098
  exports.SelectEntry = SelectEntry;
3040
3099
  exports.SimpleEntry = Simple;
3100
+ exports.TemplatingEntry = TemplatingEntry;
3041
3101
  exports.TextAreaEntry = TextAreaEntry;
3042
3102
  exports.TextFieldEntry = TextfieldEntry;
3043
3103
  exports.ToggleSwitchEntry = ToggleSwitchEntry;
3044
3104
  exports.isCheckboxEntryEdited = isEdited$8;
3045
3105
  exports.isFeelEntryEdited = isEdited$7;
3046
- exports.isFeelTemplatingEntryEdited = isEdited$6;
3047
3106
  exports.isNumberFieldEntryEdited = isEdited$5;
3048
3107
  exports.isSelectEntryEdited = isEdited$4;
3049
3108
  exports.isSimpleEntryEdited = isEdited$3;
3109
+ exports.isTemplatingEntryEdited = isEdited$6;
3050
3110
  exports.isTextAreaEntryEdited = isEdited$2;
3051
3111
  exports.isTextFieldEntryEdited = isEdited$1;
3052
3112
  exports.isToggleSwitchEntryEdited = isEdited;