@input/pen-core 0.2.0 → 0.2.1
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 +41 -3
- package/dist/index.mjs +41 -3
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -4353,6 +4353,12 @@ var DecorationSetImpl = class _DecorationSetImpl {
|
|
|
4353
4353
|
get decorations() {
|
|
4354
4354
|
return this._decorations;
|
|
4355
4355
|
}
|
|
4356
|
+
get blockIndex() {
|
|
4357
|
+
return this._blockIndex;
|
|
4358
|
+
}
|
|
4359
|
+
get isReleased() {
|
|
4360
|
+
return this._released;
|
|
4361
|
+
}
|
|
4356
4362
|
forBlock(blockId) {
|
|
4357
4363
|
return this._blockIndex.get(blockId) ?? EMPTY_ARRAY;
|
|
4358
4364
|
}
|
|
@@ -4428,6 +4434,36 @@ function mergeDecorationSets(...sets) {
|
|
|
4428
4434
|
if (all.length === 0) return EMPTY_SET;
|
|
4429
4435
|
return new DecorationSetImpl(all);
|
|
4430
4436
|
}
|
|
4437
|
+
function reconcileDecorationSets(previous, next) {
|
|
4438
|
+
if (previous === next) return previous;
|
|
4439
|
+
if (!(previous instanceof DecorationSetImpl) || !(next instanceof DecorationSetImpl) || previous.isReleased) {
|
|
4440
|
+
return next;
|
|
4441
|
+
}
|
|
4442
|
+
const previousIndex = previous.blockIndex;
|
|
4443
|
+
const nextIndex = next.blockIndex;
|
|
4444
|
+
if (previousIndex.size !== nextIndex.size) {
|
|
4445
|
+
return reuseUnchangedBlocks(previousIndex, nextIndex);
|
|
4446
|
+
}
|
|
4447
|
+
for (const [blockId, nextList] of nextIndex) {
|
|
4448
|
+
const previousList = previousIndex.get(blockId);
|
|
4449
|
+
if (!previousList || !decorationsListEqual(previousList, nextList)) {
|
|
4450
|
+
return reuseUnchangedBlocks(previousIndex, nextIndex);
|
|
4451
|
+
}
|
|
4452
|
+
}
|
|
4453
|
+
return previous;
|
|
4454
|
+
}
|
|
4455
|
+
function reuseUnchangedBlocks(previousIndex, nextIndex) {
|
|
4456
|
+
const index = /* @__PURE__ */ new Map();
|
|
4457
|
+
const flat = [];
|
|
4458
|
+
for (const [blockId, nextList] of nextIndex) {
|
|
4459
|
+
const previousList = previousIndex.get(blockId);
|
|
4460
|
+
const list = previousList && decorationsListEqual(previousList, nextList) ? previousList : nextList;
|
|
4461
|
+
index.set(blockId, list);
|
|
4462
|
+
flat.push(...list);
|
|
4463
|
+
}
|
|
4464
|
+
if (flat.length === 0) return EMPTY_SET;
|
|
4465
|
+
return new DecorationSetImpl(flat, void 0, index);
|
|
4466
|
+
}
|
|
4431
4467
|
function buildBlockIndex(decorations) {
|
|
4432
4468
|
const index = /* @__PURE__ */ new Map();
|
|
4433
4469
|
for (const dec of decorations) {
|
|
@@ -13351,7 +13387,9 @@ var EditorImpl = class {
|
|
|
13351
13387
|
}
|
|
13352
13388
|
// ── Decorations ──────────────────────────────────────────
|
|
13353
13389
|
requestDecorationUpdate() {
|
|
13390
|
+
const previousGeneration = this._decorations.generation;
|
|
13354
13391
|
const decoSet = this._refreshDecorations();
|
|
13392
|
+
if (decoSet.generation === previousGeneration) return;
|
|
13355
13393
|
this._emitter.emit("decorationsChange", decoSet.generation);
|
|
13356
13394
|
}
|
|
13357
13395
|
getDecorations() {
|
|
@@ -13361,9 +13399,9 @@ var EditorImpl = class {
|
|
|
13361
13399
|
return this._emitter.on(event, handler);
|
|
13362
13400
|
}
|
|
13363
13401
|
_refreshDecorations() {
|
|
13364
|
-
this._decorations =
|
|
13365
|
-
this.
|
|
13366
|
-
this
|
|
13402
|
+
this._decorations = reconcileDecorationSets(
|
|
13403
|
+
this._decorations,
|
|
13404
|
+
this._extensions.collectDecorations(this._documentState, this)
|
|
13367
13405
|
);
|
|
13368
13406
|
return this._decorations;
|
|
13369
13407
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -4118,6 +4118,12 @@ var DecorationSetImpl = class _DecorationSetImpl {
|
|
|
4118
4118
|
get decorations() {
|
|
4119
4119
|
return this._decorations;
|
|
4120
4120
|
}
|
|
4121
|
+
get blockIndex() {
|
|
4122
|
+
return this._blockIndex;
|
|
4123
|
+
}
|
|
4124
|
+
get isReleased() {
|
|
4125
|
+
return this._released;
|
|
4126
|
+
}
|
|
4121
4127
|
forBlock(blockId) {
|
|
4122
4128
|
return this._blockIndex.get(blockId) ?? EMPTY_ARRAY;
|
|
4123
4129
|
}
|
|
@@ -4193,6 +4199,36 @@ function mergeDecorationSets(...sets) {
|
|
|
4193
4199
|
if (all.length === 0) return EMPTY_SET;
|
|
4194
4200
|
return new DecorationSetImpl(all);
|
|
4195
4201
|
}
|
|
4202
|
+
function reconcileDecorationSets(previous, next) {
|
|
4203
|
+
if (previous === next) return previous;
|
|
4204
|
+
if (!(previous instanceof DecorationSetImpl) || !(next instanceof DecorationSetImpl) || previous.isReleased) {
|
|
4205
|
+
return next;
|
|
4206
|
+
}
|
|
4207
|
+
const previousIndex = previous.blockIndex;
|
|
4208
|
+
const nextIndex = next.blockIndex;
|
|
4209
|
+
if (previousIndex.size !== nextIndex.size) {
|
|
4210
|
+
return reuseUnchangedBlocks(previousIndex, nextIndex);
|
|
4211
|
+
}
|
|
4212
|
+
for (const [blockId, nextList] of nextIndex) {
|
|
4213
|
+
const previousList = previousIndex.get(blockId);
|
|
4214
|
+
if (!previousList || !decorationsListEqual(previousList, nextList)) {
|
|
4215
|
+
return reuseUnchangedBlocks(previousIndex, nextIndex);
|
|
4216
|
+
}
|
|
4217
|
+
}
|
|
4218
|
+
return previous;
|
|
4219
|
+
}
|
|
4220
|
+
function reuseUnchangedBlocks(previousIndex, nextIndex) {
|
|
4221
|
+
const index = /* @__PURE__ */ new Map();
|
|
4222
|
+
const flat = [];
|
|
4223
|
+
for (const [blockId, nextList] of nextIndex) {
|
|
4224
|
+
const previousList = previousIndex.get(blockId);
|
|
4225
|
+
const list = previousList && decorationsListEqual(previousList, nextList) ? previousList : nextList;
|
|
4226
|
+
index.set(blockId, list);
|
|
4227
|
+
flat.push(...list);
|
|
4228
|
+
}
|
|
4229
|
+
if (flat.length === 0) return EMPTY_SET;
|
|
4230
|
+
return new DecorationSetImpl(flat, void 0, index);
|
|
4231
|
+
}
|
|
4196
4232
|
function buildBlockIndex(decorations) {
|
|
4197
4233
|
const index = /* @__PURE__ */ new Map();
|
|
4198
4234
|
for (const dec of decorations) {
|
|
@@ -13154,7 +13190,9 @@ var EditorImpl = class {
|
|
|
13154
13190
|
}
|
|
13155
13191
|
// ── Decorations ──────────────────────────────────────────
|
|
13156
13192
|
requestDecorationUpdate() {
|
|
13193
|
+
const previousGeneration = this._decorations.generation;
|
|
13157
13194
|
const decoSet = this._refreshDecorations();
|
|
13195
|
+
if (decoSet.generation === previousGeneration) return;
|
|
13158
13196
|
this._emitter.emit("decorationsChange", decoSet.generation);
|
|
13159
13197
|
}
|
|
13160
13198
|
getDecorations() {
|
|
@@ -13164,9 +13202,9 @@ var EditorImpl = class {
|
|
|
13164
13202
|
return this._emitter.on(event, handler);
|
|
13165
13203
|
}
|
|
13166
13204
|
_refreshDecorations() {
|
|
13167
|
-
this._decorations =
|
|
13168
|
-
this.
|
|
13169
|
-
this
|
|
13205
|
+
this._decorations = reconcileDecorationSets(
|
|
13206
|
+
this._decorations,
|
|
13207
|
+
this._extensions.collectDecorations(this._documentState, this)
|
|
13170
13208
|
);
|
|
13171
13209
|
return this._decorations;
|
|
13172
13210
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@input/pen-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
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.2.
|
|
47
|
-
"@input/pen-types": "^0.2.
|
|
46
|
+
"@input/pen-yjs": "^0.2.1",
|
|
47
|
+
"@input/pen-types": "^0.2.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"tsup": "^8.4.0",
|