@prosekit/core 0.7.14 → 0.7.15

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.
@@ -1,9 +1,10 @@
1
1
  import { AllSelection } from '@prosekit/pm/state';
2
2
  import type { Attrs } from '@prosekit/pm/model';
3
+ import { BaseCommandsExtension as BaseCommandsExtension_2 } from '..';
3
4
  import { Command } from '@prosekit/pm/state';
4
5
  import type { ContentMatch } from '@prosekit/pm/model';
5
- import { config as default_alias_1 } from '@prosekit/dev/config-vitest';
6
6
  import type { DirectEditorProps } from '@prosekit/pm/view';
7
+ import { DocExtension as DocExtension_2 } from '..';
7
8
  import type { DOMEventMap } from '@prosekit/pm/view';
8
9
  import type { DOMOutputSpec } from '@prosekit/pm/model';
9
10
  import { DOMParser as DOMParser_2 } from '@prosekit/pm/model';
@@ -11,21 +12,24 @@ import { DOMSerializer } from '@prosekit/pm/model';
11
12
  import { EditorState } from '@prosekit/pm/state';
12
13
  import type { EditorStateConfig } from '@prosekit/pm/state';
13
14
  import { EditorView } from '@prosekit/pm/view';
15
+ import { Facet as Facet_2 } from '../..';
14
16
  import { Fragment } from '@prosekit/pm/model';
17
+ import { HistoryExtension as HistoryExtension_2 } from '..';
15
18
  import type { IsEqual } from 'type-fest';
16
19
  import { Mark } from '@prosekit/pm/model';
17
20
  import type { MarkSpec } from '@prosekit/pm/model';
18
21
  import type { MarkType } from '@prosekit/pm/model';
19
22
  import type { MarkViewConstructor } from '@prosekit/pm/view';
20
23
  import type { Node as Node_2 } from '@prosekit/pm/model';
24
+ import { NodeAction as NodeAction_2 } from '..';
21
25
  import { NodeSelection } from '@prosekit/pm/state';
22
26
  import type { NodeSpec } from '@prosekit/pm/model';
23
27
  import type { NodeType } from '@prosekit/pm/model';
24
28
  import { NodeType as NodeType_2 } from 'prosemirror-model';
25
29
  import type { NodeView } from '@prosekit/pm/view';
26
30
  import type { NodeViewConstructor } from '@prosekit/pm/view';
27
- import { Options } from 'tsup';
28
31
  import { ParseOptions } from '@prosekit/pm/model';
32
+ import { PlainExtension as PlainExtension_2 } from '..';
29
33
  import { Plugin as Plugin_2 } from '@prosekit/pm/state';
30
34
  import { ProseMirrorFragment } from '@prosekit/pm/model';
31
35
  import { ProseMirrorNode } from '@prosekit/pm/model';
@@ -34,10 +38,14 @@ import { Schema } from '@prosekit/pm/model';
34
38
  import { SchemaSpec } from '@prosekit/pm/model';
35
39
  import { Selection as Selection_2 } from '@prosekit/pm/state';
36
40
  import type { Simplify } from 'type-fest';
41
+ import { SimplifyDeeper as SimplifyDeeper_2 } from '..';
37
42
  import { Slice } from '@prosekit/pm/model';
38
43
  import type { TagParseRule } from '@prosekit/pm/model';
44
+ import { TextExtension as TextExtension_2 } from '..';
39
45
  import { TextSelection } from '@prosekit/pm/state';
46
+ import { ToMarkAction as ToMarkAction_2 } from '..';
40
47
  import { Transaction } from '@prosekit/pm/state';
48
+ import { Union as Union_2 } from '..';
41
49
  import type { UnionToIntersection } from 'type-fest';
42
50
 
43
51
  declare type Action = (options: {
@@ -190,7 +198,7 @@ export { BaseCommandsExtension as BaseCommandsExtension_alias_1 }
190
198
  * @internal
191
199
  */
192
200
  export declare abstract class BaseExtension<T extends ExtensionTyping = ExtensionTyping> implements Extension<T> {
193
- extension: Extension | Extension[];
201
+ abstract extension: Extension | Extension[];
194
202
  priority?: Priority;
195
203
  _type?: T;
196
204
  private trees;
@@ -264,6 +272,18 @@ declare type ClickOnHandler = (view: EditorView, pos: number, node: Node_2, node
264
272
  export { ClickOnHandler }
265
273
  export { ClickOnHandler as ClickOnHandler_alias_1 }
266
274
 
275
+ /**
276
+ * @internal
277
+ */
278
+ declare interface ClipboardSerializerOptions {
279
+ serializeFragmentWrapper?: FunctionWrapper<SerializeFragmentFunction>;
280
+ serializeNodeWrapper?: FunctionWrapper<SerializeNodeFunction>;
281
+ nodesFromSchemaWrapper?: FunctionWrapper<NodesFromSchemaFunction>;
282
+ marksFromSchemaWrapper?: FunctionWrapper<MarksFromSchemaFunction>;
283
+ }
284
+ export { ClipboardSerializerOptions }
285
+ export { ClipboardSerializerOptions as ClipboardSerializerOptions_alias_1 }
286
+
267
287
  /**
268
288
  * A utility for constructing `className` strings conditionally.
269
289
  *
@@ -395,10 +415,6 @@ export { createTestEditor as createTestEditor_alias_1 }
395
415
 
396
416
  export declare function deepEquals<T>(a: T, b: T): boolean;
397
417
 
398
- export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
399
-
400
- export { default_alias_1 }
401
-
402
418
  /**
403
419
  * @internal
404
420
  */
@@ -481,6 +497,13 @@ declare function defineClickOnHandler(handler: ClickOnHandler): PlainExtension;
481
497
  export { defineClickOnHandler }
482
498
  export { defineClickOnHandler as defineClickOnHandler_alias_1 }
483
499
 
500
+ /**
501
+ * @internal
502
+ */
503
+ declare function defineClipboardSerializer(options: ClipboardSerializerOptions): Extension;
504
+ export { defineClipboardSerializer }
505
+ export { defineClipboardSerializer as defineClipboardSerializer_alias_1 }
506
+
484
507
  declare function defineCommands<T extends Record<string, CommandCreator> = Record<string, CommandCreator>>(commands: T): Extension<{
485
508
  Commands: {
486
509
  [K in keyof T]: Parameters<T[K]>;
@@ -782,11 +805,11 @@ export { defineScrollToSelectionHandler as defineScrollToSelectionHandler_alias_
782
805
  /**
783
806
  * @internal
784
807
  */
785
- export declare function defineTestExtension(): Union<readonly [BaseCommandsExtension, PlainExtension, DocExtension, HistoryExtension, Extension<{
808
+ export declare function defineTestExtension(): Union_2<readonly [BaseCommandsExtension_2, PlainExtension_2, DocExtension_2, HistoryExtension_2, Extension<{
786
809
  Nodes: {
787
810
  paragraph: Attrs;
788
811
  };
789
- }>, TextExtension, BoldExtension, ItalicExtension, LinkExtension, HeadingExtension, CodeBlockExtension]>;
812
+ }>, TextExtension_2, BoldExtension, ItalicExtension, LinkExtension, HeadingExtension, CodeBlockExtension]>;
790
813
 
791
814
  /**
792
815
  * @public
@@ -872,6 +895,11 @@ export declare class DOMDocumentNotFoundError extends ProseKitError {
872
895
 
873
896
  /** @public */
874
897
  declare interface DOMDocumentOptions {
898
+ /**
899
+ * The Document object to use for DOM operations. If not provided, defaults to
900
+ * the current browser's document object. Useful for server-side rendering or
901
+ * testing environments.
902
+ */
875
903
  document?: Document;
876
904
  }
877
905
  export { DOMDocumentOptions }
@@ -910,7 +938,9 @@ export { DOMParserOptions as DOMParserOptions_alias_1 }
910
938
 
911
939
  /** @public */
912
940
  declare interface DOMSerializerOptions {
913
- DOMSerializer?: typeof DOMSerializer;
941
+ DOMSerializer?: {
942
+ fromSchema: typeof DOMSerializer.fromSchema;
943
+ };
914
944
  }
915
945
  export { DOMSerializerOptions }
916
946
  export { DOMSerializerOptions as DOMSerializerOptions_alias_1 }
@@ -1002,6 +1032,14 @@ declare class Editor<E extends Extension = any> {
1002
1032
  * - The string "end" (to set selection at the end)
1003
1033
  */
1004
1034
  setContent: (content: ProseMirrorNode | NodeJSON | string | HTMLElement, selection?: SelectionJSON | Selection_2 | "start" | "end") => void;
1035
+ /**
1036
+ * Return a JSON object representing the editor's current document.
1037
+ */
1038
+ getDocJSON: () => NodeJSON;
1039
+ /**
1040
+ * Return a HTML string representing the editor's current document.
1041
+ */
1042
+ getDocHTML: (options?: getDocHTMLOptions) => string;
1005
1043
  /**
1006
1044
  * Execute the given command. Return `true` if the command was successfully
1007
1045
  * executed, otherwise `false`.
@@ -1031,7 +1069,7 @@ export { Editor as Editor_alias_1 }
1031
1069
  /**
1032
1070
  * @internal
1033
1071
  */
1034
- declare const editorEventFacet: Facet<EditorEventPayload, PluginPayload>;
1072
+ declare const editorEventFacet: Facet_2<EditorEventPayload, PluginPayload>;
1035
1073
  export { editorEventFacet }
1036
1074
  export { editorEventFacet as editorEventFacet_alias_1 }
1037
1075
 
@@ -1073,9 +1111,19 @@ export declare class EditorInstance {
1073
1111
  private afterMounted;
1074
1112
  constructor(extension: Extension);
1075
1113
  getState: () => EditorState;
1114
+ private getDoc;
1115
+ private getProp;
1076
1116
  updateState(state: EditorState): void;
1077
1117
  private dispatch;
1078
1118
  setContent(content: NodeJSON | string | HTMLElement | ProseMirrorNode, selection?: SelectionJSON | Selection_2 | 'start' | 'end'): void;
1119
+ /**
1120
+ * Return a JSON object representing the editor's current document.
1121
+ */
1122
+ getDocJSON: () => NodeJSON;
1123
+ /**
1124
+ * Return a HTML string representing the editor's current document.
1125
+ */
1126
+ getDocHTML: (options?: getDocHTMLOptions) => string;
1079
1127
  private updateExtension;
1080
1128
  use(extension: Extension): VoidFunction;
1081
1129
  mount(place: HTMLElement): void;
@@ -1432,6 +1480,8 @@ declare type FocusChangeHandler = (hasFocus: boolean) => void;
1432
1480
  export { FocusChangeHandler }
1433
1481
  export { FocusChangeHandler as FocusChangeHandler_alias_1 }
1434
1482
 
1483
+ declare type FunctionWrapper<T extends AnyFunction> = (fn: T) => T;
1484
+
1435
1485
  export declare function getBrowserDocument(options?: {
1436
1486
  document?: Document;
1437
1487
  }): Document;
@@ -1442,6 +1492,12 @@ export declare function getBrowserWindow(options?: {
1442
1492
 
1443
1493
  export declare function getCustomSelection(state: EditorState, from?: number | null, to?: number | null): Selection_2;
1444
1494
 
1495
+ /**
1496
+ * @public
1497
+ */
1498
+ export declare interface getDocHTMLOptions extends DOMDocumentOptions {
1499
+ }
1500
+
1445
1501
  export declare function getEditorContentDoc(schema: Schema, content: NodeJSON | string | HTMLElement | ProseMirrorNode): ProseMirrorNode;
1446
1502
 
1447
1503
  export declare function getEditorContentJSON(schema: Schema, content: NodeJSON | string | HTMLElement): NodeJSON;
@@ -1661,7 +1717,12 @@ declare function isAtBlockStart(state: EditorState, view?: EditorView): Resolved
1661
1717
  export { isAtBlockStart }
1662
1718
  export { isAtBlockStart as isAtBlockStart_alias_1 }
1663
1719
 
1664
- export declare function isElement(el: unknown): el is Element;
1720
+ /**
1721
+ * @internal
1722
+ */
1723
+ declare function isElement(el: unknown): el is Element;
1724
+ export { isElement }
1725
+ export { isElement as isElement_alias_1 }
1665
1726
 
1666
1727
  /**
1667
1728
  * Checks if the given object is a `Fragment` instance.
@@ -1809,6 +1870,9 @@ export { jsonFromState as jsonFromState_alias_1 }
1809
1870
 
1810
1871
  /** @public */
1811
1872
  declare interface JSONParserOptions {
1873
+ /**
1874
+ * The editor schema to use.
1875
+ */
1812
1876
  schema: Schema;
1813
1877
  }
1814
1878
  export { JSONParserOptions }
@@ -1913,6 +1977,8 @@ declare type MarkBuilder = MarkAction;
1913
1977
  export { MarkBuilder }
1914
1978
  export { MarkBuilder as MarkBuilder_alias_1 }
1915
1979
 
1980
+ declare type MarksFromSchemaFunction = typeof DOMSerializer.marksFromSchema;
1981
+
1916
1982
  /**
1917
1983
  * @public
1918
1984
  */
@@ -2121,6 +2187,8 @@ declare interface NodeJSON {
2121
2187
  export { NodeJSON }
2122
2188
  export { NodeJSON as NodeJSON_alias_1 }
2123
2189
 
2190
+ declare type NodesFromSchemaFunction = typeof DOMSerializer.nodesFromSchema;
2191
+
2124
2192
  /**
2125
2193
  * @public
2126
2194
  */
@@ -2402,6 +2470,10 @@ declare interface SelectionJSON {
2402
2470
  export { SelectionJSON }
2403
2471
  export { SelectionJSON as SelectionJSON_alias_1 }
2404
2472
 
2473
+ declare type SerializeFragmentFunction = typeof DOMSerializer.prototype.serializeFragment;
2474
+
2475
+ declare type SerializeNodeFunction = typeof DOMSerializer.prototype.serializeNode;
2476
+
2405
2477
  /**
2406
2478
  * Returns a command that tries to set the selected textblocks to the given node
2407
2479
  * type with the given attributes.
@@ -2474,12 +2546,12 @@ export declare function setupEditorExtension<E extends Extension>(options: Edito
2474
2546
  * @internal
2475
2547
  */
2476
2548
  export declare function setupTest(): {
2477
- editor: TestEditor<Union<readonly [BaseCommandsExtension, PlainExtension, DocExtension, HistoryExtension, Extension<{
2549
+ editor: TestEditor<Union_2<readonly [BaseCommandsExtension_2, PlainExtension_2, DocExtension_2, HistoryExtension_2, Extension<{
2478
2550
  Nodes: {
2479
2551
  paragraph: Attrs;
2480
2552
  };
2481
- }>, TextExtension, BoldExtension, ItalicExtension, LinkExtension, HeadingExtension, CodeBlockExtension]>>;
2482
- m: ToMarkAction<SimplifyDeeper< {
2553
+ }>, TextExtension_2, BoldExtension, ItalicExtension, LinkExtension, HeadingExtension, CodeBlockExtension]>>;
2554
+ m: ToMarkAction_2<SimplifyDeeper_2< {
2483
2555
  bold: {
2484
2556
  readonly [x: string]: any;
2485
2557
  };
@@ -2491,22 +2563,22 @@ export declare function setupTest(): {
2491
2563
  };
2492
2564
  }>>;
2493
2565
  n: {
2494
- p: NodeAction< {
2566
+ p: NodeAction_2< {
2495
2567
  readonly [x: string]: any;
2496
2568
  }>;
2497
- doc: NodeAction< {
2569
+ doc: NodeAction_2< {
2498
2570
  readonly [x: string]: any;
2499
2571
  }>;
2500
- paragraph: NodeAction< {
2572
+ paragraph: NodeAction_2< {
2501
2573
  readonly [x: string]: any;
2502
2574
  }>;
2503
- text: NodeAction< {
2575
+ text: NodeAction_2< {
2504
2576
  readonly [x: string]: any;
2505
2577
  }>;
2506
- heading: NodeAction< {
2578
+ heading: NodeAction_2< {
2507
2579
  readonly [x: string]: any;
2508
2580
  }>;
2509
- codeBlock: NodeAction< {
2581
+ codeBlock: NodeAction_2< {
2510
2582
  language: string;
2511
2583
  }>;
2512
2584
  };
@@ -76,15 +76,13 @@ var Facet = class {
76
76
  this.path = parent ? [...parent.path, this.index] : [];
77
77
  }
78
78
  get reducer() {
79
- var _a, _b;
80
- return (_b = this._reducer) != null ? _b : (_a = this._reduce) == null ? void 0 : _a.call(this);
79
+ return this._reducer ?? this._reduce?.();
81
80
  }
82
81
  };
83
82
  function defineFacet(options) {
84
- var _a;
85
83
  return new Facet(
86
84
  options.parent,
87
- (_a = options.singleton) != null ? _a : false,
85
+ options.singleton ?? false,
88
86
  options.reducer,
89
87
  options.reduce
90
88
  );
@@ -138,7 +136,6 @@ import {
138
136
 
139
137
  // src/facets/root.ts
140
138
  function rootReducer(inputs) {
141
- var _a;
142
139
  let schema;
143
140
  let commands;
144
141
  let stateFunc;
@@ -149,7 +146,7 @@ function rootReducer(inputs) {
149
146
  stateFunc = input.state || stateFunc;
150
147
  view = input.view || view;
151
148
  }
152
- const state = schema && ((_a = stateFunc == null ? void 0 : stateFunc({ schema })) != null ? _a : { schema });
149
+ const state = schema && (stateFunc?.({ schema }) ?? { schema });
153
150
  return { schema, state, commands, view };
154
151
  }
155
152
  var rootFacet = new Facet(null, true, rootReducer);
@@ -169,32 +166,29 @@ var schemaFacet = defineFacet({
169
166
  // src/facets/base-extension.ts
170
167
  var BaseExtension = class {
171
168
  constructor() {
172
- this.extension = [];
173
169
  this.trees = [null, null, null, null, null];
174
170
  }
175
171
  /**
176
172
  * @internal
177
173
  */
178
174
  getTree(priority) {
179
- var _a, _b;
180
- const pri = (_a = priority != null ? priority : this.priority) != null ? _a : 2 /* default */;
181
- return (_b = this.trees)[pri] || (_b[pri] = this.createTree(pri));
175
+ var _a;
176
+ const pri = priority ?? this.priority ?? 2 /* default */;
177
+ return (_a = this.trees)[pri] || (_a[pri] = this.createTree(pri));
182
178
  }
183
179
  /**
184
180
  * @internal
185
181
  */
186
182
  findFacetOutput(facet) {
187
- var _a;
188
183
  let node = this.getTree();
189
184
  for (const index of facet.path) {
190
- node = node == null ? void 0 : node.children.get(index);
185
+ node = node?.children.get(index);
191
186
  }
192
- return (_a = node == null ? void 0 : node.getOutput()) != null ? _a : null;
187
+ return node?.getOutput() ?? null;
193
188
  }
194
189
  get schema() {
195
- var _a, _b;
196
190
  const output = this.findFacetOutput(schemaFacet);
197
- return (_b = (_a = output == null ? void 0 : output.find(Boolean)) == null ? void 0 : _a.schema) != null ? _b : null;
191
+ return output?.find(Boolean)?.schema ?? null;
198
192
  }
199
193
  };
200
194
 
@@ -212,8 +206,7 @@ function arraySubstract(a, b) {
212
206
  return a.filter((x) => !b.includes(x));
213
207
  }
214
208
  function toReversed(arr) {
215
- var _a, _b;
216
- return (_b = (_a = arr.toReversed) == null ? void 0 : _a.call(arr)) != null ? _b : [...arr].reverse();
209
+ return arr.toReversed?.() ?? [...arr].reverse();
217
210
  }
218
211
 
219
212
  // src/facets/facet-node.ts
@@ -228,7 +221,7 @@ function zip5(a, b, mapper) {
228
221
  }
229
222
  function unionInput(a, b) {
230
223
  if (!a && !b) return null;
231
- return uniqPush(a != null ? a : [], b != null ? b : []);
224
+ return uniqPush(a ?? [], b ?? []);
232
225
  }
233
226
  function subtractInput(a, b) {
234
227
  if (!a) return null;
@@ -354,8 +347,7 @@ var FacetExtensionImpl = class extends BaseExtension {
354
347
  * @internal
355
348
  */
356
349
  createTree(priority) {
357
- var _a;
358
- const pri = (_a = this.priority) != null ? _a : priority;
350
+ const pri = this.priority ?? priority;
359
351
  const inputs = [null, null, null, null, null];
360
352
  inputs[pri] = [...this.payloads];
361
353
  let node = new FacetNode(this.facet, inputs);
@@ -370,6 +362,17 @@ function defineFacetPayload(facet, payloads) {
370
362
  return new FacetExtensionImpl(facet, payloads);
371
363
  }
372
364
 
365
+ // src/utils/is-object.ts
366
+ function isObject(v) {
367
+ return typeof v === "object" && v != null;
368
+ }
369
+
370
+ // src/utils/is-element.ts
371
+ var ELEMENT_NODE = 1;
372
+ function isElement(el) {
373
+ return isObject(el) && el.nodeType === ELEMENT_NODE && typeof el.nodeName === "string";
374
+ }
375
+
373
376
  // src/utils/parse.ts
374
377
  import {
375
378
  DOMParser,
@@ -395,12 +398,10 @@ function findGlobalBrowserWindow() {
395
398
  }
396
399
  }
397
400
  function findBrowserDocument(options) {
398
- var _a, _b, _c;
399
- return (_c = (_a = options == null ? void 0 : options.document) != null ? _a : findGlobalBrowserDocument()) != null ? _c : (_b = findGlobalBrowserWindow()) == null ? void 0 : _b.document;
401
+ return options?.document ?? findGlobalBrowserDocument() ?? findGlobalBrowserWindow()?.document;
400
402
  }
401
403
  function findBrowserWindow(options) {
402
- var _a, _b, _c, _d, _e;
403
- return (_e = (_d = (_b = (_a = options == null ? void 0 : options.document) == null ? void 0 : _a.defaultView) != null ? _b : findGlobalBrowserWindow()) != null ? _d : (_c = findBrowserDocument(options)) == null ? void 0 : _c.defaultView) != null ? _e : void 0;
404
+ return options?.document?.defaultView ?? findGlobalBrowserWindow() ?? findBrowserDocument(options)?.defaultView ?? void 0;
404
405
  }
405
406
  function getBrowserDocument(options) {
406
407
  const doc = findBrowserDocument(options);
@@ -431,7 +432,7 @@ function nodeFromElement(element, options) {
431
432
  return (CustomDOMParser || DOMParser).fromSchema(schema).parse(element, parseOptions);
432
433
  }
433
434
  function elementFromNode(node, options) {
434
- const Serializer = (options == null ? void 0 : options.DOMSerializer) || DOMSerializer;
435
+ const Serializer = options?.DOMSerializer || DOMSerializer;
435
436
  const document2 = getBrowserDocument(options);
436
437
  const schema = node.type.schema;
437
438
  const serializer = Serializer.fromSchema(schema);
@@ -482,7 +483,6 @@ var stateFacet = defineFacet({
482
483
  reduce: () => {
483
484
  let callbacks = [];
484
485
  const state = (ctx) => {
485
- var _a, _b, _c, _d, _e, _f;
486
486
  const configs = callbacks.map((cb) => cb(ctx));
487
487
  const config = {
488
488
  schema: ctx.schema,
@@ -490,11 +490,11 @@ var stateFacet = defineFacet({
490
490
  plugins: []
491
491
  };
492
492
  for (const c of configs) {
493
- config.schema = (_a = config.schema) != null ? _a : c.schema;
494
- config.doc = (_b = config.doc) != null ? _b : c.doc;
495
- config.selection = (_c = config.selection) != null ? _c : c.selection;
496
- config.storedMarks = [...config.storedMarks, ...(_d = c.storedMarks) != null ? _d : []];
497
- config.plugins = uniqPush((_e = config.plugins) != null ? _e : [], (_f = c.plugins) != null ? _f : []);
493
+ config.schema = config.schema ?? c.schema;
494
+ config.doc = config.doc ?? c.doc;
495
+ config.selection = config.selection ?? c.selection;
496
+ config.storedMarks = [...config.storedMarks, ...c.storedMarks ?? []];
497
+ config.plugins = uniqPush(config.plugins ?? [], c.plugins ?? []);
498
498
  }
499
499
  assert(
500
500
  config.doc || config.schema,
@@ -516,19 +516,6 @@ var stateFacet = defineFacet({
516
516
 
517
517
  // src/utils/editor-content.ts
518
518
  import { Selection as Selection2 } from "@prosekit/pm/state";
519
-
520
- // src/utils/is-object.ts
521
- function isObject(v) {
522
- return typeof v === "object" && v != null;
523
- }
524
-
525
- // src/utils/is-element.ts
526
- var ELEMENT_NODE = 1;
527
- function isElement(el) {
528
- return isObject(el) && el.nodeType === ELEMENT_NODE && typeof el.nodeName === "string";
529
- }
530
-
531
- // src/utils/editor-content.ts
532
519
  function getEditorContentJSON(schema, content) {
533
520
  if (typeof content === "string") {
534
521
  return jsonFromHTML(content, { schema });
@@ -614,7 +601,7 @@ function isMarkAbsent(node, from, to, markType, attrs) {
614
601
  if (missing) {
615
602
  return false;
616
603
  }
617
- const allowed = (parent == null ? void 0 : parent.type.allowsMarkType(markType)) && !node2.marks.some((m) => m.type !== markType && m.type.excludes(markType));
604
+ const allowed = parent?.type.allowsMarkType(markType) && !node2.marks.some((m) => m.type !== markType && m.type.excludes(markType));
618
605
  if (allowed) {
619
606
  available = true;
620
607
  if (!includesMark(node2.marks, markType, attrs)) {
@@ -650,13 +637,9 @@ var UnionExtensionImpl = class extends BaseExtension {
650
637
  * @internal
651
638
  */
652
639
  createTree(priority) {
653
- var _a;
654
- const pri = (_a = this.priority) != null ? _a : priority;
640
+ const pri = this.priority ?? priority;
655
641
  const extensions = [...this.extension];
656
- extensions.sort((a, b) => {
657
- var _a2, _b;
658
- return ((_a2 = a.priority) != null ? _a2 : pri) - ((_b = b.priority) != null ? _b : pri);
659
- });
642
+ extensions.sort((a, b) => (a.priority ?? pri) - (b.priority ?? pri));
660
643
  const children = extensions.map((ext) => ext.getTree(pri));
661
644
  assert(children.length > 0);
662
645
  let node = children[0];
@@ -828,8 +811,7 @@ var EditorInstance = class {
828
811
  this.commands = {};
829
812
  this.afterMounted = [];
830
813
  this.getState = () => {
831
- var _a;
832
- return ((_a = this.view) == null ? void 0 : _a.state) || this.directEditorProps.state;
814
+ return this.view?.state || this.directEditorProps.state;
833
815
  };
834
816
  this.dispatch = (tr) => {
835
817
  if (this.view) {
@@ -838,6 +820,22 @@ var EditorInstance = class {
838
820
  this.directEditorProps.state = this.directEditorProps.state.apply(tr);
839
821
  }
840
822
  };
823
+ /**
824
+ * Return a JSON object representing the editor's current document.
825
+ */
826
+ this.getDocJSON = () => {
827
+ const state = this.getState();
828
+ return jsonFromNode(state.doc);
829
+ };
830
+ /**
831
+ * Return a HTML string representing the editor's current document.
832
+ */
833
+ this.getDocHTML = (options) => {
834
+ const serializer = this.getProp("clipboardSerializer");
835
+ const DOMSerializer2 = serializer ? { fromSchema: () => serializer } : void 0;
836
+ const doc = this.getDoc();
837
+ return htmlFromNode(doc, { ...options, DOMSerializer: DOMSerializer2 });
838
+ };
841
839
  this.tree = extension.getTree();
842
840
  const payload = this.tree.getRootOutput();
843
841
  const schema = payload.schema;
@@ -854,6 +852,12 @@ var EditorInstance = class {
854
852
  this.schema = state.schema;
855
853
  this.directEditorProps = { state, ...payload.view };
856
854
  }
855
+ getDoc() {
856
+ return this.getState().doc;
857
+ }
858
+ getProp(propName) {
859
+ return this.view?.someProp(propName) ?? this.directEditorProps[propName];
860
+ }
857
861
  updateState(state) {
858
862
  if (this.view) {
859
863
  this.view.updateState(state);
@@ -877,29 +881,28 @@ var EditorInstance = class {
877
881
  this.updateState(newState);
878
882
  }
879
883
  updateExtension(extension, add) {
880
- var _a, _b, _c, _d;
881
884
  const view = this.view;
882
885
  if (!view || view.isDestroyed) {
883
886
  return;
884
887
  }
885
888
  const tree = extension.getTree();
886
889
  const payload = tree.getRootOutput();
887
- if (payload == null ? void 0 : payload.schema) {
890
+ if (payload?.schema) {
888
891
  throw new ProseKitError("Schema cannot be changed");
889
892
  }
890
- if (payload == null ? void 0 : payload.view) {
893
+ if (payload?.view) {
891
894
  throw new ProseKitError("View cannot be changed");
892
895
  }
893
896
  const oldPayload = this.tree.getRootOutput();
894
- const oldPlugins = [...(_b = (_a = view.state) == null ? void 0 : _a.plugins) != null ? _b : []];
897
+ const oldPlugins = [...view.state?.plugins ?? []];
895
898
  this.tree = add ? unionFacetNode(this.tree, tree) : subtractFacetNode(this.tree, tree);
896
899
  const newPayload = this.tree.getRootOutput();
897
- const newPlugins = [...(_d = (_c = newPayload == null ? void 0 : newPayload.state) == null ? void 0 : _c.plugins) != null ? _d : []];
900
+ const newPlugins = [...newPayload?.state?.plugins ?? []];
898
901
  if (!deepEquals(oldPlugins, newPlugins)) {
899
902
  const state = view.state.reconfigure({ plugins: newPlugins });
900
903
  view.updateState(state);
901
904
  }
902
- if ((newPayload == null ? void 0 : newPayload.commands) && !deepEquals(oldPayload == null ? void 0 : oldPayload.commands, newPayload == null ? void 0 : newPayload.commands)) {
905
+ if (newPayload?.commands && !deepEquals(oldPayload?.commands, newPayload?.commands)) {
903
906
  const commands = newPayload.commands;
904
907
  const names = Object.keys(commands);
905
908
  for (const name of names) {
@@ -919,7 +922,7 @@ var EditorInstance = class {
919
922
  this.afterMounted.push(lazyCreate);
920
923
  return () => {
921
924
  canceled = true;
922
- lazyRemove == null ? void 0 : lazyRemove();
925
+ lazyRemove?.();
923
926
  };
924
927
  }
925
928
  this.updateExtension(extension, true);
@@ -963,14 +966,12 @@ var EditorInstance = class {
963
966
  view.setProps({ state: newState });
964
967
  }
965
968
  exec(command) {
966
- var _a;
967
969
  const state = this.getState();
968
- return command(state, this.dispatch, (_a = this.view) != null ? _a : void 0);
970
+ return command(state, this.dispatch, this.view ?? void 0);
969
971
  }
970
972
  canExec(command) {
971
- var _a;
972
973
  const state = this.getState();
973
- return command(state, void 0, (_a = this.view) != null ? _a : void 0);
974
+ return command(state, void 0, this.view ?? void 0);
974
975
  }
975
976
  defineCommand(name, commandCreator) {
976
977
  const action = (...args) => {
@@ -1015,15 +1016,13 @@ var Editor = class {
1015
1016
  * Focus the editor.
1016
1017
  */
1017
1018
  this.focus = () => {
1018
- var _a;
1019
- (_a = this.instance.view) == null ? void 0 : _a.focus();
1019
+ this.instance.view?.focus();
1020
1020
  };
1021
1021
  /**
1022
1022
  * Blur the editor.
1023
1023
  */
1024
1024
  this.blur = () => {
1025
- var _a;
1026
- (_a = this.instance.view) == null ? void 0 : _a.dom.blur();
1025
+ this.instance.view?.dom.blur();
1027
1026
  };
1028
1027
  /**
1029
1028
  * Register an extension to the editor. Return a function to unregister the
@@ -1060,6 +1059,18 @@ var Editor = class {
1060
1059
  this.setContent = (content, selection) => {
1061
1060
  return this.instance.setContent(content, selection);
1062
1061
  };
1062
+ /**
1063
+ * Return a JSON object representing the editor's current document.
1064
+ */
1065
+ this.getDocJSON = () => {
1066
+ return this.instance.getDocJSON();
1067
+ };
1068
+ /**
1069
+ * Return a HTML string representing the editor's current document.
1070
+ */
1071
+ this.getDocHTML = (options) => {
1072
+ return this.instance.getDocHTML(options);
1073
+ };
1063
1074
  /**
1064
1075
  * Execute the given command. Return `true` if the command was successfully
1065
1076
  * executed, otherwise `false`.
@@ -1107,8 +1118,7 @@ var Editor = class {
1107
1118
  * Whether the editor is focused.
1108
1119
  */
1109
1120
  get focused() {
1110
- var _a, _b;
1111
- return (_b = (_a = this.instance.view) == null ? void 0 : _a.hasFocus()) != null ? _b : false;
1121
+ return this.instance.view?.hasFocus() ?? false;
1112
1122
  }
1113
1123
  /**
1114
1124
  * All {@link CommandAction}s defined by the editor.
@@ -6,7 +6,7 @@ import {
6
6
  createNodeActions,
7
7
  isProseMirrorNode,
8
8
  setupEditorExtension
9
- } from "./chunk-6DIFWJEG.js";
9
+ } from "./chunk-B3WEP4DD.js";
10
10
 
11
11
  // src/test/test-editor.ts
12
12
  import {
@@ -72,8 +72,8 @@ function maybeResolve(doc, pos) {
72
72
  }
73
73
  function getSelection(doc) {
74
74
  const tags = doc.tags;
75
- const $a = maybeResolve(doc, tags == null ? void 0 : tags.a);
76
- const $b = maybeResolve(doc, tags == null ? void 0 : tags.b);
75
+ const $a = maybeResolve(doc, tags?.a);
76
+ const $b = maybeResolve(doc, tags?.b);
77
77
  if ($a) {
78
78
  if ($a.parent.inlineContent) {
79
79
  return new TextSelection($a, $b);
@@ -38,6 +38,8 @@ export { union } from './_tsup-dts-rollup.js';
38
38
  export { withPriority } from './_tsup-dts-rollup.js';
39
39
  export { EditorNotFoundError_alias_1 as EditorNotFoundError } from './_tsup-dts-rollup.js';
40
40
  export { ProseKitError_alias_1 as ProseKitError } from './_tsup-dts-rollup.js';
41
+ export { defineClipboardSerializer } from './_tsup-dts-rollup.js';
42
+ export { ClipboardSerializerOptions } from './_tsup-dts-rollup.js';
41
43
  export { defineBaseCommands } from './_tsup-dts-rollup.js';
42
44
  export { defineCommands } from './_tsup-dts-rollup.js';
43
45
  export { BaseCommandsExtension } from './_tsup-dts-rollup.js';
@@ -168,6 +170,7 @@ export { _getId } from './_tsup-dts-rollup.js';
168
170
  export { getMarkType } from './_tsup-dts-rollup.js';
169
171
  export { getNodeType } from './_tsup-dts-rollup.js';
170
172
  export { isAtBlockStart } from './_tsup-dts-rollup.js';
173
+ export { isElement } from './_tsup-dts-rollup.js';
171
174
  export { isInCodeBlock } from './_tsup-dts-rollup.js';
172
175
  export { isMarkAbsent } from './_tsup-dts-rollup.js';
173
176
  export { isMarkActive } from './_tsup-dts-rollup.js';
@@ -39,19 +39,18 @@ import {
39
39
  stateFromJSON,
40
40
  toReversed,
41
41
  union
42
- } from "./chunk-6DIFWJEG.js";
42
+ } from "./chunk-B3WEP4DD.js";
43
43
 
44
44
  // src/commands/add-mark.ts
45
45
  function addMark(options) {
46
46
  return (state, dispatch) => {
47
- var _a, _b;
48
47
  const mark = getMarkType(state.schema, options.type).create(options.attrs);
49
- const from = (_a = options.from) != null ? _a : state.selection.from;
50
- const to = (_b = options.to) != null ? _b : state.selection.to;
48
+ const from = options.from ?? state.selection.from;
49
+ const to = options.to ?? state.selection.to;
51
50
  if (from > to) {
52
51
  return false;
53
52
  }
54
- dispatch == null ? void 0 : dispatch(state.tr.addMark(from, to, mark));
53
+ dispatch?.(state.tr.addMark(from, to, mark));
55
54
  return true;
56
55
  };
57
56
  }
@@ -128,7 +127,7 @@ function defaultBlockAt(match) {
128
127
  // src/commands/insert-default-block.ts
129
128
  function insertDefaultBlock(options) {
130
129
  return (state, dispatch) => {
131
- const $pos = (options == null ? void 0 : options.pos) == null ? state.selection.$to : state.doc.resolve(options.pos);
130
+ const $pos = options?.pos == null ? state.selection.$to : state.doc.resolve(options.pos);
132
131
  const depth = $pos.parent.isTextblock ? $pos.depth - 1 : $pos.depth;
133
132
  const parent = $pos.node(depth);
134
133
  const index = $pos.indexAfter(depth);
@@ -165,12 +164,11 @@ function setSelectionAround(tr, pos) {
165
164
  // src/commands/insert-node.ts
166
165
  function insertNode(options) {
167
166
  return (state, dispatch) => {
168
- var _a;
169
167
  const node = options.node ? options.node : options.type ? getNodeType(state.schema, options.type).createAndFill(options.attrs) : null;
170
168
  assert(node, "You must provide either a node or a type");
171
169
  const insertPos = insertPoint(
172
170
  state.doc,
173
- (_a = options.pos) != null ? _a : state.selection.anchor,
171
+ options.pos ?? state.selection.anchor,
174
172
  node.type
175
173
  );
176
174
  if (insertPos == null) return false;
@@ -186,15 +184,14 @@ function insertNode(options) {
186
184
  // src/commands/remove-mark.ts
187
185
  function removeMark(options) {
188
186
  return (state, dispatch) => {
189
- var _a, _b;
190
187
  const markType = getMarkType(state.schema, options.type);
191
188
  const mark = options.attrs ? markType.create(options.attrs) : markType;
192
- const from = (_a = options.from) != null ? _a : state.selection.from;
193
- const to = (_b = options.to) != null ? _b : state.selection.to;
189
+ const from = options.from ?? state.selection.from;
190
+ const to = options.to ?? state.selection.to;
194
191
  if (from > to) {
195
192
  return false;
196
193
  }
197
- dispatch == null ? void 0 : dispatch(state.tr.removeMark(from, to, mark));
194
+ dispatch?.(state.tr.removeMark(from, to, mark));
198
195
  return true;
199
196
  };
200
197
  }
@@ -224,7 +221,7 @@ function removeNode(options) {
224
221
  const found = findParentNodeOfType(options.type, $pos);
225
222
  if (!found) return false;
226
223
  const { pos, node } = found;
227
- dispatch == null ? void 0 : dispatch(state.tr.delete(pos, pos + node.nodeSize));
224
+ dispatch?.(state.tr.delete(pos, pos + node.nodeSize));
228
225
  return true;
229
226
  };
230
227
  }
@@ -234,10 +231,10 @@ import {
234
231
  TextSelection as TextSelection4
235
232
  } from "@prosekit/pm/state";
236
233
  function getCustomSelection(state, from, to) {
237
- const pos = from != null ? from : to;
234
+ const pos = from ?? to;
238
235
  if (pos != null) {
239
- const $from = state.doc.resolve(from != null ? from : pos);
240
- const $to = state.doc.resolve(to != null ? to : pos);
236
+ const $from = state.doc.resolve(from ?? pos);
237
+ const $to = state.doc.resolve(to ?? pos);
241
238
  return TextSelection4.between($from, $to);
242
239
  }
243
240
  return state.selection;
@@ -293,10 +290,9 @@ function getNodeTypes(schema, types) {
293
290
  // src/commands/set-node-attrs.ts
294
291
  function setNodeAttrs(options) {
295
292
  return (state, dispatch) => {
296
- var _a, _b;
297
293
  const nodeTypes = getNodeTypes(state.schema, options.type);
298
- const from = (_a = options.pos) != null ? _a : state.selection.from;
299
- const to = (_b = options.pos) != null ? _b : state.selection.to;
294
+ const from = options.pos ?? state.selection.from;
295
+ const to = options.pos ?? state.selection.to;
300
296
  const positions = [];
301
297
  state.doc.nodesBetween(from, to, (node, pos) => {
302
298
  if (nodeTypes.includes(node.type)) {
@@ -368,7 +364,7 @@ function wrap(options) {
368
364
  const nodeType = getNodeType(state.schema, options.nodeType || options.type);
369
365
  const wrapping = findWrapping(range, nodeType, options.attrs);
370
366
  if (!wrapping) return false;
371
- dispatch == null ? void 0 : dispatch(state.tr.wrap(range, wrapping));
367
+ dispatch?.(state.tr.wrap(range, wrapping));
372
368
  return true;
373
369
  };
374
370
  }
@@ -392,13 +388,12 @@ import {
392
388
  import { ReplaceAroundStep } from "@prosekit/pm/transform";
393
389
  function unsetBlockType(options) {
394
390
  return (state, dispatch) => {
395
- var _a, _b;
396
- const from = (_a = options == null ? void 0 : options.from) != null ? _a : state.selection.from;
397
- const to = (_b = options == null ? void 0 : options.to) != null ? _b : state.selection.to;
391
+ const from = options?.from ?? state.selection.from;
392
+ const to = options?.to ?? state.selection.to;
398
393
  if (from > to) return false;
399
394
  const tr = state.tr;
400
395
  if (unsetTextBlockType(tr, from, to)) {
401
- dispatch == null ? void 0 : dispatch(tr);
396
+ dispatch?.(tr);
402
397
  return true;
403
398
  }
404
399
  return false;
@@ -432,11 +427,10 @@ function unsetTextBlockType(tr, from, to) {
432
427
  // src/commands/unset-mark.ts
433
428
  function unsetMark(options) {
434
429
  return (state, dispatch) => {
435
- var _a, _b;
436
- const from = (_a = options == null ? void 0 : options.from) != null ? _a : state.selection.from;
437
- const to = (_b = options == null ? void 0 : options.to) != null ? _b : state.selection.to;
430
+ const from = options?.from ?? state.selection.from;
431
+ const to = options?.to ?? state.selection.to;
438
432
  if (from > to) return false;
439
- dispatch == null ? void 0 : dispatch(state.tr.removeMark(from, to));
433
+ dispatch?.(state.tr.removeMark(from, to));
440
434
  return true;
441
435
  };
442
436
  }
@@ -448,11 +442,112 @@ function withPriority(extension, priority) {
448
442
  return result;
449
443
  }
450
444
 
445
+ // src/extensions/clipboard-serializer.ts
446
+ import {
447
+ DOMSerializer
448
+ } from "@prosekit/pm/model";
449
+ import {
450
+ PluginKey,
451
+ ProseMirrorPlugin
452
+ } from "@prosekit/pm/state";
453
+
454
+ // src/extensions/plugin.ts
455
+ import {
456
+ Plugin
457
+ } from "@prosekit/pm/state";
458
+ function definePlugin(plugin) {
459
+ if (plugin instanceof Plugin || Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin)) {
460
+ return definePluginPayload(() => plugin);
461
+ }
462
+ if (typeof plugin === "function") {
463
+ return definePluginPayload(plugin);
464
+ }
465
+ throw new TypeError("Invalid plugin");
466
+ }
467
+ function definePluginPayload(payload) {
468
+ return defineFacetPayload(pluginFacet, [payload]);
469
+ }
470
+ var pluginFacet = defineFacet({
471
+ reducer: (payloads) => {
472
+ return ({ schema }) => {
473
+ const plugins = [];
474
+ for (const payload of payloads) {
475
+ if (payload instanceof Plugin) {
476
+ plugins.push(payload);
477
+ } else if (Array.isArray(payload) && payload.every((p) => p instanceof Plugin)) {
478
+ plugins.push(...payload);
479
+ } else if (typeof payload === "function") {
480
+ plugins.push(...[payload({ schema })].flat());
481
+ } else {
482
+ throw new ProseKitError("Invalid plugin");
483
+ }
484
+ }
485
+ plugins.reverse();
486
+ return { plugins };
487
+ };
488
+ },
489
+ parent: stateFacet
490
+ });
491
+
492
+ // src/extensions/clipboard-serializer.ts
493
+ function mergeWrappers(wrappers) {
494
+ return (fn) => wrappers.filter(isNotNullish).reduce((fn2, wrapper) => wrapper(fn2), fn);
495
+ }
496
+ function wrapFunction(fn, wrapper) {
497
+ return wrapper ? wrapper(fn) : fn;
498
+ }
499
+ var CustomDOMSerializer = class extends DOMSerializer {
500
+ constructor(nodes, marks, serializeFragmentWrapper, serializeNodeWrapper) {
501
+ super(nodes, marks);
502
+ this.serializeFragmentWrapper = serializeFragmentWrapper;
503
+ this.serializeNodeWrapper = serializeNodeWrapper;
504
+ }
505
+ serializeFragment(...args) {
506
+ const fn = (...args2) => super.serializeFragment(...args2);
507
+ return wrapFunction(fn, this.serializeFragmentWrapper)(...args);
508
+ }
509
+ serializeNode(...args) {
510
+ const fn = (...args2) => super.serializeNode(...args2);
511
+ return wrapFunction(fn, this.serializeNodeWrapper)(...args);
512
+ }
513
+ };
514
+ function createCustomDOMSerializer(schema, options) {
515
+ const nodesFromSchema = (...args) => DOMSerializer.nodesFromSchema(...args);
516
+ const marksFromSchema = (...args) => DOMSerializer.marksFromSchema(...args);
517
+ const nodes = wrapFunction(nodesFromSchema, options.nodesFromSchemaWrapper)(schema);
518
+ const marks = wrapFunction(marksFromSchema, options.marksFromSchemaWrapper)(schema);
519
+ return new CustomDOMSerializer(nodes, marks, options.serializeFragmentWrapper, options.serializeNodeWrapper);
520
+ }
521
+ var clipboardSerializerFacet = defineFacet({
522
+ reducer: (inputs) => {
523
+ const options = {
524
+ serializeFragmentWrapper: mergeWrappers(inputs.map((input) => input.serializeFragmentWrapper)),
525
+ serializeNodeWrapper: mergeWrappers(inputs.map((input) => input.serializeNodeWrapper)),
526
+ nodesFromSchemaWrapper: mergeWrappers(inputs.map((input) => input.nodesFromSchemaWrapper)),
527
+ marksFromSchemaWrapper: mergeWrappers(inputs.map((input) => input.marksFromSchemaWrapper))
528
+ };
529
+ return ({ schema }) => {
530
+ const clipboardSerializer = createCustomDOMSerializer(schema, options);
531
+ return [
532
+ new ProseMirrorPlugin({
533
+ key: new PluginKey("prosekit-clipboard-serializer"),
534
+ props: { clipboardSerializer }
535
+ })
536
+ ];
537
+ };
538
+ },
539
+ singleton: true,
540
+ parent: pluginFacet
541
+ });
542
+ function defineClipboardSerializer(options) {
543
+ return defineFacetPayload(clipboardSerializerFacet, [options]);
544
+ }
545
+
451
546
  // src/commands/insert-text.ts
452
547
  function insertText({ text, from, to }) {
453
548
  return (state, dispatch) => {
454
549
  if (text) {
455
- dispatch == null ? void 0 : dispatch(state.tr.insertText(text, from, to));
550
+ dispatch?.(state.tr.insertText(text, from, to));
456
551
  }
457
552
  return true;
458
553
  };
@@ -464,7 +559,7 @@ import {
464
559
  } from "@prosekit/pm/state";
465
560
  function selectAll() {
466
561
  return (state, dispatch) => {
467
- dispatch == null ? void 0 : dispatch(state.tr.setSelection(new AllSelection(state.doc)));
562
+ dispatch?.(state.tr.setSelection(new AllSelection(state.doc)));
468
563
  return true;
469
564
  };
470
565
  }
@@ -509,14 +604,13 @@ import OrderedMap2 from "orderedmap";
509
604
  import OrderedMap from "orderedmap";
510
605
  var schemaSpecFacet = defineFacet({
511
606
  reducer: (specs) => {
512
- var _a;
513
607
  let nodes = OrderedMap.from({});
514
608
  let marks = OrderedMap.from({});
515
609
  let topNode = void 0;
516
610
  for (const spec of specs) {
517
611
  nodes = nodes.append(spec.nodes);
518
- marks = marks.append((_a = spec.marks) != null ? _a : {});
519
- topNode = topNode != null ? topNode : spec.topNode;
612
+ marks = marks.append(spec.marks ?? {});
613
+ topNode = topNode ?? spec.topNode;
520
614
  }
521
615
  return { nodes, marks, topNode };
522
616
  },
@@ -562,21 +656,20 @@ function mergeObjects(...objects) {
562
656
 
563
657
  // src/utils/merge-specs.ts
564
658
  function mergeSpecs(a, b) {
565
- var _a, _b, _c, _d, _e, _f;
566
659
  const attrs = {};
567
660
  const attrNames = /* @__PURE__ */ new Set([
568
- ...Object.keys((_a = a.attrs) != null ? _a : {}),
569
- ...Object.keys((_b = b.attrs) != null ? _b : {})
661
+ ...Object.keys(a.attrs ?? {}),
662
+ ...Object.keys(b.attrs ?? {})
570
663
  ]);
571
664
  for (const name of attrNames) {
572
- const attrSpecA = (_c = a.attrs) == null ? void 0 : _c[name];
573
- const attrSpecB = (_d = b.attrs) == null ? void 0 : _d[name];
665
+ const attrSpecA = a.attrs?.[name];
666
+ const attrSpecB = b.attrs?.[name];
574
667
  const attrSpecMerged = mergeObjects(attrSpecA, attrSpecB);
575
668
  if (attrSpecMerged) {
576
669
  attrs[name] = attrSpecMerged;
577
670
  }
578
671
  }
579
- const parseDOM = [...(_e = a.parseDOM) != null ? _e : [], ...(_f = b.parseDOM) != null ? _f : []];
672
+ const parseDOM = [...a.parseDOM ?? [], ...b.parseDOM ?? []];
580
673
  return mergeObjects(a, b, { attrs, parseDOM });
581
674
  }
582
675
 
@@ -584,10 +677,7 @@ function mergeSpecs(a, b) {
584
677
  function wrapOutputSpecAttrs(toDOM, options) {
585
678
  return (node, ...args) => {
586
679
  const dom = toDOM(node, ...args);
587
- const pairs = options.map((option) => {
588
- var _a;
589
- return (_a = option.toDOM) == null ? void 0 : _a.call(option, node.attrs[option.attr]);
590
- }).filter(isNotNullish);
680
+ const pairs = options.map((option) => option.toDOM?.(node.attrs[option.attr])).filter(isNotNullish);
591
681
  return insertOutputSpecAttrs(dom, pairs);
592
682
  };
593
683
  }
@@ -597,10 +687,9 @@ function wrapTagParseRuleAttrs(rule, options) {
597
687
  return {
598
688
  ...rule,
599
689
  getAttrs: (dom) => {
600
- var _a, _b;
601
- const baseAttrs = (_b = (_a = existingGetAttrs == null ? void 0 : existingGetAttrs(dom)) != null ? _a : existingAttrs) != null ? _b : {};
690
+ const baseAttrs = existingGetAttrs?.(dom) ?? existingAttrs ?? {};
602
691
  if (baseAttrs === false || !dom || !isElement(dom)) {
603
- return baseAttrs != null ? baseAttrs : null;
692
+ return baseAttrs ?? null;
604
693
  }
605
694
  const insertedAttrs = {};
606
695
  for (const option of options) {
@@ -724,49 +813,9 @@ function defineDoc() {
724
813
 
725
814
  // src/extensions/events/plugin-view.ts
726
815
  import {
727
- PluginKey,
728
- ProseMirrorPlugin
729
- } from "@prosekit/pm/state";
730
-
731
- // src/extensions/plugin.ts
732
- import {
733
- Plugin
816
+ PluginKey as PluginKey2,
817
+ ProseMirrorPlugin as ProseMirrorPlugin2
734
818
  } from "@prosekit/pm/state";
735
- function definePlugin(plugin) {
736
- if (plugin instanceof Plugin || Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin)) {
737
- return definePluginPayload(() => plugin);
738
- }
739
- if (typeof plugin === "function") {
740
- return definePluginPayload(plugin);
741
- }
742
- throw new TypeError("Invalid plugin");
743
- }
744
- function definePluginPayload(payload) {
745
- return defineFacetPayload(pluginFacet, [payload]);
746
- }
747
- var pluginFacet = defineFacet({
748
- reducer: (payloads) => {
749
- return ({ schema }) => {
750
- const plugins = [];
751
- for (const payload of payloads) {
752
- if (payload instanceof Plugin) {
753
- plugins.push(payload);
754
- } else if (Array.isArray(payload) && payload.every((p) => p instanceof Plugin)) {
755
- plugins.push(...payload);
756
- } else if (typeof payload === "function") {
757
- plugins.push(...[payload({ schema })].flat());
758
- } else {
759
- throw new ProseKitError("Invalid plugin");
760
- }
761
- }
762
- plugins.reverse();
763
- return { plugins };
764
- };
765
- },
766
- parent: stateFacet
767
- });
768
-
769
- // src/extensions/events/plugin-view.ts
770
819
  function defineMountHandler(handler) {
771
820
  return definePluginViewFacetPayload(["mount", handler]);
772
821
  }
@@ -784,7 +833,7 @@ var pluginViewFacet = defineFacet({
784
833
  let mountHandlers = [];
785
834
  let updateHandlers = [];
786
835
  let unmountHandlers = [];
787
- const plugin = new ProseMirrorPlugin({
836
+ const plugin = new ProseMirrorPlugin2({
788
837
  key: pluginKey,
789
838
  view: (view) => {
790
839
  mountHandlers.forEach((fn) => fn(view));
@@ -824,7 +873,7 @@ var pluginViewFacet = defineFacet({
824
873
  parent: pluginFacet,
825
874
  singleton: true
826
875
  });
827
- var pluginKey = new PluginKey("prosekit-plugin-view-handler");
876
+ var pluginKey = new PluginKey2("prosekit-plugin-view-handler");
828
877
 
829
878
  // src/extensions/events/doc-change.ts
830
879
  function defineDocChangeHandler(handler) {
@@ -837,8 +886,8 @@ function defineDocChangeHandler(handler) {
837
886
 
838
887
  // src/extensions/events/dom-event.ts
839
888
  import {
840
- PluginKey as PluginKey2,
841
- ProseMirrorPlugin as ProseMirrorPlugin2
889
+ PluginKey as PluginKey3,
890
+ ProseMirrorPlugin as ProseMirrorPlugin3
842
891
  } from "@prosekit/pm/state";
843
892
 
844
893
  // src/utils/combine-event-handlers.ts
@@ -878,7 +927,6 @@ var domEventFacet = defineFacet(
878
927
  const combinedHandlerMap = {};
879
928
  let plugin;
880
929
  const update = (payloads) => {
881
- var _a;
882
930
  let hasNewEvent = false;
883
931
  for (const [event] of payloads) {
884
932
  if (!setHandlersMap[event]) {
@@ -893,19 +941,19 @@ var domEventFacet = defineFacet(
893
941
  }
894
942
  const map = groupEntries(payloads);
895
943
  for (const [event, setHandlers] of Object.entries(setHandlersMap)) {
896
- const handlers = (_a = map[event]) != null ? _a : [];
944
+ const handlers = map[event] ?? [];
897
945
  setHandlers(handlers);
898
946
  }
899
947
  if (hasNewEvent) {
900
- plugin = new ProseMirrorPlugin2({
901
- key: new PluginKey2("prosekit-dom-event-handler"),
948
+ plugin = new ProseMirrorPlugin3({
949
+ key: new PluginKey3("prosekit-dom-event-handler"),
902
950
  props: { handleDOMEvents: combinedHandlerMap }
903
951
  });
904
952
  }
905
953
  };
906
954
  return function reducer(inputs) {
907
955
  update(inputs);
908
- return plugin != null ? plugin : [];
956
+ return plugin ?? [];
909
957
  };
910
958
  },
911
959
  parent: pluginFacet,
@@ -915,8 +963,8 @@ var domEventFacet = defineFacet(
915
963
 
916
964
  // src/extensions/events/editor-event.ts
917
965
  import {
918
- PluginKey as PluginKey3,
919
- ProseMirrorPlugin as ProseMirrorPlugin3
966
+ PluginKey as PluginKey4,
967
+ ProseMirrorPlugin as ProseMirrorPlugin4
920
968
  } from "@prosekit/pm/state";
921
969
  function defineEventFacetPayload(payload) {
922
970
  return defineFacetPayload(editorEventFacet, [payload]);
@@ -982,23 +1030,22 @@ function setupEditorEventPlugin() {
982
1030
  const [setDropHandlers, handleDrop] = combineEventHandlers();
983
1031
  const [setScrollToSelectionHandlers, handleScrollToSelection] = combineEventHandlers();
984
1032
  const update = (entries) => {
985
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
986
1033
  const map = groupEntries(entries);
987
- setKeyDownHandlers((_a = map.keyDown) != null ? _a : []);
988
- setKeyPressHandlers((_b = map.keyPress) != null ? _b : []);
989
- setTextInputHandlers((_c = map.textInput) != null ? _c : []);
990
- setClickOnHandlers((_d = map.clickOn) != null ? _d : []);
991
- setClickHandlers((_e = map.click) != null ? _e : []);
992
- setDoubleClickOnHandlers((_f = map.doubleClickOn) != null ? _f : []);
993
- setDoubleClickHandlers((_g = map.doubleClick) != null ? _g : []);
994
- setTripleClickOnHandlers((_h = map.tripleClickOn) != null ? _h : []);
995
- setTripleClickHandlers((_i = map.tripleClick) != null ? _i : []);
996
- setPasteHandlers((_j = map.paste) != null ? _j : []);
997
- setDropHandlers((_k = map.drop) != null ? _k : []);
998
- setScrollToSelectionHandlers((_l = map.scrollToSelection) != null ? _l : []);
1034
+ setKeyDownHandlers(map.keyDown ?? []);
1035
+ setKeyPressHandlers(map.keyPress ?? []);
1036
+ setTextInputHandlers(map.textInput ?? []);
1037
+ setClickOnHandlers(map.clickOn ?? []);
1038
+ setClickHandlers(map.click ?? []);
1039
+ setDoubleClickOnHandlers(map.doubleClickOn ?? []);
1040
+ setDoubleClickHandlers(map.doubleClick ?? []);
1041
+ setTripleClickOnHandlers(map.tripleClickOn ?? []);
1042
+ setTripleClickHandlers(map.tripleClick ?? []);
1043
+ setPasteHandlers(map.paste ?? []);
1044
+ setDropHandlers(map.drop ?? []);
1045
+ setScrollToSelectionHandlers(map.scrollToSelection ?? []);
999
1046
  };
1000
- const plugin = new ProseMirrorPlugin3({
1001
- key: new PluginKey3("prosekit-editor-event"),
1047
+ const plugin = new ProseMirrorPlugin4({
1048
+ key: new PluginKey4("prosekit-editor-event"),
1002
1049
  props: {
1003
1050
  handleKeyDown,
1004
1051
  handleKeyPress,
@@ -1042,7 +1089,7 @@ import { chainCommands } from "@prosekit/pm/commands";
1042
1089
  import { keydownHandler } from "@prosekit/pm/keymap";
1043
1090
  import {
1044
1091
  Plugin as Plugin2,
1045
- PluginKey as PluginKey4
1092
+ PluginKey as PluginKey5
1046
1093
  } from "@prosekit/pm/state";
1047
1094
  import mapValues from "just-map-values";
1048
1095
  function defineKeymap(keymap2) {
@@ -1085,7 +1132,7 @@ function mergeKeymaps(keymaps) {
1085
1132
  function mergeCommands(commands2) {
1086
1133
  return chainCommands(...commands2);
1087
1134
  }
1088
- var keymapPluginKey = new PluginKey4("prosekit-keymap");
1135
+ var keymapPluginKey = new PluginKey5("prosekit-keymap");
1089
1136
 
1090
1137
  // src/extensions/history.ts
1091
1138
  var keymap = {
@@ -1139,8 +1186,7 @@ var customBaseKeymap = {
1139
1186
  Backspace: customBackspace
1140
1187
  };
1141
1188
  function defineBaseKeymap(options) {
1142
- var _a;
1143
- const priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 1 /* low */;
1189
+ const priority = options?.priority ?? 1 /* low */;
1144
1190
  return withPriority(defineKeymap(customBaseKeymap), priority);
1145
1191
  }
1146
1192
 
@@ -1205,8 +1251,8 @@ function wrapParseRuleAttrs(rule, attrs) {
1205
1251
 
1206
1252
  // src/extensions/mark-view.ts
1207
1253
  import {
1208
- PluginKey as PluginKey5,
1209
- ProseMirrorPlugin as ProseMirrorPlugin4
1254
+ PluginKey as PluginKey6,
1255
+ ProseMirrorPlugin as ProseMirrorPlugin5
1210
1256
  } from "@prosekit/pm/state";
1211
1257
  function defineMarkView(options) {
1212
1258
  return defineFacetPayload(markViewFacet, [options]);
@@ -1220,8 +1266,8 @@ var markViewFacet = defineFacet({
1220
1266
  }
1221
1267
  }
1222
1268
  return () => [
1223
- new ProseMirrorPlugin4({
1224
- key: new PluginKey5("prosekit-mark-view"),
1269
+ new ProseMirrorPlugin5({
1270
+ key: new PluginKey6("prosekit-mark-view"),
1225
1271
  props: { markViews }
1226
1272
  })
1227
1273
  ];
@@ -1231,8 +1277,8 @@ var markViewFacet = defineFacet({
1231
1277
 
1232
1278
  // src/extensions/mark-view-effect.ts
1233
1279
  import {
1234
- PluginKey as PluginKey6,
1235
- ProseMirrorPlugin as ProseMirrorPlugin5
1280
+ PluginKey as PluginKey7,
1281
+ ProseMirrorPlugin as ProseMirrorPlugin6
1236
1282
  } from "@prosekit/pm/state";
1237
1283
  function defineMarkViewFactory(options) {
1238
1284
  const input = [options, null];
@@ -1255,8 +1301,8 @@ var markViewFactoryFacet = defineFacet({
1255
1301
  markViews[name] = factory.factory(args);
1256
1302
  }
1257
1303
  return () => [
1258
- new ProseMirrorPlugin5({
1259
- key: new PluginKey6("prosekit-mark-view-effect"),
1304
+ new ProseMirrorPlugin6({
1305
+ key: new PluginKey7("prosekit-mark-view-effect"),
1260
1306
  props: { markViews }
1261
1307
  })
1262
1308
  ];
@@ -1266,8 +1312,8 @@ var markViewFactoryFacet = defineFacet({
1266
1312
 
1267
1313
  // src/extensions/node-view.ts
1268
1314
  import {
1269
- PluginKey as PluginKey7,
1270
- ProseMirrorPlugin as ProseMirrorPlugin6
1315
+ PluginKey as PluginKey8,
1316
+ ProseMirrorPlugin as ProseMirrorPlugin7
1271
1317
  } from "@prosekit/pm/state";
1272
1318
  function defineNodeView(options) {
1273
1319
  return defineFacetPayload(nodeViewFacet, [options]);
@@ -1281,8 +1327,8 @@ var nodeViewFacet = defineFacet({
1281
1327
  }
1282
1328
  }
1283
1329
  return () => [
1284
- new ProseMirrorPlugin6({
1285
- key: new PluginKey7("prosekit-node-view"),
1330
+ new ProseMirrorPlugin7({
1331
+ key: new PluginKey8("prosekit-node-view"),
1286
1332
  props: { nodeViews }
1287
1333
  })
1288
1334
  ];
@@ -1292,8 +1338,8 @@ var nodeViewFacet = defineFacet({
1292
1338
 
1293
1339
  // src/extensions/node-view-effect.ts
1294
1340
  import {
1295
- PluginKey as PluginKey8,
1296
- ProseMirrorPlugin as ProseMirrorPlugin7
1341
+ PluginKey as PluginKey9,
1342
+ ProseMirrorPlugin as ProseMirrorPlugin8
1297
1343
  } from "@prosekit/pm/state";
1298
1344
  function defineNodeViewFactory(options) {
1299
1345
  const input = [options, null];
@@ -1316,8 +1362,8 @@ var nodeViewFactoryFacet = defineFacet({
1316
1362
  nodeViews[name] = factory.factory(args);
1317
1363
  }
1318
1364
  return () => [
1319
- new ProseMirrorPlugin7({
1320
- key: new PluginKey8("prosekit-node-view-effect"),
1365
+ new ProseMirrorPlugin8({
1366
+ key: new PluginKey9("prosekit-node-view-effect"),
1321
1367
  props: { nodeViews }
1322
1368
  })
1323
1369
  ];
@@ -1364,7 +1410,7 @@ function cache(fn) {
1364
1410
  var canUseRegexLookbehind = cache(() => {
1365
1411
  try {
1366
1412
  return "ab".replace(new RegExp("(?<=a)b", "g"), "c") === "ac";
1367
- } catch (e) {
1413
+ } catch {
1368
1414
  return false;
1369
1415
  }
1370
1416
  });
@@ -1475,6 +1521,7 @@ export {
1475
1521
  defineBaseKeymap,
1476
1522
  defineClickHandler,
1477
1523
  defineClickOnHandler,
1524
+ defineClipboardSerializer,
1478
1525
  defineCommands,
1479
1526
  defineDOMEventHandler,
1480
1527
  defineDefaultState,
@@ -1526,6 +1573,7 @@ export {
1526
1573
  isAllSelection,
1527
1574
  isApple,
1528
1575
  isAtBlockStart,
1576
+ isElement,
1529
1577
  isFragment,
1530
1578
  isInCodeBlock,
1531
1579
  isMark,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/core",
3
3
  "type": "module",
4
- "version": "0.7.14",
4
+ "version": "0.7.15",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -45,19 +45,19 @@
45
45
  "just-map-values": "^3.2.0",
46
46
  "orderedmap": "^2.1.1",
47
47
  "prosemirror-splittable": "^0.1.1",
48
- "type-fest": "^4.30.2",
48
+ "type-fest": "^4.32.0",
49
49
  "@prosekit/pm": "^0.1.9"
50
50
  },
51
51
  "devDependencies": {
52
- "@vitest/browser": "^2.1.8",
52
+ "@vitest/browser": "^3.0.4",
53
53
  "tsup": "^8.3.5",
54
- "typescript": "~5.6.3",
55
- "vitest": "^2.1.8",
54
+ "typescript": "~5.7.2",
55
+ "vitest": "^3.0.4",
56
56
  "@prosekit/dev": "0.0.0"
57
57
  },
58
58
  "scripts": {
59
- "build:tsup": "tsup",
60
- "build:tsc": "tsc -b tsconfig.json"
59
+ "build:tsc": "tsc -b tsconfig.json",
60
+ "build:tsup": "tsup"
61
61
  },
62
62
  "types": "./dist/prosekit-core.d.ts",
63
63
  "typesVersions": {