@kubohiroya/turbowarp-extension-data-editor 0.2.0 → 0.2.2
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 +9 -6
- package/dist/build-info.json +3 -3
- package/dist/fixed-input-branches.d.ts +12 -0
- package/dist/fixed-input-branches.js +180 -0
- package/dist/fixed-input-editor.d.ts +39 -0
- package/dist/fixed-input-editor.js +538 -0
- package/dist/fixed-input-schema.d.ts +15 -0
- package/dist/fixed-input-schema.js +21 -0
- package/dist/fixed-input-snapshot.d.ts +7 -0
- package/dist/fixed-input-snapshot.js +180 -0
- package/dist/fixed-input-types.d.ts +138 -0
- package/dist/fixed-input-types.js +23 -0
- package/dist/fixed-input-view.d.ts +14 -0
- package/dist/fixed-input-view.js +168 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/react.css +168 -0
- package/dist/react.d.ts +8 -0
- package/dist/react.js +19 -2
- package/dist/registry.d.ts +4 -0
- package/dist/registry.js +45 -7
- package/dist/rjsf-templates.d.ts +11 -0
- package/dist/rjsf-templates.js +129 -0
- package/dist/rjsf.d.ts +24 -1
- package/dist/rjsf.js +35 -3
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +1 -0
- package/dist/session.d.ts +3 -1
- package/dist/session.js +205 -7
- package/dist/turbowarp/bridge.d.ts +2 -1
- package/dist/turbowarp/bridge.js +37 -5
- package/dist/turbowarp/fixed-fields.d.ts +82 -0
- package/dist/turbowarp/fixed-fields.js +311 -0
- package/dist/turbowarp/fixed-transaction.d.ts +18 -0
- package/dist/turbowarp/fixed-transaction.js +460 -0
- package/dist/turbowarp/host.d.ts +3 -8
- package/dist/turbowarp/host.js +68 -1
- package/dist/turbowarp.d.ts +4 -0
- package/dist/turbowarp.js +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/view.js +4 -0
- package/dist/webpack4/index.js +22 -5
- package/dist/webpack4/metafile.json +592 -299
- package/dist/webpack4/react.js +20 -6
- package/dist/webpack4/react.js.map +2 -2
- package/dist/webpack4/rjsf.js +450 -60
- package/dist/webpack4/rjsf.js.map +4 -4
- package/dist/webpack4/schema.js +6 -3
- package/dist/webpack4/{shared-KQOUMWJ4.js → shared-75QIWLZY.js} +1129 -1244
- package/dist/webpack4/{shared-KQOUMWJ4.js.map → shared-75QIWLZY.js.map} +4 -4
- package/dist/webpack4/shared-FYUILHED.js +1 -0
- package/dist/webpack4/shared-GQLPPRT2.js +210 -0
- package/dist/webpack4/shared-GQLPPRT2.js.map +7 -0
- package/dist/webpack4/shared-P2JBRZFP.js +2206 -0
- package/dist/webpack4/shared-P2JBRZFP.js.map +7 -0
- package/dist/webpack4/turbowarp.js +913 -9
- package/dist/webpack4/turbowarp.js.map +4 -4
- package/docs/api.md +7 -0
- package/docs/fixed-input-contracts.md +77 -0
- package/docs/package-distribution.md +5 -0
- package/docs/stage-2-publication.ja.md +6 -0
- package/package.json +2 -1
- package/dist/webpack4/shared-CQB3NG2A.js +0 -1
- package/dist/webpack4/shared-MRPGBJIH.js +0 -75
- package/dist/webpack4/shared-MRPGBJIH.js.map +0 -7
- package/dist/webpack4/shared-N6YQE2X6.js +0 -1029
- package/dist/webpack4/shared-N6YQE2X6.js.map +0 -7
- /package/dist/webpack4/{shared-CQB3NG2A.js.map → shared-FYUILHED.js.map} +0 -0
|
@@ -1,1029 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BlockEditorConflictError,
|
|
3
|
-
BlockEditorStructureError,
|
|
4
|
-
DEFAULT_DESCENDANT_LIMITS,
|
|
5
|
-
DescendantNodeError,
|
|
6
|
-
EDITOR_API_VERSION,
|
|
7
|
-
supportsDescendantEditing
|
|
8
|
-
} from "./shared-BKTRZUZH.js";
|
|
9
|
-
import {
|
|
10
|
-
snapshotJson
|
|
11
|
-
} from "./shared-MRPGBJIH.js";
|
|
12
|
-
|
|
13
|
-
// dist/data.js
|
|
14
|
-
function isLiteral(value) {
|
|
15
|
-
return typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
|
|
16
|
-
}
|
|
17
|
-
function cloneJson(value) {
|
|
18
|
-
const ancestors = /* @__PURE__ */ new Set();
|
|
19
|
-
const visit = (item, depth) => {
|
|
20
|
-
if (depth > 100)
|
|
21
|
-
throw new TypeError("JSON data exceeds the maximum depth.");
|
|
22
|
-
if (item === null || isLiteral(item))
|
|
23
|
-
return item;
|
|
24
|
-
if (typeof item !== "object")
|
|
25
|
-
throw new TypeError("Expected JSON-compatible data.");
|
|
26
|
-
if (ancestors.has(item))
|
|
27
|
-
throw new TypeError("JSON data must not contain cycles.");
|
|
28
|
-
ancestors.add(item);
|
|
29
|
-
try {
|
|
30
|
-
if (Array.isArray(item))
|
|
31
|
-
return Array.from(item, (child) => visit(child, depth + 1));
|
|
32
|
-
const prototype = Object.getPrototypeOf(item);
|
|
33
|
-
if (prototype !== Object.prototype && prototype !== null) {
|
|
34
|
-
throw new TypeError("JSON objects must be plain objects.");
|
|
35
|
-
}
|
|
36
|
-
if (Object.getOwnPropertySymbols(item).length > 0) {
|
|
37
|
-
throw new TypeError("JSON objects must not have symbol properties.");
|
|
38
|
-
}
|
|
39
|
-
return Object.fromEntries(Object.entries(item).map(([key, child]) => [key, visit(child, depth + 1)]));
|
|
40
|
-
} finally {
|
|
41
|
-
ancestors.delete(item);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
return visit(value, 0);
|
|
45
|
-
}
|
|
46
|
-
function captureReference(reference) {
|
|
47
|
-
if (!reference || typeof reference.targetId !== "string" || !reference.targetId || typeof reference.blockId !== "string" || !reference.blockId) {
|
|
48
|
-
throw new TypeError("A target ID and block ID are required.");
|
|
49
|
-
}
|
|
50
|
-
return Object.freeze({ targetId: reference.targetId, blockId: reference.blockId });
|
|
51
|
-
}
|
|
52
|
-
function captureSnapshot(snapshot, reference) {
|
|
53
|
-
if (snapshot.targetId !== reference.targetId || snapshot.blockId !== reference.blockId || typeof snapshot.opcode !== "string" || !snapshot.opcode || typeof snapshot.revision !== "string" || !snapshot.revision || !snapshot.arguments || typeof snapshot.arguments !== "object" || Array.isArray(snapshot.arguments)) {
|
|
54
|
-
throw new TypeError("The host returned an invalid block snapshot.");
|
|
55
|
-
}
|
|
56
|
-
const entries = Object.entries(snapshot.arguments).map(([name, slot]) => {
|
|
57
|
-
if (!slot || slot.kind !== "reporter" && slot.kind !== "literal" || slot.kind === "literal" && !isLiteral(slot.value)) {
|
|
58
|
-
throw new TypeError(`Invalid argument slot: ${name}`);
|
|
59
|
-
}
|
|
60
|
-
const copy = slot.kind === "reporter" ? Object.freeze({ kind: "reporter" }) : Object.freeze({ kind: "literal", value: slot.value });
|
|
61
|
-
return [name, copy];
|
|
62
|
-
});
|
|
63
|
-
return Object.freeze({
|
|
64
|
-
...captureReference(reference),
|
|
65
|
-
opcode: snapshot.opcode,
|
|
66
|
-
revision: snapshot.revision,
|
|
67
|
-
arguments: Object.freeze(Object.fromEntries(entries))
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
function sameSnapshot(left, right) {
|
|
71
|
-
const names = Object.keys(left.arguments);
|
|
72
|
-
return left.targetId === right.targetId && left.blockId === right.blockId && left.opcode === right.opcode && left.revision === right.revision && names.length === Object.keys(right.arguments).length && names.every((name) => {
|
|
73
|
-
const a = left.arguments[name];
|
|
74
|
-
const b = Object.hasOwn(right.arguments, name) ? right.arguments[name] : void 0;
|
|
75
|
-
return b !== void 0 && a.kind === b.kind && (a.kind === "reporter" || b.kind === "literal" && a.value === b.value);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// dist/view.js
|
|
80
|
-
var __classPrivateFieldGet = function(receiver, state, kind, f) {
|
|
81
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
82
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
83
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
84
|
-
};
|
|
85
|
-
var __classPrivateFieldSet = function(receiver, state, value, kind, f) {
|
|
86
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
87
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
88
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
89
|
-
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
90
|
-
};
|
|
91
|
-
var _EditorView_unmount;
|
|
92
|
-
var _EditorView_mounting;
|
|
93
|
-
var EditorView = class {
|
|
94
|
-
constructor() {
|
|
95
|
-
_EditorView_unmount.set(this, void 0);
|
|
96
|
-
_EditorView_mounting.set(this, false);
|
|
97
|
-
}
|
|
98
|
-
mount(container, mount, owner) {
|
|
99
|
-
if (owner.getState().status !== "editing" || __classPrivateFieldGet(this, _EditorView_unmount, "f") || __classPrivateFieldGet(this, _EditorView_mounting, "f")) {
|
|
100
|
-
throw new Error("The session cannot mount another view.");
|
|
101
|
-
}
|
|
102
|
-
if (!mount)
|
|
103
|
-
throw new Error("No editor view is registered.");
|
|
104
|
-
let active = true;
|
|
105
|
-
const subscriptions = /* @__PURE__ */ new Set();
|
|
106
|
-
const assertMounted = () => {
|
|
107
|
-
if (!active)
|
|
108
|
-
throw new Error("The editor view is unmounted.");
|
|
109
|
-
};
|
|
110
|
-
const release = () => {
|
|
111
|
-
active = false;
|
|
112
|
-
for (const unsubscribe of subscriptions)
|
|
113
|
-
unsubscribe();
|
|
114
|
-
subscriptions.clear();
|
|
115
|
-
};
|
|
116
|
-
const context = Object.freeze({
|
|
117
|
-
getDraft: () => owner.getDraft(),
|
|
118
|
-
setDraft: (draft) => {
|
|
119
|
-
assertMounted();
|
|
120
|
-
owner.setDraft(draft);
|
|
121
|
-
},
|
|
122
|
-
setValidationIssues: (issues) => {
|
|
123
|
-
assertMounted();
|
|
124
|
-
owner.setValidationIssues(issues);
|
|
125
|
-
},
|
|
126
|
-
getState: () => owner.getState(),
|
|
127
|
-
subscribe: (listener) => {
|
|
128
|
-
assertMounted();
|
|
129
|
-
const unsubscribe = owner.subscribe(() => {
|
|
130
|
-
if (active)
|
|
131
|
-
listener();
|
|
132
|
-
});
|
|
133
|
-
const remove = () => {
|
|
134
|
-
subscriptions.delete(remove);
|
|
135
|
-
unsubscribe();
|
|
136
|
-
};
|
|
137
|
-
subscriptions.add(remove);
|
|
138
|
-
return remove;
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
__classPrivateFieldSet(this, _EditorView_mounting, true, "f");
|
|
142
|
-
let cleanup;
|
|
143
|
-
try {
|
|
144
|
-
cleanup = mount(container, context);
|
|
145
|
-
if (typeof cleanup !== "function")
|
|
146
|
-
throw new TypeError("mount() must return a cleanup function.");
|
|
147
|
-
} catch (error) {
|
|
148
|
-
release();
|
|
149
|
-
throw error;
|
|
150
|
-
} finally {
|
|
151
|
-
__classPrivateFieldSet(this, _EditorView_mounting, false, "f");
|
|
152
|
-
}
|
|
153
|
-
if (owner.getState().status !== "editing" && owner.getState().status !== "saving") {
|
|
154
|
-
release();
|
|
155
|
-
cleanup();
|
|
156
|
-
return () => {
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
const unmount = () => {
|
|
160
|
-
if (!active)
|
|
161
|
-
return;
|
|
162
|
-
release();
|
|
163
|
-
__classPrivateFieldSet(this, _EditorView_unmount, void 0, "f");
|
|
164
|
-
cleanup();
|
|
165
|
-
};
|
|
166
|
-
__classPrivateFieldSet(this, _EditorView_unmount, unmount, "f");
|
|
167
|
-
return unmount;
|
|
168
|
-
}
|
|
169
|
-
unmount() {
|
|
170
|
-
var _a;
|
|
171
|
-
(_a = __classPrivateFieldGet(this, _EditorView_unmount, "f")) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
_EditorView_unmount = /* @__PURE__ */ new WeakMap(), _EditorView_mounting = /* @__PURE__ */ new WeakMap();
|
|
175
|
-
|
|
176
|
-
// dist/prepared-save.js
|
|
177
|
-
function isPreparedEditor(definition) {
|
|
178
|
-
return definition.saveContract === "prepared-source-v1";
|
|
179
|
-
}
|
|
180
|
-
function capturePreparedSave(definition, draft, snapshot) {
|
|
181
|
-
const output = definition.prepareSave(draft, snapshot);
|
|
182
|
-
try {
|
|
183
|
-
const value = snapshotJson(output);
|
|
184
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
185
|
-
throw new TypeError("Invalid prepared save.");
|
|
186
|
-
const result = value;
|
|
187
|
-
if (result.kind === "ready" && Array.isArray(result.changes)) {
|
|
188
|
-
const changes = [];
|
|
189
|
-
for (let i = 0; i < result.changes.length; i++) {
|
|
190
|
-
const change = result.changes[i];
|
|
191
|
-
if (!change || typeof change.argument !== "string" || !(typeof change.value === "string" || typeof change.value === "boolean" || typeof change.value === "number" && Number.isFinite(change.value))) {
|
|
192
|
-
throw new TypeError("Invalid prepared change.");
|
|
193
|
-
}
|
|
194
|
-
changes.push(Object.freeze({ argument: change.argument, value: change.value }));
|
|
195
|
-
}
|
|
196
|
-
return Object.freeze({ kind: "ready", changes: Object.freeze(changes) });
|
|
197
|
-
}
|
|
198
|
-
if (result.kind === "invalid" && Array.isArray(result.issues) && result.issues.length > 0) {
|
|
199
|
-
const issues = [];
|
|
200
|
-
for (let i = 0; i < result.issues.length; i++) {
|
|
201
|
-
const issue = result.issues[i];
|
|
202
|
-
if (!issue || typeof issue.message !== "string" || issue.path !== void 0 && typeof issue.path !== "string") {
|
|
203
|
-
throw new TypeError("Invalid prepared issue.");
|
|
204
|
-
}
|
|
205
|
-
issues.push(Object.freeze({ message: issue.message, ...issue.path === void 0 ? {} : { path: issue.path } }));
|
|
206
|
-
}
|
|
207
|
-
return Object.freeze({ kind: "invalid", issues: Object.freeze(issues) });
|
|
208
|
-
}
|
|
209
|
-
throw new TypeError("Invalid prepared save.");
|
|
210
|
-
} catch (error) {
|
|
211
|
-
try {
|
|
212
|
-
void Promise.prototype.then.call(output, () => void 0, () => void 0);
|
|
213
|
-
} catch (_a) {
|
|
214
|
-
}
|
|
215
|
-
throw error;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// dist/session.js
|
|
220
|
-
var __classPrivateFieldSet2 = function(receiver, state, value, kind, f) {
|
|
221
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
222
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
223
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
224
|
-
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
225
|
-
};
|
|
226
|
-
var __classPrivateFieldGet2 = function(receiver, state, kind, f) {
|
|
227
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
228
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
229
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
230
|
-
};
|
|
231
|
-
var _EditorSession_instances;
|
|
232
|
-
var _EditorSession_draft;
|
|
233
|
-
var _EditorSession_status;
|
|
234
|
-
var _EditorSession_issues;
|
|
235
|
-
var _EditorSession_error;
|
|
236
|
-
var _EditorSession_listeners;
|
|
237
|
-
var _EditorSession_view;
|
|
238
|
-
var _EditorSession_definition;
|
|
239
|
-
var _EditorSession_snapshot;
|
|
240
|
-
var _EditorSession_host;
|
|
241
|
-
var _EditorSession_isRegistered;
|
|
242
|
-
var _EditorSession_prepareChanges;
|
|
243
|
-
var _EditorSession_copyIssues;
|
|
244
|
-
var _EditorSession_copyDraft;
|
|
245
|
-
var _EditorSession_assertOpen;
|
|
246
|
-
var _EditorSession_finish;
|
|
247
|
-
var _EditorSession_notify;
|
|
248
|
-
var _EditorSession_reportObserverError;
|
|
249
|
-
var EditorSession = class {
|
|
250
|
-
/** Use EditorRegistry.open() to construct sessions from a captured host snapshot. */
|
|
251
|
-
constructor(definition, snapshot, host, isRegistered) {
|
|
252
|
-
_EditorSession_instances.add(this);
|
|
253
|
-
_EditorSession_draft.set(this, void 0);
|
|
254
|
-
_EditorSession_status.set(this, "editing");
|
|
255
|
-
_EditorSession_issues.set(this, []);
|
|
256
|
-
_EditorSession_error.set(this, void 0);
|
|
257
|
-
_EditorSession_listeners.set(this, /* @__PURE__ */ new Set());
|
|
258
|
-
_EditorSession_view.set(this, new EditorView());
|
|
259
|
-
_EditorSession_definition.set(this, void 0);
|
|
260
|
-
_EditorSession_snapshot.set(this, void 0);
|
|
261
|
-
_EditorSession_host.set(this, void 0);
|
|
262
|
-
_EditorSession_isRegistered.set(this, void 0);
|
|
263
|
-
__classPrivateFieldSet2(this, _EditorSession_isRegistered, isRegistered, "f");
|
|
264
|
-
__classPrivateFieldSet2(this, _EditorSession_definition, definition, "f");
|
|
265
|
-
__classPrivateFieldSet2(this, _EditorSession_snapshot, captureSnapshot(snapshot, captureReference(snapshot)), "f");
|
|
266
|
-
__classPrivateFieldSet2(this, _EditorSession_host, host, "f");
|
|
267
|
-
__classPrivateFieldSet2(this, _EditorSession_draft, __classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_copyDraft).call(this, definition.read(__classPrivateFieldGet2(this, _EditorSession_snapshot, "f"))), "f");
|
|
268
|
-
}
|
|
269
|
-
/** Stable instance identity remains available after the session closes. */
|
|
270
|
-
get reference() {
|
|
271
|
-
return captureReference(__classPrivateFieldGet2(this, _EditorSession_snapshot, "f"));
|
|
272
|
-
}
|
|
273
|
-
getDraft() {
|
|
274
|
-
__classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_assertOpen).call(this);
|
|
275
|
-
return cloneJson(__classPrivateFieldGet2(this, _EditorSession_draft, "f"));
|
|
276
|
-
}
|
|
277
|
-
setDraft(draft) {
|
|
278
|
-
if (__classPrivateFieldGet2(this, _EditorSession_status, "f") !== "editing")
|
|
279
|
-
throw new Error("The session is not editable.");
|
|
280
|
-
__classPrivateFieldSet2(this, _EditorSession_draft, __classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_copyDraft).call(this, draft), "f");
|
|
281
|
-
__classPrivateFieldSet2(this, _EditorSession_issues, [], "f");
|
|
282
|
-
__classPrivateFieldSet2(this, _EditorSession_error, void 0, "f");
|
|
283
|
-
__classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_notify).call(this);
|
|
284
|
-
}
|
|
285
|
-
setValidationIssues(issues) {
|
|
286
|
-
if (__classPrivateFieldGet2(this, _EditorSession_status, "f") !== "editing")
|
|
287
|
-
throw new Error("The session is not editable.");
|
|
288
|
-
__classPrivateFieldSet2(this, _EditorSession_issues, __classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_copyIssues).call(this, issues), "f");
|
|
289
|
-
__classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_notify).call(this);
|
|
290
|
-
}
|
|
291
|
-
getState() {
|
|
292
|
-
return Object.freeze({
|
|
293
|
-
status: __classPrivateFieldGet2(this, _EditorSession_status, "f"),
|
|
294
|
-
canSave: __classPrivateFieldGet2(this, _EditorSession_status, "f") === "editing" && __classPrivateFieldGet2(this, _EditorSession_issues, "f").length === 0,
|
|
295
|
-
issues: __classPrivateFieldGet2(this, _EditorSession_issues, "f"),
|
|
296
|
-
error: __classPrivateFieldGet2(this, _EditorSession_error, "f")
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
subscribe(listener) {
|
|
300
|
-
__classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_assertOpen).call(this);
|
|
301
|
-
__classPrivateFieldGet2(this, _EditorSession_listeners, "f").add(listener);
|
|
302
|
-
return () => {
|
|
303
|
-
__classPrivateFieldGet2(this, _EditorSession_listeners, "f").delete(listener);
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
mount(container) {
|
|
307
|
-
return __classPrivateFieldGet2(this, _EditorSession_view, "f").mount(container, __classPrivateFieldGet2(this, _EditorSession_definition, "f").mount, this);
|
|
308
|
-
}
|
|
309
|
-
async save() {
|
|
310
|
-
if (__classPrivateFieldGet2(this, _EditorSession_status, "f") === "saving")
|
|
311
|
-
return { status: "busy" };
|
|
312
|
-
if (__classPrivateFieldGet2(this, _EditorSession_status, "f") !== "editing")
|
|
313
|
-
return { status: "closed" };
|
|
314
|
-
__classPrivateFieldSet2(this, _EditorSession_status, "saving", "f");
|
|
315
|
-
__classPrivateFieldSet2(this, _EditorSession_issues, [], "f");
|
|
316
|
-
__classPrivateFieldSet2(this, _EditorSession_error, void 0, "f");
|
|
317
|
-
__classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_notify).call(this);
|
|
318
|
-
try {
|
|
319
|
-
if (__classPrivateFieldGet2(this, _EditorSession_isRegistered, "f") && !__classPrivateFieldGet2(this, _EditorSession_isRegistered, "f").call(this))
|
|
320
|
-
throw new BlockEditorConflictError("The source editor registration expired.");
|
|
321
|
-
const prepared = isPreparedEditor(__classPrivateFieldGet2(this, _EditorSession_definition, "f")) ? capturePreparedSave(__classPrivateFieldGet2(this, _EditorSession_definition, "f"), cloneJson(__classPrivateFieldGet2(this, _EditorSession_draft, "f")), __classPrivateFieldGet2(this, _EditorSession_snapshot, "f")) : void 0;
|
|
322
|
-
const issues = prepared ? prepared.kind === "invalid" ? prepared.issues : [] : await __classPrivateFieldGet2(this, _EditorSession_definition, "f").validate(cloneJson(__classPrivateFieldGet2(this, _EditorSession_draft, "f")), __classPrivateFieldGet2(this, _EditorSession_snapshot, "f"));
|
|
323
|
-
if (!Array.isArray(issues))
|
|
324
|
-
throw new TypeError("validate() must return an issue array.");
|
|
325
|
-
if (issues.length > 0) {
|
|
326
|
-
__classPrivateFieldSet2(this, _EditorSession_issues, __classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_copyIssues).call(this, issues), "f");
|
|
327
|
-
return { status: "invalid", issues: __classPrivateFieldGet2(this, _EditorSession_issues, "f") };
|
|
328
|
-
}
|
|
329
|
-
const changes = __classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_prepareChanges).call(this, (prepared === null || prepared === void 0 ? void 0 : prepared.kind) === "ready" ? prepared.changes : __classPrivateFieldGet2(this, _EditorSession_definition, "f").createPatch(cloneJson(__classPrivateFieldGet2(this, _EditorSession_draft, "f")), __classPrivateFieldGet2(this, _EditorSession_snapshot, "f")));
|
|
330
|
-
if (__classPrivateFieldGet2(this, _EditorSession_isRegistered, "f") && !__classPrivateFieldGet2(this, _EditorSession_isRegistered, "f").call(this))
|
|
331
|
-
throw new BlockEditorConflictError("The source editor registration expired.");
|
|
332
|
-
const current = __classPrivateFieldGet2(this, _EditorSession_host, "f").readBlock(__classPrivateFieldGet2(this, _EditorSession_snapshot, "f"));
|
|
333
|
-
if (!current || !sameSnapshot(__classPrivateFieldGet2(this, _EditorSession_snapshot, "f"), captureSnapshot(current, __classPrivateFieldGet2(this, _EditorSession_snapshot, "f")))) {
|
|
334
|
-
throw new BlockEditorConflictError();
|
|
335
|
-
}
|
|
336
|
-
if (__classPrivateFieldGet2(this, _EditorSession_isRegistered, "f") && !__classPrivateFieldGet2(this, _EditorSession_isRegistered, "f").call(this))
|
|
337
|
-
throw new BlockEditorConflictError("The source editor registration expired.");
|
|
338
|
-
if (changes.length > 0) {
|
|
339
|
-
await __classPrivateFieldGet2(this, _EditorSession_host, "f").commit(Object.freeze({ expected: __classPrivateFieldGet2(this, _EditorSession_snapshot, "f"), changes }));
|
|
340
|
-
}
|
|
341
|
-
__classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_finish).call(this, "saved");
|
|
342
|
-
return { status: "saved", changed: changes.length > 0 };
|
|
343
|
-
} catch (error) {
|
|
344
|
-
__classPrivateFieldSet2(this, _EditorSession_error, error, "f");
|
|
345
|
-
return error instanceof BlockEditorConflictError ? { status: "conflict", error } : { status: "failed", error };
|
|
346
|
-
} finally {
|
|
347
|
-
if (__classPrivateFieldGet2(this, _EditorSession_status, "f") === "saving") {
|
|
348
|
-
__classPrivateFieldSet2(this, _EditorSession_status, "editing", "f");
|
|
349
|
-
__classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_notify).call(this);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
/** Closing is refused while saving; the host must keep the modal open. */
|
|
354
|
-
cancel() {
|
|
355
|
-
if (__classPrivateFieldGet2(this, _EditorSession_status, "f") !== "editing")
|
|
356
|
-
return false;
|
|
357
|
-
__classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_finish).call(this, "cancelled");
|
|
358
|
-
return true;
|
|
359
|
-
}
|
|
360
|
-
dispose() {
|
|
361
|
-
if (__classPrivateFieldGet2(this, _EditorSession_status, "f") === "saving")
|
|
362
|
-
return false;
|
|
363
|
-
if (__classPrivateFieldGet2(this, _EditorSession_status, "f") === "editing")
|
|
364
|
-
__classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_finish).call(this, "disposed");
|
|
365
|
-
return true;
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
_EditorSession_draft = /* @__PURE__ */ new WeakMap(), _EditorSession_status = /* @__PURE__ */ new WeakMap(), _EditorSession_issues = /* @__PURE__ */ new WeakMap(), _EditorSession_error = /* @__PURE__ */ new WeakMap(), _EditorSession_listeners = /* @__PURE__ */ new WeakMap(), _EditorSession_view = /* @__PURE__ */ new WeakMap(), _EditorSession_definition = /* @__PURE__ */ new WeakMap(), _EditorSession_snapshot = /* @__PURE__ */ new WeakMap(), _EditorSession_host = /* @__PURE__ */ new WeakMap(), _EditorSession_isRegistered = /* @__PURE__ */ new WeakMap(), _EditorSession_instances = /* @__PURE__ */ new WeakSet(), _EditorSession_prepareChanges = function _EditorSession_prepareChanges2(patch) {
|
|
369
|
-
if (!Array.isArray(patch))
|
|
370
|
-
throw new TypeError("createPatch() must return an array.");
|
|
371
|
-
const seen = /* @__PURE__ */ new Set();
|
|
372
|
-
const changes = [];
|
|
373
|
-
for (const change of patch) {
|
|
374
|
-
if (!change || !__classPrivateFieldGet2(this, _EditorSession_definition, "f").editableArguments.includes(change.argument) || seen.has(change.argument) || !isLiteral(change.value)) {
|
|
375
|
-
throw new TypeError("Patch contains an invalid, duplicate or disallowed argument.");
|
|
376
|
-
}
|
|
377
|
-
seen.add(change.argument);
|
|
378
|
-
const slot = Object.hasOwn(__classPrivateFieldGet2(this, _EditorSession_snapshot, "f").arguments, change.argument) ? __classPrivateFieldGet2(this, _EditorSession_snapshot, "f").arguments[change.argument] : void 0;
|
|
379
|
-
if (!slot || slot.kind !== "literal") {
|
|
380
|
-
throw new TypeError("Only existing literal arguments can be changed.");
|
|
381
|
-
}
|
|
382
|
-
if (slot.value !== change.value)
|
|
383
|
-
changes.push(Object.freeze({ ...change }));
|
|
384
|
-
}
|
|
385
|
-
return Object.freeze(changes);
|
|
386
|
-
}, _EditorSession_copyIssues = function _EditorSession_copyIssues2(issues) {
|
|
387
|
-
if (!Array.isArray(issues))
|
|
388
|
-
throw new TypeError("Expected a validation issue array.");
|
|
389
|
-
return Object.freeze(issues.map((issue) => {
|
|
390
|
-
if (!issue || typeof issue.message !== "string" || issue.path !== void 0 && typeof issue.path !== "string") {
|
|
391
|
-
throw new TypeError("Invalid validation issue.");
|
|
392
|
-
}
|
|
393
|
-
return Object.freeze({ ...issue });
|
|
394
|
-
}));
|
|
395
|
-
}, _EditorSession_copyDraft = function _EditorSession_copyDraft2(draft) {
|
|
396
|
-
if (!draft || typeof draft !== "object" || Array.isArray(draft)) {
|
|
397
|
-
throw new TypeError("The editor draft must be a JSON object.");
|
|
398
|
-
}
|
|
399
|
-
return cloneJson(draft);
|
|
400
|
-
}, _EditorSession_assertOpen = function _EditorSession_assertOpen2() {
|
|
401
|
-
if (__classPrivateFieldGet2(this, _EditorSession_status, "f") !== "editing" && __classPrivateFieldGet2(this, _EditorSession_status, "f") !== "saving") {
|
|
402
|
-
throw new Error("The session is closed.");
|
|
403
|
-
}
|
|
404
|
-
}, _EditorSession_finish = function _EditorSession_finish2(status) {
|
|
405
|
-
__classPrivateFieldSet2(this, _EditorSession_status, status, "f");
|
|
406
|
-
__classPrivateFieldSet2(this, _EditorSession_draft, {}, "f");
|
|
407
|
-
__classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_notify).call(this);
|
|
408
|
-
try {
|
|
409
|
-
__classPrivateFieldGet2(this, _EditorSession_view, "f").unmount();
|
|
410
|
-
} catch (error) {
|
|
411
|
-
__classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_reportObserverError).call(this, error);
|
|
412
|
-
}
|
|
413
|
-
__classPrivateFieldGet2(this, _EditorSession_listeners, "f").clear();
|
|
414
|
-
}, _EditorSession_notify = function _EditorSession_notify2() {
|
|
415
|
-
for (const listener of [...__classPrivateFieldGet2(this, _EditorSession_listeners, "f")]) {
|
|
416
|
-
try {
|
|
417
|
-
listener();
|
|
418
|
-
} catch (error) {
|
|
419
|
-
__classPrivateFieldGet2(this, _EditorSession_instances, "m", _EditorSession_reportObserverError).call(this, error);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}, _EditorSession_reportObserverError = function _EditorSession_reportObserverError2(error) {
|
|
423
|
-
console.error("Block editor view callback failed:", error);
|
|
424
|
-
};
|
|
425
|
-
|
|
426
|
-
// dist/subtree.js
|
|
427
|
-
function descendantLimits(limits = {}) {
|
|
428
|
-
const result = { ...DEFAULT_DESCENDANT_LIMITS, ...limits };
|
|
429
|
-
if (!Number.isSafeInteger(result.maxDepth) || result.maxDepth < 0 || result.maxDepth > DEFAULT_DESCENDANT_LIMITS.maxDepth || !Number.isSafeInteger(result.maxNodes) || result.maxNodes < 1 || result.maxNodes > DEFAULT_DESCENDANT_LIMITS.maxNodes) {
|
|
430
|
-
throw new BlockEditorStructureError("Limits must be integers: depth 0\u201332, nodes 1\u2013500.", "limit");
|
|
431
|
-
}
|
|
432
|
-
return Object.freeze(result);
|
|
433
|
-
}
|
|
434
|
-
function captureSubtree(source, reference, limits) {
|
|
435
|
-
const invalid = (message) => {
|
|
436
|
-
throw new BlockEditorStructureError(message, "invalid-structure");
|
|
437
|
-
};
|
|
438
|
-
if (!source || source.targetId !== reference.targetId || source.blockId !== reference.blockId || typeof source.generation !== "string" || !source.generation || !Array.isArray(source.nodes) || source.nodes.length === 0)
|
|
439
|
-
invalid("The host returned an invalid subtree snapshot.");
|
|
440
|
-
if (source.nodes.length > limits.maxNodes) {
|
|
441
|
-
throw new BlockEditorStructureError("The subtree exceeds the node limit.", "limit");
|
|
442
|
-
}
|
|
443
|
-
const entries = /* @__PURE__ */ new Map();
|
|
444
|
-
let edges = 0;
|
|
445
|
-
for (const node of source.nodes) {
|
|
446
|
-
if (!(node === null || node === void 0 ? void 0 : node.block) || !Array.isArray(node.branches))
|
|
447
|
-
invalid("Invalid subtree node.");
|
|
448
|
-
const block = (() => {
|
|
449
|
-
try {
|
|
450
|
-
return captureSnapshot(node.block, { targetId: reference.targetId, blockId: node.block.blockId });
|
|
451
|
-
} catch (_a) {
|
|
452
|
-
return invalid("Invalid subtree block snapshot or target identity.");
|
|
453
|
-
}
|
|
454
|
-
})();
|
|
455
|
-
if (entries.has(block.blockId))
|
|
456
|
-
invalid("Duplicate block ID in subtree.");
|
|
457
|
-
const inputs = /* @__PURE__ */ new Set();
|
|
458
|
-
const branches = node.branches.map((branch) => {
|
|
459
|
-
if (!branch || typeof branch.input !== "string" || !branch.input || inputs.has(branch.input) || !Array.isArray(branch.blockIds))
|
|
460
|
-
invalid("Invalid or duplicate statement input.");
|
|
461
|
-
inputs.add(branch.input);
|
|
462
|
-
edges += branch.blockIds.length;
|
|
463
|
-
if (edges >= source.nodes.length)
|
|
464
|
-
invalid("Subtree connections contain a cycle or duplicate parent.");
|
|
465
|
-
const blockIds = branch.blockIds.map((id) => {
|
|
466
|
-
if (typeof id !== "string" || !id)
|
|
467
|
-
invalid("Invalid statement block ID.");
|
|
468
|
-
return id;
|
|
469
|
-
});
|
|
470
|
-
return Object.freeze({ input: branch.input, blockIds: Object.freeze(blockIds) });
|
|
471
|
-
});
|
|
472
|
-
entries.set(block.blockId, Object.freeze({ block, branches: Object.freeze(branches) }));
|
|
473
|
-
}
|
|
474
|
-
const paths = /* @__PURE__ */ new Map();
|
|
475
|
-
const ordered = [];
|
|
476
|
-
const stack = [{ id: reference.blockId, path: Object.freeze([]) }];
|
|
477
|
-
while (stack.length) {
|
|
478
|
-
const { id, path } = stack.pop();
|
|
479
|
-
if (paths.has(id))
|
|
480
|
-
throw new BlockEditorStructureError("Cycle or repeated subtree node.", "cycle");
|
|
481
|
-
if (path.length > limits.maxDepth) {
|
|
482
|
-
throw new BlockEditorStructureError("The subtree exceeds the depth limit.", "limit");
|
|
483
|
-
}
|
|
484
|
-
const node = entries.get(id);
|
|
485
|
-
if (!node)
|
|
486
|
-
invalid(`Missing subtree node: ${id}`);
|
|
487
|
-
paths.set(id, path);
|
|
488
|
-
ordered.push(node);
|
|
489
|
-
for (let branchIndex = node.branches.length - 1; branchIndex >= 0; branchIndex--) {
|
|
490
|
-
const branch = node.branches[branchIndex];
|
|
491
|
-
for (let index = branch.blockIds.length - 1; index >= 0; index--) {
|
|
492
|
-
stack.push({ id: branch.blockIds[index], path: Object.freeze([
|
|
493
|
-
...path,
|
|
494
|
-
Object.freeze({ blockId: id, input: branch.input, index })
|
|
495
|
-
]) });
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
if (paths.size !== entries.size)
|
|
500
|
-
invalid("Subtree includes disconnected or out-of-scope nodes.");
|
|
501
|
-
return {
|
|
502
|
-
snapshot: Object.freeze({
|
|
503
|
-
...captureReference(reference),
|
|
504
|
-
generation: source.generation,
|
|
505
|
-
nodes: Object.freeze(ordered)
|
|
506
|
-
}),
|
|
507
|
-
paths
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
function sameSubtree(left, right) {
|
|
511
|
-
return left.targetId === right.targetId && left.blockId === right.blockId && left.generation === right.generation && left.nodes.length === right.nodes.length && left.nodes.every((node, index) => {
|
|
512
|
-
const other = right.nodes[index];
|
|
513
|
-
return sameSnapshot(node.block, other.block) && node.branches.length === other.branches.length && node.branches.every((branch, branchIndex) => {
|
|
514
|
-
const b = other.branches[branchIndex];
|
|
515
|
-
return branch.input === b.input && branch.blockIds.length === b.blockIds.length && branch.blockIds.every((id, i) => id === b.blockIds[i]);
|
|
516
|
-
});
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
// dist/descendants.js
|
|
521
|
-
var __classPrivateFieldSet3 = function(receiver, state, value, kind, f) {
|
|
522
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
523
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
524
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
525
|
-
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
526
|
-
};
|
|
527
|
-
var __classPrivateFieldGet3 = function(receiver, state, kind, f) {
|
|
528
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
529
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
530
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
531
|
-
};
|
|
532
|
-
var _DescendantSession_instances;
|
|
533
|
-
var _DescendantSession_snapshot;
|
|
534
|
-
var _DescendantSession_host;
|
|
535
|
-
var _DescendantSession_limits;
|
|
536
|
-
var _DescendantSession_lookup;
|
|
537
|
-
var _DescendantSession_bindings;
|
|
538
|
-
var _DescendantSession_records;
|
|
539
|
-
var _DescendantSession_nodes;
|
|
540
|
-
var _DescendantSession_listeners;
|
|
541
|
-
var _DescendantSession_detach;
|
|
542
|
-
var _DescendantSession_abort;
|
|
543
|
-
var _DescendantSession_status;
|
|
544
|
-
var _DescendantSession_committing;
|
|
545
|
-
var _DescendantSession_error;
|
|
546
|
-
var _DescendantSession_createRecord;
|
|
547
|
-
var _DescendantSession_isOpen;
|
|
548
|
-
var _DescendantSession_closedSaveResult;
|
|
549
|
-
var _DescendantSession_assertOpen;
|
|
550
|
-
var _DescendantSession_assertEditable;
|
|
551
|
-
var _DescendantSession_bindingsCurrent;
|
|
552
|
-
var _DescendantSession_checkBindings;
|
|
553
|
-
var _DescendantSession_assertSaving;
|
|
554
|
-
var _DescendantSession_notify;
|
|
555
|
-
var _DescendantSession_watch;
|
|
556
|
-
var _DescendantSession_finish;
|
|
557
|
-
function copyDraft(draft) {
|
|
558
|
-
if (!draft || typeof draft !== "object" || Array.isArray(draft)) {
|
|
559
|
-
throw new TypeError("The editor draft must be a JSON object.");
|
|
560
|
-
}
|
|
561
|
-
return cloneJson(draft);
|
|
562
|
-
}
|
|
563
|
-
function copyIssues(issues) {
|
|
564
|
-
if (!Array.isArray(issues))
|
|
565
|
-
throw new TypeError("Expected a validation issue array.");
|
|
566
|
-
return Object.freeze(issues.map((issue) => {
|
|
567
|
-
if (!issue || typeof issue.message !== "string" || issue.path !== void 0 && typeof issue.path !== "string") {
|
|
568
|
-
throw new TypeError("Invalid validation issue.");
|
|
569
|
-
}
|
|
570
|
-
return Object.freeze({ message: issue.message, ...issue.path === void 0 ? {} : { path: issue.path } });
|
|
571
|
-
}));
|
|
572
|
-
}
|
|
573
|
-
function observe(listeners) {
|
|
574
|
-
for (const listener of [...listeners]) {
|
|
575
|
-
try {
|
|
576
|
-
listener();
|
|
577
|
-
} catch (error) {
|
|
578
|
-
report(error);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
function report(error) {
|
|
583
|
-
console.error("Block editor view callback failed:", error);
|
|
584
|
-
}
|
|
585
|
-
function abortable(value, signal) {
|
|
586
|
-
return new Promise((resolve, reject) => {
|
|
587
|
-
const abort = () => reject(signal.reason);
|
|
588
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
589
|
-
Promise.resolve(value).then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
590
|
-
if (signal.aborted) {
|
|
591
|
-
signal.removeEventListener("abort", abort);
|
|
592
|
-
abort();
|
|
593
|
-
}
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
var DescendantSession = class {
|
|
597
|
-
/** Use EditorRegistry.openDescendants() to negotiate and capture the scope. */
|
|
598
|
-
constructor(captured, host, lookup, subscribeRegistry, limits) {
|
|
599
|
-
_DescendantSession_instances.add(this);
|
|
600
|
-
_DescendantSession_snapshot.set(this, void 0);
|
|
601
|
-
_DescendantSession_host.set(this, void 0);
|
|
602
|
-
_DescendantSession_limits.set(this, void 0);
|
|
603
|
-
_DescendantSession_lookup.set(this, void 0);
|
|
604
|
-
_DescendantSession_bindings.set(this, /* @__PURE__ */ new Map());
|
|
605
|
-
_DescendantSession_records.set(this, /* @__PURE__ */ new Map());
|
|
606
|
-
_DescendantSession_nodes.set(this, void 0);
|
|
607
|
-
_DescendantSession_listeners.set(this, /* @__PURE__ */ new Set());
|
|
608
|
-
_DescendantSession_detach.set(this, /* @__PURE__ */ new Set());
|
|
609
|
-
_DescendantSession_abort.set(this, new AbortController());
|
|
610
|
-
_DescendantSession_status.set(this, "editing");
|
|
611
|
-
_DescendantSession_committing.set(this, false);
|
|
612
|
-
_DescendantSession_error.set(this, void 0);
|
|
613
|
-
__classPrivateFieldSet3(this, _DescendantSession_snapshot, captured.snapshot, "f");
|
|
614
|
-
__classPrivateFieldSet3(this, _DescendantSession_host, host, "f");
|
|
615
|
-
__classPrivateFieldSet3(this, _DescendantSession_lookup, lookup, "f");
|
|
616
|
-
__classPrivateFieldSet3(this, _DescendantSession_limits, limits, "f");
|
|
617
|
-
for (const node of captured.snapshot.nodes)
|
|
618
|
-
__classPrivateFieldGet3(this, _DescendantSession_bindings, "f").set(node.block.opcode, lookup(node.block.opcode));
|
|
619
|
-
__classPrivateFieldSet3(this, _DescendantSession_nodes, Object.freeze(captured.snapshot.nodes.map((node) => {
|
|
620
|
-
const definition = __classPrivateFieldGet3(this, _DescendantSession_bindings, "f").get(node.block.opcode);
|
|
621
|
-
const descriptor = Object.freeze({
|
|
622
|
-
reference: captureReference(node.block),
|
|
623
|
-
opcode: node.block.opcode,
|
|
624
|
-
inputPath: captured.paths.get(node.block.blockId),
|
|
625
|
-
...definition ? { editor: Object.freeze({
|
|
626
|
-
apiVersion: definition.apiVersion,
|
|
627
|
-
extensionId: definition.extensionId,
|
|
628
|
-
editorId: definition.editorId,
|
|
629
|
-
opcodes: definition.opcodes,
|
|
630
|
-
editableArguments: definition.editableArguments
|
|
631
|
-
}) } : {}
|
|
632
|
-
});
|
|
633
|
-
if (definition) {
|
|
634
|
-
try {
|
|
635
|
-
__classPrivateFieldGet3(this, _DescendantSession_records, "f").set(node.block.blockId, __classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_createRecord).call(this, descriptor, definition, node.block));
|
|
636
|
-
} catch (cause) {
|
|
637
|
-
throw new DescendantNodeError(descriptor.reference, descriptor.inputPath, cause);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
return descriptor;
|
|
641
|
-
})), "f");
|
|
642
|
-
try {
|
|
643
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_watch).call(this, () => subscribeRegistry(() => {
|
|
644
|
-
if (!__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_bindingsCurrent).call(this))
|
|
645
|
-
this.invalidate(new BlockEditorConflictError("An editor registration changed."));
|
|
646
|
-
}));
|
|
647
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_checkBindings).call(this);
|
|
648
|
-
if (host.subscribeInvalidation) {
|
|
649
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_watch).call(this, () => host.subscribeInvalidation(this.reference, (reason) => this.invalidate(reason)));
|
|
650
|
-
}
|
|
651
|
-
} catch (error) {
|
|
652
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_finish).call(this, "disposed");
|
|
653
|
-
throw error;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
get reference() {
|
|
657
|
-
return captureReference(__classPrivateFieldGet3(this, _DescendantSession_snapshot, "f"));
|
|
658
|
-
}
|
|
659
|
-
get generation() {
|
|
660
|
-
return __classPrivateFieldGet3(this, _DescendantSession_snapshot, "f").generation;
|
|
661
|
-
}
|
|
662
|
-
getNodes() {
|
|
663
|
-
return __classPrivateFieldGet3(this, _DescendantSession_nodes, "f");
|
|
664
|
-
}
|
|
665
|
-
getEditor(blockId) {
|
|
666
|
-
var _a;
|
|
667
|
-
return (_a = __classPrivateFieldGet3(this, _DescendantSession_records, "f").get(blockId)) === null || _a === void 0 ? void 0 : _a.editor;
|
|
668
|
-
}
|
|
669
|
-
getState() {
|
|
670
|
-
const issues = Object.freeze([...__classPrivateFieldGet3(this, _DescendantSession_records, "f").values()].flatMap((record) => record.issues.map((issue) => Object.freeze({ ...issue, reference: record.descriptor.reference, inputPath: record.descriptor.inputPath }))));
|
|
671
|
-
return Object.freeze({
|
|
672
|
-
status: __classPrivateFieldGet3(this, _DescendantSession_status, "f"),
|
|
673
|
-
canSave: __classPrivateFieldGet3(this, _DescendantSession_status, "f") === "editing" && issues.length === 0,
|
|
674
|
-
issues,
|
|
675
|
-
error: __classPrivateFieldGet3(this, _DescendantSession_error, "f")
|
|
676
|
-
});
|
|
677
|
-
}
|
|
678
|
-
subscribe(listener) {
|
|
679
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_assertOpen).call(this);
|
|
680
|
-
__classPrivateFieldGet3(this, _DescendantSession_listeners, "f").add(listener);
|
|
681
|
-
return () => {
|
|
682
|
-
__classPrivateFieldGet3(this, _DescendantSession_listeners, "f").delete(listener);
|
|
683
|
-
};
|
|
684
|
-
}
|
|
685
|
-
async save() {
|
|
686
|
-
if (__classPrivateFieldGet3(this, _DescendantSession_status, "f") === "saving")
|
|
687
|
-
return { status: "busy" };
|
|
688
|
-
if (__classPrivateFieldGet3(this, _DescendantSession_status, "f") !== "editing")
|
|
689
|
-
return { status: "closed" };
|
|
690
|
-
__classPrivateFieldSet3(this, _DescendantSession_status, "saving", "f");
|
|
691
|
-
__classPrivateFieldSet3(this, _DescendantSession_error, void 0, "f");
|
|
692
|
-
for (const record of __classPrivateFieldGet3(this, _DescendantSession_records, "f").values())
|
|
693
|
-
record.issues = [];
|
|
694
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_notify).call(this);
|
|
695
|
-
try {
|
|
696
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_assertSaving).call(this);
|
|
697
|
-
const prepared = /* @__PURE__ */ new Map();
|
|
698
|
-
for (const record of __classPrivateFieldGet3(this, _DescendantSession_records, "f").values()) {
|
|
699
|
-
try {
|
|
700
|
-
const result = isPreparedEditor(record.definition) ? capturePreparedSave(record.definition, cloneJson(record.draft), record.snapshot) : void 0;
|
|
701
|
-
if (result)
|
|
702
|
-
prepared.set(record.snapshot.blockId, result);
|
|
703
|
-
const issues2 = result ? result.kind === "invalid" ? result.issues : [] : await abortable(record.definition.validate(cloneJson(record.draft), record.snapshot), __classPrivateFieldGet3(this, _DescendantSession_abort, "f").signal);
|
|
704
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_assertSaving).call(this);
|
|
705
|
-
record.issues = copyIssues(issues2);
|
|
706
|
-
} catch (cause) {
|
|
707
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_assertSaving).call(this);
|
|
708
|
-
throw new DescendantNodeError(record.descriptor.reference, record.descriptor.inputPath, cause);
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
const issues = this.getState().issues;
|
|
712
|
-
if (issues.length)
|
|
713
|
-
return { status: "invalid", issues };
|
|
714
|
-
const changes = [];
|
|
715
|
-
const destinations = /* @__PURE__ */ new Set();
|
|
716
|
-
for (const record of __classPrivateFieldGet3(this, _DescendantSession_records, "f").values()) {
|
|
717
|
-
try {
|
|
718
|
-
const result = prepared.get(record.snapshot.blockId);
|
|
719
|
-
const patch = (result === null || result === void 0 ? void 0 : result.kind) === "ready" ? result.changes : record.definition.createPatch(cloneJson(record.draft), record.snapshot);
|
|
720
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_assertSaving).call(this);
|
|
721
|
-
if (!Array.isArray(patch))
|
|
722
|
-
throw new TypeError("createPatch() must return an array.");
|
|
723
|
-
for (const change of patch) {
|
|
724
|
-
if (!change || !record.definition.editableArguments.includes(change.argument) || !isLiteral(change.value)) {
|
|
725
|
-
throw new TypeError("Patch contains an invalid or disallowed argument.");
|
|
726
|
-
}
|
|
727
|
-
const destination = JSON.stringify([record.snapshot.blockId, change.argument]);
|
|
728
|
-
if (destinations.has(destination))
|
|
729
|
-
throw new TypeError("Duplicate subtree write destination.");
|
|
730
|
-
destinations.add(destination);
|
|
731
|
-
const slot = Object.hasOwn(record.snapshot.arguments, change.argument) ? record.snapshot.arguments[change.argument] : void 0;
|
|
732
|
-
if ((slot === null || slot === void 0 ? void 0 : slot.kind) !== "literal")
|
|
733
|
-
throw new TypeError("Only existing literal arguments can be changed.");
|
|
734
|
-
if (slot.value !== change.value)
|
|
735
|
-
changes.push(Object.freeze({
|
|
736
|
-
blockId: record.snapshot.blockId,
|
|
737
|
-
argument: change.argument,
|
|
738
|
-
value: change.value
|
|
739
|
-
}));
|
|
740
|
-
}
|
|
741
|
-
} catch (cause) {
|
|
742
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_assertSaving).call(this);
|
|
743
|
-
throw new DescendantNodeError(record.descriptor.reference, record.descriptor.inputPath, cause);
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_assertSaving).call(this);
|
|
747
|
-
const live = __classPrivateFieldGet3(this, _DescendantSession_host, "f").readSubtree(this.reference);
|
|
748
|
-
let matches = false;
|
|
749
|
-
if (live) {
|
|
750
|
-
try {
|
|
751
|
-
matches = sameSubtree(__classPrivateFieldGet3(this, _DescendantSession_snapshot, "f"), captureSubtree(live, this.reference, __classPrivateFieldGet3(this, _DescendantSession_limits, "f")).snapshot);
|
|
752
|
-
} catch (_a) {
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_assertSaving).call(this);
|
|
756
|
-
if (!matches)
|
|
757
|
-
throw new BlockEditorConflictError("The subtree changed or is no longer editable.");
|
|
758
|
-
if (changes.length) {
|
|
759
|
-
__classPrivateFieldSet3(this, _DescendantSession_committing, true, "f");
|
|
760
|
-
await abortable(__classPrivateFieldGet3(this, _DescendantSession_host, "f").commitSubtree(Object.freeze({
|
|
761
|
-
expected: __classPrivateFieldGet3(this, _DescendantSession_snapshot, "f"),
|
|
762
|
-
changes: Object.freeze(changes),
|
|
763
|
-
signal: __classPrivateFieldGet3(this, _DescendantSession_abort, "f").signal
|
|
764
|
-
})), __classPrivateFieldGet3(this, _DescendantSession_abort, "f").signal);
|
|
765
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_assertSaving).call(this);
|
|
766
|
-
}
|
|
767
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_finish).call(this, "saved");
|
|
768
|
-
return { status: "saved", changed: changes.length > 0 };
|
|
769
|
-
} catch (error) {
|
|
770
|
-
if (!__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_isOpen).call(this))
|
|
771
|
-
return __classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_closedSaveResult).call(this);
|
|
772
|
-
__classPrivateFieldSet3(this, _DescendantSession_error, error, "f");
|
|
773
|
-
return error instanceof BlockEditorConflictError ? { status: "conflict", error } : { status: "failed", error };
|
|
774
|
-
} finally {
|
|
775
|
-
__classPrivateFieldSet3(this, _DescendantSession_committing, false, "f");
|
|
776
|
-
if (__classPrivateFieldGet3(this, _DescendantSession_status, "f") === "saving") {
|
|
777
|
-
__classPrivateFieldSet3(this, _DescendantSession_status, "editing", "f");
|
|
778
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_notify).call(this);
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
/** Validation may be cancelled; an already dispatched commit must finish atomically. */
|
|
783
|
-
cancel() {
|
|
784
|
-
if (!__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_isOpen).call(this) || __classPrivateFieldGet3(this, _DescendantSession_committing, "f"))
|
|
785
|
-
return false;
|
|
786
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_finish).call(this, "cancelled");
|
|
787
|
-
return true;
|
|
788
|
-
}
|
|
789
|
-
dispose() {
|
|
790
|
-
if (__classPrivateFieldGet3(this, _DescendantSession_committing, "f") && __classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_isOpen).call(this))
|
|
791
|
-
return false;
|
|
792
|
-
if (__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_isOpen).call(this))
|
|
793
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_finish).call(this, "disposed");
|
|
794
|
-
return true;
|
|
795
|
-
}
|
|
796
|
-
/** The host must observe the abort signal before any deferred write. */
|
|
797
|
-
invalidate(reason = new BlockEditorConflictError("The subtree session was invalidated.")) {
|
|
798
|
-
if (!__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_isOpen).call(this))
|
|
799
|
-
return false;
|
|
800
|
-
__classPrivateFieldSet3(this, _DescendantSession_error, reason, "f");
|
|
801
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_finish).call(this, "invalidated");
|
|
802
|
-
return true;
|
|
803
|
-
}
|
|
804
|
-
};
|
|
805
|
-
_DescendantSession_snapshot = /* @__PURE__ */ new WeakMap(), _DescendantSession_host = /* @__PURE__ */ new WeakMap(), _DescendantSession_limits = /* @__PURE__ */ new WeakMap(), _DescendantSession_lookup = /* @__PURE__ */ new WeakMap(), _DescendantSession_bindings = /* @__PURE__ */ new WeakMap(), _DescendantSession_records = /* @__PURE__ */ new WeakMap(), _DescendantSession_nodes = /* @__PURE__ */ new WeakMap(), _DescendantSession_listeners = /* @__PURE__ */ new WeakMap(), _DescendantSession_detach = /* @__PURE__ */ new WeakMap(), _DescendantSession_abort = /* @__PURE__ */ new WeakMap(), _DescendantSession_status = /* @__PURE__ */ new WeakMap(), _DescendantSession_committing = /* @__PURE__ */ new WeakMap(), _DescendantSession_error = /* @__PURE__ */ new WeakMap(), _DescendantSession_instances = /* @__PURE__ */ new WeakSet(), _DescendantSession_createRecord = function _DescendantSession_createRecord2(descriptor, definition, snapshot) {
|
|
806
|
-
const view = new EditorView();
|
|
807
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
808
|
-
const editor = Object.freeze({
|
|
809
|
-
reference: descriptor.reference,
|
|
810
|
-
getDraft: () => {
|
|
811
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_assertOpen).call(this);
|
|
812
|
-
return cloneJson(record.draft);
|
|
813
|
-
},
|
|
814
|
-
setDraft: (draft) => {
|
|
815
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_assertEditable).call(this);
|
|
816
|
-
record.draft = copyDraft(draft);
|
|
817
|
-
record.issues = [];
|
|
818
|
-
__classPrivateFieldSet3(this, _DescendantSession_error, void 0, "f");
|
|
819
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_notify).call(this, record);
|
|
820
|
-
},
|
|
821
|
-
setValidationIssues: (issues) => {
|
|
822
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_assertEditable).call(this);
|
|
823
|
-
record.issues = copyIssues(issues);
|
|
824
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_notify).call(this, record);
|
|
825
|
-
},
|
|
826
|
-
getState: () => Object.freeze({
|
|
827
|
-
status: __classPrivateFieldGet3(this, _DescendantSession_status, "f") === "invalidated" ? "disposed" : __classPrivateFieldGet3(this, _DescendantSession_status, "f"),
|
|
828
|
-
canSave: __classPrivateFieldGet3(this, _DescendantSession_status, "f") === "editing" && record.issues.length === 0,
|
|
829
|
-
issues: record.issues,
|
|
830
|
-
error: __classPrivateFieldGet3(this, _DescendantSession_error, "f")
|
|
831
|
-
}),
|
|
832
|
-
subscribe: (listener) => {
|
|
833
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_assertOpen).call(this);
|
|
834
|
-
listeners.add(listener);
|
|
835
|
-
return () => {
|
|
836
|
-
listeners.delete(listener);
|
|
837
|
-
};
|
|
838
|
-
},
|
|
839
|
-
mount: (container) => view.mount(container, definition.mount, editor)
|
|
840
|
-
});
|
|
841
|
-
const record = {
|
|
842
|
-
descriptor,
|
|
843
|
-
definition,
|
|
844
|
-
snapshot,
|
|
845
|
-
view,
|
|
846
|
-
listeners,
|
|
847
|
-
editor,
|
|
848
|
-
draft: copyDraft(definition.read(snapshot)),
|
|
849
|
-
issues: []
|
|
850
|
-
};
|
|
851
|
-
return record;
|
|
852
|
-
}, _DescendantSession_isOpen = function _DescendantSession_isOpen2() {
|
|
853
|
-
return __classPrivateFieldGet3(this, _DescendantSession_status, "f") === "editing" || __classPrivateFieldGet3(this, _DescendantSession_status, "f") === "saving";
|
|
854
|
-
}, _DescendantSession_closedSaveResult = function _DescendantSession_closedSaveResult2() {
|
|
855
|
-
return __classPrivateFieldGet3(this, _DescendantSession_status, "f") === "invalidated" ? { status: "invalidated" } : { status: "closed" };
|
|
856
|
-
}, _DescendantSession_assertOpen = function _DescendantSession_assertOpen2() {
|
|
857
|
-
if (!__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_isOpen).call(this))
|
|
858
|
-
throw new Error("The session is closed.");
|
|
859
|
-
}, _DescendantSession_assertEditable = function _DescendantSession_assertEditable2() {
|
|
860
|
-
if (__classPrivateFieldGet3(this, _DescendantSession_status, "f") !== "editing")
|
|
861
|
-
throw new Error("The session is not editable.");
|
|
862
|
-
}, _DescendantSession_bindingsCurrent = function _DescendantSession_bindingsCurrent2() {
|
|
863
|
-
return [...__classPrivateFieldGet3(this, _DescendantSession_bindings, "f")].every(([opcode, definition]) => __classPrivateFieldGet3(this, _DescendantSession_lookup, "f").call(this, opcode) === definition);
|
|
864
|
-
}, _DescendantSession_checkBindings = function _DescendantSession_checkBindings2() {
|
|
865
|
-
if (!__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_bindingsCurrent).call(this))
|
|
866
|
-
throw new BlockEditorConflictError("An editor registration changed.");
|
|
867
|
-
}, _DescendantSession_assertSaving = function _DescendantSession_assertSaving2() {
|
|
868
|
-
if (__classPrivateFieldGet3(this, _DescendantSession_status, "f") !== "saving")
|
|
869
|
-
throw new Error("The save was cancelled or invalidated.");
|
|
870
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_checkBindings).call(this);
|
|
871
|
-
}, _DescendantSession_notify = function _DescendantSession_notify2(record) {
|
|
872
|
-
if (record)
|
|
873
|
-
observe(record.listeners);
|
|
874
|
-
else
|
|
875
|
-
for (const node of __classPrivateFieldGet3(this, _DescendantSession_records, "f").values())
|
|
876
|
-
observe(node.listeners);
|
|
877
|
-
observe(__classPrivateFieldGet3(this, _DescendantSession_listeners, "f"));
|
|
878
|
-
}, _DescendantSession_watch = function _DescendantSession_watch2(subscribe) {
|
|
879
|
-
const detach = subscribe();
|
|
880
|
-
if (typeof detach !== "function")
|
|
881
|
-
throw new TypeError("Invalidation subscriptions must return a cleanup function.");
|
|
882
|
-
if (__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_isOpen).call(this))
|
|
883
|
-
__classPrivateFieldGet3(this, _DescendantSession_detach, "f").add(detach);
|
|
884
|
-
else
|
|
885
|
-
detach();
|
|
886
|
-
}, _DescendantSession_finish = function _DescendantSession_finish2(status) {
|
|
887
|
-
__classPrivateFieldSet3(this, _DescendantSession_status, status, "f");
|
|
888
|
-
__classPrivateFieldGet3(this, _DescendantSession_abort, "f").abort(__classPrivateFieldGet3(this, _DescendantSession_error, "f"));
|
|
889
|
-
__classPrivateFieldGet3(this, _DescendantSession_instances, "m", _DescendantSession_notify).call(this);
|
|
890
|
-
for (const record of __classPrivateFieldGet3(this, _DescendantSession_records, "f").values()) {
|
|
891
|
-
try {
|
|
892
|
-
record.view.unmount();
|
|
893
|
-
} catch (error) {
|
|
894
|
-
report(error);
|
|
895
|
-
}
|
|
896
|
-
record.draft = {};
|
|
897
|
-
record.issues = [];
|
|
898
|
-
record.listeners.clear();
|
|
899
|
-
}
|
|
900
|
-
for (const detach of __classPrivateFieldGet3(this, _DescendantSession_detach, "f")) {
|
|
901
|
-
try {
|
|
902
|
-
detach();
|
|
903
|
-
} catch (error) {
|
|
904
|
-
report(error);
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
__classPrivateFieldGet3(this, _DescendantSession_detach, "f").clear();
|
|
908
|
-
__classPrivateFieldGet3(this, _DescendantSession_listeners, "f").clear();
|
|
909
|
-
};
|
|
910
|
-
|
|
911
|
-
// dist/registry.js
|
|
912
|
-
var __classPrivateFieldGet4 = function(receiver, state, kind, f) {
|
|
913
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
914
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
915
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
916
|
-
};
|
|
917
|
-
var _EditorRegistry_instances;
|
|
918
|
-
var _EditorRegistry_editors;
|
|
919
|
-
var _EditorRegistry_opcodes;
|
|
920
|
-
var _EditorRegistry_changes;
|
|
921
|
-
var _EditorRegistry_register;
|
|
922
|
-
var _EditorRegistry_notifyChanges;
|
|
923
|
-
var EditorRegistry = class {
|
|
924
|
-
constructor() {
|
|
925
|
-
_EditorRegistry_instances.add(this);
|
|
926
|
-
_EditorRegistry_editors.set(this, /* @__PURE__ */ new Map());
|
|
927
|
-
_EditorRegistry_opcodes.set(this, /* @__PURE__ */ new Map());
|
|
928
|
-
_EditorRegistry_changes.set(this, /* @__PURE__ */ new Set());
|
|
929
|
-
}
|
|
930
|
-
register(definition) {
|
|
931
|
-
if (isPreparedEditor(definition))
|
|
932
|
-
throw new TypeError("Prepared editors require registerPrepared().");
|
|
933
|
-
return __classPrivateFieldGet4(this, _EditorRegistry_instances, "m", _EditorRegistry_register).call(this, definition);
|
|
934
|
-
}
|
|
935
|
-
registerPrepared(definition) {
|
|
936
|
-
if (!isPreparedEditor(definition) || typeof definition.prepareSave !== "function") {
|
|
937
|
-
throw new TypeError("Expected a prepared source editor.");
|
|
938
|
-
}
|
|
939
|
-
return __classPrivateFieldGet4(this, _EditorRegistry_instances, "m", _EditorRegistry_register).call(this, definition);
|
|
940
|
-
}
|
|
941
|
-
resolve(opcode) {
|
|
942
|
-
const entry = __classPrivateFieldGet4(this, _EditorRegistry_opcodes, "f").get(opcode);
|
|
943
|
-
if (!entry)
|
|
944
|
-
return void 0;
|
|
945
|
-
return Object.freeze({
|
|
946
|
-
apiVersion: entry.apiVersion,
|
|
947
|
-
extensionId: entry.extensionId,
|
|
948
|
-
editorId: entry.editorId,
|
|
949
|
-
opcodes: entry.opcodes,
|
|
950
|
-
editableArguments: entry.editableArguments
|
|
951
|
-
});
|
|
952
|
-
}
|
|
953
|
-
open(reference, host) {
|
|
954
|
-
const capturedReference = captureReference(reference);
|
|
955
|
-
const live = host.readBlock(capturedReference);
|
|
956
|
-
if (!live)
|
|
957
|
-
return void 0;
|
|
958
|
-
const snapshot = captureSnapshot(live, capturedReference);
|
|
959
|
-
const entry = __classPrivateFieldGet4(this, _EditorRegistry_opcodes, "f").get(snapshot.opcode);
|
|
960
|
-
return entry ? new EditorSession(entry, snapshot, host, isPreparedEditor(entry) ? () => __classPrivateFieldGet4(this, _EditorRegistry_opcodes, "f").get(snapshot.opcode) === entry : void 0) : void 0;
|
|
961
|
-
}
|
|
962
|
-
openDescendants(reference, host, limits) {
|
|
963
|
-
if (!supportsDescendantEditing(host))
|
|
964
|
-
return void 0;
|
|
965
|
-
const port = host.descendants;
|
|
966
|
-
const capturedReference = captureReference(reference);
|
|
967
|
-
const resolvedLimits = descendantLimits(limits);
|
|
968
|
-
const live = port.readSubtree(capturedReference);
|
|
969
|
-
if (!live)
|
|
970
|
-
return void 0;
|
|
971
|
-
const captured = captureSubtree(live, capturedReference, resolvedLimits);
|
|
972
|
-
if (!__classPrivateFieldGet4(this, _EditorRegistry_opcodes, "f").has(captured.snapshot.nodes[0].block.opcode))
|
|
973
|
-
return void 0;
|
|
974
|
-
return new DescendantSession(captured, port, (opcode) => __classPrivateFieldGet4(this, _EditorRegistry_opcodes, "f").get(opcode), (listener) => {
|
|
975
|
-
__classPrivateFieldGet4(this, _EditorRegistry_changes, "f").add(listener);
|
|
976
|
-
return () => {
|
|
977
|
-
__classPrivateFieldGet4(this, _EditorRegistry_changes, "f").delete(listener);
|
|
978
|
-
};
|
|
979
|
-
}, resolvedLimits);
|
|
980
|
-
}
|
|
981
|
-
};
|
|
982
|
-
_EditorRegistry_editors = /* @__PURE__ */ new WeakMap(), _EditorRegistry_opcodes = /* @__PURE__ */ new WeakMap(), _EditorRegistry_changes = /* @__PURE__ */ new WeakMap(), _EditorRegistry_instances = /* @__PURE__ */ new WeakSet(), _EditorRegistry_register = function _EditorRegistry_register2(definition) {
|
|
983
|
-
if (definition.apiVersion !== EDITOR_API_VERSION)
|
|
984
|
-
throw new TypeError("Unsupported editor API version.");
|
|
985
|
-
if (!/^[a-z0-9]+$/i.test(definition.extensionId) || !/^[a-z0-9][a-z0-9._-]*$/i.test(definition.editorId)) {
|
|
986
|
-
throw new TypeError("Invalid extension ID or editor ID.");
|
|
987
|
-
}
|
|
988
|
-
if (!Array.isArray(definition.opcodes) || definition.opcodes.length === 0 || new Set(definition.opcodes).size !== definition.opcodes.length || definition.opcodes.some((opcode) => typeof opcode !== "string" || !opcode.startsWith(`${definition.extensionId}_`) || opcode === `${definition.extensionId}_`)) {
|
|
989
|
-
throw new TypeError("Expected distinct full opcodes belonging to the extension.");
|
|
990
|
-
}
|
|
991
|
-
if (!Array.isArray(definition.editableArguments) || new Set(definition.editableArguments).size !== definition.editableArguments.length || definition.editableArguments.some((name) => typeof name !== "string" || !name)) {
|
|
992
|
-
throw new TypeError("Expected distinct editable argument names.");
|
|
993
|
-
}
|
|
994
|
-
if (typeof definition.read !== "function" || typeof definition.validate !== "function" || typeof definition.createPatch !== "function" || definition.mount !== void 0 && typeof definition.mount !== "function") {
|
|
995
|
-
throw new TypeError("Invalid editor callbacks.");
|
|
996
|
-
}
|
|
997
|
-
const key = JSON.stringify([definition.extensionId, definition.editorId]);
|
|
998
|
-
if (__classPrivateFieldGet4(this, _EditorRegistry_editors, "f").has(key) || definition.opcodes.some((opcode) => __classPrivateFieldGet4(this, _EditorRegistry_opcodes, "f").has(opcode))) {
|
|
999
|
-
throw new Error("The editor ID or an opcode is already registered.");
|
|
1000
|
-
}
|
|
1001
|
-
const entry = Object.freeze({
|
|
1002
|
-
...definition,
|
|
1003
|
-
opcodes: Object.freeze([...definition.opcodes]),
|
|
1004
|
-
editableArguments: Object.freeze([...definition.editableArguments])
|
|
1005
|
-
});
|
|
1006
|
-
__classPrivateFieldGet4(this, _EditorRegistry_editors, "f").set(key, entry);
|
|
1007
|
-
for (const opcode of entry.opcodes)
|
|
1008
|
-
__classPrivateFieldGet4(this, _EditorRegistry_opcodes, "f").set(opcode, entry);
|
|
1009
|
-
__classPrivateFieldGet4(this, _EditorRegistry_instances, "m", _EditorRegistry_notifyChanges).call(this);
|
|
1010
|
-
return () => {
|
|
1011
|
-
if (__classPrivateFieldGet4(this, _EditorRegistry_editors, "f").get(key) !== entry)
|
|
1012
|
-
return;
|
|
1013
|
-
__classPrivateFieldGet4(this, _EditorRegistry_editors, "f").delete(key);
|
|
1014
|
-
for (const opcode of entry.opcodes)
|
|
1015
|
-
__classPrivateFieldGet4(this, _EditorRegistry_opcodes, "f").delete(opcode);
|
|
1016
|
-
__classPrivateFieldGet4(this, _EditorRegistry_instances, "m", _EditorRegistry_notifyChanges).call(this);
|
|
1017
|
-
};
|
|
1018
|
-
}, _EditorRegistry_notifyChanges = function _EditorRegistry_notifyChanges2() {
|
|
1019
|
-
for (const listener of [...__classPrivateFieldGet4(this, _EditorRegistry_changes, "f")])
|
|
1020
|
-
listener();
|
|
1021
|
-
};
|
|
1022
|
-
|
|
1023
|
-
export {
|
|
1024
|
-
cloneJson,
|
|
1025
|
-
EditorSession,
|
|
1026
|
-
DescendantSession,
|
|
1027
|
-
EditorRegistry
|
|
1028
|
-
};
|
|
1029
|
-
//# sourceMappingURL=shared-N6YQE2X6.js.map
|