@vite-hub/ui 0.6.0 → 0.7.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/README.md +106 -46
- package/dist/AttachmentTitle-BWw0ck0T.js +110 -0
- package/dist/BubbleContent-B1a4e3vE.js +45 -0
- package/dist/Chat-BZxkf3Tt.js +112 -0
- package/dist/ChatMessage-Blr5F-zi.js +94 -0
- package/dist/CodeBlockContent-BjXJm8lO.js +92 -0
- package/dist/CodeBlockTitle-DYrYpc1U.js +99 -0
- package/dist/CommentRow-ViZ7r8nr.js +86 -0
- package/dist/CopyButton-Dtg_Oc9_.js +115 -0
- package/dist/Markdown-_w7feFzl.js +70 -0
- package/dist/MarkdownCodeBlock-B4j7x0H6.js +127 -0
- package/dist/MarkdownImage-CJN3myt4.js +111 -0
- package/dist/MessageHeader-CJ9eBHSS.js +61 -0
- package/dist/MessageParts-FVyYZNsn.js +57 -0
- package/dist/MessageScrollerViewport-BaTlWLki.js +142 -0
- package/dist/MorphText-CYTndbyp.js +36 -0
- package/dist/RollNumber-Bo2tzfAp.js +49 -0
- package/dist/TraceTitle-Cp0y7RRD.js +133 -0
- package/dist/agent-session-BwZSMi4S.d.ts +312 -0
- package/dist/agent-session-DhlTKCQG.js +875 -0
- package/dist/{announce-B0DLwflT.js → announce-CJNXaYbT.js} +1 -3
- package/dist/appendItems-hQ4aBd9Q.js +4047 -0
- package/dist/attachment-BllgHx9Q.d.ts +124 -0
- package/dist/attachment-DQMJNfj0.js +35 -0
- package/dist/avatar-stack-Bj1xUkzY.d.ts +4 -0
- package/dist/avatar-stack-nQErr0qn.js +72 -0
- package/dist/bubble-D3M2_InY.js +32 -0
- package/dist/bubble-DmplVxLr.d.ts +64 -0
- package/dist/chat-DWdyMSuj.d.ts +13 -0
- package/dist/chat-message-QLHnX_ED.d.ts +11 -0
- package/dist/chat-session-BOj5L3Ey.d.ts +29 -0
- package/dist/chat-session-hjZRL6jY.js +43 -0
- package/dist/choices-input-DqgXl5a-.d.ts +97 -0
- package/dist/client-BG-oCUtv-5i4sRwXP.js +6587 -0
- package/dist/code-block-Bp8y-XJp.d.ts +182 -0
- package/dist/code-block-CMERLfew.js +14 -0
- package/dist/code-view-26RY6dX8.js +137 -0
- package/dist/code-view-D8yYdFUc.d.ts +184 -0
- package/dist/{colors-BghReA9C-DEq4bhEP.js → colors-BghReA9C-A4M9YE0s.js} +1 -1
- package/dist/{comment-composer-BP-CJx7f.js → comment-composer-BUt6vbnr.js} +176 -38
- package/dist/{comment-composer-BI6CNJyO.d.ts → comment-composer-CIsbz-78.d.ts} +7 -7
- package/dist/comment-layer-BlVNORgj.d.ts +139 -0
- package/dist/comment-layer-Ck2H24oJ.js +1206 -0
- package/dist/comment-panel-Djx-KxVa.d.ts +173 -0
- package/dist/comment-selection-bar-CbOEI98x.d.ts +33 -0
- package/dist/comment-selection-bar-CxPkJxVl.js +145 -0
- package/dist/comment-send.css +2 -2
- package/dist/{comment-thread-5h93DXds.js → comment-thread-C_Q4UDaV.js} +78 -53
- package/dist/{comment-thread-DSkWODKG.d.ts → comment-thread-X6gYMNay.d.ts} +11 -14
- package/dist/comments-B1itauwb.d.ts +52 -0
- package/dist/{comments-D9dONfs9.js → comments-BaSrroRV.js} +65 -44
- package/dist/comments-BtD28xEn.js +390 -0
- package/dist/{comments-CnG_c-_c.d.ts → comments-ZfV6IZs8.d.ts} +15 -7
- package/dist/{comments-context-CrjhleVA.js → comments-context-3js2YFl2.js} +2 -2
- package/dist/components-CM5mZe0a.js +269 -0
- package/dist/{config-BDvnaVUn.js → config-CFwvNt4Y.js} +16 -29
- package/dist/{config-xL4EBeXw.d.ts → config-JmsTI7gs.d.ts} +21 -33
- package/dist/connection-status-BVSH2ZVo.js +72 -0
- package/dist/connection-status-g62BTn44.d.ts +37 -0
- package/dist/copy-button-CRiXUFsl.d.ts +17 -0
- package/dist/device-frame-BW6IjB6P.d.ts +78 -0
- package/dist/device-frame-DDWoyB-G.js +515 -0
- package/dist/diffs-BTKaVnsb.d.ts +272 -0
- package/dist/diffs.d.ts +3 -0
- package/dist/{pierre-code-view-C49BVDrc.js → diffs.js} +147 -4223
- package/dist/{draw-DzSmD7uo-Cb7s9kxJ.js → draw-DzSmD7uo-BvtKi0oE.js} +2 -2
- package/dist/drop-field-C0bXv1J-.d.ts +35 -0
- package/dist/drop-field-DKpYQ3tO.js +77 -0
- package/dist/editor-BsOTjnnN.d.ts +540 -0
- package/dist/{markdown-editor-3gY9MLvy.js → editor-DJPUs1nt.js} +877 -116
- package/dist/editor.d.ts +2 -0
- package/dist/editor.js +3 -0
- package/dist/element-BpjNQvZ0.js +6 -0
- package/dist/{file-tree-CRFIdtzw.js → file-tree-B4JKbp4r.js} +19 -18
- package/dist/{file-tree-DOtkeBaq.d.ts → file-tree-BdnKA6UA.d.ts} +33 -8
- package/dist/file-tree-DDSIafDn.d.ts +22 -0
- package/dist/file-tree-DS5shGSL.js +46 -0
- package/dist/file-tree.d.ts +2 -0
- package/dist/file-tree.js +1 -0
- package/dist/files-cuVXzWlx.js +30 -0
- package/dist/filter-search-C9e6sGij.d.ts +28 -0
- package/dist/filter-search-COZsoRiR.js +73 -0
- package/dist/formatCSSVariablePrefix-DLS1Ed1_.js +5 -0
- package/dist/headless-2IcUWHMq.d.ts +51 -0
- package/dist/headless.d.ts +7 -4
- package/dist/headless.js +5 -3
- package/dist/highlight.d.ts +2 -0
- package/dist/highlight.js +1 -0
- package/dist/{highlights-C2AbEdDI.js → highlights-8Al0-h-v.js} +3 -2
- package/dist/{hold-to-delete-BSMrpE-i.d.ts → hold-to-delete-CQc1JaG_.d.ts} +7 -0
- package/dist/{hold-to-delete-Cludb56v.js → hold-to-delete-CcQbfiQx.js} +111 -20
- package/dist/hold-to-delete-cOPqQ9FJ.js +85 -0
- package/dist/hold-to-delete-ksBE7wxc.d.ts +58 -0
- package/dist/index-9Z6Gwtnf.d.ts +77 -0
- package/dist/{index-B2cbt3py.d.ts → index-D3-uYBqH.d.ts} +1 -1
- package/dist/index.d.ts +165 -52
- package/dist/index.js +127 -670
- package/dist/markdown-BLALLOc0.d.ts +45 -0
- package/dist/{markdown-renderer-BgsmNqv7.js → markdown-DDyOdYq_.js} +13044 -12356
- package/dist/{parts/components/markdown-renderer.d.ts → markdown-DkDxdpMU.d.ts} +10 -7
- package/dist/markdown-editor.d.ts +51 -98
- package/dist/markdown-editor.js +70 -3
- package/dist/markdown.d.ts +2 -0
- package/dist/markdown.js +1 -0
- package/dist/marker-CvcWZ3Zp.d.ts +59 -0
- package/dist/marker-DNL6QR3L.js +63 -0
- package/dist/message-BwivYIEl.js +13 -0
- package/dist/message-DEq4K5cQ.d.ts +72 -0
- package/dist/message-parts-B1BZFVKe.d.ts +3 -0
- package/dist/message-parts-CG3gNWn8.d.ts +11 -0
- package/dist/message-parts.d.ts +2 -0
- package/dist/message-parts.js +1 -0
- package/dist/message-scroller-D7AvM31v.d.ts +41 -0
- package/dist/motion/core.d.ts +4 -4
- package/dist/motion/core.js +5 -11
- package/dist/motion-BH6ShUam.d.ts +12 -0
- package/dist/{effects-DEoFFycD.js → motion-core-BdTfxAhY.js} +1779 -55
- package/dist/{motion-core-DNl7TR1T.d.ts → motion-core-BfIefToe.d.ts} +32 -74
- package/dist/motion-dPwxx3Wk.js +76 -0
- package/dist/{install-qNaj4OY4.js → motion-itHFtXwA.js} +1 -1
- package/dist/motion-list-BBbz93WT.js +49 -0
- package/dist/motion.d.ts +5 -14
- package/dist/motion.js +6 -13
- package/dist/nuxt-ui-CPdiTwwD.js +22 -0
- package/dist/nuxt.d.ts +9 -5
- package/dist/nuxt.js +28 -32
- package/dist/parts/components/agent-session.d.ts +2 -252
- package/dist/parts/components/agent-session.js +1 -639
- package/dist/parts/components/attachment.d.ts +2 -85
- package/dist/parts/components/attachment.js +3 -72
- package/dist/parts/components/avatar-stack.d.ts +3 -2
- package/dist/parts/components/avatar-stack.js +1 -60
- package/dist/parts/components/bubble.d.ts +2 -69
- package/dist/parts/components/bubble.js +3 -52
- package/dist/parts/components/chat-message.d.ts +3 -25
- package/dist/parts/components/chat-message.js +1 -50
- package/dist/parts/components/chat-session.d.ts +2 -26
- package/dist/parts/components/chat-session.js +1 -37
- package/dist/parts/components/chat.d.ts +3 -52
- package/dist/parts/components/chat.js +1 -105
- package/dist/parts/components/code-block.d.ts +2 -102
- package/dist/parts/components/code-block.js +4 -109
- package/dist/parts/components/code-view.d.ts +3 -268
- package/dist/parts/components/code-view.js +1 -1
- package/dist/parts/components/comment-composer.d.ts +1 -1
- package/dist/parts/components/comment-composer.js +1 -1
- package/dist/parts/components/comment-layer.d.ts +1 -1
- package/dist/parts/components/comment-layer.js +1 -645
- package/dist/parts/components/comment-panel.d.ts +2 -2
- package/dist/parts/components/comment-panel.js +49 -40
- package/dist/parts/components/comment-selection-bar.d.ts +2 -2
- package/dist/parts/components/comment-selection-bar.js +1 -116
- package/dist/parts/components/comment-thread.d.ts +2 -2
- package/dist/parts/components/comment-thread.js +1 -3
- package/dist/parts/components/comments.d.ts +8 -9
- package/dist/parts/components/comments.js +6 -9
- package/dist/parts/components/connection-status.d.ts +2 -36
- package/dist/parts/components/connection-status.js +1 -64
- package/dist/parts/components/copy-button.d.ts +3 -126
- package/dist/parts/components/copy-button.js +3 -226
- package/dist/parts/components/device-frame.d.ts +2 -128
- package/dist/parts/components/device-frame.js +1 -470
- package/dist/parts/components/drop-field.d.ts +2 -67
- package/dist/parts/components/drop-field.js +1 -76
- package/dist/parts/components/file-tree.d.ts +3 -2
- package/dist/parts/components/file-tree.js +3 -1
- package/dist/parts/components/filter-search.d.ts +2 -45
- package/dist/parts/components/filter-search.js +1 -57
- package/dist/parts/components/hold-to-delete.d.ts +2 -80
- package/dist/parts/components/hold-to-delete.js +1 -75
- package/dist/parts/components/markdown.d.ts +3 -45
- package/dist/parts/components/markdown.js +1 -46
- package/dist/parts/components/marker.d.ts +2 -32
- package/dist/parts/components/marker.js +1 -22
- package/dist/parts/components/message-parts.d.ts +3 -25
- package/dist/parts/components/message-parts.js +1 -45
- package/dist/parts/components/message.d.ts +2 -32
- package/dist/parts/components/message.js +3 -22
- package/dist/parts/components/motion-list.d.ts +2 -40
- package/dist/parts/components/motion-list.js +1 -41
- package/dist/parts/components/motion.d.ts +5 -118
- package/dist/parts/components/motion.js +4 -171
- package/dist/parts/components/patch-parsers.d.ts +1 -1
- package/dist/parts/components/progress.d.ts +2 -39
- package/dist/parts/components/progress.js +1 -53
- package/dist/parts/components/prompt-input.d.ts +2 -134
- package/dist/parts/components/prompt-input.js +1 -253
- package/dist/parts/components/relative-time.d.ts +2 -71
- package/dist/parts/components/relative-time.js +1 -1
- package/dist/parts/components/status.d.ts +2 -58
- package/dist/parts/components/status.js +1 -47
- package/dist/parts/components/sync-status.d.ts +2 -22
- package/dist/parts/components/sync-status.js +1 -48
- package/dist/parts/components/tool-list.d.ts +2 -28
- package/dist/parts/components/tool-list.js +1 -118
- package/dist/parts/components/trace-run.d.ts +2 -25
- package/dist/parts/components/trace-run.js +1 -89
- package/dist/parts/components/trace.d.ts +2 -59
- package/dist/parts/components/trace.js +1 -76
- package/dist/parts/composables/attachments.js +75 -1
- package/dist/parts/headless/choices-input.d.ts +2 -2
- package/dist/parts/headless/choices-input.js +49 -37
- package/dist/parts/headless/comments.d.ts +1 -1
- package/dist/parts/headless/comments.js +1 -1
- package/dist/parts/headless/message-scroller.d.ts +2 -2
- package/dist/parts/headless/message-scroller.js +211 -309
- package/dist/parts/headless/relative-time.d.ts +2 -0
- package/dist/parts/headless/relative-time.js +1 -0
- package/dist/parts/workspace/browser-support-notice.d.ts +1 -1
- package/dist/parts/workspace/browser-support-notice.js +6 -5
- package/dist/parts/workspace/connect-panel.js +1 -1
- package/dist/parts/workspace/runners/web-container.js +2 -2
- package/dist/parts/workspace/workspace-bar.d.ts +1 -1
- package/dist/parts/workspace/workspace-bar.js +1 -1
- package/dist/parts/workspace/workspace-boot-status.d.ts +1 -1
- package/dist/parts/workspace/workspace-boot-status.js +1 -206
- package/dist/parts/workspace/workspace-editor-head.d.ts +1 -1
- package/dist/parts/workspace/workspace-editor-head.js +1 -1
- package/dist/parts/workspace/workspace-editor.d.ts +2 -2
- package/dist/parts/workspace/workspace-examples.js +1 -1
- package/dist/parts/workspace/workspace-file-tree.d.ts +1 -1
- package/dist/parts/workspace/workspace-file-tree.js +3 -2
- package/dist/parts/workspace/workspace-guide.js +1 -1
- package/dist/parts/workspace/workspace-preview.d.ts +1 -1
- package/dist/parts/workspace/workspace-preview.js +14 -12
- package/dist/parts/workspace/workspace-shell.d.ts +1 -1
- package/dist/parts/workspace/workspace-shell.js +11 -11
- package/dist/parts/workspace/workspace-sidebar.d.ts +3 -3
- package/dist/parts/workspace/workspace-sidebar.js +2 -2
- package/dist/parts/workspace/workspace-start.js +1 -1
- package/dist/parts/workspace/workspace-steps.js +1 -1
- package/dist/parts/workspace/workspace.d.ts +4 -4
- package/dist/parts/workspace/workspace.js +5 -5
- package/dist/press-BuEC-XvZ.d.ts +83 -0
- package/dist/progress-Ch0fA-bf.d.ts +8 -0
- package/dist/progress-D_9sG648.js +47 -0
- package/dist/prompt-input-CRXEJBAK.js +412 -0
- package/dist/prompt-input-j4OFTF5p.d.ts +116 -0
- package/dist/relative-time-BnJfjeEm.js +131 -0
- package/dist/relative-time-BuP-Gvzn.d.ts +43 -0
- package/dist/{relative-time-DJnw45tr.js → relative-time-Dz2DR4eb.js} +64 -114
- package/dist/relative-time-grHFu1kY.d.ts +11 -0
- package/dist/{ring-BN4d8vtw.js → ring-DoL9jivj.js} +64 -14
- package/dist/runtime/nuxt-plugin.js +2 -5
- package/dist/{sankey-CAYwt82B-BAAk7WkJ.js → sankey-CAYwt82B-e6k34wtW.js} +3 -3
- package/dist/{shiki-CbfEu_Az.js → shiki-CxzM_xNo.js} +3 -2
- package/dist/stand-ins-CuKM1UH1.js +339 -0
- package/dist/status-B2Yhrwv8.js +67 -0
- package/dist/status-ySiRa-8O.d.ts +38 -0
- package/dist/{stream-tokenizer-ByC3l0HQ.js → stream-tokenizer-BsjV6wxW.js} +1 -1
- package/dist/styles.css +4315 -3362
- package/dist/sync-status-BRroyOre.js +59 -0
- package/dist/sync-status-D4KdGO6y.d.ts +35 -0
- package/dist/theme.css +3 -0
- package/dist/theme.d.ts +14 -0
- package/dist/theme.js +19 -8
- package/dist/{themes-DKugPHlg.js → themes-B0_ioVT0.js} +1 -1
- package/dist/tool-list-DDaCqpR6.js +209 -0
- package/dist/tool-list-DMRPM0Yi.d.ts +50 -0
- package/dist/trace-KCBvOsw_.d.ts +113 -0
- package/dist/trace-run-Dk962P5a.d.ts +49 -0
- package/dist/trace-run-nh6FIsl6.js +202 -0
- package/dist/{opt-out-D66l60sg.js → tween-lVMRCUEv.js} +60 -1
- package/dist/types-BF_U0tgp.d.ts +74 -0
- package/dist/types-CTk3aNb5.d.ts +15 -0
- package/dist/types-D0a3i4Fw.d.ts +21 -0
- package/dist/types-DTecvcsZ.d.ts +35 -0
- package/dist/types-D_BWab7g.d.ts +75 -0
- package/dist/types-RHaQ4gj1.d.ts +27 -0
- package/dist/ui-components-CKQAPI-W.js +7 -0
- package/dist/unwrapDefault-CExq-4rm.js +5 -0
- package/dist/use-copy-DK1SSZkh.js +66 -0
- package/dist/utils-hi9-xROt.js +37 -0
- package/dist/vite.d.ts +0 -1
- package/dist/vite.js +8 -14
- package/dist/{vue-Cs_HmYsp.js → vue-DdYvDVOr.js} +1 -1
- package/dist/workspace-boot-status-CyGlJS06.js +216 -0
- package/dist/{workspace-shell-ChCwWPyv.d.ts → workspace-shell-B4A7CINd.d.ts} +1 -1
- package/dist/workspace.d.ts +1 -1
- package/dist/workspace.js +1 -2
- package/package.json +49 -15
- package/dist/attachments-DgwoQZKY.js +0 -88
- package/dist/avatar-stack-C0IKwj6g.d.ts +0 -57
- package/dist/choices-input-BUf-QqGj.d.ts +0 -92
- package/dist/code-view-Cg4nyTNA.js +0 -172
- package/dist/comment-attachments-CMpYOJod.js +0 -19
- package/dist/comment-layer-Ba2DV4L7.d.ts +0 -174
- package/dist/comment-list-BJdZu0DS.d.ts +0 -60
- package/dist/comment-panel-DISGe7yM.d.ts +0 -206
- package/dist/comment-person-D_IyIjXo.js +0 -39
- package/dist/comment-pin-C5UeLPTa.d.ts +0 -66
- package/dist/comment-row-DPMWI5Z0.js +0 -38
- package/dist/comment-selection-bar-CVuS-FNL.d.ts +0 -40
- package/dist/comment-send-CH46zawK.js +0 -275
- package/dist/comment-send-MmxFsOQf.d.ts +0 -23
- package/dist/drop-field-CNZgwFVO.js +0 -162
- package/dist/editor-BuByBIkJ.js +0 -620
- package/dist/format-Bc9m7-r0.js +0 -38
- package/dist/handlers-CnbkvXjX.js +0 -181
- package/dist/icon-XZaCUZTG.d.ts +0 -29
- package/dist/image-preview-EqfPcFZ9.js +0 -104
- package/dist/index-B_PSX-5h.d.ts +0 -69
- package/dist/list-DUTAo0uC.js +0 -270
- package/dist/markdown-editor-B7gD60tp.d.ts +0 -189
- package/dist/message-scroller-a6qaYHno.d.ts +0 -173
- package/dist/nuxt-ui-7ByUrymx.js +0 -43
- package/dist/parts/components/comment-list.d.ts +0 -2
- package/dist/parts/components/comment-list.js +0 -172
- package/dist/parts/components/comment-pin.d.ts +0 -2
- package/dist/parts/components/comment-pin.js +0 -74
- package/dist/parts/components/comment-send.d.ts +0 -2
- package/dist/parts/components/comment-send.js +0 -1
- package/dist/parts/components/markdown-editor.d.ts +0 -2
- package/dist/parts/components/markdown-editor.js +0 -1
- package/dist/parts/components/markdown-renderer.js +0 -1
- package/dist/payload-text-DQNRbJY5.js +0 -31
- package/dist/progress-DL9k-ERG.js +0 -265
- package/dist/registry-DAIjCjWd.js +0 -77
- package/dist/slot-part-BWHvQ3mK.js +0 -25
- package/dist/text-BWzZFnGY.js +0 -822
- package/dist/travel-CwVhU_GS.js +0 -180
- package/dist/tween-Dv3IIIQG.js +0 -61
- package/dist/types-Ceh7h7NT.d.ts +0 -31
- package/dist/visual-copy-CHHBfJ6O.js +0 -14
- package/dist/vue-BlknIGIm.js +0 -2501
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as shikiDark, S as theme, T as isElement$2, c as rowsOf, d as src_default, f as src_default$2, g as hash, h as src_default$3, m as src_default$1, r as Properties, t as createProgress, u as addStyles, v as scalar, w as childrenOf$1 } from "./client-BG-oCUtv-5i4sRwXP.js";
|
|
2
2
|
import { t as uiErrorDiagnostics } from "./error-diagnostics-BlgA9rI2.js";
|
|
3
|
-
import { n as
|
|
4
|
-
import { r as
|
|
5
|
-
import {
|
|
3
|
+
import { n as useViteHubUIIcons } from "./config-CFwvNt4Y.js";
|
|
4
|
+
import { r as createMotionList } from "./motion-core-BdTfxAhY.js";
|
|
5
|
+
import { i as useStandIn } from "./stand-ins-CuKM1UH1.js";
|
|
6
|
+
import { Comment, Fragment, computed, defineComponent, h, inject, isVNode, onBeforeUnmount, onMounted, onScopeDispose, provide, ref, shallowRef, unref, watch, watchEffect } from "vue";
|
|
6
7
|
import { defineDiagnostics } from "nostics";
|
|
7
|
-
import {
|
|
8
|
+
import { Tooltip, TooltipContent, TooltipShortcut, TooltipTrigger } from "@ui-sdk/vue/tooltip";
|
|
9
|
+
import { Menu, MenuContent, MenuGroup, MenuGroupLabel, MenuItem, MenuItemIcon, MenuSeparator, MenuTrigger } from "@ui-sdk/vue/menu";
|
|
8
10
|
import { defineComarkPlugin, parseMarkdown } from "comark";
|
|
9
11
|
import { indent } from "comark/utils";
|
|
10
12
|
import { renderFrontmatter, renderMarkdown } from "comark/render";
|
|
@@ -18,8 +20,16 @@ import components from "comark/plugins/components";
|
|
|
18
20
|
import frontmatterPlugin from "comark/plugins/frontmatter";
|
|
19
21
|
import taskList from "comark/plugins/task-list";
|
|
20
22
|
import { parseFrontmatter } from "comark/parse";
|
|
21
|
-
import { Plugin as Plugin$1, PluginKey } from "@tiptap/pm/state";
|
|
23
|
+
import { NodeSelection, Plugin as Plugin$1, PluginKey } from "@tiptap/pm/state";
|
|
22
24
|
import { Decoration, DecorationSet } from "@tiptap/pm/view";
|
|
25
|
+
import { Editor as Editor$1, EditorContent, NodeViewContent, NodeViewWrapper, VueNodeViewRenderer, nodeViewProps } from "@tiptap/vue-3";
|
|
26
|
+
import { flip, offset, shift } from "@floating-ui/dom";
|
|
27
|
+
import DragHandle from "@tiptap/extension-drag-handle-vue-3";
|
|
28
|
+
import { ReplaceStep } from "@tiptap/pm/transform";
|
|
29
|
+
import { BubbleMenu } from "@tiptap/vue-3/menus";
|
|
30
|
+
import { Toggle, ToggleIcon } from "@ui-sdk/vue/toggle";
|
|
31
|
+
import { Toolbar, ToolbarButton, ToolbarGroup, ToolbarSeparator } from "@ui-sdk/vue/toolbar";
|
|
32
|
+
import { TriggerMenu, TriggerMenuContent, TriggerMenuGroup, TriggerMenuGroupLabel, TriggerMenuItem, TriggerMenuItemIcon, TriggerMenuList, TriggerMenuSeparator, TriggerMenuStatus } from "@ui-sdk/vue/trigger-menu";
|
|
23
33
|
// ../blob/dist/object-DRSmpe04.js
|
|
24
34
|
/** A non-null object that is not an array. Functions do not pass. */
|
|
25
35
|
function isRecord(value) {
|
|
@@ -227,7 +237,7 @@ function sendWithProgress(url, init, onProgress) {
|
|
|
227
237
|
request.send(init.body);
|
|
228
238
|
});
|
|
229
239
|
}
|
|
230
|
-
// ../../node_modules/.pnpm/comark-ui@0.
|
|
240
|
+
// ../../node_modules/.pnpm/comark-ui@0.14.3_@comark+html@0.9.2_katex@0.19.1_shiki@4.6.0__@tiptap+core@3.35.0_@tipt_12c0f6863a75018f6c283382c6d06ad0/node_modules/comark-ui/dist/editor-Z2zhidij.mjs
|
|
231
241
|
const typesWithProps = [
|
|
232
242
|
"paragraph",
|
|
233
243
|
"heading",
|
|
@@ -1399,6 +1409,24 @@ async function readPage(markdown, { plugins = [], registerDefaultPlugins }) {
|
|
|
1399
1409
|
registerDefaultPlugins,
|
|
1400
1410
|
plugins: [sourceKey(), ...plugins]
|
|
1401
1411
|
});
|
|
1412
|
+
let tooltip = 0;
|
|
1413
|
+
const normalize = (nodes, properties = false) => {
|
|
1414
|
+
for (const node of nodes) {
|
|
1415
|
+
if (!Array.isArray(node)) continue;
|
|
1416
|
+
const inProperties = properties || node[0] === "properties";
|
|
1417
|
+
if (inProperties && node[0] === "time" && node[1].class === "ctm") {
|
|
1418
|
+
const id = node[1]["aria-describedby"];
|
|
1419
|
+
const tip = node.slice(2).find((child) => Array.isArray(child) && child[0] === "span" && child[1].class === "ctm-tip" && child[1].role === "tooltip" && child[1].id === id);
|
|
1420
|
+
if (typeof id === "string" && id.startsWith("cfm-") && Array.isArray(tip)) {
|
|
1421
|
+
const canonical = `cfm-tooltip-${tooltip++}`;
|
|
1422
|
+
node[1]["aria-describedby"] = canonical;
|
|
1423
|
+
tip[1].id = canonical;
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
normalize(node.slice(2), inProperties);
|
|
1427
|
+
}
|
|
1428
|
+
};
|
|
1429
|
+
normalize(tree.nodes);
|
|
1402
1430
|
const read = JSON.stringify({
|
|
1403
1431
|
nodes: tree.nodes,
|
|
1404
1432
|
frontmatter: tree.frontmatter
|
|
@@ -1418,8 +1446,7 @@ const uploadCss = `@layer comark{${[
|
|
|
1418
1446
|
`.cue-upload>img,.cue-upload>video{grid-area:1/1;width:100%;max-height:10rem;object-fit:cover;opacity:.55}`,
|
|
1419
1447
|
`.cue-upload-label{grid-area:1/1;align-self:end;padding:.375rem .5rem .5rem;font-variant-numeric:tabular-nums;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}`,
|
|
1420
1448
|
`.cue-upload>img~.cue-upload-label,.cue-upload>video~.cue-upload-label{background:color-mix(in srgb,var(--_comark-background) 80%,transparent)}`,
|
|
1421
|
-
`.cue-upload
|
|
1422
|
-
`@media (prefers-reduced-motion:reduce){.cue-upload::after{transition:none}}`
|
|
1449
|
+
`.cue-upload-bar{grid-area:2/1;padding:0 .5rem .375rem;color:var(--_comark-primary);--vh-progress-rail:var(--_comark-border)}`
|
|
1423
1450
|
].join("")}}`;
|
|
1424
1451
|
function placeholder(pending) {
|
|
1425
1452
|
addStyles("editor-upload", uploadCss);
|
|
@@ -1441,15 +1468,19 @@ function placeholder(pending) {
|
|
|
1441
1468
|
const label = document.createElement("span");
|
|
1442
1469
|
label.className = "cue-upload-label";
|
|
1443
1470
|
label.setAttribute("role", "status");
|
|
1444
|
-
|
|
1471
|
+
const bar = document.createElement("span");
|
|
1472
|
+
bar.className = "cue-upload-bar";
|
|
1473
|
+
root.append(label, bar);
|
|
1474
|
+
const progress = createProgress(bar, { label: `Upload ${pending.file.name}` });
|
|
1445
1475
|
const show = (fraction) => {
|
|
1446
|
-
|
|
1476
|
+
progress.set(fraction === null || fraction >= 1 ? null : fraction);
|
|
1447
1477
|
label.textContent = fraction === null ? `Uploading ${pending.file.name}` : `Uploading ${pending.file.name}, ${Math.round(fraction * 100)}%`;
|
|
1448
1478
|
};
|
|
1449
1479
|
show(pending.fraction);
|
|
1450
1480
|
return {
|
|
1451
1481
|
root,
|
|
1452
|
-
show
|
|
1482
|
+
show,
|
|
1483
|
+
progress
|
|
1453
1484
|
};
|
|
1454
1485
|
}
|
|
1455
1486
|
/**
|
|
@@ -1531,6 +1562,7 @@ function insertImage(tr, pos, image) {
|
|
|
1531
1562
|
let nextId = 1;
|
|
1532
1563
|
const pendingUploads = /* @__PURE__ */ new Map();
|
|
1533
1564
|
const elements = /* @__PURE__ */ new Map();
|
|
1565
|
+
const bars = /* @__PURE__ */ new WeakMap();
|
|
1534
1566
|
function uploadWidget(pos, id, batch) {
|
|
1535
1567
|
return Decoration.widget(pos, () => {
|
|
1536
1568
|
const element = placeholder(pendingUploads.get(id) ?? {
|
|
@@ -1539,13 +1571,17 @@ function uploadWidget(pos, id, batch) {
|
|
|
1539
1571
|
fraction: null
|
|
1540
1572
|
});
|
|
1541
1573
|
elements.set(id, element);
|
|
1574
|
+
bars.set(element.root, element.progress);
|
|
1542
1575
|
return element.root;
|
|
1543
1576
|
}, {
|
|
1544
1577
|
id,
|
|
1545
1578
|
batch,
|
|
1546
1579
|
key: String(id),
|
|
1547
1580
|
side: -1,
|
|
1548
|
-
destroy: () =>
|
|
1581
|
+
destroy: (node) => {
|
|
1582
|
+
bars.get(node)?.destroy();
|
|
1583
|
+
if (elements.get(id)?.root === node) elements.delete(id);
|
|
1584
|
+
}
|
|
1549
1585
|
});
|
|
1550
1586
|
}
|
|
1551
1587
|
/** The plugin alone, for a ProseMirror editor without Tiptap. */
|
|
@@ -1689,7 +1725,7 @@ Extension.create({
|
|
|
1689
1725
|
})];
|
|
1690
1726
|
}
|
|
1691
1727
|
});
|
|
1692
|
-
// ../../node_modules/.pnpm/comark-ui@0.
|
|
1728
|
+
// ../../node_modules/.pnpm/comark-ui@0.14.3_@comark+html@0.9.2_katex@0.19.1_shiki@4.6.0__@tiptap+core@3.35.0_@tipt_12c0f6863a75018f6c283382c6d06ad0/node_modules/comark-ui/dist/editor-vue.mjs
|
|
1693
1729
|
function readProp(props, name, type) {
|
|
1694
1730
|
if (Object.hasOwn(props, name)) {
|
|
1695
1731
|
const value = props[name];
|
|
@@ -1730,6 +1766,7 @@ const shown = (value) => isString(value) ? value : JSON.stringify(value);
|
|
|
1730
1766
|
const CHROME = "data-cev-chrome";
|
|
1731
1767
|
const stopEvent = ({ event }) => event.target instanceof Element && event.target.closest(`[${CHROME}]`) !== null;
|
|
1732
1768
|
let count = 0;
|
|
1769
|
+
const anchored = () => CSS.supports("(anchor-name: --a) and (position-area: top) and (position-try-fallbacks: flip-block) and (justify-self: anchor-center)");
|
|
1733
1770
|
/** Places an open panel under its button, or above it when there's no room below, inside the viewport. */
|
|
1734
1771
|
function place(panel, anchor) {
|
|
1735
1772
|
const box = anchor.getBoundingClientRect();
|
|
@@ -1767,8 +1804,9 @@ const ComponentView = defineComponent({
|
|
|
1767
1804
|
value: ""
|
|
1768
1805
|
});
|
|
1769
1806
|
const drafts = ref(/* @__PURE__ */ new Map());
|
|
1807
|
+
let follow = false;
|
|
1770
1808
|
const reposition = () => {
|
|
1771
|
-
if (panel.value && button.value && panel.value.matches(":popover-open")) place(panel.value, button.value);
|
|
1809
|
+
if (follow && panel.value && button.value && panel.value.matches(":popover-open")) place(panel.value, button.value);
|
|
1772
1810
|
};
|
|
1773
1811
|
function toggle() {
|
|
1774
1812
|
if (!panel.value?.matches(":popover-open")) return;
|
|
@@ -1778,6 +1816,8 @@ const ComponentView = defineComponent({
|
|
|
1778
1816
|
}
|
|
1779
1817
|
onMounted(() => {
|
|
1780
1818
|
addStyles("editor-component-view", componentViewCss);
|
|
1819
|
+
if (anchored()) return;
|
|
1820
|
+
follow = true;
|
|
1781
1821
|
addEventListener("scroll", reposition, true);
|
|
1782
1822
|
addEventListener("resize", reposition);
|
|
1783
1823
|
});
|
|
@@ -1939,6 +1979,7 @@ const ComponentView = defineComponent({
|
|
|
1939
1979
|
ref: panel,
|
|
1940
1980
|
id,
|
|
1941
1981
|
class: "cev-panel",
|
|
1982
|
+
style: `position-anchor:--${id}`,
|
|
1942
1983
|
popover: "auto",
|
|
1943
1984
|
[CHROME]: "",
|
|
1944
1985
|
contenteditable: "false",
|
|
@@ -1967,6 +2008,7 @@ const ComponentView = defineComponent({
|
|
|
1967
2008
|
ref: button,
|
|
1968
2009
|
type: "button",
|
|
1969
2010
|
class: "cev-tag",
|
|
2011
|
+
style: `anchor-name:--${id}`,
|
|
1970
2012
|
popovertarget: id,
|
|
1971
2013
|
title: summary || void 0,
|
|
1972
2014
|
contenteditable: "false",
|
|
@@ -1994,6 +2036,7 @@ const ComponentView = defineComponent({
|
|
|
1994
2036
|
ref: button,
|
|
1995
2037
|
type: "button",
|
|
1996
2038
|
class: "cev-props",
|
|
2039
|
+
style: `anchor-name:--${id}`,
|
|
1997
2040
|
popovertarget: id
|
|
1998
2041
|
}, [h("span", { class: "cev-visually-hidden" }, `Props of ${title}: `), summary || (can ? "Add props" : "No props")]),
|
|
1999
2042
|
html ? null : content
|
|
@@ -2035,8 +2078,9 @@ const componentViewCss = `@layer comark{${[
|
|
|
2035
2078
|
`.cev-block [data-comark-slot]::before{content:"#" attr(data-comark-slot);display:block;padding-top:.25rem;color:var(--_comark-muted);font:500 .6875rem/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;user-select:none}`,
|
|
2036
2079
|
`.cev-inline{padding:0 .125rem 0 .25rem;border:1px solid var(--_comark-border);border-radius:calc(var(--_comark-radius)*.75);background:var(--_comark-accent)}`,
|
|
2037
2080
|
`.cev-tag{display:inline-flex;align-items:center;gap:.25rem;margin-inline-start:.25rem;padding:0 .25rem;border:0;border-radius:calc(var(--_comark-radius)*.5);background:none;color:var(--_comark-muted);font:500 max(.75em,.6875rem)/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;vertical-align:baseline;cursor:pointer;user-select:none}`,
|
|
2038
|
-
`.cev-panel{position:fixed;inset:auto;margin:0;width:18rem;max-height:min(24rem,
|
|
2081
|
+
`.cev-panel{position:fixed;inset:auto;margin:0;width:18rem;max-height:min(24rem,50vh - 3.5rem);overflow:auto;padding:.75rem;border:1px solid var(--_comark-border);border-radius:var(--_comark-radius);background:var(--_comark-background);color:var(--_comark-foreground);box-shadow:var(--_comark-shadow);font:400 .8125rem/1.4 var(--_comark-font);white-space:normal}`,
|
|
2039
2082
|
`.cev-panel:popover-open{display:grid;gap:.625rem}`,
|
|
2083
|
+
`@supports (anchor-name: --a) and (position-area: top) and (position-try-fallbacks: flip-block) and (justify-self: anchor-center){.cev-panel{position-area:block-end span-inline-end;position-try-fallbacks:flip-block,flip-inline,flip-block flip-inline;margin:4px 8px 8px 0}}`,
|
|
2040
2084
|
`.cev-panel-title{display:flex;align-items:baseline;justify-content:space-between;gap:.5rem;margin:0;font-weight:600}`,
|
|
2041
2085
|
`.cev-panel-title .cev-code,.cev-tag-name{color:var(--_comark-muted);font-weight:500}`,
|
|
2042
2086
|
`.cev-field{display:grid;gap:.25rem}`,
|
|
@@ -2249,7 +2293,7 @@ function useComarkEditor(markdown, options = {}) {
|
|
|
2249
2293
|
components,
|
|
2250
2294
|
field
|
|
2251
2295
|
});
|
|
2252
|
-
editor.value = new Editor({
|
|
2296
|
+
editor.value = new Editor$1({
|
|
2253
2297
|
extensions: [ComarkKit.configure({
|
|
2254
2298
|
componentView: view,
|
|
2255
2299
|
...options.kit
|
|
@@ -2335,7 +2379,186 @@ defineComponent({
|
|
|
2335
2379
|
};
|
|
2336
2380
|
}
|
|
2337
2381
|
});
|
|
2338
|
-
// src/
|
|
2382
|
+
// src/editor/handlers.ts
|
|
2383
|
+
/**
|
|
2384
|
+
* The key that the editor parts read their handlers from, as a `Ref<EditorHandlers>`. It is the string that Nuxt UI's
|
|
2385
|
+
* editor components inject, so one `provide()` serves both sets.
|
|
2386
|
+
*/
|
|
2387
|
+
const editorHandlersKey = "editorHandlers";
|
|
2388
|
+
function isNodeTypeSelected(editor, types) {
|
|
2389
|
+
const { $from, to } = editor.state.selection;
|
|
2390
|
+
let found = false;
|
|
2391
|
+
editor.state.doc.nodesBetween($from.pos, to, (node) => {
|
|
2392
|
+
if (types.includes(node.type.name)) found = true;
|
|
2393
|
+
});
|
|
2394
|
+
return found;
|
|
2395
|
+
}
|
|
2396
|
+
const hasExtension = (editor, name) => editor.extensionManager.extensions.some((extension) => extension.name === name);
|
|
2397
|
+
const blocked = (editor) => isNodeTypeSelected(editor, ["image"]) || editor.isActive("code");
|
|
2398
|
+
function blockHandler(name, toggle, can) {
|
|
2399
|
+
return {
|
|
2400
|
+
canExecute: can,
|
|
2401
|
+
execute: (editor) => toggle(editor.chain().focus()),
|
|
2402
|
+
isActive: (editor) => editor.isActive(name),
|
|
2403
|
+
isDisabled: blocked
|
|
2404
|
+
};
|
|
2405
|
+
}
|
|
2406
|
+
const listItemTypes = ["bulletList", "orderedList"];
|
|
2407
|
+
function listHandler(type) {
|
|
2408
|
+
const toggle = (chain) => type === "bulletList" ? chain.toggleBulletList() : chain.toggleOrderedList();
|
|
2409
|
+
const inAnyList = (editor) => listItemTypes.some((name) => hasExtension(editor, name) && editor.isActive(name));
|
|
2410
|
+
return {
|
|
2411
|
+
canExecute: (editor) => (type === "bulletList" ? editor.can().toggleBulletList() : editor.can().toggleOrderedList()) || editor.isActive("listItem") || inAnyList(editor),
|
|
2412
|
+
execute: (editor) => {
|
|
2413
|
+
const { selection } = editor.state;
|
|
2414
|
+
let chain = editor.chain().focus();
|
|
2415
|
+
if (selection instanceof NodeSelection) {
|
|
2416
|
+
const first = selection.node.firstChild?.firstChild;
|
|
2417
|
+
const last = selection.node.lastChild?.lastChild;
|
|
2418
|
+
const from = first ? selection.from + first.nodeSize : selection.from + 1;
|
|
2419
|
+
const to = last ? selection.to - last.nodeSize : selection.to - 1;
|
|
2420
|
+
chain = chain.setTextSelection({
|
|
2421
|
+
from,
|
|
2422
|
+
to
|
|
2423
|
+
}).clearNodes();
|
|
2424
|
+
}
|
|
2425
|
+
const lift = (current) => {
|
|
2426
|
+
let result = current.liftListItem("listItem");
|
|
2427
|
+
for (const name of listItemTypes) if (hasExtension(editor, name)) result = result.lift(name);
|
|
2428
|
+
return result;
|
|
2429
|
+
};
|
|
2430
|
+
if (editor.isActive(type)) return lift(chain).selectTextblockEnd();
|
|
2431
|
+
if (inAnyList(editor)) return toggle(lift(chain)).selectTextblockEnd();
|
|
2432
|
+
return toggle(chain).selectTextblockEnd();
|
|
2433
|
+
},
|
|
2434
|
+
isActive: (editor) => editor.isActive(type),
|
|
2435
|
+
isDisabled: (editor) => !hasExtension(editor, type) || blocked(editor)
|
|
2436
|
+
};
|
|
2437
|
+
}
|
|
2438
|
+
function blockAt(editor, item) {
|
|
2439
|
+
const node = item.pos == null ? null : editor.state.doc.nodeAt(item.pos);
|
|
2440
|
+
return node && item.pos != null ? {
|
|
2441
|
+
node,
|
|
2442
|
+
pos: item.pos
|
|
2443
|
+
} : void 0;
|
|
2444
|
+
}
|
|
2445
|
+
function moveHandler(direction) {
|
|
2446
|
+
const target = (editor, item) => {
|
|
2447
|
+
const block = blockAt(editor, item);
|
|
2448
|
+
if (!block) return void 0;
|
|
2449
|
+
const $pos = editor.state.doc.resolve(block.pos);
|
|
2450
|
+
const index = $pos.index();
|
|
2451
|
+
if (direction === "up" ? index <= 0 : index >= $pos.parent.childCount - 1) return void 0;
|
|
2452
|
+
const neighbor = $pos.parent.child(direction === "up" ? index - 1 : index + 1);
|
|
2453
|
+
return {
|
|
2454
|
+
...block,
|
|
2455
|
+
to: direction === "up" ? block.pos - neighbor.nodeSize : block.pos + neighbor.nodeSize
|
|
2456
|
+
};
|
|
2457
|
+
};
|
|
2458
|
+
return {
|
|
2459
|
+
canExecute: (editor, item) => Boolean(target(editor, item)),
|
|
2460
|
+
execute: (editor, item) => {
|
|
2461
|
+
const move = target(editor, item);
|
|
2462
|
+
if (!move) return editor.chain();
|
|
2463
|
+
return editor.chain().focus().deleteRange({
|
|
2464
|
+
from: move.pos,
|
|
2465
|
+
to: move.pos + move.node.nodeSize
|
|
2466
|
+
}).insertContentAt(move.to, move.node.toJSON());
|
|
2467
|
+
},
|
|
2468
|
+
isActive: () => false
|
|
2469
|
+
};
|
|
2470
|
+
}
|
|
2471
|
+
/**
|
|
2472
|
+
* The handlers of the item kinds that ViteHub's editors use: `mark` (with `mark`), `heading` (with `level`),
|
|
2473
|
+
* `paragraph`, `blockquote`, `codeBlock`, `horizontalRule`, `bulletList`, `orderedList`, and, for the block at `pos`,
|
|
2474
|
+
* `duplicate`, `delete`, `moveUp`, `moveDown`, and `suggestion` (opens the "/" menu below it). They match Nuxt UI's
|
|
2475
|
+
* `createHandlers()` for these kinds. Spread your own over them for other kinds.
|
|
2476
|
+
*/
|
|
2477
|
+
function createEditorHandlers() {
|
|
2478
|
+
return {
|
|
2479
|
+
mark: {
|
|
2480
|
+
canExecute: (editor, { mark = "" }) => editor.can().toggleMark(mark),
|
|
2481
|
+
execute: (editor, { mark = "" }) => editor.chain().focus().toggleMark(mark),
|
|
2482
|
+
isActive: (editor, { mark = "" }) => editor.isActive(mark),
|
|
2483
|
+
isDisabled: (editor, { mark = "" }) => !editor.schema.marks[mark] || isNodeTypeSelected(editor, ["image"])
|
|
2484
|
+
},
|
|
2485
|
+
heading: {
|
|
2486
|
+
canExecute: (editor, { level = 1 }) => editor.can().toggleHeading({ level }),
|
|
2487
|
+
execute: (editor, { level = 1 }) => editor.chain().focus().toggleHeading({ level }),
|
|
2488
|
+
isActive: (editor, item) => editor.isActive("heading", { level: item.level }),
|
|
2489
|
+
isDisabled: blocked
|
|
2490
|
+
},
|
|
2491
|
+
paragraph: blockHandler("paragraph", (chain) => chain.setParagraph(), (editor) => editor.can().setParagraph()),
|
|
2492
|
+
blockquote: blockHandler("blockquote", (chain) => chain.toggleBlockquote(), (editor) => editor.can().toggleBlockquote()),
|
|
2493
|
+
codeBlock: blockHandler("codeBlock", (chain) => chain.toggleCodeBlock(), (editor) => editor.can().toggleCodeBlock()),
|
|
2494
|
+
horizontalRule: blockHandler("horizontalRule", (chain) => chain.setHorizontalRule(), (editor) => editor.can().setHorizontalRule()),
|
|
2495
|
+
bulletList: listHandler("bulletList"),
|
|
2496
|
+
orderedList: listHandler("orderedList"),
|
|
2497
|
+
duplicate: {
|
|
2498
|
+
canExecute: (editor, item) => Boolean(blockAt(editor, item)),
|
|
2499
|
+
execute: (editor, item) => {
|
|
2500
|
+
const block = blockAt(editor, item);
|
|
2501
|
+
return block ? editor.chain().focus().insertContentAt(block.pos + block.node.nodeSize, block.node.toJSON()) : editor.chain();
|
|
2502
|
+
},
|
|
2503
|
+
isActive: () => false
|
|
2504
|
+
},
|
|
2505
|
+
delete: {
|
|
2506
|
+
canExecute: (editor, item) => Boolean(blockAt(editor, item)),
|
|
2507
|
+
execute: (editor, item) => {
|
|
2508
|
+
const block = blockAt(editor, item);
|
|
2509
|
+
return block ? editor.chain().focus().deleteRange({
|
|
2510
|
+
from: block.pos,
|
|
2511
|
+
to: block.pos + block.node.nodeSize
|
|
2512
|
+
}) : editor.chain();
|
|
2513
|
+
},
|
|
2514
|
+
isActive: () => false
|
|
2515
|
+
},
|
|
2516
|
+
moveUp: moveHandler("up"),
|
|
2517
|
+
moveDown: moveHandler("down"),
|
|
2518
|
+
suggestion: {
|
|
2519
|
+
canExecute: () => true,
|
|
2520
|
+
execute: (editor, item) => {
|
|
2521
|
+
const slash = {
|
|
2522
|
+
content: [{
|
|
2523
|
+
text: "/",
|
|
2524
|
+
type: "text"
|
|
2525
|
+
}],
|
|
2526
|
+
type: "paragraph"
|
|
2527
|
+
};
|
|
2528
|
+
const block = blockAt(editor, item);
|
|
2529
|
+
if (block) return editor.chain().focus().insertContentAt(block.pos + block.node.nodeSize, slash);
|
|
2530
|
+
const { $from } = editor.state.selection;
|
|
2531
|
+
return editor.chain().focus().insertContentAt($from.before($from.depth) + $from.node($from.depth).nodeSize, slash);
|
|
2532
|
+
},
|
|
2533
|
+
isActive: () => false
|
|
2534
|
+
}
|
|
2535
|
+
};
|
|
2536
|
+
}
|
|
2537
|
+
function mapEditorItems(editor, items, handlers) {
|
|
2538
|
+
const all = {
|
|
2539
|
+
...createEditorHandlers(),
|
|
2540
|
+
...handlers
|
|
2541
|
+
};
|
|
2542
|
+
const map = (group) => group.filter(Boolean).map((entry) => {
|
|
2543
|
+
if (entry.type) return entry;
|
|
2544
|
+
const { children, ...rest } = entry;
|
|
2545
|
+
const mappedChildren = children?.length ? Array.isArray(children[0]) ? children.map(map) : map(children) : void 0;
|
|
2546
|
+
const handler = entry.kind ? all[entry.kind] : void 0;
|
|
2547
|
+
if (!handler) return {
|
|
2548
|
+
...rest,
|
|
2549
|
+
children: mappedChildren
|
|
2550
|
+
};
|
|
2551
|
+
return {
|
|
2552
|
+
...rest,
|
|
2553
|
+
active: handler.isActive(editor, entry),
|
|
2554
|
+
children: mappedChildren,
|
|
2555
|
+
disabled: Boolean(handler.isDisabled?.(editor, entry)) || !handler.canExecute(editor, entry),
|
|
2556
|
+
onSelect: () => void handler.execute(editor, entry).run()
|
|
2557
|
+
};
|
|
2558
|
+
});
|
|
2559
|
+
return items.length && Array.isArray(items[0]) ? items.map(map) : map(items);
|
|
2560
|
+
}
|
|
2561
|
+
// src/internal/markdown-editor.ts
|
|
2339
2562
|
/**
|
|
2340
2563
|
* Uploads to a route that returns the result of `blob.handleUpload()`, with progress, and resolves with the stored
|
|
2341
2564
|
* object's URL. The Blob store has to be served (`blob.serve`), so the object has a URL to link.
|
|
@@ -2350,7 +2573,7 @@ function blobUpload(route) {
|
|
|
2350
2573
|
return object.url;
|
|
2351
2574
|
};
|
|
2352
2575
|
}
|
|
2353
|
-
const
|
|
2576
|
+
const toolbarItems = [
|
|
2354
2577
|
[
|
|
2355
2578
|
{
|
|
2356
2579
|
kind: "mark",
|
|
@@ -2476,118 +2699,656 @@ const image = {
|
|
|
2476
2699
|
icon: "i-lucide-image"
|
|
2477
2700
|
};
|
|
2478
2701
|
/**
|
|
2479
|
-
*
|
|
2480
|
-
*
|
|
2481
|
-
*
|
|
2482
|
-
|
|
2702
|
+
* The state of a Markdown editor on comark-ui's editor: the editor bound to `markdown`, or the one given, with the upload
|
|
2703
|
+
* plugin on it when there is an `upload`, and the items of its bubble toolbar and "/" menu. It provides the handlers that
|
|
2704
|
+
* the menus run. Call it in `setup()`.
|
|
2705
|
+
*/
|
|
2706
|
+
function useMarkdownEditor(markdown, options = {}) {
|
|
2707
|
+
const initialEditor = options.editor;
|
|
2708
|
+
const own = initialEditor ? void 0 : useComarkEditor(markdown, {
|
|
2709
|
+
extensions: options.extensions,
|
|
2710
|
+
plugins: options.plugins
|
|
2711
|
+
});
|
|
2712
|
+
const editor = computed(() => initialEditor ?? own?.editor.value);
|
|
2713
|
+
const upload = shallowRef();
|
|
2714
|
+
watchEffect(() => {
|
|
2715
|
+
const route = unref(options.upload);
|
|
2716
|
+
const send = typeof route === "string" ? blobUpload(route) : route;
|
|
2717
|
+
upload.value = send && {
|
|
2718
|
+
upload: send,
|
|
2719
|
+
accept: unref(options.accept) ?? ((file) => /^(?:image|video|audio)\//.test(file.type)),
|
|
2720
|
+
onError: (error, file) => options.onError?.({
|
|
2721
|
+
error,
|
|
2722
|
+
file
|
|
2723
|
+
})
|
|
2724
|
+
};
|
|
2725
|
+
});
|
|
2726
|
+
watch([editor, upload], ([current, uploads], _, onCleanup) => {
|
|
2727
|
+
if (!current || !uploads || uploadKey.getState(current.state)) return;
|
|
2728
|
+
current.registerPlugin(uploadPlugin(uploads));
|
|
2729
|
+
onCleanup(() => {
|
|
2730
|
+
if (!current.isDestroyed) current.unregisterPlugin(uploadKey);
|
|
2731
|
+
});
|
|
2732
|
+
}, { immediate: true });
|
|
2733
|
+
const handlers = computed(() => ({
|
|
2734
|
+
...createEditorHandlers(),
|
|
2735
|
+
image: {
|
|
2736
|
+
canExecute: () => Boolean(upload.value),
|
|
2737
|
+
execute: (current) => ({ run: () => upload.value ? chooseFiles(current.view, upload.value) : false }),
|
|
2738
|
+
isActive: () => false,
|
|
2739
|
+
isDisabled: () => !upload.value
|
|
2740
|
+
}
|
|
2741
|
+
}));
|
|
2742
|
+
provide(editorHandlersKey, handlers);
|
|
2743
|
+
return {
|
|
2744
|
+
editor,
|
|
2745
|
+
toolbarItems,
|
|
2746
|
+
menuItems: computed(() => upload.value ? [...blocks, image] : blocks)
|
|
2747
|
+
};
|
|
2748
|
+
}
|
|
2749
|
+
// src/ui-sdk/editor.ts
|
|
2750
|
+
/**
|
|
2751
|
+
* The editor parts on ui-sdk: Nuxt UI's `UEditorToolbar`, `UEditorSuggestionMenu`, and `UEditorDragHandle`, with the
|
|
2752
|
+
* props, slots, and events that ViteHub's editors use. Positioning at the selection and the block, and dragging blocks,
|
|
2753
|
+
* stay with Tiptap's own menu plugins. They run items through the handlers that the editor provides under
|
|
2754
|
+
* `editorHandlersKey`, as Nuxt UI's do.
|
|
2483
2755
|
*/
|
|
2484
|
-
const
|
|
2485
|
-
|
|
2756
|
+
const ToggleButton = Toggle;
|
|
2757
|
+
const ToggleButtonIcon = ToggleIcon;
|
|
2758
|
+
const Bar = Toolbar;
|
|
2759
|
+
const BarButton = ToolbarButton;
|
|
2760
|
+
const BarGroup = ToolbarGroup;
|
|
2761
|
+
const BarSeparator = ToolbarSeparator;
|
|
2762
|
+
const Tip = Tooltip;
|
|
2763
|
+
const TipTrigger = TooltipTrigger;
|
|
2764
|
+
const TipContent = TooltipContent;
|
|
2765
|
+
const TipShortcut = TooltipShortcut;
|
|
2766
|
+
const DropdownMenu = Menu;
|
|
2767
|
+
const DropdownTrigger = MenuTrigger;
|
|
2768
|
+
const DropdownContent = MenuContent;
|
|
2769
|
+
const DropdownItem = MenuItem;
|
|
2770
|
+
const SlashMenu = TriggerMenu;
|
|
2771
|
+
const SlashContent = TriggerMenuContent;
|
|
2772
|
+
const SlashList = TriggerMenuList;
|
|
2773
|
+
const SlashItem = TriggerMenuItem;
|
|
2774
|
+
const SlashStatus = TriggerMenuStatus;
|
|
2775
|
+
const BlockHandle = DragHandle;
|
|
2776
|
+
const BubbleMenu$1 = BubbleMenu;
|
|
2777
|
+
function useHandlers() {
|
|
2778
|
+
return inject(editorHandlersKey, computed(createEditorHandlers), true);
|
|
2779
|
+
}
|
|
2780
|
+
const isGroups = (items) => items.length > 0 && Array.isArray(items[0]);
|
|
2781
|
+
const groupsOf = (items) => !items?.length ? [] : isGroups(items) ? items : [items];
|
|
2782
|
+
const shortcutOf = (kbds) => kbds?.length ? kbds.map((key) => key === "meta" ? "mod" : key).join("+") : void 0;
|
|
2783
|
+
/** Nuxt UI's `UEditorToolbar`, in its `fixed` and `bubble` layouts, on ui-sdk's `Toolbar`, `Toggle`, and `Menu`. */
|
|
2784
|
+
const UEditorToolbar = defineComponent({
|
|
2785
|
+
name: "UEditorToolbar",
|
|
2486
2786
|
inheritAttrs: false,
|
|
2487
2787
|
props: {
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2788
|
+
editor: {
|
|
2789
|
+
required: true,
|
|
2790
|
+
type: Object
|
|
2791
|
+
},
|
|
2792
|
+
items: {
|
|
2793
|
+
default: () => [],
|
|
2794
|
+
type: Array
|
|
2795
|
+
},
|
|
2796
|
+
layout: {
|
|
2797
|
+
default: "fixed",
|
|
2798
|
+
type: String
|
|
2799
|
+
},
|
|
2800
|
+
size: {
|
|
2801
|
+
default: "sm",
|
|
2802
|
+
type: String
|
|
2803
|
+
},
|
|
2804
|
+
/** For the `bubble` layout, as Tiptap's `BubbleMenu` takes them. */
|
|
2805
|
+
appendTo: {
|
|
2806
|
+
default: void 0,
|
|
2807
|
+
type: [Object, Function]
|
|
2808
|
+
},
|
|
2809
|
+
getReferencedVirtualElement: {
|
|
2810
|
+
default: void 0,
|
|
2811
|
+
type: Function
|
|
2812
|
+
},
|
|
2813
|
+
options: {
|
|
2814
|
+
default: void 0,
|
|
2815
|
+
type: Object
|
|
2816
|
+
},
|
|
2817
|
+
pluginKey: {
|
|
2818
|
+
default: void 0,
|
|
2819
|
+
type: [String, Object]
|
|
2820
|
+
},
|
|
2821
|
+
resizeDelay: {
|
|
2822
|
+
default: void 0,
|
|
2823
|
+
type: Number
|
|
2824
|
+
},
|
|
2825
|
+
shouldShow: {
|
|
2826
|
+
default: void 0,
|
|
2827
|
+
type: Function
|
|
2828
|
+
},
|
|
2829
|
+
updateDelay: {
|
|
2830
|
+
default: void 0,
|
|
2831
|
+
type: Number
|
|
2832
|
+
},
|
|
2833
|
+
ui: {
|
|
2834
|
+
default: () => ({}),
|
|
2835
|
+
type: Object
|
|
2836
|
+
}
|
|
2837
|
+
},
|
|
2838
|
+
setup(props, { attrs, slots }) {
|
|
2839
|
+
const UIcon = useStandIn("UIcon");
|
|
2840
|
+
const handlers = useHandlers();
|
|
2841
|
+
const icons = useViteHubUIIcons();
|
|
2842
|
+
const isActive = (item) => {
|
|
2843
|
+
if (!props.editor.isEditable) return false;
|
|
2844
|
+
if ("items" in item && item.items?.length) return groupsOf(item.items).flat().some(isActive);
|
|
2845
|
+
if (!item.kind) return "active" in item && item.active || false;
|
|
2846
|
+
return handlers.value[item.kind]?.isActive(props.editor, item) ?? false;
|
|
2847
|
+
};
|
|
2848
|
+
const isDisabled = (item) => {
|
|
2849
|
+
if (!props.editor.isEditable) return true;
|
|
2850
|
+
if ("items" in item && item.items?.length) {
|
|
2851
|
+
const actionable = groupsOf(item.items).flat().filter((entry) => entry.type !== "separator" && entry.type !== "label");
|
|
2852
|
+
return !actionable.length || actionable.every(isDisabled);
|
|
2853
|
+
}
|
|
2854
|
+
if (!item.kind) return item.disabled ?? false;
|
|
2855
|
+
const handler = handlers.value[item.kind];
|
|
2856
|
+
if (!handler) return false;
|
|
2857
|
+
return Boolean(handler.isDisabled?.(props.editor, item)) || !handler.canExecute(props.editor, item);
|
|
2858
|
+
};
|
|
2859
|
+
const onClick = (event, item) => {
|
|
2860
|
+
if (!props.editor.isEditable || isDisabled(item)) return;
|
|
2861
|
+
if (!item.kind || "items" in item && item.items) {
|
|
2862
|
+
if ("onClick" in item && item.onClick) for (const run of [item.onClick].flat()) run(event);
|
|
2863
|
+
return;
|
|
2864
|
+
}
|
|
2865
|
+
handlers.value[item.kind]?.execute(props.editor, item).run();
|
|
2866
|
+
};
|
|
2867
|
+
const content = (item) => {
|
|
2868
|
+
const child = item.items ? groupsOf(item.items).flat().find((entry) => entry.kind && isActive(entry)) : void 0;
|
|
2869
|
+
const icon = child?.icon ?? item.icon;
|
|
2870
|
+
const label = item.label !== void 0 && child?.label ? child.label : item.label;
|
|
2871
|
+
return [
|
|
2872
|
+
icon ? h(ToggleButtonIcon, () => h(UIcon, { name: icon })) : null,
|
|
2873
|
+
label ? h("span", { "data-slot": "editor-toolbar-label" }, label) : null,
|
|
2874
|
+
item.trailingIcon ? h(UIcon, {
|
|
2875
|
+
"data-slot": "editor-toolbar-trailing-icon",
|
|
2876
|
+
name: item.trailingIcon
|
|
2877
|
+
}) : null
|
|
2878
|
+
];
|
|
2879
|
+
};
|
|
2880
|
+
const named = (item) => ({ "aria-label": item["aria-label"] ?? (item.label ? void 0 : item.tooltip?.text) });
|
|
2881
|
+
const withTooltip = (item, control) => {
|
|
2882
|
+
if (!item.tooltip?.text) return control({});
|
|
2883
|
+
const shortcut = shortcutOf(item.tooltip.kbds);
|
|
2884
|
+
return h(Tip, {
|
|
2885
|
+
disabled: isDisabled(item),
|
|
2886
|
+
shortcut,
|
|
2887
|
+
type: "description"
|
|
2888
|
+
}, () => [h(TipTrigger, null, { render: ({ props: trigger }) => control(trigger) }), h(TipContent, { sideOffset: 6 }, () => [item.tooltip?.text, shortcut ? h(TipShortcut) : null])]);
|
|
2889
|
+
};
|
|
2890
|
+
const menuEntry = (entry, index) => {
|
|
2891
|
+
if (entry.type === "label") return h(MenuGroupLabel, { key: index }, () => entry.label);
|
|
2892
|
+
if (entry.type === "separator") return h(MenuSeparator, { key: index });
|
|
2893
|
+
const active = Boolean(entry.kind) && isActive(entry);
|
|
2894
|
+
return h(DropdownItem, {
|
|
2895
|
+
"data-active": active ? "" : void 0,
|
|
2896
|
+
disabled: isDisabled(entry),
|
|
2897
|
+
key: index,
|
|
2898
|
+
label: entry.label,
|
|
2899
|
+
onSelect: (event) => entry.kind ? onClick(event, entry) : entry.onSelect?.(event)
|
|
2900
|
+
}, () => [
|
|
2901
|
+
entry.icon ? h(MenuItemIcon, () => h(UIcon, { name: entry.icon })) : null,
|
|
2902
|
+
h("span", entry.label),
|
|
2903
|
+
active ? h(UIcon, {
|
|
2904
|
+
"data-slot": "editor-toolbar-check",
|
|
2905
|
+
name: icons.value.check
|
|
2906
|
+
}) : null
|
|
2907
|
+
]);
|
|
2908
|
+
};
|
|
2909
|
+
const control = (item, index) => {
|
|
2910
|
+
const slot = slots[item.slot ?? "item"];
|
|
2911
|
+
if (slot) return slot({
|
|
2912
|
+
index,
|
|
2913
|
+
isActive,
|
|
2914
|
+
isDisabled,
|
|
2915
|
+
item,
|
|
2916
|
+
onClick
|
|
2917
|
+
});
|
|
2918
|
+
const data = {
|
|
2919
|
+
"data-size": props.size,
|
|
2920
|
+
key: index
|
|
2921
|
+
};
|
|
2922
|
+
if (item.items?.length) {
|
|
2923
|
+
const groups = groupsOf(item.items);
|
|
2924
|
+
return h(DropdownMenu, { key: index }, () => [withTooltip(item, (trigger) => h(BarButton, {
|
|
2925
|
+
...data,
|
|
2926
|
+
disabled: isDisabled(item)
|
|
2927
|
+
}, { render: ({ props: button }) => h(DropdownTrigger, {
|
|
2928
|
+
...trigger,
|
|
2929
|
+
...button,
|
|
2930
|
+
...named(item),
|
|
2931
|
+
"data-active": isActive(item) ? "" : void 0,
|
|
2932
|
+
"data-slot": "toggle"
|
|
2933
|
+
}, () => content(item)) })), h(DropdownContent, {
|
|
2934
|
+
align: item.content?.align ?? "start",
|
|
2935
|
+
class: item.ui?.content,
|
|
2936
|
+
side: item.content?.side,
|
|
2937
|
+
sideOffset: item.content?.sideOffset ?? 8
|
|
2938
|
+
}, () => groups.flatMap((group, groupIndex) => [groupIndex ? h(MenuSeparator, { key: `separator-${groupIndex}` }) : null, h(MenuGroup, { key: `group-${groupIndex}` }, () => group.map(menuEntry))]))]);
|
|
2939
|
+
}
|
|
2940
|
+
if (item.kind) return withTooltip(item, (trigger) => h(ToggleButton, {
|
|
2941
|
+
...trigger,
|
|
2942
|
+
...data,
|
|
2943
|
+
...named(item),
|
|
2944
|
+
disabled: isDisabled(item),
|
|
2945
|
+
pressed: isActive(item),
|
|
2946
|
+
onPressedChange: (_pressed, details) => onClick(details.event ?? new Event("click"), item)
|
|
2947
|
+
}, () => content(item)));
|
|
2948
|
+
return withTooltip(item, (trigger) => h(BarButton, {
|
|
2949
|
+
...trigger,
|
|
2950
|
+
...data,
|
|
2951
|
+
...named(item),
|
|
2952
|
+
"data-active": isActive(item) ? "" : void 0,
|
|
2953
|
+
"data-slot": "toggle",
|
|
2954
|
+
disabled: isDisabled(item),
|
|
2955
|
+
onClick: (event) => onClick(event, item)
|
|
2956
|
+
}, () => content(item)));
|
|
2957
|
+
};
|
|
2958
|
+
return () => {
|
|
2959
|
+
props.editor.state;
|
|
2960
|
+
const groups = groupsOf(props.items);
|
|
2961
|
+
const { class: baseClass, ...rootAttrs } = attrs;
|
|
2962
|
+
const bar = h(Bar, {
|
|
2963
|
+
"aria-label": "Formatting",
|
|
2964
|
+
...props.layout === "fixed" ? rootAttrs : {},
|
|
2965
|
+
class: [
|
|
2966
|
+
"vh-editor-toolbar",
|
|
2967
|
+
props.ui.base,
|
|
2968
|
+
baseClass
|
|
2969
|
+
],
|
|
2970
|
+
"data-layout": props.layout
|
|
2971
|
+
}, () => groups.flatMap((group, groupIndex) => [h(BarGroup, {
|
|
2972
|
+
class: props.ui.group,
|
|
2973
|
+
key: `group-${groupIndex}`
|
|
2974
|
+
}, () => group.map(control)), groupIndex < groups.length - 1 ? h(BarSeparator, {
|
|
2975
|
+
class: props.ui.separator,
|
|
2976
|
+
key: `separator-${groupIndex}`
|
|
2977
|
+
}) : null]));
|
|
2978
|
+
if (props.layout !== "bubble") return bar;
|
|
2979
|
+
return h(BubbleMenu$1, {
|
|
2980
|
+
...rootAttrs,
|
|
2981
|
+
appendTo: props.appendTo,
|
|
2982
|
+
class: ["vh-editor-toolbar-root", props.ui.root],
|
|
2983
|
+
editor: props.editor,
|
|
2984
|
+
getReferencedVirtualElement: props.getReferencedVirtualElement,
|
|
2985
|
+
options: {
|
|
2986
|
+
offset: 8,
|
|
2987
|
+
shift: { padding: 8 },
|
|
2988
|
+
...props.options
|
|
2989
|
+
},
|
|
2990
|
+
pluginKey: props.pluginKey,
|
|
2991
|
+
resizeDelay: props.resizeDelay,
|
|
2992
|
+
shouldShow: props.shouldShow ?? null,
|
|
2993
|
+
tabindex: -1,
|
|
2994
|
+
updateDelay: props.updateDelay
|
|
2995
|
+
}, () => bar);
|
|
2996
|
+
};
|
|
2997
|
+
}
|
|
2998
|
+
});
|
|
2999
|
+
const collator = new Intl.Collator(void 0, {
|
|
3000
|
+
sensitivity: "base",
|
|
3001
|
+
usage: "search"
|
|
3002
|
+
});
|
|
3003
|
+
function contains(value, part) {
|
|
3004
|
+
if (!part) return true;
|
|
3005
|
+
const text = value.normalize("NFC");
|
|
3006
|
+
const search = part.normalize("NFC");
|
|
3007
|
+
for (let index = 0; index + search.length <= text.length; index++) if (collator.compare(text.slice(index, index + search.length), search) === 0) return true;
|
|
3008
|
+
return false;
|
|
3009
|
+
}
|
|
3010
|
+
function score(value, query) {
|
|
3011
|
+
if (!contains(value, query)) return void 0;
|
|
3012
|
+
if (contains(query, value)) return 0;
|
|
3013
|
+
if (collator.compare(value.slice(0, query.length), query) === 0) return 1;
|
|
3014
|
+
return 2;
|
|
3015
|
+
}
|
|
3016
|
+
function rank(items, query, fields) {
|
|
3017
|
+
if (!query) return items;
|
|
3018
|
+
const scored = [];
|
|
3019
|
+
for (const item of items) {
|
|
3020
|
+
let best;
|
|
3021
|
+
for (const field of fields) {
|
|
3022
|
+
const value = item[field];
|
|
3023
|
+
if (value == null) continue;
|
|
3024
|
+
for (const text of [value].flat().map(String)) {
|
|
3025
|
+
const found = Math.min(score(text, query) ?? 3, score(text.replace(/[\s_-]/g, ""), query) ?? 3);
|
|
3026
|
+
if (best === void 0 || found < best) best = found;
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
if (best !== void 0 && best < 3) scored.push({
|
|
3030
|
+
item,
|
|
3031
|
+
score: best
|
|
3032
|
+
});
|
|
3033
|
+
}
|
|
3034
|
+
return scored.sort((a, b) => a.score - b.score).map(({ item }) => item);
|
|
3035
|
+
}
|
|
3036
|
+
const OBJECT = "";
|
|
3037
|
+
const choosable = (item) => item.type !== "label" && item.type !== "separator";
|
|
3038
|
+
/**
|
|
3039
|
+
* The editor as ui-sdk's `TriggerMenu` reads it. Offsets are document positions. The text before the caret is the text
|
|
3040
|
+
* of its block, after a line break that stands for the block's start, so a trigger at the start of a block matches as
|
|
3041
|
+
* one after a space does.
|
|
3042
|
+
*/
|
|
3043
|
+
function tiptapAdapter(editor) {
|
|
3044
|
+
return {
|
|
3045
|
+
get element() {
|
|
3046
|
+
return editor.isDestroyed ? void 0 : editor.view.dom;
|
|
3047
|
+
},
|
|
3048
|
+
textBefore(length) {
|
|
3049
|
+
const { $head } = editor.state.selection;
|
|
3050
|
+
if (!$head.parent.isTextblock) return null;
|
|
3051
|
+
const from = Math.max(0, $head.parentOffset - length);
|
|
3052
|
+
const text = $head.parent.textBetween(from, $head.parentOffset, void 0, OBJECT);
|
|
3053
|
+
return from === 0 && text.length < length ? {
|
|
3054
|
+
offset: $head.start() - 1,
|
|
3055
|
+
text: `\n${text}`
|
|
3056
|
+
} : {
|
|
3057
|
+
offset: $head.start() + from,
|
|
3058
|
+
text
|
|
3059
|
+
};
|
|
3060
|
+
},
|
|
3061
|
+
selection() {
|
|
3062
|
+
if (editor.isDestroyed || !editor.view.hasFocus()) return null;
|
|
3063
|
+
const { from, to } = editor.state.selection;
|
|
3064
|
+
return {
|
|
3065
|
+
end: to,
|
|
3066
|
+
start: from
|
|
3067
|
+
};
|
|
3068
|
+
},
|
|
3069
|
+
rectAt(offset) {
|
|
3070
|
+
try {
|
|
3071
|
+
const rect = editor.view.coordsAtPos(offset);
|
|
3072
|
+
return {
|
|
3073
|
+
height: rect.bottom - rect.top,
|
|
3074
|
+
width: Math.max(0, rect.right - rect.left),
|
|
3075
|
+
x: rect.left,
|
|
3076
|
+
y: rect.top
|
|
3077
|
+
};
|
|
3078
|
+
} catch {
|
|
3079
|
+
return null;
|
|
3080
|
+
}
|
|
3081
|
+
},
|
|
3082
|
+
replace(range, content) {
|
|
3083
|
+
editor.chain().focus().insertContentAt({
|
|
3084
|
+
from: range.start,
|
|
3085
|
+
to: range.end
|
|
3086
|
+
}, typeof content === "string" ? content : content.label ?? "").run();
|
|
3087
|
+
},
|
|
3088
|
+
subscribe(listener) {
|
|
3089
|
+
const onTransaction = ({ transaction }) => {
|
|
3090
|
+
if (!transaction.docChanged) {
|
|
3091
|
+
if (transaction.selectionSet) listener({ type: "selection" });
|
|
3092
|
+
return;
|
|
3093
|
+
}
|
|
3094
|
+
const user = !transaction.getMeta("y-sync$");
|
|
3095
|
+
for (const step of transaction.steps) {
|
|
3096
|
+
if (!(step instanceof ReplaceStep)) continue;
|
|
3097
|
+
listener({
|
|
3098
|
+
inserted: step.slice.content.textBetween(0, step.slice.content.size, "\n", OBJECT),
|
|
3099
|
+
range: {
|
|
3100
|
+
end: step.to,
|
|
3101
|
+
start: step.from
|
|
3102
|
+
},
|
|
3103
|
+
type: "input",
|
|
3104
|
+
user
|
|
3105
|
+
});
|
|
3106
|
+
}
|
|
3107
|
+
};
|
|
3108
|
+
const onComposition = (event) => listener({ type: event.type === "compositionstart" ? "compositionstart" : "compositionend" });
|
|
3109
|
+
editor.on("transaction", onTransaction);
|
|
3110
|
+
editor.view.dom.addEventListener("compositionstart", onComposition);
|
|
3111
|
+
editor.view.dom.addEventListener("compositionend", onComposition);
|
|
3112
|
+
return () => {
|
|
3113
|
+
editor.off("transaction", onTransaction);
|
|
3114
|
+
if (!editor.isDestroyed) {
|
|
3115
|
+
editor.view.dom.removeEventListener("compositionstart", onComposition);
|
|
3116
|
+
editor.view.dom.removeEventListener("compositionend", onComposition);
|
|
3117
|
+
}
|
|
3118
|
+
};
|
|
2491
3119
|
},
|
|
2492
|
-
|
|
3120
|
+
composing: () => editor.view.composing
|
|
3121
|
+
};
|
|
3122
|
+
}
|
|
3123
|
+
/**
|
|
3124
|
+
* Nuxt UI's `UEditorSuggestionMenu` on ui-sdk's `TriggerMenu`. Typing `char` opens a list at the caret, the text after
|
|
3125
|
+
* it filters `items` with Nuxt UI's ranking, the arrow keys move the highlight and wrap, Enter or Tab runs it, and
|
|
3126
|
+
* Escape closes the list until the trigger is typed again. The caret stays in the editor, which points at the list
|
|
3127
|
+
* with `aria-controls` and `aria-activedescendant`.
|
|
3128
|
+
*/
|
|
3129
|
+
const UEditorSuggestionMenu = defineComponent({
|
|
3130
|
+
name: "UEditorSuggestionMenu",
|
|
3131
|
+
inheritAttrs: false,
|
|
3132
|
+
props: {
|
|
2493
3133
|
editor: {
|
|
2494
|
-
|
|
2495
|
-
|
|
3134
|
+
required: true,
|
|
3135
|
+
type: Object
|
|
2496
3136
|
},
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
type:
|
|
2500
|
-
default: void 0
|
|
3137
|
+
items: {
|
|
3138
|
+
default: () => [],
|
|
3139
|
+
type: Array
|
|
2501
3140
|
},
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
type:
|
|
2505
|
-
default: void 0
|
|
3141
|
+
char: {
|
|
3142
|
+
default: "/",
|
|
3143
|
+
type: String
|
|
2506
3144
|
},
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
type: Array
|
|
2510
|
-
default: void 0
|
|
3145
|
+
filterFields: {
|
|
3146
|
+
default: () => ["label"],
|
|
3147
|
+
type: Array
|
|
2511
3148
|
},
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
type:
|
|
2515
|
-
|
|
3149
|
+
limit: {
|
|
3150
|
+
default: 42,
|
|
3151
|
+
type: Number
|
|
3152
|
+
},
|
|
3153
|
+
ui: {
|
|
3154
|
+
default: () => ({}),
|
|
3155
|
+
type: Object
|
|
3156
|
+
}
|
|
3157
|
+
},
|
|
3158
|
+
setup(props, { attrs }) {
|
|
3159
|
+
const UIcon = useStandIn("UIcon");
|
|
3160
|
+
const handlers = useHandlers();
|
|
3161
|
+
const query = ref("");
|
|
3162
|
+
const adapter = shallowRef();
|
|
3163
|
+
onMounted(() => {
|
|
3164
|
+
if (!props.editor.isDestroyed) adapter.value = tiptapAdapter(props.editor);
|
|
3165
|
+
});
|
|
3166
|
+
const flat = computed(() => groupsOf(props.items).flat());
|
|
3167
|
+
const matches = computed(() => rank(flat.value, query.value, props.filterFields).slice(0, props.limit));
|
|
3168
|
+
const groups = computed(() => groupsOf(props.items).map((group) => group.filter((item) => matches.value.includes(item)).sort((a, b) => matches.value.indexOf(a) - matches.value.indexOf(b))).filter((group) => group.some(choosable)));
|
|
3169
|
+
const triggers = computed(() => [{
|
|
3170
|
+
char: props.char,
|
|
3171
|
+
filter: false
|
|
3172
|
+
}]);
|
|
3173
|
+
const onSelect = (value, details) => {
|
|
3174
|
+
details.preventDefault();
|
|
3175
|
+
const item = flat.value[Number(value)];
|
|
3176
|
+
if (!item?.kind) return;
|
|
3177
|
+
props.editor.chain().focus().deleteRange({
|
|
3178
|
+
from: details.match.start,
|
|
3179
|
+
to: details.match.end
|
|
3180
|
+
}).run();
|
|
3181
|
+
handlers.value[item.kind]?.execute(props.editor, item).run();
|
|
3182
|
+
};
|
|
3183
|
+
return () => h(SlashMenu, {
|
|
3184
|
+
editor: adapter.value,
|
|
3185
|
+
loop: true,
|
|
3186
|
+
triggers: triggers.value,
|
|
3187
|
+
onQueryChange: (next) => query.value = next,
|
|
3188
|
+
onSelect
|
|
3189
|
+
}, () => [h(SlashStatus, { class: "vh-editor-suggestion-menu__status" }), h(SlashContent, {
|
|
3190
|
+
...attrs,
|
|
3191
|
+
align: "start",
|
|
3192
|
+
class: [
|
|
3193
|
+
"vh-editor-suggestion-menu",
|
|
3194
|
+
props.ui.content,
|
|
3195
|
+
attrs.class
|
|
3196
|
+
],
|
|
3197
|
+
collisionPadding: 8,
|
|
3198
|
+
side: "bottom",
|
|
3199
|
+
sideOffset: 8
|
|
3200
|
+
}, () => h(SlashList, { "aria-label": "Insert block" }, () => groups.value.flatMap((group, groupIndex) => [groupIndex ? h(TriggerMenuSeparator, { key: `separator-${groupIndex}` }) : null, h(TriggerMenuGroup, { key: `group-${groupIndex}` }, () => group.map((item, index) => {
|
|
3201
|
+
if (item.type === "label") return h(TriggerMenuGroupLabel, {
|
|
3202
|
+
class: item.class,
|
|
3203
|
+
key: `label-${index}`
|
|
3204
|
+
}, () => item.label);
|
|
3205
|
+
if (item.type === "separator") return h(TriggerMenuSeparator, { key: `separator-${index}` });
|
|
3206
|
+
const value = String(flat.value.indexOf(item));
|
|
3207
|
+
return h(SlashItem, {
|
|
3208
|
+
class: item.class,
|
|
3209
|
+
disabled: item.disabled,
|
|
3210
|
+
key: value,
|
|
3211
|
+
keywords: item.keywords,
|
|
3212
|
+
label: item.label,
|
|
3213
|
+
value
|
|
3214
|
+
}, () => [item.icon ? h(TriggerMenuItemIcon, () => h(UIcon, { name: item.icon })) : null, h("span", { "data-slot": "editor-suggestion-text" }, [h("span", { "data-slot": "editor-suggestion-label" }, item.label), item.description ? h("span", { "data-slot": "editor-suggestion-description" }, item.description) : null])]);
|
|
3215
|
+
}))])))]);
|
|
3216
|
+
}
|
|
3217
|
+
});
|
|
3218
|
+
/**
|
|
3219
|
+
* Moves the drag handle to each new place with the list mover of the motion layer, as a neighbor of a list moves. The
|
|
3220
|
+
* drag handle extension places it with `left` and `top`. A handle that was hidden shows at its new place at once.
|
|
3221
|
+
*/
|
|
3222
|
+
function followPlace(element) {
|
|
3223
|
+
const parent = element.parentElement;
|
|
3224
|
+
if (!parent) return () => {};
|
|
3225
|
+
const list = createMotionList(parent, { items: () => [element] });
|
|
3226
|
+
const read = () => ({
|
|
3227
|
+
place: `${element.style.left} ${element.style.top}`,
|
|
3228
|
+
shown: element.style.visibility !== "hidden"
|
|
3229
|
+
});
|
|
3230
|
+
let last = read();
|
|
3231
|
+
list.measure();
|
|
3232
|
+
const observer = new MutationObserver(() => {
|
|
3233
|
+
const next = read();
|
|
3234
|
+
if (next.place === last.place && next.shown === last.shown) return;
|
|
3235
|
+
if (next.shown && last.shown) list.play();
|
|
3236
|
+
last = next;
|
|
3237
|
+
list.measure();
|
|
3238
|
+
});
|
|
3239
|
+
observer.observe(element, {
|
|
3240
|
+
attributes: true,
|
|
3241
|
+
attributeFilter: ["style"]
|
|
3242
|
+
});
|
|
3243
|
+
return () => {
|
|
3244
|
+
observer.disconnect();
|
|
3245
|
+
list.destroy();
|
|
3246
|
+
};
|
|
3247
|
+
}
|
|
3248
|
+
/**
|
|
3249
|
+
* Nuxt UI's `UEditorDragHandle`: a handle beside the block under the pointer, which drags the block to move it. A press
|
|
3250
|
+
* selects the block and emits `nodeChange`. The default slot replaces the button and gets `onClick`, which selects the
|
|
3251
|
+
* block and returns it, and `ui.handle()`, the class of a handle button.
|
|
3252
|
+
*/
|
|
3253
|
+
const UEditorDragHandle = defineComponent({
|
|
3254
|
+
name: "UEditorDragHandle",
|
|
3255
|
+
inheritAttrs: false,
|
|
3256
|
+
props: {
|
|
3257
|
+
editor: {
|
|
3258
|
+
required: true,
|
|
3259
|
+
type: Object
|
|
3260
|
+
},
|
|
3261
|
+
icon: {
|
|
3262
|
+
default: void 0,
|
|
3263
|
+
type: String
|
|
3264
|
+
},
|
|
3265
|
+
nested: {
|
|
3266
|
+
default: false,
|
|
3267
|
+
type: [Boolean, Object]
|
|
3268
|
+
},
|
|
3269
|
+
pluginKey: {
|
|
3270
|
+
default: void 0,
|
|
3271
|
+
type: [String, Object]
|
|
3272
|
+
},
|
|
3273
|
+
ui: {
|
|
3274
|
+
default: () => ({}),
|
|
3275
|
+
type: Object
|
|
2516
3276
|
}
|
|
2517
3277
|
},
|
|
2518
3278
|
emits: {
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
uploadError: (_error, _file) => true
|
|
3279
|
+
hover: (_node) => true,
|
|
3280
|
+
nodeChange: (_node) => true
|
|
2522
3281
|
},
|
|
2523
3282
|
setup(props, { attrs, emit, slots }) {
|
|
2524
|
-
const
|
|
2525
|
-
const
|
|
2526
|
-
const
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
}
|
|
2534
|
-
const
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
}
|
|
2539
|
-
const
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
3283
|
+
const UButton = useStandIn("UButton");
|
|
3284
|
+
const current = ref();
|
|
3285
|
+
const nodeAt = (pos) => {
|
|
3286
|
+
if (pos == null || pos < 0) return void 0;
|
|
3287
|
+
const node = props.editor.state.doc.nodeAt(pos);
|
|
3288
|
+
return node ? {
|
|
3289
|
+
node: node.toJSON(),
|
|
3290
|
+
pos
|
|
3291
|
+
} : void 0;
|
|
3292
|
+
};
|
|
3293
|
+
const onNodeChange = ({ pos }) => {
|
|
3294
|
+
current.value = pos;
|
|
3295
|
+
const found = nodeAt(pos);
|
|
3296
|
+
if (found) emit("hover", found);
|
|
3297
|
+
};
|
|
3298
|
+
const onClick = () => {
|
|
3299
|
+
const found = nodeAt(current.value);
|
|
3300
|
+
if (!found) return void 0;
|
|
3301
|
+
emit("nodeChange", found);
|
|
3302
|
+
props.editor.chain().setNodeSelection(found.pos).run();
|
|
3303
|
+
return found;
|
|
3304
|
+
};
|
|
3305
|
+
const ui = { handle: (options) => [
|
|
3306
|
+
"vh-editor-drag-handle__handle",
|
|
3307
|
+
props.ui.handle,
|
|
3308
|
+
options?.class
|
|
3309
|
+
].filter(Boolean).join(" ") };
|
|
3310
|
+
const handle = ref();
|
|
3311
|
+
let stopFollowing;
|
|
3312
|
+
onMounted(() => {
|
|
3313
|
+
const element = handle.value?.$el;
|
|
3314
|
+
if (element instanceof HTMLElement) stopFollowing = followPlace(element);
|
|
2548
3315
|
});
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
isActive: () => false,
|
|
2562
|
-
isDisabled: () => !options.value
|
|
2563
|
-
}
|
|
2564
|
-
}));
|
|
2565
|
-
provide(editorHandlersKey, handlers);
|
|
2566
|
-
const menu = computed(() => options.value ? [...blocks, image] : blocks);
|
|
2567
|
-
return () => {
|
|
2568
|
-
const current = editor.value;
|
|
2569
|
-
if (!current) return null;
|
|
2570
|
-
return h("div", {
|
|
2571
|
-
...attrs,
|
|
2572
|
-
class: ["vh-markdown-editor", attrs.class]
|
|
2573
|
-
}, [
|
|
2574
|
-
h("div", { class: "vh-markdown-editor-content vh-typeset" }, [h("style", {
|
|
2575
|
-
"data-comark-typeset": "",
|
|
2576
|
-
innerHTML: typesetCss
|
|
2577
|
-
}), h(EditorContent, { editor: current })]),
|
|
2578
|
-
h(UEditorToolbar, {
|
|
2579
|
-
editor: current,
|
|
2580
|
-
items: toolbar,
|
|
2581
|
-
layout: "bubble"
|
|
2582
|
-
}),
|
|
2583
|
-
h(UEditorSuggestionMenu, {
|
|
2584
|
-
editor: current,
|
|
2585
|
-
items: menu.value
|
|
2586
|
-
}),
|
|
2587
|
-
h(UEditorDragHandle, { editor: current }),
|
|
2588
|
-
slots.default?.({ editor: current })
|
|
2589
|
-
]);
|
|
3316
|
+
onBeforeUnmount(() => stopFollowing?.());
|
|
3317
|
+
const computePositionConfig = {
|
|
3318
|
+
middleware: [
|
|
3319
|
+
offset(({ rects }) => ({
|
|
3320
|
+
alignmentAxis: rects.reference.height > 40 ? 0 : (rects.reference.height - rects.floating.height) / 2,
|
|
3321
|
+
mainAxis: 8
|
|
3322
|
+
})),
|
|
3323
|
+
flip(),
|
|
3324
|
+
shift()
|
|
3325
|
+
],
|
|
3326
|
+
placement: "left-start",
|
|
3327
|
+
strategy: "absolute"
|
|
2590
3328
|
};
|
|
3329
|
+
return () => h(BlockHandle, {
|
|
3330
|
+
class: ["vh-editor-drag-handle", props.ui.root].filter(Boolean).join(" "),
|
|
3331
|
+
computePositionConfig,
|
|
3332
|
+
ref: handle,
|
|
3333
|
+
"data-slot": "editor-drag-handle",
|
|
3334
|
+
editor: props.editor,
|
|
3335
|
+
nested: props.nested,
|
|
3336
|
+
onClick,
|
|
3337
|
+
onNodeChange,
|
|
3338
|
+
...props.pluginKey ? { pluginKey: props.pluginKey } : {}
|
|
3339
|
+
}, () => slots.default ? slots.default({
|
|
3340
|
+
onClick,
|
|
3341
|
+
ui
|
|
3342
|
+
}) : h(UButton, {
|
|
3343
|
+
"aria-label": "Drag to move, or press to select the block",
|
|
3344
|
+
color: "neutral",
|
|
3345
|
+
icon: props.icon ?? "i-lucide-grip-vertical",
|
|
3346
|
+
size: "sm",
|
|
3347
|
+
variant: "ghost",
|
|
3348
|
+
...attrs,
|
|
3349
|
+
class: ui.handle({ class: attrs.class }),
|
|
3350
|
+
"data-slot": "editor-drag-handle-button"
|
|
3351
|
+
}));
|
|
2591
3352
|
}
|
|
2592
3353
|
});
|
|
2593
|
-
export { blobUpload as n,
|
|
3354
|
+
export { useMarkdownEditor as a, mapEditorItems as c, blobUpload as i, UEditorSuggestionMenu as n, createEditorHandlers as o, UEditorToolbar as r, editorHandlersKey as s, UEditorDragHandle as t };
|