@operato/menu 2.0.0-alpha.55

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.
Files changed (56) hide show
  1. package/.editorconfig +29 -0
  2. package/.storybook/main.js +3 -0
  3. package/.storybook/server.mjs +8 -0
  4. package/CHANGELOG.md +12 -0
  5. package/README.md +75 -0
  6. package/demo/index.html +40 -0
  7. package/dist/src/index.d.ts +0 -0
  8. package/dist/src/index.js +2 -0
  9. package/dist/src/index.js.map +1 -0
  10. package/dist/src/menu-landscape-styles.d.ts +1 -0
  11. package/dist/src/menu-landscape-styles.js +149 -0
  12. package/dist/src/menu-landscape-styles.js.map +1 -0
  13. package/dist/src/menu-portrait-styles.d.ts +1 -0
  14. package/dist/src/menu-portrait-styles.js +147 -0
  15. package/dist/src/menu-portrait-styles.js.map +1 -0
  16. package/dist/src/ox-menu-landscape.d.ts +21 -0
  17. package/dist/src/ox-menu-landscape.js +99 -0
  18. package/dist/src/ox-menu-landscape.js.map +1 -0
  19. package/dist/src/ox-menu-part.d.ts +29 -0
  20. package/dist/src/ox-menu-part.js +135 -0
  21. package/dist/src/ox-menu-part.js.map +1 -0
  22. package/dist/src/ox-menu-portrait.d.ts +13 -0
  23. package/dist/src/ox-menu-portrait.js +85 -0
  24. package/dist/src/ox-menu-portrait.js.map +1 -0
  25. package/dist/src/ox-top-menu-bar.d.ts +23 -0
  26. package/dist/src/ox-top-menu-bar.js +145 -0
  27. package/dist/src/ox-top-menu-bar.js.map +1 -0
  28. package/dist/src/types.d.ts +10 -0
  29. package/dist/src/types.js +2 -0
  30. package/dist/src/types.js.map +1 -0
  31. package/dist/stories/ox-menu-container.d.ts +15 -0
  32. package/dist/stories/ox-menu-container.js +94 -0
  33. package/dist/stories/ox-menu-container.js.map +1 -0
  34. package/dist/stories/ox-menu-portrait.stories.d.ts +17 -0
  35. package/dist/stories/ox-menu-portrait.stories.js +35 -0
  36. package/dist/stories/ox-menu-portrait.stories.js.map +1 -0
  37. package/dist/stories/test-menus.d.ts +2 -0
  38. package/dist/stories/test-menus.js +179 -0
  39. package/dist/stories/test-menus.js.map +1 -0
  40. package/dist/tsconfig.tsbuildinfo +1 -0
  41. package/package.json +100 -0
  42. package/src/index.ts +0 -0
  43. package/src/menu-landscape-styles.ts +149 -0
  44. package/src/menu-portrait-styles.ts +147 -0
  45. package/src/ox-menu-landscape.ts +105 -0
  46. package/src/ox-menu-part.ts +131 -0
  47. package/src/ox-menu-portrait.ts +87 -0
  48. package/src/ox-top-menu-bar.ts +147 -0
  49. package/src/types.ts +10 -0
  50. package/stories/ox-menu-container.ts +97 -0
  51. package/stories/ox-menu-portrait.stories.ts +46 -0
  52. package/stories/test-menus.ts +180 -0
  53. package/themes/app-theme.css +145 -0
  54. package/tsconfig.json +23 -0
  55. package/web-dev-server.config.mjs +27 -0
  56. package/web-test-runner.config.mjs +41 -0
@@ -0,0 +1,135 @@
1
+ import { __decorate } from "tslib";
2
+ import '@material/mwc-icon';
3
+ import './ox-menu-portrait';
4
+ import './ox-menu-landscape';
5
+ import { css, html, LitElement } from 'lit';
6
+ import { customElement, property, state } from 'lit/decorators.js';
7
+ import { connect } from 'pwa-helpers';
8
+ import { store } from '@operato/shell';
9
+ import { ScrollbarStyles } from '@operato/styles';
10
+ function isActiveMenu(menu, path) {
11
+ var _a;
12
+ return (((_a = menu.path) === null || _a === void 0 ? void 0 : _a.split('?')[0]) === path ||
13
+ (menu.active && typeof menu.active === 'function' && menu.active.call(menu, { path })));
14
+ }
15
+ let OxMenuPart = class OxMenuPart extends connect(store)(LitElement) {
16
+ render() {
17
+ return html `
18
+ <slot name="head"></slot>
19
+ ${this.orientation !== 'landscape'
20
+ ? html `<ox-menu-portrait
21
+ .menus=${this.menus}
22
+ .activeTopLevel=${this._activeTopLevel}
23
+ .activeMenu=${this._activeMenu}
24
+ .path=${this._path}
25
+ ></ox-menu-portrait>`
26
+ : html `<ox-menu-landscape
27
+ .menus=${this.menus}
28
+ .activeTopLevel=${this._activeTopLevel}
29
+ .activeMenu=${this._activeMenu}
30
+ .path=${this._path}
31
+ ></ox-menu-landscape>`}
32
+ <slot name="tail"></slot>
33
+ `;
34
+ }
35
+ firstUpdated() {
36
+ this.renderRoot.addEventListener('active-toplevel', (e) => {
37
+ e.stopPropagation();
38
+ e.preventDefault();
39
+ this._activeTopLevel = e.detail;
40
+ });
41
+ }
42
+ updated(changes) {
43
+ if (changes.has('menus') || changes.has('page') || changes.has('resourceId')) {
44
+ this.findActivePage();
45
+ }
46
+ if (changes.has('orientation')) {
47
+ if (this.orientation == 'portrait') {
48
+ this.removeAttribute('landscape');
49
+ }
50
+ else {
51
+ this.setAttribute('landscape', '');
52
+ }
53
+ }
54
+ if (changes.has('slotTemplate')) {
55
+ this.replaceChild(this.slotTemplate, this.renderRoot);
56
+ }
57
+ }
58
+ stateChanged(state) {
59
+ this.page = state.route.page;
60
+ this.resourceId = state.route.resourceId;
61
+ this.menus = state.liteMenu.menus || [];
62
+ this.slotTemplate = state.liteMenu.slotTemplate;
63
+ }
64
+ findActivePage() {
65
+ var path = this.resourceId ? `${this.page}/${this.resourceId}` : this.page;
66
+ var menus = this.menus || [];
67
+ var activeMenu;
68
+ this._activeTopLevel = menus.find(menu => {
69
+ if (isActiveMenu(menu, path)) {
70
+ activeMenu = menu;
71
+ return true;
72
+ }
73
+ else if (menu.menus) {
74
+ activeMenu = menu.menus.find(menu => isActiveMenu(menu, path));
75
+ return !!activeMenu;
76
+ }
77
+ });
78
+ this._path = path;
79
+ this._activeMenu = activeMenu || this._activeTopLevel;
80
+ }
81
+ };
82
+ OxMenuPart.styles = [
83
+ ScrollbarStyles,
84
+ css `
85
+ :host {
86
+ display: flex;
87
+ overflow-y: auto;
88
+ flex-direction: column;
89
+ height: 100%;
90
+ min-width: 200px;
91
+ background-color: var(--theme-white-color);
92
+ }
93
+
94
+ :host([landscape]) {
95
+ overflow-x: auto;
96
+ flex-direction: row;
97
+ width: 100%;
98
+ min-height: 20px;
99
+ }
100
+
101
+ ox-menu-portrait,
102
+ ox-menu-landscape {
103
+ flex: 1;
104
+ }
105
+ `
106
+ ];
107
+ __decorate([
108
+ property({ type: String })
109
+ ], OxMenuPart.prototype, "page", void 0);
110
+ __decorate([
111
+ property({ type: String })
112
+ ], OxMenuPart.prototype, "resourceId", void 0);
113
+ __decorate([
114
+ property({ type: Array })
115
+ ], OxMenuPart.prototype, "menus", void 0);
116
+ __decorate([
117
+ property({ type: String })
118
+ ], OxMenuPart.prototype, "orientation", void 0);
119
+ __decorate([
120
+ state()
121
+ ], OxMenuPart.prototype, "slotTemplate", void 0);
122
+ __decorate([
123
+ state()
124
+ ], OxMenuPart.prototype, "_activeTopLevel", void 0);
125
+ __decorate([
126
+ state()
127
+ ], OxMenuPart.prototype, "_activeMenu", void 0);
128
+ __decorate([
129
+ state()
130
+ ], OxMenuPart.prototype, "_path", void 0);
131
+ OxMenuPart = __decorate([
132
+ customElement('ox-menu-part')
133
+ ], OxMenuPart);
134
+ export { OxMenuPart };
135
+ //# sourceMappingURL=ox-menu-part.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ox-menu-part.js","sourceRoot":"","sources":["../../src/ox-menu-part.ts"],"names":[],"mappings":";AAAA,OAAO,oBAAoB,CAAA;AAC3B,OAAO,oBAAoB,CAAA;AAC3B,OAAO,qBAAqB,CAAA;AAE5B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAkB,MAAM,KAAK,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAS,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAErC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAIjD,SAAS,YAAY,CAAC,IAAU,EAAE,IAAY;;IAC5C,OAAO,CACL,CAAA,MAAA,IAAI,CAAC,IAAI,0CAAE,KA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C,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;gBAC9D,OAAO,CAAC,CAAC,UAAU,CAAA;YACrB,CAAC;QACH,CAAC,CAAC,CAAA;QAEF,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,WAAW,GAAG,UAAU,IAAI,IAAI,CAAC,eAAe,CAAA;IACvD,CAAC;;AA3GM,iBAAM,GAAG;IACd,eAAe;IACf,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;KAqBF;CACF,AAxBY,CAwBZ;AAE2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wCAAc;AACb;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8CAAoB;AACpB;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;yCAAe;AACb;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+CAAuC;AAEzD;IAAR,KAAK,EAAE;gDAAkB;AACjB;IAAR,KAAK,EAAE;mDAAuB;AACtB;IAAR,KAAK,EAAE;+CAAmB;AAClB;IAAR,KAAK,EAAE;yCAAe;AAnCZ,UAAU;IADtB,aAAa,CAAC,cAAc,CAAC;GACjB,UAAU,CA6GtB","sourcesContent":["import '@material/mwc-icon'\nimport './ox-menu-portrait'\nimport './ox-menu-landscape'\n\nimport { css, html, LitElement, PropertyValues } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\nimport { connect } from 'pwa-helpers'\n\nimport { store } from '@operato/shell'\nimport { ScrollbarStyles } from '@operato/styles'\n\nimport { Menu } from './types'\n\nfunction isActiveMenu(menu: Menu, path: string) {\n return (\n menu.path?.split('?')[0] === path ||\n (menu.active && typeof menu.active === 'function' && menu.active.call(menu, { path }))\n )\n}\n\n@customElement('ox-menu-part')\nexport class OxMenuPart extends connect(store)(LitElement) {\n static styles = [\n ScrollbarStyles,\n css`\n :host {\n display: flex;\n overflow-y: auto;\n flex-direction: column;\n height: 100%;\n min-width: 200px;\n background-color: var(--theme-white-color);\n }\n\n :host([landscape]) {\n overflow-x: auto;\n flex-direction: row;\n width: 100%;\n min-height: 20px;\n }\n\n ox-menu-portrait,\n ox-menu-landscape {\n flex: 1;\n }\n `\n ]\n\n @property({ type: String }) page!: string\n @property({ type: String }) resourceId?: string\n @property({ type: Array }) menus?: Menu[]\n @property({ type: String }) orientation?: 'landscape' | 'portrait'\n\n @state() slotTemplate: any\n @state() _activeTopLevel?: Menu\n @state() _activeMenu?: Menu\n @state() _path?: string\n\n render() {\n return html`\n <slot name=\"head\"></slot>\n ${this.orientation !== 'landscape'\n ? html`<ox-menu-portrait\n .menus=${this.menus}\n .activeTopLevel=${this._activeTopLevel}\n .activeMenu=${this._activeMenu}\n .path=${this._path}\n ></ox-menu-portrait>`\n : html`<ox-menu-landscape\n .menus=${this.menus}\n .activeTopLevel=${this._activeTopLevel}\n .activeMenu=${this._activeMenu}\n .path=${this._path}\n ></ox-menu-landscape>`}\n <slot name=\"tail\"></slot>\n `\n }\n\n firstUpdated() {\n this.renderRoot.addEventListener('active-toplevel', (e: Event) => {\n e.stopPropagation()\n e.preventDefault()\n\n this._activeTopLevel = (e as CustomEvent).detail\n })\n }\n\n updated(changes: PropertyValues<this>) {\n if (changes.has('menus') || changes.has('page') || changes.has('resourceId')) {\n this.findActivePage()\n }\n\n if (changes.has('orientation')) {\n if (this.orientation == 'portrait') {\n this.removeAttribute('landscape')\n } else {\n this.setAttribute('landscape', '')\n }\n }\n\n if (changes.has('slotTemplate')) {\n this.replaceChild(this.slotTemplate, this.renderRoot)\n }\n }\n\n stateChanged(state: any): void {\n this.page = state.route.page\n this.resourceId = state.route.resourceId\n this.menus = state.liteMenu.menus || []\n this.slotTemplate = state.liteMenu.slotTemplate\n }\n\n private findActivePage() {\n var path = this.resourceId ? `${this.page}/${this.resourceId}` : this.page\n var menus = this.menus || []\n var activeMenu\n\n this._activeTopLevel = menus.find(menu => {\n if (isActiveMenu(menu, path)) {\n activeMenu = menu\n return true\n } else if (menu.menus) {\n activeMenu = menu.menus.find(menu => isActiveMenu(menu, path))\n return !!activeMenu\n }\n })\n\n this._path = path\n this._activeMenu = activeMenu || this._activeTopLevel\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import '@material/mwc-icon';
2
+ import { LitElement, TemplateResult } from 'lit';
3
+ import { Menu } from './types';
4
+ export declare class OxMenuPortrait extends LitElement {
5
+ static styles: import("lit").CSSResult[];
6
+ menus?: Menu[];
7
+ activeTopLevel?: Menu;
8
+ activeMenu?: Menu;
9
+ path: string;
10
+ renderMenus(menus: Menu[], activeTopLevel?: Menu, activeMenu?: Menu): TemplateResult;
11
+ render(): TemplateResult;
12
+ firstUpdated(): void;
13
+ }
@@ -0,0 +1,85 @@
1
+ import { __decorate } from "tslib";
2
+ import '@material/mwc-icon';
3
+ import { html, LitElement } from 'lit';
4
+ import { customElement, property } from 'lit/decorators.js';
5
+ import { navigate } from '@operato/shell';
6
+ import { ScrollbarStyles } from '@operato/styles';
7
+ import { MenuPortraitStyles } from './menu-portrait-styles';
8
+ let OxMenuPortrait = class OxMenuPortrait extends LitElement {
9
+ renderMenus(menus, activeTopLevel, activeMenu) {
10
+ return html `
11
+ <ul>
12
+ ${menus.map(menu => {
13
+ var { type, active, path, name, badge, icon, menus = [] } = menu;
14
+ active = active && typeof active === 'function' ? active.call(menu, { path: this.path }) : false;
15
+ badge = typeof badge === 'function' ? badge.call(menu) : badge !== null && badge !== void 0 ? badge : false;
16
+ return type == 'group'
17
+ ? html `<li group-label>${name}</li>`
18
+ : html `
19
+ <li ?active=${activeTopLevel ? menu === activeTopLevel : active} .menu=${menu} menu>
20
+ <a href=${path || '#'}>
21
+ ${menus.length > 0 ? html ` <mwc-icon submenu-button></mwc-icon> ` : html ``}
22
+ <mwc-icon>${icon}</mwc-icon>
23
+ ${name} ${badge !== false ? html `<div badge>${badge}</div>` : html ``}
24
+ </a>
25
+ ${menus && this.renderMenus(menus || [], activeMenu)}
26
+ </li>
27
+ `;
28
+ })}
29
+ </ul>
30
+ `;
31
+ }
32
+ render() {
33
+ const { menus, activeTopLevel, activeMenu } = this;
34
+ return this.renderMenus(menus || [], activeTopLevel, activeMenu);
35
+ }
36
+ firstUpdated() {
37
+ this.renderRoot.addEventListener('click', (e) => {
38
+ const menuElement = e.target.closest('[menu]');
39
+ //@ts-ignore
40
+ if (menuElement === null || menuElement === void 0 ? void 0 : menuElement.menu) {
41
+ //@ts-ignore
42
+ let menu = menuElement.menu;
43
+ if (!menu.path) {
44
+ /* protect to act move to href. */
45
+ e.stopPropagation();
46
+ e.preventDefault();
47
+ }
48
+ this.dispatchEvent(new CustomEvent('active-toplevel', {
49
+ bubbles: true,
50
+ detail: this.activeTopLevel === menu ? undefined : menu
51
+ }));
52
+ }
53
+ /* to respond even if current acting menu is selected */
54
+ let href = e.target.href;
55
+ href && location.href === href && navigate(href + '#force', true);
56
+ });
57
+ /* to hide scrollbar during transition */
58
+ this.renderRoot.addEventListener('transitionstart', e => {
59
+ ;
60
+ e.target.removeAttribute('settled');
61
+ });
62
+ this.renderRoot.addEventListener('transitionend', e => {
63
+ ;
64
+ e.target.setAttribute('settled', '');
65
+ });
66
+ }
67
+ };
68
+ OxMenuPortrait.styles = [ScrollbarStyles, MenuPortraitStyles];
69
+ __decorate([
70
+ property({ type: Array })
71
+ ], OxMenuPortrait.prototype, "menus", void 0);
72
+ __decorate([
73
+ property({ type: Object })
74
+ ], OxMenuPortrait.prototype, "activeTopLevel", void 0);
75
+ __decorate([
76
+ property({ type: Object })
77
+ ], OxMenuPortrait.prototype, "activeMenu", void 0);
78
+ __decorate([
79
+ property({ type: String })
80
+ ], OxMenuPortrait.prototype, "path", void 0);
81
+ OxMenuPortrait = __decorate([
82
+ customElement('ox-menu-portrait')
83
+ ], OxMenuPortrait);
84
+ export { OxMenuPortrait };
85
+ //# sourceMappingURL=ox-menu-portrait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,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;iBACxD,CAAC,CACH,CAAA;YACH,CAAC;YAED,wDAAwD;YACxD,IAAI,IAAI,GAAI,CAAC,CAAC,MAA6B,CAAC,IAAI,CAAA;YAChD,IAAI,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,IAAI,QAAQ,CAAC,IAAI,GAAG,QAAQ,EAAE,IAAI,CAAC,CAAA;QACnE,CAAC,CAAC,CAAA;QAEF,yCAAyC;QACzC,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,CAAC,CAAC,EAAE;YACtD,CAAC;YAAC,CAAC,CAAC,MAAkB,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;QACnD,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,eAAe,EAAE,CAAC,CAAC,EAAE;YACpD,CAAC;YAAC,CAAC,CAAC,MAAkB,CAAC,YAAY,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;QACpD,CAAC,CAAC,CAAA;IACJ,CAAC;;AAxEM,qBAAM,GAAG,CAAC,eAAe,EAAE,kBAAkB,CAAC,AAAxC,CAAwC;AAE1B;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;6CAAe;AACb;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sDAAsB;AACrB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDAAkB;AACjB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4CAAc;AAN9B,cAAc;IAD1B,aAAa,CAAC,kBAAkB,CAAC;GACrB,cAAc,CA0E1B","sourcesContent":["import '@material/mwc-icon'\n\nimport { html, LitElement, TemplateResult } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { navigate } from '@operato/shell'\nimport { ScrollbarStyles } from '@operato/styles'\n\nimport { Menu } from './types'\nimport { MenuPortraitStyles } from './menu-portrait-styles'\n\n@customElement('ox-menu-portrait')\nexport class OxMenuPortrait extends LitElement {\n static styles = [ScrollbarStyles, MenuPortraitStyles]\n\n @property({ type: Array }) menus?: Menu[]\n @property({ type: Object }) activeTopLevel?: Menu\n @property({ type: Object }) activeMenu?: Menu\n @property({ type: String }) path!: string\n\n renderMenus(menus: Menu[], activeTopLevel?: Menu, activeMenu?: Menu): TemplateResult {\n return html`\n <ul>\n ${menus.map(menu => {\n var { type, active, path, name, badge, icon, menus = [] } = menu\n active = active && typeof active === 'function' ? active.call(menu, { path: this.path }) : false\n badge = typeof badge === 'function' ? badge.call(menu) : badge ?? false\n\n return type == 'group'\n ? html`<li group-label>${name}</li>`\n : html`\n <li ?active=${activeTopLevel ? menu === activeTopLevel : active} .menu=${menu} menu>\n <a href=${path || '#'}>\n ${menus.length > 0 ? html` <mwc-icon submenu-button></mwc-icon> ` : html``}\n <mwc-icon>${icon}</mwc-icon>\n ${name} ${badge !== false ? html`<div badge>${badge}</div>` : html``}\n </a>\n ${menus && this.renderMenus(menus || [], activeMenu)}\n </li>\n `\n })}\n </ul>\n `\n }\n\n render() {\n const { menus, activeTopLevel, activeMenu } = this\n return this.renderMenus(menus || [], activeTopLevel, activeMenu)\n }\n\n firstUpdated() {\n this.renderRoot.addEventListener('click', (e: Event) => {\n const menuElement = (e.target as Element)!.closest('[menu]')\n\n //@ts-ignore\n if (menuElement?.menu) {\n //@ts-ignore\n let menu = menuElement.menu\n\n if (!menu.path) {\n /* protect to act move to href. */\n e.stopPropagation()\n e.preventDefault()\n }\n\n this.dispatchEvent(\n new CustomEvent('active-toplevel', {\n bubbles: true,\n detail: this.activeTopLevel === menu ? undefined : menu\n })\n )\n }\n\n /* to respond even if current acting menu is selected */\n let href = (e.target as HTMLAnchorElement)!.href\n href && location.href === href && navigate(href + '#force', true)\n })\n\n /* to hide scrollbar during transition */\n this.renderRoot.addEventListener('transitionstart', e => {\n ;(e.target as Element).removeAttribute('settled')\n })\n this.renderRoot.addEventListener('transitionend', e => {\n ;(e.target as Element).setAttribute('settled', '')\n })\n }\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import '@material/mwc-icon';
2
+ import { LitElement, PropertyValueMap, TemplateResult } from 'lit';
3
+ import { Menu } from './types';
4
+ declare const OxTopMenuBar_base: (new (...args: any[]) => {
5
+ _storeUnsubscribe: import("redux").Unsubscribe;
6
+ connectedCallback(): void;
7
+ disconnectedCallback(): void;
8
+ stateChanged(_state: unknown): void;
9
+ readonly isConnected: boolean;
10
+ }) & typeof LitElement;
11
+ export declare class OxTopMenuBar extends OxTopMenuBar_base {
12
+ static styles: import("lit").CSSResult[];
13
+ page?: string;
14
+ resourceId?: string;
15
+ menus?: Menu[];
16
+ slotTemplate: Node;
17
+ private _activeTopLevel?;
18
+ render(): TemplateResult<1>;
19
+ stateChanged(state: any): void;
20
+ updated(changes: PropertyValueMap<this>): void;
21
+ _findActivePage(): void;
22
+ }
23
+ export {};
@@ -0,0 +1,145 @@
1
+ import { __decorate } from "tslib";
2
+ import '@material/mwc-icon';
3
+ import { css, html, LitElement } from 'lit';
4
+ import { customElement, property, state } from 'lit/decorators.js';
5
+ import { connect } from 'pwa-helpers';
6
+ import { toggleOverlay } from '@operato/layout';
7
+ import { store } from '@operato/shell';
8
+ let OxTopMenuBar = class OxTopMenuBar extends connect(store)(LitElement) {
9
+ render() {
10
+ const { menus = [], _activeTopLevel } = this;
11
+ return html `
12
+ <slot name="head"></slot>
13
+ <ul>
14
+ ${menus.map(menu => menu.type == 'group'
15
+ ? html ``
16
+ : html `
17
+ <li ?active=${menu === _activeTopLevel}>
18
+ <a
19
+ href="#"
20
+ @click=${(e) => {
21
+ e.preventDefault();
22
+ toggleOverlay('ox-menu-part', {
23
+ backdrop: true
24
+ });
25
+ }}
26
+ >
27
+ ${menu.name}
28
+ <mwc-icon>expand_more</mwc-icon>
29
+ </a>
30
+ </li>
31
+ `)}
32
+ </ul>
33
+ <slot name="tail"></slot>
34
+ `;
35
+ }
36
+ stateChanged(state) {
37
+ this.page = state.route.page;
38
+ this.resourceId = state.route.resourceId;
39
+ this.menus = state.liteMenu.menus || [];
40
+ this.slotTemplate = state.liteMenu.slotTemplate;
41
+ }
42
+ // firstUpdated() {
43
+ // this.addEventListener('mousewheel', this.onWheelEvent.bind(this), false)
44
+ // }
45
+ updated(changes) {
46
+ if (changes.has('menus') || changes.has('page') || changes.has('resourceId')) {
47
+ this._findActivePage();
48
+ }
49
+ if (changes.has('slotTemplate')) {
50
+ this.replaceChild(this.slotTemplate, this.renderRoot);
51
+ }
52
+ }
53
+ // onWheelEvent(e) {
54
+ // var delta = Math.max(-1, Math.min(1, e.wheelDelta || -e.detail))
55
+ // this.scrollLeft -= delta * 40
56
+ // console.log('delta', this.scrollLeft, delta, e.wheelDelta || -e.detail)
57
+ // e.preventDefault()
58
+ // }
59
+ _findActivePage() {
60
+ var path = this.resourceId ? `${this.page}/${this.resourceId}` : this.page;
61
+ var menus = this.menus || [];
62
+ this._activeTopLevel = menus.find(menu => {
63
+ var _a;
64
+ if (((_a = menu.path) === null || _a === void 0 ? void 0 : _a.split('?')[0]) === path) {
65
+ return true;
66
+ }
67
+ else if (menu.menus) {
68
+ return !!menu.menus.find(menu => { var _a; return ((_a = menu.path) === null || _a === void 0 ? void 0 : _a.split('?')[0]) === path; });
69
+ }
70
+ });
71
+ }
72
+ };
73
+ OxTopMenuBar.styles = [
74
+ css `
75
+ :host {
76
+ display: flex;
77
+ flex-direction: row;
78
+ }
79
+
80
+ span {
81
+ flex: 1;
82
+ }
83
+
84
+ ul {
85
+ display: flex;
86
+ align-items: center;
87
+ list-style: none;
88
+ margin: 0;
89
+ padding: 0;
90
+ }
91
+
92
+ li {
93
+ display: inline-flex;
94
+ flex-direction: row nowrap;
95
+ float: left;
96
+ overflow: none;
97
+ }
98
+
99
+ a {
100
+ display: inline-block;
101
+ white-space: nowrap;
102
+ overflow: hidden;
103
+ text-overflow: ellipsis;
104
+ padding: var(--padding-default) var(--padding-wide) var(--padding-narrow) var(--padding-wide);
105
+ text-decoration: none;
106
+ color: white;
107
+ }
108
+ a * {
109
+ vertical-align: middle;
110
+ }
111
+ a mwc-icon {
112
+ opacity: 0.5;
113
+ position: relative;
114
+ top: -2px;
115
+ font-size: 1em;
116
+ }
117
+
118
+ li[active] a {
119
+ font-weight: bold;
120
+ }
121
+ li[active] a mwc-icon {
122
+ opacity: 1;
123
+ }
124
+ `
125
+ ];
126
+ __decorate([
127
+ property({ type: String })
128
+ ], OxTopMenuBar.prototype, "page", void 0);
129
+ __decorate([
130
+ property({ type: String })
131
+ ], OxTopMenuBar.prototype, "resourceId", void 0);
132
+ __decorate([
133
+ property({ type: Array })
134
+ ], OxTopMenuBar.prototype, "menus", void 0);
135
+ __decorate([
136
+ property({ type: Object })
137
+ ], OxTopMenuBar.prototype, "slotTemplate", void 0);
138
+ __decorate([
139
+ state()
140
+ ], OxTopMenuBar.prototype, "_activeTopLevel", void 0);
141
+ OxTopMenuBar = __decorate([
142
+ customElement('ox-top-menu-bar')
143
+ ], OxTopMenuBar);
144
+ export { OxTopMenuBar };
145
+ //# sourceMappingURL=ox-top-menu-bar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ox-top-menu-bar.js","sourceRoot":"","sources":["../../src/ox-top-menu-bar.ts"],"names":[],"mappings":";AAAA,OAAO,oBAAoB,CAAA;AAE3B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAoC,MAAM,KAAK,CAAA;AAC7E,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAS,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAK/B,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,OAAO,C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,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDAAoB;AAE9B;IAAhB,KAAK,EAAE;qDAA+B;AA5D5B,YAAY;IADxB,aAAa,CAAC,iBAAiB,CAAC;GACpB,YAAY,CAsIxB","sourcesContent":["import '@material/mwc-icon'\n\nimport { css, html, LitElement, PropertyValueMap, TemplateResult } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\nimport { connect } from 'pwa-helpers'\n\nimport { toggleOverlay } from '@operato/layout'\nimport { store } from '@operato/shell'\n\nimport { Menu } from './types'\n\n@customElement('ox-top-menu-bar')\nexport class OxTopMenuBar extends connect(store)(LitElement) {\n static styles = [\n css`\n :host {\n display: flex;\n flex-direction: row;\n }\n\n span {\n flex: 1;\n }\n\n ul {\n display: flex;\n align-items: center;\n list-style: none;\n margin: 0;\n padding: 0;\n }\n\n li {\n display: inline-flex;\n flex-direction: row nowrap;\n float: left;\n overflow: none;\n }\n\n a {\n display: inline-block;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n padding: var(--padding-default) var(--padding-wide) var(--padding-narrow) var(--padding-wide);\n text-decoration: none;\n color: white;\n }\n a * {\n vertical-align: middle;\n }\n a mwc-icon {\n opacity: 0.5;\n position: relative;\n top: -2px;\n font-size: 1em;\n }\n\n li[active] a {\n font-weight: bold;\n }\n li[active] a mwc-icon {\n opacity: 1;\n }\n `\n ]\n\n @property({ type: String }) page?: string\n @property({ type: String }) resourceId?: string\n @property({ type: Array }) menus?: Menu[]\n @property({ type: Object }) slotTemplate!: Node\n\n @state() private _activeTopLevel?: Menu\n\n render() {\n const { menus = [], _activeTopLevel } = this\n\n return html`\n <slot name=\"head\"></slot>\n <ul>\n ${menus.map(menu =>\n menu.type == 'group'\n ? html``\n : html`\n <li ?active=${menu === _activeTopLevel}>\n <a\n href=\"#\"\n @click=${(e: MouseEvent) => {\n e.preventDefault()\n toggleOverlay('ox-menu-part', {\n backdrop: true\n })\n }}\n >\n ${menu.name}\n <mwc-icon>expand_more</mwc-icon>\n </a>\n </li>\n `\n )}\n </ul>\n <slot name=\"tail\"></slot>\n `\n }\n\n stateChanged(state: any): void {\n this.page = state.route.page\n this.resourceId = state.route.resourceId\n this.menus = state.liteMenu.menus || []\n this.slotTemplate = state.liteMenu.slotTemplate\n }\n\n // firstUpdated() {\n // this.addEventListener('mousewheel', this.onWheelEvent.bind(this), false)\n // }\n\n updated(changes: PropertyValueMap<this>) {\n if (changes.has('menus') || changes.has('page') || changes.has('resourceId')) {\n this._findActivePage()\n }\n\n if (changes.has('slotTemplate')) {\n this.replaceChild(this.slotTemplate, this.renderRoot)\n }\n }\n\n // onWheelEvent(e) {\n // var delta = Math.max(-1, Math.min(1, e.wheelDelta || -e.detail))\n // this.scrollLeft -= delta * 40\n // console.log('delta', this.scrollLeft, delta, e.wheelDelta || -e.detail)\n\n // e.preventDefault()\n // }\n\n _findActivePage() {\n var path = this.resourceId ? `${this.page}/${this.resourceId}` : this.page\n var menus = this.menus || []\n\n this._activeTopLevel = menus.find(menu => {\n if (menu.path?.split('?')[0] === path) {\n return true\n } else if (menu.menus) {\n return !!menu.menus.find(menu => menu.path?.split('?')[0] === path)\n }\n })\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ export type Menu = {
2
+ type?: 'group' | 'board';
3
+ name?: string;
4
+ description?: string;
5
+ path?: string;
6
+ icon?: string;
7
+ badge?: boolean | string | (() => boolean);
8
+ active?: boolean | ((menu?: Menu) => boolean);
9
+ menus?: Menu[];
10
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type Menu = {\n type?: 'group' | 'board'\n name?: string\n description?: string\n path?: string\n icon?: string\n badge?: boolean | string | (() => boolean)\n active?: boolean | ((menu?: Menu) => boolean)\n menus?: Menu[]\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import '@material/mwc-icon';
2
+ import '../src/ox-menu-portrait';
3
+ import { LitElement, PropertyValues } from 'lit';
4
+ import { Menu } from '../src/types';
5
+ export declare class OxMenuContainer extends LitElement {
6
+ static styles: import("lit").CSSResult[];
7
+ menus?: Menu[];
8
+ activeMenu?: Menu;
9
+ activeTopLevel?: Menu;
10
+ path?: string;
11
+ render(): import("lit-html").TemplateResult<1>;
12
+ firstUpdated(): void;
13
+ updated(changes: PropertyValues<this>): void;
14
+ private findActivePage;
15
+ }
@@ -0,0 +1,94 @@
1
+ import { __decorate } from "tslib";
2
+ import '@material/mwc-icon';
3
+ import '../src/ox-menu-portrait';
4
+ import { css, html, LitElement } from 'lit';
5
+ import { customElement, property, state } from 'lit/decorators.js';
6
+ import { ScrollbarStyles } from '@operato/styles';
7
+ function isActiveMenu(menu, path) {
8
+ var _a;
9
+ return (((_a = menu.path) === null || _a === void 0 ? void 0 : _a.split('?')[0]) === path ||
10
+ (menu.active && typeof menu.active === 'function' && menu.active.call(menu, { path })));
11
+ }
12
+ let OxMenuContainer = class OxMenuContainer extends LitElement {
13
+ render() {
14
+ return html `
15
+ <div
16
+ @click=${(e) => {
17
+ if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey) {
18
+ return;
19
+ }
20
+ const anchor = e.composedPath().filter((n) => n.tagName === 'A')[0];
21
+ if (!anchor) {
22
+ return;
23
+ }
24
+ const href = anchor.href;
25
+ e.preventDefault();
26
+ var [_, path, ...others] = new URL(href).pathname.split('/');
27
+ this.path = path;
28
+ }}
29
+ >
30
+ <ox-menu-portrait
31
+ .menus=${this.menus}
32
+ .activeTopLevel=${this.activeTopLevel}
33
+ .activeMenu=${this.activeMenu}
34
+ .path=${this.path || ''}
35
+ ></ox-menu-portrait>
36
+ </div>
37
+ `;
38
+ }
39
+ firstUpdated() {
40
+ this.renderRoot.addEventListener('active-toplevel', (e) => {
41
+ e.stopPropagation();
42
+ e.preventDefault();
43
+ this.activeTopLevel = e.detail;
44
+ });
45
+ }
46
+ updated(changes) {
47
+ if (changes.has('menus') || changes.has('path')) {
48
+ this.findActivePage();
49
+ }
50
+ }
51
+ findActivePage() {
52
+ var menus = this.menus || [];
53
+ var activeMenu;
54
+ this.activeTopLevel = menus.find(menu => {
55
+ if (isActiveMenu(menu, this.path)) {
56
+ activeMenu = menu;
57
+ return true;
58
+ }
59
+ else if (menu.menus) {
60
+ activeMenu = menu.menus.find((menu) => isActiveMenu(menu, this.path));
61
+ return !!activeMenu;
62
+ }
63
+ });
64
+ this.activeMenu = activeMenu || this.activeTopLevel;
65
+ }
66
+ };
67
+ OxMenuContainer.styles = [
68
+ ScrollbarStyles,
69
+ css `
70
+ :host {
71
+ display: flex;
72
+ overflow-y: auto;
73
+ flex-direction: column;
74
+ background-color: var(--theme-white-color);
75
+ }
76
+ `
77
+ ];
78
+ __decorate([
79
+ property({ type: Array })
80
+ ], OxMenuContainer.prototype, "menus", void 0);
81
+ __decorate([
82
+ state()
83
+ ], OxMenuContainer.prototype, "activeMenu", void 0);
84
+ __decorate([
85
+ state()
86
+ ], OxMenuContainer.prototype, "activeTopLevel", void 0);
87
+ __decorate([
88
+ state()
89
+ ], OxMenuContainer.prototype, "path", void 0);
90
+ OxMenuContainer = __decorate([
91
+ customElement('ox-menu-container')
92
+ ], OxMenuContainer);
93
+ export { OxMenuContainer };
94
+ //# sourceMappingURL=ox-menu-container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ox-menu-container.js","sourceRoot":"","sources":["../../stories/ox-menu-container.ts"],"names":[],"mappings":";AAAA,OAAO,oBAAoB,CAAA;AAC3B,OAAO,yBAAyB,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAkB,MAAM,KAAK,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAS,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAIjD,S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AAE,IAAI,EAAE,KAAK,EAAE,CAAC;8CAAe;AAEhC;IAAR,KAAK,EAAE;mDAAkB;AACjB;IAAR,KAAK,EAAE;uDAAsB;AACrB;IAAR,KAAK,EAAE;6CAAc;AAjBX,eAAe;IAD3B,aAAa,CAAC,mBAAmB,CAAC;GACtB,eAAe,CA8E3B","sourcesContent":["import '@material/mwc-icon'\nimport '../src/ox-menu-portrait'\n\nimport { css, html, LitElement, PropertyValues } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\n\nimport { ScrollbarStyles } from '@operato/styles'\n\nimport { Menu } from '../src/types'\n\nfunction isActiveMenu(menu: Menu, path?: string) {\n return (\n menu.path?.split('?')[0] === path ||\n (menu.active && typeof menu.active === 'function' && menu.active.call(menu, { path }))\n )\n}\n\n@customElement('ox-menu-container')\nexport class OxMenuContainer extends LitElement {\n static styles = [\n ScrollbarStyles,\n css`\n :host {\n display: flex;\n overflow-y: auto;\n flex-direction: column;\n background-color: var(--theme-white-color);\n }\n `\n ]\n\n @property({ type: Array }) menus?: Menu[]\n\n @state() activeMenu?: Menu\n @state() activeTopLevel?: Menu\n @state() path?: string\n\n render() {\n return html`\n <div\n @click=${(e: MouseEvent) => {\n if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey) {\n return\n }\n const anchor: HTMLAnchorElement = e.composedPath().filter((n: any) => n.tagName === 'A')[0] as any\n if (!anchor) {\n return\n }\n const href = anchor.href\n e.preventDefault()\n\n var [_, path, ...others] = new URL(href).pathname.split('/')\n this.path = path\n }}\n >\n <ox-menu-portrait\n .menus=${this.menus}\n .activeTopLevel=${this.activeTopLevel}\n .activeMenu=${this.activeMenu}\n .path=${this.path || ''}\n ></ox-menu-portrait>\n </div>\n `\n }\n\n firstUpdated() {\n this.renderRoot.addEventListener('active-toplevel', (e: Event) => {\n e.stopPropagation()\n e.preventDefault()\n\n this.activeTopLevel = (e as CustomEvent).detail\n })\n }\n\n updated(changes: PropertyValues<this>) {\n if (changes.has('menus') || changes.has('path')) {\n this.findActivePage()\n }\n }\n\n private findActivePage() {\n var menus = this.menus || []\n var activeMenu\n\n this.activeTopLevel = menus.find(menu => {\n if (isActiveMenu(menu, this.path)) {\n activeMenu = menu\n return true\n } else if (menu.menus) {\n activeMenu = menu.menus.find((menu: Menu) => isActiveMenu(menu, this.path))\n return !!activeMenu\n }\n })\n\n this.activeMenu = activeMenu || this.activeTopLevel\n }\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import '../src/ox-menu-portrait';
2
+ import { TemplateResult } from 'lit';
3
+ import './ox-menu-container';
4
+ declare const _default: {
5
+ title: string;
6
+ component: string;
7
+ argTypes: {};
8
+ };
9
+ export default _default;
10
+ interface Story<T> {
11
+ (args: T): TemplateResult;
12
+ args?: Partial<T>;
13
+ argTypes?: Record<string, unknown>;
14
+ }
15
+ interface ArgTypes {
16
+ }
17
+ export declare const Regular: Story<ArgTypes>;
@@ -0,0 +1,35 @@
1
+ import '../src/ox-menu-portrait';
2
+ import { html } from 'lit';
3
+ import { menus } from './test-menus';
4
+ import './ox-menu-container';
5
+ export default {
6
+ title: 'OxMenuPortrait',
7
+ component: 'ox-menu-portrait',
8
+ argTypes: {}
9
+ };
10
+ const Template = ({}) => html `
11
+ <link href="/themes/app-theme.css" rel="stylesheet" />
12
+ <link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
13
+
14
+ <style>
15
+ body {
16
+ background-color: cyan;
17
+ }
18
+
19
+ .container {
20
+ display: flex;
21
+ width: 260px;
22
+ height: 500px;
23
+ }
24
+
25
+ ox-menu-container {
26
+ flex: 1;
27
+ }
28
+ </style>
29
+
30
+ <div class="container">
31
+ <ox-menu-container .menus=${menus}></ox-menu-container>
32
+ </div>
33
+ `;
34
+ export const Regular = Template.bind({});
35
+ //# sourceMappingURL=ox-menu-portrait.stories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ox-menu-portrait.stories.js","sourceRoot":"","sources":["../../stories/ox-menu-portrait.stories.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA;AAEhC,OAAO,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,qBAAqB,CAAA;AAE5B,eAAe;IACb,KAAK,EAAE,gBAAgB;IACvB,SAAS,EAAE,kBAAkB;IAC7B,QAAQ,EAAE,EAAE;CACb,CAAA;AAUD,MAAM,QAAQ,GAAoB,CAAC,EAAY,EAAE,EAAE,CAAC,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;gCAqBxB,KAAK;;CAEpC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA","sourcesContent":["import '../src/ox-menu-portrait'\n\nimport { html, TemplateResult } from 'lit'\nimport { menus } from './test-menus'\nimport './ox-menu-container'\n\nexport default {\n title: 'OxMenuPortrait',\n component: 'ox-menu-portrait',\n argTypes: {}\n}\n\ninterface Story<T> {\n (args: T): TemplateResult\n args?: Partial<T>\n argTypes?: Record<string, unknown>\n}\n\ninterface ArgTypes {}\n\nconst Template: Story<ArgTypes> = ({}: ArgTypes) => html`\n <link href=\"/themes/app-theme.css\" rel=\"stylesheet\" />\n <link href=\"https://fonts.googleapis.com/css?family=Material+Icons&display=block\" rel=\"stylesheet\" />\n\n <style>\n body {\n background-color: cyan;\n }\n\n .container {\n display: flex;\n width: 260px;\n height: 500px;\n }\n\n ox-menu-container {\n flex: 1;\n }\n </style>\n\n <div class=\"container\">\n <ox-menu-container .menus=${menus}></ox-menu-container>\n </div>\n`\n\nexport const Regular = Template.bind({})\n"]}
@@ -0,0 +1,2 @@
1
+ import { Menu } from '../src/types';
2
+ export declare const menus: Menu[];