@aquera/nile-elements 0.1.4 → 0.1.5
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-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 +1 -1
- package/dist/src/nile-form-help-text/nile-form-help-text.js +1 -1
- 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-form-help-text/nile-form-help-text.ts +1 -1
package/README.md
CHANGED
@@ -79,6 +79,9 @@ To run a local development server that serves the basic demo located in `demo/in
|
|
79
79
|
|
80
80
|
In this section, you can find the updates for each release of `nile-elements`. It's a good practice to maintain detailed release notes to help users and developers understand what changes have been made from one version to another and how these changes might affect their projects.
|
81
81
|
|
82
|
+
#### Version 0.1.5
|
83
|
+
- Nile Form Help Text - Slot content passing fixes
|
84
|
+
|
82
85
|
#### Version 0.1.4
|
83
86
|
- Nile Tour - Restructure and New theme
|
84
87
|
|
@@ -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-form-help-text.css.cjs.js"],function(_export,_context){"use strict";var t,e,i,s,o,r,n,_templateObject,_templateObject2,l;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){t=_tslib.__decorate;},function(_lit){e=_lit.LitElement;i=_lit.html;},function(_litDecoratorsJs){s=_litDecoratorsJs.property;o=_litDecoratorsJs.query;r=_litDecoratorsJs.customElement;},function(_nileFormHelpTextCssCjsJs){n=_nileFormHelpTextCssCjsJs.s;}],execute:function execute(){_export("N",l=/*#__PURE__*/function(_e){function l(){var _this;_classCallCheck(this,l);_this=_callSuper(this,l,arguments),_this.isExpanded=!1,_this.fullText="",_this.textLimit=47,_this.displayedText="";return _this;}_inherits(l,_e);return _createClass(l,[{key:"connectedCallback",value:function connectedCallback(){var _this2=this;_get(_getPrototypeOf(l.prototype),"connectedCallback",this).call(this),requestAnimationFrame(function(){var _this2$slotElement;(_this2$slotElement=_this2.slotElement)===null||_this2$slotElement===void 0||_this2$slotElement.addEventListener("slotchange",_this2.handleSlotChange.bind(_this2));});}},{key:"firstUpdated",value:function firstUpdated(){this.handleSlotChange();}},{key:"handleSlotChange",value:function handleSlotChange(){var t=this.slotElement.assignedNodes({flatten:!0}).map(function(t){return t.textContent;}).join("");this.fullText=t.trim(),this.updateDisplayedText();}},{key:"toggleExpanded",value:function toggleExpanded(){this.isExpanded=!this.isExpanded,this.updateDisplayedText();}},{key:"updateDisplayedText",value:function updateDisplayedText(){if(this.isExpanded)this.displayedText=this.fullText;else{var _t=function(t,e){if(e<0||e>t.length)
|
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-form-help-text.css.cjs.js"],function(_export,_context){"use strict";var t,e,i,s,o,r,n,_templateObject,_templateObject2,l;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){t=_tslib.__decorate;},function(_lit){e=_lit.LitElement;i=_lit.html;},function(_litDecoratorsJs){s=_litDecoratorsJs.property;o=_litDecoratorsJs.query;r=_litDecoratorsJs.customElement;},function(_nileFormHelpTextCssCjsJs){n=_nileFormHelpTextCssCjsJs.s;}],execute:function execute(){_export("N",l=/*#__PURE__*/function(_e){function l(){var _this;_classCallCheck(this,l);_this=_callSuper(this,l,arguments),_this.isExpanded=!1,_this.fullText="",_this.textLimit=47,_this.displayedText="";return _this;}_inherits(l,_e);return _createClass(l,[{key:"connectedCallback",value:function connectedCallback(){var _this2=this;_get(_getPrototypeOf(l.prototype),"connectedCallback",this).call(this),requestAnimationFrame(function(){var _this2$slotElement;(_this2$slotElement=_this2.slotElement)===null||_this2$slotElement===void 0||_this2$slotElement.addEventListener("slotchange",_this2.handleSlotChange.bind(_this2));});}},{key:"firstUpdated",value:function firstUpdated(){this.handleSlotChange();}},{key:"handleSlotChange",value:function handleSlotChange(){var t=this.slotElement.assignedNodes({flatten:!0}).map(function(t){return t.textContent;}).join("");this.fullText=t.trim(),this.updateDisplayedText();}},{key:"toggleExpanded",value:function toggleExpanded(){this.isExpanded=!this.isExpanded,this.updateDisplayedText();}},{key:"updateDisplayedText",value:function updateDisplayedText(){if(this.isExpanded)this.displayedText=this.fullText;else{var _t=function(t,e){if(e<0||e>t.length)return e;if(" "!==t[e]&&0!==e&&e!==t.length){var _i2=e;for(;_i2>0&&" "!==t[_i2-1];)_i2--;var _s=e;for(;_s<t.length&&" "!==t[_s];)_s++;e=e-_i2<=_s-e?_i2:_s;}return e;}(this.fullText,this.textLimit),_e2=this.fullText.slice(0,_t),_i=this.fullText.length>_t?"...":"";this.displayedText="".concat(_e2).concat(_i);}}},{key:"render",value:function render(){var t=this.fullText.length>this.textLimit,e=this.isExpanded?"arrowup":"arrowdown";return i(_templateObject||(_templateObject=_taggedTemplateLiteral(["\n <div class=\"nile-form-help-text\" part=\"container\">\n <slot hidden>","</slot>\n <div part=\"text\">\n <span>","</span>\n ","\n </div>\n </div>\n "])),this.fullText,this.displayedText,t?i(_templateObject2||(_templateObject2=_taggedTemplateLiteral(["\n <span\n class=\"nile-form-help-text__more-button\"\n part=\"toggle-button\"\n @click=","\n >","\n <nile-icon color=\"#005EA6\" part=\"icon\" size=\"14\" name=\"","\"></nile-icon>\n </span>\n "])),this.toggleExpanded,this.isExpanded?"View Less":"View More",e):"");}}],[{key:"styles",get:function get(){return[n];}}]);}(e));t([s({type:Boolean,reflect:!0})],l.prototype,"isExpanded",void 0),t([s({type:String,reflect:!0})],l.prototype,"fullText",void 0),t([s({type:Number,reflect:!0})],l.prototype,"textLimit",void 0),t([s({type:String,reflect:!0})],l.prototype,"displayedText",void 0),t([o("slot")],l.prototype,"slotElement",void 0),_export("N",l=t([r("nile-form-help-text")],l));}};});
|
2
2
|
//# sourceMappingURL=nile-form-help-text.cjs.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"nile-form-help-text.cjs.js","sources":["../../../src/nile-form-help-text/nile-form-help-text.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 {LitElement, html, CSSResultArray, TemplateResult} from 'lit';\nimport { customElement, query, property } from 'lit/decorators.js';\nimport {styles} from './nile-form-help-text.css';\n\n/**\n * Nile icon component.\n *\n * @tag nile-form-help-text\n *\n */\n@customElement('nile-form-help-text')\nexport class NileFormHelpText extends LitElement {\n /**\n * The styles for FormHelpText\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 @property({ type: Boolean, reflect: true }) isExpanded: boolean = false;\n\n @property({ type: String, reflect: true }) fullText: string = '';\n\n @property({ type: Number, reflect: true }) textLimit: number = 47;\n\n @property({ type: String, reflect: true }) displayedText: string = '';\n\n @query('slot') slotElement!: HTMLSlotElement;\n\n connectedCallback() {\n super.connectedCallback();\n requestAnimationFrame(() => {\n this.slotElement?.addEventListener('slotchange', this.handleSlotChange.bind(this));\n });\n }\n\n firstUpdated() {\n this.handleSlotChange();\n }\n\n handleSlotChange() {\n const nodes = this.slotElement.assignedNodes({flatten: true});\n const textContent = nodes.map(node => node.textContent).join('');\n this.fullText = textContent.trim();\n this.updateDisplayedText()\n }\n\n toggleExpanded() {\n this.isExpanded = !this.isExpanded;\n this.updateDisplayedText()\n }\n\n updateDisplayedText() {\n if (this.isExpanded) {\n this.displayedText = this.fullText;\n } else {\n const validConcatNumber=concatSentence(this.fullText, this.textLimit)\n const truncatedText = this.fullText.slice(0, validConcatNumber);\n const ellipsis = this.fullText.length > validConcatNumber ? '...' : '';\n this.displayedText = `${truncatedText}${ellipsis}`;\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 const showMoreButton = this.fullText.length > this.textLimit;\n const iconName = this.isExpanded ? 'arrowup' : 'arrowdown';\n\n return html`\n <div class=\"nile-form-help-text\" part=\"container\">\n <slot hidden>${this.fullText}</slot>\n <div part=\"text\">\n <span>${this.displayedText}</span>\n ${showMoreButton ? html`\n <span\n class=\"nile-form-help-text__more-button\"\n part=\"toggle-button\"\n @click=${this.toggleExpanded}\n >${this.isExpanded ? 'View Less' : 'View More'}\n <nile-icon color=\"#005EA6\" part=\"icon\" size=\"14\" name=\"${iconName}\"></nile-icon>\n </span>\n ` : ''}\n </div>\n </div>\n `;\n }\n}\n\nexport default NileFormHelpText;\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-form-help-text': NileFormHelpText;\n }\n}\n\nfunction concatSentence(sentence:string, n:number) {\n if (n < 0 || n > sentence.length) {\n
|
1
|
+
{"version":3,"file":"nile-form-help-text.cjs.js","sources":["../../../src/nile-form-help-text/nile-form-help-text.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 {LitElement, html, CSSResultArray, TemplateResult} from 'lit';\nimport { customElement, query, property } from 'lit/decorators.js';\nimport {styles} from './nile-form-help-text.css';\n\n/**\n * Nile icon component.\n *\n * @tag nile-form-help-text\n *\n */\n@customElement('nile-form-help-text')\nexport class NileFormHelpText extends LitElement {\n /**\n * The styles for FormHelpText\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 @property({ type: Boolean, reflect: true }) isExpanded: boolean = false;\n\n @property({ type: String, reflect: true }) fullText: string = '';\n\n @property({ type: Number, reflect: true }) textLimit: number = 47;\n\n @property({ type: String, reflect: true }) displayedText: string = '';\n\n @query('slot') slotElement!: HTMLSlotElement;\n\n connectedCallback() {\n super.connectedCallback();\n requestAnimationFrame(() => {\n this.slotElement?.addEventListener('slotchange', this.handleSlotChange.bind(this));\n });\n }\n\n firstUpdated() {\n this.handleSlotChange();\n }\n\n handleSlotChange() {\n const nodes = this.slotElement.assignedNodes({flatten: true});\n const textContent = nodes.map(node => node.textContent).join('');\n this.fullText = textContent.trim();\n this.updateDisplayedText()\n }\n\n toggleExpanded() {\n this.isExpanded = !this.isExpanded;\n this.updateDisplayedText()\n }\n\n updateDisplayedText() {\n if (this.isExpanded) {\n this.displayedText = this.fullText;\n } else {\n const validConcatNumber=concatSentence(this.fullText, this.textLimit)\n const truncatedText = this.fullText.slice(0, validConcatNumber);\n const ellipsis = this.fullText.length > validConcatNumber ? '...' : '';\n this.displayedText = `${truncatedText}${ellipsis}`;\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 const showMoreButton = this.fullText.length > this.textLimit;\n const iconName = this.isExpanded ? 'arrowup' : 'arrowdown';\n\n return html`\n <div class=\"nile-form-help-text\" part=\"container\">\n <slot hidden>${this.fullText}</slot>\n <div part=\"text\">\n <span>${this.displayedText}</span>\n ${showMoreButton ? html`\n <span\n class=\"nile-form-help-text__more-button\"\n part=\"toggle-button\"\n @click=${this.toggleExpanded}\n >${this.isExpanded ? 'View Less' : 'View More'}\n <nile-icon color=\"#005EA6\" part=\"icon\" size=\"14\" name=\"${iconName}\"></nile-icon>\n </span>\n ` : ''}\n </div>\n </div>\n `;\n }\n}\n\nexport default NileFormHelpText;\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-form-help-text': NileFormHelpText;\n }\n}\n\nfunction concatSentence(sentence:string, n:number) {\n if (n < 0 || n > sentence.length) {\n return n;\n }\n\n // Adjust n if it falls in the middle of a word\n if (sentence[n] !== \" \" && n !== 0 && n !== sentence.length) {\n // Move left until the start of the word or the beginning of the sentence\n let left = n;\n while (left > 0 && sentence[left - 1] !== \" \") {\n left--;\n }\n\n // Move right until the end of the word or the end of the sentence\n let right = n;\n while (right < sentence.length && sentence[right] !== \" \") {\n right++;\n }\n\n // Adjust n to the closer boundary\n n = (n - left <= right - n) ? left : right;\n }\n\n // Return the substring from the start to the adjusted n\n return n;\n}\n"],"names":["NileFormHelpText","_e","l","constructor","this","isExpanded","fullText","textLimit","displayedText","_this","_inherits","_createClass","key","value","connectedCallback","super","requestAnimationFrame","slotElement","addEventListener","handleSlotChange","bind","firstUpdated","textContent","assignedNodes","flatten","map","node","join","trim","updateDisplayedText","toggleExpanded","validConcatNumber","sentence","n","length","left","right","concatSentence","truncatedText","slice","ellipsis","render","showMoreButton","iconName","html","_templateObject","_taggedTemplateLiteral","_templateObject2","get","styles","LitElement","__decorate","property","type","Boolean","reflect","prototype","String","Number","query","_export","customElement"],"mappings":"imIAkBaA,CAAN,uBAAAC,EAAA,EAAA,SAAAC,EAAA,CAAAC,KAAAA,KAAAA,CAAAA,eAAAA,MAAAA,CAAAA,mCASwCC,EAAAA,KAAAA,CAAUC,UAAY,CAAA,CAAA,CAAA,CAEvBD,KAAAA,CAAQE,QAAAA,CAAW,GAEnBF,KAAAA,CAASG,SAAAA,CAAW,GAEpBH,KAAAA,CAAaI,aAAAA,CAAW,EAoErE,QAAAC,KAAA,EA9EQC,SAAA,CAAAR,CAAA,CAAAD,EAAA,SAAAU,YAAA,CAAAT,CAAA,GAAAU,GAAA,qBAAAC,KAAA,CAcP,SAAAC,kBAAA,kBACEC,IAAAA,CAAAA,eAAAA,CAAAA,CAAAA,CAAAA,SAAAA,4BAAAA,IAAAA,OACAC,sBAAsB,UACpBZ,KAAAA,kBAAAA,CAAAA,CAAAA,kBAAAA,CAAAA,MAAAA,CAAKa,WAAaC,UAAAA,kBAAAA,WAAlBd,kBAAAA,CAAkBc,gBAAAA,CAAiB,YAAcd,CAAAA,MAAAA,CAAKe,iBAAiBC,IAAKhB,CAAAA,MAAAA,CAAAA,CAAM,GAErF,EAED,GAAA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,IAAA,EAAA,CAAA,CAE7BL,CAAA,CAAA,CAA3CC,CAAS,CAAA,CAAEC,IAAMI,CAAAA,MAAAA,CAAQF,OAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA+BvD,CAAAwD,CAAAA,SAAAA,CAAA,UAAA,CAAA,IAAA,EAAA,CAAA,CAEtBL,CAAA,CAAA,CAA3CC,CAAS,CAAA,CAAEC,IAAMK,CAAAA,MAAAA,CAAQH,OAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAgCvD,CAAAwD,CAAAA,SAAAA,CAAA,WAAA,CAAA,IAAA,EAAA,CAAA,CAEvBL,CAAA,CAAA,CAA3CC,CAAS,CAAA,CAAEC,IAAMI,CAAAA,MAAAA,CAAQF,OAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAoCvD,CAAAwD,CAAAA,SAAAA,CAAA,eAAA,CAAA,IAAA,EAAA,CAAA,CAExDL,CAAA,CAAA,CAAdQ,CAAM,CAAA,MAAA,CAAA,CAAA,CAAsC3D,CAAAwD,CAAAA,SAAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,CAAAI,OAAA,KAjBlC5D,CAAgBmD,CAAAA,CAAAA,CAAA,CAD5BU,CAAAA,CAAc,wBACF7D"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__decorate as t}from"tslib";import{LitElement as e,html as i}from"lit";import{property as s,query as o,customElement as r}from"lit/decorators.js";import{s as n}from"./nile-form-help-text.css.esm.js";let l=class extends e{constructor(){super(...arguments),this.isExpanded=!1,this.fullText="",this.textLimit=47,this.displayedText=""}static get styles(){return[n]}connectedCallback(){super.connectedCallback(),requestAnimationFrame((()=>{this.slotElement?.addEventListener("slotchange",this.handleSlotChange.bind(this))}))}firstUpdated(){this.handleSlotChange()}handleSlotChange(){const t=this.slotElement.assignedNodes({flatten:!0}).map((t=>t.textContent)).join("");this.fullText=t.trim(),this.updateDisplayedText()}toggleExpanded(){this.isExpanded=!this.isExpanded,this.updateDisplayedText()}updateDisplayedText(){if(this.isExpanded)this.displayedText=this.fullText;else{const t=function(t,e){if(e<0||e>t.length)
|
1
|
+
import{__decorate as t}from"tslib";import{LitElement as e,html as i}from"lit";import{property as s,query as o,customElement as r}from"lit/decorators.js";import{s as n}from"./nile-form-help-text.css.esm.js";let l=class extends e{constructor(){super(...arguments),this.isExpanded=!1,this.fullText="",this.textLimit=47,this.displayedText=""}static get styles(){return[n]}connectedCallback(){super.connectedCallback(),requestAnimationFrame((()=>{this.slotElement?.addEventListener("slotchange",this.handleSlotChange.bind(this))}))}firstUpdated(){this.handleSlotChange()}handleSlotChange(){const t=this.slotElement.assignedNodes({flatten:!0}).map((t=>t.textContent)).join("");this.fullText=t.trim(),this.updateDisplayedText()}toggleExpanded(){this.isExpanded=!this.isExpanded,this.updateDisplayedText()}updateDisplayedText(){if(this.isExpanded)this.displayedText=this.fullText;else{const t=function(t,e){if(e<0||e>t.length)return e;if(" "!==t[e]&&0!==e&&e!==t.length){let i=e;for(;i>0&&" "!==t[i-1];)i--;let s=e;for(;s<t.length&&" "!==t[s];)s++;e=e-i<=s-e?i:s}return e}(this.fullText,this.textLimit),e=this.fullText.slice(0,t),i=this.fullText.length>t?"...":"";this.displayedText=`${e}${i}`}}render(){const t=this.fullText.length>this.textLimit,e=this.isExpanded?"arrowup":"arrowdown";return i`
|
2
2
|
<div class="nile-form-help-text" part="container">
|
3
3
|
<slot hidden>${this.fullText}</slot>
|
4
4
|
<div part="text">
|
@@ -109,7 +109,7 @@ export { NileFormHelpText };
|
|
109
109
|
export default NileFormHelpText;
|
110
110
|
function concatSentence(sentence, n) {
|
111
111
|
if (n < 0 || n > sentence.length) {
|
112
|
-
|
112
|
+
return n;
|
113
113
|
}
|
114
114
|
// Adjust n if it falls in the middle of a word
|
115
115
|
if (sentence[n] !== " " && n !== 0 && n !== sentence.length) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"nile-form-help-text.js","sourceRoot":"","sources":["../../../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C,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;QACjC,OAAO,CAAC,CAAC;IACX,CAAC;IAED,+CAA+C;IAC/C,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC5D,yEAAyE;QACzE,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,OAAO,IAAI,GAAG,CAAC,IAAI,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAC9C,IAAI,EAAE,CAAC;QACT,CAAC;QAED,kEAAkE;QAClE,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,OAAO,KAAK,GAAG,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC;YAC1D,KAAK,EAAE,CAAC;QACV,CAAC;QAED,kCAAkC;QAClC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7C,CAAC;IAED,wDAAwD;IACxD,OAAO,CAAC,CAAC;AACX,CAAC","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 {LitElement, html, CSSResultArray, TemplateResult} from 'lit';\nimport { customElement, query, property } from 'lit/decorators.js';\nimport {styles} from './nile-form-help-text.css';\n\n/**\n * Nile icon component.\n *\n * @tag nile-form-help-text\n *\n */\n@customElement('nile-form-help-text')\nexport class NileFormHelpText extends LitElement {\n /**\n * The styles for FormHelpText\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 @property({ type: Boolean, reflect: true }) isExpanded: boolean = false;\n\n @property({ type: String, reflect: true }) fullText: string = '';\n\n @property({ type: Number, reflect: true }) textLimit: number = 47;\n\n @property({ type: String, reflect: true }) displayedText: string = '';\n\n @query('slot') slotElement!: HTMLSlotElement;\n\n connectedCallback() {\n super.connectedCallback();\n requestAnimationFrame(() => {\n this.slotElement?.addEventListener('slotchange', this.handleSlotChange.bind(this));\n });\n }\n\n firstUpdated() {\n this.handleSlotChange();\n }\n\n handleSlotChange() {\n const nodes = this.slotElement.assignedNodes({flatten: true});\n const textContent = nodes.map(node => node.textContent).join('');\n this.fullText = textContent.trim();\n this.updateDisplayedText()\n }\n\n toggleExpanded() {\n this.isExpanded = !this.isExpanded;\n this.updateDisplayedText()\n }\n\n updateDisplayedText() {\n if (this.isExpanded) {\n this.displayedText = this.fullText;\n } else {\n const validConcatNumber=concatSentence(this.fullText, this.textLimit)\n const truncatedText = this.fullText.slice(0, validConcatNumber);\n const ellipsis = this.fullText.length > validConcatNumber ? '...' : '';\n this.displayedText = `${truncatedText}${ellipsis}`;\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 const showMoreButton = this.fullText.length > this.textLimit;\n const iconName = this.isExpanded ? 'arrowup' : 'arrowdown';\n\n return html`\n <div class=\"nile-form-help-text\" part=\"container\">\n <slot hidden>${this.fullText}</slot>\n <div part=\"text\">\n <span>${this.displayedText}</span>\n ${showMoreButton ? html`\n <span\n class=\"nile-form-help-text__more-button\"\n part=\"toggle-button\"\n @click=${this.toggleExpanded}\n >${this.isExpanded ? 'View Less' : 'View More'}\n <nile-icon color=\"#005EA6\" part=\"icon\" size=\"14\" name=\"${iconName}\"></nile-icon>\n </span>\n ` : ''}\n </div>\n </div>\n `;\n }\n}\n\nexport default NileFormHelpText;\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-form-help-text': NileFormHelpText;\n }\n}\n\nfunction concatSentence(sentence:string, n:number) {\n if (n < 0 || n > sentence.length) {\n return n;\n }\n\n // Adjust n if it falls in the middle of a word\n if (sentence[n] !== \" \" && n !== 0 && n !== sentence.length) {\n // Move left until the start of the word or the beginning of the sentence\n let left = n;\n while (left > 0 && sentence[left - 1] !== \" \") {\n left--;\n }\n\n // Move right until the end of the word or the end of the sentence\n let right = n;\n while (right < sentence.length && sentence[right] !== \" \") {\n right++;\n }\n\n // Adjust n to the closer boundary\n n = (n - left <= right - n) ? left : right;\n }\n\n // Return the substring from the start to the adjusted n\n return n;\n}\n"]}
|