@wildix/uikit-handlebars 0.0.2
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/dist/components/input.d.ts +18 -0
- package/dist/components/input.d.ts.map +1 -0
- package/dist/components/input.js +90 -0
- package/dist/components/input.js.map +1 -0
- package/dist/components/lexical/context.d.ts +15 -0
- package/dist/components/lexical/context.d.ts.map +1 -0
- package/dist/components/lexical/context.js +10 -0
- package/dist/components/lexical/context.js.map +1 -0
- package/dist/components/lexical/extensions/HandlebarsDefaultsExtension.d.ts +4 -0
- package/dist/components/lexical/extensions/HandlebarsDefaultsExtension.d.ts.map +1 -0
- package/dist/components/lexical/extensions/HandlebarsDefaultsExtension.js +45 -0
- package/dist/components/lexical/extensions/HandlebarsDefaultsExtension.js.map +1 -0
- package/dist/components/lexical/extensions/HandlebarsSuggestionsExtension.d.ts +10 -0
- package/dist/components/lexical/extensions/HandlebarsSuggestionsExtension.d.ts.map +1 -0
- package/dist/components/lexical/extensions/HandlebarsSuggestionsExtension.js +352 -0
- package/dist/components/lexical/extensions/HandlebarsSuggestionsExtension.js.map +1 -0
- package/dist/components/lexical/extensions/HandlebarsVariableHighlightExtension.d.ts +10 -0
- package/dist/components/lexical/extensions/HandlebarsVariableHighlightExtension.d.ts.map +1 -0
- package/dist/components/lexical/extensions/HandlebarsVariableHighlightExtension.js +201 -0
- package/dist/components/lexical/extensions/HandlebarsVariableHighlightExtension.js.map +1 -0
- package/dist/components/lexical/handlebarsUtils.d.ts +22 -0
- package/dist/components/lexical/handlebarsUtils.d.ts.map +1 -0
- package/dist/components/lexical/handlebarsUtils.js +126 -0
- package/dist/components/lexical/handlebarsUtils.js.map +1 -0
- package/dist/components/lexical/helpers/setEditorText.d.ts +2 -0
- package/dist/components/lexical/helpers/setEditorText.d.ts.map +1 -0
- package/dist/components/lexical/helpers/setEditorText.js +10 -0
- package/dist/components/lexical/helpers/setEditorText.js.map +1 -0
- package/dist/components/lexical/nodes/HandlebarsHelperNode.d.ts +30 -0
- package/dist/components/lexical/nodes/HandlebarsHelperNode.d.ts.map +1 -0
- package/dist/components/lexical/nodes/HandlebarsHelperNode.js +89 -0
- package/dist/components/lexical/nodes/HandlebarsHelperNode.js.map +1 -0
- package/dist/components/lexical/nodes/HandlebarsVariableNode.d.ts +24 -0
- package/dist/components/lexical/nodes/HandlebarsVariableNode.d.ts.map +1 -0
- package/dist/components/lexical/nodes/HandlebarsVariableNode.js +61 -0
- package/dist/components/lexical/nodes/HandlebarsVariableNode.js.map +1 -0
- package/dist/components/lexical/plugins/AutoFocusPlugin.d.ts +2 -0
- package/dist/components/lexical/plugins/AutoFocusPlugin.d.ts.map +1 -0
- package/dist/components/lexical/plugins/AutoFocusPlugin.js +10 -0
- package/dist/components/lexical/plugins/AutoFocusPlugin.js.map +1 -0
- package/dist/components/lexical/plugins/ControlledValuePlugin.d.ts +7 -0
- package/dist/components/lexical/plugins/ControlledValuePlugin.d.ts.map +1 -0
- package/dist/components/lexical/plugins/ControlledValuePlugin.js +22 -0
- package/dist/components/lexical/plugins/ControlledValuePlugin.js.map +1 -0
- package/dist/components/lexical/plugins/DisabledValuePlugin.d.ts +6 -0
- package/dist/components/lexical/plugins/DisabledValuePlugin.d.ts.map +1 -0
- package/dist/components/lexical/plugins/DisabledValuePlugin.js +13 -0
- package/dist/components/lexical/plugins/DisabledValuePlugin.js.map +1 -0
- package/dist/components/textarea.d.ts +19 -0
- package/dist/components/textarea.d.ts.map +1 -0
- package/dist/components/textarea.js +83 -0
- package/dist/components/textarea.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface HandlebarsHelperConfig {
|
|
2
|
+
description?: string;
|
|
3
|
+
}
|
|
4
|
+
export interface HandlebarsVariableHighlightExtensionConfig {
|
|
5
|
+
variables?: string[];
|
|
6
|
+
helpers?: Record<string, HandlebarsHelperConfig>;
|
|
7
|
+
multiline?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const HandlebarsVariableHighlightExtension: (config?: HandlebarsVariableHighlightExtensionConfig) => import("lexical").LexicalExtension<import("lexical").ExtensionConfigBase, "@lexical/handlebars-variable-highlight", unknown, unknown>;
|
|
10
|
+
//# sourceMappingURL=HandlebarsVariableHighlightExtension.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HandlebarsVariableHighlightExtension.d.ts","sourceRoot":"","sources":["../../../../src/components/lexical/extensions/HandlebarsVariableHighlightExtension.tsx"],"names":[],"mappings":"AASA,MAAM,WAAW,sBAAsB;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,0CAA0C;IACzD,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IACjD,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAiND,eAAO,MAAM,oCAAoC,GAAI,SAAQ,0CAA+C,0IAiBxG,CAAC"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { $createTextNode, configExtension, defineExtension } from 'lexical';
|
|
2
|
+
import { isHandlebarsHelper, isPlainHandlebarsVariable } from '../handlebarsUtils';
|
|
3
|
+
import { $createHandlebarsHelperNode, HandlebarsHelperNode } from '../nodes/HandlebarsHelperNode';
|
|
4
|
+
import { $createHandlebarsVariableNode, HandlebarsVariableNode } from '../nodes/HandlebarsVariableNode';
|
|
5
|
+
import { $createCodeHighlightNode } from '@lexical/code';
|
|
6
|
+
import { CodeHighlighterShikiExtension, ShikiTokenizer } from '@lexical/code-shiki';
|
|
7
|
+
const getText = (n) => (typeof n?.getTextContent === 'function' ? n.getTextContent() : (n?.__text ?? ''));
|
|
8
|
+
function tokenizeHandlebars(rawNodes, config) {
|
|
9
|
+
// Pre-process nodes to split merged tokens that might confuse the parser.
|
|
10
|
+
// Shiki sometimes merges adjacent punctuation, e.g. `}}{{` or `}}}{{{`.
|
|
11
|
+
// We flatMap to split such nodes into separate components.
|
|
12
|
+
const nodes = rawNodes.flatMap((node) => {
|
|
13
|
+
const text = getText(node);
|
|
14
|
+
// Regex checks for any occurrence where one or more '}' are immediately followed by one or more '{'
|
|
15
|
+
if (/[}]+[{]+/.test(text)) {
|
|
16
|
+
const style = typeof node.getStyle === 'function' ? node.getStyle() : '';
|
|
17
|
+
const format = typeof node.getFormat === 'function' ? node.getFormat() : 0;
|
|
18
|
+
const detail = typeof node.getDetail === 'function' ? node.getDetail() : 0;
|
|
19
|
+
const mode = typeof node.getMode === 'function' ? node.getMode() : 0;
|
|
20
|
+
const parts = [];
|
|
21
|
+
let remaining = text;
|
|
22
|
+
// Iteratively split at the boundary between '}' and '{'
|
|
23
|
+
while (true) {
|
|
24
|
+
const match = /([}]+)([{]+)/.exec(remaining);
|
|
25
|
+
if (!match || match[1] == null) {
|
|
26
|
+
parts.push(remaining);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
// Split right after the closing braces
|
|
30
|
+
const splitIndex = match.index + match[1].length;
|
|
31
|
+
parts.push(remaining.slice(0, splitIndex));
|
|
32
|
+
remaining = remaining.slice(splitIndex);
|
|
33
|
+
}
|
|
34
|
+
return parts
|
|
35
|
+
.filter((p) => p.length > 0)
|
|
36
|
+
.map((part) => {
|
|
37
|
+
const n = $createCodeHighlightNode(part);
|
|
38
|
+
n.setStyle(style);
|
|
39
|
+
n.setFormat(format);
|
|
40
|
+
n.setDetail(detail);
|
|
41
|
+
n.setMode(mode);
|
|
42
|
+
return n;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return [node];
|
|
46
|
+
});
|
|
47
|
+
const result = [];
|
|
48
|
+
const { variables, helpers } = config;
|
|
49
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
50
|
+
const node = nodes[i];
|
|
51
|
+
const text = getText(node);
|
|
52
|
+
// Replace linebreaks with empty text nodes if not allowed in multiline mode.
|
|
53
|
+
if (config.multiline !== true && node.getType() === 'linebreak') {
|
|
54
|
+
result.push($createTextNode(''));
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
// Check for opening braces
|
|
58
|
+
let isTriple = false;
|
|
59
|
+
let isOpening = false;
|
|
60
|
+
if (text === '{{{') {
|
|
61
|
+
isOpening = true;
|
|
62
|
+
isTriple = true;
|
|
63
|
+
}
|
|
64
|
+
else if (text === '{{') {
|
|
65
|
+
isOpening = true;
|
|
66
|
+
// Check next token for 3rd brace (triple stash split case)
|
|
67
|
+
if (i + 1 < nodes.length && getText(nodes[i + 1]) === '{') {
|
|
68
|
+
isTriple = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (!isOpening) {
|
|
72
|
+
result.push(node);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
// We found a start. Attempt to find the matching end.
|
|
76
|
+
const openingTokens = [node];
|
|
77
|
+
let nextIndex = i + 1;
|
|
78
|
+
if (isTriple && text === '{{') {
|
|
79
|
+
// Consume the extra '{'
|
|
80
|
+
openingTokens.push(nodes[nextIndex]);
|
|
81
|
+
nextIndex++;
|
|
82
|
+
}
|
|
83
|
+
// Look ahead for closing
|
|
84
|
+
const innerTokens = [];
|
|
85
|
+
let foundEnd = false;
|
|
86
|
+
let closingTokens = [];
|
|
87
|
+
let newIndex = nextIndex;
|
|
88
|
+
for (let j = nextIndex; j < nodes.length; j++) {
|
|
89
|
+
const innerNode = nodes[j];
|
|
90
|
+
const innerText = getText(innerNode);
|
|
91
|
+
// Check for closing
|
|
92
|
+
if (isTriple) {
|
|
93
|
+
if (innerText === '}}}') {
|
|
94
|
+
foundEnd = true;
|
|
95
|
+
closingTokens = [innerNode];
|
|
96
|
+
newIndex = j;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
else if (innerText === '}}' && j + 1 < nodes.length && getText(nodes[j + 1]) === '}') {
|
|
100
|
+
// Split triple close case: '}}' + '}'
|
|
101
|
+
foundEnd = true;
|
|
102
|
+
closingTokens = [innerNode, nodes[j + 1]];
|
|
103
|
+
newIndex = j + 1;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// Double stash
|
|
109
|
+
if (innerText === '}}') {
|
|
110
|
+
foundEnd = true;
|
|
111
|
+
closingTokens = [innerNode];
|
|
112
|
+
newIndex = j;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
innerTokens.push(innerNode);
|
|
117
|
+
}
|
|
118
|
+
if (foundEnd) {
|
|
119
|
+
// We have a complete block
|
|
120
|
+
// 1. Push opening braces (preserve original styling/tokens)
|
|
121
|
+
result.push(...openingTokens);
|
|
122
|
+
// 2. Analyze inner content
|
|
123
|
+
const contentText = innerTokens.map(getText).join('');
|
|
124
|
+
const trimmed = contentText.trim();
|
|
125
|
+
let nodeToInsert = null;
|
|
126
|
+
if (trimmed.length > 0) {
|
|
127
|
+
// Check if it matches a Helper (has args or is a known helper)
|
|
128
|
+
// Strategy: Try Plain Variable first. If strictly a variable path, use VariableNode.
|
|
129
|
+
// Otherwise, check if it's a Helper.
|
|
130
|
+
if (isPlainHandlebarsVariable(trimmed)) {
|
|
131
|
+
const isDefined = variables ? variables.includes(trimmed) : undefined;
|
|
132
|
+
nodeToInsert = $createHandlebarsVariableNode(trimmed, isDefined);
|
|
133
|
+
}
|
|
134
|
+
else if (isHandlebarsHelper(trimmed)) {
|
|
135
|
+
// Parse parts manually to support "only one helper allowed" and "single variable arg" logic
|
|
136
|
+
const parts = trimmed.split(/\s+/).filter(Boolean);
|
|
137
|
+
const helperName = parts[0] ?? '';
|
|
138
|
+
const args = parts.slice(1);
|
|
139
|
+
// Validate validity based on:
|
|
140
|
+
// 1. Is helperName in config?
|
|
141
|
+
// 2. Is structure valid? (Exactly 1 argument required per requirement: {{helper variable}})
|
|
142
|
+
// 3. Is that argument a plain variable?
|
|
143
|
+
const isValidHelper = helperName
|
|
144
|
+
? (helpers ? Object.prototype.hasOwnProperty.call(helpers, helperName) : false)
|
|
145
|
+
: false;
|
|
146
|
+
let variableName;
|
|
147
|
+
let isVariableDefined;
|
|
148
|
+
let isValid = isValidHelper;
|
|
149
|
+
// Enforce strict single-argument rule for this implementation
|
|
150
|
+
if (args.length !== 1 || !helperName) {
|
|
151
|
+
isValid = false;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
const potentialVar = args[0];
|
|
155
|
+
if (isPlainHandlebarsVariable(potentialVar)) {
|
|
156
|
+
variableName = potentialVar;
|
|
157
|
+
isVariableDefined = variables ? variables.includes(potentialVar) : undefined;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
// Argument is not a simple variable (could be nested helper, string, etc.) -> Invalid per requirements
|
|
161
|
+
isValid = false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
nodeToInsert = $createHandlebarsHelperNode(trimmed, helperName, isValid, variableName, isVariableDefined);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (nodeToInsert) {
|
|
168
|
+
result.push(nodeToInsert);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
// Fallback: preserve inner tokens if we couldn't identify as Var/Helper
|
|
172
|
+
result.push(...innerTokens);
|
|
173
|
+
}
|
|
174
|
+
// 3. Push closing braces
|
|
175
|
+
result.push(...closingTokens);
|
|
176
|
+
// 4. Advance main loop to skip processed tokens
|
|
177
|
+
i = newIndex;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
// No closing found. Just push the start token and continue from next.
|
|
181
|
+
result.push(node);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
export const HandlebarsVariableHighlightExtension = (config = {}) => defineExtension({
|
|
187
|
+
name: '@lexical/handlebars-variable-highlight',
|
|
188
|
+
nodes: [HandlebarsVariableNode, HandlebarsHelperNode],
|
|
189
|
+
dependencies: [
|
|
190
|
+
configExtension(CodeHighlighterShikiExtension, {
|
|
191
|
+
defaultLanguage: 'handlebars',
|
|
192
|
+
defaultTheme: 'github-light',
|
|
193
|
+
$tokenize(codeNode) {
|
|
194
|
+
const nodes = ShikiTokenizer.$tokenize(codeNode, this.defaultLanguage);
|
|
195
|
+
console.log('nodes', JSON.stringify(nodes));
|
|
196
|
+
return tokenizeHandlebars(nodes, config);
|
|
197
|
+
},
|
|
198
|
+
}),
|
|
199
|
+
],
|
|
200
|
+
});
|
|
201
|
+
//# sourceMappingURL=HandlebarsVariableHighlightExtension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HandlebarsVariableHighlightExtension.js","sourceRoot":"","sources":["../../../../src/components/lexical/extensions/HandlebarsVariableHighlightExtension.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,eAAe,EAAE,eAAe,EAAC,MAAM,SAAS,CAAC;AAE1E,OAAO,EAAC,kBAAkB,EAAE,yBAAyB,EAAC,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAC,2BAA2B,EAAE,oBAAoB,EAAC,MAAM,+BAA+B,CAAC;AAChG,OAAO,EAAC,6BAA6B,EAAE,sBAAsB,EAAC,MAAM,iCAAiC,CAAC;AAEtG,OAAO,EAAC,wBAAwB,EAAC,MAAM,eAAe,CAAC;AACvD,OAAO,EAAC,6BAA6B,EAAE,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAYlF,MAAM,OAAO,GAAG,CAAC,CAAM,EAAU,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,cAAc,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;AAEvH,SAAS,kBAAkB,CAAC,QAAoB,EAAE,MAAkD;IAClG,0EAA0E;IAC1E,wEAAwE;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,CAAC,KAAK,CAAC,CAAC,CAAC;gBAE5C,OAAO,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAC3C,CAAC;SACF,CAAC;KACH;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true only for plain variable/path mustaches such as:
|
|
3
|
+
* - foo, this.bar, ../baz, @index, @root.user.name
|
|
4
|
+
* Excludes helpers, block/section, partials, comments, else, hashes, etc.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isPlainHandlebarsVariable(contentRaw: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Identifies triple-stash style {{{ ... }}} which we never consider a plain variable.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isTripleStash(raw: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Returns helper info if the mustache content is a helper invocation, e.g.:
|
|
13
|
+
* - jsonEscape id
|
|
14
|
+
* - formatDate user.createdAt 'YYYY-MM-DD'
|
|
15
|
+
* - helper with hash: myHelper a=1 b=2
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseHelperInfo(contentRaw: string): {
|
|
18
|
+
name: string;
|
|
19
|
+
argsCount: number;
|
|
20
|
+
} | null;
|
|
21
|
+
export declare function isHandlebarsHelper(contentRaw: string): boolean;
|
|
22
|
+
//# sourceMappingURL=handlebarsUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlebarsUtils.d.ts","sourceRoot":"","sources":["../../../src/components/lexical/handlebarsUtils.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CA2DrE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAIlD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAC,GAAG,IAAI,CA0D5F;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAE9D"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import Handlebars from 'handlebars';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true only for plain variable/path mustaches such as:
|
|
4
|
+
* - foo, this.bar, ../baz, @index, @root.user.name
|
|
5
|
+
* Excludes helpers, block/section, partials, comments, else, hashes, etc.
|
|
6
|
+
*/
|
|
7
|
+
export function isPlainHandlebarsVariable(contentRaw) {
|
|
8
|
+
const content = (contentRaw ?? '').trim();
|
|
9
|
+
if (!content)
|
|
10
|
+
return false;
|
|
11
|
+
// Do not treat references with `this` as plain variables (e.g., `this`, `this.name`)
|
|
12
|
+
// Also consider optional relative prefixes like `./` or `../`
|
|
13
|
+
if (/^(?:\.?\.\/)*this(?:\.|$)/.test(content)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
// Quick negative filters
|
|
17
|
+
if (content.startsWith('#') || // block start
|
|
18
|
+
content.startsWith('/') || // block end
|
|
19
|
+
content.startsWith('^') || // inverted section
|
|
20
|
+
content.startsWith('!') || // comment
|
|
21
|
+
content.startsWith('--') || // long comment
|
|
22
|
+
content.startsWith('>') || // partial
|
|
23
|
+
content === 'else') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
// Prefer Handlebars AST to decide
|
|
27
|
+
try {
|
|
28
|
+
const ast = Handlebars.parse(`{{${content}}}`);
|
|
29
|
+
const body = ast?.body ?? ast?.program?.body;
|
|
30
|
+
if (Array.isArray(body) && body.length === 1) {
|
|
31
|
+
const node = body[0];
|
|
32
|
+
if (node?.type === 'MustacheStatement') {
|
|
33
|
+
const hasParams = Array.isArray(node.params) && node.params.length > 0;
|
|
34
|
+
const hasHash = !!node.hash && Array.isArray(node.hash.pairs) && node.hash.pairs.length > 0;
|
|
35
|
+
const isPath = node.path?.type === 'PathExpression';
|
|
36
|
+
if (!hasParams && !hasHash && isPath) {
|
|
37
|
+
const original = node.path?.original ?? '';
|
|
38
|
+
if (/^(?:\.?\.\/)*this(?:\.|$)/.test(original))
|
|
39
|
+
return false;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// fall through to regex
|
|
47
|
+
}
|
|
48
|
+
// Fallback: strict path expression only (not helpers)
|
|
49
|
+
// Note: explicitly exclude `this` as a valid first identifier
|
|
50
|
+
const VARIABLE_FALLBACK_RE = /^(?:\.?\.\/)*(?:@(?:root|index|key)\.?)?[A-Za-z_][\w-]*(?:\.[A-Za-z_][\w-]*)*$/;
|
|
51
|
+
if (!VARIABLE_FALLBACK_RE.test(content))
|
|
52
|
+
return false;
|
|
53
|
+
const firstSegment = content
|
|
54
|
+
.replace(/^\.?\.\//, '')
|
|
55
|
+
.replace(/^\.\.\//, '')
|
|
56
|
+
.split(/[\.\s]/, 1)[0];
|
|
57
|
+
if (firstSegment === 'this')
|
|
58
|
+
return false;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Identifies triple-stash style {{{ ... }}} which we never consider a plain variable.
|
|
63
|
+
*/
|
|
64
|
+
export function isTripleStash(raw) {
|
|
65
|
+
const s = raw.trim();
|
|
66
|
+
return s.startsWith('{{{') || s.endsWith('}}}');
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Returns helper info if the mustache content is a helper invocation, e.g.:
|
|
70
|
+
* - jsonEscape id
|
|
71
|
+
* - formatDate user.createdAt 'YYYY-MM-DD'
|
|
72
|
+
* - helper with hash: myHelper a=1 b=2
|
|
73
|
+
*/
|
|
74
|
+
export function parseHelperInfo(contentRaw) {
|
|
75
|
+
const content = (contentRaw ?? '').trim();
|
|
76
|
+
if (!content)
|
|
77
|
+
return null;
|
|
78
|
+
// Exclude block helpers and special keywords from being detected as custom helpers
|
|
79
|
+
if (content.startsWith('#') || // block start
|
|
80
|
+
content.startsWith('/') || // block end
|
|
81
|
+
content.startsWith('^') || // inverted section
|
|
82
|
+
content.startsWith('!') || // comment
|
|
83
|
+
content.startsWith('--') || // long comment
|
|
84
|
+
content.startsWith('>') || // partial
|
|
85
|
+
content === 'else') {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const ast = Handlebars.parse(`{{${content}}}`);
|
|
90
|
+
const body = ast?.body ?? ast?.program?.body;
|
|
91
|
+
if (Array.isArray(body) && body.length === 1) {
|
|
92
|
+
const node = body[0];
|
|
93
|
+
if (node?.type === 'MustacheStatement') {
|
|
94
|
+
const isPath = node.path?.type === 'PathExpression';
|
|
95
|
+
const hasParams = Array.isArray(node.params) && node.params.length > 0;
|
|
96
|
+
const hasHash = !!node.hash && Array.isArray(node.hash.pairs) && node.hash.pairs.length > 0;
|
|
97
|
+
// Helper if there are any params or hash pairs, or if path is not a simple variable-like? We rely on params/hash here.
|
|
98
|
+
if (isPath && (hasParams || hasHash)) {
|
|
99
|
+
const name = node.path.original;
|
|
100
|
+
// Explicitly exclude 'this' if parsed as a helper name
|
|
101
|
+
if (name === 'this')
|
|
102
|
+
return null;
|
|
103
|
+
const argsCount = (node.params?.length ?? 0) + (node.hash?.pairs?.length ?? 0);
|
|
104
|
+
return { name, argsCount };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// ignore
|
|
111
|
+
}
|
|
112
|
+
// Fallback heuristic: treat first token as helper name if there is a whitespace (i.e., more than one token)
|
|
113
|
+
const parts = content.split(/\s+/).filter(Boolean);
|
|
114
|
+
if (parts.length > 1) {
|
|
115
|
+
// Explicitly exclude 'this' as a helper name
|
|
116
|
+
if (parts[0] === 'this')
|
|
117
|
+
return null;
|
|
118
|
+
const name = parts[0];
|
|
119
|
+
return { name, argsCount: parts.length - 1 };
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
export function isHandlebarsHelper(contentRaw) {
|
|
124
|
+
return parseHelperInfo(contentRaw) !== null;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=handlebarsUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlebarsUtils.js","sourceRoot":"","sources":["../../../src/components/lexical/handlebarsUtils.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,UAAkB;IAC1D,MAAM,OAAO,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1C,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAE3B,qFAAqF;IACrF,8DAA8D;IAC9D,IAAI,2BAA2B,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,yBAAyB;IACzB,IACE,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,cAAc;QACzC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,YAAY;QACvC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,mBAAmB;QAC9C,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,UAAU;QACrC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,eAAe;QAC3C,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,UAAU;QACrC,OAAO,KAAK,MAAM,EAClB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,kCAAkC;IAClC,IAAI,CAAC;QACH,MAAM,GAAG,GAAQ,UAAU,CAAC,KAAK,CAAC,KAAK,OAAO,IAAI,CAAC,CAAC;QACpD,MAAM,IAAI,GAAG,GAAG,EAAE,IAAI,IAAI,GAAG,EAAE,OA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CAAC,CAAC,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;QAErC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAW,CAAC;QAChC,OAAO,EAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,EAAC,CAAC;IAC7C,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,UAAkB;IACnD,OAAO,eAAe,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setEditorText.d.ts","sourceRoot":"","sources":["../../../../src/components/lexical/helpers/setEditorText.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,IAAI,EAAE,MAAM,QAMjD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { $getRoot } from 'lexical';
|
|
2
|
+
import { $createCodeHighlightNode, $createCodeNode } from '@lexical/code';
|
|
3
|
+
export default function setEditorText(text) {
|
|
4
|
+
const root = $getRoot();
|
|
5
|
+
root.clear();
|
|
6
|
+
const code = $createCodeNode('handlebars');
|
|
7
|
+
code.append($createCodeHighlightNode(text));
|
|
8
|
+
root.append(code);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=setEditorText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setEditorText.js","sourceRoot":"","sources":["../../../../src/components/lexical/helpers/setEditorText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAC,wBAAwB,EAAE,eAAe,EAAC,MAAM,eAAe,CAAC;AAExE,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,IAAY;IAChD,MAAM,IAAI,GAAG,QAAQ,EAAE,CAAC;IACxB,IAAI,CAAC,KAAK,EAAE,CAAC;IACb,MAAM,IAAI,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;IAC3C,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { EditorConfig, NodeKey, SerializedTextNode, Spread } from 'lexical';
|
|
2
|
+
import { CodeHighlightNode } from '@lexical/code';
|
|
3
|
+
type SerializedCodeHighlightNode = Spread<{
|
|
4
|
+
highlightType: string | null | undefined;
|
|
5
|
+
}, SerializedTextNode>;
|
|
6
|
+
export type SerializedHandlebarsHelperNode = Spread<{
|
|
7
|
+
type: 'handlebars-helper';
|
|
8
|
+
version: 1;
|
|
9
|
+
helperName: string;
|
|
10
|
+
variableName?: string;
|
|
11
|
+
isValid?: boolean;
|
|
12
|
+
isVariableDefined?: boolean;
|
|
13
|
+
}, SerializedCodeHighlightNode>;
|
|
14
|
+
export declare class HandlebarsHelperNode extends CodeHighlightNode {
|
|
15
|
+
__isValid?: boolean;
|
|
16
|
+
__isVariableDefined?: boolean;
|
|
17
|
+
__helperName: string;
|
|
18
|
+
__variableName?: string;
|
|
19
|
+
static getType(): string;
|
|
20
|
+
static clone(node: HandlebarsHelperNode): HandlebarsHelperNode;
|
|
21
|
+
constructor(text: string, helperName: string, variableName?: string, isValid?: boolean, isVariableDefined?: boolean, key?: NodeKey);
|
|
22
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
23
|
+
isTextEntity(): true;
|
|
24
|
+
static importJSON(serializedNode: SerializedHandlebarsHelperNode): HandlebarsHelperNode;
|
|
25
|
+
exportJSON(): SerializedHandlebarsHelperNode;
|
|
26
|
+
}
|
|
27
|
+
export declare function $createHandlebarsHelperNode(text: string, helperName: string, isValid?: boolean, variableName?: string, isVariableDefined?: boolean): HandlebarsHelperNode;
|
|
28
|
+
export declare function $isHandlebarsHelperNode(node: any): node is HandlebarsHelperNode;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=HandlebarsHelperNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HandlebarsHelperNode.d.ts","sourceRoot":"","sources":["../../../../src/components/lexical/nodes/HandlebarsHelperNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAC,MAAM,SAAS,CAAC;AAE/E,OAAO,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAEhD,KAAK,2BAA2B,GAAG,MAAM,CACvC;IACE,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CAC1C,EACD,kBAAkB,CACnB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG,MAAM,CACjD;IACE,IAAI,EAAE,mBAAmB,CAAC;IAC1B,OAAO,EAAE,CAAC,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,EACD,2BAA2B,CAC5B,CAAC;AAEF,qBAAa,oBAAqB,SAAQ,iBAAiB;IACzD,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B,YAAY,EAAE,MAAM,CAAC;IAErB,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,MAAM,CAAC,OAAO,IAAI,MAAM;IAIxB,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,oBAAoB,GAAG,oBAAoB;gBAY5D,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,YAAY,CAAC,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,OAAO,EACjB,iBAAiB,CAAC,EAAE,OAAO,EAC3B,GAAG,CAAC,EAAE,OAAO;IASf,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,WAAW;IA2C5C,YAAY,IAAI,IAAI;IAIpB,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,8BAA8B,GAAG,oBAAoB;IAgBvF,UAAU,IAAI,8BAA8B;CAW7C;AAED,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,OAAO,EACjB,YAAY,CAAC,EAAE,MAAM,EACrB,iBAAiB,CAAC,EAAE,OAAO,GAC1B,oBAAoB,CAEtB;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,IAAI,oBAAoB,CAE/E"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { CodeHighlightNode } from '@lexical/code';
|
|
2
|
+
export class HandlebarsHelperNode extends CodeHighlightNode {
|
|
3
|
+
__isValid;
|
|
4
|
+
__isVariableDefined;
|
|
5
|
+
__helperName;
|
|
6
|
+
__variableName;
|
|
7
|
+
static getType() {
|
|
8
|
+
return 'handlebars-helper';
|
|
9
|
+
}
|
|
10
|
+
static clone(node) {
|
|
11
|
+
return new HandlebarsHelperNode(node.__text, node.__helperName, node.__variableName, node.__isValid, node.__isVariableDefined, node.__key);
|
|
12
|
+
}
|
|
13
|
+
constructor(text, helperName, variableName, isValid, isVariableDefined, key) {
|
|
14
|
+
super(text, undefined, key);
|
|
15
|
+
this.__isValid = isValid;
|
|
16
|
+
this.__helperName = helperName;
|
|
17
|
+
this.__variableName = variableName;
|
|
18
|
+
this.__isVariableDefined = isVariableDefined;
|
|
19
|
+
}
|
|
20
|
+
createDOM(config) {
|
|
21
|
+
const dom = super.createDOM(config);
|
|
22
|
+
dom.classList.add('lexical-handlebars-helper');
|
|
23
|
+
dom.setAttribute('data-lexical-helper', this.__helperName);
|
|
24
|
+
if (this.__variableName) {
|
|
25
|
+
dom.setAttribute('data-lexical-helper-variable', this.__variableName);
|
|
26
|
+
}
|
|
27
|
+
// Styling for Helpers
|
|
28
|
+
if (this.__isValid === false) {
|
|
29
|
+
// Invalid/Unknown Helper or Invalid Syntax -> Red styling
|
|
30
|
+
dom.setAttribute('data-helper-valid', 'false');
|
|
31
|
+
dom.style.backgroundColor = 'rgba(239, 68, 68, 0.15)'; // red-500 @ 15%
|
|
32
|
+
dom.style.border = '1px solid rgba(239, 68, 68, 0.35)';
|
|
33
|
+
dom.title = `Invalid helper usage: ${this.__helperName}`;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// Valid Helper
|
|
37
|
+
// Check if the variable passed to it is defined
|
|
38
|
+
if (this.__isVariableDefined === false) {
|
|
39
|
+
// Valid Helper + Undefined Variable -> Yellow/Orange styling (Warning)
|
|
40
|
+
dom.setAttribute('data-helper-valid', 'warning');
|
|
41
|
+
dom.style.backgroundColor = 'rgba(234, 179, 8, 0.15)'; // yellow-500 @ 15%
|
|
42
|
+
dom.style.border = '1px solid rgba(234, 179, 8, 0.35)';
|
|
43
|
+
dom.style.color = 'rgb(161, 98, 7)'; // yellow-800
|
|
44
|
+
dom.title = `Helper: ${this.__helperName}, Variable '${this.__variableName}' is not defined`;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// Valid Helper + Valid Variable (or no variable) -> Blue/Indigo styling
|
|
48
|
+
dom.setAttribute('data-helper-valid', 'true');
|
|
49
|
+
dom.style.backgroundColor = 'rgba(99, 102, 241, 0.15)'; // indigo-500 @ 15%
|
|
50
|
+
dom.style.border = '1px solid rgba(79, 70, 229, 0.35)';
|
|
51
|
+
dom.style.color = 'rgb(49, 46, 129)'; // indigo-900
|
|
52
|
+
dom.title = `Helper: ${this.__helperName}`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
dom.style.borderRadius = '4px';
|
|
56
|
+
dom.style.padding = '0 2px';
|
|
57
|
+
dom.style.cursor = 'default';
|
|
58
|
+
return dom;
|
|
59
|
+
}
|
|
60
|
+
isTextEntity() {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
static importJSON(serializedNode) {
|
|
64
|
+
const node = $createHandlebarsHelperNode(serializedNode.text, serializedNode.helperName, serializedNode.isValid, serializedNode.variableName, serializedNode.isVariableDefined);
|
|
65
|
+
node.setFormat(serializedNode.format);
|
|
66
|
+
node.setDetail(serializedNode.detail);
|
|
67
|
+
node.setMode(serializedNode.mode);
|
|
68
|
+
node.setStyle(serializedNode.style);
|
|
69
|
+
return node;
|
|
70
|
+
}
|
|
71
|
+
exportJSON() {
|
|
72
|
+
return {
|
|
73
|
+
...super.exportJSON(),
|
|
74
|
+
type: 'handlebars-helper',
|
|
75
|
+
version: 1,
|
|
76
|
+
isValid: this.__isValid,
|
|
77
|
+
helperName: this.__helperName,
|
|
78
|
+
variableName: this.__variableName,
|
|
79
|
+
isVariableDefined: this.__isVariableDefined,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function $createHandlebarsHelperNode(text, helperName, isValid, variableName, isVariableDefined) {
|
|
84
|
+
return new HandlebarsHelperNode(text, helperName, variableName, isValid, isVariableDefined);
|
|
85
|
+
}
|
|
86
|
+
export function $isHandlebarsHelperNode(node) {
|
|
87
|
+
return node instanceof HandlebarsHelperNode;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=HandlebarsHelperNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HandlebarsHelperNode.js","sourceRoot":"","sources":["../../../../src/components/lexical/nodes/HandlebarsHelperNode.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAqBhD,MAAM,OAAO,oBAAqB,SAAQ,iBAAiB;IACzD,SAAS,CAAW;IAEpB,mBAAmB,CAAW;IAE9B,YAAY,CAAS;IAErB,cAAc,CAAU;IAExB,MAAM,CAAC,OAAO;QACZ,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAA0B;QACrC,OAAO,IAAI,oBAAoB,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OAAO,EACtB,cAAc,CAAC,YAAY,EAC3B,cAAc,CAAC,iBAAiB,CACjC,CAAC;QACF,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAEpC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,UAAU;QACR,OAAO;YACL,GAAG,KAAK,CAAC,UAAU,EAAE;YACrB,IAAI,EAAE,mBAAmB;YACzB,OAAO,EAAE,CAAC;YACV,OAAO,EAAE,IAAI,CAAC,SAAS;YACvB,UAAU,EAAE,IAAI,CAAC,YAAY;YAC7B,YAAY,EAAE,IAAI,CAAC,cAAc;YACjC,iBAAiB,EAAE,IAAI,CAAC,mBAAmB;SACV,CAAC;IACtC,CAAC;CACF;AAED,MAAM,UAAU,2BAA2B,CACzC,IAAY,EACZ,UAAkB,EAClB,OAAiB,EACjB,YAAqB,EACrB,iBAA2B;IAE3B,OAAO,IAAI,oBAAoB,CAAC,IAAI,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;AAC9F,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,IAAS;IAC/C,OAAO,IAAI,YAAY,oBAAoB,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EditorConfig, LexicalNode, NodeKey, SerializedTextNode, Spread } from 'lexical';
|
|
2
|
+
import { CodeHighlightNode } from '@lexical/code';
|
|
3
|
+
type SerializedCodeHighlightNode = Spread<{
|
|
4
|
+
highlightType: string | null | undefined;
|
|
5
|
+
}, SerializedTextNode>;
|
|
6
|
+
export type SerializedHandlebarsVariableNode = Spread<{
|
|
7
|
+
type: 'handlebars-variable';
|
|
8
|
+
version: 1;
|
|
9
|
+
isDefined?: boolean;
|
|
10
|
+
}, SerializedCodeHighlightNode>;
|
|
11
|
+
export declare class HandlebarsVariableNode extends CodeHighlightNode {
|
|
12
|
+
__isDefined?: boolean;
|
|
13
|
+
static getType(): string;
|
|
14
|
+
static clone(node: HandlebarsVariableNode): HandlebarsVariableNode;
|
|
15
|
+
constructor(text: string, key?: NodeKey, isDefined?: boolean);
|
|
16
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
17
|
+
isTextEntity(): true;
|
|
18
|
+
static importJSON(serializedNode: SerializedHandlebarsVariableNode): HandlebarsVariableNode;
|
|
19
|
+
exportJSON(): SerializedHandlebarsVariableNode;
|
|
20
|
+
}
|
|
21
|
+
export declare function $createHandlebarsVariableNode(name: string, isDefined?: boolean): HandlebarsVariableNode;
|
|
22
|
+
export declare function $isHandlebarsVariableNode(node: LexicalNode | null | undefined): node is HandlebarsVariableNode;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=HandlebarsVariableNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HandlebarsVariableNode.d.ts","sourceRoot":"","sources":["../../../../src/components/lexical/nodes/HandlebarsVariableNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAC,MAAM,SAAS,CAAC;AAEvF,OAAO,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAEhD,KAAK,2BAA2B,GAAG,MAAM,CACvC;IACE,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CAC1C,EACD,kBAAkB,CACnB,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG,MAAM,CACnD;IACE,IAAI,EAAE,qBAAqB,CAAC;IAC5B,OAAO,EAAE,CAAC,CAAC;IACX,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,EACD,2BAA2B,CAC5B,CAAC;AAEF,qBAAa,sBAAuB,SAAQ,iBAAiB;IAC3D,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,MAAM,CAAC,OAAO,IAAI,MAAM;IAIxB,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,sBAAsB,GAAG,sBAAsB;gBAItD,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO;IAK5D,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,WAAW;IAwB5C,YAAY,IAAI,IAAI;IAKpB,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,gCAAgC,GAAG,sBAAsB;IAU3F,UAAU,IAAI,gCAAgC;CAQ/C;AAED,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,sBAAsB,CAEvG;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,IAAI,sBAAsB,CAE9G"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CodeHighlightNode } from '@lexical/code';
|
|
2
|
+
export class HandlebarsVariableNode extends CodeHighlightNode {
|
|
3
|
+
__isDefined;
|
|
4
|
+
static getType() {
|
|
5
|
+
return 'handlebars-variable';
|
|
6
|
+
}
|
|
7
|
+
static clone(node) {
|
|
8
|
+
return new HandlebarsVariableNode(node.__text, node.__key, node.__isDefined);
|
|
9
|
+
}
|
|
10
|
+
constructor(text, key, isDefined) {
|
|
11
|
+
super(text, undefined, key);
|
|
12
|
+
this.__isDefined = isDefined;
|
|
13
|
+
}
|
|
14
|
+
createDOM(config) {
|
|
15
|
+
console.log('HandlebarsVariableNode createDOM', this);
|
|
16
|
+
const dom = super.createDOM(config);
|
|
17
|
+
// Apply a subtle tag-like appearance; consumer can override via CSS.
|
|
18
|
+
dom.classList.add('lexical-handlebars-variable');
|
|
19
|
+
dom.setAttribute('data-lexical-variable', this.getTextContent());
|
|
20
|
+
if (this.__isDefined === false) {
|
|
21
|
+
dom.setAttribute('data-variable-defined', 'false');
|
|
22
|
+
dom.style.backgroundColor = 'rgba(239, 68, 68, 0.15)'; // red
|
|
23
|
+
dom.style.border = '1px solid rgba(239, 68, 68, 0.35)';
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
// Default minimal styling so it is visible even without external CSS.
|
|
27
|
+
dom.style.backgroundColor = 'rgba(250,204,21,0.15)'; // amber-300 @ 15%
|
|
28
|
+
dom.style.border = '1px solid rgba(245,158,11,0.35)';
|
|
29
|
+
}
|
|
30
|
+
dom.style.borderRadius = '4px';
|
|
31
|
+
dom.style.padding = '0 2px';
|
|
32
|
+
return dom;
|
|
33
|
+
}
|
|
34
|
+
isTextEntity() {
|
|
35
|
+
// Treat as an entity so edits replace the whole token by default.
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
static importJSON(serializedNode) {
|
|
39
|
+
const node = $createHandlebarsVariableNode(serializedNode.text, serializedNode.isDefined);
|
|
40
|
+
node.setFormat(serializedNode.format);
|
|
41
|
+
node.setDetail(serializedNode.detail);
|
|
42
|
+
node.setMode(serializedNode.mode);
|
|
43
|
+
node.setStyle(serializedNode.style);
|
|
44
|
+
return node;
|
|
45
|
+
}
|
|
46
|
+
exportJSON() {
|
|
47
|
+
return {
|
|
48
|
+
...super.exportJSON(),
|
|
49
|
+
type: 'handlebars-variable',
|
|
50
|
+
version: 1,
|
|
51
|
+
isDefined: this.__isDefined,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function $createHandlebarsVariableNode(name, isDefined) {
|
|
56
|
+
return new HandlebarsVariableNode(name, undefined, isDefined);
|
|
57
|
+
}
|
|
58
|
+
export function $isHandlebarsVariableNode(node) {
|
|
59
|
+
return node instanceof HandlebarsVariableNode;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=HandlebarsVariableNode.js.map
|