@kerebron/extension-basic-editor 0.0.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.
- package/LICENSE +23 -0
- package/README.md +31 -0
- package/esm/ExtensionBaseKeymap.d.ts +8 -0
- package/esm/ExtensionBaseKeymap.d.ts.map +1 -0
- package/esm/ExtensionBaseKeymap.js +37 -0
- package/esm/ExtensionBasicEditor.d.ts +26 -0
- package/esm/ExtensionBasicEditor.d.ts.map +1 -0
- package/esm/ExtensionBasicEditor.js +59 -0
- package/esm/ExtensionDropcursor.d.ts +12 -0
- package/esm/ExtensionDropcursor.d.ts.map +1 -0
- package/esm/ExtensionDropcursor.js +28 -0
- package/esm/ExtensionGapcursor.d.ts +12 -0
- package/esm/ExtensionGapcursor.d.ts.map +1 -0
- package/esm/ExtensionGapcursor.js +28 -0
- package/esm/ExtensionHistory.d.ts +14 -0
- package/esm/ExtensionHistory.d.ts.map +1 -0
- package/esm/ExtensionHistory.js +49 -0
- package/esm/MarkCode.d.ts +14 -0
- package/esm/MarkCode.d.ts.map +1 -0
- package/esm/MarkCode.js +45 -0
- package/esm/MarkItalic.d.ts +13 -0
- package/esm/MarkItalic.d.ts.map +1 -0
- package/esm/MarkItalic.js +51 -0
- package/esm/MarkLink.d.ts +18 -0
- package/esm/MarkLink.d.ts.map +1 -0
- package/esm/MarkLink.js +74 -0
- package/esm/MarkStrong.d.ts +14 -0
- package/esm/MarkStrong.d.ts.map +1 -0
- package/esm/MarkStrong.js +60 -0
- package/esm/MarkUnderline.d.ts +13 -0
- package/esm/MarkUnderline.d.ts.map +1 -0
- package/esm/MarkUnderline.js +55 -0
- package/esm/NodeAside.d.ts +11 -0
- package/esm/NodeAside.d.ts.map +1 -0
- package/esm/NodeAside.js +37 -0
- package/esm/NodeBlockquote.d.ts +16 -0
- package/esm/NodeBlockquote.d.ts.map +1 -0
- package/esm/NodeBlockquote.js +56 -0
- package/esm/NodeBulletList.d.ts +16 -0
- package/esm/NodeBulletList.d.ts.map +1 -0
- package/esm/NodeBulletList.js +56 -0
- package/esm/NodeDocument.d.ts +7 -0
- package/esm/NodeDocument.d.ts.map +1 -0
- package/esm/NodeDocument.js +26 -0
- package/esm/NodeHardBreak.d.ts +11 -0
- package/esm/NodeHardBreak.d.ts.map +1 -0
- package/esm/NodeHardBreak.js +98 -0
- package/esm/NodeHeading.d.ts +24 -0
- package/esm/NodeHeading.d.ts.map +1 -0
- package/esm/NodeHeading.js +75 -0
- package/esm/NodeHorizontalRule.d.ts +11 -0
- package/esm/NodeHorizontalRule.d.ts.map +1 -0
- package/esm/NodeHorizontalRule.js +43 -0
- package/esm/NodeImage.d.ts +25 -0
- package/esm/NodeImage.d.ts.map +1 -0
- package/esm/NodeImage.js +68 -0
- package/esm/NodeListItem.d.ts +13 -0
- package/esm/NodeListItem.d.ts.map +1 -0
- package/esm/NodeListItem.js +217 -0
- package/esm/NodeOrderedList.d.ts +22 -0
- package/esm/NodeOrderedList.d.ts.map +1 -0
- package/esm/NodeOrderedList.js +72 -0
- package/esm/NodeParagraph.d.ts +14 -0
- package/esm/NodeParagraph.d.ts.map +1 -0
- package/esm/NodeParagraph.js +47 -0
- package/esm/NodeText.d.ts +8 -0
- package/esm/NodeText.d.ts.map +1 -0
- package/esm/NodeText.js +23 -0
- package/esm/package.json +3 -0
- package/package.json +78 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Node as PmNode, type NodeSpec } from 'prosemirror-model';
|
|
2
|
+
import { Node } from '@kerebron/editor';
|
|
3
|
+
import { BlockMarker } from '@kerebron/extension-automerge';
|
|
4
|
+
export declare class NodeImage extends Node {
|
|
5
|
+
name: string;
|
|
6
|
+
requires: string[];
|
|
7
|
+
automerge: {
|
|
8
|
+
block: string;
|
|
9
|
+
isEmbed: boolean;
|
|
10
|
+
attrParsers: {
|
|
11
|
+
fromAutomerge: (block: BlockMarker) => {
|
|
12
|
+
src: any;
|
|
13
|
+
alt: any;
|
|
14
|
+
title: any;
|
|
15
|
+
};
|
|
16
|
+
fromProsemirror: (node: PmNode) => {
|
|
17
|
+
src: any;
|
|
18
|
+
alt: any;
|
|
19
|
+
title: any;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
getNodeSpec(): NodeSpec;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=NodeImage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeImage.d.ts","sourceRoot":"","sources":["../src/NodeImage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,IAAI,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,qBAAa,SAAU,SAAQ,IAAI;IACxB,IAAI,SAAW;IACxB,QAAQ,WAAW;IAEnB,SAAS;;;;mCAIkB,WAAW;;;;;oCAKV,MAAM;;;;;;MAMhC;IAEO,WAAW,IAAI,QAAQ;CA4BjC"}
|
package/esm/NodeImage.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Node } from '@kerebron/editor';
|
|
2
|
+
import { next as automerge } from '@automerge/automerge/slim';
|
|
3
|
+
export class NodeImage extends Node {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
Object.defineProperty(this, "name", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: 'image'
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(this, "requires", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: ['doc']
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "automerge", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: {
|
|
23
|
+
block: 'image',
|
|
24
|
+
isEmbed: true,
|
|
25
|
+
attrParsers: {
|
|
26
|
+
fromAutomerge: (block) => ({
|
|
27
|
+
src: block.attrs.src?.toString() || null,
|
|
28
|
+
alt: block.attrs.alt,
|
|
29
|
+
title: block.attrs.title,
|
|
30
|
+
}),
|
|
31
|
+
fromProsemirror: (node) => ({
|
|
32
|
+
src: new automerge.RawString(node.attrs.src),
|
|
33
|
+
alt: node.attrs.alt,
|
|
34
|
+
title: node.attrs.title,
|
|
35
|
+
}),
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
getNodeSpec() {
|
|
41
|
+
return {
|
|
42
|
+
inline: true,
|
|
43
|
+
attrs: {
|
|
44
|
+
src: {},
|
|
45
|
+
alt: { default: null },
|
|
46
|
+
title: { default: null },
|
|
47
|
+
},
|
|
48
|
+
group: 'inline',
|
|
49
|
+
draggable: true,
|
|
50
|
+
parseDOM: [
|
|
51
|
+
{
|
|
52
|
+
tag: 'img[src]',
|
|
53
|
+
getAttrs(dom) {
|
|
54
|
+
return {
|
|
55
|
+
src: dom.getAttribute('src'),
|
|
56
|
+
title: dom.getAttribute('title'),
|
|
57
|
+
alt: dom.getAttribute('alt'),
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
toDOM(node) {
|
|
63
|
+
const { src, alt, title } = node.attrs;
|
|
64
|
+
return ['img', { src, alt, title }];
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type CoreEditor, Node } from '@kerebron/editor';
|
|
2
|
+
import { type Commands, type CommandShortcuts } from '@kerebron/editor/commands';
|
|
3
|
+
export declare class NodeListItem extends Node {
|
|
4
|
+
name: string;
|
|
5
|
+
requires: string[];
|
|
6
|
+
automerge: {
|
|
7
|
+
block: string;
|
|
8
|
+
};
|
|
9
|
+
getNodeSpec(): NodeSpec;
|
|
10
|
+
getCommands(editor: CoreEditor, type: NodeType): Partial<Commands>;
|
|
11
|
+
getKeyboardShortcuts(): Partial<CommandShortcuts>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=NodeListItem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeListItem.d.ts","sourceRoot":"","sources":["../src/NodeListItem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EAEtB,MAAM,2BAA2B,CAAC;AA8PnC,qBAAa,YAAa,SAAQ,IAAI;IAC3B,IAAI,SAAe;IAC5B,QAAQ,WAAW;IAEnB,SAAS;;MAEP;IAEO,WAAW,IAAI,QAAQ;IAWhC,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAQlE,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAOlD"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { Node } from '@kerebron/editor';
|
|
2
|
+
/// Build a command that splits a non-empty textblock at the top level
|
|
3
|
+
/// of a list item by also splitting that list item.
|
|
4
|
+
function splitListItem(itemType, itemAttrs) {
|
|
5
|
+
return function (state, dispatch) {
|
|
6
|
+
const { $from, $to, node } = state.selection;
|
|
7
|
+
if ((node && node.isBlock) || $from.depth < 2 || !$from.sameParent($to)) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const grandParent = $from.node(-1);
|
|
11
|
+
if (grandParent.type != itemType)
|
|
12
|
+
return false;
|
|
13
|
+
if ($from.parent.content.size == 0 &&
|
|
14
|
+
$from.node(-1).childCount == $from.indexAfter(-1)) {
|
|
15
|
+
// In an empty block. If this is a nested list, the wrapping
|
|
16
|
+
// list item should be split. Otherwise, bail out and let next
|
|
17
|
+
// command handle lifting.
|
|
18
|
+
if ($from.depth == 3 || $from.node(-3).type != itemType ||
|
|
19
|
+
$from.index(-2) != $from.node(-2).childCount - 1)
|
|
20
|
+
return false;
|
|
21
|
+
if (dispatch) {
|
|
22
|
+
let wrap = Fragment.empty;
|
|
23
|
+
const depthBefore = $from.index(-1) ? 1 : $from.index(-2) ? 2 : 3;
|
|
24
|
+
// Build a fragment containing empty versions of the structure
|
|
25
|
+
// from the outer list item to the parent node of the cursor
|
|
26
|
+
for (let d = $from.depth - depthBefore; d >= $from.depth - 3; d--) {
|
|
27
|
+
wrap = Fragment.from($from.node(d).copy(wrap));
|
|
28
|
+
}
|
|
29
|
+
let depthAfter = $from.indexAfter(-1) < $from.node(-2).childCount
|
|
30
|
+
? 1
|
|
31
|
+
: $from.indexAfter(-2) < $from.node(-3).childCount
|
|
32
|
+
? 2
|
|
33
|
+
: 3;
|
|
34
|
+
// Add a second list item with an empty default start node
|
|
35
|
+
wrap = wrap.append(Fragment.from(itemType.createAndFill()));
|
|
36
|
+
let start = $from.before($from.depth - (depthBefore - 1));
|
|
37
|
+
let tr = state.tr.replace(start, $from.after(-depthAfter), new Slice(wrap, 4 - depthBefore, 0));
|
|
38
|
+
let sel = -1;
|
|
39
|
+
tr.doc.nodesBetween(start, tr.doc.content.size, (node, pos) => {
|
|
40
|
+
if (sel > -1)
|
|
41
|
+
return false;
|
|
42
|
+
if (node.isTextblock && node.content.size == 0)
|
|
43
|
+
sel = pos + 1;
|
|
44
|
+
});
|
|
45
|
+
if (sel > -1)
|
|
46
|
+
tr.setSelection(Selection.near(tr.doc.resolve(sel)));
|
|
47
|
+
dispatch(tr.scrollIntoView());
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
let nextType = $to.pos == $from.end()
|
|
52
|
+
? grandParent.contentMatchAt(0).defaultType
|
|
53
|
+
: null;
|
|
54
|
+
let tr = state.tr.delete($from.pos, $to.pos);
|
|
55
|
+
let types = nextType
|
|
56
|
+
? [itemAttrs ? { type: itemType, attrs: itemAttrs } : null, {
|
|
57
|
+
type: nextType,
|
|
58
|
+
}]
|
|
59
|
+
: undefined;
|
|
60
|
+
if (!canSplit(tr.doc, $from.pos, 2, types))
|
|
61
|
+
return false;
|
|
62
|
+
if (dispatch)
|
|
63
|
+
dispatch(tr.split($from.pos, 2, types).scrollIntoView());
|
|
64
|
+
return true;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/// Acts like [`splitListItem`](#schema-list.splitListItem), but
|
|
68
|
+
/// without resetting the set of active marks at the cursor.
|
|
69
|
+
function splitListItemKeepMarks(itemType, itemAttrs) {
|
|
70
|
+
let split = splitListItem(itemType, itemAttrs);
|
|
71
|
+
return (state, dispatch) => {
|
|
72
|
+
return split(state, dispatch && ((tr) => {
|
|
73
|
+
let marks = state.storedMarks ||
|
|
74
|
+
(state.selection.$to.parentOffset && state.selection.$from.marks());
|
|
75
|
+
if (marks)
|
|
76
|
+
tr.ensureMarks(marks);
|
|
77
|
+
dispatch(tr);
|
|
78
|
+
}));
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/// Create a command to lift the list item around the selection up into
|
|
82
|
+
/// a wrapping list.
|
|
83
|
+
function liftListItem(itemType) {
|
|
84
|
+
return function (state, dispatch) {
|
|
85
|
+
let { $from, $to } = state.selection;
|
|
86
|
+
let range = $from.blockRange($to, (node) => node.childCount > 0 && node.firstChild.type == itemType);
|
|
87
|
+
if (!range)
|
|
88
|
+
return false;
|
|
89
|
+
if (!dispatch)
|
|
90
|
+
return true;
|
|
91
|
+
if ($from.node(range.depth - 1).type == itemType) { // Inside a parent list
|
|
92
|
+
return liftToOuterList(state, dispatch, itemType, range);
|
|
93
|
+
} // Outer list node
|
|
94
|
+
else {
|
|
95
|
+
return liftOutOfList(state, dispatch, range);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function liftToOuterList(state, dispatch, itemType, range) {
|
|
100
|
+
let tr = state.tr, end = range.end, endOfList = range.$to.end(range.depth);
|
|
101
|
+
if (end < endOfList) {
|
|
102
|
+
// There are siblings after the lifted items, which must become
|
|
103
|
+
// children of the last item
|
|
104
|
+
tr.step(new ReplaceAroundStep(end - 1, endOfList, end, endOfList, new Slice(Fragment.from(itemType.create(null, range.parent.copy())), 1, 0), 1, true));
|
|
105
|
+
range = new NodeRange(tr.doc.resolve(range.$from.pos), tr.doc.resolve(endOfList), range.depth);
|
|
106
|
+
}
|
|
107
|
+
const target = liftTarget(range);
|
|
108
|
+
if (target == null)
|
|
109
|
+
return false;
|
|
110
|
+
tr.lift(range, target);
|
|
111
|
+
let $after = tr.doc.resolve(tr.mapping.map(end, -1) - 1);
|
|
112
|
+
if (canJoin(tr.doc, $after.pos) &&
|
|
113
|
+
$after.nodeBefore.type == $after.nodeAfter.type)
|
|
114
|
+
tr.join($after.pos);
|
|
115
|
+
dispatch(tr.scrollIntoView());
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
function liftOutOfList(state, dispatch, range) {
|
|
119
|
+
let tr = state.tr, list = range.parent;
|
|
120
|
+
// Merge the list items into a single big item
|
|
121
|
+
for (let pos = range.end, i = range.endIndex - 1, e = range.startIndex; i > e; i--) {
|
|
122
|
+
pos -= list.child(i).nodeSize;
|
|
123
|
+
tr.delete(pos - 1, pos + 1);
|
|
124
|
+
}
|
|
125
|
+
let $start = tr.doc.resolve(range.start), item = $start.nodeAfter;
|
|
126
|
+
if (tr.mapping.map(range.end) != range.start + $start.nodeAfter.nodeSize) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
let atStart = range.startIndex == 0, atEnd = range.endIndex == list.childCount;
|
|
130
|
+
let parent = $start.node(-1), indexBefore = $start.index(-1);
|
|
131
|
+
if (!parent.canReplace(indexBefore + (atStart ? 0 : 1), indexBefore + 1, item.content.append(atEnd ? Fragment.empty : Fragment.from(list)))) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
let start = $start.pos, end = start + item.nodeSize;
|
|
135
|
+
// Strip off the surrounding list. At the sides where we're not at
|
|
136
|
+
// the end of the list, the existing list is closed. At sides where
|
|
137
|
+
// this is the end, it is overwritten to its end.
|
|
138
|
+
tr.step(new ReplaceAroundStep(start - (atStart ? 1 : 0), end + (atEnd ? 1 : 0), start + 1, end - 1, new Slice((atStart ? Fragment.empty : Fragment.from(list.copy(Fragment.empty)))
|
|
139
|
+
.append(atEnd ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))), atStart ? 0 : 1, atEnd ? 0 : 1), atStart ? 0 : 1));
|
|
140
|
+
dispatch(tr.scrollIntoView());
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
/// Create a command to sink the list item around the selection down
|
|
144
|
+
/// into an inner list.
|
|
145
|
+
function sinkListItem(itemType) {
|
|
146
|
+
return function (state, dispatch) {
|
|
147
|
+
const { $from, $to } = state.selection;
|
|
148
|
+
const range = $from.blockRange($to, (node) => node.childCount > 0 && node.firstChild.type == itemType);
|
|
149
|
+
if (!range)
|
|
150
|
+
return false;
|
|
151
|
+
const startIndex = range.startIndex;
|
|
152
|
+
if (startIndex == 0)
|
|
153
|
+
return false;
|
|
154
|
+
const parent = range.parent, nodeBefore = parent.child(startIndex - 1);
|
|
155
|
+
if (nodeBefore.type != itemType)
|
|
156
|
+
return false;
|
|
157
|
+
if (dispatch) {
|
|
158
|
+
const nestedBefore = nodeBefore.lastChild &&
|
|
159
|
+
nodeBefore.lastChild.type == parent.type;
|
|
160
|
+
const inner = Fragment.from(nestedBefore ? itemType.create() : null);
|
|
161
|
+
const slice = new Slice(Fragment.from(itemType.create(null, Fragment.from(parent.type.create(null, inner)))), nestedBefore ? 3 : 1, 0);
|
|
162
|
+
const before = range.start, after = range.end;
|
|
163
|
+
dispatch(state.tr.step(new ReplaceAroundStep(before - (nestedBefore ? 3 : 1), after, before, after, slice, 1, true))
|
|
164
|
+
.scrollIntoView());
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
export class NodeListItem extends Node {
|
|
170
|
+
constructor() {
|
|
171
|
+
super(...arguments);
|
|
172
|
+
Object.defineProperty(this, "name", {
|
|
173
|
+
enumerable: true,
|
|
174
|
+
configurable: true,
|
|
175
|
+
writable: true,
|
|
176
|
+
value: 'list_item'
|
|
177
|
+
});
|
|
178
|
+
Object.defineProperty(this, "requires", {
|
|
179
|
+
enumerable: true,
|
|
180
|
+
configurable: true,
|
|
181
|
+
writable: true,
|
|
182
|
+
value: ['doc']
|
|
183
|
+
});
|
|
184
|
+
Object.defineProperty(this, "automerge", {
|
|
185
|
+
enumerable: true,
|
|
186
|
+
configurable: true,
|
|
187
|
+
writable: true,
|
|
188
|
+
value: {
|
|
189
|
+
block: 'list_item',
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
getNodeSpec() {
|
|
194
|
+
return {
|
|
195
|
+
content: 'paragraph block*',
|
|
196
|
+
parseDOM: [{ tag: 'li' }],
|
|
197
|
+
defining: true,
|
|
198
|
+
toDOM() {
|
|
199
|
+
return ['li', 0];
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
getCommands(editor, type) {
|
|
204
|
+
return {
|
|
205
|
+
'splitListItem': () => splitListItem(type),
|
|
206
|
+
'liftListItem': () => liftListItem(type),
|
|
207
|
+
'sinkListItem': () => sinkListItem(type),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
getKeyboardShortcuts() {
|
|
211
|
+
return {
|
|
212
|
+
// 'Enter': 'splitListItem',
|
|
213
|
+
'Mod-[': 'liftListItem',
|
|
214
|
+
'Mod-]': 'sinkListItem',
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NodeSpec, NodeType } from 'prosemirror-model';
|
|
2
|
+
import { CoreEditor, Node } from '@kerebron/editor';
|
|
3
|
+
import { type InputRule } from '@kerebron/editor/plugins/input-rules';
|
|
4
|
+
import { type Commands, type CommandShortcuts } from '@kerebron/editor/commands';
|
|
5
|
+
export declare class NodeOrderedList extends Node {
|
|
6
|
+
name: string;
|
|
7
|
+
requires: string[];
|
|
8
|
+
attributes: {
|
|
9
|
+
start: {
|
|
10
|
+
default: number;
|
|
11
|
+
fromDom(element: HTMLElement): number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
getNodeSpec(): NodeSpec;
|
|
15
|
+
getInputRules(type: NodeType): InputRule[];
|
|
16
|
+
getCommands(editor: CoreEditor, type: NodeType): Partial<Commands>;
|
|
17
|
+
getKeyboardShortcuts(): Partial<CommandShortcuts>;
|
|
18
|
+
automerge: {
|
|
19
|
+
block: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=NodeOrderedList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeOrderedList.d.ts","sourceRoot":"","sources":["../src/NodeOrderedList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,EACL,KAAK,SAAS,EAEf,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EAEtB,MAAM,2BAA2B,CAAC;AAGnC,qBAAa,eAAgB,SAAQ,IAAI;IAC9B,IAAI,SAAkB;IAC/B,QAAQ,WAAW;IAEnB,UAAU;;;6BAGW,WAAW;;MAM9B;IAEO,WAAW,IAAI,QAAQ;IAWvB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,EAAE;IAa1C,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMlE,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAM1D,SAAS;;MAEP;CACH"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Node } from '@kerebron/editor';
|
|
2
|
+
import { getHtmlAttributes } from '@kerebron/editor/utilities';
|
|
3
|
+
import { wrappingInputRule, } from '@kerebron/editor/plugins/input-rules';
|
|
4
|
+
import { wrapInList, } from '@kerebron/editor/commands';
|
|
5
|
+
import { setHtmlAttributes } from '@kerebron/editor/utilities';
|
|
6
|
+
export class NodeOrderedList extends Node {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
Object.defineProperty(this, "name", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: 'ordered_list'
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "requires", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: ['doc']
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "attributes", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: {
|
|
26
|
+
start: {
|
|
27
|
+
default: 1,
|
|
28
|
+
fromDom(element) {
|
|
29
|
+
return element.hasAttribute('start')
|
|
30
|
+
? +element.getAttribute('start')
|
|
31
|
+
: 1;
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(this, "automerge", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true,
|
|
40
|
+
value: {
|
|
41
|
+
block: 'ordered_list',
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
getNodeSpec() {
|
|
46
|
+
return {
|
|
47
|
+
group: 'block',
|
|
48
|
+
content: 'list_item+',
|
|
49
|
+
parseDOM: [
|
|
50
|
+
{ tag: 'ol', getAttrs: (element) => setHtmlAttributes(this, element) },
|
|
51
|
+
],
|
|
52
|
+
toDOM: (node) => ['ol', getHtmlAttributes(this, node), 0],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
getInputRules(type) {
|
|
56
|
+
return [
|
|
57
|
+
/// Given a list node type, returns an input rule that turns a number
|
|
58
|
+
/// followed by a dot at the start of a textblock into an ordered list.
|
|
59
|
+
wrappingInputRule(/^(\d+)\.\s$/, type, (match) => ({ order: +match[1] }), (match, node) => node.childCount + node.attrs.order == +match[1]),
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
getCommands(editor, type) {
|
|
63
|
+
return {
|
|
64
|
+
'toggleOrderedList': () => wrapInList(type),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
getKeyboardShortcuts() {
|
|
68
|
+
return {
|
|
69
|
+
'Shift-Ctrl-9': 'toggleOrderedList',
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type NodeSpec, type NodeType } from 'prosemirror-model';
|
|
2
|
+
import { type CoreEditor, Node } from '@kerebron/editor';
|
|
3
|
+
import { type Commands, type CommandShortcuts } from '@kerebron/editor/commands';
|
|
4
|
+
export declare class NodeParagraph extends Node {
|
|
5
|
+
name: string;
|
|
6
|
+
requires: string[];
|
|
7
|
+
automerge: {
|
|
8
|
+
block: string;
|
|
9
|
+
};
|
|
10
|
+
getNodeSpec(): NodeSpec;
|
|
11
|
+
getCommands(editor: CoreEditor, type: NodeType): Partial<Commands>;
|
|
12
|
+
getKeyboardShortcuts(): Partial<CommandShortcuts>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=NodeParagraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeParagraph.d.ts","sourceRoot":"","sources":["../src/NodeParagraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,KAAK,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EAEtB,MAAM,2BAA2B,CAAC;AAEnC,qBAAa,aAAc,SAAQ,IAAI;IAC5B,IAAI,SAAe;IAC5B,QAAQ,WAAW;IAEnB,SAAS;;MAEP;IAEO,WAAW,IAAI,QAAQ;IAWvB,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMlE,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAK3D"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Node } from '@kerebron/editor';
|
|
2
|
+
import { setBlockType, } from '@kerebron/editor/commands';
|
|
3
|
+
export class NodeParagraph extends Node {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
Object.defineProperty(this, "name", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: 'paragraph'
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(this, "requires", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: ['doc']
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "automerge", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: {
|
|
23
|
+
block: 'paragraph',
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
getNodeSpec() {
|
|
28
|
+
return {
|
|
29
|
+
content: 'inline*',
|
|
30
|
+
group: 'block',
|
|
31
|
+
parseDOM: [{ tag: 'p' }],
|
|
32
|
+
toDOM() {
|
|
33
|
+
return ['p', 0];
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
getCommands(editor, type) {
|
|
38
|
+
return {
|
|
39
|
+
'setParagraph': () => setBlockType(type),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
getKeyboardShortcuts() {
|
|
43
|
+
return {
|
|
44
|
+
'Shift-Ctrl-0': 'setParagraph',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
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;IACvB,QAAQ,WAAW;IAEV,WAAW,IAAI,QAAQ;CAKjC"}
|
package/esm/NodeText.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Node } from '@kerebron/editor';
|
|
2
|
+
export class NodeText extends Node {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
Object.defineProperty(this, "name", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value: 'text'
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(this, "requires", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: ['doc']
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
getNodeSpec() {
|
|
19
|
+
return {
|
|
20
|
+
group: 'inline',
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
package/esm/package.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kerebron/extension-basic-editor",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"module": "./esm/ExtensionBasicEditor.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./esm/ExtensionBasicEditor.js"
|
|
9
|
+
},
|
|
10
|
+
"./ExtensionBaseKeymap": {
|
|
11
|
+
"import": "./esm/ExtensionBaseKeymap.js"
|
|
12
|
+
},
|
|
13
|
+
"./ExtensionHistory": {
|
|
14
|
+
"import": "./esm/ExtensionHistory.js"
|
|
15
|
+
},
|
|
16
|
+
"./ExtensionDropcursor": {
|
|
17
|
+
"import": "./esm/ExtensionDropcursor.js"
|
|
18
|
+
},
|
|
19
|
+
"./ExtensionGapcursor": {
|
|
20
|
+
"import": "./esm/ExtensionGapcursor.js"
|
|
21
|
+
},
|
|
22
|
+
"./NodeDocument": {
|
|
23
|
+
"import": "./esm/NodeDocument.js"
|
|
24
|
+
},
|
|
25
|
+
"./NodeText": {
|
|
26
|
+
"import": "./esm/NodeText.js"
|
|
27
|
+
},
|
|
28
|
+
"./NodeParagraph": {
|
|
29
|
+
"import": "./esm/NodeParagraph.js"
|
|
30
|
+
},
|
|
31
|
+
"./NodeHardBreak": {
|
|
32
|
+
"import": "./esm/NodeHardBreak.js"
|
|
33
|
+
},
|
|
34
|
+
"./NodeHorizontalRule": {
|
|
35
|
+
"import": "./esm/NodeHorizontalRule.js"
|
|
36
|
+
},
|
|
37
|
+
"./NodeOrderedList": {
|
|
38
|
+
"import": "./esm/NodeOrderedList.js"
|
|
39
|
+
},
|
|
40
|
+
"./NodeBulletList": {
|
|
41
|
+
"import": "./esm/NodeBulletList.js"
|
|
42
|
+
},
|
|
43
|
+
"./NodeListItem": {
|
|
44
|
+
"import": "./esm/NodeListItem.js"
|
|
45
|
+
},
|
|
46
|
+
"./NodeImage": {
|
|
47
|
+
"import": "./esm/NodeImage.js"
|
|
48
|
+
},
|
|
49
|
+
"./NodeBlockquote": {
|
|
50
|
+
"import": "./esm/NodeBlockquote.js"
|
|
51
|
+
},
|
|
52
|
+
"./NodeAside": {
|
|
53
|
+
"import": "./esm/NodeAside.js"
|
|
54
|
+
},
|
|
55
|
+
"./NodeHeading": {
|
|
56
|
+
"import": "./esm/NodeHeading.js"
|
|
57
|
+
},
|
|
58
|
+
"./MarkCode": {
|
|
59
|
+
"import": "./esm/MarkCode.js"
|
|
60
|
+
},
|
|
61
|
+
"./MarkLink": {
|
|
62
|
+
"import": "./esm/MarkLink.js"
|
|
63
|
+
},
|
|
64
|
+
"./MarkItalic": {
|
|
65
|
+
"import": "./esm/MarkItalic.js"
|
|
66
|
+
},
|
|
67
|
+
"./MarkStrong": {
|
|
68
|
+
"import": "./esm/MarkStrong.js"
|
|
69
|
+
},
|
|
70
|
+
"./MarkUnderline": {
|
|
71
|
+
"import": "./esm/MarkUnderline.js"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"devDependencies": {
|
|
75
|
+
"@types/node": "^20.9.0"
|
|
76
|
+
},
|
|
77
|
+
"_generatedBy": "dnt@dev"
|
|
78
|
+
}
|