Skip to content

Commit

Permalink
feat: option to not highlighting active list button and toParagraph a…
Browse files Browse the repository at this point in the history
…ction improvement
  • Loading branch information
smsochneg committed Feb 20, 2024
1 parent c64dd68 commit 20314ee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/extensions/base/BaseSchema/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {setBlockType} from 'prosemirror-commands';
import {chainCommands, setBlockType} from 'prosemirror-commands';
import type {Command} from 'prosemirror-state';
import {hasParentNodeOfType} from 'prosemirror-utils';

Expand Down Expand Up @@ -31,9 +31,11 @@ export const BaseSchema: ExtensionAuto<BaseSchemaOptions> = (builder, opts) => {
builder.addAction(pAction, ({schema}) => {
const p = pType(schema);
const cmd = setBlockType(p);
const isParagraph: Command = (state) => hasParentNodeOfType(p)(state.selection);

return {
isActive: (state) => hasParentNodeOfType(p)(state.selection),
isEnable: cmd,
isActive: isParagraph,
isEnable: chainCommands(isParagraph, cmd),
run: cmd,
};
});
Expand Down
4 changes: 3 additions & 1 deletion src/toolbar/ToolbarListButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export function ToolbarListButton<E>({
const buttonRef = React.useRef<HTMLButtonElement>(null);
const [open, , hide, toggleOpen] = useBooleanState(false);

const someActive = alwaysActive ? false : data.some((item) => item.isActive(editor));
const someActive = alwaysActive
? false
: data.some((item) => item.isActive(editor) && !item.doNotHighlightButtonWhenActive);
const everyDisabled = alwaysActive ? false : data.every((item) => !item.isEnable(editor));

const popupOpen = everyDisabled ? false : open;
Expand Down
1 change: 1 addition & 0 deletions src/toolbar/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type ToolbarItemData<E> = {
exec(editor: E): void;
isActive(editor: E): boolean;
isEnable(editor: E): boolean;
doNotHighlightButtonWhenActive?: boolean;
};

export enum ToolbarDataType {
Expand Down

0 comments on commit 20314ee

Please sign in to comment.