@estiva-app/ui 0.80.0 → 0.82.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.map +1 -1
- package/dist/CardUnder.d.ts +24 -3
- package/dist/CardUnder.d.ts.map +1 -1
- package/dist/CommentBox.d.ts +39 -5
- package/dist/CommentBox.d.ts.map +1 -1
- package/dist/ComposerTriggers.d.ts +24 -0
- package/dist/ComposerTriggers.d.ts.map +1 -1
- package/dist/DocumentEditor.d.ts +138 -0
- package/dist/DocumentEditor.d.ts.map +1 -0
- package/dist/ReferenceMenu.d.ts.map +1 -1
- package/dist/SelectionToolbar.d.ts.map +1 -1
- package/dist/editor.d.ts +3 -2
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +565 -46
- package/dist/editor.js.map +4 -4
- package/dist/index.js +2 -2
- package/dist/index.js.map +2 -2
- package/dist/links.d.ts +28 -0
- package/dist/links.d.ts.map +1 -0
- package/package.json +7 -1
- package/registry.json +199 -10
- package/src/BlockNodes.tsx +3 -1
- package/src/CardUnder.mdx +1 -0
- package/src/CardUnder.tsx +10 -6
- package/src/CommentBox.mdx +8 -0
- package/src/CommentBox.stories.tsx +62 -2
- package/src/CommentBox.test.tsx +169 -1
- package/src/CommentBox.tsx +110 -17
- package/src/ComposerTriggers.tsx +65 -0
- package/src/DocumentEditor.mdx +106 -0
- package/src/DocumentEditor.stories.tsx +305 -0
- package/src/DocumentEditor.test.tsx +528 -0
- package/src/DocumentEditor.tsx +568 -0
- package/src/ReferenceMenu.tsx +6 -1
- package/src/SelectionToolbar.tsx +2 -1
- package/src/editor.ts +13 -0
- package/src/gates/create-app.test.ts +3 -1
- package/src/links.ts +151 -0
- package/src/registry/registry.test.ts +6 -6
- package/stories/Choosing.mdx +1 -0
package/dist/editor.js
CHANGED
|
@@ -275,7 +275,7 @@ function SelectionToolbar({ editor, marks = ["bold", "italic", "underline"], lin
|
|
|
275
275
|
}
|
|
276
276
|
),
|
|
277
277
|
children,
|
|
278
|
-
actions.length > 0 && /* @__PURE__ */ jsx(ToolbarSeparator, {}),
|
|
278
|
+
actions.length > 0 && (marks.length > 0 || link || children) && /* @__PURE__ */ jsx(ToolbarSeparator, {}),
|
|
279
279
|
actions.map((action) => /* @__PURE__ */ jsx(
|
|
280
280
|
ToolbarButton,
|
|
281
281
|
{
|
|
@@ -528,10 +528,9 @@ function ComposeBox({ editor, onSend, placeholder, tools, attachments, ready = f
|
|
|
528
528
|
}
|
|
529
529
|
|
|
530
530
|
// src/CommentBox.tsx
|
|
531
|
-
import { useCallback as useCallback4, useEffect as useEffect4, useRef as useRef3, useState as useState4 } from "react";
|
|
532
|
-
import { Extension as
|
|
531
|
+
import { Fragment as Fragment2, useCallback as useCallback4, useEffect as useEffect4, useRef as useRef3, useState as useState4 } from "react";
|
|
532
|
+
import { Extension as Extension10 } from "@tiptap/core";
|
|
533
533
|
import { EditorContent as EditorContent2, useEditor } from "@tiptap/react";
|
|
534
|
-
import StarterKit from "@tiptap/starter-kit";
|
|
535
534
|
import { IconLock, IconPaperclip, IconSquareRounded } from "@tabler/icons-react";
|
|
536
535
|
import { AttachmentCard } from "@estiva-app/ui";
|
|
537
536
|
|
|
@@ -1310,7 +1309,8 @@ var ReferenceNode = Node2.create({
|
|
|
1310
1309
|
},
|
|
1311
1310
|
renderHTML({ node }) {
|
|
1312
1311
|
const embed = typeof node.attrs.embed === "string" ? { "data-embed": node.attrs.embed } : {};
|
|
1313
|
-
const
|
|
1312
|
+
const web = webUrl(typeof node.attrs.href === "string" ? node.attrs.href : null);
|
|
1313
|
+
const href = web ? { "data-href": web } : {};
|
|
1314
1314
|
return ["span", { "data-reference": String(node.attrs.uri), ...embed, ...href }, String(node.attrs.href || node.attrs.uri)];
|
|
1315
1315
|
},
|
|
1316
1316
|
renderText({ node }) {
|
|
@@ -1567,6 +1567,7 @@ var Callout = Extension6.create({
|
|
|
1567
1567
|
// src/CommentBox.tsx
|
|
1568
1568
|
import { Button } from "@estiva-app/ui";
|
|
1569
1569
|
import { Card } from "@estiva-app/ui";
|
|
1570
|
+
import { CardUnder } from "@estiva-app/ui";
|
|
1570
1571
|
import { cn as cn2 } from "@estiva-app/ui";
|
|
1571
1572
|
|
|
1572
1573
|
// src/ComposerTriggers.tsx
|
|
@@ -1689,6 +1690,41 @@ function urgentPubkeys(editor) {
|
|
|
1689
1690
|
});
|
|
1690
1691
|
return urgent.length > 0 ? urgent : void 0;
|
|
1691
1692
|
}
|
|
1693
|
+
var PersonReference = Extension7.create({
|
|
1694
|
+
name: "personReference",
|
|
1695
|
+
addOptions() {
|
|
1696
|
+
return { people: () => [], uriOf: () => null, nodeName: "reference" };
|
|
1697
|
+
},
|
|
1698
|
+
addProseMirrorPlugins() {
|
|
1699
|
+
const options = this.options;
|
|
1700
|
+
return [
|
|
1701
|
+
Suggestion({
|
|
1702
|
+
editor: this.editor,
|
|
1703
|
+
char: "@",
|
|
1704
|
+
pluginKey: new PluginKey6("personReference"),
|
|
1705
|
+
...listening("@"),
|
|
1706
|
+
// As `[`'s: only where the chip may go.
|
|
1707
|
+
allow: ({ state, range }) => {
|
|
1708
|
+
const type = state.schema.nodes[options.nodeName];
|
|
1709
|
+
return !!type && !!state.doc.resolve(range.from).parent.type.contentMatch.matchType(type);
|
|
1710
|
+
},
|
|
1711
|
+
items: ({ query }) => filterPeople(
|
|
1712
|
+
options.people().filter((person) => options.uriOf(person) !== null),
|
|
1713
|
+
query
|
|
1714
|
+
),
|
|
1715
|
+
render: suggestionPopup(peopleMenu(false)),
|
|
1716
|
+
command: ({ editor, range, props: person }) => {
|
|
1717
|
+
const uri = options.uriOf(person);
|
|
1718
|
+
if (!uri) return;
|
|
1719
|
+
editor.chain().focus().insertContentAt(range, [
|
|
1720
|
+
{ type: options.nodeName, attrs: { uri } },
|
|
1721
|
+
{ type: "text", text: " " }
|
|
1722
|
+
]).run();
|
|
1723
|
+
}
|
|
1724
|
+
})
|
|
1725
|
+
];
|
|
1726
|
+
}
|
|
1727
|
+
});
|
|
1692
1728
|
var REFERENCE_LIMIT = 6;
|
|
1693
1729
|
function filterReferences(items, query) {
|
|
1694
1730
|
const q = query.toLowerCase();
|
|
@@ -1916,9 +1952,113 @@ import { FieldLine } from "@estiva-app/ui";
|
|
|
1916
1952
|
import { FilePicker } from "@estiva-app/ui";
|
|
1917
1953
|
import { Kbd } from "@estiva-app/ui";
|
|
1918
1954
|
|
|
1919
|
-
// src/
|
|
1955
|
+
// src/links.ts
|
|
1920
1956
|
import { Extension as Extension8 } from "@tiptap/core";
|
|
1921
|
-
import { Plugin as Plugin6, PluginKey as PluginKey7 } from "@tiptap/pm/state";
|
|
1957
|
+
import { Plugin as Plugin6, PluginKey as PluginKey7, TextSelection as TextSelection2 } from "@tiptap/pm/state";
|
|
1958
|
+
import { Decoration as Decoration3, DecorationSet as DecorationSet3 } from "@tiptap/pm/view";
|
|
1959
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
1960
|
+
var LINK_ON_WORDS_TARGET = /^https?:\/\/[^\s)]+$/;
|
|
1961
|
+
var PasteOverWords = Extension8.create({
|
|
1962
|
+
name: "commentBoxPasteOverWords",
|
|
1963
|
+
priority: 1001,
|
|
1964
|
+
addProseMirrorPlugins() {
|
|
1965
|
+
return [
|
|
1966
|
+
new Plugin6({
|
|
1967
|
+
key: new PluginKey7("commentBoxPasteOverWords"),
|
|
1968
|
+
props: {
|
|
1969
|
+
handlePaste: (view, event) => {
|
|
1970
|
+
const url = (event.clipboardData?.getData("text/plain").trim() ?? "").replace(/[.,;:!?]+$/, "");
|
|
1971
|
+
const { state } = view;
|
|
1972
|
+
const { schema } = state;
|
|
1973
|
+
if (state.selection.empty || !schema.marks.link || !/^https?:\/\/\S+$/.test(url)) return false;
|
|
1974
|
+
const { $from, $to, from, to } = TextSelection2.between(state.selection.$from, state.selection.$to);
|
|
1975
|
+
let plain = $from.sameParent($to) && $from.parent.isTextblock && !$from.parent.type.spec.code;
|
|
1976
|
+
state.doc.nodesBetween(from, to, (node) => {
|
|
1977
|
+
if (!node.isInline) return true;
|
|
1978
|
+
if (!node.isText || node.marks.some((m) => m.type.spec.code || m.type.name === "code")) plain = false;
|
|
1979
|
+
return false;
|
|
1980
|
+
});
|
|
1981
|
+
if (plain && LINK_ON_WORDS_TARGET.test(url) && !/[[\]\n]/.test(state.doc.textBetween(from, to))) {
|
|
1982
|
+
view.dispatch(state.tr.addMark(from, to, schema.marks.link.create({ href: url })));
|
|
1983
|
+
return true;
|
|
1984
|
+
}
|
|
1985
|
+
const before = state.doc.textBetween(Math.max(to - 1, $to.start()), to, "", "\uFFFC");
|
|
1986
|
+
const inserted = before && !/\s/.test(before) ? ` ${url}` : url;
|
|
1987
|
+
const tr = state.tr.insertText(inserted, to);
|
|
1988
|
+
view.dispatch(tr.setSelection(TextSelection2.create(tr.doc, to + inserted.length)).scrollIntoView());
|
|
1989
|
+
return true;
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
})
|
|
1993
|
+
];
|
|
1994
|
+
}
|
|
1995
|
+
});
|
|
1996
|
+
var BoxKit = StarterKit.extend({
|
|
1997
|
+
addExtensions() {
|
|
1998
|
+
return (this.parent?.() ?? []).map((extension) => extension.name === "link" ? extension.extend({ inclusive: () => false }) : extension);
|
|
1999
|
+
}
|
|
2000
|
+
});
|
|
2001
|
+
var DocumentKit = StarterKit.extend({
|
|
2002
|
+
addExtensions() {
|
|
2003
|
+
return (this.parent?.() ?? []).map(
|
|
2004
|
+
(extension) => extension.name === "link" ? extension.extend({
|
|
2005
|
+
inclusive: () => false,
|
|
2006
|
+
addAttributes() {
|
|
2007
|
+
return { ...this.parent?.(), extra: { default: null, rendered: false, parseHTML: () => null } };
|
|
2008
|
+
}
|
|
2009
|
+
}) : extension
|
|
2010
|
+
);
|
|
2011
|
+
}
|
|
2012
|
+
});
|
|
2013
|
+
var LINK_SPLIT = /\[[^[\]\n]+\]\((?:https?:\/\/|mailto:)[^\s)]+\)|https?:\/\/[^\s]+/g;
|
|
2014
|
+
var TRAILING2 = /[.,;:!?)\]]+$/;
|
|
2015
|
+
var LINK_CLASS = "text-info-default underline underline-offset-2 cursor-pointer";
|
|
2016
|
+
var OPENABLE = /^(https?:\/\/|mailto:)/i;
|
|
2017
|
+
var LINK_MARK_ATTRIBUTES = { class: LINK_CLASS, "data-link-mark": "", target: "_blank", rel: "noopener noreferrer nofollow" };
|
|
2018
|
+
var LINK_TARGET = /\]\(([^\s)]+)\)$/;
|
|
2019
|
+
var BareLinks = Extension8.create({
|
|
2020
|
+
name: "bareLinks",
|
|
2021
|
+
addProseMirrorPlugins() {
|
|
2022
|
+
return [
|
|
2023
|
+
new Plugin6({
|
|
2024
|
+
key: new PluginKey7("bareLinks"),
|
|
2025
|
+
props: {
|
|
2026
|
+
// The one way a click opens an address: a bare one's decoration, or, while editing, a link on words (read only,
|
|
2027
|
+
// the link is a plain anchor and opens itself). Only its own attributes are read — never a chip's — and only an
|
|
2028
|
+
// address a reader may follow opens, always without handing the new tab this window.
|
|
2029
|
+
handleClick: (view, _pos, event) => {
|
|
2030
|
+
if (event.button !== 0) return false;
|
|
2031
|
+
const target = event.target;
|
|
2032
|
+
const bare = target?.closest?.("[data-bare-link]")?.getAttribute("data-bare-link");
|
|
2033
|
+
const onWords = view.editable ? target?.closest?.("a[data-link-mark]")?.getAttribute("href") : null;
|
|
2034
|
+
const href = bare ?? onWords;
|
|
2035
|
+
if (!href || !OPENABLE.test(href)) return false;
|
|
2036
|
+
window.open(href, "_blank", "noopener,noreferrer");
|
|
2037
|
+
return true;
|
|
2038
|
+
},
|
|
2039
|
+
decorations: ({ doc: doc2 }) => {
|
|
2040
|
+
const found = [];
|
|
2041
|
+
doc2.descendants((node, pos) => {
|
|
2042
|
+
if (!node.isText || !node.text) return;
|
|
2043
|
+
if (node.marks.some((mark) => mark.type.name === "code" || mark.type.name === "link")) return;
|
|
2044
|
+
for (const match of node.text.matchAll(LINK_SPLIT)) {
|
|
2045
|
+
if (match.index === void 0) continue;
|
|
2046
|
+
const text = match[0].startsWith("[") ? match[0] : match[0].replace(TRAILING2, "");
|
|
2047
|
+
const href = text.startsWith("[") ? LINK_TARGET.exec(text)?.[1] ?? "" : text;
|
|
2048
|
+
found.push(Decoration3.inline(pos + match.index, pos + match.index + text.length, { class: LINK_CLASS, ...href ? { "data-bare-link": href } : {} }));
|
|
2049
|
+
}
|
|
2050
|
+
});
|
|
2051
|
+
return found.length ? DecorationSet3.create(doc2, found) : null;
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
})
|
|
2055
|
+
];
|
|
2056
|
+
}
|
|
2057
|
+
});
|
|
2058
|
+
|
|
2059
|
+
// src/PastedImages.ts
|
|
2060
|
+
import { Extension as Extension9 } from "@tiptap/core";
|
|
2061
|
+
import { Plugin as Plugin7, PluginKey as PluginKey8 } from "@tiptap/pm/state";
|
|
1922
2062
|
var IMAGE_EXTENSIONS = {
|
|
1923
2063
|
"image/png": "png",
|
|
1924
2064
|
"image/jpeg": "jpg",
|
|
@@ -1953,7 +2093,7 @@ function pastedImages(source, at = /* @__PURE__ */ new Date()) {
|
|
|
1953
2093
|
(file) => hasUsableName(file.name) ? file : new File([file], pastedImageName(file.type, at, generated++), { type: file.type, lastModified: file.lastModified })
|
|
1954
2094
|
);
|
|
1955
2095
|
}
|
|
1956
|
-
var PastedImages =
|
|
2096
|
+
var PastedImages = Extension9.create({
|
|
1957
2097
|
name: "pastedImages",
|
|
1958
2098
|
addOptions() {
|
|
1959
2099
|
return { onImages: () => false };
|
|
@@ -1961,8 +2101,8 @@ var PastedImages = Extension8.create({
|
|
|
1961
2101
|
addProseMirrorPlugins() {
|
|
1962
2102
|
const options = this.options;
|
|
1963
2103
|
return [
|
|
1964
|
-
new
|
|
1965
|
-
key: new
|
|
2104
|
+
new Plugin7({
|
|
2105
|
+
key: new PluginKey8("pastedImages"),
|
|
1966
2106
|
props: {
|
|
1967
2107
|
handlePaste: (_view, event) => {
|
|
1968
2108
|
const files = pastedImages(event.clipboardData);
|
|
@@ -1976,7 +2116,7 @@ var PastedImages = Extension8.create({
|
|
|
1976
2116
|
|
|
1977
2117
|
// src/CommentBox.tsx
|
|
1978
2118
|
import { ToolbarButton as ToolbarButton2 } from "@estiva-app/ui";
|
|
1979
|
-
import { Fragment as
|
|
2119
|
+
import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1980
2120
|
var ATTACH_EVENT = "commentbox:attach";
|
|
1981
2121
|
var askForFile = (editor) => editor.view.dom.dispatchEvent(new CustomEvent(ATTACH_EVENT, { bubbles: true }));
|
|
1982
2122
|
var commentBoxRows = {
|
|
@@ -1985,7 +2125,7 @@ var commentBoxRows = {
|
|
|
1985
2125
|
urgent: { key: "insert-urgent", row: { label: "Urgent", shortcut: "!@" }, keywords: ["!@", "Urgent mention"], run: typeTrigger("!@") },
|
|
1986
2126
|
reference: { key: "insert-reference", row: { label: "Reference", shortcut: "[" }, keywords: ["[", "Reference"], run: typeTrigger("[") }
|
|
1987
2127
|
};
|
|
1988
|
-
var BoxKeys =
|
|
2128
|
+
var BoxKeys = Extension10.create({
|
|
1989
2129
|
name: "commentBoxKeys",
|
|
1990
2130
|
addOptions() {
|
|
1991
2131
|
return { onEscape: () => false };
|
|
@@ -1998,6 +2138,7 @@ var BoxKeys = Extension9.create({
|
|
|
1998
2138
|
};
|
|
1999
2139
|
}
|
|
2000
2140
|
});
|
|
2141
|
+
var stillNamed = (removed, names) => [...removed].every((value) => names.includes(value)) ? removed : new Set([...removed].filter((value) => names.includes(value)));
|
|
2001
2142
|
var SQUARE = /* @__PURE__ */ jsx7(IconSquareRounded, { size: 16, stroke: 1.5, className: "text-text-secondary" });
|
|
2002
2143
|
var SMALL_SQUARE = /* @__PURE__ */ jsx7(IconSquareRounded, { size: 14, stroke: 1.5 });
|
|
2003
2144
|
var fileCount = 0;
|
|
@@ -2009,6 +2150,7 @@ function CommentBox({
|
|
|
2009
2150
|
insert = [],
|
|
2010
2151
|
code = "block",
|
|
2011
2152
|
send,
|
|
2153
|
+
under,
|
|
2012
2154
|
showsAtOnce = false,
|
|
2013
2155
|
label,
|
|
2014
2156
|
placeholder,
|
|
@@ -2027,10 +2169,12 @@ function CommentBox({
|
|
|
2027
2169
|
const [files, setFiles] = useState4(edit?.files ?? []);
|
|
2028
2170
|
const [sending, setSending] = useState4(false);
|
|
2029
2171
|
const [refused, setRefused] = useState4(null);
|
|
2172
|
+
const [reading, setReading] = useState4(void 0);
|
|
2173
|
+
const [removed, setRemoved] = useState4(() => /* @__PURE__ */ new Set());
|
|
2030
2174
|
const picker = useRef3(null);
|
|
2031
2175
|
const root = useRef3(null);
|
|
2032
|
-
const latest = useRef3({ edit, people, references, referencesChanged, referenceIcon, upload, draft });
|
|
2033
|
-
latest.current = { edit, people, references, referencesChanged, referenceIcon, upload, draft };
|
|
2176
|
+
const latest = useRef3({ edit, people, references, referencesChanged, referenceIcon, upload, draft, under });
|
|
2177
|
+
latest.current = { edit, people, references, referencesChanged, referenceIcon, upload, draft, under };
|
|
2034
2178
|
const save = useRef3(() => false);
|
|
2035
2179
|
const attachFiles = useCallback4((picked) => {
|
|
2036
2180
|
const uploadOne = latest.current.upload;
|
|
@@ -2054,7 +2198,8 @@ function CommentBox({
|
|
|
2054
2198
|
const iconFor = useCallback4((uri) => latest.current.referenceIcon?.(uri), []);
|
|
2055
2199
|
const editor = useEditor({
|
|
2056
2200
|
extensions: [
|
|
2057
|
-
|
|
2201
|
+
BoxKit.configure({ link: { openOnClick: false } }),
|
|
2202
|
+
PasteOverWords,
|
|
2058
2203
|
KeptSelection,
|
|
2059
2204
|
ComposeKeys,
|
|
2060
2205
|
BoxKeys.configure({
|
|
@@ -2106,6 +2251,32 @@ function CommentBox({
|
|
|
2106
2251
|
editor.off("update", keep);
|
|
2107
2252
|
};
|
|
2108
2253
|
}, [editor, edit]);
|
|
2254
|
+
const reads = !!under;
|
|
2255
|
+
useEffect4(() => {
|
|
2256
|
+
if (!editor || !reads) {
|
|
2257
|
+
setReading(void 0);
|
|
2258
|
+
return;
|
|
2259
|
+
}
|
|
2260
|
+
const read = () => {
|
|
2261
|
+
const now = latest.current.under?.read(editor.getJSON());
|
|
2262
|
+
setReading(now);
|
|
2263
|
+
setRemoved((was) => stillNamed(was, now?.names ?? []));
|
|
2264
|
+
};
|
|
2265
|
+
read();
|
|
2266
|
+
editor.on("update", read);
|
|
2267
|
+
const unsubscribe = latest.current.under?.changed?.(read);
|
|
2268
|
+
return () => {
|
|
2269
|
+
editor.off("update", read);
|
|
2270
|
+
unsubscribe?.();
|
|
2271
|
+
};
|
|
2272
|
+
}, [editor, reads]);
|
|
2273
|
+
const underOf = useCallback4(
|
|
2274
|
+
(body) => {
|
|
2275
|
+
const card2 = latest.current.under?.read(body).card?.value;
|
|
2276
|
+
return card2 && !removed.has(card2) ? { card: card2 } : {};
|
|
2277
|
+
},
|
|
2278
|
+
[removed]
|
|
2279
|
+
);
|
|
2109
2280
|
useEffect4(() => {
|
|
2110
2281
|
editor?.setEditable(!closed && !sending);
|
|
2111
2282
|
}, [editor, closed, sending]);
|
|
@@ -2128,13 +2299,15 @@ function CommentBox({
|
|
|
2128
2299
|
(ed) => {
|
|
2129
2300
|
const body = ed.getJSON();
|
|
2130
2301
|
const sent = files.filter((f) => f.state === "ready");
|
|
2302
|
+
const sentUnder = underOf(body);
|
|
2131
2303
|
setRefused(null);
|
|
2132
2304
|
const answered = (answer) => answer.catch(() => ({ accepted: false, reason: "try again in a moment" }));
|
|
2133
2305
|
if (showsAtOnce) {
|
|
2306
|
+
const took = removed;
|
|
2134
2307
|
setFiles((all) => all.filter((f) => f.state !== "ready"));
|
|
2135
2308
|
draft?.clear();
|
|
2136
|
-
onSent?.(body, sent);
|
|
2137
|
-
void answered(send(body, sent)).then((answer) => {
|
|
2309
|
+
onSent?.(body, sent, sentUnder);
|
|
2310
|
+
void answered(send(body, sent, sentUnder)).then((answer) => {
|
|
2138
2311
|
if (answer.accepted) return;
|
|
2139
2312
|
onRefused?.();
|
|
2140
2313
|
if (ed.isDestroyed) {
|
|
@@ -2144,32 +2317,35 @@ function CommentBox({
|
|
|
2144
2317
|
if (isEmptyDoc(ed)) ed.commands.setContent(body);
|
|
2145
2318
|
else ed.commands.insertContentAt(0, body.content ?? []);
|
|
2146
2319
|
ed.commands.focus("end");
|
|
2320
|
+
setRemoved((now) => /* @__PURE__ */ new Set([...now, ...took]));
|
|
2147
2321
|
setFiles((all) => [...sent, ...all]);
|
|
2148
2322
|
setRefused(answer.reason);
|
|
2149
2323
|
});
|
|
2150
2324
|
return true;
|
|
2151
2325
|
}
|
|
2152
2326
|
setSending(true);
|
|
2153
|
-
void answered(send(body, sent)).then((answer) => {
|
|
2327
|
+
void answered(send(body, sent, sentUnder)).then((answer) => {
|
|
2154
2328
|
setSending(false);
|
|
2155
2329
|
if (!answer.accepted) {
|
|
2156
2330
|
setRefused(answer.reason);
|
|
2157
2331
|
return;
|
|
2158
2332
|
}
|
|
2159
2333
|
if (!ed.isDestroyed) ed.commands.clearContent(true);
|
|
2334
|
+
setRemoved(/* @__PURE__ */ new Set());
|
|
2160
2335
|
setFiles((all) => all.filter((f) => !sent.includes(f)));
|
|
2161
2336
|
draft?.clear();
|
|
2162
|
-
onSent?.(body, sent);
|
|
2337
|
+
onSent?.(body, sent, sentUnder);
|
|
2163
2338
|
});
|
|
2164
2339
|
return false;
|
|
2165
2340
|
},
|
|
2166
|
-
[files, showsAtOnce, send, draft, onSent, onRefused]
|
|
2341
|
+
[files, removed, underOf, showsAtOnce, send, draft, onSent, onRefused]
|
|
2167
2342
|
);
|
|
2168
2343
|
save.current = () => {
|
|
2169
2344
|
if (!editor || !edit || sending || uploading) return true;
|
|
2170
2345
|
setRefused(null);
|
|
2171
2346
|
setSending(true);
|
|
2172
|
-
|
|
2347
|
+
const body = editor.getJSON();
|
|
2348
|
+
void edit.onSave(body, files, underOf(body)).catch(() => ({ accepted: false, reason: "try again in a moment" })).then((answer) => {
|
|
2173
2349
|
setSending(false);
|
|
2174
2350
|
if (!answer.accepted) setRefused(answer.reason);
|
|
2175
2351
|
});
|
|
@@ -2190,7 +2366,7 @@ function CommentBox({
|
|
|
2190
2366
|
/* @__PURE__ */ jsx7("p", { className: "text-body-2 text-text-secondary", children: closed.reason })
|
|
2191
2367
|
] });
|
|
2192
2368
|
}
|
|
2193
|
-
const fileCards = files.length > 0 ? /* @__PURE__ */ jsx7(
|
|
2369
|
+
const fileCards = files.length > 0 ? /* @__PURE__ */ jsx7(Fragment3, { children: files.map((f) => /* @__PURE__ */ jsx7(
|
|
2194
2370
|
AttachmentCard,
|
|
2195
2371
|
{
|
|
2196
2372
|
pending: true,
|
|
@@ -2203,6 +2379,12 @@ function CommentBox({
|
|
|
2203
2379
|
},
|
|
2204
2380
|
f.id
|
|
2205
2381
|
)) }) : void 0;
|
|
2382
|
+
const card = reading?.card && !removed.has(reading.card.value) ? reading.card : void 0;
|
|
2383
|
+
const parts = edit ? [] : reading?.parts ?? [];
|
|
2384
|
+
const underBox = card || parts.length > 0 ? /* @__PURE__ */ jsxs5("div", { "data-box-under": true, className: "mt-1 flex flex-col gap-2", children: [
|
|
2385
|
+
card && /* @__PURE__ */ jsx7(CardUnder, { onRemove: () => setRemoved((was) => /* @__PURE__ */ new Set([...was, card.value])), children: card.view }),
|
|
2386
|
+
parts.map((part) => /* @__PURE__ */ jsx7(Fragment2, { children: part.view }, part.key))
|
|
2387
|
+
] }) : void 0;
|
|
2206
2388
|
const refusedLine = refused && /* @__PURE__ */ jsx7(FieldLine, { tone: "error", children: edit ? `Not saved: ${refused}. Your changes are still in the box.` : `Not sent: ${refused}. Your text is back in the box.` });
|
|
2207
2389
|
if (edit) {
|
|
2208
2390
|
return /* @__PURE__ */ jsxs5("div", { className: cn2("flex flex-col gap-1", className), children: [
|
|
@@ -2222,8 +2404,8 @@ function CommentBox({
|
|
|
2222
2404
|
] })
|
|
2223
2405
|
] })
|
|
2224
2406
|
] }),
|
|
2407
|
+
underBox,
|
|
2225
2408
|
sending && /* @__PURE__ */ jsx7(FieldLine, { children: "Saving\u2026" }),
|
|
2226
|
-
" ",
|
|
2227
2409
|
refusedLine
|
|
2228
2410
|
] });
|
|
2229
2411
|
}
|
|
@@ -2248,6 +2430,7 @@ function CommentBox({
|
|
|
2248
2430
|
className: cn2(sending && "[&_[data-composer-editor]]:text-text-muted")
|
|
2249
2431
|
}
|
|
2250
2432
|
),
|
|
2433
|
+
underBox,
|
|
2251
2434
|
upload && /* @__PURE__ */ jsx7(FilePicker, { ref: picker, multiple: true, accept, onPick: attachFiles }),
|
|
2252
2435
|
sending && /* @__PURE__ */ jsx7(FieldLine, { children: "Sending\u2026" }),
|
|
2253
2436
|
uploading && !sending && /* @__PURE__ */ jsx7(FieldLine, { children: "Uploading\u2026 Send waits for the file." }),
|
|
@@ -2258,7 +2441,7 @@ function CommentBox({
|
|
|
2258
2441
|
|
|
2259
2442
|
// src/InlineText.tsx
|
|
2260
2443
|
import { useCallback as useCallback5, useEffect as useEffect5, useImperativeHandle as useImperativeHandle2, useRef as useRef4, useState as useState5 } from "react";
|
|
2261
|
-
import { Extension as
|
|
2444
|
+
import { Extension as Extension11, Node as Node3 } from "@tiptap/core";
|
|
2262
2445
|
import { history, redo, undo } from "@tiptap/pm/history";
|
|
2263
2446
|
import { EditorContent as EditorContent3, useEditor as useEditor2 } from "@tiptap/react";
|
|
2264
2447
|
import { cn as cn3 } from "@estiva-app/ui";
|
|
@@ -2276,7 +2459,7 @@ var Paragraph = Node3.create({
|
|
|
2276
2459
|
renderHTML: () => ["p", 0]
|
|
2277
2460
|
});
|
|
2278
2461
|
var Text = Node3.create({ name: "text" });
|
|
2279
|
-
var Undo =
|
|
2462
|
+
var Undo = Extension11.create({
|
|
2280
2463
|
name: "inlineTextUndo",
|
|
2281
2464
|
addProseMirrorPlugins: () => [history()],
|
|
2282
2465
|
addKeyboardShortcuts() {
|
|
@@ -2376,10 +2559,10 @@ function InlineText({ value, placeholder, label, onCommit, onText, onEnter, vari
|
|
|
2376
2559
|
}
|
|
2377
2560
|
|
|
2378
2561
|
// src/CommentHighlights.ts
|
|
2379
|
-
import { Extension as
|
|
2380
|
-
import { Plugin as
|
|
2381
|
-
import { Decoration as
|
|
2382
|
-
var commentHighlightsKey = new
|
|
2562
|
+
import { Extension as Extension12 } from "@tiptap/core";
|
|
2563
|
+
import { Plugin as Plugin8, PluginKey as PluginKey9 } from "@tiptap/pm/state";
|
|
2564
|
+
import { Decoration as Decoration4, DecorationSet as DecorationSet4 } from "@tiptap/pm/view";
|
|
2565
|
+
var commentHighlightsKey = new PluginKey9("commentHighlights");
|
|
2383
2566
|
var COMMENT_HIGHLIGHT_CLASSES = {
|
|
2384
2567
|
rest: "cursor-pointer rounded-sm bg-warning-muted",
|
|
2385
2568
|
active: "cursor-pointer rounded-sm bg-warning-muted underline decoration-warning-default decoration-2 underline-offset-4"
|
|
@@ -2498,7 +2681,7 @@ function placeOf(doc2, anchor, places = placesIn(doc2)) {
|
|
|
2498
2681
|
if (endAt === -1 || quote.end === "") return reworded;
|
|
2499
2682
|
return { state: "resolved", from: a.starts[startAt], to: b.ends[endAt + quote.end.length - 1], words: true };
|
|
2500
2683
|
}
|
|
2501
|
-
var CommentHighlights =
|
|
2684
|
+
var CommentHighlights = Extension12.create({
|
|
2502
2685
|
name: "commentHighlights",
|
|
2503
2686
|
addOptions() {
|
|
2504
2687
|
return { onSelect: null };
|
|
@@ -2507,7 +2690,7 @@ var CommentHighlights = Extension11.create({
|
|
|
2507
2690
|
const options = this.options;
|
|
2508
2691
|
const editor = this.editor;
|
|
2509
2692
|
return [
|
|
2510
|
-
new
|
|
2693
|
+
new Plugin8({
|
|
2511
2694
|
key: commentHighlightsKey,
|
|
2512
2695
|
state: {
|
|
2513
2696
|
init: () => ({ anchors: [], active: null }),
|
|
@@ -2524,16 +2707,16 @@ var CommentHighlights = Extension11.create({
|
|
|
2524
2707
|
const place2 = placeOf(state.doc, anchor, places);
|
|
2525
2708
|
if (place2.state !== "resolved") return [];
|
|
2526
2709
|
const attrs = { class: anchor.id === active ? COMMENT_HIGHLIGHT_CLASSES.active : COMMENT_HIGHLIGHT_CLASSES.rest, "data-comment-id": anchor.id };
|
|
2527
|
-
if (place2.words) return [
|
|
2710
|
+
if (place2.words) return [Decoration4.inline(place2.from, place2.to, attrs)];
|
|
2528
2711
|
const blocks = [];
|
|
2529
2712
|
state.doc.nodesBetween(place2.from, place2.to, (node, pos) => {
|
|
2530
2713
|
if (pos < place2.from || pos + node.nodeSize > place2.to) return true;
|
|
2531
|
-
blocks.push(
|
|
2714
|
+
blocks.push(Decoration4.node(pos, pos + node.nodeSize, attrs));
|
|
2532
2715
|
return false;
|
|
2533
2716
|
});
|
|
2534
2717
|
return blocks;
|
|
2535
2718
|
});
|
|
2536
|
-
return drawn.length ?
|
|
2719
|
+
return drawn.length ? DecorationSet4.create(state.doc, drawn) : null;
|
|
2537
2720
|
},
|
|
2538
2721
|
handleClick(view, pos) {
|
|
2539
2722
|
const { anchors } = commentHighlightsKey.getState(view.state) ?? { anchors: [] };
|
|
@@ -2658,9 +2841,9 @@ function anchorOfSelection(editor) {
|
|
|
2658
2841
|
}
|
|
2659
2842
|
|
|
2660
2843
|
// src/PastedMarkdown.ts
|
|
2661
|
-
import { Extension as
|
|
2844
|
+
import { Extension as Extension13 } from "@tiptap/core";
|
|
2662
2845
|
import { Slice } from "@tiptap/pm/model";
|
|
2663
|
-
import { Plugin as
|
|
2846
|
+
import { Plugin as Plugin9, PluginKey as PluginKey10 } from "@tiptap/pm/state";
|
|
2664
2847
|
function inTableCell($context) {
|
|
2665
2848
|
for (let depth = $context.depth; depth > 0; depth--) {
|
|
2666
2849
|
const role = $context.node(depth).type.spec.tableRole;
|
|
@@ -2669,7 +2852,7 @@ function inTableCell($context) {
|
|
|
2669
2852
|
return false;
|
|
2670
2853
|
}
|
|
2671
2854
|
var hasTable = (blocks) => blocks.some((block) => block.type === "table" || hasTable(block.content ?? []));
|
|
2672
|
-
var PastedMarkdown =
|
|
2855
|
+
var PastedMarkdown = Extension13.create({
|
|
2673
2856
|
name: "pastedMarkdown",
|
|
2674
2857
|
addOptions() {
|
|
2675
2858
|
return { read: () => void 0 };
|
|
@@ -2677,8 +2860,8 @@ var PastedMarkdown = Extension12.create({
|
|
|
2677
2860
|
addProseMirrorPlugins() {
|
|
2678
2861
|
const options = this.options;
|
|
2679
2862
|
return [
|
|
2680
|
-
new
|
|
2681
|
-
key: new
|
|
2863
|
+
new Plugin9({
|
|
2864
|
+
key: new PluginKey10("pastedMarkdown"),
|
|
2682
2865
|
props: {
|
|
2683
2866
|
// Reached only for a text paste outside code; `plain` is the Shift paste.
|
|
2684
2867
|
clipboardTextParser: (text, $context, plain, view) => {
|
|
@@ -2724,7 +2907,7 @@ import { IconCopy, IconTrash } from "@tabler/icons-react";
|
|
|
2724
2907
|
import { BlockHandle, blockAtY } from "@estiva-app/ui";
|
|
2725
2908
|
import { Selection } from "@tiptap/pm/state";
|
|
2726
2909
|
import { MenuItem as MenuItem2, MenuSub } from "@estiva-app/ui";
|
|
2727
|
-
import { Fragment as
|
|
2910
|
+
import { Fragment as Fragment4, jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
2728
2911
|
function editorBlocks(view) {
|
|
2729
2912
|
const out = [];
|
|
2730
2913
|
view.state.doc.forEach((node, pos) => {
|
|
@@ -2791,7 +2974,7 @@ function EditorBlockHandle({ editor, turnInto = turnIntoRows, actions, children,
|
|
|
2791
2974
|
const node = pos === void 0 ? null : editor.state.doc.nodeAt(pos);
|
|
2792
2975
|
if (pos === void 0 || !node) return null;
|
|
2793
2976
|
const turnRows = typeof turnInto === "function" ? turnInto(node, editor) : node.isTextblock ? turnInto : [];
|
|
2794
|
-
return /* @__PURE__ */ jsxs7(
|
|
2977
|
+
return /* @__PURE__ */ jsxs7(Fragment4, { children: [
|
|
2795
2978
|
turnRows.length > 0 && /* @__PURE__ */ jsx9(MenuSub, { label: "Turn into", children: turnRows.map((row) => /* @__PURE__ */ jsx9(
|
|
2796
2979
|
MenuItem2,
|
|
2797
2980
|
{
|
|
@@ -2934,18 +3117,18 @@ function turnIntoRows(node, editor) {
|
|
|
2934
3117
|
|
|
2935
3118
|
// src/EditorTableControls.tsx
|
|
2936
3119
|
import { useCallback as useCallback6, useEffect as useEffect6, useRef as useRef5, useState as useState6 } from "react";
|
|
2937
|
-
import { TextSelection as
|
|
3120
|
+
import { TextSelection as TextSelection3 } from "@tiptap/pm/state";
|
|
2938
3121
|
import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, deleteColumn, deleteRow, deleteTable, toggleHeader } from "@tiptap/pm/tables";
|
|
2939
3122
|
import { IconCheck as IconCheck2, IconColumnInsertLeft, IconColumnInsertRight, IconGripHorizontal, IconGripVertical, IconPlus, IconRowInsertBottom, IconRowInsertTop, IconTableRow, IconTrash as IconTrash2 } from "@tabler/icons-react";
|
|
2940
3123
|
import { cn as cn4 } from "@estiva-app/ui";
|
|
2941
3124
|
import { IconButton as IconButton2 } from "@estiva-app/ui";
|
|
2942
3125
|
import { Menu, MenuItem as MenuItem3, MenuSeparator as MenuSeparator2 } from "@estiva-app/ui";
|
|
2943
|
-
import { Fragment as
|
|
3126
|
+
import { Fragment as Fragment5, jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
2944
3127
|
function inCell(editor, cell, command) {
|
|
2945
3128
|
const { view } = editor;
|
|
2946
3129
|
if (!view.dom.contains(cell)) return false;
|
|
2947
3130
|
const at = view.posAtDOM(cell, 0);
|
|
2948
|
-
view.dispatch(view.state.tr.setSelection(
|
|
3131
|
+
view.dispatch(view.state.tr.setSelection(TextSelection3.near(view.state.doc.resolve(at))));
|
|
2949
3132
|
const done = command(view.state, view.dispatch, view);
|
|
2950
3133
|
editor.commands.focus();
|
|
2951
3134
|
return done;
|
|
@@ -3040,7 +3223,7 @@ function EditorTableControls({ editor, children, className }) {
|
|
|
3040
3223
|
},
|
|
3041
3224
|
children: [
|
|
3042
3225
|
children,
|
|
3043
|
-
shown && editor && /* @__PURE__ */ jsxs8(
|
|
3226
|
+
shown && editor && /* @__PURE__ */ jsxs8(Fragment5, { children: [
|
|
3044
3227
|
/* @__PURE__ */ jsx10("div", { "data-table-control": true, className: cn4(HANDLE_BOX, "absolute -translate-x-1/2 -translate-y-1/2"), style: { left: shown.tableBox.left, top: shown.rowBox.top + shown.rowBox.height / 2 }, children: /* @__PURE__ */ jsxs8(
|
|
3045
3228
|
Menu,
|
|
3046
3229
|
{
|
|
@@ -3048,7 +3231,7 @@ function EditorTableControls({ editor, children, className }) {
|
|
|
3048
3231
|
onOpenChange: (open) => setMenu(open ? "row" : null),
|
|
3049
3232
|
trigger: /* @__PURE__ */ jsx10(IconButton2, { "aria-label": "Row menu", tooltip: "Row", className: "h-6 w-4 p-0", children: /* @__PURE__ */ jsx10(IconGripVertical, { size: 16, stroke: 1.5 }) }),
|
|
3050
3233
|
children: [
|
|
3051
|
-
shown.row.rowIndex === 0 && /* @__PURE__ */ jsxs8(
|
|
3234
|
+
shown.row.rowIndex === 0 && /* @__PURE__ */ jsxs8(Fragment5, { children: [
|
|
3052
3235
|
/* @__PURE__ */ jsx10(
|
|
3053
3236
|
MenuItem3,
|
|
3054
3237
|
{
|
|
@@ -3090,6 +3273,340 @@ function EditorTableControls({ editor, children, className }) {
|
|
|
3090
3273
|
}
|
|
3091
3274
|
);
|
|
3092
3275
|
}
|
|
3276
|
+
|
|
3277
|
+
// src/DocumentEditor.tsx
|
|
3278
|
+
import { useCallback as useCallback7, useEffect as useEffect7, useRef as useRef6, useState as useState7 } from "react";
|
|
3279
|
+
import { TextSelection as TextSelection4 } from "@tiptap/pm/state";
|
|
3280
|
+
import { EditorContent as EditorContent4, useEditor as useEditor3, useEditorState as useEditorState2 } from "@tiptap/react";
|
|
3281
|
+
import { TableKit } from "@tiptap/extension-table";
|
|
3282
|
+
import { IconMessagePlus } from "@tabler/icons-react";
|
|
3283
|
+
import { Button as Button2 } from "@estiva-app/ui";
|
|
3284
|
+
import { FieldLine as FieldLine2 } from "@estiva-app/ui";
|
|
3285
|
+
import { FilePicker as FilePicker2 } from "@estiva-app/ui";
|
|
3286
|
+
import { richTextClassName as richTextClassName2 } from "@estiva-app/ui";
|
|
3287
|
+
import { Fragment as Fragment6, jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
3288
|
+
function heldDocument(hold, key4) {
|
|
3289
|
+
const text = hold && key4 ? hold.text(key4) : void 0;
|
|
3290
|
+
if (!text) return null;
|
|
3291
|
+
try {
|
|
3292
|
+
const doc2 = JSON.parse(text);
|
|
3293
|
+
return doc2?.type === "doc" ? doc2 : null;
|
|
3294
|
+
} catch {
|
|
3295
|
+
return null;
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
function DocumentEditor({
|
|
3299
|
+
value,
|
|
3300
|
+
format,
|
|
3301
|
+
codec,
|
|
3302
|
+
onCommit,
|
|
3303
|
+
label,
|
|
3304
|
+
placeholder,
|
|
3305
|
+
readOnly = false,
|
|
3306
|
+
changedBy = null,
|
|
3307
|
+
onLeftUnsaved,
|
|
3308
|
+
hold,
|
|
3309
|
+
holdKey,
|
|
3310
|
+
references,
|
|
3311
|
+
mentions,
|
|
3312
|
+
linkChips,
|
|
3313
|
+
upload,
|
|
3314
|
+
readMarkdown,
|
|
3315
|
+
table = true,
|
|
3316
|
+
onCommentOnSelection,
|
|
3317
|
+
blockRows,
|
|
3318
|
+
referenceView,
|
|
3319
|
+
attachmentView,
|
|
3320
|
+
cards,
|
|
3321
|
+
wrap,
|
|
3322
|
+
onEditor,
|
|
3323
|
+
extensions = []
|
|
3324
|
+
}) {
|
|
3325
|
+
const [failed, setFailed] = useState7(false);
|
|
3326
|
+
const [focused, setFocused] = useState7(false);
|
|
3327
|
+
const [uploadError, setUploadError] = useState7(null);
|
|
3328
|
+
const latest = useRef6({ value, format, codec, hold, references, mentions, upload, readMarkdown, onLeftUnsaved });
|
|
3329
|
+
useEffect7(() => {
|
|
3330
|
+
latest.current = { value, format, codec, hold, references, mentions, upload, readMarkdown, onLeftUnsaved };
|
|
3331
|
+
});
|
|
3332
|
+
const ended = () => latest.current.hold?.ended() ?? false;
|
|
3333
|
+
const [base, setBase] = useState7(value);
|
|
3334
|
+
const saved = useRef6(value);
|
|
3335
|
+
const [superseded, setSuperseded] = useState7(null);
|
|
3336
|
+
const own = useRef6(/* @__PURE__ */ new Set());
|
|
3337
|
+
const [saving, setSaving] = useState7(false);
|
|
3338
|
+
const committing = useRef6(false);
|
|
3339
|
+
const [held] = useState7(() => {
|
|
3340
|
+
const doc2 = heldDocument(hold, holdKey);
|
|
3341
|
+
try {
|
|
3342
|
+
return doc2 && codec.write(doc2).value !== value ? doc2 : null;
|
|
3343
|
+
} catch {
|
|
3344
|
+
return null;
|
|
3345
|
+
}
|
|
3346
|
+
});
|
|
3347
|
+
const [restored, setRestored] = useState7(held !== null);
|
|
3348
|
+
const typed = useRef6(held);
|
|
3349
|
+
const again = useRef6(false);
|
|
3350
|
+
const left = useRef6(false);
|
|
3351
|
+
const picking = useRef6(false);
|
|
3352
|
+
const picker = useRef6(null);
|
|
3353
|
+
const save = useCallback7(
|
|
3354
|
+
async (doc2) => {
|
|
3355
|
+
if (!doc2 || readOnly || ended()) return;
|
|
3356
|
+
if (committing.current) {
|
|
3357
|
+
again.current = true;
|
|
3358
|
+
return;
|
|
3359
|
+
}
|
|
3360
|
+
const next = latest.current.codec.write(doc2);
|
|
3361
|
+
if (next.value === saved.current) return;
|
|
3362
|
+
committing.current = true;
|
|
3363
|
+
setSaving(true);
|
|
3364
|
+
const replaced = latest.current.value;
|
|
3365
|
+
const editedFrom = saved.current;
|
|
3366
|
+
try {
|
|
3367
|
+
const ok = await onCommit(next.value, next.contentFormat, editedFrom);
|
|
3368
|
+
if (ok) {
|
|
3369
|
+
saved.current = next.value;
|
|
3370
|
+
shown.current = next.value;
|
|
3371
|
+
own.current.add(next.value);
|
|
3372
|
+
setSuperseded(replaced);
|
|
3373
|
+
setBase(next.value);
|
|
3374
|
+
setRestored(false);
|
|
3375
|
+
const store = latest.current.hold;
|
|
3376
|
+
if (store && holdKey && !store.ended()) store.release(holdKey);
|
|
3377
|
+
}
|
|
3378
|
+
if (left.current) {
|
|
3379
|
+
if (!ok && !ended()) latest.current.onLeftUnsaved?.();
|
|
3380
|
+
} else setFailed(!ok);
|
|
3381
|
+
} catch {
|
|
3382
|
+
if (left.current) {
|
|
3383
|
+
if (!ended()) latest.current.onLeftUnsaved?.();
|
|
3384
|
+
} else setFailed(true);
|
|
3385
|
+
} finally {
|
|
3386
|
+
committing.current = false;
|
|
3387
|
+
setSaving(false);
|
|
3388
|
+
if (again.current) {
|
|
3389
|
+
again.current = false;
|
|
3390
|
+
if (!ended()) void latestSave.current(typed.current);
|
|
3391
|
+
}
|
|
3392
|
+
}
|
|
3393
|
+
},
|
|
3394
|
+
[onCommit, holdKey, readOnly]
|
|
3395
|
+
);
|
|
3396
|
+
const holds = !!hold;
|
|
3397
|
+
useEffect7(() => {
|
|
3398
|
+
const store = latest.current.hold;
|
|
3399
|
+
if (!holds || !store || !holdKey) return;
|
|
3400
|
+
return store.register(holdKey, () => {
|
|
3401
|
+
const doc2 = typed.current;
|
|
3402
|
+
return doc2 && latest.current.codec.write(doc2).value !== saved.current ? JSON.stringify(doc2) : void 0;
|
|
3403
|
+
});
|
|
3404
|
+
}, [holdKey, holds]);
|
|
3405
|
+
const latestSave = useRef6(save);
|
|
3406
|
+
useEffect7(() => {
|
|
3407
|
+
latestSave.current = save;
|
|
3408
|
+
}, [save]);
|
|
3409
|
+
const shown = useRef6(value);
|
|
3410
|
+
const openPicker = () => {
|
|
3411
|
+
picking.current = true;
|
|
3412
|
+
const released = () => {
|
|
3413
|
+
picking.current = false;
|
|
3414
|
+
window.removeEventListener("focus", released);
|
|
3415
|
+
};
|
|
3416
|
+
window.addEventListener("focus", released);
|
|
3417
|
+
picker.current?.click();
|
|
3418
|
+
};
|
|
3419
|
+
const pickFile = useRef6(openPicker);
|
|
3420
|
+
pickFile.current = openPicker;
|
|
3421
|
+
const attach = async (chosen) => {
|
|
3422
|
+
const uploadOne = latest.current.upload;
|
|
3423
|
+
if (!uploadOne) return;
|
|
3424
|
+
setUploadError(null);
|
|
3425
|
+
try {
|
|
3426
|
+
for (const file of chosen) {
|
|
3427
|
+
const attrs = await uploadOne(file);
|
|
3428
|
+
if (!editor || editor.isDestroyed) return;
|
|
3429
|
+
editor.chain().focus().insertContent({ type: "attachment", attrs }).run();
|
|
3430
|
+
}
|
|
3431
|
+
} catch (error) {
|
|
3432
|
+
setUploadError(error instanceof Error ? error.message : String(error));
|
|
3433
|
+
}
|
|
3434
|
+
};
|
|
3435
|
+
const attachTo = useRef6(attach);
|
|
3436
|
+
attachTo.current = attach;
|
|
3437
|
+
const editor = useEditor3(
|
|
3438
|
+
{
|
|
3439
|
+
extensions: [
|
|
3440
|
+
DocumentKit.configure({
|
|
3441
|
+
strike: false,
|
|
3442
|
+
heading: { levels: [1, 2, 3] },
|
|
3443
|
+
dropcursor: blockDropCursor,
|
|
3444
|
+
codeBlock: false,
|
|
3445
|
+
// A link on words is made by pasting a URL over them or by the strip's Link, and opens on a click, as a bare
|
|
3446
|
+
// address does — through `BareLinks`, which opens only a followable address and never hands the tab this window;
|
|
3447
|
+
// Tiptap's own click opens without that. A bare address stays text: a link made on it by typing would change what is saved.
|
|
3448
|
+
link: { openOnClick: false, shouldAutoLink: () => false, HTMLAttributes: LINK_MARK_ATTRIBUTES }
|
|
3449
|
+
}),
|
|
3450
|
+
PasteOverWords,
|
|
3451
|
+
KeptSelection,
|
|
3452
|
+
BareLinks,
|
|
3453
|
+
CodeBlockColours,
|
|
3454
|
+
TableKit.configure({ table: { resizable: false } }),
|
|
3455
|
+
BlockId,
|
|
3456
|
+
Checklist,
|
|
3457
|
+
Callout,
|
|
3458
|
+
ReferenceNode.configure({ view: referenceView ?? null }),
|
|
3459
|
+
// The card a chip asks for, after its line (SPEC §13.3); drawn by the app's `cards`.
|
|
3460
|
+
ReferenceCards,
|
|
3461
|
+
// A click on a chip offers Open and its card.
|
|
3462
|
+
ReferenceMenu,
|
|
3463
|
+
UnknownBlock,
|
|
3464
|
+
AttachmentNode.configure({ view: attachmentView ?? null }),
|
|
3465
|
+
SlashCommands.configure({ sections: slashSections({ table, file: !!upload, link: !!references, pickFile }) }),
|
|
3466
|
+
...references ? [
|
|
3467
|
+
ReferenceTrigger.configure({
|
|
3468
|
+
items: () => [],
|
|
3469
|
+
sections: (query) => latest.current.references?.sections(query) ?? [],
|
|
3470
|
+
subscribe: (listener) => latest.current.references?.subscribe?.(listener) ?? (() => {
|
|
3471
|
+
}),
|
|
3472
|
+
nodeName: "reference",
|
|
3473
|
+
ariaLabel: references.ariaLabel,
|
|
3474
|
+
sectionLabel: references.sectionLabel,
|
|
3475
|
+
icon: references.icon ?? null
|
|
3476
|
+
})
|
|
3477
|
+
] : [],
|
|
3478
|
+
...mentions ? [PersonReference.configure({ people: () => latest.current.mentions?.people() ?? [], uriOf: (person) => latest.current.mentions?.uriOf(person) ?? null })] : [],
|
|
3479
|
+
...linkChips ? [LinkChips.configure(linkChips)] : [],
|
|
3480
|
+
...upload ? [
|
|
3481
|
+
// A pasted picture is placed as `/` File places one; text on the clipboard stays text.
|
|
3482
|
+
PastedImages.configure({
|
|
3483
|
+
onImages: (pasted) => {
|
|
3484
|
+
if (!latest.current.upload) return false;
|
|
3485
|
+
void attachTo.current(pasted);
|
|
3486
|
+
return true;
|
|
3487
|
+
}
|
|
3488
|
+
})
|
|
3489
|
+
] : [],
|
|
3490
|
+
// Markdown pasted as plain text lands as the blocks it spells, tables included.
|
|
3491
|
+
...readMarkdown ? [PastedMarkdown.configure({ read: (text) => latest.current.readMarkdown?.(text) })] : [],
|
|
3492
|
+
// Where each comment is, drawn as a decoration, so a save never carries it.
|
|
3493
|
+
...onCommentOnSelection ? [CommentHighlights] : [],
|
|
3494
|
+
...extensions
|
|
3495
|
+
],
|
|
3496
|
+
// Made once. A value coming back must not rebuild the editor under the caret; see the effect below.
|
|
3497
|
+
content: held ?? codec.read(value, format),
|
|
3498
|
+
editable: !readOnly,
|
|
3499
|
+
editorProps: {
|
|
3500
|
+
// Focusable when read only too: the selection strip, and so Comment on its words, shows only in a focused view.
|
|
3501
|
+
attributes: { "aria-label": label, role: "textbox", "aria-multiline": "true", tabindex: "0", class: richTextClassName2("default", "outline-none") },
|
|
3502
|
+
handleKeyDown: (view, event) => {
|
|
3503
|
+
if (event.key !== "Escape") return false;
|
|
3504
|
+
if (isSuggestionOpen() || isReferenceMenuOpen(view.state)) return false;
|
|
3505
|
+
const { selection, tr } = view.state;
|
|
3506
|
+
if (!selection.empty) {
|
|
3507
|
+
view.dispatch(tr.setSelection(TextSelection4.create(tr.doc, selection.to)));
|
|
3508
|
+
return true;
|
|
3509
|
+
}
|
|
3510
|
+
view.dom.blur();
|
|
3511
|
+
return true;
|
|
3512
|
+
}
|
|
3513
|
+
},
|
|
3514
|
+
onUpdate: ({ editor: e, transaction }) => {
|
|
3515
|
+
typed.current = e.getJSON();
|
|
3516
|
+
if (isChecklistTick(transaction)) void latestSave.current(typed.current);
|
|
3517
|
+
},
|
|
3518
|
+
onFocus: () => setFocused(true),
|
|
3519
|
+
onBlur: () => {
|
|
3520
|
+
setFocused(false);
|
|
3521
|
+
if (picking.current) return;
|
|
3522
|
+
void latestSave.current(typed.current);
|
|
3523
|
+
}
|
|
3524
|
+
},
|
|
3525
|
+
[]
|
|
3526
|
+
);
|
|
3527
|
+
const arrived = value !== base && value !== superseded && !own.current.has(value);
|
|
3528
|
+
if (arrived && (readOnly || !focused && !saving && !failed && !restored)) {
|
|
3529
|
+
own.current.clear();
|
|
3530
|
+
setBase(value);
|
|
3531
|
+
}
|
|
3532
|
+
const waiting = arrived && !readOnly && (focused || failed || restored);
|
|
3533
|
+
useEffect7(() => {
|
|
3534
|
+
saved.current = base;
|
|
3535
|
+
if (!editor || editor.isDestroyed || base === shown.current) return;
|
|
3536
|
+
editor.commands.setContent(latest.current.codec.read(base, latest.current.format), { emitUpdate: false });
|
|
3537
|
+
shown.current = base;
|
|
3538
|
+
typed.current = null;
|
|
3539
|
+
}, [editor, base]);
|
|
3540
|
+
useEffect7(() => {
|
|
3541
|
+
if (editor && !editor.isDestroyed && editor.isEditable === readOnly) editor.setEditable(!readOnly, false);
|
|
3542
|
+
}, [editor, readOnly]);
|
|
3543
|
+
const empty = useEditorState2({ editor, selector: ({ editor: ed }) => !ed || ed.isEmpty });
|
|
3544
|
+
const load = () => {
|
|
3545
|
+
setBase(latest.current.value);
|
|
3546
|
+
setFailed(false);
|
|
3547
|
+
setRestored(false);
|
|
3548
|
+
};
|
|
3549
|
+
useEffect7(
|
|
3550
|
+
() => () => {
|
|
3551
|
+
left.current = true;
|
|
3552
|
+
if (!ended()) void latestSave.current(typed.current);
|
|
3553
|
+
},
|
|
3554
|
+
[]
|
|
3555
|
+
);
|
|
3556
|
+
useEffect7(() => {
|
|
3557
|
+
onEditor?.(editor);
|
|
3558
|
+
return () => onEditor?.(null);
|
|
3559
|
+
}, [editor, onEditor]);
|
|
3560
|
+
const who = changedBy?.name ?? "Someone";
|
|
3561
|
+
const drawn = /* @__PURE__ */ jsxs9("div", { className: "flex flex-col gap-1", children: [
|
|
3562
|
+
/* @__PURE__ */ jsxs9(EditorBlockHandle, { editor, actions: blockRows, children: [
|
|
3563
|
+
/* @__PURE__ */ jsx11(EditorTableControls, { editor, children: /* @__PURE__ */ jsx11(EditorContent4, { editor, className: "-mx-2 cursor-text px-2 py-1", "data-document-editor": "" }) }),
|
|
3564
|
+
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
|
+
] }),
|
|
3566
|
+
cards?.(editor),
|
|
3567
|
+
(!readOnly || onCommentOnSelection) && /* @__PURE__ */ jsx11(
|
|
3568
|
+
SelectionToolbar,
|
|
3569
|
+
{
|
|
3570
|
+
editor,
|
|
3571
|
+
marks: readOnly ? [] : ["bold", "italic", "underline", "code"],
|
|
3572
|
+
link: !readOnly,
|
|
3573
|
+
actions: onCommentOnSelection ? [
|
|
3574
|
+
{
|
|
3575
|
+
label: "Comment",
|
|
3576
|
+
icon: /* @__PURE__ */ jsx11(IconMessagePlus, { size: 16, stroke: 1.5 }),
|
|
3577
|
+
run: (ed) => {
|
|
3578
|
+
const anchor = anchorOfSelection(ed);
|
|
3579
|
+
if (!anchor) return;
|
|
3580
|
+
ed.commands.setTextSelection(ed.state.selection.to);
|
|
3581
|
+
onCommentOnSelection(anchor);
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
] : []
|
|
3585
|
+
}
|
|
3586
|
+
),
|
|
3587
|
+
/* @__PURE__ */ jsx11(ReferenceMenuView, { editor }),
|
|
3588
|
+
/* @__PURE__ */ jsx11(FilePicker2, { ref: picker, multiple: true, onPick: (files) => void attach(files) }),
|
|
3589
|
+
waiting && /* @__PURE__ */ jsxs9(FieldLine2, { tone: "helper", children: [
|
|
3590
|
+
`${who} saved a newer version.`,
|
|
3591
|
+
" ",
|
|
3592
|
+
/* @__PURE__ */ jsx11(Button2, { variant: "muted", size: "small", onMouseDown: (event) => event.preventDefault(), onClick: load, children: "Load it" }),
|
|
3593
|
+
" ",
|
|
3594
|
+
"(replaces your changes)"
|
|
3595
|
+
] }),
|
|
3596
|
+
uploadError && /* @__PURE__ */ jsx11(FieldLine2, { tone: "error", children: uploadError }),
|
|
3597
|
+
failed && /* @__PURE__ */ jsx11(FieldLine2, { tone: "error", children: "Could not save. Your text is still here." })
|
|
3598
|
+
] });
|
|
3599
|
+
return /* @__PURE__ */ jsx11(Fragment6, { children: wrap ? wrap(drawn, editor) : drawn });
|
|
3600
|
+
}
|
|
3601
|
+
function slashSections({ table, file, link, pickFile }) {
|
|
3602
|
+
const insert = [
|
|
3603
|
+
// Three by three with a header row, as every app's Insert → Table makes it.
|
|
3604
|
+
...table ? [{ key: "insert-table", row: { label: "Table" }, run: (editor) => void editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run() }] : [],
|
|
3605
|
+
...file ? [{ key: "insert-file", row: { label: "File" }, keywords: ["attach", "upload"], run: () => pickFile.current() }] : [],
|
|
3606
|
+
...link ? [{ key: "insert-link", row: { label: "Link to a file", shortcut: "[" }, keywords: ["[", "link", "reference"], run: typeTrigger("[") }] : []
|
|
3607
|
+
];
|
|
3608
|
+
return [formatSection("block"), ...insert.length > 0 ? [{ label: "Insert", commands: insert }] : []];
|
|
3609
|
+
}
|
|
3093
3610
|
export {
|
|
3094
3611
|
AttachmentNode,
|
|
3095
3612
|
BlockId,
|
|
@@ -3102,6 +3619,7 @@ export {
|
|
|
3102
3619
|
CommentHighlights,
|
|
3103
3620
|
ComposeBox,
|
|
3104
3621
|
ComposeKeys,
|
|
3622
|
+
DocumentEditor,
|
|
3105
3623
|
EditorBlockHandle,
|
|
3106
3624
|
EditorTableControls,
|
|
3107
3625
|
FORMATS,
|
|
@@ -3111,6 +3629,7 @@ export {
|
|
|
3111
3629
|
PastedImages,
|
|
3112
3630
|
PastedMarkdown,
|
|
3113
3631
|
PersonMention,
|
|
3632
|
+
PersonReference,
|
|
3114
3633
|
ReferenceCards,
|
|
3115
3634
|
ReferenceMenu,
|
|
3116
3635
|
ReferenceMenuView,
|