Skip to content

Commit

Permalink
feat
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfeng33 committed Oct 29, 2024
1 parent 0d2b00c commit 0bb0239
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/callout/src/lib/transforms/insertCallout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@ import {
insertNodes,
} from '@udecode/plate-common';

import { CalloutPlugin } from '../../react';
import { type TCalloutElement, BaseCalloutPlugin } from '../BaseCalloutPlugin';

export const CALLOUT_STORAGE_KEY = `plate-storage-${CalloutPlugin.key}`;

export const insertCallout = <E extends SlateEditor>(
editor: E,
{
icon,
variant,
...options
}: InsertNodesOptions<E> & {
icon?: string;
variant?: (string & {}) | TCalloutElement['variant'];
} = {}
) => {
insertNodes<TCalloutElement>(
editor,
{
children: [{ text: '' }],
icon: icon ?? localStorage.getItem(CALLOUT_STORAGE_KEY) ?? '💡',
type: editor.getType(BaseCalloutPlugin),
variant,
},
options as any
);

icon && localStorage.setItem(CALLOUT_STORAGE_KEY, icon);
};

0 comments on commit 0bb0239

Please sign in to comment.