@pixerate/editor 0.47.0 → 0.48.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 (76) hide show
  1. package/dist/agent/index.cjs +246 -29
  2. package/dist/agent/index.cjs.map +1 -1
  3. package/dist/agent/index.d.cts +18 -6
  4. package/dist/agent/index.d.ts +18 -6
  5. package/dist/agent/index.js +226 -9
  6. package/dist/agent/index.js.map +1 -1
  7. package/dist/{builtins-xs7rK6ys.d.cts → builtins-1kqwLUnb.d.cts} +1 -1
  8. package/dist/{builtins-D2nMtw2W.d.ts → builtins-BKYlHH1s.d.ts} +1 -1
  9. package/dist/chart/index.cjs +214 -3541
  10. package/dist/chart/index.cjs.map +1 -1
  11. package/dist/chart/index.d.cts +4 -494
  12. package/dist/chart/index.d.ts +4 -494
  13. package/dist/chart/index.js +135 -3462
  14. package/dist/chart/index.js.map +1 -1
  15. package/dist/{chunk-5VXI5GED.js → chunk-2CJ3LPYQ.js} +3 -3
  16. package/dist/{chunk-ZFBBVGCI.js → chunk-EKYHKQPG.js} +243 -243
  17. package/dist/{chunk-ZFBBVGCI.js.map → chunk-EKYHKQPG.js.map} +1 -1
  18. package/dist/chunk-HXUL3LS7.js +113 -0
  19. package/dist/chunk-HXUL3LS7.js.map +1 -0
  20. package/dist/{chunk-REAGGLXS.js → chunk-JQ3BB3E6.js} +2 -2
  21. package/dist/chunk-LTUM52X6.js +4074 -0
  22. package/dist/chunk-LTUM52X6.js.map +1 -0
  23. package/dist/{chunk-J3R2OWOE.cjs → chunk-MUCYWI6W.cjs} +608 -15
  24. package/dist/chunk-MUCYWI6W.cjs.map +1 -0
  25. package/dist/chunk-PIMCHMZE.cjs +521 -0
  26. package/dist/chunk-PIMCHMZE.cjs.map +1 -0
  27. package/dist/{chunk-TK2XZK6Z.js → chunk-PKBWLEL7.js} +594 -1
  28. package/dist/chunk-PKBWLEL7.js.map +1 -0
  29. package/dist/chunk-PRSJJZBS.cjs +4074 -0
  30. package/dist/chunk-PRSJJZBS.cjs.map +1 -0
  31. package/dist/chunk-U6IZKC7B.cjs +113 -0
  32. package/dist/chunk-U6IZKC7B.cjs.map +1 -0
  33. package/dist/{chunk-SQC26VQV.cjs → chunk-UN33YOXW.cjs} +191 -191
  34. package/dist/{chunk-SQC26VQV.cjs.map → chunk-UN33YOXW.cjs.map} +1 -1
  35. package/dist/{chunk-PQFAHT5O.js → chunk-VKPEPWKZ.js} +27 -94
  36. package/dist/chunk-VKPEPWKZ.js.map +1 -0
  37. package/dist/{chunk-H4PICYNL.cjs → chunk-WXEHCVJQ.cjs} +113 -180
  38. package/dist/chunk-WXEHCVJQ.cjs.map +1 -0
  39. package/dist/{chunk-LYGEEDNR.cjs → chunk-XP5IUZUO.cjs} +242 -242
  40. package/dist/chunk-XP5IUZUO.cjs.map +1 -0
  41. package/dist/{chunk-C3NWJE3K.js → chunk-XUUD43OV.js} +11 -672
  42. package/dist/chunk-XUUD43OV.js.map +1 -0
  43. package/dist/{chunk-BBRK6MOI.cjs → chunk-YU4WQE5M.cjs} +100 -100
  44. package/dist/{chunk-BBRK6MOI.cjs.map → chunk-YU4WQE5M.cjs.map} +1 -1
  45. package/dist/commands/index.d.cts +1 -1
  46. package/dist/commands/index.d.ts +1 -1
  47. package/dist/controller-ChjCCMLl.d.cts +822 -0
  48. package/dist/controller-DtbEo3om.d.ts +822 -0
  49. package/dist/extensions/index.cjs +32 -4
  50. package/dist/extensions/index.cjs.map +1 -1
  51. package/dist/extensions/index.d.cts +4 -2
  52. package/dist/extensions/index.d.ts +4 -2
  53. package/dist/extensions/index.js +31 -3
  54. package/dist/{index-QrqMmZ75.d.cts → index-DoHqT1mq.d.cts} +203 -7
  55. package/dist/{index-CSUCQYAH.d.ts → index-YLZ0fKqE.d.ts} +203 -7
  56. package/dist/index.cjs +37 -12
  57. package/dist/index.cjs.map +1 -1
  58. package/dist/index.d.cts +9 -7
  59. package/dist/index.d.ts +9 -7
  60. package/dist/index.js +31 -6
  61. package/dist/index.js.map +1 -1
  62. package/dist/spreadsheet/index.cjs +4 -4
  63. package/dist/spreadsheet/index.js +3 -3
  64. package/package.json +1 -1
  65. package/dist/chunk-C3NWJE3K.js.map +0 -1
  66. package/dist/chunk-H4PICYNL.cjs.map +0 -1
  67. package/dist/chunk-J3R2OWOE.cjs.map +0 -1
  68. package/dist/chunk-LYGEEDNR.cjs.map +0 -1
  69. package/dist/chunk-NEOO6QJD.cjs +0 -1182
  70. package/dist/chunk-NEOO6QJD.cjs.map +0 -1
  71. package/dist/chunk-PQFAHT5O.js.map +0 -1
  72. package/dist/chunk-TK2XZK6Z.js.map +0 -1
  73. package/dist/types-BVqWm3d1.d.cts +0 -320
  74. package/dist/types-BVqWm3d1.d.ts +0 -320
  75. /package/dist/{chunk-5VXI5GED.js.map → chunk-2CJ3LPYQ.js.map} +0 -0
  76. /package/dist/{chunk-REAGGLXS.js.map → chunk-JQ3BB3E6.js.map} +0 -0
@@ -1,4 +1,15 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ var _chunkPRSJJZBScjs = require('./chunk-PRSJJZBS.cjs');
12
+
2
13
 
3
14
  var _chunkIFHKKVXHcjs = require('./chunk-IFHKKVXH.cjs');
4
15
 
@@ -1174,6 +1185,570 @@ function createTableExtensions(options = {}) {
1174
1185
  ];
1175
1186
  }
1176
1187
 
1188
+ // src/extensions/chart/node-view.ts
1189
+
1190
+
1191
+ var specKey = (spec) => JSON.stringify(spec);
1192
+ var ChartNodeView = (_class = class {
1193
+ constructor(props, mount, renderStatic) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);
1194
+ this.renderStatic = renderStatic;
1195
+ this.editor = props.editor;
1196
+ this.node = props.node;
1197
+ this.getPos = typeof props.getPos === "function" ? props.getPos : () => void 0;
1198
+ this.editable = this.editor.isEditable;
1199
+ this.dom = document.createElement("div");
1200
+ this.dom.className = "pixerate-chart-node";
1201
+ this.dom.setAttribute("data-type", "chart");
1202
+ this.dom.contentEditable = "false";
1203
+ this.syncAttributes();
1204
+ this.key = specKey(this.node.attrs.spec);
1205
+ this.controller = new (0, _chunkPRSJJZBScjs.ChartController)({ spec: this.node.attrs.spec });
1206
+ this.unsubscribe = this.controller.subscribe((state) => {
1207
+ if (!state.gesture) this.writeBack();
1208
+ });
1209
+ this.editor.on("update", this.onEditorUpdate);
1210
+ this.renderer = mount ? mount(this.dom, this.viewState()) : null;
1211
+ if (!mount) this.drawStatic();
1212
+ }
1213
+
1214
+
1215
+
1216
+
1217
+
1218
+
1219
+
1220
+
1221
+ __init() {this.editing = false}
1222
+ __init2() {this.selected = false}
1223
+
1224
+
1225
+ viewState() {
1226
+ return {
1227
+ id: _nullishCoalesce(this.node.attrs.id, () => ( null)),
1228
+ controller: this.controller,
1229
+ width: _nullishCoalesce(this.node.attrs.width, () => ( null)),
1230
+ height: this.node.attrs.height,
1231
+ editable: this.editable,
1232
+ selected: this.selected,
1233
+ editing: this.editing,
1234
+ setEditing: this.setEditing,
1235
+ setSize: this.setSize
1236
+ };
1237
+ }
1238
+ render() {
1239
+ if (this.renderer) this.renderer.update(this.viewState());
1240
+ else this.drawStatic();
1241
+ this.dom.toggleAttribute("data-editing", this.editing);
1242
+ }
1243
+ drawStatic() {
1244
+ const { dom } = _model.DOMSerializer.renderSpec(document, this.renderStatic(this.node));
1245
+ this.dom.replaceChildren(dom);
1246
+ }
1247
+ syncAttributes() {
1248
+ if (this.node.attrs.id) this.dom.setAttribute("data-chart-id", this.node.attrs.id);
1249
+ else this.dom.removeAttribute("data-chart-id");
1250
+ }
1251
+ __init3() {this.onEditorUpdate = () => {
1252
+ if (this.editor.isEditable === this.editable) return;
1253
+ this.editable = this.editor.isEditable;
1254
+ if (!this.editable) this.editing = false;
1255
+ this.render();
1256
+ }}
1257
+ /** Writes the controller's spec into the node, if it changed. */
1258
+ writeBack() {
1259
+ const spec = this.controller.toJSON();
1260
+ const key = specKey(spec);
1261
+ if (key === this.key) return;
1262
+ const pos = this.getPos();
1263
+ if (typeof pos !== "number" || this.editor.isDestroyed) return;
1264
+ this.key = key;
1265
+ this.editor.view.dispatch(this.editor.state.tr.setNodeMarkup(pos, void 0, { ...this.node.attrs, spec }));
1266
+ }
1267
+ __init4() {this.setEditing = (editing) => {
1268
+ if (editing && !this.editor.isEditable) return;
1269
+ if (editing && !this.selected) {
1270
+ const pos = this.getPos();
1271
+ if (typeof pos === "number") {
1272
+ this.editor.view.dispatch(this.editor.state.tr.setSelection(_state.NodeSelection.create(this.editor.state.doc, pos)));
1273
+ }
1274
+ }
1275
+ if (this.editing === editing) return;
1276
+ this.editing = editing;
1277
+ this.render();
1278
+ }}
1279
+ __init5() {this.setSize = (size) => {
1280
+ const pos = this.getPos();
1281
+ if (typeof pos !== "number" || !this.editor.isEditable) return;
1282
+ this.editor.view.dispatch(this.editor.state.tr.setNodeMarkup(pos, void 0, { ...this.node.attrs, ...size }));
1283
+ }}
1284
+ update(node) {
1285
+ if (node.type !== this.node.type) return false;
1286
+ this.node = node;
1287
+ this.syncAttributes();
1288
+ const key = specKey(node.attrs.spec);
1289
+ if (key !== this.key) {
1290
+ this.key = key;
1291
+ if (specKey(this.controller.toJSON()) !== key) this.controller.load(node.attrs.spec, { clearHistory: true });
1292
+ }
1293
+ this.render();
1294
+ return true;
1295
+ }
1296
+ selectNode() {
1297
+ this.selected = true;
1298
+ this.dom.classList.add("ProseMirror-selectednode");
1299
+ this.render();
1300
+ }
1301
+ deselectNode() {
1302
+ this.selected = false;
1303
+ this.editing = false;
1304
+ this.dom.classList.remove("ProseMirror-selectednode");
1305
+ this.render();
1306
+ }
1307
+ /** The inspector's inputs, buttons and chart gestures keep their events while it is open. */
1308
+ stopEvent(event) {
1309
+ if (!this.editing) return false;
1310
+ return !(event.type === "dragstart" && event.target === this.dom);
1311
+ }
1312
+ ignoreMutation() {
1313
+ return true;
1314
+ }
1315
+ destroy() {
1316
+ this.editor.off("update", this.onEditorUpdate);
1317
+ this.unsubscribe();
1318
+ _optionalChain([this, 'access', _22 => _22.renderer, 'optionalAccess', _23 => _23.destroy, 'call', _24 => _24()]);
1319
+ this.controller.destroy();
1320
+ }
1321
+ }, _class);
1322
+ function createChartNodeView(mount, renderStatic) {
1323
+ return (props) => new ChartNodeView(props, mount, renderStatic);
1324
+ }
1325
+
1326
+ // src/extensions/chart/chart-node.ts
1327
+
1328
+
1329
+
1330
+ // src/extensions/document-structure/utils.ts
1331
+
1332
+
1333
+ var _transform = require('@tiptap/pm/transform');
1334
+ var idCounter = 0;
1335
+ function generateStructureId(prefix) {
1336
+ idCounter = (idCounter + 1) % 1296;
1337
+ const random = Math.random().toString(36).slice(2, 8).padEnd(6, "0");
1338
+ return `${prefix}-${random}${idCounter.toString(36).padStart(2, "0")}`;
1339
+ }
1340
+ function transactionsInsert(transactions, typeNames) {
1341
+ for (const tr of transactions) {
1342
+ for (const step of tr.steps) {
1343
+ if (!(step instanceof _transform.ReplaceStep || step instanceof _transform.ReplaceAroundStep)) {
1344
+ const mark = step.mark;
1345
+ if (mark && typeNames.includes(mark.type.name)) return true;
1346
+ continue;
1347
+ }
1348
+ let found = false;
1349
+ step.slice.content.descendants((node) => {
1350
+ if (found) return false;
1351
+ if (typeNames.includes(node.type.name) || node.marks.some((m) => typeNames.includes(m.type.name))) {
1352
+ found = true;
1353
+ }
1354
+ return !found;
1355
+ });
1356
+ if (found) return true;
1357
+ }
1358
+ }
1359
+ return false;
1360
+ }
1361
+ function docContains(doc, typeNames) {
1362
+ let found = false;
1363
+ doc.descendants((node) => {
1364
+ if (found) return false;
1365
+ if (typeNames.includes(node.type.name) || node.marks.some((m) => typeNames.includes(m.type.name))) {
1366
+ found = true;
1367
+ }
1368
+ return !found;
1369
+ });
1370
+ return found;
1371
+ }
1372
+ function presenceStateSpec(typeNames) {
1373
+ return {
1374
+ init: (_config, state) => docContains(state.doc, typeNames),
1375
+ apply: (tr, present, _oldState, newState) => {
1376
+ if (!tr.docChanged) return present;
1377
+ if (!present && !transactionsInsert([tr], typeNames)) return false;
1378
+ return docContains(newState.doc, typeNames);
1379
+ }
1380
+ };
1381
+ }
1382
+ function arraysEqual(a, b, eq) {
1383
+ if (a.length !== b.length) return false;
1384
+ for (let i = 0; i < a.length; i++) {
1385
+ if (!eq(a[i], b[i])) return false;
1386
+ }
1387
+ return true;
1388
+ }
1389
+ function scrollDomAtPos(view, pos, behavior = "smooth") {
1390
+ try {
1391
+ const dom = _optionalChain([view, 'optionalAccess', _25 => _25.nodeDOM, 'optionalCall', _26 => _26(pos)]);
1392
+ if (dom && typeof dom.scrollIntoView === "function") {
1393
+ dom.scrollIntoView({ block: "start", behavior });
1394
+ }
1395
+ } catch (e) {
1396
+ }
1397
+ }
1398
+ function syncInitialContent(editor, sync) {
1399
+ const { content } = editor.options;
1400
+ if (content == null || content === "") return;
1401
+ try {
1402
+ const doc = _core.createDocument.call(void 0, content, editor.schema, editor.options.parseOptions, {
1403
+ errorOnInvalidContent: false
1404
+ });
1405
+ const tr = sync(_state.EditorState.create({ doc }));
1406
+ if (_optionalChain([tr, 'optionalAccess', _27 => _27.docChanged])) editor.options.content = tr.doc;
1407
+ } catch (e2) {
1408
+ }
1409
+ }
1410
+ var STRUCTURE_PRIORITY = 45;
1411
+
1412
+ // src/extensions/chart/chart-node.ts
1413
+ var chartPluginKey = new (0, _state.PluginKey)("chartNode");
1414
+ function getDocumentCharts(doc, typeName = "chart") {
1415
+ const charts = [];
1416
+ doc.descendants((node, pos) => {
1417
+ if (node.type.name === typeName) {
1418
+ charts.push({ id: _nullishCoalesce(node.attrs.id, () => ( null)), pos, node, spec: node.attrs.spec });
1419
+ return false;
1420
+ }
1421
+ return !node.isTextblock;
1422
+ });
1423
+ return charts;
1424
+ }
1425
+ function isChartEnabled(editor) {
1426
+ return !!_optionalChain([editor, 'optionalAccess', _28 => _28.schema, 'optionalAccess', _29 => _29.nodes, 'optionalAccess', _30 => _30.chart]);
1427
+ }
1428
+ function readSpec(value) {
1429
+ let input = value;
1430
+ if (typeof value === "string") {
1431
+ try {
1432
+ input = JSON.parse(value);
1433
+ } catch (e3) {
1434
+ return null;
1435
+ }
1436
+ }
1437
+ if (!input || typeof input !== "object" || Array.isArray(input)) return null;
1438
+ return _chunkPRSJJZBScjs.normalizeChartSpec.call(void 0, input).spec;
1439
+ }
1440
+ var readSize = (value) => {
1441
+ const n = value === null ? NaN : Number(value);
1442
+ return Number.isFinite(n) && n >= 50 && n <= 4096 ? n : null;
1443
+ };
1444
+ function syncChartIds(state, typeName, generateId) {
1445
+ const seen = /* @__PURE__ */ new Set();
1446
+ let tr = null;
1447
+ for (const chart of getDocumentCharts(state.doc, typeName)) {
1448
+ if (chart.id && !seen.has(chart.id)) {
1449
+ seen.add(chart.id);
1450
+ continue;
1451
+ }
1452
+ let id = generateId();
1453
+ while (seen.has(id)) id = generateId();
1454
+ seen.add(id);
1455
+ tr = _nullishCoalesce(tr, () => ( state.tr));
1456
+ tr.setNodeMarkup(chart.pos, void 0, { ...chart.node.attrs, id });
1457
+ }
1458
+ return _nullishCoalesce(_optionalChain([tr, 'optionalAccess', _31 => _31.setMeta, 'call', _32 => _32("addToHistory", false)]), () => ( null));
1459
+ }
1460
+ function staticChartSvg(node, options) {
1461
+ const spec = node.attrs.spec;
1462
+ const width = _nullishCoalesce(node.attrs.width, () => ( options.defaultWidth));
1463
+ const height = _nullishCoalesce(node.attrs.height, () => ( options.defaultHeight));
1464
+ const scene = _chunkPRSJJZBScjs.layoutChart.call(void 0, spec, { width, height, theme: options.theme, selection: null });
1465
+ return _chunkPRSJJZBScjs.chartSceneToDomSpec.call(void 0, scene, {
1466
+ ariaLabel: spec.title || "Chart",
1467
+ description: _chunkPRSJJZBScjs.describeChart.call(void 0, spec),
1468
+ attrs: { style: "max-width: 100%; height: auto; display: block" }
1469
+ });
1470
+ }
1471
+ var longestBacktickRun = (text) => Math.max(0, ...Array.from(text.matchAll(/`+/g), (m) => m[0].length));
1472
+ var Chart = _core.Node.create({
1473
+ name: "chart",
1474
+ priority: STRUCTURE_PRIORITY,
1475
+ group: "block",
1476
+ atom: true,
1477
+ selectable: true,
1478
+ draggable: true,
1479
+ addOptions() {
1480
+ return {
1481
+ HTMLAttributes: {},
1482
+ nodeView: null,
1483
+ theme: _chunkPRSJJZBScjs.DEFAULT_CHART_THEME,
1484
+ defaultWidth: 640,
1485
+ defaultHeight: 320,
1486
+ generateId: () => generateStructureId("chart")
1487
+ };
1488
+ },
1489
+ addAttributes() {
1490
+ return {
1491
+ id: {
1492
+ default: null,
1493
+ parseHTML: (element) => element.getAttribute("data-chart-id") || null,
1494
+ renderHTML: (attributes) => attributes.id ? { "data-chart-id": attributes.id } : {}
1495
+ },
1496
+ spec: {
1497
+ default: _chunkPRSJJZBScjs.normalizeChartSpec.call(void 0, {}).spec,
1498
+ // null (no `data-chart`) keeps what the parse rule found, e.g. a mermaid block's spec.
1499
+ parseHTML: (element) => readSpec(element.getAttribute("data-chart")),
1500
+ renderHTML: (attributes) => ({
1501
+ "data-chart": JSON.stringify(attributes.spec)
1502
+ })
1503
+ },
1504
+ width: {
1505
+ default: null,
1506
+ parseHTML: (element) => readSize(element.getAttribute("data-width")),
1507
+ renderHTML: (attributes) => attributes.width ? { "data-width": String(attributes.width) } : {}
1508
+ },
1509
+ height: {
1510
+ default: this.options.defaultHeight,
1511
+ parseHTML: (element) => readSize(element.getAttribute("data-height")),
1512
+ renderHTML: (attributes) => ({
1513
+ "data-height": String(attributes.height)
1514
+ })
1515
+ }
1516
+ };
1517
+ },
1518
+ parseHTML() {
1519
+ return [
1520
+ {
1521
+ tag: 'div[data-type="chart"]',
1522
+ priority: 60,
1523
+ // A missing or broken spec falls through, so the fallback content inside (e.g. a
1524
+ // DOCX import's caption and data table) is kept instead.
1525
+ getAttrs: (element) => readSpec(element.getAttribute("data-chart")) ? null : false
1526
+ },
1527
+ {
1528
+ // ```mermaid blocks (from markdown) that hold a chart; other diagrams stay code.
1529
+ tag: "pre",
1530
+ priority: 60,
1531
+ getAttrs: (element) => {
1532
+ const code = element.querySelector("code");
1533
+ const language = _nullishCoalesce(_nullishCoalesce(_optionalChain([code, 'optionalAccess', _33 => _33.getAttribute, 'call', _34 => _34("class")]), () => ( element.getAttribute("data-language"))), () => ( ""));
1534
+ if (!/(?:^|\s)language-mermaid(?:\s|$)/.test(language) && language !== "mermaid") return false;
1535
+ const result = _chunkPRSJJZBScjs.chartFromMermaid.call(void 0, _nullishCoalesce((_nullishCoalesce(code, () => ( element))).textContent, () => ( "")));
1536
+ return result.family ? { spec: result.spec } : false;
1537
+ }
1538
+ }
1539
+ ];
1540
+ },
1541
+ renderHTML({ node, HTMLAttributes }) {
1542
+ const svg = staticChartSvg(node, this.options);
1543
+ return [
1544
+ "div",
1545
+ _core.mergeAttributes.call(void 0, this.options.HTMLAttributes, HTMLAttributes, {
1546
+ "data-type": "chart",
1547
+ class: "pixerate-chart"
1548
+ }),
1549
+ svg
1550
+ ];
1551
+ },
1552
+ renderText({ node }) {
1553
+ return `[Chart: ${_optionalChain([node, 'access', _35 => _35.attrs, 'access', _36 => _36.spec, 'optionalAccess', _37 => _37.title]) || "untitled"}]`;
1554
+ },
1555
+ addStorage() {
1556
+ return {
1557
+ markdown: {
1558
+ serialize(state, node) {
1559
+ const text = _chunkPRSJJZBScjs.chartToMermaid.call(void 0, node.attrs.spec);
1560
+ const fence = "`".repeat(Math.max(3, longestBacktickRun(text) + 1));
1561
+ state.write(`${fence}mermaid
1562
+ `);
1563
+ state.text(text, false);
1564
+ state.ensureNewLine();
1565
+ state.write(fence);
1566
+ state.closeBlock(node);
1567
+ },
1568
+ parse: {
1569
+ // markdown-it renders ```mermaid as <pre><code class="language-mermaid">, which
1570
+ // `parseHTML` reads.
1571
+ }
1572
+ }
1573
+ };
1574
+ },
1575
+ addCommands() {
1576
+ return {
1577
+ insertChart: (options) => ({ commands }) => commands.insertContent({
1578
+ type: this.name,
1579
+ attrs: {
1580
+ id: _nullishCoalesce(options.id, () => ( this.options.generateId())),
1581
+ spec: _chunkPRSJJZBScjs.normalizeChartSpec.call(void 0, _nullishCoalesce(options.spec, () => ( {}))).spec,
1582
+ width: _nullishCoalesce(options.width, () => ( null)),
1583
+ height: _nullishCoalesce(options.height, () => ( this.options.defaultHeight))
1584
+ }
1585
+ }),
1586
+ updateChart: (id, changes) => ({ state, tr, dispatch }) => {
1587
+ const chart = getDocumentCharts(state.doc, this.name).find((c) => c.id === id);
1588
+ if (!chart) return false;
1589
+ if (dispatch) {
1590
+ tr.setNodeMarkup(chart.pos, void 0, {
1591
+ ...chart.node.attrs,
1592
+ ...changes.spec !== void 0 ? { spec: _chunkPRSJJZBScjs.normalizeChartSpec.call(void 0, changes.spec).spec } : {},
1593
+ ...changes.width !== void 0 ? { width: changes.width } : {},
1594
+ ...changes.height !== void 0 ? { height: changes.height } : {}
1595
+ });
1596
+ }
1597
+ return true;
1598
+ }
1599
+ };
1600
+ },
1601
+ addNodeView() {
1602
+ return createChartNodeView(this.options.nodeView, (node) => staticChartSvg(node, this.options));
1603
+ },
1604
+ addProseMirrorPlugins() {
1605
+ const { name } = this;
1606
+ const { generateId } = this.options;
1607
+ return [
1608
+ new (0, _state.Plugin)({
1609
+ key: chartPluginKey,
1610
+ appendTransaction: (transactions, _oldState, newState) => {
1611
+ if (!transactions.some((tr) => tr.docChanged)) return null;
1612
+ if (!transactionsInsert(transactions, [name])) return null;
1613
+ return syncChartIds(newState, name, generateId);
1614
+ }
1615
+ })
1616
+ ];
1617
+ },
1618
+ onBeforeCreate() {
1619
+ const { generateId } = this.options;
1620
+ syncInitialContent(this.editor, (state) => syncChartIds(state, this.name, generateId));
1621
+ }
1622
+ });
1623
+
1624
+ // src/extensions/chart/sparkline-node.ts
1625
+
1626
+ var SPARKLINE_KINDS = ["line", "column", "win-loss"];
1627
+ var MAX_SPARKLINE_VALUES = 1e3;
1628
+ function normalizeSparklineValues(values) {
1629
+ if (!Array.isArray(values)) return [];
1630
+ return values.slice(0, MAX_SPARKLINE_VALUES).map((v) => typeof v === "number" && Number.isFinite(v) ? v : null);
1631
+ }
1632
+ function readValues(text) {
1633
+ if (!text) return [];
1634
+ try {
1635
+ return normalizeSparklineValues(JSON.parse(text));
1636
+ } catch (e4) {
1637
+ return normalizeSparklineValues(text.split(/[\s,]+/).filter(Boolean).map(Number));
1638
+ }
1639
+ }
1640
+ var readNumber = (text, fallback, max) => {
1641
+ const n = text === null ? NaN : Number(text);
1642
+ return Number.isFinite(n) && n >= 4 && n <= max ? n : fallback;
1643
+ };
1644
+ function sparklineLabel(node) {
1645
+ if (node.attrs.label) return node.attrs.label;
1646
+ const present = node.attrs.values.filter((v) => v !== null);
1647
+ return present.length ? `Trend from ${present[0]} to ${present[present.length - 1]}` : "No data";
1648
+ }
1649
+ var Sparkline = _core.Node.create({
1650
+ name: "sparkline",
1651
+ group: "inline",
1652
+ inline: true,
1653
+ atom: true,
1654
+ selectable: true,
1655
+ addOptions() {
1656
+ return { HTMLAttributes: {}, color: "#4269d0", negativeColor: "#e5484d" };
1657
+ },
1658
+ addAttributes() {
1659
+ return {
1660
+ values: {
1661
+ default: [],
1662
+ parseHTML: (element) => readValues(element.getAttribute("data-values")),
1663
+ renderHTML: (attributes) => ({ "data-values": JSON.stringify(_nullishCoalesce(attributes.values, () => ( []))) })
1664
+ },
1665
+ kind: {
1666
+ default: "line",
1667
+ parseHTML: (element) => {
1668
+ const kind = element.getAttribute("data-kind");
1669
+ return SPARKLINE_KINDS.includes(kind) ? kind : "line";
1670
+ },
1671
+ renderHTML: (attributes) => ({ "data-kind": attributes.kind })
1672
+ },
1673
+ width: {
1674
+ default: 80,
1675
+ parseHTML: (element) => readNumber(element.getAttribute("data-width"), 80, 1e3),
1676
+ renderHTML: (attributes) => ({ "data-width": String(attributes.width) })
1677
+ },
1678
+ height: {
1679
+ default: 18,
1680
+ parseHTML: (element) => readNumber(element.getAttribute("data-height"), 18, 200),
1681
+ renderHTML: (attributes) => ({ "data-height": String(attributes.height) })
1682
+ },
1683
+ color: {
1684
+ default: null,
1685
+ parseHTML: (element) => element.getAttribute("data-color") || null,
1686
+ renderHTML: (attributes) => attributes.color ? { "data-color": attributes.color } : {}
1687
+ },
1688
+ label: {
1689
+ default: null,
1690
+ parseHTML: (element) => element.getAttribute("data-label") || null,
1691
+ renderHTML: (attributes) => attributes.label ? { "data-label": attributes.label } : {}
1692
+ }
1693
+ };
1694
+ },
1695
+ parseHTML() {
1696
+ return [{ tag: 'span[data-type="sparkline"]', priority: 60 }];
1697
+ },
1698
+ renderHTML({ node, HTMLAttributes }) {
1699
+ const scene = _chunkPRSJJZBScjs.layoutSparkline.call(void 0, node.attrs.values, {
1700
+ kind: node.attrs.kind,
1701
+ width: node.attrs.width,
1702
+ height: node.attrs.height,
1703
+ color: _nullishCoalesce(node.attrs.color, () => ( this.options.color)),
1704
+ negativeColor: this.options.negativeColor
1705
+ });
1706
+ const svg = _chunkPRSJJZBScjs.chartSceneToDomSpec.call(void 0, scene, {
1707
+ ariaLabel: sparklineLabel(node),
1708
+ attrs: { style: "display: inline-block; vertical-align: middle" }
1709
+ });
1710
+ return [
1711
+ "span",
1712
+ _core.mergeAttributes.call(void 0, this.options.HTMLAttributes, HTMLAttributes, {
1713
+ "data-type": "sparkline",
1714
+ class: "pixerate-sparkline"
1715
+ }),
1716
+ svg
1717
+ ];
1718
+ },
1719
+ renderText({ node }) {
1720
+ return `[${sparklineLabel(node)}]`;
1721
+ },
1722
+ addStorage() {
1723
+ return {
1724
+ markdown: {
1725
+ serialize(state, node) {
1726
+ const attr = (name, value) => value === null || value === void 0 ? "" : ` ${name}="${String(value).replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;")}"`;
1727
+ state.write(
1728
+ `<span data-type="sparkline"${attr("data-values", JSON.stringify(node.attrs.values))}${attr("data-kind", node.attrs.kind)}${attr("data-width", node.attrs.width)}${attr("data-height", node.attrs.height)}${attr("data-color", node.attrs.color)}${attr("data-label", node.attrs.label)}></span>`
1729
+ );
1730
+ },
1731
+ parse: {}
1732
+ }
1733
+ };
1734
+ },
1735
+ addCommands() {
1736
+ return {
1737
+ insertSparkline: (options) => ({ commands }) => commands.insertContent({
1738
+ type: this.name,
1739
+ attrs: {
1740
+ values: normalizeSparklineValues(options.values),
1741
+ kind: options.kind && SPARKLINE_KINDS.includes(options.kind) ? options.kind : "line",
1742
+ width: _nullishCoalesce(options.width, () => ( 80)),
1743
+ height: _nullishCoalesce(options.height, () => ( 18)),
1744
+ color: _nullishCoalesce(options.color, () => ( null)),
1745
+ label: _nullishCoalesce(options.label, () => ( null))
1746
+ }
1747
+ })
1748
+ };
1749
+ }
1750
+ });
1751
+
1177
1752
  // src/extensions/table/actions.ts
1178
1753
 
1179
1754
  var TABLE_ACTIONS = [
@@ -1229,7 +1804,7 @@ var isInt = (value, min, max) => typeof value === "number" && Number.isInteger(v
1229
1804
  var can = (editor, run) => {
1230
1805
  try {
1231
1806
  return !!run(editor.can().chain()).run();
1232
- } catch (e) {
1807
+ } catch (e5) {
1233
1808
  return false;
1234
1809
  }
1235
1810
  };
@@ -1277,13 +1852,13 @@ function getTableActionState(editor, action, params = {}) {
1277
1852
  if (params.align !== void 0 && params.align !== null && !normalizeTableCellAlignment(params.align)) {
1278
1853
  return 'Alignment must be "left", "center", "right", "justify" or null.';
1279
1854
  }
1280
- if (!_optionalChain([editor, 'access', _22 => _22.schema, 'access', _23 => _23.nodes, 'access', _24 => _24.tableCell, 'optionalAccess', _25 => _25.spec, 'access', _26 => _26.attrs, 'optionalAccess', _27 => _27.align])) return "Cell alignment is not supported by this schema.";
1855
+ if (!_optionalChain([editor, 'access', _38 => _38.schema, 'access', _39 => _39.nodes, 'access', _40 => _40.tableCell, 'optionalAccess', _41 => _41.spec, 'access', _42 => _42.attrs, 'optionalAccess', _43 => _43.align])) return "Cell alignment is not supported by this schema.";
1281
1856
  return true;
1282
1857
  case "setCellBackground":
1283
1858
  if (params.color !== void 0 && params.color !== null && !normalizeTableCellColor(params.color)) {
1284
1859
  return "Color must be a CSS color such as #fde68a, rgb(\u2026) or a color name, or null.";
1285
1860
  }
1286
- if (!_optionalChain([editor, 'access', _28 => _28.schema, 'access', _29 => _29.nodes, 'access', _30 => _30.tableCell, 'optionalAccess', _31 => _31.spec, 'access', _32 => _32.attrs, 'optionalAccess', _33 => _33.backgroundColor])) return "Cell backgrounds are not supported by this schema.";
1861
+ if (!_optionalChain([editor, 'access', _44 => _44.schema, 'access', _45 => _45.nodes, 'access', _46 => _46.tableCell, 'optionalAccess', _47 => _47.spec, 'access', _48 => _48.attrs, 'optionalAccess', _49 => _49.backgroundColor])) return "Cell backgrounds are not supported by this schema.";
1287
1862
  return true;
1288
1863
  default:
1289
1864
  return can(editor, (c) => c[action]()) ? true : "This table action is not available here.";
@@ -1346,7 +1921,7 @@ function getTableState(editor) {
1346
1921
  const rect = _tables.selectedRect.call(void 0, state);
1347
1922
  const { map, table } = rect;
1348
1923
  const cellAt = (row, col) => table.nodeAt(map.map[row * map.width + col]);
1349
- const allHeaders = (positions) => positions.length > 0 && positions.every((pos) => _optionalChain([table, 'access', _34 => _34.nodeAt, 'call', _35 => _35(pos), 'optionalAccess', _36 => _36.type, 'access', _37 => _37.name]) === "tableHeader");
1924
+ const allHeaders = (positions) => positions.length > 0 && positions.every((pos) => _optionalChain([table, 'access', _50 => _50.nodeAt, 'call', _51 => _51(pos), 'optionalAccess', _52 => _52.type, 'access', _53 => _53.name]) === "tableHeader");
1350
1925
  const firstRow = map.cellsInRect({ left: 0, right: map.width, top: 0, bottom: 1 });
1351
1926
  const firstColumn = map.cellsInRect({ left: 0, right: 1, top: 0, bottom: map.height });
1352
1927
  const cell = cellAt(rect.top, rect.left);
@@ -1360,11 +1935,11 @@ function getTableState(editor) {
1360
1935
  column: rect.left,
1361
1936
  headerRow: allHeaders(firstRow),
1362
1937
  headerColumn: allHeaders(firstColumn),
1363
- headerCell: _optionalChain([cell, 'optionalAccess', _38 => _38.type, 'access', _39 => _39.name]) === "tableHeader",
1364
- cellAlignment: normalizeTableCellAlignment(_optionalChain([cell, 'optionalAccess', _40 => _40.attrs, 'access', _41 => _41.align])),
1365
- cellBackground: normalizeTableCellColor(_optionalChain([cell, 'optionalAccess', _42 => _42.attrs, 'access', _43 => _43.backgroundColor]))
1938
+ headerCell: _optionalChain([cell, 'optionalAccess', _54 => _54.type, 'access', _55 => _55.name]) === "tableHeader",
1939
+ cellAlignment: normalizeTableCellAlignment(_optionalChain([cell, 'optionalAccess', _56 => _56.attrs, 'access', _57 => _57.align])),
1940
+ cellBackground: normalizeTableCellColor(_optionalChain([cell, 'optionalAccess', _58 => _58.attrs, 'access', _59 => _59.backgroundColor]))
1366
1941
  };
1367
- } catch (e2) {
1942
+ } catch (e6) {
1368
1943
  return { ...base, inTable: true };
1369
1944
  }
1370
1945
  }
@@ -1382,10 +1957,10 @@ function createTableStore(editor) {
1382
1957
  listeners.forEach((listener) => listener());
1383
1958
  };
1384
1959
  const detach = () => {
1385
- _optionalChain([editor, 'optionalAccess', _44 => _44.off, 'call', _45 => _45("transaction", update)]);
1386
- _optionalChain([editor, 'optionalAccess', _46 => _46.off, 'call', _47 => _47("update", update)]);
1387
- _optionalChain([editor, 'optionalAccess', _48 => _48.off, 'call', _49 => _49("focus", update)]);
1388
- _optionalChain([editor, 'optionalAccess', _50 => _50.off, 'call', _51 => _51("destroy", update)]);
1960
+ _optionalChain([editor, 'optionalAccess', _60 => _60.off, 'call', _61 => _61("transaction", update)]);
1961
+ _optionalChain([editor, 'optionalAccess', _62 => _62.off, 'call', _63 => _63("update", update)]);
1962
+ _optionalChain([editor, 'optionalAccess', _64 => _64.off, 'call', _65 => _65("focus", update)]);
1963
+ _optionalChain([editor, 'optionalAccess', _66 => _66.off, 'call', _67 => _67("destroy", update)]);
1389
1964
  };
1390
1965
  return {
1391
1966
  getSnapshot: () => {
@@ -1461,5 +2036,23 @@ function createTableStore(editor) {
1461
2036
 
1462
2037
 
1463
2038
 
1464
- exports.ALLOW_NESTED_TABLES_META = ALLOW_NESTED_TABLES_META; exports.tableNestingPluginKey = tableNestingPluginKey; exports.outermostTableDepth = outermostTableDepth; exports.isInTableCell = isInTableCell; exports.sliceContainsTable = sliceContainsTable; exports.insertSliceAfterTable = insertSliceAfterTable; exports.handleTablePasteWithoutNesting = handleTablePasteWithoutNesting; exports.unnestTables = unnestTables; exports.createTableNestingPlugin = createTableNestingPlugin; exports.FIND_PARAGRAPH_MARK = FIND_PARAGRAPH_MARK; exports.MAX_FIND_PATTERN_LENGTH = MAX_FIND_PATTERN_LENGTH; exports.createSearchBudget = createSearchBudget; exports.foldCodePoint = foldCodePoint; exports.compileFindPattern = compileFindPattern; exports.findAllMatches = findAllMatches; exports.parseReplacement = parseReplacement; exports.expandReplacement = expandReplacement; exports.searchDocument = searchDocument; exports.applyReplacements = applyReplacements; exports.normalizeTableCellAlignment = normalizeTableCellAlignment; exports.normalizeTableCellColor = normalizeTableCellColor; exports.isGfmTable = isGfmTable; exports.DEFAULT_TABLE_OPTIONS = DEFAULT_TABLE_OPTIONS; exports.Table = Table; exports.TableRow = TableRow; exports.TableCell = TableCell; exports.TableHeader = TableHeader; exports.createTableExtensions = createTableExtensions; exports.TABLE_ACTIONS = TABLE_ACTIONS; exports.DEFAULT_TABLE_TOOLBAR = DEFAULT_TABLE_TOOLBAR; exports.MAX_TABLE_ROWS = MAX_TABLE_ROWS; exports.MAX_TABLE_COLUMNS = MAX_TABLE_COLUMNS; exports.isTableEnabled = isTableEnabled; exports.isSelectionInTable = isSelectionInTable; exports.shouldShowTableBubbleMenu = shouldShowTableBubbleMenu; exports.getTableActionState = getTableActionState; exports.runTableAction = runTableAction; exports.EMPTY_TABLE_STATE = EMPTY_TABLE_STATE; exports.getTableState = getTableState; exports.createTableStore = createTableStore;
1465
- //# sourceMappingURL=chunk-J3R2OWOE.cjs.map
2039
+
2040
+
2041
+
2042
+
2043
+
2044
+
2045
+
2046
+
2047
+
2048
+
2049
+
2050
+
2051
+
2052
+
2053
+
2054
+
2055
+
2056
+
2057
+ exports.ALLOW_NESTED_TABLES_META = ALLOW_NESTED_TABLES_META; exports.tableNestingPluginKey = tableNestingPluginKey; exports.outermostTableDepth = outermostTableDepth; exports.isInTableCell = isInTableCell; exports.sliceContainsTable = sliceContainsTable; exports.insertSliceAfterTable = insertSliceAfterTable; exports.handleTablePasteWithoutNesting = handleTablePasteWithoutNesting; exports.unnestTables = unnestTables; exports.createTableNestingPlugin = createTableNestingPlugin; exports.generateStructureId = generateStructureId; exports.presenceStateSpec = presenceStateSpec; exports.arraysEqual = arraysEqual; exports.scrollDomAtPos = scrollDomAtPos; exports.syncInitialContent = syncInitialContent; exports.STRUCTURE_PRIORITY = STRUCTURE_PRIORITY; exports.FIND_PARAGRAPH_MARK = FIND_PARAGRAPH_MARK; exports.MAX_FIND_PATTERN_LENGTH = MAX_FIND_PATTERN_LENGTH; exports.createSearchBudget = createSearchBudget; exports.foldCodePoint = foldCodePoint; exports.compileFindPattern = compileFindPattern; exports.findAllMatches = findAllMatches; exports.parseReplacement = parseReplacement; exports.expandReplacement = expandReplacement; exports.searchDocument = searchDocument; exports.applyReplacements = applyReplacements; exports.normalizeTableCellAlignment = normalizeTableCellAlignment; exports.normalizeTableCellColor = normalizeTableCellColor; exports.isGfmTable = isGfmTable; exports.DEFAULT_TABLE_OPTIONS = DEFAULT_TABLE_OPTIONS; exports.Table = Table; exports.TableRow = TableRow; exports.TableCell = TableCell; exports.TableHeader = TableHeader; exports.createTableExtensions = createTableExtensions; exports.ChartNodeView = ChartNodeView; exports.createChartNodeView = createChartNodeView; exports.chartPluginKey = chartPluginKey; exports.getDocumentCharts = getDocumentCharts; exports.isChartEnabled = isChartEnabled; exports.staticChartSvg = staticChartSvg; exports.Chart = Chart; exports.SPARKLINE_KINDS = SPARKLINE_KINDS; exports.MAX_SPARKLINE_VALUES = MAX_SPARKLINE_VALUES; exports.normalizeSparklineValues = normalizeSparklineValues; exports.sparklineLabel = sparklineLabel; exports.Sparkline = Sparkline; exports.TABLE_ACTIONS = TABLE_ACTIONS; exports.DEFAULT_TABLE_TOOLBAR = DEFAULT_TABLE_TOOLBAR; exports.MAX_TABLE_ROWS = MAX_TABLE_ROWS; exports.MAX_TABLE_COLUMNS = MAX_TABLE_COLUMNS; exports.isTableEnabled = isTableEnabled; exports.isSelectionInTable = isSelectionInTable; exports.shouldShowTableBubbleMenu = shouldShowTableBubbleMenu; exports.getTableActionState = getTableActionState; exports.runTableAction = runTableAction; exports.EMPTY_TABLE_STATE = EMPTY_TABLE_STATE; exports.getTableState = getTableState; exports.createTableStore = createTableStore;
2058
+ //# sourceMappingURL=chunk-MUCYWI6W.cjs.map