@input/pen-core 0.1.0 → 0.1.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/dist/index.cjs +207 -241
- package/dist/index.d.cts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.mjs +144 -181
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -692,6 +692,25 @@ function mergeSchemas(...registries2) {
|
|
|
692
692
|
});
|
|
693
693
|
}
|
|
694
694
|
|
|
695
|
+
// src/schema/slashMenuOrder.ts
|
|
696
|
+
var FALLBACK_GROUP = "other";
|
|
697
|
+
function slashMenuGroupOf(display) {
|
|
698
|
+
return display.group ?? FALLBACK_GROUP;
|
|
699
|
+
}
|
|
700
|
+
function orderSlashMenuItemsByGroup(items) {
|
|
701
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
702
|
+
for (const item of items) {
|
|
703
|
+
const group = slashMenuGroupOf(item.display);
|
|
704
|
+
const existing = grouped.get(group);
|
|
705
|
+
if (existing) {
|
|
706
|
+
existing.push(item);
|
|
707
|
+
} else {
|
|
708
|
+
grouped.set(group, [item]);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
return [...grouped.values()].flat();
|
|
712
|
+
}
|
|
713
|
+
|
|
695
714
|
// src/schema/defineBlock.ts
|
|
696
715
|
function resolveProps2(config) {
|
|
697
716
|
const raw = config.props ?? config.propSchema ?? {};
|
|
@@ -971,6 +990,15 @@ var SchemaEngineImpl = class {
|
|
|
971
990
|
markDirty(blockId) {
|
|
972
991
|
this.dirtyBlockIds.add(blockId);
|
|
973
992
|
}
|
|
993
|
+
/**
|
|
994
|
+
* Drop the cached pass index because `blockOrder` or a `children` array
|
|
995
|
+
* changed outside this engine — an executing op, or a remote/undo update.
|
|
996
|
+
* Every structural mutation the engine performs itself already invalidates
|
|
997
|
+
* at the mutation site, so those callers do not go through here.
|
|
998
|
+
*/
|
|
999
|
+
notifyStructureChanged() {
|
|
1000
|
+
this.invalidatePassIndex();
|
|
1001
|
+
}
|
|
974
1002
|
deferBlock(blockId) {
|
|
975
1003
|
this.deferredBlockIds.add(blockId);
|
|
976
1004
|
}
|
|
@@ -990,7 +1018,6 @@ var SchemaEngineImpl = class {
|
|
|
990
1018
|
}
|
|
991
1019
|
iterations++;
|
|
992
1020
|
this.dirtyBlockIds.clear();
|
|
993
|
-
this.invalidatePassIndex();
|
|
994
1021
|
this.doc.adapter.transact(this.crdtDoc, () => {
|
|
995
1022
|
for (const blockId of snapshot) {
|
|
996
1023
|
if (this.deferredBlockIds.has(blockId)) {
|
|
@@ -1001,7 +1028,6 @@ var SchemaEngineImpl = class {
|
|
|
1001
1028
|
}
|
|
1002
1029
|
});
|
|
1003
1030
|
}
|
|
1004
|
-
this.invalidatePassIndex();
|
|
1005
1031
|
if (iterations >= MAX_ITERATIONS) {
|
|
1006
1032
|
this.onDiagnostic?.({
|
|
1007
1033
|
code: "normalize-cap",
|
|
@@ -1013,6 +1039,7 @@ var SchemaEngineImpl = class {
|
|
|
1013
1039
|
}
|
|
1014
1040
|
}
|
|
1015
1041
|
normalizeAll() {
|
|
1042
|
+
this.invalidatePassIndex();
|
|
1016
1043
|
for (const blockId of this.doc.blocks.keys()) {
|
|
1017
1044
|
this.dirtyBlockIds.add(blockId);
|
|
1018
1045
|
}
|
|
@@ -2672,6 +2699,9 @@ function opBlockId(_pipeline, op) {
|
|
|
2672
2699
|
import { STRUCTURAL_ORIGIN_META_KEY } from "@input/pen-yjs";
|
|
2673
2700
|
|
|
2674
2701
|
// src/schema/contentType.ts
|
|
2702
|
+
import {
|
|
2703
|
+
isNestedContent
|
|
2704
|
+
} from "@input/pen-types";
|
|
2675
2705
|
function resolveRuntimeContentType(schema) {
|
|
2676
2706
|
if (!schema) {
|
|
2677
2707
|
return "none";
|
|
@@ -2681,6 +2711,10 @@ function resolveRuntimeContentType(schema) {
|
|
|
2681
2711
|
}
|
|
2682
2712
|
return schema.content;
|
|
2683
2713
|
}
|
|
2714
|
+
function isContainerBlock(schema) {
|
|
2715
|
+
if (!schema) return false;
|
|
2716
|
+
return isNestedContent(schema.content) || schema.isContainer === true;
|
|
2717
|
+
}
|
|
2684
2718
|
|
|
2685
2719
|
// src/editor/rejectedOwnKeys.ts
|
|
2686
2720
|
var REJECTED_OWN_PROP_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -3227,6 +3261,11 @@ function emitSchemaUnknownBlock(pipeline, type) {
|
|
|
3227
3261
|
});
|
|
3228
3262
|
}
|
|
3229
3263
|
function reportUnknownBlocksInDocument(pipeline) {
|
|
3264
|
+
const blockCount = pipeline._doc.blocks.size;
|
|
3265
|
+
if (blockCount === pipeline._unknownScanBlockCount) {
|
|
3266
|
+
return;
|
|
3267
|
+
}
|
|
3268
|
+
pipeline._unknownScanBlockCount = blockCount;
|
|
3230
3269
|
for (const [, rawBlockMap] of pipeline._doc.blocks.entries()) {
|
|
3231
3270
|
if (!isCRDTMap(rawBlockMap)) {
|
|
3232
3271
|
continue;
|
|
@@ -3526,6 +3565,9 @@ function emitMalformedOpDiagnostic(pipeline, op, error) {
|
|
|
3526
3565
|
...error !== void 0 ? { error } : {}
|
|
3527
3566
|
});
|
|
3528
3567
|
}
|
|
3568
|
+
function isStructuralOp(op) {
|
|
3569
|
+
return op.type === "insert-block" || op.type === "delete-block" || op.type === "move-block";
|
|
3570
|
+
}
|
|
3529
3571
|
function executeOps(pipeline, ops, origin, structural) {
|
|
3530
3572
|
pipeline._commitDiagnostics = [];
|
|
3531
3573
|
reportUnknownBlocksInDocument(pipeline);
|
|
@@ -3547,6 +3589,15 @@ function executeOps(pipeline, ops, origin, structural) {
|
|
|
3547
3589
|
const blockId = opBlockId(pipeline, op);
|
|
3548
3590
|
if (!validateOp(pipeline, op)) continue;
|
|
3549
3591
|
if (op.type === "insert-block") {
|
|
3592
|
+
if (blockExists(pipeline, op.blockId) || pendingBlockIds.has(op.blockId)) {
|
|
3593
|
+
emitPipelineDiagnostic(pipeline, {
|
|
3594
|
+
code: "PEN_APPLY_010",
|
|
3595
|
+
level: "warn",
|
|
3596
|
+
source: "apply",
|
|
3597
|
+
message: `apply: skipping insert-block for already-present block "${op.blockId}"`
|
|
3598
|
+
});
|
|
3599
|
+
continue;
|
|
3600
|
+
}
|
|
3550
3601
|
pendingBlockIds.add(op.blockId);
|
|
3551
3602
|
pendingBlockTypes.set(op.blockId, op.blockType);
|
|
3552
3603
|
}
|
|
@@ -3592,6 +3643,9 @@ function executeOps(pipeline, ops, origin, structural) {
|
|
|
3592
3643
|
} catch (err) {
|
|
3593
3644
|
emitMalformedOpDiagnostic(pipeline, op, err);
|
|
3594
3645
|
}
|
|
3646
|
+
if (isStructuralOp(op)) {
|
|
3647
|
+
pipeline._engine.notifyStructureChanged();
|
|
3648
|
+
}
|
|
3595
3649
|
}
|
|
3596
3650
|
for (const blockId of affectedBlocks) {
|
|
3597
3651
|
pipeline._engine.markDirty(blockId);
|
|
@@ -3763,6 +3817,7 @@ var ApplyPipeline = class {
|
|
|
3763
3817
|
_applyStormEmitted = false;
|
|
3764
3818
|
_suppressObserver = false;
|
|
3765
3819
|
_unknownBlockTypesReported;
|
|
3820
|
+
_unknownScanBlockCount;
|
|
3766
3821
|
_queue = [];
|
|
3767
3822
|
_applyBoundaryHooks = [];
|
|
3768
3823
|
_beforeApplyHooks = [];
|
|
@@ -3846,6 +3901,7 @@ var ApplyPipeline = class {
|
|
|
3846
3901
|
this._doc = doc;
|
|
3847
3902
|
this._crdtDoc = crdtDoc;
|
|
3848
3903
|
this._engine = engine;
|
|
3904
|
+
this._unknownScanBlockCount = void 0;
|
|
3849
3905
|
}
|
|
3850
3906
|
};
|
|
3851
3907
|
|
|
@@ -6007,9 +6063,11 @@ var SelectionAuthorityImpl = class {
|
|
|
6007
6063
|
};
|
|
6008
6064
|
|
|
6009
6065
|
// src/editor/documentState.ts
|
|
6066
|
+
var EMPTY_CHILD_IDS = Object.freeze([]);
|
|
6010
6067
|
var DocumentStateImpl = class {
|
|
6011
6068
|
_positionIndex;
|
|
6012
6069
|
_parentIndex;
|
|
6070
|
+
_childIndex;
|
|
6013
6071
|
_blockOrder;
|
|
6014
6072
|
_generation = 0;
|
|
6015
6073
|
_documentProfile;
|
|
@@ -6023,6 +6081,7 @@ var DocumentStateImpl = class {
|
|
|
6023
6081
|
this._documentProfile = documentProfile;
|
|
6024
6082
|
this._positionIndex = /* @__PURE__ */ new Map();
|
|
6025
6083
|
this._parentIndex = /* @__PURE__ */ new Map();
|
|
6084
|
+
this._childIndex = /* @__PURE__ */ new Map();
|
|
6026
6085
|
this._blockOrder = [];
|
|
6027
6086
|
this.rebuild();
|
|
6028
6087
|
}
|
|
@@ -6061,6 +6120,9 @@ var DocumentStateImpl = class {
|
|
|
6061
6120
|
parentOf(blockId) {
|
|
6062
6121
|
return this._parentIndex.get(blockId) ?? null;
|
|
6063
6122
|
}
|
|
6123
|
+
childrenOf(blockId) {
|
|
6124
|
+
return this._childIndex.get(blockId) ?? EMPTY_CHILD_IDS;
|
|
6125
|
+
}
|
|
6064
6126
|
*allBlocks() {
|
|
6065
6127
|
const seen = /* @__PURE__ */ new Set();
|
|
6066
6128
|
for (const id of this._blockOrder) {
|
|
@@ -6080,21 +6142,44 @@ var DocumentStateImpl = class {
|
|
|
6080
6142
|
this._blockOrder = [];
|
|
6081
6143
|
this._positionIndex = /* @__PURE__ */ new Map();
|
|
6082
6144
|
this._parentIndex = /* @__PURE__ */ new Map();
|
|
6145
|
+
this._childIndex = /* @__PURE__ */ new Map();
|
|
6083
6146
|
for (let i = 0; i < order.length; i++) {
|
|
6084
6147
|
const id = order.get(i);
|
|
6085
6148
|
this._blockOrder.push(id);
|
|
6086
6149
|
this._positionIndex.set(id, i);
|
|
6087
6150
|
}
|
|
6151
|
+
const nestedChildIds = /* @__PURE__ */ new Set();
|
|
6152
|
+
const parentIdChildIds = [];
|
|
6088
6153
|
for (const [blockId, blockMap] of this._doc.blocks.entries()) {
|
|
6089
6154
|
const props = blockMap.get("props");
|
|
6090
6155
|
if (props?.get?.("parentId")) {
|
|
6091
6156
|
this._parentIndex.set(blockId, props.get("parentId"));
|
|
6157
|
+
parentIdChildIds.push(blockId);
|
|
6092
6158
|
}
|
|
6093
6159
|
const children = blockMap.get("children");
|
|
6094
|
-
if (children) {
|
|
6160
|
+
if (children && children.length > 0) {
|
|
6161
|
+
const childIds = [];
|
|
6095
6162
|
for (let i = 0; i < children.length; i++) {
|
|
6096
|
-
|
|
6163
|
+
const childId = children.get(i);
|
|
6164
|
+
this._parentIndex.set(childId, blockId);
|
|
6165
|
+
nestedChildIds.add(childId);
|
|
6166
|
+
childIds.push(childId);
|
|
6097
6167
|
}
|
|
6168
|
+
this._childIndex.set(blockId, childIds);
|
|
6169
|
+
}
|
|
6170
|
+
}
|
|
6171
|
+
parentIdChildIds.sort(
|
|
6172
|
+
(a, b) => (this._positionIndex.get(a) ?? -1) - (this._positionIndex.get(b) ?? -1)
|
|
6173
|
+
);
|
|
6174
|
+
for (const childId of parentIdChildIds) {
|
|
6175
|
+
if (nestedChildIds.has(childId)) continue;
|
|
6176
|
+
const parentId = this._parentIndex.get(childId);
|
|
6177
|
+
if (parentId === void 0) continue;
|
|
6178
|
+
const siblings = this._childIndex.get(parentId);
|
|
6179
|
+
if (siblings === void 0) {
|
|
6180
|
+
this._childIndex.set(parentId, [childId]);
|
|
6181
|
+
} else {
|
|
6182
|
+
siblings.push(childId);
|
|
6098
6183
|
}
|
|
6099
6184
|
}
|
|
6100
6185
|
this._generation++;
|
|
@@ -6102,6 +6187,7 @@ var DocumentStateImpl = class {
|
|
|
6102
6187
|
clear() {
|
|
6103
6188
|
this._positionIndex.clear();
|
|
6104
6189
|
this._parentIndex.clear();
|
|
6190
|
+
this._childIndex.clear();
|
|
6105
6191
|
this._blockOrder = [];
|
|
6106
6192
|
this._generation++;
|
|
6107
6193
|
}
|
|
@@ -7378,11 +7464,18 @@ var BACKSPACE_EXIT_TYPES = /* @__PURE__ */ new Set([
|
|
|
7378
7464
|
...CONTAINER_EXIT_TYPES,
|
|
7379
7465
|
...HEADING_TYPES
|
|
7380
7466
|
]);
|
|
7381
|
-
|
|
7382
|
-
|
|
7383
|
-
|
|
7384
|
-
|
|
7385
|
-
|
|
7467
|
+
function isContainerBlockType(editor, blockType) {
|
|
7468
|
+
if (!blockType) {
|
|
7469
|
+
return false;
|
|
7470
|
+
}
|
|
7471
|
+
return isContainerBlock(editor.schema.resolve(blockType));
|
|
7472
|
+
}
|
|
7473
|
+
function shouldRenderContainerChildren(editor, block) {
|
|
7474
|
+
if (!block || !isContainerBlockType(editor, block.type)) {
|
|
7475
|
+
return false;
|
|
7476
|
+
}
|
|
7477
|
+
return block.props?.open !== false;
|
|
7478
|
+
}
|
|
7386
7479
|
function emitCommandDiagnostic(editor, event) {
|
|
7387
7480
|
editor.internals?.emit("diagnostic", event);
|
|
7388
7481
|
}
|
|
@@ -7434,18 +7527,13 @@ function isInsideParentIdContainer(editor, blockId) {
|
|
|
7434
7527
|
return false;
|
|
7435
7528
|
}
|
|
7436
7529
|
const parent = editor.getBlock(parentId);
|
|
7437
|
-
return !!parent &&
|
|
7530
|
+
return !!parent && isContainerBlockType(editor, parent.type);
|
|
7438
7531
|
}
|
|
7439
7532
|
function getRootBlockIds(editor) {
|
|
7440
7533
|
return editor.documentState.blockOrder.filter(
|
|
7441
7534
|
(blockId) => editor.documentState.parentOf(blockId) == null
|
|
7442
7535
|
);
|
|
7443
7536
|
}
|
|
7444
|
-
function getParentIdChildBlockIds(editor, parentBlockId) {
|
|
7445
|
-
return editor.documentState.blockOrder.filter(
|
|
7446
|
-
(blockId) => editor.documentState.parentOf(blockId) === parentBlockId
|
|
7447
|
-
);
|
|
7448
|
-
}
|
|
7449
7537
|
function getVisibleBlockIds(editor) {
|
|
7450
7538
|
const visibleBlockIds = [];
|
|
7451
7539
|
for (const rootBlockId of getRootBlockIds(editor)) {
|
|
@@ -7567,23 +7655,13 @@ function convertBlockOps(editor, options) {
|
|
|
7567
7655
|
}
|
|
7568
7656
|
function collectVisibleBlockIds(editor, blockId, visibleBlockIds) {
|
|
7569
7657
|
visibleBlockIds.push(blockId);
|
|
7570
|
-
if (!
|
|
7658
|
+
if (!shouldRenderContainerChildren(editor, editor.getBlock(blockId))) {
|
|
7571
7659
|
return;
|
|
7572
7660
|
}
|
|
7573
|
-
for (const childBlockId of
|
|
7661
|
+
for (const childBlockId of editor.documentState.childrenOf(blockId)) {
|
|
7574
7662
|
collectVisibleBlockIds(editor, childBlockId, visibleBlockIds);
|
|
7575
7663
|
}
|
|
7576
7664
|
}
|
|
7577
|
-
function shouldShowParentIdChildren(editor, blockId) {
|
|
7578
|
-
const block = editor.getBlock(blockId);
|
|
7579
|
-
if (!block || !PARENT_ID_CONTAINER_TYPES.has(block.type)) {
|
|
7580
|
-
return false;
|
|
7581
|
-
}
|
|
7582
|
-
if (block.type !== "toggle") {
|
|
7583
|
-
return true;
|
|
7584
|
-
}
|
|
7585
|
-
return Boolean(block.props?.open);
|
|
7586
|
-
}
|
|
7587
7665
|
|
|
7588
7666
|
// src/commands/commandSelection.ts
|
|
7589
7667
|
function textSelectionResult(anchor, focus = anchor, extras) {
|
|
@@ -7759,12 +7837,12 @@ function parentContainerKind(editor, parentId) {
|
|
|
7759
7837
|
if (!parent) {
|
|
7760
7838
|
return null;
|
|
7761
7839
|
}
|
|
7762
|
-
if (PARENT_ID_CONTAINER_TYPES.has(parent.type)) {
|
|
7763
|
-
return "layout-cell";
|
|
7764
|
-
}
|
|
7765
7840
|
if (parent.type === "table") {
|
|
7766
7841
|
return "table";
|
|
7767
7842
|
}
|
|
7843
|
+
if (isContainerBlockType(editor, parent.type)) {
|
|
7844
|
+
return "layout-cell";
|
|
7845
|
+
}
|
|
7768
7846
|
return null;
|
|
7769
7847
|
}
|
|
7770
7848
|
|
|
@@ -10660,44 +10738,20 @@ function createBlockIndex(initial) {
|
|
|
10660
10738
|
snapshot() {
|
|
10661
10739
|
return current;
|
|
10662
10740
|
},
|
|
10663
|
-
|
|
10664
|
-
|
|
10741
|
+
applyTextLengths(blockText) {
|
|
10742
|
+
for (const change of blockText) {
|
|
10743
|
+
const previous = current.lengthById.get(change.blockId) ?? 0;
|
|
10744
|
+
current.lengthById.set(
|
|
10745
|
+
change.blockId,
|
|
10746
|
+
lengthAfterSplices(previous, change.splices)
|
|
10747
|
+
);
|
|
10748
|
+
}
|
|
10665
10749
|
},
|
|
10666
10750
|
replace(snapshot) {
|
|
10667
10751
|
current = cloneSnapshot(snapshot);
|
|
10668
10752
|
}
|
|
10669
10753
|
};
|
|
10670
10754
|
}
|
|
10671
|
-
function applySummaryToSnapshot(snapshot, summary) {
|
|
10672
|
-
const lengthById = new Map(snapshot.lengthById);
|
|
10673
|
-
const typeById = new Map(snapshot.typeById);
|
|
10674
|
-
const childrenByParentId = cloneChildren(snapshot.childrenByParentId);
|
|
10675
|
-
for (const change of summary.structural) {
|
|
10676
|
-
applyStructural(change, lengthById, typeById, childrenByParentId);
|
|
10677
|
-
}
|
|
10678
|
-
for (const text of summary.blockText) {
|
|
10679
|
-
const previous = lengthById.get(text.blockId) ?? 0;
|
|
10680
|
-
lengthById.set(
|
|
10681
|
-
text.blockId,
|
|
10682
|
-
lengthAfterSplices(previous, text.splices)
|
|
10683
|
-
);
|
|
10684
|
-
}
|
|
10685
|
-
const roots = [...childrenByParentId.get(null) ?? []];
|
|
10686
|
-
const parentById = /* @__PURE__ */ new Map();
|
|
10687
|
-
for (const [parentId, children] of childrenByParentId) {
|
|
10688
|
-
for (const childId of children) {
|
|
10689
|
-
parentById.set(childId, parentId);
|
|
10690
|
-
}
|
|
10691
|
-
}
|
|
10692
|
-
return {
|
|
10693
|
-
lengthById,
|
|
10694
|
-
typeById,
|
|
10695
|
-
parentById,
|
|
10696
|
-
childrenByParentId,
|
|
10697
|
-
order: flattenOrder(roots, childrenByParentId),
|
|
10698
|
-
roots
|
|
10699
|
-
};
|
|
10700
|
-
}
|
|
10701
10755
|
function lengthAfterSplices(length, splices) {
|
|
10702
10756
|
let next = length;
|
|
10703
10757
|
for (const splice of splices) {
|
|
@@ -10715,120 +10769,6 @@ function cloneSnapshot(snapshot) {
|
|
|
10715
10769
|
roots: [...snapshot.roots]
|
|
10716
10770
|
};
|
|
10717
10771
|
}
|
|
10718
|
-
function applyStructural(change, lengthById, typeById, childrenByParentId) {
|
|
10719
|
-
switch (change.type) {
|
|
10720
|
-
case "block-inserted": {
|
|
10721
|
-
insertChild(
|
|
10722
|
-
childrenByParentId,
|
|
10723
|
-
change.parentId,
|
|
10724
|
-
change.index,
|
|
10725
|
-
change.blockId
|
|
10726
|
-
);
|
|
10727
|
-
if (!lengthById.has(change.blockId))
|
|
10728
|
-
lengthById.set(change.blockId, 0);
|
|
10729
|
-
break;
|
|
10730
|
-
}
|
|
10731
|
-
case "block-removed": {
|
|
10732
|
-
removeChild(childrenByParentId, change.parentId, change.blockId);
|
|
10733
|
-
lengthById.delete(change.blockId);
|
|
10734
|
-
typeById.delete(change.blockId);
|
|
10735
|
-
childrenByParentId.delete(change.blockId);
|
|
10736
|
-
break;
|
|
10737
|
-
}
|
|
10738
|
-
case "block-moved": {
|
|
10739
|
-
removeChild(
|
|
10740
|
-
childrenByParentId,
|
|
10741
|
-
change.fromParentId,
|
|
10742
|
-
change.blockId
|
|
10743
|
-
);
|
|
10744
|
-
insertChild(
|
|
10745
|
-
childrenByParentId,
|
|
10746
|
-
change.toParentId,
|
|
10747
|
-
change.toIndex,
|
|
10748
|
-
change.blockId
|
|
10749
|
-
);
|
|
10750
|
-
break;
|
|
10751
|
-
}
|
|
10752
|
-
case "block-split": {
|
|
10753
|
-
insertAfter(childrenByParentId, change.blockId, change.newBlockId);
|
|
10754
|
-
const original = lengthById.get(change.blockId) ?? 0;
|
|
10755
|
-
lengthById.set(change.blockId, Math.max(0, change.offset));
|
|
10756
|
-
lengthById.set(
|
|
10757
|
-
change.newBlockId,
|
|
10758
|
-
Math.max(0, original - change.offset)
|
|
10759
|
-
);
|
|
10760
|
-
if (!typeById.has(change.newBlockId)) {
|
|
10761
|
-
typeById.set(
|
|
10762
|
-
change.newBlockId,
|
|
10763
|
-
typeById.get(change.blockId) ?? ""
|
|
10764
|
-
);
|
|
10765
|
-
}
|
|
10766
|
-
break;
|
|
10767
|
-
}
|
|
10768
|
-
case "blocks-merged": {
|
|
10769
|
-
const parentId = parentOf(childrenByParentId, change.sourceBlockId);
|
|
10770
|
-
const targetLength = lengthById.get(change.targetBlockId) ?? 0;
|
|
10771
|
-
const sourceLength = lengthById.get(change.sourceBlockId) ?? 0;
|
|
10772
|
-
lengthById.set(change.targetBlockId, targetLength + sourceLength);
|
|
10773
|
-
removeChild(childrenByParentId, parentId, change.sourceBlockId);
|
|
10774
|
-
lengthById.delete(change.sourceBlockId);
|
|
10775
|
-
typeById.delete(change.sourceBlockId);
|
|
10776
|
-
childrenByParentId.delete(change.sourceBlockId);
|
|
10777
|
-
break;
|
|
10778
|
-
}
|
|
10779
|
-
case "block-props-changed":
|
|
10780
|
-
case "table-changed":
|
|
10781
|
-
case "apps-changed":
|
|
10782
|
-
case "metadata-changed":
|
|
10783
|
-
break;
|
|
10784
|
-
default: {
|
|
10785
|
-
const _exhaustive = change;
|
|
10786
|
-
return _exhaustive;
|
|
10787
|
-
}
|
|
10788
|
-
}
|
|
10789
|
-
}
|
|
10790
|
-
function insertAfter(childrenByParentId, beforeId, newId) {
|
|
10791
|
-
for (const [parentId, children] of childrenByParentId) {
|
|
10792
|
-
const index = children.indexOf(beforeId);
|
|
10793
|
-
if (index < 0) continue;
|
|
10794
|
-
if (!children.includes(newId)) {
|
|
10795
|
-
children.splice(index + 1, 0, newId);
|
|
10796
|
-
}
|
|
10797
|
-
childrenByParentId.set(parentId, children);
|
|
10798
|
-
return;
|
|
10799
|
-
}
|
|
10800
|
-
insertChild(childrenByParentId, null, -1, newId);
|
|
10801
|
-
}
|
|
10802
|
-
function insertChild(childrenByParentId, parentId, index, blockId) {
|
|
10803
|
-
const children = childrenByParentId.get(parentId) ?? [];
|
|
10804
|
-
const next = children.filter((id) => id !== blockId);
|
|
10805
|
-
const at = index < 0 || index > next.length ? next.length : index;
|
|
10806
|
-
next.splice(at, 0, blockId);
|
|
10807
|
-
childrenByParentId.set(parentId, next);
|
|
10808
|
-
}
|
|
10809
|
-
function removeChild(childrenByParentId, parentId, blockId) {
|
|
10810
|
-
const children = childrenByParentId.get(parentId);
|
|
10811
|
-
if (!children) {
|
|
10812
|
-
for (const [id, list] of childrenByParentId) {
|
|
10813
|
-
const index2 = list.indexOf(blockId);
|
|
10814
|
-
if (index2 >= 0) {
|
|
10815
|
-
list.splice(index2, 1);
|
|
10816
|
-
childrenByParentId.set(id, list);
|
|
10817
|
-
return;
|
|
10818
|
-
}
|
|
10819
|
-
}
|
|
10820
|
-
return;
|
|
10821
|
-
}
|
|
10822
|
-
const index = children.indexOf(blockId);
|
|
10823
|
-
if (index >= 0) children.splice(index, 1);
|
|
10824
|
-
childrenByParentId.set(parentId, children);
|
|
10825
|
-
}
|
|
10826
|
-
function parentOf(childrenByParentId, blockId) {
|
|
10827
|
-
for (const [parentId, children] of childrenByParentId) {
|
|
10828
|
-
if (children.includes(blockId)) return parentId;
|
|
10829
|
-
}
|
|
10830
|
-
return null;
|
|
10831
|
-
}
|
|
10832
10772
|
function flattenOrder(roots, childrenByParentId) {
|
|
10833
10773
|
const order = [];
|
|
10834
10774
|
const visit = (id) => {
|
|
@@ -11418,7 +11358,7 @@ function affectedBlockIdsFromSummary(summary, documentOrder) {
|
|
|
11418
11358
|
addStructuralBlockIds(ids, change);
|
|
11419
11359
|
}
|
|
11420
11360
|
const collected = [...ids];
|
|
11421
|
-
if (!documentOrder || documentOrder.length === 0) {
|
|
11361
|
+
if (collected.length < 2 || !documentOrder || documentOrder.length === 0) {
|
|
11422
11362
|
return collected;
|
|
11423
11363
|
}
|
|
11424
11364
|
const rank = /* @__PURE__ */ new Map();
|
|
@@ -11840,14 +11780,22 @@ function installChangeSummaries(host) {
|
|
|
11840
11780
|
host._unsubSummary = createSummarySource(
|
|
11841
11781
|
host._crdtDoc,
|
|
11842
11782
|
(delta) => {
|
|
11843
|
-
|
|
11783
|
+
if (delta.blockOrderDelta.length > 0 || delta.childArrayDeltas.size > 0) {
|
|
11784
|
+
host._engine.notifyStructureChanged();
|
|
11785
|
+
}
|
|
11786
|
+
const summary = buildChangeSummary(
|
|
11844
11787
|
delta,
|
|
11845
11788
|
host._blockIndex.snapshot(),
|
|
11846
11789
|
0
|
|
11847
11790
|
);
|
|
11848
|
-
host.
|
|
11849
|
-
|
|
11850
|
-
|
|
11791
|
+
host._pendingSummary = summary;
|
|
11792
|
+
if (summary.structural.length === 0) {
|
|
11793
|
+
host._blockIndex.applyTextLengths(summary.blockText);
|
|
11794
|
+
} else {
|
|
11795
|
+
host._blockIndex.replace(
|
|
11796
|
+
createBlockIndexSnapshotFromDocument(host._doc)
|
|
11797
|
+
);
|
|
11798
|
+
}
|
|
11851
11799
|
flushDeferredCRDTEvent(host);
|
|
11852
11800
|
}
|
|
11853
11801
|
);
|
|
@@ -14417,6 +14365,16 @@ var macosBindings = [
|
|
|
14417
14365
|
key: "Alt-Delete",
|
|
14418
14366
|
command: deleteForward,
|
|
14419
14367
|
param: { granularity: "word" }
|
|
14368
|
+
},
|
|
14369
|
+
{
|
|
14370
|
+
key: "Meta-Backspace",
|
|
14371
|
+
command: deleteBackward,
|
|
14372
|
+
param: { granularity: "line" }
|
|
14373
|
+
},
|
|
14374
|
+
{
|
|
14375
|
+
key: "Ctrl-k",
|
|
14376
|
+
command: deleteForward,
|
|
14377
|
+
param: { granularity: "line" }
|
|
14420
14378
|
}
|
|
14421
14379
|
];
|
|
14422
14380
|
var windowsLinuxBindings = [
|
|
@@ -14910,6 +14868,8 @@ export {
|
|
|
14910
14868
|
interpolateMessage,
|
|
14911
14869
|
isBlockSelected,
|
|
14912
14870
|
isCollapsed,
|
|
14871
|
+
isContainerBlock,
|
|
14872
|
+
isContainerBlockType,
|
|
14913
14873
|
isContinuousTextFlowCapability,
|
|
14914
14874
|
isMultiBlock,
|
|
14915
14875
|
isPseudoLocaleText,
|
|
@@ -14926,6 +14886,7 @@ export {
|
|
|
14926
14886
|
nextGraphemeBoundary,
|
|
14927
14887
|
nextWordBoundary,
|
|
14928
14888
|
normalizePendingBlocksForImport,
|
|
14889
|
+
orderSlashMenuItemsByGroup,
|
|
14929
14890
|
outdent,
|
|
14930
14891
|
previousGraphemeBoundary,
|
|
14931
14892
|
previousWordBoundary,
|
|
@@ -14968,8 +14929,10 @@ export {
|
|
|
14968
14929
|
shouldAllowFlowInsertionInSlashMenu,
|
|
14969
14930
|
shouldExposeBlockInTooling,
|
|
14970
14931
|
shouldForceBlockScopedSelectAll,
|
|
14932
|
+
shouldRenderContainerChildren,
|
|
14971
14933
|
shouldShowBlockInDefaultMenus,
|
|
14972
14934
|
singleController,
|
|
14935
|
+
slashMenuGroupOf,
|
|
14973
14936
|
snapToNormalPosition,
|
|
14974
14937
|
snapshotsControllerFacet,
|
|
14975
14938
|
sortDeltaAttributes,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@input/pen-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Headless, extension-first editor engine for human-AI co-authoring",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/input-systems/pen#readme",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
},
|
|
44
44
|
"sideEffects": false,
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@input/pen-yjs": "^0.1.
|
|
47
|
-
"@input/pen-types": "^0.1.
|
|
46
|
+
"@input/pen-yjs": "^0.1.2",
|
|
47
|
+
"@input/pen-types": "^0.1.2"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"tsup": "^8.4.0",
|