@asaleh37/ui-base 1.2.15 → 1.2.17
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 +1 -10
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -17
- package/public/icons/LICENSE.md +5 -0
- package/public/icons/arrow-clockwise.svg +4 -0
- package/public/icons/arrow-counterclockwise.svg +4 -0
- package/public/icons/journal-text.svg +5 -0
- package/public/icons/justify.svg +3 -0
- package/public/icons/text-center.svg +3 -0
- package/public/icons/text-left.svg +3 -0
- package/public/icons/text-paragraph.svg +3 -0
- package/public/icons/text-right.svg +3 -0
- package/public/icons/type-bold.svg +3 -0
- package/public/icons/type-italic.svg +3 -0
- package/public/icons/type-strikethrough.svg +3 -0
- package/public/icons/type-underline.svg +3 -0
- package/src/components/administration/dev/MailBodyGrid.tsx +3 -2
- package/src/components/common/Home.tsx +23 -24
- package/src/components/index.ts +0 -4
- package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormElementField.tsx +0 -20
- package/src/components/templates/index.ts +0 -1
- package/src/index.ts +0 -4
- package/src/redux/features/common/SideBarSlice.ts +0 -2
- package/vite.config.ts +1 -6
- package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/HtmlEditor.tsx +0 -144
- package/src/global-shim.ts +0 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asaleh37/ui-base",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.17",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Ahmed Saleh Mohamed",
|
|
@@ -37,14 +37,11 @@
|
|
|
37
37
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
38
38
|
"@rollup/plugin-terser": "^0.4.4",
|
|
39
39
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
40
|
-
"@types/react": "^19.1.
|
|
40
|
+
"@types/react": "^19.1.8",
|
|
41
41
|
"@types/react-dom": "^19.0.3",
|
|
42
42
|
"@types/react-i18next": "^7.8.3",
|
|
43
43
|
"@vitejs/plugin-react": "^4.3.4",
|
|
44
|
-
"axios": "^1.8.1",
|
|
45
|
-
"draft-js": "^0.11.7",
|
|
46
|
-
"draft-js-import-html": "^1.4.1",
|
|
47
|
-
"draftjs-to-html": "^0.9.1",
|
|
44
|
+
"axios": "^1.8.1",
|
|
48
45
|
"eslint": "^9.19.0",
|
|
49
46
|
"eslint-plugin-react-hooks": "^5.0.0",
|
|
50
47
|
"eslint-plugin-react-refresh": "^0.4.18",
|
|
@@ -56,8 +53,7 @@
|
|
|
56
53
|
"moment": "^2.30.1",
|
|
57
54
|
"oidc-client-ts": "^3.1.0",
|
|
58
55
|
"react": "^19.1.0",
|
|
59
|
-
"react-dom": "^19.0.0",
|
|
60
|
-
"react-draft-wysiwyg": "^1.15.0",
|
|
56
|
+
"react-dom": "^19.0.0",
|
|
61
57
|
"react-hook-form": "^7.54.2",
|
|
62
58
|
"react-i18next": "^15.4.0",
|
|
63
59
|
"react-redux": "^9.2.0",
|
|
@@ -96,10 +92,7 @@
|
|
|
96
92
|
"@mui/x-tree-view": "^7.26.0",
|
|
97
93
|
"@react-spring/web": "^9.7.5",
|
|
98
94
|
"@reduxjs/toolkit": "^2.5.1",
|
|
99
|
-
"axios": "^1.8.1",
|
|
100
|
-
"draft-js": "^0.11.7",
|
|
101
|
-
"draft-js-import-html": "^1.4.1",
|
|
102
|
-
"draftjs-to-html": "^0.9.1",
|
|
95
|
+
"axios": "^1.8.1",
|
|
103
96
|
"global": "^4.4.0",
|
|
104
97
|
"i18next": "^24.2.2",
|
|
105
98
|
"i18next-browser-languagedetector": "^8.0.3",
|
|
@@ -107,8 +100,7 @@
|
|
|
107
100
|
"moment": "^2.30.1",
|
|
108
101
|
"oidc-client-ts": "^3.1.0",
|
|
109
102
|
"react": "^19.0.0",
|
|
110
|
-
"react-dom": "^19.0.0",
|
|
111
|
-
"react-draft-wysiwyg": "^1.15.0",
|
|
103
|
+
"react-dom": "^19.0.0",
|
|
112
104
|
"react-hook-form": "^7.54.2",
|
|
113
105
|
"react-i18next": "^15.4.0",
|
|
114
106
|
"react-redux": "^9.2.0",
|
|
@@ -121,8 +113,7 @@
|
|
|
121
113
|
"stylis-plugin-rtl": "^2.1.1",
|
|
122
114
|
"zod": "^3.24.2"
|
|
123
115
|
},
|
|
124
|
-
"dependencies": {
|
|
125
|
-
"@rollup/plugin-json": "^6.1.0"
|
|
126
|
-
"vite-tsconfig-paths": "^5.1.4"
|
|
116
|
+
"dependencies": {
|
|
117
|
+
"@rollup/plugin-json": "^6.1.0"
|
|
127
118
|
}
|
|
128
119
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-clockwise" viewBox="0 0 16 16">
|
|
2
|
+
<path fill-rule="evenodd" d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2v1z"/>
|
|
3
|
+
<path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466z"/>
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-counterclockwise" viewBox="0 0 16 16">
|
|
2
|
+
<path fill-rule="evenodd" d="M8 3a5 5 0 1 1-4.546 2.914.5.5 0 0 0-.908-.417A6 6 0 1 0 8 2v1z"/>
|
|
3
|
+
<path d="M8 4.466V.534a.25.25 0 0 0-.41-.192L5.23 2.308a.25.25 0 0 0 0 .384l2.36 1.966A.25.25 0 0 0 8 4.466z"/>
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-journal-text" viewBox="0 0 16 16">
|
|
2
|
+
<path d="M5 10.5a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 0 1h-2a.5.5 0 0 1-.5-.5zm0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5zm0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5zm0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5z"/>
|
|
3
|
+
<path d="M3 0h10a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2v-1h1v1a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v1H1V2a2 2 0 0 1 2-2z"/>
|
|
4
|
+
<path d="M1 5v-.5a.5.5 0 0 1 1 0V5h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1H1zm0 3v-.5a.5.5 0 0 1 1 0V8h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1H1zm0 3v-.5a.5.5 0 0 1 1 0v.5h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1H1z"/>
|
|
5
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-justify" viewBox="0 0 16 16">
|
|
2
|
+
<path fill-rule="evenodd" d="M2 12.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-center" viewBox="0 0 16 16">
|
|
2
|
+
<path fill-rule="evenodd" d="M4 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-left" viewBox="0 0 16 16">
|
|
2
|
+
<path fill-rule="evenodd" d="M2 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-paragraph" viewBox="0 0 16 16">
|
|
2
|
+
<path fill-rule="evenodd" d="M2 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm4-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5z"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-right" viewBox="0 0 16 16">
|
|
2
|
+
<path fill-rule="evenodd" d="M6 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm4-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-type-bold" viewBox="0 0 16 16">
|
|
2
|
+
<path d="M8.21 13c2.106 0 3.412-1.087 3.412-2.823 0-1.306-.984-2.283-2.324-2.386v-.055a2.176 2.176 0 0 0 1.852-2.14c0-1.51-1.162-2.46-3.014-2.46H3.843V13H8.21zM5.908 4.674h1.696c.963 0 1.517.451 1.517 1.244 0 .834-.629 1.32-1.73 1.32H5.908V4.673zm0 6.788V8.598h1.73c1.217 0 1.88.492 1.88 1.415 0 .943-.643 1.449-1.832 1.449H5.907z"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-type-italic" viewBox="0 0 16 16">
|
|
2
|
+
<path d="M7.991 11.674 9.53 4.455c.123-.595.246-.71 1.347-.807l.11-.52H7.211l-.11.52c1.06.096 1.128.212 1.005.807L6.57 11.674c-.123.595-.246.71-1.346.806l-.11.52h3.774l.11-.52c-1.06-.095-1.129-.211-1.006-.806z"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-type-strikethrough" viewBox="0 0 16 16">
|
|
2
|
+
<path d="M6.333 5.686c0 .31.083.581.27.814H5.166a2.776 2.776 0 0 1-.099-.76c0-1.627 1.436-2.768 3.48-2.768 1.969 0 3.39 1.175 3.445 2.85h-1.23c-.11-1.08-.964-1.743-2.25-1.743-1.23 0-2.18.602-2.18 1.607zm2.194 7.478c-2.153 0-3.589-1.107-3.705-2.81h1.23c.144 1.06 1.129 1.703 2.544 1.703 1.34 0 2.31-.705 2.31-1.675 0-.827-.547-1.374-1.914-1.675L8.046 8.5H1v-1h14v1h-3.504c.468.437.675.994.675 1.697 0 1.826-1.436 2.967-3.644 2.967z"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-type-underline" viewBox="0 0 16 16">
|
|
2
|
+
<path d="M5.313 3.136h-1.23V9.54c0 2.105 1.47 3.623 3.917 3.623s3.917-1.518 3.917-3.623V3.136h-1.23v6.323c0 1.49-.978 2.57-2.687 2.57-1.709 0-2.687-1.08-2.687-2.57V3.136zM12.5 15h-9v-1h9v1z"/>
|
|
3
|
+
</svg>
|
|
@@ -90,7 +90,7 @@ const MailBodyGrid: React.FC<MailBodyGridProps> = (props) => {
|
|
|
90
90
|
},
|
|
91
91
|
},
|
|
92
92
|
},
|
|
93
|
-
|
|
93
|
+
{
|
|
94
94
|
type: "field",
|
|
95
95
|
mode: "props",
|
|
96
96
|
props: {
|
|
@@ -117,7 +117,8 @@ const MailBodyGrid: React.FC<MailBodyGridProps> = (props) => {
|
|
|
117
117
|
fieldLabel: "MAIL_BODY_BODY_CONTENT",
|
|
118
118
|
fieldName: "bodyContent",
|
|
119
119
|
required: true,
|
|
120
|
-
fieldType: "
|
|
120
|
+
fieldType: "text",
|
|
121
|
+
muiTextFieldProps: { multiline: true, rows: 6 },
|
|
121
122
|
},
|
|
122
123
|
},
|
|
123
124
|
|
|
@@ -3,34 +3,33 @@ import { Box } from "@mui/material";
|
|
|
3
3
|
import { TemplateForm } from "../templates";
|
|
4
4
|
import ReportViewer from "../templates/report/ReportViewer";
|
|
5
5
|
import WorkflowDocumentPanel from "../templates/workflow/WorkflowDocumentPanel";
|
|
6
|
-
import ExampleDashboard from "../templates/visuals/ExampleDashboard";
|
|
7
6
|
import DashboardViewer from "../templates/visuals/DashboardViewer";
|
|
8
7
|
|
|
9
8
|
const Home: React.FC = () => {
|
|
10
9
|
return (
|
|
11
|
-
<DashboardViewer dashboardCode="XX_TEMPLATE_DASHBOARD" />
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
10
|
+
// <DashboardViewer dashboardCode="XX_TEMPLATE_DASHBOARD" />
|
|
11
|
+
<Box
|
|
12
|
+
sx={{
|
|
13
|
+
display: "flex",
|
|
14
|
+
flexDirection: "column",
|
|
15
|
+
alignItems: "center",
|
|
16
|
+
justifyContent: "center",
|
|
17
|
+
flex: 1,
|
|
18
|
+
fontSize: 24,
|
|
19
|
+
fontWeight: "bold",
|
|
20
|
+
}}
|
|
21
|
+
>
|
|
22
|
+
<img src="logo.png" style={{ margin: 5 }} />
|
|
23
|
+
<div>Welcome to Ezzsteel Flat Product Management System</div>
|
|
24
|
+
<div style={{ fontSize: 16 }}>
|
|
25
|
+
Use side menu [
|
|
26
|
+
<FontAwesomeIcon
|
|
27
|
+
icon="bars"
|
|
28
|
+
style={{ marginLeft: 10, marginRight: 10 }}
|
|
29
|
+
/>
|
|
30
|
+
] to navigate to your authorized system modules
|
|
31
|
+
</div>
|
|
32
|
+
</Box>
|
|
34
33
|
);
|
|
35
34
|
};
|
|
36
35
|
|
package/src/components/index.ts
CHANGED
|
@@ -7,7 +7,6 @@ import CheckBox from "./FormFields/CheckBox";
|
|
|
7
7
|
import { DATE_FORMAT, DATE_TIME_FORMAT } from "../../../../util/constants";
|
|
8
8
|
import { isNumeric } from "../../../../util/AppUtils";
|
|
9
9
|
import { FormElementFieldProps } from "../DataEntryTypes";
|
|
10
|
-
import HtmlEditor from "./FormFields/HtmlEditor";
|
|
11
10
|
import SystemLookupCombobox from "./FormFields/SystemLookupCombobox";
|
|
12
11
|
|
|
13
12
|
const FormElementField: React.FC<FormElementFieldProps> = (
|
|
@@ -219,25 +218,6 @@ const FormElementField: React.FC<FormElementFieldProps> = (
|
|
|
219
218
|
fieldName
|
|
220
219
|
]?.message?.toString()}
|
|
221
220
|
/>
|
|
222
|
-
) : props?.fieldType === "html" ? (
|
|
223
|
-
<HtmlEditor
|
|
224
|
-
label={props.fieldLabel}
|
|
225
|
-
value={formValues[fieldName] || ""}
|
|
226
|
-
errorMessage={formManager?.formState?.errors[
|
|
227
|
-
fieldName
|
|
228
|
-
]?.message?.toString()}
|
|
229
|
-
setValue={(v) => {
|
|
230
|
-
formManager.setValue(fieldName, v);
|
|
231
|
-
if (props?.formProps?.onValueChangeCallBack) {
|
|
232
|
-
props?.formProps?.onValueChangeCallBack(
|
|
233
|
-
v,
|
|
234
|
-
formManager,
|
|
235
|
-
formActions
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
}}
|
|
239
|
-
maxLength={4000}
|
|
240
|
-
/>
|
|
241
221
|
) : (
|
|
242
222
|
<>Unknown field type</>
|
|
243
223
|
)}
|
|
@@ -12,7 +12,6 @@ export { default as DatetimeField } from "./DataEntryTemplates/TemplateDataForm/
|
|
|
12
12
|
export { default as TemplateTextField } from "./DataEntryTemplates/TemplateDataForm/FormFields/TemplateTextField";
|
|
13
13
|
export { default as TemplateForm } from "./DataEntryTemplates/TemplateDataForm/TemplateForm";
|
|
14
14
|
export { default as TemplateGrid } from "./DataEntryTemplates/TemplateDataGrid/TemplateGrid";
|
|
15
|
-
export { default as HtmlEditor } from "./DataEntryTemplates/TemplateDataForm/FormFields/HtmlEditor";
|
|
16
15
|
|
|
17
16
|
export type * from "./DataEntryTemplates/DataEntryTypes";
|
|
18
17
|
export type { TransferListProps } from "./TransferList";
|
package/src/index.ts
CHANGED
|
@@ -15,11 +15,9 @@ const SideBarSlice = createSlice({
|
|
|
15
15
|
initialState,
|
|
16
16
|
reducers: {
|
|
17
17
|
toggleSideBarState: (state) => {
|
|
18
|
-
debugger;
|
|
19
18
|
state.isOpened = !state.isOpened;
|
|
20
19
|
},
|
|
21
20
|
setSideBarState: (state, action) => {
|
|
22
|
-
debugger;
|
|
23
21
|
state.isOpened = action.payload;
|
|
24
22
|
},
|
|
25
23
|
},
|
package/vite.config.ts
CHANGED
|
@@ -14,12 +14,7 @@ export default defineConfig({
|
|
|
14
14
|
},
|
|
15
15
|
build: {
|
|
16
16
|
rollupOptions: {
|
|
17
|
-
plugins: [
|
|
18
|
-
rollupNodePolyFill(),
|
|
19
|
-
inject({
|
|
20
|
-
global: [require.resolve("./src/global-shim"), "global"], // Inject our shim
|
|
21
|
-
}),
|
|
22
|
-
],
|
|
17
|
+
plugins: [rollupNodePolyFill()],
|
|
23
18
|
},
|
|
24
19
|
},
|
|
25
20
|
server: {
|
package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/HtmlEditor.tsx
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { EditorState, convertToRaw } from "draft-js";
|
|
2
|
-
import { Editor } from "react-draft-wysiwyg";
|
|
3
|
-
import draftToHtml from "draftjs-to-html";
|
|
4
|
-
import { stateFromHTML } from "draft-js-import-html";
|
|
5
|
-
import { useState } from "react";
|
|
6
|
-
import "react-draft-wysiwyg/dist/react-draft-wysiwyg.css";
|
|
7
|
-
import { useEffect } from "react";
|
|
8
|
-
import { Box, Paper } from "@mui/material";
|
|
9
|
-
import { useTranslation } from "react-i18next";
|
|
10
|
-
|
|
11
|
-
type HtmlEditorProps = {
|
|
12
|
-
label?: string;
|
|
13
|
-
value: string;
|
|
14
|
-
setValue: (v: any) => void;
|
|
15
|
-
maxLength: number;
|
|
16
|
-
errorMessage?: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const HtmlEditor: React.FC<HtmlEditorProps> = ({
|
|
20
|
-
label,
|
|
21
|
-
errorMessage,
|
|
22
|
-
value,
|
|
23
|
-
setValue,
|
|
24
|
-
maxLength,
|
|
25
|
-
}) => {
|
|
26
|
-
const { t } = useTranslation();
|
|
27
|
-
const options = {
|
|
28
|
-
customInlineFn: (element, { Style }) => {
|
|
29
|
-
if (element.style.color) {
|
|
30
|
-
return Style("color-" + element.style.color);
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
let contentState = stateFromHTML(value, options);
|
|
36
|
-
|
|
37
|
-
const [editorState, setEditorState] = useState(
|
|
38
|
-
EditorState.createWithContent(contentState)
|
|
39
|
-
);
|
|
40
|
-
let onEditorStateChange = (editorState) => {
|
|
41
|
-
let newData = draftToHtml(convertToRaw(editorState.getCurrentContent()));
|
|
42
|
-
console.log("Text Length " + newData.length);
|
|
43
|
-
if (newData.length > maxLength) {
|
|
44
|
-
let contentState = stateFromHTML(
|
|
45
|
-
newData.substring(0, maxLength),
|
|
46
|
-
options
|
|
47
|
-
);
|
|
48
|
-
setEditorState(EditorState.createWithContent(contentState));
|
|
49
|
-
return;
|
|
50
|
-
} else {
|
|
51
|
-
setEditorState(editorState);
|
|
52
|
-
}
|
|
53
|
-
setValue(draftToHtml(convertToRaw(editorState.getCurrentContent())));
|
|
54
|
-
};
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
if (value != draftToHtml(convertToRaw(editorState.getCurrentContent()))) {
|
|
57
|
-
setEditorState(
|
|
58
|
-
EditorState.createWithContent(stateFromHTML(value, options))
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
}, [value]);
|
|
62
|
-
const _getLengthOfSelectedText = () => {
|
|
63
|
-
const currentSelection = editorState.getSelection();
|
|
64
|
-
const isCollapsed = currentSelection.isCollapsed();
|
|
65
|
-
|
|
66
|
-
let length = 0;
|
|
67
|
-
|
|
68
|
-
if (!isCollapsed) {
|
|
69
|
-
const currentContent = editorState.getCurrentContent();
|
|
70
|
-
const startKey = currentSelection.getStartKey();
|
|
71
|
-
const endKey = currentSelection.getEndKey();
|
|
72
|
-
const startBlock = currentContent.getBlockForKey(startKey);
|
|
73
|
-
const isStartAndEndBlockAreTheSame = startKey === endKey;
|
|
74
|
-
const startBlockTextLength = startBlock.getLength();
|
|
75
|
-
const startSelectedTextLength =
|
|
76
|
-
startBlockTextLength - currentSelection.getStartOffset();
|
|
77
|
-
const endSelectedTextLength = currentSelection.getEndOffset();
|
|
78
|
-
const keyAfterEnd = currentContent.getKeyAfter(endKey);
|
|
79
|
-
if (isStartAndEndBlockAreTheSame) {
|
|
80
|
-
length +=
|
|
81
|
-
currentSelection.getEndOffset() - currentSelection.getStartOffset();
|
|
82
|
-
} else {
|
|
83
|
-
let currentKey = startKey;
|
|
84
|
-
|
|
85
|
-
while (currentKey && currentKey !== keyAfterEnd) {
|
|
86
|
-
if (currentKey === startKey) {
|
|
87
|
-
length += startSelectedTextLength + 1;
|
|
88
|
-
} else if (currentKey === endKey) {
|
|
89
|
-
length += endSelectedTextLength;
|
|
90
|
-
} else {
|
|
91
|
-
length += currentContent.getBlockForKey(currentKey).getLength() + 1;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
currentKey = currentContent.getKeyAfter(currentKey);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return length;
|
|
100
|
-
};
|
|
101
|
-
return (
|
|
102
|
-
<Paper
|
|
103
|
-
sx={{
|
|
104
|
-
display: "flex",
|
|
105
|
-
flexDirection: "column",
|
|
106
|
-
padding: 1,
|
|
107
|
-
}}
|
|
108
|
-
>
|
|
109
|
-
{label ? <Box>{t(label)}</Box> : <></>}
|
|
110
|
-
<Editor
|
|
111
|
-
editorState={editorState}
|
|
112
|
-
onEditorStateChange={onEditorStateChange}
|
|
113
|
-
handlePastedText={(pastedText) => {
|
|
114
|
-
const currentContent = editorState.getCurrentContent();
|
|
115
|
-
const currentContentLength = currentContent.getPlainText("").length;
|
|
116
|
-
const selectedTextLength = _getLengthOfSelectedText();
|
|
117
|
-
|
|
118
|
-
if (
|
|
119
|
-
currentContentLength + pastedText.length - selectedTextLength >
|
|
120
|
-
maxLength
|
|
121
|
-
) {
|
|
122
|
-
alert("max text length is " + maxLength);
|
|
123
|
-
return "handled";
|
|
124
|
-
}
|
|
125
|
-
}}
|
|
126
|
-
editorStyle={{
|
|
127
|
-
height: "200px", // 👈 set height of content area
|
|
128
|
-
border: "1px solid #F1F1F1",
|
|
129
|
-
padding: "10px",
|
|
130
|
-
overflow: "auto", // scroll if needed
|
|
131
|
-
}}
|
|
132
|
-
wrapperStyle={{ marginBottom: "1rem" }}
|
|
133
|
-
toolbarStyle={{ border: "1px solid #ccc" }}
|
|
134
|
-
/>
|
|
135
|
-
{errorMessage ? (
|
|
136
|
-
<Box sx={{ color: "red" }}>{t(errorMessage)}</Box>
|
|
137
|
-
) : (
|
|
138
|
-
<></>
|
|
139
|
-
)}
|
|
140
|
-
</Paper>
|
|
141
|
-
);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
export default HtmlEditor;
|
package/src/global-shim.ts
DELETED