@bpmn-io/properties-panel 2.2.1 → 3.0.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.esm.js +12 -64
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +12 -64
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/preact/README.md +56 -51
- package/preact/compat/client.js +19 -0
- package/preact/compat/client.mjs +22 -0
- package/preact/compat/dist/compat.js +1 -1
- package/preact/compat/dist/compat.js.map +1 -1
- package/preact/compat/dist/compat.mjs +1 -1
- package/preact/compat/dist/compat.module.js +1 -1
- package/preact/compat/dist/compat.module.js.map +1 -1
- package/preact/compat/dist/compat.umd.js +1 -1
- package/preact/compat/dist/compat.umd.js.map +1 -1
- package/preact/compat/jsx-dev-runtime.js +2 -0
- package/preact/compat/jsx-dev-runtime.mjs +2 -0
- package/preact/compat/jsx-runtime.js +2 -0
- package/preact/compat/jsx-runtime.mjs +2 -0
- package/preact/compat/package.json +31 -0
- package/preact/compat/scheduler.js +15 -0
- package/preact/compat/{src/scheduler.js → scheduler.mjs} +8 -9
- package/preact/compat/server.browser.js +4 -0
- package/preact/compat/src/PureComponent.js +1 -1
- package/preact/compat/src/forwardRef.js +2 -9
- package/preact/compat/src/index.d.ts +58 -4
- package/preact/compat/src/index.js +73 -2
- package/preact/compat/src/portals.js +4 -2
- package/preact/compat/src/render.js +133 -76
- package/preact/compat/src/suspense-list.d.ts +2 -2
- package/preact/compat/src/suspense-list.js +14 -13
- package/preact/compat/src/suspense.d.ts +4 -4
- package/preact/compat/src/suspense.js +6 -6
- package/preact/compat/src/util.js +10 -0
- package/preact/debug/dist/debug.js +1 -1
- package/preact/debug/dist/debug.js.map +1 -1
- package/preact/debug/dist/debug.mjs +1 -1
- package/preact/debug/dist/debug.module.js +1 -1
- package/preact/debug/dist/debug.module.js.map +1 -1
- package/preact/debug/dist/debug.umd.js +1 -1
- package/preact/debug/dist/debug.umd.js.map +1 -1
- package/preact/debug/package.json +9 -0
- package/preact/debug/src/check-props.js +3 -3
- package/preact/debug/src/debug.js +38 -17
- package/preact/debug/src/index.d.ts +4 -0
- package/preact/debug/src/util.js +4 -0
- package/preact/devtools/dist/devtools.js +1 -1
- package/preact/devtools/dist/devtools.js.map +1 -1
- package/preact/devtools/dist/devtools.mjs +1 -1
- package/preact/devtools/dist/devtools.module.js +1 -1
- package/preact/devtools/dist/devtools.module.js.map +1 -1
- package/preact/devtools/dist/devtools.umd.js +1 -1
- package/preact/devtools/dist/devtools.umd.js.map +1 -1
- package/preact/devtools/package.json +23 -14
- package/preact/devtools/src/devtools.js +1 -1
- package/preact/dist/preact.js +1 -1
- package/preact/dist/preact.js.map +1 -1
- package/preact/dist/preact.min.js +1 -1
- package/preact/dist/preact.min.js.map +1 -1
- package/preact/dist/preact.min.module.js +2 -0
- package/preact/dist/preact.min.module.js.map +1 -0
- package/preact/dist/preact.min.umd.js +2 -0
- package/preact/dist/preact.min.umd.js.map +1 -0
- package/preact/dist/preact.mjs +1 -1
- package/preact/dist/preact.module.js +1 -1
- package/preact/dist/preact.module.js.map +1 -1
- package/preact/dist/preact.umd.js +1 -1
- package/preact/dist/preact.umd.js.map +1 -1
- package/preact/hooks/dist/hooks.js +1 -1
- package/preact/hooks/dist/hooks.js.map +1 -1
- package/preact/hooks/dist/hooks.mjs +1 -1
- package/preact/hooks/dist/hooks.module.js +1 -1
- package/preact/hooks/dist/hooks.module.js.map +1 -1
- package/preact/hooks/dist/hooks.umd.js +1 -1
- package/preact/hooks/dist/hooks.umd.js.map +1 -1
- package/preact/hooks/package.json +9 -0
- package/preact/hooks/src/index.d.ts +26 -14
- package/preact/hooks/src/index.js +169 -44
- package/preact/hooks/src/internal.d.ts +12 -2
- package/preact/jsx-runtime/dist/jsxRuntime.js +1 -1
- package/preact/jsx-runtime/dist/jsxRuntime.js.map +1 -1
- package/preact/jsx-runtime/dist/jsxRuntime.mjs +1 -1
- package/preact/jsx-runtime/dist/jsxRuntime.module.js +1 -1
- package/preact/jsx-runtime/dist/jsxRuntime.module.js.map +1 -1
- package/preact/jsx-runtime/dist/jsxRuntime.umd.js +1 -1
- package/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +1 -1
- package/preact/jsx-runtime/package.json +26 -17
- package/preact/jsx-runtime/src/index.js +19 -13
- package/preact/package.json +315 -262
- package/preact/src/clone-element.js +16 -10
- package/preact/src/component.js +33 -23
- package/preact/src/constants.js +2 -1
- package/preact/src/create-context.js +8 -3
- package/preact/src/create-element.js +9 -11
- package/preact/src/diff/catch-error.js +4 -2
- package/preact/src/diff/children.js +41 -32
- package/preact/src/diff/index.js +81 -34
- package/preact/src/diff/props.js +15 -14
- package/preact/src/index.d.ts +369 -301
- package/preact/src/internal.d.ts +11 -2
- package/preact/src/jsx.d.ts +1862 -626
- package/preact/src/options.js +1 -2
- package/preact/src/render.js +5 -6
- package/preact/src/util.js +6 -0
- package/preact/test-utils/dist/testUtils.js +1 -1
- package/preact/test-utils/dist/testUtils.js.map +1 -1
- package/preact/test-utils/dist/testUtils.mjs +1 -1
- package/preact/test-utils/dist/testUtils.module.js +1 -1
- package/preact/test-utils/dist/testUtils.module.js.map +1 -1
- package/preact/test-utils/dist/testUtils.umd.js +1 -1
- package/preact/test-utils/dist/testUtils.umd.js.map +1 -1
- package/preact/test-utils/package.json +9 -0
- package/preact/test-utils/src/index.js +2 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assign } from './util';
|
|
1
|
+
import { assign, slice } from './util';
|
|
2
2
|
import { createVNode } from './create-element';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -13,20 +13,26 @@ export function cloneElement(vnode, props, children) {
|
|
|
13
13
|
key,
|
|
14
14
|
ref,
|
|
15
15
|
i;
|
|
16
|
+
|
|
17
|
+
let defaultProps;
|
|
18
|
+
|
|
19
|
+
if (vnode.type && vnode.type.defaultProps) {
|
|
20
|
+
defaultProps = vnode.type.defaultProps;
|
|
21
|
+
}
|
|
22
|
+
|
|
16
23
|
for (i in props) {
|
|
17
24
|
if (i == 'key') key = props[i];
|
|
18
25
|
else if (i == 'ref') ref = props[i];
|
|
19
|
-
else
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
children = [children];
|
|
24
|
-
for (i = 3; i < arguments.length; i++) {
|
|
25
|
-
children.push(arguments[i]);
|
|
26
|
+
else if (props[i] === undefined && defaultProps !== undefined) {
|
|
27
|
+
normalizedProps[i] = defaultProps[i];
|
|
28
|
+
} else {
|
|
29
|
+
normalizedProps[i] = props[i];
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
|
|
33
|
+
if (arguments.length > 2) {
|
|
34
|
+
normalizedProps.children =
|
|
35
|
+
arguments.length > 3 ? slice.call(arguments, 2) : children;
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
return createVNode(
|
package/preact/src/component.js
CHANGED
|
@@ -24,7 +24,7 @@ export function Component(props, context) {
|
|
|
24
24
|
* @param {() => void} [callback] A function to be called once component state is
|
|
25
25
|
* updated
|
|
26
26
|
*/
|
|
27
|
-
Component.prototype.setState = function(update, callback) {
|
|
27
|
+
Component.prototype.setState = function (update, callback) {
|
|
28
28
|
// only clone state when copying to nextState the first time.
|
|
29
29
|
let s;
|
|
30
30
|
if (this._nextState != null && this._nextState !== this.state) {
|
|
@@ -47,7 +47,9 @@ Component.prototype.setState = function(update, callback) {
|
|
|
47
47
|
if (update == null) return;
|
|
48
48
|
|
|
49
49
|
if (this._vnode) {
|
|
50
|
-
if (callback)
|
|
50
|
+
if (callback) {
|
|
51
|
+
this._stateCallbacks.push(callback);
|
|
52
|
+
}
|
|
51
53
|
enqueueRender(this);
|
|
52
54
|
}
|
|
53
55
|
};
|
|
@@ -58,7 +60,7 @@ Component.prototype.setState = function(update, callback) {
|
|
|
58
60
|
* @param {() => void} [callback] A function to be called after component is
|
|
59
61
|
* re-rendered
|
|
60
62
|
*/
|
|
61
|
-
Component.prototype.forceUpdate = function(callback) {
|
|
63
|
+
Component.prototype.forceUpdate = function (callback) {
|
|
62
64
|
if (this._vnode) {
|
|
63
65
|
// Set render mode so that we can differentiate where the render request
|
|
64
66
|
// is coming from. We need this because forceUpdate should never call
|
|
@@ -170,17 +172,6 @@ function updateParentDomPointers(vnode) {
|
|
|
170
172
|
*/
|
|
171
173
|
let rerenderQueue = [];
|
|
172
174
|
|
|
173
|
-
/**
|
|
174
|
-
* Asynchronously schedule a callback
|
|
175
|
-
* @type {(cb: () => void) => void}
|
|
176
|
-
*/
|
|
177
|
-
/* istanbul ignore next */
|
|
178
|
-
// Note the following line isn't tree-shaken by rollup cuz of rollup/rollup#2566
|
|
179
|
-
const defer =
|
|
180
|
-
typeof Promise == 'function'
|
|
181
|
-
? Promise.prototype.then.bind(Promise.resolve())
|
|
182
|
-
: setTimeout;
|
|
183
|
-
|
|
184
175
|
/*
|
|
185
176
|
* The value of `Component.debounce` must asynchronously invoke the passed in callback. It is
|
|
186
177
|
* important that contributors to Preact can consistently reason about what calls to `setState`, etc.
|
|
@@ -192,6 +183,11 @@ const defer =
|
|
|
192
183
|
|
|
193
184
|
let prevDebounce;
|
|
194
185
|
|
|
186
|
+
const defer =
|
|
187
|
+
typeof Promise == 'function'
|
|
188
|
+
? Promise.prototype.then.bind(Promise.resolve())
|
|
189
|
+
: setTimeout;
|
|
190
|
+
|
|
195
191
|
/**
|
|
196
192
|
* Enqueue a rerender of a component
|
|
197
193
|
* @param {import('./internal').Component} c The component to rerender
|
|
@@ -209,17 +205,31 @@ export function enqueueRender(c) {
|
|
|
209
205
|
}
|
|
210
206
|
}
|
|
211
207
|
|
|
208
|
+
/**
|
|
209
|
+
* @param {import('./internal').Component} a
|
|
210
|
+
* @param {import('./internal').Component} b
|
|
211
|
+
*/
|
|
212
|
+
const depthSort = (a, b) => a._vnode._depth - b._vnode._depth;
|
|
213
|
+
|
|
212
214
|
/** Flush the render queue by rerendering all queued components */
|
|
213
215
|
function process() {
|
|
214
|
-
let
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
216
|
+
let c;
|
|
217
|
+
rerenderQueue.sort(depthSort);
|
|
218
|
+
// Don't update `renderCount` yet. Keep its value non-zero to prevent unnecessary
|
|
219
|
+
// process() calls from getting scheduled while `queue` is still being consumed.
|
|
220
|
+
while ((c = rerenderQueue.shift())) {
|
|
221
|
+
if (c._dirty) {
|
|
222
|
+
let renderQueueLength = rerenderQueue.length;
|
|
223
|
+
renderComponent(c);
|
|
224
|
+
if (rerenderQueue.length > renderQueueLength) {
|
|
225
|
+
// When i.e. rerendering a provider additional new items can be injected, we want to
|
|
226
|
+
// keep the order from top to bottom with those new items so we can handle them in a
|
|
227
|
+
// single pass
|
|
228
|
+
rerenderQueue.sort(depthSort);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
223
231
|
}
|
|
232
|
+
process._rerenderCount = 0;
|
|
224
233
|
}
|
|
234
|
+
|
|
225
235
|
process._rerenderCount = 0;
|
package/preact/src/constants.js
CHANGED
|
@@ -18,13 +18,14 @@ export function createContext(defaultValue, contextId) {
|
|
|
18
18
|
/** @type {import('./internal').FunctionComponent} */
|
|
19
19
|
Provider(props) {
|
|
20
20
|
if (!this.getChildContext) {
|
|
21
|
+
/** @type {import('./internal').Component[]} */
|
|
21
22
|
let subs = [];
|
|
22
23
|
let ctx = {};
|
|
23
24
|
ctx[contextId] = this;
|
|
24
25
|
|
|
25
26
|
this.getChildContext = () => ctx;
|
|
26
27
|
|
|
27
|
-
this.shouldComponentUpdate = function(_props) {
|
|
28
|
+
this.shouldComponentUpdate = function (_props) {
|
|
28
29
|
if (this.props.value !== _props.value) {
|
|
29
30
|
// I think the forced value propagation here was only needed when `options.debounceRendering` was being bypassed:
|
|
30
31
|
// https://github.com/preactjs/preact/commit/4d339fb803bea09e9f198abf38ca1bf8ea4b7771#diff-54682ce380935a717e41b8bfc54737f6R358
|
|
@@ -40,7 +41,10 @@ export function createContext(defaultValue, contextId) {
|
|
|
40
41
|
// c.context[contextId] = _props.value;
|
|
41
42
|
// enqueueRender(c);
|
|
42
43
|
// });
|
|
43
|
-
subs.some(
|
|
44
|
+
subs.some(c => {
|
|
45
|
+
c._force = true;
|
|
46
|
+
enqueueRender(c);
|
|
47
|
+
});
|
|
44
48
|
}
|
|
45
49
|
};
|
|
46
50
|
|
|
@@ -64,5 +68,6 @@ export function createContext(defaultValue, contextId) {
|
|
|
64
68
|
// of on the component itself. See:
|
|
65
69
|
// https://reactjs.org/docs/context.html#contextdisplayname
|
|
66
70
|
|
|
67
|
-
return (context.Provider._contextRef = context.Consumer.contextType =
|
|
71
|
+
return (context.Provider._contextRef = context.Consumer.contextType =
|
|
72
|
+
context);
|
|
68
73
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { slice } from './util';
|
|
1
2
|
import options from './options';
|
|
2
3
|
|
|
4
|
+
let vnodeId = 0;
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
7
|
* Create an virtual node (used for JSX)
|
|
5
8
|
* @param {import('./internal').VNode["type"]} type The node name or Component
|
|
@@ -19,15 +22,9 @@ export function createElement(type, props, children) {
|
|
|
19
22
|
else normalizedProps[i] = props[i];
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
if (arguments.length >
|
|
23
|
-
children =
|
|
24
|
-
|
|
25
|
-
for (i = 3; i < arguments.length; i++) {
|
|
26
|
-
children.push(arguments[i]);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (children != null) {
|
|
30
|
-
normalizedProps.children = children;
|
|
25
|
+
if (arguments.length > 2) {
|
|
26
|
+
normalizedProps.children =
|
|
27
|
+
arguments.length > 3 ? slice.call(arguments, 2) : children;
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
// If a Component VNode, check for and apply defaultProps
|
|
@@ -75,10 +72,11 @@ export function createVNode(type, props, key, ref, original) {
|
|
|
75
72
|
_component: null,
|
|
76
73
|
_hydrating: null,
|
|
77
74
|
constructor: undefined,
|
|
78
|
-
_original: original == null ? ++
|
|
75
|
+
_original: original == null ? ++vnodeId : original
|
|
79
76
|
};
|
|
80
77
|
|
|
81
|
-
|
|
78
|
+
// Only invoke the vnode hook if this was *not* a direct copy:
|
|
79
|
+
if (original == null && options.vnode != null) options.vnode(vnode);
|
|
82
80
|
|
|
83
81
|
return vnode;
|
|
84
82
|
}
|
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
* @param {import('../internal').VNode} vnode The vnode that threw
|
|
5
5
|
* the error that was caught (except for unmounting when this parameter
|
|
6
6
|
* is the highest parent that was being unmounted)
|
|
7
|
+
* @param {import('../internal').VNode} [oldVNode]
|
|
8
|
+
* @param {import('../internal').ErrorInfo} [errorInfo]
|
|
7
9
|
*/
|
|
8
|
-
export function _catchError(error, vnode) {
|
|
10
|
+
export function _catchError(error, vnode, oldVNode, errorInfo) {
|
|
9
11
|
/** @type {import('../internal').Component} */
|
|
10
12
|
let component, ctor, handled;
|
|
11
13
|
|
|
@@ -20,7 +22,7 @@ export function _catchError(error, vnode) {
|
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
if (component.componentDidCatch != null) {
|
|
23
|
-
component.componentDidCatch(error);
|
|
25
|
+
component.componentDidCatch(error, errorInfo || {});
|
|
24
26
|
handled = component._dirty;
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -2,6 +2,7 @@ import { diff, unmount, applyRef } from './index';
|
|
|
2
2
|
import { createVNode, Fragment } from '../create-element';
|
|
3
3
|
import { EMPTY_OBJ, EMPTY_ARR } from '../constants';
|
|
4
4
|
import { getDomSibling } from '../component';
|
|
5
|
+
import { isArray } from '../util';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Diff the children of a virtual node
|
|
@@ -47,7 +48,11 @@ export function diffChildren(
|
|
|
47
48
|
for (i = 0; i < renderResult.length; i++) {
|
|
48
49
|
childVNode = renderResult[i];
|
|
49
50
|
|
|
50
|
-
if (
|
|
51
|
+
if (
|
|
52
|
+
childVNode == null ||
|
|
53
|
+
typeof childVNode == 'boolean' ||
|
|
54
|
+
typeof childVNode == 'function'
|
|
55
|
+
) {
|
|
51
56
|
childVNode = newParentVNode._children[i] = null;
|
|
52
57
|
}
|
|
53
58
|
// If this newVNode is being reused (e.g. <div>{reuse}{reuse}</div>) in the same diff,
|
|
@@ -66,7 +71,7 @@ export function diffChildren(
|
|
|
66
71
|
null,
|
|
67
72
|
childVNode
|
|
68
73
|
);
|
|
69
|
-
} else if (
|
|
74
|
+
} else if (isArray(childVNode)) {
|
|
70
75
|
childVNode = newParentVNode._children[i] = createVNode(
|
|
71
76
|
Fragment,
|
|
72
77
|
{ children: childVNode },
|
|
@@ -83,7 +88,7 @@ export function diffChildren(
|
|
|
83
88
|
childVNode.type,
|
|
84
89
|
childVNode.props,
|
|
85
90
|
childVNode.key,
|
|
86
|
-
null,
|
|
91
|
+
childVNode.ref ? childVNode.ref : null,
|
|
87
92
|
childVNode._original
|
|
88
93
|
);
|
|
89
94
|
} else {
|
|
@@ -161,7 +166,6 @@ export function diffChildren(
|
|
|
161
166
|
|
|
162
167
|
if (
|
|
163
168
|
typeof childVNode.type == 'function' &&
|
|
164
|
-
childVNode._children != null && // Can be null if childVNode suspended
|
|
165
169
|
childVNode._children === oldVNode._children
|
|
166
170
|
) {
|
|
167
171
|
childVNode._nextDom = oldDom = reorderChildren(
|
|
@@ -180,21 +184,7 @@ export function diffChildren(
|
|
|
180
184
|
);
|
|
181
185
|
}
|
|
182
186
|
|
|
183
|
-
|
|
184
|
-
// no value is present. This essentially bypasses our code to set it
|
|
185
|
-
// later in `diff()`. It works fine in all browsers except for IE11
|
|
186
|
-
// where it breaks setting `select.value`. There it will be always set
|
|
187
|
-
// to an empty string. Re-applying an options value will fix that, so
|
|
188
|
-
// there are probably some internal data structures that aren't
|
|
189
|
-
// updated properly.
|
|
190
|
-
//
|
|
191
|
-
// To fix it we make sure to reset the inferred value, so that our own
|
|
192
|
-
// value check in `diff()` won't be skipped.
|
|
193
|
-
if (!isHydrating && newParentVNode.type === 'option') {
|
|
194
|
-
// @ts-ignore We have validated that the type of parentDOM is 'option'
|
|
195
|
-
// in the above check
|
|
196
|
-
parentDom.value = '';
|
|
197
|
-
} else if (typeof newParentVNode.type == 'function') {
|
|
187
|
+
if (typeof newParentVNode.type == 'function') {
|
|
198
188
|
// Because the newParentVNode is Fragment-like, we need to set it's
|
|
199
189
|
// _nextDom property to the nextSibling of its last child DOM node.
|
|
200
190
|
//
|
|
@@ -228,7 +218,7 @@ export function diffChildren(
|
|
|
228
218
|
// If the newParentVNode.__nextDom points to a dom node that is about to
|
|
229
219
|
// be unmounted, then get the next sibling of that vnode and set
|
|
230
220
|
// _nextDom to it
|
|
231
|
-
newParentVNode._nextDom =
|
|
221
|
+
newParentVNode._nextDom = getLastDom(oldParentVNode).nextSibling;
|
|
232
222
|
}
|
|
233
223
|
|
|
234
224
|
unmount(oldChildren[i], oldChildren[i]);
|
|
@@ -244,8 +234,11 @@ export function diffChildren(
|
|
|
244
234
|
}
|
|
245
235
|
|
|
246
236
|
function reorderChildren(childVNode, oldDom, parentDom) {
|
|
247
|
-
|
|
248
|
-
|
|
237
|
+
// Note: VNodes in nested suspended trees may be missing _children.
|
|
238
|
+
let c = childVNode._children;
|
|
239
|
+
let tmp = 0;
|
|
240
|
+
for (; c && tmp < c.length; tmp++) {
|
|
241
|
+
let vnode = c[tmp];
|
|
249
242
|
if (vnode) {
|
|
250
243
|
// We typically enter this code path on sCU bailout, where we copy
|
|
251
244
|
// oldVNode._children to newVNode._children. If that is the case, we need
|
|
@@ -256,14 +249,7 @@ function reorderChildren(childVNode, oldDom, parentDom) {
|
|
|
256
249
|
if (typeof vnode.type == 'function') {
|
|
257
250
|
oldDom = reorderChildren(vnode, oldDom, parentDom);
|
|
258
251
|
} else {
|
|
259
|
-
oldDom = placeChild(
|
|
260
|
-
parentDom,
|
|
261
|
-
vnode,
|
|
262
|
-
vnode,
|
|
263
|
-
childVNode._children,
|
|
264
|
-
vnode._dom,
|
|
265
|
-
oldDom
|
|
266
|
-
);
|
|
252
|
+
oldDom = placeChild(parentDom, vnode, vnode, c, vnode._dom, oldDom);
|
|
267
253
|
}
|
|
268
254
|
}
|
|
269
255
|
}
|
|
@@ -280,7 +266,7 @@ function reorderChildren(childVNode, oldDom, parentDom) {
|
|
|
280
266
|
export function toChildArray(children, out) {
|
|
281
267
|
out = out || [];
|
|
282
268
|
if (children == null || typeof children == 'boolean') {
|
|
283
|
-
} else if (
|
|
269
|
+
} else if (isArray(children)) {
|
|
284
270
|
children.some(child => {
|
|
285
271
|
toChildArray(child, out);
|
|
286
272
|
});
|
|
@@ -323,7 +309,7 @@ function placeChild(
|
|
|
323
309
|
for (
|
|
324
310
|
let sibDom = oldDom, j = 0;
|
|
325
311
|
(sibDom = sibDom.nextSibling) && j < oldChildren.length;
|
|
326
|
-
j +=
|
|
312
|
+
j += 1
|
|
327
313
|
) {
|
|
328
314
|
if (sibDom == newDom) {
|
|
329
315
|
break outer;
|
|
@@ -345,3 +331,26 @@ function placeChild(
|
|
|
345
331
|
|
|
346
332
|
return oldDom;
|
|
347
333
|
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* @param {import('../internal').VNode} vnode
|
|
337
|
+
*/
|
|
338
|
+
function getLastDom(vnode) {
|
|
339
|
+
if (vnode.type == null || typeof vnode.type === 'string') {
|
|
340
|
+
return vnode._dom;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (vnode._children) {
|
|
344
|
+
for (let i = vnode._children.length - 1; i >= 0; i--) {
|
|
345
|
+
let child = vnode._children[i];
|
|
346
|
+
if (child) {
|
|
347
|
+
let lastDom = getLastDom(child);
|
|
348
|
+
if (lastDom) {
|
|
349
|
+
return lastDom;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return null;
|
|
356
|
+
}
|
package/preact/src/diff/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { EMPTY_OBJ
|
|
2
|
-
import { Component } from '../component';
|
|
1
|
+
import { EMPTY_OBJ } from '../constants';
|
|
2
|
+
import { Component, getDomSibling } from '../component';
|
|
3
3
|
import { Fragment } from '../create-element';
|
|
4
4
|
import { diffChildren } from './children';
|
|
5
5
|
import { diffProps, setProperty } from './props';
|
|
6
|
-
import { assign, removeNode } from '../util';
|
|
6
|
+
import { assign, isArray, removeNode, slice } from '../util';
|
|
7
7
|
import options from '../options';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -89,12 +89,14 @@ export function diff(
|
|
|
89
89
|
c._globalContext = globalContext;
|
|
90
90
|
isNew = c._dirty = true;
|
|
91
91
|
c._renderCallbacks = [];
|
|
92
|
+
c._stateCallbacks = [];
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
// Invoke getDerivedStateFromProps
|
|
95
96
|
if (c._nextState == null) {
|
|
96
97
|
c._nextState = c.state;
|
|
97
98
|
}
|
|
99
|
+
|
|
98
100
|
if (newType.getDerivedStateFromProps != null) {
|
|
99
101
|
if (c._nextState == c.state) {
|
|
100
102
|
c._nextState = assign({}, c._nextState);
|
|
@@ -108,6 +110,7 @@ export function diff(
|
|
|
108
110
|
|
|
109
111
|
oldProps = c.props;
|
|
110
112
|
oldState = c.state;
|
|
113
|
+
c._vnode = newVNode;
|
|
111
114
|
|
|
112
115
|
// Invoke pre-render lifecycle methods
|
|
113
116
|
if (isNew) {
|
|
@@ -140,16 +143,30 @@ export function diff(
|
|
|
140
143
|
) === false) ||
|
|
141
144
|
newVNode._original === oldVNode._original
|
|
142
145
|
) {
|
|
143
|
-
c.props = newProps;
|
|
144
|
-
c.state = c._nextState;
|
|
145
146
|
// More info about this here: https://gist.github.com/JoviDeCroock/bec5f2ce93544d2e6070ef8e0036e4e8
|
|
146
|
-
if (newVNode._original !== oldVNode._original)
|
|
147
|
-
|
|
147
|
+
if (newVNode._original !== oldVNode._original) {
|
|
148
|
+
// When we are dealing with a bail because of sCU we have to update
|
|
149
|
+
// the props, state and dirty-state.
|
|
150
|
+
// when we are dealing with strict-equality we don't as the child could still
|
|
151
|
+
// be dirtied see #3883
|
|
152
|
+
c.props = newProps;
|
|
153
|
+
c.state = c._nextState;
|
|
154
|
+
c._dirty = false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// In cases of bailing due to strict-equality we have to reset force as well
|
|
158
|
+
c._force = false;
|
|
148
159
|
newVNode._dom = oldVNode._dom;
|
|
149
160
|
newVNode._children = oldVNode._children;
|
|
150
161
|
newVNode._children.forEach(vnode => {
|
|
151
162
|
if (vnode) vnode._parent = newVNode;
|
|
152
163
|
});
|
|
164
|
+
|
|
165
|
+
for (let i = 0; i < c._stateCallbacks.length; i++) {
|
|
166
|
+
c._renderCallbacks.push(c._stateCallbacks[i]);
|
|
167
|
+
}
|
|
168
|
+
c._stateCallbacks = [];
|
|
169
|
+
|
|
153
170
|
if (c._renderCallbacks.length) {
|
|
154
171
|
commitQueue.push(c);
|
|
155
172
|
}
|
|
@@ -170,15 +187,33 @@ export function diff(
|
|
|
170
187
|
|
|
171
188
|
c.context = componentContext;
|
|
172
189
|
c.props = newProps;
|
|
173
|
-
c.
|
|
190
|
+
c._parentDom = parentDom;
|
|
174
191
|
|
|
175
|
-
|
|
192
|
+
let renderHook = options._render,
|
|
193
|
+
count = 0;
|
|
194
|
+
if ('prototype' in newType && newType.prototype.render) {
|
|
195
|
+
c.state = c._nextState;
|
|
196
|
+
c._dirty = false;
|
|
176
197
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
198
|
+
if (renderHook) renderHook(newVNode);
|
|
199
|
+
|
|
200
|
+
tmp = c.render(c.props, c.state, c.context);
|
|
201
|
+
|
|
202
|
+
for (let i = 0; i < c._stateCallbacks.length; i++) {
|
|
203
|
+
c._renderCallbacks.push(c._stateCallbacks[i]);
|
|
204
|
+
}
|
|
205
|
+
c._stateCallbacks = [];
|
|
206
|
+
} else {
|
|
207
|
+
do {
|
|
208
|
+
c._dirty = false;
|
|
209
|
+
if (renderHook) renderHook(newVNode);
|
|
180
210
|
|
|
181
|
-
|
|
211
|
+
tmp = c.render(c.props, c.state, c.context);
|
|
212
|
+
|
|
213
|
+
// Handle setState called in render, see #2553
|
|
214
|
+
c.state = c._nextState;
|
|
215
|
+
} while (c._dirty && ++count < 25);
|
|
216
|
+
}
|
|
182
217
|
|
|
183
218
|
// Handle setState called in render, see #2553
|
|
184
219
|
c.state = c._nextState;
|
|
@@ -197,7 +232,7 @@ export function diff(
|
|
|
197
232
|
|
|
198
233
|
diffChildren(
|
|
199
234
|
parentDom,
|
|
200
|
-
|
|
235
|
+
isArray(renderResult) ? renderResult : [renderResult],
|
|
201
236
|
newVNode,
|
|
202
237
|
oldVNode,
|
|
203
238
|
globalContext,
|
|
@@ -320,8 +355,8 @@ function diffElementNodes(
|
|
|
320
355
|
// excessDomChildren so it isn't later removed in diffChildren
|
|
321
356
|
if (
|
|
322
357
|
child &&
|
|
323
|
-
|
|
324
|
-
|
|
358
|
+
'setAttribute' in child === !!nodeType &&
|
|
359
|
+
(nodeType ? child.localName === nodeType : child.nodeType === 3)
|
|
325
360
|
) {
|
|
326
361
|
dom = child;
|
|
327
362
|
excessDomChildren[i] = null;
|
|
@@ -363,8 +398,7 @@ function diffElementNodes(
|
|
|
363
398
|
}
|
|
364
399
|
} else {
|
|
365
400
|
// If excessDomChildren was not null, repopulate it with the current element's children:
|
|
366
|
-
excessDomChildren =
|
|
367
|
-
excessDomChildren && EMPTY_ARR.slice.call(dom.childNodes);
|
|
401
|
+
excessDomChildren = excessDomChildren && slice.call(dom.childNodes);
|
|
368
402
|
|
|
369
403
|
oldProps = oldVNode.props || EMPTY_OBJ;
|
|
370
404
|
|
|
@@ -378,7 +412,7 @@ function diffElementNodes(
|
|
|
378
412
|
// we should read the existing DOM attributes to diff them
|
|
379
413
|
if (excessDomChildren != null) {
|
|
380
414
|
oldProps = {};
|
|
381
|
-
for (
|
|
415
|
+
for (i = 0; i < dom.attributes.length; i++) {
|
|
382
416
|
oldProps[dom.attributes[i].name] = dom.attributes[i].value;
|
|
383
417
|
}
|
|
384
418
|
}
|
|
@@ -404,14 +438,16 @@ function diffElementNodes(
|
|
|
404
438
|
i = newVNode.props.children;
|
|
405
439
|
diffChildren(
|
|
406
440
|
dom,
|
|
407
|
-
|
|
441
|
+
isArray(i) ? i : [i],
|
|
408
442
|
newVNode,
|
|
409
443
|
oldVNode,
|
|
410
444
|
globalContext,
|
|
411
445
|
isSvg && nodeType !== 'foreignObject',
|
|
412
446
|
excessDomChildren,
|
|
413
447
|
commitQueue,
|
|
414
|
-
|
|
448
|
+
excessDomChildren
|
|
449
|
+
? excessDomChildren[0]
|
|
450
|
+
: oldVNode._children && getDomSibling(oldVNode, 0),
|
|
415
451
|
isHydrating
|
|
416
452
|
);
|
|
417
453
|
|
|
@@ -432,7 +468,12 @@ function diffElementNodes(
|
|
|
432
468
|
// despite the attribute not being present. When the attribute
|
|
433
469
|
// is missing the progress bar is treated as indeterminate.
|
|
434
470
|
// To fix that we'll always update it when it is 0 for progress elements
|
|
435
|
-
(i !== dom.value ||
|
|
471
|
+
(i !== dom.value ||
|
|
472
|
+
(nodeType === 'progress' && !i) ||
|
|
473
|
+
// This is only for IE 11 to fix <select> value not being updated.
|
|
474
|
+
// To avoid a stale select value we need to set the option.value
|
|
475
|
+
// again, which triggers IE11 to re-evaluate the select value
|
|
476
|
+
(nodeType === 'option' && i !== oldProps.value))
|
|
436
477
|
) {
|
|
437
478
|
setProperty(dom, 'value', i, oldProps.value, false);
|
|
438
479
|
}
|
|
@@ -477,18 +518,11 @@ export function unmount(vnode, parentVNode, skipRemove) {
|
|
|
477
518
|
if (options.unmount) options.unmount(vnode);
|
|
478
519
|
|
|
479
520
|
if ((r = vnode.ref)) {
|
|
480
|
-
if (!r.current || r.current === vnode._dom)
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
let dom;
|
|
484
|
-
if (!skipRemove && typeof vnode.type != 'function') {
|
|
485
|
-
skipRemove = (dom = vnode._dom) != null;
|
|
521
|
+
if (!r.current || r.current === vnode._dom) {
|
|
522
|
+
applyRef(r, null, parentVNode);
|
|
523
|
+
}
|
|
486
524
|
}
|
|
487
525
|
|
|
488
|
-
// Must be set to `undefined` to properly clean up `_nextDom`
|
|
489
|
-
// for which `null` is a valid value. See comment in `create-element.js`
|
|
490
|
-
vnode._dom = vnode._nextDom = undefined;
|
|
491
|
-
|
|
492
526
|
if ((r = vnode._component) != null) {
|
|
493
527
|
if (r.componentWillUnmount) {
|
|
494
528
|
try {
|
|
@@ -499,15 +533,28 @@ export function unmount(vnode, parentVNode, skipRemove) {
|
|
|
499
533
|
}
|
|
500
534
|
|
|
501
535
|
r.base = r._parentDom = null;
|
|
536
|
+
vnode._component = undefined;
|
|
502
537
|
}
|
|
503
538
|
|
|
504
539
|
if ((r = vnode._children)) {
|
|
505
540
|
for (let i = 0; i < r.length; i++) {
|
|
506
|
-
if (r[i])
|
|
541
|
+
if (r[i]) {
|
|
542
|
+
unmount(
|
|
543
|
+
r[i],
|
|
544
|
+
parentVNode,
|
|
545
|
+
skipRemove || typeof vnode.type !== 'function'
|
|
546
|
+
);
|
|
547
|
+
}
|
|
507
548
|
}
|
|
508
549
|
}
|
|
509
550
|
|
|
510
|
-
if (
|
|
551
|
+
if (!skipRemove && vnode._dom != null) {
|
|
552
|
+
removeNode(vnode._dom);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// Must be set to `undefined` to properly clean up `_nextDom`
|
|
556
|
+
// for which `null` is a valid value. See comment in `create-element.js`
|
|
557
|
+
vnode._parent = vnode._dom = vnode._nextDom = undefined;
|
|
511
558
|
}
|
|
512
559
|
|
|
513
560
|
/** The `.render()` method for a PFC backing instance. */
|