Skip to content

Commit

Permalink
Merge pull request #2635 from udecode/fix/id
Browse files Browse the repository at this point in the history
Plate id prop string
  • Loading branch information
zbeyens authored Sep 18, 2023
2 parents d376b1b + 6f27879 commit a98c032
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-avocados-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-core': patch
---

- Fix: set Plate `id` prop type to `string` to satisfy [HTML specs](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id).
2 changes: 1 addition & 1 deletion apps/www/content/docs/api/core/plate.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: API reference for Plate component.
## Plate Props

<APIParameters>
<APIItem name="id" type="symbol | string | number" optional>
<APIItem name="id" type="string" optional>
A unique ID to store the editor state by ID. This is mandatory when nesting **`Plate`** instances but optional otherwise.

- **Default:** `'plate'`.
Expand Down
3 changes: 1 addition & 2 deletions apps/www/src/lib/plate/demo/plugins/emojiPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { RenderAfterEditable } from '@udecode/plate-common';
import { EmojiPlugin } from '@udecode/plate-emoji';

import { MyPlatePlugin } from '@/types/plate-types';
import { EmojiCombobox } from '@/registry/default/plate-ui/emoji-combobox';

export const emojiPlugin: Partial<MyPlatePlugin<EmojiPlugin>> = {
renderAfterEditable: EmojiCombobox as RenderAfterEditable,
renderAfterEditable: EmojiCombobox,
};
6 changes: 3 additions & 3 deletions packages/core/src/components/Plate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,21 @@ describe('Plate', () => {
const _plugins = [{ key: 'test1' }];

const wrapper = ({ children, id }: any) => (
<Plate id={id} plugins={id === 1 ? _plugins : undefined}>
<Plate id={id} plugins={id === '1' ? _plugins : undefined}>
{children}
</Plate>
);
const { result, rerender } = renderHook(
({ id }) => usePlateSelectors(id).plugins(),
{
wrapper,
initialProps: { id: 1 },
initialProps: { id: '1' },
}
);

expect(result.current.at(-1)!.key).toBe('test1');

rerender({ id: 2 });
rerender({ id: '2' });

expect(result.current.at(-1)!.key).not.toBe('test1');
});
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/stores/plate/createPlateStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SetRecord,
UseRecord,
} from '../../atoms/index';
import { Scope, useAtom } from '../../libs/index';
import { useAtom } from '../../libs/index';
import { PlateEditor } from '../../types/PlateEditor';
import { PlateStoreState } from '../../types/PlateStore';

Expand All @@ -17,7 +17,7 @@ import { PlateStoreState } from '../../types/PlateStore';
* Use it if you have multiple `Plate` in the same React tree.
* @default PLATE_SCOPE
*/
export type PlateId = Scope;
export type PlateId = string;

export const PLATE_SCOPE = 'plate';
export const GLOBAL_PLATE_SCOPE = Symbol('global-plate');
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/types/slate-react/TEditableProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import { RenderLeafFn, TNodeEntry } from '@udecode/slate';
import { Range } from 'slate';
import { EditableProps } from 'slate-react/dist/components/editable';

import { PlateId } from '../../stores/index';
import { RenderElementFn } from './TRenderElementProps';

/**
* `EditableProps` are passed to the <Editable> component.
*/
export type TEditableProps = Omit<
EditableProps,
'id' | 'decorate' | 'renderElement' | 'renderLeaf'
'decorate' | 'renderElement' | 'renderLeaf'
> & {
id?: PlateId;
decorate?: (entry: TNodeEntry) => Range[];
renderElement?: RenderElementFn;
renderLeaf?: RenderLeafFn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export const plugins = createPlugins(
options: { enableScroller: true },
}),
createEmojiPlugin({
renderAfterEditable: EmojiCombobox,
renderAfterEditable: EmojiCombobox as RenderAfterEditable,
}),
createExitBreakPlugin({
options: {
Expand Down

0 comments on commit a98c032

Please sign in to comment.