@unifiedsoftware/react-editor 2.0.0-alpha.10
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 +44 -0
- package/dist/index.js +2 -0
- package/package.json +30 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
type EditorToolbarButtonCommand = 'undo' | 'redo' | 'font' | 'fontSize' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'ol' | 'ul' | 'outdent' | 'indent' | 'left' | 'center' | 'right' | 'justify' | 'link' | 'unlink' | 'image' | 'source' | 'brush';
|
|
2
|
+
type EditorToolbarButtonLabel = {
|
|
3
|
+
label: string;
|
|
4
|
+
tooltip?: string;
|
|
5
|
+
onAction: () => void;
|
|
6
|
+
};
|
|
7
|
+
type EditorToolbarButtonIcon = {
|
|
8
|
+
icon: React.ReactNode;
|
|
9
|
+
tooltip?: string;
|
|
10
|
+
onAction: () => void;
|
|
11
|
+
};
|
|
12
|
+
type EditorToolbarButtonLabelIcon = {
|
|
13
|
+
label: string;
|
|
14
|
+
icon: React.ReactNode;
|
|
15
|
+
tooltip?: string;
|
|
16
|
+
onAction: () => void;
|
|
17
|
+
};
|
|
18
|
+
type EditorToolbarButton = EditorToolbarButtonCommand | EditorToolbarButtonLabel | EditorToolbarButtonIcon | EditorToolbarButtonLabelIcon;
|
|
19
|
+
type EditorChangeCallback = (value: string) => void;
|
|
20
|
+
type EditorBlurCallback = (value: string) => void;
|
|
21
|
+
type EditorPasteCallback = (text: {
|
|
22
|
+
html: string;
|
|
23
|
+
plain: string;
|
|
24
|
+
}) => string;
|
|
25
|
+
interface EditorToolbarOptions {
|
|
26
|
+
buttons?: EditorToolbarButton[][];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface EditorProps {
|
|
30
|
+
value?: string;
|
|
31
|
+
height?: number;
|
|
32
|
+
readOnly?: boolean;
|
|
33
|
+
toolbar?: EditorToolbarOptions;
|
|
34
|
+
onChange?: EditorChangeCallback;
|
|
35
|
+
onBlur?: EditorBlurCallback;
|
|
36
|
+
onPaste?: EditorPasteCallback;
|
|
37
|
+
}
|
|
38
|
+
declare const Editor: React.FC<EditorProps>;
|
|
39
|
+
|
|
40
|
+
declare function isToolbarButtonLabel(arg: any): arg is EditorToolbarButtonLabel;
|
|
41
|
+
declare function isToolbarButtonIcon(arg: any): arg is EditorToolbarButtonIcon;
|
|
42
|
+
declare function isToolbarButtonLabelIcon(arg: any): arg is EditorToolbarButtonLabelIcon;
|
|
43
|
+
|
|
44
|
+
export { Editor, type EditorProps, isToolbarButtonIcon, isToolbarButtonLabel, isToolbarButtonLabelIcon };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var S=Object.create;var h=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var F=(o,r)=>{for(var n in r)h(o,n,{get:r[n],enumerable:!0})},y=(o,r,n,d)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of A(r))!O.call(o,i)&&i!==n&&h(o,i,{get:()=>r[i],enumerable:!(d=z(r,i))||d.enumerable});return o};var N=(o,r,n)=>(n=o!=null?S(H(o)):{},y(r||!o||!o.__esModule?h(n,"default",{value:o,enumerable:!0}):n,o)),X=o=>y(h({},"__esModule",{value:!0}),o);var G={};F(G,{Editor:()=>w,isToolbarButtonIcon:()=>$,isToolbarButtonLabel:()=>C,isToolbarButtonLabelIcon:()=>B});module.exports=X(G);var R=require("@unifiedsoftware/react-ui"),k=N(require("dompurify"));var x=[["undo","redo"],["font","fontSize"],["bold","italic","underline","strikethrough"],["ol","ul"],["outdent","indent"],["left","center","right","justify"],["link","unlink","image","source"]];var V=require("jodit/es5/jodit.min.css"),W=require("jodit/esm/plugins/source/source"),Y=require("jodit/esm/plugins/indent/indent"),Z=require("jodit/esm/plugins/justify/justify"),_=require("jodit/esm/plugins/select/select"),oo=require("jodit/esm/plugins/select-cells/select-cells"),to=require("jodit/esm/plugins/placeholder/placeholder"),D=require("jodit"),a=require("react"),J=require("react-dom/server");function C(o){return o.label!==void 0&&o.icon===void 0}function $(o){return o.label===void 0&&o.icon!==void 0}function B(o){return o.label!==void 0&&o.icon!==void 0}var L=require("react/jsx-runtime");function P(o){return typeof o=="string"?o:(0,J.renderToString)(o)}var q={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"},v=({value:o,height:r,readOnly:n,toolbar:d,onChange:i,onBlur:p,onPaste:m})=>{let b=(0,a.useRef)(null),c=(0,a.useRef)(null),l=(0,a.useMemo)(()=>d?.buttons?.map(e=>({buttons:e.map(t=>typeof t=="string"?q[t]:B(t)?{name:t.label,tooltip:t.tooltip,icon:P(t.icon),exec:()=>{t.onAction()}}:C(t)?{name:t.label,tooltip:t.tooltip,exec:()=>{t.onAction()}}:{name:"",icon:P(t.icon),tooltip:t.tooltip,exec:()=>{t.onAction()}})})),[d?.buttons]);return(0,a.useEffect)(()=>{let e=b.current;if(!e)return;let t={iframe:!0,height:r??"480px",readonly:n,statusbar:!1,toolbarAdaptive:!0,...n?{toolbar:!1}:{buttons:l,buttonsXS:l,buttonsSM:l,buttonsMD:l}},s=D.Jodit.make(e,{...t,events:{paste:f=>{if(m){f.preventDefault();let E=f.clipboardData,M=E.getData("text/html"),T=E.getData("text/plain");T=T.split(`
|
|
2
|
+
`).map(j=>`<p>${j.trim()}</p>`).join("");let I=m({html:M,plain:T});s.selection.insertHTML(I)}return f}}});s.container.style.cssText="border: 0; border-radius: 0; background-color: #fff;",c.current=s;let g=s.iframe?.contentDocument;if(g){let f=g.head.getElementsByTagName("style")??[];Array.from(f).forEach(E=>E.remove())}return()=>{s?.destruct()}},[]),(0,a.useEffect)(()=>{let e=c.current;if(!e)return;let t=g=>{i?.(g)},s=()=>{p?.(e.value)};return e.events.on("change",t),e.events.on("blur",s),()=>{e?.events?.off("change",t),e?.events?.off("blur",s)}},[i,p]),(0,a.useEffect)(()=>{let e=c.current;e&&e.value!==o&&(e.value=o??"")},[o]),(0,L.jsx)("div",{ref:b})};var u=require("react/jsx-runtime"),w=({value:o,readOnly:r,toolbar:n,onChange:d,onBlur:i,onPaste:p,...m})=>{let b=l=>{d?.(k.default.sanitize(l))},c=l=>{i?.(k.default.sanitize(l))};return(0,u.jsx)(u.Fragment,{children:r?(0,u.jsx)(R.Html,{src:o}):(0,u.jsx)(v,{...m,value:o,toolbar:{buttons:n?.buttons??x},onChange:b,onBlur:c,onPaste:p})})};0&&(module.exports={Editor,isToolbarButtonIcon,isToolbarButtonLabel,isToolbarButtonLabelIcon});
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unifiedsoftware/react-editor",
|
|
3
|
+
"version": "2.0.0-alpha.10",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist/**"
|
|
8
|
+
],
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsup",
|
|
15
|
+
"prepack": "clean-package",
|
|
16
|
+
"postpack": "clean-package restore",
|
|
17
|
+
"typecheck": "tsc --noEmit"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"react": ">=18",
|
|
21
|
+
"react-dom": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@unifiedsoftware/react-ui": "2.0.0-alpha.10",
|
|
25
|
+
"dompurify": "^3.1.6",
|
|
26
|
+
"jodit": "4.2.24"
|
|
27
|
+
},
|
|
28
|
+
"clean-package": "../../../clean-package.config.json",
|
|
29
|
+
"types": "dist/index.d.ts"
|
|
30
|
+
}
|