@kerebron/extension-codemirror 0.2.0 → 0.3.0

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 (96) hide show
  1. package/README.md +4 -3
  2. package/esm/editor/src/CoreEditor.d.ts +31 -0
  3. package/esm/editor/src/CoreEditor.d.ts.map +1 -0
  4. package/esm/editor/src/CoreEditor.js +198 -0
  5. package/esm/editor/src/DummyEditorView.d.ts +60 -0
  6. package/esm/editor/src/DummyEditorView.d.ts.map +1 -0
  7. package/esm/editor/src/DummyEditorView.js +277 -0
  8. package/esm/editor/src/Extension.d.ts +26 -0
  9. package/esm/editor/src/Extension.d.ts.map +1 -0
  10. package/esm/editor/src/Extension.js +33 -0
  11. package/esm/editor/src/ExtensionManager.d.ts +33 -0
  12. package/esm/editor/src/ExtensionManager.d.ts.map +1 -0
  13. package/esm/editor/src/ExtensionManager.js +272 -0
  14. package/esm/editor/src/Mark.d.ts +20 -0
  15. package/esm/editor/src/Mark.d.ts.map +1 -0
  16. package/esm/editor/src/Mark.js +40 -0
  17. package/esm/editor/src/Node.d.ts +29 -0
  18. package/esm/editor/src/Node.d.ts.map +1 -0
  19. package/esm/editor/src/Node.js +49 -0
  20. package/esm/editor/src/commands/CommandManager.d.ts +16 -0
  21. package/esm/editor/src/commands/CommandManager.d.ts.map +1 -0
  22. package/esm/editor/src/commands/CommandManager.js +61 -0
  23. package/esm/editor/src/commands/createChainableState.d.ts +3 -0
  24. package/esm/editor/src/commands/createChainableState.d.ts.map +1 -0
  25. package/esm/editor/src/commands/createChainableState.js +29 -0
  26. package/esm/editor/src/commands/mod.d.ts +55 -0
  27. package/esm/editor/src/commands/mod.d.ts.map +1 -0
  28. package/esm/editor/src/commands/mod.js +883 -0
  29. package/esm/editor/src/mod.d.ts +7 -0
  30. package/esm/editor/src/mod.d.ts.map +1 -0
  31. package/esm/editor/src/mod.js +6 -0
  32. package/esm/editor/src/nodeToTreeString.d.ts +4 -0
  33. package/esm/editor/src/nodeToTreeString.d.ts.map +1 -0
  34. package/esm/editor/src/nodeToTreeString.js +58 -0
  35. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +23 -0
  36. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
  37. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +163 -0
  38. package/esm/editor/src/plugins/input-rules/mod.d.ts +3 -0
  39. package/esm/editor/src/plugins/input-rules/mod.d.ts.map +1 -0
  40. package/esm/editor/src/plugins/input-rules/mod.js +2 -0
  41. package/esm/editor/src/plugins/input-rules/rulebuilders.d.ts +5 -0
  42. package/esm/editor/src/plugins/input-rules/rulebuilders.d.ts.map +1 -0
  43. package/esm/editor/src/plugins/input-rules/rulebuilders.js +50 -0
  44. package/esm/editor/src/plugins/keymap/keymap.d.ts +11 -0
  45. package/esm/editor/src/plugins/keymap/keymap.d.ts.map +1 -0
  46. package/esm/editor/src/plugins/keymap/keymap.js +125 -0
  47. package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts +4 -0
  48. package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts.map +1 -0
  49. package/esm/editor/src/plugins/keymap/w3c-keyname.js +124 -0
  50. package/esm/editor/src/types.d.ts +34 -0
  51. package/esm/editor/src/types.d.ts.map +1 -0
  52. package/esm/editor/src/types.js +1 -0
  53. package/esm/editor/src/utilities/createNodeFromContent.d.ts +9 -0
  54. package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +1 -0
  55. package/esm/editor/src/utilities/createNodeFromContent.js +32 -0
  56. package/esm/editor/src/utilities/getHtmlAttributes.d.ts +9 -0
  57. package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +1 -0
  58. package/esm/editor/src/utilities/getHtmlAttributes.js +47 -0
  59. package/esm/editor/src/utilities/mod.d.ts +3 -0
  60. package/esm/editor/src/utilities/mod.d.ts.map +1 -0
  61. package/esm/editor/src/utilities/mod.js +2 -0
  62. package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts +5 -0
  63. package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts.map +1 -0
  64. package/esm/extension-codemirror/src/ExtensionCodeMirror.js +4 -0
  65. package/esm/extension-codemirror/src/NodeCodeMirror.d.ts +16 -0
  66. package/esm/extension-codemirror/src/NodeCodeMirror.d.ts.map +1 -0
  67. package/esm/extension-codemirror/src/NodeCodeMirror.js +186 -0
  68. package/esm/extension-codemirror/src/NodeDocumentCode.d.ts +7 -0
  69. package/esm/extension-codemirror/src/NodeDocumentCode.d.ts.map +1 -0
  70. package/esm/extension-codemirror/src/NodeDocumentCode.js +37 -0
  71. package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts +6 -0
  72. package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts.map +1 -0
  73. package/esm/extension-codemirror/src/codeMirrorBlockNodeView.js +267 -0
  74. package/esm/extension-codemirror/src/defaults.d.ts +6 -0
  75. package/esm/extension-codemirror/src/defaults.d.ts.map +1 -0
  76. package/esm/extension-codemirror/src/defaults.js +57 -0
  77. package/esm/extension-codemirror/src/languageLoaders.d.ts +5 -0
  78. package/esm/extension-codemirror/src/languageLoaders.d.ts.map +1 -0
  79. package/esm/extension-codemirror/src/languageLoaders.js +113 -0
  80. package/esm/extension-codemirror/src/languages.d.ts +109 -0
  81. package/esm/extension-codemirror/src/languages.d.ts.map +1 -0
  82. package/esm/extension-codemirror/src/languages.js +110 -0
  83. package/esm/extension-codemirror/src/types.d.ts +30 -0
  84. package/esm/extension-codemirror/src/types.d.ts.map +1 -0
  85. package/esm/extension-codemirror/src/types.js +1 -0
  86. package/esm/extension-codemirror/src/utils.d.ts +39 -0
  87. package/esm/extension-codemirror/src/utils.d.ts.map +1 -0
  88. package/esm/extension-codemirror/src/utils.js +199 -0
  89. package/esm/extension-codemirror/src/y-remote-selections.d.ts +15 -0
  90. package/esm/extension-codemirror/src/y-remote-selections.d.ts.map +1 -0
  91. package/esm/extension-codemirror/src/y-remote-selections.js +273 -0
  92. package/esm/extension-codemirror/src/y-sync.d.ts +11 -0
  93. package/esm/extension-codemirror/src/y-sync.d.ts.map +1 -0
  94. package/esm/extension-codemirror/src/y-sync.js +29 -0
  95. package/esm/package.json +3 -0
  96. package/package.json +2 -6
@@ -0,0 +1,273 @@
1
+ import * as cmView from '@codemirror/view';
2
+ import * as cmState from '@codemirror/state';
3
+ import * as dom from 'lib0/dom';
4
+ import * as pair from 'lib0/pair';
5
+ import * as math from 'lib0/math';
6
+ import { ySyncFacet } from './y-sync.js';
7
+ export const yRemoteSelectionsTheme = cmView.EditorView.baseTheme({
8
+ '.cm-ySelection': {},
9
+ '.cm-yLineSelection': {
10
+ padding: 0,
11
+ margin: '0px 2px 0px 4px',
12
+ },
13
+ '.cm-ySelectionCaret': {
14
+ position: 'relative',
15
+ borderLeft: '1px solid black',
16
+ borderRight: '1px solid black',
17
+ marginLeft: '-1px',
18
+ marginRight: '-1px',
19
+ boxSizing: 'border-box',
20
+ display: 'inline',
21
+ },
22
+ '.cm-ySelectionCaretDot': {
23
+ borderRadius: '50%',
24
+ position: 'absolute',
25
+ width: '.4em',
26
+ height: '.4em',
27
+ top: '-.2em',
28
+ left: '-.2em',
29
+ backgroundColor: 'inherit',
30
+ transition: 'transform .3s ease-in-out',
31
+ boxSizing: 'border-box',
32
+ },
33
+ '.cm-ySelectionCaret:hover > .cm-ySelectionCaretDot': {
34
+ transformOrigin: 'bottom center',
35
+ transform: 'scale(0)',
36
+ },
37
+ '.cm-ySelectionInfo': {
38
+ position: 'absolute',
39
+ top: '-1.05em',
40
+ left: '-1px',
41
+ fontSize: '.75em',
42
+ fontFamily: 'serif',
43
+ fontStyle: 'normal',
44
+ fontWeight: 'normal',
45
+ lineHeight: 'normal',
46
+ userSelect: 'none',
47
+ color: 'white',
48
+ paddingLeft: '2px',
49
+ paddingRight: '2px',
50
+ zIndex: 101,
51
+ transition: 'opacity .3s ease-in-out',
52
+ backgroundColor: 'inherit',
53
+ // these should be separate
54
+ opacity: 0,
55
+ transitionDelay: '0s',
56
+ whiteSpace: 'nowrap',
57
+ },
58
+ '.cm-ySelectionCaret:hover > .cm-ySelectionInfo': {
59
+ opacity: 1,
60
+ transitionDelay: '0s',
61
+ },
62
+ });
63
+ const yRemoteSelectionsAnnotation = cmState.Annotation.define();
64
+ class YRemoteCaretWidget extends cmView.WidgetType {
65
+ constructor(color, name) {
66
+ super();
67
+ Object.defineProperty(this, "color", {
68
+ enumerable: true,
69
+ configurable: true,
70
+ writable: true,
71
+ value: color
72
+ });
73
+ Object.defineProperty(this, "name", {
74
+ enumerable: true,
75
+ configurable: true,
76
+ writable: true,
77
+ value: name
78
+ });
79
+ }
80
+ toDOM() {
81
+ return (dom.element('span', [
82
+ pair.create('class', 'kb-yjs__cursor kb-widget'),
83
+ pair.create('style', `border-color: ${this.color};`),
84
+ ], [
85
+ dom.text('\u2060'),
86
+ dom.element('div', [
87
+ pair.create('style', `background-color: ${this.color}`),
88
+ ], [
89
+ dom.text(this.name),
90
+ ]),
91
+ dom.text('\u2060'),
92
+ ]));
93
+ }
94
+ eq(widget) {
95
+ return widget.color === this.color;
96
+ }
97
+ compare(widget) {
98
+ return widget.color === this.color;
99
+ }
100
+ updateDOM() {
101
+ return false;
102
+ }
103
+ get estimatedHeight() {
104
+ return -1;
105
+ }
106
+ ignoreEvent() {
107
+ return true;
108
+ }
109
+ }
110
+ export class YRemoteSelectionsPluginValue {
111
+ constructor(view) {
112
+ Object.defineProperty(this, "conf", {
113
+ enumerable: true,
114
+ configurable: true,
115
+ writable: true,
116
+ value: void 0
117
+ });
118
+ Object.defineProperty(this, "_listener", {
119
+ enumerable: true,
120
+ configurable: true,
121
+ writable: true,
122
+ value: void 0
123
+ });
124
+ Object.defineProperty(this, "_awareness", {
125
+ enumerable: true,
126
+ configurable: true,
127
+ writable: true,
128
+ value: void 0
129
+ });
130
+ Object.defineProperty(this, "decorations", {
131
+ enumerable: true,
132
+ configurable: true,
133
+ writable: true,
134
+ value: void 0
135
+ });
136
+ this.conf = view.state.facet(ySyncFacet);
137
+ this._listener = ({ added, updated, removed }) => {
138
+ const clients = added.concat(updated).concat(removed);
139
+ if (clients.findIndex((id) => id !== this.conf.awareness.doc.clientID) >= 0) {
140
+ view.dispatch({ annotations: [yRemoteSelectionsAnnotation.of([])] });
141
+ }
142
+ };
143
+ this._awareness = this.conf.awareness;
144
+ this._awareness.on('change', this._listener);
145
+ this.decorations = cmState.RangeSet.of([]);
146
+ }
147
+ destroy() {
148
+ this._awareness.off('change', this._listener);
149
+ }
150
+ update(update) {
151
+ const awareness = this.conf.awareness;
152
+ const decorations = [];
153
+ const localAwarenessState = this.conf.awareness.getLocalState();
154
+ // set local awareness state (update cursors)
155
+ if (localAwarenessState != null) {
156
+ const hasFocus = update.view.hasFocus &&
157
+ update.view.dom.ownerDocument.hasFocus();
158
+ const sel = hasFocus ? update.state.selection.main : null;
159
+ if (sel != null && 'function' === typeof this.conf.getPmPos) {
160
+ const nodePos = this.conf.getPmPos();
161
+ const currentAnchor = localAwarenessState['cm-cursor'] == null
162
+ ? -1
163
+ : localAwarenessState['cm-cursor'].anchor - nodePos;
164
+ const currentHead = localAwarenessState['cm-cursor'] == null
165
+ ? -1
166
+ : localAwarenessState['cm-cursor'].head - nodePos;
167
+ const anchor = nodePos + sel.anchor;
168
+ const head = nodePos + sel.head;
169
+ if (localAwarenessState['cm-cursor'] == null ||
170
+ (currentAnchor != anchor) || (currentHead != head)) {
171
+ awareness.setLocalStateField('cm-cursor', {
172
+ anchor,
173
+ head,
174
+ });
175
+ }
176
+ }
177
+ else if (localAwarenessState['cm-cursor'] != null && hasFocus) {
178
+ awareness.setLocalStateField('cm-cursor', null);
179
+ }
180
+ }
181
+ // update decorations (remote selections)
182
+ awareness.getStates().forEach((state, clientId) => {
183
+ if (clientId === awareness.doc.clientID) {
184
+ return;
185
+ }
186
+ if (!state.user) {
187
+ return;
188
+ }
189
+ const cursor = state['cm-cursor'];
190
+ if (cursor == null || cursor.anchor == null || cursor.head == null) {
191
+ return;
192
+ }
193
+ if ('function' === typeof this.conf.getPmPos) {
194
+ const nodeAnchor = this.conf.getPmPos();
195
+ const nodeHead = this.conf.getPmPos() + this.conf.getNode().nodeSize;
196
+ if (cursor.anchor >= nodeAnchor && cursor.anchor <= nodeHead) {
197
+ const anchor = { index: cursor.anchor - nodeAnchor };
198
+ const head = { index: cursor.head - nodeAnchor };
199
+ try {
200
+ const { color = '#ffa500', name = `User: ${clientId}` } = state.user || {};
201
+ const colorLight = (state.user && state.user.colorLight) ||
202
+ color + '33';
203
+ const start = math.min(anchor.index, head.index);
204
+ const end = math.max(anchor.index, head.index);
205
+ const startLine = update.view.state.doc.lineAt(start);
206
+ const endLine = update.view.state.doc.lineAt(end);
207
+ if (startLine.number === endLine.number) {
208
+ // selected content in a single line.
209
+ decorations.push({
210
+ from: start,
211
+ to: end,
212
+ value: cmView.Decoration.mark({
213
+ attributes: { style: `background-color: ${colorLight}` },
214
+ class: 'cm-ySelection',
215
+ }),
216
+ });
217
+ }
218
+ else {
219
+ // selected content in multiple lines
220
+ // first, render text-selection in the first line
221
+ decorations.push({
222
+ from: start,
223
+ to: startLine.from + startLine.length,
224
+ value: cmView.Decoration.mark({
225
+ attributes: { style: `background-color: ${colorLight}` },
226
+ class: 'cm-ySelection',
227
+ }),
228
+ });
229
+ // render text-selection in the last line
230
+ decorations.push({
231
+ from: endLine.from,
232
+ to: end,
233
+ value: cmView.Decoration.mark({
234
+ attributes: { style: `background-color: ${colorLight}` },
235
+ class: 'cm-ySelection',
236
+ }),
237
+ });
238
+ for (let i = startLine.number + 1; i < endLine.number; i++) {
239
+ const linePos = update.view.state.doc.line(i).from;
240
+ decorations.push({
241
+ from: linePos,
242
+ to: linePos,
243
+ value: cmView.Decoration.line({
244
+ attributes: {
245
+ style: `background-color: ${colorLight}`,
246
+ class: 'cm-yLineSelection',
247
+ },
248
+ }),
249
+ });
250
+ }
251
+ }
252
+ decorations.push({
253
+ from: head.index,
254
+ to: head.index,
255
+ value: cmView.Decoration.widget({
256
+ side: head.index - anchor.index > 0 ? -1 : 1, // the local cursor should be rendered outside the remote selection
257
+ block: false,
258
+ widget: new YRemoteCaretWidget(color, name),
259
+ }),
260
+ });
261
+ }
262
+ catch (err) {
263
+ console.warn(err, `User: ${clientId}`);
264
+ }
265
+ }
266
+ }
267
+ });
268
+ this.decorations = cmView.Decoration.set(decorations, true);
269
+ }
270
+ }
271
+ export const yRemoteSelections = cmView.ViewPlugin.fromClass(YRemoteSelectionsPluginValue, {
272
+ decorations: (v) => v.decorations,
273
+ });
@@ -0,0 +1,11 @@
1
+ import * as cmState from '@codemirror/state';
2
+ import { Node } from 'prosemirror-model';
3
+ import * as awarenessProtocol from 'y-protocols/awareness';
4
+ export declare class YSyncConfig {
5
+ getNode: () => Node;
6
+ getPmPos: boolean | (() => number);
7
+ awareness: awarenessProtocol.Awareness;
8
+ constructor(getNode: () => Node, getPmPos: boolean | (() => number), awareness: awarenessProtocol.Awareness);
9
+ }
10
+ export declare const ySyncFacet: cmState.Facet<YSyncConfig, YSyncConfig>;
11
+ //# sourceMappingURL=y-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"y-sync.d.ts","sourceRoot":"","sources":["../../../src/extension-codemirror/src/y-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,KAAK,iBAAiB,MAAM,uBAAuB,CAAC;AAE3D,qBAAa,WAAW;IAEb,OAAO,EAAE,MAAM,IAAI;IACnB,QAAQ,EAAE,OAAO,GAAG,CAAC,MAAM,MAAM,CAAC;IAClC,SAAS,EAAE,iBAAiB,CAAC,SAAS;gBAFtC,OAAO,EAAE,MAAM,IAAI,EACnB,QAAQ,EAAE,OAAO,GAAG,CAAC,MAAM,MAAM,CAAC,EAClC,SAAS,EAAE,iBAAiB,CAAC,SAAS;CAGhD;AAED,eAAO,MAAM,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAK3D,CAAC"}
@@ -0,0 +1,29 @@
1
+ import * as cmState from '@codemirror/state'; // eslint-disable-line
2
+ export class YSyncConfig {
3
+ constructor(getNode, getPmPos, awareness) {
4
+ Object.defineProperty(this, "getNode", {
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true,
8
+ value: getNode
9
+ });
10
+ Object.defineProperty(this, "getPmPos", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: getPmPos
15
+ });
16
+ Object.defineProperty(this, "awareness", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: awareness
21
+ });
22
+ }
23
+ }
24
+ export const ySyncFacet = cmState.Facet
25
+ .define({
26
+ combine(inputs) {
27
+ return inputs[inputs.length - 1];
28
+ },
29
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kerebron/extension-codemirror",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "MIT",
5
5
  "module": "./esm/extension-codemirror/src/ExtensionCodeMirror.js",
6
6
  "exports": {
@@ -12,9 +12,6 @@
12
12
  }
13
13
  },
14
14
  "scripts": {},
15
- "files": [
16
- "assets/*.css"
17
- ],
18
15
  "dependencies": {
19
16
  "@codemirror/autocomplete": "6.18.6",
20
17
  "@codemirror/commands": "6.8.1",
@@ -36,8 +33,7 @@
36
33
  "@codemirror/search": "6.5.10",
37
34
  "@codemirror/state": "6.5.2",
38
35
  "@codemirror/view": "6.38.1",
39
- "prosemirror-keymap": "1.2.2",
40
- "prosemirror-model": "1.25.1",
36
+ "prosemirror-model": "1.25.2",
41
37
  "prosemirror-state": "1.4.3",
42
38
  "prosemirror-transform": "1.10.4",
43
39
  "prosemirror-view": "1.40.0"