@entur-partner/rich-text-editor 6.2.3 → 6.2.4-alpha.1
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/ExpandableMultiLanguageRichTextEditor.d.ts +21 -21
- package/dist/index.d.ts +5 -5
- package/dist/rich-text-editor.cjs.development.js +313 -330
- package/dist/rich-text-editor.cjs.development.js.map +1 -1
- package/dist/rich-text-editor.cjs.production.min.js +1 -1
- package/dist/rich-text-editor.cjs.production.min.js.map +1 -1
- package/dist/rich-text-editor.esm.js +247 -257
- package/dist/rich-text-editor.esm.js.map +1 -1
- package/dist/styles.css +14 -14
- package/package.json +60 -60
- package/dist/RichTextEditor/BlockTypeDropdown/index.d.ts +0 -3
- package/dist/RichTextEditor/Controls/BlockTypeButtonControls.d.ts +0 -3
- package/dist/RichTextEditor/Controls/BlockTypeLinkControls.d.ts +0 -3
- package/dist/RichTextEditor/Controls/BlockTypeSelectControls.d.ts +0 -7
- package/dist/RichTextEditor/Controls/InlineStyleControls.d.ts +0 -3
- package/dist/RichTextEditor/Controls/TagControls.d.ts +0 -3
- package/dist/RichTextEditor/Link/index.d.ts +0 -8
- package/dist/RichTextEditor/StyleButton/index.d.ts +0 -3
- package/dist/RichTextEditor/constants.d.ts +0 -94
- package/dist/RichTextEditor/htmlConvertion.d.ts +0 -9
- package/dist/RichTextEditor/index.d.ts +0 -58
- package/dist/RichTextEditor/markdownConvertion.d.ts +0 -4
- package/dist/events.d.ts +0 -4
- package/dist/withI18n.d.ts +0 -2
|
@@ -1,66 +1,61 @@
|
|
|
1
|
+
import { ExpandablePanel } from '@entur/expand';
|
|
2
|
+
import { TextField, FeedbackText } from '@entur/form';
|
|
3
|
+
import { Unbutton, Stack } from '@entur-partner/common';
|
|
1
4
|
import React, { Component, createRef, useState } from 'react';
|
|
5
|
+
import { Label } from '@entur/typography';
|
|
6
|
+
import cx from 'classnames';
|
|
2
7
|
import { EditorState, CompositeDecorator, Editor, RichUtils, getDefaultKeyBinding, Modifier, convertToRaw, convertFromRaw } from 'draft-js';
|
|
3
8
|
import PropTypes from 'prop-types';
|
|
4
|
-
import cx from 'classnames';
|
|
5
|
-
import { Label } from '@entur/typography';
|
|
6
|
-
import { Dropdown } from '@entur/dropdown';
|
|
7
9
|
import { useTranslation } from 'react-i18next';
|
|
8
|
-
import { TextField, FeedbackText } from '@entur/form';
|
|
9
|
-
import { LinkIcon, CloseIcon, CheckIcon, UnlinkIcon, DownArrowIcon, BulletListIcon, NumberListIcon, BoldIcon, ItalicIcon, UnderlineIcon } from '@entur/icons';
|
|
10
|
-
import { Unbutton, Stack } from '@entur-partner/common';
|
|
11
10
|
import { SecondarySquareButton } from '@entur/button';
|
|
12
|
-
import {
|
|
11
|
+
import { LinkIcon, CloseIcon, CheckIcon, UnlinkIcon, DownArrowIcon, BulletListIcon, NumberListIcon, BoldIcon, ItalicIcon, UnderlineIcon } from '@entur/icons';
|
|
12
|
+
import { Dropdown } from '@entur/dropdown';
|
|
13
13
|
import { OverflowMenuItem, OverflowMenu } from '@entur/menu';
|
|
14
|
-
import {
|
|
14
|
+
import { Popover } from '@entur/tooltip';
|
|
15
15
|
import { draftToMarkdown, markdownToDraft } from 'markdown-draft-js';
|
|
16
16
|
import showdown from 'showdown';
|
|
17
17
|
import { convertFromHTML, convertToHTML } from 'draft-convert';
|
|
18
18
|
|
|
19
19
|
function _extends() {
|
|
20
|
-
_extends = Object.assign ? Object.assign.bind() : function (
|
|
21
|
-
for (var
|
|
22
|
-
var
|
|
23
|
-
for (var
|
|
24
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
25
|
-
target[key] = source[key];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
20
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
21
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
22
|
+
var t = arguments[e];
|
|
23
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
28
24
|
}
|
|
29
|
-
return
|
|
30
|
-
};
|
|
31
|
-
return _extends.apply(this, arguments);
|
|
32
|
-
}
|
|
33
|
-
function _inheritsLoose(subClass, superClass) {
|
|
34
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
35
|
-
subClass.prototype.constructor = subClass;
|
|
36
|
-
_setPrototypeOf(subClass, superClass);
|
|
25
|
+
return n;
|
|
26
|
+
}, _extends.apply(null, arguments);
|
|
37
27
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
o.__proto__ = p;
|
|
41
|
-
return o;
|
|
42
|
-
};
|
|
43
|
-
return _setPrototypeOf(o, p);
|
|
28
|
+
function _inheritsLoose(t, o) {
|
|
29
|
+
t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
|
|
44
30
|
}
|
|
45
|
-
function _objectWithoutPropertiesLoose(
|
|
46
|
-
if (
|
|
47
|
-
var
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
key = sourceKeys[i];
|
|
52
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
53
|
-
target[key] = source[key];
|
|
31
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
32
|
+
if (null == r) return {};
|
|
33
|
+
var t = {};
|
|
34
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
35
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
36
|
+
t[n] = r[n];
|
|
54
37
|
}
|
|
55
|
-
return
|
|
38
|
+
return t;
|
|
39
|
+
}
|
|
40
|
+
function _setPrototypeOf(t, e) {
|
|
41
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
42
|
+
return t.__proto__ = e, t;
|
|
43
|
+
}, _setPrototypeOf(t, e);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var Key = /*#__PURE__*/Object.freeze({
|
|
47
|
+
ENTER: 13
|
|
48
|
+
});
|
|
49
|
+
function getKey(event) {
|
|
50
|
+
return event.keyCode || event.which;
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
function useI18N() {
|
|
59
54
|
var _useTranslation = useTranslation(),
|
|
60
55
|
t = _useTranslation.t,
|
|
61
56
|
language = _useTranslation.i18n.language;
|
|
62
|
-
if (language !==
|
|
63
|
-
throw Error(
|
|
57
|
+
if (language !== "nb" && language !== "en" && language !== "nb-NO" && language !== "en-GB") {
|
|
58
|
+
throw Error("Language must be either nb or en.");
|
|
64
59
|
}
|
|
65
60
|
return t;
|
|
66
61
|
}
|
|
@@ -73,107 +68,6 @@ function withI18n(Component) {
|
|
|
73
68
|
};
|
|
74
69
|
}
|
|
75
70
|
|
|
76
|
-
var BlockTypeDropdown = /*#__PURE__*/function (_Component) {
|
|
77
|
-
function BlockTypeDropdown() {
|
|
78
|
-
var _this;
|
|
79
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
80
|
-
args[_key] = arguments[_key];
|
|
81
|
-
}
|
|
82
|
-
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
|
|
83
|
-
_this.handleOnClick = function (selectedOption) {
|
|
84
|
-
var onChange = _this.props.onChange;
|
|
85
|
-
onChange(selectedOption);
|
|
86
|
-
};
|
|
87
|
-
return _this;
|
|
88
|
-
}
|
|
89
|
-
_inheritsLoose(BlockTypeDropdown, _Component);
|
|
90
|
-
var _proto = BlockTypeDropdown.prototype;
|
|
91
|
-
_proto.toItem = function toItem(option) {
|
|
92
|
-
return {
|
|
93
|
-
value: option.style,
|
|
94
|
-
label: this.renderFormattedLabel(option.label)
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
_proto.renderFormattedLabel = function renderFormattedLabel(label) {
|
|
98
|
-
var formattedLabelText = this.props.i18n(label);
|
|
99
|
-
switch (label) {
|
|
100
|
-
case 'styles.p':
|
|
101
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
102
|
-
className: "default-p"
|
|
103
|
-
}, formattedLabelText);
|
|
104
|
-
case 'styles.h1':
|
|
105
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
106
|
-
className: "default-h1"
|
|
107
|
-
}, formattedLabelText);
|
|
108
|
-
case 'styles.h2':
|
|
109
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
110
|
-
className: "default-h2"
|
|
111
|
-
}, formattedLabelText);
|
|
112
|
-
case 'styles.h3':
|
|
113
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
114
|
-
className: "default-h3"
|
|
115
|
-
}, formattedLabelText);
|
|
116
|
-
case 'styles.h4':
|
|
117
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
118
|
-
className: "default-h4"
|
|
119
|
-
}, formattedLabelText);
|
|
120
|
-
case 'styles.h5':
|
|
121
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
122
|
-
className: "default-h5"
|
|
123
|
-
}, formattedLabelText);
|
|
124
|
-
case 'styles.h6':
|
|
125
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
126
|
-
className: "default-h6"
|
|
127
|
-
}, formattedLabelText);
|
|
128
|
-
default:
|
|
129
|
-
return /*#__PURE__*/React.createElement("p", null, formattedLabelText);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
_proto.render = function render() {
|
|
133
|
-
var _this2 = this;
|
|
134
|
-
var _this$props = this.props,
|
|
135
|
-
options = _this$props.options,
|
|
136
|
-
selected = _this$props.selected,
|
|
137
|
-
i18n = _this$props.i18n;
|
|
138
|
-
return /*#__PURE__*/React.createElement(Dropdown, {
|
|
139
|
-
className: "block-type-dropdown",
|
|
140
|
-
items: options.map(function (option) {
|
|
141
|
-
return _this2.toItem(option);
|
|
142
|
-
}),
|
|
143
|
-
selectedItem: this.toItem(selected),
|
|
144
|
-
label: i18n('styles.style'),
|
|
145
|
-
onChange: function onChange(selectedItem) {
|
|
146
|
-
return _this2.handleOnClick(selectedItem.value);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
return BlockTypeDropdown;
|
|
151
|
-
}(Component);
|
|
152
|
-
var BlockTypeDropdown$1 = /*#__PURE__*/withI18n(BlockTypeDropdown);
|
|
153
|
-
|
|
154
|
-
var BlockTypeControls = function BlockTypeControls(_ref) {
|
|
155
|
-
var editorState = _ref.editorState,
|
|
156
|
-
blockTypes = _ref.blockTypes,
|
|
157
|
-
onToggle = _ref.onToggle;
|
|
158
|
-
var selection = editorState.getSelection();
|
|
159
|
-
var blockTypeStyle = editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
|
|
160
|
-
var selectedOption = blockTypes.find(function (option) {
|
|
161
|
-
return option.style === blockTypeStyle;
|
|
162
|
-
}) || blockTypes[0];
|
|
163
|
-
return /*#__PURE__*/React.createElement(BlockTypeDropdown$1, {
|
|
164
|
-
options: blockTypes,
|
|
165
|
-
selected: selectedOption,
|
|
166
|
-
onChange: onToggle
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
var Key = /*#__PURE__*/Object.freeze({
|
|
171
|
-
ENTER: 13
|
|
172
|
-
});
|
|
173
|
-
function getKey(event) {
|
|
174
|
-
return event.keyCode || event.which;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
71
|
var StyleButton = /*#__PURE__*/function (_Component) {
|
|
178
72
|
function StyleButton() {
|
|
179
73
|
var _this;
|
|
@@ -206,20 +100,26 @@ var StyleButton = /*#__PURE__*/function (_Component) {
|
|
|
206
100
|
label = _this$props3.label,
|
|
207
101
|
title = _this$props3.title,
|
|
208
102
|
hotKey = _this$props3.hotKey;
|
|
209
|
-
var classNames = cx(
|
|
103
|
+
var classNames = cx("editor-stylebutton", {
|
|
210
104
|
active: active
|
|
211
105
|
});
|
|
212
|
-
return
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
106
|
+
return (
|
|
107
|
+
/*#__PURE__*/
|
|
108
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: Ignore for now.
|
|
109
|
+
React.createElement("div", {
|
|
110
|
+
className: classNames,
|
|
111
|
+
onMouseDown: this.onToggle,
|
|
112
|
+
title: i18n(title) + hotKey
|
|
113
|
+
// biome-ignore lint/a11y/noNoninteractiveTabindex: Ignore for now.
|
|
114
|
+
,
|
|
115
|
+
tabIndex: 0,
|
|
116
|
+
onKeyPress: function onKeyPress(event) {
|
|
117
|
+
if (getKey(event) === Key.ENTER) {
|
|
118
|
+
_this2.onToggleNoEvent();
|
|
119
|
+
}
|
|
220
120
|
}
|
|
221
|
-
}
|
|
222
|
-
|
|
121
|
+
}, label)
|
|
122
|
+
);
|
|
223
123
|
};
|
|
224
124
|
return StyleButton;
|
|
225
125
|
}(Component);
|
|
@@ -233,9 +133,9 @@ var BlockTypeButtonControls = function BlockTypeButtonControls(props) {
|
|
|
233
133
|
var blockTypeStyle = editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
|
|
234
134
|
return /*#__PURE__*/React.createElement("div", {
|
|
235
135
|
className: "controls-group block-editor-controls"
|
|
236
|
-
}, blockTypes.map(function (type
|
|
136
|
+
}, blockTypes.map(function (type) {
|
|
237
137
|
return /*#__PURE__*/React.createElement(StyleButton$1, {
|
|
238
|
-
key:
|
|
138
|
+
key: type.style + type.label,
|
|
239
139
|
active: type.style === blockTypeStyle,
|
|
240
140
|
label: type.label,
|
|
241
141
|
onToggle: onToggle,
|
|
@@ -253,7 +153,7 @@ var BlockTypeLinkControls = /*#__PURE__*/function (_Component) {
|
|
|
253
153
|
}
|
|
254
154
|
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
|
|
255
155
|
_this.state = {
|
|
256
|
-
urlValue:
|
|
156
|
+
urlValue: "",
|
|
257
157
|
showUrlInput: false,
|
|
258
158
|
hasLink: false
|
|
259
159
|
};
|
|
@@ -272,7 +172,7 @@ var BlockTypeLinkControls = /*#__PURE__*/function (_Component) {
|
|
|
272
172
|
var startOffset = selection.getStartOffset();
|
|
273
173
|
var blockWithLinkAtBeginning = currentContent.getBlockForKey(startKey);
|
|
274
174
|
var linkKey = blockWithLinkAtBeginning.getEntityAt(startOffset);
|
|
275
|
-
var url =
|
|
175
|
+
var url = "";
|
|
276
176
|
if (linkKey) {
|
|
277
177
|
var linkInstance = currentContent.getEntity(linkKey);
|
|
278
178
|
url = linkInstance.getData().url;
|
|
@@ -291,7 +191,7 @@ var BlockTypeLinkControls = /*#__PURE__*/function (_Component) {
|
|
|
291
191
|
editorState = _this$props.editorState,
|
|
292
192
|
onToggle = _this$props.onToggle;
|
|
293
193
|
var contentState = editorState.getCurrentContent();
|
|
294
|
-
var contentStateWithEntity = contentState.createEntity(
|
|
194
|
+
var contentStateWithEntity = contentState.createEntity("LINK", "MUTABLE", {
|
|
295
195
|
url: urlValue
|
|
296
196
|
});
|
|
297
197
|
var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
@@ -301,14 +201,14 @@ var BlockTypeLinkControls = /*#__PURE__*/function (_Component) {
|
|
|
301
201
|
onToggle(newEditorState, entityKey);
|
|
302
202
|
_this.setState({
|
|
303
203
|
showUrlInput: false,
|
|
304
|
-
urlValue:
|
|
204
|
+
urlValue: ""
|
|
305
205
|
});
|
|
306
206
|
};
|
|
307
207
|
_this.cancelLink = function (e) {
|
|
308
208
|
e.preventDefault();
|
|
309
209
|
_this.setState({
|
|
310
210
|
showUrlInput: false,
|
|
311
|
-
urlValue:
|
|
211
|
+
urlValue: ""
|
|
312
212
|
});
|
|
313
213
|
};
|
|
314
214
|
_this.onLinkInputKeyDown = function (e) {
|
|
@@ -343,7 +243,7 @@ var BlockTypeLinkControls = /*#__PURE__*/function (_Component) {
|
|
|
343
243
|
className: "controls-group block-editor-controls link-controls"
|
|
344
244
|
}, /*#__PURE__*/React.createElement("div", {
|
|
345
245
|
className: "editor-stylebutton",
|
|
346
|
-
title: i18n(
|
|
246
|
+
title: i18n("styles.link"),
|
|
347
247
|
onClick: this.addLink,
|
|
348
248
|
tabIndex: 0
|
|
349
249
|
}, /*#__PURE__*/React.createElement(LinkIcon, null)), showUrlInput && /*#__PURE__*/React.createElement("div", {
|
|
@@ -353,7 +253,7 @@ var BlockTypeLinkControls = /*#__PURE__*/function (_Component) {
|
|
|
353
253
|
onMouseDown: this.cancelLink
|
|
354
254
|
}, /*#__PURE__*/React.createElement(CloseIcon, null)), /*#__PURE__*/React.createElement("div", {
|
|
355
255
|
className: "link-label"
|
|
356
|
-
}, i18n(
|
|
256
|
+
}, i18n("common.from")), /*#__PURE__*/React.createElement("div", {
|
|
357
257
|
className: "url-input-form"
|
|
358
258
|
}, /*#__PURE__*/React.createElement(TextField, {
|
|
359
259
|
style: {
|
|
@@ -373,8 +273,8 @@ var BlockTypeLinkControls = /*#__PURE__*/function (_Component) {
|
|
|
373
273
|
className: "remove-link"
|
|
374
274
|
}, /*#__PURE__*/React.createElement(Unbutton, {
|
|
375
275
|
onClick: this.removeLink,
|
|
376
|
-
title: i18n(
|
|
377
|
-
}, /*#__PURE__*/React.createElement(UnlinkIcon, null), i18n(
|
|
276
|
+
title: i18n("styles.unlink")
|
|
277
|
+
}, /*#__PURE__*/React.createElement(UnlinkIcon, null), i18n("styles.unlink")))));
|
|
378
278
|
};
|
|
379
279
|
return BlockTypeLinkControls;
|
|
380
280
|
}(Component);
|
|
@@ -384,15 +284,109 @@ BlockTypeLinkControls.propTypes = {
|
|
|
384
284
|
};
|
|
385
285
|
var BlockTypeLinkControls$1 = /*#__PURE__*/withI18n(BlockTypeLinkControls);
|
|
386
286
|
|
|
287
|
+
var BlockTypeDropdown = /*#__PURE__*/function (_Component) {
|
|
288
|
+
function BlockTypeDropdown() {
|
|
289
|
+
var _this;
|
|
290
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
291
|
+
args[_key] = arguments[_key];
|
|
292
|
+
}
|
|
293
|
+
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
|
|
294
|
+
_this.handleOnClick = function (selectedOption) {
|
|
295
|
+
var onChange = _this.props.onChange;
|
|
296
|
+
onChange(selectedOption);
|
|
297
|
+
};
|
|
298
|
+
return _this;
|
|
299
|
+
}
|
|
300
|
+
_inheritsLoose(BlockTypeDropdown, _Component);
|
|
301
|
+
var _proto = BlockTypeDropdown.prototype;
|
|
302
|
+
_proto.toItem = function toItem(option) {
|
|
303
|
+
return {
|
|
304
|
+
value: option.style,
|
|
305
|
+
label: this.renderFormattedLabel(option.label)
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
_proto.renderFormattedLabel = function renderFormattedLabel(label) {
|
|
309
|
+
var formattedLabelText = this.props.i18n(label);
|
|
310
|
+
switch (label) {
|
|
311
|
+
case "styles.p":
|
|
312
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
313
|
+
className: "default-p"
|
|
314
|
+
}, formattedLabelText);
|
|
315
|
+
case "styles.h1":
|
|
316
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
317
|
+
className: "default-h1"
|
|
318
|
+
}, formattedLabelText);
|
|
319
|
+
case "styles.h2":
|
|
320
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
321
|
+
className: "default-h2"
|
|
322
|
+
}, formattedLabelText);
|
|
323
|
+
case "styles.h3":
|
|
324
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
325
|
+
className: "default-h3"
|
|
326
|
+
}, formattedLabelText);
|
|
327
|
+
case "styles.h4":
|
|
328
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
329
|
+
className: "default-h4"
|
|
330
|
+
}, formattedLabelText);
|
|
331
|
+
case "styles.h5":
|
|
332
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
333
|
+
className: "default-h5"
|
|
334
|
+
}, formattedLabelText);
|
|
335
|
+
case "styles.h6":
|
|
336
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
337
|
+
className: "default-h6"
|
|
338
|
+
}, formattedLabelText);
|
|
339
|
+
default:
|
|
340
|
+
return /*#__PURE__*/React.createElement("p", null, formattedLabelText);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
_proto.render = function render() {
|
|
344
|
+
var _this2 = this;
|
|
345
|
+
var _this$props = this.props,
|
|
346
|
+
options = _this$props.options,
|
|
347
|
+
selected = _this$props.selected,
|
|
348
|
+
i18n = _this$props.i18n;
|
|
349
|
+
return /*#__PURE__*/React.createElement(Dropdown, {
|
|
350
|
+
className: "block-type-dropdown",
|
|
351
|
+
items: options.map(function (option) {
|
|
352
|
+
return _this2.toItem(option);
|
|
353
|
+
}),
|
|
354
|
+
selectedItem: this.toItem(selected),
|
|
355
|
+
label: i18n("styles.style"),
|
|
356
|
+
onChange: function onChange(selectedItem) {
|
|
357
|
+
return _this2.handleOnClick(selectedItem.value);
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
return BlockTypeDropdown;
|
|
362
|
+
}(Component);
|
|
363
|
+
var BlockTypeDropdown$1 = /*#__PURE__*/withI18n(BlockTypeDropdown);
|
|
364
|
+
|
|
365
|
+
var BlockTypeControls = function BlockTypeControls(_ref) {
|
|
366
|
+
var editorState = _ref.editorState,
|
|
367
|
+
blockTypes = _ref.blockTypes,
|
|
368
|
+
onToggle = _ref.onToggle;
|
|
369
|
+
var selection = editorState.getSelection();
|
|
370
|
+
var blockTypeStyle = editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
|
|
371
|
+
var selectedOption = blockTypes.find(function (option) {
|
|
372
|
+
return option.style === blockTypeStyle;
|
|
373
|
+
}) || blockTypes[0];
|
|
374
|
+
return /*#__PURE__*/React.createElement(BlockTypeDropdown$1, {
|
|
375
|
+
options: blockTypes,
|
|
376
|
+
selected: selectedOption,
|
|
377
|
+
onChange: onToggle
|
|
378
|
+
});
|
|
379
|
+
};
|
|
380
|
+
|
|
387
381
|
var InlineStyleControls = function InlineStyleControls(props) {
|
|
388
382
|
var editorState = props.editorState,
|
|
389
383
|
inlineStyles = props.inlineStyles;
|
|
390
384
|
var currentStyle = editorState.getCurrentInlineStyle();
|
|
391
385
|
return /*#__PURE__*/React.createElement("div", {
|
|
392
386
|
className: "controls-group inline-editor-controls"
|
|
393
|
-
}, inlineStyles.map(function (type
|
|
387
|
+
}, inlineStyles.map(function (type) {
|
|
394
388
|
return /*#__PURE__*/React.createElement(StyleButton$1, {
|
|
395
|
-
key:
|
|
389
|
+
key: type.style + type.label,
|
|
396
390
|
active: currentStyle.has(type.style),
|
|
397
391
|
label: type.label,
|
|
398
392
|
onToggle: props.onToggle,
|
|
@@ -415,7 +409,7 @@ var TagControls = /*#__PURE__*/function (_Component) {
|
|
|
415
409
|
isOpen: false
|
|
416
410
|
};
|
|
417
411
|
_this.handleClickOutside = function (e) {
|
|
418
|
-
if (_this.tagControlRef
|
|
412
|
+
if (_this.tagControlRef.current && !_this.tagControlRef.current.contains(e.target)) {
|
|
419
413
|
_this.setState({
|
|
420
414
|
isOpen: false
|
|
421
415
|
});
|
|
@@ -435,10 +429,10 @@ var TagControls = /*#__PURE__*/function (_Component) {
|
|
|
435
429
|
_inheritsLoose(TagControls, _Component);
|
|
436
430
|
var _proto = TagControls.prototype;
|
|
437
431
|
_proto.componentDidMount = function componentDidMount() {
|
|
438
|
-
document.addEventListener(
|
|
432
|
+
document.addEventListener("mousedown", this.handleClickOutside);
|
|
439
433
|
};
|
|
440
434
|
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
441
|
-
document.removeEventListener(
|
|
435
|
+
document.removeEventListener("mousedown", this.handleClickOutside);
|
|
442
436
|
};
|
|
443
437
|
_proto.render = function render() {
|
|
444
438
|
var _this2 = this;
|
|
@@ -446,12 +440,12 @@ var TagControls = /*#__PURE__*/function (_Component) {
|
|
|
446
440
|
i18n = _this$props2.i18n,
|
|
447
441
|
tags = _this$props2.tags;
|
|
448
442
|
var isOpen = this.state.isOpen;
|
|
449
|
-
var menuItems = tags.map(function (tag
|
|
450
|
-
var delimiter = tag.delimiter ||
|
|
443
|
+
var menuItems = tags.map(function (tag) {
|
|
444
|
+
var delimiter = tag.delimiter || "{}";
|
|
451
445
|
return /*#__PURE__*/React.createElement(OverflowMenuItem, {
|
|
452
|
-
key:
|
|
446
|
+
key: tag.tag,
|
|
453
447
|
className: "tag-control",
|
|
454
|
-
id:
|
|
448
|
+
id: "tag-control-" + tag.tag,
|
|
455
449
|
onClick: function onClick() {
|
|
456
450
|
return _this2.handleTagClick(tag.tag, delimiter);
|
|
457
451
|
}
|
|
@@ -472,7 +466,7 @@ var TagControls = /*#__PURE__*/function (_Component) {
|
|
|
472
466
|
};
|
|
473
467
|
});
|
|
474
468
|
}
|
|
475
|
-
}, i18n(
|
|
469
|
+
}, i18n("common.insert"), /*#__PURE__*/React.createElement(DownArrowIcon, {
|
|
476
470
|
className: "tag-control-chevron",
|
|
477
471
|
inline: true
|
|
478
472
|
})), /*#__PURE__*/React.createElement(Popover, {
|
|
@@ -508,101 +502,101 @@ var Link = function Link(props) {
|
|
|
508
502
|
function findLinkEntities(contentBlock, callback, contentState) {
|
|
509
503
|
contentBlock.findEntityRanges(function (character) {
|
|
510
504
|
var entityKey = character.getEntity();
|
|
511
|
-
return entityKey !== null && contentState.getEntity(entityKey).getType() ===
|
|
505
|
+
return entityKey !== null && contentState.getEntity(entityKey).getType() === "LINK";
|
|
512
506
|
}, callback);
|
|
513
507
|
}
|
|
514
508
|
|
|
515
509
|
var EditorConfigTypes = /*#__PURE__*/Object.freeze({
|
|
516
510
|
FONT_LIST: {
|
|
517
|
-
UNSTYLED:
|
|
518
|
-
HEADER_ONE:
|
|
519
|
-
HEADER_TWO:
|
|
520
|
-
HEADER_THREE:
|
|
521
|
-
HEADER_FOUR:
|
|
522
|
-
HEADER_FIVE:
|
|
523
|
-
HEADER_SIX:
|
|
511
|
+
UNSTYLED: "unstyled",
|
|
512
|
+
HEADER_ONE: "header-one",
|
|
513
|
+
HEADER_TWO: "header-two",
|
|
514
|
+
HEADER_THREE: "header-three",
|
|
515
|
+
HEADER_FOUR: "header-four",
|
|
516
|
+
HEADER_FIVE: "header-five",
|
|
517
|
+
HEADER_SIX: "header-six"
|
|
524
518
|
},
|
|
525
519
|
BLOCK_TYPES: {
|
|
526
|
-
UNORDERED_LIST:
|
|
527
|
-
ORDERED_LIST:
|
|
520
|
+
UNORDERED_LIST: "unordered-list",
|
|
521
|
+
ORDERED_LIST: "ordered-list"
|
|
528
522
|
},
|
|
529
523
|
INLINE_STYLES: {
|
|
530
|
-
BOLD:
|
|
531
|
-
ITALIC:
|
|
532
|
-
UNDERLINE:
|
|
524
|
+
BOLD: "bold",
|
|
525
|
+
ITALIC: "italic",
|
|
526
|
+
UNDERLINE: "underline"
|
|
533
527
|
}
|
|
534
528
|
});
|
|
535
529
|
var FontList = /*#__PURE__*/Object.freeze({
|
|
536
530
|
unstyled: {
|
|
537
|
-
label:
|
|
538
|
-
style:
|
|
531
|
+
label: "styles.p",
|
|
532
|
+
style: "unstyled"
|
|
539
533
|
},
|
|
540
|
-
|
|
541
|
-
label:
|
|
542
|
-
style:
|
|
534
|
+
"header-one": {
|
|
535
|
+
label: "styles.h1",
|
|
536
|
+
style: "header-one"
|
|
543
537
|
},
|
|
544
|
-
|
|
545
|
-
label:
|
|
546
|
-
style:
|
|
538
|
+
"header-two": {
|
|
539
|
+
label: "styles.h2",
|
|
540
|
+
style: "header-two"
|
|
547
541
|
},
|
|
548
|
-
|
|
549
|
-
label:
|
|
550
|
-
style:
|
|
542
|
+
"header-three": {
|
|
543
|
+
label: "styles.h3",
|
|
544
|
+
style: "header-three"
|
|
551
545
|
},
|
|
552
|
-
|
|
553
|
-
label:
|
|
554
|
-
style:
|
|
546
|
+
"header-four": {
|
|
547
|
+
label: "styles.h4",
|
|
548
|
+
style: "header-four"
|
|
555
549
|
},
|
|
556
|
-
|
|
557
|
-
label:
|
|
558
|
-
style:
|
|
550
|
+
"header-five": {
|
|
551
|
+
label: "styles.h5",
|
|
552
|
+
style: "header-five"
|
|
559
553
|
},
|
|
560
|
-
|
|
561
|
-
label:
|
|
562
|
-
style:
|
|
554
|
+
"header-six": {
|
|
555
|
+
label: "styles.h6",
|
|
556
|
+
style: "header-six"
|
|
563
557
|
}
|
|
564
558
|
});
|
|
565
559
|
var BlockTypeList = /*#__PURE__*/Object.freeze({
|
|
566
|
-
|
|
560
|
+
"unordered-list": {
|
|
567
561
|
label: /*#__PURE__*/React.createElement(BulletListIcon, null),
|
|
568
|
-
style:
|
|
569
|
-
tooltip:
|
|
562
|
+
style: "unordered-list-item",
|
|
563
|
+
tooltip: "styles.unordered_list_item"
|
|
570
564
|
},
|
|
571
|
-
|
|
565
|
+
"ordered-list": {
|
|
572
566
|
label: /*#__PURE__*/React.createElement(NumberListIcon, null),
|
|
573
|
-
style:
|
|
574
|
-
tooltip:
|
|
567
|
+
style: "ordered-list-item",
|
|
568
|
+
tooltip: "styles.ordered_list_item"
|
|
575
569
|
}
|
|
576
570
|
});
|
|
577
571
|
var InlineStylesList = /*#__PURE__*/Object.freeze({
|
|
578
572
|
bold: {
|
|
579
573
|
label: /*#__PURE__*/React.createElement(BoldIcon, null),
|
|
580
|
-
style:
|
|
581
|
-
tooltip:
|
|
582
|
-
hotKey:
|
|
574
|
+
style: "BOLD",
|
|
575
|
+
tooltip: "styles.bold",
|
|
576
|
+
hotKey: "(Ctrl+B)"
|
|
583
577
|
},
|
|
584
578
|
italic: {
|
|
585
579
|
label: /*#__PURE__*/React.createElement(ItalicIcon, null),
|
|
586
|
-
style:
|
|
587
|
-
tooltip:
|
|
588
|
-
hotKey:
|
|
580
|
+
style: "ITALIC",
|
|
581
|
+
tooltip: "styles.italic",
|
|
582
|
+
hotKey: "(Ctrl+I)"
|
|
589
583
|
},
|
|
590
584
|
underline: {
|
|
591
585
|
label: /*#__PURE__*/React.createElement(UnderlineIcon, null),
|
|
592
|
-
style:
|
|
593
|
-
tooltip:
|
|
594
|
-
hotKey:
|
|
586
|
+
style: "UNDERLINE",
|
|
587
|
+
tooltip: "styles.underline",
|
|
588
|
+
hotKey: "(Ctrl+U)"
|
|
595
589
|
}
|
|
596
590
|
});
|
|
597
591
|
var MinifiedConfigTypes = /*#__PURE__*/Object.freeze({
|
|
598
592
|
fontList: [{
|
|
599
|
-
type:
|
|
600
|
-
label:
|
|
601
|
-
style:
|
|
593
|
+
type: "unstyled",
|
|
594
|
+
label: "styles.p",
|
|
595
|
+
style: "unstyled"
|
|
602
596
|
}, {
|
|
603
|
-
type:
|
|
604
|
-
label:
|
|
605
|
-
style:
|
|
597
|
+
type: "header-two",
|
|
598
|
+
label: "styles.h1",
|
|
599
|
+
style: "header-two"
|
|
606
600
|
}],
|
|
607
601
|
blockTypes: /*#__PURE__*/Object.values(EditorConfigTypes.BLOCK_TYPES),
|
|
608
602
|
inlineStyles: [EditorConfigTypes.INLINE_STYLES.BOLD, EditorConfigTypes.INLINE_STYLES.ITALIC]
|
|
@@ -668,7 +662,7 @@ var RichTextEditor = /*#__PURE__*/function (_Component) {
|
|
|
668
662
|
};
|
|
669
663
|
_this.insertText = function (editorState, text) {
|
|
670
664
|
var newContent = Modifier.insertText(editorState.getCurrentContent(), editorState.getSelection(), text);
|
|
671
|
-
_this.props.onChange(EditorState.push(editorState, newContent,
|
|
665
|
+
_this.props.onChange(EditorState.push(editorState, newContent, "insert-characters"), function () {
|
|
672
666
|
return _this.focusEditor();
|
|
673
667
|
});
|
|
674
668
|
};
|
|
@@ -677,18 +671,18 @@ var RichTextEditor = /*#__PURE__*/function (_Component) {
|
|
|
677
671
|
return controlConfig[panelType];
|
|
678
672
|
};
|
|
679
673
|
_this.getControlConfigBySet = function (config) {
|
|
680
|
-
var fontList = (config
|
|
681
|
-
return typeof f ===
|
|
674
|
+
var fontList = ((config == null ? void 0 : config.fontList) || Object.keys(FontList)).filter(function (f) {
|
|
675
|
+
return typeof f === "object" ? FontList[f.type] : FontList[f];
|
|
682
676
|
}).map(function (f) {
|
|
683
677
|
return f.label && f.style ? f : FontList[f];
|
|
684
678
|
});
|
|
685
|
-
var blockTypes = (config
|
|
686
|
-
return typeof f ===
|
|
679
|
+
var blockTypes = ((config == null ? void 0 : config.blockTypes) || Object.keys(BlockTypeList)).filter(function (f) {
|
|
680
|
+
return typeof f === "object" ? BlockTypeList[f.type] : BlockTypeList[f];
|
|
687
681
|
}).map(function (f) {
|
|
688
682
|
return f.label && f.style ? f : BlockTypeList[f];
|
|
689
683
|
});
|
|
690
|
-
var inlineStyles = (config
|
|
691
|
-
return typeof f ===
|
|
684
|
+
var inlineStyles = ((config == null ? void 0 : config.inlineStyles) || Object.keys(InlineStylesList)).filter(function (f) {
|
|
685
|
+
return typeof f === "object" ? InlineStylesList[f.type] : InlineStylesList[f];
|
|
692
686
|
}).map(function (f) {
|
|
693
687
|
return f.label && f.style ? f : InlineStylesList[f];
|
|
694
688
|
});
|
|
@@ -703,7 +697,8 @@ var RichTextEditor = /*#__PURE__*/function (_Component) {
|
|
|
703
697
|
_inheritsLoose(RichTextEditor, _Component);
|
|
704
698
|
var _proto = RichTextEditor.prototype;
|
|
705
699
|
_proto.focusEditor = function focusEditor() {
|
|
706
|
-
|
|
700
|
+
var _this$editor$current;
|
|
701
|
+
(_this$editor$current = this.editor.current) == null || _this$editor$current.focus();
|
|
707
702
|
};
|
|
708
703
|
_proto.render = function render() {
|
|
709
704
|
var _this$props5 = this.props,
|
|
@@ -717,7 +712,7 @@ var RichTextEditor = /*#__PURE__*/function (_Component) {
|
|
|
717
712
|
editorState = _this$props5.editorState,
|
|
718
713
|
onChange = _this$props5.onChange,
|
|
719
714
|
handleBeforeInput = _this$props5.handleBeforeInput;
|
|
720
|
-
var classNames = cx(
|
|
715
|
+
var classNames = cx("editor-root", className);
|
|
721
716
|
return /*#__PURE__*/React.createElement("div", {
|
|
722
717
|
ref: this.wrapperRef
|
|
723
718
|
}, label && /*#__PURE__*/React.createElement(Label, null, label), /*#__PURE__*/React.createElement("div", {
|
|
@@ -727,15 +722,15 @@ var RichTextEditor = /*#__PURE__*/function (_Component) {
|
|
|
727
722
|
}, showFontMenu && /*#__PURE__*/React.createElement(BlockTypeControls, {
|
|
728
723
|
editorState: editorState,
|
|
729
724
|
onToggle: this.toggleSelectBlockType,
|
|
730
|
-
blockTypes: this.getFontListConfigForPanelType(
|
|
725
|
+
blockTypes: this.getFontListConfigForPanelType("fontList")
|
|
731
726
|
}), showInlineStyleMenu && /*#__PURE__*/React.createElement(InlineStyleControls, {
|
|
732
727
|
editorState: editorState,
|
|
733
728
|
onToggle: this.toggleInlineStyle,
|
|
734
|
-
inlineStyles: this.getFontListConfigForPanelType(
|
|
729
|
+
inlineStyles: this.getFontListConfigForPanelType("inlineStyles")
|
|
735
730
|
}), showTextFormatMenu && /*#__PURE__*/React.createElement(BlockTypeButtonControls, {
|
|
736
731
|
editorState: editorState,
|
|
737
732
|
onToggle: this.toggleButtonBlockType,
|
|
738
|
-
blockTypes: this.getFontListConfigForPanelType(
|
|
733
|
+
blockTypes: this.getFontListConfigForPanelType("blockTypes")
|
|
739
734
|
}), showLinkMenu && /*#__PURE__*/React.createElement(BlockTypeLinkControls$1, {
|
|
740
735
|
editorState: editorState,
|
|
741
736
|
onToggle: this.toggleLink
|
|
@@ -789,7 +784,7 @@ RichTextEditor.defaultProps = {
|
|
|
789
784
|
showInlineStyleMenu: true,
|
|
790
785
|
showTextFormatMenu: true,
|
|
791
786
|
showLinkMenu: true,
|
|
792
|
-
label:
|
|
787
|
+
label: ""
|
|
793
788
|
};
|
|
794
789
|
|
|
795
790
|
var editorStateToMarkdown = function editorStateToMarkdown(editorState) {
|
|
@@ -832,7 +827,7 @@ var RichTextEditorForLanguage = function RichTextEditorForLanguage(_ref) {
|
|
|
832
827
|
var handleOnChange = function handleOnChange(changedState) {
|
|
833
828
|
var newValues = _extends({}, values);
|
|
834
829
|
var content = editorStateToMarkdown(changedState);
|
|
835
|
-
if (values[langKey] && content ===
|
|
830
|
+
if (values[langKey] && content === "\n") {
|
|
836
831
|
delete newValues[langKey];
|
|
837
832
|
} else {
|
|
838
833
|
newValues[langKey] = content;
|
|
@@ -840,16 +835,16 @@ var RichTextEditorForLanguage = function RichTextEditorForLanguage(_ref) {
|
|
|
840
835
|
setEditorState(changedState);
|
|
841
836
|
onChange(newValues);
|
|
842
837
|
};
|
|
843
|
-
var feedbackText = feedback
|
|
838
|
+
var feedbackText = feedback == null ? void 0 : feedback(langKey);
|
|
844
839
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(RichTextEditor, {
|
|
845
|
-
label: required ? label +
|
|
840
|
+
label: required ? label + "*" : label,
|
|
846
841
|
editorState: editorState,
|
|
847
842
|
onChange: function onChange(changedState) {
|
|
848
843
|
return handleOnChange(changedState);
|
|
849
844
|
},
|
|
850
845
|
controlConfigSet: MinifiedConfigTypes,
|
|
851
846
|
tags: tags
|
|
852
|
-
}), variant &&
|
|
847
|
+
}), variant && feedbackText && feedbackText.length > 0 && (/*#__PURE__*/React.createElement(FeedbackText, {
|
|
853
848
|
variant: variant(langKey)
|
|
854
849
|
}, feedbackText)));
|
|
855
850
|
};
|
|
@@ -862,9 +857,9 @@ var ExpandableMultiLanguageRichTextEditor = function ExpandableMultiLanguageRich
|
|
|
862
857
|
title: title,
|
|
863
858
|
defaultOpen: true,
|
|
864
859
|
contentStyle: {
|
|
865
|
-
padding:
|
|
866
|
-
marginTop:
|
|
867
|
-
marginBottom:
|
|
860
|
+
padding: "4px 4px 4px 4px",
|
|
861
|
+
marginTop: "16px",
|
|
862
|
+
marginBottom: "16px"
|
|
868
863
|
}
|
|
869
864
|
}, /*#__PURE__*/React.createElement(Stack, {
|
|
870
865
|
space: "medium"
|
|
@@ -878,11 +873,9 @@ var ExpandableMultiLanguageRichTextEditor = function ExpandableMultiLanguageRich
|
|
|
878
873
|
})));
|
|
879
874
|
};
|
|
880
875
|
|
|
881
|
-
/* eslint-disable react/display-name */
|
|
882
|
-
|
|
883
876
|
var entityToHtml = {
|
|
884
877
|
entityToHTML: function entityToHTML(entity, originalText) {
|
|
885
|
-
if (entity.type ===
|
|
878
|
+
if (entity.type === "LINK") {
|
|
886
879
|
return /*#__PURE__*/React.createElement(HtmlLink, {
|
|
887
880
|
url: entity.data.url
|
|
888
881
|
}, originalText);
|
|
@@ -892,16 +885,13 @@ var entityToHtml = {
|
|
|
892
885
|
};
|
|
893
886
|
var htmlToEntity = {
|
|
894
887
|
htmlToEntity: function htmlToEntity(nodeName, node, createEntity) {
|
|
895
|
-
if (nodeName ===
|
|
896
|
-
return createEntity(
|
|
888
|
+
if (nodeName === "a") {
|
|
889
|
+
return createEntity("LINK", "MUTABLE", {
|
|
897
890
|
url: node.href
|
|
898
891
|
});
|
|
899
892
|
}
|
|
900
893
|
}
|
|
901
894
|
};
|
|
902
|
-
|
|
903
|
-
/* eslint-disable react/display-name */
|
|
904
|
-
|
|
905
895
|
var htmlToEditorState = function htmlToEditorState(html) {
|
|
906
896
|
if (!html) {
|
|
907
897
|
return EditorState.createEmpty(decorator);
|