@flighthq/command 0.5.1-next.904.b545d9c → 0.5.1-next.906.419e5c9
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/package.json +6 -6
- package/src/command.test.ts +27 -0
- package/src/commandBinding.test.ts +24 -18
- package/src/commandHistory.test.ts +26 -20
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-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/command@0.5.1-next.906.419e5c9](https://github.com/flighthq/flight/tree/419e5c925b366b5053ed7711ce371eee89dc31e7/packages/command)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/419e5c925b366b5053ed7711ce371eee89dc31e7/LICENSE.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/command",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.906.419e5c9",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/entity": "0.5.1-next.
|
|
42
|
-
"@flighthq/node": "0.5.1-next.
|
|
43
|
-
"@flighthq/registry": "0.5.1-next.
|
|
44
|
-
"@flighthq/signals": "0.5.1-next.
|
|
45
|
-
"@flighthq/types": "0.5.1-next.
|
|
41
|
+
"@flighthq/entity": "0.5.1-next.906.419e5c9",
|
|
42
|
+
"@flighthq/node": "0.5.1-next.906.419e5c9",
|
|
43
|
+
"@flighthq/registry": "0.5.1-next.906.419e5c9",
|
|
44
|
+
"@flighthq/signals": "0.5.1-next.906.419e5c9",
|
|
45
|
+
"@flighthq/types": "0.5.1-next.906.419e5c9"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"typescript": "^5.3.0"
|
package/src/command.test.ts
CHANGED
|
@@ -17,6 +17,10 @@ import {
|
|
|
17
17
|
createReorderNodeChildCommand,
|
|
18
18
|
createSetNodePropertyCommand,
|
|
19
19
|
createSetNodePropertyCommandBatch,
|
|
20
|
+
initializeAddNodeChildCommand,
|
|
21
|
+
initializeCompositeCommand,
|
|
22
|
+
initializeRemoveNodeChildCommand,
|
|
23
|
+
initializeReorderNodeChildCommand,
|
|
20
24
|
} from './command';
|
|
21
25
|
|
|
22
26
|
describe('createAddNodeChildCommand', () => {
|
|
@@ -115,3 +119,26 @@ describe('createSetNodePropertyCommandBatch', () => {
|
|
|
115
119
|
function node(): NodeAny {
|
|
116
120
|
return createNode('test.CommandTarget') as NodeAny;
|
|
117
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
|
+
});
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
createCommandBindingTable,
|
|
16
16
|
getCommandBinding,
|
|
17
17
|
hasCommandBinding,
|
|
18
|
+
initializeSetNodePropertyCommand,
|
|
18
19
|
registerCommandBinding,
|
|
19
20
|
registerDefaultCommandBindings,
|
|
20
21
|
} from './commandBinding';
|
|
@@ -42,6 +43,12 @@ describe('hasCommandBinding', () => {
|
|
|
42
43
|
});
|
|
43
44
|
});
|
|
44
45
|
|
|
46
|
+
describe('initializeSetNodePropertyCommand', () => {
|
|
47
|
+
it('is the construction initializer of createSetNodePropertyCommand', () => {
|
|
48
|
+
expect(typeof initializeSetNodePropertyCommand).toBe('function');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
45
52
|
describe('registerCommandBinding', () => {
|
|
46
53
|
it('accepts a caller-defined vendor-prefixed kind', () => {
|
|
47
54
|
const history = createCommandHistory();
|
|
@@ -74,6 +81,23 @@ describe('registerCommandBinding', () => {
|
|
|
74
81
|
});
|
|
75
82
|
});
|
|
76
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
|
+
}
|
|
77
101
|
describe('registerDefaultCommandBindings', () => {
|
|
78
102
|
it('applies and reverses an added child, restoring membership', () => {
|
|
79
103
|
const history = withDefaults();
|
|
@@ -208,21 +232,3 @@ describe('registerDefaultCommandBindings', () => {
|
|
|
208
232
|
expect(merged.entries[0].after).toBe(20);
|
|
209
233
|
});
|
|
210
234
|
});
|
|
211
|
-
|
|
212
|
-
function node(): NodeAny {
|
|
213
|
-
return createNode('test.CommandTarget') as NodeAny;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function read(target: Readonly<NodeAny>, property: string): unknown {
|
|
217
|
-
return (target as unknown as Readonly<Record<string, unknown>>)[property];
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function withDefaults() {
|
|
221
|
-
const history = createCommandHistory();
|
|
222
|
-
registerDefaultCommandBindings(history);
|
|
223
|
-
return history;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function write(target: NodeAny, property: string, value: unknown): void {
|
|
227
|
-
(target as unknown as Record<string, unknown>)[property] = value;
|
|
228
|
-
}
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
getCommandHistoryIndex,
|
|
17
17
|
getCommandHistoryRedoLabel,
|
|
18
18
|
getCommandHistoryUndoLabel,
|
|
19
|
+
initializeCommandHistory,
|
|
19
20
|
notifyCommandHistoryChanged,
|
|
20
21
|
redoCommand,
|
|
21
22
|
undoCommand,
|
|
@@ -144,6 +145,12 @@ describe('getCommandHistoryUndoLabel', () => {
|
|
|
144
145
|
});
|
|
145
146
|
});
|
|
146
147
|
|
|
148
|
+
describe('initializeCommandHistory', () => {
|
|
149
|
+
it('is the construction initializer of createCommandHistory', () => {
|
|
150
|
+
expect(typeof initializeCommandHistory).toBe('function');
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
147
154
|
describe('notifyCommandHistoryChanged', () => {
|
|
148
155
|
it('is inert when no signal was enabled', () => {
|
|
149
156
|
expect(() => notifyCommandHistoryChanged(createCommandHistory())).not.toThrow();
|
|
@@ -162,26 +169,6 @@ describe('redoCommand', () => {
|
|
|
162
169
|
});
|
|
163
170
|
});
|
|
164
171
|
|
|
165
|
-
describe('undoCommand', () => {
|
|
166
|
-
it('returns false with nothing to undo', () => {
|
|
167
|
-
expect(undoCommand(createCommandHistory())).toBe(false);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('reverses entries newest first', () => {
|
|
171
|
-
const history = counting();
|
|
172
|
-
const order: string[] = [];
|
|
173
|
-
registerCommandBinding(history, 'test.Ordered', {
|
|
174
|
-
execute: () => undefined,
|
|
175
|
-
undo: (command) => order.push(command.label),
|
|
176
|
-
});
|
|
177
|
-
executeCommand(history, command('test.Ordered', 'One'));
|
|
178
|
-
executeCommand(history, command('test.Ordered', 'Two'));
|
|
179
|
-
undoCommand(history);
|
|
180
|
-
undoCommand(history);
|
|
181
|
-
expect(order).toEqual(['Two', 'One']);
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
172
|
function counter(label: string): Command {
|
|
186
173
|
return command('test.Counter', label);
|
|
187
174
|
}
|
|
@@ -209,3 +196,22 @@ function withDefaults(): CommandHistory {
|
|
|
209
196
|
registerDefaultCommandBindings(history);
|
|
210
197
|
return history;
|
|
211
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
|
+
});
|