@estiva-app/ui 0.82.1 → 0.84.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.
- package/dist/BlockNodes.d.ts +16 -5
- package/dist/BlockNodes.d.ts.map +1 -1
- package/dist/CommentBox.d.ts +11 -2
- package/dist/CommentBox.d.ts.map +1 -1
- package/dist/ComposeBox.d.ts +17 -0
- package/dist/ComposeBox.d.ts.map +1 -1
- package/dist/DocumentEditor.d.ts +5 -4
- package/dist/DocumentEditor.d.ts.map +1 -1
- package/dist/LinkPlaces.d.ts +51 -0
- package/dist/LinkPlaces.d.ts.map +1 -0
- package/dist/ReferenceMenu.d.ts.map +1 -1
- package/dist/editor.d.ts +1 -0
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +392 -178
- package/dist/editor.js.map +4 -4
- package/dist/linked.examples.d.ts.map +1 -1
- package/dist/links.d.ts.map +1 -1
- package/package.json +1 -1
- package/registry.json +75 -12
- package/src/BlockNodes.tsx +36 -9
- package/src/CommentBox.mdx +11 -1
- package/src/CommentBox.stories.tsx +75 -2
- package/src/CommentBox.test.tsx +170 -3
- package/src/CommentBox.tsx +211 -53
- package/src/ComposeBox.tsx +19 -2
- package/src/DocumentEditor.mdx +7 -2
- package/src/DocumentEditor.stories.tsx +101 -15
- package/src/DocumentEditor.test.tsx +49 -0
- package/src/DocumentEditor.tsx +17 -10
- package/src/LinkPlaces.mdx +59 -0
- package/src/LinkPlaces.stories.tsx +60 -0
- package/src/LinkPlaces.test.ts +134 -0
- package/src/LinkPlaces.ts +169 -0
- package/src/ReferenceCards.mdx +4 -0
- package/src/ReferenceMenu.mdx +32 -24
- package/src/ReferenceMenu.stories.tsx +15 -16
- package/src/ReferenceMenu.test.tsx +161 -57
- package/src/ReferenceMenu.tsx +48 -44
- package/src/editor.ts +1 -0
- package/src/linked.examples.ts +4 -3
- package/src/links.ts +4 -1
- package/src/pages.test.ts +2 -2
- package/src/registry/registry.test.ts +6 -6
- package/stories/Choosing.mdx +3 -2
package/dist/editor.js
CHANGED
|
@@ -306,6 +306,7 @@ import { IconButton } from "@estiva-app/ui";
|
|
|
306
306
|
import { Toolbar as Toolbar2 } from "@estiva-app/ui";
|
|
307
307
|
import { cn } from "@estiva-app/ui";
|
|
308
308
|
import { richTextClassName } from "@estiva-app/ui";
|
|
309
|
+
import { ScrollArea } from "@estiva-app/ui";
|
|
309
310
|
|
|
310
311
|
// src/looks.ts
|
|
311
312
|
var FLOATING_SURFACE_CLASSES = "rounded-lg border border-border-default bg-bg-elevated shadow-lg";
|
|
@@ -426,6 +427,7 @@ function suggestionPopup(options) {
|
|
|
426
427
|
// src/ComposeBox.tsx
|
|
427
428
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
428
429
|
var COMPOSE_EDITOR_CLASSES = richTextClassName("default", "outline-none w-full bg-transparent min-h-[20px] [&>p+p]:-mt-1");
|
|
430
|
+
var COMPOSE_SCROLL_CLASSES = { area: "-mr-3", viewport: "max-h-[50vh]", content: "pr-3" };
|
|
429
431
|
var ComposeKeys = Extension2.create({
|
|
430
432
|
name: "composeKeys",
|
|
431
433
|
addStorage() {
|
|
@@ -493,8 +495,8 @@ function ComposeBox({ editor, onSend, placeholder, tools, attachments, ready = f
|
|
|
493
495
|
};
|
|
494
496
|
}, [editor]);
|
|
495
497
|
return /* @__PURE__ */ jsx3("div", { className: cn("relative", className), children: /* @__PURE__ */ jsxs2("div", { className: cn(WRITING_BOX_CLASSES, "focus-within:border-border-strong transition-colors"), children: [
|
|
496
|
-
/* @__PURE__ */ jsxs2("div", { "data-composer-editor": true, className: cn("relative min-h-[20px] transition-all", marked && "border-l-4 border-border-strong pl-2"), children: [
|
|
497
|
-
/* @__PURE__ */ jsx3(EditorContent, { editor }),
|
|
498
|
+
/* @__PURE__ */ jsxs2("div", { "data-composer-editor": true, "data-marked": marked || void 0, className: cn("relative min-h-[20px] transition-all", marked && "border-l-4 border-border-strong pl-2"), children: [
|
|
499
|
+
/* @__PURE__ */ jsx3(ScrollArea, { className: COMPOSE_SCROLL_CLASSES.area, viewportClassName: COMPOSE_SCROLL_CLASSES.viewport, contentClassName: COMPOSE_SCROLL_CLASSES.content, children: /* @__PURE__ */ jsx3(EditorContent, { editor }) }),
|
|
498
500
|
/* @__PURE__ */ jsx3(SelectionToolbar, { editor, ...selection }),
|
|
499
501
|
empty && /* @__PURE__ */ jsx3("div", { className: "pointer-events-none absolute inset-0 flex flex-wrap items-center gap-1 text-body-2 text-text-muted", children: placeholder })
|
|
500
502
|
] }),
|
|
@@ -528,34 +530,144 @@ function ComposeBox({ editor, onSend, placeholder, tools, attachments, ready = f
|
|
|
528
530
|
}
|
|
529
531
|
|
|
530
532
|
// src/CommentBox.tsx
|
|
531
|
-
import { Fragment as Fragment2, useCallback as useCallback4, useEffect as useEffect4, useRef as useRef3, useState as useState4 } from "react";
|
|
532
|
-
import { Extension as
|
|
533
|
-
import { EditorContent as EditorContent2
|
|
533
|
+
import { Fragment as Fragment2, useCallback as useCallback4, useEffect as useEffect4, useLayoutEffect, useRef as useRef3, useState as useState4 } from "react";
|
|
534
|
+
import { Extension as Extension11 } from "@tiptap/core";
|
|
535
|
+
import { Editor, EditorContent as EditorContent2 } from "@tiptap/react";
|
|
534
536
|
import { IconLock, IconPaperclip, IconSquareRounded } from "@tabler/icons-react";
|
|
535
537
|
import { AttachmentCard } from "@estiva-app/ui";
|
|
536
538
|
|
|
537
539
|
// src/BlockNodes.tsx
|
|
538
|
-
import { Extension as
|
|
540
|
+
import { Extension as Extension7, InputRule, Node as Node2 } from "@tiptap/core";
|
|
539
541
|
import { DOMSerializer } from "@tiptap/pm/model";
|
|
540
|
-
import { Plugin as
|
|
542
|
+
import { Plugin as Plugin6, PluginKey as PluginKey6 } from "@tiptap/pm/state";
|
|
541
543
|
import { Mapping, ReplaceAroundStep } from "@tiptap/pm/transform";
|
|
542
544
|
import { NodeViewWrapper, ReactNodeViewRenderer, ReactRenderer as ReactRenderer2 } from "@tiptap/react";
|
|
543
545
|
import { Checkbox } from "@estiva-app/ui";
|
|
544
546
|
import { calloutLook } from "@estiva-app/ui";
|
|
545
547
|
|
|
548
|
+
// src/LinkPlaces.ts
|
|
549
|
+
import { Extension as Extension3 } from "@tiptap/core";
|
|
550
|
+
import { Plugin as Plugin2, PluginKey as PluginKey2 } from "@tiptap/pm/state";
|
|
551
|
+
import { Decoration as Decoration2, DecorationSet as DecorationSet2 } from "@tiptap/pm/view";
|
|
552
|
+
var CONTAINERS = /* @__PURE__ */ new Set(["bulletList", "orderedList", "listItem"]);
|
|
553
|
+
var BECH32 = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
554
|
+
function bech32Words(text) {
|
|
555
|
+
const at = text.lastIndexOf("1");
|
|
556
|
+
if (at < 1 || text.length - at < 7) return null;
|
|
557
|
+
const words = [];
|
|
558
|
+
for (const char of text.slice(at + 1, -6)) {
|
|
559
|
+
const word = BECH32.indexOf(char);
|
|
560
|
+
if (word < 0) return null;
|
|
561
|
+
words.push(word);
|
|
562
|
+
}
|
|
563
|
+
return words;
|
|
564
|
+
}
|
|
565
|
+
function naddrKind(naddr) {
|
|
566
|
+
const words = bech32Words(naddr);
|
|
567
|
+
if (!words) return null;
|
|
568
|
+
const bytes = [];
|
|
569
|
+
let acc = 0;
|
|
570
|
+
let bits = 0;
|
|
571
|
+
for (const word of words) {
|
|
572
|
+
acc = acc << 5 | word;
|
|
573
|
+
bits += 5;
|
|
574
|
+
while (bits >= 8) {
|
|
575
|
+
bits -= 8;
|
|
576
|
+
bytes.push(acc >> bits & 255);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
for (let i = 0; i + 1 < bytes.length; ) {
|
|
580
|
+
const type = bytes[i];
|
|
581
|
+
const length = bytes[i + 1];
|
|
582
|
+
if (type === 3 && length === 4 && i + 6 <= bytes.length) return (bytes[i + 2] << 24 | bytes[i + 3] << 16 | bytes[i + 4] << 8 | bytes[i + 5]) >>> 0;
|
|
583
|
+
i += 2 + length;
|
|
584
|
+
}
|
|
585
|
+
return null;
|
|
586
|
+
}
|
|
587
|
+
var FOLDER = 39e3;
|
|
588
|
+
function staysChip(uri) {
|
|
589
|
+
const bare = uri.toLowerCase().replace(/^nostr:/, "");
|
|
590
|
+
if (bare.startsWith("npub1") || bare.startsWith("nprofile1")) return true;
|
|
591
|
+
return bare.startsWith("naddr1") && naddrKind(bare) === FOLDER;
|
|
592
|
+
}
|
|
593
|
+
function keepsLineRule(doc2, pos) {
|
|
594
|
+
const $pos = doc2.resolve(pos);
|
|
595
|
+
if ($pos.parent.type.name !== "paragraph" && $pos.parent.type.name !== "listItem") return false;
|
|
596
|
+
for (let depth = 1; depth < $pos.depth; depth++) if (!CONTAINERS.has($pos.node(depth).type.name)) return false;
|
|
597
|
+
return true;
|
|
598
|
+
}
|
|
599
|
+
function aloneOnLine(block, index) {
|
|
600
|
+
for (const step of [-1, 1]) {
|
|
601
|
+
for (let i = index + step; i >= 0 && i < block.childCount; i += step) {
|
|
602
|
+
const child = block.child(i);
|
|
603
|
+
if (child.type.name === "hardBreak") break;
|
|
604
|
+
if (!child.isText || (child.text ?? "").trim() !== "") return false;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
return true;
|
|
608
|
+
}
|
|
609
|
+
function linkPlaceAt(doc2, pos) {
|
|
610
|
+
const node = doc2.nodeAt(pos);
|
|
611
|
+
if (!node || node.type.name !== "reference") return "chip";
|
|
612
|
+
const uri = String(node.attrs.uri ?? "");
|
|
613
|
+
if (!uri || staysChip(uri)) return "chip";
|
|
614
|
+
if (Array.isArray(node.attrs.marks) && node.attrs.marks.length > 0) return "chip";
|
|
615
|
+
if (!keepsLineRule(doc2, pos)) return "chip";
|
|
616
|
+
const $pos = doc2.resolve(pos);
|
|
617
|
+
if (!aloneOnLine($pos.parent, $pos.index())) return "chip";
|
|
618
|
+
return node.attrs.embed === "detailed" ? "card" : "row";
|
|
619
|
+
}
|
|
620
|
+
function linkPlaces(doc2) {
|
|
621
|
+
const out = [];
|
|
622
|
+
doc2.descendants((node, pos) => {
|
|
623
|
+
if (node.type.name !== "reference") return true;
|
|
624
|
+
const place2 = linkPlaceAt(doc2, pos);
|
|
625
|
+
if (place2 !== "chip") out.push({ pos, size: node.nodeSize, place: place2 });
|
|
626
|
+
return false;
|
|
627
|
+
});
|
|
628
|
+
return out;
|
|
629
|
+
}
|
|
630
|
+
function placeOf(decorations) {
|
|
631
|
+
for (const decoration of decorations ?? []) {
|
|
632
|
+
const place2 = decoration.spec.linkPlace;
|
|
633
|
+
if (place2) return place2;
|
|
634
|
+
}
|
|
635
|
+
return "chip";
|
|
636
|
+
}
|
|
637
|
+
var key = new PluginKey2("linkPlaces");
|
|
638
|
+
var LinkPlaces = Extension3.create({
|
|
639
|
+
name: "linkPlaces",
|
|
640
|
+
addProseMirrorPlugins() {
|
|
641
|
+
const decorate = (doc2) => DecorationSet2.create(
|
|
642
|
+
doc2,
|
|
643
|
+
linkPlaces(doc2).map(({ pos, size, place: place2 }) => Decoration2.node(pos, pos + size, { "data-link-place": place2 }, { linkPlace: place2 }))
|
|
644
|
+
);
|
|
645
|
+
return [
|
|
646
|
+
new Plugin2({
|
|
647
|
+
key,
|
|
648
|
+
state: {
|
|
649
|
+
init: (_, state) => decorate(state.doc),
|
|
650
|
+
apply: (tr, set) => tr.docChanged ? decorate(tr.doc) : set
|
|
651
|
+
},
|
|
652
|
+
props: { decorations: (state) => key.getState(state) }
|
|
653
|
+
})
|
|
654
|
+
];
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
|
|
546
658
|
// src/ReferenceMenu.tsx
|
|
547
659
|
import { useCallback as useCallback3 } from "react";
|
|
548
|
-
import { Extension as
|
|
660
|
+
import { Extension as Extension6 } from "@tiptap/core";
|
|
549
661
|
import { useEditorState } from "@tiptap/react";
|
|
550
|
-
import { NodeSelection as NodeSelection2, Plugin as
|
|
662
|
+
import { NodeSelection as NodeSelection2, Plugin as Plugin5, PluginKey as PluginKey5, TextSelection } from "@tiptap/pm/state";
|
|
551
663
|
import { ReplaceStep } from "@tiptap/pm/transform";
|
|
552
|
-
import { IconCheck } from "@tabler/icons-react";
|
|
664
|
+
import { IconCheck, IconExternalLink } from "@tabler/icons-react";
|
|
553
665
|
|
|
554
666
|
// src/LinkChips.ts
|
|
555
|
-
import { Extension as
|
|
667
|
+
import { Extension as Extension4 } from "@tiptap/core";
|
|
556
668
|
import { closeHistory } from "@tiptap/pm/history";
|
|
557
|
-
import { Plugin as
|
|
558
|
-
var
|
|
669
|
+
import { Plugin as Plugin3, PluginKey as PluginKey3 } from "@tiptap/pm/state";
|
|
670
|
+
var key2 = new PluginKey3("linkChips");
|
|
559
671
|
var CHIPS_MADE = "linkChipsMade";
|
|
560
672
|
var PASTES_KEPT = 8;
|
|
561
673
|
var LINK_OR_URL = /(\[[^[\]\n]+\]\((?:https?:\/\/|mailto:)[^\s)]+\))|(https?:\/\/[^\s<>"'`]+)/g;
|
|
@@ -625,12 +737,12 @@ function apply(state, found) {
|
|
|
625
737
|
}
|
|
626
738
|
function refreshLinkChips(editor) {
|
|
627
739
|
if (editor.isDestroyed) return;
|
|
628
|
-
const chips =
|
|
740
|
+
const chips = key2.getState(editor.state);
|
|
629
741
|
if (!chips) return;
|
|
630
742
|
const tr = apply(editor.state, findLinkChips(editor.state.doc, editor.state.selection, chips.options.referenceOf, chips.pasted));
|
|
631
743
|
if (tr) editor.view.dispatch(tr);
|
|
632
744
|
}
|
|
633
|
-
var LinkChips =
|
|
745
|
+
var LinkChips = Extension4.create({
|
|
634
746
|
name: "linkChips",
|
|
635
747
|
addOptions() {
|
|
636
748
|
return { referenceOf: null, ask: null, limit: 24 };
|
|
@@ -639,8 +751,8 @@ var LinkChips = Extension3.create({
|
|
|
639
751
|
const options = this.options;
|
|
640
752
|
const editor = this.editor;
|
|
641
753
|
return [
|
|
642
|
-
new
|
|
643
|
-
key,
|
|
754
|
+
new Plugin3({
|
|
755
|
+
key: key2,
|
|
644
756
|
// The options, where `refreshLinkChips` can read them from the state alone, and where the last pastes landed.
|
|
645
757
|
state: {
|
|
646
758
|
init: () => ({ options, pasted: [] }),
|
|
@@ -656,13 +768,13 @@ var LinkChips = Extension3.create({
|
|
|
656
768
|
},
|
|
657
769
|
appendTransaction: (trs, _old, state) => {
|
|
658
770
|
if (!trs.some((tr) => tr.docChanged || tr.selectionSet)) return null;
|
|
659
|
-
return apply(state, findLinkChips(state.doc, state.selection, options.referenceOf,
|
|
771
|
+
return apply(state, findLinkChips(state.doc, state.selection, options.referenceOf, key2.getState(state)?.pasted));
|
|
660
772
|
},
|
|
661
773
|
view: (view) => {
|
|
662
774
|
const asked = /* @__PURE__ */ new Set();
|
|
663
775
|
const look = (state) => {
|
|
664
776
|
if (!options.ask) return;
|
|
665
|
-
const { open } = findLinkChips(state.doc, state.selection, options.referenceOf,
|
|
777
|
+
const { open } = findLinkChips(state.doc, state.selection, options.referenceOf, key2.getState(state)?.pasted);
|
|
666
778
|
const waiting = new Set(open);
|
|
667
779
|
for (const url of asked) if (!waiting.has(url)) asked.delete(url);
|
|
668
780
|
const fresh = open.filter((url) => !asked.has(url)).slice(0, Math.max(0, options.limit - asked.size));
|
|
@@ -703,9 +815,9 @@ import { MenuItem, MenuSection, MenuSeparator } from "@estiva-app/ui";
|
|
|
703
815
|
import { Popover as Popover2 } from "@estiva-app/ui";
|
|
704
816
|
|
|
705
817
|
// src/ReferenceCards.ts
|
|
706
|
-
import { Extension as
|
|
707
|
-
import { NodeSelection, Plugin as
|
|
708
|
-
import { Decoration as
|
|
818
|
+
import { Extension as Extension5 } from "@tiptap/core";
|
|
819
|
+
import { NodeSelection, Plugin as Plugin4, PluginKey as PluginKey4 } from "@tiptap/pm/state";
|
|
820
|
+
import { Decoration as Decoration3, DecorationSet as DecorationSet3 } from "@tiptap/pm/view";
|
|
709
821
|
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
710
822
|
function layoutOf(raw) {
|
|
711
823
|
if (typeof raw !== "string" || raw === "" || raw === "none") return void 0;
|
|
@@ -733,7 +845,7 @@ function referenceCardPlacements(doc2) {
|
|
|
733
845
|
});
|
|
734
846
|
return out;
|
|
735
847
|
}
|
|
736
|
-
var
|
|
848
|
+
var key3 = new PluginKey4("referenceCards");
|
|
737
849
|
function elementFor(storage, slotKey) {
|
|
738
850
|
let element = storage.elements.get(slotKey);
|
|
739
851
|
if (!element) {
|
|
@@ -747,17 +859,17 @@ function elementFor(storage, slotKey) {
|
|
|
747
859
|
function storageOf(editor) {
|
|
748
860
|
return editor.storage.referenceCards;
|
|
749
861
|
}
|
|
750
|
-
var ReferenceCards =
|
|
862
|
+
var ReferenceCards = Extension5.create({
|
|
751
863
|
name: "referenceCards",
|
|
752
864
|
addStorage() {
|
|
753
865
|
return { elements: /* @__PURE__ */ new Map() };
|
|
754
866
|
},
|
|
755
867
|
addProseMirrorPlugins() {
|
|
756
868
|
const storage = this.storage;
|
|
757
|
-
const decorate = (doc2) =>
|
|
869
|
+
const decorate = (doc2) => DecorationSet3.create(
|
|
758
870
|
doc2,
|
|
759
871
|
referenceCardPlacements(doc2).map(
|
|
760
|
-
(p) =>
|
|
872
|
+
(p) => Decoration3.widget(p.pos, () => elementFor(storage, p.key), {
|
|
761
873
|
key: p.key,
|
|
762
874
|
side: 1,
|
|
763
875
|
ignoreSelection: true,
|
|
@@ -767,13 +879,13 @@ var ReferenceCards = Extension4.create({
|
|
|
767
879
|
)
|
|
768
880
|
);
|
|
769
881
|
return [
|
|
770
|
-
new
|
|
771
|
-
key:
|
|
882
|
+
new Plugin4({
|
|
883
|
+
key: key3,
|
|
772
884
|
state: {
|
|
773
885
|
init: (_, state) => decorate(state.doc),
|
|
774
886
|
apply: (tr, set) => tr.docChanged ? decorate(tr.doc) : set
|
|
775
887
|
},
|
|
776
|
-
props: { decorations: (state) =>
|
|
888
|
+
props: { decorations: (state) => key3.getState(state) }
|
|
777
889
|
})
|
|
778
890
|
];
|
|
779
891
|
}
|
|
@@ -846,11 +958,10 @@ function setReferenceCardAt(editor, pos, layout) {
|
|
|
846
958
|
|
|
847
959
|
// src/ReferenceMenu.tsx
|
|
848
960
|
import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
849
|
-
var
|
|
850
|
-
var
|
|
851
|
-
{
|
|
852
|
-
{
|
|
853
|
-
{ layout: "detailed", label: "Detailed" }
|
|
961
|
+
var key4 = new PluginKey5("referenceMenu");
|
|
962
|
+
var SHOW_AS = [
|
|
963
|
+
{ as: "row", label: "Row" },
|
|
964
|
+
{ as: "card", label: "Card" }
|
|
854
965
|
];
|
|
855
966
|
function chipTarget(view, pos) {
|
|
856
967
|
const dom = view.nodeDOM(pos);
|
|
@@ -861,8 +972,9 @@ function webHref(view, pos) {
|
|
|
861
972
|
return typeof href === "string" && /^https?:\/\//i.test(href) ? href : "";
|
|
862
973
|
}
|
|
863
974
|
function rowsOf(view, pos) {
|
|
864
|
-
const
|
|
865
|
-
|
|
975
|
+
const drawn = !!view.state.doc.nodeAt(pos)?.attrs.uri && !!view.someProp("nodeViews", (views) => views?.reference);
|
|
976
|
+
const open = drawn || chipTarget(view, pos) || webHref(view, pos) ? ["open"] : [];
|
|
977
|
+
return linkPlaceAt(view.state.doc, pos) === "chip" ? open : [...open, ...SHOW_AS.map((show) => show.as)];
|
|
866
978
|
}
|
|
867
979
|
function chipAt(state, pos) {
|
|
868
980
|
const node = state.doc.nodeAt(pos);
|
|
@@ -887,10 +999,11 @@ function justPlaced(tr, state) {
|
|
|
887
999
|
const old = tr.mapping.invert().map(pos);
|
|
888
1000
|
const was = tr.before.nodeAt(old);
|
|
889
1001
|
if (was && was.type.name === "reference" && was.attrs.uri === before.attrs.uri && tr.mapping.map(old, 1) === pos) return null;
|
|
1002
|
+
if (linkPlaceAt(state.doc, pos) === "chip") return null;
|
|
890
1003
|
return pos;
|
|
891
1004
|
}
|
|
892
1005
|
function dispatchMenu(view, next) {
|
|
893
|
-
view.dispatch(view.state.tr.setMeta(
|
|
1006
|
+
view.dispatch(view.state.tr.setMeta(key4, next));
|
|
894
1007
|
}
|
|
895
1008
|
var passing = false;
|
|
896
1009
|
function openChip(view, pos) {
|
|
@@ -910,34 +1023,34 @@ function openChip(view, pos) {
|
|
|
910
1023
|
function choose(editor, pos, row) {
|
|
911
1024
|
dispatchMenu(editor.view, null);
|
|
912
1025
|
if (row === "open") openChip(editor.view, pos);
|
|
913
|
-
else if (row) setReferenceCardAt(editor, pos, row);
|
|
1026
|
+
else if (row) setReferenceCardAt(editor, pos, row === "card" ? "detailed" : "none");
|
|
914
1027
|
}
|
|
915
1028
|
function isReferenceMenuOpen(state) {
|
|
916
|
-
return !!
|
|
1029
|
+
return !!key4.getState(state);
|
|
917
1030
|
}
|
|
918
1031
|
function referenceMenuClick(editor, pos) {
|
|
919
|
-
if (passing || editor.isDestroyed || !editor.isEditable ||
|
|
1032
|
+
if (passing || editor.isDestroyed || !editor.isEditable || key4.getState(editor.state) === void 0) return false;
|
|
920
1033
|
if (!chipAt(editor.state, pos) || rowsOf(editor.view, pos).length === 0) return false;
|
|
921
|
-
editor.view.dispatch(caretAfter(editor.state, pos).setMeta(
|
|
1034
|
+
editor.view.dispatch(caretAfter(editor.state, pos).setMeta(key4, { pos, active: -1 }));
|
|
922
1035
|
return true;
|
|
923
1036
|
}
|
|
924
1037
|
function caretAfter(state, pos) {
|
|
925
1038
|
const node = state.doc.nodeAt(pos);
|
|
926
1039
|
return state.tr.setSelection(TextSelection.create(state.doc, pos + (node?.nodeSize ?? 1)));
|
|
927
1040
|
}
|
|
928
|
-
var ReferenceMenu =
|
|
1041
|
+
var ReferenceMenu = Extension6.create({
|
|
929
1042
|
name: "referenceMenu",
|
|
930
1043
|
// Before the editor's own keys, so Enter on a highlighted row is the row's, not a new line.
|
|
931
1044
|
priority: 1e3,
|
|
932
1045
|
addProseMirrorPlugins() {
|
|
933
1046
|
const editor = this.editor;
|
|
934
1047
|
return [
|
|
935
|
-
new
|
|
936
|
-
key:
|
|
1048
|
+
new Plugin5({
|
|
1049
|
+
key: key4,
|
|
937
1050
|
state: {
|
|
938
1051
|
init: () => null,
|
|
939
1052
|
apply: (tr, value, before, after) => {
|
|
940
|
-
const meta = tr.getMeta(
|
|
1053
|
+
const meta = tr.getMeta(key4);
|
|
941
1054
|
if (meta !== void 0) return meta;
|
|
942
1055
|
const placed = justPlaced(tr, after);
|
|
943
1056
|
if (placed !== null) return { pos: placed, active: -1 };
|
|
@@ -954,18 +1067,18 @@ var ReferenceMenu = Extension5.create({
|
|
|
954
1067
|
handleDOMEvents: {
|
|
955
1068
|
// Focus gone, the keys no longer reach the menu, and a card chosen now would miss the save on leaving (code review).
|
|
956
1069
|
blur: (view) => {
|
|
957
|
-
if (
|
|
1070
|
+
if (key4.getState(view.state)) dispatchMenu(view, null);
|
|
958
1071
|
return false;
|
|
959
1072
|
}
|
|
960
1073
|
},
|
|
961
1074
|
handleKeyDown: (view, event) => {
|
|
962
1075
|
if (event.shiftKey || event.ctrlKey || event.metaKey || event.altKey) return false;
|
|
963
|
-
const open =
|
|
1076
|
+
const open = key4.getState(view.state);
|
|
964
1077
|
if (!open) {
|
|
965
1078
|
const { selection } = view.state;
|
|
966
1079
|
if (event.key !== "Enter" || !view.editable || !(selection instanceof NodeSelection2) || selection.node.type.name !== "reference") return false;
|
|
967
1080
|
if (rowsOf(view, selection.from).length === 0) return false;
|
|
968
|
-
view.dispatch(caretAfter(view.state, selection.from).setMeta(
|
|
1081
|
+
view.dispatch(caretAfter(view.state, selection.from).setMeta(key4, { pos: selection.from, active: 0 }));
|
|
969
1082
|
return true;
|
|
970
1083
|
}
|
|
971
1084
|
const rows = rowsOf(view, open.pos);
|
|
@@ -998,13 +1111,10 @@ function ReferenceMenuView({ editor }) {
|
|
|
998
1111
|
editor,
|
|
999
1112
|
selector: ({ editor: ed }) => {
|
|
1000
1113
|
if (!ed || ed.isDestroyed) return null;
|
|
1001
|
-
const open =
|
|
1114
|
+
const open = key4.getState(ed.state);
|
|
1002
1115
|
if (!open) return null;
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
const embed = node.attrs.embed;
|
|
1006
|
-
const layout = embed === "detailed" ? "detailed" : typeof embed === "string" && embed !== "" && embed !== "none" ? "compact" : "none";
|
|
1007
|
-
return { pos: open.pos, active: open.active, named: !!node.attrs.uri, layout };
|
|
1116
|
+
if (!chipAt(ed.state, open.pos)) return null;
|
|
1117
|
+
return { pos: open.pos, active: open.active, shownAs: linkPlaceAt(ed.state.doc, open.pos) === "card" ? "card" : "row" };
|
|
1008
1118
|
}
|
|
1009
1119
|
});
|
|
1010
1120
|
const keepFocus2 = useCallback3((list) => {
|
|
@@ -1019,6 +1129,7 @@ function ReferenceMenuView({ editor }) {
|
|
|
1019
1129
|
const anchor = dom instanceof HTMLElement ? dom : null;
|
|
1020
1130
|
const rows = live && shown ? rowsOf(live.view, shown.pos) : [];
|
|
1021
1131
|
const opens = rows[0] === "open";
|
|
1132
|
+
const showAs = rows.includes("card");
|
|
1022
1133
|
const run = (row) => {
|
|
1023
1134
|
if (editor && shown) choose(editor, shown.pos, row);
|
|
1024
1135
|
};
|
|
@@ -1030,7 +1141,7 @@ function ReferenceMenuView({ editor }) {
|
|
|
1030
1141
|
anchor,
|
|
1031
1142
|
open: !!shown && !!anchor && rows.length > 0,
|
|
1032
1143
|
onOpenChange: (next) => {
|
|
1033
|
-
if (!next && editor && !editor.isDestroyed &&
|
|
1144
|
+
if (!next && editor && !editor.isDestroyed && key4.getState(editor.state)) dispatchMenu(editor.view, null);
|
|
1034
1145
|
},
|
|
1035
1146
|
side: "bottom",
|
|
1036
1147
|
align: "left",
|
|
@@ -1043,6 +1154,7 @@ function ReferenceMenuView({ editor }) {
|
|
|
1043
1154
|
role: "menuitem",
|
|
1044
1155
|
tabIndex: -1,
|
|
1045
1156
|
label: "Open",
|
|
1157
|
+
leading: /* @__PURE__ */ jsx4(IconExternalLink, { size: 16 }),
|
|
1046
1158
|
selected: shown.active === 0,
|
|
1047
1159
|
onMouseDown: (event) => {
|
|
1048
1160
|
event.preventDefault();
|
|
@@ -1050,23 +1162,23 @@ function ReferenceMenuView({ editor }) {
|
|
|
1050
1162
|
}
|
|
1051
1163
|
}
|
|
1052
1164
|
),
|
|
1053
|
-
|
|
1165
|
+
showAs && /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
1054
1166
|
opens && /* @__PURE__ */ jsx4(MenuSeparator, {}),
|
|
1055
|
-
/* @__PURE__ */ jsx4("div", { role: "group", "aria-label": "
|
|
1167
|
+
/* @__PURE__ */ jsx4("div", { role: "group", "aria-label": "Show as", children: /* @__PURE__ */ jsx4(MenuSection, { label: "Show as", children: SHOW_AS.map(({ as, label }, i) => /* @__PURE__ */ jsx4(
|
|
1056
1168
|
MenuItem,
|
|
1057
1169
|
{
|
|
1058
1170
|
role: "menuitemradio",
|
|
1059
|
-
"aria-checked": shown.
|
|
1171
|
+
"aria-checked": shown.shownAs === as,
|
|
1060
1172
|
tabIndex: -1,
|
|
1061
1173
|
label,
|
|
1062
1174
|
selected: shown.active === i + (opens ? 1 : 0),
|
|
1063
|
-
trailing: shown.
|
|
1175
|
+
trailing: shown.shownAs === as ? /* @__PURE__ */ jsx4(IconCheck, { size: 16, "aria-hidden": true }) : void 0,
|
|
1064
1176
|
onMouseDown: (event) => {
|
|
1065
1177
|
event.preventDefault();
|
|
1066
|
-
run(
|
|
1178
|
+
run(as);
|
|
1067
1179
|
}
|
|
1068
1180
|
},
|
|
1069
|
-
|
|
1181
|
+
as
|
|
1070
1182
|
)) }) })
|
|
1071
1183
|
] })
|
|
1072
1184
|
] })
|
|
@@ -1234,7 +1346,7 @@ function bringsInBlocks(transactions) {
|
|
|
1234
1346
|
})
|
|
1235
1347
|
);
|
|
1236
1348
|
}
|
|
1237
|
-
var BlockId =
|
|
1349
|
+
var BlockId = Extension7.create({
|
|
1238
1350
|
name: "blockId",
|
|
1239
1351
|
onCreate() {
|
|
1240
1352
|
const { state, view } = this.editor;
|
|
@@ -1246,8 +1358,8 @@ var BlockId = Extension6.create({
|
|
|
1246
1358
|
},
|
|
1247
1359
|
addProseMirrorPlugins() {
|
|
1248
1360
|
return [
|
|
1249
|
-
new
|
|
1250
|
-
key: new
|
|
1361
|
+
new Plugin6({
|
|
1362
|
+
key: new PluginKey6("blockIdSplit"),
|
|
1251
1363
|
appendTransaction: (transactions, old, state) => {
|
|
1252
1364
|
if (!bringsInBlocks(transactions)) return null;
|
|
1253
1365
|
const mapping = new Mapping();
|
|
@@ -1319,23 +1431,34 @@ var ReferenceNode = Node2.create({
|
|
|
1319
1431
|
addNodeView() {
|
|
1320
1432
|
const View = this.options.view;
|
|
1321
1433
|
if (!View) return null;
|
|
1322
|
-
return ReactNodeViewRenderer(({ node, editor, getPos }) => {
|
|
1434
|
+
return ReactNodeViewRenderer(({ node, editor, getPos, decorations }) => {
|
|
1323
1435
|
const uri = String(node.attrs.uri ?? "");
|
|
1324
1436
|
const href = typeof node.attrs.href === "string" && node.attrs.href ? node.attrs.href : void 0;
|
|
1437
|
+
const place2 = placeOf(decorations);
|
|
1325
1438
|
return /* @__PURE__ */ jsx5(
|
|
1326
1439
|
NodeViewWrapper,
|
|
1327
1440
|
{
|
|
1328
1441
|
as: "span",
|
|
1329
|
-
className: "inline",
|
|
1442
|
+
className: place2 === "chip" ? "inline" : "block w-full",
|
|
1330
1443
|
onClickCapture: (event) => {
|
|
1331
1444
|
const pos = getPos();
|
|
1332
|
-
if (typeof pos !== "number"
|
|
1445
|
+
if (typeof pos !== "number") return;
|
|
1446
|
+
const own = editor.view.nodeDOM(pos);
|
|
1447
|
+
if (!(event.target instanceof Element) || !own || !own.contains(event.target)) return;
|
|
1448
|
+
if (place2 === "card" && event.target.closest('button, input, select, [role="combobox"]')) return;
|
|
1449
|
+
if (!referenceMenuClick(editor, pos)) return;
|
|
1333
1450
|
event.preventDefault();
|
|
1334
1451
|
event.stopPropagation();
|
|
1335
1452
|
},
|
|
1336
|
-
children: uri ? /* @__PURE__ */ jsx5(View, { uri, ...href ? { href } : {} }) : /* @__PURE__ */ jsx5("span", { children: href })
|
|
1453
|
+
children: uri ? /* @__PURE__ */ jsx5(View, { uri, ...href ? { href } : {}, place: place2, editing: editor.isEditable }) : /* @__PURE__ */ jsx5("span", { children: href })
|
|
1337
1454
|
}
|
|
1338
1455
|
);
|
|
1456
|
+
}, {
|
|
1457
|
+
// Words typed beside a link leave its node as it was, and Tiptap then skips the redraw; its place has changed (code review).
|
|
1458
|
+
update: ({ oldNode, newNode, oldDecorations, newDecorations, updateProps }) => {
|
|
1459
|
+
if (oldNode !== newNode || placeOf(oldDecorations) !== placeOf(newDecorations)) updateProps();
|
|
1460
|
+
return true;
|
|
1461
|
+
}
|
|
1339
1462
|
});
|
|
1340
1463
|
}
|
|
1341
1464
|
});
|
|
@@ -1422,7 +1545,7 @@ function itemAtCaret(state) {
|
|
|
1422
1545
|
if (item.type.name !== "listItem" || $from.index(-1) !== 0) return null;
|
|
1423
1546
|
return { node: item, pos: $from.before(-1) };
|
|
1424
1547
|
}
|
|
1425
|
-
var sameAttrs = (a, b) => Object.keys({ ...a.attrs, ...b.attrs }).every((
|
|
1548
|
+
var sameAttrs = (a, b) => Object.keys({ ...a.attrs, ...b.attrs }).every((key5) => a.attrs[key5] === b.attrs[key5]);
|
|
1426
1549
|
function listItemView(editor, node, view, getPos) {
|
|
1427
1550
|
const toDOM = node.type.spec.toDOM;
|
|
1428
1551
|
const { dom, contentDOM } = toDOM ? DOMSerializer.renderSpec(document, toDOM(node)) : { dom: document.createElement("li"), contentDOM: void 0 };
|
|
@@ -1473,7 +1596,7 @@ function listItemView(editor, node, view, getPos) {
|
|
|
1473
1596
|
}
|
|
1474
1597
|
};
|
|
1475
1598
|
}
|
|
1476
|
-
var Checklist =
|
|
1599
|
+
var Checklist = Extension7.create({
|
|
1477
1600
|
name: "checklist",
|
|
1478
1601
|
// Before the list item's own Enter and Backspace.
|
|
1479
1602
|
priority: 101,
|
|
@@ -1538,14 +1661,14 @@ var Checklist = Extension6.create({
|
|
|
1538
1661
|
addProseMirrorPlugins() {
|
|
1539
1662
|
const editor = this.editor;
|
|
1540
1663
|
return [
|
|
1541
|
-
new
|
|
1542
|
-
key: new
|
|
1664
|
+
new Plugin6({
|
|
1665
|
+
key: new PluginKey6("checklist"),
|
|
1543
1666
|
props: { nodeViews: { listItem: (node, view, getPos) => listItemView(editor, node, view, getPos) } }
|
|
1544
1667
|
})
|
|
1545
1668
|
];
|
|
1546
1669
|
}
|
|
1547
1670
|
});
|
|
1548
|
-
var Callout =
|
|
1671
|
+
var Callout = Extension7.create({
|
|
1549
1672
|
name: "callout",
|
|
1550
1673
|
addGlobalAttributes() {
|
|
1551
1674
|
return [
|
|
@@ -1571,8 +1694,8 @@ import { CardUnder } from "@estiva-app/ui";
|
|
|
1571
1694
|
import { cn as cn2 } from "@estiva-app/ui";
|
|
1572
1695
|
|
|
1573
1696
|
// src/ComposerTriggers.tsx
|
|
1574
|
-
import { Extension as
|
|
1575
|
-
import { PluginKey as
|
|
1697
|
+
import { Extension as Extension8 } from "@tiptap/core";
|
|
1698
|
+
import { PluginKey as PluginKey7 } from "@tiptap/pm/state";
|
|
1576
1699
|
import Mention from "@tiptap/extension-mention";
|
|
1577
1700
|
import Suggestion from "@tiptap/suggestion";
|
|
1578
1701
|
import { NodeViewWrapper as NodeViewWrapper2, ReactNodeViewRenderer as ReactNodeViewRenderer2 } from "@tiptap/react";
|
|
@@ -1690,7 +1813,7 @@ function urgentPubkeys(editor) {
|
|
|
1690
1813
|
});
|
|
1691
1814
|
return urgent.length > 0 ? urgent : void 0;
|
|
1692
1815
|
}
|
|
1693
|
-
var PersonReference =
|
|
1816
|
+
var PersonReference = Extension8.create({
|
|
1694
1817
|
name: "personReference",
|
|
1695
1818
|
addOptions() {
|
|
1696
1819
|
return { people: () => [], uriOf: () => null, nodeName: "reference" };
|
|
@@ -1701,7 +1824,7 @@ var PersonReference = Extension7.create({
|
|
|
1701
1824
|
Suggestion({
|
|
1702
1825
|
editor: this.editor,
|
|
1703
1826
|
char: "@",
|
|
1704
|
-
pluginKey: new
|
|
1827
|
+
pluginKey: new PluginKey7("personReference"),
|
|
1705
1828
|
...listening("@"),
|
|
1706
1829
|
// As `[`'s: only where the chip may go.
|
|
1707
1830
|
allow: ({ state, range }) => {
|
|
@@ -1798,7 +1921,7 @@ function referenceMenu({ ariaLabel, sectionLabel, icon, iconFor }) {
|
|
|
1798
1921
|
};
|
|
1799
1922
|
}
|
|
1800
1923
|
var listed = (options, query) => options.sections ? options.sections(query).flatMap((section) => section.items.map((item) => ({ ...item, section: section.label }))) : filterReferences(options.items(), query);
|
|
1801
|
-
var ReferenceTrigger =
|
|
1924
|
+
var ReferenceTrigger = Extension8.create({
|
|
1802
1925
|
name: "referenceTrigger",
|
|
1803
1926
|
addOptions() {
|
|
1804
1927
|
return { items: () => [], nodeName: "captionedReference", ariaLabel: "References", sectionLabel: "References", icon: null };
|
|
@@ -1809,7 +1932,7 @@ var ReferenceTrigger = Extension7.create({
|
|
|
1809
1932
|
Suggestion({
|
|
1810
1933
|
editor: this.editor,
|
|
1811
1934
|
char: "[",
|
|
1812
|
-
pluginKey: new
|
|
1935
|
+
pluginKey: new PluginKey7("referenceTrigger"),
|
|
1813
1936
|
...listening("]"),
|
|
1814
1937
|
// As a mention's: only where the chip may go.
|
|
1815
1938
|
allow: ({ state, range }) => {
|
|
@@ -1914,7 +2037,7 @@ function filterSlashSections(sections, query) {
|
|
|
1914
2037
|
const q = query.toLowerCase();
|
|
1915
2038
|
return sections.map((section) => ({ ...section, commands: q ? section.commands.filter((command) => matches(command, q)) : section.commands }));
|
|
1916
2039
|
}
|
|
1917
|
-
var SlashCommands =
|
|
2040
|
+
var SlashCommands = Extension8.create({
|
|
1918
2041
|
name: "slashCommands",
|
|
1919
2042
|
addOptions() {
|
|
1920
2043
|
return { sections: [formatSection()] };
|
|
@@ -1926,7 +2049,7 @@ var SlashCommands = Extension7.create({
|
|
|
1926
2049
|
editor: this.editor,
|
|
1927
2050
|
char: "/",
|
|
1928
2051
|
startOfLine: false,
|
|
1929
|
-
pluginKey: new
|
|
2052
|
+
pluginKey: new PluginKey7("slashCommands"),
|
|
1930
2053
|
items: ({ query, editor }) => filterSlashSections(sections, query).flatMap(
|
|
1931
2054
|
(section, at) => section.commands.filter((command) => offers(editor, command)).map((command) => ({ ...command, section: at }))
|
|
1932
2055
|
),
|
|
@@ -1953,18 +2076,18 @@ import { FilePicker } from "@estiva-app/ui";
|
|
|
1953
2076
|
import { Kbd } from "@estiva-app/ui";
|
|
1954
2077
|
|
|
1955
2078
|
// src/links.ts
|
|
1956
|
-
import { Extension as
|
|
1957
|
-
import { Plugin as
|
|
1958
|
-
import { Decoration as
|
|
2079
|
+
import { Extension as Extension9 } from "@tiptap/core";
|
|
2080
|
+
import { Plugin as Plugin7, PluginKey as PluginKey8, TextSelection as TextSelection2 } from "@tiptap/pm/state";
|
|
2081
|
+
import { Decoration as Decoration4, DecorationSet as DecorationSet4 } from "@tiptap/pm/view";
|
|
1959
2082
|
import StarterKit from "@tiptap/starter-kit";
|
|
1960
2083
|
var LINK_ON_WORDS_TARGET = /^https?:\/\/[^\s)]+$/;
|
|
1961
|
-
var PasteOverWords =
|
|
2084
|
+
var PasteOverWords = Extension9.create({
|
|
1962
2085
|
name: "commentBoxPasteOverWords",
|
|
1963
2086
|
priority: 1001,
|
|
1964
2087
|
addProseMirrorPlugins() {
|
|
1965
2088
|
return [
|
|
1966
|
-
new
|
|
1967
|
-
key: new
|
|
2089
|
+
new Plugin7({
|
|
2090
|
+
key: new PluginKey8("commentBoxPasteOverWords"),
|
|
1968
2091
|
props: {
|
|
1969
2092
|
handlePaste: (view, event) => {
|
|
1970
2093
|
const url = (event.clipboardData?.getData("text/plain").trim() ?? "").replace(/[.,;:!?]+$/, "");
|
|
@@ -1979,7 +2102,8 @@ var PasteOverWords = Extension8.create({
|
|
|
1979
2102
|
return false;
|
|
1980
2103
|
});
|
|
1981
2104
|
if (plain && LINK_ON_WORDS_TARGET.test(url) && !/[[\]\n]/.test(state.doc.textBetween(from, to))) {
|
|
1982
|
-
|
|
2105
|
+
const tr2 = state.tr.addMark(from, to, schema.marks.link.create({ href: url }));
|
|
2106
|
+
view.dispatch(tr2.setSelection(TextSelection2.create(tr2.doc, to)).removeStoredMark(schema.marks.link));
|
|
1983
2107
|
return true;
|
|
1984
2108
|
}
|
|
1985
2109
|
const before = state.doc.textBetween(Math.max(to - 1, $to.start()), to, "", "\uFFFC");
|
|
@@ -2016,12 +2140,12 @@ var LINK_CLASS = "text-info-default underline underline-offset-2 cursor-pointer"
|
|
|
2016
2140
|
var OPENABLE = /^(https?:\/\/|mailto:)/i;
|
|
2017
2141
|
var LINK_MARK_ATTRIBUTES = { class: LINK_CLASS, "data-link-mark": "", target: "_blank", rel: "noopener noreferrer nofollow" };
|
|
2018
2142
|
var LINK_TARGET = /\]\(([^\s)]+)\)$/;
|
|
2019
|
-
var BareLinks =
|
|
2143
|
+
var BareLinks = Extension9.create({
|
|
2020
2144
|
name: "bareLinks",
|
|
2021
2145
|
addProseMirrorPlugins() {
|
|
2022
2146
|
return [
|
|
2023
|
-
new
|
|
2024
|
-
key: new
|
|
2147
|
+
new Plugin7({
|
|
2148
|
+
key: new PluginKey8("bareLinks"),
|
|
2025
2149
|
props: {
|
|
2026
2150
|
// The one way a click opens an address: a bare one's decoration, or, while editing, a link on words (read only,
|
|
2027
2151
|
// the link is a plain anchor and opens itself). Only its own attributes are read — never a chip's — and only an
|
|
@@ -2045,10 +2169,10 @@ var BareLinks = Extension8.create({
|
|
|
2045
2169
|
if (match.index === void 0) continue;
|
|
2046
2170
|
const text = match[0].startsWith("[") ? match[0] : match[0].replace(TRAILING2, "");
|
|
2047
2171
|
const href = text.startsWith("[") ? LINK_TARGET.exec(text)?.[1] ?? "" : text;
|
|
2048
|
-
found.push(
|
|
2172
|
+
found.push(Decoration4.inline(pos + match.index, pos + match.index + text.length, { class: LINK_CLASS, ...href ? { "data-bare-link": href } : {} }));
|
|
2049
2173
|
}
|
|
2050
2174
|
});
|
|
2051
|
-
return found.length ?
|
|
2175
|
+
return found.length ? DecorationSet4.create(doc2, found) : null;
|
|
2052
2176
|
}
|
|
2053
2177
|
}
|
|
2054
2178
|
})
|
|
@@ -2057,8 +2181,8 @@ var BareLinks = Extension8.create({
|
|
|
2057
2181
|
});
|
|
2058
2182
|
|
|
2059
2183
|
// src/PastedImages.ts
|
|
2060
|
-
import { Extension as
|
|
2061
|
-
import { Plugin as
|
|
2184
|
+
import { Extension as Extension10 } from "@tiptap/core";
|
|
2185
|
+
import { Plugin as Plugin8, PluginKey as PluginKey9 } from "@tiptap/pm/state";
|
|
2062
2186
|
var IMAGE_EXTENSIONS = {
|
|
2063
2187
|
"image/png": "png",
|
|
2064
2188
|
"image/jpeg": "jpg",
|
|
@@ -2093,7 +2217,7 @@ function pastedImages(source, at = /* @__PURE__ */ new Date()) {
|
|
|
2093
2217
|
(file) => hasUsableName(file.name) ? file : new File([file], pastedImageName(file.type, at, generated++), { type: file.type, lastModified: file.lastModified })
|
|
2094
2218
|
);
|
|
2095
2219
|
}
|
|
2096
|
-
var PastedImages =
|
|
2220
|
+
var PastedImages = Extension10.create({
|
|
2097
2221
|
name: "pastedImages",
|
|
2098
2222
|
addOptions() {
|
|
2099
2223
|
return { onImages: () => false };
|
|
@@ -2101,8 +2225,8 @@ var PastedImages = Extension9.create({
|
|
|
2101
2225
|
addProseMirrorPlugins() {
|
|
2102
2226
|
const options = this.options;
|
|
2103
2227
|
return [
|
|
2104
|
-
new
|
|
2105
|
-
key: new
|
|
2228
|
+
new Plugin8({
|
|
2229
|
+
key: new PluginKey9("pastedImages"),
|
|
2106
2230
|
props: {
|
|
2107
2231
|
handlePaste: (_view, event) => {
|
|
2108
2232
|
const files = pastedImages(event.clipboardData);
|
|
@@ -2115,6 +2239,7 @@ var PastedImages = Extension9.create({
|
|
|
2115
2239
|
});
|
|
2116
2240
|
|
|
2117
2241
|
// src/CommentBox.tsx
|
|
2242
|
+
import { ScrollArea as ScrollArea2 } from "@estiva-app/ui";
|
|
2118
2243
|
import { ToolbarButton as ToolbarButton2 } from "@estiva-app/ui";
|
|
2119
2244
|
import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
2120
2245
|
var ATTACH_EVENT = "commentbox:attach";
|
|
@@ -2125,7 +2250,7 @@ var commentBoxRows = {
|
|
|
2125
2250
|
urgent: { key: "insert-urgent", row: { label: "Urgent", shortcut: "!@" }, keywords: ["!@", "Urgent mention"], run: typeTrigger("!@") },
|
|
2126
2251
|
reference: { key: "insert-reference", row: { label: "Reference", shortcut: "[" }, keywords: ["[", "Reference"], run: typeTrigger("[") }
|
|
2127
2252
|
};
|
|
2128
|
-
var BoxKeys =
|
|
2253
|
+
var BoxKeys = Extension11.create({
|
|
2129
2254
|
name: "commentBoxKeys",
|
|
2130
2255
|
addOptions() {
|
|
2131
2256
|
return { onEscape: () => false };
|
|
@@ -2141,6 +2266,105 @@ var BoxKeys = Extension10.create({
|
|
|
2141
2266
|
var stillNamed = (removed, names) => [...removed].every((value) => names.includes(value)) ? removed : new Set([...removed].filter((value) => names.includes(value)));
|
|
2142
2267
|
var SQUARE = /* @__PURE__ */ jsx7(IconSquareRounded, { size: 16, stroke: 1.5, className: "text-text-secondary" });
|
|
2143
2268
|
var SMALL_SQUARE = /* @__PURE__ */ jsx7(IconSquareRounded, { size: 14, stroke: 1.5 });
|
|
2269
|
+
var NO_EXTENSIONS = [];
|
|
2270
|
+
var sameApp = (a, b) => a.referenceView === b.referenceView && a.extensions.length === b.extensions.length && a.extensions.every((one, i) => one === b.extensions[i]);
|
|
2271
|
+
function boxExtensions(hold, app) {
|
|
2272
|
+
const iconFor = (uri) => hold.current.referenceIcon?.(uri);
|
|
2273
|
+
return [
|
|
2274
|
+
BoxKit.configure({ link: { openOnClick: false } }),
|
|
2275
|
+
PasteOverWords,
|
|
2276
|
+
KeptSelection,
|
|
2277
|
+
ComposeKeys,
|
|
2278
|
+
BoxKeys.configure({
|
|
2279
|
+
onEscape: () => {
|
|
2280
|
+
const editing = hold.current.edit;
|
|
2281
|
+
if (!editing) return false;
|
|
2282
|
+
editing.onCancel();
|
|
2283
|
+
return true;
|
|
2284
|
+
}
|
|
2285
|
+
}),
|
|
2286
|
+
PersonMention.configure({ people: () => hold.current.people }),
|
|
2287
|
+
// An edit makes nobody urgent (CON-24): `!@` opens no list there, as `/` offers no Urgent.
|
|
2288
|
+
UrgentPersonMention.extend({
|
|
2289
|
+
addOptions() {
|
|
2290
|
+
const parent = this.parent();
|
|
2291
|
+
return { ...parent, suggestion: { ...parent.suggestion, allow: () => !hold.current.edit } };
|
|
2292
|
+
}
|
|
2293
|
+
}).configure({ people: () => hold.current.people }),
|
|
2294
|
+
CaptionedReference.configure({ icon: SMALL_SQUARE, iconFor }),
|
|
2295
|
+
ReferenceTrigger.configure({
|
|
2296
|
+
items: () => [],
|
|
2297
|
+
sections: (query) => hold.current.references?.(query) ?? [],
|
|
2298
|
+
subscribe: (listener) => hold.current.referencesChanged?.(listener) ?? (() => {
|
|
2299
|
+
}),
|
|
2300
|
+
ariaLabel: "References",
|
|
2301
|
+
sectionLabel: "References",
|
|
2302
|
+
icon: SQUARE,
|
|
2303
|
+
iconFor
|
|
2304
|
+
}),
|
|
2305
|
+
SlashCommands.configure({ sections: hold.sections }),
|
|
2306
|
+
ReferenceNode.configure({ view: app.referenceView }),
|
|
2307
|
+
PastedImages.configure({ onImages: (files) => hold.current.attach(files) }),
|
|
2308
|
+
...app.extensions
|
|
2309
|
+
];
|
|
2310
|
+
}
|
|
2311
|
+
function buildBox(app, options) {
|
|
2312
|
+
const hold = { current: { people: [], attach: () => false }, sections: [] };
|
|
2313
|
+
return { editor: new Editor({ ...options, extensions: boxExtensions(hold, app) }), hold };
|
|
2314
|
+
}
|
|
2315
|
+
var warmApp = null;
|
|
2316
|
+
var spare = null;
|
|
2317
|
+
var sparing = false;
|
|
2318
|
+
function scheduleSpare() {
|
|
2319
|
+
if (!warmApp || spare || sparing || typeof window === "undefined" || !window.requestIdleCallback) return;
|
|
2320
|
+
sparing = true;
|
|
2321
|
+
window.requestIdleCallback(() => {
|
|
2322
|
+
sparing = false;
|
|
2323
|
+
if (warmApp && !spare) spare = buildBox(warmApp, { autofocus: false });
|
|
2324
|
+
});
|
|
2325
|
+
}
|
|
2326
|
+
function useBoxEditor(app, content, options) {
|
|
2327
|
+
const args = useRef3({ app, content, options });
|
|
2328
|
+
args.current = { app, content, options };
|
|
2329
|
+
const [held, setHeld] = useState4(() => {
|
|
2330
|
+
const fits = !content && spare && !spare.editor.isDestroyed && warmApp && sameApp(warmApp, app);
|
|
2331
|
+
const taken = fits ? spare : null;
|
|
2332
|
+
if (taken) {
|
|
2333
|
+
spare = null;
|
|
2334
|
+
taken.editor.setOptions(options);
|
|
2335
|
+
}
|
|
2336
|
+
const one = taken ?? buildBox(app, { ...options, content });
|
|
2337
|
+
one.destroyAt = setTimeout(() => one.editor.destroy(), 1e4);
|
|
2338
|
+
scheduleSpare();
|
|
2339
|
+
return one;
|
|
2340
|
+
});
|
|
2341
|
+
useLayoutEffect(() => {
|
|
2342
|
+
clearTimeout(held.destroyAt);
|
|
2343
|
+
if (held.editor.isDestroyed) {
|
|
2344
|
+
const { app: now, content: opening, options: current } = args.current;
|
|
2345
|
+
setHeld(buildBox(now, { ...current, content: opening }));
|
|
2346
|
+
return;
|
|
2347
|
+
}
|
|
2348
|
+
return () => {
|
|
2349
|
+
held.destroyAt = setTimeout(() => held.editor.destroy(), 1);
|
|
2350
|
+
};
|
|
2351
|
+
}, [held]);
|
|
2352
|
+
const props = useRef3(options.editorProps);
|
|
2353
|
+
props.current = options.editorProps;
|
|
2354
|
+
const attributes = JSON.stringify(options.editorProps.attributes ?? {});
|
|
2355
|
+
useEffect4(() => {
|
|
2356
|
+
if (!held.editor.isDestroyed) held.editor.setOptions({ editorProps: props.current });
|
|
2357
|
+
}, [held, attributes]);
|
|
2358
|
+
return held;
|
|
2359
|
+
}
|
|
2360
|
+
var holdsUrgent = (editor) => {
|
|
2361
|
+
let found = false;
|
|
2362
|
+
editor.state.doc.descendants((node) => {
|
|
2363
|
+
if (node.type.name === "urgentMention") found = true;
|
|
2364
|
+
return !found;
|
|
2365
|
+
});
|
|
2366
|
+
return found;
|
|
2367
|
+
};
|
|
2144
2368
|
var fileCount = 0;
|
|
2145
2369
|
function CommentBox({
|
|
2146
2370
|
people,
|
|
@@ -2160,10 +2384,12 @@ function CommentBox({
|
|
|
2160
2384
|
accept,
|
|
2161
2385
|
closed,
|
|
2162
2386
|
referenceView,
|
|
2163
|
-
extensions =
|
|
2387
|
+
extensions = NO_EXTENSIONS,
|
|
2164
2388
|
autoFocus,
|
|
2165
2389
|
onSent,
|
|
2166
2390
|
onRefused,
|
|
2391
|
+
marked,
|
|
2392
|
+
onEditor,
|
|
2167
2393
|
className
|
|
2168
2394
|
}) {
|
|
2169
2395
|
const [files, setFiles] = useState4(edit?.files ?? []);
|
|
@@ -2173,8 +2399,8 @@ function CommentBox({
|
|
|
2173
2399
|
const [removed, setRemoved] = useState4(() => /* @__PURE__ */ new Set());
|
|
2174
2400
|
const picker = useRef3(null);
|
|
2175
2401
|
const root = useRef3(null);
|
|
2176
|
-
const latest = useRef3({ edit,
|
|
2177
|
-
latest.current = { edit,
|
|
2402
|
+
const latest = useRef3({ edit, upload, draft, under });
|
|
2403
|
+
latest.current = { edit, upload, draft, under };
|
|
2178
2404
|
const save = useRef3(() => false);
|
|
2179
2405
|
const attachFiles = useCallback4((picked) => {
|
|
2180
2406
|
const uploadOne = latest.current.upload;
|
|
@@ -2193,51 +2419,29 @@ function CommentBox({
|
|
|
2193
2419
|
return true;
|
|
2194
2420
|
}, []);
|
|
2195
2421
|
const rows = insert.filter((c) => !((edit || !upload) && c.key === commentBoxRows.file.key) && !(edit && c.key === commentBoxRows.urgent.key));
|
|
2196
|
-
const
|
|
2197
|
-
sections.splice(0, sections.length, formatSection(code), ...rows.length > 0 ? [{ label: "Insert", commands: rows }] : []);
|
|
2198
|
-
const iconFor = useCallback4((uri) => latest.current.referenceIcon?.(uri), []);
|
|
2199
|
-
const editor = useEditor({
|
|
2200
|
-
extensions: [
|
|
2201
|
-
BoxKit.configure({ link: { openOnClick: false } }),
|
|
2202
|
-
PasteOverWords,
|
|
2203
|
-
KeptSelection,
|
|
2204
|
-
ComposeKeys,
|
|
2205
|
-
BoxKeys.configure({
|
|
2206
|
-
onEscape: () => {
|
|
2207
|
-
const editing = latest.current.edit;
|
|
2208
|
-
if (!editing) return false;
|
|
2209
|
-
editing.onCancel();
|
|
2210
|
-
return true;
|
|
2211
|
-
}
|
|
2212
|
-
}),
|
|
2213
|
-
PersonMention.configure({ people: () => latest.current.people }),
|
|
2214
|
-
// An edit makes nobody urgent (CON-24): `!@` opens no list there, as `/` offers no Urgent.
|
|
2215
|
-
UrgentPersonMention.extend({
|
|
2216
|
-
addOptions() {
|
|
2217
|
-
const parent = this.parent();
|
|
2218
|
-
return { ...parent, suggestion: { ...parent.suggestion, allow: () => !latest.current.edit } };
|
|
2219
|
-
}
|
|
2220
|
-
}).configure({ people: () => latest.current.people }),
|
|
2221
|
-
CaptionedReference.configure({ icon: SMALL_SQUARE, iconFor }),
|
|
2222
|
-
ReferenceTrigger.configure({
|
|
2223
|
-
items: () => [],
|
|
2224
|
-
sections: (query) => latest.current.references?.(query) ?? [],
|
|
2225
|
-
subscribe: (listener) => latest.current.referencesChanged?.(listener) ?? (() => {
|
|
2226
|
-
}),
|
|
2227
|
-
ariaLabel: "References",
|
|
2228
|
-
sectionLabel: "References",
|
|
2229
|
-
icon: SQUARE,
|
|
2230
|
-
iconFor
|
|
2231
|
-
}),
|
|
2232
|
-
SlashCommands.configure({ sections }),
|
|
2233
|
-
ReferenceNode.configure({ view: referenceView ?? null }),
|
|
2234
|
-
PastedImages.configure({ onImages: attachFiles }),
|
|
2235
|
-
...extensions
|
|
2236
|
-
],
|
|
2237
|
-
content: edit?.body ?? draft?.read(),
|
|
2422
|
+
const { editor, hold } = useBoxEditor({ extensions, referenceView: referenceView ?? null }, edit?.body ?? draft?.read(), {
|
|
2238
2423
|
editable: !closed,
|
|
2239
2424
|
editorProps: { attributes: { class: COMPOSE_EDITOR_CLASSES, role: "textbox", "aria-multiline": "true", "aria-label": label } }
|
|
2240
2425
|
});
|
|
2426
|
+
hold.current = { edit, people, references, referencesChanged, referenceIcon, attach: attachFiles };
|
|
2427
|
+
hold.sections.splice(0, hold.sections.length, formatSection(code), ...rows.length > 0 ? [{ label: "Insert", commands: rows }] : []);
|
|
2428
|
+
const [marking, setMarking] = useState4(false);
|
|
2429
|
+
const markedBy = useRef3(marked);
|
|
2430
|
+
markedBy.current = marked;
|
|
2431
|
+
useLayoutEffect(() => {
|
|
2432
|
+
const read = () => setMarking(holdsUrgent(editor) || !!markedBy.current?.(editor));
|
|
2433
|
+
read();
|
|
2434
|
+
editor.on("update", read);
|
|
2435
|
+
return () => {
|
|
2436
|
+
editor.off("update", read);
|
|
2437
|
+
};
|
|
2438
|
+
}, [editor]);
|
|
2439
|
+
const handOut = useRef3(onEditor);
|
|
2440
|
+
handOut.current = onEditor;
|
|
2441
|
+
useEffect4(() => {
|
|
2442
|
+
handOut.current?.(editor);
|
|
2443
|
+
return () => handOut.current?.(null);
|
|
2444
|
+
}, [editor]);
|
|
2241
2445
|
useEffect4(() => {
|
|
2242
2446
|
if (!editor || edit) return;
|
|
2243
2447
|
const keep = () => {
|
|
@@ -2389,7 +2593,7 @@ function CommentBox({
|
|
|
2389
2593
|
if (edit) {
|
|
2390
2594
|
return /* @__PURE__ */ jsxs5("div", { className: cn2("flex flex-col gap-1", className), children: [
|
|
2391
2595
|
/* @__PURE__ */ jsxs5("div", { className: cn2(WRITING_BOX_CLASSES, "focus-within:border-border-strong transition-colors", sending && "[&_.ProseMirror]:text-text-muted"), children: [
|
|
2392
|
-
/* @__PURE__ */ jsx7(EditorContent2, { editor }),
|
|
2596
|
+
/* @__PURE__ */ jsx7("div", { "data-composer-editor": true, "data-marked": marking || void 0, className: cn2("relative min-h-[20px]", marking && "border-l-4 border-border-strong pl-2"), children: /* @__PURE__ */ jsx7(ScrollArea2, { className: COMPOSE_SCROLL_CLASSES.area, viewportClassName: COMPOSE_SCROLL_CLASSES.viewport, contentClassName: COMPOSE_SCROLL_CLASSES.content, children: /* @__PURE__ */ jsx7(EditorContent2, { editor }) }) }),
|
|
2393
2597
|
fileCards && /* @__PURE__ */ jsx7("div", { className: "flex flex-wrap gap-2", children: fileCards }),
|
|
2394
2598
|
/* @__PURE__ */ jsxs5("div", { className: "flex items-center justify-between gap-2", children: [
|
|
2395
2599
|
/* @__PURE__ */ jsxs5("span", { className: "flex items-center gap-1 text-caption text-text-muted", children: [
|
|
@@ -2425,6 +2629,7 @@ function CommentBox({
|
|
|
2425
2629
|
tools: upload ? /* @__PURE__ */ jsx7(ToolbarButton2, { tooltip: "Attach a file", "aria-label": "Attach a file", disabled: sending, onClick: () => picker.current?.click(), children: /* @__PURE__ */ jsx7(IconPaperclip, { size: 16, stroke: 1.5 }) }) : void 0,
|
|
2426
2630
|
attachments: fileCards,
|
|
2427
2631
|
ready,
|
|
2632
|
+
marked: marking,
|
|
2428
2633
|
holding: uploading || failed > 0 || sending,
|
|
2429
2634
|
selection: { link: true },
|
|
2430
2635
|
className: cn2(sending && "[&_[data-composer-editor]]:text-text-muted")
|
|
@@ -2441,9 +2646,9 @@ function CommentBox({
|
|
|
2441
2646
|
|
|
2442
2647
|
// src/InlineText.tsx
|
|
2443
2648
|
import { useCallback as useCallback5, useEffect as useEffect5, useImperativeHandle as useImperativeHandle2, useRef as useRef4, useState as useState5 } from "react";
|
|
2444
|
-
import { Extension as
|
|
2649
|
+
import { Extension as Extension12, Node as Node3 } from "@tiptap/core";
|
|
2445
2650
|
import { history, redo, undo } from "@tiptap/pm/history";
|
|
2446
|
-
import { EditorContent as EditorContent3, useEditor
|
|
2651
|
+
import { EditorContent as EditorContent3, useEditor } from "@tiptap/react";
|
|
2447
2652
|
import { cn as cn3 } from "@estiva-app/ui";
|
|
2448
2653
|
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
2449
2654
|
var VARIANT = {
|
|
@@ -2459,7 +2664,7 @@ var Paragraph = Node3.create({
|
|
|
2459
2664
|
renderHTML: () => ["p", 0]
|
|
2460
2665
|
});
|
|
2461
2666
|
var Text = Node3.create({ name: "text" });
|
|
2462
|
-
var Undo =
|
|
2667
|
+
var Undo = Extension12.create({
|
|
2463
2668
|
name: "inlineTextUndo",
|
|
2464
2669
|
addProseMirrorPlugins: () => [history()],
|
|
2465
2670
|
addKeyboardShortcuts() {
|
|
@@ -2486,7 +2691,7 @@ function InlineText({ value, placeholder, label, onCommit, onText, onEnter, vari
|
|
|
2486
2691
|
if (pending.current === next) pending.current = null;
|
|
2487
2692
|
}
|
|
2488
2693
|
}, []);
|
|
2489
|
-
const editor =
|
|
2694
|
+
const editor = useEditor({
|
|
2490
2695
|
extensions: [OneLine, Paragraph, Text, Undo],
|
|
2491
2696
|
content: doc(value),
|
|
2492
2697
|
editable: !readOnly,
|
|
@@ -2559,10 +2764,10 @@ function InlineText({ value, placeholder, label, onCommit, onText, onEnter, vari
|
|
|
2559
2764
|
}
|
|
2560
2765
|
|
|
2561
2766
|
// src/CommentHighlights.ts
|
|
2562
|
-
import { Extension as
|
|
2563
|
-
import { Plugin as
|
|
2564
|
-
import { Decoration as
|
|
2565
|
-
var commentHighlightsKey = new
|
|
2767
|
+
import { Extension as Extension13 } from "@tiptap/core";
|
|
2768
|
+
import { Plugin as Plugin9, PluginKey as PluginKey10 } from "@tiptap/pm/state";
|
|
2769
|
+
import { Decoration as Decoration5, DecorationSet as DecorationSet5 } from "@tiptap/pm/view";
|
|
2770
|
+
var commentHighlightsKey = new PluginKey10("commentHighlights");
|
|
2566
2771
|
var COMMENT_HIGHLIGHT_CLASSES = {
|
|
2567
2772
|
rest: "cursor-pointer rounded-sm bg-warning-muted",
|
|
2568
2773
|
active: "cursor-pointer rounded-sm bg-warning-muted underline decoration-warning-default decoration-2 underline-offset-4"
|
|
@@ -2650,7 +2855,7 @@ function runIn(doc2, places, ids) {
|
|
|
2650
2855
|
});
|
|
2651
2856
|
return run;
|
|
2652
2857
|
}
|
|
2653
|
-
function
|
|
2858
|
+
function placeOf2(doc2, anchor, places = placesIn(doc2)) {
|
|
2654
2859
|
const run = runIn(doc2, places, anchor.blocks);
|
|
2655
2860
|
if (!run) return { state: "detached" };
|
|
2656
2861
|
const from = run[0].pos;
|
|
@@ -2681,7 +2886,7 @@ function placeOf(doc2, anchor, places = placesIn(doc2)) {
|
|
|
2681
2886
|
if (endAt === -1 || quote.end === "") return reworded;
|
|
2682
2887
|
return { state: "resolved", from: a.starts[startAt], to: b.ends[endAt + quote.end.length - 1], words: true };
|
|
2683
2888
|
}
|
|
2684
|
-
var CommentHighlights =
|
|
2889
|
+
var CommentHighlights = Extension13.create({
|
|
2685
2890
|
name: "commentHighlights",
|
|
2686
2891
|
addOptions() {
|
|
2687
2892
|
return { onSelect: null };
|
|
@@ -2690,7 +2895,7 @@ var CommentHighlights = Extension12.create({
|
|
|
2690
2895
|
const options = this.options;
|
|
2691
2896
|
const editor = this.editor;
|
|
2692
2897
|
return [
|
|
2693
|
-
new
|
|
2898
|
+
new Plugin9({
|
|
2694
2899
|
key: commentHighlightsKey,
|
|
2695
2900
|
state: {
|
|
2696
2901
|
init: () => ({ anchors: [], active: null }),
|
|
@@ -2704,26 +2909,26 @@ var CommentHighlights = Extension12.create({
|
|
|
2704
2909
|
const { anchors, active } = commentHighlightsKey.getState(state) ?? { anchors: [], active: null };
|
|
2705
2910
|
const places = placesIn(state.doc);
|
|
2706
2911
|
const drawn = anchors.flatMap((anchor) => {
|
|
2707
|
-
const place2 =
|
|
2912
|
+
const place2 = placeOf2(state.doc, anchor, places);
|
|
2708
2913
|
if (place2.state !== "resolved") return [];
|
|
2709
2914
|
const attrs = { class: anchor.id === active ? COMMENT_HIGHLIGHT_CLASSES.active : COMMENT_HIGHLIGHT_CLASSES.rest, "data-comment-id": anchor.id };
|
|
2710
|
-
if (place2.words) return [
|
|
2915
|
+
if (place2.words) return [Decoration5.inline(place2.from, place2.to, attrs)];
|
|
2711
2916
|
const blocks = [];
|
|
2712
2917
|
state.doc.nodesBetween(place2.from, place2.to, (node, pos) => {
|
|
2713
2918
|
if (pos < place2.from || pos + node.nodeSize > place2.to) return true;
|
|
2714
|
-
blocks.push(
|
|
2919
|
+
blocks.push(Decoration5.node(pos, pos + node.nodeSize, attrs));
|
|
2715
2920
|
return false;
|
|
2716
2921
|
});
|
|
2717
2922
|
return blocks;
|
|
2718
2923
|
});
|
|
2719
|
-
return drawn.length ?
|
|
2924
|
+
return drawn.length ? DecorationSet5.create(state.doc, drawn) : null;
|
|
2720
2925
|
},
|
|
2721
2926
|
handleClick(view, pos) {
|
|
2722
2927
|
const { anchors } = commentHighlightsKey.getState(view.state) ?? { anchors: [] };
|
|
2723
2928
|
const places = placesIn(view.state.doc);
|
|
2724
2929
|
let hit = null;
|
|
2725
2930
|
for (const anchor of anchors) {
|
|
2726
|
-
const place2 =
|
|
2931
|
+
const place2 = placeOf2(view.state.doc, anchor, places);
|
|
2727
2932
|
if (place2.state !== "resolved" || pos < place2.from || pos >= place2.to) continue;
|
|
2728
2933
|
const size = place2.to - place2.from;
|
|
2729
2934
|
if (!hit || size < hit.size) hit = { id: anchor.id, size };
|
|
@@ -2744,12 +2949,12 @@ function setCommentAnchors(editor, anchors, active = null) {
|
|
|
2744
2949
|
editor.view.dispatch(editor.state.tr.setMeta(commentHighlightsKey, { anchors, active }));
|
|
2745
2950
|
}
|
|
2746
2951
|
function commentPlace(editor, anchor) {
|
|
2747
|
-
return
|
|
2952
|
+
return placeOf2(editor.state.doc, anchor);
|
|
2748
2953
|
}
|
|
2749
2954
|
function commentElement(editor, anchor) {
|
|
2750
2955
|
const drawn = editor.view.dom.querySelector(`[data-comment-id="${CSS.escape(anchor.id)}"]`);
|
|
2751
2956
|
if (drawn) return drawn;
|
|
2752
|
-
const place2 =
|
|
2957
|
+
const place2 = placeOf2(editor.state.doc, anchor);
|
|
2753
2958
|
if (place2.state === "detached") return null;
|
|
2754
2959
|
const dom = editor.view.nodeDOM(place2.from);
|
|
2755
2960
|
return dom instanceof HTMLElement ? dom : null;
|
|
@@ -2841,9 +3046,9 @@ function anchorOfSelection(editor) {
|
|
|
2841
3046
|
}
|
|
2842
3047
|
|
|
2843
3048
|
// src/PastedMarkdown.ts
|
|
2844
|
-
import { Extension as
|
|
3049
|
+
import { Extension as Extension14 } from "@tiptap/core";
|
|
2845
3050
|
import { Slice } from "@tiptap/pm/model";
|
|
2846
|
-
import { Plugin as
|
|
3051
|
+
import { Plugin as Plugin10, PluginKey as PluginKey11 } from "@tiptap/pm/state";
|
|
2847
3052
|
function inTableCell($context) {
|
|
2848
3053
|
for (let depth = $context.depth; depth > 0; depth--) {
|
|
2849
3054
|
const role = $context.node(depth).type.spec.tableRole;
|
|
@@ -2852,7 +3057,7 @@ function inTableCell($context) {
|
|
|
2852
3057
|
return false;
|
|
2853
3058
|
}
|
|
2854
3059
|
var hasTable = (blocks) => blocks.some((block) => block.type === "table" || hasTable(block.content ?? []));
|
|
2855
|
-
var PastedMarkdown =
|
|
3060
|
+
var PastedMarkdown = Extension14.create({
|
|
2856
3061
|
name: "pastedMarkdown",
|
|
2857
3062
|
addOptions() {
|
|
2858
3063
|
return { read: () => void 0 };
|
|
@@ -2860,8 +3065,8 @@ var PastedMarkdown = Extension13.create({
|
|
|
2860
3065
|
addProseMirrorPlugins() {
|
|
2861
3066
|
const options = this.options;
|
|
2862
3067
|
return [
|
|
2863
|
-
new
|
|
2864
|
-
key: new
|
|
3068
|
+
new Plugin10({
|
|
3069
|
+
key: new PluginKey11("pastedMarkdown"),
|
|
2865
3070
|
props: {
|
|
2866
3071
|
// Reached only for a text paste outside code; `plain` is the Shift paste.
|
|
2867
3072
|
clipboardTextParser: (text, $context, plain, view) => {
|
|
@@ -3277,7 +3482,7 @@ function EditorTableControls({ editor, children, className }) {
|
|
|
3277
3482
|
// src/DocumentEditor.tsx
|
|
3278
3483
|
import { useCallback as useCallback7, useEffect as useEffect7, useRef as useRef6, useState as useState7 } from "react";
|
|
3279
3484
|
import { TextSelection as TextSelection4 } from "@tiptap/pm/state";
|
|
3280
|
-
import { EditorContent as EditorContent4, useEditor as
|
|
3485
|
+
import { EditorContent as EditorContent4, useEditor as useEditor2, useEditorState as useEditorState2 } from "@tiptap/react";
|
|
3281
3486
|
import { TableKit } from "@tiptap/extension-table";
|
|
3282
3487
|
import { IconMessagePlus } from "@tabler/icons-react";
|
|
3283
3488
|
import { Button as Button2 } from "@estiva-app/ui";
|
|
@@ -3285,8 +3490,8 @@ import { FieldLine as FieldLine2 } from "@estiva-app/ui";
|
|
|
3285
3490
|
import { FilePicker as FilePicker2 } from "@estiva-app/ui";
|
|
3286
3491
|
import { richTextClassName as richTextClassName2 } from "@estiva-app/ui";
|
|
3287
3492
|
import { Fragment as Fragment6, jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
3288
|
-
function heldDocument(hold,
|
|
3289
|
-
const text = hold &&
|
|
3493
|
+
function heldDocument(hold, key5) {
|
|
3494
|
+
const text = hold && key5 ? hold.text(key5) : void 0;
|
|
3290
3495
|
if (!text) return null;
|
|
3291
3496
|
try {
|
|
3292
3497
|
const doc2 = JSON.parse(text);
|
|
@@ -3317,7 +3522,6 @@ function DocumentEditor({
|
|
|
3317
3522
|
blockRows,
|
|
3318
3523
|
referenceView,
|
|
3319
3524
|
attachmentView,
|
|
3320
|
-
cards,
|
|
3321
3525
|
wrap,
|
|
3322
3526
|
onEditor,
|
|
3323
3527
|
extensions = []
|
|
@@ -3434,7 +3638,7 @@ function DocumentEditor({
|
|
|
3434
3638
|
};
|
|
3435
3639
|
const attachTo = useRef6(attach);
|
|
3436
3640
|
attachTo.current = attach;
|
|
3437
|
-
const editor =
|
|
3641
|
+
const editor = useEditor2(
|
|
3438
3642
|
{
|
|
3439
3643
|
extensions: [
|
|
3440
3644
|
DocumentKit.configure({
|
|
@@ -3456,9 +3660,9 @@ function DocumentEditor({
|
|
|
3456
3660
|
Checklist,
|
|
3457
3661
|
Callout,
|
|
3458
3662
|
ReferenceNode.configure({ view: referenceView ?? null }),
|
|
3459
|
-
//
|
|
3460
|
-
|
|
3461
|
-
// A click on a
|
|
3663
|
+
// A link's chip in a sentence, its row alone on its line, its card in the row's place (SPEC §13.3).
|
|
3664
|
+
LinkPlaces,
|
|
3665
|
+
// A click on a link offers Open, and alone on its line Show as Row or Card.
|
|
3462
3666
|
ReferenceMenu,
|
|
3463
3667
|
UnknownBlock,
|
|
3464
3668
|
AttachmentNode.configure({ view: attachmentView ?? null }),
|
|
@@ -3498,7 +3702,15 @@ function DocumentEditor({
|
|
|
3498
3702
|
editable: !readOnly,
|
|
3499
3703
|
editorProps: {
|
|
3500
3704
|
// Focusable when read only too: the selection strip, and so Comment on its words, shows only in a focused view.
|
|
3501
|
-
attributes: {
|
|
3705
|
+
attributes: {
|
|
3706
|
+
"aria-label": label,
|
|
3707
|
+
role: "textbox",
|
|
3708
|
+
"aria-multiline": "true",
|
|
3709
|
+
tabindex: "0",
|
|
3710
|
+
// A row or a card is its whole line (`LinkPlaces`), drawn on that line: a block inside it would push the
|
|
3711
|
+
// separator and trailing break ProseMirror puts beside it onto empty lines of their own (code review).
|
|
3712
|
+
class: richTextClassName2("default", "outline-none [&_[data-link-place]]:inline-block [&_[data-link-place]]:w-full [&_[data-link-place]]:align-top")
|
|
3713
|
+
},
|
|
3502
3714
|
handleKeyDown: (view, event) => {
|
|
3503
3715
|
if (event.key !== "Escape") return false;
|
|
3504
3716
|
if (isSuggestionOpen() || isReferenceMenuOpen(view.state)) return false;
|
|
@@ -3563,7 +3775,6 @@ function DocumentEditor({
|
|
|
3563
3775
|
/* @__PURE__ */ jsx11(EditorTableControls, { editor, children: /* @__PURE__ */ jsx11(EditorContent4, { editor, className: "-mx-2 cursor-text px-2 py-1", "data-document-editor": "" }) }),
|
|
3564
3776
|
empty && !readOnly && placeholder && /* @__PURE__ */ jsx11("span", { "aria-hidden": true, className: "pointer-events-none absolute left-0 top-1 text-body-2 text-text-muted", children: placeholder })
|
|
3565
3777
|
] }),
|
|
3566
|
-
cards?.(editor),
|
|
3567
3778
|
(!readOnly || onCommentOnSelection) && /* @__PURE__ */ jsx11(
|
|
3568
3779
|
SelectionToolbar,
|
|
3569
3780
|
{
|
|
@@ -3628,6 +3839,7 @@ export {
|
|
|
3628
3839
|
InlineText,
|
|
3629
3840
|
KeptSelection,
|
|
3630
3841
|
LinkChips,
|
|
3842
|
+
LinkPlaces,
|
|
3631
3843
|
PastedImages,
|
|
3632
3844
|
PastedMarkdown,
|
|
3633
3845
|
PersonMention,
|
|
@@ -3663,6 +3875,7 @@ export {
|
|
|
3663
3875
|
isSuggestionActive,
|
|
3664
3876
|
isSuggestionOpen,
|
|
3665
3877
|
keepSelection,
|
|
3878
|
+
linkPlaceAt,
|
|
3666
3879
|
moveBlock,
|
|
3667
3880
|
normalizeHref,
|
|
3668
3881
|
pastedImageName,
|
|
@@ -3679,6 +3892,7 @@ export {
|
|
|
3679
3892
|
setReferenceCard,
|
|
3680
3893
|
setReferenceCardAt,
|
|
3681
3894
|
startBlockDrag,
|
|
3895
|
+
staysChip,
|
|
3682
3896
|
suggestionPopup,
|
|
3683
3897
|
toggleTableHeaderRow,
|
|
3684
3898
|
turnIntoRows,
|