@desynova-digital/components 9.1.1 → 9.1.2

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/_helpers/utils.js CHANGED
@@ -20,16 +20,16 @@ function timeToSeconds() {
20
20
  }
21
21
  var cleanHtml = exports.cleanHtml = function cleanHtml(htmlStr) {
22
22
  return htmlStr.replace(/"/g, '"') // Replace " with "
23
- .replace(/ /g, " ") // Replace   with a space
24
- .replace(/'|'/g, "'") // Replace ' and ' with '
25
- .replace(/&|&;/g, "&") // Replace & and &; with &
26
- .replace(/&lt;/g, "<") // Replace &lt; with <
27
- .replace(/&gt;/g, ">") // Replace &gt; with >
23
+ .replace(/&nbsp;/g, ' ') // Replace &nbsp; with a space
24
+ .replace(/&apos;|&#x27;|&#39;/g, "'") // Replace &apos; and &#x27; with '
25
+ .replace(/&amp;|&;/g, '&') // Replace &amp; and &; with &
26
+ .replace(/&lt;/g, '<') // Replace &lt; with <
27
+ .replace(/&gt;/g, '>') // Replace &gt; with >
28
28
  .replace(/[\u2018\u2019]/g, "'") // Replace special single quotes
29
29
  .replace(/[\u201C\u201D]/g, '"') // Replace special double quotes
30
- .replace(/<br\s*\/?>/gi, "") // Remove <br> tags
31
- .replace(/\s{2,}/g, " ") // Replace multiple spaces with a single space
32
- .replace(/\s\s+/g, "").replace(/\t/g, "").replace(/\n/g, " ");
30
+ .replace(/<br\s*\/?>/gi, '') // Remove <br> tags
31
+ .replace(/\s{2,}/g, ' ') // Replace multiple spaces with a single space
32
+ .replace(/\s\s+/g, '').replace(/\t/g, '').replace(/\\"/g, '"').replace(/\n/g, ' ');
33
33
  };
34
34
 
35
35
  /**
@@ -16,6 +16,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
16
16
  var _styledComponents = _interopRequireDefault(require("styled-components"));
17
17
  var _tokens = require("@desynova-digital/tokens");
18
18
  var _lodash = require("lodash");
19
+ var _quillDelta = _interopRequireDefault(require("quill-delta"));
19
20
  var _utils = require("../../_helpers/utils");
20
21
  var _excluded = ["maxLength", "defaultValue", "label", "showLengthCount", "errorMessage", "value", "autoFocus", "onChange", "handleSave", "editType"];
21
22
  var _templateObject, _templateObject2, _templateObject3, _templateObject4;
@@ -48,7 +49,7 @@ var RichTextInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
48
49
  setCharCount = _useState4[1];
49
50
  var quillRef = (0, _react.useRef)(null);
50
51
  var quillInstance = (0, _react.useRef)(null);
51
- var clickedKey = (0, _react.useRef)("");
52
+ var clickedKey = (0, _react.useRef)('');
52
53
  (0, _react.useImperativeHandle)(ref, function () {
53
54
  return {
54
55
  getEditorContent: function getEditorContent() {
@@ -56,7 +57,7 @@ var RichTextInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
56
57
  var html = quillInstance.current.root.innerHTML;
57
58
  return changeEmToI(html);
58
59
  }
59
- return "";
60
+ return '';
60
61
  },
61
62
  setEditorContent: function setEditorContent(content) {
62
63
  if (quillInstance.current) {
@@ -73,8 +74,8 @@ var RichTextInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
73
74
  * @returns
74
75
  */
75
76
  var changeEmToI = function changeEmToI(str) {
76
- var updatedStr = str.replace(/\n/g, "").replace(/<br\s*\/?>/gi, "").replace(/<\/?p>/gi, "").replace(/<[/]?em>/g, function (match) {
77
- return match === "<em>" ? "<i>" : "</i>";
77
+ var updatedStr = str.replace(/\n/g, '').replace(/<br\s*\/?>/gi, '').replace(/<\/?p>/gi, '').replace(/<[/]?em>/g, function (match) {
78
+ return match === '<em>' ? '<i>' : '</i>';
78
79
  });
79
80
 
80
81
  // Remove surrounding <p> tags if present
@@ -83,11 +84,11 @@ var RichTextInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
83
84
  return match ? match[1] : updatedStr;
84
85
  };
85
86
 
86
- // Initialize Quill
87
+ // Initialize quill
87
88
  (0, _react.useEffect)(function () {
88
89
  if (!(quillInstance !== null && quillInstance !== void 0 && quillInstance.current)) {
89
90
  var quill = new _quill["default"](quillRef.current, {
90
- theme: "snow",
91
+ theme: 'snow',
91
92
  modules: {
92
93
  toolbar: false,
93
94
  keyboard: {
@@ -98,9 +99,9 @@ var RichTextInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
98
99
  // Tab key
99
100
  handler: function handler() {
100
101
  var currentEditor = quillInstance.current.root;
101
- var editors = document.querySelectorAll(".ql-editor");
102
+ var editors = document.querySelectorAll('.ql-editor');
102
103
  var currentIndex = Array.from(editors).indexOf(currentEditor);
103
- if (editType === "mainEdit" && currentIndex !== -1 && currentIndex < editors.length - 1) {
104
+ if (editType === 'mainEdit' && currentIndex !== -1 && currentIndex < editors.length - 1) {
104
105
  editors[currentIndex + 1].focus();
105
106
  }
106
107
  }
@@ -113,9 +114,9 @@ var RichTextInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
113
114
  // Shift key combination
114
115
  handler: function handler() {
115
116
  var currentEditor = quillInstance.current.root;
116
- var editors = document.querySelectorAll(".ql-editor");
117
+ var editors = document.querySelectorAll('.ql-editor');
117
118
  var currentIndex = Array.from(editors).indexOf(currentEditor);
118
- if (editType === "mainEdit" && currentIndex !== -1 && currentIndex > 0) {
119
+ if (editType === 'mainEdit' && currentIndex !== -1 && currentIndex > 0) {
119
120
  editors[currentIndex - 1].focus(); // Move focus to the previous editor
120
121
  }
121
122
  }
@@ -124,6 +125,12 @@ var RichTextInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
124
125
  }
125
126
  }
126
127
  });
128
+
129
+ // Ensure plain text is pasted instead of formatted content
130
+ quill.clipboard.addMatcher(Node.ELEMENT_NODE, function (node, delta) {
131
+ var plainText = node.innerText || node.textContent; // Extract plain text
132
+ return new _quillDelta["default"]().insert(plainText); // Insert plain text without formatting
133
+ });
127
134
  quillInstance.current = quill;
128
135
  }
129
136
  var handleFocus = function handleFocus() {
@@ -131,9 +138,9 @@ var RichTextInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
131
138
  quillInstance.current.setSelection(length - 1, 0);
132
139
  };
133
140
  var editorRoot = quillInstance.current.root;
134
- editorRoot.addEventListener("focus", handleFocus);
141
+ editorRoot.addEventListener('focus', handleFocus);
135
142
  var updateCharCount = function updateCharCount() {
136
- var text = quillInstance.current.getText().replace(/\n/g, "");
143
+ var text = quillInstance.current.getText().replace(/\n/g, '');
137
144
  var characterCount = text.length;
138
145
  setCharCount(characterCount);
139
146
  var selection = quillInstance.current.getSelection();
@@ -143,13 +150,13 @@ var RichTextInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
143
150
  var startDeleteIndex = selection.index - excessCharacters;
144
151
  var safeDeleteIndex = Math.max(0, startDeleteIndex);
145
152
  quillInstance.current.deleteText(safeDeleteIndex, excessCharacters);
146
- text = quillInstance.current.getText().replace(/\n/g, "");
153
+ text = quillInstance.current.getText().replace(/\n/g, '');
147
154
  characterCount = text.length;
148
155
  }
149
156
  setCharCount(characterCount);
150
157
  var html = quillInstance.current.getSemanticHTML();
151
- html = changeEmToI(html);
152
- if (onChange && clickedKey.current !== "enter") {
158
+ html = changeEmToI((0, _utils.cleanHtml)(html));
159
+ if (onChange && clickedKey.current !== 'enter') {
153
160
  onChange({
154
161
  target: {
155
162
  value: html,
@@ -159,13 +166,13 @@ var RichTextInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
159
166
  }
160
167
  }
161
168
  };
162
- quillInstance.current.on("text-change", updateCharCount);
169
+ quillInstance.current.on('text-change', updateCharCount);
163
170
  var editorContainer = quillInstance.current.root;
164
- editorContainer.classList.add("quill-editor-content");
171
+ editorContainer.classList.add('quill-editor-content');
165
172
  return function () {
166
- quillInstance.current.off("text-change", updateCharCount);
167
- quillRef.current.innerHTML = "";
168
- editorRoot.removeEventListener("focus", handleFocus);
173
+ quillInstance.current.off('text-change', updateCharCount);
174
+ quillRef.current.innerHTML = '';
175
+ editorRoot.removeEventListener('focus', handleFocus);
169
176
  };
170
177
  }, []);
171
178
 
@@ -181,21 +188,21 @@ var RichTextInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
181
188
  handleSave(html);
182
189
  }, 0);
183
190
  var handleKeyDown = function handleKeyDown(event) {
184
- if (event.key === "Enter") {
191
+ if (event.key === 'Enter') {
185
192
  event.preventDefault();
186
193
  var html = quillInstance.current.getSemanticHTML();
187
194
  html = changeEmToI(html);
188
- clickedKey.current = "enter";
195
+ clickedKey.current = 'enter';
189
196
  debouncedHandleSave(html);
190
- } else if (event.key === "Backspace" || event.key === "Delete") {
191
- clickedKey.current = "backspace";
197
+ } else if (event.key === 'Backspace' || event.key === 'Delete') {
198
+ clickedKey.current = 'backspace';
192
199
  } else {
193
- clickedKey.current = "";
200
+ clickedKey.current = '';
194
201
  }
195
202
  };
196
- editorContainer.addEventListener("keydown", handleKeyDown);
203
+ editorContainer.addEventListener('keydown', handleKeyDown);
197
204
  return function () {
198
- editorContainer.removeEventListener("keydown", handleKeyDown);
205
+ editorContainer.removeEventListener('keydown', handleKeyDown);
199
206
  debouncedHandleSave.cancel(); // Clean up debounce
200
207
  };
201
208
  }
@@ -208,22 +215,22 @@ var RichTextInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
208
215
  if (value && currentContent !== value) {
209
216
  var selection = quillInstance.current.getSelection(); // Capture cursor position
210
217
 
211
- var content = changeEmToI(value) || "";
218
+ var content = changeEmToI(value) || '';
212
219
  quillInstance.current.clipboard.dangerouslyPasteHTML(content); // Insert HTML content in Quill editor
213
220
  var textLength = quillInstance.current.getLength();
214
221
  if (selection && selection.index !== 0) {
215
222
  quillInstance.current.setSelection(selection.index, selection.length); // Restore previous cursor position
216
- } else if (selection && selection.index === 0 && clickedKey.current === "backspace") {
223
+ } else if (selection && selection.index === 0 && clickedKey.current === 'backspace') {
217
224
  quillInstance.current.setSelection(0, 0); // Keep cursor at start when pressing backspace
218
225
  } else {
219
226
  quillInstance.current.setSelection(charCount || textLength - 1, (selection === null || selection === void 0 ? void 0 : selection.length) || 0); // Move cursor right for other cases
220
227
 
221
- if (editType === "mainEdit" && !selection) {
228
+ if (editType === 'mainEdit' && !selection) {
222
229
  quillInstance.current.blur();
223
230
  // Select the first video element
224
- var videoElement = document.getElementsByTagName("video")[0];
231
+ var videoElement = document.getElementsByTagName('video')[0];
225
232
  // Add a tabindex attribute to make it focusable
226
- videoElement.setAttribute("tabindex", "0");
233
+ videoElement.setAttribute('tabindex', '0');
227
234
  videoElement.focus();
228
235
  }
229
236
  }
@@ -247,14 +254,14 @@ var RichTextInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
247
254
  value: value,
248
255
  defaultValue: defaultValue
249
256
  }, props, {
250
- maxLength: maxLength || "",
257
+ maxLength: maxLength || '',
251
258
  showLengthCount: showLengthCount || false
252
259
  }), /*#__PURE__*/_react["default"].createElement("div", {
253
260
  ref: quillRef
254
261
  })), label && /*#__PURE__*/_react["default"].createElement("label", {
255
262
  htmlFor: props.id,
256
- className: charCount || focus ? "floaton" : ""
257
- }, "".concat(label).concat(props.required ? "*" : "")), errorMessage && /*#__PURE__*/_react["default"].createElement(RichTextInputError, {
263
+ className: charCount || focus ? 'floaton' : ''
264
+ }, "".concat(label).concat(props.required ? '*' : '')), errorMessage && /*#__PURE__*/_react["default"].createElement(RichTextInputError, {
258
265
  value: value,
259
266
  theme: props.theme,
260
267
  error: props.error
@@ -270,39 +277,39 @@ var returnPadding = function returnPadding(props) {
270
277
  var digitCount = props.maxLength.toString().length;
271
278
  switch (digitCount) {
272
279
  case 0:
273
- return "7px 0px 2px 0px";
280
+ return '7px 0px 2px 0px';
274
281
  case 1:
275
- return "7px 40px 2px 0px";
282
+ return '7px 40px 2px 0px';
276
283
  case 2:
277
- return "7px 60px 2px 0px";
284
+ return '7px 60px 2px 0px';
278
285
  case 3:
279
- return "7px 75px 2px 0px";
286
+ return '7px 75px 2px 0px';
280
287
  case 4:
281
- return "7px 90px 2px 0px";
288
+ return '7px 90px 2px 0px';
282
289
  case 5:
283
- return "7px 110px 2px 0px";
290
+ return '7px 110px 2px 0px';
284
291
  default:
285
- return "7px 0px 2px 0px";
292
+ return '7px 0px 2px 0px';
286
293
  }
287
294
  };
288
295
  var RichTextEditorContainer = _styledComponents["default"].div(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n max-height: 48px;\n overflow-y: scroll;\n ::-webkit-scrollbar {\n width: 0; /* Remove scrollbar space */\n background: transparent; /* Optional: just make scrollbar invisible */\n }\n white-space: nowrap;\n width: 100%;\n text-wrap: wrap;\n box-sizing: border-box;\n border-bottom: 1px solid\n ", ";\n\n font-family: \"SFUIText-Medium\";\n font-size: 14px;\n color: ", ";\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) {
289
- return props.theme === "light" ? _tokens.colors.light.inputCommon.border : _tokens.colors.dark.inputCommon.border;
296
+ return props.theme === 'light' ? _tokens.colors.light.inputCommon.border : _tokens.colors.dark.inputCommon.border;
290
297
  }, function (props) {
291
- return props.theme === "light" ? _tokens.colors.light.inputCommon.color : _tokens.colors.dark.inputCommon.color;
298
+ return props.theme === 'light' ? _tokens.colors.light.inputCommon.color : _tokens.colors.dark.inputCommon.color;
292
299
  }, function (props) {
293
- return returnPadding(props || "");
300
+ return returnPadding(props || '');
294
301
  }, function (props) {
295
- return props.theme === "light" ? _tokens.colors.light.inputCommon.borderHover : _tokens.colors.dark.inputCommon.borderHover;
302
+ return props.theme === 'light' ? _tokens.colors.light.inputCommon.borderHover : _tokens.colors.dark.inputCommon.borderHover;
296
303
  }, function (props) {
297
- return props.theme === "light" ? _tokens.colors.light.inputCommon.borderHover : _tokens.colors.dark.inputCommon.borderHover;
304
+ return props.theme === 'light' ? _tokens.colors.light.inputCommon.borderHover : _tokens.colors.dark.inputCommon.borderHover;
298
305
  }, function (props) {
299
- return props.theme === "light" ? _tokens.colors.light.inputCommon.placeholder : _tokens.colors.dark.inputCommon.placeholder;
306
+ return props.theme === 'light' ? _tokens.colors.light.inputCommon.placeholder : _tokens.colors.dark.inputCommon.placeholder;
300
307
  }, function (props) {
301
- return props.label ? "0" : "1";
308
+ return props.label ? '0' : '1';
302
309
  }, function (props) {
303
- return props.theme === "light" ? _tokens.colors.light.inputCommon.placeholder : _tokens.colors.dark.inputCommon.placeholder;
310
+ return props.theme === 'light' ? _tokens.colors.light.inputCommon.placeholder : _tokens.colors.dark.inputCommon.placeholder;
304
311
  }, function (props) {
305
- return props.label ? "1" : "1";
312
+ return props.label ? '1' : '1';
306
313
  });
307
314
  RichTextInput.propTypes = {
308
315
  masked: _propTypes["default"].bool,
@@ -336,18 +343,18 @@ RichTextInput.propTypes = {
336
343
  simpleEdit: _propTypes["default"].bool,
337
344
  required: _propTypes["default"].bool,
338
345
  autoFocus: _propTypes["default"].bool,
339
- theme: _propTypes["default"].oneOf(["light", "dark", "nexc"]),
340
- fieldType: _propTypes["default"].oneOf(["inputField", "textArea"])
346
+ theme: _propTypes["default"].oneOf(['light', 'dark', 'nexc']),
347
+ fieldType: _propTypes["default"].oneOf(['inputField', 'textArea'])
341
348
  };
342
349
  RichTextInput.defaultProps = {
343
350
  autoFocus: false,
344
- fieldType: "textArea",
351
+ fieldType: 'textArea',
345
352
  readOnly: false,
346
353
  code: false,
347
354
  error: null,
348
355
  onChange: null,
349
- type: "text",
350
- theme: "light",
356
+ type: 'text',
357
+ theme: 'light',
351
358
  showLengthCount: false,
352
359
  simpleEdit: false
353
360
  };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@desynova-digital/components",
3
- "version": "9.1.1",
3
+ "version": "9.1.2",
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.1.1",
10
+ "@desynova-digital/tokens": "9.1.2",
11
11
  "prop-types": "^15.7.2",
12
12
  "styled-components": "^4.3.2"
13
13
  },