@aquera/nile-elements 0.1.64-beta-1.2 → 0.1.65-beta-1.0

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.
Files changed (38) hide show
  1. package/demo/index.html +29 -109
  2. package/dist/index.js +608 -547
  3. package/dist/nile-rich-text-editor/nile-rich-text-editor.cjs.js +1 -1
  4. package/dist/nile-rich-text-editor/nile-rich-text-editor.cjs.js.map +1 -1
  5. package/dist/nile-rich-text-editor/nile-rich-text-editor.css.cjs.js +1 -1
  6. package/dist/nile-rich-text-editor/nile-rich-text-editor.css.cjs.js.map +1 -1
  7. package/dist/nile-rich-text-editor/nile-rich-text-editor.css.esm.js +45 -2
  8. package/dist/nile-rich-text-editor/nile-rich-text-editor.esm.js +1 -1
  9. package/dist/nile-rich-text-editor/nile-rte-mentions.cjs.js +1 -1
  10. package/dist/nile-rich-text-editor/nile-rte-mentions.cjs.js.map +1 -1
  11. package/dist/nile-rich-text-editor/nile-rte-mentions.esm.js +1 -1
  12. package/dist/nile-rich-text-editor/nile-rte-select.cjs.js +1 -1
  13. package/dist/nile-rich-text-editor/nile-rte-select.cjs.js.map +1 -1
  14. package/dist/nile-rich-text-editor/nile-rte-select.esm.js +31 -13
  15. package/dist/nile-rich-text-editor/utils.cjs.js +1 -1
  16. package/dist/nile-rich-text-editor/utils.cjs.js.map +1 -1
  17. package/dist/nile-rich-text-editor/utils.esm.js +1 -1
  18. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js +43 -0
  19. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js.map +1 -1
  20. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.d.ts +3 -0
  21. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js +81 -22
  22. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js.map +1 -1
  23. package/dist/src/nile-rich-text-editor/nile-rte-mentions.js +5 -0
  24. package/dist/src/nile-rich-text-editor/nile-rte-mentions.js.map +1 -1
  25. package/dist/src/nile-rich-text-editor/nile-rte-select.d.ts +15 -1
  26. package/dist/src/nile-rich-text-editor/nile-rte-select.js +85 -52
  27. package/dist/src/nile-rich-text-editor/nile-rte-select.js.map +1 -1
  28. package/dist/src/nile-rich-text-editor/utils.d.ts +1 -0
  29. package/dist/src/nile-rich-text-editor/utils.js +17 -0
  30. package/dist/src/nile-rich-text-editor/utils.js.map +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +1 -1
  33. package/src/nile-rich-text-editor/nile-rich-text-editor.css.ts +43 -0
  34. package/src/nile-rich-text-editor/nile-rich-text-editor.ts +112 -40
  35. package/src/nile-rich-text-editor/nile-rte-mentions.ts +5 -0
  36. package/src/nile-rich-text-editor/nile-rte-select.ts +97 -58
  37. package/src/nile-rich-text-editor/utils.ts +18 -0
  38. package/vscode-html-custom-data.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"nile-rte-mentions.js","sourceRoot":"","sources":["../../../src/nile-rich-text-editor/nile-rte-mentions.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAM5D,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,UAAU;IAAxC;;QAyBL,aAAQ,GAAmB,EAAE,CAAC;QAY9B,kBAAa,GAA2B,EAAE,CAAC,CAAC,MAAM;QAElD,wDAAwD;QACvC,mBAAc,GAAmB,EAAE,CAAC;QAErD,6EAA6E;QAC5D,gBAAW,GAAmB,EAAE,CAAC;QAEjC,gBAAW,GAA0B,EAAE,CAAC,CAAC,MAAM;QAOhE,oBAAoB;QACZ,aAAQ,GAAuB,IAAI,CAAC;QACpC,WAAM,GAAuB,IAAI,CAAC;QAGpC,eAAU,GAAuB,IAAI,CAAC,CAAG,kBAAkB;QAC3D,WAAM,GAA4B,IAAI,CAAC,CAAG,cAAc;Q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AAE;uDAA6C;AAGpC;IAAhB,KAAK,EAAE;oDAA0C;AAEjC;IAAhB,KAAK,EAAE;oDAAiD;AA7C9C,eAAe;IAD3B,aAAa,CAAC,mBAAmB,CAAC;GACtB,eAAe,CA8b3B","sourcesContent":["import { LitElement } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport type { MentionItem } from './nile-rte-mentions-item';\n\ntype MentionsConfig = Record<string, MentionItem[]>;\n\n@customElement('nile-rte-mentions')\nexport class NileRteMentions extends LitElement {\n protected createRenderRoot() { return this; } \n\n \n @property({\n attribute: 'mentions',\n converter: {\n fromAttribute: (value: string): MentionsConfig => {\n try {\n const parsed = JSON.parse(value);\n const out: MentionsConfig = {};\n for (const trig of Object.keys(parsed)) {\n const arr = parsed[trig];\n if (Array.isArray(arr)) {\n out[trig] = arr\n .filter(i => i && typeof i.key === 'string' && typeof i.label === 'string')\n .map(i => ({ key: i.key, label: i.label }));\n }\n }\n return out;\n } catch { return {}; }\n },\n toAttribute: (v: MentionsConfig) => JSON.stringify(v),\n }\n })\n mentions: MentionsConfig = {};\n\n @property({\n attribute: 'mentioncolors',\n converter: {\n fromAttribute: (value: string): Record<string,string> => {\n try { const o = JSON.parse(value); return (o && typeof o === 'object') ? o : {}; }\n catch { return {}; }\n },\n toAttribute: (v: Record<string,string>) => JSON.stringify(v ?? {})\n }\n })\n mentionColors: Record<string, string> = {}; // NEW\n\n /** External config from the editor (lowest priority) */\n @state() private externalConfig: MentionsConfig = {};\n\n /** Config gathered from child <nile-rte-mentions-item> (highest priority) */\n @state() private itemsConfig: MentionsConfig = {};\n\n @state() private itemsColors: Record<string,string> = {}; // NEW\n\n private get config(): MentionsConfig {\n // Priority: external < attribute < child-items\n return { ...this.externalConfig, ...this.mentions, ...this.itemsConfig };\n }\n\n // wired from editor\n private editorEl: HTMLElement | null = null;\n private hostEl: HTMLElement | null = null;\n\n \nprivate dropdownEl: HTMLElement | null = null; // <nile-dropdown>\nprivate menuEl: HTMLElement | null = null; // <nile-menu>\n\n\n // selection caret\n private lastRange: Range | null = null;\n\n // dropdown state\n private mentionOpen = false;\n private mentionTrigger: string | null = null;\n private mentionQuery = '';\n private mentionSuggestions: MentionItem[] = [];\n private mentionFiltered: MentionItem[] = [];\n private mentionX = 0;\n private mentionY = 0;\nprivate triggerBtn: HTMLElement | null = null;\n\n \n\n // Observe child items & their attributes\n private mo: MutationObserver | null = null;\n\n // Public API used by <nile-rich-text-editor>\n attach(editorEl: HTMLElement, hostEl: HTMLElement) {\n this.editorEl = editorEl;\n this.hostEl = hostEl;\n\n this.injectStyles();\n this.ensureMentionDropdown();\n this.rebuildConfigFromChildren();\n\n // Watch for <nile-rte-mentions-item> add/remove/attr changes\n this.mo = new MutationObserver(() => this.rebuildConfigFromChildren());\n this.mo.observe(this, { childList: true, subtree: true, attributes: true });\n\n // listeners on editor\n this.editorEl.addEventListener('input', this.onEditorInput);\n this.editorEl.addEventListener('mouseup', this.saveSelection);\n this.editorEl.addEventListener('keyup', this.onEditorKeyUp);\n this.editorEl.addEventListener('keydown', this.onEditorKeyDown);\n this.editorEl.addEventListener('scroll', this.repositionMention);\n\n // keep range fresh\n document.addEventListener('selectionchange', this.onSelectionChange, true);\n }\n\n detach() {\n if (this.mo) { this.mo.disconnect(); this.mo = null; }\n if (this.editorEl) {\n this.editorEl.removeEventListener('input', this.onEditorInput);\n this.editorEl.removeEventListener('mouseup', this.saveSelection);\n this.editorEl.removeEventListener('keyup', this.onEditorKeyUp);\n this.editorEl.removeEventListener('keydown', this.onEditorKeyDown);\n this.editorEl.removeEventListener('scroll', this.repositionMention);\n }\n document.removeEventListener('selectionchange', this.onSelectionChange, true);\n }\n\n setExternalConfig(cfg: MentionsConfig) {\n this.externalConfig = cfg || {};\n }\n\n disconnectedCallback(): void {\n this.detach();\n super.disconnectedCallback();\n }\n\n // ---------- gather child items ----------\n private rebuildConfigFromChildren() {\n const cfg: MentionsConfig = {};\n const colors: Record<string,string> = {}; // NEW\n\n const items = Array.from(this.querySelectorAll('nile-rte-mentions-item')) as Array<\n HTMLElement & { mentionsCharacter?: string; mentionsData?: MentionItem[]; mentionsColor?: string }\n >;\n\n for (const item of items) {\n const trig =\n (item as any).mentionsCharacter ??\n item.getAttribute('mentionscharacter') ??\n '';\n\n if (!trig || typeof trig !== 'string') continue;\n\n let data: MentionItem[] | null =\n (item as any).mentionsData ??\n (() => {\n const raw = item.getAttribute('mentionsdata');\n if (!raw) return null;\n try {\n const parsed = JSON.parse(raw);\n return Array.isArray(parsed)\n ? parsed.filter(i => i && typeof i.key === 'string' && typeof i.label === 'string')\n : [];\n } catch { return []; }\n })();\n\n const color =\n (item as any).mentionsColor ??\n item.getAttribute('mentionscolor') ??\n '';\n\n if (!Array.isArray(data)) data = [];\n cfg[trig] = data;\n if (color) colors[trig] = String(color); // record color if provided\n }\n\n this.itemsConfig = cfg;\n this.itemsColors = colors; // NEW\n }\n // ---------- styles ----------\n private injectStyles() {\n if (this.querySelector('style[data-mentions-style]')) return;\n const style = document.createElement('style');\n style.setAttribute('data-mentions-style', 'true');\n style.textContent = `\n .mention-dropdown {\n position: absolute; z-index: 1000; list-style: none; margin: 0; padding: 4px;\n border: 1px solid #e5e7eb; border-radius: 6px; background: #fff;\n box-shadow: 0 4px 10px rgba(0,0,0,.08); max-height: 180px; overflow: auto; font-size: 14px;\n }\n .mention-dropdown li { padding: 6px 8px; cursor: pointer; border-radius: 4px; }\n .mention-dropdown li:hover { background: #f1f5f9; }\n .mention { background: #eef2ff; padding: 0 3px; border-radius: 3px; }\n `;\n this.insertBefore(style, this.firstChild);\n }\n\n private getTriggerColor(trigger: string): string | undefined {\n // Priority: child item color > attribute JSON color\n return this.itemsColors[trigger] ?? this.mentionColors[trigger];\n }\n\n \nprivate ensureMentionDropdown() {\n if (this.dropdownEl || !this.hostEl) return;\n\n const dd = document.createElement('nile-dropdown');\n dd.style.zIndex = '1000';\n\n const btn = document.createElement('nile-button'); // invisible trigger\n btn.setAttribute('slot', 'trigger');\n btn.style.position = 'absolute'; \n btn.style.width = '1px';\n btn.style.height = '1px';\n btn.style.border = '0';\n btn.style.padding = '0';\n btn.style.opacity = '0'; \n btn.style.pointerEvents = 'none'; \n dd.appendChild(btn);\n this.triggerBtn = btn; \n const menu = document.createElement('nile-menu');\n dd.appendChild(menu);\n\n this.hostEl.appendChild(dd);\n this.dropdownEl = dd;\n this.menuEl = menu;\n}\n\n // ---------- selection helpers ----------\n private onSelectionChange = () => {\n if (!this.editorEl) return;\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n if (this.editorEl.contains(range.commonAncestorContainer)) {\n this.lastRange = range.cloneRange();\n }\n };\n private saveSelection = () => {\n const sel = window.getSelection();\n if (sel && sel.rangeCount) this.lastRange = sel.getRangeAt(0).cloneRange();\n };\n private restoreSelection() {\n if (!this.lastRange) return;\n const sel = document.getSelection(); if (!sel) return;\n sel.removeAllRanges(); sel.addRange(this.lastRange);\n }\n private focusAndRestore() { this.editorEl?.focus(); this.restoreSelection(); }\n\n private getCaretClientRect(): DOMRect | null {\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return null;\n\n const range = sel.getRangeAt(0).cloneRange();\n range.collapse(false);\n\n const rects = range.getClientRects();\n if (rects && rects.length > 0) return rects[0];\n\n const marker = document.createElement('span');\n marker.setAttribute('data-caret-marker', '1');\n marker.textContent = '\\u200B';\n range.insertNode(marker);\n\n const rect = marker.getBoundingClientRect();\n\n const after = document.createRange();\n after.setStartAfter(marker);\n after.collapse(true);\n sel.removeAllRanges();\n sel.addRange(after);\n marker.remove();\n\n return rect || null;\n }\n\n // ---------- editor events ----------\n private onEditorInput = () => {\n if (this.mentionOpen) this.handleMention();\n };\n\n private onEditorKeyUp = (e: KeyboardEvent) => {\n this.saveSelection();\n const key = e.key;\n const cfg = this.config;\n if (!this.mentionOpen && key && cfg[key]) {\n this.openMention(key);\n return;\n }\n if (this.mentionOpen) this.handleMention();\n };\n\n private onEditorKeyDown = (e: KeyboardEvent) => {\n if (!this.mentionOpen) return;\n const key = e.key;\n if (key === 'ArrowDown' || key === 'ArrowUp' || key === 'Enter') {\n e.preventDefault();\n if (key === 'Enter' && this.mentionFiltered.length) {\n this.selectMention(this.mentionFiltered[0]);\n }\n } else if (key === 'Escape') {\n e.preventDefault();\n this.closeMention();\n }\n };\n\n // ---------- mentions flow ----------\n private openMention(trigger: string) {\n this.saveSelection();\n if (!this.editorEl || !this.dropdownEl || !this.hostEl) return;\n\n const caretRect = this.getCaretClientRect();\n if (!caretRect) return;\n\n const hostRect = this.hostEl.getBoundingClientRect();\n\n this.mentionX = caretRect.left - hostRect.left;\n this.mentionY = caretRect.bottom - hostRect.top;\n\n this.mentionTrigger = trigger;\n this.mentionSuggestions = this.config[trigger] || [];\n this.mentionQuery = '';\n this.updateMentionFiltered();\n\n this.mentionOpen = true;\n this.renderMentionList();\n }\n\n private closeMention() {\n this.mentionOpen = false;\n this.mentionTrigger = null;\n this.mentionQuery = '';\n this.mentionFiltered = [];\n // hide dropdown\n this.dropdownEl?.removeAttribute('open');\n }\n\n private handleMention() {\n if (!this.mentionOpen || !this.mentionTrigger) return;\n const sel = window.getSelection(); if (!sel || !sel.anchorNode) return;\n\n let node: Node | null = sel.anchorNode;\n if (node.nodeType !== Node.TEXT_NODE) {\n const c = (node as HTMLElement).childNodes?.[sel.anchorOffset] || node.firstChild;\n if (c?.nodeType === Node.TEXT_NODE) node = c;\n }\n const text = (node && node.nodeType === Node.TEXT_NODE) ? (node.textContent || '') : '';\n const idx = text.lastIndexOf(this.mentionTrigger);\n if (idx >= 0) {\n this.mentionQuery = text.substring(idx + 1);\n this.updateMentionFiltered();\n this.renderMentionList();\n } else {\n this.closeMention();\n }\n }\n\n private updateMentionFiltered() {\n const q = this.mentionQuery.toLowerCase();\n this.mentionFiltered = (this.mentionSuggestions || []).filter(item =>\n item.label.toLowerCase().startsWith(q)\n );\n }\n\n private renderMentionList() {\n if (!this.dropdownEl || !this.menuEl) return;\n \n if (!this.triggerBtn) return;\n this.triggerBtn.style.position = 'absolute';\n this.triggerBtn.style.left = `${this.mentionX}px`;\n this.triggerBtn.style.top = `${this.mentionY}px`;\n \n \n // clear old items\n this.menuEl.innerHTML = '';\n \n if (!this.mentionOpen || !this.mentionFiltered.length) {\n this.dropdownEl.removeAttribute('open');\n return;\n }\n \n // build menu items\n for (const item of this.mentionFiltered) {\n const mi = document.createElement('nile-menu-item');\n mi.textContent = item.label;\n mi.addEventListener('mousedown', (e) => {\n e.preventDefault();\n this.selectMention(item);\n });\n this.menuEl.appendChild(mi);\n }\n \n // show dropdown\n this.dropdownEl.setAttribute('open', '');\n }\n \n\n private repositionMention = () => {\n if (!this.mentionOpen || !this.hostEl || !this.triggerBtn) return;\n\n const caretRect = this.getCaretClientRect();\n if (!caretRect) return;\n\n const hostRect = this.hostEl.getBoundingClientRect();\n\n this.mentionX = caretRect.left - hostRect.left;\n this.mentionY = caretRect.bottom - hostRect.top;\n\n this.triggerBtn.style.left = `${this.mentionX}px`;\n this.triggerBtn.style.top = `${this.mentionY}px`;\n };\n\n private selectMention(item: MentionItem) {\n this.restoreSelection(); if (!this.lastRange || !this.mentionTrigger || !this.editorEl) return;\n\n let node: Node = this.lastRange.startContainer;\n let offset = this.lastRange.startOffset;\n if (node.nodeType !== Node.TEXT_NODE) {\n const child = node.childNodes[offset];\n if (child?.nodeType === Node.TEXT_NODE) { node = child; offset = 0; } else return;\n }\n const textNode = node as Text;\n const text = textNode.textContent || '';\n const atIndex = text.lastIndexOf(this.mentionTrigger, offset);\n if (atIndex < 0) return;\n\n const endIndex = atIndex + 1 + this.mentionQuery.length;\n const mentionRange = document.createRange();\n mentionRange.setStart(textNode, atIndex);\n mentionRange.setEnd(textNode, endIndex);\n mentionRange.deleteContents();\n\n const span = document.createElement('span');\n span.classList.add('mention');\n span.textContent = `${this.mentionTrigger}${item.label}`;\n const bg = this.getTriggerColor(this.mentionTrigger);\n if (bg) {\n span.style.backgroundColor = bg;\n // Optional: if you prefer colored text instead of bg\n // span.style.color = bg;\n }\n\n mentionRange.insertNode(span);\n\n const spaceNode = document.createTextNode('\\u00A0');\n span.after(spaceNode);\n\n const sel = window.getSelection();\n const afterRange = document.createRange();\n afterRange.setStartAfter(spaceNode); afterRange.collapse(true);\n sel?.removeAllRanges(); sel?.addRange(afterRange);\n this.lastRange = afterRange.cloneRange();\n\n this.closeMention();\n\n // bubble an input event so the editor updates preview/state\n this.editorEl.dispatchEvent(new InputEvent('input', { bubbles: true }));\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-rte-mentions': NileRteMentions;\n }\n}\n"]}
1
+ {"version":3,"file":"nile-rte-mentions.js","sourceRoot":"","sources":["../../../src/nile-rich-text-editor/nile-rte-mentions.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAM5D,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,UAAU;IAAxC;;QAyBL,aAAQ,GAAmB,EAAE,CAAC;QAY9B,kBAAa,GAA2B,EAAE,CAAC,CAAC,MAAM;QAElD,wDAAwD;QACvC,mBAAc,GAAmB,EAAE,CAAC;QAErD,6EAA6E;QAC5D,gBAAW,GAAmB,EAAE,CAAC;QAEjC,gBAAW,GAA0B,EAAE,CAAC,CAAC,MAAM;QAOhE,oBAAoB;QACZ,aAAQ,GAAuB,IAAI,CAAC;QACpC,WAAM,GAAuB,IAAI,CAAC;QAGpC,eAAU,GAAuB,IAAI,CAAC,CAAG,kBAAkB;QAC3D,WAAM,GAA4B,IAAI,CAAC,CAAG,cAAc;QAG9D,kBAAkB;QACV,cAAS,GAAiB,IAAI,CAAC;QAEvC,iBAAiB;QACT,gBAAW,GAAG,KAAK,CAAC;QACpB,mBAAc,GAAkB,IAAI,CAAC;QACrC,iBAAY,GAAG,EAAE,CAAC;QAClB,uBAAkB,GAAkB,EAAE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AC,mBAAmB,CAAC;GACtB,eAAe,CAmc3B","sourcesContent":["import { LitElement } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport type { MentionItem } from './nile-rte-mentions-item';\n\ntype MentionsConfig = Record<string, MentionItem[]>;\n\n@customElement('nile-rte-mentions')\nexport class NileRteMentions extends LitElement {\n protected createRenderRoot() { return this; } \n\n \n @property({\n attribute: 'mentions',\n converter: {\n fromAttribute: (value: string): MentionsConfig => {\n try {\n const parsed = JSON.parse(value);\n const out: MentionsConfig = {};\n for (const trig of Object.keys(parsed)) {\n const arr = parsed[trig];\n if (Array.isArray(arr)) {\n out[trig] = arr\n .filter(i => i && typeof i.key === 'string' && typeof i.label === 'string')\n .map(i => ({ key: i.key, label: i.label }));\n }\n }\n return out;\n } catch { return {}; }\n },\n toAttribute: (v: MentionsConfig) => JSON.stringify(v),\n }\n })\n mentions: MentionsConfig = {};\n\n @property({\n attribute: 'mentioncolors',\n converter: {\n fromAttribute: (value: string): Record<string,string> => {\n try { const o = JSON.parse(value); return (o && typeof o === 'object') ? o : {}; }\n catch { return {}; }\n },\n toAttribute: (v: Record<string,string>) => JSON.stringify(v ?? {})\n }\n })\n mentionColors: Record<string, string> = {}; // NEW\n\n /** External config from the editor (lowest priority) */\n @state() private externalConfig: MentionsConfig = {};\n\n /** Config gathered from child <nile-rte-mentions-item> (highest priority) */\n @state() private itemsConfig: MentionsConfig = {};\n\n @state() private itemsColors: Record<string,string> = {}; // NEW\n\n private get config(): MentionsConfig {\n // Priority: external < attribute < child-items\n return { ...this.externalConfig, ...this.mentions, ...this.itemsConfig };\n }\n\n // wired from editor\n private editorEl: HTMLElement | null = null;\n private hostEl: HTMLElement | null = null;\n\n \nprivate dropdownEl: HTMLElement | null = null; // <nile-dropdown>\nprivate menuEl: HTMLElement | null = null; // <nile-menu>\n\n\n // selection caret\n private lastRange: Range | null = null;\n\n // dropdown state\n private mentionOpen = false;\n private mentionTrigger: string | null = null;\n private mentionQuery = '';\n private mentionSuggestions: MentionItem[] = [];\n private mentionFiltered: MentionItem[] = [];\n private mentionX = 0;\n private mentionY = 0;\nprivate triggerBtn: HTMLElement | null = null;\n\n \n\n // Observe child items & their attributes\n private mo: MutationObserver | null = null;\n\n // Public API used by <nile-rich-text-editor>\n attach(editorEl: HTMLElement, hostEl: HTMLElement) {\n this.editorEl = editorEl;\n this.hostEl = hostEl;\n\n this.injectStyles();\n this.ensureMentionDropdown();\n this.rebuildConfigFromChildren();\n\n // Watch for <nile-rte-mentions-item> add/remove/attr changes\n this.mo = new MutationObserver(() => this.rebuildConfigFromChildren());\n this.mo.observe(this, { childList: true, subtree: true, attributes: true });\n\n // listeners on editor\n this.editorEl.addEventListener('input', this.onEditorInput);\n this.editorEl.addEventListener('mouseup', this.saveSelection);\n this.editorEl.addEventListener('keyup', this.onEditorKeyUp);\n this.editorEl.addEventListener('keydown', this.onEditorKeyDown);\n this.editorEl.addEventListener('scroll', this.repositionMention);\n\n // keep range fresh\n document.addEventListener('selectionchange', this.onSelectionChange, true);\n }\n\n detach() {\n if (this.mo) { this.mo.disconnect(); this.mo = null; }\n if (this.editorEl) {\n this.editorEl.removeEventListener('input', this.onEditorInput);\n this.editorEl.removeEventListener('mouseup', this.saveSelection);\n this.editorEl.removeEventListener('keyup', this.onEditorKeyUp);\n this.editorEl.removeEventListener('keydown', this.onEditorKeyDown);\n this.editorEl.removeEventListener('scroll', this.repositionMention);\n }\n document.removeEventListener('selectionchange', this.onSelectionChange, true);\n }\n\n setExternalConfig(cfg: MentionsConfig) {\n this.externalConfig = cfg || {};\n }\n\n disconnectedCallback(): void {\n this.detach();\n super.disconnectedCallback();\n }\n\n // ---------- gather child items ----------\n private rebuildConfigFromChildren() {\n const cfg: MentionsConfig = {};\n const colors: Record<string,string> = {}; // NEW\n\n const items = Array.from(this.querySelectorAll('nile-rte-mentions-item')) as Array<\n HTMLElement & { mentionsCharacter?: string; mentionsData?: MentionItem[]; mentionsColor?: string }\n >;\n\n for (const item of items) {\n const trig =\n (item as any).mentionsCharacter ??\n item.getAttribute('mentionscharacter') ??\n '';\n\n if (!trig || typeof trig !== 'string') continue;\n\n let data: MentionItem[] | null =\n (item as any).mentionsData ??\n (() => {\n const raw = item.getAttribute('mentionsdata');\n if (!raw) return null;\n try {\n const parsed = JSON.parse(raw);\n return Array.isArray(parsed)\n ? parsed.filter(i => i && typeof i.key === 'string' && typeof i.label === 'string')\n : [];\n } catch { return []; }\n })();\n\n const color =\n (item as any).mentionsColor ??\n item.getAttribute('mentionscolor') ??\n '';\n\n if (!Array.isArray(data)) data = [];\n cfg[trig] = data;\n if (color) colors[trig] = String(color); // record color if provided\n }\n\n this.itemsConfig = cfg;\n this.itemsColors = colors; // NEW\n }\n // ---------- styles ----------\n private injectStyles() {\n if (this.querySelector('style[data-mentions-style]')) return;\n const style = document.createElement('style');\n style.setAttribute('data-mentions-style', 'true');\n style.textContent = `\n .mention-dropdown {\n position: absolute; z-index: 1000; list-style: none; margin: 0; padding: 4px;\n border: 1px solid #e5e7eb; border-radius: 6px; background: #fff;\n box-shadow: 0 4px 10px rgba(0,0,0,.08); max-height: 180px; overflow: auto; font-size: 14px;\n }\n .mention-dropdown li { padding: 6px 8px; cursor: pointer; border-radius: 4px; }\n .mention-dropdown li:hover { background: #f1f5f9; }\n .mention { background: #eef2ff; padding: 0 3px; border-radius: 3px; }\n nile-menu.mentions-menu::part(menu__items-wrapper){\n max-height: 260px;\n }\n\n `;\n this.insertBefore(style, this.firstChild);\n }\n\n private getTriggerColor(trigger: string): string | undefined {\n // Priority: child item color > attribute JSON color\n return this.itemsColors[trigger] ?? this.mentionColors[trigger];\n }\n\n \nprivate ensureMentionDropdown() {\n if (this.dropdownEl || !this.hostEl) return;\n\n const dd = document.createElement('nile-dropdown');\n dd.style.zIndex = '1000';\n\n const btn = document.createElement('nile-button'); // invisible trigger\n btn.setAttribute('slot', 'trigger');\n btn.style.position = 'absolute'; \n btn.style.width = '1px';\n btn.style.height = '1px';\n btn.style.border = '0';\n btn.style.padding = '0';\n btn.style.opacity = '0'; \n btn.style.pointerEvents = 'none'; \n dd.appendChild(btn);\n this.triggerBtn = btn; \n const menu = document.createElement('nile-menu');\n menu.classList.add('mentions-menu');\n dd.appendChild(menu);\n\n this.hostEl.appendChild(dd);\n this.dropdownEl = dd;\n this.menuEl = menu;\n}\n\n // ---------- selection helpers ----------\n private onSelectionChange = () => {\n if (!this.editorEl) return;\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n if (this.editorEl.contains(range.commonAncestorContainer)) {\n this.lastRange = range.cloneRange();\n }\n };\n private saveSelection = () => {\n const sel = window.getSelection();\n if (sel && sel.rangeCount) this.lastRange = sel.getRangeAt(0).cloneRange();\n };\n private restoreSelection() {\n if (!this.lastRange) return;\n const sel = document.getSelection(); if (!sel) return;\n sel.removeAllRanges(); sel.addRange(this.lastRange);\n }\n private focusAndRestore() { this.editorEl?.focus(); this.restoreSelection(); }\n\n private getCaretClientRect(): DOMRect | null {\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return null;\n\n const range = sel.getRangeAt(0).cloneRange();\n range.collapse(false);\n\n const rects = range.getClientRects();\n if (rects && rects.length > 0) return rects[0];\n\n const marker = document.createElement('span');\n marker.setAttribute('data-caret-marker', '1');\n marker.textContent = '\\u200B';\n range.insertNode(marker);\n\n const rect = marker.getBoundingClientRect();\n\n const after = document.createRange();\n after.setStartAfter(marker);\n after.collapse(true);\n sel.removeAllRanges();\n sel.addRange(after);\n marker.remove();\n\n return rect || null;\n }\n\n // ---------- editor events ----------\n private onEditorInput = () => {\n if (this.mentionOpen) this.handleMention();\n };\n\n private onEditorKeyUp = (e: KeyboardEvent) => {\n this.saveSelection();\n const key = e.key;\n const cfg = this.config;\n if (!this.mentionOpen && key && cfg[key]) {\n this.openMention(key);\n return;\n }\n if (this.mentionOpen) this.handleMention();\n };\n\n private onEditorKeyDown = (e: KeyboardEvent) => {\n if (!this.mentionOpen) return;\n const key = e.key;\n if (key === 'ArrowDown' || key === 'ArrowUp' || key === 'Enter') {\n e.preventDefault();\n if (key === 'Enter' && this.mentionFiltered.length) {\n this.selectMention(this.mentionFiltered[0]);\n }\n } else if (key === 'Escape') {\n e.preventDefault();\n this.closeMention();\n }\n };\n\n // ---------- mentions flow ----------\n private openMention(trigger: string) {\n this.saveSelection();\n if (!this.editorEl || !this.dropdownEl || !this.hostEl) return;\n\n const caretRect = this.getCaretClientRect();\n if (!caretRect) return;\n\n const hostRect = this.hostEl.getBoundingClientRect();\n\n this.mentionX = caretRect.left - hostRect.left;\n this.mentionY = caretRect.bottom - hostRect.top;\n\n this.mentionTrigger = trigger;\n this.mentionSuggestions = this.config[trigger] || [];\n this.mentionQuery = '';\n this.updateMentionFiltered();\n\n this.mentionOpen = true;\n this.renderMentionList();\n }\n\n private closeMention() {\n this.mentionOpen = false;\n this.mentionTrigger = null;\n this.mentionQuery = '';\n this.mentionFiltered = [];\n // hide dropdown\n this.dropdownEl?.removeAttribute('open');\n }\n\n private handleMention() {\n if (!this.mentionOpen || !this.mentionTrigger) return;\n const sel = window.getSelection(); if (!sel || !sel.anchorNode) return;\n\n let node: Node | null = sel.anchorNode;\n if (node.nodeType !== Node.TEXT_NODE) {\n const c = (node as HTMLElement).childNodes?.[sel.anchorOffset] || node.firstChild;\n if (c?.nodeType === Node.TEXT_NODE) node = c;\n }\n const text = (node && node.nodeType === Node.TEXT_NODE) ? (node.textContent || '') : '';\n const idx = text.lastIndexOf(this.mentionTrigger);\n if (idx >= 0) {\n this.mentionQuery = text.substring(idx + 1);\n this.updateMentionFiltered();\n this.renderMentionList();\n } else {\n this.closeMention();\n }\n }\n\n private updateMentionFiltered() {\n const q = this.mentionQuery.toLowerCase();\n this.mentionFiltered = (this.mentionSuggestions || []).filter(item =>\n item.label.toLowerCase().startsWith(q)\n );\n }\n\n private renderMentionList() {\n if (!this.dropdownEl || !this.menuEl) return;\n \n if (!this.triggerBtn) return;\n this.triggerBtn.style.position = 'absolute';\n this.triggerBtn.style.left = `${this.mentionX}px`;\n this.triggerBtn.style.top = `${this.mentionY}px`;\n \n \n // clear old items\n this.menuEl.innerHTML = '';\n \n if (!this.mentionOpen || !this.mentionFiltered.length) {\n this.dropdownEl.removeAttribute('open');\n return;\n }\n \n // build menu items\n for (const item of this.mentionFiltered) {\n const mi = document.createElement('nile-menu-item');\n mi.textContent = item.label;\n mi.addEventListener('mousedown', (e) => {\n e.preventDefault();\n this.selectMention(item);\n });\n this.menuEl.appendChild(mi);\n }\n \n // show dropdown\n this.dropdownEl.setAttribute('open', '');\n }\n \n\n private repositionMention = () => {\n if (!this.mentionOpen || !this.hostEl || !this.triggerBtn) return;\n\n const caretRect = this.getCaretClientRect();\n if (!caretRect) return;\n\n const hostRect = this.hostEl.getBoundingClientRect();\n\n this.mentionX = caretRect.left - hostRect.left;\n this.mentionY = caretRect.bottom - hostRect.top;\n\n this.triggerBtn.style.left = `${this.mentionX}px`;\n this.triggerBtn.style.top = `${this.mentionY}px`;\n };\n\n private selectMention(item: MentionItem) {\n this.restoreSelection(); if (!this.lastRange || !this.mentionTrigger || !this.editorEl) return;\n\n let node: Node = this.lastRange.startContainer;\n let offset = this.lastRange.startOffset;\n if (node.nodeType !== Node.TEXT_NODE) {\n const child = node.childNodes[offset];\n if (child?.nodeType === Node.TEXT_NODE) { node = child; offset = 0; } else return;\n }\n const textNode = node as Text;\n const text = textNode.textContent || '';\n const atIndex = text.lastIndexOf(this.mentionTrigger, offset);\n if (atIndex < 0) return;\n\n const endIndex = atIndex + 1 + this.mentionQuery.length;\n const mentionRange = document.createRange();\n mentionRange.setStart(textNode, atIndex);\n mentionRange.setEnd(textNode, endIndex);\n mentionRange.deleteContents();\n\n const span = document.createElement('span');\n span.classList.add('mention');\n span.textContent = `${this.mentionTrigger}${item.label}`;\n const bg = this.getTriggerColor(this.mentionTrigger);\n if (bg) {\n span.style.backgroundColor = bg;\n // Optional: if you prefer colored text instead of bg\n // span.style.color = bg;\n }\n\n mentionRange.insertNode(span);\n\n const spaceNode = document.createTextNode('\\u00A0');\n span.after(spaceNode);\n\n const sel = window.getSelection();\n const afterRange = document.createRange();\n afterRange.setStartAfter(spaceNode); afterRange.collapse(true);\n sel?.removeAllRanges(); sel?.addRange(afterRange);\n this.lastRange = afterRange.cloneRange();\n\n this.closeMention();\n\n // bubble an input event so the editor updates preview/state\n this.editorEl.dispatchEvent(new InputEvent('input', { bubbles: true }));\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-rte-mentions': NileRteMentions;\n }\n}\n"]}
@@ -1,10 +1,23 @@
1
1
  import { LitElement } from 'lit';
2
+ type HeadingTag = 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
3
+ type GenericOption = {
4
+ value: string;
5
+ label?: string;
6
+ icon?: string;
7
+ };
8
+ type HeadingOption = {
9
+ value: HeadingTag;
10
+ label?: string;
11
+ icon?: string;
12
+ };
2
13
  export declare class NileRteSelect extends LitElement {
3
14
  protected createRenderRoot(): this;
4
15
  /** 'heading' | 'font' | 'align' */
5
16
  type: string;
6
- /** JSON: [{ value, label?, icon? }, ...] */
17
+ /** JSON: [{ value, label?, icon? }, ...] (attribute-based; runtime-validated) */
7
18
  options: string;
19
+ /** Programmatic options (preferred for TS safety). */
20
+ optionsObj?: Array<GenericOption | HeadingOption>;
8
21
  /** Fallback label for trigger (e.g., "Align") */
9
22
  label: string;
10
23
  private selectedValue;
@@ -21,3 +34,4 @@ declare global {
21
34
  'nile-rte-select': NileRteSelect;
22
35
  }
23
36
  }
37
+ export {};
@@ -2,12 +2,18 @@ import { __decorate } from "tslib";
2
2
  // nile-rte-select.ts
3
3
  import { LitElement, html } from 'lit';
4
4
  import { customElement, property, state } from 'lit/decorators.js';
5
+ const HEADING_ALLOWLIST = new Set([
6
+ 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
7
+ ]);
8
+ function isHeadingTag(v) {
9
+ return HEADING_ALLOWLIST.has(v);
10
+ }
5
11
  let NileRteSelect = class NileRteSelect extends LitElement {
6
12
  constructor() {
7
13
  super(...arguments);
8
14
  /** 'heading' | 'font' | 'align' */
9
15
  this.type = '';
10
- /** JSON: [{ value, label?, icon? }, ...] */
16
+ /** JSON: [{ value, label?, icon? }, ...] (attribute-based; runtime-validated) */
11
17
  this.options = '[]';
12
18
  /** Fallback label for trigger (e.g., "Align") */
13
19
  this.label = '';
@@ -24,18 +30,37 @@ let NileRteSelect = class NileRteSelect extends LitElement {
24
30
  return map[v] || 'align-left';
25
31
  }
26
32
  get parsedOptions() {
27
- try {
28
- const raw = JSON.parse(this.options);
29
- return raw.map((o) => {
30
- const value = o.value ?? o;
31
- const label = o.label ?? o.value ?? o;
32
- const icon = o.icon ?? (this.type === 'align' ? this.mapAlignIcon(String(value)) : undefined);
33
- return { value, label, icon };
34
- });
35
- }
36
- catch {
37
- return [];
33
+ // Prefer programmatic options if present (gives TS compile-time checks)
34
+ const source = this.optionsObj ?? this.options;
35
+ const rawArray = (() => {
36
+ if (Array.isArray(source))
37
+ return source;
38
+ try {
39
+ return JSON.parse(String(source));
40
+ }
41
+ catch {
42
+ return [];
43
+ }
44
+ })();
45
+ // Normalize to consistent shape
46
+ let items = rawArray.map((o) => {
47
+ const value = o?.value ?? o;
48
+ const label = o?.label ?? o?.value ?? o;
49
+ const icon = o?.icon ?? (this.type === 'align' ? this.mapAlignIcon(String(value)) : undefined);
50
+ return { value, label, icon };
51
+ });
52
+ // If type is heading, enforce allowlist (runtime validation)
53
+ if (this.type === 'heading') {
54
+ const before = items.length;
55
+ items = items.filter(i => isHeadingTag(i.value));
56
+ if (items.length !== before) {
57
+ }
58
+ // If current selection is invalid for heading, reset
59
+ if (this.selectedValue && !isHeadingTag(this.selectedValue)) {
60
+ this.selectedValue = '';
61
+ }
38
62
  }
63
+ return items;
39
64
  }
40
65
  ensureDefault() {
41
66
  if (!this.selectedValue) {
@@ -45,6 +70,10 @@ let NileRteSelect = class NileRteSelect extends LitElement {
45
70
  }
46
71
  }
47
72
  onSelect(value) {
73
+ if (this.type === 'heading' && !isHeadingTag(value)) {
74
+ console.warn(`[nile-rte-select] Ignoring invalid heading value: ${value}`);
75
+ return;
76
+ }
48
77
  this.selectedValue = value;
49
78
  this.dispatchEvent(new CustomEvent('change', {
50
79
  detail: value, bubbles: true, composed: true
@@ -60,21 +89,20 @@ let NileRteSelect = class NileRteSelect extends LitElement {
60
89
  const style = document.createElement('style');
61
90
  style.setAttribute('data-rte-select-style', 'true');
62
91
  style.textContent = `
63
-
64
- nile-menu.rte-align-menu::part(menu__items-wrapper) {
65
- display: flex;
66
- }
67
- nile-menu.rte-align-menu,nile-menu.rte-default-menu{
68
- margin-top: 0px;
69
- }
70
-
71
- nile-button.rte-align-trigger::part(base),nile-button.rte-default-trigger::part(base){
72
- min-width: 32px;
73
- height: 32px;
74
- padding: 0px 6px;
75
- box-shadow: none;
76
- }
77
-
92
+ nile-menu.rte-align-menu::part(menu__items-wrapper) {
93
+ display: flex;
94
+ }
95
+ nile-menu.rte-align-menu,
96
+ nile-menu.rte-default-menu {
97
+ margin-top: 0px;
98
+ }
99
+ nile-button.rte-align-trigger::part(base),
100
+ nile-button.rte-default-trigger::part(base) {
101
+ min-width: 32px;
102
+ height: 32px;
103
+ padding: 0px 6px;
104
+ box-shadow: none;
105
+ }
78
106
  `;
79
107
  this.insertBefore(style, this.firstChild);
80
108
  }
@@ -82,8 +110,8 @@ let NileRteSelect = class NileRteSelect extends LitElement {
82
110
  const opts = this.parsedOptions;
83
111
  this.ensureDefault();
84
112
  const current = opts.find(o => o.value === this.selectedValue);
113
+ // ► Align: icon-only items + icon trigger
85
114
  if (this.type === 'align') {
86
- // ► Align: separate dropdown instance + icon-only items + icon trigger
87
115
  const trigger = current?.icon
88
116
  ? html `<nile-icon name="${current.icon}"></nile-icon>`
89
117
  : (this.label || 'Align');
@@ -103,32 +131,34 @@ let NileRteSelect = class NileRteSelect extends LitElement {
103
131
  `)}
104
132
  </nile-menu>
105
133
  </nile-dropdown>
106
-
107
-
108
134
  `;
109
- if (this.type === 'font') {
110
- const triggerText = current?.label || this.label || 'Font';
111
- return html `
112
- <nile-dropdown class="rte-default-dd">
113
- <nile-button slot="trigger" variant="tertiary" class="rte-default-trigger"
114
- style="font-family: ${current?.value || 'inherit'}">
115
- ${triggerText} <nile-icon name="arrowdown"></nile-icon>
116
- </nile-button>
117
- <nile-menu class="rte-default-menu">
118
- ${opts.map(o => html `
119
- <nile-menu-item
120
- style="font-family: ${o.value}"
121
- ?active=${o.value === this.selectedValue}
122
- @click=${() => this.onSelect(o.value)}>
123
- ${o.label}
124
- </nile-menu-item>
125
- `)}
126
- </nile-menu>
127
- </nile-dropdown>
128
- `;
129
- }
130
135
  }
131
- // ► Everything else: default (text) dropdown
136
+ // ► Font: show labels, preview fonts in items and trigger
137
+ if (this.type === 'font') {
138
+ const triggerText = current?.label || this.label || 'Font';
139
+ return html `
140
+ <nile-dropdown class="rte-default-dd">
141
+ <nile-button
142
+ slot="trigger"
143
+ variant="tertiary"
144
+ class="rte-default-trigger"
145
+ style="font-family: ${current?.value || 'inherit'}">
146
+ ${triggerText} <nile-icon name="arrowdown"></nile-icon>
147
+ </nile-button>
148
+ <nile-menu class="rte-default-menu">
149
+ ${opts.map(o => html `
150
+ <nile-menu-item
151
+ style="font-family: ${o.value}"
152
+ ?active=${o.value === this.selectedValue}
153
+ @click=${() => this.onSelect(o.value)}>
154
+ ${o.label}
155
+ </nile-menu-item>
156
+ `)}
157
+ </nile-menu>
158
+ </nile-dropdown>
159
+ `;
160
+ }
161
+ // ► Default (e.g., heading): text items; heading values are validated already
132
162
  const triggerText = current?.label || this.label || 'Select';
133
163
  return html `
134
164
  <nile-dropdown class="rte-default-dd">
@@ -154,6 +184,9 @@ __decorate([
154
184
  __decorate([
155
185
  property({ type: String })
156
186
  ], NileRteSelect.prototype, "options", void 0);
187
+ __decorate([
188
+ property({ attribute: false })
189
+ ], NileRteSelect.prototype, "optionsObj", void 0);
157
190
  __decorate([
158
191
  property({ type: String })
159
192
  ], NileRteSelect.prototype, "label", void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"nile-rte-select.js","sourceRoot":"","sources":["../../../src/nile-rich-text-editor/nile-rte-select.ts"],"names":[],"mappings":";AAAA,qBAAqB;AACrB,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI5D,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,UAAU;IAAtC;;QAGL,mCAAmC;QACP,SAAI,GAAG,EAAE,CAAC;QACtC,4CAA4C;QAChB,YAAO,GAAG,IAAI,CAAC;QAC3C,iDAAiD;QACrB,UAAK,GAAG,EAAE,CAAC;QAEtB,kBAAa,GAAG,EAAE,CAAC;IAkJtC,CAAC;IA3JW,gBAAgB,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IAWrC,YAAY,CAAC,CAAS;QAC5B,MAAM,GAAG,GAA0B;YACjC,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,cAAc;YACtB,KAAK,EAAE,aAAa;YACpB,OAAO,EAAE,cAAc;SACxB,CAAC;QACF,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC;IAChC,CAAC;IAED,IAAY,aAAa;QACvB,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrC,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE;gBACxB,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;gBAC3B,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;gBACtC,MAAM,IAAI,GAAI,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI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AA6C;QAC7C,MAAM,WAAW,GAAG,OAAO,EAAE,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC;QAC7D,OAAO,IAAI,CAAA;;;YAGH,WAAW;;;YAGX,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAA;;wBAEN,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,aAAa;uBAC/B,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;gBACnC,CAAC,CAAC,KAAK;;WAEZ,CAAC;;;KAGP,CAAC;IACJ,CAAC;CACF,CAAA;AAxJ6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;2CAAW;AAEV;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8CAAgB;AAEf;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4CAAY;AAEtB;IAAhB,KAAK,EAAE;oDAA4B;AAVzB,aAAa;IADzB,aAAa,CAAC,iBAAiB,CAAC;GACpB,aAAa,CA4JzB","sourcesContent":["// nile-rte-select.ts\nimport { LitElement, html } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\n\n\n@customElement('nile-rte-select')\nexport class NileRteSelect extends LitElement {\n protected createRenderRoot() { return this; }\n\n /** 'heading' | 'font' | 'align' */\n @property({ type: String }) type = '';\n /** JSON: [{ value, label?, icon? }, ...] */\n @property({ type: String }) options = '[]';\n /** Fallback label for trigger (e.g., \"Align\") */\n @property({ type: String }) label = '';\n\n @state() private selectedValue = '';\n\n private mapAlignIcon(v: string) {\n const map: Record<string,string> = {\n left: 'align-left',\n center: 'align-center',\n right: 'align-right',\n justify: 'nile-justify'\n };\n return map[v] || 'align-left';\n }\n\n private get parsedOptions(): Array<{ value: string; label: string; icon?: string }> {\n try {\n const raw = JSON.parse(this.options);\n return raw.map((o: any) => {\n const value = o.value ?? o;\n const label = o.label ?? o.value ?? o;\n const icon = o.icon ?? (this.type === 'align' ? this.mapAlignIcon(String(value)) : undefined);\n return { value, label, icon };\n });\n } catch {\n return [];\n }\n }\n\n private ensureDefault() {\n if (!this.selectedValue) {\n const first = this.parsedOptions[0];\n if (first) this.selectedValue = first.value;\n }\n }\n\n private onSelect(value: string) {\n this.selectedValue = value;\n this.dispatchEvent(new CustomEvent('change', {\n detail: value, bubbles: true, composed: true\n }));\n }\n\n \n\n connectedCallback(): void {\n super.connectedCallback();\n this.injectLocalStyles(); \n }\n\n private injectLocalStyles() {\n \n if (this.querySelector('style[data-rte-select-style]')) return;\n\n const style = document.createElement('style');\n style.setAttribute('data-rte-select-style', 'true');\n style.textContent = `\n\n nile-menu.rte-align-menu::part(menu__items-wrapper) {\n display: flex;\n }\n nile-menu.rte-align-menu,nile-menu.rte-default-menu{\n margin-top: 0px;\n }\n\n nile-button.rte-align-trigger::part(base),nile-button.rte-default-trigger::part(base){\n min-width: 32px;\n height: 32px;\n padding: 0px 6px;\n box-shadow: none;\n }\n \n `;\n \n this.insertBefore(style, this.firstChild);\n }\n\n\n render() {\n const opts = this.parsedOptions;\n this.ensureDefault();\n const current = opts.find(o => o.value === this.selectedValue);\n\n if (this.type === 'align') {\n // ► Align: separate dropdown instance + icon-only items + icon trigger\n const trigger = current?.icon\n ? html`<nile-icon name=\"${current.icon}\"></nile-icon>`\n : (this.label || 'Align');\n return html`\n <nile-dropdown class=\"rte-align-dd\">\n <nile-button slot=\"trigger\" variant=\"tertiary\" class=\"rte-align-trigger\">\n ${trigger}\n </nile-button>\n <nile-menu class=\"rte-align-menu\">\n ${opts.map(o => html`\n <nile-menu-item\n class=\"rte-align-item\"\n ?active=${o.value === this.selectedValue}\n @click=${() => this.onSelect(o.value)}>\n <nile-icon name=\"${o.icon}\"></nile-icon>\n </nile-menu-item>\n `)}\n </nile-menu>\n </nile-dropdown>\n\n \n `;\n if (this.type === 'font') {\n const triggerText = current?.label || this.label || 'Font';\n return html`\n <nile-dropdown class=\"rte-default-dd\">\n <nile-button slot=\"trigger\" variant=\"tertiary\" class=\"rte-default-trigger\"\n style=\"font-family: ${current?.value || 'inherit'}\">\n ${triggerText} <nile-icon name=\"arrowdown\"></nile-icon>\n </nile-button>\n <nile-menu class=\"rte-default-menu\">\n ${opts.map(o => html`\n <nile-menu-item\n style=\"font-family: ${o.value}\"\n ?active=${o.value === this.selectedValue}\n @click=${() => this.onSelect(o.value)}>\n ${o.label}\n </nile-menu-item>\n `)}\n </nile-menu>\n </nile-dropdown>\n `;\n }\n }\n\n // ► Everything else: default (text) dropdown\n const triggerText = current?.label || this.label || 'Select';\n return html`\n <nile-dropdown class=\"rte-default-dd\">\n <nile-button slot=\"trigger\" variant=\"tertiary\" class=\"rte-default-trigger\">\n ${triggerText} <nile-icon name=\"arrowdown\"></nile-icon>\n </nile-button>\n <nile-menu class=\"rte-default-menu\">\n ${opts.map(o => html`\n <nile-menu-item\n ?active=${o.value === this.selectedValue}\n @click=${() => this.onSelect(o.value)}>\n ${o.label}\n </nile-menu-item>\n `)}\n </nile-menu>\n </nile-dropdown>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-rte-select': NileRteSelect;\n }\n}\n"]}
1
+ {"version":3,"file":"nile-rte-select.js","sourceRoot":"","sources":["../../../src/nile-rich-text-editor/nile-rte-select.ts"],"names":[],"mappings":";AAAA,qBAAqB;AACrB,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAOnE,MAAM,iBAAiB,GAA4B,IAAI,GAAG,CAAC;IACzD,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CACxC,CAAC,CAAC;AAEH,SAAS,YAAY,CAAC,CAAS;IAC7B,OAAO,iBAAiB,CAAC,GAAG,CA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I3C;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;iDACmB;AAGtB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4CAAY;AAEtB;IAAhB,KAAK,EAAE;oDAA4B;AAhBzB,aAAa;IADzB,aAAa,CAAC,iBAAiB,CAAC;GACpB,aAAa,CAuLzB","sourcesContent":["// nile-rte-select.ts\nimport { LitElement, html } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\n\ntype HeadingTag = 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';\ntype GenericOption = { value: string; label?: string; icon?: string };\ntype HeadingOption = { value: HeadingTag; label?: string; icon?: string };\ntype NormalizedOption = { value: string; label: string; icon?: string };\n\nconst HEADING_ALLOWLIST: ReadonlySet<HeadingTag> = new Set([\n 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'\n]);\n\nfunction isHeadingTag(v: string): v is HeadingTag {\n return HEADING_ALLOWLIST.has(v as HeadingTag);\n}\n\n@customElement('nile-rte-select')\nexport class NileRteSelect extends LitElement {\n protected createRenderRoot() { return this; }\n\n /** 'heading' | 'font' | 'align' */\n @property({ type: String }) type = '';\n\n /** JSON: [{ value, label?, icon? }, ...] (attribute-based; runtime-validated) */\n @property({ type: String }) options = '[]';\n\n /** Programmatic options (preferred for TS safety). */\n @property({ attribute: false })\n optionsObj?: Array<GenericOption | HeadingOption>;\n\n /** Fallback label for trigger (e.g., \"Align\") */\n @property({ type: String }) label = '';\n\n @state() private selectedValue = '';\n\n private mapAlignIcon(v: string) {\n const map: Record<string,string> = {\n left: 'align-left',\n center: 'align-center',\n right: 'align-right',\n justify: 'nile-justify'\n };\n return map[v] || 'align-left';\n }\n\n private get parsedOptions(): NormalizedOption[] {\n // Prefer programmatic options if present (gives TS compile-time checks)\n const source: unknown = this.optionsObj ?? this.options;\n\n const rawArray: any[] = (() => {\n if (Array.isArray(source)) return source;\n try { return JSON.parse(String(source)); } catch { return []; }\n })();\n\n // Normalize to consistent shape\n let items: NormalizedOption[] = rawArray.map((o: any) => {\n const value: string = o?.value ?? o;\n const label: string = o?.label ?? o?.value ?? o;\n const icon: string | undefined =\n o?.icon ?? (this.type === 'align' ? this.mapAlignIcon(String(value)) : undefined);\n return { value, label, icon };\n });\n\n // If type is heading, enforce allowlist (runtime validation)\n if (this.type === 'heading') {\n const before = items.length;\n items = items.filter(i => isHeadingTag(i.value));\n if (items.length !== before) {\n }\n // If current selection is invalid for heading, reset\n if (this.selectedValue && !isHeadingTag(this.selectedValue)) {\n this.selectedValue = '';\n }\n }\n\n return items;\n }\n\n private ensureDefault() {\n if (!this.selectedValue) {\n const first = this.parsedOptions[0];\n if (first) this.selectedValue = first.value;\n }\n }\n\n private onSelect(value: string) {\n if (this.type === 'heading' && !isHeadingTag(value)) {\n console.warn(`[nile-rte-select] Ignoring invalid heading value: ${value}`);\n return;\n }\n this.selectedValue = value;\n this.dispatchEvent(new CustomEvent('change', {\n detail: value, bubbles: true, composed: true\n }));\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n this.injectLocalStyles();\n }\n\n private injectLocalStyles() {\n if (this.querySelector('style[data-rte-select-style]')) return;\n\n const style = document.createElement('style');\n style.setAttribute('data-rte-select-style', 'true');\n style.textContent = `\n nile-menu.rte-align-menu::part(menu__items-wrapper) {\n display: flex;\n }\n nile-menu.rte-align-menu,\n nile-menu.rte-default-menu {\n margin-top: 0px;\n }\n nile-button.rte-align-trigger::part(base),\n nile-button.rte-default-trigger::part(base) {\n min-width: 32px;\n height: 32px;\n padding: 0px 6px;\n box-shadow: none;\n }\n `;\n this.insertBefore(style, this.firstChild);\n }\n\n render() {\n const opts = this.parsedOptions;\n this.ensureDefault();\n const current = opts.find(o => o.value === this.selectedValue);\n\n // ► Align: icon-only items + icon trigger\n if (this.type === 'align') {\n const trigger = current?.icon\n ? html`<nile-icon name=\"${current.icon}\"></nile-icon>`\n : (this.label || 'Align');\n\n return html`\n <nile-dropdown class=\"rte-align-dd\">\n <nile-button slot=\"trigger\" variant=\"tertiary\" class=\"rte-align-trigger\">\n ${trigger}\n </nile-button>\n <nile-menu class=\"rte-align-menu\">\n ${opts.map(o => html`\n <nile-menu-item\n class=\"rte-align-item\"\n ?active=${o.value === this.selectedValue}\n @click=${() => this.onSelect(o.value)}>\n <nile-icon name=\"${o.icon}\"></nile-icon>\n </nile-menu-item>\n `)}\n </nile-menu>\n </nile-dropdown>\n `;\n }\n\n // ► Font: show labels, preview fonts in items and trigger\n if (this.type === 'font') {\n const triggerText = current?.label || this.label || 'Font';\n return html`\n <nile-dropdown class=\"rte-default-dd\">\n <nile-button\n slot=\"trigger\"\n variant=\"tertiary\"\n class=\"rte-default-trigger\"\n style=\"font-family: ${current?.value || 'inherit'}\">\n ${triggerText} <nile-icon name=\"arrowdown\"></nile-icon>\n </nile-button>\n <nile-menu class=\"rte-default-menu\">\n ${opts.map(o => html`\n <nile-menu-item\n style=\"font-family: ${o.value}\"\n ?active=${o.value === this.selectedValue}\n @click=${() => this.onSelect(o.value)}>\n ${o.label}\n </nile-menu-item>\n `)}\n </nile-menu>\n </nile-dropdown>\n `;\n }\n\n // ► Default (e.g., heading): text items; heading values are validated already\n const triggerText = current?.label || this.label || 'Select';\n return html`\n <nile-dropdown class=\"rte-default-dd\">\n <nile-button slot=\"trigger\" variant=\"tertiary\" class=\"rte-default-trigger\">\n ${triggerText} <nile-icon name=\"arrowdown\"></nile-icon>\n </nile-button>\n <nile-menu class=\"rte-default-menu\">\n ${opts.map(o => html`\n <nile-menu-item\n ?active=${o.value === this.selectedValue}\n @click=${() => this.onSelect(o.value)}>\n ${o.label}\n </nile-menu-item>\n `)}\n </nile-menu>\n </nile-dropdown>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-rte-select': NileRteSelect;\n }\n}\n"]}
@@ -7,6 +7,7 @@ export declare function toggleInlineTag(root: HTMLElement, tag: 'strong' | 'em'
7
7
  export declare function setBlockTag(root: HTMLElement, tag: 'p' | 'h1' | 'h2' | 'h3'): void;
8
8
  export declare function setAlignment(root: HTMLElement, align: 'left' | 'center' | 'right' | 'justify'): void;
9
9
  export declare function setFontFamily(root: HTMLElement, family: string): void;
10
+ export declare function setBackColor(rootEl: HTMLElement, color: string): void;
10
11
  export declare function setForeColor(root: HTMLElement, color: string): void;
11
12
  export declare function toggleList(root: HTMLElement, kind: 'ul' | 'ol'): void;
12
13
  export declare function insertOrEditLink(root: HTMLElement, href?: string): void;
@@ -127,6 +127,23 @@ export function setFontFamily(root, family) {
127
127
  }
128
128
  surroundInline(range, 'span', { style: `font-family:${family}` });
129
129
  }
130
+ export function setBackColor(rootEl, color) {
131
+ const sel = window.getSelection();
132
+ if (!sel || sel.rangeCount === 0)
133
+ return;
134
+ const range = sel.getRangeAt(0);
135
+ if (!rootEl.contains(range.commonAncestorContainer) || range.collapsed)
136
+ return;
137
+ const span = document.createElement('span');
138
+ span.style.backgroundColor = color;
139
+ span.appendChild(range.extractContents());
140
+ range.insertNode(span);
141
+ const after = document.createRange();
142
+ after.setStartAfter(span);
143
+ after.collapse(true);
144
+ sel.removeAllRanges();
145
+ sel.addRange(after);
146
+ }
130
147
  export function setForeColor(root, color) {
131
148
  const sel = document.getSelection();
132
149
  if (!sel || sel.rangeCount === 0)
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/nile-rich-text-editor/utils.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,MAAM,UAAU,YAAY,CAAC,IAAiB,EAAE,IAAiB;IAC7D,OAAO,IAAI,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAC7B,IAAI,IAAI,YAAY,WAAW,EAAE,CAAC;YAChC,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;YAC/C,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,gCAAgC,CAAC,IAAI,OAAO,KAAK,OAAO,IAAI,OAAO,K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IAAI,GAAG,GAAG,CAAC;IAC1D,IAAI,CAAC;QAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAAC,CAAC;IACrC,MAAM,CAAC;QAAC,MAAM,IAAI,GAAG,KAAK,CAAC,eAAe,EAAE,CAAC;QAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAAC,CAAC;AACjG,CAAC","sourcesContent":["// src/nile-rich-text-editor/utils.ts\nexport function closestBlock(node: Node | null, root: HTMLElement): HTMLElement | null {\n while (node && node !== root) {\n if (node instanceof HTMLElement) {\n const display = getComputedStyle(node).display;\n if (node.tagName.match(/^(P|DIV|H1|H2|H3|H4|H5|H6|LI)$/) || display === 'block' || display === 'list-item') {\n return node;\n }\n }\n node = node?.parentNode || null;\n }\n return root;\n }\n \n export function nearestElement(n: Node | null): HTMLElement | null {\n while (n && !(n instanceof HTMLElement)) n = n.parentNode as Node | null;\n return n as HTMLElement | null;\n }\n \n export function rgbToHex(rgb: string): string {\n const m = rgb.match(/rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)/i);\n if (!m) return '#000000';\n const r = Number(m[1]).toString(16).padStart(2,'0');\n const g = Number(m[2]).toString(16).padStart(2,'0');\n const b = Number(m[3]).toString(16).padStart(2,'0');\n return `#${r}${g}${b}`;\n }\n \n export function unwrap(node: HTMLElement) {\n const p = node.parentNode; if (!p) return;\n while (node.firstChild) p.insertBefore(node.firstChild, node);\n p.removeChild(node);\n }\n \n export function surroundInline(range: Range, tag: string, attrs?: Record<string,string>) {\n const wrap = document.createElement(tag);\n if (attrs) Object.entries(attrs).forEach(([k,v]) => wrap.setAttribute(k, v));\n try { range.surroundContents(wrap); }\n catch {\n const frag = range.extractContents();\n wrap.appendChild(frag);\n range.insertNode(wrap);\n }\n }\n \n export function toggleInlineTag(root: HTMLElement, tag: 'strong'|'em'|'u'|'span', attrs?: Record<string,string>) {\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n \n if (range.collapsed) {\n const elm = document.createElement(tag);\n if (attrs) Object.entries(attrs).forEach(([k,v]) => elm.setAttribute(k,v));\n elm.appendChild(document.createTextNode('\\u200b'));\n range.insertNode(elm);\n const r = document.createRange();\n r.setStart(elm.firstChild!, 1);\n r.collapse(true);\n sel.removeAllRanges(); sel.addRange(r);\n return;\n }\n \n let n: Node | null = range.startContainer;\n let target: HTMLElement | null = null;\n while (n && n !== root) {\n if (n instanceof HTMLElement && n.tagName.toLowerCase() === tag) { target = n; break; }\n n = n.parentNode;\n }\n if (target) unwrap(target); else surroundInline(range, tag, attrs);\n }\n \n export function setBlockTag(root: HTMLElement, tag: 'p'|'h1'|'h2'|'h3') {\n const sel = document.getSelection(); if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n const block = closestBlock(range.startContainer, root); if (!block) return;\n if (block.tagName.toLowerCase() === tag) return;\n const nb = document.createElement(tag);\n while (block.firstChild) nb.appendChild(block.firstChild);\n block.replaceWith(nb);\n const r = document.createRange(); r.selectNodeContents(nb); r.collapse(true);\n sel.removeAllRanges(); sel.addRange(r);\n }\n \n export function setAlignment(root: HTMLElement, align: 'left'|'center'|'right'|'justify') {\n const sel = document.getSelection(); if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n const block = closestBlock(range.startContainer, root); if (!block) return;\n block.style.textAlign = align === 'justify' ? 'justify' : align;\n }\n \n export function setFontFamily(root: HTMLElement, family: string) {\n const sel = document.getSelection(); if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n if (range.collapsed) {\n const span = document.createElement('span');\n span.style.fontFamily = family;\n span.appendChild(document.createTextNode('\\u200b'));\n range.insertNode(span);\n const r = document.createRange(); r.setStart(span.firstChild!, 1); r.collapse(true);\n sel.removeAllRanges(); sel.addRange(r);\n return;\n }\n surroundInline(range, 'span', { style: `font-family:${family}` });\n }\n \n export function setForeColor(root: HTMLElement, color: string) {\n const sel = document.getSelection(); if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n if (range.collapsed) {\n const span = document.createElement('span');\n span.style.color = color;\n span.appendChild(document.createTextNode('\\u200b'));\n range.insertNode(span);\n const r = document.createRange(); r.setStart(span.firstChild!, 1); r.collapse(true);\n sel.removeAllRanges(); sel.addRange(r);\n return;\n }\n surroundInline(range, 'span', { style: `color:${color}` });\n }\n \n export function toggleList(root: HTMLElement, kind: 'ul'|'ol') {\n const sel = document.getSelection(); if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n const block = closestBlock(range.startContainer, root); if (!block) return;\n \n let li = block.closest('li');\n if (li) {\n const list = li.closest('ul,ol') as HTMLElement | null;\n if (!list) return;\n if (list.tagName.toLowerCase() === kind) {\n const parent = list.parentElement!;\n const frag = document.createDocumentFragment();\n for (const child of Array.from(list.children)) {\n if (child.tagName.toLowerCase() === 'li') {\n const p = document.createElement('p');\n while (child.firstChild) p.appendChild(child.firstChild);\n frag.appendChild(p);\n }\n }\n parent.replaceChild(frag, list);\n } else {\n const newList = document.createElement(kind);\n while (list.firstChild) newList.appendChild(list.firstChild);\n list.replaceWith(newList);\n }\n return;\n }\n \n const list = document.createElement(kind);\n const item = document.createElement('li'); list.appendChild(item);\n while (block.firstChild) item.appendChild(block.firstChild);\n block.replaceWith(list);\n }\n \n export function insertOrEditLink(root: HTMLElement, href?: string) {\n const sel = document.getSelection(); if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n \n let n: Node | null = range.startContainer;\n let a: HTMLAnchorElement | null = null;\n while (n && n !== root) { if (n instanceof HTMLAnchorElement) { a = n; break; } n = n.parentNode; }\n \n const url = href ?? (typeof window !== 'undefined' ? window.prompt('Enter URL', a?.href || 'https://') || '' : '');\n if (!url) return;\n \n if (a) { a.href = url; return; }\n \n if (range.collapsed) {\n const link = document.createElement('a'); link.href = url; link.textContent = url; range.insertNode(link);\n const r = document.createRange(); r.setStartAfter(link); r.collapse(true);\n sel.removeAllRanges(); sel.addRange(r);\n return;\n }\n \n const link = document.createElement('a'); link.href = url;\n try { range.surroundContents(link); }\n catch { const frag = range.extractContents(); link.appendChild(frag); range.insertNode(link); }\n }\n "]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/nile-rich-text-editor/utils.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,MAAM,UAAU,YAAY,CAAC,IAAiB,EAAE,IAAiB;IAC7D,OAAO,IAAI,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAC7B,IAAI,IAAI,YAAY,WAAW,EAAE,CAAC;YAChC,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;YAC/C,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,gCAAgC,CAAC,IAAI,OAAO,KAAK,OAAO,IAAI,OAAO,KAAK,WAAW,EAAE,CAAC;gBAC3G,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,IAAI,GAAG,IAAI,EAAE,UAAU,IAAI,IAAI,CAAC;IAClC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,CAAc;IAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,WAAW,CAAC;QAAE,CAAC,GAAG,CAAC,CAAC,UAAyB,CAAC;IACzE,OAAO,CAAuB,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACvD,IAAI,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACzB,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAC,GAAG,CAAC,CAAC;IACpD,M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,GAAG,CAAC,eAAe,EAAE,CAAC;QAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IAED,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAAC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAC1D,IAAI,CAAC;QAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAAC,CAAC;IACrC,MAAM,CAAC;QAAC,MAAM,IAAI,GAAG,KAAK,CAAC,eAAe,EAAE,CAAC;QAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAAC,CAAC;AACjG,CAAC","sourcesContent":["// src/nile-rich-text-editor/utils.ts\nexport function closestBlock(node: Node | null, root: HTMLElement): HTMLElement | null {\n while (node && node !== root) {\n if (node instanceof HTMLElement) {\n const display = getComputedStyle(node).display;\n if (node.tagName.match(/^(P|DIV|H1|H2|H3|H4|H5|H6|LI)$/) || display === 'block' || display === 'list-item') {\n return node;\n }\n }\n node = node?.parentNode || null;\n }\n return root;\n }\n \n export function nearestElement(n: Node | null): HTMLElement | null {\n while (n && !(n instanceof HTMLElement)) n = n.parentNode as Node | null;\n return n as HTMLElement | null;\n }\n \n export function rgbToHex(rgb: string): string {\n const m = rgb.match(/rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)/i);\n if (!m) return '#000000';\n const r = Number(m[1]).toString(16).padStart(2,'0');\n const g = Number(m[2]).toString(16).padStart(2,'0');\n const b = Number(m[3]).toString(16).padStart(2,'0');\n return `#${r}${g}${b}`;\n }\n \n export function unwrap(node: HTMLElement) {\n const p = node.parentNode; if (!p) return;\n while (node.firstChild) p.insertBefore(node.firstChild, node);\n p.removeChild(node);\n }\n \n export function surroundInline(range: Range, tag: string, attrs?: Record<string,string>) {\n const wrap = document.createElement(tag);\n if (attrs) Object.entries(attrs).forEach(([k,v]) => wrap.setAttribute(k, v));\n try { range.surroundContents(wrap); }\n catch {\n const frag = range.extractContents();\n wrap.appendChild(frag);\n range.insertNode(wrap);\n }\n }\n \n export function toggleInlineTag(root: HTMLElement, tag: 'strong'|'em'|'u'|'span', attrs?: Record<string,string>) {\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n \n if (range.collapsed) {\n const elm = document.createElement(tag);\n if (attrs) Object.entries(attrs).forEach(([k,v]) => elm.setAttribute(k,v));\n elm.appendChild(document.createTextNode('\\u200b'));\n range.insertNode(elm);\n const r = document.createRange();\n r.setStart(elm.firstChild!, 1);\n r.collapse(true);\n sel.removeAllRanges(); sel.addRange(r);\n return;\n }\n \n let n: Node | null = range.startContainer;\n let target: HTMLElement | null = null;\n while (n && n !== root) {\n if (n instanceof HTMLElement && n.tagName.toLowerCase() === tag) { target = n; break; }\n n = n.parentNode;\n }\n if (target) unwrap(target); else surroundInline(range, tag, attrs);\n }\n \n export function setBlockTag(root: HTMLElement, tag: 'p'|'h1'|'h2'|'h3') {\n const sel = document.getSelection(); if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n const block = closestBlock(range.startContainer, root); if (!block) return;\n if (block.tagName.toLowerCase() === tag) return;\n const nb = document.createElement(tag);\n while (block.firstChild) nb.appendChild(block.firstChild);\n block.replaceWith(nb);\n const r = document.createRange(); r.selectNodeContents(nb); r.collapse(true);\n sel.removeAllRanges(); sel.addRange(r);\n }\n \n export function setAlignment(root: HTMLElement, align: 'left'|'center'|'right'|'justify') {\n const sel = document.getSelection(); if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n const block = closestBlock(range.startContainer, root); if (!block) return;\n block.style.textAlign = align === 'justify' ? 'justify' : align;\n }\n \n export function setFontFamily(root: HTMLElement, family: string) {\n const sel = document.getSelection(); if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n if (range.collapsed) {\n const span = document.createElement('span');\n span.style.fontFamily = family;\n span.appendChild(document.createTextNode('\\u200b'));\n range.insertNode(span);\n const r = document.createRange(); r.setStart(span.firstChild!, 1); r.collapse(true);\n sel.removeAllRanges(); sel.addRange(r);\n return;\n }\n surroundInline(range, 'span', { style: `font-family:${family}` });\n }\n\nexport function setBackColor(rootEl: HTMLElement, color: string) {\n const sel = window.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n if (!rootEl.contains(range.commonAncestorContainer) || range.collapsed) return;\n\n const span = document.createElement('span');\n span.style.backgroundColor = color;\n span.appendChild(range.extractContents());\n range.insertNode(span);\n const after = document.createRange();\n after.setStartAfter(span);\n after.collapse(true);\n sel.removeAllRanges();\n sel.addRange(after);\n}\n\n \n export function setForeColor(root: HTMLElement, color: string) {\n const sel = document.getSelection(); if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n if (range.collapsed) {\n const span = document.createElement('span');\n span.style.color = color;\n span.appendChild(document.createTextNode('\\u200b'));\n range.insertNode(span);\n const r = document.createRange(); r.setStart(span.firstChild!, 1); r.collapse(true);\n sel.removeAllRanges(); sel.addRange(r);\n return;\n }\n surroundInline(range, 'span', { style: `color:${color}` });\n }\n \n export function toggleList(root: HTMLElement, kind: 'ul'|'ol') {\n const sel = document.getSelection(); if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n const block = closestBlock(range.startContainer, root); if (!block) return;\n \n let li = block.closest('li');\n if (li) {\n const list = li.closest('ul,ol') as HTMLElement | null;\n if (!list) return;\n if (list.tagName.toLowerCase() === kind) {\n const parent = list.parentElement!;\n const frag = document.createDocumentFragment();\n for (const child of Array.from(list.children)) {\n if (child.tagName.toLowerCase() === 'li') {\n const p = document.createElement('p');\n while (child.firstChild) p.appendChild(child.firstChild);\n frag.appendChild(p);\n }\n }\n parent.replaceChild(frag, list);\n } else {\n const newList = document.createElement(kind);\n while (list.firstChild) newList.appendChild(list.firstChild);\n list.replaceWith(newList);\n }\n return;\n }\n \n const list = document.createElement(kind);\n const item = document.createElement('li'); list.appendChild(item);\n while (block.firstChild) item.appendChild(block.firstChild);\n block.replaceWith(list);\n }\n \n export function insertOrEditLink(root: HTMLElement, href?: string) {\n const sel = document.getSelection(); if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n \n let n: Node | null = range.startContainer;\n let a: HTMLAnchorElement | null = null;\n while (n && n !== root) { if (n instanceof HTMLAnchorElement) { a = n; break; } n = n.parentNode; }\n \n const url = href ?? (typeof window !== 'undefined' ? window.prompt('Enter URL', a?.href || 'https://') || '' : '');\n if (!url) return;\n \n if (a) { a.href = url; return; }\n \n if (range.collapsed) {\n const link = document.createElement('a'); link.href = url; link.textContent = url; range.insertNode(link);\n const r = document.createRange(); r.setStartAfter(link); r.collapse(true);\n sel.removeAllRanges(); sel.addRange(r);\n return;\n }\n \n const link = document.createElement('a'); link.href = url;\n try { range.surroundContents(link); }\n catch { const frag = range.extractContents(); link.appendChild(frag); range.insertNode(link); }\n }\n "]}