{"version":3,"file":"conversions.mjs","sources":["../../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/conversions.ts"],"sourcesContent":["import { type Element, type Path, Editor, Transforms } from 'slate';\n\n/**\n * Extracts some logic that is common to most blocks' handleConvert functions.\n * @returns The path of the converted block\n */\nconst baseHandleConvert = (\n editor: Editor,\n attributesToSet: Partial & { type: T['type'] }\n): void | Path => {\n // If there is no selection, convert last inserted node\n const [_, lastNodePath] = Editor.last(editor, []);\n\n // If the selection is inside a list, split the list so that the modified block is outside of it\n Transforms.unwrapNodes(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'list',\n split: true,\n at: editor.selection ?? lastNodePath,\n });\n\n // Make sure we get a block node, not an inline node\n const [, updatedLastNodePath] = Editor.last(editor, []);\n const entry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type !== 'text' && node.type !== 'link',\n at: editor.selection ?? updatedLastNodePath,\n });\n\n if (!entry || Editor.isEditor(entry[0])) {\n return;\n }\n\n const [element, elementPath] = entry;\n\n Transforms.setNodes(\n editor,\n {\n ...getAttributesToClear(element),\n ...attributesToSet,\n } as Partial,\n { at: elementPath }\n );\n\n return elementPath;\n};\n\n/**\n * Set all attributes except type and children to null so that Slate deletes them\n */\nconst getAttributesToClear = (element: Element) => {\n const { children: _children, type: _type, ...extra } = element;\n\n const attributesToClear = Object.keys(extra).reduce(\n (currentAttributes, key) => ({ ...currentAttributes, [key]: null }),\n {}\n );\n\n return attributesToClear as Record;\n};\n\nexport { baseHandleConvert, getAttributesToClear };\n"],"names":["baseHandleConvert","editor","attributesToSet","_","lastNodePath","Editor","last","Transforms","unwrapNodes","match","node","isEditor","type","split","at","selection","updatedLastNodePath","entry","above","element","elementPath","setNodes","getAttributesToClear","children","_children","_type","extra","attributesToClear","Object","keys","reduce","currentAttributes","key"],"mappings":";;AAEA;;;IAIA,MAAMA,iBAAAA,GAAoB,CACxBC,MAAAA,EACAC,eAAAA,GAAAA;;IAGA,MAAM,CAACC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