Skip to content

Commit

Permalink
Merge pull request #3683 from udecode/history/callout
Browse files Browse the repository at this point in the history
History/callout
  • Loading branch information
felixfeng33 authored Oct 29, 2024
2 parents 0d2b00c + 149e7e4 commit 4b21c60
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-goats-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-callout': patch
---

`insertCallout`: Add an icon option; if none is provided, use the last one stored in local storage.
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 4b21c60

Please sign in to comment.