@kerebron/extension-basic-editor 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.
- package/package.json +12 -2
- package/esm/ExtensionBaseKeymap.d.ts +0 -7
- package/esm/ExtensionBaseKeymap.d.ts.map +0 -1
- package/esm/ExtensionBaseKeymap.js +0 -55
- package/esm/ExtensionBasicCodeEditor.d.ts +0 -11
- package/esm/ExtensionBasicCodeEditor.d.ts.map +0 -1
- package/esm/ExtensionBasicCodeEditor.js +0 -61
- package/esm/ExtensionBasicEditor.d.ts +0 -46
- package/esm/ExtensionBasicEditor.d.ts.map +0 -1
- package/esm/ExtensionBasicEditor.js +0 -88
- package/esm/ExtensionDropcursor.d.ts +0 -19
- package/esm/ExtensionDropcursor.d.ts.map +0 -1
- package/esm/ExtensionDropcursor.js +0 -186
- package/esm/ExtensionGapcursor.d.ts +0 -32
- package/esm/ExtensionGapcursor.d.ts.map +0 -1
- package/esm/ExtensionGapcursor.js +0 -249
- package/esm/ExtensionHistory.d.ts +0 -15
- package/esm/ExtensionHistory.d.ts.map +0 -1
- package/esm/ExtensionHistory.js +0 -62
- package/esm/ExtensionHtml.d.ts +0 -15
- package/esm/ExtensionHtml.d.ts.map +0 -1
- package/esm/ExtensionHtml.js +0 -99
- package/esm/ExtensionMediaUpload.d.ts +0 -24
- package/esm/ExtensionMediaUpload.d.ts.map +0 -1
- package/esm/ExtensionMediaUpload.js +0 -167
- package/esm/ExtensionSelection.d.ts +0 -11
- package/esm/ExtensionSelection.d.ts.map +0 -1
- package/esm/ExtensionSelection.js +0 -229
- package/esm/MarkBookmark.d.ts +0 -8
- package/esm/MarkBookmark.d.ts.map +0 -1
- package/esm/MarkBookmark.js +0 -16
- package/esm/MarkChange.d.ts +0 -8
- package/esm/MarkChange.d.ts.map +0 -1
- package/esm/MarkChange.js +0 -13
- package/esm/MarkCode.d.ts +0 -11
- package/esm/MarkCode.d.ts.map +0 -1
- package/esm/MarkCode.js +0 -23
- package/esm/MarkHighlight.d.ts +0 -8
- package/esm/MarkHighlight.d.ts.map +0 -1
- package/esm/MarkHighlight.js +0 -35
- package/esm/MarkItalic.d.ts +0 -11
- package/esm/MarkItalic.d.ts.map +0 -1
- package/esm/MarkItalic.js +0 -29
- package/esm/MarkLink.d.ts +0 -8
- package/esm/MarkLink.d.ts.map +0 -1
- package/esm/MarkLink.js +0 -29
- package/esm/MarkStrike.d.ts +0 -11
- package/esm/MarkStrike.d.ts.map +0 -1
- package/esm/MarkStrike.js +0 -26
- package/esm/MarkStrong.d.ts +0 -11
- package/esm/MarkStrong.d.ts.map +0 -1
- package/esm/MarkStrong.js +0 -38
- package/esm/MarkTextColor.d.ts +0 -8
- package/esm/MarkTextColor.d.ts.map +0 -1
- package/esm/MarkTextColor.js +0 -27
- package/esm/MarkUnderline.d.ts +0 -11
- package/esm/MarkUnderline.d.ts.map +0 -1
- package/esm/MarkUnderline.js +0 -33
- package/esm/NodeAside.d.ts +0 -8
- package/esm/NodeAside.d.ts.map +0 -1
- package/esm/NodeAside.js +0 -16
- package/esm/NodeBlockquote.d.ts +0 -13
- package/esm/NodeBlockquote.d.ts.map +0 -1
- package/esm/NodeBlockquote.js +0 -34
- package/esm/NodeBookmark.d.ts +0 -8
- package/esm/NodeBookmark.d.ts.map +0 -1
- package/esm/NodeBookmark.js +0 -19
- package/esm/NodeBulletList.d.ts +0 -13
- package/esm/NodeBulletList.d.ts.map +0 -1
- package/esm/NodeBulletList.js +0 -34
- package/esm/NodeCodeBlock.d.ts +0 -9
- package/esm/NodeCodeBlock.d.ts.map +0 -1
- package/esm/NodeCodeBlock.js +0 -50
- package/esm/NodeDefinitionDesc.d.ts +0 -8
- package/esm/NodeDefinitionDesc.d.ts.map +0 -1
- package/esm/NodeDefinitionDesc.js +0 -16
- package/esm/NodeDefinitionList.d.ts +0 -13
- package/esm/NodeDefinitionList.d.ts.map +0 -1
- package/esm/NodeDefinitionList.js +0 -28
- package/esm/NodeDefinitionTerm.d.ts +0 -8
- package/esm/NodeDefinitionTerm.d.ts.map +0 -1
- package/esm/NodeDefinitionTerm.js +0 -16
- package/esm/NodeDocument.d.ts +0 -7
- package/esm/NodeDocument.d.ts.map +0 -1
- package/esm/NodeDocument.js +0 -19
- package/esm/NodeDocumentCode.d.ts +0 -7
- package/esm/NodeDocumentCode.d.ts.map +0 -1
- package/esm/NodeDocumentCode.js +0 -29
- package/esm/NodeFrontmatter.d.ts +0 -8
- package/esm/NodeFrontmatter.d.ts.map +0 -1
- package/esm/NodeFrontmatter.js +0 -16
- package/esm/NodeHardBreak.d.ts +0 -14
- package/esm/NodeHardBreak.d.ts.map +0 -1
- package/esm/NodeHardBreak.js +0 -67
- package/esm/NodeHeading.d.ts +0 -13
- package/esm/NodeHeading.d.ts.map +0 -1
- package/esm/NodeHeading.js +0 -49
- package/esm/NodeHorizontalRule.d.ts +0 -11
- package/esm/NodeHorizontalRule.d.ts.map +0 -1
- package/esm/NodeHorizontalRule.js +0 -29
- package/esm/NodeImage.d.ts +0 -8
- package/esm/NodeImage.d.ts.map +0 -1
- package/esm/NodeImage.js +0 -33
- package/esm/NodeInlineShortCode.d.ts +0 -10
- package/esm/NodeInlineShortCode.d.ts.map +0 -1
- package/esm/NodeInlineShortCode.js +0 -30
- package/esm/NodeListItem.d.ts +0 -15
- package/esm/NodeListItem.d.ts.map +0 -1
- package/esm/NodeListItem.js +0 -199
- package/esm/NodeMath.d.ts +0 -8
- package/esm/NodeMath.d.ts.map +0 -1
- package/esm/NodeMath.js +0 -99
- package/esm/NodeOrderedList.d.ts +0 -23
- package/esm/NodeOrderedList.d.ts.map +0 -1
- package/esm/NodeOrderedList.js +0 -52
- package/esm/NodeParagraph.d.ts +0 -11
- package/esm/NodeParagraph.d.ts.map +0 -1
- package/esm/NodeParagraph.js +0 -25
- package/esm/NodeTaskItem.d.ts +0 -24
- package/esm/NodeTaskItem.d.ts.map +0 -1
- package/esm/NodeTaskItem.js +0 -139
- package/esm/NodeTaskList.d.ts +0 -11
- package/esm/NodeTaskList.d.ts.map +0 -1
- package/esm/NodeTaskList.js +0 -25
- package/esm/NodeText.d.ts +0 -7
- package/esm/NodeText.d.ts.map +0 -1
- package/esm/NodeText.js +0 -9
- package/esm/NodeVideo.d.ts +0 -8
- package/esm/NodeVideo.d.ts.map +0 -1
- package/esm/NodeVideo.js +0 -45
- package/esm/package.json +0 -3
- package/esm/remote-selection/ExtensionRemoteSelection.d.ts +0 -24
- package/esm/remote-selection/ExtensionRemoteSelection.d.ts.map +0 -1
- package/esm/remote-selection/ExtensionRemoteSelection.js +0 -22
- package/esm/remote-selection/remoteSelectionPlugin.d.ts +0 -25
- package/esm/remote-selection/remoteSelectionPlugin.d.ts.map +0 -1
- package/esm/remote-selection/remoteSelectionPlugin.js +0 -96
package/esm/NodeTaskItem.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { Node } from '@kerebron/editor';
|
|
2
|
-
import { wrappingInputRule } from '@kerebron/editor/plugins/input-rules';
|
|
3
|
-
import { liftListItem, sinkListItem, splitListItem, } from './NodeListItem.js';
|
|
4
|
-
/**
|
|
5
|
-
* Matches a task item to a - [ ] on input.
|
|
6
|
-
*/
|
|
7
|
-
export const inputRegex = /^\s*(\[([( |x])?\])\s$/;
|
|
8
|
-
export class NodeTaskItem extends Node {
|
|
9
|
-
config;
|
|
10
|
-
name = 'task_item';
|
|
11
|
-
requires = ['doc'];
|
|
12
|
-
constructor(config = {}) {
|
|
13
|
-
super(config);
|
|
14
|
-
this.config = config;
|
|
15
|
-
}
|
|
16
|
-
getNodeSpec() {
|
|
17
|
-
return {
|
|
18
|
-
attrs: {
|
|
19
|
-
checked: {
|
|
20
|
-
default: false,
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
content: this.config.nested ? 'paragraph block*' : 'paragraph+',
|
|
24
|
-
parseDOM: [{
|
|
25
|
-
tag: 'li[data-checked]',
|
|
26
|
-
getAttrs(node) {
|
|
27
|
-
return {
|
|
28
|
-
checked: node.getAttribute('data-checked') === 'true',
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
}],
|
|
32
|
-
defining: true,
|
|
33
|
-
toDOM(node) {
|
|
34
|
-
return [
|
|
35
|
-
'li',
|
|
36
|
-
{
|
|
37
|
-
'data-type': this.name,
|
|
38
|
-
'data-checked': node.attrs.checked,
|
|
39
|
-
},
|
|
40
|
-
[
|
|
41
|
-
'label',
|
|
42
|
-
[
|
|
43
|
-
'input',
|
|
44
|
-
{
|
|
45
|
-
type: 'checkbox',
|
|
46
|
-
checked: node.attrs.checked ? 'checked' : null,
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
['span'],
|
|
50
|
-
],
|
|
51
|
-
['div', 0],
|
|
52
|
-
];
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
getCommandFactories(editor, type) {
|
|
57
|
-
return {
|
|
58
|
-
'splitListItem': () => splitListItem(type),
|
|
59
|
-
'liftListItem': () => liftListItem(type),
|
|
60
|
-
'sinkListItem': () => sinkListItem(type),
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
getNodeView(editor) {
|
|
64
|
-
return (node, view, getPos) => {
|
|
65
|
-
const listItem = document.createElement('li');
|
|
66
|
-
const checkboxWrapper = document.createElement('label');
|
|
67
|
-
const checkboxStyler = document.createElement('span');
|
|
68
|
-
const checkbox = document.createElement('input');
|
|
69
|
-
const content = document.createElement('div');
|
|
70
|
-
checkboxWrapper.contentEditable = 'false';
|
|
71
|
-
checkbox.type = 'checkbox';
|
|
72
|
-
checkbox.addEventListener('mousedown', (event) => event.preventDefault());
|
|
73
|
-
checkbox.addEventListener('change', (event) => {
|
|
74
|
-
const isEditable = true; // TODO editor.isEditable
|
|
75
|
-
// if the editor isn’t editable and we don't have a handler for
|
|
76
|
-
// readonly checks we have to undo the latest change
|
|
77
|
-
if (!isEditable && !this.config.onReadOnlyChecked) {
|
|
78
|
-
checkbox.checked = !checkbox.checked;
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const { checked } = event.target;
|
|
82
|
-
if (isEditable && typeof getPos === 'function') {
|
|
83
|
-
editor
|
|
84
|
-
.chain()
|
|
85
|
-
.focus(undefined, { scrollIntoView: false })
|
|
86
|
-
.command(({ tr }) => {
|
|
87
|
-
const position = getPos();
|
|
88
|
-
if (typeof position !== 'number') {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
const currentNode = tr.doc.nodeAt(position);
|
|
92
|
-
tr.setNodeMarkup(position, undefined, {
|
|
93
|
-
...currentNode?.attrs,
|
|
94
|
-
checked,
|
|
95
|
-
});
|
|
96
|
-
return true;
|
|
97
|
-
})
|
|
98
|
-
.run();
|
|
99
|
-
}
|
|
100
|
-
if (!isEditable && this.config.onReadOnlyChecked) {
|
|
101
|
-
// Reset state if onReadOnlyChecked returns false
|
|
102
|
-
if (!this.config.onReadOnlyChecked(node, checked)) {
|
|
103
|
-
checkbox.checked = !checkbox.checked;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
listItem.dataset.checked = node.attrs.checked;
|
|
108
|
-
checkbox.checked = node.attrs.checked;
|
|
109
|
-
checkboxWrapper.append(checkbox, checkboxStyler);
|
|
110
|
-
listItem.append(checkboxWrapper, content);
|
|
111
|
-
return {
|
|
112
|
-
dom: listItem,
|
|
113
|
-
contentDOM: content,
|
|
114
|
-
update: (updatedNode) => {
|
|
115
|
-
if (updatedNode.type.name !== this.type) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
listItem.dataset.checked = updatedNode.attrs.checked;
|
|
119
|
-
checkbox.checked = updatedNode.attrs.checked;
|
|
120
|
-
return true;
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
getKeyboardShortcuts() {
|
|
126
|
-
return {
|
|
127
|
-
'Enter': 'splitListItem',
|
|
128
|
-
'Tab': 'sinkListItem',
|
|
129
|
-
'Shift-Tab': 'liftListItem',
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
getInputRules(type) {
|
|
133
|
-
return [
|
|
134
|
-
wrappingInputRule(inputRegex, type, (match) => ({
|
|
135
|
-
checked: match[match.length - 1] === 'x',
|
|
136
|
-
})),
|
|
137
|
-
];
|
|
138
|
-
}
|
|
139
|
-
}
|
package/esm/NodeTaskList.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { NodeSpec, NodeType } from 'prosemirror-model';
|
|
2
|
-
import { type CoreEditor, Node } from '@kerebron/editor';
|
|
3
|
-
import { type CommandFactories, type CommandShortcuts } from '@kerebron/editor/commands';
|
|
4
|
-
export declare class NodeTaskList extends Node {
|
|
5
|
-
name: string;
|
|
6
|
-
requires: string[];
|
|
7
|
-
getNodeSpec(): NodeSpec;
|
|
8
|
-
getCommandFactories(editor: CoreEditor, type: NodeType): Partial<CommandFactories>;
|
|
9
|
-
getKeyboardShortcuts(): Partial<CommandShortcuts>;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=NodeTaskList.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NodeTaskList.d.ts","sourceRoot":"","sources":["../src/NodeTaskList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAE,KAAK,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACtB,MAAM,2BAA2B,CAAC;AAEnC,qBAAa,YAAa,SAAQ,IAAI;IAC3B,IAAI,SAAe;IAC5B,QAAQ,WAAW;IAEV,WAAW,IAAI,QAAQ;IAWvB,mBAAmB,CAC1B,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,QAAQ,GACb,OAAO,CAAC,gBAAgB,CAAC;IAMnB,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAK3D"}
|
package/esm/NodeTaskList.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Node } from '@kerebron/editor';
|
|
2
|
-
export class NodeTaskList extends Node {
|
|
3
|
-
name = 'task_list';
|
|
4
|
-
requires = ['doc'];
|
|
5
|
-
getNodeSpec() {
|
|
6
|
-
return {
|
|
7
|
-
content: 'list_item+',
|
|
8
|
-
group: 'block',
|
|
9
|
-
parseDOM: [{ tag: `ul[data-type="${this.name}"]` }],
|
|
10
|
-
toDOM() {
|
|
11
|
-
return ['ul', { 'data-type': this.name }, 0];
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
getCommandFactories(editor, type) {
|
|
16
|
-
return {
|
|
17
|
-
'toggleTaskList': () => editor.commandFactories.wrapInList(type),
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
getKeyboardShortcuts() {
|
|
21
|
-
return {
|
|
22
|
-
'Shift-Ctrl-9': 'toggleTaskList',
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
package/esm/NodeText.d.ts
DELETED
package/esm/NodeText.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NodeText.d.ts","sourceRoot":"","sources":["../src/NodeText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,qBAAa,QAAS,SAAQ,IAAI;IACvB,IAAI,SAAU;IAEd,WAAW,IAAI,QAAQ;CAKjC"}
|
package/esm/NodeText.js
DELETED
package/esm/NodeVideo.d.ts
DELETED
package/esm/NodeVideo.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NodeVideo.d.ts","sourceRoot":"","sources":["../src/NodeVideo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,qBAAa,SAAU,SAAQ,IAAI;IACxB,IAAI,SAAW;IACxB,QAAQ,WAAW;IAEV,WAAW,IAAI,QAAQ;CAoCjC"}
|
package/esm/NodeVideo.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Node } from '@kerebron/editor';
|
|
2
|
-
export class NodeVideo extends Node {
|
|
3
|
-
name = 'video';
|
|
4
|
-
requires = ['doc'];
|
|
5
|
-
getNodeSpec() {
|
|
6
|
-
return {
|
|
7
|
-
attrs: {
|
|
8
|
-
src: {},
|
|
9
|
-
title: { default: null },
|
|
10
|
-
controls: { default: true },
|
|
11
|
-
width: { default: null },
|
|
12
|
-
height: { default: null },
|
|
13
|
-
},
|
|
14
|
-
group: 'block',
|
|
15
|
-
draggable: true,
|
|
16
|
-
parseDOM: [
|
|
17
|
-
{
|
|
18
|
-
tag: 'video[src]',
|
|
19
|
-
getAttrs(dom) {
|
|
20
|
-
return {
|
|
21
|
-
src: dom.getAttribute('src'),
|
|
22
|
-
title: dom.getAttribute('title'),
|
|
23
|
-
controls: dom.hasAttribute('controls'),
|
|
24
|
-
width: dom.getAttribute('width'),
|
|
25
|
-
height: dom.getAttribute('height'),
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
toDOM(node) {
|
|
31
|
-
const { src, title, controls, width, height } = node.attrs;
|
|
32
|
-
const attrs = { src };
|
|
33
|
-
if (title)
|
|
34
|
-
attrs.title = title;
|
|
35
|
-
if (controls)
|
|
36
|
-
attrs.controls = ''; // Boolean attribute - just needs to be present
|
|
37
|
-
if (width)
|
|
38
|
-
attrs.width = width;
|
|
39
|
-
if (height)
|
|
40
|
-
attrs.height = height;
|
|
41
|
-
return ['video', attrs];
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
}
|
package/esm/package.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'prosemirror-state';
|
|
2
|
-
import { Extension } from '@kerebron/editor';
|
|
3
|
-
type Color = string;
|
|
4
|
-
export interface SelectionState {
|
|
5
|
-
clientId: number;
|
|
6
|
-
user: {
|
|
7
|
-
name: string;
|
|
8
|
-
color: Color;
|
|
9
|
-
colorLight: Color;
|
|
10
|
-
};
|
|
11
|
-
cursor?: {
|
|
12
|
-
anchor: number;
|
|
13
|
-
head: number;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export { remoteSelectionPluginKey } from './remoteSelectionPlugin.js';
|
|
17
|
-
export declare class ExtensionRemoteSelection extends Extension {
|
|
18
|
-
name: string;
|
|
19
|
-
private remoteStates;
|
|
20
|
-
getProseMirrorPlugins(): Plugin[];
|
|
21
|
-
getRemoteStates(): SelectionState[];
|
|
22
|
-
setRemoteStates(states: SelectionState[]): void;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=ExtensionRemoteSelection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionRemoteSelection.d.ts","sourceRoot":"","sources":["../../src/remote-selection/ExtensionRemoteSelection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAmB,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAI9D,KAAK,KAAK,GAAG,MAAM,CAAC;AAEpB,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,KAAK,CAAC;QACb,UAAU,EAAE,KAAK,CAAC;KACnB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,qBAAa,wBAAyB,SAAQ,SAAS;IAC5C,IAAI,SAAsB;IAEnC,OAAO,CAAC,YAAY,CAAwB;IAEnC,qBAAqB,IAAI,MAAM,EAAE;IAM1C,eAAe,IAAI,cAAc,EAAE;IAInC,eAAe,CAAC,MAAM,EAAE,cAAc,EAAE;CAOzC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Extension } from '@kerebron/editor';
|
|
2
|
-
import { remoteSelectionPlugin } from './remoteSelectionPlugin.js';
|
|
3
|
-
export { remoteSelectionPluginKey } from './remoteSelectionPlugin.js';
|
|
4
|
-
export class ExtensionRemoteSelection extends Extension {
|
|
5
|
-
name = 'remote-selection';
|
|
6
|
-
remoteStates = [];
|
|
7
|
-
getProseMirrorPlugins() {
|
|
8
|
-
return [
|
|
9
|
-
remoteSelectionPlugin(this, this.editor),
|
|
10
|
-
];
|
|
11
|
-
}
|
|
12
|
-
getRemoteStates() {
|
|
13
|
-
return this.remoteStates;
|
|
14
|
-
}
|
|
15
|
-
setRemoteStates(states) {
|
|
16
|
-
this.remoteStates = states;
|
|
17
|
-
const event = new CustomEvent('remoteSelectionChange', {
|
|
18
|
-
detail: {},
|
|
19
|
-
});
|
|
20
|
-
this.editor.dispatchEvent(event);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
-
import { type DecorationAttrs } from 'prosemirror-view';
|
|
3
|
-
import type { CoreEditor } from '@kerebron/editor';
|
|
4
|
-
import type { ExtensionRemoteSelection } from './ExtensionRemoteSelection.js';
|
|
5
|
-
export declare const remoteSelectionPluginKey: PluginKey<any>;
|
|
6
|
-
/**
|
|
7
|
-
* Default generator for a cursor element
|
|
8
|
-
*/
|
|
9
|
-
export declare const defaultCursorBuilder: (user: any) => HTMLElement;
|
|
10
|
-
/**
|
|
11
|
-
* Default generator for the selection attributes
|
|
12
|
-
*/
|
|
13
|
-
export declare const defaultSelectionBuilder: (user: any) => DecorationAttrs;
|
|
14
|
-
export declare const createDecorations: (state: any, extension: ExtensionRemoteSelection, createCursor: (user: {
|
|
15
|
-
name: string;
|
|
16
|
-
color: string;
|
|
17
|
-
}, clientId: number) => Element, createSelection: (user: {
|
|
18
|
-
name: string;
|
|
19
|
-
color: string;
|
|
20
|
-
}, clientId: number) => DecorationAttrs) => any;
|
|
21
|
-
export declare const remoteSelectionPlugin: (extension: ExtensionRemoteSelection, editor: CoreEditor, { cursorBuilder, selectionBuilder, }?: {
|
|
22
|
-
cursorBuilder?: (user: any, clientId: number) => HTMLElement;
|
|
23
|
-
selectionBuilder?: (user: any, clientId: number) => DecorationAttrs;
|
|
24
|
-
}) => Plugin<any>;
|
|
25
|
-
//# sourceMappingURL=remoteSelectionPlugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remoteSelectionPlugin.d.ts","sourceRoot":"","sources":["../../src/remote-selection/remoteSelectionPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAE9E,eAAO,MAAM,wBAAwB,gBAAoC,CAAC;AAE1E;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,MAAM,GAAG,KAAG,WAahD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAAI,MAAM,GAAG,KAAG,eAKnD,CAAC;AAIF,eAAO,MAAM,iBAAiB,GAC5B,OAAO,GAAG,EACV,WAAW,wBAAwB,EACnC,cAAc,CACZ,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EACrC,QAAQ,EAAE,MAAM,KACb,OAAO,EACZ,iBAAiB,CACf,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EACrC,QAAQ,EAAE,MAAM,KACb,eAAe,KACnB,GAwDF,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,WAAW,wBAAwB,EACnC,QAAQ,UAAU,EAClB,uCAGG;IACD,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,KAAK,WAAW,CAAC;IAC7D,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,KAAK,eAAe,CAAC;CAChE,gBAsCP,CAAC"}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
2
|
-
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
3
|
-
export const remoteSelectionPluginKey = new PluginKey('remote-selection');
|
|
4
|
-
/**
|
|
5
|
-
* Default generator for a cursor element
|
|
6
|
-
*/
|
|
7
|
-
export const defaultCursorBuilder = (user) => {
|
|
8
|
-
const cursor = document.createElement('span');
|
|
9
|
-
cursor.classList.add('kb-yjs__cursor');
|
|
10
|
-
cursor.setAttribute('style', `border-color: ${user.color};`);
|
|
11
|
-
const userDiv = document.createElement('div');
|
|
12
|
-
userDiv.setAttribute('style', `background-color: ${user.color}`);
|
|
13
|
-
userDiv.insertBefore(document.createTextNode(user.name), null);
|
|
14
|
-
const nonbreakingSpace1 = document.createTextNode('\u2060');
|
|
15
|
-
const nonbreakingSpace2 = document.createTextNode('\u2060');
|
|
16
|
-
cursor.insertBefore(nonbreakingSpace1, null);
|
|
17
|
-
cursor.insertBefore(userDiv, null);
|
|
18
|
-
cursor.insertBefore(nonbreakingSpace2, null);
|
|
19
|
-
return cursor;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Default generator for the selection attributes
|
|
23
|
-
*/
|
|
24
|
-
export const defaultSelectionBuilder = (user) => {
|
|
25
|
-
return {
|
|
26
|
-
style: `background-color: ${user.color}70`,
|
|
27
|
-
class: 'kb-yjs__selection',
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
const rxValidColor = /^#[0-9a-fA-F]{6}$/;
|
|
31
|
-
export const createDecorations = (state, extension, createCursor, createSelection) => {
|
|
32
|
-
const decorations = [];
|
|
33
|
-
const remoteStates = extension.getRemoteStates();
|
|
34
|
-
if (remoteStates.length === 0) {
|
|
35
|
-
return DecorationSet.create(state.doc, []);
|
|
36
|
-
}
|
|
37
|
-
for (const remoteState of remoteStates) {
|
|
38
|
-
if (remoteState.cursor != null) {
|
|
39
|
-
const user = remoteState.user || {};
|
|
40
|
-
if (user.color == null) {
|
|
41
|
-
user.color = '#ffa500';
|
|
42
|
-
}
|
|
43
|
-
else if (!rxValidColor.test(user.color)) {
|
|
44
|
-
// We only support 6-digit RGB colors in y-prosemirror
|
|
45
|
-
console.warn('A user uses an unsupported color format', user);
|
|
46
|
-
}
|
|
47
|
-
if (user.name == null) {
|
|
48
|
-
user.name = `User: ${remoteState.clientId}`;
|
|
49
|
-
}
|
|
50
|
-
const cursor = remoteState.cursor;
|
|
51
|
-
let anchor = cursor.anchor || null;
|
|
52
|
-
let head = cursor.head || null;
|
|
53
|
-
if (anchor !== null && head !== null) {
|
|
54
|
-
const maxsize = Math.max(state.doc.content.size - 1, 0);
|
|
55
|
-
anchor = Math.min(anchor, maxsize);
|
|
56
|
-
head = Math.min(head, maxsize);
|
|
57
|
-
decorations.push(Decoration.widget(head, () => createCursor(user, remoteState.clientId), {
|
|
58
|
-
key: remoteState.clientId + '',
|
|
59
|
-
side: 10,
|
|
60
|
-
}));
|
|
61
|
-
const from = Math.min(anchor, head);
|
|
62
|
-
const to = Math.max(anchor, head);
|
|
63
|
-
decorations.push(Decoration.inline(from, to, createSelection(user, remoteState.clientId), {
|
|
64
|
-
inclusiveEnd: true,
|
|
65
|
-
inclusiveStart: false,
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return DecorationSet.create(state.doc, decorations);
|
|
71
|
-
};
|
|
72
|
-
export const remoteSelectionPlugin = (extension, editor, { cursorBuilder = defaultCursorBuilder, selectionBuilder = defaultSelectionBuilder, } = {}) => {
|
|
73
|
-
return new Plugin({
|
|
74
|
-
key: remoteSelectionPluginKey,
|
|
75
|
-
state: {
|
|
76
|
-
init(_, state) {
|
|
77
|
-
return createDecorations(state, extension, cursorBuilder, selectionBuilder);
|
|
78
|
-
},
|
|
79
|
-
apply(tr, prevState, _oldState, newState) {
|
|
80
|
-
const remoteCursorState = tr.getMeta(remoteSelectionPluginKey);
|
|
81
|
-
// TODO validate: isChangeOrigin
|
|
82
|
-
// const state = remoteSelectionPluginKey.getState(newState);
|
|
83
|
-
if ((remoteCursorState?.isChangeOrigin) ||
|
|
84
|
-
(remoteCursorState?.remotePositionUpdated)) {
|
|
85
|
-
return createDecorations(newState, extension, cursorBuilder, selectionBuilder);
|
|
86
|
-
}
|
|
87
|
-
return prevState.map(tr.mapping, tr.doc);
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
props: {
|
|
91
|
-
decorations: (state) => {
|
|
92
|
-
return remoteSelectionPluginKey.getState(state);
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
};
|