@aquera/nile-elements 0.0.87 → 0.0.89
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 +6 -0
- package/demo/index.html +1 -1
- package/dist/index.iife.js +5 -2
- package/dist/nile-code-editor/index.cjs.js +1 -1
- package/dist/nile-code-editor/index.esm.js +1 -1
- package/dist/nile-code-editor/nile-code-editor.cjs.js +2 -2
- package/dist/nile-code-editor/nile-code-editor.cjs.js.map +1 -1
- package/dist/nile-code-editor/nile-code-editor.css.cjs.js +1 -1
- package/dist/nile-code-editor/nile-code-editor.css.cjs.js.map +1 -1
- package/dist/nile-code-editor/nile-code-editor.css.esm.js +5 -2
- package/dist/nile-code-editor/nile-code-editor.esm.js +3 -3
- package/dist/nile-code-editor/theme.cjs.js +1 -1
- package/dist/nile-code-editor/theme.cjs.js.map +1 -1
- package/dist/nile-code-editor/theme.esm.js +1 -1
- package/dist/src/nile-code-editor/nile-code-editor.css.js +3 -0
- package/dist/src/nile-code-editor/nile-code-editor.css.js.map +1 -1
- package/dist/src/nile-code-editor/nile-code-editor.d.ts +1 -6
- package/dist/src/nile-code-editor/nile-code-editor.js +13 -31
- package/dist/src/nile-code-editor/nile-code-editor.js.map +1 -1
- package/dist/src/nile-code-editor/theme.d.ts +3 -1
- package/dist/src/nile-code-editor/theme.js +3 -1
- package/dist/src/nile-code-editor/theme.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/nile-code-editor/nile-code-editor.css.ts +3 -0
- package/src/nile-code-editor/nile-code-editor.ts +24 -49
- package/src/nile-code-editor/theme.ts +4 -2
@@ -1,2 +1,2 @@
|
|
1
|
-
System.register([],function(_export,_context){"use strict";var
|
1
|
+
System.register([],function(_export,_context){"use strict";var t;return{setters:[],execute:function execute(){_export("T",t={"&":{fontSize:"14px",fontFamily:"Colfax-regular",fontWeight:"400"},".cm-content":{},".cm-scroller":{scrollbarWidth:"thin"}});}};});
|
2
2
|
//# sourceMappingURL=theme.cjs.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"theme.cjs.js","sources":["../../../src/nile-code-editor/theme.ts"],"sourcesContent":["export const Theme = {\n '&': {\n fontSize: '14px',\n fontFamily: 'Colfax-regular',\n fontWeight: '400',\n },\n '.cm-content': {},\n
|
1
|
+
{"version":3,"file":"theme.cjs.js","sources":["../../../src/nile-code-editor/theme.ts"],"sourcesContent":["export const Theme = {\n '&': {\n fontSize: '14px',\n fontFamily: 'Colfax-regular',\n fontWeight: '400',\n },\n '.cm-content': {},\n \".cm-scroller\": {\n scrollbarWidth:'thin',\n },\n};"],"names":["Theme","fontSize","fontFamily","fontWeight","scrollbarWidth"],"mappings":"0HAAaA,EAAQ,CACnB,GAAA,CAAK,CACHC,QAAAA,CAAU,OACVC,UAAY,CAAA,gBAAA,CACZC,UAAY,CAAA,KAAA,CAAA,CAEd,cAAe,CAAE,CAAA,CACjB,cAAgB,CAAA,CACdC,eAAe"}
|
@@ -1 +1 @@
|
|
1
|
-
const
|
1
|
+
const t={"&":{fontSize:"14px",fontFamily:"Colfax-regular",fontWeight:"400"},".cm-content":{},".cm-scroller":{scrollbarWidth:"thin"}};export{t as T};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"nile-code-editor.css.js","sourceRoot":"","sources":["../../../src/nile-code-editor/nile-code-editor.css.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA
|
1
|
+
{"version":3,"file":"nile-code-editor.css.js","sourceRoot":"","sources":["../../../src/nile-code-editor/nile-code-editor.css.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0CxB,CAAC;AAEF,eAAe,CAAC,MAAM,CAAC,CAAC","sourcesContent":["/**\n * Copyright Aquera Inc 2023\n *\n * This source code is licensed under the BSD-3-Clause license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { css } from 'lit-element';\n\n/**\n * CodeEditor CSS\n */\nexport const styles = css`\n :host {\n display: block;\n }\n\n .code-mirror {\n display: flex;\n justify-content: flex-end;\n flex-direction: row-reverse;\n padding: 5px;\n border-radius: 5px;\n border: 1px solid rgb(204, 204, 204);\n }\n .code-mirror__singleline .cm-scroller{\n scrollbar-width:none;\n }\n\n .error {\n border-color: #e5434d;\n }\n\n .noborder {\n border: none;\n }\n .cm-editor {\n flex: 1;\n min-width: 0;\n }\n\n .ͼ1.cm-focused {\n outline: none;\n }\n\n .code-editor__icon__container {\n display: none;\n }\n .code-mirror:hover > .code-editor__icon__container {\n cursor: pointer;\n display: flex;\n align-self: start;\n padding: 5px 5px 0px 0px;\n }\n`;\n\nexport default [styles];\n"]}
|
@@ -25,7 +25,7 @@ export declare class NileCodeEditor extends NileElement {
|
|
25
25
|
error: boolean;
|
26
26
|
noborder: boolean;
|
27
27
|
expandable: any;
|
28
|
-
readonly:
|
28
|
+
readonly: boolean;
|
29
29
|
/**
|
30
30
|
* The styles for CodeEditor
|
31
31
|
* @remarks If you are extending this class you can extend the base styles with super. Eg `return [super(), myCustomStyles]`
|
@@ -38,17 +38,12 @@ export declare class NileCodeEditor extends NileElement {
|
|
38
38
|
lineNumbersComp: Compartment;
|
39
39
|
restrictSingleLineComp: Compartment;
|
40
40
|
readOnlyComp: Compartment;
|
41
|
-
handleValueChange(): void;
|
42
41
|
getLineNumbersExension(): import("@codemirror/state").Extension;
|
43
42
|
getReadOnlyExtension(): import("@codemirror/state").Extension;
|
44
43
|
getSingleLineExtension(): import("@codemirror/state").Extension;
|
45
44
|
firstUpdated(): void;
|
46
|
-
addOpenListeners(): void;
|
47
45
|
singleLineMultiLineToggle(): void;
|
48
46
|
updated(changedProperties: PropertyValues): void;
|
49
|
-
toggleFocusAndBlur(action: 'blur' | 'focus'): void;
|
50
|
-
setTheme(): import("@codemirror/state").Extension;
|
51
|
-
emitValues(value: string): void;
|
52
47
|
expandCodeEditor(): void;
|
53
48
|
restrictSingleLine(): import("@codemirror/state").Extension;
|
54
49
|
render(): TemplateResult;
|
@@ -15,7 +15,6 @@ import { javascript, javascriptLanguage, scopeCompletionSource, } from '@codemir
|
|
15
15
|
import { autocompletion } from '@codemirror/autocomplete';
|
16
16
|
import NileElement from '../internal/nile-element';
|
17
17
|
import { basicSetup } from './extensionSetup';
|
18
|
-
import { watch } from '../internal/watch';
|
19
18
|
import { classMap } from 'lit/directives/class-map.js';
|
20
19
|
import { Theme } from './theme';
|
21
20
|
// Choose the appropriate mode for your use case
|
@@ -55,13 +54,15 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
|
|
55
54
|
}
|
56
55
|
disconnectedCallback() {
|
57
56
|
super.disconnectedCallback();
|
57
|
+
this.view.destroy();
|
58
58
|
this.emit('nile-destroy');
|
59
59
|
}
|
60
60
|
convertToSingleLine(code) {
|
61
|
+
if (!code)
|
62
|
+
return '';
|
61
63
|
// Remove line breaks and unnecessary whitespace
|
62
64
|
return code.replace(/\s+/g, ' ').trim();
|
63
65
|
}
|
64
|
-
handleValueChange() { }
|
65
66
|
getLineNumbersExension() {
|
66
67
|
return this.multiline ? lineNumbers() : [];
|
67
68
|
}
|
@@ -84,9 +85,8 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
|
|
84
85
|
: this.value,
|
85
86
|
extensions: [
|
86
87
|
basicSetup({
|
87
|
-
lineNumbers: false,
|
88
88
|
highlightActiveLine: false,
|
89
|
-
foldGutter:
|
89
|
+
foldGutter: !!this.multiline,
|
90
90
|
}),
|
91
91
|
lineNumbersExtension,
|
92
92
|
readOnlyExtension,
|
@@ -94,23 +94,22 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
|
|
94
94
|
customAutoCompletions,
|
95
95
|
autocompletion(),
|
96
96
|
javascript(),
|
97
|
-
|
97
|
+
EditorView.theme(Theme),
|
98
98
|
EditorView.updateListener.of((v) => {
|
99
99
|
if (v.docChanged) {
|
100
|
-
this.
|
100
|
+
this.emit('nile-change', { value: this.view.state.doc.toString() });
|
101
101
|
}
|
102
102
|
}),
|
103
|
+
EditorView.domEventHandlers({
|
104
|
+
focus: () => this.dispatchEvent(new Event('nile-focus')),
|
105
|
+
blur: () => this.dispatchEvent(new Event('nile-blur')),
|
106
|
+
}),
|
103
107
|
],
|
104
108
|
});
|
105
109
|
this.view = new EditorView({
|
106
110
|
state: startState,
|
107
111
|
parent: this.codeEditor,
|
108
112
|
});
|
109
|
-
this.addOpenListeners();
|
110
|
-
}
|
111
|
-
addOpenListeners() {
|
112
|
-
this.view.contentDOM.addEventListener('blur', () => this.toggleFocusAndBlur('blur'));
|
113
|
-
this.view.contentDOM.addEventListener('focus', () => this.toggleFocusAndBlur('focus'));
|
114
113
|
}
|
115
114
|
singleLineMultiLineToggle() {
|
116
115
|
this.view.dispatch({
|
@@ -140,20 +139,6 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
|
|
140
139
|
this.view.dispatch({ effects: this.readOnlyComp.reconfigure(this.getReadOnlyExtension()) });
|
141
140
|
}
|
142
141
|
}
|
143
|
-
toggleFocusAndBlur(action) {
|
144
|
-
if (action === 'blur') {
|
145
|
-
this.emit('nile-blur', { onBlur: true });
|
146
|
-
}
|
147
|
-
if (action === 'focus') {
|
148
|
-
this.emit('nile-focus', { onFocus: true });
|
149
|
-
}
|
150
|
-
}
|
151
|
-
setTheme() {
|
152
|
-
return EditorView.theme(Theme);
|
153
|
-
}
|
154
|
-
emitValues(value) {
|
155
|
-
this.emit('nile-change', { value: value });
|
156
|
-
}
|
157
142
|
expandCodeEditor() {
|
158
143
|
this.emit('nile-expand', { expand: true });
|
159
144
|
}
|
@@ -211,20 +196,17 @@ __decorate([
|
|
211
196
|
property({ attribute: 'error-message' })
|
212
197
|
], NileCodeEditor.prototype, "errorMessage", void 0);
|
213
198
|
__decorate([
|
214
|
-
property({ attribute: 'error' })
|
199
|
+
property({ attribute: 'error', type: Boolean })
|
215
200
|
], NileCodeEditor.prototype, "error", void 0);
|
216
201
|
__decorate([
|
217
|
-
property({ attribute: 'noborder' })
|
202
|
+
property({ attribute: 'noborder', type: Boolean })
|
218
203
|
], NileCodeEditor.prototype, "noborder", void 0);
|
219
204
|
__decorate([
|
220
205
|
property({ type: Boolean })
|
221
206
|
], NileCodeEditor.prototype, "expandable", void 0);
|
222
207
|
__decorate([
|
223
|
-
property({ type: Boolean })
|
208
|
+
property({ type: Boolean, reflect: true })
|
224
209
|
], NileCodeEditor.prototype, "readonly", void 0);
|
225
|
-
__decorate([
|
226
|
-
watch(['value'], { waitUntilFirstUpdate: true })
|
227
|
-
], NileCodeEditor.prototype, "handleValueChange", null);
|
228
210
|
NileCodeEditor = __decorate([
|
229
211
|
customElement('nile-code-editor')
|
230
212
|
], NileCodeEditor);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"nile-code-editor.js","sourceRoot":"","sources":["../../../src/nile-code-editor/nile-code-editor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAEH,OAAO,EAEL,IAAI,EACJ,QAAQ,GAIT,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,qBAAqB,GAEtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MA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E,CAAC;iDAAmB;AAClC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;6CAAY;AACX;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;6DAAiC;AAC/B;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;mDAA0B;AACZ;IAAzC,QAAQ,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC;oDAAmB;AAC1B;IAAjC,QAAQ,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;6CAAe;AACX;IAApC,QAAQ,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;gDAAkB;AAEzB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;kDAAyB;AACxB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;gDAAuB;AAgCnD;IADC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;uDAC1B;AA3CZ,cAAc;IAD1B,aAAa,CAAC,kBAAkB,CAAC;GACrB,cAAc,CAmM1B;SAnMY,cAAc;AAqM3B,eAAe,cAAc,CAAC","sourcesContent":["/**\n * Copyright Aquera Inc 2023\n *\n * This source code is licensed under the BSD-3-Clause license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport {\n LitElement,\n html,\n property,\n CSSResultArray,\n TemplateResult,\n PropertyValueMap,\n} from 'lit-element';\nimport { customElement, query } from 'lit/decorators.js';\nimport { styles } from './nile-code-editor.css';\nimport { EditorView } from 'codemirror';\nimport { ViewUpdate } from '@codemirror/view';\nimport { EditorState, Compartment } from '@codemirror/state';\nimport {lineNumbers} from '@codemirror/view';\nimport {\n javascript,\n javascriptLanguage,\n scopeCompletionSource,\n completionPath,\n} from '@codemirror/lang-javascript';\nimport { autocompletion } from '@codemirror/autocomplete';\nimport { CompletionContext, Completion } from '@codemirror/autocomplete';\nimport NileElement from '../internal/nile-element';\nimport { basicSetup } from './extensionSetup';\nimport { watch } from '../internal/watch';\nimport { PropertyValues } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { Theme } from './theme';\n\n// Choose the appropriate mode for your use case\n\n/**\n * Nile icon component.\n *\n * @tag nile-code-editor\n *\n */\n@customElement('nile-code-editor')\nexport class NileCodeEditor extends NileElement {\n @query('.code-mirror') codeEditor: HTMLInputElement;\n @property({ type: Boolean, reflect: true }) multiline = false;\n @property({ type: String }) value = '';\n @property({ type: String }) customAutoCompletions: any = {};\n @property({ type: Boolean }) updateValue: any = false;\n @property({ attribute: 'error-message' }) errorMessage = '';\n @property({ attribute: 'error' }) error = false;\n @property({ attribute: 'noborder' }) noborder = false;\n\n @property({ type: Boolean }) expandable: any = false;\n @property({ type: Boolean }) readonly: any = false;\n\n /**\n * The styles for CodeEditor\n * @remarks If you are extending this class you can extend the base styles with super. Eg `return [super(), myCustomStyles]`\n */\n public static get styles(): CSSResultArray {\n return [styles];\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n this.emit('nile-init');\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.emit('nile-destroy');\n }\n\n view: EditorView;\n\n convertToSingleLine(code: any) {\n // Remove line breaks and unnecessary whitespace\n return code.replace(/\\s+/g, ' ').trim();\n }\n lineNumbersComp = new Compartment();\n restrictSingleLineComp = new Compartment();\n readOnlyComp = new Compartment();\n\n\n @watch(['value'], { waitUntilFirstUpdate: true })\n handleValueChange() { }\n\n getLineNumbersExension() {\n return this.multiline ? lineNumbers() : [];\n }\n\n getReadOnlyExtension() {\n return EditorState.readOnly.of(this.readonly);\n }\n\n getSingleLineExtension(){\n return !this.multiline ? EditorState.transactionFilter.of(tr =>\n tr.newDoc.lines > 1 ? [] : tr\n ) : [];\n }\n\n firstUpdated() {\n const lineNumbersExtension = this.lineNumbersComp.of(this.getLineNumbersExension());\n const readOnlyExtension = this.readOnlyComp.of(this.getReadOnlyExtension());\n const restrictSingleLineExtension = this.restrictSingleLineComp.of(this.getSingleLineExtension())\n const customAutoCompletions = javascriptLanguage.data.of({\n autocomplete: scopeCompletionSource(this.customAutoCompletions),\n });\n let startState = EditorState.create({\n doc: !this.multiline\n ? this.convertToSingleLine(this.value)\n : this.value,\n extensions: [\n basicSetup({\n lineNumbers: false,\n highlightActiveLine: false,\n foldGutter: false,\n }),\n lineNumbersExtension,\n readOnlyExtension,\n restrictSingleLineExtension,\n customAutoCompletions,\n autocompletion(),\n javascript(),\n this.setTheme(),\n EditorView.updateListener.of((v: ViewUpdate) => {\n if (v.docChanged) {\n this.emitValues(this.view.state.doc.toString());\n }\n }),\n \n ],\n });\n\n this.view = new EditorView({\n state: startState,\n parent: this.codeEditor,\n });\n this.addOpenListeners();\n }\n \n\n addOpenListeners() {\n this.view.contentDOM.addEventListener('blur', () => this.toggleFocusAndBlur('blur'));\n this.view.contentDOM.addEventListener('focus', () => this.toggleFocusAndBlur('focus'));\n }\n \n\n singleLineMultiLineToggle() {\n this.view.dispatch({\n changes: {\n from: 0,\n to: this.view.state.doc.length,\n insert: !this.multiline\n ? this.convertToSingleLine(this.value)\n : this.value,\n },\n });\n }\n \n updated(changedProperties: PropertyValues) {\n super.updated(changedProperties);\n if (changedProperties.has('value') && this.updateValue) {\n // Editor has already been initialized, update its state\n this.singleLineMultiLineToggle();\n }\n if (changedProperties.has('multiline')) {\n this.view.dispatch({\n effects: [this.lineNumbersComp.reconfigure(this.getLineNumbersExension()),\n this.restrictSingleLineComp.reconfigure(this.getSingleLineExtension())],\n })\n this.singleLineMultiLineToggle();\n }\n if (changedProperties.has('readonly')) {\n this.view.dispatch({ effects: this.readOnlyComp.reconfigure(this.getReadOnlyExtension()) }) \n }\n }\n\n toggleFocusAndBlur(action: 'blur' | 'focus') {\n if(action === 'blur'){\n this.emit('nile-blur', { onBlur : true });\n }\n if (action === 'focus') {\n this.emit('nile-focus', { onFocus : true });\n }\n }\n\n setTheme() {\n return EditorView.theme(Theme);\n }\n\n emitValues(value: string) {\n this.emit('nile-change', { value: value });\n }\n\n expandCodeEditor() {\n this.emit('nile-expand', { expand: true });\n }\n\n restrictSingleLine() {\n return EditorState.transactionFilter.of(tr =>\n tr.newDoc.lines > 1 ? [] : tr\n );\n }\n public render(): TemplateResult {\n const hasErrorMessage = !!this.errorMessage;\n const hasError = !!this.error;\n const noborder = !!this.noborder;\n return html`<div\n part=\"code-editor-base\"\n class=${classMap({\n 'code-mirror': true,\n noborder: noborder,\n error: hasError || hasErrorMessage,\n 'code-mirror__singleline': !this.multiline,\n })}\n >\n ${this.expandable\n ? html` <nile-icon\n name=\"expand-2\"\n class=\"code-editor__icon__container\"\n size=\"16\"\n color=\"black\"\n @click=\"${(e: CustomEvent) => this.expandCodeEditor()}\"\n ></nile-icon>`\n : ''}\n </div>\n ${hasErrorMessage\n ? html`\n <nile-form-error-message\n >${this.errorMessage}</nile-form-error-message\n >\n `\n : ``}`;\n }\n\n /* #endregion */\n}\n\nexport default NileCodeEditor;\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-code-editor': NileCodeEditor;\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"nile-code-editor.js","sourceRoot":"","sources":["../../../src/nile-code-editor/nile-code-editor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAEH,OAAO,EAEL,IAAI,EACJ,QAAQ,GAIT,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,qBAAqB,GAEtB,MAAM,6BAA6B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EvC;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;kDAAyB;AACV;IAA1C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAC,IAAI,EAAE,CAAC;gDAA2B;AAX1D,cAAc;IAD1B,aAAa,CAAC,kBAAkB,CAAC;GACrB,cAAc,CA0K1B;SA1KY,cAAc;AA4K3B,eAAe,cAAc,CAAC","sourcesContent":["/**\n * Copyright Aquera Inc 2023\n *\n * This source code is licensed under the BSD-3-Clause license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport {\n LitElement,\n html,\n property,\n CSSResultArray,\n TemplateResult,\n PropertyValueMap,\n} from 'lit-element';\nimport { customElement, query } from 'lit/decorators.js';\nimport { styles } from './nile-code-editor.css';\nimport { EditorView } from 'codemirror';\nimport { ViewUpdate } from '@codemirror/view';\nimport { EditorState, Compartment } from '@codemirror/state';\nimport {lineNumbers} from '@codemirror/view';\nimport {\n javascript,\n javascriptLanguage,\n scopeCompletionSource,\n completionPath,\n} from '@codemirror/lang-javascript';\nimport { autocompletion } from '@codemirror/autocomplete';\nimport { CompletionContext, Completion } from '@codemirror/autocomplete';\nimport NileElement from '../internal/nile-element';\nimport { basicSetup } from './extensionSetup';\nimport { watch } from '../internal/watch';\nimport { PropertyValues } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { Theme } from './theme';\n\n// Choose the appropriate mode for your use case\n\n/**\n * Nile icon component.\n *\n * @tag nile-code-editor\n *\n */\n@customElement('nile-code-editor')\nexport class NileCodeEditor extends NileElement {\n @query('.code-mirror') codeEditor: HTMLInputElement;\n @property({ type: Boolean, reflect: true }) multiline = false;\n @property({ type: String }) value = '';\n @property({ type: String }) customAutoCompletions: any = {};\n @property({ type: Boolean }) updateValue: any = false;\n @property({ attribute: 'error-message' }) errorMessage = '';\n @property({ attribute: 'error', type: Boolean }) error = false;\n @property({ attribute: 'noborder', type:Boolean }) noborder = false;\n\n @property({ type: Boolean }) expandable: any = false;\n @property({ type: Boolean, reflect:true }) readonly: boolean = false;\n\n /**\n * The styles for CodeEditor\n * @remarks If you are extending this class you can extend the base styles with super. Eg `return [super(), myCustomStyles]`\n */\n public static get styles(): CSSResultArray {\n return [styles];\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n this.emit('nile-init');\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.view.destroy()\n this.emit('nile-destroy');\n }\n\n public view: EditorView;\n\n convertToSingleLine(code: any) {\n if(!code) return '';\n // Remove line breaks and unnecessary whitespace\n return code.replace(/\\s+/g, ' ').trim();\n }\n lineNumbersComp = new Compartment();\n restrictSingleLineComp = new Compartment();\n readOnlyComp = new Compartment();\n\n getLineNumbersExension() {\n return this.multiline ? lineNumbers() : [];\n }\n\n getReadOnlyExtension() {\n return EditorState.readOnly.of(this.readonly);\n }\n\n getSingleLineExtension(){\n return !this.multiline ? EditorState.transactionFilter.of(tr =>\n tr.newDoc.lines > 1 ? [] : tr\n ) : [];\n }\n\n firstUpdated() {\n const lineNumbersExtension = this.lineNumbersComp.of(this.getLineNumbersExension());\n const readOnlyExtension = this.readOnlyComp.of(this.getReadOnlyExtension());\n const restrictSingleLineExtension = this.restrictSingleLineComp.of(this.getSingleLineExtension())\n const customAutoCompletions = javascriptLanguage.data.of({\n autocomplete: scopeCompletionSource(this.customAutoCompletions),\n });\n let startState = EditorState.create({\n doc: !this.multiline\n ? this.convertToSingleLine(this.value)\n : this.value,\n extensions: [\n basicSetup({\n highlightActiveLine: false,\n foldGutter: !!this.multiline,\n }),\n lineNumbersExtension,\n readOnlyExtension,\n restrictSingleLineExtension,\n customAutoCompletions,\n autocompletion(),\n javascript(),\n EditorView.theme(Theme),\n EditorView.updateListener.of((v: ViewUpdate) => {\n if (v.docChanged) {\n this.emit('nile-change', { value: this.view.state.doc.toString() })\n }\n }),\n EditorView.domEventHandlers({\n focus: () => this.dispatchEvent(new Event('nile-focus')),\n blur: () => this.dispatchEvent(new Event('nile-blur')),\n }),\n ],\n });\n\n this.view = new EditorView({\n state: startState,\n parent: this.codeEditor,\n });\n }\n\n singleLineMultiLineToggle() {\n this.view.dispatch({\n changes: {\n from: 0,\n to: this.view.state.doc.length,\n insert: !this.multiline\n ? this.convertToSingleLine(this.value)\n : this.value,\n },\n });\n }\n \n updated(changedProperties: PropertyValues) {\n super.updated(changedProperties);\n if (changedProperties.has('value') && this.updateValue) {\n // Editor has already been initialized, update its state\n this.singleLineMultiLineToggle();\n }\n if (changedProperties.has('multiline')) {\n this.view.dispatch({\n effects: [this.lineNumbersComp.reconfigure(this.getLineNumbersExension()),\n this.restrictSingleLineComp.reconfigure(this.getSingleLineExtension())],\n })\n this.singleLineMultiLineToggle();\n }\n if (changedProperties.has('readonly')) {\n this.view.dispatch({ effects: this.readOnlyComp.reconfigure(this.getReadOnlyExtension()) }) \n }\n }\n\n expandCodeEditor() {\n this.emit('nile-expand', { expand: true });\n }\n\n restrictSingleLine() {\n return EditorState.transactionFilter.of(tr =>\n tr.newDoc.lines > 1 ? [] : tr\n );\n }\n public render(): TemplateResult {\n const hasErrorMessage = !!this.errorMessage;\n const hasError = !!this.error;\n const noborder = !!this.noborder;\n return html`<div\n part=\"code-editor-base\"\n class=${classMap({\n 'code-mirror': true,\n noborder: noborder,\n error: hasError || hasErrorMessage,\n 'code-mirror__singleline': !this.multiline,\n })}\n >\n ${this.expandable\n ? html` <nile-icon\n name=\"expand-2\"\n class=\"code-editor__icon__container\"\n size=\"16\"\n color=\"black\"\n @click=\"${(e: CustomEvent) => this.expandCodeEditor()}\"\n ></nile-icon>`\n : ''}\n </div>\n ${hasErrorMessage\n ? html`\n <nile-form-error-message\n >${this.errorMessage}</nile-form-error-message\n >\n `\n : ``}`;\n }\n\n /* #endregion */\n}\n\nexport default NileCodeEditor;\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-code-editor': NileCodeEditor;\n }\n}\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"theme.js","sourceRoot":"","sources":["../../../src/nile-code-editor/theme.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,GAAG,EAAE;QACH,QAAQ,EAAE,MAAM;QAChB,UAAU,EAAE,gBAAgB;QAC5B,UAAU,EAAE,KAAK;KAClB;IACD,aAAa,EAAE,EAAE;IACjB,cAAc,EAAE,
|
1
|
+
{"version":3,"file":"theme.js","sourceRoot":"","sources":["../../../src/nile-code-editor/theme.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,GAAG,EAAE;QACH,QAAQ,EAAE,MAAM;QAChB,UAAU,EAAE,gBAAgB;QAC5B,UAAU,EAAE,KAAK;KAClB;IACD,aAAa,EAAE,EAAE;IACjB,cAAc,EAAE;QACd,cAAc,EAAC,MAAM;KACtB;CACF,CAAC","sourcesContent":["export const Theme = {\n '&': {\n fontSize: '14px',\n fontFamily: 'Colfax-regular',\n fontWeight: '400',\n },\n '.cm-content': {},\n \".cm-scroller\": {\n scrollbarWidth:'thin',\n },\n};"]}
|