@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
@@ -0,0 +1,748 @@
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
+ /**
390
+ * Return a JSON object representing this state.
391
+ *
392
+ * @public
393
+ *
394
+ * @example
395
+ *
396
+ * ```ts
397
+ * const state = editor.state
398
+ * const json = jsonFromState(state)
399
+ * ```
400
+ */
401
+ declare function jsonFromState(state: EditorState): StateJSON;
402
+ /**
403
+ * Parse a JSON object to a ProseMirror state.
404
+ *
405
+ * @public
406
+ *
407
+ * @example
408
+ *
409
+ * ```ts
410
+ * const json = { state: { type: 'doc', content: [{ type: 'paragraph' }], selection: { type: 'text', from: 1, to: 1 } } }
411
+ * const state = stateFromJSON(json, { schema: editor.schema })
412
+ * ```
413
+ */
414
+ declare function stateFromJSON(json: StateJSON, options: JSONParserOptions): EditorState;
415
+ /**
416
+ * Return a JSON object representing this node.
417
+ *
418
+ * @public
419
+ *
420
+ * @example
421
+ *
422
+ * ```ts
423
+ * const node = editor.state.doc
424
+ * const json = jsonFromNode(node)
425
+ * ```
426
+ */
427
+ declare function jsonFromNode(node: ProseMirrorNode): NodeJSON;
428
+ /**
429
+ * Parse a JSON object to a ProseMirror node.
430
+ *
431
+ * @public
432
+ *
433
+ * @example
434
+ *
435
+ * ```ts
436
+ * const json = { type: 'doc', content: [{ type: 'paragraph' }] }
437
+ * const node = nodeFromJSON(json, { schema: editor.schema })
438
+ * ```
439
+ */
440
+ declare function nodeFromJSON(json: NodeJSON, options: JSONParserOptions): ProseMirrorNode;
441
+ /**
442
+ * Parse a HTML element to a ProseMirror node.
443
+ *
444
+ * @public
445
+ *
446
+ * @example
447
+ *
448
+ * ```ts
449
+ * const element = document.getElementById('content')
450
+ * const node = nodeFromElement(element, { schema: editor.schema })
451
+ * ```
452
+ */
453
+ declare function nodeFromElement(element: DOMNode, options: DOMParserOptions & JSONParserOptions): ProseMirrorNode;
454
+ /**
455
+ * Serialize a ProseMirror node to a HTML element.
456
+ *
457
+ * @public
458
+ *
459
+ * @example
460
+ *
461
+ * ```ts
462
+ * const node = editor.state.doc
463
+ * const element = elementFromNode(node)
464
+ * ```
465
+ */
466
+ declare function elementFromNode(node: ProseMirrorNode, options?: DOMSerializerOptions & DOMDocumentOptions): HTMLElement;
467
+ /**
468
+ * Parse a HTML string to a HTML element.
469
+ *
470
+ * @internal
471
+ */
472
+
473
+ /**
474
+ * Parse a HTML string to a ProseMirror node.
475
+ *
476
+ * @public
477
+ *
478
+ * @example
479
+ *
480
+ * ```ts
481
+ * const html = '<p>Hello, world!</p>'
482
+ * const node = nodeFromHTML(html, { schema: editor.schema })
483
+ * ```
484
+ */
485
+ declare function nodeFromHTML(html: string, options: DOMParserOptions & JSONParserOptions & DOMDocumentOptions): ProseMirrorNode;
486
+ /**
487
+ * Serialize a ProseMirror node to a HTML string
488
+ *
489
+ * @public
490
+ *
491
+ * @example
492
+ *
493
+ * ```ts
494
+ * const node = document.getElementById('content')
495
+ * const html = htmlFromNode(node)
496
+ * ```
497
+ */
498
+ declare function htmlFromNode(node: ProseMirrorNode, options?: DOMSerializerOptions & DOMDocumentOptions): string;
499
+ /**
500
+ * Serialize a HTML element to a ProseMirror document JSON object.
501
+ *
502
+ * @public
503
+ *
504
+ * @example
505
+ *
506
+ * ```ts
507
+ * const element = document.getElementById('content')
508
+ * const json = jsonFromElement(element, { schema: editor.schema })
509
+ * ```
510
+ */
511
+
512
+ /**
513
+ * Parse a ProseMirror document JSON object to a HTML element.
514
+ *
515
+ * @public
516
+ *
517
+ * @example
518
+ *
519
+ * ```ts
520
+ * const json = { type: 'doc', content: [{ type: 'paragraph' }] }
521
+ * const element = elementFromJSON(json, { schema: editor.schema })
522
+ * ```
523
+ */
524
+ declare function elementFromJSON(json: NodeJSON, options: JSONParserOptions & DOMSerializerOptions & DOMDocumentOptions): HTMLElement;
525
+ /**
526
+ * Parse a HTML string to a ProseMirror document JSON object.
527
+ *
528
+ * @public
529
+ *
530
+ * @example
531
+ *
532
+ * ```ts
533
+ * const html = '<p>Hello, world!</p>'
534
+ * const json = jsonFromHTML(html, { schema: editor.schema })
535
+ * ```
536
+ */
537
+ declare function jsonFromHTML(html: string, options: DOMDocumentOptions & DOMParserOptions & JSONParserOptions): NodeJSON;
538
+ /**
539
+ * Parse a ProseMirror document JSON object to a HTML string.
540
+ *
541
+ * @public
542
+ *
543
+ * @example
544
+ *
545
+ * ```ts
546
+ * const json = { type: 'doc', content: [{ type: 'paragraph' }] }
547
+ * const html = htmlFromJSON(json, { schema: editor.schema })
548
+ * ```
549
+ */
550
+ declare function htmlFromJSON(json: NodeJSON, options: JSONParserOptions & DOMSerializerOptions & DOMDocumentOptions): string;
551
+ //#endregion
552
+ //#region src/editor/editor.d.ts
553
+ /**
554
+ * @public
555
+ */
556
+ interface EditorOptions<E extends Extension> {
557
+ /**
558
+ * The extension to use when creating the editor.
559
+ */
560
+ extension: E;
561
+ /**
562
+ * The starting document to use when creating the editor. It can be a
563
+ * ProseMirror node JSON object, a HTML string, or a HTML element instance.
564
+ */
565
+ defaultContent?: NodeJSON | string | HTMLElement;
566
+ /**
567
+ * A JSON object representing the starting document to use when creating the
568
+ * editor.
569
+ *
570
+ * @deprecated Use `defaultContent` instead.
571
+ */
572
+ defaultDoc?: NodeJSON;
573
+ /**
574
+ * A HTML element or a HTML string representing the starting document to use
575
+ * when creating the editor.
576
+ *
577
+ * @deprecated Use `defaultContent` instead.
578
+ */
579
+ defaultHTML?: string | HTMLElement;
580
+ /**
581
+ * A JSON object representing the starting selection to use when creating the
582
+ * editor. It's only used when `defaultContent` is also provided.
583
+ */
584
+ defaultSelection?: SelectionJSON;
585
+ }
586
+ /**
587
+ * @public
588
+ */
589
+ interface getDocHTMLOptions extends DOMDocumentOptions {}
590
+ /**
591
+ * @internal
592
+ */
593
+
594
+ /**
595
+ * @public
596
+ */
597
+ declare function createEditor<E extends Extension>(options: EditorOptions<E>): Editor<E>;
598
+ /**
599
+ * An internal class to make TypeScript generic type easier to use.
600
+ *
601
+ * @internal
602
+ */
603
+ declare class EditorInstance {
604
+ view: EditorView | null;
605
+ schema: Schema;
606
+ nodes: Record<string, NodeAction>;
607
+ marks: Record<string, MarkAction>;
608
+ commands: Record<string, CommandAction>;
609
+ private tree;
610
+ private directEditorProps;
611
+ private afterMounted;
612
+ constructor(extension: Extension);
613
+ getState: () => EditorState;
614
+ private getDoc;
615
+ private getProp;
616
+ updateState(state: EditorState): void;
617
+ private dispatch;
618
+ setContent(content: NodeJSON | string | HTMLElement | ProseMirrorNode, selection?: SelectionJSON | Selection | 'start' | 'end'): void;
619
+ /**
620
+ * Return a JSON object representing the editor's current document.
621
+ */
622
+ getDocJSON: () => NodeJSON;
623
+ /**
624
+ * Return a HTML string representing the editor's current document.
625
+ */
626
+ getDocHTML: (options?: getDocHTMLOptions) => string;
627
+ private updateExtension;
628
+ use(extension: Extension): VoidFunction;
629
+ mount(place: HTMLElement): void;
630
+ unmount(): void;
631
+ get mounted(): boolean;
632
+ get assertView(): EditorView;
633
+ definePlugins(plugins: readonly Plugin[]): void;
634
+ removePlugins(plugins: readonly Plugin[]): void;
635
+ exec(command: Command): boolean;
636
+ canExec(command: Command): boolean;
637
+ defineCommand<Args extends any[] = any[]>(name: string, commandCreator: CommandCreator<Args>): void;
638
+ removeCommand(name: string): void;
639
+ }
640
+ /**
641
+ * @public
642
+ */
643
+ declare class Editor<E extends Extension = any> {
644
+ private instance;
645
+ /**
646
+ * @internal
647
+ */
648
+ constructor(instance: EditorInstance);
649
+ /**
650
+ * Whether the editor is mounted.
651
+ */
652
+ get mounted(): boolean;
653
+ /**
654
+ * The editor view.
655
+ */
656
+ get view(): EditorView;
657
+ /**
658
+ * The editor schema.
659
+ */
660
+ get schema(): Schema<ExtractNodeNames<E>, ExtractMarkNames<E>>;
661
+ /**
662
+ * The editor's current state.
663
+ */
664
+ get state(): EditorState;
665
+ /**
666
+ * Whether the editor is focused.
667
+ */
668
+ get focused(): boolean;
669
+ /**
670
+ * Mount the editor to the given HTML element.
671
+ * Pass `null` or `undefined` to unmount the editor.
672
+ */
673
+ mount: (place: HTMLElement | null | undefined) => void;
674
+ /**
675
+ * Unmount the editor. This is equivalent to `mount(null)`.
676
+ */
677
+ unmount: () => void;
678
+ /**
679
+ * Focus the editor.
680
+ */
681
+ focus: () => void;
682
+ /**
683
+ * Blur the editor.
684
+ */
685
+ blur: () => void;
686
+ /**
687
+ * Register an extension to the editor. Return a function to unregister the
688
+ * extension.
689
+ */
690
+ use: (extension: Extension) => VoidFunction;
691
+ /**
692
+ * Update the editor's state.
693
+ *
694
+ * @remarks
695
+ *
696
+ * This is an advanced method. Use it only if you have a specific reason to
697
+ * directly manipulate the editor's state.
698
+ */
699
+ updateState: (state: EditorState) => void;
700
+ /**
701
+ * Update the editor's document and selection.
702
+ *
703
+ * @param content - The new document to set. It can be one of the following:
704
+ * - A ProseMirror node instance
705
+ * - A ProseMirror node JSON object
706
+ * - An HTML string
707
+ * - An HTML element instance
708
+ * @param selection - Optional. Specifies the new selection. It can be one of the following:
709
+ * - A ProseMirror selection instance
710
+ * - A ProseMirror selection JSON object
711
+ * - The string "start" (to set selection at the beginning, default value)
712
+ * - The string "end" (to set selection at the end)
713
+ */
714
+ setContent: (content: ProseMirrorNode | NodeJSON | string | HTMLElement, selection?: SelectionJSON | Selection | "start" | "end") => void;
715
+ /**
716
+ * Return a JSON object representing the editor's current document.
717
+ */
718
+ getDocJSON: () => NodeJSON;
719
+ /**
720
+ * Return a HTML string representing the editor's current document.
721
+ */
722
+ getDocHTML: (options?: getDocHTMLOptions) => string;
723
+ /**
724
+ * Execute the given command. Return `true` if the command was successfully
725
+ * executed, otherwise `false`.
726
+ */
727
+ exec: (command: Command) => boolean;
728
+ /**
729
+ * Check if the given command can be executed. Return `true` if the command
730
+ * can be executed, otherwise `false`.
731
+ */
732
+ canExec: (command: Command) => boolean;
733
+ /**
734
+ * All {@link CommandAction}s defined by the editor.
735
+ */
736
+ get commands(): ExtractCommandActions<E>;
737
+ /**
738
+ * All {@link NodeAction}s defined by the editor.
739
+ */
740
+ get nodes(): ExtractNodeActions<E>;
741
+ /**
742
+ * All {@link MarkAction}s defined by the editor.
743
+ */
744
+ get marks(): ExtractMarkActions<E>;
745
+ }
746
+ //#endregion
747
+ export { AnyAttrs, AttrSpec, CommandAction, CommandCreator, CommandTyping, DOMDocumentOptions, DOMParserOptions, DOMSerializerOptions, Editor, EditorInstance, EditorOptions, Extension, ExtensionTyping, ExtractCommandActions, ExtractCommandAppliers, ExtractCommandCreators, ExtractCommands, ExtractMarkActions, ExtractMarks, ExtractNodeActions, ExtractNodes, ExtractTyping, 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 };
748
+ //# sourceMappingURL=editor-CfkZ4TNU.d.ts.map