wysimark-lite 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,10 +1,35 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
1
2
|
import * as slate from 'slate';
|
|
2
|
-
import { Element as Element$1, BaseEditor, NodeEntry, BaseRange, Location,
|
|
3
|
+
import { Descendant, Editor, Element as Element$1, BaseEditor, NodeEntry, BaseRange, Location, Path, BaseText } from 'slate';
|
|
3
4
|
import { HistoryEditor } from 'slate-history';
|
|
4
|
-
import { ReactEditor, Editable } from 'slate-react';
|
|
5
|
+
import { ReactEditor, Editable as Editable$1 } from 'slate-react';
|
|
5
6
|
import { SetReturnType, SetOptional, UnionToIntersection, Simplify } from 'type-fest';
|
|
6
7
|
import react from 'react';
|
|
7
|
-
import { RenderElementProps, RenderLeafProps, RenderPlaceholderProps, EditableProps } from 'slate-react/dist/components/editable';
|
|
8
|
+
import { RenderElementProps, RenderLeafProps, RenderPlaceholderProps, EditableProps as EditableProps$1 } from 'slate-react/dist/components/editable';
|
|
9
|
+
|
|
10
|
+
type WysimarkEditor = {
|
|
11
|
+
/**
|
|
12
|
+
* Private state for the wysimark editor.
|
|
13
|
+
*/
|
|
14
|
+
wysimark: {
|
|
15
|
+
prevValue?: {
|
|
16
|
+
markdown: string;
|
|
17
|
+
children: Descendant[];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Public methods for the wysimark editor.
|
|
22
|
+
*/
|
|
23
|
+
getMarkdown: () => string;
|
|
24
|
+
setMarkdown: (markdown: string) => void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare function useEditor({ authToken, height, minHeight, maxHeight, }: {
|
|
28
|
+
authToken?: string;
|
|
29
|
+
height?: string | number;
|
|
30
|
+
minHeight?: string | number;
|
|
31
|
+
maxHeight?: string | number;
|
|
32
|
+
}): Editor & ReactEditor & WysimarkEditor;
|
|
8
33
|
|
|
9
34
|
/**
|
|
10
35
|
* SinkEditor just adds a `sink` object where we drop all of our sink
|
|
@@ -115,8 +140,8 @@ type FullSinkEditor = SinkEditor & BaseEditor & ReactEditor & HistoryEditor;
|
|
|
115
140
|
type VoidActionReturn = boolean | (() => void);
|
|
116
141
|
|
|
117
142
|
type RenderEditableProps = {
|
|
118
|
-
attributes: EditableProps;
|
|
119
|
-
Editable: typeof Editable;
|
|
143
|
+
attributes: EditableProps$1;
|
|
144
|
+
Editable: typeof Editable$1;
|
|
120
145
|
};
|
|
121
146
|
type RenderEditable = (props: RenderEditableProps) => react.ReactElement;
|
|
122
147
|
/**
|
|
@@ -152,7 +177,7 @@ type BasePluginPolicy = {
|
|
|
152
177
|
onDrop?: EditableVoidToBooleanHandlerType<"onDrop">;
|
|
153
178
|
};
|
|
154
179
|
};
|
|
155
|
-
type EditableVoidToBooleanHandlerType<K extends keyof EditableProps> = SetReturnType<NonNullable<EditableProps[K]>, boolean>;
|
|
180
|
+
type EditableVoidToBooleanHandlerType<K extends keyof EditableProps$1> = SetReturnType<NonNullable<EditableProps$1[K]>, boolean>;
|
|
156
181
|
|
|
157
182
|
/**
|
|
158
183
|
* IMPORTANT!
|
|
@@ -849,23 +874,6 @@ type PasteMarkdownPluginCustomTypes = {
|
|
|
849
874
|
Editor: PasteMarkdownEditor;
|
|
850
875
|
};
|
|
851
876
|
|
|
852
|
-
type WysimarkEditor = {
|
|
853
|
-
/**
|
|
854
|
-
* Private state for the wysimark editor.
|
|
855
|
-
*/
|
|
856
|
-
wysimark: {
|
|
857
|
-
prevValue?: {
|
|
858
|
-
markdown: string;
|
|
859
|
-
children: Descendant[];
|
|
860
|
-
};
|
|
861
|
-
};
|
|
862
|
-
/**
|
|
863
|
-
* Public methods for the wysimark editor.
|
|
864
|
-
*/
|
|
865
|
-
getMarkdown: () => string;
|
|
866
|
-
setMarkdown: (markdown: string) => void;
|
|
867
|
-
};
|
|
868
|
-
|
|
869
877
|
declare const plugins: (TypedPlugin<PasteMarkdownPluginCustomTypes> | TypedPlugin<ConvertElementPluginCustomTypes> | TypedPlugin<AnchorPluginCustomTypes> | TypedPlugin<HeadingPluginCustomTypes> | TypedPlugin<MarksPluginCustomTypes> | TypedPlugin<InlineCodePluginCustomTypes> | TypedPlugin<BlockQuotePluginCustomTypes> | TypedPlugin<TablePluginCustomTypes> | TypedPlugin<HorizontalRulePluginCustomTypes> | TypedPlugin<{
|
|
870
878
|
Name: "trailing-block";
|
|
871
879
|
Editor: {
|
|
@@ -884,12 +892,16 @@ declare module "slate" {
|
|
|
884
892
|
}
|
|
885
893
|
}
|
|
886
894
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
895
|
+
type EditableProps = {
|
|
896
|
+
editor: Editor;
|
|
897
|
+
value: string;
|
|
898
|
+
onChange: (markdown: string) => void;
|
|
899
|
+
throttleInMs?: number;
|
|
900
|
+
placeholder?: string;
|
|
901
|
+
className?: string;
|
|
902
|
+
style?: React.CSSProperties;
|
|
903
|
+
};
|
|
904
|
+
declare function Editable({ editor, value, onChange, throttleInMs, placeholder, className, style, }: EditableProps): react_jsx_runtime.JSX.Element;
|
|
893
905
|
|
|
894
906
|
/**
|
|
895
907
|
* The options passed into the standalone version of Wysimark.
|
|
@@ -913,4 +925,4 @@ type Wysimark = {
|
|
|
913
925
|
*/
|
|
914
926
|
declare function createWysimark(containerElement: HTMLElement, options: StandaloneOptions): Wysimark;
|
|
915
927
|
|
|
916
|
-
export { Wysimark, createWysimark };
|
|
928
|
+
export { Editable, Wysimark, createWysimark, useEditor };
|
|
@@ -1365,7 +1365,7 @@ Error generating stack: `+n.message+`
|
|
|
1365
1365
|
`;var D4=_(_n)`
|
|
1366
1366
|
padding: 1em;
|
|
1367
1367
|
width: 18em;
|
|
1368
|
-
`;var tn=O(N());function iI({dest:e,close:t,icon:n,buttonCaption:r,buttonHint:i}){let a=oe(),o=(0,C4.useRef)(null),u=Hn({src:o,dest:e},({src:s,dest:f},m)=>fp(s,m,{left:f.left-16,top:f.top+f.height},{margin:16}));async function l(s){if(s.target.files==null||s.target.files.length===0)return;Jr(s);let{files:f}=s.target;for(let m of f)a.upload.upload(m);t()}return(0,tn.jsxs)(tn.Fragment,{children:[(0,tn.jsx)(ea,{close:t}),(0,tn.jsxs)(D4,{ref:o,style:u,children:[(0,tn.jsxs)("label",{children:[(0,tn.jsx)("input",{type:"file",multiple:!0,style:{display:"none"},onChange:l}),(0,tn.jsxs)(Bp,{children:[n,(0,tn.jsx)("span",{style:{marginLeft:"0.5em"},children:r})]})]}),(0,tn.jsx)(Mp,{children:i})]})]})}function w4({dest:e,close:t}){return(0,tn.jsx)(iI,{dest:e,close:t,icon:(0,tn.jsx)(p4,{}),buttonCaption:"Select images...",buttonHint:"Select image files to upload and insert into the editor"})}var A4=[{icon:c4,title:Be("insertTable"),more:!0,Component:Z5},{icon:m4,title:Be("insertImage"),more:!0,Component:w4,show:e=>e.toolbar.showUploadButtons??!1}],k4=A4,Bv=[{icon:d4,title:Be("insert"),more:!0,children:A4}];var Op=[];var S4=O(up()),_u=O(le());var xn=O(N()),aI=(0,S4.isHotkey)("enter");function T4({dest:e,close:t}){let n=oe(),r=(0,_u.useRef)(null),i=Hn({src:r,dest:e},({src:f,dest:m},p)=>fp(f,p,{left:m.left-12,top:m.top+m.height},{margin:16})),[a,o]=(0,_u.useState)(""),u=()=>{n.anchor.insertLink(a,a,{select:!0}),L.focus(n),t()},l=(0,_u.useCallback)(f=>{o(f.currentTarget.value)},[o]);return(0,xn.jsxs)(xn.Fragment,{children:[(0,xn.jsx)(ea,{close:t}),(0,xn.jsxs)(DT,{ref:r,style:i,children:[(0,xn.jsxs)(CT,{children:[(0,xn.jsx)(wT,{type:"text",value:a,autoFocus:!0,onChange:l,onKeyDown:f=>{aI(f)&&(f.preventDefault(),f.stopPropagation(),u())}}),(0,xn.jsxs)(Bp,{onClick:u,children:[(0,xn.jsx)(Tp,{}),(0,xn.jsx)(t4,{})]})]}),(0,xn.jsx)(Mp,{children:"Enter URL of link"})]})]})}var Fp={icon:Tp,title:Be("insertLink"),more:!0,hotkey:"mod+k",Component:T4};function Js(e){let t=d.marks(e);return{bold:t?.bold||!1,italic:t?.italic||!1,strike:t?.strike||!1,code:t?.code||!1,underline:t?.underline||!1}}var B4=[{icon:o4,title:Be("bold"),hotkey:"mod+b",action:e=>e.marksPlugin.toggleBold(),active:e=>Js(e).bold},{icon:u4,title:Be("italic"),hotkey:"mod+i",action:e=>e.marksPlugin.toggleItalic(),active:e=>Js(e).italic},{icon:h4,title:Be("strike"),hotkey:"super+k",action:e=>e.marksPlugin.toggleStrike(),active:e=>Js(e).strike},{icon:f4,title:Be("inlineCode"),hotkey:"mod+j",action:e=>e.inlineCode.toggleInlineCode(),active:e=>Js(e).code},{icon:g4,title:Be("underline"),hotkey:"mod+u",action:e=>e.marksPlugin.toggleUnderline(),active:e=>Js(e).underline}],Mv=B4,M4=B4;var O4=[{icon:s4,title:Be("bulletList"),hotkey:"super+8",action:e=>e.list.convertUnorderedList(!0)},{icon:kv,title:Be("numberedList"),hotkey:"super+7",action:e=>e.list.convertOrderedList(!0)},{icon:v4,title:Be("checkList"),hotkey:"super+9",action:e=>e.list.convertTaskList(!0)}],Ov=O4,F4=[{icon:kv,title:Be("list"),more:!0,children:O4}];var Rp=[{icon:l4,title:Be("quote"),hotkey:"super+.",action:e=>{e.blockQuotePlugin.isActive()?e.blockQuotePlugin.outdent():e.blockQuotePlugin.indent()},active:e=>e.blockQuotePlugin.isActive()}];var oI=[...Sv,"divider",...Ov,"divider",...Mv,"divider",Fp,...Rp,...Op,"divider",...k4],uI=[...Tv,"divider",...Ov,"divider",...Mv,"divider",Fp,...Rp,...Op,"divider",...Bv],lI=[...Tv,"divider",...F4,"divider",...M4,"divider",Fp,...Rp,...Op,"divider",...Bv],R4=[...Sv,"divider"];var Uu=[oI,uI,lI];var ju=O(le());var Ja=O(N());function z4({item:e}){let t=oe(),n=o0(),r=e.active?e.active(n):!1,i=(0,ju.useRef)(null),a=Jn({title:e.title,hotkey:()=>e.hotkey?sp(e.hotkey):void 0}),o=Vt("menu"),u=(0,ju.useCallback)(()=>{let f=i.current,m=e.children,p=e.Component;f&&(m?o.open(()=>(0,Ja.jsx)(mp,{dest:f,items:m,close:o.close})):p&&o.open(()=>(0,Ja.jsx)(p,{dest:f,close:o.close})))},[e]),l=(0,ju.useCallback)(()=>{if(e.action){e.action(t),L.focus(t);return}o.layer?o.close():u()},[o.layer,e]),s=(0,ju.useCallback)(f=>{a.onMouseEnter(f),o.layer&&u()},[o.layer]);return console.log(dp(e?.title)),(0,Ja.jsxs)(LT,{"data-item-type":"button",ref:i,onMouseEnter:s,onMouseLeave:a.onMouseLeave,onClick:l,className:ct({"--active":r&&!dp(e?.title)?.includes("Depth"),"--more":e.more,"--disabled":!r&&dp(e?.title)?.includes("Depth")}),children:[(0,Ja.jsx)(e.icon,{}),e.more?(0,Ja.jsx)(e4,{}):null]})}var eo=O(N());function sI({item:e}){let t=oe();return e==="divider"?(0,eo.jsx)(RT,{"data-item-type":"divider",children:(0,eo.jsx)(zT,{})}):(e.show===void 0?!0:e.show(t))?(0,eo.jsx)(z4,{item:e}):null}function cI(e){let t=e.querySelector("[data-item-type=button]"),n=e.querySelector("[data-item-type=divider]");if(!t||!n)throw new Error("Button or divider not found");return{toolbar:e.offsetWidth,button:t.offsetWidth,divider:n.offsetWidth}}function fI(e,t,n){let r=0;for(let i of e)r+=i==="divider"?n:t;return r}function P4(){let e=(0,qu.useRef)(null),[t,n]=(0,qu.useState)(R4);return(0,qu.useEffect)(()=>{let r=(0,L4.default)(()=>{let i=e.current;if(!i)throw new Error("Toolbar not found");let a=cI(i);for(let o=0;o<Uu.length-1;o++)if(fI(Uu[o],a.button,a.divider)<a.toolbar){n(Uu[o]);return}n(Uu[Uu.length-1])},100,{trailing:!0});return r(),window.addEventListener("resize",r),()=>{window.removeEventListener("resize",r)}},[]),(0,eo.jsx)(OT,{ref:e,children:(0,eo.jsx)(FT,{children:t.map((r,i)=>(0,eo.jsx)(sI,{item:r},typeof r=="string"?i:r.title))})})}var Vu=O(N());function N4({attributes:e,Editable:t}){let n=(0,zp.useRef)(null),r=oe(),i=b2(),a=(0,zp.useCallback)(o=>{o.target===o.currentTarget&&(k.select(r,d.end(r,[])),L.focus(r))},[r]);return(0,Vu.jsx)(sT,{children:(0,Vu.jsxs)(ST,{ref:n,className:ct({"--focused":i}),style:{height:r.toolbar.height,minHeight:r.toolbar.minHeight,maxHeight:r.toolbar.maxHeight},onClick:a,children:[(0,Vu.jsx)(P4,{}),(0,Vu.jsx)(t,{as:kT,...e,style:{overflowY:"auto"}})]})})}var I4=xe((e,t)=>(e.toolbar={height:t.toolbar?.height,minHeight:t.toolbar?.minHeight,maxHeight:t.toolbar?.maxHeight,showUploadButtons:t.toolbar?.showUploadButtons??!0},{name:"toolbar",editor:{},renderEditable:N4,editableProps:{}}));var H4=xe(e=>(e.allowTrailingBlock=!0,{name:"trailing-block",editor:{normalizeNode:t=>{if(!d.isEditor(t[0]))return!1;let n=[e.children.length-1],r=Y.child(e,e.children.length-1);return(d.hasBlocks(e,r)||d.isVoid(e,r))&&k.insertNodes(e,{type:"paragraph",children:[{text:""}]},{at:A.next(n)}),!0}}}));function mI(e,t){let n=Qi(t);k.insertNodes(e,n)}function _4(e){return{pasteMarkdown:ee(mI,e)}}var U4=xe(e=>(e.pasteMarkdown=_4(e),{name:"paste-markdown",editor:{},editableProps:{onPaste(t){let{types:n}=t.clipboardData;if(n.length!==1||n[0]!=="text/plain")return!1;let r=t.clipboardData.getData("text/plain");return e.pasteMarkdown.pasteMarkdown(r),Jr(t),!0}}}));var q4=O(N());function pI(e){let t={...e.attributes,style:{...e.attributes.style,width:void 0,maxWidth:void 0}};return(0,q4.jsx)("span",{...t,children:e.children})}var j4=xe((e,t,{createPolicy:n})=>(e.placeholder={},n({name:"placeholder",editableProps:{renderPlaceholder:pI}})));var V4=[U4,t3,eB,c3,K3,v3,HB,$5,d3,H4,V3,nB,W3,QB,Y5,I4,PB,j4];var dI=IS(V4),{withSink:$4,SinkEditable:G4}=dI;var X4=O(le());function Y4(e){return Object.prototype.toString.call(e)==="[object Object]"}function K4(e){var t,n;return Y4(e)===!1?!1:(t=e.constructor,t===void 0?!0:(n=t.prototype,!(Y4(n)===!1||n.hasOwnProperty("isPrototypeOf")===!1)))}var hI={isHistory(e){return K4(e)&&Array.isArray(e.redos)&&Array.isArray(e.undos)&&(e.redos.length===0||Gr.isOperationList(e.redos[0]))&&(e.undos.length===0||Gr.isOperationList(e.undos[0]))}};var Fv=new WeakMap,Rv=new WeakMap,$u={isHistoryEditor(e){return hI.isHistory(e.history)&&d.isEditor(e)},isMerging(e){return Rv.get(e)},isSaving(e){return Fv.get(e)},redo(e){e.redo()},undo(e){e.undo()},withoutMerging(e,t){var n=$u.isMerging(e);Rv.set(e,!1),t(),Rv.set(e,n)},withoutSaving(e,t){var n=$u.isSaving(e);Fv.set(e,!1),t(),Fv.set(e,n)}},Q4=e=>{var t=e,{apply:n}=t;return t.history={undos:[],redos:[]},t.redo=()=>{var{history:r}=t,{redos:i}=r;if(i.length>0){var a=i[i.length-1];a.selectionBefore&&k.setSelection(t,a.selectionBefore),$u.withoutSaving(t,()=>{d.withoutNormalizing(t,()=>{for(var o of a.operations)t.apply(o)})}),r.redos.pop(),r.undos.push(a)}},t.undo=()=>{var{history:r}=t,{undos:i}=r;if(i.length>0){var a=i[i.length-1];$u.withoutSaving(t,()=>{d.withoutNormalizing(t,()=>{var o=a.operations.map(Gr.inverse).reverse();for(var u of o)t.apply(u);a.selectionBefore&&k.setSelection(t,a.selectionBefore)})}),r.redos.push(a),r.undos.pop()}},t.apply=r=>{var{operations:i,history:a}=t,{undos:o}=a,u=o[o.length-1],l=u&&u.operations[u.operations.length-1],s=$u.isSaving(t),f=$u.isMerging(t);if(s==null&&(s=vI(r)),s){if(f==null&&(u==null?f=!1:i.length!==0?f=!0:f=gI(r,l)),u&&f)u.operations.push(r);else{var m={operations:[r],selectionBefore:t.selection};o.push(m)}for(;o.length>100;)o.shift();a.redos=[]}n(r)},t},gI=(e,t)=>!!(t&&e.type==="insert_text"&&t.type==="insert_text"&&e.offset===t.offset+t.text.length&&A.equals(e.path,t.path)||t&&e.type==="remove_text"&&t.type==="remove_text"&&e.offset+e.text.length===t.offset&&A.equals(e.path,t.path)),vI=(e,t)=>e.type!=="set_selection";function zv({authToken:e,height:t,minHeight:n,maxHeight:r}){let[i]=(0,X4.useState)(()=>{let a=GD(),o=$4(x2(Q4(a)),{toolbar:{height:t,minHeight:n,maxHeight:r,showUploadButtons:!!e},image:{}});return o.convertElement.addConvertElementType("paragraph"),a.wysimark={},a.getMarkdown=()=>Ss(a.children),a.setMarkdown=u=>{let l=Qi(u);a.children=l,a.selection=null,k.select(a,d.start(a,[0]))},o});return i}var Lp=O(N());function yI({children:e,attributes:t}){return(0,Lp.jsx)("span",{...t,children:e})}function Z4({editor:e,value:t,onChange:n,throttleInMs:r=1e3,placeholder:i,className:a,style:o}){let u=(0,ri.useRef)(!1),l=(0,ri.useRef)(void 0),s=(0,ri.useRef)(void 0),f=(0,ri.useCallback)((0,W4.default)(()=>{let g=Ss(e.children);e.wysimark.prevValue={markdown:g,children:e.children},n(g)},r,{leading:!1,trailing:!0}),[e,n,r]),m=(0,ri.useCallback)(()=>{s.current!==e.children&&(s.current=e.children,f())},[f]);if(e.wysimark.prevValue==null||l.current==null){u.current=!0;let g=Qi(t);s.current=l.current=g,e.wysimark.prevValue={markdown:t,children:g}}else if(t!==e.wysimark.prevValue.markdown){u.current=!0;let g=Qi(t);e.children=g,e.selection=null,k.select(e,d.start(e,[0]))}let p=(0,ri.useCallback)(()=>{navigator.userAgent.toLowerCase().includes("firefox")&&L.focus(e)},[e]),c=(0,ri.useCallback)(()=>{f.flush()},[f]);return(0,Lp.jsx)(E2,{editor:e,value:l.current,onChange:m,children:(0,Lp.jsx)(G4,{renderLeaf:yI,onMouseDown:p,onBlur:c,placeholder:i,className:a,style:o})})}var Lv=O(N());function bI({standaloneOptions:{onChange:e,placeholder:t,className:n,...r},standaloneMethodsRef:i}){let[a,o]=(0,Cr.useState)(r.initialMarkdown||""),u=(0,Cr.useRef)(a),l=zv(r);u.current=a,(0,Cr.useImperativeHandle)(i,()=>({getMarkdown(){return u.current},setMarkdown(f){u.current=f,o(f)}}),[u,o]);let s=(0,Cr.useCallback)(f=>{u.current=f,o(f),e?.(f)},[l]);return(0,Lv.jsx)(Z4,{editor:l,value:a,className:n||"",onChange:s,placeholder:t})}function yge(e,t){let n=(0,Cr.createRef)(),r=(0,J4.createRoot)(e);return r.render((0,Lv.jsx)(bI,{standaloneMethodsRef:n,standaloneOptions:t})),{unmount(){try{r.unmount()}catch{}},getMarkdown(){return n.current?.getMarkdown()||""},setMarkdown(i){n.current?.setMarkdown(i)}}}export{yge as createWysimark};
|
|
1368
|
+
`;var tn=O(N());function iI({dest:e,close:t,icon:n,buttonCaption:r,buttonHint:i}){let a=oe(),o=(0,C4.useRef)(null),u=Hn({src:o,dest:e},({src:s,dest:f},m)=>fp(s,m,{left:f.left-16,top:f.top+f.height},{margin:16}));async function l(s){if(s.target.files==null||s.target.files.length===0)return;Jr(s);let{files:f}=s.target;for(let m of f)a.upload.upload(m);t()}return(0,tn.jsxs)(tn.Fragment,{children:[(0,tn.jsx)(ea,{close:t}),(0,tn.jsxs)(D4,{ref:o,style:u,children:[(0,tn.jsxs)("label",{children:[(0,tn.jsx)("input",{type:"file",multiple:!0,style:{display:"none"},onChange:l}),(0,tn.jsxs)(Bp,{children:[n,(0,tn.jsx)("span",{style:{marginLeft:"0.5em"},children:r})]})]}),(0,tn.jsx)(Mp,{children:i})]})]})}function w4({dest:e,close:t}){return(0,tn.jsx)(iI,{dest:e,close:t,icon:(0,tn.jsx)(p4,{}),buttonCaption:"Select images...",buttonHint:"Select image files to upload and insert into the editor"})}var A4=[{icon:c4,title:Be("insertTable"),more:!0,Component:Z5},{icon:m4,title:Be("insertImage"),more:!0,Component:w4,show:e=>e.toolbar.showUploadButtons??!1}],k4=A4,Bv=[{icon:d4,title:Be("insert"),more:!0,children:A4}];var Op=[];var S4=O(up()),_u=O(le());var xn=O(N()),aI=(0,S4.isHotkey)("enter");function T4({dest:e,close:t}){let n=oe(),r=(0,_u.useRef)(null),i=Hn({src:r,dest:e},({src:f,dest:m},p)=>fp(f,p,{left:m.left-12,top:m.top+m.height},{margin:16})),[a,o]=(0,_u.useState)(""),u=()=>{n.anchor.insertLink(a,a,{select:!0}),L.focus(n),t()},l=(0,_u.useCallback)(f=>{o(f.currentTarget.value)},[o]);return(0,xn.jsxs)(xn.Fragment,{children:[(0,xn.jsx)(ea,{close:t}),(0,xn.jsxs)(DT,{ref:r,style:i,children:[(0,xn.jsxs)(CT,{children:[(0,xn.jsx)(wT,{type:"text",value:a,autoFocus:!0,onChange:l,onKeyDown:f=>{aI(f)&&(f.preventDefault(),f.stopPropagation(),u())}}),(0,xn.jsxs)(Bp,{onClick:u,children:[(0,xn.jsx)(Tp,{}),(0,xn.jsx)(t4,{})]})]}),(0,xn.jsx)(Mp,{children:"Enter URL of link"})]})]})}var Fp={icon:Tp,title:Be("insertLink"),more:!0,hotkey:"mod+k",Component:T4};function Js(e){let t=d.marks(e);return{bold:t?.bold||!1,italic:t?.italic||!1,strike:t?.strike||!1,code:t?.code||!1,underline:t?.underline||!1}}var B4=[{icon:o4,title:Be("bold"),hotkey:"mod+b",action:e=>e.marksPlugin.toggleBold(),active:e=>Js(e).bold},{icon:u4,title:Be("italic"),hotkey:"mod+i",action:e=>e.marksPlugin.toggleItalic(),active:e=>Js(e).italic},{icon:h4,title:Be("strike"),hotkey:"super+k",action:e=>e.marksPlugin.toggleStrike(),active:e=>Js(e).strike},{icon:f4,title:Be("inlineCode"),hotkey:"mod+j",action:e=>e.inlineCode.toggleInlineCode(),active:e=>Js(e).code},{icon:g4,title:Be("underline"),hotkey:"mod+u",action:e=>e.marksPlugin.toggleUnderline(),active:e=>Js(e).underline}],Mv=B4,M4=B4;var O4=[{icon:s4,title:Be("bulletList"),hotkey:"super+8",action:e=>e.list.convertUnorderedList(!0)},{icon:kv,title:Be("numberedList"),hotkey:"super+7",action:e=>e.list.convertOrderedList(!0)},{icon:v4,title:Be("checkList"),hotkey:"super+9",action:e=>e.list.convertTaskList(!0)}],Ov=O4,F4=[{icon:kv,title:Be("list"),more:!0,children:O4}];var Rp=[{icon:l4,title:Be("quote"),hotkey:"super+.",action:e=>{e.blockQuotePlugin.isActive()?e.blockQuotePlugin.outdent():e.blockQuotePlugin.indent()},active:e=>e.blockQuotePlugin.isActive()}];var oI=[...Sv,"divider",...Ov,"divider",...Mv,"divider",Fp,...Rp,...Op,"divider",...k4],uI=[...Tv,"divider",...Ov,"divider",...Mv,"divider",Fp,...Rp,...Op,"divider",...Bv],lI=[...Tv,"divider",...F4,"divider",...M4,"divider",Fp,...Rp,...Op,"divider",...Bv],R4=[...Sv,"divider"];var Uu=[oI,uI,lI];var ju=O(le());var Ja=O(N());function z4({item:e}){let t=oe(),n=o0(),r=e.active?e.active(n):!1,i=(0,ju.useRef)(null),a=Jn({title:e.title,hotkey:()=>e.hotkey?sp(e.hotkey):void 0}),o=Vt("menu"),u=(0,ju.useCallback)(()=>{let f=i.current,m=e.children,p=e.Component;f&&(m?o.open(()=>(0,Ja.jsx)(mp,{dest:f,items:m,close:o.close})):p&&o.open(()=>(0,Ja.jsx)(p,{dest:f,close:o.close})))},[e]),l=(0,ju.useCallback)(()=>{if(e.action){e.action(t),L.focus(t);return}o.layer?o.close():u()},[o.layer,e]),s=(0,ju.useCallback)(f=>{a.onMouseEnter(f),o.layer&&u()},[o.layer]);return console.log(dp(e?.title)),(0,Ja.jsxs)(LT,{"data-item-type":"button",ref:i,onMouseEnter:s,onMouseLeave:a.onMouseLeave,onClick:l,className:ct({"--active":r&&!dp(e?.title)?.includes("Depth"),"--more":e.more,"--disabled":!r&&dp(e?.title)?.includes("Depth")}),children:[(0,Ja.jsx)(e.icon,{}),e.more?(0,Ja.jsx)(e4,{}):null]})}var eo=O(N());function sI({item:e}){let t=oe();return e==="divider"?(0,eo.jsx)(RT,{"data-item-type":"divider",children:(0,eo.jsx)(zT,{})}):(e.show===void 0?!0:e.show(t))?(0,eo.jsx)(z4,{item:e}):null}function cI(e){let t=e.querySelector("[data-item-type=button]"),n=e.querySelector("[data-item-type=divider]");if(!t||!n)throw new Error("Button or divider not found");return{toolbar:e.offsetWidth,button:t.offsetWidth,divider:n.offsetWidth}}function fI(e,t,n){let r=0;for(let i of e)r+=i==="divider"?n:t;return r}function P4(){let e=(0,qu.useRef)(null),[t,n]=(0,qu.useState)(R4);return(0,qu.useEffect)(()=>{let r=(0,L4.default)(()=>{let i=e.current;if(!i)throw new Error("Toolbar not found");let a=cI(i);for(let o=0;o<Uu.length-1;o++)if(fI(Uu[o],a.button,a.divider)<a.toolbar){n(Uu[o]);return}n(Uu[Uu.length-1])},100,{trailing:!0});return r(),window.addEventListener("resize",r),()=>{window.removeEventListener("resize",r)}},[]),(0,eo.jsx)(OT,{ref:e,children:(0,eo.jsx)(FT,{children:t.map((r,i)=>(0,eo.jsx)(sI,{item:r},typeof r=="string"?i:r.title))})})}var Vu=O(N());function N4({attributes:e,Editable:t}){let n=(0,zp.useRef)(null),r=oe(),i=b2(),a=(0,zp.useCallback)(o=>{o.target===o.currentTarget&&(k.select(r,d.end(r,[])),L.focus(r))},[r]);return(0,Vu.jsx)(sT,{children:(0,Vu.jsxs)(ST,{ref:n,className:ct({"--focused":i}),style:{height:r.toolbar.height,minHeight:r.toolbar.minHeight,maxHeight:r.toolbar.maxHeight},onClick:a,children:[(0,Vu.jsx)(P4,{}),(0,Vu.jsx)(t,{as:kT,...e,style:{overflowY:"auto"}})]})})}var I4=xe((e,t)=>(e.toolbar={height:t.toolbar?.height,minHeight:t.toolbar?.minHeight,maxHeight:t.toolbar?.maxHeight,showUploadButtons:t.toolbar?.showUploadButtons??!0},{name:"toolbar",editor:{},renderEditable:N4,editableProps:{}}));var H4=xe(e=>(e.allowTrailingBlock=!0,{name:"trailing-block",editor:{normalizeNode:t=>{if(!d.isEditor(t[0]))return!1;let n=[e.children.length-1],r=Y.child(e,e.children.length-1);return(d.hasBlocks(e,r)||d.isVoid(e,r))&&k.insertNodes(e,{type:"paragraph",children:[{text:""}]},{at:A.next(n)}),!0}}}));function mI(e,t){let n=Qi(t);k.insertNodes(e,n)}function _4(e){return{pasteMarkdown:ee(mI,e)}}var U4=xe(e=>(e.pasteMarkdown=_4(e),{name:"paste-markdown",editor:{},editableProps:{onPaste(t){let{types:n}=t.clipboardData;if(n.length!==1||n[0]!=="text/plain")return!1;let r=t.clipboardData.getData("text/plain");return e.pasteMarkdown.pasteMarkdown(r),Jr(t),!0}}}));var q4=O(N());function pI(e){let t={...e.attributes,style:{...e.attributes.style,width:void 0,maxWidth:void 0}};return(0,q4.jsx)("span",{...t,children:e.children})}var j4=xe((e,t,{createPolicy:n})=>(e.placeholder={},n({name:"placeholder",editableProps:{renderPlaceholder:pI}})));var V4=[U4,t3,eB,c3,K3,v3,HB,$5,d3,H4,V3,nB,W3,QB,Y5,I4,PB,j4];var dI=IS(V4),{withSink:$4,SinkEditable:G4}=dI;var X4=O(le());function Y4(e){return Object.prototype.toString.call(e)==="[object Object]"}function K4(e){var t,n;return Y4(e)===!1?!1:(t=e.constructor,t===void 0?!0:(n=t.prototype,!(Y4(n)===!1||n.hasOwnProperty("isPrototypeOf")===!1)))}var hI={isHistory(e){return K4(e)&&Array.isArray(e.redos)&&Array.isArray(e.undos)&&(e.redos.length===0||Gr.isOperationList(e.redos[0]))&&(e.undos.length===0||Gr.isOperationList(e.undos[0]))}};var Fv=new WeakMap,Rv=new WeakMap,$u={isHistoryEditor(e){return hI.isHistory(e.history)&&d.isEditor(e)},isMerging(e){return Rv.get(e)},isSaving(e){return Fv.get(e)},redo(e){e.redo()},undo(e){e.undo()},withoutMerging(e,t){var n=$u.isMerging(e);Rv.set(e,!1),t(),Rv.set(e,n)},withoutSaving(e,t){var n=$u.isSaving(e);Fv.set(e,!1),t(),Fv.set(e,n)}},Q4=e=>{var t=e,{apply:n}=t;return t.history={undos:[],redos:[]},t.redo=()=>{var{history:r}=t,{redos:i}=r;if(i.length>0){var a=i[i.length-1];a.selectionBefore&&k.setSelection(t,a.selectionBefore),$u.withoutSaving(t,()=>{d.withoutNormalizing(t,()=>{for(var o of a.operations)t.apply(o)})}),r.redos.pop(),r.undos.push(a)}},t.undo=()=>{var{history:r}=t,{undos:i}=r;if(i.length>0){var a=i[i.length-1];$u.withoutSaving(t,()=>{d.withoutNormalizing(t,()=>{var o=a.operations.map(Gr.inverse).reverse();for(var u of o)t.apply(u);a.selectionBefore&&k.setSelection(t,a.selectionBefore)})}),r.redos.push(a),r.undos.pop()}},t.apply=r=>{var{operations:i,history:a}=t,{undos:o}=a,u=o[o.length-1],l=u&&u.operations[u.operations.length-1],s=$u.isSaving(t),f=$u.isMerging(t);if(s==null&&(s=vI(r)),s){if(f==null&&(u==null?f=!1:i.length!==0?f=!0:f=gI(r,l)),u&&f)u.operations.push(r);else{var m={operations:[r],selectionBefore:t.selection};o.push(m)}for(;o.length>100;)o.shift();a.redos=[]}n(r)},t},gI=(e,t)=>!!(t&&e.type==="insert_text"&&t.type==="insert_text"&&e.offset===t.offset+t.text.length&&A.equals(e.path,t.path)||t&&e.type==="remove_text"&&t.type==="remove_text"&&e.offset+e.text.length===t.offset&&A.equals(e.path,t.path)),vI=(e,t)=>e.type!=="set_selection";function zv({authToken:e,height:t,minHeight:n,maxHeight:r}){let[i]=(0,X4.useState)(()=>{let a=GD(),o=$4(x2(Q4(a)),{toolbar:{height:t,minHeight:n,maxHeight:r,showUploadButtons:!!e},image:{}});return o.convertElement.addConvertElementType("paragraph"),a.wysimark={},a.getMarkdown=()=>Ss(a.children),a.setMarkdown=u=>{let l=Qi(u);a.children=l,a.selection=null,k.select(a,d.start(a,[0]))},o});return i}var Lp=O(N());function yI({children:e,attributes:t}){return(0,Lp.jsx)("span",{...t,children:e})}function Z4({editor:e,value:t,onChange:n,throttleInMs:r=1e3,placeholder:i,className:a,style:o}){let u=(0,ri.useRef)(!1),l=(0,ri.useRef)(void 0),s=(0,ri.useRef)(void 0),f=(0,ri.useCallback)((0,W4.default)(()=>{let g=Ss(e.children);e.wysimark.prevValue={markdown:g,children:e.children},n(g)},r,{leading:!1,trailing:!0}),[e,n,r]),m=(0,ri.useCallback)(()=>{s.current!==e.children&&(s.current=e.children,f())},[f]);if(e.wysimark.prevValue==null||l.current==null){u.current=!0;let g=Qi(t);s.current=l.current=g,e.wysimark.prevValue={markdown:t,children:g}}else if(t!==e.wysimark.prevValue.markdown){u.current=!0;let g=Qi(t);e.children=g,e.selection=null,k.select(e,d.start(e,[0]))}let p=(0,ri.useCallback)(()=>{navigator.userAgent.toLowerCase().includes("firefox")&&L.focus(e)},[e]),c=(0,ri.useCallback)(()=>{f.flush()},[f]);return(0,Lp.jsx)(E2,{editor:e,value:l.current,onChange:m,children:(0,Lp.jsx)(G4,{renderLeaf:yI,onMouseDown:p,onBlur:c,placeholder:i,className:a,style:o})})}var Lv=O(N());function bI({standaloneOptions:{onChange:e,placeholder:t,className:n,...r},standaloneMethodsRef:i}){let[a,o]=(0,Cr.useState)(r.initialMarkdown||""),u=(0,Cr.useRef)(a),l=zv(r);u.current=a,(0,Cr.useImperativeHandle)(i,()=>({getMarkdown(){return u.current},setMarkdown(f){u.current=f,o(f)}}),[u,o]);let s=(0,Cr.useCallback)(f=>{u.current=f,o(f),e?.(f)},[l]);return(0,Lv.jsx)(Z4,{editor:l,value:a,className:n||"",onChange:s,placeholder:t})}function yge(e,t){let n=(0,Cr.createRef)(),r=(0,J4.createRoot)(e);return r.render((0,Lv.jsx)(bI,{standaloneMethodsRef:n,standaloneOptions:t})),{unmount(){try{r.unmount()}catch{}},getMarkdown(){return n.current?.getMarkdown()||""},setMarkdown(i){n.current?.setMarkdown(i)}}}export{Z4 as Editable,yge as createWysimark,zv as useEditor};
|
|
1369
1369
|
/*! Bundled license information:
|
|
1370
1370
|
|
|
1371
1371
|
react/cjs/react.production.js:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/index.tsx
|
|
2
2
|
import {
|
|
3
3
|
createRef,
|
|
4
4
|
useCallback as useCallback16,
|
|
@@ -7932,7 +7932,7 @@ function Editable2({
|
|
|
7932
7932
|
);
|
|
7933
7933
|
}
|
|
7934
7934
|
|
|
7935
|
-
// src/
|
|
7935
|
+
// src/index.tsx
|
|
7936
7936
|
import { jsx as jsx60 } from "react/jsx-runtime";
|
|
7937
7937
|
function StandaloneEditor({
|
|
7938
7938
|
standaloneOptions: { onChange, placeholder, className, ...options },
|
|
@@ -8004,6 +8004,8 @@ function createWysimark(containerElement, options) {
|
|
|
8004
8004
|
};
|
|
8005
8005
|
}
|
|
8006
8006
|
export {
|
|
8007
|
-
|
|
8007
|
+
Editable2 as Editable,
|
|
8008
|
+
createWysimark,
|
|
8009
|
+
useEditor
|
|
8008
8010
|
};
|
|
8009
|
-
//# sourceMappingURL=
|
|
8011
|
+
//# sourceMappingURL=index.mjs.map
|