@aquera/nile-elements 0.1.0 → 0.1.2

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.
@@ -1,2 +1,2 @@
1
- function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o;}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o;},_typeof(o);}System.register(["tslib","lit","lit/decorators.js","./nile-error-notification.css.cjs.js"],function(_export,_context){"use strict";var i,r,o,t,e,n,_templateObject,s;function _taggedTemplateLiteral(strings,raw){if(!raw){raw=strings.slice(0);}return Object.freeze(Object.defineProperties(strings,{raw:{value:Object.freeze(raw)}}));}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,_toPropertyKey(descriptor.key),descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+"";}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.");}return("string"===r?String:Number)(t);}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t;})();}function _get(){if(typeof Reflect!=="undefined"&&Reflect.get){_get=Reflect.get.bind();}else{_get=function _get(target,property,receiver){var base=_superPropBase(target,property);if(!base)return;var desc=Object.getOwnPropertyDescriptor(base,property);if(desc.get){return desc.get.call(arguments.length<3?target:receiver);}return desc.value;};}return _get.apply(this,arguments);}function _superPropBase(object,property){while(!Object.prototype.hasOwnProperty.call(object,property)){object=_getPrototypeOf(object);if(object===null)break;}return object;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}return{setters:[function(_tslib){i=_tslib.__decorate;},function(_lit){r=_lit.LitElement;o=_lit.html;},function(_litDecoratorsJs){t=_litDecoratorsJs.property;e=_litDecoratorsJs.customElement;},function(_nileErrorNotificationCssCjsJs){n=_nileErrorNotificationCssCjsJs.s;}],execute:function execute(){_export("N",s=/*#__PURE__*/function(_r){function s(){var _this;_classCallCheck(this,s);_this=_callSuper(this,s,arguments),_this.errorMessage="",_this.color="";return _this;}_inherits(s,_r);return _createClass(s,[{key:"connectedCallback",value:function connectedCallback(){_get(_getPrototypeOf(s.prototype),"connectedCallback",this).call(this),this.color&&this.style.setProperty("--indication-color",this.color);}},{key:"render",value:function render(){return o(_templateObject||(_templateObject=_taggedTemplateLiteral(["\n <div class=\"nile-error-notification\">\n <nile-icon\n name=\"info2\"\n size=\"14\"\n class=\"nile-error-notification__icon\"\n part=\"icon\"\n color=\"var(--indication-color)\"\n ></nile-icon>\n ","\n </div>\n "])),this.errorMessage);}}],[{key:"styles",get:function get(){return[n];}}]);}(r));i([t({type:String,reflect:!0})],s.prototype,"errorMessage",void 0),i([t({type:String,reflect:!0})],s.prototype,"color",void 0),_export("N",s=i([e("nile-error-notification")],s));}};});
1
+ function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o;}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o;},_typeof(o);}System.register(["tslib","lit","lit/decorators.js","./nile-error-notification.css.cjs.js"],function(_export,_context){"use strict";var i,r,o,t,e,n,_templateObject,s;function _taggedTemplateLiteral(strings,raw){if(!raw){raw=strings.slice(0);}return Object.freeze(Object.defineProperties(strings,{raw:{value:Object.freeze(raw)}}));}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,_toPropertyKey(descriptor.key),descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+"";}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.");}return("string"===r?String:Number)(t);}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t;})();}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}return{setters:[function(_tslib){i=_tslib.__decorate;},function(_lit){r=_lit.LitElement;o=_lit.html;},function(_litDecoratorsJs){t=_litDecoratorsJs.property;e=_litDecoratorsJs.customElement;},function(_nileErrorNotificationCssCjsJs){n=_nileErrorNotificationCssCjsJs.s;}],execute:function execute(){_export("N",s=/*#__PURE__*/function(_r){function s(){var _this;_classCallCheck(this,s);_this=_callSuper(this,s,arguments),_this.errorMessage="",_this.color="";return _this;}_inherits(s,_r);return _createClass(s,[{key:"updated",value:function updated(i){i.has("color")&&this.style.setProperty("--indication-color",this.color);}},{key:"render",value:function render(){return o(_templateObject||(_templateObject=_taggedTemplateLiteral(["\n <div class=\"nile-error-notification\">\n <nile-icon\n name=\"info2\"\n size=\"14\"\n class=\"nile-error-notification__icon\"\n part=\"icon\"\n color=\"var(--indication-color)\"\n ></nile-icon>\n ","\n </div>\n "])),this.errorMessage);}}],[{key:"styles",get:function get(){return[n];}}]);}(r));i([t({type:String,reflect:!0})],s.prototype,"errorMessage",void 0),i([t({type:String,reflect:!0})],s.prototype,"color",void 0),_export("N",s=i([e("nile-error-notification")],s));}};});
2
2
  //# sourceMappingURL=nile-error-notification.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nile-error-notification.cjs.js","sources":["../../../src/nile-error-notification/nile-error-notification.ts"],"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 CSSResultArray,\n TemplateResult,\n} from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { styles } from './nile-error-notification.css';\n\n/**\n * Nile icon component.\n *\n * @tag nile-error-notification\n *\n */\n@customElement('nile-error-notification')\nexport class NileErrorNotification extends LitElement {\n /**\n * The styles for ErrorNotification\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 // Represents the error message to be displayed to the user.\n @property({ type: String, reflect: true }) errorMessage: string = '';\n\n @property({ type: String, reflect: true }) color: string = '';\n \n connectedCallback(): void {\n super.connectedCallback();\n if(this.color){\n this.style.setProperty('--indication-color',this.color)\n }\n }\n\n /* #endregion */\n\n /* #region Methods */\n\n /**\n * Render method\n * @slot This is a slot test\n */\n public render(): TemplateResult {\n return html`\n <div class=\"nile-error-notification\">\n <nile-icon\n name=\"info2\"\n size=\"14\"\n class=\"nile-error-notification__icon\"\n part=\"icon\"\n color=\"var(--indication-color)\"\n ></nile-icon>\n ${this.errorMessage}\n </div>\n `;\n }\n\n /* #endregion */\n}\n\nexport default NileErrorNotification;\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-error-notification': NileErrorNotification;\n }\n}\n"],"names":["NileErrorNotification","s","this","errorMessage","color","_this","_inherits","_r","_createClass","key","value","connectedCallback","super","style","setProperty","render","html","_templateObject","_taggedTemplateLiteral","get","styles","LitElement","__decorate","property","type","String","reflect","prototype","_export","customElement"],"mappings":"mkIAuBaA,4BAAN,SAAAC,EAAA,uEAUuCC,KAAAA,CAAYC,YAAAA,CAAW,EAEvBD,CAAAA,KAAAA,CAAKE,KAAW,CAAA,EAiC7D,QAAAC,KAAA,EAxCQC,SAAA,CAAAL,CAAA,CAAAM,EAAA,SAAAC,YAAA,CAAAP,CAAA,GAAAQ,GAAA,qBAAAC,KAAA,CASP,SAAAC,kBAAA,CAAAA,CACEC,IAAAA,CAAAA,eAAAA,CAAAA,CAAAA,CAAAA,SAAAA,4BAAAA,IAAAA,OACGV,IAAAA,CAAKE,OACNF,IAAKW,CAAAA,KAAAA,CAAMC,YAAY,oBAAqBZ,CAAAA,IAAAA,CAAKE,MAEpD,EAUM,GAAAK,GAAA,UAAAC,KAAA,UAAAK,OAAA,CACL,CAAA,MAAOC,CAAAA,CAAI,CAAAC,eAAA,GAAAA,eAAA,CAAAC,sBAAA,6SASLhB,IAAKC,CAAAA,YAAAA,EAGZ,CAAA,KAAAM,GAAA,UAAAU,GAAA,CArCM,SAAAA,IAAA,CAAWC,CAChB,MAAO,CAACA,CAAAA,CACT,EAOD,MAdyCC,CAAAA,GAUGC,CAAA,CAAA,CAA3CC,CAAS,CAAA,CAAEC,IAAMC,CAAAA,MAAAA,CAAQC,OAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAmC1B,CAAA2B,CAAAA,SAAAA,CAAA,cAAA,CAAA,IAAA,EAAA,CAAA,CAE1BL,CAAA,CAAA,CAA3CC,CAAS,CAAA,CAAEC,IAAMC,CAAAA,MAAAA,CAAQC,OAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA4B1B,CAAA2B,CAAAA,SAAAA,CAAA,OAAA,CAAA,IAAA,EAAA,CAAA,CAAAC,OAAA,KAZpD5B,CAAqBsB,CAAAA,CAAAA,CAAA,CADjCO,CAAAA,CAAc,4BACF7B"}
1
+ {"version":3,"file":"nile-error-notification.cjs.js","sources":["../../../src/nile-error-notification/nile-error-notification.ts"],"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 CSSResultArray,\n TemplateResult,\n PropertyValues,\n} from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { styles } from './nile-error-notification.css';\n\n/**\n * Nile icon component.\n *\n * @tag nile-error-notification\n *\n */\n@customElement('nile-error-notification')\nexport class NileErrorNotification extends LitElement {\n /**\n * The styles for ErrorNotification\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 // Represents the error message to be displayed to the user.\n @property({ type: String, reflect: true }) errorMessage: string = '';\n\n @property({ type: String, reflect: true }) color: string = '';\n \n protected updated(_changedProperties: PropertyValues): void {\n if(_changedProperties.has('color')){\n this.style.setProperty('--indication-color',this.color)\n }\n }\n\n /* #endregion */\n\n /* #region Methods */\n\n /**\n * Render method\n * @slot This is a slot test\n */\n public render(): TemplateResult {\n return html`\n <div class=\"nile-error-notification\">\n <nile-icon\n name=\"info2\"\n size=\"14\"\n class=\"nile-error-notification__icon\"\n part=\"icon\"\n color=\"var(--indication-color)\"\n ></nile-icon>\n ${this.errorMessage}\n </div>\n `;\n }\n\n /* #endregion */\n}\n\nexport default NileErrorNotification;\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-error-notification': NileErrorNotification;\n }\n}\n"],"names":["NileErrorNotification","s","this","errorMessage","color","_this","_inherits","_r","_createClass","key","value","updated","_changedProperties","has","style","setProperty","render","html","_templateObject","_taggedTemplateLiteral","get","styles","LitElement","__decorate","property","type","String","reflect","prototype","_export","customElement"],"mappings":"6hHAwBaA,4BAAN,SAAAC,EAAA,uEAUuCC,KAAAA,CAAYC,YAAAA,CAAW,EAEvBD,CAAAA,KAAAA,CAAKE,KAAW,CAAA,EAgC7D,QAAAC,KAAA,EAvCQC,SAAA,CAAAL,CAAA,CAAAM,EAAA,SAAAC,YAAA,CAAAP,CAAA,GAAAQ,GAAA,WAAAC,KAAA,CASG,SAAAC,QAAQC,GACbA,CAAmBC,CAAAA,GAAAA,CAAI,UACxBX,IAAKY,CAAAA,KAAAA,CAAMC,YAAY,oBAAqBb,CAAAA,IAAAA,CAAKE,MAEpD,EAUM,GAAAK,GAAA,UAAAC,KAAA,UAAAM,OAAA,CACL,CAAA,MAAOC,CAAAA,CAAI,CAAAC,eAAA,GAAAA,eAAA,CAAAC,sBAAA,6SASLjB,IAAKC,CAAAA,YAAAA,EAGZ,CAAA,KAAAM,GAAA,UAAAW,GAAA,CApCM,SAAAA,IAAA,CAAWC,CAChB,MAAO,CAACA,CAAAA,CACT,EAOS,MAd+BC,CAAAA,GAUGC,CAAA,CAAA,CAA3CC,CAAS,CAAA,CAAEC,IAAMC,CAAAA,MAAAA,CAAQC,OAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAmC3B,CAAA4B,CAAAA,SAAAA,CAAA,cAAA,CAAA,IAAA,EAAA,CAAA,CAE1BL,CAAA,CAAA,CAA3CC,CAAS,CAAA,CAAEC,IAAMC,CAAAA,MAAAA,CAAQC,OAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA4B3B,CAAA4B,CAAAA,SAAAA,CAAA,OAAA,CAAA,IAAA,EAAA,CAAA,CAAAC,OAAA,KAZpD7B,CAAqBuB,CAAAA,CAAAA,CAAA,CADjCO,CAAAA,CAAc,4BACF9B"}
@@ -1,4 +1,4 @@
1
- import{__decorate as i}from"tslib";import{LitElement as r,html as o}from"lit";import{property as t,customElement as e}from"lit/decorators.js";import{s as n}from"./nile-error-notification.css.esm.js";let s=class extends r{constructor(){super(...arguments),this.errorMessage="",this.color=""}static get styles(){return[n]}connectedCallback(){super.connectedCallback(),this.color&&this.style.setProperty("--indication-color",this.color)}render(){return o`
1
+ import{__decorate as i}from"tslib";import{LitElement as r,html as o}from"lit";import{property as t,customElement as e}from"lit/decorators.js";import{s as n}from"./nile-error-notification.css.esm.js";let s=class extends r{constructor(){super(...arguments),this.errorMessage="",this.color=""}static get styles(){return[n]}updated(i){i.has("color")&&this.style.setProperty("--indication-color",this.color)}render(){return o`
2
2
  <div class="nile-error-notification">
3
3
  <nile-icon
4
4
  name="info2"
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { CSSResultArray, TemplateResult, PropertyValueMap } from 'lit';
8
8
  import { EditorView } from 'codemirror';
9
- import { EditorState } from '@codemirror/state';
9
+ import { EditorState, Extension } from '@codemirror/state';
10
10
  import { CompletionContext, CompletionResult } from '@codemirror/autocomplete';
11
11
  import NileElement from '../internal/nile-element';
12
12
  /**
@@ -19,13 +19,15 @@ export declare class NileCodeEditor extends NileElement {
19
19
  codeEditor: HTMLInputElement;
20
20
  value: string;
21
21
  expandIcon: string;
22
+ placeholder: string;
22
23
  customAutoCompletions: object | any;
23
- language: 'javascript' | 'sql' | 'json';
24
+ customCompletionsPaths: string[];
25
+ language: 'javascript' | 'sql' | 'json' | 'html';
24
26
  errorMessage: string;
25
27
  error: boolean;
26
28
  noborder: boolean;
27
29
  multiline: boolean;
28
- suggestionBracketSupport: boolean;
30
+ allowVariableInCustomSuggestion: boolean;
29
31
  lineNumbers: boolean;
30
32
  lineNumbersMultiline: boolean;
31
33
  hasScroller: boolean;
@@ -39,6 +41,7 @@ export declare class NileCodeEditor extends NileElement {
39
41
  private restrictSingleLineComp;
40
42
  private readOnlyComp;
41
43
  private customCompletionComp;
44
+ private placeholderComp;
42
45
  /**
43
46
  * The styles for CodeEditor
44
47
  * @remarks If you are extending this class you can extend the base styles with super. Eg `return [super(), myCustomStyles]`
@@ -51,21 +54,35 @@ export declare class NileCodeEditor extends NileElement {
51
54
  render(): TemplateResult;
52
55
  createNewView(emitEvent?: boolean): void;
53
56
  createState(): EditorState;
54
- singleLineMultiLineToggle(): void;
55
- convertToSingleLine(code: any): any;
57
+ customAutocomplete: (context: CompletionContext) => CompletionResult | null;
58
+ getNestedSuggestions(context: CompletionContext, textBeforeCursor: string, baseTextAfterSeperation: string): {
59
+ from: number;
60
+ options: {
61
+ label: string;
62
+ type: string;
63
+ info: string;
64
+ apply: string;
65
+ boost: number;
66
+ }[];
67
+ } | null;
68
+ getTopLevelSuggestions(context: CompletionContext, textBeforeCursor: string): {
69
+ from: number;
70
+ options: {
71
+ label: string;
72
+ type: string;
73
+ apply: string;
74
+ boost: number;
75
+ }[];
76
+ } | null;
56
77
  emitAfterTimeout(value: any): void;
57
78
  insertBetweenCode: (text: string) => void;
58
- getLineNumbersExension(): import("@codemirror/state").Extension;
59
- getLanguageExtension(): import("@codemirror/language").LanguageSupport;
60
- getReadOnlyExtension(): import("@codemirror/state").Extension;
61
- getSingleLineExtension(): import("@codemirror/state").Extension;
62
- restrictSingleLine(): import("@codemirror/state").Extension;
63
- emitNileExpand(): void;
64
- customAutocomplete: (context: CompletionContext) => CompletionResult | null;
65
- resolveNestedProperties: (obj: any, keys: any[]) => any;
66
- parsePath(text: string): string[] | null;
67
- isValidPath(path: string): boolean;
68
- splitStringAtLastSeparator(input: string): string[];
79
+ singleLineMultiLineToggle(): void;
80
+ getLineNumbersExension(): Extension;
81
+ getLanguageExtension(): Extension;
82
+ getReadOnlyExtension(): Extension;
83
+ getSingleLineExtension(): Extension;
84
+ getPlaceholderExtension(): Extension;
85
+ restrictSingleLine(): Extension;
69
86
  }
70
87
  export default NileCodeEditor;
71
88
  declare global {
@@ -9,11 +9,13 @@ import { html, } from 'lit';
9
9
  import { customElement, query, property } from 'lit/decorators.js';
10
10
  import { styles } from './nile-code-editor.css';
11
11
  import { EditorView } from 'codemirror';
12
- import { Compartment, EditorState, } from '@codemirror/state';
12
+ import { placeholder } from '@codemirror/view';
13
+ import { Compartment, EditorState } from '@codemirror/state';
13
14
  import { lineNumbers } from '@codemirror/view';
14
- import { javascript, javascriptLanguage, scopeCompletionSource, } from '@codemirror/lang-javascript';
15
+ import { javascript, javascriptLanguage, } from '@codemirror/lang-javascript';
15
16
  import { sql } from '@codemirror/lang-sql';
16
17
  import { json } from '@codemirror/lang-json';
18
+ import { html as htmlLang } from '@codemirror/lang-html';
17
19
  import { autocompletion } from '@codemirror/autocomplete';
18
20
  import NileElement from '../internal/nile-element';
19
21
  import { basicSetup } from './extensionSetup';
@@ -32,13 +34,15 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
32
34
  super(...arguments);
33
35
  this.value = '';
34
36
  this.expandIcon = "expand-2";
37
+ this.placeholder = "";
35
38
  this.customAutoCompletions = {};
39
+ this.customCompletionsPaths = [];
36
40
  this.language = 'javascript';
37
41
  this.errorMessage = '';
38
42
  this.error = false;
39
43
  this.noborder = false;
40
44
  this.multiline = false;
41
- this.suggestionBracketSupport = false;
45
+ this.allowVariableInCustomSuggestion = false;
42
46
  this.lineNumbers = false;
43
47
  this.lineNumbersMultiline = true;
44
48
  this.hasScroller = true;
@@ -51,6 +55,15 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
51
55
  this.restrictSingleLineComp = new Compartment();
52
56
  this.readOnlyComp = new Compartment();
53
57
  this.customCompletionComp = new Compartment();
58
+ this.placeholderComp = new Compartment();
59
+ this.customAutocomplete = (context) => {
60
+ // Getting the valid last line, last text from the code editor
61
+ const text = context.state.doc.sliceString(0, context.pos);
62
+ const lastWord = text.split('\n').at(-1)?.split(' ').at(-1) || '';
63
+ const [textBeforeCursor, baseTextAfterSeperation] = splitStringAtLastSeparator(lastWord);
64
+ return this.getNestedSuggestions(context, textBeforeCursor, baseTextAfterSeperation)
65
+ || this.getTopLevelSuggestions(context, textBeforeCursor);
66
+ };
54
67
  this.insertBetweenCode = (text) => {
55
68
  const transaction = this.view.state.changeByRange(range => {
56
69
  const { from, to } = range;
@@ -58,68 +71,6 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
58
71
  });
59
72
  this.view.dispatch(transaction);
60
73
  };
61
- this.customAutocomplete = (context) => {
62
- // Getting the valid last line, last text from the code editor
63
- let text = context.state.doc.sliceString(0, context.pos);
64
- const [textBeforeCursor, baseTextAfterSeperation] = this.splitStringAtLastSeparator(text.split('\n').at(-1)?.split(' ').at(-1) + '');
65
- const textAfterSeperation = baseTextAfterSeperation.replace(/["'\[]/g, '');
66
- const isSuggestionString = textAfterSeperation != baseTextAfterSeperation;
67
- if (!this.isValidPath(textBeforeCursor))
68
- return { from: context.pos, options: [] };
69
- if (['.', '['].includes(textBeforeCursor[textBeforeCursor.length - 1])) {
70
- // Parse the path for dot or bracket notation
71
- const path = this.parsePath(textBeforeCursor);
72
- if (path) {
73
- let resolved = this.resolveNestedProperties(this.customAutoCompletions, path);
74
- if (textAfterSeperation) {
75
- const obj = {};
76
- Object.keys(resolved).forEach((key) => {
77
- if (key.toLowerCase().startsWith(textAfterSeperation.toLowerCase())) {
78
- obj[key] = resolved[key];
79
- }
80
- });
81
- resolved = obj;
82
- }
83
- // If resolved is an object, provide its keys as suggestions
84
- if (resolved && typeof resolved === 'object') {
85
- return {
86
- from: context.pos - textAfterSeperation.length,
87
- options: Object.keys(resolved).map((key) => ({
88
- label: key,
89
- type: 'property',
90
- info: `Key of ${path[path.length - 1]}`,
91
- apply: key,
92
- boost: 999
93
- })),
94
- };
95
- }
96
- }
97
- }
98
- // Match for top-level object suggestions, e.g., "a"
99
- const baseMatch = textBeforeCursor.match(/([a-zA-Z_$][\w$]*)$/);
100
- if (baseMatch) {
101
- const optionsList = Object.keys(this.customAutoCompletions).filter(key => key.toLowerCase().startsWith(textBeforeCursor.toLowerCase()));
102
- return {
103
- from: context.pos - baseMatch[1].length,
104
- options: optionsList.map((key) => ({
105
- label: key,
106
- type: 'property',
107
- apply: key,
108
- boost: 999
109
- }))
110
- };
111
- }
112
- // Default to an empty list if no match
113
- return { from: context.pos, options: [] };
114
- };
115
- this.resolveNestedProperties = (obj, keys) => {
116
- return keys.reduce((acc, key) => {
117
- if (acc && typeof acc === 'object') {
118
- return acc[key];
119
- }
120
- return null;
121
- }, obj);
122
- };
123
74
  /* #endregion */
124
75
  }
125
76
  /**
@@ -168,6 +119,13 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
168
119
  ]
169
120
  });
170
121
  }
122
+ if (changedProperties.has('placeholder')) {
123
+ this.view.dispatch({
124
+ effects: [
125
+ this.placeholderComp.reconfigure(this.getPlaceholderExtension()),
126
+ ]
127
+ });
128
+ }
171
129
  if (changedProperties.has('lineNumbers') || changedProperties.has('lineNumbersMultiline')) {
172
130
  this.view.dispatch({
173
131
  effects: [
@@ -175,11 +133,11 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
175
133
  ]
176
134
  });
177
135
  }
178
- if (changedProperties.has('customAutoCompletions') || changedProperties.has('suggestionBracketSupport')) {
136
+ if (changedProperties.has('customAutoCompletions') || changedProperties.has('customCompletionsPaths')) {
179
137
  this.view.dispatch({
180
138
  effects: [
181
139
  this.customCompletionComp.reconfigure(javascriptLanguage.data.of({
182
- autocomplete: this.suggestionBracketSupport ? this.customAutocomplete : scopeCompletionSource(this.customAutoCompletions),
140
+ autocomplete: this.customAutocomplete
183
141
  }))
184
142
  ]
185
143
  });
@@ -200,15 +158,15 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
200
158
  'no-scroller': noScrollbar
201
159
  })}
202
160
  >
203
- ${this.expandable
161
+ ${this.expandable
204
162
  ? html `
205
- <nile-icon
206
- name="${this.expandIcon}"
207
- class="code-editor__icon__container"
208
- size="16"
209
- color="black"
210
- @click="${(e) => this.emitNileExpand()}"
211
- ></nile-icon>`
163
+ <nile-icon
164
+ name="${this.expandIcon}"
165
+ class="code-editor__icon__container"
166
+ size="16"
167
+ color="black"
168
+ @click="${(e) => this.emit('nile-expand')}"
169
+ ></nile-icon>`
212
170
  : ''}
213
171
  </div>
214
172
  ${hasErrorMessage
@@ -234,12 +192,13 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
234
192
  const lineNumbersExtension = this.lineNumbersComp.of(this.getLineNumbersExension());
235
193
  const readOnlyExtension = this.readOnlyComp.of(this.getReadOnlyExtension());
236
194
  const restrictSingleLineExtension = this.restrictSingleLineComp.of(this.getSingleLineExtension());
195
+ const placeholderExtension = this.placeholderComp.of(this.getPlaceholderExtension());
196
+ const language = this.getLanguageExtension();
237
197
  const customAutoCompletions = this.customCompletionComp.of(javascriptLanguage.data.of({
238
- autocomplete: this.suggestionBracketSupport ? this.customAutocomplete : scopeCompletionSource(this.customAutoCompletions),
198
+ autocomplete: this.customAutocomplete
239
199
  }));
240
- const language = this.getLanguageExtension();
241
200
  this.viewState = EditorState.create({
242
- doc: !this.multiline ? this.convertToSingleLine(this.value) : this.value,
201
+ doc: !this.multiline ? convertToSingleLine(this.value) : this.value,
243
202
  extensions: [
244
203
  basicSetup({
245
204
  highlightActiveLine: false,
@@ -249,6 +208,7 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
249
208
  readOnlyExtension,
250
209
  restrictSingleLineExtension,
251
210
  customAutoCompletions,
211
+ placeholderExtension,
252
212
  autocompletion(),
253
213
  language,
254
214
  EditorView.theme(Theme),
@@ -265,28 +225,85 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
265
225
  });
266
226
  return this.viewState;
267
227
  }
228
+ getNestedSuggestions(context, textBeforeCursor, baseTextAfterSeperation) {
229
+ // Return early if not a valid path or not ending with . or [
230
+ if (!isValidPath(textBeforeCursor) || !['.', '['].includes(textBeforeCursor.at(-1))) {
231
+ return null;
232
+ }
233
+ const path = parsePath(textBeforeCursor);
234
+ if (!path)
235
+ return null;
236
+ const textAfterSeperation = baseTextAfterSeperation.replace(/["'\[]/g, '');
237
+ const isInString = textAfterSeperation !== baseTextAfterSeperation;
238
+ const isBracket = textBeforeCursor.at(-1) === '[';
239
+ // Return null if we're in a string after a dot
240
+ if (textBeforeCursor.at(-1) === '.' && isInString)
241
+ return null;
242
+ // Get nested properties and filter by text after separation if it exists
243
+ let resolved = resolveNestedProperties(this.customAutoCompletions, path);
244
+ if (!resolved || typeof resolved !== 'object')
245
+ return null;
246
+ if (textAfterSeperation) {
247
+ resolved = Object.fromEntries(Object.entries(resolved).filter(([key]) => key.toLowerCase().startsWith(textAfterSeperation.toLowerCase())));
248
+ }
249
+ return {
250
+ from: context.pos - textAfterSeperation.length,
251
+ options: Object.keys(resolved).map(key => ({
252
+ label: key,
253
+ type: 'property',
254
+ info: `Key of ${path[path.length - 1]}`,
255
+ apply: !this.allowVariableInCustomSuggestion && (isBracket && !isInString)
256
+ ? `'${key}'`
257
+ : key,
258
+ boost: 999
259
+ }))
260
+ };
261
+ }
262
+ getTopLevelSuggestions(context, textBeforeCursor) {
263
+ const baseMatch = textBeforeCursor.match(/([a-zA-Z_$][\w$]*)$/);
264
+ if (!baseMatch)
265
+ return null;
266
+ const optionsList = Object.keys(this.customAutoCompletions).filter(key => Object.keys(this.customAutoCompletions[key]).length &&
267
+ key.toLowerCase().startsWith(textBeforeCursor.toLowerCase()));
268
+ const options = optionsList.map((key) => ({
269
+ label: key,
270
+ type: 'property',
271
+ apply: key,
272
+ boost: 999
273
+ }));
274
+ if (this.customCompletionsPaths.length) {
275
+ this.customCompletionsPaths
276
+ .filter(path => path.toLocaleLowerCase().includes(textBeforeCursor.toLocaleLowerCase()))
277
+ .map(path => {
278
+ options.push({
279
+ label: '' + path,
280
+ type: 'property',
281
+ apply: '' + path,
282
+ boost: 998
283
+ });
284
+ });
285
+ }
286
+ return {
287
+ from: context.pos - baseMatch[1].length,
288
+ options: options
289
+ };
290
+ }
291
+ emitAfterTimeout(value) {
292
+ if (this.timeOut)
293
+ clearTimeout(this.timeOut);
294
+ this.timeOut = setTimeout(() => this.emit('nile-change', value, false), TIME_OUT_DURATION);
295
+ }
268
296
  singleLineMultiLineToggle() {
269
297
  this.view.dispatch({
270
298
  changes: {
271
299
  from: 0,
272
300
  to: this.view.state.doc.length,
273
301
  insert: !this.multiline
274
- ? this.convertToSingleLine(this.value)
302
+ ? convertToSingleLine(this.value)
275
303
  : this.value,
276
304
  },
277
305
  });
278
306
  }
279
- convertToSingleLine(code) {
280
- if (!code)
281
- return '';
282
- // Remove line breaks and unnecessary whitespace
283
- return code.replace(/\s+/g, ' ').trim();
284
- }
285
- emitAfterTimeout(value) {
286
- if (this.timeOut)
287
- clearTimeout(this.timeOut);
288
- this.timeOut = setTimeout(() => this.emit('nile-change', value, false), TIME_OUT_DURATION);
289
- }
290
307
  //EXTENSION CONFIGURATIONS
291
308
  getLineNumbersExension() {
292
309
  return (!this.multiline && this.lineNumbers) || (this.multiline && this.lineNumbersMultiline) ? lineNumbers() : [];
@@ -297,6 +314,8 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
297
314
  return sql();
298
315
  case 'json':
299
316
  return json();
317
+ case 'html':
318
+ return htmlLang();
300
319
  default:
301
320
  return javascript();
302
321
  }
@@ -307,45 +326,12 @@ let NileCodeEditor = class NileCodeEditor extends NileElement {
307
326
  getSingleLineExtension() {
308
327
  return !this.multiline ? EditorState.transactionFilter.of(tr => tr.newDoc.lines > 1 ? [] : tr) : [];
309
328
  }
329
+ getPlaceholderExtension() {
330
+ return this.placeholder ? placeholder(this.placeholder) : [];
331
+ }
310
332
  restrictSingleLine() {
311
333
  return EditorState.transactionFilter.of(tr => tr.newDoc.lines > 1 ? [] : tr);
312
334
  }
313
- emitNileExpand() {
314
- this.emit('nile-expand', { expand: true }, false);
315
- }
316
- parsePath(text) {
317
- const regex = /([a-zA-Z_$][\w$]*)(\[(?:[^\]]+)\]|\.[a-zA-Z_$][\w$]*)*/g;
318
- const matches = [...text.matchAll(regex)];
319
- if (matches.length > 0) {
320
- const base = matches[0][1]; // The base object name
321
- const keys = [base];
322
- // Extract keys from dot or bracket notation
323
- const pathMatches = text.match(/\[(.*?)\]|\.(\w+)/g) || [];
324
- for (const match of pathMatches) {
325
- if (match.startsWith('[')) {
326
- keys.push(match.slice(1, -1).replace(/['"]/g, '')); // Remove brackets and quotes
327
- }
328
- else if (match.startsWith('.')) {
329
- keys.push(match.slice(1));
330
- }
331
- }
332
- return keys;
333
- }
334
- return null;
335
- }
336
- ;
337
- isValidPath(path) {
338
- // Regex to validate the format of the string
339
- const regex = /^([a-zA-Z_$][\w$]*)(\.[a-zA-Z_$][\w$]*|\[\s*(['"]?[a-zA-Z0-9_$]*['"]?)\s*\])*([\.\[])?$/;
340
- // Test the string against the regex
341
- return regex.test(path);
342
- }
343
- splitStringAtLastSeparator(input) {
344
- const lastSeparatorIndex = Math.max(input.lastIndexOf('.'), input.lastIndexOf('['));
345
- if (lastSeparatorIndex === -1)
346
- return [input, ''];
347
- return [input.slice(0, lastSeparatorIndex + 1), input.slice(lastSeparatorIndex + 1)];
348
- }
349
335
  };
350
336
  __decorate([
351
337
  query('.code-mirror')
@@ -356,9 +342,15 @@ __decorate([
356
342
  __decorate([
357
343
  property({ type: String, reflect: true, attribute: true })
358
344
  ], NileCodeEditor.prototype, "expandIcon", void 0);
345
+ __decorate([
346
+ property({ type: String, reflect: true, attribute: true })
347
+ ], NileCodeEditor.prototype, "placeholder", void 0);
359
348
  __decorate([
360
349
  property({ type: Object, reflect: true, attribute: true })
361
350
  ], NileCodeEditor.prototype, "customAutoCompletions", void 0);
351
+ __decorate([
352
+ property({ type: Array, reflect: true, attribute: true })
353
+ ], NileCodeEditor.prototype, "customCompletionsPaths", void 0);
362
354
  __decorate([
363
355
  property({ type: String, reflect: true, attribute: true })
364
356
  ], NileCodeEditor.prototype, "language", void 0);
@@ -376,7 +368,7 @@ __decorate([
376
368
  ], NileCodeEditor.prototype, "multiline", void 0);
377
369
  __decorate([
378
370
  property({ type: Boolean, reflect: true, attribute: true })
379
- ], NileCodeEditor.prototype, "suggestionBracketSupport", void 0);
371
+ ], NileCodeEditor.prototype, "allowVariableInCustomSuggestion", void 0);
380
372
  __decorate([
381
373
  property({ type: Boolean, reflect: true, attribute: true })
382
374
  ], NileCodeEditor.prototype, "lineNumbers", void 0);
@@ -400,4 +392,52 @@ NileCodeEditor = __decorate([
400
392
  ], NileCodeEditor);
401
393
  export { NileCodeEditor };
402
394
  export default NileCodeEditor;
395
+ function parsePath(text) {
396
+ const regex = /([a-zA-Z_$][\w$]*)(\[(?:[^\]]+)\]|\.[a-zA-Z_$][\w$]*)*/g;
397
+ const matches = [...text.matchAll(regex)];
398
+ if (matches.length > 0) {
399
+ const base = matches[0][1]; // The base object name
400
+ const keys = [base];
401
+ // Extract keys from dot or bracket notation
402
+ const pathMatches = text.match(/\[(.*?)\]|\.(\w+)/g) || [];
403
+ for (const match of pathMatches) {
404
+ if (match.startsWith('[')) {
405
+ keys.push(match.slice(1, -1).replace(/['"]/g, '')); // Remove brackets and quotes
406
+ }
407
+ else if (match.startsWith('.')) {
408
+ keys.push(match.slice(1));
409
+ }
410
+ }
411
+ return keys;
412
+ }
413
+ return null;
414
+ }
415
+ ;
416
+ function splitStringAtLastSeparator(input) {
417
+ const lastSeparatorIndex = Math.max(input.lastIndexOf('.'), input.lastIndexOf('['));
418
+ if (lastSeparatorIndex === -1)
419
+ return [input, ''];
420
+ return [input.slice(0, lastSeparatorIndex + 1), input.slice(lastSeparatorIndex + 1)];
421
+ }
422
+ function resolveNestedProperties(obj, keys) {
423
+ return keys.reduce((acc, key) => {
424
+ if (acc && typeof acc === 'object') {
425
+ return acc[key];
426
+ }
427
+ return null;
428
+ }, obj);
429
+ }
430
+ ;
431
+ function isValidPath(path) {
432
+ // Regex to validate the format of the string
433
+ const regex = /^([a-zA-Z_$][\w$]*)(\.[a-zA-Z_$][\w$]*|\[\s*(['"]?[a-zA-Z0-9_$]*['"]?)\s*\])*([\.\[])?$/;
434
+ // Test the string against the regex
435
+ return regex.test(path);
436
+ }
437
+ function convertToSingleLine(code) {
438
+ if (!code)
439
+ return '';
440
+ // Remove line breaks and unnecessary whitespace
441
+ return code.replace(/\s+/g, ' ').trim();
442
+ }
403
443
  //# sourceMappingURL=nile-code-editor.js.map