@estiva-app/ui 0.100.0 → 0.102.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/AskedBlocks.d.ts +30 -0
- package/dist/AskedBlocks.d.ts.map +1 -0
- package/dist/DeletedNotice.d.ts +17 -0
- package/dist/DeletedNotice.d.ts.map +1 -0
- package/dist/DocumentEditor.d.ts +39 -6
- package/dist/DocumentEditor.d.ts.map +1 -1
- package/dist/IconButton.d.ts +7 -1
- package/dist/IconButton.d.ts.map +1 -1
- package/dist/LinkRow.d.ts +7 -10
- package/dist/LinkRow.d.ts.map +1 -1
- package/dist/NoAccessNotice.d.ts +13 -0
- package/dist/NoAccessNotice.d.ts.map +1 -0
- package/dist/PartCard.d.ts +3 -3
- package/dist/PartCard.d.ts.map +1 -1
- package/dist/editor.d.ts +1 -1
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +311 -8
- package/dist/editor.js.map +4 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +433 -389
- package/dist/index.js.map +4 -4
- package/dist/linked.d.ts +2 -2
- package/dist/linked.d.ts.map +1 -1
- package/dist/linkedFrom.d.ts.map +1 -1
- package/package.json +1 -1
- package/registry.json +95 -7
- package/src/AskedBlocks.ts +158 -0
- package/src/DeletedNotice.mdx +43 -0
- package/src/DeletedNotice.stories.tsx +29 -0
- package/src/DeletedNotice.test.tsx +46 -0
- package/src/DeletedNotice.tsx +47 -0
- package/src/DocumentEditor.mdx +5 -1
- package/src/DocumentEditor.stories.tsx +84 -0
- package/src/DocumentEditor.test.tsx +188 -0
- package/src/DocumentEditor.tsx +294 -14
- package/src/IconButton.mdx +4 -0
- package/src/IconButton.stories.tsx +28 -1
- package/src/IconButton.test.tsx +30 -0
- package/src/IconButton.tsx +22 -1
- package/src/LinkCard.test.tsx +4 -6
- package/src/LinkCard.tsx +1 -1
- package/src/LinkRow.mdx +1 -1
- package/src/LinkRow.stories.tsx +3 -3
- package/src/LinkRow.test.tsx +2 -2
- package/src/LinkRow.tsx +11 -20
- package/src/NoAccessNotice.mdx +40 -0
- package/src/NoAccessNotice.stories.tsx +17 -0
- package/src/NoAccessNotice.tsx +18 -0
- package/src/PartCard.test.tsx +2 -2
- package/src/PartCard.tsx +5 -4
- package/src/Toolbar.test.tsx +15 -0
- package/src/UnreadDot.mdx +3 -0
- package/src/editor.ts +1 -0
- package/src/index.ts +2 -0
- package/src/linked.ts +2 -2
- package/src/linkedFrom.test.tsx +4 -7
- package/src/linkedFrom.ts +0 -2
- package/src/registry/registry.test.ts +5 -4
- package/stories/Choosing.mdx +2 -0
package/dist/editor.js
CHANGED
|
@@ -3593,16 +3593,223 @@ function EditorTableControls({ editor, children, className }) {
|
|
|
3593
3593
|
|
|
3594
3594
|
// src/DocumentEditor.tsx
|
|
3595
3595
|
import { useCallback as useCallback7, useEffect as useEffect7, useRef as useRef6, useState as useState6 } from "react";
|
|
3596
|
+
import { createPortal } from "react-dom";
|
|
3596
3597
|
import { TextSelection as TextSelection4 } from "@tiptap/pm/state";
|
|
3597
3598
|
import { EditorContent as EditorContent3, useEditor as useEditor2, useEditorState as useEditorState2 } from "@tiptap/react";
|
|
3598
3599
|
import { TableKit } from "@tiptap/extension-table";
|
|
3599
|
-
import { IconMessagePlus } from "@tabler/icons-react";
|
|
3600
|
+
import { IconCheck as IconCheck3, IconCopy as IconCopy2, IconMessagePlus } from "@tabler/icons-react";
|
|
3601
|
+
|
|
3602
|
+
// src/AskedBlocks.ts
|
|
3603
|
+
import { Extension as Extension14 } from "@tiptap/core";
|
|
3604
|
+
import { Plugin as Plugin10, PluginKey as PluginKey11 } from "@tiptap/pm/state";
|
|
3605
|
+
import { Decoration as Decoration6, DecorationSet as DecorationSet6 } from "@tiptap/pm/view";
|
|
3606
|
+
var askedBlocksKey = new PluginKey11("askedBlocks");
|
|
3607
|
+
var ASKED_BLOCK_CLASSES = {
|
|
3608
|
+
block: "relative -ml-3 pl-3",
|
|
3609
|
+
bar: "absolute left-0 top-0 h-full w-0.5 bg-accent-primary",
|
|
3610
|
+
beside: "hidden md:float-right md:ml-3 md:block md:w-64",
|
|
3611
|
+
under: "mt-2 block md:hidden"
|
|
3612
|
+
};
|
|
3613
|
+
var newBar = () => {
|
|
3614
|
+
const bar = document.createElement("span");
|
|
3615
|
+
bar.className = ASKED_BLOCK_CLASSES.bar;
|
|
3616
|
+
bar.dataset.askedBar = "";
|
|
3617
|
+
bar.contentEditable = "false";
|
|
3618
|
+
return bar;
|
|
3619
|
+
};
|
|
3620
|
+
function wordsHeight(block) {
|
|
3621
|
+
const top = block.getBoundingClientRect().top;
|
|
3622
|
+
let bottom = null;
|
|
3623
|
+
let glyphs = 0;
|
|
3624
|
+
const range = document.createRange();
|
|
3625
|
+
const walker = document.createTreeWalker(block, NodeFilter.SHOW_TEXT);
|
|
3626
|
+
for (let text = walker.nextNode(); text; text = walker.nextNode()) {
|
|
3627
|
+
if (text.parentElement?.closest(".ProseMirror-widget")) continue;
|
|
3628
|
+
range.selectNodeContents(text);
|
|
3629
|
+
for (const box of range.getClientRects()) {
|
|
3630
|
+
if (box.height > 0 && (bottom === null || box.bottom > bottom)) [bottom, glyphs] = [box.bottom, box.height];
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
if (bottom === null) return null;
|
|
3634
|
+
const line = parseFloat(getComputedStyle(block).lineHeight);
|
|
3635
|
+
return bottom - top + (line > glyphs ? (line - glyphs) / 2 : 0);
|
|
3636
|
+
}
|
|
3637
|
+
function measureWords(root) {
|
|
3638
|
+
for (const block of root.querySelectorAll("[data-asked-block]")) {
|
|
3639
|
+
const bar = block.querySelector("[data-asked-bar]");
|
|
3640
|
+
if (!bar) continue;
|
|
3641
|
+
const height = typeof document.createRange().getClientRects === "function" ? wordsHeight(block) : null;
|
|
3642
|
+
const next = height === null ? "" : `${height}px`;
|
|
3643
|
+
if (bar.style.height !== next) bar.style.height = next;
|
|
3644
|
+
}
|
|
3645
|
+
}
|
|
3646
|
+
function blockAt(doc2, id) {
|
|
3647
|
+
let found = null;
|
|
3648
|
+
doc2.descendants((node, pos) => {
|
|
3649
|
+
if (found) return false;
|
|
3650
|
+
if (node.attrs.blockId === id) {
|
|
3651
|
+
found = { node, pos };
|
|
3652
|
+
return false;
|
|
3653
|
+
}
|
|
3654
|
+
return true;
|
|
3655
|
+
});
|
|
3656
|
+
return found;
|
|
3657
|
+
}
|
|
3658
|
+
var AskedBlocks = Extension14.create({
|
|
3659
|
+
name: "askedBlocks",
|
|
3660
|
+
addProseMirrorPlugins() {
|
|
3661
|
+
return [
|
|
3662
|
+
new Plugin10({
|
|
3663
|
+
key: askedBlocksKey,
|
|
3664
|
+
state: {
|
|
3665
|
+
init: () => ({ ids: [], slot: null }),
|
|
3666
|
+
apply(tr, previous) {
|
|
3667
|
+
return tr.getMeta(askedBlocksKey) ?? previous;
|
|
3668
|
+
}
|
|
3669
|
+
},
|
|
3670
|
+
props: {
|
|
3671
|
+
decorations(state) {
|
|
3672
|
+
const { ids, slot } = askedBlocksKey.getState(state) ?? { ids: [], slot: null };
|
|
3673
|
+
if (!slot || ids.length === 0) return null;
|
|
3674
|
+
const drawn = [];
|
|
3675
|
+
for (const id of ids) {
|
|
3676
|
+
const at = blockAt(state.doc, id);
|
|
3677
|
+
if (!at) continue;
|
|
3678
|
+
const end = at.pos + at.node.nodeSize;
|
|
3679
|
+
drawn.push(Decoration6.node(at.pos, end, { class: ASKED_BLOCK_CLASSES.block, "data-asked-block": id }));
|
|
3680
|
+
const widget = { ignoreSelection: true, stopEvent: () => true };
|
|
3681
|
+
const widgetAt = (pos, where, side) => Decoration6.widget(pos, () => slot(id, where), { ...widget, key: `asked-${id}-${where}`, side });
|
|
3682
|
+
drawn.push(
|
|
3683
|
+
Decoration6.widget(at.pos + 1, newBar, { ...widget, key: `asked-${id}-bar`, side: -2 }),
|
|
3684
|
+
widgetAt(at.pos + 1, "beside", -1),
|
|
3685
|
+
widgetAt(end, "under", 1)
|
|
3686
|
+
);
|
|
3687
|
+
}
|
|
3688
|
+
return drawn.length ? DecorationSet6.create(state.doc, drawn) : null;
|
|
3689
|
+
}
|
|
3690
|
+
},
|
|
3691
|
+
// The bar's height, again whenever the text, the editor's width or a card (drawn after the block) changes it.
|
|
3692
|
+
// Nothing is watched or measured while no block asks: typing costs what it did.
|
|
3693
|
+
view(view) {
|
|
3694
|
+
const measure = () => measureWords(view.dom);
|
|
3695
|
+
const resized = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measure);
|
|
3696
|
+
let watched = [];
|
|
3697
|
+
return {
|
|
3698
|
+
update() {
|
|
3699
|
+
const asking = (askedBlocksKey.getState(view.state)?.ids.length ?? 0) > 0;
|
|
3700
|
+
const blocks = asking ? [...view.dom.querySelectorAll("[data-asked-block]")] : [];
|
|
3701
|
+
if (resized && (blocks.length !== watched.length || blocks.some((block, i) => block !== watched[i]))) {
|
|
3702
|
+
resized.disconnect();
|
|
3703
|
+
if (blocks.length) for (const element of [view.dom, ...blocks]) resized.observe(element);
|
|
3704
|
+
watched = blocks;
|
|
3705
|
+
}
|
|
3706
|
+
if (asking) measure();
|
|
3707
|
+
},
|
|
3708
|
+
destroy: () => resized?.disconnect()
|
|
3709
|
+
};
|
|
3710
|
+
}
|
|
3711
|
+
})
|
|
3712
|
+
];
|
|
3713
|
+
}
|
|
3714
|
+
});
|
|
3715
|
+
function setAskedBlocks(editor, ids, slot) {
|
|
3716
|
+
if (editor.isDestroyed) return;
|
|
3717
|
+
editor.view.dispatch(editor.state.tr.setMeta(askedBlocksKey, { ids, slot }));
|
|
3718
|
+
}
|
|
3719
|
+
|
|
3720
|
+
// src/DocumentEditor.tsx
|
|
3600
3721
|
import { Button as Button2 } from "@estiva-app/ui";
|
|
3722
|
+
import { Card as Card2 } from "@estiva-app/ui";
|
|
3601
3723
|
import { cn as cn5 } from "@estiva-app/ui";
|
|
3602
3724
|
import { FieldLine as FieldLine2 } from "@estiva-app/ui";
|
|
3603
3725
|
import { FilePicker as FilePicker2 } from "@estiva-app/ui";
|
|
3604
3726
|
import { richTextClassName as richTextClassName2 } from "@estiva-app/ui";
|
|
3727
|
+
import { SectionLabel } from "@estiva-app/ui";
|
|
3605
3728
|
import { Fragment as Fragment6, jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
3729
|
+
var isAsks = (answer) => typeof answer === "object" && answer !== null;
|
|
3730
|
+
function blockOf(doc2, id) {
|
|
3731
|
+
if (doc2.attrs?.blockId === id) return doc2;
|
|
3732
|
+
for (const child of doc2.content ?? []) {
|
|
3733
|
+
const found = blockOf(child, id);
|
|
3734
|
+
if (found) return found;
|
|
3735
|
+
}
|
|
3736
|
+
return null;
|
|
3737
|
+
}
|
|
3738
|
+
var wordsOf = (node) => {
|
|
3739
|
+
const children = node.content ?? [];
|
|
3740
|
+
const inline = children.every((child) => child.text !== void 0 || !child.content);
|
|
3741
|
+
return (node.text ?? "") + children.map(wordsOf).join(inline ? "" : "\n");
|
|
3742
|
+
};
|
|
3743
|
+
function withBlocksFrom(doc2, ids, from) {
|
|
3744
|
+
if (!doc2.content) return doc2;
|
|
3745
|
+
return {
|
|
3746
|
+
...doc2,
|
|
3747
|
+
content: doc2.content.flatMap((child) => {
|
|
3748
|
+
const id = child.attrs?.blockId;
|
|
3749
|
+
if (id && ids.includes(id)) return blockOf(from, id) ?? [];
|
|
3750
|
+
return [withBlocksFrom(child, ids, from)];
|
|
3751
|
+
})
|
|
3752
|
+
};
|
|
3753
|
+
}
|
|
3754
|
+
function blocksChanged(from, to) {
|
|
3755
|
+
if (from === to) return [];
|
|
3756
|
+
const before = new Map((from.content ?? []).map((child) => [child.attrs?.blockId, JSON.stringify(child)]));
|
|
3757
|
+
const after = /* @__PURE__ */ new Set();
|
|
3758
|
+
const changed = [];
|
|
3759
|
+
for (const child of to.content ?? []) {
|
|
3760
|
+
const id = child.attrs?.blockId;
|
|
3761
|
+
if (!id) continue;
|
|
3762
|
+
after.add(id);
|
|
3763
|
+
if (before.get(id) !== JSON.stringify(child)) changed.push(id);
|
|
3764
|
+
}
|
|
3765
|
+
for (const id of before.keys()) if (id && !after.has(id)) changed.push(id);
|
|
3766
|
+
return changed;
|
|
3767
|
+
}
|
|
3768
|
+
function withTypedSince(merged, typedNow, ids) {
|
|
3769
|
+
if (ids.length === 0) return merged;
|
|
3770
|
+
const yours = typedNow.content ?? [];
|
|
3771
|
+
const content = (merged.content ?? []).flatMap((child) => {
|
|
3772
|
+
const id = child.attrs?.blockId;
|
|
3773
|
+
return id && ids.includes(id) ? yours.find((block) => block.attrs?.blockId === id) ?? [] : [child];
|
|
3774
|
+
});
|
|
3775
|
+
yours.forEach((block, i) => {
|
|
3776
|
+
const id = block.attrs?.blockId;
|
|
3777
|
+
if (!id || !ids.includes(id) || content.some((child) => child.attrs?.blockId === id)) return;
|
|
3778
|
+
let at = 0;
|
|
3779
|
+
for (let j = i - 1; j >= 0 && at === 0; j--) {
|
|
3780
|
+
const before = yours[j].attrs?.blockId;
|
|
3781
|
+
at = content.findIndex((child) => child.attrs?.blockId === before) + 1;
|
|
3782
|
+
}
|
|
3783
|
+
content.splice(at, 0, block);
|
|
3784
|
+
});
|
|
3785
|
+
return { ...merged, content };
|
|
3786
|
+
}
|
|
3787
|
+
function YourVersion({ words, onUseMine, onDismiss }) {
|
|
3788
|
+
const [copied, setCopied] = useState6(false);
|
|
3789
|
+
const keep = (event) => event.preventDefault();
|
|
3790
|
+
return /* @__PURE__ */ jsxs9(Card2, { fill: "inset", className: "flex flex-col gap-2 p-3", "data-your-version": "", children: [
|
|
3791
|
+
/* @__PURE__ */ jsx11(SectionLabel, { children: "Your version" }),
|
|
3792
|
+
/* @__PURE__ */ jsx11("p", { className: "whitespace-pre-wrap text-body-2 text-text-primary", children: words }),
|
|
3793
|
+
/* @__PURE__ */ jsxs9("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
3794
|
+
/* @__PURE__ */ jsx11(Button2, { variant: "outlined", size: "small", onMouseDown: keep, onClick: onUseMine, children: "Use mine" }),
|
|
3795
|
+
/* @__PURE__ */ jsx11(
|
|
3796
|
+
Button2,
|
|
3797
|
+
{
|
|
3798
|
+
variant: "muted",
|
|
3799
|
+
size: "small",
|
|
3800
|
+
leadingIcon: copied ? /* @__PURE__ */ jsx11(IconCheck3, { size: 14, stroke: 1.5 }) : /* @__PURE__ */ jsx11(IconCopy2, { size: 14, stroke: 1.5 }),
|
|
3801
|
+
onMouseDown: keep,
|
|
3802
|
+
onClick: () => {
|
|
3803
|
+
void navigator.clipboard?.writeText(words).catch(() => void 0);
|
|
3804
|
+
setCopied(true);
|
|
3805
|
+
},
|
|
3806
|
+
children: copied ? "Copied" : "Copy"
|
|
3807
|
+
}
|
|
3808
|
+
),
|
|
3809
|
+
/* @__PURE__ */ jsx11(Button2, { variant: "muted", size: "small", onMouseDown: keep, onClick: onDismiss, children: "Dismiss" })
|
|
3810
|
+
] })
|
|
3811
|
+
] });
|
|
3812
|
+
}
|
|
3606
3813
|
function heldDocument(hold, key4) {
|
|
3607
3814
|
const text = hold && key4 ? hold.text(key4) : void 0;
|
|
3608
3815
|
if (!text) return null;
|
|
@@ -3618,6 +3825,7 @@ function DocumentEditor({
|
|
|
3618
3825
|
format,
|
|
3619
3826
|
codec,
|
|
3620
3827
|
onCommit,
|
|
3828
|
+
merges = false,
|
|
3621
3829
|
label,
|
|
3622
3830
|
placeholder,
|
|
3623
3831
|
readOnly = false,
|
|
@@ -3667,9 +3875,56 @@ function DocumentEditor({
|
|
|
3667
3875
|
const left = useRef6(false);
|
|
3668
3876
|
const picking = useRef6(false);
|
|
3669
3877
|
const picker = useRef6(null);
|
|
3878
|
+
const [asking, setAsking] = useState6(null);
|
|
3879
|
+
const askingNow = useRef6(null);
|
|
3880
|
+
const ask = (next) => {
|
|
3881
|
+
askingNow.current = next;
|
|
3882
|
+
setAsking(next);
|
|
3883
|
+
};
|
|
3884
|
+
const asked = () => {
|
|
3885
|
+
const now = askingNow.current;
|
|
3886
|
+
return now && typed.current ? withBlocksFrom(typed.current, now.blocks, now.mine) : null;
|
|
3887
|
+
};
|
|
3888
|
+
const current = useRef6(null);
|
|
3889
|
+
const slots = useRef6(/* @__PURE__ */ new Map());
|
|
3890
|
+
const slotOf = useCallback7((id, where) => {
|
|
3891
|
+
const key4 = `${id} ${where}`;
|
|
3892
|
+
let slot = slots.current.get(key4);
|
|
3893
|
+
if (!slot) {
|
|
3894
|
+
slot = document.createElement("span");
|
|
3895
|
+
slot.className = ASKED_BLOCK_CLASSES[where];
|
|
3896
|
+
slot.contentEditable = "false";
|
|
3897
|
+
slots.current.set(key4, slot);
|
|
3898
|
+
}
|
|
3899
|
+
return slot;
|
|
3900
|
+
}, []);
|
|
3901
|
+
const askAbout = (answer, replaced, sent) => {
|
|
3902
|
+
const { codec: words, format: written } = latest.current;
|
|
3903
|
+
const asRead = (doc2) => words.read(words.write(doc2).value, written);
|
|
3904
|
+
const before = asRead(sent);
|
|
3905
|
+
const now = typed.current && typed.current !== sent ? asRead(typed.current) : before;
|
|
3906
|
+
const since = blocksChanged(before, now);
|
|
3907
|
+
const mine = withBlocksFrom(words.read(answer.mine, written), since, now);
|
|
3908
|
+
const value2 = words.read(answer.value, written);
|
|
3909
|
+
const theirsToo = (id) => !!blockOf(before, id) && JSON.stringify(blockOf(value2, id)) !== JSON.stringify(blockOf(before, id));
|
|
3910
|
+
const asks = [...answer.blocks, ...since.filter((id) => !answer.blocks.includes(id) && theirsToo(id))];
|
|
3911
|
+
const missing = asks.flatMap((id) => blockOf(value2, id) ? [] : blockOf(mine, id) ?? []);
|
|
3912
|
+
const merged = missing.length ? { ...value2, content: [...value2.content ?? [], ...missing] } : value2;
|
|
3913
|
+
const held2 = withTypedSince(merged, now, since.filter((id) => !asks.includes(id)));
|
|
3914
|
+
const blocks = asks.filter((id) => blockOf(held2, id));
|
|
3915
|
+
saved.current = answer.theirs;
|
|
3916
|
+
shown.current = answer.theirs;
|
|
3917
|
+
setSuperseded(replaced);
|
|
3918
|
+
setBase(answer.theirs);
|
|
3919
|
+
const editor2 = current.current;
|
|
3920
|
+
if (editor2 && !editor2.isDestroyed) editor2.commands.setContent(held2, { emitUpdate: false });
|
|
3921
|
+
typed.current = held2;
|
|
3922
|
+
ask(blocks.length ? { blocks, mine, theirs: words.read(answer.theirs, written), sinceOpened: !!answer.sinceOpened } : null);
|
|
3923
|
+
};
|
|
3670
3924
|
const save = useCallback7(
|
|
3671
3925
|
async (doc2) => {
|
|
3672
3926
|
if (!doc2 || readOnly || ended()) return;
|
|
3927
|
+
if (askingNow.current) return;
|
|
3673
3928
|
if (committing.current) {
|
|
3674
3929
|
again.current = true;
|
|
3675
3930
|
return;
|
|
@@ -3681,7 +3936,17 @@ function DocumentEditor({
|
|
|
3681
3936
|
const replaced = latest.current.value;
|
|
3682
3937
|
const editedFrom = saved.current;
|
|
3683
3938
|
try {
|
|
3684
|
-
const
|
|
3939
|
+
const answer = await onCommit(next.value, next.contentFormat, editedFrom);
|
|
3940
|
+
if (isAsks(answer)) {
|
|
3941
|
+
if (left.current) {
|
|
3942
|
+
if (!ended()) latest.current.onLeftUnsaved?.(next.value);
|
|
3943
|
+
} else {
|
|
3944
|
+
askAbout(answer, replaced, doc2);
|
|
3945
|
+
setFailed(false);
|
|
3946
|
+
}
|
|
3947
|
+
return;
|
|
3948
|
+
}
|
|
3949
|
+
const ok = answer;
|
|
3685
3950
|
if (ok) {
|
|
3686
3951
|
saved.current = next.value;
|
|
3687
3952
|
shown.current = next.value;
|
|
@@ -3702,7 +3967,7 @@ function DocumentEditor({
|
|
|
3702
3967
|
} finally {
|
|
3703
3968
|
committing.current = false;
|
|
3704
3969
|
setSaving(false);
|
|
3705
|
-
if (again.current) {
|
|
3970
|
+
if (again.current && !askingNow.current) {
|
|
3706
3971
|
again.current = false;
|
|
3707
3972
|
const waiting2 = typed.current;
|
|
3708
3973
|
if (!ended() && waiting2 && latest.current.codec.write(waiting2).value !== next.value) void latestSave.current(waiting2);
|
|
@@ -3716,7 +3981,7 @@ function DocumentEditor({
|
|
|
3716
3981
|
const store = latest.current.hold;
|
|
3717
3982
|
if (!holds || !store || !holdKey) return;
|
|
3718
3983
|
return store.register(holdKey, () => {
|
|
3719
|
-
const doc2 = typed.current;
|
|
3984
|
+
const doc2 = asked() ?? typed.current;
|
|
3720
3985
|
return doc2 && latest.current.codec.write(doc2).value !== saved.current ? JSON.stringify(doc2) : void 0;
|
|
3721
3986
|
});
|
|
3722
3987
|
}, [holdKey, holds]);
|
|
@@ -3809,11 +4074,11 @@ function DocumentEditor({
|
|
|
3809
4074
|
[]
|
|
3810
4075
|
);
|
|
3811
4076
|
const arrived = value !== base && value !== superseded && !own.current.has(value);
|
|
3812
|
-
if (arrived && (readOnly || !focused && !saving && !failed && !restored)) {
|
|
4077
|
+
if (arrived && (readOnly || !focused && !saving && !failed && !restored && !asking)) {
|
|
3813
4078
|
own.current.clear();
|
|
3814
4079
|
setBase(value);
|
|
3815
4080
|
}
|
|
3816
|
-
const waiting = arrived && !readOnly && (focused || failed || restored);
|
|
4081
|
+
const waiting = arrived && !readOnly && (focused || failed || restored || !!asking);
|
|
3817
4082
|
useEffect7(() => {
|
|
3818
4083
|
saved.current = base;
|
|
3819
4084
|
if (!editor || editor.isDestroyed || base === shown.current) return;
|
|
@@ -3829,20 +4094,51 @@ function DocumentEditor({
|
|
|
3829
4094
|
setBase(latest.current.value);
|
|
3830
4095
|
setFailed(false);
|
|
3831
4096
|
setRestored(false);
|
|
4097
|
+
ask(null);
|
|
4098
|
+
slots.current.clear();
|
|
3832
4099
|
};
|
|
3833
4100
|
useEffect7(
|
|
3834
4101
|
() => () => {
|
|
3835
4102
|
left.current = true;
|
|
3836
|
-
if (
|
|
4103
|
+
if (ended()) return;
|
|
4104
|
+
const draft = asked();
|
|
4105
|
+
if (draft) latest.current.onLeftUnsaved?.(latest.current.codec.write(draft).value);
|
|
4106
|
+
else void latestSave.current(typed.current);
|
|
3837
4107
|
},
|
|
3838
4108
|
[]
|
|
3839
4109
|
);
|
|
3840
4110
|
useEffect7(() => {
|
|
4111
|
+
current.current = editor;
|
|
3841
4112
|
onEditor?.(editor);
|
|
3842
4113
|
return () => onEditor?.(null);
|
|
3843
4114
|
}, [editor, onEditor]);
|
|
4115
|
+
const askedIds = asking?.blocks;
|
|
4116
|
+
useEffect7(() => {
|
|
4117
|
+
if (editor && !editor.isDestroyed) setAskedBlocks(editor, askedIds ?? [], slotOf);
|
|
4118
|
+
}, [editor, askedIds, slotOf]);
|
|
4119
|
+
const choose2 = (id, side) => {
|
|
4120
|
+
const now = askingNow.current;
|
|
4121
|
+
if (!editor || editor.isDestroyed || !now) return;
|
|
4122
|
+
const chosen = blockOf(side === "mine" ? now.mine : now.theirs, id);
|
|
4123
|
+
const at = blockAt(editor.state.doc, id);
|
|
4124
|
+
if (at) {
|
|
4125
|
+
const end = at.pos + at.node.nodeSize;
|
|
4126
|
+
const tr = chosen ? editor.state.tr.replaceWith(at.pos, end, editor.schema.nodeFromJSON(chosen)) : editor.state.tr.delete(at.pos, end);
|
|
4127
|
+
editor.view.dispatch(tr);
|
|
4128
|
+
}
|
|
4129
|
+
typed.current = editor.getJSON();
|
|
4130
|
+
const rest = now.blocks.filter((block) => block !== id);
|
|
4131
|
+
if (rest.length > 0) {
|
|
4132
|
+
ask({ ...now, blocks: rest });
|
|
4133
|
+
return;
|
|
4134
|
+
}
|
|
4135
|
+
ask(null);
|
|
4136
|
+
slots.current.clear();
|
|
4137
|
+
void latestSave.current(typed.current);
|
|
4138
|
+
};
|
|
3844
4139
|
const who = changedBy?.name ?? "Someone";
|
|
3845
4140
|
const drawn = /* @__PURE__ */ jsxs9("div", { className: "flex flex-col gap-1", children: [
|
|
4141
|
+
asking?.sinceOpened && /* @__PURE__ */ jsx11(FieldLine2, { tone: "helper", children: "This page changed since you opened it." }),
|
|
3846
4142
|
/* @__PURE__ */ jsxs9(EditorBlockHandle, { editor, actions: blockRows, children: [
|
|
3847
4143
|
/* @__PURE__ */ jsx11(EditorTableControls, { editor, children: /* @__PURE__ */ jsx11(EditorContent3, { editor, className: "-mx-2 cursor-text px-2 py-1", "data-document-editor": "" }) }),
|
|
3848
4144
|
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 })
|
|
@@ -3869,7 +4165,12 @@ function DocumentEditor({
|
|
|
3869
4165
|
),
|
|
3870
4166
|
/* @__PURE__ */ jsx11(ReferenceMenuView, { editor }),
|
|
3871
4167
|
/* @__PURE__ */ jsx11(FilePicker2, { ref: picker, multiple: true, onPick: (files) => void attach(files) }),
|
|
3872
|
-
|
|
4168
|
+
asking?.blocks.flatMap((id) => {
|
|
4169
|
+
const mine = blockOf(asking.mine, id);
|
|
4170
|
+
const card = /* @__PURE__ */ jsx11(YourVersion, { words: mine ? wordsOf(mine) : "You deleted this block.", onUseMine: () => choose2(id, "mine"), onDismiss: () => choose2(id, "theirs") });
|
|
4171
|
+
return ["beside", "under"].map((where) => createPortal(card, slotOf(id, where), `${id} ${where}`));
|
|
4172
|
+
}),
|
|
4173
|
+
waiting && !merges && /* @__PURE__ */ jsxs9(FieldLine2, { tone: "helper", children: [
|
|
3873
4174
|
`${who} saved a newer version.`,
|
|
3874
4175
|
" ",
|
|
3875
4176
|
/* @__PURE__ */ jsx11(Button2, { variant: "muted", size: "small", onMouseDown: (event) => event.preventDefault(), onClick: load, children: "Load it" }),
|
|
@@ -3899,6 +4200,8 @@ function documentExtensions({ latest, references, mentions, linkChips, table, up
|
|
|
3899
4200
|
CodeBlockColours,
|
|
3900
4201
|
TableKit.configure({ table: { resizable: false } }),
|
|
3901
4202
|
BlockId,
|
|
4203
|
+
// A block a refused save asks about, drawn so a save never carries it.
|
|
4204
|
+
AskedBlocks,
|
|
3902
4205
|
Checklist,
|
|
3903
4206
|
Callout,
|
|
3904
4207
|
// A link is being edited only while the caret is on its line: anywhere else on the page it previews on hover.
|