slate-vue3 0.7.5 → 0.7.7

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.
@@ -303,246 +303,227 @@ const Path = {
303
303
  return p;
304
304
  }
305
305
  };
306
- const applyToDraft = (editor, selection, op) => {
307
- switch (op.type) {
308
- case "insert_node": {
309
- const { path, node } = op;
310
- const parent = Node.parent(editor, path);
311
- const index = path[path.length - 1];
312
- if (index > parent.children.length) {
313
- throw new Error(
314
- `Cannot apply an "insert_node" operation at path [${path}] because the destination is past the end of the node.`
315
- );
316
- }
317
- parent.children.splice(index, 0, node);
318
- if (selection) {
319
- for (const [point, key] of Range.points(selection)) {
320
- selection[key] = Point.transform(point, op);
321
- }
322
- }
323
- break;
324
- }
325
- case "insert_text": {
326
- const { path, offset, text } = op;
327
- if (text.length === 0) break;
328
- const node = Node.leaf(editor, path);
329
- const before = node.text.slice(0, offset);
330
- const after = node.text.slice(offset);
331
- node.text = before + text + after;
332
- if (selection) {
333
- for (const [point, key] of Range.points(selection)) {
334
- selection[key] = Point.transform(point, op);
306
+ const GeneralTransforms = {
307
+ transform(editor, op) {
308
+ let transformSelection = false;
309
+ switch (op.type) {
310
+ case "insert_node": {
311
+ const { path, node } = op;
312
+ const parent = Node.parent(editor, path);
313
+ const index = path[path.length - 1];
314
+ if (index > parent.children.length) {
315
+ throw new Error(
316
+ `Cannot apply an 'insert_node' operation at path [${path}] because the destination is past the end of the node.`
317
+ );
335
318
  }
319
+ parent.children.splice(index, 0, node);
320
+ transformSelection = true;
321
+ break;
336
322
  }
337
- break;
338
- }
339
- case "merge_node": {
340
- const { path } = op;
341
- const node = Node.get(editor, path);
342
- const prevPath = Path.previous(path);
343
- const prev = Node.get(editor, prevPath);
344
- const parent = Node.parent(editor, path);
345
- const index = path[path.length - 1];
346
- if (Text.isText(node) && Text.isText(prev)) {
347
- prev.text += node.text;
348
- } else if (!Text.isText(node) && !Text.isText(prev)) {
349
- prev.children.push(...node.children);
350
- } else {
351
- throw new Error(
352
- `Cannot apply a "merge_node" operation at path [${path}] to nodes of different interfaces: ${Scrubber.stringify(
353
- node
354
- )} ${Scrubber.stringify(prev)}`
355
- );
323
+ case "insert_text": {
324
+ const { path, offset, text } = op;
325
+ if (text.length === 0) break;
326
+ const node = Node.leaf(editor, path);
327
+ const before = node.text.slice(0, offset);
328
+ const after = node.text.slice(offset);
329
+ node.text = before + text + after;
330
+ transformSelection = true;
331
+ break;
356
332
  }
357
- parent.children.splice(index, 1);
358
- if (selection) {
359
- for (const [point, key] of Range.points(selection)) {
360
- selection[key] = Point.transform(point, op);
333
+ case "merge_node": {
334
+ const { path } = op;
335
+ const node = Node.get(editor, path);
336
+ const prevPath = Path.previous(path);
337
+ const prev = Node.get(editor, prevPath);
338
+ const parent = Node.parent(editor, path);
339
+ const index = path[path.length - 1];
340
+ if (Text.isText(node) && Text.isText(prev)) {
341
+ prev.text += node.text;
342
+ } else if (!Text.isText(node) && !Text.isText(prev)) {
343
+ prev.children.push(...node.children);
344
+ } else {
345
+ throw new Error(
346
+ `Cannot apply a 'merge_node' operation at path [${path}] to nodes of different interfaces: ${Scrubber.stringify(
347
+ node
348
+ )} ${Scrubber.stringify(prev)}`
349
+ );
361
350
  }
351
+ parent.children.splice(index, 1);
352
+ transformSelection = true;
353
+ break;
362
354
  }
363
- break;
364
- }
365
- case "move_node": {
366
- const { path, newPath } = op;
367
- if (Path.isAncestor(path, newPath)) {
368
- throw new Error(
369
- `Cannot move a path [${path}] to new path [${newPath}] because the destination is inside itself.`
370
- );
371
- }
372
- const node = Node.get(editor, path);
373
- const parent = Node.parent(editor, path);
374
- const index = path[path.length - 1];
375
- parent.children.splice(index, 1);
376
- const truePath = Path.transform(path, op);
377
- const newParent = Node.get(editor, Path.parent(truePath));
378
- const newIndex = truePath[truePath.length - 1];
379
- newParent.children.splice(newIndex, 0, node);
380
- if (selection) {
381
- for (const [point, key] of Range.points(selection)) {
382
- selection[key] = Point.transform(point, op);
355
+ case "move_node": {
356
+ const { path, newPath } = op;
357
+ if (Path.isAncestor(path, newPath)) {
358
+ throw new Error(
359
+ `Cannot move a path [${path}] to new path [${newPath}] because the destination is inside itself.`
360
+ );
383
361
  }
362
+ const node = Node.get(editor, path);
363
+ const parent = Node.parent(editor, path);
364
+ const index = path[path.length - 1];
365
+ parent.children.splice(index, 1);
366
+ const truePath = Path.transform(path, op);
367
+ const newParent = Node.get(editor, Path.parent(truePath));
368
+ const newIndex = truePath[truePath.length - 1];
369
+ newParent.children.splice(newIndex, 0, node);
370
+ transformSelection = true;
371
+ break;
384
372
  }
385
- break;
386
- }
387
- case "remove_node": {
388
- const { path } = op;
389
- const index = path[path.length - 1];
390
- const parent = Node.parent(editor, path);
391
- parent.children.splice(index, 1);
392
- if (selection) {
393
- for (const [point, key] of Range.points(selection)) {
394
- const result = Point.transform(point, op);
395
- if (selection != null && result != null) {
396
- selection[key] = result;
397
- } else {
398
- let prev;
399
- let next;
400
- for (const [n, p] of Node.texts(editor)) {
401
- if (Path.compare(p, path) === -1) {
402
- prev = [n, p];
403
- } else {
404
- next = [n, p];
405
- break;
373
+ case "remove_node": {
374
+ const { path } = op;
375
+ const index = path[path.length - 1];
376
+ const parent = Node.parent(editor, path);
377
+ parent.children.splice(index, 1);
378
+ if (editor.selection) {
379
+ let selection = { ...editor.selection };
380
+ for (const [point, key] of Range.points(selection)) {
381
+ const result = Point.transform(point, op);
382
+ if (selection != null && result != null) {
383
+ selection[key] = result;
384
+ } else {
385
+ let prev;
386
+ let next;
387
+ for (const [n, p] of Node.texts(editor)) {
388
+ if (Path.compare(p, path) === -1) {
389
+ prev = [n, p];
390
+ } else {
391
+ next = [n, p];
392
+ break;
393
+ }
406
394
  }
407
- }
408
- let preferNext = false;
409
- if (prev && next) {
410
- if (Path.equals(next[1], path)) {
411
- preferNext = !Path.hasPrevious(next[1]);
395
+ let preferNext = false;
396
+ if (prev && next) {
397
+ if (Path.equals(next[1], path)) {
398
+ preferNext = !Path.hasPrevious(next[1]);
399
+ } else {
400
+ preferNext = Path.common(prev[1], path).length < Path.common(next[1], path).length;
401
+ }
402
+ }
403
+ if (prev && !preferNext) {
404
+ selection[key] = {
405
+ path: prev[1],
406
+ offset: prev[0].text.length
407
+ };
408
+ } else if (next) {
409
+ selection[key] = { path: next[1], offset: 0 };
412
410
  } else {
413
- preferNext = Path.common(prev[1], path).length < Path.common(next[1], path).length;
411
+ selection = null;
414
412
  }
415
413
  }
416
- if (prev && !preferNext) {
417
- point.path = prev[1];
418
- point.offset = prev[0].text.length;
419
- } else if (next) {
420
- point.path = next[1];
421
- point.offset = 0;
422
- } else {
423
- selection = null;
424
- }
414
+ }
415
+ if (!selection || !Range.equals(selection, editor.selection)) {
416
+ editor.selection = selection;
425
417
  }
426
418
  }
419
+ break;
427
420
  }
428
- break;
429
- }
430
- case "remove_text": {
431
- const { path, offset, text } = op;
432
- if (text.length === 0) break;
433
- const node = Node.leaf(editor, path);
434
- const before = node.text.slice(0, offset);
435
- const after = node.text.slice(offset + text.length);
436
- node.text = before + after;
437
- if (selection) {
438
- for (const [point, key] of Range.points(selection)) {
439
- selection[key] = Point.transform(point, op);
440
- }
441
- }
442
- break;
443
- }
444
- case "set_node": {
445
- const { path, properties, newProperties } = op;
446
- if (path.length === 0) {
447
- throw new Error(`Cannot set properties on the root node!`);
421
+ case "remove_text": {
422
+ const { path, offset, text } = op;
423
+ if (text.length === 0) break;
424
+ const node = Node.leaf(editor, path);
425
+ const before = node.text.slice(0, offset);
426
+ const after = node.text.slice(offset + text.length);
427
+ node.text = before + after;
428
+ transformSelection = true;
429
+ break;
448
430
  }
449
- const node = Node.get(editor, path);
450
- for (const key in newProperties) {
451
- if (key === "children" || key === "text") {
452
- throw new Error(`Cannot set the "${key}" property of nodes!`);
431
+ case "set_node": {
432
+ const { path, properties, newProperties } = op;
433
+ if (path.length === 0) {
434
+ throw new Error(`Cannot set properties on the root node!`);
453
435
  }
454
- const value = newProperties[key];
455
- if (value == null) {
456
- delete node[key];
457
- } else {
458
- node[key] = value;
436
+ const node = Node.get(editor, path);
437
+ for (const key in newProperties) {
438
+ if (key === "children" || key === "text") {
439
+ throw new Error(`Cannot set the '${key}' property of nodes!`);
440
+ }
441
+ const value = newProperties[key];
442
+ if (value == null) {
443
+ delete node[key];
444
+ } else {
445
+ node[key] = value;
446
+ }
459
447
  }
460
- }
461
- for (const key in properties) {
462
- if (!newProperties.hasOwnProperty(key)) {
463
- delete node[key];
448
+ for (const key in properties) {
449
+ if (!newProperties.hasOwnProperty(key)) {
450
+ delete node[key];
451
+ }
464
452
  }
453
+ break;
465
454
  }
466
- break;
467
- }
468
- case "set_selection": {
469
- const { newProperties } = op;
470
- if (newProperties == null) {
471
- selection = newProperties;
472
- } else {
473
- if (selection == null) {
455
+ case "set_selection": {
456
+ const { newProperties } = op;
457
+ if (newProperties == null) {
458
+ editor.selection = null;
459
+ break;
460
+ }
461
+ if (editor.selection == null) {
474
462
  if (!Range.isRange(newProperties)) {
475
463
  throw new Error(
476
- `Cannot apply an incomplete "set_selection" operation properties ${Scrubber.stringify(
464
+ `Cannot apply an incomplete 'set_selection' operation properties ${Scrubber.stringify(
477
465
  newProperties
478
466
  )} when there is no current selection.`
479
467
  );
480
468
  }
481
- selection = { ...newProperties };
469
+ editor.selection = { ...newProperties };
470
+ break;
482
471
  }
472
+ const selection = { ...editor.selection };
483
473
  for (const key in newProperties) {
484
474
  const value = newProperties[key];
485
475
  if (value == null) {
486
476
  if (key === "anchor" || key === "focus") {
487
- throw new Error(`Cannot remove the "${key}" selection property`);
477
+ throw new Error(`Cannot remove the '${key}' selection property`);
488
478
  }
489
479
  delete selection[key];
490
480
  } else {
491
481
  selection[key] = value;
492
482
  }
493
483
  }
484
+ editor.selection = selection;
485
+ break;
494
486
  }
495
- break;
496
- }
497
- case "split_node": {
498
- const { path, position, properties } = op;
499
- if (path.length === 0) {
500
- throw new Error(
501
- `Cannot apply a "split_node" operation at path [${path}] because the root node cannot be split.`
502
- );
503
- }
504
- const node = Node.get(editor, path);
505
- const parent = Node.parent(editor, path);
506
- const index = path[path.length - 1];
507
- let newNode;
508
- if (Text.isText(node)) {
509
- const before = node.text.slice(0, position);
510
- const after = node.text.slice(position);
511
- node.text = before;
512
- newNode = {
513
- ...properties,
514
- text: after
515
- };
516
- } else {
517
- const before = node.children.slice(0, position);
518
- const after = node.children.slice(position);
519
- node.children = before;
520
- newNode = {
521
- ...properties,
522
- children: after
523
- };
524
- }
525
- parent.children.splice(index + 1, 0, newNode);
526
- if (selection) {
527
- for (const [point, key] of Range.points(selection)) {
528
- selection[key] = Point.transform(point, op);
487
+ case "split_node": {
488
+ const { path, position, properties } = op;
489
+ if (path.length === 0) {
490
+ throw new Error(
491
+ `Cannot apply a 'split_node' operation at path [${path}] because the root node cannot be split.`
492
+ );
493
+ }
494
+ const node = Node.get(editor, path);
495
+ const parent = Node.parent(editor, path);
496
+ const index = path[path.length - 1];
497
+ let newNode;
498
+ if (Text.isText(node)) {
499
+ const before = node.text.slice(0, position);
500
+ const after = node.text.slice(position);
501
+ node.text = before;
502
+ newNode = {
503
+ ...properties,
504
+ text: after
505
+ };
506
+ } else {
507
+ const before = node.children.slice(0, position);
508
+ const after = node.children.slice(position);
509
+ node.children = before;
510
+ newNode = {
511
+ ...properties,
512
+ children: after
513
+ };
529
514
  }
515
+ parent.children.splice(index + 1, 0, newNode);
516
+ transformSelection = true;
517
+ break;
530
518
  }
531
- break;
532
519
  }
533
- }
534
- return selection;
535
- };
536
- const GeneralTransforms = {
537
- transform(editor, op) {
538
- let selection = editor.selection;
539
- try {
540
- selection = applyToDraft(editor, selection, op);
541
- } finally {
542
- if (selection) {
520
+ if (transformSelection && editor.selection) {
521
+ const selection = { ...editor.selection };
522
+ for (const [point, key] of Range.points(selection)) {
523
+ selection[key] = Point.transform(point, op);
524
+ }
525
+ if (!Range.equals(selection, editor.selection)) {
543
526
  editor.selection = selection;
544
- } else {
545
- editor.selection = null;
546
527
  }
547
528
  }
548
529
  }
package/dist/core.js CHANGED
@@ -1,6 +1,6 @@
1
- import { a6, a7, a8, d, e, f, a, h, aj, c, i, j, k, ap, ak, l, m, o, p, q, g, b, r, t, u, v, w, x, aq, y, a9, z, A, B, C, D, E, F, G, H, I, J, aa, K, ab, al, ac, L, M, N, O, n, P, S, Q, R, V, T, U, W, X, _, Y, Z, $, ad, am, ae, a0, an, ao, a5, s, af, a1, a2, a3, ag, ah, a4, ai } from "./create-editor-ZZEkf55h.js";
2
- import { E as E2, a as a10, I as I2, N as N2, O as O2, P as P2, b as b2, R as R2, S as S2, T as T2, c as c2, i as i2, d as d2 } from "./batch-dirty-paths-BGS8X5pd.js";
3
- import { L as L2, S as S3 } from "./location-D4Ys3xEt.js";
1
+ import { a6, a7, a8, d, e, f, a, h, aj, c, i, j, k, ap, ak, l, m, o, p, q, g, b, r, t, u, v, w, x, aq, y, a9, z, A, B, C, D, E, F, G, H, I, J, aa, K, ab, al, ac, L, M, N, O, n, P, S, Q, R, V, T, U, W, X, _, Y, Z, $, ad, am, ae, a0, an, ao, a5, s, af, a1, a2, a3, ag, ah, a4, ai } from "./create-editor-CDo9JOV_.js";
2
+ import { E as E2, a as a10, I as I2, N as N2, O as O2, P as P2, b as b2, R as R2, S as S2, T as T2, c as c2, i as i2, d as d2 } from "./batch-dirty-paths-9ixbU5Xv.js";
3
+ import { L as L2, S as S3 } from "./location-Df07ugyf.js";
4
4
  export {
5
5
  E2 as Editor,
6
6
  a10 as Element,
@@ -1,6 +1,6 @@
1
- import { P as Path, b as Point, R as Range, E as Editor, D as DIRTY_PATHS, e as DIRTY_PATH_KEYS, f as isBatchingDirtyPaths, c as Transforms, F as FLUSHING, T as Text, N as Node, a as Element, g as NORMALIZING, h as PATH_REFS, j as POINT_REFS, k as RANGE_REFS, l as cloneDeep, m as getDefaultInsertLocation, S as Scrubber, n as batchDirtyPaths, I as IS_EDITOR_SET } from "./batch-dirty-paths-BGS8X5pd.js";
1
+ import { P as Path, b as Point, R as Range, E as Editor, D as DIRTY_PATHS, e as DIRTY_PATH_KEYS, f as isBatchingDirtyPaths, c as Transforms, F as FLUSHING, T as Text, N as Node, a as Element, g as NORMALIZING, h as PATH_REFS, j as POINT_REFS, k as RANGE_REFS, l as cloneDeep, m as getDefaultInsertLocation, S as Scrubber, n as batchDirtyPaths, I as IS_EDITOR_SET } from "./batch-dirty-paths-9ixbU5Xv.js";
2
2
  import { reactive } from "vue";
3
- import { S as Span } from "./location-D4Ys3xEt.js";
3
+ import { S as Span } from "./location-Df07ugyf.js";
4
4
  const PathRef = {
5
5
  transform(ref, op) {
6
6
  const { current, affinity } = ref;
@@ -439,7 +439,7 @@ const normalizeNode = (editor, entry, options) => {
439
439
  const isInlineOrText = Text.isText(child) || Element.isElement(child) && editor.isInline(child);
440
440
  if (isInlineOrText !== shouldHaveInlines) {
441
441
  if (isInlineOrText) {
442
- if (options == null ? void 0 : options.fallbackElement) {
442
+ if (options?.fallbackElement) {
443
443
  Transforms.wrapNodes(editor, options.fallbackElement(), {
444
444
  at: path2.concat(n),
445
445
  voids: true
@@ -2276,7 +2276,7 @@ const splitNodes = (editor, options = {}) => {
2276
2276
  }
2277
2277
  } finally {
2278
2278
  beforeRef.unref();
2279
- afterRef == null ? void 0 : afterRef.unref();
2279
+ afterRef?.unref();
2280
2280
  }
2281
2281
  });
2282
2282
  };