@bikdotai/bik-component-library 0.0.806-beta.4 → 0.0.806-beta.5
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/components/feature-announcements/FeatureAnnouncementProvider.js +1 -1
- package/dist/cjs/components/feature-announcements/FeatureAnnouncementProvider.js.map +1 -1
- package/dist/cjs/components/feature-announcements/MajorUpdatePopup.js +1 -1
- package/dist/cjs/components/feature-announcements/MajorUpdatePopup.js.map +1 -1
- package/dist/cjs/components/feature-announcements/MinorUpdatePopup.js +1 -1
- package/dist/cjs/components/feature-announcements/MinorUpdatePopup.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/mention/MentionExtension.js +1 -1
- package/dist/cjs/editor/extensions/mention/MentionExtension.js.map +1 -1
- package/dist/cjs/editor/extensions/plainClipboard/PlainClipboardExtension.js +1 -1
- package/dist/cjs/editor/extensions/plainClipboard/PlainClipboardExtension.js.map +1 -1
- package/dist/cjs/editor/extensions/slashCommand/SlashCommandExtension.js +1 -1
- package/dist/cjs/editor/extensions/slashCommand/SlashCommandExtension.js.map +1 -1
- package/dist/cjs/editor/serializers/toWhatsAppText.js +1 -1
- package/dist/cjs/editor/serializers/toWhatsAppText.js.map +1 -1
- package/dist/cjs/src/editor/BikEditor.utils.d.ts +7 -10
- package/dist/cjs/src/editor/serializers/toWhatsAppText.d.ts +2 -2
- package/dist/esm/components/feature-announcements/FeatureAnnouncementProvider.js +1 -1
- package/dist/esm/components/feature-announcements/FeatureAnnouncementProvider.js.map +1 -1
- package/dist/esm/components/feature-announcements/MajorUpdatePopup.js +1 -1
- package/dist/esm/components/feature-announcements/MajorUpdatePopup.js.map +1 -1
- package/dist/esm/components/feature-announcements/MinorUpdatePopup.js +1 -1
- package/dist/esm/components/feature-announcements/MinorUpdatePopup.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/mention/MentionExtension.js +1 -1
- package/dist/esm/editor/extensions/mention/MentionExtension.js.map +1 -1
- package/dist/esm/editor/extensions/plainClipboard/PlainClipboardExtension.js +1 -1
- package/dist/esm/editor/extensions/plainClipboard/PlainClipboardExtension.js.map +1 -1
- package/dist/esm/editor/extensions/slashCommand/SlashCommandExtension.js +1 -1
- package/dist/esm/editor/extensions/slashCommand/SlashCommandExtension.js.map +1 -1
- package/dist/esm/editor/serializers/toWhatsAppText.js +1 -1
- package/dist/esm/editor/serializers/toWhatsAppText.js.map +1 -1
- package/dist/esm/src/editor/BikEditor.utils.d.ts +7 -10
- package/dist/esm/src/editor/serializers/toWhatsAppText.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DOMSerializer as t,DOMParser as e}from"../node_modules/prosemirror-model/dist/index.js";function n(t){return t.replace(/<p
|
|
1
|
+
import{DOMSerializer as t,DOMParser as e}from"../node_modules/prosemirror-model/dist/index.js";function n(t){return t.replace(/<p[^>]*>\s*<br\s*\/?>\s*<\/p>/gi,"").replace(/<\/?span[^>]*>/gi,"")}function i(t,i){const r=n(i),o=document.createElement("div");o.innerHTML=r;const s=e.fromSchema(t.schema).parseSlice(o);if(0===s.size)return;const{from:c,to:l}=t.state.selection,d=t.state.tr.replaceRange(c,l,s);t.view.dispatch(d)}const r=t=>`<div data-section-divider="${t}" style="display:none;height:0;line-height:0;overflow:hidden;"></div>`;function o(t,e){let n=t;for(const t of e)n+=r(t.id)+t.content;return n}function s(t){var e;if(!t)return"";return null!==(e=l(t).get("body"))&&void 0!==e?e:t}function c(t){if(!t)return"";const e=s(t);return t.substring(e.length)}function l(t){const e=new Map,n=/<div[^>]*data-section-divider="([^"]*)[^>]*>\s*<\/div>/g,i=[];let r;for(;null!==(r=n.exec(t));)i.push({id:r[1],index:r.index,endIndex:r.index+r[0].length});if(0===i.length)return e.set("body",t),e;e.set("body",t.slice(0,i[0].index));for(let n=0;n<i.length;n++){const r=i[n].endIndex,o=n+1<i.length?i[n+1].index:t.length;e.set(i[n].id,t.slice(r,o))}return e}function d(e,n){var i;const r=h(e,n);if(-1===r)return{html:"",text:"",isEmpty:!0,characterCount:0};const o=m(e,n),s=e.state.doc.slice(r,o),c=document.createElement("div"),l=t.fromSchema(e.schema);c.appendChild(l.serializeFragment(s.content));const d=c.innerHTML,u=null!==(i=c.textContent)&&void 0!==i?i:"";return{html:d,text:u,isEmpty:!u.trim(),characterCount:u.length}}function u(t,n,i){const o=h(t,n);if(-1===o){const e=t.state.doc.content.size,o=r(n)+i;return void t.commands.insertContentAt(e,o,{updateSelection:!1})}const s=m(t,n),c=function(t,n){const i=document.createElement("div");return i.innerHTML=n,e.fromSchema(t.schema).parse(i).content}(t,i),{tr:l}=t.state,d="body"===n?0:o;l.replaceWith(d,s,c),l.setMeta("addToHistory",!1),t.view.dispatch(l)}function a(t){return d(t,"body")}function f(t){var e,n,i,r;return{bold:t.isActive("bold"),italic:t.isActive("italic"),underline:t.isActive("underline"),strike:t.isActive("strike"),bulletList:t.isActive("bulletList"),orderedList:t.isActive("orderedList"),blockquote:t.isActive("blockquote"),codeBlock:t.isActive("codeBlock"),link:(()=>{var e,n,i;if(t.isActive("link"))return{href:null!==(e=t.getAttributes("link").href)&&void 0!==e?e:""};const{$from:r}=t.state.selection;if(r.pos>0){const t=r.doc.resolve(r.pos).marks().find((t=>"link"===t.type.name));if(t)return{href:null!==(i=t.attrs.href)&&void 0!==i?i:""};{const t=r.nodeBefore,e=null==t?void 0:t.marks.find((t=>"link"===t.type.name));if(e)return{href:null!==(n=e.attrs.href)&&void 0!==n?n:""}}}return null})(),textAlign:t.isActive({textAlign:"center"})?"center":t.isActive({textAlign:"right"})?"right":t.isActive({textAlign:"justify"})?"justify":t.isActive({textAlign:"left"})?"left":null,fontFamily:null!==(e=t.getAttributes("textStyle").fontFamily)&&void 0!==e?e:null,fontSize:null!==(n=t.getAttributes("textStyle").fontSize)&&void 0!==n?n:null,color:null!==(i=t.getAttributes("textStyle").color)&&void 0!==i?i:null,highlight:t.isActive("highlight")?null!==(r=t.getAttributes("highlight").color)&&void 0!==r?r:"default":null,superscript:t.isActive("superscript"),subscript:t.isActive("subscript")}}function v(t){var e,n,i;return{html:t.getHTML(),text:t.getText(),isEmpty:t.isEmpty,characterCount:null!==(i=null===(n=null===(e=t.storage.characterCount)||void 0===e?void 0:e.characters)||void 0===n?void 0:n.call(e))&&void 0!==i?i:t.getText().length}}function h(t,e){if("body"===e)return 1;let n=-1;return t.state.doc.descendants(((t,i)=>{if(-1!==n)return!1;"sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(n=i+t.nodeSize)})),n}function m(t,e){const n=t.state.doc,i=n.content.size;if("body"===e){let t=-1;return n.descendants(((e,n)=>{if(-1!==t)return!1;"sectionDivider"===e.type.name&&(t=n)})),-1!==t?t:i}let r=!1,o=-1;return n.descendants(((t,n)=>-1===o&&(r?void("sectionDivider"===t.type.name&&(o=n)):("sectionDivider"===t.type.name&&t.attrs.sectionId===e&&(r=!0),!1)))),-1!==o?o:i}export{r as SECTION_DIVIDER_HTML,o as buildSectionedContent,f as extractActiveFormats,l as extractAllSectionsFromHtml,a as extractBodyContent,v as extractContent,d as extractSectionContent,m as findSectionEndPos,h as findSectionStartPos,s as getBodyHtml,c as getSectionsHtml,i as insertInlineHtml,n as normalizeHtml,u as setSectionContentInEditor};
|
|
2
2
|
//# sourceMappingURL=BikEditor.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BikEditor.utils.js","sources":["../../../src/editor/BikEditor.utils.ts"],"sourcesContent":["import { Editor } from '@tiptap/core';\nimport { DOMParser, DOMSerializer } from 'prosemirror-model';\nimport { EditorSnapshot, FormatState } from './BikEditor.types';\n\n// ---------------------------------------------------------------------------\n// HTML normalisation\n// ---------------------------------------------------------------------------\n\n/**\n * Normalise HTML before passing it to TipTap.\n *\n * Problem: Quill uses `<p><br></p>` as a blank-line separator. TipTap's\n * HardBreak extension parses that `<br>` as a real `hard_break` node.\n * ProseMirror then also appends `<br class=\"ProseMirror-trailingBreak\">` as a\n * cursor-position decoration, making the empty paragraph render at **2× line\n * height** instead of 1×.\n *\n * Fix: replace `<p><br></p>` → `<p></p>` so TipTap stores a truly empty\n * paragraph. ProseMirror adds only the trailing decoration, giving the correct\n * 1× line height. The WA text output is unchanged (`\\n` either way after\n * surrounding-newline collapse in `toWhatsAppText`).\n */\nexport function normalizeHtml(html: string): string {\n\treturn html\n\t\t.replace(/<p>\\s*<br\\s*\\/?>\\s*<\\/p>/gi, '<p></p>')\n\t\t.replace(/<\\/?span[^>]*>/gi, '');\n}\n\n// ---------------------------------------------------------------------------\n// Inline content insertion\n// ---------------------------------------------------------------------------\n\n/**\n * Insert HTML at the current cursor position, merging the first paragraph\n * inline while preserving the block structure of subsequent paragraphs/lists.\n *\n * Uses `parseSlice` which returns an open-ended Slice — the first block merges\n * at the cursor, middle blocks stay intact, and the last block merges with any\n * text that follows the cursor.\n */\nexport function insertInlineHtml(editor: Editor, html: string): void {\n\tconst normalised = normalizeHtml(html);\n\tconst dom = document.createElement('div');\n\tdom.innerHTML = normalised;\n\tconst slice = DOMParser.fromSchema(editor.schema).parseSlice(dom);\n\n\tif (slice.size === 0) return;\n\n\tconst { from, to } = editor.state.selection;\n\tconst tr = editor.state.tr.replaceRange(from, to, slice);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Section divider HTML\n// ---------------------------------------------------------------------------\n\nexport const SECTION_DIVIDER_HTML = (id: string) =>\n\t`<div data-section-divider=\"${id}\" style=\"display:none;height:0;line-height:0;overflow:hidden;\"></div>`;\n\n/**\n * Build initial HTML for an editor with one or more named sections below the body.\n * Each section is separated by an invisible divider node.\n *\n * @example\n * buildSectionedContent('<p>Body</p>', [\n * { id: 'signature', content: '<p>Alice</p>' },\n * { id: 'forwarded', content: '<p>--- fwd ---</p>' },\n * ])\n */\nexport function buildSectionedContent(\n\tbody: string,\n\tsections: Array<{ id: string; content: string }>,\n): string {\n\tlet html = body;\n\tfor (const s of sections) {\n\t\thtml += SECTION_DIVIDER_HTML(s.id) + s.content;\n\t}\n\treturn html;\n}\n\n// ---------------------------------------------------------------------------\n// Section extraction\n// ---------------------------------------------------------------------------\n\n/**\n * Parse the editor HTML into a Map of sectionId → raw HTML string.\n * The special key `'body'` always holds the content before the first divider.\n * Map iteration order matches document order.\n */\nexport function extractAllSections(editor: Editor): Map<string, string> {\n\treturn extractAllSectionsFromHtml(editor.getHTML());\n}\n\n/**\n * Extract just the body portion (everything before the first section divider)\n * from an HTML string produced by BikEditor. Safe to call on plain HTML too —\n * returns the full string when no dividers are present.\n */\nexport function getBodyHtml(html: string): string {\n\tif (!html) return '';\n\tconst sections = extractAllSectionsFromHtml(html);\n\treturn sections.get('body') ?? html;\n}\n\n/**\n * Extract everything from the first section divider onward (dividers + their\n * content). Returns an empty string when there are no sections.\n */\nexport function getSectionsHtml(html: string): string {\n\tif (!html) return '';\n\tconst body = getBodyHtml(html);\n\treturn html.substring(body.length);\n}\n\nexport function extractAllSectionsFromHtml(html: string): Map<string, string> {\n\tconst sections = new Map<string, string>();\n\tconst dividerRegex =\n\t\t/<div[^>]*data-section-divider=\"([^\"]*)[^>]*>\\s*<\\/div>/g;\n\tconst dividers: Array<{ id: string; index: number; endIndex: number }> = [];\n\n\tlet match: RegExpExecArray | null;\n\twhile ((match = dividerRegex.exec(html)) !== null) {\n\t\tdividers.push({\n\t\t\tid: match[1],\n\t\t\tindex: match.index,\n\t\t\tendIndex: match.index + match[0].length,\n\t\t});\n\t}\n\n\tif (dividers.length === 0) {\n\t\tsections.set('body', html);\n\t\treturn sections;\n\t}\n\n\tsections.set('body', html.slice(0, dividers[0].index));\n\tfor (let i = 0; i < dividers.length; i++) {\n\t\tconst start = dividers[i].endIndex;\n\t\tconst end = i + 1 < dividers.length ? dividers[i + 1].index : html.length;\n\t\tsections.set(dividers[i].id, html.slice(start, end));\n\t}\n\n\treturn sections;\n}\n\n/** Returns BikEditorContent for a single named section (or 'body'). */\nexport function extractSectionContent(\n\teditor: Editor,\n\tid: string,\n): EditorSnapshot {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1)\n\t\treturn { html: '', text: '', isEmpty: true, characterCount: 0 };\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst slice = editor.state.doc.slice(startPos, endPos);\n\tconst container = document.createElement('div');\n\tconst serializer = DOMSerializer.fromSchema(editor.schema);\n\tcontainer.appendChild(serializer.serializeFragment(slice.content));\n\tconst html = container.innerHTML;\n\tconst text = container.textContent ?? '';\n\treturn { html, text, isEmpty: !text.trim(), characterCount: text.length };\n}\n\n/**\n * Parse an HTML string into ProseMirror nodes using the editor's schema.\n */\nfunction parseHtmlToNodes(editor: Editor, html: string) {\n\tconst container = document.createElement('div');\n\tcontainer.innerHTML = html;\n\treturn DOMParser.fromSchema(editor.schema).parse(container).content;\n}\n\n/**\n * Replace the content of a single named section without touching others.\n * Uses a ProseMirror transaction to replace only the target range,\n * preserving undo history and other sections' state.\n * If the section doesn't exist yet, it is appended at the end of the document.\n */\nexport function setSectionContentInEditor(\n\teditor: Editor,\n\tid: string,\n\thtml: string,\n): void {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1) {\n\t\tconst endPos = editor.state.doc.content.size;\n\t\tconst dividerHtml = SECTION_DIVIDER_HTML(id) + html;\n\t\teditor.commands.insertContentAt(endPos, dividerHtml, {\n\t\t\tupdateSelection: false,\n\t\t});\n\t\treturn;\n\t}\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst fragment = parseHtmlToNodes(editor, html);\n\tconst { tr } = editor.state;\n\t// For body, replace from position 0 (before the first paragraph's opening\n\t// boundary) so ProseMirror swaps entire block nodes cleanly. Position 1\n\t// (inside the paragraph) would force ProseMirror to close the open paragraph\n\t// first, creating a ghost empty <p></p>.\n\tconst replaceFrom = id === 'body' ? 0 : startPos;\n\ttr.replaceWith(replaceFrom, endPos, fragment);\n\ttr.setMeta('addToHistory', false);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Convenience shorthands (body = first section)\n// ---------------------------------------------------------------------------\n\n/** Extract BikEditorContent for just the body (before the first divider). */\nexport function extractBodyContent(editor: Editor): EditorSnapshot {\n\treturn extractSectionContent(editor, 'body');\n}\n\n// ---------------------------------------------------------------------------\n// Active formats\n// ---------------------------------------------------------------------------\n\nexport function extractActiveFormats(editor: Editor): FormatState {\n\treturn {\n\t\tbold: editor.isActive('bold'),\n\t\titalic: editor.isActive('italic'),\n\t\tunderline: editor.isActive('underline'),\n\t\tstrike: editor.isActive('strike'),\n\t\tbulletList: editor.isActive('bulletList'),\n\t\torderedList: editor.isActive('orderedList'),\n\t\tblockquote: editor.isActive('blockquote'),\n\t\tcodeBlock: editor.isActive('codeBlock'),\n\t\tlink: (() => {\n\t\t\tif (editor.isActive('link')) {\n\t\t\t\treturn { href: editor.getAttributes('link')['href'] ?? '' };\n\t\t\t}\n\t\t\tconst { $from } = editor.state.selection;\n\t\t\tif ($from.pos > 0) {\n\t\t\t\tconst before = $from.doc.resolve($from.pos);\n\t\t\t\tconst linkMark = before.marks().find((m) => m.type.name === 'link');\n\t\t\t\tif (!linkMark) {\n\t\t\t\t\tconst nodeBefore = $from.nodeBefore;\n\t\t\t\t\tconst markOnPrev = nodeBefore?.marks.find(\n\t\t\t\t\t\t(m) => m.type.name === 'link',\n\t\t\t\t\t);\n\t\t\t\t\tif (markOnPrev) {\n\t\t\t\t\t\treturn { href: markOnPrev.attrs['href'] ?? '' };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn { href: linkMark.attrs['href'] ?? '' };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t})(),\n\t\ttextAlign: editor.isActive({ textAlign: 'center' })\n\t\t\t? 'center'\n\t\t\t: editor.isActive({ textAlign: 'right' })\n\t\t\t? 'right'\n\t\t\t: editor.isActive({ textAlign: 'justify' })\n\t\t\t? 'justify'\n\t\t\t: editor.isActive({ textAlign: 'left' })\n\t\t\t? 'left'\n\t\t\t: null,\n\t\tfontFamily: editor.getAttributes('textStyle')['fontFamily'] ?? null,\n\t\tfontSize: editor.getAttributes('textStyle')['fontSize'] ?? null,\n\t\tcolor: editor.getAttributes('textStyle')['color'] ?? null,\n\t\thighlight: editor.isActive('highlight')\n\t\t\t? editor.getAttributes('highlight')['color'] ?? 'default'\n\t\t\t: null,\n\t\tsuperscript: editor.isActive('superscript'),\n\t\tsubscript: editor.isActive('subscript'),\n\t};\n}\n\nexport function extractContent(editor: Editor): EditorSnapshot {\n\treturn {\n\t\thtml: editor.getHTML(),\n\t\ttext: editor.getText(),\n\t\tisEmpty: editor.isEmpty,\n\t\tcharacterCount:\n\t\t\teditor.storage.characterCount?.characters?.() ?? editor.getText().length,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Section position helpers (used by insertAtSectionStart/End and appendBodyContent)\n// ---------------------------------------------------------------------------\n\n/**\n * Returns the ProseMirror position immediately after a section's opening divider\n * (i.e. the start of the section's own content).\n * For `'body'`, returns 1 (beginning of the document).\n * Returns -1 if the named section's divider is not found.\n */\nexport function findSectionStartPos(editor: Editor, sectionId: string): number {\n\tif (sectionId === 'body') return 1;\n\tlet startPos = -1;\n\teditor.state.doc.descendants((node, pos) => {\n\t\tif (startPos !== -1) return false;\n\t\tif (\n\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t) {\n\t\t\tstartPos = pos + node.nodeSize; // position right after the divider\n\t\t}\n\t});\n\treturn startPos;\n}\n\n/**\n * Returns the ProseMirror position at the end of a named section's content:\n * - For `'body'`: position of the first section divider, or end of document.\n * - For a named section: position of the next divider, or end of document.\n */\nexport function findSectionEndPos(editor: Editor, sectionId: string): number {\n\tconst doc = editor.state.doc;\n\tconst docSize = doc.content.size;\n\n\tif (sectionId === 'body') {\n\t\tlet firstDividerPos = -1;\n\t\tdoc.descendants((node, pos) => {\n\t\t\tif (firstDividerPos !== -1) return false;\n\t\t\tif (node.type.name === 'sectionDivider') {\n\t\t\t\tfirstDividerPos = pos;\n\t\t\t}\n\t\t});\n\t\treturn firstDividerPos !== -1 ? firstDividerPos : docSize;\n\t}\n\n\tlet passedSection = false;\n\tlet nextDividerPos = -1;\n\tdoc.descendants((node, pos) => {\n\t\tif (nextDividerPos !== -1) return false;\n\t\tif (!passedSection) {\n\t\t\tif (\n\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t) {\n\t\t\t\tpassedSection = true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tif (node.type.name === 'sectionDivider') {\n\t\t\tnextDividerPos = pos;\n\t\t}\n\t});\n\treturn nextDividerPos !== -1 ? nextDividerPos : docSize;\n}\n"],"names":["normalizeHtml","html","replace","insertInlineHtml","editor","normalised","dom","document","createElement","innerHTML","slice","DOMParser","fromSchema","schema","parseSlice","size","from","to","state","selection","tr","replaceRange","view","dispatch","SECTION_DIVIDER_HTML","id","buildSectionedContent","body","sections","s","content","getBodyHtml","_a","extractAllSectionsFromHtml","get","getSectionsHtml","substring","length","Map","dividerRegex","dividers","match","exec","push","index","endIndex","set","i","start","end","extractSectionContent","startPos","findSectionStartPos","text","isEmpty","characterCount","endPos","findSectionEndPos","doc","container","serializer","DOMSerializer","appendChild","serializeFragment","textContent","trim","setSectionContentInEditor","dividerHtml","commands","insertContentAt","updateSelection","fragment","parse","parseHtmlToNodes","replaceFrom","replaceWith","setMeta","extractBodyContent","extractActiveFormats","bold","isActive","italic","underline","strike","bulletList","orderedList","blockquote","codeBlock","link","href","getAttributes","$from","pos","linkMark","resolve","marks","find","m","type","name","_c","attrs","nodeBefore","markOnPrev","_b","textAlign","fontFamily","fontSize","color","highlight","_d","superscript","subscript","extractContent","getHTML","getText","storage","characters","sectionId","descendants","node","nodeSize","docSize","fir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EAAkBrD,EAAgBkH,GACjD,MAAM5D,EAAMtD,EAAOc,MAAMwC,IACnBgE,EAAUhE,EAAI5B,QAAQf,KAE5B,GAAkB,SAAduG,EAAsB,CACzB,IAAIK,GAAmB,EAOvB,OANAjE,EAAI6D,aAAY,CAACC,EAAM5B,KACtB,IAAyB,IAArB+B,EAAwB,OAAO,EACZ,mBAAnBH,EAAKtB,KAAKC,OACbwB,EAAkB/B,EAClB,KAE0B,IAArB+B,EAAyBA,EAAkBD,CAClD,CAED,IAAIE,GAAgB,EAChBC,GAAkB,EAgBtB,OAfAnE,EAAI6D,aAAY,CAACC,EAAM5B,KACE,IAApBiC,IACCD,OASkB,mBAAnBJ,EAAKtB,KAAKC,OACb0B,EAAiBjC,KARG,mBAAnB4B,EAAKtB,KAAKC,MACVqB,EAAKnB,MAAiB,YAAMiB,IAE5BM,GAAgB,IAEV,OAMkB,IAApBC,EAAwBA,EAAiBH,CACjD"}
|
|
1
|
+
{"version":3,"file":"BikEditor.utils.js","sources":["../../../src/editor/BikEditor.utils.ts"],"sourcesContent":["import { Editor } from '@tiptap/core';\nimport { DOMParser, DOMSerializer } from 'prosemirror-model';\nimport { EditorSnapshot, FormatState } from './BikEditor.types';\n\n// ---------------------------------------------------------------------------\n// HTML normalisation\n// ---------------------------------------------------------------------------\n\n/**\n * Normalise HTML before passing it to TipTap.\n *\n * Empty paragraphs containing only a `<br>` (e.g. `<p><br></p>` or\n * `<p style=\"...\"><br></p>`) are removed entirely. ProseMirror adds a\n * trailing `<br>` to every empty paragraph in the DOM for cursor\n * positioning, so stripping just the `<br>` and leaving `<p></p>`\n * doesn't work — the paragraph still renders with height. Removing\n * the whole element avoids creating a node at all. This is in sync\n * with how Gmail renders HTML.\n */\nexport function normalizeHtml(html: string): string {\n\treturn html\n\t\t.replace(/<p[^>]*>\\s*<br\\s*\\/?>\\s*<\\/p>/gi, '')\n\t\t.replace(/<\\/?span[^>]*>/gi, '');\n}\n\n// ---------------------------------------------------------------------------\n// Inline content insertion\n// ---------------------------------------------------------------------------\n\n/**\n * Insert HTML at the current cursor position, merging the first paragraph\n * inline while preserving the block structure of subsequent paragraphs/lists.\n *\n * Uses `parseSlice` which returns an open-ended Slice — the first block merges\n * at the cursor, middle blocks stay intact, and the last block merges with any\n * text that follows the cursor.\n */\nexport function insertInlineHtml(editor: Editor, html: string): void {\n\tconst normalised = normalizeHtml(html);\n\tconst dom = document.createElement('div');\n\tdom.innerHTML = normalised;\n\tconst slice = DOMParser.fromSchema(editor.schema).parseSlice(dom);\n\n\tif (slice.size === 0) return;\n\n\tconst { from, to } = editor.state.selection;\n\tconst tr = editor.state.tr.replaceRange(from, to, slice);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Section divider HTML\n// ---------------------------------------------------------------------------\n\nexport const SECTION_DIVIDER_HTML = (id: string) =>\n\t`<div data-section-divider=\"${id}\" style=\"display:none;height:0;line-height:0;overflow:hidden;\"></div>`;\n\n/**\n * Build initial HTML for an editor with one or more named sections below the body.\n * Each section is separated by an invisible divider node.\n *\n * @example\n * buildSectionedContent('<p>Body</p>', [\n * { id: 'signature', content: '<p>Alice</p>' },\n * { id: 'forwarded', content: '<p>--- fwd ---</p>' },\n * ])\n */\nexport function buildSectionedContent(\n\tbody: string,\n\tsections: Array<{ id: string; content: string }>,\n): string {\n\tlet html = body;\n\tfor (const s of sections) {\n\t\thtml += SECTION_DIVIDER_HTML(s.id) + s.content;\n\t}\n\treturn html;\n}\n\n// ---------------------------------------------------------------------------\n// Section extraction\n// ---------------------------------------------------------------------------\n\n/**\n * Parse the editor HTML into a Map of sectionId → raw HTML string.\n * The special key `'body'` always holds the content before the first divider.\n * Map iteration order matches document order.\n */\nexport function extractAllSections(editor: Editor): Map<string, string> {\n\treturn extractAllSectionsFromHtml(editor.getHTML());\n}\n\n/**\n * Extract just the body portion (everything before the first section divider)\n * from an HTML string produced by BikEditor. Safe to call on plain HTML too —\n * returns the full string when no dividers are present.\n */\nexport function getBodyHtml(html: string): string {\n\tif (!html) return '';\n\tconst sections = extractAllSectionsFromHtml(html);\n\treturn sections.get('body') ?? html;\n}\n\n/**\n * Extract everything from the first section divider onward (dividers + their\n * content). Returns an empty string when there are no sections.\n */\nexport function getSectionsHtml(html: string): string {\n\tif (!html) return '';\n\tconst body = getBodyHtml(html);\n\treturn html.substring(body.length);\n}\n\nexport function extractAllSectionsFromHtml(html: string): Map<string, string> {\n\tconst sections = new Map<string, string>();\n\tconst dividerRegex =\n\t\t/<div[^>]*data-section-divider=\"([^\"]*)[^>]*>\\s*<\\/div>/g;\n\tconst dividers: Array<{ id: string; index: number; endIndex: number }> = [];\n\n\tlet match: RegExpExecArray | null;\n\twhile ((match = dividerRegex.exec(html)) !== null) {\n\t\tdividers.push({\n\t\t\tid: match[1],\n\t\t\tindex: match.index,\n\t\t\tendIndex: match.index + match[0].length,\n\t\t});\n\t}\n\n\tif (dividers.length === 0) {\n\t\tsections.set('body', html);\n\t\treturn sections;\n\t}\n\n\tsections.set('body', html.slice(0, dividers[0].index));\n\tfor (let i = 0; i < dividers.length; i++) {\n\t\tconst start = dividers[i].endIndex;\n\t\tconst end = i + 1 < dividers.length ? dividers[i + 1].index : html.length;\n\t\tsections.set(dividers[i].id, html.slice(start, end));\n\t}\n\n\treturn sections;\n}\n\n/** Returns BikEditorContent for a single named section (or 'body'). */\nexport function extractSectionContent(\n\teditor: Editor,\n\tid: string,\n): EditorSnapshot {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1)\n\t\treturn { html: '', text: '', isEmpty: true, characterCount: 0 };\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst slice = editor.state.doc.slice(startPos, endPos);\n\tconst container = document.createElement('div');\n\tconst serializer = DOMSerializer.fromSchema(editor.schema);\n\tcontainer.appendChild(serializer.serializeFragment(slice.content));\n\tconst html = container.innerHTML;\n\tconst text = container.textContent ?? '';\n\treturn { html, text, isEmpty: !text.trim(), characterCount: text.length };\n}\n\n/**\n * Parse an HTML string into ProseMirror nodes using the editor's schema.\n */\nfunction parseHtmlToNodes(editor: Editor, html: string) {\n\tconst container = document.createElement('div');\n\tcontainer.innerHTML = html;\n\treturn DOMParser.fromSchema(editor.schema).parse(container).content;\n}\n\n/**\n * Replace the content of a single named section without touching others.\n * Uses a ProseMirror transaction to replace only the target range,\n * preserving undo history and other sections' state.\n * If the section doesn't exist yet, it is appended at the end of the document.\n */\nexport function setSectionContentInEditor(\n\teditor: Editor,\n\tid: string,\n\thtml: string,\n): void {\n\tconst startPos = findSectionStartPos(editor, id);\n\tif (startPos === -1) {\n\t\tconst endPos = editor.state.doc.content.size;\n\t\tconst dividerHtml = SECTION_DIVIDER_HTML(id) + html;\n\t\teditor.commands.insertContentAt(endPos, dividerHtml, {\n\t\t\tupdateSelection: false,\n\t\t});\n\t\treturn;\n\t}\n\tconst endPos = findSectionEndPos(editor, id);\n\tconst fragment = parseHtmlToNodes(editor, html);\n\tconst { tr } = editor.state;\n\t// For body, replace from position 0 (before the first paragraph's opening\n\t// boundary) so ProseMirror swaps entire block nodes cleanly. Position 1\n\t// (inside the paragraph) would force ProseMirror to close the open paragraph\n\t// first, creating a ghost empty <p></p>.\n\tconst replaceFrom = id === 'body' ? 0 : startPos;\n\ttr.replaceWith(replaceFrom, endPos, fragment);\n\ttr.setMeta('addToHistory', false);\n\teditor.view.dispatch(tr);\n}\n\n// ---------------------------------------------------------------------------\n// Convenience shorthands (body = first section)\n// ---------------------------------------------------------------------------\n\n/** Extract BikEditorContent for just the body (before the first divider). */\nexport function extractBodyContent(editor: Editor): EditorSnapshot {\n\treturn extractSectionContent(editor, 'body');\n}\n\n// ---------------------------------------------------------------------------\n// Active formats\n// ---------------------------------------------------------------------------\n\nexport function extractActiveFormats(editor: Editor): FormatState {\n\treturn {\n\t\tbold: editor.isActive('bold'),\n\t\titalic: editor.isActive('italic'),\n\t\tunderline: editor.isActive('underline'),\n\t\tstrike: editor.isActive('strike'),\n\t\tbulletList: editor.isActive('bulletList'),\n\t\torderedList: editor.isActive('orderedList'),\n\t\tblockquote: editor.isActive('blockquote'),\n\t\tcodeBlock: editor.isActive('codeBlock'),\n\t\tlink: (() => {\n\t\t\tif (editor.isActive('link')) {\n\t\t\t\treturn { href: editor.getAttributes('link')['href'] ?? '' };\n\t\t\t}\n\t\t\tconst { $from } = editor.state.selection;\n\t\t\tif ($from.pos > 0) {\n\t\t\t\tconst before = $from.doc.resolve($from.pos);\n\t\t\t\tconst linkMark = before.marks().find((m) => m.type.name === 'link');\n\t\t\t\tif (!linkMark) {\n\t\t\t\t\tconst nodeBefore = $from.nodeBefore;\n\t\t\t\t\tconst markOnPrev = nodeBefore?.marks.find(\n\t\t\t\t\t\t(m) => m.type.name === 'link',\n\t\t\t\t\t);\n\t\t\t\t\tif (markOnPrev) {\n\t\t\t\t\t\treturn { href: markOnPrev.attrs['href'] ?? '' };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn { href: linkMark.attrs['href'] ?? '' };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t})(),\n\t\ttextAlign: editor.isActive({ textAlign: 'center' })\n\t\t\t? 'center'\n\t\t\t: editor.isActive({ textAlign: 'right' })\n\t\t\t? 'right'\n\t\t\t: editor.isActive({ textAlign: 'justify' })\n\t\t\t? 'justify'\n\t\t\t: editor.isActive({ textAlign: 'left' })\n\t\t\t? 'left'\n\t\t\t: null,\n\t\tfontFamily: editor.getAttributes('textStyle')['fontFamily'] ?? null,\n\t\tfontSize: editor.getAttributes('textStyle')['fontSize'] ?? null,\n\t\tcolor: editor.getAttributes('textStyle')['color'] ?? null,\n\t\thighlight: editor.isActive('highlight')\n\t\t\t? editor.getAttributes('highlight')['color'] ?? 'default'\n\t\t\t: null,\n\t\tsuperscript: editor.isActive('superscript'),\n\t\tsubscript: editor.isActive('subscript'),\n\t};\n}\n\nexport function extractContent(editor: Editor): EditorSnapshot {\n\treturn {\n\t\thtml: editor.getHTML(),\n\t\ttext: editor.getText(),\n\t\tisEmpty: editor.isEmpty,\n\t\tcharacterCount:\n\t\t\teditor.storage.characterCount?.characters?.() ?? editor.getText().length,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Section position helpers (used by insertAtSectionStart/End and appendBodyContent)\n// ---------------------------------------------------------------------------\n\n/**\n * Returns the ProseMirror position immediately after a section's opening divider\n * (i.e. the start of the section's own content).\n * For `'body'`, returns 1 (beginning of the document).\n * Returns -1 if the named section's divider is not found.\n */\nexport function findSectionStartPos(editor: Editor, sectionId: string): number {\n\tif (sectionId === 'body') return 1;\n\tlet startPos = -1;\n\teditor.state.doc.descendants((node, pos) => {\n\t\tif (startPos !== -1) return false;\n\t\tif (\n\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t) {\n\t\t\tstartPos = pos + node.nodeSize; // position right after the divider\n\t\t}\n\t});\n\treturn startPos;\n}\n\n/**\n * Returns the ProseMirror position at the end of a named section's content:\n * - For `'body'`: position of the first section divider, or end of document.\n * - For a named section: position of the next divider, or end of document.\n */\nexport function findSectionEndPos(editor: Editor, sectionId: string): number {\n\tconst doc = editor.state.doc;\n\tconst docSize = doc.content.size;\n\n\tif (sectionId === 'body') {\n\t\tlet firstDividerPos = -1;\n\t\tdoc.descendants((node, pos) => {\n\t\t\tif (firstDividerPos !== -1) return false;\n\t\t\tif (node.type.name === 'sectionDivider') {\n\t\t\t\tfirstDividerPos = pos;\n\t\t\t}\n\t\t});\n\t\treturn firstDividerPos !== -1 ? firstDividerPos : docSize;\n\t}\n\n\tlet passedSection = false;\n\tlet nextDividerPos = -1;\n\tdoc.descendants((node, pos) => {\n\t\tif (nextDividerPos !== -1) return false;\n\t\tif (!passedSection) {\n\t\t\tif (\n\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t) {\n\t\t\t\tpassedSection = true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tif (node.type.name === 'sectionDivider') {\n\t\t\tnextDividerPos = pos;\n\t\t}\n\t});\n\treturn nextDividerPos !== -1 ? nextDividerPos : docSize;\n}\n"],"names":["normalizeHtml","html","replace","insertInlineHtml","editor","normalised","dom","document","createElement","innerHTML","slice","DOMParser","fromSchema","schema","parseSlice","size","from","to","state","selection","tr","replaceRange","view","dispatch","SECTION_DIVIDER_HTML","id","buildSectionedContent","body","sections","s","content","getBodyHtml","_a","extractAllSectionsFromHtml","get","getSectionsHtml","substring","length","Map","dividerRegex","dividers","match","exec","push","index","endIndex","set","i","start","end","extractSectionContent","startPos","findSectionStartPos","text","isEmpty","characterCount","endPos","findSectionEndPos","doc","container","serializer","DOMSerializer","appendChild","serializeFragment","textContent","trim","setSectionContentInEditor","dividerHtml","commands","insertContentAt","updateSelection","fragment","parse","parseHtmlToNodes","replaceFrom","replaceWith","setMeta","extractBodyContent","extractActiveFormats","bold","isActive","italic","underline","strike","bulletList","orderedList","blockquote","codeBlock","link","href","getAttributes","$from","pos","linkMark","resolve","marks","find","m","type","name","_c","attrs","nodeBefore","markOnPrev","_b","textAlign","fontFamily","fontSize","color","highlight","_d","superscript","subscript","extractContent","getHTML","getText","storage","characters","sectionId","descendants","node","nodeSize","docSize","firstDividerPos","passedSection","nextDividerPos"],"mappings":"+FAmBM,SAAUA,EAAcC,GAC7B,OAAOA,EACLC,QAAQ,kCAAmC,IAC3CA,QAAQ,mBAAoB,GAC/B,CAcgB,SAAAC,EAAiBC,EAAgBH,GAChD,MAAMI,EAAaL,EAAcC,GAC3BK,EAAMC,SAASC,cAAc,OACnCF,EAAIG,UAAYJ,EAChB,MAAMK,EAAQC,EAAUC,WAAWR,EAAOS,QAAQC,WAAWR,GAE7D,GAAmB,IAAfI,EAAMK,KAAY,OAEtB,MAAMC,KAAEA,EAAIC,GAAEA,GAAOb,EAAOc,MAAMC,UAC5BC,EAAKhB,EAAOc,MAAME,GAAGC,aAAaL,EAAMC,EAAIP,GAClDN,EAAOkB,KAAKC,SAASH,EACtB,OAMaI,EAAw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KC,MACVqB,EAAKnB,MAAiB,YAAMiB,IAE5BM,GAAgB,IAEV,OAMkB,IAApBC,EAAwBA,EAAiBH,CACjD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{mergeAttributes as e}from"../../../node_modules/@tiptap/core/dist/index.js";import t from"@tiptap/extension-mention";import{ReactRenderer as n}from"@tiptap/react";import{createSuggestionPopup as r}from"../suggestionPopup.js";import{MentionDropdown as o}from"./MentionDropdown.js";function i(e){let t=arguments.length>2?arguments[2]:void 0,i=arguments.length>3?arguments[3]:void 0;return()=>{let e,s;return{onStart:a=>{e=new n(o,{props:Object.assign(Object.assign({},a),{renderItem:t,renderDropdown:i}),editor:a.editor}),s=r(e.element,a.clientRect)},onUpdate:n=>{var r;e.updateProps(Object.assign(Object.assign({},n),{renderItem:t,renderDropdown:i})),(null===(r=n.items)||void 0===r?void 0:r.length)?(s.show(),s.updatePosition(n.clientRect)):s.hide()},onKeyDown:t=>{var n,r;return"Escape"===t.event.key?(s.hide(),!0):null!==(r=null===(n=e.ref)||void 0===n?void 0:n.onKeyDown(t))&&void 0!==r&&r},onExit:()=>{s.destroy(),e.destroy()}}}}function s(n,r,o,s){return t.extend({name:"mentionAgent"}).configure({HTMLAttributes:{class:"bik-mention bik-mention--agent"},renderText:e=>{let{options:t,node:n}=e;return`${t.suggestion.char}${n.attrs.label}`},renderHTML:t=>{let{options:n,node:r}=t;return["span",e(n.HTMLAttributes),`${n.suggestion.char}${r.attrs.label}`]},suggestion:{char:"@",items:e=>{let{query:t}=e;return n.current.filter((e=>e.label.toLowerCase().includes(t.toLowerCase())))},command:e=>{let{editor:t,range:n,props:o}=e;t.chain().focus().deleteRange(n).insertContent({type:"mentionAgent",attrs:{id:o.id,label:o.label}}).run(),null==r||r(o,"@")},render:i(r,"@",o,s)}})}function a(n,r,o,s){return t.extend({name:"mentionTeam"}).configure({HTMLAttributes:{class:"bik-mention bik-mention--team"},renderText:e=>{let{options:t,node:n}=e;return`${t.suggestion.char}${n.attrs.label}`},renderHTML:t=>{let{options:n,node:r}=t;return["span",e(n.HTMLAttributes),`${n.suggestion.char}${r.attrs.label}`]},suggestion:{char:"#",items:e=>{let{query:t}=e;return n.current.filter((e=>e.label.toLowerCase().includes(t.toLowerCase())))},command:e=>{let{editor:t,range:n,props:o}=e;t.chain().focus().deleteRange(n).insertContent({type:"mentionTeam",attrs:{id:o.id,label:o.label}}).run(),null==r||r(o,"#")},render:i(r,"#",o,s)}})}export{s as buildAgentMentionExtension,a as buildTeamMentionExtension};
|
|
1
|
+
import{mergeAttributes as e}from"../../../node_modules/@tiptap/core/dist/index.js";import t from"@tiptap/extension-mention";import{ReactRenderer as n}from"@tiptap/react";import{createSuggestionPopup as r}from"../suggestionPopup.js";import{MentionDropdown as o}from"./MentionDropdown.js";function i(e){let t=arguments.length>2?arguments[2]:void 0,i=arguments.length>3?arguments[3]:void 0;return()=>{let e,s;return{onStart:a=>{e=new n(o,{props:Object.assign(Object.assign({},a),{renderItem:t,renderDropdown:i}),editor:a.editor}),s=r(e.element,a.clientRect)},onUpdate:n=>{var r;e.updateProps(Object.assign(Object.assign({},n),{renderItem:t,renderDropdown:i})),(null===(r=n.items)||void 0===r?void 0:r.length)?(s.show(),s.updatePosition(n.clientRect)):s.hide()},onKeyDown:t=>{var n,r;return"Escape"===t.event.key?(s.hide(),!0):null!==(r=null===(n=e.ref)||void 0===n?void 0:n.onKeyDown(t))&&void 0!==r&&r},onExit:()=>{s.destroy(),e.destroy()}}}}function s(n,r,o,s){return t.extend({name:"mentionAgent"}).configure({HTMLAttributes:{class:"bik-mention bik-mention--agent"},renderText:e=>{let{options:t,node:n}=e;return`${t.suggestion.char}${n.attrs.label}`},renderHTML:t=>{let{options:n,node:r}=t;return["span",e(n.HTMLAttributes),`${n.suggestion.char}${r.attrs.label}`]},suggestion:{char:"@",allowSpaces:!0,items:e=>{let{query:t}=e;return n.current.filter((e=>e.label.toLowerCase().includes(t.toLowerCase())))},command:e=>{let{editor:t,range:n,props:o}=e;t.chain().focus().deleteRange(n).insertContent({type:"mentionAgent",attrs:{id:o.id,label:o.label}}).run(),null==r||r(o,"@")},render:i(r,"@",o,s)}})}function a(n,r,o,s){return t.extend({name:"mentionTeam"}).configure({HTMLAttributes:{class:"bik-mention bik-mention--team"},renderText:e=>{let{options:t,node:n}=e;return`${t.suggestion.char}${n.attrs.label}`},renderHTML:t=>{let{options:n,node:r}=t;return["span",e(n.HTMLAttributes),`${n.suggestion.char}${r.attrs.label}`]},suggestion:{char:"#",allowSpaces:!0,items:e=>{let{query:t}=e;return n.current.filter((e=>e.label.toLowerCase().includes(t.toLowerCase())))},command:e=>{let{editor:t,range:n,props:o}=e;t.chain().focus().deleteRange(n).insertContent({type:"mentionTeam",attrs:{id:o.id,label:o.label}}).run(),null==r||r(o,"#")},render:i(r,"#",o,s)}})}export{s as buildAgentMentionExtension,a as buildTeamMentionExtension};
|
|
2
2
|
//# sourceMappingURL=MentionExtension.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MentionExtension.js","sources":["../../../../../src/editor/extensions/mention/MentionExtension.ts"],"sourcesContent":["import { mergeAttributes } from '@tiptap/core';\nimport Mention from '@tiptap/extension-mention';\nimport { ReactRenderer } from '@tiptap/react';\nimport type { ReactNode } from 'react';\nimport type {\n\tMentionDropdownRenderProps,\n\tMentionItem,\n} from '../../BikEditor.types';\nimport {\n\tcreateSuggestionPopup,\n\ttype SuggestionPopup,\n} from '../suggestionPopup';\nimport { MentionDropdown } from './MentionDropdown';\n\nfunction buildRender(\n\tonSelect?: (item: MentionItem, char: '@' | '#') => void,\n\tchar: '@' | '#' = '@',\n\trenderItem?: (item: MentionItem, isActive: boolean) => ReactNode,\n\trenderDropdown?: (props: MentionDropdownRenderProps) => ReactNode,\n) {\n\treturn () => {\n\t\tlet component: ReactRenderer;\n\t\tlet popup: SuggestionPopup;\n\n\t\treturn {\n\t\t\tonStart: (props: any) => {\n\t\t\t\tcomponent = new ReactRenderer(MentionDropdown, {\n\t\t\t\t\tprops: { ...props, renderItem, renderDropdown },\n\t\t\t\t\teditor: props.editor,\n\t\t\t\t});\n\t\t\t\tpopup = createSuggestionPopup(component.element, props.clientRect);\n\t\t\t},\n\t\t\tonUpdate: (props: any) => {\n\t\t\t\tcomponent.updateProps({ ...props, renderItem, renderDropdown });\n\t\t\t\tif (!props.items?.length) {\n\t\t\t\t\tpopup.hide();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tpopup.show();\n\t\t\t\tpopup.updatePosition(props.clientRect);\n\t\t\t},\n\t\t\tonKeyDown: (props: any) => {\n\t\t\t\tif (props.event.key === 'Escape') {\n\t\t\t\t\tpopup.hide();\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\treturn (component.ref as any)?.onKeyDown(props) ?? false;\n\t\t\t},\n\t\t\tonExit: () => {\n\t\t\t\tpopup.destroy();\n\t\t\t\tcomponent.destroy();\n\t\t\t},\n\t\t};\n\t};\n}\n\nexport function buildAgentMentionExtension(\n\tagentsRef: { current: MentionItem[] },\n\tonSelect?: (item: MentionItem, char: '@' | '#') => void,\n\trenderItem?: (item: MentionItem, isActive: boolean) => ReactNode,\n\trenderDropdown?: (props: MentionDropdownRenderProps) => ReactNode,\n) {\n\treturn Mention.extend({ name: 'mentionAgent' }).configure({\n\t\tHTMLAttributes: { class: 'bik-mention bik-mention--agent' },\n\t\trenderText: ({ options, node }) =>\n\t\t\t`${options.suggestion.char}${node.attrs['label']}`,\n\t\trenderHTML: ({ options, node }) => [\n\t\t\t'span',\n\t\t\tmergeAttributes(options.HTMLAttributes),\n\t\t\t`${options.suggestion.char}${node.attrs['label']}`,\n\t\t],\n\t\tsuggestion: {\n\t\t\tchar: '@',\n\t\t\titems: ({ query }: { query: string }) =>\n\t\t\t\tagentsRef.current.filter((a) =>\n\t\t\t\t\ta.label.toLowerCase().includes(query.toLowerCase()),\n\t\t\t\t),\n\t\t\tcommand: ({ editor, range, props }: any) => {\n\t\t\t\teditor\n\t\t\t\t\t.chain()\n\t\t\t\t\t.focus()\n\t\t\t\t\t.deleteRange(range)\n\t\t\t\t\t.insertContent({\n\t\t\t\t\t\ttype: 'mentionAgent',\n\t\t\t\t\t\tattrs: { id: props.id, label: props.label },\n\t\t\t\t\t})\n\t\t\t\t\t.run();\n\t\t\t\tonSelect?.(props, '@');\n\t\t\t},\n\t\t\trender: buildRender(onSelect, '@', renderItem, renderDropdown),\n\t\t},\n\t});\n}\n\nexport function buildTeamMentionExtension(\n\tteamsRef: { current: MentionItem[] },\n\tonSelect?: (item: MentionItem, char: '@' | '#') => void,\n\trenderItem?: (item: MentionItem, isActive: boolean) => ReactNode,\n\trenderDropdown?: (props: MentionDropdownRenderProps) => ReactNode,\n) {\n\treturn Mention.extend({ name: 'mentionTeam' }).configure({\n\t\tHTMLAttributes: { class: 'bik-mention bik-mention--team' },\n\t\trenderText: ({ options, node }) =>\n\t\t\t`${options.suggestion.char}${node.attrs['label']}`,\n\t\trenderHTML: ({ options, node }) => [\n\t\t\t'span',\n\t\t\tmergeAttributes(options.HTMLAttributes),\n\t\t\t`${options.suggestion.char}${node.attrs['label']}`,\n\t\t],\n\t\tsuggestion: {\n\t\t\tchar: '#',\n\t\t\titems: ({ query }: { query: string }) =>\n\t\t\t\tteamsRef.current.filter((t) =>\n\t\t\t\t\tt.label.toLowerCase().includes(query.toLowerCase()),\n\t\t\t\t),\n\t\t\tcommand: ({ editor, range, props }: any) => {\n\t\t\t\teditor\n\t\t\t\t\t.chain()\n\t\t\t\t\t.focus()\n\t\t\t\t\t.deleteRange(range)\n\t\t\t\t\t.insertContent({\n\t\t\t\t\t\ttype: 'mentionTeam',\n\t\t\t\t\t\tattrs: { id: props.id, label: props.label },\n\t\t\t\t\t})\n\t\t\t\t\t.run();\n\t\t\t\tonSelect?.(props, '#');\n\t\t\t},\n\t\t\trender: buildRender(onSelect, '#', renderItem, renderDropdown),\n\t\t},\n\t});\n}\n"],"names":["buildRender","onSelect","renderItem","arguments","length","undefined","renderDropdown","component","popup","onStart","props","ReactRenderer","MentionDropdown","editor","createSuggestionPopup","element","clientRect","onUpdate","updateProps","Object","assign","_a","items","show","updatePosition","hide","onKeyDown","event","key","_b","ref","onExit","destroy","buildAgentMentionExtension","agentsRef","Mention","extend","name","configure","HTMLAttributes","class","renderText","_ref","options","node","suggestion","char","attrs","renderHTML","_ref2","mergeAttributes","_ref3","query","current","filter","a","label","toLowerCase","includes","command","_ref4","range","chain","focus","deleteRange","insertContent","type","id","run","render","buildTeamMentionExtension","teamsRef","_ref5","_ref6","_ref7","t","_ref8"],"mappings":"+RAcA,SAASA,EACRC,GACqB,IACrBC,EAAgEC,UAAAC,OAAAD,EAAAA,kBAAAE,EAChEC,EAAiEH,UAAAC,OAAAD,EAAAA,kBAAAE,EAEjE,MAAO,KACN,IAAIE,EACAC,EAEJ,MAAO,CACNC,QAAUC,IACTH,EAAY,IAAII,EAAcC,EAAiB,CAC9CF,qCAAYA,GAAK,CAAER,aAAYI,mBAC/BO,OAAQH,EAAMG,SAEfL,EAAQM,EAAsBP,EAAUQ,QAASL,EAAMM,WAAW,EAEnEC,SAAWP,UACVH,EAAUW,YAAiBC,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EAAAV,IAAOR,aAAYI,qBAC9B,QAAXe,EAAAX,EAAMY,aAAK,IAAAD,OAAA,EAAAA,EAAEjB,SAIlBI,EAAMe,OACNf,EAAMgB,eAAed,EAAMM,aAJ1BR,EAAMiB,MAI+B,EAEvCC,UAAYhB,YACX,MAAwB,WAApBA,EAAMiB,MAAMC,KACfpB,EAAMiB,QACC,GAE2C,QAA5CI,EAAsB,QAAtBR,EAACd,EAAUuB,WAAW,IAAAT,OAAA,EAAAA,EAAEK,UAAUhB,UAAU,IAAAmB,GAAAA,CAAK,EAEzDE,OAAQA,KACPvB,EAAMwB,UACNzB,EAAUyB,SAAS,EAEpB,CAEH,CAEM,SAAUC,EACfC,EACAjC,EACAC,EACAI,GAEA,OAAO6B,EAAQC,OAAO,CAAEC,KAAM,iBAAkBC,UAAU,CACzDC,eAAgB,CAAEC,MAAO,kCACzBC,WAAYC,IAAA,IAACC,QAAEA,EAAOC,KAAEA,GAAMF,EAAA,MAC7B,GAAGC,EAAQE,WAAWC,OAAOF,EAAKG,MAAa,OAAG,EACnDC,WAAYC,IAAA,IAACN,QAAEA,EAAOC,KAAEA,GAAMK,EAAA,MAAK,CAClC,OACAC,EAAgBP,EAAQJ,gBACxB,GAAGI,EAAQE,WAAWC,OAAOF,EAAKG,MAAa,QAC/C,EACDF,WAAY,CACXC,KAAM,
|
|
1
|
+
{"version":3,"file":"MentionExtension.js","sources":["../../../../../src/editor/extensions/mention/MentionExtension.ts"],"sourcesContent":["import { mergeAttributes } from '@tiptap/core';\nimport Mention from '@tiptap/extension-mention';\nimport { ReactRenderer } from '@tiptap/react';\nimport type { ReactNode } from 'react';\nimport type {\n\tMentionDropdownRenderProps,\n\tMentionItem,\n} from '../../BikEditor.types';\nimport {\n\tcreateSuggestionPopup,\n\ttype SuggestionPopup,\n} from '../suggestionPopup';\nimport { MentionDropdown } from './MentionDropdown';\n\nfunction buildRender(\n\tonSelect?: (item: MentionItem, char: '@' | '#') => void,\n\tchar: '@' | '#' = '@',\n\trenderItem?: (item: MentionItem, isActive: boolean) => ReactNode,\n\trenderDropdown?: (props: MentionDropdownRenderProps) => ReactNode,\n) {\n\treturn () => {\n\t\tlet component: ReactRenderer;\n\t\tlet popup: SuggestionPopup;\n\n\t\treturn {\n\t\t\tonStart: (props: any) => {\n\t\t\t\tcomponent = new ReactRenderer(MentionDropdown, {\n\t\t\t\t\tprops: { ...props, renderItem, renderDropdown },\n\t\t\t\t\teditor: props.editor,\n\t\t\t\t});\n\t\t\t\tpopup = createSuggestionPopup(component.element, props.clientRect);\n\t\t\t},\n\t\t\tonUpdate: (props: any) => {\n\t\t\t\tcomponent.updateProps({ ...props, renderItem, renderDropdown });\n\t\t\t\tif (!props.items?.length) {\n\t\t\t\t\tpopup.hide();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tpopup.show();\n\t\t\t\tpopup.updatePosition(props.clientRect);\n\t\t\t},\n\t\t\tonKeyDown: (props: any) => {\n\t\t\t\tif (props.event.key === 'Escape') {\n\t\t\t\t\tpopup.hide();\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\treturn (component.ref as any)?.onKeyDown(props) ?? false;\n\t\t\t},\n\t\t\tonExit: () => {\n\t\t\t\tpopup.destroy();\n\t\t\t\tcomponent.destroy();\n\t\t\t},\n\t\t};\n\t};\n}\n\nexport function buildAgentMentionExtension(\n\tagentsRef: { current: MentionItem[] },\n\tonSelect?: (item: MentionItem, char: '@' | '#') => void,\n\trenderItem?: (item: MentionItem, isActive: boolean) => ReactNode,\n\trenderDropdown?: (props: MentionDropdownRenderProps) => ReactNode,\n) {\n\treturn Mention.extend({ name: 'mentionAgent' }).configure({\n\t\tHTMLAttributes: { class: 'bik-mention bik-mention--agent' },\n\t\trenderText: ({ options, node }) =>\n\t\t\t`${options.suggestion.char}${node.attrs['label']}`,\n\t\trenderHTML: ({ options, node }) => [\n\t\t\t'span',\n\t\t\tmergeAttributes(options.HTMLAttributes),\n\t\t\t`${options.suggestion.char}${node.attrs['label']}`,\n\t\t],\n\t\tsuggestion: {\n\t\t\tchar: '@',\n\t\t\tallowSpaces: true,\n\t\t\titems: ({ query }: { query: string }) =>\n\t\t\t\tagentsRef.current.filter((a) =>\n\t\t\t\t\ta.label.toLowerCase().includes(query.toLowerCase()),\n\t\t\t\t),\n\t\t\tcommand: ({ editor, range, props }: any) => {\n\t\t\t\teditor\n\t\t\t\t\t.chain()\n\t\t\t\t\t.focus()\n\t\t\t\t\t.deleteRange(range)\n\t\t\t\t\t.insertContent({\n\t\t\t\t\t\ttype: 'mentionAgent',\n\t\t\t\t\t\tattrs: { id: props.id, label: props.label },\n\t\t\t\t\t})\n\t\t\t\t\t.run();\n\t\t\t\tonSelect?.(props, '@');\n\t\t\t},\n\t\t\trender: buildRender(onSelect, '@', renderItem, renderDropdown),\n\t\t},\n\t});\n}\n\nexport function buildTeamMentionExtension(\n\tteamsRef: { current: MentionItem[] },\n\tonSelect?: (item: MentionItem, char: '@' | '#') => void,\n\trenderItem?: (item: MentionItem, isActive: boolean) => ReactNode,\n\trenderDropdown?: (props: MentionDropdownRenderProps) => ReactNode,\n) {\n\treturn Mention.extend({ name: 'mentionTeam' }).configure({\n\t\tHTMLAttributes: { class: 'bik-mention bik-mention--team' },\n\t\trenderText: ({ options, node }) =>\n\t\t\t`${options.suggestion.char}${node.attrs['label']}`,\n\t\trenderHTML: ({ options, node }) => [\n\t\t\t'span',\n\t\t\tmergeAttributes(options.HTMLAttributes),\n\t\t\t`${options.suggestion.char}${node.attrs['label']}`,\n\t\t],\n\t\tsuggestion: {\n\t\t\tchar: '#',\n\t\t\tallowSpaces: true,\n\t\t\titems: ({ query }: { query: string }) =>\n\t\t\t\tteamsRef.current.filter((t) =>\n\t\t\t\t\tt.label.toLowerCase().includes(query.toLowerCase()),\n\t\t\t\t),\n\t\t\tcommand: ({ editor, range, props }: any) => {\n\t\t\t\teditor\n\t\t\t\t\t.chain()\n\t\t\t\t\t.focus()\n\t\t\t\t\t.deleteRange(range)\n\t\t\t\t\t.insertContent({\n\t\t\t\t\t\ttype: 'mentionTeam',\n\t\t\t\t\t\tattrs: { id: props.id, label: props.label },\n\t\t\t\t\t})\n\t\t\t\t\t.run();\n\t\t\t\tonSelect?.(props, '#');\n\t\t\t},\n\t\t\trender: buildRender(onSelect, '#', renderItem, renderDropdown),\n\t\t},\n\t});\n}\n"],"names":["buildRender","onSelect","renderItem","arguments","length","undefined","renderDropdown","component","popup","onStart","props","ReactRenderer","MentionDropdown","editor","createSuggestionPopup","element","clientRect","onUpdate","updateProps","Object","assign","_a","items","show","updatePosition","hide","onKeyDown","event","key","_b","ref","onExit","destroy","buildAgentMentionExtension","agentsRef","Mention","extend","name","configure","HTMLAttributes","class","renderText","_ref","options","node","suggestion","char","attrs","renderHTML","_ref2","mergeAttributes","allowSpaces","_ref3","query","current","filter","a","label","toLowerCase","includes","command","_ref4","range","chain","focus","deleteRange","insertContent","type","id","run","render","buildTeamMentionExtension","teamsRef","_ref5","_ref6","_ref7","t","_ref8"],"mappings":"+RAcA,SAASA,EACRC,GACqB,IACrBC,EAAgEC,UAAAC,OAAAD,EAAAA,kBAAAE,EAChEC,EAAiEH,UAAAC,OAAAD,EAAAA,kBAAAE,EAEjE,MAAO,KACN,IAAIE,EACAC,EAEJ,MAAO,CACNC,QAAUC,IACTH,EAAY,IAAII,EAAcC,EAAiB,CAC9CF,qCAAYA,GAAK,CAAER,aAAYI,mBAC/BO,OAAQH,EAAMG,SAEfL,EAAQM,EAAsBP,EAAUQ,QAASL,EAAMM,WAAW,EAEnEC,SAAWP,UACVH,EAAUW,YAAiBC,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EAAAV,IAAOR,aAAYI,qBAC9B,QAAXe,EAAAX,EAAMY,aAAK,IAAAD,OAAA,EAAAA,EAAEjB,SAIlBI,EAAMe,OACNf,EAAMgB,eAAed,EAAMM,aAJ1BR,EAAMiB,MAI+B,EAEvCC,UAAYhB,YACX,MAAwB,WAApBA,EAAMiB,MAAMC,KACfpB,EAAMiB,QACC,GAE2C,QAA5CI,EAAsB,QAAtBR,EAACd,EAAUuB,WAAW,IAAAT,OAAA,EAAAA,EAAEK,UAAUhB,UAAU,IAAAmB,GAAAA,CAAK,EAEzDE,OAAQA,KACPvB,EAAMwB,UACNzB,EAAUyB,SAAS,EAEpB,CAEH,CAEM,SAAUC,EACfC,EACAjC,EACAC,EACAI,GAEA,OAAO6B,EAAQC,OAAO,CAAEC,KAAM,iBAAkBC,UAAU,CACzDC,eAAgB,CAAEC,MAAO,kCACzBC,WAAYC,IAAA,IAACC,QAAEA,EAAOC,KAAEA,GAAMF,EAAA,MAC7B,GAAGC,EAAQE,WAAWC,OAAOF,EAAKG,MAAa,OAAG,EACnDC,WAAYC,IAAA,IAACN,QAAEA,EAAOC,KAAEA,GAAMK,E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YH,GACZI,cAAc,CACdC,KAAM,cACNpB,MAAO,CAAEqB,GAAI1D,EAAM0D,GAAIX,MAAO/C,EAAM+C,SAEpCY,MACFpE,SAAAA,EAAWS,EAAO,IAAI,EAEvB4D,OAAQtE,EAAYC,EAAU,IAAKC,EAAYI,KAGlD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Extension as t}from"../../../node_modules/@tiptap/core/dist/index.js";import{Slice as
|
|
1
|
+
import{Extension as t}from"../../../node_modules/@tiptap/core/dist/index.js";import{DOMParser as e,Slice as o,Fragment as n}from"@tiptap/pm/model";import{Plugin as r}from"@tiptap/pm/state";function a(t){const e=[];return t.forEach((t=>{t.isText?e.push(t.mark([])):e.push(t.copy(a(t.content)))})),n.from(e)}const i=t.create({name:"plainClipboard",addProseMirrorPlugins:()=>[new r({props:{handlePaste(t,r){var i,l,s,c;if(null===(l=null===(i=r.clipboardData)||void 0===i?void 0:i.files)||void 0===l?void 0:l.length)return!1;const p=null===(s=r.clipboardData)||void 0===s?void 0:s.getData("text/html"),d=null===(c=r.clipboardData)||void 0===c?void 0:c.getData("text/plain");if(!d)return!1;if(console.log("[PASTE-DEBUG] clipboard html:",p),console.log("[PASTE-DEBUG] clipboard text:",JSON.stringify(d)),console.log("[PASTE-DEBUG] has data-pm-slice:",null==p?void 0:p.includes("data-pm-slice")),null==p?void 0:p.includes("data-pm-slice"))return console.log("[PASTE-DEBUG] → returning false, letting ProseMirror handle"),!1;const m=t.state.schema;if(p){const n=document.createElement("div");n.innerHTML=p;const r=e.fromSchema(m).parseSlice(n),i=new o(a(r.content),r.openStart,r.openEnd);return t.dispatch(t.state.tr.replaceSelection(i)),!0}const u=d.split("\n").map((t=>m.node("paragraph",null,t?[m.text(t)]:[]))),f=new o(n.fromArray(u),1,1);return t.dispatch(t.state.tr.replaceSelection(f)),!0}}})]});export{i as PlainClipboardExtension};
|
|
2
2
|
//# sourceMappingURL=PlainClipboardExtension.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlainClipboardExtension.js","sources":["../../../../../src/editor/extensions/plainClipboard/PlainClipboardExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport {
|
|
1
|
+
{"version":3,"file":"PlainClipboardExtension.js","sources":["../../../../../src/editor/extensions/plainClipboard/PlainClipboardExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport {\n\tFragment,\n\tNode as PMNode,\n\tDOMParser as ProseMirrorDOMParser,\n\tSlice,\n} from '@tiptap/pm/model';\nimport { Plugin } from '@tiptap/pm/state';\n\nfunction stripMarks(fragment: Fragment): Fragment {\n\tconst nodes: PMNode[] = [];\n\tfragment.forEach((node) => {\n\t\tif (node.isText) {\n\t\t\tnodes.push(node.mark([]));\n\t\t} else {\n\t\t\tnodes.push(node.copy(stripMarks(node.content)));\n\t\t}\n\t});\n\treturn Fragment.from(nodes);\n}\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; // let ImagePaste handle\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\tconsole.log('[PASTE-DEBUG] clipboard html:', html);\n\t\t\t\t\t\tconsole.log('[PASTE-DEBUG] clipboard text:', JSON.stringify(text));\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t'[PASTE-DEBUG] has data-pm-slice:',\n\t\t\t\t\t\t\thtml?.includes('data-pm-slice'),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// ProseMirror stamps its own clipboard with data-pm-slice.\n\t\t\t\t\t\t// Let ProseMirror handle its own format natively — it round-trips perfectly.\n\t\t\t\t\t\tif (html?.includes('data-pm-slice')) {\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t'[PASTE-DEBUG] → returning false, letting ProseMirror handle',\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\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\t// Parse the HTML to get the correct block structure,\n\t\t\t\t\t\t\t// then strip all inline marks (bold, italic, links, etc.)\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 parsed =\n\t\t\t\t\t\t\t\tProseMirrorDOMParser.fromSchema(schema).parseSlice(container);\n\t\t\t\t\t\t\tconst stripped = new Slice(\n\t\t\t\t\t\t\t\tstripMarks(parsed.content),\n\t\t\t\t\t\t\t\tparsed.openStart,\n\t\t\t\t\t\t\t\tparsed.openEnd,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t_view.dispatch(_view.state.tr.replaceSelection(stripped));\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Plain text only (no HTML): split on newlines\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":["stripMarks","fragment","nodes","forEach","node","isText","push","mark","copy","content","Fragment","from","PlainClipboardExtension","Extension","create","name","addProseMirrorPlugins","Plugin","props","handlePaste","_view","event","_b","clipboardData","_a","files","length","html","_c","getData","text","_d","console","log","JSON","stringify","includes","schema","state","container","document","createElement","innerHTML","parsed","ProseMirrorDOMParser","fromSchema","parseSlice","stripped","Slice","openStart","openEnd","dispatch","tr","replaceSelection","paragraphs","split","map","line","slice","fromArray"],"mappings":"6LASA,SAASA,EAAWC,GACnB,MAAMC,EAAkB,GAQxB,OAPAD,EAASE,SAASC,IACbA,EAAKC,OACRH,EAAMI,KAAKF,EAAKG,KAAK,KAErBL,EAAMI,KAAKF,EAAKI,KAAKR,EAAWI,EAAKK,UACrC,IAEKC,EAASC,KAAKT,EACtB,OAEaU,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,EAWlB,GATAE,QAAQC,IAAI,gCAAiCN,GAC7CK,QAAQC,IAAI,gCAAiCC,KAAKC,UAAUL,IAC5DE,QAAQC,IACP,mCACAN,aAAA,EAAAA,EAAMS,SAAS,kBAKZT,aAAA,EAAAA,EAAMS,SAAS,iBAIlB,OAHAJ,QAAQC,IACP,gEAEM,EAGR,MAAMI,EAASjB,EAAMkB,MAAMD,OAE3B,GAAIV,EAAM,CAGT,MAAMY,EAAYC,SAASC,cAAc,OACzCF,EAAUG,UAAYf,EACtB,MAAMgB,EACLC,EAAqBC,WAAWR,GAAQS,WAAWP,GAC9CQ,EAAW,IAAIC,EACpBhD,EAAW2C,EAAOlC,SAClBkC,EAAOM,UACPN,EAAOO,SAGR,OADA9B,EAAM+B,SAAS/B,EAAMkB,MAAMc,GAAGC,iBAAiBN,KACxC,CACP,CAGD,MAAMO,EAAaxB,EACjByB,MAAM,MACNC,KAAKC,GACLpB,EAAOjC,KAAK,YAAa,KAAMqD,EAAO,CAACpB,EAAOP,KAAK2B,IAAS,MAExDC,EAAQ,IAAIV,EAAMtC,EAASiD,UAAUL,GAAa,EAAG,GAE3D,OADAlC,EAAM+B,SAAS/B,EAAMkB,MAAMc,GAAGC,iBAAiBK,KACxC,CACR"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Extension as e}from"../../../node_modules/@tiptap/core/dist/index.js";import{ReactRenderer as r}from"@tiptap/react";import t from"@tiptap/suggestion";import{createSuggestionPopup as o}from"../suggestionPopup.js";import{SlashCommandMenu as n}from"./SlashCommandMenu.js";function i(i,s,d,a){return e.create({name:"slashCommand",addProseMirrorPlugins(){return[t({editor:this.editor,char:"/",items:e=>{let{query:r}=e;return i.current.filter((e=>e.label.toLowerCase().includes(r.toLowerCase()))).slice(0,20)},command:e=>{let{editor:r,range:t,props:o}=e;r.chain().focus().deleteRange(t).run(),null==s||s(o)},render:()=>{let e,t;return{onStart:i=>{e=new r(n,{props:Object.assign(Object.assign({},i),{renderItem:d,renderDropdown:a}),editor:i.editor}),t=o(e.element,i.clientRect)},onUpdate:r=>{var o;e.updateProps(Object.assign(Object.assign({},r),{renderItem:d,renderDropdown:a})),(null===(o=r.items)||void 0===o?void 0:o.length)?(t.show(),t.updatePosition(r.clientRect)):t.hide()},onKeyDown:r=>{var o,n;return"Escape"===r.event.key?(t.hide(),!0):null!==(n=null===(o=e.ref)||void 0===o?void 0:o.onKeyDown(r))&&void 0!==n&&n},onExit:()=>{t.destroy(),e.destroy()}}}})]}})}export{i as buildSlashCommandExtension};
|
|
1
|
+
import{Extension as e}from"../../../node_modules/@tiptap/core/dist/index.js";import{ReactRenderer as r}from"@tiptap/react";import t from"@tiptap/suggestion";import{createSuggestionPopup as o}from"../suggestionPopup.js";import{SlashCommandMenu as n}from"./SlashCommandMenu.js";function i(i,s,d,a){return e.create({name:"slashCommand",addProseMirrorPlugins(){return[t({editor:this.editor,char:"/",allowSpaces:!0,items:e=>{let{query:r}=e;return i.current.filter((e=>e.label.toLowerCase().includes(r.toLowerCase()))).slice(0,20)},command:e=>{let{editor:r,range:t,props:o}=e;r.chain().focus().deleteRange(t).run(),null==s||s(o)},render:()=>{let e,t;return{onStart:i=>{e=new r(n,{props:Object.assign(Object.assign({},i),{renderItem:d,renderDropdown:a}),editor:i.editor}),t=o(e.element,i.clientRect)},onUpdate:r=>{var o;e.updateProps(Object.assign(Object.assign({},r),{renderItem:d,renderDropdown:a})),(null===(o=r.items)||void 0===o?void 0:o.length)?(t.show(),t.updatePosition(r.clientRect)):t.hide()},onKeyDown:r=>{var o,n;return"Escape"===r.event.key?(t.hide(),!0):null!==(n=null===(o=e.ref)||void 0===o?void 0:o.onKeyDown(r))&&void 0!==n&&n},onExit:()=>{t.destroy(),e.destroy()}}}})]}})}export{i as buildSlashCommandExtension};
|
|
2
2
|
//# sourceMappingURL=SlashCommandExtension.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SlashCommandExtension.js","sources":["../../../../../src/editor/extensions/slashCommand/SlashCommandExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport { ReactRenderer } from '@tiptap/react';\nimport Suggestion from '@tiptap/suggestion';\nimport type { ReactNode } from 'react';\nimport type {\n\tSlashCommandDropdownRenderProps,\n\tSlashCommandItem,\n} from '../../BikEditor.types';\nimport {\n\tcreateSuggestionPopup,\n\ttype SuggestionPopup,\n} from '../suggestionPopup';\nimport { SlashCommandMenu } from './SlashCommandMenu';\n\nexport function buildSlashCommandExtension(\n\tcommandsRef: { current: SlashCommandItem[] },\n\tonSelect?: (command: SlashCommandItem) => void,\n\trenderItem?: (item: SlashCommandItem, isActive: boolean) => ReactNode,\n\trenderDropdown?: (props: SlashCommandDropdownRenderProps) => ReactNode,\n) {\n\treturn Extension.create({\n\t\tname: 'slashCommand',\n\t\taddProseMirrorPlugins() {\n\t\t\treturn [\n\t\t\t\tSuggestion({\n\t\t\t\t\teditor: this.editor,\n\t\t\t\t\tchar: '/',\n\t\t\t\t\titems: ({ query }: any) =>\n\t\t\t\t\t\tcommandsRef.current\n\t\t\t\t\t\t\t.filter((c) =>\n\t\t\t\t\t\t\t\tc.label.toLowerCase().includes(query.toLowerCase()),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.slice(0, 20),\n\t\t\t\t\tcommand: ({ editor, range, props }: any) => {\n\t\t\t\t\t\teditor.chain().focus().deleteRange(range).run();\n\t\t\t\t\t\tonSelect?.(props);\n\t\t\t\t\t},\n\t\t\t\t\trender: () => {\n\t\t\t\t\t\tlet component: ReactRenderer;\n\t\t\t\t\t\tlet popup: SuggestionPopup;\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tonStart: (props: any) => {\n\t\t\t\t\t\t\t\tcomponent = new ReactRenderer(SlashCommandMenu, {\n\t\t\t\t\t\t\t\t\tprops: { ...props, renderItem, renderDropdown },\n\t\t\t\t\t\t\t\t\teditor: props.editor,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tpopup = createSuggestionPopup(\n\t\t\t\t\t\t\t\t\tcomponent.element,\n\t\t\t\t\t\t\t\t\tprops.clientRect,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonUpdate: (props: any) => {\n\t\t\t\t\t\t\t\tcomponent.updateProps({ ...props, renderItem, renderDropdown });\n\t\t\t\t\t\t\t\tif (!props.items?.length) {\n\t\t\t\t\t\t\t\t\tpopup.hide();\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tpopup.show();\n\t\t\t\t\t\t\t\tpopup.updatePosition(props.clientRect);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonKeyDown: (props: any) => {\n\t\t\t\t\t\t\t\tif (props.event.key === 'Escape') {\n\t\t\t\t\t\t\t\t\tpopup.hide();\n\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn (component.ref as any)?.onKeyDown(props) ?? false;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonExit: () => {\n\t\t\t\t\t\t\t\tpopup.destroy();\n\t\t\t\t\t\t\t\tcomponent.destroy();\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t];\n\t\t},\n\t});\n}\n"],"names":["buildSlashCommandExtension","commandsRef","onSelect","renderItem","renderDropdown","Extension","create","name","addProseMirrorPlugins","Suggestion","editor","this","char","items","_ref","query","current","filter","c","label","toLowerCase","includes","slice","command","_ref2","range","props","chain","focus","deleteRange","run","render","component","popup","onStart","ReactRenderer","SlashCommandMenu","createSuggestionPopup","element","clientRect","onUpdate","updateProps","Object","assign","_a","length","show","updatePosition","hide","onKeyDown","event","key","_b","ref","onExit","destroy"],"mappings":"oRAcM,SAAUA,EACfC,EACAC,EACAC,EACAC,GAEA,OAAOC,EAAUC,OAAO,CACvBC,KAAM,eACNC,wBACC,MAAO,CACNC,EAAW,CACVC,OAAQC,KAAKD,OACbE,KAAM,IACNC,MAAOC,IAAA,IAACC,MAAEA,GAAYD,EAAA,
|
|
1
|
+
{"version":3,"file":"SlashCommandExtension.js","sources":["../../../../../src/editor/extensions/slashCommand/SlashCommandExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport { ReactRenderer } from '@tiptap/react';\nimport Suggestion from '@tiptap/suggestion';\nimport type { ReactNode } from 'react';\nimport type {\n\tSlashCommandDropdownRenderProps,\n\tSlashCommandItem,\n} from '../../BikEditor.types';\nimport {\n\tcreateSuggestionPopup,\n\ttype SuggestionPopup,\n} from '../suggestionPopup';\nimport { SlashCommandMenu } from './SlashCommandMenu';\n\nexport function buildSlashCommandExtension(\n\tcommandsRef: { current: SlashCommandItem[] },\n\tonSelect?: (command: SlashCommandItem) => void,\n\trenderItem?: (item: SlashCommandItem, isActive: boolean) => ReactNode,\n\trenderDropdown?: (props: SlashCommandDropdownRenderProps) => ReactNode,\n) {\n\treturn Extension.create({\n\t\tname: 'slashCommand',\n\t\taddProseMirrorPlugins() {\n\t\t\treturn [\n\t\t\t\tSuggestion({\n\t\t\t\t\teditor: this.editor,\n\t\t\t\t\tchar: '/',\n\t\t\t\t\tallowSpaces: true,\n\t\t\t\t\titems: ({ query }: any) =>\n\t\t\t\t\t\tcommandsRef.current\n\t\t\t\t\t\t\t.filter((c) =>\n\t\t\t\t\t\t\t\tc.label.toLowerCase().includes(query.toLowerCase()),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.slice(0, 20),\n\t\t\t\t\tcommand: ({ editor, range, props }: any) => {\n\t\t\t\t\t\teditor.chain().focus().deleteRange(range).run();\n\t\t\t\t\t\tonSelect?.(props);\n\t\t\t\t\t},\n\t\t\t\t\trender: () => {\n\t\t\t\t\t\tlet component: ReactRenderer;\n\t\t\t\t\t\tlet popup: SuggestionPopup;\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tonStart: (props: any) => {\n\t\t\t\t\t\t\t\tcomponent = new ReactRenderer(SlashCommandMenu, {\n\t\t\t\t\t\t\t\t\tprops: { ...props, renderItem, renderDropdown },\n\t\t\t\t\t\t\t\t\teditor: props.editor,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tpopup = createSuggestionPopup(\n\t\t\t\t\t\t\t\t\tcomponent.element,\n\t\t\t\t\t\t\t\t\tprops.clientRect,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonUpdate: (props: any) => {\n\t\t\t\t\t\t\t\tcomponent.updateProps({ ...props, renderItem, renderDropdown });\n\t\t\t\t\t\t\t\tif (!props.items?.length) {\n\t\t\t\t\t\t\t\t\tpopup.hide();\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tpopup.show();\n\t\t\t\t\t\t\t\tpopup.updatePosition(props.clientRect);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonKeyDown: (props: any) => {\n\t\t\t\t\t\t\t\tif (props.event.key === 'Escape') {\n\t\t\t\t\t\t\t\t\tpopup.hide();\n\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn (component.ref as any)?.onKeyDown(props) ?? false;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonExit: () => {\n\t\t\t\t\t\t\t\tpopup.destroy();\n\t\t\t\t\t\t\t\tcomponent.destroy();\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t];\n\t\t},\n\t});\n}\n"],"names":["buildSlashCommandExtension","commandsRef","onSelect","renderItem","renderDropdown","Extension","create","name","addProseMirrorPlugins","Suggestion","editor","this","char","allowSpaces","items","_ref","query","current","filter","c","label","toLowerCase","includes","slice","command","_ref2","range","props","chain","focus","deleteRange","run","render","component","popup","onStart","ReactRenderer","SlashCommandMenu","createSuggestionPopup","element","clientRect","onUpdate","updateProps","Object","assign","_a","length","show","updatePosition","hide","onKeyDown","event","key","_b","ref","onExit","destroy"],"mappings":"oRAcM,SAAUA,EACfC,EACAC,EACAC,EACAC,GAEA,OAAOC,EAAUC,OAAO,CACvBC,KAAM,eACNC,wBACC,MAAO,CACNC,EAAW,CACVC,OAAQC,KAAKD,OACbE,KAAM,IACNC,aAAa,EACbC,MAAOC,IAAA,IAACC,MAAEA,GAAYD,EAAA,OACrBd,EAAYgB,QACVC,QAAQC,GACRA,EAAEC,MAAMC,cAAcC,SAASN,EAAMK,iBAErCE,MAAM,EAAG,GAAG,EACfC,QAASC,IAAkC,IAAjCf,OAAEA,EAAMgB,MAAEA,EAAKC,MAAEA,GAAYF,EACtCf,EAAOkB,QAAQC,QAAQC,YAAYJ,GAAOK,MAC1C7B,SAAAA,EAAWyB,EAAM,EAElBK,OAAQA,KACP,IAAIC,EACAC,EAEJ,MAAO,CACNC,QAAUR,IACTM,EAAY,IAAIG,EAAcC,EAAkB,CAC/CV,qCAAYA,GAAK,CAAExB,aAAYC,mBAC/BM,OAAQiB,EAAMjB,SAEfwB,EAAQI,EACPL,EAAUM,QACVZ,EAAMa,WACN,EAEFC,SAAWd,UACVM,EAAUS,YAAiBC,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EAAAjB,IAAOxB,aAAYC,qBAC9B,QAAXyC,EAAAlB,EAAMb,aAAK,IAAA+B,OAAA,EAAAA,EAAEC,SAIlBZ,EAAMa,OACNb,EAAMc,eAAerB,EAAMa,aAJ1BN,EAAMe,MAI+B,EAEvCC,UAAYvB,YACX,MAAwB,WAApBA,EAAMwB,MAAMC,KACflB,EAAMe,QACC,GAE2C,QAA5CI,EAAsB,QAAtBR,EAACZ,EAAUqB,WAAW,IAAAT,OAAA,EAAAA,EAAEK,UAAUvB,UAAU,IAAA0B,GAAAA,CAAK,EAEzDE,OAAQA,KACPrB,EAAMsB,UACNvB,EAAUuB,SAAS,EAEpB,IAIL,GAEF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e){if(!e)return"";if("undefined"!=typeof document){return r((new DOMParser).parseFromString(e,"text/html").body).replace(/\n{3,}/g,"\n\n").trim()}return function(e){return e.replace(/<strong[^>]*>([\s\S]*?)<\/strong>/gi,"*$1*").replace(/<b[^>]*>([\s\S]*?)<\/b>/gi,"*$1*").replace(/<em[^>]*>([\s\S]*?)<\/em>/gi,"_$1_").replace(/<i[^>]*>([\s\S]*?)<\/i>/gi,"_$1_").replace(/<s[^>]*>([\s\S]*?)<\/s>/gi,"~$1~").replace(/<del[^>]*>([\s\S]*?)<\/del>/gi,"~$1~").replace(/<code[^>]*>([\s\S]*?)<\/code>/gi,"`$1`").replace(/<a[^>]
|
|
1
|
+
function e(e){if(!e)return"";if("undefined"!=typeof document){return r((new DOMParser).parseFromString(e,"text/html").body).replace(/\n{3,}/g,"\n\n").trim()}return function(e){return e.replace(/<strong[^>]*>([\s\S]*?)<\/strong>/gi,"*$1*").replace(/<b[^>]*>([\s\S]*?)<\/b>/gi,"*$1*").replace(/<em[^>]*>([\s\S]*?)<\/em>/gi,"_$1_").replace(/<i[^>]*>([\s\S]*?)<\/i>/gi,"_$1_").replace(/<s[^>]*>([\s\S]*?)<\/s>/gi,"~$1~").replace(/<del[^>]*>([\s\S]*?)<\/del>/gi,"~$1~").replace(/<code[^>]*>([\s\S]*?)<\/code>/gi,"`$1`").replace(/<a[^>]*>([\s\S]*?)<\/a>/gi,"$1").replace(/<br\s*\/?>/gi,"\n").replace(/<\/p>/gi,"\n").replace(/<\/div>/gi,"\n").replace(/<\/h[1-6]>/gi,"\n").replace(/<li[^>]*>/gi,"• ").replace(/<\/li>/gi,"\n").replace(/<[^>]+>/g,"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/ /g," ").replace(/\n{3,}/g,"\n\n").trim()}(e)}function r(e){var n;if(e.nodeType===Node.TEXT_NODE)return null!==(n=e.textContent)&&void 0!==n?n:"";if(e.nodeType!==Node.ELEMENT_NODE)return"";const a=e,c=a.tagName.toLowerCase(),t=function(e){return Array.from(e.childNodes).map(r).join("")}(a);switch(c){case"strong":case"b":return t?`*${t}*`:"";case"em":case"i":return t?`_${t}_`:"";case"s":case"del":case"strike":return t?`~${t}~`:"";case"code":return t?`\`${t}\``:"";case"pre":return t?`\`\`\`${t}\`\`\``:"";case"a":case"ul":case"ol":case"body":default:return t;case"br":return"\n";case"p":case"div":return t?`${t}\n`:"\n";case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":return t?`*${t}*\n`:"\n";case"li":return`• ${t.trimEnd()}\n`;case"blockquote":return t.split("\n").map((e=>e?`> ${e}`:"")).join("\n")+"\n"}}export{e as toWhatsAppText};
|
|
2
2
|
//# sourceMappingURL=toWhatsAppText.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toWhatsAppText.js","sources":["../../../../src/editor/serializers/toWhatsAppText.ts"],"sourcesContent":["/**\n * Converts TipTap HTML to WhatsApp-flavoured markdown text.\n *\n * WhatsApp formatting:\n * *bold* _italic_ ~strikethrough~ ```monospace```\n *\n * Links: WhatsApp does not support
|
|
1
|
+
{"version":3,"file":"toWhatsAppText.js","sources":["../../../../src/editor/serializers/toWhatsAppText.ts"],"sourcesContent":["/**\n * Converts TipTap HTML to WhatsApp-flavoured markdown text.\n *\n * WhatsApp formatting:\n * *bold* _italic_ ~strikethrough~ ```monospace```\n *\n * Links: WhatsApp does not support hyperlinks.\n * <a href=\"https://…\">Visit us</a> → Visit us (display text kept, href dropped)\n *\n * @example\n * const { html } = ref.current?.getContent();\n * const waText = toWhatsAppText(html);\n * sendWhatsApp({ text: waText });\n */\nexport function toWhatsAppText(html: string): string {\n\tif (!html) return '';\n\n\tif (typeof document !== 'undefined') {\n\t\tconst doc = new DOMParser().parseFromString(html, 'text/html');\n\t\treturn serializeNode(doc.body)\n\t\t\t.replace(/\\n{3,}/g, '\\n\\n')\n\t\t\t.trim();\n\t}\n\n\t// SSR / Node.js fallback — handles simple non-nested markup\n\treturn ssrFallback(html);\n}\n\n// ---------------------------------------------------------------------------\n// Browser path — DOM-based, handles nested marks correctly\n// ---------------------------------------------------------------------------\n\nfunction serializeNode(node: Node): string {\n\tif (node.nodeType === Node.TEXT_NODE) {\n\t\treturn node.textContent ?? '';\n\t}\n\tif (node.nodeType !== Node.ELEMENT_NODE) return '';\n\n\tconst el = node as Element;\n\tconst tag = el.tagName.toLowerCase();\n\tconst inner = serializeChildren(el);\n\n\tswitch (tag) {\n\t\tcase 'strong':\n\t\tcase 'b':\n\t\t\treturn inner ? `*${inner}*` : '';\n\n\t\tcase 'em':\n\t\tcase 'i':\n\t\t\treturn inner ? `_${inner}_` : '';\n\n\t\tcase 's':\n\t\tcase 'del':\n\t\tcase 'strike':\n\t\t\treturn inner ? `~${inner}~` : '';\n\n\t\tcase 'code':\n\t\t\treturn inner ? `\\`${inner}\\`` : '';\n\n\t\tcase 'pre':\n\t\t\treturn inner ? `\\`\\`\\`${inner}\\`\\`\\`` : '';\n\n\t\tcase 'a':\n\t\t\treturn inner;\n\n\t\tcase 'br':\n\t\t\treturn '\\n';\n\n\t\tcase 'p':\n\t\tcase 'div':\n\t\t\treturn inner ? `${inner}\\n` : '\\n';\n\n\t\tcase 'h1':\n\t\tcase 'h2':\n\t\tcase 'h3':\n\t\tcase 'h4':\n\t\tcase 'h5':\n\t\tcase 'h6':\n\t\t\treturn inner ? `*${inner}*\\n` : '\\n';\n\n\t\tcase 'ul':\n\t\tcase 'ol':\n\t\t\treturn inner;\n\n\t\tcase 'li':\n\t\t\treturn `• ${inner.trimEnd()}\\n`;\n\n\t\tcase 'blockquote':\n\t\t\treturn (\n\t\t\t\tinner\n\t\t\t\t\t.split('\\n')\n\t\t\t\t\t.map((l) => (l ? `> ${l}` : ''))\n\t\t\t\t\t.join('\\n') + '\\n'\n\t\t\t);\n\n\t\tcase 'body':\n\t\tdefault:\n\t\t\treturn inner;\n\t}\n}\n\nfunction serializeChildren(el: Element): string {\n\treturn Array.from(el.childNodes).map(serializeNode).join('');\n}\n\n// ---------------------------------------------------------------------------\n// SSR fallback — regex-based, best-effort for simple markup\n// ---------------------------------------------------------------------------\n\nfunction ssrFallback(html: string): string {\n\treturn html\n\t\t.replace(/<strong[^>]*>([\\s\\S]*?)<\\/strong>/gi, '*$1*')\n\t\t.replace(/<b[^>]*>([\\s\\S]*?)<\\/b>/gi, '*$1*')\n\t\t.replace(/<em[^>]*>([\\s\\S]*?)<\\/em>/gi, '_$1_')\n\t\t.replace(/<i[^>]*>([\\s\\S]*?)<\\/i>/gi, '_$1_')\n\t\t.replace(/<s[^>]*>([\\s\\S]*?)<\\/s>/gi, '~$1~')\n\t\t.replace(/<del[^>]*>([\\s\\S]*?)<\\/del>/gi, '~$1~')\n\t\t.replace(/<code[^>]*>([\\s\\S]*?)<\\/code>/gi, '`$1`')\n\t\t.replace(/<a[^>]*>([\\s\\S]*?)<\\/a>/gi, '$1')\n\t\t.replace(/<br\\s*\\/?>/gi, '\\n')\n\t\t.replace(/<\\/p>/gi, '\\n')\n\t\t.replace(/<\\/div>/gi, '\\n')\n\t\t.replace(/<\\/h[1-6]>/gi, '\\n')\n\t\t.replace(/<li[^>]*>/gi, '• ')\n\t\t.replace(/<\\/li>/gi, '\\n')\n\t\t.replace(/<[^>]+>/g, '')\n\t\t.replace(/&/g, '&')\n\t\t.replace(/</g, '<')\n\t\t.replace(/>/g, '>')\n\t\t.replace(/ /g, ' ')\n\t\t.replace(/\\n{3,}/g, '\\n\\n')\n\t\t.trim();\n}\n"],"names":["toWhatsAppText","html","document","serializeNode","DOMParser","parseFromString","body","replace","trim","ssrFallback","node","nodeType","Node","TEXT_NODE","textContent","_a","ELEMENT_NODE","el","tag","tagName","toLowerCase","inner","Array","from","childNodes","map","join","serializeChildren","trimEnd","split","l"],"mappings":"AAcM,SAAUA,EAAeC,GAC9B,IAAKA,EAAM,MAAO,GAElB,GAAwB,oBAAbC,SAA0B,CAEpC,OAAOC,GADK,IAAIC,WAAYC,gBAAgBJ,EAAM,aACzBK,MACvBC,QAAQ,UAAW,QACnBC,MACF,CAGD,OAoFD,SAAqBP,GACpB,OAAOA,EACLM,QAAQ,sCAAuC,QAC/CA,QAAQ,4BAA6B,QACrCA,QAAQ,8BAA+B,QACvCA,QAAQ,4BAA6B,QACrCA,QAAQ,4BAA6B,QACrCA,QAAQ,gCAAiC,QACzCA,QAAQ,kCAAmC,QAC3CA,QAAQ,4BAA6B,MACrCA,QAAQ,eAAgB,MACxBA,QAAQ,UAAW,MACnBA,QAAQ,YAAa,MACrBA,QAAQ,eAAgB,MACxBA,QAAQ,cAAe,MACvBA,QAAQ,WAAY,MACpBA,QAAQ,WAAY,IACpBA,QAAQ,SAAU,KAClBA,QAAQ,QAAS,KACjBA,QAAQ,QAAS,KACjBA,QAAQ,UAAW,KACnBA,QAAQ,UA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
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* paragraph. ProseMirror adds only the trailing decoration, giving the correct
|
|
14
|
-
* 1× line height. The WA text output is unchanged (`\n` either way after
|
|
15
|
-
* surrounding-newline collapse in `toWhatsAppText`).
|
|
6
|
+
* Empty paragraphs containing only a `<br>` (e.g. `<p><br></p>` or
|
|
7
|
+
* `<p style="..."><br></p>`) are removed entirely. ProseMirror adds a
|
|
8
|
+
* trailing `<br>` to every empty paragraph in the DOM for cursor
|
|
9
|
+
* positioning, so stripping just the `<br>` and leaving `<p></p>`
|
|
10
|
+
* doesn't work — the paragraph still renders with height. Removing
|
|
11
|
+
* the whole element avoids creating a node at all. This is in sync
|
|
12
|
+
* with how Gmail renders HTML.
|
|
16
13
|
*/
|
|
17
14
|
export declare function normalizeHtml(html: string): string;
|
|
18
15
|
/**
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* WhatsApp formatting:
|
|
5
5
|
* *bold* _italic_ ~strikethrough~ ```monospace```
|
|
6
6
|
*
|
|
7
|
-
* Links: WhatsApp does not support
|
|
8
|
-
* <a href="https://…">Visit us</a> →
|
|
7
|
+
* Links: WhatsApp does not support hyperlinks.
|
|
8
|
+
* <a href="https://…">Visit us</a> → Visit us (display text kept, href dropped)
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* const { html } = ref.current?.getContent();
|