@desynova-digital/components 9.1.51 → 9.2.0
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/atoms/cardV2/cardV2.js +11 -1
- package/atoms/cardV2/content.js +150 -94
- package/atoms/cardV2/thumbnail.js +61 -58
- package/atoms/icon/icons.json +61 -5
- package/atoms/timeCodeDisplay/timeCodeDisplay.js +7 -2
- package/atoms/timeCodeInput/timeCodeMSInput.js +9 -1
- package/atoms/timeCodeInput/timeCodeMainInput.js +10 -1
- package/atoms/timeCodeInput/timeCodeStandardInput.js +19 -7
- package/components.js +7 -0
- package/index.js +6 -0
- package/molecules/richTextInput/RichTextInput.js +54 -54
- package/molecules/richTextInputV2/RichTextInput.storyV2.js +197 -0
- package/molecules/richTextInputV2/RichTextInputV2.js +369 -0
- package/molecules/richTextInputV2/index.js +9 -0
- package/package.json +2 -2
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@storybook/react");
|
|
6
|
+
var _storyHelpers = require("../../_helpers/story-helpers");
|
|
7
|
+
var _components = require("../../components");
|
|
8
|
+
var _this = void 0;
|
|
9
|
+
(0, _react2.storiesOf)("RichTextInput").add("light theme", function () {
|
|
10
|
+
return /*#__PURE__*/_react["default"].createElement(_storyHelpers.Example, {
|
|
11
|
+
title: "Appearances"
|
|
12
|
+
}, /*#__PURE__*/_react["default"].createElement(_storyHelpers.Stack, null, /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
13
|
+
type: "text",
|
|
14
|
+
label: "First Name",
|
|
15
|
+
onKeyPress: function onKeyPress(e) {
|
|
16
|
+
return _this.value = e.target.value;
|
|
17
|
+
},
|
|
18
|
+
onChange: function onChange(e) {
|
|
19
|
+
return console.log(e.target.value);
|
|
20
|
+
},
|
|
21
|
+
placeholder: "Enter Name max 10",
|
|
22
|
+
value: "asd",
|
|
23
|
+
required: true
|
|
24
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
25
|
+
type: "password",
|
|
26
|
+
label: "Middle Name",
|
|
27
|
+
minLength: 3,
|
|
28
|
+
maxLength: 6,
|
|
29
|
+
placeholder: "Show as password",
|
|
30
|
+
required: true
|
|
31
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
32
|
+
type: "text",
|
|
33
|
+
value: "hello",
|
|
34
|
+
label: "Label and default value",
|
|
35
|
+
required: true
|
|
36
|
+
})), /*#__PURE__*/_react["default"].createElement(_storyHelpers.Stack, null, /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
37
|
+
type: "number",
|
|
38
|
+
placeholder: "number field & no Label",
|
|
39
|
+
required: true,
|
|
40
|
+
maxLength: 10
|
|
41
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
42
|
+
type: "number",
|
|
43
|
+
id: "input-text-1",
|
|
44
|
+
label: "Label 'For'-'id' prop",
|
|
45
|
+
placeholder: "No Label & Number Field",
|
|
46
|
+
required: true,
|
|
47
|
+
maxLength: 10
|
|
48
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
49
|
+
type: "text",
|
|
50
|
+
value: "No Label and default value",
|
|
51
|
+
onChange: function onChange(e) {
|
|
52
|
+
alert("some Handler code");
|
|
53
|
+
},
|
|
54
|
+
placeholder: "Placeholder text",
|
|
55
|
+
required: true
|
|
56
|
+
})), /*#__PURE__*/_react["default"].createElement(_storyHelpers.Stack, null, /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
57
|
+
type: "number",
|
|
58
|
+
label: "number & max 5",
|
|
59
|
+
placeholder: "max length 5",
|
|
60
|
+
required: true,
|
|
61
|
+
minLength: 3,
|
|
62
|
+
maxLength: 5
|
|
63
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
64
|
+
type: "text",
|
|
65
|
+
error: "Invalid text",
|
|
66
|
+
placeholder: "Display error",
|
|
67
|
+
required: true
|
|
68
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
69
|
+
readOnly: true,
|
|
70
|
+
type: "text",
|
|
71
|
+
value: "hello",
|
|
72
|
+
onChange: function onChange(e) {
|
|
73
|
+
alert("some Handler code");
|
|
74
|
+
},
|
|
75
|
+
placeholder: "Placeholder text",
|
|
76
|
+
required: true
|
|
77
|
+
})), /*#__PURE__*/_react["default"].createElement(_storyHelpers.Stack, null, /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
78
|
+
type: "password",
|
|
79
|
+
value: "this@is$passw0rd",
|
|
80
|
+
placeholder: "This is password toggle",
|
|
81
|
+
passwordButton: true
|
|
82
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
83
|
+
label: "Label 'For'-'id' prop",
|
|
84
|
+
type: "password",
|
|
85
|
+
value: "this@is$passw0rd",
|
|
86
|
+
placeholder: "This is password toggle",
|
|
87
|
+
passwordButton: true
|
|
88
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
89
|
+
label: "Label 'For'-'id' ",
|
|
90
|
+
error: " this is error",
|
|
91
|
+
type: "password",
|
|
92
|
+
value: "this@is$passw0rd",
|
|
93
|
+
placeholder: "This is password toggle",
|
|
94
|
+
passwordButton: true
|
|
95
|
+
})));
|
|
96
|
+
});
|
|
97
|
+
(0, _react2.storiesOf)("RichTextInput").add("dark theme", function () {
|
|
98
|
+
return /*#__PURE__*/_react["default"].createElement(_storyHelpers.Example, {
|
|
99
|
+
title: "Appearances",
|
|
100
|
+
background: "dark"
|
|
101
|
+
}, /*#__PURE__*/_react["default"].createElement(_storyHelpers.Stack, null, /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
102
|
+
theme: "dark",
|
|
103
|
+
type: "text",
|
|
104
|
+
label: "First Name",
|
|
105
|
+
showLengthCount: true,
|
|
106
|
+
value: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean m",
|
|
107
|
+
maxLength: 100,
|
|
108
|
+
onChange: function onChange(e) {
|
|
109
|
+
return console.log(e.target.value);
|
|
110
|
+
},
|
|
111
|
+
placeholder: "Enter Name max 10",
|
|
112
|
+
required: true
|
|
113
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
114
|
+
theme: "dark",
|
|
115
|
+
type: "password",
|
|
116
|
+
label: "Middle Name",
|
|
117
|
+
minLength: 3,
|
|
118
|
+
maxLength: 6,
|
|
119
|
+
placeholder: "Show as password",
|
|
120
|
+
required: true
|
|
121
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
122
|
+
theme: "dark",
|
|
123
|
+
type: "text",
|
|
124
|
+
value: "hello there i am using",
|
|
125
|
+
label: "Label and default value",
|
|
126
|
+
required: true
|
|
127
|
+
})), /*#__PURE__*/_react["default"].createElement(_storyHelpers.Stack, null, /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
128
|
+
theme: "dark",
|
|
129
|
+
type: "number",
|
|
130
|
+
placeholder: "number field & no Label",
|
|
131
|
+
required: true,
|
|
132
|
+
maxLength: 10
|
|
133
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
134
|
+
theme: "dark",
|
|
135
|
+
type: "number",
|
|
136
|
+
id: "input-text-1",
|
|
137
|
+
label: "Label 'For'-'id' prop",
|
|
138
|
+
placeholder: "No Label & Number Field",
|
|
139
|
+
required: true,
|
|
140
|
+
maxLength: 10
|
|
141
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
142
|
+
theme: "dark",
|
|
143
|
+
capitalizeFirstLetter: true,
|
|
144
|
+
type: "text",
|
|
145
|
+
value: "no label and default value",
|
|
146
|
+
onChange: function onChange(e) {
|
|
147
|
+
alert("some Handler code");
|
|
148
|
+
},
|
|
149
|
+
placeholder: "Placeholder text",
|
|
150
|
+
required: true
|
|
151
|
+
})), /*#__PURE__*/_react["default"].createElement(_storyHelpers.Stack, null, /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
152
|
+
theme: "dark",
|
|
153
|
+
type: "number",
|
|
154
|
+
label: "number & max 5",
|
|
155
|
+
placeholder: "max length 5",
|
|
156
|
+
required: true,
|
|
157
|
+
minLength: 3,
|
|
158
|
+
maxLength: 5
|
|
159
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
160
|
+
theme: "dark",
|
|
161
|
+
type: "text",
|
|
162
|
+
error: "Invalid text",
|
|
163
|
+
placeholder: "Display error",
|
|
164
|
+
required: true
|
|
165
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
166
|
+
theme: "dark",
|
|
167
|
+
readOnly: true,
|
|
168
|
+
type: "text",
|
|
169
|
+
value: "hello",
|
|
170
|
+
onChange: function onChange(e) {
|
|
171
|
+
alert("some Handler code");
|
|
172
|
+
},
|
|
173
|
+
placeholder: "Placeholder text",
|
|
174
|
+
required: true
|
|
175
|
+
})), /*#__PURE__*/_react["default"].createElement(_storyHelpers.Stack, null, /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
176
|
+
theme: "dark",
|
|
177
|
+
type: "password",
|
|
178
|
+
value: "this@is$passw0rd",
|
|
179
|
+
placeholder: "This is password toggle",
|
|
180
|
+
passwordButton: true
|
|
181
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
182
|
+
theme: "dark",
|
|
183
|
+
label: "Label 'For'-'id' prop",
|
|
184
|
+
type: "password",
|
|
185
|
+
value: "this@is$passw0rd",
|
|
186
|
+
placeholder: "This is password toggle",
|
|
187
|
+
passwordButton: true
|
|
188
|
+
}), /*#__PURE__*/_react["default"].createElement(RichTextInput, {
|
|
189
|
+
theme: "dark",
|
|
190
|
+
label: "Label 'For'-'id' ",
|
|
191
|
+
error: " this is error",
|
|
192
|
+
type: "password",
|
|
193
|
+
value: "this@is$passw0rd",
|
|
194
|
+
placeholder: "This is password toggle",
|
|
195
|
+
passwordButton: true
|
|
196
|
+
})));
|
|
197
|
+
});
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
12
|
+
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
13
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
14
|
+
var _quill = _interopRequireDefault(require("quill"));
|
|
15
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
16
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
17
|
+
var _tokens = require("@desynova-digital/tokens");
|
|
18
|
+
var _lodash = require("lodash");
|
|
19
|
+
var _quillDelta = _interopRequireDefault(require("quill-delta"));
|
|
20
|
+
var _utils = require("../../_helpers/utils");
|
|
21
|
+
var _excluded = ["maxLength", "defaultValue", "label", "showLengthCount", "errorMessage", "value", "autoFocus", "onChange", "handleSave", "editType", "hideBorder", "type", "onBlur", "placeholder", "isUpdateCase", "isDisabled"];
|
|
22
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4;
|
|
23
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
24
|
+
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; }
|
|
25
|
+
var RichTextInputDiv = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n i,\n em {\n font-style: italic;\n }\n strong {\n font-weight: bold;\n }\n .quill-editor-content {\n white-space: pre-wrap; /* Preserve whitespace and line breaks */\n }\n background: transparent;\n font-family: \"SFUIText-Medium\";\n position: relative;\n width: 92%;\n width: ", ";\n margin-bottom: ", ";\n margin-top: ", ";\n\n display: block;\n .ql-container.ql-snow {\n border: none;\n position: relative;\n }\n .ql-editor {\n padding: 0;\n position: relative;\n }\n\n // Custom placeholder styles - this will show the placeholder value from props\n .ql-editor.ql-blank::before {\n color: #999999 !important;\n font-style: normal !important;\n font-family: \"SFUIText-Medium\" !important;\n font-size: 14px !important;\n left: 0 !important;\n right: auto !important;\n opacity: 1 !important;\n visibility: visible !important;\n display: block !important;\n position: absolute !important;\n content: attr(data-placeholder) !important;\n pointer-events: none !important;\n }\n\n // Ensure placeholder is visible even when not focused\n .ql-editor.ql-blank {\n position: relative;\n\n &::before {\n display: block !important;\n opacity: 1 !important;\n visibility: visible !important;\n }\n }\n\n > label {\n color: #999999;\n font-size: 14px;\n font-family: inherit;\n position: absolute;\n pointer-events: none;\n left: 0px;\n top: 5px;\n transition: 0.2s ease all;\n -moz-transition: 0.2s ease all;\n -webkit-transition: 0.2s ease all;\n }\n > div:focus ~ label {\n top: -10px;\n left: 0px;\n font-size: 10px;\n color: #999999;\n text-transform: capitalize;\n }\n > div ~ label.floaton {\n top: -10px;\n left: 0px;\n font-size: 10px;\n color: #999999;\n text-transform: capitalize;\n }\n"])), function (props) {
|
|
26
|
+
return props.sleek === "sleek" ? "100%" : "92%";
|
|
27
|
+
}, function (props) {
|
|
28
|
+
return props.sleek === "sleek" ? "" : "10px";
|
|
29
|
+
}, function (props) {
|
|
30
|
+
return props.sleek === "sleek" ? "" : "10px";
|
|
31
|
+
});
|
|
32
|
+
var CountWrapper = _styledComponents["default"].div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n position: absolute;\n right: 0px;\n top: 0px;\n background-color: #303f51;\n border-radius: 12px;\n font-size: 12px;\n padding: 5px 10px;\n color: #ffffff;\n"])));
|
|
33
|
+
var RichTextInputError = _styledComponents["default"].span(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n padding-top: 5px;\n display: inline-block;\n font-size: 12px;\n font-family: inherit;\n width: 100%;\n text-align: left;\n"])), function (props) {
|
|
34
|
+
return _tokens.colors[props.theme].inputError.color;
|
|
35
|
+
});
|
|
36
|
+
var RichTextInputV2 = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
37
|
+
var maxLength = _ref.maxLength,
|
|
38
|
+
defaultValue = _ref.defaultValue,
|
|
39
|
+
label = _ref.label,
|
|
40
|
+
showLengthCount = _ref.showLengthCount,
|
|
41
|
+
errorMessage = _ref.errorMessage,
|
|
42
|
+
value = _ref.value,
|
|
43
|
+
autoFocus = _ref.autoFocus,
|
|
44
|
+
onChange = _ref.onChange,
|
|
45
|
+
handleSave = _ref.handleSave,
|
|
46
|
+
editType = _ref.editType,
|
|
47
|
+
hideBorder = _ref.hideBorder,
|
|
48
|
+
type = _ref.type,
|
|
49
|
+
onBlur = _ref.onBlur,
|
|
50
|
+
placeholder = _ref.placeholder,
|
|
51
|
+
isUpdateCase = _ref.isUpdateCase,
|
|
52
|
+
isDisabled = _ref.isDisabled,
|
|
53
|
+
props = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
54
|
+
var _useState = (0, _react.useState)(false),
|
|
55
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
56
|
+
focus = _useState2[0],
|
|
57
|
+
setFocus = _useState2[1];
|
|
58
|
+
var _useState3 = (0, _react.useState)(0),
|
|
59
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
60
|
+
charCount = _useState4[0],
|
|
61
|
+
setCharCount = _useState4[1];
|
|
62
|
+
var quillRef = (0, _react.useRef)(null);
|
|
63
|
+
var quillInstance = (0, _react.useRef)(null);
|
|
64
|
+
var clickedKey = (0, _react.useRef)("");
|
|
65
|
+
var handleFocus = function handleFocus() {
|
|
66
|
+
if (quillInstance.current) {
|
|
67
|
+
var length = quillInstance.current.getLength();
|
|
68
|
+
quillInstance.current.setSelection(length - 1, 0);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var onBlurEvent = function onBlurEvent() {
|
|
72
|
+
if (quillInstance.current) {
|
|
73
|
+
quillInstance.current.blur();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
(0, _react.useImperativeHandle)(ref, function () {
|
|
77
|
+
return {
|
|
78
|
+
getEditorContent: function getEditorContent() {
|
|
79
|
+
if (quillInstance.current) {
|
|
80
|
+
var html = quillInstance.current.root.innerHTML;
|
|
81
|
+
return changeEmToI(html);
|
|
82
|
+
}
|
|
83
|
+
return "";
|
|
84
|
+
},
|
|
85
|
+
setEditorContent: function setEditorContent(content) {
|
|
86
|
+
if (quillInstance.current) {
|
|
87
|
+
var delta = quillInstance.current.clipboard.convert(content); // Convert HTML to Quill's Delta format
|
|
88
|
+
quillInstance.current.setContents(delta); // Set the content in Quill editor
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
handleFocus: handleFocus,
|
|
92
|
+
onBlurEvent: onBlurEvent
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
* @param {*} str
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
var changeEmToI = function changeEmToI(str) {
|
|
102
|
+
var updatedStr = str.replace(/\n/g, "").replace(/<br\s*\/?>/gi, "").replace(/<\/?p>/gi, "").replace(/<[/]?em>/g, function (match) {
|
|
103
|
+
return match === "<em>" ? "<i>" : "</i>";
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Remove surrounding <p> tags if present
|
|
107
|
+
var regex = /^<p(?:[^>]*?)>(.*?)<\/p>$/;
|
|
108
|
+
var match = updatedStr.match(regex);
|
|
109
|
+
return match ? match[1] : updatedStr;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Initialize quill
|
|
113
|
+
(0, _react.useEffect)(function () {
|
|
114
|
+
if (!(quillInstance !== null && quillInstance !== void 0 && quillInstance.current)) {
|
|
115
|
+
var quill = new _quill["default"](quillRef.current, {
|
|
116
|
+
theme: "snow",
|
|
117
|
+
placeholder: placeholder,
|
|
118
|
+
modules: {
|
|
119
|
+
toolbar: false,
|
|
120
|
+
readOnly: isDisabled,
|
|
121
|
+
keyboard: {
|
|
122
|
+
bindings: {
|
|
123
|
+
// This will overwrite the default binding for Tab
|
|
124
|
+
tab: {
|
|
125
|
+
key: 9,
|
|
126
|
+
// Tab key
|
|
127
|
+
handler: function handler() {
|
|
128
|
+
var currentEditor = quillInstance.current.root;
|
|
129
|
+
var editors = document.querySelectorAll(".ql-editor");
|
|
130
|
+
var currentIndex = Array.from(editors).indexOf(currentEditor);
|
|
131
|
+
if (editType === "mainEdit" && currentIndex !== -1 && currentIndex < editors.length - 1) {
|
|
132
|
+
editors[currentIndex + 1].focus();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
// This will handle Shift + Tab
|
|
137
|
+
shiftTab: {
|
|
138
|
+
key: 9,
|
|
139
|
+
// Tab key
|
|
140
|
+
shiftKey: true,
|
|
141
|
+
// Shift key combination
|
|
142
|
+
handler: function handler() {
|
|
143
|
+
var currentEditor = quillInstance.current.root;
|
|
144
|
+
var editors = document.querySelectorAll(".ql-editor");
|
|
145
|
+
var currentIndex = Array.from(editors).indexOf(currentEditor);
|
|
146
|
+
if (editType === "mainEdit" && currentIndex !== -1 && currentIndex > 0) {
|
|
147
|
+
editors[currentIndex - 1].focus(); // Move focus to the previous editor
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Ensure plain text is pasted instead of formatted content
|
|
157
|
+
quill.clipboard.addMatcher(Node.ELEMENT_NODE, function (node, delta) {
|
|
158
|
+
var plainText = node.innerText || node.textContent; // Extract plain text
|
|
159
|
+
return new _quillDelta["default"]().insert(plainText); // Insert plain text without formatting
|
|
160
|
+
});
|
|
161
|
+
quillInstance.current = quill;
|
|
162
|
+
if (quill.root) {
|
|
163
|
+
quill.root.setAttribute("data-placeholder", placeholder);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
var editorRoot = quillInstance.current.root;
|
|
167
|
+
var updateCharCount = function updateCharCount() {
|
|
168
|
+
var text = quillInstance.current.getText().replace(/\n/g, "");
|
|
169
|
+
var characterCount = text.length;
|
|
170
|
+
setCharCount(characterCount);
|
|
171
|
+
var selection = quillInstance.current.getSelection(false);
|
|
172
|
+
if (selection) {
|
|
173
|
+
if (maxLength && characterCount > maxLength) {
|
|
174
|
+
var excessCharacters = characterCount - maxLength;
|
|
175
|
+
var startDeleteIndex = selection.index - excessCharacters;
|
|
176
|
+
var safeDeleteIndex = Math.max(0, startDeleteIndex);
|
|
177
|
+
quillInstance.current.deleteText(safeDeleteIndex, excessCharacters);
|
|
178
|
+
text = quillInstance.current.getText().replace(/\n/g, "");
|
|
179
|
+
characterCount = text.length;
|
|
180
|
+
}
|
|
181
|
+
setCharCount(characterCount);
|
|
182
|
+
var html = quillInstance.current.getSemanticHTML();
|
|
183
|
+
html = changeEmToI((0, _utils.cleanHtml)(html));
|
|
184
|
+
if (onChange && clickedKey.current !== "enter") {
|
|
185
|
+
onChange({
|
|
186
|
+
target: {
|
|
187
|
+
value: html,
|
|
188
|
+
count: characterCount
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
quillInstance.current.on("text-change", updateCharCount);
|
|
195
|
+
var editorContainer = quillInstance.current.root;
|
|
196
|
+
editorContainer.classList.add("quill-editor-content");
|
|
197
|
+
return function () {
|
|
198
|
+
quillInstance.current.off("text-change", updateCharCount);
|
|
199
|
+
quillRef.current.innerHTML = "";
|
|
200
|
+
};
|
|
201
|
+
}, []);
|
|
202
|
+
(0, _react.useEffect)(function () {
|
|
203
|
+
if (quillInstance.current) {
|
|
204
|
+
var editorContainer = quillInstance.current.root;
|
|
205
|
+
var debouncedHandleSave = (0, _lodash.debounce)(function (html) {
|
|
206
|
+
handleSave(html);
|
|
207
|
+
}, 0);
|
|
208
|
+
var handleKeyDown = function handleKeyDown(event) {
|
|
209
|
+
if (event.key === "Enter" && !event.altKey) {
|
|
210
|
+
event.preventDefault();
|
|
211
|
+
event.stopPropagation();
|
|
212
|
+
var html = quillInstance.current.getSemanticHTML();
|
|
213
|
+
html = changeEmToI(html);
|
|
214
|
+
clickedKey.current = "enter";
|
|
215
|
+
debouncedHandleSave(html);
|
|
216
|
+
} else if (event.key === "Backspace" || event.key === "Delete") {
|
|
217
|
+
clickedKey.current = "backspace";
|
|
218
|
+
} else {
|
|
219
|
+
clickedKey.current = "";
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
editorContainer.addEventListener("keydown", handleKeyDown);
|
|
223
|
+
return function () {
|
|
224
|
+
editorContainer.removeEventListener("keydown", handleKeyDown);
|
|
225
|
+
debouncedHandleSave.cancel(); // Clean up debounce
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
}, [quillInstance.current]);
|
|
229
|
+
(0, _react.useEffect)(function () {
|
|
230
|
+
if (quillInstance.current && value !== quillInstance.current.root.innerHTML) {
|
|
231
|
+
var currentContent = changeEmToI((0, _utils.cleanHtml)(quillInstance.current.root.innerHTML));
|
|
232
|
+
if (value && currentContent !== value) {
|
|
233
|
+
var selection = quillInstance.current.getSelection(false);
|
|
234
|
+
var wasFocused = !!selection;
|
|
235
|
+
var content = changeEmToI(value) || "";
|
|
236
|
+
quillInstance.current.clipboard.dangerouslyPasteHTML(content);
|
|
237
|
+
var textLength = quillInstance.current.getLength();
|
|
238
|
+
if (wasFocused) {
|
|
239
|
+
if (selection && selection.index !== 0) {
|
|
240
|
+
quillInstance.current.setSelection(selection.index, selection.length);
|
|
241
|
+
} else if (selection && selection.index === 0 && clickedKey.current === "backspace") {
|
|
242
|
+
quillInstance.current.setSelection(0, 0);
|
|
243
|
+
} else {
|
|
244
|
+
quillInstance.current.setSelection(charCount || textLength - 1, (selection === null || selection === void 0 ? void 0 : selection.length) || 0);
|
|
245
|
+
}
|
|
246
|
+
} else if (isUpdateCase) {
|
|
247
|
+
quillInstance.current.blur();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}, [value, isUpdateCase]);
|
|
252
|
+
return /*#__PURE__*/_react["default"].createElement(RichTextInputDiv, {
|
|
253
|
+
theme: props.theme,
|
|
254
|
+
sleek: type,
|
|
255
|
+
hideBorder: hideBorder,
|
|
256
|
+
inputWidth: props.inputWidth
|
|
257
|
+
}, /*#__PURE__*/_react["default"].createElement(RichTextEditorContainer, (0, _extends2["default"])({
|
|
258
|
+
type: "text",
|
|
259
|
+
value: value,
|
|
260
|
+
defaultValue: defaultValue
|
|
261
|
+
}, props, {
|
|
262
|
+
maxLength: maxLength || "",
|
|
263
|
+
showLengthCount: showLengthCount || false
|
|
264
|
+
}), /*#__PURE__*/_react["default"].createElement("div", {
|
|
265
|
+
ref: quillRef
|
|
266
|
+
})), label && /*#__PURE__*/_react["default"].createElement("label", {
|
|
267
|
+
htmlFor: props.id,
|
|
268
|
+
className: charCount || focus ? "floaton" : ""
|
|
269
|
+
}, "".concat(label).concat(props.required ? "*" : "")), errorMessage && /*#__PURE__*/_react["default"].createElement(RichTextInputError, {
|
|
270
|
+
value: value,
|
|
271
|
+
theme: props.theme,
|
|
272
|
+
error: props.error
|
|
273
|
+
}, errorMessage), maxLength && showLengthCount && quillInstance.current && /*#__PURE__*/_react["default"].createElement(CountWrapper, null, charCount, "/", maxLength));
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
*
|
|
278
|
+
* @param {*} props
|
|
279
|
+
* @returns
|
|
280
|
+
*/
|
|
281
|
+
var returnPadding = function returnPadding(props) {
|
|
282
|
+
if (props.sleek = "sleek") {
|
|
283
|
+
return "0px 0px 4px 0px";
|
|
284
|
+
}
|
|
285
|
+
var digitCount = props.maxLength.toString().length;
|
|
286
|
+
switch (digitCount) {
|
|
287
|
+
case 0:
|
|
288
|
+
return "7px 0px 2px 0px";
|
|
289
|
+
case 1:
|
|
290
|
+
return "7px 40px 2px 0px";
|
|
291
|
+
case 2:
|
|
292
|
+
return "7px 60px 2px 0px";
|
|
293
|
+
case 3:
|
|
294
|
+
return "7px 75px 2px 0px";
|
|
295
|
+
case 4:
|
|
296
|
+
return "7px 90px 2px 0px";
|
|
297
|
+
case 5:
|
|
298
|
+
return "7px 110px 2px 0px";
|
|
299
|
+
default:
|
|
300
|
+
return "7px 0px 2px 0px";
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
var RichTextEditorContainer = _styledComponents["default"].div(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n max-height: 48px;\n overflow-y: scroll;\n ::-webkit-scrollbar {\n width: 0;\n background: transparent;\n }\n white-space: nowrap;\n width: 100%;\n text-wrap: wrap;\n box-sizing: border-box;\n font-family: \"SFUIText-Medium\";\n font-size: 14px;\n color: ", ";\n border-bottom: ", ";\n\n display: inline-block;\n position: relative;\n padding: ", ";\n &:hover {\n border-color: ", ";\n }\n\n &:focus-within {\n border-color: ", ";\n }\n\n &::placeholder {\n color: ", ";\n opacity: ", ";\n transition: 0.2s ease all;\n }\n\n &:focus-within::placeholder {\n color: ", ";\n opacity: ", ";\n }\n"])), function (props) {
|
|
304
|
+
return props.theme === "light" ? _tokens.colors.light.inputCommon.color : _tokens.colors.dark.inputCommon.color;
|
|
305
|
+
}, function (props) {
|
|
306
|
+
return !props.hideBorder ? props.theme === "light" ? _tokens.colors.light.inputCommon.color : _tokens.colors.dark.inputCommon.color : "none";
|
|
307
|
+
}, function (props) {
|
|
308
|
+
return returnPadding(props || "");
|
|
309
|
+
}, function (props) {
|
|
310
|
+
return props.theme === "light" ? _tokens.colors.light.inputCommon.borderHover : _tokens.colors.dark.inputCommon.borderHover;
|
|
311
|
+
}, function (props) {
|
|
312
|
+
return props.theme === "light" ? _tokens.colors.light.inputCommon.borderHover : _tokens.colors.dark.inputCommon.borderHover;
|
|
313
|
+
}, function (props) {
|
|
314
|
+
return props.theme === "light" ? _tokens.colors.light.inputCommon.placeholder : _tokens.colors.dark.inputCommon.placeholder;
|
|
315
|
+
}, function (props) {
|
|
316
|
+
return props.label ? "0" : "1";
|
|
317
|
+
}, function (props) {
|
|
318
|
+
return props.theme === "light" ? _tokens.colors.light.inputCommon.placeholder : _tokens.colors.dark.inputCommon.placeholder;
|
|
319
|
+
}, function (props) {
|
|
320
|
+
return props.label ? "1" : "1";
|
|
321
|
+
});
|
|
322
|
+
RichTextInputV2.propTypes = {
|
|
323
|
+
masked: _propTypes["default"].bool,
|
|
324
|
+
/** Make input readOnly if it does not validate constraint */
|
|
325
|
+
readOnly: _propTypes["default"].bool,
|
|
326
|
+
/** Use when the expected input is code */
|
|
327
|
+
code: _propTypes["default"].bool,
|
|
328
|
+
/** Pass hasError to show error state */
|
|
329
|
+
hasError: _propTypes["default"].bool,
|
|
330
|
+
/** Pass error string directly to show error state */
|
|
331
|
+
error: _propTypes["default"].string,
|
|
332
|
+
/** onChange transparently passed to the input */
|
|
333
|
+
onChange: _propTypes["default"].func,
|
|
334
|
+
onKeyDownFn: _propTypes["default"].func,
|
|
335
|
+
handleSave: _propTypes["default"].func,
|
|
336
|
+
/** Text to display when the input is empty */
|
|
337
|
+
placeholder: _propTypes["default"].string,
|
|
338
|
+
/** The default value for the field */
|
|
339
|
+
defaultValue: _propTypes["default"].string,
|
|
340
|
+
/** The (HTML) type for the input. */
|
|
341
|
+
type: _propTypes["default"].string,
|
|
342
|
+
value: _propTypes["default"].string,
|
|
343
|
+
/** The (HTML) maxLength for the input. */
|
|
344
|
+
maxLength: _propTypes["default"].number,
|
|
345
|
+
inputWidth: _propTypes["default"].number,
|
|
346
|
+
showLengthCount: _propTypes["default"].bool,
|
|
347
|
+
label: _propTypes["default"].string,
|
|
348
|
+
errorMessage: _propTypes["default"].string,
|
|
349
|
+
editType: _propTypes["default"].string,
|
|
350
|
+
id: _propTypes["default"].string,
|
|
351
|
+
simpleEdit: _propTypes["default"].bool,
|
|
352
|
+
required: _propTypes["default"].bool,
|
|
353
|
+
autoFocus: _propTypes["default"].bool,
|
|
354
|
+
theme: _propTypes["default"].oneOf(["light", "dark", "nexc"]),
|
|
355
|
+
fieldType: _propTypes["default"].oneOf(["inputField", "textArea"])
|
|
356
|
+
};
|
|
357
|
+
RichTextInputV2.defaultProps = {
|
|
358
|
+
autoFocus: false,
|
|
359
|
+
fieldType: "textArea",
|
|
360
|
+
readOnly: false,
|
|
361
|
+
code: false,
|
|
362
|
+
error: null,
|
|
363
|
+
onChange: null,
|
|
364
|
+
type: "text",
|
|
365
|
+
theme: "light",
|
|
366
|
+
showLengthCount: false,
|
|
367
|
+
simpleEdit: false
|
|
368
|
+
};
|
|
369
|
+
var _default = exports["default"] = RichTextInputV2;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _RichTextInputV = _interopRequireDefault(require("./RichTextInputV2"));
|
|
9
|
+
var _default = exports["default"] = _RichTextInputV["default"];
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@desynova-digital/components",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"description": "Components for Desynova Digital",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "desynova-digital",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": "desynova-digital",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@desynova-digital/tokens": "9.
|
|
10
|
+
"@desynova-digital/tokens": "9.2.0",
|
|
11
11
|
"prop-types": "^15.7.2",
|
|
12
12
|
"styled-components": "^4.3.2"
|
|
13
13
|
},
|