@nyaruka/temba-components 0.36.1 → 0.37.0

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/dist/sw.js CHANGED
@@ -1,2 +1,2 @@
1
- if(!self.define){let e,t={};const n=(n,o)=>(n=new URL(n+".js",o).href,t[n]||new Promise((t=>{if("document"in self){const e=document.createElement("script");e.src=n,e.onload=t,document.head.appendChild(e)}else e=n,importScripts(n),t()})).then((()=>{let e=t[n];if(!e)throw new Error(`Module ${n} didn’t register its module`);return e})));self.define=(o,i)=>{const s=e||("document"in self?document.currentScript.src:"")||location.href;if(t[s])return;let r={};const c=e=>n(e,s),l={module:{uri:s},exports:r,require:c};t[s]=Promise.all(o.map((e=>l[e]||c(e)))).then((e=>(i(...e),r)))}}define(["./workbox-919adfb7"],(function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"4d30c7b8.js",revision:"68b329da9893e34099c7d8ad5cb9c940"}],{}),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("/index.html"))),e.registerRoute("polyfills/*.js",new e.CacheFirst,"GET")}));
1
+ if(!self.define){let e,t={};const o=(o,n)=>(o=new URL(o+".js",n).href,t[o]||new Promise((t=>{if("document"in self){const e=document.createElement("script");e.src=o,e.onload=t,document.head.appendChild(e)}else e=o,importScripts(o),t()})).then((()=>{let e=t[o];if(!e)throw new Error(`Module ${o} didn’t register its module`);return e})));self.define=(n,s)=>{const i=e||("document"in self?document.currentScript.src:"")||location.href;if(t[i])return;let r={};const l=e=>o(e,i),c={module:{uri:i},exports:r,require:l};t[i]=Promise.all(n.map((e=>c[e]||l(e)))).then((e=>(s(...e),r)))}}define(["./workbox-919adfb7"],(function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"46adbabc.js",revision:"af48f573ba96b7acc6f78ef60871f43e"},{url:"templates/components-body.html",revision:"ad986a6780d59fa16313bacf3dc55136"},{url:"templates/components-head.html",revision:"9e3eb28ab074fc2db8ab6062c1019351"}],{}),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("/index.html"))),e.registerRoute("polyfills/*.js",new e.CacheFirst,"GET")}));
2
2
  //# sourceMappingURL=sw.js.map
package/dist/sw.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sw.js","sources":["../../../../../tmp/d6b884422dc4c0e5c7a12ddb43461cf9/sw.js"],"sourcesContent":["import {registerRoute as workbox_routing_registerRoute} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-routing/registerRoute.mjs';\nimport {CacheFirst as workbox_strategies_CacheFirst} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-strategies/CacheFirst.mjs';\nimport {clientsClaim as workbox_core_clientsClaim} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-core/clientsClaim.mjs';\nimport {precacheAndRoute as workbox_precaching_precacheAndRoute} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-precaching/precacheAndRoute.mjs';\nimport {NavigationRoute as workbox_routing_NavigationRoute} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-routing/NavigationRoute.mjs';\nimport {createHandlerBoundToURL as workbox_precaching_createHandlerBoundToURL} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-precaching/createHandlerBoundToURL.mjs';/**\n * Welcome to your Workbox-powered service worker!\n *\n * You'll need to register this file in your web app.\n * See https://goo.gl/nhQhGp\n *\n * The rest of the code is auto-generated. Please don't update this file\n * directly; instead, make changes to your Workbox build configuration\n * and re-run your build process.\n * See https://goo.gl/2aRDsh\n */\n\n\n\n\n\n\n\n\nself.skipWaiting();\n\nworkbox_core_clientsClaim();\n\n\n/**\n * The precacheAndRoute() method efficiently caches and responds to\n * requests for URLs in the manifest.\n * See https://goo.gl/S9QRab\n */\nworkbox_precaching_precacheAndRoute([\n {\n \"url\": \"4d30c7b8.js\",\n \"revision\": \"68b329da9893e34099c7d8ad5cb9c940\"\n }\n], {});\n\nworkbox_routing_registerRoute(new workbox_routing_NavigationRoute(workbox_precaching_createHandlerBoundToURL(\"/index.html\")));\n\n\nworkbox_routing_registerRoute(\"polyfills/*.js\", new workbox_strategies_CacheFirst(), 'GET');\n\n\n\n\n"],"names":["self","skipWaiting","workbox_core_clientsClaim","workbox_precaching_precacheAndRoute","url","revision","workbox","registerRoute","workbox_routing_NavigationRoute","workbox_precaching_createHandlerBoundToURL","workbox_strategies_CacheFirst"],"mappings":"0nBAwBAA,KAAKC,cAELC,EAAAA,eAQAC,EAAAA,iBAAoC,CAClC,CACEC,IAAO,cACPC,SAAY,qCAEb,CAAE,GAEwBC,EAAAC,cAAC,IAAIC,EAAAA,gBAAgCC,EAAAA,wBAA2C,iBAGhFH,EAAAC,cAAC,iBAAkB,IAAIG,aAAiC"}
1
+ {"version":3,"file":"sw.js","sources":["../../../../../tmp/9e76a4d39f77551fdef7b9321fe7ae67/sw.js"],"sourcesContent":["import {registerRoute as workbox_routing_registerRoute} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-routing/registerRoute.mjs';\nimport {CacheFirst as workbox_strategies_CacheFirst} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-strategies/CacheFirst.mjs';\nimport {clientsClaim as workbox_core_clientsClaim} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-core/clientsClaim.mjs';\nimport {precacheAndRoute as workbox_precaching_precacheAndRoute} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-precaching/precacheAndRoute.mjs';\nimport {NavigationRoute as workbox_routing_NavigationRoute} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-routing/NavigationRoute.mjs';\nimport {createHandlerBoundToURL as workbox_precaching_createHandlerBoundToURL} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-precaching/createHandlerBoundToURL.mjs';/**\n * Welcome to your Workbox-powered service worker!\n *\n * You'll need to register this file in your web app.\n * See https://goo.gl/nhQhGp\n *\n * The rest of the code is auto-generated. Please don't update this file\n * directly; instead, make changes to your Workbox build configuration\n * and re-run your build process.\n * See https://goo.gl/2aRDsh\n */\n\n\n\n\n\n\n\n\nself.skipWaiting();\n\nworkbox_core_clientsClaim();\n\n\n/**\n * The precacheAndRoute() method efficiently caches and responds to\n * requests for URLs in the manifest.\n * See https://goo.gl/S9QRab\n */\nworkbox_precaching_precacheAndRoute([\n {\n \"url\": \"46adbabc.js\",\n \"revision\": \"af48f573ba96b7acc6f78ef60871f43e\"\n },\n {\n \"url\": \"templates/components-body.html\",\n \"revision\": \"ad986a6780d59fa16313bacf3dc55136\"\n },\n {\n \"url\": \"templates/components-head.html\",\n \"revision\": \"9e3eb28ab074fc2db8ab6062c1019351\"\n }\n], {});\n\nworkbox_routing_registerRoute(new workbox_routing_NavigationRoute(workbox_precaching_createHandlerBoundToURL(\"/index.html\")));\n\n\nworkbox_routing_registerRoute(\"polyfills/*.js\", new workbox_strategies_CacheFirst(), 'GET');\n\n\n\n\n"],"names":["self","skipWaiting","workbox_core_clientsClaim","workbox_precaching_precacheAndRoute","url","revision","workbox","registerRoute","workbox_routing_NavigationRoute","workbox_precaching_createHandlerBoundToURL","workbox_strategies_CacheFirst"],"mappings":"0nBAwBAA,KAAKC,cAELC,EAAAA,eAQAC,EAAAA,iBAAoC,CAClC,CACEC,IAAO,cACPC,SAAY,oCAEd,CACED,IAAO,iCACPC,SAAY,oCAEd,CACED,IAAO,iCACPC,SAAY,qCAEb,CAAE,GAEwBC,EAAAC,cAAC,IAAIC,EAAAA,gBAAgCC,EAAAA,wBAA2C,iBAGhFH,EAAAC,cAAC,iBAAkB,IAAIG,aAAiC"}
@@ -0,0 +1 @@
1
+ <script type="module" src="{{STATIC_URL}}@nyaruka/temba-components/dist/46adbabc.js"></script><script>window.TEMBA_COMPONENTS_VERSION="0.37.0"</script>
@@ -0,0 +1 @@
1
+ <link rel="modulepreload" href="{{STATIC_URL}}@nyaruka/temba-components/dist/46adbabc.js" crossorigin="anonymous">
@@ -73,11 +73,19 @@ export class ContentMenu extends RapidElement {
73
73
  `;
74
74
  }
75
75
  fetchContentMenu() {
76
- if (this.endpoint) {
77
- getUrl(this.endpoint, null, HEADERS)
76
+ const url = this.endpoint;
77
+ if (url) {
78
+ const legacy = this.legacy;
79
+ const headers = HEADERS;
80
+ if (legacy) {
81
+ delete headers['Temba-Spa'];
82
+ }
83
+ //ok, fetch the content menu
84
+ getUrl(url, null, headers)
78
85
  .then((response) => {
79
86
  const json = response.json;
80
87
  const contentMenu = json.items;
88
+ //populate (or initialize) the buttons and items
81
89
  if (contentMenu) {
82
90
  this.buttons = contentMenu.filter(item => item.as_button);
83
91
  this.items = contentMenu.filter(item => !item.as_button);
@@ -86,6 +94,7 @@ export class ContentMenu extends RapidElement {
86
94
  this.buttons = [];
87
95
  this.items = [];
88
96
  }
97
+ //fire custom loaded event type when we're finished
89
98
  this.fireCustomEvent(CustomEventType.Loaded, {
90
99
  buttons: this.buttons,
91
100
  items: this.items,
@@ -100,7 +109,8 @@ export class ContentMenu extends RapidElement {
100
109
  this.fetchContentMenu();
101
110
  }
102
111
  updated(changes) {
103
- if (changes.has('endpoint')) {
112
+ super.updated(changes);
113
+ if (changes.has('endpoint') || changes.has('legacy')) {
104
114
  this.fetchContentMenu();
105
115
  }
106
116
  }
@@ -155,9 +165,12 @@ __decorate([
155
165
  property({ type: String })
156
166
  ], ContentMenu.prototype, "endpoint", void 0);
157
167
  __decorate([
158
- property({ type: Array })
168
+ property({ type: Number })
169
+ ], ContentMenu.prototype, "legacy", void 0);
170
+ __decorate([
171
+ property({ type: Array, attribute: false })
159
172
  ], ContentMenu.prototype, "buttons", void 0);
160
173
  __decorate([
161
- property({ type: Array })
174
+ property({ type: Array, attribute: false })
162
175
  ], ContentMenu.prototype, "items", void 0);
163
176
  //# sourceMappingURL=ContentMenu.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContentMenu.js","sourceRoot":"","sources":["../../../src/list/ContentMenu.ts"],"names":[],"mappings":";AAAA,OAAO,EAAkB,IAAI,EAAE,GAAG,EAAoB,MAAM,KAAK,CAAC;AAClE,OAAO,E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C,EAAE;gBACtB,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB,CAAC,OAAO,EAAE;oBAC7C,OAAO,IAAI,CAAA,8BAA8B,CAAC;iBAC3C;qBAAM;oBACL,OAAO,IAAI,CAAA;;6BAEF,IAAI,CAAC,KAAK;+BACR,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC;;wBAEzC,IAAI,CAAC,KAAK;2BACP,CAAC;iBACT;YACH,CAAC,CAAC;;8BAEY;YACpB,CAAC,CAAC,IAAI;;KAEX,CAAC;IACJ,CAAC;CACF;AAzFC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;6CACV;AAGjB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;4CACM;AAGhC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;0CACI","sourcesContent":["import { TemplateResult, html, css, PropertyValueMap } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { CustomEventType } from '../interfaces';\n\nimport { RapidElement } from '../RapidElement';\nimport { getUrl, WebResponse } from '../utils';\n\nconst HEADERS = {\n 'Temba-Content-Menu': '1',\n 'Temba-Spa': '1',\n};\n\nexport interface ContentMenuItem {\n type: string;\n as_button: boolean;\n label: string;\n url: string;\n disabled: boolean;\n modal_id: string;\n on_submit: string;\n primary: boolean;\n title: string;\n on_click: null;\n link_class: string;\n}\n\nexport enum ContentMenuItemType {\n LINK = 'link',\n JS = 'js',\n URL_POST = 'url_post',\n MODAX = 'modax',\n DIVIDER = 'divider',\n}\n\nexport class ContentMenu extends RapidElement {\n static get styles() {\n return css`\n .container {\n --button-y: 0.4em;\n --button-x: 1em;\n display: flex;\n }\n\n .button_item,\n .primary_button_item {\n margin-left: 1rem;\n }\n\n .toggle {\n --icon-color: rgb(102, 102, 102);\n padding: 0.5rem;\n margin-left: 0.5rem;\n }\n\n .toggle:hover {\n background: rgba(0, 0, 0, 0.05);\n border-radius: var(--curvature);\n --icon-color: rgb(136, 136, 136);\n }\n\n .dropdown {\n padding: 1rem 1.5rem;\n color: rgb(45, 45, 45);\n z-index: 50;\n min-width: 200px;\n }\n\n .divider {\n border-bottom: 1px solid rgb(237, 237, 237);\n margin: 1rem -1.5em;\n }\n\n .item {\n white-space: nowrap;\n margin: 0.2em 0em;\n font-size: 1.1rem;\n cursor: pointer;\n font-weight: 400;\n }\n\n .item:hover {\n color: rgb(var(--primary-rgb));\n }\n `;\n }\n\n @property({ type: String })\n endpoint: string;\n\n @property({ type: Array })\n buttons: ContentMenuItem[] = [];\n\n @property({ type: Array })\n items: ContentMenuItem[] = [];\n\n private fetchContentMenu() {\n if (this.endpoint) {\n getUrl(this.endpoint, null, HEADERS)\n .then((response: WebResponse) => {\n const json = response.json;\n const contentMenu = json.items as ContentMenuItem[];\n if (contentMenu) {\n this.buttons = contentMenu.filter(item => item.as_button);\n this.items = contentMenu.filter(item => !item.as_button);\n } else {\n this.buttons = [];\n this.items = [];\n }\n\n this.fireCustomEvent(CustomEventType.Loaded, {\n buttons: this.buttons,\n items: this.items,\n });\n })\n .catch((error: any) => {\n console.error(error);\n });\n }\n }\n\n public refresh() {\n this.fetchContentMenu();\n }\n\n protected updated(changes: Map<string, any>) {\n if (changes.has('endpoint')) {\n this.fetchContentMenu();\n }\n }\n\n private handleItemClicked(item: ContentMenuItem) {\n this.fireCustomEvent(CustomEventType.Selection, item);\n }\n\n public render(): TemplateResult {\n return html`\n <div class=\"container\">\n ${this.buttons.map(button => {\n return html`<temba-button\n class=\"${button.primary ? 'primary_button_item' : 'button_item'}\"\n name=${button.label}\n @click=${() => this.handleItemClicked(button)}\n >\n ${button.label}\n </temba-button>`;\n })}\n ${this.items && this.items.length > 0\n ? html` <temba-dropdown\n arrowsize=\"8\"\n arrowoffset=\"-12\"\n offsetx=\"-200\"\n offsety=\"6\"\n >\n <div slot=\"toggle\" class=\"toggle\">\n <temba-icon name=\"menu\" size=\"1.5\"></temba-icon>\n </div>\n <div slot=\"dropdown\" class=\"dropdown\">\n ${this.items.map(item => {\n if (item.type === ContentMenuItemType.DIVIDER) {\n return html` <div class=\"divider\"></div>`;\n } else {\n return html` <div\n class=\"item\"\n name=${item.label}\n @click=${() => this.handleItemClicked(item)}\n >\n ${item.label}\n </div>`;\n }\n })}\n </div>\n </temba-dropdown>`\n : null}\n </div>\n `;\n }\n}\n"]}
1
+ {"version":3,"file":"ContentMenu.js","sourceRoot":"","sources":["../../../src/list/ContentMenu.ts"],"names":[],"mappings":";AAAA,OAAO,EAAkB,IAAI,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAe,MAAM,UAAU,CAAC;AAE/C,MAAM,OAAO,GAAG;IACd,oBAAoB,EAAE,GAAG;IACzB,WAAW,EAAE,GAAG;CACjB,CAAC;AAeF,MAAM,CAAN,IAAY,mBAMX;AAND,WAAY,mBAAmB;IAC7B,oCAAa,CAAA;IACb,gCAAS,CAAA;IACT,4CAAqB,CAAA;IACrB,sCAAe,CAAA;IACf,0CAAmB,CAAA;AACrB,CAAC,EANW,mBAAmB,KAAnB,mBAAmB,QAM9B;AAED,MAAM,OAAO,WAAY,SAAQ,YAAY;IAA7C;;QA2DE,YAAO,GAAsB,EAAE,CAAC;QAGhC,UAAK,GAAsB,EAAE,CAAC;IAgGhC,CAAC;IA7JC,MAAM,KAAK,MAAM;QACf,OAAO,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA+CT,CAAC;IACJ,CAAC;IAcO,gBAAgB;QACtB,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC1B,IAAI,GAAG,EAAE;YACP,MAAM,MA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f;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;4CACZ;AAGhC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;0CACd","sourcesContent":["import { TemplateResult, html, css } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { CustomEventType } from '../interfaces';\n\nimport { RapidElement } from '../RapidElement';\nimport { getUrl, WebResponse } from '../utils';\n\nconst HEADERS = {\n 'Temba-Content-Menu': '1',\n 'Temba-Spa': '1',\n};\nexport interface ContentMenuItem {\n type: string;\n as_button: boolean;\n label: string;\n url: string;\n disabled: boolean;\n modal_id: string;\n on_submit: string;\n primary: boolean;\n title: string;\n on_click: null;\n link_class: string;\n}\n\nexport enum ContentMenuItemType {\n LINK = 'link',\n JS = 'js',\n URL_POST = 'url_post',\n MODAX = 'modax',\n DIVIDER = 'divider',\n}\n\nexport class ContentMenu extends RapidElement {\n static get styles() {\n return css`\n .container {\n --button-y: 0.4em;\n --button-x: 1em;\n display: flex;\n }\n\n .button_item,\n .primary_button_item {\n margin-left: 1rem;\n }\n\n .toggle {\n --icon-color: rgb(102, 102, 102);\n padding: 0.5rem;\n margin-left: 0.5rem;\n }\n\n .toggle:hover {\n background: rgba(0, 0, 0, 0.05);\n border-radius: var(--curvature);\n --icon-color: rgb(136, 136, 136);\n }\n\n .dropdown {\n padding: 1rem 1.5rem;\n color: rgb(45, 45, 45);\n z-index: 50;\n min-width: 200px;\n }\n\n .divider {\n border-bottom: 1px solid rgb(237, 237, 237);\n margin: 1rem -1.5em;\n }\n\n .item {\n white-space: nowrap;\n margin: 0.2em 0em;\n font-size: 1.1rem;\n cursor: pointer;\n font-weight: 400;\n }\n\n .item:hover {\n color: rgb(var(--primary-rgb));\n }\n `;\n }\n\n @property({ type: String })\n endpoint: string;\n\n @property({ type: Number })\n legacy: number;\n\n @property({ type: Array, attribute: false })\n buttons: ContentMenuItem[] = [];\n\n @property({ type: Array, attribute: false })\n items: ContentMenuItem[] = [];\n\n private fetchContentMenu() {\n const url = this.endpoint;\n if (url) {\n const legacy = this.legacy;\n const headers = HEADERS;\n if (legacy) {\n delete headers['Temba-Spa'];\n }\n\n //ok, fetch the content menu\n getUrl(url, null, headers)\n .then((response: WebResponse) => {\n const json = response.json;\n const contentMenu = json.items as ContentMenuItem[];\n\n //populate (or initialize) the buttons and items\n if (contentMenu) {\n this.buttons = contentMenu.filter(item => item.as_button);\n this.items = contentMenu.filter(item => !item.as_button);\n } else {\n this.buttons = [];\n this.items = [];\n }\n\n //fire custom loaded event type when we're finished\n this.fireCustomEvent(CustomEventType.Loaded, {\n buttons: this.buttons,\n items: this.items,\n });\n })\n .catch((error: any) => {\n console.error(error);\n });\n }\n }\n\n public refresh() {\n this.fetchContentMenu();\n }\n\n protected updated(changes: Map<string, any>) {\n super.updated(changes);\n\n if (changes.has('endpoint') || changes.has('legacy')) {\n this.fetchContentMenu();\n }\n }\n\n private handleItemClicked(item: ContentMenuItem) {\n this.fireCustomEvent(CustomEventType.Selection, item);\n }\n\n public render(): TemplateResult {\n return html`\n <div class=\"container\">\n ${this.buttons.map(button => {\n return html`<temba-button\n class=\"${button.primary ? 'primary_button_item' : 'button_item'}\"\n name=${button.label}\n @click=${() => this.handleItemClicked(button)}\n >\n ${button.label}\n </temba-button>`;\n })}\n ${this.items && this.items.length > 0\n ? html` <temba-dropdown\n arrowsize=\"8\"\n arrowoffset=\"-12\"\n offsetx=\"-200\"\n offsety=\"6\"\n >\n <div slot=\"toggle\" class=\"toggle\">\n <temba-icon name=\"menu\" size=\"1.5\"></temba-icon>\n </div>\n <div slot=\"dropdown\" class=\"dropdown\">\n ${this.items.map(item => {\n if (item.type === ContentMenuItemType.DIVIDER) {\n return html` <div class=\"divider\"></div>`;\n } else {\n return html` <div\n class=\"item\"\n name=${item.label}\n @click=${() => this.handleItemClicked(item)}\n >\n ${item.label}\n </div>`;\n }\n })}\n </div>\n </temba-dropdown>`\n : null}\n </div>\n `;\n }\n}\n"]}
@@ -53,5 +53,19 @@ describe('temba-content-menu', () => {
53
53
  expect(contentMenu.items.length).equals(0);
54
54
  expect(contentMenu.buttons.length).equals(0);
55
55
  });
56
+ it('is spa page', async () => {
57
+ const contentMenu = await getContentMenu({
58
+ endpoint: '/test-assets/list/content-menu-contact-read.json',
59
+ legacy: 0,
60
+ });
61
+ expect(contentMenu.legacy).equals(0);
62
+ });
63
+ it('is legacy page', async () => {
64
+ const contentMenu = await getContentMenu({
65
+ endpoint: '/test-assets/list/content-menu-contact-read.json',
66
+ legacy: 1,
67
+ });
68
+ expect(contentMenu.legacy).equals(1);
69
+ });
56
70
  });
57
71
  //# sourceMappingURL=temba-content-menu.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"temba-content-menu.test.js","sourceRoot":"","sources":["../../test/temba-content-menu.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAuB,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEvE,MAAM,GAAG,GAAG,oBAAoB,CAAC;AACjC,MAAM,cAAc,GAAG,KAAK,EAAE,QAAa,EAAE,EAAE,KAAK,GAAG,CAAC,EAAE,EAAE;IAC1D,MAAM,WAAW,GAAG,CAAC,MAAM,YAAY,CACrC,GAAG,EACH,KAAK,EACL,EAAE,EACF,KAAK,EACL,CAAC,EACD,sBAAsB,CACvB,CAAgB,CAAC;IAElB,iDAAiD;IACjD,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE;QACzB,OAAO,WAAW,CAAC;KACpB;IAED,mEAAmE;IACnE,OAAO,IAAI,OAAO,CAAc,OAAO,CAAC,EAAE;QACxC,WAAW,CAAC,gBAAgB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8BAA8B,EAC9B,OAAO,CAAC,WAAW,CAAC,CACrB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6BAA6B,EAAE,KAAK,IAAI,EAAE;QAC3C,MAAM,WAAW,GAAgB,MAAM,cAAc,CAAC;YACpD,QAAQ,EAAE,kDAAkD;SAC7D,CAAC,CAAC;QAEH,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC3C,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC7C,MAAM,gBAAgB,CACpB,8BAA8B,EAC9B,OAAO,CAAC,WAAW,CAAC,CACrB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,cAAc,EAAE,KAAK,IAAI,EAAE;QAC5B,MAAM,WAAW,GAAgB,MAAM,cAAc,CAAC;YACpD,QAAQ,EAAE,kDAAkD;SAC7D,CAAC,CAAC;QAEH,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC3C,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { assert, expect } from '@open-wc/testing';\nimport { CustomEventType } from '../src/interfaces';\nimport { ContentMenu, ContentMenuItemType } from '../src/list/ContentMenu';\nimport { assertScreenshot, getClip, getComponent } from './utils.test';\n\nconst TAG = 'temba-content-menu';\nconst getContentMenu = async (attrs: any = {}, width = 0) => {\n const contentMenu = (await getComponent(\n TAG,\n attrs,\n '',\n width,\n 0,\n 'display:inline-block'\n )) as ContentMenu;\n\n // return right away if we don't have an endpoint\n if (!contentMenu.endpoint) {\n return contentMenu;\n }\n\n // if we have an endpoint, wait for a loaded event before returning\n return new Promise<ContentMenu>(resolve => {\n contentMenu.addEventListener(CustomEventType.Loaded, async () => {\n resolve(contentMenu);\n });\n });\n};\n\ndescribe('temba-content-menu', () => {\n it('can initially be created without endpoint', async () => {\n const contentMenu: ContentMenu = await getContentMenu();\n assert.instanceOf(contentMenu, ContentMenu);\n expect(contentMenu.endpoint).is.undefined;\n });\n\n it('with 1+ items and 1+ buttons', async () => {\n const contentMenu: ContentMenu = await getContentMenu({\n endpoint: '/test-assets/list/content-menu-contact-read.json',\n });\n\n expect(contentMenu.items.length).equals(5);\n expect(contentMenu.buttons.length).equals(1);\n await assertScreenshot(\n 'content-menu/items-and-buttons',\n getClip(contentMenu)\n );\n });\n\n it('with 1+ items and 0 buttons', async () => {\n const contentMenu: ContentMenu = await getContentMenu({\n endpoint: '/test-assets/list/content-menu-archived-contacts.json',\n });\n\n expect(contentMenu.items.length).equals(1);\n expect(contentMenu.buttons.length).equals(0);\n await assertScreenshot(\n 'content-menu/item-no-buttons',\n getClip(contentMenu)\n );\n });\n\n it('with 0 items and 1+ buttons', async () => {\n const contentMenu: ContentMenu = await getContentMenu({\n endpoint: '/test-assets/list/content-menu-new-campaign.json',\n });\n\n expect(contentMenu.items.length).equals(0);\n expect(contentMenu.buttons.length).equals(1);\n await assertScreenshot(\n 'content-menu/button-no-items',\n getClip(contentMenu)\n );\n });\n\n it('bad endpoint', async () => {\n const contentMenu: ContentMenu = await getContentMenu({\n endpoint: '/test-assets/list/content-menu-bad-endpoint.json',\n });\n\n expect(contentMenu.items.length).equals(0);\n expect(contentMenu.buttons.length).equals(0);\n });\n});\n"]}
1
+ {"version":3,"file":"temba-content-menu.test.js","sourceRoot":"","sources":["../../test/temba-content-menu.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAuB,MAAM,yBAAyB,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CAAC,CAAC;QAC3C,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QAC3B,MAAM,WAAW,GAAgB,MAAM,cAAc,CAAC;YACpD,QAAQ,EAAE,kDAAkD;YAC5D,MAAM,EAAE,CAAC;SACV,CAAC,CAAC;QACH,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gBAAgB,EAAE,KAAK,IAAI,EAAE;QAC9B,MAAM,WAAW,GAAgB,MAAM,cAAc,CAAC;YACpD,QAAQ,EAAE,kDAAkD;YAC5D,MAAM,EAAE,CAAC;SACV,CAAC,CAAC;QACH,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { assert, expect } from '@open-wc/testing';\nimport { CustomEventType } from '../src/interfaces';\nimport { ContentMenu, ContentMenuItemType } from '../src/list/ContentMenu';\nimport { assertScreenshot, getClip, getComponent } from './utils.test';\n\nconst TAG = 'temba-content-menu';\nconst getContentMenu = async (attrs: any = {}, width = 0) => {\n const contentMenu = (await getComponent(\n TAG,\n attrs,\n '',\n width,\n 0,\n 'display:inline-block'\n )) as ContentMenu;\n\n // return right away if we don't have an endpoint\n if (!contentMenu.endpoint) {\n return contentMenu;\n }\n\n // if we have an endpoint, wait for a loaded event before returning\n return new Promise<ContentMenu>(resolve => {\n contentMenu.addEventListener(CustomEventType.Loaded, async () => {\n resolve(contentMenu);\n });\n });\n};\n\ndescribe('temba-content-menu', () => {\n it('can initially be created without endpoint', async () => {\n const contentMenu: ContentMenu = await getContentMenu();\n assert.instanceOf(contentMenu, ContentMenu);\n expect(contentMenu.endpoint).is.undefined;\n });\n\n it('with 1+ items and 1+ buttons', async () => {\n const contentMenu: ContentMenu = await getContentMenu({\n endpoint: '/test-assets/list/content-menu-contact-read.json',\n });\n\n expect(contentMenu.items.length).equals(5);\n expect(contentMenu.buttons.length).equals(1);\n await assertScreenshot(\n 'content-menu/items-and-buttons',\n getClip(contentMenu)\n );\n });\n\n it('with 1+ items and 0 buttons', async () => {\n const contentMenu: ContentMenu = await getContentMenu({\n endpoint: '/test-assets/list/content-menu-archived-contacts.json',\n });\n\n expect(contentMenu.items.length).equals(1);\n expect(contentMenu.buttons.length).equals(0);\n await assertScreenshot(\n 'content-menu/item-no-buttons',\n getClip(contentMenu)\n );\n });\n\n it('with 0 items and 1+ buttons', async () => {\n const contentMenu: ContentMenu = await getContentMenu({\n endpoint: '/test-assets/list/content-menu-new-campaign.json',\n });\n\n expect(contentMenu.items.length).equals(0);\n expect(contentMenu.buttons.length).equals(1);\n await assertScreenshot(\n 'content-menu/button-no-items',\n getClip(contentMenu)\n );\n });\n\n it('bad endpoint', async () => {\n const contentMenu: ContentMenu = await getContentMenu({\n endpoint: '/test-assets/list/content-menu-bad-endpoint.json',\n });\n\n expect(contentMenu.items.length).equals(0);\n expect(contentMenu.buttons.length).equals(0);\n });\n\n it('is spa page', async () => {\n const contentMenu: ContentMenu = await getContentMenu({\n endpoint: '/test-assets/list/content-menu-contact-read.json',\n legacy: 0,\n });\n expect(contentMenu.legacy).equals(0);\n });\n\n it('is legacy page', async () => {\n const contentMenu: ContentMenu = await getContentMenu({\n endpoint: '/test-assets/list/content-menu-contact-read.json',\n legacy: 1,\n });\n expect(contentMenu.legacy).equals(1);\n });\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nyaruka/temba-components",
3
- "version": "0.36.1",
3
+ "version": "0.37.0",
4
4
  "description": "Web components to support rapidpro and related projects",
5
5
  "author": "Nyaruka <code@nyaruka.coim>",
6
6
  "main": "dist/index.js",
package/rollup.config.js CHANGED
@@ -15,12 +15,9 @@ const baseConfig = createSpaConfig({
15
15
  injectServiceWorker: false,
16
16
 
17
17
  html: {
18
- files: [
19
- './templates/components-head.html',
20
- './templates/components-body.html',
21
- ],
22
- flatten: false,
23
- transform: [
18
+ input: [ './templates/components-*.html' ],
19
+ flattenOutput: false,
20
+ transformHtml: [
24
21
  // inject app version
25
22
  (html, args) => {
26
23
  if (args.htmlFileName === 'templates/components-body.html') {
@@ -48,10 +45,18 @@ const baseConfig = createSpaConfig({
48
45
  );
49
46
  },
50
47
  ],
51
- },
48
+ }
52
49
  });
53
50
 
54
51
  const rollupConfig = merge(baseConfig, {
52
+ onwarn(warning, warn) {
53
+ if (warning.code === 'CIRCULAR_DEPENDENCY') {
54
+ if(warning.message.includes('luxon')) {
55
+ return;
56
+ }
57
+ }
58
+ warn(warning);
59
+ },
55
60
  plugins: [
56
61
  commonjs({
57
62
  include: 'node_modules/**',
@@ -1,4 +1,4 @@
1
- import { TemplateResult, html, css, PropertyValueMap } from 'lit';
1
+ import { TemplateResult, html, css } from 'lit';
2
2
  import { property } from 'lit/decorators.js';
3
3
  import { CustomEventType } from '../interfaces';
4
4
 
@@ -9,7 +9,6 @@ const HEADERS = {
9
9
  'Temba-Content-Menu': '1',
10
10
  'Temba-Spa': '1',
11
11
  };
12
-
13
12
  export interface ContentMenuItem {
14
13
  type: string;
15
14
  as_button: boolean;
@@ -87,18 +86,31 @@ export class ContentMenu extends RapidElement {
87
86
  @property({ type: String })
88
87
  endpoint: string;
89
88
 
90
- @property({ type: Array })
89
+ @property({ type: Number })
90
+ legacy: number;
91
+
92
+ @property({ type: Array, attribute: false })
91
93
  buttons: ContentMenuItem[] = [];
92
94
 
93
- @property({ type: Array })
95
+ @property({ type: Array, attribute: false })
94
96
  items: ContentMenuItem[] = [];
95
97
 
96
98
  private fetchContentMenu() {
97
- if (this.endpoint) {
98
- getUrl(this.endpoint, null, HEADERS)
99
+ const url = this.endpoint;
100
+ if (url) {
101
+ const legacy = this.legacy;
102
+ const headers = HEADERS;
103
+ if (legacy) {
104
+ delete headers['Temba-Spa'];
105
+ }
106
+
107
+ //ok, fetch the content menu
108
+ getUrl(url, null, headers)
99
109
  .then((response: WebResponse) => {
100
110
  const json = response.json;
101
111
  const contentMenu = json.items as ContentMenuItem[];
112
+
113
+ //populate (or initialize) the buttons and items
102
114
  if (contentMenu) {
103
115
  this.buttons = contentMenu.filter(item => item.as_button);
104
116
  this.items = contentMenu.filter(item => !item.as_button);
@@ -107,6 +119,7 @@ export class ContentMenu extends RapidElement {
107
119
  this.items = [];
108
120
  }
109
121
 
122
+ //fire custom loaded event type when we're finished
110
123
  this.fireCustomEvent(CustomEventType.Loaded, {
111
124
  buttons: this.buttons,
112
125
  items: this.items,
@@ -123,7 +136,9 @@ export class ContentMenu extends RapidElement {
123
136
  }
124
137
 
125
138
  protected updated(changes: Map<string, any>) {
126
- if (changes.has('endpoint')) {
139
+ super.updated(changes);
140
+
141
+ if (changes.has('endpoint') || changes.has('legacy')) {
127
142
  this.fetchContentMenu();
128
143
  }
129
144
  }
@@ -81,4 +81,20 @@ describe('temba-content-menu', () => {
81
81
  expect(contentMenu.items.length).equals(0);
82
82
  expect(contentMenu.buttons.length).equals(0);
83
83
  });
84
+
85
+ it('is spa page', async () => {
86
+ const contentMenu: ContentMenu = await getContentMenu({
87
+ endpoint: '/test-assets/list/content-menu-contact-read.json',
88
+ legacy: 0,
89
+ });
90
+ expect(contentMenu.legacy).equals(0);
91
+ });
92
+
93
+ it('is legacy page', async () => {
94
+ const contentMenu: ContentMenu = await getContentMenu({
95
+ endpoint: '/test-assets/list/content-menu-contact-read.json',
96
+ legacy: 1,
97
+ });
98
+ expect(contentMenu.legacy).equals(1);
99
+ });
84
100
  });
package/dist/4d30c7b8.js DELETED
@@ -1 +0,0 @@
1
-