@unifiedsoftware/react-editor 2.0.0-alpha.14 → 2.0.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +16 -6
- package/dist/index.js +2 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -16,24 +16,34 @@ type EditorToolbarButtonLabelIcon = {
|
|
|
16
16
|
onAction: () => void;
|
|
17
17
|
};
|
|
18
18
|
type EditorToolbarButton = EditorToolbarButtonCommand | EditorToolbarButtonLabel | EditorToolbarButtonIcon | EditorToolbarButtonLabelIcon;
|
|
19
|
-
type
|
|
20
|
-
type
|
|
21
|
-
type
|
|
19
|
+
type OnChange = (value: string) => void;
|
|
20
|
+
type OnBlur = (value: string) => void;
|
|
21
|
+
type OnPaste = (text: {
|
|
22
22
|
html: string;
|
|
23
23
|
plain: string;
|
|
24
24
|
}) => string;
|
|
25
25
|
interface EditorToolbarOptions {
|
|
26
26
|
buttons?: EditorToolbarButton[][];
|
|
27
27
|
}
|
|
28
|
+
type OnMentionSearch = (search: string) => void;
|
|
29
|
+
type EditorMention = {
|
|
30
|
+
data: any;
|
|
31
|
+
renderItem: (options: {
|
|
32
|
+
data: any;
|
|
33
|
+
props: any;
|
|
34
|
+
}) => HTMLElement | string;
|
|
35
|
+
onSearch?: OnMentionSearch;
|
|
36
|
+
};
|
|
28
37
|
|
|
29
38
|
interface EditorProps {
|
|
30
39
|
value?: string;
|
|
31
40
|
height?: number;
|
|
32
41
|
readOnly?: boolean;
|
|
33
42
|
toolbar?: EditorToolbarOptions;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
mention?: EditorMention;
|
|
44
|
+
onChange?: OnChange;
|
|
45
|
+
onBlur?: OnBlur;
|
|
46
|
+
onPaste?: OnPaste;
|
|
37
47
|
}
|
|
38
48
|
declare const Editor: React.FC<EditorProps>;
|
|
39
49
|
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`).map(
|
|
1
|
+
"use strict";var j=Object.create;var T=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var N=(o,e)=>{for(var n in e)T(o,n,{get:e[n],enumerable:!0})},D=(o,e,n,d)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of A(e))!F.call(o,i)&&i!==n&&T(o,i,{get:()=>e[i],enumerable:!(d=z(e,i))||d.enumerable});return o};var X=(o,e,n)=>(n=o!=null?j(H(o)):{},D(e||!o||!o.__esModule?T(n,"default",{value:o,enumerable:!0}):n,o)),Z=o=>D(T({},"__esModule",{value:!0}),o);var w={};N(w,{Editor:()=>q,isToolbarButtonIcon:()=>_,isToolbarButtonLabel:()=>y,isToolbarButtonLabelIcon:()=>C});module.exports=Z(w);var R=require("@unifiedsoftware/react-ui"),P=X(require("dompurify"));var J=[["undo","redo"],["font","fontSize"],["bold","italic","underline","strikethrough"],["ol","ul"],["outdent","indent"],["left","center","right","justify"],["link","unlink","image","source"]];var U=require("jodit/es5/jodit.min.css");var v=require("jodit"),s=require("react"),M=require("react-dom/server");function y(o){return o.label!==void 0&&o.icon===void 0}function _(o){return o.label===void 0&&o.icon!==void 0}function C(o){return o.label!==void 0&&o.icon!==void 0}var O=require("react/jsx-runtime");function k(o){return typeof o=="string"?o:(0,M.renderToString)(o)}var $={undo:"undo",redo:"redo",font:"font",fontSize:"fontsize",bold:"bold",italic:"italic",underline:"underline",strikethrough:"strikethrough",ol:"ol",ul:"ul",outdent:"outdent",indent:"indent",left:"left",center:"center",right:"right",justify:"justify",link:"link",unlink:"unlink",image:"image",source:"source",brush:"brush"},x=({value:o,height:e,readOnly:n,toolbar:d,mention:i,onChange:p,onBlur:m,onPaste:b})=>{let g=(0,s.useRef)(null),c=(0,s.useRef)(null),h=(0,s.useMemo)(()=>d?.buttons?.map(r=>({buttons:r.map(t=>typeof t=="string"?$[t]:C(t)?{name:t.label,tooltip:t.tooltip,icon:k(t.icon),exec:()=>{t.onAction()}}:y(t)?{name:t.label,tooltip:t.tooltip,exec:()=>{t.onAction()}}:{name:"",icon:k(t.icon),tooltip:t.tooltip,exec:()=>{t.onAction()}})})),[d?.buttons]);return(0,s.useEffect)(()=>{let r=g.current;if(!r)return;let t={iframe:!0,height:e??"480px",readonly:n,statusbar:!1,toolbarAdaptive:!0,...n?{toolbar:!1}:{buttons:h,buttonsXS:h,buttonsSM:h,buttonsMD:h}};console.log(i);let u=v.Jodit.make(r,{...t,...i?{highlightSignature:{schema:{"@[a-zA-Z0-9._-]+":a=>{let l=a.createInside.element("strong",{style:{color:"blue"}});return console.log(l),l}}},autocomplete:{itemRenderer:a=>{try{return i.renderItem?.({data:a,props:{}})}catch{return a.value}},sources:[i.data]}}:{},events:{paste:a=>{if(b){a.preventDefault();let l=a.clipboardData,I=l.getData("text/html"),B=l.getData("text/plain");B=B.split(`
|
|
2
|
+
`).map(S=>`<p>${S.trim()}</p>`).join("");let L=b({html:I,plain:B});u.selection.insertHTML(L)}return a}}});u.container.style.cssText="border: 0; border-radius: 0; background-color: #fff;",c.current=u;let E=u.iframe?.contentDocument;if(E){let a=E.head.getElementsByTagName("style")??[];Array.from(a).forEach(l=>l.remove())}return()=>{u?.destruct()}},[]),(0,s.useEffect)(()=>{let r=c.current;if(!r)return;let t=E=>{p?.(E)},u=()=>{m?.(r.value)};return r.events.on("change",t),r.events.on("blur",u),()=>{r?.events?.off("change",t),r?.events?.off("blur",u)}},[p,m]),(0,s.useEffect)(()=>{let r=c.current;r&&r.value!==o&&(r.value=o??"")},[o]),(0,O.jsx)("div",{ref:g})};var f=require("react/jsx-runtime"),q=({value:o,readOnly:e,toolbar:n,onChange:d,onBlur:i,onPaste:p,...m})=>{let b=c=>{d?.(P.default.sanitize(c))},g=c=>{i?.(P.default.sanitize(c))};return(0,f.jsx)(f.Fragment,{children:e?(0,f.jsx)(R.Html,{src:o}):(0,f.jsx)(x,{...m,value:o,toolbar:{buttons:n?.buttons??J},onChange:b,onBlur:g,onPaste:p})})};0&&(module.exports={Editor,isToolbarButtonIcon,isToolbarButtonLabel,isToolbarButtonLabelIcon});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unifiedsoftware/react-editor",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.15",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"react-dom": ">=18"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@unifiedsoftware/react-ui": "2.0.0-alpha.
|
|
24
|
+
"@unifiedsoftware/react-ui": "2.0.0-alpha.15",
|
|
25
25
|
"dompurify": "^3.1.6",
|
|
26
26
|
"jodit": "4.2.24"
|
|
27
27
|
},
|