@stesura/wordgard-view 0.0.0-stage → 0.4.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.
- package/CHANGELOG.md +7 -0
- package/LICENSE.txt +21 -0
- package/README.md +19 -2
- package/THIRD_PARTY_LICENSES.txt +89 -0
- package/dist/index.d.ts +411 -0
- package/dist/index.js +2891 -0
- package/package.json +47 -4
package/CHANGELOG.md
ADDED
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Edoardo Caratti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @stesura/wordgard-view
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The core of [react-wordgard](https://www.npmjs.com/package/@stesura/react-wordgard) and
|
|
4
|
+
[vue-wordgard](https://www.npmjs.com/package/@stesura/vue-wordgard): the part of their view over
|
|
5
|
+
[Wordgard](https://www.wordgard.net) that doesn't depend on a framework. It lays out the document,
|
|
6
|
+
builds Wordgard's tiles over the DOM a framework draws, and registers the decorations components
|
|
7
|
+
draw.
|
|
8
|
+
|
|
9
|
+
**Not for apps.** Install react-wordgard or vue-wordgard, which bring it at their own version. Its
|
|
10
|
+
API is what the views need and changes with them; they're released together.
|
|
11
|
+
|
|
12
|
+
How it works: [docs/how-it-works.md](https://github.com/stesura/react-wordgard/blob/master/docs/how-it-works.md).
|
|
13
|
+
|
|
14
|
+
## Licence
|
|
15
|
+
|
|
16
|
+
MIT, © 2026 Edoardo Caratti, see [LICENSE.txt](LICENSE.txt).
|
|
17
|
+
|
|
18
|
+
Includes code from react-prosemirror (© Handle with Care Collective and The New York Times
|
|
19
|
+
Company) and Wordgard (© Marijn Haverbeke); their notices are in
|
|
20
|
+
[THIRD_PARTY_LICENSES.txt](THIRD_PARTY_LICENSES.txt).
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
@stesura/wordgard-view, the core of react-wordgard and vue-wordgard, includes code
|
|
2
|
+
from the projects below. Their copyright and license notices are reproduced
|
|
3
|
+
here, as their licenses require.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
================================================================================
|
|
7
|
+
react-prosemirror
|
|
8
|
+
https://github.com/handlewithcarecollective/react-prosemirror
|
|
9
|
+
================================================================================
|
|
10
|
+
|
|
11
|
+
The core is derived from react-prosemirror, maintained by Handle with Care
|
|
12
|
+
Collective and originally created at The New York Times Company, through
|
|
13
|
+
react-wordgard.
|
|
14
|
+
|
|
15
|
+
react-prosemirror was released under the Apache License 2.0 until 2026-10-02
|
|
16
|
+
(commit 1827d3a) and under the MIT License since then. Both notices follow.
|
|
17
|
+
|
|
18
|
+
--- MIT License (since 2026-10-02) ---------------------------------------------
|
|
19
|
+
|
|
20
|
+
MIT License
|
|
21
|
+
|
|
22
|
+
Copyright (c) 2026 Handle with Care Collective
|
|
23
|
+
|
|
24
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
25
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
26
|
+
in the Software without restriction, including without limitation the rights
|
|
27
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
28
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
29
|
+
furnished to do so, subject to the following conditions:
|
|
30
|
+
|
|
31
|
+
The above copyright notice and this permission notice shall be included in all
|
|
32
|
+
copies or substantial portions of the Software.
|
|
33
|
+
|
|
34
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
35
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
36
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
37
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
38
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
39
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
40
|
+
SOFTWARE.
|
|
41
|
+
|
|
42
|
+
--- Apache License 2.0 (until 2026-10-02) --------------------------------------
|
|
43
|
+
|
|
44
|
+
Copyright (c) 2022 The New York Times Company
|
|
45
|
+
Copyright (c) 2025 Handle with Care Collective
|
|
46
|
+
|
|
47
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
48
|
+
this library except in compliance with the License. You may obtain a copy of the
|
|
49
|
+
License at
|
|
50
|
+
|
|
51
|
+
www.apache.org/licenses/LICENSE-2.0
|
|
52
|
+
|
|
53
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
54
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
55
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
56
|
+
specific language governing permissions and limitations under the License.
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
================================================================================
|
|
60
|
+
Wordgard
|
|
61
|
+
https://wordgard.net
|
|
62
|
+
================================================================================
|
|
63
|
+
|
|
64
|
+
dist/index.js includes a copy of Wordgard's decoration walker
|
|
65
|
+
(src/editor/decoration.ts in its repository), with changes, and of
|
|
66
|
+
`setUneditable` from its tile tree (src/editor/tile.ts).
|
|
67
|
+
|
|
68
|
+
MIT License
|
|
69
|
+
|
|
70
|
+
Copyright (C) 2026 by Marijn Haverbeke <marijn@haverbeke.berlin>.
|
|
71
|
+
|
|
72
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
73
|
+
a copy of this software and associated documentation files (the
|
|
74
|
+
"Software"), to deal in the Software without restriction, including
|
|
75
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
76
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
77
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
78
|
+
the following conditions:
|
|
79
|
+
|
|
80
|
+
The above copyright notice and this permission notice shall be
|
|
81
|
+
included in all copies or substantial portions of the Software.
|
|
82
|
+
|
|
83
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
84
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
85
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
86
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
87
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
88
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
89
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import { Wordgard, Decoration, Widget } from 'wordgard/editor';
|
|
2
|
+
import * as wordgard_doc from 'wordgard/doc';
|
|
3
|
+
import { Elt, Mark, Node as Node$1, Plot, Attributes } from 'wordgard/doc';
|
|
4
|
+
import { GardState } from 'wordgard/state';
|
|
5
|
+
|
|
6
|
+
declare const editorEvents: readonly ["keydown", "keyup", "keypress", "beforeinput", "input", "mousedown", "mouseup", "mouseover", "mouseout", "click", "dblclick", "contextmenu", "focus", "blur", "copy", "cut", "paste", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "drop", "compositionstart", "compositionupdate", "compositionend"];
|
|
7
|
+
type EditorEvent = (typeof editorEvents)[number];
|
|
8
|
+
type Listener<Type extends EditorEvent> = (event: HTMLElementEventMap[Type]) => boolean | void;
|
|
9
|
+
type Listeners = {
|
|
10
|
+
[Type in EditorEvent]: Listener<Type>[];
|
|
11
|
+
};
|
|
12
|
+
declare const listenersOf: <Type extends EditorEvent>(wg: Wordgard, type: Type) => Listeners[Type];
|
|
13
|
+
|
|
14
|
+
type DecorationHandlers = {
|
|
15
|
+
readonly getPos: () => number;
|
|
16
|
+
readonly stopEvent: Set<(event: Event) => boolean>;
|
|
17
|
+
readonly ignoreMutation: Set<(record: MutationRecord) => boolean>;
|
|
18
|
+
};
|
|
19
|
+
declare const createDecorationHandlers: (getPos: () => number) => DecorationHandlers;
|
|
20
|
+
declare const decorationRoot: (handlers: DecorationHandlers) => (dom: Element | null) => void;
|
|
21
|
+
|
|
22
|
+
type Tile = NonNullable<Node["wgTile"]>;
|
|
23
|
+
type CompositeTile = NonNullable<Tile["parent"]>;
|
|
24
|
+
type DecoSet = {
|
|
25
|
+
readonly points: Map<(state: GardState) => Decoration.Point.Set, Decoration.Point.Set>;
|
|
26
|
+
readonly ranges: Map<(state: GardState) => Decoration.Range.Set, Decoration.Range.Set>;
|
|
27
|
+
};
|
|
28
|
+
interface CompositionInfo {
|
|
29
|
+
readonly fromB: number;
|
|
30
|
+
readonly toB: number;
|
|
31
|
+
readonly text: string;
|
|
32
|
+
readonly target: Text | null;
|
|
33
|
+
readonly wrapCursor?: Mark.Set | null;
|
|
34
|
+
}
|
|
35
|
+
interface DOMObserver {
|
|
36
|
+
ignore<T>(f: () => T): T;
|
|
37
|
+
observer: MutationObserver;
|
|
38
|
+
queue: MutationRecord[];
|
|
39
|
+
}
|
|
40
|
+
interface DocTileClass {
|
|
41
|
+
new (state: GardState, dom: Element, cursorWrapper: Mark.Set | null, decoSet: DecoSet): DocTile;
|
|
42
|
+
create(state: GardState, dom: Element, wg: Wordgard): DocTile;
|
|
43
|
+
}
|
|
44
|
+
declare const TileFlag: {
|
|
45
|
+
readonly NodeInner: 1;
|
|
46
|
+
readonly PlotContent: 2;
|
|
47
|
+
readonly Spanning: 4;
|
|
48
|
+
readonly Wrapper: 8;
|
|
49
|
+
readonly Point: 16;
|
|
50
|
+
readonly PointBefore: 32;
|
|
51
|
+
readonly PointAfter: 64;
|
|
52
|
+
readonly Composition: 128;
|
|
53
|
+
readonly Synced: 256;
|
|
54
|
+
readonly Atom: 512;
|
|
55
|
+
readonly Uneditable: 1024;
|
|
56
|
+
readonly HasContent: 2048;
|
|
57
|
+
readonly AfterContent: 4096;
|
|
58
|
+
readonly ContentNotLast: 8192;
|
|
59
|
+
readonly Dirty: 16384;
|
|
60
|
+
};
|
|
61
|
+
interface NodeShape<Param> {
|
|
62
|
+
readonly atom: boolean;
|
|
63
|
+
create(param: Param): Elt;
|
|
64
|
+
}
|
|
65
|
+
interface EltSelector {
|
|
66
|
+
match(elt: Elt): boolean;
|
|
67
|
+
}
|
|
68
|
+
declare module "wordgard/doc" {
|
|
69
|
+
namespace Plot {
|
|
70
|
+
interface Type<Param = unknown> {
|
|
71
|
+
readonly shape: NodeShape<Param>;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
namespace Leaf {
|
|
75
|
+
interface Type<Param = unknown> {
|
|
76
|
+
readonly shape: NodeShape<Param>;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
namespace Mark {
|
|
80
|
+
interface Type<Param = unknown> {
|
|
81
|
+
readonly rank: number;
|
|
82
|
+
readonly element: {
|
|
83
|
+
readonly name: string;
|
|
84
|
+
attrs(value: Param): Attributes;
|
|
85
|
+
} | null;
|
|
86
|
+
readonly attribute: {
|
|
87
|
+
get(value: Param): Attributes;
|
|
88
|
+
readonly target: EltSelector | null;
|
|
89
|
+
} | null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
interface Elt<T = string> {
|
|
93
|
+
addAttrs(attrs: Attributes, target?: EltSelector): Elt<T>;
|
|
94
|
+
wrap(wrapper: Elt<T>, target?: EltSelector): Elt<T>;
|
|
95
|
+
fill(content: readonly (0 | T | Elt<T>)[]): Elt<T>;
|
|
96
|
+
}
|
|
97
|
+
namespace Attributes {
|
|
98
|
+
function push(attrs: string[], name: string, value: string): void;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
declare module "wordgard/editor" {
|
|
102
|
+
interface Widget<Param = unknown> {
|
|
103
|
+
readonly hasContent: boolean;
|
|
104
|
+
render(wg: Wordgard): Element | Text;
|
|
105
|
+
}
|
|
106
|
+
namespace Wordgard {
|
|
107
|
+
const DocTile: DocTileClass;
|
|
108
|
+
}
|
|
109
|
+
namespace Widget {
|
|
110
|
+
interface Type<Param> {
|
|
111
|
+
readonly inFlow: boolean;
|
|
112
|
+
readonly editable: boolean;
|
|
113
|
+
}
|
|
114
|
+
const br: Widget<null>;
|
|
115
|
+
const img: Widget<null>;
|
|
116
|
+
const blockImg: Widget<null>;
|
|
117
|
+
const text: Widget.Type<string>;
|
|
118
|
+
const editableText: Widget.Type<string>;
|
|
119
|
+
}
|
|
120
|
+
namespace Decoration {
|
|
121
|
+
interface Range {
|
|
122
|
+
readonly query: Node$1.Query | null;
|
|
123
|
+
readonly scope: number;
|
|
124
|
+
readonly inc: number;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
interface DocTile extends CompositeTile {
|
|
129
|
+
readonly state: GardState;
|
|
130
|
+
readonly cursorWrapper: Mark.Set | null;
|
|
131
|
+
readonly decoSet: DecoSet;
|
|
132
|
+
update(state: GardState, changes: readonly number[], wg: Wordgard, composition?: CompositionInfo | null): DocTile;
|
|
133
|
+
updateRanges(state: GardState, decoSet: DecoSet, changes: readonly number[], wg: Wordgard, composition?: CompositionInfo | null): DocTile;
|
|
134
|
+
resolve(pos: number, side?: -1 | 1): {
|
|
135
|
+
tile: Tile;
|
|
136
|
+
offset: number;
|
|
137
|
+
pos: number;
|
|
138
|
+
};
|
|
139
|
+
nodeTile(pos: number): Tile | null;
|
|
140
|
+
nearest(dom: Node): Tile | null;
|
|
141
|
+
posFromDOM(dom: Node, offset: number, bias?: -1 | 1): number;
|
|
142
|
+
}
|
|
143
|
+
declare const DocTile: DocTileClass;
|
|
144
|
+
type DecoElt = Elt<Widget | string>;
|
|
145
|
+
|
|
146
|
+
type ReactKeys = WeakMap<Plot, readonly string[]>;
|
|
147
|
+
declare const childViewKeys: (views: readonly ChildView[]) => ({
|
|
148
|
+
view: {
|
|
149
|
+
type: "widget";
|
|
150
|
+
widget: Widget;
|
|
151
|
+
side: number;
|
|
152
|
+
key?: string;
|
|
153
|
+
offset?: number;
|
|
154
|
+
};
|
|
155
|
+
key: string;
|
|
156
|
+
} | {
|
|
157
|
+
view: NodeView | {
|
|
158
|
+
type: "text";
|
|
159
|
+
text: string;
|
|
160
|
+
} | {
|
|
161
|
+
type: "wrapper";
|
|
162
|
+
elt: DecoElt;
|
|
163
|
+
spanning: boolean;
|
|
164
|
+
children: ChildView[];
|
|
165
|
+
key?: string;
|
|
166
|
+
mark?: wordgard_doc.Mark;
|
|
167
|
+
} | {
|
|
168
|
+
type: "buffer";
|
|
169
|
+
side: -1 | 1;
|
|
170
|
+
} | {
|
|
171
|
+
type: "composition";
|
|
172
|
+
key: string;
|
|
173
|
+
rendered: string | null;
|
|
174
|
+
} | {
|
|
175
|
+
type: "trailingHack";
|
|
176
|
+
};
|
|
177
|
+
key: string;
|
|
178
|
+
})[];
|
|
179
|
+
|
|
180
|
+
type NodeCell = {
|
|
181
|
+
view: NodeView;
|
|
182
|
+
listener: (() => void) | null;
|
|
183
|
+
};
|
|
184
|
+
type RenderStore = {
|
|
185
|
+
readonly keys: ReactKeys;
|
|
186
|
+
readonly pending: Map<NodeCell, NodeView>;
|
|
187
|
+
};
|
|
188
|
+
declare const cellOf: (view: NodeView) => NodeCell;
|
|
189
|
+
|
|
190
|
+
type Words = {
|
|
191
|
+
readonly library: string;
|
|
192
|
+
readonly name: string;
|
|
193
|
+
readonly root: string;
|
|
194
|
+
readonly widgetRoot: string;
|
|
195
|
+
readonly content: string;
|
|
196
|
+
readonly wrapped: string;
|
|
197
|
+
readonly anchor: string;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
type NodeView = {
|
|
201
|
+
type: "node";
|
|
202
|
+
node: Node$1;
|
|
203
|
+
key: string;
|
|
204
|
+
shape: Decoration.Shape;
|
|
205
|
+
children: readonly ChildView[] | null;
|
|
206
|
+
};
|
|
207
|
+
type WrapperChildView = {
|
|
208
|
+
type: "wrapper";
|
|
209
|
+
elt: DecoElt;
|
|
210
|
+
spanning: boolean;
|
|
211
|
+
children: ChildView[];
|
|
212
|
+
key?: string;
|
|
213
|
+
mark?: Mark;
|
|
214
|
+
};
|
|
215
|
+
type WidgetChildView = {
|
|
216
|
+
type: "widget";
|
|
217
|
+
widget: Widget;
|
|
218
|
+
side: number;
|
|
219
|
+
key?: string;
|
|
220
|
+
offset?: number;
|
|
221
|
+
};
|
|
222
|
+
type ChildView = NodeView | {
|
|
223
|
+
type: "text";
|
|
224
|
+
text: string;
|
|
225
|
+
} | WrapperChildView | {
|
|
226
|
+
type: "buffer";
|
|
227
|
+
side: -1 | 1;
|
|
228
|
+
} | WidgetChildView | {
|
|
229
|
+
type: "composition";
|
|
230
|
+
key: string;
|
|
231
|
+
rendered: string | null;
|
|
232
|
+
} | {
|
|
233
|
+
type: "trailingHack";
|
|
234
|
+
};
|
|
235
|
+
type WrapperView = {
|
|
236
|
+
readonly elt: DecoElt;
|
|
237
|
+
readonly spanning: boolean;
|
|
238
|
+
readonly key?: string;
|
|
239
|
+
readonly mark?: Mark;
|
|
240
|
+
};
|
|
241
|
+
declare const VOID: RegExp;
|
|
242
|
+
declare const uneditable: (shape: DecoElt, inEditable: boolean) => {
|
|
243
|
+
shape: DecoElt;
|
|
244
|
+
inEditable: boolean;
|
|
245
|
+
flag: number;
|
|
246
|
+
};
|
|
247
|
+
declare const shapeOf: (views: readonly ChildView[]) => object;
|
|
248
|
+
|
|
249
|
+
type MarkShape = {
|
|
250
|
+
element: string;
|
|
251
|
+
attributes: Record<string, string>;
|
|
252
|
+
};
|
|
253
|
+
declare const defineMarkShape: () => {
|
|
254
|
+
id: string;
|
|
255
|
+
shape: (element: string) => MarkShape;
|
|
256
|
+
};
|
|
257
|
+
declare const isComponentMark: (elt: Elt<unknown>) => boolean;
|
|
258
|
+
|
|
259
|
+
/** Picks the node types a wrapper goes around. */
|
|
260
|
+
type SelectTypes = (type: Node$1.Type) => boolean;
|
|
261
|
+
type Entry<C> = {
|
|
262
|
+
readonly type: Node$1.Type | null;
|
|
263
|
+
readonly select: SelectTypes | null;
|
|
264
|
+
readonly component: C;
|
|
265
|
+
};
|
|
266
|
+
type NodeWrappers<C> = {
|
|
267
|
+
/** A type's wrappers, the first outermost; undefined without any. */
|
|
268
|
+
readonly of: (type: Node$1.Type) => readonly C[] | undefined;
|
|
269
|
+
readonly entries: readonly Entry<C>[];
|
|
270
|
+
};
|
|
271
|
+
declare const createNodeWrappers: <C>(entries: readonly Entry<C>[]) => NodeWrappers<C>;
|
|
272
|
+
declare const defineNodeWrappers: <C>() => {
|
|
273
|
+
facet: GardState.Facet<Entry<C>, NodeWrappers<C>>;
|
|
274
|
+
nodeWrapper: (type: Node$1.Type.Ref<any> | SelectTypes, component: C) => GardState.Extension;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
type ComponentShape = ((tag: Node$1.Tag) => Elt) & {
|
|
278
|
+
of: (element: string, options?: {
|
|
279
|
+
atom?: boolean;
|
|
280
|
+
}) => Elt;
|
|
281
|
+
};
|
|
282
|
+
declare const defineShape: () => {
|
|
283
|
+
id: string;
|
|
284
|
+
shape: ComponentShape;
|
|
285
|
+
};
|
|
286
|
+
declare const idOf: (elt: Elt<unknown>) => string | null;
|
|
287
|
+
declare const isComponentShape: (elt: Elt<unknown>) => boolean;
|
|
288
|
+
declare const shapeAttributes: (elt: Elt<unknown>) => string[];
|
|
289
|
+
type ShapeHandle = {
|
|
290
|
+
root: Element | null;
|
|
291
|
+
content: Element | null;
|
|
292
|
+
wrapper: boolean;
|
|
293
|
+
atom: boolean;
|
|
294
|
+
};
|
|
295
|
+
declare const atomRef: (handle: ShapeHandle, atom: boolean) => () => void;
|
|
296
|
+
declare const createShapeHandle: () => {
|
|
297
|
+
handle: ShapeHandle;
|
|
298
|
+
ref: (dom: Element | null) => void;
|
|
299
|
+
contentDOMRef: (dom: Element | null) => void;
|
|
300
|
+
};
|
|
301
|
+
declare const createWrapperHandle: () => {
|
|
302
|
+
handle: ShapeHandle;
|
|
303
|
+
ref: (dom: Element | null) => void;
|
|
304
|
+
wrappedRef: (dom: Element | null) => void;
|
|
305
|
+
};
|
|
306
|
+
declare const nodePos: (handle: {
|
|
307
|
+
readonly root: Element | null;
|
|
308
|
+
}, name: string) => () => number;
|
|
309
|
+
|
|
310
|
+
declare const rootReplaced: (old: Element, root: Element) => void;
|
|
311
|
+
|
|
312
|
+
declare const defineWidgetType: <Param>({ propagateEvent, ...spec }: Widget.Spec<Param>) => Widget.Type<Param>;
|
|
313
|
+
declare const isComponentWidget: (widget: Widget) => boolean;
|
|
314
|
+
declare const attributedWidget: (elt: Elt<unknown>) => Widget<any> | null;
|
|
315
|
+
declare const widgetRoot: (dom: Element | null) => void;
|
|
316
|
+
|
|
317
|
+
declare const defineWrapper: () => {
|
|
318
|
+
id: string;
|
|
319
|
+
elt: (element: string) => Elt<string>;
|
|
320
|
+
};
|
|
321
|
+
declare const isComponentWrapper: (elt: Elt<unknown>) => boolean;
|
|
322
|
+
|
|
323
|
+
type StateField<T> = GardState.Field<T> | GardState.Field.Derived<T>;
|
|
324
|
+
type EditorStore = {
|
|
325
|
+
readonly getState: () => GardState;
|
|
326
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
327
|
+
readonly subscribeField: (field: StateField<unknown>, listener: () => void, key?: unknown) => () => void;
|
|
328
|
+
};
|
|
329
|
+
type Measure = () => (() => void) | null;
|
|
330
|
+
type EditorValue = {
|
|
331
|
+
readonly wg: Wordgard;
|
|
332
|
+
readonly store: EditorStore;
|
|
333
|
+
readonly afterFlush: (effect: () => void) => void;
|
|
334
|
+
readonly cancel: (effect: () => void) => void;
|
|
335
|
+
readonly measures: Set<Measure>;
|
|
336
|
+
readonly requestMeasure: () => void;
|
|
337
|
+
};
|
|
338
|
+
type Editor = EditorValue & {
|
|
339
|
+
readonly publish: (state: GardState) => void;
|
|
340
|
+
readonly readMeasures: (wg: Wordgard) => void;
|
|
341
|
+
readonly runEffects: () => void;
|
|
342
|
+
readonly requestEffects: () => void;
|
|
343
|
+
flushing: boolean;
|
|
344
|
+
batch: (change: () => void) => void;
|
|
345
|
+
};
|
|
346
|
+
declare const editorOf: (wg: Wordgard) => Editor;
|
|
347
|
+
declare const findEditor: (wg: Wordgard) => EditorValue | undefined;
|
|
348
|
+
|
|
349
|
+
declare const attrsToRecord: (attrs: Attributes) => Record<string, string>;
|
|
350
|
+
declare const namespaced: RegExp;
|
|
351
|
+
declare const localTagName: (tagName: string) => string;
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* A copy of what an editor drew under `dom` (its content element, or a node's element), to lay out
|
|
355
|
+
* as it does outside the editor: a header's copy on every page. It has no ids, which would repeat
|
|
356
|
+
* the document's, and none of the editor's own: no `contenteditable`, no selection classes, none of
|
|
357
|
+
* Wordgard's buffers. The `<br>`s Wordgard ends textblocks with get the class
|
|
358
|
+
* `wg-trailing-break`, which only the editor's tiles tell from a line break's.
|
|
359
|
+
*/
|
|
360
|
+
declare const staticCopy: (dom: Element) => Element;
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Whether `dom` is the `<br>` Wordgard puts at the end of a textblock to hold the cursor, not a
|
|
364
|
+
* line break's. It adds no line of its own, except after a line break, where it holds the empty
|
|
365
|
+
* last line. Reads the editor's tiles: a copy of the DOM doesn't tell.
|
|
366
|
+
*/
|
|
367
|
+
declare const isTrailingBreak: (dom: Node) => boolean;
|
|
368
|
+
|
|
369
|
+
type DocTiles = {
|
|
370
|
+
readonly create: (state: GardState, dom: Element, wg: Wordgard) => DocTile;
|
|
371
|
+
readonly host: (state: GardState, dom: Element, wg: Wordgard, mount: () => void) => DocTile;
|
|
372
|
+
};
|
|
373
|
+
declare class RenderedWordgard extends Wordgard {
|
|
374
|
+
docTile: DocTile;
|
|
375
|
+
observer: DOMObserver;
|
|
376
|
+
scheduleFlush: () => void;
|
|
377
|
+
constructor(spec: Wordgard.Spec, tiles: DocTiles, hosted: boolean);
|
|
378
|
+
flush(): void;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
type Renderer = {
|
|
382
|
+
readonly commit: (state: GardState, views: readonly ChildView[], publish: () => void) => void;
|
|
383
|
+
readonly batch: (change: () => void) => void;
|
|
384
|
+
readonly redrawsAll: (before: GardState, after: GardState) => boolean;
|
|
385
|
+
readonly words: Words;
|
|
386
|
+
readonly settle?: () => boolean;
|
|
387
|
+
};
|
|
388
|
+
type HostedRenderer = Renderer & {
|
|
389
|
+
readonly prepare: (state: GardState, views: readonly ChildView[]) => void;
|
|
390
|
+
};
|
|
391
|
+
type RendererContext = {
|
|
392
|
+
readonly wg: Wordgard;
|
|
393
|
+
readonly store: RenderStore;
|
|
394
|
+
readonly failed: (thrown: unknown) => void;
|
|
395
|
+
};
|
|
396
|
+
type RendererFactory<R extends Renderer> = (dom: Element, context: RendererContext) => R;
|
|
397
|
+
type TileClass = new (state: GardState, dom: Element, cursorWrapper: Mark.Set | null, decoSet: DecoSet) => RenderedDocTile;
|
|
398
|
+
declare const nodeViewOf: (tile: Tile) => NodeView | undefined;
|
|
399
|
+
declare class RefusedUpdate extends Error {
|
|
400
|
+
}
|
|
401
|
+
declare const createDocTile: (Tile: TileClass, create: RendererFactory<Renderer>, state: GardState, dom: Element, wg: Wordgard) => RenderedDocTile;
|
|
402
|
+
declare const hostDocTile: (Tile: TileClass, create: RendererFactory<HostedRenderer>, state: GardState, dom: Element, wg: Wordgard) => RenderedDocTile;
|
|
403
|
+
declare class RenderedDocTile extends DocTile {
|
|
404
|
+
widgets: boolean;
|
|
405
|
+
updateRanges(state: GardState, decoSet: DecoSet, ranges: readonly number[], wg: Wordgard, info?: CompositionInfo | null): RenderedDocTile;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
declare const viewRoot: (dom: Element | null) => void;
|
|
409
|
+
declare const drawnRoot: (dom: Element | null) => void;
|
|
410
|
+
|
|
411
|
+
export { type ChildView, type ComponentShape, type DecoElt, type DecorationHandlers, DocTile, type EditorEvent, type EditorValue, type HostedRenderer, type MarkShape, type NodeCell, type NodeView, type NodeWrappers, RefusedUpdate, RenderedDocTile, RenderedWordgard, type Renderer, type RendererContext, type SelectTypes, type StateField, type Tile, TileFlag, VOID, type Words, type WrapperView, atomRef, attributedWidget, attrsToRecord, cellOf, childViewKeys, createDecorationHandlers, createDocTile, createNodeWrappers, createShapeHandle, createWrapperHandle, decorationRoot, defineMarkShape, defineNodeWrappers, defineShape, defineWidgetType, defineWrapper, drawnRoot, editorOf, findEditor, hostDocTile, idOf, isComponentMark, isComponentShape, isComponentWidget, isComponentWrapper, isTrailingBreak, listenersOf, localTagName, namespaced, nodePos, nodeViewOf, rootReplaced, shapeAttributes, shapeOf, staticCopy, uneditable, viewRoot, widgetRoot };
|