@pixerate/editor 0.1.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/LICENSE +21 -0
- package/dist/extensions/index.cjs +616 -0
- package/dist/extensions/index.cjs.map +1 -0
- package/dist/extensions/index.d.cts +84 -0
- package/dist/extensions/index.d.ts +84 -0
- package/dist/extensions/index.js +571 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/grammar/index.cjs +401 -0
- package/dist/grammar/index.cjs.map +1 -0
- package/dist/grammar/index.d.cts +65 -0
- package/dist/grammar/index.d.ts +65 -0
- package/dist/grammar/index.js +359 -0
- package/dist/grammar/index.js.map +1 -0
- package/dist/index.cjs +1149 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +49 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +1082 -0
- package/dist/index.js.map +1 -0
- package/dist/serializers/index.cjs +83 -0
- package/dist/serializers/index.cjs.map +1 -0
- package/dist/serializers/index.d.cts +20 -0
- package/dist/serializers/index.d.ts +20 -0
- package/dist/serializers/index.js +53 -0
- package/dist/serializers/index.js.map +1 -0
- package/dist/tokens-CE6SS_hd.d.cts +37 -0
- package/dist/tokens-CE6SS_hd.d.ts +37 -0
- package/package.json +66 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
ColorHighlighter: () => ColorHighlighter,
|
|
34
|
+
EditorController: () => EditorController,
|
|
35
|
+
FontSize: () => FontSize,
|
|
36
|
+
GradientText: () => GradientText,
|
|
37
|
+
INSTRUCTION_REGEX: () => INSTRUCTION_REGEX,
|
|
38
|
+
LoadingNode: () => LoadingNode,
|
|
39
|
+
SlashCommands: () => SlashCommands,
|
|
40
|
+
SmilieReplacer: () => SmilieReplacer,
|
|
41
|
+
TEMPLATE_REGEX: () => TEMPLATE_REGEX,
|
|
42
|
+
TemplateSuggestions: () => TemplateSuggestions,
|
|
43
|
+
VARIABLE_REGEX: () => VARIABLE_REGEX,
|
|
44
|
+
createEditor: () => createEditor,
|
|
45
|
+
createRichTextPreset: () => createRichTextPreset,
|
|
46
|
+
escapeHtml: () => escapeHtml,
|
|
47
|
+
extractInstructionNames: () => extractInstructionNames,
|
|
48
|
+
extractTemplateNames: () => extractTemplateNames,
|
|
49
|
+
extractVariableNames: () => extractVariableNames,
|
|
50
|
+
findHexColors: () => findHexColors,
|
|
51
|
+
getEditorText: () => getEditorText,
|
|
52
|
+
getLatestVersion: () => getLatestVersion,
|
|
53
|
+
htmlToPlainText: () => htmlToPlainText,
|
|
54
|
+
instructionRegex: () => instructionRegex,
|
|
55
|
+
mapRawOffsetToResolved: () => mapRawOffsetToResolved,
|
|
56
|
+
mapResolvedOffsetToRaw: () => mapResolvedOffsetToRaw,
|
|
57
|
+
plainTextToTipTapHtml: () => plainTextToTipTapHtml,
|
|
58
|
+
resolveTemplates: () => resolveTemplates,
|
|
59
|
+
resolveTemplatesWithMapping: () => resolveTemplatesWithMapping,
|
|
60
|
+
resolveVariables: () => resolveVariables,
|
|
61
|
+
templateRegex: () => templateRegex,
|
|
62
|
+
tokenizePrompt: () => tokenizePrompt,
|
|
63
|
+
variableRegex: () => variableRegex
|
|
64
|
+
});
|
|
65
|
+
module.exports = __toCommonJS(src_exports);
|
|
66
|
+
|
|
67
|
+
// src/grammar/tokens.ts
|
|
68
|
+
var TEMPLATE_REGEX = /{{\s*([^}]+?)\s*}}/g;
|
|
69
|
+
var VARIABLE_REGEX = /(?<!\{)\{([^{}]+)\}(?!\})/g;
|
|
70
|
+
var INSTRUCTION_REGEX = /__(.+?)__/g;
|
|
71
|
+
var templateRegex = TEMPLATE_REGEX;
|
|
72
|
+
var variableRegex = VARIABLE_REGEX;
|
|
73
|
+
var instructionRegex = INSTRUCTION_REGEX;
|
|
74
|
+
|
|
75
|
+
// src/grammar/tokenizer.ts
|
|
76
|
+
function tokenizePrompt(text) {
|
|
77
|
+
if (!text) {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
const rawMatches = [];
|
|
81
|
+
const tmplRegex = new RegExp(TEMPLATE_REGEX.source, TEMPLATE_REGEX.flags);
|
|
82
|
+
let match;
|
|
83
|
+
while ((match = tmplRegex.exec(text)) !== null) {
|
|
84
|
+
rawMatches.push({
|
|
85
|
+
type: "template",
|
|
86
|
+
raw: match[0],
|
|
87
|
+
value: match[1].trim(),
|
|
88
|
+
start: match.index,
|
|
89
|
+
end: match.index + match[0].length
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const varRegex = new RegExp(VARIABLE_REGEX.source, VARIABLE_REGEX.flags);
|
|
93
|
+
while ((match = varRegex.exec(text)) !== null) {
|
|
94
|
+
const start = match.index;
|
|
95
|
+
const end = start + match[0].length;
|
|
96
|
+
const overlaps = rawMatches.some(
|
|
97
|
+
(m) => !(end <= m.start || start >= m.end)
|
|
98
|
+
);
|
|
99
|
+
if (!overlaps) {
|
|
100
|
+
rawMatches.push({
|
|
101
|
+
type: "variable",
|
|
102
|
+
raw: match[0],
|
|
103
|
+
value: match[1].trim(),
|
|
104
|
+
start,
|
|
105
|
+
end
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const instRegex = new RegExp(
|
|
110
|
+
INSTRUCTION_REGEX.source,
|
|
111
|
+
INSTRUCTION_REGEX.flags
|
|
112
|
+
);
|
|
113
|
+
while ((match = instRegex.exec(text)) !== null) {
|
|
114
|
+
const start = match.index;
|
|
115
|
+
const end = start + match[0].length;
|
|
116
|
+
const overlaps = rawMatches.some(
|
|
117
|
+
(m) => !(end <= m.start || start >= m.end)
|
|
118
|
+
);
|
|
119
|
+
if (!overlaps) {
|
|
120
|
+
rawMatches.push({
|
|
121
|
+
type: "instruction",
|
|
122
|
+
raw: match[0],
|
|
123
|
+
value: match[1].trim(),
|
|
124
|
+
start,
|
|
125
|
+
end
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
rawMatches.sort((a, b) => a.start - b.start);
|
|
130
|
+
const tokens = [];
|
|
131
|
+
let currentIdx = 0;
|
|
132
|
+
for (const m of rawMatches) {
|
|
133
|
+
if (m.start > currentIdx) {
|
|
134
|
+
const textChunk = text.slice(currentIdx, m.start);
|
|
135
|
+
tokens.push({
|
|
136
|
+
type: "text",
|
|
137
|
+
raw: textChunk,
|
|
138
|
+
value: textChunk,
|
|
139
|
+
start: currentIdx,
|
|
140
|
+
end: m.start
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
tokens.push({
|
|
144
|
+
type: m.type,
|
|
145
|
+
raw: m.raw,
|
|
146
|
+
value: m.value,
|
|
147
|
+
start: m.start,
|
|
148
|
+
end: m.end
|
|
149
|
+
});
|
|
150
|
+
currentIdx = m.end;
|
|
151
|
+
}
|
|
152
|
+
if (currentIdx < text.length) {
|
|
153
|
+
const textChunk = text.slice(currentIdx);
|
|
154
|
+
tokens.push({
|
|
155
|
+
type: "text",
|
|
156
|
+
raw: textChunk,
|
|
157
|
+
value: textChunk,
|
|
158
|
+
start: currentIdx,
|
|
159
|
+
end: text.length
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return tokens;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/grammar/resolver.ts
|
|
166
|
+
function getLatestVersion(template) {
|
|
167
|
+
if (!template.versions || template.versions.length === 0) {
|
|
168
|
+
if (template.body !== void 0) {
|
|
169
|
+
return {
|
|
170
|
+
id: template.id || "default",
|
|
171
|
+
version: "1.0",
|
|
172
|
+
body: template.body
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return void 0;
|
|
176
|
+
}
|
|
177
|
+
if (template.latestVersion) {
|
|
178
|
+
const found = template.versions.find(
|
|
179
|
+
(v) => v.version === template.latestVersion
|
|
180
|
+
);
|
|
181
|
+
if (found) return found;
|
|
182
|
+
}
|
|
183
|
+
return template.versions[template.versions.length - 1];
|
|
184
|
+
}
|
|
185
|
+
function resolveTemplates(text, templates = [], options) {
|
|
186
|
+
const templateMap = /* @__PURE__ */ new Map();
|
|
187
|
+
for (const t of templates) {
|
|
188
|
+
templateMap.set(t.name, t);
|
|
189
|
+
}
|
|
190
|
+
const maxDepth = options?.maxDepth ?? 10;
|
|
191
|
+
function resolveRecursive(currentText, visited, depth) {
|
|
192
|
+
if (depth > maxDepth) {
|
|
193
|
+
return "[Template max depth exceeded]";
|
|
194
|
+
}
|
|
195
|
+
let result = currentText;
|
|
196
|
+
const regex = new RegExp(TEMPLATE_REGEX.source, TEMPLATE_REGEX.flags);
|
|
197
|
+
let match;
|
|
198
|
+
while ((match = regex.exec(result)) !== null) {
|
|
199
|
+
const [fullMatch, rawTemplateName] = match;
|
|
200
|
+
const templateName = rawTemplateName.trim();
|
|
201
|
+
if (visited.has(templateName)) {
|
|
202
|
+
return "[Template loop detected]";
|
|
203
|
+
}
|
|
204
|
+
const template = templateMap.get(templateName);
|
|
205
|
+
if (!template) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
let versionBody;
|
|
209
|
+
const boundVersionId = options?.bindings?.[templateName];
|
|
210
|
+
if (boundVersionId && template.versions) {
|
|
211
|
+
const boundVersion = template.versions.find(
|
|
212
|
+
(v) => v.id === boundVersionId || v.version === boundVersionId
|
|
213
|
+
);
|
|
214
|
+
versionBody = boundVersion?.body;
|
|
215
|
+
} else {
|
|
216
|
+
const latest = getLatestVersion(template);
|
|
217
|
+
versionBody = latest?.body ?? template.body;
|
|
218
|
+
}
|
|
219
|
+
if (versionBody === void 0) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
const nextVisited = new Set(visited);
|
|
223
|
+
nextVisited.add(templateName);
|
|
224
|
+
const resolvedBody = resolveRecursive(
|
|
225
|
+
versionBody,
|
|
226
|
+
nextVisited,
|
|
227
|
+
depth + 1
|
|
228
|
+
);
|
|
229
|
+
if (resolvedBody === "[Template loop detected]" || resolvedBody === "[Template max depth exceeded]") {
|
|
230
|
+
return resolvedBody;
|
|
231
|
+
}
|
|
232
|
+
result = result.replace(fullMatch, resolvedBody);
|
|
233
|
+
regex.lastIndex = 0;
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
return resolveRecursive(text, /* @__PURE__ */ new Set(), 0);
|
|
238
|
+
}
|
|
239
|
+
function resolveVariables(text, values) {
|
|
240
|
+
if (!text) return "";
|
|
241
|
+
return text.replace(
|
|
242
|
+
new RegExp(VARIABLE_REGEX.source, VARIABLE_REGEX.flags),
|
|
243
|
+
(fullMatch, varName) => {
|
|
244
|
+
const key = varName.trim();
|
|
245
|
+
if (Object.prototype.hasOwnProperty.call(values, key)) {
|
|
246
|
+
return String(values[key]);
|
|
247
|
+
}
|
|
248
|
+
return fullMatch;
|
|
249
|
+
}
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
function extractTemplateNames(text) {
|
|
253
|
+
if (!text) return [];
|
|
254
|
+
const set = /* @__PURE__ */ new Set();
|
|
255
|
+
const regex = new RegExp(TEMPLATE_REGEX.source, TEMPLATE_REGEX.flags);
|
|
256
|
+
let match;
|
|
257
|
+
while ((match = regex.exec(text)) !== null) {
|
|
258
|
+
set.add(match[1].trim());
|
|
259
|
+
}
|
|
260
|
+
return Array.from(set);
|
|
261
|
+
}
|
|
262
|
+
function extractVariableNames(text) {
|
|
263
|
+
if (!text) return [];
|
|
264
|
+
const set = /* @__PURE__ */ new Set();
|
|
265
|
+
const regex = new RegExp(VARIABLE_REGEX.source, VARIABLE_REGEX.flags);
|
|
266
|
+
let match;
|
|
267
|
+
while ((match = regex.exec(text)) !== null) {
|
|
268
|
+
set.add(match[1].trim());
|
|
269
|
+
}
|
|
270
|
+
return Array.from(set);
|
|
271
|
+
}
|
|
272
|
+
function extractInstructionNames(text) {
|
|
273
|
+
if (!text) return [];
|
|
274
|
+
const set = /* @__PURE__ */ new Set();
|
|
275
|
+
const regex = new RegExp(INSTRUCTION_REGEX.source, INSTRUCTION_REGEX.flags);
|
|
276
|
+
let match;
|
|
277
|
+
while ((match = regex.exec(text)) !== null) {
|
|
278
|
+
set.add(match[1].trim());
|
|
279
|
+
}
|
|
280
|
+
return Array.from(set);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/grammar/sourcemap.ts
|
|
284
|
+
function resolveTemplatesWithMapping(text, templates = [], templateBindings) {
|
|
285
|
+
if (!templates || templates.length === 0 || !text.includes("{{")) {
|
|
286
|
+
return {
|
|
287
|
+
text,
|
|
288
|
+
map: [
|
|
289
|
+
{
|
|
290
|
+
resolvedStart: 0,
|
|
291
|
+
resolvedEnd: text.length,
|
|
292
|
+
source: "raw",
|
|
293
|
+
rawStart: 0,
|
|
294
|
+
rawEnd: text.length
|
|
295
|
+
}
|
|
296
|
+
]
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
const templateMap = new Map(templates.map((t) => [t.name, t]));
|
|
300
|
+
const regex = /{{\s*([^}]+?)\s*}}/g;
|
|
301
|
+
let match;
|
|
302
|
+
let lastIndex = 0;
|
|
303
|
+
let resolvedText = "";
|
|
304
|
+
const map = [];
|
|
305
|
+
while ((match = regex.exec(text)) !== null) {
|
|
306
|
+
const [fullMatch, rawTemplateName] = match;
|
|
307
|
+
const templateName = rawTemplateName.trim();
|
|
308
|
+
const matchIndex = match.index;
|
|
309
|
+
if (matchIndex > lastIndex) {
|
|
310
|
+
const rawSegment = text.substring(lastIndex, matchIndex);
|
|
311
|
+
map.push({
|
|
312
|
+
resolvedStart: resolvedText.length,
|
|
313
|
+
resolvedEnd: resolvedText.length + rawSegment.length,
|
|
314
|
+
source: "raw",
|
|
315
|
+
rawStart: lastIndex,
|
|
316
|
+
rawEnd: matchIndex
|
|
317
|
+
});
|
|
318
|
+
resolvedText += rawSegment;
|
|
319
|
+
}
|
|
320
|
+
let resolvedBody = fullMatch;
|
|
321
|
+
let isTemplate = false;
|
|
322
|
+
if (templateMap.has(templateName)) {
|
|
323
|
+
const template = templateMap.get(templateName);
|
|
324
|
+
let versionBody;
|
|
325
|
+
const boundVersionId = templateBindings?.[templateName];
|
|
326
|
+
if (boundVersionId && template.versions) {
|
|
327
|
+
const boundVersion = template.versions.find(
|
|
328
|
+
(v) => v.id === boundVersionId || v.version === boundVersionId
|
|
329
|
+
);
|
|
330
|
+
versionBody = boundVersion?.body;
|
|
331
|
+
} else {
|
|
332
|
+
const latestVersion = getLatestVersion(template);
|
|
333
|
+
versionBody = latestVersion?.body ?? template.body;
|
|
334
|
+
}
|
|
335
|
+
if (versionBody !== void 0) {
|
|
336
|
+
resolvedBody = resolveTemplates(versionBody, templates, {
|
|
337
|
+
bindings: templateBindings
|
|
338
|
+
});
|
|
339
|
+
isTemplate = true;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (isTemplate) {
|
|
343
|
+
map.push({
|
|
344
|
+
resolvedStart: resolvedText.length,
|
|
345
|
+
resolvedEnd: resolvedText.length + resolvedBody.length,
|
|
346
|
+
source: "template",
|
|
347
|
+
rawStart: matchIndex,
|
|
348
|
+
rawEnd: matchIndex + fullMatch.length,
|
|
349
|
+
templateName
|
|
350
|
+
});
|
|
351
|
+
resolvedText += resolvedBody;
|
|
352
|
+
} else {
|
|
353
|
+
map.push({
|
|
354
|
+
resolvedStart: resolvedText.length,
|
|
355
|
+
resolvedEnd: resolvedText.length + fullMatch.length,
|
|
356
|
+
source: "raw",
|
|
357
|
+
rawStart: matchIndex,
|
|
358
|
+
rawEnd: matchIndex + fullMatch.length
|
|
359
|
+
});
|
|
360
|
+
resolvedText += fullMatch;
|
|
361
|
+
}
|
|
362
|
+
lastIndex = matchIndex + fullMatch.length;
|
|
363
|
+
}
|
|
364
|
+
if (lastIndex < text.length) {
|
|
365
|
+
const rawSegment = text.substring(lastIndex);
|
|
366
|
+
map.push({
|
|
367
|
+
resolvedStart: resolvedText.length,
|
|
368
|
+
resolvedEnd: resolvedText.length + rawSegment.length,
|
|
369
|
+
source: "raw",
|
|
370
|
+
rawStart: lastIndex,
|
|
371
|
+
rawEnd: text.length
|
|
372
|
+
});
|
|
373
|
+
resolvedText += rawSegment;
|
|
374
|
+
}
|
|
375
|
+
return { text: resolvedText, map };
|
|
376
|
+
}
|
|
377
|
+
function mapResolvedOffsetToRaw(resolvedOffset, map) {
|
|
378
|
+
for (let i = 0; i < map.length; i++) {
|
|
379
|
+
const seg = map[i];
|
|
380
|
+
const isLast = i === map.length - 1;
|
|
381
|
+
const inRange = isLast ? resolvedOffset >= seg.resolvedStart && resolvedOffset <= seg.resolvedEnd : resolvedOffset >= seg.resolvedStart && resolvedOffset < seg.resolvedEnd;
|
|
382
|
+
if (inRange) {
|
|
383
|
+
if (seg.source === "raw") {
|
|
384
|
+
return seg.rawStart + (resolvedOffset - seg.resolvedStart);
|
|
385
|
+
} else {
|
|
386
|
+
return seg.rawStart;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return resolvedOffset;
|
|
391
|
+
}
|
|
392
|
+
function mapRawOffsetToResolved(rawOffset, map) {
|
|
393
|
+
for (let i = 0; i < map.length; i++) {
|
|
394
|
+
const seg = map[i];
|
|
395
|
+
const isLast = i === map.length - 1;
|
|
396
|
+
const inRange = isLast ? rawOffset >= seg.rawStart && rawOffset <= seg.rawEnd : rawOffset >= seg.rawStart && rawOffset < seg.rawEnd;
|
|
397
|
+
if (inRange) {
|
|
398
|
+
if (seg.source === "raw") {
|
|
399
|
+
return seg.resolvedStart + (rawOffset - seg.rawStart);
|
|
400
|
+
} else {
|
|
401
|
+
return seg.resolvedStart;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return rawOffset;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// src/extensions/gradient-text.ts
|
|
409
|
+
var import_core = require("@tiptap/core");
|
|
410
|
+
var import_state = require("@tiptap/pm/state");
|
|
411
|
+
var import_view = require("@tiptap/pm/view");
|
|
412
|
+
var createGradientDecorations = (doc, options) => {
|
|
413
|
+
const decorations = [];
|
|
414
|
+
const speed = options.speed ?? 1;
|
|
415
|
+
const jsonVarSet = options.jsonVariables ? options.jsonVariables instanceof Set ? options.jsonVariables : new Set(options.jsonVariables) : null;
|
|
416
|
+
doc.descendants((node, pos) => {
|
|
417
|
+
if (node.isText) {
|
|
418
|
+
const text = node.text || "";
|
|
419
|
+
let match;
|
|
420
|
+
const tmplRegex = new RegExp(TEMPLATE_REGEX.source, TEMPLATE_REGEX.flags);
|
|
421
|
+
while ((match = tmplRegex.exec(text)) !== null) {
|
|
422
|
+
const templateName = match[1].trim();
|
|
423
|
+
const colors = options.templateColorMap?.get(templateName);
|
|
424
|
+
if (colors) {
|
|
425
|
+
const start = pos + match.index;
|
|
426
|
+
const end = start + match[0].length;
|
|
427
|
+
const { from: colorFrom, to: colorTo } = colors;
|
|
428
|
+
const style = `--bg-size: ${speed * 300}%; --color-from: ${colorFrom}; --color-to: ${colorTo}; caret-color: #111 !important;`;
|
|
429
|
+
decorations.push(
|
|
430
|
+
import_view.Decoration.inline(start, end, {
|
|
431
|
+
class: "inline animate-gradient bg-gradient-to-r from-[var(--color-from)] via-[var(--color-to)] to-[var(--color-from)] bg-[length:var(--bg-size)_100%] bg-clip-text text-transparent border border-(--color-to)/20 px-1 py-0.5 rounded-sm cursor-pointer",
|
|
432
|
+
style,
|
|
433
|
+
"data-template": templateName
|
|
434
|
+
})
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
const instRegex = new RegExp(
|
|
439
|
+
INSTRUCTION_REGEX.source,
|
|
440
|
+
INSTRUCTION_REGEX.flags
|
|
441
|
+
);
|
|
442
|
+
while ((match = instRegex.exec(text)) !== null) {
|
|
443
|
+
const content = match[1].trim();
|
|
444
|
+
const colors = options.templateColorMap?.get(content) || {
|
|
445
|
+
from: "#ffaa40",
|
|
446
|
+
to: "#9c40ff"
|
|
447
|
+
};
|
|
448
|
+
const start = pos + match.index;
|
|
449
|
+
const end = start + match[0].length;
|
|
450
|
+
const { from: colorFrom, to: colorTo } = colors;
|
|
451
|
+
const style = `--bg-size: ${speed * 300}%; --color-from: ${colorFrom}; --color-to: ${colorTo}; caret-color: #111 !important;`;
|
|
452
|
+
decorations.push(
|
|
453
|
+
import_view.Decoration.inline(start, end, {
|
|
454
|
+
class: "italic animate-gradient bg-gradient-to-r from-rose-400 from-50% to-violet-500 to-50% bg-size-[200%_100%] bg-clip-text text-transparent inline-flex items-baseline gap-0.5",
|
|
455
|
+
style
|
|
456
|
+
})
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
const varRegex = new RegExp(
|
|
460
|
+
VARIABLE_REGEX.source,
|
|
461
|
+
VARIABLE_REGEX.flags
|
|
462
|
+
);
|
|
463
|
+
while ((match = varRegex.exec(text)) !== null) {
|
|
464
|
+
const variableName = match[1].trim();
|
|
465
|
+
const start = pos + match.index;
|
|
466
|
+
const end = start + match[0].length;
|
|
467
|
+
const isJsonVar = jsonVarSet?.has(variableName);
|
|
468
|
+
decorations.push(
|
|
469
|
+
import_view.Decoration.inline(start, end, {
|
|
470
|
+
class: isJsonVar ? "bg-violet-400/40 border-b-4 border-rose-300 dark:border-rose-800 inline-flex items-baseline px-1 py-0 text-foreground/80 gap-0.5 rounded-xs" : "bg-rose-400/40 border-b-4 border-violet-300 dark:border-violet-800 inline-flex items-baseline px-1 py-0 text-foreground/80 gap-0.5 rounded-xs",
|
|
471
|
+
"data-variable": variableName
|
|
472
|
+
})
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
return decorations;
|
|
478
|
+
};
|
|
479
|
+
var GradientText = import_core.Mark.create({
|
|
480
|
+
name: "gradientText",
|
|
481
|
+
addOptions() {
|
|
482
|
+
return {
|
|
483
|
+
templateColorMap: /* @__PURE__ */ new Map(),
|
|
484
|
+
speed: 1,
|
|
485
|
+
jsonVariables: void 0,
|
|
486
|
+
onTemplateClick: void 0
|
|
487
|
+
};
|
|
488
|
+
},
|
|
489
|
+
renderHTML({ HTMLAttributes }) {
|
|
490
|
+
const defaultColors = {
|
|
491
|
+
from: "#ffaa40",
|
|
492
|
+
to: "#9c40ff"
|
|
493
|
+
};
|
|
494
|
+
const speed = this.options.speed ?? 1;
|
|
495
|
+
const style = `--bg-size: ${speed * 300}%; --color-from: ${defaultColors.from}; --color-to: ${defaultColors.to}; caret-color: #111 !important;`;
|
|
496
|
+
return [
|
|
497
|
+
"span",
|
|
498
|
+
{
|
|
499
|
+
class: "inline animate-gradient bg-gradient-to-r from-[var(--color-from)] via-[var(--color-to)] to-[var(--color-from)] bg-[length:var(--bg-size)_100%] bg-clip-text text-transparent",
|
|
500
|
+
style,
|
|
501
|
+
...HTMLAttributes
|
|
502
|
+
},
|
|
503
|
+
0
|
|
504
|
+
];
|
|
505
|
+
},
|
|
506
|
+
parseHTML() {
|
|
507
|
+
return [
|
|
508
|
+
{
|
|
509
|
+
tag: "span",
|
|
510
|
+
getAttrs: (node) => node.classList.contains("animate-gradient") && node.classList.contains("bg-clip-text") && null
|
|
511
|
+
}
|
|
512
|
+
];
|
|
513
|
+
},
|
|
514
|
+
addProseMirrorPlugins() {
|
|
515
|
+
const markOptions = this.options;
|
|
516
|
+
return [
|
|
517
|
+
new import_state.Plugin({
|
|
518
|
+
state: {
|
|
519
|
+
init(_, { doc }) {
|
|
520
|
+
return import_view.DecorationSet.create(
|
|
521
|
+
doc,
|
|
522
|
+
createGradientDecorations(doc, markOptions)
|
|
523
|
+
);
|
|
524
|
+
},
|
|
525
|
+
apply(tr, value) {
|
|
526
|
+
const newDoc = tr.doc;
|
|
527
|
+
if (tr.docChanged) {
|
|
528
|
+
return import_view.DecorationSet.create(
|
|
529
|
+
newDoc,
|
|
530
|
+
createGradientDecorations(newDoc, markOptions)
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
return value.map(tr.mapping, newDoc);
|
|
534
|
+
}
|
|
535
|
+
},
|
|
536
|
+
props: {
|
|
537
|
+
decorations(state) {
|
|
538
|
+
return this.getState(state);
|
|
539
|
+
},
|
|
540
|
+
handleClickOn(view, pos, _node, _nodePos, event) {
|
|
541
|
+
const decorationSet = this.getState(
|
|
542
|
+
view.state
|
|
543
|
+
);
|
|
544
|
+
const decorations = decorationSet.find(pos, pos + 1);
|
|
545
|
+
for (const decoration of decorations) {
|
|
546
|
+
const decorationWithAttrs = decoration;
|
|
547
|
+
const templateName = decorationWithAttrs.type?.attrs?.["data-template"];
|
|
548
|
+
if (templateName) {
|
|
549
|
+
if (markOptions.onTemplateClick) {
|
|
550
|
+
markOptions.onTemplateClick(templateName, event);
|
|
551
|
+
}
|
|
552
|
+
if (typeof window !== "undefined") {
|
|
553
|
+
window.dispatchEvent(
|
|
554
|
+
new CustomEvent("show-gradient-popover", {
|
|
555
|
+
detail: {
|
|
556
|
+
templateName,
|
|
557
|
+
target: event.target
|
|
558
|
+
}
|
|
559
|
+
})
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
return true;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
})
|
|
569
|
+
];
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
// src/extensions/slash-commands.ts
|
|
574
|
+
var import_core2 = require("@tiptap/core");
|
|
575
|
+
var import_state2 = require("@tiptap/pm/state");
|
|
576
|
+
var SlashCommands = import_core2.Extension.create({
|
|
577
|
+
name: "slashCommands",
|
|
578
|
+
addOptions() {
|
|
579
|
+
return {
|
|
580
|
+
trigger: "/",
|
|
581
|
+
onMatch: void 0,
|
|
582
|
+
onClear: void 0,
|
|
583
|
+
containerId: void 0
|
|
584
|
+
};
|
|
585
|
+
},
|
|
586
|
+
addProseMirrorPlugins() {
|
|
587
|
+
const opts = this.options;
|
|
588
|
+
return [
|
|
589
|
+
new import_state2.Plugin({
|
|
590
|
+
view() {
|
|
591
|
+
return {
|
|
592
|
+
update(view) {
|
|
593
|
+
const { state } = view;
|
|
594
|
+
const { selection } = state;
|
|
595
|
+
const { $from } = selection;
|
|
596
|
+
if (!$from.parent.isTextblock) {
|
|
597
|
+
opts.onClear?.();
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
const textBeforeCursor = $from.parent.textBetween(
|
|
601
|
+
0,
|
|
602
|
+
$from.parentOffset
|
|
603
|
+
);
|
|
604
|
+
const slashMatch = textBeforeCursor.match(
|
|
605
|
+
/(?:^|\s)\/([a-zA-Z0-9_-]*)$/
|
|
606
|
+
);
|
|
607
|
+
if (slashMatch) {
|
|
608
|
+
const matchIndex = slashMatch.index ?? 0;
|
|
609
|
+
const offsetInParent = matchIndex + (slashMatch[0].startsWith(" ") ? 1 : 0);
|
|
610
|
+
const matchFrom = $from.start() + offsetInParent;
|
|
611
|
+
const matchTo = $from.pos;
|
|
612
|
+
const coords = view.coordsAtPos($from.pos);
|
|
613
|
+
let relativeCoords = {
|
|
614
|
+
top: coords.top,
|
|
615
|
+
left: coords.left,
|
|
616
|
+
bottom: coords.bottom,
|
|
617
|
+
right: coords.right
|
|
618
|
+
};
|
|
619
|
+
if (opts.containerId && typeof document !== "undefined") {
|
|
620
|
+
const container = document.getElementById(opts.containerId);
|
|
621
|
+
if (container) {
|
|
622
|
+
const rect = container.getBoundingClientRect();
|
|
623
|
+
relativeCoords = {
|
|
624
|
+
top: coords.bottom - rect.top + 5,
|
|
625
|
+
left: coords.left - rect.left,
|
|
626
|
+
bottom: coords.bottom - rect.top,
|
|
627
|
+
right: coords.right - rect.left
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
opts.onMatch?.({
|
|
632
|
+
match: slashMatch,
|
|
633
|
+
query: slashMatch[1] || "",
|
|
634
|
+
from: matchFrom,
|
|
635
|
+
to: matchTo,
|
|
636
|
+
coords: relativeCoords
|
|
637
|
+
});
|
|
638
|
+
} else {
|
|
639
|
+
opts.onClear?.();
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
})
|
|
645
|
+
];
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
// src/extensions/template-suggestions.ts
|
|
650
|
+
var import_core3 = require("@tiptap/core");
|
|
651
|
+
var import_suggestion = __toESM(require("@tiptap/suggestion"), 1);
|
|
652
|
+
var TemplateSuggestions = import_core3.Extension.create({
|
|
653
|
+
name: "templateSuggestions",
|
|
654
|
+
addOptions() {
|
|
655
|
+
return {
|
|
656
|
+
templates: [],
|
|
657
|
+
char: "{{",
|
|
658
|
+
onSuggestion: void 0
|
|
659
|
+
};
|
|
660
|
+
},
|
|
661
|
+
addProseMirrorPlugins() {
|
|
662
|
+
const opts = this.options;
|
|
663
|
+
const suggestionConfig = {
|
|
664
|
+
char: opts.char || "{{",
|
|
665
|
+
items: ({ query }) => {
|
|
666
|
+
const lower = query.toLowerCase();
|
|
667
|
+
return (opts.templates || []).filter(
|
|
668
|
+
(t) => t.name.toLowerCase().includes(lower)
|
|
669
|
+
);
|
|
670
|
+
},
|
|
671
|
+
command: ({ editor, range, props }) => {
|
|
672
|
+
editor.chain().focus().deleteRange(range).insertContent(`{{${props.name}}}`).run();
|
|
673
|
+
},
|
|
674
|
+
render: () => {
|
|
675
|
+
return {
|
|
676
|
+
onStart: (props) => {
|
|
677
|
+
opts.onSuggestion?.(props);
|
|
678
|
+
},
|
|
679
|
+
onUpdate: (props) => {
|
|
680
|
+
opts.onSuggestion?.(props);
|
|
681
|
+
},
|
|
682
|
+
onExit: () => {
|
|
683
|
+
opts.onSuggestion?.({
|
|
684
|
+
query: "",
|
|
685
|
+
range: { from: 0, to: 0 },
|
|
686
|
+
items: [],
|
|
687
|
+
command: () => {
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
return [
|
|
695
|
+
(0, import_suggestion.default)({
|
|
696
|
+
editor: this.editor,
|
|
697
|
+
...suggestionConfig
|
|
698
|
+
})
|
|
699
|
+
];
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
// src/extensions/loading-node.ts
|
|
704
|
+
var import_core4 = require("@tiptap/core");
|
|
705
|
+
var LoadingNode = import_core4.Node.create({
|
|
706
|
+
name: "loadingNode",
|
|
707
|
+
group: "inline",
|
|
708
|
+
inline: true,
|
|
709
|
+
selectable: true,
|
|
710
|
+
atom: true,
|
|
711
|
+
addAttributes() {
|
|
712
|
+
return {
|
|
713
|
+
id: {
|
|
714
|
+
default: null,
|
|
715
|
+
parseHTML: (element) => element.getAttribute("data-id"),
|
|
716
|
+
renderHTML: (attributes) => {
|
|
717
|
+
if (!attributes.id) return {};
|
|
718
|
+
return { "data-id": attributes.id };
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
},
|
|
723
|
+
parseHTML() {
|
|
724
|
+
return [
|
|
725
|
+
{
|
|
726
|
+
tag: 'span[data-type="loading"]'
|
|
727
|
+
}
|
|
728
|
+
];
|
|
729
|
+
},
|
|
730
|
+
renderHTML({ HTMLAttributes }) {
|
|
731
|
+
return [
|
|
732
|
+
"span",
|
|
733
|
+
(0, import_core4.mergeAttributes)(HTMLAttributes, {
|
|
734
|
+
"data-type": "loading",
|
|
735
|
+
class: "inline-flex items-center px-1.5 py-0.5 text-xs text-muted-foreground animate-pulse"
|
|
736
|
+
}),
|
|
737
|
+
"\u23F3"
|
|
738
|
+
];
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
// src/extensions/SmilieReplacer.ts
|
|
743
|
+
var import_core5 = require("@tiptap/core");
|
|
744
|
+
var SmilieReplacer = import_core5.Extension.create({
|
|
745
|
+
name: "smilieReplacer",
|
|
746
|
+
addInputRules() {
|
|
747
|
+
return [
|
|
748
|
+
(0, import_core5.textInputRule)({ find: /-___- $/, replace: "\u{1F611} " }),
|
|
749
|
+
(0, import_core5.textInputRule)({ find: /:'-\) $/, replace: "\u{1F602} " }),
|
|
750
|
+
(0, import_core5.textInputRule)({ find: /':-\) $/, replace: "\u{1F605} " }),
|
|
751
|
+
(0, import_core5.textInputRule)({ find: /':-D $/, replace: "\u{1F605} " }),
|
|
752
|
+
(0, import_core5.textInputRule)({ find: />:-\) $/, replace: "\u{1F606} " }),
|
|
753
|
+
(0, import_core5.textInputRule)({ find: /-__- $/, replace: "\u{1F611} " }),
|
|
754
|
+
(0, import_core5.textInputRule)({ find: /':-\( $/, replace: "\u{1F613} " }),
|
|
755
|
+
(0, import_core5.textInputRule)({ find: /:'-\( $/, replace: "\u{1F622} " }),
|
|
756
|
+
(0, import_core5.textInputRule)({ find: />:-\( $/, replace: "\u{1F620} " }),
|
|
757
|
+
(0, import_core5.textInputRule)({ find: /O:-\) $/, replace: "\u{1F607} " }),
|
|
758
|
+
(0, import_core5.textInputRule)({ find: /:'\) $/, replace: "\u{1F602} " }),
|
|
759
|
+
(0, import_core5.textInputRule)({ find: /:-D $/, replace: "\u{1F603} " }),
|
|
760
|
+
(0, import_core5.textInputRule)({ find: /':\) $/, replace: "\u{1F605} " }),
|
|
761
|
+
(0, import_core5.textInputRule)({ find: /;-\) $/, replace: "\u{1F609} " }),
|
|
762
|
+
(0, import_core5.textInputRule)({ find: /B-\) $/, replace: "\u{1F60E} " }),
|
|
763
|
+
(0, import_core5.textInputRule)({ find: /:-\* $/, replace: "\u{1F618} " }),
|
|
764
|
+
(0, import_core5.textInputRule)({ find: /:-\) $/, replace: "\u{1F642} " }),
|
|
765
|
+
(0, import_core5.textInputRule)({ find: /-_- $/, replace: "\u{1F611} " }),
|
|
766
|
+
(0, import_core5.textInputRule)({ find: /:-O $/, replace: "\u{1F62E} " }),
|
|
767
|
+
(0, import_core5.textInputRule)({ find: /:-P $/, replace: "\u{1F61B} " }),
|
|
768
|
+
(0, import_core5.textInputRule)({ find: /:-p $/, replace: "\u{1F61B} " }),
|
|
769
|
+
(0, import_core5.textInputRule)({ find: /:-\/ $/, replace: "\u{1F615} " }),
|
|
770
|
+
(0, import_core5.textInputRule)({ find: /:-\( $/, replace: "\u{1F61E} " }),
|
|
771
|
+
(0, import_core5.textInputRule)({ find: /:'\( $/, replace: "\u{1F622} " }),
|
|
772
|
+
(0, import_core5.textInputRule)({ find: /:D $/, replace: "\u{1F603} " }),
|
|
773
|
+
(0, import_core5.textInputRule)({ find: /=D $/, replace: "\u{1F603} " }),
|
|
774
|
+
(0, import_core5.textInputRule)({ find: /;\) $/, replace: "\u{1F609} " }),
|
|
775
|
+
(0, import_core5.textInputRule)({ find: /B\) $/, replace: "\u{1F60E} " }),
|
|
776
|
+
(0, import_core5.textInputRule)({ find: /:\) $/, replace: "\u{1F642} " }),
|
|
777
|
+
(0, import_core5.textInputRule)({ find: /=\) $/, replace: "\u{1F642} " }),
|
|
778
|
+
(0, import_core5.textInputRule)({ find: /:O $/, replace: "\u{1F62E} " }),
|
|
779
|
+
(0, import_core5.textInputRule)({ find: /:P $/, replace: "\u{1F61B} " }),
|
|
780
|
+
(0, import_core5.textInputRule)({ find: /:p $/, replace: "\u{1F61B} " }),
|
|
781
|
+
(0, import_core5.textInputRule)({ find: /:\/ $/, replace: "\u{1F615} " }),
|
|
782
|
+
(0, import_core5.textInputRule)({ find: /:\( $/, replace: "\u{1F61E} " }),
|
|
783
|
+
(0, import_core5.textInputRule)({ find: /<3 $/, replace: "\u2764\uFE0F " }),
|
|
784
|
+
(0, import_core5.textInputRule)({ find: /<\/3 $/, replace: "\u{1F494} " }),
|
|
785
|
+
(0, import_core5.textInputRule)({ find: /\/shrug $/, replace: "\xAF\\_(\u30C4)_/\xAF " })
|
|
786
|
+
];
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
// src/extensions/ColorHighlighter.ts
|
|
791
|
+
var import_core6 = require("@tiptap/core");
|
|
792
|
+
var import_state3 = require("@tiptap/pm/state");
|
|
793
|
+
var import_view2 = require("@tiptap/pm/view");
|
|
794
|
+
function findHexColors(doc) {
|
|
795
|
+
const hexColorRegex = /(#[0-9a-fA-F]{3,8})\b/g;
|
|
796
|
+
const decorations = [];
|
|
797
|
+
doc.descendants((node, position) => {
|
|
798
|
+
if (!node.text) return;
|
|
799
|
+
let match;
|
|
800
|
+
while ((match = hexColorRegex.exec(node.text)) !== null) {
|
|
801
|
+
const color = match[0];
|
|
802
|
+
const from = position + match.index;
|
|
803
|
+
const to = from + color.length;
|
|
804
|
+
decorations.push(
|
|
805
|
+
import_view2.Decoration.inline(from, to, {
|
|
806
|
+
class: "color-highlight px-1 py-0.5 rounded text-xs font-mono border",
|
|
807
|
+
style: `--color: ${color}; background-color: ${color}20; border-color: ${color}; color: ${color};`
|
|
808
|
+
})
|
|
809
|
+
);
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
return import_view2.DecorationSet.create(doc, decorations);
|
|
813
|
+
}
|
|
814
|
+
var ColorHighlighter = import_core6.Extension.create({
|
|
815
|
+
name: "colorHighlighter",
|
|
816
|
+
addProseMirrorPlugins() {
|
|
817
|
+
return [
|
|
818
|
+
new import_state3.Plugin({
|
|
819
|
+
state: {
|
|
820
|
+
init(_, { doc }) {
|
|
821
|
+
return findHexColors(doc);
|
|
822
|
+
},
|
|
823
|
+
apply(transaction, oldState) {
|
|
824
|
+
return transaction.docChanged ? findHexColors(transaction.doc) : oldState;
|
|
825
|
+
}
|
|
826
|
+
},
|
|
827
|
+
props: {
|
|
828
|
+
decorations(state) {
|
|
829
|
+
return this.getState(state);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
})
|
|
833
|
+
];
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
// src/extensions/FontSize.ts
|
|
838
|
+
var import_core7 = require("@tiptap/core");
|
|
839
|
+
var import_extension_text_style = require("@tiptap/extension-text-style");
|
|
840
|
+
var FontSize = import_core7.Extension.create({
|
|
841
|
+
name: "fontSize",
|
|
842
|
+
addOptions() {
|
|
843
|
+
return {
|
|
844
|
+
types: ["textStyle"]
|
|
845
|
+
};
|
|
846
|
+
},
|
|
847
|
+
addGlobalAttributes() {
|
|
848
|
+
return [
|
|
849
|
+
{
|
|
850
|
+
types: this.options.types,
|
|
851
|
+
attributes: {
|
|
852
|
+
fontSize: {
|
|
853
|
+
default: null,
|
|
854
|
+
parseHTML: (element) => element.style.fontSize.replace(/['"]+/g, ""),
|
|
855
|
+
renderHTML: (attributes) => {
|
|
856
|
+
if (!attributes.fontSize) {
|
|
857
|
+
return {};
|
|
858
|
+
}
|
|
859
|
+
return {
|
|
860
|
+
style: `font-size: ${attributes.fontSize}`
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
];
|
|
867
|
+
},
|
|
868
|
+
addCommands() {
|
|
869
|
+
return {
|
|
870
|
+
setFontSize: (fontSize) => ({ chain }) => chain().setMark("textStyle", { fontSize }).run(),
|
|
871
|
+
unsetFontSize: () => ({ chain }) => chain().setMark("textStyle", { fontSize: null }).removeEmptyTextStyle().run()
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
// src/extensions/rich-text-preset.ts
|
|
877
|
+
var import_starter_kit = __toESM(require("@tiptap/starter-kit"), 1);
|
|
878
|
+
var import_extension_color = __toESM(require("@tiptap/extension-color"), 1);
|
|
879
|
+
var import_extension_highlight = __toESM(require("@tiptap/extension-highlight"), 1);
|
|
880
|
+
var import_extension_link = __toESM(require("@tiptap/extension-link"), 1);
|
|
881
|
+
var import_extension_task_list = __toESM(require("@tiptap/extension-task-list"), 1);
|
|
882
|
+
var import_extension_task_item = __toESM(require("@tiptap/extension-task-item"), 1);
|
|
883
|
+
var import_extension_text_align = __toESM(require("@tiptap/extension-text-align"), 1);
|
|
884
|
+
var import_extension_text_style2 = __toESM(require("@tiptap/extension-text-style"), 1);
|
|
885
|
+
var import_extension_typography = __toESM(require("@tiptap/extension-typography"), 1);
|
|
886
|
+
var import_extension_underline = __toESM(require("@tiptap/extension-underline"), 1);
|
|
887
|
+
var import_extension_placeholder = __toESM(require("@tiptap/extension-placeholder"), 1);
|
|
888
|
+
var import_extension_character_count = __toESM(require("@tiptap/extension-character-count"), 1);
|
|
889
|
+
function createRichTextPreset(options = {}) {
|
|
890
|
+
const {
|
|
891
|
+
placeholder = "Start typing...",
|
|
892
|
+
characterLimit,
|
|
893
|
+
openLinksOnClick = false,
|
|
894
|
+
enableSmilies = true,
|
|
895
|
+
enableColorHighlighter = true,
|
|
896
|
+
headingLevels = [1, 2, 3, 4]
|
|
897
|
+
} = options;
|
|
898
|
+
const extensions = [
|
|
899
|
+
import_starter_kit.default.configure({
|
|
900
|
+
orderedList: {
|
|
901
|
+
HTMLAttributes: {
|
|
902
|
+
class: "list-decimal pl-4"
|
|
903
|
+
}
|
|
904
|
+
},
|
|
905
|
+
bulletList: {
|
|
906
|
+
HTMLAttributes: {
|
|
907
|
+
class: "list-disc pl-4"
|
|
908
|
+
}
|
|
909
|
+
},
|
|
910
|
+
heading: {
|
|
911
|
+
levels: headingLevels,
|
|
912
|
+
HTMLAttributes: {
|
|
913
|
+
class: "font-bold tracking-tight"
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}),
|
|
917
|
+
import_extension_text_style2.default,
|
|
918
|
+
import_extension_color.default,
|
|
919
|
+
import_extension_highlight.default.configure({ multicolor: true }),
|
|
920
|
+
import_extension_underline.default,
|
|
921
|
+
import_extension_typography.default,
|
|
922
|
+
import_extension_text_align.default.configure({
|
|
923
|
+
types: ["heading", "paragraph"]
|
|
924
|
+
}),
|
|
925
|
+
import_extension_link.default.configure({
|
|
926
|
+
openOnClick: openLinksOnClick,
|
|
927
|
+
autolink: true,
|
|
928
|
+
defaultProtocol: "https",
|
|
929
|
+
HTMLAttributes: {
|
|
930
|
+
target: "_blank",
|
|
931
|
+
rel: "noopener noreferrer",
|
|
932
|
+
class: "text-blue-500 underline underline-offset-2"
|
|
933
|
+
}
|
|
934
|
+
}),
|
|
935
|
+
import_extension_task_list.default,
|
|
936
|
+
import_extension_task_item.default.configure({
|
|
937
|
+
nested: true
|
|
938
|
+
}),
|
|
939
|
+
FontSize,
|
|
940
|
+
import_extension_placeholder.default.configure({
|
|
941
|
+
emptyEditorClass: "is-empty",
|
|
942
|
+
placeholder: typeof placeholder === "function" ? placeholder : () => placeholder
|
|
943
|
+
})
|
|
944
|
+
];
|
|
945
|
+
if (characterLimit) {
|
|
946
|
+
extensions.push(
|
|
947
|
+
import_extension_character_count.default.configure({
|
|
948
|
+
limit: characterLimit
|
|
949
|
+
})
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
if (enableSmilies) {
|
|
953
|
+
extensions.push(SmilieReplacer);
|
|
954
|
+
}
|
|
955
|
+
if (enableColorHighlighter) {
|
|
956
|
+
extensions.push(ColorHighlighter);
|
|
957
|
+
}
|
|
958
|
+
return extensions;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// src/serializers/plain-text.ts
|
|
962
|
+
function escapeHtml(text) {
|
|
963
|
+
if (!text) return "";
|
|
964
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
965
|
+
}
|
|
966
|
+
function plainTextToTipTapHtml(text) {
|
|
967
|
+
if (!text) return "<p></p>";
|
|
968
|
+
if (/<p[\s>]/i.test(text)) {
|
|
969
|
+
return text;
|
|
970
|
+
}
|
|
971
|
+
return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n").map((line) => `<p>${escapeHtml(line)}</p>`).join("");
|
|
972
|
+
}
|
|
973
|
+
function htmlToPlainText(html) {
|
|
974
|
+
if (!html) return "";
|
|
975
|
+
if (typeof document !== "undefined") {
|
|
976
|
+
const tempDiv = document.createElement("div");
|
|
977
|
+
tempDiv.innerHTML = html;
|
|
978
|
+
tempDiv.querySelectorAll("br.ProseMirror-trailingBreak").forEach((br) => br.remove());
|
|
979
|
+
tempDiv.querySelectorAll("br").forEach((br) => br.replaceWith("\n"));
|
|
980
|
+
const paragraphs = tempDiv.querySelectorAll("p, div, li, h1, h2, h3, h4, h5, h6");
|
|
981
|
+
if (paragraphs.length > 0) {
|
|
982
|
+
const textParts = [];
|
|
983
|
+
paragraphs.forEach((p) => {
|
|
984
|
+
textParts.push(p.textContent || "");
|
|
985
|
+
});
|
|
986
|
+
return textParts.join("\n");
|
|
987
|
+
}
|
|
988
|
+
return tempDiv.textContent || "";
|
|
989
|
+
}
|
|
990
|
+
return html.replace(/<br\s*\/?>/gi, "\n").replace(/<\/p>/gi, "\n").replace(/<\/div>/gi, "\n").replace(/<\/li>/gi, "\n").replace(/<[^>]+>/g, "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").trim();
|
|
991
|
+
}
|
|
992
|
+
function getEditorText(editor) {
|
|
993
|
+
if (!editor) return "";
|
|
994
|
+
const html = typeof editor.getHTML === "function" ? editor.getHTML() : "";
|
|
995
|
+
if (html) {
|
|
996
|
+
return htmlToPlainText(html);
|
|
997
|
+
}
|
|
998
|
+
if (typeof editor.getText === "function") {
|
|
999
|
+
try {
|
|
1000
|
+
return editor.getText({ blockSeparator: "\n" });
|
|
1001
|
+
} catch {
|
|
1002
|
+
return editor.getText();
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
return "";
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// src/controller.ts
|
|
1009
|
+
var import_core8 = require("@tiptap/core");
|
|
1010
|
+
var import_model = require("@tiptap/pm/model");
|
|
1011
|
+
var EditorController = class {
|
|
1012
|
+
editor;
|
|
1013
|
+
plainTextMode;
|
|
1014
|
+
onPlainTextChange;
|
|
1015
|
+
onTokensChange;
|
|
1016
|
+
onSelectionChange;
|
|
1017
|
+
constructor(options = {}) {
|
|
1018
|
+
const {
|
|
1019
|
+
element,
|
|
1020
|
+
content,
|
|
1021
|
+
plainTextMode = false,
|
|
1022
|
+
extensions = [],
|
|
1023
|
+
onPlainTextChange,
|
|
1024
|
+
onTokensChange,
|
|
1025
|
+
onSelectionChange,
|
|
1026
|
+
...editorOptions
|
|
1027
|
+
} = options;
|
|
1028
|
+
this.plainTextMode = plainTextMode;
|
|
1029
|
+
this.onPlainTextChange = onPlainTextChange;
|
|
1030
|
+
this.onTokensChange = onTokensChange;
|
|
1031
|
+
this.onSelectionChange = onSelectionChange;
|
|
1032
|
+
const initialContent = plainTextMode && typeof content === "string" ? plainTextToTipTapHtml(content) : content;
|
|
1033
|
+
this.editor = new import_core8.Editor({
|
|
1034
|
+
element: element || void 0,
|
|
1035
|
+
content: initialContent,
|
|
1036
|
+
extensions,
|
|
1037
|
+
...editorOptions,
|
|
1038
|
+
onUpdate: (props) => {
|
|
1039
|
+
editorOptions.onUpdate?.(props);
|
|
1040
|
+
this.handleUpdate();
|
|
1041
|
+
},
|
|
1042
|
+
onSelectionUpdate: (props) => {
|
|
1043
|
+
editorOptions.onSelectionUpdate?.(props);
|
|
1044
|
+
this.handleSelectionUpdate();
|
|
1045
|
+
}
|
|
1046
|
+
});
|
|
1047
|
+
if (plainTextMode) {
|
|
1048
|
+
this.enforcePlainTextClipboard();
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
enforcePlainTextClipboard() {
|
|
1052
|
+
this.editor.setOptions({
|
|
1053
|
+
editorProps: {
|
|
1054
|
+
...this.editor.options.editorProps,
|
|
1055
|
+
clipboardTextParser: (text, context, _plain, view) => {
|
|
1056
|
+
const schema = context?.doc?.type?.schema || context?.schema || view?.state?.schema || this.editor.schema;
|
|
1057
|
+
if (!schema) return import_model.Slice.empty;
|
|
1058
|
+
const blocks = text.replace(/\r\n?/g, "\n").split("\n");
|
|
1059
|
+
const nodes = [];
|
|
1060
|
+
blocks.forEach((line) => {
|
|
1061
|
+
const nodeJson = { type: "paragraph" };
|
|
1062
|
+
if (line.length > 0) {
|
|
1063
|
+
nodeJson.content = [{ type: "text", text: line }];
|
|
1064
|
+
}
|
|
1065
|
+
try {
|
|
1066
|
+
const node = import_model.Node.fromJSON(schema, nodeJson);
|
|
1067
|
+
nodes.push(node);
|
|
1068
|
+
} catch {
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
return import_model.Slice.maxOpen(import_model.Fragment.fromArray(nodes));
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
1076
|
+
handleUpdate() {
|
|
1077
|
+
if (this.plainTextMode || this.onPlainTextChange || this.onTokensChange) {
|
|
1078
|
+
const text = this.getPlainText();
|
|
1079
|
+
this.onPlainTextChange?.(text);
|
|
1080
|
+
if (this.onTokensChange) {
|
|
1081
|
+
const tokens = tokenizePrompt(text);
|
|
1082
|
+
this.onTokensChange(tokens);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
handleSelectionUpdate() {
|
|
1087
|
+
if (this.onSelectionChange) {
|
|
1088
|
+
const { from, to } = this.editor.state.selection;
|
|
1089
|
+
this.onSelectionChange({ from, to });
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
getPlainText() {
|
|
1093
|
+
return getEditorText(this.editor);
|
|
1094
|
+
}
|
|
1095
|
+
setPlainText(text, emitUpdate = true) {
|
|
1096
|
+
const html = plainTextToTipTapHtml(text);
|
|
1097
|
+
this.editor.commands.setContent(html, emitUpdate);
|
|
1098
|
+
}
|
|
1099
|
+
insertText(text) {
|
|
1100
|
+
this.editor.commands.insertContent(text);
|
|
1101
|
+
}
|
|
1102
|
+
insertTextAt(pos, text) {
|
|
1103
|
+
this.editor.chain().focus().insertContentAt(pos, text).run();
|
|
1104
|
+
}
|
|
1105
|
+
replaceRange(from, to, text) {
|
|
1106
|
+
this.editor.chain().focus().deleteRange({ from, to }).insertContentAt(from, text).run();
|
|
1107
|
+
}
|
|
1108
|
+
destroy() {
|
|
1109
|
+
this.editor.destroy();
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
function createEditor(options = {}) {
|
|
1113
|
+
return new EditorController(options);
|
|
1114
|
+
}
|
|
1115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1116
|
+
0 && (module.exports = {
|
|
1117
|
+
ColorHighlighter,
|
|
1118
|
+
EditorController,
|
|
1119
|
+
FontSize,
|
|
1120
|
+
GradientText,
|
|
1121
|
+
INSTRUCTION_REGEX,
|
|
1122
|
+
LoadingNode,
|
|
1123
|
+
SlashCommands,
|
|
1124
|
+
SmilieReplacer,
|
|
1125
|
+
TEMPLATE_REGEX,
|
|
1126
|
+
TemplateSuggestions,
|
|
1127
|
+
VARIABLE_REGEX,
|
|
1128
|
+
createEditor,
|
|
1129
|
+
createRichTextPreset,
|
|
1130
|
+
escapeHtml,
|
|
1131
|
+
extractInstructionNames,
|
|
1132
|
+
extractTemplateNames,
|
|
1133
|
+
extractVariableNames,
|
|
1134
|
+
findHexColors,
|
|
1135
|
+
getEditorText,
|
|
1136
|
+
getLatestVersion,
|
|
1137
|
+
htmlToPlainText,
|
|
1138
|
+
instructionRegex,
|
|
1139
|
+
mapRawOffsetToResolved,
|
|
1140
|
+
mapResolvedOffsetToRaw,
|
|
1141
|
+
plainTextToTipTapHtml,
|
|
1142
|
+
resolveTemplates,
|
|
1143
|
+
resolveTemplatesWithMapping,
|
|
1144
|
+
resolveVariables,
|
|
1145
|
+
templateRegex,
|
|
1146
|
+
tokenizePrompt,
|
|
1147
|
+
variableRegex
|
|
1148
|
+
});
|
|
1149
|
+
//# sourceMappingURL=index.cjs.map
|