@raphy-js/raph 1.0.0-dev.2 → 1.0.1-dev.25
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 +1096 -0
- package/dist/api/Raph.d.ts +59 -190
- package/dist/api/RaphFacadeSession.d.ts +90 -0
- package/dist/api/RaphReactivityInstance.d.ts +72 -0
- package/dist/api/errors.d.ts +9 -4
- package/dist/api/types.d.ts +162 -17
- package/dist/core-CClhT8WR.js +1044 -0
- package/dist/core-cPQWYD4K.cjs +1 -0
- package/dist/debug/api/Raph.cjs +1 -1
- package/dist/debug/api/Raph.js +368 -367
- package/dist/debug/api/RaphFacadeSession.cjs +1 -0
- package/dist/debug/api/RaphFacadeSession.js +302 -0
- package/dist/debug/api/RaphReactivityInstance.cjs +1 -0
- package/dist/debug/api/RaphReactivityInstance.js +146 -0
- package/dist/debug/api/errors.cjs +1 -1
- package/dist/debug/api/errors.js +10 -7
- package/dist/debug/path/DataPath.cjs +1 -0
- package/dist/debug/path/DataPath.js +390 -0
- package/dist/debug/path/PathRouter.cjs +1 -0
- package/dist/debug/path/PathRouter.js +80 -0
- package/dist/debug/path/RaphKernel.cjs +1 -1
- package/dist/debug/path/RaphKernel.js +316 -236
- package/dist/debug/path/data-path.utils.cjs +1 -0
- package/dist/debug/path/data-path.utils.js +56 -0
- package/dist/debug/path/derived/DerivedRegistry.cjs +1 -0
- package/dist/debug/path/derived/DerivedRegistry.js +143 -0
- package/dist/debug/path/derived/RaphDerivedHandle.cjs +1 -0
- package/dist/debug/path/{RaphDerivedHandle.js → derived/RaphDerivedHandle.js} +19 -22
- package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
- package/dist/debug/path/{derived-collection.js → derived/derived-collection.utils.js} +71 -71
- package/dist/debug/path/derived/derived-strategy.types.cjs +1 -0
- package/dist/debug/path/derived/derived-strategy.types.js +1 -0
- package/dist/debug/path/meta/MetaController.cjs +1 -0
- package/dist/debug/path/{MetaController.js → meta/MetaController.js} +58 -66
- package/dist/debug/path/meta/RaphMeta.cjs +1 -0
- package/dist/debug/path/meta/RaphMeta.js +62 -0
- package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
- package/dist/debug/path/{RaphMetaStore.js → meta/RaphMetaStore.js} +24 -30
- package/dist/debug/path/meta/meta.types.cjs +1 -0
- package/dist/debug/path/meta/meta.types.js +1 -0
- package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
- package/dist/debug/path/storage/AdapterPathStore.js +128 -0
- package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
- package/dist/debug/path/{data-adapter.js → storage/DefaultDataAdapter.js} +47 -57
- package/dist/debug/path/storage/PathEventHub.cjs +1 -0
- package/dist/debug/path/storage/PathEventHub.js +161 -0
- package/dist/debug/path/storage/PathStore.cjs +1 -0
- package/dist/debug/path/{PathStore.js → storage/PathStore.js} +88 -98
- package/dist/debug/path/storage/createDataDraft.cjs +1 -0
- package/dist/debug/path/{data-draft.js → storage/createDataDraft.js} +24 -28
- package/dist/debug/path/storage/data-adapter.types.cjs +1 -0
- package/dist/debug/path/storage/data-adapter.types.js +1 -0
- package/dist/debug/reactivity/disposal.cjs +1 -0
- package/dist/debug/reactivity/disposal.js +32 -0
- package/dist/debug/reactivity/engine.cjs +1 -1
- package/dist/debug/reactivity/engine.js +888 -321
- package/dist/debug/reactivity/reactive-object.cjs +1 -0
- package/dist/debug/reactivity/reactive-object.js +265 -0
- package/dist/debug/reactivity/scope.cjs +1 -1
- package/dist/debug/reactivity/scope.js +221 -117
- package/dist/debug/reactivity/watch.cjs +1 -1
- package/dist/debug/reactivity/watch.js +1 -1
- package/dist/debug/runtime/RaphRuntime.cjs +1 -1
- package/dist/debug/runtime/RaphRuntime.js +1134 -502
- package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
- package/dist/debug/runtime/diagnostics/RaphDebug.js +287 -0
- package/dist/debug/runtime/errors.cjs +1 -1
- package/dist/debug/runtime/errors.js +6 -3
- package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphEffectScope.js +304 -0
- package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphNode.js +665 -0
- package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphScope.js +236 -0
- package/dist/debug/runtime/ownership/parent-graph.types.cjs +1 -0
- package/dist/debug/runtime/ownership/parent-graph.types.js +1 -0
- package/dist/debug/runtime/phases/RaphFrameLoop.cjs +1 -0
- package/dist/debug/runtime/{RaphFrameLoop.js → phases/RaphFrameLoop.js} +13 -17
- package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhasePipeline.js +848 -0
- package/dist/debug/runtime/phases/RaphPhaseTaskRecord.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhaseTaskRecord.js +176 -0
- package/dist/debug/runtime/phases/RaphPhaseWatch.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhaseWatch.js +20 -0
- package/dist/debug/runtime/phases/orderPhaseTasks.cjs +1 -0
- package/dist/debug/runtime/phases/orderPhaseTasks.js +59 -0
- package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
- package/dist/debug/runtime/reactivity/PathHandle.js +165 -0
- package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphMetaSource.js +108 -0
- package/dist/debug/runtime/reactivity/RaphSelector.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphSelector.js +503 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.js +1157 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.js +550 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.js +77 -0
- package/dist/debug/runtime/reactivity/disposal-sweep.utils.cjs +1 -0
- package/dist/debug/runtime/reactivity/disposal-sweep.utils.js +42 -0
- package/dist/debug/runtime/reactivity/runtime-reactivity.types.cjs +1 -0
- package/dist/debug/runtime/reactivity/runtime-reactivity.types.js +1 -0
- package/dist/entrypoints/machine-testing.d.ts +2 -0
- package/dist/entrypoints/machine.d.ts +5 -0
- package/dist/entrypoints/path.d.ts +14 -0
- package/dist/entrypoints/reactivity.d.ts +1 -0
- package/dist/entrypoints/runtime.d.ts +18 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +46 -38
- package/dist/machine/compiler.d.ts +71 -0
- package/dist/machine/core.d.ts +50 -0
- package/dist/machine/persistence.d.ts +5 -0
- package/dist/machine/runtime.d.ts +4 -0
- package/dist/machine/testing.d.ts +43 -0
- package/dist/machine/types.d.ts +155 -0
- package/dist/machine-testing.cjs +1 -0
- package/dist/machine-testing.js +188 -0
- package/dist/machine.cjs +1 -0
- package/dist/machine.js +822 -0
- package/dist/main.d.ts +20 -0
- package/dist/path/{data-path.d.ts → DataPath.d.ts} +16 -40
- package/dist/path/{path-router.d.ts → PathRouter.d.ts} +1 -1
- package/dist/path/RaphKernel.d.ts +37 -10
- package/dist/path/data-path.types.d.ts +34 -0
- package/dist/path/data-path.utils.d.ts +9 -0
- package/dist/path/{DerivedRegistry.d.ts → derived/DerivedRegistry.d.ts} +2 -2
- package/dist/path/{RaphDerivedHandle.d.ts → derived/RaphDerivedHandle.d.ts} +3 -3
- package/dist/path/derived/derived-collection.types.d.ts +12 -0
- package/dist/path/{derived-collection.d.ts → derived/derived-collection.utils.d.ts} +3 -13
- package/dist/path/{derived-strategies.d.ts → derived/derived-strategy.types.d.ts} +0 -3
- package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
- package/dist/path/{MetaController.d.ts → meta/MetaController.d.ts} +4 -4
- package/dist/path/{RaphMeta.d.ts → meta/RaphMeta.d.ts} +2 -2
- package/dist/path/{RaphMetaStore.d.ts → meta/RaphMetaStore.d.ts} +1 -1
- package/dist/path/{meta.types.d.ts → meta/meta.types.d.ts} +2 -4
- package/dist/path/path.types.d.ts +3 -2
- package/dist/path/{segment-key.d.ts → pathSegmentKey.d.ts} +1 -1
- package/dist/path/{AdapterPathStore.d.ts → storage/AdapterPathStore.d.ts} +4 -4
- package/dist/path/{data-adapter.d.ts → storage/DefaultDataAdapter.d.ts} +2 -17
- package/dist/path/storage/PathEventHub.d.ts +62 -0
- package/dist/path/{PathStore.d.ts → storage/PathStore.d.ts} +7 -7
- package/dist/path/storage/data-adapter.types.d.ts +17 -0
- package/dist/path.cjs +1 -1
- package/dist/path.js +16 -16
- package/dist/raph.cjs +1 -1
- package/dist/raph.js +46 -38
- package/dist/reactivity/disposal.d.ts +14 -0
- package/dist/reactivity/engine.d.ts +193 -6
- package/dist/reactivity/reactive-object.d.ts +36 -0
- package/dist/reactivity/scope.d.ts +108 -30
- package/dist/reactivity/types.d.ts +25 -0
- package/dist/reactivity.cjs +1 -1
- package/dist/reactivity.js +12 -12
- package/dist/runtime/RaphRuntime.d.ts +319 -160
- package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
- package/dist/runtime/errors.d.ts +5 -0
- package/dist/runtime/ownership/RaphEffectScope.d.ts +98 -0
- package/dist/runtime/ownership/RaphNode.d.ts +310 -0
- package/dist/runtime/ownership/RaphScope.d.ts +168 -0
- package/dist/runtime/{parent-graph.d.ts → ownership/parent-graph.types.d.ts} +0 -1
- package/dist/runtime/ownership/parentGraph.d.ts +3 -0
- package/dist/runtime/phases/RaphPhasePipeline.d.ts +253 -0
- package/dist/runtime/phases/RaphPhaseTaskRecord.d.ts +195 -0
- package/dist/runtime/phases/RaphPhaseWatch.d.ts +22 -0
- package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
- package/dist/runtime/phases/phase.types.d.ts +171 -0
- package/dist/runtime/{PathHandle.d.ts → reactivity/PathHandle.d.ts} +14 -6
- package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
- package/dist/runtime/reactivity/RaphSelector.d.ts +338 -0
- package/dist/runtime/reactivity/RaphWorkGraph.d.ts +309 -0
- package/dist/runtime/reactivity/RuntimeReactivity.d.ts +293 -0
- package/dist/runtime/{RuntimeWatch.d.ts → reactivity/RuntimeWatch.d.ts} +12 -6
- package/dist/runtime/reactivity/disposal-sweep.utils.d.ts +19 -0
- package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +56 -0
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +21 -16
- package/package.json +76 -35
- package/ReadMe.md +0 -153
- package/dist/api/public.d.ts +0 -22
- package/dist/debug/api/public.cjs +0 -1
- package/dist/debug/api/public.js +0 -40
- package/dist/debug/path/AdapterPathStore.cjs +0 -1
- package/dist/debug/path/AdapterPathStore.js +0 -133
- package/dist/debug/path/DerivedRegistry.cjs +0 -1
- package/dist/debug/path/DerivedRegistry.js +0 -157
- package/dist/debug/path/MetaController.cjs +0 -1
- package/dist/debug/path/PathEventHub.cjs +0 -1
- package/dist/debug/path/PathEventHub.js +0 -148
- package/dist/debug/path/PathStore.cjs +0 -1
- package/dist/debug/path/RaphDerivedHandle.cjs +0 -1
- package/dist/debug/path/RaphMeta.cjs +0 -1
- package/dist/debug/path/RaphMeta.js +0 -68
- package/dist/debug/path/RaphMetaStore.cjs +0 -1
- package/dist/debug/path/data-adapter.cjs +0 -1
- package/dist/debug/path/data-draft.cjs +0 -1
- package/dist/debug/path/data-path.cjs +0 -1
- package/dist/debug/path/data-path.js +0 -423
- package/dist/debug/path/derived-collection.cjs +0 -1
- package/dist/debug/path/path-router.cjs +0 -1
- package/dist/debug/path/path-router.js +0 -86
- package/dist/debug/path/public.cjs +0 -1
- package/dist/debug/path/public.js +0 -18
- package/dist/debug/runtime/PathHandle.cjs +0 -1
- package/dist/debug/runtime/PathHandle.js +0 -139
- package/dist/debug/runtime/RaphDebug.cjs +0 -1
- package/dist/debug/runtime/RaphDebug.js +0 -15
- package/dist/debug/runtime/RaphFrameLoop.cjs +0 -1
- package/dist/debug/runtime/RaphNode.cjs +0 -1
- package/dist/debug/runtime/RaphNode.js +0 -143
- package/dist/debug/runtime/RaphPhasePipeline.cjs +0 -1
- package/dist/debug/runtime/RaphPhasePipeline.js +0 -526
- package/dist/debug/runtime/RaphScope.cjs +0 -1
- package/dist/debug/runtime/RaphScope.js +0 -64
- package/dist/debug/runtime/RuntimeReactivity.cjs +0 -1
- package/dist/debug/runtime/RuntimeReactivity.js +0 -154
- package/dist/debug/runtime/RuntimeWatch.cjs +0 -1
- package/dist/debug/runtime/RuntimeWatch.js +0 -71
- package/dist/debug/runtime/public.cjs +0 -1
- package/dist/debug/runtime/public.js +0 -18
- package/dist/path/PathEventHub.d.ts +0 -48
- package/dist/path/public.d.ts +0 -14
- package/dist/runtime/RaphDebug.d.ts +0 -32
- package/dist/runtime/RaphNode.d.ts +0 -68
- package/dist/runtime/RaphPhasePipeline.d.ts +0 -133
- package/dist/runtime/RaphScope.d.ts +0 -50
- package/dist/runtime/RuntimeReactivity.d.ts +0 -40
- package/dist/runtime/phase.types.d.ts +0 -49
- package/dist/runtime/public.d.ts +0 -13
- package/dist/runtime/runtime-reactivity.types.d.ts +0 -9
- /package/dist/debug/path/{meta.types.cjs → data-path.types.cjs} +0 -0
- /package/dist/debug/path/{meta.types.js → data-path.types.js} +0 -0
- /package/dist/debug/{runtime/runtime-reactivity.types.cjs → path/derived/derived-collection.types.cjs} +0 -0
- /package/dist/debug/{runtime/runtime-reactivity.types.js → path/derived/derived-collection.types.js} +0 -0
- /package/dist/debug/path/{derived-strategies.cjs → derived/derived-strategy.utils.cjs} +0 -0
- /package/dist/debug/path/{derived-strategies.js → derived/derived-strategy.utils.js} +0 -0
- /package/dist/debug/path/{segment-key.cjs → pathSegmentKey.cjs} +0 -0
- /package/dist/debug/path/{segment-key.js → pathSegmentKey.js} +0 -0
- /package/dist/debug/runtime/{parent-graph.cjs → ownership/parentGraph.cjs} +0 -0
- /package/dist/debug/runtime/{parent-graph.js → ownership/parentGraph.js} +0 -0
- /package/dist/debug/runtime/{disposal.cjs → ownership/throwDisposalErrors.cjs} +0 -0
- /package/dist/debug/runtime/{disposal.js → ownership/throwDisposalErrors.js} +0 -0
- /package/dist/debug/runtime/{phase.types.cjs → phases/phase.types.cjs} +0 -0
- /package/dist/debug/runtime/{phase.types.js → phases/phase.types.js} +0 -0
- /package/dist/path/{data-draft.d.ts → storage/createDataDraft.d.ts} +0 -0
- /package/dist/runtime/{disposal.d.ts → ownership/throwDisposalErrors.d.ts} +0 -0
- /package/dist/runtime/{RaphFrameLoop.d.ts → phases/RaphFrameLoop.d.ts} +0 -0
|
@@ -0,0 +1,665 @@
|
|
|
1
|
+
import { throwDisposalFailure as S, unroutedDisposalFailure as u, combineDisposalFailures as w } from "../../reactivity/disposal.js";
|
|
2
|
+
import { RaphCrossRuntimeError as v } from "../errors.js";
|
|
3
|
+
import { RaphProducer as x } from "../reactivity/RaphWorkGraph.js";
|
|
4
|
+
import { RaphScope as A } from "./RaphScope.js";
|
|
5
|
+
let O = 0;
|
|
6
|
+
const C = Symbol("RaphProvisionalNode"), N = Object.freeze({}), I = "[Raph] Child order must contain every direct child exactly once.", f = "[Raph] Child order can contain only direct children of the node.";
|
|
7
|
+
let p, c;
|
|
8
|
+
class o extends A {
|
|
9
|
+
#i;
|
|
10
|
+
constructor(i, t = {}, e, r) {
|
|
11
|
+
const s = e ?? (i instanceof o ? i.runtime : i ?? void 0);
|
|
12
|
+
if (s === void 0)
|
|
13
|
+
throw new Error("[RaphNode] A root node requires an explicit runtime.");
|
|
14
|
+
const n = i instanceof o ? i : i?.root ?? null;
|
|
15
|
+
if (n !== null && n.runtime !== s)
|
|
16
|
+
throw new v("[Raph] Parent belongs to another runtime.");
|
|
17
|
+
const l = t.priority ?? 0, h = t.id, a = t.meta, y = a === void 0 ? void 0 : { ...a }, m = t.type ?? "default";
|
|
18
|
+
n?._assertAlive(), b(l), super(h ?? O++, s);
|
|
19
|
+
const g = r === C;
|
|
20
|
+
if (this.priority = l, this._parent = n, this._prevSibling = null, this._nextSibling = null, this._firstChild = null, this._lastChild = null, this._childCount = 0, this._childArray = void 0, this._published = n === null || !g && n._published, this.#i = N, new.target !== o && Object.defineProperty(this, "api", {
|
|
21
|
+
configurable: !0,
|
|
22
|
+
enumerable: !0,
|
|
23
|
+
value: this.#i,
|
|
24
|
+
writable: !0
|
|
25
|
+
}), this._meta = y, this.type = m, this._subtreeIdentity = void 0, n !== null) {
|
|
26
|
+
if (n._appendChild(this), !this._published)
|
|
27
|
+
return;
|
|
28
|
+
s._hasNodeStructureDemand(this) ? s._notifyNodeStructure(this, {
|
|
29
|
+
node: this,
|
|
30
|
+
newIndex: n._childCount - 1,
|
|
31
|
+
newParent: n
|
|
32
|
+
}, [], d(this)) : s._touchMutationBoundary(), this._assertAlive();
|
|
33
|
+
} else
|
|
34
|
+
s._addTopOwner(this);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Возвращает id; номер id по умолчанию превращается в `node-N` при первом чтении.
|
|
38
|
+
*/
|
|
39
|
+
get id() {
|
|
40
|
+
const i = this._id;
|
|
41
|
+
return typeof i == "string" ? i : this._id = `node-${i}`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Возвращает изменяемую metadata node; объект создаётся при первом чтении.
|
|
45
|
+
*/
|
|
46
|
+
get meta() {
|
|
47
|
+
return this._meta ??= {};
|
|
48
|
+
}
|
|
49
|
+
set meta(i) {
|
|
50
|
+
this._meta = i;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Возвращает api, зафиксированный после setup; присваивание снаружи запрещено.
|
|
54
|
+
*/
|
|
55
|
+
get api() {
|
|
56
|
+
return this.#i;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Отличает subtree granule от self granule; identity создаётся по запросу.
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
get _subtreeSourceIdentity() {
|
|
63
|
+
return this._subtreeIdentity ??= Object.freeze({});
|
|
64
|
+
}
|
|
65
|
+
get node() {
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
get parent() {
|
|
69
|
+
return this._parent;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Возвращает прямых детей в их порядке. Массив действителен до следующей
|
|
73
|
+
* структурной mutation этой node; после неё порядок даёт новое чтение.
|
|
74
|
+
*
|
|
75
|
+
* Добавление в конец, удаление последнего child и `reorderChildren`
|
|
76
|
+
* обновляют уже выданный массив на месте. После удаления любого другого
|
|
77
|
+
* child — первого или из середины — выданный массив либо остаётся прежним, и
|
|
78
|
+
* следующее чтение строит новый, либо обновляется на месте — второе
|
|
79
|
+
* происходит, пока у Runtime есть подписчик на node.
|
|
80
|
+
*
|
|
81
|
+
* `moveChild` и `_swapChildren` следуют тому же правилу, что и удаление не
|
|
82
|
+
* последнего child: без подписчика на node выданный массив остаётся прежним,
|
|
83
|
+
* с подписчиком получает новый порядок на месте. `_disposeChildren` забывает
|
|
84
|
+
* выданный массив, если набор начинается с первого child списка: массив
|
|
85
|
+
* хранит состав на начало удаления. Набор, который начинается с другого
|
|
86
|
+
* child, следует правилу отдельных удалений.
|
|
87
|
+
*
|
|
88
|
+
* Собственный dispose node выданный массив не обновляет: пока node удаляет
|
|
89
|
+
* своих детей, он хранит их состав на начало удаления, а после удаления
|
|
90
|
+
* последнего child становится пустым. Оставшихся детей в это время даёт
|
|
91
|
+
* новое чтение; выданный им массив остаётся массивом node до конца удаления:
|
|
92
|
+
* дети выходят из него на месте и при отсутствии подписчика на node, а после
|
|
93
|
+
* последнего child он тоже пуст.
|
|
94
|
+
*/
|
|
95
|
+
get children() {
|
|
96
|
+
return this._childArray ?? this._materializeChildren();
|
|
97
|
+
}
|
|
98
|
+
addChild(i) {
|
|
99
|
+
if (this._assertAlive(), i._assertAlive(), i.runtime !== this.runtime)
|
|
100
|
+
throw new v("[Raph] Child belongs to another runtime.");
|
|
101
|
+
if (this === i)
|
|
102
|
+
throw new Error("[Raph] A node cannot become its own ancestor.");
|
|
103
|
+
if (!i._published || !this._published)
|
|
104
|
+
throw new Error("[Raph] A provisional node cannot be reparented before setup commits.");
|
|
105
|
+
for (let t = this; t !== null; t = t.parent)
|
|
106
|
+
if (t === i)
|
|
107
|
+
throw new Error("[Raph] A node cannot become its own ancestor.");
|
|
108
|
+
return i.parent === this ? !0 : this.runtime._runNodeMutation(() => {
|
|
109
|
+
const t = this.runtime;
|
|
110
|
+
t._assertNodeReparentAllowed(i, this);
|
|
111
|
+
const e = i._parent;
|
|
112
|
+
if (!t._hasNodeStructureDemand(i))
|
|
113
|
+
return e !== null && i._unlinkFrom(e, -1), i._parent = this, this._appendChild(i), e === null && t._removeTopOwner(i), !0;
|
|
114
|
+
const r = d(i), s = e === null ? -1 : i._indexIn(e);
|
|
115
|
+
e !== null && i._unlinkFrom(e, s), i._parent = this;
|
|
116
|
+
const n = this._childCount;
|
|
117
|
+
return this._appendChild(i), e === null && t._removeTopOwner(i), t._notifyNodeStructure(i, {
|
|
118
|
+
node: i,
|
|
119
|
+
...e === null ? {} : { oldParent: e },
|
|
120
|
+
...s < 0 ? {} : { oldIndex: s },
|
|
121
|
+
newParent: this,
|
|
122
|
+
newIndex: n
|
|
123
|
+
}, r, d(i)), !0;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Ставит прямых детей в порядок `nodes`: в нём каждый прямой child ровно
|
|
128
|
+
* один раз. Без подписчика на node порядок проверяется и применяется по
|
|
129
|
+
* связям между siblings, без Set и Map.
|
|
130
|
+
*
|
|
131
|
+
* Каждый элемент `nodes` читается один раз, до проверки. Чтение, которое само
|
|
132
|
+
* меняет дерево — элемент Proxy либо accessor, — не оставляет списки в
|
|
133
|
+
* промежуточном состоянии: порядок проверяется по составу детей после чтения.
|
|
134
|
+
*/
|
|
135
|
+
reorderChildren(i) {
|
|
136
|
+
this._assertAlive(), this._applyChildOrder(i) || this._rejectChildOrder(i);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Ставит прямого child перед прямым child `before` либо в конец списка, если
|
|
140
|
+
* `before === null`. Без подписчика на node меняются только связи самого
|
|
141
|
+
* child и его соседей: цена не зависит от числа детей. С подписчиком каждый
|
|
142
|
+
* child, чей индекс изменился, получает тот же structure cause, что и после
|
|
143
|
+
* `reorderChildren` с итоговым порядком.
|
|
144
|
+
*/
|
|
145
|
+
moveChild(i, t) {
|
|
146
|
+
if (this._assertAlive(), i._assertAlive(), t !== null && t._assertAlive(), i._parent !== this || t !== null && t._parent !== this)
|
|
147
|
+
throw new Error(f);
|
|
148
|
+
const e = this.runtime;
|
|
149
|
+
if (i === t || i._nextSibling === t) {
|
|
150
|
+
e._touchMutationBoundary();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const r = e._hasNodeSubscribers() ? this._indexChildren() : void 0;
|
|
154
|
+
if (this._relinkBefore(i, t), r !== void 0) {
|
|
155
|
+
this._publishChildOrder(r);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
this._childArray = void 0, e._touchMutationBoundary();
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Меняет местами двух прямых детей. Без подписчика на node правятся только
|
|
162
|
+
* связи этих детей и их соседей; с подписчиком оба child получают те же
|
|
163
|
+
* structure causes, что и после `reorderChildren` с итоговым порядком.
|
|
164
|
+
*
|
|
165
|
+
* @internal
|
|
166
|
+
*/
|
|
167
|
+
_swapChildren(i, t) {
|
|
168
|
+
if (this._assertAlive(), i._assertAlive(), t._assertAlive(), i._parent !== this || t._parent !== this)
|
|
169
|
+
throw new Error(f);
|
|
170
|
+
const e = this.runtime;
|
|
171
|
+
if (i === t) {
|
|
172
|
+
e._touchMutationBoundary();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const r = e._hasNodeSubscribers() ? this._indexChildren() : void 0, s = i._nextSibling, n = t._nextSibling;
|
|
176
|
+
if (s === t ? this._relinkBefore(t, i) : n === i ? this._relinkBefore(i, t) : (this._relinkBefore(i, n), this._relinkBefore(t, s)), r !== void 0) {
|
|
177
|
+
this._publishChildOrder(r);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
this._childArray = void 0, e._touchMutationBoundary();
|
|
181
|
+
}
|
|
182
|
+
_disposeChildren(i, t = 0, e = i === void 0 ? 0 : i.length) {
|
|
183
|
+
let r = i;
|
|
184
|
+
if (r === void 0 && (r = this._childArray ?? this._collectChildren(), e = r.length), t >= e)
|
|
185
|
+
return;
|
|
186
|
+
const s = this._childArray;
|
|
187
|
+
s !== void 0 && (s === r || this._firstChild === r[t].node) && (this._childArray = void 0);
|
|
188
|
+
const n = this.runtime;
|
|
189
|
+
let l;
|
|
190
|
+
n._beginOwnerDisposal();
|
|
191
|
+
for (let h = t; h < e; h++)
|
|
192
|
+
try {
|
|
193
|
+
r[h].node.dispose();
|
|
194
|
+
} catch (a) {
|
|
195
|
+
(l ??= []).push(a);
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
n._endOwnerDisposal();
|
|
199
|
+
} catch (h) {
|
|
200
|
+
(l ??= []).push(h);
|
|
201
|
+
}
|
|
202
|
+
return l;
|
|
203
|
+
}
|
|
204
|
+
options(i) {
|
|
205
|
+
this._assertAlive(), i.meta !== void 0 && (this._meta = { ...i.meta }), i.priority !== void 0 && (b(i.priority), this.priority = i.priority), i.type !== void 0 && (this.type = i.type), this.touch(Object.freeze({ options: Object.freeze({ ...i }) }));
|
|
206
|
+
}
|
|
207
|
+
/** Invalidates coarse self/subtree/runtime granules for non-reactive state. */
|
|
208
|
+
touch(i) {
|
|
209
|
+
this._assertAlive(), this.runtime._runNodeMutation(() => this.runtime._notifyNodeTouch(this, i));
|
|
210
|
+
}
|
|
211
|
+
remove() {
|
|
212
|
+
this.dispose();
|
|
213
|
+
}
|
|
214
|
+
dispose() {
|
|
215
|
+
S(c.call(this));
|
|
216
|
+
}
|
|
217
|
+
/** Calls actual public dispatch once; only native disposal can return provenance. @internal */
|
|
218
|
+
_disposeForOwner() {
|
|
219
|
+
try {
|
|
220
|
+
const i = this.dispose;
|
|
221
|
+
if (i === p)
|
|
222
|
+
return c.call(this);
|
|
223
|
+
i.call(this);
|
|
224
|
+
return;
|
|
225
|
+
} catch (i) {
|
|
226
|
+
return u(i);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/** Result of this exact framework call, without changing raw public disposal. @internal */
|
|
230
|
+
_disposeWithOutcome() {
|
|
231
|
+
if (this._disposed || this._disposing)
|
|
232
|
+
return;
|
|
233
|
+
this._disposing = !0;
|
|
234
|
+
const i = this.runtime;
|
|
235
|
+
i._beginOwnerDisposal(this);
|
|
236
|
+
let t;
|
|
237
|
+
try {
|
|
238
|
+
if (this._firstChild !== null) {
|
|
239
|
+
const r = this._takeChildSnapshot();
|
|
240
|
+
for (let s = 0; s < r.length; s++) {
|
|
241
|
+
const n = r[s];
|
|
242
|
+
try {
|
|
243
|
+
const l = n.dispose;
|
|
244
|
+
if (l === p) {
|
|
245
|
+
const h = c.call(n);
|
|
246
|
+
h !== void 0 && (t ??= []).push(h);
|
|
247
|
+
} else
|
|
248
|
+
l.call(n);
|
|
249
|
+
} catch (l) {
|
|
250
|
+
(t ??= []).push(u(l));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
this._resetChildList(r);
|
|
254
|
+
}
|
|
255
|
+
const e = this._parent;
|
|
256
|
+
if (this._published && i._hasNodeStructureDemand(this)) {
|
|
257
|
+
const r = d(this), s = e === null ? -1 : this._indexIn(e);
|
|
258
|
+
e !== null && (this._unlinkFrom(e, s), this._parent = null);
|
|
259
|
+
try {
|
|
260
|
+
i._notifyNodeStructure(this, {
|
|
261
|
+
node: this,
|
|
262
|
+
...e === null ? {} : { oldParent: e },
|
|
263
|
+
...s < 0 ? {} : { oldIndex: s }
|
|
264
|
+
}, r, []);
|
|
265
|
+
} catch (n) {
|
|
266
|
+
(t ??= []).push(u(n));
|
|
267
|
+
}
|
|
268
|
+
} else if (e !== null && (this._unlinkFrom(e, -1), this._parent = null), this._published)
|
|
269
|
+
try {
|
|
270
|
+
i._touchMutationBoundary();
|
|
271
|
+
} catch (r) {
|
|
272
|
+
(t ??= []).push(u(r));
|
|
273
|
+
}
|
|
274
|
+
try {
|
|
275
|
+
const r = super._disposeScopeForOwner(super.dispose);
|
|
276
|
+
r !== void 0 && (t ??= []).push(r);
|
|
277
|
+
} catch (r) {
|
|
278
|
+
(t ??= []).push(u(r));
|
|
279
|
+
}
|
|
280
|
+
e === null && i._removeTopOwner(this), this._published = !1;
|
|
281
|
+
try {
|
|
282
|
+
i._releaseNode(this);
|
|
283
|
+
} catch (r) {
|
|
284
|
+
(t ??= []).push(u(r));
|
|
285
|
+
}
|
|
286
|
+
} finally {
|
|
287
|
+
try {
|
|
288
|
+
i._endOwnerDisposal();
|
|
289
|
+
} catch (e) {
|
|
290
|
+
(t ??= []).push(u(e));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (t !== void 0)
|
|
294
|
+
return w(t, `[Raph] Node "${this.id}" disposal failed.`);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Фиксирует api после setup; object api замораживается, как и раньше.
|
|
298
|
+
* Исключение — Runtime signal, возвращённый как api: значение, запись графа
|
|
299
|
+
* и связи подписчиков лежат в его собственных полях, поэтому заморозка
|
|
300
|
+
* лишила бы его записи, отслеживаемого чтения, watch и освобождения вместе
|
|
301
|
+
* с владельцем.
|
|
302
|
+
* @internal
|
|
303
|
+
*/
|
|
304
|
+
_setApi(i) {
|
|
305
|
+
this.#i = typeof i == "object" && i !== null && !(i instanceof x) ? Object.freeze(i) : i, Object.hasOwn(this, "api") && Object.defineProperty(this, "api", {
|
|
306
|
+
configurable: !1,
|
|
307
|
+
enumerable: !0,
|
|
308
|
+
value: this.#i,
|
|
309
|
+
writable: !1
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
/** Publishes a fully initialized provisional subtree. @internal */
|
|
313
|
+
_publishCreation() {
|
|
314
|
+
if (this._published)
|
|
315
|
+
return;
|
|
316
|
+
const i = this._parent;
|
|
317
|
+
if (!(i === null || !i._published)) {
|
|
318
|
+
this._published = !0;
|
|
319
|
+
try {
|
|
320
|
+
const t = this.runtime;
|
|
321
|
+
t._hasNodeStructureDemand(this) ? t._notifyNodeStructure(this, {
|
|
322
|
+
node: this,
|
|
323
|
+
newIndex: this._indexIn(i),
|
|
324
|
+
newParent: i
|
|
325
|
+
}, [], d(this)) : t._touchMutationBoundary();
|
|
326
|
+
for (let e = this._firstChild; e !== null; e = e._nextSibling)
|
|
327
|
+
e._publishCreation();
|
|
328
|
+
} catch (t) {
|
|
329
|
+
throw this._published = !1, t;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/** @internal */
|
|
334
|
+
_isPublished() {
|
|
335
|
+
return this._published;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Сообщает, стоит ли node в списке детей своего parent. Node без parent и
|
|
339
|
+
* node, чей parent уже сбросил свой список, в нём не стоят.
|
|
340
|
+
*
|
|
341
|
+
* @internal
|
|
342
|
+
*/
|
|
343
|
+
_isLinked() {
|
|
344
|
+
const i = this._parent;
|
|
345
|
+
return i !== null && (this._prevSibling !== null || i._firstChild === this);
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Добавляет в `into` всех потомков node по связям списков детей: каждый
|
|
349
|
+
* child сразу за своим parent, дети — в порядке списка. Обход не строит
|
|
350
|
+
* массивы `children` и не зависит от глубины стека.
|
|
351
|
+
*
|
|
352
|
+
* @internal
|
|
353
|
+
*/
|
|
354
|
+
_collectDescendants(i) {
|
|
355
|
+
let t = this;
|
|
356
|
+
for (; ; ) {
|
|
357
|
+
let e = t._firstChild;
|
|
358
|
+
for (; e === null; ) {
|
|
359
|
+
if (t === this)
|
|
360
|
+
return;
|
|
361
|
+
e = t._nextSibling, e === null && (t = t._parent);
|
|
362
|
+
}
|
|
363
|
+
t = e, i.push(t);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Прибавляет к `totals` число ресурсов и sources самой node и всех её
|
|
368
|
+
* потомков. Обход тот же, что у `_collectDescendants`, но владельцев он не
|
|
369
|
+
* собирает: подсчёт для diagnostics не выделяет память по числу владельцев.
|
|
370
|
+
*
|
|
371
|
+
* @internal
|
|
372
|
+
*/
|
|
373
|
+
_countSubtree(i) {
|
|
374
|
+
let t = this;
|
|
375
|
+
for (; ; ) {
|
|
376
|
+
i.resources += t._debugResourceCount(), i.sources += t._debugSourceCount();
|
|
377
|
+
let e = t._firstChild;
|
|
378
|
+
for (; e === null; ) {
|
|
379
|
+
if (t === this)
|
|
380
|
+
return;
|
|
381
|
+
e = t._nextSibling, e === null && (t = t._parent);
|
|
382
|
+
}
|
|
383
|
+
t = e;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Ищет node по id в своём поддереве. Порядок обхода прежний: сама node,
|
|
388
|
+
* затем дети от последнего к первому, каждый вместе со своим поддеревом.
|
|
389
|
+
*
|
|
390
|
+
* @internal
|
|
391
|
+
*/
|
|
392
|
+
_findNode(i) {
|
|
393
|
+
let t = this;
|
|
394
|
+
for (; ; ) {
|
|
395
|
+
if (t.id === i)
|
|
396
|
+
return t;
|
|
397
|
+
let e = t._lastChild;
|
|
398
|
+
for (; e === null; ) {
|
|
399
|
+
if (t === this)
|
|
400
|
+
return;
|
|
401
|
+
e = t._prevSibling, e === null && (t = t._parent);
|
|
402
|
+
}
|
|
403
|
+
t = e;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Применяет порядок детей `nodes`. Возвращает `false` и оставляет список
|
|
408
|
+
* прежним, если `nodes` не содержит каждого живого прямого child ровно один
|
|
409
|
+
* раз. Прежние индексы собираются только при подписчике на node: без него
|
|
410
|
+
* structure cause никто не получит.
|
|
411
|
+
*/
|
|
412
|
+
_applyChildOrder(i) {
|
|
413
|
+
const t = i.length;
|
|
414
|
+
if (t !== this._childCount)
|
|
415
|
+
return !1;
|
|
416
|
+
const e = [];
|
|
417
|
+
for (let l = 0; l < t; l++)
|
|
418
|
+
e.push(i[l]);
|
|
419
|
+
if (t !== this._childCount)
|
|
420
|
+
return !1;
|
|
421
|
+
const r = this.runtime, s = r._hasNodeSubscribers() ? this._indexChildren() : void 0;
|
|
422
|
+
if (!this._relinkChildren(e))
|
|
423
|
+
return !1;
|
|
424
|
+
const n = this._childArray;
|
|
425
|
+
if (n !== void 0 && n !== i)
|
|
426
|
+
for (let l = 0; l < t; l++)
|
|
427
|
+
n[l] = e[l];
|
|
428
|
+
return s === void 0 ? r._touchMutationBoundary() : this._notifyChildOrder(e, s), !0;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Проверяет порядок и переставляет связи за три прохода без Set и Map.
|
|
432
|
+
* Сначала каждый child списка получает метку: его `_prevSibling` указывает на
|
|
433
|
+
* parent, чего у прямого child не бывает. Затем метка снимается у каждой node
|
|
434
|
+
* из `nodes`: node без метки — чужая, удаляемая либо повторная. При отказе
|
|
435
|
+
* и при ошибке чтения `nodes` связи `_prevSibling` восстанавливаются по
|
|
436
|
+
* нетронутым `_nextSibling`.
|
|
437
|
+
*
|
|
438
|
+
* `nodes` — собственная копия порядка: её чтение не исполняет чужой код, и
|
|
439
|
+
* между расстановкой меток и их снятием дерево никто не меняет.
|
|
440
|
+
*/
|
|
441
|
+
_relinkChildren(i) {
|
|
442
|
+
for (let n = this._firstChild; n !== null; n = n._nextSibling)
|
|
443
|
+
n._prevSibling = this;
|
|
444
|
+
const t = i.length;
|
|
445
|
+
let e = null, r = 0;
|
|
446
|
+
try {
|
|
447
|
+
for (; r < t; r++) {
|
|
448
|
+
const n = i[r];
|
|
449
|
+
if (n?._parent !== this || n._prevSibling !== this || n._disposing)
|
|
450
|
+
break;
|
|
451
|
+
n._prevSibling = e, e = n;
|
|
452
|
+
}
|
|
453
|
+
} finally {
|
|
454
|
+
if (r !== t) {
|
|
455
|
+
let n = null;
|
|
456
|
+
for (let l = this._firstChild; l !== null; l = l._nextSibling)
|
|
457
|
+
l._prevSibling = n, n = l;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (r !== t)
|
|
461
|
+
return !1;
|
|
462
|
+
let s = null;
|
|
463
|
+
for (let n = e; n !== null; n = n._prevSibling)
|
|
464
|
+
n._nextSibling = s, s = n;
|
|
465
|
+
return this._firstChild = s, this._lastChild = e, !0;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Сообщает причину отказа порядка `nodes` теми же ошибками и в том же
|
|
469
|
+
* порядке, что и прежняя проверка; Set нужен только здесь.
|
|
470
|
+
*/
|
|
471
|
+
_rejectChildOrder(i) {
|
|
472
|
+
if (i.length === this._childCount && new Set(i).size === i.length) {
|
|
473
|
+
for (const t of i)
|
|
474
|
+
if (t._assertAlive(), t._parent !== this)
|
|
475
|
+
throw new Error(f);
|
|
476
|
+
}
|
|
477
|
+
throw new Error(I);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Запоминает индекс каждого child до перестановки; нужен только для
|
|
481
|
+
* structure causes.
|
|
482
|
+
*/
|
|
483
|
+
_indexChildren() {
|
|
484
|
+
const i = /* @__PURE__ */ new Map();
|
|
485
|
+
let t = 0;
|
|
486
|
+
for (let e = this._firstChild; e !== null; e = e._nextSibling)
|
|
487
|
+
i.set(e, t++);
|
|
488
|
+
return i;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Завершает перестановку связей при подписчике на node: массив детей
|
|
492
|
+
* получает новый порядок на месте либо строится, и каждый child со
|
|
493
|
+
* сменившимся индексом получает structure cause.
|
|
494
|
+
*/
|
|
495
|
+
_publishChildOrder(i) {
|
|
496
|
+
let t = this._childArray;
|
|
497
|
+
if (t === void 0)
|
|
498
|
+
t = this._materializeChildren();
|
|
499
|
+
else {
|
|
500
|
+
let e = 0;
|
|
501
|
+
for (let r = this._firstChild; r !== null; r = r._nextSibling)
|
|
502
|
+
t[e++] = r;
|
|
503
|
+
}
|
|
504
|
+
this._notifyChildOrder(t, i);
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Публикует structure cause каждому child, чей индекс изменился, в новом
|
|
508
|
+
* порядке детей и одной границей mutation.
|
|
509
|
+
*/
|
|
510
|
+
_notifyChildOrder(i, t) {
|
|
511
|
+
const e = this.runtime;
|
|
512
|
+
e._runNodeMutation(() => {
|
|
513
|
+
for (let r = 0; r < i.length; r++) {
|
|
514
|
+
const s = i[r], n = t.get(s);
|
|
515
|
+
if (n === r)
|
|
516
|
+
continue;
|
|
517
|
+
const l = d(s);
|
|
518
|
+
e._notifyNodeStructure(s, {
|
|
519
|
+
node: s,
|
|
520
|
+
oldParent: this,
|
|
521
|
+
newParent: this,
|
|
522
|
+
oldIndex: n,
|
|
523
|
+
newIndex: r
|
|
524
|
+
}, l, l);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Переставляет child перед `before` либо в конец списка, меняя только связи
|
|
530
|
+
* child и его соседей. Вызывающий гарантирует, что оба — дети этой node и
|
|
531
|
+
* что child ещё не стоит перед `before`.
|
|
532
|
+
*/
|
|
533
|
+
_relinkBefore(i, t) {
|
|
534
|
+
const e = i._prevSibling, r = i._nextSibling;
|
|
535
|
+
e === null ? this._firstChild = r : e._nextSibling = r, r === null ? this._lastChild = e : r._prevSibling = e;
|
|
536
|
+
const s = t === null ? this._lastChild : t._prevSibling;
|
|
537
|
+
i._prevSibling = s, i._nextSibling = t, s === null ? this._firstChild = i : s._nextSibling = i, t === null ? this._lastChild = i : t._prevSibling = i;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Строит массив детей по связям и запоминает его для следующих чтений.
|
|
541
|
+
*/
|
|
542
|
+
_materializeChildren() {
|
|
543
|
+
return this._childArray = this._collectChildren();
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Собирает детей по связям в новый массив, не запоминая его.
|
|
547
|
+
*/
|
|
548
|
+
_collectChildren() {
|
|
549
|
+
const i = [];
|
|
550
|
+
for (let t = this._firstChild; t !== null; t = t._nextSibling)
|
|
551
|
+
i.push(t);
|
|
552
|
+
return i;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Очищает и забывает выданный массив детей, если он есть.
|
|
556
|
+
*/
|
|
557
|
+
_clearChildArray() {
|
|
558
|
+
const i = this._childArray;
|
|
559
|
+
i !== void 0 && (i.length = 0, this._childArray = void 0);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Добавляет child в конец списка; уже выданный массив получает его через push.
|
|
563
|
+
*/
|
|
564
|
+
_appendChild(i) {
|
|
565
|
+
const t = this._lastChild;
|
|
566
|
+
i._prevSibling = t, t === null ? this._firstChild = i : t._nextSibling = i, this._lastChild = i, this._childCount++;
|
|
567
|
+
const e = this._childArray;
|
|
568
|
+
e !== void 0 && e.push(i);
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Возвращает позицию node среди детей `parent` либо -1, если `parent` уже
|
|
572
|
+
* сбросил свой список и node в нём не состоит. Нужна только для structure
|
|
573
|
+
* cause. Первый и последний child определяются по связям, остальные — через
|
|
574
|
+
* `indexOf` по массиву детей, как и раньше; массив строится один раз и затем
|
|
575
|
+
* поддерживается, поэтому обход связей на каждый запрос не повторяется.
|
|
576
|
+
*/
|
|
577
|
+
_indexIn(i) {
|
|
578
|
+
return this._prevSibling === null ? i._firstChild === this ? 0 : -1 : i._lastChild === this ? i._childCount - 1 : (i._childArray ?? i._materializeChildren()).indexOf(this);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Вынимает node из списка `parent` и обнуляет её связи, чтобы удержанная node
|
|
582
|
+
* не удерживала соседей. Связи правятся за постоянное время.
|
|
583
|
+
*
|
|
584
|
+
* Уже выданный массив теряет последний child через pop. Любой другой child —
|
|
585
|
+
* первый или из середины — вырезается на месте, только если его `index`
|
|
586
|
+
* известен (>= 0) либо у Runtime есть подписчик на node: тогда массив ещё
|
|
587
|
+
* понадобится для индексов и перестраивать его по связям после каждого
|
|
588
|
+
* удаления дороже. Иначе массив не правится, а отбрасывается, и следующее
|
|
589
|
+
* чтение `children` строит новый: очистка списка от первого child к
|
|
590
|
+
* последнему не сдвигает массив на каждое удаление.
|
|
591
|
+
*
|
|
592
|
+
* Пока parent удаляет собственных детей, массив не отбрасывается: его мог
|
|
593
|
+
* запросить только cleanup уже удаляемого child, и `_resetChildList` обязан
|
|
594
|
+
* очистить именно его. Отброшенный массив остался бы у cleanup с удалёнными
|
|
595
|
+
* детьми внутри.
|
|
596
|
+
*/
|
|
597
|
+
_unlinkFrom(i, t) {
|
|
598
|
+
const e = this._prevSibling, r = this._nextSibling;
|
|
599
|
+
if (e === null) {
|
|
600
|
+
if (i._firstChild !== this)
|
|
601
|
+
return;
|
|
602
|
+
i._firstChild = r;
|
|
603
|
+
} else
|
|
604
|
+
e._nextSibling = r, this._prevSibling = null;
|
|
605
|
+
r === null ? i._lastChild = e : (r._prevSibling = e, this._nextSibling = null), i._childCount--;
|
|
606
|
+
const s = i._childArray;
|
|
607
|
+
if (s !== void 0)
|
|
608
|
+
if (r === null)
|
|
609
|
+
s.pop();
|
|
610
|
+
else if (t < 0 && !i._disposing && !this.runtime._hasNodeSubscribers())
|
|
611
|
+
i._childArray = void 0;
|
|
612
|
+
else if (e === null)
|
|
613
|
+
s.shift();
|
|
614
|
+
else {
|
|
615
|
+
const n = t >= 0 ? t : s.indexOf(this);
|
|
616
|
+
n >= 0 ? s.splice(n, 1) : i._childArray = void 0;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Возвращает snapshot детей для их удаления. Уже выданный массив
|
|
621
|
+
* переиспользуется без копии и на время удаления перестаёт быть массивом
|
|
622
|
+
* node: дети выходят из списка только через связи, snapshot не сдвигается, и
|
|
623
|
+
* удаление не платит за `shift` на каждого child. Иначе snapshot строится по
|
|
624
|
+
* связям.
|
|
625
|
+
*/
|
|
626
|
+
_takeChildSnapshot() {
|
|
627
|
+
const i = this._childArray;
|
|
628
|
+
return i === void 0 ? this._collectChildren() : (this._childArray = void 0, i);
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Сбрасывает собственный список после удаления детей. `snapshot` мог быть
|
|
632
|
+
* выданным массивом: как и раньше, у удалённой node он остаётся пустым.
|
|
633
|
+
* Массив, запрошенный во время удаления, очищается так же: `_unlinkFrom` не
|
|
634
|
+
* отбрасывает его, пока node удаляет своих детей.
|
|
635
|
+
*/
|
|
636
|
+
_resetChildList(i) {
|
|
637
|
+
i.length = 0, this._clearChildArray();
|
|
638
|
+
let t = this._firstChild;
|
|
639
|
+
for (; t !== null; ) {
|
|
640
|
+
const e = t._nextSibling;
|
|
641
|
+
t._prevSibling = null, t._nextSibling = null, t = e;
|
|
642
|
+
}
|
|
643
|
+
this._firstChild = null, this._lastChild = null, this._childCount = 0;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
function E(_, i, t) {
|
|
647
|
+
return new o(_, i, t, C);
|
|
648
|
+
}
|
|
649
|
+
o.prototype._isNode = !0;
|
|
650
|
+
function d(_) {
|
|
651
|
+
const i = [];
|
|
652
|
+
for (let t = _; t !== null; t = t.parent)
|
|
653
|
+
i.push(t);
|
|
654
|
+
return i;
|
|
655
|
+
}
|
|
656
|
+
function b(_) {
|
|
657
|
+
if (!Number.isFinite(_))
|
|
658
|
+
throw new TypeError("[Raph] Node priority must be finite.");
|
|
659
|
+
}
|
|
660
|
+
p = o.prototype.dispose;
|
|
661
|
+
c = o.prototype._disposeWithOutcome;
|
|
662
|
+
export {
|
|
663
|
+
o as RaphNode,
|
|
664
|
+
E as createProvisionalNode
|
|
665
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../../reactivity/disposal.cjs"),c=require("../../reactivity/scope.cjs"),p=require("../errors.cjs");let l,u;class n extends c.ScopeOwner{constructor(e,t){super(),this._id=e,this.runtime=t,this._order=t._registerOwner(this)}get id(){return this._id}get node(){}signal(e){return this._assertAlive(),this.runtime.signal(e,this)}computed(e){return this._assertAlive(),typeof e=="function"?this.runtime.computed(e,this):this.runtime.computed(e,this)}selector(e,t){const i=this.runtime;return i._assertOwnerRuntime(this),i._getReactivity().selectorForOwner(e,this,t).select}effect(e,t,i){return this._assertAlive(),this.runtime.effect(this,e,t,i)}bindEffect(e,t,i){this._assertAlive(),this.runtime._effectRegistration(this,e,t,i,!1,!0)}effectGroup(e,t,i,s,r){return this._assertAlive(),this.runtime._effectGroupRegistration(this,e,t,i,s,r)}watch(e,t,i,s){return this._assertAlive(),this.runtime.watch(this,e,t,i,s)}_registerEffect(e,t,i,s,r,h){this._assertAlive(),this.runtime._effectRegistration(this,e,t,i,!1,s,r,h)}_registerWatch(e,t,i,s,r,h){this._assertAlive(),this.runtime._watchRegistration(this,e,t,i,s,!1,r,h)}_registerEffectGroup(e,t,i,s,r){return this._assertAlive(),this.runtime._effectGroupRegistration(this,e,t,i,s,r)}aggregate(e){return this._assertAlive(),this.runtime.aggregate(this,e)}action(e,t){return this._assertAlive(),typeof e=="function"?this.runtime.action(e,this):this.runtime.action(e,t,this)}own(e){return this._disposed||this._disposing?(e(),a):this._ownCleanup(e)}dispose(){o.throwDisposalFailure(u.call(this))}_disposeScopeForOwner(e){try{if(e===l)return u.call(this);e.call(this);return}catch(t){return o.unroutedDisposalFailure(t)}}_disposeWithOutcome(){if(this._disposed)return;this._disposed=!0,this._disposing=!0;const e=this.runtime,t=!e._ownerDisposalActive();t&&e._beginOwnerDisposal();let i;try{const s=this._releaseOwned();s!==void 0&&(i=[o.combineDisposalFailures(s,"ScopeNode disposal failed.")])}finally{this._disposing=!1;try{e._unregisterOwner(this)}catch(s){(i??=[]).push(o.unroutedDisposalFailure(s))}if(t)try{e._endOwnerDisposal()}catch(s){(i??=[]).push(o.unroutedDisposalFailure(s))}}if(i!==void 0)return o.combineDisposalFailures(i,`[Raph] Scope "${this.id}" disposal failed.`)}_ownCompletedCleanup(e){return this._disposed||this._disposing?(o.throwDisposalFailure(e()),a):this._ownCompleted(e)}_adoptResource(e){return this._assertAlive(),this._ownCleanup(e)}_adoptRecord(e){this._assertAlive(),this._ownRecord(e)}_adoptSource(e){return this._assertAlive(),this._ownSourceFinalizer(e.dispose),e.source}_adoptSourceEntry(e){this._assertAlive(),this._ownSourceEntry(e)}_assertAlive(){if(this._disposed||this._disposing)throw new p.RaphDisposedError(`[Raph] Owner "${this.id}" is disposed.`)}}n.prototype._isNode=!1;function a(){}l=n.prototype.dispose;u=n.prototype._disposeWithOutcome;exports.RaphScope=n;
|