Skip to content

Commit 35d0219

Browse files
authored
feat: option to not highlighting active list button and toParagraph action improvement (#196)
1 parent c64dd68 commit 35d0219

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/extensions/base/BaseSchema/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {setBlockType} from 'prosemirror-commands';
1+
import {chainCommands, setBlockType} from 'prosemirror-commands';
22
import type {Command} from 'prosemirror-state';
33
import {hasParentNodeOfType} from 'prosemirror-utils';
44

@@ -31,9 +31,11 @@ export const BaseSchema: ExtensionAuto<BaseSchemaOptions> = (builder, opts) => {
3131
builder.addAction(pAction, ({schema}) => {
3232
const p = pType(schema);
3333
const cmd = setBlockType(p);
34+
const isParagraph: Command = (state) => hasParentNodeOfType(p)(state.selection);
35+
3436
return {
35-
isActive: (state) => hasParentNodeOfType(p)(state.selection),
36-
isEnable: cmd,
37+
isActive: isParagraph,
38+
isEnable: chainCommands(isParagraph, cmd),
3739
run: cmd,
3840
};
3941
});

src/toolbar/ToolbarListButton.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {i18n} from '../i18n/common';
1010
import {useBooleanState} from '../react-utils/hooks';
1111

1212
import {ToolbarTooltipDelay} from './const';
13-
import {ToolbarBaseProps, ToolbarIconData, ToolbarItemData} from './types';
13+
import {ToolbarBaseProps, ToolbarIconData, ToolbarListButtonItemData} from './types';
1414

1515
import './ToolbarListButton.scss';
1616

@@ -20,7 +20,7 @@ export type ToolbarListButtonData<E> = {
2020
icon: ToolbarIconData;
2121
title: string | (() => string);
2222
withArrow?: boolean;
23-
data: ToolbarItemData<E>[];
23+
data: ToolbarListButtonItemData<E>[];
2424
alwaysActive?: boolean;
2525
hideDisabled?: boolean;
2626
};
@@ -41,7 +41,9 @@ export function ToolbarListButton<E>({
4141
const buttonRef = React.useRef<HTMLButtonElement>(null);
4242
const [open, , hide, toggleOpen] = useBooleanState(false);
4343

44-
const someActive = alwaysActive ? false : data.some((item) => item.isActive(editor));
44+
const someActive = alwaysActive
45+
? false
46+
: data.some((item) => item.isActive(editor) && !item.doNotActivateList);
4547
const everyDisabled = alwaysActive ? false : data.every((item) => !item.isEnable(editor));
4648

4749
const popupOpen = everyDisabled ? false : open;

src/toolbar/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ export type ToolbarReactComponentData<E> = {
7272
component: React.ComponentType<ToolbarBaseProps<E>>;
7373
};
7474

75+
export type ToolbarListButtonItemData<E> = ToolbarItemData<E> & {
76+
doNotActivateList?: boolean;
77+
};
78+
7579
export type ToolbarReactNodeData = {
7680
id: string;
7781
type: ToolbarDataType.ReactNode;

0 commit comments

Comments
 (0)