@kerebron/extension-yjs 0.2.1 → 0.3.1

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.
Files changed (70) hide show
  1. package/esm/editor/src/CoreEditor.d.ts +11 -5
  2. package/esm/editor/src/CoreEditor.d.ts.map +1 -1
  3. package/esm/editor/src/CoreEditor.js +64 -61
  4. package/esm/editor/src/DummyEditorView.d.ts +60 -0
  5. package/esm/editor/src/DummyEditorView.d.ts.map +1 -0
  6. package/esm/editor/src/DummyEditorView.js +277 -0
  7. package/esm/editor/src/Extension.d.ts +9 -9
  8. package/esm/editor/src/Extension.d.ts.map +1 -1
  9. package/esm/editor/src/Extension.js +2 -2
  10. package/esm/editor/src/ExtensionManager.d.ts +8 -7
  11. package/esm/editor/src/ExtensionManager.d.ts.map +1 -1
  12. package/esm/editor/src/ExtensionManager.js +58 -39
  13. package/esm/editor/src/Mark.d.ts +8 -6
  14. package/esm/editor/src/Mark.d.ts.map +1 -1
  15. package/esm/editor/src/Mark.js +8 -2
  16. package/esm/editor/src/Node.d.ts +14 -12
  17. package/esm/editor/src/Node.d.ts.map +1 -1
  18. package/esm/editor/src/Node.js +10 -4
  19. package/esm/editor/src/commands/CommandManager.d.ts +5 -9
  20. package/esm/editor/src/commands/CommandManager.d.ts.map +1 -1
  21. package/esm/editor/src/commands/CommandManager.js +7 -6
  22. package/esm/editor/src/commands/mod.d.ts +12 -6
  23. package/esm/editor/src/commands/mod.d.ts.map +1 -1
  24. package/esm/editor/src/commands/mod.js +0 -45
  25. package/esm/editor/src/mod.d.ts +1 -0
  26. package/esm/editor/src/mod.d.ts.map +1 -1
  27. package/esm/editor/src/mod.js +1 -0
  28. package/esm/editor/src/nodeToTreeString.d.ts +8 -2
  29. package/esm/editor/src/nodeToTreeString.d.ts.map +1 -1
  30. package/esm/editor/src/nodeToTreeString.js +47 -29
  31. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +2 -2
  32. package/esm/editor/src/plugins/keymap/keymap.d.ts +11 -0
  33. package/esm/editor/src/plugins/keymap/keymap.d.ts.map +1 -0
  34. package/esm/editor/src/plugins/keymap/keymap.js +125 -0
  35. package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts +4 -0
  36. package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts.map +1 -0
  37. package/esm/editor/src/plugins/keymap/w3c-keyname.js +124 -0
  38. package/esm/editor/src/types.d.ts +10 -5
  39. package/esm/editor/src/types.d.ts.map +1 -1
  40. package/esm/editor/src/utilities/SmartOutput.d.ts +39 -0
  41. package/esm/editor/src/utilities/SmartOutput.d.ts.map +1 -0
  42. package/esm/editor/src/utilities/SmartOutput.js +213 -0
  43. package/esm/editor/src/utilities/createNodeFromContent.d.ts +4 -3
  44. package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +1 -1
  45. package/esm/editor/src/utilities/createNodeFromContent.js +4 -5
  46. package/esm/editor/src/utilities/getHtmlAttributes.d.ts +8 -3
  47. package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +1 -1
  48. package/esm/extension-yjs/src/ExtensionYjs.d.ts +5 -5
  49. package/esm/extension-yjs/src/ExtensionYjs.d.ts.map +1 -1
  50. package/esm/extension-yjs/src/ExtensionYjs.js +3 -2
  51. package/esm/extension-yjs/src/keys.d.ts +15 -0
  52. package/esm/extension-yjs/src/keys.d.ts.map +1 -0
  53. package/esm/extension-yjs/src/keys.js +13 -0
  54. package/esm/extension-yjs/src/lib.js +269 -0
  55. package/esm/extension-yjs/src/utils.d.ts +0 -3
  56. package/esm/extension-yjs/src/utils.d.ts.map +1 -1
  57. package/esm/extension-yjs/src/utils.js +0 -8
  58. package/esm/extension-yjs/src/yCursorPlugin.d.ts +3 -17
  59. package/esm/extension-yjs/src/yCursorPlugin.d.ts.map +1 -1
  60. package/esm/extension-yjs/src/yCursorPlugin.js +21 -13
  61. package/esm/extension-yjs/src/ySyncPlugin.d.ts +54 -91
  62. package/esm/extension-yjs/src/ySyncPlugin.d.ts.map +1 -1
  63. package/esm/extension-yjs/src/ySyncPlugin.js +99 -222
  64. package/esm/extension-yjs/src/yUndoPlugin.d.ts +21 -0
  65. package/esm/extension-yjs/src/yUndoPlugin.d.ts.map +1 -0
  66. package/esm/extension-yjs/src/yUndoPlugin.js +86 -0
  67. package/package.json +2 -4
  68. package/LICENSE +0 -23
  69. package/README.md +0 -57
  70. package/esm/package.json +0 -3
@@ -0,0 +1,86 @@
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 undoManager = yUndoPluginKey.getState(view.state).undoManager;
67
+ undoManager.on('stack-item-added', ({ stackItem }) => {
68
+ const binding = ystate.binding;
69
+ if (binding) {
70
+ stackItem.meta.set(binding, yUndoPluginKey.getState(view.state).prevSel);
71
+ }
72
+ });
73
+ undoManager.on('stack-item-popped', ({ stackItem }) => {
74
+ const binding = ystate.binding;
75
+ if (binding) {
76
+ binding.beforeTransactionSelection = stackItem.meta.get(binding) ||
77
+ binding.beforeTransactionSelection;
78
+ }
79
+ });
80
+ return {
81
+ destroy: () => {
82
+ undoManager.destroy();
83
+ },
84
+ };
85
+ },
86
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kerebron/extension-yjs",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "license": "MIT",
5
5
  "module": "./esm/extension-yjs/src/ExtensionYjs.js",
6
6
  "exports": {
@@ -13,12 +13,10 @@
13
13
  },
14
14
  "scripts": {},
15
15
  "dependencies": {
16
- "prosemirror-keymap": "1.2.2",
17
- "prosemirror-model": "1.25.1",
16
+ "prosemirror-model": "1.25.2",
18
17
  "prosemirror-state": "1.4.3",
19
18
  "prosemirror-transform": "1.10.4",
20
19
  "prosemirror-view": "1.40.0",
21
- "y-prosemirror": "1.3.6",
22
20
  "yjs": "13.6.24"
23
21
  },
24
22
  "devDependencies": {
package/LICENSE DELETED
@@ -1,23 +0,0 @@
1
- Permission is hereby granted, free of charge, to any
2
- person obtaining a copy of this software and associated
3
- documentation files (the "Software"), to deal in the
4
- Software without restriction, including without
5
- limitation the rights to use, copy, modify, merge,
6
- publish, distribute, sublicense, and/or sell copies of
7
- the Software, and to permit persons to whom the Software
8
- is furnished to do so, subject to the following
9
- conditions:
10
-
11
- The above copyright notice and this permission notice
12
- shall be included in all copies or substantial portions
13
- of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16
- ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17
- TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18
- PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19
- SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
22
- IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
- DEALINGS IN THE SOFTWARE.
package/README.md DELETED
@@ -1,57 +0,0 @@
1
- # Kerebron - Prosemirror based online editor kit
2
-
3
- ## Watch a Demo
4
-
5
- <a href="https://youtube.com/shorts/OdJjhAPj-wA?feature=share" target="_blank">
6
- <img src="https://github.com/user-attachments/assets/b63ec84a-0ed2-4f98-920c-76f6d3215168" alt="Alt Text" width="200">
7
- </a>
8
-
9
- ## Playground Demo
10
-
11
- [playground](https://editor-test.gitgis.com) - be nice.
12
-
13
- ## Overview
14
-
15
- Using vanilla Prosemirror modules is often impossible because of
16
- incompatibilities.
17
-
18
- Kerebron forks several prosemirror projects into one monorepo in order to keep
19
- them in sync.
20
-
21
- Project is inspired on https://tiptap.dev/, but instead of building wrapper
22
- around a wrapper it borrows concept of extension and command manager.
23
-
24
- It has simplified tooling (deno), fewer dependencies and resulting in lower
25
- number of output npm modules.
26
-
27
- **Work in progress**
28
-
29
- ## Development
30
-
31
- To start example server:
32
-
33
- ```
34
- deno task -f example-server-hono start
35
- ```
36
-
37
- ## Build
38
-
39
- # NPM packages are generated using DNT
40
-
41
- - https://deno.com/blog/publish-esm-cjs-module-dnt - the easiest way to publish
42
- a hybrid npm module for ESM and CommonJS
43
- - https://github.com/denoland/dnt
44
- - https://gaubee.com/article/Publishing-Your-Deno-Project-as-a-Monorepo-using-dnt/
45
-
46
- To generate npm packages
47
-
48
- ```shell
49
- deno -A ./scripts/build_npm.ts
50
- ```
51
-
52
- ## Run through docker
53
-
54
- ```
55
- docker build . -t editor-test
56
- docker run -it -p 8000:8000 -v $PWD:/usr/src/app editor-test
57
- ```
package/esm/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }