@prosekit/core 0.8.3 → 0.8.5

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