slate-vue3 0.0.6 → 0.0.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.
package/dist/index.d.ts CHANGED
@@ -268,6 +268,11 @@ export declare interface BaseText {
268
268
  text: string;
269
269
  }
270
270
 
271
+ declare interface Batch {
272
+ operations: Operation[];
273
+ selectionBefore: Range_2 | null;
274
+ }
275
+
271
276
  export declare const before: EditorInterface['before'];
272
277
 
273
278
  export declare const CAN_USE_DOM: boolean;
@@ -1420,6 +1425,87 @@ export declare const hasShadowRoot: (node: Node | null) => boolean;
1420
1425
 
1421
1426
  export declare const hasTexts: EditorInterface['hasTexts'];
1422
1427
 
1428
+ /**
1429
+ * Weakmaps for attaching state to the editor.
1430
+ */
1431
+ export declare const HISTORY: toRawWeakMap<DOMEditor, History_2>;
1432
+
1433
+ /**
1434
+ * `History` objects hold all of the operations that are applied to a value, so
1435
+ * they can be undone or redone as necessary.
1436
+ */
1437
+ declare interface History_2 {
1438
+ redos: Batch[];
1439
+ undos: Batch[];
1440
+ }
1441
+
1442
+ declare const History_2: {
1443
+ /**
1444
+ * Check if a value is a `History` object.
1445
+ */
1446
+ isHistory(value: any): value is History_2;
1447
+ };
1448
+ export { History_2 as History }
1449
+
1450
+ /**
1451
+ * `HistoryEditor` contains helpers for history-enabled editors.
1452
+ */
1453
+ export declare interface HistoryEditor extends BaseEditor {
1454
+ history: History_2;
1455
+ undo: () => void;
1456
+ redo: () => void;
1457
+ writeHistory: (stack: "undos" | "redos", batch: any) => void;
1458
+ }
1459
+
1460
+ export declare const HistoryEditor: {
1461
+ /**
1462
+ * Check if a value is a `HistoryEditor` object.
1463
+ */
1464
+ isHistoryEditor(value: any): value is HistoryEditor;
1465
+ /**
1466
+ * Get the merge flag's current value.
1467
+ */
1468
+ isMerging(editor: HistoryEditor): boolean | undefined;
1469
+ /**
1470
+ * Get the splitting once flag's current value.
1471
+ */
1472
+ isSplittingOnce(editor: HistoryEditor): boolean | undefined;
1473
+ setSplittingOnce(editor: HistoryEditor, value: boolean | undefined): void;
1474
+ /**
1475
+ * Get the saving flag's current value.
1476
+ */
1477
+ isSaving(editor: HistoryEditor): boolean | undefined;
1478
+ /**
1479
+ * Redo to the previous saved state.
1480
+ */
1481
+ redo(editor: HistoryEditor): void;
1482
+ /**
1483
+ * Undo to the previous saved state.
1484
+ */
1485
+ undo(editor: HistoryEditor): void;
1486
+ /**
1487
+ * Apply a series of changes inside a synchronous `fn`, These operations will
1488
+ * be merged into the previous history.
1489
+ */
1490
+ withMerging(editor: HistoryEditor, fn: () => void): void;
1491
+ /**
1492
+ * Apply a series of changes inside a synchronous `fn`, ensuring that the first
1493
+ * operation starts a new batch in the history. Subsequent operations will be
1494
+ * merged as usual.
1495
+ */
1496
+ withNewBatch(editor: HistoryEditor, fn: () => void): void;
1497
+ /**
1498
+ * Apply a series of changes inside a synchronous `fn`, without merging any of
1499
+ * the new operations into previous save point in the history.
1500
+ */
1501
+ withoutMerging(editor: HistoryEditor, fn: () => void): void;
1502
+ /**
1503
+ * Apply a series of changes inside a synchronous `fn`, without saving any of
1504
+ * their operations into the history.
1505
+ */
1506
+ withoutSaving(editor: HistoryEditor, fn: () => void): void;
1507
+ };
1508
+
1423
1509
  /**
1424
1510
  * Hotkeys.
1425
1511
  */
@@ -1622,6 +1708,8 @@ export declare const mergeNodes: NodeTransforms['mergeNodes'];
1622
1708
  */
1623
1709
  export declare function mergeStringDiffs(targetText: string, a: StringDiff, b: StringDiff): StringDiff | null;
1624
1710
 
1711
+ export declare const MERGING: toRawWeakMap<DOMEditor, boolean | undefined>;
1712
+
1625
1713
  export declare const move: SelectionTransforms['move'];
1626
1714
 
1627
1715
  export declare type MoveNodeOperation = ExtendedType<'MoveNodeOperation', BaseMoveNodeOperation>;
@@ -2405,6 +2493,8 @@ export declare interface RenderPlaceholderProps {
2405
2493
  };
2406
2494
  }
2407
2495
 
2496
+ export declare const SAVING: toRawWeakMap<DOMEditor, boolean | undefined>;
2497
+
2408
2498
  export declare type Scrubber = (key: string, value: unknown) => unknown;
2409
2499
 
2410
2500
  /**
@@ -2542,6 +2632,8 @@ export declare type SplitNodeOperation = ExtendedType<'SplitNodeOperation', Base
2542
2632
 
2543
2633
  export declare const splitNodes: NodeTransforms['splitNodes'];
2544
2634
 
2635
+ export declare const SPLITTING_ONCE: toRawWeakMap<DOMEditor, boolean | undefined>;
2636
+
2545
2637
  export declare const start: EditorInterface['start'];
2546
2638
 
2547
2639
  export declare const string: EditorInterface['string'];
@@ -2735,6 +2827,17 @@ export declare const withDOM: <T extends BaseEditor>(editor: T, clipboardFormatK
2735
2827
 
2736
2828
  declare type WithEditorFirstArg<T extends (...args: any) => any> = (editor: Editor, ...args: Parameters<T>) => ReturnType<T>;
2737
2829
 
2830
+ /**
2831
+ * The `withHistory` plugin keeps track of the operation history of a Slate
2832
+ * editor as operations are applied to it, using undo and redo stacks.
2833
+ *
2834
+ * If you are using TypeScript, you must extend Slate's CustomTypes to use
2835
+ * this plugin.
2836
+ *
2837
+ * See https://docs.slatejs.org/concepts/11-typescript to learn how.
2838
+ */
2839
+ export declare const withHistory: <T extends Editor>(editor: T) => T & HistoryEditor;
2840
+
2738
2841
  export declare const withoutNormalizing: EditorInterface['withoutNormalizing'];
2739
2842
 
2740
2843
  export declare const wrapNodes: NodeTransforms['wrapNodes'];
@@ -12365,6 +12365,205 @@ const useSelection = () => {
12365
12365
  }
12366
12366
  return selection;
12367
12367
  };
12368
+ const History = {
12369
+ /**
12370
+ * Check if a value is a `History` object.
12371
+ */
12372
+ isHistory(value) {
12373
+ return isPlainObject(value) && Array.isArray(value.redos) && Array.isArray(value.undos) && (value.redos.length === 0 || Operation.isOperationList(value.redos[0].operations)) && (value.undos.length === 0 || Operation.isOperationList(value.undos[0].operations));
12374
+ }
12375
+ };
12376
+ const HISTORY = new toRawWeakMap();
12377
+ const SAVING = new toRawWeakMap();
12378
+ const MERGING = new toRawWeakMap();
12379
+ const SPLITTING_ONCE = new toRawWeakMap();
12380
+ const HistoryEditor = {
12381
+ /**
12382
+ * Check if a value is a `HistoryEditor` object.
12383
+ */
12384
+ isHistoryEditor(value) {
12385
+ return History.isHistory(value.history) && Editor.isEditor(value);
12386
+ },
12387
+ /**
12388
+ * Get the merge flag's current value.
12389
+ */
12390
+ isMerging(editor) {
12391
+ return MERGING.get(editor);
12392
+ },
12393
+ /**
12394
+ * Get the splitting once flag's current value.
12395
+ */
12396
+ isSplittingOnce(editor) {
12397
+ return SPLITTING_ONCE.get(editor);
12398
+ },
12399
+ setSplittingOnce(editor, value) {
12400
+ SPLITTING_ONCE.set(editor, value);
12401
+ },
12402
+ /**
12403
+ * Get the saving flag's current value.
12404
+ */
12405
+ isSaving(editor) {
12406
+ return SAVING.get(editor);
12407
+ },
12408
+ /**
12409
+ * Redo to the previous saved state.
12410
+ */
12411
+ redo(editor) {
12412
+ editor.redo();
12413
+ },
12414
+ /**
12415
+ * Undo to the previous saved state.
12416
+ */
12417
+ undo(editor) {
12418
+ editor.undo();
12419
+ },
12420
+ /**
12421
+ * Apply a series of changes inside a synchronous `fn`, These operations will
12422
+ * be merged into the previous history.
12423
+ */
12424
+ withMerging(editor, fn) {
12425
+ const prev = HistoryEditor.isMerging(editor);
12426
+ MERGING.set(editor, true);
12427
+ fn();
12428
+ MERGING.set(editor, prev);
12429
+ },
12430
+ /**
12431
+ * Apply a series of changes inside a synchronous `fn`, ensuring that the first
12432
+ * operation starts a new batch in the history. Subsequent operations will be
12433
+ * merged as usual.
12434
+ */
12435
+ withNewBatch(editor, fn) {
12436
+ const prev = HistoryEditor.isMerging(editor);
12437
+ MERGING.set(editor, true);
12438
+ SPLITTING_ONCE.set(editor, true);
12439
+ fn();
12440
+ MERGING.set(editor, prev);
12441
+ SPLITTING_ONCE.delete(editor);
12442
+ },
12443
+ /**
12444
+ * Apply a series of changes inside a synchronous `fn`, without merging any of
12445
+ * the new operations into previous save point in the history.
12446
+ */
12447
+ withoutMerging(editor, fn) {
12448
+ const prev = HistoryEditor.isMerging(editor);
12449
+ MERGING.set(editor, false);
12450
+ fn();
12451
+ MERGING.set(editor, prev);
12452
+ },
12453
+ /**
12454
+ * Apply a series of changes inside a synchronous `fn`, without saving any of
12455
+ * their operations into the history.
12456
+ */
12457
+ withoutSaving(editor, fn) {
12458
+ const prev = HistoryEditor.isSaving(editor);
12459
+ SAVING.set(editor, false);
12460
+ fn();
12461
+ SAVING.set(editor, prev);
12462
+ }
12463
+ };
12464
+ const withHistory = (editor) => {
12465
+ const e2 = editor;
12466
+ const { apply: apply2 } = e2;
12467
+ e2.history = { undos: [], redos: [] };
12468
+ e2.redo = () => {
12469
+ const { history } = e2;
12470
+ const { redos } = history;
12471
+ if (redos.length > 0) {
12472
+ const batch2 = redos[redos.length - 1];
12473
+ if (batch2.selectionBefore) {
12474
+ Transforms.setSelection(e2, batch2.selectionBefore);
12475
+ }
12476
+ HistoryEditor.withoutSaving(e2, () => {
12477
+ Editor.withoutNormalizing(e2, () => {
12478
+ for (const op of batch2.operations) {
12479
+ e2.apply(op);
12480
+ }
12481
+ });
12482
+ });
12483
+ history.redos.pop();
12484
+ e2.writeHistory("undos", batch2);
12485
+ }
12486
+ };
12487
+ e2.undo = () => {
12488
+ const { history } = e2;
12489
+ const { undos } = history;
12490
+ if (undos.length > 0) {
12491
+ const batch2 = undos[undos.length - 1];
12492
+ HistoryEditor.withoutSaving(e2, () => {
12493
+ Editor.withoutNormalizing(e2, () => {
12494
+ const inverseOps = batch2.operations.map(Operation.inverse).reverse();
12495
+ for (const op of inverseOps) {
12496
+ e2.apply(op);
12497
+ }
12498
+ if (batch2.selectionBefore) {
12499
+ Transforms.setSelection(e2, batch2.selectionBefore);
12500
+ }
12501
+ });
12502
+ });
12503
+ e2.writeHistory("redos", batch2);
12504
+ history.undos.pop();
12505
+ }
12506
+ };
12507
+ e2.apply = (op) => {
12508
+ const { operations, history } = e2;
12509
+ const { undos } = history;
12510
+ const lastBatch = undos[undos.length - 1];
12511
+ const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
12512
+ let save = HistoryEditor.isSaving(e2);
12513
+ let merge = HistoryEditor.isMerging(e2);
12514
+ if (save == null) {
12515
+ save = shouldSave(op);
12516
+ }
12517
+ if (save) {
12518
+ if (merge == null) {
12519
+ if (lastBatch == null) {
12520
+ merge = false;
12521
+ } else if (operations.length !== 0) {
12522
+ merge = true;
12523
+ } else {
12524
+ merge = shouldMerge(op, lastOp);
12525
+ }
12526
+ }
12527
+ if (HistoryEditor.isSplittingOnce(e2)) {
12528
+ merge = false;
12529
+ HistoryEditor.setSplittingOnce(e2, void 0);
12530
+ }
12531
+ if (lastBatch && merge) {
12532
+ lastBatch.operations.push(op);
12533
+ } else {
12534
+ const batch2 = {
12535
+ operations: [op],
12536
+ selectionBefore: e2.selection
12537
+ };
12538
+ e2.writeHistory("undos", batch2);
12539
+ }
12540
+ while (undos.length > 100) {
12541
+ undos.shift();
12542
+ }
12543
+ history.redos = [];
12544
+ }
12545
+ apply2(op);
12546
+ };
12547
+ e2.writeHistory = (stack2, batch2) => {
12548
+ e2.history[stack2].push(batch2);
12549
+ };
12550
+ return e2;
12551
+ };
12552
+ const shouldMerge = (op, prev) => {
12553
+ if (prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && Path.equals(op.path, prev.path)) {
12554
+ return true;
12555
+ }
12556
+ if (prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && Path.equals(op.path, prev.path)) {
12557
+ return true;
12558
+ }
12559
+ return false;
12560
+ };
12561
+ const shouldSave = (op, prev) => {
12562
+ if (op.type === "set_selection") {
12563
+ return false;
12564
+ }
12565
+ return true;
12566
+ };
12368
12567
  export {
12369
12568
  CAN_USE_DOM,
12370
12569
  DOMEditor,
@@ -12386,6 +12585,9 @@ export {
12386
12585
  Editor,
12387
12586
  Element,
12388
12587
  HAS_BEFORE_INPUT_SUPPORT,
12588
+ HISTORY,
12589
+ History,
12590
+ HistoryEditor,
12389
12591
  Hotkeys,
12390
12592
  IS_ANDROID,
12391
12593
  IS_CHROME,
@@ -12402,6 +12604,7 @@ export {
12402
12604
  Key,
12403
12605
  Location,
12404
12606
  MARK_PLACEHOLDER_SYMBOL,
12607
+ MERGING,
12405
12608
  NODE_TO_ELEMENT,
12406
12609
  NODE_TO_INDEX,
12407
12610
  NODE_TO_KEY,
@@ -12415,6 +12618,8 @@ export {
12415
12618
  PointRef,
12416
12619
  Range,
12417
12620
  RangeRef,
12621
+ SAVING,
12622
+ SPLITTING_ONCE,
12418
12623
  Scrubber,
12419
12624
  Slate,
12420
12625
  Span,
@@ -12528,6 +12733,7 @@ export {
12528
12733
  useSelection,
12529
12734
  verifyDiffState,
12530
12735
  withDOM,
12736
+ withHistory,
12531
12737
  withoutNormalizing,
12532
12738
  wrapNodes
12533
12739
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slate-vue3",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -19,10 +19,10 @@
19
19
  "is-hotkey": "^0.2.0",
20
20
  "lodash-es": "^4.17.21",
21
21
  "scroll-into-view-if-needed": "^3.1.0",
22
- "slate-history": "^0.110.3",
23
- "slate-hyperscript": "^0.100.0",
24
- "vue": "^3.5.13",
25
- "vue-router": "^4.5.0"
22
+ "slate-history": "^0.110.3"
23
+ },
24
+ "peerDependencies": {
25
+ "vue": "^3.5.13"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@faker-js/faker": "^9.4.0",
@@ -39,7 +39,9 @@
39
39
  "typescript": "~5.7.2",
40
40
  "vite": "^6.0.11",
41
41
  "vite-plugin-dts": "^4.5.0",
42
- "vue-tsc": "^2.2.0"
42
+ "vue-tsc": "^2.2.0",
43
+ "slate-hyperscript": "^0.100.0",
44
+ "vue-router": "^4.5.0"
43
45
  },
44
46
  "keywords": [
45
47
  "canvas",