@estiva-app/ui 0.50.4 → 0.52.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 (51) hide show
  1. package/dist/CollapsibleSection.d.ts +7 -1
  2. package/dist/CollapsibleSection.d.ts.map +1 -1
  3. package/dist/ComposerTriggers.d.ts +169 -0
  4. package/dist/ComposerTriggers.d.ts.map +1 -0
  5. package/dist/NavItem.d.ts +23 -3
  6. package/dist/NavItem.d.ts.map +1 -1
  7. package/dist/NavTree.d.ts +49 -0
  8. package/dist/NavTree.d.ts.map +1 -0
  9. package/dist/SectionLabel.d.ts +7 -1
  10. package/dist/SectionLabel.d.ts.map +1 -1
  11. package/dist/editor.d.ts +1 -0
  12. package/dist/editor.d.ts.map +1 -1
  13. package/dist/editor.js +313 -12
  14. package/dist/editor.js.map +4 -4
  15. package/dist/eslint/index.js +1 -1
  16. package/dist/eslint/index.js.map +2 -2
  17. package/dist/eslint/no-native-title.d.ts +1 -1
  18. package/dist/eslint/no-native-title.d.ts.map +1 -1
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +332 -212
  22. package/dist/index.js.map +4 -4
  23. package/dist/looks.d.ts +7 -0
  24. package/dist/looks.d.ts.map +1 -1
  25. package/package.json +6 -1
  26. package/registry.json +426 -5
  27. package/src/CollapsibleSection.mdx +6 -0
  28. package/src/CollapsibleSection.stories.tsx +5 -0
  29. package/src/CollapsibleSection.tsx +12 -4
  30. package/src/ComposerTriggers.mdx +108 -0
  31. package/src/ComposerTriggers.stories.tsx +79 -0
  32. package/src/ComposerTriggers.test.tsx +207 -0
  33. package/src/ComposerTriggers.tsx +507 -0
  34. package/src/NavItem.mdx +30 -0
  35. package/src/NavItem.stories.tsx +34 -0
  36. package/src/NavItem.test.tsx +82 -0
  37. package/src/NavItem.tsx +123 -25
  38. package/src/NavTree.mdx +83 -0
  39. package/src/NavTree.stories.tsx +84 -0
  40. package/src/NavTree.test.tsx +54 -0
  41. package/src/NavTree.tsx +112 -0
  42. package/src/SectionHeader.tsx +1 -1
  43. package/src/SectionLabel.mdx +4 -1
  44. package/src/SectionLabel.stories.tsx +3 -0
  45. package/src/SectionLabel.tsx +10 -2
  46. package/src/editor.ts +29 -0
  47. package/src/eslint/no-native-title.ts +1 -1
  48. package/src/index.ts +1 -0
  49. package/src/looks.ts +8 -0
  50. package/src/registry/registry.test.ts +9 -8
  51. package/stories/Choosing.mdx +2 -0
package/dist/editor.js CHANGED
@@ -347,12 +347,298 @@ function suggestionPopup(options) {
347
347
  };
348
348
  }
349
349
 
350
+ // src/ComposerTriggers.tsx
351
+ import { Extension as Extension2 } from "@tiptap/core";
352
+ import { PluginKey as PluginKey2 } from "@tiptap/pm/state";
353
+ import Mention from "@tiptap/extension-mention";
354
+ import Suggestion from "@tiptap/suggestion";
355
+ import { NodeViewWrapper, ReactNodeViewRenderer } from "@tiptap/react";
356
+ import { Avatar } from "@estiva-app/ui";
357
+ import { EnterHint } from "@estiva-app/ui";
358
+ import { inlineChipClassName } from "@estiva-app/ui";
359
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
360
+ var PEOPLE_LIMIT = 6;
361
+ function filterPeople(people, query) {
362
+ const q = query.toLowerCase();
363
+ return people.filter((person) => q === "" || person.name.toLowerCase().includes(q)).slice(0, PEOPLE_LIMIT);
364
+ }
365
+ function peopleMenu(urgent) {
366
+ const section = urgent ? "Urgent mention" : "People";
367
+ return {
368
+ ariaLabel: section,
369
+ // The people and the reference lists are the same box: 658px, capped at 360.
370
+ width: "w-[658px]",
371
+ maxHeight: "max-h-[360px]",
372
+ sections: (people) => [{ label: section, items: people, className: "px-3 py-1" }],
373
+ itemKey: (person) => person.id,
374
+ row: (person) => ({
375
+ label: person.name,
376
+ description: person.description,
377
+ leading: person.avatar ?? /* @__PURE__ */ jsx3(Avatar, { size: 32, alt: person.name }),
378
+ hint: /* @__PURE__ */ jsx3(EnterHint, {}),
379
+ size: "tall"
380
+ })
381
+ };
382
+ }
383
+ function optionsOf(editor, name) {
384
+ return editor.extensionManager.extensions.find((one) => one.name === name)?.options;
385
+ }
386
+ function personSuggestion(urgent, name) {
387
+ return {
388
+ ...urgent ? { char: "!@" } : {},
389
+ items: ({ query, editor }) => filterPeople(optionsOf(editor, name)?.people() ?? [], query),
390
+ render: suggestionPopup(peopleMenu(urgent)),
391
+ command: ({ editor, range, props: person }) => {
392
+ editor.chain().focus().insertContentAt(range, [
393
+ { type: name, attrs: { id: person.id, label: person.name, pubkey: person.pubkey ?? null } },
394
+ { type: "text", text: " " }
395
+ ]).run();
396
+ }
397
+ };
398
+ }
399
+ var HEX_KEY = /^[0-9a-f]{64}$/;
400
+ var NOSTR_URI = /^nostr:[a-z0-9]+$/i;
401
+ var fromData = (name, valid) => ({
402
+ parseHTML: (element) => {
403
+ const value = element.getAttribute(`data-${name}`);
404
+ return value !== null && (!valid || valid.test(value)) ? value : null;
405
+ },
406
+ // The node's own `renderHTML` writes it.
407
+ renderHTML: () => ({})
408
+ });
409
+ var personAttributes = () => ({
410
+ id: { default: null, ...fromData("id") },
411
+ label: { default: null, ...fromData("label") },
412
+ /**
413
+ * The person's Nostr key, when they have one — SPEC §13.1. `id` is the app's
414
+ * own and means nothing to another app; this is what the body is written
415
+ * with, so a mention survives a rename.
416
+ */
417
+ pubkey: { default: null, ...fromData("pubkey", HEX_KEY) }
418
+ });
419
+ function personData(attrs) {
420
+ return {
421
+ "data-id": String(attrs.id ?? ""),
422
+ "data-label": String(attrs.label ?? ""),
423
+ ...typeof attrs.pubkey === "string" && attrs.pubkey ? { "data-pubkey": attrs.pubkey } : {}
424
+ };
425
+ }
426
+ var PersonMention = Mention.extend({
427
+ name: "mention",
428
+ addOptions() {
429
+ return { ...this.parent(), HTMLAttributes: {}, people: () => [], suggestion: personSuggestion(false, this.name) };
430
+ },
431
+ addAttributes: personAttributes,
432
+ renderHTML({ node }) {
433
+ return ["span", { "data-mention": "true", ...personData(node.attrs), class: inlineChipClassName("person", "cursor-default") }, `@${node.attrs.label}`];
434
+ },
435
+ parseHTML() {
436
+ return [{ tag: "span[data-mention]" }];
437
+ }
438
+ });
439
+ var UrgentPersonMention = Mention.extend({
440
+ name: "urgentMention",
441
+ addOptions() {
442
+ return { ...this.parent(), HTMLAttributes: {}, people: () => [], suggestion: personSuggestion(true, this.name) };
443
+ },
444
+ addAttributes: personAttributes,
445
+ renderHTML({ node }) {
446
+ return [
447
+ "span",
448
+ { "data-urgent-mention": "true", ...personData(node.attrs), class: inlineChipClassName("urgent", "cursor-default") },
449
+ `@${node.attrs.label}`
450
+ ];
451
+ },
452
+ parseHTML() {
453
+ return [{ tag: "span[data-urgent-mention]" }];
454
+ }
455
+ });
456
+ function urgentPubkeys(editor) {
457
+ const urgent = [];
458
+ editor.state.doc.descendants((node) => {
459
+ if (node.type.name === "urgentMention" && typeof node.attrs.pubkey === "string" && node.attrs.pubkey) urgent.push(node.attrs.pubkey);
460
+ });
461
+ return urgent.length > 0 ? urgent : void 0;
462
+ }
463
+ var REFERENCE_LIMIT = 6;
464
+ function filterReferences(items, query) {
465
+ const q = query.toLowerCase();
466
+ const shown = q ? items.filter((item) => (item.search ?? item.snippet).toLowerCase().includes(q) || item.label.toLowerCase().includes(q)) : [...items];
467
+ return shown.slice(-REFERENCE_LIMIT);
468
+ }
469
+ var captionOf = (label, snippet) => snippet ? `${label}: ${snippet}` : label;
470
+ var CaptionedReference = Mention.extend({
471
+ name: "captionedReference",
472
+ group: "inline",
473
+ inline: true,
474
+ atom: true,
475
+ addOptions() {
476
+ return { ...this.parent(), HTMLAttributes: {}, icon: null, suggestion: { char: "\0", items: () => [] } };
477
+ },
478
+ addAttributes() {
479
+ return {
480
+ id: { default: null, ...fromData("id") },
481
+ label: { default: null, ...fromData("label") },
482
+ snippet: { default: "", parseHTML: (element) => element.getAttribute("data-snippet") ?? "", renderHTML: () => ({}) },
483
+ uri: { default: null, ...fromData("uri", NOSTR_URI) }
484
+ };
485
+ },
486
+ renderHTML({ node }) {
487
+ return [
488
+ "span",
489
+ { [`data-${this.name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}`]: "true", "data-id": String(node.attrs.id ?? ""), "data-label": String(node.attrs.label ?? ""), "data-snippet": String(node.attrs.snippet ?? ""), ...node.attrs.uri ? { "data-uri": String(node.attrs.uri) } : {}, class: inlineChipClassName("neutral", "cursor-default") },
490
+ captionOf(node.attrs.label, node.attrs.snippet)
491
+ ];
492
+ },
493
+ parseHTML() {
494
+ return [{ tag: `span[data-${this.name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}]` }];
495
+ },
496
+ addNodeView() {
497
+ const icon = this.options.icon;
498
+ return ReactNodeViewRenderer(
499
+ ({ node }) => /* @__PURE__ */ jsxs2(NodeViewWrapper, { as: "span", className: inlineChipClassName("neutral", "max-w-[24ch] cursor-default"), children: [
500
+ /* @__PURE__ */ jsx3("span", { className: "flex items-center justify-center w-4 h-4 shrink-0 text-text-secondary", children: icon }),
501
+ /* @__PURE__ */ jsx3("span", { className: "truncate", children: captionOf(node.attrs.label, node.attrs.snippet) })
502
+ ] }),
503
+ { as: "span" }
504
+ );
505
+ }
506
+ });
507
+ function referenceMenu({ ariaLabel, sectionLabel, icon }) {
508
+ return {
509
+ ariaLabel,
510
+ width: "w-[658px]",
511
+ maxHeight: "max-h-[360px]",
512
+ sections: (items) => [{ label: sectionLabel, items, className: "px-2" }],
513
+ itemKey: (item) => `reference-${item.id}`,
514
+ row: (item) => ({ leading: icon, label: captionOf(item.label, item.snippet), hint: /* @__PURE__ */ jsx3(EnterHint, {}) })
515
+ };
516
+ }
517
+ var ReferenceTrigger = Extension2.create({
518
+ name: "referenceTrigger",
519
+ addOptions() {
520
+ return { items: () => [], nodeName: "captionedReference", ariaLabel: "References", sectionLabel: "References", icon: null };
521
+ },
522
+ addProseMirrorPlugins() {
523
+ const options = this.options;
524
+ return [
525
+ Suggestion({
526
+ editor: this.editor,
527
+ char: "[",
528
+ pluginKey: new PluginKey2("referenceTrigger"),
529
+ // As a mention's: only where the chip may go.
530
+ allow: ({ state, range }) => {
531
+ const type = state.schema.nodes[options.nodeName];
532
+ return !!type && !!state.doc.resolve(range.from).parent.type.contentMatch.matchType(type);
533
+ },
534
+ items: ({ query }) => filterReferences(options.items(), query),
535
+ render: suggestionPopup(referenceMenu(options)),
536
+ command: ({ editor, range, props: item }) => {
537
+ editor.chain().focus().insertContentAt(range, [
538
+ { type: options.nodeName, attrs: { id: item.id, label: item.label, snippet: item.snippet, uri: item.uri } },
539
+ { type: "text", text: " " }
540
+ ]).run();
541
+ }
542
+ })
543
+ ];
544
+ }
545
+ });
546
+ var FORMATS = [
547
+ { id: "paragraph", label: "Text" },
548
+ { id: "heading", label: "Heading", trigger: "#" },
549
+ { id: "subheading", label: "Subheading", trigger: "##" },
550
+ { id: "quote", label: "Quote", trigger: ">" },
551
+ { id: "code", label: "Code", trigger: "`" },
552
+ { id: "bulletList", label: "Bulleted list", trigger: "-" },
553
+ { id: "orderedList", label: "Numbered list", trigger: "1." }
554
+ ];
555
+ function applyFormat(editor, id, code = "inline") {
556
+ const chain = editor.chain().focus();
557
+ const run = (command, ...args) => {
558
+ const named = chain[command];
559
+ return named ? named(...args).run() : false;
560
+ };
561
+ switch (id) {
562
+ case "paragraph":
563
+ return run("setParagraph");
564
+ case "heading":
565
+ return run("setHeading", { level: 1 });
566
+ case "subheading":
567
+ return run("setHeading", { level: 2 });
568
+ case "quote":
569
+ return run("toggleBlockquote");
570
+ case "bulletList":
571
+ return run("toggleBulletList");
572
+ case "orderedList":
573
+ return run("toggleOrderedList");
574
+ case "code":
575
+ return run(code === "block" ? "toggleCodeBlock" : "toggleCode");
576
+ default:
577
+ return false;
578
+ }
579
+ }
580
+ function formatSection(code = "inline") {
581
+ return {
582
+ label: "Format",
583
+ commands: FORMATS.map((format) => ({
584
+ key: `format-${format.id}`,
585
+ row: { label: format.label, shortcut: format.trigger },
586
+ keywords: [format.id],
587
+ run: (editor) => {
588
+ applyFormat(editor, format.id, code);
589
+ }
590
+ }))
591
+ };
592
+ }
593
+ function typeTrigger(input) {
594
+ return (editor) => {
595
+ requestAnimationFrame(() => editor.commands.insertContent(input));
596
+ };
597
+ }
598
+ function matches(command, q) {
599
+ return [command.row.label, ...command.keywords ?? []].some((text) => text.toLowerCase().includes(q));
600
+ }
601
+ function filterSlashSections(sections, query) {
602
+ const q = query.toLowerCase();
603
+ return sections.map((section) => ({ ...section, commands: q ? section.commands.filter((command) => matches(command, q)) : section.commands }));
604
+ }
605
+ var SlashCommands = Extension2.create({
606
+ name: "slashCommands",
607
+ addOptions() {
608
+ return { sections: [formatSection()] };
609
+ },
610
+ addProseMirrorPlugins() {
611
+ const sections = this.options.sections;
612
+ return [
613
+ Suggestion({
614
+ editor: this.editor,
615
+ char: "/",
616
+ startOfLine: false,
617
+ pluginKey: new PluginKey2("slashCommands"),
618
+ items: ({ query }) => filterSlashSections(sections, query).flatMap((section, at) => section.commands.map((command) => ({ ...command, section: at }))),
619
+ command: ({ editor, range, props }) => {
620
+ editor.chain().focus().deleteRange(range).run();
621
+ props.run(editor);
622
+ },
623
+ render: suggestionPopup({
624
+ ariaLabel: "Commands",
625
+ width: "w-[300px]",
626
+ maxHeight: "max-h-[400px]",
627
+ sections: (rows) => sections.map((section, at) => ({ label: section.label, items: rows.filter((row) => row.section === at) })),
628
+ itemKey: (row) => row.key,
629
+ row: (row) => row.row
630
+ })
631
+ })
632
+ ];
633
+ }
634
+ });
635
+
350
636
  // src/BlockNodes.tsx
351
- import { Extension as Extension2, Node as Node2 } from "@tiptap/core";
352
- import { Plugin as Plugin2, PluginKey as PluginKey2 } from "@tiptap/pm/state";
637
+ import { Extension as Extension3, Node as Node2 } from "@tiptap/core";
638
+ import { Plugin as Plugin2, PluginKey as PluginKey3 } from "@tiptap/pm/state";
353
639
  import { Mapping, ReplaceAroundStep } from "@tiptap/pm/transform";
354
- import { NodeViewWrapper, ReactNodeViewRenderer } from "@tiptap/react";
355
- import { jsx as jsx3 } from "react/jsx-runtime";
640
+ import { NodeViewWrapper as NodeViewWrapper2, ReactNodeViewRenderer as ReactNodeViewRenderer2 } from "@tiptap/react";
641
+ import { jsx as jsx4 } from "react/jsx-runtime";
356
642
  var BLOCK_TYPES = [
357
643
  "paragraph",
358
644
  "heading",
@@ -497,7 +783,7 @@ function bringsInBlocks(transactions) {
497
783
  })
498
784
  );
499
785
  }
500
- var BlockId = Extension2.create({
786
+ var BlockId = Extension3.create({
501
787
  name: "blockId",
502
788
  onCreate() {
503
789
  const { state, view } = this.editor;
@@ -510,7 +796,7 @@ var BlockId = Extension2.create({
510
796
  addProseMirrorPlugins() {
511
797
  return [
512
798
  new Plugin2({
513
- key: new PluginKey2("blockIdSplit"),
799
+ key: new PluginKey3("blockIdSplit"),
514
800
  appendTransaction: (transactions, old, state) => {
515
801
  if (!bringsInBlocks(transactions)) return null;
516
802
  const mapping = new Mapping();
@@ -569,7 +855,7 @@ var ReferenceNode = Node2.create({
569
855
  addNodeView() {
570
856
  const View = this.options.view;
571
857
  if (!View) return null;
572
- return ReactNodeViewRenderer(({ node }) => /* @__PURE__ */ jsx3(NodeViewWrapper, { as: "span", className: "inline", children: /* @__PURE__ */ jsx3(View, { uri: String(node.attrs.uri ?? "") }) }));
858
+ return ReactNodeViewRenderer2(({ node }) => /* @__PURE__ */ jsx4(NodeViewWrapper2, { as: "span", className: "inline", children: /* @__PURE__ */ jsx4(View, { uri: String(node.attrs.uri ?? "") }) }));
573
859
  }
574
860
  });
575
861
  var UnknownBlock = Node2.create({
@@ -591,14 +877,14 @@ var UnknownBlock = Node2.create({
591
877
  return ["div", { "data-unknown-block": String(node.attrs.blockId ?? "") }, String(node.attrs.text ?? "")];
592
878
  },
593
879
  addNodeView() {
594
- return ReactNodeViewRenderer(UnknownBlockView);
880
+ return ReactNodeViewRenderer2(UnknownBlockView);
595
881
  }
596
882
  });
597
883
  function UnknownBlockView({ node }) {
598
884
  const source = node.attrs.source;
599
885
  const text = String(node.attrs.text ?? "");
600
- return /* @__PURE__ */ jsx3(
601
- NodeViewWrapper,
886
+ return /* @__PURE__ */ jsx4(
887
+ NodeViewWrapper2,
602
888
  {
603
889
  "data-block-id": source?.id,
604
890
  "data-block-type": source?.type,
@@ -637,19 +923,34 @@ var AttachmentNode = Node2.create({
637
923
  addNodeView() {
638
924
  const View = this.options.view;
639
925
  if (!View) return null;
640
- return ReactNodeViewRenderer(({ node }) => /* @__PURE__ */ jsx3(NodeViewWrapper, { className: "my-2", children: /* @__PURE__ */ jsx3(View, { attrs: node.attrs }) }));
926
+ return ReactNodeViewRenderer2(({ node }) => /* @__PURE__ */ jsx4(NodeViewWrapper2, { className: "my-2", children: /* @__PURE__ */ jsx4(View, { attrs: node.attrs }) }));
641
927
  }
642
928
  });
643
929
  export {
644
930
  AttachmentNode,
645
931
  BlockId,
932
+ CaptionedReference,
933
+ FORMATS,
646
934
  KeptSelection,
935
+ PersonMention,
647
936
  ReferenceNode,
937
+ ReferenceTrigger,
648
938
  SelectionToolbar,
939
+ SlashCommands,
649
940
  UnknownBlock,
941
+ UrgentPersonMention,
942
+ applyFormat,
943
+ filterPeople,
944
+ filterReferences,
945
+ filterSlashSections,
946
+ formatSection,
650
947
  isSuggestionActive,
651
948
  isSuggestionOpen,
652
949
  normalizeHref,
653
- suggestionPopup
950
+ peopleMenu,
951
+ referenceMenu,
952
+ suggestionPopup,
953
+ typeTrigger,
954
+ urgentPubkeys
654
955
  };
655
956
  //# sourceMappingURL=editor.js.map