@prosekit/core 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/dist/editor-CfkZ4TNU.d.ts +748 -0
  2. package/dist/editor-CfkZ4TNU.d.ts.map +1 -0
  3. package/dist/{editor-DlGlYOp-.js → editor-CizSwUN8.js} +76 -168
  4. package/dist/editor-CizSwUN8.js.map +1 -0
  5. package/dist/prosekit-core-test.d.ts +20 -19
  6. package/dist/prosekit-core-test.d.ts.map +1 -0
  7. package/dist/prosekit-core-test.js +4 -5
  8. package/dist/prosekit-core-test.js.map +1 -0
  9. package/dist/prosekit-core.d.ts +766 -743
  10. package/dist/prosekit-core.d.ts.map +1 -0
  11. package/dist/prosekit-core.js +26 -43
  12. package/dist/prosekit-core.js.map +1 -0
  13. package/package.json +12 -9
  14. package/src/commands/add-mark.ts +53 -0
  15. package/src/commands/expand-mark.ts +96 -0
  16. package/src/commands/insert-default-block.spec.ts +102 -0
  17. package/src/commands/insert-default-block.ts +49 -0
  18. package/src/commands/insert-node.ts +71 -0
  19. package/src/commands/insert-text.ts +24 -0
  20. package/src/commands/remove-mark.ts +54 -0
  21. package/src/commands/remove-node.ts +43 -0
  22. package/src/commands/select-all.ts +16 -0
  23. package/src/commands/set-block-type.ts +64 -0
  24. package/src/commands/set-node-attrs.ts +68 -0
  25. package/src/commands/toggle-mark.ts +65 -0
  26. package/src/commands/toggle-node.ts +47 -0
  27. package/src/commands/toggle-wrap.spec.ts +35 -0
  28. package/src/commands/toggle-wrap.ts +42 -0
  29. package/src/commands/unset-block-type.spec.ts +49 -0
  30. package/src/commands/unset-block-type.ts +84 -0
  31. package/src/commands/unset-mark.spec.ts +35 -0
  32. package/src/commands/unset-mark.ts +38 -0
  33. package/src/commands/wrap.ts +50 -0
  34. package/src/editor/action.spec.ts +143 -0
  35. package/src/editor/action.ts +248 -0
  36. package/src/editor/editor.spec.ts +186 -0
  37. package/src/editor/editor.ts +563 -0
  38. package/src/editor/union.spec.ts +108 -0
  39. package/src/editor/union.ts +47 -0
  40. package/src/editor/with-priority.ts +25 -0
  41. package/src/error.ts +28 -0
  42. package/src/extensions/clipboard-serializer.ts +107 -0
  43. package/src/extensions/command.ts +121 -0
  44. package/src/extensions/default-state.spec.ts +60 -0
  45. package/src/extensions/default-state.ts +76 -0
  46. package/src/extensions/doc.ts +31 -0
  47. package/src/extensions/events/doc-change.ts +34 -0
  48. package/src/extensions/events/dom-event.spec.ts +70 -0
  49. package/src/extensions/events/dom-event.ts +117 -0
  50. package/src/extensions/events/editor-event.ts +293 -0
  51. package/src/extensions/events/focus.spec.ts +50 -0
  52. package/src/extensions/events/focus.ts +28 -0
  53. package/src/extensions/events/plugin-view.ts +132 -0
  54. package/src/extensions/history.ts +81 -0
  55. package/src/extensions/keymap-base.ts +60 -0
  56. package/src/extensions/keymap.spec.ts +89 -0
  57. package/src/extensions/keymap.ts +96 -0
  58. package/src/extensions/mark-spec.spec.ts +177 -0
  59. package/src/extensions/mark-spec.ts +181 -0
  60. package/src/extensions/mark-view-effect.ts +85 -0
  61. package/src/extensions/mark-view.ts +43 -0
  62. package/src/extensions/node-spec.spec.ts +224 -0
  63. package/src/extensions/node-spec.ts +199 -0
  64. package/src/extensions/node-view-effect.ts +85 -0
  65. package/src/extensions/node-view.ts +43 -0
  66. package/src/extensions/paragraph.ts +61 -0
  67. package/src/extensions/plugin.ts +91 -0
  68. package/src/extensions/text.ts +34 -0
  69. package/src/facets/base-extension.ts +54 -0
  70. package/src/facets/command.ts +21 -0
  71. package/src/facets/facet-extension.spec.ts +173 -0
  72. package/src/facets/facet-extension.ts +53 -0
  73. package/src/facets/facet-node.spec.ts +265 -0
  74. package/src/facets/facet-node.ts +185 -0
  75. package/src/facets/facet-types.ts +9 -0
  76. package/src/facets/facet.spec.ts +76 -0
  77. package/src/facets/facet.ts +84 -0
  78. package/src/facets/root.ts +44 -0
  79. package/src/facets/schema-spec.ts +30 -0
  80. package/src/facets/schema.ts +26 -0
  81. package/src/facets/state.ts +57 -0
  82. package/src/facets/union-extension.ts +41 -0
  83. package/src/index.ts +302 -0
  84. package/src/test/index.ts +4 -0
  85. package/src/test/test-builder.ts +68 -0
  86. package/src/test/test-editor.spec.ts +104 -0
  87. package/src/test/test-editor.ts +113 -0
  88. package/src/testing/index.ts +283 -0
  89. package/src/testing/keyboard.ts +5 -0
  90. package/src/types/any-function.ts +4 -0
  91. package/src/types/assert-type-equal.ts +8 -0
  92. package/src/types/attrs.ts +32 -0
  93. package/src/types/base-node-view-options.ts +33 -0
  94. package/src/types/dom-node.ts +1 -0
  95. package/src/types/extension-command.ts +52 -0
  96. package/src/types/extension-mark.ts +15 -0
  97. package/src/types/extension-node.ts +15 -0
  98. package/src/types/extension.spec.ts +56 -0
  99. package/src/types/extension.ts +168 -0
  100. package/src/types/model.ts +54 -0
  101. package/src/types/object-entries.ts +13 -0
  102. package/src/types/pick-string-literal.spec.ts +10 -0
  103. package/src/types/pick-string-literal.ts +6 -0
  104. package/src/types/pick-sub-type.spec.ts +20 -0
  105. package/src/types/pick-sub-type.ts +6 -0
  106. package/src/types/priority.ts +12 -0
  107. package/src/types/setter.ts +4 -0
  108. package/src/types/simplify-deeper.spec.ts +40 -0
  109. package/src/types/simplify-deeper.ts +6 -0
  110. package/src/types/simplify-union.spec.ts +21 -0
  111. package/src/types/simplify-union.ts +11 -0
  112. package/src/utils/array-grouping.spec.ts +29 -0
  113. package/src/utils/array-grouping.ts +25 -0
  114. package/src/utils/array.ts +21 -0
  115. package/src/utils/assert.ts +13 -0
  116. package/src/utils/attrs-match.ts +20 -0
  117. package/src/utils/can-use-regex-lookbehind.ts +12 -0
  118. package/src/utils/clsx.spec.ts +14 -0
  119. package/src/utils/clsx.ts +12 -0
  120. package/src/utils/collect-children.ts +21 -0
  121. package/src/utils/collect-nodes.ts +37 -0
  122. package/src/utils/combine-event-handlers.spec.ts +27 -0
  123. package/src/utils/combine-event-handlers.ts +27 -0
  124. package/src/utils/contains-inline-node.ts +17 -0
  125. package/src/utils/deep-equals.spec.ts +26 -0
  126. package/src/utils/deep-equals.ts +29 -0
  127. package/src/utils/default-block-at.ts +15 -0
  128. package/src/utils/editor-content.spec.ts +47 -0
  129. package/src/utils/editor-content.ts +77 -0
  130. package/src/utils/env.ts +6 -0
  131. package/src/utils/find-parent-node-of-type.ts +29 -0
  132. package/src/utils/find-parent-node.spec.ts +68 -0
  133. package/src/utils/find-parent-node.ts +55 -0
  134. package/src/utils/get-custom-selection.ts +19 -0
  135. package/src/utils/get-dom-api.ts +56 -0
  136. package/src/utils/get-id.spec.ts +14 -0
  137. package/src/utils/get-id.ts +13 -0
  138. package/src/utils/get-mark-type.ts +20 -0
  139. package/src/utils/get-node-type.ts +20 -0
  140. package/src/utils/get-node-types.ts +19 -0
  141. package/src/utils/includes-mark.ts +18 -0
  142. package/src/utils/is-at-block-start.ts +26 -0
  143. package/src/utils/is-in-code-block.ts +18 -0
  144. package/src/utils/is-mark-absent.spec.ts +53 -0
  145. package/src/utils/is-mark-absent.ts +42 -0
  146. package/src/utils/is-mark-active.ts +27 -0
  147. package/src/utils/is-node-active.ts +25 -0
  148. package/src/utils/is-subset.spec.ts +12 -0
  149. package/src/utils/is-subset.ts +11 -0
  150. package/src/utils/maybe-run.spec.ts +39 -0
  151. package/src/utils/maybe-run.ts +11 -0
  152. package/src/utils/merge-objects.spec.ts +30 -0
  153. package/src/utils/merge-objects.ts +11 -0
  154. package/src/utils/merge-specs.ts +35 -0
  155. package/src/utils/object-equal.spec.ts +26 -0
  156. package/src/utils/object-equal.ts +28 -0
  157. package/src/utils/output-spec.test.ts +95 -0
  158. package/src/utils/output-spec.ts +130 -0
  159. package/src/utils/parse.spec.ts +46 -0
  160. package/src/utils/parse.ts +321 -0
  161. package/src/utils/remove-undefined-values.spec.ts +15 -0
  162. package/src/utils/remove-undefined-values.ts +9 -0
  163. package/src/utils/set-selection-around.ts +11 -0
  164. package/src/utils/type-assertion.ts +91 -0
  165. package/src/utils/unicode.spec.ts +10 -0
  166. package/src/utils/unicode.ts +4 -0
  167. package/src/utils/with-skip-code-block.ts +15 -0
  168. package/dist/editor-OUH5V8BA.d.ts +0 -754
@@ -1,754 +0,0 @@
1
- import { Command, EditorState, Plugin, Selection } from "@prosekit/pm/state";
2
- import { Attrs, DOMParser, DOMSerializer, Mark, NodeType, ParseOptions, ProseMirrorNode, Schema } from "@prosekit/pm/model";
3
- import { EditorView } from "@prosekit/pm/view";
4
- import { Simplify, UnionToIntersection } from "type-fest";
5
-
6
- //#region src/types/attrs.d.ts
7
- /**
8
- * An object holding the attributes of a node.
9
-
10
- * @public
11
- */
12
- type AnyAttrs = Attrs;
13
- /**
14
- * @public
15
- */
16
- type AttrSpec<AttrType = any> = {
17
- /**
18
- * The default value for this attribute, to use when no explicit value is
19
- * provided. Attributes that have no default must be provided whenever a node
20
- * or mark of a type that has them is created.
21
- */
22
- default?: AttrType;
23
- /**
24
- * A function or type name used to validate values of this attribute. This
25
- * will be used when deserializing the attribute from JSON, and when running
26
- * [`Node.check`](https://prosemirror.net/docs/ref/#model.Node.check). When a
27
- * function, it should raise an exception if the value isn't of the expected
28
- * type or shape. When a string, it should be a `|`-separated string of
29
- * primitive types (`"number"`, `"string"`, `"boolean"`, `"null"`, and
30
- * `"undefined"`), and the library will raise an error when the value is not
31
- * one of those types.
32
- */
33
- validate?: string | ((value: unknown) => void);
34
- };
35
- //#endregion
36
- //#region src/editor/action.d.ts
37
- /**
38
- * Available children parameters for {@link NodeAction} and {@link MarkAction}.
39
- *
40
- * @public
41
- */
42
- type NodeChild = ProseMirrorNode | string | NodeChild[];
43
- /**
44
- * A function for creating a node with optional attributes and any number of
45
- * children.
46
- *
47
- * It also has a `isActive` method for checking if the node is active in the
48
- * current editor selection.
49
- *
50
- * @public
51
- */
52
- interface NodeAction<Attrs extends AnyAttrs = AnyAttrs> {
53
- /**
54
- * Creates a node with attributes and any number of children.
55
- */
56
- (attrs: Attrs | null, ...children: NodeChild[]): ProseMirrorNode;
57
- /**
58
- * Creates a node with any number of children.
59
- */
60
- (...children: NodeChild[]): ProseMirrorNode;
61
- /**
62
- * Checks if the node is active in the current editor selection. If the
63
- * optional `attrs` parameter is provided, it will check if the node is active
64
- * with the given attributes.
65
- */
66
- isActive: (attrs?: Attrs) => boolean;
67
- }
68
- /**
69
- * A function for applying a mark with optional attributes and any number of
70
- * children.
71
- *
72
- * It also has a `isActive` method for checking if the mark is active in the
73
- * current editor selection.
74
- *
75
- * @public
76
- */
77
- interface MarkAction<Attrs extends AnyAttrs = AnyAttrs> {
78
- /**
79
- * Applies a mark with attributes and any number of children.
80
- */
81
- (attrs: Attrs | null, ...children: NodeChild[]): ProseMirrorNode[];
82
- /**
83
- * Applies a mark with any number of children.
84
- */
85
- (...children: NodeChild[]): ProseMirrorNode[];
86
- /**
87
- * Checks if the mark is active in the current editor selection. If the
88
- * optional `attrs` parameter is provided, it will check if the mark is active
89
- * with the given attributes.
90
- */
91
- isActive: (attrs?: Attrs) => boolean;
92
- }
93
- /**
94
- * @deprecated Use type {@link NodeAction} instead.
95
- */
96
- type NodeBuilder = NodeAction;
97
- /**
98
- * @deprecated Use type {@link MarkAction} instead.
99
- */
100
- type MarkBuilder = MarkAction;
101
- /**
102
- * @internal
103
- */
104
- //#endregion
105
- //#region src/types/extension-command.d.ts
106
- /**
107
- * A function to apply a command to the editor. It will return `true` if the command was applied, and `false` otherwise.
108
- *
109
- * It also has a `canExec` method to check if the command can be applied.
110
- *
111
- * @public
112
- */
113
- interface CommandAction<Args extends any[] = any[]> {
114
- /**
115
- * Execute the current command. Return `true` if the command was successfully
116
- * executed, otherwise `false`.
117
- */
118
- (...args: Args): boolean;
119
- /**
120
- * Check if the current command can be executed. Return `true` if the command
121
- * can be executed, otherwise `false`.
122
- */
123
- canExec(...args: Args): boolean;
124
- /**
125
- * An alias for `canExec`.
126
- *
127
- * @deprecated Use `canExec` instead.
128
- */
129
- canApply(...args: Args): boolean;
130
- }
131
- type CommandCreator<Args extends any[] = any[]> = (...arg: Args) => Command;
132
- /**
133
- * @internal
134
- */
135
- interface CommandTyping {
136
- [name: string]: any[];
137
- }
138
- type ToCommandCreators<T extends CommandTyping> = { [K in keyof T]: CommandCreator<T[K]> };
139
- type ToCommandAction<T extends CommandTyping> = { [K in keyof T]: CommandAction<T[K]> };
140
- //#endregion
141
- //#region src/types/extension-mark.d.ts
142
- /**
143
- * @internal
144
- */
145
- interface MarkTyping {
146
- [name: string]: Record<string, any>;
147
- }
148
- /**
149
- * @internal
150
- */
151
- type ToMarkAction<T extends MarkTyping> = { [K in keyof T]: MarkAction<T[K]> };
152
- //#endregion
153
- //#region src/types/extension-node.d.ts
154
- /**
155
- * @internal
156
- */
157
- interface NodeTyping {
158
- [name: string]: Record<string, any>;
159
- }
160
- /**
161
- * @internal
162
- */
163
- type ToNodeAction<T extends NodeTyping> = { [K in keyof T]: NodeAction<T[K]> };
164
- //#endregion
165
- //#region src/types/pick-sub-type.d.ts
166
- /**
167
- * @internal
168
- */
169
- type PickSubType<Type, ParentType> = Type extends ParentType ? [ParentType] extends [Type] ? never : Type : never;
170
- //#endregion
171
- //#region src/types/pick-string-literal.d.ts
172
- /**
173
- * @internal
174
- */
175
- type PickStringLiteral<T> = PickSubType<T, string>;
176
- //#endregion
177
- //#region src/types/priority.d.ts
178
- /**
179
- * ProseKit extension priority.
180
- *
181
- * @public
182
- */
183
- declare enum Priority {
184
- lowest = 0,
185
- low = 1,
186
- default = 2,
187
- high = 3,
188
- highest = 4,
189
- }
190
- //#endregion
191
- //#region src/types/simplify-deeper.d.ts
192
- /**
193
- * @internal
194
- */
195
- type SimplifyDeeper<T> = { [KeyType in keyof T]: Simplify<T[KeyType]> };
196
- //#endregion
197
- //#region src/types/simplify-union.d.ts
198
- /**
199
- * @internal
200
- */
201
- type SimplifyUnion<T> = Simplify<UnionToIntersection<T extends undefined ? never : T>>;
202
- //#endregion
203
- //#region src/types/extension.d.ts
204
- /**
205
- * @internal
206
- */
207
- interface ExtensionTyping<N extends NodeTyping = never, M extends MarkTyping = never, C extends CommandTyping = never> {
208
- Nodes?: N;
209
- Marks?: M;
210
- Commands?: C;
211
- }
212
- /**
213
- * @public
214
- */
215
- interface Extension<T extends ExtensionTyping<any, any, any> = ExtensionTyping<any, any, any>> {
216
- extension: Extension | Extension[];
217
- priority?: Priority;
218
- /**
219
- * @public
220
- *
221
- * The schema that this extension represents.
222
- */
223
- schema: Schema | null;
224
- /** @internal */
225
- _type?: T;
226
- }
227
- /**
228
- * @internal
229
- */
230
- type ExtractTyping<E extends Extension> = E extends Extension<ExtensionTyping<infer N, infer M, infer C>> ? ExtensionTyping<PickSubType<N, NodeTyping>, PickSubType<M, MarkTyping>, PickSubType<C, CommandTyping>> : never;
231
- /**
232
- * An extension that does not define any nodes, marks, or commands.
233
- *
234
- * @internal
235
- */
236
- type PlainExtension = Extension<{
237
- Nodes: never;
238
- Marks: never;
239
- Commands: never;
240
- }>;
241
- /**
242
- * @public
243
- */
244
- type ExtractNodes<E extends Extension> = SimplifyDeeper<SimplifyUnion<ExtractTyping<E>["Nodes"]>>;
245
- /**
246
- * @public
247
- */
248
- type ExtractNodeNames<E extends Extension> = PickStringLiteral<keyof ExtractNodes<E>>;
249
- /**
250
- * @public
251
- */
252
- type ExtractMarks<E extends Extension> = SimplifyDeeper<SimplifyUnion<ExtractTyping<E>["Marks"]>>;
253
- /**
254
- * @public
255
- */
256
- type ExtractMarkNames<E extends Extension> = PickStringLiteral<keyof ExtractMarks<E>>;
257
- /**
258
- * @internal
259
- */
260
- type ExtractCommands<E extends Extension> = SimplifyUnion<ExtractTyping<E>["Commands"]>;
261
- /**
262
- * @public
263
- */
264
- type ExtractCommandCreators<E extends Extension> = ToCommandCreators<ExtractCommands<E>>;
265
- /**
266
- * Extracts the {@link CommandAction}s from an extension type.
267
- *
268
- * @public
269
- */
270
- type ExtractCommandActions<E extends Extension> = ToCommandAction<ExtractCommands<E>>;
271
- /**
272
- * Extracts the {@link NodeAction}s from an extension type.
273
- *
274
- * @public
275
- */
276
- type ExtractNodeActions<E extends Extension> = ToNodeAction<ExtractNodes<E>>;
277
- /**
278
- * Extracts the {@link MarkAction}s from an extension type.
279
- *
280
- * @public
281
- */
282
- type ExtractMarkActions<E extends Extension> = ToMarkAction<ExtractMarks<E>>;
283
- /**
284
- * @deprecated Use `ExtractCommandActions` instead.
285
- */
286
- type ExtractCommandAppliers<E extends Extension> = ExtractCommandActions<E>;
287
- /**
288
- * @internal
289
- */
290
- type Union<E extends readonly Extension[]> = Extension<{
291
- Nodes: ExtractNodes<E[number]>;
292
- Marks: ExtractMarks<E[number]>;
293
- Commands: ExtractCommands<E[number]>;
294
- }>;
295
- /**
296
- * @deprecated Use `Union` instead.
297
- * @internal
298
- */
299
- type UnionExtension<E extends Extension | readonly Extension[]> = E extends readonly Extension[] ? Extension<{
300
- Nodes: ExtractNodes<E[number]>;
301
- Marks: ExtractMarks<E[number]>;
302
- Commands: ExtractCommands<E[number]>;
303
- }> : E;
304
- //#endregion
305
- //#region src/types/model.d.ts
306
- /**
307
- * A JSON representation of the prosemirror node.
308
- *
309
- * @public
310
- */
311
- interface NodeJSON {
312
- type: string;
313
- marks?: Array<{
314
- type: string;
315
- attrs?: Record<string, any>;
316
- }>;
317
- text?: string;
318
- content?: NodeJSON[];
319
- attrs?: Record<string, any>;
320
- }
321
- /**
322
- * A JSON representation of the prosemirror selection.
323
- *
324
- * @public
325
- */
326
- interface SelectionJSON {
327
- anchor: number;
328
- head: number;
329
- type: string;
330
- }
331
- /**
332
- * A JSON representation of the prosemirror state.
333
- *
334
- * @public
335
- */
336
- interface StateJSON {
337
- /**
338
- * The main `ProseMirror` doc.
339
- */
340
- doc: NodeJSON;
341
- /**
342
- * The current selection.
343
- */
344
- selection: SelectionJSON;
345
- }
346
- /**
347
- * A JSON representation of the prosemirror step.
348
- *
349
- * @public
350
- */
351
- interface StepJSON {
352
- /**
353
- * The type of the step.
354
- */
355
- stepType: string;
356
- [x: string]: unknown;
357
- }
358
- //#endregion
359
- //#region src/types/dom-node.d.ts
360
- type DOMNode = InstanceType<typeof window.Node>;
361
- //#endregion
362
- //#region src/utils/parse.d.ts
363
- /** @public */
364
- interface DOMParserOptions extends ParseOptions {
365
- DOMParser?: typeof DOMParser;
366
- }
367
- /** @public */
368
- interface DOMSerializerOptions {
369
- DOMSerializer?: {
370
- fromSchema: typeof DOMSerializer.fromSchema;
371
- };
372
- }
373
- /** @public */
374
- interface DOMDocumentOptions {
375
- /**
376
- * The Document object to use for DOM operations. If not provided, defaults to
377
- * the current browser's document object. Useful for server-side rendering or
378
- * testing environments.
379
- */
380
- document?: Document;
381
- }
382
- /** @public */
383
- interface JSONParserOptions {
384
- /**
385
- * The editor schema to use.
386
- */
387
- schema: Schema;
388
- }
389
- /////////////// JSON <=> State ///////////////
390
- /**
391
- * Return a JSON object representing this state.
392
- *
393
- * @public
394
- *
395
- * @example
396
- *
397
- * ```ts
398
- * const state = editor.state
399
- * const json = jsonFromState(state)
400
- * ```
401
- */
402
- declare function jsonFromState(state: EditorState): StateJSON;
403
- /**
404
- * Parse a JSON object to a ProseMirror state.
405
- *
406
- * @public
407
- *
408
- * @example
409
- *
410
- * ```ts
411
- * const json = { state: { type: 'doc', content: [{ type: 'paragraph' }], selection: { type: 'text', from: 1, to: 1 } } }
412
- * const state = stateFromJSON(json, { schema: editor.schema })
413
- * ```
414
- */
415
- declare function stateFromJSON(json: StateJSON, options: JSONParserOptions): EditorState;
416
- /////////////// JSON <=> Node ///////////////
417
- /**
418
- * Return a JSON object representing this node.
419
- *
420
- * @public
421
- *
422
- * @example
423
- *
424
- * ```ts
425
- * const node = editor.state.doc
426
- * const json = jsonFromNode(node)
427
- * ```
428
- */
429
- declare function jsonFromNode(node: ProseMirrorNode): NodeJSON;
430
- /**
431
- * Parse a JSON object to a ProseMirror node.
432
- *
433
- * @public
434
- *
435
- * @example
436
- *
437
- * ```ts
438
- * const json = { type: 'doc', content: [{ type: 'paragraph' }] }
439
- * const node = nodeFromJSON(json, { schema: editor.schema })
440
- * ```
441
- */
442
- declare function nodeFromJSON(json: NodeJSON, options: JSONParserOptions): ProseMirrorNode;
443
- /////////////// Node <=> Element ///////////////
444
- /**
445
- * Parse a HTML element to a ProseMirror node.
446
- *
447
- * @public
448
- *
449
- * @example
450
- *
451
- * ```ts
452
- * const element = document.getElementById('content')
453
- * const node = nodeFromElement(element, { schema: editor.schema })
454
- * ```
455
- */
456
- declare function nodeFromElement(element: DOMNode, options: DOMParserOptions & JSONParserOptions): ProseMirrorNode;
457
- /**
458
- * Serialize a ProseMirror node to a HTML element.
459
- *
460
- * @public
461
- *
462
- * @example
463
- *
464
- * ```ts
465
- * const node = editor.state.doc
466
- * const element = elementFromNode(node)
467
- * ```
468
- */
469
- declare function elementFromNode(node: ProseMirrorNode, options?: DOMSerializerOptions & DOMDocumentOptions): HTMLElement;
470
- /////////////// Element <=> HTML ///////////////
471
- /**
472
- * Parse a HTML string to a HTML element.
473
- *
474
- * @internal
475
- */
476
-
477
- /////////////// Node <=> HTML ///////////////
478
- /**
479
- * Parse a HTML string to a ProseMirror node.
480
- *
481
- * @public
482
- *
483
- * @example
484
- *
485
- * ```ts
486
- * const html = '<p>Hello, world!</p>'
487
- * const node = nodeFromHTML(html, { schema: editor.schema })
488
- * ```
489
- */
490
- declare function nodeFromHTML(html: string, options: DOMParserOptions & JSONParserOptions & DOMDocumentOptions): ProseMirrorNode;
491
- /**
492
- * Serialize a ProseMirror node to a HTML string
493
- *
494
- * @public
495
- *
496
- * @example
497
- *
498
- * ```ts
499
- * const node = document.getElementById('content')
500
- * const html = htmlFromNode(node)
501
- * ```
502
- */
503
- declare function htmlFromNode(node: ProseMirrorNode, options?: DOMSerializerOptions & DOMDocumentOptions): string;
504
- /////////////// JSON <=> Element ///////////////
505
- /**
506
- * Serialize a HTML element to a ProseMirror document JSON object.
507
- *
508
- * @public
509
- *
510
- * @example
511
- *
512
- * ```ts
513
- * const element = document.getElementById('content')
514
- * const json = jsonFromElement(element, { schema: editor.schema })
515
- * ```
516
- */
517
-
518
- /**
519
- * Parse a ProseMirror document JSON object to a HTML element.
520
- *
521
- * @public
522
- *
523
- * @example
524
- *
525
- * ```ts
526
- * const json = { type: 'doc', content: [{ type: 'paragraph' }] }
527
- * const element = elementFromJSON(json, { schema: editor.schema })
528
- * ```
529
- */
530
- declare function elementFromJSON(json: NodeJSON, options: JSONParserOptions & DOMSerializerOptions & DOMDocumentOptions): HTMLElement;
531
- /////////////// JSON <=> HTML ///////////////
532
- /**
533
- * Parse a HTML string to a ProseMirror document JSON object.
534
- *
535
- * @public
536
- *
537
- * @example
538
- *
539
- * ```ts
540
- * const html = '<p>Hello, world!</p>'
541
- * const json = jsonFromHTML(html, { schema: editor.schema })
542
- * ```
543
- */
544
- declare function jsonFromHTML(html: string, options: DOMDocumentOptions & DOMParserOptions & JSONParserOptions): NodeJSON;
545
- /**
546
- * Parse a ProseMirror document JSON object to a HTML string.
547
- *
548
- * @public
549
- *
550
- * @example
551
- *
552
- * ```ts
553
- * const json = { type: 'doc', content: [{ type: 'paragraph' }] }
554
- * const html = htmlFromJSON(json, { schema: editor.schema })
555
- * ```
556
- */
557
- declare function htmlFromJSON(json: NodeJSON, options: JSONParserOptions & DOMSerializerOptions & DOMDocumentOptions): string;
558
- //#endregion
559
- //#region src/editor/editor.d.ts
560
- /**
561
- * @public
562
- */
563
- interface EditorOptions<E extends Extension> {
564
- /**
565
- * The extension to use when creating the editor.
566
- */
567
- extension: E;
568
- /**
569
- * The starting document to use when creating the editor. It can be a
570
- * ProseMirror node JSON object, a HTML string, or a HTML element instance.
571
- */
572
- defaultContent?: NodeJSON | string | HTMLElement;
573
- /**
574
- * A JSON object representing the starting document to use when creating the
575
- * editor.
576
- *
577
- * @deprecated Use `defaultContent` instead.
578
- */
579
- defaultDoc?: NodeJSON;
580
- /**
581
- * A HTML element or a HTML string representing the starting document to use
582
- * when creating the editor.
583
- *
584
- * @deprecated Use `defaultContent` instead.
585
- */
586
- defaultHTML?: string | HTMLElement;
587
- /**
588
- * A JSON object representing the starting selection to use when creating the
589
- * editor. It's only used when `defaultContent` is also provided.
590
- */
591
- defaultSelection?: SelectionJSON;
592
- }
593
- /**
594
- * @public
595
- */
596
- interface getDocHTMLOptions extends DOMDocumentOptions {}
597
- /**
598
- * @internal
599
- */
600
-
601
- /**
602
- * @public
603
- */
604
- declare function createEditor<E extends Extension>(options: EditorOptions<E>): Editor<E>;
605
- /**
606
- * An internal class to make TypeScript generic type easier to use.
607
- *
608
- * @internal
609
- */
610
- declare class EditorInstance {
611
- view: EditorView | null;
612
- schema: Schema;
613
- nodes: Record<string, NodeAction>;
614
- marks: Record<string, MarkAction>;
615
- commands: Record<string, CommandAction>;
616
- private tree;
617
- private directEditorProps;
618
- private afterMounted;
619
- constructor(extension: Extension);
620
- getState: () => EditorState;
621
- private getDoc;
622
- private getProp;
623
- updateState(state: EditorState): void;
624
- private dispatch;
625
- setContent(content: NodeJSON | string | HTMLElement | ProseMirrorNode, selection?: SelectionJSON | Selection | "start" | "end"): void;
626
- /**
627
- * Return a JSON object representing the editor's current document.
628
- */
629
- getDocJSON: () => NodeJSON;
630
- /**
631
- * Return a HTML string representing the editor's current document.
632
- */
633
- getDocHTML: (options?: getDocHTMLOptions) => string;
634
- private updateExtension;
635
- use(extension: Extension): VoidFunction;
636
- mount(place: HTMLElement): void;
637
- unmount(): void;
638
- get mounted(): boolean;
639
- get assertView(): EditorView;
640
- definePlugins(plugins: readonly Plugin[]): void;
641
- removePlugins(plugins: readonly Plugin[]): void;
642
- exec(command: Command): boolean;
643
- canExec(command: Command): boolean;
644
- defineCommand<Args extends any[] = any[]>(name: string, commandCreator: CommandCreator<Args>): void;
645
- removeCommand(name: string): void;
646
- }
647
- /**
648
- * @public
649
- */
650
- declare class Editor<E extends Extension = any> {
651
- private instance;
652
- /**
653
- * @internal
654
- */
655
- constructor(instance: EditorInstance);
656
- /**
657
- * Whether the editor is mounted.
658
- */
659
- get mounted(): boolean;
660
- /**
661
- * The editor view.
662
- */
663
- get view(): EditorView;
664
- /**
665
- * The editor schema.
666
- */
667
- get schema(): Schema<ExtractNodeNames<E>, ExtractMarkNames<E>>;
668
- /**
669
- * The editor's current state.
670
- */
671
- get state(): EditorState;
672
- /**
673
- * Whether the editor is focused.
674
- */
675
- get focused(): boolean;
676
- /**
677
- * Mount the editor to the given HTML element.
678
- * Pass `null` or `undefined` to unmount the editor.
679
- */
680
- mount: (place: HTMLElement | null | undefined) => void;
681
- /**
682
- * Unmount the editor. This is equivalent to `mount(null)`.
683
- */
684
- unmount: () => void;
685
- /**
686
- * Focus the editor.
687
- */
688
- focus: () => void;
689
- /**
690
- * Blur the editor.
691
- */
692
- blur: () => void;
693
- /**
694
- * Register an extension to the editor. Return a function to unregister the
695
- * extension.
696
- */
697
- use: (extension: Extension) => VoidFunction;
698
- /**
699
- * Update the editor's state.
700
- *
701
- * @remarks
702
- *
703
- * This is an advanced method. Use it only if you have a specific reason to
704
- * directly manipulate the editor's state.
705
- */
706
- updateState: (state: EditorState) => void;
707
- /**
708
- * Update the editor's document and selection.
709
- *
710
- * @param content - The new document to set. It can be one of the following:
711
- * - A ProseMirror node instance
712
- * - A ProseMirror node JSON object
713
- * - An HTML string
714
- * - An HTML element instance
715
- * @param selection - Optional. Specifies the new selection. It can be one of the following:
716
- * - A ProseMirror selection instance
717
- * - A ProseMirror selection JSON object
718
- * - The string "start" (to set selection at the beginning, default value)
719
- * - The string "end" (to set selection at the end)
720
- */
721
- setContent: (content: ProseMirrorNode | NodeJSON | string | HTMLElement, selection?: SelectionJSON | Selection | "start" | "end") => void;
722
- /**
723
- * Return a JSON object representing the editor's current document.
724
- */
725
- getDocJSON: () => NodeJSON;
726
- /**
727
- * Return a HTML string representing the editor's current document.
728
- */
729
- getDocHTML: (options?: getDocHTMLOptions) => string;
730
- /**
731
- * Execute the given command. Return `true` if the command was successfully
732
- * executed, otherwise `false`.
733
- */
734
- exec: (command: Command) => boolean;
735
- /**
736
- * Check if the given command can be executed. Return `true` if the command
737
- * can be executed, otherwise `false`.
738
- */
739
- canExec: (command: Command) => boolean;
740
- /**
741
- * All {@link CommandAction}s defined by the editor.
742
- */
743
- get commands(): ExtractCommandActions<E>;
744
- /**
745
- * All {@link NodeAction}s defined by the editor.
746
- */
747
- get nodes(): ExtractNodeActions<E>;
748
- /**
749
- * All {@link MarkAction}s defined by the editor.
750
- */
751
- get marks(): ExtractMarkActions<E>;
752
- }
753
- //#endregion
754
- export { AnyAttrs, AttrSpec, CommandAction, CommandCreator, CommandTyping, DOMDocumentOptions, DOMParserOptions, DOMSerializerOptions, Editor, EditorInstance, EditorOptions, Extension, ExtensionTyping, ExtractCommandActions, ExtractCommandAppliers, ExtractCommandCreators, ExtractMarkActions, ExtractMarks, ExtractNodeActions, ExtractNodes, JSONParserOptions, MarkAction, MarkBuilder, MarkTyping, NodeAction, NodeBuilder, NodeChild, NodeJSON, NodeTyping, PickSubType, PlainExtension, Priority, SelectionJSON, SimplifyDeeper, SimplifyUnion, StateJSON, StepJSON, ToMarkAction, ToNodeAction, Union, UnionExtension, createEditor, elementFromJSON, elementFromNode, htmlFromJSON, htmlFromNode, jsonFromHTML, jsonFromNode, jsonFromState, nodeFromElement, nodeFromHTML, nodeFromJSON, stateFromJSON };