@aquera/nile-elements 1.2.8-beta-1.1 → 1.2.8-beta-1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/demo/index.html +33 -93
- package/demo/nxtgen.css +0 -6
- package/demo/variables.css +0 -4
- package/dist/index.js +411 -699
- package/dist/nile-calendar/nile-calendar.cjs.js +1 -1
- package/dist/nile-calendar/nile-calendar.cjs.js.map +1 -1
- package/dist/nile-calendar/nile-calendar.css.cjs.js +1 -1
- package/dist/nile-calendar/nile-calendar.css.cjs.js.map +1 -1
- package/dist/nile-calendar/nile-calendar.css.esm.js +46 -234
- package/dist/nile-calendar/nile-calendar.esm.js +106 -220
- package/dist/nile-rich-text-editor/nile-rich-text-editor.cjs.js +1 -1
- package/dist/nile-rich-text-editor/nile-rich-text-editor.cjs.js.map +1 -1
- package/dist/nile-rich-text-editor/nile-rich-text-editor.css.cjs.js +1 -1
- package/dist/nile-rich-text-editor/nile-rich-text-editor.css.cjs.js.map +1 -1
- package/dist/nile-rich-text-editor/nile-rich-text-editor.css.esm.js +32 -18
- package/dist/nile-rich-text-editor/nile-rich-text-editor.esm.js +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.cjs.js +2 -2
- package/dist/nile-virtual-select/nile-virtual-select.cjs.js.map +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.esm.js +3 -3
- package/dist/src/nile-calendar/nile-calendar.css.js +44 -232
- package/dist/src/nile-calendar/nile-calendar.css.js.map +1 -1
- package/dist/src/nile-calendar/nile-calendar.d.ts +0 -15
- package/dist/src/nile-calendar/nile-calendar.js +101 -340
- package/dist/src/nile-calendar/nile-calendar.js.map +1 -1
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js +30 -16
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js.map +1 -1
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.d.ts +1 -0
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js +12 -0
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js.map +1 -1
- package/dist/src/nile-virtual-select/nile-virtual-select.js +19 -1
- package/dist/src/nile-virtual-select/nile-virtual-select.js.map +1 -1
- package/dist/src/version.js +2 -2
- package/dist/src/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/nile-calendar/nile-calendar.css.ts +44 -232
- package/src/nile-calendar/nile-calendar.ts +115 -369
- package/src/nile-rich-text-editor/nile-rich-text-editor.css.ts +30 -16
- package/src/nile-rich-text-editor/nile-rich-text-editor.ts +12 -0
- package/src/nile-virtual-select/nile-virtual-select.ts +26 -2
- package/vscode-html-custom-data.json +27 -47
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import{__decorate as t}from"tslib";import{html as i,nothing as e}from"lit";import{property as s,state as n,customElement as a}from"lit/decorators.js";import{s as l}from"./nile-calendar.css.esm.js";import{classMap as
|
|
1
|
+
import{__decorate as t}from"tslib";import{html as i,nothing as e}from"lit";import{property as s,state as n,customElement as a}from"lit/decorators.js";import{s as l}from"./nile-calendar.css.esm.js";import{classMap as h}from"lit/directives/class-map.js";import{w as r}from"../internal/watch.esm.js";import{N as d}from"../internal/nile-element.esm.js";let o=class extends d{constructor(){super(...arguments),this.valueAttribute=null,this.allowedDates=JSON.stringify({}),this.range=!1,this.hideTypes=!1,this.doubleClickUnselect=!1,this.allowClear=!1,this.type="absolute",this.hideDurationFields=[],this.showManualInputs=!1,this.startDate=null,this.endDate=null,this.isSelectingStart=!0,this.hideInput=!1,this.currentMonth=(new Date).getMonth(),this.currentYear=(new Date).getFullYear(),this.allowedDatesLocal=null}static get styles(){return[l]}connectedCallback(){super.connectedCallback(),this.initializeValue(),this.emit("nile-init")}disconnectedCallback(){super.disconnectedCallback(),this.emit("nile-destroy")}updated(t){if(super.updated(t),t.has("valueAttribute")){this.valueAttribute||(this.value=null,this.startDate=null,this.endDate=null,this.isSelectingStart=!0);const t=new Date(this.valueAttribute||"");if(!isNaN(t.getTime())){const i=t.getTimezoneOffset();this.value=new Date(t.getTime()-60*i*1e3),this.currentMonth=this.value.getMonth(),this.currentYear=this.value.getFullYear()}this.initializeValue()}}checkValidAllowedDate(){let t;try{t=JSON.parse(this.allowedDates)}catch(i){t=null}if(!t||0==Object.keys(t).length)return void(this.allowedDatesLocal=null);this.hideInput=!0;this.getUTCDate(t.startDate)>this.getUTCDate(t.endDate)?console.error("StartDate must be greater than endDate"):this.allowedDatesLocal=t}render(){return i`
|
|
2
2
|
<div
|
|
3
|
-
class=${
|
|
4
|
-
part="calendar-container"
|
|
3
|
+
class=${h({base:!0,base__range:this.range})}
|
|
5
4
|
>
|
|
6
|
-
<div class=${
|
|
7
|
-
<div class="calendar-switcher"
|
|
5
|
+
<div class=${h({"calendar-config":!0,hidden:!this.range||this.range&&this.hideTypes})}>
|
|
6
|
+
<div class="calendar-switcher">
|
|
8
7
|
<nile-tab-group centered @nile-tab-show="${this.onTypeChange}" value="${this.type}">
|
|
9
|
-
<nile-tab slot="nav" panel="absolute"
|
|
10
|
-
<nile-tab slot="nav" panel="relative"
|
|
8
|
+
<nile-tab slot="nav" panel="absolute">Absolute</nile-tab>
|
|
9
|
+
<nile-tab slot="nav" panel="relative">Relative</nile-tab>
|
|
11
10
|
</nile-tab-group>
|
|
12
11
|
</div>
|
|
13
12
|
</div>
|
|
@@ -16,163 +15,122 @@ import{__decorate as t}from"tslib";import{html as i,nothing as e}from"lit";impor
|
|
|
16
15
|
${"absolute"==this.type?this.renderAbsoluteCalendar():""}
|
|
17
16
|
|
|
18
17
|
${this.range?i`
|
|
19
|
-
<div class="button-container"
|
|
18
|
+
<div class="button-container">
|
|
20
19
|
${this.allowClear?i`
|
|
21
20
|
<nile-button
|
|
22
21
|
class="clear-button"
|
|
23
22
|
variant="secondary"
|
|
24
|
-
role="button"
|
|
25
23
|
?disabled="${!this.startDate||!this.endDate}"
|
|
26
|
-
@keydown="${t=>{"Enter"!==t.key&&" "!==t.key||this.clearDate()}}"
|
|
27
24
|
@click="${this.clearDate}"
|
|
28
|
-
|
|
29
|
-
> Reset</nile-button>`:e}
|
|
25
|
+
> Clear</nile-button>`:e}
|
|
30
26
|
<nile-button
|
|
31
27
|
class="apply-button"
|
|
32
28
|
?disabled="${!this.startDate||!this.endDate}"
|
|
33
29
|
@click="${this.confimRange}"
|
|
34
|
-
@keydown="${t=>{"Enter"!==t.key&&" "!==t.key||this.confimRange()}}"
|
|
35
30
|
> Apply</nile-button>
|
|
36
31
|
</div>
|
|
37
32
|
`:""}
|
|
38
33
|
</div>
|
|
39
34
|
`}renderAbsoluteCalendar(){return i`
|
|
40
|
-
<div class="calendar-wrapper"
|
|
41
|
-
<div class="calendar-container"
|
|
35
|
+
<div class="calendar-wrapper">
|
|
36
|
+
<div class="calendar-container">
|
|
42
37
|
${this.renderMonth(this.currentYear,this.currentMonth,this.getDaysArray(this.currentYear,this.currentMonth))}
|
|
43
38
|
</div>
|
|
44
39
|
</div>
|
|
45
40
|
${this.range?i`
|
|
46
41
|
<div class="calender-input ${this.showManualInputs?"":"hidden"}" >
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
></nile-input>
|
|
56
|
-
</div>
|
|
57
|
-
|
|
58
|
-
<div class="from-time">
|
|
59
|
-
<nile-input
|
|
60
|
-
class="manual-input time-input"
|
|
61
|
-
placeholder="HH:MM:SS"
|
|
62
|
-
value="${this.formatTime(this.startDate)}"
|
|
63
|
-
@nile-change="${this.handleStartTimeInput}"
|
|
64
|
-
></nile-input>
|
|
65
|
-
</div>
|
|
66
|
-
</div>
|
|
67
|
-
|
|
42
|
+
<div class="from">
|
|
43
|
+
<nile-input
|
|
44
|
+
label="From"
|
|
45
|
+
class="manual-input"
|
|
46
|
+
value="${this.formatTime(this.startDate)}"
|
|
47
|
+
placeholder="HH:MM:SS" @nile-change="${this.handleStartTimeInput}"
|
|
48
|
+
> </nile-input>
|
|
49
|
+
</div>
|
|
68
50
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
></nile-input>
|
|
78
|
-
</div>
|
|
79
|
-
<div class="from-time">
|
|
80
|
-
<nile-input
|
|
81
|
-
class="manual-input time-input"
|
|
82
|
-
placeholder="HH:MM:SS"
|
|
83
|
-
value="${this.formatTime(this.endDate)}"
|
|
84
|
-
@nile-change="${this.handleEndTimeInput}"
|
|
85
|
-
></nile-input>
|
|
86
|
-
</div>
|
|
87
|
-
</div>
|
|
51
|
+
<div class="from">
|
|
52
|
+
<nile-input
|
|
53
|
+
label="To"
|
|
54
|
+
class="manual-input"
|
|
55
|
+
value="${this.formatTime(this.endDate)}"
|
|
56
|
+
placeholder="HH:MM:SS" @nile-change="${this.handleEndTimeInput}"
|
|
57
|
+
> </nile-input>
|
|
58
|
+
</div>
|
|
88
59
|
</div>
|
|
89
60
|
`:""}
|
|
90
61
|
`}renderRelativeCalendar(){return i`
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
<div class="duration-units">
|
|
98
|
-
${this.renderTimeValues("minutes",[1,5,15,30,45])}
|
|
99
|
-
</div>
|
|
100
|
-
</div>
|
|
101
|
-
`}
|
|
102
|
-
|
|
103
|
-
${this.hideDurationFields?.includes("hours")?"":i`
|
|
104
|
-
<div class="unit-group">
|
|
105
|
-
<div class="duration-name">Hours</div>
|
|
106
|
-
<div class="duration-units">
|
|
107
|
-
${this.renderTimeValues("hours",[1,2,3,6,8,12])}
|
|
108
|
-
</div>
|
|
109
|
-
</div>
|
|
110
|
-
`}
|
|
111
|
-
|
|
112
|
-
${this.hideDurationFields?.includes("days")?"":i`
|
|
113
|
-
<div class="unit-group">
|
|
114
|
-
<div class="duration-name">Days</div>
|
|
115
|
-
<div class="duration-units">
|
|
116
|
-
${this.renderTimeValues("days",[1,2,3,4,5,6])}
|
|
117
|
-
</div>
|
|
118
|
-
</div>
|
|
119
|
-
`}
|
|
120
|
-
|
|
121
|
-
${this.hideDurationFields?.includes("weeks")?"":i`
|
|
122
|
-
<div class="unit-group">
|
|
123
|
-
<div class="duration-name">Weeks</div>
|
|
124
|
-
<div class="duration-units">
|
|
125
|
-
${this.renderTimeValues("weeks",[1,2,4,6])}
|
|
126
|
-
</div>
|
|
127
|
-
</div>
|
|
128
|
-
`}
|
|
129
|
-
|
|
130
|
-
${this.hideDurationFields?.includes("months")?"":i`
|
|
131
|
-
<div class="unit-group">
|
|
132
|
-
<div class="duration-name">Months</div>
|
|
133
|
-
<div class="duration-units">
|
|
134
|
-
${this.renderTimeValues("months",[3,6,12,15])}
|
|
135
|
-
</div>
|
|
136
|
-
</div>
|
|
137
|
-
`}
|
|
62
|
+
<div class="units-wrapper">
|
|
63
|
+
<div class="unit-container">
|
|
64
|
+
${this.hideDurationFields?.includes("minutes")?"":i`
|
|
65
|
+
<div class="duration-name">Minutes</div>
|
|
66
|
+
<div class="duration-units">
|
|
67
|
+
${this.renderTimeValues("minutes",[1,5,15,30,45])}
|
|
138
68
|
</div>
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
<div class="
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
>
|
|
160
|
-
<nile-option value="minutes" class="${this.hideDurationFields?.includes("minutes")?"hidden":""}">Minutes</nile-option>
|
|
161
|
-
<nile-option value="hours" class="${this.hideDurationFields?.includes("hours")?"hidden":""}">Hours</nile-option>
|
|
162
|
-
<nile-option value="days" class="${this.hideDurationFields?.includes("days")?"hidden":""}">Days</nile-option>
|
|
163
|
-
<nile-option value="weeks" class="${this.hideDurationFields?.includes("weeks")?"hidden":""}">Weeks</nile-option>
|
|
164
|
-
<nile-option value="months" class="${this.hideDurationFields?.includes("months")?"hidden":""}">Months</nile-option>
|
|
165
|
-
</nile-select>
|
|
69
|
+
`}
|
|
70
|
+
|
|
71
|
+
${this.hideDurationFields?.includes("hours")?"":i`
|
|
72
|
+
<div class="duration-name">Hours</div>
|
|
73
|
+
<div class="duration-units">
|
|
74
|
+
${this.renderTimeValues("hours",[1,2,3,6,8,12])}
|
|
75
|
+
</div>
|
|
76
|
+
`}
|
|
77
|
+
|
|
78
|
+
${this.hideDurationFields?.includes("days")?"":i`
|
|
79
|
+
<div class="duration-name">Days</div>
|
|
80
|
+
<div class="duration-units">
|
|
81
|
+
${this.renderTimeValues("days",[1,2,3,4,5,6])}
|
|
82
|
+
</div>
|
|
83
|
+
`}
|
|
84
|
+
|
|
85
|
+
${this.hideDurationFields?.includes("weeks")?"":i`
|
|
86
|
+
<div class="duration-name">Weeks</div>
|
|
87
|
+
<div class="duration-units">
|
|
88
|
+
${this.renderTimeValues("weeks",[1,2,4,6])}
|
|
166
89
|
</div>
|
|
90
|
+
`}
|
|
91
|
+
|
|
92
|
+
${this.hideDurationFields?.includes("months")?"":i`
|
|
93
|
+
<div class="duration-name">Months</div>
|
|
94
|
+
<div class="duration-units">
|
|
95
|
+
${this.renderTimeValues("months",[3,6,12,15])}
|
|
96
|
+
</div>
|
|
97
|
+
`}
|
|
167
98
|
</div>
|
|
168
|
-
|
|
99
|
+
</div>
|
|
100
|
+
|
|
101
|
+
${this.range?i`
|
|
102
|
+
<div>
|
|
103
|
+
<div class="unit-input-container">
|
|
104
|
+
<nile-input
|
|
105
|
+
class="manual-input duration-input"
|
|
106
|
+
label="Duration"
|
|
107
|
+
inputmode="numeric"
|
|
108
|
+
type="number"
|
|
109
|
+
value="${this.selectedValue}"
|
|
110
|
+
@nile-change="${this.handleDurationChange}"
|
|
111
|
+
placeholder="Enter Value"
|
|
112
|
+
></nile-input>
|
|
113
|
+
|
|
114
|
+
<nile-select class="manual-input time-input"
|
|
115
|
+
label="Unit of time"
|
|
116
|
+
value="${this.selectedUnit}"
|
|
117
|
+
@nile-change="${this.handleUnitChange}"
|
|
118
|
+
>
|
|
119
|
+
<nile-option value="minutes" class="${this.hideDurationFields?.includes("minutes")?"hidden":""}">Minutes</nile-option>
|
|
120
|
+
<nile-option value="hours" class="${this.hideDurationFields?.includes("hours")?"hidden":""}"> Hours </nile-option>
|
|
121
|
+
<nile-option value="days" class="${this.hideDurationFields?.includes("days")?"hidden":""}">Days</nile-option>
|
|
122
|
+
<nile-option value="weeks" class="${this.hideDurationFields?.includes("weeks")?"hidden":""}">Weeks</nile-option>
|
|
123
|
+
<nile-option value="months" class="${this.hideDurationFields?.includes("months")?"hidden":""}"> Months </nile-option>
|
|
124
|
+
</nile-select>
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
`:""}
|
|
169
128
|
`}renderTimeValues(t,e){return e.map((e=>i`
|
|
170
129
|
<div
|
|
171
130
|
class="duration__value ${this.selectedUnit===t&&this.selectedValue===e?"duration__value--selected":""}"
|
|
172
131
|
@click=${i=>this.handleTimeValueClick(t,e,i)}
|
|
173
|
-
@keydown="${i=>{"Enter"!==i.key&&" "!==i.key||this.handleTimeValueClick(t,e,i)}}"
|
|
174
132
|
>${e}
|
|
175
|
-
</div>`))}renderMonth(t,s,n){const a=new Date(t,s,1).getDay(),l=new Date(t,s+1,0).getDay(),
|
|
133
|
+
</div>`))}renderMonth(t,s,n){const a=new Date(t,s,1).getDay(),l=new Date(t,s+1,0).getDay(),r=this.getDaysArray(0===s?t-1:t,0===s?11:s-1),d=this.getDaysArray(11===s?t+1:t,11===s?0:s+1),o=r.slice(r.length-a),c=d.slice(0,6-l),u=[...o,...n,...c],v=(t,i,e,s)=>{if(!s)return"";if(!this.range&&this.value){if(t===this.value.getDate()&&i===this.value.getMonth()&&e===this.value.getFullYear())return"selected-date"}const n=this.startDate&&t===this.startDate.getDate()&&i===this.startDate.getMonth()&&e===this.startDate.getFullYear(),a=this.endDate&&t===this.endDate.getDate()&&i===this.endDate.getMonth()&&e===this.endDate.getFullYear();return n?"range-start":a?"range-end":""},p=(t,i,e,s)=>{if(!s)return!1;if(this.startDate&&this.endDate){const s=new Date(e,i,t);return s>=this.startDate&&s<=this.endDate}return!1};return i`
|
|
176
134
|
<div class="calendar">
|
|
177
135
|
<div class="calendar-header">
|
|
178
136
|
<nile-icon
|
|
@@ -180,113 +138,41 @@ import{__decorate as t}from"tslib";import{html as i,nothing as e}from"lit";impor
|
|
|
180
138
|
name="var(--nile-icon-arrow-left, var(--ng-icon-chevron-left))"
|
|
181
139
|
method="var(--nile-svg-method-fill, var(--ng-svg-method-stroke))"
|
|
182
140
|
color="black"
|
|
183
|
-
role="button"
|
|
184
|
-
tabindex="${this.isPrevDisabled()?"-1":"0"}"
|
|
185
|
-
@keydown="${t=>{"Enter"!==t.key&&" "!==t.key||this.prevMonth()}}"
|
|
186
141
|
@click="${this.prevMonth}"
|
|
187
142
|
>
|
|
188
143
|
</nile-icon>
|
|
189
|
-
<
|
|
190
|
-
|
|
191
|
-
${
|
|
192
|
-
|
|
193
|
-
<nile-dropdown class="month-dropdown">
|
|
194
|
-
<span
|
|
195
|
-
slot="trigger"
|
|
196
|
-
class="calendar-header__trigger month-trigger"
|
|
197
|
-
role="button"
|
|
198
|
-
>
|
|
199
|
-
${new Date(t,s).toLocaleString("default",{month:"long"})}
|
|
200
|
-
<nile-icon name="arrowdropdown" color="black" class="calendar-header__caret"></nile-icon>
|
|
201
|
-
</span>
|
|
202
|
-
<nile-menu>
|
|
203
|
-
<div class="month-scroll-wrapper">
|
|
204
|
-
${this.monthNames.map(((t,e)=>i`
|
|
205
|
-
<nile-menu-item
|
|
206
|
-
class="month-menu-item"
|
|
207
|
-
?selected="${e===s}"
|
|
208
|
-
@click="${()=>this.onMonthSelected(e)}"
|
|
209
|
-
>
|
|
210
|
-
${t}
|
|
211
|
-
</nile-menu-item>
|
|
212
|
-
`))}
|
|
213
|
-
</div>
|
|
214
|
-
</nile-menu>
|
|
215
|
-
</nile-dropdown>
|
|
216
|
-
`:i`
|
|
217
|
-
<span
|
|
218
|
-
>${new Date(t,s).toLocaleString("default",{month:"long"})}</span
|
|
219
|
-
>
|
|
220
|
-
`}
|
|
221
|
-
${this.showYearDropdown?i`
|
|
222
|
-
<nile-dropdown class="year-dropdown">
|
|
223
|
-
<span
|
|
224
|
-
slot="trigger"
|
|
225
|
-
class="calendar-header__trigger"
|
|
226
|
-
role="button"
|
|
227
|
-
>
|
|
228
|
-
${t}
|
|
229
|
-
<nile-icon name="arrowdropdown" color="black" class="calendar-header__caret"></nile-icon>
|
|
230
|
-
</span>
|
|
231
|
-
<nile-menu>
|
|
232
|
-
<div class="year-scroll-wrapper">
|
|
233
|
-
${this.yearOptions.map((e=>i`
|
|
234
|
-
<nile-menu-item
|
|
235
|
-
class="year-menu-item"
|
|
236
|
-
?selected="${e===t}"
|
|
237
|
-
@click="${()=>this.onYearSelected(e)}"
|
|
238
|
-
>
|
|
239
|
-
${e}
|
|
240
|
-
</nile-menu-item>
|
|
241
|
-
`))}
|
|
242
|
-
</div>
|
|
243
|
-
</nile-menu>
|
|
244
|
-
</nile-dropdown>
|
|
245
|
-
`:i`
|
|
246
|
-
<span>${t}</span>
|
|
247
|
-
`}
|
|
248
|
-
`:i`
|
|
249
|
-
<span
|
|
250
|
-
>${new Date(t,s).toLocaleString("default",{month:"long"})}
|
|
251
|
-
${t}</span
|
|
252
|
-
>
|
|
253
|
-
`}
|
|
254
|
-
</div>
|
|
255
|
-
|
|
144
|
+
<span
|
|
145
|
+
>${new Date(t,s).toLocaleString("default",{month:"long"})}
|
|
146
|
+
${t}</span
|
|
147
|
+
>
|
|
256
148
|
<nile-icon
|
|
257
149
|
class="calendar-header__month-navigation"
|
|
258
150
|
name="var(--nile-icon-arrow-right, var(--ng-icon-chevron-right))"
|
|
259
151
|
method="var(--nile-svg-method-fill, var(--ng-svg-method-stroke))"
|
|
260
152
|
color="black"
|
|
261
|
-
role="button"
|
|
262
|
-
tabindex="${this.isNextDisabled()?"-1":"0"}"
|
|
263
|
-
@keydown="${t=>{"Enter"!==t.key&&" "!==t.key||this.nextMonth()}}"
|
|
264
153
|
@click="${this.nextMonth}"
|
|
265
154
|
>
|
|
266
155
|
</nile-icon>
|
|
267
156
|
</div>
|
|
268
157
|
<div class="days_container">
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
<div class="day_name">
|
|
272
|
-
<div class="day_name">
|
|
273
|
-
<div class="day_name">
|
|
274
|
-
<div class="day_name">
|
|
275
|
-
<div class="day_name">
|
|
158
|
+
<div class="day_name">Su</div>
|
|
159
|
+
<div class="day_name">Mo</div>
|
|
160
|
+
<div class="day_name">Tu</div>
|
|
161
|
+
<div class="day_name">We</div>
|
|
162
|
+
<div class="day_name">Th</div>
|
|
163
|
+
<div class="day_name">Fr</div>
|
|
164
|
+
<div class="day_name">Sa</div>
|
|
276
165
|
|
|
277
|
-
${u.map(((a,l)=>{const
|
|
166
|
+
${u.map(((a,l)=>{const r=l>=o.length&&l<o.length+n.length,d=v(a,s,t,r),c={day_date:!0,"not-allowed":!this.isAllowedDate(a,s,t),"in-range":p(a,s,t,r),filler:!r};return d&&(c[d]=!0),i`
|
|
278
167
|
<div
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
tabindex="${h&&this.isAllowedDate(a,s,t)?"0":"-1"}"
|
|
282
|
-
@keydown="${i=>{"Enter"!==i.key&&" "!==i.key||this.selectDate(a,s,t)}}"
|
|
283
|
-
@click="${()=>{h&&this.selectDate(a,s,t)}}"
|
|
168
|
+
class=${h(c)}
|
|
169
|
+
@click="${()=>{r&&this.selectDate(a,s,t)}}"
|
|
284
170
|
>
|
|
285
171
|
<span style="position:relative;">
|
|
286
172
|
${a}
|
|
287
|
-
${((t,i,e)=>{const s=new Date;return t===s.getDate()&&i+1===s.getMonth()+1&&e===s.getFullYear()})(a,s,t)&&
|
|
173
|
+
${((t,i,e)=>{const s=new Date;return t===s.getDate()&&i+1===s.getMonth()+1&&e===s.getFullYear()})(a,s,t)&&r?i`<div class="current__date__dot"></div>`:e}
|
|
288
174
|
</span>
|
|
289
175
|
</div>`}))}
|
|
290
176
|
</div>
|
|
291
177
|
</div>
|
|
292
|
-
`}isAllowedDate(t,i,e){if(!this.allowedDatesLocal)return!0;const s=new Date(Date.UTC(e,i,t)),n=this.getUTCDate(this.allowedDatesLocal.startDate),a=this.getUTCDate(this.allowedDatesLocal.endDate);a.setUTCHours(23,59,59,999);return s>=n&&s<=a}clearDate(){this.range?(this.valueAttribute="",this.startDate=null,this.endDate=null
|
|
178
|
+
`}isAllowedDate(t,i,e){if(!this.allowedDatesLocal)return!0;const s=new Date(Date.UTC(e,i,t)),n=this.getUTCDate(this.allowedDatesLocal.startDate),a=this.getUTCDate(this.allowedDatesLocal.endDate);a.setUTCHours(23,59,59,999);return s>=n&&s<=a}clearDate(){this.range?(this.valueAttribute="",this.startDate=null,this.endDate=null):this.value=null,this.emit("nile-clear")}selectDate(t,i,e){const s=new Date(e,i,t);if(this.range)if(this.startDate&&this.endDate&&(this.startDate=null,this.endDate=null),this.isSelectingStart)this.startDate=s,this.endDate&&s>this.endDate&&(this.endDate=null),this.isSelectingStart=!1;else if(this.isSelectingStart=!0,this.startDate&&s<this.startDate)this.startDate=s,this.endDate=null,this.isSelectingStart=!1;else{const t=s;t.setHours(23,59,59,999),this.endDate=t}else{if(String(this.value)==String(s)&&this.doubleClickUnselect)return void this.clearDate();this.value=s,this.emitChangedData({value:this.value})}}initializeValue(){if(this.range)try{const t=JSON.parse(this.valueAttribute||"");this.startDate=new Date(t.startDate),this.endDate=new Date(t.endDate),this.startDate=new Date(this.startDate.getTime()),this.endDate=new Date(this.endDate.getTime()),this.value=null}catch(t){}else if(this.valueAttribute){let t=new Date(this.valueAttribute);t=new Date(t.getTime()-6e4*t.getTimezoneOffset()),isNaN(t.getTime())||(this.value=t,this.currentMonth=this.value.getMonth(),this.currentYear=this.value.getFullYear())}}handleDurationChange(t){t.stopPropagation(),t.detail.value=t.detail.value.replace(/e/gi,"");const i=Number(t.detail.value);i&&(this.selectedValue=i,this.selectedUnit&&this.selectedValue&&this.handleTimeValueClick(this.selectedUnit,this.selectedValue,t))}handleUnitChange(t){t.stopPropagation(),this.selectedUnit=t.detail.value,this.selectedUnit&&this.selectedValue&&this.handleTimeValueClick(this.selectedUnit,this.selectedValue,t)}handleTimeValueClick(t,i,e){this.createRelativePeriod(t,i),this.selectedUnit=t,this.selectedValue=i}createRelativePeriod(t,i){const e=new Date,s=new Date;switch(t){case"minutes":s.setMinutes(s.getMinutes()-i);break;case"hours":s.setHours(s.getHours()-i);break;case"days":s.setDate(s.getDate()-i);break;case"weeks":s.setDate(s.getDate()-7*i);break;case"months":s.setMonth(s.getMonth()-i)}return this.startDate=new Date(s.getTime()),this.endDate=new Date(e.getTime()),{startDate:this.startDate,endDate:this.endDate}}handleStartTimeInput(t){if(t.stopPropagation(),!this.startDate)return void(this.startDate=null);const i=this.parseTime(t.detail.value,this.startDate);i?this.startDate=i:this.startDate.setHours(0,0,0),this.requestUpdate()}handleEndTimeInput(t){if(t.stopPropagation(),!this.endDate)return void(this.endDate=null);const i=this.parseTime(t.detail.value,this.endDate);i?this.endDate=i:this.endDate.setHours(0,0,0),this.requestUpdate()}parseTime(t,i){if(!this.isValidTimeInput(t))return null;const[e,s,n]=t.split(":").map(Number),a=new Date(i.getTime());return a.setHours(e,s,n),a}isValidTimeInput(t){return/^([0-1]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/.test(t)}formatTime(t){if(!t)return"";return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}:${String(t.getSeconds()).padStart(2,"0")}`}nextMonth(){11===this.currentMonth?(this.currentMonth=0,this.currentYear++):this.currentMonth++}prevMonth(){0===this.currentMonth?(this.currentMonth=11,this.currentYear--):this.currentMonth--}confimRange(){this.startDate&&this.endDate&&this.emitChangedData({startDate:this.startDate,endDate:this.endDate})}onTypeChange(t){this.type=t.detail.value,this.emit("nile-type-change",{value:this.type})}getUTCDate(t){return new Date(Date.UTC(t.slice(0,4),t.slice(5,7)-1,t.slice(8,10)))}emitChangedData(t){this.emit("nile-changed",t),this.emit("nile-change",t)}getDaysArray(t,i){const e=new Date(t,i+1,0).getDate();return Array.from({length:e},((t,i)=>i+1))}};t([s({type:String,attribute:"value"})],o.prototype,"valueAttribute",void 0),t([s({type:String,attribute:!0,reflect:!0})],o.prototype,"allowedDates",void 0),t([s({type:Boolean,reflect:!0})],o.prototype,"range",void 0),t([s({type:Boolean,attribute:!0,reflect:!0})],o.prototype,"hideTypes",void 0),t([s({type:Boolean,reflect:!0})],o.prototype,"doubleClickUnselect",void 0),t([s({type:Boolean,reflect:!0})],o.prototype,"allowClear",void 0),t([s({type:String,reflect:!0})],o.prototype,"type",void 0),t([s({type:String})],o.prototype,"selectedUnit",void 0),t([s({type:Number})],o.prototype,"selectedValue",void 0),t([s({type:Array,attribute:"hide-duration-fields"})],o.prototype,"hideDurationFields",void 0),t([s({type:Boolean})],o.prototype,"showManualInputs",void 0),t([n()],o.prototype,"startDate",void 0),t([n()],o.prototype,"endDate",void 0),t([n()],o.prototype,"isSelectingStart",void 0),t([n()],o.prototype,"hideInput",void 0),t([n()],o.prototype,"value",void 0),t([n()],o.prototype,"currentMonth",void 0),t([n()],o.prototype,"currentYear",void 0),t([n()],o.prototype,"allowedDatesLocal",void 0),t([r("allowedDates")],o.prototype,"checkValidAllowedDate",null),o=t([a("nile-calendar")],o);export{o 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","./nile-rte-toolbar.cjs.js","./nile-rte-toolbar-item.cjs.js","./nile-rte-select.cjs.js","./nile-rte-color.cjs.js","./nile-rte-divider.cjs.js","./nile-rte-preview.cjs.js","./nile-rte-mentions.cjs.js","./nile-rte-link.cjs.js","./utils/block-utils.cjs.js","./utils/inline-utils.cjs.js","./utils/color-utils.cjs.js","./utils/list-utils.cjs.js","./nile-rich-text-editor.css.cjs.js"],function(_export,_context){"use strict";var t,i,s,e,n,o,r,h,l,c,a,u,f,d,m,p,b,g;function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var n=0,F=function F(){};return{s:F,n:function(_n4){function n(){return _n4.apply(this,arguments);}n.toString=function(){return _n4.toString();};return n;}(function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]};}),e:function e(r){throw r;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}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);}return{setters:[function(_tslib){t=_tslib.__decorate;},function(_lit){i=_lit.LitElement;},function(_litDecoratorsJs){s=_litDecoratorsJs.property;e=_litDecoratorsJs.state;n=_litDecoratorsJs.customElement;},function(_nileRteToolbarCjsJs){},function(_nileRteToolbarItemCjsJs){},function(_nileRteSelectCjsJs){},function(_nileRteColorCjsJs){},function(_nileRteDividerCjsJs){},function(_nileRtePreviewCjsJs){},function(_nileRteMentionsCjsJs){},function(_nileRteLinkCjsJs){},function(_utilsBlockUtilsCjsJs){o=_utilsBlockUtilsCjsJs.s;r=_utilsBlockUtilsCjsJs.a;h=_utilsBlockUtilsCjsJs.n;l=_utilsBlockUtilsCjsJs.c;},function(_utilsInlineUtilsCjsJs){c=_utilsInlineUtilsCjsJs.t;a=_utilsInlineUtilsCjsJs.s;u=_utilsInlineUtilsCjsJs.r;},function(_utilsColorUtilsCjsJs){f=_utilsColorUtilsCjsJs.s;d=_utilsColorUtilsCjsJs.a;},function(_utilsListUtilsCjsJs){m=_utilsListUtilsCjsJs.t;},function(_nileRichTextEditorCssCjsJs){p=_nileRichTextEditorCssCjsJs.s;}],execute:function execute(){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:"format_clear"};_export("N",g=/*#__PURE__*/function(_i){function g(){var _this;_classCallCheck(this,g);_this=_callSuper(this,g,arguments),_this.value="",_this.noStyles=!1,_this.singleLineEditor=!1,_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.containerEl=null,_this.mentionsEl=null,_this.onEditorKeydown=function(t){if(_this.singleLineEditor&&"Enter"===t.key&&t.shiftKey)return void t.preventDefault();if(t.ctrlKey&&"i"===t.key.toLowerCase()&&(t.preventDefault(),c(_this.editorEl,"em"),_this.updateContent(),_this.updateToolbarState()),_this.singleLineEditor&&"Enter"===t.key)return void t.preventDefault();if("Tab"!==t.key)return;t.preventDefault(),_this.focusAndRestore();var i=window.getSelection();if(!i||0===i.rangeCount)return;var s=i.getRangeAt(0);if(t.shiftKey){if(s.collapsed&&s.startContainer.nodeType===Node.TEXT_NODE){var _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);var _s=document.createRange();_s.setStart(_t,_o.length),_s.collapse(!0),i.removeAllRanges(),i.addRange(_s),_this.updateContent(),_this.updateToolbarState();}}return;}s.deleteContents();var e=document.createTextNode("\t");s.insertNode(e);var n=document.createRange();n.setStartAfter(e),n.collapse(!0),i.removeAllRanges(),i.addRange(n),_this.updateContent(),_this.updateToolbarState();},_this.onSelectionChange=function(){if(!_this.editorEl)return;var t=document.getSelection();if(!t||0===t.rangeCount)return;var i=t.getRangeAt(0);_this.editorEl.contains(i.commonAncestorContainer)&&(_this.lastRange=i.cloneRange(),_this.updateToolbarState());};return _this;}_inherits(g,_i);return _createClass(g,[{key:"createRenderRoot",value:function createRenderRoot(){return this;}},{key:"injectCss",value:function injectCss(t){if(this.querySelector("style[data-rte-style]"))return;var i=document.createElement("style");i.setAttribute("data-rte-style","true"),i.textContent=t,this.insertBefore(i,this.firstChild);}},{key:"connectedCallback",value:function connectedCallback(){var _this$mentionsEl$atta,_this$mentionsEl,_this$mentionsEl$setE,_this$mentionsEl2;_superPropGet(g,"connectedCallback",this,3)([]),this.injectCss(p.cssText),this.ensureStructure(),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$atta=(_this$mentionsEl=this.mentionsEl).attach)!==null&&_this$mentionsEl$atta!==void 0&&_this$mentionsEl$atta.call(_this$mentionsEl,this.editorEl,this),(_this$mentionsEl$setE=(_this$mentionsEl2=this.mentionsEl).setExternalConfig)!==null&&_this$mentionsEl$setE!==void 0&&_this$mentionsEl$setE.call(_this$mentionsEl2,this.mentions)),this.wireEditor(),document.addEventListener("selectionchange",this.onSelectionChange,{passive:!0}),this.updateToolbarState(),this.syncPreview();}},{key:"ensureStructure",value:function ensureStructure(){this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.containerEl=this.querySelector(".rte-container"),this.containerEl||(this.containerEl=document.createElement("div"),this.containerEl.className="rte-container",this.appendChild(this.containerEl)),this.ensureEditor(),this.toolbarEl&&this.toolbarEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.toolbarEl),this.editorEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.editorEl),this.previewEl&&(this.previewEl.parentElement!==this&&this.appendChild(this.previewEl),this.previewEl.previousElementSibling!==this.containerEl&&this.insertBefore(this.previewEl,this.containerEl.nextSibling));}},{key:"updateContentWithMention",value:function updateContentWithMention(t){this.updateContent(),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content,mention:t},bubbles:!0,composed:!0}));}},{key:"disconnectedCallback",value:function disconnectedCallback(){document.removeEventListener("selectionchange",this.onSelectionChange),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),_superPropGet(g,"disconnectedCallback",this,3)([]);}},{key:"updated",value:function updated(t){t.has("value")&&this.editorEl&&this.value!==this.editorEl.innerHTML&&(this.editorEl.innerHTML=this.value||"<p><br></p>",this.content=this.editorEl.innerHTML,this.syncPreview()),t.has("singleLineEditor")&&(this.editorEl&&this.editorEl.classList.toggle("single-line",this.singleLineEditor),this.previewEl&&this.previewEl.classList.toggle("single-line",this.singleLineEditor));}},{key:"ensureEditor",value:function ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){var _t2=document.createElement("article");_t2.className="editor",_t2.setAttribute("contenteditable","true"),this.editorEl=_t2;}this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>");}},{key:"unwrapMention",value:function unwrapMention(t){var _t$textContent;var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var s=t.parentNode;if(!s)return;var e=i?((_t$textContent=t.textContent)!==null&&_t$textContent!==void 0?_t$textContent:"").replace(/\u200B/g,""):"",n=document.createTextNode(e);s.insertBefore(n,t),s.removeChild(t);var o=document.createRange();o.setStartAfter(n),o.collapse(!0);var r=window.getSelection();r!==null&&r!==void 0&&r.removeAllRanges(),r===null||r===void 0?void 0:r.addRange(o);}},{key:"scrubBrokenMentions",value:function scrubBrokenMentions(){var _this2=this;if(!this.editorEl)return;this.editorEl.querySelectorAll("span.mention").forEach(function(t){var _i$textContent;var i=t,s=i.getAttribute("data-mention-key"),e=i.getAttribute("data-mention-label"),n=i.getAttribute("data-mention-trigger")||"",o=((_i$textContent=i.textContent)!==null&&_i$textContent!==void 0?_i$textContent:"").replace(/\u200B/g,"").trim(),r=!!s&&!!e&&o.length>0&&o.startsWith(n)&&o.includes(e);o&&r||_this2.unwrapMention(i,!0);});}},{key:"wireEditor",value:function wireEditor(){var _this3=this;this.editorEl.addEventListener("input",function(){_this3.ensureAtLeastOneParagraph(),_this3.scrubBrokenMentions(),_this3.updateContent(),_this3.updateToolbarState();}),this.editorEl.addEventListener("mouseup",function(){_this3.saveSelection(),_this3.updateToolbarState();}),this.editorEl.addEventListener("keyup",function(t){_this3.saveSelection(),["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(t.key)&&_this3.updateToolbarState();}),this.editorEl.addEventListener("keydown",this.onEditorKeydown);}},{key:"wireAuthoredToolbar",value:function wireAuthoredToolbar(t){var _this4=this;this.buttonMap.clear(),this.headingSelect=null,this.fontSelect=null,this.colorInput=null,Array.from(t.children).forEach(function(t){var i=t.tagName.toLowerCase();if("nile-rte-select"!==i||"align"!==t.getAttribute("type")){if("nile-rte-link"===i)return t.editorEl=_this4.editorEl,void t.addEventListener("link-changed",function(){_this4.updateContent(),_this4.updateToolbarState();});if("nile-rte-toolbar-item"===i){var _this4$buttonMap$get;var _i2=t.querySelector(":scope > nile-button");var _s2=t.getAttribute("name")||"",_e2=t.getAttribute("label")||_s2,_n2=t.getAttribute("icon"),_o2=t.innerHTML.trim().length>0;if(_i2||(_i2=document.createElement("nile-button"),_i2.variant="tertiary",_i2.size="small"),_n2)_i2.innerHTML="<nile-icon name=\"".concat(_n2,"\" aria-label=\"").concat(_e2,"\"></nile-icon>"),t.innerHTML="";else if(_o2)_i2.innerHTML=t.innerHTML,t.innerHTML="";else{var _n3=b[_s2];_n3?_i2.innerHTML="<nile-icon name=\"".concat(_n3,"\" size=\"20\" color=\"black\" aria-label=\"").concat(_e2,"\"></nile-icon>"):_i2.textContent=_e2||_s2,t.innerHTML="";}if(!_i2.isConnected){var _s3=document.createElement("nile-tooltip");_s3.setAttribute("content",_e2),_s3.appendChild(_i2),t.appendChild(_s3);}_i2.setAttribute("aria-label",_e2),_i2.addEventListener("mousedown",function(t){return t.preventDefault();}),_i2.addEventListener("click",function(){return _this4.onToolbarCommand(_s2);});var _r=(_this4$buttonMap$get=_this4.buttonMap.get(_s2))!==null&&_this4$buttonMap$get!==void 0?_this4$buttonMap$get:[];return _r.push(_i2),void _this4.buttonMap.set(_s2,_r);}if("nile-rte-select"!==i)"nile-rte-color"!==i||t.addEventListener("change",function(t){_this4.focusAndRestore();var _t$detail=t.detail,i=_t$detail.mode,s=_t$detail.value;"backColor"===i?f(_this4.editorEl,s):d(_this4.editorEl,s),_this4.updateContent(),_this4.updateToolbarState();});else{var _i3=t.getAttribute("type")||"";t.addEventListener("change",function(t){_this4.focusAndRestore();var s=t.detail;"heading"===_i3?r(_this4.editorEl,s):"font"===_i3&&a(_this4.editorEl,s),_this4.updateContent(),_this4.updateToolbarState();});}}else t.addEventListener("change",function(t){_this4.focusAndRestore();var i=t.detail;o(_this4.editorEl,i),_this4.updateContent(),_this4.updateToolbarState();});});}},{key:"saveSelection",value:function saveSelection(){var t=window.getSelection();t&&t.rangeCount&&(this.lastRange=t.getRangeAt(0).cloneRange());}},{key:"restoreSelection",value:function restoreSelection(){if(!this.lastRange)return;var t=document.getSelection();t&&(t.removeAllRanges(),t.addRange(this.lastRange));}},{key:"focusAndRestore",value:function focusAndRestore(){var _this$editorEl;(_this$editorEl=this.editorEl)!==null&&_this$editorEl!==void 0&&_this$editorEl.focus(),this.restoreSelection();}},{key:"getCleanContent",value:function getCleanContent(){var t=this.editorEl.cloneNode(!0);return t.querySelectorAll("*").forEach(function(t){t.removeAttribute("style");}),t.innerHTML;}},{key:"insertList",value:function insertList(t){if(this.restoreSelection(),!this.lastRange)return;var i=document.createElement(t),s=this.lastRange.extractContents(),e=document.createElement("div");e.appendChild(s),Array.from(e.childNodes).forEach(function(t){var _t$textContent2;if(t.nodeType===Node.TEXT_NODE&&!((_t$textContent2=t.textContent)!==null&&_t$textContent2!==void 0&&_t$textContent2.trim()))return;var s=document.createElement("li");s.appendChild(t),i.appendChild(s);}),this.lastRange.insertNode(i),this.afterListEdit(i);}},{key:"afterListEdit",value:function afterListEdit(t){var i=document.createRange();i.setStartAfter(t),i.collapse(!0);var s=window.getSelection();s!==null&&s!==void 0&&s.removeAllRanges(),s!==null&&s!==void 0&&s.addRange(i),this.saveSelection(),this.updateContent(),this.updateToolbarState();}},{key:"ensureAtLeastOneParagraph",value:function ensureAtLeastOneParagraph(){var _t$textContent3;var t=this.editorEl;if(!t)return;var i=""===((_t$textContent3=t.textContent)!==null&&_t$textContent3!==void 0?_t$textContent3:"").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")){var _i4=document.createElement("p");for(;t.firstChild;)_i4.appendChild(t.firstChild);return _i4.hasChildNodes()||_i4.appendChild(document.createElement("br")),void t.appendChild(_i4);}t.querySelectorAll("p").forEach(function(t){var _t$textContent4;""===((_t$textContent4=t.textContent)!==null&&_t$textContent4!==void 0?_t$textContent4:"").replace(/\u200B/g,"")&&(t.innerHTML.toLowerCase().includes("<br")||(t.innerHTML="<br>"));});}},{key:"onToolbarCommand",value:function onToolbarCommand(t){switch(this.focusAndRestore(),t){case"bold":c(this.editorEl,"strong");break;case"italic":c(this.editorEl,"em");break;case"underline":c(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":m(this.editorEl,"ul"),this.updateContent(),this.updateToolbarState();break;case"ol":m(this.editorEl,"ol"),this.updateContent(),this.updateToolbarState();break;case"link":break;case"clear":var _t3=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),_i5=[];for(;_t3.nextNode();){var _s4=_t3.currentNode;_s4.removeAttribute("style"),["B","STRONG","I","EM","U","SPAN","FONT"].includes(_s4.tagName)&&_i5.push(_s4);}for(var _i7=0,_i6=_i5;_i7<_i6.length;_i7++){var _t4=_i6[_i7];for(;_t4.firstChild;){var _t4$parentNode;(_t4$parentNode=_t4.parentNode)===null||_t4$parentNode===void 0||_t4$parentNode.insertBefore(_t4.firstChild,_t4);}_t4.remove();}this.ensureAtLeastOneParagraph();}this.updateContent(),this.updateToolbarState();}},{key:"setBtnActive",value:function setBtnActive(t,i){var s=this.buttonMap.get(t);if(s){var _iterator=_createForOfIteratorHelper(s),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var _t5=_step.value;_t5.toggleAttribute("data-active",!!i);}}catch(err){_iterator.e(err);}finally{_iterator.f();}}}},{key:"updateToolbarState",value:function updateToolbarState(){var _this5=this,_s$closest;if(!this.editorEl)return;var t=document.getSelection();if(!t||0===t.rangeCount)return;var i=t.getRangeAt(0);if(!this.editorEl.contains(i.commonAncestorContainer))return;var s=h(i.startContainer)||this.editorEl,e=getComputedStyle(s),n=l(i.startContainer,this.editorEl)||this.editorEl,o=function(){var t=s;for(;t&&t!==_this5.editorEl;){if(t instanceof HTMLElement){var _i8=t.tagName.toLowerCase();if("strong"===_i8||"b"===_i8)return!0;var _s5=getComputedStyle(t).fontWeight;if(parseInt(_s5,10)>=600)return!0;}t=t.parentNode;}return!1;}(),r=function(){var t=s;for(;t&&t!==_this5.editorEl;){if(t instanceof HTMLElement){var _i9=t.tagName.toLowerCase();if("em"===_i9||"i"===_i9)return!0;if("italic"===getComputedStyle(t).fontStyle)return!0;}t=t.parentNode;}return!1;}(),c=function(){var t=s;for(;t&&t!==_this5.editorEl;){if(t instanceof HTMLElement){var _i10=getComputedStyle(t).textDecorationLine;if(_i10&&_i10.includes("underline"))return!0;if("u"===t.tagName.toLowerCase())return!0;}t=t.parentNode;}return!1;}(),a=!!s.closest("a"),f=n.style.textAlign||getComputedStyle(n).textAlign||"start",d="start"===f?"left":f,m=!!s.closest("li")&&((_s$closest=s.closest("ul,ol"))===null||_s$closest===void 0?void 0:_s$closest.tagName.toLowerCase())||"";if(this.setBtnActive("bold",o),this.setBtnActive("italic",r),this.setBtnActive("underline",c),this.setBtnActive("link",a),this.setBtnActive("left","left"===d&&!["center","right","justify"].includes(d)),this.setBtnActive("center","center"===d),this.setBtnActive("right","right"===d),this.setBtnActive("justify","justify"===d),this.setBtnActive("ul","ul"===m),this.setBtnActive("ol","ol"===m),this.headingSelect){var _t6=n.tagName.toLowerCase(),_i11=["h1","h2","h3"].includes(_t6)?_t6:"p";this.headingSelect.value!==_i11&&(this.headingSelect.value=_i11);}if(this.fontSelect){var _t7=(e.fontFamily||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase();if(_t7)for(var _i12=0,_Array$from=Array.from(this.fontSelect.options);_i12<_Array$from.length;_i12++){var _i13=_Array$from[_i12];if(_i13.value.toLowerCase()===_t7){this.fontSelect.value=_i13.value;break;}}}if(this.colorInput){var _t8=u(e.color);_t8&&this.colorInput.value.toLowerCase()!==_t8.toLowerCase()&&(this.colorInput.value=_t8),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=this.colorInput.value);}if(this.bgColorInput){var _t9=getComputedStyle(s).backgroundColor;if(_t9&&!/transparent|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/i.test(_t9)){var _i14=u(_t9);_i14&&this.bgColorInput.value.toLowerCase()!==_i14.toLowerCase()&&(this.bgColorInput.value=_i14);}this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=this.bgColorInput.value);}}},{key:"syncPreview",value:function syncPreview(){this.updateContent();}},{key:"updateContent",value:function updateContent(){if(!this.editorEl)return;this.ensureAtLeastOneParagraph();var t=this.editorEl.cloneNode(!0);if(this.noStyles)t.querySelectorAll("[style]").forEach(function(t){return t.removeAttribute("style");});else{var _i15=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),_s6=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),_e3=["font-weight","font-style","text-decoration","color","background-color","font-size","font-family","text-align","line-height","letter-spacing","white-space","vertical-align","list-style-position","padding-inline-start"];var _loop=function _loop(){var t=_i15.currentNode,n=_s6.currentNode,o=window.getComputedStyle(t),r=_e3.map(function(t){return"".concat(t,":").concat(o.getPropertyValue(t));}).join(";");r.trim()&&n.setAttribute("style",r);};for(;_i15.nextNode()&&_s6.nextNode();){_loop();}}this.content=t.innerHTML,this.previewEl&&(this.previewEl.innerHTML=this.content),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content},bubbles:!0,composed:!0}));}}]);}(i));t([s({type:String,attribute:!0,reflect:!0})],g.prototype,"value",void 0),t([s({type:Boolean,attribute:!0,reflect:!0})],g.prototype,"noStyles",void 0),t([s({type:Boolean,attribute:"singlelineeditor",reflect:!0})],g.prototype,"singleLineEditor",void 0),t([s({attribute:"mentions",reflect:!0,converter:{fromAttribute:function fromAttribute(t){try{var _i16=JSON.parse(t),_s7={};for(var _i17=0,_Object$keys=Object.keys(_i16);_i17<_Object$keys.length;_i17++){var _t10=_Object$keys[_i17];var _e4=_i16[_t10];Array.isArray(_e4)&&(_s7[_t10]=_e4.filter(function(t){return t&&"string"==typeof t.key&&"string"==typeof t.label;}).map(function(t){return{key:t.key,label:t.label};}));}return _s7;}catch(_unused){return{};}},toAttribute:function toAttribute(t){return JSON.stringify(t);}}})],g.prototype,"mentions",void 0),t([e()],g.prototype,"content",void 0),_export("N",g=t([n("nile-rich-text-editor")],g));}};});
|
|
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","./nile-rte-toolbar.cjs.js","./nile-rte-toolbar-item.cjs.js","./nile-rte-select.cjs.js","./nile-rte-color.cjs.js","./nile-rte-divider.cjs.js","./nile-rte-preview.cjs.js","./nile-rte-mentions.cjs.js","./nile-rte-link.cjs.js","./utils/block-utils.cjs.js","./utils/inline-utils.cjs.js","./utils/color-utils.cjs.js","./utils/list-utils.cjs.js","./nile-rich-text-editor.css.cjs.js"],function(_export,_context){"use strict";var t,i,s,e,n,o,r,h,l,c,a,u,d,f,m,p,b,g;function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var n=0,F=function F(){};return{s:F,n:function(_n4){function n(){return _n4.apply(this,arguments);}n.toString=function(){return _n4.toString();};return n;}(function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]};}),e:function e(r){throw r;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}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);}return{setters:[function(_tslib){t=_tslib.__decorate;},function(_lit){i=_lit.LitElement;},function(_litDecoratorsJs){s=_litDecoratorsJs.property;e=_litDecoratorsJs.state;n=_litDecoratorsJs.customElement;},function(_nileRteToolbarCjsJs){},function(_nileRteToolbarItemCjsJs){},function(_nileRteSelectCjsJs){},function(_nileRteColorCjsJs){},function(_nileRteDividerCjsJs){},function(_nileRtePreviewCjsJs){},function(_nileRteMentionsCjsJs){},function(_nileRteLinkCjsJs){},function(_utilsBlockUtilsCjsJs){o=_utilsBlockUtilsCjsJs.s;r=_utilsBlockUtilsCjsJs.a;h=_utilsBlockUtilsCjsJs.n;l=_utilsBlockUtilsCjsJs.c;},function(_utilsInlineUtilsCjsJs){c=_utilsInlineUtilsCjsJs.t;a=_utilsInlineUtilsCjsJs.s;u=_utilsInlineUtilsCjsJs.r;},function(_utilsColorUtilsCjsJs){d=_utilsColorUtilsCjsJs.s;f=_utilsColorUtilsCjsJs.a;},function(_utilsListUtilsCjsJs){m=_utilsListUtilsCjsJs.t;},function(_nileRichTextEditorCssCjsJs){p=_nileRichTextEditorCssCjsJs.s;}],execute:function execute(){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:"format_clear"};_export("N",g=/*#__PURE__*/function(_i){function g(){var _this;_classCallCheck(this,g);_this=_callSuper(this,g,arguments),_this.value="",_this.noStyles=!1,_this.singleLineEditor=!1,_this.placeholder="",_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.containerEl=null,_this.mentionsEl=null,_this.onEditorKeydown=function(t){if(_this.singleLineEditor&&"Enter"===t.key&&t.shiftKey)return void t.preventDefault();if(t.ctrlKey&&"i"===t.key.toLowerCase()&&(t.preventDefault(),c(_this.editorEl,"em"),_this.updateContent(),_this.updateToolbarState()),_this.singleLineEditor&&"Enter"===t.key)return void t.preventDefault();if("Tab"!==t.key)return;t.preventDefault(),_this.focusAndRestore();var i=window.getSelection();if(!i||0===i.rangeCount)return;var s=i.getRangeAt(0);if(t.shiftKey){if(s.collapsed&&s.startContainer.nodeType===Node.TEXT_NODE){var _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);var _s=document.createRange();_s.setStart(_t,_o.length),_s.collapse(!0),i.removeAllRanges(),i.addRange(_s),_this.updateContent(),_this.updateToolbarState();}}return;}s.deleteContents();var e=document.createTextNode("\t");s.insertNode(e);var n=document.createRange();n.setStartAfter(e),n.collapse(!0),i.removeAllRanges(),i.addRange(n),_this.updateContent(),_this.updateToolbarState();},_this.onSelectionChange=function(){if(!_this.editorEl)return;var t=document.getSelection();if(!t||0===t.rangeCount)return;var i=t.getRangeAt(0);_this.editorEl.contains(i.commonAncestorContainer)&&(_this.lastRange=i.cloneRange(),_this.updateToolbarState());};return _this;}_inherits(g,_i);return _createClass(g,[{key:"createRenderRoot",value:function createRenderRoot(){return this;}},{key:"injectCss",value:function injectCss(t){if(this.querySelector("style[data-rte-style]"))return;var i=document.createElement("style");i.setAttribute("data-rte-style","true"),i.textContent=t,this.insertBefore(i,this.firstChild);}},{key:"connectedCallback",value:function connectedCallback(){var _this$mentionsEl$atta,_this$mentionsEl,_this$mentionsEl$setE,_this$mentionsEl2;_superPropGet(g,"connectedCallback",this,3)([]),this.injectCss(p.cssText),this.ensureStructure(),this.placeholder&&this.editorEl&&(this.editorEl.dataset.placeholder=this.placeholder),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$atta=(_this$mentionsEl=this.mentionsEl).attach)!==null&&_this$mentionsEl$atta!==void 0&&_this$mentionsEl$atta.call(_this$mentionsEl,this.editorEl,this),(_this$mentionsEl$setE=(_this$mentionsEl2=this.mentionsEl).setExternalConfig)!==null&&_this$mentionsEl$setE!==void 0&&_this$mentionsEl$setE.call(_this$mentionsEl2,this.mentions)),this.wireEditor(),document.addEventListener("selectionchange",this.onSelectionChange,{passive:!0}),this.updateToolbarState(),this.syncPreview();}},{key:"ensureStructure",value:function ensureStructure(){this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.containerEl=this.querySelector(".rte-container"),this.containerEl||(this.containerEl=document.createElement("div"),this.containerEl.className="rte-container",this.appendChild(this.containerEl)),this.ensureEditor(),this.toolbarEl&&this.toolbarEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.toolbarEl),this.editorEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.editorEl),this.previewEl&&(this.previewEl.parentElement!==this&&this.appendChild(this.previewEl),this.previewEl.previousElementSibling!==this.containerEl&&this.insertBefore(this.previewEl,this.containerEl.nextSibling));}},{key:"updateContentWithMention",value:function updateContentWithMention(t){this.updateContent(),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content,mention:t},bubbles:!0,composed:!0}));}},{key:"disconnectedCallback",value:function disconnectedCallback(){document.removeEventListener("selectionchange",this.onSelectionChange),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),_superPropGet(g,"disconnectedCallback",this,3)([]);}},{key:"updated",value:function updated(t){t.has("value")&&this.editorEl&&this.value!==this.editorEl.innerHTML&&(this.editorEl.innerHTML=this.value||"<p><br></p>",this.content=this.editorEl.innerHTML,this.syncPreview()),t.has("singleLineEditor")&&(this.editorEl&&this.editorEl.classList.toggle("single-line",this.singleLineEditor),this.previewEl&&this.previewEl.classList.toggle("single-line",this.singleLineEditor));}},{key:"ensureEditor",value:function ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){var _t2=document.createElement("article");_t2.className="editor",_t2.setAttribute("contenteditable","true"),this.editorEl=_t2;}this.placeholder&&(this.editorEl.dataset.placeholder=this.placeholder),this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>");}},{key:"unwrapMention",value:function unwrapMention(t){var _t$textContent;var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var s=t.parentNode;if(!s)return;var e=i?((_t$textContent=t.textContent)!==null&&_t$textContent!==void 0?_t$textContent:"").replace(/\u200B/g,""):"",n=document.createTextNode(e);s.insertBefore(n,t),s.removeChild(t);var o=document.createRange();o.setStartAfter(n),o.collapse(!0);var r=window.getSelection();r!==null&&r!==void 0&&r.removeAllRanges(),r===null||r===void 0?void 0:r.addRange(o);}},{key:"scrubBrokenMentions",value:function scrubBrokenMentions(){var _this2=this;if(!this.editorEl)return;this.editorEl.querySelectorAll("span.mention").forEach(function(t){var _i$textContent;var i=t,s=i.getAttribute("data-mention-key"),e=i.getAttribute("data-mention-label"),n=i.getAttribute("data-mention-trigger")||"",o=((_i$textContent=i.textContent)!==null&&_i$textContent!==void 0?_i$textContent:"").replace(/\u200B/g,"").trim(),r=!!s&&!!e&&o.length>0&&o.startsWith(n)&&o.includes(e);o&&r||_this2.unwrapMention(i,!0);});}},{key:"wireEditor",value:function wireEditor(){var _this3=this;this.editorEl.addEventListener("input",function(){_this3.ensureAtLeastOneParagraph(),_this3.scrubBrokenMentions(),_this3.updateContent(),_this3.updateToolbarState();}),this.editorEl.addEventListener("mouseup",function(){_this3.saveSelection(),_this3.updateToolbarState();}),this.editorEl.addEventListener("keyup",function(t){_this3.saveSelection(),["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(t.key)&&_this3.updateToolbarState();}),this.editorEl.addEventListener("keydown",this.onEditorKeydown);}},{key:"wireAuthoredToolbar",value:function wireAuthoredToolbar(t){var _this4=this;this.buttonMap.clear(),this.headingSelect=null,this.fontSelect=null,this.colorInput=null,Array.from(t.children).forEach(function(t){var i=t.tagName.toLowerCase();if("nile-rte-select"!==i||"align"!==t.getAttribute("type")){if("nile-rte-link"===i)return t.editorEl=_this4.editorEl,void t.addEventListener("link-changed",function(){_this4.updateContent(),_this4.updateToolbarState();});if("nile-rte-toolbar-item"===i){var _this4$buttonMap$get;var _i2=t.querySelector(":scope > nile-button");var _s2=t.getAttribute("name")||"",_e2=t.getAttribute("label")||_s2,_n2=t.getAttribute("icon"),_o2=t.innerHTML.trim().length>0;if(_i2||(_i2=document.createElement("nile-button"),_i2.variant="tertiary",_i2.size="small"),_n2)_i2.innerHTML="<nile-icon name=\"".concat(_n2,"\" aria-label=\"").concat(_e2,"\"></nile-icon>"),t.innerHTML="";else if(_o2)_i2.innerHTML=t.innerHTML,t.innerHTML="";else{var _n3=b[_s2];_n3?_i2.innerHTML="<nile-icon name=\"".concat(_n3,"\" size=\"20\" color=\"black\" aria-label=\"").concat(_e2,"\"></nile-icon>"):_i2.textContent=_e2||_s2,t.innerHTML="";}if(!_i2.isConnected){var _s3=document.createElement("nile-tooltip");_s3.setAttribute("content",_e2),_s3.appendChild(_i2),t.appendChild(_s3);}_i2.setAttribute("aria-label",_e2),_i2.addEventListener("mousedown",function(t){return t.preventDefault();}),_i2.addEventListener("click",function(){return _this4.onToolbarCommand(_s2);});var _r=(_this4$buttonMap$get=_this4.buttonMap.get(_s2))!==null&&_this4$buttonMap$get!==void 0?_this4$buttonMap$get:[];return _r.push(_i2),void _this4.buttonMap.set(_s2,_r);}if("nile-rte-select"!==i)"nile-rte-color"!==i||t.addEventListener("change",function(t){_this4.focusAndRestore();var _t$detail=t.detail,i=_t$detail.mode,s=_t$detail.value;"backColor"===i?d(_this4.editorEl,s):f(_this4.editorEl,s),_this4.updateContent(),_this4.updateToolbarState();});else{var _i3=t.getAttribute("type")||"";t.addEventListener("change",function(t){_this4.focusAndRestore();var s=t.detail;"heading"===_i3?r(_this4.editorEl,s):"font"===_i3&&a(_this4.editorEl,s),_this4.updateContent(),_this4.updateToolbarState();});}}else t.addEventListener("change",function(t){_this4.focusAndRestore();var i=t.detail;o(_this4.editorEl,i),_this4.updateContent(),_this4.updateToolbarState();});});}},{key:"saveSelection",value:function saveSelection(){var t=window.getSelection();t&&t.rangeCount&&(this.lastRange=t.getRangeAt(0).cloneRange());}},{key:"restoreSelection",value:function restoreSelection(){if(!this.lastRange)return;var t=document.getSelection();t&&(t.removeAllRanges(),t.addRange(this.lastRange));}},{key:"focusAndRestore",value:function focusAndRestore(){var _this$editorEl;(_this$editorEl=this.editorEl)!==null&&_this$editorEl!==void 0&&_this$editorEl.focus(),this.restoreSelection();}},{key:"getCleanContent",value:function getCleanContent(){var t=this.editorEl.cloneNode(!0);return t.querySelectorAll("*").forEach(function(t){t.removeAttribute("style");}),t.innerHTML;}},{key:"insertList",value:function insertList(t){if(this.restoreSelection(),!this.lastRange)return;var i=document.createElement(t),s=this.lastRange.extractContents(),e=document.createElement("div");e.appendChild(s),Array.from(e.childNodes).forEach(function(t){var _t$textContent2;if(t.nodeType===Node.TEXT_NODE&&!((_t$textContent2=t.textContent)!==null&&_t$textContent2!==void 0&&_t$textContent2.trim()))return;var s=document.createElement("li");s.appendChild(t),i.appendChild(s);}),this.lastRange.insertNode(i),this.afterListEdit(i);}},{key:"afterListEdit",value:function afterListEdit(t){var i=document.createRange();i.setStartAfter(t),i.collapse(!0);var s=window.getSelection();s!==null&&s!==void 0&&s.removeAllRanges(),s!==null&&s!==void 0&&s.addRange(i),this.saveSelection(),this.updateContent(),this.updateToolbarState();}},{key:"ensureAtLeastOneParagraph",value:function ensureAtLeastOneParagraph(){var _t$textContent3;var t=this.editorEl;if(!t)return;var i=""===((_t$textContent3=t.textContent)!==null&&_t$textContent3!==void 0?_t$textContent3:"").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")){var _i4=document.createElement("p");for(;t.firstChild;)_i4.appendChild(t.firstChild);return _i4.hasChildNodes()||_i4.appendChild(document.createElement("br")),void t.appendChild(_i4);}t.querySelectorAll("p").forEach(function(t){var _t$textContent4;""===((_t$textContent4=t.textContent)!==null&&_t$textContent4!==void 0?_t$textContent4:"").replace(/\u200B/g,"")&&(t.innerHTML.toLowerCase().includes("<br")||(t.innerHTML="<br>"));});}},{key:"onToolbarCommand",value:function onToolbarCommand(t){switch(this.focusAndRestore(),t){case"bold":c(this.editorEl,"strong");break;case"italic":c(this.editorEl,"em");break;case"underline":c(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":m(this.editorEl,"ul"),this.updateContent(),this.updateToolbarState();break;case"ol":m(this.editorEl,"ol"),this.updateContent(),this.updateToolbarState();break;case"link":break;case"clear":var _t3=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),_i5=[];for(;_t3.nextNode();){var _s4=_t3.currentNode;_s4.removeAttribute("style"),["B","STRONG","I","EM","U","SPAN","FONT"].includes(_s4.tagName)&&_i5.push(_s4);}for(var _i7=0,_i6=_i5;_i7<_i6.length;_i7++){var _t4=_i6[_i7];for(;_t4.firstChild;){var _t4$parentNode;(_t4$parentNode=_t4.parentNode)===null||_t4$parentNode===void 0||_t4$parentNode.insertBefore(_t4.firstChild,_t4);}_t4.remove();}this.ensureAtLeastOneParagraph();}this.updateContent(),this.updateToolbarState();}},{key:"setBtnActive",value:function setBtnActive(t,i){var s=this.buttonMap.get(t);if(s){var _iterator=_createForOfIteratorHelper(s),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var _t5=_step.value;_t5.toggleAttribute("data-active",!!i);}}catch(err){_iterator.e(err);}finally{_iterator.f();}}}},{key:"updateToolbarState",value:function updateToolbarState(){var _this5=this,_s$closest;if(!this.editorEl)return;var t=document.getSelection();if(!t||0===t.rangeCount)return;var i=t.getRangeAt(0);if(!this.editorEl.contains(i.commonAncestorContainer))return;var s=h(i.startContainer)||this.editorEl,e=getComputedStyle(s),n=l(i.startContainer,this.editorEl)||this.editorEl,o=function(){var t=s;for(;t&&t!==_this5.editorEl;){if(t instanceof HTMLElement){var _i8=t.tagName.toLowerCase();if("strong"===_i8||"b"===_i8)return!0;var _s5=getComputedStyle(t).fontWeight;if(parseInt(_s5,10)>=600)return!0;}t=t.parentNode;}return!1;}(),r=function(){var t=s;for(;t&&t!==_this5.editorEl;){if(t instanceof HTMLElement){var _i9=t.tagName.toLowerCase();if("em"===_i9||"i"===_i9)return!0;if("italic"===getComputedStyle(t).fontStyle)return!0;}t=t.parentNode;}return!1;}(),c=function(){var t=s;for(;t&&t!==_this5.editorEl;){if(t instanceof HTMLElement){var _i10=getComputedStyle(t).textDecorationLine;if(_i10&&_i10.includes("underline"))return!0;if("u"===t.tagName.toLowerCase())return!0;}t=t.parentNode;}return!1;}(),a=!!s.closest("a"),d=n.style.textAlign||getComputedStyle(n).textAlign||"start",f="start"===d?"left":d,m=!!s.closest("li")&&((_s$closest=s.closest("ul,ol"))===null||_s$closest===void 0?void 0:_s$closest.tagName.toLowerCase())||"";if(this.setBtnActive("bold",o),this.setBtnActive("italic",r),this.setBtnActive("underline",c),this.setBtnActive("link",a),this.setBtnActive("left","left"===f&&!["center","right","justify"].includes(f)),this.setBtnActive("center","center"===f),this.setBtnActive("right","right"===f),this.setBtnActive("justify","justify"===f),this.setBtnActive("ul","ul"===m),this.setBtnActive("ol","ol"===m),this.headingSelect){var _t6=n.tagName.toLowerCase(),_i11=["h1","h2","h3"].includes(_t6)?_t6:"p";this.headingSelect.value!==_i11&&(this.headingSelect.value=_i11);}if(this.fontSelect){var _t7=(e.fontFamily||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase();if(_t7)for(var _i12=0,_Array$from=Array.from(this.fontSelect.options);_i12<_Array$from.length;_i12++){var _i13=_Array$from[_i12];if(_i13.value.toLowerCase()===_t7){this.fontSelect.value=_i13.value;break;}}}if(this.colorInput){var _t8=u(e.color);_t8&&this.colorInput.value.toLowerCase()!==_t8.toLowerCase()&&(this.colorInput.value=_t8),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=this.colorInput.value);}if(this.bgColorInput){var _t9=getComputedStyle(s).backgroundColor;if(_t9&&!/transparent|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/i.test(_t9)){var _i14=u(_t9);_i14&&this.bgColorInput.value.toLowerCase()!==_i14.toLowerCase()&&(this.bgColorInput.value=_i14);}this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=this.bgColorInput.value);}}},{key:"syncPreview",value:function syncPreview(){this.updateContent();}},{key:"updateContent",value:function updateContent(){var _this$editorEl$textCo;if(!this.editorEl)return;this.ensureAtLeastOneParagraph();var t=""===((_this$editorEl$textCo=this.editorEl.textContent)!==null&&_this$editorEl$textCo!==void 0?_this$editorEl$textCo:"").trim();this.editorEl.classList.toggle("empty",t);var i=this.editorEl.cloneNode(!0);if(this.noStyles)i.querySelectorAll("[style]").forEach(function(t){return t.removeAttribute("style");});else{var _t10=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),_s6=document.createTreeWalker(i,NodeFilter.SHOW_ELEMENT),_e3=["font-weight","font-style","text-decoration","color","background-color","font-size","font-family","text-align","line-height","letter-spacing","white-space","vertical-align","list-style-position","padding-inline-start"];var _loop=function _loop(){var i=_t10.currentNode,n=_s6.currentNode,o=window.getComputedStyle(i),r=_e3.map(function(t){return"".concat(t,":").concat(o.getPropertyValue(t));}).join(";");r.trim()&&n.setAttribute("style",r);};for(;_t10.nextNode()&&_s6.nextNode();){_loop();}}this.content=i.innerHTML,this.previewEl&&(this.previewEl.innerHTML=this.content),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content},bubbles:!0,composed:!0}));}}]);}(i));t([s({type:String,attribute:!0,reflect:!0})],g.prototype,"value",void 0),t([s({type:Boolean,attribute:!0,reflect:!0})],g.prototype,"noStyles",void 0),t([s({type:Boolean,attribute:"singlelineeditor",reflect:!0})],g.prototype,"singleLineEditor",void 0),t([s({type:String})],g.prototype,"placeholder",void 0),t([s({attribute:"mentions",reflect:!0,converter:{fromAttribute:function fromAttribute(t){try{var _i15=JSON.parse(t),_s7={};for(var _i16=0,_Object$keys=Object.keys(_i15);_i16<_Object$keys.length;_i16++){var _t11=_Object$keys[_i16];var _e4=_i15[_t11];Array.isArray(_e4)&&(_s7[_t11]=_e4.filter(function(t){return t&&"string"==typeof t.key&&"string"==typeof t.label;}).map(function(t){return{key:t.key,label:t.label};}));}return _s7;}catch(_unused){return{};}},toAttribute:function toAttribute(t){return JSON.stringify(t);}}})],g.prototype,"mentions",void 0),t([e()],g.prototype,"content",void 0),_export("N",g=t([n("nile-rich-text-editor")],g));}};});
|
|
2
2
|
//# sourceMappingURL=nile-rich-text-editor.cjs.js.map
|