prosekit 0.0.0-next-20230627094841
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 +21 -0
- package/README.md +13 -0
- package/dist/basic/style.css +133 -0
- package/dist/chunk-23S3SZFA.js +46 -0
- package/dist/chunk-2MVHS73Q.js +709 -0
- package/dist/chunk-4GDRVRDP.js +0 -0
- package/dist/chunk-5PFF57NB.js +1546 -0
- package/dist/chunk-6A2XHVFY.js +46 -0
- package/dist/chunk-7OYIOTDD.js +16472 -0
- package/dist/chunk-ARJTWYPA.js +1321 -0
- package/dist/chunk-CDGN4JUS.js +1546 -0
- package/dist/chunk-CG5B6PMC.js +973 -0
- package/dist/chunk-DDN3TFRH.js +185 -0
- package/dist/chunk-EQV3CWHZ.js +2213 -0
- package/dist/chunk-ERNIDFFW.js +1711 -0
- package/dist/chunk-FAVXZAF7.js +3279 -0
- package/dist/chunk-HSPTUO6P.js +53 -0
- package/dist/chunk-JMNJUDT7.js +165 -0
- package/dist/chunk-LXCCO2LO.js +52 -0
- package/dist/chunk-MIPON3OH.js +922 -0
- package/dist/chunk-NAWSCY5F.js +166 -0
- package/dist/chunk-S64NFSV2.js +236 -0
- package/dist/chunk-S65R2BUY.js +15 -0
- package/dist/chunk-T2V5UU6H.js +204 -0
- package/dist/chunk-TWIMWRRZ.js +57 -0
- package/dist/chunk-US2P3K6I.js +185 -0
- package/dist/chunk-UTNVEPBA.js +950 -0
- package/dist/chunk-UWHQRU5N.js +4883 -0
- package/dist/chunk-VIKPJJET.js +662 -0
- package/dist/chunk-WAMZOD5I.js +67 -0
- package/dist/chunk-YUY5I2TY.js +236 -0
- package/dist/core/style.css +54 -0
- package/dist/extension-list/style.css +78 -0
- package/dist/pm/view/style/prosemirror.css +52 -0
- package/dist/prosekit-basic.js +2 -0
- package/dist/prosekit-core.js +2 -0
- package/dist/prosekit-extension-blockquote.js +2 -0
- package/dist/prosekit-extension-bold.js +2 -0
- package/dist/prosekit-extension-code-block.js +2 -0
- package/dist/prosekit-extension-code.js +2 -0
- package/dist/prosekit-extension-heading.js +2 -0
- package/dist/prosekit-extension-horizontal-rule.js +2 -0
- package/dist/prosekit-extension-italic.js +2 -0
- package/dist/prosekit-extension-list.js +2 -0
- package/dist/prosekit-extension-suggestion.js +2 -0
- package/dist/prosekit-lit-elements-menu-item.js +2 -0
- package/dist/prosekit-lit-elements-menu.js +2 -0
- package/dist/prosekit-lit-elements-popover.js +2 -0
- package/dist/prosekit-lit.js +2 -0
- package/dist/prosekit-pm-commands.js +2 -0
- package/dist/prosekit-pm-inputrules.js +2 -0
- package/dist/prosekit-pm-keymap.js +2 -0
- package/dist/prosekit-pm-model.js +2 -0
- package/dist/prosekit-pm-state.js +2 -0
- package/dist/prosekit-pm-transform.js +2 -0
- package/dist/prosekit-pm-view.js +2 -0
- package/dist/prosekit-pm.js +2 -0
- package/dist/prosekit-react-components-menu-item.js +2 -0
- package/dist/prosekit-react-components-menu.js +2 -0
- package/dist/prosekit-react-components-popover-suggestion.js +2 -0
- package/dist/prosekit-react-components-popover.js +2 -0
- package/dist/prosekit-react.js +2 -0
- package/dist/prosekit-vue-components-menu-item.js +2 -0
- package/dist/prosekit-vue-components-menu.js +2 -0
- package/dist/prosekit-vue-components-popover-suggestion.js +2 -0
- package/dist/prosekit-vue-components-popover.js +2 -0
- package/dist/prosekit-vue.js +2 -0
- package/dist/prosekit.js +0 -0
- package/package.json +262 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EditorView
|
|
3
|
+
} from "./chunk-UWHQRU5N.js";
|
|
4
|
+
import {
|
|
5
|
+
baseKeymap,
|
|
6
|
+
chainCommands,
|
|
7
|
+
toggleMark
|
|
8
|
+
} from "./chunk-VIKPJJET.js";
|
|
9
|
+
import {
|
|
10
|
+
inputRules
|
|
11
|
+
} from "./chunk-JMNJUDT7.js";
|
|
12
|
+
import {
|
|
13
|
+
keymap
|
|
14
|
+
} from "./chunk-T2V5UU6H.js";
|
|
15
|
+
import {
|
|
16
|
+
AllSelection,
|
|
17
|
+
EditorState,
|
|
18
|
+
Plugin,
|
|
19
|
+
Selection
|
|
20
|
+
} from "./chunk-UTNVEPBA.js";
|
|
21
|
+
import {
|
|
22
|
+
findWrapping,
|
|
23
|
+
insertPoint
|
|
24
|
+
} from "./chunk-ERNIDFFW.js";
|
|
25
|
+
import {
|
|
26
|
+
Schema,
|
|
27
|
+
dist_default
|
|
28
|
+
} from "./chunk-FAVXZAF7.js";
|
|
29
|
+
|
|
30
|
+
// ../core/src/error.ts
|
|
31
|
+
var ProseKitError = class extends Error {
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// ../core/src/utils/get-mark-type.ts
|
|
35
|
+
function getMarkType(schema, type) {
|
|
36
|
+
if (typeof type === "string") {
|
|
37
|
+
const markType = schema.marks[type];
|
|
38
|
+
if (!markType) {
|
|
39
|
+
throw new ProseKitError(`Cannot find mark type "${type}"`);
|
|
40
|
+
}
|
|
41
|
+
return markType;
|
|
42
|
+
}
|
|
43
|
+
return type;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ../core/src/commands/toggle-mark.ts
|
|
47
|
+
function toggleMark2(options) {
|
|
48
|
+
return (state, dispatch, view) => {
|
|
49
|
+
return toggleMark(
|
|
50
|
+
getMarkType(state.schema, options.type),
|
|
51
|
+
options.attrs
|
|
52
|
+
)(state, dispatch, view);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ../core/src/types/priority.ts
|
|
57
|
+
var Priority = /* @__PURE__ */ ((Priority2) => {
|
|
58
|
+
Priority2[Priority2["lowest"] = 4] = "lowest";
|
|
59
|
+
Priority2[Priority2["low"] = 3] = "low";
|
|
60
|
+
Priority2[Priority2["default"] = 2] = "default";
|
|
61
|
+
Priority2[Priority2["high"] = 1] = "high";
|
|
62
|
+
Priority2[Priority2["highest"] = 0] = "highest";
|
|
63
|
+
return Priority2;
|
|
64
|
+
})(Priority || {});
|
|
65
|
+
|
|
66
|
+
// ../core/src/editor/facet.ts
|
|
67
|
+
var nextIndex = 0;
|
|
68
|
+
var Facet = class _Facet {
|
|
69
|
+
constructor(combine, next) {
|
|
70
|
+
/** @internal */
|
|
71
|
+
this.index = nextIndex++;
|
|
72
|
+
this.combine = combine;
|
|
73
|
+
this.next = next;
|
|
74
|
+
}
|
|
75
|
+
static define({ combine, next }) {
|
|
76
|
+
return new _Facet(combine, next);
|
|
77
|
+
}
|
|
78
|
+
/** @internal */
|
|
79
|
+
static defineSlot({
|
|
80
|
+
combine
|
|
81
|
+
}) {
|
|
82
|
+
return new _Facet(combine, null);
|
|
83
|
+
}
|
|
84
|
+
extension(inputs) {
|
|
85
|
+
return new FacetExtension(this, inputs);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var FacetExtension = class {
|
|
89
|
+
constructor(facet, inputs) {
|
|
90
|
+
this.facet = facet;
|
|
91
|
+
this.inputs = inputs;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
function sortFacets(unsorted) {
|
|
95
|
+
var _a;
|
|
96
|
+
const facets = unsorted.filter((val) => val);
|
|
97
|
+
const facetMap = [];
|
|
98
|
+
const inbounds = [];
|
|
99
|
+
let facetCount = 0;
|
|
100
|
+
for (const facet of facets) {
|
|
101
|
+
const index = facet.index;
|
|
102
|
+
if (facetMap[index] != null) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (inbounds[index] == null) {
|
|
106
|
+
inbounds[index] = 0;
|
|
107
|
+
}
|
|
108
|
+
facetCount++;
|
|
109
|
+
facetMap[index] = facet;
|
|
110
|
+
if (facet.next) {
|
|
111
|
+
const nextIndex2 = facet.next.index;
|
|
112
|
+
if (inbounds[nextIndex2] == null) {
|
|
113
|
+
inbounds[nextIndex2] = 0;
|
|
114
|
+
}
|
|
115
|
+
inbounds[nextIndex2] += 1;
|
|
116
|
+
if (facetMap[nextIndex2] == null) {
|
|
117
|
+
facets.push(facet.next);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const sortedFacets = [];
|
|
122
|
+
const sortedIndexes = [];
|
|
123
|
+
inbounds.forEach((inbound, index) => {
|
|
124
|
+
if (inbound === 0) {
|
|
125
|
+
sortedIndexes.push(index);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
for (const index of sortedIndexes) {
|
|
129
|
+
const facet = facetMap[index];
|
|
130
|
+
sortedFacets.push(facet);
|
|
131
|
+
const nextIndex2 = (_a = facet.next) == null ? void 0 : _a.index;
|
|
132
|
+
if (nextIndex2 == null)
|
|
133
|
+
continue;
|
|
134
|
+
inbounds[nextIndex2] -= 1;
|
|
135
|
+
if (inbounds[nextIndex2] === 0) {
|
|
136
|
+
sortedIndexes.push(nextIndex2);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (facetCount !== sortedFacets.length) {
|
|
140
|
+
throw new Error(`Facet has circular dependency`);
|
|
141
|
+
}
|
|
142
|
+
return sortedFacets;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ../core/src/types/void-function.ts
|
|
146
|
+
function voidFunction() {
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ../core/src/editor/slot.ts
|
|
150
|
+
var schemaSlot = Facet.defineSlot({
|
|
151
|
+
combine: (specs) => {
|
|
152
|
+
var _a;
|
|
153
|
+
let nodes = dist_default.from({});
|
|
154
|
+
let marks = dist_default.from({});
|
|
155
|
+
let topNode = void 0;
|
|
156
|
+
for (const spec of specs) {
|
|
157
|
+
nodes = nodes.append(spec.nodes);
|
|
158
|
+
marks = marks.append((_a = spec.marks) != null ? _a : {});
|
|
159
|
+
topNode = topNode != null ? topNode : spec.topNode;
|
|
160
|
+
}
|
|
161
|
+
return { nodes, marks, topNode };
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
var stateSlot = Facet.defineSlot({
|
|
165
|
+
combine: (callbacks) => {
|
|
166
|
+
return (ctx) => {
|
|
167
|
+
var _a, _b, _c, _d, _e;
|
|
168
|
+
const configs = callbacks.map((cb) => cb(ctx));
|
|
169
|
+
const config = {
|
|
170
|
+
schema: ctx.schema,
|
|
171
|
+
storedMarks: [],
|
|
172
|
+
plugins: []
|
|
173
|
+
};
|
|
174
|
+
for (const c of configs) {
|
|
175
|
+
config.schema = (_a = config.schema) != null ? _a : c.schema;
|
|
176
|
+
config.doc = (_b = config.doc) != null ? _b : c.doc;
|
|
177
|
+
config.selection = (_c = config.selection) != null ? _c : c.selection;
|
|
178
|
+
config.storedMarks = [...config.storedMarks, ...(_d = c.storedMarks) != null ? _d : []];
|
|
179
|
+
config.plugins = [...config.plugins, ...(_e = c.plugins) != null ? _e : []];
|
|
180
|
+
}
|
|
181
|
+
if (!config.doc && !config.schema) {
|
|
182
|
+
throw new Error("Can't create state without a schema nor a document");
|
|
183
|
+
}
|
|
184
|
+
if (config.doc) {
|
|
185
|
+
config.schema = void 0;
|
|
186
|
+
}
|
|
187
|
+
return config;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
var viewSlot = Facet.defineSlot({
|
|
192
|
+
combine: (props) => {
|
|
193
|
+
return Object.assign({}, ...props);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
var commandSlot = Facet.defineSlot({
|
|
197
|
+
combine: (inputs) => {
|
|
198
|
+
return Object.assign({}, ...inputs);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// ../core/src/editor/flatten.ts
|
|
203
|
+
function flatten(root) {
|
|
204
|
+
var _a;
|
|
205
|
+
const extensions = [root];
|
|
206
|
+
const priorities = [2 /* default */];
|
|
207
|
+
const facets = [];
|
|
208
|
+
const inputs = [];
|
|
209
|
+
while (extensions.length > 0) {
|
|
210
|
+
const ext = extensions.pop();
|
|
211
|
+
const pri = priorities.pop();
|
|
212
|
+
if (ext instanceof FacetExtension) {
|
|
213
|
+
const facet = ext.facet;
|
|
214
|
+
if (!facets[facet.index]) {
|
|
215
|
+
facets[facet.index] = facet;
|
|
216
|
+
inputs[facet.index] = [[], [], [], [], []];
|
|
217
|
+
}
|
|
218
|
+
const facetInputs = ext.inputs;
|
|
219
|
+
inputs[facet.index][pri].push(...facetInputs);
|
|
220
|
+
} else if (ext.extension) {
|
|
221
|
+
const p = (_a = ext.priority) != null ? _a : pri;
|
|
222
|
+
if (Array.isArray(ext.extension)) {
|
|
223
|
+
for (const e of ext.extension) {
|
|
224
|
+
extensions.push(e);
|
|
225
|
+
priorities.push(p);
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
extensions.push(ext.extension);
|
|
229
|
+
priorities.push(p);
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
throw new Error("Invalid extension");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
let schemaInput = null;
|
|
236
|
+
let stateInput = null;
|
|
237
|
+
let viewInput = null;
|
|
238
|
+
let commandInput = null;
|
|
239
|
+
const sortedFacets = sortFacets(facets);
|
|
240
|
+
for (const facet of sortedFacets) {
|
|
241
|
+
const nextFacet = facet.next;
|
|
242
|
+
if (nextFacet) {
|
|
243
|
+
for (let pri = 0; pri < 5; pri++) {
|
|
244
|
+
const input = inputs[facet.index][pri];
|
|
245
|
+
if (input.length > 0) {
|
|
246
|
+
const output = facet.combine(input);
|
|
247
|
+
if (!inputs[nextFacet.index]) {
|
|
248
|
+
inputs[nextFacet.index] = [[], [], [], [], []];
|
|
249
|
+
}
|
|
250
|
+
inputs[nextFacet.index][pri].push(output);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
} else if (inputs[facet.index]) {
|
|
254
|
+
const [i1, i2, i3, i4, i5] = inputs[facet.index];
|
|
255
|
+
const jointInputs = [...i1, ...i2, ...i3, ...i4, ...i5];
|
|
256
|
+
const output = facet.combine(jointInputs);
|
|
257
|
+
switch (facet) {
|
|
258
|
+
case schemaSlot:
|
|
259
|
+
schemaInput = output;
|
|
260
|
+
break;
|
|
261
|
+
case stateSlot:
|
|
262
|
+
stateInput = output;
|
|
263
|
+
break;
|
|
264
|
+
case viewSlot:
|
|
265
|
+
viewInput = output;
|
|
266
|
+
break;
|
|
267
|
+
case commandSlot:
|
|
268
|
+
commandInput = output;
|
|
269
|
+
break;
|
|
270
|
+
default:
|
|
271
|
+
throw new Error("Invalid facet");
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return { schemaInput, stateInput, viewInput, commandInput };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// ../core/src/editor/editor.ts
|
|
279
|
+
function createEditor({
|
|
280
|
+
extension
|
|
281
|
+
}) {
|
|
282
|
+
const { schemaInput, stateInput, viewInput, commandInput } = flatten(extension);
|
|
283
|
+
if (!schemaInput) {
|
|
284
|
+
throw new Error("Schema must be defined");
|
|
285
|
+
}
|
|
286
|
+
const schema = new Schema(schemaInput);
|
|
287
|
+
const stateConfig = stateInput ? stateInput({ schema }) : { schema };
|
|
288
|
+
const state = EditorState.create(stateConfig);
|
|
289
|
+
const directEditorProps = { state, ...viewInput };
|
|
290
|
+
const instance = new EditorInstance(directEditorProps);
|
|
291
|
+
if (commandInput) {
|
|
292
|
+
for (const [name, commandCreator] of Object.entries(commandInput)) {
|
|
293
|
+
instance.addCommand(name, commandCreator);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return Editor.create(instance);
|
|
297
|
+
}
|
|
298
|
+
var EditorInstance = class {
|
|
299
|
+
constructor(directEditorProps) {
|
|
300
|
+
this.directEditorProps = directEditorProps;
|
|
301
|
+
this.view = null;
|
|
302
|
+
this.commandDispatchers = {};
|
|
303
|
+
this.mount.bind(this);
|
|
304
|
+
this.unmount.bind(this);
|
|
305
|
+
this.schema = directEditorProps.state.schema;
|
|
306
|
+
}
|
|
307
|
+
mount(place) {
|
|
308
|
+
if (this.view) {
|
|
309
|
+
throw new Error("Editor is already mounted");
|
|
310
|
+
}
|
|
311
|
+
if (!place) {
|
|
312
|
+
throw new Error("Can't mount editor without a place");
|
|
313
|
+
}
|
|
314
|
+
this.view = new EditorView(place, this.directEditorProps);
|
|
315
|
+
}
|
|
316
|
+
unmount() {
|
|
317
|
+
if (!this.view) {
|
|
318
|
+
throw new Error("Editor is not mounted yet");
|
|
319
|
+
}
|
|
320
|
+
this.view.destroy();
|
|
321
|
+
this.view = null;
|
|
322
|
+
}
|
|
323
|
+
get assertView() {
|
|
324
|
+
if (!this.view)
|
|
325
|
+
throw new Error("Editor is not mounted");
|
|
326
|
+
return this.view;
|
|
327
|
+
}
|
|
328
|
+
addPlugins(plugins) {
|
|
329
|
+
const view = this.assertView;
|
|
330
|
+
const state = view.state;
|
|
331
|
+
const newPlugins = [...plugins, ...state.plugins];
|
|
332
|
+
const newState = state.reconfigure({ plugins: newPlugins });
|
|
333
|
+
view.setProps({ state: newState });
|
|
334
|
+
}
|
|
335
|
+
removePlugins(plugins) {
|
|
336
|
+
const view = this.view;
|
|
337
|
+
if (!view)
|
|
338
|
+
return;
|
|
339
|
+
const state = view.state;
|
|
340
|
+
const newPlugins = state.plugins.filter((p) => !plugins.includes(p));
|
|
341
|
+
const newState = state.reconfigure({ plugins: newPlugins });
|
|
342
|
+
view.setProps({ state: newState });
|
|
343
|
+
}
|
|
344
|
+
addCommand(name, commandCreator) {
|
|
345
|
+
const dispatcher = (...args) => {
|
|
346
|
+
const view = this.assertView;
|
|
347
|
+
const command = commandCreator(...args);
|
|
348
|
+
return command(view.state, view.dispatch.bind(view), view);
|
|
349
|
+
};
|
|
350
|
+
this.commandDispatchers[name] = dispatcher;
|
|
351
|
+
}
|
|
352
|
+
removeCommand(name) {
|
|
353
|
+
delete this.commandDispatchers[name];
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
var Editor = class _Editor {
|
|
357
|
+
constructor(instance) {
|
|
358
|
+
this.afterMounted = [];
|
|
359
|
+
this.instance = instance;
|
|
360
|
+
}
|
|
361
|
+
/** @internal */
|
|
362
|
+
static create(instance) {
|
|
363
|
+
if (!(instance instanceof EditorInstance)) {
|
|
364
|
+
throw new TypeError("Editor's instance is not EditorInstance");
|
|
365
|
+
}
|
|
366
|
+
return new _Editor(instance);
|
|
367
|
+
}
|
|
368
|
+
get mounted() {
|
|
369
|
+
return !!this.instance.view;
|
|
370
|
+
}
|
|
371
|
+
get view() {
|
|
372
|
+
return this.instance.assertView;
|
|
373
|
+
}
|
|
374
|
+
get schema() {
|
|
375
|
+
return this.instance.schema;
|
|
376
|
+
}
|
|
377
|
+
get commands() {
|
|
378
|
+
return this.instance.commandDispatchers;
|
|
379
|
+
}
|
|
380
|
+
mount(place) {
|
|
381
|
+
this.instance.mount(place);
|
|
382
|
+
this.afterMounted.forEach((callback) => callback());
|
|
383
|
+
}
|
|
384
|
+
unmount() {
|
|
385
|
+
this.instance.unmount();
|
|
386
|
+
}
|
|
387
|
+
use(extension) {
|
|
388
|
+
if (!this.mounted) {
|
|
389
|
+
let lazyRemove = null;
|
|
390
|
+
const lazyCreate = () => {
|
|
391
|
+
lazyRemove = this.use(extension);
|
|
392
|
+
};
|
|
393
|
+
this.afterMounted.push(lazyCreate);
|
|
394
|
+
return () => {
|
|
395
|
+
lazyRemove == null ? void 0 : lazyRemove();
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
const { schemaInput, stateInput, viewInput, commandInput } = flatten(extension);
|
|
399
|
+
if (schemaInput) {
|
|
400
|
+
throw new ProseKitError("Schema cannot be changed");
|
|
401
|
+
}
|
|
402
|
+
if (viewInput) {
|
|
403
|
+
throw new ProseKitError("View cannot be changed");
|
|
404
|
+
}
|
|
405
|
+
if (stateInput) {
|
|
406
|
+
const stateConfig = stateInput({ schema: this.schema });
|
|
407
|
+
const plugins = stateConfig.plugins;
|
|
408
|
+
if (plugins && plugins.length > 0) {
|
|
409
|
+
this.instance.addPlugins(plugins);
|
|
410
|
+
return () => this.instance.removePlugins(plugins);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (commandInput) {
|
|
414
|
+
const names = Object.keys(commandInput);
|
|
415
|
+
for (const name of names) {
|
|
416
|
+
this.instance.addCommand(name, commandInput[name]);
|
|
417
|
+
}
|
|
418
|
+
return () => {
|
|
419
|
+
for (const name of names) {
|
|
420
|
+
this.instance.removeCommand(name);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
return voidFunction;
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
// ../core/src/editor/type-utils.ts
|
|
429
|
+
function defineExtension(extension) {
|
|
430
|
+
if (extension && Array.isArray(extension)) {
|
|
431
|
+
return { extension };
|
|
432
|
+
}
|
|
433
|
+
return extension;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// ../core/src/editor/with-priority.ts
|
|
437
|
+
function withPriority(extension, priority) {
|
|
438
|
+
return { extension, priority };
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// ../core/src/extensions/command.ts
|
|
442
|
+
function addCommands(commands) {
|
|
443
|
+
return commandSlot.extension([commands]);
|
|
444
|
+
}
|
|
445
|
+
function addBaseCommands() {
|
|
446
|
+
return addCommands({
|
|
447
|
+
insertText: ({
|
|
448
|
+
text,
|
|
449
|
+
from,
|
|
450
|
+
to
|
|
451
|
+
}) => {
|
|
452
|
+
return (state, dispatch) => {
|
|
453
|
+
if (text) {
|
|
454
|
+
dispatch == null ? void 0 : dispatch(state.tr.insertText(text, from, to));
|
|
455
|
+
}
|
|
456
|
+
return true;
|
|
457
|
+
};
|
|
458
|
+
},
|
|
459
|
+
insertNode: ({ node, pos }) => {
|
|
460
|
+
return (state, dispatch) => {
|
|
461
|
+
const insertPos = insertPoint(
|
|
462
|
+
state.doc,
|
|
463
|
+
pos != null ? pos : state.selection.to,
|
|
464
|
+
node.type
|
|
465
|
+
);
|
|
466
|
+
if (insertPos == null)
|
|
467
|
+
return false;
|
|
468
|
+
if (dispatch) {
|
|
469
|
+
const tr = state.tr.insert(insertPos, node);
|
|
470
|
+
const $pos = tr.doc.resolve(insertPos);
|
|
471
|
+
tr.setSelection(Selection.near($pos));
|
|
472
|
+
dispatch(tr);
|
|
473
|
+
}
|
|
474
|
+
return true;
|
|
475
|
+
};
|
|
476
|
+
},
|
|
477
|
+
wrap: ({
|
|
478
|
+
nodeType,
|
|
479
|
+
attrs
|
|
480
|
+
}) => {
|
|
481
|
+
return (state, dispatch) => {
|
|
482
|
+
const { $from, $to } = state.selection;
|
|
483
|
+
const range = $from.blockRange($to);
|
|
484
|
+
if (!range)
|
|
485
|
+
return false;
|
|
486
|
+
const wrapping = findWrapping(range, nodeType, attrs);
|
|
487
|
+
if (!wrapping)
|
|
488
|
+
return false;
|
|
489
|
+
dispatch == null ? void 0 : dispatch(state.tr.wrap(range, wrapping));
|
|
490
|
+
return true;
|
|
491
|
+
};
|
|
492
|
+
},
|
|
493
|
+
setBlockType: ({
|
|
494
|
+
nodeType,
|
|
495
|
+
attrs,
|
|
496
|
+
from,
|
|
497
|
+
to
|
|
498
|
+
}) => {
|
|
499
|
+
return (state, dispatch) => {
|
|
500
|
+
from = from != null ? from : state.selection.from;
|
|
501
|
+
to = from != null ? from : state.selection.from;
|
|
502
|
+
dispatch == null ? void 0 : dispatch(state.tr.setBlockType(from, to, nodeType, attrs));
|
|
503
|
+
return true;
|
|
504
|
+
};
|
|
505
|
+
},
|
|
506
|
+
selectAll: () => {
|
|
507
|
+
return (state, dispatch) => {
|
|
508
|
+
dispatch == null ? void 0 : dispatch(state.tr.setSelection(new AllSelection(state.doc)));
|
|
509
|
+
return true;
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// ../core/src/extensions/node-spec.ts
|
|
516
|
+
function addNodeSpec(options) {
|
|
517
|
+
return nodeSpecFacet.extension([options]);
|
|
518
|
+
}
|
|
519
|
+
var nodeSpecFacet = Facet.define({
|
|
520
|
+
combine: (options) => {
|
|
521
|
+
const nodes = {};
|
|
522
|
+
let topNode = void 0;
|
|
523
|
+
for (const { name, spec, topNode: isTopNode } of options) {
|
|
524
|
+
if (nodes[name]) {
|
|
525
|
+
throw new Error(`Node type ${name} has already been defined`);
|
|
526
|
+
}
|
|
527
|
+
nodes[name] = spec;
|
|
528
|
+
if (isTopNode && !topNode) {
|
|
529
|
+
topNode = name;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return { nodes, topNode };
|
|
533
|
+
},
|
|
534
|
+
next: schemaSlot
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
// ../core/src/extensions/doc.ts
|
|
538
|
+
function addDoc() {
|
|
539
|
+
return addNodeSpec({
|
|
540
|
+
name: "doc",
|
|
541
|
+
spec: {
|
|
542
|
+
content: "block+"
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// ../core/src/extensions/plugin.ts
|
|
548
|
+
function addPlugin({ plugins }) {
|
|
549
|
+
if (typeof plugins === "function") {
|
|
550
|
+
return pluginFacet.extension([plugins]);
|
|
551
|
+
} else if (Array.isArray(plugins)) {
|
|
552
|
+
return pluginFacet.extension([() => plugins]);
|
|
553
|
+
} else {
|
|
554
|
+
throw new TypeError("plugins must be a function or an array");
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
var pluginFacet = Facet.define({
|
|
558
|
+
combine: (callbacks) => {
|
|
559
|
+
return ({ schema }) => {
|
|
560
|
+
const plugins = callbacks.flatMap((func) => func({ schema }));
|
|
561
|
+
return { plugins };
|
|
562
|
+
};
|
|
563
|
+
},
|
|
564
|
+
next: stateSlot
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
// ../core/src/extensions/input-rules.ts
|
|
568
|
+
function addInputRule(rules) {
|
|
569
|
+
return inputRuleFacet.extension([rules]);
|
|
570
|
+
}
|
|
571
|
+
var inputRuleFacet = Facet.define({
|
|
572
|
+
combine: (inputs) => {
|
|
573
|
+
return (context) => {
|
|
574
|
+
const rules = inputs.flatMap((callback) => callback(context));
|
|
575
|
+
return [inputRules({ rules })];
|
|
576
|
+
};
|
|
577
|
+
},
|
|
578
|
+
next: pluginFacet
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
// ../core/src/extensions/keymap.ts
|
|
582
|
+
function addKeymap(keymap2) {
|
|
583
|
+
return keymapFacet.extension([keymap2]);
|
|
584
|
+
}
|
|
585
|
+
function addBaseKeymap() {
|
|
586
|
+
return addKeymap(baseKeymap);
|
|
587
|
+
}
|
|
588
|
+
var keymapFacet = Facet.define({
|
|
589
|
+
combine: (keymaps) => {
|
|
590
|
+
const keymap2 = mergeKeymaps(keymaps);
|
|
591
|
+
const plugin = keymap(keymap2);
|
|
592
|
+
return () => [plugin];
|
|
593
|
+
},
|
|
594
|
+
next: pluginFacet
|
|
595
|
+
});
|
|
596
|
+
function mergeKeymaps(keymaps) {
|
|
597
|
+
const bindings = {};
|
|
598
|
+
for (const keymap2 of keymaps) {
|
|
599
|
+
for (const [key, command] of Object.entries(keymap2)) {
|
|
600
|
+
if (!bindings[key])
|
|
601
|
+
bindings[key] = [];
|
|
602
|
+
bindings[key].push(command);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
return Object.fromEntries(
|
|
606
|
+
Object.entries(bindings).map(([key, commands]) => [
|
|
607
|
+
key,
|
|
608
|
+
chainCommands(...commands)
|
|
609
|
+
])
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// ../core/src/extensions/mark-spec.ts
|
|
614
|
+
function addMarkSpec(options) {
|
|
615
|
+
return markSpecFacet.extension([options]);
|
|
616
|
+
}
|
|
617
|
+
var markSpecFacet = Facet.define({
|
|
618
|
+
combine: (options) => {
|
|
619
|
+
const marks = {};
|
|
620
|
+
for (const { name, spec } of options) {
|
|
621
|
+
if (marks[name]) {
|
|
622
|
+
throw new Error(`Mark type ${name} has already been defined`);
|
|
623
|
+
}
|
|
624
|
+
marks[name] = spec;
|
|
625
|
+
}
|
|
626
|
+
return { marks, nodes: {} };
|
|
627
|
+
},
|
|
628
|
+
next: schemaSlot
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
// ../core/src/extensions/paragraph.ts
|
|
632
|
+
function addParagraph() {
|
|
633
|
+
return addNodeSpec({
|
|
634
|
+
name: "paragraph",
|
|
635
|
+
spec: {
|
|
636
|
+
content: "inline*",
|
|
637
|
+
group: "block",
|
|
638
|
+
parseDOM: [{ tag: "p" }],
|
|
639
|
+
toDOM() {
|
|
640
|
+
return ["p", 0];
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// ../core/src/extensions/text.ts
|
|
647
|
+
function addText() {
|
|
648
|
+
return addNodeSpec({
|
|
649
|
+
name: "text",
|
|
650
|
+
spec: {
|
|
651
|
+
group: "inline"
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// ../core/src/utils/get-node-type.ts
|
|
657
|
+
function getNodeType(schema, type) {
|
|
658
|
+
if (typeof type === "string") {
|
|
659
|
+
const nodeType = schema.nodes[type];
|
|
660
|
+
if (!nodeType) {
|
|
661
|
+
throw new ProseKitError(`Cannot find node type "${type}"`);
|
|
662
|
+
}
|
|
663
|
+
return nodeType;
|
|
664
|
+
}
|
|
665
|
+
return type;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// ../core/src/extensions/node-view.ts
|
|
669
|
+
function addNodeView(options) {
|
|
670
|
+
return nodeViewFacet.extension([options]);
|
|
671
|
+
}
|
|
672
|
+
var nodeViewFacet = Facet.define({
|
|
673
|
+
combine: (inputs) => {
|
|
674
|
+
const nodeViews = {};
|
|
675
|
+
for (const input of inputs) {
|
|
676
|
+
if (!nodeViews[input.name]) {
|
|
677
|
+
nodeViews[input.name] = input.constructor;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
return () => [new Plugin({ props: { nodeViews } })];
|
|
681
|
+
},
|
|
682
|
+
next: pluginFacet
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
export {
|
|
686
|
+
ProseKitError,
|
|
687
|
+
getMarkType,
|
|
688
|
+
toggleMark2 as toggleMark,
|
|
689
|
+
Priority,
|
|
690
|
+
Facet,
|
|
691
|
+
FacetExtension,
|
|
692
|
+
createEditor,
|
|
693
|
+
Editor,
|
|
694
|
+
defineExtension,
|
|
695
|
+
withPriority,
|
|
696
|
+
addCommands,
|
|
697
|
+
addBaseCommands,
|
|
698
|
+
addNodeSpec,
|
|
699
|
+
addDoc,
|
|
700
|
+
addPlugin,
|
|
701
|
+
addInputRule,
|
|
702
|
+
addKeymap,
|
|
703
|
+
addBaseKeymap,
|
|
704
|
+
addMarkSpec,
|
|
705
|
+
addNodeView,
|
|
706
|
+
addParagraph,
|
|
707
|
+
addText,
|
|
708
|
+
getNodeType
|
|
709
|
+
};
|
|
File without changes
|