@faiwer/react 0.8.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/README.md +90 -0
- package/dist/core/actions/applyAction.d.ts +11 -0
- package/dist/core/actions/applyAction.d.ts.map +1 -0
- package/dist/core/actions/applyAction.js +35 -0
- package/dist/core/actions/applyAction.js.map +1 -0
- package/dist/core/actions/createComment.action.d.ts +7 -0
- package/dist/core/actions/createComment.action.d.ts.map +1 -0
- package/dist/core/actions/createComment.action.js +20 -0
- package/dist/core/actions/createComment.action.js.map +1 -0
- package/dist/core/actions/createTag.action.d.ts +10 -0
- package/dist/core/actions/createTag.action.d.ts.map +1 -0
- package/dist/core/actions/createTag.action.js +27 -0
- package/dist/core/actions/createTag.action.js.map +1 -0
- package/dist/core/actions/createText.action.d.ts +6 -0
- package/dist/core/actions/createText.action.d.ts.map +1 -0
- package/dist/core/actions/createText.action.js +16 -0
- package/dist/core/actions/createText.action.js.map +1 -0
- package/dist/core/actions/helpers.d.ts +43 -0
- package/dist/core/actions/helpers.d.ts.map +1 -0
- package/dist/core/actions/helpers.js +141 -0
- package/dist/core/actions/helpers.js.map +1 -0
- package/dist/core/actions/relayout.action.d.ts +20 -0
- package/dist/core/actions/relayout.action.d.ts.map +1 -0
- package/dist/core/actions/relayout.action.js +113 -0
- package/dist/core/actions/relayout.action.js.map +1 -0
- package/dist/core/actions/remove.action.d.ts +7 -0
- package/dist/core/actions/remove.action.d.ts.map +1 -0
- package/dist/core/actions/remove.action.js +64 -0
- package/dist/core/actions/remove.action.js.map +1 -0
- package/dist/core/actions/replace.action.d.ts +18 -0
- package/dist/core/actions/replace.action.d.ts.map +1 -0
- package/dist/core/actions/replace.action.js +57 -0
- package/dist/core/actions/replace.action.js.map +1 -0
- package/dist/core/actions/setAttr.action.d.ts +9 -0
- package/dist/core/actions/setAttr.action.d.ts.map +1 -0
- package/dist/core/actions/setAttr.action.js +62 -0
- package/dist/core/actions/setAttr.action.js.map +1 -0
- package/dist/core/actions/setProps.action.d.ts +8 -0
- package/dist/core/actions/setProps.action.d.ts.map +1 -0
- package/dist/core/actions/setProps.action.js +13 -0
- package/dist/core/actions/setProps.action.js.map +1 -0
- package/dist/core/actions/setRef.action.d.ts +11 -0
- package/dist/core/actions/setRef.action.d.ts.map +1 -0
- package/dist/core/actions/setRef.action.js +38 -0
- package/dist/core/actions/setRef.action.js.map +1 -0
- package/dist/core/actions/setText.action.d.ts +7 -0
- package/dist/core/actions/setText.action.d.ts.map +1 -0
- package/dist/core/actions/setText.action.js +12 -0
- package/dist/core/actions/setText.action.js.map +1 -0
- package/dist/core/compact.d.ts +38 -0
- package/dist/core/compact.d.ts.map +1 -0
- package/dist/core/compact.js +112 -0
- package/dist/core/compact.js.map +1 -0
- package/dist/core/components.d.ts +32 -0
- package/dist/core/components.d.ts.map +1 -0
- package/dist/core/components.js +57 -0
- package/dist/core/components.js.map +1 -0
- package/dist/core/createElement.d.ts +47 -0
- package/dist/core/createElement.d.ts.map +1 -0
- package/dist/core/createElement.js +73 -0
- package/dist/core/createElement.js.map +1 -0
- package/dist/core/createRoot.d.ts +13 -0
- package/dist/core/createRoot.d.ts.map +1 -0
- package/dist/core/createRoot.js +33 -0
- package/dist/core/createRoot.js.map +1 -0
- package/dist/core/reactNodeToFiberNode.d.ts +8 -0
- package/dist/core/reactNodeToFiberNode.d.ts.map +1 -0
- package/dist/core/reactNodeToFiberNode.js +132 -0
- package/dist/core/reactNodeToFiberNode.js.map +1 -0
- package/dist/core/reconciliation/app.d.ts +5 -0
- package/dist/core/reconciliation/app.d.ts.map +1 -0
- package/dist/core/reconciliation/app.js +20 -0
- package/dist/core/reconciliation/app.js.map +1 -0
- package/dist/core/reconciliation/applyActions.d.ts +8 -0
- package/dist/core/reconciliation/applyActions.d.ts.map +1 -0
- package/dist/core/reconciliation/applyActions.js +12 -0
- package/dist/core/reconciliation/applyActions.js.map +1 -0
- package/dist/core/reconciliation/collect/fromApp.d.ts +9 -0
- package/dist/core/reconciliation/collect/fromApp.d.ts.map +1 -0
- package/dist/core/reconciliation/collect/fromApp.js +39 -0
- package/dist/core/reconciliation/collect/fromApp.js.map +1 -0
- package/dist/core/reconciliation/collect/fromChildrenPair.d.ts +9 -0
- package/dist/core/reconciliation/collect/fromChildrenPair.d.ts.map +1 -0
- package/dist/core/reconciliation/collect/fromChildrenPair.js +127 -0
- package/dist/core/reconciliation/collect/fromChildrenPair.js.map +1 -0
- package/dist/core/reconciliation/collect/fromComponent.d.ts +10 -0
- package/dist/core/reconciliation/collect/fromComponent.d.ts.map +1 -0
- package/dist/core/reconciliation/collect/fromComponent.js +22 -0
- package/dist/core/reconciliation/collect/fromComponent.js.map +1 -0
- package/dist/core/reconciliation/collect/fromFiberPair.d.ts +9 -0
- package/dist/core/reconciliation/collect/fromFiberPair.d.ts.map +1 -0
- package/dist/core/reconciliation/collect/fromFiberPair.js +125 -0
- package/dist/core/reconciliation/collect/fromFiberPair.js.map +1 -0
- package/dist/core/reconciliation/collect/fromNewFiber.d.ts +7 -0
- package/dist/core/reconciliation/collect/fromNewFiber.d.ts.map +1 -0
- package/dist/core/reconciliation/collect/fromNewFiber.js +45 -0
- package/dist/core/reconciliation/collect/fromNewFiber.js.map +1 -0
- package/dist/core/reconciliation/comments.d.ts +3 -0
- package/dist/core/reconciliation/comments.d.ts.map +1 -0
- package/dist/core/reconciliation/comments.js +3 -0
- package/dist/core/reconciliation/comments.js.map +1 -0
- package/dist/core/reconciliation/compare/areFiberNodesEq.d.ts +7 -0
- package/dist/core/reconciliation/compare/areFiberNodesEq.d.ts.map +1 -0
- package/dist/core/reconciliation/compare/areFiberNodesEq.js +14 -0
- package/dist/core/reconciliation/compare/areFiberNodesEq.js.map +1 -0
- package/dist/core/reconciliation/compare/areFiberPropsEq.d.ts +7 -0
- package/dist/core/reconciliation/compare/areFiberPropsEq.d.ts.map +1 -0
- package/dist/core/reconciliation/compare/areFiberPropsEq.js +18 -0
- package/dist/core/reconciliation/compare/areFiberPropsEq.js.map +1 -0
- package/dist/core/reconciliation/effects.d.ts +14 -0
- package/dist/core/reconciliation/effects.d.ts.map +1 -0
- package/dist/core/reconciliation/effects.js +26 -0
- package/dist/core/reconciliation/effects.js.map +1 -0
- package/dist/core/reconciliation/fibers.d.ts +35 -0
- package/dist/core/reconciliation/fibers.d.ts.map +1 -0
- package/dist/core/reconciliation/fibers.js +51 -0
- package/dist/core/reconciliation/fibers.js.map +1 -0
- package/dist/core/reconciliation/invalidateFiber.d.ts +8 -0
- package/dist/core/reconciliation/invalidateFiber.d.ts.map +1 -0
- package/dist/core/reconciliation/invalidateFiber.js +28 -0
- package/dist/core/reconciliation/invalidateFiber.js.map +1 -0
- package/dist/core/reconciliation/mount.d.ts +7 -0
- package/dist/core/reconciliation/mount.d.ts.map +1 -0
- package/dist/core/reconciliation/mount.js +53 -0
- package/dist/core/reconciliation/mount.js.map +1 -0
- package/dist/core/reconciliation/postCommit.d.ts +11 -0
- package/dist/core/reconciliation/postCommit.d.ts.map +1 -0
- package/dist/core/reconciliation/postCommit.js +47 -0
- package/dist/core/reconciliation/postCommit.js.map +1 -0
- package/dist/core/reconciliation/render.d.ts +11 -0
- package/dist/core/reconciliation/render.d.ts.map +1 -0
- package/dist/core/reconciliation/render.js +35 -0
- package/dist/core/reconciliation/render.js.map +1 -0
- package/dist/core/reconciliation/runFiberComponents.d.ts +10 -0
- package/dist/core/reconciliation/runFiberComponents.d.ts.map +1 -0
- package/dist/core/reconciliation/runFiberComponents.js +37 -0
- package/dist/core/reconciliation/runFiberComponents.js.map +1 -0
- package/dist/core/reconciliation/typeGuards.d.ts +12 -0
- package/dist/core/reconciliation/typeGuards.d.ts.map +1 -0
- package/dist/core/reconciliation/typeGuards.js +32 -0
- package/dist/core/reconciliation/typeGuards.js.map +1 -0
- package/dist/core/reconciliation/validateTree.d.ts +6 -0
- package/dist/core/reconciliation/validateTree.d.ts.map +1 -0
- package/dist/core/reconciliation/validateTree.js +48 -0
- package/dist/core/reconciliation/validateTree.js.map +1 -0
- package/dist/hooks/helpers.d.ts +19 -0
- package/dist/hooks/helpers.d.ts.map +1 -0
- package/dist/hooks/helpers.js +40 -0
- package/dist/hooks/helpers.js.map +1 -0
- package/dist/hooks/index.d.ts +9 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +9 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useCallback.d.ts +2 -0
- package/dist/hooks/useCallback.d.ts.map +1 -0
- package/dist/hooks/useCallback.js +5 -0
- package/dist/hooks/useCallback.js.map +1 -0
- package/dist/hooks/useContext.d.ts +37 -0
- package/dist/hooks/useContext.d.ts.map +1 -0
- package/dist/hooks/useContext.js +101 -0
- package/dist/hooks/useContext.js.map +1 -0
- package/dist/hooks/useEffect.d.ts +48 -0
- package/dist/hooks/useEffect.d.ts.map +1 -0
- package/dist/hooks/useEffect.js +100 -0
- package/dist/hooks/useEffect.js.map +1 -0
- package/dist/hooks/useId.d.ts +2 -0
- package/dist/hooks/useId.d.ts.map +1 -0
- package/dist/hooks/useId.js +10 -0
- package/dist/hooks/useId.js.map +1 -0
- package/dist/hooks/useMemo.d.ts +20 -0
- package/dist/hooks/useMemo.d.ts.map +1 -0
- package/dist/hooks/useMemo.js +33 -0
- package/dist/hooks/useMemo.js.map +1 -0
- package/dist/hooks/useRef.d.ts +4 -0
- package/dist/hooks/useRef.d.ts.map +1 -0
- package/dist/hooks/useRef.js +9 -0
- package/dist/hooks/useRef.js.map +1 -0
- package/dist/hooks/useStableCallback.d.ts +45 -0
- package/dist/hooks/useStableCallback.d.ts.map +1 -0
- package/dist/hooks/useStableCallback.js +66 -0
- package/dist/hooks/useStableCallback.js.map +1 -0
- package/dist/hooks/useState.d.ts +15 -0
- package/dist/hooks/useState.d.ts.map +1 -0
- package/dist/hooks/useState.js +39 -0
- package/dist/hooks/useState.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +6 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +7 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.d.ts +31 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +32 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/testing.d.ts +8 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +10 -0
- package/dist/testing.js.map +1 -0
- package/dist/types/actions.d.ts +53 -0
- package/dist/types/actions.d.ts.map +1 -0
- package/dist/types/actions.js +2 -0
- package/dist/types/actions.js.map +1 -0
- package/dist/types/app.d.ts +74 -0
- package/dist/types/app.d.ts.map +1 -0
- package/dist/types/app.js +2 -0
- package/dist/types/app.js.map +1 -0
- package/dist/types/component.d.ts +11 -0
- package/dist/types/component.d.ts.map +1 -0
- package/dist/types/component.js +2 -0
- package/dist/types/component.js.map +1 -0
- package/dist/types/context.d.ts +28 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/core.d.ts +51 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +2 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/dom.d.ts +48 -0
- package/dist/types/dom.d.ts.map +1 -0
- package/dist/types/dom.js +2 -0
- package/dist/types/dom.js.map +1 -0
- package/dist/types/fiber.d.ts +169 -0
- package/dist/types/fiber.d.ts.map +1 -0
- package/dist/types/fiber.js +2 -0
- package/dist/types/fiber.js.map +1 -0
- package/dist/types/hooks.d.ts +47 -0
- package/dist/types/hooks.d.ts.map +1 -0
- package/dist/types/hooks.js +2 -0
- package/dist/types/hooks.js.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +9 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/refs.d.ts +19 -0
- package/dist/types/refs.d.ts.map +1 -0
- package/dist/types/refs.js +2 -0
- package/dist/types/refs.js.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +7 -0
- package/dist/utils.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { isCompactSingleChild, unwrapCompactFiber } from '../compact';
|
|
2
|
+
import { emptyFiberNode, getFiberDomNodes, unsetRef } from './helpers';
|
|
3
|
+
import { applyAction } from './applyAction';
|
|
4
|
+
/**
|
|
5
|
+
* This action can be called directly (<div/> -> []), or indirectly (<div/> ->
|
|
6
|
+
* false) from the replace action. `replaced` is `true` in the 2nd scenario.
|
|
7
|
+
*/
|
|
8
|
+
export function removeAction(fiber) {
|
|
9
|
+
for (const child of fiber.children) {
|
|
10
|
+
// Recursively remove all children before removing the parent node. This is
|
|
11
|
+
// critical for components with effects - we must run cleanup effects
|
|
12
|
+
// before removing their parent nodes.
|
|
13
|
+
applyAction({ type: 'Remove', fiber: child });
|
|
14
|
+
}
|
|
15
|
+
if (fiber.type === 'component') {
|
|
16
|
+
destroyHooks(fiber);
|
|
17
|
+
}
|
|
18
|
+
else if (fiber.role === 'context' && fiber.data.consumers.size > 0) {
|
|
19
|
+
throw new Error(`One of the context consumers wasn't unmounted`);
|
|
20
|
+
}
|
|
21
|
+
else if (fiber.type === 'tag' && fiber.role !== 'portal') {
|
|
22
|
+
unlistenTagEvents(fiber);
|
|
23
|
+
}
|
|
24
|
+
if (isCompactSingleChild(fiber.parent)) {
|
|
25
|
+
// Can't remove `fiber` when its parent lacks its own direct DOM node.
|
|
26
|
+
// We need to unwrap the compact-fiber (create <!--begin|end--> wrappers).
|
|
27
|
+
unwrapCompactFiber(fiber.parent);
|
|
28
|
+
}
|
|
29
|
+
for (const n of getFiberDomNodes(fiber)) {
|
|
30
|
+
if (n.childNodes.length > 0) {
|
|
31
|
+
throw new Error(`Remove: Node is not empty`);
|
|
32
|
+
}
|
|
33
|
+
n.remove();
|
|
34
|
+
}
|
|
35
|
+
if (fiber.ref) {
|
|
36
|
+
unsetRef(fiber.ref);
|
|
37
|
+
}
|
|
38
|
+
emptyFiberNode(fiber); // Help with garbage collection.
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Removes all assigned event listeners. While we never reuse tag nodes after
|
|
42
|
+
* removal, this cleanup is important because event handlers capture references
|
|
43
|
+
* to the fiber tree. If the tag node is preserved in user code, this would
|
|
44
|
+
* create a memory leak. Better to mitigate this potential issue.
|
|
45
|
+
*/
|
|
46
|
+
const unlistenTagEvents = (fiber) => {
|
|
47
|
+
for (const [name, record] of Object.entries(fiber.data.events)) {
|
|
48
|
+
if (record?.wrapper) {
|
|
49
|
+
fiber.element.removeEventListener(name, record.wrapper);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Some component hooks might have destructors. We have to run them before we
|
|
55
|
+
* destroy the component.
|
|
56
|
+
*/
|
|
57
|
+
const destroyHooks = (fiber) => {
|
|
58
|
+
for (const item of fiber.data.hooks ?? [])
|
|
59
|
+
if ('destructor' in item) {
|
|
60
|
+
item.destructor?.();
|
|
61
|
+
item.destructor = null;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=remove.action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove.action.js","sourceRoot":"","sources":["../../../src/core/actions/remove.action.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAgB,EAAE;IAC7C,KAAK,MAAM,KAAK,IAAI,KAAK,CAA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K,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/D,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YACnB,KAAK,CAAC,OAAuB,CAAC,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;AAAA,CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,YAAY,GAAG,CAAC,KAAyB,EAAQ,EAAE,CAAC;IACxD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;QACvC,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC;YACzB,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;YACpB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACzB,CAAC;AAAA,CACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FiberNode } from '../../types';
|
|
2
|
+
import type { ReplaceAction } from '../../types/actions';
|
|
3
|
+
/**
|
|
4
|
+
* Handles fiber replacement when a component with the same key renders a
|
|
5
|
+
* completely different node. This happens when the `type`, `tag`, or
|
|
6
|
+
* `component` fields change between renders.
|
|
7
|
+
*
|
|
8
|
+
* It's not called when the same node changes its `key`. In such a case we get:
|
|
9
|
+
* - "create*" for the new fiber
|
|
10
|
+
* - "remove" for the previous fiber
|
|
11
|
+
* - "relayout" for the parent fiber
|
|
12
|
+
*
|
|
13
|
+
* The process involves removing the old fiber's DOM and fiber nodes (and
|
|
14
|
+
* subnodes), and inserting the new fiber's DOM nodes in the same position
|
|
15
|
+
* while preserving the original fiber object (keeping the same ID).
|
|
16
|
+
*/
|
|
17
|
+
export declare function replaceAction(fiber: FiberNode, { newFiber }: ReplaceAction): void;
|
|
18
|
+
//# sourceMappingURL=replace.action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace.action.d.ts","sourceRoot":"","sources":["../../../src/core/actions/replace.action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAMhE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,QAAQ,EAAE,EAAE,aAAa,QAuB1E"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { getFiberDomNodes } from './helpers';
|
|
2
|
+
import { isCompactSingleChild, unwrapCompactFiber } from '../compact';
|
|
3
|
+
import { nullthrows } from '../../utils';
|
|
4
|
+
import { applyAction } from './applyAction';
|
|
5
|
+
/**
|
|
6
|
+
* Handles fiber replacement when a component with the same key renders a
|
|
7
|
+
* completely different node. This happens when the `type`, `tag`, or
|
|
8
|
+
* `component` fields change between renders.
|
|
9
|
+
*
|
|
10
|
+
* It's not called when the same node changes its `key`. In such a case we get:
|
|
11
|
+
* - "create*" for the new fiber
|
|
12
|
+
* - "remove" for the previous fiber
|
|
13
|
+
* - "relayout" for the parent fiber
|
|
14
|
+
*
|
|
15
|
+
* The process involves removing the old fiber's DOM and fiber nodes (and
|
|
16
|
+
* subnodes), and inserting the new fiber's DOM nodes in the same position
|
|
17
|
+
* while preserving the original fiber object (keeping the same ID).
|
|
18
|
+
*/
|
|
19
|
+
export function replaceAction(fiber, { newFiber }) {
|
|
20
|
+
const { parent } = fiber;
|
|
21
|
+
if (isCompactSingleChild(parent)) {
|
|
22
|
+
// The node we're replacing is the only child of its parent, so the parent
|
|
23
|
+
// is in compact mode. We should unwrap it before removing this node,
|
|
24
|
+
// otherwise it will be disconnected from the DOM tree.
|
|
25
|
+
unwrapCompactFiber(parent);
|
|
26
|
+
}
|
|
27
|
+
// Add new nodes right after the previous nodes.
|
|
28
|
+
const nodesBefore = getFiberDomNodes(fiber);
|
|
29
|
+
let prev = nullthrows(nodesBefore.at(-1));
|
|
30
|
+
const nodesAfter = getFiberDomNodes(newFiber);
|
|
31
|
+
for (const n of nodesAfter) {
|
|
32
|
+
prev.parentElement.insertBefore(n, prev.nextSibling);
|
|
33
|
+
prev = n;
|
|
34
|
+
}
|
|
35
|
+
applyAction({ type: 'Remove', fiber });
|
|
36
|
+
fiber.parent = parent; // undo `parent = null` (done in "Remove").
|
|
37
|
+
displaceFiber(fiber, newFiber);
|
|
38
|
+
}
|
|
39
|
+
/** Override `before` fiber fields with the `after` fiber fields. */
|
|
40
|
+
const displaceFiber = (before, after) => {
|
|
41
|
+
before.id = after.id;
|
|
42
|
+
before.type = after.type;
|
|
43
|
+
before.role = after.role;
|
|
44
|
+
before.data = after.data;
|
|
45
|
+
before.children = after.children;
|
|
46
|
+
for (const child of before.children) {
|
|
47
|
+
// after's DOM nodes were in a <x-container/>. We moved them to the correct
|
|
48
|
+
// container. Now update the `parent` field.
|
|
49
|
+
child.parent = before;
|
|
50
|
+
}
|
|
51
|
+
before.component = after.component;
|
|
52
|
+
before.element = after.element;
|
|
53
|
+
before.tag = after.tag;
|
|
54
|
+
before.props = after.props;
|
|
55
|
+
before.ref = after.ref;
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=replace.action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace.action.js","sourceRoot":"","sources":["../../../src/core/actions/replace.action.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAAC,KAAgB,EAAE,EAAE,QAAQ,EAAiB,EAAE;IAC3E,MAAM,E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AAC,MAAM,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;IACnC,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAC/B,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;IAEvB,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC3B,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;AAAA,CACxB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FiberNode } from '../../types';
|
|
2
|
+
import type { SetAttrAction } from '../../types/actions';
|
|
3
|
+
/**
|
|
4
|
+
* Applicable only to DOM tag nodes and handles the following scenarios:
|
|
5
|
+
* - Removing, adding or updating an attribute
|
|
6
|
+
* - Removing, adding or replacing an event handler
|
|
7
|
+
*/
|
|
8
|
+
export declare function setAttrAction(fiber: FiberNode, { name, value }: SetAttrAction): void;
|
|
9
|
+
//# sourceMappingURL=setAttr.action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setAttr.action.d.ts","sourceRoot":"","sources":["../../../src/core/actions/setAttr.action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAA8B,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAIhE;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,SAAS,EAChB,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,aAAa,QAwB/B"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { nullthrows } from '../../utils';
|
|
2
|
+
import { isEventName } from './helpers';
|
|
3
|
+
/**
|
|
4
|
+
* Applicable only to DOM tag nodes and handles the following scenarios:
|
|
5
|
+
* - Removing, adding or updating an attribute
|
|
6
|
+
* - Removing, adding or replacing an event handler
|
|
7
|
+
*/
|
|
8
|
+
export function setAttrAction(fiber, { name, value }) {
|
|
9
|
+
if (fiber.type !== 'tag') {
|
|
10
|
+
throw new Error(`Can't apply SetAttr to a ${fiber.type} node`);
|
|
11
|
+
}
|
|
12
|
+
if (fiber.role === 'portal') {
|
|
13
|
+
throw new Error(`Can't apply SetAttr to a portal node`);
|
|
14
|
+
}
|
|
15
|
+
const element = nullthrows(fiber.element);
|
|
16
|
+
if (isEventName(name) || name in fiber.data.events) {
|
|
17
|
+
setEventHandler(fiber, element, name, value);
|
|
18
|
+
}
|
|
19
|
+
else if (value == null) {
|
|
20
|
+
element.removeAttribute(name);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const strValue = String(value);
|
|
24
|
+
if (strValue !== element.getAttribute(name)) {
|
|
25
|
+
// Without this check, updates like img.src = the-same-src
|
|
26
|
+
// lead to retriggering the onload handler.
|
|
27
|
+
element.setAttribute(name === 'className' ? 'class' : name, strValue);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const setEventHandler = (fiber, element, name, value) => {
|
|
32
|
+
const { events } = fiber.data;
|
|
33
|
+
if (value == null || value === false) {
|
|
34
|
+
if (events[name]) {
|
|
35
|
+
// Event handler was added before but now it's removed.
|
|
36
|
+
events[name].handler = null;
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (typeof value !== 'function') {
|
|
41
|
+
throw new Error(`Unsupported format of event handler. It has to be "undefined" or a function`);
|
|
42
|
+
}
|
|
43
|
+
const eventName = name.slice(2); // onclick -> click.
|
|
44
|
+
// Instead of adding and removing event handlers on every render, we can add a
|
|
45
|
+
// wrapper that calls `events[eventName]` and update only the internal
|
|
46
|
+
// function when it changes.
|
|
47
|
+
if (!events[name]) {
|
|
48
|
+
events[name] = {
|
|
49
|
+
handler: value,
|
|
50
|
+
wrapper: (event) => {
|
|
51
|
+
// Original React doesn't support stopping propagation on `false` return.
|
|
52
|
+
events[name].handler?.(event);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
element.addEventListener(eventName, events[name].wrapper);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// The tag is already listening to this event. Just update the internal ref.
|
|
59
|
+
events[name].handler = value;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=setAttr.action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setAttr.action.js","sourceRoot":"","sources":["../../../src/core/actions/setAttr.action.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,KAAgB,EAChB,EAAE,IAAI,EAAE,KAAK,EAAiB,EAC9B;IACA,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,IAAI,OAAO,CAAC,CAAC;IACjE,CAAC;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAE1C,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACnD,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/C,CAAC;SAAM,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;SAAM,CAAC;QACN,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,I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D,CAAC;SAAM,CAAC;QACN,4EAA4E;QAC5E,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,GAAG,KAAK,CAAC;IAC/B,CAAC;AAAA,CACF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FiberNode } from '../../types';
|
|
2
|
+
import type { SetPropsAction } from '../../types/actions';
|
|
3
|
+
/**
|
|
4
|
+
* Updates the set of props for the given fiber node. This doesn't make any
|
|
5
|
+
* DOM changes or run components.
|
|
6
|
+
*/
|
|
7
|
+
export declare function setPropsAction(fiber: FiberNode, { props }: SetPropsAction): void;
|
|
8
|
+
//# sourceMappingURL=setProps.action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setProps.action.d.ts","sourceRoot":"","sources":["../../../src/core/actions/setProps.action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,EAAE,cAAc,QASzE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Updates the set of props for the given fiber node. This doesn't make any
|
|
3
|
+
* DOM changes or run components.
|
|
4
|
+
*/
|
|
5
|
+
export function setPropsAction(fiber, { props }) {
|
|
6
|
+
if (fiber.type !== 'component' &&
|
|
7
|
+
fiber.type !== 'tag' &&
|
|
8
|
+
fiber.role !== 'context') {
|
|
9
|
+
throw new Error(`setProps action is not applicable to this fiber node`);
|
|
10
|
+
}
|
|
11
|
+
fiber.props = props;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=setProps.action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setProps.action.js","sourceRoot":"","sources":["../../../src/core/actions/setProps.action.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,KAAgB,EAAE,EAAE,KAAK,EAAkB,EAAE;IAC1E,IACE,KAAK,CAAC,IAAI,KAAK,WAAW;QAC1B,KAAK,CAAC,IAAI,KAAK,KAAK;QACpB,KAAK,CAAC,IAAI,KAAK,SAAS,EACxB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;IACD,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;AAAA,CACrB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FiberNode } from '../../types';
|
|
2
|
+
import type { SetRefAction } from '../../types/actions';
|
|
3
|
+
/**
|
|
4
|
+
* A ref or ref handler for the given node was:
|
|
5
|
+
* - set up
|
|
6
|
+
* - or replaced
|
|
7
|
+
*
|
|
8
|
+
* Removing nodes with ref handlers is handled in remove and replace actions.
|
|
9
|
+
*/
|
|
10
|
+
export declare function setRefAction(fiber: FiberNode, { ref, dontUnsetRef }: SetRefAction): void;
|
|
11
|
+
//# sourceMappingURL=setRef.action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setRef.action.d.ts","sourceRoot":"","sources":["../../../src/core/actions/setRef.action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAK/D;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,SAAS,EAChB,EAAE,GAAG,EAAE,YAAY,EAAE,EAAE,YAAY,QAiCpC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { nullthrows } from '../../utils';
|
|
2
|
+
import { unsetRef } from './helpers';
|
|
3
|
+
import { scheduleEffect } from '../reconciliation/effects';
|
|
4
|
+
import { getAppByFiber } from '../reconciliation/app';
|
|
5
|
+
/**
|
|
6
|
+
* A ref or ref handler for the given node was:
|
|
7
|
+
* - set up
|
|
8
|
+
* - or replaced
|
|
9
|
+
*
|
|
10
|
+
* Removing nodes with ref handlers is handled in remove and replace actions.
|
|
11
|
+
*/
|
|
12
|
+
export function setRefAction(fiber, { ref, dontUnsetRef }) {
|
|
13
|
+
if (fiber.type !== 'tag') {
|
|
14
|
+
throw new Error(`setRefAction is not compatible with ${fiber.type} nodes`);
|
|
15
|
+
}
|
|
16
|
+
if (fiber.ref &&
|
|
17
|
+
// It's `true` on the first render of the tag. We shouldn't run `onRef(null)`
|
|
18
|
+
// in such a case.
|
|
19
|
+
!dontUnsetRef) {
|
|
20
|
+
// ref.current = null | ref(null)
|
|
21
|
+
unsetRef(fiber.ref);
|
|
22
|
+
}
|
|
23
|
+
// Run effects only when the DOM node is already mounted to a real DOM node.
|
|
24
|
+
scheduleEffect(getAppByFiber(fiber), () => {
|
|
25
|
+
const element = nullthrows(fiber.element);
|
|
26
|
+
if (typeof ref === 'function') {
|
|
27
|
+
ref(element);
|
|
28
|
+
}
|
|
29
|
+
else if (ref) {
|
|
30
|
+
ref.current = element;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
// React calls ref handlers even before it runs layout effects.
|
|
34
|
+
'refs');
|
|
35
|
+
fiber.ref = ref;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=setRef.action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setRef.action.js","sourceRoot":"","sources":["../../../src/core/actions/setRef.action.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAgB,EAChB,EAAE,GAAG,EAAE,YAAY,EAAgB,EACnC;IACA,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,uCAAuC,KAAK,CAAC,IAAI,QAAQ,CAAC,CAAC;IAC7E,CAAC;IAED,IACE,KAAK,CAAC,GAAG;QACT,6EAA6E;QAC7E,kBAAkB;QAClB,CAAC,YAAY,EACb,CAAC;QACD,iCAAiC;QACjC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtB,CAAC;IAED,4EAA4E;IAC5E,cAAc,CACZ,aAAa,CAAC,KAAK,CAAC,EACpB,GAAG,EAAE,CAAC;QACJ,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,OAAO,CAAgB,CAAC;QACzD,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;YAC9B,GAAG,CAAC,OAAO,CAAC,CAAC;QACf,CAAC;aAAM,IAAI,GAAG,EAAE,CAAC;YACf,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC;QACxB,CAAC;IAAA,CACF;IACD,+DAA+D;IAC/D,MAAM,CACP,CAAC;IAEF,KAAK,CAAC,GAAG,GAAG,GAAuB,CAAC;IACpC,OAAO;AAAA,CACR"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FiberNode } from '../../types';
|
|
2
|
+
import type { SetTextAction } from '../../types/actions';
|
|
3
|
+
/**
|
|
4
|
+
* Replaces the text content within a Text DOM node.
|
|
5
|
+
*/
|
|
6
|
+
export declare function setTextAction(fiber: FiberNode, { text }: SetTextAction): void;
|
|
7
|
+
//# sourceMappingURL=setText.action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setText.action.d.ts","sourceRoot":"","sources":["../../../src/core/actions/setText.action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAGhE;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,EAAE,aAAa,QAMtE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { nullthrows } from '../../utils';
|
|
2
|
+
/**
|
|
3
|
+
* Replaces the text content within a Text DOM node.
|
|
4
|
+
*/
|
|
5
|
+
export function setTextAction(fiber, { text }) {
|
|
6
|
+
if (fiber.type !== 'text') {
|
|
7
|
+
throw new Error(`Can't apply setText action to non-text node`);
|
|
8
|
+
}
|
|
9
|
+
fiber.props = { text };
|
|
10
|
+
nullthrows(fiber.element).textContent = text;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=setText.action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setText.action.js","sourceRoot":"","sources":["../../../src/core/actions/setText.action.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAgB,EAAE,EAAE,IAAI,EAAiB,EAAE;IACvE,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IACD,KAAK,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,CAAC;IACvB,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC;AAAA,CAC9C"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type DomNode, type FiberNode } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if domNode is <!--r:begin:ID--> where ID is fiber.id
|
|
4
|
+
*/
|
|
5
|
+
export declare const isBeginOf: (domNode: ChildNode, fiber: FiberNode) => domNode is Comment;
|
|
6
|
+
/**
|
|
7
|
+
* Returns true if the given `fiber` is in solo compact mode. This means it
|
|
8
|
+
* doesn't have its own direct DOM element. Instead, its `element` refers to its
|
|
9
|
+
* only child's `element`, avoiding the need for <!--brackets-->.
|
|
10
|
+
*/
|
|
11
|
+
export declare const isCompactSingleChild: (fiber: FiberNode) => fiber is FiberNode & {
|
|
12
|
+
element: DomNode;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Returns true if the given `fiber` is in none compact mode. This means it
|
|
16
|
+
* has no fiber children, and its element is <!--r:empty:id-->
|
|
17
|
+
*/
|
|
18
|
+
export declare const isCompactNone: (fiber: FiberNode) => fiber is FiberNode & {
|
|
19
|
+
element: DomNode;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* If the given fiber node has <!--brackets-->, this function tries to apply one
|
|
23
|
+
* of the "compact" optimizations:
|
|
24
|
+
*
|
|
25
|
+
* - If the node has no children, it replaces the brackets with
|
|
26
|
+
* <!--r:empty:id-->
|
|
27
|
+
* - If the node has only one child, it removes the brackets and sets
|
|
28
|
+
* `fiber.element` to reference its only direct DOM child
|
|
29
|
+
*
|
|
30
|
+
* It also tries to recursively compact parent nodes when possible.
|
|
31
|
+
*/
|
|
32
|
+
export declare function tryToCompactNode(fiber: FiberNode): void;
|
|
33
|
+
/**
|
|
34
|
+
* Converts <!--empty--> or the single compact container node into:
|
|
35
|
+
* <!--begin-->...children...<!--end-->
|
|
36
|
+
*/
|
|
37
|
+
export declare const unwrapCompactFiber: (fiber: FiberNode) => void;
|
|
38
|
+
//# sourceMappingURL=compact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact.d.ts","sourceRoot":"","sources":["../../src/core/compact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAGxD;;GAEG;AACH,eAAO,MAAM,SAAS,8DAKuC,CAAC;AAgB9D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;CAOE,CAAC;AAEpC;;;GAGG;AACH,eAAO,MAAM,aAAa;;CAMQ,CAAC;AAEnC;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAiCvD;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,4BAuC9B,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { buildComment, buildCommentText } from './reconciliation/comments';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if domNode is <!--r:begin:ID--> where ID is fiber.id
|
|
4
|
+
*/
|
|
5
|
+
export const isBeginOf = (domNode, fiber) => domNode instanceof Comment &&
|
|
6
|
+
domNode.textContent === buildCommentText('begin', fiber.id);
|
|
7
|
+
/**
|
|
8
|
+
* Returns true if domNode is <!--r:end:ID--> where ID is fiber.id
|
|
9
|
+
*/
|
|
10
|
+
const isEndOf = (domNode, fiber) => domNode instanceof Comment &&
|
|
11
|
+
domNode.textContent === buildCommentText('end', fiber.id);
|
|
12
|
+
/**
|
|
13
|
+
* Returns true if domNode is <!--r:empty:ID--> where ID is fiber.id
|
|
14
|
+
*/
|
|
15
|
+
const isEmptyOf = (domNode, fiber) => domNode instanceof Comment &&
|
|
16
|
+
domNode.textContent === buildCommentText('empty', fiber.id);
|
|
17
|
+
/**
|
|
18
|
+
* Returns true if the given `fiber` is in solo compact mode. This means it
|
|
19
|
+
* doesn't have its own direct DOM element. Instead, its `element` refers to its
|
|
20
|
+
* only child's `element`, avoiding the need for <!--brackets-->.
|
|
21
|
+
*/
|
|
22
|
+
export const isCompactSingleChild = (fiber) => (fiber.type === 'fragment' || fiber.type === 'component') &&
|
|
23
|
+
!isEndOf(fiber.element, fiber) &&
|
|
24
|
+
!isEmptyOf(fiber.element, fiber);
|
|
25
|
+
/**
|
|
26
|
+
* Returns true if the given `fiber` is in none compact mode. This means it
|
|
27
|
+
* has no fiber children, and its element is <!--r:empty:id-->
|
|
28
|
+
*/
|
|
29
|
+
export const isCompactNone = (fiber) => (fiber.type === 'fragment' || fiber.type === 'component') &&
|
|
30
|
+
isEmptyOf(fiber.element, fiber);
|
|
31
|
+
/**
|
|
32
|
+
* If the given fiber node has <!--brackets-->, this function tries to apply one
|
|
33
|
+
* of the "compact" optimizations:
|
|
34
|
+
*
|
|
35
|
+
* - If the node has no children, it replaces the brackets with
|
|
36
|
+
* <!--r:empty:id-->
|
|
37
|
+
* - If the node has only one child, it removes the brackets and sets
|
|
38
|
+
* `fiber.element` to reference its only direct DOM child
|
|
39
|
+
*
|
|
40
|
+
* It also tries to recursively compact parent nodes when possible.
|
|
41
|
+
*/
|
|
42
|
+
export function tryToCompactNode(fiber) {
|
|
43
|
+
if (!isEndOf(fiber.element, fiber)) {
|
|
44
|
+
return; // Node is not a !--container or is already compact.
|
|
45
|
+
}
|
|
46
|
+
// By default each fragment or component is rendered with 3+ nodes:
|
|
47
|
+
// <!--r:begin:id--> + …children + <!--r:end:id-->
|
|
48
|
+
// This approach supports 0 or 2+ nodes without overly complex logic.
|
|
49
|
+
// However, most cases have only one child or none. For these scenarios,
|
|
50
|
+
// we support two different compact modes.
|
|
51
|
+
const prev1 = fiber.element.previousSibling;
|
|
52
|
+
// Scenario 1: 0 children.
|
|
53
|
+
if (prev1 && isBeginOf(prev1, fiber)) {
|
|
54
|
+
const emptyNode = buildComment('empty', fiber.id);
|
|
55
|
+
prev1.parentElement.insertBefore(emptyNode, prev1);
|
|
56
|
+
prev1.remove(); // !--begin
|
|
57
|
+
fiber.element.remove(); // !--end
|
|
58
|
+
fiber.element = emptyNode;
|
|
59
|
+
return;
|
|
60
|
+
// <!--begin--><--end--> are replaced with <!--empty-->
|
|
61
|
+
}
|
|
62
|
+
const prev2 = prev1?.previousSibling;
|
|
63
|
+
// Scenario 2: 1 children
|
|
64
|
+
if (prev2 && isBeginOf(prev2, fiber)) {
|
|
65
|
+
prev2.remove(); // !--begin
|
|
66
|
+
fiber.element.remove(); // !--end
|
|
67
|
+
fiber.element = fiber.children[0].element;
|
|
68
|
+
// <!--begin--><!--end--> are removed. Now `fiber.element` refers to its
|
|
69
|
+
// only child node.
|
|
70
|
+
tryToCompactNode(fiber.parent);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Converts <!--empty--> or the single compact container node into:
|
|
75
|
+
* <!--begin-->...children...<!--end-->
|
|
76
|
+
*/
|
|
77
|
+
export const unwrapCompactFiber = (fiber) => {
|
|
78
|
+
const container = fiber.element.parentElement;
|
|
79
|
+
let begin = buildComment('begin', fiber.id);
|
|
80
|
+
let end = buildComment('end', fiber.id);
|
|
81
|
+
if (isCompactSingleChild(fiber)) {
|
|
82
|
+
// before: <container><child/></container>
|
|
83
|
+
// after: <container><!--begin--><child/><!--end--></container>
|
|
84
|
+
container.insertBefore(begin, fiber.element);
|
|
85
|
+
container.insertBefore(end, fiber.element.nextSibling);
|
|
86
|
+
fiber.element = end;
|
|
87
|
+
// Repeat the same with every single-compact ancestor:
|
|
88
|
+
let parent = fiber.parent;
|
|
89
|
+
while (isCompactSingleChild(parent)) {
|
|
90
|
+
const pBegin = buildComment('begin', parent.id);
|
|
91
|
+
const pEnd = buildComment('end', parent.id);
|
|
92
|
+
container.insertBefore(pBegin, begin);
|
|
93
|
+
container.insertBefore(pEnd, end.nextSibling);
|
|
94
|
+
parent.element = pEnd;
|
|
95
|
+
begin = pBegin;
|
|
96
|
+
end = pEnd;
|
|
97
|
+
parent = parent.parent;
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (isCompactNone(fiber)) {
|
|
102
|
+
// before: <container><!--empty--></container>
|
|
103
|
+
// after: <container><!--begin--><!--end--></container>
|
|
104
|
+
container.insertBefore(begin, fiber.element);
|
|
105
|
+
container.insertBefore(end, fiber.element.nextSibling);
|
|
106
|
+
fiber.element.remove();
|
|
107
|
+
fiber.element = end;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
throw new Error(`Unsupported format of compact node`);
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EAAE,CAAC;QACzB,8CAA8C;QAC9C,wDAAwD;QACxD,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,OAAQ,CAAC,CAAC;QAC9C,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,OAAQ,CAAC,WAAW,CAAC,CAAC;QACxD,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACvB,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC;QACpB,OAAO;IACT,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;AAAA,CACvD,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type HookStateItem, type FiberNode, type App, type ComponentFiberNode } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the fiber of the component that is being rendered right now. Don't
|
|
4
|
+
* run this function outside of the render phase.
|
|
5
|
+
*/
|
|
6
|
+
export declare const getCurrentComponentFiber: () => ComponentFiberNode;
|
|
7
|
+
/**
|
|
8
|
+
* The app of the component that is being rendered right now. Don't run this
|
|
9
|
+
* function outside of the render phase.
|
|
10
|
+
*/
|
|
11
|
+
export declare const getCurrentApp: () => App;
|
|
12
|
+
/**
|
|
13
|
+
* Returns true when it's the 1st render of currentFiber's component.
|
|
14
|
+
*/
|
|
15
|
+
export declare const isFirstFiberRender: () => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Runs the functional component. Before running, it prepares everything that
|
|
18
|
+
* is required to make hooks work. The result is JSX returned from the component
|
|
19
|
+
* function.
|
|
20
|
+
*/
|
|
21
|
+
export declare const runComponent: (fiber: FiberNode, propsSource: FiberNode | null) => import("../index.js").JsxElement;
|
|
22
|
+
/**
|
|
23
|
+
* Switches to the next hook and returns its state.
|
|
24
|
+
*/
|
|
25
|
+
export declare const getNextFiberState: () => HookStateItem;
|
|
26
|
+
/**
|
|
27
|
+
* Adds a new item to the current component's hook store
|
|
28
|
+
*/
|
|
29
|
+
export declare const registerStateItem: (item: {
|
|
30
|
+
type: "context" | "effect" | "memo" | "ref" | "state";
|
|
31
|
+
}) => void;
|
|
32
|
+
//# sourceMappingURL=components.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../src/core/components.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,SAAS,EAEd,KAAK,GAAG,EACR,KAAK,kBAAkB,EACxB,MAAM,UAAU,CAAC;AAMlB;;;GAGG;AACH,eAAO,MAAM,wBAAwB,0BACX,CAAC;AAE3B;;;GAGG;AACH,eAAO,MAAM,aAAa,WAC6B,CAAC;AAIxD;;GAEG;AACH,eAAO,MAAM,kBAAkB,eAAkC,CAAC;AAElE;;;;GAIG;AACH,eAAO,MAAM,YAAY,wFAsBxB,CAAC;AAYF;;GAEG;AACH,eAAO,MAAM,iBAAiB,qBACgC,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,iBAAiB;;UAI7B,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { nullthrows } from '../utils';
|
|
2
|
+
import { getAppByFiber } from './reconciliation/app';
|
|
3
|
+
/** Component that is rendered right now. */
|
|
4
|
+
let currentFiber;
|
|
5
|
+
/**
|
|
6
|
+
* Returns the fiber of the component that is being rendered right now. Don't
|
|
7
|
+
* run this function outside of the render phase.
|
|
8
|
+
*/
|
|
9
|
+
export const getCurrentComponentFiber = () => nullthrows(currentFiber);
|
|
10
|
+
/**
|
|
11
|
+
* The app of the component that is being rendered right now. Don't run this
|
|
12
|
+
* function outside of the render phase.
|
|
13
|
+
*/
|
|
14
|
+
export const getCurrentApp = () => nullthrows(getAppByFiber(getCurrentComponentFiber()));
|
|
15
|
+
let firstFiberRender = false;
|
|
16
|
+
/**
|
|
17
|
+
* Returns true when it's the 1st render of currentFiber's component.
|
|
18
|
+
*/
|
|
19
|
+
export const isFirstFiberRender = () => firstFiberRender;
|
|
20
|
+
/**
|
|
21
|
+
* Runs the functional component. Before running, it prepares everything that
|
|
22
|
+
* is required to make hooks work. The result is JSX returned from the component
|
|
23
|
+
* function.
|
|
24
|
+
*/
|
|
25
|
+
export const runComponent = (fiber,
|
|
26
|
+
/** Source of `.props`. If not given `fiber.props` are used. */
|
|
27
|
+
propsSource) => {
|
|
28
|
+
if (fiber.type !== 'component') {
|
|
29
|
+
throw new Error(`Can't run ${fiber.type} as a component`);
|
|
30
|
+
}
|
|
31
|
+
currentFiber = fiber;
|
|
32
|
+
firstFiberRender = !fiber.data.hooks;
|
|
33
|
+
fiber.data.hooks ??= [];
|
|
34
|
+
hookIdx = -1;
|
|
35
|
+
let jsxElement = fiber.component(propsSource?.props ?? fiber.props);
|
|
36
|
+
currentFiber = null;
|
|
37
|
+
firstFiberRender = false;
|
|
38
|
+
return jsxElement;
|
|
39
|
+
};
|
|
40
|
+
let hookIdx = -1;
|
|
41
|
+
const getComponentHookStore = (fiberNode) => {
|
|
42
|
+
if (!fiberNode.data.hooks) {
|
|
43
|
+
throw new Error(`HookStore is empty.`);
|
|
44
|
+
}
|
|
45
|
+
return fiberNode.data.hooks;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Switches to the next hook and returns its state.
|
|
49
|
+
*/
|
|
50
|
+
export const getNextFiberState = () => getComponentHookStore(getCurrentComponentFiber())[++hookIdx];
|
|
51
|
+
/**
|
|
52
|
+
* Adds a new item to the current component's hook store
|
|
53
|
+
*/
|
|
54
|
+
export const registerStateItem = (item) => {
|
|
55
|
+
getComponentHookStore(getCurrentComponentFiber()).push(item);
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/core/components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAQrC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,4CAA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