@bikdotai/bik-component-library 0.0.809-beta.10 → 0.0.809-beta.11
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.styles.js +12 -2
- package/dist/cjs/editor/BikEditor.styles.js.map +1 -1
- package/dist/cjs/editor/extensions/plainClipboard/PasteNormalizationExtension.js +1 -1
- package/dist/cjs/editor/extensions/plainClipboard/PasteNormalizationExtension.js.map +1 -1
- package/dist/cjs/editor/extensions/plainClipboard/pasteUtils.js +1 -1
- package/dist/cjs/editor/extensions/plainClipboard/pasteUtils.js.map +1 -1
- package/dist/cjs/src/editor/extensions/plainClipboard/PasteNormalizationExtension.d.ts +3 -0
- package/dist/esm/editor/BikEditor.styles.js +17 -7
- package/dist/esm/editor/BikEditor.styles.js.map +1 -1
- package/dist/esm/editor/extensions/plainClipboard/PasteNormalizationExtension.js +1 -1
- package/dist/esm/editor/extensions/plainClipboard/PasteNormalizationExtension.js.map +1 -1
- package/dist/esm/editor/extensions/plainClipboard/pasteUtils.js +1 -1
- package/dist/esm/editor/extensions/plainClipboard/pasteUtils.js.map +1 -1
- package/dist/esm/src/editor/extensions/plainClipboard/PasteNormalizationExtension.d.ts +3 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("styled-components"),t=require("../constants/Theme.js");function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("styled-components"),t=require("../constants/Theme.js");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}const n=r(e).default.div`
|
|
2
2
|
position: relative;
|
|
3
3
|
width: 100%;
|
|
4
4
|
|
|
@@ -23,6 +23,16 @@
|
|
|
23
23
|
margin-top: ${e=>{let{paragraphGap:t}=e;return null!=t?t:"4px"}};
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/* Blank lines (empty paragraphs) get their height from line-height
|
|
27
|
+
alone — no extra margins. Prevents double-spacing when paragraphGap
|
|
28
|
+
is large (e.g. 1em for email). */
|
|
29
|
+
p.is-blank {
|
|
30
|
+
margin-top: 0;
|
|
31
|
+
}
|
|
32
|
+
p.is-blank + p {
|
|
33
|
+
margin-top: 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
ul,
|
|
27
37
|
ol {
|
|
28
38
|
margin: 0;
|
|
@@ -64,5 +74,5 @@
|
|
|
64
74
|
text-decoration-color: #6366f1;
|
|
65
75
|
}
|
|
66
76
|
}
|
|
67
|
-
`;exports.BikEditorShell=
|
|
77
|
+
`;exports.BikEditorShell=n;
|
|
68
78
|
//# sourceMappingURL=BikEditor.styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BikEditor.styles.js","sources":["../../../src/editor/BikEditor.styles.ts"],"sourcesContent":["import styled from 'styled-components';\nimport { COLORS } from '../constants/Theme';\n\nexport const BikEditorShell = styled.div<{\n\tminHeight?: string;\n\tmaxHeight?: string;\n\tparagraphGap?: string;\n}>`\n\tposition: relative;\n\twidth: 100%;\n\n\t.ProseMirror {\n\t\tmin-height: ${({ minHeight }) => minHeight ?? '80px'};\n\t\tmax-height: ${({ maxHeight }) => maxHeight ?? 'none'};\n\t\toverflow-y: auto;\n\t\toutline: none;\n\t\tpadding: 8px 12px;\n\t\tfont-size: 14px;\n\t\tline-height: 1.5;\n\t\tword-break: break-word;\n\n\t\tp {\n\t\t\tmargin: 0;\n\t\t\tpadding: 0;\n\t\t}\n\n\t\t/* Enter = new paragraph → visible gap. Shift+Enter = <br> inside\n\t\t the same paragraph → no gap. Matches Google Docs / Word behavior. */\n\t\tp + p {\n\t\t\tmargin-top: ${({ paragraphGap }) => paragraphGap ?? '4px'};\n\t\t}\n\n\t\tul,\n\t\tol {\n\t\t\tmargin: 0;\n\t\t\tpadding-left: 1.5em;\n\t\t}\n\n\t\tli + li {\n\t\t\tmargin-top: 2px;\n\t\t}\n\n\t\tp.is-editor-empty:first-child::before {\n\t\t\tcontent: attr(data-placeholder);\n\t\t\tfloat: left;\n\t\t\tcolor: #adb5bd;\n\t\t\tpointer-events: none;\n\t\t\theight: 0;\n\t\t}\n\t}\n\n\t.bik-mention {\n\t\tcolor: ${COLORS.content.brand};\n\t\tpadding: 1px 4px;\n\t}\n\t.bik-mention--team {\n\t\tcolor: ${COLORS.content.brand};\n\t}\n\t.bik-variable {\n\t}\n\n\ta,\n\t.bik-link {\n\t\tcolor: #4f46e5;\n\t\ttext-decoration: underline;\n\t\ttext-decoration-color: #a5b4fc;\n\t\ttext-underline-offset: 2px;\n\t\tcursor: pointer;\n\t\t&:hover {\n\t\t\tcolor: #3730a3;\n\t\t\ttext-decoration-color: #6366f1;\n\t\t}\n\t}\n`;\n"],"names":["BikEditorShell","div","_ref","minHeight","_ref2","maxHeight","_ref3","paragraphGap","COLORS","content","brand"],"mappings":"kNAGaA,MAAAA,OAAuB,QAACC,GAInC;;;;;gBAKcC,IAAA,IAACC,UAAEA,GAAWD,EAAA,OAAKC,QAAAA,EAAa,MAAM;gBACtCC,IAAA,IAACC,UAAEA,GAAWD,EAAA,OAAKC,QAAAA,EAAa,MAAM;;;;;;;;;;;;;;;;iBAgBrCC,IAAA,IAACC,aAAEA,GAAcD,EAAA,OAAKC,QAAAA,EAAgB,KAAK
|
|
1
|
+
{"version":3,"file":"BikEditor.styles.js","sources":["../../../src/editor/BikEditor.styles.ts"],"sourcesContent":["import styled from 'styled-components';\nimport { COLORS } from '../constants/Theme';\n\nexport const BikEditorShell = styled.div<{\n\tminHeight?: string;\n\tmaxHeight?: string;\n\tparagraphGap?: string;\n}>`\n\tposition: relative;\n\twidth: 100%;\n\n\t.ProseMirror {\n\t\tmin-height: ${({ minHeight }) => minHeight ?? '80px'};\n\t\tmax-height: ${({ maxHeight }) => maxHeight ?? 'none'};\n\t\toverflow-y: auto;\n\t\toutline: none;\n\t\tpadding: 8px 12px;\n\t\tfont-size: 14px;\n\t\tline-height: 1.5;\n\t\tword-break: break-word;\n\n\t\tp {\n\t\t\tmargin: 0;\n\t\t\tpadding: 0;\n\t\t}\n\n\t\t/* Enter = new paragraph → visible gap. Shift+Enter = <br> inside\n\t\t the same paragraph → no gap. Matches Google Docs / Word behavior. */\n\t\tp + p {\n\t\t\tmargin-top: ${({ paragraphGap }) => paragraphGap ?? '4px'};\n\t\t}\n\n\t\t/* Blank lines (empty paragraphs) get their height from line-height\n\t\t alone — no extra margins. Prevents double-spacing when paragraphGap\n\t\t is large (e.g. 1em for email). */\n\t\tp.is-blank {\n\t\t\tmargin-top: 0;\n\t\t}\n\t\tp.is-blank + p {\n\t\t\tmargin-top: 0;\n\t\t}\n\n\t\tul,\n\t\tol {\n\t\t\tmargin: 0;\n\t\t\tpadding-left: 1.5em;\n\t\t}\n\n\t\tli + li {\n\t\t\tmargin-top: 2px;\n\t\t}\n\n\t\tp.is-editor-empty:first-child::before {\n\t\t\tcontent: attr(data-placeholder);\n\t\t\tfloat: left;\n\t\t\tcolor: #adb5bd;\n\t\t\tpointer-events: none;\n\t\t\theight: 0;\n\t\t}\n\t}\n\n\t.bik-mention {\n\t\tcolor: ${COLORS.content.brand};\n\t\tpadding: 1px 4px;\n\t}\n\t.bik-mention--team {\n\t\tcolor: ${COLORS.content.brand};\n\t}\n\t.bik-variable {\n\t}\n\n\ta,\n\t.bik-link {\n\t\tcolor: #4f46e5;\n\t\ttext-decoration: underline;\n\t\ttext-decoration-color: #a5b4fc;\n\t\ttext-underline-offset: 2px;\n\t\tcursor: pointer;\n\t\t&:hover {\n\t\t\tcolor: #3730a3;\n\t\t\ttext-decoration-color: #6366f1;\n\t\t}\n\t}\n`;\n"],"names":["BikEditorShell","div","_ref","minHeight","_ref2","maxHeight","_ref3","paragraphGap","COLORS","content","brand"],"mappings":"kNAGaA,MAAAA,OAAuB,QAACC,GAInC;;;;;gBAKcC,IAAA,IAACC,UAAEA,GAAWD,EAAA,OAAKC,QAAAA,EAAa,MAAM;gBACtCC,IAAA,IAACC,UAAEA,GAAWD,EAAA,OAAKC,QAAAA,EAAa,MAAM;;;;;;;;;;;;;;;;iBAgBrCC,IAAA,IAACC,aAAEA,GAAcD,EAAA,OAAKC,QAAAA,EAAgB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAiCjDC,EAAMA,OAACC,QAAQC;;;;WAIfF,EAAMA,OAACC,QAAQC;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../node_modules/@tiptap/core/dist/index.js"),r=require("@tiptap/pm/model"),t=require("@tiptap/pm/state"),s=require("./pasteUtils.js");const a=e.Extension.create({name:"pasteNormalization",addOptions:()=>({preserveMarks:!1}),addProseMirrorPlugins(){const e=this.options.preserveMarks;return[new t.Plugin({props:{
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../node_modules/@tiptap/core/dist/index.js"),r=require("@tiptap/pm/model"),t=require("@tiptap/pm/state"),s=require("@tiptap/pm/view"),n=require("./pasteUtils.js");const a=e.Extension.create({name:"pasteNormalization",addOptions:()=>({preserveMarks:!1}),addProseMirrorPlugins(){const e=this.options.preserveMarks;return[new t.Plugin({props:{decorations(e){const r=[];return e.doc.descendants(((e,t)=>{"paragraph"===e.type.name&&0===e.childCount&&r.push(s.Decoration.node(t,t+e.nodeSize,{class:"is-blank"}))})),s.DecorationSet.create(e.doc,r)},clipboardTextParser:(e,r,t,s)=>n.parseClipboardText(e,s.state.schema),transformPastedHTML(e){if(e.includes("data-pm-slice"))return e;const r=document.createElement("div");return r.innerHTML=e,n.cleanBlockBrs(r),n.stripTrailingBrs(r),r.innerHTML},transformPasted(t){let s=n.normalizeHardBreaks(t.content);return e||(s=n.stripRichMarks(s)),new r.Slice(s,t.openStart,t.openEnd)}}})]}});exports.PasteNormalizationExtension=a;
|
|
2
2
|
//# sourceMappingURL=PasteNormalizationExtension.js.map
|
|
@@ -1 +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 {\n\tcleanBlockBrs,\n\tnormalizeHardBreaks,\n\tparseClipboardText,\n\
|
|
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} 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\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\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","clipboardTextParser","text","_$context","_plain","view","parseClipboardText","schema","transformPastedHTML","html","includes","container","document","createElement","innerHTML","cleanBlockBrs","stripTrailingBrs","transformPasted","slice","content","normalizeHardBreaks","stripRichMarks","Slice","openStart","openEnd"],"mappings":"kQAuBaA,EAA8BC,EAASA,UAACC,OAAO,CAC3DC,KAAM,qBACNC,WAAUA,KACF,CACNC,eAAe,IAGjBC,wBACC,MAAMD,EAAgBE,KAAKC,QAAQH,cACnC,MAAO,CACN,IAAII,EAAAA,OAAO,CACVC,MAAO,CACNC,YAAYC,GACX,MAAMD,EAA4B,GAUlC,OATAC,EAAMC,IAAIC,aAAY,CAACC,EAAMC,KACL,cAAnBD,EAAKE,KAAKd,MAA4C,IAApBY,EAAKG,YAC1CP,EAAYQ,KACXC,aAAWL,KAAKC,EAAKA,EAAMD,EAAKM,SAAU,CACzCC,MAAO,aAGT,IAEKC,EAAaA,cAACrB,OAAOU,EAAMC,IAAKF,EACvC,EAEDa,oBAAmBA,CAACC,EAAMC,EAAWC,EAAQC,IACrCC,EAAkBA,mBAACJ,EAAMG,EAAKhB,MAAMkB,QAG5CC,oBAAoBC,GACnB,GAAIA,EAAKC,SAAS,iBAAkB,OAAOD,EAC3C,MAAME,EAAYC,SAASC,cAAc,OAIzC,OAHAF,EAAUG,UAAYL,EACtBM,EAAaA,cAACJ,GACdK,EAAgBA,iBAACL,GACVA,EAAUG,SACjB,EAEDG,gBAAgBC,GACf,IAAIC,EAAUC,EAAAA,oBAAoBF,EAAMC,SAIxC,OAHKrC,IACJqC,EAAUE,EAAAA,eAAeF,IAEnB,IAAIG,EAAKA,MAACH,EAASD,EAAMK,UAAWL,EAAMM,QAClD,KAIJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@tiptap/pm/model");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@tiptap/pm/model");const t=new Set(["P","LI","H1","H2","H3","H4","H5","H6","TD","TH","PRE"]),r=new Set(["bold","italic","strike","underline","code"]);exports.TEXTBLOCK_TAGS=t,exports.cleanBlockBrs=function(e){const r=Array.from(e.querySelectorAll("br"));for(const n of r){let r=!1,o=n.parentElement;for(;o&&o!==e;){if(t.has(o.tagName)){r=!0;break}o=o.parentElement}r||n.parentElement.replaceChild(document.createElement("p"),n)}},exports.normalizeHardBreaks=function t(r){const n=[];return r.forEach((r=>{var o,a;if("paragraph"===r.type.name){if(1===r.childCount&&"hardBreak"===(null===(o=r.firstChild)||void 0===o?void 0:o.type.name))return void n.push(r.type.create(r.attrs));if(r.childCount>1&&"hardBreak"===(null===(a=r.lastChild)||void 0===a?void 0:a.type.name)){const t=[];return r.content.forEach(((e,n,o)=>{o<r.childCount-1&&t.push(e)})),void n.push(r.copy(e.Fragment.from(t)))}}r.isBlock&&!r.isLeaf?n.push(r.copy(t(r.content))):n.push(r)})),e.Fragment.from(n)},exports.parseClipboardText=function(t,r){const n=t.split("\n").map((e=>r.node("paragraph",null,e?[r.text(e)]:[])));return new e.Slice(e.Fragment.fromArray(n),1,1)},exports.stripRichMarks=function t(n){const o=[];return n.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(t(e.content)))})),e.Fragment.from(o)},exports.stripTrailingBrs=function(e){for(const t of["p","div"])for(const r of Array.from(e.querySelectorAll(t))){const e=r.lastElementChild;"BR"===(null==e?void 0:e.tagName)&&r.childNodes.length>1&&e.remove()}};
|
|
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, 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 * 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 using double-newline as paragraph separator\n * and single newline as a line break (<br>) within a paragraph. Produces\n * the same structure as Gmail's Cmd+V output.\n *\n * Best for channels with CSS-based paragraph gaps (e.g. email) where the\n * margin between `<p>` tags already provides visual separation.\n */\nexport function parseClipboardTextAsParagraphs(\n\ttext: string,\n\tschema: Schema,\n): Slice {\n\tconst trimmed = text.replace(/\\n+$/, '');\n\tconst blocks = trimmed.split(/\\n\\n+/);\n\tconst hardBreak = schema.nodes['hardBreak'];\n\tconst paragraphs = blocks.map((block) => {\n\t\tconst lines = block.split('\\n');\n\t\tconst children: PMNode[] = [];\n\t\tlines.forEach((line, i) => {\n\t\t\tif (line) children.push(schema.text(line));\n\t\t\tif (i < lines.length - 1 && hardBreak) {\n\t\t\t\tchildren.push(hardBreak.create());\n\t\t\t}\n\t\t});\n\t\treturn schema.node('paragraph', null, children.length ? children : []);\n\t});\n\treturn new Slice(Fragment.fromArray(paragraphs), 1, 1);\n}\n"],"names":["TEXTBLOCK_TAGS","Set","BASIC_MARKS","container","brs","Array","from","querySelectorAll","br","insideTextblock","el","parentElement","has","tagName","replaceChild","document","createElement","normalizeHardBreaks","fragment","nodes","forEach","node","type","name","childCount","_a","firstChild","push","create","attrs","_b","lastChild","children","content","child","_offset","index","copy","Fragment","isBlock","isLeaf","text","schema","paragraphs","split","map","line","Slice","fromArray","
|
|
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 * 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 using double-newline as paragraph separator\n * and single newline as a line break (<br>) within a paragraph. Produces\n * the same structure as Gmail's Cmd+V output.\n *\n * Best for channels with CSS-based paragraph gaps (e.g. email) where the\n * margin between `<p>` tags already provides visual separation.\n */\nexport function parseClipboardTextAsParagraphs(\n\ttext: string,\n\tschema: Schema,\n): Slice {\n\tconst trimmed = text.replace(/\\n+$/, '');\n\tconst blocks = trimmed.split(/\\n\\n+/);\n\tconst hardBreak = schema.nodes['hardBreak'];\n\tconst paragraphs = blocks.map((block) => {\n\t\tconst lines = block.split('\\n');\n\t\tconst children: PMNode[] = [];\n\t\tlines.forEach((line, i) => {\n\t\t\tif (line) children.push(schema.text(line));\n\t\t\tif (i < lines.length - 1 && hardBreak) {\n\t\t\t\tchildren.push(hardBreak.create());\n\t\t\t}\n\t\t});\n\t\treturn schema.node('paragraph', null, children.length ? children : []);\n\t});\n\treturn new Slice(Fragment.fromArray(paragraphs), 1, 1);\n}\n"],"names":["TEXTBLOCK_TAGS","Set","BASIC_MARKS","container","brs","Array","from","querySelectorAll","br","insideTextblock","el","parentElement","has","tagName","replaceChild","document","createElement","normalizeHardBreaks","fragment","nodes","forEach","node","type","name","childCount","_a","firstChild","push","create","attrs","_b","lastChild","children","content","child","_offset","index","copy","Fragment","isBlock","isLeaf","text","schema","paragraphs","split","map","line","Slice","fromArray","stripRichMarks","isText","kept","marks","filter","m","length","mark","tag","last","lastElementChild","childNodes","remove"],"mappings":"sGAEaA,MAAAA,EAAiB,IAAIC,IAAI,CACrC,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,QAMKC,EAAc,IAAID,IAAI,CAAC,OAAQ,SAAU,SAAU,YAAa,wDAOhE,SAAwBE,GAC7B,MAAMC,EAAMC,MAAMC,KAAKH,EAAUI,iBAAiB,OAClD,IAAK,MAAMC,KAAMJ,EAAK,CACrB,IAAIK,GAAkB,EAClBC,EAAKF,EAAGG,cACZ,KAAOD,GAAMA,IAAOP,GAAW,CAC9B,GAAIH,EAAeY,IAAIF,EAAGG,SAAU,CACnCJ,GAAkB,EAClB,KACA,CACDC,EAAKA,EAAGC,aACR,CACIF,GACJD,EAAGG,cAAeG,aAAaC,SAASC,cAAc,KAAMR,EAE7D,CACF,8BA2BM,SAAUS,EAAoBC,GACnC,MAAMC,EAAkB,GAsBxB,OArBAD,EAASE,SAASC,YACjB,GAAuB,cAAnBA,EAAKC,KAAKC,KAAsB,CACnC,GAAwB,IAApBF,EAAKG,YAAmD,eAAd,QAAjBC,EAAAJ,EAAKK,kBAAY,IAAAD,OAAA,EAAAA,EAAAH,KAAKC,MAElD,YADAJ,EAAMQ,KAAKN,EAAKC,KAAKM,OAAOP,EAAKQ,QAGlC,GAAIR,EAAKG,WAAa,GAAmC,eAAd,QAAhBM,EAAAT,EAAKU,iBAAW,IAAAD,OAAA,EAAAA,EAAAR,KAAKC,MAAsB,CACrE,MAAMS,EAAqB,GAK3B,OAJAX,EAAKY,QAAQb,SAAQ,CAACc,EAAOC,EAASC,KACjCA,EAAQf,EAAKG,WAAa,GAAGQ,EAASL,KAAKO,EAAM,SAEtDf,EAAMQ,KAAKN,EAAKgB,KAAKC,EAAQA,SAAChC,KAAK0B,IAEnC,CACD,CACGX,EAAKkB,UAAYlB,EAAKmB,OACzBrB,EAAMQ,KAAKN,EAAKgB,KAAKpB,EAAoBI,EAAKY,WAE9Cd,EAAMQ,KAAKN,EACX,IAEKiB,EAAQA,SAAChC,KAAKa,EACtB,6BA4BgB,SAAmBsB,EAAcC,GAChD,MAAMC,EAAaF,EACjBG,MAAM,MACNC,KAAKC,GACLJ,EAAOrB,KAAK,YAAa,KAAMyB,EAAO,CAACJ,EAAOD,KAAKK,IAAS,MAE9D,OAAO,IAAIC,EAAKA,MAACT,WAASU,UAAUL,GAAa,EAAG,EACrD,yBA5BM,SAAUM,EAAe/B,GAC9B,MAAMC,EAAkB,GASxB,OARAD,EAASE,SAASC,IACjB,GAAIA,EAAK6B,OAAQ,CAChB,MAAMC,EAAO9B,EAAK+B,MAAMC,QAAQC,GAAMpD,EAAYU,IAAI0C,EAAEhC,KAAKC,QAC7DJ,EAAMQ,KAAKwB,EAAKI,SAAWlC,EAAK+B,MAAMG,OAASlC,EAAOA,EAAKmC,KAAKL,GAChE,MACAhC,EAAMQ,KAAKN,EAAKgB,KAAKY,EAAe5B,EAAKY,UACzC,IAEKK,EAAQA,SAAChC,KAAKa,EACtB,2BA7DM,SAA2BhB,GAChC,IAAK,MAAMsD,IAAO,CAAC,IAAK,OACvB,IAAK,MAAM/C,KAAML,MAAMC,KAAKH,EAAUI,iBAAiBkD,IAAO,CAC7D,MAAMC,EAAOhD,EAAGiD,iBACM,QAAlBD,aAAA,EAAAA,EAAM7C,UAAoBH,EAAGkD,WAAWL,OAAS,GACpDG,EAAKG,QAEN,CAEH"}
|
|
@@ -6,5 +6,8 @@ import { Extension } from '@tiptap/core';
|
|
|
6
6
|
* - clipboardTextParser: plain text → Slice (preserves blank lines)
|
|
7
7
|
* - transformPastedHTML: HTML → HTML (cleans Google Docs / Word artifacts)
|
|
8
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.
|
|
9
12
|
*/
|
|
10
13
|
export declare const PasteNormalizationExtension: Extension<any, any>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import e from"styled-components";import{COLORS as
|
|
1
|
+
import e from"styled-components";import{COLORS as t}from"../constants/Theme.js";const r=e.div`
|
|
2
2
|
position: relative;
|
|
3
3
|
width: 100%;
|
|
4
4
|
|
|
5
5
|
.ProseMirror {
|
|
6
|
-
min-height: ${e=>{let{minHeight:
|
|
7
|
-
max-height: ${e=>{let{maxHeight:
|
|
6
|
+
min-height: ${e=>{let{minHeight:t}=e;return null!=t?t:"80px"}};
|
|
7
|
+
max-height: ${e=>{let{maxHeight:t}=e;return null!=t?t:"none"}};
|
|
8
8
|
overflow-y: auto;
|
|
9
9
|
outline: none;
|
|
10
10
|
padding: 8px 12px;
|
|
@@ -20,7 +20,17 @@ import e from"styled-components";import{COLORS as o}from"../constants/Theme.js";
|
|
|
20
20
|
/* Enter = new paragraph → visible gap. Shift+Enter = <br> inside
|
|
21
21
|
the same paragraph → no gap. Matches Google Docs / Word behavior. */
|
|
22
22
|
p + p {
|
|
23
|
-
margin-top: ${e=>{let{paragraphGap:
|
|
23
|
+
margin-top: ${e=>{let{paragraphGap:t}=e;return null!=t?t:"4px"}};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* Blank lines (empty paragraphs) get their height from line-height
|
|
27
|
+
alone — no extra margins. Prevents double-spacing when paragraphGap
|
|
28
|
+
is large (e.g. 1em for email). */
|
|
29
|
+
p.is-blank {
|
|
30
|
+
margin-top: 0;
|
|
31
|
+
}
|
|
32
|
+
p.is-blank + p {
|
|
33
|
+
margin-top: 0;
|
|
24
34
|
}
|
|
25
35
|
|
|
26
36
|
ul,
|
|
@@ -43,11 +53,11 @@ import e from"styled-components";import{COLORS as o}from"../constants/Theme.js";
|
|
|
43
53
|
}
|
|
44
54
|
|
|
45
55
|
.bik-mention {
|
|
46
|
-
color: ${
|
|
56
|
+
color: ${t.content.brand};
|
|
47
57
|
padding: 1px 4px;
|
|
48
58
|
}
|
|
49
59
|
.bik-mention--team {
|
|
50
|
-
color: ${
|
|
60
|
+
color: ${t.content.brand};
|
|
51
61
|
}
|
|
52
62
|
.bik-variable {
|
|
53
63
|
}
|
|
@@ -64,5 +74,5 @@ import e from"styled-components";import{COLORS as o}from"../constants/Theme.js";
|
|
|
64
74
|
text-decoration-color: #6366f1;
|
|
65
75
|
}
|
|
66
76
|
}
|
|
67
|
-
`;export{
|
|
77
|
+
`;export{r as BikEditorShell};
|
|
68
78
|
//# sourceMappingURL=BikEditor.styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BikEditor.styles.js","sources":["../../../src/editor/BikEditor.styles.ts"],"sourcesContent":["import styled from 'styled-components';\nimport { COLORS } from '../constants/Theme';\n\nexport const BikEditorShell = styled.div<{\n\tminHeight?: string;\n\tmaxHeight?: string;\n\tparagraphGap?: string;\n}>`\n\tposition: relative;\n\twidth: 100%;\n\n\t.ProseMirror {\n\t\tmin-height: ${({ minHeight }) => minHeight ?? '80px'};\n\t\tmax-height: ${({ maxHeight }) => maxHeight ?? 'none'};\n\t\toverflow-y: auto;\n\t\toutline: none;\n\t\tpadding: 8px 12px;\n\t\tfont-size: 14px;\n\t\tline-height: 1.5;\n\t\tword-break: break-word;\n\n\t\tp {\n\t\t\tmargin: 0;\n\t\t\tpadding: 0;\n\t\t}\n\n\t\t/* Enter = new paragraph → visible gap. Shift+Enter = <br> inside\n\t\t the same paragraph → no gap. Matches Google Docs / Word behavior. */\n\t\tp + p {\n\t\t\tmargin-top: ${({ paragraphGap }) => paragraphGap ?? '4px'};\n\t\t}\n\n\t\tul,\n\t\tol {\n\t\t\tmargin: 0;\n\t\t\tpadding-left: 1.5em;\n\t\t}\n\n\t\tli + li {\n\t\t\tmargin-top: 2px;\n\t\t}\n\n\t\tp.is-editor-empty:first-child::before {\n\t\t\tcontent: attr(data-placeholder);\n\t\t\tfloat: left;\n\t\t\tcolor: #adb5bd;\n\t\t\tpointer-events: none;\n\t\t\theight: 0;\n\t\t}\n\t}\n\n\t.bik-mention {\n\t\tcolor: ${COLORS.content.brand};\n\t\tpadding: 1px 4px;\n\t}\n\t.bik-mention--team {\n\t\tcolor: ${COLORS.content.brand};\n\t}\n\t.bik-variable {\n\t}\n\n\ta,\n\t.bik-link {\n\t\tcolor: #4f46e5;\n\t\ttext-decoration: underline;\n\t\ttext-decoration-color: #a5b4fc;\n\t\ttext-underline-offset: 2px;\n\t\tcursor: pointer;\n\t\t&:hover {\n\t\t\tcolor: #3730a3;\n\t\t\ttext-decoration-color: #6366f1;\n\t\t}\n\t}\n`;\n"],"names":["BikEditorShell","styled","div","_ref","minHeight","_ref2","maxHeight","_ref3","paragraphGap","COLORS","content","brand"],"mappings":"gFAGaA,MAAAA,EAAiBC,EAAOC,GAInC;;;;;gBAKcC,IAAA,IAACC,UAAEA,GAAWD,EAAA,OAAKC,QAAAA,EAAa,MAAM;gBACtCC,IAAA,IAACC,UAAEA,GAAWD,EAAA,OAAKC,QAAAA,EAAa,MAAM;;;;;;;;;;;;;;;;iBAgBrCC,IAAA,IAACC,aAAEA,GAAcD,EAAA,OAAKC,QAAAA,EAAgB,KAAK
|
|
1
|
+
{"version":3,"file":"BikEditor.styles.js","sources":["../../../src/editor/BikEditor.styles.ts"],"sourcesContent":["import styled from 'styled-components';\nimport { COLORS } from '../constants/Theme';\n\nexport const BikEditorShell = styled.div<{\n\tminHeight?: string;\n\tmaxHeight?: string;\n\tparagraphGap?: string;\n}>`\n\tposition: relative;\n\twidth: 100%;\n\n\t.ProseMirror {\n\t\tmin-height: ${({ minHeight }) => minHeight ?? '80px'};\n\t\tmax-height: ${({ maxHeight }) => maxHeight ?? 'none'};\n\t\toverflow-y: auto;\n\t\toutline: none;\n\t\tpadding: 8px 12px;\n\t\tfont-size: 14px;\n\t\tline-height: 1.5;\n\t\tword-break: break-word;\n\n\t\tp {\n\t\t\tmargin: 0;\n\t\t\tpadding: 0;\n\t\t}\n\n\t\t/* Enter = new paragraph → visible gap. Shift+Enter = <br> inside\n\t\t the same paragraph → no gap. Matches Google Docs / Word behavior. */\n\t\tp + p {\n\t\t\tmargin-top: ${({ paragraphGap }) => paragraphGap ?? '4px'};\n\t\t}\n\n\t\t/* Blank lines (empty paragraphs) get their height from line-height\n\t\t alone — no extra margins. Prevents double-spacing when paragraphGap\n\t\t is large (e.g. 1em for email). */\n\t\tp.is-blank {\n\t\t\tmargin-top: 0;\n\t\t}\n\t\tp.is-blank + p {\n\t\t\tmargin-top: 0;\n\t\t}\n\n\t\tul,\n\t\tol {\n\t\t\tmargin: 0;\n\t\t\tpadding-left: 1.5em;\n\t\t}\n\n\t\tli + li {\n\t\t\tmargin-top: 2px;\n\t\t}\n\n\t\tp.is-editor-empty:first-child::before {\n\t\t\tcontent: attr(data-placeholder);\n\t\t\tfloat: left;\n\t\t\tcolor: #adb5bd;\n\t\t\tpointer-events: none;\n\t\t\theight: 0;\n\t\t}\n\t}\n\n\t.bik-mention {\n\t\tcolor: ${COLORS.content.brand};\n\t\tpadding: 1px 4px;\n\t}\n\t.bik-mention--team {\n\t\tcolor: ${COLORS.content.brand};\n\t}\n\t.bik-variable {\n\t}\n\n\ta,\n\t.bik-link {\n\t\tcolor: #4f46e5;\n\t\ttext-decoration: underline;\n\t\ttext-decoration-color: #a5b4fc;\n\t\ttext-underline-offset: 2px;\n\t\tcursor: pointer;\n\t\t&:hover {\n\t\t\tcolor: #3730a3;\n\t\t\ttext-decoration-color: #6366f1;\n\t\t}\n\t}\n`;\n"],"names":["BikEditorShell","styled","div","_ref","minHeight","_ref2","maxHeight","_ref3","paragraphGap","COLORS","content","brand"],"mappings":"gFAGaA,MAAAA,EAAiBC,EAAOC,GAInC;;;;;gBAKcC,IAAA,IAACC,UAAEA,GAAWD,EAAA,OAAKC,QAAAA,EAAa,MAAM;gBACtCC,IAAA,IAACC,UAAEA,GAAWD,EAAA,OAAKC,QAAAA,EAAa,MAAM;;;;;;;;;;;;;;;;iBAgBrCC,IAAA,IAACC,aAAEA,GAAcD,EAAA,OAAKC,QAAAA,EAAgB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAiCjDC,EAAOC,QAAQC;;;;WAIfF,EAAOC,QAAQC;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Extension as
|
|
1
|
+
import{Extension as e}from"../../../node_modules/@tiptap/core/dist/index.js";import{Slice as t}from"@tiptap/pm/model";import{Plugin as r}from"@tiptap/pm/state";import{Decoration as o,DecorationSet as n}from"@tiptap/pm/view";import{parseClipboardText as s,cleanBlockBrs as a,stripTrailingBrs as p,normalizeHardBreaks as i,stripRichMarks as d}from"./pasteUtils.js";const m=e.create({name:"pasteNormalization",addOptions:()=>({preserveMarks:!1}),addProseMirrorPlugins(){const e=this.options.preserveMarks;return[new r({props:{decorations(e){const t=[];return e.doc.descendants(((e,r)=>{"paragraph"===e.type.name&&0===e.childCount&&t.push(o.node(r,r+e.nodeSize,{class:"is-blank"}))})),n.create(e.doc,t)},clipboardTextParser:(e,t,r,o)=>s(e,o.state.schema),transformPastedHTML(e){if(e.includes("data-pm-slice"))return e;const t=document.createElement("div");return t.innerHTML=e,a(t),p(t),t.innerHTML},transformPasted(r){let o=i(r.content);return e||(o=d(o)),new t(o,r.openStart,r.openEnd)}}})]}});export{m as PasteNormalizationExtension};
|
|
2
2
|
//# sourceMappingURL=PasteNormalizationExtension.js.map
|
|
@@ -1 +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 {\n\tcleanBlockBrs,\n\tnormalizeHardBreaks,\n\tparseClipboardText,\n\
|
|
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} 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\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\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","clipboardTextParser","text","_$context","_plain","view","parseClipboardText","schema","transformPastedHTML","html","includes","container","document","createElement","innerHTML","cleanBlockBrs","stripTrailingBrs","transformPasted","slice","content","normalizeHardBreaks","stripRichMarks","Slice","openStart","openEnd"],"mappings":"iXAuBaA,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,oBAAmBA,CAACC,EAAMC,EAAWC,EAAQC,IACrCC,EAAmBJ,EAAMG,EAAKhB,MAAMkB,QAG5CC,oBAAoBC,GACnB,GAAIA,EAAKC,SAAS,iBAAkB,OAAOD,EAC3C,MAAME,EAAYC,SAASC,cAAc,OAIzC,OAHAF,EAAUG,UAAYL,EACtBM,EAAcJ,GACdK,EAAiBL,GACVA,EAAUG,SACjB,EAEDG,gBAAgBC,GACf,IAAIC,EAAUC,EAAoBF,EAAMC,SAIxC,OAHKrC,IACJqC,EAAUE,EAAeF,IAEnB,IAAIG,EAAMH,EAASD,EAAMK,UAAWL,EAAMM,QAClD,KAIJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Fragment as e,Slice as t}from"@tiptap/pm/model";const n=new Set(["P","LI","H1","H2","H3","H4","H5","H6","TD","TH","PRE"]),r=new Set(["bold","italic","strike","underline","code"]);function o(e){const t=Array.from(e.querySelectorAll("br"));for(const r of t){let t=!1,o=r.parentElement;for(;o&&o!==e;){if(n.has(o.tagName)){t=!0;break}o=o.parentElement}t||r.parentElement.replaceChild(document.createElement("p"),r)}}function a(e){for(const t of["p","div"])for(const n of Array.from(e.querySelectorAll(t))){const e=n.lastElementChild;"BR"===(null==e?void 0:e.tagName)&&n.childNodes.length>1&&e.remove()}}function l(t){const n=[];return t.forEach((t=>{var r,o;if("paragraph"===t.type.name){if(1===t.childCount&&"hardBreak"===(null===(r=t.firstChild)||void 0===r?void 0:r.type.name))return void n.push(t.type.create(t.attrs));if(t.childCount>1&&"hardBreak"===(null===(o=t.lastChild)||void 0===o?void 0:o.type.name)){const r=[];return t.content.forEach(((e,n,o)=>{o<t.childCount-1&&r.push(e)})),void n.push(t.copy(e.from(r)))}}t.isBlock&&!t.isLeaf?n.push(t.copy(l(t.content))):n.push(t)})),e.from(n)}function c(t){const n=[];return t.forEach((e=>{if(e.isText){const t=e.marks.filter((e=>r.has(e.type.name)));n.push(t.length===e.marks.length?e:e.mark(t))}else n.push(e.copy(c(e.content)))})),e.from(n)}function i(n,r){const o=n.split("\n").map((e=>r.node("paragraph",null,e?[r.text(e)]:[])));return new t(e.fromArray(o),1,1)}
|
|
1
|
+
import{Fragment as e,Slice as t}from"@tiptap/pm/model";const n=new Set(["P","LI","H1","H2","H3","H4","H5","H6","TD","TH","PRE"]),r=new Set(["bold","italic","strike","underline","code"]);function o(e){const t=Array.from(e.querySelectorAll("br"));for(const r of t){let t=!1,o=r.parentElement;for(;o&&o!==e;){if(n.has(o.tagName)){t=!0;break}o=o.parentElement}t||r.parentElement.replaceChild(document.createElement("p"),r)}}function a(e){for(const t of["p","div"])for(const n of Array.from(e.querySelectorAll(t))){const e=n.lastElementChild;"BR"===(null==e?void 0:e.tagName)&&n.childNodes.length>1&&e.remove()}}function l(t){const n=[];return t.forEach((t=>{var r,o;if("paragraph"===t.type.name){if(1===t.childCount&&"hardBreak"===(null===(r=t.firstChild)||void 0===r?void 0:r.type.name))return void n.push(t.type.create(t.attrs));if(t.childCount>1&&"hardBreak"===(null===(o=t.lastChild)||void 0===o?void 0:o.type.name)){const r=[];return t.content.forEach(((e,n,o)=>{o<t.childCount-1&&r.push(e)})),void n.push(t.copy(e.from(r)))}}t.isBlock&&!t.isLeaf?n.push(t.copy(l(t.content))):n.push(t)})),e.from(n)}function c(t){const n=[];return t.forEach((e=>{if(e.isText){const t=e.marks.filter((e=>r.has(e.type.name)));n.push(t.length===e.marks.length?e:e.mark(t))}else n.push(e.copy(c(e.content)))})),e.from(n)}function i(n,r){const o=n.split("\n").map((e=>r.node("paragraph",null,e?[r.text(e)]:[])));return new t(e.fromArray(o),1,1)}export{n as TEXTBLOCK_TAGS,o as cleanBlockBrs,l as normalizeHardBreaks,i as parseClipboardText,c as stripRichMarks,a as stripTrailingBrs};
|
|
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, 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 * 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 using double-newline as paragraph separator\n * and single newline as a line break (<br>) within a paragraph. Produces\n * the same structure as Gmail's Cmd+V output.\n *\n * Best for channels with CSS-based paragraph gaps (e.g. email) where the\n * margin between `<p>` tags already provides visual separation.\n */\nexport function parseClipboardTextAsParagraphs(\n\ttext: string,\n\tschema: Schema,\n): Slice {\n\tconst trimmed = text.replace(/\\n+$/, '');\n\tconst blocks = trimmed.split(/\\n\\n+/);\n\tconst hardBreak = schema.nodes['hardBreak'];\n\tconst paragraphs = blocks.map((block) => {\n\t\tconst lines = block.split('\\n');\n\t\tconst children: PMNode[] = [];\n\t\tlines.forEach((line, i) => {\n\t\t\tif (line) children.push(schema.text(line));\n\t\t\tif (i < lines.length - 1 && hardBreak) {\n\t\t\t\tchildren.push(hardBreak.create());\n\t\t\t}\n\t\t});\n\t\treturn schema.node('paragraph', null, children.length ? children : []);\n\t});\n\treturn new Slice(Fragment.fromArray(paragraphs), 1, 1);\n}\n"],"names":["TEXTBLOCK_TAGS","Set","BASIC_MARKS","cleanBlockBrs","container","brs","Array","from","querySelectorAll","br","insideTextblock","el","parentElement","has","tagName","replaceChild","document","createElement","stripTrailingBrs","tag","last","lastElementChild","childNodes","length","remove","normalizeHardBreaks","fragment","nodes","forEach","node","type","name","childCount","_a","firstChild","push","create","attrs","_b","lastChild","children","content","child","_offset","index","copy","Fragment","isBlock","isLeaf","stripRichMarks","isText","kept","marks","filter","m","mark","parseClipboardText","text","schema","paragraphs","split","map","line","Slice","fromArray"
|
|
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 * 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 using double-newline as paragraph separator\n * and single newline as a line break (<br>) within a paragraph. Produces\n * the same structure as Gmail's Cmd+V output.\n *\n * Best for channels with CSS-based paragraph gaps (e.g. email) where the\n * margin between `<p>` tags already provides visual separation.\n */\nexport function parseClipboardTextAsParagraphs(\n\ttext: string,\n\tschema: Schema,\n): Slice {\n\tconst trimmed = text.replace(/\\n+$/, '');\n\tconst blocks = trimmed.split(/\\n\\n+/);\n\tconst hardBreak = schema.nodes['hardBreak'];\n\tconst paragraphs = blocks.map((block) => {\n\t\tconst lines = block.split('\\n');\n\t\tconst children: PMNode[] = [];\n\t\tlines.forEach((line, i) => {\n\t\t\tif (line) children.push(schema.text(line));\n\t\t\tif (i < lines.length - 1 && hardBreak) {\n\t\t\t\tchildren.push(hardBreak.create());\n\t\t\t}\n\t\t});\n\t\treturn schema.node('paragraph', null, children.length ? children : []);\n\t});\n\treturn new Slice(Fragment.fromArray(paragraphs), 1, 1);\n}\n"],"names":["TEXTBLOCK_TAGS","Set","BASIC_MARKS","cleanBlockBrs","container","brs","Array","from","querySelectorAll","br","insideTextblock","el","parentElement","has","tagName","replaceChild","document","createElement","stripTrailingBrs","tag","last","lastElementChild","childNodes","length","remove","normalizeHardBreaks","fragment","nodes","forEach","node","type","name","childCount","_a","firstChild","push","create","attrs","_b","lastChild","children","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,QAMKC,EAAc,IAAID,IAAI,CAAC,OAAQ,SAAU,SAAU,YAAa,SAOhE,SAAUE,EAAcC,GAC7B,MAAMC,EAAMC,MAAMC,KAAKH,EAAUI,iBAAiB,OAClD,IAAK,MAAMC,KAAMJ,EAAK,CACrB,IAAIK,GAAkB,EAClBC,EAAKF,EAAGG,cACZ,KAAOD,GAAMA,IAAOP,GAAW,CAC9B,GAAIJ,EAAea,IAAIF,EAAGG,SAAU,CACnCJ,GAAkB,EAClB,KACA,CACDC,EAAKA,EAAGC,aACR,CACIF,GACJD,EAAGG,cAAeG,aAAaC,SAASC,cAAc,KAAMR,EAE7D,CACF,CAQM,SAAUS,EAAiBd,GAChC,IAAK,MAAMe,IAAO,CAAC,IAAK,OACvB,IAAK,MAAMR,KAAML,MAAMC,KAAKH,EAAUI,iBAAiBW,IAAO,CAC7D,MAAMC,EAAOT,EAAGU,iBACM,QAAlBD,aAAA,EAAAA,EAAMN,UAAoBH,EAAGW,WAAWC,OAAS,GACpDH,EAAKI,QAEN,CAEH,CAUM,SAAUC,EAAoBC,GACnC,MAAMC,EAAkB,GAsBxB,OArBAD,EAASE,SAASC,YACjB,GAAuB,cAAnBA,EAAKC,KAAKC,KAAsB,CACnC,GAAwB,IAApBF,EAAKG,YAAmD,eAAd,QAAjBC,EAAAJ,EAAKK,kBAAY,IAAAD,OAAA,EAAAA,EAAAH,KAAKC,MAElD,YADAJ,EAAMQ,KAAKN,EAAKC,KAAKM,OAAOP,EAAKQ,QAGlC,GAAIR,EAAKG,WAAa,GAAmC,eAAd,QAAhBM,EAAAT,EAAKU,iBAAW,IAAAD,OAAA,EAAAA,EAAAR,KAAKC,MAAsB,CACrE,MAAMS,EAAqB,GAK3B,OAJAX,EAAKY,QAAQb,SAAQ,CAACc,EAAOC,EAASC,KACjCA,EAAQf,EAAKG,WAAa,GAAGQ,EAASL,KAAKO,EAAM,SAEtDf,EAAMQ,KAAKN,EAAKgB,KAAKC,EAASvC,KAAKiC,IAEnC,CACD,CACGX,EAAKkB,UAAYlB,EAAKmB,OACzBrB,EAAMQ,KAAKN,EAAKgB,KAAKpB,EAAoBI,EAAKY,WAE9Cd,EAAMQ,KAAKN,EACX,IAEKiB,EAASvC,KAAKoB,EACtB,CAOM,SAAUsB,EAAevB,GAC9B,MAAMC,EAAkB,GASxB,OARAD,EAASE,SAASC,IACjB,GAAIA,EAAKqB,OAAQ,CAChB,MAAMC,EAAOtB,EAAKuB,MAAMC,QAAQC,GAAMpD,EAAYW,IAAIyC,EAAExB,KAAKC,QAC7DJ,EAAMQ,KAAKgB,EAAK5B,SAAWM,EAAKuB,MAAM7B,OAASM,EAAOA,EAAK0B,KAAKJ,GAChE,MACAxB,EAAMQ,KAAKN,EAAKgB,KAAKI,EAAepB,EAAKY,UACzC,IAEKK,EAASvC,KAAKoB,EACtB,CAUgB,SAAA6B,EAAmBC,EAAcC,GAChD,MAAMC,EAAaF,EACjBG,MAAM,MACNC,KAAKC,GACLJ,EAAO7B,KAAK,YAAa,KAAMiC,EAAO,CAACJ,EAAOD,KAAKK,IAAS,MAE9D,OAAO,IAAIC,EAAMjB,EAASkB,UAAUL,GAAa,EAAG,EACrD"}
|
|
@@ -6,5 +6,8 @@ import { Extension } from '@tiptap/core';
|
|
|
6
6
|
* - clipboardTextParser: plain text → Slice (preserves blank lines)
|
|
7
7
|
* - transformPastedHTML: HTML → HTML (cleans Google Docs / Word artifacts)
|
|
8
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.
|
|
9
12
|
*/
|
|
10
13
|
export declare const PasteNormalizationExtension: Extension<any, any>;
|