@aquera/nile-elements 0.0.31 → 0.0.32
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/index.d.ts +1 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/index.js +1 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/index.js.map +1 -1
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-code-editor/extensionSetup.d.ts +33 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-code-editor/extensionSetup.js +63 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-code-editor/extensionSetup.js.map +1 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-code-editor/index.d.ts +1 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-code-editor/index.js +2 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-code-editor/index.js.map +1 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-code-editor/nile-code-editor.css.d.ts +12 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-code-editor/nile-code-editor.css.js +42 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-code-editor/nile-code-editor.css.js.map +1 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-code-editor/nile-code-editor.d.ts +43 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-code-editor/nile-code-editor.js +114 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-code-editor/nile-code-editor.js.map +1 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.css.js +11 -0
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.css.js.map +1 -1
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.d.ts +11 -5
- package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.js +55 -7
- 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 +408 -352
- package/dist/nile-code-editor/extensionSetup.cjs.js +7 -0
- package/dist/nile-code-editor/extensionSetup.cjs.js.map +1 -0
- package/dist/nile-code-editor/extensionSetup.esm.js +1 -0
- package/dist/nile-code-editor/index.cjs.js +2 -0
- package/dist/nile-code-editor/index.cjs.js.map +1 -0
- package/dist/nile-code-editor/index.esm.js +1 -0
- package/dist/nile-code-editor/nile-code-editor.cjs.js +3 -0
- package/dist/nile-code-editor/nile-code-editor.cjs.js.map +1 -0
- package/dist/nile-code-editor/nile-code-editor.css.cjs.js +2 -0
- package/dist/nile-code-editor/nile-code-editor.css.cjs.js.map +1 -0
- package/dist/nile-code-editor/nile-code-editor.css.esm.js +30 -0
- package/dist/nile-code-editor/nile-code-editor.esm.js +9 -0
- package/dist/nile-switcher/index.cjs.js +1 -1
- package/dist/nile-switcher/index.esm.js +1 -1
- 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.css.cjs.js +1 -1
- package/dist/nile-switcher/nile-switcher.css.cjs.js.map +1 -1
- package/dist/nile-switcher/nile-switcher.css.esm.js +13 -2
- package/dist/nile-switcher/nile-switcher.esm.js +38 -30
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/nile-code-editor/extensionSetup.d.ts +33 -0
- package/dist/src/nile-code-editor/extensionSetup.js +63 -0
- package/dist/src/nile-code-editor/extensionSetup.js.map +1 -0
- package/dist/src/nile-code-editor/index.d.ts +1 -0
- package/dist/src/nile-code-editor/index.js +2 -0
- package/dist/src/nile-code-editor/index.js.map +1 -0
- package/dist/src/nile-code-editor/nile-code-editor.css.d.ts +12 -0
- package/dist/src/nile-code-editor/nile-code-editor.css.js +42 -0
- package/dist/src/nile-code-editor/nile-code-editor.css.js.map +1 -0
- package/dist/src/nile-code-editor/nile-code-editor.d.ts +43 -0
- package/dist/src/nile-code-editor/nile-code-editor.js +114 -0
- package/dist/src/nile-code-editor/nile-code-editor.js.map +1 -0
- package/dist/src/nile-switcher/nile-switcher.css.js +11 -0
- package/dist/src/nile-switcher/nile-switcher.css.js.map +1 -1
- package/dist/src/nile-switcher/nile-switcher.d.ts +11 -5
- package/dist/src/nile-switcher/nile-switcher.js +55 -7
- package/dist/src/nile-switcher/nile-switcher.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -1
- package/src/nile-code-editor/extensionSetup.ts +125 -0
- package/src/nile-code-editor/index.ts +1 -0
- package/src/nile-code-editor/nile-code-editor.css.ts +44 -0
- package/src/nile-code-editor/nile-code-editor.ts +127 -0
- package/src/nile-switcher/nile-switcher.css.ts +11 -0
- package/src/nile-switcher/nile-switcher.ts +70 -10
package/package.json
CHANGED
package/src/index.ts
CHANGED
@@ -29,7 +29,7 @@ export { NileErrorMessage } from './nile-error-message';
|
|
29
29
|
export { NileFormErrorMessage } from './nile-form-error-message';
|
30
30
|
export { NileFormHelpText } from './nile-form-help-text';
|
31
31
|
export { NileCalendar } from './nile-calendar';
|
32
|
-
export { NileLink} from './nile-link';
|
32
|
+
export { NileLink } from './nile-link';
|
33
33
|
export { NileButtonToggleGroup } from './nile-button-toggle-group';
|
34
34
|
export { NileButtonToggle } from './nile-button-toggle';
|
35
35
|
export { NileSwitcher } from './nile-switcher';
|
@@ -39,4 +39,5 @@ export { NileErrorNotification } from './nile-error-notification';
|
|
39
39
|
export { NileTabGroup } from './nile-tab-group';
|
40
40
|
export { NileTab } from './nile-tab';
|
41
41
|
export { NileTabPanel } from './nile-tab-panel';
|
42
|
+
export { NileCodeEditor } from './nile-code-editor';
|
42
43
|
export { NileToast } from './nile-toast';
|
@@ -0,0 +1,125 @@
|
|
1
|
+
import {
|
2
|
+
KeyBinding,
|
3
|
+
lineNumbers,
|
4
|
+
highlightActiveLineGutter,
|
5
|
+
highlightSpecialChars,
|
6
|
+
drawSelection,
|
7
|
+
dropCursor,
|
8
|
+
rectangularSelection,
|
9
|
+
crosshairCursor,
|
10
|
+
highlightActiveLine,
|
11
|
+
keymap,
|
12
|
+
} from '@codemirror/view';
|
13
|
+
import { EditorState, Extension } from '@codemirror/state';
|
14
|
+
import { history, defaultKeymap, historyKeymap } from '@codemirror/commands';
|
15
|
+
import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';
|
16
|
+
import {
|
17
|
+
closeBrackets,
|
18
|
+
autocompletion,
|
19
|
+
closeBracketsKeymap,
|
20
|
+
completionKeymap,
|
21
|
+
} from '@codemirror/autocomplete';
|
22
|
+
import {
|
23
|
+
foldGutter,
|
24
|
+
indentOnInput,
|
25
|
+
syntaxHighlighting,
|
26
|
+
defaultHighlightStyle,
|
27
|
+
bracketMatching,
|
28
|
+
indentUnit,
|
29
|
+
foldKeymap,
|
30
|
+
} from '@codemirror/language';
|
31
|
+
|
32
|
+
import { lintKeymap } from '@codemirror/lint';
|
33
|
+
|
34
|
+
export interface BasicSetupOptions extends MinimalSetupOptions {
|
35
|
+
lineNumbers?: boolean;
|
36
|
+
highlightActiveLineGutter?: boolean;
|
37
|
+
foldGutter?: boolean;
|
38
|
+
dropCursor?: boolean;
|
39
|
+
allowMultipleSelections?: boolean;
|
40
|
+
indentOnInput?: boolean;
|
41
|
+
bracketMatching?: boolean;
|
42
|
+
closeBrackets?: boolean;
|
43
|
+
autocompletion?: boolean;
|
44
|
+
rectangularSelection?: boolean;
|
45
|
+
crosshairCursor?: boolean;
|
46
|
+
highlightActiveLine?: boolean;
|
47
|
+
highlightSelectionMatches?: boolean;
|
48
|
+
closeBracketsKeymap?: boolean;
|
49
|
+
searchKeymap?: boolean;
|
50
|
+
foldKeymap?: boolean;
|
51
|
+
completionKeymap?: boolean;
|
52
|
+
lintKeymap?: boolean;
|
53
|
+
tabSize?: number;
|
54
|
+
}
|
55
|
+
|
56
|
+
export const isValidSetup = (item: any) => {
|
57
|
+
return typeof item === 'undefined' || item;
|
58
|
+
};
|
59
|
+
|
60
|
+
export const basicSetup = (options: BasicSetupOptions = {}): Extension[] => {
|
61
|
+
const { crosshairCursor: initCrosshairCursor = false } = options;
|
62
|
+
let keymaps: KeyBinding[] = [];
|
63
|
+
isValidSetup(options.defaultKeymap) && keymaps.push(...defaultKeymap);
|
64
|
+
isValidSetup(options.closeBracketsKeymap) &&
|
65
|
+
keymaps.push(...closeBracketsKeymap);
|
66
|
+
isValidSetup(options.searchKeymap) && keymaps.push(...searchKeymap);
|
67
|
+
isValidSetup(options.historyKeymap) && keymaps.push(...historyKeymap);
|
68
|
+
isValidSetup(options.foldKeymap) && keymaps.push(...foldKeymap);
|
69
|
+
isValidSetup(options.lintKeymap) && keymaps.push(...lintKeymap);
|
70
|
+
const extensions: Extension[] = [];
|
71
|
+
isValidSetup(options.lineNumbers) && extensions.push(lineNumbers());
|
72
|
+
isValidSetup(options.highlightActiveLineGutter) &&
|
73
|
+
extensions.push(highlightActiveLineGutter());
|
74
|
+
isValidSetup(options.highlightSpecialChars) &&
|
75
|
+
extensions.push(highlightSpecialChars());
|
76
|
+
isValidSetup(options.history) && extensions.push(history());
|
77
|
+
isValidSetup(options.foldGutter) && extensions.push(foldGutter());
|
78
|
+
isValidSetup(options.drawSelection) && extensions.push(drawSelection());
|
79
|
+
isValidSetup(options.dropCursor) && extensions.push(dropCursor());
|
80
|
+
isValidSetup(options.allowMultipleSelections) &&
|
81
|
+
extensions.push(EditorState.allowMultipleSelections.of(true));
|
82
|
+
isValidSetup(options.indentOnInput) && extensions.push(indentOnInput());
|
83
|
+
isValidSetup(options.syntaxHighlighting) &&
|
84
|
+
extensions.push(
|
85
|
+
syntaxHighlighting(defaultHighlightStyle, { fallback: true })
|
86
|
+
);
|
87
|
+
isValidSetup(options.bracketMatching) && extensions.push(bracketMatching());
|
88
|
+
isValidSetup(options.closeBrackets) && extensions.push(closeBrackets());
|
89
|
+
isValidSetup(options.autocompletion) && extensions.push(autocompletion());
|
90
|
+
isValidSetup(options.rectangularSelection) &&
|
91
|
+
extensions.push(rectangularSelection());
|
92
|
+
isValidSetup(options.crosshairCursor) && extensions.push(crosshairCursor());
|
93
|
+
isValidSetup(options.highlightActiveLine) &&
|
94
|
+
extensions.push(highlightActiveLine());
|
95
|
+
isValidSetup(options.highlightSelectionMatches) &&
|
96
|
+
extensions.push(highlightSelectionMatches());
|
97
|
+
if (options.tabSize && typeof options.tabSize === 'number')
|
98
|
+
extensions.push(indentUnit.of(' '.repeat(options.tabSize)));
|
99
|
+
return extensions.concat([keymap.of(keymaps.flat())]).filter(Boolean);
|
100
|
+
};
|
101
|
+
|
102
|
+
export interface MinimalSetupOptions {
|
103
|
+
highlightSpecialChars?: boolean;
|
104
|
+
history?: boolean;
|
105
|
+
drawSelection?: boolean;
|
106
|
+
syntaxHighlighting?: boolean;
|
107
|
+
defaultKeymap?: boolean;
|
108
|
+
historyKeymap?: boolean;
|
109
|
+
}
|
110
|
+
|
111
|
+
export const minimalSetup = (options: MinimalSetupOptions = {}) => {
|
112
|
+
let keymaps: KeyBinding[] = [];
|
113
|
+
isValidSetup(options.defaultKeymap) && keymaps.push(...defaultKeymap);
|
114
|
+
isValidSetup(options.historyKeymap) && keymaps.push(...historyKeymap);
|
115
|
+
const extensions: Extension[] = [];
|
116
|
+
isValidSetup(options.highlightSpecialChars) &&
|
117
|
+
extensions.push(highlightSpecialChars());
|
118
|
+
isValidSetup(options.history) && extensions.push(history());
|
119
|
+
isValidSetup(options.drawSelection) && extensions.push(drawSelection());
|
120
|
+
isValidSetup(options.syntaxHighlighting) &&
|
121
|
+
extensions.push(
|
122
|
+
syntaxHighlighting(defaultHighlightStyle, { fallback: true })
|
123
|
+
);
|
124
|
+
return extensions.concat([keymap.of(keymaps.flat())]).filter(Boolean);
|
125
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export { NileCodeEditor } from './nile-code-editor';
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright Aquera Inc 2023
|
3
|
+
*
|
4
|
+
* This source code is licensed under the BSD-3-Clause license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
import { css } from 'lit-element';
|
9
|
+
|
10
|
+
/**
|
11
|
+
* CodeEditor CSS
|
12
|
+
*/
|
13
|
+
export const styles = css`
|
14
|
+
:host {
|
15
|
+
display: block;
|
16
|
+
}
|
17
|
+
|
18
|
+
.code-mirror {
|
19
|
+
display: flex;
|
20
|
+
justify-content: flex-end;
|
21
|
+
flex-direction: row-reverse;
|
22
|
+
gap: 0.6rem;
|
23
|
+
}
|
24
|
+
|
25
|
+
.cm-editor {
|
26
|
+
overflow: hidden;
|
27
|
+
width: 100%;
|
28
|
+
height: 100%;
|
29
|
+
}
|
30
|
+
|
31
|
+
.ͼ1.cm-focused {
|
32
|
+
outline: none;
|
33
|
+
}
|
34
|
+
|
35
|
+
.code-editor__icon__container {
|
36
|
+
cursor: pointer;
|
37
|
+
}
|
38
|
+
|
39
|
+
.code-editor__icon__container {
|
40
|
+
padding-right: 5px;
|
41
|
+
}
|
42
|
+
`;
|
43
|
+
|
44
|
+
export default [styles];
|
@@ -0,0 +1,127 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright Aquera Inc 2023
|
3
|
+
*
|
4
|
+
* This source code is licensed under the BSD-3-Clause license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
import {
|
9
|
+
LitElement,
|
10
|
+
html,
|
11
|
+
property,
|
12
|
+
CSSResultArray,
|
13
|
+
TemplateResult,
|
14
|
+
} from 'lit-element';
|
15
|
+
import { customElement, query } from 'lit/decorators.js';
|
16
|
+
import { styles } from './nile-code-editor.css';
|
17
|
+
import { EditorView } from 'codemirror';
|
18
|
+
import { ViewUpdate } from '@codemirror/view';
|
19
|
+
import { EditorState, Compartment } from '@codemirror/state';
|
20
|
+
import { javascript, javascriptLanguage } from '@codemirror/lang-javascript';
|
21
|
+
import { autocompletion } from '@codemirror/autocomplete';
|
22
|
+
import { CompletionContext } from '@codemirror/autocomplete';
|
23
|
+
import NileElement from '../internal/nile-element';
|
24
|
+
import { basicSetup } from './extensionSetup';
|
25
|
+
|
26
|
+
// Choose the appropriate mode for your use case
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Nile icon component.
|
30
|
+
*
|
31
|
+
* @tag nile-code-editor
|
32
|
+
*
|
33
|
+
*/
|
34
|
+
@customElement('nile-code-editor')
|
35
|
+
export class NileCodeEditor extends NileElement {
|
36
|
+
@query('.code-mirror') codeEditor: HTMLInputElement;
|
37
|
+
@property({ type: Boolean }) multiline: true;
|
38
|
+
@property({ type: String }) value: true;
|
39
|
+
@property({ type: String }) customOptions: any;
|
40
|
+
@property({ type: String }) showLineNumbers: any;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* The styles for CodeEditor
|
44
|
+
* @remarks If you are extending this class you can extend the base styles with super. Eg `return [super(), myCustomStyles]`
|
45
|
+
*/
|
46
|
+
public static get styles(): CSSResultArray {
|
47
|
+
return [styles];
|
48
|
+
}
|
49
|
+
|
50
|
+
connectedCallback(): void {
|
51
|
+
super.connectedCallback();
|
52
|
+
}
|
53
|
+
|
54
|
+
view: EditorView;
|
55
|
+
|
56
|
+
convertToSingleLine(code: any) {
|
57
|
+
// Remove line breaks and unnecessary whitespace
|
58
|
+
return code.replace(/\s+/g, ' ').trim();
|
59
|
+
}
|
60
|
+
lineNumbersComp = new Compartment();
|
61
|
+
|
62
|
+
updated() {
|
63
|
+
const customAutoCompletions = javascriptLanguage.data.of({
|
64
|
+
autocomplete: this.customOptions,
|
65
|
+
});
|
66
|
+
let startState = EditorState.create({
|
67
|
+
doc: !this.multiline ? this.convertToSingleLine(this.value) : this.value,
|
68
|
+
extensions: [
|
69
|
+
basicSetup({
|
70
|
+
lineNumbers: !!this.showLineNumbers,
|
71
|
+
foldGutter: !this.multiline ? false : true,
|
72
|
+
}),
|
73
|
+
customAutoCompletions,
|
74
|
+
autocompletion(),
|
75
|
+
javascript(),
|
76
|
+
!this.multiline ? this.restrictSingleLine() : [],
|
77
|
+
EditorView.updateListener.of((v: ViewUpdate) => {
|
78
|
+
if (v.docChanged) {
|
79
|
+
this.emitValues(this.view.state.doc.toString());
|
80
|
+
}
|
81
|
+
}),
|
82
|
+
],
|
83
|
+
});
|
84
|
+
|
85
|
+
this.view = new EditorView({
|
86
|
+
state: startState,
|
87
|
+
parent: this.codeEditor,
|
88
|
+
});
|
89
|
+
}
|
90
|
+
|
91
|
+
emitValues(value: string) {
|
92
|
+
this.emit('nile-change', { value: value });
|
93
|
+
}
|
94
|
+
|
95
|
+
expandCodeEditor() {
|
96
|
+
this.emit('nile-expand', { expand: true });
|
97
|
+
}
|
98
|
+
|
99
|
+
restrictSingleLine() {
|
100
|
+
return EditorState.transactionFilter.of(tr =>
|
101
|
+
tr.newDoc.lines > 1 ? [] : tr
|
102
|
+
);
|
103
|
+
}
|
104
|
+
public render(): TemplateResult {
|
105
|
+
return html`<div class="code-mirror">
|
106
|
+
${!this.multiline
|
107
|
+
? html`<nile-icon
|
108
|
+
name="fullscreenshrink"
|
109
|
+
class="code-editor__icon__container"
|
110
|
+
size="16"
|
111
|
+
color="black"
|
112
|
+
@click="${(e: CustomEvent) => this.expandCodeEditor()}"
|
113
|
+
></nile-icon>`
|
114
|
+
: ''}
|
115
|
+
</div>`;
|
116
|
+
}
|
117
|
+
|
118
|
+
/* #endregion */
|
119
|
+
}
|
120
|
+
|
121
|
+
export default NileCodeEditor;
|
122
|
+
|
123
|
+
declare global {
|
124
|
+
interface HTMLElementTagNameMap {
|
125
|
+
'nile-code-editor': NileCodeEditor;
|
126
|
+
}
|
127
|
+
}
|
@@ -63,6 +63,17 @@ export const styles = css`
|
|
63
63
|
padding-right: 10px;
|
64
64
|
}
|
65
65
|
|
66
|
+
nile-code-editor {
|
67
|
+
overflow: hidden;
|
68
|
+
padding-top: 2px;
|
69
|
+
border-radius: 5px;
|
70
|
+
border: 1px solid rgb(204, 204, 204);
|
71
|
+
}
|
72
|
+
|
73
|
+
.code-editor__no-border {
|
74
|
+
border: none;
|
75
|
+
}
|
76
|
+
|
66
77
|
.switcher-object-mapper::part(input) {
|
67
78
|
color: var(--nile-colors-primary-600);
|
68
79
|
cursor: pointer;
|
@@ -13,6 +13,7 @@ import { CSSResultGroup } from 'lit';
|
|
13
13
|
import { choose } from 'lit/directives/choose.js';
|
14
14
|
import { classMap } from 'lit/directives/class-map.js';
|
15
15
|
import { repeat } from 'lit/directives/repeat.js';
|
16
|
+
import { watch } from '../internal/watch';
|
16
17
|
|
17
18
|
/**
|
18
19
|
* @summary Allows you to switch between nile elements
|
@@ -32,7 +33,6 @@ export interface switchconfig {
|
|
32
33
|
toggleSwitch: boolean;
|
33
34
|
disable?: boolean;
|
34
35
|
confirmation?: boolean;
|
35
|
-
current: number;
|
36
36
|
align: 'block' | 'inline';
|
37
37
|
inputs: switchInputType[];
|
38
38
|
}
|
@@ -45,11 +45,11 @@ export interface switchInputType {
|
|
45
45
|
| INPUT_TYPE_NAMES.TEXTAREA
|
46
46
|
| INPUT_TYPE_NAMES.RADIO
|
47
47
|
| INPUT_TYPE_NAMES.CONTENTEDITOR
|
48
|
-
| INPUT_TYPE_NAMES.OBJECT_MAPPER
|
48
|
+
| INPUT_TYPE_NAMES.OBJECT_MAPPER
|
49
|
+
| INPUT_TYPE_NAMES.CODE_EDITOR;
|
49
50
|
value?: String | boolean;
|
50
51
|
label?: String;
|
51
52
|
readonly?: boolean;
|
52
|
-
order: number;
|
53
53
|
type?: string;
|
54
54
|
icon: string;
|
55
55
|
mode?: string;
|
@@ -62,6 +62,8 @@ export interface switchInputType {
|
|
62
62
|
helperText?: string;
|
63
63
|
multiple?: boolean;
|
64
64
|
noborder?: boolean;
|
65
|
+
multiLine?: boolean;
|
66
|
+
expand?: boolean;
|
65
67
|
}
|
66
68
|
|
67
69
|
export enum POSITIONS {
|
@@ -82,6 +84,7 @@ export enum INPUT_TYPE_NAMES {
|
|
82
84
|
RADIO = 'radio',
|
83
85
|
CONTENTEDITOR = 'content-editor',
|
84
86
|
OBJECT_MAPPER = 'object-mapper',
|
87
|
+
CODE_EDITOR = 'code-editor',
|
85
88
|
}
|
86
89
|
|
87
90
|
export enum MODE {
|
@@ -98,14 +101,31 @@ export class NileSwitcher extends NileElement {
|
|
98
101
|
static styles: CSSResultGroup = styles;
|
99
102
|
|
100
103
|
@property({ type: Object }) nileSwitchConfig: switchconfig;
|
101
|
-
|
104
|
+
|
105
|
+
@property({ type: Number }) current: Number = 0;
|
106
|
+
|
107
|
+
@property({ type: Object }) currentInput: switchInputType;
|
102
108
|
|
103
109
|
connectedCallback() {
|
104
|
-
this.currentInput = this.nileSwitchConfig.inputs[0];
|
105
110
|
super.connectedCallback();
|
111
|
+
this.setCurrentInput();
|
106
112
|
this.emit('nile-init');
|
107
113
|
}
|
108
114
|
|
115
|
+
@watch(['current'], { waitUntilFirstUpdate: true })
|
116
|
+
handleSwitcherChange() {
|
117
|
+
this.setCurrentInput();
|
118
|
+
}
|
119
|
+
|
120
|
+
setCurrentInput() {
|
121
|
+
if (this.nileSwitchConfig?.inputs) {
|
122
|
+
this.currentInput = this.nileSwitchConfig.inputs.filter(
|
123
|
+
(input: switchInputType, index: Number) => {
|
124
|
+
return index === this.current;
|
125
|
+
}
|
126
|
+
)[0];
|
127
|
+
}
|
128
|
+
}
|
109
129
|
disconnectedCallback() {
|
110
130
|
super.disconnectedCallback();
|
111
131
|
this.emit('nile-destroy');
|
@@ -276,6 +296,39 @@ export class NileSwitcher extends NileElement {
|
|
276
296
|
</nile-input>`;
|
277
297
|
}
|
278
298
|
|
299
|
+
renderCodeEditor(Input: switchInputType) {
|
300
|
+
const {
|
301
|
+
value,
|
302
|
+
multiLine,
|
303
|
+
options,
|
304
|
+
disabled,
|
305
|
+
readonly,
|
306
|
+
errorMessage,
|
307
|
+
error,
|
308
|
+
inputType,
|
309
|
+
noborder,
|
310
|
+
} = Input;
|
311
|
+
return html`<nile-code-editor
|
312
|
+
class=${classMap({
|
313
|
+
'code-editor': true,
|
314
|
+
'code-editor__no-border': !!noborder,
|
315
|
+
})}
|
316
|
+
@nile-expand="${(e: CustomEvent) =>
|
317
|
+
this.handleExpand(e, INPUT_TYPE_NAMES.CODE_EDITOR)}"
|
318
|
+
@nile-change="${(e: CustomEvent) =>
|
319
|
+
this.handleChange(e, INPUT_TYPE_NAMES.CODE_EDITOR)}"
|
320
|
+
.multiline="${multiLine}"
|
321
|
+
.value="${value}"
|
322
|
+
.customOptions="${options}"
|
323
|
+
.showLineNumbers="false"
|
324
|
+
></nile-code-editor> `;
|
325
|
+
}
|
326
|
+
|
327
|
+
handleExpand(event: CustomEvent, inputType: string) {
|
328
|
+
this.currentInput.expand = event.detail.expand;
|
329
|
+
this.emit('nile-change', { input: this.currentInput });
|
330
|
+
}
|
331
|
+
|
279
332
|
handleChange(event: CustomEvent, inputType: string) {
|
280
333
|
switch (inputType) {
|
281
334
|
case INPUT_TYPE_NAMES.OBJECT_MAPPER:
|
@@ -284,6 +337,9 @@ export class NileSwitcher extends NileElement {
|
|
284
337
|
case INPUT_TYPE_NAMES.CHECKBOX:
|
285
338
|
this.currentInput.value = event.detail.checked;
|
286
339
|
break;
|
340
|
+
case INPUT_TYPE_NAMES.CODE_EDITOR:
|
341
|
+
this.currentInput.value = event.detail.value;
|
342
|
+
break;
|
287
343
|
default:
|
288
344
|
this.currentInput.value = event.detail.value;
|
289
345
|
}
|
@@ -300,7 +356,7 @@ export class NileSwitcher extends NileElement {
|
|
300
356
|
<div class="switcher-icons-container">
|
301
357
|
${repeat(
|
302
358
|
inputs,
|
303
|
-
input => html` <nile-tooltip
|
359
|
+
(input: any, index: number) => html` <nile-tooltip
|
304
360
|
class=${classMap({
|
305
361
|
'switcher-tooltip-container': true,
|
306
362
|
})}
|
@@ -309,7 +365,7 @@ export class NileSwitcher extends NileElement {
|
|
309
365
|
>
|
310
366
|
<div class=${classMap({
|
311
367
|
'switcher-icon-container': true,
|
312
|
-
current:
|
368
|
+
current: index === this.current,
|
313
369
|
})}>
|
314
370
|
<nile-icon
|
315
371
|
size="16"
|
@@ -318,7 +374,7 @@ export class NileSwitcher extends NileElement {
|
|
318
374
|
})}
|
319
375
|
.name=${input.icon}
|
320
376
|
color="#000000"
|
321
|
-
@click=${() => this.toggleField(input)}
|
377
|
+
@click=${() => this.toggleField(input, index)}
|
322
378
|
></nile-icon>
|
323
379
|
<div>
|
324
380
|
|
@@ -328,8 +384,8 @@ export class NileSwitcher extends NileElement {
|
|
328
384
|
`;
|
329
385
|
}
|
330
386
|
|
331
|
-
toggleField(currentInput: switchInputType) {
|
332
|
-
this.
|
387
|
+
toggleField(currentInput: switchInputType, index: Number) {
|
388
|
+
this.current = index;
|
333
389
|
this.emit('nile-switch', { input: this.currentInput });
|
334
390
|
}
|
335
391
|
|
@@ -360,6 +416,10 @@ export class NileSwitcher extends NileElement {
|
|
360
416
|
() => this.renderContentEditor(this.currentInput),
|
361
417
|
],
|
362
418
|
[INPUT_TYPE_NAMES.OBJECT_MAPPER, () => this.renderObjectMapper()],
|
419
|
+
[
|
420
|
+
INPUT_TYPE_NAMES.CODE_EDITOR,
|
421
|
+
() => this.renderCodeEditor(this.currentInput),
|
422
|
+
],
|
363
423
|
],
|
364
424
|
() => this.renderNileText(this.currentInput)
|
365
425
|
)}
|