@zuilib/text-editor 0.7.2 → 0.8.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 +15 -0
- package/dist/index.d.ts +278 -1
- package/dist/index.js +1477 -75
- package/dist/styles.css +72 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog — @zuilib/text-editor
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
- **Syntax highlighting** for fenced code blocks, driven by the package's
|
|
6
|
+
own grammars instead of Prism: JavaScript/TypeScript, Kotlin, Java, C/C++,
|
|
7
|
+
Python, Go, Rust, JSON, YAML, shell, SQL, CSS, HTML/XML, diff and
|
|
8
|
+
markdown. Colors are CSS custom properties (`--zui-code-<type>` on
|
|
9
|
+
`.zui-code`) with light and dark defaults; override them to retheme.
|
|
10
|
+
`registerCodeLanguage(grammar)` adds a language from a data-only grammar;
|
|
11
|
+
`tokenizeCode` and `codeTokenizer` are exported for reuse
|
|
12
|
+
- Untagged code blocks are highlighted as `plain` and export as a bare
|
|
13
|
+
``` fence (previously they came back as ```javascript). `CODE_BLOCK` is
|
|
14
|
+
the exported transformer that does this
|
|
15
|
+
- Unknown languages get the same line structure as known ones, so cursor
|
|
16
|
+
movement and indentation behave identically
|
|
17
|
+
|
|
3
18
|
## 0.7.2
|
|
4
19
|
|
|
5
20
|
- 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:
|
|
@@ -975,4 +976,280 @@ type MermaidOptions = Readonly<{
|
|
|
975
976
|
*/
|
|
976
977
|
declare function drawingToMermaid(data: DrawingData, options?: MermaidOptions): string;
|
|
977
978
|
|
|
978
|
-
|
|
979
|
+
/**
|
|
980
|
+
* `@lexical/markdown`'s CODE transformer, except that a block whose language
|
|
981
|
+
* is the highlighter's default (`plain`, assigned to every untagged block)
|
|
982
|
+
* exports as a bare ``` fence — markdown in, markdown out.
|
|
983
|
+
*/
|
|
984
|
+
declare const CODE_BLOCK: MultilineElementTransformer;
|
|
985
|
+
|
|
986
|
+
/** The built-in grammars. Importing this module registers them. */
|
|
987
|
+
declare const BUILTIN_CODE_LANGUAGES: readonly [Readonly<{
|
|
988
|
+
name: string;
|
|
989
|
+
aliases?: readonly string[];
|
|
990
|
+
rules: readonly CodeRule[];
|
|
991
|
+
keywords?: readonly string[];
|
|
992
|
+
builtins?: readonly string[];
|
|
993
|
+
types?: readonly string[];
|
|
994
|
+
constants?: readonly string[];
|
|
995
|
+
identifier?: string;
|
|
996
|
+
caseInsensitive?: boolean;
|
|
997
|
+
callIsFunction?: boolean;
|
|
998
|
+
capitalizedIsType?: boolean;
|
|
999
|
+
}>, Readonly<{
|
|
1000
|
+
name: string;
|
|
1001
|
+
aliases?: readonly string[];
|
|
1002
|
+
rules: readonly CodeRule[];
|
|
1003
|
+
keywords?: readonly string[];
|
|
1004
|
+
builtins?: readonly string[];
|
|
1005
|
+
types?: readonly string[];
|
|
1006
|
+
constants?: readonly string[];
|
|
1007
|
+
identifier?: string;
|
|
1008
|
+
caseInsensitive?: boolean;
|
|
1009
|
+
callIsFunction?: boolean;
|
|
1010
|
+
capitalizedIsType?: boolean;
|
|
1011
|
+
}>, Readonly<{
|
|
1012
|
+
name: string;
|
|
1013
|
+
aliases?: readonly string[];
|
|
1014
|
+
rules: readonly CodeRule[];
|
|
1015
|
+
keywords?: readonly string[];
|
|
1016
|
+
builtins?: readonly string[];
|
|
1017
|
+
types?: readonly string[];
|
|
1018
|
+
constants?: readonly string[];
|
|
1019
|
+
identifier?: string;
|
|
1020
|
+
caseInsensitive?: boolean;
|
|
1021
|
+
callIsFunction?: boolean;
|
|
1022
|
+
capitalizedIsType?: boolean;
|
|
1023
|
+
}>, Readonly<{
|
|
1024
|
+
name: string;
|
|
1025
|
+
aliases?: readonly string[];
|
|
1026
|
+
rules: readonly CodeRule[];
|
|
1027
|
+
keywords?: readonly string[];
|
|
1028
|
+
builtins?: readonly string[];
|
|
1029
|
+
types?: readonly string[];
|
|
1030
|
+
constants?: readonly string[];
|
|
1031
|
+
identifier?: string;
|
|
1032
|
+
caseInsensitive?: boolean;
|
|
1033
|
+
callIsFunction?: boolean;
|
|
1034
|
+
capitalizedIsType?: boolean;
|
|
1035
|
+
}>, Readonly<{
|
|
1036
|
+
name: string;
|
|
1037
|
+
aliases?: readonly string[];
|
|
1038
|
+
rules: readonly CodeRule[];
|
|
1039
|
+
keywords?: readonly string[];
|
|
1040
|
+
builtins?: readonly string[];
|
|
1041
|
+
types?: readonly string[];
|
|
1042
|
+
constants?: readonly string[];
|
|
1043
|
+
identifier?: string;
|
|
1044
|
+
caseInsensitive?: boolean;
|
|
1045
|
+
callIsFunction?: boolean;
|
|
1046
|
+
capitalizedIsType?: boolean;
|
|
1047
|
+
}>, Readonly<{
|
|
1048
|
+
name: string;
|
|
1049
|
+
aliases?: readonly string[];
|
|
1050
|
+
rules: readonly CodeRule[];
|
|
1051
|
+
keywords?: readonly string[];
|
|
1052
|
+
builtins?: readonly string[];
|
|
1053
|
+
types?: readonly string[];
|
|
1054
|
+
constants?: readonly string[];
|
|
1055
|
+
identifier?: string;
|
|
1056
|
+
caseInsensitive?: boolean;
|
|
1057
|
+
callIsFunction?: boolean;
|
|
1058
|
+
capitalizedIsType?: boolean;
|
|
1059
|
+
}>, Readonly<{
|
|
1060
|
+
name: string;
|
|
1061
|
+
aliases?: readonly string[];
|
|
1062
|
+
rules: readonly CodeRule[];
|
|
1063
|
+
keywords?: readonly string[];
|
|
1064
|
+
builtins?: readonly string[];
|
|
1065
|
+
types?: readonly string[];
|
|
1066
|
+
constants?: readonly string[];
|
|
1067
|
+
identifier?: string;
|
|
1068
|
+
caseInsensitive?: boolean;
|
|
1069
|
+
callIsFunction?: boolean;
|
|
1070
|
+
capitalizedIsType?: boolean;
|
|
1071
|
+
}>, Readonly<{
|
|
1072
|
+
name: string;
|
|
1073
|
+
aliases?: readonly string[];
|
|
1074
|
+
rules: readonly CodeRule[];
|
|
1075
|
+
keywords?: readonly string[];
|
|
1076
|
+
builtins?: readonly string[];
|
|
1077
|
+
types?: readonly string[];
|
|
1078
|
+
constants?: readonly string[];
|
|
1079
|
+
identifier?: string;
|
|
1080
|
+
caseInsensitive?: boolean;
|
|
1081
|
+
callIsFunction?: boolean;
|
|
1082
|
+
capitalizedIsType?: boolean;
|
|
1083
|
+
}>, Readonly<{
|
|
1084
|
+
name: string;
|
|
1085
|
+
aliases?: readonly string[];
|
|
1086
|
+
rules: readonly CodeRule[];
|
|
1087
|
+
keywords?: readonly string[];
|
|
1088
|
+
builtins?: readonly string[];
|
|
1089
|
+
types?: readonly string[];
|
|
1090
|
+
constants?: readonly string[];
|
|
1091
|
+
identifier?: string;
|
|
1092
|
+
caseInsensitive?: boolean;
|
|
1093
|
+
callIsFunction?: boolean;
|
|
1094
|
+
capitalizedIsType?: boolean;
|
|
1095
|
+
}>, Readonly<{
|
|
1096
|
+
name: string;
|
|
1097
|
+
aliases?: readonly string[];
|
|
1098
|
+
rules: readonly CodeRule[];
|
|
1099
|
+
keywords?: readonly string[];
|
|
1100
|
+
builtins?: readonly string[];
|
|
1101
|
+
types?: readonly string[];
|
|
1102
|
+
constants?: readonly string[];
|
|
1103
|
+
identifier?: string;
|
|
1104
|
+
caseInsensitive?: boolean;
|
|
1105
|
+
callIsFunction?: boolean;
|
|
1106
|
+
capitalizedIsType?: boolean;
|
|
1107
|
+
}>, Readonly<{
|
|
1108
|
+
name: string;
|
|
1109
|
+
aliases?: readonly string[];
|
|
1110
|
+
rules: readonly CodeRule[];
|
|
1111
|
+
keywords?: readonly string[];
|
|
1112
|
+
builtins?: readonly string[];
|
|
1113
|
+
types?: readonly string[];
|
|
1114
|
+
constants?: readonly string[];
|
|
1115
|
+
identifier?: string;
|
|
1116
|
+
caseInsensitive?: boolean;
|
|
1117
|
+
callIsFunction?: boolean;
|
|
1118
|
+
capitalizedIsType?: boolean;
|
|
1119
|
+
}>, Readonly<{
|
|
1120
|
+
name: string;
|
|
1121
|
+
aliases?: readonly string[];
|
|
1122
|
+
rules: readonly CodeRule[];
|
|
1123
|
+
keywords?: readonly string[];
|
|
1124
|
+
builtins?: readonly string[];
|
|
1125
|
+
types?: readonly string[];
|
|
1126
|
+
constants?: readonly string[];
|
|
1127
|
+
identifier?: string;
|
|
1128
|
+
caseInsensitive?: boolean;
|
|
1129
|
+
callIsFunction?: boolean;
|
|
1130
|
+
capitalizedIsType?: boolean;
|
|
1131
|
+
}>, Readonly<{
|
|
1132
|
+
name: string;
|
|
1133
|
+
aliases?: readonly string[];
|
|
1134
|
+
rules: readonly CodeRule[];
|
|
1135
|
+
keywords?: readonly string[];
|
|
1136
|
+
builtins?: readonly string[];
|
|
1137
|
+
types?: readonly string[];
|
|
1138
|
+
constants?: readonly string[];
|
|
1139
|
+
identifier?: string;
|
|
1140
|
+
caseInsensitive?: boolean;
|
|
1141
|
+
callIsFunction?: boolean;
|
|
1142
|
+
capitalizedIsType?: boolean;
|
|
1143
|
+
}>, Readonly<{
|
|
1144
|
+
name: string;
|
|
1145
|
+
aliases?: readonly string[];
|
|
1146
|
+
rules: readonly CodeRule[];
|
|
1147
|
+
keywords?: readonly string[];
|
|
1148
|
+
builtins?: readonly string[];
|
|
1149
|
+
types?: readonly string[];
|
|
1150
|
+
constants?: readonly string[];
|
|
1151
|
+
identifier?: string;
|
|
1152
|
+
caseInsensitive?: boolean;
|
|
1153
|
+
callIsFunction?: boolean;
|
|
1154
|
+
capitalizedIsType?: boolean;
|
|
1155
|
+
}>, Readonly<{
|
|
1156
|
+
name: string;
|
|
1157
|
+
aliases?: readonly string[];
|
|
1158
|
+
rules: readonly CodeRule[];
|
|
1159
|
+
keywords?: readonly string[];
|
|
1160
|
+
builtins?: readonly string[];
|
|
1161
|
+
types?: readonly string[];
|
|
1162
|
+
constants?: readonly string[];
|
|
1163
|
+
identifier?: string;
|
|
1164
|
+
caseInsensitive?: boolean;
|
|
1165
|
+
callIsFunction?: boolean;
|
|
1166
|
+
capitalizedIsType?: boolean;
|
|
1167
|
+
}>];
|
|
1168
|
+
|
|
1169
|
+
/**
|
|
1170
|
+
* Semantic token vocabulary for code highlighting. Closed on purpose: every
|
|
1171
|
+
* grammar maps its syntax onto these names, and the theme maps each name onto
|
|
1172
|
+
* one class (`zui-token-<type>`) and one color custom property
|
|
1173
|
+
* (`--zui-code-<type>`). Adding a language never adds a color.
|
|
1174
|
+
*/
|
|
1175
|
+
declare const CODE_TOKEN_TYPES: readonly ["comment", "string", "number", "keyword", "builtin", "type", "function", "property", "variable", "constant", "operator", "punctuation", "tag", "attr", "regex", "meta", "inserted", "deleted"];
|
|
1176
|
+
type CodeTokenType = (typeof CODE_TOKEN_TYPES)[number];
|
|
1177
|
+
/** A run of source text. `text` is uncolored (identifiers, whitespace, …). */
|
|
1178
|
+
type CodeToken = Readonly<{
|
|
1179
|
+
type: CodeTokenType | 'text';
|
|
1180
|
+
text: string;
|
|
1181
|
+
}>;
|
|
1182
|
+
/**
|
|
1183
|
+
* One lexer rule: a regular-expression *source* (no flags, no capturing
|
|
1184
|
+
* groups — use `(?:…)`, no backreferences) tried at the current position.
|
|
1185
|
+
* Rules are tried in order; the first one that matches wins.
|
|
1186
|
+
*/
|
|
1187
|
+
type CodeRule = Readonly<{
|
|
1188
|
+
type: CodeTokenType;
|
|
1189
|
+
match: string;
|
|
1190
|
+
}>;
|
|
1191
|
+
/**
|
|
1192
|
+
* A language definition. Pure data: the lexer compiles it once (cached per
|
|
1193
|
+
* object identity) and walks the source with it.
|
|
1194
|
+
*
|
|
1195
|
+
* Identifiers not consumed by a rule are classified by the word lists, then
|
|
1196
|
+
* by the two heuristics, and otherwise left as plain text.
|
|
1197
|
+
*/
|
|
1198
|
+
type CodeGrammar = Readonly<{
|
|
1199
|
+
/** Canonical name, as written after ``` in markdown */
|
|
1200
|
+
name: string;
|
|
1201
|
+
aliases?: readonly string[];
|
|
1202
|
+
rules: readonly CodeRule[];
|
|
1203
|
+
keywords?: readonly string[];
|
|
1204
|
+
builtins?: readonly string[];
|
|
1205
|
+
types?: readonly string[];
|
|
1206
|
+
constants?: readonly string[];
|
|
1207
|
+
/** Regex source for identifiers (default: `[A-Za-z_$][\w$]*`) */
|
|
1208
|
+
identifier?: string;
|
|
1209
|
+
/** Word lists and rules match case-insensitively (SQL) */
|
|
1210
|
+
caseInsensitive?: boolean;
|
|
1211
|
+
/** An identifier directly followed by `(` is a `function` */
|
|
1212
|
+
callIsFunction?: boolean;
|
|
1213
|
+
/**
|
|
1214
|
+
* A Capitalized identifier is a `type`; a SCREAMING_CASE one is a
|
|
1215
|
+
* `constant`
|
|
1216
|
+
*/
|
|
1217
|
+
capitalizedIsType?: boolean;
|
|
1218
|
+
}>;
|
|
1219
|
+
|
|
1220
|
+
/**
|
|
1221
|
+
* Splits `code` into a flat list of tokens covering the whole input, in
|
|
1222
|
+
* order; adjacent tokens of the same type are merged. Never throws on user
|
|
1223
|
+
* input and always makes progress (an empty match counts as no match).
|
|
1224
|
+
*/
|
|
1225
|
+
declare function tokenizeCode(code: string, grammar: CodeGrammar): CodeToken[];
|
|
1226
|
+
|
|
1227
|
+
/**
|
|
1228
|
+
* Language registry: canonical names and aliases, lower-cased, mapped to a
|
|
1229
|
+
* grammar. Unknown names resolve to `plain` (line structure, no colors) so
|
|
1230
|
+
* every fenced block gets the same editing behavior.
|
|
1231
|
+
*/
|
|
1232
|
+
declare const PLAIN_LANGUAGE = "plain";
|
|
1233
|
+
/** Adds (or replaces) a language. Call before the editor mounts. */
|
|
1234
|
+
declare function registerCodeLanguage(grammar: CodeGrammar): void;
|
|
1235
|
+
declare function hasCodeLanguage(name: string): boolean;
|
|
1236
|
+
/** Resolves a fence name (canonical, alias, or `diff-<lang>`) to a grammar. */
|
|
1237
|
+
declare function resolveCodeLanguage(name: string | null | undefined): CodeGrammar;
|
|
1238
|
+
/** Canonical names of every registered language, sorted */
|
|
1239
|
+
declare function getCodeLanguages(): string[];
|
|
1240
|
+
|
|
1241
|
+
type LexicalTokenizer = NonNullable<Parameters<typeof registerCodeHighlighting>[1]>;
|
|
1242
|
+
/**
|
|
1243
|
+
* The tokenizer handed to `@lexical/code`. It never touches Prism: the
|
|
1244
|
+
* registry's grammars produce the tokens, and `$tokenize` turns them into the
|
|
1245
|
+
* flat CodeHighlightNode / LineBreakNode / TabNode structure CodeNode expects.
|
|
1246
|
+
*/
|
|
1247
|
+
declare const codeTokenizer: LexicalTokenizer;
|
|
1248
|
+
/**
|
|
1249
|
+
* Registers syntax highlighting for every CodeNode in the editor, driven by
|
|
1250
|
+
* the language registry. Unknown languages render as plain text with the
|
|
1251
|
+
* same line structure, so editing behaves identically.
|
|
1252
|
+
*/
|
|
1253
|
+
declare function registerCodeBlockHighlighting(editor: LexicalEditor): () => void;
|
|
1254
|
+
|
|
1255
|
+
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, EMPTY_DRAWING, type EditorContentProps, type EditorMode, type EditorRootProps, FILL_COLORS, FRONTMATTER, FormatButtons, FrontmatterNode, HistoryButtons, 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, isBlockWidth, isDrawingSkeleton, makeBinding, normalizeDrawingData, parseDrawingData, parseDrawingSkeleton, parseTableSettingsMarker, registerCodeBlockHighlighting, registerCodeLanguage, resolveBindings, resolveCodeLanguage, routeElbow, serializeDrawingData, tokenizeCode, useMarkdownEditor };
|