@festo-ui/react 9.0.0-dev.681 → 9.0.0-dev.683
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/index.css +1 -14
- package/index.d.ts +0 -5
- package/index.js +0 -5
- package/node/index.js +0 -35
- package/package.json +1 -6
- package/508.bundle.js +0 -1
- package/lib/forms/color-indicator/ColorIndicator.d.ts +0 -11
- package/lib/forms/color-indicator/ColorIndicator.js +0 -119
- package/lib/forms/color-picker/ColorHelper.d.ts +0 -9
- package/lib/forms/color-picker/ColorHelper.js +0 -140
- package/lib/forms/color-picker/ColorPicker.d.ts +0 -14
- package/lib/forms/color-picker/ColorPicker.js +0 -545
- package/lib/forms/date-picker/DatePicker.d.ts +0 -25
- package/lib/forms/date-picker/DatePicker.js +0 -155
- package/lib/forms/date-range-picker/DateRangePicker.d.ts +0 -19
- package/lib/forms/date-range-picker/DateRangePicker.js +0 -135
- package/lib/forms/text-editor/TextEditor.d.ts +0 -29
- package/lib/forms/text-editor/TextEditor.js +0 -256
- package/lib/forms/text-editor/TextEditorButton.d.ts +0 -14
- package/lib/forms/text-editor/TextEditorButton.js +0 -80
- package/node/lib/forms/color-indicator/ColorIndicator.js +0 -128
- package/node/lib/forms/color-picker/ColorHelper.js +0 -147
- package/node/lib/forms/color-picker/ColorPicker.js +0 -552
- package/node/lib/forms/date-picker/DatePicker.js +0 -162
- package/node/lib/forms/date-range-picker/DateRangePicker.js +0 -142
- package/node/lib/forms/text-editor/TextEditor.js +0 -265
- package/node/lib/forms/text-editor/TextEditorButton.js +0 -87
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
-
var _flatpickr = _interopRequireDefault(require("flatpickr"));
|
|
10
|
-
var _reactIcons = require("@festo-ui/react-icons");
|
|
11
|
-
var _useId = _interopRequireDefault(require("../../helper/useId.js"));
|
|
12
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
function DatePicker(_ref) {
|
|
15
|
-
let {
|
|
16
|
-
children,
|
|
17
|
-
className,
|
|
18
|
-
disabled,
|
|
19
|
-
required,
|
|
20
|
-
error,
|
|
21
|
-
hint,
|
|
22
|
-
value,
|
|
23
|
-
defaultValue = new Date(),
|
|
24
|
-
formatDate = Intl.DateTimeFormat().format,
|
|
25
|
-
options,
|
|
26
|
-
onChange,
|
|
27
|
-
id: idProps,
|
|
28
|
-
allowManualInput = false,
|
|
29
|
-
dateFormat = "d/m/Y",
|
|
30
|
-
openOnInputClick = true
|
|
31
|
-
} = _ref;
|
|
32
|
-
const id = (0, _useId.default)(idProps);
|
|
33
|
-
const [open, setOpen] = (0, _react.useState)(false);
|
|
34
|
-
const [calendar, setCalendar] = (0, _react.useState)(null);
|
|
35
|
-
const innerDefaultValue = value || defaultValue;
|
|
36
|
-
function toggle() {
|
|
37
|
-
const newOpen = !open;
|
|
38
|
-
setOpen(newOpen);
|
|
39
|
-
if (newOpen) {
|
|
40
|
-
calendar?.open();
|
|
41
|
-
} else {
|
|
42
|
-
calendar?.close();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const datePickerRef = (0, _react.useRef)(null);
|
|
46
|
-
const {
|
|
47
|
-
keepOpenOnDateChange,
|
|
48
|
-
maxDate,
|
|
49
|
-
minDate,
|
|
50
|
-
position = "below center"
|
|
51
|
-
} = options || {};
|
|
52
|
-
(0, _react.useEffect)(() => {
|
|
53
|
-
if (calendar !== null && value !== undefined) {
|
|
54
|
-
calendar.setDate(value);
|
|
55
|
-
}
|
|
56
|
-
}, [calendar, value]);
|
|
57
|
-
(0, _react.useEffect)(() => {
|
|
58
|
-
function handleChange(date) {
|
|
59
|
-
datePickerRef.current?.blur();
|
|
60
|
-
if (onChange) {
|
|
61
|
-
onChange(date);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function handleClose() {
|
|
65
|
-
setOpen(false);
|
|
66
|
-
datePickerRef.current?.blur();
|
|
67
|
-
}
|
|
68
|
-
if (datePickerRef.current) {
|
|
69
|
-
if (calendar === null) {
|
|
70
|
-
setCalendar((0, _flatpickr.default)(datePickerRef.current, {
|
|
71
|
-
defaultDate: innerDefaultValue,
|
|
72
|
-
onChange: v => handleChange(v[0]),
|
|
73
|
-
onClose: handleClose,
|
|
74
|
-
position,
|
|
75
|
-
formatDate,
|
|
76
|
-
closeOnSelect: !keepOpenOnDateChange,
|
|
77
|
-
clickOpens: false,
|
|
78
|
-
minDate,
|
|
79
|
-
maxDate,
|
|
80
|
-
allowInput: allowManualInput,
|
|
81
|
-
dateFormat
|
|
82
|
-
}));
|
|
83
|
-
} else {
|
|
84
|
-
calendar.set({
|
|
85
|
-
defaultDate: innerDefaultValue,
|
|
86
|
-
minDate,
|
|
87
|
-
maxDate,
|
|
88
|
-
position,
|
|
89
|
-
closeOnSelect: !keepOpenOnDateChange,
|
|
90
|
-
allowInput: allowManualInput,
|
|
91
|
-
dateFormat
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}, [datePickerRef, calendar, maxDate, minDate, onChange, innerDefaultValue, formatDate, keepOpenOnDateChange, position, allowManualInput, dateFormat]);
|
|
96
|
-
(0, _react.useEffect)(() => () => {
|
|
97
|
-
if (calendar !== null) {
|
|
98
|
-
calendar.destroy();
|
|
99
|
-
}
|
|
100
|
-
}, [calendar]);
|
|
101
|
-
const handleKeyDown = event => {
|
|
102
|
-
if (event.key === "Enter") {
|
|
103
|
-
toggle();
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
const handleKeyUp = event => {
|
|
107
|
-
if (event.key === " ") {
|
|
108
|
-
toggle();
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
112
|
-
tabIndex: 0,
|
|
113
|
-
role: "button",
|
|
114
|
-
onClick: toggle,
|
|
115
|
-
onKeyDown: handleKeyDown,
|
|
116
|
-
onKeyUp: handleKeyUp,
|
|
117
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
|
|
118
|
-
className: (0, _classnames.default)("fwe-input-text fwe-input-text-icon", className),
|
|
119
|
-
htmlFor: id,
|
|
120
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIcons.IconCalendar, {
|
|
121
|
-
className: (0, _classnames.default)({
|
|
122
|
-
"fwe-color-hero": open && !disabled,
|
|
123
|
-
"fwe-color-control-disabled": disabled,
|
|
124
|
-
"icon-hover": allowManualInput && !openOnInputClick
|
|
125
|
-
})
|
|
126
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
127
|
-
id: id,
|
|
128
|
-
ref: datePickerRef,
|
|
129
|
-
"aria-label": "picked date",
|
|
130
|
-
type: "text",
|
|
131
|
-
readOnly: !allowManualInput,
|
|
132
|
-
onClick: e => {
|
|
133
|
-
if (allowManualInput && !openOnInputClick) e.stopPropagation();
|
|
134
|
-
},
|
|
135
|
-
onKeyDown: e => {
|
|
136
|
-
if (allowManualInput && !openOnInputClick) e.stopPropagation();
|
|
137
|
-
},
|
|
138
|
-
onBlur: () => {
|
|
139
|
-
if (allowManualInput && calendar && datePickerRef.current) {
|
|
140
|
-
const raw = datePickerRef.current.value;
|
|
141
|
-
if (raw) calendar.setDate(raw, true, dateFormat);
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
required: required,
|
|
145
|
-
className: (0, _classnames.default)("fr-date-picker", {
|
|
146
|
-
"fwe-border-hero": open && !disabled
|
|
147
|
-
}),
|
|
148
|
-
disabled: disabled
|
|
149
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
150
|
-
className: "fwe-input-text-label",
|
|
151
|
-
children: children
|
|
152
|
-
}), hint && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
153
|
-
className: "fwe-input-text-info",
|
|
154
|
-
children: hint
|
|
155
|
-
}), error && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
156
|
-
className: "fwe-input-text-invalid",
|
|
157
|
-
children: error
|
|
158
|
-
})]
|
|
159
|
-
})
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
var _default = exports.default = DatePicker;
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
8
|
-
var _flatpickr = _interopRequireDefault(require("flatpickr"));
|
|
9
|
-
var _rangePlugin = _interopRequireDefault(require("flatpickr/dist/plugins/rangePlugin.js"));
|
|
10
|
-
var _react = require("react");
|
|
11
|
-
var _reactIcons = require("@festo-ui/react-icons");
|
|
12
|
-
var _useId = _interopRequireDefault(require("../../helper/useId.js"));
|
|
13
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
function DateRangePicker(_ref) {
|
|
16
|
-
let {
|
|
17
|
-
children,
|
|
18
|
-
className,
|
|
19
|
-
disabled,
|
|
20
|
-
error,
|
|
21
|
-
formatDate,
|
|
22
|
-
hint,
|
|
23
|
-
onChange,
|
|
24
|
-
options,
|
|
25
|
-
required,
|
|
26
|
-
defaultValue = new Date()
|
|
27
|
-
} = _ref;
|
|
28
|
-
const [open, setOpen] = (0, _react.useState)(false);
|
|
29
|
-
const [calendar, setCalendar] = (0, _react.useState)(null);
|
|
30
|
-
const id = (0, _useId.default)();
|
|
31
|
-
function toggle() {
|
|
32
|
-
const newOpen = !open;
|
|
33
|
-
setOpen(newOpen);
|
|
34
|
-
if (newOpen) {
|
|
35
|
-
calendar?.open();
|
|
36
|
-
} else {
|
|
37
|
-
calendar?.close();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const inputRef = (0, _react.useRef)(null);
|
|
41
|
-
const input2Ref = (0, _react.useRef)(null);
|
|
42
|
-
const containerRef = (0, _react.useRef)(null);
|
|
43
|
-
(0, _react.useEffect)(() => {
|
|
44
|
-
function handleChange(dates) {
|
|
45
|
-
if (onChange) {
|
|
46
|
-
onChange(dates);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function handleClose() {
|
|
50
|
-
setOpen(false);
|
|
51
|
-
inputRef.current?.blur();
|
|
52
|
-
input2Ref.current?.blur();
|
|
53
|
-
}
|
|
54
|
-
if (containerRef.current && inputRef.current && input2Ref.current && calendar === null) {
|
|
55
|
-
setCalendar((0, _flatpickr.default)(inputRef.current, {
|
|
56
|
-
defaultDate: defaultValue,
|
|
57
|
-
plugins: [(0, _rangePlugin.default)({
|
|
58
|
-
input: input2Ref.current
|
|
59
|
-
})],
|
|
60
|
-
onChange: v => handleChange(v),
|
|
61
|
-
position: "below center",
|
|
62
|
-
positionElement: containerRef.current,
|
|
63
|
-
formatDate,
|
|
64
|
-
closeOnSelect: !options?.keepOpenOnDateChange ?? true,
|
|
65
|
-
clickOpens: false,
|
|
66
|
-
onClose: handleClose,
|
|
67
|
-
minDate: options?.minDate,
|
|
68
|
-
maxDate: options?.maxDate
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
71
|
-
}, [inputRef, input2Ref, containerRef, formatDate, options, onChange, calendar, defaultValue]);
|
|
72
|
-
(0, _react.useEffect)(() => () => {
|
|
73
|
-
if (calendar !== null) {
|
|
74
|
-
calendar.destroy();
|
|
75
|
-
}
|
|
76
|
-
}, [calendar]);
|
|
77
|
-
const handleKeyDown = event => {
|
|
78
|
-
if (event.key === "Enter") {
|
|
79
|
-
toggle();
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
const handleKeyUp = event => {
|
|
83
|
-
if (event.key === " ") {
|
|
84
|
-
toggle();
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
88
|
-
tabIndex: 0,
|
|
89
|
-
role: "button",
|
|
90
|
-
className: (0, _classnames.default)("fr-date-range-picker", className),
|
|
91
|
-
onClick: toggle,
|
|
92
|
-
onKeyDown: handleKeyDown,
|
|
93
|
-
onKeyUp: handleKeyUp,
|
|
94
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
|
|
95
|
-
className: "fwe-input-text fwe-input-text-icon",
|
|
96
|
-
htmlFor: id,
|
|
97
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIcons.IconCalendar, {
|
|
98
|
-
className: (0, _classnames.default)({
|
|
99
|
-
"fwe-color-hero": open && !disabled,
|
|
100
|
-
"fwe-color-control-disabled": disabled
|
|
101
|
-
})
|
|
102
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
103
|
-
ref: containerRef,
|
|
104
|
-
className: "fr-date-range-picker-inputs",
|
|
105
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
106
|
-
ref: inputRef,
|
|
107
|
-
"aria-label": "picked start date",
|
|
108
|
-
type: "text",
|
|
109
|
-
readOnly: true,
|
|
110
|
-
required: required,
|
|
111
|
-
className: (0, _classnames.default)({
|
|
112
|
-
"fwe-border-hero": open && !disabled
|
|
113
|
-
}),
|
|
114
|
-
disabled: disabled,
|
|
115
|
-
id: id
|
|
116
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
117
|
-
ref: input2Ref,
|
|
118
|
-
"aria-label": "picked end date",
|
|
119
|
-
type: "text",
|
|
120
|
-
readOnly: true,
|
|
121
|
-
required: required,
|
|
122
|
-
className: (0, _classnames.default)({
|
|
123
|
-
"fwe-border-hero": open && !disabled
|
|
124
|
-
}),
|
|
125
|
-
disabled: disabled
|
|
126
|
-
})]
|
|
127
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
128
|
-
className: (0, _classnames.default)("fwe-input-text-label", {
|
|
129
|
-
"fwe-color-text-disabled": disabled
|
|
130
|
-
}),
|
|
131
|
-
children: children
|
|
132
|
-
}), hint && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
133
|
-
className: "fwe-input-text-info",
|
|
134
|
-
children: hint
|
|
135
|
-
}), error && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
136
|
-
className: "fwe-input-text-invalid",
|
|
137
|
-
children: error
|
|
138
|
-
})]
|
|
139
|
-
})
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
var _default = exports.default = DateRangePicker;
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
-
var xss = _interopRequireWildcard(require("xss"));
|
|
10
|
-
var _reactIcons = require("@festo-ui/react-icons");
|
|
11
|
-
var _useId = _interopRequireDefault(require("../../helper/useId.js"));
|
|
12
|
-
var _TextEditorButton = _interopRequireDefault(require("./TextEditorButton.js"));
|
|
13
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
-
const defaultConfig = {
|
|
18
|
-
toolbar: {
|
|
19
|
-
bold: true,
|
|
20
|
-
italic: true,
|
|
21
|
-
underline: true,
|
|
22
|
-
alignCenter: false,
|
|
23
|
-
alignRight: false,
|
|
24
|
-
bulletList: true,
|
|
25
|
-
orderedList: true,
|
|
26
|
-
image: true,
|
|
27
|
-
link: true
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
function postpone(fn) {
|
|
31
|
-
Promise.resolve().then(fn);
|
|
32
|
-
}
|
|
33
|
-
function TextEditor(_ref) {
|
|
34
|
-
let {
|
|
35
|
-
disabled = false,
|
|
36
|
-
defaultValue,
|
|
37
|
-
label,
|
|
38
|
-
maxLength,
|
|
39
|
-
value,
|
|
40
|
-
hint,
|
|
41
|
-
error,
|
|
42
|
-
readOnly = false,
|
|
43
|
-
onChange,
|
|
44
|
-
className,
|
|
45
|
-
config: configProps
|
|
46
|
-
} = _ref;
|
|
47
|
-
const editorRef = (0, _react.useRef)(null);
|
|
48
|
-
const [editor, setEditor] = (0, _react.useState)(null);
|
|
49
|
-
const id = (0, _useId.default)();
|
|
50
|
-
const [innerValue, setInnerValue] = (0, _react.useState)(null);
|
|
51
|
-
const config = {
|
|
52
|
-
toolbar: {
|
|
53
|
-
...defaultConfig.toolbar,
|
|
54
|
-
...configProps?.toolbar
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const setEditorContents = (0, _react.useCallback)((e, v) => {
|
|
58
|
-
if (e) {
|
|
59
|
-
const whiteList = {
|
|
60
|
-
...xss.whiteList,
|
|
61
|
-
p: [...(xss.whiteList?.p ?? []), "class"],
|
|
62
|
-
li: [...(xss.whiteList?.li ?? []), "class"],
|
|
63
|
-
a: [...(xss.whiteList?.a ?? []), "rel", "class"]
|
|
64
|
-
};
|
|
65
|
-
const sanitizedValue = xss.filterXSS(v, {
|
|
66
|
-
whiteList
|
|
67
|
-
});
|
|
68
|
-
const content = e.clipboard.convert({
|
|
69
|
-
html: sanitizedValue
|
|
70
|
-
});
|
|
71
|
-
const selection = e.getSelection();
|
|
72
|
-
e.setContents(content, "silent");
|
|
73
|
-
setInnerValue(sanitizedValue);
|
|
74
|
-
postpone(() => e.setSelection(selection));
|
|
75
|
-
}
|
|
76
|
-
}, []);
|
|
77
|
-
(0, _react.useEffect)(() => {
|
|
78
|
-
const initializeQuill = async () => {
|
|
79
|
-
let Quill;
|
|
80
|
-
if (typeof window !== "undefined") {
|
|
81
|
-
const QuillModule = await Promise.resolve().then(() => _interopRequireWildcard(require("quill")));
|
|
82
|
-
Quill = QuillModule.default;
|
|
83
|
-
}
|
|
84
|
-
if (editorRef.current && Quill && editor === null) {
|
|
85
|
-
const newEditor = new Quill(editorRef.current, {
|
|
86
|
-
modules: {
|
|
87
|
-
toolbar: `#editor-toolbar-${CSS.escape(id ?? "")}`
|
|
88
|
-
},
|
|
89
|
-
theme: "snow"
|
|
90
|
-
});
|
|
91
|
-
newEditor.root.setAttribute("role", "textbox");
|
|
92
|
-
newEditor.root.setAttribute("aria-labelledby", `editor-label-${id}`);
|
|
93
|
-
newEditor.root.setAttribute("aria-multiline", "true");
|
|
94
|
-
newEditor.enable(!readOnly);
|
|
95
|
-
if (disabled) {
|
|
96
|
-
newEditor.disable();
|
|
97
|
-
} else if (!readOnly) {
|
|
98
|
-
newEditor.enable();
|
|
99
|
-
}
|
|
100
|
-
setEditor(newEditor);
|
|
101
|
-
if (defaultValue) {
|
|
102
|
-
setEditorContents(newEditor, defaultValue);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
initializeQuill();
|
|
107
|
-
}, [editor, disabled, readOnly, id, setEditorContents, defaultValue]);
|
|
108
|
-
(0, _react.useEffect)(() => {
|
|
109
|
-
if (editor) {
|
|
110
|
-
editor.on("text-change", () => {
|
|
111
|
-
let html = editor.getSemanticHTML();
|
|
112
|
-
if (html === "<p><br></p>" || html === "<div><br></div>" || html === undefined) {
|
|
113
|
-
html = null;
|
|
114
|
-
}
|
|
115
|
-
if (html !== null) {
|
|
116
|
-
// Repairs relative links in an HTML string by prepending "https://".
|
|
117
|
-
// It ignores links that are already absolute (http, https) as well as mailto: and tel: links.
|
|
118
|
-
const relativeLinkRegex = /href="(?!https?:\/\/|mailto:|tel:)([^"]+)"/g;
|
|
119
|
-
html = html.replace(relativeLinkRegex, 'href="https://$1"');
|
|
120
|
-
}
|
|
121
|
-
if (onChange) {
|
|
122
|
-
onChange(html);
|
|
123
|
-
}
|
|
124
|
-
setInnerValue(html);
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}, [editor, onChange]);
|
|
128
|
-
(0, _react.useEffect)(() => {
|
|
129
|
-
if (value !== innerValue && value !== undefined && value !== null) {
|
|
130
|
-
setEditorContents(editor, value);
|
|
131
|
-
}
|
|
132
|
-
}, [editor, innerValue, setEditorContents, value]);
|
|
133
|
-
function currentLength() {
|
|
134
|
-
return innerValue?.length || 0;
|
|
135
|
-
}
|
|
136
|
-
function hideDivider(name) {
|
|
137
|
-
const linkOrImage = config.toolbar?.image || config.toolbar?.link;
|
|
138
|
-
const lists = config.toolbar?.bulletList || config.toolbar?.orderedList;
|
|
139
|
-
const typos = config.toolbar?.bold || config.toolbar?.italic || config.toolbar?.underline;
|
|
140
|
-
const textAlign = config.toolbar?.alignCenter || config.toolbar?.alignRight;
|
|
141
|
-
switch (name) {
|
|
142
|
-
case "typo":
|
|
143
|
-
return !typos || !textAlign && !linkOrImage && !lists;
|
|
144
|
-
case "text-align":
|
|
145
|
-
return !textAlign || !linkOrImage && !lists;
|
|
146
|
-
case "lists":
|
|
147
|
-
return !lists || !linkOrImage;
|
|
148
|
-
case "image":
|
|
149
|
-
return !config.toolbar?.image || !config.toolbar.link;
|
|
150
|
-
default:
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
|
|
156
|
-
className: (0, _classnames.default)("fwe-input-text", {
|
|
157
|
-
disabled
|
|
158
|
-
}),
|
|
159
|
-
htmlFor: `editor-label-${id}`,
|
|
160
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
161
|
-
className: (0, _classnames.default)("fwe-editor-toolbar", {
|
|
162
|
-
[`fwe-editor-toolbar-${className}`]: className
|
|
163
|
-
}),
|
|
164
|
-
id: `editor-toolbar-${id}`,
|
|
165
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
166
|
-
className: "ql-formats fwe-mr-3",
|
|
167
|
-
children: [config?.toolbar?.bold && /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextEditorButton.default, {
|
|
168
|
-
disabled: disabled,
|
|
169
|
-
type: "bold",
|
|
170
|
-
className: "fwe-mr-3",
|
|
171
|
-
label: "B"
|
|
172
|
-
}), config?.toolbar?.italic && /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextEditorButton.default, {
|
|
173
|
-
disabled: disabled,
|
|
174
|
-
type: "italic",
|
|
175
|
-
className: "fwe-mr-3",
|
|
176
|
-
label: "I"
|
|
177
|
-
}), config?.toolbar?.underline && /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextEditorButton.default, {
|
|
178
|
-
disabled: disabled,
|
|
179
|
-
type: "underline",
|
|
180
|
-
label: "U"
|
|
181
|
-
}), !hideDivider("typo") && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
182
|
-
className: "fwe-divider-y fwe-d-inline-flex fwe-mx-4"
|
|
183
|
-
}), config?.toolbar?.alignCenter && /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextEditorButton.default, {
|
|
184
|
-
disabled: disabled,
|
|
185
|
-
category: "align",
|
|
186
|
-
type: "align-center",
|
|
187
|
-
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIcons.IconAlignCenter, {
|
|
188
|
-
className: (0, _classnames.default)({
|
|
189
|
-
"fwe-gray": disabled
|
|
190
|
-
})
|
|
191
|
-
}),
|
|
192
|
-
value: "center",
|
|
193
|
-
className: (0, _classnames.default)({
|
|
194
|
-
"fwe-mr-3": config?.toolbar?.alignRight
|
|
195
|
-
})
|
|
196
|
-
}), config?.toolbar?.alignRight && /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextEditorButton.default, {
|
|
197
|
-
disabled: disabled,
|
|
198
|
-
category: "align",
|
|
199
|
-
type: "align-right",
|
|
200
|
-
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIcons.IconAlignRight, {
|
|
201
|
-
className: (0, _classnames.default)({
|
|
202
|
-
"fwe-gray": disabled
|
|
203
|
-
})
|
|
204
|
-
}),
|
|
205
|
-
value: "right"
|
|
206
|
-
}), !hideDivider("text-align") && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
207
|
-
className: "fwe-divider-y fwe-d-inline-flex fwe-mx-4"
|
|
208
|
-
}), config?.toolbar?.bulletList && /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextEditorButton.default, {
|
|
209
|
-
disabled: disabled,
|
|
210
|
-
className: "fwe-mr-3",
|
|
211
|
-
type: "ul",
|
|
212
|
-
list: true,
|
|
213
|
-
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIcons.IconListView, {}),
|
|
214
|
-
value: "bullet"
|
|
215
|
-
}), config?.toolbar?.orderedList && /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextEditorButton.default, {
|
|
216
|
-
disabled: disabled,
|
|
217
|
-
type: "ol",
|
|
218
|
-
list: true,
|
|
219
|
-
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIcons.IconEnumeration, {}),
|
|
220
|
-
value: "ordered"
|
|
221
|
-
}), config?.toolbar?.image && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
222
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
223
|
-
className: "fwe-divider-y fwe-d-inline-flex fwe-mx-4"
|
|
224
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextEditorButton.default, {
|
|
225
|
-
disabled: disabled,
|
|
226
|
-
type: "image",
|
|
227
|
-
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIcons.IconImage, {}),
|
|
228
|
-
noAction: true
|
|
229
|
-
})]
|
|
230
|
-
}), config?.toolbar?.link && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
231
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
232
|
-
className: "fwe-divider-y fwe-d-inline-flex fwe-mx-4"
|
|
233
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextEditorButton.default, {
|
|
234
|
-
disabled: disabled,
|
|
235
|
-
type: "link",
|
|
236
|
-
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIcons.IconLink, {}),
|
|
237
|
-
noAction: true
|
|
238
|
-
})]
|
|
239
|
-
})]
|
|
240
|
-
})
|
|
241
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
242
|
-
className: (0, _classnames.default)("fwe-editor-container", {
|
|
243
|
-
"fwe-editor-container--error": error
|
|
244
|
-
}),
|
|
245
|
-
id: `editor-container-${id}`,
|
|
246
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
247
|
-
className: "fwe-editor",
|
|
248
|
-
ref: editorRef
|
|
249
|
-
})
|
|
250
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
251
|
-
className: "fwe-input-text-label",
|
|
252
|
-
children: label
|
|
253
|
-
}), error && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
254
|
-
className: "fwe-text-editor-invalid",
|
|
255
|
-
children: error
|
|
256
|
-
}), hint && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
257
|
-
className: "fwe-text-editor-info",
|
|
258
|
-
children: hint
|
|
259
|
-
}), maxLength && maxLength > 0 && value != null && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
260
|
-
className: "fwe-input-text-count",
|
|
261
|
-
children: `${currentLength()} / ${maxLength}`
|
|
262
|
-
})]
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
var _default = exports.default = TextEditor;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
function TextEditorButton(_ref) {
|
|
12
|
-
let {
|
|
13
|
-
disabled,
|
|
14
|
-
label,
|
|
15
|
-
type,
|
|
16
|
-
className,
|
|
17
|
-
icon,
|
|
18
|
-
list,
|
|
19
|
-
value,
|
|
20
|
-
noAction,
|
|
21
|
-
category
|
|
22
|
-
} = _ref;
|
|
23
|
-
const [active, setActive] = (0, _react.useState)(false);
|
|
24
|
-
const btnRef = (0, _react.useRef)(null);
|
|
25
|
-
function handleClick() {
|
|
26
|
-
const btn = btnRef.current;
|
|
27
|
-
setActive(prevActive => !prevActive);
|
|
28
|
-
btn?.click();
|
|
29
|
-
}
|
|
30
|
-
(0, _react.useEffect)(() => {
|
|
31
|
-
function callback(mutationRecords) {
|
|
32
|
-
mutationRecords.forEach(mutationRecord => {
|
|
33
|
-
const {
|
|
34
|
-
classList
|
|
35
|
-
} = mutationRecord.target;
|
|
36
|
-
const {
|
|
37
|
-
oldValue
|
|
38
|
-
} = mutationRecord;
|
|
39
|
-
if (classList.contains("ql-active")) {
|
|
40
|
-
setActive(true);
|
|
41
|
-
}
|
|
42
|
-
if (!classList.contains("ql-active") && oldValue?.includes("ql-active")) {
|
|
43
|
-
setActive(false);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
if (btnRef.current && !noAction) {
|
|
48
|
-
const observer = new MutationObserver(callback);
|
|
49
|
-
observer.observe(btnRef.current, {
|
|
50
|
-
attributes: true,
|
|
51
|
-
attributeFilter: ["class"],
|
|
52
|
-
attributeOldValue: true
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}, [btnRef, noAction]);
|
|
56
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
57
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
58
|
-
ref: btnRef,
|
|
59
|
-
type: "button",
|
|
60
|
-
className: (0, _classnames.default)({
|
|
61
|
-
[`ql-${category || type}`]: !list
|
|
62
|
-
}, {
|
|
63
|
-
"ql-list": list
|
|
64
|
-
}, "fwe-d-none", {
|
|
65
|
-
[`action-${type}`]: !noAction
|
|
66
|
-
}),
|
|
67
|
-
"aria-hidden": "true",
|
|
68
|
-
value: value
|
|
69
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("button", {
|
|
70
|
-
type: "button",
|
|
71
|
-
className: (0, _classnames.default)({
|
|
72
|
-
"fr-icon-button": !!icon
|
|
73
|
-
}, "fr-button", className, {
|
|
74
|
-
"fwe-active": active && !noAction
|
|
75
|
-
}),
|
|
76
|
-
onClick: () => handleClick(),
|
|
77
|
-
disabled: disabled,
|
|
78
|
-
children: [label && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
79
|
-
className: `fr-button-text fwe-text-${type}`,
|
|
80
|
-
children: label
|
|
81
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
82
|
-
children: icon
|
|
83
|
-
})]
|
|
84
|
-
})]
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
var _default = exports.default = TextEditorButton;
|