@kerebron/extension-yjs 0.4.26 → 0.4.27

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.
@@ -1,21 +0,0 @@
1
- import { Command, EditorState, Plugin } from 'prosemirror-state';
2
- import { UndoManager } from 'yjs';
3
- import { getRelativeSelection } from './ySyncPlugin.js';
4
- export interface UndoPluginState {
5
- undoManager: UndoManager;
6
- prevSel: ReturnType<typeof getRelativeSelection> | null;
7
- hasUndoOps: boolean;
8
- hasRedoOps: boolean;
9
- }
10
- export declare const undo: (state: EditorState) => boolean;
11
- export declare const redo: (state: EditorState) => boolean;
12
- export declare const undoCommand: Command;
13
- export declare const redoCommand: Command;
14
- export declare const defaultProtectedNodes: Set<string>;
15
- export declare const defaultDeleteFilter: (item: import("yjs").Item, protectedNodes: Set<string>) => boolean;
16
- export declare const yUndoPlugin: ({ protectedNodes, trackedOrigins, undoManager, }?: {
17
- protectedNodes?: Set<string>;
18
- trackedOrigins?: any[];
19
- undoManager?: import("yjs").UndoManager | null;
20
- }) => Plugin<any>;
21
- //# sourceMappingURL=yUndoPlugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"yUndoPlugin.d.ts","sourceRoot":"","sources":["../src/yUndoPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAA2B,WAAW,EAAc,MAAM,KAAK,CAAC;AAEvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,WAAW,CAAC;IACzB,OAAO,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,GAAG,IAAI,CAAC;IACxD,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,IAAI,GAAI,OAAO,WAAW,KAAG,OACmB,CAAC;AAE9D,eAAO,MAAM,IAAI,GAAI,OAAO,WAAW,KAAG,OACmB,CAAC;AAE9D,eAAO,MAAM,WAAW,EAAE,OAGT,CAAC;AAElB,eAAO,MAAM,WAAW,EAAE,OAGT,CAAC;AAElB,eAAO,MAAM,qBAAqB,aAAyB,CAAC;AAE5D,eAAO,MAAM,mBAAmB,GAC9B,MAAM,OAAO,KAAK,EAAE,IAAI,EACxB,gBAAgB,GAAG,CAAC,MAAM,CAAC,KAC1B,OAM8B,CAAC;AAElC,eAAO,MAAM,WAAW,GAAI,mDAIzB;IACD,cAAc,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7B,cAAc,CAAC,EAAE,GAAG,EAAE,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;CAC3C,gBAuEF,CAAC"}
@@ -1,89 +0,0 @@
1
- import { Plugin } from 'prosemirror-state';
2
- import { ContentType, Item, Text, UndoManager, XmlElement } from 'yjs';
3
- import { getRelativeSelection } from './ySyncPlugin.js';
4
- import { ySyncPluginKey, yUndoPluginKey } from './keys.js';
5
- export const undo = (state) => yUndoPluginKey.getState(state)?.undoManager?.undo() != null;
6
- export const redo = (state) => yUndoPluginKey.getState(state)?.undoManager?.redo() != null;
7
- export const undoCommand = (state, dispatch) => dispatch == null
8
- ? yUndoPluginKey.getState(state)?.undoManager?.canUndo()
9
- : undo(state);
10
- export const redoCommand = (state, dispatch) => dispatch == null
11
- ? yUndoPluginKey.getState(state)?.undoManager?.canRedo()
12
- : redo(state);
13
- export const defaultProtectedNodes = new Set(['paragraph']);
14
- export const defaultDeleteFilter = (item, protectedNodes) => !(item instanceof Item) ||
15
- !(item.content instanceof ContentType) ||
16
- !(item.content.type instanceof Text ||
17
- (item.content.type instanceof XmlElement &&
18
- protectedNodes.has(item.content.type.nodeName))) ||
19
- item.content.type._length === 0;
20
- export const yUndoPlugin = ({ protectedNodes = defaultProtectedNodes, trackedOrigins = [], undoManager = null, } = {}) => new Plugin({
21
- key: yUndoPluginKey,
22
- state: {
23
- init: (initargs, state) => {
24
- // TODO: check if plugin order matches and fix
25
- const ystate = ySyncPluginKey.getState(state);
26
- const _undoManager = undoManager || new UndoManager(ystate.type, {
27
- trackedOrigins: new Set([ySyncPluginKey].concat(trackedOrigins)),
28
- deleteFilter: (item) => defaultDeleteFilter(item, protectedNodes),
29
- captureTransaction: (tr) => tr.meta.get('addToHistory') !== false,
30
- });
31
- return {
32
- undoManager: _undoManager,
33
- prevSel: null,
34
- hasUndoOps: _undoManager.undoStack.length > 0,
35
- hasRedoOps: _undoManager.redoStack.length > 0,
36
- };
37
- },
38
- apply: (tr, val, oldState, state) => {
39
- const binding = ySyncPluginKey.getState(state).binding;
40
- const undoManager = val.undoManager;
41
- const hasUndoOps = undoManager.undoStack.length > 0;
42
- const hasRedoOps = undoManager.redoStack.length > 0;
43
- if (binding) {
44
- return {
45
- undoManager,
46
- prevSel: getRelativeSelection(binding, oldState),
47
- hasUndoOps,
48
- hasRedoOps,
49
- };
50
- }
51
- else {
52
- if (hasUndoOps !== val.hasUndoOps || hasRedoOps !== val.hasRedoOps) {
53
- return Object.assign({}, val, {
54
- hasUndoOps: undoManager.undoStack.length > 0,
55
- hasRedoOps: undoManager.redoStack.length > 0,
56
- });
57
- }
58
- else { // nothing changed
59
- return val;
60
- }
61
- }
62
- },
63
- },
64
- view: (view) => {
65
- const ystate = ySyncPluginKey.getState(view.state);
66
- const yUndoPlugin = yUndoPluginKey.getState(view.state);
67
- const undoManager = yUndoPlugin?.undoManager;
68
- if (undoManager) {
69
- undoManager.on('stack-item-added', ({ stackItem }) => {
70
- const binding = ystate.binding;
71
- if (binding) {
72
- stackItem.meta.set(binding, yUndoPlugin.prevSel);
73
- }
74
- });
75
- undoManager.on('stack-item-popped', ({ stackItem }) => {
76
- const binding = ystate.binding;
77
- if (binding) {
78
- binding.beforeTransactionSelection = stackItem.meta.get(binding) ||
79
- binding.beforeTransactionSelection;
80
- }
81
- });
82
- }
83
- return {
84
- destroy: () => {
85
- undoManager?.destroy();
86
- },
87
- };
88
- },
89
- });