Skip to content

Commit

Permalink
feat
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfeng33 committed Nov 28, 2024
1 parent 6c2b4d3 commit 11fb757
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-keys-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-selection': minor
---

Add `duration` in addSelectedRow option
26 changes: 17 additions & 9 deletions packages/selection/src/react/BlockSelectionPlugin.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import type { CSSProperties } from 'react';
import type React from 'react';

import {
type PluginConfig,
type TElement,
type TNodeEntry,
bindFirst,
getNodeEntries,
} from '@udecode/plate-common';
import type { PluginConfig, TElement, TNodeEntry } from '@udecode/plate-common';

import { bindFirst, getNodeEntries } from '@udecode/plate-common';
import { createTPlatePlugin } from '@udecode/plate-common/react';

import type { ChangedElements, PartialSelectionOptions } from '../internal';
Expand Down Expand Up @@ -52,10 +48,13 @@ export type BlockSelectionSelectors = {
};

export type BlockSelectionApi = {
addSelectedRow: (
id: string,
options?: { clear?: boolean; duration?: number }
) => void;
setSelectedIds: (
options: Partial<ChangedElements> & { ids?: string[] }
) => void;
addSelectedRow: (id: string, options?: { clear?: boolean }) => void;
focus: () => void;
getNodes: () => TNodeEntry[];
resetSelectedIds: () => void;
Expand Down Expand Up @@ -181,7 +180,7 @@ export const BlockSelectionPlugin = createTPlatePlugin<BlockSelectionConfig>({
)
.extendApi<Partial<BlockSelectionApi>>(({ api, getOptions, setOption }) => ({
addSelectedRow: (id, options = {}) => {
const { clear = true } = options;
const { clear = true, duration } = options;

const element = getSelectedDomNode(id);

Expand All @@ -194,6 +193,15 @@ export const BlockSelectionPlugin = createTPlatePlugin<BlockSelectionConfig>({
added: [element],
removed: [],
});

if (duration) {
setTimeout(() => {
api.blockSelection.setSelectedIds({
added: [],
removed: [element],
});
}, duration);
}
},

selectedAll: () => {
Expand Down

0 comments on commit 11fb757

Please sign in to comment.