@bpmn-io/properties-panel 0.4.1 → 0.5.1
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/CHANGELOG.md +22 -0
- package/assets/properties-panel.css +351 -129
- package/lib/PropertiesPanel.js +9 -4
- package/lib/PropertiesPanel.js.map +1 -1
- package/lib/components/Group.js +10 -24
- package/lib/components/Group.js.map +1 -1
- package/lib/components/Header.js +6 -6
- package/lib/components/Header.js.map +1 -1
- package/lib/components/ListGroup.js +40 -33
- package/lib/components/ListGroup.js.map +1 -1
- package/lib/components/ListItem.js +6 -1
- package/lib/components/ListItem.js.map +1 -1
- package/lib/components/entries/Checkbox.js +9 -4
- package/lib/components/entries/Checkbox.js.map +1 -1
- package/lib/components/entries/Collapsible.js +8 -5
- package/lib/components/entries/Collapsible.js.map +1 -1
- package/lib/components/entries/List.js +31 -23
- package/lib/components/entries/List.js.map +1 -1
- package/lib/components/entries/ToggleSwitch.js +1 -1
- package/lib/components/entries/ToggleSwitch.js.map +1 -1
- package/lib/components/icons/index.js +18 -33
- package/lib/context/LayoutContext.js +1 -0
- package/lib/context/LayoutContext.js.map +1 -1
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useLayoutState.js +36 -0
- package/lib/hooks/useLayoutState.js.map +1 -0
- package/package.json +2 -2
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'preact/hooks';
|
|
2
2
|
import { query as domQuery } from 'min-dom';
|
|
3
|
+
import { isFunction } from 'min-dash';
|
|
3
4
|
import { useKeyFactory, usePrevious } from '../../hooks';
|
|
4
5
|
import classnames from 'classnames';
|
|
5
|
-
import {
|
|
6
|
+
import { ArrowIcon, CreateIcon, DeleteIcon } from '../icons';
|
|
6
7
|
/**
|
|
7
8
|
* Entry for handling lists represented as nested entries.
|
|
8
9
|
*
|
|
@@ -16,7 +17,7 @@ import { CreateIcon, GroupArrowIcon, ListDeleteIcon } from '../icons';
|
|
|
16
17
|
* @param {Function} [props.onRemove]
|
|
17
18
|
* @param {Item[]} [props.items]
|
|
18
19
|
* @param {boolean} [props.open]
|
|
19
|
-
* @param {string} [props.autoFocusEntry]
|
|
20
|
+
* @param {string|boolean} [props.autoFocusEntry] either a custom selector string or true to focus the first input
|
|
20
21
|
* @param {(a: Item, b: Item) => -1 | 0 | 1} [props.compareFn]
|
|
21
22
|
* @returns
|
|
22
23
|
*/
|
|
@@ -66,26 +67,32 @@ export default function List(props) {
|
|
|
66
67
|
|
|
67
68
|
return _jsxs("div", {
|
|
68
69
|
"data-entry-id": id,
|
|
69
|
-
class: classnames('bio-properties-panel-entry', 'bio-properties-panel-list-entry', open ? 'open' : ''),
|
|
70
|
+
class: classnames('bio-properties-panel-entry', 'bio-properties-panel-list-entry', hasItems ? '' : 'empty', open ? 'open' : ''),
|
|
70
71
|
children: [_jsxs("div", {
|
|
71
72
|
class: "bio-properties-panel-list-entry-header",
|
|
72
73
|
onClick: toggleOpen,
|
|
73
74
|
children: [_jsx("div", {
|
|
74
|
-
title:
|
|
75
|
+
title: label,
|
|
75
76
|
class: classnames('bio-properties-panel-list-entry-header-title', open && 'open'),
|
|
76
77
|
children: label
|
|
77
78
|
}), _jsxs("div", {
|
|
78
79
|
class: "bio-properties-panel-list-entry-header-buttons",
|
|
79
|
-
children: [
|
|
80
|
+
children: [_jsxs("button", {
|
|
81
|
+
title: "Create new list item",
|
|
80
82
|
onClick: addItem,
|
|
81
83
|
class: "bio-properties-panel-add-entry",
|
|
82
|
-
children: _jsx(CreateIcon, {})
|
|
84
|
+
children: [_jsx(CreateIcon, {}), !hasItems ? _jsx("div", {
|
|
85
|
+
class: "bio-properties-panel-add-entry-label",
|
|
86
|
+
children: "Create"
|
|
87
|
+
}) : null]
|
|
83
88
|
}), hasItems && _jsx("div", {
|
|
89
|
+
title: `List contains ${items.length} item${items.length != 1 ? 's' : ''}`,
|
|
84
90
|
class: "bio-properties-panel-list-badge",
|
|
85
91
|
children: items.length
|
|
86
92
|
}), hasItems && _jsx("button", {
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
title: "Toggle list item",
|
|
94
|
+
class: "bio-properties-panel-arrow",
|
|
95
|
+
children: _jsx(ArrowIcon, {
|
|
89
96
|
class: open ? 'bio-properties-panel-arrow-down' : 'bio-properties-panel-arrow-right'
|
|
90
97
|
})
|
|
91
98
|
})]
|
|
@@ -116,11 +123,18 @@ function ItemsList(props) {
|
|
|
116
123
|
const newItem = newItems[0];
|
|
117
124
|
useEffect(() => {
|
|
118
125
|
if (newItem && autoFocusEntry) {
|
|
119
|
-
|
|
120
|
-
const
|
|
126
|
+
// (0) select the parent entry (containing all list items)
|
|
127
|
+
const entry = domQuery(`[data-entry-id="${id}"]`); // (1) select the first input or a custom element to be focussed
|
|
128
|
+
|
|
129
|
+
const selector = typeof autoFocusEntry === 'boolean' ? '.bio-properties-panel-input' : autoFocusEntry;
|
|
130
|
+
const focusableInput = domQuery(selector, entry); // (2) set focus
|
|
121
131
|
|
|
122
132
|
if (focusableInput) {
|
|
123
|
-
focusableInput.
|
|
133
|
+
if (isFunction(focusableInput.select)) {
|
|
134
|
+
focusableInput.select();
|
|
135
|
+
} else if (isFunction(focusableInput.focus)) {
|
|
136
|
+
focusableInput.focus();
|
|
137
|
+
}
|
|
124
138
|
}
|
|
125
139
|
}
|
|
126
140
|
}, [newItem, autoFocusEntry, id]);
|
|
@@ -132,22 +146,15 @@ function ItemsList(props) {
|
|
|
132
146
|
class: "bio-properties-panel-list-entry-item",
|
|
133
147
|
children: [renderItem(item, index, item === newItem), onRemove && _jsx("button", {
|
|
134
148
|
type: "button",
|
|
135
|
-
|
|
149
|
+
title: "Delete item",
|
|
150
|
+
class: "bio-properties-panel-remove-entry bio-properties-panel-remove-list-entry",
|
|
136
151
|
onClick: () => onRemove && onRemove(item),
|
|
137
|
-
children: _jsx(
|
|
152
|
+
children: _jsx(DeleteIcon, {})
|
|
138
153
|
})]
|
|
139
154
|
}, key);
|
|
140
155
|
})
|
|
141
156
|
});
|
|
142
157
|
}
|
|
143
|
-
|
|
144
|
-
function getTitle(label, items) {
|
|
145
|
-
if (!items.length) {
|
|
146
|
-
return label;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return `${label} (${items.length} items)`;
|
|
150
|
-
}
|
|
151
158
|
/**
|
|
152
159
|
* Place new items in the beginning of the list and sort the rest with provided function.
|
|
153
160
|
*
|
|
@@ -169,11 +176,12 @@ function useSortedItems(currentItems, compareFn, shouldReset = false) {
|
|
|
169
176
|
itemsRef.current.sort(compareFn);
|
|
170
177
|
}
|
|
171
178
|
} else {
|
|
172
|
-
const items = itemsRef.current; // (2)
|
|
179
|
+
const items = itemsRef.current; // (2) Add new item to the list.
|
|
173
180
|
|
|
174
181
|
for (const item of currentItems) {
|
|
175
182
|
if (!items.includes(item)) {
|
|
176
|
-
|
|
183
|
+
// Unshift or push depending on whether we have a compareFn
|
|
184
|
+
compareFn ? items.unshift(item) : items.push(item);
|
|
177
185
|
}
|
|
178
186
|
} // (3) Filter out removed items.
|
|
179
187
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/entries/List.js"],"names":["useEffect","useRef","useState","query","domQuery","useKeyFactory","usePrevious","classnames","CreateIcon","GroupArrowIcon","ListDeleteIcon","List","props","id","element","items","renderItem","label","open","shouldOpen","onAdd","onRemove","autoFocusEntry","compareFn","setOpen","hasItems","length","toggleOpen","opening","elementChanged","shouldReset","sortedItems","useSortedItems","newItems","useNewItems","addItem","event","stopPropagation","getTitle","ItemsList","getKey","newItem","entry","focusableInput","focus","map","item","index","key","currentItems","itemsRef","slice","current","sort","includes","unshift","filter","previousItems"],"mappings":"AAAA,SACEA,SADF,EAEEC,MAFF,EAGEC,QAHF,QAIO,cAJP;AAMA,SACEC,KAAK,IAAIC,QADX,QAEO,SAFP;AAIA,SACEC,aADF,EAEEC,WAFF,QAGO,aAHP;AAKA,OAAOC,UAAP,MAAuB,Y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J,EAAiB;AACf,WAAO,EAAP;AACD;;AAED,SAAO2B,aAAa,GAAG1C,KAAK,CAACyC,MAAN,CAAaV,IAAI,IAAI,CAACW,aAAa,CAACH,QAAd,CAAuBR,IAAvB,CAAtB,CAAH,GAAyD,EAA7E;AACD","sourcesContent":["import {\n useEffect,\n useRef,\n useState\n} from 'preact/hooks';\n\nimport {\n query as domQuery\n} from 'min-dom';\n\nimport {\n useKeyFactory,\n usePrevious\n} from '../../hooks';\n\nimport classnames from 'classnames';\n\nimport {\n CreateIcon,\n GroupArrowIcon,\n ListDeleteIcon\n} from '../icons';\n\n/**\n * Entry for handling lists represented as nested entries.\n *\n * @template Item\n * @param {object} props\n * @param {string} props.id\n * @param {*} props.element\n * @param {Function} props.onAdd\n * @param {(item: Item, index: number, isNew: boolean) => JSX.Element} props.renderItem\n * @param {string} [props.label='<empty>']\n * @param {Function} [props.onRemove]\n * @param {Item[]} [props.items]\n * @param {boolean} [props.open]\n * @param {string} [props.autoFocusEntry]\n * @param {(a: Item, b: Item) => -1 | 0 | 1} [props.compareFn]\n * @returns\n */\nexport default function List(props) {\n const {\n id,\n element,\n items = [],\n renderItem,\n label = '<empty>',\n open: shouldOpen,\n onAdd,\n onRemove,\n autoFocusEntry,\n compareFn\n } = props;\n\n const [ open, setOpen ] = useState(!!shouldOpen);\n\n const hasItems = !!items.length;\n const toggleOpen = () => hasItems && setOpen(!open);\n\n const opening = !usePrevious(open) && open;\n const elementChanged = usePrevious(element) !== element;\n const shouldReset = opening || elementChanged;\n const sortedItems = useSortedItems(items, compareFn, shouldReset);\n\n const newItems = useNewItems(items, elementChanged);\n\n useEffect(() => {\n if (open && !hasItems) {\n setOpen(false);\n }\n }, [ open, hasItems ]);\n\n /**\n * @param {MouseEvent} event\n */\n function addItem(event) {\n event.stopPropagation();\n onAdd();\n\n if (!open) {\n setOpen(true);\n }\n }\n\n return (\n <div\n data-entry-id={ id }\n class={ classnames(\n 'bio-properties-panel-entry',\n 'bio-properties-panel-list-entry',\n open ? 'open' : ''\n ) }>\n <div class=\"bio-properties-panel-list-entry-header\" onClick={ toggleOpen }>\n <div\n title={ getTitle(label, items) }\n class={ classnames(\n 'bio-properties-panel-list-entry-header-title',\n open && 'open'\n ) }>\n { label }\n </div>\n <div\n class=\"bio-properties-panel-list-entry-header-buttons\"\n >\n <button onClick={ addItem } class=\"bio-properties-panel-add-entry\">\n <CreateIcon />\n </button>\n {\n hasItems && (\n <div class=\"bio-properties-panel-list-badge\">\n { items.length }\n </div>\n )\n }\n {\n hasItems && (\n <button class=\"bio-properties-panel-list-entry-arrow\">\n <GroupArrowIcon class={ open ? 'bio-properties-panel-arrow-down' : 'bio-properties-panel-arrow-right' } />\n </button>\n )\n }\n </div>\n </div>\n {\n hasItems && (\n <ItemsList\n autoFocusEntry={ autoFocusEntry }\n id={ id }\n open={ open }\n items={ sortedItems }\n newItems={ newItems }\n onRemove={ onRemove }\n renderItem={ renderItem }\n />\n )\n }\n </div>\n );\n}\n\nfunction ItemsList(props) {\n const {\n autoFocusEntry,\n id,\n items,\n newItems,\n open,\n onRemove,\n renderItem\n } = props;\n\n const getKey = useKeyFactory();\n\n const newItem = newItems[0];\n\n useEffect(() => {\n if (newItem && autoFocusEntry) {\n const entry = domQuery(`[data-entry-id=\"${id}\"]`);\n const focusableInput = domQuery('.bio-properties-panel-input', entry);\n\n if (focusableInput) {\n focusableInput.focus();\n }\n }\n }, [ newItem, autoFocusEntry, id ]);\n\n return (\n <ol class={ classnames(\n 'bio-properties-panel-list-entry-items',\n open ? 'open' : ''\n ) }>\n {\n items.map((item, index) => {\n const key = getKey(item);\n\n return (<li class=\"bio-properties-panel-list-entry-item\" key={ key }>\n {renderItem(item, index, item === newItem)}\n {\n onRemove && (\n <button\n type=\"button\"\n class=\"bio-properties-panel-remove-entry\"\n onClick={ () => onRemove && onRemove(item) }\n ><ListDeleteIcon /></button>\n )\n }\n </li>);\n })\n }\n </ol>);\n}\n\nfunction getTitle(label, items) {\n if (!items.length) {\n return label;\n }\n\n return `${label} (${items.length} items)`;\n}\n\n/**\n * Place new items in the beginning of the list and sort the rest with provided function.\n *\n * @template Item\n * @param {Item[]} currentItems\n * @param {(a: Item, b: Item) => 0 | 1 | -1} [compareFn] function used to sort items\n * @param {boolean} [shouldReset=false] set to `true` to reset state of the hook\n * @returns {Item[]}\n */\nfunction useSortedItems(currentItems, compareFn, shouldReset = false) {\n const itemsRef = useRef(currentItems.slice());\n\n // (1) Reset and optionally sort.\n if (shouldReset) {\n itemsRef.current = currentItems.slice();\n\n if (compareFn) {\n itemsRef.current.sort(compareFn);\n }\n } else {\n const items = itemsRef.current;\n\n // (2) Move new items to the beginning of the list.\n for (const item of currentItems) {\n if (!items.includes(item)) {\n items.unshift(item);\n }\n }\n\n // (3) Filter out removed items.\n itemsRef.current = items.filter(item => currentItems.includes(item));\n }\n\n return itemsRef.current;\n}\n\nfunction useNewItems(items = [], shouldReset) {\n const previousItems = usePrevious(items.slice()) || [];\n\n if (shouldReset) {\n return [];\n }\n\n return previousItems ? items.filter(item => !previousItems.includes(item)) : [];\n}\n"],"file":"List.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/entries/List.js"],"names":["useEffect","useRef","useState","query","domQuery","isFunction","useKeyFactory","usePrevious","classnames","ArrowIcon","CreateIcon","DeleteIcon","List","props","id","element","items","renderItem","label","open","shouldOpen","onAdd","onRemove","autoFocusEntry","compareFn","setOpen","hasItems","length","toggleOpen","opening","elementChanged","shouldReset","sortedItems","useSortedItems","newItems","useNewItems","addItem","event","stopPropagation","ItemsList","getKey","newItem","entry","selector","focusableInput","select","focus","map","item","index","key","currentItems","itemsRef","slice","current","sort","includes","unshift","push","filter","previousItems"],"mappings":"AAAA,SACEA,SADF,EAEEC,MAFF,EAGEC,QAHF,QAIO,cAJP;AAMA,SACEC,KAAK,IAAIC,QADX,QAEO,SAFP;AAIA,SAASC,UAAT,QAA2B,UAA3B;AAEA,SACEC,aADF,EAEEC,WAFF,QAGO,aAHP;AAKA,OAAOC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AL,EAA2B;AAEzB;AACAxB,QAAAA,SAAS,GAAGR,KAAK,CAACyC,OAAN,CAAcT,IAAd,CAAH,GAAyBhC,KAAK,CAAC0C,IAAN,CAAWV,IAAX,CAAlC;AACD;AACF,KAVI,CAYL;;;AACAI,IAAAA,QAAQ,CAACE,OAAT,GAAmBtC,KAAK,CAAC2C,MAAN,CAAaX,IAAI,IAAIG,YAAY,CAACK,QAAb,CAAsBR,IAAtB,CAArB,CAAnB;AACD;;AAED,SAAOI,QAAQ,CAACE,OAAhB;AACD;;AAED,SAASnB,WAAT,CAAqBnB,KAAK,GAAG,EAA7B,EAAiCe,WAAjC,EAA8C;AAC5C,QAAM6B,aAAa,GAAGrD,WAAW,CAACS,KAAK,CAACqC,KAAN,EAAD,CAAX,IAA8B,EAApD;;AAEA,MAAItB,WAAJ,EAAiB;AACf,WAAO,EAAP;AACD;;AAED,SAAO6B,aAAa,GAAG5C,KAAK,CAAC2C,MAAN,CAAaX,IAAI,IAAI,CAACY,aAAa,CAACJ,QAAd,CAAuBR,IAAvB,CAAtB,CAAH,GAAyD,EAA7E;AACD","sourcesContent":["import {\n useEffect,\n useRef,\n useState\n} from 'preact/hooks';\n\nimport {\n query as domQuery\n} from 'min-dom';\n\nimport { isFunction } from 'min-dash';\n\nimport {\n useKeyFactory,\n usePrevious\n} from '../../hooks';\n\nimport classnames from 'classnames';\n\nimport {\n ArrowIcon,\n CreateIcon,\n DeleteIcon\n} from '../icons';\n\n/**\n * Entry for handling lists represented as nested entries.\n *\n * @template Item\n * @param {object} props\n * @param {string} props.id\n * @param {*} props.element\n * @param {Function} props.onAdd\n * @param {(item: Item, index: number, isNew: boolean) => JSX.Element} props.renderItem\n * @param {string} [props.label='<empty>']\n * @param {Function} [props.onRemove]\n * @param {Item[]} [props.items]\n * @param {boolean} [props.open]\n * @param {string|boolean} [props.autoFocusEntry] either a custom selector string or true to focus the first input\n * @param {(a: Item, b: Item) => -1 | 0 | 1} [props.compareFn]\n * @returns\n */\nexport default function List(props) {\n const {\n id,\n element,\n items = [],\n renderItem,\n label = '<empty>',\n open: shouldOpen,\n onAdd,\n onRemove,\n autoFocusEntry,\n compareFn\n } = props;\n\n const [ open, setOpen ] = useState(!!shouldOpen);\n\n const hasItems = !!items.length;\n const toggleOpen = () => hasItems && setOpen(!open);\n\n const opening = !usePrevious(open) && open;\n const elementChanged = usePrevious(element) !== element;\n const shouldReset = opening || elementChanged;\n const sortedItems = useSortedItems(items, compareFn, shouldReset);\n\n const newItems = useNewItems(items, elementChanged);\n\n useEffect(() => {\n if (open && !hasItems) {\n setOpen(false);\n }\n }, [ open, hasItems ]);\n\n /**\n * @param {MouseEvent} event\n */\n function addItem(event) {\n event.stopPropagation();\n onAdd();\n\n if (!open) {\n setOpen(true);\n }\n }\n\n return (\n <div\n data-entry-id={ id }\n class={ classnames(\n 'bio-properties-panel-entry',\n 'bio-properties-panel-list-entry',\n hasItems ? '' : 'empty',\n open ? 'open' : ''\n ) }>\n <div class=\"bio-properties-panel-list-entry-header\" onClick={ toggleOpen }>\n <div\n title={ label }\n class={ classnames(\n 'bio-properties-panel-list-entry-header-title',\n open && 'open'\n ) }>\n { label }\n </div>\n <div\n class=\"bio-properties-panel-list-entry-header-buttons\"\n >\n <button\n title=\"Create new list item\"\n onClick={ addItem }\n class=\"bio-properties-panel-add-entry\"\n >\n <CreateIcon />\n {\n !hasItems ? (\n <div class=\"bio-properties-panel-add-entry-label\">Create</div>\n )\n : null\n }\n </button>\n {\n hasItems && (\n <div\n title={ `List contains ${items.length} item${items.length != 1 ? 's' : ''}` }\n class=\"bio-properties-panel-list-badge\"\n >\n { items.length }\n </div>\n )\n }\n {\n hasItems && (\n <button\n title=\"Toggle list item\"\n class=\"bio-properties-panel-arrow\"\n >\n <ArrowIcon class={ open ? 'bio-properties-panel-arrow-down' : 'bio-properties-panel-arrow-right' } />\n </button>\n )\n }\n </div>\n </div>\n {\n hasItems && (\n <ItemsList\n autoFocusEntry={ autoFocusEntry }\n id={ id }\n open={ open }\n items={ sortedItems }\n newItems={ newItems }\n onRemove={ onRemove }\n renderItem={ renderItem }\n />\n )\n }\n </div>\n );\n}\n\nfunction ItemsList(props) {\n const {\n autoFocusEntry,\n id,\n items,\n newItems,\n open,\n onRemove,\n renderItem\n } = props;\n\n const getKey = useKeyFactory();\n\n const newItem = newItems[0];\n\n useEffect(() => {\n if (newItem && autoFocusEntry) {\n\n // (0) select the parent entry (containing all list items)\n const entry = domQuery(`[data-entry-id=\"${id}\"]`);\n\n // (1) select the first input or a custom element to be focussed\n const selector = typeof(autoFocusEntry) === 'boolean' ?\n '.bio-properties-panel-input' :\n autoFocusEntry;\n const focusableInput = domQuery(selector, entry);\n\n // (2) set focus\n if (focusableInput) {\n\n if (isFunction(focusableInput.select)) {\n focusableInput.select();\n } else if (isFunction(focusableInput.focus)) {\n focusableInput.focus();\n }\n\n }\n }\n }, [ newItem, autoFocusEntry, id ]);\n\n return (\n <ol class={ classnames(\n 'bio-properties-panel-list-entry-items',\n open ? 'open' : ''\n ) }>\n {\n items.map((item, index) => {\n const key = getKey(item);\n\n return (<li class=\"bio-properties-panel-list-entry-item\" key={ key }>\n { renderItem(item, index, item === newItem) }\n {\n onRemove && (\n <button\n type=\"button\"\n title=\"Delete item\"\n class=\"bio-properties-panel-remove-entry bio-properties-panel-remove-list-entry\"\n onClick={ () => onRemove && onRemove(item) }\n ><DeleteIcon /></button>\n )\n }\n </li>);\n })\n }\n </ol>);\n}\n\n/**\n * Place new items in the beginning of the list and sort the rest with provided function.\n *\n * @template Item\n * @param {Item[]} currentItems\n * @param {(a: Item, b: Item) => 0 | 1 | -1} [compareFn] function used to sort items\n * @param {boolean} [shouldReset=false] set to `true` to reset state of the hook\n * @returns {Item[]}\n */\nfunction useSortedItems(currentItems, compareFn, shouldReset = false) {\n const itemsRef = useRef(currentItems.slice());\n\n // (1) Reset and optionally sort.\n if (shouldReset) {\n itemsRef.current = currentItems.slice();\n\n if (compareFn) {\n itemsRef.current.sort(compareFn);\n }\n } else {\n const items = itemsRef.current;\n\n // (2) Add new item to the list.\n for (const item of currentItems) {\n if (!items.includes(item)) {\n\n // Unshift or push depending on whether we have a compareFn\n compareFn ? items.unshift(item) : items.push(item);\n }\n }\n\n // (3) Filter out removed items.\n itemsRef.current = items.filter(item => currentItems.includes(item));\n }\n\n return itemsRef.current;\n}\n\nfunction useNewItems(items = [], shouldReset) {\n const previousItems = usePrevious(items.slice()) || [];\n\n if (shouldReset) {\n return [];\n }\n\n return previousItems ? items.filter(item => !previousItems.includes(item)) : [];\n}\n"],"file":"List.js"}
|
|
@@ -63,7 +63,7 @@ export default function ToggleSwitchEntry(props) {
|
|
|
63
63
|
} = props;
|
|
64
64
|
const value = getValue();
|
|
65
65
|
return _jsxs("div", {
|
|
66
|
-
class: "bio-properties-panel-entry",
|
|
66
|
+
class: "bio-properties-panel-entry bio-properties-panel-toggle-switch-entry",
|
|
67
67
|
"data-entry-id": id,
|
|
68
68
|
children: [_jsx(ToggleSwitch, {
|
|
69
69
|
id: id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/entries/ToggleSwitch.js"],"names":["ToggleSwitch","props","id","label","onInput","value","switcherLabel","handleInput","prefixId","ToggleSwitchEntry","description","getValue","setValue","isEdited","node","checked"],"mappings":";;;AAAA,SAASA,YAAT,CAAsBC,KAAtB,EAA6B;AAC3B,QAAM;AACJC,IAAAA,EADI;AAEJC,IAAAA,KAFI;AAGJC,IAAAA,OAHI;AAIJC,IAAAA,KAJI;AAKJC,IAAAA;AALI,MAMFL,KANJ;;AAQA,QAAMM,WAAW,GAAG,YAAY;AAC9BH,IAAAA,OAAO,CAAC,CAACC,KAAF,CAAP;AACD,GAFD;;AAIA,SACE;AAAK,IAAA,KAAK,EAAC,oCAAX;AAAA,eACE;AAAO,MAAA,KAAK,EAAC,4BAAb;AACE,MAAA,GAAG,EAAGG,QAAQ,CAACN,EAAD,CADhB;AAAA,gBAEIC;AAFJ,MADF,EAKE;AAAK,MAAA,KAAK,EAAC,oCAAX;AAAA,iBACE;AAAO,QAAA,KAAK,EAAC,8CAAb;AAAA,mBACE;AACE,UAAA,EAAE,EAAGK,QAAQ,CAACN,EAAD,CADf;AAEE,UAAA,KAAK,EAAC,4BAFR;AAGE,UAAA,IAAI,EAAC,UAHP;AAIE,UAAA,IAAI,EAAGA,EAJT;AAKE,UAAA,OAAO,EAAGK,WALZ;AAME,UAAA,OAAO,EAAGF;AANZ,UADF,EAQE;AAAM,UAAA,KAAK,EAAC;AAAZ,UARF;AAAA,QADF,EAWE;AAAG,QAAA,KAAK,EAAC,2CAAT;AAAA,kBAAuDC;AAAvD,QAXF;AAAA,MALF;AAAA,IADF;AAqBD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,SAASG,iBAAT,CAA2BR,KAA3B,EAAkC;AAC/C,QAAM;AACJC,IAAAA,EADI;AAEJQ,IAAAA,WAFI;AAGJP,IAAAA,KAHI;AAIJG,IAAAA,aAJI;AAKJK,IAAAA,QALI;AAMJC,IAAAA;AANI,MAOFX,KAPJ;AASA,QAAMI,KAAK,GAAGM,QAAQ,EAAtB;AACA,SACE;AAAK,IAAA,KAAK,EAAC,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/entries/ToggleSwitch.js"],"names":["ToggleSwitch","props","id","label","onInput","value","switcherLabel","handleInput","prefixId","ToggleSwitchEntry","description","getValue","setValue","isEdited","node","checked"],"mappings":";;;AAAA,SAASA,YAAT,CAAsBC,KAAtB,EAA6B;AAC3B,QAAM;AACJC,IAAAA,EADI;AAEJC,IAAAA,KAFI;AAGJC,IAAAA,OAHI;AAIJC,IAAAA,KAJI;AAKJC,IAAAA;AALI,MAMFL,KANJ;;AAQA,QAAMM,WAAW,GAAG,YAAY;AAC9BH,IAAAA,OAAO,CAAC,CAACC,KAAF,CAAP;AACD,GAFD;;AAIA,SACE;AAAK,IAAA,KAAK,EAAC,oCAAX;AAAA,eACE;AAAO,MAAA,KAAK,EAAC,4BAA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,CAAC,CAACA,IAAI,CAACC,OAAtB;AACD,C,CAGD;;AAEA,SAASP,QAAT,CAAkBN,EAAlB,EAAsB;AACpB,SAAQ,wBAAwBA,EAAI,EAApC;AACD","sourcesContent":["function ToggleSwitch(props) {\n const {\n id,\n label,\n onInput,\n value,\n switcherLabel\n } = props;\n\n const handleInput = async () => {\n onInput(!value);\n };\n\n return (\n <div class=\"bio-properties-panel-toggle-switch\">\n <label class=\"bio-properties-panel-label\"\n for={ prefixId(id) }>\n { label }\n </label>\n <div class=\"bio-properties-panel-field-wrapper\">\n <label class=\"bio-properties-panel-toggle-switch__switcher\">\n <input\n id={ prefixId(id) }\n class=\"bio-properties-panel-input\"\n type=\"checkbox\"\n name={ id }\n onInput={ handleInput }\n checked={ value } />\n <span class=\"bio-properties-panel-toggle-switch__slider\" />\n </label>\n <p class=\"bio-properties-panel-toggle-switch__label\">{ switcherLabel }</p>\n </div>\n </div>\n );\n}\n\n/**\n * @param {Object} props\n * @param {String} props.id\n * @param {String} props.description\n * @param {String} props.label\n * @param {String} props.switcherLabel\n * @param {Function} props.getValue\n * @param {Function} props.setValue\n */\nexport default function ToggleSwitchEntry(props) {\n const {\n id,\n description,\n label,\n switcherLabel,\n getValue,\n setValue\n } = props;\n\n const value = getValue();\n return (\n <div class=\"bio-properties-panel-entry bio-properties-panel-toggle-switch-entry\" data-entry-id={ id }>\n <ToggleSwitch id={ id } label={ label } value={ value } onInput={ setValue } switcherLabel={ switcherLabel } />\n { description && <div class=\"bio-properties-panel-description\">{ description }</div> }\n </div>\n );\n}\n\nexport function isEdited(node) {\n return node && !!node.checked;\n}\n\n\n// helpers /////////////////\n\nfunction prefixId(id) {\n return `bio-properties-panel-${ id }`;\n}\n"],"file":"ToggleSwitch.js"}
|
|
@@ -1,66 +1,51 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var ArrowIcon = function ArrowIcon(props) {
|
|
5
5
|
return _jsx("svg", { ...props,
|
|
6
6
|
children: _jsx("path", {
|
|
7
7
|
fillRule: "evenodd",
|
|
8
|
-
d: "
|
|
8
|
+
d: "m11.657 8-4.95 4.95a1 1 0 0 1-1.414-1.414L8.828 8 5.293 4.464A1 1 0 1 1 6.707 3.05L11.657 8z"
|
|
9
9
|
})
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
ArrowIcon.defaultProps = {
|
|
14
14
|
xmlns: "http://www.w3.org/2000/svg",
|
|
15
|
-
width: "
|
|
16
|
-
height: "
|
|
15
|
+
width: "16",
|
|
16
|
+
height: "16"
|
|
17
17
|
};
|
|
18
|
-
export {
|
|
18
|
+
export { ArrowIcon };
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
var CreateIcon = function CreateIcon(props) {
|
|
21
21
|
return _jsx("svg", { ...props,
|
|
22
22
|
children: _jsx("path", {
|
|
23
23
|
fillRule: "evenodd",
|
|
24
|
-
d: "
|
|
24
|
+
d: "M9 13V9h4a1 1 0 0 0 0-2H9V3a1 1 0 1 0-2 0v4H3a1 1 0 1 0 0 2h4v4a1 1 0 0 0 2 0z"
|
|
25
25
|
})
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
31
|
-
width: "7",
|
|
32
|
-
height: "9"
|
|
33
|
-
};
|
|
34
|
-
export { ListArrowIcon };
|
|
35
|
-
|
|
36
|
-
var ListDeleteIcon = function ListDeleteIcon(props) {
|
|
37
|
-
return _jsx("svg", { ...props,
|
|
38
|
-
children: _jsx("path", {
|
|
39
|
-
d: "M10 4v8c0 1.1-.9 2-2 2H3c-1.1 0-2-.9-2-2V4h9zM8 6H3v4.8c0 .66.5 1.2 1.111 1.2H6.89C7.5 12 8 11.46 8 10.8V6zm3-5H8.5l-1-1h-4l-1 1H0v1.5h11V1z"
|
|
40
|
-
})
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
ListDeleteIcon.defaultProps = {
|
|
29
|
+
CreateIcon.defaultProps = {
|
|
45
30
|
xmlns: "http://www.w3.org/2000/svg",
|
|
46
|
-
width: "
|
|
47
|
-
height: "
|
|
31
|
+
width: "16",
|
|
32
|
+
height: "16"
|
|
48
33
|
};
|
|
49
|
-
export {
|
|
34
|
+
export { CreateIcon };
|
|
50
35
|
|
|
51
|
-
var
|
|
36
|
+
var DeleteIcon = function DeleteIcon(props) {
|
|
52
37
|
return _jsx("svg", { ...props,
|
|
53
38
|
children: _jsx("path", {
|
|
54
39
|
fillRule: "evenodd",
|
|
55
|
-
d: "
|
|
40
|
+
d: "M12 6v7c0 1.1-.4 1.55-1.5 1.55h-5C4.4 14.55 4 14.1 4 13V6h8zm-1.5 1.5h-5v4.3c0 .66.5 1.2 1.111 1.2H9.39c.611 0 1.111-.54 1.111-1.2V7.5zM13 3h-2l-1-1H6L5 3H3v1.5h10V3z"
|
|
56
41
|
})
|
|
57
42
|
});
|
|
58
43
|
};
|
|
59
44
|
|
|
60
|
-
|
|
45
|
+
DeleteIcon.defaultProps = {
|
|
61
46
|
xmlns: "http://www.w3.org/2000/svg",
|
|
62
|
-
width: "
|
|
63
|
-
height: "
|
|
47
|
+
width: "16",
|
|
48
|
+
height: "16"
|
|
64
49
|
};
|
|
65
|
-
export {
|
|
50
|
+
export { DeleteIcon };
|
|
66
51
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/LayoutContext.js"],"names":["createContext","LayoutContext","layout","setLayout","setLayoutForKey"],"mappings":"AAAA,SACEA,aADF,QAEO,QAFP;AAIA,MAAMC,aAAa,GAAGD,aAAa,CAAC;AAClCE,EAAAA,MAAM,EAAE,EAD0B;AAElCC,EAAAA,SAAS,EAAE,MAAM,CAAE,CAFe;AAGlCC,EAAAA,eAAe,EAAE,MAAM,CAAE;
|
|
1
|
+
{"version":3,"sources":["../../src/context/LayoutContext.js"],"names":["createContext","LayoutContext","layout","setLayout","getLayoutForKey","setLayoutForKey"],"mappings":"AAAA,SACEA,aADF,QAEO,QAFP;AAIA,MAAMC,aAAa,GAAGD,aAAa,CAAC;AAClCE,EAAAA,MAAM,EAAE,EAD0B;AAElCC,EAAAA,SAAS,EAAE,MAAM,CAAE,CAFe;AAGlCC,EAAAA,eAAe,EAAE,MAAM,CAAE,CAHS;AAIlCC,EAAAA,eAAe,EAAE,MAAM,CAAE;AAJS,CAAD,CAAnC;AAOA,eAAeJ,aAAf","sourcesContent":["import {\n createContext\n} from 'preact';\n\nconst LayoutContext = createContext({\n layout: {},\n setLayout: () => {},\n getLayoutForKey: () => {},\n setLayoutForKey: () => {}\n});\n\nexport default LayoutContext;"],"file":"LayoutContext.js"}
|
package/lib/hooks/index.js
CHANGED
package/lib/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/index.js"],"names":["default","usePrevious","useKeyFactory"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAApB,QAAuC,eAAvC;AACA,SAASC,aAAT,QAA8B,iBAA9B","sourcesContent":["export { default as usePrevious } from './usePrevious';\nexport { useKeyFactory } from './useKeyFactory';"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/index.js"],"names":["default","usePrevious","useKeyFactory","useLayoutState"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAApB,QAAuC,eAAvC;AACA,SAASC,aAAT,QAA8B,iBAA9B;AACA,SAASC,cAAT,QAA+B,kBAA/B","sourcesContent":["export { default as usePrevious } from './usePrevious';\nexport { useKeyFactory } from './useKeyFactory';\nexport { useLayoutState } from './useLayoutState';"],"file":"index.js"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useContext, useState } from 'preact/hooks';
|
|
2
|
+
import { LayoutContext } from '../context';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a state that persists in the global LayoutContext.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```jsx
|
|
8
|
+
* function Group(props) {
|
|
9
|
+
* const [ open, setOpen ] = useLayoutState([ 'groups', 'foo', 'open' ], false);
|
|
10
|
+
* }
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param {(string|number)[]} path
|
|
14
|
+
* @param {any} [defaultValue]
|
|
15
|
+
*
|
|
16
|
+
* @returns {[ any, Function ]}
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export function useLayoutState(path, defaultValue) {
|
|
20
|
+
const {
|
|
21
|
+
getLayoutForKey,
|
|
22
|
+
setLayoutForKey
|
|
23
|
+
} = useContext(LayoutContext);
|
|
24
|
+
const layoutForKey = getLayoutForKey(path, defaultValue);
|
|
25
|
+
const [value, set] = useState(layoutForKey);
|
|
26
|
+
|
|
27
|
+
const setState = newValue => {
|
|
28
|
+
// (1) set component state
|
|
29
|
+
set(newValue); // (2) set context
|
|
30
|
+
|
|
31
|
+
setLayoutForKey(path, newValue);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return [value, setState];
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=useLayoutState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useLayoutState.js"],"names":["useContext","useState","LayoutContext","useLayoutState","path","defaultValue","getLayoutForKey","setLayoutForKey","layoutForKey","value","set","setState","newValue"],"mappings":"AAAA,SACEA,UADF,EAEEC,QAFF,QAGO,cAHP;AAKA,SACEC,aADF,QAEO,YAFP;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,cAAT,CAAwBC,IAAxB,EAA8BC,YAA9B,EAA4C;AACjD,QAAM;AACJC,IAAAA,eADI;AAEJC,IAAAA;AAFI,MAGFP,UAAU,CAACE,aAAD,CAHd;AAKA,QAAMM,YAAY,GAAGF,eAAe,CAACF,IAAD,EAAOC,YAAP,CAApC;AACA,QAAM,CAAEI,KAAF,EAASC,GAAT,IAAiBT,QAAQ,CAACO,YAAD,CAA/B;;AAEA,QAAMG,QAAQ,GAAIC,QAAD,IAAc;AAE7B;AACAF,IAAAA,GAAG,CAACE,QAAD,CAAH,CAH6B,CAK7B;;AACAL,IAAAA,eAAe,CAACH,IAAD,EAAOQ,QAAP,CAAf;AACD,GAPD;;AASA,SAAO,CAAEH,KAAF,EAASE,QAAT,CAAP;AACD","sourcesContent":["import {\n useContext,\n useState\n} from 'preact/hooks';\n\nimport {\n LayoutContext\n} from '../context';\n\n/**\n * Creates a state that persists in the global LayoutContext.\n *\n * @example\n * ```jsx\n * function Group(props) {\n * const [ open, setOpen ] = useLayoutState([ 'groups', 'foo', 'open' ], false);\n * }\n * ```\n *\n * @param {(string|number)[]} path\n * @param {any} [defaultValue]\n *\n * @returns {[ any, Function ]}\n */\nexport function useLayoutState(path, defaultValue) {\n const {\n getLayoutForKey,\n setLayoutForKey\n } = useContext(LayoutContext);\n\n const layoutForKey = getLayoutForKey(path, defaultValue);\n const [ value, set ] = useState(layoutForKey);\n\n const setState = (newValue) => {\n\n // (1) set component state\n set(newValue);\n\n // (2) set context\n setLayoutForKey(path, newValue);\n };\n\n return [ value, setState ];\n}\n"],"file":"useLayoutState.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bpmn-io/properties-panel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Library for creating bpmn-io properties panels.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"karma-mocha": "^2.0.1",
|
|
64
64
|
"karma-sinon-chai": "^2.0.2",
|
|
65
65
|
"karma-webpack": "^5.0.0",
|
|
66
|
-
"mocha": "^9.
|
|
66
|
+
"mocha": "^9.1.3",
|
|
67
67
|
"mocha-test-container-support": "^0.2.0",
|
|
68
68
|
"npm-run-all": "^4.1.5",
|
|
69
69
|
"preact": "^10.5.13",
|