@bpmn-io/properties-panel 0.9.0 → 0.10.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/CHANGELOG.md +11 -0
- package/dist/index.esm.js +1607 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +1648 -0
- package/dist/index.js.map +1 -0
- package/package.json +16 -7
- package/preact/LICENSE +21 -0
- package/preact/README.md +185 -0
- package/preact/compat/dist/compat.js +2 -0
- package/preact/compat/dist/compat.js.map +1 -0
- package/preact/compat/dist/compat.mjs +2 -0
- package/preact/compat/dist/compat.module.js +2 -0
- package/preact/compat/dist/compat.module.js.map +1 -0
- package/preact/compat/dist/compat.umd.js +2 -0
- package/preact/compat/dist/compat.umd.js.map +1 -0
- package/preact/compat/jsx-dev-runtime.js +1 -0
- package/preact/compat/jsx-dev-runtime.mjs +1 -0
- package/preact/compat/jsx-runtime.js +1 -0
- package/preact/compat/jsx-runtime.mjs +1 -0
- package/preact/compat/package.json +19 -0
- package/preact/compat/server.js +15 -0
- package/preact/compat/server.mjs +4 -0
- package/preact/compat/src/Children.js +21 -0
- package/preact/compat/src/PureComponent.js +15 -0
- package/preact/compat/src/forwardRef.js +51 -0
- package/preact/compat/src/index.d.ts +140 -0
- package/preact/compat/src/index.js +175 -0
- package/preact/compat/src/internal.d.ts +47 -0
- package/preact/compat/src/memo.js +34 -0
- package/preact/compat/src/portals.js +80 -0
- package/preact/compat/src/render.js +219 -0
- package/preact/compat/src/scheduler.js +24 -0
- package/preact/compat/src/suspense-list.d.ts +14 -0
- package/preact/compat/src/suspense-list.js +126 -0
- package/preact/compat/src/suspense.d.ts +15 -0
- package/preact/compat/src/suspense.js +270 -0
- package/preact/compat/src/util.js +28 -0
- package/preact/compat/test-utils.js +1 -0
- package/preact/debug/dist/debug.js +2 -0
- package/preact/debug/dist/debug.js.map +1 -0
- package/preact/debug/dist/debug.mjs +2 -0
- package/preact/debug/dist/debug.module.js +2 -0
- package/preact/debug/dist/debug.module.js.map +1 -0
- package/preact/debug/dist/debug.umd.js +2 -0
- package/preact/debug/dist/debug.umd.js.map +1 -0
- package/preact/debug/package.json +18 -0
- package/preact/debug/src/check-props.js +54 -0
- package/preact/debug/src/component-stack.js +146 -0
- package/preact/debug/src/constants.js +3 -0
- package/preact/debug/src/debug.js +442 -0
- package/preact/debug/src/index.js +6 -0
- package/preact/debug/src/internal.d.ts +82 -0
- package/preact/debug/src/util.js +11 -0
- package/preact/devtools/dist/devtools.js +2 -0
- package/preact/devtools/dist/devtools.js.map +1 -0
- package/preact/devtools/dist/devtools.mjs +2 -0
- package/preact/devtools/dist/devtools.module.js +2 -0
- package/preact/devtools/dist/devtools.module.js.map +1 -0
- package/preact/devtools/dist/devtools.umd.js +2 -0
- package/preact/devtools/dist/devtools.umd.js.map +1 -0
- package/preact/devtools/package.json +16 -0
- package/preact/devtools/src/devtools.js +10 -0
- package/preact/devtools/src/index.d.ts +8 -0
- package/preact/devtools/src/index.js +15 -0
- package/preact/dist/preact.js +2 -0
- package/preact/dist/preact.js.map +1 -0
- package/preact/dist/preact.min.js +2 -0
- package/preact/dist/preact.min.js.map +1 -0
- package/preact/dist/preact.mjs +2 -0
- package/preact/dist/preact.module.js +2 -0
- package/preact/dist/preact.module.js.map +1 -0
- package/preact/dist/preact.umd.js +2 -0
- package/preact/dist/preact.umd.js.map +1 -0
- package/preact/hooks/dist/hooks.js +2 -0
- package/preact/hooks/dist/hooks.js.map +1 -0
- package/preact/hooks/dist/hooks.mjs +2 -0
- package/preact/hooks/dist/hooks.module.js +2 -0
- package/preact/hooks/dist/hooks.module.js.map +1 -0
- package/preact/hooks/dist/hooks.umd.js +2 -0
- package/preact/hooks/dist/hooks.umd.js.map +1 -0
- package/preact/hooks/package.json +26 -0
- package/preact/hooks/src/index.d.ts +130 -0
- package/preact/hooks/src/index.js +386 -0
- package/preact/hooks/src/internal.d.ts +75 -0
- package/preact/jsx-runtime/dist/jsxRuntime.js +2 -0
- package/preact/jsx-runtime/dist/jsxRuntime.js.map +1 -0
- package/preact/jsx-runtime/dist/jsxRuntime.mjs +2 -0
- package/preact/jsx-runtime/dist/jsxRuntime.module.js +2 -0
- package/preact/jsx-runtime/dist/jsxRuntime.module.js.map +1 -0
- package/preact/jsx-runtime/dist/jsxRuntime.umd.js +2 -0
- package/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +1 -0
- package/preact/jsx-runtime/package.json +19 -0
- package/preact/jsx-runtime/src/index.d.ts +50 -0
- package/preact/jsx-runtime/src/index.js +72 -0
- package/preact/package.json +268 -0
- package/preact/src/cjs.js +3 -0
- package/preact/src/clone-element.js +39 -0
- package/preact/src/component.js +225 -0
- package/preact/src/constants.js +3 -0
- package/preact/src/create-context.js +68 -0
- package/preact/src/create-element.js +100 -0
- package/preact/src/diff/catch-error.js +38 -0
- package/preact/src/diff/children.js +347 -0
- package/preact/src/diff/index.js +516 -0
- package/preact/src/diff/props.js +158 -0
- package/preact/src/index.d.ts +310 -0
- package/preact/src/index.js +13 -0
- package/preact/src/internal.d.ts +147 -0
- package/preact/src/jsx.d.ts +955 -0
- package/preact/src/options.js +17 -0
- package/preact/src/render.js +74 -0
- package/preact/src/util.js +23 -0
- package/preact/test-utils/dist/testUtils.js +2 -0
- package/preact/test-utils/dist/testUtils.js.map +1 -0
- package/preact/test-utils/dist/testUtils.mjs +2 -0
- package/preact/test-utils/dist/testUtils.module.js +2 -0
- package/preact/test-utils/dist/testUtils.module.js.map +1 -0
- package/preact/test-utils/dist/testUtils.umd.js +2 -0
- package/preact/test-utils/dist/testUtils.umd.js.map +1 -0
- package/preact/test-utils/package.json +19 -0
- package/preact/test-utils/src/index.d.ts +3 -0
- package/preact/test-utils/src/index.js +117 -0
- package/lib/PropertiesPanel.js +0 -166
- package/lib/PropertiesPanel.js.map +0 -1
- package/lib/components/DropdownButton.js +0 -109
- package/lib/components/DropdownButton.js.map +0 -1
- package/lib/components/Group.js +0 -75
- package/lib/components/Group.js.map +0 -1
- package/lib/components/Header.js +0 -49
- package/lib/components/Header.js.map +0 -1
- package/lib/components/HeaderButton.js +0 -16
- package/lib/components/HeaderButton.js.map +0 -1
- package/lib/components/ListGroup.js +0 -167
- package/lib/components/ListGroup.js.map +0 -1
- package/lib/components/ListItem.js +0 -37
- package/lib/components/ListItem.js.map +0 -1
- package/lib/components/entries/Checkbox.js +0 -83
- package/lib/components/entries/Checkbox.js.map +0 -1
- package/lib/components/entries/Collapsible.js +0 -48
- package/lib/components/entries/Collapsible.js.map +0 -1
- package/lib/components/entries/Description.js +0 -26
- package/lib/components/entries/Description.js.map +0 -1
- package/lib/components/entries/List.js +0 -204
- package/lib/components/entries/List.js.map +0 -1
- package/lib/components/entries/NumberField.js +0 -110
- package/lib/components/entries/NumberField.js.map +0 -1
- package/lib/components/entries/Select.js +0 -110
- package/lib/components/entries/Select.js.map +0 -1
- package/lib/components/entries/Simple.js +0 -56
- package/lib/components/entries/Simple.js.map +0 -1
- package/lib/components/entries/TextArea.js +0 -98
- package/lib/components/entries/TextArea.js.map +0 -1
- package/lib/components/entries/TextField.js +0 -123
- package/lib/components/entries/TextField.js.map +0 -1
- package/lib/components/entries/ToggleSwitch.js +0 -91
- package/lib/components/entries/ToggleSwitch.js.map +0 -1
- package/lib/components/icons/index.js +0 -51
- package/lib/components/icons/index.js.map +0 -1
- package/lib/context/DescriptionContext.js +0 -7
- package/lib/context/DescriptionContext.js.map +0 -1
- package/lib/context/LayoutContext.js +0 -9
- package/lib/context/LayoutContext.js.map +0 -1
- package/lib/context/index.js +0 -3
- package/lib/context/index.js.map +0 -1
- package/lib/features/debounce-input/debounceInput.js +0 -14
- package/lib/features/debounce-input/debounceInput.js.map +0 -1
- package/lib/features/debounce-input/index.js +0 -5
- package/lib/features/debounce-input/index.js.map +0 -1
- package/lib/hooks/index.js +0 -5
- package/lib/hooks/index.js.map +0 -1
- package/lib/hooks/useDescriptionContext.js +0 -25
- package/lib/hooks/useDescriptionContext.js.map +0 -1
- package/lib/hooks/useKeyFactory.js +0 -39
- package/lib/hooks/useKeyFactory.js.map +0 -1
- package/lib/hooks/useLayoutState.js +0 -36
- package/lib/hooks/useLayoutState.js.map +0 -1
- package/lib/hooks/usePrevious.js +0 -16
- package/lib/hooks/usePrevious.js.map +0 -1
- package/lib/index.js +0 -2
- package/lib/index.js.map +0 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { _catchError } from './diff/catch-error';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The `option` object can potentially contain callback functions
|
|
5
|
+
* that are called during various stages of our renderer. This is the
|
|
6
|
+
* foundation on which all our addons like `preact/debug`, `preact/compat`,
|
|
7
|
+
* and `preact/hooks` are based on. See the `Options` type in `internal.d.ts`
|
|
8
|
+
* for a full list of available option hooks (most editors/IDEs allow you to
|
|
9
|
+
* ctrl+click or cmd+click on mac the type definition below).
|
|
10
|
+
* @type {import('./internal').Options}
|
|
11
|
+
*/
|
|
12
|
+
const options = {
|
|
13
|
+
_catchError,
|
|
14
|
+
_vnodeId: 0
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default options;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { EMPTY_OBJ, EMPTY_ARR } from './constants';
|
|
2
|
+
import { commitRoot, diff } from './diff/index';
|
|
3
|
+
import { createElement, Fragment } from './create-element';
|
|
4
|
+
import options from './options';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Render a Preact virtual node into a DOM element
|
|
8
|
+
* @param {import('./internal').ComponentChild} vnode The virtual node to render
|
|
9
|
+
* @param {import('./internal').PreactElement} parentDom The DOM element to
|
|
10
|
+
* render into
|
|
11
|
+
* @param {import('./internal').PreactElement | object} [replaceNode] Optional: Attempt to re-use an
|
|
12
|
+
* existing DOM tree rooted at `replaceNode`
|
|
13
|
+
*/
|
|
14
|
+
export function render(vnode, parentDom, replaceNode) {
|
|
15
|
+
if (options._root) options._root(vnode, parentDom);
|
|
16
|
+
|
|
17
|
+
// We abuse the `replaceNode` parameter in `hydrate()` to signal if we are in
|
|
18
|
+
// hydration mode or not by passing the `hydrate` function instead of a DOM
|
|
19
|
+
// element..
|
|
20
|
+
let isHydrating = typeof replaceNode === 'function';
|
|
21
|
+
|
|
22
|
+
// To be able to support calling `render()` multiple times on the same
|
|
23
|
+
// DOM node, we need to obtain a reference to the previous tree. We do
|
|
24
|
+
// this by assigning a new `_children` property to DOM nodes which points
|
|
25
|
+
// to the last rendered tree. By default this property is not present, which
|
|
26
|
+
// means that we are mounting a new tree for the first time.
|
|
27
|
+
let oldVNode = isHydrating
|
|
28
|
+
? null
|
|
29
|
+
: (replaceNode && replaceNode._children) || parentDom._children;
|
|
30
|
+
|
|
31
|
+
vnode = (
|
|
32
|
+
(!isHydrating && replaceNode) ||
|
|
33
|
+
parentDom
|
|
34
|
+
)._children = createElement(Fragment, null, [vnode]);
|
|
35
|
+
|
|
36
|
+
// List of effects that need to be called after diffing.
|
|
37
|
+
let commitQueue = [];
|
|
38
|
+
diff(
|
|
39
|
+
parentDom,
|
|
40
|
+
// Determine the new vnode tree and store it on the DOM element on
|
|
41
|
+
// our custom `_children` property.
|
|
42
|
+
vnode,
|
|
43
|
+
oldVNode || EMPTY_OBJ,
|
|
44
|
+
EMPTY_OBJ,
|
|
45
|
+
parentDom.ownerSVGElement !== undefined,
|
|
46
|
+
!isHydrating && replaceNode
|
|
47
|
+
? [replaceNode]
|
|
48
|
+
: oldVNode
|
|
49
|
+
? null
|
|
50
|
+
: parentDom.firstChild
|
|
51
|
+
? EMPTY_ARR.slice.call(parentDom.childNodes)
|
|
52
|
+
: null,
|
|
53
|
+
commitQueue,
|
|
54
|
+
!isHydrating && replaceNode
|
|
55
|
+
? replaceNode
|
|
56
|
+
: oldVNode
|
|
57
|
+
? oldVNode._dom
|
|
58
|
+
: parentDom.firstChild,
|
|
59
|
+
isHydrating
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// Flush all queued effects
|
|
63
|
+
commitRoot(commitQueue, vnode);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Update an existing DOM element with data from a Preact virtual node
|
|
68
|
+
* @param {import('./internal').ComponentChild} vnode The virtual node to render
|
|
69
|
+
* @param {import('./internal').PreactElement} parentDom The DOM element to
|
|
70
|
+
* update
|
|
71
|
+
*/
|
|
72
|
+
export function hydrate(vnode, parentDom) {
|
|
73
|
+
render(vnode, parentDom, hydrate);
|
|
74
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assign properties from `props` to `obj`
|
|
3
|
+
* @template O, P The obj and props types
|
|
4
|
+
* @param {O} obj The object to copy properties to
|
|
5
|
+
* @param {P} props The object to copy properties from
|
|
6
|
+
* @returns {O & P}
|
|
7
|
+
*/
|
|
8
|
+
export function assign(obj, props) {
|
|
9
|
+
// @ts-ignore We change the type of `obj` to be `O & P`
|
|
10
|
+
for (let i in props) obj[i] = props[i];
|
|
11
|
+
return /** @type {O & P} */ (obj);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Remove a child node from its parent if attached. This is a workaround for
|
|
16
|
+
* IE11 which doesn't support `Element.prototype.remove()`. Using this function
|
|
17
|
+
* is smaller than including a dedicated polyfill.
|
|
18
|
+
* @param {Node} node The node to remove
|
|
19
|
+
*/
|
|
20
|
+
export function removeNode(node) {
|
|
21
|
+
let parentNode = node.parentNode;
|
|
22
|
+
if (parentNode) parentNode.removeChild(node);
|
|
23
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=require("../..");function n(){return r.options.t=r.options.debounceRendering,r.options.debounceRendering=function(n){return r.options.o=n},function(){return r.options.o&&r.options.o()}}var t=function(r){return null!=r&&"function"==typeof r.then},e=0;function o(){r.options.o&&(r.options.o(),delete r.options.o),void 0!==r.options.t?(r.options.debounceRendering=r.options.t,delete r.options.t):r.options.debounceRendering=void 0}exports.setupRerender=n,exports.act=function(u){if(++e>1){var i=u();return t(i)?i.then(function(){--e}):(--e,Promise.resolve())}var c,f,a=r.options.requestAnimationFrame,v=n();r.options.requestAnimationFrame=function(r){return c=r};var l,p,s=function(){try{for(v();c;)f=c,c=null,f(),v();o()}catch(r){l||(l=r)}r.options.requestAnimationFrame=a,--e};try{p=u()}catch(r){l=r}if(t(p))return p.then(s,function(r){throw s(),r});if(s(),l)throw l;return Promise.resolve()},exports.teardown=o;
|
|
2
|
+
//# sourceMappingURL=testUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testUtils.js","sources":["../src/index.js"],"sourcesContent":["import { options } from '../..';\n\n/**\n * Setup a rerender function that will drain the queue of pending renders\n * @returns {() => void}\n */\nexport function setupRerender() {\n\toptions.__test__previousDebounce = options.debounceRendering;\n\toptions.debounceRendering = cb => (options.__test__drainQueue = cb);\n\treturn () => options.__test__drainQueue && options.__test__drainQueue();\n}\n\nconst isThenable = value => value != null && typeof value.then == 'function';\n\n/** Depth of nested calls to `act`. */\nlet actDepth = 0;\n\n/**\n * Run a test function, and flush all effects and rerenders after invoking it.\n *\n * Returns a Promise which resolves \"immediately\" if the callback is\n * synchronous or when the callback's result resolves if it is asynchronous.\n *\n * @param {() => void|Promise<void>} cb The function under test. This may be sync or async.\n * @return {Promise<void>}\n */\nexport function act(cb) {\n\tif (++actDepth > 1) {\n\t\t// If calls to `act` are nested, a flush happens only when the\n\t\t// outermost call returns. In the inner call, we just execute the\n\t\t// callback and return since the infrastructure for flushing has already\n\t\t// been set up.\n\t\t//\n\t\t// If an exception occurs, the outermost `act` will handle cleanup.\n\t\tconst result = cb();\n\t\tif (isThenable(result)) {\n\t\t\treturn result.then(() => {\n\t\t\t\t--actDepth;\n\t\t\t});\n\t\t}\n\t\t--actDepth;\n\t\treturn Promise.resolve();\n\t}\n\n\tconst previousRequestAnimationFrame = options.requestAnimationFrame;\n\tconst rerender = setupRerender();\n\n\t/** @type {() => void} */\n\tlet flush, toFlush;\n\n\t// Override requestAnimationFrame so we can flush pending hooks.\n\toptions.requestAnimationFrame = fc => (flush = fc);\n\n\tconst finish = () => {\n\t\ttry {\n\t\t\trerender();\n\t\t\twhile (flush) {\n\t\t\t\ttoFlush = flush;\n\t\t\t\tflush = null;\n\n\t\t\t\ttoFlush();\n\t\t\t\trerender();\n\t\t\t}\n\t\t\tteardown();\n\t\t} catch (e) {\n\t\t\tif (!err) {\n\t\t\t\terr = e;\n\t\t\t}\n\t\t}\n\n\t\toptions.requestAnimationFrame = previousRequestAnimationFrame;\n\t\t--actDepth;\n\t};\n\n\tlet err;\n\tlet result;\n\n\ttry {\n\t\tresult = cb();\n\t} catch (e) {\n\t\terr = e;\n\t}\n\n\tif (isThenable(result)) {\n\t\treturn result.then(finish, err => {\n\t\t\tfinish();\n\t\t\tthrow err;\n\t\t});\n\t}\n\n\t// nb. If the callback is synchronous, effects must be flushed before\n\t// `act` returns, so that the caller does not have to await the result,\n\t// even though React recommends this.\n\tfinish();\n\tif (err) {\n\t\tthrow err;\n\t}\n\treturn Promise.resolve();\n}\n\n/**\n * Teardown test environment and reset preact's internal state\n */\nexport function teardown() {\n\tif (options.__test__drainQueue) {\n\t\t// Flush any pending updates leftover by test\n\t\toptions.__test__drainQueue();\n\t\tdelete options.__test__drainQueue;\n\t}\n\n\tif (typeof options.__test__previousDebounce != 'undefined') {\n\t\toptions.debounceRendering = options.__test__previousDebounce;\n\t\tdelete options.__test__previousDebounce;\n\t} else {\n\t\toptions.debounceRendering = undefined;\n\t}\n}\n"],"names":["setupRerender","options","__test__previousDebounce","debounceRendering","cb","__test__drainQueue","isThenable","value","then","actDepth","teardown","undefined","result","Promise","resolve","flush","toFlush","previousRequestAnimationFrame","requestAnimationFrame","rerender","fc","err","finish","e"],"mappings":"wBAMA,SAAgBA,WACfC,UAAQC,EAA2BD,UAAQE,kBAC3CF,UAAQE,kBAAoB,SAAAC,UAAOH,UAAQI,EAAqBD,GACzD,kBAAMH,UAAQI,GAAsBJ,UAAQI,KAGpD,IAAMC,EAAa,SAAAC,UAAkB,MAATA,GAAsC,mBAAdA,EAAMC,MAGtDC,EAAW,EAwFf,SAAgBC,IACXT,UAAQI,IAEXJ,UAAQI,WACDJ,UAAQI,QAG+B,IAApCJ,UAAQC,GAClBD,UAAQE,kBAAoBF,UAAQC,SAC7BD,UAAQC,GAEfD,UAAQE,uBAAoBQ,sCAxFvB,SAAaP,QACbK,EAAW,EAAG,KAObG,EAASR,WACXE,EAAWM,GACPA,EAAOJ,KAAK,aAChBC,OAGFA,EACKI,QAAQC,eAOZC,EAAOC,EAJLC,EAAgChB,UAAQiB,sBACxCC,EAAWnB,IAMjBC,UAAQiB,sBAAwB,SAAAE,UAAOL,EAAQK,OAuB3CC,EACAT,EAtBEU,EAAS,mBAEbH,IACOJ,GACNC,EAAUD,EACVA,EAAQ,KAERC,IACAG,IAEDT,IACC,MAAOa,GACHF,IACJA,EAAME,GAIRtB,UAAQiB,sBAAwBD,IAC9BR,OAOFG,EAASR,IACR,MAAOmB,GACRF,EAAME,KAGHjB,EAAWM,UACPA,EAAOJ,KAAKc,EAAQ,SAAAD,SAC1BC,IACMD,OAORC,IACID,QACGA,SAEAR,QAAQC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{options as n}from"../..";function r(){return n.t=n.debounceRendering,n.debounceRendering=function(r){return n.o=r},function(){return n.o&&n.o()}}var t=function(n){return null!=n&&"function"==typeof n.then},o=0;function u(u){if(++o>1){var i=u();return t(i)?i.then(function(){--o}):(--o,Promise.resolve())}var f,c,a=n.requestAnimationFrame,l=r();n.requestAnimationFrame=function(n){return f=n};var v,d,h=function(){try{for(l();f;)c=f,f=null,c(),l();e()}catch(n){v||(v=n)}n.requestAnimationFrame=a,--o};try{d=u()}catch(n){v=n}if(t(d))return d.then(h,function(n){throw h(),n});if(h(),v)throw v;return Promise.resolve()}function e(){n.o&&(n.o(),delete n.o),void 0!==n.t?(n.debounceRendering=n.t,delete n.t):n.debounceRendering=void 0}export{r as setupRerender,u as act,e as teardown};
|
|
2
|
+
//# sourceMappingURL=testUtils.module.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{options as n}from"../..";function r(){return n.t=n.debounceRendering,n.debounceRendering=function(r){return n.o=r},function(){return n.o&&n.o()}}var t=function(n){return null!=n&&"function"==typeof n.then},o=0;function u(u){if(++o>1){var i=u();return t(i)?i.then(function(){--o}):(--o,Promise.resolve())}var f,c,a=n.requestAnimationFrame,l=r();n.requestAnimationFrame=function(n){return f=n};var v,d,h=function(){try{for(l();f;)c=f,f=null,c(),l();e()}catch(n){v||(v=n)}n.requestAnimationFrame=a,--o};try{d=u()}catch(n){v=n}if(t(d))return d.then(h,function(n){throw h(),n});if(h(),v)throw v;return Promise.resolve()}function e(){n.o&&(n.o(),delete n.o),void 0!==n.t?(n.debounceRendering=n.t,delete n.t):n.debounceRendering=void 0}export{r as setupRerender,u as act,e as teardown};
|
|
2
|
+
//# sourceMappingURL=testUtils.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testUtils.module.js","sources":["../src/index.js"],"sourcesContent":["import { options } from '../..';\n\n/**\n * Setup a rerender function that will drain the queue of pending renders\n * @returns {() => void}\n */\nexport function setupRerender() {\n\toptions.__test__previousDebounce = options.debounceRendering;\n\toptions.debounceRendering = cb => (options.__test__drainQueue = cb);\n\treturn () => options.__test__drainQueue && options.__test__drainQueue();\n}\n\nconst isThenable = value => value != null && typeof value.then == 'function';\n\n/** Depth of nested calls to `act`. */\nlet actDepth = 0;\n\n/**\n * Run a test function, and flush all effects and rerenders after invoking it.\n *\n * Returns a Promise which resolves \"immediately\" if the callback is\n * synchronous or when the callback's result resolves if it is asynchronous.\n *\n * @param {() => void|Promise<void>} cb The function under test. This may be sync or async.\n * @return {Promise<void>}\n */\nexport function act(cb) {\n\tif (++actDepth > 1) {\n\t\t// If calls to `act` are nested, a flush happens only when the\n\t\t// outermost call returns. In the inner call, we just execute the\n\t\t// callback and return since the infrastructure for flushing has already\n\t\t// been set up.\n\t\t//\n\t\t// If an exception occurs, the outermost `act` will handle cleanup.\n\t\tconst result = cb();\n\t\tif (isThenable(result)) {\n\t\t\treturn result.then(() => {\n\t\t\t\t--actDepth;\n\t\t\t});\n\t\t}\n\t\t--actDepth;\n\t\treturn Promise.resolve();\n\t}\n\n\tconst previousRequestAnimationFrame = options.requestAnimationFrame;\n\tconst rerender = setupRerender();\n\n\t/** @type {() => void} */\n\tlet flush, toFlush;\n\n\t// Override requestAnimationFrame so we can flush pending hooks.\n\toptions.requestAnimationFrame = fc => (flush = fc);\n\n\tconst finish = () => {\n\t\ttry {\n\t\t\trerender();\n\t\t\twhile (flush) {\n\t\t\t\ttoFlush = flush;\n\t\t\t\tflush = null;\n\n\t\t\t\ttoFlush();\n\t\t\t\trerender();\n\t\t\t}\n\t\t\tteardown();\n\t\t} catch (e) {\n\t\t\tif (!err) {\n\t\t\t\terr = e;\n\t\t\t}\n\t\t}\n\n\t\toptions.requestAnimationFrame = previousRequestAnimationFrame;\n\t\t--actDepth;\n\t};\n\n\tlet err;\n\tlet result;\n\n\ttry {\n\t\tresult = cb();\n\t} catch (e) {\n\t\terr = e;\n\t}\n\n\tif (isThenable(result)) {\n\t\treturn result.then(finish, err => {\n\t\t\tfinish();\n\t\t\tthrow err;\n\t\t});\n\t}\n\n\t// nb. If the callback is synchronous, effects must be flushed before\n\t// `act` returns, so that the caller does not have to await the result,\n\t// even though React recommends this.\n\tfinish();\n\tif (err) {\n\t\tthrow err;\n\t}\n\treturn Promise.resolve();\n}\n\n/**\n * Teardown test environment and reset preact's internal state\n */\nexport function teardown() {\n\tif (options.__test__drainQueue) {\n\t\t// Flush any pending updates leftover by test\n\t\toptions.__test__drainQueue();\n\t\tdelete options.__test__drainQueue;\n\t}\n\n\tif (typeof options.__test__previousDebounce != 'undefined') {\n\t\toptions.debounceRendering = options.__test__previousDebounce;\n\t\tdelete options.__test__previousDebounce;\n\t} else {\n\t\toptions.debounceRendering = undefined;\n\t}\n}\n"],"names":["setupRerender","options","__test__previousDebounce","debounceRendering","cb","__test__drainQueue","isThenable","value","then","actDepth","act","result","Promise","resolve","flush","toFlush","previousRequestAnimationFrame","requestAnimationFrame","rerender","fc","err","finish","teardown","e","undefined"],"mappings":"iCAMA,SAAgBA,WACfC,EAAQC,EAA2BD,EAAQE,kBAC3CF,EAAQE,kBAAoB,SAAAC,UAAOH,EAAQI,EAAqBD,GACzD,kBAAMH,EAAQI,GAAsBJ,EAAQI,KAGpD,IAAMC,EAAa,SAAAC,UAAkB,MAATA,GAAsC,mBAAdA,EAAMC,MAGtDC,EAAW,EAWR,SAASC,EAAIN,QACbK,EAAW,EAAG,KAObE,EAASP,WACXE,EAAWK,GACPA,EAAOH,KAAK,aAChBC,OAGFA,EACKG,QAAQC,eAOZC,EAAOC,EAJLC,EAAgCf,EAAQgB,sBACxCC,EAAWlB,IAMjBC,EAAQgB,sBAAwB,SAAAE,UAAOL,EAAQK,OAuB3CC,EACAT,EAtBEU,EAAS,mBAEbH,IACOJ,GACNC,EAAUD,EACVA,EAAQ,KAERC,IACAG,IAEDI,IACC,MAAOC,GACHH,IACJA,EAAMG,GAIRtB,EAAQgB,sBAAwBD,IAC9BP,OAOFE,EAASP,IACR,MAAOmB,GACRH,EAAMG,KAGHjB,EAAWK,UACPA,EAAOH,KAAKa,EAAQ,SAAAD,SAC1BC,IACMD,OAORC,IACID,QACGA,SAEAR,QAAQC,UAMhB,SAAgBS,IACXrB,EAAQI,IAEXJ,EAAQI,WACDJ,EAAQI,QAG+B,IAApCJ,EAAQC,GAClBD,EAAQE,kBAAoBF,EAAQC,SAC7BD,EAAQC,GAEfD,EAAQE,uBAAoBqB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("../..")):"function"==typeof define&&define.amd?define(["exports","preact"],t):t(n.preactTestUtils={},n.preact)}(this,function(n,t){function e(){return t.options.t=t.options.debounceRendering,t.options.debounceRendering=function(n){return t.options.o=n},function(){return t.options.o&&t.options.o()}}var r=function(n){return null!=n&&"function"==typeof n.then},o=0;function i(){t.options.o&&(t.options.o(),delete t.options.o),void 0!==t.options.t?(t.options.debounceRendering=t.options.t,delete t.options.t):t.options.debounceRendering=void 0}n.setupRerender=e,n.act=function(n){if(++o>1){var u=n();return r(u)?u.then(function(){--o}):(--o,Promise.resolve())}var f,c,d=t.options.requestAnimationFrame,p=e();t.options.requestAnimationFrame=function(n){return f=n};var a,l,s=function(){try{for(p();f;)c=f,f=null,c(),p();i()}catch(n){a||(a=n)}t.options.requestAnimationFrame=d,--o};try{l=n()}catch(n){a=n}if(r(l))return l.then(s,function(n){throw s(),n});if(s(),a)throw a;return Promise.resolve()},n.teardown=i});
|
|
2
|
+
//# sourceMappingURL=testUtils.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testUtils.umd.js","sources":["../src/index.js"],"sourcesContent":["import { options } from '../..';\n\n/**\n * Setup a rerender function that will drain the queue of pending renders\n * @returns {() => void}\n */\nexport function setupRerender() {\n\toptions.__test__previousDebounce = options.debounceRendering;\n\toptions.debounceRendering = cb => (options.__test__drainQueue = cb);\n\treturn () => options.__test__drainQueue && options.__test__drainQueue();\n}\n\nconst isThenable = value => value != null && typeof value.then == 'function';\n\n/** Depth of nested calls to `act`. */\nlet actDepth = 0;\n\n/**\n * Run a test function, and flush all effects and rerenders after invoking it.\n *\n * Returns a Promise which resolves \"immediately\" if the callback is\n * synchronous or when the callback's result resolves if it is asynchronous.\n *\n * @param {() => void|Promise<void>} cb The function under test. This may be sync or async.\n * @return {Promise<void>}\n */\nexport function act(cb) {\n\tif (++actDepth > 1) {\n\t\t// If calls to `act` are nested, a flush happens only when the\n\t\t// outermost call returns. In the inner call, we just execute the\n\t\t// callback and return since the infrastructure for flushing has already\n\t\t// been set up.\n\t\t//\n\t\t// If an exception occurs, the outermost `act` will handle cleanup.\n\t\tconst result = cb();\n\t\tif (isThenable(result)) {\n\t\t\treturn result.then(() => {\n\t\t\t\t--actDepth;\n\t\t\t});\n\t\t}\n\t\t--actDepth;\n\t\treturn Promise.resolve();\n\t}\n\n\tconst previousRequestAnimationFrame = options.requestAnimationFrame;\n\tconst rerender = setupRerender();\n\n\t/** @type {() => void} */\n\tlet flush, toFlush;\n\n\t// Override requestAnimationFrame so we can flush pending hooks.\n\toptions.requestAnimationFrame = fc => (flush = fc);\n\n\tconst finish = () => {\n\t\ttry {\n\t\t\trerender();\n\t\t\twhile (flush) {\n\t\t\t\ttoFlush = flush;\n\t\t\t\tflush = null;\n\n\t\t\t\ttoFlush();\n\t\t\t\trerender();\n\t\t\t}\n\t\t\tteardown();\n\t\t} catch (e) {\n\t\t\tif (!err) {\n\t\t\t\terr = e;\n\t\t\t}\n\t\t}\n\n\t\toptions.requestAnimationFrame = previousRequestAnimationFrame;\n\t\t--actDepth;\n\t};\n\n\tlet err;\n\tlet result;\n\n\ttry {\n\t\tresult = cb();\n\t} catch (e) {\n\t\terr = e;\n\t}\n\n\tif (isThenable(result)) {\n\t\treturn result.then(finish, err => {\n\t\t\tfinish();\n\t\t\tthrow err;\n\t\t});\n\t}\n\n\t// nb. If the callback is synchronous, effects must be flushed before\n\t// `act` returns, so that the caller does not have to await the result,\n\t// even though React recommends this.\n\tfinish();\n\tif (err) {\n\t\tthrow err;\n\t}\n\treturn Promise.resolve();\n}\n\n/**\n * Teardown test environment and reset preact's internal state\n */\nexport function teardown() {\n\tif (options.__test__drainQueue) {\n\t\t// Flush any pending updates leftover by test\n\t\toptions.__test__drainQueue();\n\t\tdelete options.__test__drainQueue;\n\t}\n\n\tif (typeof options.__test__previousDebounce != 'undefined') {\n\t\toptions.debounceRendering = options.__test__previousDebounce;\n\t\tdelete options.__test__previousDebounce;\n\t} else {\n\t\toptions.debounceRendering = undefined;\n\t}\n}\n"],"names":["setupRerender","options","__test__previousDebounce","debounceRendering","cb","__test__drainQueue","isThenable","value","then","actDepth","teardown","undefined","result","Promise","resolve","flush","toFlush","previousRequestAnimationFrame","requestAnimationFrame","rerender","fc","err","finish","e"],"mappings":"2NAMO,SAASA,WACfC,UAAQC,EAA2BD,UAAQE,kBAC3CF,UAAQE,kBAAoB,SAAAC,UAAOH,UAAQI,EAAqBD,GACzD,kBAAMH,UAAQI,GAAsBJ,UAAQI,KAGpD,IAAMC,EAAa,SAAAC,UAAkB,MAATA,GAAsC,mBAAdA,EAAMC,MAGtDC,EAAW,EAwFR,SAASC,IACXT,UAAQI,IAEXJ,UAAQI,WACDJ,UAAQI,QAG+B,IAApCJ,UAAQC,GAClBD,UAAQE,kBAAoBF,UAAQC,SAC7BD,UAAQC,GAEfD,UAAQE,uBAAoBQ,0BAxFvB,SAAaP,QACbK,EAAW,EAAG,KAObG,EAASR,WACXE,EAAWM,GACPA,EAAOJ,KAAK,aAChBC,OAGFA,EACKI,QAAQC,eAOZC,EAAOC,EAJLC,EAAgChB,UAAQiB,sBACxCC,EAAWnB,IAMjBC,UAAQiB,sBAAwB,SAAAE,UAAOL,EAAQK,OAuB3CC,EACAT,EAtBEU,EAAS,mBAEbH,IACOJ,GACNC,EAAUD,EACVA,EAAQ,KAERC,IACAG,IAEDT,IACC,MAAOa,GACHF,IACJA,EAAME,GAIRtB,UAAQiB,sBAAwBD,IAC9BR,OAOFG,EAASR,IACR,MAAOmB,GACRF,EAAME,KAGHjB,EAAWM,UACPA,EAAOJ,KAAKc,EAAQ,SAAAD,SAC1BC,IACMD,OAORC,IACID,QACGA,SAEAR,QAAQC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "test-utils",
|
|
3
|
+
"amdName": "preactTestUtils",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"private": true,
|
|
6
|
+
"description": "Test-utils for Preact",
|
|
7
|
+
"main": "dist/testUtils.js",
|
|
8
|
+
"module": "dist/testUtils.module.js",
|
|
9
|
+
"umd:main": "dist/testUtils.umd.js",
|
|
10
|
+
"source": "src/index.js",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"types": "src/index.d.ts",
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"preact": "^10.0.0"
|
|
15
|
+
},
|
|
16
|
+
"mangle": {
|
|
17
|
+
"regex": "^_"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { options } from '../..';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Setup a rerender function that will drain the queue of pending renders
|
|
5
|
+
* @returns {() => void}
|
|
6
|
+
*/
|
|
7
|
+
export function setupRerender() {
|
|
8
|
+
options.__test__previousDebounce = options.debounceRendering;
|
|
9
|
+
options.debounceRendering = cb => (options.__test__drainQueue = cb);
|
|
10
|
+
return () => options.__test__drainQueue && options.__test__drainQueue();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const isThenable = value => value != null && typeof value.then == 'function';
|
|
14
|
+
|
|
15
|
+
/** Depth of nested calls to `act`. */
|
|
16
|
+
let actDepth = 0;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Run a test function, and flush all effects and rerenders after invoking it.
|
|
20
|
+
*
|
|
21
|
+
* Returns a Promise which resolves "immediately" if the callback is
|
|
22
|
+
* synchronous or when the callback's result resolves if it is asynchronous.
|
|
23
|
+
*
|
|
24
|
+
* @param {() => void|Promise<void>} cb The function under test. This may be sync or async.
|
|
25
|
+
* @return {Promise<void>}
|
|
26
|
+
*/
|
|
27
|
+
export function act(cb) {
|
|
28
|
+
if (++actDepth > 1) {
|
|
29
|
+
// If calls to `act` are nested, a flush happens only when the
|
|
30
|
+
// outermost call returns. In the inner call, we just execute the
|
|
31
|
+
// callback and return since the infrastructure for flushing has already
|
|
32
|
+
// been set up.
|
|
33
|
+
//
|
|
34
|
+
// If an exception occurs, the outermost `act` will handle cleanup.
|
|
35
|
+
const result = cb();
|
|
36
|
+
if (isThenable(result)) {
|
|
37
|
+
return result.then(() => {
|
|
38
|
+
--actDepth;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
--actDepth;
|
|
42
|
+
return Promise.resolve();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const previousRequestAnimationFrame = options.requestAnimationFrame;
|
|
46
|
+
const rerender = setupRerender();
|
|
47
|
+
|
|
48
|
+
/** @type {() => void} */
|
|
49
|
+
let flush, toFlush;
|
|
50
|
+
|
|
51
|
+
// Override requestAnimationFrame so we can flush pending hooks.
|
|
52
|
+
options.requestAnimationFrame = fc => (flush = fc);
|
|
53
|
+
|
|
54
|
+
const finish = () => {
|
|
55
|
+
try {
|
|
56
|
+
rerender();
|
|
57
|
+
while (flush) {
|
|
58
|
+
toFlush = flush;
|
|
59
|
+
flush = null;
|
|
60
|
+
|
|
61
|
+
toFlush();
|
|
62
|
+
rerender();
|
|
63
|
+
}
|
|
64
|
+
teardown();
|
|
65
|
+
} catch (e) {
|
|
66
|
+
if (!err) {
|
|
67
|
+
err = e;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
options.requestAnimationFrame = previousRequestAnimationFrame;
|
|
72
|
+
--actDepth;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
let err;
|
|
76
|
+
let result;
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
result = cb();
|
|
80
|
+
} catch (e) {
|
|
81
|
+
err = e;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (isThenable(result)) {
|
|
85
|
+
return result.then(finish, err => {
|
|
86
|
+
finish();
|
|
87
|
+
throw err;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// nb. If the callback is synchronous, effects must be flushed before
|
|
92
|
+
// `act` returns, so that the caller does not have to await the result,
|
|
93
|
+
// even though React recommends this.
|
|
94
|
+
finish();
|
|
95
|
+
if (err) {
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
98
|
+
return Promise.resolve();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Teardown test environment and reset preact's internal state
|
|
103
|
+
*/
|
|
104
|
+
export function teardown() {
|
|
105
|
+
if (options.__test__drainQueue) {
|
|
106
|
+
// Flush any pending updates leftover by test
|
|
107
|
+
options.__test__drainQueue();
|
|
108
|
+
delete options.__test__drainQueue;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (typeof options.__test__previousDebounce != 'undefined') {
|
|
112
|
+
options.debounceRendering = options.__test__previousDebounce;
|
|
113
|
+
delete options.__test__previousDebounce;
|
|
114
|
+
} else {
|
|
115
|
+
options.debounceRendering = undefined;
|
|
116
|
+
}
|
|
117
|
+
}
|
package/lib/PropertiesPanel.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'preact/hooks';
|
|
2
|
-
import { get, set } from 'min-dash';
|
|
3
|
-
import classnames from 'classnames';
|
|
4
|
-
import Header from './components/Header';
|
|
5
|
-
import Group from './components/Group';
|
|
6
|
-
import { LayoutContext, DescriptionContext } from './context';
|
|
7
|
-
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
8
|
-
import { jsxs as _jsxs } from "preact/jsx-runtime";
|
|
9
|
-
const DEFAULT_LAYOUT = {
|
|
10
|
-
open: true
|
|
11
|
-
};
|
|
12
|
-
const DEFAULT_DESCRIPTION = {};
|
|
13
|
-
/**
|
|
14
|
-
* @typedef { {
|
|
15
|
-
* component: import('preact').ComponentChild,
|
|
16
|
-
* id: String,
|
|
17
|
-
* isEdited?: Function
|
|
18
|
-
* } } EntryDefinition
|
|
19
|
-
*
|
|
20
|
-
* @typedef { {
|
|
21
|
-
* autoFocusEntry: String,
|
|
22
|
-
* autoOpen?: Boolean,
|
|
23
|
-
* entries: Array<EntryDefinition>,
|
|
24
|
-
* id: String,
|
|
25
|
-
* label: String,
|
|
26
|
-
* remove: (event: MouseEvent) => void
|
|
27
|
-
* } } ListItemDefinition
|
|
28
|
-
*
|
|
29
|
-
* @typedef { {
|
|
30
|
-
* add: (event: MouseEvent) => void,
|
|
31
|
-
* component: import('preact').Component,
|
|
32
|
-
* element: Object,
|
|
33
|
-
* id: String,
|
|
34
|
-
* items: Array<ListItemDefinition>,
|
|
35
|
-
* label: String,
|
|
36
|
-
* shouldSort?: Boolean,
|
|
37
|
-
* shouldOpen?: Boolean
|
|
38
|
-
* } } ListGroupDefinition
|
|
39
|
-
*
|
|
40
|
-
* @typedef { {
|
|
41
|
-
* component?: import('preact').Component,
|
|
42
|
-
* entries: Array<EntryDefinition>,
|
|
43
|
-
* id: String,
|
|
44
|
-
* label: String
|
|
45
|
-
* } } GroupDefinition
|
|
46
|
-
*
|
|
47
|
-
* @typedef { {
|
|
48
|
-
* [id: String]: GetDescriptionFunction
|
|
49
|
-
* } } DescriptionConfig
|
|
50
|
-
*
|
|
51
|
-
* @callback { {
|
|
52
|
-
* @param {string} id
|
|
53
|
-
* @param {djs.model.base} element
|
|
54
|
-
* @returns {string}
|
|
55
|
-
* } } GetDescriptionFunction
|
|
56
|
-
*
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* A basic properties panel component. Describes *how* content will be rendered, accepts
|
|
61
|
-
* data from implementor to describe *what* will be rendered.
|
|
62
|
-
*
|
|
63
|
-
* @param {Object} props
|
|
64
|
-
* @param {Object} props.element
|
|
65
|
-
* @param {import('./components/Header').HeaderProvider} props.headerProvider
|
|
66
|
-
* @param {Array<GroupDefinition|ListGroupDefinition>} props.groups
|
|
67
|
-
* @param {Object} [props.layoutConfig]
|
|
68
|
-
* @param {Function} [props.layoutChanged]
|
|
69
|
-
* @param {DescriptionConfig} [props.descriptionConfig]
|
|
70
|
-
* @param {Function} [props.descriptionLoaded]
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
export default function PropertiesPanel(props) {
|
|
74
|
-
const {
|
|
75
|
-
element,
|
|
76
|
-
headerProvider,
|
|
77
|
-
groups,
|
|
78
|
-
layoutConfig = {},
|
|
79
|
-
layoutChanged,
|
|
80
|
-
descriptionConfig = {},
|
|
81
|
-
descriptionLoaded
|
|
82
|
-
} = props; // set-up layout context
|
|
83
|
-
|
|
84
|
-
const [layout, setLayout] = useState(createLayoutContext(layoutConfig));
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
if (typeof layoutChanged === 'function') {
|
|
87
|
-
layoutChanged(layout);
|
|
88
|
-
}
|
|
89
|
-
}, [layout, layoutChanged]);
|
|
90
|
-
|
|
91
|
-
const getLayoutForKey = (key, defaultValue) => {
|
|
92
|
-
return get(layout, key, defaultValue);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const setLayoutForKey = (key, config) => {
|
|
96
|
-
setLayout(set(layout, key, config));
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const layoutContext = {
|
|
100
|
-
layout,
|
|
101
|
-
setLayout,
|
|
102
|
-
getLayoutForKey,
|
|
103
|
-
setLayoutForKey
|
|
104
|
-
}; // set-up description context
|
|
105
|
-
|
|
106
|
-
const description = createDescriptionContext(descriptionConfig);
|
|
107
|
-
|
|
108
|
-
if (typeof descriptionLoaded === 'function') {
|
|
109
|
-
descriptionLoaded(description);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const getDescriptionForId = (id, element) => {
|
|
113
|
-
return description[id] && description[id](element);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const descriptionContext = {
|
|
117
|
-
description,
|
|
118
|
-
getDescriptionForId
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
if (!element) {
|
|
122
|
-
return _jsx("div", {
|
|
123
|
-
class: "bio-properties-panel-placeholder",
|
|
124
|
-
children: "Select an element to edit its properties."
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return _jsx(DescriptionContext.Provider, {
|
|
129
|
-
value: descriptionContext,
|
|
130
|
-
children: _jsx(LayoutContext.Provider, {
|
|
131
|
-
value: layoutContext,
|
|
132
|
-
children: _jsxs("div", {
|
|
133
|
-
class: classnames('bio-properties-panel', layout.open ? 'open' : ''),
|
|
134
|
-
children: [_jsx(Header, {
|
|
135
|
-
element: element,
|
|
136
|
-
headerProvider: headerProvider
|
|
137
|
-
}), _jsx("div", {
|
|
138
|
-
class: "bio-properties-panel-scroll-container",
|
|
139
|
-
children: groups.map(group => {
|
|
140
|
-
const {
|
|
141
|
-
component: GroupComponent = Group,
|
|
142
|
-
id
|
|
143
|
-
} = group;
|
|
144
|
-
return _jsx(GroupComponent, {
|
|
145
|
-
element: element,
|
|
146
|
-
...group
|
|
147
|
-
}, id);
|
|
148
|
-
})
|
|
149
|
-
})]
|
|
150
|
-
})
|
|
151
|
-
})
|
|
152
|
-
});
|
|
153
|
-
} // helpers //////////////////
|
|
154
|
-
|
|
155
|
-
function createLayoutContext(overrides) {
|
|
156
|
-
return { ...DEFAULT_LAYOUT,
|
|
157
|
-
...overrides
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function createDescriptionContext(overrides) {
|
|
162
|
-
return { ...DEFAULT_DESCRIPTION,
|
|
163
|
-
...overrides
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
//# sourceMappingURL=PropertiesPanel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/PropertiesPanel.js"],"names":["useState","useEffect","get","set","classnames","Header","Group","LayoutContext","DescriptionContext","DEFAULT_LAYOUT","open","DEFAULT_DESCRIPTION","PropertiesPanel","props","element","headerProvider","groups","layoutConfig","layoutChanged","descriptionConfig","descriptionLoaded","layout","setLayout","createLayoutContext","getLayoutForKey","key","defaultValue","setLayoutForKey","config","layoutContext","description","createDescriptionContext","getDescriptionForId","id","descriptionContext","map","group","component","GroupComponent","overrides"],"mappings":"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","sourcesContent":["import {\n useState,\n useEffect\n} from 'preact/hooks';\n\nimport {\n get,\n set\n} from 'min-dash';\n\nimport classnames from 'classnames';\n\nimport Header from './components/Header';\n\nimport Group from './components/Group';\n\nimport {\n LayoutContext,\n DescriptionContext\n} from './context';\n\nconst DEFAULT_LAYOUT = {\n open: true\n};\n\nconst DEFAULT_DESCRIPTION = {};\n\n\n/**\n * @typedef { {\n * component: import('preact').ComponentChild,\n * id: String,\n * isEdited?: Function\n * } } EntryDefinition\n *\n * @typedef { {\n * autoFocusEntry: String,\n * autoOpen?: Boolean,\n * entries: Array<EntryDefinition>,\n * id: String,\n * label: String,\n * remove: (event: MouseEvent) => void\n * } } ListItemDefinition\n *\n * @typedef { {\n * add: (event: MouseEvent) => void,\n * component: import('preact').Component,\n * element: Object,\n * id: String,\n * items: Array<ListItemDefinition>,\n * label: String,\n * shouldSort?: Boolean,\n * shouldOpen?: Boolean\n * } } ListGroupDefinition\n *\n * @typedef { {\n * component?: import('preact').Component,\n * entries: Array<EntryDefinition>,\n * id: String,\n * label: String\n * } } GroupDefinition\n *\n * @typedef { {\n * [id: String]: GetDescriptionFunction\n * } } DescriptionConfig\n *\n * @callback { {\n * @param {string} id\n * @param {djs.model.base} element\n * @returns {string}\n * } } GetDescriptionFunction\n *\n */\n\n\n/**\n * A basic properties panel component. Describes *how* content will be rendered, accepts\n * data from implementor to describe *what* will be rendered.\n *\n * @param {Object} props\n * @param {Object} props.element\n * @param {import('./components/Header').HeaderProvider} props.headerProvider\n * @param {Array<GroupDefinition|ListGroupDefinition>} props.groups\n * @param {Object} [props.layoutConfig]\n * @param {Function} [props.layoutChanged]\n * @param {DescriptionConfig} [props.descriptionConfig]\n * @param {Function} [props.descriptionLoaded]\n */\nexport default function PropertiesPanel(props) {\n const {\n element,\n headerProvider,\n groups,\n layoutConfig = {},\n layoutChanged,\n descriptionConfig = {},\n descriptionLoaded\n } = props;\n\n // set-up layout context\n const [ layout, setLayout ] = useState(createLayoutContext(layoutConfig));\n\n useEffect(() => {\n if (typeof layoutChanged === 'function') {\n layoutChanged(layout);\n }\n }, [ layout, layoutChanged ]);\n\n const getLayoutForKey = (key, defaultValue) => {\n return get(layout, key, defaultValue);\n };\n\n const setLayoutForKey = (key, config) => {\n setLayout(set(layout, key, config));\n };\n\n const layoutContext = {\n layout,\n setLayout,\n getLayoutForKey,\n setLayoutForKey\n };\n\n // set-up description context\n const description = createDescriptionContext(descriptionConfig);\n\n if (typeof descriptionLoaded === 'function') {\n descriptionLoaded(description);\n }\n\n const getDescriptionForId = (id, element) => {\n return description[id] && description[id](element);\n };\n\n const descriptionContext = {\n description,\n getDescriptionForId\n };\n\n if (!element) {\n return <div class=\"bio-properties-panel-placeholder\">Select an element to edit its properties.</div>;\n }\n\n return <DescriptionContext.Provider value={ descriptionContext }>\n <LayoutContext.Provider value={ layoutContext }>\n <div\n class={ classnames(\n 'bio-properties-panel',\n layout.open ? 'open' : '')\n }>\n <Header\n element={ element }\n headerProvider={ headerProvider } />\n <div class=\"bio-properties-panel-scroll-container\">\n {\n groups.map(group => {\n\n const {\n component: GroupComponent = Group,\n id\n } = group;\n\n return <GroupComponent\n key={ id }\n element={ element }\n { ...group } />;\n })\n }\n </div>\n </div>\n </LayoutContext.Provider>\n </DescriptionContext.Provider>;\n}\n\n\n// helpers //////////////////\n\nfunction createLayoutContext(overrides) {\n return {\n ...DEFAULT_LAYOUT,\n ...overrides\n };\n}\n\nfunction createDescriptionContext(overrides) {\n return {\n ...DEFAULT_DESCRIPTION,\n ...overrides\n };\n}\n"],"file":"PropertiesPanel.js"}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'preact/hooks';
|
|
2
|
-
import classnames from 'classnames';
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {object} props
|
|
6
|
-
* @param {string} [props.class]
|
|
7
|
-
* @param {import('preact').Component[]} [props.menuItems]
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
12
|
-
import { jsxs as _jsxs } from "preact/jsx-runtime";
|
|
13
|
-
export function DropdownButton(props) {
|
|
14
|
-
const {
|
|
15
|
-
class: className,
|
|
16
|
-
children,
|
|
17
|
-
menuItems = []
|
|
18
|
-
} = props;
|
|
19
|
-
const dropdownRef = useRef(null);
|
|
20
|
-
const menuRef = useRef(null);
|
|
21
|
-
const [open, setOpen] = useState(false);
|
|
22
|
-
|
|
23
|
-
const close = () => setOpen(false);
|
|
24
|
-
|
|
25
|
-
function onDropdownToggle(event) {
|
|
26
|
-
if (menuRef.current && menuRef.current.contains(event.target)) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
event.stopPropagation();
|
|
31
|
-
setOpen(open => !open);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function onActionClick(event, action) {
|
|
35
|
-
event.stopPropagation();
|
|
36
|
-
close();
|
|
37
|
-
action();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
useGlobalClick([dropdownRef.current], () => close());
|
|
41
|
-
return _jsxs("div", {
|
|
42
|
-
class: classnames('bio-properties-panel-dropdown-button', {
|
|
43
|
-
open
|
|
44
|
-
}, className),
|
|
45
|
-
onClick: onDropdownToggle,
|
|
46
|
-
ref: dropdownRef,
|
|
47
|
-
children: [children, _jsx("div", {
|
|
48
|
-
class: "bio-properties-panel-dropdown-button__menu",
|
|
49
|
-
ref: menuRef,
|
|
50
|
-
children: menuItems.map((item, index) => _jsx(MenuItem, {
|
|
51
|
-
onClick: onActionClick,
|
|
52
|
-
item: item
|
|
53
|
-
}, index))
|
|
54
|
-
})]
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function MenuItem({
|
|
59
|
-
item,
|
|
60
|
-
onClick
|
|
61
|
-
}) {
|
|
62
|
-
if (item.separator) {
|
|
63
|
-
return _jsx("div", {
|
|
64
|
-
class: "bio-properties-panel-dropdown-button__menu-item bio-properties-panel-dropdown-button__menu-item--separator"
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (item.action) {
|
|
69
|
-
return _jsx("button", {
|
|
70
|
-
class: "bio-properties-panel-dropdown-button__menu-item bio-properties-panel-dropdown-button__menu-item--actionable",
|
|
71
|
-
onClick: event => onClick(event, item.action),
|
|
72
|
-
children: item.entry
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return _jsx("div", {
|
|
77
|
-
class: "bio-properties-panel-dropdown-button__menu-item",
|
|
78
|
-
children: item.entry
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
*
|
|
83
|
-
* @param {Array<null | Element>} ignoredElements
|
|
84
|
-
* @param {Function} callback
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
function useGlobalClick(ignoredElements, callback) {
|
|
89
|
-
useEffect(() => {
|
|
90
|
-
/**
|
|
91
|
-
* @param {MouseEvent} event
|
|
92
|
-
*/
|
|
93
|
-
function listener(event) {
|
|
94
|
-
if (ignoredElements.some(element => element && element.contains(event.target))) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
callback();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
document.addEventListener('click', listener, {
|
|
102
|
-
capture: true
|
|
103
|
-
});
|
|
104
|
-
return () => document.removeEventListener('click', listener, {
|
|
105
|
-
capture: true
|
|
106
|
-
});
|
|
107
|
-
}, [...ignoredElements, callback]);
|
|
108
|
-
}
|
|
109
|
-
//# sourceMappingURL=DropdownButton.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/DropdownButton.js"],"names":["useEffect","useRef","useState","classnames","DropdownButton","props","class","className","children","menuItems","dropdownRef","menuRef","open","setOpen","close","onDropdownToggle","event","current","contains","target","stopPropagation","onActionClick","action","useGlobalClick","map","item","index","MenuItem","onClick","separator","entry","ignoredElements","callback","listener","some","element","document","addEventListener","capture","removeEventListener"],"mappings":"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","sourcesContent":["import {\n useEffect,\n useRef,\n useState\n} from 'preact/hooks';\n\nimport classnames from 'classnames';\n\n/**\n *\n * @param {object} props\n * @param {string} [props.class]\n * @param {import('preact').Component[]} [props.menuItems]\n * @returns\n */\nexport function DropdownButton(props) {\n const {\n class: className,\n children,\n menuItems = []\n } = props;\n\n const dropdownRef = useRef(null);\n const menuRef = useRef(null);\n\n const [ open, setOpen ] = useState(false);\n const close = () => setOpen(false);\n\n function onDropdownToggle(event) {\n if (menuRef.current && menuRef.current.contains(event.target)) {\n return;\n }\n\n event.stopPropagation();\n\n setOpen(open => !open);\n }\n\n function onActionClick(event, action) {\n event.stopPropagation();\n\n close();\n action();\n }\n\n useGlobalClick([ dropdownRef.current ], () => close());\n\n return (\n <div\n class={ classnames('bio-properties-panel-dropdown-button', { open }, className) }\n onClick={ onDropdownToggle }\n ref={ dropdownRef }\n >\n { children }\n <div class=\"bio-properties-panel-dropdown-button__menu\" ref={ menuRef }>\n { menuItems.map((item, index) => (\n <MenuItem onClick={ onActionClick } item={ item } key={ index } />\n )) }\n </div>\n </div>\n );\n}\n\nfunction MenuItem({ item, onClick }) {\n if (item.separator) {\n return <div class=\"bio-properties-panel-dropdown-button__menu-item bio-properties-panel-dropdown-button__menu-item--separator\" />;\n }\n\n if (item.action) {\n return (<button\n class=\"bio-properties-panel-dropdown-button__menu-item bio-properties-panel-dropdown-button__menu-item--actionable\"\n onClick={ event => onClick(event, item.action) }\n >\n {item.entry}\n </button>);\n }\n\n return <div\n class=\"bio-properties-panel-dropdown-button__menu-item\"\n >\n {item.entry}\n </div>;\n}\n\n/**\n *\n * @param {Array<null | Element>} ignoredElements\n * @param {Function} callback\n */\nfunction useGlobalClick(ignoredElements, callback) {\n useEffect(() => {\n\n /**\n * @param {MouseEvent} event\n */\n function listener(event) {\n if (ignoredElements.some(element => element && element.contains(event.target))) {\n return;\n }\n\n callback();\n }\n\n document.addEventListener('click', listener, { capture: true });\n\n return () => document.removeEventListener('click', listener, { capture: true });\n }, [ ...ignoredElements, callback ]);\n}\n"],"file":"DropdownButton.js"}
|