tiptap-editor-custom-stg 1.0.8 → 1.0.9

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/index.js CHANGED
@@ -115,6 +115,45 @@ var FontSize = import_core.Extension.create({
115
115
  // src/backgroundColor.ts
116
116
  var import_core2 = require("@tiptap/core");
117
117
  var import_extension_text_style2 = require("@tiptap/extension-text-style");
118
+
119
+ // src/utils.ts
120
+ var toHex2 = (n) => n.toString(16).padStart(2, "0");
121
+ function rgbToHex(input) {
122
+ if (!input) return input;
123
+ const m = input.match(
124
+ /^\s*rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)\s*$/i
125
+ );
126
+ if (!m) return input.trim();
127
+ const r = Math.min(255, parseInt(m[1], 10));
128
+ const g = Math.min(255, parseInt(m[2], 10));
129
+ const b = Math.min(255, parseInt(m[3], 10));
130
+ const base = "#" + toHex2(r) + toHex2(g) + toHex2(b);
131
+ if (m[4] === void 0) return base;
132
+ const a = Math.max(0, Math.min(1, parseFloat(m[4])));
133
+ if (a >= 1) return base;
134
+ return base + toHex2(Math.round(a * 255));
135
+ }
136
+ function normalizeColorsInHtml(html) {
137
+ if (!html) return html;
138
+ return html.replace(
139
+ /rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+(?:\s*,\s*[\d.]+)?\s*\)/gi,
140
+ (match) => rgbToHex(match)
141
+ );
142
+ }
143
+ async function uploadFileToCOS(file, docNum, onUploadFile, receiveStatus, elementId, onLoadingChange, suppressStatusChange = false) {
144
+ receiveStatus && elementId && receiveStatus(elementId, true);
145
+ if (!suppressStatusChange) onLoadingChange == null ? void 0 : onLoadingChange(true);
146
+ try {
147
+ const url = await onUploadFile(file, docNum);
148
+ if (!url) throw new Error("Upload failed: no URL returned");
149
+ return url;
150
+ } finally {
151
+ if (!suppressStatusChange) onLoadingChange == null ? void 0 : onLoadingChange(false);
152
+ receiveStatus && elementId && receiveStatus(elementId, false);
153
+ }
154
+ }
155
+
156
+ // src/backgroundColor.ts
118
157
  var BackgroundColor = import_core2.Extension.create({
119
158
  name: "backgroundColor",
120
159
  addOptions() {
@@ -129,13 +168,13 @@ var BackgroundColor = import_core2.Extension.create({
129
168
  attributes: {
130
169
  backgroundColor: {
131
170
  default: null,
132
- parseHTML: (element) => element.style.backgroundColor.replace(/['"]+/g, ""),
171
+ parseHTML: (element) => rgbToHex(element.style.backgroundColor.replace(/['"]+/g, "")),
133
172
  renderHTML: (attributes) => {
134
173
  if (!attributes.backgroundColor) {
135
174
  return {};
136
175
  }
137
176
  return {
138
- style: `background-color: ${attributes.backgroundColor}`
177
+ style: `background-color: ${rgbToHex(attributes.backgroundColor)}`
139
178
  };
140
179
  }
141
180
  }
@@ -187,20 +226,6 @@ var createTiptapExtensions = (placeholder = "Enter content here...") => [
187
226
  import_extension_table_cell.TableCell
188
227
  ];
189
228
 
190
- // src/utils.ts
191
- async function uploadFileToCOS(file, docNum, onUploadFile, receiveStatus, elementId, onLoadingChange, suppressStatusChange = false) {
192
- receiveStatus && elementId && receiveStatus(elementId, true);
193
- if (!suppressStatusChange) onLoadingChange == null ? void 0 : onLoadingChange(true);
194
- try {
195
- const url = await onUploadFile(file, docNum);
196
- if (!url) throw new Error("Upload failed: no URL returned");
197
- return url;
198
- } finally {
199
- if (!suppressStatusChange) onLoadingChange == null ? void 0 : onLoadingChange(false);
200
- receiveStatus && elementId && receiveStatus(elementId, false);
201
- }
202
- }
203
-
204
229
  // src/constants.ts
205
230
  var TIPTAP_COLORS = [
206
231
  "#000000",
@@ -975,7 +1000,8 @@ var isEmptyRichTextHtml = (html) => {
975
1000
  };
976
1001
  var getNormalizedEditorHtml = (editor) => {
977
1002
  const html = editor.getHTML();
978
- return isEmptyRichTextHtml(html) ? "" : html;
1003
+ if (isEmptyRichTextHtml(html)) return "";
1004
+ return normalizeColorsInHtml(html);
979
1005
  };
980
1006
  var TiptapEditor = ({
981
1007
  elementId,