Skip to content

Commit

Permalink
Merge pull request #3855 from udecode/registry
Browse files Browse the repository at this point in the history
Update Registry
  • Loading branch information
felixfeng33 authored Dec 19, 2024
2 parents bb183f8 + bc12076 commit 126e4f1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/transforms.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"files": [
{
"content": "'use client';\n\nimport type { PlateEditor } from '@udecode/plate-common/react';\n\nimport { insertCallout } from '@udecode/plate-callout';\nimport { CalloutPlugin } from '@udecode/plate-callout/react';\nimport { insertCodeBlock } from '@udecode/plate-code-block';\nimport { CodeBlockPlugin } from '@udecode/plate-code-block/react';\nimport {\n type TElement,\n type TNodeEntry,\n getBlockAbove,\n getBlocks,\n getNodeEntry,\n insertNodes,\n removeEmptyPreviousBlock,\n setNodes,\n unsetNodes,\n withoutNormalizing,\n} from '@udecode/plate-common';\nimport { insertDate } from '@udecode/plate-date';\nimport { DatePlugin } from '@udecode/plate-date/react';\nimport { insertToc } from '@udecode/plate-heading';\nimport { TocPlugin } from '@udecode/plate-heading/react';\nimport { INDENT_LIST_KEYS, ListStyleType } from '@udecode/plate-indent-list';\nimport { IndentListPlugin } from '@udecode/plate-indent-list/react';\nimport { insertColumnGroup, toggleColumnGroup } from '@udecode/plate-layout';\nimport { LinkPlugin, triggerFloatingLink } from '@udecode/plate-link/react';\nimport { insertEquation, insertInlineEquation } from '@udecode/plate-math';\nimport {\n EquationPlugin,\n InlineEquationPlugin,\n} from '@udecode/plate-math/react';\nimport {\n insertAudioPlaceholder,\n insertFilePlaceholder,\n insertMedia,\n insertVideoPlaceholder,\n} from '@udecode/plate-media';\nimport {\n AudioPlugin,\n FilePlugin,\n ImagePlugin,\n MediaEmbedPlugin,\n VideoPlugin,\n} from '@udecode/plate-media/react';\nimport { insertTable } from '@udecode/plate-table';\nimport { TablePlugin } from '@udecode/plate-table/react';\nimport { Path } from 'slate';\n\nconst ACTION_THREE_COLUMNS = 'action_three_columns';\n\nconst insertList = (editor: PlateEditor, type: string) => {\n insertNodes(\n editor,\n editor.api.create.block({\n indent: 1,\n listStyleType: type,\n }),\n { select: true }\n );\n};\n\nconst insertBlockMap: Record<\n string,\n (editor: PlateEditor, type: string) => void\n> = {\n [ACTION_THREE_COLUMNS]: (editor) =>\n insertColumnGroup(editor, { layout: 3, select: true }),\n [AudioPlugin.key]: (editor) =>\n insertAudioPlaceholder(editor, { select: true }),\n [CalloutPlugin.key]: (editor) => insertCallout(editor, { select: true }),\n [CodeBlockPlugin.key]: (editor) => insertCodeBlock(editor, { select: true }),\n [EquationPlugin.key]: (editor) => insertEquation(editor, { select: true }),\n [FilePlugin.key]: (editor) => insertFilePlaceholder(editor, { select: true }),\n [INDENT_LIST_KEYS.todo]: insertList,\n [ImagePlugin.key]: (editor) =>\n insertMedia(editor, {\n select: true,\n type: ImagePlugin.key,\n }),\n [ListStyleType.Decimal]: insertList,\n [ListStyleType.Disc]: insertList,\n [MediaEmbedPlugin.key]: (editor) =>\n insertMedia(editor, {\n select: true,\n type: MediaEmbedPlugin.key,\n }),\n [TablePlugin.key]: (editor) => insertTable(editor, {}, { select: true }),\n [TocPlugin.key]: (editor) => insertToc(editor, { select: true }),\n [VideoPlugin.key]: (editor) =>\n insertVideoPlaceholder(editor, { select: true }),\n};\n\nconst insertInlineMap: Record<\n string,\n (editor: PlateEditor, type: string) => void\n> = {\n [DatePlugin.key]: (editor) => insertDate(editor, { select: true }),\n [InlineEquationPlugin.key]: (editor) =>\n insertInlineEquation(editor, '', { select: true }),\n [LinkPlugin.key]: (editor) => triggerFloatingLink(editor, { focused: true }),\n};\n\nexport const insertBlock = (editor: PlateEditor, type: string) => {\n withoutNormalizing(editor, () => {\n if (type in insertBlockMap) {\n insertBlockMap[type](editor, type);\n } else {\n const path = getBlockAbove(editor)?.[1];\n\n if (!path) return;\n\n const at = Path.next(path);\n\n insertNodes(editor, editor.api.create.block({ type }), {\n at,\n select: true,\n });\n }\n\n removeEmptyPreviousBlock(editor);\n });\n};\n\nexport const insertInlineElement = (editor: PlateEditor, type: string) => {\n if (insertInlineMap[type]) {\n insertInlineMap[type](editor, type);\n }\n};\n\nconst setList = (\n editor: PlateEditor,\n type: string,\n entry: TNodeEntry<TElement>\n) => {\n setNodes(\n editor,\n editor.api.create.block({\n indent: 1,\n listStyleType: type,\n }),\n {\n at: entry[1],\n }\n );\n};\n\nconst setBlockMap: Record<\n string,\n (editor: PlateEditor, type: string, entry: TNodeEntry<TElement>) => void\n> = {\n [ACTION_THREE_COLUMNS]: (editor) => toggleColumnGroup(editor, { layout: 3 }),\n [INDENT_LIST_KEYS.todo]: setList,\n [ListStyleType.Decimal]: setList,\n [ListStyleType.Disc]: setList,\n};\n\nexport const setBlockType = (\n editor: PlateEditor,\n type: string,\n { at }: { at?: Path } = {}\n) => {\n withoutNormalizing(editor, () => {\n const setEntry = (entry: TNodeEntry<TElement>) => {\n const [node, path] = entry;\n\n if (node[IndentListPlugin.key]) {\n unsetNodes(editor, [IndentListPlugin.key, 'indent'], { at: path });\n }\n if (type in setBlockMap) {\n return setBlockMap[type](editor, type, entry);\n }\n if (node.type !== type) {\n editor.setNodes<TElement>({ type }, { at: path });\n }\n };\n\n if (at) {\n const entry = getNodeEntry<TElement>(editor, at);\n\n if (entry) {\n setEntry(entry);\n\n return;\n }\n }\n\n const entries = getBlocks(editor);\n\n entries.forEach((entry) => setEntry(entry));\n });\n};\n\nexport const getBlockType = (block: TElement) => {\n if (block[IndentListPlugin.key]) {\n if (block[IndentListPlugin.key] === ListStyleType.Decimal) {\n return ListStyleType.Decimal;\n } else if (block[IndentListPlugin.key] === INDENT_LIST_KEYS.todo) {\n return INDENT_LIST_KEYS.todo;\n } else {\n return ListStyleType.Disc;\n }\n }\n\n return block.type;\n};\n",
"content": "'use client';\n\nimport type { PlateEditor } from '@udecode/plate-common/react';\n\nimport { insertCallout } from '@udecode/plate-callout';\nimport { CalloutPlugin } from '@udecode/plate-callout/react';\nimport { insertCodeBlock } from '@udecode/plate-code-block';\nimport { CodeBlockPlugin } from '@udecode/plate-code-block/react';\nimport {\n type TElement,\n type TNodeEntry,\n getBlockAbove,\n getBlocks,\n getNodeEntry,\n insertNodes,\n removeEmptyPreviousBlock,\n setNodes,\n unsetNodes,\n withoutNormalizing,\n} from '@udecode/plate-common';\nimport { insertDate } from '@udecode/plate-date';\nimport { DatePlugin } from '@udecode/plate-date/react';\nimport { insertToc } from '@udecode/plate-heading';\nimport { TocPlugin } from '@udecode/plate-heading/react';\nimport { INDENT_LIST_KEYS, ListStyleType } from '@udecode/plate-indent-list';\nimport { IndentListPlugin } from '@udecode/plate-indent-list/react';\nimport { insertColumnGroup, toggleColumnGroup } from '@udecode/plate-layout';\nimport { ColumnItemPlugin, ColumnPlugin } from '@udecode/plate-layout/react';\nimport { LinkPlugin, triggerFloatingLink } from '@udecode/plate-link/react';\nimport { insertEquation, insertInlineEquation } from '@udecode/plate-math';\nimport {\n EquationPlugin,\n InlineEquationPlugin,\n} from '@udecode/plate-math/react';\nimport {\n insertAudioPlaceholder,\n insertFilePlaceholder,\n insertMedia,\n insertVideoPlaceholder,\n} from '@udecode/plate-media';\nimport {\n AudioPlugin,\n FilePlugin,\n ImagePlugin,\n MediaEmbedPlugin,\n VideoPlugin,\n} from '@udecode/plate-media/react';\nimport { insertTable } from '@udecode/plate-table';\nimport {\n TableCellPlugin,\n TablePlugin,\n TableRowPlugin,\n} from '@udecode/plate-table/react';\nimport { Path } from 'slate';\n\nexport const STRUCTURAL_TYPES = [\n ColumnPlugin.key,\n ColumnItemPlugin.key,\n TablePlugin.key,\n TableRowPlugin.key,\n TableCellPlugin.key,\n];\n\nconst ACTION_THREE_COLUMNS = 'action_three_columns';\n\nconst insertList = (editor: PlateEditor, type: string) => {\n insertNodes(\n editor,\n editor.api.create.block({\n indent: 1,\n listStyleType: type,\n }),\n { select: true }\n );\n};\n\nconst insertBlockMap: Record<\n string,\n (editor: PlateEditor, type: string) => void\n> = {\n [ACTION_THREE_COLUMNS]: (editor) =>\n insertColumnGroup(editor, { layout: 3, select: true }),\n [AudioPlugin.key]: (editor) =>\n insertAudioPlaceholder(editor, { select: true }),\n [CalloutPlugin.key]: (editor) => insertCallout(editor, { select: true }),\n [CodeBlockPlugin.key]: (editor) => insertCodeBlock(editor, { select: true }),\n [EquationPlugin.key]: (editor) => insertEquation(editor, { select: true }),\n [FilePlugin.key]: (editor) => insertFilePlaceholder(editor, { select: true }),\n [INDENT_LIST_KEYS.todo]: insertList,\n [ImagePlugin.key]: (editor) =>\n insertMedia(editor, {\n select: true,\n type: ImagePlugin.key,\n }),\n [ListStyleType.Decimal]: insertList,\n [ListStyleType.Disc]: insertList,\n [MediaEmbedPlugin.key]: (editor) =>\n insertMedia(editor, {\n select: true,\n type: MediaEmbedPlugin.key,\n }),\n [TablePlugin.key]: (editor) => insertTable(editor, {}, { select: true }),\n [TocPlugin.key]: (editor) => insertToc(editor, { select: true }),\n [VideoPlugin.key]: (editor) =>\n insertVideoPlaceholder(editor, { select: true }),\n};\n\nconst insertInlineMap: Record<\n string,\n (editor: PlateEditor, type: string) => void\n> = {\n [DatePlugin.key]: (editor) => insertDate(editor, { select: true }),\n [InlineEquationPlugin.key]: (editor) =>\n insertInlineEquation(editor, '', { select: true }),\n [LinkPlugin.key]: (editor) => triggerFloatingLink(editor, { focused: true }),\n};\n\nexport const insertBlock = (editor: PlateEditor, type: string) => {\n withoutNormalizing(editor, () => {\n if (type in insertBlockMap) {\n insertBlockMap[type](editor, type);\n } else {\n const path = getBlockAbove(editor)?.[1];\n\n if (!path) return;\n\n const at = Path.next(path);\n\n insertNodes(editor, editor.api.create.block({ type }), {\n at,\n select: true,\n });\n }\n\n removeEmptyPreviousBlock(editor);\n });\n};\n\nexport const insertInlineElement = (editor: PlateEditor, type: string) => {\n if (insertInlineMap[type]) {\n insertInlineMap[type](editor, type);\n }\n};\n\nconst setList = (\n editor: PlateEditor,\n type: string,\n entry: TNodeEntry<TElement>\n) => {\n setNodes(\n editor,\n editor.api.create.block({\n indent: 1,\n listStyleType: type,\n }),\n {\n at: entry[1],\n }\n );\n};\n\nconst setBlockMap: Record<\n string,\n (editor: PlateEditor, type: string, entry: TNodeEntry<TElement>) => void\n> = {\n [ACTION_THREE_COLUMNS]: (editor) => toggleColumnGroup(editor, { layout: 3 }),\n [INDENT_LIST_KEYS.todo]: setList,\n [ListStyleType.Decimal]: setList,\n [ListStyleType.Disc]: setList,\n};\n\nexport const setBlockType = (\n editor: PlateEditor,\n type: string,\n { at }: { at?: Path } = {}\n) => {\n withoutNormalizing(editor, () => {\n const setEntry = (entry: TNodeEntry<TElement>) => {\n const [node, path] = entry;\n\n if (node[IndentListPlugin.key]) {\n unsetNodes(editor, [IndentListPlugin.key, 'indent'], { at: path });\n }\n if (type in setBlockMap) {\n return setBlockMap[type](editor, type, entry);\n }\n if (node.type !== type) {\n editor.setNodes<TElement>({ type }, { at: path });\n }\n };\n\n if (at) {\n const entry = getNodeEntry<TElement>(editor, at);\n\n if (entry) {\n setEntry(entry);\n\n return;\n }\n }\n\n const entries = getBlocks(editor, { mode: 'lowest' });\n\n entries.forEach((entry) => setEntry(entry));\n });\n};\n\nexport const getBlockType = (block: TElement) => {\n if (block[IndentListPlugin.key]) {\n if (block[IndentListPlugin.key] === ListStyleType.Decimal) {\n return ListStyleType.Decimal;\n } else if (block[IndentListPlugin.key] === INDENT_LIST_KEYS.todo) {\n return INDENT_LIST_KEYS.todo;\n } else {\n return ListStyleType.Disc;\n }\n }\n\n return block.type;\n};\n",
"path": "components/editor/transforms.ts",
"target": "components/editor/transforms.ts",
"type": "registry:component"
Expand Down
Loading

0 comments on commit 126e4f1

Please sign in to comment.