@nanoporetech-digital/components 5.2.1 → 5.3.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.
Files changed (259) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/{_commonjsHelpers-9f2314fc.js → _commonjsHelpers-29614748.js} +1 -17
  3. package/dist/cjs/_commonjsHelpers-29614748.js.map +1 -0
  4. package/dist/cjs/algoliasearch-lite.esm.browser-992a2eff.js +922 -0
  5. package/dist/cjs/algoliasearch-lite.esm.browser-992a2eff.js.map +1 -0
  6. package/dist/cjs/component-store-21cb4901.js +328 -0
  7. package/dist/cjs/component-store-21cb4901.js.map +1 -0
  8. package/dist/cjs/events-db0a42ee.js +39 -0
  9. package/dist/cjs/events-db0a42ee.js.map +1 -0
  10. package/dist/cjs/loader.cjs.js +1 -1
  11. package/dist/cjs/nano-alert.cjs.entry.js +9 -2
  12. package/dist/cjs/nano-alert.cjs.entry.js.map +1 -1
  13. package/dist/cjs/nano-algolia-filter.cjs.entry.js +1 -2
  14. package/dist/cjs/nano-algolia-filter.cjs.entry.js.map +1 -1
  15. package/dist/cjs/nano-algolia-input.cjs.entry.js +8 -4
  16. package/dist/cjs/nano-algolia-input.cjs.entry.js.map +1 -1
  17. package/dist/cjs/nano-algolia.cjs.entry.js +4 -4
  18. package/dist/cjs/nano-algolia.cjs.entry.js.map +1 -1
  19. package/dist/cjs/nano-components.cjs.js +1 -1
  20. package/dist/cjs/nano-datalist_3.cjs.entry.js +1 -1
  21. package/dist/cjs/nano-dialog.cjs.entry.js +23 -22
  22. package/dist/cjs/nano-dialog.cjs.entry.js.map +1 -1
  23. package/dist/cjs/nano-drawer.cjs.entry.js +169 -111
  24. package/dist/cjs/nano-drawer.cjs.entry.js.map +1 -1
  25. package/dist/cjs/nano-dropdown.cjs.entry.js +16 -2
  26. package/dist/cjs/nano-dropdown.cjs.entry.js.map +1 -1
  27. package/dist/cjs/nano-global-nav.cjs.entry.js +5 -6
  28. package/dist/cjs/nano-global-nav.cjs.entry.js.map +1 -1
  29. package/dist/cjs/nano-global-search-results.cjs.entry.js +2 -1
  30. package/dist/cjs/nano-global-search-results.cjs.entry.js.map +1 -1
  31. package/dist/cjs/nano-slides.cjs.entry.js +1 -1
  32. package/dist/cjs/nano-sortable.cjs.entry.js +3 -15
  33. package/dist/cjs/nano-sortable.cjs.entry.js.map +1 -1
  34. package/dist/cjs/nano-sticker.cjs.entry.js +16 -9
  35. package/dist/cjs/nano-sticker.cjs.entry.js.map +1 -1
  36. package/dist/cjs/nano-tab-group.cjs.entry.js +1 -2
  37. package/dist/cjs/nano-tab-group.cjs.entry.js.map +1 -1
  38. package/dist/cjs/{nano-table-10a40ab3.js → nano-table-e15cc6b0.js} +6 -6
  39. package/dist/cjs/nano-table-e15cc6b0.js.map +1 -0
  40. package/dist/cjs/nano-table.cjs.entry.js +1 -1
  41. package/dist/cjs/{slot-a448c1a7.js → slot-2dd6ed1d.js} +20 -15
  42. package/dist/cjs/slot-2dd6ed1d.js.map +1 -0
  43. package/dist/cjs/{table.worker-f04588c1.js → table.worker-8759e6ea.js} +2 -2
  44. package/dist/cjs/table.worker-8759e6ea.js.map +1 -0
  45. package/dist/collection/components/alert/alert.css +15 -0
  46. package/dist/collection/components/alert/alert.js +10 -2
  47. package/dist/collection/components/alert/alert.js.map +1 -1
  48. package/dist/collection/components/algolia/algolia-interface.js.map +1 -1
  49. package/dist/collection/components/algolia/algolia.js +1 -1
  50. package/dist/collection/components/algolia/algolia.js.map +1 -1
  51. package/dist/collection/components/dialog/dialog.css +1 -17
  52. package/dist/collection/components/dialog/dialog.js +31 -20
  53. package/dist/collection/components/dialog/dialog.js.map +1 -1
  54. package/dist/collection/components/drawer/drawer.css +136 -67
  55. package/dist/collection/components/drawer/drawer.js +282 -154
  56. package/dist/collection/components/drawer/drawer.js.map +1 -1
  57. package/dist/collection/components/dropdown/dropdown.css +10 -0
  58. package/dist/collection/components/dropdown/dropdown.js +15 -1
  59. package/dist/collection/components/dropdown/dropdown.js.map +1 -1
  60. package/dist/collection/components/global-nav/global-nav.js +2 -2
  61. package/dist/collection/components/global-nav/global-nav.js.map +1 -1
  62. package/dist/collection/components/global-nav/style/global-nav.css +5 -1
  63. package/dist/collection/components/global-search-results/global-search-results.js +2 -1
  64. package/dist/collection/components/global-search-results/global-search-results.js.map +1 -1
  65. package/dist/collection/components/sticker/sticker.js +16 -9
  66. package/dist/collection/components/sticker/sticker.js.map +1 -1
  67. package/dist/collection/components/table/table.pin-service.js +4 -4
  68. package/dist/collection/components/table/table.pin-service.js.map +1 -1
  69. package/dist/collection/utils/events.js +17 -0
  70. package/dist/collection/utils/events.js.map +1 -1
  71. package/dist/collection/utils/slot.js +19 -14
  72. package/dist/collection/utils/slot.js.map +1 -1
  73. package/dist/collection/utils/store/get-set.js +6 -12
  74. package/dist/collection/utils/store/get-set.js.map +1 -1
  75. package/dist/components/_commonjsHelpers.js +1 -16
  76. package/dist/components/_commonjsHelpers.js.map +1 -1
  77. package/dist/components/algolia.js +2 -2
  78. package/dist/components/algolia.js.map +1 -1
  79. package/dist/components/algoliasearch-lite.esm.browser.js +920 -0
  80. package/dist/components/algoliasearch-lite.esm.browser.js.map +1 -0
  81. package/dist/components/component-store.js +68 -2001
  82. package/dist/components/component-store.js.map +1 -1
  83. package/dist/components/dropdown.js +16 -2
  84. package/dist/components/dropdown.js.map +1 -1
  85. package/dist/components/events.js +36 -0
  86. package/dist/components/events.js.map +1 -0
  87. package/dist/components/nano-alert.js +10 -2
  88. package/dist/components/nano-alert.js.map +1 -1
  89. package/dist/components/nano-algolia-input.js +6 -1
  90. package/dist/components/nano-algolia-input.js.map +1 -1
  91. package/dist/components/nano-dialog.js +21 -20
  92. package/dist/components/nano-dialog.js.map +1 -1
  93. package/dist/components/nano-drawer.js +205 -122
  94. package/dist/components/nano-drawer.js.map +1 -1
  95. package/dist/components/nano-global-nav.js +4 -4
  96. package/dist/components/nano-global-nav.js.map +1 -1
  97. package/dist/components/nano-global-search-results.js +2 -1
  98. package/dist/components/nano-global-search-results.js.map +1 -1
  99. package/dist/components/nano-sortable.js +1 -13
  100. package/dist/components/nano-sortable.js.map +1 -1
  101. package/dist/components/slot.js +19 -14
  102. package/dist/components/slot.js.map +1 -1
  103. package/dist/components/sticker.js +16 -9
  104. package/dist/components/sticker.js.map +1 -1
  105. package/dist/components/table.js +4 -4
  106. package/dist/components/table.js.map +1 -1
  107. package/dist/esm/{_commonjsHelpers-e401b2a2.js → _commonjsHelpers-04a0e019.js} +2 -17
  108. package/dist/esm/_commonjsHelpers-04a0e019.js.map +1 -0
  109. package/dist/esm/algoliasearch-lite.esm.browser-04891fdc.js +920 -0
  110. package/dist/esm/algoliasearch-lite.esm.browser-04891fdc.js.map +1 -0
  111. package/dist/esm/component-store-65d7e36a.js +326 -0
  112. package/dist/esm/component-store-65d7e36a.js.map +1 -0
  113. package/dist/esm/events-6a805b42.js +36 -0
  114. package/dist/esm/events-6a805b42.js.map +1 -0
  115. package/dist/esm/loader.js +1 -1
  116. package/dist/esm/nano-alert.entry.js +9 -2
  117. package/dist/esm/nano-alert.entry.js.map +1 -1
  118. package/dist/esm/nano-algolia-filter.entry.js +1 -2
  119. package/dist/esm/nano-algolia-filter.entry.js.map +1 -1
  120. package/dist/esm/nano-algolia-input.entry.js +7 -3
  121. package/dist/esm/nano-algolia-input.entry.js.map +1 -1
  122. package/dist/esm/nano-algolia.entry.js +4 -4
  123. package/dist/esm/nano-algolia.entry.js.map +1 -1
  124. package/dist/esm/nano-components.js +1 -1
  125. package/dist/esm/nano-datalist_3.entry.js +1 -1
  126. package/dist/esm/nano-dialog.entry.js +23 -22
  127. package/dist/esm/nano-dialog.entry.js.map +1 -1
  128. package/dist/esm/nano-drawer.entry.js +171 -113
  129. package/dist/esm/nano-drawer.entry.js.map +1 -1
  130. package/dist/esm/nano-dropdown.entry.js +16 -2
  131. package/dist/esm/nano-dropdown.entry.js.map +1 -1
  132. package/dist/esm/nano-global-nav.entry.js +5 -6
  133. package/dist/esm/nano-global-nav.entry.js.map +1 -1
  134. package/dist/esm/nano-global-search-results.entry.js +2 -1
  135. package/dist/esm/nano-global-search-results.entry.js.map +1 -1
  136. package/dist/esm/nano-slides.entry.js +1 -1
  137. package/dist/esm/nano-sortable.entry.js +1 -13
  138. package/dist/esm/nano-sortable.entry.js.map +1 -1
  139. package/dist/esm/nano-sticker.entry.js +16 -9
  140. package/dist/esm/nano-sticker.entry.js.map +1 -1
  141. package/dist/esm/nano-tab-group.entry.js +1 -2
  142. package/dist/esm/nano-tab-group.entry.js.map +1 -1
  143. package/dist/esm/{nano-table-2bbcaa8d.js → nano-table-5c5bd3f2.js} +6 -6
  144. package/dist/esm/nano-table-5c5bd3f2.js.map +1 -0
  145. package/dist/esm/nano-table.entry.js +1 -1
  146. package/dist/esm/{slot-a4f6e2af.js → slot-8126e238.js} +20 -15
  147. package/dist/esm/slot-8126e238.js.map +1 -0
  148. package/dist/esm/{table.worker-7324ad73.js → table.worker-e7f4f50c.js} +2 -2
  149. package/dist/esm/table.worker-e7f4f50c.js.map +1 -0
  150. package/dist/nano-components/nano-components.css +1 -1
  151. package/dist/nano-components/nano-components.esm.js +1 -1
  152. package/dist/nano-components/nano-components.esm.js.map +1 -1
  153. package/dist/nano-components/p-0301e8f7.entry.js +5 -0
  154. package/dist/nano-components/p-0301e8f7.entry.js.map +1 -0
  155. package/dist/nano-components/p-27422aa9.entry.js +5 -0
  156. package/dist/nano-components/{p-6920ad69.entry.js.map → p-27422aa9.entry.js.map} +1 -1
  157. package/dist/nano-components/{p-52ae36ec.js → p-2d79f5b3.js} +2 -2
  158. package/dist/nano-components/{p-0697795a.entry.js → p-31c23d6e.entry.js} +2 -2
  159. package/dist/nano-components/p-31c23d6e.entry.js.map +1 -0
  160. package/dist/nano-components/p-487de04d.entry.js.map +1 -1
  161. package/dist/nano-components/p-570d2e50.entry.js +5 -0
  162. package/dist/nano-components/p-570d2e50.entry.js.map +1 -0
  163. package/dist/nano-components/{p-3eb6d833.entry.js → p-5a4b3fa9.entry.js} +2 -2
  164. package/dist/nano-components/p-653ae985.js +5 -0
  165. package/dist/nano-components/p-653ae985.js.map +1 -0
  166. package/dist/nano-components/p-676a4744.entry.js +5 -0
  167. package/dist/nano-components/{p-d0eefd52.entry.js.map → p-676a4744.entry.js.map} +1 -1
  168. package/dist/nano-components/p-8fe51abf.js +5 -0
  169. package/dist/nano-components/{p-4884b65a.entry.js → p-90cd4f56.entry.js} +2 -2
  170. package/dist/nano-components/p-90cd4f56.entry.js.map +1 -0
  171. package/dist/nano-components/p-9ba81ed2.js +5 -0
  172. package/dist/nano-components/p-9ba81ed2.js.map +1 -0
  173. package/dist/nano-components/p-9bfdee71.js +5 -0
  174. package/dist/nano-components/p-9bfdee71.js.map +1 -0
  175. package/dist/nano-components/p-a8d6ca38.entry.js +5 -0
  176. package/dist/nano-components/p-a8d6ca38.entry.js.map +1 -0
  177. package/dist/nano-components/p-ace7743c.entry.js +5 -0
  178. package/dist/nano-components/p-ace7743c.entry.js.map +1 -0
  179. package/dist/nano-components/{p-39aec880.entry.js → p-bab2888b.entry.js} +2 -2
  180. package/dist/nano-components/p-bdb5b6fc.entry.js +5 -0
  181. package/dist/nano-components/p-bdb5b6fc.entry.js.map +1 -0
  182. package/dist/nano-components/p-cad86fb8.js +5 -0
  183. package/dist/nano-components/p-cad86fb8.js.map +1 -0
  184. package/dist/nano-components/p-dc565459.js +5 -0
  185. package/dist/nano-components/p-dc565459.js.map +1 -0
  186. package/dist/nano-components/p-ede12d35.entry.js +5 -0
  187. package/dist/nano-components/p-ede12d35.entry.js.map +1 -0
  188. package/dist/nano-components/p-f504b1df.entry.js +7 -0
  189. package/dist/nano-components/p-f504b1df.entry.js.map +1 -0
  190. package/dist/nano-components/{p-db370094.entry.js → p-f7a4c62b.entry.js} +2 -2
  191. package/dist/themes/london-calling.css.map +1 -1
  192. package/dist/themes/nanopore.cn.css.map +1 -1
  193. package/dist/themes/nanopore.css.map +1 -1
  194. package/dist/types/components/alert/alert.d.ts +1 -0
  195. package/dist/types/components/algolia/algolia-interface.d.ts +1 -1
  196. package/dist/types/components/algolia/algolia.d.ts +1 -1
  197. package/dist/types/components/dialog/dialog.d.ts +15 -4
  198. package/dist/types/components/drawer/drawer.d.ts +69 -50
  199. package/dist/types/components/sticker/sticker.d.ts +4 -4
  200. package/dist/types/components.d.ts +50 -28
  201. package/dist/types/types/algolia.d.ts +4 -0
  202. package/dist/types/types/scss.vars.d.ts +4 -0
  203. package/dist/types/utils/events.d.ts +7 -0
  204. package/dist/types/utils/slot.d.ts +3 -3
  205. package/docs-json.json +268 -61
  206. package/docs-vscode.json +28 -11
  207. package/hydrate/index.js +1335 -2236
  208. package/package.json +4 -4
  209. package/dist/cjs/_commonjsHelpers-9f2314fc.js.map +0 -1
  210. package/dist/cjs/algoliasearch.umd-689c1560.js +0 -15
  211. package/dist/cjs/algoliasearch.umd-689c1560.js.map +0 -1
  212. package/dist/cjs/component-store-f1dc1276.js +0 -2261
  213. package/dist/cjs/component-store-f1dc1276.js.map +0 -1
  214. package/dist/cjs/nano-table-10a40ab3.js.map +0 -1
  215. package/dist/cjs/slot-a448c1a7.js.map +0 -1
  216. package/dist/cjs/table.worker-f04588c1.js.map +0 -1
  217. package/dist/components/algoliasearch.umd.js +0 -13
  218. package/dist/components/algoliasearch.umd.js.map +0 -1
  219. package/dist/esm/_commonjsHelpers-e401b2a2.js.map +0 -1
  220. package/dist/esm/algoliasearch.umd-4f7efa84.js +0 -13
  221. package/dist/esm/algoliasearch.umd-4f7efa84.js.map +0 -1
  222. package/dist/esm/component-store-c23ebc9c.js +0 -2259
  223. package/dist/esm/component-store-c23ebc9c.js.map +0 -1
  224. package/dist/esm/nano-table-2bbcaa8d.js.map +0 -1
  225. package/dist/esm/slot-a4f6e2af.js.map +0 -1
  226. package/dist/esm/table.worker-7324ad73.js.map +0 -1
  227. package/dist/nano-components/p-0697795a.entry.js.map +0 -1
  228. package/dist/nano-components/p-17b099cc.entry.js +0 -5
  229. package/dist/nano-components/p-17b099cc.entry.js.map +0 -1
  230. package/dist/nano-components/p-1a0b5bc3.js +0 -5
  231. package/dist/nano-components/p-1a0b5bc3.js.map +0 -1
  232. package/dist/nano-components/p-4884b65a.entry.js.map +0 -1
  233. package/dist/nano-components/p-58cf5446.js +0 -5
  234. package/dist/nano-components/p-58cf5446.js.map +0 -1
  235. package/dist/nano-components/p-6920ad69.entry.js +0 -5
  236. package/dist/nano-components/p-69a3e911.js +0 -5
  237. package/dist/nano-components/p-7baa9e14.entry.js +0 -5
  238. package/dist/nano-components/p-7baa9e14.entry.js.map +0 -1
  239. package/dist/nano-components/p-9b533dc3.js +0 -5
  240. package/dist/nano-components/p-9b533dc3.js.map +0 -1
  241. package/dist/nano-components/p-a362bd23.entry.js +0 -5
  242. package/dist/nano-components/p-a362bd23.entry.js.map +0 -1
  243. package/dist/nano-components/p-b04fd7ca.entry.js +0 -5
  244. package/dist/nano-components/p-b04fd7ca.entry.js.map +0 -1
  245. package/dist/nano-components/p-b72df1aa.entry.js +0 -5
  246. package/dist/nano-components/p-b72df1aa.entry.js.map +0 -1
  247. package/dist/nano-components/p-ce5efc3f.entry.js +0 -5
  248. package/dist/nano-components/p-ce5efc3f.entry.js.map +0 -1
  249. package/dist/nano-components/p-d0eefd52.entry.js +0 -5
  250. package/dist/nano-components/p-e2b2b015.entry.js +0 -5
  251. package/dist/nano-components/p-e2b2b015.entry.js.map +0 -1
  252. package/dist/nano-components/p-ed6adde2.js +0 -7
  253. package/dist/nano-components/p-ed6adde2.js.map +0 -1
  254. package/dist/types/dom.ie.d.ts +0 -3
  255. /package/dist/nano-components/{p-39aec880.entry.js.map → p-2d79f5b3.js.map} +0 -0
  256. /package/dist/nano-components/{p-3eb6d833.entry.js.map → p-5a4b3fa9.entry.js.map} +0 -0
  257. /package/dist/nano-components/{p-52ae36ec.js.map → p-8fe51abf.js.map} +0 -0
  258. /package/dist/nano-components/{p-69a3e911.js.map → p-bab2888b.entry.js.map} +0 -0
  259. /package/dist/nano-components/{p-db370094.entry.js.map → p-f7a4c62b.entry.js.map} +0 -0
@@ -1,154 +1,223 @@
1
1
  /*!
2
2
  * Web Components for Nanopore digital Web Apps
3
3
  */
4
- import { h, Host, } from '@stencil/core';
4
+ import { h, } from '@stencil/core';
5
5
  import Modal from '../../utils/modal';
6
6
  import { lockBodyScrolling, unlockBodyScrolling } from '../../utils/scroll';
7
- let id = 0;
7
+ import { hasSlot } from '../../utils/slot';
8
+ import { waitForEvent } from '../../utils/events';
9
+ import { ComponentStore, } from '../../utils/store/component-store';
8
10
  /**
9
- * WIP / TODO. https://git.oxfordnanolabs.local/Digital/nano-components/-/issues/24
10
- * @slot - The drawer's content.
11
- * @slot label - The dialog's label. Alternatively, you can use the label prop.
12
- * @slot footer - The drawer's footer, usually one or more buttons representing various options.
11
+ * Drawers slide in from a container to expose additional options and information.
12
+ *
13
+ * @slot - The drawer's main content
14
+ * @slot label - The drawer's label. Alternatively, you can use the `label` attribute
15
+ * @slot header-actions - Optional actions to add to the header. Works best with `<nano-icon-button>`
16
+ * @slot footer - The drawer's footer, usually one or more buttons representing various options
17
+ *
18
+ * @part base - The component's base wrapper
19
+ * @part overlay - The overlay that covers the screen behind the drawer
20
+ * @part panel - The drawer's panel (where the drawer and its content are rendered)
21
+ * @part header - The drawer's header. This element wraps the title and header actions
22
+ * @part header-actions - Optional actions to add to the header. Works best with `<nano-icon-button>`
23
+ * @part title - The drawer's title
24
+ * @part close-button - The close button, an `<nano-icon-button>`
25
+ * @part close-button__base - The close button's exported `base` part
26
+ * @part body - The drawer's body
27
+ * @part footer - The drawer's footer
13
28
  */
14
29
  export class Drawer {
15
30
  constructor() {
16
- this.componentId = `drawer-${++id}`;
17
- this.hasFooter = false;
18
- this.isVisible = false;
31
+ this.handleDocumentKeyDown = (event) => {
32
+ // Contained drawers aren't modal and don't response to the escape key
33
+ if (this.contained) {
34
+ return;
35
+ }
36
+ if (event.key === 'Escape' && this.modal.isActive() && this.open) {
37
+ event.stopImmediatePropagation();
38
+ this.requestClose('keyboard');
39
+ }
40
+ };
41
+ this.handleTransitionEnd = (event) => {
42
+ if (event.propertyName === 'opacity' &&
43
+ event
44
+ .composedPath()
45
+ .find((node) => node === this.panel || node === this.overlay)) {
46
+ if (!this.open) {
47
+ this.drawer.hidden = true;
48
+ // Now that the dialog is hidden, restore the overlay and panel for next time
49
+ this.overlay.hidden = false;
50
+ this.panel.hidden = false;
51
+ }
52
+ this.open ? this.nanoAfterShow.emit() : this.nanoAfterHide.emit();
53
+ }
54
+ };
55
+ this.handleSlotChange = () => {
56
+ this.hasFooter = hasSlot(this.host, 'footer');
57
+ };
58
+ this.noDismiss = false;
59
+ this.hasFooter = undefined;
19
60
  this.open = false;
20
- this.label = '';
61
+ this.label = undefined;
21
62
  this.placement = 'end';
22
63
  this.contained = false;
23
64
  this.noHeader = false;
24
- this.type = 'overlay';
25
- this.contentSelector = undefined;
65
+ this.storeId = undefined;
66
+ this.storeMethod = 'url-hash';
67
+ this.noUserDismiss = false;
68
+ this.hoist = false;
26
69
  }
27
- handleOpenChange() {
28
- this.open ? this.show() : this.hide();
70
+ get panel() {
71
+ return this._panel;
29
72
  }
30
- handleTypeChange() {
31
- if (this.type !== 'push' && this.type !== 'reveal')
32
- return;
33
- if (!this.contentEle) {
34
- this.type = 'overlay';
35
- console.warn('a valid contentSelector must be set');
36
- return;
73
+ set panel(ele) {
74
+ if (this._panel) {
75
+ this.panel.removeEventListener('animationend', this.handleTransitionEnd);
37
76
  }
77
+ if (!ele)
78
+ return;
79
+ ele.addEventListener('transitionend', this.handleTransitionEnd);
80
+ this._panel = ele;
38
81
  }
39
- handleContentSelector() {
40
- if (!this.contentSelector)
41
- this.contentEle = null;
42
- else
43
- this.contentEle = this.host.ownerDocument.querySelector(this.contentSelector);
44
- }
45
- connectedCallback() {
46
- this.handleCloseClick = this.handleCloseClick.bind(this);
47
- this.handleTransitionEnd = this.handleTransitionEnd.bind(this);
48
- this.handleKeyDown = this.handleKeyDown.bind(this);
49
- this.handleOverlayClick = this.handleOverlayClick.bind(this);
50
- this.handleSlotChange = this.handleSlotChange.bind(this);
51
- this.modal = new Modal(this.host);
82
+ handleHoistChange() {
83
+ if (!this.hoist || Array.from(document.body.children).includes(this.host))
84
+ return;
85
+ document.body.prepend(this.host);
52
86
  }
53
- componentWillLoad() {
54
- // Show on init if open
55
- if (this.open) {
56
- this.show();
57
- }
58
- this.handleContentSelector();
87
+ /** Shows the drawer. */
88
+ async show() {
89
+ if (this.open)
90
+ return undefined;
91
+ this.open = true;
92
+ return waitForEvent(this.host, 'nanoAfterShow');
59
93
  }
60
- disconnectedCallback() {
61
- unlockBodyScrolling(this.host);
94
+ /** Hides the drawer */
95
+ async hide() {
96
+ if (!this.open)
97
+ return undefined;
98
+ this.open = false;
99
+ return waitForEvent(this.host, 'nanoAfterHide');
62
100
  }
63
- /** Shows the drawer */
64
- async show() {
65
- // Prevent subsequent calls to the method, whether manually or triggered by the `open` watcher
66
- if (this.isVisible) {
101
+ requestClose(source) {
102
+ const nanoRequestClose = this.nanoRquestClose.emit({ source });
103
+ if (nanoRequestClose.defaultPrevented || this.noUserDismiss) {
104
+ this.noDismiss = true;
105
+ setTimeout(() => (this.noDismiss = false), 250);
67
106
  return;
68
107
  }
69
- const nanoShow = this.nanoShow.emit();
70
- if (nanoShow.defaultPrevented) {
71
- this.open = false;
72
- return;
73
- }
74
- this.isVisible = true;
75
- this.open = true;
76
- // Lock body scrolling only if the drawer isn't contained
77
- if (!this.contained) {
108
+ this.hide();
109
+ }
110
+ // Prop Change Handlers
111
+ handleNoModalChange() {
112
+ if (this.open && !this.contained) {
78
113
  this.modal.activate();
79
114
  lockBodyScrolling(this.host);
80
115
  }
81
- if (!this.contentEle || (this.type !== 'push' && this.type !== 'reveal'))
82
- return;
83
- this.contentEle.style.right = '0';
84
- this.contentEle.style.transition = 'all ease 250ms';
85
- this.contentEle.style.position = 'relative';
86
- this.contentEle.style.overflow = 'hidden';
87
- setTimeout((_) => (this.contentEle.style.right = '25rem'), 0);
116
+ if (this.open && this.contained) {
117
+ this.modal.deactivate();
118
+ unlockBodyScrolling(this.host);
119
+ }
88
120
  }
89
- /** Hides the drawer */
90
- async hide() {
91
- // Prevent subsequent calls to the method, whether manually or triggered by the `open` watcher
92
- if (!this.isVisible) {
121
+ async handleOpenChange() {
122
+ if (this.open) {
123
+ // Show
124
+ this.nanoShow.emit();
125
+ this.addOpenListeners();
126
+ this.originalTrigger = document.activeElement;
127
+ // Lock body scrolling only if the drawer isn't contained
128
+ if (!this.contained) {
129
+ this.modal.activate();
130
+ lockBodyScrolling(this.host);
131
+ }
132
+ // When the drawer is shown, Safari will attempt to set focus on whatever element has autofocus. This causes the
133
+ // drawer's animation to jitter, so we'll temporarily remove the attribute, call `focus({ preventScroll: true })`
134
+ // ourselves, and add the attribute back afterwards.
135
+ const autoFocusTarget = this.host.querySelector('[autofocus]');
136
+ if (autoFocusTarget) {
137
+ autoFocusTarget.removeAttribute('autofocus');
138
+ }
139
+ this.drawer.hidden = false;
140
+ // Set initial focus
141
+ requestAnimationFrame(() => {
142
+ const nanoInitialFocus = this.nanoInitialFocus.emit();
143
+ if (!nanoInitialFocus.defaultPrevented) {
144
+ // Set focus to the autofocus target and restore the attribute
145
+ if (autoFocusTarget) {
146
+ autoFocusTarget.focus({
147
+ preventScroll: true,
148
+ });
149
+ }
150
+ else {
151
+ this.panel.focus({ preventScroll: true });
152
+ }
153
+ }
154
+ // Restore the autofocus attribute
155
+ if (autoFocusTarget) {
156
+ autoFocusTarget.setAttribute('autofocus', '');
157
+ }
158
+ });
159
+ this.nanoAfterShow.emit();
93
160
  return;
94
161
  }
95
- const nanoHide = this.nanoHide.emit();
96
- if (nanoHide.defaultPrevented) {
97
- this.open = true;
98
- return;
162
+ // Hide
163
+ this.nanoHide.emit();
164
+ this.removeOpenListeners();
165
+ if (!this.contained) {
166
+ this.modal.deactivate();
167
+ unlockBodyScrolling(this.host);
168
+ }
169
+ // Restore focus to the original trigger
170
+ const trigger = this.originalTrigger;
171
+ if (typeof (trigger === null || trigger === void 0 ? void 0 : trigger.focus) === 'function') {
172
+ setTimeout(() => trigger.focus());
99
173
  }
100
- this.open = false;
101
- this.modal.deactivate();
102
- unlockBodyScrolling(this.host);
103
- if (!this.contentEle)
104
- return;
105
- this.contentEle.style.transition = '';
106
- this.contentEle.style.position = '';
107
- this.contentEle.style.overflow = '';
108
- this.contentEle.style.right = '';
109
174
  }
110
- handleCloseClick() {
111
- this.hide();
175
+ // Event Handling
176
+ addOpenListeners() {
177
+ document.addEventListener('keydown', this.handleDocumentKeyDown);
112
178
  }
113
- handleKeyDown(event) {
114
- if (event.key === 'Escape') {
115
- this.hide();
116
- }
179
+ removeOpenListeners() {
180
+ document.removeEventListener('keydown', this.handleDocumentKeyDown);
117
181
  }
118
- handleOverlayClick() {
119
- const slOverlayDismiss = this.nanoOverlayDismiss.emit();
120
- if (!slOverlayDismiss.defaultPrevented) {
121
- this.hide();
122
- }
182
+ // Component Lifecycle
183
+ connectedCallback() {
184
+ this.handleHoistChange();
185
+ this.modal = new Modal(this.host);
123
186
  }
124
- handleSlotChange() {
125
- this.hasFooter = !!this.host.querySelector('[slot="footer"]');
187
+ disconnectedCallback() {
188
+ unlockBodyScrolling(this.host);
126
189
  }
127
- handleTransitionEnd(event) {
128
- const target = event.target;
129
- // Ensure we only emit one event when the target element is no longer visible
130
- if (event.propertyName === 'transform' &&
131
- target.classList.contains('drawer__panel')) {
132
- this.isVisible = this.open;
133
- this.open ? this.nanoAfterShow.emit() : this.nanoAfterHide.emit();
134
- if (this.open) {
135
- this.panel.focus();
190
+ componentWillLoad() {
191
+ this.handleSlotChange();
192
+ // Show on init if open
193
+ if (this.open)
194
+ this.show();
195
+ if (this.storeId)
196
+ ComponentStore.init(this, ['open'], this.storeMethod, this.storeId);
197
+ }
198
+ componentDidLoad() {
199
+ this.drawer.hidden = !this.open;
200
+ if (this.open) {
201
+ this.addOpenListeners();
202
+ if (!this.contained) {
203
+ this.modal.activate();
204
+ lockBodyScrolling(this.host);
136
205
  }
137
206
  }
138
207
  }
139
208
  render() {
140
- const placementClass = 'drawer--' + this.placement;
141
- const typeClass = 'drawer--' + this.type;
142
- return (h(Host, null, h("div", { part: "base", class: {
209
+ return (h("div", { ref: (ele) => (this.drawer = ele), part: "base", class: {
143
210
  drawer: true,
144
211
  'drawer--open': this.open,
145
- 'drawer--visible': this.isVisible,
146
- [typeClass]: true,
147
- [placementClass]: true,
212
+ [`drawer--${this.placement}`]: true,
148
213
  'drawer--contained': this.contained,
149
214
  'drawer--fixed': !this.contained,
150
- 'drawer--has-footer': this.hasFooter,
151
- }, onKeyDown: this.handleKeyDown, onTransitionEnd: this.handleTransitionEnd }, h("div", { part: "overlay", class: "drawer__overlay", onClick: this.handleOverlayClick }), h("div", { ref: (el) => (this.panel = el), part: "panel", class: "drawer__panel", role: "dialog", "aria-modal": "true", "aria-hidden": this.open ? 'false' : 'true', "aria-label": this.noHeader ? this.label : null, "aria-labelledby": !this.noHeader ? `${this.componentId}-title` : null, tabIndex: 0 }, !this.noHeader && (h("header", { part: "header", class: "drawer__header" }, h("span", { part: "title", class: "drawer__title", id: `${this.componentId}-title` }, h("slot", { name: "label" }, this.label || String.fromCharCode(65279))))), h("div", { part: "body", class: "drawer__body" }, h("slot", null)), h("footer", { part: "footer", class: "drawer__footer" }, h("slot", { name: "footer", onSlotchange: this.handleSlotChange }))))));
215
+ 'drawer--has-footer': hasSlot(this.host, 'footer'),
216
+ 'drawer--has-header': !this.noHeader,
217
+ 'drawer--nodismiss': this.noDismiss,
218
+ } }, h("div", { ref: (ele) => (this.overlay = ele), part: "overlay", class: "drawer__overlay", onClick: () => this.requestClose('overlay'), tabindex: "-1" }), h("div", { ref: (ele) => (this.panel = ele), part: "panel", class: "drawer__panel", role: "dialog", "aria-modal": "true", "aria-hidden": this.open ? 'false' : 'true', "aria-label": this.noHeader ? this.label : undefined, "aria-labelledby": !this.noHeader ? 'title' : undefined, tabindex: "0" }, h("div", { class: "drawer__main" }, !this.noHeader && (h("nano-sticker", null, h("header", { part: "header", class: "drawer__header" }, h("h2", { part: "title", class: "drawer__title", id: "title" }, h("slot", { name: "label" }, this.label.length > 0
219
+ ? this.label
220
+ : String.fromCharCode(65279))), h("div", { part: "header-actions", class: "drawer__header-actions" }, h("slot", { name: "header-actions" }), !this.noUserDismiss && (h("nano-icon-button", { part: "close-button", exportparts: "base:close-button__base", class: "drawer__close", iconName: "light/times", label: "Close", onClick: () => this.requestClose('close-button') })))))), h("div", { part: "body", class: "drawer__body" }, h("slot", null)), h("nano-sticker", { position: "bottom" }, h("footer", { part: "footer", class: "drawer__footer" }, h("slot", { name: "footer", onSlotchange: this.handleSlotChange })))))));
152
221
  }
153
222
  static get is() { return "nano-drawer"; }
154
223
  static get encapsulation() { return "shadow"; }
@@ -166,7 +235,7 @@ export class Drawer {
166
235
  return {
167
236
  "open": {
168
237
  "type": "boolean",
169
- "mutable": true,
238
+ "mutable": false,
170
239
  "complexType": {
171
240
  "original": "boolean",
172
241
  "resolved": "boolean",
@@ -176,7 +245,7 @@ export class Drawer {
176
245
  "optional": false,
177
246
  "docs": {
178
247
  "tags": [],
179
- "text": "Indicates whether or not the drawer is open. You can use this in lieu of the show/hide methods."
248
+ "text": "Indicates whether or not the drawer is open. You can toggle this attribute to show and hide the drawer, or you can\nuse the `show()` and `hide()` methods and this attribute will reflect the drawer's open state."
180
249
  },
181
250
  "getter": false,
182
251
  "setter": false,
@@ -192,17 +261,16 @@ export class Drawer {
192
261
  "resolved": "string",
193
262
  "references": {}
194
263
  },
195
- "required": false,
264
+ "required": true,
196
265
  "optional": false,
197
266
  "docs": {
198
267
  "tags": [],
199
- "text": "The drawer's label as displayed in the header. You should always include a relevant label even when using\n`no-header`, as it is required for proper accessibility."
268
+ "text": "The drawer's label as displayed in the header. You should always include a relevant label even when using\n`no-header`, as it is required for proper accessibility. If you need to display HTML, use the `label` slot instead."
200
269
  },
201
270
  "getter": false,
202
271
  "setter": false,
203
272
  "attribute": "label",
204
- "reflect": false,
205
- "defaultValue": "''"
273
+ "reflect": true
206
274
  },
207
275
  "placement": {
208
276
  "type": "string",
@@ -221,7 +289,7 @@ export class Drawer {
221
289
  "getter": false,
222
290
  "setter": false,
223
291
  "attribute": "placement",
224
- "reflect": false,
292
+ "reflect": true,
225
293
  "defaultValue": "'end'"
226
294
  },
227
295
  "contained": {
@@ -236,12 +304,12 @@ export class Drawer {
236
304
  "optional": false,
237
305
  "docs": {
238
306
  "tags": [],
239
- "text": "By default, the drawer slides out of its containing block (usually the viewport). To make the drawer slide out of\nits parent element, set this prop and add `position: relative` to the parent."
307
+ "text": "By default, the drawer slides out of its containing block (usually the viewport). To make the drawer slide out of\nits parent element, set this attribute and add `position: relative` to the parent."
240
308
  },
241
309
  "getter": false,
242
310
  "setter": false,
243
311
  "attribute": "contained",
244
- "reflect": false,
312
+ "reflect": true,
245
313
  "defaultValue": "false"
246
314
  },
247
315
  "noHeader": {
@@ -261,54 +329,99 @@ export class Drawer {
261
329
  "getter": false,
262
330
  "setter": false,
263
331
  "attribute": "no-header",
264
- "reflect": false,
332
+ "reflect": true,
265
333
  "defaultValue": "false"
266
334
  },
267
- "type": {
335
+ "storeId": {
268
336
  "type": "string",
269
337
  "mutable": false,
270
338
  "complexType": {
271
- "original": "'overlay' | 'reveal' | 'push'",
272
- "resolved": "\"overlay\" | \"push\" | \"reveal\"",
339
+ "original": "string",
340
+ "resolved": "string",
273
341
  "references": {}
274
342
  },
275
343
  "required": false,
344
+ "optional": true,
345
+ "docs": {
346
+ "tags": [],
347
+ "text": "Store search queries (against this ID) to the component store. Use in conjunction with storeMethod"
348
+ },
349
+ "getter": false,
350
+ "setter": false,
351
+ "attribute": "store-id",
352
+ "reflect": false
353
+ },
354
+ "storeMethod": {
355
+ "type": "string",
356
+ "mutable": false,
357
+ "complexType": {
358
+ "original": "StorageMethods",
359
+ "resolved": "\"local\" | \"session\" | \"url-hash\" | \"url-hash-push\" | \"url-query\" | \"url-query-push\"",
360
+ "references": {
361
+ "StorageMethods": {
362
+ "location": "import",
363
+ "path": "../../utils/store/component-store"
364
+ }
365
+ }
366
+ },
367
+ "required": false,
276
368
  "optional": false,
277
369
  "docs": {
278
370
  "tags": [],
279
- "text": "The display type of the drawer"
371
+ "text": "The method of storage. Either session storage, url hash (after the '#') or url query (after the '?')."
280
372
  },
281
373
  "getter": false,
282
374
  "setter": false,
283
- "attribute": "type",
375
+ "attribute": "store-method",
284
376
  "reflect": false,
285
- "defaultValue": "'overlay'"
377
+ "defaultValue": "'url-hash'"
286
378
  },
287
- "contentSelector": {
288
- "type": "string",
379
+ "noUserDismiss": {
380
+ "type": "boolean",
289
381
  "mutable": false,
290
382
  "complexType": {
291
- "original": "string",
292
- "resolved": "string",
383
+ "original": "boolean",
384
+ "resolved": "boolean",
293
385
  "references": {}
294
386
  },
295
387
  "required": false,
296
388
  "optional": false,
297
389
  "docs": {
298
390
  "tags": [],
299
- "text": "Required for 'reveal' and 'push' types\nA valid DOM selector of the content element that this drawer will push or reveal underneath\nPlease remember - elements wrapping the content element must be 'overflow: hidden'\notherwise menus will be shown when closed"
391
+ "text": "An alternative to `preventDefault()` on the `nanoRequestClose` event. This will hide the close button and disable clicks on the overlay or presses the `Escape` key"
300
392
  },
301
393
  "getter": false,
302
394
  "setter": false,
303
- "attribute": "content-selector",
304
- "reflect": false
395
+ "attribute": "no-user-dismiss",
396
+ "reflect": false,
397
+ "defaultValue": "false"
398
+ },
399
+ "hoist": {
400
+ "type": "boolean",
401
+ "mutable": false,
402
+ "complexType": {
403
+ "original": "boolean",
404
+ "resolved": "boolean",
405
+ "references": {}
406
+ },
407
+ "required": false,
408
+ "optional": false,
409
+ "docs": {
410
+ "tags": [],
411
+ "text": "Relocate the dialog to the root of the DOM. Useful for elements bound via css `transform: ...`"
412
+ },
413
+ "getter": false,
414
+ "setter": false,
415
+ "attribute": "hoist",
416
+ "reflect": false,
417
+ "defaultValue": "false"
305
418
  }
306
419
  };
307
420
  }
308
421
  static get states() {
309
422
  return {
310
- "hasFooter": {},
311
- "isVisible": {}
423
+ "noDismiss": {},
424
+ "hasFooter": {}
312
425
  };
313
426
  }
314
427
  static get events() {
@@ -320,7 +433,7 @@ export class Drawer {
320
433
  "composed": true,
321
434
  "docs": {
322
435
  "tags": [],
323
- "text": "Emitted when the drawer opens. Calling `event.preventDefault()` will prevent it from being opened."
436
+ "text": "Emitted when the drawer opens."
324
437
  },
325
438
  "complexType": {
326
439
  "original": "any",
@@ -328,14 +441,14 @@ export class Drawer {
328
441
  "references": {}
329
442
  }
330
443
  }, {
331
- "method": "nanoAfterShow",
332
- "name": "nanoAfterShow",
444
+ "method": "nanoHide",
445
+ "name": "nanoHide",
333
446
  "bubbles": true,
334
447
  "cancelable": true,
335
448
  "composed": true,
336
449
  "docs": {
337
450
  "tags": [],
338
- "text": "Emitted after the drawer opens and all transitions are complete."
451
+ "text": "Emitted when the drawer closes."
339
452
  },
340
453
  "complexType": {
341
454
  "original": "any",
@@ -343,14 +456,14 @@ export class Drawer {
343
456
  "references": {}
344
457
  }
345
458
  }, {
346
- "method": "nanoHide",
347
- "name": "nanoHide",
459
+ "method": "nanoAfterHide",
460
+ "name": "nanoAfterHide",
348
461
  "bubbles": true,
349
462
  "cancelable": true,
350
463
  "composed": true,
351
464
  "docs": {
352
465
  "tags": [],
353
- "text": "Emitted when the drawer closes. Calling `event.preventDefault()` will prevent it from being closed."
466
+ "text": "Emitted after the drawer closes and all animations are complete."
354
467
  },
355
468
  "complexType": {
356
469
  "original": "any",
@@ -358,14 +471,14 @@ export class Drawer {
358
471
  "references": {}
359
472
  }
360
473
  }, {
361
- "method": "nanoAfterHide",
362
- "name": "nanoAfterHide",
474
+ "method": "nanoAfterShow",
475
+ "name": "nanoAfterShow",
363
476
  "bubbles": true,
364
477
  "cancelable": true,
365
478
  "composed": true,
366
479
  "docs": {
367
480
  "tags": [],
368
- "text": "Emitted after the drawer closes and all transitions are complete."
481
+ "text": "Emitted after the drawer opens and all animations are complete."
369
482
  },
370
483
  "complexType": {
371
484
  "original": "any",
@@ -373,20 +486,35 @@ export class Drawer {
373
486
  "references": {}
374
487
  }
375
488
  }, {
376
- "method": "nanoOverlayDismiss",
377
- "name": "nanoOverlayDismiss",
489
+ "method": "nanoInitialFocus",
490
+ "name": "nanoInitialFocus",
378
491
  "bubbles": true,
379
492
  "cancelable": true,
380
493
  "composed": true,
381
494
  "docs": {
382
495
  "tags": [],
383
- "text": "Emitted when the overlay is clicked. Calling `event.preventDefault()` will prevent the drawer from closing."
496
+ "text": "Emitted when the drawer opens and is ready to receive focus. Calling\n`event.preventDefault()` will prevent focusing and allow you to set it on a different element, such as an input."
384
497
  },
385
498
  "complexType": {
386
499
  "original": "any",
387
500
  "resolved": "any",
388
501
  "references": {}
389
502
  }
503
+ }, {
504
+ "method": "nanoRquestClose",
505
+ "name": "nanoRquestClose",
506
+ "bubbles": true,
507
+ "cancelable": true,
508
+ "composed": true,
509
+ "docs": {
510
+ "tags": [],
511
+ "text": "Emitted when the user attempts to\nclose the drawer by clicking the close button, clicking the overlay, or pressing escape. Calling\n`event.preventDefault()` will keep the drawer open. Avoid using this unless closing the drawer will result in\ndestructive behavior such as data loss."
512
+ },
513
+ "complexType": {
514
+ "original": "{\n source: 'close-button' | 'keyboard' | 'overlay';\n }",
515
+ "resolved": "{ source: \"overlay\" | \"keyboard\" | \"close-button\"; }",
516
+ "references": {}
517
+ }
390
518
  }];
391
519
  }
392
520
  static get methods() {
@@ -403,7 +531,7 @@ export class Drawer {
403
531
  "return": "Promise<void>"
404
532
  },
405
533
  "docs": {
406
- "text": "Shows the drawer",
534
+ "text": "Shows the drawer.",
407
535
  "tags": []
408
536
  }
409
537
  },
@@ -428,14 +556,14 @@ export class Drawer {
428
556
  static get elementRef() { return "host"; }
429
557
  static get watchers() {
430
558
  return [{
431
- "propName": "open",
432
- "methodName": "handleOpenChange"
559
+ "propName": "hoist",
560
+ "methodName": "handleHoistChange"
433
561
  }, {
434
- "propName": "type",
435
- "methodName": "handleTypeChange"
562
+ "propName": "contained",
563
+ "methodName": "handleNoModalChange"
436
564
  }, {
437
- "propName": "contentSelector",
438
- "methodName": "handleContentSelector"
565
+ "propName": "open",
566
+ "methodName": "handleOpenChange"
439
567
  }];
440
568
  }
441
569
  }