@tarviks/lexical-rich-editor 1.0.8 → 1.0.10
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 +111 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +112 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5145,11 +5145,18 @@ function useDrag(onMove, onEnd, interactingRef) {
|
|
|
5145
5145
|
);
|
|
5146
5146
|
return start;
|
|
5147
5147
|
}
|
|
5148
|
-
var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
5148
|
+
var ColorPickerControl = ({ value, title, disabled, onChange, icon, onOpenChange }) => {
|
|
5149
5149
|
const [open, setOpen] = React9__namespace.useState(false);
|
|
5150
5150
|
const btnRef = React9__namespace.useRef(null);
|
|
5151
|
+
const setOpenAndNotify = React9__namespace.useCallback(
|
|
5152
|
+
(next) => {
|
|
5153
|
+
setOpen(next);
|
|
5154
|
+
onOpenChange?.(next);
|
|
5155
|
+
},
|
|
5156
|
+
[onOpenChange]
|
|
5157
|
+
);
|
|
5151
5158
|
const interactingRef = React9__namespace.useRef(false);
|
|
5152
|
-
const handleDismiss = React9__namespace.useCallback(() =>
|
|
5159
|
+
const handleDismiss = React9__namespace.useCallback(() => setOpenAndNotify(false), [setOpenAndNotify]);
|
|
5153
5160
|
const preventDismissOnEvent = React9__namespace.useCallback(
|
|
5154
5161
|
(ev) => {
|
|
5155
5162
|
if (interactingRef.current) return true;
|
|
@@ -5183,11 +5190,21 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5183
5190
|
const [s, setS] = React9__namespace.useState(hsv.s);
|
|
5184
5191
|
const [v, setV] = React9__namespace.useState(hsv.v);
|
|
5185
5192
|
const wasOpenRef = React9__namespace.useRef(open);
|
|
5193
|
+
console.log("[AO-ColorPicker]", title, "render with incoming value prop:", JSON.stringify(value));
|
|
5186
5194
|
React9__namespace.useEffect(() => {
|
|
5187
5195
|
const justOpened = open && !wasOpenRef.current;
|
|
5188
5196
|
wasOpenRef.current = open;
|
|
5197
|
+
console.log("[AO-ColorPicker]", title, "open-seed effect", {
|
|
5198
|
+
open,
|
|
5199
|
+
justOpened,
|
|
5200
|
+
incomingValue: value
|
|
5201
|
+
});
|
|
5189
5202
|
if (!justOpened) return;
|
|
5190
5203
|
const n = normalizeHex(value || "#000000");
|
|
5204
|
+
console.log("[AO-ColorPicker]", title, "seeding local state from value on open", {
|
|
5205
|
+
incomingValue: value,
|
|
5206
|
+
normalized: n
|
|
5207
|
+
});
|
|
5191
5208
|
setHex(n);
|
|
5192
5209
|
const rgb = hexToRgb(n);
|
|
5193
5210
|
const next = rgbToHsv(rgb.r, rgb.g, rgb.b);
|
|
@@ -5200,10 +5217,11 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5200
5217
|
const rgb = hsvToRgb(hh, ss, vv);
|
|
5201
5218
|
const nextHex = rgbToHex(rgb.r, rgb.g, rgb.b);
|
|
5202
5219
|
setHex(nextHex);
|
|
5220
|
+
console.log("[AO-ColorPicker]", title, "commitHsv -> onChange", { nextHex, close: !!close });
|
|
5203
5221
|
onChange(nextHex);
|
|
5204
|
-
if (close)
|
|
5222
|
+
if (close) setOpenAndNotify(false);
|
|
5205
5223
|
},
|
|
5206
|
-
[onChange]
|
|
5224
|
+
[onChange, title, setOpenAndNotify]
|
|
5207
5225
|
);
|
|
5208
5226
|
const svRef = React9__namespace.useRef(null);
|
|
5209
5227
|
const onSVMove = React9__namespace.useCallback(
|
|
@@ -5258,7 +5276,11 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5258
5276
|
},
|
|
5259
5277
|
onClick: () => {
|
|
5260
5278
|
if (disabled) return;
|
|
5261
|
-
|
|
5279
|
+
console.log("[AO-ColorPicker]", title, "trigger button clicked", {
|
|
5280
|
+
wasOpen: open,
|
|
5281
|
+
activeElementBeforeToggle: document.activeElement?.tagName
|
|
5282
|
+
});
|
|
5283
|
+
setOpenAndNotify(!open);
|
|
5262
5284
|
}
|
|
5263
5285
|
}
|
|
5264
5286
|
),
|
|
@@ -5308,6 +5330,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5308
5330
|
setH(next.h);
|
|
5309
5331
|
setS(next.s);
|
|
5310
5332
|
setV(next.v);
|
|
5333
|
+
console.log("[AO-ColorPicker]", title, "hex field blur -> onChange", { raw: hex, normalized: n });
|
|
5311
5334
|
onChange(n);
|
|
5312
5335
|
}
|
|
5313
5336
|
}
|
|
@@ -5326,6 +5349,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5326
5349
|
setH(next.h);
|
|
5327
5350
|
setS(next.s);
|
|
5328
5351
|
setV(next.v);
|
|
5352
|
+
console.log("[AO-ColorPicker]", title, "preset swatch click -> onChange", { color: c });
|
|
5329
5353
|
onChange(c);
|
|
5330
5354
|
},
|
|
5331
5355
|
title: c
|
|
@@ -5351,7 +5375,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5351
5375
|
}
|
|
5352
5376
|
}
|
|
5353
5377
|
),
|
|
5354
|
-
/* @__PURE__ */ jsxRuntime.jsx(react.DefaultButton, { type: "button", text: "Close", onClick: () =>
|
|
5378
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.DefaultButton, { type: "button", text: "Close", onClick: () => setOpenAndNotify(false) })
|
|
5355
5379
|
] })
|
|
5356
5380
|
] })
|
|
5357
5381
|
}
|
|
@@ -5364,10 +5388,20 @@ var ColorPickerPlugin = ({ disabled }) => {
|
|
|
5364
5388
|
const lastRangeSelectionRef = React9__namespace.default.useRef(null);
|
|
5365
5389
|
const updateToolbar = () => {
|
|
5366
5390
|
const selection$1 = lexical.$getSelection();
|
|
5367
|
-
|
|
5391
|
+
const isRange = lexical.$isRangeSelection(selection$1);
|
|
5392
|
+
console.log("[AO-ColorPicker] updateToolbar", {
|
|
5393
|
+
isRangeSelection: isRange,
|
|
5394
|
+
isCollapsed: isRange ? selection$1.isCollapsed() : null
|
|
5395
|
+
});
|
|
5396
|
+
if (isRange) {
|
|
5368
5397
|
lastRangeSelectionRef.current = selection$1.clone();
|
|
5369
5398
|
const c = selection.$getSelectionStyleValueForProperty(selection$1, "color", "#000000");
|
|
5370
|
-
const bg = selection.$getSelectionStyleValueForProperty(
|
|
5399
|
+
const bg = selection.$getSelectionStyleValueForProperty(
|
|
5400
|
+
selection$1,
|
|
5401
|
+
"background-color",
|
|
5402
|
+
"#ffffff"
|
|
5403
|
+
);
|
|
5404
|
+
console.log("[AO-ColorPicker] updateToolbar readback", { color: c, bgColor: bg });
|
|
5371
5405
|
setColors({ color: c, bgColor: bg });
|
|
5372
5406
|
}
|
|
5373
5407
|
};
|
|
@@ -5386,21 +5420,68 @@ var ColorPickerPlugin = ({ disabled }) => {
|
|
|
5386
5420
|
)
|
|
5387
5421
|
);
|
|
5388
5422
|
}, [editor]);
|
|
5423
|
+
const wasEditorActiveRef = React9__namespace.default.useRef(false);
|
|
5424
|
+
const handleOpenChange = (open) => {
|
|
5425
|
+
if (open) {
|
|
5426
|
+
const root = editor.getRootElement();
|
|
5427
|
+
wasEditorActiveRef.current = !!root && (document.activeElement === root || root.contains(document.activeElement));
|
|
5428
|
+
} else if (wasEditorActiveRef.current) {
|
|
5429
|
+
editor.focus();
|
|
5430
|
+
}
|
|
5431
|
+
};
|
|
5389
5432
|
const applyStyle = (args) => {
|
|
5390
5433
|
if (disabled) return;
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
const selection$1 = lexical.$getSelection();
|
|
5400
|
-
if (lexical.$isRangeSelection(selection$1)) {
|
|
5401
|
-
selection.$patchStyleText(selection$1, { [args.property]: args.color });
|
|
5402
|
-
}
|
|
5434
|
+
console.log("[AO-ColorPicker] applyStyle called", {
|
|
5435
|
+
property: args.property,
|
|
5436
|
+
color: args.color,
|
|
5437
|
+
hasSavedSelection: !!lastRangeSelectionRef.current,
|
|
5438
|
+
savedSelectionIsCollapsed: lastRangeSelectionRef.current?.isCollapsed() ?? null,
|
|
5439
|
+
wasEditorActiveAtOpen: wasEditorActiveRef.current,
|
|
5440
|
+
activeElementTag: document.activeElement?.tagName,
|
|
5441
|
+
activeElementClass: document.activeElement?.className
|
|
5403
5442
|
});
|
|
5443
|
+
editor.update(
|
|
5444
|
+
() => {
|
|
5445
|
+
const saved = lastRangeSelectionRef.current;
|
|
5446
|
+
if (saved) {
|
|
5447
|
+
lexical.$setSelection(saved.clone());
|
|
5448
|
+
}
|
|
5449
|
+
const selection$1 = lexical.$getSelection();
|
|
5450
|
+
const isRange = lexical.$isRangeSelection(selection$1);
|
|
5451
|
+
console.log("[AO-ColorPicker] applyStyle inside editor.update", {
|
|
5452
|
+
hadSavedSelection: !!saved,
|
|
5453
|
+
selectionAfterRestoreIsRange: isRange,
|
|
5454
|
+
selectionAfterRestoreIsCollapsed: isRange ? selection$1.isCollapsed() : null
|
|
5455
|
+
});
|
|
5456
|
+
if (isRange) {
|
|
5457
|
+
selection.$patchStyleText(selection$1, { [args.property]: args.color });
|
|
5458
|
+
const verify = selection.$getSelectionStyleValueForProperty(
|
|
5459
|
+
selection$1,
|
|
5460
|
+
args.property,
|
|
5461
|
+
"<none>"
|
|
5462
|
+
);
|
|
5463
|
+
console.log("[AO-ColorPicker] applyStyle after patchStyleText, readback in same update", {
|
|
5464
|
+
property: args.property,
|
|
5465
|
+
appliedColor: args.color,
|
|
5466
|
+
readBack: verify
|
|
5467
|
+
});
|
|
5468
|
+
} else {
|
|
5469
|
+
console.warn(
|
|
5470
|
+
"[AO-ColorPicker] applyStyle: no range selection available \u2014 style was NOT applied",
|
|
5471
|
+
{ property: args.property, color: args.color }
|
|
5472
|
+
);
|
|
5473
|
+
}
|
|
5474
|
+
},
|
|
5475
|
+
// Without this tag, Lexical's reconciler force-focuses the editor root
|
|
5476
|
+
// whenever this update's selection diff finds the root isn't already
|
|
5477
|
+
// focused (see Lexical.dev.mjs ~8112) — which it never is while the
|
|
5478
|
+
// color picker's Callout legitimately holds focus. That forced focus
|
|
5479
|
+
// then fights Fluent's Callout for focus on every single drag-driven
|
|
5480
|
+
// commit, repeatedly bouncing focus (and, via FocusEventsPlugin,
|
|
5481
|
+
// nulling and restoring the selection) between the editor and the
|
|
5482
|
+
// popover until the drag's tracked color desynced from the cursor.
|
|
5483
|
+
{ tag: lexical.SKIP_SELECTION_FOCUS_TAG }
|
|
5484
|
+
);
|
|
5404
5485
|
};
|
|
5405
5486
|
const containerStyle = disabled ? {
|
|
5406
5487
|
display: "flex",
|
|
@@ -5424,7 +5505,8 @@ var ColorPickerPlugin = ({ disabled }) => {
|
|
|
5424
5505
|
title: "Text color",
|
|
5425
5506
|
disabled,
|
|
5426
5507
|
icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.TextColorRegular, { style: { color: iconColor } }),
|
|
5427
|
-
onChange: (c) => applyStyle({ property: "color", color: c })
|
|
5508
|
+
onChange: (c) => applyStyle({ property: "color", color: c }),
|
|
5509
|
+
onOpenChange: handleOpenChange
|
|
5428
5510
|
}
|
|
5429
5511
|
),
|
|
5430
5512
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -5434,7 +5516,8 @@ var ColorPickerPlugin = ({ disabled }) => {
|
|
|
5434
5516
|
title: "Background color",
|
|
5435
5517
|
disabled,
|
|
5436
5518
|
icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.PaintBucket16Filled, { style: { color: iconColor } }),
|
|
5437
|
-
onChange: (c) => applyStyle({ property: "background-color", color: c })
|
|
5519
|
+
onChange: (c) => applyStyle({ property: "background-color", color: c }),
|
|
5520
|
+
onOpenChange: handleOpenChange
|
|
5438
5521
|
}
|
|
5439
5522
|
)
|
|
5440
5523
|
] });
|
|
@@ -6742,6 +6825,12 @@ function FocusEventsPlugin({
|
|
|
6742
6825
|
const next = e.relatedTarget;
|
|
6743
6826
|
const container = containerRef.current;
|
|
6744
6827
|
const stillInside = !!next && (container ? container.contains(next) : root.contains(next));
|
|
6828
|
+
console.log("[AO-ColorPicker] FocusEventsPlugin focusout", {
|
|
6829
|
+
relatedTargetTag: next ? next.tagName : null,
|
|
6830
|
+
relatedTargetClass: next ? next.className : null,
|
|
6831
|
+
stillInside,
|
|
6832
|
+
willClearSelection: !stillInside
|
|
6833
|
+
});
|
|
6745
6834
|
if (stillInside) return;
|
|
6746
6835
|
editor.update(() => {
|
|
6747
6836
|
lexical.$setSelection(null);
|