reactjs-tiptap-editor 1.0.11 → 1.0.13
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/lib/ActionMenuButton-DNj0f_A4.cjs +1 -0
- package/lib/{ActionMenuButton-DTXFBdGX.js → ActionMenuButton-l5rSmAO_.js} +18 -14
- package/lib/Attachment.cjs +2 -2
- package/lib/Attachment.js +24 -21
- package/lib/Blockquote.cjs +2 -2
- package/lib/Blockquote.js +7 -5
- package/lib/Bold.cjs +1 -1
- package/lib/Bold.js +11 -9
- package/lib/BulletList.cjs +1 -1
- package/lib/BulletList.js +14 -12
- package/lib/Callout.cjs +1 -0
- package/lib/Callout.js +230 -0
- package/lib/Clear.cjs +1 -1
- package/lib/Clear.js +3 -3
- package/lib/Code.cjs +1 -1
- package/lib/Code.js +11 -9
- package/lib/CodeBlock.cjs +39 -39
- package/lib/CodeBlock.js +840 -945
- package/lib/CodeView.cjs +1 -1
- package/lib/CodeView.js +10 -8
- package/lib/Color.cjs +1 -1
- package/lib/Color.js +20 -18
- package/lib/Column.cjs +1 -1
- package/lib/Column.js +7 -5
- package/lib/{Drawer-D0yQ0wR7.js → Drawer-Cbi_MURj.js} +10 -9
- package/lib/Drawer-DKU32YW_.cjs +1 -0
- package/lib/Drawer.cjs +1 -1
- package/lib/Drawer.js +3 -3
- package/lib/Emoji.cjs +1 -1
- package/lib/Emoji.js +11 -9
- package/lib/{Excalidraw-CO4IRHmG.js → Excalidraw-CWrVL5hs.js} +28 -27
- package/lib/Excalidraw-Kb-TRcWY.cjs +1 -0
- package/lib/Excalidraw.cjs +1 -1
- package/lib/Excalidraw.js +2 -2
- package/lib/ExportPdf.cjs +2 -2
- package/lib/ExportPdf.js +7 -5
- package/lib/ExportWord.cjs +1 -1
- package/lib/ExportWord.js +7 -5
- package/lib/FontFamily.cjs +1 -1
- package/lib/FontFamily.js +9 -8
- package/lib/FontSize.cjs +1 -1
- package/lib/FontSize.js +13 -12
- package/lib/Heading.cjs +1 -1
- package/lib/Heading.js +20 -19
- package/lib/Highlight.cjs +1 -1
- package/lib/Highlight.js +9 -7
- package/lib/History.cjs +1 -1
- package/lib/History.js +11 -8
- package/lib/HorizontalRule.cjs +1 -1
- package/lib/HorizontalRule.js +7 -5
- package/lib/Icon-Ctva8VeB.js +12 -0
- package/lib/Icon-yqCglrdK.cjs +1 -0
- package/lib/Iframe-BczF8Hex.cjs +1 -0
- package/lib/{Iframe-BEO28NPs.js → Iframe-C942bNjs.js} +42 -40
- package/lib/Iframe.cjs +1 -1
- package/lib/Iframe.js +2 -2
- package/lib/Image.cjs +1 -1
- package/lib/Image.js +25 -23
- package/lib/ImageGif.cjs +1 -1
- package/lib/ImageGif.js +50 -48
- package/lib/ImportWord.cjs +31 -31
- package/lib/ImportWord.js +8 -6
- package/lib/{Indent-CXurBbOr.js → Indent-C_O5WdyR.js} +26 -24
- package/lib/Indent-CkEC7x36.cjs +1 -0
- package/lib/Indent.cjs +1 -1
- package/lib/Indent.js +2 -2
- package/lib/Italic.cjs +1 -1
- package/lib/Italic.js +12 -10
- package/lib/{Katex-Bvj469K1.js → Katex-D3PEWimM.js} +12 -10
- package/lib/Katex-DW_HjgNM.cjs +4 -0
- package/lib/Katex.cjs +1 -1
- package/lib/Katex.js +2 -2
- package/lib/LineHeight.cjs +1 -1
- package/lib/LineHeight.js +10 -8
- package/lib/Link.cjs +1 -1
- package/lib/Link.js +2 -2
- package/lib/{LinkEditBlock-8ePAZ-G1.cjs → LinkEditBlock-DL1e2ILk.cjs} +1 -1
- package/lib/{LinkEditBlock-DjXUEubR.js → LinkEditBlock-h5054QDo.js} +22 -20
- package/lib/Mention.cjs +1 -1
- package/lib/Mention.js +3 -3
- package/lib/Mermaid.cjs +2 -2
- package/lib/Mermaid.js +8 -8
- package/lib/MoreMark.cjs +1 -1
- package/lib/MoreMark.js +25 -22
- package/lib/OrderedList.cjs +1 -1
- package/lib/OrderedList.js +10 -8
- package/lib/SearchAndReplace.cjs +1 -1
- package/lib/SearchAndReplace.js +43 -41
- package/lib/SlashCommand.cjs +1 -1
- package/lib/SlashCommand.js +6 -6
- package/lib/SlashCommandNodeView-BqrmHCpu.cjs +1 -0
- package/lib/{SlashCommandNodeView-CcqL8ymb.js → SlashCommandNodeView-DXUqkx82.js} +75 -66
- package/lib/Strike.cjs +1 -1
- package/lib/Strike.js +7 -5
- package/lib/{Table-9Y0Cg8Ab.js → Table-DdrY4jcM.js} +10 -8
- package/lib/Table-kY0nbqJo.cjs +9 -0
- package/lib/Table.cjs +1 -1
- package/lib/Table.js +1 -1
- package/lib/TaskList.cjs +1 -1
- package/lib/TaskList.js +15 -13
- package/lib/TextAlign.cjs +1 -1
- package/lib/TextAlign.js +20 -17
- package/lib/TextDirection.cjs +1 -1
- package/lib/TextDirection.js +20 -17
- package/lib/TextUnderline.cjs +1 -1
- package/lib/TextUnderline.js +7 -5
- package/lib/{Twitter-DWwd0vHR.js → Twitter-B-JQ3ZJ1.js} +51 -49
- package/lib/Twitter-DjZcVa3l.cjs +1 -0
- package/lib/Twitter.cjs +1 -1
- package/lib/Twitter.js +2 -2
- package/lib/Video.cjs +1 -1
- package/lib/Video.js +13 -11
- package/lib/bubble.cjs +4 -4
- package/lib/bubble.js +2084 -1949
- package/lib/button-BS3n6_Aq.cjs +1 -0
- package/lib/{button-RnHbJfd-.js → button-Uv01FNnd.js} +9 -8
- package/lib/{checkbox-CTEN0q4y.cjs → checkbox-C8ByRi7-.cjs} +1 -1
- package/lib/{checkbox-CLSoR1Qj.js → checkbox-DEFNwGwb.js} +1 -1
- package/lib/{index-sVScpCFG.js → clsx-BWSGDJNJ.js} +224 -224
- package/lib/{index-BBNITgNi.cjs → clsx-CXbNJWDD.cjs} +13 -13
- package/lib/components/Bubble/RichTextBubbleCallout.d.ts +1 -0
- package/lib/components/Bubble/index.d.ts +1 -0
- package/lib/components/ui/index.d.ts +1 -0
- package/lib/{dialog-CMC9hsCo.cjs → dialog-Bt5zwGYB.cjs} +1 -1
- package/lib/{dialog-D_HCtKvc.js → dialog-DwTMZSt6.js} +1 -1
- package/lib/{dropdown-menu-66q7Ofc5.js → dropdown-menu-BetI14G6.js} +1 -1
- package/lib/{dropdown-menu-DKSAS-w_.cjs → dropdown-menu-Bo68IEOT.cjs} +1 -1
- package/lib/events.constant-Dq21NPdV.cjs +1 -0
- package/lib/events.constant-do95b767.js +21 -0
- package/lib/extensions/Callout/Callout.d.ts +18 -0
- package/lib/extensions/Callout/components/NodeViewCallout/NodeViewCallout.d.ts +1 -0
- package/lib/extensions/Callout/components/RichTextCallout.d.ts +1 -0
- package/lib/extensions/Callout/index.d.ts +1 -0
- package/lib/{index-CApXPpjF.cjs → index-BCzvbrf5.cjs} +1 -1
- package/lib/{index-9A6-kVBM.js → index-BDKHXe7R.js} +1 -1
- package/lib/{index-DmPwbBqm.js → index-CHKWG6E8.js} +1 -1
- package/lib/index-CcoWj0mF.js +426 -0
- package/lib/index-CjhjjJsN.cjs +1 -0
- package/lib/index-Cs6cp0Y6.cjs +1 -0
- package/lib/index-D3RLYf-J.cjs +1 -0
- package/lib/{index-C3zg3DPB.js → index-DF5ZPtWM.js} +371 -1177
- package/lib/{index-DRHrDScg.js → index-DJbmnBzK.js} +1 -1
- package/lib/index-Doks9cbR.cjs +1 -0
- package/lib/{index-0OnGZkVF.js → index-Dujzr6bY.js} +179 -317
- package/lib/index-VhKd73hZ.cjs +1 -0
- package/lib/{index-DKt5wfAc.js → index-mR8PNv5P.js} +1 -1
- package/lib/{index--nUS7Y66.cjs → index-neeeY2o7.cjs} +3 -3
- package/lib/index.cjs +9 -2
- package/lib/index.js +142 -26
- package/lib/{input-CvyMYMZG.js → input-DUBdJD3L.js} +5 -5
- package/lib/{input-D555880-.cjs → input-Dt_BA_9B.cjs} +1 -1
- package/lib/{isNumber-Bv1Qhmw8.cjs → isNumber-BTYSVlKo.cjs} +1 -1
- package/lib/{isNumber-DF0fU3ob.js → isNumber-CIgubz2e.js} +1 -1
- package/lib/label-JNOksCA-.cjs +1 -0
- package/lib/label-topD46-u.js +19 -0
- package/lib/locale-bundle.cjs +1 -1
- package/lib/locale-bundle.js +6 -7
- package/lib/locales/en.d.ts +16 -0
- package/lib/locales/fi.d.ts +16 -0
- package/lib/locales/hu.d.ts +16 -0
- package/lib/locales/index.d.ts +99 -4316
- package/lib/locales/pt-br.d.ts +16 -0
- package/lib/locales/vi.d.ts +16 -0
- package/lib/locales/zh-cn.d.ts +16 -0
- package/lib/{popover-B7ec5-u2.js → popover-LfNBhRyz.js} +1 -1
- package/lib/{popover-BSzR_R01.cjs → popover-mL-2sX5r.cjs} +1 -1
- package/lib/react-BEoMZB61.cjs +1 -0
- package/lib/react-c9FSfB30.js +27 -0
- package/lib/select-CwGYPsPq.cjs +1 -0
- package/lib/select-DctYuHLH.js +117 -0
- package/lib/separator-Ddfrhn4D.js +329 -0
- package/lib/separator-NoH_SLRW.cjs +1 -0
- package/lib/store/EditorEditableReactive.d.ts +1 -0
- package/lib/store/ThemeColorReactive.d.ts +1 -0
- package/lib/store/commandList.d.ts +1 -1
- package/lib/store/store.d.ts +6 -7
- package/lib/store-CkjKIgjQ.cjs +1 -0
- package/lib/store-DNpS8vXA.js +10 -0
- package/lib/style.css +1 -1
- package/lib/{tabs-CWr9HYaM.js → tabs-BT3AeqQQ.js} +1 -1
- package/lib/{tabs-BTwiZkWd.cjs → tabs-DRSwUeKP.cjs} +1 -1
- package/lib/{textarea-Yetl_PZi.cjs → textarea-BDO6XQoF.cjs} +1 -1
- package/lib/{textarea-BdeLXbp8.js → textarea-DZzMEDfZ.js} +1 -1
- package/lib/theme/theme.d.ts +5 -0
- package/lib/theme.cjs +1 -1
- package/lib/theme.js +37 -8
- package/lib/{throttle-DsowOft0.js → throttle-IERhwcLa.js} +1 -1
- package/lib/throttle-gTTvqDTW.cjs +1 -0
- package/lib/toggle-BQHMh_Q-.cjs +1 -0
- package/lib/toggle-DKHg5sLm.js +99 -0
- package/lib/tooltip-BYtGp6FM.cjs +1 -0
- package/lib/tooltip-DNKq7zgN.js +24 -0
- package/lib/{updatePosition-Bbd8ETMv.js → updatePosition-Bie75EFq.js} +2 -2
- package/lib/updatePosition-Cjuj2E26.cjs +1 -0
- package/lib/useButtonProps-DBJkNDS2.cjs +1 -0
- package/lib/{useButtonProps-cMoicZgd.js → useButtonProps-DVP4s_ER.js} +48 -36
- package/lib/utils/customEvents/events.constant.d.ts +0 -5
- package/package.json +3 -3
- package/lib/ActionMenuButton-BLlse5KO.cjs +0 -1
- package/lib/Drawer-kv6BU_6O.cjs +0 -1
- package/lib/Excalidraw-B82ThkJA.cjs +0 -1
- package/lib/Icon-DRuJhcHK.js +0 -10
- package/lib/Icon-DXePECFW.cjs +0 -1
- package/lib/Iframe-03dn9wcM.cjs +0 -1
- package/lib/Indent-Cqjdn3Jt.cjs +0 -1
- package/lib/Katex-DdWTV5NJ.cjs +0 -4
- package/lib/SlashCommandNodeView-Bl_gwZJB.cjs +0 -1
- package/lib/Table-DBGjezZK.cjs +0 -9
- package/lib/Twitter-Cnvt7GBg.cjs +0 -1
- package/lib/button-BW5bDPz_.cjs +0 -1
- package/lib/events.constant-DQYeJpu5.cjs +0 -1
- package/lib/events.constant-wrlJ_7JZ.js +0 -26
- package/lib/index-BZ6DfR2r.cjs +0 -1
- package/lib/index-C838s-or.cjs +0 -8
- package/lib/index-Cv9Z6dyV.cjs +0 -1
- package/lib/index-FSRjMsxW.cjs +0 -1
- package/lib/label-DsOYPjAo.js +0 -18
- package/lib/label-E6jF3Xud.cjs +0 -1
- package/lib/separator-JaTTqb3J.js +0 -241
- package/lib/separator-PGnA-6Hr.cjs +0 -1
- package/lib/store/ProviderUniqueId.d.ts +0 -6
- package/lib/store-Cf7tFiiI.js +0 -10
- package/lib/store-oDk-lTPM.cjs +0 -1
- package/lib/throttle-BM3Bmbf_.cjs +0 -1
- package/lib/updatePosition-M2IyqkI1.cjs +0 -1
- package/lib/useButtonProps-DfnJiJLV.cjs +0 -1
package/lib/Highlight.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./clsx-CXbNJWDD.cjs"),e=require("react/jsx-runtime"),x=require("react"),C=require("./toggle-BQHMh_Q-.cjs"),m=require("./separator-NoH_SLRW.cjs");require("./index-D3RLYf-J.cjs");require("./theme.cjs");const a=require("./useButtonProps-DBJkNDS2.cjs"),L=require("./Icon-yqCglrdK.cjs"),H=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,M=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,v=l.Mark.create({name:"highlight",addOptions(){return{multicolor:!1,HTMLAttributes:{}}},addAttributes(){return this.options.multicolor?{color:{default:null,parseHTML:t=>t.getAttribute("data-color")||t.style.backgroundColor,renderHTML:t=>t.color?{"data-color":t.color,style:`background-color: ${t.color}; color: inherit`}:{}}}:{}},parseHTML(){return[{tag:"mark"}]},renderHTML({HTMLAttributes:t}){return["mark",l.mergeAttributes(this.options.HTMLAttributes,t),0]},addCommands(){return{setHighlight:t=>({commands:r})=>r.setMark(this.name,t),toggleHighlight:t=>({commands:r})=>r.toggleMark(this.name,t),unsetHighlight:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-h":()=>this.editor.commands.toggleHighlight()}},addInputRules(){return[l.markInputRule({find:H,type:this.type})]},addPasteRules(){return[l.markPasteRule({find:M,type:this.type})]}});function j({fill:t}){return e.jsx("svg",{height:"18px",version:"1.1",viewBox:"0 0 256 256",width:"18px",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("g",{fill:"none",fillRule:"evenodd",stroke:"none",strokeWidth:1,children:e.jsxs("g",{id:"icon/背景颜色",children:[e.jsx("g",{fill:"currentColor",children:e.jsxs("g",{transform:"translate(119.502295, 137.878331) rotate(-135.000000) translate(-119.502295, -137.878331) translate(48.002295, 31.757731)",children:[e.jsx("path",{d:"M100.946943,60.8084699 L43.7469427,60.8084699 C37.2852111,60.8084699 32.0469427,66.0467383 32.0469427,72.5084699 L32.0469427,118.70847 C32.0469427,125.170201 37.2852111,130.40847 43.7469427,130.40847 L100.946943,130.40847 C107.408674,130.40847 112.646943,125.170201 112.646943,118.70847 L112.646943,72.5084699 C112.646943,66.0467383 107.408674,60.8084699 100.946943,60.8084699 Z M93.646,79.808 L93.646,111.408 L51.046,111.408 L51.046,79.808 L93.646,79.808 Z",fillRule:"nonzero"}),e.jsx("path",{d:"M87.9366521,16.90916 L87.9194966,68.2000001 C87.9183543,69.4147389 86.9334998,70.399264 85.7187607,70.4 L56.9423078,70.4 C55.7272813,70.4 54.7423078,69.4150264 54.7423078,68.2 L54.7423078,39.4621057 C54.7423078,37.2523513 55.5736632,35.1234748 57.0711706,33.4985176 L76.4832996,12.4342613 C78.9534987,9.75382857 83.1289108,9.5834005 85.8093436,12.0535996 C87.1658473,13.303709 87.9372691,15.0644715 87.9366521,16.90916 Z",fillRule:"evenodd"}),e.jsx("path",{d:"M131.3,111.241199 L11.7,111.241199 C5.23826843,111.241199 0,116.479467 0,122.941199 L0,200.541199 C0,207.002931 5.23826843,212.241199 11.7,212.241199 L131.3,212.241199 C137.761732,212.241199 143,207.002931 143,200.541199 L143,122.941199 C143,116.479467 137.761732,111.241199 131.3,111.241199 Z M124,130.241 L124,193.241 L19,193.241 L19,130.241 L124,130.241 Z",fillRule:"nonzero"})]})}),e.jsx("path",{d:"M51,218 L205,218 C211.075132,218 216,222.924868 216,229 C216,235.075132 211.075132,240 205,240 L51,240 C44.9248678,240 40,235.075132 40,229 C40,222.924868 44.9248678,218 51,218 Z",fill:typeof t=="string"?t:"none",id:"矩形"})]})})})}function y(){const t=a.useButtonProps(g.name),{tooltip:r=void 0,isActive:s=void 0,defaultColor:i=void 0,colors:o,action:n,shortcutKeys:d}=(t==null?void 0:t.componentProps)??{},{editorDisabled:h}=a.useActive(s),[u,f]=x.useState(i);function p(c){h||n&&(n==null||n(c),f(c))}return t?e.jsx(m.ColorPicker,{colors:o,disabled:h,highlight:!0,onChange:p,value:u,children:e.jsx(C.ActionButton,{disabled:h,tooltip:r,shortcutKeys:d,children:e.jsxs("span",{className:"richtext-flex richtext-items-center richtext-justify-center richtext-gap-[4px] richtext-text-sm",children:[e.jsx(j,{fill:u}),e.jsx(L.IconComponent,{className:"!richtext-h-3 !richtext-w-3 richtext-text-zinc-500",name:"MenuDown"})]})})}):e.jsx(e.Fragment,{})}const g=v.extend({addStorage(){return{currentColor:this.options.defaultColor||void 0}},addOptions(){var t;return{...(t=this.parent)==null?void 0:t.call(this),multicolor:!0,button:({editor:r,t:s,extension:i})=>({componentProps:{action:o=>{if(typeof o=="string"){r.storage.highlight.currentColor=o,r.chain().focus().setHighlight({color:o}).run();return}r.chain().focus().unsetHighlight().run()},isActive:()=>r.isActive("highlight")||!1,disabled:!1,shortcutKeys:i.options.shortcutKeys??["⇧","mod","H"],tooltip:s("editor.highlight.tooltip"),defaultColor:i.options.defaultColor}})}},addKeyboardShortcuts(){var t;return{...(t=this.parent)==null?void 0:t.call(this),"Mod-Shift-h":()=>{const r=this.storage.currentColor||this.options.defaultColor;if(!r){const{color:i}=this.editor.getAttributes("highlight");return i?this.editor.chain().focus().unsetHighlight().run():!1}return this.editor.isActive("highlight",{color:r})?this.editor.chain().focus().unsetHighlight().run():this.editor.chain().focus().setHighlight({color:r}).run()}}}});exports.Highlight=g;exports.RichTextHighlight=y;
|
package/lib/Highlight.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { M as f,
|
|
1
|
+
import { M as f, e as p, f as m, m as C } from "./clsx-BWSGDJNJ.js";
|
|
2
2
|
import { jsx as r, jsxs as h, Fragment as L } from "react/jsx-runtime";
|
|
3
3
|
import { useState as x } from "react";
|
|
4
|
-
import { A as H } from "./
|
|
5
|
-
import { C as M } from "./separator-
|
|
6
|
-
import
|
|
7
|
-
import
|
|
4
|
+
import { A as H } from "./toggle-DKHg5sLm.js";
|
|
5
|
+
import { C as M } from "./separator-Ddfrhn4D.js";
|
|
6
|
+
import "./index-DF5ZPtWM.js";
|
|
7
|
+
import "./theme.js";
|
|
8
|
+
import { u as v, b as A } from "./useButtonProps-DVP4s_ER.js";
|
|
9
|
+
import { I as y } from "./Icon-Ctva8VeB.js";
|
|
8
10
|
const b = /(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/, k = /(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g, R = f.create({
|
|
9
11
|
name: "highlight",
|
|
10
12
|
addOptions() {
|
|
@@ -124,7 +126,7 @@ function w({ fill: t }) {
|
|
|
124
126
|
}
|
|
125
127
|
);
|
|
126
128
|
}
|
|
127
|
-
function
|
|
129
|
+
function D() {
|
|
128
130
|
const t = v(T.name), {
|
|
129
131
|
tooltip: e = void 0,
|
|
130
132
|
isActive: n = void 0,
|
|
@@ -213,5 +215,5 @@ const T = /* @__PURE__ */ R.extend({
|
|
|
213
215
|
});
|
|
214
216
|
export {
|
|
215
217
|
T as Highlight,
|
|
216
|
-
|
|
218
|
+
D as RichTextHighlight
|
|
217
219
|
};
|
package/lib/History.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./index-BBNITgNi.cjs"),C=require("@tiptap/pm/state"),x=require("@tiptap/pm/view"),R=require("./index--nUS7Y66.cjs"),S=require("react/jsx-runtime"),z=require("./index-C838s-or.cjs");require("react");const A=require("./useButtonProps-DfnJiJLV.cjs");function W(r={}){return new p.Plugin({view(e){return new U(e,r)}})}class U{constructor(e,t){var n;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(n=t.width)!==null&&n!==void 0?n:1,this.color=t.color===!1?void 0:t.color||"black",this.class=t.class,this.handlers=["dragover","dragend","drop","dragleave"].map(i=>{let o=s=>{this[i](s)};return e.dom.addEventListener(i,o),{name:i,handler:o}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n,i=this.editorView.dom,o=i.getBoundingClientRect(),s=o.width/i.offsetWidth,l=o.height/i.offsetHeight;if(t){let c=e.nodeBefore,h=e.nodeAfter;if(c||h){let m=this.editorView.nodeDOM(this.cursorPos-(c?c.nodeSize:0));if(m){let v=m.getBoundingClientRect(),M=c?v.bottom:v.top;c&&h&&(M=(M+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let b=this.width/2*l;n={left:v.left,right:v.right,top:M-b,bottom:M+b}}}}if(!n){let c=this.editorView.coordsAtPos(this.cursorPos),h=this.width/2*s;n={left:c.left-h,right:c.left+h,top:c.top,bottom:c.bottom}}let a=this.editorView.dom.offsetParent;this.element||(this.element=a.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",t),this.element.classList.toggle("prosemirror-dropcursor-inline",!t);let d,u;if(!a||a==document.body&&getComputedStyle(a).position=="static")d=-pageXOffset,u=-pageYOffset;else{let c=a.getBoundingClientRect(),h=c.width/a.offsetWidth,m=c.height/a.offsetHeight;d=c.left-a.scrollLeft*h,u=c.top-a.scrollTop*m}this.element.style.left=(n.left-d)/s+"px",this.element.style.top=(n.top-u)/l+"px",this.element.style.width=(n.right-n.left)/s+"px",this.element.style.height=(n.bottom-n.top)/l+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),i=n&&n.type.spec.disableDropCursor,o=typeof i=="function"?i(this.editorView,t,e):i;if(t&&!o){let s=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=p.dropPoint(this.editorView.state.doc,s,this.editorView.dragging.slice);l!=null&&(s=l)}this.setCursor(s),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}class f extends p.Selection{constructor(e){super(e,e)}map(e,t){let n=e.resolve(t.map(this.head));return f.valid(n)?new f(n):p.Selection.near(n)}content(){return p.Slice.empty}eq(e){return e instanceof f&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new f(e.resolve(t.pos))}getBookmark(){return new N(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!q(e)||!X(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,n=!1){e:for(;;){if(!n&&f.valid(e))return e;let i=e.pos,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(t>0?e.indexAfter(s)<l.childCount:e.index(s)>0){o=l.child(t>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=t;let a=e.doc.resolve(i);if(f.valid(a))return a}for(;;){let s=t>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!p.NodeSelection.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*t),n=!1;continue e}break}o=s,i+=t;let l=e.doc.resolve(i);if(f.valid(l))return l}return null}}}f.prototype.visible=!1;f.findFrom=f.findGapCursorFrom;p.Selection.jsonID("gapcursor",f);class N{constructor(e){this.pos=e}map(e){return new N(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return f.valid(t)?new f(t):p.Selection.near(t)}}function B(r){return r.isAtom||r.spec.isolating||r.spec.createGapCursor}function q(r){for(let e=r.depth;e>=0;e--){let t=r.index(e),n=r.node(e);if(t==0){if(n.type.spec.isolating)return!0;continue}for(let i=n.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||B(i.type))return!0;if(i.inlineContent)return!1}}return!0}function X(r){for(let e=r.depth;e>=0;e--){let t=r.indexAfter(e),n=r.node(e);if(t==n.childCount){if(n.type.spec.isolating)return!0;continue}for(let i=n.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||B(i.type))return!0;if(i.inlineContent)return!1}}return!0}function Y(){return new p.Plugin({props:{decorations:$,createSelectionBetween(r,e,t){return e.pos==t.pos&&f.valid(t)?new f(t):null},handleClick:Z,handleKeyDown:J,handleDOMEvents:{beforeinput:Q}}})}const J=R.keydownHandler({ArrowLeft:I("horiz",-1),ArrowRight:I("horiz",1),ArrowUp:I("vert",-1),ArrowDown:I("vert",1)});function I(r,e){const t=r=="vert"?e>0?"down":"up":e>0?"right":"left";return function(n,i,o){let s=n.selection,l=e>0?s.$to:s.$from,a=s.empty;if(s instanceof p.TextSelection){if(!o.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=n.doc.resolve(e>0?l.after():l.before())}let d=f.findGapCursorFrom(l,e,a);return d?(i&&i(n.tr.setSelection(new f(d))),!0):!1}}function Z(r,e,t){if(!r||!r.editable)return!1;let n=r.state.doc.resolve(e);if(!f.valid(n))return!1;let i=r.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&p.NodeSelection.isSelectable(r.state.doc.nodeAt(i.inside))?!1:(r.dispatch(r.state.tr.setSelection(new f(n))),!0)}function Q(r,e){if(e.inputType!="insertCompositionText"||!(r.state.selection instanceof f))return!1;let{$from:t}=r.state.selection,n=t.parent.contentMatchAt(t.index()).findWrapping(r.state.schema.nodes.text);if(!n)return!1;let i=p.Fragment.empty;for(let s=n.length-1;s>=0;s--)i=p.Fragment.from(n[s].createAndFill(null,i));let o=r.state.tr.replace(t.pos,t.pos,new p.Slice(i,0,0));return o.setSelection(p.TextSelection.near(o.doc.resolve(t.pos+1))),r.dispatch(o),!1}function $(r){if(!(r.selection instanceof f))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",R.DecorationSet.create(r.doc,[R.Decoration.widget(r.selection.head,e,{key:"gapcursor"})])}var O=200,g=function(){};g.prototype.append=function(e){return e.length?(e=g.from(e),!this.length&&e||e.length<O&&this.leafAppend(e)||this.length<O&&e.leafPrepend(this)||this.appendInner(e)):this};g.prototype.prepend=function(e){return e.length?g.from(e).append(this):this};g.prototype.appendInner=function(e){return new ee(this,e)};g.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?g.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};g.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};g.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)};g.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var i=[];return this.forEach(function(o,s){return i.push(e(o,s))},t,n),i};g.from=function(e){return e instanceof g?e:e&&e.length?new j(e):g.empty};var j=(function(r){function e(n){r.call(this),this.values=n}r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,s,l){for(var a=o;a<s;a++)if(i(this.values[a],l+a)===!1)return!1},e.prototype.forEachInvertedInner=function(i,o,s,l){for(var a=o-1;a>=s;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=O)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=O)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e})(g);g.empty=new j([]);var ee=(function(r){function e(t,n){r.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(n){return n<this.left.length?this.left.get(n):this.right.get(n-this.left.length)},e.prototype.forEachInner=function(n,i,o,s){var l=this.left.length;if(i<l&&this.left.forEachInner(n,i,Math.min(o,l),s)===!1||o>l&&this.right.forEachInner(n,Math.max(i-l,0),Math.min(this.length,o)-l,s+l)===!1)return!1},e.prototype.forEachInvertedInner=function(n,i,o,s){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(n,i-l,Math.max(o,l)-l,s+l)===!1||o<l&&this.left.forEachInvertedInner(n,Math.min(i,l),o,s)===!1)return!1},e.prototype.sliceInner=function(n,i){if(n==0&&i==this.length)return this;var o=this.left.length;return i<=o?this.left.slice(n,i):n>=o?this.right.slice(n-o,i-o):this.left.slice(n,o).append(this.right.slice(0,i-o))},e.prototype.leafAppend=function(n){var i=this.right.leafAppend(n);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(n){var i=this.left.leafPrepend(n);if(i)return new e(i,this.right)},e.prototype.appendInner=function(n){return this.left.depth>=Math.max(this.right.depth,n.depth)+1?new e(this.left,new e(this.right,n)):new e(this,n)},e})(g);const te=500;class w{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let n=this.items.length;for(;;n--)if(this.items.get(n-1).selection){--n;break}let i,o;t&&(i=this.remapping(n,this.items.length),o=i.maps.length);let s=e.tr,l,a,d=[],u=[];return this.items.forEach((c,h)=>{if(!c.step){i||(i=this.remapping(n,h+1),o=i.maps.length),o--,u.push(c);return}if(i){u.push(new y(c.map));let m=c.step.map(i.slice(o)),v;m&&s.maybeStep(m).doc&&(v=s.mapping.maps[s.mapping.maps.length-1],d.push(new y(v,void 0,void 0,d.length+u.length))),o--,v&&i.appendMap(v,o)}else s.maybeStep(c.step);if(c.selection)return l=i?c.selection.map(i.slice(o)):c.selection,a=new w(this.items.slice(0,n).append(u.reverse().concat(d)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:s,selection:l}}addTransform(e,t,n,i){let o=[],s=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let u=0;u<e.steps.length;u++){let c=e.steps[u].invert(e.docs[u]),h=new y(e.mapping.maps[u],c,t),m;(m=a&&a.merge(h))&&(h=m,u?o.pop():l=l.slice(0,l.length-1)),o.push(h),t&&(s++,t=void 0),i||(a=h)}let d=s-n.depth;return d>ie&&(l=ne(l,d),s-=d),new w(l.append(o),s)}remapping(e,t){let n=new p.Mapping;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=e?n.maps.length-i.mirrorOffset:void 0;n.appendMap(i.map,s)},e,t),n}addMaps(e){return this.eventCount==0?this:new w(this.items.append(e.map(t=>new y(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],i=Math.max(0,this.items.length-t),o=e.mapping,s=e.steps.length,l=this.eventCount;this.items.forEach(h=>{h.selection&&l--},i);let a=t;this.items.forEach(h=>{let m=o.getMirror(--a);if(m==null)return;s=Math.min(s,m);let v=o.maps[m];if(h.step){let M=e.steps[m].invert(e.docs[m]),b=h.selection&&h.selection.map(o.slice(a+1,m));b&&l++,n.push(new y(v,M,b))}else n.push(new y(v))},i);let d=[];for(let h=t;h<s;h++)d.push(new y(o.maps[h]));let u=this.items.slice(0,i).append(d).append(n),c=new w(u,l);return c.emptyItemCount()>te&&(c=c.compress(this.items.length-n.length)),c}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),n=t.maps.length,i=[],o=0;return this.items.forEach((s,l)=>{if(l>=e)i.push(s),s.selection&&o++;else if(s.step){let a=s.step.map(t.slice(n)),d=a&&a.getMap();if(n--,d&&t.appendMap(d,n),a){let u=s.selection&&s.selection.map(t.slice(n));u&&o++;let c=new y(d.invert(),a,u),h,m=i.length-1;(h=i.length&&i[m].merge(c))?i[m]=h:i.push(c)}}else s.map&&n--},this.items.length,0),new w(g.from(i.reverse()),o)}}w.empty=new w(g.empty,0);function ne(r,e){let t;return r.forEach((n,i)=>{if(n.selection&&e--==0)return t=i,!1}),r.slice(t)}class y{constructor(e,t,n,i){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new y(t.getMap().invert(),t,this.selection)}}}class P{constructor(e,t,n,i,o){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=i,this.prevComposition=o}}const ie=20;function re(r,e,t,n){let i=t.getMeta(E),o;if(i)return i.historyState;t.getMeta(le)&&(r=new P(r.done,r.undone,null,0,-1));let s=t.getMeta("appendedTransaction");if(t.steps.length==0)return r;if(s&&s.getMeta(E))return s.getMeta(E).redo?new P(r.done.addTransform(t,void 0,n,T(e)),r.undone,V(t.mapping.maps),r.prevTime,r.prevComposition):new P(r.done,r.undone.addTransform(t,void 0,n,T(e)),null,r.prevTime,r.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=r.prevTime==0||!s&&r.prevComposition!=l&&(r.prevTime<(t.time||0)-n.newGroupDelay||!oe(t,r.prevRanges)),d=s?D(r.prevRanges,t.mapping):V(t.mapping.maps);return new P(r.done.addTransform(t,a?e.selection.getBookmark():void 0,n,T(e)),w.empty,d,t.time,l??r.prevComposition)}else return(o=t.getMeta("rebased"))?new P(r.done.rebased(t,o),r.undone.rebased(t,o),D(r.prevRanges,t.mapping),r.prevTime,r.prevComposition):new P(r.done.addMaps(t.mapping.maps),r.undone.addMaps(t.mapping.maps),D(r.prevRanges,t.mapping),r.prevTime,r.prevComposition)}function oe(r,e){if(!e)return!1;if(!r.docChanged)return!0;let t=!1;return r.mapping.maps[0].forEach((n,i)=>{for(let o=0;o<e.length;o+=2)n<=e[o+1]&&i>=e[o]&&(t=!0)}),t}function V(r){let e=[];for(let t=r.length-1;t>=0&&e.length==0;t--)r[t].forEach((n,i,o,s)=>e.push(o,s));return e}function D(r,e){if(!r)return null;let t=[];for(let n=0;n<r.length;n+=2){let i=e.map(r[n],1),o=e.map(r[n+1],-1);i<=o&&t.push(i,o)}return t}function se(r,e,t){let n=T(e),i=E.get(e).spec.config,o=(t?r.undone:r.done).popEvent(e,n);if(!o)return null;let s=o.selection.resolve(o.transform.doc),l=(t?r.done:r.undone).addTransform(o.transform,e.selection.getBookmark(),i,n),a=new P(t?l:o.remaining,t?o.remaining:l,null,0,-1);return o.transform.setSelection(s).setMeta(E,{redo:t,historyState:a})}let k=!1,K=null;function T(r){let e=r.plugins;if(K!=e){k=!1,K=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){k=!0;break}}return k}const E=new p.PluginKey("history"),le=new p.PluginKey("closeHistory");function ae(r={}){return r={depth:r.depth||100,newGroupDelay:r.newGroupDelay||500},new p.Plugin({key:E,state:{init(){return new P(w.empty,w.empty,null,0,-1)},apply(e,t,n){return re(t,n,e,r)}},config:r,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,i=n=="historyUndo"?G:n=="historyRedo"?_:null;return!i||!e.editable?!1:(t.preventDefault(),i(e.state,e.dispatch))}}}})}function H(r,e){return(t,n)=>{let i=E.getState(t);if(!i||(r?i.undone:i.done).eventCount==0)return!1;if(n){let o=se(i,t,r);o&&n(e?o.scrollIntoView():o)}return!0}}const G=H(!1,!0),_=H(!0,!0);p.Extension.create({name:"characterCount",addOptions(){return{limit:null,mode:"textSize",textCounter:r=>r.length,wordCounter:r=>r.split(" ").filter(e=>e!=="").length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=r=>{const e=(r==null?void 0:r.node)||this.editor.state.doc;if(((r==null?void 0:r.mode)||this.options.mode)==="textSize"){const n=e.textBetween(0,e.content.size,void 0," ");return this.options.textCounter(n)}return e.nodeSize},this.storage.words=r=>{const e=(r==null?void 0:r.node)||this.editor.state.doc,t=e.textBetween(0,e.content.size," "," ");return this.options.wordCounter(t)}},addProseMirrorPlugins(){let r=!1;return[new C.Plugin({key:new C.PluginKey("characterCount"),appendTransaction:(e,t,n)=>{if(r)return;const i=this.options.limit;if(i==null||i===0){r=!0;return}const o=this.storage.characters({node:n.doc});if(o>i){const s=o-i,l=0,a=s;console.warn(`[CharacterCount] Initial content exceeded limit of ${i} characters. Content was automatically trimmed.`);const d=n.tr.deleteRange(l,a);return r=!0,d}r=!0},filterTransaction:(e,t)=>{const n=this.options.limit;if(!e.docChanged||n===0||n===null||n===void 0)return!0;const i=this.storage.characters({node:t.doc}),o=this.storage.characters({node:e.doc});if(o<=n||i>n&&o>n&&o<=i)return!0;if(i>n&&o>n&&o>i||!e.getMeta("paste"))return!1;const l=e.selection.$head.pos,a=o-n,d=l-a,u=l;return e.deleteRange(d,u),!(this.storage.characters({node:e.doc})>n)}})]}});p.Extension.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[W(this.options)]}});p.Extension.create({name:"focus",addOptions(){return{className:"has-focus",mode:"all"}},addProseMirrorPlugins(){return[new C.Plugin({key:new C.PluginKey("focus"),props:{decorations:({doc:r,selection:e})=>{const{isEditable:t,isFocused:n}=this.editor,{anchor:i}=e,o=[];if(!t||!n)return x.DecorationSet.create(r,[]);let s=0;this.options.mode==="deepest"&&r.descendants((a,d)=>{if(a.isText)return;if(!(i>=d&&i<=d+a.nodeSize-1))return!1;s+=1});let l=0;return r.descendants((a,d)=>{if(a.isText||!(i>=d&&i<=d+a.nodeSize-1))return!1;if(l+=1,this.options.mode==="deepest"&&s-l>0||this.options.mode==="shallowest"&&l>1)return this.options.mode==="deepest";o.push(x.Decoration.node(d,d+a.nodeSize,{class:this.options.className}))}),x.DecorationSet.create(r,o)}}})]}});p.Extension.create({name:"gapCursor",addProseMirrorPlugins(){return[Y()]},extendNodeSchema(r){var e;const t={name:r.name,options:r.options,storage:r.storage};return{allowGapCursor:(e=p.callOrReturn(p.getExtensionField(r,"allowGapCursor",t)))!=null?e:null}}});p.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new C.Plugin({key:new C.PluginKey("placeholder"),props:{decorations:({doc:r,selection:e})=>{const t=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:n}=e,i=[];if(!t)return null;const o=this.editor.isEmpty;return r.descendants((s,l)=>{const a=n>=l&&n<=l+s.nodeSize,d=!s.isLeaf&&p.isNodeEmpty(s);if((a||!this.options.showOnlyCurrent)&&d){const u=[this.options.emptyNodeClass];o&&u.push(this.options.emptyEditorClass);const c=x.Decoration.node(l,l+s.nodeSize,{class:u.join(" "),"data-placeholder":typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:s,pos:l,hasAnchor:a}):this.options.placeholder});i.push(c)}return this.options.includeChildren}),x.DecorationSet.create(r,i)}}})]}});p.Extension.create({name:"selection",addOptions(){return{className:"selection"}},addProseMirrorPlugins(){const{editor:r,options:e}=this;return[new C.Plugin({key:new C.PluginKey("selection"),props:{decorations(t){return t.selection.empty||r.isFocused||!r.isEditable||p.isNodeSelection(t.selection)||r.view.dragging?null:x.DecorationSet.create(t.doc,[x.Decoration.inline(t.selection.from,t.selection.to,{class:e.className})])}}})]}});function L({types:r,node:e}){return e&&Array.isArray(r)&&r.includes(e.type)||(e==null?void 0:e.type)===r}p.Extension.create({name:"trailingNode",addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){var r;const e=new C.PluginKey(this.name),t=this.options.node||((r=this.editor.schema.topNodeType.contentMatch.defaultType)==null?void 0:r.name)||"paragraph",n=Object.entries(this.editor.schema.nodes).map(([,i])=>i).filter(i=>(this.options.notAfter||[]).concat(t).includes(i.name));return[new C.Plugin({key:e,appendTransaction:(i,o,s)=>{const{doc:l,tr:a,schema:d}=s,u=e.getState(s),c=l.content.size,h=d.nodes[t];if(u)return a.insert(c,h.create())},state:{init:(i,o)=>{const s=o.tr.doc.lastChild;return!L({node:s,types:n})},apply:(i,o)=>{if(!i.docChanged||i.getMeta("__uniqueIDTransaction"))return o;const s=i.doc.lastChild;return!L({node:s,types:n})}}})]}});var de=p.Extension.create({name:"undoRedo",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:r,dispatch:e})=>G(r,e),redo:()=>({state:r,dispatch:e})=>_(r,e)}},addProseMirrorPlugins(){return[ae(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}});function ce(){var u;const r=A.useButtonProps(F.name),{icon:e=void 0,tooltip:t=void 0,shortcutKeys:n=void 0,tooltipOptions:i={},action:o=void 0,isActive:s=void 0}=((u=r==null?void 0:r.componentProps)==null?void 0:u.undo)??{},{disabled:l}=A.useActive(s),a=z.icons[e],d=()=>{l||o&&o()};return!r||!a?S.jsx(S.Fragment,{}):S.jsx(z.ActionButton,{action:d,disabled:l,icon:e,shortcutKeys:n,tooltip:t,tooltipOptions:i})}function ue(){var d;const r=A.useButtonProps(F.name),{icon:e=void 0,tooltip:t=void 0,shortcutKeys:n=void 0,tooltipOptions:i={},action:o=void 0,isActive:s=void 0}=((d=r==null?void 0:r.componentProps)==null?void 0:d.redo)??{},{disabled:l}=A.useActive(s),a=()=>{l||o&&o()};return r?S.jsx(z.ActionButton,{action:a,disabled:l,icon:e,shortcutKeys:n,tooltip:t,tooltipOptions:i}):S.jsx(S.Fragment,{})}const F=de.extend({addOptions(){var r;return{...(r=this.parent)==null?void 0:r.call(this),depth:100,newGroupDelay:500,button:({editor:e,t,extension:n})=>{var i,o;return{componentProps:{undo:{action:()=>{e.chain().focus().undo().run()},shortcutKeys:((i=n.options.shortcutKeys)==null?void 0:i[0])??["mod","Z"],isActive:()=>e.can().undo(),icon:"Undo2",tooltip:t("editor.undo.tooltip")},redo:{action:()=>{e.chain().focus().redo().run()},shortcutKeys:((o=n.options.shortcutKeys)==null?void 0:o[1])??["shift","mod","Z"],isActive:()=>e.can().redo(),icon:"Redo2",tooltip:t("editor.redo.tooltip")}}}}}}});exports.History=F;exports.RichTextRedo=ue;exports.RichTextUndo=ce;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./clsx-CXbNJWDD.cjs"),C=require("@tiptap/pm/state"),x=require("@tiptap/pm/view"),R=require("./index-neeeY2o7.cjs"),S=require("react/jsx-runtime"),L=require("./toggle-BQHMh_Q-.cjs");require("react");require("./index-D3RLYf-J.cjs");require("./theme.cjs");const A=require("./useButtonProps-DBJkNDS2.cjs"),W=require("./index-VhKd73hZ.cjs");function q(r={}){return new p.Plugin({view(e){return new U(e,r)}})}class U{constructor(e,t){var n;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(n=t.width)!==null&&n!==void 0?n:1,this.color=t.color===!1?void 0:t.color||"black",this.class=t.class,this.handlers=["dragover","dragend","drop","dragleave"].map(i=>{let o=s=>{this[i](s)};return e.dom.addEventListener(i,o),{name:i,handler:o}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n,i=this.editorView.dom,o=i.getBoundingClientRect(),s=o.width/i.offsetWidth,l=o.height/i.offsetHeight;if(t){let c=e.nodeBefore,h=e.nodeAfter;if(c||h){let m=this.editorView.nodeDOM(this.cursorPos-(c?c.nodeSize:0));if(m){let v=m.getBoundingClientRect(),M=c?v.bottom:v.top;c&&h&&(M=(M+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let b=this.width/2*l;n={left:v.left,right:v.right,top:M-b,bottom:M+b}}}}if(!n){let c=this.editorView.coordsAtPos(this.cursorPos),h=this.width/2*s;n={left:c.left-h,right:c.left+h,top:c.top,bottom:c.bottom}}let a=this.editorView.dom.offsetParent;this.element||(this.element=a.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",t),this.element.classList.toggle("prosemirror-dropcursor-inline",!t);let d,u;if(!a||a==document.body&&getComputedStyle(a).position=="static")d=-pageXOffset,u=-pageYOffset;else{let c=a.getBoundingClientRect(),h=c.width/a.offsetWidth,m=c.height/a.offsetHeight;d=c.left-a.scrollLeft*h,u=c.top-a.scrollTop*m}this.element.style.left=(n.left-d)/s+"px",this.element.style.top=(n.top-u)/l+"px",this.element.style.width=(n.right-n.left)/s+"px",this.element.style.height=(n.bottom-n.top)/l+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),i=n&&n.type.spec.disableDropCursor,o=typeof i=="function"?i(this.editorView,t,e):i;if(t&&!o){let s=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=p.dropPoint(this.editorView.state.doc,s,this.editorView.dragging.slice);l!=null&&(s=l)}this.setCursor(s),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}class f extends p.Selection{constructor(e){super(e,e)}map(e,t){let n=e.resolve(t.map(this.head));return f.valid(n)?new f(n):p.Selection.near(n)}content(){return p.Slice.empty}eq(e){return e instanceof f&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new f(e.resolve(t.pos))}getBookmark(){return new z(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!X(e)||!Y(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,n=!1){e:for(;;){if(!n&&f.valid(e))return e;let i=e.pos,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(t>0?e.indexAfter(s)<l.childCount:e.index(s)>0){o=l.child(t>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=t;let a=e.doc.resolve(i);if(f.valid(a))return a}for(;;){let s=t>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!p.NodeSelection.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*t),n=!1;continue e}break}o=s,i+=t;let l=e.doc.resolve(i);if(f.valid(l))return l}return null}}}f.prototype.visible=!1;f.findFrom=f.findGapCursorFrom;p.Selection.jsonID("gapcursor",f);class z{constructor(e){this.pos=e}map(e){return new z(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return f.valid(t)?new f(t):p.Selection.near(t)}}function B(r){return r.isAtom||r.spec.isolating||r.spec.createGapCursor}function X(r){for(let e=r.depth;e>=0;e--){let t=r.index(e),n=r.node(e);if(t==0){if(n.type.spec.isolating)return!0;continue}for(let i=n.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||B(i.type))return!0;if(i.inlineContent)return!1}}return!0}function Y(r){for(let e=r.depth;e>=0;e--){let t=r.indexAfter(e),n=r.node(e);if(t==n.childCount){if(n.type.spec.isolating)return!0;continue}for(let i=n.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||B(i.type))return!0;if(i.inlineContent)return!1}}return!0}function J(){return new p.Plugin({props:{decorations:ee,createSelectionBetween(r,e,t){return e.pos==t.pos&&f.valid(t)?new f(t):null},handleClick:Q,handleKeyDown:Z,handleDOMEvents:{beforeinput:$}}})}const Z=R.keydownHandler({ArrowLeft:I("horiz",-1),ArrowRight:I("horiz",1),ArrowUp:I("vert",-1),ArrowDown:I("vert",1)});function I(r,e){const t=r=="vert"?e>0?"down":"up":e>0?"right":"left";return function(n,i,o){let s=n.selection,l=e>0?s.$to:s.$from,a=s.empty;if(s instanceof p.TextSelection){if(!o.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=n.doc.resolve(e>0?l.after():l.before())}let d=f.findGapCursorFrom(l,e,a);return d?(i&&i(n.tr.setSelection(new f(d))),!0):!1}}function Q(r,e,t){if(!r||!r.editable)return!1;let n=r.state.doc.resolve(e);if(!f.valid(n))return!1;let i=r.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&p.NodeSelection.isSelectable(r.state.doc.nodeAt(i.inside))?!1:(r.dispatch(r.state.tr.setSelection(new f(n))),!0)}function $(r,e){if(e.inputType!="insertCompositionText"||!(r.state.selection instanceof f))return!1;let{$from:t}=r.state.selection,n=t.parent.contentMatchAt(t.index()).findWrapping(r.state.schema.nodes.text);if(!n)return!1;let i=p.Fragment.empty;for(let s=n.length-1;s>=0;s--)i=p.Fragment.from(n[s].createAndFill(null,i));let o=r.state.tr.replace(t.pos,t.pos,new p.Slice(i,0,0));return o.setSelection(p.TextSelection.near(o.doc.resolve(t.pos+1))),r.dispatch(o),!1}function ee(r){if(!(r.selection instanceof f))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",R.DecorationSet.create(r.doc,[R.Decoration.widget(r.selection.head,e,{key:"gapcursor"})])}var O=200,g=function(){};g.prototype.append=function(e){return e.length?(e=g.from(e),!this.length&&e||e.length<O&&this.leafAppend(e)||this.length<O&&e.leafPrepend(this)||this.appendInner(e)):this};g.prototype.prepend=function(e){return e.length?g.from(e).append(this):this};g.prototype.appendInner=function(e){return new te(this,e)};g.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?g.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};g.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};g.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)};g.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var i=[];return this.forEach(function(o,s){return i.push(e(o,s))},t,n),i};g.from=function(e){return e instanceof g?e:e&&e.length?new j(e):g.empty};var j=(function(r){function e(n){r.call(this),this.values=n}r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,s,l){for(var a=o;a<s;a++)if(i(this.values[a],l+a)===!1)return!1},e.prototype.forEachInvertedInner=function(i,o,s,l){for(var a=o-1;a>=s;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=O)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=O)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e})(g);g.empty=new j([]);var te=(function(r){function e(t,n){r.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(n){return n<this.left.length?this.left.get(n):this.right.get(n-this.left.length)},e.prototype.forEachInner=function(n,i,o,s){var l=this.left.length;if(i<l&&this.left.forEachInner(n,i,Math.min(o,l),s)===!1||o>l&&this.right.forEachInner(n,Math.max(i-l,0),Math.min(this.length,o)-l,s+l)===!1)return!1},e.prototype.forEachInvertedInner=function(n,i,o,s){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(n,i-l,Math.max(o,l)-l,s+l)===!1||o<l&&this.left.forEachInvertedInner(n,Math.min(i,l),o,s)===!1)return!1},e.prototype.sliceInner=function(n,i){if(n==0&&i==this.length)return this;var o=this.left.length;return i<=o?this.left.slice(n,i):n>=o?this.right.slice(n-o,i-o):this.left.slice(n,o).append(this.right.slice(0,i-o))},e.prototype.leafAppend=function(n){var i=this.right.leafAppend(n);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(n){var i=this.left.leafPrepend(n);if(i)return new e(i,this.right)},e.prototype.appendInner=function(n){return this.left.depth>=Math.max(this.right.depth,n.depth)+1?new e(this.left,new e(this.right,n)):new e(this,n)},e})(g);const ne=500;class w{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let n=this.items.length;for(;;n--)if(this.items.get(n-1).selection){--n;break}let i,o;t&&(i=this.remapping(n,this.items.length),o=i.maps.length);let s=e.tr,l,a,d=[],u=[];return this.items.forEach((c,h)=>{if(!c.step){i||(i=this.remapping(n,h+1),o=i.maps.length),o--,u.push(c);return}if(i){u.push(new y(c.map));let m=c.step.map(i.slice(o)),v;m&&s.maybeStep(m).doc&&(v=s.mapping.maps[s.mapping.maps.length-1],d.push(new y(v,void 0,void 0,d.length+u.length))),o--,v&&i.appendMap(v,o)}else s.maybeStep(c.step);if(c.selection)return l=i?c.selection.map(i.slice(o)):c.selection,a=new w(this.items.slice(0,n).append(u.reverse().concat(d)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:s,selection:l}}addTransform(e,t,n,i){let o=[],s=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let u=0;u<e.steps.length;u++){let c=e.steps[u].invert(e.docs[u]),h=new y(e.mapping.maps[u],c,t),m;(m=a&&a.merge(h))&&(h=m,u?o.pop():l=l.slice(0,l.length-1)),o.push(h),t&&(s++,t=void 0),i||(a=h)}let d=s-n.depth;return d>re&&(l=ie(l,d),s-=d),new w(l.append(o),s)}remapping(e,t){let n=new p.Mapping;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=e?n.maps.length-i.mirrorOffset:void 0;n.appendMap(i.map,s)},e,t),n}addMaps(e){return this.eventCount==0?this:new w(this.items.append(e.map(t=>new y(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],i=Math.max(0,this.items.length-t),o=e.mapping,s=e.steps.length,l=this.eventCount;this.items.forEach(h=>{h.selection&&l--},i);let a=t;this.items.forEach(h=>{let m=o.getMirror(--a);if(m==null)return;s=Math.min(s,m);let v=o.maps[m];if(h.step){let M=e.steps[m].invert(e.docs[m]),b=h.selection&&h.selection.map(o.slice(a+1,m));b&&l++,n.push(new y(v,M,b))}else n.push(new y(v))},i);let d=[];for(let h=t;h<s;h++)d.push(new y(o.maps[h]));let u=this.items.slice(0,i).append(d).append(n),c=new w(u,l);return c.emptyItemCount()>ne&&(c=c.compress(this.items.length-n.length)),c}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),n=t.maps.length,i=[],o=0;return this.items.forEach((s,l)=>{if(l>=e)i.push(s),s.selection&&o++;else if(s.step){let a=s.step.map(t.slice(n)),d=a&&a.getMap();if(n--,d&&t.appendMap(d,n),a){let u=s.selection&&s.selection.map(t.slice(n));u&&o++;let c=new y(d.invert(),a,u),h,m=i.length-1;(h=i.length&&i[m].merge(c))?i[m]=h:i.push(c)}}else s.map&&n--},this.items.length,0),new w(g.from(i.reverse()),o)}}w.empty=new w(g.empty,0);function ie(r,e){let t;return r.forEach((n,i)=>{if(n.selection&&e--==0)return t=i,!1}),r.slice(t)}class y{constructor(e,t,n,i){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new y(t.getMap().invert(),t,this.selection)}}}class P{constructor(e,t,n,i,o){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=i,this.prevComposition=o}}const re=20;function oe(r,e,t,n){let i=t.getMeta(E),o;if(i)return i.historyState;t.getMeta(ae)&&(r=new P(r.done,r.undone,null,0,-1));let s=t.getMeta("appendedTransaction");if(t.steps.length==0)return r;if(s&&s.getMeta(E))return s.getMeta(E).redo?new P(r.done.addTransform(t,void 0,n,T(e)),r.undone,F(t.mapping.maps),r.prevTime,r.prevComposition):new P(r.done,r.undone.addTransform(t,void 0,n,T(e)),null,r.prevTime,r.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=r.prevTime==0||!s&&r.prevComposition!=l&&(r.prevTime<(t.time||0)-n.newGroupDelay||!se(t,r.prevRanges)),d=s?D(r.prevRanges,t.mapping):F(t.mapping.maps);return new P(r.done.addTransform(t,a?e.selection.getBookmark():void 0,n,T(e)),w.empty,d,t.time,l??r.prevComposition)}else return(o=t.getMeta("rebased"))?new P(r.done.rebased(t,o),r.undone.rebased(t,o),D(r.prevRanges,t.mapping),r.prevTime,r.prevComposition):new P(r.done.addMaps(t.mapping.maps),r.undone.addMaps(t.mapping.maps),D(r.prevRanges,t.mapping),r.prevTime,r.prevComposition)}function se(r,e){if(!e)return!1;if(!r.docChanged)return!0;let t=!1;return r.mapping.maps[0].forEach((n,i)=>{for(let o=0;o<e.length;o+=2)n<=e[o+1]&&i>=e[o]&&(t=!0)}),t}function F(r){let e=[];for(let t=r.length-1;t>=0&&e.length==0;t--)r[t].forEach((n,i,o,s)=>e.push(o,s));return e}function D(r,e){if(!r)return null;let t=[];for(let n=0;n<r.length;n+=2){let i=e.map(r[n],1),o=e.map(r[n+1],-1);i<=o&&t.push(i,o)}return t}function le(r,e,t){let n=T(e),i=E.get(e).spec.config,o=(t?r.undone:r.done).popEvent(e,n);if(!o)return null;let s=o.selection.resolve(o.transform.doc),l=(t?r.done:r.undone).addTransform(o.transform,e.selection.getBookmark(),i,n),a=new P(t?l:o.remaining,t?o.remaining:l,null,0,-1);return o.transform.setSelection(s).setMeta(E,{redo:t,historyState:a})}let k=!1,V=null;function T(r){let e=r.plugins;if(V!=e){k=!1,V=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){k=!0;break}}return k}const E=new p.PluginKey("history"),ae=new p.PluginKey("closeHistory");function de(r={}){return r={depth:r.depth||100,newGroupDelay:r.newGroupDelay||500},new p.Plugin({key:E,state:{init(){return new P(w.empty,w.empty,null,0,-1)},apply(e,t,n){return oe(t,n,e,r)}},config:r,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,i=n=="historyUndo"?G:n=="historyRedo"?_:null;return!i||!e.editable?!1:(t.preventDefault(),i(e.state,e.dispatch))}}}})}function H(r,e){return(t,n)=>{let i=E.getState(t);if(!i||(r?i.undone:i.done).eventCount==0)return!1;if(n){let o=le(i,t,r);o&&n(e?o.scrollIntoView():o)}return!0}}const G=H(!1,!0),_=H(!0,!0);p.Extension.create({name:"characterCount",addOptions(){return{limit:null,mode:"textSize",textCounter:r=>r.length,wordCounter:r=>r.split(" ").filter(e=>e!=="").length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=r=>{const e=(r==null?void 0:r.node)||this.editor.state.doc;if(((r==null?void 0:r.mode)||this.options.mode)==="textSize"){const n=e.textBetween(0,e.content.size,void 0," ");return this.options.textCounter(n)}return e.nodeSize},this.storage.words=r=>{const e=(r==null?void 0:r.node)||this.editor.state.doc,t=e.textBetween(0,e.content.size," "," ");return this.options.wordCounter(t)}},addProseMirrorPlugins(){let r=!1;return[new C.Plugin({key:new C.PluginKey("characterCount"),appendTransaction:(e,t,n)=>{if(r)return;const i=this.options.limit;if(i==null||i===0){r=!0;return}const o=this.storage.characters({node:n.doc});if(o>i){const s=o-i,l=0,a=s;console.warn(`[CharacterCount] Initial content exceeded limit of ${i} characters. Content was automatically trimmed.`);const d=n.tr.deleteRange(l,a);return r=!0,d}r=!0},filterTransaction:(e,t)=>{const n=this.options.limit;if(!e.docChanged||n===0||n===null||n===void 0)return!0;const i=this.storage.characters({node:t.doc}),o=this.storage.characters({node:e.doc});if(o<=n||i>n&&o>n&&o<=i)return!0;if(i>n&&o>n&&o>i||!e.getMeta("paste"))return!1;const l=e.selection.$head.pos,a=o-n,d=l-a,u=l;return e.deleteRange(d,u),!(this.storage.characters({node:e.doc})>n)}})]}});p.Extension.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[q(this.options)]}});p.Extension.create({name:"focus",addOptions(){return{className:"has-focus",mode:"all"}},addProseMirrorPlugins(){return[new C.Plugin({key:new C.PluginKey("focus"),props:{decorations:({doc:r,selection:e})=>{const{isEditable:t,isFocused:n}=this.editor,{anchor:i}=e,o=[];if(!t||!n)return x.DecorationSet.create(r,[]);let s=0;this.options.mode==="deepest"&&r.descendants((a,d)=>{if(a.isText)return;if(!(i>=d&&i<=d+a.nodeSize-1))return!1;s+=1});let l=0;return r.descendants((a,d)=>{if(a.isText||!(i>=d&&i<=d+a.nodeSize-1))return!1;if(l+=1,this.options.mode==="deepest"&&s-l>0||this.options.mode==="shallowest"&&l>1)return this.options.mode==="deepest";o.push(x.Decoration.node(d,d+a.nodeSize,{class:this.options.className}))}),x.DecorationSet.create(r,o)}}})]}});p.Extension.create({name:"gapCursor",addProseMirrorPlugins(){return[J()]},extendNodeSchema(r){var e;const t={name:r.name,options:r.options,storage:r.storage};return{allowGapCursor:(e=p.callOrReturn(p.getExtensionField(r,"allowGapCursor",t)))!=null?e:null}}});p.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new C.Plugin({key:new C.PluginKey("placeholder"),props:{decorations:({doc:r,selection:e})=>{const t=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:n}=e,i=[];if(!t)return null;const o=this.editor.isEmpty;return r.descendants((s,l)=>{const a=n>=l&&n<=l+s.nodeSize,d=!s.isLeaf&&p.isNodeEmpty(s);if((a||!this.options.showOnlyCurrent)&&d){const u=[this.options.emptyNodeClass];o&&u.push(this.options.emptyEditorClass);const c=x.Decoration.node(l,l+s.nodeSize,{class:u.join(" "),"data-placeholder":typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:s,pos:l,hasAnchor:a}):this.options.placeholder});i.push(c)}return this.options.includeChildren}),x.DecorationSet.create(r,i)}}})]}});p.Extension.create({name:"selection",addOptions(){return{className:"selection"}},addProseMirrorPlugins(){const{editor:r,options:e}=this;return[new C.Plugin({key:new C.PluginKey("selection"),props:{decorations(t){return t.selection.empty||r.isFocused||!r.isEditable||p.isNodeSelection(t.selection)||r.view.dragging?null:x.DecorationSet.create(t.doc,[x.Decoration.inline(t.selection.from,t.selection.to,{class:e.className})])}}})]}});function K({types:r,node:e}){return e&&Array.isArray(r)&&r.includes(e.type)||(e==null?void 0:e.type)===r}p.Extension.create({name:"trailingNode",addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){var r;const e=new C.PluginKey(this.name),t=this.options.node||((r=this.editor.schema.topNodeType.contentMatch.defaultType)==null?void 0:r.name)||"paragraph",n=Object.entries(this.editor.schema.nodes).map(([,i])=>i).filter(i=>(this.options.notAfter||[]).concat(t).includes(i.name));return[new C.Plugin({key:e,appendTransaction:(i,o,s)=>{const{doc:l,tr:a,schema:d}=s,u=e.getState(s),c=l.content.size,h=d.nodes[t];if(u)return a.insert(c,h.create())},state:{init:(i,o)=>{const s=o.tr.doc.lastChild;return!K({node:s,types:n})},apply:(i,o)=>{if(!i.docChanged||i.getMeta("__uniqueIDTransaction"))return o;const s=i.doc.lastChild;return!K({node:s,types:n})}}})]}});var ce=p.Extension.create({name:"undoRedo",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:r,dispatch:e})=>G(r,e),redo:()=>({state:r,dispatch:e})=>_(r,e)}},addProseMirrorPlugins(){return[de(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}});function ue(){var u;const r=A.useButtonProps(N.name),{icon:e=void 0,tooltip:t=void 0,shortcutKeys:n=void 0,tooltipOptions:i={},action:o=void 0,isActive:s=void 0}=((u=r==null?void 0:r.componentProps)==null?void 0:u.undo)??{},{disabled:l}=A.useActive(s),a=W.icons[e],d=()=>{l||o&&o()};return!r||!a?S.jsx(S.Fragment,{}):S.jsx(L.ActionButton,{action:d,disabled:l,icon:e,shortcutKeys:n,tooltip:t,tooltipOptions:i})}function pe(){var d;const r=A.useButtonProps(N.name),{icon:e=void 0,tooltip:t=void 0,shortcutKeys:n=void 0,tooltipOptions:i={},action:o=void 0,isActive:s=void 0}=((d=r==null?void 0:r.componentProps)==null?void 0:d.redo)??{},{disabled:l}=A.useActive(s),a=()=>{l||o&&o()};return r?S.jsx(L.ActionButton,{action:a,disabled:l,icon:e,shortcutKeys:n,tooltip:t,tooltipOptions:i}):S.jsx(S.Fragment,{})}const N=ce.extend({addOptions(){var r;return{...(r=this.parent)==null?void 0:r.call(this),depth:100,newGroupDelay:500,button:({editor:e,t,extension:n})=>{var i,o;return{componentProps:{undo:{action:()=>{e.chain().focus().undo().run()},shortcutKeys:((i=n.options.shortcutKeys)==null?void 0:i[0])??["mod","Z"],isActive:()=>e.can().undo(),icon:"Undo2",tooltip:t("editor.undo.tooltip")},redo:{action:()=>{e.chain().focus().redo().run()},shortcutKeys:((o=n.options.shortcutKeys)==null?void 0:o[1])??["shift","mod","Z"],isActive:()=>e.can().redo(),icon:"Redo2",tooltip:t("editor.redo.tooltip")}}}}}}});exports.History=N;exports.RichTextRedo=pe;exports.RichTextUndo=ue;
|
package/lib/History.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { Q as N, y as te, F as V, x as G, T as H, v as _, S as A, U as W, V as ne, E as C, W as re, X as ie, Y as oe,
|
|
1
|
+
import { Q as N, y as te, F as V, x as G, T as H, v as _, S as A, U as W, V as ne, E as C, W as re, X as ie, Y as oe, q as se } from "./clsx-BWSGDJNJ.js";
|
|
2
2
|
import { Plugin as I, PluginKey as b } from "@tiptap/pm/state";
|
|
3
3
|
import { DecorationSet as O, Decoration as R } from "@tiptap/pm/view";
|
|
4
|
-
import { k as le, D as ae, a as de } from "./index-
|
|
4
|
+
import { k as le, D as ae, a as de } from "./index-mR8PNv5P.js";
|
|
5
5
|
import { jsx as T, Fragment as j } from "react/jsx-runtime";
|
|
6
|
-
import { A as U
|
|
6
|
+
import { A as U } from "./toggle-DKHg5sLm.js";
|
|
7
7
|
import "react";
|
|
8
|
-
import
|
|
8
|
+
import "./index-DF5ZPtWM.js";
|
|
9
|
+
import "./theme.js";
|
|
10
|
+
import { u as X, b as Y } from "./useButtonProps-DVP4s_ER.js";
|
|
11
|
+
import { i as ce } from "./index-CcoWj0mF.js";
|
|
9
12
|
function ue(i = {}) {
|
|
10
13
|
return new N({
|
|
11
14
|
view(e) {
|
|
@@ -899,7 +902,7 @@ var Oe = C.create({
|
|
|
899
902
|
};
|
|
900
903
|
}
|
|
901
904
|
});
|
|
902
|
-
function
|
|
905
|
+
function Ge() {
|
|
903
906
|
var u;
|
|
904
907
|
const i = X(ee.name), {
|
|
905
908
|
icon: e = void 0,
|
|
@@ -923,7 +926,7 @@ function Le() {
|
|
|
923
926
|
}
|
|
924
927
|
);
|
|
925
928
|
}
|
|
926
|
-
function
|
|
929
|
+
function He() {
|
|
927
930
|
var d;
|
|
928
931
|
const i = X(ee.name), {
|
|
929
932
|
icon: e = void 0,
|
|
@@ -986,6 +989,6 @@ const ee = /* @__PURE__ */ Oe.extend({
|
|
|
986
989
|
});
|
|
987
990
|
export {
|
|
988
991
|
ee as History,
|
|
989
|
-
|
|
990
|
-
|
|
992
|
+
He as RichTextRedo,
|
|
993
|
+
Ge as RichTextUndo
|
|
991
994
|
};
|
package/lib/HorizontalRule.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./clsx-CXbNJWDD.cjs"),d=require("@tiptap/pm/state"),f=require("./toggle-BQHMh_Q-.cjs"),h=require("react/jsx-runtime");require("react");require("./index-D3RLYf-J.cjs");require("./theme.cjs");const T=require("./useButtonProps-DBJkNDS2.cjs");var A=i.Node3.create({name:"horizontalRule",addOptions(){return{HTMLAttributes:{},nextNodeType:"paragraph"}},group:"block",parseHTML(){return[{tag:"hr"}]},renderHTML({HTMLAttributes:t}){return["hr",i.mergeAttributes(this.options.HTMLAttributes,t)]},markdownTokenName:"hr",parseMarkdown:(t,n)=>n.createNode("horizontalRule"),renderMarkdown:()=>"---",addCommands(){return{setHorizontalRule:()=>({chain:t,state:n})=>{if(!i.canInsertNode(n,n.schema.nodes[this.name]))return!1;const{selection:r}=n,{$to:s}=r,c=t();return i.isNodeSelection(r)?c.insertContentAt(s.pos,{type:this.name}):c.insertContent({type:this.name}),c.command(({state:a,tr:e,dispatch:p})=>{if(p){const{$to:o}=e.selection,u=o.end();if(o.nodeAfter)o.nodeAfter.isTextblock?e.setSelection(d.TextSelection.create(e.doc,o.pos+1)):o.nodeAfter.isBlock?e.setSelection(d.NodeSelection.create(e.doc,o.pos)):e.setSelection(d.TextSelection.create(e.doc,o.pos));else{const l=a.schema.nodes[this.options.nextNodeType]||o.parent.type.contentMatch.defaultType,m=l==null?void 0:l.create();m&&(e.insert(u,m),e.setSelection(d.TextSelection.create(e.doc,u+1)))}e.scrollIntoView()}return!0}).run()}}},addInputRules(){return[i.nodeInputRule({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}});function R(){const t=T.useButtonProps(y.name),{icon:n=void 0,tooltip:r=void 0,shortcutKeys:s=void 0,tooltipOptions:c={},action:a=void 0,isActive:e=void 0}=(t==null?void 0:t.componentProps)??{},{dataState:p,disabled:o,update:u}=T.useToggleActive(e),l=()=>{o||a&&(a(),u())};return t?h.jsx(f.ActionButton,{action:l,dataState:p,disabled:o,icon:n,shortcutKeys:s,tooltip:r,tooltipOptions:c}):h.jsx(h.Fragment,{})}const y=A.extend({addOptions(){var t;return{...(t=this.parent)==null?void 0:t.call(this),button:({editor:n,t:r,extension:s})=>({component:f.ActionButton,componentProps:{action:()=>n.commands.setHorizontalRule(),disabled:!n.can().setHorizontalRule(),icon:"Minus",shortcutKeys:s.options.shortcutKeys??["mod","alt","S"],tooltip:r("editor.horizontalrule.tooltip")}})}},addKeyboardShortcuts(){return{"Mod-Alt-s":()=>this.editor.commands.setHorizontalRule()}},renderHTML(){return["div",i.mergeAttributes(this.options.HTMLAttributes,{"data-type":this.name}),["hr"]]}});exports.HorizontalRule=y;exports.RichTextHorizontalRule=R;
|
package/lib/HorizontalRule.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { N as T, n as A,
|
|
1
|
+
import { N as T, n as A, o as y, q as H, m as h } from "./clsx-BWSGDJNJ.js";
|
|
2
2
|
import { TextSelection as u, NodeSelection as R } from "@tiptap/pm/state";
|
|
3
|
-
import { A as f } from "./
|
|
3
|
+
import { A as f } from "./toggle-DKHg5sLm.js";
|
|
4
4
|
import { jsx as m, Fragment as M } from "react/jsx-runtime";
|
|
5
5
|
import "react";
|
|
6
|
-
import
|
|
6
|
+
import "./index-DF5ZPtWM.js";
|
|
7
|
+
import "./theme.js";
|
|
8
|
+
import { u as v, a as z } from "./useButtonProps-DVP4s_ER.js";
|
|
7
9
|
var S = T.create({
|
|
8
10
|
name: "horizontalRule",
|
|
9
11
|
addOptions() {
|
|
@@ -55,7 +57,7 @@ var S = T.create({
|
|
|
55
57
|
];
|
|
56
58
|
}
|
|
57
59
|
});
|
|
58
|
-
function
|
|
60
|
+
function I() {
|
|
59
61
|
const t = v(b.name), {
|
|
60
62
|
icon: n = void 0,
|
|
61
63
|
tooltip: r = void 0,
|
|
@@ -115,5 +117,5 @@ const b = /* @__PURE__ */ S.extend({
|
|
|
115
117
|
});
|
|
116
118
|
export {
|
|
117
119
|
b as HorizontalRule,
|
|
118
|
-
|
|
120
|
+
I as RichTextHorizontalRule
|
|
119
121
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import "./index-DF5ZPtWM.js";
|
|
4
|
+
import "./theme.js";
|
|
5
|
+
import { i as c } from "./index-CcoWj0mF.js";
|
|
6
|
+
function x(t) {
|
|
7
|
+
const n = c[t.name];
|
|
8
|
+
return n ? /* @__PURE__ */ i(n, { onClick: t == null ? void 0 : t.onClick, className: `richtext-w-4 richtext-h-4 ${(t == null ? void 0 : t.className) || ""}` }) : null;
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
x as I
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const c=require("react/jsx-runtime");require("react");require("./index-D3RLYf-J.cjs");require("./theme.cjs");const i=require("./index-VhKd73hZ.cjs");function t(e){const n=i.icons[e.name];return n?c.jsx(n,{onClick:e==null?void 0:e.onClick,className:`richtext-w-4 richtext-h-4 ${(e==null?void 0:e.className)||""}`}):null}exports.IconComponent=t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const u=require("./clsx-CXbNJWDD.cjs"),s=require("react/jsx-runtime"),b=require("react"),y=require("re-resizable"),h=require("./dom-dataset-BqoJhJXt.cjs"),S=require("./toggle-BQHMh_Q-.cjs"),I=require("./index-D3RLYf-J.cjs");require("./theme.cjs");const g=require("./useButtonProps-DBJkNDS2.cjs"),P=require("./input-Dt_BA_9B.cjs"),R=require("./button-BS3n6_Aq.cjs"),m={youtube:{example:"https://www.youtube.com/watch?v=I4sMhHbHYXM",src:"https://www.youtube.com/embed/I4sMhHbHYXM",srcPrefix:"https://www.youtube.com/embed",linkRule:[/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\s/]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[&?]v=)|youtu\.be\/)([\w-]{11})/]},youku:{example:"https://v.youku.com/v_show/id_XNDM0NDM4MTcy.html?spm=a2h0c.8166622.PhoneSokuUgc_4.dtitle",src:"https://player.youku.com/embed/XNDM0NDM4MTcy",srcPrefix:"https://player.youku.com/embed",linkRule:[String.raw`v.youku.com\/v_show\/id_\w+\=*`],idRule:String.raw`id_\w+\=*`},bilibili:{example:"https://www.bilibili.com/video/BV1EJ411u7DN",src:"https://player.bilibili.com/player.html?bvid=BV1EJ411u7DN",srcPrefix:"https://player.bilibili.com/player.html?bvid",linkRule:[String.raw`www.bilibili.com\/video\/\w+`]},qqvideo:{example:"https://v.qq.com/x/cover/mzc0020006aw1mn/u0033nvzb5v.html",src:"https://v.qq.com/txp/iframe/player.html?vid=u0033nvzb5v",srcPrefix:"https://v.qq.com/txp/iframe/player.html?vid",linkRule:[String.raw`v.qq.com\/x\/cover\/\w+\/\w+`]},amap:{example:"https://ditu.amap.com/",src:"https://www.amap.com/place/B000A45467",srcPrefix:"",linkRule:[String.raw`\.amap\.com`]},baidu_map:{example:"https://j.map.baidu.com/15/fo",src:"https://j.map.baidu.com/15/fo",srcPrefix:"",linkRule:[String.raw`map\.baidu\.com`]},modao:{example:"https://free.modao.cc/app/2cd26580a6717a147454df7470e7ec464093cba3/embed/v2#screen=sk71k6d1dfxulzx",src:"https://free.modao.cc/app/6UkpAxcGE3nPz52GLqhnOZgC7MATBSy/embed/v2",srcPrefix:"",linkRule:[String.raw`https:\/\/\w+.modao.cc\/app\/\w+\/embed\/v2`],tips:"Modao > More > Share > Embed > COPY"},lanhu:{example:"https://lanhuapp.com/link/#/invite?sid=evP7L",src:"https://lanhuapp.com/url/evP7L",srcPrefix:"",linkRule:[String.raw`https:\/\/lanhuapp.com\/url\/\w+`],tips:"Lanhu > Project > Share > Copy Link"},figma:{example:"https://www.figma.com/file/aS9uSgPXoNpaPkzbjNcK8v/Demo?node-id=0%3A1",src:"https://www.figma.com/file/aS9uSgPXoNpaPkzbjNcK8v/Demo?node-id=0%3A1",srcPrefix:"https://www.figma.com/embed?embed_host=share&url",linkRule:[String.raw`https:\/\/www.figma.com\/file\/\w+`]},canva:{example:"https://www.canva.cn/design/DAD61-t29UI/view",src:"https://www.canva.cn/design/DAD61-t29UI/view",srcPrefix:"",linkRule:[String.raw`https:\/\/www.canva.cn\/design\/.+\/view`]},processon:{example:"https://www.processon.com/embed/5ea99d8607912948b0e6fe78",src:"https://www.processon.com/embed/5ea99d8607912948b0e6fe78",srcPrefix:"",linkRule:[String.raw`https:\/\/www.processon.com\/embed\/\w+`]},codepen:{example:"https://codepen.io/mekery/embed/YzyrKOJ",src:"https://codepen.io/mekery/embed/YzyrKOJ",srcPrefix:"",linkRule:[String.raw`https:\/\/codepen.io\/.+\/embed\/\w+`]},jinshuju:{example:"https://jinshuju.net/f/q9YvVf",src:"https://jinshuju.net/f/q9YvVf",srcPrefix:"",linkRule:[String.raw`https:\/\/jinshuju.net\/f\/\w+`]},iframe:{example:"https://v.youku.com/v_show/id_XNDM0NDM4MTcy.html",src:"https://player.youku.com/embed/XNDM0NDM4MTcy",srcPrefix:"",linkRule:[".+"]},googlemaps:{example:"https://goo.gl/maps/8Ys8b4K1ZJY2",src:"https://www.google.com/maps/embed?pb=https://goo.gl/maps/8Ys8b4K1ZJY2",srcPrefix:"",linkRule:[String.raw`https:\/\/goo.gl\/maps\/\w+`]}};function j(e){const t=m.youtube,i=e.matchedUrl;e.validLink=!0;const r=i.split("="),n=r.length;if(n>0){const c=r[n-1];e.src=`${t.srcPrefix}/${c}`,e.validId=!0}return e}function q(e){const t=m.youku,i=e.matchedUrl,r=t.idRule,n=new RegExp(r),c=i.match(n);if(c&&c.length>0){const o=c[0].slice(3);e.validId=!0,e.src=`${t.srcPrefix}/${o}`}else e.validId=!1;return e}function M(e){const t=m.bilibili,r=e.matchedUrl.split("/"),n=r.length;if(n>0){const c=r[n-1];e.src=`${t.srcPrefix}=${c}`,e.validId=!0}return e}function N(e){const t=m.qqvideo,r=e.matchedUrl.split("/"),n=r.length;if(n>0){const c=r[n-1];e.src=`${t.srcPrefix}=${c}`,e.validId=!0}return e}function U(e,t){return t.src=e,t.validId=!0,t}function A(e,t){return t.src=e,t.validId=!0,t}function D(e,t){return t.src=e,t.validId=!0,t.originalLink=e,t}function L(e){return e.src=e.matchedUrl,e.validId=!0,e.originalLink=e.src,e}function _(e){return e.src=e.matchedUrl,e.validId=!0,e.originalLink=e.src,e}function $(e){const t=m.figma;return e.src=`${t.srcPrefix}=${encodeURIComponent(e.matchedUrl)}`,e.validId=!0,e.originalLink=e.matchedUrl,e}function T(e,t){return t.src=`${t.matchedUrl}?embed`,t.validId=!0,t.originalLink=e,t}function z(e,t){return t.src=`${t.matchedUrl}`,t.validId=!0,t.originalLink=e,t}function Y(e){return e.src=`${e.matchedUrl}`,e.validId=!0,e.originalLink=e.src,e}function C(e,t){return t.src=`${t.matchedUrl}?background=white&banner=show&embedded=true`,t.validId=!0,t.originalLink=e,t}function E(e,t){return t.src=`${t.matchedUrl}`,t.validId=!0,t.originalLink=e,t}function H(e,t,i){if(e==="googlemaps")return i.validLink=!0,i.matchedUrl=t,i;const n=m[e].linkRule;for(const c of n){const o=new RegExp(c),a=t.match(o);if(a&&a.length>0)return i.validLink=!0,i.matchedUrl=e==="youtube"?a[1]:a[0],i}return i}function B(e){var i,r;let t="iframe";return((i=e.includes)!=null&&i.call(e,"youtube")||(r=e.includes)!=null&&r.call(e,"youtu.be"))&&(t="youtube"),e.includes("youku")&&(t="youku"),e.includes("bilibili")&&(t="bilibili"),e.includes("qq")&&(t="qqvideo"),e.includes("amap")&&(t="amap"),e.includes("map.baidu")&&(t="baidu_map"),(e.includes("google.com/maps")||e.includes("maps.app.goo.gl"))&&(t="googlemaps"),e.includes("modao")&&(t="modao"),e.includes("lanhuapp")&&(t="lanhu"),e.includes("figma")&&(t="figma"),e.includes("canva")&&(t="canva"),e.includes("processon")&&(t="processon"),e.includes("codepen")&&(t="codepen"),e.includes("jinshuju")&&(t="jinshuju"),e.includes("iframe")&&(t="iframe"),t}function x(e){let t={validLink:!1,validId:!1,matchedUrl:"",originalLink:e,src:""};const i=B(e);if(t=H(i,e,t),!t.validLink)return t;switch(i){case"youtube":return j(t);case"youku":return q(t);case"bilibili":return M(t);case"qqvideo":return N(t);case"amap":return U(e,t);case"baidu_map":return A(e,t);case"googlemaps":return D(e,t);case"modao":return L(t);case"lanhu":return _(t);case"figma":return $(t);case"canva":return T(e,t);case"processon":return z(e,t);case"codepen":return Y(t);case"jinshuju":return C(e,t);case"iframe":return E(e,t);default:return e}}const V="_wrap_5y04w_1",K="_innerWrap_5y04w_15",v={wrap:V,innerWrap:K};function O({editor:e,node:t,updateAttributes:i}){const r=I.useEditableEditor(),{src:n,width:c,height:o}=t.attrs,[a,p]=b.useState("");function l(){if(!a)return;const d=x(a);e.chain().updateAttributes(f.name,{src:(d==null?void 0:d.src)||a}).setNodeSelection(e.state.selection.from).focus().run()}const k=b.useCallback(d=>{i({width:d.width,height:d.height})},[i]);return s.jsxs(u.NodeViewWrapper,{children:[!n&&s.jsxs("div",{className:"richtext-mx-auto richtext-my-[12px] richtext-flex richtext-max-w-[600px] richtext-items-center richtext-justify-center richtext-gap-[10px] richtext-rounded-[12px] richtext-border richtext-border-solid richtext-border-border richtext-p-[10px]",children:[s.jsx(P.Input,{autoFocus:!0,className:"richtext-flex-1",onInput:d=>p(d.target.value),placeholder:"Enter link",type:"url",value:a}),s.jsx(R.Button,{className:"richtext-w-[60px]",onClick:l,children:"OK"})]}),n&&s.jsx(y.Resizable,{size:{width:Number.parseInt(c),height:Number.parseInt(o)},onResizeStop:(d,J,W,w)=>{k({width:Number.parseInt(c)+w.width,height:Number.parseInt(o)+w.height})},children:s.jsx("div",{className:u.clsx(v.wrap,"render-wrapper"),children:s.jsx("div",{className:v.innerWrap,style:{pointerEvents:r?"none":"auto"},children:s.jsx("iframe",{className:"richtext-my-[12px] ",src:n})})})})]})}function X(){const e=g.useButtonProps(f.name),{icon:t=void 0,tooltip:i=void 0,shortcutKeys:r=void 0,tooltipOptions:n={},action:c=void 0,isActive:o=void 0}=(e==null?void 0:e.componentProps)??{},{editorDisabled:a,update:p}=g.useToggleActive(o),l=()=>{a||c&&(c(),p())};return e?s.jsx(S.ActionButton,{action:l,disabled:a,icon:t,shortcutKeys:r,tooltip:i,tooltipOptions:n}):s.jsx(s.Fragment,{})}const f=u.Node3.create({name:"iframe",content:"",marks:"",group:"block",selectable:!0,atom:!0,draggable:!0,addOptions(){var e;return{...(e=this.parent)==null?void 0:e.call(this),HTMLAttributes:{class:"iframe"},button:({editor:t,extension:i,t:r})=>({componentProps:{action:n=>t.commands.setIframe(n),upload:i.options.upload,icon:"Iframe",tooltip:r("editor.iframe.tooltip")}})}},addAttributes(){return{width:{default:600,parseHTML:h.getDatasetAttribute("width")},height:{default:300,parseHTML:h.getDatasetAttribute("height")},src:{default:null,parseHTML:h.getDatasetAttribute("src")},defaultShowPicker:{default:!1},frameborder:{default:0},allowfullscreen:{default:this.options.allowFullscreen,parseHTML:()=>this.options.allowFullscreen}}},parseHTML(){return[{tag:"iframe"}]},renderHTML({HTMLAttributes:e}){return["iframe",u.mergeAttributes(this.options.HTMLAttributes,e)]},addCommands(){return{setIframe:e=>({tr:t,commands:i,chain:r})=>{var c,o,a;if(((a=(o=(c=t.selection)==null?void 0:c.node)==null?void 0:o.type)==null?void 0:a.name)==this.name)return i.updateAttributes(this.name,e);const n=e||{url:""};return r().insertContent({type:this.name,attrs:n}).run()}}},addInputRules(){return[u.nodeInputRule({find:/^\$iframe\$$/,type:this.type,getAttributes:()=>({width:"100%"})})]},addNodeView(){return u.ReactNodeViewRenderer(O)}});exports.Iframe=f;exports.RichTextIframe=X;exports.getServiceSrc=x;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as v, j as x, N as k, k as y, n as S, m as I } from "./clsx-BWSGDJNJ.js";
|
|
2
2
|
import { jsxs as f, jsx as d, Fragment as P } from "react/jsx-runtime";
|
|
3
3
|
import { useState as M, useCallback as R } from "react";
|
|
4
4
|
import { Resizable as N } from "re-resizable";
|
|
5
5
|
import { g as l } from "./dom-dataset-CIEeltF6.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
6
|
+
import { A as j } from "./toggle-DKHg5sLm.js";
|
|
7
|
+
import { a as U } from "./index-DF5ZPtWM.js";
|
|
8
|
+
import "./theme.js";
|
|
9
|
+
import { u as q, a as A } from "./useButtonProps-DVP4s_ER.js";
|
|
10
|
+
import { I as L } from "./input-DUBdJD3L.js";
|
|
11
|
+
import { B as D } from "./button-Uv01FNnd.js";
|
|
10
12
|
const m = {
|
|
11
13
|
youtube: {
|
|
12
14
|
example: "https://www.youtube.com/watch?v=I4sMhHbHYXM",
|
|
@@ -109,15 +111,15 @@ function _(e) {
|
|
|
109
111
|
e.validLink = !0;
|
|
110
112
|
const r = i.split("="), n = r.length;
|
|
111
113
|
if (n > 0) {
|
|
112
|
-
const
|
|
113
|
-
e.src = `${t.srcPrefix}/${
|
|
114
|
+
const a = r[n - 1];
|
|
115
|
+
e.src = `${t.srcPrefix}/${a}`, e.validId = !0;
|
|
114
116
|
}
|
|
115
117
|
return e;
|
|
116
118
|
}
|
|
117
119
|
function $(e) {
|
|
118
|
-
const t = m.youku, i = e.matchedUrl, r = t.idRule, n = new RegExp(r),
|
|
119
|
-
if (
|
|
120
|
-
const o =
|
|
120
|
+
const t = m.youku, i = e.matchedUrl, r = t.idRule, n = new RegExp(r), a = i.match(n);
|
|
121
|
+
if (a && a.length > 0) {
|
|
122
|
+
const o = a[0].slice(3);
|
|
121
123
|
e.validId = !0, e.src = `${t.srcPrefix}/${o}`;
|
|
122
124
|
} else
|
|
123
125
|
e.validId = !1;
|
|
@@ -126,23 +128,23 @@ function $(e) {
|
|
|
126
128
|
function T(e) {
|
|
127
129
|
const t = m.bilibili, r = e.matchedUrl.split("/"), n = r.length;
|
|
128
130
|
if (n > 0) {
|
|
129
|
-
const
|
|
130
|
-
e.src = `${t.srcPrefix}=${
|
|
131
|
+
const a = r[n - 1];
|
|
132
|
+
e.src = `${t.srcPrefix}=${a}`, e.validId = !0;
|
|
131
133
|
}
|
|
132
134
|
return e;
|
|
133
135
|
}
|
|
134
|
-
function
|
|
136
|
+
function Y(e) {
|
|
135
137
|
const t = m.qqvideo, r = e.matchedUrl.split("/"), n = r.length;
|
|
136
138
|
if (n > 0) {
|
|
137
|
-
const
|
|
138
|
-
e.src = `${t.srcPrefix}=${
|
|
139
|
+
const a = r[n - 1];
|
|
140
|
+
e.src = `${t.srcPrefix}=${a}`, e.validId = !0;
|
|
139
141
|
}
|
|
140
142
|
return e;
|
|
141
143
|
}
|
|
142
|
-
function
|
|
144
|
+
function z(e, t) {
|
|
143
145
|
return t.src = e, t.validId = !0, t;
|
|
144
146
|
}
|
|
145
|
-
function
|
|
147
|
+
function C(e, t) {
|
|
146
148
|
return t.src = e, t.validId = !0, t;
|
|
147
149
|
}
|
|
148
150
|
function E(e, t) {
|
|
@@ -177,10 +179,10 @@ function F(e, t, i) {
|
|
|
177
179
|
if (e === "googlemaps")
|
|
178
180
|
return i.validLink = !0, i.matchedUrl = t, i;
|
|
179
181
|
const n = m[e].linkRule;
|
|
180
|
-
for (const
|
|
181
|
-
const o = new RegExp(
|
|
182
|
-
if (
|
|
183
|
-
return i.validLink = !0, i.matchedUrl = e === "youtube" ?
|
|
182
|
+
for (const a of n) {
|
|
183
|
+
const o = new RegExp(a), c = t.match(o);
|
|
184
|
+
if (c && c.length > 0)
|
|
185
|
+
return i.validLink = !0, i.matchedUrl = e === "youtube" ? c[1] : c[0], i;
|
|
184
186
|
}
|
|
185
187
|
return i;
|
|
186
188
|
}
|
|
@@ -208,11 +210,11 @@ function Z(e) {
|
|
|
208
210
|
case "bilibili":
|
|
209
211
|
return T(t);
|
|
210
212
|
case "qqvideo":
|
|
211
|
-
return
|
|
213
|
+
return Y(t);
|
|
212
214
|
case "amap":
|
|
213
|
-
return Y(e, t);
|
|
214
|
-
case "baidu_map":
|
|
215
215
|
return z(e, t);
|
|
216
|
+
case "baidu_map":
|
|
217
|
+
return C(e, t);
|
|
216
218
|
case "googlemaps":
|
|
217
219
|
return E(e, t);
|
|
218
220
|
case "modao":
|
|
@@ -240,13 +242,13 @@ const Q = "_wrap_5y04w_1", ee = "_innerWrap_5y04w_15", w = {
|
|
|
240
242
|
innerWrap: ee
|
|
241
243
|
};
|
|
242
244
|
function te({ editor: e, node: t, updateAttributes: i }) {
|
|
243
|
-
const r =
|
|
245
|
+
const r = U(), { src: n, width: a, height: o } = t.attrs, [c, p] = M("");
|
|
244
246
|
function u() {
|
|
245
|
-
if (!
|
|
247
|
+
if (!c)
|
|
246
248
|
return;
|
|
247
|
-
const s = Z(
|
|
249
|
+
const s = Z(c);
|
|
248
250
|
e.chain().updateAttributes(b.name, {
|
|
249
|
-
src: (s == null ? void 0 : s.src) ||
|
|
251
|
+
src: (s == null ? void 0 : s.src) || c
|
|
250
252
|
}).setNodeSelection(e.state.selection.from).focus().run();
|
|
251
253
|
}
|
|
252
254
|
const g = R(
|
|
@@ -265,7 +267,7 @@ function te({ editor: e, node: t, updateAttributes: i }) {
|
|
|
265
267
|
onInput: (s) => p(s.target.value),
|
|
266
268
|
placeholder: "Enter link",
|
|
267
269
|
type: "url",
|
|
268
|
-
value:
|
|
270
|
+
value: c
|
|
269
271
|
}
|
|
270
272
|
),
|
|
271
273
|
/* @__PURE__ */ d(
|
|
@@ -280,10 +282,10 @@ function te({ editor: e, node: t, updateAttributes: i }) {
|
|
|
280
282
|
n && /* @__PURE__ */ d(
|
|
281
283
|
N,
|
|
282
284
|
{
|
|
283
|
-
size: { width: Number.parseInt(
|
|
285
|
+
size: { width: Number.parseInt(a), height: Number.parseInt(o) },
|
|
284
286
|
onResizeStop: (s, ie, re, h) => {
|
|
285
287
|
g({
|
|
286
|
-
width: Number.parseInt(
|
|
288
|
+
width: Number.parseInt(a) + h.width,
|
|
287
289
|
height: Number.parseInt(o) + h.height
|
|
288
290
|
});
|
|
289
291
|
},
|
|
@@ -305,22 +307,22 @@ function te({ editor: e, node: t, updateAttributes: i }) {
|
|
|
305
307
|
)
|
|
306
308
|
] });
|
|
307
309
|
}
|
|
308
|
-
function
|
|
310
|
+
function fe() {
|
|
309
311
|
const e = q(b.name), {
|
|
310
312
|
icon: t = void 0,
|
|
311
313
|
tooltip: i = void 0,
|
|
312
314
|
shortcutKeys: r = void 0,
|
|
313
315
|
tooltipOptions: n = {},
|
|
314
|
-
action:
|
|
316
|
+
action: a = void 0,
|
|
315
317
|
isActive: o = void 0
|
|
316
|
-
} = (e == null ? void 0 : e.componentProps) ?? {}, { editorDisabled:
|
|
317
|
-
|
|
318
|
+
} = (e == null ? void 0 : e.componentProps) ?? {}, { editorDisabled: c, update: p } = A(o), u = () => {
|
|
319
|
+
c || a && (a(), p());
|
|
318
320
|
};
|
|
319
321
|
return e ? /* @__PURE__ */ d(
|
|
320
|
-
|
|
322
|
+
j,
|
|
321
323
|
{
|
|
322
324
|
action: u,
|
|
323
|
-
disabled:
|
|
325
|
+
disabled: c,
|
|
324
326
|
icon: t,
|
|
325
327
|
shortcutKeys: r,
|
|
326
328
|
tooltip: i,
|
|
@@ -397,8 +399,8 @@ const b = /* @__PURE__ */ k.create({
|
|
|
397
399
|
addCommands() {
|
|
398
400
|
return {
|
|
399
401
|
setIframe: (e) => ({ tr: t, commands: i, chain: r }) => {
|
|
400
|
-
var
|
|
401
|
-
if (((
|
|
402
|
+
var a, o, c;
|
|
403
|
+
if (((c = (o = (a = t.selection) == null ? void 0 : a.node) == null ? void 0 : o.type) == null ? void 0 : c.name) == this.name)
|
|
402
404
|
return i.updateAttributes(this.name, e);
|
|
403
405
|
const n = e || { url: "" };
|
|
404
406
|
return r().insertContent({
|
|
@@ -423,6 +425,6 @@ const b = /* @__PURE__ */ k.create({
|
|
|
423
425
|
});
|
|
424
426
|
export {
|
|
425
427
|
b as I,
|
|
426
|
-
|
|
428
|
+
fe as R,
|
|
427
429
|
Z as g
|
|
428
430
|
};
|
package/lib/Iframe.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./clsx-CXbNJWDD.cjs");const e=require("./Iframe-BczF8Hex.cjs");require("./dom-dataset-BqoJhJXt.cjs");exports.Iframe=e.Iframe;exports.RichTextIframe=e.RichTextIframe;
|
package/lib/Iframe.js
CHANGED
package/lib/Image.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("./index-BBNITgNi.cjs"),W=require("./throttle-BM3Bmbf_.cjs"),n=require("react/jsx-runtime"),o=require("react"),F=require("./index-FSRjMsxW.cjs"),Y=require("./isNumber-Bv1Qhmw8.cjs"),ie=require("./index-C838s-or.cjs"),z=require("./dialog-CMC9hsCo.cjs"),ae=require("react-image-crop"),B=require("./button-BW5bDPz_.cjs"),Z=require("./file-i7e4nQY2.cjs"),U=require("./useButtonProps-DfnJiJLV.cjs"),ee=require("./use-toast-Bz3QCOtE.cjs"),P=require("./Icon-DXePECFW.cjs"),re=require("./store-oDk-lTPM.cjs"),J=require("./events.constant-DQYeJpu5.cjs"),q=require("./tabs-BTwiZkWd.cjs"),se=require("./checkbox-CTEN0q4y.cjs"),K=require("./label-E6jF3Xud.cjs"),Q=require("./input-D555880-.cjs"),H={TOP_LEFT:"tl",TOP_RIGHT:"tr",BOTTOM_LEFT:"bl",BOTTOM_RIGHT:"br"};function le(e){var O,d,E;const[t,a]=o.useState({width:F.IMAGE_MAX_SIZE,height:F.IMAGE_MAX_SIZE}),[c,f]=o.useState({width:0,height:0}),[h]=o.useState([H.TOP_LEFT,H.TOP_RIGHT,H.BOTTOM_LEFT,H.BOTTOM_RIGHT]),[x,T]=o.useState(!1),[g,b]=o.useState({x:0,y:0,w:0,h:0,dir:""}),{align:A,inline:j}=(O=e==null?void 0:e.node)==null?void 0:O.attrs,L=j&&(A==="left"||A==="right"),M=o.useMemo(()=>{var V;const{src:r,alt:I,width:i,height:s,flipX:m,flipY:l}=(V=e==null?void 0:e.node)==null?void 0:V.attrs,y=Y.isNumber(i)?`${i}px`:i,w=Y.isNumber(s)?`${s}px`:s,X=[];m&&X.push("rotateX(180deg)"),l&&X.push("rotateY(180deg)");const ne=X.join(" ");return{src:r||void 0,alt:I||void 0,style:{width:y||void 0,height:w||void 0,transform:ne||"none",...L?{float:A}:{}}}},[(d=e==null?void 0:e.node)==null?void 0:d.attrs]),R=o.useMemo(()=>{const{style:{width:r}}=M;return{width:r==="100%"?r:void 0}},[M]);function _(r){f({width:r.target.width,height:r.target.height})}function C(){const{editor:r,getPos:I}=e;r.commands.setNodeSelection(I())}const S=o.useCallback(W.throttle(()=>{const{editor:r}=e,{width:I}=getComputedStyle(r.view.dom);a(i=>({...i,width:Number.parseInt(I,10)}))},F.IMAGE_THROTTLE_WAIT_TIME),[e==null?void 0:e.editor]);function N(r,I){r.preventDefault(),r.stopPropagation();const i=c.width,s=c.height,m=i/s;let l=Number(e.node.attrs.width),y=Number(e.node.attrs.height);const w=t.width;l&&!y?(l=l>w?w:l,y=Math.round(l/m)):y&&!l?(l=Math.round(y*m),l=l>w?w:l):!l&&!y?(l=i>w?w:i,y=Math.round(l/m)):l=l>w?w:l,T(!0),b({x:r.clientX,y:r.clientY,w:l,h:y,dir:I})}const v=o.useCallback(W.throttle(r=>{if(r.preventDefault(),r.stopPropagation(),!x)return;const{x:I,w:i,dir:s}=g,m=(r.clientX-I)*(/l/.test(s)?-1:1),l=Y.clamp(i+m,F.IMAGE_MIN_SIZE,t.width);e.updateAttributes({width:l,height:null})},F.IMAGE_THROTTLE_WAIT_TIME),[x,g,t,e.updateAttributes]),p=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),x&&(b({x:0,y:0,w:0,h:0,dir:""}),T(!1),C())},[x,C]),u=o.useCallback(()=>{document==null||document.addEventListener("mousemove",v,!0),document==null||document.addEventListener("mouseup",p,!0)},[v,p]),k=o.useCallback(()=>{document==null||document.removeEventListener("mousemove",v,!0),document==null||document.removeEventListener("mouseup",p,!0)},[v,p]);o.useEffect(()=>(x?u():k(),()=>{k()}),[x,u,k]);const D=o.useMemo(()=>new ResizeObserver(()=>S()),[S]);return o.useEffect(()=>(D.observe(e.editor.view.dom),()=>{D.disconnect()}),[e.editor.view.dom,D]),n.jsx(G.NodeViewWrapper,{as:j?"span":"div",className:"image-view",style:{float:L?A:void 0,margin:L?A==="left"?"1em 1em 1em 0":"1em 0 1em 1em":void 0,display:j?"inline":"block",textAlign:L?void 0:A,width:((E=M.style)==null?void 0:E.width)??"auto",...L?{}:R},children:n.jsxs("div",{"data-drag-handle":!0,draggable:"true",style:R,className:`image-view__body ${e!=null&&e.selected?"image-view__body--focused":""} ${x?"image-view__body--resizing":""}`,children:[n.jsx("img",{alt:M.alt,className:"image-view__body__image block",height:"auto",onClick:C,onLoad:_,src:M.src,style:M.style}),(e==null?void 0:e.editor.view.editable)&&((e==null?void 0:e.selected)||x)&&n.jsx("div",{className:"image-resizer",children:h==null?void 0:h.map(r=>n.jsx("span",{className:`image-resizer__handler image-resizer__handler--${r}`,onMouseDown:I=>N(I,r)},`image-dir-${r}`))})]})})}function oe(e,t){const a=e.type,c=e.name.toLowerCase(),f=c.split(".").pop();if(!f)return!1;const x=a||{heif:"image/heif",heic:"image/heic",dng:"image/x-adobe-dng",cr2:"image/x-canon-cr2",nef:"image/x-nikon-nef",arw:"image/x-sony-arw",raf:"image/x-fuji-raf",orf:"image/x-olympus-orf"}[f];return t.some(T=>{if(T.startsWith("."))return c.endsWith(T);if(T.endsWith("/*")){const g=T.split("/")[0];return x==null?void 0:x.startsWith(g+"/")}return x===T})}function te(e,t){const{acceptMimes:a,maxSize:c,t:f,toast:h}=t,x=[];return(Array.isArray(e)?e:Object.values(e)).forEach(g=>{if(!oe(g,a)){t.onError?t.onError({type:"type",message:f("editor.upload.fileTypeNotSupported",{fileName:g.name}),file:g}):h({variant:"default",title:f("editor.upload.fileTypeNotSupported",{fileName:g.name})});return}if(g.size>c){const b=(c/1024/1024).toFixed(2);t.onError?t.onError({type:"size",message:f("editor.upload.fileSizeTooBig",{fileName:g.name,size:b}),file:g}):h({variant:"default",title:f("editor.upload.fileSizeTooBig",{fileName:g.name,size:b})});return}x.push(g)}),x}function ce({editor:e,imageInline:t,onClose:a,disabled:c,alt:f}){var r,I;const{t:h}=F.useLocale(),{toast:x}=ee.useToast(),[T,g]=o.useState(!1),[b,A]=o.useState(!1),j=o.useRef(null),[L,M]=o.useState(),[R,_]=o.useState(""),C=o.useRef(null),[S,N]=o.useState({src:"",file:null}),v=U.useExtension($.name),p=o.useMemo(()=>(v==null?void 0:v.options)??{},[v]);function u(i){if(j.current&&i.width&&i.height){const s=k(j.current,i);_(s)}}function k(i,s){const m=document.createElement("canvas"),l=i.naturalWidth/i.width,y=i.naturalHeight/i.height;m.width=s.width*l,m.height=s.height*y;const w=m.getContext("2d");return w&&(w.imageSmoothingEnabled=!1,w.drawImage(i,s.x*l,s.y*y,s.width*l,s.height*y,0,0,s.width*l,s.height*y)),m.toDataURL("image/png",1)}const D=o.useCallback(async()=>{var i;if(!b){A(!0);try{const s=Z.dataURLtoFile(R,((i=S==null?void 0:S.file)==null?void 0:i.name)||"image.png");let m="";p.upload?m=await p.upload(s):m=URL.createObjectURL(s),e.chain().focus().setImageInline({src:m,inline:t,alt:f}).run(),g(!1),N({src:"",file:null}),E(),a()}catch(s){console.log("Error cropping image",s)}finally{A(!1)}}},[R,e,t,b,a,(r=S==null?void 0:S.file)==null?void 0:r.name,p]);function O(i){var s;i.preventDefault(),(s=C.current)==null||s.click()}const d=async i=>{var w;const s=(w=i==null?void 0:i.target)==null?void 0:w.files;if(!e||e.isDestroyed||s.length===0){i.target.value="";return}const m=te(s,{acceptMimes:p==null?void 0:p.acceptMimes,maxSize:p==null?void 0:p.maxSize,t:h,toast:x,onError:p.onError});if(m.length<=0){i.target.value="";return}const l=m[0],y=await Z.readImageAsBase64(l);g(!0),N({src:y.src,file:l})},E=()=>{C.current&&(C.current.value="")};return n.jsxs(n.Fragment,{children:[n.jsx(B.Button,{className:"richtext-mt-1 richtext-w-full",disabled:c,onClick:O,size:"sm",children:h("editor.image.dialog.tab.uploadCrop")}),n.jsxs(z.Dialog,{open:T,onOpenChange:i=>{g(i),i||(N({src:"",file:null}),E())},children:[n.jsx(z.DialogTrigger,{}),n.jsxs(z.DialogContent,{children:[n.jsx(z.DialogTitle,{children:h("editor.image.dialog.tab.uploadCrop")}),n.jsx("div",{children:S.src&&n.jsx(ae,{className:"richtext-w-full",crop:L,onChange:i=>M(i),onComplete:i=>u(i),children:n.jsx("img",{alt:"Crop me",ref:j,src:S.src})})}),n.jsxs(z.DialogFooter,{children:[n.jsxs(B.Button,{disabled:b,onClick:()=>{g(!1),N({src:"",file:null}),E()},children:[h("editor.imageUpload.cancel"),n.jsx(P.IconComponent,{className:"richtext-ml-1",name:"Trash2"})]}),n.jsx(B.Button,{className:"richtext-w-fit",disabled:b||!L,onClick:D,children:b?n.jsxs(n.Fragment,{children:[h("editor.imageUpload.uploading"),n.jsx(P.IconComponent,{className:"richtext-ml-1 richtext-animate-spin",name:"Loader"})]}):n.jsxs(n.Fragment,{children:[h("editor.imageUpload.crop"),n.jsx(P.IconComponent,{className:"richtext-ml-1",name:"Crop"})]})})]})]})]}),n.jsx("input",{accept:((I=p==null?void 0:p.acceptMimes)==null?void 0:I.join(","))||"image/*",multiple:!1,onChange:d,ref:C,style:{display:"none"},type:"file"})]})}function ue(){const{t:e}=F.useLocale(),{toast:t}=ee.useToast(),a=U.useEditorInstance(),c=U.useButtonProps($.name),{icon:f,tooltip:h}=(c==null?void 0:c.componentProps)??{},{editorDisabled:x}=U.useToggleActive(),[T,g]=o.useState(!1),[b,A]=o.useState(!1),j=U.useExtension($.name),L=d=>{g(d.detail)},[M,R]=o.useState(""),[_,C]=o.useState(""),S=o.useRef(null),N=(j==null?void 0:j.options.defaultInline)||!1,[v,p]=o.useState(N),u=o.useMemo(()=>j==null?void 0:j.options,[j]);o.useEffect(()=>{const d=J.listenEvent(J.EVENTS.UPLOAD_IMAGE(a.id),L);return()=>{d()}},[]);async function k(d){var I;const E=(I=d==null?void 0:d.target)==null?void 0:I.files;if(!a||a.isDestroyed||E.length===0||b){d.target.value="";return}const r=te(E,{acceptMimes:u==null?void 0:u.acceptMimes,maxSize:u==null?void 0:u.maxSize,t:e,toast:t,onError:u.onError});if(r.length<=0){d.target.value="";return}A(!0);try{if(u!=null&&u.multiple){const i=r.map(async m=>{let l="";return u.upload?l=await u.upload(m):l=URL.createObjectURL(m),l});(await Promise.all(i)).forEach(m=>{a.chain().focus().setImageInline({src:m,inline:v,alt:_}).run()})}else{const i=r[0];let s="";u.upload?s=await u.upload(i):s=URL.createObjectURL(i),a.chain().focus().setImageInline({src:s,inline:v,alt:_}).run()}g(!1),C(""),p(N)}catch(i){console.error("Error uploading image",i),u.onError?u.onError({type:"upload",message:e("editor.upload.error")}):t({variant:"destructive",title:e("editor.upload.error")})}finally{A(!1),d.target.value=""}}function D(d){d.preventDefault(),d.stopPropagation(),a.chain().focus().setImageInline({src:M,inline:v,alt:_}).run(),g(!1),p(N),R(""),C("")}function O(d){var E;d.preventDefault(),(E=S.current)==null||E.click()}return c?n.jsxs(z.Dialog,{onOpenChange:g,open:T,children:[n.jsx(z.DialogTrigger,{asChild:!0,children:n.jsx(ie.ActionButton,{disabled:x,icon:f,tooltip:h,action:()=>{x||g(!0)}})}),n.jsxs(z.DialogContent,{children:[n.jsx(z.DialogTitle,{children:e("editor.image.dialog.title")}),n.jsxs(q.Tabs,{activationMode:"manual",defaultValue:u.resourceImage==="both"||u.resourceImage==="upload"?"upload":"link",children:[u.resourceImage==="both"&&n.jsxs(q.TabsList,{className:"richtext-grid richtext-w-full richtext-grid-cols-2",children:[n.jsx(q.TabsTrigger,{value:"upload",children:e("editor.image.dialog.tab.upload")}),n.jsx(q.TabsTrigger,{value:"link",children:e("editor.image.dialog.tab.url")})]}),n.jsxs("div",{className:"richtext-my-[10px] richtext-flex richtext-items-center richtext-gap-[4px]",children:[n.jsx(se.Checkbox,{checked:v,onCheckedChange:d=>{p(d)}}),n.jsx(K.Label,{children:e("editor.link.dialog.inline")})]}),u.enableAlt&&n.jsxs("div",{className:"richtext-my-[10px] ",children:[n.jsx(K.Label,{className:"mb-[6px]",children:e("editor.imageUpload.alt")}),n.jsx(Q.Input,{onChange:d=>C(d.target.value),required:!0,type:"text",value:_})]}),n.jsxs(q.TabsContent,{value:"upload",children:[n.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-[10px]",children:[n.jsx(B.Button,{className:"richtext-mt-1 richtext-w-full",disabled:b,onClick:O,size:"sm",children:b?n.jsxs(n.Fragment,{children:[e("editor.imageUpload.uploading"),n.jsx(P.IconComponent,{className:"richtext-ml-1 richtext-animate-spin",name:"Loader"})]}):e("editor.image.dialog.tab.upload")}),n.jsx(ce,{alt:_,disabled:b,editor:a,imageInline:v,onClose:()=>{re.actionDialogImage.setOpen(a.id,!1),C("")}})]}),n.jsx("input",{accept:u.acceptMimes.join(",")||"image/*",multiple:u.multiple,onChange:k,ref:S,style:{display:"none"},type:"file"})]}),n.jsx(q.TabsContent,{value:"link",children:n.jsx("form",{onSubmit:D,children:n.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2",children:[n.jsx(Q.Input,{autoFocus:!0,onChange:d=>R(d.target.value),placeholder:e("editor.image.dialog.placeholder"),required:!0,type:"url",value:M}),n.jsx(B.Button,{type:"submit",children:e("editor.image.dialog.button.apply")})]})})})]})]})]}):n.jsx(n.Fragment,{})}const de={acceptMimes:["image/jpeg","image/gif","image/png","image/jpg"],maxSize:1024*1024*5,multiple:!0,resourceImage:"both",defaultInline:!1,enableAlt:!0},$=W.index_default.extend({group:"inline",inline:!0,defining:!0,draggable:!0,selectable:!0,addOptions(){var e;return{...de,...(e=this.parent)==null?void 0:e.call(this),upload:()=>Promise.reject("Image Upload Function"),button:({editor:t,extension:a,t:c})=>{var f,h;return{componentProps:{action:()=>!0,upload:a.options.upload,disabled:!((h=(f=t.can()).setImage)!=null&&h.call(f,{})),icon:"ImageUp",tooltip:c("editor.image.tooltip")}}}}},addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),flipX:{default:!1},flipY:{default:!1},width:{default:null,parseHTML:t=>{const a=t.style.width||t.getAttribute("width")||null;return a?Number.parseInt(a,10):null},renderHTML:t=>({width:t.width})},align:{default:"center",parseHTML:t=>t.getAttribute("align"),renderHTML:t=>({align:t.align})},inline:{default:!1,parseHTML:t=>!!t.getAttribute("inline"),renderHTML:t=>({inline:t.inline})},alt:{default:"",parseHTML:t=>t.getAttribute("alt"),renderHTML:t=>({alt:t.alt})}}},addNodeView(){return G.ReactNodeViewRenderer(le)},addCommands(){var e;return{...(e=this.parent)==null?void 0:e.call(this),setImageInline:t=>({commands:a})=>a.insertContent({type:this.name,attrs:{...t,inline:t.inline??this.options.defaultInline}}),updateImage:t=>({commands:a})=>a.updateAttributes(this.name,t),setAlignImage:t=>({commands:a})=>a.updateAttributes(this.name,{align:t})}},renderHTML({HTMLAttributes:e}){const{flipX:t,flipY:a,align:c,inline:f}=e,h=f&&(c==="left"||c==="right"),x=t||a?`transform: rotateX(${t?"180":"0"}deg) rotateY(${a?"180":"0"}deg);`:"",T=h?"":`text-align: ${c};`,A=`${h?`float: ${c};`:""}${h?c==="left"?"margin: 1em 1em 1em 0;":"margin: 1em 0 1em 1em;":""}${x}`;return[f?"span":"div",{style:T,class:"image"},["img",G.mergeAttributes({height:"auto",style:A},this.options.HTMLAttributes,e)]]},parseHTML(){return[{tag:"span.image img",getAttrs:e=>{var h;const t=e==null?void 0:e.parentElement,a=e==null?void 0:e.getAttribute("width"),c=(e==null?void 0:e.getAttribute("flipx"))||!1,f=(e==null?void 0:e.getAttribute("flipy"))||!1;return{src:e==null?void 0:e.getAttribute("src"),alt:e==null?void 0:e.getAttribute("alt"),caption:e==null?void 0:e.getAttribute("caption"),width:a?Number.parseInt(a,10):null,align:(e==null?void 0:e.getAttribute("align"))||((h=t==null?void 0:t.style)==null?void 0:h.textAlign)||null,inline:(e==null?void 0:e.getAttribute("inline"))||!1,flipX:c==="true",flipY:f==="true"}}},{tag:"div[class=image]",getAttrs:e=>{const t=e.querySelector("img"),a=t==null?void 0:t.getAttribute("width"),c=(t==null?void 0:t.getAttribute("flipx"))||!1,f=(t==null?void 0:t.getAttribute("flipy"))||!1;return{src:t==null?void 0:t.getAttribute("src"),alt:t==null?void 0:t.getAttribute("alt"),caption:t==null?void 0:t.getAttribute("caption"),width:a?Number.parseInt(a,10):null,align:(t==null?void 0:t.getAttribute("align"))||e.style.textAlign||null,inline:(t==null?void 0:t.getAttribute("inline"))||!1,flipX:c==="true",flipY:f==="true"}}},{tag:'img[src]:not([src^="data:"])'}]}});exports.Image=$;exports.RichTextImage=ue;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("./clsx-CXbNJWDD.cjs"),W=require("./throttle-gTTvqDTW.cjs"),n=require("react/jsx-runtime"),o=require("react"),D=require("./index-Doks9cbR.cjs"),Y=require("./isNumber-BTYSVlKo.cjs"),ie=require("./toggle-BQHMh_Q-.cjs");require("./index-D3RLYf-J.cjs");require("./theme.cjs");const z=require("./dialog-Bt5zwGYB.cjs"),ae=require("react-image-crop"),B=require("./button-BS3n6_Aq.cjs"),U=require("./useButtonProps-DBJkNDS2.cjs"),Z=require("./file-i7e4nQY2.cjs"),ee=require("./use-toast-Bz3QCOtE.cjs"),P=require("./Icon-yqCglrdK.cjs"),re=require("./store-CkjKIgjQ.cjs"),J=require("./events.constant-Dq21NPdV.cjs"),O=require("./tabs-DRSwUeKP.cjs"),se=require("./checkbox-C8ByRi7-.cjs"),K=require("./label-JNOksCA-.cjs"),Q=require("./input-Dt_BA_9B.cjs"),H={TOP_LEFT:"tl",TOP_RIGHT:"tr",BOTTOM_LEFT:"bl",BOTTOM_RIGHT:"br"};function le(e){var F,d,E;const[t,a]=o.useState({width:D.IMAGE_MAX_SIZE,height:D.IMAGE_MAX_SIZE}),[c,f]=o.useState({width:0,height:0}),[h]=o.useState([H.TOP_LEFT,H.TOP_RIGHT,H.BOTTOM_LEFT,H.BOTTOM_RIGHT]),[x,T]=o.useState(!1),[g,b]=o.useState({x:0,y:0,w:0,h:0,dir:""}),{align:A,inline:j}=(F=e==null?void 0:e.node)==null?void 0:F.attrs,L=j&&(A==="left"||A==="right"),M=o.useMemo(()=>{var V;const{src:r,alt:I,width:i,height:s,flipX:m,flipY:l}=(V=e==null?void 0:e.node)==null?void 0:V.attrs,y=Y.isNumber(i)?`${i}px`:i,w=Y.isNumber(s)?`${s}px`:s,$=[];m&&$.push("rotateX(180deg)"),l&&$.push("rotateY(180deg)");const ne=$.join(" ");return{src:r||void 0,alt:I||void 0,style:{width:y||void 0,height:w||void 0,transform:ne||"none",...L?{float:A}:{}}}},[(d=e==null?void 0:e.node)==null?void 0:d.attrs]),R=o.useMemo(()=>{const{style:{width:r}}=M;return{width:r==="100%"?r:void 0}},[M]);function _(r){f({width:r.target.width,height:r.target.height})}function C(){const{editor:r,getPos:I}=e;r.commands.setNodeSelection(I())}const S=o.useCallback(W.throttle(()=>{const{editor:r}=e,{width:I}=getComputedStyle(r.view.dom);a(i=>({...i,width:Number.parseInt(I,10)}))},D.IMAGE_THROTTLE_WAIT_TIME),[e==null?void 0:e.editor]);function N(r,I){r.preventDefault(),r.stopPropagation();const i=c.width,s=c.height,m=i/s;let l=Number(e.node.attrs.width),y=Number(e.node.attrs.height);const w=t.width;l&&!y?(l=l>w?w:l,y=Math.round(l/m)):y&&!l?(l=Math.round(y*m),l=l>w?w:l):!l&&!y?(l=i>w?w:i,y=Math.round(l/m)):l=l>w?w:l,T(!0),b({x:r.clientX,y:r.clientY,w:l,h:y,dir:I})}const v=o.useCallback(W.throttle(r=>{if(r.preventDefault(),r.stopPropagation(),!x)return;const{x:I,w:i,dir:s}=g,m=(r.clientX-I)*(/l/.test(s)?-1:1),l=Y.clamp(i+m,D.IMAGE_MIN_SIZE,t.width);e.updateAttributes({width:l,height:null})},D.IMAGE_THROTTLE_WAIT_TIME),[x,g,t,e.updateAttributes]),p=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),x&&(b({x:0,y:0,w:0,h:0,dir:""}),T(!1),C())},[x,C]),u=o.useCallback(()=>{document==null||document.addEventListener("mousemove",v,!0),document==null||document.addEventListener("mouseup",p,!0)},[v,p]),k=o.useCallback(()=>{document==null||document.removeEventListener("mousemove",v,!0),document==null||document.removeEventListener("mouseup",p,!0)},[v,p]);o.useEffect(()=>(x?u():k(),()=>{k()}),[x,u,k]);const q=o.useMemo(()=>new ResizeObserver(()=>S()),[S]);return o.useEffect(()=>(q.observe(e.editor.view.dom),()=>{q.disconnect()}),[e.editor.view.dom,q]),n.jsx(G.NodeViewWrapper,{as:j?"span":"div",className:"image-view",style:{float:L?A:void 0,margin:L?A==="left"?"1em 1em 1em 0":"1em 0 1em 1em":void 0,display:j?"inline":"block",textAlign:L?void 0:A,width:((E=M.style)==null?void 0:E.width)??"auto",...L?{}:R},children:n.jsxs("div",{"data-drag-handle":!0,draggable:"true",style:R,className:`image-view__body ${e!=null&&e.selected?"image-view__body--focused":""} ${x?"image-view__body--resizing":""}`,children:[n.jsx("img",{alt:M.alt,className:"image-view__body__image block",height:"auto",onClick:C,onLoad:_,src:M.src,style:M.style}),(e==null?void 0:e.editor.view.editable)&&((e==null?void 0:e.selected)||x)&&n.jsx("div",{className:"image-resizer",children:h==null?void 0:h.map(r=>n.jsx("span",{className:`image-resizer__handler image-resizer__handler--${r}`,onMouseDown:I=>N(I,r)},`image-dir-${r}`))})]})})}function oe(e,t){const a=e.type,c=e.name.toLowerCase(),f=c.split(".").pop();if(!f)return!1;const x=a||{heif:"image/heif",heic:"image/heic",dng:"image/x-adobe-dng",cr2:"image/x-canon-cr2",nef:"image/x-nikon-nef",arw:"image/x-sony-arw",raf:"image/x-fuji-raf",orf:"image/x-olympus-orf"}[f];return t.some(T=>{if(T.startsWith("."))return c.endsWith(T);if(T.endsWith("/*")){const g=T.split("/")[0];return x==null?void 0:x.startsWith(g+"/")}return x===T})}function te(e,t){const{acceptMimes:a,maxSize:c,t:f,toast:h}=t,x=[];return(Array.isArray(e)?e:Object.values(e)).forEach(g=>{if(!oe(g,a)){t.onError?t.onError({type:"type",message:f("editor.upload.fileTypeNotSupported",{fileName:g.name}),file:g}):h({variant:"default",title:f("editor.upload.fileTypeNotSupported",{fileName:g.name})});return}if(g.size>c){const b=(c/1024/1024).toFixed(2);t.onError?t.onError({type:"size",message:f("editor.upload.fileSizeTooBig",{fileName:g.name,size:b}),file:g}):h({variant:"default",title:f("editor.upload.fileSizeTooBig",{fileName:g.name,size:b})});return}x.push(g)}),x}function ce({editor:e,imageInline:t,onClose:a,disabled:c,alt:f}){var r,I;const{t:h}=D.useLocale(),{toast:x}=ee.useToast(),[T,g]=o.useState(!1),[b,A]=o.useState(!1),j=o.useRef(null),[L,M]=o.useState(),[R,_]=o.useState(""),C=o.useRef(null),[S,N]=o.useState({src:"",file:null}),v=U.useExtension(X.name),p=o.useMemo(()=>(v==null?void 0:v.options)??{},[v]);function u(i){if(j.current&&i.width&&i.height){const s=k(j.current,i);_(s)}}function k(i,s){const m=document.createElement("canvas"),l=i.naturalWidth/i.width,y=i.naturalHeight/i.height;m.width=s.width*l,m.height=s.height*y;const w=m.getContext("2d");return w&&(w.imageSmoothingEnabled=!1,w.drawImage(i,s.x*l,s.y*y,s.width*l,s.height*y,0,0,s.width*l,s.height*y)),m.toDataURL("image/png",1)}const q=o.useCallback(async()=>{var i;if(!b){A(!0);try{const s=Z.dataURLtoFile(R,((i=S==null?void 0:S.file)==null?void 0:i.name)||"image.png");let m="";p.upload?m=await p.upload(s):m=URL.createObjectURL(s),e.chain().focus().setImageInline({src:m,inline:t,alt:f}).run(),g(!1),N({src:"",file:null}),E(),a()}catch(s){console.error("Error cropping image",s)}finally{A(!1)}}},[R,e,t,b,a,(r=S==null?void 0:S.file)==null?void 0:r.name,p]);function F(i){var s;i.preventDefault(),(s=C.current)==null||s.click()}const d=async i=>{var w;const s=(w=i==null?void 0:i.target)==null?void 0:w.files;if(!e||e.isDestroyed||s.length===0){i.target.value="";return}const m=te(s,{acceptMimes:p==null?void 0:p.acceptMimes,maxSize:p==null?void 0:p.maxSize,t:h,toast:x,onError:p.onError});if(m.length<=0){i.target.value="";return}const l=m[0],y=await Z.readImageAsBase64(l);g(!0),N({src:y.src,file:l})},E=()=>{C.current&&(C.current.value="")};return n.jsxs(n.Fragment,{children:[n.jsx(B.Button,{className:"richtext-mt-1 richtext-w-full",disabled:c,onClick:F,size:"sm",children:h("editor.image.dialog.tab.uploadCrop")}),n.jsxs(z.Dialog,{open:T,onOpenChange:i=>{g(i),i||(N({src:"",file:null}),E())},children:[n.jsx(z.DialogTrigger,{}),n.jsxs(z.DialogContent,{children:[n.jsx(z.DialogTitle,{children:h("editor.image.dialog.tab.uploadCrop")}),n.jsx("div",{children:S.src&&n.jsx(ae,{className:"richtext-w-full",crop:L,onChange:i=>M(i),onComplete:i=>u(i),children:n.jsx("img",{alt:"Crop me",ref:j,src:S.src})})}),n.jsxs(z.DialogFooter,{children:[n.jsxs(B.Button,{disabled:b,onClick:()=>{g(!1),N({src:"",file:null}),E()},children:[h("editor.imageUpload.cancel"),n.jsx(P.IconComponent,{className:"richtext-ml-1",name:"Trash2"})]}),n.jsx(B.Button,{className:"richtext-w-fit",disabled:b||!L,onClick:q,children:b?n.jsxs(n.Fragment,{children:[h("editor.imageUpload.uploading"),n.jsx(P.IconComponent,{className:"richtext-ml-1 richtext-animate-spin",name:"Loader"})]}):n.jsxs(n.Fragment,{children:[h("editor.imageUpload.crop"),n.jsx(P.IconComponent,{className:"richtext-ml-1",name:"Crop"})]})})]})]})]}),n.jsx("input",{accept:((I=p==null?void 0:p.acceptMimes)==null?void 0:I.join(","))||"image/*",multiple:!1,onChange:d,ref:C,style:{display:"none"},type:"file"})]})}function ue(){const{t:e}=D.useLocale(),{toast:t}=ee.useToast(),a=U.useEditorInstance(),c=U.useButtonProps(X.name),{icon:f,tooltip:h}=(c==null?void 0:c.componentProps)??{},{editorDisabled:x}=U.useToggleActive(),[T,g]=o.useState(!1),[b,A]=o.useState(!1),j=U.useExtension(X.name),L=d=>{g(d.detail)},[M,R]=o.useState(""),[_,C]=o.useState(""),S=o.useRef(null),N=(j==null?void 0:j.options.defaultInline)||!1,[v,p]=o.useState(N),u=o.useMemo(()=>j==null?void 0:j.options,[j]);o.useEffect(()=>{const d=J.listenEvent(J.EVENTS.UPLOAD_IMAGE(a.id),L);return()=>{d()}},[]);async function k(d){var I;const E=(I=d==null?void 0:d.target)==null?void 0:I.files;if(!a||a.isDestroyed||E.length===0||b){d.target.value="";return}const r=te(E,{acceptMimes:u==null?void 0:u.acceptMimes,maxSize:u==null?void 0:u.maxSize,t:e,toast:t,onError:u.onError});if(r.length<=0){d.target.value="";return}A(!0);try{if(u!=null&&u.multiple){const i=r.map(async m=>{let l="";return u.upload?l=await u.upload(m):l=URL.createObjectURL(m),l});(await Promise.all(i)).forEach(m=>{a.chain().focus().setImageInline({src:m,inline:v,alt:_}).run()})}else{const i=r[0];let s="";u.upload?s=await u.upload(i):s=URL.createObjectURL(i),a.chain().focus().setImageInline({src:s,inline:v,alt:_}).run()}g(!1),C(""),p(N)}catch(i){console.error("Error uploading image",i),u.onError?u.onError({type:"upload",message:e("editor.upload.error")}):t({variant:"destructive",title:e("editor.upload.error")})}finally{A(!1),d.target.value=""}}function q(d){d.preventDefault(),d.stopPropagation(),a.chain().focus().setImageInline({src:M,inline:v,alt:_}).run(),g(!1),p(N),R(""),C("")}function F(d){var E;d.preventDefault(),(E=S.current)==null||E.click()}return c?n.jsxs(z.Dialog,{onOpenChange:g,open:T,children:[n.jsx(z.DialogTrigger,{asChild:!0,children:n.jsx(ie.ActionButton,{disabled:x,icon:f,tooltip:h,action:()=>{x||g(!0)}})}),n.jsxs(z.DialogContent,{children:[n.jsx(z.DialogTitle,{children:e("editor.image.dialog.title")}),n.jsxs(O.Tabs,{activationMode:"manual",defaultValue:u.resourceImage==="both"||u.resourceImage==="upload"?"upload":"link",children:[u.resourceImage==="both"&&n.jsxs(O.TabsList,{className:"richtext-grid richtext-w-full richtext-grid-cols-2",children:[n.jsx(O.TabsTrigger,{value:"upload",children:e("editor.image.dialog.tab.upload")}),n.jsx(O.TabsTrigger,{value:"link",children:e("editor.image.dialog.tab.url")})]}),n.jsxs("div",{className:"richtext-my-[10px] richtext-flex richtext-items-center richtext-gap-[4px]",children:[n.jsx(se.Checkbox,{checked:v,onCheckedChange:d=>{p(d)}}),n.jsx(K.Label,{children:e("editor.link.dialog.inline")})]}),u.enableAlt&&n.jsxs("div",{className:"richtext-my-[10px] ",children:[n.jsx(K.Label,{className:"mb-[6px]",children:e("editor.imageUpload.alt")}),n.jsx(Q.Input,{onChange:d=>C(d.target.value),required:!0,type:"text",value:_})]}),n.jsxs(O.TabsContent,{value:"upload",children:[n.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-[10px]",children:[n.jsx(B.Button,{className:"richtext-mt-1 richtext-w-full",disabled:b,onClick:F,size:"sm",children:b?n.jsxs(n.Fragment,{children:[e("editor.imageUpload.uploading"),n.jsx(P.IconComponent,{className:"richtext-ml-1 richtext-animate-spin",name:"Loader"})]}):e("editor.image.dialog.tab.upload")}),n.jsx(ce,{alt:_,disabled:b,editor:a,imageInline:v,onClose:()=>{re.actionDialogImage.setOpen(a.id,!1),C("")}})]}),n.jsx("input",{accept:u.acceptMimes.join(",")||"image/*",multiple:u.multiple,onChange:k,ref:S,style:{display:"none"},type:"file"})]}),n.jsx(O.TabsContent,{value:"link",children:n.jsx("form",{onSubmit:q,children:n.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2",children:[n.jsx(Q.Input,{autoFocus:!0,onChange:d=>R(d.target.value),placeholder:e("editor.image.dialog.placeholder"),required:!0,type:"url",value:M}),n.jsx(B.Button,{type:"submit",children:e("editor.image.dialog.button.apply")})]})})})]})]})]}):n.jsx(n.Fragment,{})}const de={acceptMimes:["image/jpeg","image/gif","image/png","image/jpg"],maxSize:1024*1024*5,multiple:!0,resourceImage:"both",defaultInline:!1,enableAlt:!0},X=W.index_default.extend({group:"inline",inline:!0,defining:!0,draggable:!0,selectable:!0,addOptions(){var e;return{...de,...(e=this.parent)==null?void 0:e.call(this),upload:()=>Promise.reject("Image Upload Function"),button:({editor:t,extension:a,t:c})=>{var f,h;return{componentProps:{action:()=>!0,upload:a.options.upload,disabled:!((h=(f=t.can()).setImage)!=null&&h.call(f,{})),icon:"ImageUp",tooltip:c("editor.image.tooltip")}}}}},addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),flipX:{default:!1},flipY:{default:!1},width:{default:null,parseHTML:t=>{const a=t.style.width||t.getAttribute("width")||null;return a?Number.parseInt(a,10):null},renderHTML:t=>({width:t.width})},align:{default:"center",parseHTML:t=>t.getAttribute("align"),renderHTML:t=>({align:t.align})},inline:{default:!1,parseHTML:t=>!!t.getAttribute("inline"),renderHTML:t=>({inline:t.inline})},alt:{default:"",parseHTML:t=>t.getAttribute("alt"),renderHTML:t=>({alt:t.alt})}}},addNodeView(){return G.ReactNodeViewRenderer(le)},addCommands(){var e;return{...(e=this.parent)==null?void 0:e.call(this),setImageInline:t=>({commands:a})=>a.insertContent({type:this.name,attrs:{...t,inline:t.inline??this.options.defaultInline}}),updateImage:t=>({commands:a})=>a.updateAttributes(this.name,t),setAlignImage:t=>({commands:a})=>a.updateAttributes(this.name,{align:t})}},renderHTML({HTMLAttributes:e}){const{flipX:t,flipY:a,align:c,inline:f}=e,h=f&&(c==="left"||c==="right"),x=t||a?`transform: rotateX(${t?"180":"0"}deg) rotateY(${a?"180":"0"}deg);`:"",T=h?"":`text-align: ${c};`,A=`${h?`float: ${c};`:""}${h?c==="left"?"margin: 1em 1em 1em 0;":"margin: 1em 0 1em 1em;":""}${x}`;return[f?"span":"div",{style:T,class:"image"},["img",G.mergeAttributes({height:"auto",style:A},this.options.HTMLAttributes,e)]]},parseHTML(){return[{tag:"span.image img",getAttrs:e=>{var h;const t=e==null?void 0:e.parentElement,a=e==null?void 0:e.getAttribute("width"),c=(e==null?void 0:e.getAttribute("flipx"))||!1,f=(e==null?void 0:e.getAttribute("flipy"))||!1;return{src:e==null?void 0:e.getAttribute("src"),alt:e==null?void 0:e.getAttribute("alt"),caption:e==null?void 0:e.getAttribute("caption"),width:a?Number.parseInt(a,10):null,align:(e==null?void 0:e.getAttribute("align"))||((h=t==null?void 0:t.style)==null?void 0:h.textAlign)||null,inline:(e==null?void 0:e.getAttribute("inline"))||!1,flipX:c==="true",flipY:f==="true"}}},{tag:"div[class=image]",getAttrs:e=>{const t=e.querySelector("img"),a=t==null?void 0:t.getAttribute("width"),c=(t==null?void 0:t.getAttribute("flipx"))||!1,f=(t==null?void 0:t.getAttribute("flipy"))||!1;return{src:t==null?void 0:t.getAttribute("src"),alt:t==null?void 0:t.getAttribute("alt"),caption:t==null?void 0:t.getAttribute("caption"),width:a?Number.parseInt(a,10):null,align:(t==null?void 0:t.getAttribute("align"))||e.style.textAlign||null,inline:(t==null?void 0:t.getAttribute("inline"))||!1,flipX:c==="true",flipY:f==="true"}}},{tag:'img[src]:not([src^="data:"])'}]}});exports.Image=X;exports.RichTextImage=ue;
|