@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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent nile-elements following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "nile-elements",
6
- "version": "0.0.126",
6
+ "version": "0.0.127",
7
7
  "main": "dist/src/index.js",
8
8
  "type": "module",
9
9
  "module": "dist/src/index.js",
@@ -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
- let textBeforeCursor=text.split('\n').at(-1)?.split(' ').at(-1)+'';
313
-
314
- if (!(this.isValidPath(textBeforeCursor) && ['.', '['].includes(textBeforeCursor[textBeforeCursor.length - 1]))) {
315
- return { from: context.pos, options: [] };
316
- }
317
- // Parse the path for dot or bracket notation
318
- const path = this.parsePath(textBeforeCursor);
319
- if (path) {
320
- const resolved = this.resolveNestedProperties(this.customAutoCompletions, path);
321
- // If resolved is an object, provide its keys as suggestions
322
- if (resolved && typeof resolved === 'object') {
323
- return {
324
- from: context.pos,
325
- options: Object.keys(resolved).map((key) => ({
326
- label: key,
327
- type: 'property',
328
- info: `Key of ${path[path.length - 1]}`
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 resolved = this.customAutoCompletions[baseMatch[1]];
337
- // If resolved is an object, provide its top-level properties as suggestions
338
- if (resolved && typeof resolved === 'object') {
339
- return {
340
- from: context.pos - baseMatch[1].length,
341
- options: Object.keys(resolved).map((key) => ({
342
- label: key,
343
- type: 'property',
344
- info: `Property of ${baseMatch[1]}`,
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