@oasys/oecs 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +553 -0
- package/README.md +42 -31
- package/dist/core/ecs/access_check.d.cts +77 -0
- package/dist/core/ecs/access_check.d.ts +8 -8
- package/dist/core/ecs/access_check.d.ts.map +1 -1
- package/dist/core/ecs/archetype.d.cts +486 -0
- package/dist/core/ecs/archetype.d.ts +23 -11
- package/dist/core/ecs/archetype.d.ts.map +1 -1
- package/dist/core/ecs/archetype_graph.d.cts +96 -0
- package/dist/core/ecs/archetype_graph.d.ts +96 -0
- package/dist/core/ecs/archetype_graph.d.ts.map +1 -0
- package/dist/core/ecs/builtin_relations.d.cts +43 -0
- package/dist/core/ecs/builtin_relations.d.ts +8 -8
- package/dist/core/ecs/builtin_relations.d.ts.map +1 -1
- package/dist/core/ecs/command_log.d.cts +116 -0
- package/dist/core/ecs/command_log.d.ts +13 -10
- package/dist/core/ecs/command_log.d.ts.map +1 -1
- package/dist/core/ecs/component.d.cts +176 -0
- package/dist/core/ecs/component.d.ts +75 -5
- package/dist/core/ecs/component.d.ts.map +1 -1
- package/dist/core/ecs/compute_backend.d.cts +37 -0
- package/dist/core/ecs/compute_backend.d.ts +2 -2
- package/dist/core/ecs/debug_names.d.cts +7 -0
- package/dist/core/ecs/debug_names.d.ts +7 -0
- package/dist/core/ecs/debug_names.d.ts.map +1 -0
- package/dist/core/ecs/deferred_commands.d.cts +55 -0
- package/dist/core/ecs/deferred_commands.d.ts +55 -0
- package/dist/core/ecs/deferred_commands.d.ts.map +1 -0
- package/dist/core/ecs/dispatch_trace.d.cts +93 -0
- package/dist/core/ecs/dispatch_trace.d.ts +3 -3
- package/dist/core/ecs/ecs.d.cts +562 -0
- package/dist/core/ecs/ecs.d.ts +314 -285
- package/dist/core/ecs/ecs.d.ts.map +1 -1
- package/dist/core/ecs/ecs_memory.d.cts +179 -0
- package/dist/core/ecs/ecs_memory.d.ts +1 -1
- package/dist/core/ecs/entity.d.cts +34 -0
- package/dist/core/ecs/entity.d.ts +7 -1
- package/dist/core/ecs/entity.d.ts.map +1 -1
- package/dist/core/ecs/entity_allocator.d.cts +59 -0
- package/dist/core/ecs/entity_allocator.d.ts +59 -0
- package/dist/core/ecs/entity_allocator.d.ts.map +1 -0
- package/dist/core/ecs/event.d.cts +79 -0
- package/dist/core/ecs/event.d.ts +36 -11
- package/dist/core/ecs/event.d.ts.map +1 -1
- package/dist/core/ecs/event_registry.d.cts +22 -0
- package/dist/core/ecs/event_registry.d.ts +22 -0
- package/dist/core/ecs/event_registry.d.ts.map +1 -0
- package/dist/core/ecs/facades.d.cts +158 -0
- package/dist/core/ecs/facades.d.ts +158 -0
- package/dist/core/ecs/facades.d.ts.map +1 -0
- package/dist/core/ecs/frame_stepper.d.cts +58 -0
- package/dist/core/ecs/frame_stepper.d.ts +58 -0
- package/dist/core/ecs/frame_stepper.d.ts.map +1 -0
- package/dist/core/ecs/frame_trace.d.cts +133 -0
- package/dist/core/ecs/frame_trace.d.ts +5 -5
- package/dist/core/ecs/frame_trace.d.ts.map +1 -1
- package/dist/core/ecs/host_commands.d.cts +274 -0
- package/dist/core/ecs/host_commands.d.ts +53 -31
- package/dist/core/ecs/host_commands.d.ts.map +1 -1
- package/dist/core/ecs/index.d.cts +46 -0
- package/dist/core/ecs/index.d.ts +45 -40
- package/dist/core/ecs/index.d.ts.map +1 -1
- package/dist/core/ecs/observer.d.cts +173 -0
- package/dist/core/ecs/observer.d.ts +43 -12
- package/dist/core/ecs/observer.d.ts.map +1 -1
- package/dist/core/ecs/query.d.cts +718 -0
- package/dist/core/ecs/query.d.ts +251 -90
- package/dist/core/ecs/query.d.ts.map +1 -1
- package/dist/core/ecs/ref.d.cts +31 -0
- package/dist/core/ecs/ref.d.ts +3 -3
- package/dist/core/ecs/relation.d.cts +243 -0
- package/dist/core/ecs/relation.d.ts +26 -14
- package/dist/core/ecs/relation.d.ts.map +1 -1
- package/dist/core/ecs/relation_service.d.cts +235 -0
- package/dist/core/ecs/relation_service.d.ts +235 -0
- package/dist/core/ecs/relation_service.d.ts.map +1 -0
- package/dist/core/ecs/resource.d.cts +53 -0
- package/dist/core/ecs/resource.d.ts +25 -5
- package/dist/core/ecs/resource.d.ts.map +1 -1
- package/dist/core/ecs/resource_registry.d.cts +20 -0
- package/dist/core/ecs/resource_registry.d.ts +20 -0
- package/dist/core/ecs/resource_registry.d.ts.map +1 -0
- package/dist/core/ecs/resume.d.cts +85 -0
- package/dist/core/ecs/resume.d.ts +6 -6
- package/dist/core/ecs/resume.d.ts.map +1 -1
- package/dist/core/ecs/run_condition.d.cts +81 -0
- package/dist/core/ecs/run_condition.d.ts +15 -9
- package/dist/core/ecs/run_condition.d.ts.map +1 -1
- package/dist/core/ecs/schedule.d.cts +142 -0
- package/dist/core/ecs/schedule.d.ts +15 -6
- package/dist/core/ecs/schedule.d.ts.map +1 -1
- package/dist/core/ecs/snapshot_service.d.cts +94 -0
- package/dist/core/ecs/snapshot_service.d.ts +94 -0
- package/dist/core/ecs/snapshot_service.d.ts.map +1 -0
- package/dist/core/ecs/sparse_store.d.cts +110 -0
- package/dist/core/ecs/sparse_store.d.ts +5 -2
- package/dist/core/ecs/sparse_store.d.ts.map +1 -1
- package/dist/core/ecs/store.d.cts +950 -0
- package/dist/core/ecs/store.d.ts +143 -342
- package/dist/core/ecs/store.d.ts.map +1 -1
- package/dist/core/ecs/store_layout_listener.d.cts +23 -0
- package/dist/core/ecs/system.d.cts +250 -0
- package/dist/core/ecs/system.d.ts +138 -22
- package/dist/core/ecs/system.d.ts.map +1 -1
- package/dist/{utils/arrays.d.ts → core/ecs/utils/arrays.d.cts} +1 -0
- package/dist/core/ecs/utils/error.d.cts +61 -0
- package/dist/core/ecs/utils/error.d.ts +12 -2
- package/dist/core/ecs/utils/error.d.ts.map +1 -1
- package/dist/core/store/action_ring.d.cts +136 -0
- package/dist/core/store/allocator.d.cts +238 -0
- package/dist/core/store/allocator.d.ts.map +1 -1
- package/dist/core/store/buffer_backed_column.d.cts +69 -0
- package/dist/core/store/buffer_backed_column.d.ts +2 -2
- package/dist/core/store/column_store.d.cts +273 -0
- package/dist/core/store/column_store.d.ts +18 -10
- package/dist/core/store/column_store.d.ts.map +1 -1
- package/dist/core/store/command_dispatch.d.cts +52 -0
- package/dist/core/store/command_ring.d.cts +107 -0
- package/dist/core/store/descriptor.d.cts +80 -0
- package/dist/core/store/descriptor.d.ts +1 -1
- package/dist/core/store/descriptor.d.ts.map +1 -1
- package/dist/core/store/entity_index.d.cts +108 -0
- package/dist/core/store/event_ring.d.cts +95 -0
- package/dist/core/store/extend.d.cts +39 -0
- package/dist/core/store/extend.d.ts +3 -73
- package/dist/core/store/extend.d.ts.map +1 -1
- package/dist/core/store/grow.d.cts +34 -0
- package/dist/core/store/grow.d.ts +4 -9
- package/dist/core/store/grow.d.ts.map +1 -1
- package/dist/core/store/header.d.cts +64 -0
- package/dist/core/store/header.d.ts +1 -1
- package/dist/core/store/header.d.ts.map +1 -1
- package/dist/core/store/index.d.cts +17 -0
- package/dist/core/store/index.d.ts +16 -15
- package/dist/core/store/index.d.ts.map +1 -1
- package/dist/core/store/layout_ops.d.cts +152 -0
- package/dist/core/store/layout_ops.d.ts +152 -0
- package/dist/core/store/layout_ops.d.ts.map +1 -0
- package/dist/core/store/region_table.d.cts +74 -0
- package/dist/core/store/region_table.d.ts +1 -1
- package/dist/core/store/region_table.d.ts.map +1 -1
- package/dist/core/store/snapshot.d.cts +43 -0
- package/dist/core/store/snapshot.d.ts +2 -2
- package/dist/core/store/state_hash.d.cts +38 -0
- package/dist/core/store/state_hash.d.ts +1 -1
- package/dist/core/store/store_regions.d.cts +38 -0
- package/dist/core/store/store_regions.d.ts +1 -1
- package/dist/core/store/vendored_abi/abi.d.ts +43 -0
- package/dist/core/store/{__generated__ → vendored_abi}/abi.d.ts.map +1 -1
- package/dist/dev_flag.d.cts +17 -0
- package/dist/dev_flag.d.ts +17 -0
- package/dist/dev_flag.d.ts.map +1 -0
- package/dist/extensions/editor/editor.d.cts +170 -0
- package/dist/extensions/editor/editor.d.ts +43 -22
- package/dist/extensions/editor/editor.d.ts.map +1 -1
- package/dist/extensions/editor/field_handle.d.cts +40 -0
- package/dist/extensions/editor/field_handle.d.ts +8 -3
- package/dist/extensions/editor/field_handle.d.ts.map +1 -1
- package/dist/extensions/editor/index.cjs +1 -1
- package/dist/extensions/editor/index.d.cts +21 -0
- package/dist/extensions/editor/index.d.ts +2 -2
- package/dist/extensions/editor/index.js +116 -88
- package/dist/extensions/reactive/ecs_sync.d.cts +214 -0
- package/dist/extensions/reactive/ecs_sync.d.ts +26 -22
- package/dist/extensions/reactive/ecs_sync.d.ts.map +1 -1
- package/dist/extensions/reactive/index.cjs +1 -1
- package/dist/extensions/reactive/index.d.cts +23 -0
- package/dist/extensions/reactive/index.d.ts +1 -1
- package/dist/extensions/reactive/index.js +106 -116
- package/dist/extensions/solid/index.cjs +1 -1
- package/dist/extensions/solid/index.d.cts +6 -0
- package/dist/extensions/solid/index.d.ts +2 -2
- package/dist/extensions/solid/index.js +8 -4
- package/dist/extensions/solid/kernel_solid.d.cts +45 -0
- package/dist/extensions/solid/kernel_solid.d.ts +6 -3
- package/dist/extensions/solid/kernel_solid.d.ts.map +1 -1
- package/dist/host_commands-BF8QMi3c.cjs +1 -0
- package/dist/host_commands-i4cAeyL5.js +2318 -0
- package/dist/index.cjs +1 -2
- package/dist/index.d.cts +66 -0
- package/dist/index.d.ts +50 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4469 -5933
- package/dist/internal.cjs +2 -0
- package/dist/internal.d.cts +20 -0
- package/dist/internal.d.ts +20 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +141 -0
- package/dist/primitives.cjs +1 -1
- package/dist/primitives.d.cts +18 -0
- package/dist/primitives.d.ts +6 -6
- package/dist/primitives.js +24 -23
- package/dist/reactive/array.d.ts +24 -0
- package/dist/reactive/array.d.ts.map +1 -0
- package/dist/reactive/index.cjs +1 -0
- package/dist/reactive/index.d.cts +11 -0
- package/dist/reactive/index.d.ts +11 -0
- package/dist/reactive/index.d.ts.map +1 -0
- package/dist/reactive/index.js +18 -0
- package/dist/reactive/interop.d.cts +19 -0
- package/dist/{core/reactive → reactive}/interop.d.ts +1 -1
- package/dist/reactive/interop.d.ts.map +1 -0
- package/dist/reactive/kernel.d.cts +73 -0
- package/dist/{core/reactive → reactive}/kernel.d.ts +5 -3
- package/dist/reactive/kernel.d.ts.map +1 -0
- package/dist/reactive/map.d.ts +16 -0
- package/dist/reactive/map.d.ts.map +1 -0
- package/dist/reactive/shallow.d.cts +11 -0
- package/dist/reactive/shallow.d.ts +11 -0
- package/dist/reactive/shallow.d.ts.map +1 -0
- package/dist/reactive/struct.d.cts +10 -0
- package/dist/{core/reactive → reactive}/struct.d.ts +1 -1
- package/dist/reactive/struct.d.ts.map +1 -0
- package/dist/shallow-DQ8aG51_.cjs +1 -0
- package/dist/shallow-DfnAm9vG.js +150 -0
- package/dist/shared-BU1Cd40h.js +103 -0
- package/dist/shared-BymrGTyR.cjs +1 -0
- package/dist/shared.cjs +1 -1
- package/dist/shared.d.cts +22 -0
- package/dist/shared.d.ts +2 -2
- package/dist/shared.js +1 -1
- package/dist/topological_sort-BDvEyb9W.cjs +1 -0
- package/dist/topological_sort-DK6EjpWa.js +135 -0
- package/dist/type_primitives/assertions.d.cts +32 -0
- package/dist/type_primitives/assertions.d.ts +13 -1
- package/dist/type_primitives/assertions.d.ts.map +1 -1
- package/dist/type_primitives/binary_heap/binary_heap.d.cts +37 -0
- package/dist/type_primitives/bitset/bitset.d.cts +54 -0
- package/dist/type_primitives/brand.d.cts +23 -0
- package/dist/type_primitives/error.d.cts +16 -0
- package/dist/type_primitives/error.d.ts +4 -3
- package/dist/type_primitives/error.d.ts.map +1 -1
- package/dist/type_primitives/index.d.cts +13 -0
- package/dist/type_primitives/index.d.ts +9 -9
- package/dist/type_primitives/sparse_map/sparse_map.d.cts +30 -0
- package/dist/type_primitives/sparse_set/sparse_set.d.cts +28 -0
- package/dist/type_primitives/topological_sort/topological_sort.d.cts +29 -0
- package/dist/type_primitives/typed_arrays/typed_arrays.d.cts +127 -0
- package/dist/typed_arrays-BcXcnzB4.js +258 -0
- package/dist/typed_arrays-D3NmwtCG.cjs +1 -0
- package/dist/utils/error.d.cts +6 -0
- package/dist/version.d.cts +10 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +102 -19
- package/dist/array-CxbPyiHO.cjs +0 -1
- package/dist/array-uFR7Q8fU.js +0 -132
- package/dist/core/reactive/array.d.ts.map +0 -1
- package/dist/core/reactive/index.cjs +0 -1
- package/dist/core/reactive/index.d.ts +0 -10
- package/dist/core/reactive/index.d.ts.map +0 -1
- package/dist/core/reactive/index.js +0 -17
- package/dist/core/reactive/interop.d.ts.map +0 -1
- package/dist/core/reactive/kernel.d.ts.map +0 -1
- package/dist/core/reactive/map.d.ts.map +0 -1
- package/dist/core/reactive/struct.d.ts.map +0 -1
- package/dist/log/console_sink.d.ts +0 -4
- package/dist/log/console_sink.d.ts.map +0 -1
- package/dist/log/index.d.ts +0 -3
- package/dist/log/index.d.ts.map +0 -1
- package/dist/log/logger.d.ts +0 -27
- package/dist/log/logger.d.ts.map +0 -1
- package/dist/shared-BXSZnxx4.cjs +0 -1
- package/dist/shared-C678TAPY.js +0 -99
- package/dist/topological_sort-DlRpSrxu.js +0 -391
- package/dist/topological_sort-WAT-VHb-.cjs +0 -1
- package/dist/utils/arrays.d.ts.map +0 -1
- package/dist/utils/constants.d.ts.map +0 -1
- /package/dist/{utils/constants.d.ts → core/ecs/utils/constants.d.cts} +0 -0
- /package/dist/core/store/{__generated__/abi.d.ts → vendored_abi/abi.d.cts} +0 -0
- /package/dist/{core/reactive/array.d.ts → reactive/array.d.cts} +0 -0
- /package/dist/{core/reactive/map.d.ts → reactive/map.d.cts} +0 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { ComponentDef, ComponentHandle, ComponentSchema, EntityID, CompleteFieldValues, HostCommand, HostCommandQueue, SpawnEntries } from '../../core/ecs/index.cjs';
|
|
2
|
+
/**
|
|
3
|
+
* Reads the committed value of one `(entity, component, field)` slot — the editor
|
|
4
|
+
* uses it to seed a `setField` inverse with the value the edit replaced. Wire it
|
|
5
|
+
* to the reactive read channel (e.g. a `reactiveMap`/`reactiveStruct` projection)
|
|
6
|
+
* or to `ecs.getField`; `undefined` for an unknown slot falls back to `0`.
|
|
7
|
+
*/
|
|
8
|
+
export type FieldReader = (eid: EntityID, def: ComponentDef, field: string) => number | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* A reified, undoable unit of editor work: the `forward` commands and their
|
|
11
|
+
* `inverse`, both plain `HostCommand` data on the one bus. The arrays are mutable
|
|
12
|
+
* internally (the spawn/despawn id finalizers patch a slot at apply time) but the
|
|
13
|
+
* type handed back from {@link Editor.transaction} is read-only.
|
|
14
|
+
*/
|
|
15
|
+
export interface EditorTransaction {
|
|
16
|
+
readonly forward: readonly HostCommand[];
|
|
17
|
+
readonly inverse: readonly HostCommand[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Accumulates the `forward`/`inverse` commands for ONE transaction. Each method
|
|
21
|
+
* appends a forward command and its inverse, computing the inverse from the
|
|
22
|
+
* shadow / read channel where needed. Spawn and despawn install id-finalizers
|
|
23
|
+
* (via `HostCommand.onSpawned`) that patch the apply-time id into the right slot.
|
|
24
|
+
*
|
|
25
|
+
* Obtained from {@link Editor.transaction}; not constructed directly.
|
|
26
|
+
*/
|
|
27
|
+
export declare class TransactionBuilder {
|
|
28
|
+
private readonly readField;
|
|
29
|
+
private readonly shadow;
|
|
30
|
+
/** Values staged by THIS build, layered over the editor's shared shadow. Kept
|
|
31
|
+
* transaction-local so an aborted build (the callback throws before commit)
|
|
32
|
+
* leaves the shared shadow untouched — a phantom staged value would poison
|
|
33
|
+
* `pendingField` and seed the NEXT edit's inverse with a value the world never
|
|
34
|
+
* held. The one merge point into the shared shadow is commit's `applyShadow`. */
|
|
35
|
+
private readonly staged;
|
|
36
|
+
/** @internal */
|
|
37
|
+
constructor(readField: FieldReader, shadow: Map<string, number>);
|
|
38
|
+
private get _txn();
|
|
39
|
+
/**
|
|
40
|
+
* Spawn an entity carrying `components`. Inverse: despawn the created entity,
|
|
41
|
+
* finalized once the spawn applies (the id only exists post-flush). `onSpawned`
|
|
42
|
+
* also forwards the new id to the caller. The finalizer re-fires on redo, so the
|
|
43
|
+
* inverse tracks the current id.
|
|
44
|
+
*/
|
|
45
|
+
spawn<Defs extends readonly ComponentDef[]>(components: SpawnEntries<Defs>, onSpawned?: (eid: EntityID) => void): this;
|
|
46
|
+
/**
|
|
47
|
+
* Despawn `eid`. Inverse: respawn from `restore` (the components+values to
|
|
48
|
+
* recreate — read them from the channel before despawning). Undo respawns the
|
|
49
|
+
* DATA, not the identity: the new entity gets a fresh id, and the respawn's
|
|
50
|
+
* `onSpawned` rewrites this despawn's target so redo removes the respawned
|
|
51
|
+
* entity rather than the dead original.
|
|
52
|
+
*/
|
|
53
|
+
despawn<Defs extends readonly ComponentDef[]>(eid: EntityID, restore: SpawnEntries<Defs>): this;
|
|
54
|
+
/**
|
|
55
|
+
* Set `field` of `def` on `eid` to `value`. Inverse: set it back to the value
|
|
56
|
+
* this edit replaced — read from the staged overlay / shadow (so stacked edits,
|
|
57
|
+
* within one build or before a commit, invert correctly) or, failing that, the
|
|
58
|
+
* read channel (`0` if unknown).
|
|
59
|
+
*/
|
|
60
|
+
setField<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, field: string & keyof S, value: number): this;
|
|
61
|
+
/** Add `def` (with complete `values`) to `eid`. Inverse: remove it. */
|
|
62
|
+
addComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, values: CompleteFieldValues<S>): this;
|
|
63
|
+
/**
|
|
64
|
+
* Remove `def` from `eid`. Inverse: re-add it from `restore` (the field values
|
|
65
|
+
* to recreate — read them from the channel before removing).
|
|
66
|
+
*/
|
|
67
|
+
removeComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, restore: CompleteFieldValues<S>): this;
|
|
68
|
+
/** Disable `eid`. Inverse: enable it. */
|
|
69
|
+
disable(eid: EntityID): this;
|
|
70
|
+
/** Enable `eid`. Inverse: disable it. */
|
|
71
|
+
enable(eid: EntityID): this;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The editor's undo/redo manager over a {@link HostCommandQueue}. Each action is a
|
|
75
|
+
* reified {@link EditorTransaction} pushed onto the undo stack; `undo()`/`redo()`
|
|
76
|
+
* enqueue its inverse/forward on the SAME bus. The single-action methods
|
|
77
|
+
* (`spawn`, `setField`, …) are sugar for one-command transactions; `transaction`
|
|
78
|
+
* groups several into one undo entry.
|
|
79
|
+
*
|
|
80
|
+
* Construct with the queue and a {@link FieldReader} for the committed read
|
|
81
|
+
* channel (used to seed `setField` inverses).
|
|
82
|
+
*/
|
|
83
|
+
export declare class Editor {
|
|
84
|
+
private readonly queue;
|
|
85
|
+
private readonly readField;
|
|
86
|
+
private readonly undoStack;
|
|
87
|
+
private readonly redoStack;
|
|
88
|
+
/** onChange subscribers — see {@link onChange}. */
|
|
89
|
+
private readonly listeners;
|
|
90
|
+
/** Per-`(entity, component, field)` shadow of edited values, for inverse correctness. */
|
|
91
|
+
private readonly shadow;
|
|
92
|
+
constructor(queue: HostCommandQueue, readField: FieldReader);
|
|
93
|
+
/**
|
|
94
|
+
* Group several actions into ONE undo entry. Build them on the passed
|
|
95
|
+
* {@link TransactionBuilder}; the whole group commits (enqueues its forward
|
|
96
|
+
* commands) and lands on the undo stack atomically, clearing the redo stack.
|
|
97
|
+
*/
|
|
98
|
+
transaction(build: (tx: TransactionBuilder) => void): EditorTransaction;
|
|
99
|
+
/** Spawn `components` as its own undo entry. `onSpawned` reports the new id. */
|
|
100
|
+
spawn<Defs extends readonly ComponentDef[]>(components: SpawnEntries<Defs>, onSpawned?: (eid: EntityID) => void): EditorTransaction;
|
|
101
|
+
/** Despawn `eid` as its own undo entry; `restore` recreates it on undo. */
|
|
102
|
+
despawn<Defs extends readonly ComponentDef[]>(eid: EntityID, restore: SpawnEntries<Defs>): EditorTransaction;
|
|
103
|
+
/** Set one field as its own undo entry. */
|
|
104
|
+
setField<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, field: string & keyof S, value: number): EditorTransaction;
|
|
105
|
+
/** Add a component as its own undo entry. */
|
|
106
|
+
addComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, values: CompleteFieldValues<S>): EditorTransaction;
|
|
107
|
+
/** Remove a component as its own undo entry; `restore` re-adds it on undo. */
|
|
108
|
+
removeComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, restore: CompleteFieldValues<S>): EditorTransaction;
|
|
109
|
+
/** Disable `eid` as its own undo entry. */
|
|
110
|
+
disable(eid: EntityID): EditorTransaction;
|
|
111
|
+
/** Enable `eid` as its own undo entry. */
|
|
112
|
+
enable(eid: EntityID): EditorTransaction;
|
|
113
|
+
/**
|
|
114
|
+
* Undo the most recent transaction: enqueue its inverse commands (in reverse
|
|
115
|
+
* order — a group unwinds last-action-first) on the bus and move it to the redo
|
|
116
|
+
* stack. Returns `false` if the undo stack is empty.
|
|
117
|
+
*/
|
|
118
|
+
undo(): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Redo the most recently undone transaction: re-enqueue its forward commands on
|
|
121
|
+
* the bus and move it back to the undo stack. Returns `false` if the redo stack
|
|
122
|
+
* is empty.
|
|
123
|
+
*/
|
|
124
|
+
redo(): boolean;
|
|
125
|
+
/** Drop both stacks (e.g. on load). Does not touch the world. */
|
|
126
|
+
clear(): void;
|
|
127
|
+
/** Current stack depths — for an "Undo (3)" / "Redo" affordance. */
|
|
128
|
+
depths(): {
|
|
129
|
+
undo: number;
|
|
130
|
+
redo: number;
|
|
131
|
+
};
|
|
132
|
+
/** `true` when `undo()` would do something — allocation-free (M10). */
|
|
133
|
+
get canUndo(): boolean;
|
|
134
|
+
/** `true` when `redo()` would do something — allocation-free (M10). */
|
|
135
|
+
get canRedo(): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Subscribe to undo/redo-stack changes: fires after every commit, undo,
|
|
138
|
+
* redo, and clear — the push signal an "Undo (3)" affordance needs instead
|
|
139
|
+
* of polling `depths()` per frame (M10). Returns an unsubscribe function.
|
|
140
|
+
* Callbacks run synchronously in subscription order; read `canUndo` /
|
|
141
|
+
* `canRedo` / `depths()` inside.
|
|
142
|
+
*/
|
|
143
|
+
onChange(cb: () => void): () => void;
|
|
144
|
+
private notify;
|
|
145
|
+
/** Read one committed `(entity, component, field)` slot through the reader
|
|
146
|
+
* this editor was constructed with — the default read for `fieldHandle`
|
|
147
|
+
* when no channel thunk is supplied (M11). */
|
|
148
|
+
committedField(eid: EntityID, def: ComponentDef, field: string): number | undefined;
|
|
149
|
+
/**
|
|
150
|
+
* The pending value the editor believes for a field that the committed read
|
|
151
|
+
* channel has NOT caught up to yet (the shadow), or `undefined` if none. Lets an
|
|
152
|
+
* inspector echo an edit between the `set` and the tick that commits it.
|
|
153
|
+
*
|
|
154
|
+
* Self-resolving: once the read channel reports the shadowed value (the edit
|
|
155
|
+
* landed) — or reports `undefined` (the slot is gone: entity despawned or
|
|
156
|
+
* component removed) — the entry is dropped and this returns `undefined`, so
|
|
157
|
+
* `pending` does not outlive its set→commit window and shadow a later external
|
|
158
|
+
* write, nor a dead slot's lifetime. The one
|
|
159
|
+
* residual: if an external write changes the field to a *different* value within
|
|
160
|
+
* the same window before this is next consulted, `pending` can read stale until
|
|
161
|
+
* the next edit to the slot. `value` (the read channel) is always the source of
|
|
162
|
+
* truth; `pending` is only the optimistic bridge.
|
|
163
|
+
*/
|
|
164
|
+
pendingField(eid: EntityID, def: ComponentHandle, field: string): number | undefined;
|
|
165
|
+
/** Enqueue forward commands, record the transaction, clear redo, sync shadow. */
|
|
166
|
+
private commit;
|
|
167
|
+
/** Keep the setField shadow in step with the commands just enqueued. */
|
|
168
|
+
private applyShadow;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=editor.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ComponentDef, ComponentHandle, ComponentSchema, EntityID,
|
|
1
|
+
import { ComponentDef, ComponentHandle, ComponentSchema, EntityID, CompleteFieldValues, HostCommand, HostCommandQueue, SpawnEntries } from '../../core/ecs/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Reads the committed value of one `(entity, component, field)` slot — the editor
|
|
4
4
|
* uses it to seed a `setField` inverse with the value the edit replaced. Wire it
|
|
5
5
|
* to the reactive read channel (e.g. a `reactiveMap`/`reactiveStruct` projection)
|
|
6
|
-
* or to `
|
|
6
|
+
* or to `ecs.getField`; `undefined` for an unknown slot falls back to `0`.
|
|
7
7
|
*/
|
|
8
8
|
export type FieldReader = (eid: EntityID, def: ComponentDef, field: string) => number | undefined;
|
|
9
9
|
/**
|
|
@@ -16,11 +16,6 @@ export interface EditorTransaction {
|
|
|
16
16
|
readonly forward: readonly HostCommand[];
|
|
17
17
|
readonly inverse: readonly HostCommand[];
|
|
18
18
|
}
|
|
19
|
-
/** Internal, mutable transaction the id-finalizers patch in place. */
|
|
20
|
-
interface MutableTxn {
|
|
21
|
-
forward: HostCommand[];
|
|
22
|
-
inverse: HostCommand[];
|
|
23
|
-
}
|
|
24
19
|
/**
|
|
25
20
|
* Accumulates the `forward`/`inverse` commands for ONE transaction. Each method
|
|
26
21
|
* appends a forward command and its inverse, computing the inverse from the
|
|
@@ -32,17 +27,22 @@ interface MutableTxn {
|
|
|
32
27
|
export declare class TransactionBuilder {
|
|
33
28
|
private readonly readField;
|
|
34
29
|
private readonly shadow;
|
|
35
|
-
/**
|
|
36
|
-
|
|
30
|
+
/** Values staged by THIS build, layered over the editor's shared shadow. Kept
|
|
31
|
+
* transaction-local so an aborted build (the callback throws before commit)
|
|
32
|
+
* leaves the shared shadow untouched — a phantom staged value would poison
|
|
33
|
+
* `pendingField` and seed the NEXT edit's inverse with a value the world never
|
|
34
|
+
* held. The one merge point into the shared shadow is commit's `applyShadow`. */
|
|
35
|
+
private readonly staged;
|
|
37
36
|
/** @internal */
|
|
38
37
|
constructor(readField: FieldReader, shadow: Map<string, number>);
|
|
38
|
+
private get _txn();
|
|
39
39
|
/**
|
|
40
40
|
* Spawn an entity carrying `components`. Inverse: despawn the created entity,
|
|
41
41
|
* finalized once the spawn applies (the id only exists post-flush). `onSpawned`
|
|
42
42
|
* also forwards the new id to the caller. The finalizer re-fires on redo, so the
|
|
43
43
|
* inverse tracks the current id.
|
|
44
44
|
*/
|
|
45
|
-
spawn
|
|
45
|
+
spawn<Defs extends readonly ComponentDef[]>(components: SpawnEntries<Defs>, onSpawned?: (eid: EntityID) => void): this;
|
|
46
46
|
/**
|
|
47
47
|
* Despawn `eid`. Inverse: respawn from `restore` (the components+values to
|
|
48
48
|
* recreate — read them from the channel before despawning). Undo respawns the
|
|
@@ -50,20 +50,21 @@ export declare class TransactionBuilder {
|
|
|
50
50
|
* `onSpawned` rewrites this despawn's target so redo removes the respawned
|
|
51
51
|
* entity rather than the dead original.
|
|
52
52
|
*/
|
|
53
|
-
despawn(eid: EntityID, restore:
|
|
53
|
+
despawn<Defs extends readonly ComponentDef[]>(eid: EntityID, restore: SpawnEntries<Defs>): this;
|
|
54
54
|
/**
|
|
55
55
|
* Set `field` of `def` on `eid` to `value`. Inverse: set it back to the value
|
|
56
|
-
* this edit replaced — read from the shadow (so stacked edits
|
|
57
|
-
* invert correctly) or, failing that, the
|
|
56
|
+
* this edit replaced — read from the staged overlay / shadow (so stacked edits,
|
|
57
|
+
* within one build or before a commit, invert correctly) or, failing that, the
|
|
58
|
+
* read channel (`0` if unknown).
|
|
58
59
|
*/
|
|
59
60
|
setField<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, field: string & keyof S, value: number): this;
|
|
60
61
|
/** Add `def` (with complete `values`) to `eid`. Inverse: remove it. */
|
|
61
|
-
addComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, values:
|
|
62
|
+
addComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, values: CompleteFieldValues<S>): this;
|
|
62
63
|
/**
|
|
63
64
|
* Remove `def` from `eid`. Inverse: re-add it from `restore` (the field values
|
|
64
65
|
* to recreate — read them from the channel before removing).
|
|
65
66
|
*/
|
|
66
|
-
removeComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, restore:
|
|
67
|
+
removeComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, restore: CompleteFieldValues<S>): this;
|
|
67
68
|
/** Disable `eid`. Inverse: enable it. */
|
|
68
69
|
disable(eid: EntityID): this;
|
|
69
70
|
/** Enable `eid`. Inverse: disable it. */
|
|
@@ -84,6 +85,8 @@ export declare class Editor {
|
|
|
84
85
|
private readonly readField;
|
|
85
86
|
private readonly undoStack;
|
|
86
87
|
private readonly redoStack;
|
|
88
|
+
/** onChange subscribers — see {@link onChange}. */
|
|
89
|
+
private readonly listeners;
|
|
87
90
|
/** Per-`(entity, component, field)` shadow of edited values, for inverse correctness. */
|
|
88
91
|
private readonly shadow;
|
|
89
92
|
constructor(queue: HostCommandQueue, readField: FieldReader);
|
|
@@ -94,15 +97,15 @@ export declare class Editor {
|
|
|
94
97
|
*/
|
|
95
98
|
transaction(build: (tx: TransactionBuilder) => void): EditorTransaction;
|
|
96
99
|
/** Spawn `components` as its own undo entry. `onSpawned` reports the new id. */
|
|
97
|
-
spawn
|
|
100
|
+
spawn<Defs extends readonly ComponentDef[]>(components: SpawnEntries<Defs>, onSpawned?: (eid: EntityID) => void): EditorTransaction;
|
|
98
101
|
/** Despawn `eid` as its own undo entry; `restore` recreates it on undo. */
|
|
99
|
-
despawn(eid: EntityID, restore:
|
|
102
|
+
despawn<Defs extends readonly ComponentDef[]>(eid: EntityID, restore: SpawnEntries<Defs>): EditorTransaction;
|
|
100
103
|
/** Set one field as its own undo entry. */
|
|
101
104
|
setField<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, field: string & keyof S, value: number): EditorTransaction;
|
|
102
105
|
/** Add a component as its own undo entry. */
|
|
103
|
-
addComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, values:
|
|
106
|
+
addComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, values: CompleteFieldValues<S>): EditorTransaction;
|
|
104
107
|
/** Remove a component as its own undo entry; `restore` re-adds it on undo. */
|
|
105
|
-
removeComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, restore:
|
|
108
|
+
removeComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, restore: CompleteFieldValues<S>): EditorTransaction;
|
|
106
109
|
/** Disable `eid` as its own undo entry. */
|
|
107
110
|
disable(eid: EntityID): EditorTransaction;
|
|
108
111
|
/** Enable `eid` as its own undo entry. */
|
|
@@ -126,14 +129,33 @@ export declare class Editor {
|
|
|
126
129
|
undo: number;
|
|
127
130
|
redo: number;
|
|
128
131
|
};
|
|
132
|
+
/** `true` when `undo()` would do something — allocation-free (M10). */
|
|
133
|
+
get canUndo(): boolean;
|
|
134
|
+
/** `true` when `redo()` would do something — allocation-free (M10). */
|
|
135
|
+
get canRedo(): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Subscribe to undo/redo-stack changes: fires after every commit, undo,
|
|
138
|
+
* redo, and clear — the push signal an "Undo (3)" affordance needs instead
|
|
139
|
+
* of polling `depths()` per frame (M10). Returns an unsubscribe function.
|
|
140
|
+
* Callbacks run synchronously in subscription order; read `canUndo` /
|
|
141
|
+
* `canRedo` / `depths()` inside.
|
|
142
|
+
*/
|
|
143
|
+
onChange(cb: () => void): () => void;
|
|
144
|
+
private notify;
|
|
145
|
+
/** Read one committed `(entity, component, field)` slot through the reader
|
|
146
|
+
* this editor was constructed with — the default read for `fieldHandle`
|
|
147
|
+
* when no channel thunk is supplied (M11). */
|
|
148
|
+
committedField(eid: EntityID, def: ComponentDef, field: string): number | undefined;
|
|
129
149
|
/**
|
|
130
150
|
* The pending value the editor believes for a field that the committed read
|
|
131
151
|
* channel has NOT caught up to yet (the shadow), or `undefined` if none. Lets an
|
|
132
152
|
* inspector echo an edit between the `set` and the tick that commits it.
|
|
133
153
|
*
|
|
134
154
|
* Self-resolving: once the read channel reports the shadowed value (the edit
|
|
135
|
-
* landed)
|
|
136
|
-
*
|
|
155
|
+
* landed) — or reports `undefined` (the slot is gone: entity despawned or
|
|
156
|
+
* component removed) — the entry is dropped and this returns `undefined`, so
|
|
157
|
+
* `pending` does not outlive its set→commit window and shadow a later external
|
|
158
|
+
* write, nor a dead slot's lifetime. The one
|
|
137
159
|
* residual: if an external write changes the field to a *different* value within
|
|
138
160
|
* the same window before this is next consulted, `pending` can read stale until
|
|
139
161
|
* the next edit to the slot. `value` (the read channel) is always the source of
|
|
@@ -145,5 +167,4 @@ export declare class Editor {
|
|
|
145
167
|
/** Keep the setField shadow in step with the commands just enqueued. */
|
|
146
168
|
private applyShadow;
|
|
147
169
|
}
|
|
148
|
-
export {};
|
|
149
170
|
//# sourceMappingURL=editor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../../src/extensions/editor/editor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,KAAK,EACX,YAAY,EACZ,eAAe,EACf,eAAe,EACf,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../../src/extensions/editor/editor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,KAAK,EACX,YAAY,EACZ,eAAe,EACf,eAAe,EACf,QAAQ,EACR,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAEhB,YAAY,EACZ,MAAM,gBAAgB,CAAC;AAExB;;;;;GAKG;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AG,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAkBpF,iFAAiF;IACjF,OAAO,CAAC,MAAM;IAad,wEAAwE;IACxE,OAAO,CAAC,WAAW;CAOnB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ComponentDef, ComponentSchema, EntityID } from '../../core/ecs/index.cjs';
|
|
2
|
+
import { Editor } from './editor.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* A two-way handle on one `(entity, component, field)` slot. `value` reads the
|
|
5
|
+
* reactive channel (tracked, if read in a tracking scope); `set` enqueues an
|
|
6
|
+
* undoable `setField` command via the editor.
|
|
7
|
+
*/
|
|
8
|
+
export interface FieldHandle {
|
|
9
|
+
/**
|
|
10
|
+
* The field's current value through the reactive read channel — `undefined`
|
|
11
|
+
* until the channel has it (e.g. before the spawn's first commit). Read inside
|
|
12
|
+
* a tracking scope to subscribe to the channel; the value reflects the last
|
|
13
|
+
* COMMITTED tick, so a fresh `set` shows up on the next tick.
|
|
14
|
+
*/
|
|
15
|
+
readonly value: number | undefined;
|
|
16
|
+
/** Enqueue an undoable `setField` for this slot; applied at the next tick. */
|
|
17
|
+
set(value: number): void;
|
|
18
|
+
/**
|
|
19
|
+
* The editor's pending (not-yet-committed) value for this slot, or `undefined`
|
|
20
|
+
* if none — a NON-reactive read of the editor shadow, for an optimistic echo
|
|
21
|
+
* between the `set` and its commit. Self-resolves to `undefined` once the read
|
|
22
|
+
* channel catches up, so it does not outlive the edit. Not a substitute for
|
|
23
|
+
* `value` in a tracking scope (it does not subscribe); `value` is the source of
|
|
24
|
+
* truth.
|
|
25
|
+
*/
|
|
26
|
+
readonly pending: number | undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Build a {@link FieldHandle} for one `(eid, def, field)` slot. `read` is the
|
|
30
|
+
* tracked read of the reactive channel for this field (e.g.
|
|
31
|
+
* `() => sync.map.get(eid)?.x`); `set` routes through `editor.setField`, so the
|
|
32
|
+
* edit is queued, batched, and undoable.
|
|
33
|
+
*
|
|
34
|
+
* `read` is optional (M11): omitted, the handle reads through the editor's own
|
|
35
|
+
* committed-channel reader (`editor.committedField`). That default is correct
|
|
36
|
+
* but NOT reactive — supply the channel thunk when the handle's `value` must
|
|
37
|
+
* subscribe inside a tracking scope.
|
|
38
|
+
*/
|
|
39
|
+
export declare function fieldHandle<S extends ComponentSchema>(editor: Editor, eid: EntityID, def: ComponentDef<S>, field: string & keyof S, read?: () => number | undefined): FieldHandle;
|
|
40
|
+
//# sourceMappingURL=field_handle.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ComponentDef, ComponentSchema, EntityID } from '../../core/ecs';
|
|
2
|
-
import { Editor } from './editor';
|
|
1
|
+
import { ComponentDef, ComponentSchema, EntityID } from '../../core/ecs/index.js';
|
|
2
|
+
import { Editor } from './editor.js';
|
|
3
3
|
/**
|
|
4
4
|
* A two-way handle on one `(entity, component, field)` slot. `value` reads the
|
|
5
5
|
* reactive channel (tracked, if read in a tracking scope); `set` enqueues an
|
|
@@ -30,6 +30,11 @@ export interface FieldHandle {
|
|
|
30
30
|
* tracked read of the reactive channel for this field (e.g.
|
|
31
31
|
* `() => sync.map.get(eid)?.x`); `set` routes through `editor.setField`, so the
|
|
32
32
|
* edit is queued, batched, and undoable.
|
|
33
|
+
*
|
|
34
|
+
* `read` is optional (M11): omitted, the handle reads through the editor's own
|
|
35
|
+
* committed-channel reader (`editor.committedField`). That default is correct
|
|
36
|
+
* but NOT reactive — supply the channel thunk when the handle's `value` must
|
|
37
|
+
* subscribe inside a tracking scope.
|
|
33
38
|
*/
|
|
34
|
-
export declare function fieldHandle<S extends ComponentSchema>(editor: Editor, eid: EntityID, def: ComponentDef<S>, field: string & keyof S, read
|
|
39
|
+
export declare function fieldHandle<S extends ComponentSchema>(editor: Editor, eid: EntityID, def: ComponentDef<S>, field: string & keyof S, read?: () => number | undefined): FieldHandle;
|
|
35
40
|
//# sourceMappingURL=field_handle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field_handle.d.ts","sourceRoot":"","sources":["../../../src/extensions/editor/field_handle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,8EAA8E;IAC9E,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED
|
|
1
|
+
{"version":3,"file":"field_handle.d.ts","sourceRoot":"","sources":["../../../src/extensions/editor/field_handle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,8EAA8E;IAC9E,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,eAAe,EACpD,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,EACpB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,EACvB,IAAI,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,GAC7B,WAAW,CAYb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function d(r,t,e){return`${r}:${t.id}:${e}`}const a=new WeakMap;class h{constructor(t,e){this.readField=t,this.shadow=e,a.set(this,{forward:[],inverse:[]})}staged=new Map;get _txn(){return a.get(this)}spawn(t,e){const n={kind:"despawn",eid:0};return this._txn.inverse.push(n),this._txn.forward.push({kind:"spawn",components:t,onSpawned:s=>{n.eid=s,e?.(s)}}),this}despawn(t,e){const n={kind:"despawn",eid:t};return this._txn.forward.push(n),this._txn.inverse.push({kind:"spawn",components:e,onSpawned:s=>{n.eid=s}}),this}setField(t,e,n,s){const i=d(t,e,n),o=this.staged.get(i)??this.shadow.get(i)??this.readField(t,e,n)??0;return this.staged.set(i,s),this._txn.forward.push({kind:"set_field",eid:t,def:e,field:n,value:s}),this._txn.inverse.push({kind:"set_field",eid:t,def:e,field:n,value:o}),this}addComponent(t,e,n){return this._txn.forward.push({kind:"add_component",eid:t,def:e,values:n}),this._txn.inverse.push({kind:"remove_component",eid:t,def:e}),this}removeComponent(t,e,n){return this._txn.forward.push({kind:"remove_component",eid:t,def:e}),this._txn.inverse.push({kind:"add_component",eid:t,def:e,values:n}),this}disable(t){return this._txn.forward.push({kind:"disable",eid:t}),this._txn.inverse.push({kind:"enable",eid:t}),this}enable(t){return this._txn.forward.push({kind:"enable",eid:t}),this._txn.inverse.push({kind:"disable",eid:t}),this}}class u{constructor(t,e){this.queue=t,this.readField=e}undoStack=[];redoStack=[];listeners=[];shadow=new Map;transaction(t){const e=new h(this.readField,this.shadow);return t(e),this.commit(a.get(e))}spawn(t,e){return this.transaction(n=>n.spawn(t,e))}despawn(t,e){return this.transaction(n=>n.despawn(t,e))}setField(t,e,n,s){return this.transaction(i=>i.setField(t,e,n,s))}addComponent(t,e,n){return this.transaction(s=>s.addComponent(t,e,n))}removeComponent(t,e,n){return this.transaction(s=>s.removeComponent(t,e,n))}disable(t){return this.transaction(e=>e.disable(t))}enable(t){return this.transaction(e=>e.enable(t))}undo(){const t=this.undoStack.pop();if(t===void 0)return!1;const e=t.inverse.slice().reverse();for(const n of e)this.queue.push(n);return this.applyShadow(e),this.redoStack.push(t),this.notify(),!0}redo(){const t=this.redoStack.pop();if(t===void 0)return!1;for(const e of t.forward)this.queue.push(e);return this.applyShadow(t.forward),this.undoStack.push(t),this.notify(),!0}clear(){this.undoStack.length=0,this.redoStack.length=0,this.shadow.clear(),this.notify()}depths(){return{undo:this.undoStack.length,redo:this.redoStack.length}}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}onChange(t){return this.listeners.push(t),()=>{const e=this.listeners.indexOf(t);e!==-1&&this.listeners.splice(e,1)}}notify(){for(const t of this.listeners.slice())t()}committedField(t,e,n){return this.readField(t,e,n)}pendingField(t,e,n){const s=d(t,e,n),i=this.shadow.get(s);if(i===void 0)return;const o=this.readField(t,e,n);if(o===i||o===void 0){this.shadow.delete(s);return}return i}commit(t){if(t.forward.length===0)return t;for(const e of t.forward)this.queue.push(e);return this.applyShadow(t.forward),this.undoStack.push(t),this.redoStack.length=0,this.notify(),t}applyShadow(t){for(const e of t)e.kind==="set_field"&&this.shadow.set(d(e.eid,e.def,e.field),e.value)}}function c(r,t,e,n,s){return{get value(){return s!==void 0?s():r.committedField(t,e,n)},set(i){r.setField(t,e,n,i)},get pending(){return r.pendingField(t,e,n)}}}exports.Editor=u;exports.TransactionBuilder=h;exports.fieldHandle=c;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host write seam's EDITOR layer (#701) — layer 2 of #681 / PATTERNS §85.
|
|
3
|
+
*
|
|
4
|
+
* Reified undo/redo + the inspector field-handle, built on the shipped typed
|
|
5
|
+
* `HostCommandQueue` (#698). Application policy, so it lives here in
|
|
6
|
+
* `engine-extensions`, not engine core — and it pulls NO third-party / framework
|
|
7
|
+
* dependency (the field-handle reads through a caller-supplied thunk).
|
|
8
|
+
*
|
|
9
|
+
* - `Editor` — reified `EditorTransaction`s on undo/redo stacks, with
|
|
10
|
+
* transaction grouping; `undo()`/`redo()` enqueue the inverse/forward on the
|
|
11
|
+
* SAME bus, applied at the next schedule head (undo is just another command).
|
|
12
|
+
* - `fieldHandle` — pairs a reactive-channel read with a `setField` command, so
|
|
13
|
+
* an inspector field feels two-way while staying safe and undoable.
|
|
14
|
+
*
|
|
15
|
+
* Reachable as `@oasys/oecs/editor`. Pair it with
|
|
16
|
+
* `@oasys/oecs/reactive-sync`'s `syncFieldsToMap` /
|
|
17
|
+
* `syncSingletonToStruct` for the read channel the field-handle reads through.
|
|
18
|
+
*/
|
|
19
|
+
export { Editor, TransactionBuilder, type EditorTransaction, type FieldReader } from './editor.cjs';
|
|
20
|
+
export { fieldHandle, type FieldHandle } from './field_handle.cjs';
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
* `@oasys/oecs/reactive-sync`'s `syncFieldsToMap` /
|
|
17
17
|
* `syncSingletonToStruct` for the read channel the field-handle reads through.
|
|
18
18
|
*/
|
|
19
|
-
export { Editor, TransactionBuilder, type EditorTransaction, type FieldReader } from './editor';
|
|
20
|
-
export { fieldHandle, type FieldHandle } from './field_handle';
|
|
19
|
+
export { Editor, TransactionBuilder, type EditorTransaction, type FieldReader } from './editor.js';
|
|
20
|
+
export { fieldHandle, type FieldHandle } from './field_handle.js';
|
|
21
21
|
//# sourceMappingURL=index.d.ts.map
|