@aquera/nile-elements 0.1.67-beta-1.4 → 0.1.67-beta-1.6

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 (57) hide show
  1. package/demo/index.html +13 -6
  2. package/dist/index.js +143 -247
  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 +68 -172
  8. package/dist/nile-rich-text-editor/nile-rich-text-editor.esm.js +1 -1
  9. package/dist/nile-rich-text-editor/nile-rte-select.cjs.js +1 -1
  10. package/dist/nile-rich-text-editor/nile-rte-select.cjs.js.map +1 -1
  11. package/dist/nile-rich-text-editor/nile-rte-select.esm.js +39 -39
  12. package/dist/nile-rich-text-editor/utils.cjs.js.map +1 -1
  13. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js +68 -172
  14. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js.map +1 -1
  15. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.d.ts +0 -3
  16. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js +35 -125
  17. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js.map +1 -1
  18. package/dist/src/nile-rich-text-editor/nile-rte-select.js +62 -57
  19. package/dist/src/nile-rich-text-editor/nile-rte-select.js.map +1 -1
  20. package/dist/src/nile-rich-text-editor/rte-utils/content.d.ts +2 -0
  21. package/dist/src/nile-rich-text-editor/rte-utils/content.js +25 -0
  22. package/dist/src/nile-rich-text-editor/rte-utils/content.js.map +1 -0
  23. package/dist/src/nile-rich-text-editor/rte-utils/css.d.ts +1 -0
  24. package/dist/src/nile-rich-text-editor/rte-utils/css.js +9 -0
  25. package/dist/src/nile-rich-text-editor/rte-utils/css.js.map +1 -0
  26. package/dist/src/nile-rich-text-editor/rte-utils/dom.d.ts +2 -0
  27. package/dist/src/nile-rich-text-editor/rte-utils/dom.js +48 -0
  28. package/dist/src/nile-rich-text-editor/rte-utils/dom.js.map +1 -0
  29. package/dist/src/nile-rich-text-editor/rte-utils/formatting.d.ts +2 -0
  30. package/dist/src/nile-rich-text-editor/rte-utils/formatting.js +69 -0
  31. package/dist/src/nile-rich-text-editor/rte-utils/formatting.js.map +1 -0
  32. package/dist/src/nile-rich-text-editor/rte-utils/keys.d.ts +2 -0
  33. package/dist/src/nile-rich-text-editor/rte-utils/keys.js +38 -0
  34. package/dist/src/nile-rich-text-editor/rte-utils/keys.js.map +1 -0
  35. package/dist/src/nile-rich-text-editor/rte-utils/lists.d.ts +2 -0
  36. package/dist/src/nile-rich-text-editor/rte-utils/lists.js +28 -0
  37. package/dist/src/nile-rich-text-editor/rte-utils/lists.js.map +1 -0
  38. package/dist/src/nile-rich-text-editor/rte-utils/selection.d.ts +17 -0
  39. package/dist/src/nile-rich-text-editor/rte-utils/selection.js +39 -0
  40. package/dist/src/nile-rich-text-editor/rte-utils/selection.js.map +1 -0
  41. package/dist/src/nile-rich-text-editor/rte-utils/toolbar.d.ts +28 -0
  42. package/dist/src/nile-rich-text-editor/rte-utils/toolbar.js +161 -0
  43. package/dist/src/nile-rich-text-editor/rte-utils/toolbar.js.map +1 -0
  44. package/dist/src/nile-rich-text-editor/rte-utils/toolbarState.d.ts +13 -0
  45. package/dist/src/nile-rich-text-editor/rte-utils/toolbarState.js +119 -0
  46. package/dist/src/nile-rich-text-editor/rte-utils/toolbarState.js.map +1 -0
  47. package/dist/src/nile-rich-text-editor/rte-utils/vars.d.ts +1 -0
  48. package/dist/src/nile-rich-text-editor/rte-utils/vars.js +14 -0
  49. package/dist/src/nile-rich-text-editor/rte-utils/vars.js.map +1 -0
  50. package/dist/src/nile-rich-text-editor/utils.js.map +1 -1
  51. package/dist/tsconfig.tsbuildinfo +1 -1
  52. package/package.json +1 -1
  53. package/src/nile-rich-text-editor/nile-rich-text-editor.css.ts +68 -172
  54. package/src/nile-rich-text-editor/nile-rich-text-editor.ts +74 -160
  55. package/src/nile-rich-text-editor/nile-rte-select.ts +178 -173
  56. package/src/nile-rich-text-editor/utils.ts +342 -341
  57. package/vscode-html-custom-data.json +1 -1
@@ -1,211 +1,107 @@
1
1
  import{css as e}from"lit";const r=e`
2
- /* ---- SAFER RESET INSIDE THE EDITOR -------------------------------------- */
3
- .editor * {
4
- all: revert; /* keep your reset… */
5
- box-sizing: border-box; /* …but preserve sane layout */
6
- overflow-wrap: anywhere; /* break long words/URLs */
7
- word-break: break-word;
2
+ .editor * {
3
+ all: revert;
8
4
  }
9
5
 
10
- /* Let component & editor shrink inside flex/grid parents */
11
- nile-rich-text-editor,
12
- .editor {
13
- display: block;
14
- min-width: 0;
15
- max-width: 100%;
16
- font-family: inherit;
17
- }
18
-
19
- /* ---- TOOLBAR ------------------------------------------------------------- */
20
- nile-rte-toolbar,
21
- .toolbar {
22
- display: flex;
23
- flex-wrap: wrap; /* allow wrapping to next row */
24
- align-items: center;
25
- gap: 8px;
26
- padding: 8px;
27
- border: 1px solid #e5e7eb;
28
- border-bottom: none;
29
- border-radius: 8px 8px 0 0;
30
- background: #fff;
31
- box-sizing: border-box;
32
- width: 100%;
33
- }
34
-
35
- /* allow children to shrink instead of forcing overflow */
36
- nile-rte-toolbar > *,
37
- .toolbar > * {
38
- flex: 0 1 auto;
39
- min-width: 0;
40
- }
6
+ nile-rich-text-editor { position: relative; display: block; font-family: inherit; }
41
7
 
42
- /* buttons */
8
+
43
9
  nile-rte-toolbar-item > nile-button::part(base) {
44
- width: 32px;
45
- height: 32px;
46
- padding: 0 6px;
10
+
11
+ width:32px; height:32px; padding:0px 6px;
47
12
  border: none;
48
13
  }
49
-
50
- nile-rte-toolbar-item > button,
51
- .toolbar button,
52
- nile-rte-toolbar button {
53
- border: 1px solid #e5e7eb;
54
- background: #fff;
55
- border-radius: 6px;
56
- cursor: pointer;
57
- }
58
-
59
- nile-rte-toolbar-item > button nile-icon { pointer-events: none; }
60
-
61
- nile-rte-toolbar-item > button.active {
62
- border-color: #2563eb;
63
- background: #eff6ff;
64
- }
65
-
66
- /* selects should be able to shrink on small screens */
67
- nile-rte-select select {
68
- height: 32px;
69
- border: 1px solid #e5e7eb;
70
- border-radius: 6px;
71
- background: #fff;
72
- min-width: 0;
73
- max-width: 100%;
74
- }
75
-
76
- /* color input */
77
- nile-rte-color input[type="color"] {
78
- height: 32px;
79
- width: 36px;
80
- border: 1px solid #e5e7eb;
81
- padding: 0;
82
- border-radius: 6px;
83
- background: #fff;
84
- }
85
-
86
- nile-rte-divider {
87
- width: 1px;
88
- height: 20px;
89
- background: #e5e7eb;
90
- display: inline-block;
91
- margin: 0 4px;
92
- }
93
-
94
- /* ---- EDITOR AREA --------------------------------------------------------- */
95
- .editor {
96
- min-height: 160px;
97
- padding: 12px;
98
- border: 1px solid #e5e7eb;
99
- border-radius: 0 0 8px 8px;
100
- background: #fff;
101
- outline: none;
102
- white-space: pre-wrap;
103
- tab-size: 4;
104
- -moz-tab-size: 4;
105
- overflow-wrap: anywhere;
106
- box-sizing: border-box;
107
- width: 100%;
108
- }
109
-
110
14
 
111
- .editor p { margin: 1em 0; }
112
- .editor h1, .editor h2, .editor h3, .editor h4, .editor h5, .editor h6 {
113
- margin-left: 0;
114
- margin-right: 0;
115
- font-weight: bold;
116
- }
117
- .editor h1 { font-size: 2em; margin: 0.67em 0; }
118
- .editor h2 { font-size: 1.5em; margin: 0.83em 0; }
119
- .editor h3 { font-size: 1.17em; margin: 1em 0; }
120
- .editor h4 { font-size: 1em; margin: 1.33em 0; }
121
- .editor h5 { font-size: 0.83em; margin: 1.67em 0; }
122
- .editor h6 { font-size: 0.67em; margin: 2.33em 0; }
123
-
124
- /* Keep typical wide content inside the box */
125
- .editor img,
126
- .editor svg,
127
- .editor table,
128
- .editor pre,
129
- .editor code,
130
- .editor blockquote {
131
- max-width: 100%;
132
- box-sizing: border-box;
133
- }
134
-
135
- /* Make <pre> wrap on small screens */
136
- .editor pre {
137
- white-space: pre-wrap;
138
- word-break: break-word;
139
- }
140
-
141
- /* Long links shouldn’t push layout */
142
- .editor a { word-break: break-all; }
15
+
143
16
 
144
- /* ---- PREVIEW ------------------------------------------------------------- */
145
- nile-rte-preview {
146
- display: block;
147
- margin-top: 10px;
148
- padding: 10px;
149
- border: 1px dashed #cbd5e1;
150
- border-radius: 8px;
151
- background: #fafafa;
152
- }
153
17
 
154
- /* ---- COLOR TRIGGER (unchanged) ------------------------------------------ */
155
- .rte-color-trigger {
18
+ .toolbar, nile-rte-toolbar {
19
+ display:flex; align-items:center; gap:6px; padding:8px;
20
+ border:1px solid #e5e7eb; border-bottom:none; border-radius:8px 8px 0 0; background:#fff;
21
+ }
22
+
23
+ nile-rte-toolbar-item > button, .toolbar button, nile-rte-toolbar button {
24
+ border:1px solid #e5e7eb; background:#fff; border-radius:6px;
25
+ cursor:pointer;
26
+ }
27
+
28
+
29
+ /* Ensure clicks hit the button (not nested icon internals) */
30
+ nile-rte-toolbar-item > button nile-icon { pointer-events:none; }
31
+
32
+ nile-rte-toolbar-item > button.active { border-color:#2563eb; background:#eff6ff; }
33
+ nile-rte-select select { height:32px; border:1px solid #e5e7eb; border-radius:6px; background:#fff; }
34
+ nile-rte-color input[type="color"] { height:32px; width:36px; border:1px solid #e5e7eb; padding:0; border-radius:6px; background:#fff; }
35
+ nile-rte-divider { width:1px; height:20px; background:#e5e7eb; display:inline-block; margin:0 4px; }
36
+
37
+ .editor p { margin:1em 0; }
38
+ .editor h1 { font-size:2em, all: revert; display: block;
39
+ font-size: 2em;
40
+ margin-top: 0.67em;
41
+ margin-bottom: 0.67em;
42
+ margin-left: 0;
43
+ margin-right: 0;
44
+ font-weight: bold; }
45
+ .editor h2 { all: revert; display: block;
46
+ font-size: 1.5em;
47
+ margin-top: 0.83em;
48
+ margin-bottom: 0.83em;
49
+ margin-left: 0;
50
+ margin-right: 0;
51
+ font-weight: bold;}
52
+ .editor h3 { font-size:1.17em }
53
+ .editor h4 { font-size:1em }
54
+ .editor h5 { font-size:0.83em }
55
+ .editor h6 { font-size:0.67em }
56
+
57
+ .editor { min-height:160px; padding:12px; border:1px solid #e5e7eb; border-radius:0 0 8px 8px; background:#fff; outline:none; white-space: pre-wrap;
58
+ tab-size: 4;
59
+ -moz-tab-size: 4; }
60
+ nile-rte-preview { display:block; margin-top:10px; padding:10px; border:1px dashed #cbd5e1; border-radius:8px; background:#fafafa; }
61
+
62
+ .rte-color-trigger {
156
63
  display: inline-flex;
157
64
  align-items: center;
158
65
  justify-content: center;
159
- height: 28px;
160
- padding: 0 8px;
161
- border: 1px solid var(--nile-color-border, #d9d9d9);
66
+ /* border: 1px solid var(--nile-color-border, #d9d9d9); */
162
67
  border-radius: 6px;
163
68
  background: #fff;
164
69
  cursor: pointer;
70
+ border:none;
71
+
72
+
73
+ }
74
+ nile-button.rte-color-trigger::part(base){
75
+ width:32px; height:32px; padding:0px 6px;
165
76
  }
166
77
  .rte-color-trigger .glyph-stack {
167
- display: grid;
168
- grid-auto-rows: max-content;
78
+ display: grid; /* stack vertically */
79
+ grid-auto-rows: max-content;
169
80
  align-items: center;
170
81
  justify-items: center;
171
82
  line-height: 1;
172
83
  }
84
+
173
85
  .rte-color-trigger .glyph {
174
86
  font-size: 14px;
175
87
  line-height: 1;
176
- margin-bottom: 2px;
88
+ margin-bottom: 2px;
177
89
  }
90
+
178
91
  .rte-color-trigger .underline {
179
92
  width: 18px;
180
93
  height: 3px;
181
94
  border-radius: 2px;
182
- background: currentColor;
95
+ background: currentColor;
183
96
  }
97
+
98
+
184
99
  .rte-color-trigger .swatch-box {
185
100
  width: 18px;
186
101
  height: 16px;
187
102
  border-radius: 4px;
188
103
  border: 1px solid rgba(0,0,0,0.35);
189
- background: currentColor;
104
+ background: currentColor; /* overridden via JS */
190
105
  }
191
106
 
192
- /* ---- RESPONSIVE TWEAKS --------------------------------------------------- */
193
- @media (max-width: 900px) {
194
- nile-rte-toolbar { gap: 6px; padding: 6px; }
195
- nile-rte-select select { max-width: 160px; }
196
- }
197
-
198
- @media (max-width: 600px) {
199
- nile-rte-toolbar { gap: 4px; }
200
- nile-rte-select select { max-width: 120px; }
201
- /* optional fallback if wrapping still feels tight */
202
- /* nile-rte-toolbar { overflow-x: auto; } */
203
- }
204
-
205
- @media (max-width: 420px) {
206
- nile-rte-select select { max-width: 100px; }
207
- nile-rte-divider { display: none; }
208
- }
209
-
210
-
211
107
  `;export{r as s};
@@ -1 +1 @@
1
- import{__decorate as t}from"tslib";import{LitElement as i}from"lit";import{property as s,state as e,customElement as n}from"lit/decorators.js";import"./nile-rte-toolbar.esm.js";import"./nile-rte-toolbar-item.esm.js";import"./nile-rte-select.esm.js";import"./nile-rte-color.esm.js";import"./nile-rte-divider.esm.js";import"./nile-rte-preview.esm.js";import"./nile-rte-mentions.esm.js";import{s as o,a as r,b as h,c as l,d as c,i as a,t as u,n as d,e as f,r as m}from"./utils.esm.js";import{s as p}from"./nile-rich-text-editor.css.esm.js";const b={bold:"format_bold",italic:"format_italic",underline:"format_underline",link:"link_2",left:"format_align_left",center:"format_align_middle",right:"format_align_right",justify:"format_align_justify",ul:"nile-ul",ol:"nile-ol",clear:"error"};let g=class extends i{constructor(){super(...arguments),this.value="",this.mentions={},this.content="",this.previewEl=null,this.toolbarEl=null,this.lastRange=null,this.buttonMap=new Map,this.headingSelect=null,this.fontSelect=null,this.colorInput=null,this.bgColorInput=null,this.colorSwatchEl=null,this.bgSwatchEl=null,this.mentionsEl=null,this.onPaste=t=>{const i=t.clipboardData?.getData("text/html");if(!i)return;t.preventDefault(),this.focusAndRestore();const s=document.createElement("div");s.innerHTML=i;const e=document.createTreeWalker(s,NodeFilter.SHOW_ELEMENT),n=new Set(["width","height","max-width","min-width","margin","padding","position","left","right","top","bottom","float","display","border","line-height","white-space"]);for(;e.nextNode();){const t=e.currentNode;if(t.removeAttribute("width"),t.removeAttribute("height"),t.hasAttribute("style")){const i=(t.getAttribute("style")||"").split(";").map((t=>t.trim())).filter(Boolean).filter((t=>{const i=t.split(":")[0]?.trim().toLowerCase();return i&&!n.has(i)}));i.length?t.setAttribute("style",i.join("; ")):t.removeAttribute("style")}}const o=window.getSelection();if(o&&o.rangeCount){const t=o.getRangeAt(0);t.deleteContents();const i=document.createDocumentFragment();for(;s.firstChild;)i.appendChild(s.firstChild);t.insertNode(i),o.removeAllRanges(),o.addRange(t)}this.ensureAtLeastOneParagraph(),this.updateContent(),this.updateToolbarState()},this.onEditorKeydown=t=>{if("Tab"!==t.key)return;t.preventDefault(),this.focusAndRestore();const i=window.getSelection();if(!i||0===i.rangeCount)return;const s=i.getRangeAt(0);if(t.shiftKey){if(s.collapsed&&s.startContainer.nodeType===Node.TEXT_NODE){const t=s.startContainer,e=s.startOffset,n=t.data.slice(0,e),o=n.replace(/(\t|[ \u00a0]{2})$/,"");if(o.length!==n.length){t.data=o+t.data.slice(e);const s=document.createRange();s.setStart(t,o.length),s.collapse(!0),i.removeAllRanges(),i.addRange(s),this.updateContent(),this.updateToolbarState()}}return}s.deleteContents();const e=document.createTextNode("\t");s.insertNode(e);const n=document.createRange();n.setStartAfter(e),n.collapse(!0),i.removeAllRanges(),i.addRange(n),this.updateContent(),this.updateToolbarState()},this.onSelectionChange=()=>{if(!this.editorEl)return;const t=document.getSelection();if(!t||0===t.rangeCount)return;const i=t.getRangeAt(0);this.editorEl.contains(i.commonAncestorContainer)&&(this.lastRange=i.cloneRange(),this.updateToolbarState())}}createRenderRoot(){return this}shouldUpdate(){return!1}injectCss(t){if(this.querySelector("style[data-rte-style]"))return;const i=document.createElement("style");i.setAttribute("data-rte-style","true"),i.textContent=t,this.insertBefore(i,this.firstChild)}connectedCallback(){super.connectedCallback(),this.injectCss(p.cssText),this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.ensureEditor(),this.value&&!this.editorEl.innerHTML.trim()&&(this.editorEl.innerHTML=this.value),this.content=this.editorEl.innerHTML,this.toolbarEl&&this.wireAuthoredToolbar(this.toolbarEl),this.mentionsEl=this.querySelector("nile-rte-mentions"),this.mentionsEl&&(this.mentionsEl.attach?.(this.editorEl,this),this.mentionsEl.setExternalConfig?.(this.mentions)),this.wireEditor(),this.updateToolbarState(),this.syncPreview(),document.addEventListener("selectionchange",this.onSelectionChange,!0)}disconnectedCallback(){document.removeEventListener("selectionchange",this.onSelectionChange,!0),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),super.disconnectedCallback()}ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){const t=document.createElement("article");t.className="editor",t.setAttribute("contenteditable","true"),this.toolbarEl?.nextSibling?this.insertBefore(t,this.toolbarEl.nextSibling):this.previewEl?this.insertBefore(t,this.previewEl):this.appendChild(t),this.editorEl=t}this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>"),this.ensureAtLeastOneParagraph()}wireEditor(){this.editorEl.addEventListener("input",(()=>{this.ensureAtLeastOneParagraph(),this.updateContent()})),this.editorEl.addEventListener("mouseup",(()=>this.saveSelection())),this.editorEl.addEventListener("keyup",(()=>this.saveSelection())),this.editorEl.addEventListener("keydown",this.onEditorKeydown),this.editorEl.addEventListener("paste",this.onPaste)}wireAuthoredToolbar(t){this.buttonMap.clear(),this.headingSelect=null,this.fontSelect=null,this.colorInput=null,Array.from(t.children).forEach((t=>{const i=t.tagName.toLowerCase();if("nile-rte-select"!==i||"align"!==t.getAttribute("type")){if("nile-rte-toolbar-item"===i){let i=t.querySelector(":scope > nile-button");const s=t.getAttribute("name")||"",e=t.getAttribute("label")||s,n=t.getAttribute("icon"),o=t.innerHTML.trim().length>0;if(i||(i=document.createElement("nile-button"),i.variant="tertiary",i.size="small"),n)i.innerHTML=`<nile-icon name="${n}" aria-label="${e}"></nile-icon>`,t.innerHTML="";else if(o)i.innerHTML=t.innerHTML,t.innerHTML="";else{const n=b[s];n?i.innerHTML=`<nile-icon name="${n}" size="20" color="black" aria-label="${e}"></nile-icon>`:i.textContent=e||s,t.innerHTML=""}i.isConnected||t.appendChild(i),i.setAttribute("aria-label",e),i.addEventListener("mousedown",(t=>t.preventDefault())),i.addEventListener("click",(()=>this.onToolbarCommand(s)));const r=this.buttonMap.get(s)??[];return r.push(i),void this.buttonMap.set(s,r)}if("nile-rte-select"!==i){if("nile-rte-color"===i){const i=t.getAttribute("label")??"Text color",s=t.getAttribute("value")??"#000000",e=t.getAttribute("mode")??"text";let n=t.querySelector(':scope > input[type="color"]');n||(n=document.createElement("input"),n.type="color",n.style.position="absolute",n.style.opacity="0",n.style.pointerEvents="none",t.appendChild(n)),n.title=i,n.value=s;let o=t.querySelector(":scope > button.rte-color-trigger");o||(o=document.createElement("button"),o.type="button",o.className="rte-color-trigger",o.setAttribute("aria-label",i),o.innerHTML="background"===e?'\n <span class="swatch-box" aria-hidden="true"></span>\n ':'\n <span class="glyph-stack" aria-hidden="true">\n <span class="glyph">A</span>\n <span class="underline"></span>\n </span>\n ',t.appendChild(o));const r=o.querySelector(".underline"),h=o.querySelector(".swatch-box");"background"===e?(this.bgColorInput=n,this.bgSwatchEl=h,this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=n.value)):(this.colorInput=n,this.colorSwatchEl=r,this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=n.value)),o.addEventListener("click",(t=>{t.preventDefault(),this.focusAndRestore(),n.click()})),n.addEventListener("input",(()=>{this.focusAndRestore(),"background"===e?(l(this.editorEl,n.value),this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=n.value)):(c(this.editorEl,n.value),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=n.value)),this.updateContent(),this.updateToolbarState()})),o.addEventListener("mousedown",(t=>t.preventDefault())),n.addEventListener("mousedown",(t=>t.preventDefault()))}}else{const i=t.getAttribute("type")||"";t.addEventListener("change",(t=>{this.focusAndRestore();const s=t.detail;"heading"===i?r(this.editorEl,s):"font"===i&&h(this.editorEl,s),this.updateContent(),this.updateToolbarState()}))}}else t.addEventListener("change",(t=>{this.focusAndRestore();const i=t.detail;o(this.editorEl,i),this.updateContent(),this.updateToolbarState()}))}))}saveSelection(){const t=window.getSelection();t&&t.rangeCount&&(this.lastRange=t.getRangeAt(0).cloneRange())}restoreSelection(){if(!this.lastRange)return;const t=document.getSelection();t&&(t.removeAllRanges(),t.addRange(this.lastRange))}focusAndRestore(){this.editorEl?.focus(),this.restoreSelection()}insertList(t){if(this.restoreSelection(),!this.lastRange)return;const i=document.createElement(t),s=this.lastRange.extractContents(),e=document.createElement("div");e.appendChild(s),Array.from(e.childNodes).forEach((t=>{if(t.nodeType===Node.TEXT_NODE&&!t.textContent?.trim())return;const s=document.createElement("li");s.appendChild(t),i.appendChild(s)})),this.lastRange.insertNode(i),this.afterListEdit(i)}afterListEdit(t){const i=document.createRange();i.setStartAfter(t),i.collapse(!0);const s=window.getSelection();s?.removeAllRanges(),s?.addRange(i),this.saveSelection(),this.updateContent(),this.updateToolbarState()}ensureAtLeastOneParagraph(){const t=this.editorEl;if(!t)return;const i=""===(t.textContent??"").replace(/\u200B/g,"").trim();if(0===t.childNodes.length||i)return void(t.innerHTML="<p><br></p>");if(!t.querySelector("p,h1,h2,h3,h4,h5,h6,ul,ol,table,blockquote,pre")){const i=document.createElement("p");for(;t.firstChild;)i.appendChild(t.firstChild);return i.hasChildNodes()||i.appendChild(document.createElement("br")),void t.appendChild(i)}t.querySelectorAll("p").forEach((t=>{""===(t.textContent??"").replace(/\u200B/g,"")&&(t.innerHTML.toLowerCase().includes("<br")||(t.innerHTML="<br>"))}))}onToolbarCommand(t){switch(this.focusAndRestore(),t){case"bold":u(this.editorEl,"strong");break;case"italic":u(this.editorEl,"em");break;case"underline":u(this.editorEl,"u");break;case"left":o(this.editorEl,"left");break;case"center":o(this.editorEl,"center");break;case"right":o(this.editorEl,"right");break;case"justify":o(this.editorEl,"justify");break;case"ul":this.insertList("ul");break;case"ol":this.insertList("ol");break;case"link":a(this.editorEl);break;case"clear":const t=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),i=[];for(;t.nextNode();){const s=t.currentNode;s.removeAttribute("style"),["B","STRONG","I","EM","U","SPAN","FONT"].includes(s.tagName)&&i.push(s)}for(const t of i){for(;t.firstChild;)t.parentNode?.insertBefore(t.firstChild,t);t.remove()}this.ensureAtLeastOneParagraph()}this.updateContent(),this.updateToolbarState()}setBtnActive(t,i){const s=this.buttonMap.get(t);if(s)for(const t of s)t.toggleAttribute("data-active",!!i)}updateToolbarState(){if(!this.editorEl)return;const t=document.getSelection();if(!t||0===t.rangeCount)return;const i=t.getRangeAt(0);if(!this.editorEl.contains(i.commonAncestorContainer))return;const s=d(i.startContainer)||this.editorEl,e=getComputedStyle(s),n=f(i.startContainer,this.editorEl)||this.editorEl,o=(()=>{let t=s;for(;t&&t!==this.editorEl;){if(t instanceof HTMLElement){const i=t.tagName.toLowerCase();if("strong"===i||"b"===i)return!0;const s=getComputedStyle(t).fontWeight;if(parseInt(s,10)>=600)return!0}t=t.parentNode}return!1})(),r=(()=>{let t=s;for(;t&&t!==this.editorEl;){if(t instanceof HTMLElement){const i=t.tagName.toLowerCase();if("em"===i||"i"===i)return!0;if("italic"===getComputedStyle(t).fontStyle)return!0}t=t.parentNode}return!1})(),h=(()=>{let t=s;for(;t&&t!==this.editorEl;){if(t instanceof HTMLElement){const i=getComputedStyle(t).textDecorationLine;if(i&&i.includes("underline"))return!0;if("u"===t.tagName.toLowerCase())return!0}t=t.parentNode}return!1})(),l=!!s.closest("a"),c=n.style.textAlign||getComputedStyle(n).textAlign||"start",a="start"===c?"left":c,u=!!s.closest("li")&&s.closest("ul,ol")?.tagName.toLowerCase()||"";if(this.setBtnActive("bold",o),this.setBtnActive("italic",r),this.setBtnActive("underline",h),this.setBtnActive("link",l),this.setBtnActive("left","left"===a&&!["center","right","justify"].includes(a)),this.setBtnActive("center","center"===a),this.setBtnActive("right","right"===a),this.setBtnActive("justify","justify"===a),this.setBtnActive("ul","ul"===u),this.setBtnActive("ol","ol"===u),this.headingSelect){const t=n.tagName.toLowerCase(),i=["h1","h2","h3"].includes(t)?t:"p";this.headingSelect.value!==i&&(this.headingSelect.value=i)}if(this.fontSelect){const t=(e.fontFamily||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase();if(t)for(const i of Array.from(this.fontSelect.options))if(i.value.toLowerCase()===t){this.fontSelect.value=i.value;break}}if(this.colorInput){const t=m(e.color);t&&this.colorInput.value.toLowerCase()!==t.toLowerCase()&&(this.colorInput.value=t),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=this.colorInput.value)}if(this.bgColorInput){const t=getComputedStyle(s).backgroundColor;if(t&&!/transparent|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/i.test(t)){const i=m(t);i&&this.bgColorInput.value.toLowerCase()!==i.toLowerCase()&&(this.bgColorInput.value=i)}this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=this.bgColorInput.value)}}syncPreview(){this.updateContent()}updateContent(){if(!this.editorEl)return;this.ensureAtLeastOneParagraph();const t=this.editorEl.cloneNode(!0),i=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),s=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT);for(;i.nextNode()&&s.nextNode();){const t=i.currentNode,e=s.currentNode;if(e.removeAttribute("style"),["B","STRONG","I","EM","U","H1","H2","H3","H4","H5","H6"].includes(e.tagName))continue;const n=this.collectMinimalInline(t);n&&e.setAttribute("style",n)}this.content=t.innerHTML,this.previewEl&&(this.previewEl.innerHTML=this.content),this.dispatchEvent(new CustomEvent("content-changed",{detail:{content:this.content},bubbles:!0,composed:!0}))}collectMinimalInline(t){const i=getComputedStyle(t),s=t.parentElement?getComputedStyle(t.parentElement):null,e=[],n=(t,i)=>{i&&e.push(`${t}:${i}`)};if(["P","DIV","LI","TD","TH","BLOCKQUOTE","H1","H2","H3","H4","H5","H6"].includes(t.tagName)){const t=i.textAlign;t!==(s?.textAlign||"start")&&"start"!==t&&n("text-align",t)}s&&i.color===s.color||n("color",i.color);const o=i.backgroundColor;/transparent|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/i.test(o)||n("background-color",o);const r=this.normalizeFontFamily(i.fontFamily),h=this.normalizeFontFamily(s?.fontFamily||"");if(r&&r!==h&&n("font-family",i.fontFamily),"SPAN"===t.tagName||t.style.fontSize){const t=i.fontSize,e=s?.fontSize;e&&t===e||n("font-size",t)}if("UL"===t.tagName||"OL"===t.tagName){const s=i.listStyleType,e="UL"===t.tagName?"disc":"decimal";s&&s!==e&&n("list-style-type",s)}const l=i.textDecorationLine;return l&&"none"!==l&&"U"!==t.tagName&&n("text-decoration-line",l),e.join(";")}normalizeFontFamily(t){return(t||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase()}};t([s({type:String})],g.prototype,"value",void 0),t([s({attribute:"mentions",converter:{fromAttribute:t=>{try{const i=JSON.parse(t),s={};for(const t of Object.keys(i)){const e=i[t];Array.isArray(e)&&(s[t]=e.filter((t=>t&&"string"==typeof t.key&&"string"==typeof t.label)).map((t=>({key:t.key,label:t.label}))))}return s}catch{return{}}},toAttribute:t=>JSON.stringify(t)}})],g.prototype,"mentions",void 0),t([e()],g.prototype,"content",void 0),g=t([n("nile-rich-text-editor")],g);export{g as N};
1
+ import{__decorate as t}from"tslib";import{LitElement as i}from"lit";import{property as s,state as e,customElement as n}from"lit/decorators.js";import"./nile-rte-toolbar.esm.js";import"./nile-rte-toolbar-item.esm.js";import"./nile-rte-select.esm.js";import"./nile-rte-color.esm.js";import"./nile-rte-divider.esm.js";import"./nile-rte-preview.esm.js";import"./nile-rte-mentions.esm.js";import{s as o,a as r,b as h,c as l,d as c,i as a,t as u,n as d,e as f,r as m}from"./utils.esm.js";import{s as p}from"./nile-rich-text-editor.css.esm.js";const b={bold:"format_bold",italic:"format_italic",underline:"format_underline",link:"link_2",left:"format_align_left",center:"format_align_middle",right:"format_align_right",justify:"format_align_justify",ul:"format_list_bulleted",ol:"format_list_numbered",clear:"error"};let g=class extends i{constructor(){super(...arguments),this.value="",this.mentions={},this.content="",this.previewEl=null,this.toolbarEl=null,this.lastRange=null,this.buttonMap=new Map,this.headingSelect=null,this.fontSelect=null,this.colorInput=null,this.bgColorInput=null,this.colorSwatchEl=null,this.bgSwatchEl=null,this.mentionsEl=null,this.onEditorKeydown=t=>{if("Tab"!==t.key)return;t.preventDefault(),this.focusAndRestore();const i=window.getSelection();if(!i||0===i.rangeCount)return;const s=i.getRangeAt(0);if(t.shiftKey){if(s.collapsed&&s.startContainer.nodeType===Node.TEXT_NODE){const t=s.startContainer,e=s.startOffset,n=t.data.slice(0,e),o=n.replace(/(\t|[ \u00a0]{2})$/,"");if(o.length!==n.length){t.data=o+t.data.slice(e);const s=document.createRange();s.setStart(t,o.length),s.collapse(!0),i.removeAllRanges(),i.addRange(s),this.updateContent(),this.updateToolbarState()}}return}s.deleteContents();const e=document.createTextNode("\t");s.insertNode(e);const n=document.createRange();n.setStartAfter(e),n.collapse(!0),i.removeAllRanges(),i.addRange(n),this.updateContent(),this.updateToolbarState()},this.onSelectionChange=()=>{if(!this.editorEl)return;const t=document.getSelection();if(!t||0===t.rangeCount)return;const i=t.getRangeAt(0);this.editorEl.contains(i.commonAncestorContainer)&&(this.lastRange=i.cloneRange(),this.updateToolbarState())}}createRenderRoot(){return this}shouldUpdate(){return!1}injectCss(t){if(this.querySelector("style[data-rte-style]"))return;const i=document.createElement("style");i.setAttribute("data-rte-style","true"),i.textContent=t,this.insertBefore(i,this.firstChild)}connectedCallback(){super.connectedCallback(),this.injectCss(p.cssText),this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.ensureEditor(),this.value&&!this.editorEl.innerHTML.trim()&&(this.editorEl.innerHTML=this.value),this.content=this.editorEl.innerHTML,this.toolbarEl&&this.wireAuthoredToolbar(this.toolbarEl),this.mentionsEl=this.querySelector("nile-rte-mentions"),this.mentionsEl&&(this.mentionsEl.attach?.(this.editorEl,this),this.mentionsEl.setExternalConfig?.(this.mentions)),this.wireEditor(),this.updateToolbarState(),this.syncPreview(),document.addEventListener("selectionchange",this.onSelectionChange,!0)}disconnectedCallback(){document.removeEventListener("selectionchange",this.onSelectionChange,!0),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),super.disconnectedCallback()}ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){const t=document.createElement("article");t.className="editor",t.setAttribute("contenteditable","true"),this.toolbarEl?.nextSibling?this.insertBefore(t,this.toolbarEl.nextSibling):this.previewEl?this.insertBefore(t,this.previewEl):this.appendChild(t),this.editorEl=t}this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>"),this.ensureAtLeastOneParagraph()}wireEditor(){this.editorEl.addEventListener("input",(()=>{this.ensureAtLeastOneParagraph(),this.updateContent()})),this.editorEl.addEventListener("mouseup",(()=>this.saveSelection())),this.editorEl.addEventListener("keyup",(()=>this.saveSelection())),this.editorEl.addEventListener("keydown",this.onEditorKeydown)}wireAuthoredToolbar(t){this.buttonMap.clear(),this.headingSelect=null,this.fontSelect=null,this.colorInput=null,Array.from(t.children).forEach((t=>{const i=t.tagName.toLowerCase();if("nile-rte-select"!==i||"align"!==t.getAttribute("type")){if("nile-rte-toolbar-item"===i){let i=t.querySelector(":scope > nile-button");const s=t.getAttribute("name")||"",e=t.getAttribute("label")||s,n=t.getAttribute("icon"),o=t.innerHTML.trim().length>0;if(i||(i=document.createElement("nile-button"),i.variant="tertiary",i.size="small"),n)i.innerHTML=`<nile-icon name="${n}" aria-label="${e}"></nile-icon>`,t.innerHTML="";else if(o)i.innerHTML=t.innerHTML,t.innerHTML="";else{const n=b[s];n?i.innerHTML=`<nile-icon name="${n}" size="20" color="black" aria-label="${e}"></nile-icon>`:i.textContent=e||s,t.innerHTML=""}i.isConnected||t.appendChild(i),i.setAttribute("aria-label",e),i.addEventListener("mousedown",(t=>t.preventDefault())),i.addEventListener("click",(()=>this.onToolbarCommand(s)));const r=this.buttonMap.get(s)??[];return r.push(i),void this.buttonMap.set(s,r)}if("nile-rte-select"!==i){if("nile-rte-color"===i){const i=t.getAttribute("label")??"Text color",s=t.getAttribute("value")??"#000000",e=t.getAttribute("mode")??"text";let n=t.querySelector(':scope > input[type="color"]');n||(n=document.createElement("input"),n.type="color",n.style.position="absolute",n.style.opacity="0",n.style.pointerEvents="none",t.appendChild(n)),n.title=i,n.value=s;let o=t.querySelector(":scope > nile-button");if(!o){const s=document.createElement("nile-button");s.variant="ghost",s.className="rte-color-trigger",s.setAttribute("aria-label",i),s.innerHTML="background"===e?'<span class="swatch-box" aria-hidden="true"></span>':'\n <span class="glyph-stack" aria-hidden="true">\n <span class="glyph">A</span>\n <span class="underline"></span>\n </span>\n ',t.appendChild(s),o=s}const r=o.querySelector(".underline"),h=o.querySelector(".swatch-box");"background"===e?(this.bgColorInput=n,this.bgSwatchEl=h,this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=n.value)):(this.colorInput=n,this.colorSwatchEl=r,this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=n.value)),o.addEventListener("click",(t=>{t.preventDefault(),this.focusAndRestore(),n.click()})),n.addEventListener("input",(()=>{this.focusAndRestore(),"background"===e?(l(this.editorEl,n.value),this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=n.value)):(c(this.editorEl,n.value),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=n.value)),this.updateContent(),this.updateToolbarState()})),o.addEventListener("mousedown",(t=>t.preventDefault())),n.addEventListener("mousedown",(t=>t.preventDefault()))}}else{const i=t.getAttribute("type")||"";t.addEventListener("change",(t=>{this.focusAndRestore();const s=t.detail;"heading"===i?r(this.editorEl,s):"font"===i&&h(this.editorEl,s),this.updateContent(),this.updateToolbarState()}))}}else t.addEventListener("change",(t=>{this.focusAndRestore();const i=t.detail;o(this.editorEl,i),this.updateContent(),this.updateToolbarState()}))}))}saveSelection(){const t=window.getSelection();t&&t.rangeCount&&(this.lastRange=t.getRangeAt(0).cloneRange())}restoreSelection(){if(!this.lastRange)return;const t=document.getSelection();t&&(t.removeAllRanges(),t.addRange(this.lastRange))}focusAndRestore(){this.editorEl?.focus(),this.restoreSelection()}insertList(t){if(this.restoreSelection(),!this.lastRange)return;const i=document.createElement(t),s=this.lastRange.extractContents(),e=document.createElement("div");e.appendChild(s),Array.from(e.childNodes).forEach((t=>{if(t.nodeType===Node.TEXT_NODE&&!t.textContent?.trim())return;const s=document.createElement("li");s.appendChild(t),i.appendChild(s)})),this.lastRange.insertNode(i),this.afterListEdit(i)}afterListEdit(t){const i=document.createRange();i.setStartAfter(t),i.collapse(!0);const s=window.getSelection();s?.removeAllRanges(),s?.addRange(i),this.saveSelection(),this.updateContent(),this.updateToolbarState()}ensureAtLeastOneParagraph(){const t=this.editorEl;if(!t)return;const i=""===(t.textContent??"").replace(/\u200B/g,"").trim();if(0===t.childNodes.length||i)return void(t.innerHTML="<p><br></p>");if(!t.querySelector("p,h1,h2,h3,h4,h5,h6,ul,ol,table,blockquote,pre")){const i=document.createElement("p");for(;t.firstChild;)i.appendChild(t.firstChild);return i.hasChildNodes()||i.appendChild(document.createElement("br")),void t.appendChild(i)}t.querySelectorAll("p").forEach((t=>{""===(t.textContent??"").replace(/\u200B/g,"")&&(t.innerHTML.toLowerCase().includes("<br")||(t.innerHTML="<br>"))}))}onToolbarCommand(t){switch(this.focusAndRestore(),t){case"bold":u(this.editorEl,"strong");break;case"italic":u(this.editorEl,"em");break;case"underline":u(this.editorEl,"u");break;case"left":o(this.editorEl,"left");break;case"center":o(this.editorEl,"center");break;case"right":o(this.editorEl,"right");break;case"justify":o(this.editorEl,"justify");break;case"ul":this.insertList("ul");break;case"ol":this.insertList("ol");break;case"link":a(this.editorEl);break;case"clear":const t=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),i=[];for(;t.nextNode();){const s=t.currentNode;s.removeAttribute("style"),["B","STRONG","I","EM","U","SPAN","FONT"].includes(s.tagName)&&i.push(s)}for(const t of i){for(;t.firstChild;)t.parentNode?.insertBefore(t.firstChild,t);t.remove()}this.ensureAtLeastOneParagraph()}this.updateContent(),this.updateToolbarState()}setBtnActive(t,i){const s=this.buttonMap.get(t);if(s)for(const t of s)t.toggleAttribute("data-active",!!i)}updateToolbarState(){if(!this.editorEl)return;const t=document.getSelection();if(!t||0===t.rangeCount)return;const i=t.getRangeAt(0);if(!this.editorEl.contains(i.commonAncestorContainer))return;const s=d(i.startContainer)||this.editorEl,e=getComputedStyle(s),n=f(i.startContainer,this.editorEl)||this.editorEl,o=(()=>{let t=s;for(;t&&t!==this.editorEl;){if(t instanceof HTMLElement){const i=t.tagName.toLowerCase();if("strong"===i||"b"===i)return!0;const s=getComputedStyle(t).fontWeight;if(parseInt(s,10)>=600)return!0}t=t.parentNode}return!1})(),r=(()=>{let t=s;for(;t&&t!==this.editorEl;){if(t instanceof HTMLElement){const i=t.tagName.toLowerCase();if("em"===i||"i"===i)return!0;if("italic"===getComputedStyle(t).fontStyle)return!0}t=t.parentNode}return!1})(),h=(()=>{let t=s;for(;t&&t!==this.editorEl;){if(t instanceof HTMLElement){const i=getComputedStyle(t).textDecorationLine;if(i&&i.includes("underline"))return!0;if("u"===t.tagName.toLowerCase())return!0}t=t.parentNode}return!1})(),l=!!s.closest("a"),c=n.style.textAlign||getComputedStyle(n).textAlign||"start",a="start"===c?"left":c,u=!!s.closest("li")&&s.closest("ul,ol")?.tagName.toLowerCase()||"";if(this.setBtnActive("bold",o),this.setBtnActive("italic",r),this.setBtnActive("underline",h),this.setBtnActive("link",l),this.setBtnActive("left","left"===a&&!["center","right","justify"].includes(a)),this.setBtnActive("center","center"===a),this.setBtnActive("right","right"===a),this.setBtnActive("justify","justify"===a),this.setBtnActive("ul","ul"===u),this.setBtnActive("ol","ol"===u),this.headingSelect){const t=n.tagName.toLowerCase(),i=["h1","h2","h3"].includes(t)?t:"p";this.headingSelect.value!==i&&(this.headingSelect.value=i)}if(this.fontSelect){const t=(e.fontFamily||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase();if(t)for(const i of Array.from(this.fontSelect.options))if(i.value.toLowerCase()===t){this.fontSelect.value=i.value;break}}if(this.colorInput){const t=m(e.color);t&&this.colorInput.value.toLowerCase()!==t.toLowerCase()&&(this.colorInput.value=t),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=this.colorInput.value)}if(this.bgColorInput){const t=getComputedStyle(s).backgroundColor;if(t&&!/transparent|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/i.test(t)){const i=m(t);i&&this.bgColorInput.value.toLowerCase()!==i.toLowerCase()&&(this.bgColorInput.value=i)}this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=this.bgColorInput.value)}}syncPreview(){this.updateContent()}updateContent(){if(!this.editorEl)return;this.ensureAtLeastOneParagraph();const t=this.editorEl.cloneNode(!0),i=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),s=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),e=["font-weight","font-style","text-decoration","color","background-color","font-size","font-family","text-align","line-height","letter-spacing","white-space","vertical-align"];for(;i.nextNode()&&s.nextNode();){const t=i.currentNode,n=s.currentNode,o=window.getComputedStyle(t),r=e.map((t=>`${t}:${o.getPropertyValue(t)}`)).join(";");r.trim()&&n.setAttribute("style",r)}this.content=t.innerHTML,this.previewEl&&(this.previewEl.innerHTML=this.content),this.dispatchEvent(new CustomEvent("content-changed",{detail:{content:this.content},bubbles:!0,composed:!0}))}};t([s({type:String})],g.prototype,"value",void 0),t([s({attribute:"mentions",converter:{fromAttribute:t=>{try{const i=JSON.parse(t),s={};for(const t of Object.keys(i)){const e=i[t];Array.isArray(e)&&(s[t]=e.filter((t=>t&&"string"==typeof t.key&&"string"==typeof t.label)).map((t=>({key:t.key,label:t.label}))))}return s}catch{return{}}},toAttribute:t=>JSON.stringify(t)}})],g.prototype,"mentions",void 0),t([e()],g.prototype,"content",void 0),g=t([n("nile-rich-text-editor")],g);export{g as N};
@@ -1,2 +1,2 @@
1
- function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o;}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o;},_typeof(o);}System.register(["tslib","lit","lit/decorators.js"],function(_export,_context){"use strict";var t,e,n,i,l,r,_templateObject,_templateObject2,_templateObject3,_templateObject4,_templateObject5,_templateObject6,_templateObject7,s,o;function _taggedTemplateLiteral(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}));}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function");}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o);}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+"";}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.");}return("string"===r?String:Number)(t);}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e));}function _possibleConstructorReturn(t,e){if(e&&("object"==_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t);}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e;}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t;})();}function _superPropGet(t,o,e,r){var p=_get(_getPrototypeOf(1&r?t.prototype:t),o,e);return 2&r&&"function"==typeof p?function(t){return p.apply(e,t);}:p;}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var p=_superPropBase(e,t);if(p){var n=Object.getOwnPropertyDescriptor(p,t);return n.get?n.get.call(arguments.length<3?e:r):n.value;}},_get.apply(null,arguments);}function _superPropBase(t,o){for(;!{}.hasOwnProperty.call(t,o)&&null!==(t=_getPrototypeOf(t)););return t;}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t);},_getPrototypeOf(t);}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e);}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t;},_setPrototypeOf(t,e);}function a(t){return s.has(t);}return{setters:[function(_tslib){t=_tslib.__decorate;},function(_lit){e=_lit.LitElement;n=_lit.html;},function(_litDecoratorsJs){i=_litDecoratorsJs.property;l=_litDecoratorsJs.state;r=_litDecoratorsJs.customElement;}],execute:function execute(){s=new Set(["p","h1","h2","h3","h4","h5","h6"]);o=/*#__PURE__*/function(_e){function o(){var _this;_classCallCheck(this,o);_this=_callSuper(this,o,arguments),_this.type="",_this.options="[]",_this.label="",_this.selectedValue="";return _this;}_inherits(o,_e);return _createClass(o,[{key:"createRenderRoot",value:function createRenderRoot(){return this;}},{key:"mapAlignIcon",value:function mapAlignIcon(t){return{left:"format_align_left",center:"format_align_middle",right:"format_align_right",justify:"format_align_justify"}[t]||"align-left";}},{key:"parsedOptions",get:function get(){var _this$optionsObj,_this2=this;var t=(_this$optionsObj=this.optionsObj)!==null&&_this$optionsObj!==void 0?_this$optionsObj:this.options;var e=function(){if(Array.isArray(t))return t;try{return JSON.parse(String(t));}catch(_unused){return[];}}().map(function(t){var _t$value,_ref,_t$label,_t$icon;var e=(_t$value=t===null||t===void 0?void 0:t.value)!==null&&_t$value!==void 0?_t$value:t;return{value:e,label:(_ref=(_t$label=t===null||t===void 0?void 0:t.label)!==null&&_t$label!==void 0?_t$label:t===null||t===void 0?void 0:t.value)!==null&&_ref!==void 0?_ref:t,icon:(_t$icon=t===null||t===void 0?void 0:t.icon)!==null&&_t$icon!==void 0?_t$icon:"align"===_this2.type?_this2.mapAlignIcon(String(e)):void 0};});if("heading"===this.type){e.length;e=e.filter(function(t){return a(t.value);}),e.length,this.selectedValue&&!a(this.selectedValue)&&(this.selectedValue="");}return e;}},{key:"ensureDefault",value:function ensureDefault(){if(!this.selectedValue){var _t=this.parsedOptions[0];_t&&(this.selectedValue=_t.value);}}},{key:"onSelect",value:function onSelect(t){"heading"!==this.type||a(t)?(this.selectedValue=t,this.dispatchEvent(new CustomEvent("change",{detail:t,bubbles:!0,composed:!0}))):console.warn("[nile-rte-select] Ignoring invalid heading value: ".concat(t));}},{key:"connectedCallback",value:function connectedCallback(){_superPropGet(o,"connectedCallback",this,3)([]),this.injectLocalStyles();}},{key:"injectLocalStyles",value:function injectLocalStyles(){if(this.querySelector("style[data-rte-select-style]"))return;var t=document.createElement("style");t.setAttribute("data-rte-select-style","true"),t.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 ",this.insertBefore(t,this.firstChild);}},{key:"render",value:function render(){var _this3=this;var t=this.parsedOptions;this.ensureDefault();var e=t.find(function(t){return t.value===_this3.selectedValue;});if("align"===this.type){var _i=e!==null&&e!==void 0&&e.icon?n(_templateObject||(_templateObject=_taggedTemplateLiteral(["<nile-icon name=\"","\"></nile-icon>"])),e.icon):this.label||"Align";return n(_templateObject2||(_templateObject2=_taggedTemplateLiteral(["\n <nile-dropdown class=\"rte-align-dd\">\n <nile-button slot=\"trigger\" variant=\"tertiary\" class=\"rte-align-trigger\">\n ","\n </nile-button>\n <nile-menu class=\"rte-align-menu\">\n ","\n </nile-menu>\n </nile-dropdown>\n "])),_i,t.map(function(t){return n(_templateObject3||(_templateObject3=_taggedTemplateLiteral(["\n <nile-menu-item\n class=\"rte-align-item\"\n ?active=","\n @click=",">\n <nile-icon name=\"","\"></nile-icon>\n </nile-menu-item>\n "])),t.value===_this3.selectedValue,function(){return _this3.onSelect(t.value);},t.icon);}));}if("font"===this.type){var _i2=(e===null||e===void 0?void 0:e.label)||this.label||"Font";return n(_templateObject4||(_templateObject4=_taggedTemplateLiteral(["\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: ","\">\n "," <nile-icon name=\"arrowdown\"></nile-icon>\n </nile-button>\n <nile-menu class=\"rte-default-menu\">\n ","\n </nile-menu>\n </nile-dropdown>\n "])),(e===null||e===void 0?void 0:e.value)||"inherit",_i2,t.map(function(t){return n(_templateObject5||(_templateObject5=_taggedTemplateLiteral(["\n <nile-menu-item\n style=\"font-family: ","\"\n ?active=","\n @click=",">\n ","\n </nile-menu-item>\n "])),t.value,t.value===_this3.selectedValue,function(){return _this3.onSelect(t.value);},t.label);}));}var i=(e===null||e===void 0?void 0:e.label)||this.label||"Select";return n(_templateObject6||(_templateObject6=_taggedTemplateLiteral(["\n <nile-dropdown class=\"rte-default-dd\">\n <nile-button slot=\"trigger\" variant=\"tertiary\" class=\"rte-default-trigger\">\n "," <nile-icon name=\"arrowdown\"></nile-icon>\n </nile-button>\n <nile-menu class=\"rte-default-menu\">\n ","\n </nile-menu>\n </nile-dropdown>\n "])),i,t.map(function(t){return n(_templateObject7||(_templateObject7=_taggedTemplateLiteral(["\n <nile-menu-item\n ?active=","\n @click=",">\n ","\n </nile-menu-item>\n "])),t.value===_this3.selectedValue,function(){return _this3.onSelect(t.value);},t.label);}));}}]);}(e);t([i({type:String})],o.prototype,"type",void 0),t([i({type:String})],o.prototype,"options",void 0),t([i({attribute:!1})],o.prototype,"optionsObj",void 0),t([i({type:String})],o.prototype,"label",void 0),t([l()],o.prototype,"selectedValue",void 0),o=t([r("nile-rte-select")],o);}};});
1
+ function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o;}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o;},_typeof(o);}System.register(["tslib","lit","lit/decorators.js"],function(_export,_context){"use strict";var t,e,n,i,r,l,_templateObject,_templateObject2,_templateObject3,_templateObject4,_templateObject5,_templateObject6,_templateObject7,s,o;function _taggedTemplateLiteral(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}));}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function");}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o);}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+"";}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.");}return("string"===r?String:Number)(t);}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e));}function _possibleConstructorReturn(t,e){if(e&&("object"==_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t);}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e;}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t;})();}function _superPropGet(t,o,e,r){var p=_get(_getPrototypeOf(1&r?t.prototype:t),o,e);return 2&r&&"function"==typeof p?function(t){return p.apply(e,t);}:p;}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var p=_superPropBase(e,t);if(p){var n=Object.getOwnPropertyDescriptor(p,t);return n.get?n.get.call(arguments.length<3?e:r):n.value;}},_get.apply(null,arguments);}function _superPropBase(t,o){for(;!{}.hasOwnProperty.call(t,o)&&null!==(t=_getPrototypeOf(t)););return t;}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t);},_getPrototypeOf(t);}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e);}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t;},_setPrototypeOf(t,e);}function a(t){return s.has(t);}return{setters:[function(_tslib){t=_tslib.__decorate;},function(_lit){e=_lit.LitElement;n=_lit.html;},function(_litDecoratorsJs){i=_litDecoratorsJs.property;r=_litDecoratorsJs.state;l=_litDecoratorsJs.customElement;}],execute:function execute(){s=new Set(["p","h1","h2","h3","h4","h5","h6"]);o=/*#__PURE__*/function(_e){function o(){var _this;_classCallCheck(this,o);_this=_callSuper(this,o,arguments),_this.type="",_this.options="[]",_this.label="",_this.selectedValue="";return _this;}_inherits(o,_e);return _createClass(o,[{key:"createRenderRoot",value:function createRenderRoot(){return this;}},{key:"mapAlignIcon",value:function mapAlignIcon(t){return{left:"format_align_left",center:"format_align_middle",right:"format_align_right",justify:"format_align_justify"}[t]||"format_align_left";}},{key:"parsedOptions",get:function get(){var _this$optionsObj,_this2=this;var t=(_this$optionsObj=this.optionsObj)!==null&&_this$optionsObj!==void 0?_this$optionsObj:this.options;var e=function(){if(Array.isArray(t))return t;try{return JSON.parse(String(t));}catch(_unused){return[];}}().map(function(t){var _t$value,_ref,_t$label,_t$icon;var e=(_t$value=t===null||t===void 0?void 0:t.value)!==null&&_t$value!==void 0?_t$value:t;return{value:e,label:(_ref=(_t$label=t===null||t===void 0?void 0:t.label)!==null&&_t$label!==void 0?_t$label:t===null||t===void 0?void 0:t.value)!==null&&_ref!==void 0?_ref:t,icon:(_t$icon=t===null||t===void 0?void 0:t.icon)!==null&&_t$icon!==void 0?_t$icon:"align"===_this2.type?_this2.mapAlignIcon(String(e)):void 0};});if("heading"===this.type){e.length;e=e.filter(function(t){return a(t.value);}),e.length,this.selectedValue&&!a(this.selectedValue)&&(this.selectedValue="");}return e;}},{key:"ensureDefault",value:function ensureDefault(){if(!this.selectedValue){var _t=this.parsedOptions[0];_t&&(this.selectedValue=_t.value);}}},{key:"onSelect",value:function onSelect(t){"heading"!==this.type||a(t)?(this.selectedValue=t,this.dispatchEvent(new CustomEvent("change",{detail:t,bubbles:!0,composed:!0}))):console.warn("[nile-rte-select] Ignoring invalid heading value: ".concat(t));}},{key:"connectedCallback",value:function connectedCallback(){_superPropGet(o,"connectedCallback",this,3)([]),this.injectLocalStyles();}},{key:"injectLocalStyles",value:function injectLocalStyles(){if(this.querySelector("style[data-rte-select-style]"))return;var t=document.createElement("style");t.setAttribute("data-rte-select-style","true"),t.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 nile-button.rte-align-trigger::part(base) {\n \n\n border: none;\n}\n ",this.insertBefore(t,this.firstChild);}},{key:"render",value:function render(){var _this3=this;var t=this.parsedOptions;this.ensureDefault();var e=t.find(function(t){return t.value===_this3.selectedValue;});if("align"===this.type){var _i=e!==null&&e!==void 0&&e.icon?n(_templateObject||(_templateObject=_taggedTemplateLiteral(["<nile-icon name=\"","\"></nile-icon>"])),e.icon):this.label||"Align";return n(_templateObject2||(_templateObject2=_taggedTemplateLiteral(["\n <nile-dropdown class=\"rte-align-dd\">\n <nile-button slot=\"trigger\" variant=\"tertiary\" class=\"rte-align-trigger\">\n ","\n </nile-button>\n <nile-menu class=\"rte-align-menu\">\n ","\n </nile-menu>\n </nile-dropdown>\n "])),_i,t.map(function(t){return n(_templateObject3||(_templateObject3=_taggedTemplateLiteral(["\n <nile-menu-item\n class=\"rte-align-item\"\n ?active=","\n @click=",">\n <nile-icon name=\"","\"></nile-icon>\n </nile-menu-item>\n "])),t.value===_this3.selectedValue,function(){return _this3.onSelect(t.value);},t.icon);}));}if("font"===this.type){var _i2=(e===null||e===void 0?void 0:e.label)||this.label||"Font";return n(_templateObject4||(_templateObject4=_taggedTemplateLiteral(["\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: ","\">\n "," <nile-icon name=\"arrowdown\"></nile-icon>\n </nile-button>\n <nile-menu class=\"rte-default-menu\">\n ","\n </nile-menu>\n </nile-dropdown>\n "])),(e===null||e===void 0?void 0:e.value)||"inherit",_i2,t.map(function(t){return n(_templateObject5||(_templateObject5=_taggedTemplateLiteral(["\n <nile-menu-item\n style=\"font-family: ","\"\n ?active=","\n @click=",">\n ","\n </nile-menu-item>\n "])),t.value,t.value===_this3.selectedValue,function(){return _this3.onSelect(t.value);},t.label);}));}var i=(e===null||e===void 0?void 0:e.label)||this.label||"Select";return n(_templateObject6||(_templateObject6=_taggedTemplateLiteral(["\n <nile-dropdown class=\"rte-default-dd\">\n <nile-button slot=\"trigger\" variant=\"tertiary\" class=\"rte-default-trigger\">\n "," <nile-icon name=\"arrowdown\"></nile-icon>\n </nile-button>\n <nile-menu class=\"rte-default-menu\">\n ","\n </nile-menu>\n </nile-dropdown>\n "])),i,t.map(function(t){return n(_templateObject7||(_templateObject7=_taggedTemplateLiteral(["\n <nile-menu-item\n ?active=","\n @click=",">\n ","\n </nile-menu-item>\n "])),t.value===_this3.selectedValue,function(){return _this3.onSelect(t.value);},t.label);}));}}]);}(e);t([i({type:String})],o.prototype,"type",void 0),t([i({type:String})],o.prototype,"options",void 0),t([i({attribute:!1})],o.prototype,"optionsObj",void 0),t([i({type:String})],o.prototype,"label",void 0),t([r()],o.prototype,"selectedValue",void 0),o=t([l("nile-rte-select")],o);}};});
2
2
  //# sourceMappingURL=nile-rte-select.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nile-rte-select.cjs.js","sources":["../../../src/nile-rich-text-editor/nile-rte-select.ts"],"sourcesContent":[" // nile-rte-select.ts\n import { LitElement, html } from 'lit';\n import { customElement, property, state } from 'lit/decorators.js';\n\n type HeadingTag = 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';\n type GenericOption = { value: string; label?: string; icon?: string };\n type HeadingOption = { value: HeadingTag; label?: string; icon?: string };\n type NormalizedOption = { value: string; label: string; icon?: string };\n\n const HEADING_ALLOWLIST: ReadonlySet<HeadingTag> = new Set([\n 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'\n ]);\n\n function isHeadingTag(v: string): v is HeadingTag {\n return HEADING_ALLOWLIST.has(v as HeadingTag);\n }\n\n @customElement('nile-rte-select')\n export 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: 'format_align_left',\n center: 'format_align_middle',\n right: 'format_align_right',\n justify: 'format_align_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\n declare global {\n interface HTMLElementTagNameMap {\n 'nile-rte-select': NileRteSelect;\n }\n }\n"],"names":["isHeadingTag","v","HEADING_ALLOWLIST","has","setters","_tslib","Set","NileRteSelect","o","constructor","this","type","options","label","selectedValue","_this","_inherits","_e","_createClass","key","value","createRenderRoot","mapAlignIcon","left","center","right","justify","get","parsedOptions","source","optionsObj","items","Array","isArray","JSON","parse","String","_unused","map","icon","undefined","length","filter","i","ensureDefault","first","onSelect","dispatchEvent","CustomEvent","detail","bubbles","composed","console","warn","connectedCallback","super","injectLocalStyles","querySelector","style","document","createElement","setAttribute","textContent","insertBefore","firstChild","render","opts","current","find","trigger","html","_templateObject","_taggedTemplateLiteral","_templateObject2","_templateObject3","triggerText","_templateObject4","_templateObject5","_templateObject6","_templateObject7","__decorate","LitElement","property","prototype","attribute","state","customElement"],"mappings":"i2GAaE,QAASA,CAAAA,CAAaC,CAAAA,CAAAA,CAAAA,CACpB,MAAOC,CAAAA,CAAAA,CAAkBC,GAAIF,CAAAA,CAAAA,CAC/B,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A,EAI3CH,CAAAA,CAAAA,CAAAA,CAAA,CADCE,CAAAA,CAAS,CAAEE,SAAAA,CAAAA,CAAW,KAC2B7E,CAAA4E,CAAAA,SAAAA,CAAA,YAAA,CAAA,IAAA,EAAA,CAAA,CAGtBH,CAAA,CAAA,CAA3BE,EAAS,CAAEvE,IAAAA,CAAMyB,MAAqB7B,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA4E,SAAA,CAAA,OAAA,CAAA,IAAA,IAEtBH,CAAA,CAAA,CAAhBK,CAAmC9E,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA4E,SAAA,CAAA,eAAA,CAAA,IAAA,IAhBzB5E,CAAayE,CAAAA,CAAAA,CAAA,CADzBM,CAAAA,CAAc,iBACF/E,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA"}
1
+ {"version":3,"file":"nile-rte-select.cjs.js","sources":["../../../src/nile-rich-text-editor/nile-rte-select.ts"],"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: 'format_align_left',\n center: 'format_align_middle',\n right: 'format_align_right',\n justify: 'format_align_justify'\n };\n return map[v] || 'format_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 nile-button.rte-align-trigger::part(base) {\n \n\n border: 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"],"names":["isHeadingTag","v","HEADING_ALLOWLIST","has","setters","_tslib","Set","NileRteSelect","o","constructor","this","type","options","label","selectedValue","_this","_inherits","_e","_createClass","key","value","createRenderRoot","mapAlignIcon","left","center","right","justify","get","parsedOptions","source","optionsObj","items","Array","isArray","JSON","parse","String","_unused","map","icon","undefined","length","filter","i","ensureDefault","first","onSelect","dispatchEvent","CustomEvent","detail","bubbles","composed","console","warn","connectedCallback","super","injectLocalStyles","querySelector","style","document","createElement","setAttribute","textContent","insertBefore","firstChild","render","opts","current","find","trigger","html","_templateObject","_taggedTemplateLiteral","_templateObject2","_templateObject3","triggerText","_templateObject4","_templateObject5","_templateObject6","_templateObject7","__decorate","LitElement","property","prototype","attribute","state","customElement"],"mappings":"i2GAaA,QAASA,CAAAA,CAAaC,CAAAA,CAAAA,CAAAA,CACpB,MAAOC,CAAAA,CAAAA,CAAkBC,GAAIF,CAAAA,CAAAA,CAC/B,EAGO,OAAAG,OAAA,WAAAC,MAAA,sNATDH,CAAAA,CAA6C,GAAII,CAAAA,GAAAA,CAAI,CACzD,GAAK,CAAA,IAAA,CAAM,IAAM,CAAA,IAAA,CAAM,IAAM,CAAA,IAAA,CAAM,IAGrC,CAAA,CAAA,CAKaC,4BAAN,SAAAC,EAAA,CAAAC,KAAAA,KAAAA,CAAAA,eAAAA,MAAAA,CAAAA,qCAIuBC,KAAAA,CAAIC,IAAAA,CAAG,EAGPD,CAAAA,KAAAA,CAAOE,OAAG,CAAA,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E,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA4E,SAAA,CAAA,eAAA,CAAA,IAAA,IAhBzB5E,CAAayE,CAAAA,CAAAA,CAAA,CADzBM,CAAAA,CAAc,iBACF/E,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA"}
@@ -1,47 +1,32 @@
1
- import{__decorate as t}from"tslib";import{LitElement as e,html as n}from"lit";import{property as i,state as l,customElement as r}from"lit/decorators.js";const s=new Set(["p","h1","h2","h3","h4","h5","h6"]);function a(t){return s.has(t)}let o=class extends e{constructor(){super(...arguments),this.type="",this.options="[]",this.label="",this.selectedValue=""}createRenderRoot(){return this}mapAlignIcon(t){return{left:"format_align_left",center:"format_align_middle",right:"format_align_right",justify:"format_align_justify"}[t]||"align-left"}get parsedOptions(){const t=this.optionsObj??this.options;let e=(()=>{if(Array.isArray(t))return t;try{return JSON.parse(String(t))}catch{return[]}})().map((t=>{const e=t?.value??t;return{value:e,label:t?.label??t?.value??t,icon:t?.icon??("align"===this.type?this.mapAlignIcon(String(e)):void 0)}}));if("heading"===this.type){e.length;e=e.filter((t=>a(t.value))),e.length,this.selectedValue&&!a(this.selectedValue)&&(this.selectedValue="")}return e}ensureDefault(){if(!this.selectedValue){const t=this.parsedOptions[0];t&&(this.selectedValue=t.value)}}onSelect(t){"heading"!==this.type||a(t)?(this.selectedValue=t,this.dispatchEvent(new CustomEvent("change",{detail:t,bubbles:!0,composed:!0}))):console.warn(`[nile-rte-select] Ignoring invalid heading value: ${t}`)}connectedCallback(){super.connectedCallback(),this.injectLocalStyles()}injectLocalStyles(){if(this.querySelector("style[data-rte-select-style]"))return;const t=document.createElement("style");t.setAttribute("data-rte-select-style","true"),t.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 ",this.insertBefore(t,this.firstChild)}render(){const t=this.parsedOptions;this.ensureDefault();const e=t.find((t=>t.value===this.selectedValue));if("align"===this.type){const i=e?.icon?n`<nile-icon name="${e.icon}"></nile-icon>`:this.label||"Align";return n`
2
- <nile-dropdown class="rte-align-dd">
3
- <nile-button slot="trigger" variant="tertiary" class="rte-align-trigger">
4
- ${i}
5
- </nile-button>
6
- <nile-menu class="rte-align-menu">
7
- ${t.map((t=>n`
8
- <nile-menu-item
9
- class="rte-align-item"
10
- ?active=${t.value===this.selectedValue}
11
- @click=${()=>this.onSelect(t.value)}>
12
- <nile-icon name="${t.icon}"></nile-icon>
13
- </nile-menu-item>
14
- `))}
15
- </nile-menu>
16
- </nile-dropdown>
17
- `}if("font"===this.type){const i=e?.label||this.label||"Font";return n`
18
- <nile-dropdown class="rte-default-dd">
19
- <nile-button
20
- slot="trigger"
21
- variant="tertiary"
22
- class="rte-default-trigger"
23
- style="font-family: ${e?.value||"inherit"}">
24
- ${i} <nile-icon name="arrowdown"></nile-icon>
25
- </nile-button>
26
- <nile-menu class="rte-default-menu">
27
- ${t.map((t=>n`
28
- <nile-menu-item
29
- style="font-family: ${t.value}"
30
- ?active=${t.value===this.selectedValue}
31
- @click=${()=>this.onSelect(t.value)}>
32
- ${t.label}
33
- </nile-menu-item>
34
- `))}
35
- </nile-menu>
36
- </nile-dropdown>
37
- `}const i=e?.label||this.label||"Select";return n`
1
+ import{__decorate as t}from"tslib";import{LitElement as e,html as n}from"lit";import{property as i,state as r,customElement as l}from"lit/decorators.js";const s=new Set(["p","h1","h2","h3","h4","h5","h6"]);function a(t){return s.has(t)}let o=class extends e{constructor(){super(...arguments),this.type="",this.options="[]",this.label="",this.selectedValue=""}createRenderRoot(){return this}mapAlignIcon(t){return{left:"format_align_left",center:"format_align_middle",right:"format_align_right",justify:"format_align_justify"}[t]||"format_align_left"}get parsedOptions(){const t=this.optionsObj??this.options;let e=(()=>{if(Array.isArray(t))return t;try{return JSON.parse(String(t))}catch{return[]}})().map((t=>{const e=t?.value??t;return{value:e,label:t?.label??t?.value??t,icon:t?.icon??("align"===this.type?this.mapAlignIcon(String(e)):void 0)}}));if("heading"===this.type){e.length;e=e.filter((t=>a(t.value))),e.length,this.selectedValue&&!a(this.selectedValue)&&(this.selectedValue="")}return e}ensureDefault(){if(!this.selectedValue){const t=this.parsedOptions[0];t&&(this.selectedValue=t.value)}}onSelect(t){"heading"!==this.type||a(t)?(this.selectedValue=t,this.dispatchEvent(new CustomEvent("change",{detail:t,bubbles:!0,composed:!0}))):console.warn(`[nile-rte-select] Ignoring invalid heading value: ${t}`)}connectedCallback(){super.connectedCallback(),this.injectLocalStyles()}injectLocalStyles(){if(this.querySelector("style[data-rte-select-style]"))return;const t=document.createElement("style");t.setAttribute("data-rte-select-style","true"),t.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 nile-button.rte-align-trigger::part(base) {\n \n\n border: none;\n}\n ",this.insertBefore(t,this.firstChild)}render(){const t=this.parsedOptions;this.ensureDefault();const e=t.find((t=>t.value===this.selectedValue));if("align"===this.type){const i=e?.icon?n`<nile-icon name="${e.icon}"></nile-icon>`:this.label||"Align";return n`
2
+ <nile-dropdown class="rte-align-dd">
3
+ <nile-button slot="trigger" variant="tertiary" class="rte-align-trigger">
4
+ ${i}
5
+ </nile-button>
6
+ <nile-menu class="rte-align-menu">
7
+ ${t.map((t=>n`
8
+ <nile-menu-item
9
+ class="rte-align-item"
10
+ ?active=${t.value===this.selectedValue}
11
+ @click=${()=>this.onSelect(t.value)}>
12
+ <nile-icon name="${t.icon}"></nile-icon>
13
+ </nile-menu-item>
14
+ `))}
15
+ </nile-menu>
16
+ </nile-dropdown>
17
+ `}if("font"===this.type){const i=e?.label||this.label||"Font";return n`
38
18
  <nile-dropdown class="rte-default-dd">
39
- <nile-button slot="trigger" variant="tertiary" class="rte-default-trigger">
19
+ <nile-button
20
+ slot="trigger"
21
+ variant="tertiary"
22
+ class="rte-default-trigger"
23
+ style="font-family: ${e?.value||"inherit"}">
40
24
  ${i} <nile-icon name="arrowdown"></nile-icon>
41
25
  </nile-button>
42
26
  <nile-menu class="rte-default-menu">
43
27
  ${t.map((t=>n`
44
28
  <nile-menu-item
29
+ style="font-family: ${t.value}"
45
30
  ?active=${t.value===this.selectedValue}
46
31
  @click=${()=>this.onSelect(t.value)}>
47
32
  ${t.label}
@@ -49,4 +34,19 @@ import{__decorate as t}from"tslib";import{LitElement as e,html as n}from"lit";im
49
34
  `))}
50
35
  </nile-menu>
51
36
  </nile-dropdown>
52
- `}};t([i({type:String})],o.prototype,"type",void 0),t([i({type:String})],o.prototype,"options",void 0),t([i({attribute:!1})],o.prototype,"optionsObj",void 0),t([i({type:String})],o.prototype,"label",void 0),t([l()],o.prototype,"selectedValue",void 0),o=t([r("nile-rte-select")],o);
37
+ `}const i=e?.label||this.label||"Select";return n`
38
+ <nile-dropdown class="rte-default-dd">
39
+ <nile-button slot="trigger" variant="tertiary" class="rte-default-trigger">
40
+ ${i} <nile-icon name="arrowdown"></nile-icon>
41
+ </nile-button>
42
+ <nile-menu class="rte-default-menu">
43
+ ${t.map((t=>n`
44
+ <nile-menu-item
45
+ ?active=${t.value===this.selectedValue}
46
+ @click=${()=>this.onSelect(t.value)}>
47
+ ${t.label}
48
+ </nile-menu-item>
49
+ `))}
50
+ </nile-menu>
51
+ </nile-dropdown>
52
+ `}};t([i({type:String})],o.prototype,"type",void 0),t([i({type:String})],o.prototype,"options",void 0),t([i({attribute:!1})],o.prototype,"optionsObj",void 0),t([i({type:String})],o.prototype,"label",void 0),t([r()],o.prototype,"selectedValue",void 0),o=t([l("nile-rte-select")],o);