@tarviks/lexical-rich-editor 1.0.7 → 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.mjs CHANGED
@@ -5032,10 +5032,16 @@ var PRESET = [
5032
5032
  ];
5033
5033
  var clamp3 = (v, min, max) => Math.min(max, Math.max(min, v));
5034
5034
  var normalizeHex = (v) => {
5035
- let s = (v ?? "").trim();
5035
+ const s = (v ?? "").trim();
5036
5036
  if (!s) return "#000000";
5037
- if (!s.startsWith("#")) s = `#${s}`;
5038
- if (s.length === 4 || s.length === 7) return s;
5037
+ const rgbMatch = s.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*[\d.]+\s*)?\)$/i);
5038
+ if (rgbMatch) {
5039
+ const [, r, g, b] = rgbMatch;
5040
+ return rgbToHex(clamp3(+r, 0, 255), clamp3(+g, 0, 255), clamp3(+b, 0, 255));
5041
+ }
5042
+ let hex = s.startsWith("#") ? s : `#${s}`;
5043
+ if (hex.length === 9) hex = hex.slice(0, 7);
5044
+ if (hex.length === 4 || hex.length === 7) return hex.toLowerCase();
5039
5045
  return "#000000";
5040
5046
  };
5041
5047
  var hexToRgb = (hex) => {
@@ -5156,11 +5162,21 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
5156
5162
  const [s, setS] = React9.useState(hsv.s);
5157
5163
  const [v, setV] = React9.useState(hsv.v);
5158
5164
  const wasOpenRef = React9.useRef(open);
5165
+ console.log("[AO-ColorPicker]", title, "render with incoming value prop:", JSON.stringify(value));
5159
5166
  React9.useEffect(() => {
5160
5167
  const justOpened = open && !wasOpenRef.current;
5161
5168
  wasOpenRef.current = open;
5169
+ console.log("[AO-ColorPicker]", title, "open-seed effect", {
5170
+ open,
5171
+ justOpened,
5172
+ incomingValue: value
5173
+ });
5162
5174
  if (!justOpened) return;
5163
5175
  const n = normalizeHex(value || "#000000");
5176
+ console.log("[AO-ColorPicker]", title, "seeding local state from value on open", {
5177
+ incomingValue: value,
5178
+ normalized: n
5179
+ });
5164
5180
  setHex(n);
5165
5181
  const rgb = hexToRgb(n);
5166
5182
  const next = rgbToHsv(rgb.r, rgb.g, rgb.b);
@@ -5173,10 +5189,11 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
5173
5189
  const rgb = hsvToRgb(hh, ss, vv);
5174
5190
  const nextHex = rgbToHex(rgb.r, rgb.g, rgb.b);
5175
5191
  setHex(nextHex);
5192
+ console.log("[AO-ColorPicker]", title, "commitHsv -> onChange", { nextHex, close: !!close });
5176
5193
  onChange(nextHex);
5177
5194
  if (close) setOpen(false);
5178
5195
  },
5179
- [onChange]
5196
+ [onChange, title]
5180
5197
  );
5181
5198
  const svRef = React9.useRef(null);
5182
5199
  const onSVMove = React9.useCallback(
@@ -5217,6 +5234,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
5217
5234
  /* @__PURE__ */ jsx(
5218
5235
  Button,
5219
5236
  {
5237
+ type: "button",
5220
5238
  size: "small",
5221
5239
  icon,
5222
5240
  value: title,
@@ -5230,6 +5248,10 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
5230
5248
  },
5231
5249
  onClick: () => {
5232
5250
  if (disabled) return;
5251
+ console.log("[AO-ColorPicker]", title, "trigger button clicked", {
5252
+ wasOpen: open,
5253
+ activeElementBeforeToggle: document.activeElement?.tagName
5254
+ });
5233
5255
  setOpen((p) => !p);
5234
5256
  }
5235
5257
  }
@@ -5280,6 +5302,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
5280
5302
  setH(next.h);
5281
5303
  setS(next.s);
5282
5304
  setV(next.v);
5305
+ console.log("[AO-ColorPicker]", title, "hex field blur -> onChange", { raw: hex, normalized: n });
5283
5306
  onChange(n);
5284
5307
  }
5285
5308
  }
@@ -5298,6 +5321,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
5298
5321
  setH(next.h);
5299
5322
  setS(next.s);
5300
5323
  setV(next.v);
5324
+ console.log("[AO-ColorPicker]", title, "preset swatch click -> onChange", { color: c });
5301
5325
  onChange(c);
5302
5326
  },
5303
5327
  title: c
@@ -5316,13 +5340,14 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
5316
5340
  /* @__PURE__ */ jsx(
5317
5341
  DefaultButton,
5318
5342
  {
5343
+ type: "button",
5319
5344
  text: "Apply",
5320
5345
  onClick: () => {
5321
5346
  commitHsv(h, s, v, true);
5322
5347
  }
5323
5348
  }
5324
5349
  ),
5325
- /* @__PURE__ */ jsx(DefaultButton, { text: "Close", onClick: () => setOpen(false) })
5350
+ /* @__PURE__ */ jsx(DefaultButton, { type: "button", text: "Close", onClick: () => setOpen(false) })
5326
5351
  ] })
5327
5352
  ] })
5328
5353
  }
@@ -5335,10 +5360,20 @@ var ColorPickerPlugin = ({ disabled }) => {
5335
5360
  const lastRangeSelectionRef = React9__default.useRef(null);
5336
5361
  const updateToolbar = () => {
5337
5362
  const selection = $getSelection();
5338
- if ($isRangeSelection(selection)) {
5363
+ const isRange = $isRangeSelection(selection);
5364
+ console.log("[AO-ColorPicker] updateToolbar", {
5365
+ isRangeSelection: isRange,
5366
+ isCollapsed: isRange ? selection.isCollapsed() : null
5367
+ });
5368
+ if (isRange) {
5339
5369
  lastRangeSelectionRef.current = selection.clone();
5340
5370
  const c = $getSelectionStyleValueForProperty(selection, "color", "#000000");
5341
- const bg = $getSelectionStyleValueForProperty(selection, "background-color", "#ffffff");
5371
+ const bg = $getSelectionStyleValueForProperty(
5372
+ selection,
5373
+ "background-color",
5374
+ "#ffffff"
5375
+ );
5376
+ console.log("[AO-ColorPicker] updateToolbar readback", { color: c, bgColor: bg });
5342
5377
  setColors({ color: c, bgColor: bg });
5343
5378
  }
5344
5379
  };
@@ -5361,6 +5396,17 @@ var ColorPickerPlugin = ({ disabled }) => {
5361
5396
  if (disabled) return;
5362
5397
  const root = editor.getRootElement();
5363
5398
  const editorIsActive = !!lastRangeSelectionRef.current && !!root && (document.activeElement === root || root.contains(document.activeElement));
5399
+ console.log("[AO-ColorPicker] applyStyle called", {
5400
+ property: args.property,
5401
+ color: args.color,
5402
+ hasSavedSelection: !!lastRangeSelectionRef.current,
5403
+ savedSelectionIsCollapsed: lastRangeSelectionRef.current?.isCollapsed() ?? null,
5404
+ editorIsActive,
5405
+ activeElementTag: document.activeElement?.tagName,
5406
+ activeElementClass: document.activeElement?.className,
5407
+ rootIsActiveElement: document.activeElement === root,
5408
+ rootContainsActiveElement: !!root && root.contains(document.activeElement)
5409
+ });
5364
5410
  if (editorIsActive) editor.focus();
5365
5411
  editor.update(() => {
5366
5412
  const saved = lastRangeSelectionRef.current;
@@ -5368,8 +5414,29 @@ var ColorPickerPlugin = ({ disabled }) => {
5368
5414
  $setSelection(saved.clone());
5369
5415
  }
5370
5416
  const selection = $getSelection();
5371
- if ($isRangeSelection(selection)) {
5417
+ const isRange = $isRangeSelection(selection);
5418
+ console.log("[AO-ColorPicker] applyStyle inside editor.update", {
5419
+ hadSavedSelection: !!saved,
5420
+ selectionAfterRestoreIsRange: isRange,
5421
+ selectionAfterRestoreIsCollapsed: isRange ? selection.isCollapsed() : null
5422
+ });
5423
+ if (isRange) {
5372
5424
  $patchStyleText(selection, { [args.property]: args.color });
5425
+ const verify = $getSelectionStyleValueForProperty(
5426
+ selection,
5427
+ args.property,
5428
+ "<none>"
5429
+ );
5430
+ console.log("[AO-ColorPicker] applyStyle after patchStyleText, readback in same update", {
5431
+ property: args.property,
5432
+ appliedColor: args.color,
5433
+ readBack: verify
5434
+ });
5435
+ } else {
5436
+ console.warn(
5437
+ "[AO-ColorPicker] applyStyle: no range selection available \u2014 style was NOT applied",
5438
+ { property: args.property, color: args.color }
5439
+ );
5373
5440
  }
5374
5441
  });
5375
5442
  };
@@ -6713,6 +6780,12 @@ function FocusEventsPlugin({
6713
6780
  const next = e.relatedTarget;
6714
6781
  const container = containerRef.current;
6715
6782
  const stillInside = !!next && (container ? container.contains(next) : root.contains(next));
6783
+ console.log("[AO-ColorPicker] FocusEventsPlugin focusout", {
6784
+ relatedTargetTag: next ? next.tagName : null,
6785
+ relatedTargetClass: next ? next.className : null,
6786
+ stillInside,
6787
+ willClearSelection: !stillInside
6788
+ });
6716
6789
  if (stillInside) return;
6717
6790
  editor.update(() => {
6718
6791
  $setSelection(null);