@estiva-app/ui 0.83.0 → 0.85.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/CommentBox.d.ts +12 -3
- package/dist/CommentBox.d.ts.map +1 -1
- package/dist/commentBoxFrame.d.ts +93 -0
- package/dist/commentBoxFrame.d.ts.map +1 -0
- package/dist/editor.d.ts +0 -1
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +445 -337
- package/dist/editor.js.map +4 -4
- package/dist/eslint/index.js +594 -559
- package/dist/eslint/index.js.map +4 -4
- package/dist/eslint/no-hand-rolled-behaviour.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/links.d.ts.map +1 -1
- package/dist/looks.d.ts +1 -1
- package/package.json +1 -1
- package/registry.json +16 -128
- package/src/CommentBox.mdx +15 -4
- package/src/CommentBox.stories.tsx +78 -2
- package/src/CommentBox.test.tsx +185 -3
- package/src/CommentBox.tsx +241 -76
- package/src/{ComposeBox.tsx → commentBoxFrame.tsx} +76 -25
- package/src/editor.ts +1 -1
- package/src/eslint/no-hand-rolled-behaviour.test.ts +27 -0
- package/src/eslint/no-hand-rolled-behaviour.ts +44 -0
- package/src/links.ts +4 -1
- package/src/looks.ts +1 -1
- package/src/registry/app.test.ts +3 -4
- package/src/registry/registry.test.ts +5 -5
- package/stories/Choosing.mdx +0 -1
- package/dist/ComposeBox.d.ts +0 -57
- package/dist/ComposeBox.d.ts.map +0 -1
- package/src/ComposeBox.mdx +0 -58
- package/src/ComposeBox.stories.tsx +0 -81
package/dist/editor.js
CHANGED
|
@@ -297,254 +297,24 @@ function SelectionToolbar({ editor, marks = ["bold", "italic", "underline"], lin
|
|
|
297
297
|
);
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
// src/ComposeBox.tsx
|
|
301
|
-
import { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
|
|
302
|
-
import { Extension as Extension2 } from "@tiptap/core";
|
|
303
|
-
import { EditorContent } from "@tiptap/react";
|
|
304
|
-
import { IconArrowUp } from "@tabler/icons-react";
|
|
305
|
-
import { IconButton } from "@estiva-app/ui";
|
|
306
|
-
import { Toolbar as Toolbar2 } from "@estiva-app/ui";
|
|
307
|
-
import { cn } from "@estiva-app/ui";
|
|
308
|
-
import { richTextClassName } from "@estiva-app/ui";
|
|
309
|
-
|
|
310
|
-
// src/looks.ts
|
|
311
|
-
var FLOATING_SURFACE_CLASSES = "rounded-lg border border-border-default bg-bg-elevated shadow-lg";
|
|
312
|
-
var WRITING_BOX_CLASSES = "relative bg-bg-inset border border-border-default rounded-lg p-3 flex flex-col gap-4 signal:transition-shadow signal:focus-within:border-border-focus signal:focus-within:shadow-focus-ring";
|
|
313
|
-
|
|
314
|
-
// src/suggestionPopup.tsx
|
|
315
|
-
import { forwardRef, useRef as useRef2, useImperativeHandle } from "react";
|
|
316
|
-
import { ReactRenderer } from "@tiptap/react";
|
|
317
|
-
import { exitSuggestion } from "@tiptap/suggestion";
|
|
318
|
-
import { SuggestionMenu } from "@estiva-app/ui";
|
|
319
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
320
|
-
var openCount = 0;
|
|
321
|
-
var lastClose = 0;
|
|
322
|
-
function isSuggestionActive() {
|
|
323
|
-
return openCount > 0 || Date.now() - lastClose < 100;
|
|
324
|
-
}
|
|
325
|
-
function isSuggestionOpen() {
|
|
326
|
-
return openCount > 0;
|
|
327
|
-
}
|
|
328
|
-
var Popup = forwardRef(function Popup2({ options, ...props }, handle) {
|
|
329
|
-
const menu = useRef2(null);
|
|
330
|
-
useImperativeHandle(handle, () => ({ onKeyDown: (event) => menu.current?.onKeyDown(event) ?? false }));
|
|
331
|
-
const sections = options.sections ? options.sections(props.items, props.query) : [{ items: props.items }];
|
|
332
|
-
return /* @__PURE__ */ jsx2(
|
|
333
|
-
SuggestionMenu,
|
|
334
|
-
{
|
|
335
|
-
handle: menu,
|
|
336
|
-
rect: props.clientRect?.() ?? null,
|
|
337
|
-
editorElement: props.editor.view.dom,
|
|
338
|
-
ariaLabel: options.ariaLabel,
|
|
339
|
-
width: options.width,
|
|
340
|
-
maxHeight: options.maxHeight,
|
|
341
|
-
sections,
|
|
342
|
-
itemKey: options.itemKey,
|
|
343
|
-
row: options.row,
|
|
344
|
-
onSelect: (item) => props.command(item)
|
|
345
|
-
}
|
|
346
|
-
);
|
|
347
|
-
});
|
|
348
|
-
function suggestionPopup(options) {
|
|
349
|
-
return () => {
|
|
350
|
-
let component = null;
|
|
351
|
-
let container = null;
|
|
352
|
-
let last = null;
|
|
353
|
-
let unsubscribe;
|
|
354
|
-
let counted = false;
|
|
355
|
-
let unlisten;
|
|
356
|
-
const count = (shown) => {
|
|
357
|
-
if (shown === counted) return;
|
|
358
|
-
counted = shown;
|
|
359
|
-
openCount = shown ? openCount + 1 : Math.max(0, openCount - 1);
|
|
360
|
-
};
|
|
361
|
-
const listen = (props) => {
|
|
362
|
-
const { view } = props.editor;
|
|
363
|
-
const dom = view.dom;
|
|
364
|
-
const onBlur = () => {
|
|
365
|
-
if (dom.contains(document.activeElement) || !last) return;
|
|
366
|
-
const from = last.range.from;
|
|
367
|
-
count(false);
|
|
368
|
-
for (const plugin of view.state.plugins) {
|
|
369
|
-
const state = plugin.getState(view.state);
|
|
370
|
-
if (state?.active && state.range?.from === from && plugin.spec.key) exitSuggestion(view, plugin.spec.key);
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
dom.addEventListener("blur", onBlur);
|
|
374
|
-
unlisten = () => dom.removeEventListener("blur", onBlur);
|
|
375
|
-
};
|
|
376
|
-
const exit = () => {
|
|
377
|
-
unsubscribe?.();
|
|
378
|
-
unsubscribe = void 0;
|
|
379
|
-
unlisten?.();
|
|
380
|
-
unlisten = void 0;
|
|
381
|
-
last = null;
|
|
382
|
-
if (counted) lastClose = Date.now();
|
|
383
|
-
count(false);
|
|
384
|
-
if (!component) return;
|
|
385
|
-
component.destroy();
|
|
386
|
-
container?.remove();
|
|
387
|
-
component = null;
|
|
388
|
-
container = null;
|
|
389
|
-
};
|
|
390
|
-
return {
|
|
391
|
-
onStart: (props) => {
|
|
392
|
-
count(props.items.length > 0);
|
|
393
|
-
component = new ReactRenderer(Popup, { props: { ...props, options }, editor: props.editor });
|
|
394
|
-
container = document.createElement("div");
|
|
395
|
-
document.body.appendChild(container);
|
|
396
|
-
container.appendChild(component.element);
|
|
397
|
-
last = props;
|
|
398
|
-
listen(props);
|
|
399
|
-
const { subscribe, refresh } = options;
|
|
400
|
-
if (subscribe && refresh) {
|
|
401
|
-
unsubscribe = subscribe(() => {
|
|
402
|
-
if (!last || !component) return;
|
|
403
|
-
last = { ...last, items: refresh(last.query) };
|
|
404
|
-
count(last.items.length > 0);
|
|
405
|
-
component.updateProps({ ...last, options });
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
},
|
|
409
|
-
onUpdate: (props) => {
|
|
410
|
-
last = props;
|
|
411
|
-
count(props.items.length > 0);
|
|
412
|
-
component?.updateProps({ ...props, options });
|
|
413
|
-
},
|
|
414
|
-
onKeyDown: ({ event }) => {
|
|
415
|
-
if (event.key === "Escape") {
|
|
416
|
-
exit();
|
|
417
|
-
return true;
|
|
418
|
-
}
|
|
419
|
-
return component?.ref?.onKeyDown(event) ?? false;
|
|
420
|
-
},
|
|
421
|
-
onExit: exit
|
|
422
|
-
};
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
// src/ComposeBox.tsx
|
|
427
|
-
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
428
|
-
var COMPOSE_EDITOR_CLASSES = richTextClassName("default", "outline-none w-full bg-transparent min-h-[20px] [&>p+p]:-mt-1");
|
|
429
|
-
var ComposeKeys = Extension2.create({
|
|
430
|
-
name: "composeKeys",
|
|
431
|
-
addStorage() {
|
|
432
|
-
return { send: null };
|
|
433
|
-
},
|
|
434
|
-
addKeyboardShortcuts() {
|
|
435
|
-
return {
|
|
436
|
-
Enter: () => {
|
|
437
|
-
if (isSuggestionActive()) return false;
|
|
438
|
-
this.storage.send?.();
|
|
439
|
-
return true;
|
|
440
|
-
},
|
|
441
|
-
"Shift-Enter": ({ editor }) => {
|
|
442
|
-
const { $from } = editor.state.selection;
|
|
443
|
-
for (let d = $from.depth; d > 0; d--) {
|
|
444
|
-
const node = $from.node(d);
|
|
445
|
-
if (node.type.name === "listItem") {
|
|
446
|
-
return node.textContent.length === 0 ? editor.commands.liftListItem("listItem") : editor.commands.splitListItem("listItem");
|
|
447
|
-
}
|
|
448
|
-
if (node.type.name === "blockquote") {
|
|
449
|
-
if ($from.parent.textContent.length === 0) return editor.commands.lift("paragraph");
|
|
450
|
-
break;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return editor.commands.splitBlock();
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
function isEmptyDoc(editor) {
|
|
459
|
-
const doc2 = editor.state.doc;
|
|
460
|
-
if (doc2.textContent.trim().length > 0) return false;
|
|
461
|
-
let empty = true;
|
|
462
|
-
doc2.descendants((node) => {
|
|
463
|
-
if (node.isAtom && !node.isText && node.type.name !== "hardBreak") empty = false;
|
|
464
|
-
});
|
|
465
|
-
return empty;
|
|
466
|
-
}
|
|
467
|
-
function ComposeBox({ editor, onSend, placeholder, tools, attachments, ready = false, holding = false, marked = false, selection, className }) {
|
|
468
|
-
const [empty, setEmpty] = useState2(true);
|
|
469
|
-
const canSend = (!empty || ready) && !holding;
|
|
470
|
-
const send = useCallback2(() => {
|
|
471
|
-
if (!editor || holding || isEmptyDoc(editor) && !ready) return true;
|
|
472
|
-
if (onSend(editor) === false) return true;
|
|
473
|
-
editor.commands.clearContent(true);
|
|
474
|
-
editor.commands.focus();
|
|
475
|
-
return true;
|
|
476
|
-
}, [editor, holding, ready, onSend]);
|
|
477
|
-
useEffect2(() => {
|
|
478
|
-
if (!editor) return;
|
|
479
|
-
const storage = editor.storage.composeKeys;
|
|
480
|
-
if (!storage) return;
|
|
481
|
-
storage.send = send;
|
|
482
|
-
return () => {
|
|
483
|
-
storage.send = null;
|
|
484
|
-
};
|
|
485
|
-
}, [editor, send]);
|
|
486
|
-
useEffect2(() => {
|
|
487
|
-
if (!editor) return;
|
|
488
|
-
const read = () => setEmpty(isEmptyDoc(editor));
|
|
489
|
-
read();
|
|
490
|
-
editor.on("update", read);
|
|
491
|
-
return () => {
|
|
492
|
-
editor.off("update", read);
|
|
493
|
-
};
|
|
494
|
-
}, [editor]);
|
|
495
|
-
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__ */ jsx3(SelectionToolbar, { editor, ...selection }),
|
|
499
|
-
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
|
-
] }),
|
|
501
|
-
attachments && /* @__PURE__ */ jsx3("div", { className: "flex flex-wrap gap-2", children: attachments }),
|
|
502
|
-
/* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between", children: [
|
|
503
|
-
tools ? /* @__PURE__ */ jsx3(Toolbar2, { "aria-label": "Compose tools", surface: false, className: "flex items-center gap-1", children: tools }) : /* @__PURE__ */ jsx3("span", {}),
|
|
504
|
-
/* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-2.5", children: [
|
|
505
|
-
/* @__PURE__ */ jsx3("span", { className: "hidden select-none font-mono text-menu font-normal tracking-wider text-text-muted signal:inline", children: "Enter to send \xB7 Shift+Enter new line" }),
|
|
506
|
-
/* @__PURE__ */ jsx3(
|
|
507
|
-
IconButton,
|
|
508
|
-
{
|
|
509
|
-
variant: "primary",
|
|
510
|
-
onMouseDown: (e) => {
|
|
511
|
-
e.preventDefault();
|
|
512
|
-
send();
|
|
513
|
-
},
|
|
514
|
-
onClick: (e) => {
|
|
515
|
-
if (e.detail === 0) send();
|
|
516
|
-
},
|
|
517
|
-
disabled: !canSend,
|
|
518
|
-
"aria-label": "Send",
|
|
519
|
-
tooltip: "Send",
|
|
520
|
-
tooltipShortcut: "Enter",
|
|
521
|
-
glow: canSend,
|
|
522
|
-
children: /* @__PURE__ */ jsx3(IconArrowUp, { size: 16, stroke: 1.5 })
|
|
523
|
-
}
|
|
524
|
-
)
|
|
525
|
-
] })
|
|
526
|
-
] })
|
|
527
|
-
] }) });
|
|
528
|
-
}
|
|
529
|
-
|
|
530
300
|
// src/CommentBox.tsx
|
|
531
|
-
import { Fragment as Fragment2, useCallback as useCallback4, useEffect as useEffect4, useRef as useRef3, useState as useState4 } from "react";
|
|
301
|
+
import { Fragment as Fragment2, useCallback as useCallback4, useEffect as useEffect4, useLayoutEffect, useRef as useRef3, useState as useState4 } from "react";
|
|
532
302
|
import { Extension as Extension11 } from "@tiptap/core";
|
|
533
|
-
import {
|
|
303
|
+
import { Editor } from "@tiptap/react";
|
|
534
304
|
import { IconLock, IconPaperclip, IconSquareRounded } from "@tabler/icons-react";
|
|
535
305
|
import { AttachmentCard } from "@estiva-app/ui";
|
|
536
306
|
|
|
537
307
|
// src/BlockNodes.tsx
|
|
538
|
-
import { Extension as
|
|
308
|
+
import { Extension as Extension6, InputRule, Node as Node2 } from "@tiptap/core";
|
|
539
309
|
import { DOMSerializer } from "@tiptap/pm/model";
|
|
540
310
|
import { Plugin as Plugin6, PluginKey as PluginKey6 } from "@tiptap/pm/state";
|
|
541
311
|
import { Mapping, ReplaceAroundStep } from "@tiptap/pm/transform";
|
|
542
|
-
import { NodeViewWrapper, ReactNodeViewRenderer, ReactRenderer
|
|
312
|
+
import { NodeViewWrapper, ReactNodeViewRenderer, ReactRenderer } from "@tiptap/react";
|
|
543
313
|
import { Checkbox } from "@estiva-app/ui";
|
|
544
314
|
import { calloutLook } from "@estiva-app/ui";
|
|
545
315
|
|
|
546
316
|
// src/LinkPlaces.ts
|
|
547
|
-
import { Extension as
|
|
317
|
+
import { Extension as Extension2 } from "@tiptap/core";
|
|
548
318
|
import { Plugin as Plugin2, PluginKey as PluginKey2 } from "@tiptap/pm/state";
|
|
549
319
|
import { Decoration as Decoration2, DecorationSet as DecorationSet2 } from "@tiptap/pm/view";
|
|
550
320
|
var CONTAINERS = /* @__PURE__ */ new Set(["bulletList", "orderedList", "listItem"]);
|
|
@@ -633,7 +403,7 @@ function placeOf(decorations) {
|
|
|
633
403
|
return "chip";
|
|
634
404
|
}
|
|
635
405
|
var key = new PluginKey2("linkPlaces");
|
|
636
|
-
var LinkPlaces =
|
|
406
|
+
var LinkPlaces = Extension2.create({
|
|
637
407
|
name: "linkPlaces",
|
|
638
408
|
addProseMirrorPlugins() {
|
|
639
409
|
const decorate = (doc2) => DecorationSet2.create(
|
|
@@ -654,15 +424,15 @@ var LinkPlaces = Extension3.create({
|
|
|
654
424
|
});
|
|
655
425
|
|
|
656
426
|
// src/ReferenceMenu.tsx
|
|
657
|
-
import { useCallback as
|
|
658
|
-
import { Extension as
|
|
427
|
+
import { useCallback as useCallback2 } from "react";
|
|
428
|
+
import { Extension as Extension5 } from "@tiptap/core";
|
|
659
429
|
import { useEditorState } from "@tiptap/react";
|
|
660
430
|
import { NodeSelection as NodeSelection2, Plugin as Plugin5, PluginKey as PluginKey5, TextSelection } from "@tiptap/pm/state";
|
|
661
431
|
import { ReplaceStep } from "@tiptap/pm/transform";
|
|
662
432
|
import { IconCheck, IconExternalLink } from "@tabler/icons-react";
|
|
663
433
|
|
|
664
434
|
// src/LinkChips.ts
|
|
665
|
-
import { Extension as
|
|
435
|
+
import { Extension as Extension3 } from "@tiptap/core";
|
|
666
436
|
import { closeHistory } from "@tiptap/pm/history";
|
|
667
437
|
import { Plugin as Plugin3, PluginKey as PluginKey3 } from "@tiptap/pm/state";
|
|
668
438
|
var key2 = new PluginKey3("linkChips");
|
|
@@ -740,7 +510,7 @@ function refreshLinkChips(editor) {
|
|
|
740
510
|
const tr = apply(editor.state, findLinkChips(editor.state.doc, editor.state.selection, chips.options.referenceOf, chips.pasted));
|
|
741
511
|
if (tr) editor.view.dispatch(tr);
|
|
742
512
|
}
|
|
743
|
-
var LinkChips =
|
|
513
|
+
var LinkChips = Extension3.create({
|
|
744
514
|
name: "linkChips",
|
|
745
515
|
addOptions() {
|
|
746
516
|
return { referenceOf: null, ask: null, limit: 24 };
|
|
@@ -813,10 +583,10 @@ import { MenuItem, MenuSection, MenuSeparator } from "@estiva-app/ui";
|
|
|
813
583
|
import { Popover as Popover2 } from "@estiva-app/ui";
|
|
814
584
|
|
|
815
585
|
// src/ReferenceCards.ts
|
|
816
|
-
import { Extension as
|
|
586
|
+
import { Extension as Extension4 } from "@tiptap/core";
|
|
817
587
|
import { NodeSelection, Plugin as Plugin4, PluginKey as PluginKey4 } from "@tiptap/pm/state";
|
|
818
588
|
import { Decoration as Decoration3, DecorationSet as DecorationSet3 } from "@tiptap/pm/view";
|
|
819
|
-
import { useEffect as
|
|
589
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
820
590
|
function layoutOf(raw) {
|
|
821
591
|
if (typeof raw !== "string" || raw === "" || raw === "none") return void 0;
|
|
822
592
|
return raw === "detailed" ? "detailed" : "compact";
|
|
@@ -857,7 +627,7 @@ function elementFor(storage, slotKey) {
|
|
|
857
627
|
function storageOf(editor) {
|
|
858
628
|
return editor.storage.referenceCards;
|
|
859
629
|
}
|
|
860
|
-
var ReferenceCards =
|
|
630
|
+
var ReferenceCards = Extension4.create({
|
|
861
631
|
name: "referenceCards",
|
|
862
632
|
addStorage() {
|
|
863
633
|
return { elements: /* @__PURE__ */ new Map() };
|
|
@@ -889,8 +659,8 @@ var ReferenceCards = Extension5.create({
|
|
|
889
659
|
}
|
|
890
660
|
});
|
|
891
661
|
function useReferenceCards(editor) {
|
|
892
|
-
const [slots, setSlots] =
|
|
893
|
-
|
|
662
|
+
const [slots, setSlots] = useState2([]);
|
|
663
|
+
useEffect2(() => {
|
|
894
664
|
if (!editor) return;
|
|
895
665
|
const storage = storageOf(editor);
|
|
896
666
|
if (!storage) return;
|
|
@@ -955,7 +725,7 @@ function setReferenceCardAt(editor, pos, layout) {
|
|
|
955
725
|
}
|
|
956
726
|
|
|
957
727
|
// src/ReferenceMenu.tsx
|
|
958
|
-
import { Fragment, jsx as
|
|
728
|
+
import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
959
729
|
var key4 = new PluginKey5("referenceMenu");
|
|
960
730
|
var SHOW_AS = [
|
|
961
731
|
{ as: "row", label: "Row" },
|
|
@@ -1036,7 +806,7 @@ function caretAfter(state, pos) {
|
|
|
1036
806
|
const node = state.doc.nodeAt(pos);
|
|
1037
807
|
return state.tr.setSelection(TextSelection.create(state.doc, pos + (node?.nodeSize ?? 1)));
|
|
1038
808
|
}
|
|
1039
|
-
var ReferenceMenu =
|
|
809
|
+
var ReferenceMenu = Extension5.create({
|
|
1040
810
|
name: "referenceMenu",
|
|
1041
811
|
// Before the editor's own keys, so Enter on a highlighted row is the row's, not a new line.
|
|
1042
812
|
priority: 1e3,
|
|
@@ -1115,7 +885,7 @@ function ReferenceMenuView({ editor }) {
|
|
|
1115
885
|
return { pos: open.pos, active: open.active, shownAs: linkPlaceAt(ed.state.doc, open.pos) === "card" ? "card" : "row" };
|
|
1116
886
|
}
|
|
1117
887
|
});
|
|
1118
|
-
const keepFocus2 =
|
|
888
|
+
const keepFocus2 = useCallback2((list) => {
|
|
1119
889
|
const panel = list?.closest('[role="dialog"]');
|
|
1120
890
|
if (!panel) return;
|
|
1121
891
|
const keep = (event) => event.preventDefault();
|
|
@@ -1133,7 +903,7 @@ function ReferenceMenuView({ editor }) {
|
|
|
1133
903
|
};
|
|
1134
904
|
return (
|
|
1135
905
|
// finalFocus={false}: focus never left the text.
|
|
1136
|
-
/* @__PURE__ */
|
|
906
|
+
/* @__PURE__ */ jsx2(
|
|
1137
907
|
Popover2,
|
|
1138
908
|
{
|
|
1139
909
|
anchor,
|
|
@@ -1145,14 +915,14 @@ function ReferenceMenuView({ editor }) {
|
|
|
1145
915
|
align: "left",
|
|
1146
916
|
ariaLabel: "Link",
|
|
1147
917
|
finalFocus: false,
|
|
1148
|
-
children: shown && /* @__PURE__ */
|
|
1149
|
-
opens && /* @__PURE__ */
|
|
918
|
+
children: shown && /* @__PURE__ */ jsxs2("div", { ref: keepFocus2, role: "menu", "aria-label": "Link", className: "flex flex-col gap-0.5", children: [
|
|
919
|
+
opens && /* @__PURE__ */ jsx2(
|
|
1150
920
|
MenuItem,
|
|
1151
921
|
{
|
|
1152
922
|
role: "menuitem",
|
|
1153
923
|
tabIndex: -1,
|
|
1154
924
|
label: "Open",
|
|
1155
|
-
leading: /* @__PURE__ */
|
|
925
|
+
leading: /* @__PURE__ */ jsx2(IconExternalLink, { size: 16 }),
|
|
1156
926
|
selected: shown.active === 0,
|
|
1157
927
|
onMouseDown: (event) => {
|
|
1158
928
|
event.preventDefault();
|
|
@@ -1160,9 +930,9 @@ function ReferenceMenuView({ editor }) {
|
|
|
1160
930
|
}
|
|
1161
931
|
}
|
|
1162
932
|
),
|
|
1163
|
-
showAs && /* @__PURE__ */
|
|
1164
|
-
opens && /* @__PURE__ */
|
|
1165
|
-
/* @__PURE__ */
|
|
933
|
+
showAs && /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
934
|
+
opens && /* @__PURE__ */ jsx2(MenuSeparator, {}),
|
|
935
|
+
/* @__PURE__ */ jsx2("div", { role: "group", "aria-label": "Show as", children: /* @__PURE__ */ jsx2(MenuSection, { label: "Show as", children: SHOW_AS.map(({ as, label }, i) => /* @__PURE__ */ jsx2(
|
|
1166
936
|
MenuItem,
|
|
1167
937
|
{
|
|
1168
938
|
role: "menuitemradio",
|
|
@@ -1170,7 +940,7 @@ function ReferenceMenuView({ editor }) {
|
|
|
1170
940
|
tabIndex: -1,
|
|
1171
941
|
label,
|
|
1172
942
|
selected: shown.active === i + (opens ? 1 : 0),
|
|
1173
|
-
trailing: shown.shownAs === as ? /* @__PURE__ */
|
|
943
|
+
trailing: shown.shownAs === as ? /* @__PURE__ */ jsx2(IconCheck, { size: 16, "aria-hidden": true }) : void 0,
|
|
1174
944
|
onMouseDown: (event) => {
|
|
1175
945
|
event.preventDefault();
|
|
1176
946
|
run(as);
|
|
@@ -1186,7 +956,7 @@ function ReferenceMenuView({ editor }) {
|
|
|
1186
956
|
}
|
|
1187
957
|
|
|
1188
958
|
// src/BlockNodes.tsx
|
|
1189
|
-
import { jsx as
|
|
959
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
1190
960
|
var BLOCK_TYPES = [
|
|
1191
961
|
"paragraph",
|
|
1192
962
|
"heading",
|
|
@@ -1344,7 +1114,7 @@ function bringsInBlocks(transactions) {
|
|
|
1344
1114
|
})
|
|
1345
1115
|
);
|
|
1346
1116
|
}
|
|
1347
|
-
var BlockId =
|
|
1117
|
+
var BlockId = Extension6.create({
|
|
1348
1118
|
name: "blockId",
|
|
1349
1119
|
onCreate() {
|
|
1350
1120
|
const { state, view } = this.editor;
|
|
@@ -1433,7 +1203,7 @@ var ReferenceNode = Node2.create({
|
|
|
1433
1203
|
const uri = String(node.attrs.uri ?? "");
|
|
1434
1204
|
const href = typeof node.attrs.href === "string" && node.attrs.href ? node.attrs.href : void 0;
|
|
1435
1205
|
const place2 = placeOf(decorations);
|
|
1436
|
-
return /* @__PURE__ */
|
|
1206
|
+
return /* @__PURE__ */ jsx3(
|
|
1437
1207
|
NodeViewWrapper,
|
|
1438
1208
|
{
|
|
1439
1209
|
as: "span",
|
|
@@ -1448,7 +1218,7 @@ var ReferenceNode = Node2.create({
|
|
|
1448
1218
|
event.preventDefault();
|
|
1449
1219
|
event.stopPropagation();
|
|
1450
1220
|
},
|
|
1451
|
-
children: uri ? /* @__PURE__ */
|
|
1221
|
+
children: uri ? /* @__PURE__ */ jsx3(View, { uri, ...href ? { href } : {}, place: place2, editing: editor.isEditable }) : /* @__PURE__ */ jsx3("span", { children: href })
|
|
1452
1222
|
}
|
|
1453
1223
|
);
|
|
1454
1224
|
}, {
|
|
@@ -1485,7 +1255,7 @@ var UnknownBlock = Node2.create({
|
|
|
1485
1255
|
function UnknownBlockView({ node }) {
|
|
1486
1256
|
const source = node.attrs.source;
|
|
1487
1257
|
const text = String(node.attrs.text ?? "");
|
|
1488
|
-
return /* @__PURE__ */
|
|
1258
|
+
return /* @__PURE__ */ jsx3(
|
|
1489
1259
|
NodeViewWrapper,
|
|
1490
1260
|
{
|
|
1491
1261
|
"data-block-id": source?.id,
|
|
@@ -1525,7 +1295,7 @@ var AttachmentNode = Node2.create({
|
|
|
1525
1295
|
addNodeView() {
|
|
1526
1296
|
const View = this.options.view;
|
|
1527
1297
|
if (!View) return null;
|
|
1528
|
-
return ReactNodeViewRenderer(({ node }) => /* @__PURE__ */
|
|
1298
|
+
return ReactNodeViewRenderer(({ node }) => /* @__PURE__ */ jsx3(NodeViewWrapper, { className: "my-2", children: /* @__PURE__ */ jsx3(View, { attrs: node.attrs }) }));
|
|
1529
1299
|
}
|
|
1530
1300
|
});
|
|
1531
1301
|
var TICK = "checklistTick";
|
|
@@ -1562,7 +1332,7 @@ function listItemView(editor, node, view, getPos) {
|
|
|
1562
1332
|
};
|
|
1563
1333
|
let words = node.firstChild?.textContent.trim() || "Item";
|
|
1564
1334
|
const props = () => ({ checked, onChange: view.editable ? tick : void 0, "aria-label": words });
|
|
1565
|
-
const renderer = new
|
|
1335
|
+
const renderer = new ReactRenderer(Checkbox, { editor, props: props(), as: "span" });
|
|
1566
1336
|
box.appendChild(renderer.element);
|
|
1567
1337
|
let drawn = "";
|
|
1568
1338
|
const sync = () => {
|
|
@@ -1594,7 +1364,7 @@ function listItemView(editor, node, view, getPos) {
|
|
|
1594
1364
|
}
|
|
1595
1365
|
};
|
|
1596
1366
|
}
|
|
1597
|
-
var Checklist =
|
|
1367
|
+
var Checklist = Extension6.create({
|
|
1598
1368
|
name: "checklist",
|
|
1599
1369
|
// Before the list item's own Enter and Backspace.
|
|
1600
1370
|
priority: 101,
|
|
@@ -1666,7 +1436,7 @@ var Checklist = Extension7.create({
|
|
|
1666
1436
|
];
|
|
1667
1437
|
}
|
|
1668
1438
|
});
|
|
1669
|
-
var Callout =
|
|
1439
|
+
var Callout = Extension6.create({
|
|
1670
1440
|
name: "callout",
|
|
1671
1441
|
addGlobalAttributes() {
|
|
1672
1442
|
return [
|
|
@@ -1691,6 +1461,255 @@ import { Card } from "@estiva-app/ui";
|
|
|
1691
1461
|
import { CardUnder } from "@estiva-app/ui";
|
|
1692
1462
|
import { cn as cn2 } from "@estiva-app/ui";
|
|
1693
1463
|
|
|
1464
|
+
// src/commentBoxFrame.tsx
|
|
1465
|
+
import { useCallback as useCallback3, useEffect as useEffect3, useState as useState3 } from "react";
|
|
1466
|
+
import { Extension as Extension7 } from "@tiptap/core";
|
|
1467
|
+
import { EditorContent } from "@tiptap/react";
|
|
1468
|
+
import { IconArrowUp } from "@tabler/icons-react";
|
|
1469
|
+
import { IconButton } from "@estiva-app/ui";
|
|
1470
|
+
import { Toolbar as Toolbar2 } from "@estiva-app/ui";
|
|
1471
|
+
import { cn } from "@estiva-app/ui";
|
|
1472
|
+
import { richTextClassName } from "@estiva-app/ui";
|
|
1473
|
+
import { ScrollArea } from "@estiva-app/ui";
|
|
1474
|
+
|
|
1475
|
+
// src/looks.ts
|
|
1476
|
+
var FLOATING_SURFACE_CLASSES = "rounded-lg border border-border-default bg-bg-elevated shadow-lg";
|
|
1477
|
+
var WRITING_BOX_CLASSES = "relative bg-bg-inset border border-border-default rounded-lg p-3 flex flex-col gap-4 signal:transition-shadow signal:focus-within:border-border-focus signal:focus-within:shadow-focus-ring";
|
|
1478
|
+
|
|
1479
|
+
// src/suggestionPopup.tsx
|
|
1480
|
+
import { forwardRef, useRef as useRef2, useImperativeHandle } from "react";
|
|
1481
|
+
import { ReactRenderer as ReactRenderer2 } from "@tiptap/react";
|
|
1482
|
+
import { exitSuggestion } from "@tiptap/suggestion";
|
|
1483
|
+
import { SuggestionMenu } from "@estiva-app/ui";
|
|
1484
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1485
|
+
var openCount = 0;
|
|
1486
|
+
var lastClose = 0;
|
|
1487
|
+
function isSuggestionActive() {
|
|
1488
|
+
return openCount > 0 || Date.now() - lastClose < 100;
|
|
1489
|
+
}
|
|
1490
|
+
function isSuggestionOpen() {
|
|
1491
|
+
return openCount > 0;
|
|
1492
|
+
}
|
|
1493
|
+
var Popup = forwardRef(function Popup2({ options, ...props }, handle) {
|
|
1494
|
+
const menu = useRef2(null);
|
|
1495
|
+
useImperativeHandle(handle, () => ({ onKeyDown: (event) => menu.current?.onKeyDown(event) ?? false }));
|
|
1496
|
+
const sections = options.sections ? options.sections(props.items, props.query) : [{ items: props.items }];
|
|
1497
|
+
return /* @__PURE__ */ jsx4(
|
|
1498
|
+
SuggestionMenu,
|
|
1499
|
+
{
|
|
1500
|
+
handle: menu,
|
|
1501
|
+
rect: props.clientRect?.() ?? null,
|
|
1502
|
+
editorElement: props.editor.view.dom,
|
|
1503
|
+
ariaLabel: options.ariaLabel,
|
|
1504
|
+
width: options.width,
|
|
1505
|
+
maxHeight: options.maxHeight,
|
|
1506
|
+
sections,
|
|
1507
|
+
itemKey: options.itemKey,
|
|
1508
|
+
row: options.row,
|
|
1509
|
+
onSelect: (item) => props.command(item)
|
|
1510
|
+
}
|
|
1511
|
+
);
|
|
1512
|
+
});
|
|
1513
|
+
function suggestionPopup(options) {
|
|
1514
|
+
return () => {
|
|
1515
|
+
let component = null;
|
|
1516
|
+
let container = null;
|
|
1517
|
+
let last = null;
|
|
1518
|
+
let unsubscribe;
|
|
1519
|
+
let counted = false;
|
|
1520
|
+
let unlisten;
|
|
1521
|
+
const count = (shown) => {
|
|
1522
|
+
if (shown === counted) return;
|
|
1523
|
+
counted = shown;
|
|
1524
|
+
openCount = shown ? openCount + 1 : Math.max(0, openCount - 1);
|
|
1525
|
+
};
|
|
1526
|
+
const listen = (props) => {
|
|
1527
|
+
const { view } = props.editor;
|
|
1528
|
+
const dom = view.dom;
|
|
1529
|
+
const onBlur = () => {
|
|
1530
|
+
if (dom.contains(document.activeElement) || !last) return;
|
|
1531
|
+
const from = last.range.from;
|
|
1532
|
+
count(false);
|
|
1533
|
+
for (const plugin of view.state.plugins) {
|
|
1534
|
+
const state = plugin.getState(view.state);
|
|
1535
|
+
if (state?.active && state.range?.from === from && plugin.spec.key) exitSuggestion(view, plugin.spec.key);
|
|
1536
|
+
}
|
|
1537
|
+
};
|
|
1538
|
+
dom.addEventListener("blur", onBlur);
|
|
1539
|
+
unlisten = () => dom.removeEventListener("blur", onBlur);
|
|
1540
|
+
};
|
|
1541
|
+
const exit = () => {
|
|
1542
|
+
unsubscribe?.();
|
|
1543
|
+
unsubscribe = void 0;
|
|
1544
|
+
unlisten?.();
|
|
1545
|
+
unlisten = void 0;
|
|
1546
|
+
last = null;
|
|
1547
|
+
if (counted) lastClose = Date.now();
|
|
1548
|
+
count(false);
|
|
1549
|
+
if (!component) return;
|
|
1550
|
+
component.destroy();
|
|
1551
|
+
container?.remove();
|
|
1552
|
+
component = null;
|
|
1553
|
+
container = null;
|
|
1554
|
+
};
|
|
1555
|
+
return {
|
|
1556
|
+
onStart: (props) => {
|
|
1557
|
+
count(props.items.length > 0);
|
|
1558
|
+
component = new ReactRenderer2(Popup, { props: { ...props, options }, editor: props.editor });
|
|
1559
|
+
container = document.createElement("div");
|
|
1560
|
+
document.body.appendChild(container);
|
|
1561
|
+
container.appendChild(component.element);
|
|
1562
|
+
last = props;
|
|
1563
|
+
listen(props);
|
|
1564
|
+
const { subscribe, refresh } = options;
|
|
1565
|
+
if (subscribe && refresh) {
|
|
1566
|
+
unsubscribe = subscribe(() => {
|
|
1567
|
+
if (!last || !component) return;
|
|
1568
|
+
last = { ...last, items: refresh(last.query) };
|
|
1569
|
+
count(last.items.length > 0);
|
|
1570
|
+
component.updateProps({ ...last, options });
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
},
|
|
1574
|
+
onUpdate: (props) => {
|
|
1575
|
+
last = props;
|
|
1576
|
+
count(props.items.length > 0);
|
|
1577
|
+
component?.updateProps({ ...props, options });
|
|
1578
|
+
},
|
|
1579
|
+
onKeyDown: ({ event }) => {
|
|
1580
|
+
if (event.key === "Escape") {
|
|
1581
|
+
exit();
|
|
1582
|
+
return true;
|
|
1583
|
+
}
|
|
1584
|
+
return component?.ref?.onKeyDown(event) ?? false;
|
|
1585
|
+
},
|
|
1586
|
+
onExit: exit
|
|
1587
|
+
};
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
// src/commentBoxFrame.tsx
|
|
1592
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1593
|
+
var COMPOSE_EDITOR_CLASSES = richTextClassName("default", "outline-none w-full bg-transparent min-h-[20px] [&>p+p]:-mt-1");
|
|
1594
|
+
var COMPOSE_SCROLL_CLASSES = { area: "-mr-3", viewport: "max-h-[50vh]", content: "pr-3" };
|
|
1595
|
+
var ComposeKeys = Extension7.create({
|
|
1596
|
+
name: "composeKeys",
|
|
1597
|
+
addStorage() {
|
|
1598
|
+
return { send: null };
|
|
1599
|
+
},
|
|
1600
|
+
addKeyboardShortcuts() {
|
|
1601
|
+
return {
|
|
1602
|
+
Enter: () => {
|
|
1603
|
+
if (isSuggestionActive()) return false;
|
|
1604
|
+
this.storage.send?.();
|
|
1605
|
+
return true;
|
|
1606
|
+
},
|
|
1607
|
+
"Shift-Enter": ({ editor }) => {
|
|
1608
|
+
const { $from } = editor.state.selection;
|
|
1609
|
+
for (let d = $from.depth; d > 0; d--) {
|
|
1610
|
+
const node = $from.node(d);
|
|
1611
|
+
if (node.type.name === "listItem") {
|
|
1612
|
+
return node.textContent.length === 0 ? editor.commands.liftListItem("listItem") : editor.commands.splitListItem("listItem");
|
|
1613
|
+
}
|
|
1614
|
+
if (node.type.name === "blockquote") {
|
|
1615
|
+
if ($from.parent.textContent.length === 0) return editor.commands.lift("paragraph");
|
|
1616
|
+
break;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
return editor.commands.splitBlock();
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
});
|
|
1624
|
+
function isEmptyDoc(editor) {
|
|
1625
|
+
const doc2 = editor.state.doc;
|
|
1626
|
+
if (doc2.textContent.trim().length > 0) return false;
|
|
1627
|
+
let empty = true;
|
|
1628
|
+
doc2.descendants((node) => {
|
|
1629
|
+
if (node.isAtom && !node.isText && node.type.name !== "hardBreak") empty = false;
|
|
1630
|
+
});
|
|
1631
|
+
return empty;
|
|
1632
|
+
}
|
|
1633
|
+
function BoxFrame({ editor, marked = false, selection, placeholder, empty = false, attachments, footer, className }) {
|
|
1634
|
+
return /* @__PURE__ */ jsxs3("div", { className: cn(WRITING_BOX_CLASSES, "focus-within:border-border-strong transition-colors", className), children: [
|
|
1635
|
+
/* @__PURE__ */ jsxs3("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: [
|
|
1636
|
+
/* @__PURE__ */ jsx5(ScrollArea, { className: COMPOSE_SCROLL_CLASSES.area, viewportClassName: COMPOSE_SCROLL_CLASSES.viewport, contentClassName: COMPOSE_SCROLL_CLASSES.content, children: /* @__PURE__ */ jsx5(EditorContent, { editor }) }),
|
|
1637
|
+
selection && /* @__PURE__ */ jsx5(SelectionToolbar, { editor, ...selection }),
|
|
1638
|
+
empty && placeholder != null && /* @__PURE__ */ jsx5("div", { className: "pointer-events-none absolute inset-0 flex flex-wrap items-center gap-1 text-body-2 text-text-muted", children: placeholder })
|
|
1639
|
+
] }),
|
|
1640
|
+
attachments && /* @__PURE__ */ jsx5("div", { className: "flex flex-wrap gap-2", children: attachments }),
|
|
1641
|
+
footer
|
|
1642
|
+
] });
|
|
1643
|
+
}
|
|
1644
|
+
function SendBox({ editor, onSend, placeholder, tools, attachments, ready = false, holding = false, marked = false, selection, className }) {
|
|
1645
|
+
const [empty, setEmpty] = useState3(true);
|
|
1646
|
+
const canSend = (!empty || ready) && !holding;
|
|
1647
|
+
const send = useCallback3(() => {
|
|
1648
|
+
if (!editor || holding || isEmptyDoc(editor) && !ready) return true;
|
|
1649
|
+
if (onSend(editor) === false) return true;
|
|
1650
|
+
editor.commands.clearContent(true);
|
|
1651
|
+
editor.commands.focus();
|
|
1652
|
+
return true;
|
|
1653
|
+
}, [editor, holding, ready, onSend]);
|
|
1654
|
+
useEffect3(() => {
|
|
1655
|
+
if (!editor) return;
|
|
1656
|
+
const storage = editor.storage.composeKeys;
|
|
1657
|
+
if (!storage) return;
|
|
1658
|
+
storage.send = send;
|
|
1659
|
+
return () => {
|
|
1660
|
+
storage.send = null;
|
|
1661
|
+
};
|
|
1662
|
+
}, [editor, send]);
|
|
1663
|
+
useEffect3(() => {
|
|
1664
|
+
if (!editor) return;
|
|
1665
|
+
const read = () => setEmpty(isEmptyDoc(editor));
|
|
1666
|
+
read();
|
|
1667
|
+
editor.on("update", read);
|
|
1668
|
+
return () => {
|
|
1669
|
+
editor.off("update", read);
|
|
1670
|
+
};
|
|
1671
|
+
}, [editor]);
|
|
1672
|
+
return /* @__PURE__ */ jsx5("div", { className: cn("relative", className), children: /* @__PURE__ */ jsx5(
|
|
1673
|
+
BoxFrame,
|
|
1674
|
+
{
|
|
1675
|
+
editor,
|
|
1676
|
+
marked,
|
|
1677
|
+
selection: selection ?? {},
|
|
1678
|
+
placeholder,
|
|
1679
|
+
empty,
|
|
1680
|
+
attachments,
|
|
1681
|
+
footer: (
|
|
1682
|
+
// The tools are one strip — one Tab stop, arrows along it; Send, the answer rather than a tool, keeps its own.
|
|
1683
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between", children: [
|
|
1684
|
+
tools ? /* @__PURE__ */ jsx5(Toolbar2, { "aria-label": "Compose tools", surface: false, className: "flex items-center gap-1", children: tools }) : /* @__PURE__ */ jsx5("span", {}),
|
|
1685
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-2.5", children: [
|
|
1686
|
+
/* @__PURE__ */ jsx5("span", { className: "hidden select-none font-mono text-menu font-normal tracking-wider text-text-muted signal:inline", children: "Enter to send \xB7 Shift+Enter new line" }),
|
|
1687
|
+
/* @__PURE__ */ jsx5(
|
|
1688
|
+
IconButton,
|
|
1689
|
+
{
|
|
1690
|
+
variant: "primary",
|
|
1691
|
+
onMouseDown: (e) => {
|
|
1692
|
+
e.preventDefault();
|
|
1693
|
+
send();
|
|
1694
|
+
},
|
|
1695
|
+
onClick: (e) => {
|
|
1696
|
+
if (e.detail === 0) send();
|
|
1697
|
+
},
|
|
1698
|
+
disabled: !canSend,
|
|
1699
|
+
"aria-label": "Send",
|
|
1700
|
+
tooltip: "Send",
|
|
1701
|
+
tooltipShortcut: "Enter",
|
|
1702
|
+
glow: canSend,
|
|
1703
|
+
children: /* @__PURE__ */ jsx5(IconArrowUp, { size: 16, stroke: 1.5 })
|
|
1704
|
+
}
|
|
1705
|
+
)
|
|
1706
|
+
] })
|
|
1707
|
+
] })
|
|
1708
|
+
)
|
|
1709
|
+
}
|
|
1710
|
+
) });
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1694
1713
|
// src/ComposerTriggers.tsx
|
|
1695
1714
|
import { Extension as Extension8 } from "@tiptap/core";
|
|
1696
1715
|
import { PluginKey as PluginKey7 } from "@tiptap/pm/state";
|
|
@@ -2100,7 +2119,8 @@ var PasteOverWords = Extension9.create({
|
|
|
2100
2119
|
return false;
|
|
2101
2120
|
});
|
|
2102
2121
|
if (plain && LINK_ON_WORDS_TARGET.test(url) && !/[[\]\n]/.test(state.doc.textBetween(from, to))) {
|
|
2103
|
-
|
|
2122
|
+
const tr2 = state.tr.addMark(from, to, schema.marks.link.create({ href: url }));
|
|
2123
|
+
view.dispatch(tr2.setSelection(TextSelection2.create(tr2.doc, to)).removeStoredMark(schema.marks.link));
|
|
2104
2124
|
return true;
|
|
2105
2125
|
}
|
|
2106
2126
|
const before = state.doc.textBetween(Math.max(to - 1, $to.start()), to, "", "\uFFFC");
|
|
@@ -2255,13 +2275,117 @@ var BoxKeys = Extension11.create({
|
|
|
2255
2275
|
return {
|
|
2256
2276
|
"Mod-Enter": ({ editor }) => editor.storage.composeKeys?.send?.() ?? false,
|
|
2257
2277
|
// Open now, with no grace: the first Escape closes a list, the next is a deliberate cancel (suggestionPopup).
|
|
2258
|
-
Escape: () => isSuggestionOpen() ? false : this.options.onEscape()
|
|
2278
|
+
Escape: ({ editor }) => isSuggestionOpen() ? false : this.options.onEscape(editor)
|
|
2259
2279
|
};
|
|
2260
2280
|
}
|
|
2261
2281
|
});
|
|
2262
2282
|
var stillNamed = (removed, names) => [...removed].every((value) => names.includes(value)) ? removed : new Set([...removed].filter((value) => names.includes(value)));
|
|
2263
2283
|
var SQUARE = /* @__PURE__ */ jsx7(IconSquareRounded, { size: 16, stroke: 1.5, className: "text-text-secondary" });
|
|
2264
2284
|
var SMALL_SQUARE = /* @__PURE__ */ jsx7(IconSquareRounded, { size: 14, stroke: 1.5 });
|
|
2285
|
+
var NO_EXTENSIONS = [];
|
|
2286
|
+
var sameApp = (a, b) => a.referenceView === b.referenceView && a.extensions.length === b.extensions.length && a.extensions.every((one, i) => one === b.extensions[i]);
|
|
2287
|
+
function boxExtensions(hold, app) {
|
|
2288
|
+
const iconFor = (uri) => hold.current.referenceIcon?.(uri);
|
|
2289
|
+
return [
|
|
2290
|
+
BoxKit.configure({ link: { openOnClick: false } }),
|
|
2291
|
+
PasteOverWords,
|
|
2292
|
+
KeptSelection,
|
|
2293
|
+
ComposeKeys,
|
|
2294
|
+
BoxKeys.configure({
|
|
2295
|
+
onEscape: (ed) => {
|
|
2296
|
+
const editing = hold.current.edit;
|
|
2297
|
+
if (!editing) return false;
|
|
2298
|
+
const { selection } = ed.state;
|
|
2299
|
+
if (!selection.empty) {
|
|
2300
|
+
ed.commands.setTextSelection(selection.to);
|
|
2301
|
+
return true;
|
|
2302
|
+
}
|
|
2303
|
+
editing.onCancel();
|
|
2304
|
+
return true;
|
|
2305
|
+
}
|
|
2306
|
+
}),
|
|
2307
|
+
PersonMention.configure({ people: () => hold.current.people }),
|
|
2308
|
+
// An edit makes nobody urgent (CON-24): `!@` opens no list there, as `/` offers no Urgent.
|
|
2309
|
+
UrgentPersonMention.extend({
|
|
2310
|
+
addOptions() {
|
|
2311
|
+
const parent = this.parent();
|
|
2312
|
+
return { ...parent, suggestion: { ...parent.suggestion, allow: () => !hold.current.edit } };
|
|
2313
|
+
}
|
|
2314
|
+
}).configure({ people: () => hold.current.people }),
|
|
2315
|
+
CaptionedReference.configure({ icon: SMALL_SQUARE, iconFor }),
|
|
2316
|
+
ReferenceTrigger.configure({
|
|
2317
|
+
items: () => [],
|
|
2318
|
+
sections: (query) => hold.current.references?.(query) ?? [],
|
|
2319
|
+
subscribe: (listener) => hold.current.referencesChanged?.(listener) ?? (() => {
|
|
2320
|
+
}),
|
|
2321
|
+
ariaLabel: "References",
|
|
2322
|
+
sectionLabel: "References",
|
|
2323
|
+
icon: SQUARE,
|
|
2324
|
+
iconFor
|
|
2325
|
+
}),
|
|
2326
|
+
SlashCommands.configure({ sections: hold.sections }),
|
|
2327
|
+
ReferenceNode.configure({ view: app.referenceView }),
|
|
2328
|
+
PastedImages.configure({ onImages: (files) => hold.current.attach(files) }),
|
|
2329
|
+
...app.extensions
|
|
2330
|
+
];
|
|
2331
|
+
}
|
|
2332
|
+
function buildBox(app, options) {
|
|
2333
|
+
const hold = { current: { people: [], attach: () => false }, sections: [] };
|
|
2334
|
+
return { editor: new Editor({ ...options, extensions: boxExtensions(hold, app) }), hold };
|
|
2335
|
+
}
|
|
2336
|
+
var warmApp = null;
|
|
2337
|
+
var spare = null;
|
|
2338
|
+
var sparing = false;
|
|
2339
|
+
function scheduleSpare() {
|
|
2340
|
+
if (!warmApp || spare || sparing || typeof window === "undefined" || !window.requestIdleCallback) return;
|
|
2341
|
+
sparing = true;
|
|
2342
|
+
window.requestIdleCallback(() => {
|
|
2343
|
+
sparing = false;
|
|
2344
|
+
if (warmApp && !spare) spare = buildBox(warmApp, { autofocus: false });
|
|
2345
|
+
});
|
|
2346
|
+
}
|
|
2347
|
+
function useBoxEditor(app, content, options) {
|
|
2348
|
+
const args = useRef3({ app, content, options });
|
|
2349
|
+
args.current = { app, content, options };
|
|
2350
|
+
const [held, setHeld] = useState4(() => {
|
|
2351
|
+
const fits = !content && spare && !spare.editor.isDestroyed && warmApp && sameApp(warmApp, app);
|
|
2352
|
+
const taken = fits ? spare : null;
|
|
2353
|
+
if (taken) {
|
|
2354
|
+
spare = null;
|
|
2355
|
+
taken.editor.setOptions(options);
|
|
2356
|
+
}
|
|
2357
|
+
const one = taken ?? buildBox(app, { ...options, content });
|
|
2358
|
+
one.destroyAt = setTimeout(() => one.editor.destroy(), 1e4);
|
|
2359
|
+
scheduleSpare();
|
|
2360
|
+
return one;
|
|
2361
|
+
});
|
|
2362
|
+
useLayoutEffect(() => {
|
|
2363
|
+
clearTimeout(held.destroyAt);
|
|
2364
|
+
if (held.editor.isDestroyed) {
|
|
2365
|
+
const { app: now, content: opening, options: current } = args.current;
|
|
2366
|
+
setHeld(buildBox(now, { ...current, content: opening }));
|
|
2367
|
+
return;
|
|
2368
|
+
}
|
|
2369
|
+
return () => {
|
|
2370
|
+
held.destroyAt = setTimeout(() => held.editor.destroy(), 1);
|
|
2371
|
+
};
|
|
2372
|
+
}, [held]);
|
|
2373
|
+
const props = useRef3(options.editorProps);
|
|
2374
|
+
props.current = options.editorProps;
|
|
2375
|
+
const attributes = JSON.stringify(options.editorProps.attributes ?? {});
|
|
2376
|
+
useEffect4(() => {
|
|
2377
|
+
if (!held.editor.isDestroyed) held.editor.setOptions({ editorProps: props.current });
|
|
2378
|
+
}, [held, attributes]);
|
|
2379
|
+
return held;
|
|
2380
|
+
}
|
|
2381
|
+
var holdsUrgent = (editor) => {
|
|
2382
|
+
let found = false;
|
|
2383
|
+
editor.state.doc.descendants((node) => {
|
|
2384
|
+
if (node.type.name === "urgentMention") found = true;
|
|
2385
|
+
return !found;
|
|
2386
|
+
});
|
|
2387
|
+
return found;
|
|
2388
|
+
};
|
|
2265
2389
|
var fileCount = 0;
|
|
2266
2390
|
function CommentBox({
|
|
2267
2391
|
people,
|
|
@@ -2281,10 +2405,12 @@ function CommentBox({
|
|
|
2281
2405
|
accept,
|
|
2282
2406
|
closed,
|
|
2283
2407
|
referenceView,
|
|
2284
|
-
extensions =
|
|
2408
|
+
extensions = NO_EXTENSIONS,
|
|
2285
2409
|
autoFocus,
|
|
2286
2410
|
onSent,
|
|
2287
2411
|
onRefused,
|
|
2412
|
+
marked,
|
|
2413
|
+
onEditor,
|
|
2288
2414
|
className
|
|
2289
2415
|
}) {
|
|
2290
2416
|
const [files, setFiles] = useState4(edit?.files ?? []);
|
|
@@ -2294,8 +2420,8 @@ function CommentBox({
|
|
|
2294
2420
|
const [removed, setRemoved] = useState4(() => /* @__PURE__ */ new Set());
|
|
2295
2421
|
const picker = useRef3(null);
|
|
2296
2422
|
const root = useRef3(null);
|
|
2297
|
-
const latest = useRef3({ edit,
|
|
2298
|
-
latest.current = { edit,
|
|
2423
|
+
const latest = useRef3({ edit, upload, draft, under });
|
|
2424
|
+
latest.current = { edit, upload, draft, under };
|
|
2299
2425
|
const save = useRef3(() => false);
|
|
2300
2426
|
const attachFiles = useCallback4((picked) => {
|
|
2301
2427
|
const uploadOne = latest.current.upload;
|
|
@@ -2314,51 +2440,29 @@ function CommentBox({
|
|
|
2314
2440
|
return true;
|
|
2315
2441
|
}, []);
|
|
2316
2442
|
const rows = insert.filter((c) => !((edit || !upload) && c.key === commentBoxRows.file.key) && !(edit && c.key === commentBoxRows.urgent.key));
|
|
2317
|
-
const
|
|
2318
|
-
sections.splice(0, sections.length, formatSection(code), ...rows.length > 0 ? [{ label: "Insert", commands: rows }] : []);
|
|
2319
|
-
const iconFor = useCallback4((uri) => latest.current.referenceIcon?.(uri), []);
|
|
2320
|
-
const editor = useEditor({
|
|
2321
|
-
extensions: [
|
|
2322
|
-
BoxKit.configure({ link: { openOnClick: false } }),
|
|
2323
|
-
PasteOverWords,
|
|
2324
|
-
KeptSelection,
|
|
2325
|
-
ComposeKeys,
|
|
2326
|
-
BoxKeys.configure({
|
|
2327
|
-
onEscape: () => {
|
|
2328
|
-
const editing = latest.current.edit;
|
|
2329
|
-
if (!editing) return false;
|
|
2330
|
-
editing.onCancel();
|
|
2331
|
-
return true;
|
|
2332
|
-
}
|
|
2333
|
-
}),
|
|
2334
|
-
PersonMention.configure({ people: () => latest.current.people }),
|
|
2335
|
-
// An edit makes nobody urgent (CON-24): `!@` opens no list there, as `/` offers no Urgent.
|
|
2336
|
-
UrgentPersonMention.extend({
|
|
2337
|
-
addOptions() {
|
|
2338
|
-
const parent = this.parent();
|
|
2339
|
-
return { ...parent, suggestion: { ...parent.suggestion, allow: () => !latest.current.edit } };
|
|
2340
|
-
}
|
|
2341
|
-
}).configure({ people: () => latest.current.people }),
|
|
2342
|
-
CaptionedReference.configure({ icon: SMALL_SQUARE, iconFor }),
|
|
2343
|
-
ReferenceTrigger.configure({
|
|
2344
|
-
items: () => [],
|
|
2345
|
-
sections: (query) => latest.current.references?.(query) ?? [],
|
|
2346
|
-
subscribe: (listener) => latest.current.referencesChanged?.(listener) ?? (() => {
|
|
2347
|
-
}),
|
|
2348
|
-
ariaLabel: "References",
|
|
2349
|
-
sectionLabel: "References",
|
|
2350
|
-
icon: SQUARE,
|
|
2351
|
-
iconFor
|
|
2352
|
-
}),
|
|
2353
|
-
SlashCommands.configure({ sections }),
|
|
2354
|
-
ReferenceNode.configure({ view: referenceView ?? null }),
|
|
2355
|
-
PastedImages.configure({ onImages: attachFiles }),
|
|
2356
|
-
...extensions
|
|
2357
|
-
],
|
|
2358
|
-
content: edit?.body ?? draft?.read(),
|
|
2443
|
+
const { editor, hold } = useBoxEditor({ extensions, referenceView: referenceView ?? null }, edit?.body ?? draft?.read(), {
|
|
2359
2444
|
editable: !closed,
|
|
2360
2445
|
editorProps: { attributes: { class: COMPOSE_EDITOR_CLASSES, role: "textbox", "aria-multiline": "true", "aria-label": label } }
|
|
2361
2446
|
});
|
|
2447
|
+
hold.current = { edit, people, references, referencesChanged, referenceIcon, attach: attachFiles };
|
|
2448
|
+
hold.sections.splice(0, hold.sections.length, formatSection(code), ...rows.length > 0 ? [{ label: "Insert", commands: rows }] : []);
|
|
2449
|
+
const [marking, setMarking] = useState4(false);
|
|
2450
|
+
const markedBy = useRef3(marked);
|
|
2451
|
+
markedBy.current = marked;
|
|
2452
|
+
useLayoutEffect(() => {
|
|
2453
|
+
const read = () => setMarking(holdsUrgent(editor) || !!markedBy.current?.(editor));
|
|
2454
|
+
read();
|
|
2455
|
+
editor.on("update", read);
|
|
2456
|
+
return () => {
|
|
2457
|
+
editor.off("update", read);
|
|
2458
|
+
};
|
|
2459
|
+
}, [editor]);
|
|
2460
|
+
const handOut = useRef3(onEditor);
|
|
2461
|
+
handOut.current = onEditor;
|
|
2462
|
+
useEffect4(() => {
|
|
2463
|
+
handOut.current?.(editor);
|
|
2464
|
+
return () => handOut.current?.(null);
|
|
2465
|
+
}, [editor]);
|
|
2362
2466
|
useEffect4(() => {
|
|
2363
2467
|
if (!editor || edit) return;
|
|
2364
2468
|
const keep = () => {
|
|
@@ -2509,22 +2613,28 @@ function CommentBox({
|
|
|
2509
2613
|
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.` });
|
|
2510
2614
|
if (edit) {
|
|
2511
2615
|
return /* @__PURE__ */ jsxs5("div", { className: cn2("flex flex-col gap-1", className), children: [
|
|
2512
|
-
/* @__PURE__ */
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2616
|
+
/* @__PURE__ */ jsx7(
|
|
2617
|
+
BoxFrame,
|
|
2618
|
+
{
|
|
2619
|
+
editor,
|
|
2620
|
+
marked: marking,
|
|
2621
|
+
selection: { link: true },
|
|
2622
|
+
attachments: fileCards,
|
|
2623
|
+
className: cn2(sending && "[&_.ProseMirror]:text-text-muted"),
|
|
2624
|
+
footer: /* @__PURE__ */ jsxs5("div", { className: "flex items-center justify-between gap-2", children: [
|
|
2625
|
+
/* @__PURE__ */ jsxs5("span", { className: "flex items-center gap-1 text-caption text-text-muted", children: [
|
|
2626
|
+
/* @__PURE__ */ jsx7(Kbd, { children: "Esc" }),
|
|
2627
|
+
" to cancel \xB7 ",
|
|
2628
|
+
/* @__PURE__ */ jsx7(Kbd, { children: "Enter" }),
|
|
2629
|
+
" to save"
|
|
2630
|
+
] }),
|
|
2631
|
+
/* @__PURE__ */ jsxs5("div", { className: "flex items-center gap-2", children: [
|
|
2632
|
+
/* @__PURE__ */ jsx7(Button, { variant: "outlined", size: "small", onClick: edit.onCancel, children: "Cancel" }),
|
|
2633
|
+
/* @__PURE__ */ jsx7(Button, { variant: "primary", size: "small", disabled: uploading || sending, onClick: () => save.current(), children: "Save" })
|
|
2634
|
+
] })
|
|
2525
2635
|
] })
|
|
2526
|
-
|
|
2527
|
-
|
|
2636
|
+
}
|
|
2637
|
+
),
|
|
2528
2638
|
underBox,
|
|
2529
2639
|
sending && /* @__PURE__ */ jsx7(FieldLine, { children: "Saving\u2026" }),
|
|
2530
2640
|
refusedLine
|
|
@@ -2538,7 +2648,7 @@ function CommentBox({
|
|
|
2538
2648
|
};
|
|
2539
2649
|
return /* @__PURE__ */ jsxs5("div", { ref: root, className: cn2("flex flex-col gap-1", className), onDragOver: upload ? (e) => e.preventDefault() : void 0, onDrop, children: [
|
|
2540
2650
|
/* @__PURE__ */ jsx7(
|
|
2541
|
-
|
|
2651
|
+
SendBox,
|
|
2542
2652
|
{
|
|
2543
2653
|
editor,
|
|
2544
2654
|
onSend: go,
|
|
@@ -2546,6 +2656,7 @@ function CommentBox({
|
|
|
2546
2656
|
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,
|
|
2547
2657
|
attachments: fileCards,
|
|
2548
2658
|
ready,
|
|
2659
|
+
marked: marking,
|
|
2549
2660
|
holding: uploading || failed > 0 || sending,
|
|
2550
2661
|
selection: { link: true },
|
|
2551
2662
|
className: cn2(sending && "[&_[data-composer-editor]]:text-text-muted")
|
|
@@ -2564,7 +2675,7 @@ function CommentBox({
|
|
|
2564
2675
|
import { useCallback as useCallback5, useEffect as useEffect5, useImperativeHandle as useImperativeHandle2, useRef as useRef4, useState as useState5 } from "react";
|
|
2565
2676
|
import { Extension as Extension12, Node as Node3 } from "@tiptap/core";
|
|
2566
2677
|
import { history, redo, undo } from "@tiptap/pm/history";
|
|
2567
|
-
import { EditorContent as
|
|
2678
|
+
import { EditorContent as EditorContent2, useEditor } from "@tiptap/react";
|
|
2568
2679
|
import { cn as cn3 } from "@estiva-app/ui";
|
|
2569
2680
|
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
2570
2681
|
var VARIANT = {
|
|
@@ -2607,7 +2718,7 @@ function InlineText({ value, placeholder, label, onCommit, onText, onEnter, vari
|
|
|
2607
2718
|
if (pending.current === next) pending.current = null;
|
|
2608
2719
|
}
|
|
2609
2720
|
}, []);
|
|
2610
|
-
const editor =
|
|
2721
|
+
const editor = useEditor({
|
|
2611
2722
|
extensions: [OneLine, Paragraph, Text, Undo],
|
|
2612
2723
|
content: doc(value),
|
|
2613
2724
|
editable: !readOnly,
|
|
@@ -2674,7 +2785,7 @@ function InlineText({ value, placeholder, label, onCommit, onText, onEnter, vari
|
|
|
2674
2785
|
focus: (at = "start") => editor?.commands.focus(at)
|
|
2675
2786
|
}), [editor]);
|
|
2676
2787
|
return /* @__PURE__ */ jsxs6("div", { className: cn3("relative", VARIANT[variant], className), children: [
|
|
2677
|
-
/* @__PURE__ */ jsx8(
|
|
2788
|
+
/* @__PURE__ */ jsx8(EditorContent2, { editor, className: cn3(ROOM, !readOnly && "cursor-text") }),
|
|
2678
2789
|
empty && !readOnly && /* @__PURE__ */ jsx8("span", { "aria-hidden": true, className: "pointer-events-none absolute left-0 top-1 text-text-muted", children: placeholder })
|
|
2679
2790
|
] });
|
|
2680
2791
|
}
|
|
@@ -3398,7 +3509,7 @@ function EditorTableControls({ editor, children, className }) {
|
|
|
3398
3509
|
// src/DocumentEditor.tsx
|
|
3399
3510
|
import { useCallback as useCallback7, useEffect as useEffect7, useRef as useRef6, useState as useState7 } from "react";
|
|
3400
3511
|
import { TextSelection as TextSelection4 } from "@tiptap/pm/state";
|
|
3401
|
-
import { EditorContent as
|
|
3512
|
+
import { EditorContent as EditorContent3, useEditor as useEditor2, useEditorState as useEditorState2 } from "@tiptap/react";
|
|
3402
3513
|
import { TableKit } from "@tiptap/extension-table";
|
|
3403
3514
|
import { IconMessagePlus } from "@tabler/icons-react";
|
|
3404
3515
|
import { Button as Button2 } from "@estiva-app/ui";
|
|
@@ -3554,7 +3665,7 @@ function DocumentEditor({
|
|
|
3554
3665
|
};
|
|
3555
3666
|
const attachTo = useRef6(attach);
|
|
3556
3667
|
attachTo.current = attach;
|
|
3557
|
-
const editor =
|
|
3668
|
+
const editor = useEditor2(
|
|
3558
3669
|
{
|
|
3559
3670
|
extensions: [
|
|
3560
3671
|
DocumentKit.configure({
|
|
@@ -3688,7 +3799,7 @@ function DocumentEditor({
|
|
|
3688
3799
|
const who = changedBy?.name ?? "Someone";
|
|
3689
3800
|
const drawn = /* @__PURE__ */ jsxs9("div", { className: "flex flex-col gap-1", children: [
|
|
3690
3801
|
/* @__PURE__ */ jsxs9(EditorBlockHandle, { editor, actions: blockRows, children: [
|
|
3691
|
-
/* @__PURE__ */ jsx11(EditorTableControls, { editor, children: /* @__PURE__ */ jsx11(
|
|
3802
|
+
/* @__PURE__ */ jsx11(EditorTableControls, { editor, children: /* @__PURE__ */ jsx11(EditorContent3, { editor, className: "-mx-2 cursor-text px-2 py-1", "data-document-editor": "" }) }),
|
|
3692
3803
|
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 })
|
|
3693
3804
|
] }),
|
|
3694
3805
|
(!readOnly || onCommentOnSelection) && /* @__PURE__ */ jsx11(
|
|
@@ -3739,15 +3850,12 @@ function slashSections({ table, upload, pickFile }) {
|
|
|
3739
3850
|
export {
|
|
3740
3851
|
AttachmentNode,
|
|
3741
3852
|
BlockId,
|
|
3742
|
-
COMPOSE_EDITOR_CLASSES,
|
|
3743
3853
|
Callout,
|
|
3744
3854
|
CaptionedReference,
|
|
3745
3855
|
Checklist,
|
|
3746
3856
|
CodeBlockColours,
|
|
3747
3857
|
CommentBox,
|
|
3748
3858
|
CommentHighlights,
|
|
3749
|
-
ComposeBox,
|
|
3750
|
-
ComposeKeys,
|
|
3751
3859
|
DocumentEditor,
|
|
3752
3860
|
EditorBlockHandle,
|
|
3753
3861
|
EditorTableControls,
|