@crewlethq/ui 0.156.0 → 0.157.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.
@@ -1,4 +1,4 @@
1
- import { MARKDOWN_CALLOUT_TONES, parseMarkdownSpans, markdownInline, markdownCodeText } from './chunk-KBZO4B33.js';
1
+ import { MARKDOWN_CALLOUT_TONES, parseMarkdownSpans, markdownInline, markdownCodeText, htmlBlockStart } from './chunk-KMTOGF6T.js';
2
2
  import { Schema, Fragment } from 'prosemirror-model';
3
3
 
4
4
  function headingTag(level) {
@@ -23,7 +23,7 @@ var schema = new Schema({
23
23
  doc: { content: "block+" },
24
24
  paragraph: {
25
25
  content: "inline*",
26
- group: "block item_first item_rest",
26
+ group: "block",
27
27
  parseDOM: [{ tag: "p" }],
28
28
  toDOM: () => ["p", 0]
29
29
  },
@@ -31,7 +31,7 @@ var schema = new Schema({
31
31
  attrs: { level: { default: 1 } },
32
32
  // A heading is one line of Markdown, so it holds no line break.
33
33
  content: "(text | image)*",
34
- group: "block item_first",
34
+ group: "block",
35
35
  defining: true,
36
36
  // THE ELEMENT IS ONE LEVEL DOWN from the Markdown (a `#` is an `h2`), so
37
37
  // the level it was written at travels in `data-level`, and a heading
@@ -70,7 +70,7 @@ var schema = new Schema({
70
70
  },
71
71
  blockquote: {
72
72
  content: "block+",
73
- group: "block item_first item_rest",
73
+ group: "block",
74
74
  defining: true,
75
75
  parseDOM: [{ tag: "blockquote" }],
76
76
  toDOM: () => ["blockquote", 0]
@@ -78,7 +78,7 @@ var schema = new Schema({
78
78
  callout: {
79
79
  attrs: { tone: { default: "note" } },
80
80
  content: "block+",
81
- group: "block item_first item_rest",
81
+ group: "block",
82
82
  defining: true,
83
83
  parseDOM: [
84
84
  {
@@ -94,21 +94,21 @@ var schema = new Schema({
94
94
  ]
95
95
  },
96
96
  horizontal_rule: {
97
- group: "block item_first item_rest",
97
+ group: "block",
98
98
  parseDOM: [{ tag: "hr" }],
99
99
  toDOM: () => ["hr"]
100
100
  },
101
101
  bullet_list: {
102
102
  attrs: { marker: { default: "-" }, loose: { default: false } },
103
103
  content: "list_item+",
104
- group: "block item_first item_rest",
104
+ group: "block",
105
105
  parseDOM: [{ tag: "ul" }],
106
106
  toDOM: () => ["ul", 0]
107
107
  },
108
108
  ordered_list: {
109
109
  attrs: { start: { default: 1 }, marker: { default: "." }, loose: { default: false } },
110
110
  content: "list_item+",
111
- group: "block item_first item_rest",
111
+ group: "block",
112
112
  parseDOM: [
113
113
  {
114
114
  tag: "ol",
@@ -120,11 +120,10 @@ var schema = new Schema({
120
120
  list_item: {
121
121
  // null is a plain item; true and false are a task item, ticked or not.
122
122
  attrs: { checked: { default: null } },
123
- // WHAT AN ITEM CAN HOLD AND STILL BE WRITTEN BACK: the grammar reads an
124
- // item's later blocks from indented lines, and an indented fence or
125
- // heading is a paragraph to it. A heading is kept on the marker line;
126
- // a code block is never inside an item.
127
- content: "item_first item_rest*",
123
+ // AN ITEM HOLDS BLOCKS, any of them, as a CommonMark item does: the
124
+ // grammar reads an item's lines as blocks at its content indent, and
125
+ // the writer writes every block back there.
126
+ content: "block+",
128
127
  defining: true,
129
128
  parseDOM: [
130
129
  {
@@ -145,7 +144,7 @@ var schema = new Schema({
145
144
  // A column's alignment is on each of its cells, which is where the
146
145
  // reader's renderer draws it; the header row's is what is written.
147
146
  content: "table_row+",
148
- group: "block item_first item_rest",
147
+ group: "block",
149
148
  isolating: true,
150
149
  parseDOM: [{ tag: "table" }],
151
150
  toDOM: () => ["div", { class: "md-table" }, ["table", ["tbody", 0]]]
@@ -273,7 +272,7 @@ function blockNode(block2) {
273
272
  return schema.node(
274
273
  block2.ordered ? "ordered_list" : "bullet_list",
275
274
  block2.ordered ? { start: block2.start, marker: block2.marker, loose: block2.loose } : { marker: block2.marker, loose: block2.loose },
276
- block2.items.map((item) => schema.node("list_item", { checked: item.checked }, itemNodes(item.blocks)))
275
+ block2.items.map((item) => schema.node("list_item", { checked: item.checked }, blockNodes(item.blocks)))
277
276
  );
278
277
  case "table":
279
278
  return schema.node("table", null, [
@@ -286,19 +285,6 @@ function blockNodes(blocks2) {
286
285
  const nodes = blocks2.map(blockNode);
287
286
  return nodes.length > 0 ? nodes : [schema.node("paragraph")];
288
287
  }
289
- function itemNodes(blocks2) {
290
- const nodes = blockNodes(blocks2);
291
- const item = schema.nodes.list_item;
292
- const fitted = [];
293
- for (const node of nodes) {
294
- if (item.contentMatch.matchFragment(Fragment.from([...fitted, node]))) {
295
- fitted.push(node);
296
- } else {
297
- fitted.push(schema.node("paragraph", null, node.textContent ? schema.text(node.textContent) : void 0));
298
- }
299
- }
300
- return fitted;
301
- }
302
288
  function row(type, cells, align) {
303
289
  const nodes = cells.map(
304
290
  (cell2, i) => schema.node(type, { align: align[i] ?? "left" }, inline(cell2, [], { breaks: false }))
@@ -364,6 +350,12 @@ function collapse(nodes) {
364
350
  lastSpace = false;
365
351
  continue;
366
352
  }
353
+ if (isCode(node)) {
354
+ out.push(node);
355
+ lineStart = false;
356
+ lastSpace = false;
357
+ continue;
358
+ }
367
359
  let text = node.text ?? "";
368
360
  if (lineStart || lastSpace) text = text.replace(/^ /, "");
369
361
  if (!text) continue;
@@ -376,7 +368,7 @@ function collapse(nodes) {
376
368
  }
377
369
  function trimEnd(out) {
378
370
  const last = out[out.length - 1];
379
- if (!last?.isText) return;
371
+ if (!last?.isText || isCode(last)) return;
380
372
  const text = (last.text ?? "").replace(/ $/, "");
381
373
  if (text) out[out.length - 1] = schema.text(text, last.marks);
382
374
  else out.pop();
@@ -387,21 +379,25 @@ function writeMarkdown(doc, source) {
387
379
  let out = "";
388
380
  let emitted = false;
389
381
  let prev = null;
390
- let prevNode = null;
382
+ let last = null;
391
383
  for (let i = 0; i < doc.childCount; i++) {
392
384
  const node = doc.child(i);
393
- const known = source ? recall(node, source, used) : null;
394
- const text = known ? known.text : writeBlock(node);
385
+ let known = source ? recall(node, source, used) : null;
386
+ const marker = markerAfter(last, node);
387
+ if (known && isList(node) && marker !== node.attrs.marker) {
388
+ used.delete(known.index);
389
+ known = null;
390
+ }
391
+ const text = known ? known.text : writeBlock(node, marker);
395
392
  if (!known && text === "") continue;
396
393
  if (!emitted) {
397
394
  out = (known && known.index === 0 && source ? source.lead : "") + text;
398
395
  } else {
399
- const adjacent = known && prev && known.index === prev.index + 1;
400
- out += (adjacent ? known.sep : separator(prevNode, node)) + text;
396
+ out += (known && prev && known.index === prev.index + 1 ? known.sep : "\n\n") + text;
401
397
  }
402
398
  emitted = true;
403
399
  prev = known;
404
- prevNode = node;
400
+ last = { node, marker };
405
401
  }
406
402
  if (source) {
407
403
  const lastBlock = source.blocks[source.blocks.length - 1];
@@ -434,34 +430,33 @@ function recall(node, source, used) {
434
430
  }
435
431
  return null;
436
432
  }
437
- function separator(prev, next) {
438
- if (prev && isList(prev) && isList(next) && (prev.type === next.type || bothBullet(prev, next))) return "\n\n\n";
439
- return "\n\n";
433
+ var OTHER_MARKER = { "-": "*", "*": "-", "+": "-", ".": ")", ")": "." };
434
+ function markerAfter(last, node) {
435
+ const own = node.attrs.marker ?? "";
436
+ if (!isList(node) || !last || last.node.type !== node.type || last.marker !== own) return own;
437
+ return OTHER_MARKER[own] ?? own;
440
438
  }
441
439
  function isList(node) {
442
440
  return node.type.name === "bullet_list" || node.type.name === "ordered_list";
443
441
  }
444
- function bothBullet(a, b) {
445
- return a.type.name === "bullet_list" && b.type.name === "bullet_list";
446
- }
447
442
  var RULE = "-".repeat(3);
448
443
  var SPELLINGS = [
449
444
  { markers: "keep", escape: "light" },
450
445
  { markers: "star", escape: "light" },
451
446
  { markers: "star", escape: "all" }
452
447
  ];
453
- function writeBlock(node) {
448
+ function writeBlock(node, marker) {
454
449
  if (node.type.name === "paragraph" && node.childCount === 0) return "";
455
- const want = signature(node);
450
+ const want = signature(asWritten(node));
456
451
  let text = "";
457
452
  for (const spelling of SPELLINGS) {
458
- text = block(node, spelling);
453
+ text = block(node, spelling, marker);
459
454
  const back = readMarkdown(text).doc;
460
455
  if (back.childCount === 1 && signature(back.firstChild) === want) return text;
461
456
  }
462
457
  return text;
463
458
  }
464
- function block(node, s) {
459
+ function block(node, s, marker) {
465
460
  switch (node.type.name) {
466
461
  case "paragraph":
467
462
  return lineStarts(inlineText(node, s, false).replace(/^[ \t]+|[ \t]+$/g, ""));
@@ -480,7 +475,7 @@ ${blocks(node, s)}`);
480
475
  return RULE;
481
476
  case "bullet_list":
482
477
  case "ordered_list":
483
- return list(node, s);
478
+ return list(node, s, marker ?? node.attrs.marker);
484
479
  case "table":
485
480
  return table(node, s);
486
481
  default:
@@ -489,12 +484,12 @@ ${blocks(node, s)}`);
489
484
  }
490
485
  function blocks(parent, s) {
491
486
  const parts = [];
492
- let prev = null;
487
+ let last = null;
493
488
  parent.forEach((child) => {
494
- const text = block(child, s);
495
- if (parts.length > 0) parts.push(separator(prev, child));
496
- parts.push(text);
497
- prev = child;
489
+ const marker = markerAfter(last, child);
490
+ if (parts.length > 0) parts.push("\n\n");
491
+ parts.push(block(child, s, marker));
492
+ last = { node: child, marker };
498
493
  });
499
494
  return parts.join("");
500
495
  }
@@ -504,35 +499,91 @@ function quoted(text) {
504
499
  function codeBlock(node) {
505
500
  const text = node.textContent;
506
501
  const lang = node.attrs.lang;
507
- const closes = (fence2) => text.split("\n").some((line) => CLOSER[fence2].test(line));
508
- const wanted = node.attrs.fence;
509
- const other = wanted === "```" ? "~~~" : "```";
510
- const fence = closes(wanted) && !closes(other) ? other : wanted;
502
+ const char = node.attrs.fence[0] ?? "`";
503
+ const longest = Math.max(0, ...(text.match(char === "`" ? /`+/g : /~+/g) ?? []).map((run) => run.length));
504
+ const fence = char.repeat(Math.max(3, longest + 1));
511
505
  return `${fence}${lang}
512
506
  ${text}${text ? "\n" : ""}${fence}`;
513
507
  }
514
- var CLOSER = { "```": /^`{3,}[ \t]*$/, "~~~": /^~{3,}[ \t]*$/ };
515
- function list(node, s) {
508
+ function list(node, s, listMarker) {
516
509
  const ordered = node.type.name === "ordered_list";
517
- const loose = node.attrs.loose;
518
- const items = [];
510
+ const { items, loose } = layout(node);
511
+ const written = [];
519
512
  node.forEach((item, _offset, i) => {
520
- const marker = ordered ? `${node.attrs.start + i}${node.attrs.marker} ` : `${node.attrs.marker} `;
513
+ const marker = ordered ? `${node.attrs.start + i}${listMarker} ` : `${listMarker} `;
521
514
  const checked = item.attrs.checked;
522
515
  const box = checked === null ? "" : checked ? "[x] " : "[ ] ";
523
516
  const indent = " ".repeat(marker.length);
524
517
  const parts = [];
525
- item.forEach((child) => {
526
- if (parts.length > 0) parts.push(isList(child) ? "\n" : "\n\n");
527
- parts.push(block(child, s));
528
- });
529
- const body = parts.join("");
530
- const lines = body.split("\n");
531
- items.push(
518
+ let last = null;
519
+ for (const child of items[i]) {
520
+ const prev = last ? last.node : null;
521
+ const childMarker = markerAfter(last, child);
522
+ if (prev) parts.push(loose ? "\n\n" : "\n");
523
+ parts.push(
524
+ !loose && prev?.type.name === "paragraph" && child.type.name === "horizontal_rule" ? "***" : block(child, s, childMarker)
525
+ );
526
+ last = { node: child, marker: childMarker };
527
+ }
528
+ const lines = parts.join("").split("\n");
529
+ written.push(
532
530
  marker + box + lines.map((line, j) => j === 0 ? line : line === "" ? "" : indent + line).join("\n")
533
531
  );
534
532
  });
535
- return items.join(loose ? "\n\n" : "\n");
533
+ return written.join(loose ? "\n\n" : "\n");
534
+ }
535
+ function opensHtmlBlock(paragraph) {
536
+ const first = paragraph.firstChild;
537
+ if (!first?.isText || first.marks.length > 0) return false;
538
+ return htmlBlockStart(first.text ?? "");
539
+ }
540
+ function layout(node) {
541
+ const items = [];
542
+ node.forEach((item) => {
543
+ const children = [];
544
+ item.forEach((child) => {
545
+ if (child.type.name !== "paragraph" || child.childCount > 0) children.push(child);
546
+ });
547
+ items.push(children.length > 0 ? children : [schema.node("paragraph")]);
548
+ });
549
+ const loose = node.attrs.loose || items.some((children) => children.some((child, j) => j > 0 && needsBlank(children[j - 1], child)));
550
+ return { items, loose };
551
+ }
552
+ function asWritten(node) {
553
+ if (node.isLeaf || node.isTextblock) return node;
554
+ if (isList(node)) {
555
+ const { items, loose } = layout(node);
556
+ const children2 = [];
557
+ node.forEach((item, _o, i) => children2.push(item.copy(Fragment.from(items[i].map(asWritten)))));
558
+ return node.type.create({ ...node.attrs, loose }, children2);
559
+ }
560
+ const children = [];
561
+ node.forEach((child) => children.push(asWritten(child)));
562
+ return node.copy(Fragment.from(children));
563
+ }
564
+ function needsBlank(prev, next) {
565
+ const p = prev.type.name;
566
+ const n = next.type.name;
567
+ if (p === "code_block" || p === "heading" || p === "horizontal_rule") return false;
568
+ const quoted2 = (name) => name === "blockquote" || name === "callout";
569
+ if (quoted2(p) && quoted2(n)) return true;
570
+ switch (n) {
571
+ case "paragraph":
572
+ return !opensHtmlBlock(next);
573
+ case "table":
574
+ return p === "table";
575
+ case "bullet_list":
576
+ case "ordered_list": {
577
+ const first = next.firstChild;
578
+ let empty = first !== null && first.attrs.checked === null;
579
+ first?.forEach((child) => {
580
+ if (child.type.name !== "paragraph" || child.childCount > 0) empty = false;
581
+ });
582
+ return p === "paragraph" && (empty || n === "ordered_list" && next.attrs.start !== 1);
583
+ }
584
+ default:
585
+ return false;
586
+ }
536
587
  }
537
588
  function table(node, s) {
538
589
  const rows = [];
@@ -551,9 +602,12 @@ function table(node, s) {
551
602
  }
552
603
  function lineStarts(text) {
553
604
  return text.split("\n").map(
554
- (line) => line.replace(/^(#{1,6})(?=\s|$)/, "\\$1").replace(/^>/, "\\>").replace(/^([-+])(?=\s)/, "\\$1").replace(/^(\d{1,9})([.)])(?=\s)/, "$1\\$2").replace(/^(-{3,}|_{3,})\s*$/, "\\$1").replace(/^\|/, "\\|")
605
+ (line) => line.replace(/^(#{1,6})(?=\s|$)/, "\\$1").replace(/^>/, "\\>").replace(/^([-+])(?=\s)/, "\\$1").replace(/^(\d{1,9})([.)])(?=\s)/, "$1\\$2").replace(/^(-{3,}|_{3,})\s*$/, "\\$1")
555
606
  ).join("\n");
556
607
  }
608
+ function isCode(node) {
609
+ return node.marks.some((m) => m.type.name === "code");
610
+ }
557
611
  function inlineText(parent, s, cell2) {
558
612
  const children = [];
559
613
  parent.forEach((child) => children.push(child));
@@ -657,12 +711,15 @@ function content(node, s, cell2, next, inLink) {
657
711
  const escaped = escapeText(text, s.escape, cell2, next);
658
712
  return inLink ? escaped.replace(/(^|[^\\])\]/g, "$1\\]") : escaped;
659
713
  }
660
- function codeSpan(text, cell2) {
714
+ function codeSpan(code, cell2) {
715
+ const text = code.replace(/\n/g, " ");
661
716
  const longest = Math.max(0, ...(text.match(/`+/g) ?? []).map((run) => run.length));
662
717
  const fence = "`".repeat(longest + 1);
663
- const pad = (side) => side === " " || side === "`" ? " " : "";
718
+ const first = text[0] ?? "";
719
+ const last = text[text.length - 1] ?? "";
720
+ const pad = first === "`" || last === "`" || first === " " && last === " " && text.trim() !== "" ? " " : "";
664
721
  const body = cell2 ? text.replace(/\|/g, "\\|") : text;
665
- return `${fence}${pad(body[0] ?? "")}${body}${pad(body[body.length - 1] ?? "")}${fence}`;
722
+ return `${fence}${pad}${body}${pad}${fence}`;
666
723
  }
667
724
  var ASCII_PUNCTUATION = /[!-/:-@[-`{-~]/;
668
725
  function escapeText(text, mode, cell2, next) {
@@ -683,7 +740,7 @@ function escapeText(text, mode, cell2, next) {
683
740
  const word = /[\p{L}\p{N}]/u;
684
741
  out += word.test(before) && word.test(after) ? "_" : "\\_";
685
742
  } else if (c === "~") {
686
- out += after === "~" || before === "~" ? "\\~" : "~";
743
+ out += /^\s?$/.test(before) && /^\s?$/.test(after) ? "~" : "\\~";
687
744
  } else if (c === "[") {
688
745
  out += text.indexOf("](", i) >= 0 ? "\\[" : "[";
689
746
  } else if (c === "<") {
@@ -712,7 +769,9 @@ function signature(node) {
712
769
  const marks = node.marks.filter((m) => m.type.name !== "link").map((m) => m.type.name).join("+");
713
770
  const link = linkOf(node);
714
771
  const tag = `${marks}${link ? `@${link.attrs.href}` : ""}`;
715
- return [...node.text ?? ""].map((c) => c === " " ? " " : `${c}${tag ? `{${tag}}` : ""}`).join("");
772
+ const code = isCode(node);
773
+ const text = code ? (node.text ?? "").replace(/\n/g, " ") : node.text ?? "";
774
+ return [...text].map((c) => c === " " && !code ? " " : `${c}${tag ? `{${tag}}` : ""}`).join("");
716
775
  }
717
776
  const attrs = visibleAttrs(node);
718
777
  let inner = "";
@@ -732,8 +791,11 @@ function visibleAttrs(node) {
732
791
  return ` ${node.attrs.lang}`;
733
792
  case "callout":
734
793
  return ` ${node.attrs.tone}`;
794
+ // LOOSENESS IS SEEN: a loose list's items stand apart from each other.
795
+ case "bullet_list":
796
+ return ` ${String(node.attrs.loose)}`;
735
797
  case "ordered_list":
736
- return ` ${node.attrs.start}`;
798
+ return ` ${node.attrs.start} ${String(node.attrs.loose)}`;
737
799
  case "list_item":
738
800
  return ` ${String(node.attrs.checked)}`;
739
801
  case "table_header":
@@ -1,4 +1,4 @@
1
- import { MARKDOWN_CALLOUT_NAMES } from './chunk-KBZO4B33.js';
1
+ import { MARKDOWN_CALLOUT_NAMES } from './chunk-KMTOGF6T.js';
2
2
 
3
3
  // src/RichEditor/types.ts
4
4
  var RICH_EDITOR_LABELS = {