@aquera/nile-elements 0.0.9 → 0.0.10
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/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/internal/enum.d.ts +17 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/internal/enum.js +18 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/internal/enum.js.map +1 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-content-editor/nile-content-editor.css.js +14 -3
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-content-editor/nile-content-editor.css.js.map +1 -1
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-content-editor/nile-content-editor.d.ts +15 -4
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-content-editor/nile-content-editor.js +111 -51
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-content-editor/nile-content-editor.js.map +1 -1
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.d.ts +3 -1
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.js +9 -6
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.js.map +1 -1
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.iife.js +31 -18
- package/dist/internal/enum.cjs.js +2 -0
- package/dist/internal/enum.cjs.js.map +1 -0
- package/dist/internal/enum.esm.js +1 -0
- package/dist/nile-content-editor/index.cjs.js +1 -1
- package/dist/nile-content-editor/index.esm.js +1 -1
- package/dist/nile-content-editor/nile-content-editor.cjs.js +1 -1
- package/dist/nile-content-editor/nile-content-editor.cjs.js.map +1 -1
- package/dist/nile-content-editor/nile-content-editor.css.cjs.js +1 -1
- package/dist/nile-content-editor/nile-content-editor.css.cjs.js.map +1 -1
- package/dist/nile-content-editor/nile-content-editor.css.esm.js +14 -3
- package/dist/nile-content-editor/nile-content-editor.esm.js +13 -12
- package/dist/nile-switcher/nile-switcher.cjs.js +1 -1
- package/dist/nile-switcher/nile-switcher.cjs.js.map +1 -1
- package/dist/nile-switcher/nile-switcher.esm.js +9 -8
- package/dist/src/internal/enum.d.ts +17 -0
- package/dist/src/internal/enum.js +18 -0
- package/dist/src/internal/enum.js.map +1 -0
- package/dist/src/nile-content-editor/nile-content-editor.css.js +14 -3
- package/dist/src/nile-content-editor/nile-content-editor.css.js.map +1 -1
- package/dist/src/nile-content-editor/nile-content-editor.d.ts +15 -4
- package/dist/src/nile-content-editor/nile-content-editor.js +111 -51
- package/dist/src/nile-content-editor/nile-content-editor.js.map +1 -1
- package/dist/src/nile-switcher/nile-switcher.d.ts +3 -1
- package/dist/src/nile-switcher/nile-switcher.js +9 -6
- package/dist/src/nile-switcher/nile-switcher.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/internal/enum.ts +17 -0
- package/src/nile-content-editor/nile-content-editor.css.ts +14 -3
- package/src/nile-content-editor/nile-content-editor.ts +123 -59
- package/src/nile-switcher/nile-switcher.ts +12 -6
package/package.json
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
export const KeyCode = {
|
2
|
+
BACKSPACE: 'Backspace',
|
3
|
+
TAB: 'Tab',
|
4
|
+
ENTER: 'Enter',
|
5
|
+
SHIFT: 'ShiftLeft', // or 'ShiftRight'
|
6
|
+
CTRL: 'ControlLeft', // or 'ControlRight'
|
7
|
+
ESCAPE: 'Escape',
|
8
|
+
SPACE: 'Space',
|
9
|
+
PAGE_UP: 'PageUp',
|
10
|
+
PAGE_DOWN: 'PageDown',
|
11
|
+
END: 'End',
|
12
|
+
HOME: 'Home',
|
13
|
+
ARROW_LEFT: 'ArrowLeft',
|
14
|
+
ARROW_UP: 'ArrowUp',
|
15
|
+
ARROW_RIGHT: 'ArrowRight',
|
16
|
+
ARROW_DOWN: 'ArrowDown',
|
17
|
+
};
|
@@ -14,6 +14,7 @@ export const styles = css`
|
|
14
14
|
:host {
|
15
15
|
width: 100%;
|
16
16
|
box-sizing: border-box;
|
17
|
+
font-size: 14px;
|
17
18
|
}
|
18
19
|
|
19
20
|
.content-editable-wrapper {
|
@@ -49,21 +50,30 @@ export const styles = css`
|
|
49
50
|
border-color: #e5434d;
|
50
51
|
}
|
51
52
|
|
53
|
+
.read-only {
|
54
|
+
cursor: not-allowed;
|
55
|
+
}
|
56
|
+
|
52
57
|
.chips {
|
58
|
+
display: inline;
|
53
59
|
background: #e5e9eb;
|
54
60
|
color: #000;
|
55
61
|
border-radius: 4px;
|
56
62
|
padding: 6px;
|
63
|
+
height: 24px;
|
64
|
+
line-height: 10px;
|
57
65
|
margin-left: 3px;
|
58
|
-
display: inline;
|
59
66
|
letter-spacing: 0.2px;
|
60
67
|
}
|
61
68
|
|
62
69
|
.text-area {
|
63
70
|
height: 120px;
|
64
|
-
white-space: pre-wrap;
|
65
71
|
overflow: scroll;
|
66
|
-
line-height:
|
72
|
+
line-height: 26px;
|
73
|
+
}
|
74
|
+
|
75
|
+
.text-area .chips {
|
76
|
+
padding: 4px 8px;
|
67
77
|
}
|
68
78
|
|
69
79
|
.chip-error {
|
@@ -74,6 +84,7 @@ export const styles = css`
|
|
74
84
|
background-color: #ffffff;
|
75
85
|
border: 1px solid #c7ced4;
|
76
86
|
overflow: auto;
|
87
|
+
max-height: 150px;
|
77
88
|
}
|
78
89
|
|
79
90
|
label {
|
@@ -12,6 +12,8 @@ import { CSSResultGroup } from 'lit';
|
|
12
12
|
import { classMap } from 'lit/directives/class-map.js';
|
13
13
|
import NileElement from '../internal/nile-element';
|
14
14
|
import { watch } from '../internal/watch';
|
15
|
+
import { KeyCode } from '../internal/enum';
|
16
|
+
import { live } from 'lit/directives/live.js';
|
15
17
|
|
16
18
|
/**
|
17
19
|
* Nile icon component.
|
@@ -33,6 +35,8 @@ export class NileContentEditor extends NileElement {
|
|
33
35
|
|
34
36
|
@property() options: Array<any>;
|
35
37
|
|
38
|
+
@property() filteredOptions: Array<any>;
|
39
|
+
|
36
40
|
@property() showLabel: boolean = true;
|
37
41
|
|
38
42
|
@property() labelText = '';
|
@@ -41,53 +45,113 @@ export class NileContentEditor extends NileElement {
|
|
41
45
|
|
42
46
|
@property() required: boolean = true;
|
43
47
|
|
44
|
-
@query('.content-editable-input')
|
48
|
+
@query('.content-editable-input') contentEditor: HTMLInputElement;
|
45
49
|
@query('.nile-options-container') autoOptions: HTMLInputElement;
|
46
50
|
|
47
|
-
@state()
|
51
|
+
@state() openDropdown = false;
|
52
|
+
|
53
|
+
tagIdentifier = '$';
|
54
|
+
|
55
|
+
filteredValue = '';
|
48
56
|
|
49
57
|
@property({ attribute: 'help-text' }) helpText = '';
|
50
58
|
|
59
|
+
@property({ attribute: 'readonly' }) readonly = false;
|
60
|
+
|
51
61
|
@property({ attribute: 'error-message' }) errorMessage = '';
|
52
62
|
|
63
|
+
@property({ attribute: 'error' }) error = false;
|
64
|
+
|
53
65
|
static styles: CSSResultGroup = styles;
|
54
66
|
|
55
67
|
connectedCallback() {
|
68
|
+
this.handleOutsideClick = this.handleOutsideClick.bind(this);
|
56
69
|
super.connectedCallback();
|
57
70
|
this.emit('nile-init');
|
58
|
-
this.
|
59
|
-
|
60
|
-
|
71
|
+
this.addOpenListeners();
|
72
|
+
this.setInitialValues();
|
73
|
+
}
|
74
|
+
|
75
|
+
setInitialValues() {
|
76
|
+
this.updateComplete.then(res => {
|
77
|
+
if (res && !!this.value)
|
78
|
+
this.contentEditor.innerHTML = this.generateHTMLTagsWithValues(
|
79
|
+
this.value
|
80
|
+
);
|
61
81
|
});
|
62
82
|
}
|
63
83
|
|
84
|
+
addOpenListeners() {
|
85
|
+
window.addEventListener('click', this.handleOutsideClick);
|
86
|
+
}
|
87
|
+
|
88
|
+
removeOpenListeners() {
|
89
|
+
window.removeEventListener('click', this.handleOutsideClick);
|
90
|
+
}
|
91
|
+
|
92
|
+
toggleDropdown(value: boolean) {
|
93
|
+
this.openDropdown = value;
|
94
|
+
}
|
95
|
+
|
96
|
+
handleOutsideClick(event: Event) {
|
97
|
+
if (event && event.target) {
|
98
|
+
this.toggleDropdown(false);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
64
102
|
@watch('type', { waitUntilFirstUpdate: true })
|
65
103
|
handleTypeChange() {
|
66
|
-
this.
|
104
|
+
this.contentEditor.innerHTML = this.generateHTMLTagsWithValues(this.value);
|
67
105
|
}
|
68
106
|
|
69
107
|
disconnectedCallback(): void {
|
70
108
|
super.disconnectedCallback();
|
109
|
+
this.removeOpenListeners();
|
71
110
|
this.emit('nile-destroy');
|
72
111
|
}
|
73
112
|
|
74
|
-
|
75
|
-
|
113
|
+
handlePaste(event: ClipboardEvent) {
|
114
|
+
event.preventDefault();
|
115
|
+
if (event.clipboardData) {
|
116
|
+
let text = event.clipboardData.getData('text/plain');
|
117
|
+
document.execCommand('insertText', false, text);
|
118
|
+
}
|
119
|
+
this.emitInputChange();
|
76
120
|
}
|
77
121
|
|
78
122
|
private handlekeyDown(event: any) {
|
79
|
-
if (event.code ===
|
123
|
+
if (event.code === KeyCode.ENTER && this.type === 'text') {
|
80
124
|
event.preventDefault();
|
125
|
+
return;
|
126
|
+
}
|
127
|
+
if (event.code === KeyCode.ESCAPE) {
|
128
|
+
event.preventDefault();
|
129
|
+
this.toggleDropdown(false);
|
130
|
+
return;
|
81
131
|
}
|
82
132
|
setTimeout(() => {
|
83
|
-
const value = this.
|
133
|
+
const value = this.contentEditor.innerText;
|
84
134
|
this.emitInputChange();
|
85
|
-
if (value.includes(
|
86
|
-
this.
|
135
|
+
if (value.includes(this.tagIdentifier)) {
|
136
|
+
this.toggleDropdown(true);
|
137
|
+
this.filterOptions();
|
138
|
+
} else {
|
139
|
+
this.toggleDropdown(false);
|
87
140
|
}
|
88
141
|
});
|
89
142
|
}
|
90
143
|
|
144
|
+
filterOptions() {
|
145
|
+
this.filteredOptions = this.options;
|
146
|
+
if (!!this.options.length && !!this.filteredValue) {
|
147
|
+
this.filteredOptions = this.options.filter(item =>
|
148
|
+
item.startsWith(this.filteredValue)
|
149
|
+
);
|
150
|
+
} else {
|
151
|
+
this.filteredOptions = this.options;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
91
155
|
generateValuesFromHTMLTags(string: any): string {
|
92
156
|
var pattern =
|
93
157
|
/<span class="chips(?: chip-error)?" contenteditable="false">(.*?)<\/span>/g;
|
@@ -110,53 +174,49 @@ export class NileContentEditor extends NileElement {
|
|
110
174
|
}
|
111
175
|
|
112
176
|
emitInputChange(): void {
|
113
|
-
|
177
|
+
if (this.contentEditor) {
|
178
|
+
let fieldValue = this.contentEditor.innerHTML;
|
114
179
|
|
115
|
-
|
116
|
-
|
180
|
+
if (this.contentEditor.innerText !== '') {
|
181
|
+
fieldValue = this.generateValuesFromHTMLTags(fieldValue);
|
182
|
+
}
|
183
|
+
fieldValue = fieldValue.replace(/ /g, ' ');
|
184
|
+
fieldValue = fieldValue === '<br>' ? '' : fieldValue?.trim();
|
185
|
+
this.emit('nile-change', {
|
186
|
+
value: this.generateValuesFromHTMLTags(fieldValue),
|
187
|
+
});
|
117
188
|
}
|
118
|
-
fieldValue = fieldValue.replace(/ /g, ' ');
|
119
|
-
fieldValue = fieldValue === '<br>' ? '' : fieldValue?.trim();
|
120
|
-
this.emit('nile-change', {
|
121
|
-
value: this.generateValuesFromHTMLTags(fieldValue),
|
122
|
-
});
|
123
189
|
}
|
124
190
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
};
|
134
|
-
|
135
|
-
handleOptions(option: any): void {
|
136
|
-
this.openDropdown = !this.openDropdown;
|
137
|
-
|
138
|
-
// not appending Native element as it replaces all existing child nodes with new node
|
139
|
-
const autoOptionsTag =
|
140
|
-
'<span class="chips" contenteditable="false">' + option + '</span>';
|
141
|
-
// text editor adds div when pressing enter , so before appending have to check if its parent node is div else append it to content editable parent
|
142
|
-
if (this.input?.lastElementChild?.tagName === 'DIV') {
|
143
|
-
this.input.lastElementChild.insertAdjacentHTML(
|
144
|
-
'beforeend',
|
145
|
-
autoOptionsTag
|
146
|
-
);
|
147
|
-
if (this.input.lastElementChild.lastChild?.previousSibling)
|
148
|
-
this.input.lastElementChild.lastChild.previousSibling.nodeValue =
|
149
|
-
this.input.lastElementChild.lastChild.previousSibling.nodeValue!.replace(
|
150
|
-
'$',
|
191
|
+
insertNodes(parentNode: Node, childNodes: NodeList, autoOptionsTag: Node) {
|
192
|
+
Array.from(childNodes).map((node: Node, index: number) => {
|
193
|
+
if (node.hasChildNodes()) {
|
194
|
+
this.insertNodes(node, node.childNodes, autoOptionsTag);
|
195
|
+
} else {
|
196
|
+
if (node.nodeValue?.includes(this.tagIdentifier)) {
|
197
|
+
parentNode.childNodes[index].nodeValue = node.nodeValue?.replace(
|
198
|
+
this.tagIdentifier + this.filteredValue,
|
151
199
|
''
|
152
200
|
);
|
153
|
-
|
154
|
-
|
155
|
-
if (this.input.lastChild?.previousSibling) {
|
156
|
-
this.input.lastChild.previousSibling.nodeValue =
|
157
|
-
this.input.lastChild.previousSibling.nodeValue!.replace('$', '');
|
201
|
+
parentNode.childNodes[index].after(autoOptionsTag);
|
202
|
+
}
|
158
203
|
}
|
159
|
-
}
|
204
|
+
});
|
205
|
+
}
|
206
|
+
|
207
|
+
handleOptions(option: any): void {
|
208
|
+
this.toggleDropdown(false);
|
209
|
+
let autoOptionsTag = document.createElement('span');
|
210
|
+
autoOptionsTag.setAttribute('class', 'chips');
|
211
|
+
autoOptionsTag.setAttribute('contentEditable', 'false');
|
212
|
+
autoOptionsTag.innerText = option;
|
213
|
+
this.insertNodes(
|
214
|
+
this.contentEditor,
|
215
|
+
this.contentEditor.childNodes,
|
216
|
+
autoOptionsTag
|
217
|
+
);
|
218
|
+
this.filteredOptions = this.options;
|
219
|
+
this.filteredValue = '';
|
160
220
|
this.emitInputChange();
|
161
221
|
}
|
162
222
|
|
@@ -165,10 +225,10 @@ export class NileContentEditor extends NileElement {
|
|
165
225
|
class="${classMap({
|
166
226
|
'nile-options-container': true,
|
167
227
|
'dropdown-position': this.type === 'text-area',
|
168
|
-
})}
|
228
|
+
})}"
|
169
229
|
>
|
170
|
-
${this.
|
171
|
-
this.
|
230
|
+
${this.filteredOptions &&
|
231
|
+
this.filteredOptions.map((option: any) => {
|
172
232
|
return html` <nile-option
|
173
233
|
.value="${option}"
|
174
234
|
@click="${(event: Event) => {
|
@@ -182,11 +242,13 @@ export class NileContentEditor extends NileElement {
|
|
182
242
|
|
183
243
|
public render(): TemplateResult {
|
184
244
|
const hasHelpText = this.helpText ? true : false;
|
245
|
+
const hasError = !!this.error;
|
185
246
|
const hasErrorMessage = !!this.errorMessage;
|
247
|
+
const readonly = !!this.readonly;
|
186
248
|
const type = this.type;
|
187
249
|
return html`
|
188
250
|
<nile-popup
|
189
|
-
.active="${this.openDropdown}"
|
251
|
+
.active="${live(this.openDropdown)}"
|
190
252
|
sync="width"
|
191
253
|
placement="bottom"
|
192
254
|
class=${classMap({
|
@@ -199,17 +261,19 @@ export class NileContentEditor extends NileElement {
|
|
199
261
|
${this.showLabel && this.labelText
|
200
262
|
? html`<label class="ods-label">${this.labelText} </label> ${this
|
201
263
|
.required
|
202
|
-
? html`<
|
264
|
+
? html`<sapn class="asterik">*</span>`
|
203
265
|
: ''}`
|
204
266
|
: ''}
|
205
267
|
<div
|
206
|
-
contenteditable="
|
268
|
+
contenteditable="${!readonly}"
|
207
269
|
class=${classMap({
|
208
270
|
'content-editable-input': true,
|
209
|
-
error: hasErrorMessage,
|
271
|
+
error: hasError || hasErrorMessage,
|
272
|
+
'read-only': readonly,
|
210
273
|
'text-area': type === 'text-area' ? true : false,
|
211
274
|
})}
|
212
275
|
@keydown=${this.handlekeyDown}
|
276
|
+
@paste=${this.handlePaste}
|
213
277
|
></div>
|
214
278
|
${hasHelpText
|
215
279
|
? html`
|
@@ -32,6 +32,7 @@ export interface switchconfig {
|
|
32
32
|
[key: string]: any;
|
33
33
|
toggleSwitch: boolean;
|
34
34
|
disable?: boolean;
|
35
|
+
confirmation?: boolean;
|
35
36
|
defaultInput: switchInputType;
|
36
37
|
switchInput: switchInputType;
|
37
38
|
}
|
@@ -46,7 +47,8 @@ export interface switchInputType {
|
|
46
47
|
| INPUT_TYPE_NAMES.CONTENTEDITOR;
|
47
48
|
value?: String | boolean;
|
48
49
|
label?: String;
|
49
|
-
|
50
|
+
readonly?: boolean;
|
51
|
+
type?: string;
|
50
52
|
placeholder?: string;
|
51
53
|
disabled?: boolean;
|
52
54
|
required?: boolean;
|
@@ -183,11 +185,13 @@ export class NileSwitcher extends NileElement {
|
|
183
185
|
inputType: inputTypeName,
|
184
186
|
errorMessage,
|
185
187
|
type,
|
188
|
+
readonly,
|
186
189
|
} = Input;
|
187
190
|
return html`<nile-content-editor
|
188
191
|
.value=${value}
|
189
192
|
.options=${options}
|
190
193
|
.type =${type}
|
194
|
+
.readonly=${readonly}
|
191
195
|
.errorMessage=${errorMessage}
|
192
196
|
@nile-change=${(e: CustomEvent) => {
|
193
197
|
this.handleChange(e, inputType, inputTypeName);
|
@@ -216,7 +220,7 @@ export class NileSwitcher extends NileElement {
|
|
216
220
|
size="14"
|
217
221
|
class=${classMap({
|
218
222
|
'pointer-cursor': true,
|
219
|
-
'flex-start':
|
223
|
+
'flex-start': true,
|
220
224
|
})}
|
221
225
|
.name=${icon}
|
222
226
|
color="#005EA6"
|
@@ -225,10 +229,12 @@ export class NileSwitcher extends NileElement {
|
|
225
229
|
}
|
226
230
|
|
227
231
|
toggleField() {
|
228
|
-
this.nileSwitchConfig
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
+
if (!this.nileSwitchConfig.confirmation) {
|
233
|
+
this.nileSwitchConfig = {
|
234
|
+
...this.nileSwitchConfig,
|
235
|
+
toggleSwitch: !this.nileSwitchConfig.toggleSwitch,
|
236
|
+
};
|
237
|
+
}
|
232
238
|
this.emit('nile-switch', { config: this.nileSwitchConfig });
|
233
239
|
}
|
234
240
|
|