@unifiedsoftware/react-editor 2.0.0-alpha.2

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.
@@ -0,0 +1,22 @@
1
+ import * as React from 'react';
2
+
3
+ type EditorToolbarButton = 'undo' | 'redo' | 'font' | 'fontsize' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'ol' | 'ul' | 'outdent' | 'indent' | 'left' | 'center' | 'right' | 'justify' | 'link' | 'unlink' | 'image' | 'source' | 'brush';
4
+ interface EditorProps {
5
+ value?: string;
6
+ height?: number;
7
+ readOnly?: boolean;
8
+ toolbar?: {
9
+ buttons?: EditorToolbarButton[][];
10
+ };
11
+ onChange?: (value: string) => void;
12
+ onPaste?: (text: {
13
+ html: string;
14
+ plain: string;
15
+ }) => string;
16
+ }
17
+ declare const Editor: React.FC<EditorProps>;
18
+
19
+ declare function convertHtmlToRtf(html: string): string;
20
+ declare function convertHtmlToPlainText(html: string): string;
21
+
22
+ export { Editor, type EditorProps, type EditorToolbarButton, convertHtmlToPlainText, convertHtmlToRtf };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var R=Object.create;var g=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var H=(t,o)=>{for(var n in o)g(t,n,{get:o[n],enumerable:!0})},v=(t,o,n,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of B(o))!j.call(t,r)&&r!==n&&g(t,r,{get:()=>o[r],enumerable:!(i=k(o,r))||i.enumerable});return t};var h=(t,o,n)=>(n=t!=null?R(M(t)):{},v(o||!t||!t.__esModule?g(n,"default",{value:t,enumerable:!0}):n,t)),L=t=>v(g({},"__esModule",{value:!0}),t);var O={};H(O,{Editor:()=>A,convertHtmlToPlainText:()=>N,convertHtmlToRtf:()=>F});module.exports=L(O);var $=require("jodit/es5/jodit.min.css"),q=require("jodit/esm/plugins/source/source"),w=require("jodit/esm/plugins/indent/indent"),G=require("jodit/esm/plugins/justify/justify"),I=require("jodit/esm/plugins/select/select"),K=require("jodit/esm/plugins/select-cells/select-cells"),Q=require("jodit/esm/plugins/placeholder/placeholder"),T=h(require("dompurify")),x=require("jodit"),C=h(require("react")),u=require("react"),f=require("react/jsx-runtime"),S=({value:t,config:o,onChange:n,onBlur:i,onPaste:r})=>{let d=(0,u.useRef)(null),s=(0,u.useRef)(null);return(0,u.useEffect)(()=>{let e=d.current;if(!e)return;let a=o,l=x.Jodit.make(e,{...a,events:{paste:c=>{if(r){c.preventDefault();let m=c.clipboardData,D=m.getData("text/html"),b=m.getData("text/plain");b=b.split(`
2
+ `).map(J=>`<p>${J.trim()}</p>`).join("");let P=r({html:D,plain:b});l.selection.insertHTML(P)}return c}}});l.container.style.cssText="border: 0; border-radius: 0; background-color: #fff;",s.current=l;let p=l.iframe?.contentDocument;if(p){let c=p.head.getElementsByTagName("style")??[];Array.from(c).forEach(m=>m.remove())}return()=>{l?.destruct()}},[o]),(0,u.useEffect)(()=>{let e=s.current;if(!e)return;let a=p=>{n?.(p)},l=()=>{i?.(e.value)};return e.events.on("change",a),e.events.on("blur",l),()=>{e?.events?.off("change",a),e?.events?.off("blur",l)}},[n,i]),(0,u.useEffect)(()=>{let e=s.current;e&&e.value!==t&&(e.value=t??"")},[t]),(0,f.jsx)("div",{ref:d})},z=[["undo","redo"],["font","fontsize"],["bold","italic","underline","strikethrough"],["ol","ul"],["outdent","indent"],["left","center","right","justify"],["link","unlink","image","source"]],A=({value:t,height:o,readOnly:n,toolbar:i,onChange:r,onPaste:d})=>{let s=C.useMemo(()=>(i?.buttons??z).map(a=>({buttons:a})),[i?.buttons]),e=a=>{r?.(T.default.sanitize(a))};return(0,f.jsx)(f.Fragment,{children:(0,f.jsx)(S,{value:t,config:{iframe:!0,height:o??"480px",readonly:n,statusbar:!1,toolbarAdaptive:!0,...n?{toolbar:!1}:{buttons:s,buttonsXS:s,buttonsSM:s,buttonsMD:s}},onBlur:e,onPaste:d})})};var E=h(require("html-to-rtf")),y=require("html-to-text");function F(t){return E.default.convertHtmlToRtf(t)}function N(t){return(0,y.convert)(t,{selectors:[{selector:"p",options:{leadingLineBreaks:1,trailingLineBreaks:1}}]})}0&&(module.exports={Editor,convertHtmlToPlainText,convertHtmlToRtf});
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@unifiedsoftware/react-editor",
3
+ "version": "2.0.0-alpha.2",
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
+ "dompurify": "^3.1.6",
25
+ "html-to-rtf": "^2.1.0",
26
+ "html-to-rtf-browser": "^1.6.1",
27
+ "html-to-text": "^9.0.5",
28
+ "jodit": "4.2.24"
29
+ },
30
+ "clean-package": "../../../clean-package.config.json",
31
+ "types": "dist/index.d.ts"
32
+ }