@prosekit/core 0.7.2 → 0.7.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.
@@ -2,61 +2,91 @@ import {
2
2
  Editor,
3
3
  EditorInstance,
4
4
  assert,
5
- createMarkBuilders,
6
- createNodeBuilders,
5
+ createMarkActions,
6
+ createNodeActions,
7
7
  setupEditorExtension
8
- } from "./chunk-YWQGKV6X.js";
8
+ } from "./chunk-52BNHWWJ.js";
9
9
 
10
10
  // src/test/test-editor.ts
11
11
  import { EditorState, NodeSelection, TextSelection } from "@prosekit/pm/state";
12
12
 
13
13
  // src/test/test-builder.ts
14
14
  var createNodeForTest = (type, attrs, children) => {
15
- let tags = {}, pos = type === type.schema.topNodeType ? 0 : 1, normalizedChildren = [];
16
- for (let child of children)
15
+ const tags = {};
16
+ const isTopNode = type === type.schema.topNodeType;
17
+ let pos = isTopNode ? 0 : 1;
18
+ const normalizedChildren = [];
19
+ for (const child of children) {
17
20
  if (child.tags) {
18
- for (let [key, value] of Object.entries(child.tags))
21
+ for (const [key, value] of Object.entries(child.tags)) {
19
22
  tags[key] = pos + value;
20
- normalizedChildren.push(child), pos += child.nodeSize;
23
+ }
24
+ normalizedChildren.push(child);
25
+ pos += child.nodeSize;
21
26
  } else if (child.isText) {
22
- let text = child.text, re = /<(a|b)>/g, i = 0, out = "";
23
- for (let match of text.matchAll(re))
24
- out += text.slice(i, match.index), tags[match[1]] = pos + out.length, i = match.index + match[0].length;
25
- out += text.slice(i), out && (normalizedChildren.push(child.type.schema.text(out).mark(child.marks)), pos += out.length);
26
- } else
27
- normalizedChildren.push(child), pos += child.nodeSize;
28
- let node = type.createAndFill(
27
+ const text = child.text;
28
+ const re = /<(a|b)>/g;
29
+ let i = 0;
30
+ let out = "";
31
+ for (const match of text.matchAll(re)) {
32
+ out += text.slice(i, match.index);
33
+ tags[match[1]] = pos + out.length;
34
+ i = match.index + match[0].length;
35
+ }
36
+ out += text.slice(i);
37
+ if (out) {
38
+ normalizedChildren.push(child.type.schema.text(out).mark(child.marks));
39
+ pos += out.length;
40
+ }
41
+ } else {
42
+ normalizedChildren.push(child);
43
+ pos += child.nodeSize;
44
+ }
45
+ }
46
+ const node = type.createAndFill(
29
47
  attrs,
30
48
  normalizedChildren
31
49
  );
32
- return assert(node, `Failed to create node ${type.name}`), node.tags = tags, node;
33
- }, applyMarkForTest = (mark, children) => children.map((node) => {
34
- let newNode = node.mark([mark]);
35
- return newNode.tags = node.tags, newNode;
36
- });
50
+ assert(node, `Failed to create node ${type.name}`);
51
+ node.tags = tags;
52
+ return node;
53
+ };
54
+ var applyMarkForTest = (mark, children) => {
55
+ return children.map((node) => {
56
+ const newNode = node.mark([mark]);
57
+ newNode.tags = node.tags;
58
+ return newNode;
59
+ });
60
+ };
37
61
 
38
62
  // src/test/test-editor.ts
39
63
  function maybeResolve(doc, pos) {
40
- if (pos != null)
64
+ if (pos != null) {
41
65
  return doc.resolve(pos);
66
+ }
67
+ return void 0;
42
68
  }
43
69
  function getSelection(doc) {
44
- let tags = doc.tags, $a = maybeResolve(doc, tags == null ? void 0 : tags.a), $b = maybeResolve(doc, tags == null ? void 0 : tags.b);
45
- return $a ? $a.parent.inlineContent ? new TextSelection($a, $b) : new NodeSelection($a) : TextSelection.atStart(doc);
70
+ const tags = doc.tags;
71
+ const $a = maybeResolve(doc, tags == null ? void 0 : tags.a);
72
+ const $b = maybeResolve(doc, tags == null ? void 0 : tags.b);
73
+ if ($a) {
74
+ if ($a.parent.inlineContent) {
75
+ return new TextSelection($a, $b);
76
+ } else {
77
+ return new NodeSelection($a);
78
+ }
79
+ }
80
+ return TextSelection.atStart(doc);
46
81
  }
47
82
  var TestEditorInstance = class extends EditorInstance {
48
83
  constructor(extension) {
49
- super(extension), this.nodeBuilders = createNodeBuilders(
50
- this.schema,
51
- this.getState,
52
- createNodeForTest
53
- ), this.markBuilders = createMarkBuilders(
54
- this.schema,
55
- this.getState,
56
- applyMarkForTest
57
- );
84
+ super(extension);
85
+ this.nodes = createNodeActions(this.schema, this.getState, createNodeForTest);
86
+ this.marks = createMarkActions(this.schema, this.getState, applyMarkForTest);
58
87
  }
59
- }, TestEditor = class extends Editor {
88
+ };
89
+ var TestEditor = class extends Editor {
60
90
  constructor(instance) {
61
91
  super(instance);
62
92
  }
@@ -77,11 +107,13 @@ var TestEditorInstance = class extends EditorInstance {
77
107
  assert(
78
108
  doc.type.schema === this.schema,
79
109
  "Document schema does not match editor schema"
80
- ), assert(
110
+ );
111
+ assert(
81
112
  doc.type === this.schema.topNodeType,
82
113
  "Document type does not match editor top node type"
83
114
  );
84
- let selection = getSelection(doc), state = EditorState.create({
115
+ const selection = getSelection(doc);
116
+ const state = EditorState.create({
85
117
  doc,
86
118
  selection,
87
119
  plugins: this.state.plugins
@@ -93,7 +125,7 @@ var TestEditorInstance = class extends EditorInstance {
93
125
  }
94
126
  };
95
127
  function createTestEditor(options) {
96
- let extension = setupEditorExtension(options);
128
+ const extension = setupEditorExtension(options);
97
129
  return new TestEditor(new TestEditorInstance(extension));
98
130
  }
99
131
  export {
@@ -22,8 +22,11 @@ export { unsetMark } from './_tsup-dts-rollup';
22
22
  export { UnsetMarkOptions } from './_tsup-dts-rollup';
23
23
  export { wrap } from './_tsup-dts-rollup';
24
24
  export { WrapOptions } from './_tsup-dts-rollup';
25
+ export { MarkAction } from './_tsup-dts-rollup';
25
26
  export { MarkBuilder } from './_tsup-dts-rollup';
27
+ export { NodeAction } from './_tsup-dts-rollup';
26
28
  export { NodeBuilder } from './_tsup-dts-rollup';
29
+ export { NodeChild } from './_tsup-dts-rollup';
27
30
  export { Editor } from './_tsup-dts-rollup';
28
31
  export { createEditor } from './_tsup-dts-rollup';
29
32
  export { EditorOptions } from './_tsup-dts-rollup';
@@ -73,6 +76,7 @@ export { MountHandler } from './_tsup-dts-rollup';
73
76
  export { UnmountHandler } from './_tsup-dts-rollup';
74
77
  export { UpdateHandler } from './_tsup-dts-rollup';
75
78
  export { defineHistory } from './_tsup-dts-rollup';
79
+ export { HistoryOptions } from './_tsup-dts-rollup';
76
80
  export { defineKeymap } from './_tsup-dts-rollup';
77
81
  export { keymapFacet } from './_tsup-dts-rollup';
78
82
  export { Keymap } from './_tsup-dts-rollup';
@@ -100,20 +104,32 @@ export { defineText } from './_tsup-dts-rollup';
100
104
  export { defineFacet } from './_tsup-dts-rollup';
101
105
  export { Facet } from './_tsup-dts-rollup';
102
106
  export { defineFacetPayload } from './_tsup-dts-rollup';
107
+ export { AnyAttrs } from './_tsup-dts-rollup';
108
+ export { AttrSpec } from './_tsup-dts-rollup';
103
109
  export { BaseNodeViewOptions } from './_tsup-dts-rollup';
104
- export { CommandTyping } from './_tsup-dts-rollup';
105
110
  export { Extension } from './_tsup-dts-rollup';
106
111
  export { ExtensionTyping } from './_tsup-dts-rollup';
112
+ export { ExtractCommandActions } from './_tsup-dts-rollup';
107
113
  export { ExtractCommandAppliers } from './_tsup-dts-rollup';
108
114
  export { ExtractCommandCreators } from './_tsup-dts-rollup';
115
+ export { ExtractMarkActions } from './_tsup-dts-rollup';
109
116
  export { ExtractMarks } from './_tsup-dts-rollup';
117
+ export { ExtractNodeActions } from './_tsup-dts-rollup';
110
118
  export { ExtractNodes } from './_tsup-dts-rollup';
111
119
  export { UnionExtension } from './_tsup-dts-rollup';
120
+ export { CommandAction } from './_tsup-dts-rollup';
121
+ export { CommandTyping } from './_tsup-dts-rollup';
122
+ export { MarkTyping } from './_tsup-dts-rollup';
123
+ export { ToMarkAction } from './_tsup-dts-rollup';
124
+ export { NodeTyping } from './_tsup-dts-rollup';
125
+ export { ToNodeAction } from './_tsup-dts-rollup';
112
126
  export { NodeJSON } from './_tsup-dts-rollup';
113
127
  export { SelectionJSON } from './_tsup-dts-rollup';
114
128
  export { StateJSON } from './_tsup-dts-rollup';
115
129
  export { StepJSON } from './_tsup-dts-rollup';
130
+ export { PickSubType } from './_tsup-dts-rollup';
116
131
  export { Priority } from './_tsup-dts-rollup';
132
+ export { SimplifyDeeper } from './_tsup-dts-rollup';
117
133
  export { SimplifyUnion } from './_tsup-dts-rollup';
118
134
  export { assert } from './_tsup-dts-rollup';
119
135
  export { canUseRegexLookbehind } from './_tsup-dts-rollup';