@editorcn/editor 0.5.1 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @editorcn/editor
2
2
 
3
+ ## 0.5.3
4
+
5
+ ### Fixes
6
+
7
+ - When the toolbar wraps onto more than one row, the first group on each new row no longer starts with a stray separator. The toolbar marks those groups with `data-line-start` and updates them when its width changes.
8
+ - `RichTextEditor.Control` has a display name, so `react/display-name` no longer flags it.
9
+ - The Twitter embed's lint suppression uses an `oxlint-disable` comment, so ESLint no longer reports `Definition for rule 'promise/avoid-new' was not found` in projects that install the editor through the registry.
10
+
3
11
  ## 0.5.1
4
12
 
5
13
  ### Fixes
package/README.md CHANGED
@@ -53,13 +53,12 @@ Make sure your `components.json` includes the editorcn registry:
53
53
 
54
54
  import { useEditor } from "@tiptap/react";
55
55
  import { StarterKit } from "@tiptap/starter-kit";
56
- import { Underline } from "@tiptap/extension-underline";
57
56
  import { RichTextEditor, Link } from "@editorcn/editor";
58
57
  import "@editorcn/editor/style.css";
59
58
 
60
59
  export function MyEditor() {
61
60
  const editor = useEditor({
62
- extensions: [StarterKit, Link, Underline],
61
+ extensions: [StarterKit.configure({ link: false }), Link],
63
62
  content: "<p>Start typing...</p>",
64
63
  });
65
64
 
package/dist/index.cjs CHANGED
@@ -43,7 +43,7 @@ __export(index_exports, {
43
43
  module.exports = __toCommonJS(index_exports);
44
44
 
45
45
  // src/rte-text-editor.tsx
46
- var import_react22 = require("react");
46
+ var import_react23 = require("react");
47
47
 
48
48
  // src/bubble-menu/index.tsx
49
49
  var import_core = require("@tiptap/core");
@@ -1050,6 +1050,7 @@ var BubbleMenu = ({ editor }) => {
1050
1050
  return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1051
1051
  import_menus.BubbleMenu,
1052
1052
  {
1053
+ className: "z-50",
1053
1054
  editor,
1054
1055
  options: { offset: 8, placement: "top" },
1055
1056
  shouldShow,
@@ -1146,6 +1147,7 @@ var RichTextEditorControl = (0, import_react8.forwardRef)(
1146
1147
  return props.title ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(RichTextEditorTooltip, { id: props.id, label: props.title, children: toggle }) : toggle;
1147
1148
  }
1148
1149
  );
1150
+ RichTextEditorControl.displayName = "RichTextEditorControl";
1149
1151
  var resolveIsActive = (editor, config) => {
1150
1152
  if (!editor || !config) {
1151
1153
  return false;
@@ -3126,7 +3128,7 @@ var Content = ({
3126
3128
  // src/rte-controls-group.tsx
3127
3129
  var import_react20 = require("react");
3128
3130
  var import_jsx_runtime29 = require("react/jsx-runtime");
3129
- 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-['']";
3131
+ 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";
3130
3132
  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";
3131
3133
  var variantClasses = {
3132
3134
  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`,
@@ -3259,7 +3261,50 @@ var Footer = ({
3259
3261
  };
3260
3262
 
3261
3263
  // src/rte-toolbar.tsx
3264
+ var import_react22 = require("react");
3262
3265
  var import_jsx_runtime31 = require("react/jsx-runtime");
3266
+ var GROUPS = ":scope > .rte-controls-group";
3267
+ var useMarkLineStarts = (enabled) => {
3268
+ const ref = (0, import_react22.useRef)(null);
3269
+ (0, import_react22.useLayoutEffect)(() => {
3270
+ const toolbar = ref.current;
3271
+ if (!enabled || !toolbar || typeof ResizeObserver === "undefined") {
3272
+ return;
3273
+ }
3274
+ const mark = () => {
3275
+ let previous = null;
3276
+ for (const group of toolbar.querySelectorAll(GROUPS)) {
3277
+ if (group.getClientRects().length === 0) {
3278
+ continue;
3279
+ }
3280
+ const rect = group.getBoundingClientRect();
3281
+ const startsLine = previous !== null && rect.top >= previous.bottom - 1;
3282
+ group.toggleAttribute("data-line-start", startsLine);
3283
+ previous = rect;
3284
+ }
3285
+ };
3286
+ const resize = new ResizeObserver(mark);
3287
+ const observeAll = () => {
3288
+ resize.disconnect();
3289
+ resize.observe(toolbar);
3290
+ for (const group of toolbar.querySelectorAll(GROUPS)) {
3291
+ resize.observe(group);
3292
+ }
3293
+ };
3294
+ const mutation = new MutationObserver(() => {
3295
+ observeAll();
3296
+ mark();
3297
+ });
3298
+ mutation.observe(toolbar, { childList: true });
3299
+ observeAll();
3300
+ mark();
3301
+ return () => {
3302
+ resize.disconnect();
3303
+ mutation.disconnect();
3304
+ };
3305
+ }, [enabled]);
3306
+ return ref;
3307
+ };
3263
3308
  var Toolbar = ({
3264
3309
  children,
3265
3310
  className,
@@ -3267,12 +3312,14 @@ var Toolbar = ({
3267
3312
  stickyOffset = 0
3268
3313
  }) => {
3269
3314
  const { variant, editable } = useRichTextEditorContext();
3315
+ const ref = useMarkLineStarts(editable);
3270
3316
  if (!editable) {
3271
3317
  return null;
3272
3318
  }
3273
3319
  return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
3274
3320
  "div",
3275
3321
  {
3322
+ ref,
3276
3323
  className: cn(
3277
3324
  "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]",
3278
3325
  "[@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)]",
@@ -3303,13 +3350,13 @@ var RichTextEditorRoot = ({
3303
3350
  preset = "document",
3304
3351
  editable = true
3305
3352
  }) => {
3306
- const mergedLabels = (0, import_react22.useMemo)(
3353
+ const mergedLabels = (0, import_react23.useMemo)(
3307
3354
  () => ({ ...DEFAULT_LABELS, ...labels }),
3308
3355
  [labels]
3309
3356
  );
3310
- const mergedIcons = (0, import_react22.useMemo)(() => ({ ...DEFAULT_ICONS, ...icons }), [icons]);
3311
- const [tooltip] = (0, import_react22.useState)(createTooltipHandle);
3312
- (0, import_react22.useEffect)(() => {
3357
+ const mergedIcons = (0, import_react23.useMemo)(() => ({ ...DEFAULT_ICONS, ...icons }), [icons]);
3358
+ const [tooltip] = (0, import_react23.useState)(createTooltipHandle);
3359
+ (0, import_react23.useEffect)(() => {
3313
3360
  if (editor && editor.isEditable !== editable) {
3314
3361
  editor.setEditable(editable);
3315
3362
  }