@aquera/nile-elements 0.0.126 → 0.0.127
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 +3 -0
- 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 +2 -2
- package/dist/src/nile-code-editor/nile-code-editor.d.ts +1 -0
- package/dist/src/nile-code-editor/nile-code-editor.js +45 -29
- package/dist/src/nile-code-editor/nile-code-editor.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/nile-code-editor/nile-code-editor.ts +45 -30
package/package.json
CHANGED
@@ -309,41 +309,51 @@ export class NileCodeEditor extends NileElement {
|
|
309
309
|
customAutocomplete = (context: CompletionContext): CompletionResult | null => {
|
310
310
|
// Getting the valid last line, last text from the code editor
|
311
311
|
let text = context.state.doc.sliceString(0, context.pos);
|
312
|
-
|
313
|
-
|
314
|
-
if (!
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
312
|
+
const [textBeforeCursor,textAfterSeperation]=this.splitStringAtLastSeparator(text.split('\n').at(-1)?.split(' ').at(-1)+'')
|
313
|
+
|
314
|
+
if (!this.isValidPath(textBeforeCursor)) return { from: context.pos, options: [] };
|
315
|
+
if(['.', '['].includes(textBeforeCursor[textBeforeCursor.length - 1])){
|
316
|
+
// Parse the path for dot or bracket notation
|
317
|
+
const path = this.parsePath(textBeforeCursor);
|
318
|
+
if (path) {
|
319
|
+
let resolved = this.resolveNestedProperties(this.customAutoCompletions, path);
|
320
|
+
if(textAfterSeperation){
|
321
|
+
const obj:any={}
|
322
|
+
Object.keys(resolved).forEach((key)=>{
|
323
|
+
if(key.startsWith(textAfterSeperation)){
|
324
|
+
obj[key]=resolved[key]
|
325
|
+
}
|
326
|
+
})
|
327
|
+
resolved=obj
|
328
|
+
}
|
329
|
+
// If resolved is an object, provide its keys as suggestions
|
330
|
+
if (resolved && typeof resolved === 'object') {
|
331
|
+
return {
|
332
|
+
from: context.pos,
|
333
|
+
options: Object.keys(resolved).map((key) => ({
|
334
|
+
label: key,
|
335
|
+
type: 'property',
|
336
|
+
info: `Key of ${path[path.length - 1]}`,
|
337
|
+
apply: key.slice(textAfterSeperation.length),
|
338
|
+
boost: 999
|
339
|
+
})),
|
340
|
+
};
|
341
|
+
}
|
331
342
|
}
|
332
343
|
}
|
344
|
+
|
333
345
|
// Match for top-level object suggestions, e.g., "a"
|
334
346
|
const baseMatch: any = textBeforeCursor.match(/([a-zA-Z_$][\w$]*)$/);
|
335
347
|
if (baseMatch) {
|
336
|
-
const
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
})),
|
346
|
-
};
|
348
|
+
const optionsList=Object.keys(this.customAutoCompletions).filter(key=>key.startsWith(textBeforeCursor));
|
349
|
+
return {
|
350
|
+
from: context.pos - baseMatch[1].length,
|
351
|
+
options: optionsList.map((key) => ({
|
352
|
+
label: key,
|
353
|
+
type: 'property',
|
354
|
+
apply: key.slice(textBeforeCursor.length),
|
355
|
+
boost: 999
|
356
|
+
}))
|
347
357
|
}
|
348
358
|
}
|
349
359
|
// Default to an empty list if no match
|
@@ -386,6 +396,11 @@ export class NileCodeEditor extends NileElement {
|
|
386
396
|
return regex.test(path);
|
387
397
|
}
|
388
398
|
|
399
|
+
splitStringAtLastSeparator(input:string) {
|
400
|
+
const lastSeparatorIndex = Math.max(input.lastIndexOf('.'), input.lastIndexOf('['));
|
401
|
+
if (lastSeparatorIndex === -1) return [input, ''];
|
402
|
+
return [input.slice(0, lastSeparatorIndex + 1), input.slice(lastSeparatorIndex + 1).replace(/["'\[]/g, '')];
|
403
|
+
}
|
389
404
|
/* #endregion */
|
390
405
|
}
|
391
406
|
|