UNPKG

@mantine/tiptap

Version:

Rich text editor based on tiptap

1 lines 2.69 kB
{"version":3,"file":"RichTextEditorSourceCodeControl.cjs","names":["useRichTextEditorContext","RichTextEditorControl","IconBraces"],"sources":["../../src/RichTextEditorControl/RichTextEditorSourceCodeControl.tsx"],"sourcesContent":["import { useState } from 'react';\nimport { BoxProps, ElementProps, rem, useProps } from '@mantine/core';\nimport { IconBraces } from '../icons/Icons';\nimport { useRichTextEditorContext } from '../RichTextEditor.context';\nimport { RichTextEditorControl } from './RichTextEditorControl';\n\nexport interface RichTextEditorSourceCodeControlProps extends BoxProps, ElementProps<'button'> {}\n\nconst defaultProps: Partial<RichTextEditorSourceCodeControlProps> = {};\n\nexport function RichTextEditorSourceCodeControl(props: RichTextEditorSourceCodeControlProps) {\n const { ...others } = useProps('RichTextEditorSourceCodeControl', defaultProps, props);\n const { editor, labels, variant, onSourceCodeTextSwitch } = useRichTextEditorContext();\n const [isSourceCodeModeActive, setIsSourceCodeModeActive] = useState(false);\n\n const handleStateChange = () => {\n if (isSourceCodeModeActive) {\n editor?.commands.setContent(editor.getText(), { emitUpdate: true });\n } else {\n editor?.commands.setContent(`<textarea>${editor.getHTML()}</textarea>`);\n }\n\n const isSourceCodeModeActiveNew = !isSourceCodeModeActive;\n\n setIsSourceCodeModeActive(isSourceCodeModeActiveNew);\n onSourceCodeTextSwitch?.(isSourceCodeModeActiveNew);\n };\n\n return (\n <RichTextEditorControl\n {...others}\n variant={variant}\n active={isSourceCodeModeActive}\n aria-label={labels.sourceCodeControlLabel}\n title={labels.sourceCodeControlLabel}\n onClick={() => handleStateChange()}\n >\n <IconBraces style={{ width: rem(16), height: rem(16) }} />\n </RichTextEditorControl>\n );\n}\n\nRichTextEditorSourceCodeControl.displayName = '@mantine/tiptap/RichTextEditorSourceCodeControl';\n"],"mappings":";;;;;;;;;AAQA,MAAM,eAA8D,CAAC;AAErE,SAAgB,gCAAgC,OAA6C;CAC3F,MAAM,EAAE,GAAG,YAAA,GAAA,cAAA,UAAoB,mCAAmC,cAAc,KAAK;CACrF,MAAM,EAAE,QAAQ,QAAQ,SAAS,2BAA2BA,+BAAAA,yBAAyB;CACrF,MAAM,CAAC,wBAAwB,8BAAA,GAAA,MAAA,UAAsC,KAAK;CAE1E,MAAM,0BAA0B;EAC9B,IAAI,wBACF,QAAQ,SAAS,WAAW,OAAO,QAAQ,GAAG,EAAE,YAAY,KAAK,CAAC;OAElE,QAAQ,SAAS,WAAW,aAAa,OAAO,QAAQ,EAAE,YAAY;EAGxE,MAAM,4BAA4B,CAAC;EAEnC,0BAA0B,yBAAyB;EACnD,yBAAyB,yBAAyB;CACpD;CAEA,OACE,iBAAA,GAAA,kBAAA,KAACC,8BAAAA,uBAAD;EACE,GAAI;EACK;EACT,QAAQ;EACR,cAAY,OAAO;EACnB,OAAO,OAAO;EACd,eAAe,kBAAkB;YAEjC,iBAAA,GAAA,kBAAA,KAACC,cAAAA,YAAD,EAAY,OAAO;GAAE,QAAA,GAAA,cAAA,KAAW,EAAE;GAAG,SAAA,GAAA,cAAA,KAAY,EAAE;EAAE,EAAI,CAAA;CACpC,CAAA;AAE3B;AAEA,gCAAgC,cAAc"}