@trojanbox-vcp-test/site-edit-engine 0.1.0 → 0.2.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/dist/index.d.ts +3 -0
- package/dist/index.js +127 -2
- package/dist/internal/protocol/operation.d.ts +2 -0
- package/dist/internal/protocol/render.d.ts +3 -30
- package/dist/internal/protocol.d.ts +1 -1
- package/dist/next-app-router.js +1 -140
- package/dist/preview-runtime.d.ts +249 -303
- package/dist/runtime-sync.d.ts +8 -8
- package/dist/runtime.d.ts +1 -127
- package/dist/site-edit-instrumentation.d.ts +1 -1
- package/dist/source-watcher.js +1 -150
- package/dist/types.d.ts +12 -14
- package/dist/webpack-loader.cjs +50 -588
- package/package.json +2 -2
- package/dist/execute-integration/execute-fixture-harness.d.ts +0 -25
- package/dist/execute-integration/execute-fixture-harness.js +0 -37
- package/dist/internal/ast/diagnostics/index.d.ts +0 -5
- package/dist/internal/ast/diagnostics/index.js +0 -25
- package/dist/internal/ast/history/index.d.ts +0 -15
- package/dist/internal/ast/history/index.js +0 -62
- package/dist/internal/ast/index.d.ts +0 -8
- package/dist/internal/ast/index.js +0 -5
- package/dist/internal/ast/locators/index.d.ts +0 -1
- package/dist/internal/ast/locators/index.js +0 -1
- package/dist/internal/ast/locators/resolve-locator.d.ts +0 -16
- package/dist/internal/ast/locators/resolve-locator.js +0 -920
- package/dist/internal/ast/parser/SourceParser.d.ts +0 -30
- package/dist/internal/ast/parser/SourceParser.js +0 -49
- package/dist/internal/ast/parser/index.d.ts +0 -21
- package/dist/internal/ast/parser/index.js +0 -64
- package/dist/internal/ast/primitives/conditional/conditional-primitives.d.ts +0 -18
- package/dist/internal/ast/primitives/conditional/conditional-primitives.js +0 -237
- package/dist/internal/ast/primitives/conditional/index.d.ts +0 -1
- package/dist/internal/ast/primitives/conditional/index.js +0 -1
- package/dist/internal/ast/primitives/imports/add-import.d.ts +0 -18
- package/dist/internal/ast/primitives/imports/add-import.js +0 -111
- package/dist/internal/ast/primitives/imports/index.d.ts +0 -2
- package/dist/internal/ast/primitives/imports/index.js +0 -2
- package/dist/internal/ast/primitives/imports/remove-import.d.ts +0 -15
- package/dist/internal/ast/primitives/imports/remove-import.js +0 -72
- package/dist/internal/ast/primitives/index.d.ts +0 -10
- package/dist/internal/ast/primitives/index.js +0 -10
- package/dist/internal/ast/primitives/jsx/index.d.ts +0 -4
- package/dist/internal/ast/primitives/jsx/index.js +0 -4
- package/dist/internal/ast/primitives/jsx/insert-child.d.ts +0 -11
- package/dist/internal/ast/primitives/jsx/insert-child.js +0 -69
- package/dist/internal/ast/primitives/jsx/move-node.d.ts +0 -9
- package/dist/internal/ast/primitives/jsx/move-node.js +0 -76
- package/dist/internal/ast/primitives/jsx/remove-node.d.ts +0 -7
- package/dist/internal/ast/primitives/jsx/remove-node.js +0 -36
- package/dist/internal/ast/primitives/jsx/update-text.d.ts +0 -8
- package/dist/internal/ast/primitives/jsx/update-text.js +0 -81
- package/dist/internal/ast/primitives/next/index.d.ts +0 -1
- package/dist/internal/ast/primitives/next/index.js +0 -1
- package/dist/internal/ast/primitives/next/next-primitives.d.ts +0 -43
- package/dist/internal/ast/primitives/next/next-primitives.js +0 -211
- package/dist/internal/ast/primitives/shared.d.ts +0 -60
- package/dist/internal/ast/primitives/shared.js +0 -176
- package/dist/internal/ast/primitives/style/class-expression.d.ts +0 -23
- package/dist/internal/ast/primitives/style/class-expression.js +0 -174
- package/dist/internal/ast/primitives/style/index.d.ts +0 -1
- package/dist/internal/ast/primitives/style/index.js +0 -1
- package/dist/internal/ast/primitives/style/style-primitives.d.ts +0 -49
- package/dist/internal/ast/primitives/style/style-primitives.js +0 -555
- package/dist/internal/ast/primitives/values/index.d.ts +0 -1
- package/dist/internal/ast/primitives/values/index.js +0 -1
- package/dist/internal/ast/primitives/values/value-primitives.d.ts +0 -42
- package/dist/internal/ast/primitives/values/value-primitives.js +0 -158
- package/dist/internal/ast/printer/SourcePrinter.d.ts +0 -21
- package/dist/internal/ast/printer/SourcePrinter.js +0 -76
- package/dist/internal/ast/printer/index.d.ts +0 -6
- package/dist/internal/ast/printer/index.js +0 -126
- package/dist/internal/ast/types.d.ts +0 -190
- package/dist/internal/ast/types.js +0 -1
- package/dist/internal/capability/capability-resolver.d.ts +0 -16
- package/dist/internal/capability/capability-resolver.js +0 -127
- package/dist/internal/classname-source.d.ts +0 -24
- package/dist/internal/classname-source.js +0 -220
- package/dist/internal/contracts/IEditEngineRuntime.d.ts +0 -18
- package/dist/internal/contracts/IEditEngineRuntime.js +0 -1
- package/dist/internal/domain/EditDiagnostic.d.ts +0 -38
- package/dist/internal/domain/EditDiagnostic.js +0 -43
- package/dist/internal/events/event-bus.d.ts +0 -14
- package/dist/internal/events/event-bus.js +0 -21
- package/dist/internal/graph/graph-builder.d.ts +0 -12
- package/dist/internal/graph/graph-builder.js +0 -1371
- package/dist/internal/graph/import-resolver.d.ts +0 -31
- package/dist/internal/graph/import-resolver.js +0 -109
- package/dist/internal/graph/project-graph-builder.d.ts +0 -32
- package/dist/internal/graph/project-graph-builder.js +0 -133
- package/dist/internal/graph/types.d.ts +0 -114
- package/dist/internal/graph/types.js +0 -6
- package/dist/internal/history/undo-redo.d.ts +0 -28
- package/dist/internal/history/undo-redo.js +0 -42
- package/dist/internal/index.d.ts +0 -2
- package/dist/internal/index.js +0 -1
- package/dist/internal/planner/planner.d.ts +0 -104
- package/dist/internal/planner/planner.js +0 -2533
- package/dist/internal/planner/types.d.ts +0 -275
- package/dist/internal/planner/types.js +0 -6
- package/dist/internal/protocol/boundary.js +0 -3
- package/dist/internal/protocol/capability.js +0 -8
- package/dist/internal/protocol/error.js +0 -38
- package/dist/internal/protocol/event.js +0 -3
- package/dist/internal/protocol/identity.js +0 -30
- package/dist/internal/protocol/operation.js +0 -8
- package/dist/internal/protocol/render.js +0 -3
- package/dist/internal/protocol.js +0 -2
- package/dist/internal/provenance/binding-graph.d.ts +0 -39
- package/dist/internal/provenance/binding-graph.js +0 -184
- package/dist/internal/provenance/capability-policy.d.ts +0 -15
- package/dist/internal/provenance/capability-policy.js +0 -96
- package/dist/internal/provenance/data-source-classifier.d.ts +0 -14
- package/dist/internal/provenance/data-source-classifier.js +0 -281
- package/dist/internal/provenance/resolve-text-provenance.d.ts +0 -45
- package/dist/internal/provenance/resolve-text-provenance.js +0 -3090
- package/dist/internal/provenance/types.d.ts +0 -89
- package/dist/internal/provenance/types.js +0 -1
- package/dist/internal/render/component-semantic.d.ts +0 -11
- package/dist/internal/render/component-semantic.js +0 -141
- package/dist/internal/render/content-model.d.ts +0 -3
- package/dist/internal/render/content-model.js +0 -89
- package/dist/internal/render/media-model.d.ts +0 -3
- package/dist/internal/render/media-model.js +0 -45
- package/dist/internal/render/provenance-types.d.ts +0 -33
- package/dist/internal/render/provenance-types.js +0 -1
- package/dist/internal/render/render-projection.d.ts +0 -24
- package/dist/internal/render/render-projection.js +0 -281
- package/dist/internal/render/tailwind-style-model.d.ts +0 -19
- package/dist/internal/render/tailwind-style-model.js +0 -1187
- package/dist/internal/runtime/EditEngineRuntime.d.ts +0 -25
- package/dist/internal/runtime/EditEngineRuntime.js +0 -89
- package/dist/internal/runtime/EditEngineRuntimeSnapshot.d.ts +0 -31
- package/dist/internal/runtime/EditEngineRuntimeSnapshot.js +0 -15
- package/dist/internal/runtime/InternalEditEngine.d.ts +0 -44
- package/dist/internal/runtime/InternalEditEngine.js +0 -1391
- package/dist/internal/runtime.d.ts +0 -3
- package/dist/internal/runtime.js +0 -1
- package/dist/internal/topology/topology.d.ts +0 -6
- package/dist/internal/topology/topology.js +0 -98
- package/dist/internal/topology/types.d.ts +0 -35
- package/dist/internal/topology/types.js +0 -5
- package/dist/internal/types.d.ts +0 -1
- package/dist/internal/types.js +0 -1
- package/dist/internal/writeback/in-memory-fs.d.ts +0 -7
- package/dist/internal/writeback/in-memory-fs.js +0 -44
- package/dist/internal/writeback/types.d.ts +0 -45
- package/dist/internal/writeback/types.js +0 -7
- package/dist/internal/writeback/writeback-service.d.ts +0 -7
- package/dist/internal/writeback/writeback-service.js +0 -568
- package/dist/internal-adapter.d.ts +0 -18
- package/dist/internal-adapter.js +0 -350
- package/dist/next-app-router-fs.js +0 -64
- package/dist/preview-runtime.js +0 -102
- package/dist/public-file-system.js +0 -1
- package/dist/runtime-sync.js +0 -321
- package/dist/runtime.js +0 -134
- package/dist/site-edit-instrumentation.js +0 -322
- package/dist/snapshot-file-system.d.ts +0 -19
- package/dist/snapshot-file-system.js +0 -49
- package/dist/source-writeback-test-harness.d.ts +0 -244
- package/dist/source-writeback-test-harness.js +0 -119
- package/dist/types.js +0 -1
package/dist/runtime-sync.js
DELETED
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_SITE_EDIT_RUNTIME_READY_TIMEOUT_MS = 1500;
|
|
2
|
-
export const SITE_EDIT_RUNTIME_READY_POLL_INTERVAL_MS = 16;
|
|
3
|
-
export const SITE_EDIT_RUNTIME_ATTRIBUTES = {
|
|
4
|
-
key: "data-vcp-edit-key",
|
|
5
|
-
parentKey: "data-vcp-edit-parent-key",
|
|
6
|
-
movable: "data-vcp-movable",
|
|
7
|
-
removable: "data-vcp-removable",
|
|
8
|
-
flags: "data-vcp-flags",
|
|
9
|
-
};
|
|
10
|
-
const CONTAINER_TAGS = new Set([
|
|
11
|
-
"article",
|
|
12
|
-
"aside",
|
|
13
|
-
"div",
|
|
14
|
-
"footer",
|
|
15
|
-
"form",
|
|
16
|
-
"header",
|
|
17
|
-
"li",
|
|
18
|
-
"main",
|
|
19
|
-
"nav",
|
|
20
|
-
"ol",
|
|
21
|
-
"section",
|
|
22
|
-
"ul",
|
|
23
|
-
]);
|
|
24
|
-
const TEXT_TAGS = new Set([
|
|
25
|
-
"a",
|
|
26
|
-
"button",
|
|
27
|
-
"em",
|
|
28
|
-
"h1",
|
|
29
|
-
"h2",
|
|
30
|
-
"h3",
|
|
31
|
-
"h4",
|
|
32
|
-
"h5",
|
|
33
|
-
"h6",
|
|
34
|
-
"label",
|
|
35
|
-
"p",
|
|
36
|
-
"small",
|
|
37
|
-
"span",
|
|
38
|
-
"strong",
|
|
39
|
-
]);
|
|
40
|
-
const STRONG_SYNC_OPERATION_KINDS = new Set([
|
|
41
|
-
"update-text",
|
|
42
|
-
"remove-node",
|
|
43
|
-
"insert-child",
|
|
44
|
-
"move-node",
|
|
45
|
-
"replace-rich-text-content",
|
|
46
|
-
"insert-rich-text-block",
|
|
47
|
-
"remove-rich-text-block",
|
|
48
|
-
"set-media-field",
|
|
49
|
-
"set-component-slot-content",
|
|
50
|
-
"set-object-field",
|
|
51
|
-
"insert-object-field",
|
|
52
|
-
"remove-object-field",
|
|
53
|
-
"update-array-item",
|
|
54
|
-
"insert-array-item",
|
|
55
|
-
"remove-array-item",
|
|
56
|
-
"move-array-item",
|
|
57
|
-
"replace-conditional-expression",
|
|
58
|
-
"set-conditional-branch-content",
|
|
59
|
-
"set-jsx-prop",
|
|
60
|
-
"remove-jsx-prop",
|
|
61
|
-
"set-class-name",
|
|
62
|
-
"add-class-token",
|
|
63
|
-
"remove-class-token",
|
|
64
|
-
"set-style-property",
|
|
65
|
-
"set-style-properties",
|
|
66
|
-
"set-css-module-class",
|
|
67
|
-
]);
|
|
68
|
-
export function diffSiteEditRenderDocuments(previous_document, next_document) {
|
|
69
|
-
const previousEntries = new Map(previous_document.entries.map((entry) => [entry.key, entry]));
|
|
70
|
-
const nextEntries = new Map(next_document.entries.map((entry) => [entry.key, entry]));
|
|
71
|
-
const added_keys = next_document.entries
|
|
72
|
-
.map((entry) => entry.key)
|
|
73
|
-
.filter((key) => !previousEntries.has(key));
|
|
74
|
-
const removed_keys = previous_document.entries
|
|
75
|
-
.map((entry) => entry.key)
|
|
76
|
-
.filter((key) => !nextEntries.has(key));
|
|
77
|
-
const retained_keys = next_document.entries
|
|
78
|
-
.map((entry) => entry.key)
|
|
79
|
-
.filter((key) => previousEntries.has(key));
|
|
80
|
-
const changed_parentKeys = retained_keys.filter((key) => previousEntries.get(key)?.parentKey !== nextEntries.get(key)?.parentKey);
|
|
81
|
-
const changed_child_order_keys = retained_keys.filter((key) => {
|
|
82
|
-
const previousChildren = previousEntries.get(key)?.childKeys ?? [];
|
|
83
|
-
const nextChildren = nextEntries.get(key)?.childKeys ?? [];
|
|
84
|
-
return previousChildren.join("\u0000") !== nextChildren.join("\u0000");
|
|
85
|
-
});
|
|
86
|
-
return {
|
|
87
|
-
added_keys,
|
|
88
|
-
removed_keys,
|
|
89
|
-
retained_keys,
|
|
90
|
-
changed_parentKeys,
|
|
91
|
-
changed_child_order_keys,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
export function isSiteEditRuntimeSyncedOperation(kind) {
|
|
95
|
-
return STRONG_SYNC_OPERATION_KINDS.has(kind);
|
|
96
|
-
}
|
|
97
|
-
export class SiteEditRuntimeDomAdapter {
|
|
98
|
-
constructor(documentLike, attributes = SITE_EDIT_RUNTIME_ATTRIBUTES) {
|
|
99
|
-
this.documentLike = documentLike;
|
|
100
|
-
this.attributes = attributes;
|
|
101
|
-
}
|
|
102
|
-
getKeyFromElement(element) {
|
|
103
|
-
return element.getAttribute(this.attributes.key);
|
|
104
|
-
}
|
|
105
|
-
findEditableElement(element) {
|
|
106
|
-
return element?.closest(`[${this.attributes.key}]`) ?? null;
|
|
107
|
-
}
|
|
108
|
-
findElementByKey(key) {
|
|
109
|
-
return (this.documentLike?.querySelector(`[${this.attributes.key}="${escapeAttributeValue(key)}"]`) ?? null);
|
|
110
|
-
}
|
|
111
|
-
findElementByRef(ref) {
|
|
112
|
-
if (typeof ref.instance_index !== "number" ||
|
|
113
|
-
typeof ref.instance_count !== "number" ||
|
|
114
|
-
ref.instance_count <= 1 ||
|
|
115
|
-
!this.documentLike?.querySelectorAll) {
|
|
116
|
-
return this.findElementByKey(ref.key);
|
|
117
|
-
}
|
|
118
|
-
const matches = Array.from(this.documentLike.querySelectorAll(`[${this.attributes.key}]`)).filter((item) => item.getAttribute(this.attributes.key) === ref.key);
|
|
119
|
-
return matches[ref.instance_index] ?? null;
|
|
120
|
-
}
|
|
121
|
-
snapshot(element) {
|
|
122
|
-
const attributes = Object.fromEntries(element
|
|
123
|
-
.getAttributeNames()
|
|
124
|
-
.map((name) => [name, element.getAttribute(name) ?? ""]));
|
|
125
|
-
const key = element.getAttribute(this.attributes.key) ?? "";
|
|
126
|
-
const tagName = element.tagName.toLowerCase();
|
|
127
|
-
const textPreview = element.textContent?.trim().slice(0, 80);
|
|
128
|
-
const snapshot = {
|
|
129
|
-
key,
|
|
130
|
-
tag_name: tagName,
|
|
131
|
-
attributes,
|
|
132
|
-
runtime_flags: {
|
|
133
|
-
editable: true,
|
|
134
|
-
movable: element.getAttribute(this.attributes.movable) !== "false",
|
|
135
|
-
removable: element.getAttribute(this.attributes.removable) !== "false",
|
|
136
|
-
text_editable: TEXT_TAGS.has(tagName),
|
|
137
|
-
container: CONTAINER_TAGS.has(tagName),
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
const instancePosition = this.resolveInstancePosition(element, key);
|
|
141
|
-
if (instancePosition) {
|
|
142
|
-
snapshot.instance_index = instancePosition.index;
|
|
143
|
-
snapshot.instance_count = instancePosition.count;
|
|
144
|
-
}
|
|
145
|
-
if (textPreview !== undefined) {
|
|
146
|
-
snapshot.text_preview = textPreview;
|
|
147
|
-
}
|
|
148
|
-
return snapshot;
|
|
149
|
-
}
|
|
150
|
-
resolveInstancePosition(element, key) {
|
|
151
|
-
if (!key || !this.documentLike?.querySelectorAll) {
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
const matches = Array.from(this.documentLike.querySelectorAll(`[${this.attributes.key}]`)).filter((item) => item.getAttribute(this.attributes.key) === key);
|
|
155
|
-
if (matches.length <= 1) {
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
const index = matches.indexOf(element);
|
|
159
|
-
if (index < 0) {
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
return {
|
|
163
|
-
count: matches.length,
|
|
164
|
-
index,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
export class SiteEditRuntimeReadyProbe {
|
|
169
|
-
constructor(documentLike, attributes = SITE_EDIT_RUNTIME_ATTRIBUTES) {
|
|
170
|
-
this.dom = new SiteEditRuntimeDomAdapter(documentLike, attributes);
|
|
171
|
-
}
|
|
172
|
-
probe(input, diff = diffSiteEditRenderDocuments(input.previous_document, input.next_document)) {
|
|
173
|
-
const rootKeys = input.next_document.rootKeys.length > 0
|
|
174
|
-
? input.next_document.rootKeys
|
|
175
|
-
: input.next_document.entries.slice(0, 1).map((entry) => entry.key);
|
|
176
|
-
const missingRoot = rootKeys.find((key) => !this.dom.findElementByKey(key));
|
|
177
|
-
if (missingRoot) {
|
|
178
|
-
return failure(input, "missing-root", "document-root", `preview root is missing: ${missingRoot}`);
|
|
179
|
-
}
|
|
180
|
-
if (input.selected_key &&
|
|
181
|
-
hasDocumentKey(input.next_document, input.selected_key) &&
|
|
182
|
-
!this.dom.findElementByKey(input.selected_key)) {
|
|
183
|
-
return failure(input, "missing-selected-key", "selected-node", `selected node is missing from preview DOM: ${input.selected_key}`);
|
|
184
|
-
}
|
|
185
|
-
const kind = input.request?.kind ?? input.result.kind;
|
|
186
|
-
if (!isSiteEditRuntimeSyncedOperation(kind)) {
|
|
187
|
-
return failure(input, "unsupported-operation", "operation-specific", `runtime ready check is not implemented for ${kind}`);
|
|
188
|
-
}
|
|
189
|
-
return this.checkOperationProjection(input, diff);
|
|
190
|
-
}
|
|
191
|
-
checkOperationProjection(input, diff) {
|
|
192
|
-
const kind = input.request?.kind ?? input.result.kind;
|
|
193
|
-
const targetKey = getNodeTargetKey(input.request) ?? getNodeTargetKey(input.result);
|
|
194
|
-
if (kind === "update-text" &&
|
|
195
|
-
input.request?.params.kind === "update-text") {
|
|
196
|
-
return this.checkTextProjection(input, targetKey);
|
|
197
|
-
}
|
|
198
|
-
if (kind === "remove-node" &&
|
|
199
|
-
targetKey &&
|
|
200
|
-
!hasDocumentKey(input.next_document, targetKey)) {
|
|
201
|
-
if (this.dom.findElementByKey(targetKey)) {
|
|
202
|
-
return failure(input, "removed-target-still-present", "removed-node", `removed node is still present in preview DOM: ${targetKey}`);
|
|
203
|
-
}
|
|
204
|
-
return this.checkGenericDiffProjection(input, diff, "removed-node");
|
|
205
|
-
}
|
|
206
|
-
if (kind === "insert-child") {
|
|
207
|
-
const addedResult = this.checkAddedKeys(input, diff, "inserted-node");
|
|
208
|
-
return addedResult.ok
|
|
209
|
-
? this.checkGenericDiffProjection(input, diff, "inserted-node")
|
|
210
|
-
: addedResult;
|
|
211
|
-
}
|
|
212
|
-
if (kind === "move-node") {
|
|
213
|
-
return this.checkMovedNodeProjection(input, diff, targetKey);
|
|
214
|
-
}
|
|
215
|
-
return this.checkGenericDiffProjection(input, diff, "document-diff");
|
|
216
|
-
}
|
|
217
|
-
checkTextProjection(input, targetKey) {
|
|
218
|
-
if (!targetKey) {
|
|
219
|
-
return failure(input, "missing-target", "text-content", "update-text target key is missing");
|
|
220
|
-
}
|
|
221
|
-
const target = this.dom.findElementByKey(targetKey);
|
|
222
|
-
if (!target) {
|
|
223
|
-
return failure(input, "missing-target", "text-content", `update-text target is missing: ${targetKey}`);
|
|
224
|
-
}
|
|
225
|
-
const actualText = normalizeText(target.textContent ?? "");
|
|
226
|
-
const params = input.request?.params;
|
|
227
|
-
const expectedText = normalizeText(params?.kind === "update-text" ? params.value : "");
|
|
228
|
-
if (actualText !== expectedText) {
|
|
229
|
-
return failure(input, "text-mismatch", "text-content", `preview text has not updated for ${targetKey}`);
|
|
230
|
-
}
|
|
231
|
-
return success(input, "text-content", [targetKey]);
|
|
232
|
-
}
|
|
233
|
-
checkMovedNodeProjection(input, diff, targetKey) {
|
|
234
|
-
if (targetKey && !this.dom.findElementByKey(targetKey)) {
|
|
235
|
-
return failure(input, "missing-target", "moved-node", `moved node is missing: ${targetKey}`);
|
|
236
|
-
}
|
|
237
|
-
for (const parentKey of diff.changed_child_order_keys) {
|
|
238
|
-
const parent = input.next_document.entries.find((entry) => entry.key === parentKey);
|
|
239
|
-
if (!parent || !this.isChildOrderReady(parent.childKeys)) {
|
|
240
|
-
return failure(input, "order-mismatch", "child-order", `child order is not ready for ${parentKey}`);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return this.checkGenericDiffProjection(input, diff, "moved-node");
|
|
244
|
-
}
|
|
245
|
-
checkGenericDiffProjection(input, diff, check) {
|
|
246
|
-
const addedResult = this.checkAddedKeys(input, diff, check);
|
|
247
|
-
if (!addedResult.ok) {
|
|
248
|
-
return addedResult;
|
|
249
|
-
}
|
|
250
|
-
const presentRemovedKey = diff.removed_keys.find((key) => this.dom.findElementByKey(key));
|
|
251
|
-
if (presentRemovedKey) {
|
|
252
|
-
return failure(input, "removed-target-still-present", check, `removed node is still present in preview DOM: ${presentRemovedKey}`);
|
|
253
|
-
}
|
|
254
|
-
return success(input, check, [
|
|
255
|
-
...input.next_document.rootKeys,
|
|
256
|
-
...diff.added_keys,
|
|
257
|
-
...diff.changed_parentKeys,
|
|
258
|
-
...diff.changed_child_order_keys,
|
|
259
|
-
]);
|
|
260
|
-
}
|
|
261
|
-
checkAddedKeys(input, diff, check) {
|
|
262
|
-
const missingAddedKey = diff.added_keys.find((key) => !this.dom.findElementByKey(key));
|
|
263
|
-
if (missingAddedKey) {
|
|
264
|
-
return failure(input, "missing-added-key", check, `added node is missing from preview DOM: ${missingAddedKey}`);
|
|
265
|
-
}
|
|
266
|
-
return success(input, check, diff.added_keys);
|
|
267
|
-
}
|
|
268
|
-
isChildOrderReady(childKeys) {
|
|
269
|
-
const elements = childKeys
|
|
270
|
-
.map((key) => this.dom.findElementByKey(key))
|
|
271
|
-
.filter((element) => Boolean(element));
|
|
272
|
-
if (elements.length < 2) {
|
|
273
|
-
return elements.length === childKeys.length;
|
|
274
|
-
}
|
|
275
|
-
for (let index = 1; index < elements.length; index += 1) {
|
|
276
|
-
const previous = elements[index - 1];
|
|
277
|
-
const current = elements[index];
|
|
278
|
-
if (previous &&
|
|
279
|
-
current &&
|
|
280
|
-
(previous.compareDocumentPosition(current) & 4) === 0) {
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return elements.length === childKeys.length;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
export function getSiteEditNodeTargetKey(input) {
|
|
288
|
-
return getNodeTargetKey(input);
|
|
289
|
-
}
|
|
290
|
-
export function hasSiteEditDocumentKey(document, key) {
|
|
291
|
-
return hasDocumentKey(document, key);
|
|
292
|
-
}
|
|
293
|
-
function getNodeTargetKey(input) {
|
|
294
|
-
return input?.target.kind === "node" ? input.target.key : null;
|
|
295
|
-
}
|
|
296
|
-
function hasDocumentKey(document, key) {
|
|
297
|
-
return document.entries.some((entry) => entry.key === key);
|
|
298
|
-
}
|
|
299
|
-
function normalizeText(value) {
|
|
300
|
-
return value.replace(/\s+/g, " ").trim();
|
|
301
|
-
}
|
|
302
|
-
function success(input, check, observed_keys) {
|
|
303
|
-
return {
|
|
304
|
-
ok: true,
|
|
305
|
-
version: input.next_document.version,
|
|
306
|
-
observed_keys: [...new Set(observed_keys.filter(Boolean))],
|
|
307
|
-
check,
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
function failure(input, reason, check, message) {
|
|
311
|
-
return {
|
|
312
|
-
ok: false,
|
|
313
|
-
version: input.next_document.version,
|
|
314
|
-
reason,
|
|
315
|
-
check,
|
|
316
|
-
message,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
function escapeAttributeValue(value) {
|
|
320
|
-
return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
321
|
-
}
|
package/dist/runtime.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { SiteEditPatchPlanSchema } from "@trojanbox-vcp-test/contracts";
|
|
2
|
-
import { toInternalOperationRequest, toSiteEditEvent, toSiteEditObjectContentDetail, toSiteEditObjectDetail, toSiteEditObjectEditContext, toSiteEditObjectMediaDetail, toSiteEditObjectStyleDetail, toSiteEditObjectSummary, toSiteEditOperationResult, toSiteEditRenderDocument, } from "./internal-adapter.js";
|
|
3
|
-
import { createInternalEditEngine } from "./internal/runtime/InternalEditEngine.js";
|
|
4
|
-
import { sha256ContentHash, SnapshotFileSystem, } from "./snapshot-file-system.js";
|
|
5
|
-
export class SnapshotSiteEditEngineRuntime {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
this.options = options;
|
|
8
|
-
this.fileSystem = new SnapshotFileSystem(options.files);
|
|
9
|
-
this.engine = this.createEngine(this.fileSystem);
|
|
10
|
-
}
|
|
11
|
-
get status() {
|
|
12
|
-
return this.engine.status;
|
|
13
|
-
}
|
|
14
|
-
async setActiveRoute(routeId) {
|
|
15
|
-
await this.engine.setActiveRoute(routeId);
|
|
16
|
-
}
|
|
17
|
-
getDocument(routeId) {
|
|
18
|
-
return toSiteEditRenderDocument(this.engine.getDocument(routeId), {
|
|
19
|
-
siteId: this.options.siteId,
|
|
20
|
-
snapshotId: this.options.snapshotId,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
getObjectCapabilities(key, routeId) {
|
|
24
|
-
const detail = toSiteEditObjectDetail(this.engine.getRenderDetail(key, routeId));
|
|
25
|
-
return {
|
|
26
|
-
key: detail.key,
|
|
27
|
-
canUpdateText: detail.capabilities.canUpdateText,
|
|
28
|
-
canInsertChild: detail.capabilities.canInsertChild,
|
|
29
|
-
canMove: detail.capabilities.canMove,
|
|
30
|
-
canRemove: detail.capabilities.canRemove,
|
|
31
|
-
boundaryKind: detail.boundaryKind,
|
|
32
|
-
isOpaque: detail.isOpaque,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
getObjectSummary(key, routeId) {
|
|
36
|
-
return toSiteEditObjectSummary(this.engine.getRenderDetail(key, routeId));
|
|
37
|
-
}
|
|
38
|
-
getObjectEditContext(key, routeId) {
|
|
39
|
-
return toSiteEditObjectEditContext(this.engine.getRenderDetail(key, routeId));
|
|
40
|
-
}
|
|
41
|
-
getObjectStyleDetail(key, routeId) {
|
|
42
|
-
return toSiteEditObjectStyleDetail(this.engine.getRenderDetail(key, routeId));
|
|
43
|
-
}
|
|
44
|
-
getObjectContentDetail(key, routeId) {
|
|
45
|
-
return toSiteEditObjectContentDetail(this.engine.getRenderDetail(key, routeId));
|
|
46
|
-
}
|
|
47
|
-
getObjectMediaDetail(key, routeId) {
|
|
48
|
-
return toSiteEditObjectMediaDetail(this.engine.getRenderDetail(key, routeId));
|
|
49
|
-
}
|
|
50
|
-
getClassNameSource(key, routeId) {
|
|
51
|
-
return this.engine.getClassNameSource(key, routeId);
|
|
52
|
-
}
|
|
53
|
-
setClassNameSource(request) {
|
|
54
|
-
return this.engine.setClassNameSource(request);
|
|
55
|
-
}
|
|
56
|
-
async planOperation(request) {
|
|
57
|
-
const scratchFileSystem = new SnapshotFileSystem(this.options.files);
|
|
58
|
-
const scratchEngine = this.createEngine(scratchFileSystem);
|
|
59
|
-
for (const route of this.options.routes) {
|
|
60
|
-
await scratchEngine.setActiveRoute(route.routeId);
|
|
61
|
-
}
|
|
62
|
-
const result = toSiteEditOperationResult(await scratchEngine.execute(toInternalOperationRequest(request)));
|
|
63
|
-
if (!result.ok) {
|
|
64
|
-
return { result };
|
|
65
|
-
}
|
|
66
|
-
const changedFiles = scratchFileSystem.getChangedFiles();
|
|
67
|
-
if (changedFiles.length === 0) {
|
|
68
|
-
return { result };
|
|
69
|
-
}
|
|
70
|
-
const patchPlan = SiteEditPatchPlanSchema.parse({
|
|
71
|
-
siteId: request.siteId,
|
|
72
|
-
baseSnapshotId: request.baseSnapshotId,
|
|
73
|
-
operationId: request.id,
|
|
74
|
-
reason: `site-edit:${request.kind}`,
|
|
75
|
-
patches: changedFiles.map((file) => ({
|
|
76
|
-
path: file.path,
|
|
77
|
-
operation: file.before === undefined ? "create" : "update",
|
|
78
|
-
expectedHash: file.before === undefined
|
|
79
|
-
? undefined
|
|
80
|
-
: sha256ContentHash(file.before),
|
|
81
|
-
fullContent: file.after,
|
|
82
|
-
})),
|
|
83
|
-
changedRouteIds: this.getChangedRouteIds(changedFiles.map((file) => file.path)),
|
|
84
|
-
diagnostics: [],
|
|
85
|
-
});
|
|
86
|
-
this.options.onEvent?.({
|
|
87
|
-
type: "site-edit.operation.planned",
|
|
88
|
-
siteId: request.siteId,
|
|
89
|
-
operationId: request.id,
|
|
90
|
-
baseSnapshotId: request.baseSnapshotId,
|
|
91
|
-
changedFiles: patchPlan.patches.map((patch) => patch.path),
|
|
92
|
-
at: new Date().toISOString(),
|
|
93
|
-
});
|
|
94
|
-
return { result, patchPlan };
|
|
95
|
-
}
|
|
96
|
-
dispose() {
|
|
97
|
-
this.engine.dispose();
|
|
98
|
-
}
|
|
99
|
-
createEngine(fileSystem) {
|
|
100
|
-
return createInternalEditEngine({
|
|
101
|
-
projectRoot: "/snapshot",
|
|
102
|
-
fileSystem,
|
|
103
|
-
routes: this.options.routes.map((route) => ({
|
|
104
|
-
routeId: route.routeId,
|
|
105
|
-
entryFile: route.entryFile,
|
|
106
|
-
})),
|
|
107
|
-
onEvent: this.options.onEvent
|
|
108
|
-
? (event) => {
|
|
109
|
-
const siteEditEvent = toSiteEditEvent(event, {
|
|
110
|
-
siteId: this.options.siteId,
|
|
111
|
-
snapshotId: this.options.snapshotId,
|
|
112
|
-
});
|
|
113
|
-
if (siteEditEvent) {
|
|
114
|
-
this.options.onEvent?.(siteEditEvent);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
: undefined,
|
|
118
|
-
dev: this.options.dev,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
getChangedRouteIds(changedPaths) {
|
|
122
|
-
const changedPathSet = new Set(changedPaths);
|
|
123
|
-
const directlyChangedRoutes = this.options.routes
|
|
124
|
-
.filter((route) => changedPathSet.has(route.entryFile))
|
|
125
|
-
.map((route) => route.routeId);
|
|
126
|
-
if (directlyChangedRoutes.length > 0) {
|
|
127
|
-
return directlyChangedRoutes;
|
|
128
|
-
}
|
|
129
|
-
return this.options.routes.map((route) => route.routeId);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
export function createSiteEditEngineRuntime(options) {
|
|
133
|
-
return new SnapshotSiteEditEngineRuntime(options);
|
|
134
|
-
}
|