@truedat/core 6.0.1 → 6.0.3
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truedat/core",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.3",
|
|
4
4
|
"description": "Truedat Web Core",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"jsnext:main": "src/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@testing-library/jest-dom": "^5.16.5",
|
|
36
36
|
"@testing-library/react": "^12.0.0",
|
|
37
37
|
"@testing-library/user-event": "^13.2.1",
|
|
38
|
-
"@truedat/test": "6.0.
|
|
38
|
+
"@truedat/test": "6.0.3",
|
|
39
39
|
"babel-jest": "^28.1.0",
|
|
40
40
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
41
41
|
"babel-plugin-lodash": "^3.3.4",
|
|
@@ -117,5 +117,5 @@
|
|
|
117
117
|
"react-dom": ">= 16.8.6 < 17",
|
|
118
118
|
"semantic-ui-react": ">= 2.0.3 < 2.2"
|
|
119
119
|
},
|
|
120
|
-
"gitHead": "
|
|
120
|
+
"gitHead": "c88ddc501214b8c4e2732654ca0052ebbcc802c9"
|
|
121
121
|
}
|
|
@@ -36,7 +36,10 @@ const structureNoteItems = [
|
|
|
36
36
|
const catalogViewConfigItems = (formatMessage) =>
|
|
37
37
|
_.flow(
|
|
38
38
|
_.map(({ fieldType, fieldName }) => ({
|
|
39
|
-
name: formatMessage({
|
|
39
|
+
name: formatMessage({
|
|
40
|
+
id: `${fieldType}.${fieldName}`,
|
|
41
|
+
defaultMessage: `${fieldType}.${fieldName}`,
|
|
42
|
+
}),
|
|
40
43
|
routes: [
|
|
41
44
|
linkTo.BUCKETS_VIEW({ propertyPath: `${fieldType}.${fieldName}` }),
|
|
42
45
|
],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
|
-
import React from "react";
|
|
2
|
+
import React, { useState, useEffect } from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { isKeyHotkey } from "is-hotkey";
|
|
5
5
|
import isUrl from "is-url";
|
|
@@ -12,10 +12,6 @@ import SafeLink from "./SafeLink";
|
|
|
12
12
|
|
|
13
13
|
const DEFAULT_NODE = "paragraph";
|
|
14
14
|
|
|
15
|
-
const isBoldHotkey = isKeyHotkey("mod+b");
|
|
16
|
-
const isItalicHotkey = isKeyHotkey("mod+i");
|
|
17
|
-
const isUnderlinedHotkey = isKeyHotkey("mod+u");
|
|
18
|
-
|
|
19
15
|
function wrapLink(change, value) {
|
|
20
16
|
const href = validUrl(value);
|
|
21
17
|
if (href) {
|
|
@@ -32,294 +28,153 @@ function unwrapLink(change) {
|
|
|
32
28
|
change.unwrapInline("link");
|
|
33
29
|
}
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
31
|
+
function renderBlock(props, _editor, next) {
|
|
32
|
+
const { attributes, children, node } = props;
|
|
33
|
+
|
|
34
|
+
switch (node.type) {
|
|
35
|
+
// case 'block-quote':
|
|
36
|
+
// return <blockquote {...attributes}>{children}</blockquote>
|
|
37
|
+
case "bulleted-list":
|
|
38
|
+
return <ul {...attributes}>{children}</ul>;
|
|
39
|
+
case "heading-one":
|
|
40
|
+
return (
|
|
41
|
+
<h1 style={{ fontSize: "18px" }} {...attributes}>
|
|
42
|
+
{children}
|
|
43
|
+
</h1>
|
|
44
|
+
);
|
|
45
|
+
case "heading-two":
|
|
46
|
+
return (
|
|
47
|
+
<h2 style={{ fontSize: "15px" }} {...attributes}>
|
|
48
|
+
{children}
|
|
49
|
+
</h2>
|
|
50
|
+
);
|
|
51
|
+
case "list-item":
|
|
52
|
+
return <li {...attributes}>{children}</li>;
|
|
53
|
+
case "numbered-list":
|
|
54
|
+
return <ol {...attributes}> {children}</ol>;
|
|
55
|
+
case "link":
|
|
56
|
+
return (
|
|
57
|
+
<SafeLink href={node.data?.get("href")} {...attributes}>
|
|
58
|
+
{children}
|
|
59
|
+
</SafeLink>
|
|
60
|
+
);
|
|
61
|
+
default:
|
|
62
|
+
return next();
|
|
54
63
|
}
|
|
64
|
+
}
|
|
55
65
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
renderLabel() {
|
|
71
|
-
const { label, required } = this.props;
|
|
72
|
-
if (!label) return null;
|
|
73
|
-
const classname = required ? "required field" : "field";
|
|
74
|
-
return (
|
|
75
|
-
<div className={classname}>
|
|
76
|
-
<label>{label}</label>
|
|
77
|
-
</div>
|
|
78
|
-
);
|
|
66
|
+
function renderMark(props, _editor, next) {
|
|
67
|
+
const { children, mark, attributes } = props;
|
|
68
|
+
|
|
69
|
+
switch (mark.type) {
|
|
70
|
+
case "bold":
|
|
71
|
+
return <strong {...attributes}>{children}</strong>;
|
|
72
|
+
// case 'code':
|
|
73
|
+
// return <code {...attributes}>{children}</code>
|
|
74
|
+
case "italic":
|
|
75
|
+
return <em {...attributes}>{children}</em>;
|
|
76
|
+
case "underlined":
|
|
77
|
+
return <u {...attributes}>{children}</u>;
|
|
78
|
+
default:
|
|
79
|
+
return next();
|
|
79
80
|
}
|
|
81
|
+
}
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
{this.renderMarkButton("italic", "italic")}
|
|
94
|
-
{this.renderMarkButton("underlined", "underline")}
|
|
95
|
-
{/* {this.renderMarkButton('code', 'file code')} */}
|
|
96
|
-
{this.renderBlockButton("heading-one", "header")}
|
|
97
|
-
{this.renderBlockButton("heading-two", "h")}
|
|
98
|
-
{/* {this.renderBlockButton('block-quote', 'quote right')} */}
|
|
99
|
-
{this.renderBlockButton("numbered-list", "list ol")}
|
|
100
|
-
{this.renderBlockButton("bulleted-list", "list ul")}
|
|
101
|
-
{this.renderLinkButton("link", "linkify")}
|
|
102
|
-
</Menu>
|
|
103
|
-
<div style={{ padding: "10px" }}>
|
|
104
|
-
<Editor
|
|
105
|
-
style={{ WebkitUserModify: "read-write !important" }}
|
|
106
|
-
spellCheck
|
|
107
|
-
autoFocus
|
|
108
|
-
value={this.state.value}
|
|
109
|
-
onChange={this.onChange}
|
|
110
|
-
onPaste={this.onPaste}
|
|
111
|
-
onKeyDown={this.onKeyDown}
|
|
112
|
-
renderBlock={this.renderBlock}
|
|
113
|
-
renderMark={this.renderMark}
|
|
114
|
-
renderInline={this.renderInline}
|
|
115
|
-
ref={this.ref}
|
|
116
|
-
/>
|
|
117
|
-
</div>
|
|
118
|
-
</div>
|
|
119
|
-
</div>
|
|
120
|
-
);
|
|
121
|
-
}
|
|
83
|
+
function renderInline(props, _editor, next) {
|
|
84
|
+
const { attributes, children, node } = props;
|
|
85
|
+
|
|
86
|
+
switch (node.type) {
|
|
87
|
+
case "link": {
|
|
88
|
+
const props = _.omit(["ref"])(attributes);
|
|
89
|
+
return (
|
|
90
|
+
<SafeLink href={node.data?.get("href")} {...props}>
|
|
91
|
+
{children}
|
|
92
|
+
</SafeLink>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
122
95
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
<div>
|
|
126
|
-
<Editor
|
|
127
|
-
readOnly
|
|
128
|
-
value={this.state.value}
|
|
129
|
-
renderBlock={this.renderBlock}
|
|
130
|
-
renderMark={this.renderMark}
|
|
131
|
-
renderInline={this.renderInline}
|
|
132
|
-
/>
|
|
133
|
-
</div>
|
|
134
|
-
);
|
|
96
|
+
default:
|
|
97
|
+
return next();
|
|
135
98
|
}
|
|
99
|
+
}
|
|
136
100
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
101
|
+
function onKeyDown(event, editor, next) {
|
|
102
|
+
const isBoldHotkey = isKeyHotkey("mod+b");
|
|
103
|
+
const isItalicHotkey = isKeyHotkey("mod+i");
|
|
104
|
+
const isUnderlinedHotkey = isKeyHotkey("mod+u");
|
|
105
|
+
const mark = isBoldHotkey(event)
|
|
106
|
+
? "bold"
|
|
107
|
+
: isItalicHotkey(event)
|
|
108
|
+
? "italic"
|
|
109
|
+
: isUnderlinedHotkey(event)
|
|
110
|
+
? "underlined"
|
|
111
|
+
: undefined;
|
|
112
|
+
if (!_.isNil(mark)) {
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
editor.toggleMark(mark);
|
|
115
|
+
return true;
|
|
116
|
+
} else {
|
|
117
|
+
next();
|
|
144
118
|
}
|
|
119
|
+
}
|
|
145
120
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
);
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
renderBlockButton = (type, icon) => {
|
|
161
|
-
const {
|
|
162
|
-
value: { document, blocks },
|
|
163
|
-
} = this.state;
|
|
164
|
-
const parent =
|
|
165
|
-
blocks.size != 0 ? document.getParent(blocks.first().key) : null;
|
|
166
|
-
const isActive = _.includes(type)(["numbered-list", "bulleted-list"])
|
|
167
|
-
? this.hasBlock("list-item") && parent && parent.type === type
|
|
168
|
-
: this.hasBlock(type);
|
|
121
|
+
const EMPTY_VALUE = {
|
|
122
|
+
document: {
|
|
123
|
+
nodes: [
|
|
124
|
+
{
|
|
125
|
+
object: "block",
|
|
126
|
+
type: "paragraph",
|
|
127
|
+
nodes: [],
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
};
|
|
169
132
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
133
|
+
export const RichTextEditor = ({
|
|
134
|
+
readOnly,
|
|
135
|
+
value: propValue,
|
|
136
|
+
label,
|
|
137
|
+
required,
|
|
138
|
+
onChange,
|
|
139
|
+
name,
|
|
140
|
+
}) => {
|
|
141
|
+
const [jsonValue, setJsonValue] = useState(propValue || EMPTY_VALUE);
|
|
142
|
+
const [value, setValue] = useState(Value.fromJSON(jsonValue));
|
|
143
|
+
const [editor, setEditor] = useState();
|
|
144
|
+
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (!_.equals(propValue)(jsonValue)) {
|
|
147
|
+
setValue(Value.fromJSON(propValue));
|
|
148
|
+
}
|
|
149
|
+
}, [propValue]);
|
|
180
150
|
|
|
181
|
-
|
|
182
|
-
const isActive =
|
|
151
|
+
const renderMarkButton = (type, icon) => {
|
|
152
|
+
const isActive = value?.activeMarks.some((mark) => mark.type == type);
|
|
183
153
|
|
|
184
154
|
return (
|
|
185
155
|
<Menu.Item
|
|
186
156
|
icon
|
|
187
|
-
|
|
188
|
-
onMouseDown={(
|
|
157
|
+
active={isActive}
|
|
158
|
+
onMouseDown={(e) => {
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
editor?.toggleMark(type);
|
|
161
|
+
}}
|
|
162
|
+
onClick={() => {}}
|
|
189
163
|
>
|
|
190
164
|
<Icon name={icon} />
|
|
191
165
|
</Menu.Item>
|
|
192
166
|
);
|
|
193
167
|
};
|
|
194
168
|
|
|
195
|
-
|
|
196
|
-
const { attributes, children, node } = props;
|
|
197
|
-
|
|
198
|
-
switch (node.type) {
|
|
199
|
-
// case 'block-quote':
|
|
200
|
-
// return <blockquote {...attributes}>{children}</blockquote>
|
|
201
|
-
case "bulleted-list":
|
|
202
|
-
return <ul {...attributes}>{children}</ul>;
|
|
203
|
-
case "heading-one":
|
|
204
|
-
return (
|
|
205
|
-
<h1 style={{ fontSize: "18px" }} {...attributes}>
|
|
206
|
-
{children}
|
|
207
|
-
</h1>
|
|
208
|
-
);
|
|
209
|
-
case "heading-two":
|
|
210
|
-
return (
|
|
211
|
-
<h2 style={{ fontSize: "15px" }} {...attributes}>
|
|
212
|
-
{children}
|
|
213
|
-
</h2>
|
|
214
|
-
);
|
|
215
|
-
case "list-item":
|
|
216
|
-
return <li {...attributes}>{children}</li>;
|
|
217
|
-
case "numbered-list":
|
|
218
|
-
return <ol {...attributes}> {children}</ol>;
|
|
219
|
-
case "link":
|
|
220
|
-
return (
|
|
221
|
-
<SafeLink href={node.data?.get("href")} {...attributes}>
|
|
222
|
-
{children}
|
|
223
|
-
</SafeLink>
|
|
224
|
-
);
|
|
225
|
-
default:
|
|
226
|
-
return next();
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
renderMark = (props, editor, next) => {
|
|
231
|
-
const { children, mark, attributes } = props;
|
|
232
|
-
|
|
233
|
-
switch (mark.type) {
|
|
234
|
-
case "bold":
|
|
235
|
-
return <strong {...attributes}>{children}</strong>;
|
|
236
|
-
// case 'code':
|
|
237
|
-
// return <code {...attributes}>{children}</code>
|
|
238
|
-
case "italic":
|
|
239
|
-
return <em {...attributes}>{children}</em>;
|
|
240
|
-
case "underlined":
|
|
241
|
-
return <u {...attributes}>{children}</u>;
|
|
242
|
-
default:
|
|
243
|
-
return next();
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
renderInline = (props, editor, next) => {
|
|
248
|
-
const { attributes, children, node } = props;
|
|
249
|
-
|
|
250
|
-
switch (node.type) {
|
|
251
|
-
case "link": {
|
|
252
|
-
const props = _.omit(["ref"])(attributes);
|
|
253
|
-
return (
|
|
254
|
-
<SafeLink href={node.data?.get("href")} {...props}>
|
|
255
|
-
{children}
|
|
256
|
-
</SafeLink>
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
default:
|
|
261
|
-
return next();
|
|
262
|
-
}
|
|
263
|
-
};
|
|
169
|
+
const hasBlock = (type) => value?.blocks.some((node) => node.type == type);
|
|
264
170
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const {
|
|
268
|
-
if (onChange) {
|
|
269
|
-
const { text } = value.document;
|
|
270
|
-
const json = text ? value.toJSON() : {};
|
|
271
|
-
const event = undefined; // the onChange handler expects an event as the first argument
|
|
272
|
-
onChange(event, { name, value: json });
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
onKeyDown = (event, editor, next) => {
|
|
277
|
-
const mark = isBoldHotkey(event)
|
|
278
|
-
? "bold"
|
|
279
|
-
: isItalicHotkey(event)
|
|
280
|
-
? "italic"
|
|
281
|
-
: isUnderlinedHotkey(event)
|
|
282
|
-
? "underlined"
|
|
283
|
-
: undefined;
|
|
284
|
-
if (!_.isNil(mark)) {
|
|
285
|
-
event.preventDefault();
|
|
286
|
-
editor.toggleMark(mark);
|
|
287
|
-
return true;
|
|
288
|
-
} else {
|
|
289
|
-
next();
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
onPaste = (event, editor, next) => {
|
|
294
|
-
if (editor.value.selection.isCollapsed) return next();
|
|
295
|
-
|
|
296
|
-
const transfer = getEventTransfer(event);
|
|
297
|
-
const { type, text } = transfer;
|
|
298
|
-
if (type !== "text" && type !== "html") return next();
|
|
299
|
-
if (!isUrl(text)) return next();
|
|
300
|
-
|
|
301
|
-
if (this.hasLinks()) {
|
|
302
|
-
editor.command(unwrapLink);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
editor.command(wrapLink, text);
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
onClickMark = (event, type) => {
|
|
309
|
-
event.preventDefault();
|
|
310
|
-
this.editor.toggleMark(type);
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
onClickBlock = (event, type) => {
|
|
314
|
-
event.preventDefault();
|
|
315
|
-
|
|
316
|
-
const { editor } = this;
|
|
317
|
-
const { value } = editor;
|
|
318
|
-
const { document } = value;
|
|
171
|
+
const onClickBlock = (type) => {
|
|
172
|
+
const { value } = editor || {};
|
|
173
|
+
const { document } = value || {};
|
|
319
174
|
|
|
320
175
|
if (type != "bulleted-list" && type != "numbered-list") {
|
|
321
|
-
const isActive =
|
|
322
|
-
const isList =
|
|
176
|
+
const isActive = hasBlock(type);
|
|
177
|
+
const isList = hasBlock("list-item");
|
|
323
178
|
|
|
324
179
|
if (isList) {
|
|
325
180
|
editor
|
|
@@ -330,9 +185,9 @@ export class RichTextEditor extends React.Component {
|
|
|
330
185
|
editor.setBlocks(isActive ? DEFAULT_NODE : type);
|
|
331
186
|
}
|
|
332
187
|
} else {
|
|
333
|
-
const isList =
|
|
334
|
-
const isType = value
|
|
335
|
-
return !!document
|
|
188
|
+
const isList = hasBlock("list-item");
|
|
189
|
+
const isType = value?.blocks.some((block) => {
|
|
190
|
+
return !!document?.getClosest(
|
|
336
191
|
block.key,
|
|
337
192
|
(parent) => parent.type == type
|
|
338
193
|
);
|
|
@@ -355,22 +210,37 @@ export class RichTextEditor extends React.Component {
|
|
|
355
210
|
}
|
|
356
211
|
};
|
|
357
212
|
|
|
358
|
-
|
|
359
|
-
const {
|
|
360
|
-
|
|
361
|
-
|
|
213
|
+
const renderBlockButton = (type, icon) => {
|
|
214
|
+
const { document, blocks } = value || {};
|
|
215
|
+
const parent =
|
|
216
|
+
blocks?.size != 0 ? document?.getParent(blocks?.first().key) : null;
|
|
217
|
+
const isActive = _.includes(type)(["numbered-list", "bulleted-list"])
|
|
218
|
+
? hasBlock("list-item") && parent && parent?.type === type
|
|
219
|
+
: hasBlock(type);
|
|
362
220
|
|
|
363
|
-
|
|
364
|
-
|
|
221
|
+
return (
|
|
222
|
+
<Menu.Item
|
|
223
|
+
icon
|
|
224
|
+
active={isActive}
|
|
225
|
+
onMouseDown={(e) => {
|
|
226
|
+
e.preventDefault();
|
|
227
|
+
onClickBlock(type);
|
|
228
|
+
}}
|
|
229
|
+
onClick={() => {}}
|
|
230
|
+
>
|
|
231
|
+
<Icon name={icon} />
|
|
232
|
+
</Menu.Item>
|
|
233
|
+
);
|
|
234
|
+
};
|
|
365
235
|
|
|
366
|
-
|
|
367
|
-
const { value } = editor;
|
|
236
|
+
const hasLinks = () => value?.inlines.some((inline) => inline.type == "link");
|
|
368
237
|
|
|
369
|
-
|
|
238
|
+
const onClickLink = () => {
|
|
239
|
+
const { value } = editor || {};
|
|
370
240
|
|
|
371
|
-
if (hasLinks) {
|
|
241
|
+
if (hasLinks()) {
|
|
372
242
|
editor.command(unwrapLink);
|
|
373
|
-
} else if (value
|
|
243
|
+
} else if (value?.selection.isExpanded) {
|
|
374
244
|
const href = window.prompt("Introduzca la URL del Link:");
|
|
375
245
|
editor.command(wrapLink, href);
|
|
376
246
|
} else {
|
|
@@ -382,7 +252,102 @@ export class RichTextEditor extends React.Component {
|
|
|
382
252
|
.command(wrapLink, href);
|
|
383
253
|
}
|
|
384
254
|
};
|
|
385
|
-
|
|
255
|
+
|
|
256
|
+
const renderLinkButton = (icon) => {
|
|
257
|
+
const isActive = hasLinks();
|
|
258
|
+
|
|
259
|
+
return (
|
|
260
|
+
<Menu.Item
|
|
261
|
+
icon
|
|
262
|
+
active={isActive}
|
|
263
|
+
onMouseDown={(e) => {
|
|
264
|
+
e.preventDefault();
|
|
265
|
+
onClickLink();
|
|
266
|
+
}}
|
|
267
|
+
onClick={() => {}}
|
|
268
|
+
>
|
|
269
|
+
<Icon name={icon} />
|
|
270
|
+
</Menu.Item>
|
|
271
|
+
);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const handleChange = ({ value }) => {
|
|
275
|
+
const { text } = value?.document || {};
|
|
276
|
+
const json = text ? value?.toJSON() : {};
|
|
277
|
+
setJsonValue(json);
|
|
278
|
+
setValue(value);
|
|
279
|
+
if (onChange) {
|
|
280
|
+
onChange(undefined, { name, value: json });
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const onPaste = (event, editor, next) => {
|
|
285
|
+
if (editor?.value?.selection?.isCollapsed) return next();
|
|
286
|
+
|
|
287
|
+
const transfer = getEventTransfer(event);
|
|
288
|
+
const { type, text } = transfer;
|
|
289
|
+
if (type !== "text" && type !== "html") return next();
|
|
290
|
+
if (!isUrl(text)) return next();
|
|
291
|
+
|
|
292
|
+
if (hasLinks()) {
|
|
293
|
+
editor.command(unwrapLink);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
editor.command(wrapLink, text);
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
return readOnly ? (
|
|
300
|
+
<Editor
|
|
301
|
+
readOnly
|
|
302
|
+
value={value}
|
|
303
|
+
renderBlock={renderBlock}
|
|
304
|
+
renderMark={renderMark}
|
|
305
|
+
renderInline={renderInline}
|
|
306
|
+
/>
|
|
307
|
+
) : (
|
|
308
|
+
<div>
|
|
309
|
+
{label ? (
|
|
310
|
+
<div className={required ? "required field" : "field"}>
|
|
311
|
+
<label>{label}</label>
|
|
312
|
+
</div>
|
|
313
|
+
) : null}
|
|
314
|
+
<div
|
|
315
|
+
style={{
|
|
316
|
+
border: "1px solid rgba(34, 36, 38, 0.15)",
|
|
317
|
+
borderRadius: "0.28571429rem",
|
|
318
|
+
}}
|
|
319
|
+
>
|
|
320
|
+
<Menu>
|
|
321
|
+
{renderMarkButton("bold", "bold")}
|
|
322
|
+
{renderMarkButton("italic", "italic")}
|
|
323
|
+
{renderMarkButton("underlined", "underline")}
|
|
324
|
+
{/* {renderMarkButton('code', 'file code')} */}
|
|
325
|
+
{renderBlockButton("heading-one", "header")}
|
|
326
|
+
{renderBlockButton("heading-two", "h")}
|
|
327
|
+
{/* {renderBlockButton('block-quote', 'quote right')} */}
|
|
328
|
+
{renderBlockButton("numbered-list", "list ol")}
|
|
329
|
+
{renderBlockButton("bulleted-list", "list ul")}
|
|
330
|
+
{renderLinkButton("linkify")}
|
|
331
|
+
</Menu>
|
|
332
|
+
<div style={{ padding: "10px" }}>
|
|
333
|
+
<Editor
|
|
334
|
+
style={{ WebkitUserModify: "read-write !important" }}
|
|
335
|
+
spellCheck
|
|
336
|
+
autoFocus
|
|
337
|
+
value={value}
|
|
338
|
+
onChange={handleChange}
|
|
339
|
+
onPaste={onPaste}
|
|
340
|
+
onKeyDown={onKeyDown}
|
|
341
|
+
renderBlock={renderBlock}
|
|
342
|
+
renderMark={renderMark}
|
|
343
|
+
renderInline={renderInline}
|
|
344
|
+
ref={setEditor}
|
|
345
|
+
/>
|
|
346
|
+
</div>
|
|
347
|
+
</div>
|
|
348
|
+
</div>
|
|
349
|
+
);
|
|
350
|
+
};
|
|
386
351
|
|
|
387
352
|
RichTextEditor.propTypes = {
|
|
388
353
|
label: PropTypes.string,
|
|
@@ -27,6 +27,7 @@ export const TemplateSelector = ({
|
|
|
27
27
|
templates,
|
|
28
28
|
placeholder,
|
|
29
29
|
hideLabel = false,
|
|
30
|
+
disabled,
|
|
30
31
|
}) => {
|
|
31
32
|
const { formatMessage } = useIntl();
|
|
32
33
|
const options = makeOptions(formatMessage)(templates);
|
|
@@ -50,6 +51,7 @@ export const TemplateSelector = ({
|
|
|
50
51
|
</label>
|
|
51
52
|
)}
|
|
52
53
|
<Form.Dropdown
|
|
54
|
+
disabled={disabled}
|
|
53
55
|
clearable={clearable}
|
|
54
56
|
loading={loading}
|
|
55
57
|
name={name}
|
|
@@ -80,6 +82,7 @@ TemplateSelector.propTypes = {
|
|
|
80
82
|
templates: PropTypes.array,
|
|
81
83
|
placeholder: PropTypes.string,
|
|
82
84
|
hideLabel: PropTypes.bool,
|
|
85
|
+
disabled: PropTypes.bool,
|
|
83
86
|
};
|
|
84
87
|
|
|
85
88
|
const emptyTemplates = [];
|
package/src/services/format.js
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
1
|
export const formatNumber = (value) => value?.toLocaleString();
|
|
2
|
+
|
|
3
|
+
export const toEnrichedTextFormat = (value) => ({
|
|
4
|
+
object: "value",
|
|
5
|
+
document: {
|
|
6
|
+
object: "document",
|
|
7
|
+
data: {},
|
|
8
|
+
nodes: [
|
|
9
|
+
{
|
|
10
|
+
object: "block",
|
|
11
|
+
type: "paragraph",
|
|
12
|
+
data: {},
|
|
13
|
+
nodes: [
|
|
14
|
+
{
|
|
15
|
+
object: "text",
|
|
16
|
+
text: value,
|
|
17
|
+
marks: [],
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
});
|