plitejs 54.0.0-beta.7 → 54.0.0-beta.8
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/authored/index.d.ts +44 -41
- package/dist/authored/index.js +16489 -16181
- package/dist/{authored-veto-CferDljr.js → authored-veto-DLmBMIcy.js} +1 -1
- package/dist/{clipboard-format-key-CLFcThXH.js → clipboard-format-key-SzffxWqa.js} +1 -1
- package/dist/{comparison-plan-7iIABSWG.js → comparison-plan-BqFJWjO4.js} +36 -14
- package/dist/{create-editor-acDgsovY.js → create-editor-kU8fg-PF.js} +6 -30
- package/dist/diff/index.d.ts +2 -32
- package/dist/diff/index.js +7 -378
- package/dist/dom/index.d.ts +2 -2
- package/dist/dom/index.js +2 -2
- package/dist/{dom-B5bAma7X.js → dom-SUWlnfT9.js} +562 -145
- package/dist/history/index.d.ts +5 -5
- package/dist/history/index.js +2041 -1833
- package/dist/history-skip-CcEhIzak.js +35 -0
- package/dist/hyperscript/index.d.ts +1 -1
- package/dist/hyperscript/index.js +1 -1
- package/dist/{hyperscript-BXUV6sdO.js → hyperscript-DdeGYoSc.js} +3 -2
- package/dist/{index-CTTjpWgb.d.ts → index-4PpawhYe.d.ts} +1 -1
- package/dist/{index-DJvrmSRP.d.ts → index-BsOySJwr.d.ts} +9 -9
- package/dist/{index-D8DQ1YFB.d.ts → index-CHEKdrHP.d.ts} +12 -4
- package/dist/{comparison-types-CsmDG5r2.d.ts → index-DM-b6jEe.d.ts} +21 -57
- package/dist/{index-LhVJuuEf.d.ts → index-DqmhcD_0.d.ts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -4
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.js +66 -5
- package/dist/law-check-Bvnz2EKh.js +19271 -0
- package/dist/pagination/index.d.ts +1 -1
- package/dist/pagination/index.js +1 -1
- package/dist/pagination/react.d.ts +2 -2
- package/dist/pagination/react.js +92 -46
- package/dist/{pagination-CwjmxPoX.js → pagination-XEnxZ1DX.js} +2 -1
- package/dist/{plugin-BZCGtqMI.js → plugin-B8uCi-Hr.js} +8758 -19452
- package/dist/{range-geometry-CZari453.d.ts → range-geometry-B2f67yLv.d.ts} +1 -1
- package/dist/{range-geometry-CqWrwkjH.js → range-geometry-BGKYQHqO.js} +3 -2
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +7 -6
- package/dist/react/virtualized.d.ts +2 -2
- package/dist/react/virtualized.js +59 -38
- package/dist/{react-DO9IETEQ.js → react-B6B-5z7t.js} +24 -55
- package/dist/{retraction-RHEKiF3h.js → retraction-BMzQ2on5.js} +1 -1
- package/dist/scroll-root-DudA40xj.js +25 -0
- package/dist/{src-fLbHzUjC.js → src--BZ7fZY4.js} +60 -26
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +4 -3
- package/dist/{tx-only-1FM45FSj.d.ts → tx-only-D8lpB-sT.d.ts} +338 -147
- package/dist/{update-policy-C32RjjGt.js → update-policy-J-4sHmrg.js} +2 -1
- package/dist/{use-editor-dom-scope-CUBnNAZV.js → use-editor-dom-scope-BFWvutxn.js} +2837 -2093
- package/dist/yjs/index.d.ts +1 -1
- package/dist/yjs/index.js +1 -1
- package/dist/yjs/react/index.d.ts +3 -3
- package/dist/yjs/react/index.js +3 -3
- package/dist/{yjs-BMguSAX_.js → yjs-DPngKQWQ.js} +114 -39
- package/package.json +2 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cd as definePluginPoint } from "./plugin-B8uCi-Hr.js";
|
|
2
2
|
//#region src/core/authored-veto.ts
|
|
3
3
|
/** Contribute a reason Suggesting refuses a change that touches an element. */
|
|
4
4
|
const authoredVeto = definePluginPoint("authored.veto");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ld as getEditorRuntimeOwner } from "./plugin-B8uCi-Hr.js";
|
|
2
2
|
//#region src/internal/clipboard-format-key.ts
|
|
3
3
|
const DEFAULT_CLIPBOARD_FORMAT_KEY = "x-editor-fragment";
|
|
4
4
|
const EDITOR_TO_CLIPBOARD_FORMAT_KEY = /* @__PURE__ */ new WeakMap();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cr as recordOpsToJson, Dn as isElementNode, E as getInternalDocumentChangeEntries, Gr as snapshotEditorJsonValue, H as isUnboundV4DocumentChange, Ii as isRecord, Jt as storedElementIdOf, Li as jsonEqual, Ni as cloneFrozen, O as getInternalDocumentChangeRecords, On as isTextNode, cn as canonicalJsonKey, gt as RootChange, kn as nodeProps, p as createInternalDocumentChange, s as attachLazyV4Steps, t as lawCheckEnabled, tn as DocumentIndex, u as bindV4DocumentChange } from "./law-check-Bvnz2EKh.js";
|
|
2
2
|
//#region src/core/json-fingerprint.ts
|
|
3
3
|
/** Deterministic fingerprint for already validated JSON-compatible data. */
|
|
4
4
|
const fingerprintEditorJson = (value) => {
|
|
@@ -25,11 +25,27 @@ const stableStringify = (value) => {
|
|
|
25
25
|
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`).join(",")}}`;
|
|
26
26
|
};
|
|
27
27
|
const comparisonHash = (value) => fingerprintEditorJson(value);
|
|
28
|
+
const comparisonChangeHashPayload = (change) => {
|
|
29
|
+
try {
|
|
30
|
+
return change.toJSON();
|
|
31
|
+
} catch {
|
|
32
|
+
const records = getInternalDocumentChangeRecords(change);
|
|
33
|
+
return {
|
|
34
|
+
createRoots: [...change.createRoots].sort(),
|
|
35
|
+
deleteRoots: [...change.deleteRoots].sort(),
|
|
36
|
+
...records.size > 0 ? { records: recordOpsToJson(records) } : {},
|
|
37
|
+
roots: [...getInternalDocumentChangeEntries(change)].map(([root, rootChange]) => [root, rootChange.toJSON()]).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
28
41
|
const detachComparisonEnvelope = (input) => {
|
|
29
42
|
if (Array.isArray(input) || typeof input !== "object" || input === null) return null;
|
|
30
|
-
const { meta } = input;
|
|
31
|
-
if (meta === void 0) return null;
|
|
32
|
-
return fingerprintEditorJson(
|
|
43
|
+
const { meta, records } = input;
|
|
44
|
+
if (meta === void 0 && records === void 0) return null;
|
|
45
|
+
return fingerprintEditorJson({
|
|
46
|
+
...meta === void 0 ? {} : { meta: snapshotEditorJsonValue(meta, "Comparison document metadata") },
|
|
47
|
+
...records === void 0 ? {} : { records: snapshotEditorJsonValue(records, "Comparison document records") }
|
|
48
|
+
});
|
|
33
49
|
};
|
|
34
50
|
const detachComparisonDocument = (input, schema) => {
|
|
35
51
|
const candidate = Array.isArray(input) ? { children: input } : input;
|
|
@@ -1353,14 +1369,15 @@ const walkPlan = (input) => {
|
|
|
1353
1369
|
const flags = (kind) => lifecycle.filter((flag) => flag.kind === kind && keep(flag.owners)).map(({ root }) => root);
|
|
1354
1370
|
const createRoots = flags("create");
|
|
1355
1371
|
const deleteRoots = flags("delete");
|
|
1356
|
-
const
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
};
|
|
1363
|
-
|
|
1372
|
+
const rootChanges = /* @__PURE__ */ new Map();
|
|
1373
|
+
if (primary) rootChanges.set("main", RootChange.fromJSON(primary));
|
|
1374
|
+
for (const [root, rootChange] of named) rootChanges.set(root, RootChange.fromJSON(rootChange));
|
|
1375
|
+
const selected = createInternalDocumentChange(rootChanges, {
|
|
1376
|
+
createRoots,
|
|
1377
|
+
deleteRoots
|
|
1378
|
+
});
|
|
1379
|
+
attachLazyV4Steps(selected, before, selected.apply(before));
|
|
1380
|
+
return selected;
|
|
1364
1381
|
};
|
|
1365
1382
|
const change = select("all");
|
|
1366
1383
|
return Object.freeze({
|
|
@@ -1426,7 +1443,12 @@ const comparisonPlanOf = (comparison, schema) => {
|
|
|
1426
1443
|
beforeIndex,
|
|
1427
1444
|
groups: comparison.changes
|
|
1428
1445
|
});
|
|
1429
|
-
|
|
1446
|
+
const rootEntriesJson = (change) => ({
|
|
1447
|
+
createRoots: [...change.createRoots].sort(),
|
|
1448
|
+
deleteRoots: [...change.deleteRoots].sort(),
|
|
1449
|
+
roots: [...getInternalDocumentChangeEntries(change)].map(([root, rootChange]) => [root, rootChange.toJSON()]).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)
|
|
1450
|
+
});
|
|
1451
|
+
if (!(isUnboundV4DocumentChange(comparison.change) ? jsonEqual(bindV4DocumentChange(comparison.change, comparison.before.document).apply(comparison.before.document), plan.change.apply(comparison.before.document)) : jsonEqual(rootEntriesJson(plan.change), rootEntriesJson(comparison.change))) || !sameChanges(plan, comparison.changes)) return null;
|
|
1430
1452
|
PLANS.set(comparison.change, plan);
|
|
1431
1453
|
return plan;
|
|
1432
1454
|
} catch {
|
|
@@ -1441,4 +1463,4 @@ const closeOverRequired = (groups, ids) => {
|
|
|
1441
1463
|
return closed;
|
|
1442
1464
|
};
|
|
1443
1465
|
//#endregion
|
|
1444
|
-
export { uniqueSpans as C, stripComparisonElementIds as S, fingerprintEditorJson as T, fillComparisonElementIds as _, comparisonTextRuns as a, spanKey$1 as b, COMPARISON_POLICY as c,
|
|
1466
|
+
export { uniqueSpans as C, stripComparisonElementIds as S, fingerprintEditorJson as T, fillComparisonElementIds as _, comparisonTextRuns as a, spanKey$1 as b, COMPARISON_POLICY as c, comparisonChangeHashPayload as d, comparisonDocumentsEqual as f, detachComparisonEnvelope as g, detachComparisonDocument as h, comparisonTextPoint as i, COMPARISON_WORD as l, createComparisonSnapshot as m, comparisonPlanOf as n, comparisonTextSpans as o, comparisonHash as p, planComparison as r, createComparisonIndex as s, closeOverRequired as t, assertComparisonActive as u, mergeGroups as v, yieldComparisonWork as w, stableStringify as x, needsComparisonElementIds as y };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Wi as getDefined, Xr as defineEffect, ai as MAIN_ROOT_KEY, hi as PathApi, ii as PointApi, ni as LocationApi, oi as getCommonLocationRoot, ti as RangeApi } from "./law-check-Bvnz2EKh.js";
|
|
2
|
+
import { $a as previous, Al as authoredDocumentCapabilityPoint, As as createEditorReadApi, At as isVoid, Au as getPluginRegistry, Bc as constructLoadedDocumentChange, Bt as path$1, Cc as mapDetachedSelectionThroughChange, Cn as applyTransactionSpecToDocument, Co as nodes, Cu as setEditorLifecycleErrorSink, Ds as subscribe, Dt as isInline, Du as getCompiledEditorSchema, Ed as SelectionApi, Et as isEnd$1, Eu as finalizePluginRegistry, Fr as initializePublicState, Fu as registerEffectTypeInRegistry, G as before, Ga as range$1, Gn as getChildren$1, Gr as readEditor, Gt as range, H as above, Hr as loadOpenedRecords, Hs as admitDocument, Ic as loadElementIds, Id as getEditorRuntime, Ir as invalidateEditorTransactionSpecs, Ka as above$1, Ks as onlyDocumentAdmission, M as createCommandDispatch, Ma as getFragment, Md as isEditorContent, Ml as createEditorAnchorApi, Mr as initializeEditorSchemaDocument, Mu as initializeBasePluginRegistry, Ni as transformEditorSnapshotInput, Nr as initializeEditorSchemaSelection, Os as subscribeCommit, Pi as updateEditor, Pr as initializeEditorSchemaSnapshot, Qn as getEditorChildrenRoot, Ri as withEditorRootChildren, To as node, Tt as isEmpty$1, Tu as createPluginRegistry, Us as admitEditorDocument, V as NodeApi, Vd as setEditorRuntime, Vt as point, W as after, Wn as getChildList, Ws as documentAdmissionPoint, Xn as getCurrentSelection, Yl as assertNoDocumentViewRead, Zn as getCurrentSelectionRoot, _ as markEditorDormant, _c as assertSelectionSupported, _r as getPathByNodeKey, bd as failInvariant, d as extendEditor, dr as getLiveNode, eo as elementReadOnly, fn as voidEditor, fr as getLiveSelection, ft as hasInlines$1, hr as getNodeKey, io as after$1, jc as isEmptyElement, js as createEditorUpdateApi, jt as last$1, kn as createTransactionSpec, ks as subscribeSource, kt as isStart$1, ku as getPluginContributions, li as seedUniqueMaps, lo as getCharacterDistance, nc as createDetachedEditorSchema, ni as repairEditorValue, nt as getChildren, nu as hasActiveAnchors, oo as resolveShouldMergeNodesRemovePrevNode, pr as getLiveText, qs as repairLoadedDocument, rc as createEditorSchema, ro as before$1, s as createEditorViewPluginApis, si as saveEditorSchemaDocument, tr as getEditorDocumentValue, u as destroyEditor, uo as getWordDistances, ur as getLastCommit, ut as getSnapshot, v as prepareInitialPluginPublication, wc as mapSelectionThroughChange, wd as point$1, wi as snapshotInitialDocumentState, wo as normalizeNodeMatch, wu as assertPluginPublicationInactive, xr as getSnapshot$1, xt as isBlock$1, y as prepareScopedPluginPublication, zd as getEditorSchema, zi as withEditorRootChildrenGenerator, zt as parent$1 } from "./plugin-B8uCi-Hr.js";
|
|
2
3
|
/**
|
|
3
4
|
* Local, ephemeral screen-reader text emitted by an application command.
|
|
4
5
|
*
|
|
@@ -12,31 +13,6 @@ const screenReaderAnnouncementEffect = defineEffect({
|
|
|
12
13
|
});
|
|
13
14
|
const getScreenReaderAnnouncements = (effects) => effects.flatMap((effect) => effect.type.key === "screen-reader-announcement" && typeof effect.value === "string" && effect.value.trim().length > 0 ? [effect.value] : []);
|
|
14
15
|
//#endregion
|
|
15
|
-
//#region src/editor/above.ts
|
|
16
|
-
const assertNumericPath = (path) => {
|
|
17
|
-
for (const index of path) if (typeof index !== "number") throw new Error("Got non-numeric path index");
|
|
18
|
-
};
|
|
19
|
-
const above = ((editor, options = {}) => {
|
|
20
|
-
const { voids = false, mode = "lowest", at = getSnapshot(editor).selection, match, type } = options;
|
|
21
|
-
if (!at || !LocationApi.isLocation(at)) return;
|
|
22
|
-
let path;
|
|
23
|
-
path = path$1(editor, at);
|
|
24
|
-
assertNumericPath(path);
|
|
25
|
-
if (!LocationApi.isRange(at) || PathApi.equals(at.focus.path, at.anchor.path)) {
|
|
26
|
-
if (path.length === 0) return void 0;
|
|
27
|
-
path = PathApi.parent(path);
|
|
28
|
-
}
|
|
29
|
-
if (!NodeApi.has(editor, path)) return;
|
|
30
|
-
const [firstMatch] = levels$1(editor, {
|
|
31
|
-
at: path,
|
|
32
|
-
voids,
|
|
33
|
-
match,
|
|
34
|
-
reverse: mode === "lowest",
|
|
35
|
-
type
|
|
36
|
-
});
|
|
37
|
-
return firstMatch;
|
|
38
|
-
});
|
|
39
|
-
//#endregion
|
|
40
16
|
//#region src/editor/edges.ts
|
|
41
17
|
const edges = (editor, at) => [point(editor, at, { edge: "start" }), point(editor, at, { edge: "end" })];
|
|
42
18
|
//#endregion
|
|
@@ -46,7 +22,7 @@ const first = (editor, at) => {
|
|
|
46
22
|
};
|
|
47
23
|
//#endregion
|
|
48
24
|
//#region src/editor/get-void.ts
|
|
49
|
-
const getVoid = (editor, options = {}) => above
|
|
25
|
+
const getVoid = (editor, options = {}) => above(editor, {
|
|
50
26
|
...options,
|
|
51
27
|
match: (n) => NodeApi.isElement(n) && isVoid(editor, n)
|
|
52
28
|
});
|
|
@@ -198,7 +174,7 @@ const comparePoints = (left, right) => {
|
|
|
198
174
|
};
|
|
199
175
|
const getAtomicNonTraversablePoint = (editor, path, voids) => {
|
|
200
176
|
if (voids) return null;
|
|
201
|
-
const atomicEntry = above
|
|
177
|
+
const atomicEntry = above(editor, {
|
|
202
178
|
at: path,
|
|
203
179
|
match: (node) => NodeApi.isElement(node) && (getEditorSchema(editor).isAtom(node) || getEditorSchema(editor).isReadOnly(node)),
|
|
204
180
|
mode: "highest",
|
|
@@ -588,7 +564,7 @@ const unhangRange = (editor, range, options = {}) => {
|
|
|
588
564
|
const [start, initialEnd] = RangeApi.edges(range);
|
|
589
565
|
let end = initialEnd;
|
|
590
566
|
if (start.offset !== 0 || end.offset !== 0 || RangeApi.isCollapsed(range) || PathApi.hasPrevious(end.path)) return inputRange;
|
|
591
|
-
const endBlock = above
|
|
567
|
+
const endBlock = above(editor, {
|
|
592
568
|
at: end,
|
|
593
569
|
match: (n) => NodeApi.isElement(n) && isBlock$1(editor, n),
|
|
594
570
|
voids
|
|
@@ -656,7 +632,7 @@ const withExplicitRangeRoot = (innerRange, root) => root ? {
|
|
|
656
632
|
focus: withExplicitPointRoot(innerRange.focus, root)
|
|
657
633
|
} : innerRange;
|
|
658
634
|
const createEditorReadRuntime = (editor) => ({
|
|
659
|
-
above: (options) => (({ options: innerOptions }) => withOptionsQueryRoot(editor, innerOptions, () => above(editor, innerOptions), { selectionFallback: usesImplicitSelectionLocation(innerOptions) }))({ options }),
|
|
635
|
+
above: (options) => (({ options: innerOptions }) => withOptionsQueryRoot(editor, innerOptions, () => above$1(editor, innerOptions), { selectionFallback: usesImplicitSelectionLocation(innerOptions) }))({ options }),
|
|
660
636
|
after: (at, options) => (({ at: innerAt, options: innerOptions2 }) => {
|
|
661
637
|
const root = getQueryRoot(editor, [innerAt]);
|
|
662
638
|
return withQueryRoot(editor, [innerAt], () => withExplicitPointRoot(after$1(editor, innerAt, innerOptions2), root));
|
package/dist/diff/index.d.ts
CHANGED
|
@@ -1,32 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/diff/lib/compare.d.ts
|
|
4
|
-
type TwoWayInput<V extends Value> = Readonly<{
|
|
5
|
-
after: unknown;
|
|
6
|
-
before: unknown;
|
|
7
|
-
projection?: Readonly<{
|
|
8
|
-
after: 'accepted' | 'proposed';
|
|
9
|
-
before: 'accepted' | 'proposed';
|
|
10
|
-
}>;
|
|
11
|
-
schema: EditorStateSchemaApi<V>;
|
|
12
|
-
signal?: AbortSignal;
|
|
13
|
-
}>;
|
|
14
|
-
type ThreeWayInput<V extends Value> = Readonly<{
|
|
15
|
-
base: unknown;
|
|
16
|
-
local: unknown;
|
|
17
|
-
remote: unknown;
|
|
18
|
-
schema: EditorStateSchemaApi<V>;
|
|
19
|
-
signal?: AbortSignal;
|
|
20
|
-
}>;
|
|
21
|
-
/** Compare immutable schema-valid documents without installing editor state. */
|
|
22
|
-
declare function compare<V extends Value>(input: ThreeWayInput<V>): Promise<ThreeWayComparison<V>>;
|
|
23
|
-
declare function compare<V extends Value>(input: TwoWayInput<V>): Promise<TwoWayComparison<V>>;
|
|
24
|
-
/** Resolve one published three-way comparison without rematching its inputs. */
|
|
25
|
-
declare function resolveComparison<V extends Value>(input: Readonly<{
|
|
26
|
-
baseline: 'base' | ComparisonBranch;
|
|
27
|
-
comparison: ThreeWayComparison<V>;
|
|
28
|
-
resolutions?: readonly ComparisonResolution[];
|
|
29
|
-
signal?: AbortSignal;
|
|
30
|
-
}>): Promise<ComparisonResolutionResult<V>>;
|
|
31
|
-
//#endregion
|
|
32
|
-
export { ComparedChange, Comparison, ComparisonBranch, ComparisonConflict, ComparisonConflictAlternative, ComparisonCorrespondence, ComparisonDiagnostic, ComparisonEffect, ComparisonEvidence, ComparisonResolution, ComparisonResolutionResult, ComparisonSnapshot, ComparisonSpan, ThreeWayComparison, TwoWayComparison, compare, resolveComparison };
|
|
1
|
+
import { a as ComparisonDiagnostic, c as ComparisonSnapshot, i as ComparisonCorrespondence, l as ComparisonSpan, n as ComparedChange, o as ComparisonEffect, r as Comparison, s as ComparisonEvidence, t as compare } from "../index-DM-b6jEe.js";
|
|
2
|
+
export { ComparedChange, Comparison, ComparisonCorrespondence, ComparisonDiagnostic, ComparisonEffect, ComparisonEvidence, ComparisonSnapshot, ComparisonSpan, compare };
|
package/dist/diff/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { C as uniqueSpans
|
|
1
|
+
import { Li as jsonEqual } from "../law-check-Bvnz2EKh.js";
|
|
2
|
+
import { C as uniqueSpans, S as stripComparisonElementIds, _ as fillComparisonElementIds, a as comparisonTextRuns, b as spanKey, c as COMPARISON_POLICY, d as comparisonChangeHashPayload, f as comparisonDocumentsEqual, g as detachComparisonEnvelope, h as detachComparisonDocument, i as comparisonTextPoint, l as COMPARISON_WORD, m as createComparisonSnapshot, o as comparisonTextSpans, p as comparisonHash, r as planComparison, s as createComparisonIndex, u as assertComparisonActive, v as mergeGroups, w as yieldComparisonWork, x as stableStringify, y as needsComparisonElementIds } from "../comparison-plan-BqFJWjO4.js";
|
|
3
3
|
import { DiffMatchPatch, DiffOp } from "diff-match-patch-ts";
|
|
4
4
|
//#region src/diff/lib/comparison-matcher.ts
|
|
5
5
|
const CANDIDATES_PER_NODE = 24;
|
|
@@ -1255,7 +1255,7 @@ const matchComparison = async (before, after, comparisonId, options) => {
|
|
|
1255
1255
|
}
|
|
1256
1256
|
const beforeNodeBySpan = new Map(beforeElements.map((node) => [spanKey(node.span), node]));
|
|
1257
1257
|
const afterNodeBySpan = new Map(afterElements.map((node) => [spanKey(node.span), node]));
|
|
1258
|
-
const unsupportedSpans = uniqueSpans
|
|
1258
|
+
const unsupportedSpans = uniqueSpans(changes.flatMap(({ effects }) => effects.flatMap((effect) => {
|
|
1259
1259
|
if (effect.kind !== "structure" && effect.kind !== "wrapper" && effect.kind !== "node-type") return [];
|
|
1260
1260
|
return [...effect.before.filter((value) => {
|
|
1261
1261
|
const node = beforeNodeBySpan.get(spanKey(value));
|
|
@@ -1322,7 +1322,6 @@ const matchComparison = async (before, after, comparisonId, options) => {
|
|
|
1322
1322
|
};
|
|
1323
1323
|
//#endregion
|
|
1324
1324
|
//#region src/diff/lib/compare.ts
|
|
1325
|
-
const THREE_WAY_STATE = /* @__PURE__ */ new WeakMap();
|
|
1326
1325
|
const allRootSpans = (index) => Object.freeze([...index.roots.values()].map(({ length, name }) => Object.freeze({
|
|
1327
1326
|
from: 0,
|
|
1328
1327
|
root: name,
|
|
@@ -1365,115 +1364,6 @@ const coarseFallback = (id, before, after) => {
|
|
|
1365
1364
|
})
|
|
1366
1365
|
});
|
|
1367
1366
|
};
|
|
1368
|
-
const groupSemanticKey = (group) => comparisonHash({
|
|
1369
|
-
after: group.after,
|
|
1370
|
-
before: group.before,
|
|
1371
|
-
correspondence: group.correspondence.map(({ after, before, evidence, kind }) => ({
|
|
1372
|
-
after,
|
|
1373
|
-
before,
|
|
1374
|
-
evidence,
|
|
1375
|
-
kind
|
|
1376
|
-
})),
|
|
1377
|
-
effects: group.effects.map(({ id: _id, ...effect }) => effect),
|
|
1378
|
-
evidence: group.evidence
|
|
1379
|
-
});
|
|
1380
|
-
const publishThreeWayGroup = (comparisonId, index, group, branches) => {
|
|
1381
|
-
const id = `${comparisonId}:change:${index}`;
|
|
1382
|
-
return Object.freeze({
|
|
1383
|
-
after: group.after,
|
|
1384
|
-
before: group.before,
|
|
1385
|
-
branches: Object.freeze([...branches]),
|
|
1386
|
-
correspondence: Object.freeze(group.correspondence.map((item, correspondenceIndex) => Object.freeze({
|
|
1387
|
-
...item,
|
|
1388
|
-
id: `${id}:correspondence:${correspondenceIndex}`
|
|
1389
|
-
}))),
|
|
1390
|
-
effects: Object.freeze(group.effects.map((effect, effectIndex) => Object.freeze({
|
|
1391
|
-
...effect,
|
|
1392
|
-
id: `${id}:effect:${effectIndex}`
|
|
1393
|
-
}))),
|
|
1394
|
-
evidence: group.evidence,
|
|
1395
|
-
id,
|
|
1396
|
-
requiredChangeIds: Object.freeze([])
|
|
1397
|
-
});
|
|
1398
|
-
};
|
|
1399
|
-
const spansTouch = (left, right) => left.some((a) => right.some((b) => {
|
|
1400
|
-
if (a.root !== b.root) return false;
|
|
1401
|
-
if (a.from === a.to && b.from === b.to) return a.from === b.from;
|
|
1402
|
-
if (a.from === a.to) return b.from <= a.from && a.from <= b.to;
|
|
1403
|
-
if (b.from === b.to) return a.from <= b.from && b.from <= a.to;
|
|
1404
|
-
return Math.max(a.from, b.from) < Math.min(a.to, b.to);
|
|
1405
|
-
}));
|
|
1406
|
-
const propertyKeys = (group) => new Set(group.effects.flatMap((effect) => effect.kind === "property" ? [...effect.beforeProperties, ...effect.afterProperties].flatMap(Object.keys) : []));
|
|
1407
|
-
const groupsConflict = (left, right) => {
|
|
1408
|
-
if (!spansTouch(left.before, right.before)) return false;
|
|
1409
|
-
const leftKinds = new Set(left.effects.map(({ kind }) => kind));
|
|
1410
|
-
const rightKinds = new Set(right.effects.map(({ kind }) => kind));
|
|
1411
|
-
if (leftKinds.size === 1 && leftKinds.has("placement") && [...rightKinds].every((kind) => kind === "text" || kind === "property") || rightKinds.size === 1 && rightKinds.has("placement") && [...leftKinds].every((kind) => kind === "text" || kind === "property")) return false;
|
|
1412
|
-
if ([...leftKinds].every((kind) => kind === "property") && [...rightKinds].every((kind) => kind === "property")) {
|
|
1413
|
-
const rightProperties = propertyKeys(right);
|
|
1414
|
-
return [...propertyKeys(left)].some((key) => rightProperties.has(key));
|
|
1415
|
-
}
|
|
1416
|
-
return true;
|
|
1417
|
-
};
|
|
1418
|
-
const conflictKind = (local, remote, gridSpans) => {
|
|
1419
|
-
const effects = [...local, ...remote].flatMap(({ effects: value }) => value);
|
|
1420
|
-
const kinds = new Set(effects.map(({ kind }) => kind));
|
|
1421
|
-
if (kinds.has("root-create") || kinds.has("root-delete")) return "root";
|
|
1422
|
-
if ([...local, ...remote].some(({ before }) => spansTouch(before, gridSpans))) return "grid";
|
|
1423
|
-
if (kinds.has("delete") && [...kinds].some((kind) => kind !== "delete" && kind !== "structure")) return "delete-edit";
|
|
1424
|
-
if (kinds.has("placement")) return "placement";
|
|
1425
|
-
if (local.every(({ effects: value }) => value.some(({ kind }) => kind === "insert")) && remote.every(({ effects: value }) => value.some(({ kind }) => kind === "insert"))) return "order";
|
|
1426
|
-
return "structure";
|
|
1427
|
-
};
|
|
1428
|
-
const uniqueSpans = (spans) => Object.freeze([...new Map(spans.map((span) => [`${span.root}:${span.from}:${span.to}`, span])).values()]);
|
|
1429
|
-
const buildConflicts = (comparisonId, local, remote, gridSpans) => {
|
|
1430
|
-
const { find, join } = disjointSets(local.length + remote.length);
|
|
1431
|
-
const edges = local.flatMap((localGroup, localIndex) => remote.flatMap((remoteGroup, remoteIndex) => groupsConflict(localGroup, remoteGroup) ? [[localIndex, local.length + remoteIndex]] : []));
|
|
1432
|
-
for (const [left, right] of edges) join(left, right);
|
|
1433
|
-
for (const [offset, branchGroups] of [[0, local], [local.length, remote]]) {
|
|
1434
|
-
const indexById = new Map(branchGroups.map(({ id: groupId }, index) => [groupId, offset + index]));
|
|
1435
|
-
branchGroups.forEach(({ requiredChangeIds }, index) => {
|
|
1436
|
-
for (const requiredId of requiredChangeIds) {
|
|
1437
|
-
const required = indexById.get(requiredId);
|
|
1438
|
-
if (required !== void 0) join(offset + index, required);
|
|
1439
|
-
}
|
|
1440
|
-
});
|
|
1441
|
-
}
|
|
1442
|
-
const components = [...new Set(edges.map(([left]) => find(left)))].map((root) => ({
|
|
1443
|
-
local: local.filter((_group, index) => find(index) === root),
|
|
1444
|
-
remote: remote.filter((_group, index) => find(local.length + index) === root)
|
|
1445
|
-
}));
|
|
1446
|
-
return Object.freeze(components.map((component, index) => {
|
|
1447
|
-
const localGroups = [...component.local];
|
|
1448
|
-
const remoteGroups = [...component.remote];
|
|
1449
|
-
const localIds = Object.freeze(localGroups.map(({ id }) => id));
|
|
1450
|
-
const remoteIds = Object.freeze(remoteGroups.map(({ id }) => id));
|
|
1451
|
-
const kind = conflictKind(localGroups, remoteGroups, gridSpans);
|
|
1452
|
-
const changeIds = Object.freeze([...localIds, ...remoteIds]);
|
|
1453
|
-
const requiredChangeIds = Object.freeze([...new Set([...localGroups, ...remoteGroups].flatMap(({ requiredChangeIds: ids }) => ids))].filter((id) => !changeIds.includes(id)));
|
|
1454
|
-
return Object.freeze({
|
|
1455
|
-
base: uniqueSpans([...localGroups, ...remoteGroups].flatMap(({ before }) => before)),
|
|
1456
|
-
changeIds,
|
|
1457
|
-
id: `${comparisonId}:conflict:${index}:${comparisonHash({
|
|
1458
|
-
kind,
|
|
1459
|
-
localIds,
|
|
1460
|
-
remoteIds
|
|
1461
|
-
})}`,
|
|
1462
|
-
kind,
|
|
1463
|
-
local: Object.freeze({
|
|
1464
|
-
branch: "local",
|
|
1465
|
-
changeIds: localIds,
|
|
1466
|
-
spans: uniqueSpans(localGroups.flatMap(({ after }) => after))
|
|
1467
|
-
}),
|
|
1468
|
-
remote: Object.freeze({
|
|
1469
|
-
branch: "remote",
|
|
1470
|
-
changeIds: remoteIds,
|
|
1471
|
-
spans: uniqueSpans(remoteGroups.flatMap(({ after }) => after))
|
|
1472
|
-
}),
|
|
1473
|
-
requiredChangeIds
|
|
1474
|
-
});
|
|
1475
|
-
}));
|
|
1476
|
-
};
|
|
1477
1367
|
const rekeyComparedChanges = (changes, fromPrefix, toPrefix) => {
|
|
1478
1368
|
const rekey = (value) => value.startsWith(fromPrefix) ? `${toPrefix}${value.slice(fromPrefix.length)}` : value;
|
|
1479
1369
|
return Object.freeze(changes.map((group) => Object.freeze({
|
|
@@ -1490,7 +1380,8 @@ const rekeyComparedChanges = (changes, fromPrefix, toPrefix) => {
|
|
|
1490
1380
|
requiredChangeIds: Object.freeze(group.requiredChangeIds.map(rekey))
|
|
1491
1381
|
})));
|
|
1492
1382
|
};
|
|
1493
|
-
|
|
1383
|
+
/** Compare two immutable schema-valid documents without installing editor state. */
|
|
1384
|
+
async function compare(input) {
|
|
1494
1385
|
assertComparisonActive(input.signal);
|
|
1495
1386
|
const beforeEnvelopeFingerprint = detachComparisonEnvelope(input.before);
|
|
1496
1387
|
const afterEnvelopeFingerprint = detachComparisonEnvelope(input.after);
|
|
@@ -1559,7 +1450,7 @@ const compareTwoWay = async (input) => {
|
|
|
1559
1450
|
if (!comparisonDocumentsEqual(change.invert(beforeDocument).apply(afterDocument), beforeDocument)) throw new Error("Comparison inverse does not reconstruct the source document.");
|
|
1560
1451
|
assertComparisonActive(input.signal);
|
|
1561
1452
|
const comparisonId = `${id}:${comparisonHash({
|
|
1562
|
-
change: change
|
|
1453
|
+
change: comparisonChangeHashPayload(change),
|
|
1563
1454
|
changes,
|
|
1564
1455
|
diagnostics
|
|
1565
1456
|
})}`;
|
|
@@ -1570,270 +1461,8 @@ const compareTwoWay = async (input) => {
|
|
|
1570
1461
|
changes,
|
|
1571
1462
|
diagnostics,
|
|
1572
1463
|
id: comparisonId,
|
|
1573
|
-
kind: "two-way",
|
|
1574
1464
|
policy: COMPARISON_POLICY
|
|
1575
1465
|
});
|
|
1576
|
-
};
|
|
1577
|
-
const alignThreeWayBase = async (input) => {
|
|
1578
|
-
const rawBase = detachComparisonDocument(input.base, input.schema);
|
|
1579
|
-
if (needsComparisonElementIds(detachComparisonDocument(input.remote, input.schema), rawBase)) return (await compareTwoWay({
|
|
1580
|
-
after: input.base,
|
|
1581
|
-
before: input.remote,
|
|
1582
|
-
schema: input.schema,
|
|
1583
|
-
signal: input.signal
|
|
1584
|
-
})).after.document;
|
|
1585
|
-
if (needsComparisonElementIds(detachComparisonDocument(input.local, input.schema), rawBase)) return (await compareTwoWay({
|
|
1586
|
-
after: input.base,
|
|
1587
|
-
before: input.local,
|
|
1588
|
-
schema: input.schema,
|
|
1589
|
-
signal: input.signal
|
|
1590
|
-
})).after.document;
|
|
1591
|
-
return input.base;
|
|
1592
|
-
};
|
|
1593
|
-
const compareThreeWay = async (input) => {
|
|
1594
|
-
assertComparisonActive(input.signal);
|
|
1595
|
-
const alignedBase = await alignThreeWayBase(input);
|
|
1596
|
-
const [local, remote] = await Promise.all([compareTwoWay({
|
|
1597
|
-
after: input.local,
|
|
1598
|
-
before: alignedBase,
|
|
1599
|
-
schema: input.schema,
|
|
1600
|
-
signal: input.signal
|
|
1601
|
-
}), compareTwoWay({
|
|
1602
|
-
after: input.remote,
|
|
1603
|
-
before: alignedBase,
|
|
1604
|
-
schema: input.schema,
|
|
1605
|
-
signal: input.signal
|
|
1606
|
-
})]);
|
|
1607
|
-
const base = local.before;
|
|
1608
|
-
const id = `comparison:${comparisonHash({
|
|
1609
|
-
base: base.fingerprint,
|
|
1610
|
-
local: local.after.fingerprint,
|
|
1611
|
-
policy: COMPARISON_POLICY,
|
|
1612
|
-
remote: remote.after.fingerprint
|
|
1613
|
-
})}`;
|
|
1614
|
-
const localIds = /* @__PURE__ */ new Map();
|
|
1615
|
-
const remoteIds = /* @__PURE__ */ new Map();
|
|
1616
|
-
const commonRemoteIds = /* @__PURE__ */ new Set();
|
|
1617
|
-
const remoteByKey = /* @__PURE__ */ new Map();
|
|
1618
|
-
for (const group of remote.changes) {
|
|
1619
|
-
const key = groupSemanticKey(group);
|
|
1620
|
-
const bucket = remoteByKey.get(key) ?? [];
|
|
1621
|
-
bucket.push(group);
|
|
1622
|
-
remoteByKey.set(key, bucket);
|
|
1623
|
-
}
|
|
1624
|
-
const staged = [];
|
|
1625
|
-
for (const group of local.changes) {
|
|
1626
|
-
const matching = remoteByKey.get(groupSemanticKey(group))?.shift();
|
|
1627
|
-
staged.push(Object.freeze({
|
|
1628
|
-
branches: matching ? Object.freeze(["local", "remote"]) : Object.freeze(["local"]),
|
|
1629
|
-
group,
|
|
1630
|
-
localId: group.id,
|
|
1631
|
-
...matching ? { remoteId: matching.id } : {}
|
|
1632
|
-
}));
|
|
1633
|
-
}
|
|
1634
|
-
for (const groups of remoteByKey.values()) for (const group of groups) staged.push(Object.freeze({
|
|
1635
|
-
branches: Object.freeze(["remote"]),
|
|
1636
|
-
group,
|
|
1637
|
-
remoteId: group.id
|
|
1638
|
-
}));
|
|
1639
|
-
const published = staged.map((item, index) => {
|
|
1640
|
-
const group = publishThreeWayGroup(id, index, item.group, item.branches);
|
|
1641
|
-
if (item.localId) localIds.set(group.id, item.localId);
|
|
1642
|
-
if (item.remoteId) {
|
|
1643
|
-
remoteIds.set(group.id, item.remoteId);
|
|
1644
|
-
if (item.localId) commonRemoteIds.add(group.id);
|
|
1645
|
-
}
|
|
1646
|
-
return group;
|
|
1647
|
-
});
|
|
1648
|
-
const localPublicBySource = new Map([...localIds].map(([publishedId, sourceId]) => [sourceId, publishedId]));
|
|
1649
|
-
const remotePublicBySource = new Map([...remoteIds].map(([publishedId, sourceId]) => [sourceId, publishedId]));
|
|
1650
|
-
const changes = Object.freeze(published.map((group, index) => {
|
|
1651
|
-
const source = staged[index];
|
|
1652
|
-
if (!source) throw new Error("Missing three-way comparison source.");
|
|
1653
|
-
const requiredChangeIds = Object.freeze([...new Set([...source.localId ? local.changes.find(({ id: sourceId }) => sourceId === source.localId)?.requiredChangeIds.map((sourceId) => localPublicBySource.get(sourceId)) ?? [] : [], ...source.remoteId ? remote.changes.find(({ id: sourceId }) => sourceId === source.remoteId)?.requiredChangeIds.map((sourceId) => remotePublicBySource.get(sourceId)) ?? [] : []].filter((required) => Boolean(required && required !== group.id)))]);
|
|
1654
|
-
return Object.freeze({
|
|
1655
|
-
...group,
|
|
1656
|
-
requiredChangeIds
|
|
1657
|
-
});
|
|
1658
|
-
}));
|
|
1659
|
-
const localGroups = changes.filter(({ branches }) => branches?.includes("local"));
|
|
1660
|
-
const remoteGroups = changes.filter(({ branches, id: groupId }) => branches?.includes("remote") && !commonRemoteIds.has(groupId));
|
|
1661
|
-
const gridSpans = createComparisonIndex(base.document, input.schema).nodes.flatMap(({ span, structure }) => structure?.kind === "grid" ? [span] : []);
|
|
1662
|
-
const conflicts = buildConflicts(id, localGroups, remoteGroups, gridSpans);
|
|
1663
|
-
const diagnostics = Object.freeze([
|
|
1664
|
-
...local.diagnostics,
|
|
1665
|
-
...remote.diagnostics,
|
|
1666
|
-
...conflicts.length > 0 ? [Object.freeze({
|
|
1667
|
-
code: "ambiguous",
|
|
1668
|
-
message: "Concurrent branch contributions require explicit conflict resolution.",
|
|
1669
|
-
severity: "warning",
|
|
1670
|
-
spans: uniqueSpans(conflicts.flatMap(({ base: spans }) => spans))
|
|
1671
|
-
})] : []
|
|
1672
|
-
]);
|
|
1673
|
-
const comparisonId = `${id}:${comparisonHash({
|
|
1674
|
-
changes,
|
|
1675
|
-
conflicts,
|
|
1676
|
-
diagnostics
|
|
1677
|
-
})}`;
|
|
1678
|
-
const comparison = Object.freeze({
|
|
1679
|
-
base,
|
|
1680
|
-
changes,
|
|
1681
|
-
conflicts,
|
|
1682
|
-
diagnostics,
|
|
1683
|
-
id: comparisonId,
|
|
1684
|
-
kind: "three-way",
|
|
1685
|
-
local: local.after,
|
|
1686
|
-
policy: COMPARISON_POLICY,
|
|
1687
|
-
remote: remote.after
|
|
1688
|
-
});
|
|
1689
|
-
THREE_WAY_STATE.set(comparison, Object.freeze({
|
|
1690
|
-
local,
|
|
1691
|
-
localIds,
|
|
1692
|
-
remote,
|
|
1693
|
-
remoteIds,
|
|
1694
|
-
schema: input.schema
|
|
1695
|
-
}));
|
|
1696
|
-
return comparison;
|
|
1697
|
-
};
|
|
1698
|
-
function compare(input) {
|
|
1699
|
-
return "base" in input ? compareThreeWay(input) : compareTwoWay(input);
|
|
1700
|
-
}
|
|
1701
|
-
const invalidResolution = (message) => Object.freeze({
|
|
1702
|
-
diagnostics: Object.freeze([Object.freeze({
|
|
1703
|
-
code: "invalid-resolution",
|
|
1704
|
-
message,
|
|
1705
|
-
severity: "warning"
|
|
1706
|
-
})]),
|
|
1707
|
-
status: "invalid"
|
|
1708
|
-
});
|
|
1709
|
-
const annotateResolvedComparison = (comparison, branches) => {
|
|
1710
|
-
if (comparison.changes.length === 0 || branches.length === 0) return comparison;
|
|
1711
|
-
const changes = Object.freeze(comparison.changes.map((group) => Object.freeze({
|
|
1712
|
-
...group,
|
|
1713
|
-
branches: Object.freeze([...branches])
|
|
1714
|
-
})));
|
|
1715
|
-
const prefix = `comparison:${comparisonHash({
|
|
1716
|
-
after: comparison.after.fingerprint,
|
|
1717
|
-
before: comparison.before.fingerprint,
|
|
1718
|
-
policy: comparison.policy
|
|
1719
|
-
})}`;
|
|
1720
|
-
return Object.freeze({
|
|
1721
|
-
...comparison,
|
|
1722
|
-
changes,
|
|
1723
|
-
id: `${prefix}:${comparisonHash({
|
|
1724
|
-
change: comparison.change.toJSON(),
|
|
1725
|
-
changes,
|
|
1726
|
-
diagnostics: comparison.diagnostics
|
|
1727
|
-
})}`
|
|
1728
|
-
});
|
|
1729
|
-
};
|
|
1730
|
-
const restoreBaselineSnapshot = (comparison, before) => {
|
|
1731
|
-
const prefix = `comparison:${comparisonHash({
|
|
1732
|
-
after: comparison.after.fingerprint,
|
|
1733
|
-
before: before.fingerprint,
|
|
1734
|
-
policy: comparison.policy
|
|
1735
|
-
})}`;
|
|
1736
|
-
return Object.freeze({
|
|
1737
|
-
...comparison,
|
|
1738
|
-
before,
|
|
1739
|
-
id: `${prefix}:${comparisonHash({
|
|
1740
|
-
change: comparison.change.toJSON(),
|
|
1741
|
-
changes: comparison.changes,
|
|
1742
|
-
diagnostics: comparison.diagnostics
|
|
1743
|
-
})}`
|
|
1744
|
-
});
|
|
1745
|
-
};
|
|
1746
|
-
/** Resolve one published three-way comparison without rematching its inputs. */
|
|
1747
|
-
async function resolveComparison(input) {
|
|
1748
|
-
assertComparisonActive(input.signal);
|
|
1749
|
-
const state = THREE_WAY_STATE.get(input.comparison);
|
|
1750
|
-
if (!state) return invalidResolution("The comparison was not created by this resolver.");
|
|
1751
|
-
const resolutions = input.resolutions ?? [];
|
|
1752
|
-
const byConflict = /* @__PURE__ */ new Map();
|
|
1753
|
-
for (const resolution of resolutions) {
|
|
1754
|
-
if (resolution.comparisonId !== input.comparison.id || byConflict.has(resolution.conflictId) || !input.comparison.conflicts.some(({ id }) => id === resolution.conflictId)) return invalidResolution("A resolution has an unknown, duplicate, or stale comparison identity.");
|
|
1755
|
-
byConflict.set(resolution.conflictId, resolution);
|
|
1756
|
-
}
|
|
1757
|
-
const unresolved = input.comparison.conflicts.filter(({ id }) => !byConflict.has(id));
|
|
1758
|
-
if (unresolved.length > 0) return Object.freeze({
|
|
1759
|
-
conflicts: Object.freeze([...unresolved]),
|
|
1760
|
-
status: "unresolved"
|
|
1761
|
-
});
|
|
1762
|
-
const customChoices = resolutions.filter(({ choice }) => typeof choice === "object");
|
|
1763
|
-
if (customChoices.length > 0) {
|
|
1764
|
-
if (customChoices.length !== resolutions.length || customChoices.length !== input.comparison.conflicts.length) return invalidResolution("Custom resolution documents must resolve every conflict together.");
|
|
1765
|
-
let target;
|
|
1766
|
-
try {
|
|
1767
|
-
const custom = customChoices[0];
|
|
1768
|
-
if (!custom) return invalidResolution("A custom resolution target is missing.");
|
|
1769
|
-
target = detachComparisonDocument(custom.choice.document, state.schema);
|
|
1770
|
-
if (customChoices.some(({ choice }) => {
|
|
1771
|
-
return !comparisonDocumentsEqual(detachComparisonDocument(choice.document, state.schema), target);
|
|
1772
|
-
})) return invalidResolution("Custom resolutions must name one identical target document.");
|
|
1773
|
-
} catch {
|
|
1774
|
-
return invalidResolution("A custom resolution document does not satisfy the comparison schema.");
|
|
1775
|
-
}
|
|
1776
|
-
const baseline = input.comparison[input.baseline];
|
|
1777
|
-
const comparison = restoreBaselineSnapshot(await compareTwoWay({
|
|
1778
|
-
after: target,
|
|
1779
|
-
before: baseline.document,
|
|
1780
|
-
schema: state.schema,
|
|
1781
|
-
signal: input.signal
|
|
1782
|
-
}), baseline);
|
|
1783
|
-
return Object.freeze({
|
|
1784
|
-
comparison,
|
|
1785
|
-
status: "resolved"
|
|
1786
|
-
});
|
|
1787
|
-
}
|
|
1788
|
-
const excludedLocal = /* @__PURE__ */ new Set();
|
|
1789
|
-
const excludedRemote = /* @__PURE__ */ new Set();
|
|
1790
|
-
for (const conflict of input.comparison.conflicts) {
|
|
1791
|
-
const choice = byConflict.get(conflict.id)?.choice;
|
|
1792
|
-
if (choice === "local") for (const groupId of conflict.remote.changeIds) excludedRemote.add(groupId);
|
|
1793
|
-
else if (choice === "remote") for (const groupId of conflict.local.changeIds) excludedLocal.add(groupId);
|
|
1794
|
-
}
|
|
1795
|
-
const localSelected = [...state.localIds.keys()].filter((groupId) => !excludedLocal.has(groupId));
|
|
1796
|
-
const sourcesOf = (ids, groupIds) => [...groupIds].flatMap((groupId) => {
|
|
1797
|
-
const sourceId = ids.get(groupId);
|
|
1798
|
-
return sourceId ? [sourceId] : [];
|
|
1799
|
-
});
|
|
1800
|
-
const leftOut = new Set(sourcesOf(state.remoteIds, localSelected));
|
|
1801
|
-
const branch = (comparison, ids, selected, excluded, met) => {
|
|
1802
|
-
const plan = comparisonPlanOf(comparison, state.schema);
|
|
1803
|
-
if (!plan) return null;
|
|
1804
|
-
const closed = closeOverRequired(comparison.changes.map((group) => ({
|
|
1805
|
-
...group,
|
|
1806
|
-
requiredChangeIds: group.requiredChangeIds.filter((id) => !met.has(id))
|
|
1807
|
-
})), sourcesOf(ids, selected));
|
|
1808
|
-
const excludedSources = new Set(sourcesOf(ids, excluded));
|
|
1809
|
-
const all = closed.size === comparison.changes.length;
|
|
1810
|
-
if ([...closed].some((id) => excludedSources.has(id)) || plan.windows.some(({ owners }) => owners.some((id) => closed.has(id)) && owners.some((id) => met.has(id))) || !all && !plan.partitioned) return null;
|
|
1811
|
-
return {
|
|
1812
|
-
change: plan.select(all ? "all" : closed),
|
|
1813
|
-
size: closed.size
|
|
1814
|
-
};
|
|
1815
|
-
};
|
|
1816
|
-
const local = branch(state.local, state.localIds, localSelected, excludedLocal, /* @__PURE__ */ new Set());
|
|
1817
|
-
const remote = branch(state.remote, state.remoteIds, [...state.remoteIds.keys()].filter((groupId) => !excludedRemote.has(groupId) && !leftOut.has(state.remoteIds.get(groupId) ?? "")), excludedRemote, leftOut);
|
|
1818
|
-
if (!local || !remote) return invalidResolution("The selected branch contributions cannot be separated into one exact change.");
|
|
1819
|
-
let target;
|
|
1820
|
-
try {
|
|
1821
|
-
target = detachComparisonDocument(DocumentChange.transform(local.change, remote.change, input.comparison.base.document).b.apply(local.change.apply(input.comparison.base.document)), state.schema);
|
|
1822
|
-
} catch {
|
|
1823
|
-
return invalidResolution("The selected branch contributions do not form one schema-valid document.");
|
|
1824
|
-
}
|
|
1825
|
-
const baseline = input.comparison[input.baseline];
|
|
1826
|
-
const compared = restoreBaselineSnapshot(await compareTwoWay({
|
|
1827
|
-
after: target,
|
|
1828
|
-
before: baseline.document,
|
|
1829
|
-
schema: state.schema,
|
|
1830
|
-
signal: input.signal
|
|
1831
|
-
}), baseline);
|
|
1832
|
-
const branches = Object.freeze([...local.size > 0 ? ["local"] : [], ...remote.size > 0 ? ["remote"] : []]);
|
|
1833
|
-
return Object.freeze({
|
|
1834
|
-
comparison: annotateResolvedComparison(compared, branches),
|
|
1835
|
-
status: "resolved"
|
|
1836
|
-
});
|
|
1837
1466
|
}
|
|
1838
1467
|
//#endregion
|
|
1839
|
-
export { compare
|
|
1468
|
+
export { compare };
|