@platejs/ai 50.2.1 → 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.
- package/dist/react/index.d.mts +9 -4
- package/dist/react/index.d.ts +9 -4
- package/dist/react/index.js +126 -2767
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +39 -2680
- package/dist/react/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/react/index.js
CHANGED
|
@@ -199,2660 +199,11 @@ var AIPlugin = (0, import_react.toPlatePlugin)(BaseAIPlugin);
|
|
|
199
199
|
|
|
200
200
|
// src/react/ai/utils/aiCommentToRange.ts
|
|
201
201
|
var import_markdown = require("@platejs/markdown");
|
|
202
|
-
var
|
|
203
|
-
|
|
204
|
-
// src/react/ai/utils/findTextRangeInBlock.tsx
|
|
205
|
-
var import_fastest_levenshtein = require("fastest-levenshtein");
|
|
206
|
-
|
|
207
|
-
// ../../node_modules/immer/dist/immer.mjs
|
|
208
|
-
var NOTHING = Symbol.for("immer-nothing");
|
|
209
|
-
var DRAFTABLE = Symbol.for("immer-draftable");
|
|
210
|
-
var DRAFT_STATE = Symbol.for("immer-state");
|
|
211
|
-
var errors = process.env.NODE_ENV !== "production" ? [
|
|
212
|
-
// All error codes, starting by 0:
|
|
213
|
-
function(plugin) {
|
|
214
|
-
return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
|
|
215
|
-
},
|
|
216
|
-
function(thing) {
|
|
217
|
-
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}'`;
|
|
218
|
-
},
|
|
219
|
-
"This object has been frozen and should not be mutated",
|
|
220
|
-
function(data) {
|
|
221
|
-
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
|
|
222
|
-
},
|
|
223
|
-
"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
|
|
224
|
-
"Immer forbids circular references",
|
|
225
|
-
"The first or second argument to `produce` must be a function",
|
|
226
|
-
"The third argument to `produce` must be a function or undefined",
|
|
227
|
-
"First argument to `createDraft` must be a plain object, an array, or an immerable object",
|
|
228
|
-
"First argument to `finishDraft` must be a draft returned by `createDraft`",
|
|
229
|
-
function(thing) {
|
|
230
|
-
return `'current' expects a draft, got: ${thing}`;
|
|
231
|
-
},
|
|
232
|
-
"Object.defineProperty() cannot be used on an Immer draft",
|
|
233
|
-
"Object.setPrototypeOf() cannot be used on an Immer draft",
|
|
234
|
-
"Immer only supports deleting array indices",
|
|
235
|
-
"Immer only supports setting array indices and the 'length' property",
|
|
236
|
-
function(thing) {
|
|
237
|
-
return `'original' expects a draft, got: ${thing}`;
|
|
238
|
-
}
|
|
239
|
-
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
|
|
240
|
-
// See Patches.ts for additional errors
|
|
241
|
-
] : [];
|
|
242
|
-
function die(error, ...args) {
|
|
243
|
-
if (process.env.NODE_ENV !== "production") {
|
|
244
|
-
const e = errors[error];
|
|
245
|
-
const msg = typeof e === "function" ? e.apply(null, args) : e;
|
|
246
|
-
throw new Error(`[Immer] ${msg}`);
|
|
247
|
-
}
|
|
248
|
-
throw new Error(
|
|
249
|
-
`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
var getPrototypeOf = Object.getPrototypeOf;
|
|
253
|
-
function isDraft(value) {
|
|
254
|
-
return !!value && !!value[DRAFT_STATE];
|
|
255
|
-
}
|
|
256
|
-
function isDraftable(value) {
|
|
257
|
-
if (!value)
|
|
258
|
-
return false;
|
|
259
|
-
return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);
|
|
260
|
-
}
|
|
261
|
-
var objectCtorString = Object.prototype.constructor.toString();
|
|
262
|
-
function isPlainObject(value) {
|
|
263
|
-
if (!value || typeof value !== "object")
|
|
264
|
-
return false;
|
|
265
|
-
const proto = getPrototypeOf(value);
|
|
266
|
-
if (proto === null) {
|
|
267
|
-
return true;
|
|
268
|
-
}
|
|
269
|
-
const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
270
|
-
if (Ctor === Object)
|
|
271
|
-
return true;
|
|
272
|
-
return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
|
|
273
|
-
}
|
|
274
|
-
function each(obj, iter) {
|
|
275
|
-
if (getArchtype(obj) === 0) {
|
|
276
|
-
Reflect.ownKeys(obj).forEach((key) => {
|
|
277
|
-
iter(key, obj[key], obj);
|
|
278
|
-
});
|
|
279
|
-
} else {
|
|
280
|
-
obj.forEach((entry, index) => iter(index, entry, obj));
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
function getArchtype(thing) {
|
|
284
|
-
const state = thing[DRAFT_STATE];
|
|
285
|
-
return state ? state.type_ : Array.isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
|
|
286
|
-
}
|
|
287
|
-
function has(thing, prop) {
|
|
288
|
-
return getArchtype(thing) === 2 ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
|
|
289
|
-
}
|
|
290
|
-
function set(thing, propOrOldValue, value) {
|
|
291
|
-
const t = getArchtype(thing);
|
|
292
|
-
if (t === 2)
|
|
293
|
-
thing.set(propOrOldValue, value);
|
|
294
|
-
else if (t === 3) {
|
|
295
|
-
thing.add(value);
|
|
296
|
-
} else
|
|
297
|
-
thing[propOrOldValue] = value;
|
|
298
|
-
}
|
|
299
|
-
function is(x, y) {
|
|
300
|
-
if (x === y) {
|
|
301
|
-
return x !== 0 || 1 / x === 1 / y;
|
|
302
|
-
} else {
|
|
303
|
-
return x !== x && y !== y;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
function isMap(target) {
|
|
307
|
-
return target instanceof Map;
|
|
308
|
-
}
|
|
309
|
-
function isSet(target) {
|
|
310
|
-
return target instanceof Set;
|
|
311
|
-
}
|
|
312
|
-
function latest(state) {
|
|
313
|
-
return state.copy_ || state.base_;
|
|
314
|
-
}
|
|
315
|
-
function shallowCopy(base, strict) {
|
|
316
|
-
if (isMap(base)) {
|
|
317
|
-
return new Map(base);
|
|
318
|
-
}
|
|
319
|
-
if (isSet(base)) {
|
|
320
|
-
return new Set(base);
|
|
321
|
-
}
|
|
322
|
-
if (Array.isArray(base))
|
|
323
|
-
return Array.prototype.slice.call(base);
|
|
324
|
-
const isPlain = isPlainObject(base);
|
|
325
|
-
if (strict === true || strict === "class_only" && !isPlain) {
|
|
326
|
-
const descriptors = Object.getOwnPropertyDescriptors(base);
|
|
327
|
-
delete descriptors[DRAFT_STATE];
|
|
328
|
-
let keys = Reflect.ownKeys(descriptors);
|
|
329
|
-
for (let i = 0; i < keys.length; i++) {
|
|
330
|
-
const key = keys[i];
|
|
331
|
-
const desc = descriptors[key];
|
|
332
|
-
if (desc.writable === false) {
|
|
333
|
-
desc.writable = true;
|
|
334
|
-
desc.configurable = true;
|
|
335
|
-
}
|
|
336
|
-
if (desc.get || desc.set)
|
|
337
|
-
descriptors[key] = {
|
|
338
|
-
configurable: true,
|
|
339
|
-
writable: true,
|
|
340
|
-
// could live with !!desc.set as well here...
|
|
341
|
-
enumerable: desc.enumerable,
|
|
342
|
-
value: base[key]
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
return Object.create(getPrototypeOf(base), descriptors);
|
|
346
|
-
} else {
|
|
347
|
-
const proto = getPrototypeOf(base);
|
|
348
|
-
if (proto !== null && isPlain) {
|
|
349
|
-
return { ...base };
|
|
350
|
-
}
|
|
351
|
-
const obj = Object.create(proto);
|
|
352
|
-
return Object.assign(obj, base);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
function freeze(obj, deep = false) {
|
|
356
|
-
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
|
|
357
|
-
return obj;
|
|
358
|
-
if (getArchtype(obj) > 1) {
|
|
359
|
-
obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
|
|
360
|
-
}
|
|
361
|
-
Object.freeze(obj);
|
|
362
|
-
if (deep)
|
|
363
|
-
Object.entries(obj).forEach(([key, value]) => freeze(value, true));
|
|
364
|
-
return obj;
|
|
365
|
-
}
|
|
366
|
-
function dontMutateFrozenCollections() {
|
|
367
|
-
die(2);
|
|
368
|
-
}
|
|
369
|
-
function isFrozen(obj) {
|
|
370
|
-
return Object.isFrozen(obj);
|
|
371
|
-
}
|
|
372
|
-
var plugins = {};
|
|
373
|
-
function getPlugin(pluginKey) {
|
|
374
|
-
const plugin = plugins[pluginKey];
|
|
375
|
-
if (!plugin) {
|
|
376
|
-
die(0, pluginKey);
|
|
377
|
-
}
|
|
378
|
-
return plugin;
|
|
379
|
-
}
|
|
380
|
-
var currentScope;
|
|
381
|
-
function getCurrentScope() {
|
|
382
|
-
return currentScope;
|
|
383
|
-
}
|
|
384
|
-
function createScope(parent_, immer_) {
|
|
385
|
-
return {
|
|
386
|
-
drafts_: [],
|
|
387
|
-
parent_,
|
|
388
|
-
immer_,
|
|
389
|
-
// Whenever the modified draft contains a draft from another scope, we
|
|
390
|
-
// need to prevent auto-freezing so the unowned draft can be finalized.
|
|
391
|
-
canAutoFreeze_: true,
|
|
392
|
-
unfinalizedDrafts_: 0
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
function usePatchesInScope(scope, patchListener) {
|
|
396
|
-
if (patchListener) {
|
|
397
|
-
getPlugin("Patches");
|
|
398
|
-
scope.patches_ = [];
|
|
399
|
-
scope.inversePatches_ = [];
|
|
400
|
-
scope.patchListener_ = patchListener;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
function revokeScope(scope) {
|
|
404
|
-
leaveScope(scope);
|
|
405
|
-
scope.drafts_.forEach(revokeDraft);
|
|
406
|
-
scope.drafts_ = null;
|
|
407
|
-
}
|
|
408
|
-
function leaveScope(scope) {
|
|
409
|
-
if (scope === currentScope) {
|
|
410
|
-
currentScope = scope.parent_;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
function enterScope(immer2) {
|
|
414
|
-
return currentScope = createScope(currentScope, immer2);
|
|
415
|
-
}
|
|
416
|
-
function revokeDraft(draft) {
|
|
417
|
-
const state = draft[DRAFT_STATE];
|
|
418
|
-
if (state.type_ === 0 || state.type_ === 1)
|
|
419
|
-
state.revoke_();
|
|
420
|
-
else
|
|
421
|
-
state.revoked_ = true;
|
|
422
|
-
}
|
|
423
|
-
function processResult(result, scope) {
|
|
424
|
-
scope.unfinalizedDrafts_ = scope.drafts_.length;
|
|
425
|
-
const baseDraft = scope.drafts_[0];
|
|
426
|
-
const isReplaced = result !== void 0 && result !== baseDraft;
|
|
427
|
-
if (isReplaced) {
|
|
428
|
-
if (baseDraft[DRAFT_STATE].modified_) {
|
|
429
|
-
revokeScope(scope);
|
|
430
|
-
die(4);
|
|
431
|
-
}
|
|
432
|
-
if (isDraftable(result)) {
|
|
433
|
-
result = finalize(scope, result);
|
|
434
|
-
if (!scope.parent_)
|
|
435
|
-
maybeFreeze(scope, result);
|
|
436
|
-
}
|
|
437
|
-
if (scope.patches_) {
|
|
438
|
-
getPlugin("Patches").generateReplacementPatches_(
|
|
439
|
-
baseDraft[DRAFT_STATE].base_,
|
|
440
|
-
result,
|
|
441
|
-
scope.patches_,
|
|
442
|
-
scope.inversePatches_
|
|
443
|
-
);
|
|
444
|
-
}
|
|
445
|
-
} else {
|
|
446
|
-
result = finalize(scope, baseDraft, []);
|
|
447
|
-
}
|
|
448
|
-
revokeScope(scope);
|
|
449
|
-
if (scope.patches_) {
|
|
450
|
-
scope.patchListener_(scope.patches_, scope.inversePatches_);
|
|
451
|
-
}
|
|
452
|
-
return result !== NOTHING ? result : void 0;
|
|
453
|
-
}
|
|
454
|
-
function finalize(rootScope, value, path) {
|
|
455
|
-
if (isFrozen(value))
|
|
456
|
-
return value;
|
|
457
|
-
const state = value[DRAFT_STATE];
|
|
458
|
-
if (!state) {
|
|
459
|
-
each(
|
|
460
|
-
value,
|
|
461
|
-
(key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path)
|
|
462
|
-
);
|
|
463
|
-
return value;
|
|
464
|
-
}
|
|
465
|
-
if (state.scope_ !== rootScope)
|
|
466
|
-
return value;
|
|
467
|
-
if (!state.modified_) {
|
|
468
|
-
maybeFreeze(rootScope, state.base_, true);
|
|
469
|
-
return state.base_;
|
|
470
|
-
}
|
|
471
|
-
if (!state.finalized_) {
|
|
472
|
-
state.finalized_ = true;
|
|
473
|
-
state.scope_.unfinalizedDrafts_--;
|
|
474
|
-
const result = state.copy_;
|
|
475
|
-
let resultEach = result;
|
|
476
|
-
let isSet2 = false;
|
|
477
|
-
if (state.type_ === 3) {
|
|
478
|
-
resultEach = new Set(result);
|
|
479
|
-
result.clear();
|
|
480
|
-
isSet2 = true;
|
|
481
|
-
}
|
|
482
|
-
each(
|
|
483
|
-
resultEach,
|
|
484
|
-
(key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2)
|
|
485
|
-
);
|
|
486
|
-
maybeFreeze(rootScope, result, false);
|
|
487
|
-
if (path && rootScope.patches_) {
|
|
488
|
-
getPlugin("Patches").generatePatches_(
|
|
489
|
-
state,
|
|
490
|
-
path,
|
|
491
|
-
rootScope.patches_,
|
|
492
|
-
rootScope.inversePatches_
|
|
493
|
-
);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
return state.copy_;
|
|
497
|
-
}
|
|
498
|
-
function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
|
|
499
|
-
if (process.env.NODE_ENV !== "production" && childValue === targetObject)
|
|
500
|
-
die(5);
|
|
501
|
-
if (isDraft(childValue)) {
|
|
502
|
-
const path = rootPath && parentState && parentState.type_ !== 3 && // Set objects are atomic since they have no keys.
|
|
503
|
-
!has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
|
|
504
|
-
const res = finalize(rootScope, childValue, path);
|
|
505
|
-
set(targetObject, prop, res);
|
|
506
|
-
if (isDraft(res)) {
|
|
507
|
-
rootScope.canAutoFreeze_ = false;
|
|
508
|
-
} else
|
|
509
|
-
return;
|
|
510
|
-
} else if (targetIsSet) {
|
|
511
|
-
targetObject.add(childValue);
|
|
512
|
-
}
|
|
513
|
-
if (isDraftable(childValue) && !isFrozen(childValue)) {
|
|
514
|
-
if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
finalize(rootScope, childValue);
|
|
518
|
-
if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && Object.prototype.propertyIsEnumerable.call(targetObject, prop))
|
|
519
|
-
maybeFreeze(rootScope, childValue);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
function maybeFreeze(scope, value, deep = false) {
|
|
523
|
-
if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
|
|
524
|
-
freeze(value, deep);
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
function createProxyProxy(base, parent) {
|
|
528
|
-
const isArray = Array.isArray(base);
|
|
529
|
-
const state = {
|
|
530
|
-
type_: isArray ? 1 : 0,
|
|
531
|
-
// Track which produce call this is associated with.
|
|
532
|
-
scope_: parent ? parent.scope_ : getCurrentScope(),
|
|
533
|
-
// True for both shallow and deep changes.
|
|
534
|
-
modified_: false,
|
|
535
|
-
// Used during finalization.
|
|
536
|
-
finalized_: false,
|
|
537
|
-
// Track which properties have been assigned (true) or deleted (false).
|
|
538
|
-
assigned_: {},
|
|
539
|
-
// The parent draft state.
|
|
540
|
-
parent_: parent,
|
|
541
|
-
// The base state.
|
|
542
|
-
base_: base,
|
|
543
|
-
// The base proxy.
|
|
544
|
-
draft_: null,
|
|
545
|
-
// set below
|
|
546
|
-
// The base copy with any updated values.
|
|
547
|
-
copy_: null,
|
|
548
|
-
// Called by the `produce` function.
|
|
549
|
-
revoke_: null,
|
|
550
|
-
isManual_: false
|
|
551
|
-
};
|
|
552
|
-
let target = state;
|
|
553
|
-
let traps = objectTraps;
|
|
554
|
-
if (isArray) {
|
|
555
|
-
target = [state];
|
|
556
|
-
traps = arrayTraps;
|
|
557
|
-
}
|
|
558
|
-
const { revoke, proxy } = Proxy.revocable(target, traps);
|
|
559
|
-
state.draft_ = proxy;
|
|
560
|
-
state.revoke_ = revoke;
|
|
561
|
-
return proxy;
|
|
562
|
-
}
|
|
563
|
-
var objectTraps = {
|
|
564
|
-
get(state, prop) {
|
|
565
|
-
if (prop === DRAFT_STATE)
|
|
566
|
-
return state;
|
|
567
|
-
const source = latest(state);
|
|
568
|
-
if (!has(source, prop)) {
|
|
569
|
-
return readPropFromProto(state, source, prop);
|
|
570
|
-
}
|
|
571
|
-
const value = source[prop];
|
|
572
|
-
if (state.finalized_ || !isDraftable(value)) {
|
|
573
|
-
return value;
|
|
574
|
-
}
|
|
575
|
-
if (value === peek(state.base_, prop)) {
|
|
576
|
-
prepareCopy(state);
|
|
577
|
-
return state.copy_[prop] = createProxy(value, state);
|
|
578
|
-
}
|
|
579
|
-
return value;
|
|
580
|
-
},
|
|
581
|
-
has(state, prop) {
|
|
582
|
-
return prop in latest(state);
|
|
583
|
-
},
|
|
584
|
-
ownKeys(state) {
|
|
585
|
-
return Reflect.ownKeys(latest(state));
|
|
586
|
-
},
|
|
587
|
-
set(state, prop, value) {
|
|
588
|
-
const desc = getDescriptorFromProto(latest(state), prop);
|
|
589
|
-
if (desc?.set) {
|
|
590
|
-
desc.set.call(state.draft_, value);
|
|
591
|
-
return true;
|
|
592
|
-
}
|
|
593
|
-
if (!state.modified_) {
|
|
594
|
-
const current2 = peek(latest(state), prop);
|
|
595
|
-
const currentState = current2?.[DRAFT_STATE];
|
|
596
|
-
if (currentState && currentState.base_ === value) {
|
|
597
|
-
state.copy_[prop] = value;
|
|
598
|
-
state.assigned_[prop] = false;
|
|
599
|
-
return true;
|
|
600
|
-
}
|
|
601
|
-
if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
|
|
602
|
-
return true;
|
|
603
|
-
prepareCopy(state);
|
|
604
|
-
markChanged(state);
|
|
605
|
-
}
|
|
606
|
-
if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
|
|
607
|
-
(value !== void 0 || prop in state.copy_) || // special case: NaN
|
|
608
|
-
Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
|
|
609
|
-
return true;
|
|
610
|
-
state.copy_[prop] = value;
|
|
611
|
-
state.assigned_[prop] = true;
|
|
612
|
-
return true;
|
|
613
|
-
},
|
|
614
|
-
deleteProperty(state, prop) {
|
|
615
|
-
if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
|
|
616
|
-
state.assigned_[prop] = false;
|
|
617
|
-
prepareCopy(state);
|
|
618
|
-
markChanged(state);
|
|
619
|
-
} else {
|
|
620
|
-
delete state.assigned_[prop];
|
|
621
|
-
}
|
|
622
|
-
if (state.copy_) {
|
|
623
|
-
delete state.copy_[prop];
|
|
624
|
-
}
|
|
625
|
-
return true;
|
|
626
|
-
},
|
|
627
|
-
// Note: We never coerce `desc.value` into an Immer draft, because we can't make
|
|
628
|
-
// the same guarantee in ES5 mode.
|
|
629
|
-
getOwnPropertyDescriptor(state, prop) {
|
|
630
|
-
const owner = latest(state);
|
|
631
|
-
const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
|
|
632
|
-
if (!desc)
|
|
633
|
-
return desc;
|
|
634
|
-
return {
|
|
635
|
-
writable: true,
|
|
636
|
-
configurable: state.type_ !== 1 || prop !== "length",
|
|
637
|
-
enumerable: desc.enumerable,
|
|
638
|
-
value: owner[prop]
|
|
639
|
-
};
|
|
640
|
-
},
|
|
641
|
-
defineProperty() {
|
|
642
|
-
die(11);
|
|
643
|
-
},
|
|
644
|
-
getPrototypeOf(state) {
|
|
645
|
-
return getPrototypeOf(state.base_);
|
|
646
|
-
},
|
|
647
|
-
setPrototypeOf() {
|
|
648
|
-
die(12);
|
|
649
|
-
}
|
|
650
|
-
};
|
|
651
|
-
var arrayTraps = {};
|
|
652
|
-
each(objectTraps, (key, fn) => {
|
|
653
|
-
arrayTraps[key] = function() {
|
|
654
|
-
arguments[0] = arguments[0][0];
|
|
655
|
-
return fn.apply(this, arguments);
|
|
656
|
-
};
|
|
657
|
-
});
|
|
658
|
-
arrayTraps.deleteProperty = function(state, prop) {
|
|
659
|
-
if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
|
|
660
|
-
die(13);
|
|
661
|
-
return arrayTraps.set.call(this, state, prop, void 0);
|
|
662
|
-
};
|
|
663
|
-
arrayTraps.set = function(state, prop, value) {
|
|
664
|
-
if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
|
|
665
|
-
die(14);
|
|
666
|
-
return objectTraps.set.call(this, state[0], prop, value, state[0]);
|
|
667
|
-
};
|
|
668
|
-
function peek(draft, prop) {
|
|
669
|
-
const state = draft[DRAFT_STATE];
|
|
670
|
-
const source = state ? latest(state) : draft;
|
|
671
|
-
return source[prop];
|
|
672
|
-
}
|
|
673
|
-
function readPropFromProto(state, source, prop) {
|
|
674
|
-
const desc = getDescriptorFromProto(source, prop);
|
|
675
|
-
return desc ? `value` in desc ? desc.value : (
|
|
676
|
-
// This is a very special case, if the prop is a getter defined by the
|
|
677
|
-
// prototype, we should invoke it with the draft as context!
|
|
678
|
-
desc.get?.call(state.draft_)
|
|
679
|
-
) : void 0;
|
|
680
|
-
}
|
|
681
|
-
function getDescriptorFromProto(source, prop) {
|
|
682
|
-
if (!(prop in source))
|
|
683
|
-
return void 0;
|
|
684
|
-
let proto = getPrototypeOf(source);
|
|
685
|
-
while (proto) {
|
|
686
|
-
const desc = Object.getOwnPropertyDescriptor(proto, prop);
|
|
687
|
-
if (desc)
|
|
688
|
-
return desc;
|
|
689
|
-
proto = getPrototypeOf(proto);
|
|
690
|
-
}
|
|
691
|
-
return void 0;
|
|
692
|
-
}
|
|
693
|
-
function markChanged(state) {
|
|
694
|
-
if (!state.modified_) {
|
|
695
|
-
state.modified_ = true;
|
|
696
|
-
if (state.parent_) {
|
|
697
|
-
markChanged(state.parent_);
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
function prepareCopy(state) {
|
|
702
|
-
if (!state.copy_) {
|
|
703
|
-
state.copy_ = shallowCopy(
|
|
704
|
-
state.base_,
|
|
705
|
-
state.scope_.immer_.useStrictShallowCopy_
|
|
706
|
-
);
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
var Immer2 = class {
|
|
710
|
-
constructor(config) {
|
|
711
|
-
this.autoFreeze_ = true;
|
|
712
|
-
this.useStrictShallowCopy_ = false;
|
|
713
|
-
this.produce = (base, recipe, patchListener) => {
|
|
714
|
-
if (typeof base === "function" && typeof recipe !== "function") {
|
|
715
|
-
const defaultBase = recipe;
|
|
716
|
-
recipe = base;
|
|
717
|
-
const self = this;
|
|
718
|
-
return function curriedProduce(base2 = defaultBase, ...args) {
|
|
719
|
-
return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
if (typeof recipe !== "function")
|
|
723
|
-
die(6);
|
|
724
|
-
if (patchListener !== void 0 && typeof patchListener !== "function")
|
|
725
|
-
die(7);
|
|
726
|
-
let result;
|
|
727
|
-
if (isDraftable(base)) {
|
|
728
|
-
const scope = enterScope(this);
|
|
729
|
-
const proxy = createProxy(base, void 0);
|
|
730
|
-
let hasError = true;
|
|
731
|
-
try {
|
|
732
|
-
result = recipe(proxy);
|
|
733
|
-
hasError = false;
|
|
734
|
-
} finally {
|
|
735
|
-
if (hasError)
|
|
736
|
-
revokeScope(scope);
|
|
737
|
-
else
|
|
738
|
-
leaveScope(scope);
|
|
739
|
-
}
|
|
740
|
-
usePatchesInScope(scope, patchListener);
|
|
741
|
-
return processResult(result, scope);
|
|
742
|
-
} else if (!base || typeof base !== "object") {
|
|
743
|
-
result = recipe(base);
|
|
744
|
-
if (result === void 0)
|
|
745
|
-
result = base;
|
|
746
|
-
if (result === NOTHING)
|
|
747
|
-
result = void 0;
|
|
748
|
-
if (this.autoFreeze_)
|
|
749
|
-
freeze(result, true);
|
|
750
|
-
if (patchListener) {
|
|
751
|
-
const p = [];
|
|
752
|
-
const ip = [];
|
|
753
|
-
getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
|
|
754
|
-
patchListener(p, ip);
|
|
755
|
-
}
|
|
756
|
-
return result;
|
|
757
|
-
} else
|
|
758
|
-
die(1, base);
|
|
759
|
-
};
|
|
760
|
-
this.produceWithPatches = (base, recipe) => {
|
|
761
|
-
if (typeof base === "function") {
|
|
762
|
-
return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
|
|
763
|
-
}
|
|
764
|
-
let patches, inversePatches;
|
|
765
|
-
const result = this.produce(base, recipe, (p, ip) => {
|
|
766
|
-
patches = p;
|
|
767
|
-
inversePatches = ip;
|
|
768
|
-
});
|
|
769
|
-
return [result, patches, inversePatches];
|
|
770
|
-
};
|
|
771
|
-
if (typeof config?.autoFreeze === "boolean")
|
|
772
|
-
this.setAutoFreeze(config.autoFreeze);
|
|
773
|
-
if (typeof config?.useStrictShallowCopy === "boolean")
|
|
774
|
-
this.setUseStrictShallowCopy(config.useStrictShallowCopy);
|
|
775
|
-
}
|
|
776
|
-
createDraft(base) {
|
|
777
|
-
if (!isDraftable(base))
|
|
778
|
-
die(8);
|
|
779
|
-
if (isDraft(base))
|
|
780
|
-
base = current(base);
|
|
781
|
-
const scope = enterScope(this);
|
|
782
|
-
const proxy = createProxy(base, void 0);
|
|
783
|
-
proxy[DRAFT_STATE].isManual_ = true;
|
|
784
|
-
leaveScope(scope);
|
|
785
|
-
return proxy;
|
|
786
|
-
}
|
|
787
|
-
finishDraft(draft, patchListener) {
|
|
788
|
-
const state = draft && draft[DRAFT_STATE];
|
|
789
|
-
if (!state || !state.isManual_)
|
|
790
|
-
die(9);
|
|
791
|
-
const { scope_: scope } = state;
|
|
792
|
-
usePatchesInScope(scope, patchListener);
|
|
793
|
-
return processResult(void 0, scope);
|
|
794
|
-
}
|
|
795
|
-
/**
|
|
796
|
-
* Pass true to automatically freeze all copies created by Immer.
|
|
797
|
-
*
|
|
798
|
-
* By default, auto-freezing is enabled.
|
|
799
|
-
*/
|
|
800
|
-
setAutoFreeze(value) {
|
|
801
|
-
this.autoFreeze_ = value;
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
* Pass true to enable strict shallow copy.
|
|
805
|
-
*
|
|
806
|
-
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
|
|
807
|
-
*/
|
|
808
|
-
setUseStrictShallowCopy(value) {
|
|
809
|
-
this.useStrictShallowCopy_ = value;
|
|
810
|
-
}
|
|
811
|
-
applyPatches(base, patches) {
|
|
812
|
-
let i;
|
|
813
|
-
for (i = patches.length - 1; i >= 0; i--) {
|
|
814
|
-
const patch = patches[i];
|
|
815
|
-
if (patch.path.length === 0 && patch.op === "replace") {
|
|
816
|
-
base = patch.value;
|
|
817
|
-
break;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
if (i > -1) {
|
|
821
|
-
patches = patches.slice(i + 1);
|
|
822
|
-
}
|
|
823
|
-
const applyPatchesImpl = getPlugin("Patches").applyPatches_;
|
|
824
|
-
if (isDraft(base)) {
|
|
825
|
-
return applyPatchesImpl(base, patches);
|
|
826
|
-
}
|
|
827
|
-
return this.produce(
|
|
828
|
-
base,
|
|
829
|
-
(draft) => applyPatchesImpl(draft, patches)
|
|
830
|
-
);
|
|
831
|
-
}
|
|
832
|
-
};
|
|
833
|
-
function createProxy(value, parent) {
|
|
834
|
-
const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
|
|
835
|
-
const scope = parent ? parent.scope_ : getCurrentScope();
|
|
836
|
-
scope.drafts_.push(draft);
|
|
837
|
-
return draft;
|
|
838
|
-
}
|
|
839
|
-
function current(value) {
|
|
840
|
-
if (!isDraft(value))
|
|
841
|
-
die(10, value);
|
|
842
|
-
return currentImpl(value);
|
|
843
|
-
}
|
|
844
|
-
function currentImpl(value) {
|
|
845
|
-
if (!isDraftable(value) || isFrozen(value))
|
|
846
|
-
return value;
|
|
847
|
-
const state = value[DRAFT_STATE];
|
|
848
|
-
let copy;
|
|
849
|
-
if (state) {
|
|
850
|
-
if (!state.modified_)
|
|
851
|
-
return state.base_;
|
|
852
|
-
state.finalized_ = true;
|
|
853
|
-
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
|
|
854
|
-
} else {
|
|
855
|
-
copy = shallowCopy(value, true);
|
|
856
|
-
}
|
|
857
|
-
each(copy, (key, childValue) => {
|
|
858
|
-
set(copy, key, currentImpl(childValue));
|
|
859
|
-
});
|
|
860
|
-
if (state) {
|
|
861
|
-
state.finalized_ = false;
|
|
862
|
-
}
|
|
863
|
-
return copy;
|
|
864
|
-
}
|
|
865
|
-
var immer = new Immer2();
|
|
866
|
-
var produce = immer.produce;
|
|
867
|
-
var produceWithPatches = immer.produceWithPatches.bind(
|
|
868
|
-
immer
|
|
869
|
-
);
|
|
870
|
-
var setAutoFreeze = immer.setAutoFreeze.bind(immer);
|
|
871
|
-
var setUseStrictShallowCopy = immer.setUseStrictShallowCopy.bind(immer);
|
|
872
|
-
var applyPatches = immer.applyPatches.bind(immer);
|
|
873
|
-
var createDraft = immer.createDraft.bind(immer);
|
|
874
|
-
var finishDraft = immer.finishDraft.bind(immer);
|
|
875
|
-
|
|
876
|
-
// ../../node_modules/slate/dist/index.es.js
|
|
877
|
-
var Path = {
|
|
878
|
-
ancestors(path) {
|
|
879
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
880
|
-
var {
|
|
881
|
-
reverse = false
|
|
882
|
-
} = options;
|
|
883
|
-
var paths = Path.levels(path, options);
|
|
884
|
-
if (reverse) {
|
|
885
|
-
paths = paths.slice(1);
|
|
886
|
-
} else {
|
|
887
|
-
paths = paths.slice(0, -1);
|
|
888
|
-
}
|
|
889
|
-
return paths;
|
|
890
|
-
},
|
|
891
|
-
common(path, another) {
|
|
892
|
-
var common = [];
|
|
893
|
-
for (var i = 0; i < path.length && i < another.length; i++) {
|
|
894
|
-
var av = path[i];
|
|
895
|
-
var bv = another[i];
|
|
896
|
-
if (av !== bv) {
|
|
897
|
-
break;
|
|
898
|
-
}
|
|
899
|
-
common.push(av);
|
|
900
|
-
}
|
|
901
|
-
return common;
|
|
902
|
-
},
|
|
903
|
-
compare(path, another) {
|
|
904
|
-
var min = Math.min(path.length, another.length);
|
|
905
|
-
for (var i = 0; i < min; i++) {
|
|
906
|
-
if (path[i] < another[i]) return -1;
|
|
907
|
-
if (path[i] > another[i]) return 1;
|
|
908
|
-
}
|
|
909
|
-
return 0;
|
|
910
|
-
},
|
|
911
|
-
endsAfter(path, another) {
|
|
912
|
-
var i = path.length - 1;
|
|
913
|
-
var as = path.slice(0, i);
|
|
914
|
-
var bs = another.slice(0, i);
|
|
915
|
-
var av = path[i];
|
|
916
|
-
var bv = another[i];
|
|
917
|
-
return Path.equals(as, bs) && av > bv;
|
|
918
|
-
},
|
|
919
|
-
endsAt(path, another) {
|
|
920
|
-
var i = path.length;
|
|
921
|
-
var as = path.slice(0, i);
|
|
922
|
-
var bs = another.slice(0, i);
|
|
923
|
-
return Path.equals(as, bs);
|
|
924
|
-
},
|
|
925
|
-
endsBefore(path, another) {
|
|
926
|
-
var i = path.length - 1;
|
|
927
|
-
var as = path.slice(0, i);
|
|
928
|
-
var bs = another.slice(0, i);
|
|
929
|
-
var av = path[i];
|
|
930
|
-
var bv = another[i];
|
|
931
|
-
return Path.equals(as, bs) && av < bv;
|
|
932
|
-
},
|
|
933
|
-
equals(path, another) {
|
|
934
|
-
return path.length === another.length && path.every((n, i) => n === another[i]);
|
|
935
|
-
},
|
|
936
|
-
hasPrevious(path) {
|
|
937
|
-
return path[path.length - 1] > 0;
|
|
938
|
-
},
|
|
939
|
-
isAfter(path, another) {
|
|
940
|
-
return Path.compare(path, another) === 1;
|
|
941
|
-
},
|
|
942
|
-
isAncestor(path, another) {
|
|
943
|
-
return path.length < another.length && Path.compare(path, another) === 0;
|
|
944
|
-
},
|
|
945
|
-
isBefore(path, another) {
|
|
946
|
-
return Path.compare(path, another) === -1;
|
|
947
|
-
},
|
|
948
|
-
isChild(path, another) {
|
|
949
|
-
return path.length === another.length + 1 && Path.compare(path, another) === 0;
|
|
950
|
-
},
|
|
951
|
-
isCommon(path, another) {
|
|
952
|
-
return path.length <= another.length && Path.compare(path, another) === 0;
|
|
953
|
-
},
|
|
954
|
-
isDescendant(path, another) {
|
|
955
|
-
return path.length > another.length && Path.compare(path, another) === 0;
|
|
956
|
-
},
|
|
957
|
-
isParent(path, another) {
|
|
958
|
-
return path.length + 1 === another.length && Path.compare(path, another) === 0;
|
|
959
|
-
},
|
|
960
|
-
isPath(value) {
|
|
961
|
-
return Array.isArray(value) && (value.length === 0 || typeof value[0] === "number");
|
|
962
|
-
},
|
|
963
|
-
isSibling(path, another) {
|
|
964
|
-
if (path.length !== another.length) {
|
|
965
|
-
return false;
|
|
966
|
-
}
|
|
967
|
-
var as = path.slice(0, -1);
|
|
968
|
-
var bs = another.slice(0, -1);
|
|
969
|
-
var al = path[path.length - 1];
|
|
970
|
-
var bl = another[another.length - 1];
|
|
971
|
-
return al !== bl && Path.equals(as, bs);
|
|
972
|
-
},
|
|
973
|
-
levels(path) {
|
|
974
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
975
|
-
var {
|
|
976
|
-
reverse = false
|
|
977
|
-
} = options;
|
|
978
|
-
var list = [];
|
|
979
|
-
for (var i = 0; i <= path.length; i++) {
|
|
980
|
-
list.push(path.slice(0, i));
|
|
981
|
-
}
|
|
982
|
-
if (reverse) {
|
|
983
|
-
list.reverse();
|
|
984
|
-
}
|
|
985
|
-
return list;
|
|
986
|
-
},
|
|
987
|
-
next(path) {
|
|
988
|
-
if (path.length === 0) {
|
|
989
|
-
throw new Error("Cannot get the next path of a root path [".concat(path, "], because it has no next index."));
|
|
990
|
-
}
|
|
991
|
-
var last = path[path.length - 1];
|
|
992
|
-
return path.slice(0, -1).concat(last + 1);
|
|
993
|
-
},
|
|
994
|
-
operationCanTransformPath(operation) {
|
|
995
|
-
switch (operation.type) {
|
|
996
|
-
case "insert_node":
|
|
997
|
-
case "remove_node":
|
|
998
|
-
case "merge_node":
|
|
999
|
-
case "split_node":
|
|
1000
|
-
case "move_node":
|
|
1001
|
-
return true;
|
|
1002
|
-
default:
|
|
1003
|
-
return false;
|
|
1004
|
-
}
|
|
1005
|
-
},
|
|
1006
|
-
parent(path) {
|
|
1007
|
-
if (path.length === 0) {
|
|
1008
|
-
throw new Error("Cannot get the parent path of the root path [".concat(path, "]."));
|
|
1009
|
-
}
|
|
1010
|
-
return path.slice(0, -1);
|
|
1011
|
-
},
|
|
1012
|
-
previous(path) {
|
|
1013
|
-
if (path.length === 0) {
|
|
1014
|
-
throw new Error("Cannot get the previous path of a root path [".concat(path, "], because it has no previous index."));
|
|
1015
|
-
}
|
|
1016
|
-
var last = path[path.length - 1];
|
|
1017
|
-
if (last <= 0) {
|
|
1018
|
-
throw new Error("Cannot get the previous path of a first child path [".concat(path, "] because it would result in a negative index."));
|
|
1019
|
-
}
|
|
1020
|
-
return path.slice(0, -1).concat(last - 1);
|
|
1021
|
-
},
|
|
1022
|
-
relative(path, ancestor) {
|
|
1023
|
-
if (!Path.isAncestor(ancestor, path) && !Path.equals(path, ancestor)) {
|
|
1024
|
-
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."));
|
|
1025
|
-
}
|
|
1026
|
-
return path.slice(ancestor.length);
|
|
1027
|
-
},
|
|
1028
|
-
transform(path, operation) {
|
|
1029
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1030
|
-
if (!path) return null;
|
|
1031
|
-
var p = [...path];
|
|
1032
|
-
var {
|
|
1033
|
-
affinity = "forward"
|
|
1034
|
-
} = options;
|
|
1035
|
-
if (path.length === 0) {
|
|
1036
|
-
return p;
|
|
1037
|
-
}
|
|
1038
|
-
switch (operation.type) {
|
|
1039
|
-
case "insert_node": {
|
|
1040
|
-
var {
|
|
1041
|
-
path: op
|
|
1042
|
-
} = operation;
|
|
1043
|
-
if (Path.equals(op, p) || Path.endsBefore(op, p) || Path.isAncestor(op, p)) {
|
|
1044
|
-
p[op.length - 1] += 1;
|
|
1045
|
-
}
|
|
1046
|
-
break;
|
|
1047
|
-
}
|
|
1048
|
-
case "remove_node": {
|
|
1049
|
-
var {
|
|
1050
|
-
path: _op
|
|
1051
|
-
} = operation;
|
|
1052
|
-
if (Path.equals(_op, p) || Path.isAncestor(_op, p)) {
|
|
1053
|
-
return null;
|
|
1054
|
-
} else if (Path.endsBefore(_op, p)) {
|
|
1055
|
-
p[_op.length - 1] -= 1;
|
|
1056
|
-
}
|
|
1057
|
-
break;
|
|
1058
|
-
}
|
|
1059
|
-
case "merge_node": {
|
|
1060
|
-
var {
|
|
1061
|
-
path: _op2,
|
|
1062
|
-
position
|
|
1063
|
-
} = operation;
|
|
1064
|
-
if (Path.equals(_op2, p) || Path.endsBefore(_op2, p)) {
|
|
1065
|
-
p[_op2.length - 1] -= 1;
|
|
1066
|
-
} else if (Path.isAncestor(_op2, p)) {
|
|
1067
|
-
p[_op2.length - 1] -= 1;
|
|
1068
|
-
p[_op2.length] += position;
|
|
1069
|
-
}
|
|
1070
|
-
break;
|
|
1071
|
-
}
|
|
1072
|
-
case "split_node": {
|
|
1073
|
-
var {
|
|
1074
|
-
path: _op3,
|
|
1075
|
-
position: _position
|
|
1076
|
-
} = operation;
|
|
1077
|
-
if (Path.equals(_op3, p)) {
|
|
1078
|
-
if (affinity === "forward") {
|
|
1079
|
-
p[p.length - 1] += 1;
|
|
1080
|
-
} else if (affinity === "backward") ;
|
|
1081
|
-
else {
|
|
1082
|
-
return null;
|
|
1083
|
-
}
|
|
1084
|
-
} else if (Path.endsBefore(_op3, p)) {
|
|
1085
|
-
p[_op3.length - 1] += 1;
|
|
1086
|
-
} else if (Path.isAncestor(_op3, p) && path[_op3.length] >= _position) {
|
|
1087
|
-
p[_op3.length - 1] += 1;
|
|
1088
|
-
p[_op3.length] -= _position;
|
|
1089
|
-
}
|
|
1090
|
-
break;
|
|
1091
|
-
}
|
|
1092
|
-
case "move_node": {
|
|
1093
|
-
var {
|
|
1094
|
-
path: _op4,
|
|
1095
|
-
newPath: onp
|
|
1096
|
-
} = operation;
|
|
1097
|
-
if (Path.equals(_op4, onp)) {
|
|
1098
|
-
return p;
|
|
1099
|
-
}
|
|
1100
|
-
if (Path.isAncestor(_op4, p) || Path.equals(_op4, p)) {
|
|
1101
|
-
var copy = onp.slice();
|
|
1102
|
-
if (Path.endsBefore(_op4, onp) && _op4.length < onp.length) {
|
|
1103
|
-
copy[_op4.length - 1] -= 1;
|
|
1104
|
-
}
|
|
1105
|
-
return copy.concat(p.slice(_op4.length));
|
|
1106
|
-
} else if (Path.isSibling(_op4, onp) && (Path.isAncestor(onp, p) || Path.equals(onp, p))) {
|
|
1107
|
-
if (Path.endsBefore(_op4, p)) {
|
|
1108
|
-
p[_op4.length - 1] -= 1;
|
|
1109
|
-
} else {
|
|
1110
|
-
p[_op4.length - 1] += 1;
|
|
1111
|
-
}
|
|
1112
|
-
} else if (Path.endsBefore(onp, p) || Path.equals(onp, p) || Path.isAncestor(onp, p)) {
|
|
1113
|
-
if (Path.endsBefore(_op4, p)) {
|
|
1114
|
-
p[_op4.length - 1] -= 1;
|
|
1115
|
-
}
|
|
1116
|
-
p[onp.length - 1] += 1;
|
|
1117
|
-
} else if (Path.endsBefore(_op4, p)) {
|
|
1118
|
-
if (Path.equals(onp, p)) {
|
|
1119
|
-
p[onp.length - 1] += 1;
|
|
1120
|
-
}
|
|
1121
|
-
p[_op4.length - 1] -= 1;
|
|
1122
|
-
}
|
|
1123
|
-
break;
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
return p;
|
|
1127
|
-
}
|
|
1128
|
-
};
|
|
1129
|
-
function _typeof(o) {
|
|
1130
|
-
"@babel/helpers - typeof";
|
|
1131
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
|
|
1132
|
-
return typeof o2;
|
|
1133
|
-
} : function(o2) {
|
|
1134
|
-
return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
|
|
1135
|
-
}, _typeof(o);
|
|
1136
|
-
}
|
|
1137
|
-
function _toPrimitive(input, hint) {
|
|
1138
|
-
if (_typeof(input) !== "object" || input === null) return input;
|
|
1139
|
-
var prim = input[Symbol.toPrimitive];
|
|
1140
|
-
if (prim !== void 0) {
|
|
1141
|
-
var res = prim.call(input, hint || "default");
|
|
1142
|
-
if (_typeof(res) !== "object") return res;
|
|
1143
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1144
|
-
}
|
|
1145
|
-
return (hint === "string" ? String : Number)(input);
|
|
1146
|
-
}
|
|
1147
|
-
function _toPropertyKey(arg) {
|
|
1148
|
-
var key = _toPrimitive(arg, "string");
|
|
1149
|
-
return _typeof(key) === "symbol" ? key : String(key);
|
|
1150
|
-
}
|
|
1151
|
-
function _defineProperty(obj, key, value) {
|
|
1152
|
-
key = _toPropertyKey(key);
|
|
1153
|
-
if (key in obj) {
|
|
1154
|
-
Object.defineProperty(obj, key, {
|
|
1155
|
-
value,
|
|
1156
|
-
enumerable: true,
|
|
1157
|
-
configurable: true,
|
|
1158
|
-
writable: true
|
|
1159
|
-
});
|
|
1160
|
-
} else {
|
|
1161
|
-
obj[key] = value;
|
|
1162
|
-
}
|
|
1163
|
-
return obj;
|
|
1164
|
-
}
|
|
1165
|
-
function ownKeys$e(e, r) {
|
|
1166
|
-
var t = Object.keys(e);
|
|
1167
|
-
if (Object.getOwnPropertySymbols) {
|
|
1168
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
1169
|
-
r && (o = o.filter(function(r2) {
|
|
1170
|
-
return Object.getOwnPropertyDescriptor(e, r2).enumerable;
|
|
1171
|
-
})), t.push.apply(t, o);
|
|
1172
|
-
}
|
|
1173
|
-
return t;
|
|
1174
|
-
}
|
|
1175
|
-
function _objectSpread$e(e) {
|
|
1176
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
1177
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
1178
|
-
r % 2 ? ownKeys$e(Object(t), true).forEach(function(r2) {
|
|
1179
|
-
_defineProperty(e, r2, t[r2]);
|
|
1180
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$e(Object(t)).forEach(function(r2) {
|
|
1181
|
-
Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
|
|
1182
|
-
});
|
|
1183
|
-
}
|
|
1184
|
-
return e;
|
|
1185
|
-
}
|
|
1186
|
-
var insertChildren = function insertChildren2(xs, index) {
|
|
1187
|
-
for (var _len = arguments.length, newValues = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
1188
|
-
newValues[_key - 2] = arguments[_key];
|
|
1189
|
-
}
|
|
1190
|
-
return [...xs.slice(0, index), ...newValues, ...xs.slice(index)];
|
|
1191
|
-
};
|
|
1192
|
-
var replaceChildren = function replaceChildren2(xs, index, removeCount) {
|
|
1193
|
-
for (var _len2 = arguments.length, newValues = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
|
1194
|
-
newValues[_key2 - 3] = arguments[_key2];
|
|
1195
|
-
}
|
|
1196
|
-
return [...xs.slice(0, index), ...newValues, ...xs.slice(index + removeCount)];
|
|
1197
|
-
};
|
|
1198
|
-
var removeChildren = replaceChildren;
|
|
1199
|
-
var modifyDescendant = (editor, path, f) => {
|
|
1200
|
-
if (path.length === 0) {
|
|
1201
|
-
throw new Error("Cannot modify the editor");
|
|
1202
|
-
}
|
|
1203
|
-
var node = Node.get(editor, path);
|
|
1204
|
-
var slicedPath = path.slice();
|
|
1205
|
-
var modifiedNode = f(node);
|
|
1206
|
-
while (slicedPath.length > 1) {
|
|
1207
|
-
var _index = slicedPath.pop();
|
|
1208
|
-
var ancestorNode = Node.get(editor, slicedPath);
|
|
1209
|
-
modifiedNode = _objectSpread$e(_objectSpread$e({}, ancestorNode), {}, {
|
|
1210
|
-
children: replaceChildren(ancestorNode.children, _index, 1, modifiedNode)
|
|
1211
|
-
});
|
|
1212
|
-
}
|
|
1213
|
-
var index = slicedPath.pop();
|
|
1214
|
-
editor.children = replaceChildren(editor.children, index, 1, modifiedNode);
|
|
1215
|
-
};
|
|
1216
|
-
var modifyChildren = (editor, path, f) => {
|
|
1217
|
-
if (path.length === 0) {
|
|
1218
|
-
editor.children = f(editor.children);
|
|
1219
|
-
} else {
|
|
1220
|
-
modifyDescendant(editor, path, (node) => {
|
|
1221
|
-
if (Text.isText(node)) {
|
|
1222
|
-
throw new Error("Cannot get the element at path [".concat(path, "] because it refers to a leaf node: ").concat(Scrubber.stringify(node)));
|
|
1223
|
-
}
|
|
1224
|
-
return _objectSpread$e(_objectSpread$e({}, node), {}, {
|
|
1225
|
-
children: f(node.children)
|
|
1226
|
-
});
|
|
1227
|
-
});
|
|
1228
|
-
}
|
|
1229
|
-
};
|
|
1230
|
-
var modifyLeaf = (editor, path, f) => modifyDescendant(editor, path, (node) => {
|
|
1231
|
-
if (!Text.isText(node)) {
|
|
1232
|
-
throw new Error("Cannot get the leaf node at path [".concat(path, "] because it refers to a non-leaf node: ").concat(Scrubber.stringify(node)));
|
|
1233
|
-
}
|
|
1234
|
-
return f(node);
|
|
1235
|
-
});
|
|
1236
|
-
var GeneralTransforms = {
|
|
1237
|
-
transform(editor, op) {
|
|
1238
|
-
var transformSelection = false;
|
|
1239
|
-
switch (op.type) {
|
|
1240
|
-
case "insert_node": {
|
|
1241
|
-
var {
|
|
1242
|
-
path,
|
|
1243
|
-
node
|
|
1244
|
-
} = op;
|
|
1245
|
-
modifyChildren(editor, Path.parent(path), (children) => {
|
|
1246
|
-
var index2 = path[path.length - 1];
|
|
1247
|
-
if (index2 > children.length) {
|
|
1248
|
-
throw new Error('Cannot apply an "insert_node" operation at path ['.concat(path, "] because the destination is past the end of the node."));
|
|
1249
|
-
}
|
|
1250
|
-
return insertChildren(children, index2, node);
|
|
1251
|
-
});
|
|
1252
|
-
transformSelection = true;
|
|
1253
|
-
break;
|
|
1254
|
-
}
|
|
1255
|
-
case "insert_text": {
|
|
1256
|
-
var {
|
|
1257
|
-
path: _path,
|
|
1258
|
-
offset,
|
|
1259
|
-
text
|
|
1260
|
-
} = op;
|
|
1261
|
-
if (text.length === 0) break;
|
|
1262
|
-
modifyLeaf(editor, _path, (node2) => {
|
|
1263
|
-
var before = node2.text.slice(0, offset);
|
|
1264
|
-
var after = node2.text.slice(offset);
|
|
1265
|
-
return _objectSpread$e(_objectSpread$e({}, node2), {}, {
|
|
1266
|
-
text: before + text + after
|
|
1267
|
-
});
|
|
1268
|
-
});
|
|
1269
|
-
transformSelection = true;
|
|
1270
|
-
break;
|
|
1271
|
-
}
|
|
1272
|
-
case "merge_node": {
|
|
1273
|
-
var {
|
|
1274
|
-
path: _path2
|
|
1275
|
-
} = op;
|
|
1276
|
-
var index = _path2[_path2.length - 1];
|
|
1277
|
-
var prevPath = Path.previous(_path2);
|
|
1278
|
-
var prevIndex = prevPath[prevPath.length - 1];
|
|
1279
|
-
modifyChildren(editor, Path.parent(_path2), (children) => {
|
|
1280
|
-
var node2 = children[index];
|
|
1281
|
-
var prev2 = children[prevIndex];
|
|
1282
|
-
var newNode;
|
|
1283
|
-
if (Text.isText(node2) && Text.isText(prev2)) {
|
|
1284
|
-
newNode = _objectSpread$e(_objectSpread$e({}, prev2), {}, {
|
|
1285
|
-
text: prev2.text + node2.text
|
|
1286
|
-
});
|
|
1287
|
-
} else if (!Text.isText(node2) && !Text.isText(prev2)) {
|
|
1288
|
-
newNode = _objectSpread$e(_objectSpread$e({}, prev2), {}, {
|
|
1289
|
-
children: prev2.children.concat(node2.children)
|
|
1290
|
-
});
|
|
1291
|
-
} else {
|
|
1292
|
-
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)));
|
|
1293
|
-
}
|
|
1294
|
-
return replaceChildren(children, prevIndex, 2, newNode);
|
|
1295
|
-
});
|
|
1296
|
-
transformSelection = true;
|
|
1297
|
-
break;
|
|
1298
|
-
}
|
|
1299
|
-
case "move_node": {
|
|
1300
|
-
var {
|
|
1301
|
-
path: _path3,
|
|
1302
|
-
newPath
|
|
1303
|
-
} = op;
|
|
1304
|
-
var _index2 = _path3[_path3.length - 1];
|
|
1305
|
-
if (Path.isAncestor(_path3, newPath)) {
|
|
1306
|
-
throw new Error("Cannot move a path [".concat(_path3, "] to new path [").concat(newPath, "] because the destination is inside itself."));
|
|
1307
|
-
}
|
|
1308
|
-
var _node = Node.get(editor, _path3);
|
|
1309
|
-
modifyChildren(editor, Path.parent(_path3), (children) => removeChildren(children, _index2, 1));
|
|
1310
|
-
var truePath = Path.transform(_path3, op);
|
|
1311
|
-
var newIndex = truePath[truePath.length - 1];
|
|
1312
|
-
modifyChildren(editor, Path.parent(truePath), (children) => insertChildren(children, newIndex, _node));
|
|
1313
|
-
transformSelection = true;
|
|
1314
|
-
break;
|
|
1315
|
-
}
|
|
1316
|
-
case "remove_node": {
|
|
1317
|
-
var {
|
|
1318
|
-
path: _path4
|
|
1319
|
-
} = op;
|
|
1320
|
-
var _index3 = _path4[_path4.length - 1];
|
|
1321
|
-
modifyChildren(editor, Path.parent(_path4), (children) => removeChildren(children, _index3, 1));
|
|
1322
|
-
if (editor.selection) {
|
|
1323
|
-
var selection = _objectSpread$e({}, editor.selection);
|
|
1324
|
-
for (var [point, key] of Range.points(selection)) {
|
|
1325
|
-
var result = Point.transform(point, op);
|
|
1326
|
-
if (selection != null && result != null) {
|
|
1327
|
-
selection[key] = result;
|
|
1328
|
-
} else {
|
|
1329
|
-
var prev = void 0;
|
|
1330
|
-
var next = void 0;
|
|
1331
|
-
for (var [n, p] of Node.texts(editor)) {
|
|
1332
|
-
if (Path.compare(p, _path4) === -1) {
|
|
1333
|
-
prev = [n, p];
|
|
1334
|
-
} else {
|
|
1335
|
-
next = [n, p];
|
|
1336
|
-
break;
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
var preferNext = false;
|
|
1340
|
-
if (prev && next) {
|
|
1341
|
-
if (Path.isSibling(prev[1], _path4)) {
|
|
1342
|
-
preferNext = false;
|
|
1343
|
-
} else if (Path.equals(next[1], _path4)) {
|
|
1344
|
-
preferNext = true;
|
|
1345
|
-
} else {
|
|
1346
|
-
preferNext = Path.common(prev[1], _path4).length < Path.common(next[1], _path4).length;
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
if (prev && !preferNext) {
|
|
1350
|
-
selection[key] = {
|
|
1351
|
-
path: prev[1],
|
|
1352
|
-
offset: prev[0].text.length
|
|
1353
|
-
};
|
|
1354
|
-
} else if (next) {
|
|
1355
|
-
selection[key] = {
|
|
1356
|
-
path: next[1],
|
|
1357
|
-
offset: 0
|
|
1358
|
-
};
|
|
1359
|
-
} else {
|
|
1360
|
-
selection = null;
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
if (!selection || !Range.equals(selection, editor.selection)) {
|
|
1365
|
-
editor.selection = selection;
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
break;
|
|
1369
|
-
}
|
|
1370
|
-
case "remove_text": {
|
|
1371
|
-
var {
|
|
1372
|
-
path: _path5,
|
|
1373
|
-
offset: _offset,
|
|
1374
|
-
text: _text
|
|
1375
|
-
} = op;
|
|
1376
|
-
if (_text.length === 0) break;
|
|
1377
|
-
modifyLeaf(editor, _path5, (node2) => {
|
|
1378
|
-
var before = node2.text.slice(0, _offset);
|
|
1379
|
-
var after = node2.text.slice(_offset + _text.length);
|
|
1380
|
-
return _objectSpread$e(_objectSpread$e({}, node2), {}, {
|
|
1381
|
-
text: before + after
|
|
1382
|
-
});
|
|
1383
|
-
});
|
|
1384
|
-
transformSelection = true;
|
|
1385
|
-
break;
|
|
1386
|
-
}
|
|
1387
|
-
case "set_node": {
|
|
1388
|
-
var {
|
|
1389
|
-
path: _path6,
|
|
1390
|
-
properties,
|
|
1391
|
-
newProperties
|
|
1392
|
-
} = op;
|
|
1393
|
-
if (_path6.length === 0) {
|
|
1394
|
-
throw new Error("Cannot set properties on the root node!");
|
|
1395
|
-
}
|
|
1396
|
-
modifyDescendant(editor, _path6, (node2) => {
|
|
1397
|
-
var newNode = _objectSpread$e({}, node2);
|
|
1398
|
-
for (var _key3 in newProperties) {
|
|
1399
|
-
if (_key3 === "children" || _key3 === "text") {
|
|
1400
|
-
throw new Error('Cannot set the "'.concat(_key3, '" property of nodes!'));
|
|
1401
|
-
}
|
|
1402
|
-
var value2 = newProperties[_key3];
|
|
1403
|
-
if (value2 == null) {
|
|
1404
|
-
delete newNode[_key3];
|
|
1405
|
-
} else {
|
|
1406
|
-
newNode[_key3] = value2;
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
for (var _key4 in properties) {
|
|
1410
|
-
if (!newProperties.hasOwnProperty(_key4)) {
|
|
1411
|
-
delete newNode[_key4];
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
return newNode;
|
|
1415
|
-
});
|
|
1416
|
-
break;
|
|
1417
|
-
}
|
|
1418
|
-
case "set_selection": {
|
|
1419
|
-
var {
|
|
1420
|
-
newProperties: _newProperties
|
|
1421
|
-
} = op;
|
|
1422
|
-
if (_newProperties == null) {
|
|
1423
|
-
editor.selection = null;
|
|
1424
|
-
break;
|
|
1425
|
-
}
|
|
1426
|
-
if (editor.selection == null) {
|
|
1427
|
-
if (!Range.isRange(_newProperties)) {
|
|
1428
|
-
throw new Error('Cannot apply an incomplete "set_selection" operation properties '.concat(Scrubber.stringify(_newProperties), " when there is no current selection."));
|
|
1429
|
-
}
|
|
1430
|
-
editor.selection = _objectSpread$e({}, _newProperties);
|
|
1431
|
-
break;
|
|
1432
|
-
}
|
|
1433
|
-
var _selection = _objectSpread$e({}, editor.selection);
|
|
1434
|
-
for (var _key5 in _newProperties) {
|
|
1435
|
-
var value = _newProperties[_key5];
|
|
1436
|
-
if (value == null) {
|
|
1437
|
-
if (_key5 === "anchor" || _key5 === "focus") {
|
|
1438
|
-
throw new Error('Cannot remove the "'.concat(_key5, '" selection property'));
|
|
1439
|
-
}
|
|
1440
|
-
delete _selection[_key5];
|
|
1441
|
-
} else {
|
|
1442
|
-
_selection[_key5] = value;
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
editor.selection = _selection;
|
|
1446
|
-
break;
|
|
1447
|
-
}
|
|
1448
|
-
case "split_node": {
|
|
1449
|
-
var {
|
|
1450
|
-
path: _path7,
|
|
1451
|
-
position,
|
|
1452
|
-
properties: _properties
|
|
1453
|
-
} = op;
|
|
1454
|
-
var _index4 = _path7[_path7.length - 1];
|
|
1455
|
-
if (_path7.length === 0) {
|
|
1456
|
-
throw new Error('Cannot apply a "split_node" operation at path ['.concat(_path7, "] because the root node cannot be split."));
|
|
1457
|
-
}
|
|
1458
|
-
modifyChildren(editor, Path.parent(_path7), (children) => {
|
|
1459
|
-
var node2 = children[_index4];
|
|
1460
|
-
var newNode;
|
|
1461
|
-
var nextNode;
|
|
1462
|
-
if (Text.isText(node2)) {
|
|
1463
|
-
var before = node2.text.slice(0, position);
|
|
1464
|
-
var after = node2.text.slice(position);
|
|
1465
|
-
newNode = _objectSpread$e(_objectSpread$e({}, node2), {}, {
|
|
1466
|
-
text: before
|
|
1467
|
-
});
|
|
1468
|
-
nextNode = _objectSpread$e(_objectSpread$e({}, _properties), {}, {
|
|
1469
|
-
text: after
|
|
1470
|
-
});
|
|
1471
|
-
} else {
|
|
1472
|
-
var _before = node2.children.slice(0, position);
|
|
1473
|
-
var _after = node2.children.slice(position);
|
|
1474
|
-
newNode = _objectSpread$e(_objectSpread$e({}, node2), {}, {
|
|
1475
|
-
children: _before
|
|
1476
|
-
});
|
|
1477
|
-
nextNode = _objectSpread$e(_objectSpread$e({}, _properties), {}, {
|
|
1478
|
-
children: _after
|
|
1479
|
-
});
|
|
1480
|
-
}
|
|
1481
|
-
return replaceChildren(children, _index4, 1, newNode, nextNode);
|
|
1482
|
-
});
|
|
1483
|
-
transformSelection = true;
|
|
1484
|
-
break;
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
if (transformSelection && editor.selection) {
|
|
1488
|
-
var _selection2 = _objectSpread$e({}, editor.selection);
|
|
1489
|
-
for (var [_point, _key6] of Range.points(_selection2)) {
|
|
1490
|
-
_selection2[_key6] = Point.transform(_point, op);
|
|
1491
|
-
}
|
|
1492
|
-
if (!Range.equals(_selection2, editor.selection)) {
|
|
1493
|
-
editor.selection = _selection2;
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1497
|
-
};
|
|
1498
|
-
var NodeTransforms = {
|
|
1499
|
-
insertNodes(editor, nodes, options) {
|
|
1500
|
-
editor.insertNodes(nodes, options);
|
|
1501
|
-
},
|
|
1502
|
-
liftNodes(editor, options) {
|
|
1503
|
-
editor.liftNodes(options);
|
|
1504
|
-
},
|
|
1505
|
-
mergeNodes(editor, options) {
|
|
1506
|
-
editor.mergeNodes(options);
|
|
1507
|
-
},
|
|
1508
|
-
moveNodes(editor, options) {
|
|
1509
|
-
editor.moveNodes(options);
|
|
1510
|
-
},
|
|
1511
|
-
removeNodes(editor, options) {
|
|
1512
|
-
editor.removeNodes(options);
|
|
1513
|
-
},
|
|
1514
|
-
setNodes(editor, props, options) {
|
|
1515
|
-
editor.setNodes(props, options);
|
|
1516
|
-
},
|
|
1517
|
-
splitNodes(editor, options) {
|
|
1518
|
-
editor.splitNodes(options);
|
|
1519
|
-
},
|
|
1520
|
-
unsetNodes(editor, props, options) {
|
|
1521
|
-
editor.unsetNodes(props, options);
|
|
1522
|
-
},
|
|
1523
|
-
unwrapNodes(editor, options) {
|
|
1524
|
-
editor.unwrapNodes(options);
|
|
1525
|
-
},
|
|
1526
|
-
wrapNodes(editor, element, options) {
|
|
1527
|
-
editor.wrapNodes(element, options);
|
|
1528
|
-
}
|
|
1529
|
-
};
|
|
1530
|
-
var SelectionTransforms = {
|
|
1531
|
-
collapse(editor, options) {
|
|
1532
|
-
editor.collapse(options);
|
|
1533
|
-
},
|
|
1534
|
-
deselect(editor) {
|
|
1535
|
-
editor.deselect();
|
|
1536
|
-
},
|
|
1537
|
-
move(editor, options) {
|
|
1538
|
-
editor.move(options);
|
|
1539
|
-
},
|
|
1540
|
-
select(editor, target) {
|
|
1541
|
-
editor.select(target);
|
|
1542
|
-
},
|
|
1543
|
-
setPoint(editor, props, options) {
|
|
1544
|
-
editor.setPoint(props, options);
|
|
1545
|
-
},
|
|
1546
|
-
setSelection(editor, props) {
|
|
1547
|
-
editor.setSelection(props);
|
|
1548
|
-
}
|
|
1549
|
-
};
|
|
1550
|
-
var isObject = (value) => typeof value === "object" && value !== null;
|
|
1551
|
-
var isDeepEqual = (node, another) => {
|
|
1552
|
-
for (var key in node) {
|
|
1553
|
-
var a = node[key];
|
|
1554
|
-
var b = another[key];
|
|
1555
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
1556
|
-
if (a.length !== b.length) return false;
|
|
1557
|
-
for (var i = 0; i < a.length; i++) {
|
|
1558
|
-
if (a[i] !== b[i]) return false;
|
|
1559
|
-
}
|
|
1560
|
-
} else if (isObject(a) && isObject(b)) {
|
|
1561
|
-
if (!isDeepEqual(a, b)) return false;
|
|
1562
|
-
} else if (a !== b) {
|
|
1563
|
-
return false;
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
for (var _key in another) {
|
|
1567
|
-
if (node[_key] === void 0 && another[_key] !== void 0) {
|
|
1568
|
-
return false;
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
return true;
|
|
1572
|
-
};
|
|
1573
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
1574
|
-
if (source == null) return {};
|
|
1575
|
-
var target = {};
|
|
1576
|
-
var sourceKeys = Object.keys(source);
|
|
1577
|
-
var key, i;
|
|
1578
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
1579
|
-
key = sourceKeys[i];
|
|
1580
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
1581
|
-
target[key] = source[key];
|
|
1582
|
-
}
|
|
1583
|
-
return target;
|
|
1584
|
-
}
|
|
1585
|
-
function _objectWithoutProperties(source, excluded) {
|
|
1586
|
-
if (source == null) return {};
|
|
1587
|
-
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
1588
|
-
var key, i;
|
|
1589
|
-
if (Object.getOwnPropertySymbols) {
|
|
1590
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
1591
|
-
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
1592
|
-
key = sourceSymbolKeys[i];
|
|
1593
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
1594
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
1595
|
-
target[key] = source[key];
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
return target;
|
|
1599
|
-
}
|
|
1600
|
-
var _excluded$4 = ["anchor", "focus"];
|
|
1601
|
-
function ownKeys$d(e, r) {
|
|
1602
|
-
var t = Object.keys(e);
|
|
1603
|
-
if (Object.getOwnPropertySymbols) {
|
|
1604
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
1605
|
-
r && (o = o.filter(function(r2) {
|
|
1606
|
-
return Object.getOwnPropertyDescriptor(e, r2).enumerable;
|
|
1607
|
-
})), t.push.apply(t, o);
|
|
1608
|
-
}
|
|
1609
|
-
return t;
|
|
1610
|
-
}
|
|
1611
|
-
function _objectSpread$d(e) {
|
|
1612
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
1613
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
1614
|
-
r % 2 ? ownKeys$d(Object(t), true).forEach(function(r2) {
|
|
1615
|
-
_defineProperty(e, r2, t[r2]);
|
|
1616
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$d(Object(t)).forEach(function(r2) {
|
|
1617
|
-
Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
|
|
1618
|
-
});
|
|
1619
|
-
}
|
|
1620
|
-
return e;
|
|
1621
|
-
}
|
|
1622
|
-
var Range = {
|
|
1623
|
-
edges(range) {
|
|
1624
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1625
|
-
var {
|
|
1626
|
-
reverse = false
|
|
1627
|
-
} = options;
|
|
1628
|
-
var {
|
|
1629
|
-
anchor,
|
|
1630
|
-
focus
|
|
1631
|
-
} = range;
|
|
1632
|
-
return Range.isBackward(range) === reverse ? [anchor, focus] : [focus, anchor];
|
|
1633
|
-
},
|
|
1634
|
-
end(range) {
|
|
1635
|
-
var [, end] = Range.edges(range);
|
|
1636
|
-
return end;
|
|
1637
|
-
},
|
|
1638
|
-
equals(range, another) {
|
|
1639
|
-
return Point.equals(range.anchor, another.anchor) && Point.equals(range.focus, another.focus);
|
|
1640
|
-
},
|
|
1641
|
-
surrounds(range, target) {
|
|
1642
|
-
var intersectionRange = Range.intersection(range, target);
|
|
1643
|
-
if (!intersectionRange) {
|
|
1644
|
-
return false;
|
|
1645
|
-
}
|
|
1646
|
-
return Range.equals(intersectionRange, target);
|
|
1647
|
-
},
|
|
1648
|
-
includes(range, target) {
|
|
1649
|
-
if (Range.isRange(target)) {
|
|
1650
|
-
if (Range.includes(range, target.anchor) || Range.includes(range, target.focus)) {
|
|
1651
|
-
return true;
|
|
1652
|
-
}
|
|
1653
|
-
var [rs, re] = Range.edges(range);
|
|
1654
|
-
var [ts, te] = Range.edges(target);
|
|
1655
|
-
return Point.isBefore(rs, ts) && Point.isAfter(re, te);
|
|
1656
|
-
}
|
|
1657
|
-
var [start, end] = Range.edges(range);
|
|
1658
|
-
var isAfterStart = false;
|
|
1659
|
-
var isBeforeEnd = false;
|
|
1660
|
-
if (Point.isPoint(target)) {
|
|
1661
|
-
isAfterStart = Point.compare(target, start) >= 0;
|
|
1662
|
-
isBeforeEnd = Point.compare(target, end) <= 0;
|
|
1663
|
-
} else {
|
|
1664
|
-
isAfterStart = Path.compare(target, start.path) >= 0;
|
|
1665
|
-
isBeforeEnd = Path.compare(target, end.path) <= 0;
|
|
1666
|
-
}
|
|
1667
|
-
return isAfterStart && isBeforeEnd;
|
|
1668
|
-
},
|
|
1669
|
-
intersection(range, another) {
|
|
1670
|
-
var rest = _objectWithoutProperties(range, _excluded$4);
|
|
1671
|
-
var [s1, e1] = Range.edges(range);
|
|
1672
|
-
var [s2, e2] = Range.edges(another);
|
|
1673
|
-
var start = Point.isBefore(s1, s2) ? s2 : s1;
|
|
1674
|
-
var end = Point.isBefore(e1, e2) ? e1 : e2;
|
|
1675
|
-
if (Point.isBefore(end, start)) {
|
|
1676
|
-
return null;
|
|
1677
|
-
} else {
|
|
1678
|
-
return _objectSpread$d({
|
|
1679
|
-
anchor: start,
|
|
1680
|
-
focus: end
|
|
1681
|
-
}, rest);
|
|
1682
|
-
}
|
|
1683
|
-
},
|
|
1684
|
-
isBackward(range) {
|
|
1685
|
-
var {
|
|
1686
|
-
anchor,
|
|
1687
|
-
focus
|
|
1688
|
-
} = range;
|
|
1689
|
-
return Point.isAfter(anchor, focus);
|
|
1690
|
-
},
|
|
1691
|
-
isCollapsed(range) {
|
|
1692
|
-
var {
|
|
1693
|
-
anchor,
|
|
1694
|
-
focus
|
|
1695
|
-
} = range;
|
|
1696
|
-
return Point.equals(anchor, focus);
|
|
1697
|
-
},
|
|
1698
|
-
isExpanded(range) {
|
|
1699
|
-
return !Range.isCollapsed(range);
|
|
1700
|
-
},
|
|
1701
|
-
isForward(range) {
|
|
1702
|
-
return !Range.isBackward(range);
|
|
1703
|
-
},
|
|
1704
|
-
isRange(value) {
|
|
1705
|
-
return isObject(value) && Point.isPoint(value.anchor) && Point.isPoint(value.focus);
|
|
1706
|
-
},
|
|
1707
|
-
*points(range) {
|
|
1708
|
-
yield [range.anchor, "anchor"];
|
|
1709
|
-
yield [range.focus, "focus"];
|
|
1710
|
-
},
|
|
1711
|
-
start(range) {
|
|
1712
|
-
var [start] = Range.edges(range);
|
|
1713
|
-
return start;
|
|
1714
|
-
},
|
|
1715
|
-
transform(range, op) {
|
|
1716
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1717
|
-
if (range === null) {
|
|
1718
|
-
return null;
|
|
1719
|
-
}
|
|
1720
|
-
var {
|
|
1721
|
-
affinity = "inward"
|
|
1722
|
-
} = options;
|
|
1723
|
-
var affinityAnchor;
|
|
1724
|
-
var affinityFocus;
|
|
1725
|
-
if (affinity === "inward") {
|
|
1726
|
-
var isCollapsed = Range.isCollapsed(range);
|
|
1727
|
-
if (Range.isForward(range)) {
|
|
1728
|
-
affinityAnchor = "forward";
|
|
1729
|
-
affinityFocus = isCollapsed ? affinityAnchor : "backward";
|
|
1730
|
-
} else {
|
|
1731
|
-
affinityAnchor = "backward";
|
|
1732
|
-
affinityFocus = isCollapsed ? affinityAnchor : "forward";
|
|
1733
|
-
}
|
|
1734
|
-
} else if (affinity === "outward") {
|
|
1735
|
-
if (Range.isForward(range)) {
|
|
1736
|
-
affinityAnchor = "backward";
|
|
1737
|
-
affinityFocus = "forward";
|
|
1738
|
-
} else {
|
|
1739
|
-
affinityAnchor = "forward";
|
|
1740
|
-
affinityFocus = "backward";
|
|
1741
|
-
}
|
|
1742
|
-
} else {
|
|
1743
|
-
affinityAnchor = affinity;
|
|
1744
|
-
affinityFocus = affinity;
|
|
1745
|
-
}
|
|
1746
|
-
var anchor = Point.transform(range.anchor, op, {
|
|
1747
|
-
affinity: affinityAnchor
|
|
1748
|
-
});
|
|
1749
|
-
var focus = Point.transform(range.focus, op, {
|
|
1750
|
-
affinity: affinityFocus
|
|
1751
|
-
});
|
|
1752
|
-
if (!anchor || !focus) {
|
|
1753
|
-
return null;
|
|
1754
|
-
}
|
|
1755
|
-
return {
|
|
1756
|
-
anchor,
|
|
1757
|
-
focus
|
|
1758
|
-
};
|
|
1759
|
-
}
|
|
1760
|
-
};
|
|
1761
|
-
var isElement = function isElement2(value) {
|
|
1762
|
-
var {
|
|
1763
|
-
deep = false
|
|
1764
|
-
} = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1765
|
-
if (!isObject(value)) return false;
|
|
1766
|
-
var isEditor3 = typeof value.apply === "function";
|
|
1767
|
-
if (isEditor3) return false;
|
|
1768
|
-
var isChildrenValid = deep ? Node.isNodeList(value.children) : Array.isArray(value.children);
|
|
1769
|
-
return isChildrenValid;
|
|
1770
|
-
};
|
|
1771
|
-
var Element = {
|
|
1772
|
-
isAncestor(value) {
|
|
1773
|
-
var {
|
|
1774
|
-
deep = false
|
|
1775
|
-
} = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1776
|
-
return isObject(value) && Node.isNodeList(value.children, {
|
|
1777
|
-
deep
|
|
1778
|
-
});
|
|
1779
|
-
},
|
|
1780
|
-
isElement,
|
|
1781
|
-
isElementList(value) {
|
|
1782
|
-
var {
|
|
1783
|
-
deep = false
|
|
1784
|
-
} = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1785
|
-
return Array.isArray(value) && value.every((val) => Element.isElement(val, {
|
|
1786
|
-
deep
|
|
1787
|
-
}));
|
|
1788
|
-
},
|
|
1789
|
-
isElementProps(props) {
|
|
1790
|
-
return props.children !== void 0;
|
|
1791
|
-
},
|
|
1792
|
-
isElementType: function isElementType(value, elementVal) {
|
|
1793
|
-
var elementKey = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "type";
|
|
1794
|
-
return isElement(value) && value[elementKey] === elementVal;
|
|
1795
|
-
},
|
|
1796
|
-
matches(element, props) {
|
|
1797
|
-
for (var key in props) {
|
|
1798
|
-
if (key === "children") {
|
|
1799
|
-
continue;
|
|
1800
|
-
}
|
|
1801
|
-
if (element[key] !== props[key]) {
|
|
1802
|
-
return false;
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
return true;
|
|
1806
|
-
}
|
|
1807
|
-
};
|
|
1808
|
-
var _excluded$3 = ["children"];
|
|
1809
|
-
var _excluded2$3 = ["text"];
|
|
1810
|
-
var Node = {
|
|
1811
|
-
ancestor(root, path) {
|
|
1812
|
-
var node = Node.get(root, path);
|
|
1813
|
-
if (Text.isText(node)) {
|
|
1814
|
-
throw new Error("Cannot get the ancestor node at path [".concat(path, "] because it refers to a text node instead: ").concat(Scrubber.stringify(node)));
|
|
1815
|
-
}
|
|
1816
|
-
return node;
|
|
1817
|
-
},
|
|
1818
|
-
ancestors(root, path) {
|
|
1819
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1820
|
-
return function* () {
|
|
1821
|
-
for (var p of Path.ancestors(path, options)) {
|
|
1822
|
-
var n = Node.ancestor(root, p);
|
|
1823
|
-
var entry = [n, p];
|
|
1824
|
-
yield entry;
|
|
1825
|
-
}
|
|
1826
|
-
}();
|
|
1827
|
-
},
|
|
1828
|
-
child(root, index) {
|
|
1829
|
-
if (Text.isText(root)) {
|
|
1830
|
-
throw new Error("Cannot get the child of a text node: ".concat(Scrubber.stringify(root)));
|
|
1831
|
-
}
|
|
1832
|
-
var c = root.children[index];
|
|
1833
|
-
if (c == null) {
|
|
1834
|
-
throw new Error("Cannot get child at index `".concat(index, "` in node: ").concat(Scrubber.stringify(root)));
|
|
1835
|
-
}
|
|
1836
|
-
return c;
|
|
1837
|
-
},
|
|
1838
|
-
children(root, path) {
|
|
1839
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1840
|
-
return function* () {
|
|
1841
|
-
var {
|
|
1842
|
-
reverse = false
|
|
1843
|
-
} = options;
|
|
1844
|
-
var ancestor = Node.ancestor(root, path);
|
|
1845
|
-
var {
|
|
1846
|
-
children
|
|
1847
|
-
} = ancestor;
|
|
1848
|
-
var index = reverse ? children.length - 1 : 0;
|
|
1849
|
-
while (reverse ? index >= 0 : index < children.length) {
|
|
1850
|
-
var child = Node.child(ancestor, index);
|
|
1851
|
-
var childPath = path.concat(index);
|
|
1852
|
-
yield [child, childPath];
|
|
1853
|
-
index = reverse ? index - 1 : index + 1;
|
|
1854
|
-
}
|
|
1855
|
-
}();
|
|
1856
|
-
},
|
|
1857
|
-
common(root, path, another) {
|
|
1858
|
-
var p = Path.common(path, another);
|
|
1859
|
-
var n = Node.get(root, p);
|
|
1860
|
-
return [n, p];
|
|
1861
|
-
},
|
|
1862
|
-
descendant(root, path) {
|
|
1863
|
-
var node = Node.get(root, path);
|
|
1864
|
-
if (Editor.isEditor(node)) {
|
|
1865
|
-
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)));
|
|
1866
|
-
}
|
|
1867
|
-
return node;
|
|
1868
|
-
},
|
|
1869
|
-
descendants(root) {
|
|
1870
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1871
|
-
return function* () {
|
|
1872
|
-
for (var [node, path] of Node.nodes(root, options)) {
|
|
1873
|
-
if (path.length !== 0) {
|
|
1874
|
-
yield [node, path];
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
}();
|
|
1878
|
-
},
|
|
1879
|
-
elements(root) {
|
|
1880
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1881
|
-
return function* () {
|
|
1882
|
-
for (var [node, path] of Node.nodes(root, options)) {
|
|
1883
|
-
if (Element.isElement(node)) {
|
|
1884
|
-
yield [node, path];
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
}();
|
|
1888
|
-
},
|
|
1889
|
-
extractProps(node) {
|
|
1890
|
-
if (Element.isAncestor(node)) {
|
|
1891
|
-
var properties = _objectWithoutProperties(node, _excluded$3);
|
|
1892
|
-
return properties;
|
|
1893
|
-
} else {
|
|
1894
|
-
var properties = _objectWithoutProperties(node, _excluded2$3);
|
|
1895
|
-
return properties;
|
|
1896
|
-
}
|
|
1897
|
-
},
|
|
1898
|
-
first(root, path) {
|
|
1899
|
-
var p = path.slice();
|
|
1900
|
-
var n = Node.get(root, p);
|
|
1901
|
-
while (n) {
|
|
1902
|
-
if (Text.isText(n) || n.children.length === 0) {
|
|
1903
|
-
break;
|
|
1904
|
-
} else {
|
|
1905
|
-
n = n.children[0];
|
|
1906
|
-
p.push(0);
|
|
1907
|
-
}
|
|
1908
|
-
}
|
|
1909
|
-
return [n, p];
|
|
1910
|
-
},
|
|
1911
|
-
fragment(root, range) {
|
|
1912
|
-
var newRoot = produce({
|
|
1913
|
-
children: root.children
|
|
1914
|
-
}, (r) => {
|
|
1915
|
-
var [start, end] = Range.edges(range);
|
|
1916
|
-
var nodeEntries = Node.nodes(r, {
|
|
1917
|
-
reverse: true,
|
|
1918
|
-
pass: (_ref) => {
|
|
1919
|
-
var [, path2] = _ref;
|
|
1920
|
-
return !Range.includes(range, path2);
|
|
1921
|
-
}
|
|
1922
|
-
});
|
|
1923
|
-
for (var [, path] of nodeEntries) {
|
|
1924
|
-
if (!Range.includes(range, path)) {
|
|
1925
|
-
var parent = Node.parent(r, path);
|
|
1926
|
-
var index = path[path.length - 1];
|
|
1927
|
-
parent.children.splice(index, 1);
|
|
1928
|
-
}
|
|
1929
|
-
if (Path.equals(path, end.path)) {
|
|
1930
|
-
var leaf = Node.leaf(r, path);
|
|
1931
|
-
leaf.text = leaf.text.slice(0, end.offset);
|
|
1932
|
-
}
|
|
1933
|
-
if (Path.equals(path, start.path)) {
|
|
1934
|
-
var _leaf = Node.leaf(r, path);
|
|
1935
|
-
_leaf.text = _leaf.text.slice(start.offset);
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
if (Editor.isEditor(r)) {
|
|
1939
|
-
r.selection = null;
|
|
1940
|
-
}
|
|
1941
|
-
});
|
|
1942
|
-
return newRoot.children;
|
|
1943
|
-
},
|
|
1944
|
-
get(root, path) {
|
|
1945
|
-
var node = Node.getIf(root, path);
|
|
1946
|
-
if (node === void 0) {
|
|
1947
|
-
throw new Error("Cannot find a descendant at path [".concat(path, "] in node: ").concat(Scrubber.stringify(root)));
|
|
1948
|
-
}
|
|
1949
|
-
return node;
|
|
1950
|
-
},
|
|
1951
|
-
getIf(root, path) {
|
|
1952
|
-
var node = root;
|
|
1953
|
-
for (var i = 0; i < path.length; i++) {
|
|
1954
|
-
var p = path[i];
|
|
1955
|
-
if (Text.isText(node) || !node.children[p]) {
|
|
1956
|
-
return;
|
|
1957
|
-
}
|
|
1958
|
-
node = node.children[p];
|
|
1959
|
-
}
|
|
1960
|
-
return node;
|
|
1961
|
-
},
|
|
1962
|
-
has(root, path) {
|
|
1963
|
-
var node = root;
|
|
1964
|
-
for (var i = 0; i < path.length; i++) {
|
|
1965
|
-
var p = path[i];
|
|
1966
|
-
if (Text.isText(node) || !node.children[p]) {
|
|
1967
|
-
return false;
|
|
1968
|
-
}
|
|
1969
|
-
node = node.children[p];
|
|
1970
|
-
}
|
|
1971
|
-
return true;
|
|
1972
|
-
},
|
|
1973
|
-
isNode(value) {
|
|
1974
|
-
var {
|
|
1975
|
-
deep = false
|
|
1976
|
-
} = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1977
|
-
return Text.isText(value) || Element.isElement(value, {
|
|
1978
|
-
deep
|
|
1979
|
-
}) || Editor.isEditor(value, {
|
|
1980
|
-
deep
|
|
1981
|
-
});
|
|
1982
|
-
},
|
|
1983
|
-
isNodeList(value) {
|
|
1984
|
-
var {
|
|
1985
|
-
deep = false
|
|
1986
|
-
} = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1987
|
-
return Array.isArray(value) && value.every((val) => Node.isNode(val, {
|
|
1988
|
-
deep
|
|
1989
|
-
}));
|
|
1990
|
-
},
|
|
1991
|
-
last(root, path) {
|
|
1992
|
-
var p = path.slice();
|
|
1993
|
-
var n = Node.get(root, p);
|
|
1994
|
-
while (n) {
|
|
1995
|
-
if (Text.isText(n) || n.children.length === 0) {
|
|
1996
|
-
break;
|
|
1997
|
-
} else {
|
|
1998
|
-
var i = n.children.length - 1;
|
|
1999
|
-
n = n.children[i];
|
|
2000
|
-
p.push(i);
|
|
2001
|
-
}
|
|
2002
|
-
}
|
|
2003
|
-
return [n, p];
|
|
2004
|
-
},
|
|
2005
|
-
leaf(root, path) {
|
|
2006
|
-
var node = Node.get(root, path);
|
|
2007
|
-
if (!Text.isText(node)) {
|
|
2008
|
-
throw new Error("Cannot get the leaf node at path [".concat(path, "] because it refers to a non-leaf node: ").concat(Scrubber.stringify(node)));
|
|
2009
|
-
}
|
|
2010
|
-
return node;
|
|
2011
|
-
},
|
|
2012
|
-
levels(root, path) {
|
|
2013
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
2014
|
-
return function* () {
|
|
2015
|
-
for (var p of Path.levels(path, options)) {
|
|
2016
|
-
var n = Node.get(root, p);
|
|
2017
|
-
yield [n, p];
|
|
2018
|
-
}
|
|
2019
|
-
}();
|
|
2020
|
-
},
|
|
2021
|
-
matches(node, props) {
|
|
2022
|
-
return Element.isElement(node) && Element.isElementProps(props) && Element.matches(node, props) || Text.isText(node) && Text.isTextProps(props) && Text.matches(node, props);
|
|
2023
|
-
},
|
|
2024
|
-
nodes(root) {
|
|
2025
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2026
|
-
return function* () {
|
|
2027
|
-
var {
|
|
2028
|
-
pass,
|
|
2029
|
-
reverse = false
|
|
2030
|
-
} = options;
|
|
2031
|
-
var {
|
|
2032
|
-
from = [],
|
|
2033
|
-
to
|
|
2034
|
-
} = options;
|
|
2035
|
-
var visited = /* @__PURE__ */ new Set();
|
|
2036
|
-
var p = [];
|
|
2037
|
-
var n = root;
|
|
2038
|
-
while (true) {
|
|
2039
|
-
if (to && (reverse ? Path.isBefore(p, to) : Path.isAfter(p, to))) {
|
|
2040
|
-
break;
|
|
2041
|
-
}
|
|
2042
|
-
if (!visited.has(n)) {
|
|
2043
|
-
yield [n, p];
|
|
2044
|
-
}
|
|
2045
|
-
if (!visited.has(n) && !Text.isText(n) && n.children.length !== 0 && (pass == null || pass([n, p]) === false)) {
|
|
2046
|
-
visited.add(n);
|
|
2047
|
-
var nextIndex = reverse ? n.children.length - 1 : 0;
|
|
2048
|
-
if (Path.isAncestor(p, from)) {
|
|
2049
|
-
nextIndex = from[p.length];
|
|
2050
|
-
}
|
|
2051
|
-
p = p.concat(nextIndex);
|
|
2052
|
-
n = Node.get(root, p);
|
|
2053
|
-
continue;
|
|
2054
|
-
}
|
|
2055
|
-
if (p.length === 0) {
|
|
2056
|
-
break;
|
|
2057
|
-
}
|
|
2058
|
-
if (!reverse) {
|
|
2059
|
-
var newPath = Path.next(p);
|
|
2060
|
-
if (Node.has(root, newPath)) {
|
|
2061
|
-
p = newPath;
|
|
2062
|
-
n = Node.get(root, p);
|
|
2063
|
-
continue;
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
if (reverse && p[p.length - 1] !== 0) {
|
|
2067
|
-
var _newPath = Path.previous(p);
|
|
2068
|
-
p = _newPath;
|
|
2069
|
-
n = Node.get(root, p);
|
|
2070
|
-
continue;
|
|
2071
|
-
}
|
|
2072
|
-
p = Path.parent(p);
|
|
2073
|
-
n = Node.get(root, p);
|
|
2074
|
-
visited.add(n);
|
|
2075
|
-
}
|
|
2076
|
-
}();
|
|
2077
|
-
},
|
|
2078
|
-
parent(root, path) {
|
|
2079
|
-
var parentPath = Path.parent(path);
|
|
2080
|
-
var p = Node.get(root, parentPath);
|
|
2081
|
-
if (Text.isText(p)) {
|
|
2082
|
-
throw new Error("Cannot get the parent of path [".concat(path, "] because it does not exist in the root."));
|
|
2083
|
-
}
|
|
2084
|
-
return p;
|
|
2085
|
-
},
|
|
2086
|
-
string(node) {
|
|
2087
|
-
if (Text.isText(node)) {
|
|
2088
|
-
return node.text;
|
|
2089
|
-
} else {
|
|
2090
|
-
return node.children.map(Node.string).join("");
|
|
2091
|
-
}
|
|
2092
|
-
},
|
|
2093
|
-
texts(root) {
|
|
2094
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2095
|
-
return function* () {
|
|
2096
|
-
for (var [node, path] of Node.nodes(root, options)) {
|
|
2097
|
-
if (Text.isText(node)) {
|
|
2098
|
-
yield [node, path];
|
|
2099
|
-
}
|
|
2100
|
-
}
|
|
2101
|
-
}();
|
|
2102
|
-
}
|
|
2103
|
-
};
|
|
2104
|
-
function ownKeys$c(e, r) {
|
|
2105
|
-
var t = Object.keys(e);
|
|
2106
|
-
if (Object.getOwnPropertySymbols) {
|
|
2107
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
2108
|
-
r && (o = o.filter(function(r2) {
|
|
2109
|
-
return Object.getOwnPropertyDescriptor(e, r2).enumerable;
|
|
2110
|
-
})), t.push.apply(t, o);
|
|
2111
|
-
}
|
|
2112
|
-
return t;
|
|
2113
|
-
}
|
|
2114
|
-
function _objectSpread$c(e) {
|
|
2115
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
2116
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
2117
|
-
r % 2 ? ownKeys$c(Object(t), true).forEach(function(r2) {
|
|
2118
|
-
_defineProperty(e, r2, t[r2]);
|
|
2119
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$c(Object(t)).forEach(function(r2) {
|
|
2120
|
-
Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
|
|
2121
|
-
});
|
|
2122
|
-
}
|
|
2123
|
-
return e;
|
|
2124
|
-
}
|
|
2125
|
-
var Operation = {
|
|
2126
|
-
isNodeOperation(value) {
|
|
2127
|
-
return Operation.isOperation(value) && value.type.endsWith("_node");
|
|
2128
|
-
},
|
|
2129
|
-
isOperation(value) {
|
|
2130
|
-
if (!isObject(value)) {
|
|
2131
|
-
return false;
|
|
2132
|
-
}
|
|
2133
|
-
switch (value.type) {
|
|
2134
|
-
case "insert_node":
|
|
2135
|
-
return Path.isPath(value.path) && Node.isNode(value.node);
|
|
2136
|
-
case "insert_text":
|
|
2137
|
-
return typeof value.offset === "number" && typeof value.text === "string" && Path.isPath(value.path);
|
|
2138
|
-
case "merge_node":
|
|
2139
|
-
return typeof value.position === "number" && Path.isPath(value.path) && isObject(value.properties);
|
|
2140
|
-
case "move_node":
|
|
2141
|
-
return Path.isPath(value.path) && Path.isPath(value.newPath);
|
|
2142
|
-
case "remove_node":
|
|
2143
|
-
return Path.isPath(value.path) && Node.isNode(value.node);
|
|
2144
|
-
case "remove_text":
|
|
2145
|
-
return typeof value.offset === "number" && typeof value.text === "string" && Path.isPath(value.path);
|
|
2146
|
-
case "set_node":
|
|
2147
|
-
return Path.isPath(value.path) && isObject(value.properties) && isObject(value.newProperties);
|
|
2148
|
-
case "set_selection":
|
|
2149
|
-
return value.properties === null && Range.isRange(value.newProperties) || value.newProperties === null && Range.isRange(value.properties) || isObject(value.properties) && isObject(value.newProperties);
|
|
2150
|
-
case "split_node":
|
|
2151
|
-
return Path.isPath(value.path) && typeof value.position === "number" && isObject(value.properties);
|
|
2152
|
-
default:
|
|
2153
|
-
return false;
|
|
2154
|
-
}
|
|
2155
|
-
},
|
|
2156
|
-
isOperationList(value) {
|
|
2157
|
-
return Array.isArray(value) && value.every((val) => Operation.isOperation(val));
|
|
2158
|
-
},
|
|
2159
|
-
isSelectionOperation(value) {
|
|
2160
|
-
return Operation.isOperation(value) && value.type.endsWith("_selection");
|
|
2161
|
-
},
|
|
2162
|
-
isTextOperation(value) {
|
|
2163
|
-
return Operation.isOperation(value) && value.type.endsWith("_text");
|
|
2164
|
-
},
|
|
2165
|
-
inverse(op) {
|
|
2166
|
-
switch (op.type) {
|
|
2167
|
-
case "insert_node": {
|
|
2168
|
-
return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
|
2169
|
-
type: "remove_node"
|
|
2170
|
-
});
|
|
2171
|
-
}
|
|
2172
|
-
case "insert_text": {
|
|
2173
|
-
return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
|
2174
|
-
type: "remove_text"
|
|
2175
|
-
});
|
|
2176
|
-
}
|
|
2177
|
-
case "merge_node": {
|
|
2178
|
-
return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
|
2179
|
-
type: "split_node",
|
|
2180
|
-
path: Path.previous(op.path)
|
|
2181
|
-
});
|
|
2182
|
-
}
|
|
2183
|
-
case "move_node": {
|
|
2184
|
-
var {
|
|
2185
|
-
newPath,
|
|
2186
|
-
path
|
|
2187
|
-
} = op;
|
|
2188
|
-
if (Path.equals(newPath, path)) {
|
|
2189
|
-
return op;
|
|
2190
|
-
}
|
|
2191
|
-
if (Path.isSibling(path, newPath)) {
|
|
2192
|
-
return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
|
2193
|
-
path: newPath,
|
|
2194
|
-
newPath: path
|
|
2195
|
-
});
|
|
2196
|
-
}
|
|
2197
|
-
var inversePath = Path.transform(path, op);
|
|
2198
|
-
var inverseNewPath = Path.transform(Path.next(path), op);
|
|
2199
|
-
return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
|
2200
|
-
path: inversePath,
|
|
2201
|
-
newPath: inverseNewPath
|
|
2202
|
-
});
|
|
2203
|
-
}
|
|
2204
|
-
case "remove_node": {
|
|
2205
|
-
return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
|
2206
|
-
type: "insert_node"
|
|
2207
|
-
});
|
|
2208
|
-
}
|
|
2209
|
-
case "remove_text": {
|
|
2210
|
-
return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
|
2211
|
-
type: "insert_text"
|
|
2212
|
-
});
|
|
2213
|
-
}
|
|
2214
|
-
case "set_node": {
|
|
2215
|
-
var {
|
|
2216
|
-
properties,
|
|
2217
|
-
newProperties
|
|
2218
|
-
} = op;
|
|
2219
|
-
return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
|
2220
|
-
properties: newProperties,
|
|
2221
|
-
newProperties: properties
|
|
2222
|
-
});
|
|
2223
|
-
}
|
|
2224
|
-
case "set_selection": {
|
|
2225
|
-
var {
|
|
2226
|
-
properties: _properties,
|
|
2227
|
-
newProperties: _newProperties
|
|
2228
|
-
} = op;
|
|
2229
|
-
if (_properties == null) {
|
|
2230
|
-
return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
|
2231
|
-
properties: _newProperties,
|
|
2232
|
-
newProperties: null
|
|
2233
|
-
});
|
|
2234
|
-
} else if (_newProperties == null) {
|
|
2235
|
-
return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
|
2236
|
-
properties: null,
|
|
2237
|
-
newProperties: _properties
|
|
2238
|
-
});
|
|
2239
|
-
} else {
|
|
2240
|
-
return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
|
2241
|
-
properties: _newProperties,
|
|
2242
|
-
newProperties: _properties
|
|
2243
|
-
});
|
|
2244
|
-
}
|
|
2245
|
-
}
|
|
2246
|
-
case "split_node": {
|
|
2247
|
-
return _objectSpread$c(_objectSpread$c({}, op), {}, {
|
|
2248
|
-
type: "merge_node",
|
|
2249
|
-
path: Path.next(op.path)
|
|
2250
|
-
});
|
|
2251
|
-
}
|
|
2252
|
-
}
|
|
2253
|
-
}
|
|
2254
|
-
};
|
|
2255
|
-
var isEditor = function isEditor2(value) {
|
|
2256
|
-
var {
|
|
2257
|
-
deep = false
|
|
2258
|
-
} = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2259
|
-
if (!isObject(value)) {
|
|
2260
|
-
return false;
|
|
2261
|
-
}
|
|
2262
|
-
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);
|
|
2263
|
-
return isEditor3;
|
|
2264
|
-
};
|
|
2265
|
-
var Editor = {
|
|
2266
|
-
above(editor, options) {
|
|
2267
|
-
return editor.above(options);
|
|
2268
|
-
},
|
|
2269
|
-
addMark(editor, key, value) {
|
|
2270
|
-
editor.addMark(key, value);
|
|
2271
|
-
},
|
|
2272
|
-
after(editor, at, options) {
|
|
2273
|
-
return editor.after(at, options);
|
|
2274
|
-
},
|
|
2275
|
-
before(editor, at, options) {
|
|
2276
|
-
return editor.before(at, options);
|
|
2277
|
-
},
|
|
2278
|
-
deleteBackward(editor) {
|
|
2279
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2280
|
-
var {
|
|
2281
|
-
unit = "character"
|
|
2282
|
-
} = options;
|
|
2283
|
-
editor.deleteBackward(unit);
|
|
2284
|
-
},
|
|
2285
|
-
deleteForward(editor) {
|
|
2286
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2287
|
-
var {
|
|
2288
|
-
unit = "character"
|
|
2289
|
-
} = options;
|
|
2290
|
-
editor.deleteForward(unit);
|
|
2291
|
-
},
|
|
2292
|
-
deleteFragment(editor, options) {
|
|
2293
|
-
editor.deleteFragment(options);
|
|
2294
|
-
},
|
|
2295
|
-
edges(editor, at) {
|
|
2296
|
-
return editor.edges(at);
|
|
2297
|
-
},
|
|
2298
|
-
elementReadOnly(editor) {
|
|
2299
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2300
|
-
return editor.elementReadOnly(options);
|
|
2301
|
-
},
|
|
2302
|
-
end(editor, at) {
|
|
2303
|
-
return editor.end(at);
|
|
2304
|
-
},
|
|
2305
|
-
first(editor, at) {
|
|
2306
|
-
return editor.first(at);
|
|
2307
|
-
},
|
|
2308
|
-
fragment(editor, at) {
|
|
2309
|
-
return editor.fragment(at);
|
|
2310
|
-
},
|
|
2311
|
-
hasBlocks(editor, element) {
|
|
2312
|
-
return editor.hasBlocks(element);
|
|
2313
|
-
},
|
|
2314
|
-
hasInlines(editor, element) {
|
|
2315
|
-
return editor.hasInlines(element);
|
|
2316
|
-
},
|
|
2317
|
-
hasPath(editor, path) {
|
|
2318
|
-
return editor.hasPath(path);
|
|
2319
|
-
},
|
|
2320
|
-
hasTexts(editor, element) {
|
|
2321
|
-
return editor.hasTexts(element);
|
|
2322
|
-
},
|
|
2323
|
-
insertBreak(editor) {
|
|
2324
|
-
editor.insertBreak();
|
|
2325
|
-
},
|
|
2326
|
-
insertFragment(editor, fragment, options) {
|
|
2327
|
-
editor.insertFragment(fragment, options);
|
|
2328
|
-
},
|
|
2329
|
-
insertNode(editor, node) {
|
|
2330
|
-
editor.insertNode(node);
|
|
2331
|
-
},
|
|
2332
|
-
insertSoftBreak(editor) {
|
|
2333
|
-
editor.insertSoftBreak();
|
|
2334
|
-
},
|
|
2335
|
-
insertText(editor, text) {
|
|
2336
|
-
editor.insertText(text);
|
|
2337
|
-
},
|
|
2338
|
-
isBlock(editor, value) {
|
|
2339
|
-
return editor.isBlock(value);
|
|
2340
|
-
},
|
|
2341
|
-
isEdge(editor, point, at) {
|
|
2342
|
-
return editor.isEdge(point, at);
|
|
2343
|
-
},
|
|
2344
|
-
isEditor(value) {
|
|
2345
|
-
return isEditor(value);
|
|
2346
|
-
},
|
|
2347
|
-
isElementReadOnly(editor, element) {
|
|
2348
|
-
return editor.isElementReadOnly(element);
|
|
2349
|
-
},
|
|
2350
|
-
isEmpty(editor, element) {
|
|
2351
|
-
return editor.isEmpty(element);
|
|
2352
|
-
},
|
|
2353
|
-
isEnd(editor, point, at) {
|
|
2354
|
-
return editor.isEnd(point, at);
|
|
2355
|
-
},
|
|
2356
|
-
isInline(editor, value) {
|
|
2357
|
-
return editor.isInline(value);
|
|
2358
|
-
},
|
|
2359
|
-
isNormalizing(editor) {
|
|
2360
|
-
return editor.isNormalizing();
|
|
2361
|
-
},
|
|
2362
|
-
isSelectable(editor, value) {
|
|
2363
|
-
return editor.isSelectable(value);
|
|
2364
|
-
},
|
|
2365
|
-
isStart(editor, point, at) {
|
|
2366
|
-
return editor.isStart(point, at);
|
|
2367
|
-
},
|
|
2368
|
-
isVoid(editor, value) {
|
|
2369
|
-
return editor.isVoid(value);
|
|
2370
|
-
},
|
|
2371
|
-
last(editor, at) {
|
|
2372
|
-
return editor.last(at);
|
|
2373
|
-
},
|
|
2374
|
-
leaf(editor, at, options) {
|
|
2375
|
-
return editor.leaf(at, options);
|
|
2376
|
-
},
|
|
2377
|
-
levels(editor, options) {
|
|
2378
|
-
return editor.levels(options);
|
|
2379
|
-
},
|
|
2380
|
-
marks(editor) {
|
|
2381
|
-
return editor.getMarks();
|
|
2382
|
-
},
|
|
2383
|
-
next(editor, options) {
|
|
2384
|
-
return editor.next(options);
|
|
2385
|
-
},
|
|
2386
|
-
node(editor, at, options) {
|
|
2387
|
-
return editor.node(at, options);
|
|
2388
|
-
},
|
|
2389
|
-
nodes(editor, options) {
|
|
2390
|
-
return editor.nodes(options);
|
|
2391
|
-
},
|
|
2392
|
-
normalize(editor, options) {
|
|
2393
|
-
editor.normalize(options);
|
|
2394
|
-
},
|
|
2395
|
-
parent(editor, at, options) {
|
|
2396
|
-
return editor.parent(at, options);
|
|
2397
|
-
},
|
|
2398
|
-
path(editor, at, options) {
|
|
2399
|
-
return editor.path(at, options);
|
|
2400
|
-
},
|
|
2401
|
-
pathRef(editor, path, options) {
|
|
2402
|
-
return editor.pathRef(path, options);
|
|
2403
|
-
},
|
|
2404
|
-
pathRefs(editor) {
|
|
2405
|
-
return editor.pathRefs();
|
|
2406
|
-
},
|
|
2407
|
-
point(editor, at, options) {
|
|
2408
|
-
return editor.point(at, options);
|
|
2409
|
-
},
|
|
2410
|
-
pointRef(editor, point, options) {
|
|
2411
|
-
return editor.pointRef(point, options);
|
|
2412
|
-
},
|
|
2413
|
-
pointRefs(editor) {
|
|
2414
|
-
return editor.pointRefs();
|
|
2415
|
-
},
|
|
2416
|
-
positions(editor, options) {
|
|
2417
|
-
return editor.positions(options);
|
|
2418
|
-
},
|
|
2419
|
-
previous(editor, options) {
|
|
2420
|
-
return editor.previous(options);
|
|
2421
|
-
},
|
|
2422
|
-
range(editor, at, to) {
|
|
2423
|
-
return editor.range(at, to);
|
|
2424
|
-
},
|
|
2425
|
-
rangeRef(editor, range, options) {
|
|
2426
|
-
return editor.rangeRef(range, options);
|
|
2427
|
-
},
|
|
2428
|
-
rangeRefs(editor) {
|
|
2429
|
-
return editor.rangeRefs();
|
|
2430
|
-
},
|
|
2431
|
-
removeMark(editor, key) {
|
|
2432
|
-
editor.removeMark(key);
|
|
2433
|
-
},
|
|
2434
|
-
setNormalizing(editor, isNormalizing) {
|
|
2435
|
-
editor.setNormalizing(isNormalizing);
|
|
2436
|
-
},
|
|
2437
|
-
start(editor, at) {
|
|
2438
|
-
return editor.start(at);
|
|
2439
|
-
},
|
|
2440
|
-
string(editor, at, options) {
|
|
2441
|
-
return editor.string(at, options);
|
|
2442
|
-
},
|
|
2443
|
-
unhangRange(editor, range, options) {
|
|
2444
|
-
return editor.unhangRange(range, options);
|
|
2445
|
-
},
|
|
2446
|
-
void(editor, options) {
|
|
2447
|
-
return editor.void(options);
|
|
2448
|
-
},
|
|
2449
|
-
withoutNormalizing(editor, fn) {
|
|
2450
|
-
editor.withoutNormalizing(fn);
|
|
2451
|
-
},
|
|
2452
|
-
shouldMergeNodesRemovePrevNode: (editor, prevNode, curNode) => {
|
|
2453
|
-
return editor.shouldMergeNodesRemovePrevNode(prevNode, curNode);
|
|
2454
|
-
}
|
|
2455
|
-
};
|
|
2456
|
-
function ownKeys$b(e, r) {
|
|
2457
|
-
var t = Object.keys(e);
|
|
2458
|
-
if (Object.getOwnPropertySymbols) {
|
|
2459
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
2460
|
-
r && (o = o.filter(function(r2) {
|
|
2461
|
-
return Object.getOwnPropertyDescriptor(e, r2).enumerable;
|
|
2462
|
-
})), t.push.apply(t, o);
|
|
2463
|
-
}
|
|
2464
|
-
return t;
|
|
2465
|
-
}
|
|
2466
|
-
function _objectSpread$b(e) {
|
|
2467
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
2468
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
2469
|
-
r % 2 ? ownKeys$b(Object(t), true).forEach(function(r2) {
|
|
2470
|
-
_defineProperty(e, r2, t[r2]);
|
|
2471
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$b(Object(t)).forEach(function(r2) {
|
|
2472
|
-
Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
|
|
2473
|
-
});
|
|
2474
|
-
}
|
|
2475
|
-
return e;
|
|
2476
|
-
}
|
|
2477
|
-
var Point = {
|
|
2478
|
-
compare(point, another) {
|
|
2479
|
-
var result = Path.compare(point.path, another.path);
|
|
2480
|
-
if (result === 0) {
|
|
2481
|
-
if (point.offset < another.offset) return -1;
|
|
2482
|
-
if (point.offset > another.offset) return 1;
|
|
2483
|
-
return 0;
|
|
2484
|
-
}
|
|
2485
|
-
return result;
|
|
2486
|
-
},
|
|
2487
|
-
isAfter(point, another) {
|
|
2488
|
-
return Point.compare(point, another) === 1;
|
|
2489
|
-
},
|
|
2490
|
-
isBefore(point, another) {
|
|
2491
|
-
return Point.compare(point, another) === -1;
|
|
2492
|
-
},
|
|
2493
|
-
equals(point, another) {
|
|
2494
|
-
return point.offset === another.offset && Path.equals(point.path, another.path);
|
|
2495
|
-
},
|
|
2496
|
-
isPoint(value) {
|
|
2497
|
-
return isObject(value) && typeof value.offset === "number" && Path.isPath(value.path);
|
|
2498
|
-
},
|
|
2499
|
-
transform(point, op) {
|
|
2500
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
2501
|
-
if (point === null) {
|
|
2502
|
-
return null;
|
|
2503
|
-
}
|
|
2504
|
-
var {
|
|
2505
|
-
affinity = "forward"
|
|
2506
|
-
} = options;
|
|
2507
|
-
var {
|
|
2508
|
-
path,
|
|
2509
|
-
offset
|
|
2510
|
-
} = point;
|
|
2511
|
-
switch (op.type) {
|
|
2512
|
-
case "insert_node":
|
|
2513
|
-
case "move_node": {
|
|
2514
|
-
path = Path.transform(path, op, options);
|
|
2515
|
-
break;
|
|
2516
|
-
}
|
|
2517
|
-
case "insert_text": {
|
|
2518
|
-
if (Path.equals(op.path, path) && (op.offset < offset || op.offset === offset && affinity === "forward")) {
|
|
2519
|
-
offset += op.text.length;
|
|
2520
|
-
}
|
|
2521
|
-
break;
|
|
2522
|
-
}
|
|
2523
|
-
case "merge_node": {
|
|
2524
|
-
if (Path.equals(op.path, path)) {
|
|
2525
|
-
offset += op.position;
|
|
2526
|
-
}
|
|
2527
|
-
path = Path.transform(path, op, options);
|
|
2528
|
-
break;
|
|
2529
|
-
}
|
|
2530
|
-
case "remove_text": {
|
|
2531
|
-
if (Path.equals(op.path, path) && op.offset <= offset) {
|
|
2532
|
-
offset -= Math.min(offset - op.offset, op.text.length);
|
|
2533
|
-
}
|
|
2534
|
-
break;
|
|
2535
|
-
}
|
|
2536
|
-
case "remove_node": {
|
|
2537
|
-
if (Path.equals(op.path, path) || Path.isAncestor(op.path, path)) {
|
|
2538
|
-
return null;
|
|
2539
|
-
}
|
|
2540
|
-
path = Path.transform(path, op, options);
|
|
2541
|
-
break;
|
|
2542
|
-
}
|
|
2543
|
-
case "split_node": {
|
|
2544
|
-
if (Path.equals(op.path, path)) {
|
|
2545
|
-
if (op.position === offset && affinity == null) {
|
|
2546
|
-
return null;
|
|
2547
|
-
} else if (op.position < offset || op.position === offset && affinity === "forward") {
|
|
2548
|
-
offset -= op.position;
|
|
2549
|
-
path = Path.transform(path, op, _objectSpread$b(_objectSpread$b({}, options), {}, {
|
|
2550
|
-
affinity: "forward"
|
|
2551
|
-
}));
|
|
2552
|
-
}
|
|
2553
|
-
} else {
|
|
2554
|
-
path = Path.transform(path, op, options);
|
|
2555
|
-
}
|
|
2556
|
-
break;
|
|
2557
|
-
}
|
|
2558
|
-
default:
|
|
2559
|
-
return point;
|
|
2560
|
-
}
|
|
2561
|
-
return {
|
|
2562
|
-
path,
|
|
2563
|
-
offset
|
|
2564
|
-
};
|
|
2565
|
-
}
|
|
2566
|
-
};
|
|
2567
|
-
var _scrubber = void 0;
|
|
2568
|
-
var Scrubber = {
|
|
2569
|
-
setScrubber(scrubber) {
|
|
2570
|
-
_scrubber = scrubber;
|
|
2571
|
-
},
|
|
2572
|
-
stringify(value) {
|
|
2573
|
-
return JSON.stringify(value, _scrubber);
|
|
2574
|
-
}
|
|
2575
|
-
};
|
|
2576
|
-
var _excluded$2 = ["text"];
|
|
2577
|
-
var _excluded2$2 = ["anchor", "focus", "merge"];
|
|
2578
|
-
function ownKeys$a(e, r) {
|
|
2579
|
-
var t = Object.keys(e);
|
|
2580
|
-
if (Object.getOwnPropertySymbols) {
|
|
2581
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
2582
|
-
r && (o = o.filter(function(r2) {
|
|
2583
|
-
return Object.getOwnPropertyDescriptor(e, r2).enumerable;
|
|
2584
|
-
})), t.push.apply(t, o);
|
|
2585
|
-
}
|
|
2586
|
-
return t;
|
|
2587
|
-
}
|
|
2588
|
-
function _objectSpread$a(e) {
|
|
2589
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
2590
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
2591
|
-
r % 2 ? ownKeys$a(Object(t), true).forEach(function(r2) {
|
|
2592
|
-
_defineProperty(e, r2, t[r2]);
|
|
2593
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$a(Object(t)).forEach(function(r2) {
|
|
2594
|
-
Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
|
|
2595
|
-
});
|
|
2596
|
-
}
|
|
2597
|
-
return e;
|
|
2598
|
-
}
|
|
2599
|
-
var Text = {
|
|
2600
|
-
equals(text, another) {
|
|
2601
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
2602
|
-
var {
|
|
2603
|
-
loose = false
|
|
2604
|
-
} = options;
|
|
2605
|
-
function omitText(obj) {
|
|
2606
|
-
var rest = _objectWithoutProperties(obj, _excluded$2);
|
|
2607
|
-
return rest;
|
|
2608
|
-
}
|
|
2609
|
-
return isDeepEqual(loose ? omitText(text) : text, loose ? omitText(another) : another);
|
|
2610
|
-
},
|
|
2611
|
-
isText(value) {
|
|
2612
|
-
return isObject(value) && typeof value.text === "string";
|
|
2613
|
-
},
|
|
2614
|
-
isTextList(value) {
|
|
2615
|
-
return Array.isArray(value) && value.every((val) => Text.isText(val));
|
|
2616
|
-
},
|
|
2617
|
-
isTextProps(props) {
|
|
2618
|
-
return props.text !== void 0;
|
|
2619
|
-
},
|
|
2620
|
-
matches(text, props) {
|
|
2621
|
-
for (var key in props) {
|
|
2622
|
-
if (key === "text") {
|
|
2623
|
-
continue;
|
|
2624
|
-
}
|
|
2625
|
-
if (!text.hasOwnProperty(key) || text[key] !== props[key]) {
|
|
2626
|
-
return false;
|
|
2627
|
-
}
|
|
2628
|
-
}
|
|
2629
|
-
return true;
|
|
2630
|
-
},
|
|
2631
|
-
decorations(node, decorations) {
|
|
2632
|
-
var leaves = [{
|
|
2633
|
-
leaf: _objectSpread$a({}, node)
|
|
2634
|
-
}];
|
|
2635
|
-
for (var dec of decorations) {
|
|
2636
|
-
var {
|
|
2637
|
-
anchor,
|
|
2638
|
-
focus,
|
|
2639
|
-
merge: mergeDecoration
|
|
2640
|
-
} = dec, rest = _objectWithoutProperties(dec, _excluded2$2);
|
|
2641
|
-
var [start, end] = Range.edges(dec);
|
|
2642
|
-
var next = [];
|
|
2643
|
-
var leafEnd = 0;
|
|
2644
|
-
var decorationStart = start.offset;
|
|
2645
|
-
var decorationEnd = end.offset;
|
|
2646
|
-
var merge = mergeDecoration !== null && mergeDecoration !== void 0 ? mergeDecoration : Object.assign;
|
|
2647
|
-
for (var {
|
|
2648
|
-
leaf
|
|
2649
|
-
} of leaves) {
|
|
2650
|
-
var {
|
|
2651
|
-
length
|
|
2652
|
-
} = leaf.text;
|
|
2653
|
-
var leafStart = leafEnd;
|
|
2654
|
-
leafEnd += length;
|
|
2655
|
-
if (decorationStart <= leafStart && leafEnd <= decorationEnd) {
|
|
2656
|
-
merge(leaf, rest);
|
|
2657
|
-
next.push({
|
|
2658
|
-
leaf
|
|
2659
|
-
});
|
|
2660
|
-
continue;
|
|
2661
|
-
}
|
|
2662
|
-
if (decorationStart !== decorationEnd && (decorationStart === leafEnd || decorationEnd === leafStart) || decorationStart > leafEnd || decorationEnd < leafStart || decorationEnd === leafStart && leafStart !== 0) {
|
|
2663
|
-
next.push({
|
|
2664
|
-
leaf
|
|
2665
|
-
});
|
|
2666
|
-
continue;
|
|
2667
|
-
}
|
|
2668
|
-
var middle = leaf;
|
|
2669
|
-
var before = void 0;
|
|
2670
|
-
var after = void 0;
|
|
2671
|
-
if (decorationEnd < leafEnd) {
|
|
2672
|
-
var off = decorationEnd - leafStart;
|
|
2673
|
-
after = {
|
|
2674
|
-
leaf: _objectSpread$a(_objectSpread$a({}, middle), {}, {
|
|
2675
|
-
text: middle.text.slice(off)
|
|
2676
|
-
})
|
|
2677
|
-
};
|
|
2678
|
-
middle = _objectSpread$a(_objectSpread$a({}, middle), {}, {
|
|
2679
|
-
text: middle.text.slice(0, off)
|
|
2680
|
-
});
|
|
2681
|
-
}
|
|
2682
|
-
if (decorationStart > leafStart) {
|
|
2683
|
-
var _off = decorationStart - leafStart;
|
|
2684
|
-
before = {
|
|
2685
|
-
leaf: _objectSpread$a(_objectSpread$a({}, middle), {}, {
|
|
2686
|
-
text: middle.text.slice(0, _off)
|
|
2687
|
-
})
|
|
2688
|
-
};
|
|
2689
|
-
middle = _objectSpread$a(_objectSpread$a({}, middle), {}, {
|
|
2690
|
-
text: middle.text.slice(_off)
|
|
2691
|
-
});
|
|
2692
|
-
}
|
|
2693
|
-
merge(middle, rest);
|
|
2694
|
-
if (before) {
|
|
2695
|
-
next.push(before);
|
|
2696
|
-
}
|
|
2697
|
-
next.push({
|
|
2698
|
-
leaf: middle
|
|
2699
|
-
});
|
|
2700
|
-
if (after) {
|
|
2701
|
-
next.push(after);
|
|
2702
|
-
}
|
|
2703
|
-
}
|
|
2704
|
-
leaves = next;
|
|
2705
|
-
}
|
|
2706
|
-
if (leaves.length > 1) {
|
|
2707
|
-
var currentOffset = 0;
|
|
2708
|
-
for (var [index, item] of leaves.entries()) {
|
|
2709
|
-
var _start = currentOffset;
|
|
2710
|
-
var _end = _start + item.leaf.text.length;
|
|
2711
|
-
var position = {
|
|
2712
|
-
start: _start,
|
|
2713
|
-
end: _end
|
|
2714
|
-
};
|
|
2715
|
-
if (index === 0) position.isFirst = true;
|
|
2716
|
-
if (index === leaves.length - 1) position.isLast = true;
|
|
2717
|
-
item.position = position;
|
|
2718
|
-
currentOffset = _end;
|
|
2719
|
-
}
|
|
2720
|
-
}
|
|
2721
|
-
return leaves;
|
|
2722
|
-
}
|
|
2723
|
-
};
|
|
2724
|
-
var getDefaultInsertLocation = (editor) => {
|
|
2725
|
-
if (editor.selection) {
|
|
2726
|
-
return editor.selection;
|
|
2727
|
-
} else if (editor.children.length > 0) {
|
|
2728
|
-
return Editor.end(editor, []);
|
|
2729
|
-
} else {
|
|
2730
|
-
return [0];
|
|
2731
|
-
}
|
|
2732
|
-
};
|
|
2733
|
-
var CodepointType;
|
|
2734
|
-
(function(CodepointType2) {
|
|
2735
|
-
CodepointType2[CodepointType2["None"] = 0] = "None";
|
|
2736
|
-
CodepointType2[CodepointType2["Extend"] = 1] = "Extend";
|
|
2737
|
-
CodepointType2[CodepointType2["ZWJ"] = 2] = "ZWJ";
|
|
2738
|
-
CodepointType2[CodepointType2["RI"] = 4] = "RI";
|
|
2739
|
-
CodepointType2[CodepointType2["Prepend"] = 8] = "Prepend";
|
|
2740
|
-
CodepointType2[CodepointType2["SpacingMark"] = 16] = "SpacingMark";
|
|
2741
|
-
CodepointType2[CodepointType2["L"] = 32] = "L";
|
|
2742
|
-
CodepointType2[CodepointType2["V"] = 64] = "V";
|
|
2743
|
-
CodepointType2[CodepointType2["T"] = 128] = "T";
|
|
2744
|
-
CodepointType2[CodepointType2["LV"] = 256] = "LV";
|
|
2745
|
-
CodepointType2[CodepointType2["LVT"] = 512] = "LVT";
|
|
2746
|
-
CodepointType2[CodepointType2["ExtPict"] = 1024] = "ExtPict";
|
|
2747
|
-
CodepointType2[CodepointType2["Any"] = 2048] = "Any";
|
|
2748
|
-
})(CodepointType || (CodepointType = {}));
|
|
2749
|
-
var NonBoundaryPairs = [
|
|
2750
|
-
// GB6
|
|
2751
|
-
[CodepointType.L, CodepointType.L | CodepointType.V | CodepointType.LV | CodepointType.LVT],
|
|
2752
|
-
// GB7
|
|
2753
|
-
[CodepointType.LV | CodepointType.V, CodepointType.V | CodepointType.T],
|
|
2754
|
-
// GB8
|
|
2755
|
-
[CodepointType.LVT | CodepointType.T, CodepointType.T],
|
|
2756
|
-
// GB9
|
|
2757
|
-
[CodepointType.Any, CodepointType.Extend | CodepointType.ZWJ],
|
|
2758
|
-
// GB9a
|
|
2759
|
-
[CodepointType.Any, CodepointType.SpacingMark],
|
|
2760
|
-
// GB9b
|
|
2761
|
-
[CodepointType.Prepend, CodepointType.Any],
|
|
2762
|
-
// GB11
|
|
2763
|
-
[CodepointType.ZWJ, CodepointType.ExtPict],
|
|
2764
|
-
// GB12 and GB13
|
|
2765
|
-
[CodepointType.RI, CodepointType.RI]
|
|
2766
|
-
];
|
|
2767
|
-
var TextTransforms = {
|
|
2768
|
-
delete(editor, options) {
|
|
2769
|
-
editor.delete(options);
|
|
2770
|
-
},
|
|
2771
|
-
insertFragment(editor, fragment, options) {
|
|
2772
|
-
editor.insertFragment(fragment, options);
|
|
2773
|
-
},
|
|
2774
|
-
insertText(editor, text) {
|
|
2775
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
2776
|
-
Editor.withoutNormalizing(editor, () => {
|
|
2777
|
-
var {
|
|
2778
|
-
voids = false
|
|
2779
|
-
} = options;
|
|
2780
|
-
var {
|
|
2781
|
-
at = getDefaultInsertLocation(editor)
|
|
2782
|
-
} = options;
|
|
2783
|
-
if (Path.isPath(at)) {
|
|
2784
|
-
at = Editor.range(editor, at);
|
|
2785
|
-
}
|
|
2786
|
-
if (Range.isRange(at)) {
|
|
2787
|
-
if (Range.isCollapsed(at)) {
|
|
2788
|
-
at = at.anchor;
|
|
2789
|
-
} else {
|
|
2790
|
-
var end = Range.end(at);
|
|
2791
|
-
if (!voids && Editor.void(editor, {
|
|
2792
|
-
at: end
|
|
2793
|
-
})) {
|
|
2794
|
-
return;
|
|
2795
|
-
}
|
|
2796
|
-
var start = Range.start(at);
|
|
2797
|
-
var startRef = Editor.pointRef(editor, start);
|
|
2798
|
-
var endRef = Editor.pointRef(editor, end);
|
|
2799
|
-
Transforms.delete(editor, {
|
|
2800
|
-
at,
|
|
2801
|
-
voids
|
|
2802
|
-
});
|
|
2803
|
-
var startPoint = startRef.unref();
|
|
2804
|
-
var endPoint = endRef.unref();
|
|
2805
|
-
at = startPoint || endPoint;
|
|
2806
|
-
Transforms.setSelection(editor, {
|
|
2807
|
-
anchor: at,
|
|
2808
|
-
focus: at
|
|
2809
|
-
});
|
|
2810
|
-
}
|
|
2811
|
-
}
|
|
2812
|
-
if (!voids && Editor.void(editor, {
|
|
2813
|
-
at
|
|
2814
|
-
}) || Editor.elementReadOnly(editor, {
|
|
2815
|
-
at
|
|
2816
|
-
})) {
|
|
2817
|
-
return;
|
|
2818
|
-
}
|
|
2819
|
-
var {
|
|
2820
|
-
path,
|
|
2821
|
-
offset
|
|
2822
|
-
} = at;
|
|
2823
|
-
if (text.length > 0) editor.apply({
|
|
2824
|
-
type: "insert_text",
|
|
2825
|
-
path,
|
|
2826
|
-
offset,
|
|
2827
|
-
text
|
|
2828
|
-
});
|
|
2829
|
-
});
|
|
2830
|
-
}
|
|
2831
|
-
};
|
|
2832
|
-
function ownKeys$9(e, r) {
|
|
2833
|
-
var t = Object.keys(e);
|
|
2834
|
-
if (Object.getOwnPropertySymbols) {
|
|
2835
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
2836
|
-
r && (o = o.filter(function(r2) {
|
|
2837
|
-
return Object.getOwnPropertyDescriptor(e, r2).enumerable;
|
|
2838
|
-
})), t.push.apply(t, o);
|
|
2839
|
-
}
|
|
2840
|
-
return t;
|
|
2841
|
-
}
|
|
2842
|
-
function _objectSpread$9(e) {
|
|
2843
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
2844
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
2845
|
-
r % 2 ? ownKeys$9(Object(t), true).forEach(function(r2) {
|
|
2846
|
-
_defineProperty(e, r2, t[r2]);
|
|
2847
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$9(Object(t)).forEach(function(r2) {
|
|
2848
|
-
Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
|
|
2849
|
-
});
|
|
2850
|
-
}
|
|
2851
|
-
return e;
|
|
2852
|
-
}
|
|
2853
|
-
var Transforms = _objectSpread$9(_objectSpread$9(_objectSpread$9(_objectSpread$9({}, GeneralTransforms), NodeTransforms), SelectionTransforms), TextTransforms);
|
|
202
|
+
var import_platejs6 = require("platejs");
|
|
2854
203
|
|
|
2855
204
|
// src/react/ai/utils/findTextRangeInBlock.tsx
|
|
205
|
+
var import_fastest_levenshtein = require("fastest-levenshtein");
|
|
206
|
+
var import_platejs5 = require("platejs");
|
|
2856
207
|
function maxAllowedDistance(len) {
|
|
2857
208
|
if (len <= 2) return 0;
|
|
2858
209
|
if (len <= 5) return 1;
|
|
@@ -2867,7 +218,7 @@ function findTextRangeInBlock({
|
|
|
2867
218
|
const [blockNode, blockPath] = block;
|
|
2868
219
|
const textSegments = [];
|
|
2869
220
|
let fullText = "";
|
|
2870
|
-
for (const [textNode, textPath] of
|
|
221
|
+
for (const [textNode, textPath] of import_platejs5.NodeApi.texts(blockNode)) {
|
|
2871
222
|
const startOffset = fullText.length;
|
|
2872
223
|
const absolutePath = [...blockPath, ...textPath];
|
|
2873
224
|
textSegments.push({
|
|
@@ -2970,7 +321,7 @@ var aiCommentToRange = (editor, aiComment) => {
|
|
|
2970
321
|
if (!currentBlock) return;
|
|
2971
322
|
const range = findTextRangeInBlock({
|
|
2972
323
|
block: currentBlock,
|
|
2973
|
-
findText:
|
|
324
|
+
findText: import_platejs6.NodeApi.string(node)
|
|
2974
325
|
});
|
|
2975
326
|
if (!range) return;
|
|
2976
327
|
ranges.push(range);
|
|
@@ -2991,19 +342,19 @@ var aiCommentToRange = (editor, aiComment) => {
|
|
|
2991
342
|
|
|
2992
343
|
// src/react/ai-chat/AIChatPlugin.ts
|
|
2993
344
|
var import_react9 = require("@platejs/selection/react");
|
|
2994
|
-
var
|
|
345
|
+
var import_platejs14 = require("platejs");
|
|
2995
346
|
var import_react10 = require("platejs/react");
|
|
2996
347
|
|
|
2997
348
|
// src/react/ai-chat/transforms/acceptAIChat.ts
|
|
2998
349
|
var import_suggestion2 = require("@platejs/suggestion");
|
|
2999
350
|
var import_react2 = require("@platejs/suggestion/react");
|
|
3000
|
-
var
|
|
351
|
+
var import_platejs7 = require("platejs");
|
|
3001
352
|
var import_react3 = require("platejs/react");
|
|
3002
353
|
var acceptAIChat = (editor) => {
|
|
3003
354
|
const mode = editor.getOption(AIChatPlugin, "mode");
|
|
3004
355
|
if (mode === "insert") {
|
|
3005
356
|
const { tf } = (0, import_react3.getEditorPlugin)(editor, AIPlugin);
|
|
3006
|
-
const api = editor.getApi({ key:
|
|
357
|
+
const api = editor.getApi({ key: import_platejs7.KEYS.ai });
|
|
3007
358
|
const lastAINodePath = api.aiChat.node({ at: [], reverse: true })[1];
|
|
3008
359
|
withAIBatch(editor, () => {
|
|
3009
360
|
tf.ai.removeMarks();
|
|
@@ -3050,12 +401,12 @@ var acceptSuggestions = (editor) => {
|
|
|
3050
401
|
// src/react/ai-chat/transforms/insertBelowAIChat.ts
|
|
3051
402
|
var import_react5 = require("@platejs/selection/react");
|
|
3052
403
|
var import_cloneDeep2 = __toESM(require("lodash/cloneDeep.js"));
|
|
3053
|
-
var
|
|
404
|
+
var import_platejs9 = require("platejs");
|
|
3054
405
|
|
|
3055
406
|
// src/react/ai-chat/transforms/replaceSelectionAIChat.ts
|
|
3056
407
|
var import_react4 = require("@platejs/selection/react");
|
|
3057
408
|
var import_cloneDeep = __toESM(require("lodash/cloneDeep.js"));
|
|
3058
|
-
var
|
|
409
|
+
var import_platejs8 = require("platejs");
|
|
3059
410
|
var createFormattedBlocks = ({
|
|
3060
411
|
blocks,
|
|
3061
412
|
format,
|
|
@@ -3063,12 +414,12 @@ var createFormattedBlocks = ({
|
|
|
3063
414
|
}) => {
|
|
3064
415
|
if (format === "none") return (0, import_cloneDeep.default)(blocks);
|
|
3065
416
|
const [sourceNode] = sourceBlock;
|
|
3066
|
-
const firstTextEntry =
|
|
417
|
+
const firstTextEntry = import_platejs8.NodeApi.firstText(sourceNode);
|
|
3067
418
|
if (!firstTextEntry) return null;
|
|
3068
|
-
const blockProps =
|
|
3069
|
-
const textProps =
|
|
419
|
+
const blockProps = import_platejs8.NodeApi.extractProps(sourceNode);
|
|
420
|
+
const textProps = import_platejs8.NodeApi.extractProps(firstTextEntry[0]);
|
|
3070
421
|
const applyTextFormatting = (node) => {
|
|
3071
|
-
if (
|
|
422
|
+
if (import_platejs8.TextApi.isText(node)) {
|
|
3072
423
|
return { ...textProps, ...node };
|
|
3073
424
|
}
|
|
3074
425
|
if (node.children) {
|
|
@@ -3095,7 +446,7 @@ var replaceSelectionAIChat = (editor, sourceEditor, { format = "single" } = {})
|
|
|
3095
446
|
import_react4.BlockSelectionPlugin,
|
|
3096
447
|
"isSelectingSome"
|
|
3097
448
|
);
|
|
3098
|
-
editor.getApi({ key:
|
|
449
|
+
editor.getApi({ key: import_platejs8.KEYS.ai }).aiChat.hide();
|
|
3099
450
|
if (!isBlockSelecting) {
|
|
3100
451
|
const firstBlock = editor.api.node({
|
|
3101
452
|
block: true,
|
|
@@ -3108,7 +459,7 @@ var replaceSelectionAIChat = (editor, sourceEditor, { format = "single" } = {})
|
|
|
3108
459
|
sourceBlock: firstBlock
|
|
3109
460
|
});
|
|
3110
461
|
if (!formattedBlocks2) return;
|
|
3111
|
-
if (firstBlock[0].type ===
|
|
462
|
+
if (firstBlock[0].type === import_platejs8.KEYS.codeLine && sourceEditor.children[0].type === import_platejs8.KEYS.codeBlock && sourceEditor.children.length === 1) {
|
|
3112
463
|
editor.tf.insertFragment(formattedBlocks2[0].children);
|
|
3113
464
|
} else {
|
|
3114
465
|
editor.tf.insertFragment(formattedBlocks2);
|
|
@@ -3168,7 +519,7 @@ var insertBelowAIChat = (editor, sourceEditor, { format = "single" } = {}) => {
|
|
|
3168
519
|
if (!selectedIds || selectedIds.size === 0) return;
|
|
3169
520
|
const lastBlock = selectedBlocks.at(-1);
|
|
3170
521
|
if (!lastBlock) return;
|
|
3171
|
-
const nextPath =
|
|
522
|
+
const nextPath = import_platejs9.PathApi.next(lastBlock[1]);
|
|
3172
523
|
const nodes = selectedBlocks.map((block) => block[0]);
|
|
3173
524
|
insertBlocksAndSelect(nodes, {
|
|
3174
525
|
at: nextPath,
|
|
@@ -3186,7 +537,7 @@ var insertBelowGenerate = (editor, sourceEditor, { format = "single" } = {}) =>
|
|
|
3186
537
|
import_react5.BlockSelectionPlugin,
|
|
3187
538
|
"isSelectingSome"
|
|
3188
539
|
);
|
|
3189
|
-
editor.getApi({ key:
|
|
540
|
+
editor.getApi({ key: import_platejs9.KEYS.ai }).aiChat.hide();
|
|
3190
541
|
const insertBlocksAndSelect = editor.getTransforms(import_react5.BlockSelectionPlugin).blockSelection.insertBlocksAndSelect;
|
|
3191
542
|
if (isBlockSelecting) {
|
|
3192
543
|
const selectedBlocks = editor.getApi(import_react5.BlockSelectionPlugin).blockSelection.getNodes();
|
|
@@ -3194,7 +545,7 @@ var insertBelowGenerate = (editor, sourceEditor, { format = "single" } = {}) =>
|
|
|
3194
545
|
if (!selectedIds || selectedIds.size === 0) return;
|
|
3195
546
|
const lastBlock = selectedBlocks.at(-1);
|
|
3196
547
|
if (!lastBlock) return;
|
|
3197
|
-
const nextPath =
|
|
548
|
+
const nextPath = import_platejs9.PathApi.next(lastBlock[1]);
|
|
3198
549
|
if (format === "none") {
|
|
3199
550
|
insertBlocksAndSelect((0, import_cloneDeep2.default)(sourceEditor.children), {
|
|
3200
551
|
at: nextPath
|
|
@@ -3211,7 +562,7 @@ var insertBelowGenerate = (editor, sourceEditor, { format = "single" } = {}) =>
|
|
|
3211
562
|
at: nextPath
|
|
3212
563
|
});
|
|
3213
564
|
} else {
|
|
3214
|
-
const [, end] =
|
|
565
|
+
const [, end] = import_platejs9.RangeApi.edges(editor.selection);
|
|
3215
566
|
const endPath = [end.path[0]];
|
|
3216
567
|
const currentBlock = editor.api.node({
|
|
3217
568
|
at: endPath,
|
|
@@ -3221,7 +572,7 @@ var insertBelowGenerate = (editor, sourceEditor, { format = "single" } = {}) =>
|
|
|
3221
572
|
if (!currentBlock) return;
|
|
3222
573
|
if (format === "none") {
|
|
3223
574
|
insertBlocksAndSelect((0, import_cloneDeep2.default)(sourceEditor.children), {
|
|
3224
|
-
at:
|
|
575
|
+
at: import_platejs9.PathApi.next(endPath)
|
|
3225
576
|
});
|
|
3226
577
|
return;
|
|
3227
578
|
}
|
|
@@ -3232,31 +583,31 @@ var insertBelowGenerate = (editor, sourceEditor, { format = "single" } = {}) =>
|
|
|
3232
583
|
});
|
|
3233
584
|
if (!formattedBlocks) return;
|
|
3234
585
|
insertBlocksAndSelect(formattedBlocks, {
|
|
3235
|
-
at:
|
|
586
|
+
at: import_platejs9.PathApi.next(endPath)
|
|
3236
587
|
});
|
|
3237
588
|
}
|
|
3238
589
|
};
|
|
3239
590
|
|
|
3240
591
|
// src/react/ai-chat/transforms/removeAnchorAIChat.ts
|
|
3241
|
-
var
|
|
592
|
+
var import_platejs10 = require("platejs");
|
|
3242
593
|
var removeAnchorAIChat = (editor, options) => {
|
|
3243
594
|
editor.tf.withoutSaving(() => {
|
|
3244
595
|
editor.tf.removeNodes({
|
|
3245
596
|
at: [],
|
|
3246
|
-
match: (n) =>
|
|
597
|
+
match: (n) => import_platejs10.ElementApi.isElement(n) && n.type === (0, import_platejs10.getPluginType)(editor, import_platejs10.KEYS.aiChat),
|
|
3247
598
|
...options
|
|
3248
599
|
});
|
|
3249
600
|
});
|
|
3250
601
|
};
|
|
3251
602
|
|
|
3252
603
|
// src/react/ai-chat/utils/resetAIChat.ts
|
|
3253
|
-
var
|
|
604
|
+
var import_platejs11 = require("platejs");
|
|
3254
605
|
var import_react6 = require("platejs/react");
|
|
3255
|
-
var resetAIChat = (editor) => {
|
|
606
|
+
var resetAIChat = (editor, { undo = true } = {}) => {
|
|
3256
607
|
const { api, getOptions, setOptions } = (0, import_react6.getEditorPlugin)(
|
|
3257
608
|
editor,
|
|
3258
609
|
{
|
|
3259
|
-
key:
|
|
610
|
+
key: import_platejs11.KEYS.aiChat
|
|
3260
611
|
}
|
|
3261
612
|
);
|
|
3262
613
|
api.aiChat.stop();
|
|
@@ -3270,13 +621,15 @@ var resetAIChat = (editor) => {
|
|
|
3270
621
|
mode: "insert",
|
|
3271
622
|
toolName: "generate"
|
|
3272
623
|
});
|
|
3273
|
-
|
|
624
|
+
if (undo) {
|
|
625
|
+
editor.getTransforms(AIPlugin).ai.undo();
|
|
626
|
+
}
|
|
3274
627
|
};
|
|
3275
628
|
|
|
3276
629
|
// src/react/ai-chat/utils/submitAIChat.ts
|
|
3277
630
|
var import_selection2 = require("@platejs/selection");
|
|
3278
631
|
var import_react7 = require("@platejs/selection/react");
|
|
3279
|
-
var
|
|
632
|
+
var import_platejs12 = require("platejs");
|
|
3280
633
|
var import_react8 = require("platejs/react");
|
|
3281
634
|
var submitAIChat = (editor, input, {
|
|
3282
635
|
mode,
|
|
@@ -3287,7 +640,7 @@ var submitAIChat = (editor, input, {
|
|
|
3287
640
|
const { getOptions, setOption } = (0, import_react8.getEditorPlugin)(
|
|
3288
641
|
editor,
|
|
3289
642
|
{
|
|
3290
|
-
key:
|
|
643
|
+
key: import_platejs12.KEYS.aiChat
|
|
3291
644
|
}
|
|
3292
645
|
);
|
|
3293
646
|
const { chat } = getOptions();
|
|
@@ -3333,7 +686,7 @@ var submitAIChat = (editor, input, {
|
|
|
3333
686
|
};
|
|
3334
687
|
|
|
3335
688
|
// src/react/ai-chat/withAIChat.ts
|
|
3336
|
-
var
|
|
689
|
+
var import_platejs13 = require("platejs");
|
|
3337
690
|
var withAIChat = ({
|
|
3338
691
|
api,
|
|
3339
692
|
editor,
|
|
@@ -3375,11 +728,11 @@ var withAIChat = ({
|
|
|
3375
728
|
},
|
|
3376
729
|
normalizeNode(entry) {
|
|
3377
730
|
const [node, path] = entry;
|
|
3378
|
-
if (node[
|
|
731
|
+
if (node[import_platejs13.KEYS.ai] && !getOptions().open) {
|
|
3379
732
|
tf.ai.removeMarks({ at: path });
|
|
3380
733
|
return;
|
|
3381
734
|
}
|
|
3382
|
-
if (
|
|
735
|
+
if (import_platejs13.ElementApi.isElement(node) && node.type === type && !getOptions().open) {
|
|
3383
736
|
editor.getTransforms(AIChatPlugin).aiChat.removeAnchor({ at: path });
|
|
3384
737
|
return;
|
|
3385
738
|
}
|
|
@@ -3391,7 +744,7 @@ var withAIChat = ({
|
|
|
3391
744
|
|
|
3392
745
|
// src/react/ai-chat/AIChatPlugin.ts
|
|
3393
746
|
var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
|
|
3394
|
-
key:
|
|
747
|
+
key: import_platejs14.KEYS.aiChat,
|
|
3395
748
|
dependencies: ["ai"],
|
|
3396
749
|
node: {
|
|
3397
750
|
isElement: true
|
|
@@ -3415,14 +768,14 @@ var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
|
|
|
3415
768
|
}
|
|
3416
769
|
}).overrideEditor(withAIChat).extendApi(({ editor, getOption, getOptions, setOption, type }) => {
|
|
3417
770
|
return {
|
|
3418
|
-
reset: (0,
|
|
3419
|
-
submit: (0,
|
|
771
|
+
reset: (0, import_platejs14.bindFirst)(resetAIChat, editor),
|
|
772
|
+
submit: (0, import_platejs14.bindFirst)(submitAIChat, editor),
|
|
3420
773
|
node: (options = {}) => {
|
|
3421
774
|
const { anchor = false, streaming = false, ...rest } = options;
|
|
3422
775
|
if (anchor) {
|
|
3423
776
|
return editor.api.node({
|
|
3424
777
|
at: [],
|
|
3425
|
-
match: (n) =>
|
|
778
|
+
match: (n) => import_platejs14.ElementApi.isElement(n) && n.type === type,
|
|
3426
779
|
...rest
|
|
3427
780
|
});
|
|
3428
781
|
}
|
|
@@ -3434,12 +787,12 @@ var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
|
|
|
3434
787
|
at: path,
|
|
3435
788
|
mode: "lowest",
|
|
3436
789
|
reverse: true,
|
|
3437
|
-
match: (t) => !!t[(0,
|
|
790
|
+
match: (t) => !!t[(0, import_platejs14.getPluginType)(editor, import_platejs14.KEYS.ai)],
|
|
3438
791
|
...rest
|
|
3439
792
|
});
|
|
3440
793
|
}
|
|
3441
794
|
return editor.api.node({
|
|
3442
|
-
match: (n) => n[(0,
|
|
795
|
+
match: (n) => n[(0, import_platejs14.getPluginType)(editor, import_platejs14.KEYS.ai)],
|
|
3443
796
|
...rest
|
|
3444
797
|
});
|
|
3445
798
|
},
|
|
@@ -3470,8 +823,11 @@ var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
|
|
|
3470
823
|
}
|
|
3471
824
|
};
|
|
3472
825
|
}).extendApi(({ api, editor, getOptions, setOption, tf, type }) => ({
|
|
3473
|
-
hide: ({
|
|
3474
|
-
|
|
826
|
+
hide: ({
|
|
827
|
+
focus = true,
|
|
828
|
+
undo = true
|
|
829
|
+
} = {}) => {
|
|
830
|
+
api.aiChat.reset({ undo });
|
|
3475
831
|
setOption("open", false);
|
|
3476
832
|
if (focus) {
|
|
3477
833
|
if (editor.getOption(import_react9.BlockSelectionPlugin, "isSelectingSome")) {
|
|
@@ -3493,10 +849,10 @@ var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
|
|
|
3493
849
|
setOption("open", true);
|
|
3494
850
|
}
|
|
3495
851
|
})).extendTransforms(({ editor }) => ({
|
|
3496
|
-
accept: (0,
|
|
3497
|
-
insertBelow: (0,
|
|
3498
|
-
removeAnchor: (0,
|
|
3499
|
-
replaceSelection: (0,
|
|
852
|
+
accept: (0, import_platejs14.bindFirst)(acceptAIChat, editor),
|
|
853
|
+
insertBelow: (0, import_platejs14.bindFirst)(insertBelowAIChat, editor),
|
|
854
|
+
removeAnchor: (0, import_platejs14.bindFirst)(removeAnchorAIChat, editor),
|
|
855
|
+
replaceSelection: (0, import_platejs14.bindFirst)(replaceSelectionAIChat, editor)
|
|
3500
856
|
}));
|
|
3501
857
|
|
|
3502
858
|
// src/react/ai-chat/hooks/useAIChatEditor.ts
|
|
@@ -3522,7 +878,7 @@ var useAIChatEditor = (editor, content, { parser } = {}) => {
|
|
|
3522
878
|
|
|
3523
879
|
// src/react/ai-chat/hooks/useChatChunk.ts
|
|
3524
880
|
var import_react14 = require("react");
|
|
3525
|
-
var
|
|
881
|
+
var import_platejs15 = require("platejs");
|
|
3526
882
|
var import_react15 = require("platejs/react");
|
|
3527
883
|
|
|
3528
884
|
// src/react/ai-chat/utils/getLastAssistantMessage.ts
|
|
@@ -3544,7 +900,7 @@ var useChatChunk = ({
|
|
|
3544
900
|
onFinish
|
|
3545
901
|
}) => {
|
|
3546
902
|
const { status } = (0, import_react15.usePluginOption)(
|
|
3547
|
-
{ key:
|
|
903
|
+
{ key: import_platejs15.KEYS.aiChat },
|
|
3548
904
|
"chat"
|
|
3549
905
|
);
|
|
3550
906
|
const isLoading = status === "streaming" || status === "submitted";
|
|
@@ -3629,7 +985,7 @@ var streamDeserializeInlineMd = (editor, text, options) => {
|
|
|
3629
985
|
|
|
3630
986
|
// src/react/ai-chat/streaming/streamDeserializeMd.ts
|
|
3631
987
|
var import_markdown4 = require("@platejs/markdown");
|
|
3632
|
-
var
|
|
988
|
+
var import_platejs18 = require("platejs");
|
|
3633
989
|
|
|
3634
990
|
// src/react/ai-chat/streaming/utils/utils.ts
|
|
3635
991
|
var getChunkTrimmed = (chunk, {
|
|
@@ -3684,22 +1040,22 @@ var getListNode = (editor, node) => {
|
|
|
3684
1040
|
};
|
|
3685
1041
|
|
|
3686
1042
|
// src/react/ai-chat/streaming/utils/isSameNode.ts
|
|
3687
|
-
var
|
|
1043
|
+
var import_platejs16 = require("platejs");
|
|
3688
1044
|
var LIST_STYLE_TYPE = "listStyleType";
|
|
3689
1045
|
var isSameNode = (editor, node1, node2) => {
|
|
3690
|
-
if (node1.type !== editor.getType(
|
|
1046
|
+
if (node1.type !== editor.getType(import_platejs16.KEYS.p) || node2.type !== editor.getType(import_platejs16.KEYS.p))
|
|
3691
1047
|
return node1.type === node2.type;
|
|
3692
|
-
if ((0,
|
|
1048
|
+
if ((0, import_platejs16.isDefined)(node1[LIST_STYLE_TYPE]) || (0, import_platejs16.isDefined)(node2[LIST_STYLE_TYPE])) {
|
|
3693
1049
|
return node1[LIST_STYLE_TYPE] === node2[LIST_STYLE_TYPE];
|
|
3694
1050
|
}
|
|
3695
1051
|
return node1.type === node2.type;
|
|
3696
1052
|
};
|
|
3697
1053
|
|
|
3698
1054
|
// src/react/ai-chat/streaming/utils/nodesWithProps.ts
|
|
3699
|
-
var
|
|
1055
|
+
var import_platejs17 = require("platejs");
|
|
3700
1056
|
var nodesWithProps = (editor, nodes, options) => {
|
|
3701
1057
|
return nodes.map((node) => {
|
|
3702
|
-
if (
|
|
1058
|
+
if (import_platejs17.ElementApi.isElement(node)) {
|
|
3703
1059
|
return {
|
|
3704
1060
|
...getListNode(editor, node),
|
|
3705
1061
|
...options.elementProps,
|
|
@@ -3739,7 +1095,7 @@ var streamDeserializeMd = (editor, data, options) => {
|
|
|
3739
1095
|
}
|
|
3740
1096
|
];
|
|
3741
1097
|
const lastChild = lastBlock.children.at(-1);
|
|
3742
|
-
if (lastChild &&
|
|
1098
|
+
if (lastChild && import_platejs18.TextApi.isText(lastChild) && Object.keys(lastChild).length === 1) {
|
|
3743
1099
|
lastBlock.children.pop();
|
|
3744
1100
|
const textNode2 = [
|
|
3745
1101
|
{
|
|
@@ -3755,13 +1111,13 @@ var streamDeserializeMd = (editor, data, options) => {
|
|
|
3755
1111
|
if (addNewLine && !isCodeBlockOrTable) {
|
|
3756
1112
|
result.push({
|
|
3757
1113
|
children: [{ text: "" }],
|
|
3758
|
-
type:
|
|
1114
|
+
type: import_platejs18.KEYS.p
|
|
3759
1115
|
});
|
|
3760
1116
|
}
|
|
3761
1117
|
if (unshiftNewLine && !isCodeBlockOrTable) {
|
|
3762
1118
|
result.unshift({
|
|
3763
1119
|
children: [{ text: "" }],
|
|
3764
|
-
type:
|
|
1120
|
+
type: import_platejs18.KEYS.p
|
|
3765
1121
|
});
|
|
3766
1122
|
}
|
|
3767
1123
|
return result;
|
|
@@ -3781,7 +1137,7 @@ var withoutDeserializeInMdx = (editor, input) => {
|
|
|
3781
1137
|
text: input
|
|
3782
1138
|
}
|
|
3783
1139
|
],
|
|
3784
|
-
type: (0,
|
|
1140
|
+
type: (0, import_platejs18.getPluginType)(editor, import_platejs18.KEYS.p)
|
|
3785
1141
|
}
|
|
3786
1142
|
];
|
|
3787
1143
|
}
|
|
@@ -3794,26 +1150,26 @@ var withoutDeserializeInMdx = (editor, input) => {
|
|
|
3794
1150
|
};
|
|
3795
1151
|
|
|
3796
1152
|
// src/react/ai-chat/streaming/streamInsertChunk.ts
|
|
3797
|
-
var
|
|
1153
|
+
var import_platejs20 = require("platejs");
|
|
3798
1154
|
|
|
3799
1155
|
// src/react/ai-chat/streaming/streamSerializeMd.ts
|
|
3800
1156
|
var import_markdown5 = require("@platejs/markdown");
|
|
3801
|
-
var
|
|
1157
|
+
var import_platejs19 = require("platejs");
|
|
3802
1158
|
var trimEndHeading = (editor, value) => {
|
|
3803
1159
|
const headingKeys = /* @__PURE__ */ new Set([
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
1160
|
+
import_platejs19.KEYS.h1,
|
|
1161
|
+
import_platejs19.KEYS.h2,
|
|
1162
|
+
import_platejs19.KEYS.h3,
|
|
1163
|
+
import_platejs19.KEYS.h4,
|
|
1164
|
+
import_platejs19.KEYS.h5,
|
|
1165
|
+
import_platejs19.KEYS.h6
|
|
3810
1166
|
]);
|
|
3811
1167
|
const lastBlock = value.at(-1);
|
|
3812
1168
|
if (lastBlock && headingKeys.has(
|
|
3813
|
-
(0,
|
|
3814
|
-
) &&
|
|
1169
|
+
(0, import_platejs19.getPluginKey)(editor, lastBlock.type) ?? lastBlock.type
|
|
1170
|
+
) && import_platejs19.ElementApi.isElement(lastBlock)) {
|
|
3815
1171
|
const lastTextNode = lastBlock.children.at(-1);
|
|
3816
|
-
if (
|
|
1172
|
+
if (import_platejs19.TextApi.isText(lastTextNode)) {
|
|
3817
1173
|
const trimmedText = getChunkTrimmed(lastTextNode?.text);
|
|
3818
1174
|
const newChildren = [
|
|
3819
1175
|
...lastBlock.children.slice(0, -1),
|
|
@@ -3867,7 +1223,7 @@ var streamSerializeMd = (editor, options, chunk) => {
|
|
|
3867
1223
|
var getNextPath = (path, length) => {
|
|
3868
1224
|
let result = path;
|
|
3869
1225
|
for (let i = 0; i < length; i++) {
|
|
3870
|
-
result =
|
|
1226
|
+
result = import_platejs20.PathApi.next(result);
|
|
3871
1227
|
}
|
|
3872
1228
|
return result;
|
|
3873
1229
|
};
|
|
@@ -3877,7 +1233,7 @@ function streamInsertChunk(editor, chunk, options = {}) {
|
|
|
3877
1233
|
const blocks = streamDeserializeMd(editor, chunk);
|
|
3878
1234
|
const path = getCurrentBlockPath(editor);
|
|
3879
1235
|
const startBlock = editor.api.node(path)[0];
|
|
3880
|
-
const startInEmptyParagraph =
|
|
1236
|
+
const startInEmptyParagraph = import_platejs20.NodeApi.string(startBlock).length === 0 && startBlock.type === (0, import_platejs20.getPluginType)(editor, import_platejs20.KEYS.p);
|
|
3881
1237
|
if (startInEmptyParagraph) {
|
|
3882
1238
|
editor.tf.removeNodes({ at: path });
|
|
3883
1239
|
}
|
|
@@ -3935,7 +1291,7 @@ function streamInsertChunk(editor, chunk, options = {}) {
|
|
|
3935
1291
|
},
|
|
3936
1292
|
tempBlockChunks
|
|
3937
1293
|
);
|
|
3938
|
-
const blockText =
|
|
1294
|
+
const blockText = import_platejs20.NodeApi.string(tempBlocks[0]);
|
|
3939
1295
|
if (serializedBlock === tempBlockChunks && blockText === serializedBlock) {
|
|
3940
1296
|
editor.setOption(AIChatPlugin, "_blockChunks", tempBlockChunks);
|
|
3941
1297
|
} else {
|
|
@@ -3957,7 +1313,7 @@ function streamInsertChunk(editor, chunk, options = {}) {
|
|
|
3957
1313
|
AIChatPlugin,
|
|
3958
1314
|
"_blockChunks",
|
|
3959
1315
|
// one block includes multiple children
|
|
3960
|
-
tempBlocks[0].type === (0,
|
|
1316
|
+
tempBlocks[0].type === (0, import_platejs20.getPluginType)(editor, import_platejs20.KEYS.codeBlock) || tempBlocks[0].type === (0, import_platejs20.getPluginType)(editor, import_platejs20.KEYS.table) || tempBlocks[0].type === (0, import_platejs20.getPluginType)(editor, import_platejs20.KEYS.equation) ? tempBlockChunks : serializedBlock2
|
|
3961
1317
|
);
|
|
3962
1318
|
}
|
|
3963
1319
|
} else {
|
|
@@ -3987,7 +1343,7 @@ function streamInsertChunk(editor, chunk, options = {}) {
|
|
|
3987
1343
|
editor.tf.insertNodes(
|
|
3988
1344
|
nodesWithProps(editor, tempBlocks.slice(1), options),
|
|
3989
1345
|
{
|
|
3990
|
-
at:
|
|
1346
|
+
at: import_platejs20.PathApi.next(_blockPath),
|
|
3991
1347
|
select: true
|
|
3992
1348
|
}
|
|
3993
1349
|
);
|
|
@@ -4009,7 +1365,7 @@ var getCurrentBlockPath = (editor) => {
|
|
|
4009
1365
|
const getAnchorPreviousPath = (editor2) => {
|
|
4010
1366
|
const anchorNode = editor2.getApi(AIChatPlugin).aiChat.node({ anchor: true });
|
|
4011
1367
|
if (anchorNode) {
|
|
4012
|
-
return
|
|
1368
|
+
return import_platejs20.PathApi.previous(anchorNode[1]);
|
|
4013
1369
|
}
|
|
4014
1370
|
};
|
|
4015
1371
|
const getFocusPath = (editor2) => {
|
|
@@ -4017,7 +1373,7 @@ var getCurrentBlockPath = (editor) => {
|
|
|
4017
1373
|
};
|
|
4018
1374
|
const path = getAnchorPreviousPath(editor) ?? getFocusPath(editor) ?? [0];
|
|
4019
1375
|
const entry = editor.api.node(path);
|
|
4020
|
-
if (entry && (entry[0].type === (0,
|
|
1376
|
+
if (entry && (entry[0].type === (0, import_platejs20.getPluginType)(editor, import_platejs20.KEYS.columnGroup) || entry[0].type === (0, import_platejs20.getPluginType)(editor, import_platejs20.KEYS.table))) {
|
|
4021
1377
|
return editor.api.above()?.[1] ?? path;
|
|
4022
1378
|
}
|
|
4023
1379
|
return path;
|
|
@@ -4027,7 +1383,7 @@ var getCurrentBlockPath = (editor) => {
|
|
|
4027
1383
|
var import_markdown6 = require("@platejs/markdown");
|
|
4028
1384
|
var import_react19 = require("@platejs/selection/react");
|
|
4029
1385
|
var import_suggestion3 = require("@platejs/suggestion");
|
|
4030
|
-
var
|
|
1386
|
+
var import_platejs21 = require("platejs");
|
|
4031
1387
|
var applyAISuggestions = (editor, content) => {
|
|
4032
1388
|
const isBlockSelecting = editor.getOption(
|
|
4033
1389
|
import_react19.BlockSelectionPlugin,
|
|
@@ -4045,7 +1401,7 @@ var applyAISuggestions = (editor, content) => {
|
|
|
4045
1401
|
const replaceNodes = Array.from(
|
|
4046
1402
|
editor.api.nodes({
|
|
4047
1403
|
at: [],
|
|
4048
|
-
match: (n) =>
|
|
1404
|
+
match: (n) => import_platejs21.ElementApi.isElement(n) && editor.getOption(AIChatPlugin, "_replaceIds").includes(n.id)
|
|
4049
1405
|
})
|
|
4050
1406
|
);
|
|
4051
1407
|
replaceNodes.forEach(([node, path], index) => {
|
|
@@ -4053,48 +1409,49 @@ var applyAISuggestions = (editor, content) => {
|
|
|
4053
1409
|
const diffNode = diffNodes[index];
|
|
4054
1410
|
const isSameString = (0, import_suggestion3.SkipSuggestionDeletes)(editor, replaceNode) === (0, import_suggestion3.SkipSuggestionDeletes)(editor, diffNode);
|
|
4055
1411
|
const isSameSuggestion = replaceNode.suggestion?.type === diffNode.suggestion?.type;
|
|
4056
|
-
if (isSameString && isSameSuggestion && node.id == diffNode.id) {
|
|
4057
|
-
return;
|
|
4058
|
-
}
|
|
4059
1412
|
if (index === replaceNodes.length - 1 && diffNodes.length > replaceNodes.length) {
|
|
4060
1413
|
editor.tf.replaceNodes(diffNodes.slice(index), {
|
|
4061
1414
|
at: path
|
|
4062
1415
|
});
|
|
4063
|
-
} else {
|
|
4064
|
-
editor.tf.replaceNodes(diffNode, {
|
|
4065
|
-
at: path
|
|
4066
|
-
});
|
|
4067
1416
|
}
|
|
1417
|
+
if (isSameString && isSameSuggestion && node.id == diffNode.id) {
|
|
1418
|
+
return;
|
|
1419
|
+
}
|
|
1420
|
+
editor.tf.replaceNodes(diffNode, {
|
|
1421
|
+
at: path
|
|
1422
|
+
});
|
|
4068
1423
|
});
|
|
4069
1424
|
editor.getApi(import_react19.BlockSelectionPlugin).blockSelection.set(diffNodes.map((node) => node.id));
|
|
4070
1425
|
setReplaceIds(diffNodes.map((node) => node.id));
|
|
4071
1426
|
} else {
|
|
4072
1427
|
const diffNodes = getDiffNodes(editor, content);
|
|
4073
1428
|
editor.tf.insertFragment(diffNodes);
|
|
4074
|
-
const nodes =
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
1429
|
+
const nodes = Array.from(
|
|
1430
|
+
editor.api.nodes({
|
|
1431
|
+
at: [],
|
|
1432
|
+
mode: "lowest",
|
|
1433
|
+
match: (n) => import_platejs21.TextApi.isText(n) && !!n[(0, import_suggestion3.getTransientSuggestionKey)()]
|
|
1434
|
+
})
|
|
1435
|
+
);
|
|
1436
|
+
const range = editor.api.nodesRange(nodes);
|
|
4080
1437
|
editor.tf.setSelection(range);
|
|
4081
1438
|
return;
|
|
4082
1439
|
}
|
|
4083
1440
|
};
|
|
4084
1441
|
var withProps = (diffNodes, chatNodes) => {
|
|
4085
1442
|
return diffNodes.map((node, index) => {
|
|
4086
|
-
if (!
|
|
1443
|
+
if (!import_platejs21.ElementApi.isElement(node)) return node;
|
|
4087
1444
|
const originalNode = chatNodes?.[index];
|
|
4088
1445
|
return {
|
|
4089
1446
|
...node,
|
|
4090
|
-
...originalNode ?? { id: (0,
|
|
1447
|
+
...originalNode ?? { id: (0, import_platejs21.nanoid)() },
|
|
4091
1448
|
children: node.children
|
|
4092
1449
|
};
|
|
4093
1450
|
});
|
|
4094
1451
|
};
|
|
4095
1452
|
var withTransient = (diffNodes) => {
|
|
4096
1453
|
return diffNodes.map((node) => {
|
|
4097
|
-
if (
|
|
1454
|
+
if (import_platejs21.TextApi.isText(node)) {
|
|
4098
1455
|
return {
|
|
4099
1456
|
...node,
|
|
4100
1457
|
[(0, import_suggestion3.getTransientSuggestionKey)()]: true
|
|
@@ -4110,19 +1467,19 @@ var withTransient = (diffNodes) => {
|
|
|
4110
1467
|
};
|
|
4111
1468
|
var withoutSuggestionAndComments = (nodes) => {
|
|
4112
1469
|
return nodes.map((node) => {
|
|
4113
|
-
if (
|
|
4114
|
-
if (node[
|
|
1470
|
+
if (import_platejs21.TextApi.isText(node)) {
|
|
1471
|
+
if (node[import_platejs21.KEYS.suggestion] || node[import_platejs21.KEYS.comment]) {
|
|
4115
1472
|
return {
|
|
4116
1473
|
text: node.text
|
|
4117
1474
|
};
|
|
4118
1475
|
}
|
|
4119
1476
|
return node;
|
|
4120
1477
|
}
|
|
4121
|
-
if (
|
|
4122
|
-
if (node[
|
|
1478
|
+
if (import_platejs21.ElementApi.isElement(node)) {
|
|
1479
|
+
if (node[import_platejs21.KEYS.suggestion]) {
|
|
4123
1480
|
const nodeWithoutSuggestion = {};
|
|
4124
1481
|
Object.keys(node).forEach((key) => {
|
|
4125
|
-
if (key !==
|
|
1482
|
+
if (key !== import_platejs21.KEYS.suggestion && !key.startsWith(import_platejs21.KEYS.suggestion)) {
|
|
4126
1483
|
nodeWithoutSuggestion[key] = node[key];
|
|
4127
1484
|
}
|
|
4128
1485
|
});
|
|
@@ -4145,7 +1502,9 @@ var getDiffNodes = (editor, aiContent) => {
|
|
|
4145
1502
|
);
|
|
4146
1503
|
const aiNodes = withProps((0, import_markdown6.deserializeMd)(editor, aiContent), chatNodes);
|
|
4147
1504
|
const diffNodes = withTransient(
|
|
4148
|
-
(0, import_suggestion3.diffToSuggestions)(editor, chatNodes, aiNodes, {
|
|
1505
|
+
(0, import_suggestion3.diffToSuggestions)(editor, chatNodes, aiNodes, {
|
|
1506
|
+
ignoreProps: ["id", "listStart"]
|
|
1507
|
+
})
|
|
4149
1508
|
);
|
|
4150
1509
|
return diffNodes;
|
|
4151
1510
|
};
|
|
@@ -4153,18 +1512,18 @@ var getDiffNodes = (editor, aiContent) => {
|
|
|
4153
1512
|
// src/react/copilot/CopilotPlugin.tsx
|
|
4154
1513
|
var import_markdown10 = require("@platejs/markdown");
|
|
4155
1514
|
var import_debounce = __toESM(require("lodash/debounce.js"));
|
|
4156
|
-
var
|
|
1515
|
+
var import_platejs27 = require("platejs");
|
|
4157
1516
|
var import_react24 = require("platejs/react");
|
|
4158
1517
|
|
|
4159
1518
|
// src/react/copilot/renderCopilotBelowNodes.tsx
|
|
4160
1519
|
var import_react20 = __toESM(require("react"));
|
|
4161
|
-
var
|
|
1520
|
+
var import_platejs22 = require("platejs");
|
|
4162
1521
|
var import_react21 = require("platejs/react");
|
|
4163
1522
|
var renderCopilotBelowNodes = ({
|
|
4164
1523
|
editor
|
|
4165
1524
|
}) => {
|
|
4166
1525
|
const copilot = (0, import_react21.getEditorPlugin)(editor, {
|
|
4167
|
-
key:
|
|
1526
|
+
key: import_platejs22.KEYS.copilot
|
|
4168
1527
|
});
|
|
4169
1528
|
const { renderGhostText: GhostText } = copilot.getOptions();
|
|
4170
1529
|
if (!GhostText) return;
|
|
@@ -4175,10 +1534,10 @@ var renderCopilotBelowNodes = ({
|
|
|
4175
1534
|
|
|
4176
1535
|
// src/react/copilot/transforms/acceptCopilot.ts
|
|
4177
1536
|
var import_markdown7 = require("@platejs/markdown");
|
|
4178
|
-
var
|
|
1537
|
+
var import_platejs23 = require("platejs");
|
|
4179
1538
|
var acceptCopilot = (editor) => {
|
|
4180
1539
|
const { suggestionText } = editor.getOptions({
|
|
4181
|
-
key:
|
|
1540
|
+
key: import_platejs23.KEYS.copilot
|
|
4182
1541
|
});
|
|
4183
1542
|
if (!suggestionText?.length) return false;
|
|
4184
1543
|
editor.tf.insertFragment((0, import_markdown7.deserializeInlineMd)(editor, suggestionText));
|
|
@@ -4186,7 +1545,7 @@ var acceptCopilot = (editor) => {
|
|
|
4186
1545
|
|
|
4187
1546
|
// src/react/copilot/transforms/acceptCopilotNextWord.ts
|
|
4188
1547
|
var import_markdown8 = require("@platejs/markdown");
|
|
4189
|
-
var
|
|
1548
|
+
var import_platejs25 = require("platejs");
|
|
4190
1549
|
var import_react23 = require("platejs/react");
|
|
4191
1550
|
|
|
4192
1551
|
// src/react/copilot/utils/callCompletionApi.ts
|
|
@@ -4304,17 +1663,17 @@ var getNextWord = ({ text }) => {
|
|
|
4304
1663
|
};
|
|
4305
1664
|
|
|
4306
1665
|
// src/react/copilot/utils/triggerCopilotSuggestion.ts
|
|
4307
|
-
var
|
|
1666
|
+
var import_platejs24 = require("platejs");
|
|
4308
1667
|
var import_react22 = require("platejs/react");
|
|
4309
1668
|
var triggerCopilotSuggestion = async (editor) => {
|
|
4310
1669
|
const { api, getOptions, setOption } = (0, import_react22.getEditorPlugin)(
|
|
4311
1670
|
editor,
|
|
4312
1671
|
{
|
|
4313
|
-
key:
|
|
1672
|
+
key: import_platejs24.KEYS.copilot
|
|
4314
1673
|
}
|
|
4315
1674
|
);
|
|
4316
1675
|
const { completeOptions, getPrompt, isLoading, triggerQuery } = getOptions();
|
|
4317
|
-
if (isLoading || editor.getOptions({ key:
|
|
1676
|
+
if (isLoading || editor.getOptions({ key: import_platejs24.KEYS.aiChat }).chat?.isLoading) {
|
|
4318
1677
|
return false;
|
|
4319
1678
|
}
|
|
4320
1679
|
if (!triggerQuery({ editor })) return false;
|
|
@@ -4348,7 +1707,7 @@ var withoutAbort = (editor, fn) => {
|
|
|
4348
1707
|
// src/react/copilot/transforms/acceptCopilotNextWord.ts
|
|
4349
1708
|
var acceptCopilotNextWord = (editor) => {
|
|
4350
1709
|
const { api, getOptions } = (0, import_react23.getEditorPlugin)(editor, {
|
|
4351
|
-
key:
|
|
1710
|
+
key: import_platejs25.KEYS.copilot
|
|
4352
1711
|
});
|
|
4353
1712
|
const { getNextWord: getNextWord2, suggestionText } = getOptions();
|
|
4354
1713
|
if (!suggestionText?.length) {
|
|
@@ -4365,7 +1724,7 @@ var acceptCopilotNextWord = (editor) => {
|
|
|
4365
1724
|
|
|
4366
1725
|
// src/react/copilot/withCopilot.ts
|
|
4367
1726
|
var import_markdown9 = require("@platejs/markdown");
|
|
4368
|
-
var
|
|
1727
|
+
var import_platejs26 = require("platejs");
|
|
4369
1728
|
var getPatchString = (editor, operations) => {
|
|
4370
1729
|
let string = "";
|
|
4371
1730
|
for (const operation of operations) {
|
|
@@ -4427,7 +1786,7 @@ var withCopilot = ({
|
|
|
4427
1786
|
},
|
|
4428
1787
|
setSelection(props) {
|
|
4429
1788
|
setSelection(props);
|
|
4430
|
-
if (editor.selection && (!prevSelection || !
|
|
1789
|
+
if (editor.selection && (!prevSelection || !import_platejs26.RangeApi.equals(prevSelection, editor.selection)) && getOptions().autoTriggerQuery({ editor }) && editor.api.isFocused()) {
|
|
4431
1790
|
void api.copilot.triggerSuggestion();
|
|
4432
1791
|
}
|
|
4433
1792
|
prevSelection = editor.selection;
|
|
@@ -4462,7 +1821,7 @@ var withCopilot = ({
|
|
|
4462
1821
|
|
|
4463
1822
|
// src/react/copilot/CopilotPlugin.tsx
|
|
4464
1823
|
var CopilotPlugin = (0, import_react24.createTPlatePlugin)({
|
|
4465
|
-
key:
|
|
1824
|
+
key: import_platejs27.KEYS.copilot,
|
|
4466
1825
|
handlers: {
|
|
4467
1826
|
onBlur: ({ api }) => {
|
|
4468
1827
|
api.copilot.reject();
|
|
@@ -4484,14 +1843,14 @@ var CopilotPlugin = (0, import_react24.createTPlatePlugin)({
|
|
|
4484
1843
|
suggestionNodeId: null,
|
|
4485
1844
|
suggestionText: null,
|
|
4486
1845
|
autoTriggerQuery: ({ editor }) => {
|
|
4487
|
-
if (editor.getOptions({ key:
|
|
1846
|
+
if (editor.getOptions({ key: import_platejs27.KEYS.copilot }).suggestionText) {
|
|
4488
1847
|
return false;
|
|
4489
1848
|
}
|
|
4490
1849
|
const isEmpty = editor.api.isEmpty(editor.selection, { block: true });
|
|
4491
1850
|
if (isEmpty) return false;
|
|
4492
1851
|
const blockAbove = editor.api.block();
|
|
4493
1852
|
if (!blockAbove) return false;
|
|
4494
|
-
const blockString =
|
|
1853
|
+
const blockString = import_platejs27.NodeApi.string(blockAbove[0]);
|
|
4495
1854
|
return blockString.at(-1) === " ";
|
|
4496
1855
|
},
|
|
4497
1856
|
getPrompt: ({ editor }) => {
|
|
@@ -4511,15 +1870,15 @@ var CopilotPlugin = (0, import_react24.createTPlatePlugin)({
|
|
|
4511
1870
|
}).overrideEditor(withCopilot).extendSelectors(({ getOptions }) => ({
|
|
4512
1871
|
isSuggested: (id) => getOptions().suggestionNodeId === id
|
|
4513
1872
|
})).extendTransforms(({ editor }) => ({
|
|
4514
|
-
accept: (0,
|
|
4515
|
-
acceptNextWord: (0,
|
|
1873
|
+
accept: (0, import_platejs27.bindFirst)(acceptCopilot, editor),
|
|
1874
|
+
acceptNextWord: (0, import_platejs27.bindFirst)(acceptCopilotNextWord, editor)
|
|
4516
1875
|
})).extendApi(
|
|
4517
1876
|
({ api, editor, getOptions, setOption, setOptions }) => {
|
|
4518
1877
|
const debounceDelay = getOptions().debounceDelay;
|
|
4519
|
-
let triggerSuggestion = (0,
|
|
1878
|
+
let triggerSuggestion = (0, import_platejs27.bindFirst)(triggerCopilotSuggestion, editor);
|
|
4520
1879
|
if (debounceDelay) {
|
|
4521
1880
|
triggerSuggestion = (0, import_debounce.default)(
|
|
4522
|
-
(0,
|
|
1881
|
+
(0, import_platejs27.bindFirst)(triggerCopilotSuggestion, editor),
|
|
4523
1882
|
debounceDelay
|
|
4524
1883
|
);
|
|
4525
1884
|
}
|