@bikdotai/bik-component-library 0.0.809 → 0.0.810
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/editor/BikEditor.js +1 -1
- package/dist/cjs/editor/BikEditor.js.map +1 -1
- package/dist/cjs/editor/BikEditor.styles.js +10 -5
- package/dist/cjs/editor/BikEditor.styles.js.map +1 -1
- package/dist/cjs/editor/BikEditor.types.js.map +1 -1
- package/dist/cjs/editor/BikEditor.utils.js +1 -1
- package/dist/cjs/editor/BikEditor.utils.js.map +1 -1
- package/dist/cjs/editor/extensions/buildExtensions.js +1 -1
- package/dist/cjs/editor/extensions/buildExtensions.js.map +1 -1
- package/dist/cjs/editor/extensions/plainClipboard/PasteNormalizationExtension.js +2 -0
- package/dist/cjs/editor/extensions/plainClipboard/PasteNormalizationExtension.js.map +1 -0
- package/dist/cjs/editor/extensions/plainClipboard/pasteUtils.js +1 -1
- package/dist/cjs/editor/extensions/plainClipboard/pasteUtils.js.map +1 -1
- package/dist/cjs/node_modules/@tiptap/extension-paragraph/dist/index.js +2 -0
- package/dist/cjs/node_modules/@tiptap/extension-paragraph/dist/index.js.map +1 -0
- package/dist/cjs/src/editor/BikEditor.styles.d.ts +1 -0
- package/dist/cjs/src/editor/BikEditor.types.d.ts +2 -0
- package/dist/cjs/src/editor/BikEditor.utils.d.ts +8 -4
- package/dist/cjs/src/editor/extensions/buildExtensions.d.ts +2 -1
- package/dist/cjs/src/editor/extensions/plainClipboard/PasteNormalizationExtension.d.ts +13 -0
- package/dist/cjs/src/editor/extensions/plainClipboard/pasteUtils.d.ts +40 -8
- package/dist/esm/editor/BikEditor.js +1 -1
- package/dist/esm/editor/BikEditor.js.map +1 -1
- package/dist/esm/editor/BikEditor.styles.js +14 -9
- package/dist/esm/editor/BikEditor.styles.js.map +1 -1
- package/dist/esm/editor/BikEditor.types.js.map +1 -1
- package/dist/esm/editor/BikEditor.utils.js +1 -1
- package/dist/esm/editor/BikEditor.utils.js.map +1 -1
- package/dist/esm/editor/extensions/buildExtensions.js +1 -1
- package/dist/esm/editor/extensions/buildExtensions.js.map +1 -1
- package/dist/esm/editor/extensions/plainClipboard/PasteNormalizationExtension.js +2 -0
- package/dist/esm/editor/extensions/plainClipboard/PasteNormalizationExtension.js.map +1 -0
- package/dist/esm/editor/extensions/plainClipboard/pasteUtils.js +1 -1
- package/dist/esm/editor/extensions/plainClipboard/pasteUtils.js.map +1 -1
- package/dist/esm/node_modules/@tiptap/extension-paragraph/dist/index.js +2 -0
- package/dist/esm/node_modules/@tiptap/extension-paragraph/dist/index.js.map +1 -0
- package/dist/esm/src/editor/BikEditor.styles.d.ts +1 -0
- package/dist/esm/src/editor/BikEditor.types.d.ts +2 -0
- package/dist/esm/src/editor/BikEditor.utils.d.ts +8 -4
- package/dist/esm/src/editor/extensions/buildExtensions.d.ts +2 -1
- package/dist/esm/src/editor/extensions/plainClipboard/PasteNormalizationExtension.d.ts +13 -0
- package/dist/esm/src/editor/extensions/plainClipboard/pasteUtils.d.ts +40 -8
- package/package.json +1 -1
- package/dist/cjs/editor/extensions/plainClipboard/ClipboardNormalizationExtension.js +0 -2
- package/dist/cjs/editor/extensions/plainClipboard/ClipboardNormalizationExtension.js.map +0 -1
- package/dist/cjs/editor/extensions/plainClipboard/PlainClipboardExtension.js +0 -2
- package/dist/cjs/editor/extensions/plainClipboard/PlainClipboardExtension.js.map +0 -1
- package/dist/cjs/src/editor/extensions/plainClipboard/ClipboardNormalizationExtension.d.ts +0 -7
- package/dist/cjs/src/editor/extensions/plainClipboard/PlainClipboardExtension.d.ts +0 -2
- package/dist/esm/editor/extensions/plainClipboard/ClipboardNormalizationExtension.js +0 -2
- package/dist/esm/editor/extensions/plainClipboard/ClipboardNormalizationExtension.js.map +0 -1
- package/dist/esm/editor/extensions/plainClipboard/PlainClipboardExtension.js +0 -2
- package/dist/esm/editor/extensions/plainClipboard/PlainClipboardExtension.js.map +0 -1
- package/dist/esm/src/editor/extensions/plainClipboard/ClipboardNormalizationExtension.d.ts +0 -7
- package/dist/esm/src/editor/extensions/plainClipboard/PlainClipboardExtension.d.ts +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildExtensions.js","sources":["../../../../src/editor/extensions/buildExtensions.ts"],"sourcesContent":["import CharacterCount from '@tiptap/extension-character-count';\nimport Color from '@tiptap/extension-color';\nimport FontFamily from '@tiptap/extension-font-family';\nimport Highlight from '@tiptap/extension-highlight';\nimport Image from '@tiptap/extension-image';\nimport Link from '@tiptap/extension-link';\nimport Placeholder from '@tiptap/extension-placeholder';\nimport Subscript from '@tiptap/extension-subscript';\nimport Superscript from '@tiptap/extension-superscript';\nimport TextAlign from '@tiptap/extension-text-align';\nimport { TextStyle } from '@tiptap/extension-text-style';\nimport Underline from '@tiptap/extension-underline';\nimport StarterKit from '@tiptap/starter-kit';\nimport type { ReactNode } from 'react';\nimport type {\n\tEditorFeatures,\n\tEditorSnapshot,\n\tKeyboardShortcut,\n\tMentionDropdownRenderProps,\n\tMentionItem,\n\tPasteData,\n\tSlashCommandDropdownRenderProps,\n\tSlashCommandItem,\n} from '../BikEditor.types';\nimport { FontSizeExtension } from './FontSizeExtension';\nimport {\n\tbuildAgentMentionExtension,\n\tbuildTeamMentionExtension,\n} from './mention/MentionExtension';\nimport { PasteExtension } from './paste/PasteExtension';\nimport { ClipboardNormalizationExtension } from './plainClipboard/ClipboardNormalizationExtension';\nimport { PlainClipboardExtension } from './plainClipboard/PlainClipboardExtension';\nimport { SectionDividerNode } from './sectionDivider/SectionDividerNode';\nimport { SendShortcutExtension } from './sendShortcut/SendShortcutExtension';\nimport { buildSlashCommandExtension } from './slashCommand/SlashCommandExtension';\nimport { VariableDecorationExtension } from './variable/VariableDecorationExtension';\n\ninterface ExtensionConfig {\n\tfeatures?: EditorFeatures;\n\tplaceholder?: string;\n\tmaxCharacters?: number;\n\thasSections?: boolean;\n\tmentions?: {\n\t\tagents?: { current: MentionItem[] };\n\t\tteams?: { current: MentionItem[] };\n\t};\n\tslashCommands?: { current: SlashCommandItem[] };\n\tonPaste?: (data: PasteData) => boolean | void;\n\tonSend?: (content: EditorSnapshot) => void;\n\tsendShortcut?:\n\t\t| { key: string; modifiers?: Array<'mod' | 'ctrl' | 'shift' | 'alt'> }\n\t\t| Array<{\n\t\t\t\tkey: string;\n\t\t\t\tmodifiers?: Array<'mod' | 'ctrl' | 'shift' | 'alt'>;\n\t\t }>;\n\tshortcuts?: KeyboardShortcut[];\n\tonMentionSelected?: (item: MentionItem, char: '@' | '#') => void;\n\tonSlashCommandSelected?: (command: SlashCommandItem) => void;\n\trenderMentionItem?: (item: MentionItem, isActive: boolean) => ReactNode;\n\trenderMentionDropdown?: (props: MentionDropdownRenderProps) => ReactNode;\n\trenderSlashCommandItem?: (\n\t\titem: SlashCommandItem,\n\t\tisActive: boolean,\n\t) => ReactNode;\n\trenderSlashCommandDropdown?: (\n\t\tprops: SlashCommandDropdownRenderProps,\n\t) => ReactNode;\n}\n\nexport function buildExtensions(config: ExtensionConfig) {\n\tconst hasRichPaste = config.features?.richPaste ?? false;\n\tconst hasRichTypography = config.features?.richTypography ?? false;\n\n\t// When allowedMarks is specified only those marks are registered in the schema.\n\t// This disables rendering, keyboard shortcuts AND paste-preservation for the\n\t// excluded marks — all three come for free when the extension is absent.\n\tconst allowedMarks = config.features?.allowedMarks;\n\tconst isMark = (m: 'bold' | 'italic' | 'strike' | 'underline' | 'code') =>\n\t\t!allowedMarks || allowedMarks.includes(m);\n\n\tconst base = [\n\t\t// Exclude Link and Underline from StarterKit — TipTap v3 bundles both.\n\t\t// Without this, two copies of each are registered and the StarterKit copy's\n\t\t// click handler calls window.open even when openOnClick: false is set.\n\t\tStarterKit.configure({\n\t\t\tlink: false,\n\t\t\tunderline: false,\n\t\t\tbold: isMark('bold') ? {} : false,\n\t\t\titalic: isMark('italic') ? {} : false,\n\t\t\tstrike: isMark('strike') ? {} : false,\n\t\t\tcode: isMark('code') ? {} : false,\n\t\t}),\n\t\t...(isMark('underline') ? [Underline] : []),\n\t\t// Extend Link to strip addPasteRules() and addInputRules() so pasting a\n\t\t// URL never creates a hyperlink regardless of autolink/linkOnPaste values.\n\t\tLink.extend({\n\t\t\taddPasteRules: () => [],\n\t\t\taddInputRules: () => [],\n\t\t}).configure({\n\t\t\topenOnClick: false,\n\t\t\tautolink: false,\n\t\t\tlinkOnPaste: false,\n\t\t\tHTMLAttributes: {\n\t\t\t\trel: 'noopener noreferrer',\n\t\t\t\tclass: 'bik-link',\n\t\t\t},\n\t\t}),\n\t\tTextStyle,\n\t\tPlaceholder.configure({\n\t\t\tplaceholder: config.placeholder ?? 'Type a message...',\n\t\t}),\n\t\t// Consumer paste callback runs first. If it returns true the event is\n\t\t// consumed and neither PlainClipboardExtension nor the editor's default\n\t\t// paste handling will run for that event.\n\t\t...(config.onPaste\n\t\t\t? [PasteExtension.configure({ onPaste: config.onPaste })]\n\t\t\t: []),\n\t\t// Non-rich editors: strip rich marks + normalize blanks on paste.\n\t\t// Rich editors (email): only normalize blanks (fix Google Docs spacing).\n\t\t...(!hasRichPaste\n\t\t\t? [PlainClipboardExtension]\n\t\t\t: [ClipboardNormalizationExtension]),\n\t\tSendShortcutExtension.configure({\n\t\t\tonSend: config.onSend,\n\t\t\tsendShortcut: config.sendShortcut,\n\t\t\textraShortcuts: config.shortcuts ?? [],\n\t\t}),\n\t\tVariableDecorationExtension,\n\t\t...(config.maxCharacters\n\t\t\t? [CharacterCount.configure({ limit: config.maxCharacters })]\n\t\t\t: []),\n\t\t// Always register SectionDividerNode so the custom <div data-section-divider>\n\t\t// node is part of the schema in every editor instance. This means imperative\n\t\t// callers (setBodyAndSections / setSectionContent) work even when no\n\t\t// `sections` prop was provided at mount time.\n\t\tSectionDividerNode,\n\t];\n\n\tconst mentionExtensions = [\n\t\t...(config.mentions?.agents\n\t\t\t? [\n\t\t\t\t\tbuildAgentMentionExtension(\n\t\t\t\t\t\tconfig.mentions.agents,\n\t\t\t\t\t\tconfig.onMentionSelected,\n\t\t\t\t\t\tconfig.renderMentionItem,\n\t\t\t\t\t\tconfig.renderMentionDropdown,\n\t\t\t\t\t),\n\t\t\t ]\n\t\t\t: []),\n\t\t...(config.mentions?.teams\n\t\t\t? [\n\t\t\t\t\tbuildTeamMentionExtension(\n\t\t\t\t\t\tconfig.mentions.teams,\n\t\t\t\t\t\tconfig.onMentionSelected,\n\t\t\t\t\t\tconfig.renderMentionItem,\n\t\t\t\t\t\tconfig.renderMentionDropdown,\n\t\t\t\t\t),\n\t\t\t ]\n\t\t\t: []),\n\t\t...(config.slashCommands\n\t\t\t? [\n\t\t\t\t\tbuildSlashCommandExtension(\n\t\t\t\t\t\tconfig.slashCommands,\n\t\t\t\t\t\tconfig.onSlashCommandSelected,\n\t\t\t\t\t\tconfig.renderSlashCommandItem,\n\t\t\t\t\t\tconfig.renderSlashCommandDropdown,\n\t\t\t\t\t),\n\t\t\t ]\n\t\t\t: []),\n\t];\n\n\tconst richExtensions = hasRichTypography\n\t\t? [\n\t\t\t\tColor,\n\t\t\t\tHighlight.configure({ multicolor: true }),\n\t\t\t\tFontFamily,\n\t\t\t\tFontSizeExtension,\n\t\t\t\tTextAlign.configure({ types: ['heading', 'paragraph'] }),\n\t\t\t\tSubscript,\n\t\t\t\tSuperscript,\n\t\t\t\tImage,\n\t\t ]\n\t\t: [Color];\n\n\treturn [...base, ...mentionExtensions, ...richExtensions];\n}\n"],"names":["buildExtensions","config","hasRichPaste","_b","_a","features","richPaste","hasRichTypography","_d","_c","richTypography","allowedMarks","_e","isMark","m","includes","StarterKit","configure","link","underline","bold","italic","strike","code","Underline","Link","extend","addPasteRules","addInputRules","openOnClick","autolink","linkOnPaste","HTMLAttributes","rel","class","TextStyle","Placeholder","placeholder","_f","onPaste","PasteExtension","ClipboardNormalizationExtension","PlainClipboardExtension","SendShortcutExtension","onSend","sendShortcut","extraShortcuts","_g","shortcuts","VariableDecorationExtension","maxCharacters","CharacterCount","limit","SectionDividerNode","_h","mentions","agents","buildAgentMentionExtension","onMentionSelected","renderMentionItem","renderMentionDropdown","_j","teams","buildTeamMentionExtension","slashCommands","buildSlashCommandExtension","onSlashCommandSelected","renderSlashCommandItem","renderSlashCommandDropdown","Color","Highlight","multicolor","FontFamily","FontSizeExtension","TextAlign","types","Subscript","Superscript","Image"],"mappings":"0xCAqEM,SAAUA,EAAgBC,yBAC/B,MAAMC,EAA6C,QAA9BC,EAAiB,QAAjBC,EAAAH,EAAOI,gBAAU,IAAAD,OAAA,EAAAA,EAAAE,iBAAa,IAAAH,GAAAA,EAC7CI,EAAuD,QAAnCC,EAAiB,QAAjBC,EAAAR,EAAOI,gBAAU,IAAAI,OAAA,EAAAA,EAAAC,sBAAkB,IAAAF,GAAAA,EAKvDG,EAA8B,QAAfC,EAAAX,EAAOI,gBAAQ,IAAAO,OAAA,EAAAA,EAAED,aAChCE,EAAUC,IACdH,GAAgBA,EAAaI,SAASD,GA0GxC,MAAO,IAxGM,CAIZE,EAAWC,UAAU,CACpBC,MAAM,EACNC,WAAW,EACXC,OAAMP,EAAO,SAAU,CAAE,EACzBQ,SAAQR,EAAO,WAAY,CAAE,EAC7BS,SAAQT,EAAO,WAAY,CAAE,EAC7BU,OAAMV,EAAO,SAAU,CAAE,OAEtBA,EAAO,aAAe,CAACW,GAAa,GAGxCC,EAAKC,OAAO,CACXC,cAAeA,IAAM,GACrBC,cAAeA,IAAM,KACnBX,UAAU,CACZY,aAAa,EACbC,UAAU,EACVC,aAAa,EACbC,eAAgB,CACfC,IAAK,sBACLC,MAAO,cAGTC,EACAC,EAAYnB,UAAU,CACrBoB,oBAAaC,EAAArC,EAAOoC,2BAAe,yBAKhCpC,EAAOsC,QACR,CAACC,EAAevB,UAAU,CAAEsB,QAAStC,EAAOsC,WAC5C,MAGErC,EAEF,CAACuC,GADD,CAACC,GAEJC,EAAsB1B,UAAU,CAC/B2B,OAAQ3C,EAAO2C,OACfC,aAAc5C,EAAO4C,aACrBC,uBAAgBC,EAAA9C,EAAO+C,yBAAa,KAErCC,KACIhD,EAAOiD,cACR,CAACC,EAAelC,UAAU,CAAEmC,MAAOnD,EAAOiD,iBAC1C,GAKHG,MAGyB,aACrBC,EAAArD,EAAOsD,+BAAUC,QAClB,CACAC,EACCxD,EAAOsD,SAASC,OAChBvD,EAAOyD,kBACPzD,EAAO0D,kBACP1D,EAAO2D,wBAGR,eACCC,EAAA5D,EAAOsD,+BAAUO,OAClB,CACAC,EACC9D,EAAOsD,SAASO,MAChB7D,EAAOyD,kBACPzD,EAAO0D,kBACP1D,EAAO2D,wBAGR,MACC3D,EAAO+D,cACR,CACAC,EACChE,EAAO+D,cACP/D,EAAOiE,uBACPjE,EAAOkE,uBACPlE,EAAOmE,6BAGR,OAGmB7D,EACpB,CACA8D,EACAC,EAAUrD,UAAU,CAAEsD,YAAY,IAClCC,EACAC,EACAC,EAAUzD,UAAU,CAAE0D,MAAO,CAAC,UAAW,eACzCC,EACAC,EACAC,GAEA,CAACT,GAGL"}
|
|
1
|
+
{"version":3,"file":"buildExtensions.js","sources":["../../../../src/editor/extensions/buildExtensions.ts"],"sourcesContent":["import { Extension, mergeAttributes } from '@tiptap/core';\nimport CharacterCount from '@tiptap/extension-character-count';\nimport Color from '@tiptap/extension-color';\nimport FontFamily from '@tiptap/extension-font-family';\nimport Highlight from '@tiptap/extension-highlight';\nimport Image from '@tiptap/extension-image';\nimport Link from '@tiptap/extension-link';\nimport Paragraph from '@tiptap/extension-paragraph';\nimport Placeholder from '@tiptap/extension-placeholder';\nimport Subscript from '@tiptap/extension-subscript';\nimport Superscript from '@tiptap/extension-superscript';\nimport TextAlign from '@tiptap/extension-text-align';\nimport { TextStyle } from '@tiptap/extension-text-style';\nimport Underline from '@tiptap/extension-underline';\nimport StarterKit from '@tiptap/starter-kit';\nimport type { ReactNode } from 'react';\nimport type {\n\tEditorFeatures,\n\tEditorSnapshot,\n\tKeyboardShortcut,\n\tMentionDropdownRenderProps,\n\tMentionItem,\n\tPasteData,\n\tSlashCommandDropdownRenderProps,\n\tSlashCommandItem,\n} from '../BikEditor.types';\nimport { FontSizeExtension } from './FontSizeExtension';\nimport {\n\tbuildAgentMentionExtension,\n\tbuildTeamMentionExtension,\n} from './mention/MentionExtension';\nimport { PasteExtension } from './paste/PasteExtension';\nimport { PasteNormalizationExtension } from './plainClipboard/PasteNormalizationExtension';\nimport { SectionDividerNode } from './sectionDivider/SectionDividerNode';\nimport { SendShortcutExtension } from './sendShortcut/SendShortcutExtension';\nimport { buildSlashCommandExtension } from './slashCommand/SlashCommandExtension';\nimport { VariableDecorationExtension } from './variable/VariableDecorationExtension';\n\ninterface ExtensionConfig {\n\tfeatures?: EditorFeatures;\n\tplaceholder?: string;\n\tmaxCharacters?: number;\n\thasSections?: boolean;\n\tmentions?: {\n\t\tagents?: { current: MentionItem[] };\n\t\tteams?: { current: MentionItem[] };\n\t};\n\tslashCommands?: { current: SlashCommandItem[] };\n\tonPaste?: (data: PasteData) => boolean | void;\n\tonSend?: (content: EditorSnapshot) => void;\n\tsendShortcut?:\n\t\t| { key: string; modifiers?: Array<'mod' | 'ctrl' | 'shift' | 'alt'> }\n\t\t| Array<{\n\t\t\t\tkey: string;\n\t\t\t\tmodifiers?: Array<'mod' | 'ctrl' | 'shift' | 'alt'>;\n\t\t }>;\n\tshortcuts?: KeyboardShortcut[];\n\tonMentionSelected?: (item: MentionItem, char: '@' | '#') => void;\n\tonSlashCommandSelected?: (command: SlashCommandItem) => void;\n\trenderMentionItem?: (item: MentionItem, isActive: boolean) => ReactNode;\n\trenderMentionDropdown?: (props: MentionDropdownRenderProps) => ReactNode;\n\trenderSlashCommandItem?: (\n\t\titem: SlashCommandItem,\n\t\tisActive: boolean,\n\t) => ReactNode;\n\trenderSlashCommandDropdown?: (\n\t\tprops: SlashCommandDropdownRenderProps,\n\t) => ReactNode;\n}\n\nexport function buildExtensions(config: ExtensionConfig) {\n\tconst hasRichPaste = config.features?.richPaste ?? false;\n\tconst hasRichTypography = config.features?.richTypography ?? false;\n\n\t// When allowedMarks is specified only those marks are registered in the schema.\n\t// This disables rendering, keyboard shortcuts AND paste-preservation for the\n\t// excluded marks — all three come for free when the extension is absent.\n\tconst allowedMarks = config.features?.allowedMarks;\n\tconst isMark = (m: 'bold' | 'italic' | 'strike' | 'underline' | 'code') =>\n\t\t!allowedMarks || allowedMarks.includes(m);\n\n\tconst emailParagraph = Paragraph.extend({\n\t\trenderHTML({ HTMLAttributes }) {\n\t\t\treturn [\n\t\t\t\t'p',\n\t\t\t\tmergeAttributes(HTMLAttributes, {\n\t\t\t\t\tstyle: 'margin: 0px; padding: 0px;',\n\t\t\t\t}),\n\t\t\t\t0,\n\t\t\t];\n\t\t},\n\t});\n\n\tconst base = [\n\t\t// Exclude Link and Underline from StarterKit — TipTap v3 bundles both.\n\t\t// Without this, two copies of each are registered and the StarterKit copy's\n\t\t// click handler calls window.open even when openOnClick: false is set.\n\t\tStarterKit.configure({\n\t\t\tlink: false,\n\t\t\tunderline: false,\n\t\t\tparagraph: hasRichPaste ? false : {},\n\t\t\thardBreak: false,\n\t\t\tbold: isMark('bold') ? {} : false,\n\t\t\titalic: isMark('italic') ? {} : false,\n\t\t\tstrike: isMark('strike') ? {} : false,\n\t\t\tcode: isMark('code') ? {} : false,\n\t\t}),\n\t\tExtension.create({\n\t\t\tname: 'shiftEnterParagraph',\n\t\t\taddKeyboardShortcuts() {\n\t\t\t\treturn {\n\t\t\t\t\t'Shift-Enter': ({ editor }) => editor.commands.splitBlock(),\n\t\t\t\t};\n\t\t\t},\n\t\t}),\n\t\t...(hasRichPaste ? [emailParagraph] : []),\n\t\t...(isMark('underline') ? [Underline] : []),\n\t\t// Extend Link to strip addPasteRules() and addInputRules() so pasting a\n\t\t// URL never creates a hyperlink regardless of autolink/linkOnPaste values.\n\t\tLink.extend({\n\t\t\taddPasteRules: () => [],\n\t\t\taddInputRules: () => [],\n\t\t}).configure({\n\t\t\topenOnClick: false,\n\t\t\tautolink: false,\n\t\t\tlinkOnPaste: false,\n\t\t\tHTMLAttributes: {\n\t\t\t\trel: 'noopener noreferrer',\n\t\t\t\tclass: 'bik-link',\n\t\t\t},\n\t\t}),\n\t\tTextStyle,\n\t\tPlaceholder.configure({\n\t\t\tplaceholder: config.placeholder ?? 'Type a message...',\n\t\t}),\n\t\t// Consumer paste callback runs first. If it returns true the event is\n\t\t// consumed and neither PlainClipboardExtension nor the editor's default\n\t\t// paste handling will run for that event.\n\t\t...(config.onPaste\n\t\t\t? [PasteExtension.configure({ onPaste: config.onPaste })]\n\t\t\t: []),\n\t\tPasteNormalizationExtension.configure({\n\t\t\tpreserveMarks: hasRichPaste,\n\t\t}),\n\t\tSendShortcutExtension.configure({\n\t\t\tonSend: config.onSend,\n\t\t\tsendShortcut: config.sendShortcut,\n\t\t\textraShortcuts: config.shortcuts ?? [],\n\t\t}),\n\t\tVariableDecorationExtension,\n\t\t...(config.maxCharacters\n\t\t\t? [CharacterCount.configure({ limit: config.maxCharacters })]\n\t\t\t: []),\n\t\t// Always register SectionDividerNode so the custom <div data-section-divider>\n\t\t// node is part of the schema in every editor instance. This means imperative\n\t\t// callers (setBodyAndSections / setSectionContent) work even when no\n\t\t// `sections` prop was provided at mount time.\n\t\tSectionDividerNode,\n\t];\n\n\tconst mentionExtensions = [\n\t\t...(config.mentions?.agents\n\t\t\t? [\n\t\t\t\t\tbuildAgentMentionExtension(\n\t\t\t\t\t\tconfig.mentions.agents,\n\t\t\t\t\t\tconfig.onMentionSelected,\n\t\t\t\t\t\tconfig.renderMentionItem,\n\t\t\t\t\t\tconfig.renderMentionDropdown,\n\t\t\t\t\t),\n\t\t\t ]\n\t\t\t: []),\n\t\t...(config.mentions?.teams\n\t\t\t? [\n\t\t\t\t\tbuildTeamMentionExtension(\n\t\t\t\t\t\tconfig.mentions.teams,\n\t\t\t\t\t\tconfig.onMentionSelected,\n\t\t\t\t\t\tconfig.renderMentionItem,\n\t\t\t\t\t\tconfig.renderMentionDropdown,\n\t\t\t\t\t),\n\t\t\t ]\n\t\t\t: []),\n\t\t...(config.slashCommands\n\t\t\t? [\n\t\t\t\t\tbuildSlashCommandExtension(\n\t\t\t\t\t\tconfig.slashCommands,\n\t\t\t\t\t\tconfig.onSlashCommandSelected,\n\t\t\t\t\t\tconfig.renderSlashCommandItem,\n\t\t\t\t\t\tconfig.renderSlashCommandDropdown,\n\t\t\t\t\t),\n\t\t\t ]\n\t\t\t: []),\n\t];\n\n\tconst richExtensions = hasRichTypography\n\t\t? [\n\t\t\t\tColor,\n\t\t\t\tHighlight.configure({ multicolor: true }),\n\t\t\t\tFontFamily,\n\t\t\t\tFontSizeExtension,\n\t\t\t\tTextAlign.configure({ types: ['heading', 'paragraph'] }),\n\t\t\t\tSubscript,\n\t\t\t\tSuperscript,\n\t\t\t\tImage,\n\t\t ]\n\t\t: [Color];\n\n\treturn [...base, ...mentionExtensions, ...richExtensions];\n}\n"],"names":["buildExtensions","config","hasRichPaste","_b","_a","features","richPaste","hasRichTypography","_d","_c","richTypography","allowedMarks","_e","isMark","m","includes","emailParagraph","Paragraph","extend","renderHTML","_ref","HTMLAttributes","mergeAttributes","style","StarterKit","configure","link","underline","paragraph","hardBreak","bold","italic","strike","code","Extension","create","name","addKeyboardShortcuts","_ref2","editor","commands","splitBlock","Underline","Link","addPasteRules","addInputRules","openOnClick","autolink","linkOnPaste","rel","class","TextStyle","Placeholder","placeholder","_f","onPaste","PasteExtension","PasteNormalizationExtension","preserveMarks","SendShortcutExtension","onSend","sendShortcut","extraShortcuts","_g","shortcuts","VariableDecorationExtension","maxCharacters","CharacterCount","limit","SectionDividerNode","_h","mentions","agents","buildAgentMentionExtension","onMentionSelected","renderMentionItem","renderMentionDropdown","_j","teams","buildTeamMentionExtension","slashCommands","buildSlashCommandExtension","onSlashCommandSelected","renderSlashCommandItem","renderSlashCommandDropdown","Color","Highlight","multicolor","FontFamily","FontSizeExtension","TextAlign","types","Subscript","Superscript","Image"],"mappings":"u2CAsEM,SAAUA,EAAgBC,yBAC/B,MAAMC,EAA6C,QAA9BC,EAAiB,QAAjBC,EAAAH,EAAOI,gBAAU,IAAAD,OAAA,EAAAA,EAAAE,iBAAa,IAAAH,GAAAA,EAC7CI,EAAuD,QAAnCC,EAAiB,QAAjBC,EAAAR,EAAOI,gBAAU,IAAAI,OAAA,EAAAA,EAAAC,sBAAkB,IAAAF,GAAAA,EAKvDG,EAA8B,QAAfC,EAAAX,EAAOI,gBAAQ,IAAAO,OAAA,EAAAA,EAAED,aAChCE,EAAUC,IACdH,GAAgBA,EAAaI,SAASD,GAElCE,EAAiBC,EAAUC,OAAO,CACvCC,WAAUC,GAAmB,IAAlBC,eAAEA,GAAgBD,EAC5B,MAAO,CACN,IACAE,EAAgBD,EAAgB,CAC/BE,MAAO,+BAER,EAEF,IAoHD,MAAO,IAjHM,CAIZC,EAAWC,UAAU,CACpBC,MAAM,EACNC,WAAW,EACXC,WAAW1B,GAAuB,CAAE,EACpC2B,WAAW,EACXC,OAAMjB,EAAO,SAAU,CAAE,EACzBkB,SAAQlB,EAAO,WAAY,CAAE,EAC7BmB,SAAQnB,EAAO,WAAY,CAAE,EAC7BoB,OAAMpB,EAAO,SAAU,CAAE,IAE1BqB,EAAUC,OAAO,CAChBC,KAAM,sBACNC,qBAAoBA,KACZ,CACN,cAAeC,IAAA,IAACC,OAAEA,GAAQD,EAAA,OAAKC,EAAOC,SAASC,YAAY,SAI1DvC,EAAe,CAACc,GAAkB,MAClCH,EAAO,aAAe,CAAC6B,GAAa,GAGxCC,EAAKzB,OAAO,CACX0B,cAAeA,IAAM,GACrBC,cAAeA,IAAM,KACnBpB,UAAU,CACZqB,aAAa,EACbC,UAAU,EACVC,aAAa,EACb3B,eAAgB,CACf4B,IAAK,sBACLC,MAAO,cAGTC,EACAC,EAAY3B,UAAU,CACrB4B,oBAAaC,EAAArD,EAAOoD,2BAAe,yBAKhCpD,EAAOsD,QACR,CAACC,EAAe/B,UAAU,CAAE8B,QAAStD,EAAOsD,WAC5C,GACHE,EAA4BhC,UAAU,CACrCiC,cAAexD,IAEhByD,EAAsBlC,UAAU,CAC/BmC,OAAQ3D,EAAO2D,OACfC,aAAc5D,EAAO4D,aACrBC,uBAAgBC,EAAA9D,EAAO+D,yBAAa,KAErCC,KACIhE,EAAOiE,cACR,CAACC,EAAe1C,UAAU,CAAE2C,MAAOnE,EAAOiE,iBAC1C,GAKHG,MAGyB,aACrBC,EAAArE,EAAOsE,+BAAUC,QAClB,CACAC,EACCxE,EAAOsE,SAASC,OAChBvE,EAAOyE,kBACPzE,EAAO0E,kBACP1E,EAAO2E,wBAGR,eACCC,EAAA5E,EAAOsE,+BAAUO,OAClB,CACAC,EACC9E,EAAOsE,SAASO,MAChB7E,EAAOyE,kBACPzE,EAAO0E,kBACP1E,EAAO2E,wBAGR,MACC3E,EAAO+E,cACR,CACAC,EACChF,EAAO+E,cACP/E,EAAOiF,uBACPjF,EAAOkF,uBACPlF,EAAOmF,6BAGR,OAGmB7E,EACpB,CACA8E,EACAC,EAAU7D,UAAU,CAAE8D,YAAY,IAClCC,EACAC,EACAC,EAAUjE,UAAU,CAAEkE,MAAO,CAAC,UAAW,eACzCC,EACAC,EACAC,GAEA,CAACT,GAGL"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Extension as t}from"../../../node_modules/@tiptap/core/dist/index.js";import{Slice as e}from"@tiptap/pm/model";import{Plugin as r}from"@tiptap/pm/state";import{Decoration as a,DecorationSet as n}from"@tiptap/pm/view";import{parseClipboardText as o,wrapInlineContent as s,cleanBlockBrs as i,stripTrailingBrs as p,normalizeHardBreaks as d,stripRichMarks as c}from"./pasteUtils.js";const l=t.create({name:"pasteNormalization",addOptions:()=>({preserveMarks:!1}),addProseMirrorPlugins(){const t=this.options.preserveMarks;return[new r({props:{decorations(t){const e=[];return t.doc.descendants(((t,r)=>{"paragraph"===t.type.name&&0===t.childCount&&e.push(a.node(r,r+t.nodeSize,{class:"is-blank"}))})),n.create(t.doc,e)},handlePaste(t,e){var r,a;const n=null===(r=e.clipboardData)||void 0===r?void 0:r.getData("text/html");if(null==n?void 0:n.includes("data-pm-slice"))return!1;const s=null===(a=e.clipboardData)||void 0===a?void 0:a.getData("text/plain");if(!s)return!1;const i=o(s,t.state.schema);return t.dispatch(t.state.tr.replaceSelection(i)),!0},clipboardTextParser:(t,e,r,a)=>o(t,a.state.schema),transformPastedHTML(t){if(t.includes("data-pm-slice"))return t;const e=document.createElement("div");return e.innerHTML=t,s(e),i(e),p(e),e.innerHTML},transformPasted(r){let a=d(r.content);return t||(a=c(a)),new e(a,r.openStart,r.openEnd)}}})]}});export{l as PasteNormalizationExtension};
|
|
2
|
+
//# sourceMappingURL=PasteNormalizationExtension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PasteNormalizationExtension.js","sources":["../../../../../src/editor/extensions/plainClipboard/PasteNormalizationExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport { Slice } from '@tiptap/pm/model';\nimport { Plugin } from '@tiptap/pm/state';\nimport { Decoration, DecorationSet } from '@tiptap/pm/view';\nimport {\n\tcleanBlockBrs,\n\tnormalizeHardBreaks,\n\tparseClipboardText,\n\tstripRichMarks,\n\tstripTrailingBrs,\n\twrapInlineContent,\n} from './pasteUtils';\n\n/**\n * Unified paste normalizer for all editor channels.\n *\n * Uses ProseMirror's recommended hooks instead of overriding handlePaste:\n * - clipboardTextParser: plain text → Slice (preserves blank lines)\n * - transformPastedHTML: HTML → HTML (cleans Google Docs / Word artifacts)\n * - transformPasted: Slice → Slice (normalizes hardBreaks, strips marks)\n *\n * Also decorates empty paragraphs with an `is-blank` CSS class so the\n * editor stylesheet can give blank lines precise height without extra margins.\n */\nexport const PasteNormalizationExtension = Extension.create({\n\tname: 'pasteNormalization',\n\taddOptions() {\n\t\treturn {\n\t\t\tpreserveMarks: false,\n\t\t};\n\t},\n\taddProseMirrorPlugins() {\n\t\tconst preserveMarks = this.options.preserveMarks;\n\t\treturn [\n\t\t\tnew Plugin({\n\t\t\t\tprops: {\n\t\t\t\t\tdecorations(state) {\n\t\t\t\t\t\tconst decorations: Decoration[] = [];\n\t\t\t\t\t\tstate.doc.descendants((node, pos) => {\n\t\t\t\t\t\t\tif (node.type.name === 'paragraph' && node.childCount === 0) {\n\t\t\t\t\t\t\t\tdecorations.push(\n\t\t\t\t\t\t\t\t\tDecoration.node(pos, pos + node.nodeSize, {\n\t\t\t\t\t\t\t\t\t\tclass: 'is-blank',\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn DecorationSet.create(state.doc, decorations);\n\t\t\t\t\t},\n\n\t\t\t\t\thandlePaste(view, event) {\n\t\t\t\t\t\tconst html = event.clipboardData?.getData('text/html');\n\t\t\t\t\t\tif (html?.includes('data-pm-slice')) return false;\n\t\t\t\t\t\tconst text = event.clipboardData?.getData('text/plain');\n\t\t\t\t\t\tif (!text) return false;\n\t\t\t\t\t\tconst slice = parseClipboardText(text, view.state.schema);\n\t\t\t\t\t\tview.dispatch(view.state.tr.replaceSelection(slice));\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t},\n\n\t\t\t\t\tclipboardTextParser(text, _$context, _plain, view) {\n\t\t\t\t\t\treturn parseClipboardText(text, view.state.schema);\n\t\t\t\t\t},\n\n\t\t\t\t\ttransformPastedHTML(html) {\n\t\t\t\t\t\tif (html.includes('data-pm-slice')) return html;\n\t\t\t\t\t\tconst container = document.createElement('div');\n\t\t\t\t\t\tcontainer.innerHTML = html;\n\t\t\t\t\t\twrapInlineContent(container);\n\t\t\t\t\t\tcleanBlockBrs(container);\n\t\t\t\t\t\tstripTrailingBrs(container);\n\t\t\t\t\t\treturn container.innerHTML;\n\t\t\t\t\t},\n\n\t\t\t\t\ttransformPasted(slice) {\n\t\t\t\t\t\tlet content = normalizeHardBreaks(slice.content);\n\t\t\t\t\t\tif (!preserveMarks) {\n\t\t\t\t\t\t\tcontent = stripRichMarks(content);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn new Slice(content, slice.openStart, slice.openEnd);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t];\n\t},\n});\n"],"names":["PasteNormalizationExtension","Extension","create","name","addOptions","preserveMarks","addProseMirrorPlugins","this","options","Plugin","props","decorations","state","doc","descendants","node","pos","type","childCount","push","Decoration","nodeSize","class","DecorationSet","handlePaste","view","event","html","_a","clipboardData","getData","includes","text","_b","slice","parseClipboardText","schema","dispatch","tr","replaceSelection","clipboardTextParser","_$context","_plain","transformPastedHTML","container","document","createElement","innerHTML","wrapInlineContent","cleanBlockBrs","stripTrailingBrs","transformPasted","content","normalizeHardBreaks","stripRichMarks","Slice","openStart","openEnd"],"mappings":"wYAwBaA,EAA8BC,EAAUC,OAAO,CAC3DC,KAAM,qBACNC,WAAUA,KACF,CACNC,eAAe,IAGjBC,wBACC,MAAMD,EAAgBE,KAAKC,QAAQH,cACnC,MAAO,CACN,IAAII,EAAO,CACVC,MAAO,CACNC,YAAYC,GACX,MAAMD,EAA4B,GAUlC,OATAC,EAAMC,IAAIC,aAAY,CAACC,EAAMC,KACL,cAAnBD,EAAKE,KAAKd,MAA4C,IAApBY,EAAKG,YAC1CP,EAAYQ,KACXC,EAAWL,KAAKC,EAAKA,EAAMD,EAAKM,SAAU,CACzCC,MAAO,aAGT,IAEKC,EAAcrB,OAAOU,EAAMC,IAAKF,EACvC,EAEDa,YAAYC,EAAMC,WACjB,MAAMC,EAA0B,QAAnBC,EAAAF,EAAMG,qBAAa,IAAAD,OAAA,EAAAA,EAAEE,QAAQ,aAC1C,GAAIH,aAAI,EAAJA,EAAMI,SAAS,iBAAkB,OAAO,EAC5C,MAAMC,EAA0B,QAAnBC,EAAAP,EAAMG,qBAAa,IAAAI,OAAA,EAAAA,EAAEH,QAAQ,cAC1C,IAAKE,EAAM,OAAO,EAClB,MAAME,EAAQC,EAAmBH,EAAMP,EAAKb,MAAMwB,QAElD,OADAX,EAAKY,SAASZ,EAAKb,MAAM0B,GAAGC,iBAAiBL,KACtC,CACP,EAEDM,oBAAmBA,CAACR,EAAMS,EAAWC,EAAQjB,IACrCU,EAAmBH,EAAMP,EAAKb,MAAMwB,QAG5CO,oBAAoBhB,GACnB,GAAIA,EAAKI,SAAS,iBAAkB,OAAOJ,EAC3C,MAAMiB,EAAYC,SAASC,cAAc,OAKzC,OAJAF,EAAUG,UAAYpB,EACtBqB,EAAkBJ,GAClBK,EAAcL,GACdM,EAAiBN,GACVA,EAAUG,SACjB,EAEDI,gBAAgBjB,GACf,IAAIkB,EAAUC,EAAoBnB,EAAMkB,SAIxC,OAHK/C,IACJ+C,EAAUE,EAAeF,IAEnB,IAAIG,EAAMH,EAASlB,EAAMsB,UAAWtB,EAAMuB,QAClD,KAIJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Fragment as e}from"@tiptap/pm/model";const
|
|
1
|
+
import{Fragment as e,Slice as t}from"@tiptap/pm/model";const o=new Set(["P","LI","H1","H2","H3","H4","H5","H6","TD","TH","PRE"]),n="p,div,h1,h2,h3,h4,h5,h6,ul,ol,li,blockquote,table,pre",r=new Set(["bold","italic","strike","underline","code"]);function l(e){if(e.querySelector(n))return;const t=Array.from(e.childNodes),o=[[]];for(let e=0;e<t.length;e++){const n=t[e];n instanceof HTMLBRElement&&t[e+1]instanceof HTMLBRElement?(o.push([]),e++):o[o.length-1].push(n)}for(;e.firstChild;)e.firstChild.remove();for(const t of o){const o=document.createElement("p");for(const e of t)o.appendChild(e);e.appendChild(o)}}function a(e){const t=Array.from(e.querySelectorAll("br"));for(const n of t){let t=!1,r=n.parentElement;for(;r&&r!==e;){if(o.has(r.tagName)){t=!0;break}r=r.parentElement}t||n.parentElement.replaceChild(document.createElement("p"),n)}}function c(e){for(const t of["p","div"])for(const o of Array.from(e.querySelectorAll(t))){const e=o.lastElementChild;"BR"===(null==e?void 0:e.tagName)&&o.childNodes.length>1&&e.remove()}}function i(t){const o=[];return t.forEach((t=>{var n,r;if("paragraph"===t.type.name){if(1===t.childCount&&"hardBreak"===(null===(n=t.firstChild)||void 0===n?void 0:n.type.name))return void o.push(t.type.create(t.attrs));if(t.childCount>1&&"hardBreak"===(null===(r=t.lastChild)||void 0===r?void 0:r.type.name)){const n=[];return t.content.forEach(((e,o,r)=>{r<t.childCount-1&&n.push(e)})),void o.push(t.copy(e.from(n)))}}t.isBlock&&!t.isLeaf?o.push(t.copy(i(t.content))):o.push(t)})),e.from(o)}function s(t){const o=[];return t.forEach((e=>{if(e.isText){const t=e.marks.filter((e=>r.has(e.type.name)));o.push(t.length===e.marks.length?e:e.mark(t))}else o.push(e.copy(s(e.content)))})),e.from(o)}function f(o,n){const r=o.split("\n").map((e=>n.node("paragraph",null,e?[n.text(e)]:[])));return new t(e.fromArray(r),1,1)}export{n as BLOCK_SELECTOR,o as TEXTBLOCK_TAGS,a as cleanBlockBrs,i as normalizeHardBreaks,f as parseClipboardText,s as stripRichMarks,c as stripTrailingBrs,l as wrapInlineContent};
|
|
2
2
|
//# sourceMappingURL=pasteUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pasteUtils.js","sources":["../../../../../src/editor/extensions/plainClipboard/pasteUtils.ts"],"sourcesContent":["import { Fragment, Node as PMNode } from '@tiptap/pm/model';\n\nexport const TEXTBLOCK_TAGS = new Set([\n\t'P',\n\t'LI',\n\t'H1',\n\t'H2',\n\t'H3',\n\t'H4',\n\t'H5',\n\t'H6',\n\t'TD',\n\t'TH',\n\t'PRE',\n]);\n\nexport const BLOCK_SELECTOR =\n\t'p,div,h1,h2,h3,h4,h5,h6,ul,ol,li,blockquote,table,pre';\n\nconst BASIC_MARKS = new Set(['bold', 'italic', 'strike', 'underline', 'code']);\n\n/**\n * Replace `<br>` elements that sit at block level (not inside a textblock\n * like `<p>`, `<li>`, etc.) with empty `<p></p>` elements. Google Docs\n * puts standalone `<br>` tags between paragraphs to represent blank lines.\n
|
|
1
|
+
{"version":3,"file":"pasteUtils.js","sources":["../../../../../src/editor/extensions/plainClipboard/pasteUtils.ts"],"sourcesContent":["import { Fragment, Node as PMNode, Schema, Slice } from '@tiptap/pm/model';\n\nexport const TEXTBLOCK_TAGS = new Set([\n\t'P',\n\t'LI',\n\t'H1',\n\t'H2',\n\t'H3',\n\t'H4',\n\t'H5',\n\t'H6',\n\t'TD',\n\t'TH',\n\t'PRE',\n]);\n\nexport const BLOCK_SELECTOR =\n\t'p,div,h1,h2,h3,h4,h5,h6,ul,ol,li,blockquote,table,pre';\n\nconst BASIC_MARKS = new Set(['bold', 'italic', 'strike', 'underline', 'code']);\n\n/**\n * When pasted HTML is entirely inline (no block elements), split at\n * `<br><br>` boundaries into `<p>` elements. Single `<br>` stays as a\n * line break inside the paragraph.\n */\nexport function wrapInlineContent(container: HTMLElement): void {\n\tif (container.querySelector(BLOCK_SELECTOR)) return;\n\n\tconst children = Array.from(container.childNodes);\n\tconst groups: Node[][] = [[]];\n\n\tfor (let i = 0; i < children.length; i++) {\n\t\tconst node = children[i];\n\t\tif (\n\t\t\tnode instanceof HTMLBRElement &&\n\t\t\tchildren[i + 1] instanceof HTMLBRElement\n\t\t) {\n\t\t\tgroups.push([]);\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\t\tgroups[groups.length - 1].push(node);\n\t}\n\n\twhile (container.firstChild) container.firstChild.remove();\n\n\tfor (const group of groups) {\n\t\tconst p = document.createElement('p');\n\t\tfor (const node of group) p.appendChild(node);\n\t\tcontainer.appendChild(p);\n\t}\n}\n\n/**\n * Replace `<br>` elements that sit at block level (not inside a textblock\n * like `<p>`, `<li>`, etc.) with empty `<p></p>` elements. Google Docs\n * puts standalone `<br>` tags between paragraphs to represent blank lines.\n */\nexport function cleanBlockBrs(container: HTMLElement): void {\n\tconst brs = Array.from(container.querySelectorAll('br'));\n\tfor (const br of brs) {\n\t\tlet insideTextblock = false;\n\t\tlet el = br.parentElement;\n\t\twhile (el && el !== container) {\n\t\t\tif (TEXTBLOCK_TAGS.has(el.tagName)) {\n\t\t\t\tinsideTextblock = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tel = el.parentElement;\n\t\t}\n\t\tif (!insideTextblock) {\n\t\t\tbr.parentElement!.replaceChild(document.createElement('p'), br);\n\t\t}\n\t}\n}\n\n/**\n * Strip trailing `<br>` from content paragraphs in the DOM.\n * Google Docs adds a `<br>` at the end of non-empty paragraphs as a cursor\n * placeholder. Without this, ProseMirror creates a trailing hardBreak that\n * adds a visual blank line at the bottom of the paragraph.\n */\nexport function stripTrailingBrs(container: HTMLElement): void {\n\tfor (const tag of ['p', 'div']) {\n\t\tfor (const el of Array.from(container.querySelectorAll(tag))) {\n\t\t\tconst last = el.lastElementChild;\n\t\t\tif (last?.tagName === 'BR' && el.childNodes.length > 1) {\n\t\t\t\tlast.remove();\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Convert paragraphs containing only a hardBreak into truly empty paragraphs.\n * Google Docs represents blank lines as `<p><br></p>` — ProseMirror parses\n * the `<br>` as a hardBreak node, which renders double-height. Converting to\n * an empty paragraph (childCount 0) gives a single-height blank line.\n *\n * Does NOT collapse consecutive empties — that would destroy user intent.\n */\nexport function normalizeHardBreaks(fragment: Fragment): Fragment {\n\tconst nodes: PMNode[] = [];\n\tfragment.forEach((node) => {\n\t\tif (node.type.name === 'paragraph') {\n\t\t\tif (node.childCount === 1 && node.firstChild?.type.name === 'hardBreak') {\n\t\t\t\tnodes.push(node.type.create(node.attrs));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (node.childCount > 1 && node.lastChild?.type.name === 'hardBreak') {\n\t\t\t\tconst children: PMNode[] = [];\n\t\t\t\tnode.content.forEach((child, _offset, index) => {\n\t\t\t\t\tif (index < node.childCount - 1) children.push(child);\n\t\t\t\t});\n\t\t\t\tnodes.push(node.copy(Fragment.from(children)));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (node.isBlock && !node.isLeaf) {\n\t\t\tnodes.push(node.copy(normalizeHardBreaks(node.content)));\n\t\t} else {\n\t\t\tnodes.push(node);\n\t\t}\n\t});\n\treturn Fragment.from(nodes);\n}\n\n/**\n * Strip \"rich\" marks (link, textStyle, highlight, etc.) while keeping\n * basic marks (bold, italic, strike, underline, code) that messaging\n * channels can represent.\n */\nexport function stripRichMarks(fragment: Fragment): Fragment {\n\tconst nodes: PMNode[] = [];\n\tfragment.forEach((node) => {\n\t\tif (node.isText) {\n\t\t\tconst kept = node.marks.filter((m) => BASIC_MARKS.has(m.type.name));\n\t\t\tnodes.push(kept.length === node.marks.length ? node : node.mark(kept));\n\t\t} else {\n\t\t\tnodes.push(node.copy(stripRichMarks(node.content)));\n\t\t}\n\t});\n\treturn Fragment.from(nodes);\n}\n\n/**\n * Parse plain clipboard text into a ProseMirror Slice, preserving blank\n * lines as empty paragraphs. This replaces ProseMirror's default text\n * parser which uses `\\n+` and loses all blank lines.\n *\n * Best for channels with compact paragraph gaps (e.g. WhatsApp) where\n * blank lines need structural representation as empty paragraphs.\n */\nexport function parseClipboardText(text: string, schema: Schema): Slice {\n\tconst paragraphs = text\n\t\t.split('\\n')\n\t\t.map((line) =>\n\t\t\tschema.node('paragraph', null, line ? [schema.text(line)] : []),\n\t\t);\n\treturn new Slice(Fragment.fromArray(paragraphs), 1, 1);\n}\n\n/**\n * Parse plain clipboard text into a single paragraph with hardBreaks for\n * every `\\n`. Produces the same structure as Gmail's Cmd+Shift+V output:\n * one block element with `<br>` for line breaks and `<br><br>` for blank\n * lines. This gives identical html and text output to Gmail.\n */\nexport function parseClipboardTextAsBreaks(\n\ttext: string,\n\tschema: Schema,\n): Slice {\n\tconst trimmed = text.replace(/\\n+$/, '');\n\tif (!trimmed) {\n\t\treturn new Slice(Fragment.from(schema.node('paragraph', null, [])), 1, 1);\n\t}\n\tconst hardBreak = schema.nodes['hardBreak'];\n\tconst lines = trimmed.split('\\n');\n\tconst children: PMNode[] = [];\n\tlines.forEach((line, i) => {\n\t\tif (line) children.push(schema.text(line));\n\t\tif (i < lines.length - 1 && hardBreak) {\n\t\t\tchildren.push(hardBreak.create());\n\t\t}\n\t});\n\treturn new Slice(\n\t\tFragment.from(\n\t\t\tschema.node('paragraph', null, children.length ? children : []),\n\t\t),\n\t\t1,\n\t\t1,\n\t);\n}\n"],"names":["TEXTBLOCK_TAGS","Set","BLOCK_SELECTOR","BASIC_MARKS","wrapInlineContent","container","querySelector","children","Array","from","childNodes","groups","i","length","node","HTMLBRElement","push","firstChild","remove","group","p","document","createElement","appendChild","cleanBlockBrs","brs","querySelectorAll","br","insideTextblock","el","parentElement","has","tagName","replaceChild","stripTrailingBrs","tag","last","lastElementChild","normalizeHardBreaks","fragment","nodes","forEach","type","name","childCount","_a","create","attrs","_b","lastChild","content","child","_offset","index","copy","Fragment","isBlock","isLeaf","stripRichMarks","isText","kept","marks","filter","m","mark","parseClipboardText","text","schema","paragraphs","split","map","line","Slice","fromArray"],"mappings":"uDAEaA,MAAAA,EAAiB,IAAIC,IAAI,CACrC,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,QAGYC,EACZ,wDAEKC,EAAc,IAAIF,IAAI,CAAC,OAAQ,SAAU,SAAU,YAAa,SAOhE,SAAUG,EAAkBC,GACjC,GAAIA,EAAUC,cAAcJ,GAAiB,OAE7C,MAAMK,EAAWC,MAAMC,KAAKJ,EAAUK,YAChCC,EAAmB,CAAC,IAE1B,IAAK,IAAIC,EAAI,EAAGA,EAAIL,EAASM,OAAQD,IAAK,CACzC,MAAME,EAAOP,EAASK,GAErBE,aAAgBC,eAChBR,EAASK,EAAI,aAAcG,eAE3BJ,EAAOK,KAAK,IACZJ,KAGDD,EAAOA,EAAOE,OAAS,GAAGG,KAAKF,EAC/B,CAED,KAAOT,EAAUY,YAAYZ,EAAUY,WAAWC,SAElD,IAAK,MAAMC,KAASR,EAAQ,CAC3B,MAAMS,EAAIC,SAASC,cAAc,KACjC,IAAK,MAAMR,KAAQK,EAAOC,EAAEG,YAAYT,GACxCT,EAAUkB,YAAYH,EACtB,CACF,CAOM,SAAUI,EAAcnB,GAC7B,MAAMoB,EAAMjB,MAAMC,KAAKJ,EAAUqB,iBAAiB,OAClD,IAAK,MAAMC,KAAMF,EAAK,CACrB,IAAIG,GAAkB,EAClBC,EAAKF,EAAGG,cACZ,KAAOD,GAAMA,IAAOxB,GAAW,CAC9B,GAAIL,EAAe+B,IAAIF,EAAGG,SAAU,CACnCJ,GAAkB,EAClB,KACA,CACDC,EAAKA,EAAGC,aACR,CACIF,GACJD,EAAGG,cAAeG,aAAaZ,SAASC,cAAc,KAAMK,EAE7D,CACF,CAQM,SAAUO,EAAiB7B,GAChC,IAAK,MAAM8B,IAAO,CAAC,IAAK,OACvB,IAAK,MAAMN,KAAMrB,MAAMC,KAAKJ,EAAUqB,iBAAiBS,IAAO,CAC7D,MAAMC,EAAOP,EAAGQ,iBACM,QAAlBD,aAAA,EAAAA,EAAMJ,UAAoBH,EAAGnB,WAAWG,OAAS,GACpDuB,EAAKlB,QAEN,CAEH,CAUM,SAAUoB,EAAoBC,GACnC,MAAMC,EAAkB,GAsBxB,OArBAD,EAASE,SAAS3B,YACjB,GAAuB,cAAnBA,EAAK4B,KAAKC,KAAsB,CACnC,GAAwB,IAApB7B,EAAK8B,YAAmD,eAAd,QAAjBC,EAAA/B,EAAKG,kBAAY,IAAA4B,OAAA,EAAAA,EAAAH,KAAKC,MAElD,YADAH,EAAMxB,KAAKF,EAAK4B,KAAKI,OAAOhC,EAAKiC,QAGlC,GAAIjC,EAAK8B,WAAa,GAAmC,eAAd,QAAhBI,EAAAlC,EAAKmC,iBAAW,IAAAD,OAAA,EAAAA,EAAAN,KAAKC,MAAsB,CACrE,MAAMpC,EAAqB,GAK3B,OAJAO,EAAKoC,QAAQT,SAAQ,CAACU,EAAOC,EAASC,KACjCA,EAAQvC,EAAK8B,WAAa,GAAGrC,EAASS,KAAKmC,EAAM,SAEtDX,EAAMxB,KAAKF,EAAKwC,KAAKC,EAAS9C,KAAKF,IAEnC,CACD,CACGO,EAAK0C,UAAY1C,EAAK2C,OACzBjB,EAAMxB,KAAKF,EAAKwC,KAAKhB,EAAoBxB,EAAKoC,WAE9CV,EAAMxB,KAAKF,EACX,IAEKyC,EAAS9C,KAAK+B,EACtB,CAOM,SAAUkB,EAAenB,GAC9B,MAAMC,EAAkB,GASxB,OARAD,EAASE,SAAS3B,IACjB,GAAIA,EAAK6C,OAAQ,CAChB,MAAMC,EAAO9C,EAAK+C,MAAMC,QAAQC,GAAM5D,EAAY4B,IAAIgC,EAAErB,KAAKC,QAC7DH,EAAMxB,KAAK4C,EAAK/C,SAAWC,EAAK+C,MAAMhD,OAASC,EAAOA,EAAKkD,KAAKJ,GAChE,MACApB,EAAMxB,KAAKF,EAAKwC,KAAKI,EAAe5C,EAAKoC,UACzC,IAEKK,EAAS9C,KAAK+B,EACtB,CAUgB,SAAAyB,EAAmBC,EAAcC,GAChD,MAAMC,EAAaF,EACjBG,MAAM,MACNC,KAAKC,GACLJ,EAAOrD,KAAK,YAAa,KAAMyD,EAAO,CAACJ,EAAOD,KAAKK,IAAS,MAE9D,OAAO,IAAIC,EAAMjB,EAASkB,UAAUL,GAAa,EAAG,EACrD"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Node as e,mergeAttributes as t}from"../../core/dist/index.js";var r=" ",n=e.create({name:"paragraph",priority:1e3,addOptions:()=>({HTMLAttributes:{}}),group:"block",content:"inline*",parseHTML:()=>[{tag:"p"}],renderHTML({HTMLAttributes:e}){return["p",t(this.options.HTMLAttributes,e),0]},parseMarkdown:(e,t)=>{const n=e.tokens||[];if(1===n.length&&"image"===n[0].type)return t.parseChildren([n[0]]);const a=t.parseInline(n);return!(1===n.length&&"text"===n[0].type&&(n[0].raw===r||n[0].text===r||" "===n[0].raw||" "===n[0].text))||1!==a.length||"text"!==a[0].type||a[0].text!==r&&" "!==a[0].text?t.createNode("paragraph",void 0,a):t.createNode("paragraph",void 0,[])},renderMarkdown:(e,t,n)=>{var a,o;if(!e)return"";const d=Array.isArray(e.content)?e.content:[];if(0===d.length){const e=Array.isArray(null==(a=null==n?void 0:n.previousNode)?void 0:a.content)?n.previousNode.content:[];return"paragraph"===(null==(o=null==n?void 0:n.previousNode)?void 0:o.type)&&0===e.length?r:""}return t.renderChildren(d)},addCommands(){return{setParagraph:()=>({commands:e})=>e.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),a=n;export{n as Paragraph,a as default};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../node_modules/@tiptap/extension-paragraph/dist/index.js"],"sourcesContent":["// src/paragraph.ts\nimport { mergeAttributes, Node } from \"@tiptap/core\";\nvar EMPTY_PARAGRAPH_MARKDOWN = \" \";\nvar NBSP_CHAR = \"\\xA0\";\nvar Paragraph = Node.create({\n name: \"paragraph\",\n priority: 1e3,\n addOptions() {\n return {\n HTMLAttributes: {}\n };\n },\n group: \"block\",\n content: \"inline*\",\n parseHTML() {\n return [{ tag: \"p\" }];\n },\n renderHTML({ HTMLAttributes }) {\n return [\"p\", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];\n },\n parseMarkdown: (token, helpers) => {\n const tokens = token.tokens || [];\n if (tokens.length === 1 && tokens[0].type === \"image\") {\n return helpers.parseChildren([tokens[0]]);\n }\n const content = helpers.parseInline(tokens);\n const hasExplicitEmptyParagraphMarker = tokens.length === 1 && tokens[0].type === \"text\" && (tokens[0].raw === EMPTY_PARAGRAPH_MARKDOWN || tokens[0].text === EMPTY_PARAGRAPH_MARKDOWN || tokens[0].raw === NBSP_CHAR || tokens[0].text === NBSP_CHAR);\n if (hasExplicitEmptyParagraphMarker && content.length === 1 && content[0].type === \"text\" && (content[0].text === EMPTY_PARAGRAPH_MARKDOWN || content[0].text === NBSP_CHAR)) {\n return helpers.createNode(\"paragraph\", void 0, []);\n }\n return helpers.createNode(\"paragraph\", void 0, content);\n },\n renderMarkdown: (node, h, ctx) => {\n var _a, _b;\n if (!node) {\n return \"\";\n }\n const content = Array.isArray(node.content) ? node.content : [];\n if (content.length === 0) {\n const previousContent = Array.isArray((_a = ctx == null ? void 0 : ctx.previousNode) == null ? void 0 : _a.content) ? ctx.previousNode.content : [];\n const previousNodeIsEmptyParagraph = ((_b = ctx == null ? void 0 : ctx.previousNode) == null ? void 0 : _b.type) === \"paragraph\" && previousContent.length === 0;\n return previousNodeIsEmptyParagraph ? EMPTY_PARAGRAPH_MARKDOWN : \"\";\n }\n return h.renderChildren(content);\n },\n addCommands() {\n return {\n setParagraph: () => ({ commands }) => {\n return commands.setNode(this.name);\n }\n };\n },\n addKeyboardShortcuts() {\n return {\n \"Mod-Alt-0\": () => this.editor.commands.setParagraph()\n };\n }\n});\n\n// src/index.ts\nvar index_default = Paragraph;\nexport {\n Paragraph,\n index_default as default\n};\n//# sourceMappingURL=index.js.map"],"names":["EMPTY_PARAGRAPH_MARKDOWN","Paragraph","Node","create","name","priority","addOptions","HTMLAttributes","group","content","parseHTML","tag","renderHTML","mergeAttributes","this","options","parseMarkdown","token","helpers","tokens","length","type","parseChildren","parseInline","raw","text","createNode","renderMarkdown","node","h","ctx","_a","_b","Array","isArray","previousContent","previousNode","renderChildren","addCommands","setParagraph","commands","setNode","addKeyboardShortcuts","editor","index_default"],"mappings":"qEAEA,IAAIA,EAA2B,SAE3BC,EAAYC,EAAKC,OAAO,CAC1BC,KAAM,YACNC,SAAU,IACVC,WAAU,KACD,CACLC,eAAgB,CAAE,IAGtBC,MAAO,QACPC,QAAS,UACTC,UAAS,IACA,CAAC,CAAEC,IAAK,MAEjBC,YAAWL,eAAEA,IACX,MAAO,CAAC,IAAKM,EAAgBC,KAAKC,QAAQR,eAAgBA,GAAiB,EAC5E,EACDS,cAAe,CAACC,EAAOC,KACrB,MAAMC,EAASF,EAAME,QAAU,GAC/B,GAAsB,IAAlBA,EAAOC,QAAmC,UAAnBD,EAAO,GAAGE,KACnC,OAAOH,EAAQI,cAAc,CAACH,EAAO,KAEvC,MAAMV,EAAUS,EAAQK,YAAYJ,GAEpC,QAD0D,IAAlBA,EAAOC,QAAmC,SAAnBD,EAAO,GAAGE,OAAoBF,EAAO,GAAGK,MAAQxB,GAA4BmB,EAAO,GAAGM,OAASzB,GAvBlJ,MAuB8KmB,EAAO,GAAGK,KAvBxL,MAuB6ML,EAAO,GAAGM,QACzK,IAAnBhB,EAAQW,QAAoC,SAApBX,EAAQ,GAAGY,MAAoBZ,EAAQ,GAAGgB,OAASzB,GAxBtG,MAwBkIS,EAAQ,GAAGgB,KAGlJP,EAAQQ,WAAW,iBAAa,EAAQjB,GAFtCS,EAAQQ,WAAW,iBAAa,EAAQ,GAEM,EAEzDC,eAAgB,CAACC,EAAMC,EAAGC,KACxB,IAAIC,EAAIC,EACR,IAAKJ,EACH,MAAO,GAET,MAAMnB,EAAUwB,MAAMC,QAAQN,EAAKnB,SAAWmB,EAAKnB,QAAU,GAC7D,GAAuB,IAAnBA,EAAQW,OAAc,CACxB,MAAMe,EAAkBF,MAAMC,QAA0D,OAAjDH,EAAY,MAAPD,OAAc,EAASA,EAAIM,mBAAwB,EAASL,EAAGtB,SAAWqB,EAAIM,aAAa3B,QAAU,GAEjJ,MADqH,eAA7B,OAAjDuB,EAAY,MAAPF,OAAc,EAASA,EAAIM,mBAAwB,EAASJ,EAAGX,OAAoD,IAA3Bc,EAAgBf,OAC9GpB,EAA2B,EAClE,CACD,OAAO6B,EAAEQ,eAAe5B,EAAQ,EAElC6B,cACE,MAAO,CACLC,aAAc,IAAM,EAAGC,cACdA,EAASC,QAAQ3B,KAAKV,MAGlC,EACDsC,uBACE,MAAO,CACL,YAAa,IAAM5B,KAAK6B,OAAOH,SAASD,eAE3C,IAICK,EAAgB3C"}
|
|
@@ -728,4 +728,6 @@ export interface BikEditorProps {
|
|
|
728
728
|
minHeight?: string;
|
|
729
729
|
/** Maximum height. The editor scrolls internally when exceeded. CSS value, e.g. `'400px'`. */
|
|
730
730
|
maxHeight?: string;
|
|
731
|
+
/** Gap between consecutive paragraphs. CSS value, defaults to `'4px'`. */
|
|
732
|
+
paragraphGap?: string;
|
|
731
733
|
}
|
|
@@ -14,10 +14,14 @@ import { EditorSnapshot, FormatState } from './BikEditor.types';
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function normalizeHtml(html: string): string;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
17
|
+
* Make editor HTML portable across email clients and chat renderers.
|
|
18
|
+
*
|
|
19
|
+
* 1. Double a trailing `<br>` in content paragraphs so the blank line is
|
|
20
|
+
* visible. A single trailing `<br>` before `</p>` is swallowed by most
|
|
21
|
+
* email clients; `<br><br>` renders as a visible blank line (matches
|
|
22
|
+
* Gmail's output).
|
|
23
|
+
* 2. Convert empty `<p></p>` to `<p><br></p>` — email clients collapse
|
|
24
|
+
* zero-height paragraphs without a `<br>`.
|
|
21
25
|
*/
|
|
22
26
|
export declare function toPortableHtml(html: string): string;
|
|
23
27
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
1
2
|
import type { ReactNode } from 'react';
|
|
2
3
|
import type { EditorFeatures, EditorSnapshot, KeyboardShortcut, MentionDropdownRenderProps, MentionItem, PasteData, SlashCommandDropdownRenderProps, SlashCommandItem } from '../BikEditor.types';
|
|
3
4
|
interface ExtensionConfig {
|
|
@@ -33,5 +34,5 @@ interface ExtensionConfig {
|
|
|
33
34
|
renderSlashCommandItem?: (item: SlashCommandItem, isActive: boolean) => ReactNode;
|
|
34
35
|
renderSlashCommandDropdown?: (props: SlashCommandDropdownRenderProps) => ReactNode;
|
|
35
36
|
}
|
|
36
|
-
export declare function buildExtensions(config: ExtensionConfig): (import("@tiptap/core").Extension<import("@tiptap/starter-kit").StarterKitOptions, any> | import("@tiptap/core").Mark<import("@tiptap/extension-underline").UnderlineOptions, any> | import("@tiptap/core").Mark<import("@tiptap/extension-link").LinkOptions, any> | import("@tiptap/core").Mark<import("@tiptap/extension-text-style").TextStyleOptions, any> |
|
|
37
|
+
export declare function buildExtensions(config: ExtensionConfig): (import("@tiptap/core").Node<import("@tiptap/extension-paragraph").ParagraphOptions, any> | Extension<import("@tiptap/starter-kit").StarterKitOptions, any> | Extension<any, any> | import("@tiptap/core").Mark<import("@tiptap/extension-underline").UnderlineOptions, any> | import("@tiptap/core").Mark<import("@tiptap/extension-link").LinkOptions, any> | import("@tiptap/core").Mark<import("@tiptap/extension-text-style").TextStyleOptions, any> | Extension<import("@tiptap/extensions").PlaceholderOptions, any> | Extension<import("@tiptap/extensions").CharacterCountOptions, import("@tiptap/extensions").CharacterCountStorage> | import("@tiptap/core").Node<any, any> | import("@tiptap/core").Node<import("@tiptap/extension-mention").MentionOptions<any, import("@tiptap/extension-mention").MentionNodeAttrs>, any> | Extension<import("@tiptap/extension-text-style").ColorOptions, any> | import("@tiptap/core").Mark<import("@tiptap/extension-highlight").HighlightOptions, any> | Extension<import("@tiptap/extension-text-align").TextAlignOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-image").ImageOptions, any>)[];
|
|
37
38
|
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
/**
|
|
3
|
+
* Unified paste normalizer for all editor channels.
|
|
4
|
+
*
|
|
5
|
+
* Uses ProseMirror's recommended hooks instead of overriding handlePaste:
|
|
6
|
+
* - clipboardTextParser: plain text → Slice (preserves blank lines)
|
|
7
|
+
* - transformPastedHTML: HTML → HTML (cleans Google Docs / Word artifacts)
|
|
8
|
+
* - transformPasted: Slice → Slice (normalizes hardBreaks, strips marks)
|
|
9
|
+
*
|
|
10
|
+
* Also decorates empty paragraphs with an `is-blank` CSS class so the
|
|
11
|
+
* editor stylesheet can give blank lines precise height without extra margins.
|
|
12
|
+
*/
|
|
13
|
+
export declare const PasteNormalizationExtension: Extension<any, any>;
|
|
@@ -1,21 +1,53 @@
|
|
|
1
|
-
import { Fragment } from '@tiptap/pm/model';
|
|
1
|
+
import { Fragment, Schema, Slice } from '@tiptap/pm/model';
|
|
2
2
|
export declare const TEXTBLOCK_TAGS: Set<string>;
|
|
3
3
|
export declare const BLOCK_SELECTOR = "p,div,h1,h2,h3,h4,h5,h6,ul,ol,li,blockquote,table,pre";
|
|
4
|
+
/**
|
|
5
|
+
* When pasted HTML is entirely inline (no block elements), split at
|
|
6
|
+
* `<br><br>` boundaries into `<p>` elements. Single `<br>` stays as a
|
|
7
|
+
* line break inside the paragraph.
|
|
8
|
+
*/
|
|
9
|
+
export declare function wrapInlineContent(container: HTMLElement): void;
|
|
4
10
|
/**
|
|
5
11
|
* Replace `<br>` elements that sit at block level (not inside a textblock
|
|
6
12
|
* like `<p>`, `<li>`, etc.) with empty `<p></p>` elements. Google Docs
|
|
7
13
|
* puts standalone `<br>` tags between paragraphs to represent blank lines.
|
|
8
|
-
* Without this, ProseMirror parses them as top-level hardBreak nodes.
|
|
9
14
|
*/
|
|
10
15
|
export declare function cleanBlockBrs(container: HTMLElement): void;
|
|
11
16
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
17
|
+
* Strip trailing `<br>` from content paragraphs in the DOM.
|
|
18
|
+
* Google Docs adds a `<br>` at the end of non-empty paragraphs as a cursor
|
|
19
|
+
* placeholder. Without this, ProseMirror creates a trailing hardBreak that
|
|
20
|
+
* adds a visual blank line at the bottom of the paragraph.
|
|
21
|
+
*/
|
|
22
|
+
export declare function stripTrailingBrs(container: HTMLElement): void;
|
|
23
|
+
/**
|
|
24
|
+
* Convert paragraphs containing only a hardBreak into truly empty paragraphs.
|
|
25
|
+
* Google Docs represents blank lines as `<p><br></p>` — ProseMirror parses
|
|
26
|
+
* the `<br>` as a hardBreak node, which renders double-height. Converting to
|
|
27
|
+
* an empty paragraph (childCount 0) gives a single-height blank line.
|
|
28
|
+
*
|
|
29
|
+
* Does NOT collapse consecutive empties — that would destroy user intent.
|
|
14
30
|
*/
|
|
15
|
-
export declare function
|
|
31
|
+
export declare function normalizeHardBreaks(fragment: Fragment): Fragment;
|
|
16
32
|
/**
|
|
17
|
-
* Strip
|
|
18
|
-
* basic
|
|
19
|
-
*
|
|
33
|
+
* Strip "rich" marks (link, textStyle, highlight, etc.) while keeping
|
|
34
|
+
* basic marks (bold, italic, strike, underline, code) that messaging
|
|
35
|
+
* channels can represent.
|
|
20
36
|
*/
|
|
21
37
|
export declare function stripRichMarks(fragment: Fragment): Fragment;
|
|
38
|
+
/**
|
|
39
|
+
* Parse plain clipboard text into a ProseMirror Slice, preserving blank
|
|
40
|
+
* lines as empty paragraphs. This replaces ProseMirror's default text
|
|
41
|
+
* parser which uses `\n+` and loses all blank lines.
|
|
42
|
+
*
|
|
43
|
+
* Best for channels with compact paragraph gaps (e.g. WhatsApp) where
|
|
44
|
+
* blank lines need structural representation as empty paragraphs.
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseClipboardText(text: string, schema: Schema): Slice;
|
|
47
|
+
/**
|
|
48
|
+
* Parse plain clipboard text into a single paragraph with hardBreaks for
|
|
49
|
+
* every `\n`. Produces the same structure as Gmail's Cmd+Shift+V output:
|
|
50
|
+
* one block element with `<br>` for line breaks and `<br><br>` for blank
|
|
51
|
+
* lines. This gives identical html and text output to Gmail.
|
|
52
|
+
*/
|
|
53
|
+
export declare function parseClipboardTextAsBreaks(text: string, schema: Schema): Slice;
|
package/package.json
CHANGED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../node_modules/@tiptap/core/dist/index.js"),t=require("@tiptap/pm/model"),r=require("@tiptap/pm/state"),i=require("./pasteUtils.js");const a=e.Extension.create({name:"clipboardNormalization",addProseMirrorPlugins:()=>[new r.Plugin({props:{handlePaste(e,r){var a,n,o;if(null===(n=null===(a=r.clipboardData)||void 0===a?void 0:a.files)||void 0===n?void 0:n.length)return!1;const l=null===(o=r.clipboardData)||void 0===o?void 0:o.getData("text/html");if(!l)return!1;if(l.includes("data-pm-slice"))return!1;const s=document.createElement("div");if(s.innerHTML=l,!s.querySelector(i.BLOCK_SELECTOR))return!1;i.cleanBlockBrs(s);const c=e.state.schema,d=t.DOMParser.fromSchema(c).parseSlice(s),p=i.normalizeBlanks(d.content),u=new t.Slice(p,d.openStart,d.openEnd);return e.dispatch(e.state.tr.replaceSelection(u)),!0}}})]});exports.ClipboardNormalizationExtension=a;
|
|
2
|
-
//# sourceMappingURL=ClipboardNormalizationExtension.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ClipboardNormalizationExtension.js","sources":["../../../../../src/editor/extensions/plainClipboard/ClipboardNormalizationExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport { DOMParser as ProseMirrorDOMParser, Slice } from '@tiptap/pm/model';\nimport { Plugin } from '@tiptap/pm/state';\nimport { BLOCK_SELECTOR, cleanBlockBrs, normalizeBlanks } from './pasteUtils';\n\n/**\n * Lightweight paste normalizer for rich-paste editors (email).\n * Fixes Google Docs' standalone `<br>` between paragraphs and collapses\n * consecutive empty paragraphs — but keeps ALL formatting marks intact.\n */\nexport const ClipboardNormalizationExtension = Extension.create({\n\tname: 'clipboardNormalization',\n\taddProseMirrorPlugins() {\n\t\treturn [\n\t\t\tnew Plugin({\n\t\t\t\tprops: {\n\t\t\t\t\thandlePaste(_view, event) {\n\t\t\t\t\t\tif (event.clipboardData?.files?.length) return false;\n\t\t\t\t\t\tconst html = event.clipboardData?.getData('text/html');\n\t\t\t\t\t\tif (!html) return false;\n\t\t\t\t\t\tif (html.includes('data-pm-slice')) return false;\n\n\t\t\t\t\t\tconst container = document.createElement('div');\n\t\t\t\t\t\tcontainer.innerHTML = html;\n\t\t\t\t\t\tif (!container.querySelector(BLOCK_SELECTOR)) return false;\n\n\t\t\t\t\t\tcleanBlockBrs(container);\n\t\t\t\t\t\tconst schema = _view.state.schema;\n\t\t\t\t\t\tconst parsed =\n\t\t\t\t\t\t\tProseMirrorDOMParser.fromSchema(schema).parseSlice(container);\n\t\t\t\t\t\tconst cleaned = normalizeBlanks(parsed.content);\n\t\t\t\t\t\tconst slice = new Slice(cleaned, parsed.openStart, parsed.openEnd);\n\t\t\t\t\t\t_view.dispatch(_view.state.tr.replaceSelection(slice));\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t];\n\t},\n});\n"],"names":["ClipboardNormalizationExtension","Extension","create","name","addProseMirrorPlugins","Plugin","props","handlePaste","_view","event","_b","clipboardData","_a","files","length","html","_c","getData","includes","container","document","createElement","innerHTML","querySelector","BLOCK_SELECTOR","cleanBlockBrs","schema","state","parsed","ProseMirrorDOMParser","fromSchema","parseSlice","cleaned","normalizeBlanks","content","slice","Slice","openStart","openEnd","dispatch","tr","replaceSelection"],"mappings":"qOAUaA,EAAkCC,EAASA,UAACC,OAAO,CAC/DC,KAAM,yBACNC,sBAAqBA,IACb,CACN,IAAIC,EAAAA,OAAO,CACVC,MAAO,CACNC,YAAYC,EAAOC,aAClB,WAAIC,EAAqB,UAArBD,EAAME,qBAAe,IAAAC,OAAA,EAAAA,EAAAC,4BAAOC,OAAQ,OAAO,EAC/C,MAAMC,EAA0B,QAAnBC,EAAAP,EAAME,qBAAa,IAAAK,OAAA,EAAAA,EAAEC,QAAQ,aAC1C,IAAKF,EAAM,OAAO,EAClB,GAAIA,EAAKG,SAAS,iBAAkB,OAAO,EAE3C,MAAMC,EAAYC,SAASC,cAAc,OAEzC,GADAF,EAAUG,UAAYP,GACjBI,EAAUI,cAAcC,EAAAA,gBAAiB,OAAO,EAErDC,EAAaA,cAACN,GACd,MAAMO,EAASlB,EAAMmB,MAAMD,OACrBE,EACLC,EAAAA,UAAqBC,WAAWJ,GAAQK,WAAWZ,GAC9Ca,EAAUC,EAAAA,gBAAgBL,EAAOM,SACjCC,EAAQ,IAAIC,EAAAA,MAAMJ,EAASJ,EAAOS,UAAWT,EAAOU,SAE1D,OADA9B,EAAM+B,SAAS/B,EAAMmB,MAAMa,GAAGC,iBAAiBN,KACxC,CACR"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../node_modules/@tiptap/core/dist/index.js"),t=require("@tiptap/pm/model"),r=require("@tiptap/pm/state"),a=require("./pasteUtils.js");const i=e.Extension.create({name:"plainClipboard",addProseMirrorPlugins:()=>[new r.Plugin({props:{handlePaste(e,r){var i,n,l,o;if(null===(n=null===(i=r.clipboardData)||void 0===i?void 0:i.files)||void 0===n?void 0:n.length)return!1;const s=null===(l=r.clipboardData)||void 0===l?void 0:l.getData("text/html"),p=null===(o=r.clipboardData)||void 0===o?void 0:o.getData("text/plain");if(!p)return!1;if(null==s?void 0:s.includes("data-pm-slice"))return!1;const c=e.state.schema;if(s){const r=document.createElement("div");r.innerHTML=s;if(r.querySelector(a.BLOCK_SELECTOR)){a.cleanBlockBrs(r);const i=t.DOMParser.fromSchema(c).parseSlice(r),n=a.normalizeBlanks(a.stripRichMarks(i.content)),l=new t.Slice(n,i.openStart,i.openEnd);return e.dispatch(e.state.tr.replaceSelection(l)),!0}}const d=p.split("\n").map((e=>c.node("paragraph",null,e?[c.text(e)]:[]))),u=new t.Slice(t.Fragment.fromArray(d),1,1);return e.dispatch(e.state.tr.replaceSelection(u)),!0}}})]});exports.PlainClipboardExtension=i;
|
|
2
|
-
//# sourceMappingURL=PlainClipboardExtension.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlainClipboardExtension.js","sources":["../../../../../src/editor/extensions/plainClipboard/PlainClipboardExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport {\n\tFragment,\n\tDOMParser as ProseMirrorDOMParser,\n\tSlice,\n} from '@tiptap/pm/model';\nimport { Plugin } from '@tiptap/pm/state';\nimport {\n\tBLOCK_SELECTOR,\n\tcleanBlockBrs,\n\tnormalizeBlanks,\n\tstripRichMarks,\n} from './pasteUtils';\n\nexport const PlainClipboardExtension = Extension.create({\n\tname: 'plainClipboard',\n\taddProseMirrorPlugins() {\n\t\treturn [\n\t\t\tnew Plugin({\n\t\t\t\tprops: {\n\t\t\t\t\thandlePaste(_view, event) {\n\t\t\t\t\t\tif (event.clipboardData?.files?.length) return false;\n\t\t\t\t\t\tconst html = event.clipboardData?.getData('text/html');\n\t\t\t\t\t\tconst text = event.clipboardData?.getData('text/plain');\n\t\t\t\t\t\tif (!text) return false;\n\n\t\t\t\t\t\tif (html?.includes('data-pm-slice')) return false;\n\n\t\t\t\t\t\tconst schema = _view.state.schema;\n\n\t\t\t\t\t\tif (html) {\n\t\t\t\t\t\t\tconst container = document.createElement('div');\n\t\t\t\t\t\t\tcontainer.innerHTML = html;\n\t\t\t\t\t\t\tconst hasBlocks = container.querySelector(BLOCK_SELECTOR);\n\t\t\t\t\t\t\tif (hasBlocks) {\n\t\t\t\t\t\t\t\tcleanBlockBrs(container);\n\t\t\t\t\t\t\t\tconst parsed =\n\t\t\t\t\t\t\t\t\tProseMirrorDOMParser.fromSchema(schema).parseSlice(container);\n\t\t\t\t\t\t\t\tconst cleaned = normalizeBlanks(stripRichMarks(parsed.content));\n\t\t\t\t\t\t\t\tconst slice = new Slice(\n\t\t\t\t\t\t\t\t\tcleaned,\n\t\t\t\t\t\t\t\t\tparsed.openStart,\n\t\t\t\t\t\t\t\t\tparsed.openEnd,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t_view.dispatch(_view.state.tr.replaceSelection(slice));\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst paragraphs = text\n\t\t\t\t\t\t\t.split('\\n')\n\t\t\t\t\t\t\t.map((line) =>\n\t\t\t\t\t\t\t\tschema.node('paragraph', null, line ? [schema.text(line)] : []),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\tconst slice = new Slice(Fragment.fromArray(paragraphs), 1, 1);\n\t\t\t\t\t\t_view.dispatch(_view.state.tr.replaceSelection(slice));\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t];\n\t},\n});\n"],"names":["PlainClipboardExtension","Extension","create","name","addProseMirrorPlugins","Plugin","props","handlePaste","_view","event","_b","clipboardData","_a","files","length","html","_c","getData","text","_d","includes","schema","state","container","document","createElement","innerHTML","querySelector","BLOCK_SELECTOR","cleanBlockBrs","parsed","ProseMirrorDOMParser","fromSchema","parseSlice","cleaned","normalizeBlanks","stripRichMarks","content","slice","Slice","openStart","openEnd","dispatch","tr","replaceSelection","paragraphs","split","map","line","node","Fragment","fromArray"],"mappings":"qOAcaA,EAA0BC,EAASA,UAACC,OAAO,CACvDC,KAAM,iBACNC,sBAAqBA,IACb,CACN,IAAIC,EAAAA,OAAO,CACVC,MAAO,CACNC,YAAYC,EAAOC,eAClB,WAAIC,EAAqB,UAArBD,EAAME,qBAAe,IAAAC,OAAA,EAAAA,EAAAC,4BAAOC,OAAQ,OAAO,EAC/C,MAAMC,EAA0B,QAAnBC,EAAAP,EAAME,qBAAa,IAAAK,OAAA,EAAAA,EAAEC,QAAQ,aACpCC,EAA0B,QAAnBC,EAAAV,EAAME,qBAAa,IAAAQ,OAAA,EAAAA,EAAEF,QAAQ,cAC1C,IAAKC,EAAM,OAAO,EAElB,GAAIH,aAAI,EAAJA,EAAMK,SAAS,iBAAkB,OAAO,EAE5C,MAAMC,EAASb,EAAMc,MAAMD,OAE3B,GAAIN,EAAM,CACT,MAAMQ,EAAYC,SAASC,cAAc,OACzCF,EAAUG,UAAYX,EAEtB,GADkBQ,EAAUI,cAAcC,EAAcA,gBACzC,CACdC,EAAaA,cAACN,GACd,MAAMO,EACLC,EAAAA,UAAqBC,WAAWX,GAAQY,WAAWV,GAC9CW,EAAUC,EAAAA,gBAAgBC,EAAAA,eAAeN,EAAOO,UAChDC,EAAQ,IAAIC,EAAAA,MACjBL,EACAJ,EAAOU,UACPV,EAAOW,SAGR,OADAjC,EAAMkC,SAASlC,EAAMc,MAAMqB,GAAGC,iBAAiBN,KACxC,CACP,CACD,CAED,MAAMO,EAAa3B,EACjB4B,MAAM,MACNC,KAAKC,GACL3B,EAAO4B,KAAK,YAAa,KAAMD,EAAO,CAAC3B,EAAOH,KAAK8B,IAAS,MAExDV,EAAQ,IAAIC,EAAAA,MAAMW,EAAQA,SAACC,UAAUN,GAAa,EAAG,GAE3D,OADArC,EAAMkC,SAASlC,EAAMc,MAAMqB,GAAGC,iBAAiBN,KACxC,CACR"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Extension } from '@tiptap/core';
|
|
2
|
-
/**
|
|
3
|
-
* Lightweight paste normalizer for rich-paste editors (email).
|
|
4
|
-
* Fixes Google Docs' standalone `<br>` between paragraphs and collapses
|
|
5
|
-
* consecutive empty paragraphs — but keeps ALL formatting marks intact.
|
|
6
|
-
*/
|
|
7
|
-
export declare const ClipboardNormalizationExtension: Extension<any, any>;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{Extension as t}from"../../../node_modules/@tiptap/core/dist/index.js";import{DOMParser as e,Slice as r}from"@tiptap/pm/model";import{Plugin as o}from"@tiptap/pm/state";import{BLOCK_SELECTOR as i,cleanBlockBrs as a,normalizeBlanks as n}from"./pasteUtils.js";const l=t.create({name:"clipboardNormalization",addProseMirrorPlugins:()=>[new o({props:{handlePaste(t,o){var l,p,d;if(null===(p=null===(l=o.clipboardData)||void 0===l?void 0:l.files)||void 0===p?void 0:p.length)return!1;const s=null===(d=o.clipboardData)||void 0===d?void 0:d.getData("text/html");if(!s)return!1;if(s.includes("data-pm-slice"))return!1;const c=document.createElement("div");if(c.innerHTML=s,!c.querySelector(i))return!1;a(c);const m=t.state.schema,u=e.fromSchema(m).parseSlice(c),f=n(u.content),v=new r(f,u.openStart,u.openEnd);return t.dispatch(t.state.tr.replaceSelection(v)),!0}}})]});export{l as ClipboardNormalizationExtension};
|
|
2
|
-
//# sourceMappingURL=ClipboardNormalizationExtension.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ClipboardNormalizationExtension.js","sources":["../../../../../src/editor/extensions/plainClipboard/ClipboardNormalizationExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport { DOMParser as ProseMirrorDOMParser, Slice } from '@tiptap/pm/model';\nimport { Plugin } from '@tiptap/pm/state';\nimport { BLOCK_SELECTOR, cleanBlockBrs, normalizeBlanks } from './pasteUtils';\n\n/**\n * Lightweight paste normalizer for rich-paste editors (email).\n * Fixes Google Docs' standalone `<br>` between paragraphs and collapses\n * consecutive empty paragraphs — but keeps ALL formatting marks intact.\n */\nexport const ClipboardNormalizationExtension = Extension.create({\n\tname: 'clipboardNormalization',\n\taddProseMirrorPlugins() {\n\t\treturn [\n\t\t\tnew Plugin({\n\t\t\t\tprops: {\n\t\t\t\t\thandlePaste(_view, event) {\n\t\t\t\t\t\tif (event.clipboardData?.files?.length) return false;\n\t\t\t\t\t\tconst html = event.clipboardData?.getData('text/html');\n\t\t\t\t\t\tif (!html) return false;\n\t\t\t\t\t\tif (html.includes('data-pm-slice')) return false;\n\n\t\t\t\t\t\tconst container = document.createElement('div');\n\t\t\t\t\t\tcontainer.innerHTML = html;\n\t\t\t\t\t\tif (!container.querySelector(BLOCK_SELECTOR)) return false;\n\n\t\t\t\t\t\tcleanBlockBrs(container);\n\t\t\t\t\t\tconst schema = _view.state.schema;\n\t\t\t\t\t\tconst parsed =\n\t\t\t\t\t\t\tProseMirrorDOMParser.fromSchema(schema).parseSlice(container);\n\t\t\t\t\t\tconst cleaned = normalizeBlanks(parsed.content);\n\t\t\t\t\t\tconst slice = new Slice(cleaned, parsed.openStart, parsed.openEnd);\n\t\t\t\t\t\t_view.dispatch(_view.state.tr.replaceSelection(slice));\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t];\n\t},\n});\n"],"names":["ClipboardNormalizationExtension","Extension","create","name","addProseMirrorPlugins","Plugin","props","handlePaste","_view","event","_b","clipboardData","_a","files","length","html","_c","getData","includes","container","document","createElement","innerHTML","querySelector","BLOCK_SELECTOR","cleanBlockBrs","schema","state","parsed","ProseMirrorDOMParser","fromSchema","parseSlice","cleaned","normalizeBlanks","content","slice","Slice","openStart","openEnd","dispatch","tr","replaceSelection"],"mappings":"8QAUaA,EAAkCC,EAAUC,OAAO,CAC/DC,KAAM,yBACNC,sBAAqBA,IACb,CACN,IAAIC,EAAO,CACVC,MAAO,CACNC,YAAYC,EAAOC,aAClB,WAAIC,EAAqB,UAArBD,EAAME,qBAAe,IAAAC,OAAA,EAAAA,EAAAC,4BAAOC,OAAQ,OAAO,EAC/C,MAAMC,EAA0B,QAAnBC,EAAAP,EAAME,qBAAa,IAAAK,OAAA,EAAAA,EAAEC,QAAQ,aAC1C,IAAKF,EAAM,OAAO,EAClB,GAAIA,EAAKG,SAAS,iBAAkB,OAAO,EAE3C,MAAMC,EAAYC,SAASC,cAAc,OAEzC,GADAF,EAAUG,UAAYP,GACjBI,EAAUI,cAAcC,GAAiB,OAAO,EAErDC,EAAcN,GACd,MAAMO,EAASlB,EAAMmB,MAAMD,OACrBE,EACLC,EAAqBC,WAAWJ,GAAQK,WAAWZ,GAC9Ca,EAAUC,EAAgBL,EAAOM,SACjCC,EAAQ,IAAIC,EAAMJ,EAASJ,EAAOS,UAAWT,EAAOU,SAE1D,OADA9B,EAAM+B,SAAS/B,EAAMmB,MAAMa,GAAGC,iBAAiBN,KACxC,CACR"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{Extension as t}from"../../../node_modules/@tiptap/core/dist/index.js";import{DOMParser as e,Slice as r,Fragment as a}from"@tiptap/pm/model";import{Plugin as o}from"@tiptap/pm/state";import{BLOCK_SELECTOR as i,cleanBlockBrs as n,normalizeBlanks as l,stripRichMarks as p}from"./pasteUtils.js";const d=t.create({name:"plainClipboard",addProseMirrorPlugins:()=>[new o({props:{handlePaste(t,o){var d,s,c,m;if(null===(s=null===(d=o.clipboardData)||void 0===d?void 0:d.files)||void 0===s?void 0:s.length)return!1;const u=null===(c=o.clipboardData)||void 0===c?void 0:c.getData("text/html"),f=null===(m=o.clipboardData)||void 0===m?void 0:m.getData("text/plain");if(!f)return!1;if(null==u?void 0:u.includes("data-pm-slice"))return!1;const v=t.state.schema;if(u){const a=document.createElement("div");a.innerHTML=u;if(a.querySelector(i)){n(a);const o=e.fromSchema(v).parseSlice(a),i=l(p(o.content)),d=new r(i,o.openStart,o.openEnd);return t.dispatch(t.state.tr.replaceSelection(d)),!0}}const h=f.split("\n").map((t=>v.node("paragraph",null,t?[v.text(t)]:[]))),S=new r(a.fromArray(h),1,1);return t.dispatch(t.state.tr.replaceSelection(S)),!0}}})]});export{d as PlainClipboardExtension};
|
|
2
|
-
//# sourceMappingURL=PlainClipboardExtension.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlainClipboardExtension.js","sources":["../../../../../src/editor/extensions/plainClipboard/PlainClipboardExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport {\n\tFragment,\n\tDOMParser as ProseMirrorDOMParser,\n\tSlice,\n} from '@tiptap/pm/model';\nimport { Plugin } from '@tiptap/pm/state';\nimport {\n\tBLOCK_SELECTOR,\n\tcleanBlockBrs,\n\tnormalizeBlanks,\n\tstripRichMarks,\n} from './pasteUtils';\n\nexport const PlainClipboardExtension = Extension.create({\n\tname: 'plainClipboard',\n\taddProseMirrorPlugins() {\n\t\treturn [\n\t\t\tnew Plugin({\n\t\t\t\tprops: {\n\t\t\t\t\thandlePaste(_view, event) {\n\t\t\t\t\t\tif (event.clipboardData?.files?.length) return false;\n\t\t\t\t\t\tconst html = event.clipboardData?.getData('text/html');\n\t\t\t\t\t\tconst text = event.clipboardData?.getData('text/plain');\n\t\t\t\t\t\tif (!text) return false;\n\n\t\t\t\t\t\tif (html?.includes('data-pm-slice')) return false;\n\n\t\t\t\t\t\tconst schema = _view.state.schema;\n\n\t\t\t\t\t\tif (html) {\n\t\t\t\t\t\t\tconst container = document.createElement('div');\n\t\t\t\t\t\t\tcontainer.innerHTML = html;\n\t\t\t\t\t\t\tconst hasBlocks = container.querySelector(BLOCK_SELECTOR);\n\t\t\t\t\t\t\tif (hasBlocks) {\n\t\t\t\t\t\t\t\tcleanBlockBrs(container);\n\t\t\t\t\t\t\t\tconst parsed =\n\t\t\t\t\t\t\t\t\tProseMirrorDOMParser.fromSchema(schema).parseSlice(container);\n\t\t\t\t\t\t\t\tconst cleaned = normalizeBlanks(stripRichMarks(parsed.content));\n\t\t\t\t\t\t\t\tconst slice = new Slice(\n\t\t\t\t\t\t\t\t\tcleaned,\n\t\t\t\t\t\t\t\t\tparsed.openStart,\n\t\t\t\t\t\t\t\t\tparsed.openEnd,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t_view.dispatch(_view.state.tr.replaceSelection(slice));\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst paragraphs = text\n\t\t\t\t\t\t\t.split('\\n')\n\t\t\t\t\t\t\t.map((line) =>\n\t\t\t\t\t\t\t\tschema.node('paragraph', null, line ? [schema.text(line)] : []),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\tconst slice = new Slice(Fragment.fromArray(paragraphs), 1, 1);\n\t\t\t\t\t\t_view.dispatch(_view.state.tr.replaceSelection(slice));\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t];\n\t},\n});\n"],"names":["PlainClipboardExtension","Extension","create","name","addProseMirrorPlugins","Plugin","props","handlePaste","_view","event","_b","clipboardData","_a","files","length","html","_c","getData","text","_d","includes","schema","state","container","document","createElement","innerHTML","querySelector","BLOCK_SELECTOR","cleanBlockBrs","parsed","ProseMirrorDOMParser","fromSchema","parseSlice","cleaned","normalizeBlanks","stripRichMarks","content","slice","Slice","openStart","openEnd","dispatch","tr","replaceSelection","paragraphs","split","map","line","node","Fragment","fromArray"],"mappings":"gTAcaA,EAA0BC,EAAUC,OAAO,CACvDC,KAAM,iBACNC,sBAAqBA,IACb,CACN,IAAIC,EAAO,CACVC,MAAO,CACNC,YAAYC,EAAOC,eAClB,WAAIC,EAAqB,UAArBD,EAAME,qBAAe,IAAAC,OAAA,EAAAA,EAAAC,4BAAOC,OAAQ,OAAO,EAC/C,MAAMC,EAA0B,QAAnBC,EAAAP,EAAME,qBAAa,IAAAK,OAAA,EAAAA,EAAEC,QAAQ,aACpCC,EAA0B,QAAnBC,EAAAV,EAAME,qBAAa,IAAAQ,OAAA,EAAAA,EAAEF,QAAQ,cAC1C,IAAKC,EAAM,OAAO,EAElB,GAAIH,aAAI,EAAJA,EAAMK,SAAS,iBAAkB,OAAO,EAE5C,MAAMC,EAASb,EAAMc,MAAMD,OAE3B,GAAIN,EAAM,CACT,MAAMQ,EAAYC,SAASC,cAAc,OACzCF,EAAUG,UAAYX,EAEtB,GADkBQ,EAAUI,cAAcC,GAC3B,CACdC,EAAcN,GACd,MAAMO,EACLC,EAAqBC,WAAWX,GAAQY,WAAWV,GAC9CW,EAAUC,EAAgBC,EAAeN,EAAOO,UAChDC,EAAQ,IAAIC,EACjBL,EACAJ,EAAOU,UACPV,EAAOW,SAGR,OADAjC,EAAMkC,SAASlC,EAAMc,MAAMqB,GAAGC,iBAAiBN,KACxC,CACP,CACD,CAED,MAAMO,EAAa3B,EACjB4B,MAAM,MACNC,KAAKC,GACL3B,EAAO4B,KAAK,YAAa,KAAMD,EAAO,CAAC3B,EAAOH,KAAK8B,IAAS,MAExDV,EAAQ,IAAIC,EAAMW,EAASC,UAAUN,GAAa,EAAG,GAE3D,OADArC,EAAMkC,SAASlC,EAAMc,MAAMqB,GAAGC,iBAAiBN,KACxC,CACR"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Extension } from '@tiptap/core';
|
|
2
|
-
/**
|
|
3
|
-
* Lightweight paste normalizer for rich-paste editors (email).
|
|
4
|
-
* Fixes Google Docs' standalone `<br>` between paragraphs and collapses
|
|
5
|
-
* consecutive empty paragraphs — but keeps ALL formatting marks intact.
|
|
6
|
-
*/
|
|
7
|
-
export declare const ClipboardNormalizationExtension: Extension<any, any>;
|