@aquera/nile-elements 0.1.2 → 0.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/dist/nile-code-editor/extensionSetup.cjs.js.map +1 -1
- package/dist/nile-code-editor/nile-code-editor.cjs.js +1 -1
- package/dist/nile-code-editor/nile-code-editor.cjs.js.map +1 -1
- package/dist/nile-code-editor/nile-code-editor.esm.js +2 -2
- package/dist/nile-drawer/nile-drawer.css.cjs.js +1 -1
- package/dist/nile-drawer/nile-drawer.css.cjs.js.map +1 -1
- package/dist/nile-drawer/nile-drawer.css.esm.js +1 -1
- package/dist/nile-form-help-text/nile-form-help-text.cjs.js +1 -1
- package/dist/nile-form-help-text/nile-form-help-text.cjs.js.map +1 -1
- package/dist/nile-form-help-text/nile-form-help-text.esm.js +2 -2
- package/dist/src/nile-code-editor/extensionSetup.d.ts +8 -9
- package/dist/src/nile-code-editor/extensionSetup.js +0 -13
- package/dist/src/nile-code-editor/extensionSetup.js.map +1 -1
- package/dist/src/nile-code-editor/nile-code-editor.d.ts +19 -0
- package/dist/src/nile-code-editor/nile-code-editor.js +61 -2
- package/dist/src/nile-code-editor/nile-code-editor.js.map +1 -1
- package/dist/src/nile-drawer/nile-drawer.css.js +1 -1
- package/dist/src/nile-drawer/nile-drawer.css.js.map +1 -1
- package/dist/src/nile-form-help-text/nile-form-help-text.js +32 -2
- package/dist/src/nile-form-help-text/nile-form-help-text.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/nile-code-editor/extensionSetup.ts +8 -23
- package/src/nile-code-editor/nile-code-editor.ts +59 -3
- package/src/nile-drawer/nile-drawer.css.ts +1 -1
- package/src/nile-form-help-text/nile-form-help-text.ts +37 -3
- package/vscode-html-custom-data.json +5 -1
package/package.json
CHANGED
@@ -30,6 +30,14 @@ import {
|
|
30
30
|
|
31
31
|
import { lintKeymap } from '@codemirror/lint';
|
32
32
|
|
33
|
+
export interface MinimalSetupOptions {
|
34
|
+
highlightSpecialChars?: boolean;
|
35
|
+
history?: boolean;
|
36
|
+
drawSelection?: boolean;
|
37
|
+
syntaxHighlighting?: boolean;
|
38
|
+
defaultKeymap?: boolean;
|
39
|
+
historyKeymap?: boolean;
|
40
|
+
}
|
33
41
|
export interface BasicSetupOptions extends MinimalSetupOptions {
|
34
42
|
lineNumbers?: boolean;
|
35
43
|
highlightActiveLineGutter?: boolean;
|
@@ -91,27 +99,4 @@ export const basicSetup = (options: BasicSetupOptions = {}): Extension[] => {
|
|
91
99
|
return extensions.concat([keymap.of(keymaps.flat())]).filter(Boolean);
|
92
100
|
};
|
93
101
|
|
94
|
-
export interface MinimalSetupOptions {
|
95
|
-
highlightSpecialChars?: boolean;
|
96
|
-
history?: boolean;
|
97
|
-
drawSelection?: boolean;
|
98
|
-
syntaxHighlighting?: boolean;
|
99
|
-
defaultKeymap?: boolean;
|
100
|
-
historyKeymap?: boolean;
|
101
|
-
}
|
102
102
|
|
103
|
-
export const minimalSetup = (options: MinimalSetupOptions = {}) => {
|
104
|
-
let keymaps: KeyBinding[] = [];
|
105
|
-
isValidSetup(options.defaultKeymap) && keymaps.push(...defaultKeymap);
|
106
|
-
isValidSetup(options.historyKeymap) && keymaps.push(...historyKeymap);
|
107
|
-
const extensions: Extension[] = [];
|
108
|
-
isValidSetup(options.highlightSpecialChars) &&
|
109
|
-
extensions.push(highlightSpecialChars());
|
110
|
-
isValidSetup(options.history) && extensions.push(history());
|
111
|
-
isValidSetup(options.drawSelection) && extensions.push(drawSelection());
|
112
|
-
isValidSetup(options.syntaxHighlighting) &&
|
113
|
-
extensions.push(
|
114
|
-
syntaxHighlighting(defaultHighlightStyle, { fallback: true })
|
115
|
-
);
|
116
|
-
return extensions.concat([keymap.of(keymaps.flat())]).filter(Boolean);
|
117
|
-
};
|
@@ -36,7 +36,6 @@ import { basicSetup } from './extensionSetup';
|
|
36
36
|
import { classMap } from 'lit/directives/class-map.js';
|
37
37
|
import { Theme } from './theme';
|
38
38
|
|
39
|
-
const TIME_OUT_DURATION=200;
|
40
39
|
// Choose the appropriate mode for your use case
|
41
40
|
|
42
41
|
/**
|
@@ -84,6 +83,8 @@ export class NileCodeEditor extends NileElement {
|
|
84
83
|
|
85
84
|
@property({ type: Boolean, reflect: true , attribute: true}) debounce: boolean = false;
|
86
85
|
|
86
|
+
@property({ type: Number, reflect: true , attribute: true}) debounceTimeout: number = 200;
|
87
|
+
|
87
88
|
public view: EditorView;
|
88
89
|
public viewState:EditorState;
|
89
90
|
private timeOut: any = null;
|
@@ -254,7 +255,11 @@ export class NileCodeEditor extends NileElement {
|
|
254
255
|
});
|
255
256
|
return this.viewState
|
256
257
|
}
|
257
|
-
|
258
|
+
/**
|
259
|
+
* Custom autocomplete handler for code editor suggestions
|
260
|
+
* @param context CompletionContext from CodeMirror
|
261
|
+
* @returns CompletionResult with suggestions or null if no suggestions
|
262
|
+
*/
|
258
263
|
customAutocomplete = (context: CompletionContext): CompletionResult | null => {
|
259
264
|
// Getting the valid last line, last text from the code editor
|
260
265
|
const text = context.state.doc.sliceString(0, context.pos);
|
@@ -265,6 +270,13 @@ export class NileCodeEditor extends NileElement {
|
|
265
270
|
|| this.getTopLevelSuggestions(context, textBeforeCursor);
|
266
271
|
};
|
267
272
|
|
273
|
+
/**
|
274
|
+
* Gets nested property suggestions based on the current path
|
275
|
+
* @param context CompletionContext from CodeMirror
|
276
|
+
* @param textBeforeCursor Text before cursor position
|
277
|
+
* @param baseTextAfterSeperation Text after the last separator (. or [)
|
278
|
+
* @returns CompletionResult with nested suggestions or null
|
279
|
+
*/
|
268
280
|
getNestedSuggestions(context: CompletionContext, textBeforeCursor: string, baseTextAfterSeperation: string) {
|
269
281
|
// Return early if not a valid path or not ending with . or [
|
270
282
|
if (!isValidPath(textBeforeCursor) || !['.', '['].includes(textBeforeCursor.at(-1)!)) {
|
@@ -307,6 +319,12 @@ export class NileCodeEditor extends NileElement {
|
|
307
319
|
};
|
308
320
|
}
|
309
321
|
|
322
|
+
/**
|
323
|
+
* Gets top level suggestions based on custom completions and paths
|
324
|
+
* @param context CompletionContext from CodeMirror
|
325
|
+
* @param textBeforeCursor Text before cursor position
|
326
|
+
* @returns CompletionResult with top level suggestions or null
|
327
|
+
*/
|
310
328
|
getTopLevelSuggestions(context: CompletionContext,textBeforeCursor:string){
|
311
329
|
const baseMatch: any = textBeforeCursor.match(/([a-zA-Z_$][\w$]*)$/);
|
312
330
|
if (!baseMatch) return null;
|
@@ -342,7 +360,7 @@ export class NileCodeEditor extends NileElement {
|
|
342
360
|
|
343
361
|
emitAfterTimeout(value:any){
|
344
362
|
if(this.timeOut) clearTimeout(this.timeOut);
|
345
|
-
this.timeOut=setTimeout(()=> this.emit('nile-change', value, false),
|
363
|
+
this.timeOut=setTimeout(()=> this.emit('nile-change', value, false), this.debounceTimeout)
|
346
364
|
}
|
347
365
|
|
348
366
|
public insertBetweenCode=(text: string) => {
|
@@ -413,6 +431,14 @@ declare global {
|
|
413
431
|
}
|
414
432
|
}
|
415
433
|
|
434
|
+
/**
|
435
|
+
* Parses a string path into an array of keys representing nested object access
|
436
|
+
* @param text The path string to parse (e.g. "foo.bar[0].baz")
|
437
|
+
* @returns Array of keys if valid path, null otherwise
|
438
|
+
* @example
|
439
|
+
* parsePath("foo.bar[0]") // returns ["foo", "bar", "0"]
|
440
|
+
* parsePath("invalid") // returns null
|
441
|
+
*/
|
416
442
|
function parsePath(text: string) {
|
417
443
|
const regex = /([a-zA-Z_$][\w$]*)(\[(?:[^\]]+)\]|\.[a-zA-Z_$][\w$]*)*/g;
|
418
444
|
const matches = [...text.matchAll(regex)];
|
@@ -433,12 +459,27 @@ function parsePath(text: string) {
|
|
433
459
|
return null;
|
434
460
|
};
|
435
461
|
|
462
|
+
/**
|
463
|
+
* Splits a path string at the last separator (. or [)
|
464
|
+
* @param input The path string to split
|
465
|
+
* @returns Array containing [path up to last separator, remainder after separator]
|
466
|
+
* @example
|
467
|
+
* splitStringAtLastSeparator("foo.bar[0]") // returns ["foo.bar[", "0"]
|
468
|
+
*/
|
436
469
|
function splitStringAtLastSeparator(input:string) {
|
437
470
|
const lastSeparatorIndex = Math.max(input.lastIndexOf('.'), input.lastIndexOf('['));
|
438
471
|
if (lastSeparatorIndex === -1) return [input, ''];
|
439
472
|
return [input.slice(0, lastSeparatorIndex + 1), input.slice(lastSeparatorIndex + 1)];
|
440
473
|
}
|
441
474
|
|
475
|
+
/**
|
476
|
+
* Traverses an object using an array of keys to access nested properties
|
477
|
+
* @param obj The object to traverse
|
478
|
+
* @param keys Array of keys defining the path to the desired property
|
479
|
+
* @returns The value at the specified path, or null if path is invalid
|
480
|
+
* @example
|
481
|
+
* resolveNestedProperties({foo: {bar: 123}}, ["foo", "bar"]) // returns 123
|
482
|
+
*/
|
442
483
|
function resolveNestedProperties (obj:any, keys:any[]){
|
443
484
|
return keys.reduce((acc, key) => {
|
444
485
|
if (acc && typeof acc === 'object') {
|
@@ -448,6 +489,14 @@ function resolveNestedProperties (obj:any, keys:any[]){
|
|
448
489
|
}, obj);
|
449
490
|
};
|
450
491
|
|
492
|
+
/**
|
493
|
+
* Validates if a string represents a valid object path format
|
494
|
+
* @param path The path string to validate
|
495
|
+
* @returns Boolean indicating if path format is valid
|
496
|
+
* @example
|
497
|
+
* isValidPath("foo.bar[0]") // returns true
|
498
|
+
* isValidPath("foo..bar") // returns false
|
499
|
+
*/
|
451
500
|
function isValidPath(path: string) {
|
452
501
|
// Regex to validate the format of the string
|
453
502
|
const regex = /^([a-zA-Z_$][\w$]*)(\.[a-zA-Z_$][\w$]*|\[\s*(['"]?[a-zA-Z0-9_$]*['"]?)\s*\])*([\.\[])?$/;
|
@@ -455,6 +504,13 @@ function isValidPath(path: string) {
|
|
455
504
|
return regex.test(path);
|
456
505
|
}
|
457
506
|
|
507
|
+
/**
|
508
|
+
* Converts multi-line code into a single line by removing line breaks and extra whitespace
|
509
|
+
* @param code The code string to convert
|
510
|
+
* @returns Single line version of the code
|
511
|
+
* @example
|
512
|
+
* convertToSingleLine("foo\n bar") // returns "foo bar"
|
513
|
+
*/
|
458
514
|
function convertToSingleLine(code: string) {
|
459
515
|
if (!code) return '';
|
460
516
|
// Remove line breaks and unnecessary whitespace
|
@@ -58,8 +58,15 @@ export class NileFormHelpText extends LitElement {
|
|
58
58
|
this.updateDisplayedText()
|
59
59
|
}
|
60
60
|
|
61
|
-
updateDisplayedText(){
|
62
|
-
|
61
|
+
updateDisplayedText() {
|
62
|
+
if (this.isExpanded) {
|
63
|
+
this.displayedText = this.fullText;
|
64
|
+
} else {
|
65
|
+
const validConcatNumber=concatSentence(this.fullText, this.textLimit)
|
66
|
+
const truncatedText = this.fullText.slice(0, validConcatNumber);
|
67
|
+
const ellipsis = this.fullText.length > validConcatNumber ? '...' : '';
|
68
|
+
this.displayedText = `${truncatedText}${ellipsis}`;
|
69
|
+
}
|
63
70
|
}
|
64
71
|
|
65
72
|
/* #endregion */
|
@@ -71,7 +78,7 @@ export class NileFormHelpText extends LitElement {
|
|
71
78
|
* @slot This is a slot test
|
72
79
|
*/
|
73
80
|
public render(): TemplateResult {
|
74
|
-
const showMoreButton = this.fullText.length > this.textLimit
|
81
|
+
const showMoreButton = this.fullText.length > this.textLimit;
|
75
82
|
const iconName = this.isExpanded ? 'arrowup' : 'arrowdown';
|
76
83
|
|
77
84
|
return html`
|
@@ -101,3 +108,30 @@ declare global {
|
|
101
108
|
'nile-form-help-text': NileFormHelpText;
|
102
109
|
}
|
103
110
|
}
|
111
|
+
|
112
|
+
function concatSentence(sentence:string, n:number) {
|
113
|
+
if (n < 0 || n > sentence.length) {
|
114
|
+
throw new Error("Invalid value of n. It must be between 0 and the sentence length.");
|
115
|
+
}
|
116
|
+
|
117
|
+
// Adjust n if it falls in the middle of a word
|
118
|
+
if (sentence[n] !== " " && n !== 0 && n !== sentence.length) {
|
119
|
+
// Move left until the start of the word or the beginning of the sentence
|
120
|
+
let left = n;
|
121
|
+
while (left > 0 && sentence[left - 1] !== " ") {
|
122
|
+
left--;
|
123
|
+
}
|
124
|
+
|
125
|
+
// Move right until the end of the word or the end of the sentence
|
126
|
+
let right = n;
|
127
|
+
while (right < sentence.length && sentence[right] !== " ") {
|
128
|
+
right++;
|
129
|
+
}
|
130
|
+
|
131
|
+
// Adjust n to the closer boundary
|
132
|
+
n = (n - left <= right - n) ? left : right;
|
133
|
+
}
|
134
|
+
|
135
|
+
// Return the substring from the start to the adjusted n
|
136
|
+
return n;
|
137
|
+
}
|
@@ -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 * `placeholder` {`string`} - \n\n * `customAutoCompletions` - \n\n * `customCompletionsPaths` {`string[]`} - \n\n * `language` {`\"html\" | \"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 * `customCompletionsPaths` {`string[]`} - \n\n * `language` {`\"html\" | \"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 * `customAutocomplete` - \n\n * `insertBetweenCode` - \n\n * `BUBBLES` {`boolean`} - \n\n * `COMPOSED` {`boolean`} - \n\n * `CANCELABLE` {`boolean`} - ",
|
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 * `customCompletionsPaths` {`string[]`} - \n\n * `language` {`\"html\" | \"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\n * `debounceTimeout` {`number`} - \n\nProperties:\n\n * `codeEditor` {`HTMLInputElement`} - \n\n * `value` {`string`} - \n\n * `expandIcon` {`string`} - \n\n * `placeholder` {`string`} - \n\n * `customAutoCompletions` - \n\n * `customCompletionsPaths` {`string[]`} - \n\n * `language` {`\"html\" | \"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 * `debounceTimeout` {`number`} - \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 * `customAutocomplete` - Custom autocomplete handler for code editor suggestions\n\n * `insertBetweenCode` - \n\n * `BUBBLES` {`boolean`} - \n\n * `COMPOSED` {`boolean`} - \n\n * `CANCELABLE` {`boolean`} - ",
|
730
730
|
"attributes": [
|
731
731
|
{
|
732
732
|
"name": "value",
|
@@ -820,6 +820,10 @@
|
|
820
820
|
"description": "`debounce` {`boolean`} - \n\nProperty: debounce\n\nDefault: false",
|
821
821
|
"valueSet": "v"
|
822
822
|
},
|
823
|
+
{
|
824
|
+
"name": "debounceTimeout",
|
825
|
+
"description": "`debounceTimeout` {`number`} - \n\nProperty: debounceTimeout\n\nDefault: 200"
|
826
|
+
},
|
823
827
|
{
|
824
828
|
"name": "onnile-focus",
|
825
829
|
"description": "`nile-focus` {`Event`} - "
|