@thomasfosterau/effect-richtext 0.0.0-stage → 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 +118 -2
  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 +206 -3
@@ -0,0 +1,236 @@
1
+ import { TagParseRule } from "../model/from_dom.js";
2
+ import { AnySchema, MarkNames, NodeNames } from "../model/schema.js";
3
+ import { Mark } from "../model/mark.js";
4
+ import { Node } from "../model/node.js";
5
+ import "../model.js";
6
+ import { Decoration, DecorationSource } from "./decoration.js";
7
+ import { DOMNode } from "./dom.js";
8
+ import { EditorView } from "./view.js";
9
+ type AnyView = EditorView<any, any, any>;
10
+ /**
11
+ * A `ViewMutationRecord` represents a DOM mutation or a selection
12
+ * change happens within the view. When the change is a selection
13
+ * change, the record will have a `type` property of `"selection"`
14
+ * (which doesn't occur for native mutation records).
15
+ *
16
+ * @since 0.1.0
17
+ * @category models
18
+ */
19
+ export type ViewMutationRecord = MutationRecord | {
20
+ readonly type: "selection";
21
+ readonly target: DOMNode;
22
+ };
23
+ /**
24
+ * By default, document nodes are rendered using the result of the
25
+ * `toDOM` method of their spec, and managed entirely by the editor. For
26
+ * some use cases, such as embedded node-specific editing interfaces,
27
+ * you want more control over the behavior of a node's in-editor
28
+ * representation, and need to define a custom node view.
29
+ *
30
+ * Objects returned as node views must conform to this interface. Node
31
+ * views are plain, synchronous objects.
32
+ *
33
+ * @since 0.1.0
34
+ * @category models
35
+ */
36
+ export interface NodeView<Sc extends AnySchema = AnySchema> {
37
+ /** The outer DOM node that represents the document node. */
38
+ dom: DOMNode;
39
+ /**
40
+ * The DOM node that should hold the node's content. Only meaningful if
41
+ * the node view also defines a `dom` property and if its node type is
42
+ * not a leaf node type. When this is present, the view will take care
43
+ * of rendering the node's children into it. When it is not present,
44
+ * the node view itself is responsible for rendering (or deciding not
45
+ * to render) its child nodes.
46
+ */
47
+ contentDOM?: HTMLElement | null | undefined;
48
+ /**
49
+ * When given, this will be called when the view is updating itself.
50
+ * It will be given a node, an array of active decorations around the
51
+ * node (which are automatically drawn, and the node view may ignore if
52
+ * it isn't interested in them), and a decoration source that
53
+ * represents any decorations that apply to the content of the node
54
+ * (which again may be ignored). It should return true if it was able
55
+ * to update to that node, and false otherwise. If the node view has a
56
+ * `contentDOM` property (or no `dom` property), updating its child
57
+ * nodes will be handled by the view.
58
+ */
59
+ update?: ((node: Node<Sc>, decorations: ReadonlyArray<Decoration>, innerDecorations: DecorationSource) => boolean) | undefined;
60
+ /**
61
+ * By default, `update` will only be called when a node of the same
62
+ * node type appears in this view's position. When you set this to
63
+ * true, it will be called for any node, making it possible to have a
64
+ * node view that represents multiple types of nodes. You will need to
65
+ * check the type of the nodes you get in `update` and return `false`
66
+ * for types you cannot handle.
67
+ */
68
+ multiType?: boolean | undefined;
69
+ /**
70
+ * Can be used to override the way the node's selected status (as a
71
+ * node selection) is displayed.
72
+ */
73
+ selectNode?: (() => void) | undefined;
74
+ /**
75
+ * When defining a `selectNode` method, you should also provide a
76
+ * `deselectNode` method to remove the effect again.
77
+ */
78
+ deselectNode?: (() => void) | undefined;
79
+ /**
80
+ * This will be called to handle setting the selection inside the
81
+ * node. The `anchor` and `head` positions are relative to the start of
82
+ * the node. By default, a DOM selection will be created between the
83
+ * DOM positions corresponding to those positions, but if you override
84
+ * it you can do something else.
85
+ */
86
+ setSelection?: ((anchor: number, head: number, root: Document | ShadowRoot) => void) | undefined;
87
+ /**
88
+ * Can be used to prevent the editor view from trying to handle some
89
+ * or all DOM events that bubble up from the node view. Events for
90
+ * which this returns true are not handled by the editor.
91
+ */
92
+ stopEvent?: ((event: Event) => boolean) | undefined;
93
+ /**
94
+ * Called when a mutation happens within the view. Return false if the
95
+ * editor should re-read the selection or re-parse the range around
96
+ * the mutation, true if it can safely be ignored.
97
+ */
98
+ ignoreMutation?: ((mutation: ViewMutationRecord) => boolean) | undefined;
99
+ /** Called when the node view is removed from the editor or the whole editor is destroyed. */
100
+ destroy?: (() => void) | undefined;
101
+ }
102
+ /**
103
+ * By default, document marks are rendered using the result of the
104
+ * `toDOM` method of their spec, and managed entirely by the editor. For
105
+ * some use cases, you want more control over the behavior of a mark's
106
+ * in-editor representation, and need to define a custom mark view.
107
+ *
108
+ * Objects returned as mark views must conform to this interface.
109
+ *
110
+ * @since 0.1.0
111
+ * @category models
112
+ */
113
+ export interface MarkView {
114
+ /** The outer DOM node that represents the document node. */
115
+ dom: HTMLElement;
116
+ /**
117
+ * The DOM node that should hold the mark's content. When this is not
118
+ * present, the `dom` property is used as the content DOM.
119
+ */
120
+ contentDOM?: HTMLElement | null | undefined;
121
+ /**
122
+ * Called when the mark at this position changes to another mark of the
123
+ * same type. Return true to keep this view (it now represents `mark`),
124
+ * false to have it redrawn.
125
+ */
126
+ update?: ((mark: Mark<any, any>) => boolean) | undefined;
127
+ /**
128
+ * Called when a mutation happens within the view. Return false if the
129
+ * editor should re-read the selection or re-parse the range around
130
+ * the mutation, true if it can safely be ignored.
131
+ */
132
+ ignoreMutation?: ((mutation: ViewMutationRecord) => boolean) | undefined;
133
+ /** Called when the mark view is removed from the editor or the whole editor is destroyed. */
134
+ destroy?: (() => void) | undefined;
135
+ }
136
+ /**
137
+ * The type of function provided to create node views for nodes named
138
+ * `N`. `getPos` returns the node's current position, or `undefined`
139
+ * when the node is not in the document.
140
+ *
141
+ * @since 0.1.0
142
+ * @category models
143
+ */
144
+ export type NodeViewConstructor<Sc extends AnySchema = AnySchema, N extends NodeNames<Sc> = NodeNames<Sc>> = (node: Node<Sc, N>, view: EditorView<Sc, any, any>, getPos: () => number | undefined, decorations: ReadonlyArray<Decoration>, innerDecorations: DecorationSource) => NodeView<Sc>;
145
+ /**
146
+ * The function type used to create mark views for marks named `M`.
147
+ *
148
+ * @since 0.1.0
149
+ * @category models
150
+ */
151
+ export type MarkViewConstructor<Sc extends AnySchema = AnySchema, M extends MarkNames<Sc> = MarkNames<Sc>> = (mark: Mark<Sc, M>, view: EditorView<Sc, any, any>, inline: boolean) => MarkView;
152
+ type ParseRuleLike = Omit<TagParseRule, "tag">;
153
+ /** @internal */
154
+ export declare class ViewDesc {
155
+ parent: ViewDesc | undefined;
156
+ children: Array<ViewDesc>;
157
+ dom: DOMNode;
158
+ contentDOM: HTMLElement | null;
159
+ dirty: number;
160
+ node: Node<any, any> | null;
161
+ constructor(parent: ViewDesc | undefined, children: Array<ViewDesc>, dom: DOMNode, contentDOM: HTMLElement | null);
162
+ matchesWidget(_widget: Decoration): boolean;
163
+ matchesMark(_mark: Mark<any, any>): boolean;
164
+ matchesNode(_node: Node<any, any>, _outerDeco: ReadonlyArray<Decoration>, _innerDeco: DecorationSource): boolean;
165
+ matchesHack(_nodeName: string): boolean;
166
+ parseRule(_addedNodes?: ReadonlyArray<DOMNode>): ParseRuleLike | null;
167
+ stopEvent(_event: Event): boolean;
168
+ get size(): number;
169
+ get border(): number;
170
+ destroy(): void;
171
+ posBeforeChild(child: ViewDesc): number;
172
+ get posBefore(): number;
173
+ get posAtStart(): number;
174
+ get posAfter(): number;
175
+ get posAtEnd(): number;
176
+ localPosFromDOM(dom: DOMNode, offset: number, bias: number): number;
177
+ nearestDesc(dom: DOMNode): ViewDesc | undefined;
178
+ nearestDesc(dom: DOMNode, onlyNodes: true): NodeViewDesc | undefined;
179
+ getDesc(dom: DOMNode): ViewDesc | undefined;
180
+ posFromDOM(dom: DOMNode, offset: number, bias: number): number;
181
+ descAt(pos: number): ViewDesc | undefined;
182
+ domFromPos(pos: number, side: number): {
183
+ node: DOMNode;
184
+ offset: number;
185
+ atom?: number | undefined;
186
+ };
187
+ parseRange(from: number, to: number, base?: number): {
188
+ node: DOMNode;
189
+ from: number;
190
+ to: number;
191
+ fromOffset: number;
192
+ toOffset: number;
193
+ };
194
+ emptyChildAt(side: number): boolean;
195
+ domAfterPos(pos: number): DOMNode;
196
+ setSelection(anchor: number, head: number, view: AnyView, force?: boolean): void;
197
+ ignoreMutation(mutation: ViewMutationRecord): boolean;
198
+ get contentLost(): boolean;
199
+ markDirty(from: number, to: number): void;
200
+ markParentsDirty(): void;
201
+ get domAtom(): boolean;
202
+ get ignoreForCoords(): boolean;
203
+ get ignoreForSelection(): boolean;
204
+ isText(_text: string): boolean;
205
+ }
206
+ /** @internal */
207
+ export declare class NodeViewDesc extends ViewDesc {
208
+ node: Node<any, any>;
209
+ outerDeco: ReadonlyArray<Decoration>;
210
+ innerDeco: DecorationSource;
211
+ readonly nodeDOM: DOMNode;
212
+ constructor(parent: ViewDesc | undefined, node: Node<any, any>, outerDeco: ReadonlyArray<Decoration>, innerDeco: DecorationSource, dom: DOMNode, contentDOM: HTMLElement | null, nodeDOM: DOMNode, _view: AnyView, _pos: number);
213
+ static create(parent: ViewDesc | undefined, node: Node<any, any>, outerDeco: ReadonlyArray<Decoration>, innerDeco: DecorationSource, view: AnyView, pos: number): NodeViewDesc;
214
+ parseRule(addedNodes?: ReadonlyArray<DOMNode>): ParseRuleLike | null;
215
+ matchesNode(node: Node<any, any>, outerDeco: ReadonlyArray<Decoration>, innerDeco: DecorationSource): boolean;
216
+ get size(): number;
217
+ get border(): 0 | 1;
218
+ updateChildren(view: AnyView, pos: number): void;
219
+ localCompositionInfo(view: AnyView, pos: number): {
220
+ node: Text;
221
+ pos: number;
222
+ text: string;
223
+ } | null;
224
+ protectLocalComposition(view: AnyView, { node, pos, text }: {
225
+ node: Text;
226
+ pos: number;
227
+ text: string;
228
+ }): void;
229
+ update(node: Node<any, any>, outerDeco: ReadonlyArray<Decoration>, innerDeco: DecorationSource, view: AnyView): boolean;
230
+ updateInner(node: Node<any, any>, outerDeco: ReadonlyArray<Decoration>, innerDeco: DecorationSource, view: AnyView): void;
231
+ updateOuterDeco(outerDeco: ReadonlyArray<Decoration>): void;
232
+ selectNode(): void;
233
+ deselectNode(): void;
234
+ get domAtom(): boolean;
235
+ }
236
+ export {};