@flighthq/command 0.5.1-edge.743.8d09db1 → 0.5.1-edge.909.a5d1857
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 +2 -2
- package/dist/command.d.ts +5 -1
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +57 -19
- package/dist/command.js.map +1 -1
- package/dist/commandBinding.d.ts +3 -2
- package/dist/commandBinding.d.ts.map +1 -1
- package/dist/commandBinding.js +18 -14
- package/dist/commandBinding.js.map +1 -1
- package/dist/commandHistory.d.ts +3 -2
- package/dist/commandHistory.d.ts.map +1 -1
- package/dist/commandHistory.js +15 -11
- package/dist/commandHistory.js.map +1 -1
- package/dist/contract.d.ts +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +1 -0
- package/dist/contract.js.map +1 -1
- package/package.json +6 -5
- package/src/command.test.ts +31 -2
- package/src/commandBinding.test.ts +34 -19
- package/src/commandHistory.test.ts +36 -22
- package/src/commandHistorySignals.test.ts +19 -2
- package/src/explainCommandDispatch.test.ts +39 -4
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/command`. The `@flig
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/command@0.5.1-edge.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/command@0.5.1-edge.909.a5d1857](https://github.com/flighthq/flight/tree/a5d18571cd3176400ab4dd8e03a2ed880037b213/packages/command)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/a5d18571cd3176400ab4dd8e03a2ed880037b213/LICENSE.md)
|
package/dist/command.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AddNodeChildCommand, Command, CompositeCommand, NodeAny, RemoveNodeChildCommand, ReorderNodeChildCommand, SetNodePropertyCommand } from '@flighthq/types/contract';
|
|
1
|
+
import type { AddNodeChildCommand, Command, CompositeCommand, EntityConstruction, NodeAny, RemoveNodeChildCommand, ReorderNodeChildCommand, SetNodePropertyCommand } from '@flighthq/types/contract';
|
|
2
2
|
/** Adds `child` to `parent`. `index` of `-1` appends. */
|
|
3
3
|
export declare function createAddNodeChildCommand(label: string, parent: NodeAny, child: NodeAny, index?: number): AddNodeChildCommand;
|
|
4
4
|
/** Applies `children` as one history entry, in order; undo runs them in reverse. Nesting is allowed. */
|
|
@@ -11,4 +11,8 @@ export declare function createSetNodePropertyCommandBatch(label: string, entries
|
|
|
11
11
|
target: NodeAny;
|
|
12
12
|
value: unknown;
|
|
13
13
|
}>[], mergeWindow?: number, time?: number): SetNodePropertyCommand;
|
|
14
|
+
export declare function initializeAddNodeChildCommand(out: EntityConstruction<AddNodeChildCommand>, label: string, parent: NodeAny, child: NodeAny, index: number): void;
|
|
15
|
+
export declare function initializeCompositeCommand(out: EntityConstruction<CompositeCommand>, label: string, children: readonly Command[]): void;
|
|
16
|
+
export declare function initializeRemoveNodeChildCommand(out: EntityConstruction<RemoveNodeChildCommand>, label: string, parent: NodeAny, child: NodeAny): void;
|
|
17
|
+
export declare function initializeReorderNodeChildCommand(out: EntityConstruction<ReorderNodeChildCommand>, label: string, parent: NodeAny, child: NodeAny, toIndex: number): void;
|
|
14
18
|
//# sourceMappingURL=command.d.ts.map
|
package/dist/command.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,mBAAmB,EACnB,OAAO,EAEP,gBAAgB,EAChB,kBAAkB,EAClB,OAAO,EACP,sBAAsB,EACtB,uBAAuB,EACvB,s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K,EAAE,MAAM,EACb,QAAQ,EAAE,SAAS,OAAO,EAAE,GAC3B,IAAI,CAIN;AAED,wBAAgB,gCAAgC,CAC9C,GAAG,EAAE,kBAAkB,CAAC,sBAAsB,CAAC,EAC/C,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,OAAO,GACb,IAAI,CAMN;AAED,wBAAgB,iCAAiC,CAC/C,GAAG,EAAE,kBAAkB,CAAC,uBAAuB,CAAC,EAChD,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,MAAM,GACd,IAAI,CAON"}
|
package/dist/command.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
1
2
|
import { getNodeChildIndex } from '@flighthq/node/contract';
|
|
2
3
|
import { AddNodeChildCommandKind, CompositeCommandKind, RemoveNodeChildCommandKind, ReorderNodeChildCommandKind, SetNodePropertyCommandKind, } from '@flighthq/types/contract';
|
|
3
4
|
// Constructors for the built-in command kinds. Each returns PLAIN DATA — no method, no captured closure —
|
|
@@ -9,27 +10,28 @@ import { AddNodeChildCommandKind, CompositeCommandKind, RemoveNodeChildCommandKi
|
|
|
9
10
|
// command BEFORE applying the change by hand.
|
|
10
11
|
/** Adds `child` to `parent`. `index` of `-1` appends. */
|
|
11
12
|
export function createAddNodeChildCommand(label, parent, child, index = -1) {
|
|
12
|
-
|
|
13
|
+
const out = allocateEntity();
|
|
14
|
+
initializeAddNodeChildCommand(out, label, parent, child, index);
|
|
15
|
+
return finishEntity(out);
|
|
13
16
|
}
|
|
14
17
|
/** Applies `children` as one history entry, in order; undo runs them in reverse. Nesting is allowed. */
|
|
15
18
|
export function createCompositeCommand(label, children) {
|
|
16
|
-
|
|
19
|
+
const out = allocateEntity();
|
|
20
|
+
initializeCompositeCommand(out, label, children);
|
|
21
|
+
return finishEntity(out);
|
|
17
22
|
}
|
|
18
23
|
// Removes `child` from `parent`, capturing its CURRENT index so undo restores position and not merely
|
|
19
24
|
// membership. Build this before removing the child — once it is detached the index is gone.
|
|
20
25
|
export function createRemoveNodeChildCommand(label, parent, child) {
|
|
21
|
-
|
|
26
|
+
const out = allocateEntity();
|
|
27
|
+
initializeRemoveNodeChildCommand(out, label, parent, child);
|
|
28
|
+
return finishEntity(out);
|
|
22
29
|
}
|
|
23
30
|
// Moves `child` to `toIndex`, capturing where it started. Build this before moving the child.
|
|
24
31
|
export function createReorderNodeChildCommand(label, parent, child, toIndex) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
kind: ReorderNodeChildCommandKind,
|
|
29
|
-
label,
|
|
30
|
-
parent,
|
|
31
|
-
toIndex,
|
|
32
|
-
};
|
|
32
|
+
const out = allocateEntity();
|
|
33
|
+
initializeReorderNodeChildCommand(out, label, parent, child, toIndex);
|
|
34
|
+
return finishEntity(out);
|
|
33
35
|
}
|
|
34
36
|
// One property assignment. `before` is read from the node NOW, so build this before writing the value.
|
|
35
37
|
//
|
|
@@ -38,13 +40,9 @@ export function createReorderNodeChildCommand(label, parent, child, toIndex) {
|
|
|
38
40
|
// undo entry. Both default to 0, meaning every change is its own entry. `time` is supplied by the caller
|
|
39
41
|
// because this package takes no clock dependency — and a caller-supplied number stays serializable.
|
|
40
42
|
export function createSetNodePropertyCommand(label, target, property, value, mergeWindow = 0, time = 0) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
label,
|
|
45
|
-
mergeWindow,
|
|
46
|
-
time,
|
|
47
|
-
};
|
|
43
|
+
const out = allocateEntity();
|
|
44
|
+
initializeSetNodePropertyCommand(out, label, target, property, value, mergeWindow, time);
|
|
45
|
+
return finishEntity(out);
|
|
48
46
|
}
|
|
49
47
|
// Several property assignments applied together as one entry — the shape a gizmo drag produces when it
|
|
50
48
|
// writes x and y at once. Each `before` is read now, in the order given.
|
|
@@ -55,7 +53,47 @@ export function createSetNodePropertyCommandBatch(label, entries, mergeWindow =
|
|
|
55
53
|
property: entry.property,
|
|
56
54
|
target: entry.target,
|
|
57
55
|
}));
|
|
58
|
-
|
|
56
|
+
const out = allocateEntity();
|
|
57
|
+
out.entries = captured;
|
|
58
|
+
out.kind = SetNodePropertyCommandKind;
|
|
59
|
+
out.label = label;
|
|
60
|
+
out.mergeWindow = mergeWindow;
|
|
61
|
+
out.time = time;
|
|
62
|
+
return finishEntity(out);
|
|
63
|
+
}
|
|
64
|
+
export function initializeAddNodeChildCommand(out, label, parent, child, index) {
|
|
65
|
+
out.child = child;
|
|
66
|
+
out.index = index;
|
|
67
|
+
out.kind = AddNodeChildCommandKind;
|
|
68
|
+
out.label = label;
|
|
69
|
+
out.parent = parent;
|
|
70
|
+
}
|
|
71
|
+
export function initializeCompositeCommand(out, label, children) {
|
|
72
|
+
out.children = [...children];
|
|
73
|
+
out.kind = CompositeCommandKind;
|
|
74
|
+
out.label = label;
|
|
75
|
+
}
|
|
76
|
+
export function initializeRemoveNodeChildCommand(out, label, parent, child) {
|
|
77
|
+
out.child = child;
|
|
78
|
+
out.index = getNodeChildIndex(parent, child);
|
|
79
|
+
out.kind = RemoveNodeChildCommandKind;
|
|
80
|
+
out.label = label;
|
|
81
|
+
out.parent = parent;
|
|
82
|
+
}
|
|
83
|
+
export function initializeReorderNodeChildCommand(out, label, parent, child, toIndex) {
|
|
84
|
+
out.child = child;
|
|
85
|
+
out.fromIndex = getNodeChildIndex(parent, child);
|
|
86
|
+
out.kind = ReorderNodeChildCommandKind;
|
|
87
|
+
out.label = label;
|
|
88
|
+
out.parent = parent;
|
|
89
|
+
out.toIndex = toIndex;
|
|
90
|
+
}
|
|
91
|
+
function initializeSetNodePropertyCommand(out, label, target, property, value, mergeWindow, time) {
|
|
92
|
+
out.entries = [{ after: value, before: readNodeProperty(target, property), property, target }];
|
|
93
|
+
out.kind = SetNodePropertyCommandKind;
|
|
94
|
+
out.label = label;
|
|
95
|
+
out.mergeWindow = mergeWindow;
|
|
96
|
+
out.time = time;
|
|
59
97
|
}
|
|
60
98
|
function readNodeProperty(target, property) {
|
|
61
99
|
return target[property];
|
package/dist/command.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAY5D,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,0BAA0B,EAC1B,2BAA2B,EAC3B,0BAA0B,GAC3B,MAAM,0BAA0B,CAAC;AAElC,0GAA0G;AAC1G,sGAAsG;AACtG,2FAA2F;AAC3F,EAAE;AACF,2GAA2G;AAC3G,2GAA2G;AAC3G,8CAA8C;AAE9C,yDAAyD;AACzD,MAAM,UAAU,yBAAyB,CACvC,KAAa,EACb,MAAe,EACf,KAAc,EACd,KAAK,GAAG,CAAC,CAAC;IAEV,MAAM,GAAG,GAAG,cAAc,EAAuB,CAAC;IAClD,6BAA6B,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAChE,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,wGAAwG;AACxG,MAAM,UAAU,sBAAsB,CAAC,KAAa,EAAE,QAA4B;IAChF,MAAM,GAAG,GAAG,cAAc,EAAoB,CAAC;IAC/C,0BAA0B,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IACjD,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,sGAAsG;AACtG,4FAA4F;AAC5F,MAAM,UAAU,4BAA4B,CAAC,KA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AAM,GAAG,MAAM,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,GAAgD,EAChD,KAAa,EACb,MAAe,EACf,KAAc,EACd,OAAe;IAEf,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;IAClB,GAAG,CAAC,SAAS,GAAG,iBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACjD,GAAG,CAAC,IAAI,GAAG,2BAA2B,CAAC;IACvC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;IAClB,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;IACpB,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC;AACxB,CAAC;AAED,SAAS,gCAAgC,CACvC,GAA+C,EAC/C,KAAa,EACb,MAAe,EACf,QAAgB,EAChB,KAAc,EACd,WAAmB,EACnB,IAAY;IAEZ,GAAG,CAAC,OAAO,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/F,GAAG,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACtC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;IAClB,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC;IAC9B,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;AAClB,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAyB,EAAE,QAAgB;IACnE,OAAQ,MAAuD,CAAC,QAAQ,CAAC,CAAC;AAC5E,CAAC"}
|
package/dist/commandBinding.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { CommandBinding, CommandHistory, Kind,
|
|
1
|
+
import type { CommandBinding, CommandBindingTable, CommandHistory, EntityConstruction, Kind, SetNodePropertyCommand } from '@flighthq/types/contract';
|
|
2
2
|
/** An empty command binding table. Every kind a history will dispatch must be registered into it. */
|
|
3
|
-
export declare function createCommandBindingTable():
|
|
3
|
+
export declare function createCommandBindingTable(): CommandBindingTable;
|
|
4
4
|
/** The binding registered for `kind`, or `null` when nothing is. */
|
|
5
5
|
export declare function getCommandBinding(history: Readonly<CommandHistory>, kind: Kind): CommandBinding | null;
|
|
6
6
|
export declare function hasCommandBinding(history: Readonly<CommandHistory>, kind: Kind): boolean;
|
|
7
|
+
export declare function initializeSetNodePropertyCommand(out: EntityConstruction<SetNodePropertyCommand>, entries: SetNodePropertyCommand['entries'], kind: Kind, label: string, mergeWindow: number, time: number): void;
|
|
7
8
|
export declare function registerCommandBinding(history: CommandHistory, kind: Kind, binding: CommandBinding): void;
|
|
8
9
|
export declare function registerDefaultCommandBindings(history: CommandHistory): void;
|
|
9
10
|
//# sourceMappingURL=commandBinding.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandBinding.d.ts","sourceRoot":"","sources":["../src/commandBinding.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commandBinding.d.ts","sourceRoot":"","sources":["../src/commandBinding.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,cAAc,EACd,mBAAmB,EACnB,cAAc,EAEd,kBAAkB,EAClB,IAAI,EAIJ,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAWlC,qGAAqG;AACrG,wBAAgB,yBAAyB,IAAI,mBAAmB,CAE/D;AAED,oEAAoE;AACpE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,cAAc,GAAG,IAAI,CAEtG;AAKD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAExF;AAID,wBAAgB,gCAAgC,CAC9C,GAAG,EAAE,kBAAkB,CAAC,sBAAsB,CAAC,EAC/C,OAAO,EAAE,sBAAsB,CAAC,SAAS,CAAC,EAC1C,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,GACX,IAAI,CAMN;AAKD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CAEzG;AAED,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAM5E"}
|
package/dist/commandBinding.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
1
2
|
import { addNodeChildAt, getNodeChildCount, removeNodeChild, setNodeChildIndex } from '@flighthq/node/contract';
|
|
2
3
|
import { createKeyedTable, getRegistryTableEntry, withRegistryTableEntry } from '@flighthq/registry/contract';
|
|
3
4
|
import { AddNodeChildCommandKind, CommandBindingMissPolicy, CommandBindingRegistryId, CompositeCommandKind, RemoveNodeChildCommandKind, ReorderNodeChildCommandKind, SetNodePropertyCommandKind, } from '@flighthq/types/contract';
|
|
@@ -15,14 +16,21 @@ export function getCommandBinding(history, kind) {
|
|
|
15
16
|
export function hasCommandBinding(history, kind) {
|
|
16
17
|
return getCommandBinding(history, kind) !== null;
|
|
17
18
|
}
|
|
19
|
+
// Registers the five built-in kinds. An explicit call rather than a side effect at import: a history that
|
|
20
|
+
// only dispatches a caller's own kinds never references these, so they shake out of the bundle.
|
|
21
|
+
export function initializeSetNodePropertyCommand(out, entries, kind, label, mergeWindow, time) {
|
|
22
|
+
out.entries = entries;
|
|
23
|
+
out.kind = kind;
|
|
24
|
+
out.label = label;
|
|
25
|
+
out.mergeWindow = mergeWindow;
|
|
26
|
+
out.time = time;
|
|
27
|
+
}
|
|
18
28
|
// Binds behaviour to a command kind. NOT called at module load anywhere in this package — a caller opts
|
|
19
29
|
// in, which is what keeps unused command kinds shakeable and lets a consumer override a built-in binding
|
|
20
30
|
// or add a vendor-prefixed kind of their own. Last write wins.
|
|
21
31
|
export function registerCommandBinding(history, kind, binding) {
|
|
22
32
|
history.bindings = withRegistryTableEntry(history.bindings, kind, binding);
|
|
23
33
|
}
|
|
24
|
-
// Registers the five built-in kinds. An explicit call rather than a side effect at import: a history that
|
|
25
|
-
// only dispatches a caller's own kinds never references these, so they shake out of the bundle.
|
|
26
34
|
export function registerDefaultCommandBindings(history) {
|
|
27
35
|
registerCommandBinding(history, AddNodeChildCommandKind, addNodeChildCommandBinding);
|
|
28
36
|
registerCommandBinding(history, CompositeCommandKind, compositeCommandBinding(history));
|
|
@@ -112,18 +120,14 @@ const setNodePropertyCommandBinding = {
|
|
|
112
120
|
if (a.entries[i].property !== b.entries[i].property)
|
|
113
121
|
return null;
|
|
114
122
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
label: b.label,
|
|
124
|
-
mergeWindow: b.mergeWindow,
|
|
125
|
-
time: b.time,
|
|
126
|
-
};
|
|
123
|
+
const out = allocateEntity();
|
|
124
|
+
initializeSetNodePropertyCommand(out, a.entries.map((entry, i) => ({
|
|
125
|
+
after: b.entries[i].after,
|
|
126
|
+
before: entry.before,
|
|
127
|
+
property: entry.property,
|
|
128
|
+
target: entry.target,
|
|
129
|
+
})), a.kind, b.label, b.mergeWindow, b.time);
|
|
130
|
+
return finishEntity(out);
|
|
127
131
|
},
|
|
128
132
|
undo: (command) => {
|
|
129
133
|
const entries = command.entries;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandBinding.js","sourceRoot":"","sources":["../src/commandBinding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAChH,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":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7C,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;CACF,CAAC;AAEF,2GAA2G;AAC3G,2GAA2G;AAC3G,oBAAoB;AACpB,SAAS,kBAAkB,CAAC,MAAyB,EAAE,KAAa;IAClE,MAAM,KAAK,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACxC,OAAO,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AACpD,CAAC;AAED,sGAAsG;AACtG,2EAA2E;AAC3E,SAAS,iBAAiB,CAAC,MAAe,EAAE,QAAgB,EAAE,KAAc;IACzE,MAA6C,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;AACnE,CAAC"}
|
package/dist/commandHistory.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type { Command, CommandHistory } from '@flighthq/types/contract';
|
|
1
|
+
import type { Command, CommandHistory, EntityConstruction } from '@flighthq/types/contract';
|
|
2
2
|
/** Whether there is an applied entry to reverse. */
|
|
3
3
|
export declare function canRedoCommand(history: Readonly<CommandHistory>): boolean;
|
|
4
4
|
/** Whether there is a reversed entry ahead of the cursor to re-apply. */
|
|
5
5
|
export declare function canUndoCommand(history: Readonly<CommandHistory>): boolean;
|
|
6
6
|
export declare function clearCommandHistory(history: CommandHistory): void;
|
|
7
|
-
/** An empty history with no bindings registered. `maxSize` of `0` (the default) is unbounded. */
|
|
8
7
|
export declare function createCommandHistory(maxSize?: number): CommandHistory;
|
|
9
8
|
export declare function executeCommand(history: CommandHistory, command: Command): boolean;
|
|
10
9
|
/** Every entry, oldest first, including the reversed ones ahead of the cursor. */
|
|
@@ -15,6 +14,8 @@ export declare function getCommandHistoryIndex(history: Readonly<CommandHistory>
|
|
|
15
14
|
export declare function getCommandHistoryRedoLabel(history: Readonly<CommandHistory>): string | null;
|
|
16
15
|
/** The label of the entry undo would reverse, or null. */
|
|
17
16
|
export declare function getCommandHistoryUndoLabel(history: Readonly<CommandHistory>): string | null;
|
|
17
|
+
/** An empty history with no bindings registered. `maxSize` of `0` (the default) is unbounded. */
|
|
18
|
+
export declare function initializeCommandHistory(out: EntityConstruction<CommandHistory>, maxSize?: number): void;
|
|
18
19
|
export declare function notifyCommandHistoryChanged(history: Readonly<CommandHistory>): void;
|
|
19
20
|
export declare function redoCommand(history: CommandHistory): boolean;
|
|
20
21
|
/** Reverses the most recently applied entry. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandHistory.d.ts","sourceRoot":"","sources":["../src/commandHistory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commandHistory.d.ts","sourceRoot":"","sources":["../src/commandHistory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAI5F,oDAAoD;AACpD,wBAAgB,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,OAAO,CAEzE;AAED,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,OAAO,CAEzE;AAID,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAQjE;AAED,wBAAgB,oBAAoB,CAAC,OAAO,SAAI,GAAG,cAAc,CAIhE;AAUD,wBAAgB,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAuBjF;AAED,kFAAkF;AAClF,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,SAAS,OAAO,EAAE,CAE9F;AAED,qGAAqG;AACrG,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,MAAM,CAEhF;AAED,2DAA2D;AAC3D,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,MAAM,GAAG,IAAI,CAE3F;AAED,0DAA0D;AAC1D,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,MAAM,GAAG,IAAI,CAE3F;AAED,iGAAiG;AACjG,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,kBAAkB,CAAC,cAAc,CAAC,EAAE,OAAO,SAAI,GAAG,IAAI,CASnG;AAID,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,IAAI,CAEnF;AAKD,wBAAgB,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAS5D;AAED,gDAAgD;AAChD,wBAAgB,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAS5D"}
|
package/dist/commandHistory.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
1
2
|
import { emitSignal } from '@flighthq/signals/contract';
|
|
2
3
|
import { createCommandBindingTable, getCommandBinding } from './commandBinding';
|
|
3
4
|
/** Whether there is an applied entry to reverse. */
|
|
@@ -20,18 +21,10 @@ export function clearCommandHistory(history) {
|
|
|
20
21
|
history.transactionLabel = null;
|
|
21
22
|
notifyCommandHistoryChanged(history);
|
|
22
23
|
}
|
|
23
|
-
/** An empty history with no bindings registered. `maxSize` of `0` (the default) is unbounded. */
|
|
24
24
|
export function createCommandHistory(maxSize = 0) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
index: 0,
|
|
29
|
-
maxSize,
|
|
30
|
-
onChange: null,
|
|
31
|
-
transactionDepth: 0,
|
|
32
|
-
transactionIndex: 0,
|
|
33
|
-
transactionLabel: null,
|
|
34
|
-
};
|
|
25
|
+
const out = allocateEntity();
|
|
26
|
+
initializeCommandHistory(out, maxSize);
|
|
27
|
+
return finishEntity(out);
|
|
35
28
|
}
|
|
36
29
|
// Applies `command` and pushes it. Returns false and changes nothing when the command's kind has no
|
|
37
30
|
// registered binding — an unregistered kind is an expected lookup failure, so it takes a sentinel rather
|
|
@@ -80,6 +73,17 @@ export function getCommandHistoryRedoLabel(history) {
|
|
|
80
73
|
export function getCommandHistoryUndoLabel(history) {
|
|
81
74
|
return canUndoCommand(history) ? history.entries[history.index - 1].label : null;
|
|
82
75
|
}
|
|
76
|
+
/** An empty history with no bindings registered. `maxSize` of `0` (the default) is unbounded. */
|
|
77
|
+
export function initializeCommandHistory(out, maxSize = 0) {
|
|
78
|
+
out.bindings = createCommandBindingTable();
|
|
79
|
+
out.entries = [];
|
|
80
|
+
out.index = 0;
|
|
81
|
+
out.maxSize = maxSize;
|
|
82
|
+
out.onChange = null;
|
|
83
|
+
out.transactionDepth = 0;
|
|
84
|
+
out.transactionIndex = 0;
|
|
85
|
+
out.transactionLabel = null;
|
|
86
|
+
}
|
|
83
87
|
// Emits the opt-in change signal if a caller allocated one. Internal rather than exported: emitting a
|
|
84
88
|
// change nobody made is how a history panel learns to distrust the signal.
|
|
85
89
|
export function notifyCommandHistoryChanged(history) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandHistory.js","sourceRoot":"","sources":["../src/commandHistory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAGxD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAEhF,oDAAoD;AACpD,MAAM,UAAU,cAAc,CAAC,OAAiC;IAC9D,OAAO,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;AAChD,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,cAAc,CAAC,OAAiC;IAC9D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,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IACnD,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACnC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtB,OAAO,CAAC,KAAK,EAAE,CAAC;IAChB,2BAA2B,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,2GAA2G;AAC3G,oEAAoE;AACpE,SAAS,kBAAkB,CAAC,OAAuB;IACjD,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,OAAO;QAAE,OAAO;IAC9E,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IACxD,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAClC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;IACpD,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,gBAAgB,GAAG,MAAM,CAAC,CAAC;AAC5E,CAAC"}
|
package/dist/contract.d.ts
CHANGED
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/contract.js
CHANGED
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/command",
|
|
3
|
-
"version": "0.5.1-edge.
|
|
3
|
+
"version": "0.5.1-edge.909.a5d1857",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,10 +38,11 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/
|
|
42
|
-
"@flighthq/
|
|
43
|
-
"@flighthq/
|
|
44
|
-
"@flighthq/
|
|
41
|
+
"@flighthq/entity": "0.5.1-edge.909.a5d1857",
|
|
42
|
+
"@flighthq/node": "0.5.1-edge.909.a5d1857",
|
|
43
|
+
"@flighthq/registry": "0.5.1-edge.909.a5d1857",
|
|
44
|
+
"@flighthq/signals": "0.5.1-edge.909.a5d1857",
|
|
45
|
+
"@flighthq/types": "0.5.1-edge.909.a5d1857"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"typescript": "^5.3.0"
|
package/src/command.test.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { NodeAny } from '@flighthq/types/contract';
|
|
|
3
3
|
import {
|
|
4
4
|
AddNodeChildCommandKind,
|
|
5
5
|
CompositeCommandKind,
|
|
6
|
+
EntityRuntimeKey,
|
|
6
7
|
RemoveNodeChildCommandKind,
|
|
7
8
|
ReorderNodeChildCommandKind,
|
|
8
9
|
SetNodePropertyCommandKind,
|
|
@@ -16,14 +17,19 @@ import {
|
|
|
16
17
|
createReorderNodeChildCommand,
|
|
17
18
|
createSetNodePropertyCommand,
|
|
18
19
|
createSetNodePropertyCommandBatch,
|
|
20
|
+
initializeAddNodeChildCommand,
|
|
21
|
+
initializeCompositeCommand,
|
|
22
|
+
initializeRemoveNodeChildCommand,
|
|
23
|
+
initializeReorderNodeChildCommand,
|
|
19
24
|
} from './command';
|
|
20
25
|
|
|
21
26
|
describe('createAddNodeChildCommand', () => {
|
|
22
|
-
it('is
|
|
27
|
+
it('is Entity data carrying its kind, and appends by default', () => {
|
|
23
28
|
const parent = node();
|
|
24
29
|
const child = node();
|
|
25
30
|
const command = createAddNodeChildCommand('Add sprite', parent, child);
|
|
26
|
-
expect(
|
|
31
|
+
expect(Object.hasOwn(command, EntityRuntimeKey)).toBe(true);
|
|
32
|
+
expect(command).toMatchObject({ child, index: -1, kind: AddNodeChildCommandKind, label: 'Add sprite', parent });
|
|
27
33
|
});
|
|
28
34
|
|
|
29
35
|
it('records an explicit insertion index', () => {
|
|
@@ -113,3 +119,26 @@ describe('createSetNodePropertyCommandBatch', () => {
|
|
|
113
119
|
function node(): NodeAny {
|
|
114
120
|
return createNode('test.CommandTarget') as NodeAny;
|
|
115
121
|
}
|
|
122
|
+
describe('initializeAddNodeChildCommand', () => {
|
|
123
|
+
it('is the construction initializer of createAddNodeChildCommand', () => {
|
|
124
|
+
expect(typeof initializeAddNodeChildCommand).toBe('function');
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe('initializeCompositeCommand', () => {
|
|
129
|
+
it('is the construction initializer of createCompositeCommand', () => {
|
|
130
|
+
expect(typeof initializeCompositeCommand).toBe('function');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('initializeRemoveNodeChildCommand', () => {
|
|
135
|
+
it('is the construction initializer of createRemoveNodeChildCommand', () => {
|
|
136
|
+
expect(typeof initializeRemoveNodeChildCommand).toBe('function');
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe('initializeReorderNodeChildCommand', () => {
|
|
141
|
+
it('is the construction initializer of createReorderNodeChildCommand', () => {
|
|
142
|
+
expect(typeof initializeReorderNodeChildCommand).toBe('function');
|
|
143
|
+
});
|
|
144
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
1
2
|
import { addNodeChild, createNode, getNodeChildCount, getNodeChildIndex } from '@flighthq/node/contract';
|
|
2
3
|
import type { CommandBinding, NodeAny, SetNodePropertyCommand } from '@flighthq/types/contract';
|
|
3
4
|
import { SetNodePropertyCommandKind } from '@flighthq/types/contract';
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
createCommandBindingTable,
|
|
15
16
|
getCommandBinding,
|
|
16
17
|
hasCommandBinding,
|
|
18
|
+
initializeSetNodePropertyCommand,
|
|
17
19
|
registerCommandBinding,
|
|
18
20
|
registerDefaultCommandBindings,
|
|
19
21
|
} from './commandBinding';
|
|
@@ -41,6 +43,12 @@ describe('hasCommandBinding', () => {
|
|
|
41
43
|
});
|
|
42
44
|
});
|
|
43
45
|
|
|
46
|
+
describe('initializeSetNodePropertyCommand', () => {
|
|
47
|
+
it('is the construction initializer of createSetNodePropertyCommand', () => {
|
|
48
|
+
expect(typeof initializeSetNodePropertyCommand).toBe('function');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
44
52
|
describe('registerCommandBinding', () => {
|
|
45
53
|
it('accepts a caller-defined vendor-prefixed kind', () => {
|
|
46
54
|
const history = createCommandHistory();
|
|
@@ -49,7 +57,15 @@ describe('registerCommandBinding', () => {
|
|
|
49
57
|
execute: () => seen.push('execute'),
|
|
50
58
|
undo: () => seen.push('undo'),
|
|
51
59
|
});
|
|
52
|
-
executeCommand(
|
|
60
|
+
executeCommand(
|
|
61
|
+
history,
|
|
62
|
+
(() => {
|
|
63
|
+
const out = allocateEntity<any>();
|
|
64
|
+
out.kind = 'acme.Custom';
|
|
65
|
+
out.label = 'Custom';
|
|
66
|
+
return finishEntity(out);
|
|
67
|
+
})(),
|
|
68
|
+
);
|
|
53
69
|
undoCommand(history);
|
|
54
70
|
expect(seen).toEqual(['execute', 'undo']);
|
|
55
71
|
});
|
|
@@ -65,6 +81,23 @@ describe('registerCommandBinding', () => {
|
|
|
65
81
|
});
|
|
66
82
|
});
|
|
67
83
|
|
|
84
|
+
function node(): NodeAny {
|
|
85
|
+
return createNode('test.CommandTarget') as NodeAny;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function read(target: Readonly<NodeAny>, property: string): unknown {
|
|
89
|
+
return (target as unknown as Readonly<Record<string, unknown>>)[property];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function withDefaults() {
|
|
93
|
+
const history = createCommandHistory();
|
|
94
|
+
registerDefaultCommandBindings(history);
|
|
95
|
+
return history;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function write(target: NodeAny, property: string, value: unknown): void {
|
|
99
|
+
(target as unknown as Record<string, unknown>)[property] = value;
|
|
100
|
+
}
|
|
68
101
|
describe('registerDefaultCommandBindings', () => {
|
|
69
102
|
it('applies and reverses an added child, restoring membership', () => {
|
|
70
103
|
const history = withDefaults();
|
|
@@ -199,21 +232,3 @@ describe('registerDefaultCommandBindings', () => {
|
|
|
199
232
|
expect(merged.entries[0].after).toBe(20);
|
|
200
233
|
});
|
|
201
234
|
});
|
|
202
|
-
|
|
203
|
-
function node(): NodeAny {
|
|
204
|
-
return createNode('test.CommandTarget') as NodeAny;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function read(target: Readonly<NodeAny>, property: string): unknown {
|
|
208
|
-
return (target as unknown as Readonly<Record<string, unknown>>)[property];
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function withDefaults() {
|
|
212
|
-
const history = createCommandHistory();
|
|
213
|
-
registerDefaultCommandBindings(history);
|
|
214
|
-
return history;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function write(target: NodeAny, property: string, value: unknown): void {
|
|
218
|
-
(target as unknown as Record<string, unknown>)[property] = value;
|
|
219
|
-
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
1
2
|
import { createNode, getNodeChildCount } from '@flighthq/node/contract';
|
|
2
3
|
import { connectSignal } from '@flighthq/signals/contract';
|
|
3
4
|
import type { Command, CommandHistory, NodeAny } from '@flighthq/types/contract';
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
getCommandHistoryIndex,
|
|
16
17
|
getCommandHistoryRedoLabel,
|
|
17
18
|
getCommandHistoryUndoLabel,
|
|
19
|
+
initializeCommandHistory,
|
|
18
20
|
notifyCommandHistoryChanged,
|
|
19
21
|
redoCommand,
|
|
20
22
|
undoCommand,
|
|
@@ -77,7 +79,7 @@ describe('createCommandHistory', () => {
|
|
|
77
79
|
describe('executeCommand', () => {
|
|
78
80
|
it('refuses an unregistered kind rather than pushing an entry undo would skip', () => {
|
|
79
81
|
const history = createCommandHistory();
|
|
80
|
-
expect(executeCommand(history,
|
|
82
|
+
expect(executeCommand(history, command('acme.Unbound', 'Nope'))).toBe(false);
|
|
81
83
|
expect(getCommandHistoryEntries(history)).toHaveLength(0);
|
|
82
84
|
});
|
|
83
85
|
|
|
@@ -143,6 +145,12 @@ describe('getCommandHistoryUndoLabel', () => {
|
|
|
143
145
|
});
|
|
144
146
|
});
|
|
145
147
|
|
|
148
|
+
describe('initializeCommandHistory', () => {
|
|
149
|
+
it('is the construction initializer of createCommandHistory', () => {
|
|
150
|
+
expect(typeof initializeCommandHistory).toBe('function');
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
146
154
|
describe('notifyCommandHistoryChanged', () => {
|
|
147
155
|
it('is inert when no signal was enabled', () => {
|
|
148
156
|
expect(() => notifyCommandHistoryChanged(createCommandHistory())).not.toThrow();
|
|
@@ -161,28 +169,15 @@ describe('redoCommand', () => {
|
|
|
161
169
|
});
|
|
162
170
|
});
|
|
163
171
|
|
|
164
|
-
describe('undoCommand', () => {
|
|
165
|
-
it('returns false with nothing to undo', () => {
|
|
166
|
-
expect(undoCommand(createCommandHistory())).toBe(false);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('reverses entries newest first', () => {
|
|
170
|
-
const history = counting();
|
|
171
|
-
const order: string[] = [];
|
|
172
|
-
registerCommandBinding(history, 'test.Ordered', {
|
|
173
|
-
execute: () => undefined,
|
|
174
|
-
undo: (command) => order.push(command.label),
|
|
175
|
-
});
|
|
176
|
-
executeCommand(history, { kind: 'test.Ordered', label: 'One' });
|
|
177
|
-
executeCommand(history, { kind: 'test.Ordered', label: 'Two' });
|
|
178
|
-
undoCommand(history);
|
|
179
|
-
undoCommand(history);
|
|
180
|
-
expect(order).toEqual(['Two', 'One']);
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
|
|
184
172
|
function counter(label: string): Command {
|
|
185
|
-
return
|
|
173
|
+
return command('test.Counter', label);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function command(kind: string, label: string): Command {
|
|
177
|
+
const out = allocateEntity<Command>();
|
|
178
|
+
out.kind = kind;
|
|
179
|
+
out.label = label;
|
|
180
|
+
return finishEntity(out);
|
|
186
181
|
}
|
|
187
182
|
|
|
188
183
|
// A history bound to one inert kind, so stack behaviour can be tested without any graph mutation.
|
|
@@ -201,3 +196,22 @@ function withDefaults(): CommandHistory {
|
|
|
201
196
|
registerDefaultCommandBindings(history);
|
|
202
197
|
return history;
|
|
203
198
|
}
|
|
199
|
+
describe('undoCommand', () => {
|
|
200
|
+
it('returns false with nothing to undo', () => {
|
|
201
|
+
expect(undoCommand(createCommandHistory())).toBe(false);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('reverses entries newest first', () => {
|
|
205
|
+
const history = counting();
|
|
206
|
+
const order: string[] = [];
|
|
207
|
+
registerCommandBinding(history, 'test.Ordered', {
|
|
208
|
+
execute: () => undefined,
|
|
209
|
+
undo: (command) => order.push(command.label),
|
|
210
|
+
});
|
|
211
|
+
executeCommand(history, command('test.Ordered', 'One'));
|
|
212
|
+
executeCommand(history, command('test.Ordered', 'Two'));
|
|
213
|
+
undoCommand(history);
|
|
214
|
+
undoCommand(history);
|
|
215
|
+
expect(order).toEqual(['Two', 'One']);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
1
2
|
import { connectSignal } from '@flighthq/signals/contract';
|
|
2
3
|
import { describe, expect, it } from 'vitest';
|
|
3
4
|
|
|
@@ -19,7 +20,15 @@ describe('enableCommandHistorySignals', () => {
|
|
|
19
20
|
let changes = 0;
|
|
20
21
|
connectSignal(enableCommandHistorySignals(history), () => changes++);
|
|
21
22
|
|
|
22
|
-
executeCommand(
|
|
23
|
+
executeCommand(
|
|
24
|
+
history,
|
|
25
|
+
(() => {
|
|
26
|
+
const out = allocateEntity<any>();
|
|
27
|
+
out.kind = 'test.Counter';
|
|
28
|
+
out.label = 'One';
|
|
29
|
+
return finishEntity(out);
|
|
30
|
+
})(),
|
|
31
|
+
);
|
|
23
32
|
expect(changes).toBe(1);
|
|
24
33
|
undoCommand(history);
|
|
25
34
|
expect(changes).toBe(2);
|
|
@@ -30,7 +39,15 @@ describe('enableCommandHistorySignals', () => {
|
|
|
30
39
|
const history = createCommandHistory();
|
|
31
40
|
let changes = 0;
|
|
32
41
|
connectSignal(enableCommandHistorySignals(history), () => changes++);
|
|
33
|
-
executeCommand(
|
|
42
|
+
executeCommand(
|
|
43
|
+
history,
|
|
44
|
+
(() => {
|
|
45
|
+
const out = allocateEntity<any>();
|
|
46
|
+
out.kind = 'acme.Unbound';
|
|
47
|
+
out.label = 'Nope';
|
|
48
|
+
return finishEntity(out);
|
|
49
|
+
})(),
|
|
50
|
+
);
|
|
34
51
|
expect(changes).toBe(0);
|
|
35
52
|
});
|
|
36
53
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
1
2
|
import { describe, expect, it } from 'vitest';
|
|
2
3
|
|
|
3
4
|
import { createCompositeCommand } from './command';
|
|
@@ -8,7 +9,17 @@ import { explainCommandDispatch } from './explainCommandDispatch';
|
|
|
8
9
|
describe('explainCommandDispatch', () => {
|
|
9
10
|
it('names the unregistered kind behind a refusal', () => {
|
|
10
11
|
const history = createCommandHistory();
|
|
11
|
-
expect(
|
|
12
|
+
expect(
|
|
13
|
+
explainCommandDispatch(
|
|
14
|
+
history,
|
|
15
|
+
(() => {
|
|
16
|
+
const out = allocateEntity<any>();
|
|
17
|
+
out.kind = 'acme.Unbound';
|
|
18
|
+
out.label = 'Nope';
|
|
19
|
+
return finishEntity(out);
|
|
20
|
+
})(),
|
|
21
|
+
),
|
|
22
|
+
).toEqual({
|
|
12
23
|
missingKind: 'acme.Unbound',
|
|
13
24
|
resolved: false,
|
|
14
25
|
});
|
|
@@ -17,7 +28,17 @@ describe('explainCommandDispatch', () => {
|
|
|
17
28
|
it('resolves when the kind is registered', () => {
|
|
18
29
|
const history = createCommandHistory();
|
|
19
30
|
registerCommandBinding(history, 'acme.Bound', { execute: () => undefined, undo: () => undefined });
|
|
20
|
-
expect(
|
|
31
|
+
expect(
|
|
32
|
+
explainCommandDispatch(
|
|
33
|
+
history,
|
|
34
|
+
(() => {
|
|
35
|
+
const out = allocateEntity<any>();
|
|
36
|
+
out.kind = 'acme.Bound';
|
|
37
|
+
out.label = 'Yes';
|
|
38
|
+
return finishEntity(out);
|
|
39
|
+
})(),
|
|
40
|
+
),
|
|
41
|
+
).toEqual({
|
|
21
42
|
missingKind: null,
|
|
22
43
|
resolved: true,
|
|
23
44
|
});
|
|
@@ -28,7 +49,14 @@ describe('explainCommandDispatch', () => {
|
|
|
28
49
|
it('descends into a composite and names an unbound child kind', () => {
|
|
29
50
|
const history = createCommandHistory();
|
|
30
51
|
registerCommandBinding(history, 'CompositeCommand', { execute: () => undefined, undo: () => undefined });
|
|
31
|
-
const composite = createCompositeCommand('Group', [
|
|
52
|
+
const composite = createCompositeCommand('Group', [
|
|
53
|
+
(() => {
|
|
54
|
+
const out = allocateEntity<any>();
|
|
55
|
+
out.kind = 'acme.Unbound';
|
|
56
|
+
out.label = 'Child';
|
|
57
|
+
return finishEntity(out);
|
|
58
|
+
})(),
|
|
59
|
+
]);
|
|
32
60
|
expect(explainCommandDispatch(history, composite).missingKind).toBe('acme.Unbound');
|
|
33
61
|
});
|
|
34
62
|
|
|
@@ -36,7 +64,14 @@ describe('explainCommandDispatch', () => {
|
|
|
36
64
|
const history = createCommandHistory();
|
|
37
65
|
registerCommandBinding(history, 'CompositeCommand', { execute: () => undefined, undo: () => undefined });
|
|
38
66
|
registerCommandBinding(history, 'acme.Bound', { execute: () => undefined, undo: () => undefined });
|
|
39
|
-
const composite = createCompositeCommand('Group', [
|
|
67
|
+
const composite = createCompositeCommand('Group', [
|
|
68
|
+
(() => {
|
|
69
|
+
const out = allocateEntity<any>();
|
|
70
|
+
out.kind = 'acme.Bound';
|
|
71
|
+
out.label = 'Child';
|
|
72
|
+
return finishEntity(out);
|
|
73
|
+
})(),
|
|
74
|
+
]);
|
|
40
75
|
expect(explainCommandDispatch(history, composite).resolved).toBe(true);
|
|
41
76
|
});
|
|
42
77
|
});
|