@zuilib/text-editor 0.11.1 → 0.13.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 (50) hide show
  1. package/CHANGELOG.md +202 -18
  2. package/DRAWING_FORMAT.md +23 -21
  3. package/README.md +531 -87
  4. package/dist/chunk-32RX4GZF.js +2 -0
  5. package/dist/chunk-3KAABUZQ.js +2 -0
  6. package/dist/chunk-5J4TV6XA.js +2 -0
  7. package/dist/chunk-5VRVC56Y.js +2 -0
  8. package/dist/chunk-6JQG6QDN.js +16 -0
  9. package/dist/chunk-6LHJXZZ2.js +2 -0
  10. package/dist/chunk-7Z3CW6Q3.js +2 -0
  11. package/dist/chunk-A7MCBSAZ.js +2 -0
  12. package/dist/chunk-AGTPMKLK.js +2 -0
  13. package/dist/chunk-LDVPFZCN.js +2 -0
  14. package/dist/chunk-N5JWZ2VW.js +9 -0
  15. package/dist/chunk-N6OUUWQO.js +5 -0
  16. package/dist/chunk-QKHMJQO3.js +2 -0
  17. package/dist/chunk-TGVEPLDM.js +1 -0
  18. package/dist/chunk-XRJNLGI4.js +2 -0
  19. package/dist/chunk-YFFSTMIR.js +2 -0
  20. package/dist/chunk-ZXZMYJ7F.js +2 -0
  21. package/dist/comment-markers-BrrrAdSL.d.ts +27 -0
  22. package/dist/comments.d.ts +68 -0
  23. package/dist/comments.js +2 -0
  24. package/dist/drawing-data-EWzEQ1_i.d.ts +111 -0
  25. package/dist/drawing-preset-Ag7a7F9h.d.ts +69 -0
  26. package/dist/drawing.d.ts +7 -0
  27. package/dist/drawing.js +2 -0
  28. package/dist/image-node-kR1Zf5kz.d.ts +70 -0
  29. package/dist/images.d.ts +66 -0
  30. package/dist/images.js +2 -0
  31. package/dist/index-A4S7bRwQ.d.ts +425 -0
  32. package/dist/index.d.ts +36 -1394
  33. package/dist/index.js +1 -7449
  34. package/dist/lexical.d.ts +117 -0
  35. package/dist/lexical.js +2 -0
  36. package/dist/markdown.d.ts +29 -0
  37. package/dist/markdown.js +2 -0
  38. package/dist/mention-node-eSsjUpaE.d.ts +44 -0
  39. package/dist/mentions-plugin-gio3_XKd.d.ts +74 -0
  40. package/dist/mentions.d.ts +5 -0
  41. package/dist/mentions.js +2 -0
  42. package/dist/mermaid-BwGHjwpk.d.ts +553 -0
  43. package/dist/paste.d.ts +45 -0
  44. package/dist/paste.js +2 -0
  45. package/dist/presets-BtNPH0pa.d.ts +78 -0
  46. package/dist/styles.css +612 -96
  47. package/dist/table-grid-D70tNhp2.d.ts +459 -0
  48. package/dist/tailwind.css +7 -0
  49. package/package.json +58 -27
  50. package/dist/index.css +0 -79
@@ -0,0 +1,425 @@
1
+ import { LexicalEditor, TextFormatType, NodeKey, LexicalCommand } from 'lexical';
2
+ import { HeadingTagType } from '@lexical/rich-text';
3
+ import { a as BlockWidth } from './presets-BtNPH0pa.js';
4
+ import { l as TableDensity, k as TableCellPosition } from './table-grid-D70tNhp2.js';
5
+ import { RefObject, KeyboardEvent, FocusEvent } from 'react';
6
+
7
+ /** Block kinds the toolbar can switch the selected blocks to */
8
+ type BlockType = 'paragraph' | HeadingTagType | 'quote' | 'bullet' | 'number' | 'check';
9
+ type MarkdownEditorApi = Readonly<{
10
+ /** The underlying Lexical editor, for dispatching your own commands */
11
+ editor: LexicalEditor;
12
+ /** Text formats active at the current selection */
13
+ activeFormats: ReadonlySet<TextFormatType>;
14
+ toggleFormat: (format: TextFormatType) => void;
15
+ /** Kind of the block the selection is in; `null` without a range selection */
16
+ blockType: BlockType | null;
17
+ /** Turn the selected blocks into the given kind. Repeating the current list kind lifts the list. */
18
+ setBlockType: (type: BlockType) => void;
19
+ /** The link the selection is in (`null` outside links) */
20
+ link: {
21
+ key: NodeKey;
22
+ url: string;
23
+ } | null;
24
+ /**
25
+ * Wrap the selection in a link (or change the current link's URL);
26
+ * `null` removes it. Outside a link a collapsed selection is a no-op:
27
+ * there is nothing to wrap, and Lexical would otherwise link the whole
28
+ * text node the caret sits in.
29
+ */
30
+ setLink: (url: string | null) => void;
31
+ /** Whether the selection is a non-empty range (something the link button can wrap) */
32
+ hasSelection: boolean;
33
+ /**
34
+ * Insert a table at the selection. `width` defaults to
35
+ * `newBlockWidth.table` (Root prop); when given it is written to the
36
+ * markdown explicitly, even when `full`.
37
+ */
38
+ insertTable: (options?: {
39
+ rows?: number;
40
+ columns?: number;
41
+ width?: BlockWidth;
42
+ }) => void;
43
+ /**
44
+ * Insert an empty drawing at the selection. `width` defaults to
45
+ * `newBlockWidth.drawing` (Root prop); when given it is written to
46
+ * the markdown explicitly, even when `full`.
47
+ */
48
+ insertDrawing: (options?: {
49
+ width?: BlockWidth;
50
+ }) => void;
51
+ /**
52
+ * Width of the block containing the selection — the focused drawing, or
53
+ * else the table the caret is in; `null` outside both.
54
+ */
55
+ blockWidth: BlockWidth | null;
56
+ /** Resize that block; no-op when `blockWidth` is `null` */
57
+ setBlockWidth: (width: BlockWidth) => void;
58
+ /**
59
+ * Width of the table containing the selection; `null` outside tables.
60
+ * @deprecated Use `blockWidth`, which also covers drawings.
61
+ */
62
+ tableWidth: BlockWidth | null;
63
+ /**
64
+ * Resize the table containing the selection; no-op outside tables.
65
+ * @deprecated Use `setBlockWidth`, which also covers drawings.
66
+ */
67
+ setTableWidth: (width: BlockWidth) => void;
68
+ /** Density of the table containing the selection; `null` outside tables */
69
+ tableDensity: TableDensity | null;
70
+ /** Change the density of the table containing the selection; no-op outside tables */
71
+ setTableDensity: (density: TableDensity) => void;
72
+ /** The selection's cell in its table (row, column, counts, header); `null` outside tables */
73
+ tableCell: TableCellPosition | null;
74
+ /**
75
+ * Insert an empty row next to the selection's row (default `below`) and
76
+ * move the caret into it; no-op outside tables. A row is never inserted
77
+ * above the header row: `above` there inserts right below it.
78
+ */
79
+ insertTableRow: (position?: 'above' | 'below') => void;
80
+ /**
81
+ * Remove the selection's row; no-op outside tables and on the last
82
+ * remaining row. Deleting the header row makes the next row the header.
83
+ */
84
+ deleteTableRow: () => void;
85
+ /**
86
+ * Insert an empty column next to the selection's column (default
87
+ * `after`) and move the caret into it; no-op outside tables.
88
+ */
89
+ insertTableColumn: (position?: 'before' | 'after') => void;
90
+ /** Remove the selection's column; no-op outside tables and on the last remaining column. */
91
+ deleteTableColumn: () => void;
92
+ canUndo: boolean;
93
+ canRedo: boolean;
94
+ undo: () => void;
95
+ redo: () => void;
96
+ }>;
97
+ /**
98
+ * Headless access to the editor. Must be rendered under `MarkdownEditor.Root`
99
+ * (or `MarkdownEditor`). Use it to wire editor actions into your own buttons.
100
+ */
101
+ declare function useMarkdownEditor(): MarkdownEditorApi;
102
+
103
+ type CollapsibleHeadingsLabels = Readonly<{
104
+ collapse: string;
105
+ expand: string;
106
+ collapsed: string;
107
+ expanded: string;
108
+ }>;
109
+
110
+ type TableColumnShortcutsLabels = Readonly<{
111
+ inserted: string;
112
+ deleted: string;
113
+ }>;
114
+
115
+ type TableRowShortcutsLabels = Readonly<{
116
+ inserted: string;
117
+ deleted: string;
118
+ }>;
119
+
120
+ /**
121
+ * Schemes a link may use. Anything else (`javascript:`, `data:`,
122
+ * `vbscript:`, ...) is rejected by `LinkPlugin`, so a pasted or typed URL
123
+ * cannot run script when the rendered document is clicked. Scheme-less
124
+ * values (`example.com/path`, `#anchor`, `/relative`) are allowed.
125
+ */
126
+ declare const SAFE_LINK_PROTOCOLS: readonly string[];
127
+ /**
128
+ * Opens the link bubble for the selection. Nothing is written to the
129
+ * document until the bubble applies a URL: outside a link the selection
130
+ * must be non-empty (there is nothing to wrap otherwise), inside a link the
131
+ * bubble edits that link.
132
+ */
133
+ declare const EDIT_LINK_COMMAND: LexicalCommand<undefined>;
134
+ declare function isSafeUrl(url: string): boolean;
135
+
136
+ type ToolbarOrientation = 'horizontal' | 'vertical';
137
+ /**
138
+ * Items take part in the roving tabindex by opting in with this attribute
139
+ * (`ToolbarButton` and the built-in controls set it). Anything else inside
140
+ * the toolbar, a popover's own buttons or a host's nested widget, keeps its
141
+ * own focus handling.
142
+ */
143
+ declare const TOOLBAR_ITEM_ATTRIBUTE = "data-toolbar-item";
144
+ /**
145
+ * APG toolbar keyboard pattern: one Tab stop, arrow keys move between the
146
+ * items, Home / End jump to the ends. Spread the result onto the
147
+ * `role="toolbar"` element.
148
+ */
149
+ declare function useToolbarKeyboard<T extends HTMLElement = HTMLDivElement>(orientation?: ToolbarOrientation): {
150
+ ref: RefObject<T>;
151
+ onKeyDown: (event: KeyboardEvent<T>) => void;
152
+ onFocus: (event: FocusEvent<T>) => void;
153
+ 'aria-orientation': ToolbarOrientation;
154
+ };
155
+
156
+ /**
157
+ * Semantic token vocabulary for code highlighting. Closed on purpose: every
158
+ * grammar maps its syntax onto these names, and the theme maps each name onto
159
+ * one class (`zui-token-<type>`) and one color custom property
160
+ * (`--zui-code-<type>`). Adding a language never adds a color.
161
+ */
162
+ declare const CODE_TOKEN_TYPES: readonly ["comment", "string", "number", "keyword", "builtin", "type", "function", "property", "variable", "constant", "operator", "punctuation", "tag", "attr", "regex", "meta", "inserted", "deleted"];
163
+ type CodeTokenType = (typeof CODE_TOKEN_TYPES)[number];
164
+ /** A run of source text. `text` is uncolored (identifiers, whitespace, …). */
165
+ type CodeToken = Readonly<{
166
+ type: CodeTokenType | 'text';
167
+ text: string;
168
+ }>;
169
+ /**
170
+ * One lexer rule: a regular-expression *source* (no flags, no capturing
171
+ * groups — use `(?:…)`, no backreferences) tried at the current position.
172
+ * Rules are tried in order; the first one that matches wins.
173
+ */
174
+ type CodeRule = Readonly<{
175
+ type: CodeTokenType;
176
+ match: string;
177
+ }>;
178
+ /**
179
+ * A language definition. Pure data: the lexer compiles it once (cached per
180
+ * object identity) and walks the source with it.
181
+ *
182
+ * Identifiers not consumed by a rule are classified by the word lists, then
183
+ * by the two heuristics, and otherwise left as plain text.
184
+ */
185
+ type CodeGrammar = Readonly<{
186
+ /** Canonical name, as written after ``` in markdown */
187
+ name: string;
188
+ aliases?: readonly string[];
189
+ rules: readonly CodeRule[];
190
+ keywords?: readonly string[];
191
+ builtins?: readonly string[];
192
+ types?: readonly string[];
193
+ constants?: readonly string[];
194
+ /** Regex source for identifiers (default: `[A-Za-z_$][\w$]*`) */
195
+ identifier?: string;
196
+ /** Word lists and rules match case-insensitively (SQL) */
197
+ caseInsensitive?: boolean;
198
+ /** An identifier directly followed by `(` is a `function` */
199
+ callIsFunction?: boolean;
200
+ /**
201
+ * A Capitalized identifier is a `type`; a SCREAMING_CASE one is a
202
+ * `constant`
203
+ */
204
+ capitalizedIsType?: boolean;
205
+ }>;
206
+
207
+ /**
208
+ * Splits `code` into a flat list of tokens covering the whole input, in
209
+ * order; adjacent tokens of the same type are merged. Never throws on user
210
+ * input and always makes progress (an empty match counts as no match).
211
+ */
212
+ declare function tokenizeCode(code: string, grammar: CodeGrammar): CodeToken[];
213
+
214
+ /**
215
+ * Language registry: canonical names and aliases, lower-cased, mapped to a
216
+ * grammar. Unknown names resolve to `plain` (line structure, no colors) so
217
+ * every fenced block gets the same editing behavior. The built-in grammars
218
+ * are registered on first use, not at import, so the module has no side
219
+ * effects and bundlers can drop it when unused.
220
+ */
221
+ declare const PLAIN_LANGUAGE = "plain";
222
+ /** Adds (or replaces) a language. Call before the editor mounts. */
223
+ declare function registerCodeLanguage(grammar: CodeGrammar): void;
224
+ declare function hasCodeLanguage(name: string): boolean;
225
+ /** Resolves a fence name (canonical, alias, or `diff-<lang>`) to a grammar. */
226
+ declare function resolveCodeLanguage(name: string | null | undefined): CodeGrammar;
227
+ /** Canonical names of every registered language, sorted */
228
+ declare function getCodeLanguages(): string[];
229
+
230
+ /** The built-in grammars. The registry loads them on first lookup. */
231
+ declare const BUILTIN_CODE_LANGUAGES: readonly [Readonly<{
232
+ name: string;
233
+ aliases?: readonly string[];
234
+ rules: readonly CodeRule[];
235
+ keywords?: readonly string[];
236
+ builtins?: readonly string[];
237
+ types?: readonly string[];
238
+ constants?: readonly string[];
239
+ identifier?: string;
240
+ caseInsensitive?: boolean;
241
+ callIsFunction?: boolean;
242
+ capitalizedIsType?: boolean;
243
+ }>, Readonly<{
244
+ name: string;
245
+ aliases?: readonly string[];
246
+ rules: readonly CodeRule[];
247
+ keywords?: readonly string[];
248
+ builtins?: readonly string[];
249
+ types?: readonly string[];
250
+ constants?: readonly string[];
251
+ identifier?: string;
252
+ caseInsensitive?: boolean;
253
+ callIsFunction?: boolean;
254
+ capitalizedIsType?: boolean;
255
+ }>, Readonly<{
256
+ name: string;
257
+ aliases?: readonly string[];
258
+ rules: readonly CodeRule[];
259
+ keywords?: readonly string[];
260
+ builtins?: readonly string[];
261
+ types?: readonly string[];
262
+ constants?: readonly string[];
263
+ identifier?: string;
264
+ caseInsensitive?: boolean;
265
+ callIsFunction?: boolean;
266
+ capitalizedIsType?: boolean;
267
+ }>, Readonly<{
268
+ name: string;
269
+ aliases?: readonly string[];
270
+ rules: readonly CodeRule[];
271
+ keywords?: readonly string[];
272
+ builtins?: readonly string[];
273
+ types?: readonly string[];
274
+ constants?: readonly string[];
275
+ identifier?: string;
276
+ caseInsensitive?: boolean;
277
+ callIsFunction?: boolean;
278
+ capitalizedIsType?: boolean;
279
+ }>, Readonly<{
280
+ name: string;
281
+ aliases?: readonly string[];
282
+ rules: readonly CodeRule[];
283
+ keywords?: readonly string[];
284
+ builtins?: readonly string[];
285
+ types?: readonly string[];
286
+ constants?: readonly string[];
287
+ identifier?: string;
288
+ caseInsensitive?: boolean;
289
+ callIsFunction?: boolean;
290
+ capitalizedIsType?: boolean;
291
+ }>, Readonly<{
292
+ name: string;
293
+ aliases?: readonly string[];
294
+ rules: readonly CodeRule[];
295
+ keywords?: readonly string[];
296
+ builtins?: readonly string[];
297
+ types?: readonly string[];
298
+ constants?: readonly string[];
299
+ identifier?: string;
300
+ caseInsensitive?: boolean;
301
+ callIsFunction?: boolean;
302
+ capitalizedIsType?: boolean;
303
+ }>, Readonly<{
304
+ name: string;
305
+ aliases?: readonly string[];
306
+ rules: readonly CodeRule[];
307
+ keywords?: readonly string[];
308
+ builtins?: readonly string[];
309
+ types?: readonly string[];
310
+ constants?: readonly string[];
311
+ identifier?: string;
312
+ caseInsensitive?: boolean;
313
+ callIsFunction?: boolean;
314
+ capitalizedIsType?: boolean;
315
+ }>, Readonly<{
316
+ name: string;
317
+ aliases?: readonly string[];
318
+ rules: readonly CodeRule[];
319
+ keywords?: readonly string[];
320
+ builtins?: readonly string[];
321
+ types?: readonly string[];
322
+ constants?: readonly string[];
323
+ identifier?: string;
324
+ caseInsensitive?: boolean;
325
+ callIsFunction?: boolean;
326
+ capitalizedIsType?: boolean;
327
+ }>, Readonly<{
328
+ name: string;
329
+ aliases?: readonly string[];
330
+ rules: readonly CodeRule[];
331
+ keywords?: readonly string[];
332
+ builtins?: readonly string[];
333
+ types?: readonly string[];
334
+ constants?: readonly string[];
335
+ identifier?: string;
336
+ caseInsensitive?: boolean;
337
+ callIsFunction?: boolean;
338
+ capitalizedIsType?: boolean;
339
+ }>, Readonly<{
340
+ name: string;
341
+ aliases?: readonly string[];
342
+ rules: readonly CodeRule[];
343
+ keywords?: readonly string[];
344
+ builtins?: readonly string[];
345
+ types?: readonly string[];
346
+ constants?: readonly string[];
347
+ identifier?: string;
348
+ caseInsensitive?: boolean;
349
+ callIsFunction?: boolean;
350
+ capitalizedIsType?: boolean;
351
+ }>, Readonly<{
352
+ name: string;
353
+ aliases?: readonly string[];
354
+ rules: readonly CodeRule[];
355
+ keywords?: readonly string[];
356
+ builtins?: readonly string[];
357
+ types?: readonly string[];
358
+ constants?: readonly string[];
359
+ identifier?: string;
360
+ caseInsensitive?: boolean;
361
+ callIsFunction?: boolean;
362
+ capitalizedIsType?: boolean;
363
+ }>, Readonly<{
364
+ name: string;
365
+ aliases?: readonly string[];
366
+ rules: readonly CodeRule[];
367
+ keywords?: readonly string[];
368
+ builtins?: readonly string[];
369
+ types?: readonly string[];
370
+ constants?: readonly string[];
371
+ identifier?: string;
372
+ caseInsensitive?: boolean;
373
+ callIsFunction?: boolean;
374
+ capitalizedIsType?: boolean;
375
+ }>, Readonly<{
376
+ name: string;
377
+ aliases?: readonly string[];
378
+ rules: readonly CodeRule[];
379
+ keywords?: readonly string[];
380
+ builtins?: readonly string[];
381
+ types?: readonly string[];
382
+ constants?: readonly string[];
383
+ identifier?: string;
384
+ caseInsensitive?: boolean;
385
+ callIsFunction?: boolean;
386
+ capitalizedIsType?: boolean;
387
+ }>, Readonly<{
388
+ name: string;
389
+ aliases?: readonly string[];
390
+ rules: readonly CodeRule[];
391
+ keywords?: readonly string[];
392
+ builtins?: readonly string[];
393
+ types?: readonly string[];
394
+ constants?: readonly string[];
395
+ identifier?: string;
396
+ caseInsensitive?: boolean;
397
+ callIsFunction?: boolean;
398
+ capitalizedIsType?: boolean;
399
+ }>, Readonly<{
400
+ name: string;
401
+ aliases?: readonly string[];
402
+ rules: readonly CodeRule[];
403
+ keywords?: readonly string[];
404
+ builtins?: readonly string[];
405
+ types?: readonly string[];
406
+ constants?: readonly string[];
407
+ identifier?: string;
408
+ caseInsensitive?: boolean;
409
+ callIsFunction?: boolean;
410
+ capitalizedIsType?: boolean;
411
+ }>, Readonly<{
412
+ name: string;
413
+ aliases?: readonly string[];
414
+ rules: readonly CodeRule[];
415
+ keywords?: readonly string[];
416
+ builtins?: readonly string[];
417
+ types?: readonly string[];
418
+ constants?: readonly string[];
419
+ identifier?: string;
420
+ caseInsensitive?: boolean;
421
+ callIsFunction?: boolean;
422
+ capitalizedIsType?: boolean;
423
+ }>];
424
+
425
+ export { BUILTIN_CODE_LANGUAGES as B, CODE_TOKEN_TYPES as C, EDIT_LINK_COMMAND as E, type MarkdownEditorApi as M, PLAIN_LANGUAGE as P, SAFE_LINK_PROTOCOLS as S, TOOLBAR_ITEM_ATTRIBUTE as T, type BlockType as a, type CodeGrammar as b, type CodeRule as c, type CodeToken as d, type CodeTokenType as e, type CollapsibleHeadingsLabels as f, type TableColumnShortcutsLabels as g, type TableRowShortcutsLabels as h, getCodeLanguages as i, hasCodeLanguage as j, isSafeUrl as k, resolveCodeLanguage as l, useToolbarKeyboard as m, registerCodeLanguage as r, tokenizeCode as t, useMarkdownEditor as u };