@pixerate/editor 0.13.0 → 0.14.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/dist/grammar/index.cjs +45 -58
- package/dist/grammar/index.cjs.map +1 -1
- package/dist/grammar/index.d.cts +13 -3
- package/dist/grammar/index.d.ts +13 -3
- package/dist/grammar/index.js +42 -58
- package/dist/grammar/index.js.map +1 -1
- package/dist/index.cjs +45 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +42 -58
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { T as Token } from './tokens-7kRTEtPb.cjs';
|
|
2
2
|
export { C as ColorGradient, I as INSTRUCTION_REGEX, a as TEMPLATE_REGEX, b as Template, c as TemplateVersion, d as TokenType, V as VARIABLE_REGEX, i as instructionRegex, t as templateRegex, v as variableRegex } from './tokens-7kRTEtPb.cjs';
|
|
3
|
-
export { ResolveTemplatesOptions, SourceMapSegment, extractInstructionNames, extractTemplateNames, extractVariableNames, getLatestVersion, mapRawOffsetToResolved, mapResolvedOffsetToRaw, resolveTemplates, resolveTemplatesWithMapping, resolveVariables, tokenizePrompt } from './grammar/index.cjs';
|
|
3
|
+
export { ResolveTemplatesOptions, SourceMapSegment, TEMPLATE_DEPTH_ERROR, TEMPLATE_LOOP_ERROR, extractInstructionNames, extractTemplateNames, extractVariableNames, getLatestVersion, getTemplateBody, mapRawOffsetToResolved, mapResolvedOffsetToRaw, resolveTemplates, resolveTemplatesWithMapping, resolveVariables, tokenizePrompt } from './grammar/index.cjs';
|
|
4
4
|
export { ColorHighlighter, FontSize, GradientText, GradientTextOptions, Image, ImageOptions, LoadingNode, Markdown, RichTextPresetOptions, SlashCommandMatchData, SlashCommands, SlashCommandsOptions, SmilieReplacer, TemplateSuggestions, TemplateSuggestionsOptions, createRichTextPreset, findHexColors, handleImageInsertion, imagePastePluginKey, insertImageNode, removeImageNode, updateImageSrc } from './extensions/index.cjs';
|
|
5
5
|
export { M as Mention, a as MentionEntity, b as MentionOptions, c as createMentionExtension } from './mention-Dcevh3ff.cjs';
|
|
6
6
|
export { ExtractedMention, MARKDOWN_MENTION_SPLIT_REGEX, MENTION_REGEX, MarkdownToHtmlOptions, MentionSegment, PreprocessMarkdownMentionsOptions, escapeHtml, extractMentions, extractMentionsFromDoc, getEditorMarkdown, getEditorText, htmlToPlainText, markdownToTipTapHtml, parseMentionSegments, plainTextToTipTapHtml, preprocessMarkdownFileLinks, preprocessMarkdownMentions, stripMarkdownCode } from './serializers/index.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { T as Token } from './tokens-7kRTEtPb.js';
|
|
2
2
|
export { C as ColorGradient, I as INSTRUCTION_REGEX, a as TEMPLATE_REGEX, b as Template, c as TemplateVersion, d as TokenType, V as VARIABLE_REGEX, i as instructionRegex, t as templateRegex, v as variableRegex } from './tokens-7kRTEtPb.js';
|
|
3
|
-
export { ResolveTemplatesOptions, SourceMapSegment, extractInstructionNames, extractTemplateNames, extractVariableNames, getLatestVersion, mapRawOffsetToResolved, mapResolvedOffsetToRaw, resolveTemplates, resolveTemplatesWithMapping, resolveVariables, tokenizePrompt } from './grammar/index.js';
|
|
3
|
+
export { ResolveTemplatesOptions, SourceMapSegment, TEMPLATE_DEPTH_ERROR, TEMPLATE_LOOP_ERROR, extractInstructionNames, extractTemplateNames, extractVariableNames, getLatestVersion, getTemplateBody, mapRawOffsetToResolved, mapResolvedOffsetToRaw, resolveTemplates, resolveTemplatesWithMapping, resolveVariables, tokenizePrompt } from './grammar/index.js';
|
|
4
4
|
export { ColorHighlighter, FontSize, GradientText, GradientTextOptions, Image, ImageOptions, LoadingNode, Markdown, RichTextPresetOptions, SlashCommandMatchData, SlashCommands, SlashCommandsOptions, SmilieReplacer, TemplateSuggestions, TemplateSuggestionsOptions, createRichTextPreset, findHexColors, handleImageInsertion, imagePastePluginKey, insertImageNode, removeImageNode, updateImageSrc } from './extensions/index.js';
|
|
5
5
|
export { M as Mention, a as MentionEntity, b as MentionOptions, c as createMentionExtension } from './mention-Dcevh3ff.js';
|
|
6
6
|
export { ExtractedMention, MARKDOWN_MENTION_SPLIT_REGEX, MENTION_REGEX, MarkdownToHtmlOptions, MentionSegment, PreprocessMarkdownMentionsOptions, escapeHtml, extractMentions, extractMentionsFromDoc, getEditorMarkdown, getEditorText, htmlToPlainText, markdownToTipTapHtml, parseMentionSegments, plainTextToTipTapHtml, preprocessMarkdownFileLinks, preprocessMarkdownMentions, stripMarkdownCode } from './serializers/index.js';
|
package/dist/index.js
CHANGED
|
@@ -116,6 +116,18 @@ function getLatestVersion(template) {
|
|
|
116
116
|
}
|
|
117
117
|
return template.versions[template.versions.length - 1];
|
|
118
118
|
}
|
|
119
|
+
var TEMPLATE_LOOP_ERROR = "[Template loop detected]";
|
|
120
|
+
var TEMPLATE_DEPTH_ERROR = "[Template max depth exceeded]";
|
|
121
|
+
function getTemplateBody(template, bindings) {
|
|
122
|
+
const boundVersionId = bindings?.[template.name];
|
|
123
|
+
if (boundVersionId && template.versions) {
|
|
124
|
+
const boundVersion = template.versions.find(
|
|
125
|
+
(v) => v.id === boundVersionId || v.version === boundVersionId
|
|
126
|
+
);
|
|
127
|
+
return boundVersion?.body;
|
|
128
|
+
}
|
|
129
|
+
return getLatestVersion(template)?.body ?? template.body;
|
|
130
|
+
}
|
|
119
131
|
function resolveTemplates(text, templates = [], options) {
|
|
120
132
|
const templateMap = /* @__PURE__ */ new Map();
|
|
121
133
|
for (const t of templates) {
|
|
@@ -123,50 +135,27 @@ function resolveTemplates(text, templates = [], options) {
|
|
|
123
135
|
}
|
|
124
136
|
const maxDepth = options?.maxDepth ?? 10;
|
|
125
137
|
function resolveRecursive(currentText, visited, depth) {
|
|
126
|
-
if (depth > maxDepth) {
|
|
127
|
-
return "[Template max depth exceeded]";
|
|
128
|
-
}
|
|
129
|
-
let result = currentText;
|
|
130
138
|
const regex = new RegExp(TEMPLATE_REGEX.source, TEMPLATE_REGEX.flags);
|
|
131
|
-
|
|
132
|
-
while ((match = regex.exec(result)) !== null) {
|
|
133
|
-
const [fullMatch, rawTemplateName] = match;
|
|
139
|
+
return currentText.replace(regex, (fullMatch, rawTemplateName) => {
|
|
134
140
|
const templateName = rawTemplateName.trim();
|
|
135
141
|
if (visited.has(templateName)) {
|
|
136
|
-
return
|
|
142
|
+
return TEMPLATE_LOOP_ERROR;
|
|
137
143
|
}
|
|
138
144
|
const template = templateMap.get(templateName);
|
|
139
145
|
if (!template) {
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
let versionBody;
|
|
143
|
-
const boundVersionId = options?.bindings?.[templateName];
|
|
144
|
-
if (boundVersionId && template.versions) {
|
|
145
|
-
const boundVersion = template.versions.find(
|
|
146
|
-
(v) => v.id === boundVersionId || v.version === boundVersionId
|
|
147
|
-
);
|
|
148
|
-
versionBody = boundVersion?.body;
|
|
149
|
-
} else {
|
|
150
|
-
const latest = getLatestVersion(template);
|
|
151
|
-
versionBody = latest?.body ?? template.body;
|
|
146
|
+
return fullMatch;
|
|
152
147
|
}
|
|
148
|
+
const versionBody = getTemplateBody(template, options?.bindings);
|
|
153
149
|
if (versionBody === void 0) {
|
|
154
|
-
|
|
150
|
+
return fullMatch;
|
|
151
|
+
}
|
|
152
|
+
if (depth + 1 > maxDepth) {
|
|
153
|
+
return TEMPLATE_DEPTH_ERROR;
|
|
155
154
|
}
|
|
156
155
|
const nextVisited = new Set(visited);
|
|
157
156
|
nextVisited.add(templateName);
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
nextVisited,
|
|
161
|
-
depth + 1
|
|
162
|
-
);
|
|
163
|
-
if (resolvedBody === "[Template loop detected]" || resolvedBody === "[Template max depth exceeded]") {
|
|
164
|
-
return resolvedBody;
|
|
165
|
-
}
|
|
166
|
-
result = result.replace(fullMatch, resolvedBody);
|
|
167
|
-
regex.lastIndex = 0;
|
|
168
|
-
}
|
|
169
|
-
return result;
|
|
157
|
+
return resolveRecursive(versionBody, nextVisited, depth + 1);
|
|
158
|
+
});
|
|
170
159
|
}
|
|
171
160
|
return resolveRecursive(text, /* @__PURE__ */ new Set(), 0);
|
|
172
161
|
}
|
|
@@ -215,7 +204,7 @@ function extractInstructionNames(text) {
|
|
|
215
204
|
}
|
|
216
205
|
|
|
217
206
|
// src/grammar/sourcemap.ts
|
|
218
|
-
function resolveTemplatesWithMapping(text, templates = [], templateBindings) {
|
|
207
|
+
function resolveTemplatesWithMapping(text, templates = [], templateBindings, options) {
|
|
219
208
|
if (!templates || templates.length === 0 || !text.includes("{{")) {
|
|
220
209
|
return {
|
|
221
210
|
text,
|
|
@@ -231,7 +220,7 @@ function resolveTemplatesWithMapping(text, templates = [], templateBindings) {
|
|
|
231
220
|
};
|
|
232
221
|
}
|
|
233
222
|
const templateMap = new Map(templates.map((t) => [t.name, t]));
|
|
234
|
-
const regex =
|
|
223
|
+
const regex = new RegExp(TEMPLATE_REGEX.source, TEMPLATE_REGEX.flags);
|
|
235
224
|
let match;
|
|
236
225
|
let lastIndex = 0;
|
|
237
226
|
let resolvedText = "";
|
|
@@ -253,25 +242,13 @@ function resolveTemplatesWithMapping(text, templates = [], templateBindings) {
|
|
|
253
242
|
}
|
|
254
243
|
let resolvedBody = fullMatch;
|
|
255
244
|
let isTemplate = false;
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
);
|
|
264
|
-
versionBody = boundVersion?.body;
|
|
265
|
-
} else {
|
|
266
|
-
const latestVersion = getLatestVersion(template);
|
|
267
|
-
versionBody = latestVersion?.body ?? template.body;
|
|
268
|
-
}
|
|
269
|
-
if (versionBody !== void 0) {
|
|
270
|
-
resolvedBody = resolveTemplates(versionBody, templates, {
|
|
271
|
-
bindings: templateBindings
|
|
272
|
-
});
|
|
273
|
-
isTemplate = true;
|
|
274
|
-
}
|
|
245
|
+
const template = templateMap.get(templateName);
|
|
246
|
+
if (template && getTemplateBody(template, templateBindings) !== void 0) {
|
|
247
|
+
resolvedBody = resolveTemplates(fullMatch, templates, {
|
|
248
|
+
bindings: templateBindings,
|
|
249
|
+
maxDepth: options?.maxDepth
|
|
250
|
+
});
|
|
251
|
+
isTemplate = true;
|
|
275
252
|
}
|
|
276
253
|
if (isTemplate) {
|
|
277
254
|
map.push({
|
|
@@ -316,9 +293,11 @@ function mapResolvedOffsetToRaw(resolvedOffset, map) {
|
|
|
316
293
|
if (inRange) {
|
|
317
294
|
if (seg.source === "raw") {
|
|
318
295
|
return seg.rawStart + (resolvedOffset - seg.resolvedStart);
|
|
319
|
-
} else {
|
|
320
|
-
return seg.rawStart;
|
|
321
296
|
}
|
|
297
|
+
if (resolvedOffset === seg.resolvedEnd) {
|
|
298
|
+
return seg.rawEnd;
|
|
299
|
+
}
|
|
300
|
+
return seg.rawStart;
|
|
322
301
|
}
|
|
323
302
|
}
|
|
324
303
|
return resolvedOffset;
|
|
@@ -331,9 +310,11 @@ function mapRawOffsetToResolved(rawOffset, map) {
|
|
|
331
310
|
if (inRange) {
|
|
332
311
|
if (seg.source === "raw") {
|
|
333
312
|
return seg.resolvedStart + (rawOffset - seg.rawStart);
|
|
334
|
-
} else {
|
|
335
|
-
return seg.resolvedStart;
|
|
336
313
|
}
|
|
314
|
+
if (rawOffset === seg.rawEnd) {
|
|
315
|
+
return seg.resolvedEnd;
|
|
316
|
+
}
|
|
317
|
+
return seg.resolvedStart;
|
|
337
318
|
}
|
|
338
319
|
}
|
|
339
320
|
return rawOffset;
|
|
@@ -6865,6 +6846,8 @@ export {
|
|
|
6865
6846
|
SmilieReplacer,
|
|
6866
6847
|
SpreadsheetController,
|
|
6867
6848
|
StreamingLayoutManager,
|
|
6849
|
+
TEMPLATE_DEPTH_ERROR,
|
|
6850
|
+
TEMPLATE_LOOP_ERROR,
|
|
6868
6851
|
TEMPLATE_REGEX,
|
|
6869
6852
|
TemplateSuggestions,
|
|
6870
6853
|
VARIABLE_REGEX,
|
|
@@ -6910,6 +6893,7 @@ export {
|
|
|
6910
6893
|
getEditorText,
|
|
6911
6894
|
getLatestVersion,
|
|
6912
6895
|
getLayoutedNodes,
|
|
6896
|
+
getTemplateBody,
|
|
6913
6897
|
getViewportMetrics,
|
|
6914
6898
|
globalImageCache,
|
|
6915
6899
|
handleImageInsertion,
|