@pixerate/editor 0.268.2 → 0.269.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.
Files changed (57) hide show
  1. package/dist/agent/index.cjs +27 -27
  2. package/dist/agent/index.js +1 -1
  3. package/dist/animation-editor/index.cjs +61 -61
  4. package/dist/animation-editor/index.js +5 -5
  5. package/dist/brushes/import/abr.d.cts +48 -0
  6. package/dist/brushes/import/abr.d.ts +48 -0
  7. package/dist/brushes/import/bplist.d.cts +24 -0
  8. package/dist/brushes/import/bplist.d.ts +24 -0
  9. package/dist/brushes/import/pack.d.cts +82 -0
  10. package/dist/brushes/import/pack.d.ts +82 -0
  11. package/dist/brushes/import/zip.d.cts +31 -0
  12. package/dist/brushes/import/zip.d.ts +31 -0
  13. package/dist/brushes/index.cjs +26 -6
  14. package/dist/brushes/index.d.cts +2 -0
  15. package/dist/brushes/index.d.ts +2 -0
  16. package/dist/brushes/index.js +22 -2
  17. package/dist/{chunk-SIFAIGB3.js → chunk-3AJCEJNH.js} +2 -162
  18. package/dist/{chunk-YXP6X3SY.cjs → chunk-3KNQ2W6X.cjs} +697 -10
  19. package/dist/{chunk-QNY7BDFP.js → chunk-4CPOKP27.js} +1 -1
  20. package/dist/{chunk-J4GXP53R.cjs → chunk-4NMPUJUK.cjs} +86 -86
  21. package/dist/{chunk-LDOD7VCT.js → chunk-4YSPQGZW.js} +1 -1
  22. package/dist/{chunk-JBB3GDBB.cjs → chunk-56RHCIJV.cjs} +2 -2
  23. package/dist/{chunk-4IMD2TLY.cjs → chunk-AI4F33IV.cjs} +3166 -2966
  24. package/dist/{chunk-YOVXQHA3.cjs → chunk-BENSE3VX.cjs} +23 -23
  25. package/dist/{chunk-VDGBHYC7.js → chunk-F7OO3DHP.js} +157 -1
  26. package/dist/{chunk-UVTO3D4E.js → chunk-FUDP5QBB.js} +1 -1
  27. package/dist/{chunk-3XDSNIGF.js → chunk-ININNHLM.js} +687 -0
  28. package/dist/{chunk-WIC7TG73.cjs → chunk-M4UQA2T4.cjs} +18 -18
  29. package/dist/{chunk-ITURMC2M.js → chunk-N3UMQVKX.js} +176 -176
  30. package/dist/{chunk-UWEQ55MY.cjs → chunk-N4KP3UQR.cjs} +157 -1
  31. package/dist/{chunk-D5BXSOSU.js → chunk-QGVTOCNB.js} +3118 -2918
  32. package/dist/{chunk-M6DNZNVY.js → chunk-RWDSSK2I.js} +4 -2
  33. package/dist/{chunk-CVFAAZXE.cjs → chunk-SPIO2GJU.cjs} +8 -6
  34. package/dist/{chunk-RHEMMGCN.cjs → chunk-T4JPGBW3.cjs} +173 -173
  35. package/dist/{chunk-HFY5LG5J.js → chunk-THBJHPUL.js} +1 -1
  36. package/dist/{chunk-NPWWSCWT.cjs → chunk-VBRHE4AM.cjs} +35 -35
  37. package/dist/{chunk-AZC2NDAR.js → chunk-WB22XMW3.js} +6 -6
  38. package/dist/{chunk-NIBFDFYW.cjs → chunk-YBMUHIOM.cjs} +12 -172
  39. package/dist/extensions/index.cjs +18 -4
  40. package/dist/extensions/index.d.cts +1 -0
  41. package/dist/extensions/index.d.ts +1 -0
  42. package/dist/extensions/index.js +17 -3
  43. package/dist/extensions/prompt-editor.d.cts +109 -0
  44. package/dist/extensions/prompt-editor.d.ts +109 -0
  45. package/dist/generation/index.cjs +15 -15
  46. package/dist/generation/index.js +3 -3
  47. package/dist/grammar/index.cjs +4 -4
  48. package/dist/grammar/index.js +7 -7
  49. package/dist/image-editor/index.cjs +785 -785
  50. package/dist/image-editor/index.js +6 -6
  51. package/dist/index.cjs +27 -13
  52. package/dist/index.js +23 -9
  53. package/dist/paint-editor/index.cjs +91 -91
  54. package/dist/paint-editor/index.js +6 -6
  55. package/dist/vector/index.cjs +1001 -1001
  56. package/dist/vector/index.js +6 -6
  57. package/package.json +1 -1
@@ -4,9 +4,9 @@ var _chunkN3KJFGXTcjs = require('./chunk-N3KJFGXT.cjs');
4
4
 
5
5
 
6
6
 
7
+ var _chunkYBMUHIOMcjs = require('./chunk-YBMUHIOM.cjs');
7
8
 
8
9
 
9
- var _chunkNIBFDFYWcjs = require('./chunk-NIBFDFYW.cjs');
10
10
 
11
11
 
12
12
 
@@ -15,20 +15,20 @@ var _chunkNIBFDFYWcjs = require('./chunk-NIBFDFYW.cjs');
15
15
 
16
16
 
17
17
 
18
- var _chunkUWEQ55MYcjs = require('./chunk-UWEQ55MY.cjs');
18
+ var _chunkN4KP3UQRcjs = require('./chunk-N4KP3UQR.cjs');
19
19
 
20
20
  // src/grammar/resolver.ts
21
21
  function resolveTemplates(text, templates = [], options) {
22
- return _chunkNIBFDFYWcjs.resolvePrompt.call(void 0, text, templates, options).text;
22
+ return _chunkYBMUHIOMcjs.resolvePrompt.call(void 0, text, templates, options).text;
23
23
  }
24
24
  function resolveVariables(text, values) {
25
25
  if (!text) return "";
26
- return _chunkNIBFDFYWcjs.resolvePrompt.call(void 0, text, [], { values }).text;
26
+ return _chunkYBMUHIOMcjs.resolvePrompt.call(void 0, text, [], { values }).text;
27
27
  }
28
28
  function extractTemplateNames(text) {
29
29
  if (!text) return [];
30
30
  const set = /* @__PURE__ */ new Set();
31
- const regex = new RegExp(_chunkUWEQ55MYcjs.TEMPLATE_REGEX.source, _chunkUWEQ55MYcjs.TEMPLATE_REGEX.flags);
31
+ const regex = new RegExp(_chunkN4KP3UQRcjs.TEMPLATE_REGEX.source, _chunkN4KP3UQRcjs.TEMPLATE_REGEX.flags);
32
32
  let match;
33
33
  while ((match = regex.exec(text)) !== null) {
34
34
  set.add(match[1].trim());
@@ -38,17 +38,17 @@ function extractTemplateNames(text) {
38
38
  function extractVariableNames(text) {
39
39
  if (!text) return [];
40
40
  const set = /* @__PURE__ */ new Set();
41
- const regex = new RegExp(_chunkUWEQ55MYcjs.VARIABLE_REGEX.source, _chunkUWEQ55MYcjs.VARIABLE_REGEX.flags);
41
+ const regex = new RegExp(_chunkN4KP3UQRcjs.VARIABLE_REGEX.source, _chunkN4KP3UQRcjs.VARIABLE_REGEX.flags);
42
42
  let comparisonStarts;
43
43
  let match;
44
44
  while ((match = regex.exec(text)) !== null) {
45
- const parsed = _chunkUWEQ55MYcjs.parseVariableBody.call(void 0, match[1]);
45
+ const parsed = _chunkN4KP3UQRcjs.parseVariableBody.call(void 0, match[1]);
46
46
  let name = parsed.name;
47
47
  if (parsed.kind === "conditional" && parsed.conditional !== "end") {
48
- const subject = _chunkUWEQ55MYcjs.conditionSubject.call(void 0, name);
48
+ const subject = _chunkN4KP3UQRcjs.conditionSubject.call(void 0, name);
49
49
  if (subject) {
50
50
  comparisonStarts ??= new Set(
51
- _chunkNIBFDFYWcjs.tokenizePrompt.call(void 0, text).filter((token) => token.comparison).map((token) => token.start)
51
+ _chunkN4KP3UQRcjs.tokenizePrompt.call(void 0, text).filter((token) => token.comparison).map((token) => token.start)
52
52
  );
53
53
  if (comparisonStarts.has(match.index)) name = subject;
54
54
  }
@@ -60,7 +60,7 @@ function extractVariableNames(text) {
60
60
  function extractInstructionNames(text) {
61
61
  if (!text) return [];
62
62
  const set = /* @__PURE__ */ new Set();
63
- const regex = new RegExp(_chunkUWEQ55MYcjs.INSTRUCTION_REGEX.source, _chunkUWEQ55MYcjs.INSTRUCTION_REGEX.flags);
63
+ const regex = new RegExp(_chunkN4KP3UQRcjs.INSTRUCTION_REGEX.source, _chunkN4KP3UQRcjs.INSTRUCTION_REGEX.flags);
64
64
  let match;
65
65
  while ((match = regex.exec(text)) !== null) {
66
66
  set.add(match[1].trim());
@@ -72,7 +72,7 @@ function extractInstructionNames(text) {
72
72
  function resolveTemplatesWithMapping(text, templates = [], templateBindings, options) {
73
73
  if (_optionalChain([options, 'optionalAccess', _2 => _2.values]) === void 0 && (!templates || templates.length === 0 || !text.includes("{{"))) {
74
74
  return {
75
- diagnostics: _chunkNIBFDFYWcjs.getPromptDiagnostics.call(void 0, text),
75
+ diagnostics: _chunkN4KP3UQRcjs.getPromptDiagnostics.call(void 0, text),
76
76
  text,
77
77
  map: [
78
78
  {
@@ -85,7 +85,7 @@ function resolveTemplatesWithMapping(text, templates = [], templateBindings, opt
85
85
  ]
86
86
  };
87
87
  }
88
- return _chunkNIBFDFYWcjs.resolvePrompt.call(void 0, text, templates, {
88
+ return _chunkYBMUHIOMcjs.resolvePrompt.call(void 0, text, templates, {
89
89
  bindings: templateBindings,
90
90
  maxDepth: _optionalChain([options, 'optionalAccess', _3 => _3.maxDepth]),
91
91
  values: _optionalChain([options, 'optionalAccess', _4 => _4.values])
@@ -152,7 +152,7 @@ function extractVariables(text, options = {}) {
152
152
  return descriptor;
153
153
  };
154
154
  const visit = (source, visited, depth, templateName) => {
155
- for (const token of _chunkNIBFDFYWcjs.tokenizePrompt.call(void 0, source)) {
155
+ for (const token of _chunkN4KP3UQRcjs.tokenizePrompt.call(void 0, source)) {
156
156
  if (token.type === "variable") {
157
157
  const descriptor = describe(token.value, templateName);
158
158
  descriptor.usedAsValue = true;
@@ -171,7 +171,7 @@ function extractVariables(text, options = {}) {
171
171
  if (!template || visited.has(token.value) || depth + 1 > maxDepth) {
172
172
  continue;
173
173
  }
174
- const body = _chunkNIBFDFYWcjs.getTemplateBody.call(void 0, template, options.bindings);
174
+ const body = _chunkYBMUHIOMcjs.getTemplateBody.call(void 0, template, options.bindings);
175
175
  if (body === void 0) continue;
176
176
  visit(body, new Set(visited).add(token.value), depth + 1, token.value);
177
177
  }
@@ -570,7 +570,7 @@ function mergeRecords(template, source, options = {}) {
570
570
  if (typeof options.skipIf === "function") {
571
571
  skip = options.skipIf;
572
572
  } else if (typeof options.skipIf === "string" && options.skipIf.trim()) {
573
- const parsed = _chunkUWEQ55MYcjs.parseConditionExpression.call(void 0, options.skipIf);
573
+ const parsed = _chunkN4KP3UQRcjs.parseConditionExpression.call(void 0, options.skipIf);
574
574
  if ("error" in parsed) {
575
575
  diagnostics.push({
576
576
  code: "invalid-skip-condition",
@@ -580,12 +580,12 @@ function mergeRecords(template, source, options = {}) {
580
580
  const field = _nullishCoalesce(mapping[parsed.name], () => ( matchFields([parsed.name], data.fields).mapping[parsed.name]));
581
581
  skip = (record, values) => {
582
582
  if (field && !Object.prototype.hasOwnProperty.call(values, parsed.name) && Object.prototype.hasOwnProperty.call(record, field)) {
583
- return _chunkUWEQ55MYcjs.evaluateConditionExpression.call(void 0, parsed, {
583
+ return _chunkN4KP3UQRcjs.evaluateConditionExpression.call(void 0, parsed, {
584
584
  ...values,
585
585
  [parsed.name]: record[field]
586
586
  });
587
587
  }
588
- return _chunkUWEQ55MYcjs.evaluateConditionExpression.call(void 0, parsed, values);
588
+ return _chunkN4KP3UQRcjs.evaluateConditionExpression.call(void 0, parsed, values);
589
589
  };
590
590
  }
591
591
  }
@@ -619,7 +619,7 @@ function mergeRecords(template, source, options = {}) {
619
619
  });
620
620
  break;
621
621
  }
622
- const resolved = _chunkNIBFDFYWcjs.resolvePrompt.call(void 0, template, options.templates, {
622
+ const resolved = _chunkYBMUHIOMcjs.resolvePrompt.call(void 0, template, options.templates, {
623
623
  bindings: options.bindings,
624
624
  maxDepth: options.maxDepth,
625
625
  values
@@ -24,11 +24,176 @@ import {
24
24
  safeMergeAttributes
25
25
  } from "./chunk-6IN474P4.js";
26
26
 
27
+ // src/extensions/table/nesting.ts
28
+ import { Fragment, Slice } from "@tiptap/pm/model";
29
+ import { Plugin, PluginKey, Selection } from "@tiptap/pm/state";
30
+ import {
31
+ CellSelection,
32
+ __pastedCells,
33
+ handlePaste as handleTablePaste
34
+ } from "@tiptap/pm/tables";
35
+ var ALLOW_NESTED_TABLES_META = "allowNestedTables";
36
+ var tableNestingPluginKey = new PluginKey("tableNesting");
37
+ var roleOf = (node) => node.type.spec.tableRole;
38
+ var isTableNode = (node) => roleOf(node) === "table";
39
+ function outermostTableDepth($pos) {
40
+ for (let d = 1; d <= $pos.depth; d++) if (isTableNode($pos.node(d))) return d;
41
+ return -1;
42
+ }
43
+ function isInTableCell($pos) {
44
+ for (let d = $pos.depth; d > 0; d--) {
45
+ const role = roleOf($pos.node(d));
46
+ if (role === "cell" || role === "header_cell") return true;
47
+ }
48
+ return false;
49
+ }
50
+ function sliceContainsTable(content) {
51
+ const fragment = content instanceof Slice ? content.content : content;
52
+ let found = false;
53
+ fragment.descendants((node) => {
54
+ if (found) return false;
55
+ if (isTableNode(node)) found = true;
56
+ return !found;
57
+ });
58
+ return found;
59
+ }
60
+ function insertSliceAfterTable(tr, from, to, slice) {
61
+ const $from = tr.doc.resolve(from);
62
+ const depth = outermostTableDepth($from);
63
+ if (depth < 0) return null;
64
+ const tableStart = $from.before(depth);
65
+ const tableEnd = $from.after(depth);
66
+ if (to > from && to < tableEnd) {
67
+ if (tr.selection instanceof CellSelection && tr.selection.from === from && tr.selection.to === to) {
68
+ tr.deleteSelection();
69
+ } else {
70
+ tr.delete(from, to);
71
+ }
72
+ }
73
+ const table = tr.doc.nodeAt(tableStart);
74
+ if (!table) return null;
75
+ const after = tableStart + table.nodeSize;
76
+ const before = tr.doc.content.size;
77
+ tr.replace(after, after, new Slice(slice.content, 0, 0));
78
+ return after + (tr.doc.content.size - before);
79
+ }
80
+ function handleTablePasteWithoutNesting(view, event, slice) {
81
+ const { state } = view;
82
+ const { selection } = state;
83
+ if (outermostTableDepth(selection.$from) < 0) return false;
84
+ if (selection instanceof CellSelection || __pastedCells(slice)) {
85
+ if (handleTablePaste(view, event, slice)) return true;
86
+ }
87
+ if (!sliceContainsTable(slice)) return false;
88
+ const tr = state.tr;
89
+ const end = insertSliceAfterTable(tr, selection.from, selection.to, slice);
90
+ if (end === null) return false;
91
+ tr.setSelection(Selection.near(tr.doc.resolve(end), -1));
92
+ view.dispatch(tr.scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste"));
93
+ return true;
94
+ }
95
+ function changedRanges(transactions, skip2) {
96
+ let ranges = [];
97
+ for (const tr of transactions) {
98
+ const skipped = skip2(tr);
99
+ for (const step of tr.steps) {
100
+ const map = step.getMap();
101
+ ranges = ranges.map(([from, to]) => [map.map(from, 1), map.map(to, -1)]).filter(([from, to]) => to > from);
102
+ if (skipped) continue;
103
+ map.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
104
+ if (newEnd > newStart) ranges.push([newStart, newEnd]);
105
+ });
106
+ }
107
+ }
108
+ return ranges;
109
+ }
110
+ function findNestedTables(doc, ranges) {
111
+ const found = /* @__PURE__ */ new Set();
112
+ for (const [from, to] of ranges) {
113
+ doc.nodesBetween(from, to, (node, pos) => {
114
+ if (!isTableNode(node) || pos < from) return true;
115
+ if (isInTableCell(doc.resolve(pos))) {
116
+ found.add(pos);
117
+ return false;
118
+ }
119
+ return true;
120
+ });
121
+ }
122
+ const sorted = [...found].sort((a, b) => a - b);
123
+ const outer = [];
124
+ for (const pos of sorted) {
125
+ const last = outer[outer.length - 1];
126
+ if (last === void 0 || pos >= last + doc.nodeAt(last).nodeSize) outer.push(pos);
127
+ }
128
+ return outer;
129
+ }
130
+ function unnestTables(tr, ranges) {
131
+ let changed = false;
132
+ for (let round = 0; round < 32 && ranges.length; round++) {
133
+ const nested = findNestedTables(tr.doc, ranges);
134
+ if (!nested.length) break;
135
+ const groups = /* @__PURE__ */ new Map();
136
+ for (const pos of nested) {
137
+ const $pos = tr.doc.resolve(pos);
138
+ const outer = $pos.before(outermostTableDepth($pos));
139
+ groups.set(outer, [...groups.get(outer) ?? [], pos]);
140
+ }
141
+ const next = [];
142
+ for (const outer of [...groups.keys()].sort((a, b) => b - a)) {
143
+ const positions = groups.get(outer);
144
+ const nodes = positions.map((pos) => tr.doc.nodeAt(pos));
145
+ for (let i = positions.length - 1; i >= 0; i--) {
146
+ const pos = positions[i];
147
+ const node = nodes[i];
148
+ const $pos = tr.doc.resolve(pos);
149
+ const parent = $pos.parent;
150
+ const filler = parent.childCount === 1 ? parent.type.contentMatch.defaultType?.createAndFill() : null;
151
+ if (filler) tr.replaceWith(pos, pos + node.nodeSize, filler);
152
+ else tr.delete(pos, pos + node.nodeSize);
153
+ }
154
+ const table = tr.doc.nodeAt(outer);
155
+ const after = outer + table.nodeSize;
156
+ const fragment = Fragment.fromArray(nodes);
157
+ tr.insert(after, fragment);
158
+ next.push([after, after + fragment.size]);
159
+ changed = true;
160
+ }
161
+ ranges = next;
162
+ }
163
+ return changed;
164
+ }
165
+ function replacesDocument(tr) {
166
+ return tr.steps.some((step, i) => {
167
+ const { from, to } = step;
168
+ return from === 0 && to !== void 0 && to >= tr.docs[i].content.size;
169
+ });
170
+ }
171
+ var skip = (tr) => !tr.docChanged || tr.getMeta(ALLOW_NESTED_TABLES_META) === true || // Undo/redo and remote collaborative changes restore what was there.
172
+ !!tr.getMeta("history$") || !!tr.getMeta("y-sync$") || // Other plugins' housekeeping, e.g. Track Changes putting a deleted
173
+ // (nested) table back so the deletion can be reviewed.
174
+ !!tr.getMeta("appendedTransaction") || replacesDocument(tr);
175
+ function createTableNestingPlugin() {
176
+ return new Plugin({
177
+ key: tableNestingPluginKey,
178
+ props: {
179
+ handlePaste: (view, event, slice) => handleTablePasteWithoutNesting(view, event, slice)
180
+ },
181
+ appendTransaction(transactions, _oldState, newState) {
182
+ if (transactions.every(skip)) return null;
183
+ const ranges = changedRanges(transactions, skip);
184
+ if (!ranges.length) return null;
185
+ const tr = newState.tr;
186
+ if (!unnestTables(tr, ranges)) return null;
187
+ return tr;
188
+ }
189
+ });
190
+ }
191
+
27
192
  // src/extensions/comments.ts
28
193
  import { Mark } from "@tiptap/core";
29
- import { Plugin, PluginKey, TextSelection } from "@tiptap/pm/state";
194
+ import { Plugin as Plugin2, PluginKey as PluginKey2, TextSelection } from "@tiptap/pm/state";
30
195
  import { Decoration, DecorationSet } from "@tiptap/pm/view";
31
- var commentsPluginKey = new PluginKey("comments");
196
+ var commentsPluginKey = new PluginKey2("comments");
32
197
  var COMMENT_MARK_NAME = "comment";
33
198
  function findCommentRanges(doc) {
34
199
  const result = /* @__PURE__ */ new Map();
@@ -218,7 +383,7 @@ var Comments = Mark.create({
218
383
  return set;
219
384
  };
220
385
  return [
221
- new Plugin({
386
+ new Plugin2({
222
387
  key: commentsPluginKey,
223
388
  props: {
224
389
  decorations: (state) => buildDecorations2(state.doc)
@@ -268,171 +433,6 @@ function getCommentAuthor(editor) {
268
433
  return ext ? resolveAuthor(ext.options.author) : null;
269
434
  }
270
435
 
271
- // src/extensions/table/nesting.ts
272
- import { Fragment, Slice } from "@tiptap/pm/model";
273
- import { Plugin as Plugin2, PluginKey as PluginKey2, Selection } from "@tiptap/pm/state";
274
- import {
275
- CellSelection,
276
- __pastedCells,
277
- handlePaste as handleTablePaste
278
- } from "@tiptap/pm/tables";
279
- var ALLOW_NESTED_TABLES_META = "allowNestedTables";
280
- var tableNestingPluginKey = new PluginKey2("tableNesting");
281
- var roleOf = (node) => node.type.spec.tableRole;
282
- var isTableNode = (node) => roleOf(node) === "table";
283
- function outermostTableDepth($pos) {
284
- for (let d = 1; d <= $pos.depth; d++) if (isTableNode($pos.node(d))) return d;
285
- return -1;
286
- }
287
- function isInTableCell($pos) {
288
- for (let d = $pos.depth; d > 0; d--) {
289
- const role = roleOf($pos.node(d));
290
- if (role === "cell" || role === "header_cell") return true;
291
- }
292
- return false;
293
- }
294
- function sliceContainsTable(content) {
295
- const fragment = content instanceof Slice ? content.content : content;
296
- let found = false;
297
- fragment.descendants((node) => {
298
- if (found) return false;
299
- if (isTableNode(node)) found = true;
300
- return !found;
301
- });
302
- return found;
303
- }
304
- function insertSliceAfterTable(tr, from, to, slice) {
305
- const $from = tr.doc.resolve(from);
306
- const depth = outermostTableDepth($from);
307
- if (depth < 0) return null;
308
- const tableStart = $from.before(depth);
309
- const tableEnd = $from.after(depth);
310
- if (to > from && to < tableEnd) {
311
- if (tr.selection instanceof CellSelection && tr.selection.from === from && tr.selection.to === to) {
312
- tr.deleteSelection();
313
- } else {
314
- tr.delete(from, to);
315
- }
316
- }
317
- const table = tr.doc.nodeAt(tableStart);
318
- if (!table) return null;
319
- const after = tableStart + table.nodeSize;
320
- const before = tr.doc.content.size;
321
- tr.replace(after, after, new Slice(slice.content, 0, 0));
322
- return after + (tr.doc.content.size - before);
323
- }
324
- function handleTablePasteWithoutNesting(view, event, slice) {
325
- const { state } = view;
326
- const { selection } = state;
327
- if (outermostTableDepth(selection.$from) < 0) return false;
328
- if (selection instanceof CellSelection || __pastedCells(slice)) {
329
- if (handleTablePaste(view, event, slice)) return true;
330
- }
331
- if (!sliceContainsTable(slice)) return false;
332
- const tr = state.tr;
333
- const end = insertSliceAfterTable(tr, selection.from, selection.to, slice);
334
- if (end === null) return false;
335
- tr.setSelection(Selection.near(tr.doc.resolve(end), -1));
336
- view.dispatch(tr.scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste"));
337
- return true;
338
- }
339
- function changedRanges(transactions, skip2) {
340
- let ranges = [];
341
- for (const tr of transactions) {
342
- const skipped = skip2(tr);
343
- for (const step of tr.steps) {
344
- const map = step.getMap();
345
- ranges = ranges.map(([from, to]) => [map.map(from, 1), map.map(to, -1)]).filter(([from, to]) => to > from);
346
- if (skipped) continue;
347
- map.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
348
- if (newEnd > newStart) ranges.push([newStart, newEnd]);
349
- });
350
- }
351
- }
352
- return ranges;
353
- }
354
- function findNestedTables(doc, ranges) {
355
- const found = /* @__PURE__ */ new Set();
356
- for (const [from, to] of ranges) {
357
- doc.nodesBetween(from, to, (node, pos) => {
358
- if (!isTableNode(node) || pos < from) return true;
359
- if (isInTableCell(doc.resolve(pos))) {
360
- found.add(pos);
361
- return false;
362
- }
363
- return true;
364
- });
365
- }
366
- const sorted = [...found].sort((a, b) => a - b);
367
- const outer = [];
368
- for (const pos of sorted) {
369
- const last = outer[outer.length - 1];
370
- if (last === void 0 || pos >= last + doc.nodeAt(last).nodeSize) outer.push(pos);
371
- }
372
- return outer;
373
- }
374
- function unnestTables(tr, ranges) {
375
- let changed = false;
376
- for (let round = 0; round < 32 && ranges.length; round++) {
377
- const nested = findNestedTables(tr.doc, ranges);
378
- if (!nested.length) break;
379
- const groups = /* @__PURE__ */ new Map();
380
- for (const pos of nested) {
381
- const $pos = tr.doc.resolve(pos);
382
- const outer = $pos.before(outermostTableDepth($pos));
383
- groups.set(outer, [...groups.get(outer) ?? [], pos]);
384
- }
385
- const next = [];
386
- for (const outer of [...groups.keys()].sort((a, b) => b - a)) {
387
- const positions = groups.get(outer);
388
- const nodes = positions.map((pos) => tr.doc.nodeAt(pos));
389
- for (let i = positions.length - 1; i >= 0; i--) {
390
- const pos = positions[i];
391
- const node = nodes[i];
392
- const $pos = tr.doc.resolve(pos);
393
- const parent = $pos.parent;
394
- const filler = parent.childCount === 1 ? parent.type.contentMatch.defaultType?.createAndFill() : null;
395
- if (filler) tr.replaceWith(pos, pos + node.nodeSize, filler);
396
- else tr.delete(pos, pos + node.nodeSize);
397
- }
398
- const table = tr.doc.nodeAt(outer);
399
- const after = outer + table.nodeSize;
400
- const fragment = Fragment.fromArray(nodes);
401
- tr.insert(after, fragment);
402
- next.push([after, after + fragment.size]);
403
- changed = true;
404
- }
405
- ranges = next;
406
- }
407
- return changed;
408
- }
409
- function replacesDocument(tr) {
410
- return tr.steps.some((step, i) => {
411
- const { from, to } = step;
412
- return from === 0 && to !== void 0 && to >= tr.docs[i].content.size;
413
- });
414
- }
415
- var skip = (tr) => !tr.docChanged || tr.getMeta(ALLOW_NESTED_TABLES_META) === true || // Undo/redo and remote collaborative changes restore what was there.
416
- !!tr.getMeta("history$") || !!tr.getMeta("y-sync$") || // Other plugins' housekeeping, e.g. Track Changes putting a deleted
417
- // (nested) table back so the deletion can be reviewed.
418
- !!tr.getMeta("appendedTransaction") || replacesDocument(tr);
419
- function createTableNestingPlugin() {
420
- return new Plugin2({
421
- key: tableNestingPluginKey,
422
- props: {
423
- handlePaste: (view, event, slice) => handleTablePasteWithoutNesting(view, event, slice)
424
- },
425
- appendTransaction(transactions, _oldState, newState) {
426
- if (transactions.every(skip)) return null;
427
- const ranges = changedRanges(transactions, skip);
428
- if (!ranges.length) return null;
429
- const tr = newState.tr;
430
- if (!unnestTables(tr, ranges)) return null;
431
- return tr;
432
- }
433
- });
434
- }
435
-
436
436
  // src/extensions/find-replace/pattern.ts
437
437
  var FIND_PARAGRAPH_MARK = "\r";
438
438
  var MAX_FIND_PATTERN_LENGTH = 1024;
@@ -2463,14 +2463,6 @@ async function typeAgentText(editor, options) {
2463
2463
  }
2464
2464
 
2465
2465
  export {
2466
- commentsPluginKey,
2467
- COMMENT_MARK_NAME,
2468
- findCommentRanges,
2469
- getCommentAnchors,
2470
- getCommentIdsAt,
2471
- getCommentStore,
2472
- Comments,
2473
- getCommentAuthor,
2474
2466
  ALLOW_NESTED_TABLES_META,
2475
2467
  tableNestingPluginKey,
2476
2468
  outermostTableDepth,
@@ -2480,6 +2472,14 @@ export {
2480
2472
  handleTablePasteWithoutNesting,
2481
2473
  unnestTables,
2482
2474
  createTableNestingPlugin,
2475
+ commentsPluginKey,
2476
+ COMMENT_MARK_NAME,
2477
+ findCommentRanges,
2478
+ getCommentAnchors,
2479
+ getCommentIdsAt,
2480
+ getCommentStore,
2481
+ Comments,
2482
+ getCommentAuthor,
2483
2483
  generateStructureId,
2484
2484
  presenceStateSpec,
2485
2485
  arraysEqual,
@@ -230,6 +230,162 @@ function matchConditionalTags(tags) {
230
230
  return result;
231
231
  }
232
232
 
233
+ // src/grammar/tokenizer.ts
234
+ function tokenizePrompt(text) {
235
+ return tokenizePromptWithDiagnostics(text).tokens;
236
+ }
237
+ function getPromptDiagnostics(text) {
238
+ return tokenizePromptWithDiagnostics(text).diagnostics;
239
+ }
240
+ function tokenizePromptWithDiagnostics(text) {
241
+ if (!text) {
242
+ return { tokens: [], diagnostics: [] };
243
+ }
244
+ const rawMatches = [];
245
+ const tmplRegex = new RegExp(TEMPLATE_REGEX.source, TEMPLATE_REGEX.flags);
246
+ let match;
247
+ while ((match = tmplRegex.exec(text)) !== null) {
248
+ rawMatches.push({
249
+ type: "template",
250
+ raw: match[0],
251
+ value: match[1].trim(),
252
+ start: match.index,
253
+ end: match.index + match[0].length
254
+ });
255
+ }
256
+ const varRegex = new RegExp(VARIABLE_REGEX.source, VARIABLE_REGEX.flags);
257
+ while ((match = varRegex.exec(text)) !== null) {
258
+ const start = match.index;
259
+ const end = start + match[0].length;
260
+ const overlaps = rawMatches.some(
261
+ (m) => !(end <= m.start || start >= m.end)
262
+ );
263
+ if (!overlaps) {
264
+ const parsed = parseVariableBody(match[1]);
265
+ if (parsed.kind === "conditional") {
266
+ rawMatches.push({
267
+ type: "conditional",
268
+ raw: match[0],
269
+ value: parsed.name,
270
+ start,
271
+ end,
272
+ conditional: parsed.conditional
273
+ });
274
+ } else {
275
+ const token = {
276
+ type: "variable",
277
+ raw: match[0],
278
+ value: parsed.name,
279
+ start,
280
+ end
281
+ };
282
+ if (parsed.defaultValue !== void 0) {
283
+ token.defaultValue = parsed.defaultValue;
284
+ }
285
+ if (parsed.description !== void 0) {
286
+ token.description = parsed.description;
287
+ }
288
+ rawMatches.push(token);
289
+ }
290
+ }
291
+ }
292
+ const instRegex = new RegExp(
293
+ INSTRUCTION_REGEX.source,
294
+ INSTRUCTION_REGEX.flags
295
+ );
296
+ while ((match = instRegex.exec(text)) !== null) {
297
+ const start = match.index;
298
+ const end = start + match[0].length;
299
+ const overlaps = rawMatches.some(
300
+ (m) => !(end <= m.start || start >= m.end)
301
+ );
302
+ if (!overlaps) {
303
+ rawMatches.push({
304
+ type: "instruction",
305
+ raw: match[0],
306
+ value: match[1].trim(),
307
+ start,
308
+ end
309
+ });
310
+ }
311
+ }
312
+ rawMatches.sort((a, b) => a.start - b.start);
313
+ const diagnostics = [];
314
+ const literal = /* @__PURE__ */ new Set();
315
+ const conditionals = rawMatches.filter(
316
+ (m) => m.type === "conditional"
317
+ );
318
+ matchConditionalTags(
319
+ conditionals.map((m) => ({ conditional: m.conditional, name: m.value }))
320
+ ).forEach((result, i) => {
321
+ const tag = conditionals[i];
322
+ const parsed = result.comparison;
323
+ if (!result.error) {
324
+ if (_optionalChain([parsed, 'optionalAccess', _2 => _2.comparison]) && tag.conditional !== "end") {
325
+ tag.value = parsed.subject;
326
+ tag.comparison = parsed.comparison;
327
+ }
328
+ return;
329
+ }
330
+ literal.add(tag);
331
+ if (result.error === "invalid-condition") {
332
+ if (tag.conditional === "end") return;
333
+ diagnostics.push({
334
+ code: result.error,
335
+ message: `Invalid condition "${tag.raw}": ${_nullishCoalesce(_optionalChain([parsed, 'optionalAccess', _3 => _3.error]), () => ( "malformed comparison"))}`,
336
+ name: _nullishCoalesce(_optionalChain([parsed, 'optionalAccess', _4 => _4.subject]), () => ( tag.value)),
337
+ start: tag.start,
338
+ end: tag.end
339
+ });
340
+ return;
341
+ }
342
+ diagnostics.push({
343
+ code: result.error,
344
+ message: result.error === "unclosed-section" ? `Section "${tag.raw}" is never closed with "{/${tag.value}}"` : `"${tag.raw}" does not close any open section`,
345
+ name: tag.value,
346
+ start: tag.start,
347
+ end: tag.end
348
+ });
349
+ });
350
+ diagnostics.sort((a, b) => a.start - b.start);
351
+ const tokens = [];
352
+ let currentIdx = 0;
353
+ const pushText = (start, end) => {
354
+ const previous = tokens[tokens.length - 1];
355
+ if (_optionalChain([previous, 'optionalAccess', _5 => _5.type]) === "text" && previous.end === start) {
356
+ previous.raw = previous.value = text.slice(previous.start, end);
357
+ previous.end = end;
358
+ return;
359
+ }
360
+ const textChunk = text.slice(start, end);
361
+ tokens.push({
362
+ type: "text",
363
+ raw: textChunk,
364
+ value: textChunk,
365
+ start,
366
+ end
367
+ });
368
+ };
369
+ for (const m of rawMatches) {
370
+ if (m.start > currentIdx) {
371
+ pushText(currentIdx, m.start);
372
+ }
373
+ if (literal.has(m)) {
374
+ pushText(m.start, m.end);
375
+ } else {
376
+ tokens.push({ ...m });
377
+ }
378
+ currentIdx = m.end;
379
+ }
380
+ if (currentIdx < text.length) {
381
+ pushText(currentIdx, text.length);
382
+ }
383
+ return { tokens, diagnostics };
384
+ }
385
+
386
+
387
+
388
+
233
389
 
234
390
 
235
391
 
@@ -252,4 +408,4 @@ function matchConditionalTags(tags) {
252
408
 
253
409
 
254
410
 
255
- exports.TEMPLATE_REGEX = TEMPLATE_REGEX; exports.VARIABLE_REGEX = VARIABLE_REGEX; exports.INSTRUCTION_REGEX = INSTRUCTION_REGEX; exports.templateRegex = templateRegex; exports.variableRegex = variableRegex; exports.instructionRegex = instructionRegex; exports.unescapeVariableText = unescapeVariableText; exports.escapeVariableText = escapeVariableText; exports.parseVariableBody = parseVariableBody; exports.isPromptValueSet = isPromptValueSet; exports.getSuppliedValue = getSuppliedValue; exports.evaluateCondition = evaluateCondition; exports.compareConditionValues = compareConditionValues; exports.conditionSubject = conditionSubject; exports.parseComparison = parseComparison; exports.formatComparisonOperand = formatComparisonOperand; exports.formatConditionalTag = formatConditionalTag; exports.describeConditionalTag = describeConditionalTag; exports.parseConditionExpression = parseConditionExpression; exports.evaluateConditionExpression = evaluateConditionExpression; exports.matchConditionalTags = matchConditionalTags;
411
+ exports.TEMPLATE_REGEX = TEMPLATE_REGEX; exports.VARIABLE_REGEX = VARIABLE_REGEX; exports.INSTRUCTION_REGEX = INSTRUCTION_REGEX; exports.templateRegex = templateRegex; exports.variableRegex = variableRegex; exports.instructionRegex = instructionRegex; exports.unescapeVariableText = unescapeVariableText; exports.escapeVariableText = escapeVariableText; exports.parseVariableBody = parseVariableBody; exports.isPromptValueSet = isPromptValueSet; exports.getSuppliedValue = getSuppliedValue; exports.evaluateCondition = evaluateCondition; exports.compareConditionValues = compareConditionValues; exports.conditionSubject = conditionSubject; exports.parseComparison = parseComparison; exports.formatComparisonOperand = formatComparisonOperand; exports.formatConditionalTag = formatConditionalTag; exports.describeConditionalTag = describeConditionalTag; exports.parseConditionExpression = parseConditionExpression; exports.evaluateConditionExpression = evaluateConditionExpression; exports.matchConditionalTags = matchConditionalTags; exports.tokenizePrompt = tokenizePrompt; exports.getPromptDiagnostics = getPromptDiagnostics; exports.tokenizePromptWithDiagnostics = tokenizePromptWithDiagnostics;