@pixerate/editor 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,8 +1,9 @@
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
3
  export { ResolveTemplatesOptions, SourceMapSegment, extractInstructionNames, extractTemplateNames, extractVariableNames, getLatestVersion, mapRawOffsetToResolved, mapResolvedOffsetToRaw, resolveTemplates, resolveTemplatesWithMapping, resolveVariables, tokenizePrompt } from './grammar/index.cjs';
4
- export { ColorHighlighter, FontSize, GradientText, GradientTextOptions, Image, ImageOptions, LoadingNode, Markdown, Mention, MentionEntity, MentionOptions, RichTextPresetOptions, SlashCommandMatchData, SlashCommands, SlashCommandsOptions, SmilieReplacer, TemplateSuggestions, TemplateSuggestionsOptions, createMentionExtension, createRichTextPreset, findHexColors, handleImageInsertion, imagePastePluginKey, insertImageNode, removeImageNode, updateImageSrc } from './extensions/index.cjs';
5
- export { ExtractedMention, escapeHtml, extractMentionsFromDoc, getEditorMarkdown, getEditorText, htmlToPlainText, markdownToTipTapHtml, plainTextToTipTapHtml } from './serializers/index.cjs';
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
+ export { M as Mention, a as MentionEntity, b as MentionOptions, c as createMentionExtension } from './mention-Dcevh3ff.cjs';
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';
6
7
  import { Editor, EditorOptions, Content, Extensions } from '@tiptap/core';
7
8
  export { Content, Editor, EditorOptions, Extensions } from '@tiptap/core';
8
9
  export { ASTNode, BinaryOpNode, CellCoordinate, CellData, CellDep, CellFormat, CellRange, CellRefNode, ColumnBinding, ColumnType, DataSourceBinder, DependencyGraph, EvaluationContext, FormulaEvaluator, FormulaParser, FormulaToken, FormulaTokenType, FunctionCallNode, LiteralNode, PropertyRefNode, RangeNode, RowType, SpreadsheetColumn, SpreadsheetController, SpreadsheetControllerOptions, SpreadsheetDataSource, SpreadsheetDataSourceField, SpreadsheetDocument, SpreadsheetRow, UnaryOpNode, colNameToIndex, extractCellDependencies, indexToColName, parseCellReference, parseFormula, parseRange, tokenizeFormula } from './spreadsheet/index.cjs';
@@ -10,10 +11,10 @@ export { Command, HistoryManager, HistoryManagerOptions, HistoryState, MergedExe
10
11
  export { MarkdownOptions } from 'tiptap-markdown';
11
12
  import '@tiptap/pm/view';
12
13
  import '@tiptap/pm/model';
13
- import '@tiptap/extension-mention';
14
- import '@tiptap/suggestion';
15
14
  import '@tiptap/extension-image';
16
15
  import '@tiptap/pm/state';
16
+ import '@tiptap/extension-mention';
17
+ import '@tiptap/suggestion';
17
18
 
18
19
  interface EditorControllerOptions extends Partial<Omit<EditorOptions, "element" | "content">> {
19
20
  element?: Element | HTMLElement | null;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
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
3
  export { ResolveTemplatesOptions, SourceMapSegment, extractInstructionNames, extractTemplateNames, extractVariableNames, getLatestVersion, mapRawOffsetToResolved, mapResolvedOffsetToRaw, resolveTemplates, resolveTemplatesWithMapping, resolveVariables, tokenizePrompt } from './grammar/index.js';
4
- export { ColorHighlighter, FontSize, GradientText, GradientTextOptions, Image, ImageOptions, LoadingNode, Markdown, Mention, MentionEntity, MentionOptions, RichTextPresetOptions, SlashCommandMatchData, SlashCommands, SlashCommandsOptions, SmilieReplacer, TemplateSuggestions, TemplateSuggestionsOptions, createMentionExtension, createRichTextPreset, findHexColors, handleImageInsertion, imagePastePluginKey, insertImageNode, removeImageNode, updateImageSrc } from './extensions/index.js';
5
- export { ExtractedMention, escapeHtml, extractMentionsFromDoc, getEditorMarkdown, getEditorText, htmlToPlainText, markdownToTipTapHtml, plainTextToTipTapHtml } from './serializers/index.js';
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
+ export { M as Mention, a as MentionEntity, b as MentionOptions, c as createMentionExtension } from './mention-Dcevh3ff.js';
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';
6
7
  import { Editor, EditorOptions, Content, Extensions } from '@tiptap/core';
7
8
  export { Content, Editor, EditorOptions, Extensions } from '@tiptap/core';
8
9
  export { ASTNode, BinaryOpNode, CellCoordinate, CellData, CellDep, CellFormat, CellRange, CellRefNode, ColumnBinding, ColumnType, DataSourceBinder, DependencyGraph, EvaluationContext, FormulaEvaluator, FormulaParser, FormulaToken, FormulaTokenType, FunctionCallNode, LiteralNode, PropertyRefNode, RangeNode, RowType, SpreadsheetColumn, SpreadsheetController, SpreadsheetControllerOptions, SpreadsheetDataSource, SpreadsheetDataSourceField, SpreadsheetDocument, SpreadsheetRow, UnaryOpNode, colNameToIndex, extractCellDependencies, indexToColName, parseCellReference, parseFormula, parseRange, tokenizeFormula } from './spreadsheet/index.js';
@@ -10,10 +11,10 @@ export { Command, HistoryManager, HistoryManagerOptions, HistoryState, MergedExe
10
11
  export { MarkdownOptions } from 'tiptap-markdown';
11
12
  import '@tiptap/pm/view';
12
13
  import '@tiptap/pm/model';
13
- import '@tiptap/extension-mention';
14
- import '@tiptap/suggestion';
15
14
  import '@tiptap/extension-image';
16
15
  import '@tiptap/pm/state';
16
+ import '@tiptap/extension-mention';
17
+ import '@tiptap/suggestion';
17
18
 
18
19
  interface EditorControllerOptions extends Partial<Omit<EditorOptions, "element" | "content">> {
19
20
  element?: Element | HTMLElement | null;
package/dist/index.js CHANGED
@@ -2200,6 +2200,150 @@ function createRichTextPreset(options = {}) {
2200
2200
  return extensions2;
2201
2201
  }
2202
2202
 
2203
+ // src/serializers/mentions.ts
2204
+ var MENTION_REGEX = /(?:^|[\s>(*_"';\\/[\]{}~`:]|&quot;|&gt;|&lt;|&amp;)@(?:"([^"]+)"|&quot;([^&]+)&quot;|([a-zA-Z0-9_-]+(?:\.[a-zA-Z0-9_-]+)*))/g;
2205
+ var MARKDOWN_MENTION_SPLIT_REGEX = /(```[\s\S]*?```|~~~[\s\S]*?~~~|<pre[\s\S]*?<\/pre>|<code[\s\S]*?<\/code>|`[^`\n]+`|<span\b[^>]*\b(?:data-type=["']mention["']|class=["'][^"']*pixerate-mention-node[^"']*["']|data-mention=["'][^"']*["'])[^>]*>[\s\S]*?<\/span>|<[^>]+>|\]\([^)]+\)|(?:https?|file|vscode|cursor|mailto):\/\/[^\s<)]+)/gi;
2206
+ function stripMarkdownCode(content) {
2207
+ if (!content || typeof content !== "string") return "";
2208
+ return content.replace(/```[\s\S]*?```/g, "").replace(/~~~[\s\S]*?~~~/g, "").replace(/<pre[\s\S]*?<\/pre>/gi, "").replace(/<code[\s\S]*?<\/code>/gi, "").replace(/`[^`\n]*`/g, "");
2209
+ }
2210
+ function extractMentions(content) {
2211
+ if (!content || typeof content !== "string") return [];
2212
+ const normalizedMentionNodes = content.replace(
2213
+ /<span\b[^>]*\b(?:data-type=["']mention["']|class=["'][^"']*pixerate-mention-node[^"']*["'])[^>]*>([\s\S]*?)<\/span>/gi,
2214
+ (match2, inner) => {
2215
+ const labelMatch = match2.match(/\bdata-label=["']([^"']+)["']/i);
2216
+ if (labelMatch) return ` @${labelMatch[1]} `;
2217
+ const idMatch = match2.match(/\bdata-id=["']([^"']+)["']/i);
2218
+ if (idMatch) return ` @${idMatch[1]} `;
2219
+ return ` ${inner} `;
2220
+ }
2221
+ );
2222
+ const cleanContent = stripMarkdownCode(normalizedMentionNodes);
2223
+ const withoutUrls = cleanContent.replace(/(?:https?|ftp|file|vscode|cursor|mailto):\/\/[^\s<>()]+/gi, "").replace(/\]\([^)]*\)/g, "]");
2224
+ const textOnly = withoutUrls.replace(/<[^>]+>/g, " ");
2225
+ const mentions = [];
2226
+ const seen = /* @__PURE__ */ new Set();
2227
+ const regex = new RegExp(MENTION_REGEX.source, "g");
2228
+ let match;
2229
+ while ((match = regex.exec(textOnly)) !== null) {
2230
+ const handle = (match[1] ?? match[2] ?? match[3] ?? "").trim();
2231
+ if (handle && !seen.has(handle)) {
2232
+ seen.add(handle);
2233
+ mentions.push(handle);
2234
+ }
2235
+ }
2236
+ return mentions;
2237
+ }
2238
+ function parseMentionSegments(content) {
2239
+ if (!content) return [];
2240
+ const segments = [];
2241
+ const regex = new RegExp(MENTION_REGEX.source, "g");
2242
+ let lastIndex = 0;
2243
+ let match;
2244
+ while ((match = regex.exec(content)) !== null) {
2245
+ const fullMatch = match[0];
2246
+ const atIndex = fullMatch.indexOf("@");
2247
+ const prefix = atIndex > 0 ? fullMatch.slice(0, atIndex) : "";
2248
+ const mentionToken = fullMatch.slice(atIndex);
2249
+ const handle = match[1] ?? match[2] ?? match[3];
2250
+ const matchStart = match.index + prefix.length;
2251
+ if (matchStart > lastIndex) {
2252
+ segments.push({
2253
+ type: "text",
2254
+ value: content.slice(lastIndex, matchStart)
2255
+ });
2256
+ }
2257
+ segments.push({
2258
+ type: "mention",
2259
+ value: mentionToken,
2260
+ handle
2261
+ });
2262
+ lastIndex = matchStart + mentionToken.length;
2263
+ }
2264
+ if (lastIndex < content.length) {
2265
+ segments.push({
2266
+ type: "text",
2267
+ value: content.slice(lastIndex)
2268
+ });
2269
+ }
2270
+ return segments;
2271
+ }
2272
+ function preprocessMarkdownMentions(content, optionsOrMentionables = []) {
2273
+ if (!content || typeof content !== "string") return "";
2274
+ const options = Array.isArray(optionsOrMentionables) ? { mentionables: optionsOrMentionables } : optionsOrMentionables;
2275
+ const allMentionables = options.mentionables || [];
2276
+ const defaultType = options.defaultType || "user";
2277
+ const resolveMention = options.resolveMention;
2278
+ const parts = content.split(MARKDOWN_MENTION_SPLIT_REGEX);
2279
+ return parts.map((part) => {
2280
+ if (!part) return "";
2281
+ if (part.startsWith("```") || part.startsWith("~~~") || part.startsWith("`") || part.startsWith("](") || /^(?:https?|file|vscode|cursor|mailto):\/\//i.test(part) || /^<pre[\s>]/i.test(part) || /^<code[\s>]/i.test(part) || /^<[^>]+>$/i.test(part) || /^<span\b[^>]*\b(?:data-type=["']mention["']|class=["'][^"']*pixerate-mention-node[^"']*["']|data-mention=["'][^"']*["'])/i.test(
2282
+ part
2283
+ )) {
2284
+ return part;
2285
+ }
2286
+ const regex = new RegExp(MENTION_REGEX.source, "g");
2287
+ return part.replace(regex, (match, quotedHandle, escapedQuotedHandle, standardHandle) => {
2288
+ const atIndex = match.indexOf("@");
2289
+ const prefix = atIndex > 0 ? match.slice(0, atIndex) : "";
2290
+ const rawHandle = (quotedHandle || escapedQuotedHandle || standardHandle || "").trim();
2291
+ if (!rawHandle) return match;
2292
+ const lowerHandle = rawHandle.toLowerCase();
2293
+ const entity = allMentionables.find((e) => {
2294
+ if (e.label?.toLowerCase() === lowerHandle) return true;
2295
+ if (e.handle?.toLowerCase() === lowerHandle) return true;
2296
+ if (e.name?.toLowerCase() === lowerHandle) return true;
2297
+ if (e.id?.toLowerCase() === lowerHandle) return true;
2298
+ if (e.type === "agent" && `agent${(e.handle || e.label || "").toLowerCase()}` === lowerHandle) return true;
2299
+ if (e.aliases?.some(
2300
+ (a) => a.toLowerCase() === lowerHandle || e.type === "agent" && `agent${a.toLowerCase()}` === lowerHandle
2301
+ )) {
2302
+ return true;
2303
+ }
2304
+ return false;
2305
+ });
2306
+ let id = entity?.id;
2307
+ let label = entity?.label || entity?.handle || rawHandle;
2308
+ let type = entity?.type;
2309
+ let avatarUrl = entity?.avatarUrl;
2310
+ let color = entity?.color || entity?.hexColor;
2311
+ if (!entity) {
2312
+ const customResolved = resolveMention?.(rawHandle);
2313
+ if (customResolved) {
2314
+ id = customResolved.id ?? id;
2315
+ label = customResolved.label ?? customResolved.handle ?? label;
2316
+ type = customResolved.type ?? type;
2317
+ avatarUrl = customResolved.avatarUrl ?? avatarUrl;
2318
+ color = customResolved.color ?? customResolved.hexColor ?? color;
2319
+ } else {
2320
+ const stripped = lowerHandle.replace(/^agent[\s\-_]*/i, "");
2321
+ if (["supervisor", "coordinator", "planner", "validator", "executor"].includes(stripped)) {
2322
+ type = "agent";
2323
+ id = stripped;
2324
+ label = stripped;
2325
+ } else if (lowerHandle === "agents") {
2326
+ type = "team";
2327
+ id = "agents";
2328
+ label = "agents";
2329
+ } else {
2330
+ type = defaultType;
2331
+ id = rawHandle;
2332
+ label = rawHandle;
2333
+ }
2334
+ }
2335
+ }
2336
+ const avatarAttr = avatarUrl ? ` data-avatar-url="${escapeHtml(avatarUrl)}"` : "";
2337
+ const colorAttr = color ? ` data-color="${escapeHtml(color)}"` : "";
2338
+ return `${prefix}<span class="pixerate-mention-node" data-type="mention" data-id="${escapeHtml(
2339
+ id || label
2340
+ )}" data-label="${escapeHtml(label)}" data-mention-suggestion-char="@" data-type-name="${escapeHtml(
2341
+ type || defaultType
2342
+ )}"${avatarAttr}${colorAttr}>@${escapeHtml(label)}</span>`;
2343
+ });
2344
+ }).join("");
2345
+ }
2346
+
2203
2347
  // src/serializers/plain-text.ts
2204
2348
  function escapeHtml(text) {
2205
2349
  if (!text) return "";
@@ -2324,6 +2468,16 @@ function extractMentionsFromDoc(docOrEditor) {
2324
2468
  });
2325
2469
  }
2326
2470
  }
2471
+ if (mentions.length === 0) {
2472
+ const rawHandles = extractMentions(docOrEditor);
2473
+ for (const handle of rawHandles) {
2474
+ mentions.push({
2475
+ id: handle,
2476
+ label: handle,
2477
+ type: "user"
2478
+ });
2479
+ }
2480
+ }
2327
2481
  }
2328
2482
  return mentions;
2329
2483
  }
@@ -2343,9 +2497,31 @@ md2.validateLink = (url) => {
2343
2497
  }
2344
2498
  return defaultValidateLink.call(md2, url);
2345
2499
  };
2346
- function markdownToTipTapHtml(markdown) {
2500
+ function preprocessMarkdownFileLinks(content) {
2501
+ if (!content) return "";
2502
+ return content.replace(
2503
+ /\[([^\]]+)\]\(((?:file|vscode|cursor):\/\/[^)]+)\)/g,
2504
+ (_match, rawLabel, href) => {
2505
+ const trimmed = rawLabel.trim();
2506
+ const codeMatch = trimmed.match(/^`([^`]+)`$/);
2507
+ const labelContent = codeMatch ? `<code>${codeMatch[1]}</code>` : trimmed;
2508
+ return `<a href="${href}" data-file-link="true" title="Click to copy file path">${labelContent}</a>`;
2509
+ }
2510
+ );
2511
+ }
2512
+ function markdownToTipTapHtml(markdown, options) {
2347
2513
  if (!markdown) return "<p></p>";
2348
- return md2.render(markdown);
2514
+ let content = markdown;
2515
+ if (options?.preprocessFileLinks) {
2516
+ content = preprocessMarkdownFileLinks(content);
2517
+ }
2518
+ if (options?.preprocessMentions || options?.mentionables || options?.preprocessOptions) {
2519
+ const mentionOpts = options.preprocessOptions || {
2520
+ mentionables: options.mentionables
2521
+ };
2522
+ content = preprocessMarkdownMentions(content, mentionOpts);
2523
+ }
2524
+ return md2.render(content);
2349
2525
  }
2350
2526
  function getEditorMarkdown(editor) {
2351
2527
  if (!editor) return "";
@@ -4084,6 +4260,8 @@ export {
4084
4260
  INSTRUCTION_REGEX,
4085
4261
  Image2 as Image,
4086
4262
  LoadingNode,
4263
+ MARKDOWN_MENTION_SPLIT_REGEX,
4264
+ MENTION_REGEX,
4087
4265
  Markdown2 as Markdown,
4088
4266
  Mention,
4089
4267
  SlashCommands,
@@ -4102,6 +4280,7 @@ export {
4102
4280
  escapeHtml,
4103
4281
  extractCellDependencies,
4104
4282
  extractInstructionNames,
4283
+ extractMentions,
4105
4284
  extractMentionsFromDoc,
4106
4285
  extractTemplateNames,
4107
4286
  extractVariableNames,
@@ -4120,12 +4299,16 @@ export {
4120
4299
  markdownToTipTapHtml,
4121
4300
  parseCellReference,
4122
4301
  parseFormula,
4302
+ parseMentionSegments,
4123
4303
  parseRange,
4124
4304
  plainTextToTipTapHtml,
4305
+ preprocessMarkdownFileLinks,
4306
+ preprocessMarkdownMentions,
4125
4307
  removeImageNode,
4126
4308
  resolveTemplates,
4127
4309
  resolveTemplatesWithMapping,
4128
4310
  resolveVariables,
4311
+ stripMarkdownCode,
4129
4312
  templateRegex,
4130
4313
  tokenizeFormula,
4131
4314
  tokenizePrompt,