@platejs/ai 50.2.2 → 50.3.3

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.
@@ -128,2661 +128,12 @@ var AIPlugin = toPlatePlugin(BaseAIPlugin);
128
128
  // src/react/ai/utils/aiCommentToRange.ts
129
129
  import { deserializeMd } from "@platejs/markdown";
130
130
  import {
131
- NodeApi
131
+ NodeApi as NodeApi2
132
132
  } from "platejs";
133
133
 
134
134
  // src/react/ai/utils/findTextRangeInBlock.tsx
135
135
  import { distance } from "fastest-levenshtein";
136
-
137
- // ../../node_modules/immer/dist/immer.mjs
138
- var NOTHING = Symbol.for("immer-nothing");
139
- var DRAFTABLE = Symbol.for("immer-draftable");
140
- var DRAFT_STATE = Symbol.for("immer-state");
141
- var errors = process.env.NODE_ENV !== "production" ? [
142
- // All error codes, starting by 0:
143
- function(plugin) {
144
- return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
145
- },
146
- function(thing) {
147
- return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
148
- },
149
- "This object has been frozen and should not be mutated",
150
- function(data) {
151
- return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
152
- },
153
- "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
154
- "Immer forbids circular references",
155
- "The first or second argument to `produce` must be a function",
156
- "The third argument to `produce` must be a function or undefined",
157
- "First argument to `createDraft` must be a plain object, an array, or an immerable object",
158
- "First argument to `finishDraft` must be a draft returned by `createDraft`",
159
- function(thing) {
160
- return `'current' expects a draft, got: ${thing}`;
161
- },
162
- "Object.defineProperty() cannot be used on an Immer draft",
163
- "Object.setPrototypeOf() cannot be used on an Immer draft",
164
- "Immer only supports deleting array indices",
165
- "Immer only supports setting array indices and the 'length' property",
166
- function(thing) {
167
- return `'original' expects a draft, got: ${thing}`;
168
- }
169
- // Note: if more errors are added, the errorOffset in Patches.ts should be increased
170
- // See Patches.ts for additional errors
171
- ] : [];
172
- function die(error, ...args) {
173
- if (process.env.NODE_ENV !== "production") {
174
- const e = errors[error];
175
- const msg = typeof e === "function" ? e.apply(null, args) : e;
176
- throw new Error(`[Immer] ${msg}`);
177
- }
178
- throw new Error(
179
- `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
180
- );
181
- }
182
- var getPrototypeOf = Object.getPrototypeOf;
183
- function isDraft(value) {
184
- return !!value && !!value[DRAFT_STATE];
185
- }
186
- function isDraftable(value) {
187
- if (!value)
188
- return false;
189
- return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);
190
- }
191
- var objectCtorString = Object.prototype.constructor.toString();
192
- function isPlainObject(value) {
193
- if (!value || typeof value !== "object")
194
- return false;
195
- const proto = getPrototypeOf(value);
196
- if (proto === null) {
197
- return true;
198
- }
199
- const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
200
- if (Ctor === Object)
201
- return true;
202
- return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
203
- }
204
- function each(obj, iter) {
205
- if (getArchtype(obj) === 0) {
206
- Reflect.ownKeys(obj).forEach((key) => {
207
- iter(key, obj[key], obj);
208
- });
209
- } else {
210
- obj.forEach((entry, index) => iter(index, entry, obj));
211
- }
212
- }
213
- function getArchtype(thing) {
214
- const state = thing[DRAFT_STATE];
215
- return state ? state.type_ : Array.isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
216
- }
217
- function has(thing, prop) {
218
- return getArchtype(thing) === 2 ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
219
- }
220
- function set(thing, propOrOldValue, value) {
221
- const t = getArchtype(thing);
222
- if (t === 2)
223
- thing.set(propOrOldValue, value);
224
- else if (t === 3) {
225
- thing.add(value);
226
- } else
227
- thing[propOrOldValue] = value;
228
- }
229
- function is(x, y) {
230
- if (x === y) {
231
- return x !== 0 || 1 / x === 1 / y;
232
- } else {
233
- return x !== x && y !== y;
234
- }
235
- }
236
- function isMap(target) {
237
- return target instanceof Map;
238
- }
239
- function isSet(target) {
240
- return target instanceof Set;
241
- }
242
- function latest(state) {
243
- return state.copy_ || state.base_;
244
- }
245
- function shallowCopy(base, strict) {
246
- if (isMap(base)) {
247
- return new Map(base);
248
- }
249
- if (isSet(base)) {
250
- return new Set(base);
251
- }
252
- if (Array.isArray(base))
253
- return Array.prototype.slice.call(base);
254
- const isPlain = isPlainObject(base);
255
- if (strict === true || strict === "class_only" && !isPlain) {
256
- const descriptors = Object.getOwnPropertyDescriptors(base);
257
- delete descriptors[DRAFT_STATE];
258
- let keys = Reflect.ownKeys(descriptors);
259
- for (let i = 0; i < keys.length; i++) {
260
- const key = keys[i];
261
- const desc = descriptors[key];
262
- if (desc.writable === false) {
263
- desc.writable = true;
264
- desc.configurable = true;
265
- }
266
- if (desc.get || desc.set)
267
- descriptors[key] = {
268
- configurable: true,
269
- writable: true,
270
- // could live with !!desc.set as well here...
271
- enumerable: desc.enumerable,
272
- value: base[key]
273
- };
274
- }
275
- return Object.create(getPrototypeOf(base), descriptors);
276
- } else {
277
- const proto = getPrototypeOf(base);
278
- if (proto !== null && isPlain) {
279
- return { ...base };
280
- }
281
- const obj = Object.create(proto);
282
- return Object.assign(obj, base);
283
- }
284
- }
285
- function freeze(obj, deep = false) {
286
- if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
287
- return obj;
288
- if (getArchtype(obj) > 1) {
289
- obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
290
- }
291
- Object.freeze(obj);
292
- if (deep)
293
- Object.entries(obj).forEach(([key, value]) => freeze(value, true));
294
- return obj;
295
- }
296
- function dontMutateFrozenCollections() {
297
- die(2);
298
- }
299
- function isFrozen(obj) {
300
- return Object.isFrozen(obj);
301
- }
302
- var plugins = {};
303
- function getPlugin(pluginKey) {
304
- const plugin = plugins[pluginKey];
305
- if (!plugin) {
306
- die(0, pluginKey);
307
- }
308
- return plugin;
309
- }
310
- var currentScope;
311
- function getCurrentScope() {
312
- return currentScope;
313
- }
314
- function createScope(parent_, immer_) {
315
- return {
316
- drafts_: [],
317
- parent_,
318
- immer_,
319
- // Whenever the modified draft contains a draft from another scope, we
320
- // need to prevent auto-freezing so the unowned draft can be finalized.
321
- canAutoFreeze_: true,
322
- unfinalizedDrafts_: 0
323
- };
324
- }
325
- function usePatchesInScope(scope, patchListener) {
326
- if (patchListener) {
327
- getPlugin("Patches");
328
- scope.patches_ = [];
329
- scope.inversePatches_ = [];
330
- scope.patchListener_ = patchListener;
331
- }
332
- }
333
- function revokeScope(scope) {
334
- leaveScope(scope);
335
- scope.drafts_.forEach(revokeDraft);
336
- scope.drafts_ = null;
337
- }
338
- function leaveScope(scope) {
339
- if (scope === currentScope) {
340
- currentScope = scope.parent_;
341
- }
342
- }
343
- function enterScope(immer2) {
344
- return currentScope = createScope(currentScope, immer2);
345
- }
346
- function revokeDraft(draft) {
347
- const state = draft[DRAFT_STATE];
348
- if (state.type_ === 0 || state.type_ === 1)
349
- state.revoke_();
350
- else
351
- state.revoked_ = true;
352
- }
353
- function processResult(result, scope) {
354
- scope.unfinalizedDrafts_ = scope.drafts_.length;
355
- const baseDraft = scope.drafts_[0];
356
- const isReplaced = result !== void 0 && result !== baseDraft;
357
- if (isReplaced) {
358
- if (baseDraft[DRAFT_STATE].modified_) {
359
- revokeScope(scope);
360
- die(4);
361
- }
362
- if (isDraftable(result)) {
363
- result = finalize(scope, result);
364
- if (!scope.parent_)
365
- maybeFreeze(scope, result);
366
- }
367
- if (scope.patches_) {
368
- getPlugin("Patches").generateReplacementPatches_(
369
- baseDraft[DRAFT_STATE].base_,
370
- result,
371
- scope.patches_,
372
- scope.inversePatches_
373
- );
374
- }
375
- } else {
376
- result = finalize(scope, baseDraft, []);
377
- }
378
- revokeScope(scope);
379
- if (scope.patches_) {
380
- scope.patchListener_(scope.patches_, scope.inversePatches_);
381
- }
382
- return result !== NOTHING ? result : void 0;
383
- }
384
- function finalize(rootScope, value, path) {
385
- if (isFrozen(value))
386
- return value;
387
- const state = value[DRAFT_STATE];
388
- if (!state) {
389
- each(
390
- value,
391
- (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path)
392
- );
393
- return value;
394
- }
395
- if (state.scope_ !== rootScope)
396
- return value;
397
- if (!state.modified_) {
398
- maybeFreeze(rootScope, state.base_, true);
399
- return state.base_;
400
- }
401
- if (!state.finalized_) {
402
- state.finalized_ = true;
403
- state.scope_.unfinalizedDrafts_--;
404
- const result = state.copy_;
405
- let resultEach = result;
406
- let isSet2 = false;
407
- if (state.type_ === 3) {
408
- resultEach = new Set(result);
409
- result.clear();
410
- isSet2 = true;
411
- }
412
- each(
413
- resultEach,
414
- (key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2)
415
- );
416
- maybeFreeze(rootScope, result, false);
417
- if (path && rootScope.patches_) {
418
- getPlugin("Patches").generatePatches_(
419
- state,
420
- path,
421
- rootScope.patches_,
422
- rootScope.inversePatches_
423
- );
424
- }
425
- }
426
- return state.copy_;
427
- }
428
- function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
429
- if (process.env.NODE_ENV !== "production" && childValue === targetObject)
430
- die(5);
431
- if (isDraft(childValue)) {
432
- const path = rootPath && parentState && parentState.type_ !== 3 && // Set objects are atomic since they have no keys.
433
- !has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
434
- const res = finalize(rootScope, childValue, path);
435
- set(targetObject, prop, res);
436
- if (isDraft(res)) {
437
- rootScope.canAutoFreeze_ = false;
438
- } else
439
- return;
440
- } else if (targetIsSet) {
441
- targetObject.add(childValue);
442
- }
443
- if (isDraftable(childValue) && !isFrozen(childValue)) {
444
- if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
445
- return;
446
- }
447
- finalize(rootScope, childValue);
448
- if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && Object.prototype.propertyIsEnumerable.call(targetObject, prop))
449
- maybeFreeze(rootScope, childValue);
450
- }
451
- }
452
- function maybeFreeze(scope, value, deep = false) {
453
- if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
454
- freeze(value, deep);
455
- }
456
- }
457
- function createProxyProxy(base, parent) {
458
- const isArray = Array.isArray(base);
459
- const state = {
460
- type_: isArray ? 1 : 0,
461
- // Track which produce call this is associated with.
462
- scope_: parent ? parent.scope_ : getCurrentScope(),
463
- // True for both shallow and deep changes.
464
- modified_: false,
465
- // Used during finalization.
466
- finalized_: false,
467
- // Track which properties have been assigned (true) or deleted (false).
468
- assigned_: {},
469
- // The parent draft state.
470
- parent_: parent,
471
- // The base state.
472
- base_: base,
473
- // The base proxy.
474
- draft_: null,
475
- // set below
476
- // The base copy with any updated values.
477
- copy_: null,
478
- // Called by the `produce` function.
479
- revoke_: null,
480
- isManual_: false
481
- };
482
- let target = state;
483
- let traps = objectTraps;
484
- if (isArray) {
485
- target = [state];
486
- traps = arrayTraps;
487
- }
488
- const { revoke, proxy } = Proxy.revocable(target, traps);
489
- state.draft_ = proxy;
490
- state.revoke_ = revoke;
491
- return proxy;
492
- }
493
- var objectTraps = {
494
- get(state, prop) {
495
- if (prop === DRAFT_STATE)
496
- return state;
497
- const source = latest(state);
498
- if (!has(source, prop)) {
499
- return readPropFromProto(state, source, prop);
500
- }
501
- const value = source[prop];
502
- if (state.finalized_ || !isDraftable(value)) {
503
- return value;
504
- }
505
- if (value === peek(state.base_, prop)) {
506
- prepareCopy(state);
507
- return state.copy_[prop] = createProxy(value, state);
508
- }
509
- return value;
510
- },
511
- has(state, prop) {
512
- return prop in latest(state);
513
- },
514
- ownKeys(state) {
515
- return Reflect.ownKeys(latest(state));
516
- },
517
- set(state, prop, value) {
518
- const desc = getDescriptorFromProto(latest(state), prop);
519
- if (desc?.set) {
520
- desc.set.call(state.draft_, value);
521
- return true;
522
- }
523
- if (!state.modified_) {
524
- const current2 = peek(latest(state), prop);
525
- const currentState = current2?.[DRAFT_STATE];
526
- if (currentState && currentState.base_ === value) {
527
- state.copy_[prop] = value;
528
- state.assigned_[prop] = false;
529
- return true;
530
- }
531
- if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
532
- return true;
533
- prepareCopy(state);
534
- markChanged(state);
535
- }
536
- if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
537
- (value !== void 0 || prop in state.copy_) || // special case: NaN
538
- Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
539
- return true;
540
- state.copy_[prop] = value;
541
- state.assigned_[prop] = true;
542
- return true;
543
- },
544
- deleteProperty(state, prop) {
545
- if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
546
- state.assigned_[prop] = false;
547
- prepareCopy(state);
548
- markChanged(state);
549
- } else {
550
- delete state.assigned_[prop];
551
- }
552
- if (state.copy_) {
553
- delete state.copy_[prop];
554
- }
555
- return true;
556
- },
557
- // Note: We never coerce `desc.value` into an Immer draft, because we can't make
558
- // the same guarantee in ES5 mode.
559
- getOwnPropertyDescriptor(state, prop) {
560
- const owner = latest(state);
561
- const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
562
- if (!desc)
563
- return desc;
564
- return {
565
- writable: true,
566
- configurable: state.type_ !== 1 || prop !== "length",
567
- enumerable: desc.enumerable,
568
- value: owner[prop]
569
- };
570
- },
571
- defineProperty() {
572
- die(11);
573
- },
574
- getPrototypeOf(state) {
575
- return getPrototypeOf(state.base_);
576
- },
577
- setPrototypeOf() {
578
- die(12);
579
- }
580
- };
581
- var arrayTraps = {};
582
- each(objectTraps, (key, fn) => {
583
- arrayTraps[key] = function() {
584
- arguments[0] = arguments[0][0];
585
- return fn.apply(this, arguments);
586
- };
587
- });
588
- arrayTraps.deleteProperty = function(state, prop) {
589
- if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
590
- die(13);
591
- return arrayTraps.set.call(this, state, prop, void 0);
592
- };
593
- arrayTraps.set = function(state, prop, value) {
594
- if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
595
- die(14);
596
- return objectTraps.set.call(this, state[0], prop, value, state[0]);
597
- };
598
- function peek(draft, prop) {
599
- const state = draft[DRAFT_STATE];
600
- const source = state ? latest(state) : draft;
601
- return source[prop];
602
- }
603
- function readPropFromProto(state, source, prop) {
604
- const desc = getDescriptorFromProto(source, prop);
605
- return desc ? `value` in desc ? desc.value : (
606
- // This is a very special case, if the prop is a getter defined by the
607
- // prototype, we should invoke it with the draft as context!
608
- desc.get?.call(state.draft_)
609
- ) : void 0;
610
- }
611
- function getDescriptorFromProto(source, prop) {
612
- if (!(prop in source))
613
- return void 0;
614
- let proto = getPrototypeOf(source);
615
- while (proto) {
616
- const desc = Object.getOwnPropertyDescriptor(proto, prop);
617
- if (desc)
618
- return desc;
619
- proto = getPrototypeOf(proto);
620
- }
621
- return void 0;
622
- }
623
- function markChanged(state) {
624
- if (!state.modified_) {
625
- state.modified_ = true;
626
- if (state.parent_) {
627
- markChanged(state.parent_);
628
- }
629
- }
630
- }
631
- function prepareCopy(state) {
632
- if (!state.copy_) {
633
- state.copy_ = shallowCopy(
634
- state.base_,
635
- state.scope_.immer_.useStrictShallowCopy_
636
- );
637
- }
638
- }
639
- var Immer2 = class {
640
- constructor(config) {
641
- this.autoFreeze_ = true;
642
- this.useStrictShallowCopy_ = false;
643
- this.produce = (base, recipe, patchListener) => {
644
- if (typeof base === "function" && typeof recipe !== "function") {
645
- const defaultBase = recipe;
646
- recipe = base;
647
- const self = this;
648
- return function curriedProduce(base2 = defaultBase, ...args) {
649
- return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
650
- };
651
- }
652
- if (typeof recipe !== "function")
653
- die(6);
654
- if (patchListener !== void 0 && typeof patchListener !== "function")
655
- die(7);
656
- let result;
657
- if (isDraftable(base)) {
658
- const scope = enterScope(this);
659
- const proxy = createProxy(base, void 0);
660
- let hasError = true;
661
- try {
662
- result = recipe(proxy);
663
- hasError = false;
664
- } finally {
665
- if (hasError)
666
- revokeScope(scope);
667
- else
668
- leaveScope(scope);
669
- }
670
- usePatchesInScope(scope, patchListener);
671
- return processResult(result, scope);
672
- } else if (!base || typeof base !== "object") {
673
- result = recipe(base);
674
- if (result === void 0)
675
- result = base;
676
- if (result === NOTHING)
677
- result = void 0;
678
- if (this.autoFreeze_)
679
- freeze(result, true);
680
- if (patchListener) {
681
- const p = [];
682
- const ip = [];
683
- getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
684
- patchListener(p, ip);
685
- }
686
- return result;
687
- } else
688
- die(1, base);
689
- };
690
- this.produceWithPatches = (base, recipe) => {
691
- if (typeof base === "function") {
692
- return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
693
- }
694
- let patches, inversePatches;
695
- const result = this.produce(base, recipe, (p, ip) => {
696
- patches = p;
697
- inversePatches = ip;
698
- });
699
- return [result, patches, inversePatches];
700
- };
701
- if (typeof config?.autoFreeze === "boolean")
702
- this.setAutoFreeze(config.autoFreeze);
703
- if (typeof config?.useStrictShallowCopy === "boolean")
704
- this.setUseStrictShallowCopy(config.useStrictShallowCopy);
705
- }
706
- createDraft(base) {
707
- if (!isDraftable(base))
708
- die(8);
709
- if (isDraft(base))
710
- base = current(base);
711
- const scope = enterScope(this);
712
- const proxy = createProxy(base, void 0);
713
- proxy[DRAFT_STATE].isManual_ = true;
714
- leaveScope(scope);
715
- return proxy;
716
- }
717
- finishDraft(draft, patchListener) {
718
- const state = draft && draft[DRAFT_STATE];
719
- if (!state || !state.isManual_)
720
- die(9);
721
- const { scope_: scope } = state;
722
- usePatchesInScope(scope, patchListener);
723
- return processResult(void 0, scope);
724
- }
725
- /**
726
- * Pass true to automatically freeze all copies created by Immer.
727
- *
728
- * By default, auto-freezing is enabled.
729
- */
730
- setAutoFreeze(value) {
731
- this.autoFreeze_ = value;
732
- }
733
- /**
734
- * Pass true to enable strict shallow copy.
735
- *
736
- * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
737
- */
738
- setUseStrictShallowCopy(value) {
739
- this.useStrictShallowCopy_ = value;
740
- }
741
- applyPatches(base, patches) {
742
- let i;
743
- for (i = patches.length - 1; i >= 0; i--) {
744
- const patch = patches[i];
745
- if (patch.path.length === 0 && patch.op === "replace") {
746
- base = patch.value;
747
- break;
748
- }
749
- }
750
- if (i > -1) {
751
- patches = patches.slice(i + 1);
752
- }
753
- const applyPatchesImpl = getPlugin("Patches").applyPatches_;
754
- if (isDraft(base)) {
755
- return applyPatchesImpl(base, patches);
756
- }
757
- return this.produce(
758
- base,
759
- (draft) => applyPatchesImpl(draft, patches)
760
- );
761
- }
762
- };
763
- function createProxy(value, parent) {
764
- const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
765
- const scope = parent ? parent.scope_ : getCurrentScope();
766
- scope.drafts_.push(draft);
767
- return draft;
768
- }
769
- function current(value) {
770
- if (!isDraft(value))
771
- die(10, value);
772
- return currentImpl(value);
773
- }
774
- function currentImpl(value) {
775
- if (!isDraftable(value) || isFrozen(value))
776
- return value;
777
- const state = value[DRAFT_STATE];
778
- let copy;
779
- if (state) {
780
- if (!state.modified_)
781
- return state.base_;
782
- state.finalized_ = true;
783
- copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
784
- } else {
785
- copy = shallowCopy(value, true);
786
- }
787
- each(copy, (key, childValue) => {
788
- set(copy, key, currentImpl(childValue));
789
- });
790
- if (state) {
791
- state.finalized_ = false;
792
- }
793
- return copy;
794
- }
795
- var immer = new Immer2();
796
- var produce = immer.produce;
797
- var produceWithPatches = immer.produceWithPatches.bind(
798
- immer
799
- );
800
- var setAutoFreeze = immer.setAutoFreeze.bind(immer);
801
- var setUseStrictShallowCopy = immer.setUseStrictShallowCopy.bind(immer);
802
- var applyPatches = immer.applyPatches.bind(immer);
803
- var createDraft = immer.createDraft.bind(immer);
804
- var finishDraft = immer.finishDraft.bind(immer);
805
-
806
- // ../../node_modules/slate/dist/index.es.js
807
- var Path = {
808
- ancestors(path) {
809
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
810
- var {
811
- reverse = false
812
- } = options;
813
- var paths = Path.levels(path, options);
814
- if (reverse) {
815
- paths = paths.slice(1);
816
- } else {
817
- paths = paths.slice(0, -1);
818
- }
819
- return paths;
820
- },
821
- common(path, another) {
822
- var common = [];
823
- for (var i = 0; i < path.length && i < another.length; i++) {
824
- var av = path[i];
825
- var bv = another[i];
826
- if (av !== bv) {
827
- break;
828
- }
829
- common.push(av);
830
- }
831
- return common;
832
- },
833
- compare(path, another) {
834
- var min = Math.min(path.length, another.length);
835
- for (var i = 0; i < min; i++) {
836
- if (path[i] < another[i]) return -1;
837
- if (path[i] > another[i]) return 1;
838
- }
839
- return 0;
840
- },
841
- endsAfter(path, another) {
842
- var i = path.length - 1;
843
- var as = path.slice(0, i);
844
- var bs = another.slice(0, i);
845
- var av = path[i];
846
- var bv = another[i];
847
- return Path.equals(as, bs) && av > bv;
848
- },
849
- endsAt(path, another) {
850
- var i = path.length;
851
- var as = path.slice(0, i);
852
- var bs = another.slice(0, i);
853
- return Path.equals(as, bs);
854
- },
855
- endsBefore(path, another) {
856
- var i = path.length - 1;
857
- var as = path.slice(0, i);
858
- var bs = another.slice(0, i);
859
- var av = path[i];
860
- var bv = another[i];
861
- return Path.equals(as, bs) && av < bv;
862
- },
863
- equals(path, another) {
864
- return path.length === another.length && path.every((n, i) => n === another[i]);
865
- },
866
- hasPrevious(path) {
867
- return path[path.length - 1] > 0;
868
- },
869
- isAfter(path, another) {
870
- return Path.compare(path, another) === 1;
871
- },
872
- isAncestor(path, another) {
873
- return path.length < another.length && Path.compare(path, another) === 0;
874
- },
875
- isBefore(path, another) {
876
- return Path.compare(path, another) === -1;
877
- },
878
- isChild(path, another) {
879
- return path.length === another.length + 1 && Path.compare(path, another) === 0;
880
- },
881
- isCommon(path, another) {
882
- return path.length <= another.length && Path.compare(path, another) === 0;
883
- },
884
- isDescendant(path, another) {
885
- return path.length > another.length && Path.compare(path, another) === 0;
886
- },
887
- isParent(path, another) {
888
- return path.length + 1 === another.length && Path.compare(path, another) === 0;
889
- },
890
- isPath(value) {
891
- return Array.isArray(value) && (value.length === 0 || typeof value[0] === "number");
892
- },
893
- isSibling(path, another) {
894
- if (path.length !== another.length) {
895
- return false;
896
- }
897
- var as = path.slice(0, -1);
898
- var bs = another.slice(0, -1);
899
- var al = path[path.length - 1];
900
- var bl = another[another.length - 1];
901
- return al !== bl && Path.equals(as, bs);
902
- },
903
- levels(path) {
904
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
905
- var {
906
- reverse = false
907
- } = options;
908
- var list = [];
909
- for (var i = 0; i <= path.length; i++) {
910
- list.push(path.slice(0, i));
911
- }
912
- if (reverse) {
913
- list.reverse();
914
- }
915
- return list;
916
- },
917
- next(path) {
918
- if (path.length === 0) {
919
- throw new Error("Cannot get the next path of a root path [".concat(path, "], because it has no next index."));
920
- }
921
- var last = path[path.length - 1];
922
- return path.slice(0, -1).concat(last + 1);
923
- },
924
- operationCanTransformPath(operation) {
925
- switch (operation.type) {
926
- case "insert_node":
927
- case "remove_node":
928
- case "merge_node":
929
- case "split_node":
930
- case "move_node":
931
- return true;
932
- default:
933
- return false;
934
- }
935
- },
936
- parent(path) {
937
- if (path.length === 0) {
938
- throw new Error("Cannot get the parent path of the root path [".concat(path, "]."));
939
- }
940
- return path.slice(0, -1);
941
- },
942
- previous(path) {
943
- if (path.length === 0) {
944
- throw new Error("Cannot get the previous path of a root path [".concat(path, "], because it has no previous index."));
945
- }
946
- var last = path[path.length - 1];
947
- if (last <= 0) {
948
- throw new Error("Cannot get the previous path of a first child path [".concat(path, "] because it would result in a negative index."));
949
- }
950
- return path.slice(0, -1).concat(last - 1);
951
- },
952
- relative(path, ancestor) {
953
- if (!Path.isAncestor(ancestor, path) && !Path.equals(path, ancestor)) {
954
- throw new Error("Cannot get the relative path of [".concat(path, "] inside ancestor [").concat(ancestor, "], because it is not above or equal to the path."));
955
- }
956
- return path.slice(ancestor.length);
957
- },
958
- transform(path, operation) {
959
- var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
960
- if (!path) return null;
961
- var p = [...path];
962
- var {
963
- affinity = "forward"
964
- } = options;
965
- if (path.length === 0) {
966
- return p;
967
- }
968
- switch (operation.type) {
969
- case "insert_node": {
970
- var {
971
- path: op
972
- } = operation;
973
- if (Path.equals(op, p) || Path.endsBefore(op, p) || Path.isAncestor(op, p)) {
974
- p[op.length - 1] += 1;
975
- }
976
- break;
977
- }
978
- case "remove_node": {
979
- var {
980
- path: _op
981
- } = operation;
982
- if (Path.equals(_op, p) || Path.isAncestor(_op, p)) {
983
- return null;
984
- } else if (Path.endsBefore(_op, p)) {
985
- p[_op.length - 1] -= 1;
986
- }
987
- break;
988
- }
989
- case "merge_node": {
990
- var {
991
- path: _op2,
992
- position
993
- } = operation;
994
- if (Path.equals(_op2, p) || Path.endsBefore(_op2, p)) {
995
- p[_op2.length - 1] -= 1;
996
- } else if (Path.isAncestor(_op2, p)) {
997
- p[_op2.length - 1] -= 1;
998
- p[_op2.length] += position;
999
- }
1000
- break;
1001
- }
1002
- case "split_node": {
1003
- var {
1004
- path: _op3,
1005
- position: _position
1006
- } = operation;
1007
- if (Path.equals(_op3, p)) {
1008
- if (affinity === "forward") {
1009
- p[p.length - 1] += 1;
1010
- } else if (affinity === "backward") ;
1011
- else {
1012
- return null;
1013
- }
1014
- } else if (Path.endsBefore(_op3, p)) {
1015
- p[_op3.length - 1] += 1;
1016
- } else if (Path.isAncestor(_op3, p) && path[_op3.length] >= _position) {
1017
- p[_op3.length - 1] += 1;
1018
- p[_op3.length] -= _position;
1019
- }
1020
- break;
1021
- }
1022
- case "move_node": {
1023
- var {
1024
- path: _op4,
1025
- newPath: onp
1026
- } = operation;
1027
- if (Path.equals(_op4, onp)) {
1028
- return p;
1029
- }
1030
- if (Path.isAncestor(_op4, p) || Path.equals(_op4, p)) {
1031
- var copy = onp.slice();
1032
- if (Path.endsBefore(_op4, onp) && _op4.length < onp.length) {
1033
- copy[_op4.length - 1] -= 1;
1034
- }
1035
- return copy.concat(p.slice(_op4.length));
1036
- } else if (Path.isSibling(_op4, onp) && (Path.isAncestor(onp, p) || Path.equals(onp, p))) {
1037
- if (Path.endsBefore(_op4, p)) {
1038
- p[_op4.length - 1] -= 1;
1039
- } else {
1040
- p[_op4.length - 1] += 1;
1041
- }
1042
- } else if (Path.endsBefore(onp, p) || Path.equals(onp, p) || Path.isAncestor(onp, p)) {
1043
- if (Path.endsBefore(_op4, p)) {
1044
- p[_op4.length - 1] -= 1;
1045
- }
1046
- p[onp.length - 1] += 1;
1047
- } else if (Path.endsBefore(_op4, p)) {
1048
- if (Path.equals(onp, p)) {
1049
- p[onp.length - 1] += 1;
1050
- }
1051
- p[_op4.length - 1] -= 1;
1052
- }
1053
- break;
1054
- }
1055
- }
1056
- return p;
1057
- }
1058
- };
1059
- function _typeof(o) {
1060
- "@babel/helpers - typeof";
1061
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
1062
- return typeof o2;
1063
- } : function(o2) {
1064
- return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
1065
- }, _typeof(o);
1066
- }
1067
- function _toPrimitive(input, hint) {
1068
- if (_typeof(input) !== "object" || input === null) return input;
1069
- var prim = input[Symbol.toPrimitive];
1070
- if (prim !== void 0) {
1071
- var res = prim.call(input, hint || "default");
1072
- if (_typeof(res) !== "object") return res;
1073
- throw new TypeError("@@toPrimitive must return a primitive value.");
1074
- }
1075
- return (hint === "string" ? String : Number)(input);
1076
- }
1077
- function _toPropertyKey(arg) {
1078
- var key = _toPrimitive(arg, "string");
1079
- return _typeof(key) === "symbol" ? key : String(key);
1080
- }
1081
- function _defineProperty(obj, key, value) {
1082
- key = _toPropertyKey(key);
1083
- if (key in obj) {
1084
- Object.defineProperty(obj, key, {
1085
- value,
1086
- enumerable: true,
1087
- configurable: true,
1088
- writable: true
1089
- });
1090
- } else {
1091
- obj[key] = value;
1092
- }
1093
- return obj;
1094
- }
1095
- function ownKeys$e(e, r) {
1096
- var t = Object.keys(e);
1097
- if (Object.getOwnPropertySymbols) {
1098
- var o = Object.getOwnPropertySymbols(e);
1099
- r && (o = o.filter(function(r2) {
1100
- return Object.getOwnPropertyDescriptor(e, r2).enumerable;
1101
- })), t.push.apply(t, o);
1102
- }
1103
- return t;
1104
- }
1105
- function _objectSpread$e(e) {
1106
- for (var r = 1; r < arguments.length; r++) {
1107
- var t = null != arguments[r] ? arguments[r] : {};
1108
- r % 2 ? ownKeys$e(Object(t), true).forEach(function(r2) {
1109
- _defineProperty(e, r2, t[r2]);
1110
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$e(Object(t)).forEach(function(r2) {
1111
- Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
1112
- });
1113
- }
1114
- return e;
1115
- }
1116
- var insertChildren = function insertChildren2(xs, index) {
1117
- for (var _len = arguments.length, newValues = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
1118
- newValues[_key - 2] = arguments[_key];
1119
- }
1120
- return [...xs.slice(0, index), ...newValues, ...xs.slice(index)];
1121
- };
1122
- var replaceChildren = function replaceChildren2(xs, index, removeCount) {
1123
- for (var _len2 = arguments.length, newValues = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
1124
- newValues[_key2 - 3] = arguments[_key2];
1125
- }
1126
- return [...xs.slice(0, index), ...newValues, ...xs.slice(index + removeCount)];
1127
- };
1128
- var removeChildren = replaceChildren;
1129
- var modifyDescendant = (editor, path, f) => {
1130
- if (path.length === 0) {
1131
- throw new Error("Cannot modify the editor");
1132
- }
1133
- var node = Node.get(editor, path);
1134
- var slicedPath = path.slice();
1135
- var modifiedNode = f(node);
1136
- while (slicedPath.length > 1) {
1137
- var _index = slicedPath.pop();
1138
- var ancestorNode = Node.get(editor, slicedPath);
1139
- modifiedNode = _objectSpread$e(_objectSpread$e({}, ancestorNode), {}, {
1140
- children: replaceChildren(ancestorNode.children, _index, 1, modifiedNode)
1141
- });
1142
- }
1143
- var index = slicedPath.pop();
1144
- editor.children = replaceChildren(editor.children, index, 1, modifiedNode);
1145
- };
1146
- var modifyChildren = (editor, path, f) => {
1147
- if (path.length === 0) {
1148
- editor.children = f(editor.children);
1149
- } else {
1150
- modifyDescendant(editor, path, (node) => {
1151
- if (Text.isText(node)) {
1152
- throw new Error("Cannot get the element at path [".concat(path, "] because it refers to a leaf node: ").concat(Scrubber.stringify(node)));
1153
- }
1154
- return _objectSpread$e(_objectSpread$e({}, node), {}, {
1155
- children: f(node.children)
1156
- });
1157
- });
1158
- }
1159
- };
1160
- var modifyLeaf = (editor, path, f) => modifyDescendant(editor, path, (node) => {
1161
- if (!Text.isText(node)) {
1162
- throw new Error("Cannot get the leaf node at path [".concat(path, "] because it refers to a non-leaf node: ").concat(Scrubber.stringify(node)));
1163
- }
1164
- return f(node);
1165
- });
1166
- var GeneralTransforms = {
1167
- transform(editor, op) {
1168
- var transformSelection = false;
1169
- switch (op.type) {
1170
- case "insert_node": {
1171
- var {
1172
- path,
1173
- node
1174
- } = op;
1175
- modifyChildren(editor, Path.parent(path), (children) => {
1176
- var index2 = path[path.length - 1];
1177
- if (index2 > children.length) {
1178
- throw new Error('Cannot apply an "insert_node" operation at path ['.concat(path, "] because the destination is past the end of the node."));
1179
- }
1180
- return insertChildren(children, index2, node);
1181
- });
1182
- transformSelection = true;
1183
- break;
1184
- }
1185
- case "insert_text": {
1186
- var {
1187
- path: _path,
1188
- offset,
1189
- text
1190
- } = op;
1191
- if (text.length === 0) break;
1192
- modifyLeaf(editor, _path, (node2) => {
1193
- var before = node2.text.slice(0, offset);
1194
- var after = node2.text.slice(offset);
1195
- return _objectSpread$e(_objectSpread$e({}, node2), {}, {
1196
- text: before + text + after
1197
- });
1198
- });
1199
- transformSelection = true;
1200
- break;
1201
- }
1202
- case "merge_node": {
1203
- var {
1204
- path: _path2
1205
- } = op;
1206
- var index = _path2[_path2.length - 1];
1207
- var prevPath = Path.previous(_path2);
1208
- var prevIndex = prevPath[prevPath.length - 1];
1209
- modifyChildren(editor, Path.parent(_path2), (children) => {
1210
- var node2 = children[index];
1211
- var prev2 = children[prevIndex];
1212
- var newNode;
1213
- if (Text.isText(node2) && Text.isText(prev2)) {
1214
- newNode = _objectSpread$e(_objectSpread$e({}, prev2), {}, {
1215
- text: prev2.text + node2.text
1216
- });
1217
- } else if (!Text.isText(node2) && !Text.isText(prev2)) {
1218
- newNode = _objectSpread$e(_objectSpread$e({}, prev2), {}, {
1219
- children: prev2.children.concat(node2.children)
1220
- });
1221
- } else {
1222
- throw new Error('Cannot apply a "merge_node" operation at path ['.concat(_path2, "] to nodes of different interfaces: ").concat(Scrubber.stringify(node2), " ").concat(Scrubber.stringify(prev2)));
1223
- }
1224
- return replaceChildren(children, prevIndex, 2, newNode);
1225
- });
1226
- transformSelection = true;
1227
- break;
1228
- }
1229
- case "move_node": {
1230
- var {
1231
- path: _path3,
1232
- newPath
1233
- } = op;
1234
- var _index2 = _path3[_path3.length - 1];
1235
- if (Path.isAncestor(_path3, newPath)) {
1236
- throw new Error("Cannot move a path [".concat(_path3, "] to new path [").concat(newPath, "] because the destination is inside itself."));
1237
- }
1238
- var _node = Node.get(editor, _path3);
1239
- modifyChildren(editor, Path.parent(_path3), (children) => removeChildren(children, _index2, 1));
1240
- var truePath = Path.transform(_path3, op);
1241
- var newIndex = truePath[truePath.length - 1];
1242
- modifyChildren(editor, Path.parent(truePath), (children) => insertChildren(children, newIndex, _node));
1243
- transformSelection = true;
1244
- break;
1245
- }
1246
- case "remove_node": {
1247
- var {
1248
- path: _path4
1249
- } = op;
1250
- var _index3 = _path4[_path4.length - 1];
1251
- modifyChildren(editor, Path.parent(_path4), (children) => removeChildren(children, _index3, 1));
1252
- if (editor.selection) {
1253
- var selection = _objectSpread$e({}, editor.selection);
1254
- for (var [point, key] of Range.points(selection)) {
1255
- var result = Point.transform(point, op);
1256
- if (selection != null && result != null) {
1257
- selection[key] = result;
1258
- } else {
1259
- var prev = void 0;
1260
- var next = void 0;
1261
- for (var [n, p] of Node.texts(editor)) {
1262
- if (Path.compare(p, _path4) === -1) {
1263
- prev = [n, p];
1264
- } else {
1265
- next = [n, p];
1266
- break;
1267
- }
1268
- }
1269
- var preferNext = false;
1270
- if (prev && next) {
1271
- if (Path.isSibling(prev[1], _path4)) {
1272
- preferNext = false;
1273
- } else if (Path.equals(next[1], _path4)) {
1274
- preferNext = true;
1275
- } else {
1276
- preferNext = Path.common(prev[1], _path4).length < Path.common(next[1], _path4).length;
1277
- }
1278
- }
1279
- if (prev && !preferNext) {
1280
- selection[key] = {
1281
- path: prev[1],
1282
- offset: prev[0].text.length
1283
- };
1284
- } else if (next) {
1285
- selection[key] = {
1286
- path: next[1],
1287
- offset: 0
1288
- };
1289
- } else {
1290
- selection = null;
1291
- }
1292
- }
1293
- }
1294
- if (!selection || !Range.equals(selection, editor.selection)) {
1295
- editor.selection = selection;
1296
- }
1297
- }
1298
- break;
1299
- }
1300
- case "remove_text": {
1301
- var {
1302
- path: _path5,
1303
- offset: _offset,
1304
- text: _text
1305
- } = op;
1306
- if (_text.length === 0) break;
1307
- modifyLeaf(editor, _path5, (node2) => {
1308
- var before = node2.text.slice(0, _offset);
1309
- var after = node2.text.slice(_offset + _text.length);
1310
- return _objectSpread$e(_objectSpread$e({}, node2), {}, {
1311
- text: before + after
1312
- });
1313
- });
1314
- transformSelection = true;
1315
- break;
1316
- }
1317
- case "set_node": {
1318
- var {
1319
- path: _path6,
1320
- properties,
1321
- newProperties
1322
- } = op;
1323
- if (_path6.length === 0) {
1324
- throw new Error("Cannot set properties on the root node!");
1325
- }
1326
- modifyDescendant(editor, _path6, (node2) => {
1327
- var newNode = _objectSpread$e({}, node2);
1328
- for (var _key3 in newProperties) {
1329
- if (_key3 === "children" || _key3 === "text") {
1330
- throw new Error('Cannot set the "'.concat(_key3, '" property of nodes!'));
1331
- }
1332
- var value2 = newProperties[_key3];
1333
- if (value2 == null) {
1334
- delete newNode[_key3];
1335
- } else {
1336
- newNode[_key3] = value2;
1337
- }
1338
- }
1339
- for (var _key4 in properties) {
1340
- if (!newProperties.hasOwnProperty(_key4)) {
1341
- delete newNode[_key4];
1342
- }
1343
- }
1344
- return newNode;
1345
- });
1346
- break;
1347
- }
1348
- case "set_selection": {
1349
- var {
1350
- newProperties: _newProperties
1351
- } = op;
1352
- if (_newProperties == null) {
1353
- editor.selection = null;
1354
- break;
1355
- }
1356
- if (editor.selection == null) {
1357
- if (!Range.isRange(_newProperties)) {
1358
- throw new Error('Cannot apply an incomplete "set_selection" operation properties '.concat(Scrubber.stringify(_newProperties), " when there is no current selection."));
1359
- }
1360
- editor.selection = _objectSpread$e({}, _newProperties);
1361
- break;
1362
- }
1363
- var _selection = _objectSpread$e({}, editor.selection);
1364
- for (var _key5 in _newProperties) {
1365
- var value = _newProperties[_key5];
1366
- if (value == null) {
1367
- if (_key5 === "anchor" || _key5 === "focus") {
1368
- throw new Error('Cannot remove the "'.concat(_key5, '" selection property'));
1369
- }
1370
- delete _selection[_key5];
1371
- } else {
1372
- _selection[_key5] = value;
1373
- }
1374
- }
1375
- editor.selection = _selection;
1376
- break;
1377
- }
1378
- case "split_node": {
1379
- var {
1380
- path: _path7,
1381
- position,
1382
- properties: _properties
1383
- } = op;
1384
- var _index4 = _path7[_path7.length - 1];
1385
- if (_path7.length === 0) {
1386
- throw new Error('Cannot apply a "split_node" operation at path ['.concat(_path7, "] because the root node cannot be split."));
1387
- }
1388
- modifyChildren(editor, Path.parent(_path7), (children) => {
1389
- var node2 = children[_index4];
1390
- var newNode;
1391
- var nextNode;
1392
- if (Text.isText(node2)) {
1393
- var before = node2.text.slice(0, position);
1394
- var after = node2.text.slice(position);
1395
- newNode = _objectSpread$e(_objectSpread$e({}, node2), {}, {
1396
- text: before
1397
- });
1398
- nextNode = _objectSpread$e(_objectSpread$e({}, _properties), {}, {
1399
- text: after
1400
- });
1401
- } else {
1402
- var _before = node2.children.slice(0, position);
1403
- var _after = node2.children.slice(position);
1404
- newNode = _objectSpread$e(_objectSpread$e({}, node2), {}, {
1405
- children: _before
1406
- });
1407
- nextNode = _objectSpread$e(_objectSpread$e({}, _properties), {}, {
1408
- children: _after
1409
- });
1410
- }
1411
- return replaceChildren(children, _index4, 1, newNode, nextNode);
1412
- });
1413
- transformSelection = true;
1414
- break;
1415
- }
1416
- }
1417
- if (transformSelection && editor.selection) {
1418
- var _selection2 = _objectSpread$e({}, editor.selection);
1419
- for (var [_point, _key6] of Range.points(_selection2)) {
1420
- _selection2[_key6] = Point.transform(_point, op);
1421
- }
1422
- if (!Range.equals(_selection2, editor.selection)) {
1423
- editor.selection = _selection2;
1424
- }
1425
- }
1426
- }
1427
- };
1428
- var NodeTransforms = {
1429
- insertNodes(editor, nodes, options) {
1430
- editor.insertNodes(nodes, options);
1431
- },
1432
- liftNodes(editor, options) {
1433
- editor.liftNodes(options);
1434
- },
1435
- mergeNodes(editor, options) {
1436
- editor.mergeNodes(options);
1437
- },
1438
- moveNodes(editor, options) {
1439
- editor.moveNodes(options);
1440
- },
1441
- removeNodes(editor, options) {
1442
- editor.removeNodes(options);
1443
- },
1444
- setNodes(editor, props, options) {
1445
- editor.setNodes(props, options);
1446
- },
1447
- splitNodes(editor, options) {
1448
- editor.splitNodes(options);
1449
- },
1450
- unsetNodes(editor, props, options) {
1451
- editor.unsetNodes(props, options);
1452
- },
1453
- unwrapNodes(editor, options) {
1454
- editor.unwrapNodes(options);
1455
- },
1456
- wrapNodes(editor, element, options) {
1457
- editor.wrapNodes(element, options);
1458
- }
1459
- };
1460
- var SelectionTransforms = {
1461
- collapse(editor, options) {
1462
- editor.collapse(options);
1463
- },
1464
- deselect(editor) {
1465
- editor.deselect();
1466
- },
1467
- move(editor, options) {
1468
- editor.move(options);
1469
- },
1470
- select(editor, target) {
1471
- editor.select(target);
1472
- },
1473
- setPoint(editor, props, options) {
1474
- editor.setPoint(props, options);
1475
- },
1476
- setSelection(editor, props) {
1477
- editor.setSelection(props);
1478
- }
1479
- };
1480
- var isObject = (value) => typeof value === "object" && value !== null;
1481
- var isDeepEqual = (node, another) => {
1482
- for (var key in node) {
1483
- var a = node[key];
1484
- var b = another[key];
1485
- if (Array.isArray(a) && Array.isArray(b)) {
1486
- if (a.length !== b.length) return false;
1487
- for (var i = 0; i < a.length; i++) {
1488
- if (a[i] !== b[i]) return false;
1489
- }
1490
- } else if (isObject(a) && isObject(b)) {
1491
- if (!isDeepEqual(a, b)) return false;
1492
- } else if (a !== b) {
1493
- return false;
1494
- }
1495
- }
1496
- for (var _key in another) {
1497
- if (node[_key] === void 0 && another[_key] !== void 0) {
1498
- return false;
1499
- }
1500
- }
1501
- return true;
1502
- };
1503
- function _objectWithoutPropertiesLoose(source, excluded) {
1504
- if (source == null) return {};
1505
- var target = {};
1506
- var sourceKeys = Object.keys(source);
1507
- var key, i;
1508
- for (i = 0; i < sourceKeys.length; i++) {
1509
- key = sourceKeys[i];
1510
- if (excluded.indexOf(key) >= 0) continue;
1511
- target[key] = source[key];
1512
- }
1513
- return target;
1514
- }
1515
- function _objectWithoutProperties(source, excluded) {
1516
- if (source == null) return {};
1517
- var target = _objectWithoutPropertiesLoose(source, excluded);
1518
- var key, i;
1519
- if (Object.getOwnPropertySymbols) {
1520
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
1521
- for (i = 0; i < sourceSymbolKeys.length; i++) {
1522
- key = sourceSymbolKeys[i];
1523
- if (excluded.indexOf(key) >= 0) continue;
1524
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
1525
- target[key] = source[key];
1526
- }
1527
- }
1528
- return target;
1529
- }
1530
- var _excluded$4 = ["anchor", "focus"];
1531
- function ownKeys$d(e, r) {
1532
- var t = Object.keys(e);
1533
- if (Object.getOwnPropertySymbols) {
1534
- var o = Object.getOwnPropertySymbols(e);
1535
- r && (o = o.filter(function(r2) {
1536
- return Object.getOwnPropertyDescriptor(e, r2).enumerable;
1537
- })), t.push.apply(t, o);
1538
- }
1539
- return t;
1540
- }
1541
- function _objectSpread$d(e) {
1542
- for (var r = 1; r < arguments.length; r++) {
1543
- var t = null != arguments[r] ? arguments[r] : {};
1544
- r % 2 ? ownKeys$d(Object(t), true).forEach(function(r2) {
1545
- _defineProperty(e, r2, t[r2]);
1546
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$d(Object(t)).forEach(function(r2) {
1547
- Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
1548
- });
1549
- }
1550
- return e;
1551
- }
1552
- var Range = {
1553
- edges(range) {
1554
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1555
- var {
1556
- reverse = false
1557
- } = options;
1558
- var {
1559
- anchor,
1560
- focus
1561
- } = range;
1562
- return Range.isBackward(range) === reverse ? [anchor, focus] : [focus, anchor];
1563
- },
1564
- end(range) {
1565
- var [, end] = Range.edges(range);
1566
- return end;
1567
- },
1568
- equals(range, another) {
1569
- return Point.equals(range.anchor, another.anchor) && Point.equals(range.focus, another.focus);
1570
- },
1571
- surrounds(range, target) {
1572
- var intersectionRange = Range.intersection(range, target);
1573
- if (!intersectionRange) {
1574
- return false;
1575
- }
1576
- return Range.equals(intersectionRange, target);
1577
- },
1578
- includes(range, target) {
1579
- if (Range.isRange(target)) {
1580
- if (Range.includes(range, target.anchor) || Range.includes(range, target.focus)) {
1581
- return true;
1582
- }
1583
- var [rs, re] = Range.edges(range);
1584
- var [ts, te] = Range.edges(target);
1585
- return Point.isBefore(rs, ts) && Point.isAfter(re, te);
1586
- }
1587
- var [start, end] = Range.edges(range);
1588
- var isAfterStart = false;
1589
- var isBeforeEnd = false;
1590
- if (Point.isPoint(target)) {
1591
- isAfterStart = Point.compare(target, start) >= 0;
1592
- isBeforeEnd = Point.compare(target, end) <= 0;
1593
- } else {
1594
- isAfterStart = Path.compare(target, start.path) >= 0;
1595
- isBeforeEnd = Path.compare(target, end.path) <= 0;
1596
- }
1597
- return isAfterStart && isBeforeEnd;
1598
- },
1599
- intersection(range, another) {
1600
- var rest = _objectWithoutProperties(range, _excluded$4);
1601
- var [s1, e1] = Range.edges(range);
1602
- var [s2, e2] = Range.edges(another);
1603
- var start = Point.isBefore(s1, s2) ? s2 : s1;
1604
- var end = Point.isBefore(e1, e2) ? e1 : e2;
1605
- if (Point.isBefore(end, start)) {
1606
- return null;
1607
- } else {
1608
- return _objectSpread$d({
1609
- anchor: start,
1610
- focus: end
1611
- }, rest);
1612
- }
1613
- },
1614
- isBackward(range) {
1615
- var {
1616
- anchor,
1617
- focus
1618
- } = range;
1619
- return Point.isAfter(anchor, focus);
1620
- },
1621
- isCollapsed(range) {
1622
- var {
1623
- anchor,
1624
- focus
1625
- } = range;
1626
- return Point.equals(anchor, focus);
1627
- },
1628
- isExpanded(range) {
1629
- return !Range.isCollapsed(range);
1630
- },
1631
- isForward(range) {
1632
- return !Range.isBackward(range);
1633
- },
1634
- isRange(value) {
1635
- return isObject(value) && Point.isPoint(value.anchor) && Point.isPoint(value.focus);
1636
- },
1637
- *points(range) {
1638
- yield [range.anchor, "anchor"];
1639
- yield [range.focus, "focus"];
1640
- },
1641
- start(range) {
1642
- var [start] = Range.edges(range);
1643
- return start;
1644
- },
1645
- transform(range, op) {
1646
- var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1647
- if (range === null) {
1648
- return null;
1649
- }
1650
- var {
1651
- affinity = "inward"
1652
- } = options;
1653
- var affinityAnchor;
1654
- var affinityFocus;
1655
- if (affinity === "inward") {
1656
- var isCollapsed = Range.isCollapsed(range);
1657
- if (Range.isForward(range)) {
1658
- affinityAnchor = "forward";
1659
- affinityFocus = isCollapsed ? affinityAnchor : "backward";
1660
- } else {
1661
- affinityAnchor = "backward";
1662
- affinityFocus = isCollapsed ? affinityAnchor : "forward";
1663
- }
1664
- } else if (affinity === "outward") {
1665
- if (Range.isForward(range)) {
1666
- affinityAnchor = "backward";
1667
- affinityFocus = "forward";
1668
- } else {
1669
- affinityAnchor = "forward";
1670
- affinityFocus = "backward";
1671
- }
1672
- } else {
1673
- affinityAnchor = affinity;
1674
- affinityFocus = affinity;
1675
- }
1676
- var anchor = Point.transform(range.anchor, op, {
1677
- affinity: affinityAnchor
1678
- });
1679
- var focus = Point.transform(range.focus, op, {
1680
- affinity: affinityFocus
1681
- });
1682
- if (!anchor || !focus) {
1683
- return null;
1684
- }
1685
- return {
1686
- anchor,
1687
- focus
1688
- };
1689
- }
1690
- };
1691
- var isElement = function isElement2(value) {
1692
- var {
1693
- deep = false
1694
- } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1695
- if (!isObject(value)) return false;
1696
- var isEditor3 = typeof value.apply === "function";
1697
- if (isEditor3) return false;
1698
- var isChildrenValid = deep ? Node.isNodeList(value.children) : Array.isArray(value.children);
1699
- return isChildrenValid;
1700
- };
1701
- var Element = {
1702
- isAncestor(value) {
1703
- var {
1704
- deep = false
1705
- } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1706
- return isObject(value) && Node.isNodeList(value.children, {
1707
- deep
1708
- });
1709
- },
1710
- isElement,
1711
- isElementList(value) {
1712
- var {
1713
- deep = false
1714
- } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1715
- return Array.isArray(value) && value.every((val) => Element.isElement(val, {
1716
- deep
1717
- }));
1718
- },
1719
- isElementProps(props) {
1720
- return props.children !== void 0;
1721
- },
1722
- isElementType: function isElementType(value, elementVal) {
1723
- var elementKey = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "type";
1724
- return isElement(value) && value[elementKey] === elementVal;
1725
- },
1726
- matches(element, props) {
1727
- for (var key in props) {
1728
- if (key === "children") {
1729
- continue;
1730
- }
1731
- if (element[key] !== props[key]) {
1732
- return false;
1733
- }
1734
- }
1735
- return true;
1736
- }
1737
- };
1738
- var _excluded$3 = ["children"];
1739
- var _excluded2$3 = ["text"];
1740
- var Node = {
1741
- ancestor(root, path) {
1742
- var node = Node.get(root, path);
1743
- if (Text.isText(node)) {
1744
- throw new Error("Cannot get the ancestor node at path [".concat(path, "] because it refers to a text node instead: ").concat(Scrubber.stringify(node)));
1745
- }
1746
- return node;
1747
- },
1748
- ancestors(root, path) {
1749
- var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1750
- return function* () {
1751
- for (var p of Path.ancestors(path, options)) {
1752
- var n = Node.ancestor(root, p);
1753
- var entry = [n, p];
1754
- yield entry;
1755
- }
1756
- }();
1757
- },
1758
- child(root, index) {
1759
- if (Text.isText(root)) {
1760
- throw new Error("Cannot get the child of a text node: ".concat(Scrubber.stringify(root)));
1761
- }
1762
- var c = root.children[index];
1763
- if (c == null) {
1764
- throw new Error("Cannot get child at index `".concat(index, "` in node: ").concat(Scrubber.stringify(root)));
1765
- }
1766
- return c;
1767
- },
1768
- children(root, path) {
1769
- var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1770
- return function* () {
1771
- var {
1772
- reverse = false
1773
- } = options;
1774
- var ancestor = Node.ancestor(root, path);
1775
- var {
1776
- children
1777
- } = ancestor;
1778
- var index = reverse ? children.length - 1 : 0;
1779
- while (reverse ? index >= 0 : index < children.length) {
1780
- var child = Node.child(ancestor, index);
1781
- var childPath = path.concat(index);
1782
- yield [child, childPath];
1783
- index = reverse ? index - 1 : index + 1;
1784
- }
1785
- }();
1786
- },
1787
- common(root, path, another) {
1788
- var p = Path.common(path, another);
1789
- var n = Node.get(root, p);
1790
- return [n, p];
1791
- },
1792
- descendant(root, path) {
1793
- var node = Node.get(root, path);
1794
- if (Editor.isEditor(node)) {
1795
- throw new Error("Cannot get the descendant node at path [".concat(path, "] because it refers to the root editor node instead: ").concat(Scrubber.stringify(node)));
1796
- }
1797
- return node;
1798
- },
1799
- descendants(root) {
1800
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1801
- return function* () {
1802
- for (var [node, path] of Node.nodes(root, options)) {
1803
- if (path.length !== 0) {
1804
- yield [node, path];
1805
- }
1806
- }
1807
- }();
1808
- },
1809
- elements(root) {
1810
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1811
- return function* () {
1812
- for (var [node, path] of Node.nodes(root, options)) {
1813
- if (Element.isElement(node)) {
1814
- yield [node, path];
1815
- }
1816
- }
1817
- }();
1818
- },
1819
- extractProps(node) {
1820
- if (Element.isAncestor(node)) {
1821
- var properties = _objectWithoutProperties(node, _excluded$3);
1822
- return properties;
1823
- } else {
1824
- var properties = _objectWithoutProperties(node, _excluded2$3);
1825
- return properties;
1826
- }
1827
- },
1828
- first(root, path) {
1829
- var p = path.slice();
1830
- var n = Node.get(root, p);
1831
- while (n) {
1832
- if (Text.isText(n) || n.children.length === 0) {
1833
- break;
1834
- } else {
1835
- n = n.children[0];
1836
- p.push(0);
1837
- }
1838
- }
1839
- return [n, p];
1840
- },
1841
- fragment(root, range) {
1842
- var newRoot = produce({
1843
- children: root.children
1844
- }, (r) => {
1845
- var [start, end] = Range.edges(range);
1846
- var nodeEntries = Node.nodes(r, {
1847
- reverse: true,
1848
- pass: (_ref) => {
1849
- var [, path2] = _ref;
1850
- return !Range.includes(range, path2);
1851
- }
1852
- });
1853
- for (var [, path] of nodeEntries) {
1854
- if (!Range.includes(range, path)) {
1855
- var parent = Node.parent(r, path);
1856
- var index = path[path.length - 1];
1857
- parent.children.splice(index, 1);
1858
- }
1859
- if (Path.equals(path, end.path)) {
1860
- var leaf = Node.leaf(r, path);
1861
- leaf.text = leaf.text.slice(0, end.offset);
1862
- }
1863
- if (Path.equals(path, start.path)) {
1864
- var _leaf = Node.leaf(r, path);
1865
- _leaf.text = _leaf.text.slice(start.offset);
1866
- }
1867
- }
1868
- if (Editor.isEditor(r)) {
1869
- r.selection = null;
1870
- }
1871
- });
1872
- return newRoot.children;
1873
- },
1874
- get(root, path) {
1875
- var node = Node.getIf(root, path);
1876
- if (node === void 0) {
1877
- throw new Error("Cannot find a descendant at path [".concat(path, "] in node: ").concat(Scrubber.stringify(root)));
1878
- }
1879
- return node;
1880
- },
1881
- getIf(root, path) {
1882
- var node = root;
1883
- for (var i = 0; i < path.length; i++) {
1884
- var p = path[i];
1885
- if (Text.isText(node) || !node.children[p]) {
1886
- return;
1887
- }
1888
- node = node.children[p];
1889
- }
1890
- return node;
1891
- },
1892
- has(root, path) {
1893
- var node = root;
1894
- for (var i = 0; i < path.length; i++) {
1895
- var p = path[i];
1896
- if (Text.isText(node) || !node.children[p]) {
1897
- return false;
1898
- }
1899
- node = node.children[p];
1900
- }
1901
- return true;
1902
- },
1903
- isNode(value) {
1904
- var {
1905
- deep = false
1906
- } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1907
- return Text.isText(value) || Element.isElement(value, {
1908
- deep
1909
- }) || Editor.isEditor(value, {
1910
- deep
1911
- });
1912
- },
1913
- isNodeList(value) {
1914
- var {
1915
- deep = false
1916
- } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1917
- return Array.isArray(value) && value.every((val) => Node.isNode(val, {
1918
- deep
1919
- }));
1920
- },
1921
- last(root, path) {
1922
- var p = path.slice();
1923
- var n = Node.get(root, p);
1924
- while (n) {
1925
- if (Text.isText(n) || n.children.length === 0) {
1926
- break;
1927
- } else {
1928
- var i = n.children.length - 1;
1929
- n = n.children[i];
1930
- p.push(i);
1931
- }
1932
- }
1933
- return [n, p];
1934
- },
1935
- leaf(root, path) {
1936
- var node = Node.get(root, path);
1937
- if (!Text.isText(node)) {
1938
- throw new Error("Cannot get the leaf node at path [".concat(path, "] because it refers to a non-leaf node: ").concat(Scrubber.stringify(node)));
1939
- }
1940
- return node;
1941
- },
1942
- levels(root, path) {
1943
- var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1944
- return function* () {
1945
- for (var p of Path.levels(path, options)) {
1946
- var n = Node.get(root, p);
1947
- yield [n, p];
1948
- }
1949
- }();
1950
- },
1951
- matches(node, props) {
1952
- return Element.isElement(node) && Element.isElementProps(props) && Element.matches(node, props) || Text.isText(node) && Text.isTextProps(props) && Text.matches(node, props);
1953
- },
1954
- nodes(root) {
1955
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1956
- return function* () {
1957
- var {
1958
- pass,
1959
- reverse = false
1960
- } = options;
1961
- var {
1962
- from = [],
1963
- to
1964
- } = options;
1965
- var visited = /* @__PURE__ */ new Set();
1966
- var p = [];
1967
- var n = root;
1968
- while (true) {
1969
- if (to && (reverse ? Path.isBefore(p, to) : Path.isAfter(p, to))) {
1970
- break;
1971
- }
1972
- if (!visited.has(n)) {
1973
- yield [n, p];
1974
- }
1975
- if (!visited.has(n) && !Text.isText(n) && n.children.length !== 0 && (pass == null || pass([n, p]) === false)) {
1976
- visited.add(n);
1977
- var nextIndex = reverse ? n.children.length - 1 : 0;
1978
- if (Path.isAncestor(p, from)) {
1979
- nextIndex = from[p.length];
1980
- }
1981
- p = p.concat(nextIndex);
1982
- n = Node.get(root, p);
1983
- continue;
1984
- }
1985
- if (p.length === 0) {
1986
- break;
1987
- }
1988
- if (!reverse) {
1989
- var newPath = Path.next(p);
1990
- if (Node.has(root, newPath)) {
1991
- p = newPath;
1992
- n = Node.get(root, p);
1993
- continue;
1994
- }
1995
- }
1996
- if (reverse && p[p.length - 1] !== 0) {
1997
- var _newPath = Path.previous(p);
1998
- p = _newPath;
1999
- n = Node.get(root, p);
2000
- continue;
2001
- }
2002
- p = Path.parent(p);
2003
- n = Node.get(root, p);
2004
- visited.add(n);
2005
- }
2006
- }();
2007
- },
2008
- parent(root, path) {
2009
- var parentPath = Path.parent(path);
2010
- var p = Node.get(root, parentPath);
2011
- if (Text.isText(p)) {
2012
- throw new Error("Cannot get the parent of path [".concat(path, "] because it does not exist in the root."));
2013
- }
2014
- return p;
2015
- },
2016
- string(node) {
2017
- if (Text.isText(node)) {
2018
- return node.text;
2019
- } else {
2020
- return node.children.map(Node.string).join("");
2021
- }
2022
- },
2023
- texts(root) {
2024
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
2025
- return function* () {
2026
- for (var [node, path] of Node.nodes(root, options)) {
2027
- if (Text.isText(node)) {
2028
- yield [node, path];
2029
- }
2030
- }
2031
- }();
2032
- }
2033
- };
2034
- function ownKeys$c(e, r) {
2035
- var t = Object.keys(e);
2036
- if (Object.getOwnPropertySymbols) {
2037
- var o = Object.getOwnPropertySymbols(e);
2038
- r && (o = o.filter(function(r2) {
2039
- return Object.getOwnPropertyDescriptor(e, r2).enumerable;
2040
- })), t.push.apply(t, o);
2041
- }
2042
- return t;
2043
- }
2044
- function _objectSpread$c(e) {
2045
- for (var r = 1; r < arguments.length; r++) {
2046
- var t = null != arguments[r] ? arguments[r] : {};
2047
- r % 2 ? ownKeys$c(Object(t), true).forEach(function(r2) {
2048
- _defineProperty(e, r2, t[r2]);
2049
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$c(Object(t)).forEach(function(r2) {
2050
- Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
2051
- });
2052
- }
2053
- return e;
2054
- }
2055
- var Operation = {
2056
- isNodeOperation(value) {
2057
- return Operation.isOperation(value) && value.type.endsWith("_node");
2058
- },
2059
- isOperation(value) {
2060
- if (!isObject(value)) {
2061
- return false;
2062
- }
2063
- switch (value.type) {
2064
- case "insert_node":
2065
- return Path.isPath(value.path) && Node.isNode(value.node);
2066
- case "insert_text":
2067
- return typeof value.offset === "number" && typeof value.text === "string" && Path.isPath(value.path);
2068
- case "merge_node":
2069
- return typeof value.position === "number" && Path.isPath(value.path) && isObject(value.properties);
2070
- case "move_node":
2071
- return Path.isPath(value.path) && Path.isPath(value.newPath);
2072
- case "remove_node":
2073
- return Path.isPath(value.path) && Node.isNode(value.node);
2074
- case "remove_text":
2075
- return typeof value.offset === "number" && typeof value.text === "string" && Path.isPath(value.path);
2076
- case "set_node":
2077
- return Path.isPath(value.path) && isObject(value.properties) && isObject(value.newProperties);
2078
- case "set_selection":
2079
- return value.properties === null && Range.isRange(value.newProperties) || value.newProperties === null && Range.isRange(value.properties) || isObject(value.properties) && isObject(value.newProperties);
2080
- case "split_node":
2081
- return Path.isPath(value.path) && typeof value.position === "number" && isObject(value.properties);
2082
- default:
2083
- return false;
2084
- }
2085
- },
2086
- isOperationList(value) {
2087
- return Array.isArray(value) && value.every((val) => Operation.isOperation(val));
2088
- },
2089
- isSelectionOperation(value) {
2090
- return Operation.isOperation(value) && value.type.endsWith("_selection");
2091
- },
2092
- isTextOperation(value) {
2093
- return Operation.isOperation(value) && value.type.endsWith("_text");
2094
- },
2095
- inverse(op) {
2096
- switch (op.type) {
2097
- case "insert_node": {
2098
- return _objectSpread$c(_objectSpread$c({}, op), {}, {
2099
- type: "remove_node"
2100
- });
2101
- }
2102
- case "insert_text": {
2103
- return _objectSpread$c(_objectSpread$c({}, op), {}, {
2104
- type: "remove_text"
2105
- });
2106
- }
2107
- case "merge_node": {
2108
- return _objectSpread$c(_objectSpread$c({}, op), {}, {
2109
- type: "split_node",
2110
- path: Path.previous(op.path)
2111
- });
2112
- }
2113
- case "move_node": {
2114
- var {
2115
- newPath,
2116
- path
2117
- } = op;
2118
- if (Path.equals(newPath, path)) {
2119
- return op;
2120
- }
2121
- if (Path.isSibling(path, newPath)) {
2122
- return _objectSpread$c(_objectSpread$c({}, op), {}, {
2123
- path: newPath,
2124
- newPath: path
2125
- });
2126
- }
2127
- var inversePath = Path.transform(path, op);
2128
- var inverseNewPath = Path.transform(Path.next(path), op);
2129
- return _objectSpread$c(_objectSpread$c({}, op), {}, {
2130
- path: inversePath,
2131
- newPath: inverseNewPath
2132
- });
2133
- }
2134
- case "remove_node": {
2135
- return _objectSpread$c(_objectSpread$c({}, op), {}, {
2136
- type: "insert_node"
2137
- });
2138
- }
2139
- case "remove_text": {
2140
- return _objectSpread$c(_objectSpread$c({}, op), {}, {
2141
- type: "insert_text"
2142
- });
2143
- }
2144
- case "set_node": {
2145
- var {
2146
- properties,
2147
- newProperties
2148
- } = op;
2149
- return _objectSpread$c(_objectSpread$c({}, op), {}, {
2150
- properties: newProperties,
2151
- newProperties: properties
2152
- });
2153
- }
2154
- case "set_selection": {
2155
- var {
2156
- properties: _properties,
2157
- newProperties: _newProperties
2158
- } = op;
2159
- if (_properties == null) {
2160
- return _objectSpread$c(_objectSpread$c({}, op), {}, {
2161
- properties: _newProperties,
2162
- newProperties: null
2163
- });
2164
- } else if (_newProperties == null) {
2165
- return _objectSpread$c(_objectSpread$c({}, op), {}, {
2166
- properties: null,
2167
- newProperties: _properties
2168
- });
2169
- } else {
2170
- return _objectSpread$c(_objectSpread$c({}, op), {}, {
2171
- properties: _newProperties,
2172
- newProperties: _properties
2173
- });
2174
- }
2175
- }
2176
- case "split_node": {
2177
- return _objectSpread$c(_objectSpread$c({}, op), {}, {
2178
- type: "merge_node",
2179
- path: Path.next(op.path)
2180
- });
2181
- }
2182
- }
2183
- }
2184
- };
2185
- var isEditor = function isEditor2(value) {
2186
- var {
2187
- deep = false
2188
- } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
2189
- if (!isObject(value)) {
2190
- return false;
2191
- }
2192
- var isEditor3 = typeof value.addMark === "function" && typeof value.apply === "function" && typeof value.deleteFragment === "function" && typeof value.insertBreak === "function" && typeof value.insertSoftBreak === "function" && typeof value.insertFragment === "function" && typeof value.insertNode === "function" && typeof value.insertText === "function" && typeof value.isElementReadOnly === "function" && typeof value.isInline === "function" && typeof value.isSelectable === "function" && typeof value.isVoid === "function" && typeof value.normalizeNode === "function" && typeof value.onChange === "function" && typeof value.removeMark === "function" && typeof value.getDirtyPaths === "function" && (value.marks === null || isObject(value.marks)) && (value.selection === null || Range.isRange(value.selection)) && (!deep || Node.isNodeList(value.children)) && Operation.isOperationList(value.operations);
2193
- return isEditor3;
2194
- };
2195
- var Editor = {
2196
- above(editor, options) {
2197
- return editor.above(options);
2198
- },
2199
- addMark(editor, key, value) {
2200
- editor.addMark(key, value);
2201
- },
2202
- after(editor, at, options) {
2203
- return editor.after(at, options);
2204
- },
2205
- before(editor, at, options) {
2206
- return editor.before(at, options);
2207
- },
2208
- deleteBackward(editor) {
2209
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
2210
- var {
2211
- unit = "character"
2212
- } = options;
2213
- editor.deleteBackward(unit);
2214
- },
2215
- deleteForward(editor) {
2216
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
2217
- var {
2218
- unit = "character"
2219
- } = options;
2220
- editor.deleteForward(unit);
2221
- },
2222
- deleteFragment(editor, options) {
2223
- editor.deleteFragment(options);
2224
- },
2225
- edges(editor, at) {
2226
- return editor.edges(at);
2227
- },
2228
- elementReadOnly(editor) {
2229
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
2230
- return editor.elementReadOnly(options);
2231
- },
2232
- end(editor, at) {
2233
- return editor.end(at);
2234
- },
2235
- first(editor, at) {
2236
- return editor.first(at);
2237
- },
2238
- fragment(editor, at) {
2239
- return editor.fragment(at);
2240
- },
2241
- hasBlocks(editor, element) {
2242
- return editor.hasBlocks(element);
2243
- },
2244
- hasInlines(editor, element) {
2245
- return editor.hasInlines(element);
2246
- },
2247
- hasPath(editor, path) {
2248
- return editor.hasPath(path);
2249
- },
2250
- hasTexts(editor, element) {
2251
- return editor.hasTexts(element);
2252
- },
2253
- insertBreak(editor) {
2254
- editor.insertBreak();
2255
- },
2256
- insertFragment(editor, fragment, options) {
2257
- editor.insertFragment(fragment, options);
2258
- },
2259
- insertNode(editor, node) {
2260
- editor.insertNode(node);
2261
- },
2262
- insertSoftBreak(editor) {
2263
- editor.insertSoftBreak();
2264
- },
2265
- insertText(editor, text) {
2266
- editor.insertText(text);
2267
- },
2268
- isBlock(editor, value) {
2269
- return editor.isBlock(value);
2270
- },
2271
- isEdge(editor, point, at) {
2272
- return editor.isEdge(point, at);
2273
- },
2274
- isEditor(value) {
2275
- return isEditor(value);
2276
- },
2277
- isElementReadOnly(editor, element) {
2278
- return editor.isElementReadOnly(element);
2279
- },
2280
- isEmpty(editor, element) {
2281
- return editor.isEmpty(element);
2282
- },
2283
- isEnd(editor, point, at) {
2284
- return editor.isEnd(point, at);
2285
- },
2286
- isInline(editor, value) {
2287
- return editor.isInline(value);
2288
- },
2289
- isNormalizing(editor) {
2290
- return editor.isNormalizing();
2291
- },
2292
- isSelectable(editor, value) {
2293
- return editor.isSelectable(value);
2294
- },
2295
- isStart(editor, point, at) {
2296
- return editor.isStart(point, at);
2297
- },
2298
- isVoid(editor, value) {
2299
- return editor.isVoid(value);
2300
- },
2301
- last(editor, at) {
2302
- return editor.last(at);
2303
- },
2304
- leaf(editor, at, options) {
2305
- return editor.leaf(at, options);
2306
- },
2307
- levels(editor, options) {
2308
- return editor.levels(options);
2309
- },
2310
- marks(editor) {
2311
- return editor.getMarks();
2312
- },
2313
- next(editor, options) {
2314
- return editor.next(options);
2315
- },
2316
- node(editor, at, options) {
2317
- return editor.node(at, options);
2318
- },
2319
- nodes(editor, options) {
2320
- return editor.nodes(options);
2321
- },
2322
- normalize(editor, options) {
2323
- editor.normalize(options);
2324
- },
2325
- parent(editor, at, options) {
2326
- return editor.parent(at, options);
2327
- },
2328
- path(editor, at, options) {
2329
- return editor.path(at, options);
2330
- },
2331
- pathRef(editor, path, options) {
2332
- return editor.pathRef(path, options);
2333
- },
2334
- pathRefs(editor) {
2335
- return editor.pathRefs();
2336
- },
2337
- point(editor, at, options) {
2338
- return editor.point(at, options);
2339
- },
2340
- pointRef(editor, point, options) {
2341
- return editor.pointRef(point, options);
2342
- },
2343
- pointRefs(editor) {
2344
- return editor.pointRefs();
2345
- },
2346
- positions(editor, options) {
2347
- return editor.positions(options);
2348
- },
2349
- previous(editor, options) {
2350
- return editor.previous(options);
2351
- },
2352
- range(editor, at, to) {
2353
- return editor.range(at, to);
2354
- },
2355
- rangeRef(editor, range, options) {
2356
- return editor.rangeRef(range, options);
2357
- },
2358
- rangeRefs(editor) {
2359
- return editor.rangeRefs();
2360
- },
2361
- removeMark(editor, key) {
2362
- editor.removeMark(key);
2363
- },
2364
- setNormalizing(editor, isNormalizing) {
2365
- editor.setNormalizing(isNormalizing);
2366
- },
2367
- start(editor, at) {
2368
- return editor.start(at);
2369
- },
2370
- string(editor, at, options) {
2371
- return editor.string(at, options);
2372
- },
2373
- unhangRange(editor, range, options) {
2374
- return editor.unhangRange(range, options);
2375
- },
2376
- void(editor, options) {
2377
- return editor.void(options);
2378
- },
2379
- withoutNormalizing(editor, fn) {
2380
- editor.withoutNormalizing(fn);
2381
- },
2382
- shouldMergeNodesRemovePrevNode: (editor, prevNode, curNode) => {
2383
- return editor.shouldMergeNodesRemovePrevNode(prevNode, curNode);
2384
- }
2385
- };
2386
- function ownKeys$b(e, r) {
2387
- var t = Object.keys(e);
2388
- if (Object.getOwnPropertySymbols) {
2389
- var o = Object.getOwnPropertySymbols(e);
2390
- r && (o = o.filter(function(r2) {
2391
- return Object.getOwnPropertyDescriptor(e, r2).enumerable;
2392
- })), t.push.apply(t, o);
2393
- }
2394
- return t;
2395
- }
2396
- function _objectSpread$b(e) {
2397
- for (var r = 1; r < arguments.length; r++) {
2398
- var t = null != arguments[r] ? arguments[r] : {};
2399
- r % 2 ? ownKeys$b(Object(t), true).forEach(function(r2) {
2400
- _defineProperty(e, r2, t[r2]);
2401
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$b(Object(t)).forEach(function(r2) {
2402
- Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
2403
- });
2404
- }
2405
- return e;
2406
- }
2407
- var Point = {
2408
- compare(point, another) {
2409
- var result = Path.compare(point.path, another.path);
2410
- if (result === 0) {
2411
- if (point.offset < another.offset) return -1;
2412
- if (point.offset > another.offset) return 1;
2413
- return 0;
2414
- }
2415
- return result;
2416
- },
2417
- isAfter(point, another) {
2418
- return Point.compare(point, another) === 1;
2419
- },
2420
- isBefore(point, another) {
2421
- return Point.compare(point, another) === -1;
2422
- },
2423
- equals(point, another) {
2424
- return point.offset === another.offset && Path.equals(point.path, another.path);
2425
- },
2426
- isPoint(value) {
2427
- return isObject(value) && typeof value.offset === "number" && Path.isPath(value.path);
2428
- },
2429
- transform(point, op) {
2430
- var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
2431
- if (point === null) {
2432
- return null;
2433
- }
2434
- var {
2435
- affinity = "forward"
2436
- } = options;
2437
- var {
2438
- path,
2439
- offset
2440
- } = point;
2441
- switch (op.type) {
2442
- case "insert_node":
2443
- case "move_node": {
2444
- path = Path.transform(path, op, options);
2445
- break;
2446
- }
2447
- case "insert_text": {
2448
- if (Path.equals(op.path, path) && (op.offset < offset || op.offset === offset && affinity === "forward")) {
2449
- offset += op.text.length;
2450
- }
2451
- break;
2452
- }
2453
- case "merge_node": {
2454
- if (Path.equals(op.path, path)) {
2455
- offset += op.position;
2456
- }
2457
- path = Path.transform(path, op, options);
2458
- break;
2459
- }
2460
- case "remove_text": {
2461
- if (Path.equals(op.path, path) && op.offset <= offset) {
2462
- offset -= Math.min(offset - op.offset, op.text.length);
2463
- }
2464
- break;
2465
- }
2466
- case "remove_node": {
2467
- if (Path.equals(op.path, path) || Path.isAncestor(op.path, path)) {
2468
- return null;
2469
- }
2470
- path = Path.transform(path, op, options);
2471
- break;
2472
- }
2473
- case "split_node": {
2474
- if (Path.equals(op.path, path)) {
2475
- if (op.position === offset && affinity == null) {
2476
- return null;
2477
- } else if (op.position < offset || op.position === offset && affinity === "forward") {
2478
- offset -= op.position;
2479
- path = Path.transform(path, op, _objectSpread$b(_objectSpread$b({}, options), {}, {
2480
- affinity: "forward"
2481
- }));
2482
- }
2483
- } else {
2484
- path = Path.transform(path, op, options);
2485
- }
2486
- break;
2487
- }
2488
- default:
2489
- return point;
2490
- }
2491
- return {
2492
- path,
2493
- offset
2494
- };
2495
- }
2496
- };
2497
- var _scrubber = void 0;
2498
- var Scrubber = {
2499
- setScrubber(scrubber) {
2500
- _scrubber = scrubber;
2501
- },
2502
- stringify(value) {
2503
- return JSON.stringify(value, _scrubber);
2504
- }
2505
- };
2506
- var _excluded$2 = ["text"];
2507
- var _excluded2$2 = ["anchor", "focus", "merge"];
2508
- function ownKeys$a(e, r) {
2509
- var t = Object.keys(e);
2510
- if (Object.getOwnPropertySymbols) {
2511
- var o = Object.getOwnPropertySymbols(e);
2512
- r && (o = o.filter(function(r2) {
2513
- return Object.getOwnPropertyDescriptor(e, r2).enumerable;
2514
- })), t.push.apply(t, o);
2515
- }
2516
- return t;
2517
- }
2518
- function _objectSpread$a(e) {
2519
- for (var r = 1; r < arguments.length; r++) {
2520
- var t = null != arguments[r] ? arguments[r] : {};
2521
- r % 2 ? ownKeys$a(Object(t), true).forEach(function(r2) {
2522
- _defineProperty(e, r2, t[r2]);
2523
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$a(Object(t)).forEach(function(r2) {
2524
- Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
2525
- });
2526
- }
2527
- return e;
2528
- }
2529
- var Text = {
2530
- equals(text, another) {
2531
- var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
2532
- var {
2533
- loose = false
2534
- } = options;
2535
- function omitText(obj) {
2536
- var rest = _objectWithoutProperties(obj, _excluded$2);
2537
- return rest;
2538
- }
2539
- return isDeepEqual(loose ? omitText(text) : text, loose ? omitText(another) : another);
2540
- },
2541
- isText(value) {
2542
- return isObject(value) && typeof value.text === "string";
2543
- },
2544
- isTextList(value) {
2545
- return Array.isArray(value) && value.every((val) => Text.isText(val));
2546
- },
2547
- isTextProps(props) {
2548
- return props.text !== void 0;
2549
- },
2550
- matches(text, props) {
2551
- for (var key in props) {
2552
- if (key === "text") {
2553
- continue;
2554
- }
2555
- if (!text.hasOwnProperty(key) || text[key] !== props[key]) {
2556
- return false;
2557
- }
2558
- }
2559
- return true;
2560
- },
2561
- decorations(node, decorations) {
2562
- var leaves = [{
2563
- leaf: _objectSpread$a({}, node)
2564
- }];
2565
- for (var dec of decorations) {
2566
- var {
2567
- anchor,
2568
- focus,
2569
- merge: mergeDecoration
2570
- } = dec, rest = _objectWithoutProperties(dec, _excluded2$2);
2571
- var [start, end] = Range.edges(dec);
2572
- var next = [];
2573
- var leafEnd = 0;
2574
- var decorationStart = start.offset;
2575
- var decorationEnd = end.offset;
2576
- var merge = mergeDecoration !== null && mergeDecoration !== void 0 ? mergeDecoration : Object.assign;
2577
- for (var {
2578
- leaf
2579
- } of leaves) {
2580
- var {
2581
- length
2582
- } = leaf.text;
2583
- var leafStart = leafEnd;
2584
- leafEnd += length;
2585
- if (decorationStart <= leafStart && leafEnd <= decorationEnd) {
2586
- merge(leaf, rest);
2587
- next.push({
2588
- leaf
2589
- });
2590
- continue;
2591
- }
2592
- if (decorationStart !== decorationEnd && (decorationStart === leafEnd || decorationEnd === leafStart) || decorationStart > leafEnd || decorationEnd < leafStart || decorationEnd === leafStart && leafStart !== 0) {
2593
- next.push({
2594
- leaf
2595
- });
2596
- continue;
2597
- }
2598
- var middle = leaf;
2599
- var before = void 0;
2600
- var after = void 0;
2601
- if (decorationEnd < leafEnd) {
2602
- var off = decorationEnd - leafStart;
2603
- after = {
2604
- leaf: _objectSpread$a(_objectSpread$a({}, middle), {}, {
2605
- text: middle.text.slice(off)
2606
- })
2607
- };
2608
- middle = _objectSpread$a(_objectSpread$a({}, middle), {}, {
2609
- text: middle.text.slice(0, off)
2610
- });
2611
- }
2612
- if (decorationStart > leafStart) {
2613
- var _off = decorationStart - leafStart;
2614
- before = {
2615
- leaf: _objectSpread$a(_objectSpread$a({}, middle), {}, {
2616
- text: middle.text.slice(0, _off)
2617
- })
2618
- };
2619
- middle = _objectSpread$a(_objectSpread$a({}, middle), {}, {
2620
- text: middle.text.slice(_off)
2621
- });
2622
- }
2623
- merge(middle, rest);
2624
- if (before) {
2625
- next.push(before);
2626
- }
2627
- next.push({
2628
- leaf: middle
2629
- });
2630
- if (after) {
2631
- next.push(after);
2632
- }
2633
- }
2634
- leaves = next;
2635
- }
2636
- if (leaves.length > 1) {
2637
- var currentOffset = 0;
2638
- for (var [index, item] of leaves.entries()) {
2639
- var _start = currentOffset;
2640
- var _end = _start + item.leaf.text.length;
2641
- var position = {
2642
- start: _start,
2643
- end: _end
2644
- };
2645
- if (index === 0) position.isFirst = true;
2646
- if (index === leaves.length - 1) position.isLast = true;
2647
- item.position = position;
2648
- currentOffset = _end;
2649
- }
2650
- }
2651
- return leaves;
2652
- }
2653
- };
2654
- var getDefaultInsertLocation = (editor) => {
2655
- if (editor.selection) {
2656
- return editor.selection;
2657
- } else if (editor.children.length > 0) {
2658
- return Editor.end(editor, []);
2659
- } else {
2660
- return [0];
2661
- }
2662
- };
2663
- var CodepointType;
2664
- (function(CodepointType2) {
2665
- CodepointType2[CodepointType2["None"] = 0] = "None";
2666
- CodepointType2[CodepointType2["Extend"] = 1] = "Extend";
2667
- CodepointType2[CodepointType2["ZWJ"] = 2] = "ZWJ";
2668
- CodepointType2[CodepointType2["RI"] = 4] = "RI";
2669
- CodepointType2[CodepointType2["Prepend"] = 8] = "Prepend";
2670
- CodepointType2[CodepointType2["SpacingMark"] = 16] = "SpacingMark";
2671
- CodepointType2[CodepointType2["L"] = 32] = "L";
2672
- CodepointType2[CodepointType2["V"] = 64] = "V";
2673
- CodepointType2[CodepointType2["T"] = 128] = "T";
2674
- CodepointType2[CodepointType2["LV"] = 256] = "LV";
2675
- CodepointType2[CodepointType2["LVT"] = 512] = "LVT";
2676
- CodepointType2[CodepointType2["ExtPict"] = 1024] = "ExtPict";
2677
- CodepointType2[CodepointType2["Any"] = 2048] = "Any";
2678
- })(CodepointType || (CodepointType = {}));
2679
- var NonBoundaryPairs = [
2680
- // GB6
2681
- [CodepointType.L, CodepointType.L | CodepointType.V | CodepointType.LV | CodepointType.LVT],
2682
- // GB7
2683
- [CodepointType.LV | CodepointType.V, CodepointType.V | CodepointType.T],
2684
- // GB8
2685
- [CodepointType.LVT | CodepointType.T, CodepointType.T],
2686
- // GB9
2687
- [CodepointType.Any, CodepointType.Extend | CodepointType.ZWJ],
2688
- // GB9a
2689
- [CodepointType.Any, CodepointType.SpacingMark],
2690
- // GB9b
2691
- [CodepointType.Prepend, CodepointType.Any],
2692
- // GB11
2693
- [CodepointType.ZWJ, CodepointType.ExtPict],
2694
- // GB12 and GB13
2695
- [CodepointType.RI, CodepointType.RI]
2696
- ];
2697
- var TextTransforms = {
2698
- delete(editor, options) {
2699
- editor.delete(options);
2700
- },
2701
- insertFragment(editor, fragment, options) {
2702
- editor.insertFragment(fragment, options);
2703
- },
2704
- insertText(editor, text) {
2705
- var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
2706
- Editor.withoutNormalizing(editor, () => {
2707
- var {
2708
- voids = false
2709
- } = options;
2710
- var {
2711
- at = getDefaultInsertLocation(editor)
2712
- } = options;
2713
- if (Path.isPath(at)) {
2714
- at = Editor.range(editor, at);
2715
- }
2716
- if (Range.isRange(at)) {
2717
- if (Range.isCollapsed(at)) {
2718
- at = at.anchor;
2719
- } else {
2720
- var end = Range.end(at);
2721
- if (!voids && Editor.void(editor, {
2722
- at: end
2723
- })) {
2724
- return;
2725
- }
2726
- var start = Range.start(at);
2727
- var startRef = Editor.pointRef(editor, start);
2728
- var endRef = Editor.pointRef(editor, end);
2729
- Transforms.delete(editor, {
2730
- at,
2731
- voids
2732
- });
2733
- var startPoint = startRef.unref();
2734
- var endPoint = endRef.unref();
2735
- at = startPoint || endPoint;
2736
- Transforms.setSelection(editor, {
2737
- anchor: at,
2738
- focus: at
2739
- });
2740
- }
2741
- }
2742
- if (!voids && Editor.void(editor, {
2743
- at
2744
- }) || Editor.elementReadOnly(editor, {
2745
- at
2746
- })) {
2747
- return;
2748
- }
2749
- var {
2750
- path,
2751
- offset
2752
- } = at;
2753
- if (text.length > 0) editor.apply({
2754
- type: "insert_text",
2755
- path,
2756
- offset,
2757
- text
2758
- });
2759
- });
2760
- }
2761
- };
2762
- function ownKeys$9(e, r) {
2763
- var t = Object.keys(e);
2764
- if (Object.getOwnPropertySymbols) {
2765
- var o = Object.getOwnPropertySymbols(e);
2766
- r && (o = o.filter(function(r2) {
2767
- return Object.getOwnPropertyDescriptor(e, r2).enumerable;
2768
- })), t.push.apply(t, o);
2769
- }
2770
- return t;
2771
- }
2772
- function _objectSpread$9(e) {
2773
- for (var r = 1; r < arguments.length; r++) {
2774
- var t = null != arguments[r] ? arguments[r] : {};
2775
- r % 2 ? ownKeys$9(Object(t), true).forEach(function(r2) {
2776
- _defineProperty(e, r2, t[r2]);
2777
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$9(Object(t)).forEach(function(r2) {
2778
- Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
2779
- });
2780
- }
2781
- return e;
2782
- }
2783
- var Transforms = _objectSpread$9(_objectSpread$9(_objectSpread$9(_objectSpread$9({}, GeneralTransforms), NodeTransforms), SelectionTransforms), TextTransforms);
2784
-
2785
- // src/react/ai/utils/findTextRangeInBlock.tsx
136
+ import { NodeApi } from "platejs";
2786
137
  function maxAllowedDistance(len) {
2787
138
  if (len <= 2) return 0;
2788
139
  if (len <= 5) return 1;
@@ -2797,7 +148,7 @@ function findTextRangeInBlock({
2797
148
  const [blockNode, blockPath] = block;
2798
149
  const textSegments = [];
2799
150
  let fullText = "";
2800
- for (const [textNode, textPath] of Node.texts(blockNode)) {
151
+ for (const [textNode, textPath] of NodeApi.texts(blockNode)) {
2801
152
  const startOffset = fullText.length;
2802
153
  const absolutePath = [...blockPath, ...textPath];
2803
154
  textSegments.push({
@@ -2900,7 +251,7 @@ var aiCommentToRange = (editor, aiComment) => {
2900
251
  if (!currentBlock) return;
2901
252
  const range = findTextRangeInBlock({
2902
253
  block: currentBlock,
2903
- findText: NodeApi.string(node)
254
+ findText: NodeApi2.string(node)
2904
255
  });
2905
256
  if (!range) return;
2906
257
  ranges.push(range);
@@ -2999,7 +350,7 @@ import {
2999
350
  import cloneDeep from "lodash/cloneDeep.js";
3000
351
  import {
3001
352
  KEYS as KEYS5,
3002
- NodeApi as NodeApi2,
353
+ NodeApi as NodeApi3,
3003
354
  TextApi as TextApi2
3004
355
  } from "platejs";
3005
356
  var createFormattedBlocks = ({
@@ -3009,10 +360,10 @@ var createFormattedBlocks = ({
3009
360
  }) => {
3010
361
  if (format === "none") return cloneDeep(blocks);
3011
362
  const [sourceNode] = sourceBlock;
3012
- const firstTextEntry = NodeApi2.firstText(sourceNode);
363
+ const firstTextEntry = NodeApi3.firstText(sourceNode);
3013
364
  if (!firstTextEntry) return null;
3014
- const blockProps = NodeApi2.extractProps(sourceNode);
3015
- const textProps = NodeApi2.extractProps(firstTextEntry[0]);
365
+ const blockProps = NodeApi3.extractProps(sourceNode);
366
+ const textProps = NodeApi3.extractProps(firstTextEntry[0]);
3016
367
  const applyTextFormatting = (node) => {
3017
368
  if (TextApi2.isText(node)) {
3018
369
  return { ...textProps, ...node };
@@ -3752,7 +1103,7 @@ var withoutDeserializeInMdx = (editor, input) => {
3752
1103
  import {
3753
1104
  getPluginType as getPluginType5,
3754
1105
  KEYS as KEYS16,
3755
- NodeApi as NodeApi3,
1106
+ NodeApi as NodeApi4,
3756
1107
  PathApi as PathApi2
3757
1108
  } from "platejs";
3758
1109
 
@@ -3842,7 +1193,7 @@ function streamInsertChunk(editor, chunk, options = {}) {
3842
1193
  const blocks = streamDeserializeMd(editor, chunk);
3843
1194
  const path = getCurrentBlockPath(editor);
3844
1195
  const startBlock = editor.api.node(path)[0];
3845
- const startInEmptyParagraph = NodeApi3.string(startBlock).length === 0 && startBlock.type === getPluginType5(editor, KEYS16.p);
1196
+ const startInEmptyParagraph = NodeApi4.string(startBlock).length === 0 && startBlock.type === getPluginType5(editor, KEYS16.p);
3846
1197
  if (startInEmptyParagraph) {
3847
1198
  editor.tf.removeNodes({ at: path });
3848
1199
  }
@@ -3900,7 +1251,7 @@ function streamInsertChunk(editor, chunk, options = {}) {
3900
1251
  },
3901
1252
  tempBlockChunks
3902
1253
  );
3903
- const blockText = NodeApi3.string(tempBlocks[0]);
1254
+ const blockText = NodeApi4.string(tempBlocks[0]);
3904
1255
  if (serializedBlock === tempBlockChunks && blockText === serializedBlock) {
3905
1256
  editor.setOption(AIChatPlugin, "_blockChunks", tempBlockChunks);
3906
1257
  } else {
@@ -4027,30 +1378,31 @@ var applyAISuggestions = (editor, content) => {
4027
1378
  const diffNode = diffNodes[index];
4028
1379
  const isSameString = SkipSuggestionDeletes(editor, replaceNode) === SkipSuggestionDeletes(editor, diffNode);
4029
1380
  const isSameSuggestion = replaceNode.suggestion?.type === diffNode.suggestion?.type;
4030
- if (isSameString && isSameSuggestion && node.id == diffNode.id) {
4031
- return;
4032
- }
4033
1381
  if (index === replaceNodes.length - 1 && diffNodes.length > replaceNodes.length) {
4034
1382
  editor.tf.replaceNodes(diffNodes.slice(index), {
4035
1383
  at: path
4036
1384
  });
4037
- } else {
4038
- editor.tf.replaceNodes(diffNode, {
4039
- at: path
4040
- });
4041
1385
  }
1386
+ if (isSameString && isSameSuggestion && node.id == diffNode.id) {
1387
+ return;
1388
+ }
1389
+ editor.tf.replaceNodes(diffNode, {
1390
+ at: path
1391
+ });
4042
1392
  });
4043
1393
  editor.getApi(BlockSelectionPlugin6).blockSelection.set(diffNodes.map((node) => node.id));
4044
1394
  setReplaceIds(diffNodes.map((node) => node.id));
4045
1395
  } else {
4046
1396
  const diffNodes = getDiffNodes(editor, content);
4047
1397
  editor.tf.insertFragment(diffNodes);
4048
- const nodes = editor.api.nodes({
4049
- at: [],
4050
- mode: "lowest",
4051
- match: (n) => TextApi5.isText(n) && !!n[getTransientSuggestionKey3()]
4052
- });
4053
- const range = editor.api.nodesRange(Array.from(nodes));
1398
+ const nodes = Array.from(
1399
+ editor.api.nodes({
1400
+ at: [],
1401
+ mode: "lowest",
1402
+ match: (n) => TextApi5.isText(n) && !!n[getTransientSuggestionKey3()]
1403
+ })
1404
+ );
1405
+ const range = editor.api.nodesRange(nodes);
4054
1406
  editor.tf.setSelection(range);
4055
1407
  return;
4056
1408
  }
@@ -4119,7 +1471,9 @@ var getDiffNodes = (editor, aiContent) => {
4119
1471
  );
4120
1472
  const aiNodes = withProps(deserializeMd2(editor, aiContent), chatNodes);
4121
1473
  const diffNodes = withTransient(
4122
- diffToSuggestions(editor, chatNodes, aiNodes, { ignoreProps: ["id"] })
1474
+ diffToSuggestions(editor, chatNodes, aiNodes, {
1475
+ ignoreProps: ["id", "listStart"]
1476
+ })
4123
1477
  );
4124
1478
  return diffNodes;
4125
1479
  };
@@ -4130,7 +1484,7 @@ import debounce from "lodash/debounce.js";
4130
1484
  import {
4131
1485
  bindFirst as bindFirst3,
4132
1486
  KEYS as KEYS22,
4133
- NodeApi as NodeApi4
1487
+ NodeApi as NodeApi5
4134
1488
  } from "platejs";
4135
1489
  import { createTPlatePlugin as createTPlatePlugin2 } from "platejs/react";
4136
1490
 
@@ -4471,7 +1825,7 @@ var CopilotPlugin = createTPlatePlugin2({
4471
1825
  if (isEmpty) return false;
4472
1826
  const blockAbove = editor.api.block();
4473
1827
  if (!blockAbove) return false;
4474
- const blockString = NodeApi4.string(blockAbove[0]);
1828
+ const blockString = NodeApi5.string(blockAbove[0]);
4475
1829
  return blockString.at(-1) === " ";
4476
1830
  },
4477
1831
  getPrompt: ({ editor }) => {