@salla.sa/twilight-components 2.13.79 → 2.13.80

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.
@@ -38,6 +38,7 @@ const SallaMenu$1 = /*@__PURE__*/ proxyCustomElement(class SallaMenu extends HTM
38
38
  const cachedMenus = salla.storage.getWithTTL(cacheKey, []);
39
39
  if (cachedMenus.length > 0 && !isPreview) {
40
40
  this.menus = cachedMenus;
41
+ return;
41
42
  }
42
43
  return salla.api.component.getMenus(this.source).then(({ data }) => {
43
44
  this.menus = data;
@@ -1 +1 @@
1
- {"file":"salla-menu.js","mappings":";;;;;;AAAA,MAAM,YAAY,GAAG,sBAAsB;;MCQ9BA,WAAS;;;;kBAKM,QAAQ;;;wBAeF,KAAK;;iBAOR,EAAE;;EAI/B,MAAM,iBAAiB;IACrB,OAAO,KAAK,CAAC,OAAO,CAAC;MACnB,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;MAChE,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM,EAAE;QAC9C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAA;OAChD;WAAM;QACL,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC;OAC5B;KAEF,CAAC,CAAC;GACJ;EAGO,YAAY;;;;;IAMlB,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,CAAA;IACrE,MAAM,QAAQ,GAAG,GAAG,IAAI,CAAC,MAAM,UAAU,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAA;IAC5D,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAE1D,IAAI,WAA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AAC,IAAuB;MACrC,OAAO,SAAG,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE;UAClE,oBAAoB,EAAE,CAAC,IAAI,CAAC,MAAM;UAClC,gDAAgD,EAAE,IAAI,CAAC,MAAM;SAC9D,IAAG,IAAI,CAAC,KAAK,CAAK,CAAA;KACpB,CAAC,CACE,CACF,CAAA;GACP;;;;;;EAOO,aAAa,CAAC,KAAiB;IACrC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAc,KAC9B;MACE,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC;MAC7C,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC;KAChC,CACF,CAAA;GACF;EAID,MAAM;IACJ,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ;MAC7B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC;;QAE9B;UACE,WAAK,GAAG,EAAC,UAAU,EAAC,EAAE,EAAC,aAAa,EAAC,KAAK,EAAC,aAAa,IACtD,UAAI,KAAK,EAAC,WAAW,IAClB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAC5B,EACL,cAAQ,KAAK,EAAC,qDAAqD,GAAG,CAClE;UACN,cAAQ,GAAG,EAAC,WAAW,EAAC,KAAK,EAAC,qDAAqD,GAAG;SACvF,CAAA;GACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SallaMenu"],"sources":["src/components/salla-menu/salla-menu.scss?tag=salla-menu","src/components/salla-menu/salla-menu.tsx"],"sourcesContent":[":host {\n display: block;\n}\n","import { Component, Fragment, h, Prop, State } from '@stencil/core';\nimport { MenuItem, Sources } from './interfaces';\n\n@Component({\n tag: 'salla-menu',\n styleUrl: 'salla-menu.scss',\n})\n\nexport class SallaMenu {\n\n /**\n * The source of the menu, specifying whether it is a header or footer menu.\n */\n @Prop() source: Sources = \"header\"\n\n /**\n * The source value, a stringified JSON representation of the menu content.\n */\n @Prop() sourceValue?: string;\n\n /**\n * Boolean indicating whether the menu is a top navigation menu.\n */\n @Prop() topnav: boolean;\n\n /**\n * Boolean indicating whether to use React Link elements for menu links.\n */\n @Prop() useReactLink: boolean = false;\n\n /**\n * Limiting the number of menu items\n */\n @Prop() limit: number;\n\n @State() menus: MenuItem[] = [];\n\n private displayAllText: ''\n\n async componentWillLoad() {\n return salla.onReady(() => {\n this.displayAllText = salla.lang.get('blocks.home.display_all');\n if (this.sourceValue && this.source === 'json') {\n this.menus = JSON.parse(this.sourceValue) || []\n } else {\n return this.getMenuItems();\n }\n\n });\n }\n\n\n private getMenuItems() {\n\n /**\n * Avoid saving the menu to localStorage (default) when in the development environment\n * or when modifying the theme in the dashboard\n */\n const isPreview = salla.config.isDebug() || salla.helpers.isPreview()\n const cacheKey = `${this.source}_menus_${salla.lang.locale}`\n const cachedMenus = salla.storage.getWithTTL(cacheKey, [])\n\n if (cachedMenus.length > 0 && !isPreview) {\n this.menus = cachedMenus\n }\n\n return salla.api.component.getMenus(this.source).then(({ data }) => {\n this.menus = data;\n !isPreview && salla.storage.setWithTTL(cacheKey, this.menus)\n }).catch((error) => {\n salla.logger.error('salla-menu::Error fetching menus', error)\n });\n }\n\n private hasChildren(menu: MenuItem) {\n return menu?.children?.length > 0;\n }\n\n\n private hasProducts(menu: MenuItem) {\n return menu?.products?.length > 0;\n }\n\n\n /**\n * Get the classes for desktop menu\n * @param {Object} menu\n * @param {Boolean} isRootMenu\n * @returns {String}\n */\n private getDesktopClasses(menu: MenuItem, isRootMenu: boolean) {\n return `!hidden lg:!block ${isRootMenu ? 'root-level lg:!inline-block' : 'relative'} ${menu.products ? ' mega-menu' : ''}\n ${this.hasChildren(menu) ? 'has-children' : ''}`\n }\n\n private getAttributes(attrs: string) {\n return attrs.trim().split(' ').reduce((result, attr) => {\n let [key, value] = attr.split('=');\n result[key] = value.replace(/\"/g, '');\n return result;\n }, {});\n }\n\n /**\n * Get the mobile menu\n * @param {Object} menu\n * @param {String} displayAllText\n * @returns {String}\n */\n private getMobileMenu(menu: MenuItem, displayAllText: string) {\n const menuImage = menu.image ? <img src={menu.image} class=\"rounded-full\" width=\"48\" height=\"48\" alt={menu.title} /> : null;\n\n return (\n <li class=\"lg:hidden text-sm font-bold\" {...this.getAttributes(menu.attrs)}>\n {!this.hasChildren(menu) ?\n <a href={menu.url} aria-label={menu.title || 'category'} class={`text-gray-500 ${menu.image ? '!py-3' : ''}`} {...this.getAttributes(menu.link_attrs)}>\n {menuImage}\n <span>{menu.title || ''}</span>\n </a>\n :\n <Fragment>\n <span class={menu.image ? '!py-3' : ''}>\n {menuImage}\n {menu.title}\n </span>\n <ul>\n <li class=\"text-sm font-bold\">\n <a href={menu.url} class=\"text-gray-500\">{displayAllText}</a>\n </li>\n {menu.children.map((subMenu) => this.getMobileMenu(subMenu, displayAllText))}\n </ul>\n </Fragment>\n }\n </li>\n )\n }\n\n\n /**\n * Get the desktop menu\n * @param {Object} menu\n * @param {Boolean} isRootMenu\n * @returns {String}\n */\n private getDesktopMenu(menu: MenuItem, isRootMenu: boolean) {\n\n return <li class={this.getDesktopClasses(menu, isRootMenu)} {...this.getAttributes(menu.attrs)}>\n <a href={menu.url} aria-label={menu.title || 'category'} {...this.getAttributes(menu.link_attrs)}>\n <span>{menu.title}</span>\n </a>\n {this.hasChildren(menu) ?\n <div class={`sub-menu shadow-default ${this.hasProducts(menu) ? 'w-full left-0 flex' : 'w-56'}`}>\n <ul class={this.hasProducts(menu) ? 'w-56 shrink-0 m-8 rtl:ml-0 ltr:mr-0' : ''}>\n {menu.children.map((subMenu) => this.getDesktopMenu(subMenu, false))}\n </ul>\n {this.hasProducts(menu) ?\n <salla-products-list\n source=\"selected\"\n shadow-on-hover\n source-value={`[${menu.products}]`}\n /> : null}\n </div> : null}\n </li>\n }\n\n\n /**\n * Get the footer menu\n * @param {Array} menus\n */\n private getFooterMenu(menus: Partial<MenuItem>[]) {\n const Menuitems = (this.topnav || this.limit) ? menus.slice(0, this.limit || 3) : menus\n\n return <div>\n <div class={{\n \"s-menu-footer-list\": !this.topnav,\n \"s-menu-topnav-list\": this.topnav\n }}\n >\n {Menuitems.map((menu: Partial<MenuItem>) => {\n return <a key={menu.id} href={menu.url} target={menu.target} class={{\n \"s-menu-footer-item\": !this.topnav,\n \"s-menu-topnav-item topnav-link-item right-side\": this.topnav\n }}>{menu.title}</a>\n })}\n </div>\n </div>\n }\n\n /**\n* Get the menus\n* @param {Array} menus\n* @returns {String}\n*/\n private getHeaderMenu(menus: MenuItem[]) {\n return menus.map((menu: MenuItem) =>\n [\n this.getMobileMenu(menu, this.displayAllText),\n this.getDesktopMenu(menu, true)\n ]\n )\n }\n\n\n\n render() {\n return this.source === \"footer\" ?\n this.getFooterMenu(this.menus)\n :\n [\n <nav key=\"main-nav\" id=\"mobile-menu\" class=\"mobile-menu\">\n <ul class=\"main-menu\">\n {this.getHeaderMenu(this.menus)}\n </ul>\n <button class=\"btn--close close-mobile-menu sicon-cancel lg:hidden\" />\n </nav>,\n <button key=\"close-btn\" class=\"btn--close-sm close-mobile-menu sicon-cancel hidden\" />\n ]\n }\n}\n"],"version":3}
1
+ {"file":"salla-menu.js","mappings":";;;;;;AAAA,MAAM,YAAY,GAAG,sBAAsB;;MCQ9BA,WAAS;;;;kBAKM,QAAQ;;;wBAeF,KAAK;;iBAOR,EAAE;;EAI/B,MAAM,iBAAiB;IACrB,OAAO,KAAK,CAAC,OAAO,CAAC;MACnB,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;MAChE,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM,EAAE;QAC9C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EA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AAI,CAAC,KAAK,CAAC,CAC5B,EACL,cAAQ,KAAK,EAAC,qDAAqD,GAAG,CAClE;UACN,cAAQ,GAAG,EAAC,WAAW,EAAC,KAAK,EAAC,qDAAqD,GAAG;SACvF,CAAA;GACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SallaMenu"],"sources":["src/components/salla-menu/salla-menu.scss?tag=salla-menu","src/components/salla-menu/salla-menu.tsx"],"sourcesContent":[":host {\n display: block;\n}\n","import { Component, Fragment, h, Prop, State } from '@stencil/core';\nimport { MenuItem, Sources } from './interfaces';\n\n@Component({\n tag: 'salla-menu',\n styleUrl: 'salla-menu.scss',\n})\n\nexport class SallaMenu {\n\n /**\n * The source of the menu, specifying whether it is a header or footer menu.\n */\n @Prop() source: Sources = \"header\"\n\n /**\n * The source value, a stringified JSON representation of the menu content.\n */\n @Prop() sourceValue?: string;\n\n /**\n * Boolean indicating whether the menu is a top navigation menu.\n */\n @Prop() topnav: boolean;\n\n /**\n * Boolean indicating whether to use React Link elements for menu links.\n */\n @Prop() useReactLink: boolean = false;\n\n /**\n * Limiting the number of menu items\n */\n @Prop() limit: number;\n\n @State() menus: MenuItem[] = [];\n\n private displayAllText: ''\n\n async componentWillLoad() {\n return salla.onReady(() => {\n this.displayAllText = salla.lang.get('blocks.home.display_all');\n if (this.sourceValue && this.source === 'json') {\n this.menus = JSON.parse(this.sourceValue) || []\n } else {\n return this.getMenuItems();\n }\n\n });\n }\n\n\n private getMenuItems() {\n\n /**\n * Avoid saving the menu to localStorage (default) when in the development environment\n * or when modifying the theme in the dashboard\n */\n const isPreview = salla.config.isDebug() || salla.helpers.isPreview()\n const cacheKey = `${this.source}_menus_${salla.lang.locale}`\n const cachedMenus = salla.storage.getWithTTL(cacheKey, [])\n\n if (cachedMenus.length > 0 && !isPreview) {\n this.menus = cachedMenus\n return;\n }\n\n return salla.api.component.getMenus(this.source).then(({ data }) => {\n this.menus = data;\n !isPreview && salla.storage.setWithTTL(cacheKey, this.menus)\n }).catch((error) => {\n salla.logger.error('salla-menu::Error fetching menus', error)\n });\n }\n\n private hasChildren(menu: MenuItem) {\n return menu?.children?.length > 0;\n }\n\n\n private hasProducts(menu: MenuItem) {\n return menu?.products?.length > 0;\n }\n\n\n /**\n * Get the classes for desktop menu\n * @param {Object} menu\n * @param {Boolean} isRootMenu\n * @returns {String}\n */\n private getDesktopClasses(menu: MenuItem, isRootMenu: boolean) {\n return `!hidden lg:!block ${isRootMenu ? 'root-level lg:!inline-block' : 'relative'} ${menu.products ? ' mega-menu' : ''}\n ${this.hasChildren(menu) ? 'has-children' : ''}`\n }\n\n private getAttributes(attrs: string) {\n return attrs.trim().split(' ').reduce((result, attr) => {\n let [key, value] = attr.split('=');\n result[key] = value.replace(/\"/g, '');\n return result;\n }, {});\n }\n\n /**\n * Get the mobile menu\n * @param {Object} menu\n * @param {String} displayAllText\n * @returns {String}\n */\n private getMobileMenu(menu: MenuItem, displayAllText: string) {\n const menuImage = menu.image ? <img src={menu.image} class=\"rounded-full\" width=\"48\" height=\"48\" alt={menu.title} /> : null;\n\n return (\n <li class=\"lg:hidden text-sm font-bold\" {...this.getAttributes(menu.attrs)}>\n {!this.hasChildren(menu) ?\n <a href={menu.url} aria-label={menu.title || 'category'} class={`text-gray-500 ${menu.image ? '!py-3' : ''}`} {...this.getAttributes(menu.link_attrs)}>\n {menuImage}\n <span>{menu.title || ''}</span>\n </a>\n :\n <Fragment>\n <span class={menu.image ? '!py-3' : ''}>\n {menuImage}\n {menu.title}\n </span>\n <ul>\n <li class=\"text-sm font-bold\">\n <a href={menu.url} class=\"text-gray-500\">{displayAllText}</a>\n </li>\n {menu.children.map((subMenu) => this.getMobileMenu(subMenu, displayAllText))}\n </ul>\n </Fragment>\n }\n </li>\n )\n }\n\n\n /**\n * Get the desktop menu\n * @param {Object} menu\n * @param {Boolean} isRootMenu\n * @returns {String}\n */\n private getDesktopMenu(menu: MenuItem, isRootMenu: boolean) {\n\n return <li class={this.getDesktopClasses(menu, isRootMenu)} {...this.getAttributes(menu.attrs)}>\n <a href={menu.url} aria-label={menu.title || 'category'} {...this.getAttributes(menu.link_attrs)}>\n <span>{menu.title}</span>\n </a>\n {this.hasChildren(menu) ?\n <div class={`sub-menu shadow-default ${this.hasProducts(menu) ? 'w-full left-0 flex' : 'w-56'}`}>\n <ul class={this.hasProducts(menu) ? 'w-56 shrink-0 m-8 rtl:ml-0 ltr:mr-0' : ''}>\n {menu.children.map((subMenu) => this.getDesktopMenu(subMenu, false))}\n </ul>\n {this.hasProducts(menu) ?\n <salla-products-list\n source=\"selected\"\n shadow-on-hover\n source-value={`[${menu.products}]`}\n /> : null}\n </div> : null}\n </li>\n }\n\n\n /**\n * Get the footer menu\n * @param {Array} menus\n */\n private getFooterMenu(menus: Partial<MenuItem>[]) {\n const Menuitems = (this.topnav || this.limit) ? menus.slice(0, this.limit || 3) : menus\n\n return <div>\n <div class={{\n \"s-menu-footer-list\": !this.topnav,\n \"s-menu-topnav-list\": this.topnav\n }}\n >\n {Menuitems.map((menu: Partial<MenuItem>) => {\n return <a key={menu.id} href={menu.url} target={menu.target} class={{\n \"s-menu-footer-item\": !this.topnav,\n \"s-menu-topnav-item topnav-link-item right-side\": this.topnav\n }}>{menu.title}</a>\n })}\n </div>\n </div>\n }\n\n /**\n* Get the menus\n* @param {Array} menus\n* @returns {String}\n*/\n private getHeaderMenu(menus: MenuItem[]) {\n return menus.map((menu: MenuItem) =>\n [\n this.getMobileMenu(menu, this.displayAllText),\n this.getDesktopMenu(menu, true)\n ]\n )\n }\n\n\n\n render() {\n return this.source === \"footer\" ?\n this.getFooterMenu(this.menus)\n :\n [\n <nav key=\"main-nav\" id=\"mobile-menu\" class=\"mobile-menu\">\n <ul class=\"main-menu\">\n {this.getHeaderMenu(this.menus)}\n </ul>\n <button class=\"btn--close close-mobile-menu sicon-cancel lg:hidden\" />\n </nav>,\n <button key=\"close-btn\" class=\"btn--close-sm close-mobile-menu sicon-cancel hidden\" />\n ]\n }\n}\n"],"version":3}