pixifact 0.1.3 → 0.1.4
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 +3 -3
- package/dist/builtin-scenes/CenterContainer.d.ts +13 -0
- package/dist/builtin-scenes/CenterContainer.js +71 -0
- package/dist/builtin-scenes/CenterContainer.scene +3 -0
- package/dist/builtin-scenes/CenterContainer.ts +77 -0
- package/dist/builtin-scenes/Control.d.ts +44 -0
- package/dist/builtin-scenes/Control.js +206 -0
- package/dist/builtin-scenes/Control.scene +3 -0
- package/dist/builtin-scenes/Control.ts +233 -0
- package/dist/builtin-scenes/FlexItem.d.ts +45 -0
- package/dist/builtin-scenes/FlexItem.js +164 -0
- package/dist/builtin-scenes/FlexItem.scene +3 -0
- package/dist/builtin-scenes/FlexItem.ts +180 -0
- package/dist/builtin-scenes/FlexLayout.d.ts +29 -0
- package/dist/builtin-scenes/FlexLayout.js +358 -0
- package/dist/builtin-scenes/FlexLayout.scene +3 -0
- package/dist/builtin-scenes/FlexLayout.ts +409 -0
- package/dist/builtin-scenes/HBoxContainer.d.ts +15 -0
- package/dist/builtin-scenes/HBoxContainer.js +70 -0
- package/dist/builtin-scenes/HBoxContainer.scene +3 -0
- package/dist/builtin-scenes/HBoxContainer.ts +75 -0
- package/dist/builtin-scenes/MarginContainer.d.ts +23 -0
- package/dist/builtin-scenes/MarginContainer.js +131 -0
- package/dist/builtin-scenes/MarginContainer.scene +3 -0
- package/dist/builtin-scenes/MarginContainer.ts +139 -0
- package/dist/builtin-scenes/VBoxContainer.d.ts +15 -0
- package/dist/builtin-scenes/VBoxContainer.js +70 -0
- package/dist/builtin-scenes/VBoxContainer.scene +3 -0
- package/dist/builtin-scenes/VBoxContainer.ts +75 -0
- package/dist/builtin-scenes/controlLayout.d.ts +57 -0
- package/dist/builtin-scenes/controlLayout.js +202 -0
- package/dist/builtin-scenes/controlLayout.ts +270 -0
- package/dist/compiler/builtinScenes.d.ts +14 -0
- package/dist/compiler/builtinScenes.js +62 -0
- package/dist/compiler/compileScenes.js +126 -19
- package/dist/compiler/decorators.js +3 -0
- package/dist/compiler/index.d.ts +1 -0
- package/dist/compiler/index.js +1 -0
- package/dist/compiler/sceneAssetPair.js +19 -0
- package/dist/compiler/sceneRuntime.d.ts +5 -4
- package/dist/compiler/scriptInterfaceExtractor.d.ts +5 -0
- package/dist/compiler/scriptInterfaceExtractor.js +214 -8
- package/dist/compiler/spec.d.ts +2 -0
- package/dist/compiler/templateParser.js +4 -3
- package/dist/compiler/templateSerializer.js +2 -1
- package/dist/compiler/typescriptCompiler.js +87 -13
- package/dist/compiler-node/builtinSceneAssets.d.ts +8 -0
- package/dist/compiler-node/builtinSceneAssets.js +57 -0
- package/dist/compiler-node/index.d.ts +1 -0
- package/dist/compiler-node/index.js +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +24 -0
- package/dist/index.d.ts +2 -5
- package/dist/index.js +2 -5
- package/dist/{authoring/ProjectConfig.d.ts → project/index.d.ts} +7 -0
- package/dist/{authoring/ProjectConfig.js → project/index.js} +22 -0
- package/dist/runtime/Group.d.ts +18 -0
- package/dist/runtime/Group.js +45 -0
- package/dist/runtime/index.d.ts +1 -9
- package/dist/runtime/index.js +1 -9
- package/package.json +4 -26
- package/dist/authoring/ActionRegistry.d.ts +0 -10
- package/dist/authoring/ActionRegistry.js +0 -26
- package/dist/authoring/ComponentPalette.d.ts +0 -16
- package/dist/authoring/ComponentPalette.js +0 -50
- package/dist/authoring/DesignToken.d.ts +0 -16
- package/dist/authoring/DesignToken.js +0 -33
- package/dist/authoring/DiffModel.d.ts +0 -10
- package/dist/authoring/DiffModel.js +0 -104
- package/dist/authoring/InspectorModel.d.ts +0 -27
- package/dist/authoring/InspectorModel.js +0 -139
- package/dist/authoring/LogicGraph.d.ts +0 -66
- package/dist/authoring/LogicGraph.js +0 -184
- package/dist/authoring/OverrideJournal.d.ts +0 -18
- package/dist/authoring/OverrideJournal.js +0 -23
- package/dist/authoring/PreferenceMemory.d.ts +0 -21
- package/dist/authoring/PreferenceMemory.js +0 -39
- package/dist/authoring/RuntimePreview.d.ts +0 -11
- package/dist/authoring/RuntimePreview.js +0 -25
- package/dist/authoring/SceneDocument.d.ts +0 -74
- package/dist/authoring/SceneDocument.js +0 -332
- package/dist/authoring/SceneProjectState.d.ts +0 -20
- package/dist/authoring/SceneProjectState.js +0 -8
- package/dist/authoring/SceneSelection.d.ts +0 -11
- package/dist/authoring/SceneSelection.js +0 -1
- package/dist/authoring/index.d.ts +0 -13
- package/dist/authoring/index.js +0 -13
- package/dist/commands/Command.d.ts +0 -63
- package/dist/commands/Command.js +0 -1
- package/dist/commands/CommandStack.d.ts +0 -14
- package/dist/commands/CommandStack.js +0 -45
- package/dist/commands/applyCommand.d.ts +0 -23
- package/dist/commands/applyCommand.js +0 -316
- package/dist/commands/index.d.ts +0 -4
- package/dist/commands/index.js +0 -4
- package/dist/commands/utils.d.ts +0 -17
- package/dist/commands/utils.js +0 -77
- package/dist/commands/validateCommand.d.ts +0 -12
- package/dist/commands/validateCommand.js +0 -285
- package/dist/nodes/Input.d.ts +0 -91
- package/dist/nodes/Input.js +0 -352
- package/dist/nodes/Textarea.d.ts +0 -10
- package/dist/nodes/Textarea.js +0 -38
- package/dist/nodes/components/Button.d.ts +0 -8
- package/dist/nodes/components/Button.js +0 -45
- package/dist/nodes/components/InputField.d.ts +0 -12
- package/dist/nodes/components/InputField.js +0 -53
- package/dist/nodes/components/ProgressBar.d.ts +0 -14
- package/dist/nodes/components/ProgressBar.js +0 -66
- package/dist/nodes/components/ScrollRect.d.ts +0 -23
- package/dist/nodes/components/ScrollRect.js +0 -108
- package/dist/nodes/components/Selectable.d.ts +0 -32
- package/dist/nodes/components/Selectable.js +0 -153
- package/dist/nodes/components/index.d.ts +0 -5
- package/dist/nodes/components/index.js +0 -5
- package/dist/nodes/graphics/Graphic.d.ts +0 -14
- package/dist/nodes/graphics/Graphic.js +0 -47
- package/dist/nodes/graphics/ImageGraphic.d.ts +0 -9
- package/dist/nodes/graphics/ImageGraphic.js +0 -42
- package/dist/nodes/graphics/RoundedRectGraphic.d.ts +0 -13
- package/dist/nodes/graphics/RoundedRectGraphic.js +0 -65
- package/dist/nodes/graphics/TextGraphic.d.ts +0 -13
- package/dist/nodes/graphics/TextGraphic.js +0 -70
- package/dist/nodes/graphics/index.d.ts +0 -4
- package/dist/nodes/graphics/index.js +0 -4
- package/dist/nodes/index.d.ts +0 -3
- package/dist/nodes/index.js +0 -3
- package/dist/runtime/Application.d.ts +0 -15
- package/dist/runtime/Application.js +0 -67
- package/dist/runtime/GameObject.d.ts +0 -100
- package/dist/runtime/GameObject.js +0 -297
- package/dist/runtime/GameObjectEvent.d.ts +0 -52
- package/dist/runtime/GameObjectEvent.js +0 -38
- package/dist/runtime/Transform.d.ts +0 -32
- package/dist/runtime/Transform.js +0 -157
- package/dist/runtime/component/Component.d.ts +0 -13
- package/dist/runtime/component/Component.js +0 -13
- package/dist/runtime/component/ComponentRegistry.d.ts +0 -49
- package/dist/runtime/component/ComponentRegistry.js +0 -25
- package/dist/runtime/component/Flex.d.ts +0 -6
- package/dist/runtime/component/Flex.js +0 -15
- package/dist/runtime/component/FlexGroup.d.ts +0 -26
- package/dist/runtime/component/FlexGroup.js +0 -136
- package/dist/runtime/component/GridLayout.d.ts +0 -47
- package/dist/runtime/component/GridLayout.js +0 -129
- package/dist/runtime/component/Layout.d.ts +0 -104
- package/dist/runtime/component/Layout.js +0 -248
- package/dist/runtime/component/decorators.d.ts +0 -4
- package/dist/runtime/component/decorators.js +0 -52
- package/dist/runtime/component/index.d.ts +0 -7
- package/dist/runtime/component/index.js +0 -7
- package/dist/runtime/graphics/index.d.ts +0 -11
- package/dist/runtime/graphics/index.js +0 -29
- package/dist/runtime/group/index.d.ts +0 -39
- package/dist/runtime/group/index.js +0 -102
- package/dist/runtime/image/Image.d.ts +0 -19
- package/dist/runtime/image/Image.js +0 -60
- package/dist/runtime/image/NineSliceImage.d.ts +0 -23
- package/dist/runtime/image/NineSliceImage.js +0 -64
- package/dist/runtime/image/index.d.ts +0 -2
- package/dist/runtime/image/index.js +0 -2
- package/dist/runtime/label/Label.d.ts +0 -11
- package/dist/runtime/label/Label.js +0 -26
- package/dist/runtime/label/LabelStyle.d.ts +0 -3
- package/dist/runtime/label/LabelStyle.js +0 -3
- package/dist/runtime/label/index.d.ts +0 -2
- package/dist/runtime/label/index.js +0 -2
- package/dist/runtime/utils/index.d.ts +0 -1
- package/dist/runtime/utils/index.js +0 -1
- package/dist/runtime/utils/onlyOnceQueueMicrotask.d.ts +0 -1
- package/dist/runtime/utils/onlyOnceQueueMicrotask.js +0 -12
- package/dist/runtime/utils/setProps.d.ts +0 -10
- package/dist/runtime/utils/setProps.js +0 -17
- package/dist/scene/dsl.d.ts +0 -25
- package/dist/scene/dsl.js +0 -112
- package/dist/scene/index.d.ts +0 -5
- package/dist/scene/index.js +0 -5
- package/dist/scene/instantiate.d.ts +0 -8
- package/dist/scene/instantiate.js +0 -208
- package/dist/scene/nodesDsl.d.ts +0 -42
- package/dist/scene/nodesDsl.js +0 -169
- package/dist/scene/spec.d.ts +0 -100
- package/dist/scene/spec.js +0 -1
- package/dist/scene/templates.d.ts +0 -21
- package/dist/scene/templates.js +0 -239
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import { validateCommand } from "./validateCommand.js";
|
|
2
|
-
import { cloneValue, findComponent, findNode } from "./utils.js";
|
|
3
|
-
export function hintForCommandError(error) {
|
|
4
|
-
if (error.includes('inside projectRoot')) {
|
|
5
|
-
return 'Use a project-relative scene path that stays inside projectRoot.';
|
|
6
|
-
}
|
|
7
|
-
if (error.includes('already exists')) {
|
|
8
|
-
return 'Choose a different scene path or inspect the existing file before writing.';
|
|
9
|
-
}
|
|
10
|
-
if (error.includes('Unknown template kind')) {
|
|
11
|
-
return 'Use one of: button, progressBar, scrollView, loginForm.';
|
|
12
|
-
}
|
|
13
|
-
if (error.includes('was not found')) {
|
|
14
|
-
return 'Re-run scene get or node inspect to refresh locators before regenerating the command.';
|
|
15
|
-
}
|
|
16
|
-
if (error.includes('Only container nodes')) {
|
|
17
|
-
return 'Choose a container node as the parent, or create a container template before adding children.';
|
|
18
|
-
}
|
|
19
|
-
if (error.includes('does not exist')) {
|
|
20
|
-
return 'Verify that the field belongs to the target node or component schema before retrying.';
|
|
21
|
-
}
|
|
22
|
-
if (error.includes('expects')) {
|
|
23
|
-
return 'Check the target schema and send a value with the expected type.';
|
|
24
|
-
}
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
function commandNode(command) {
|
|
28
|
-
switch (command.op) {
|
|
29
|
-
case 'createNode':
|
|
30
|
-
return nodeLocator(command.node);
|
|
31
|
-
case 'batch':
|
|
32
|
-
return undefined;
|
|
33
|
-
default:
|
|
34
|
-
return command.node;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function commandTarget(command) {
|
|
38
|
-
switch (command.op) {
|
|
39
|
-
case 'setNodeProp':
|
|
40
|
-
return `${command.node}.${command.prop}`;
|
|
41
|
-
case 'setTransform':
|
|
42
|
-
return `${command.node}.transform`;
|
|
43
|
-
case 'setNodeData':
|
|
44
|
-
return `${command.node}.${command.field}.${command.prop}`;
|
|
45
|
-
case 'setComponentProp':
|
|
46
|
-
return `${command.node}.${command.component}.${command.prop}`;
|
|
47
|
-
case 'addComponent':
|
|
48
|
-
return `${command.node}.components.${command.component.id ?? command.component.type}`;
|
|
49
|
-
case 'removeComponent':
|
|
50
|
-
return `${command.node}.components.${command.component}`;
|
|
51
|
-
case 'createNode':
|
|
52
|
-
return `${command.parent ?? 'root'}.children`;
|
|
53
|
-
case 'deleteNode':
|
|
54
|
-
return command.node;
|
|
55
|
-
case 'reparentNode':
|
|
56
|
-
return `${command.node}.parent`;
|
|
57
|
-
case 'reorderNode':
|
|
58
|
-
return `${command.node}.index`;
|
|
59
|
-
case 'batch':
|
|
60
|
-
return 'batch.commands';
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
export function commandFailureDetails(commands, results, error) {
|
|
64
|
-
const failedResultIndex = results.findIndex((result) => !result.ok);
|
|
65
|
-
const commandIndex = failedResultIndex >= 0
|
|
66
|
-
? failedResultIndex
|
|
67
|
-
: Math.min(results.length, commands.length - 1);
|
|
68
|
-
const command = commands[commandIndex];
|
|
69
|
-
if (!command) {
|
|
70
|
-
return {
|
|
71
|
-
hint: error ? hintForCommandError(error) : undefined,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
commandIndex,
|
|
76
|
-
op: command.op,
|
|
77
|
-
node: commandNode(command),
|
|
78
|
-
target: commandTarget(command),
|
|
79
|
-
hint: error ? hintForCommandError(error) : undefined,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function applySetTransform(scene, command) {
|
|
83
|
-
const located = findNode(scene, command.node);
|
|
84
|
-
const previous = {};
|
|
85
|
-
const transform = located.node.transform ?? {};
|
|
86
|
-
for (const key of Object.keys(command.values)) {
|
|
87
|
-
previous[key] = transform[key];
|
|
88
|
-
}
|
|
89
|
-
located.node.transform = { ...transform };
|
|
90
|
-
for (const [key, value] of Object.entries(command.values)) {
|
|
91
|
-
if (value === undefined) {
|
|
92
|
-
delete located.node.transform[key];
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
located.node.transform[key] = value;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
op: 'setTransform',
|
|
100
|
-
node: command.node,
|
|
101
|
-
values: previous,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
function applySetNodeData(scene, command) {
|
|
105
|
-
const located = findNode(scene, command.node);
|
|
106
|
-
const nodeData = located.node;
|
|
107
|
-
const current = nodeData[command.field] ?? {};
|
|
108
|
-
const previous = current[command.prop];
|
|
109
|
-
const next = { ...current };
|
|
110
|
-
if (command.value === undefined) {
|
|
111
|
-
delete next[command.prop];
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
next[command.prop] = cloneValue(command.value);
|
|
115
|
-
}
|
|
116
|
-
nodeData[command.field] = next;
|
|
117
|
-
return {
|
|
118
|
-
op: 'setNodeData',
|
|
119
|
-
node: command.node,
|
|
120
|
-
field: command.field,
|
|
121
|
-
prop: command.prop,
|
|
122
|
-
value: previous,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
function applySetNodeProp(scene, command) {
|
|
126
|
-
const located = findNode(scene, command.node);
|
|
127
|
-
const previous = located.node[command.prop];
|
|
128
|
-
if (command.value === undefined) {
|
|
129
|
-
delete located.node[command.prop];
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
located.node[command.prop] = command.value;
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
op: 'setNodeProp',
|
|
136
|
-
node: command.value ?? command.node,
|
|
137
|
-
prop: command.prop,
|
|
138
|
-
value: previous,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
function applySetComponentProp(scene, command) {
|
|
142
|
-
const locatedNode = findNode(scene, command.node);
|
|
143
|
-
const locatedComponent = findComponent(locatedNode.node, command.component);
|
|
144
|
-
const props = locatedComponent.component.props ?? {};
|
|
145
|
-
const previous = props[command.prop];
|
|
146
|
-
locatedComponent.component.props = { ...props };
|
|
147
|
-
if (command.value === undefined) {
|
|
148
|
-
delete locatedComponent.component.props[command.prop];
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
locatedComponent.component.props[command.prop] = cloneValue(command.value);
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
op: 'setComponentProp',
|
|
155
|
-
node: command.node,
|
|
156
|
-
component: command.component,
|
|
157
|
-
prop: command.prop,
|
|
158
|
-
value: previous,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
function applyAddComponent(scene, command) {
|
|
162
|
-
const locatedNode = findNode(scene, command.node);
|
|
163
|
-
const components = locatedNode.node.components ?? [];
|
|
164
|
-
const index = command.index ?? components.length;
|
|
165
|
-
components.splice(index, 0, cloneValue(command.component));
|
|
166
|
-
locatedNode.node.components = components;
|
|
167
|
-
return {
|
|
168
|
-
op: 'removeComponent',
|
|
169
|
-
node: command.node,
|
|
170
|
-
component: command.component.id ?? command.component.type,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
function applyRemoveComponent(scene, command) {
|
|
174
|
-
const locatedNode = findNode(scene, command.node);
|
|
175
|
-
const locatedComponent = findComponent(locatedNode.node, command.component);
|
|
176
|
-
const components = locatedNode.node.components ?? [];
|
|
177
|
-
const [removed] = components.splice(locatedComponent.index, 1);
|
|
178
|
-
locatedNode.node.components = components;
|
|
179
|
-
return {
|
|
180
|
-
op: 'addComponent',
|
|
181
|
-
node: command.node,
|
|
182
|
-
component: cloneValue(removed),
|
|
183
|
-
index: locatedComponent.index,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function applyCreateNode(scene, command) {
|
|
187
|
-
const children = command.parent
|
|
188
|
-
? (findNode(scene, command.parent).node.children ??= [])
|
|
189
|
-
: (scene.root.children ??= []);
|
|
190
|
-
const index = command.index ?? children.length;
|
|
191
|
-
children.splice(index, 0, cloneValue(command.node));
|
|
192
|
-
return {
|
|
193
|
-
op: 'deleteNode',
|
|
194
|
-
node: command.node.id ?? command.node.key ?? command.node.name ?? '',
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
function applyDeleteNode(scene, command) {
|
|
198
|
-
const located = findNode(scene, command.node);
|
|
199
|
-
const siblings = located.parent?.children ?? [];
|
|
200
|
-
const [removed] = siblings.splice(located.index, 1);
|
|
201
|
-
return {
|
|
202
|
-
op: 'createNode',
|
|
203
|
-
parent: located.parent?.id ?? located.parent?.key ?? located.parent?.name,
|
|
204
|
-
node: cloneValue(removed),
|
|
205
|
-
index: located.index,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
function nodeLocator(node) {
|
|
209
|
-
return node.id ?? node.key ?? node.name ?? '';
|
|
210
|
-
}
|
|
211
|
-
function applyReparentNode(scene, command) {
|
|
212
|
-
const located = findNode(scene, command.node);
|
|
213
|
-
const previousParent = located.parent;
|
|
214
|
-
const previousIndex = located.index;
|
|
215
|
-
const oldSiblings = previousParent?.children ?? [];
|
|
216
|
-
const [node] = oldSiblings.splice(previousIndex, 1);
|
|
217
|
-
const nextParent = command.parent ? findNode(scene, command.parent).node : scene.root;
|
|
218
|
-
const nextSiblings = nextParent.children ??= [];
|
|
219
|
-
const index = Math.min(command.index ?? nextSiblings.length, nextSiblings.length);
|
|
220
|
-
nextSiblings.splice(index, 0, node);
|
|
221
|
-
return {
|
|
222
|
-
op: 'reparentNode',
|
|
223
|
-
node: command.node,
|
|
224
|
-
parent: previousParent ? nodeLocator(previousParent) : undefined,
|
|
225
|
-
index: previousIndex,
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
function applyReorderNode(scene, command) {
|
|
229
|
-
const located = findNode(scene, command.node);
|
|
230
|
-
const siblings = located.parent.children ?? [];
|
|
231
|
-
const previousIndex = located.index;
|
|
232
|
-
const [node] = siblings.splice(previousIndex, 1);
|
|
233
|
-
const index = Math.min(command.index, siblings.length);
|
|
234
|
-
siblings.splice(index, 0, node);
|
|
235
|
-
return {
|
|
236
|
-
op: 'reorderNode',
|
|
237
|
-
node: command.node,
|
|
238
|
-
index: previousIndex,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
function applyBatch(scene, command, context) {
|
|
242
|
-
const inverseCommands = [];
|
|
243
|
-
for (const child of command.commands) {
|
|
244
|
-
const result = applyCommand(scene, child, context);
|
|
245
|
-
if (!result.ok) {
|
|
246
|
-
for (let i = inverseCommands.length - 1; i >= 0; i--) {
|
|
247
|
-
applyCommand(scene, inverseCommands[i], context);
|
|
248
|
-
}
|
|
249
|
-
return {
|
|
250
|
-
ok: false,
|
|
251
|
-
command,
|
|
252
|
-
error: result.error,
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
inverseCommands.push(result.inverse);
|
|
256
|
-
}
|
|
257
|
-
return {
|
|
258
|
-
ok: true,
|
|
259
|
-
command,
|
|
260
|
-
inverse: {
|
|
261
|
-
op: 'batch',
|
|
262
|
-
commands: [...inverseCommands].reverse(),
|
|
263
|
-
},
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
export function applyCommand(scene, command, context = {}) {
|
|
267
|
-
const validation = validateCommand(scene, command, context);
|
|
268
|
-
if (!validation.ok) {
|
|
269
|
-
return {
|
|
270
|
-
ok: false,
|
|
271
|
-
command,
|
|
272
|
-
error: validation.error ?? 'Command validation failed.',
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
let inverse;
|
|
276
|
-
switch (command.op) {
|
|
277
|
-
case 'setNodeProp':
|
|
278
|
-
inverse = applySetNodeProp(scene, command);
|
|
279
|
-
break;
|
|
280
|
-
case 'setTransform':
|
|
281
|
-
inverse = applySetTransform(scene, command);
|
|
282
|
-
break;
|
|
283
|
-
case 'setNodeData':
|
|
284
|
-
inverse = applySetNodeData(scene, command);
|
|
285
|
-
break;
|
|
286
|
-
case 'setComponentProp':
|
|
287
|
-
inverse = applySetComponentProp(scene, command);
|
|
288
|
-
break;
|
|
289
|
-
case 'addComponent':
|
|
290
|
-
inverse = applyAddComponent(scene, command);
|
|
291
|
-
break;
|
|
292
|
-
case 'removeComponent':
|
|
293
|
-
inverse = applyRemoveComponent(scene, command);
|
|
294
|
-
break;
|
|
295
|
-
case 'createNode':
|
|
296
|
-
inverse = applyCreateNode(scene, command);
|
|
297
|
-
break;
|
|
298
|
-
case 'deleteNode':
|
|
299
|
-
inverse = applyDeleteNode(scene, command);
|
|
300
|
-
break;
|
|
301
|
-
case 'reparentNode':
|
|
302
|
-
inverse = applyReparentNode(scene, command);
|
|
303
|
-
break;
|
|
304
|
-
case 'reorderNode':
|
|
305
|
-
inverse = applyReorderNode(scene, command);
|
|
306
|
-
break;
|
|
307
|
-
case 'batch':
|
|
308
|
-
return applyBatch(scene, command, context);
|
|
309
|
-
}
|
|
310
|
-
return {
|
|
311
|
-
ok: true,
|
|
312
|
-
command,
|
|
313
|
-
inverse,
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
export const applySceneCommand = applyCommand;
|
package/dist/commands/index.d.ts
DELETED
package/dist/commands/index.js
DELETED
package/dist/commands/utils.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ComponentSpec, ContainerNodeSpec, NodeSpec, SceneSpec } from "../scene/index.js";
|
|
2
|
-
export interface LocatedNode {
|
|
3
|
-
node: NodeSpec;
|
|
4
|
-
parent?: ContainerNodeSpec;
|
|
5
|
-
index: number;
|
|
6
|
-
}
|
|
7
|
-
export interface LocatedComponent {
|
|
8
|
-
component: ComponentSpec;
|
|
9
|
-
index: number;
|
|
10
|
-
}
|
|
11
|
-
export declare function cloneValue<T>(value: T): T;
|
|
12
|
-
export declare function findNode(scene: SceneSpec, locator: string): LocatedNode | undefined;
|
|
13
|
-
export declare function findComponent(node: NodeSpec, locator: string): LocatedComponent | undefined;
|
|
14
|
-
export declare function hasDuplicateNodeId(scene: SceneSpec, id: string): boolean;
|
|
15
|
-
export declare function hasDuplicateNodeLocator(scene: SceneSpec, locator: string, except?: NodeSpec): boolean;
|
|
16
|
-
export declare function isDescendant(candidate: NodeSpec, parent: NodeSpec): boolean;
|
|
17
|
-
export declare function hasDuplicateComponentId(node: NodeSpec, id: string): boolean;
|
package/dist/commands/utils.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
export function cloneValue(value) {
|
|
2
|
-
return structuredClone(value);
|
|
3
|
-
}
|
|
4
|
-
function nodeMatches(node, locator) {
|
|
5
|
-
return node.id === locator || node.key === locator || node.name === locator;
|
|
6
|
-
}
|
|
7
|
-
export function findNode(scene, locator) {
|
|
8
|
-
const visit = (node, parent, index) => {
|
|
9
|
-
if (nodeMatches(node, locator)) {
|
|
10
|
-
return { node, parent, index };
|
|
11
|
-
}
|
|
12
|
-
if (node.kind === 'container') {
|
|
13
|
-
for (let i = 0; i < (node.children?.length ?? 0); i++) {
|
|
14
|
-
const child = node.children[i];
|
|
15
|
-
const found = visit(child, node, i);
|
|
16
|
-
if (found) {
|
|
17
|
-
return found;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return undefined;
|
|
22
|
-
};
|
|
23
|
-
return visit(scene.root, undefined, 0);
|
|
24
|
-
}
|
|
25
|
-
export function findComponent(node, locator) {
|
|
26
|
-
const components = node.components ?? [];
|
|
27
|
-
for (let i = 0; i < components.length; i++) {
|
|
28
|
-
const component = components[i];
|
|
29
|
-
if (component.id === locator || component.type === locator) {
|
|
30
|
-
return { component, index: i };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
export function hasDuplicateNodeId(scene, id) {
|
|
36
|
-
let count = 0;
|
|
37
|
-
const visit = (node) => {
|
|
38
|
-
if (node.id === id) {
|
|
39
|
-
count++;
|
|
40
|
-
}
|
|
41
|
-
if (node.kind === 'container') {
|
|
42
|
-
for (const child of node.children ?? []) {
|
|
43
|
-
visit(child);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
visit(scene.root);
|
|
48
|
-
return count > 0;
|
|
49
|
-
}
|
|
50
|
-
export function hasDuplicateNodeLocator(scene, locator, except) {
|
|
51
|
-
let count = 0;
|
|
52
|
-
const visit = (node) => {
|
|
53
|
-
if (node !== except && (node.id === locator || node.key === locator || node.name === locator)) {
|
|
54
|
-
count++;
|
|
55
|
-
}
|
|
56
|
-
if (node.kind === 'container') {
|
|
57
|
-
for (const child of node.children ?? []) {
|
|
58
|
-
visit(child);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
visit(scene.root);
|
|
63
|
-
return count > 0;
|
|
64
|
-
}
|
|
65
|
-
export function isDescendant(candidate, parent) {
|
|
66
|
-
if (parent.kind === 'container') {
|
|
67
|
-
for (const child of parent.children ?? []) {
|
|
68
|
-
if (child === candidate || isDescendant(candidate, child)) {
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
export function hasDuplicateComponentId(node, id) {
|
|
76
|
-
return (node.components ?? []).some((component) => component.id === id);
|
|
77
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { SceneSpec } from "../scene/index.js";
|
|
2
|
-
import type { SceneCommand } from "./Command.js";
|
|
3
|
-
import type { ActionSpec } from "../authoring/ActionRegistry.js";
|
|
4
|
-
export interface ValidationResult {
|
|
5
|
-
ok: boolean;
|
|
6
|
-
error?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface CommandValidationContext {
|
|
9
|
-
actions?: readonly ActionSpec[];
|
|
10
|
-
}
|
|
11
|
-
export declare function validateCommand(scene: SceneSpec, command: SceneCommand, context?: CommandValidationContext): ValidationResult;
|
|
12
|
-
export declare const validateSceneCommand: typeof validateCommand;
|