@thomasfosterau/effect-richtext 0.0.0 → 0.1.0

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 (176) hide show
  1. package/LICENSE +48 -0
  2. package/README.md +117 -1
  3. package/dist/_virtual/_rolldown/runtime.js +12 -0
  4. package/dist/commands/commands.d.ts +323 -0
  5. package/dist/commands/commands.js +722 -0
  6. package/dist/commands/internal.js +43 -0
  7. package/dist/commands/keymaps.d.ts +46 -0
  8. package/dist/commands/keymaps.js +64 -0
  9. package/dist/commands.d.ts +3 -0
  10. package/dist/commands.js +3 -0
  11. package/dist/compat/commands.d.ts +250 -0
  12. package/dist/compat/commands.js +275 -0
  13. package/dist/compat/internal/core.d.ts +20 -0
  14. package/dist/compat/internal/core.js +148 -0
  15. package/dist/compat/internal/props.js +82 -0
  16. package/dist/compat/keymap.d.ts +21 -0
  17. package/dist/compat/keymap.js +38 -0
  18. package/dist/compat/model.d.ts +893 -0
  19. package/dist/compat/model.js +1212 -0
  20. package/dist/compat/orderedmap.d.ts +74 -0
  21. package/dist/compat/orderedmap.js +124 -0
  22. package/dist/compat/schema-basic.d.ts +38 -0
  23. package/dist/compat/schema-basic.js +238 -0
  24. package/dist/compat/schema-list.d.ts +81 -0
  25. package/dist/compat/schema-list.js +156 -0
  26. package/dist/compat/state.d.ts +415 -0
  27. package/dist/compat/state.js +689 -0
  28. package/dist/compat/test-builder.d.ts +98 -0
  29. package/dist/compat/test-builder.js +197 -0
  30. package/dist/compat/transform.d.ts +458 -0
  31. package/dist/compat/transform.js +803 -0
  32. package/dist/compat/view.d.ts +411 -0
  33. package/dist/compat/view.js +409 -0
  34. package/dist/dropcursor.d.ts +46 -0
  35. package/dist/dropcursor.js +176 -0
  36. package/dist/extensions/defaults.d.ts +716 -0
  37. package/dist/extensions/defaults.js +209 -0
  38. package/dist/extensions/editor.d.ts +246 -0
  39. package/dist/extensions/editor.js +271 -0
  40. package/dist/extensions/extension.d.ts +375 -0
  41. package/dist/extensions/extension.js +233 -0
  42. package/dist/extensions.d.ts +4 -0
  43. package/dist/extensions.js +4 -0
  44. package/dist/gapcursor.d.ts +66 -0
  45. package/dist/gapcursor.js +273 -0
  46. package/dist/history.d.ts +178 -0
  47. package/dist/history.js +412 -0
  48. package/dist/html.d.ts +158 -0
  49. package/dist/html.js +164 -0
  50. package/dist/inputrules.d.ts +271 -0
  51. package/dist/inputrules.js +321 -0
  52. package/dist/internal/attempt.js +15 -0
  53. package/dist/internal/json.js +29 -0
  54. package/dist/keymap/keymap.d.ts +130 -0
  55. package/dist/keymap/keymap.js +159 -0
  56. package/dist/keymap.d.ts +2 -0
  57. package/dist/keymap.js +1 -0
  58. package/dist/markdown/errors.d.ts +23 -0
  59. package/dist/markdown/errors.js +26 -0
  60. package/dist/markdown/from_markdown.d.ts +185 -0
  61. package/dist/markdown/from_markdown.js +266 -0
  62. package/dist/markdown/schema.d.ts +522 -0
  63. package/dist/markdown/schema.js +292 -0
  64. package/dist/markdown/to_markdown.d.ts +251 -0
  65. package/dist/markdown/to_markdown.js +413 -0
  66. package/dist/markdown.d.ts +5 -0
  67. package/dist/markdown.js +5 -0
  68. package/dist/model/attrsCodec.js +48 -0
  69. package/dist/model/comparedeep.js +17 -0
  70. package/dist/model/content.d.ts +232 -0
  71. package/dist/model/content.js +630 -0
  72. package/dist/model/diff.js +66 -0
  73. package/dist/model/dom.d.ts +3 -0
  74. package/dist/model/errors.d.ts +90 -0
  75. package/dist/model/errors.js +76 -0
  76. package/dist/model/fragment.d.ts +131 -0
  77. package/dist/model/fragment.js +262 -0
  78. package/dist/model/from_dom.d.ts +299 -0
  79. package/dist/model/from_dom.js +618 -0
  80. package/dist/model/json.d.ts +37 -0
  81. package/dist/model/json.js +126 -0
  82. package/dist/model/mark.d.ts +73 -0
  83. package/dist/model/mark.js +121 -0
  84. package/dist/model/node.d.ts +267 -0
  85. package/dist/model/node.js +434 -0
  86. package/dist/model/replace.d.ts +78 -0
  87. package/dist/model/replace.js +207 -0
  88. package/dist/model/resolvedpos.d.ts +196 -0
  89. package/dist/model/resolvedpos.js +305 -0
  90. package/dist/model/schema.d.ts +740 -0
  91. package/dist/model/schema.js +451 -0
  92. package/dist/model/to_dom.d.ts +169 -0
  93. package/dist/model/to_dom.js +238 -0
  94. package/dist/model.d.ts +12 -0
  95. package/dist/model.js +12 -0
  96. package/dist/placeholder.d.ts +53 -0
  97. package/dist/placeholder.js +79 -0
  98. package/dist/reactive/observer.d.ts +54 -0
  99. package/dist/reactive/observer.js +61 -0
  100. package/dist/reactive/selectors.d.ts +22 -0
  101. package/dist/reactive/selectors.js +61 -0
  102. package/dist/reactive/stateref.d.ts +72 -0
  103. package/dist/reactive/stateref.js +71 -0
  104. package/dist/reactive/streams.d.ts +83 -0
  105. package/dist/reactive/streams.js +85 -0
  106. package/dist/reactive.d.ts +16 -0
  107. package/dist/reactive.js +26 -0
  108. package/dist/schema-basic.d.ts +448 -0
  109. package/dist/schema-basic.js +269 -0
  110. package/dist/schema-list/commands.d.ts +66 -0
  111. package/dist/schema-list/commands.js +203 -0
  112. package/dist/schema-list.d.ts +92 -0
  113. package/dist/schema-list.js +100 -0
  114. package/dist/state/errors.d.ts +39 -0
  115. package/dist/state/errors.js +32 -0
  116. package/dist/state/plugin.d.ts +232 -0
  117. package/dist/state/plugin.js +82 -0
  118. package/dist/state/selection.d.ts +297 -0
  119. package/dist/state/selection.js +486 -0
  120. package/dist/state/state.d.ts +212 -0
  121. package/dist/state/state.js +489 -0
  122. package/dist/state/transaction.d.ts +145 -0
  123. package/dist/state/transaction.js +195 -0
  124. package/dist/state.d.ts +6 -0
  125. package/dist/state.js +6 -0
  126. package/dist/test-builder.d.ts +3582 -0
  127. package/dist/test-builder.js +239 -0
  128. package/dist/transform/attr_step.d.ts +60 -0
  129. package/dist/transform/attr_step.js +105 -0
  130. package/dist/transform/errors.d.ts +50 -0
  131. package/dist/transform/errors.js +35 -0
  132. package/dist/transform/map.d.ts +182 -0
  133. package/dist/transform/map.js +280 -0
  134. package/dist/transform/mark.js +98 -0
  135. package/dist/transform/mark_set_step.js +69 -0
  136. package/dist/transform/mark_step.d.ts +113 -0
  137. package/dist/transform/mark_step.js +225 -0
  138. package/dist/transform/replace.d.ts +18 -0
  139. package/dist/transform/replace.js +381 -0
  140. package/dist/transform/replace_step.d.ts +109 -0
  141. package/dist/transform/replace_step.js +175 -0
  142. package/dist/transform/step.d.ts +157 -0
  143. package/dist/transform/step.js +168 -0
  144. package/dist/transform/structure.d.ts +89 -0
  145. package/dist/transform/structure.js +350 -0
  146. package/dist/transform/transform.d.ts +248 -0
  147. package/dist/transform/transform.js +373 -0
  148. package/dist/transform.d.ts +10 -0
  149. package/dist/transform.js +10 -0
  150. package/dist/view/browser.js +39 -0
  151. package/dist/view/capturekeys.js +282 -0
  152. package/dist/view/clipboard.d.ts +8 -0
  153. package/dist/view/clipboard.js +245 -0
  154. package/dist/view/decoration.d.ts +339 -0
  155. package/dist/view/decoration.js +566 -0
  156. package/dist/view/dom.d.ts +18 -0
  157. package/dist/view/dom.js +140 -0
  158. package/dist/view/domchange.js +295 -0
  159. package/dist/view/domcoords.d.ts +22 -0
  160. package/dist/view/domcoords.js +448 -0
  161. package/dist/view/domobserver.d.ts +47 -0
  162. package/dist/view/domobserver.js +328 -0
  163. package/dist/view/errors.d.ts +18 -0
  164. package/dist/view/errors.js +21 -0
  165. package/dist/view/input.d.ts +58 -0
  166. package/dist/view/input.js +704 -0
  167. package/dist/view/selection.js +198 -0
  168. package/dist/view/view.d.ts +699 -0
  169. package/dist/view/view.js +623 -0
  170. package/dist/view/viewdesc.d.ts +236 -0
  171. package/dist/view/viewdesc.js +1205 -0
  172. package/dist/view-css.d.ts +43 -0
  173. package/dist/view-css.js +124 -0
  174. package/dist/view.d.ts +6 -0
  175. package/dist/view.js +4 -0
  176. package/package.json +200 -4
@@ -0,0 +1,43 @@
1
+ import * as Effect from "effect/Effect";
2
+ // src/commands/internal.ts
3
+ /**
4
+ * Helpers shared by the command modules.
5
+ *
6
+ * @internal
7
+ */
8
+ /** @internal */
9
+ const succeedTrue = Effect.succeed(true);
10
+ /** @internal */
11
+ const succeedFalse = Effect.succeed(false);
12
+ /**
13
+ * Build a command from a synchronous body. The body receives whether a
14
+ * dispatch function was given, and returns `false`, `true`, or a
15
+ * transaction to dispatch. Exceptions thrown by the body are defects.
16
+ *
17
+ * @internal
18
+ */
19
+ const syncCommand = (body) => (state, dispatch, view) => Effect.suspend(() => {
20
+ const result = body(state, dispatch !== void 0, view);
21
+ if (result === true) return succeedTrue;
22
+ if (result === false) return succeedFalse;
23
+ return dispatch ? Effect.as(dispatch(result), true) : succeedTrue;
24
+ });
25
+ /**
26
+ * When dispatching, build the transaction; otherwise just report that
27
+ * the command applies.
28
+ *
29
+ * @internal
30
+ */
31
+ const done = (dispatching, build) => dispatching ? build() : true;
32
+ /**
33
+ * Wrap a dispatch function so that the marks active before a split are
34
+ * kept active after it.
35
+ *
36
+ * @internal
37
+ */
38
+ const keepMarks = (state, dispatch) => dispatch && ((tr) => Effect.suspend(() => {
39
+ const marks = state.storedMarksOrNull || state.selection.$to.parentOffset && state.selection.$from.marks();
40
+ if (marks) tr.ensureMarks(marks);
41
+ return dispatch(tr);
42
+ }));
43
+ export { done, keepMarks, succeedFalse, succeedTrue, syncCommand };
@@ -0,0 +1,46 @@
1
+ import { Command } from "../state/transaction.js";
2
+ import "../state.js";
3
+ /**
4
+ * A keymap: commands keyed by key name (`"Mod-b"`, `"Enter"`), as the base
5
+ * keymaps below and `keymap(...)` from `@thomasfosterau/effect-richtext/keymap` use them.
6
+ *
7
+ * @since 0.1.0
8
+ * @category models
9
+ */
10
+ export interface Keymap {
11
+ readonly [key: string]: Command;
12
+ }
13
+ /**
14
+ * A basic keymap containing bindings not specific to any schema. Binds
15
+ * the following keys (when multiple commands are listed, they are
16
+ * chained with `chainCommands`):
17
+ *
18
+ * - **Enter** to `newlineInCode`, `createParagraphNear`, `liftEmptyBlock`, `splitBlock`
19
+ * - **Mod-Enter** to `exitCode`
20
+ * - **Backspace**, **Mod-Backspace** and **Shift-Backspace** to `deleteSelection`, `joinBackward`, `selectNodeBackward`
21
+ * - **Delete** and **Mod-Delete** to `deleteSelection`, `joinForward`, `selectNodeForward`
22
+ * - **Mod-a** to `selectAll`
23
+ *
24
+ * @since 0.1.0
25
+ * @category keymaps
26
+ */
27
+ export declare const pcBaseKeymap: Keymap;
28
+ /**
29
+ * A copy of `pcBaseKeymap` that also binds **Ctrl-h** like Backspace,
30
+ * **Ctrl-d** like Delete, **Alt-Backspace** like Ctrl-Backspace, and
31
+ * **Ctrl-Alt-Backspace**, **Alt-Delete**, and **Alt-d** like
32
+ * Ctrl-Delete, plus **Ctrl-a** / **Ctrl-e** to `selectTextblockStart` /
33
+ * `selectTextblockEnd`.
34
+ *
35
+ * @since 0.1.0
36
+ * @category keymaps
37
+ */
38
+ export declare const macBaseKeymap: Keymap;
39
+ /**
40
+ * Depending on the detected platform, this will hold `pcBaseKeymap` or
41
+ * `macBaseKeymap`.
42
+ *
43
+ * @since 0.1.0
44
+ * @category keymaps
45
+ */
46
+ export declare const baseKeymap: Keymap;
@@ -0,0 +1,64 @@
1
+ import { chainCommands, createParagraphNear, deleteSelection, exitCode, joinBackward, joinForward, liftEmptyBlock, newlineInCode, selectAll, selectNodeBackward, selectNodeForward, selectTextblockEnd, selectTextblockStart, splitBlock } from "./commands.js";
2
+ import * as Predicate from "effect/Predicate";
3
+ // src/commands/keymaps.ts
4
+ /**
5
+ * Base keymaps, ported from `prosemirror-commands`.
6
+ *
7
+ * @since 0.1.0
8
+ */
9
+ const backspace = chainCommands(deleteSelection, joinBackward, selectNodeBackward);
10
+ const del = chainCommands(deleteSelection, joinForward, selectNodeForward);
11
+ /**
12
+ * A basic keymap containing bindings not specific to any schema. Binds
13
+ * the following keys (when multiple commands are listed, they are
14
+ * chained with `chainCommands`):
15
+ *
16
+ * - **Enter** to `newlineInCode`, `createParagraphNear`, `liftEmptyBlock`, `splitBlock`
17
+ * - **Mod-Enter** to `exitCode`
18
+ * - **Backspace**, **Mod-Backspace** and **Shift-Backspace** to `deleteSelection`, `joinBackward`, `selectNodeBackward`
19
+ * - **Delete** and **Mod-Delete** to `deleteSelection`, `joinForward`, `selectNodeForward`
20
+ * - **Mod-a** to `selectAll`
21
+ *
22
+ * @since 0.1.0
23
+ * @category keymaps
24
+ */
25
+ const pcBaseKeymap = {
26
+ Enter: chainCommands(newlineInCode, createParagraphNear, liftEmptyBlock, splitBlock),
27
+ "Mod-Enter": exitCode,
28
+ Backspace: backspace,
29
+ "Mod-Backspace": backspace,
30
+ "Shift-Backspace": backspace,
31
+ Delete: del,
32
+ "Mod-Delete": del,
33
+ "Mod-a": selectAll
34
+ };
35
+ /**
36
+ * A copy of `pcBaseKeymap` that also binds **Ctrl-h** like Backspace,
37
+ * **Ctrl-d** like Delete, **Alt-Backspace** like Ctrl-Backspace, and
38
+ * **Ctrl-Alt-Backspace**, **Alt-Delete**, and **Alt-d** like
39
+ * Ctrl-Delete, plus **Ctrl-a** / **Ctrl-e** to `selectTextblockStart` /
40
+ * `selectTextblockEnd`.
41
+ *
42
+ * @since 0.1.0
43
+ * @category keymaps
44
+ */
45
+ const macBaseKeymap = {
46
+ "Ctrl-h": backspace,
47
+ "Alt-Backspace": backspace,
48
+ "Ctrl-d": del,
49
+ "Ctrl-Alt-Backspace": del,
50
+ "Alt-Delete": del,
51
+ "Alt-d": del,
52
+ "Ctrl-a": selectTextblockStart,
53
+ "Ctrl-e": selectTextblockEnd,
54
+ ...pcBaseKeymap
55
+ };
56
+ /**
57
+ * Depending on the detected platform, this will hold `pcBaseKeymap` or
58
+ * `macBaseKeymap`.
59
+ *
60
+ * @since 0.1.0
61
+ * @category keymaps
62
+ */
63
+ const baseKeymap = !Predicate.isUndefined(globalThis.navigator) && /Mac|iP(hone|[oa]d)/.test(navigator.platform) ? macBaseKeymap : pcBaseKeymap;
64
+ export { baseKeymap, macBaseKeymap, pcBaseKeymap };
@@ -0,0 +1,3 @@
1
+ import { CommandError, CommandRequirements, SplitNodeType, TextblockBoundaryDirection, TextblockBoundaryView, ToggleMarkOptions, autoJoin, chainCommands, createParagraphNear, deleteSelection, exitCode, isTextblockBoundaryView, joinBackward, joinDown, joinForward, joinTextblockBackward, joinTextblockForward, joinUp, lift, liftEmptyBlock, newlineInCode, selectAll, selectNodeBackward, selectNodeForward, selectParentNode, selectTextblockEnd, selectTextblockStart, setBlockType, splitBlock, splitBlockAs, splitBlockKeepMarks, toggleMark, wrapIn } from "./commands/commands.js";
2
+ import { Keymap, baseKeymap, macBaseKeymap, pcBaseKeymap } from "./commands/keymaps.js";
3
+ export { CommandError, CommandRequirements, Keymap, SplitNodeType, TextblockBoundaryDirection, TextblockBoundaryView, ToggleMarkOptions, autoJoin, baseKeymap, chainCommands, createParagraphNear, deleteSelection, exitCode, isTextblockBoundaryView, joinBackward, joinDown, joinForward, joinTextblockBackward, joinTextblockForward, joinUp, lift, liftEmptyBlock, macBaseKeymap, newlineInCode, pcBaseKeymap, selectAll, selectNodeBackward, selectNodeForward, selectParentNode, selectTextblockEnd, selectTextblockStart, setBlockType, splitBlock, splitBlockAs, splitBlockKeepMarks, toggleMark, wrapIn };
@@ -0,0 +1,3 @@
1
+ import { autoJoin, chainCommands, createParagraphNear, deleteSelection, exitCode, isTextblockBoundaryView, joinBackward, joinDown, joinForward, joinTextblockBackward, joinTextblockForward, joinUp, lift, liftEmptyBlock, newlineInCode, selectAll, selectNodeBackward, selectNodeForward, selectParentNode, selectTextblockEnd, selectTextblockStart, setBlockType, splitBlock, splitBlockAs, splitBlockKeepMarks, toggleMark, wrapIn } from "./commands/commands.js";
2
+ import { baseKeymap, macBaseKeymap, pcBaseKeymap } from "./commands/keymaps.js";
3
+ export { autoJoin, baseKeymap, chainCommands, createParagraphNear, deleteSelection, exitCode, isTextblockBoundaryView, joinBackward, joinDown, joinForward, joinTextblockBackward, joinTextblockForward, joinUp, lift, liftEmptyBlock, macBaseKeymap, newlineInCode, pcBaseKeymap, selectAll, selectNodeBackward, selectNodeForward, selectParentNode, selectTextblockEnd, selectTextblockStart, setBlockType, splitBlock, splitBlockAs, splitBlockKeepMarks, toggleMark, wrapIn };
@@ -0,0 +1,250 @@
1
+ import { Attrs, MarkType, Node, NodeType, ResolvedPos } from "./model.js";
2
+ import { Command, fromCoreCommand, toCoreCommand } from "./state.js";
3
+ /**
4
+ * Delete the selection, if there is one.
5
+ *
6
+ * @since 0.1.0
7
+ * @category commands
8
+ */
9
+ export declare const deleteSelection: Command;
10
+ /**
11
+ * If the selection is empty and at the start of a textblock, try to
12
+ * reduce the distance between that block and the one before it.
13
+ *
14
+ * @since 0.1.0
15
+ * @category commands
16
+ */
17
+ export declare const joinBackward: Command;
18
+ /**
19
+ * A more limited form of `joinBackward` that only tries to join the
20
+ * current textblock to the one before it, if the cursor is at the
21
+ * start of a textblock.
22
+ *
23
+ * @since 0.1.0
24
+ * @category commands
25
+ */
26
+ export declare const joinTextblockBackward: Command;
27
+ /**
28
+ * A more limited form of `joinForward` that only tries to join the
29
+ * current textblock to the one after it, if the cursor is at the end
30
+ * of a textblock.
31
+ *
32
+ * @since 0.1.0
33
+ * @category commands
34
+ */
35
+ export declare const joinTextblockForward: Command;
36
+ /**
37
+ * When the selection is empty and at the start of a textblock, select
38
+ * the node before that textblock, if possible.
39
+ *
40
+ * @since 0.1.0
41
+ * @category commands
42
+ */
43
+ export declare const selectNodeBackward: Command;
44
+ /**
45
+ * If the selection is empty and the cursor is at the end of a
46
+ * textblock, try to reduce or remove the boundary between that block
47
+ * and the one after it.
48
+ *
49
+ * @since 0.1.0
50
+ * @category commands
51
+ */
52
+ export declare const joinForward: Command;
53
+ /**
54
+ * When the selection is empty and at the end of a textblock, select
55
+ * the node coming after that textblock, if possible.
56
+ *
57
+ * @since 0.1.0
58
+ * @category commands
59
+ */
60
+ export declare const selectNodeForward: Command;
61
+ /**
62
+ * Join the selected block or, if there is a text selection, the
63
+ * closest ancestor block of the selection that can be joined, with the
64
+ * sibling above it.
65
+ *
66
+ * @since 0.1.0
67
+ * @category commands
68
+ */
69
+ export declare const joinUp: Command;
70
+ /**
71
+ * Join the selected block, or the closest ancestor of the selection
72
+ * that can be joined, with the sibling after it.
73
+ *
74
+ * @since 0.1.0
75
+ * @category commands
76
+ */
77
+ export declare const joinDown: Command;
78
+ /**
79
+ * Lift the selected block, or the closest ancestor block of the
80
+ * selection that can be lifted, out of its parent node.
81
+ *
82
+ * @since 0.1.0
83
+ * @category commands
84
+ */
85
+ export declare const lift: Command;
86
+ /**
87
+ * If the selection is in a node whose type has a truthy `code`
88
+ * property in its spec, replace the selection with a newline
89
+ * character.
90
+ *
91
+ * @since 0.1.0
92
+ * @category commands
93
+ */
94
+ export declare const newlineInCode: Command;
95
+ /**
96
+ * When the selection is in a node with a truthy `code` property in its
97
+ * spec, create a default block after the code block, and move the
98
+ * cursor there.
99
+ *
100
+ * @since 0.1.0
101
+ * @category commands
102
+ */
103
+ export declare const exitCode: Command;
104
+ /**
105
+ * If a block node is selected, create an empty paragraph before (if it
106
+ * is its parent's first child) or after it.
107
+ *
108
+ * @since 0.1.0
109
+ * @category commands
110
+ */
111
+ export declare const createParagraphNear: Command;
112
+ /**
113
+ * If the cursor is in an empty textblock that can be lifted, lift the
114
+ * block.
115
+ *
116
+ * @since 0.1.0
117
+ * @category commands
118
+ */
119
+ export declare const liftEmptyBlock: Command;
120
+ /**
121
+ * Create a variant of `splitBlock` that uses a custom function to
122
+ * determine the type of the newly split off block.
123
+ *
124
+ * @since 0.1.0
125
+ * @category commands
126
+ */
127
+ export declare function splitBlockAs(splitNode?: (node: Node, atEnd: boolean, $from: ResolvedPos) => {
128
+ type: NodeType;
129
+ attrs?: Attrs;
130
+ } | null): Command;
131
+ /**
132
+ * Split the parent block of the selection.
133
+ *
134
+ * @since 0.1.0
135
+ * @category commands
136
+ */
137
+ export declare const splitBlock: Command;
138
+ /**
139
+ * Acts like `splitBlock`, but without resetting the set of active
140
+ * marks at the cursor.
141
+ *
142
+ * @since 0.1.0
143
+ * @category commands
144
+ */
145
+ export declare const splitBlockKeepMarks: Command;
146
+ /**
147
+ * Move the selection to the node wrapping the current selection, if
148
+ * any.
149
+ *
150
+ * @since 0.1.0
151
+ * @category commands
152
+ */
153
+ export declare const selectParentNode: Command;
154
+ /**
155
+ * Select the whole document.
156
+ *
157
+ * @since 0.1.0
158
+ * @category commands
159
+ */
160
+ export declare const selectAll: Command;
161
+ /**
162
+ * Moves the cursor to the start of current text block.
163
+ *
164
+ * @since 0.1.0
165
+ * @category commands
166
+ */
167
+ export declare const selectTextblockStart: Command;
168
+ /**
169
+ * Moves the cursor to the end of current text block.
170
+ *
171
+ * @since 0.1.0
172
+ * @category commands
173
+ */
174
+ export declare const selectTextblockEnd: Command;
175
+ /**
176
+ * Wrap the selection in a node of the given type with the given
177
+ * attributes.
178
+ *
179
+ * @since 0.1.0
180
+ * @category commands
181
+ */
182
+ export declare function wrapIn(nodeType: NodeType, attrs?: Attrs | null): Command;
183
+ /**
184
+ * Returns a command that tries to set the selected textblocks to the
185
+ * given node type with the given attributes.
186
+ *
187
+ * @since 0.1.0
188
+ * @category commands
189
+ */
190
+ export declare function setBlockType(nodeType: NodeType, attrs?: Attrs | null): Command;
191
+ /**
192
+ * Create a command function that toggles the given mark with the given
193
+ * attributes.
194
+ *
195
+ * @since 0.1.0
196
+ * @category commands
197
+ */
198
+ export declare function toggleMark(markType: MarkType, attrs?: Attrs | null, options?: {
199
+ removeWhenPresent?: boolean;
200
+ enterInlineAtoms?: boolean;
201
+ includeWhitespace?: boolean;
202
+ }): Command;
203
+ /**
204
+ * Wrap a command so that, when it produces a transform that causes two
205
+ * joinable nodes to end up next to each other, those are joined.
206
+ *
207
+ * @since 0.1.0
208
+ * @category commands
209
+ */
210
+ export declare function autoJoin(command: Command, isJoinable: ((before: Node, after: Node) => boolean) | ReadonlyArray<string>): Command;
211
+ /**
212
+ * Combine a number of command functions into a single function (which
213
+ * calls them one by one until one returns true).
214
+ *
215
+ * @since 0.1.0
216
+ * @category commands
217
+ */
218
+ export declare function chainCommands(...commands: ReadonlyArray<Command>): Command;
219
+ /**
220
+ * A basic keymap containing bindings not specific to any schema.
221
+ *
222
+ * @since 0.1.0
223
+ * @category keymaps
224
+ */
225
+ export declare const pcBaseKeymap: {
226
+ [key: string]: Command;
227
+ };
228
+ /**
229
+ * A copy of `pcBaseKeymap` that also binds **Ctrl-h** like Backspace,
230
+ * **Ctrl-d** like Delete, **Alt-Backspace** like Ctrl-Backspace, and
231
+ * **Ctrl-Alt-Backspace**, **Alt-Delete**, and **Alt-d** like
232
+ * Ctrl-Delete.
233
+ *
234
+ * @since 0.1.0
235
+ * @category keymaps
236
+ */
237
+ export declare const macBaseKeymap: {
238
+ [key: string]: Command;
239
+ };
240
+ /**
241
+ * Depending on the detected platform, this will hold `pcBasekeymap` or
242
+ * `macBaseKeymap`.
243
+ *
244
+ * @since 0.1.0
245
+ * @category keymaps
246
+ */
247
+ export declare const baseKeymap: {
248
+ [key: string]: Command;
249
+ };
250
+ export { fromCoreCommand, toCoreCommand };
@@ -0,0 +1,275 @@
1
+ import { autoJoin as autoJoin$1, createParagraphNear as createParagraphNear$1, deleteSelection as deleteSelection$1, exitCode as exitCode$1, joinBackward as joinBackward$1, joinDown as joinDown$1, joinForward as joinForward$1, joinTextblockBackward as joinTextblockBackward$1, joinTextblockForward as joinTextblockForward$1, joinUp as joinUp$1, lift as lift$1, liftEmptyBlock as liftEmptyBlock$1, newlineInCode as newlineInCode$1, selectAll as selectAll$1, selectNodeBackward as selectNodeBackward$1, selectNodeForward as selectNodeForward$1, selectParentNode as selectParentNode$1, selectTextblockEnd as selectTextblockEnd$1, selectTextblockStart as selectTextblockStart$1, setBlockType as setBlockType$1, splitBlock as splitBlock$1, splitBlockAs as splitBlockAs$1, splitBlockKeepMarks as splitBlockKeepMarks$1, toggleMark as toggleMark$1, wrapIn as wrapIn$1 } from "../commands/commands.js";
2
+ import { baseKeymap as baseKeymap$1, macBaseKeymap as macBaseKeymap$1, pcBaseKeymap as pcBaseKeymap$1 } from "../commands/keymaps.js";
3
+ import { CORE, wrap } from "./internal/core.js";
4
+ import { fromCoreCommand, toCoreCommand } from "./state.js";
5
+ // src/compat/commands.ts
6
+ /**
7
+ * A `prosemirror-commands`-compatible module: the core editing commands
8
+ * (`@thomasfosterau/effect-richtext/commands`), bridged to ProseMirror-style
9
+ * `(state, dispatch?, view?) => boolean` commands.
10
+ *
11
+ * Ported API surface from prosemirror-commands (MIT, Marijn Haverbeke and others).
12
+ *
13
+ * @since 0.1.0
14
+ */
15
+ /**
16
+ * Delete the selection, if there is one.
17
+ *
18
+ * @since 0.1.0
19
+ * @category commands
20
+ */
21
+ const deleteSelection = fromCoreCommand(deleteSelection$1);
22
+ /**
23
+ * If the selection is empty and at the start of a textblock, try to
24
+ * reduce the distance between that block and the one before it.
25
+ *
26
+ * @since 0.1.0
27
+ * @category commands
28
+ */
29
+ const joinBackward = fromCoreCommand(joinBackward$1);
30
+ /**
31
+ * A more limited form of `joinBackward` that only tries to join the
32
+ * current textblock to the one before it, if the cursor is at the
33
+ * start of a textblock.
34
+ *
35
+ * @since 0.1.0
36
+ * @category commands
37
+ */
38
+ const joinTextblockBackward = fromCoreCommand(joinTextblockBackward$1);
39
+ /**
40
+ * A more limited form of `joinForward` that only tries to join the
41
+ * current textblock to the one after it, if the cursor is at the end
42
+ * of a textblock.
43
+ *
44
+ * @since 0.1.0
45
+ * @category commands
46
+ */
47
+ const joinTextblockForward = fromCoreCommand(joinTextblockForward$1);
48
+ /**
49
+ * When the selection is empty and at the start of a textblock, select
50
+ * the node before that textblock, if possible.
51
+ *
52
+ * @since 0.1.0
53
+ * @category commands
54
+ */
55
+ const selectNodeBackward = fromCoreCommand(selectNodeBackward$1);
56
+ /**
57
+ * If the selection is empty and the cursor is at the end of a
58
+ * textblock, try to reduce or remove the boundary between that block
59
+ * and the one after it.
60
+ *
61
+ * @since 0.1.0
62
+ * @category commands
63
+ */
64
+ const joinForward = fromCoreCommand(joinForward$1);
65
+ /**
66
+ * When the selection is empty and at the end of a textblock, select
67
+ * the node coming after that textblock, if possible.
68
+ *
69
+ * @since 0.1.0
70
+ * @category commands
71
+ */
72
+ const selectNodeForward = fromCoreCommand(selectNodeForward$1);
73
+ /**
74
+ * Join the selected block or, if there is a text selection, the
75
+ * closest ancestor block of the selection that can be joined, with the
76
+ * sibling above it.
77
+ *
78
+ * @since 0.1.0
79
+ * @category commands
80
+ */
81
+ const joinUp = fromCoreCommand(joinUp$1);
82
+ /**
83
+ * Join the selected block, or the closest ancestor of the selection
84
+ * that can be joined, with the sibling after it.
85
+ *
86
+ * @since 0.1.0
87
+ * @category commands
88
+ */
89
+ const joinDown = fromCoreCommand(joinDown$1);
90
+ /**
91
+ * Lift the selected block, or the closest ancestor block of the
92
+ * selection that can be lifted, out of its parent node.
93
+ *
94
+ * @since 0.1.0
95
+ * @category commands
96
+ */
97
+ const lift = fromCoreCommand(lift$1);
98
+ /**
99
+ * If the selection is in a node whose type has a truthy `code`
100
+ * property in its spec, replace the selection with a newline
101
+ * character.
102
+ *
103
+ * @since 0.1.0
104
+ * @category commands
105
+ */
106
+ const newlineInCode = fromCoreCommand(newlineInCode$1);
107
+ /**
108
+ * When the selection is in a node with a truthy `code` property in its
109
+ * spec, create a default block after the code block, and move the
110
+ * cursor there.
111
+ *
112
+ * @since 0.1.0
113
+ * @category commands
114
+ */
115
+ const exitCode = fromCoreCommand(exitCode$1);
116
+ /**
117
+ * If a block node is selected, create an empty paragraph before (if it
118
+ * is its parent's first child) or after it.
119
+ *
120
+ * @since 0.1.0
121
+ * @category commands
122
+ */
123
+ const createParagraphNear = fromCoreCommand(createParagraphNear$1);
124
+ /**
125
+ * If the cursor is in an empty textblock that can be lifted, lift the
126
+ * block.
127
+ *
128
+ * @since 0.1.0
129
+ * @category commands
130
+ */
131
+ const liftEmptyBlock = fromCoreCommand(liftEmptyBlock$1);
132
+ /**
133
+ * Create a variant of `splitBlock` that uses a custom function to
134
+ * determine the type of the newly split off block.
135
+ *
136
+ * @since 0.1.0
137
+ * @category commands
138
+ */
139
+ function splitBlockAs(splitNode) {
140
+ return fromCoreCommand(splitBlockAs$1(splitNode && ((node, atEnd, $from) => {
141
+ const result = splitNode(wrap(node), atEnd, wrap($from));
142
+ return result && {
143
+ type: result.type[CORE],
144
+ attrs: result.attrs ?? null
145
+ };
146
+ })));
147
+ }
148
+ /**
149
+ * Split the parent block of the selection.
150
+ *
151
+ * @since 0.1.0
152
+ * @category commands
153
+ */
154
+ const splitBlock = fromCoreCommand(splitBlock$1);
155
+ /**
156
+ * Acts like `splitBlock`, but without resetting the set of active
157
+ * marks at the cursor.
158
+ *
159
+ * @since 0.1.0
160
+ * @category commands
161
+ */
162
+ const splitBlockKeepMarks = fromCoreCommand(splitBlockKeepMarks$1);
163
+ /**
164
+ * Move the selection to the node wrapping the current selection, if
165
+ * any.
166
+ *
167
+ * @since 0.1.0
168
+ * @category commands
169
+ */
170
+ const selectParentNode = fromCoreCommand(selectParentNode$1);
171
+ /**
172
+ * Select the whole document.
173
+ *
174
+ * @since 0.1.0
175
+ * @category commands
176
+ */
177
+ const selectAll = fromCoreCommand(selectAll$1);
178
+ /**
179
+ * Moves the cursor to the start of current text block.
180
+ *
181
+ * @since 0.1.0
182
+ * @category commands
183
+ */
184
+ const selectTextblockStart = fromCoreCommand(selectTextblockStart$1);
185
+ /**
186
+ * Moves the cursor to the end of current text block.
187
+ *
188
+ * @since 0.1.0
189
+ * @category commands
190
+ */
191
+ const selectTextblockEnd = fromCoreCommand(selectTextblockEnd$1);
192
+ /**
193
+ * Wrap the selection in a node of the given type with the given
194
+ * attributes.
195
+ *
196
+ * @since 0.1.0
197
+ * @category commands
198
+ */
199
+ function wrapIn(nodeType, attrs = null) {
200
+ return fromCoreCommand(wrapIn$1(nodeType[CORE], attrs));
201
+ }
202
+ /**
203
+ * Returns a command that tries to set the selected textblocks to the
204
+ * given node type with the given attributes.
205
+ *
206
+ * @since 0.1.0
207
+ * @category commands
208
+ */
209
+ function setBlockType(nodeType, attrs = null) {
210
+ return fromCoreCommand(setBlockType$1(nodeType[CORE], attrs));
211
+ }
212
+ /**
213
+ * Create a command function that toggles the given mark with the given
214
+ * attributes.
215
+ *
216
+ * @since 0.1.0
217
+ * @category commands
218
+ */
219
+ function toggleMark(markType, attrs = null, options) {
220
+ return fromCoreCommand(toggleMark$1(markType[CORE], attrs ?? void 0, options));
221
+ }
222
+ /**
223
+ * Wrap a command so that, when it produces a transform that causes two
224
+ * joinable nodes to end up next to each other, those are joined.
225
+ *
226
+ * @since 0.1.0
227
+ * @category commands
228
+ */
229
+ function autoJoin(command, isJoinable) {
230
+ return fromCoreCommand(autoJoin$1(toCoreCommand(command), typeof isJoinable === "function" ? (a, b) => isJoinable(wrap(a), wrap(b)) : isJoinable));
231
+ }
232
+ /**
233
+ * Combine a number of command functions into a single function (which
234
+ * calls them one by one until one returns true).
235
+ *
236
+ * @since 0.1.0
237
+ * @category commands
238
+ */
239
+ function chainCommands(...commands) {
240
+ return function(state, dispatch, view) {
241
+ for (let i = 0; i < commands.length; i++) if (commands[i](state, dispatch, view)) return true;
242
+ return false;
243
+ };
244
+ }
245
+ const fromCoreKeymap = (map) => {
246
+ const result = {};
247
+ for (const key in map) result[key] = fromCoreCommand(map[key]);
248
+ return result;
249
+ };
250
+ /**
251
+ * A basic keymap containing bindings not specific to any schema.
252
+ *
253
+ * @since 0.1.0
254
+ * @category keymaps
255
+ */
256
+ const pcBaseKeymap = fromCoreKeymap(pcBaseKeymap$1);
257
+ /**
258
+ * A copy of `pcBaseKeymap` that also binds **Ctrl-h** like Backspace,
259
+ * **Ctrl-d** like Delete, **Alt-Backspace** like Ctrl-Backspace, and
260
+ * **Ctrl-Alt-Backspace**, **Alt-Delete**, and **Alt-d** like
261
+ * Ctrl-Delete.
262
+ *
263
+ * @since 0.1.0
264
+ * @category keymaps
265
+ */
266
+ const macBaseKeymap = fromCoreKeymap(macBaseKeymap$1);
267
+ /**
268
+ * Depending on the detected platform, this will hold `pcBasekeymap` or
269
+ * `macBaseKeymap`.
270
+ *
271
+ * @since 0.1.0
272
+ * @category keymaps
273
+ */
274
+ const baseKeymap = baseKeymap$1 === macBaseKeymap$1 ? macBaseKeymap : pcBaseKeymap;
275
+ export { autoJoin, baseKeymap, chainCommands, createParagraphNear, deleteSelection, exitCode, fromCoreCommand, joinBackward, joinDown, joinForward, joinTextblockBackward, joinTextblockForward, joinUp, lift, liftEmptyBlock, macBaseKeymap, newlineInCode, pcBaseKeymap, selectAll, selectNodeBackward, selectNodeForward, selectParentNode, selectTextblockEnd, selectTextblockStart, setBlockType, splitBlock, splitBlockAs, splitBlockKeepMarks, toCoreCommand, toggleMark, wrapIn };