@aquera/nile-elements 0.1.0 → 0.1.1
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 +4 -0
- package/dist/nile-code-editor/extensionSetup.cjs.js +5 -5
- package/dist/nile-code-editor/extensionSetup.cjs.js.map +1 -1
- package/dist/nile-code-editor/extensionSetup.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.esm.js +11 -11
- package/dist/nile-error-notification/nile-error-notification.cjs.js +1 -1
- package/dist/nile-error-notification/nile-error-notification.cjs.js.map +1 -1
- package/dist/nile-error-notification/nile-error-notification.esm.js +1 -1
- package/dist/src/nile-code-editor/nile-code-editor.d.ts +4 -2
- package/dist/src/nile-code-editor/nile-code-editor.js +39 -20
- package/dist/src/nile-code-editor/nile-code-editor.js.map +1 -1
- package/dist/src/nile-error-notification/nile-error-notification.d.ts +2 -2
- package/dist/src/nile-error-notification/nile-error-notification.js +2 -3
- package/dist/src/nile-error-notification/nile-error-notification.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/nile-code-editor/nile-code-editor.ts +50 -34
- package/src/nile-error-notification/nile-error-notification.ts +3 -3
- package/vscode-html-custom-data.json +7 -3
package/package.json
CHANGED
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
import { customElement, query, property } from 'lit/decorators.js';
|
17
17
|
import { styles } from './nile-code-editor.css';
|
18
18
|
import { EditorView } from 'codemirror';
|
19
|
-
import { ViewUpdate } from '@codemirror/view';
|
19
|
+
import { ViewUpdate, placeholder } from '@codemirror/view';
|
20
20
|
import {
|
21
21
|
Compartment,
|
22
22
|
EditorState,
|
@@ -54,6 +54,8 @@ export class NileCodeEditor extends NileElement {
|
|
54
54
|
|
55
55
|
@property({ type: String, reflect: true , attribute: true }) expandIcon = "expand-2";
|
56
56
|
|
57
|
+
@property({ type: String, reflect: true , attribute: true }) placeholder = "";
|
58
|
+
|
57
59
|
@property({ type: Object, reflect: true , attribute: true }) customAutoCompletions: object | any = {};
|
58
60
|
|
59
61
|
@property({ type: String, reflect: true , attribute: true}) language: 'javascript' | 'sql' | 'json' = 'javascript';
|
@@ -65,8 +67,8 @@ export class NileCodeEditor extends NileElement {
|
|
65
67
|
@property({ type: Boolean, reflect: true , attribute: 'noborder' }) noborder: boolean = false;
|
66
68
|
|
67
69
|
@property({ type: Boolean, reflect: true , attribute: true }) multiline: boolean = false;
|
68
|
-
|
69
|
-
@property({ type: Boolean, reflect: true , attribute: true })
|
70
|
+
|
71
|
+
@property({ type: Boolean, reflect: true , attribute: true }) allowVariableInCustomSuggestion: boolean = false;
|
70
72
|
|
71
73
|
@property({ type: Boolean, reflect: true , attribute: true }) lineNumbers: boolean = false;
|
72
74
|
|
@@ -89,6 +91,7 @@ export class NileCodeEditor extends NileElement {
|
|
89
91
|
private restrictSingleLineComp = new Compartment();
|
90
92
|
private readOnlyComp = new Compartment();
|
91
93
|
private customCompletionComp = new Compartment();
|
94
|
+
private placeholderComp = new Compartment();
|
92
95
|
|
93
96
|
/**
|
94
97
|
* The styles for CodeEditor
|
@@ -140,6 +143,13 @@ export class NileCodeEditor extends NileElement {
|
|
140
143
|
]
|
141
144
|
})
|
142
145
|
}
|
146
|
+
if (changedProperties.has('placeholder')) {
|
147
|
+
this.view.dispatch({
|
148
|
+
effects: [
|
149
|
+
this.placeholderComp.reconfigure(this.getPlaceholderExtension()),
|
150
|
+
]
|
151
|
+
})
|
152
|
+
}
|
143
153
|
if (changedProperties.has('lineNumbers') || changedProperties.has('lineNumbersMultiline')) {
|
144
154
|
this.view.dispatch({
|
145
155
|
effects: [
|
@@ -151,7 +161,7 @@ export class NileCodeEditor extends NileElement {
|
|
151
161
|
this.view.dispatch({
|
152
162
|
effects: [
|
153
163
|
this.customCompletionComp.reconfigure(javascriptLanguage.data.of({
|
154
|
-
autocomplete: this.
|
164
|
+
autocomplete: this.customAutocomplete
|
155
165
|
}))
|
156
166
|
]
|
157
167
|
})
|
@@ -173,16 +183,16 @@ export class NileCodeEditor extends NileElement {
|
|
173
183
|
'no-scroller': noScrollbar
|
174
184
|
})}
|
175
185
|
>
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
+
${this.expandable
|
187
|
+
? html`
|
188
|
+
<nile-icon
|
189
|
+
name="${this.expandIcon}"
|
190
|
+
class="code-editor__icon__container"
|
191
|
+
size="16"
|
192
|
+
color="black"
|
193
|
+
@click="${(e: CustomEvent) => this.emit('nile-expand')}"
|
194
|
+
></nile-icon>`
|
195
|
+
: ''}
|
186
196
|
</div>
|
187
197
|
${hasErrorMessage
|
188
198
|
? html`
|
@@ -208,10 +218,12 @@ export class NileCodeEditor extends NileElement {
|
|
208
218
|
const lineNumbersExtension = this.lineNumbersComp.of(this.getLineNumbersExension());
|
209
219
|
const readOnlyExtension = this.readOnlyComp.of(this.getReadOnlyExtension());
|
210
220
|
const restrictSingleLineExtension = this.restrictSingleLineComp.of(this.getSingleLineExtension())
|
221
|
+
const placeholderExtension = this.placeholderComp.of(this.getPlaceholderExtension())
|
222
|
+
const language = this.getLanguageExtension()
|
211
223
|
const customAutoCompletions = this.customCompletionComp.of(javascriptLanguage.data.of({
|
212
|
-
autocomplete: this.
|
224
|
+
autocomplete: this.customAutocomplete
|
213
225
|
}));
|
214
|
-
|
226
|
+
|
215
227
|
this.viewState = EditorState.create({
|
216
228
|
doc: !this.multiline ? this.convertToSingleLine(this.value) : this.value,
|
217
229
|
extensions: [
|
@@ -223,6 +235,7 @@ export class NileCodeEditor extends NileElement {
|
|
223
235
|
readOnlyExtension,
|
224
236
|
restrictSingleLineExtension,
|
225
237
|
customAutoCompletions,
|
238
|
+
placeholderExtension,
|
226
239
|
autocompletion(),
|
227
240
|
language,
|
228
241
|
EditorView.theme(Theme),
|
@@ -297,55 +310,58 @@ export class NileCodeEditor extends NileElement {
|
|
297
310
|
) : [];
|
298
311
|
}
|
299
312
|
|
313
|
+
getPlaceholderExtension(){
|
314
|
+
return this.placeholder ? placeholder(this.placeholder) : [];
|
315
|
+
}
|
316
|
+
|
300
317
|
restrictSingleLine() {
|
301
318
|
return EditorState.transactionFilter.of(tr =>
|
302
319
|
tr.newDoc.lines > 1 ? [] : tr
|
303
320
|
);
|
304
321
|
}
|
305
322
|
|
306
|
-
emitNileExpand() {
|
307
|
-
this.emit('nile-expand', { expand: true },false);
|
308
|
-
}
|
309
|
-
|
310
323
|
customAutocomplete = (context: CompletionContext): CompletionResult | null => {
|
311
324
|
// Getting the valid last line, last text from the code editor
|
312
325
|
let text = context.state.doc.sliceString(0, context.pos);
|
313
|
-
const [textBeforeCursor,baseTextAfterSeperation]=this.splitStringAtLastSeparator(text.split('\n').at(-1)?.split(' ').at(-1)+'')
|
314
|
-
const textAfterSeperation=baseTextAfterSeperation.replace(/["'\[]/g, '')
|
326
|
+
const [textBeforeCursor, baseTextAfterSeperation] = this.splitStringAtLastSeparator(text.split('\n').at(-1)?.split(' ').at(-1) + '')
|
327
|
+
const textAfterSeperation = baseTextAfterSeperation.replace(/["'\[]/g, '')
|
315
328
|
|
316
|
-
const
|
329
|
+
const isInString = textAfterSeperation != baseTextAfterSeperation;
|
330
|
+
const isBracket = textBeforeCursor.at(-1) == '[';
|
331
|
+
const isDot = textBeforeCursor.at(-1) == '.';
|
317
332
|
|
318
333
|
if (!this.isValidPath(textBeforeCursor)) return { from: context.pos, options: [] };
|
319
|
-
if(['.', '['].includes(textBeforeCursor[textBeforeCursor.length - 1])){
|
334
|
+
if (['.', '['].includes(textBeforeCursor[textBeforeCursor.length - 1])) {
|
320
335
|
// Parse the path for dot or bracket notation
|
321
336
|
const path = this.parsePath(textBeforeCursor);
|
322
337
|
if (path) {
|
338
|
+
if (isDot && isInString) return null;
|
323
339
|
let resolved = this.resolveNestedProperties(this.customAutoCompletions, path);
|
324
|
-
if(textAfterSeperation){
|
325
|
-
const obj:any={}
|
326
|
-
Object.keys(resolved).forEach((key)=>{
|
327
|
-
if(key.toLowerCase().startsWith(textAfterSeperation.toLowerCase())){
|
328
|
-
obj[key]=resolved[key]
|
340
|
+
if (textAfterSeperation) {
|
341
|
+
const obj: any = {}
|
342
|
+
Object.keys(resolved).forEach((key) => {
|
343
|
+
if (key.toLowerCase().startsWith(textAfterSeperation.toLowerCase())) {
|
344
|
+
obj[key] = resolved[key]
|
329
345
|
}
|
330
346
|
})
|
331
|
-
resolved=obj
|
347
|
+
resolved = obj
|
332
348
|
}
|
333
349
|
// If resolved is an object, provide its keys as suggestions
|
334
350
|
if (resolved && typeof resolved === 'object') {
|
335
351
|
return {
|
336
|
-
from: context.pos-textAfterSeperation.length,
|
352
|
+
from: context.pos - textAfterSeperation.length,
|
337
353
|
options: Object.keys(resolved).map((key) => ({
|
338
354
|
label: key,
|
339
355
|
type: 'property',
|
340
356
|
info: `Key of ${path[path.length - 1]}`,
|
341
|
-
apply: key,
|
357
|
+
apply: !this.allowVariableInCustomSuggestion && (isBracket && !isInString) ? "\'" + key + "\'" : key,
|
342
358
|
boost: 999
|
343
359
|
})),
|
344
360
|
};
|
345
361
|
}
|
346
362
|
}
|
347
363
|
}
|
348
|
-
|
364
|
+
|
349
365
|
// Match for top-level object suggestions, e.g., "a"
|
350
366
|
const baseMatch: any = textBeforeCursor.match(/([a-zA-Z_$][\w$]*)$/);
|
351
367
|
if (baseMatch) {
|
@@ -361,7 +377,7 @@ export class NileCodeEditor extends NileElement {
|
|
361
377
|
}
|
362
378
|
}
|
363
379
|
// Default to an empty list if no match
|
364
|
-
return
|
380
|
+
return null;
|
365
381
|
};
|
366
382
|
|
367
383
|
resolveNestedProperties = (obj:any, keys:any[]) => {
|
@@ -10,6 +10,7 @@ import {
|
|
10
10
|
html,
|
11
11
|
CSSResultArray,
|
12
12
|
TemplateResult,
|
13
|
+
PropertyValues,
|
13
14
|
} from 'lit';
|
14
15
|
import { customElement, property } from 'lit/decorators.js';
|
15
16
|
import { styles } from './nile-error-notification.css';
|
@@ -35,9 +36,8 @@ export class NileErrorNotification extends LitElement {
|
|
35
36
|
|
36
37
|
@property({ type: String, reflect: true }) color: string = '';
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
if(this.color){
|
39
|
+
protected updated(_changedProperties: PropertyValues): void {
|
40
|
+
if(_changedProperties.has('color')){
|
41
41
|
this.style.setProperty('--indication-color',this.color)
|
42
42
|
}
|
43
43
|
}
|
@@ -726,7 +726,7 @@
|
|
726
726
|
},
|
727
727
|
{
|
728
728
|
"name": "nile-code-editor",
|
729
|
-
"description": "Nile icon component.\n\nEvents:\n\n * `nile-focus` {`Event`} - \n\n * `nile-blur` {`Event`} - \n\nAttributes:\n\n * `value` {`string`} - \n\n * `expandIcon` {`string`} - \n\n * `customAutoCompletions` - \n\n * `language` {`\"javascript\" | \"sql\" | \"json\"`} - \n\n * `error-message` {`string`} - \n\n * `error` {`boolean`} - \n\n * `noborder` {`boolean`} - \n\n * `multiline` {`boolean`} - \n\n * `
|
729
|
+
"description": "Nile icon component.\n\nEvents:\n\n * `nile-focus` {`Event`} - \n\n * `nile-blur` {`Event`} - \n\nAttributes:\n\n * `value` {`string`} - \n\n * `expandIcon` {`string`} - \n\n * `placeholder` {`string`} - \n\n * `customAutoCompletions` - \n\n * `language` {`\"javascript\" | \"sql\" | \"json\"`} - \n\n * `error-message` {`string`} - \n\n * `error` {`boolean`} - \n\n * `noborder` {`boolean`} - \n\n * `multiline` {`boolean`} - \n\n * `allowVariableInCustomSuggestion` {`boolean`} - \n\n * `lineNumbers` {`boolean`} - \n\n * `lineNumbersMultiline` {`boolean`} - \n\n * `hasScroller` {`boolean`} - \n\n * `expandable` {`boolean`} - \n\n * `readonly` {`boolean`} - \n\n * `debounce` {`boolean`} - \n\nProperties:\n\n * `codeEditor` {`HTMLInputElement`} - \n\n * `value` {`string`} - \n\n * `expandIcon` {`string`} - \n\n * `placeholder` {`string`} - \n\n * `customAutoCompletions` - \n\n * `language` {`\"javascript\" | \"sql\" | \"json\"`} - \n\n * `errorMessage` {`string`} - \n\n * `error` {`boolean`} - \n\n * `noborder` {`boolean`} - \n\n * `multiline` {`boolean`} - \n\n * `allowVariableInCustomSuggestion` {`boolean`} - \n\n * `lineNumbers` {`boolean`} - \n\n * `lineNumbersMultiline` {`boolean`} - \n\n * `hasScroller` {`boolean`} - \n\n * `expandable` {`boolean`} - \n\n * `readonly` {`boolean`} - \n\n * `debounce` {`boolean`} - \n\n * `view` - \n\n * `viewState` - \n\n * `timeOut` - \n\n * `lineNumbersComp` - \n\n * `restrictSingleLineComp` - \n\n * `readOnlyComp` - \n\n * `customCompletionComp` - \n\n * `placeholderComp` - \n\n * `insertBetweenCode` - \n\n * `customAutocomplete` - \n\n * `resolveNestedProperties` - \n\n * `BUBBLES` {`boolean`} - \n\n * `COMPOSED` {`boolean`} - \n\n * `CANCELABLE` {`boolean`} - ",
|
730
730
|
"attributes": [
|
731
731
|
{
|
732
732
|
"name": "value",
|
@@ -736,6 +736,10 @@
|
|
736
736
|
"name": "expandIcon",
|
737
737
|
"description": "`expandIcon` {`string`} - \n\nProperty: expandIcon\n\nDefault: expand-2"
|
738
738
|
},
|
739
|
+
{
|
740
|
+
"name": "placeholder",
|
741
|
+
"description": "`placeholder` {`string`} - \n\nProperty: placeholder\n\nDefault: "
|
742
|
+
},
|
739
743
|
{
|
740
744
|
"name": "customAutoCompletions",
|
741
745
|
"description": "`customAutoCompletions` - \n\nProperty: customAutoCompletions\n\nDefault: [object Object]"
|
@@ -775,8 +779,8 @@
|
|
775
779
|
"valueSet": "v"
|
776
780
|
},
|
777
781
|
{
|
778
|
-
"name": "
|
779
|
-
"description": "`
|
782
|
+
"name": "allowVariableInCustomSuggestion",
|
783
|
+
"description": "`allowVariableInCustomSuggestion` {`boolean`} - \n\nProperty: allowVariableInCustomSuggestion\n\nDefault: false",
|
780
784
|
"valueSet": "v"
|
781
785
|
},
|
782
786
|
{
|