@kerebron/extension-codemirror 0.1.2 → 0.2.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.
- package/assets/codemirror.css +80 -0
- package/package.json +6 -4
- package/esm/editor/src/CoreEditor.d.ts +0 -25
- package/esm/editor/src/CoreEditor.d.ts.map +0 -1
- package/esm/editor/src/CoreEditor.js +0 -194
- package/esm/editor/src/Extension.d.ts +0 -26
- package/esm/editor/src/Extension.d.ts.map +0 -1
- package/esm/editor/src/Extension.js +0 -33
- package/esm/editor/src/ExtensionManager.d.ts +0 -32
- package/esm/editor/src/ExtensionManager.d.ts.map +0 -1
- package/esm/editor/src/ExtensionManager.js +0 -253
- package/esm/editor/src/Mark.d.ts +0 -18
- package/esm/editor/src/Mark.d.ts.map +0 -1
- package/esm/editor/src/Mark.js +0 -34
- package/esm/editor/src/Node.d.ts +0 -27
- package/esm/editor/src/Node.d.ts.map +0 -1
- package/esm/editor/src/Node.js +0 -43
- package/esm/editor/src/commands/CommandManager.d.ts +0 -20
- package/esm/editor/src/commands/CommandManager.d.ts.map +0 -1
- package/esm/editor/src/commands/CommandManager.js +0 -60
- package/esm/editor/src/commands/createChainableState.d.ts +0 -3
- package/esm/editor/src/commands/createChainableState.d.ts.map +0 -1
- package/esm/editor/src/commands/createChainableState.js +0 -29
- package/esm/editor/src/commands/mod.d.ts +0 -49
- package/esm/editor/src/commands/mod.d.ts.map +0 -1
- package/esm/editor/src/commands/mod.js +0 -928
- package/esm/editor/src/mod.d.ts +0 -6
- package/esm/editor/src/mod.d.ts.map +0 -1
- package/esm/editor/src/mod.js +0 -5
- package/esm/editor/src/nodeToTreeString.d.ts +0 -4
- package/esm/editor/src/nodeToTreeString.d.ts.map +0 -1
- package/esm/editor/src/nodeToTreeString.js +0 -56
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +0 -23
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +0 -1
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +0 -163
- package/esm/editor/src/plugins/input-rules/mod.d.ts +0 -3
- package/esm/editor/src/plugins/input-rules/mod.d.ts.map +0 -1
- package/esm/editor/src/plugins/input-rules/mod.js +0 -2
- package/esm/editor/src/plugins/input-rules/rulebuilders.d.ts +0 -5
- package/esm/editor/src/plugins/input-rules/rulebuilders.d.ts.map +0 -1
- package/esm/editor/src/plugins/input-rules/rulebuilders.js +0 -50
- package/esm/editor/src/types.d.ts +0 -29
- package/esm/editor/src/types.d.ts.map +0 -1
- package/esm/editor/src/types.js +0 -1
- package/esm/editor/src/utilities/createNodeFromContent.d.ts +0 -8
- package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +0 -1
- package/esm/editor/src/utilities/createNodeFromContent.js +0 -33
- package/esm/editor/src/utilities/getHtmlAttributes.d.ts +0 -4
- package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +0 -1
- package/esm/editor/src/utilities/getHtmlAttributes.js +0 -47
- package/esm/editor/src/utilities/mod.d.ts +0 -3
- package/esm/editor/src/utilities/mod.d.ts.map +0 -1
- package/esm/editor/src/utilities/mod.js +0 -2
- package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts +0 -5
- package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts.map +0 -1
- package/esm/extension-codemirror/src/ExtensionCodeMirror.js +0 -4
- package/esm/extension-codemirror/src/NodeCodeMirror.d.ts +0 -27
- package/esm/extension-codemirror/src/NodeCodeMirror.d.ts.map +0 -1
- package/esm/extension-codemirror/src/NodeCodeMirror.js +0 -187
- package/esm/extension-codemirror/src/NodeDocumentCode.d.ts +0 -7
- package/esm/extension-codemirror/src/NodeDocumentCode.d.ts.map +0 -1
- package/esm/extension-codemirror/src/NodeDocumentCode.js +0 -37
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts +0 -6
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts.map +0 -1
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.js +0 -265
- package/esm/extension-codemirror/src/defaults.d.ts +0 -6
- package/esm/extension-codemirror/src/defaults.d.ts.map +0 -1
- package/esm/extension-codemirror/src/defaults.js +0 -57
- package/esm/extension-codemirror/src/languageLoaders.d.ts +0 -5
- package/esm/extension-codemirror/src/languageLoaders.d.ts.map +0 -1
- package/esm/extension-codemirror/src/languageLoaders.js +0 -113
- package/esm/extension-codemirror/src/languages.d.ts +0 -109
- package/esm/extension-codemirror/src/languages.d.ts.map +0 -1
- package/esm/extension-codemirror/src/languages.js +0 -110
- package/esm/extension-codemirror/src/types.d.ts +0 -29
- package/esm/extension-codemirror/src/types.d.ts.map +0 -1
- package/esm/extension-codemirror/src/types.js +0 -1
- package/esm/extension-codemirror/src/utils.d.ts +0 -39
- package/esm/extension-codemirror/src/utils.d.ts.map +0 -1
- package/esm/extension-codemirror/src/utils.js +0 -199
- package/esm/extension-codemirror/src/y-remote-selections.d.ts +0 -15
- package/esm/extension-codemirror/src/y-remote-selections.d.ts.map +0 -1
- package/esm/extension-codemirror/src/y-remote-selections.js +0 -273
- package/esm/extension-codemirror/src/y-sync.d.ts +0 -11
- package/esm/extension-codemirror/src/y-sync.d.ts.map +0 -1
- package/esm/extension-codemirror/src/y-sync.js +0 -29
- package/esm/package.json +0 -3
|
@@ -1,273 +0,0 @@
|
|
|
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', 'ProseMirror-yjs-cursor ProseMirror-widget'),
|
|
83
|
-
pair.create('style', `border-color: ${this.color}; position: fixed;`),
|
|
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
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
});
|
package/esm/package.json
DELETED