f_000003 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. import { h } from './core-800e68f4.js';
  2. import { TiUtils } from '../ti-core-assets/lib/TiUtils';
  3. import '../ti-core-assets/lib/TiFiles';
  4. import { TiConsole } from '../ti-core-assets/lib/TiConsole';
  5. import { TiLocalStorage } from '../ti-core-assets/lib/TiLocalStorage';
  6. const style = document.createElement('style');
  7. style.innerHTML = `
  8. @font-face {
  9. font-family: 'Roboto';
  10. font-style: normal;
  11. font-weight: 300;
  12. src: local('Roboto Light'), local('Roboto-Light'), url(components/assets/fonts/font-roboto/Roboto_300_normal.woff) format('woff');
  13. }
  14. @font-face {
  15. font-family: 'Roboto';
  16. font-style: normal;
  17. font-weight: 400;
  18. src: local('Roboto'), local('Roboto-Regular'), url(components/assets/fonts/font-roboto/Roboto_400_normal.woff) format('woff');
  19. }
  20. @font-face {
  21. font-family: 'Roboto';
  22. font-style: normal;
  23. font-weight: 500;
  24. src: local('Roboto Medium'), local('Roboto-Medium'), url(components/assets/fonts/font-roboto/Roboto_500_normal.woff) format('woff');
  25. }
  26. @font-face {
  27. font-family: 'Roboto';
  28. font-style: normal;
  29. font-weight: 700;
  30. src: local('Roboto Bold'), local('Roboto-Bold'), url(components/assets/fonts/font-roboto/Roboto_700_normal.woff) format('woff');
  31. }
  32. @font-face {
  33. font-family: 'Roboto';
  34. font-style: italic;
  35. font-weight: 300;
  36. src: local('Roboto Light Italic'), local('Roboto-LightItalic'), url(components/assets/fonts/font-roboto/Roboto_300_italic.woff) format('woff');
  37. }
  38. @font-face {
  39. font-family: 'Roboto';
  40. font-style: italic;
  41. font-weight: 400;
  42. src: local('Roboto Italic'), local('Roboto-Italic'), url(components/assets/fonts/font-roboto/Roboto_400_italic.woff) format('woff');
  43. }
  44. @font-face {
  45. font-family: 'Roboto';
  46. font-style: italic;
  47. font-weight: 500;
  48. src: local('Roboto Medium Italic'), local('Roboto-MediumItalic'), url(components/assets/fonts/font-roboto/Roboto_500_italic.woff) format('woff');
  49. }
  50. @font-face {
  51. font-family: 'Roboto';
  52. font-style: italic;
  53. font-weight: 700;
  54. src: local('Roboto Bold Italic'), local('Roboto-BoldItalic'), url(components/assets/fonts/font-roboto/Roboto_700_italic.woff) format('woff');
  55. }
  56. `;
  57. document.head.appendChild(style);
  58. /**
  59. * Copyright (c) 2019, Texas Instruments Incorporated
  60. * All rights reserved.
  61. *
  62. * Redistribution and use in source and binary forms, with or without
  63. * modification, are permitted provided that the following conditions
  64. * are met:
  65. *
  66. * * Redistributions of source code must retain the above copyright
  67. * notice, this list of conditions and the following disclaimer.
  68. * notice, this list of conditions and the following disclaimer in the
  69. * documentation and/or other materials provided with the distribution.
  70. * * Neither the name of Texas Instruments Incorporated nor the names of
  71. * its contributors may be used to endorse or promote products derived
  72. * from this software without specific prior written permission.
  73. *
  74. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  75. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  76. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  77. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  78. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  79. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  80. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  81. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  82. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  83. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  84. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  85. */
  86. /**
  87. * Theme css switching using MutationObserver to the body attribute change.
  88. * Only loaded once when added to the dom.
  89. */
  90. //create ti-widget-theme-stylesheet on load, append to document
  91. const style$1 = document.createElement('style');
  92. style$1.setAttribute('title', 'ti-widget-theme-stylesheet');
  93. const element = document.head || document.body;
  94. element.appendChild(style$1);
  95. style$1.sheet.insertRule('html {}', 0);
  96. const styleSheet = style$1.sheet.cssRules[0].style;
  97. // modify stylesheet/css variables on theme attribute change in body
  98. const observer = new MutationObserver((mutations) => {
  99. mutations.forEach(function (mutation) {
  100. switch (document.body.getAttribute('theme')) {
  101. case 'ti-theme':
  102. styleSheet.setProperty('--theme-primary-color', '#cc0000');
  103. styleSheet.setProperty('--theme-secondary-color', '#115566');
  104. styleSheet.setProperty('--theme-alternative-color', '#990000');
  105. styleSheet.setProperty('--theme-background-color', '#fff');
  106. styleSheet.setProperty('--theme-font-color', '#231F20');
  107. styleSheet.setProperty('--theme-header-font-color', '#231F20');
  108. break;
  109. case 'ti-dark':
  110. styleSheet.setProperty('--theme-primary-color', '#990000');
  111. styleSheet.setProperty('--theme-secondary-color', '#115566');
  112. styleSheet.setProperty('--theme-alternative-color', '#990000');
  113. styleSheet.setProperty('--theme-background-color', '#2f2f2f');
  114. styleSheet.setProperty('--theme-font-color', '#f2f2f2');
  115. styleSheet.setProperty('--theme-header-font-color', '#f2f2f2');
  116. break;
  117. }
  118. });
  119. });
  120. observer.observe(document.body, {
  121. attributes: true,
  122. attributeFilter: ['theme']
  123. });
  124. /**
  125. * Copyright (c) 2019-2020, Texas Instruments Incorporated
  126. * All rights reserved.
  127. *
  128. * Redistribution and use in source and binary forms, with or without
  129. * modification, are permitted provided that the following conditions
  130. * are met:
  131. *
  132. * * Redistributions of source code must retain the above copyright
  133. * notice, this list of conditions and the following disclaimer.
  134. * notice, this list of conditions and the following disclaimer in the
  135. * documentation and/or other materials provided with the distribution.
  136. * * Neither the name of Texas Instruments Incorporated nor the names of
  137. * its contributors may be used to endorse or promote products derived
  138. * from this software without specific prior written permission.
  139. *
  140. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  141. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  142. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  143. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  144. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  145. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  146. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  147. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  148. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  149. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  150. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  151. */
  152. /**
  153. * `TiElementBase` provides the base implementation for TI elements.
  154. *
  155. * @customElement
  156. * @isHidden
  157. */
  158. class TiElementBase {
  159. constructor(parent) {
  160. this.parent = parent;
  161. }
  162. /**
  163. * Returns true if the element is hosted in the designer, otherwise false.
  164. *
  165. * @return {boolean}
  166. */
  167. isDesignerHosted() {
  168. return !!TiUtils.rootWin.TIDesigner;
  169. }
  170. /**
  171. * Parse the delimited string into an array.
  172. *
  173. * @param {undefined|string|Array<string>} text the input text
  174. * @param delimiter the delimiter character
  175. * @return {Array<string>} the array
  176. */
  177. parseArray(text, delimiter) {
  178. text = text || '';
  179. // support arrays as well
  180. if (text instanceof Array) {
  181. return text;
  182. }
  183. // support using terminating character as a delimiter if one of [,;|].
  184. // this means that if you want a blank element at the end of the list, you have to use a double terminator; for example, A|B|C||
  185. if (!delimiter && text.length > 1) {
  186. const lastCharacter = text.charAt(text.length - 1);
  187. if (lastCharacter === '|' || lastCharacter === ',' || lastCharacter === ';') {
  188. delimiter = lastCharacter;
  189. text = text.substring(0, text.length - 1);
  190. }
  191. }
  192. // support comma-separated values, semi-colon separated, or | separated fields.
  193. let fields = text.split(delimiter || '|');
  194. if (!delimiter) {
  195. let altFields = text.split(';');
  196. if (altFields.length > fields.length) {
  197. fields = altFields;
  198. }
  199. altFields = text.split(',');
  200. if (altFields.length > fields.length && (altFields.length !== fields.length + 1 || fields.length === 1)) {
  201. fields = altFields;
  202. }
  203. }
  204. for (let i = fields.length; i-- > 0;) {
  205. fields[i] = fields[i].trim();
  206. }
  207. if (fields.length === 1 && fields[0].length === 0) {
  208. return [];
  209. }
  210. return fields;
  211. }
  212. /**
  213. * Returns the cookie value.
  214. *
  215. * @param {string} name the name of the cookie
  216. * @return {string} the cookie value
  217. */
  218. static getCookie(name) {
  219. const value = '; ' + document.cookie;
  220. const parts = value.split('; ' + name + '=');
  221. if (parts.length === 2) {
  222. const item = parts.pop();
  223. if (item !== null) {
  224. return item.split(';').shift() || '';
  225. }
  226. }
  227. return '';
  228. }
  229. /**
  230. * Helper method to log trace message to the console.
  231. *
  232. * @param {string} logtype trace type, can be log|info|warn|debug
  233. * @param {function|string} message the message to log
  234. */
  235. trace(logType, message) {
  236. const output = typeof message === 'object' ? JSON.stringify(message) : message;
  237. const id = this.element.id ? this.element.id : 'no-id';
  238. switch (logType) {
  239. case 'error':
  240. TiConsole.error('[' + this.element.localName + ': ' + id + ']', output);
  241. break;
  242. case 'warning':
  243. TiConsole.warning('[' + this.element.localName + ': ' + id + ']', output);
  244. break;
  245. case 'info':
  246. TiConsole.info('[' + this.element.localName + ': ' + id + ']', output);
  247. break;
  248. case 'log':
  249. TiConsole.log('[' + this.element.localName + ': ' + id + ']', output);
  250. break;
  251. case 'debug':
  252. TiConsole.debug('[' + this.element.localName + ': ' + id + ']', output);
  253. break;
  254. }
  255. }
  256. /**
  257. * Saves the setting to local storage.
  258. *
  259. * @param {string} name the setting name
  260. * @param {string} value the value
  261. */
  262. saveSetting(name, value) {
  263. const id = this.element.tagName.toLowerCase();
  264. const root = JSON.parse(TiLocalStorage.getItem(TiElementBase.STORAGE_ROOT) || '{}');
  265. if (!root[id]) {
  266. root[id] = {};
  267. }
  268. root[id][name] = value;
  269. TiLocalStorage.setItem(TiElementBase.STORAGE_ROOT, JSON.stringify(root));
  270. }
  271. /**
  272. * Loads the setting from local storage.
  273. *
  274. * @param {string} name the setting name
  275. * @return {object} the setting JSON object
  276. */
  277. loadSetting(name) {
  278. const id = this.element.tagName.toLowerCase();
  279. const root = JSON.parse(TiLocalStorage.getItem(TiElementBase.STORAGE_ROOT) || '{}');
  280. const element = root[id] || {};
  281. return element[name];
  282. }
  283. }
  284. TiElementBase.STORAGE_ROOT = 'GC-SETTINGS';
  285. /**
  286. * Copyright (c) 2019-2020, Texas Instruments Incorporated
  287. * All rights reserved.
  288. *
  289. * Redistribution and use in source and binary forms, with or without
  290. * modification, are permitted provided that the following conditions
  291. * are met:
  292. *
  293. * * Redistributions of source code must retain the above copyright
  294. * notice, this list of conditions and the following disclaimer.
  295. * notice, this list of conditions and the following disclaimer in the
  296. * documentation and/or other materials provided with the distribution.
  297. * * Neither the name of Texas Instruments Incorporated nor the names of
  298. * its contributors may be used to endorse or promote products derived
  299. * from this software without specific prior written permission.
  300. *
  301. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  302. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  303. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  304. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  305. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  306. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  307. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  308. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  309. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  310. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  311. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  312. */
  313. /**
  314. * `TiWidgetBase` provides the base implementation for TI widgets.
  315. */
  316. class TiWidgetBase extends TiElementBase {
  317. constructor(parent) {
  318. super(parent);
  319. this.parent = parent;
  320. }
  321. /* Widget that response to CSS property change should override this method to re-render */
  322. onCSSPropertyChanged(name, value) { }
  323. ;
  324. renderInfoText(infoText) {
  325. if (infoText) {
  326. // JSXON
  327. return (h("div", { class: "help-text icon" },
  328. h("ti-widget-tooltip", { text: infoText },
  329. h("ti-widget-icon", { appearance: "secondary", icon: "help", size: "s" }))));
  330. // JSXOFF
  331. }
  332. else {
  333. return null;
  334. }
  335. }
  336. render(element, options) {
  337. if (options && (options.caption || options.infoText)) {
  338. // JSXON
  339. return (h("div", { class: "root-container", onClick: (e) => this.onClickHandler(e, e.target) },
  340. (options === null || options === void 0 ? void 0 : options.caption) ? h("div", { class: "header-container top" },
  341. (options === null || options === void 0 ? void 0 : options.caption) ? h("div", { class: "caption" }, options.caption) : null,
  342. this.renderInfoText(options === null || options === void 0 ? void 0 : options.infoText)) : null,
  343. this.parent.tooltip ? (h("div", { id: "elementWrapper" },
  344. element,
  345. h("ti-widget-tooltip", { class: "tooltip", text: this.parent.tooltip, anchorId: "elementWrapper" }))) : h("div", { id: "elementWrapper" }, element),
  346. (options === null || options === void 0 ? void 0 : options.infoText) && !(options === null || options === void 0 ? void 0 : options.caption) ? h("div", { class: "header-container side" }, this.renderInfoText(options === null || options === void 0 ? void 0 : options.infoText)) : null));
  347. // JSXOFF
  348. }
  349. else {
  350. // JSXON
  351. return (h("div", { id: "elementWrapper" },
  352. element,
  353. this.parent.tooltip ? h("ti-widget-tooltip", { class: "tooltip", text: this.parent.tooltip, anchorId: "elementWrapper" }) : null));
  354. // JSXOFF
  355. }
  356. }
  357. onClickHandler(event, element) {
  358. if (element) {
  359. const parent = element.parentElement;
  360. if (parent && parent.id === 'elementWrapper') {
  361. return;
  362. }
  363. else if (!element.classList.contains('root-container')) {
  364. this.onClickHandler(event, element.parentElement);
  365. }
  366. else {
  367. event.stopPropagation();
  368. }
  369. }
  370. }
  371. fire(eventName, detail) {
  372. const obj = this.parent;
  373. for (const x in obj) {
  374. if (TiUtils.camelToDashCase(x) === eventName) {
  375. return obj[x].emit(detail);
  376. }
  377. }
  378. }
  379. setCSSProperty(name, value) {
  380. value = value.replace(/^[ ]+|[ ]+$/g, '');
  381. this.element.style.setProperty(name, value);
  382. this.parent.cssPropertyChanged.emit({ name: name, value: value });
  383. }
  384. getCSSProperty(name) {
  385. return getComputedStyle(this.element).getPropertyValue(name);
  386. }
  387. refresh() {
  388. return this.element['forceUpdate']();
  389. }
  390. /**
  391. * Add the class name to the element.
  392. *
  393. * @param {string} name the class name
  394. * @param {HTMLElement} element the element
  395. * @protected
  396. */
  397. addClassName(name, element) {
  398. this.modifyClassName(true, name, element);
  399. }
  400. /**
  401. * Remove the class name from the element.
  402. *
  403. * @param {string} name the class name
  404. * @param {HTMLElement} element the element
  405. * @protected
  406. */
  407. removeClassName(name, element) {
  408. this.modifyClassName(false, name, element);
  409. }
  410. modifyClassName(isAdd, name, element = this.element) {
  411. if (element.className.indexOf(name) < 0) {
  412. if (isAdd) {
  413. // add because it doesn't exist yet and should
  414. element.className = (element.className + ' ' + name).trim();
  415. }
  416. }
  417. else if (!isAdd) {
  418. // remove because it does exist and shouldn't
  419. element.className = element.className.replace(name, '').trim();
  420. }
  421. }
  422. }
  423. export { TiWidgetBase as T };
  424. //# sourceMappingURL=ti-widget-base-fe722328.js.map