@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.js CHANGED
@@ -5053,10 +5053,16 @@ var PRESET = [
5053
5053
  ];
5054
5054
  var clamp3 = (v, min, max) => Math.min(max, Math.max(min, v));
5055
5055
  var normalizeHex = (v) => {
5056
- let s = (v ?? "").trim();
5056
+ const s = (v ?? "").trim();
5057
5057
  if (!s) return "#000000";
5058
- if (!s.startsWith("#")) s = `#${s}`;
5059
- if (s.length === 4 || s.length === 7) return s;
5058
+ const rgbMatch = s.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*[\d.]+\s*)?\)$/i);
5059
+ if (rgbMatch) {
5060
+ const [, r, g, b] = rgbMatch;
5061
+ return rgbToHex(clamp3(+r, 0, 255), clamp3(+g, 0, 255), clamp3(+b, 0, 255));
5062
+ }
5063
+ let hex = s.startsWith("#") ? s : `#${s}`;
5064
+ if (hex.length === 9) hex = hex.slice(0, 7);
5065
+ if (hex.length === 4 || hex.length === 7) return hex.toLowerCase();
5060
5066
  return "#000000";
5061
5067
  };
5062
5068
  var hexToRgb = (hex) => {
@@ -5177,11 +5183,21 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
5177
5183
  const [s, setS] = React9__namespace.useState(hsv.s);
5178
5184
  const [v, setV] = React9__namespace.useState(hsv.v);
5179
5185
  const wasOpenRef = React9__namespace.useRef(open);
5186
+ console.log("[AO-ColorPicker]", title, "render with incoming value prop:", JSON.stringify(value));
5180
5187
  React9__namespace.useEffect(() => {
5181
5188
  const justOpened = open && !wasOpenRef.current;
5182
5189
  wasOpenRef.current = open;
5190
+ console.log("[AO-ColorPicker]", title, "open-seed effect", {
5191
+ open,
5192
+ justOpened,
5193
+ incomingValue: value
5194
+ });
5183
5195
  if (!justOpened) return;
5184
5196
  const n = normalizeHex(value || "#000000");
5197
+ console.log("[AO-ColorPicker]", title, "seeding local state from value on open", {
5198
+ incomingValue: value,
5199
+ normalized: n
5200
+ });
5185
5201
  setHex(n);
5186
5202
  const rgb = hexToRgb(n);
5187
5203
  const next = rgbToHsv(rgb.r, rgb.g, rgb.b);
@@ -5194,10 +5210,11 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
5194
5210
  const rgb = hsvToRgb(hh, ss, vv);
5195
5211
  const nextHex = rgbToHex(rgb.r, rgb.g, rgb.b);
5196
5212
  setHex(nextHex);
5213
+ console.log("[AO-ColorPicker]", title, "commitHsv -> onChange", { nextHex, close: !!close });
5197
5214
  onChange(nextHex);
5198
5215
  if (close) setOpen(false);
5199
5216
  },
5200
- [onChange]
5217
+ [onChange, title]
5201
5218
  );
5202
5219
  const svRef = React9__namespace.useRef(null);
5203
5220
  const onSVMove = React9__namespace.useCallback(
@@ -5238,6 +5255,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
5238
5255
  /* @__PURE__ */ jsxRuntime.jsx(
5239
5256
  reactComponents.Button,
5240
5257
  {
5258
+ type: "button",
5241
5259
  size: "small",
5242
5260
  icon,
5243
5261
  value: title,
@@ -5251,6 +5269,10 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
5251
5269
  },
5252
5270
  onClick: () => {
5253
5271
  if (disabled) return;
5272
+ console.log("[AO-ColorPicker]", title, "trigger button clicked", {
5273
+ wasOpen: open,
5274
+ activeElementBeforeToggle: document.activeElement?.tagName
5275
+ });
5254
5276
  setOpen((p) => !p);
5255
5277
  }
5256
5278
  }
@@ -5301,6 +5323,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
5301
5323
  setH(next.h);
5302
5324
  setS(next.s);
5303
5325
  setV(next.v);
5326
+ console.log("[AO-ColorPicker]", title, "hex field blur -> onChange", { raw: hex, normalized: n });
5304
5327
  onChange(n);
5305
5328
  }
5306
5329
  }
@@ -5319,6 +5342,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
5319
5342
  setH(next.h);
5320
5343
  setS(next.s);
5321
5344
  setV(next.v);
5345
+ console.log("[AO-ColorPicker]", title, "preset swatch click -> onChange", { color: c });
5322
5346
  onChange(c);
5323
5347
  },
5324
5348
  title: c
@@ -5337,13 +5361,14 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
5337
5361
  /* @__PURE__ */ jsxRuntime.jsx(
5338
5362
  react.DefaultButton,
5339
5363
  {
5364
+ type: "button",
5340
5365
  text: "Apply",
5341
5366
  onClick: () => {
5342
5367
  commitHsv(h, s, v, true);
5343
5368
  }
5344
5369
  }
5345
5370
  ),
5346
- /* @__PURE__ */ jsxRuntime.jsx(react.DefaultButton, { text: "Close", onClick: () => setOpen(false) })
5371
+ /* @__PURE__ */ jsxRuntime.jsx(react.DefaultButton, { type: "button", text: "Close", onClick: () => setOpen(false) })
5347
5372
  ] })
5348
5373
  ] })
5349
5374
  }
@@ -5356,10 +5381,20 @@ var ColorPickerPlugin = ({ disabled }) => {
5356
5381
  const lastRangeSelectionRef = React9__namespace.default.useRef(null);
5357
5382
  const updateToolbar = () => {
5358
5383
  const selection$1 = lexical.$getSelection();
5359
- if (lexical.$isRangeSelection(selection$1)) {
5384
+ const isRange = lexical.$isRangeSelection(selection$1);
5385
+ console.log("[AO-ColorPicker] updateToolbar", {
5386
+ isRangeSelection: isRange,
5387
+ isCollapsed: isRange ? selection$1.isCollapsed() : null
5388
+ });
5389
+ if (isRange) {
5360
5390
  lastRangeSelectionRef.current = selection$1.clone();
5361
5391
  const c = selection.$getSelectionStyleValueForProperty(selection$1, "color", "#000000");
5362
- const bg = selection.$getSelectionStyleValueForProperty(selection$1, "background-color", "#ffffff");
5392
+ const bg = selection.$getSelectionStyleValueForProperty(
5393
+ selection$1,
5394
+ "background-color",
5395
+ "#ffffff"
5396
+ );
5397
+ console.log("[AO-ColorPicker] updateToolbar readback", { color: c, bgColor: bg });
5363
5398
  setColors({ color: c, bgColor: bg });
5364
5399
  }
5365
5400
  };
@@ -5382,6 +5417,17 @@ var ColorPickerPlugin = ({ disabled }) => {
5382
5417
  if (disabled) return;
5383
5418
  const root = editor.getRootElement();
5384
5419
  const editorIsActive = !!lastRangeSelectionRef.current && !!root && (document.activeElement === root || root.contains(document.activeElement));
5420
+ console.log("[AO-ColorPicker] applyStyle called", {
5421
+ property: args.property,
5422
+ color: args.color,
5423
+ hasSavedSelection: !!lastRangeSelectionRef.current,
5424
+ savedSelectionIsCollapsed: lastRangeSelectionRef.current?.isCollapsed() ?? null,
5425
+ editorIsActive,
5426
+ activeElementTag: document.activeElement?.tagName,
5427
+ activeElementClass: document.activeElement?.className,
5428
+ rootIsActiveElement: document.activeElement === root,
5429
+ rootContainsActiveElement: !!root && root.contains(document.activeElement)
5430
+ });
5385
5431
  if (editorIsActive) editor.focus();
5386
5432
  editor.update(() => {
5387
5433
  const saved = lastRangeSelectionRef.current;
@@ -5389,8 +5435,29 @@ var ColorPickerPlugin = ({ disabled }) => {
5389
5435
  lexical.$setSelection(saved.clone());
5390
5436
  }
5391
5437
  const selection$1 = lexical.$getSelection();
5392
- if (lexical.$isRangeSelection(selection$1)) {
5438
+ const isRange = lexical.$isRangeSelection(selection$1);
5439
+ console.log("[AO-ColorPicker] applyStyle inside editor.update", {
5440
+ hadSavedSelection: !!saved,
5441
+ selectionAfterRestoreIsRange: isRange,
5442
+ selectionAfterRestoreIsCollapsed: isRange ? selection$1.isCollapsed() : null
5443
+ });
5444
+ if (isRange) {
5393
5445
  selection.$patchStyleText(selection$1, { [args.property]: args.color });
5446
+ const verify = selection.$getSelectionStyleValueForProperty(
5447
+ selection$1,
5448
+ args.property,
5449
+ "<none>"
5450
+ );
5451
+ console.log("[AO-ColorPicker] applyStyle after patchStyleText, readback in same update", {
5452
+ property: args.property,
5453
+ appliedColor: args.color,
5454
+ readBack: verify
5455
+ });
5456
+ } else {
5457
+ console.warn(
5458
+ "[AO-ColorPicker] applyStyle: no range selection available \u2014 style was NOT applied",
5459
+ { property: args.property, color: args.color }
5460
+ );
5394
5461
  }
5395
5462
  });
5396
5463
  };
@@ -6734,6 +6801,12 @@ function FocusEventsPlugin({
6734
6801
  const next = e.relatedTarget;
6735
6802
  const container = containerRef.current;
6736
6803
  const stillInside = !!next && (container ? container.contains(next) : root.contains(next));
6804
+ console.log("[AO-ColorPicker] FocusEventsPlugin focusout", {
6805
+ relatedTargetTag: next ? next.tagName : null,
6806
+ relatedTargetClass: next ? next.className : null,
6807
+ stillInside,
6808
+ willClearSelection: !stillInside
6809
+ });
6737
6810
  if (stillInside) return;
6738
6811
  editor.update(() => {
6739
6812
  lexical.$setSelection(null);