vertex-notes 0.1.4 → 0.2.1

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 (39) hide show
  1. package/dist/{chunk-4QLCD6TZ.js → chunk-EEEL6ZKK.js} +378 -43
  2. package/dist/chunk-EEEL6ZKK.js.map +1 -0
  3. package/dist/{chunk-DDFOKGIX.js → chunk-URRSVCB7.js} +2 -2
  4. package/dist/commands/capture.js +2 -2
  5. package/dist/commands/daily.js +2 -2
  6. package/dist/commands/delete.js +2 -2
  7. package/dist/commands/edit.js +3 -5
  8. package/dist/commands/edit.js.map +1 -1
  9. package/dist/commands/export.js +2 -2
  10. package/dist/commands/hello.js +1 -1
  11. package/dist/commands/help.js +23 -14
  12. package/dist/commands/help.js.map +1 -1
  13. package/dist/commands/howto.js +379 -0
  14. package/dist/commands/howto.js.map +1 -0
  15. package/dist/commands/import.js +39 -0
  16. package/dist/commands/import.js.map +1 -0
  17. package/dist/commands/interactive.js +187 -74
  18. package/dist/commands/interactive.js.map +1 -1
  19. package/dist/commands/login.js +1 -1
  20. package/dist/commands/new.js +2 -2
  21. package/dist/commands/notes.js +2 -2
  22. package/dist/commands/restore.js +2 -2
  23. package/dist/commands/search.js +2 -2
  24. package/dist/commands/status.js +2 -2
  25. package/dist/commands/syntax.js +276 -0
  26. package/dist/commands/syntax.js.map +1 -0
  27. package/dist/commands/tags.js +2 -2
  28. package/dist/commands/today.js +2 -2
  29. package/dist/commands/trash/empty.js +2 -2
  30. package/dist/commands/trash/index.js +2 -2
  31. package/dist/commands/view.js +2 -2
  32. package/dist/lib/client.js +2 -2
  33. package/dist/lib/md-to-tiptap.js +245 -3
  34. package/dist/lib/md-to-tiptap.js.map +1 -1
  35. package/package.json +2 -1
  36. package/dist/chunk-4QLCD6TZ.js.map +0 -1
  37. package/dist/chunk-FWK2J3FR.js +0 -163
  38. package/dist/chunk-FWK2J3FR.js.map +0 -1
  39. /package/dist/{chunk-DDFOKGIX.js.map → chunk-URRSVCB7.js.map} +0 -0
@@ -253,7 +253,9 @@ function mapTiptapTypeToBlockType(tiptapType) {
253
253
  calloutBlock: "callout",
254
254
  queryBlock: "query",
255
255
  horizontalRule: "divider",
256
- fileBlock: "file"
256
+ fileBlock: "file",
257
+ linkPreview: "text",
258
+ inlineMath: "text"
257
259
  };
258
260
  return MAP[tiptapType] ?? "text";
259
261
  }
@@ -395,6 +397,134 @@ function extractTextFromNode(node) {
395
397
  if (!content) return "";
396
398
  return content.map(extractTextFromNode).join("");
397
399
  }
400
+ function extractInlineMarkdown(node) {
401
+ if (node.type === "inlineMath") {
402
+ const formula = node.attrs?.formula ?? "";
403
+ return `$${formula}$`;
404
+ }
405
+ if (typeof node.text === "string") {
406
+ const marks = node.marks ?? [];
407
+ let text = node.text;
408
+ const linkMark = marks.find((m) => m.type === "link");
409
+ if (linkMark) {
410
+ const href = linkMark.attrs?.href ?? "";
411
+ return `[${text}](${href})`;
412
+ }
413
+ for (const mark of marks) {
414
+ if (mark.type === "bold") text = `**${text}**`;
415
+ else if (mark.type === "italic") text = `*${text}*`;
416
+ else if (mark.type === "code") text = `\`${text}\``;
417
+ else if (mark.type === "strike") text = `~~${text}~~`;
418
+ }
419
+ return text;
420
+ }
421
+ const content = node.content;
422
+ if (!content) return "";
423
+ return content.map(extractInlineMarkdown).join("");
424
+ }
425
+ function tiptapNodeToMarkdown(node) {
426
+ const type = node.type;
427
+ const attrs = node.attrs ?? {};
428
+ const content = node.content ?? [];
429
+ const lines = [];
430
+ switch (type) {
431
+ case "heading": {
432
+ const level = attrs.level ?? 1;
433
+ lines.push(`${"#".repeat(level)} ${extractInlineMarkdown({ content })}`);
434
+ break;
435
+ }
436
+ case "paragraph": {
437
+ lines.push(extractInlineMarkdown({ content }));
438
+ break;
439
+ }
440
+ case "taskList": {
441
+ for (const child of content) {
442
+ const childAttrs = child.attrs ?? {};
443
+ const checked = childAttrs.checked ? "x" : " ";
444
+ const text = extractInlineMarkdown(child);
445
+ lines.push(`- [${checked}] ${text}`);
446
+ }
447
+ break;
448
+ }
449
+ case "taskItem": {
450
+ const checked = attrs.checked ? "x" : " ";
451
+ lines.push(`- [${checked}] ${extractInlineMarkdown({ content })}`);
452
+ break;
453
+ }
454
+ case "bulletList": {
455
+ for (const child of content) {
456
+ const text = extractInlineMarkdown(child);
457
+ lines.push(`- ${text}`);
458
+ }
459
+ break;
460
+ }
461
+ case "orderedList": {
462
+ content.forEach((child, i) => {
463
+ const text = extractInlineMarkdown(child);
464
+ lines.push(`${i + 1}. ${text}`);
465
+ });
466
+ break;
467
+ }
468
+ case "codeBlock": {
469
+ const lang = attrs.language ?? "";
470
+ lines.push("```" + lang, extractTextFromNode(node), "```");
471
+ break;
472
+ }
473
+ case "mermaidBlock": {
474
+ lines.push("```mermaid", extractTextFromNode(node), "```");
475
+ break;
476
+ }
477
+ case "mathBlock": {
478
+ lines.push("$$", extractTextFromNode(node), "$$");
479
+ break;
480
+ }
481
+ case "calloutBlock": {
482
+ const variant = attrs.variant ?? "info";
483
+ const text = extractInlineMarkdown({ content });
484
+ lines.push(`> [!${variant}]`, ...text.split("\n").map((l) => `> ${l}`));
485
+ break;
486
+ }
487
+ case "queryBlock": {
488
+ const text = extractTextFromNode(node).trim();
489
+ lines.push(`> [!query]`, `> ${text}`);
490
+ break;
491
+ }
492
+ case "blockquote": {
493
+ const text = extractInlineMarkdown({ content });
494
+ lines.push(...text.split("\n").map((l) => `> ${l}`));
495
+ break;
496
+ }
497
+ case "horizontalRule": {
498
+ lines.push("---");
499
+ break;
500
+ }
501
+ case "image": {
502
+ const src = attrs.src ?? "";
503
+ const alt = attrs.alt ?? "";
504
+ lines.push(`![${alt}](${src})`);
505
+ break;
506
+ }
507
+ case "linkPreview": {
508
+ const url = attrs.url ?? "";
509
+ lines.push(`> [!embed]`, `> ${url}`);
510
+ break;
511
+ }
512
+ case "fileBlock": {
513
+ const src = attrs.src ?? "";
514
+ const filename = attrs.filename ?? "file";
515
+ const filesize = attrs.filesize ?? 0;
516
+ const filetype = attrs.filetype ?? "";
517
+ lines.push(`> [!file]`, `> [${filename}](${src})`, `> ${filetype} ${filesize}`);
518
+ break;
519
+ }
520
+ default: {
521
+ const text = extractTextFromNode(node);
522
+ if (text.trim()) lines.push(text);
523
+ break;
524
+ }
525
+ }
526
+ return lines;
527
+ }
398
528
  async function exportNoteAsJson(client, noteId) {
399
529
  const { data: note } = await client.from("notes").select("*").eq("id", noteId).single();
400
530
  const { data: blocks } = await client.from("blocks").select("*").eq("note_id", noteId).is("deleted_at", null).order("position");
@@ -408,53 +538,257 @@ async function exportNoteAsMarkdown(client, noteId) {
408
538
  const lines = [`# ${title}`, ""];
409
539
  for (const block of blocks) {
410
540
  const tiptap = block.metadata.tiptap;
411
- const type = tiptap?.type ?? block.type;
412
- const attrs = tiptap?.attrs ?? {};
413
- switch (type) {
414
- case "heading": {
415
- const level = attrs.level ?? 1;
416
- lines.push(`${"#".repeat(level)} ${block.content}`);
417
- break;
541
+ if (tiptap) {
542
+ lines.push(...tiptapNodeToMarkdown(tiptap), "");
543
+ } else {
544
+ if (block.content.trim()) lines.push(block.content, "");
545
+ }
546
+ }
547
+ return lines.join("\n");
548
+ }
549
+ function markdownToTiptap(md) {
550
+ const lines = md.split("\n");
551
+ const nodes = [];
552
+ let i = 0;
553
+ while (i < lines.length) {
554
+ const line = lines[i];
555
+ if (line.match(/^#{1,4}\s/)) {
556
+ const match = line.match(/^(#{1,4})\s(.*)$/);
557
+ if (match) {
558
+ nodes.push({
559
+ type: "heading",
560
+ attrs: { level: match[1].length },
561
+ content: parseInline(match[2])
562
+ });
563
+ }
564
+ i++;
565
+ continue;
566
+ }
567
+ if (line.match(/^```mermaid\s*$/)) {
568
+ const mermaidLines = [];
569
+ i++;
570
+ while (i < lines.length && !lines[i].match(/^```\s*$/)) {
571
+ mermaidLines.push(lines[i]);
572
+ i++;
573
+ }
574
+ i++;
575
+ nodes.push({
576
+ type: "mermaidBlock",
577
+ content: [{ type: "text", text: mermaidLines.join("\n") }]
578
+ });
579
+ continue;
580
+ }
581
+ if (line.match(/^```/)) {
582
+ const langMatch = line.match(/^```(\w*)$/);
583
+ const language = langMatch?.[1] || "plaintext";
584
+ const codeLines = [];
585
+ i++;
586
+ while (i < lines.length && !lines[i].match(/^```\s*$/)) {
587
+ codeLines.push(lines[i]);
588
+ i++;
589
+ }
590
+ i++;
591
+ nodes.push({
592
+ type: "codeBlock",
593
+ attrs: { language },
594
+ content: [{ type: "text", text: codeLines.join("\n") }]
595
+ });
596
+ continue;
597
+ }
598
+ if (line.match(/^\$\$\s*$/)) {
599
+ const mathLines = [];
600
+ i++;
601
+ while (i < lines.length && !lines[i].match(/^\$\$\s*$/)) {
602
+ mathLines.push(lines[i]);
603
+ i++;
604
+ }
605
+ i++;
606
+ nodes.push({
607
+ type: "mathBlock",
608
+ content: [{ type: "text", text: mathLines.join("\n") }]
609
+ });
610
+ continue;
611
+ }
612
+ if (line.match(/^>\s*\[!(\w+)\]\s*$/)) {
613
+ const variantMatch = line.match(/^>\s*\[!(\w+)\]\s*$/);
614
+ const variant = variantMatch?.[1] ?? "info";
615
+ if (variant === "query") {
616
+ const queryLines = [];
617
+ i++;
618
+ while (i < lines.length && lines[i].match(/^>\s/)) {
619
+ queryLines.push(lines[i].replace(/^>\s?/, ""));
620
+ i++;
621
+ }
622
+ nodes.push({
623
+ type: "queryBlock",
624
+ content: [{ type: "text", text: queryLines.join("\n") }]
625
+ });
626
+ continue;
627
+ }
628
+ if (variant === "embed") {
629
+ i++;
630
+ const embedUrl = lines[i]?.replace(/^>\s?/, "").trim() ?? "";
631
+ i++;
632
+ nodes.push({
633
+ type: "linkPreview",
634
+ attrs: { url: embedUrl }
635
+ });
636
+ continue;
637
+ }
638
+ if (variant === "file") {
639
+ i++;
640
+ const linkLine = lines[i]?.replace(/^>\s?/, "") ?? "";
641
+ const linkMatch = linkLine.match(/^\[(.+?)\]\((.+?)\)$/);
642
+ i++;
643
+ const metaLine = lines[i]?.replace(/^>\s?/, "") ?? "";
644
+ const metaParts = metaLine.split(" ");
645
+ i++;
646
+ nodes.push({
647
+ type: "fileBlock",
648
+ attrs: {
649
+ filename: linkMatch?.[1] ?? "file",
650
+ src: linkMatch?.[2] ?? "",
651
+ filetype: metaParts[0] ?? "",
652
+ filesize: parseInt(metaParts[1] ?? "0", 10) || 0
653
+ }
654
+ });
655
+ continue;
656
+ }
657
+ const calloutLines = [];
658
+ i++;
659
+ while (i < lines.length && lines[i].match(/^>\s/)) {
660
+ calloutLines.push(lines[i].replace(/^>\s?/, ""));
661
+ i++;
662
+ }
663
+ nodes.push({
664
+ type: "calloutBlock",
665
+ attrs: { variant },
666
+ content: [{ type: "paragraph", content: parseInline(calloutLines.join("\n")) }]
667
+ });
668
+ continue;
669
+ }
670
+ if (line.match(/^>\s/)) {
671
+ const quoteLines = [];
672
+ while (i < lines.length && lines[i].match(/^>\s?/)) {
673
+ quoteLines.push(lines[i].replace(/^>\s?/, ""));
674
+ i++;
418
675
  }
419
- case "taskList": {
420
- const children = tiptap?.content ?? [];
421
- for (const child of children) {
422
- const childAttrs = child.attrs ?? {};
423
- const checked = childAttrs.checked ? "x" : " ";
424
- const text = extractTextFromNode(child);
425
- lines.push(`- [${checked}] ${text}`);
676
+ nodes.push({
677
+ type: "blockquote",
678
+ content: [{ type: "paragraph", content: parseInline(quoteLines.join("\n")) }]
679
+ });
680
+ continue;
681
+ }
682
+ if (line.match(/^---\s*$/)) {
683
+ nodes.push({ type: "horizontalRule" });
684
+ i++;
685
+ continue;
686
+ }
687
+ if (line.match(/^!\[.*?\]\(.*?\)$/)) {
688
+ const imgMatch = line.match(/^!\[(.*?)\]\((.*?)\)$/);
689
+ if (imgMatch) {
690
+ nodes.push({
691
+ type: "image",
692
+ attrs: { src: imgMatch[2], alt: imgMatch[1] }
693
+ });
694
+ }
695
+ i++;
696
+ continue;
697
+ }
698
+ if (line.match(/^[-*]\s\[[ x]\]\s/)) {
699
+ const taskItems = [];
700
+ while (i < lines.length && lines[i].match(/^[-*]\s\[[ x]\]\s/)) {
701
+ const m = lines[i].match(/^[-*]\s\[([ x])\]\s(.*)$/);
702
+ if (m) {
703
+ taskItems.push({
704
+ type: "taskItem",
705
+ attrs: { checked: m[1] === "x" },
706
+ content: [{ type: "paragraph", content: parseInline(m[2]) }]
707
+ });
426
708
  }
427
- break;
709
+ i++;
428
710
  }
429
- case "taskItem": {
430
- const checked = attrs.checked ? "x" : " ";
431
- lines.push(`- [${checked}] ${block.content}`);
432
- break;
711
+ nodes.push({ type: "taskList", content: taskItems });
712
+ continue;
713
+ }
714
+ if (line.match(/^[-*]\s/)) {
715
+ const items = [];
716
+ while (i < lines.length && lines[i].match(/^[-*]\s/)) {
717
+ const text = lines[i].replace(/^[-*]\s/, "");
718
+ items.push({
719
+ type: "listItem",
720
+ content: [{ type: "paragraph", content: parseInline(text) }]
721
+ });
722
+ i++;
433
723
  }
434
- case "codeBlock": {
435
- const lang = attrs.language ?? "";
436
- lines.push("```" + lang, block.content, "```");
437
- break;
724
+ nodes.push({ type: "bulletList", content: items });
725
+ continue;
726
+ }
727
+ if (line.match(/^\d+\.\s/)) {
728
+ const items = [];
729
+ while (i < lines.length && lines[i].match(/^\d+\.\s/)) {
730
+ const text = lines[i].replace(/^\d+\.\s/, "");
731
+ items.push({
732
+ type: "listItem",
733
+ content: [{ type: "paragraph", content: parseInline(text) }]
734
+ });
735
+ i++;
438
736
  }
439
- case "bulletList":
440
- lines.push(`- ${block.content}`);
441
- break;
442
- case "orderedList":
443
- lines.push(`1. ${block.content}`);
444
- break;
445
- case "blockquote":
446
- lines.push(`> ${block.content}`);
447
- break;
448
- case "horizontalRule":
449
- lines.push("---");
450
- break;
451
- default:
452
- lines.push(block.content);
453
- break;
454
- }
455
- lines.push("");
737
+ nodes.push({ type: "orderedList", content: items });
738
+ continue;
739
+ }
740
+ if (line.trim() === "") {
741
+ i++;
742
+ continue;
743
+ }
744
+ const paraLines = [];
745
+ while (i < lines.length && lines[i].trim() !== "" && !lines[i].match(/^#{1,4}\s/) && !lines[i].match(/^```/) && !lines[i].match(/^\$\$/) && !lines[i].match(/^---\s*$/) && !lines[i].match(/^[-*]\s/) && !lines[i].match(/^\d+\.\s/) && !lines[i].match(/^>\s/) && !lines[i].match(/^!\[/)) {
746
+ paraLines.push(lines[i]);
747
+ i++;
748
+ }
749
+ nodes.push({
750
+ type: "paragraph",
751
+ content: parseInline(paraLines.join("\n"))
752
+ });
456
753
  }
457
- return lines.join("\n");
754
+ if (nodes.length === 0) {
755
+ nodes.push({ type: "paragraph" });
756
+ }
757
+ return { type: "doc", content: nodes };
758
+ }
759
+ function parseInline(text) {
760
+ if (!text) return [];
761
+ const nodes = [];
762
+ const regex = /(\*\*([^*]+)\*\*|\*([^*]+)\*|`([^`]+)`|~~([^~]+)~~|\[\[([^\]]+)\]\]|#([a-zA-Z][a-zA-Z0-9_/-]*)|\[([^\]]+)\]\(([^)]+)\)|(?<!\$)\$([^\$\n]+)\$(?!\$))/g;
763
+ let lastIndex = 0;
764
+ let match;
765
+ while ((match = regex.exec(text)) !== null) {
766
+ if (match.index > lastIndex) {
767
+ nodes.push({ type: "text", text: text.slice(lastIndex, match.index) });
768
+ }
769
+ if (match[2]) {
770
+ nodes.push({ type: "text", text: match[2], marks: [{ type: "bold" }] });
771
+ } else if (match[3]) {
772
+ nodes.push({ type: "text", text: match[3], marks: [{ type: "italic" }] });
773
+ } else if (match[4]) {
774
+ nodes.push({ type: "text", text: match[4], marks: [{ type: "code" }] });
775
+ } else if (match[5]) {
776
+ nodes.push({ type: "text", text: match[5], marks: [{ type: "strike" }] });
777
+ } else if (match[6]) {
778
+ nodes.push({ type: "text", text: `[[${match[6]}]]` });
779
+ } else if (match[7]) {
780
+ nodes.push({ type: "text", text: `#${match[7]}` });
781
+ } else if (match[8] && match[9]) {
782
+ nodes.push({ type: "text", text: match[8], marks: [{ type: "link", attrs: { href: match[9], target: "_blank" } }] });
783
+ } else if (match[10]) {
784
+ nodes.push({ type: "inlineMath", attrs: { formula: match[10] } });
785
+ }
786
+ lastIndex = match.index + match[0].length;
787
+ }
788
+ if (lastIndex < text.length) {
789
+ nodes.push({ type: "text", text: text.slice(lastIndex) });
790
+ }
791
+ return nodes.length > 0 ? nodes : [{ type: "text", text: text || " " }];
458
792
  }
459
793
  var VERTEX_VERSION = "0.1.0";
460
794
 
@@ -474,6 +808,7 @@ export {
474
808
  executeQuery,
475
809
  exportNoteAsJson,
476
810
  exportNoteAsMarkdown,
811
+ markdownToTiptap,
477
812
  VERTEX_VERSION
478
813
  };
479
- //# sourceMappingURL=chunk-4QLCD6TZ.js.map
814
+ //# sourceMappingURL=chunk-EEEL6ZKK.js.map