Skip to content

Commit c4987cf

Browse files
committed
fix(components): 修正 form/Editor 的工具共用颜色选择面板导致的错误
1 parent 8732019 commit c4987cf

6 files changed

Lines changed: 25 additions & 18 deletions

File tree

apps/docs/src/components/demo/form/editor/editor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function (props: MountProps): JSX.Element {
1616
const [Layout, layout] = layoutSelector('_d.demo.componentLayout', 'horizontal');
1717

1818
return (
19-
<div>
19+
<>
2020
<Portal mount={props.mount}>
2121
<Palette />
2222
<Disabled />
@@ -40,6 +40,6 @@ export default function (props: MountProps): JSX.Element {
4040
placeholder="placeholder text"
4141
/>
4242
<pre>{txt.getValue()}</pre>
43-
</div>
43+
</>
4444
);
4545
}

packages/components/src/button/split/root.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export function Root<T extends AvailableEnumType = string>(props: Props<T>): JSX
9696
toggle: () => dropdownRef.toggle(),
9797
root: () => dropdownRef.root(),
9898
menu: () => dropdownRef.menu(),
99+
trigger: () => dropdownRef.trigger(),
99100
group: () => el,
100101
});
101102
}

packages/components/src/color/root.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface Props extends BaseProps, RefProps<Ref> {
5959
/**
6060
* 指定的颜色拾取面板的类型
6161
*/
62-
pickers: Array<PickerPanel>;
62+
pickers: ReadonlyArray<PickerPanel>;
6363
}
6464

6565
/**

packages/components/src/context/options/context.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type Result = ReturnType<typeof render>;
5454
* NOTE: 实例需要放在 describe 方法中。
5555
*/
5656
export class ComponentTester {
57-
readonly #component;
57+
readonly #component: string;
5858
readonly #result: Result;
5959

6060
private constructor(component: string, result: Result) {

packages/components/src/form/editor/toolbar/style.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@layer components {
1010
.toolbar {
1111
@apply border-b border-palette-border bg-palette-bg text-palette-fg p-1;
12-
@apply flex gap-1;
12+
@apply flex gap-1 justify-center;
1313

1414
.item {
1515
@apply px-0 flex justify-center items-center h-8;

packages/components/src/form/editor/toolbar/textstyle.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ import { Numeric } from '@components/form/textfield';
1818
import styles from './style.module.css';
1919
import type { Props } from './types';
2020

21-
const pickers = [
22-
new ColorPanel.TailwindVarsPickerPanel(),
23-
new ColorPanel.HSLPickerPanel(),
24-
new ColorPanel.OKLCHPickerPanel(),
25-
new ColorPanel.PresetPickerPanel(),
26-
new ColorPanel.RGBPickerPanel(),
27-
new ColorPanel.WebSafePickerPanel(),
28-
];
29-
3021
/**
3122
* 指定文本的颜色
3223
*
@@ -55,6 +46,8 @@ export function Color(props: Props): JSX.Element {
5546
if (accessor.getValue() === color) {
5647
return;
5748
}
49+
50+
isSelectUpdate = true;
5851
accessor.setValue(color);
5952
};
6053
onMount(() => props.editor.on('selectionUpdate', selectionUpdate));
@@ -77,7 +70,13 @@ export function Color(props: Props): JSX.Element {
7770
<ColorPicker.Root
7871
ref={el => (picker = el)}
7972
accessor={accessor}
80-
pickers={pickers}
73+
pickers={[
74+
new ColorPanel.TailwindVarsPickerPanel(),
75+
new ColorPanel.HSLPickerPanel(),
76+
new ColorPanel.OKLCHPickerPanel(),
77+
new ColorPanel.RGBPickerPanel(),
78+
new ColorPanel.WebSafePickerPanel(),
79+
]}
8180
activatorClass={styles['color-activator']}
8281
>
8382
<IconColor />
@@ -95,7 +94,7 @@ export function BackgroundColor(props: Props): JSX.Element {
9594
const l = useLocale();
9695

9796
const accessor = fieldAccessor<string | undefined>(
98-
'bgcolor',
97+
'backgroundColor',
9998
props.editor.getAttributes('textStyle').backgroundColor,
10099
);
101100
let isSelectUpdate = false; // 是否来自 selectionUpdate 事件,如果是来自该事件,不需要执行 setColor 操作
@@ -117,6 +116,8 @@ export function BackgroundColor(props: Props): JSX.Element {
117116
if (accessor.getValue() === color) {
118117
return;
119118
}
119+
120+
isSelectUpdate = true;
120121
accessor.setValue(color);
121122
};
122123
onMount(() => props.editor.on('selectionUpdate', selectionUpdate));
@@ -139,7 +140,13 @@ export function BackgroundColor(props: Props): JSX.Element {
139140
<ColorPicker.Root
140141
ref={el => (picker = el)}
141142
accessor={accessor}
142-
pickers={pickers}
143+
pickers={[
144+
new ColorPanel.TailwindVarsPickerPanel(),
145+
new ColorPanel.HSLPickerPanel(),
146+
new ColorPanel.OKLCHPickerPanel(),
147+
new ColorPanel.RGBPickerPanel(),
148+
new ColorPanel.WebSafePickerPanel(),
149+
]}
143150
activatorClass={styles['color-activator']}
144151
>
145152
<IconBackgroundColor />
@@ -159,7 +166,6 @@ export function LineHeight(props: Props): JSX.Element {
159166
const lh = props.editor.getAttributes('textStyle').lineHeight;
160167
const accessor = fieldAccessor<number | undefined>('lineHeight', lh ? parseFloat(lh) : undefined);
161168
accessor.onChange(v => {
162-
// TODO
163169
if (v) {
164170
props.editor.chain().setLineHeight(v.toString()).run();
165171
} else {

0 commit comments

Comments
 (0)