@zuilib/text-editor 0.7.2 → 0.9.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 +23 -0
- package/dist/index.d.ts +425 -98
- package/dist/index.js +2052 -255
- package/dist/styles.css +89 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog — @zuilib/text-editor
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
- **Ink drawing style**: `drawingStyle="ink"` on the editor renders shapes
|
|
6
|
+
as one seeded, pressure-varying pen stroke with misregistered fills and
|
|
7
|
+
tapered connectors, and switches the canvas face to Recursive (casual
|
|
8
|
+
axes) when the host loads it. Renderer-only: the drawing format is
|
|
9
|
+
unchanged. Geometry helpers are exported (`inkStroke`, `seedFrom`, …)
|
|
10
|
+
|
|
11
|
+
## 0.8.0
|
|
12
|
+
|
|
13
|
+
- **Syntax highlighting** for fenced code blocks, driven by the package's
|
|
14
|
+
own grammars instead of Prism: JavaScript/TypeScript, Kotlin, Java, C/C++,
|
|
15
|
+
Python, Go, Rust, JSON, YAML, shell, SQL, CSS, HTML/XML, diff and
|
|
16
|
+
markdown. Colors are CSS custom properties (`--zui-code-<type>` on
|
|
17
|
+
`.zui-code`) with light and dark defaults; override them to retheme.
|
|
18
|
+
`registerCodeLanguage(grammar)` adds a language from a data-only grammar;
|
|
19
|
+
`tokenizeCode` and `codeTokenizer` are exported for reuse
|
|
20
|
+
- Untagged code blocks are highlighted as `plain` and export as a bare
|
|
21
|
+
``` fence (previously they came back as ```javascript). `CODE_BLOCK` is
|
|
22
|
+
the exported transformer that does this
|
|
23
|
+
- Unknown languages get the same line structure as known ones, so cursor
|
|
24
|
+
movement and indentation behave identically
|
|
25
|
+
|
|
3
26
|
## 0.7.2
|
|
4
27
|
|
|
5
28
|
- Canvas properties are one **color** setting (outline plus its matching
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ReactNode, ReactElement } from 'react';
|
|
|
3
3
|
import { LexicalEditor, TextFormatType, ElementNode, NodeKey, EditorConfig, SerializedElementNode, LexicalNode, DecoratorNode, Spread, SerializedLexicalNode, DOMExportOutput, DOMConversionMap } from 'lexical';
|
|
4
4
|
import { TableNode } from '@lexical/table';
|
|
5
5
|
import { MultilineElementTransformer, ElementTransformer } from '@lexical/markdown';
|
|
6
|
+
import { registerCodeHighlighting } from '@lexical/code';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Horizontal sizing of a block that would otherwise span the editor:
|
|
@@ -29,6 +30,146 @@ type BlockWidthDefaults = Readonly<{
|
|
|
29
30
|
drawing?: BlockWidth;
|
|
30
31
|
}>;
|
|
31
32
|
|
|
33
|
+
/** Card-like shapes: fillable, bindable, carrying the three text slots */
|
|
34
|
+
type BoxType = 'rect' | 'ellipse' | 'diamond' | 'note' | 'cylinder' | 'cloud' | 'queue' | 'actor';
|
|
35
|
+
type ConnectorType = 'arrow' | 'line';
|
|
36
|
+
type DrawingShapeType = BoxType | ConnectorType | 'text';
|
|
37
|
+
declare const BOX_TYPES: readonly BoxType[];
|
|
38
|
+
declare const CONNECTOR_TYPES: readonly ConnectorType[];
|
|
39
|
+
declare const SHAPE_TYPES: readonly DrawingShapeType[];
|
|
40
|
+
type Point = Readonly<{
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
}>;
|
|
44
|
+
type BindingSide = 'top' | 'right' | 'bottom' | 'left';
|
|
45
|
+
/**
|
|
46
|
+
* Where a connector endpoint attaches to a box.
|
|
47
|
+
*
|
|
48
|
+
* `fixedPoint` is a ratio inside the box's bounding box (`[0,0]` top-left,
|
|
49
|
+
* `[1,1]` bottom-right). Omitted = the box center, which makes the endpoint
|
|
50
|
+
* auto-aim at the other end. `mode: 'inside'` pins the endpoint exactly on
|
|
51
|
+
* the fixed point; the default (`'orbit'`) projects it onto the outline with
|
|
52
|
+
* a small gap.
|
|
53
|
+
*/
|
|
54
|
+
type Binding = Readonly<{
|
|
55
|
+
id: string;
|
|
56
|
+
fixedPoint?: readonly [number, number];
|
|
57
|
+
mode?: 'orbit' | 'inside';
|
|
58
|
+
}>;
|
|
59
|
+
type DrawingShape = Readonly<{
|
|
60
|
+
id: string;
|
|
61
|
+
type: DrawingShapeType;
|
|
62
|
+
/** Top-left corner (boxes/text) or start point (connectors) */
|
|
63
|
+
x: number;
|
|
64
|
+
y: number;
|
|
65
|
+
/** Size (boxes/text) or delta to the end point (connectors) */
|
|
66
|
+
w: number;
|
|
67
|
+
h: number;
|
|
68
|
+
stroke: string;
|
|
69
|
+
fill: string;
|
|
70
|
+
strokeWidth: number;
|
|
71
|
+
/** Standalone text, main (center) content of a box, or connector label */
|
|
72
|
+
text?: string;
|
|
73
|
+
/** Small heading rendered at the top of a box */
|
|
74
|
+
label?: string;
|
|
75
|
+
/** Small line rendered at the bottom of a box */
|
|
76
|
+
footer?: string;
|
|
77
|
+
/** Connector: box the start point is attached to */
|
|
78
|
+
startBinding?: Binding;
|
|
79
|
+
/** Connector: box the end point is attached to */
|
|
80
|
+
endBinding?: Binding;
|
|
81
|
+
/** Arrow: arrowheads on both ends */
|
|
82
|
+
bidirectional?: boolean;
|
|
83
|
+
/** Connector routing: right-angled auto-routed path instead of a straight line */
|
|
84
|
+
routing?: 'elbow';
|
|
85
|
+
/**
|
|
86
|
+
* Elbow override: position of the middle segment as a fraction of the
|
|
87
|
+
* span, applied only when the routed path is a simple three-segment Z.
|
|
88
|
+
*/
|
|
89
|
+
elbow?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Connector: intermediate path points between start and end (absolute
|
|
92
|
+
* canvas coordinates). Takes precedence over `routing`.
|
|
93
|
+
*/
|
|
94
|
+
waypoints?: readonly Point[];
|
|
95
|
+
}>;
|
|
96
|
+
type DrawingData = Readonly<{
|
|
97
|
+
version: 2;
|
|
98
|
+
/**
|
|
99
|
+
* Logical canvas width. When set the drawing is scaled to fit narrower
|
|
100
|
+
* layouts (SVG viewBox); when omitted the canvas is fluid and shapes are
|
|
101
|
+
* in CSS pixels.
|
|
102
|
+
*/
|
|
103
|
+
canvasWidth?: number;
|
|
104
|
+
canvasHeight: number;
|
|
105
|
+
/**
|
|
106
|
+
* Block width: `full` (default) spans the editor; `text` aligns with the
|
|
107
|
+
* text column; `content` fits the shapes' horizontal extent. The editor
|
|
108
|
+
* omits `full` unless it was written explicitly (an insertion default or
|
|
109
|
+
* the source payload); unknown values are dropped.
|
|
110
|
+
*/
|
|
111
|
+
width?: BlockWidth;
|
|
112
|
+
shapes: readonly DrawingShape[];
|
|
113
|
+
}>;
|
|
114
|
+
declare const EMPTY_DRAWING: DrawingData;
|
|
115
|
+
declare const STROKE_COLORS: readonly ["#1e1e1e", "#e03131", "#2f9e44", "#1971c2", "#f08c00", "#7048e8"];
|
|
116
|
+
declare const FILL_COLORS: readonly ["transparent", "#ffc9c9", "#b2f2bb", "#a5d8ff", "#ffec99", "#d0bfff"];
|
|
117
|
+
/** Edge midpoints, used by the ```diagram skeleton's `side` option */
|
|
118
|
+
declare const SIDE_FIXED_POINTS: Record<BindingSide, readonly [number, number]>;
|
|
119
|
+
declare function serializeDrawingData(data: DrawingData): string;
|
|
120
|
+
/**
|
|
121
|
+
* Parse a ```drawing payload. Exactly one format is accepted: version 2 as
|
|
122
|
+
* written by the editor (the ```diagram skeleton is a separate block type,
|
|
123
|
+
* see skeleton.ts). Shapes that fail validation are dropped and a malformed
|
|
124
|
+
* document yields an empty canvas. Never throws.
|
|
125
|
+
*/
|
|
126
|
+
declare function parseDrawingData(json: string): DrawingData;
|
|
127
|
+
declare function normalizeDrawingData(parsed: unknown): DrawingData;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* "Ink" rendering: one confident pen stroke instead of a plotted outline.
|
|
131
|
+
* Every shape's centerline is resampled densely, displaced along its normal
|
|
132
|
+
* by a smooth low-frequency field (two sines, integer frequencies on closed
|
|
133
|
+
* paths so the seam is continuous) and widened by a slowly varying pressure
|
|
134
|
+
* factor. The result is a filled ring path, not an SVG stroke, so the width
|
|
135
|
+
* can breathe along the path. Everything is seeded from the shape id: the
|
|
136
|
+
* same shape draws the same way on every render, undo, export and machine.
|
|
137
|
+
*
|
|
138
|
+
* This is a renderer concern only — the drawing format never sees it.
|
|
139
|
+
*/
|
|
140
|
+
type DrawingStyle = 'clean' | 'ink';
|
|
141
|
+
type InkOptions = Readonly<{
|
|
142
|
+
closed: boolean;
|
|
143
|
+
seed: number;
|
|
144
|
+
/** Nominal stroke width; the pressure factor varies it by ±30 % */
|
|
145
|
+
width: number;
|
|
146
|
+
/** Peak displacement from the geometric path, in px */
|
|
147
|
+
amplitude: number;
|
|
148
|
+
}>;
|
|
149
|
+
type InkStroke = Readonly<{
|
|
150
|
+
/** Filled outline of the stroke (use `fillRule="evenodd"`) */
|
|
151
|
+
ring: string;
|
|
152
|
+
/** Displaced centerline, for fills */
|
|
153
|
+
center: string;
|
|
154
|
+
}>;
|
|
155
|
+
/** FNV-1a: a stable 32-bit seed from a shape id */
|
|
156
|
+
declare function seedFrom(text: string): number;
|
|
157
|
+
/** Wobble amplitude for a shape of the given smallest dimension (px) */
|
|
158
|
+
declare function inkAmplitude(size: number): number;
|
|
159
|
+
/** Fill misregistration for a shape: a seeded 2–3 px offset */
|
|
160
|
+
declare function inkFillOffset(seed: number): Point;
|
|
161
|
+
/** Ink stroke along a polyline (open) or polygon (closed) */
|
|
162
|
+
declare function inkStroke(points: readonly Point[], options: InkOptions): InkStroke;
|
|
163
|
+
/** Rectangle outline with circular corners, as a polygon */
|
|
164
|
+
declare function roundedRectPolygon(r: Readonly<{
|
|
165
|
+
x: number;
|
|
166
|
+
y: number;
|
|
167
|
+
w: number;
|
|
168
|
+
h: number;
|
|
169
|
+
}>, radius: number, segments?: number): Point[];
|
|
170
|
+
/** Polyline with its interior corners rounded (quadratic), as points */
|
|
171
|
+
declare function roundedPolyline(points: readonly Point[], cornerRadius?: number, segments?: number): Point[];
|
|
172
|
+
|
|
32
173
|
type EditorMode = 'edit-raw' | 'edit-md' | 'view';
|
|
33
174
|
|
|
34
175
|
type EditorRootProps = Readonly<{
|
|
@@ -54,6 +195,12 @@ type EditorRootProps = Readonly<{
|
|
|
54
195
|
* insertion — markdown without a width marker always means `full`.
|
|
55
196
|
*/
|
|
56
197
|
defaultBlockWidth?: BlockWidthDefaults;
|
|
198
|
+
/**
|
|
199
|
+
* `clean` (default) draws crisp geometry; `ink` draws every shape as a
|
|
200
|
+
* single pen stroke with pressure and slightly misregistered fills, and
|
|
201
|
+
* sets the casual face (Recursive, if the host loads it).
|
|
202
|
+
*/
|
|
203
|
+
drawingStyle?: DrawingStyle;
|
|
57
204
|
children: ReactNode;
|
|
58
205
|
}>;
|
|
59
206
|
/**
|
|
@@ -61,7 +208,7 @@ type EditorRootProps = Readonly<{
|
|
|
61
208
|
* beneath it (`Content`, `Toolbar`, `Outline`, or your own components using
|
|
62
209
|
* `useMarkdownEditor`) shares the same editor instance.
|
|
63
210
|
*/
|
|
64
|
-
declare function EditorRoot({ value, onChange, readOnly, className, mode, autoFocus, measure, defaultBlockWidth, children, }: EditorRootProps): ReactElement;
|
|
211
|
+
declare function EditorRoot({ value, onChange, readOnly, className, mode, autoFocus, measure, defaultBlockWidth, drawingStyle, children, }: EditorRootProps): ReactElement;
|
|
65
212
|
|
|
66
213
|
type EditorContentProps = Readonly<{
|
|
67
214
|
placeholder?: string;
|
|
@@ -284,102 +431,6 @@ declare function $isFrontmatterNode(node: LexicalNode | null | undefined): node
|
|
|
284
431
|
*/
|
|
285
432
|
declare const FRONTMATTER: MultilineElementTransformer;
|
|
286
433
|
|
|
287
|
-
/** Card-like shapes: fillable, bindable, carrying the three text slots */
|
|
288
|
-
type BoxType = 'rect' | 'ellipse' | 'diamond' | 'note' | 'cylinder' | 'cloud' | 'queue' | 'actor';
|
|
289
|
-
type ConnectorType = 'arrow' | 'line';
|
|
290
|
-
type DrawingShapeType = BoxType | ConnectorType | 'text';
|
|
291
|
-
declare const BOX_TYPES: readonly BoxType[];
|
|
292
|
-
declare const CONNECTOR_TYPES: readonly ConnectorType[];
|
|
293
|
-
declare const SHAPE_TYPES: readonly DrawingShapeType[];
|
|
294
|
-
type Point = Readonly<{
|
|
295
|
-
x: number;
|
|
296
|
-
y: number;
|
|
297
|
-
}>;
|
|
298
|
-
type BindingSide = 'top' | 'right' | 'bottom' | 'left';
|
|
299
|
-
/**
|
|
300
|
-
* Where a connector endpoint attaches to a box.
|
|
301
|
-
*
|
|
302
|
-
* `fixedPoint` is a ratio inside the box's bounding box (`[0,0]` top-left,
|
|
303
|
-
* `[1,1]` bottom-right). Omitted = the box center, which makes the endpoint
|
|
304
|
-
* auto-aim at the other end. `mode: 'inside'` pins the endpoint exactly on
|
|
305
|
-
* the fixed point; the default (`'orbit'`) projects it onto the outline with
|
|
306
|
-
* a small gap.
|
|
307
|
-
*/
|
|
308
|
-
type Binding = Readonly<{
|
|
309
|
-
id: string;
|
|
310
|
-
fixedPoint?: readonly [number, number];
|
|
311
|
-
mode?: 'orbit' | 'inside';
|
|
312
|
-
}>;
|
|
313
|
-
type DrawingShape = Readonly<{
|
|
314
|
-
id: string;
|
|
315
|
-
type: DrawingShapeType;
|
|
316
|
-
/** Top-left corner (boxes/text) or start point (connectors) */
|
|
317
|
-
x: number;
|
|
318
|
-
y: number;
|
|
319
|
-
/** Size (boxes/text) or delta to the end point (connectors) */
|
|
320
|
-
w: number;
|
|
321
|
-
h: number;
|
|
322
|
-
stroke: string;
|
|
323
|
-
fill: string;
|
|
324
|
-
strokeWidth: number;
|
|
325
|
-
/** Standalone text, main (center) content of a box, or connector label */
|
|
326
|
-
text?: string;
|
|
327
|
-
/** Small heading rendered at the top of a box */
|
|
328
|
-
label?: string;
|
|
329
|
-
/** Small line rendered at the bottom of a box */
|
|
330
|
-
footer?: string;
|
|
331
|
-
/** Connector: box the start point is attached to */
|
|
332
|
-
startBinding?: Binding;
|
|
333
|
-
/** Connector: box the end point is attached to */
|
|
334
|
-
endBinding?: Binding;
|
|
335
|
-
/** Arrow: arrowheads on both ends */
|
|
336
|
-
bidirectional?: boolean;
|
|
337
|
-
/** Connector routing: right-angled auto-routed path instead of a straight line */
|
|
338
|
-
routing?: 'elbow';
|
|
339
|
-
/**
|
|
340
|
-
* Elbow override: position of the middle segment as a fraction of the
|
|
341
|
-
* span, applied only when the routed path is a simple three-segment Z.
|
|
342
|
-
*/
|
|
343
|
-
elbow?: number;
|
|
344
|
-
/**
|
|
345
|
-
* Connector: intermediate path points between start and end (absolute
|
|
346
|
-
* canvas coordinates). Takes precedence over `routing`.
|
|
347
|
-
*/
|
|
348
|
-
waypoints?: readonly Point[];
|
|
349
|
-
}>;
|
|
350
|
-
type DrawingData = Readonly<{
|
|
351
|
-
version: 2;
|
|
352
|
-
/**
|
|
353
|
-
* Logical canvas width. When set the drawing is scaled to fit narrower
|
|
354
|
-
* layouts (SVG viewBox); when omitted the canvas is fluid and shapes are
|
|
355
|
-
* in CSS pixels.
|
|
356
|
-
*/
|
|
357
|
-
canvasWidth?: number;
|
|
358
|
-
canvasHeight: number;
|
|
359
|
-
/**
|
|
360
|
-
* Block width: `full` (default) spans the editor; `text` aligns with the
|
|
361
|
-
* text column; `content` fits the shapes' horizontal extent. The editor
|
|
362
|
-
* omits `full` unless it was written explicitly (an insertion default or
|
|
363
|
-
* the source payload); unknown values are dropped.
|
|
364
|
-
*/
|
|
365
|
-
width?: BlockWidth;
|
|
366
|
-
shapes: readonly DrawingShape[];
|
|
367
|
-
}>;
|
|
368
|
-
declare const EMPTY_DRAWING: DrawingData;
|
|
369
|
-
declare const STROKE_COLORS: readonly ["#1e1e1e", "#e03131", "#2f9e44", "#1971c2", "#f08c00", "#7048e8"];
|
|
370
|
-
declare const FILL_COLORS: readonly ["transparent", "#ffc9c9", "#b2f2bb", "#a5d8ff", "#ffec99", "#d0bfff"];
|
|
371
|
-
/** Edge midpoints, used by the ```diagram skeleton's `side` option */
|
|
372
|
-
declare const SIDE_FIXED_POINTS: Record<BindingSide, readonly [number, number]>;
|
|
373
|
-
declare function serializeDrawingData(data: DrawingData): string;
|
|
374
|
-
/**
|
|
375
|
-
* Parse a ```drawing payload. Exactly one format is accepted: version 2 as
|
|
376
|
-
* written by the editor (the ```diagram skeleton is a separate block type,
|
|
377
|
-
* see skeleton.ts). Shapes that fail validation are dropped and a malformed
|
|
378
|
-
* document yields an empty canvas. Never throws.
|
|
379
|
-
*/
|
|
380
|
-
declare function parseDrawingData(json: string): DrawingData;
|
|
381
|
-
declare function normalizeDrawingData(parsed: unknown): DrawingData;
|
|
382
|
-
|
|
383
434
|
type SerializedDrawingNode = Spread<{
|
|
384
435
|
data: string;
|
|
385
436
|
}, SerializedLexicalNode>;
|
|
@@ -975,4 +1026,280 @@ type MermaidOptions = Readonly<{
|
|
|
975
1026
|
*/
|
|
976
1027
|
declare function drawingToMermaid(data: DrawingData, options?: MermaidOptions): string;
|
|
977
1028
|
|
|
978
|
-
|
|
1029
|
+
/**
|
|
1030
|
+
* `@lexical/markdown`'s CODE transformer, except that a block whose language
|
|
1031
|
+
* is the highlighter's default (`plain`, assigned to every untagged block)
|
|
1032
|
+
* exports as a bare ``` fence — markdown in, markdown out.
|
|
1033
|
+
*/
|
|
1034
|
+
declare const CODE_BLOCK: MultilineElementTransformer;
|
|
1035
|
+
|
|
1036
|
+
/** The built-in grammars. Importing this module registers them. */
|
|
1037
|
+
declare const BUILTIN_CODE_LANGUAGES: readonly [Readonly<{
|
|
1038
|
+
name: string;
|
|
1039
|
+
aliases?: readonly string[];
|
|
1040
|
+
rules: readonly CodeRule[];
|
|
1041
|
+
keywords?: readonly string[];
|
|
1042
|
+
builtins?: readonly string[];
|
|
1043
|
+
types?: readonly string[];
|
|
1044
|
+
constants?: readonly string[];
|
|
1045
|
+
identifier?: string;
|
|
1046
|
+
caseInsensitive?: boolean;
|
|
1047
|
+
callIsFunction?: boolean;
|
|
1048
|
+
capitalizedIsType?: boolean;
|
|
1049
|
+
}>, Readonly<{
|
|
1050
|
+
name: string;
|
|
1051
|
+
aliases?: readonly string[];
|
|
1052
|
+
rules: readonly CodeRule[];
|
|
1053
|
+
keywords?: readonly string[];
|
|
1054
|
+
builtins?: readonly string[];
|
|
1055
|
+
types?: readonly string[];
|
|
1056
|
+
constants?: readonly string[];
|
|
1057
|
+
identifier?: string;
|
|
1058
|
+
caseInsensitive?: boolean;
|
|
1059
|
+
callIsFunction?: boolean;
|
|
1060
|
+
capitalizedIsType?: boolean;
|
|
1061
|
+
}>, Readonly<{
|
|
1062
|
+
name: string;
|
|
1063
|
+
aliases?: readonly string[];
|
|
1064
|
+
rules: readonly CodeRule[];
|
|
1065
|
+
keywords?: readonly string[];
|
|
1066
|
+
builtins?: readonly string[];
|
|
1067
|
+
types?: readonly string[];
|
|
1068
|
+
constants?: readonly string[];
|
|
1069
|
+
identifier?: string;
|
|
1070
|
+
caseInsensitive?: boolean;
|
|
1071
|
+
callIsFunction?: boolean;
|
|
1072
|
+
capitalizedIsType?: boolean;
|
|
1073
|
+
}>, Readonly<{
|
|
1074
|
+
name: string;
|
|
1075
|
+
aliases?: readonly string[];
|
|
1076
|
+
rules: readonly CodeRule[];
|
|
1077
|
+
keywords?: readonly string[];
|
|
1078
|
+
builtins?: readonly string[];
|
|
1079
|
+
types?: readonly string[];
|
|
1080
|
+
constants?: readonly string[];
|
|
1081
|
+
identifier?: string;
|
|
1082
|
+
caseInsensitive?: boolean;
|
|
1083
|
+
callIsFunction?: boolean;
|
|
1084
|
+
capitalizedIsType?: boolean;
|
|
1085
|
+
}>, Readonly<{
|
|
1086
|
+
name: string;
|
|
1087
|
+
aliases?: readonly string[];
|
|
1088
|
+
rules: readonly CodeRule[];
|
|
1089
|
+
keywords?: readonly string[];
|
|
1090
|
+
builtins?: readonly string[];
|
|
1091
|
+
types?: readonly string[];
|
|
1092
|
+
constants?: readonly string[];
|
|
1093
|
+
identifier?: string;
|
|
1094
|
+
caseInsensitive?: boolean;
|
|
1095
|
+
callIsFunction?: boolean;
|
|
1096
|
+
capitalizedIsType?: boolean;
|
|
1097
|
+
}>, Readonly<{
|
|
1098
|
+
name: string;
|
|
1099
|
+
aliases?: readonly string[];
|
|
1100
|
+
rules: readonly CodeRule[];
|
|
1101
|
+
keywords?: readonly string[];
|
|
1102
|
+
builtins?: readonly string[];
|
|
1103
|
+
types?: readonly string[];
|
|
1104
|
+
constants?: readonly string[];
|
|
1105
|
+
identifier?: string;
|
|
1106
|
+
caseInsensitive?: boolean;
|
|
1107
|
+
callIsFunction?: boolean;
|
|
1108
|
+
capitalizedIsType?: boolean;
|
|
1109
|
+
}>, Readonly<{
|
|
1110
|
+
name: string;
|
|
1111
|
+
aliases?: readonly string[];
|
|
1112
|
+
rules: readonly CodeRule[];
|
|
1113
|
+
keywords?: readonly string[];
|
|
1114
|
+
builtins?: readonly string[];
|
|
1115
|
+
types?: readonly string[];
|
|
1116
|
+
constants?: readonly string[];
|
|
1117
|
+
identifier?: string;
|
|
1118
|
+
caseInsensitive?: boolean;
|
|
1119
|
+
callIsFunction?: boolean;
|
|
1120
|
+
capitalizedIsType?: boolean;
|
|
1121
|
+
}>, Readonly<{
|
|
1122
|
+
name: string;
|
|
1123
|
+
aliases?: readonly string[];
|
|
1124
|
+
rules: readonly CodeRule[];
|
|
1125
|
+
keywords?: readonly string[];
|
|
1126
|
+
builtins?: readonly string[];
|
|
1127
|
+
types?: readonly string[];
|
|
1128
|
+
constants?: readonly string[];
|
|
1129
|
+
identifier?: string;
|
|
1130
|
+
caseInsensitive?: boolean;
|
|
1131
|
+
callIsFunction?: boolean;
|
|
1132
|
+
capitalizedIsType?: boolean;
|
|
1133
|
+
}>, Readonly<{
|
|
1134
|
+
name: string;
|
|
1135
|
+
aliases?: readonly string[];
|
|
1136
|
+
rules: readonly CodeRule[];
|
|
1137
|
+
keywords?: readonly string[];
|
|
1138
|
+
builtins?: readonly string[];
|
|
1139
|
+
types?: readonly string[];
|
|
1140
|
+
constants?: readonly string[];
|
|
1141
|
+
identifier?: string;
|
|
1142
|
+
caseInsensitive?: boolean;
|
|
1143
|
+
callIsFunction?: boolean;
|
|
1144
|
+
capitalizedIsType?: boolean;
|
|
1145
|
+
}>, Readonly<{
|
|
1146
|
+
name: string;
|
|
1147
|
+
aliases?: readonly string[];
|
|
1148
|
+
rules: readonly CodeRule[];
|
|
1149
|
+
keywords?: readonly string[];
|
|
1150
|
+
builtins?: readonly string[];
|
|
1151
|
+
types?: readonly string[];
|
|
1152
|
+
constants?: readonly string[];
|
|
1153
|
+
identifier?: string;
|
|
1154
|
+
caseInsensitive?: boolean;
|
|
1155
|
+
callIsFunction?: boolean;
|
|
1156
|
+
capitalizedIsType?: boolean;
|
|
1157
|
+
}>, Readonly<{
|
|
1158
|
+
name: string;
|
|
1159
|
+
aliases?: readonly string[];
|
|
1160
|
+
rules: readonly CodeRule[];
|
|
1161
|
+
keywords?: readonly string[];
|
|
1162
|
+
builtins?: readonly string[];
|
|
1163
|
+
types?: readonly string[];
|
|
1164
|
+
constants?: readonly string[];
|
|
1165
|
+
identifier?: string;
|
|
1166
|
+
caseInsensitive?: boolean;
|
|
1167
|
+
callIsFunction?: boolean;
|
|
1168
|
+
capitalizedIsType?: boolean;
|
|
1169
|
+
}>, Readonly<{
|
|
1170
|
+
name: string;
|
|
1171
|
+
aliases?: readonly string[];
|
|
1172
|
+
rules: readonly CodeRule[];
|
|
1173
|
+
keywords?: readonly string[];
|
|
1174
|
+
builtins?: readonly string[];
|
|
1175
|
+
types?: readonly string[];
|
|
1176
|
+
constants?: readonly string[];
|
|
1177
|
+
identifier?: string;
|
|
1178
|
+
caseInsensitive?: boolean;
|
|
1179
|
+
callIsFunction?: boolean;
|
|
1180
|
+
capitalizedIsType?: boolean;
|
|
1181
|
+
}>, Readonly<{
|
|
1182
|
+
name: string;
|
|
1183
|
+
aliases?: readonly string[];
|
|
1184
|
+
rules: readonly CodeRule[];
|
|
1185
|
+
keywords?: readonly string[];
|
|
1186
|
+
builtins?: readonly string[];
|
|
1187
|
+
types?: readonly string[];
|
|
1188
|
+
constants?: readonly string[];
|
|
1189
|
+
identifier?: string;
|
|
1190
|
+
caseInsensitive?: boolean;
|
|
1191
|
+
callIsFunction?: boolean;
|
|
1192
|
+
capitalizedIsType?: boolean;
|
|
1193
|
+
}>, Readonly<{
|
|
1194
|
+
name: string;
|
|
1195
|
+
aliases?: readonly string[];
|
|
1196
|
+
rules: readonly CodeRule[];
|
|
1197
|
+
keywords?: readonly string[];
|
|
1198
|
+
builtins?: readonly string[];
|
|
1199
|
+
types?: readonly string[];
|
|
1200
|
+
constants?: readonly string[];
|
|
1201
|
+
identifier?: string;
|
|
1202
|
+
caseInsensitive?: boolean;
|
|
1203
|
+
callIsFunction?: boolean;
|
|
1204
|
+
capitalizedIsType?: boolean;
|
|
1205
|
+
}>, Readonly<{
|
|
1206
|
+
name: string;
|
|
1207
|
+
aliases?: readonly string[];
|
|
1208
|
+
rules: readonly CodeRule[];
|
|
1209
|
+
keywords?: readonly string[];
|
|
1210
|
+
builtins?: readonly string[];
|
|
1211
|
+
types?: readonly string[];
|
|
1212
|
+
constants?: readonly string[];
|
|
1213
|
+
identifier?: string;
|
|
1214
|
+
caseInsensitive?: boolean;
|
|
1215
|
+
callIsFunction?: boolean;
|
|
1216
|
+
capitalizedIsType?: boolean;
|
|
1217
|
+
}>];
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* Semantic token vocabulary for code highlighting. Closed on purpose: every
|
|
1221
|
+
* grammar maps its syntax onto these names, and the theme maps each name onto
|
|
1222
|
+
* one class (`zui-token-<type>`) and one color custom property
|
|
1223
|
+
* (`--zui-code-<type>`). Adding a language never adds a color.
|
|
1224
|
+
*/
|
|
1225
|
+
declare const CODE_TOKEN_TYPES: readonly ["comment", "string", "number", "keyword", "builtin", "type", "function", "property", "variable", "constant", "operator", "punctuation", "tag", "attr", "regex", "meta", "inserted", "deleted"];
|
|
1226
|
+
type CodeTokenType = (typeof CODE_TOKEN_TYPES)[number];
|
|
1227
|
+
/** A run of source text. `text` is uncolored (identifiers, whitespace, …). */
|
|
1228
|
+
type CodeToken = Readonly<{
|
|
1229
|
+
type: CodeTokenType | 'text';
|
|
1230
|
+
text: string;
|
|
1231
|
+
}>;
|
|
1232
|
+
/**
|
|
1233
|
+
* One lexer rule: a regular-expression *source* (no flags, no capturing
|
|
1234
|
+
* groups — use `(?:…)`, no backreferences) tried at the current position.
|
|
1235
|
+
* Rules are tried in order; the first one that matches wins.
|
|
1236
|
+
*/
|
|
1237
|
+
type CodeRule = Readonly<{
|
|
1238
|
+
type: CodeTokenType;
|
|
1239
|
+
match: string;
|
|
1240
|
+
}>;
|
|
1241
|
+
/**
|
|
1242
|
+
* A language definition. Pure data: the lexer compiles it once (cached per
|
|
1243
|
+
* object identity) and walks the source with it.
|
|
1244
|
+
*
|
|
1245
|
+
* Identifiers not consumed by a rule are classified by the word lists, then
|
|
1246
|
+
* by the two heuristics, and otherwise left as plain text.
|
|
1247
|
+
*/
|
|
1248
|
+
type CodeGrammar = Readonly<{
|
|
1249
|
+
/** Canonical name, as written after ``` in markdown */
|
|
1250
|
+
name: string;
|
|
1251
|
+
aliases?: readonly string[];
|
|
1252
|
+
rules: readonly CodeRule[];
|
|
1253
|
+
keywords?: readonly string[];
|
|
1254
|
+
builtins?: readonly string[];
|
|
1255
|
+
types?: readonly string[];
|
|
1256
|
+
constants?: readonly string[];
|
|
1257
|
+
/** Regex source for identifiers (default: `[A-Za-z_$][\w$]*`) */
|
|
1258
|
+
identifier?: string;
|
|
1259
|
+
/** Word lists and rules match case-insensitively (SQL) */
|
|
1260
|
+
caseInsensitive?: boolean;
|
|
1261
|
+
/** An identifier directly followed by `(` is a `function` */
|
|
1262
|
+
callIsFunction?: boolean;
|
|
1263
|
+
/**
|
|
1264
|
+
* A Capitalized identifier is a `type`; a SCREAMING_CASE one is a
|
|
1265
|
+
* `constant`
|
|
1266
|
+
*/
|
|
1267
|
+
capitalizedIsType?: boolean;
|
|
1268
|
+
}>;
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* Splits `code` into a flat list of tokens covering the whole input, in
|
|
1272
|
+
* order; adjacent tokens of the same type are merged. Never throws on user
|
|
1273
|
+
* input and always makes progress (an empty match counts as no match).
|
|
1274
|
+
*/
|
|
1275
|
+
declare function tokenizeCode(code: string, grammar: CodeGrammar): CodeToken[];
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* Language registry: canonical names and aliases, lower-cased, mapped to a
|
|
1279
|
+
* grammar. Unknown names resolve to `plain` (line structure, no colors) so
|
|
1280
|
+
* every fenced block gets the same editing behavior.
|
|
1281
|
+
*/
|
|
1282
|
+
declare const PLAIN_LANGUAGE = "plain";
|
|
1283
|
+
/** Adds (or replaces) a language. Call before the editor mounts. */
|
|
1284
|
+
declare function registerCodeLanguage(grammar: CodeGrammar): void;
|
|
1285
|
+
declare function hasCodeLanguage(name: string): boolean;
|
|
1286
|
+
/** Resolves a fence name (canonical, alias, or `diff-<lang>`) to a grammar. */
|
|
1287
|
+
declare function resolveCodeLanguage(name: string | null | undefined): CodeGrammar;
|
|
1288
|
+
/** Canonical names of every registered language, sorted */
|
|
1289
|
+
declare function getCodeLanguages(): string[];
|
|
1290
|
+
|
|
1291
|
+
type LexicalTokenizer = NonNullable<Parameters<typeof registerCodeHighlighting>[1]>;
|
|
1292
|
+
/**
|
|
1293
|
+
* The tokenizer handed to `@lexical/code`. It never touches Prism: the
|
|
1294
|
+
* registry's grammars produce the tokens, and `$tokenize` turns them into the
|
|
1295
|
+
* flat CodeHighlightNode / LineBreakNode / TabNode structure CodeNode expects.
|
|
1296
|
+
*/
|
|
1297
|
+
declare const codeTokenizer: LexicalTokenizer;
|
|
1298
|
+
/**
|
|
1299
|
+
* Registers syntax highlighting for every CodeNode in the editor, driven by
|
|
1300
|
+
* the language registry. Unknown languages render as plain text with the
|
|
1301
|
+
* same line structure, so editing behaves identically.
|
|
1302
|
+
*/
|
|
1303
|
+
declare function registerCodeBlockHighlighting(editor: LexicalEditor): () => void;
|
|
1304
|
+
|
|
1305
|
+
export { $createDrawingNode, $createFrontmatterNode, $getSelectedTable, $getTableDensity, $getTableSettings, $getTableWidth, $isDrawingNode, $isFrontmatterNode, $isTableWidthExplicit, $setTableDensity, $setTableSettings, $setTableWidth, BLOCK_WIDTHS, BOX_DEFINITIONS, BOX_TYPES, BUILTIN_CODE_LANGUAGES, type Binding, type BindingSide, type BlockWidth, type BlockWidthDefaults, type BoxDefinition, type BoxType, CODE_BLOCK, CODE_TOKEN_TYPES, COLOR_PRESETS, CONNECTOR_TYPES, type CodeGrammar, type CodeRule, type CodeToken, type CodeTokenType, type ColorName, type ConnectorType, DEFAULT_TABLE_SETTINGS, DIAGRAM, DRAWING, DRAWING_DATA_JSON_SCHEMA, DRAWING_SKELETON_JSON_SCHEMA, type DrawingData, DrawingNode, type DrawingShape, type DrawingShapeType, type DrawingSkeleton, type DrawingStyle, EMPTY_DRAWING, type EditorContentProps, type EditorMode, type EditorRootProps, FILL_COLORS, FRONTMATTER, FormatButtons, FrontmatterNode, HistoryButtons, type InkOptions, type InkStroke, InsertButtons, MarkdownEditor, type MarkdownEditorApi, type Props as MarkdownEditorProps, type MermaidDirection, type MermaidOptions, PLAIN_LANGUAGE, type Point, SHAPE_TYPES, SIDE_FIXED_POINTS, STROKE_COLORS, type SerializedDrawingNode, type SerializedFrontmatterNode, type SkeletonBox, type SkeletonConnector, type SkeletonEnd, type SkeletonText, TABLE, TABLE_WIDTH_MARKER, type TableDensity, type TableSettings, type TableSettingsOptions, type TextField, Toolbar, ToolbarButton, ToolbarDivider, type ToolbarItems, anchorPoint, bindEndpoints, boxOutline, codeTokenizer, connectorPoints, drawingToMermaid, expandSkeleton, findBoxAt, fixedPointFor, formatTableSettingsMarker, getCodeLanguages, hasCodeLanguage, inkAmplitude, inkFillOffset, inkStroke, isBlockWidth, isDrawingSkeleton, makeBinding, normalizeDrawingData, parseDrawingData, parseDrawingSkeleton, parseTableSettingsMarker, registerCodeBlockHighlighting, registerCodeLanguage, resolveBindings, resolveCodeLanguage, roundedPolyline, roundedRectPolygon, routeElbow, seedFrom, serializeDrawingData, tokenizeCode, useMarkdownEditor };
|