@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/CHANGELOG.md +8 -0
- package/dist/index.cjs +52 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +47 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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/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
|
|
46
|
+
var import_react23 = require("react");
|
|
47
47
|
|
|
48
48
|
// src/bubble-menu/index.tsx
|
|
49
49
|
var import_core = require("@tiptap/core");
|
|
@@ -1147,6 +1147,7 @@ var RichTextEditorControl = (0, import_react8.forwardRef)(
|
|
|
1147
1147
|
return props.title ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(RichTextEditorTooltip, { id: props.id, label: props.title, children: toggle }) : toggle;
|
|
1148
1148
|
}
|
|
1149
1149
|
);
|
|
1150
|
+
RichTextEditorControl.displayName = "RichTextEditorControl";
|
|
1150
1151
|
var resolveIsActive = (editor, config) => {
|
|
1151
1152
|
if (!editor || !config) {
|
|
1152
1153
|
return false;
|
|
@@ -3127,7 +3128,7 @@ var Content = ({
|
|
|
3127
3128
|
// src/rte-controls-group.tsx
|
|
3128
3129
|
var import_react20 = require("react");
|
|
3129
3130
|
var import_jsx_runtime29 = require("react/jsx-runtime");
|
|
3130
|
-
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";
|
|
3131
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";
|
|
3132
3133
|
var variantClasses = {
|
|
3133
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`,
|
|
@@ -3260,7 +3261,50 @@ var Footer = ({
|
|
|
3260
3261
|
};
|
|
3261
3262
|
|
|
3262
3263
|
// src/rte-toolbar.tsx
|
|
3264
|
+
var import_react22 = require("react");
|
|
3263
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
|
+
};
|
|
3264
3308
|
var Toolbar = ({
|
|
3265
3309
|
children,
|
|
3266
3310
|
className,
|
|
@@ -3268,12 +3312,14 @@ var Toolbar = ({
|
|
|
3268
3312
|
stickyOffset = 0
|
|
3269
3313
|
}) => {
|
|
3270
3314
|
const { variant, editable } = useRichTextEditorContext();
|
|
3315
|
+
const ref = useMarkLineStarts(editable);
|
|
3271
3316
|
if (!editable) {
|
|
3272
3317
|
return null;
|
|
3273
3318
|
}
|
|
3274
3319
|
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
|
|
3275
3320
|
"div",
|
|
3276
3321
|
{
|
|
3322
|
+
ref,
|
|
3277
3323
|
className: cn(
|
|
3278
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]",
|
|
3279
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)]",
|
|
@@ -3304,13 +3350,13 @@ var RichTextEditorRoot = ({
|
|
|
3304
3350
|
preset = "document",
|
|
3305
3351
|
editable = true
|
|
3306
3352
|
}) => {
|
|
3307
|
-
const mergedLabels = (0,
|
|
3353
|
+
const mergedLabels = (0, import_react23.useMemo)(
|
|
3308
3354
|
() => ({ ...DEFAULT_LABELS, ...labels }),
|
|
3309
3355
|
[labels]
|
|
3310
3356
|
);
|
|
3311
|
-
const mergedIcons = (0,
|
|
3312
|
-
const [tooltip] = (0,
|
|
3313
|
-
(0,
|
|
3357
|
+
const mergedIcons = (0, import_react23.useMemo)(() => ({ ...DEFAULT_ICONS, ...icons }), [icons]);
|
|
3358
|
+
const [tooltip] = (0, import_react23.useState)(createTooltipHandle);
|
|
3359
|
+
(0, import_react23.useEffect)(() => {
|
|
3314
3360
|
if (editor && editor.isEditable !== editable) {
|
|
3315
3361
|
editor.setEditable(editable);
|
|
3316
3362
|
}
|