@editorcn/editor 0.5.2 → 0.5.3

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
@@ -1103,6 +1103,7 @@ var RichTextEditorControl = forwardRef12(
1103
1103
  return props.title ? /* @__PURE__ */ jsx20(RichTextEditorTooltip, { id: props.id, label: props.title, children: toggle }) : toggle;
1104
1104
  }
1105
1105
  );
1106
+ RichTextEditorControl.displayName = "RichTextEditorControl";
1106
1107
  var resolveIsActive = (editor, config) => {
1107
1108
  if (!editor || !config) {
1108
1109
  return false;
@@ -3122,7 +3123,7 @@ var Content = ({
3122
3123
  // src/rte-controls-group.tsx
3123
3124
  import { useContext as useContext3 } from "react";
3124
3125
  import { jsx as jsx29 } from "react/jsx-runtime";
3125
- var SEPARATOR = "[.rte-controls-group+&]:before:w-px [.rte-controls-group+&]:before:shrink-0 [.rte-controls-group+&]:before:bg-border [.rte-controls-group+&]:before:content-['']";
3126
+ var SEPARATOR = "[.rte-controls-group+&]:before:w-px [.rte-controls-group+&]:before:shrink-0 [.rte-controls-group+&]:before:bg-border [.rte-controls-group+&]:before:content-[''] [.rte-controls-group+&]:data-line-start:before:invisible";
3126
3127
  var BUTTON = "[&>button]:border-none [&>button]:bg-transparent [&>button]:transition-[background-color,color] [&>button]:duration-150 [&>button]:ease-[ease-out] [&>button:focus-visible]:outline-2 [&>button:focus-visible]:outline-offset-1 [&>button:focus-visible]:outline-ring/50 [&>button:focus-visible]:outline-solid";
3127
3128
  var variantClasses = {
3128
3129
  compact: `${SEPARATOR} [.rte-controls-group+&]:before:mx-0.5 [.rte-controls-group+&]:before:h-3.5 ${BUTTON} [&>button]:h-7 [&>button]:min-w-7 [&>button]:rounded-sm [&>button]:text-muted-foreground [&>button:hover]:bg-muted [&>button:hover]:text-foreground [&>button[aria-pressed=true]]:bg-muted [&>button[aria-pressed=true]]:text-foreground [&>button[data-state=on]]:bg-muted [&>button[data-state=on]]:text-foreground`,
@@ -3255,7 +3256,50 @@ var Footer = ({
3255
3256
  };
3256
3257
 
3257
3258
  // src/rte-toolbar.tsx
3259
+ import { useLayoutEffect, useRef as useRef6 } from "react";
3258
3260
  import { jsx as jsx31 } from "react/jsx-runtime";
3261
+ var GROUPS = ":scope > .rte-controls-group";
3262
+ var useMarkLineStarts = (enabled) => {
3263
+ const ref = useRef6(null);
3264
+ useLayoutEffect(() => {
3265
+ const toolbar = ref.current;
3266
+ if (!enabled || !toolbar || typeof ResizeObserver === "undefined") {
3267
+ return;
3268
+ }
3269
+ const mark = () => {
3270
+ let previous = null;
3271
+ for (const group of toolbar.querySelectorAll(GROUPS)) {
3272
+ if (group.getClientRects().length === 0) {
3273
+ continue;
3274
+ }
3275
+ const rect = group.getBoundingClientRect();
3276
+ const startsLine = previous !== null && rect.top >= previous.bottom - 1;
3277
+ group.toggleAttribute("data-line-start", startsLine);
3278
+ previous = rect;
3279
+ }
3280
+ };
3281
+ const resize = new ResizeObserver(mark);
3282
+ const observeAll = () => {
3283
+ resize.disconnect();
3284
+ resize.observe(toolbar);
3285
+ for (const group of toolbar.querySelectorAll(GROUPS)) {
3286
+ resize.observe(group);
3287
+ }
3288
+ };
3289
+ const mutation = new MutationObserver(() => {
3290
+ observeAll();
3291
+ mark();
3292
+ });
3293
+ mutation.observe(toolbar, { childList: true });
3294
+ observeAll();
3295
+ mark();
3296
+ return () => {
3297
+ resize.disconnect();
3298
+ mutation.disconnect();
3299
+ };
3300
+ }, [enabled]);
3301
+ return ref;
3302
+ };
3259
3303
  var Toolbar = ({
3260
3304
  children,
3261
3305
  className,
@@ -3263,12 +3307,14 @@ var Toolbar = ({
3263
3307
  stickyOffset = 0
3264
3308
  }) => {
3265
3309
  const { variant, editable } = useRichTextEditorContext();
3310
+ const ref = useMarkLineStarts(editable);
3266
3311
  if (!editable) {
3267
3312
  return null;
3268
3313
  }
3269
3314
  return /* @__PURE__ */ jsx31(
3270
3315
  "div",
3271
3316
  {
3317
+ ref,
3272
3318
  className: cn(
3273
3319
  "rte-toolbar top-[var(--rte-sticky-offset,0px)] z-1 flex flex-wrap items-center justify-center gap-1 rounded-ss-[calc(var(--radius)+3px)] rounded-se-[calc(var(--radius)+3px)] border-b border-(--rte-hairline) bg-(--rte-strip) px-2 py-1.5 [transition:background-color_150ms_ease-out]",
3274
3320
  "[@media(max-width:640px)]:justify-start [@media(max-width:640px)]:flex-nowrap [@media(max-width:640px)]:overflow-x-auto [@media(max-width:640px)]:[--rte-toolbar-fade-end:1.5rem] [@media(max-width:640px)]:[-ms-overflow-style:none] [@media(max-width:640px)]:[-webkit-overflow-scrolling:touch] [@media(max-width:640px)]:[mask-image:linear-gradient(to_right,transparent,black_var(--rte-toolbar-fade-start),black_calc(100%-var(--rte-toolbar-fade-end)),transparent)] [@media(max-width:640px)]:[scrollbar-width:none] [@media(max-width:640px)]:[&::-webkit-scrollbar]:hidden [@media(max-width:640px)]:supports-[animation-timeline:scroll()]:[--rte-toolbar-fade-end:0px] [@media(max-width:640px)]:supports-[animation-timeline:scroll()]:animate-rte-toolbar-fade [@media(max-width:640px)]:supports-[animation-timeline:scroll()]:[animation-timeline:scroll(self_inline)]",