@operato/popup 9.0.0-beta.0 → 9.0.0-beta.10

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 (33) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/src/ox-floating-overlay.js +77 -32
  3. package/dist/src/ox-floating-overlay.js.map +1 -1
  4. package/dist/src/ox-popup-list.js +84 -65
  5. package/dist/src/ox-popup-list.js.map +1 -1
  6. package/dist/src/ox-popup-menu.d.ts +1 -1
  7. package/dist/src/ox-popup-menu.js +60 -63
  8. package/dist/src/ox-popup-menu.js.map +1 -1
  9. package/dist/src/ox-popup-menuitem.d.ts +1 -1
  10. package/dist/src/ox-popup-menuitem.js +49 -47
  11. package/dist/src/ox-popup-menuitem.js.map +1 -1
  12. package/dist/src/ox-popup.js +47 -50
  13. package/dist/src/ox-popup.js.map +1 -1
  14. package/dist/src/ox-prompt.js +99 -69
  15. package/dist/src/ox-prompt.js.map +1 -1
  16. package/dist/stories/open-popup.stories.js +2 -2
  17. package/dist/stories/open-popup.stories.js.map +1 -1
  18. package/dist/stories/ox-popup-list-sortable.stories.js +1 -1
  19. package/dist/stories/ox-popup-list-sortable.stories.js.map +1 -1
  20. package/dist/stories/ox-popup-list.stories.js +1 -1
  21. package/dist/stories/ox-popup-list.stories.js.map +1 -1
  22. package/dist/stories/ox-popup-menu.stories.js +1 -1
  23. package/dist/stories/ox-popup-menu.stories.js.map +1 -1
  24. package/dist/stories/ox-popup.stories.js +2 -2
  25. package/dist/stories/ox-popup.stories.js.map +1 -1
  26. package/dist/stories/ox-prompt-icon.stories.js +2 -2
  27. package/dist/stories/ox-prompt-icon.stories.js.map +1 -1
  28. package/dist/stories/ox-prompt-normal.stories.js +2 -2
  29. package/dist/stories/ox-prompt-normal.stories.js.map +1 -1
  30. package/dist/stories/ox-prompt.stories.js +2 -2
  31. package/dist/stories/ox-prompt.stories.js.map +1 -1
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +6 -5
@@ -2,7 +2,7 @@ import { __decorate } from "tslib";
2
2
  import { css, html } from 'lit';
3
3
  import { render } from 'lit-html';
4
4
  import { customElement, property } from 'lit/decorators.js';
5
- import { OxPopup } from './ox-popup';
5
+ import { OxPopup } from './ox-popup.js';
6
6
  import { convertToFixedPosition } from './position-converter.js';
7
7
  function focusClosest(element) {
8
8
  /* Find the closest focusable element. */
@@ -14,67 +14,7 @@ function focusClosest(element) {
14
14
  * Custom element representing a popup menu. It extends OxPopup.
15
15
  */
16
16
  let OxPopupMenu = class OxPopupMenu extends OxPopup {
17
- constructor() {
18
- super(...arguments);
19
- /**
20
- * Property to track the index of the active menu item.
21
- */
22
- this.activeIndex = 0;
23
- this._onkeydown = function (e) {
24
- e.stopPropagation();
25
- switch (e.key) {
26
- case 'Esc': // for IE/Edge
27
- case 'Escape':
28
- case 'Left': // for IE/Edge
29
- case 'ArrowLeft':
30
- this.close();
31
- break;
32
- case 'Up': // for IE/Edge
33
- case 'ArrowUp':
34
- this.activeIndex--;
35
- break;
36
- case 'Right': // for IE/Edge
37
- case 'ArrowRight':
38
- case 'Down': // for IE/Edge
39
- case 'ArrowDown':
40
- this.activeIndex++;
41
- break;
42
- case 'Enter':
43
- e.stopPropagation();
44
- var menu = e.target?.closest('[menu], ox-popup-menuitem');
45
- if (menu) {
46
- this.select(menu);
47
- }
48
- break;
49
- }
50
- }.bind(this);
51
- this._onfocusout = function (e) {
52
- const target = e.target;
53
- const to = e.relatedTarget;
54
- const from = target.closest('ox-popup-menu');
55
- if (!to && from !== this) {
56
- e.stopPropagation();
57
- /* "하위의 POPUP-MENU 엘리먼트가 포커스를 잃었지만, 그 포커스를 받은 엘리먼트가 없다."는 의미는 그 서브메뉴가 클로즈된 것을 의미한다. */
58
- this.setActive(this.activeIndex);
59
- }
60
- else {
61
- if (!this.contains(to)) {
62
- /* 분명히 내 범위가 아닌 엘리먼트로 포커스가 옮겨졌다면, popup-menu는 닫혀야 한다. */
63
- // @ts-ignore for debug
64
- !window.POPUP_DEBUG && this.close();
65
- }
66
- }
67
- }.bind(this);
68
- this._onclick = function (e) {
69
- e.stopPropagation();
70
- const menu = e.target?.closest('[menu], ox-popup-menuitem');
71
- if (menu) {
72
- this.setActive(menu);
73
- this.select(menu);
74
- }
75
- }.bind(this);
76
- }
77
- static { this.styles = [
17
+ static styles = [
78
18
  ...OxPopup.styles,
79
19
  css `
80
20
  :host {
@@ -138,10 +78,67 @@ let OxPopupMenu = class OxPopupMenu extends OxPopup {
138
78
  background-color: var(--ox-popup-menu-separator-color, var(--md-sys-color-surface-variant));
139
79
  }
140
80
  `
141
- ]; }
81
+ ];
82
+ /**
83
+ * Property to track the index of the active menu item.
84
+ */
85
+ activeIndex = 0;
142
86
  render() {
143
87
  return html ` <slot> </slot> `;
144
88
  }
89
+ _onkeydown = function (e) {
90
+ e.stopPropagation();
91
+ switch (e.key) {
92
+ case 'Esc': // for IE/Edge
93
+ case 'Escape':
94
+ case 'Left': // for IE/Edge
95
+ case 'ArrowLeft':
96
+ this.close();
97
+ break;
98
+ case 'Up': // for IE/Edge
99
+ case 'ArrowUp':
100
+ this.activeIndex--;
101
+ break;
102
+ case 'Right': // for IE/Edge
103
+ case 'ArrowRight':
104
+ case 'Down': // for IE/Edge
105
+ case 'ArrowDown':
106
+ this.activeIndex++;
107
+ break;
108
+ case 'Enter':
109
+ e.stopPropagation();
110
+ var menu = e.target?.closest('[menu], ox-popup-menuitem');
111
+ if (menu) {
112
+ this.select(menu);
113
+ }
114
+ break;
115
+ }
116
+ }.bind(this);
117
+ _onfocusout = function (e) {
118
+ const target = e.target;
119
+ const to = e.relatedTarget;
120
+ const from = target.closest('ox-popup-menu');
121
+ if (!to && from !== this) {
122
+ e.stopPropagation();
123
+ /* "하위의 POPUP-MENU 엘리먼트가 포커스를 잃었지만, 그 포커스를 받은 엘리먼트가 없다."는 의미는 그 서브메뉴가 클로즈된 것을 의미한다. */
124
+ this.setActive(this.activeIndex);
125
+ }
126
+ else {
127
+ if (!this.contains(to)) {
128
+ /* 분명히 내 범위가 아닌 엘리먼트로 포커스가 옮겨졌다면, popup-menu는 닫혀야 한다. */
129
+ // @ts-ignore for debug
130
+ !window.POPUP_DEBUG && this.close();
131
+ }
132
+ }
133
+ }.bind(this);
134
+ _onclick = function (e) {
135
+ e.stopPropagation();
136
+ const menu = e.target?.closest('[menu], ox-popup-menuitem');
137
+ if (menu) {
138
+ this.setActive(menu);
139
+ this.select(menu);
140
+ }
141
+ }.bind(this);
145
142
  updated(changes) {
146
143
  if (changes.has('activeIndex')) {
147
144
  this.setActive(this.activeIndex);
@@ -1 +1 @@
1
- {"version":3,"file":"ox-popup-menu.js","sourceRoot":"","sources":["../../src/ox-popup-menu.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAEhE,SAAS,YAAY,CAAC,OAAoB;IACxC,yCAAyC;IACzC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAC7B,0EAA0E,CAC5D,CAAA;IAEhB,OAAO,EAAE,KAAK,EAAE,CAAA;IAEhB,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;GAEG;AAEI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,OAAO;IAAjC;;QAmEL;;WAEG;QACyB,gBAAW,GAAW,CAAC,CAAA;QAMzC,eAAU,GAA+B,UAA6B,CAAgB;YAC9F,CAAC,CAAC,eAAe,EAAE,CAAA;YAEnB,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC;gBACd,KAAK,KAAK,CAAC,CAAC,cAAc;gBAC1B,KAAK,QAAQ,CAAC;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AI,MAAM,EAAE,CAAC;YACX,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,sBAAsB,CAAC;gBACxD,IAAI;gBACJ,GAAG;gBACH,KAAK;gBACL,MAAM;gBACN,eAAe,EAAE,MAAqB;aACvC,CAAC,CAAA;QACJ,CAAC;QAED,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;QACjC,MAAM,CAAC,cAAc,GAAG,IAAI,CAAA;QAC5B,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;QAEzC,OAAO,MAAM,CAAA;IACf,CAAC;;AAzJ2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gDAAwB;AAtExC,WAAW;IADvB,aAAa,CAAC,eAAe,CAAC;GAClB,WAAW,CAgOvB","sourcesContent":["import { css, html, PropertyValues } from 'lit'\nimport { render } from 'lit-html'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { OxPopup } from './ox-popup'\nimport { convertToFixedPosition } from './position-converter.js'\n\nfunction focusClosest(element: HTMLElement) {\n /* Find the closest focusable element. */\n const closest = element.closest(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])'\n ) as HTMLElement\n\n closest?.focus()\n\n return closest\n}\n\n/**\n * Custom element representing a popup menu. It extends OxPopup.\n */\n@customElement('ox-popup-menu')\nexport class OxPopupMenu extends OxPopup {\n static styles = [\n ...OxPopup.styles,\n css`\n :host {\n display: none;\n flex-direction: column;\n align-items: stretch;\n background-color: var(--ox-popup-menu-background-color, var(--md-sys-color-surface));\n color: var(--ox-popup-list-color, var(--md-sys-color-on-surface));\n z-index: 100;\n box-shadow: 2px 3px 10px 5px rgba(0, 0, 0, 0.15);\n padding: var(--spacing-small) 0;\n border-radius: var(--spacing-small);\n\n font-size: var(--md-sys-typescale-label-large-size, 0.875rem);\n }\n\n :host([active]) {\n display: flex;\n }\n\n :host(*:focus) {\n outline: none;\n }\n\n ::slotted(*) {\n padding: var(--spacing-medium);\n border-bottom: 1px solid var(--md-sys-color-surface-variant);\n cursor: pointer;\n color: var(--ox-popup-list-color, var(--md-sys-color-outline-variant));\n }\n\n ::slotted(*:focus) {\n cursor: pointer;\n outline: none;\n }\n\n ::slotted([menu]),\n ::slotted(ox-popup-menuitem) {\n border-left: 3px solid transparent;\n background-color: var(--ox-popup-menu-background-color, var(--md-sys-color-surface));\n color: var(--ox-popup-menu-color, var(--md-sys-color-on-surface));\n }\n\n ::slotted([menu][active]),\n ::slotted([menu]:hover),\n ::slotted(ox-popup-menuitem[active]),\n ::slotted(ox-popup-menuitem:hover) {\n background-color: var(--ox-popup-list-background-color-variant, var(--md-sys-color-surface-variant));\n color: var(--ox-popup-list-color-variant, var(--md-sys-color-on-surface-variant));\n }\n\n ::slotted(ox-popup-menuitem[active]) {\n border-left: 3px solid var(--md-sys-color-primary);\n font-weight: var(--md-sys-typescale-label-large-weight, var(--md-ref-typeface-weight-medium, 500));\n }\n\n ::slotted([separator]) {\n height: 1px;\n width: 100%;\n padding: 0;\n background-color: var(--ox-popup-menu-separator-color, var(--md-sys-color-surface-variant));\n }\n `\n ]\n\n /**\n * Property to track the index of the active menu item.\n */\n @property({ type: Number }) activeIndex: number = 0\n\n render() {\n return html` <slot> </slot> `\n }\n\n protected _onkeydown: (e: KeyboardEvent) => void = function (this: OxPopupMenu, e: KeyboardEvent) {\n e.stopPropagation()\n\n switch (e.key) {\n case 'Esc': // for IE/Edge\n case 'Escape':\n case 'Left': // for IE/Edge\n case 'ArrowLeft':\n this.close()\n break\n\n case 'Up': // for IE/Edge\n case 'ArrowUp':\n this.activeIndex--\n break\n\n case 'Right': // for IE/Edge\n case 'ArrowRight':\n case 'Down': // for IE/Edge\n case 'ArrowDown':\n this.activeIndex++\n break\n\n case 'Enter':\n e.stopPropagation()\n var menu = (e.target as HTMLElement)?.closest('[menu], ox-popup-menuitem')\n if (menu) {\n this.select(menu)\n }\n break\n }\n }.bind(this)\n\n protected _onfocusout: (e: FocusEvent) => void = function (this: OxPopupMenu, e: FocusEvent) {\n const target = e.target as HTMLElement\n const to = e.relatedTarget as HTMLElement\n const from = target.closest('ox-popup-menu')\n\n if (!to && from !== this) {\n e.stopPropagation()\n\n /* \"하위의 POPUP-MENU 엘리먼트가 포커스를 잃었지만, 그 포커스를 받은 엘리먼트가 없다.\"는 의미는 그 서브메뉴가 클로즈된 것을 의미한다. */\n this.setActive(this.activeIndex)\n } else {\n if (!this.contains(to)) {\n /* 분명히 내 범위가 아닌 엘리먼트로 포커스가 옮겨졌다면, popup-menu는 닫혀야 한다. */\n // @ts-ignore for debug\n !window.POPUP_DEBUG && this.close()\n }\n }\n }.bind(this)\n\n protected _onclick: (e: MouseEvent) => void = function (this: OxPopupMenu, e: MouseEvent) {\n e.stopPropagation()\n\n const menu = (e.target as HTMLElement)?.closest('[menu], ox-popup-menuitem')\n if (menu) {\n this.setActive(menu)\n this.select(menu)\n }\n }.bind(this)\n\n updated(changes: PropertyValues<this>) {\n if (changes.has('activeIndex')) {\n this.setActive(this.activeIndex)\n }\n }\n\n /**\n * Selects a menu item by dispatching a 'select' event.\n * Closes the menu if the item doesn't have 'alive-on-select' attribute.\n */\n select(menu: Element) {\n menu.dispatchEvent(new CustomEvent('select'))\n if (!menu.hasAttribute('alive-on-select')) {\n this.dispatchEvent(new CustomEvent('ox-close', { bubbles: true, composed: true, detail: this }))\n }\n }\n\n /**\n * Sets the active menu item based on the index or the menu element itself.\n */\n setActive(active: number | Element | null) {\n const menus = Array.from(this.querySelectorAll(':scope > ox-popup-menuitem, :scope > [menu]'))\n\n menus.map(async (menu, index) => {\n if (typeof active === 'number' && index === (active + menus.length) % menus.length) {\n menu.setAttribute('active', '')\n focusClosest(menu as HTMLElement)\n\n this.activeIndex = index\n } else if (active === menu) {\n if (this.activeIndex === index) {\n /* 메뉴의 update를 유도하기 위해서 강제로 토글시킴 */\n menu.removeAttribute('active')\n await this.updateComplete\n menu.setAttribute('active', '')\n }\n\n this.activeIndex = index\n } else {\n menu.removeAttribute('active')\n }\n })\n }\n\n /**\n * Static method to open a popup menu with the provided template and position options.\n * Creates and returns an instance of OxPopupMenu.\n *\n * @param {PopupOpenOptions}\n */\n static open({\n template,\n top,\n left,\n right,\n bottom,\n parent\n }: {\n template: unknown\n top?: number\n left?: number\n right?: number\n bottom?: number\n parent?: Element | null\n }): OxPopupMenu {\n const target = document.createElement('ox-popup-menu') as OxPopupMenu\n render(template, target)\n\n target.setAttribute('active', '')\n\n if (parent) {\n var { left, top, right, bottom } = convertToFixedPosition({\n left,\n top,\n right,\n bottom,\n relativeElement: parent as HTMLElement\n })\n }\n\n document.body.appendChild(target)\n target.removeAfterUse = true\n target.open({ top, left, right, bottom })\n\n return target\n }\n}\n"]}
1
+ {"version":3,"file":"ox-popup-menu.js","sourceRoot":"","sources":["../../src/ox-popup-menu.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAEhE,SAAS,YAAY,CAAC,OAAoB;IACxC,yCAAyC;IACzC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAC7B,0EAA0E,CAC5D,CAAA;IAEhB,OAAO,EAAE,KAAK,EAAE,CAAA;IAEhB,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;GAEG;AAEI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,OAAO;IACtC,MAAM,CAAC,MAAM,GAAG;QACd,GAAG,OAAO,CAAC,MAAM;QACjB,GAAG,CAAA;;;;;;;;;;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,EAAE,MAAM,CAAC,CAAA;QAExB,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;QAEjC,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,sBAAsB,CAAC;gBACxD,IAAI;gBACJ,GAAG;gBACH,KAAK;gBACL,MAAM;gBACN,eAAe,EAAE,MAAqB;aACvC,CAAC,CAAA;QACJ,CAAC;QAED,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;QACjC,MAAM,CAAC,cAAc,GAAG,IAAI,CAAA;QAC5B,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;QAEzC,OAAO,MAAM,CAAA;IACf,CAAC;;AAzJ2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gDAAwB;AAtExC,WAAW;IADvB,aAAa,CAAC,eAAe,CAAC;GAClB,WAAW,CAgOvB","sourcesContent":["import { css, html, PropertyValues } from 'lit'\nimport { render } from 'lit-html'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { OxPopup } from './ox-popup.js'\nimport { convertToFixedPosition } from './position-converter.js'\n\nfunction focusClosest(element: HTMLElement) {\n /* Find the closest focusable element. */\n const closest = element.closest(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])'\n ) as HTMLElement\n\n closest?.focus()\n\n return closest\n}\n\n/**\n * Custom element representing a popup menu. It extends OxPopup.\n */\n@customElement('ox-popup-menu')\nexport class OxPopupMenu extends OxPopup {\n static styles = [\n ...OxPopup.styles,\n css`\n :host {\n display: none;\n flex-direction: column;\n align-items: stretch;\n background-color: var(--ox-popup-menu-background-color, var(--md-sys-color-surface));\n color: var(--ox-popup-list-color, var(--md-sys-color-on-surface));\n z-index: 100;\n box-shadow: 2px 3px 10px 5px rgba(0, 0, 0, 0.15);\n padding: var(--spacing-small) 0;\n border-radius: var(--spacing-small);\n\n font-size: var(--md-sys-typescale-label-large-size, 0.875rem);\n }\n\n :host([active]) {\n display: flex;\n }\n\n :host(*:focus) {\n outline: none;\n }\n\n ::slotted(*) {\n padding: var(--spacing-medium);\n border-bottom: 1px solid var(--md-sys-color-surface-variant);\n cursor: pointer;\n color: var(--ox-popup-list-color, var(--md-sys-color-outline-variant));\n }\n\n ::slotted(*:focus) {\n cursor: pointer;\n outline: none;\n }\n\n ::slotted([menu]),\n ::slotted(ox-popup-menuitem) {\n border-left: 3px solid transparent;\n background-color: var(--ox-popup-menu-background-color, var(--md-sys-color-surface));\n color: var(--ox-popup-menu-color, var(--md-sys-color-on-surface));\n }\n\n ::slotted([menu][active]),\n ::slotted([menu]:hover),\n ::slotted(ox-popup-menuitem[active]),\n ::slotted(ox-popup-menuitem:hover) {\n background-color: var(--ox-popup-list-background-color-variant, var(--md-sys-color-surface-variant));\n color: var(--ox-popup-list-color-variant, var(--md-sys-color-on-surface-variant));\n }\n\n ::slotted(ox-popup-menuitem[active]) {\n border-left: 3px solid var(--md-sys-color-primary);\n font-weight: var(--md-sys-typescale-label-large-weight, var(--md-ref-typeface-weight-medium, 500));\n }\n\n ::slotted([separator]) {\n height: 1px;\n width: 100%;\n padding: 0;\n background-color: var(--ox-popup-menu-separator-color, var(--md-sys-color-surface-variant));\n }\n `\n ]\n\n /**\n * Property to track the index of the active menu item.\n */\n @property({ type: Number }) activeIndex: number = 0\n\n render() {\n return html` <slot> </slot> `\n }\n\n protected _onkeydown: (e: KeyboardEvent) => void = function (this: OxPopupMenu, e: KeyboardEvent) {\n e.stopPropagation()\n\n switch (e.key) {\n case 'Esc': // for IE/Edge\n case 'Escape':\n case 'Left': // for IE/Edge\n case 'ArrowLeft':\n this.close()\n break\n\n case 'Up': // for IE/Edge\n case 'ArrowUp':\n this.activeIndex--\n break\n\n case 'Right': // for IE/Edge\n case 'ArrowRight':\n case 'Down': // for IE/Edge\n case 'ArrowDown':\n this.activeIndex++\n break\n\n case 'Enter':\n e.stopPropagation()\n var menu = (e.target as HTMLElement)?.closest('[menu], ox-popup-menuitem')\n if (menu) {\n this.select(menu)\n }\n break\n }\n }.bind(this)\n\n protected _onfocusout: (e: FocusEvent) => void = function (this: OxPopupMenu, e: FocusEvent) {\n const target = e.target as HTMLElement\n const to = e.relatedTarget as HTMLElement\n const from = target.closest('ox-popup-menu')\n\n if (!to && from !== this) {\n e.stopPropagation()\n\n /* \"하위의 POPUP-MENU 엘리먼트가 포커스를 잃었지만, 그 포커스를 받은 엘리먼트가 없다.\"는 의미는 그 서브메뉴가 클로즈된 것을 의미한다. */\n this.setActive(this.activeIndex)\n } else {\n if (!this.contains(to)) {\n /* 분명히 내 범위가 아닌 엘리먼트로 포커스가 옮겨졌다면, popup-menu는 닫혀야 한다. */\n // @ts-ignore for debug\n !window.POPUP_DEBUG && this.close()\n }\n }\n }.bind(this)\n\n protected _onclick: (e: MouseEvent) => void = function (this: OxPopupMenu, e: MouseEvent) {\n e.stopPropagation()\n\n const menu = (e.target as HTMLElement)?.closest('[menu], ox-popup-menuitem')\n if (menu) {\n this.setActive(menu)\n this.select(menu)\n }\n }.bind(this)\n\n updated(changes: PropertyValues<this>) {\n if (changes.has('activeIndex')) {\n this.setActive(this.activeIndex)\n }\n }\n\n /**\n * Selects a menu item by dispatching a 'select' event.\n * Closes the menu if the item doesn't have 'alive-on-select' attribute.\n */\n select(menu: Element) {\n menu.dispatchEvent(new CustomEvent('select'))\n if (!menu.hasAttribute('alive-on-select')) {\n this.dispatchEvent(new CustomEvent('ox-close', { bubbles: true, composed: true, detail: this }))\n }\n }\n\n /**\n * Sets the active menu item based on the index or the menu element itself.\n */\n setActive(active: number | Element | null) {\n const menus = Array.from(this.querySelectorAll(':scope > ox-popup-menuitem, :scope > [menu]'))\n\n menus.map(async (menu, index) => {\n if (typeof active === 'number' && index === (active + menus.length) % menus.length) {\n menu.setAttribute('active', '')\n focusClosest(menu as HTMLElement)\n\n this.activeIndex = index\n } else if (active === menu) {\n if (this.activeIndex === index) {\n /* 메뉴의 update를 유도하기 위해서 강제로 토글시킴 */\n menu.removeAttribute('active')\n await this.updateComplete\n menu.setAttribute('active', '')\n }\n\n this.activeIndex = index\n } else {\n menu.removeAttribute('active')\n }\n })\n }\n\n /**\n * Static method to open a popup menu with the provided template and position options.\n * Creates and returns an instance of OxPopupMenu.\n *\n * @param {PopupOpenOptions}\n */\n static open({\n template,\n top,\n left,\n right,\n bottom,\n parent\n }: {\n template: unknown\n top?: number\n left?: number\n right?: number\n bottom?: number\n parent?: Element | null\n }): OxPopupMenu {\n const target = document.createElement('ox-popup-menu') as OxPopupMenu\n render(template, target)\n\n target.setAttribute('active', '')\n\n if (parent) {\n var { left, top, right, bottom } = convertToFixedPosition({\n left,\n top,\n right,\n bottom,\n relativeElement: parent as HTMLElement\n })\n }\n\n document.body.appendChild(target)\n target.removeAfterUse = true\n target.open({ top, left, right, bottom })\n\n return target\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { LitElement, PropertyValues } from 'lit';
2
- import { OxPopupMenu } from './ox-popup-menu';
2
+ import { OxPopupMenu } from './ox-popup-menu.js';
3
3
  /**
4
4
  * Custom element representing a menu item within an OxPopup menu.
5
5
  * It can contain a label and an optional submenu.
@@ -6,52 +6,7 @@ import { customElement, property, state } from 'lit/decorators.js';
6
6
  * It can contain a label and an optional submenu.
7
7
  */
8
8
  let OxPopupMenuItem = class OxPopupMenuItem extends LitElement {
9
- constructor() {
10
- super(...arguments);
11
- /**
12
- * Property indicating whether the menu item is active or not.
13
- * When active, it may show a submenu.
14
- */
15
- this.active = false;
16
- this._onclick = function (e) {
17
- if (!this._submenu) {
18
- return;
19
- }
20
- e.stopPropagation();
21
- const parent = this.closest('ox-popup-menu');
22
- if (parent) {
23
- parent.setActive(this);
24
- }
25
- this.dispatchEvent(new CustomEvent('select'));
26
- requestAnimationFrame(() => {
27
- this.expand(false);
28
- });
29
- }.bind(this);
30
- this._onkeydown = function (e) {
31
- switch (e.key) {
32
- case 'Right':
33
- case 'ArrowRight':
34
- e.stopPropagation();
35
- this.expand(false);
36
- break;
37
- case 'Left':
38
- case 'ArrowLeft':
39
- e.stopPropagation();
40
- this.collapseSelf();
41
- break;
42
- case 'Enter':
43
- if (this._submenu) {
44
- e.stopPropagation();
45
- this.expand(false);
46
- }
47
- break;
48
- }
49
- }.bind(this);
50
- this._onslotchange = function (e) {
51
- this._submenu = this.querySelector('ox-popup-menu');
52
- }.bind(this);
53
- }
54
- static { this.styles = [
9
+ static styles = [
55
10
  css `
56
11
  :host {
57
12
  display: flex;
@@ -93,7 +48,17 @@ let OxPopupMenuItem = class OxPopupMenuItem extends LitElement {
93
48
  opacity: 0.7;
94
49
  }
95
50
  `
96
- ]; }
51
+ ];
52
+ /**
53
+ * Property indicating whether the menu item is active or not.
54
+ * When active, it may show a submenu.
55
+ */
56
+ active = false;
57
+ /**
58
+ * The label to display for the menu item.
59
+ */
60
+ label;
61
+ _submenu;
97
62
  render() {
98
63
  return html `
99
64
  <div icon>
@@ -111,6 +76,43 @@ let OxPopupMenuItem = class OxPopupMenuItem extends LitElement {
111
76
  this.addEventListener('keydown', this._onkeydown);
112
77
  this.addEventListener('click', this._onclick);
113
78
  }
79
+ _onclick = function (e) {
80
+ if (!this._submenu) {
81
+ return;
82
+ }
83
+ e.stopPropagation();
84
+ const parent = this.closest('ox-popup-menu');
85
+ if (parent) {
86
+ parent.setActive(this);
87
+ }
88
+ this.dispatchEvent(new CustomEvent('select'));
89
+ requestAnimationFrame(() => {
90
+ this.expand(false);
91
+ });
92
+ }.bind(this);
93
+ _onkeydown = function (e) {
94
+ switch (e.key) {
95
+ case 'Right':
96
+ case 'ArrowRight':
97
+ e.stopPropagation();
98
+ this.expand(false);
99
+ break;
100
+ case 'Left':
101
+ case 'ArrowLeft':
102
+ e.stopPropagation();
103
+ this.collapseSelf();
104
+ break;
105
+ case 'Enter':
106
+ if (this._submenu) {
107
+ e.stopPropagation();
108
+ this.expand(false);
109
+ }
110
+ break;
111
+ }
112
+ }.bind(this);
113
+ _onslotchange = function (e) {
114
+ this._submenu = this.querySelector('ox-popup-menu');
115
+ }.bind(this);
114
116
  updated(changes) {
115
117
  if (changes.has('active')) {
116
118
  this.updateActive();
@@ -1 +1 @@
1
- {"version":3,"file":"ox-popup-menuitem.js","sourceRoot":"","sources":["../../src/ox-popup-menuitem.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAkB,MAAM,KAAK,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAIlE;;;GAGG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,UAAU;IAAxC;;QA6CL;;;WAGG;QAC0B,WAAM,GAAY,KAAK,CAAA;QA4B1C,aAAQ,GAA4B,UAAiC,CAAa;YAC1F,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACnB,OAAM;YACR,CAAC;YAED,CAAC,CAAC,eAAe,EAAE,CAAA;YAEnB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAgB,CAAA;YAC3D,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;YACxB,CAAC;YAED,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAA;YAE7C,qBAAqB,CAAC,GAAG,EAAE;gBACzB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YACpB,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEF,eAAU,GAA+B,UAAiC,CAAgB;YAClG,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC;gBACd,KAAK,OAAO,CAAC;gBACb,KAAK,YAAY;oBACf,CAAC,CAAC,eAAe,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Ae;IAD3B,aAAa,CAAC,mBAAmB,CAAC;GACtB,eAAe,CAgL3B","sourcesContent":["import { css, html, LitElement, PropertyValues } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { OxPopupMenu } from './ox-popup-menu'\n\n/**\n * Custom element representing a menu item within an OxPopup menu.\n * It can contain a label and an optional submenu.\n */\n@customElement('ox-popup-menuitem')\nexport class OxPopupMenuItem extends LitElement {\n static styles = [\n css`\n :host {\n display: flex;\n flex-direction: row;\n position: relative;\n align-items: center;\n }\n\n [icon] {\n width: 20px;\n display: flex;\n flex-direction: row;\n padding: 0;\n margin: 0 var(--spacing-small) 0 0;\n align-items: center;\n justify-content: center;\n }\n\n [icon] > * {\n flex: 1;\n }\n\n [label] {\n flex: 1;\n text-transform: capitalize;\n }\n\n ::slotted(*[slot='icon']) {\n color: var(--ox-popup-menu-color-variant, var(--md-sys-color-on-surface-variant));\n font-size: var(--icon-size-small);\n }\n\n md-icon {\n display: block;\n width: 24px;\n text-align: right;\n font-size: var(--icon-size-small);\n color: var(--ox-popup-menu-color-variant, var(--md-sys-color-primary));\n opacity: 0.7;\n }\n `\n ]\n\n /**\n * Property indicating whether the menu item is active or not.\n * When active, it may show a submenu.\n */\n @property({ type: Boolean }) active: boolean = false\n\n /**\n * The label to display for the menu item.\n */\n @property({ type: String }) label!: string\n\n @state() _submenu?: OxPopupMenu\n\n render() {\n return html`\n <div icon>\n <slot name=\"icon\"> </slot>\n </div>\n <div label>${this.label}</div>\n\n ${this._submenu ? html`<md-icon>chevron_right</md-icon>` : html``}\n\n <slot @slotchange=${this._onslotchange}> </slot>\n `\n }\n\n firstUpdated() {\n this.setAttribute('tabindex', '0')\n this.addEventListener('keydown', this._onkeydown)\n this.addEventListener('click', this._onclick)\n }\n\n protected _onclick: (e: MouseEvent) => void = function (this: OxPopupMenuItem, e: MouseEvent) {\n if (!this._submenu) {\n return\n }\n\n e.stopPropagation()\n\n const parent = this.closest('ox-popup-menu') as OxPopupMenu\n if (parent) {\n parent.setActive(this)\n }\n\n this.dispatchEvent(new CustomEvent('select'))\n\n requestAnimationFrame(() => {\n this.expand(false)\n })\n }.bind(this)\n\n protected _onkeydown: (e: KeyboardEvent) => void = function (this: OxPopupMenuItem, e: KeyboardEvent) {\n switch (e.key) {\n case 'Right':\n case 'ArrowRight':\n e.stopPropagation()\n this.expand(false)\n break\n\n case 'Left':\n case 'ArrowLeft':\n e.stopPropagation()\n this.collapseSelf()\n break\n\n case 'Enter':\n if (this._submenu) {\n e.stopPropagation()\n this.expand(false)\n }\n break\n }\n }.bind(this)\n\n protected _onslotchange: (e: Event) => void = function (this: OxPopupMenuItem, e: Event) {\n this._submenu = this.querySelector('ox-popup-menu') as OxPopupMenu\n }.bind(this)\n\n updated(changes: PropertyValues<this>) {\n if (changes.has('active')) {\n this.updateActive()\n }\n }\n\n updateActive() {\n if (this.active) {\n this.expand(true)\n } else {\n this.collapse()\n }\n }\n\n /**\n * Expands the submenu, if it exists.\n * The submenu is displayed below and to the right of the menu item.\n *\n * @param {boolean} silent - If true, the submenu is opened silently without user interaction.\n */\n expand(silent: boolean) {\n if (!this._submenu) {\n return\n }\n\n const top = 0\n const left = this.clientWidth\n\n this._submenu.open({ top, left, silent })\n }\n\n /**\n * Collapses the submenu, if it exists.\n */\n collapse() {\n this._submenu?.close()\n }\n\n /**\n * Dispatches a custom 'ox-collapse' event indicating that the menu item should collapse itself.\n * This event can be used to trigger further interactions or logic in the application.\n */\n collapseSelf() {\n this.dispatchEvent(new CustomEvent('ox-collapse', { bubbles: true, composed: true, detail: this }))\n }\n\n /**\n * Dispatches a custom 'ox-close' event indicating that the menu item should close itself.\n * This event can be used to trigger further interactions or logic in the application.\n */\n close() {\n this.dispatchEvent(new CustomEvent('ox-close', { bubbles: true, composed: true, detail: this }))\n }\n}\n"]}
1
+ {"version":3,"file":"ox-popup-menuitem.js","sourceRoot":"","sources":["../../src/ox-popup-menuitem.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,E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M,CAAC,MAAe;QACpB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAM;QACR,CAAC;QAED,MAAM,GAAG,GAAG,CAAC,CAAA;QACb,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAA;QAE7B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA;IAC3C,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAA;IACxB,CAAC;IAED;;;OAGG;IACH,YAAY;QACV,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACrG,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,UAAU,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IAClG,CAAC;;AA9H4B;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;+CAAwB;AAKxB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8CAAe;AAEjC;IAAR,KAAK,EAAE;iDAAuB;AAxDpB,eAAe;IAD3B,aAAa,CAAC,mBAAmB,CAAC;GACtB,eAAe,CAgL3B","sourcesContent":["import { css, html, LitElement, PropertyValues } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { OxPopupMenu } from './ox-popup-menu.js'\n\n/**\n * Custom element representing a menu item within an OxPopup menu.\n * It can contain a label and an optional submenu.\n */\n@customElement('ox-popup-menuitem')\nexport class OxPopupMenuItem extends LitElement {\n static styles = [\n css`\n :host {\n display: flex;\n flex-direction: row;\n position: relative;\n align-items: center;\n }\n\n [icon] {\n width: 20px;\n display: flex;\n flex-direction: row;\n padding: 0;\n margin: 0 var(--spacing-small) 0 0;\n align-items: center;\n justify-content: center;\n }\n\n [icon] > * {\n flex: 1;\n }\n\n [label] {\n flex: 1;\n text-transform: capitalize;\n }\n\n ::slotted(*[slot='icon']) {\n color: var(--ox-popup-menu-color-variant, var(--md-sys-color-on-surface-variant));\n font-size: var(--icon-size-small);\n }\n\n md-icon {\n display: block;\n width: 24px;\n text-align: right;\n font-size: var(--icon-size-small);\n color: var(--ox-popup-menu-color-variant, var(--md-sys-color-primary));\n opacity: 0.7;\n }\n `\n ]\n\n /**\n * Property indicating whether the menu item is active or not.\n * When active, it may show a submenu.\n */\n @property({ type: Boolean }) active: boolean = false\n\n /**\n * The label to display for the menu item.\n */\n @property({ type: String }) label!: string\n\n @state() _submenu?: OxPopupMenu\n\n render() {\n return html`\n <div icon>\n <slot name=\"icon\"> </slot>\n </div>\n <div label>${this.label}</div>\n\n ${this._submenu ? html`<md-icon>chevron_right</md-icon>` : html``}\n\n <slot @slotchange=${this._onslotchange}> </slot>\n `\n }\n\n firstUpdated() {\n this.setAttribute('tabindex', '0')\n this.addEventListener('keydown', this._onkeydown)\n this.addEventListener('click', this._onclick)\n }\n\n protected _onclick: (e: MouseEvent) => void = function (this: OxPopupMenuItem, e: MouseEvent) {\n if (!this._submenu) {\n return\n }\n\n e.stopPropagation()\n\n const parent = this.closest('ox-popup-menu') as OxPopupMenu\n if (parent) {\n parent.setActive(this)\n }\n\n this.dispatchEvent(new CustomEvent('select'))\n\n requestAnimationFrame(() => {\n this.expand(false)\n })\n }.bind(this)\n\n protected _onkeydown: (e: KeyboardEvent) => void = function (this: OxPopupMenuItem, e: KeyboardEvent) {\n switch (e.key) {\n case 'Right':\n case 'ArrowRight':\n e.stopPropagation()\n this.expand(false)\n break\n\n case 'Left':\n case 'ArrowLeft':\n e.stopPropagation()\n this.collapseSelf()\n break\n\n case 'Enter':\n if (this._submenu) {\n e.stopPropagation()\n this.expand(false)\n }\n break\n }\n }.bind(this)\n\n protected _onslotchange: (e: Event) => void = function (this: OxPopupMenuItem, e: Event) {\n this._submenu = this.querySelector('ox-popup-menu') as OxPopupMenu\n }.bind(this)\n\n updated(changes: PropertyValues<this>) {\n if (changes.has('active')) {\n this.updateActive()\n }\n }\n\n updateActive() {\n if (this.active) {\n this.expand(true)\n } else {\n this.collapse()\n }\n }\n\n /**\n * Expands the submenu, if it exists.\n * The submenu is displayed below and to the right of the menu item.\n *\n * @param {boolean} silent - If true, the submenu is opened silently without user interaction.\n */\n expand(silent: boolean) {\n if (!this._submenu) {\n return\n }\n\n const top = 0\n const left = this.clientWidth\n\n this._submenu.open({ top, left, silent })\n }\n\n /**\n * Collapses the submenu, if it exists.\n */\n collapse() {\n this._submenu?.close()\n }\n\n /**\n * Dispatches a custom 'ox-collapse' event indicating that the menu item should collapse itself.\n * This event can be used to trigger further interactions or logic in the application.\n */\n collapseSelf() {\n this.dispatchEvent(new CustomEvent('ox-collapse', { bubbles: true, composed: true, detail: this }))\n }\n\n /**\n * Dispatches a custom 'ox-close' event indicating that the menu item should close itself.\n * This event can be used to trigger further interactions or logic in the application.\n */\n close() {\n this.dispatchEvent(new CustomEvent('ox-close', { bubbles: true, composed: true, detail: this }))\n }\n}\n"]}
@@ -14,55 +14,7 @@ import { convertToFixedPosition } from './position-converter.js';
14
14
  * @fires ox-collapse - Dispatched when the popup is collapsed.
15
15
  */
16
16
  let OxPopup = class OxPopup extends LitElement {
17
- constructor() {
18
- super(...arguments);
19
- this.preventCloseOnBlur = false;
20
- this.backdrop = false;
21
- this.lastActive = document.activeElement;
22
- this.removeAfterUse = false;
23
- this._onfocusout = function (e) {
24
- const to = e.relatedTarget;
25
- if (!this.contains(to)) {
26
- !this.preventCloseOnBlur && !window.POPUP_DEBUG && this.close();
27
- }
28
- }.bind(this);
29
- this._onkeydown = function (e) {
30
- e.stopPropagation();
31
- switch (e.key) {
32
- case 'Esc': // for IE/Edge
33
- case 'Escape':
34
- this.close();
35
- break;
36
- }
37
- }.bind(this);
38
- this._onkeyup = function (e) {
39
- e.stopPropagation();
40
- }.bind(this);
41
- this._onmouseup = function (e) {
42
- e.stopPropagation();
43
- }.bind(this);
44
- this._onmousedown = function (e) {
45
- e.stopPropagation();
46
- }.bind(this);
47
- this._oncontextmenu = function (e) {
48
- e.stopPropagation();
49
- // this.close()
50
- }.bind(this);
51
- this._onclick = function (e) {
52
- e.stopPropagation();
53
- }.bind(this);
54
- this._onclose = function (e) {
55
- this.close();
56
- }.bind(this);
57
- this._oncollapse = function (e) {
58
- e.stopPropagation();
59
- this.close();
60
- }.bind(this);
61
- this._onwindowblur = function (e) {
62
- !this.preventCloseOnBlur && !window.POPUP_DEBUG && this.close();
63
- }.bind(this);
64
- }
65
- static { this.styles = [
17
+ static styles = [
66
18
  ScrollbarStyles,
67
19
  css `
68
20
  :host {
@@ -99,13 +51,58 @@ let OxPopup = class OxPopup extends LitElement {
99
51
  opacity: 0.5;
100
52
  }
101
53
  `
102
- ]; }
54
+ ];
55
+ preventCloseOnBlur = false;
56
+ backdrop = false;
57
+ lastActive = document.activeElement;
58
+ removeAfterUse = false;
103
59
  render() {
104
60
  return html `
105
61
  ${this.backdrop ? html `<div id="backdrop" @click=${() => this.close()}></div>` : nothing}
106
62
  <slot></slot>
107
63
  `;
108
64
  }
65
+ _onfocusout = function (e) {
66
+ const to = e.relatedTarget;
67
+ if (!this.contains(to)) {
68
+ !this.preventCloseOnBlur && !window.POPUP_DEBUG && this.close();
69
+ }
70
+ }.bind(this);
71
+ _onkeydown = function (e) {
72
+ e.stopPropagation();
73
+ switch (e.key) {
74
+ case 'Esc': // for IE/Edge
75
+ case 'Escape':
76
+ this.close();
77
+ break;
78
+ }
79
+ }.bind(this);
80
+ _onkeyup = function (e) {
81
+ e.stopPropagation();
82
+ }.bind(this);
83
+ _onmouseup = function (e) {
84
+ e.stopPropagation();
85
+ }.bind(this);
86
+ _onmousedown = function (e) {
87
+ e.stopPropagation();
88
+ }.bind(this);
89
+ _oncontextmenu = function (e) {
90
+ e.stopPropagation();
91
+ // this.close()
92
+ }.bind(this);
93
+ _onclick = function (e) {
94
+ e.stopPropagation();
95
+ }.bind(this);
96
+ _onclose = function (e) {
97
+ this.close();
98
+ }.bind(this);
99
+ _oncollapse = function (e) {
100
+ e.stopPropagation();
101
+ this.close();
102
+ }.bind(this);
103
+ _onwindowblur = function (e) {
104
+ !this.preventCloseOnBlur && !window.POPUP_DEBUG && this.close();
105
+ }.bind(this);
109
106
  connectedCallback() {
110
107
  super.connectedCallback();
111
108
  this.addEventListener('focusout', this._onfocusout);
@@ -1 +1 @@
1
- {"version":3,"file":"ox-popup.js","sourceRoot":"","sources":["../../src/ox-popup.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAS,MAAM,mBAAmB,CAAA;AAElE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAQhE;;;;;;;;GAQG;AAEI,IAAM,OAAO,GAAb,MAAM,OAAQ,SAAQ,UAAU;IAAhC;;QAwC4D,uBAAkB,GAAY,KAAK,CAAA;QAChD,aAAQ,GAAY,KAAK,CAAA;QAErE,eAAU,GAAgB,QAAQ,CAAC,aAA4B,CAAA;QAC7D,mBAAc,GAAY,KAAK,CAAA;QAS/B,gBAAW,GAA4B,UAAyB,CAAa;YACrF,MAAM,EAAE,GAAG,CAAC,CAAC,aAA4B,CAAA;YAEzC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;gBACvB,CAAC,IAAI,CAAC,kBAAkB,IAAI,CAAC,MAAM,C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AAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;yCAA0B;AAzClE,OAAO;IADnB,aAAa,CAAC,UAAU,CAAC;GACb,OAAO,CAuXnB","sourcesContent":["import { css, html, LitElement, nothing } from 'lit'\nimport { render } from 'lit-html'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { ScrollbarStyles } from '@operato/styles'\n\nimport { convertToFixedPosition } from './position-converter.js'\n\ndeclare global {\n interface Window {\n POPUP_DEBUG?: boolean\n }\n}\n\n/**\n * Custom element class representing the 'ox-popup' component.\n *\n * This component provides the functionality to display a popup with various configuration options.\n * It can be used to show additional information, notifications, or user interactions within a web application.\n *\n * @fires ox-close - Dispatched when the popup is closed.\n * @fires ox-collapse - Dispatched when the popup is collapsed.\n */\n@customElement('ox-popup')\nexport class OxPopup extends LitElement {\n static styles = [\n ScrollbarStyles,\n css`\n :host {\n position: absolute;\n display: none;\n z-index: 1000; /* Increased z-index to ensure it's on top */\n padding: 0;\n box-shadow: 2px 3px 10px 5px rgba(0, 0, 0, 0.15);\n box-sizing: border-box;\n min-width: fit-content;\n line-height: initial;\n text-align: initial;\n background-color: var(--ox-popup-list-background-color, var(--md-sys-color-surface));\n color: var(--ox-popup-list-color, var(--md-sys-color-on-surface));\n margin: 0;\n }\n\n :host([active]) {\n display: flex;\n flex-direction: column;\n }\n\n :host(*:focus) {\n outline: none;\n }\n\n #backdrop {\n position: fixed;\n top: -100vh;\n left: -100vw;\n width: 300vw;\n height: 300vh;\n background-color: black;\n opacity: 0.5;\n }\n `\n ]\n\n @property({ type: Boolean, attribute: 'prevent-close-on-blur' }) preventCloseOnBlur: boolean = false\n @property({ type: Boolean, attribute: 'backdrop' }) backdrop: boolean = false\n\n private lastActive: HTMLElement = document.activeElement as HTMLElement\n protected removeAfterUse: boolean = false\n\n render() {\n return html`\n ${this.backdrop ? html`<div id=\"backdrop\" @click=${() => this.close()}></div>` : nothing}\n <slot></slot>\n `\n }\n\n protected _onfocusout: (e: FocusEvent) => void = function (this: OxPopup, e: FocusEvent) {\n const to = e.relatedTarget as HTMLElement\n\n if (!this.contains(to)) {\n !this.preventCloseOnBlur && !window.POPUP_DEBUG && this.close()\n }\n }.bind(this)\n\n protected _onkeydown: (e: KeyboardEvent) => void = function (this: OxPopup, e: KeyboardEvent) {\n e.stopPropagation()\n\n switch (e.key) {\n case 'Esc': // for IE/Edge\n case 'Escape':\n this.close()\n break\n }\n }.bind(this)\n\n protected _onkeyup: (e: KeyboardEvent) => void = function (this: OxPopup, e: KeyboardEvent) {\n e.stopPropagation()\n }.bind(this)\n\n protected _onmouseup: (e: MouseEvent) => void = function (this: OxPopup, e: MouseEvent) {\n e.stopPropagation()\n }.bind(this)\n\n protected _onmousedown: (e: MouseEvent) => void = function (this: OxPopup, e: MouseEvent) {\n e.stopPropagation()\n }.bind(this)\n\n protected _oncontextmenu: (e: Event) => void = function (this: OxPopup, e: Event) {\n e.stopPropagation()\n // this.close()\n }.bind(this)\n\n protected _onclick: (e: MouseEvent) => void = function (this: OxPopup, e: MouseEvent) {\n e.stopPropagation()\n }.bind(this)\n\n protected _onclose: (e: Event) => void = function (this: OxPopup, e: Event) {\n this.close()\n }.bind(this)\n\n protected _oncollapse: (e: Event) => void = function (this: OxPopup, e: Event) {\n e.stopPropagation()\n this.close()\n }.bind(this)\n\n protected _onwindowblur: (e: Event) => void = function (this: OxPopup, e: Event) {\n !this.preventCloseOnBlur && !window.POPUP_DEBUG && this.close()\n }.bind(this)\n\n connectedCallback() {\n super.connectedCallback()\n\n this.addEventListener('focusout', this._onfocusout)\n this.addEventListener('keydown', this._onkeydown)\n this.addEventListener('keyup', this._onkeyup)\n this.addEventListener('click', this._onclick)\n this.addEventListener('mouseup', this._onmouseup)\n this.addEventListener('mousedown', this._onmousedown)\n this.addEventListener('contextmenu', this._oncontextmenu)\n this.addEventListener('ox-close', this._onclose)\n this.addEventListener('ox-collapse', this._oncollapse)\n\n this.setAttribute('tabindex', '0') // make this element focusable\n this.guaranteeFocus()\n }\n\n /**\n * Configuration for opening ox-popup\n *\n * @typedef {Object} PopupOpenOptions\n * @property {HTMLTemplate} template HTMLTemplate to be displayed inside the popup\n * @property {Number} top The position-top where the pop-up will be displayed\n * @property {Number} left The position-left where the pop-up will be displayed\n * @property {Number} right The position-right where the pop-up will be displayed\n * @property {Number} bottom The position-bottom where the pop-up will be displayed\n * @property {string} width The maximum width of the popup (CSS string)\n * @property {string} height The maximum height of the popup (CSS string)\n * @property {HTMLElement} parent Popup's parent element\n * @property {string} style Additional CSS styles for the popup\n * @property {boolean} preventCloseOnBlur Flag to prevent closing the popup on blur\n * @property {boolean} backdrop If true, a semi-transparent background will be applied behind the popup, dimming the rest of the page.\n */\n static open({\n template,\n top,\n left,\n right,\n bottom,\n width,\n height,\n parent,\n style,\n preventCloseOnBlur,\n backdrop\n }: {\n template: unknown\n top?: number\n left?: number\n right?: number\n bottom?: number\n width?: string\n height?: string\n parent?: Element | null\n style?: string\n preventCloseOnBlur?: boolean\n backdrop?: boolean\n }): OxPopup {\n const target = document.createElement('ox-popup') as OxPopup\n if (preventCloseOnBlur) {\n target.preventCloseOnBlur = preventCloseOnBlur\n }\n\n if (backdrop) {\n target.backdrop = backdrop\n }\n\n if (style) {\n target.style.cssText = style\n }\n\n render(template, target)\n\n if (parent) {\n var { left, top, right, bottom } = convertToFixedPosition({\n left,\n top,\n right,\n bottom,\n relativeElement: parent as HTMLElement\n })\n }\n\n document.body.appendChild(target)\n target.removeAfterUse = true\n target.open({ top, left, right, bottom, width, height })\n\n return target\n }\n\n /**\n * Opens the 'ox-popup' with the specified position and dimensions.\n *\n * @param {Object} options - An object specifying the position and dimensions of the popup.\n * @param {number} options.left - The left position (in pixels) where the popup should be displayed. If not provided, it will be centered horizontally.\n * @param {number} options.top - The top position (in pixels) where the popup should be displayed. If not provided, it will be centered vertically.\n * @param {number} options.right - The right position (in pixels) where the popup should be displayed. If provided, it will override the 'left' value.\n * @param {number} options.bottom - The bottom position (in pixels) where the popup should be displayed. If provided, it will override the 'top' value.\n * @param {string} options.width - The maximum width of the popup (CSS string). For example, '300px'.\n * @param {string} options.height - The maximum height of the popup (CSS string). For example, '200px'.\n * @param {boolean} [options.silent=false] - A flag indicating whether the popup should auto-focus or not. If set to true, the popup won't attempt to focus on any element.\n * @param {boolean} [options.fixed=false] - A flag indicating whether the popup should be positioned fixed relative to the viewport. If set to true, the popup will be fixed.\n */\n open({\n left,\n top,\n right,\n bottom,\n width,\n height,\n silent = false,\n fixed = false\n }: {\n left?: number\n top?: number\n right?: number\n bottom?: number\n width?: string\n height?: string\n silent?: boolean\n fixed?: boolean\n }) {\n if (width) {\n this.style.maxWidth = width\n this.style.overflowX = 'auto'\n }\n\n if (height) {\n this.style.maxHeight = height\n this.style.overflowY = 'auto'\n }\n\n if (left === undefined && top === undefined && right === undefined && bottom === undefined) {\n this.style.transform = 'translateX(-50%) translateY(-50%)'\n this.style.left = '50%'\n this.style.top = '50%'\n } else if (fixed) {\n const bounding = this.parentElement?.getBoundingClientRect() || {\n left: 0,\n right: 0,\n top: 0,\n bottom: 0\n }\n\n this.style.position = 'fixed'\n\n if (left !== undefined) {\n left += bounding.left\n this.style.left = `${left}px`\n }\n if (top !== undefined) {\n top += bounding.top\n this.style.top = `${top}px`\n }\n if (right !== undefined) {\n right = window.innerWidth - (bounding.right - right)\n this.style.right = `${right}px`\n }\n if (bottom !== undefined) {\n bottom = window.innerHeight - (bounding.bottom - bottom)\n this.style.bottom = `${bottom}px`\n }\n } else {\n if (left !== undefined) {\n this.style.left = `${left}px`\n }\n if (top !== undefined) {\n this.style.top = `${top}px`\n }\n if (right !== undefined) {\n this.style.right = `${right}px`\n }\n if (bottom !== undefined) {\n this.style.bottom = `${bottom}px`\n }\n }\n\n this.setAttribute('active', '')\n\n requestAnimationFrame(() => {\n const vh = window.innerHeight\n const vw = window.innerWidth\n\n var bounding = this.getBoundingClientRect()\n\n var h = bounding.height\n var w = bounding.width\n var t = bounding.top\n var l = bounding.left\n\n // If the popup is too large, it will cause overflow scrolling.\n if (vh < h) {\n this.style.height = `${Math.min(Math.max(Math.floor((vh * 2) / 3), vh - (t + 20)), vh)}px`\n this.style.overflow = 'auto'\n h = vh\n }\n\n if (vw < w) {\n this.style.width = `${Math.min(Math.max(Math.floor((vw * 2) / 3), vw - (l + 20)), vw)}px`\n this.style.overflow = 'auto'\n w = vw\n }\n\n // To prevent pop-ups from crossing screen boundaries, use the\n const computedStyle = getComputedStyle(this)\n\n if (t < 0) {\n this.style.top = '10px'\n this.style.bottom = ''\n } else if (vh <= t + h) {\n this.style.top = ''\n this.style.bottom = '10px'\n }\n\n if (l < 0) {\n this.style.left = `calc(${computedStyle.left} - ${l - 10}px)`\n this.style.right = ''\n } else if (vw < l + w) {\n this.style.left = `calc(${computedStyle.left} - ${l + w - vw + 10}px)`\n this.style.right = ''\n }\n })\n\n // auto focusing\n !silent && this.guaranteeFocus()\n\n /* When the window is out of focus, all pop-ups should disappear. */\n window.addEventListener('blur', this._onwindowblur)\n }\n\n guaranteeFocus(target?: HTMLElement) {\n const focusible = (target || this).querySelector(\n ':scope > button, :scope > [href], :scope > input, :scope > select, :scope > textarea, :scope > [tabindex]:not([tabindex=\"-1\"])'\n )\n\n if (focusible) {\n ;(focusible as HTMLElement).focus()\n } else {\n this.focus()\n }\n }\n\n /**\n * Closes the 'ox-popup'.\n */\n close() {\n this.removeAttribute('active')\n\n window.removeEventListener('blur', this._onwindowblur)\n\n if (this.removeAfterUse && this.parentElement) {\n /* this case is when the popup is opened by OxPopup.open(...) */\n this.removeEventListener('focusout', this._onfocusout)\n this.removeEventListener('keydown', this._onkeydown)\n this.removeEventListener('keyup', this._onkeyup)\n this.removeEventListener('click', this._onclick)\n this.removeEventListener('ox-close', this._onclose)\n this.removeEventListener('ox-collapse', this._oncollapse)\n this.removeEventListener('mouseup', this._onmouseup)\n this.removeEventListener('mousedown', this._onmousedown)\n this.removeEventListener('contextmenu', this._oncontextmenu)\n\n this.parentElement.removeChild(this)\n\n if (this.lastActive) {\n this.lastAct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CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;YAChD,IAAI,CAAC,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;YACnD,IAAI,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;YACzD,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;YACpD,IAAI,CAAC,mBAAmB,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;YACxD,IAAI,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;YAE5D,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;YAEpC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACpB,IAAI,CAAC,UAAU,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAA;YAClD,CAAC;QACH,CAAC;IACH,CAAC;;AA9UgE;IAAhE,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,CAAC;mDAAoC;AAChD;IAAnD,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;yCAA0B;AAzClE,OAAO;IADnB,aAAa,CAAC,UAAU,CAAC;GACb,OAAO,CAuXnB","sourcesContent":["import { css, html, LitElement, nothing } from 'lit'\nimport { render } from 'lit-html'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { ScrollbarStyles } from '@operato/styles'\n\nimport { convertToFixedPosition } from './position-converter.js'\n\ndeclare global {\n interface Window {\n POPUP_DEBUG?: boolean\n }\n}\n\n/**\n * Custom element class representing the 'ox-popup' component.\n *\n * This component provides the functionality to display a popup with various configuration options.\n * It can be used to show additional information, notifications, or user interactions within a web application.\n *\n * @fires ox-close - Dispatched when the popup is closed.\n * @fires ox-collapse - Dispatched when the popup is collapsed.\n */\n@customElement('ox-popup')\nexport class OxPopup extends LitElement {\n static styles = [\n ScrollbarStyles,\n css`\n :host {\n position: absolute;\n display: none;\n z-index: 1000; /* Increased z-index to ensure it's on top */\n padding: 0;\n box-shadow: 2px 3px 10px 5px rgba(0, 0, 0, 0.15);\n box-sizing: border-box;\n min-width: fit-content;\n line-height: initial;\n text-align: initial;\n background-color: var(--ox-popup-list-background-color, var(--md-sys-color-surface));\n color: var(--ox-popup-list-color, var(--md-sys-color-on-surface));\n margin: 0;\n }\n\n :host([active]) {\n display: flex;\n flex-direction: column;\n }\n\n :host(*:focus) {\n outline: none;\n }\n\n #backdrop {\n position: fixed;\n top: -100vh;\n left: -100vw;\n width: 300vw;\n height: 300vh;\n background-color: black;\n opacity: 0.5;\n }\n `\n ]\n\n @property({ type: Boolean, attribute: 'prevent-close-on-blur' }) preventCloseOnBlur: boolean = false\n @property({ type: Boolean, attribute: 'backdrop' }) backdrop: boolean = false\n\n private lastActive: HTMLElement = document.activeElement as HTMLElement\n protected removeAfterUse: boolean = false\n\n render() {\n return html`\n ${this.backdrop ? html`<div id=\"backdrop\" @click=${() => this.close()}></div>` : nothing}\n <slot></slot>\n `\n }\n\n protected _onfocusout: (e: FocusEvent) => void = function (this: OxPopup, e: FocusEvent) {\n const to = e.relatedTarget as HTMLElement\n\n if (!this.contains(to)) {\n !this.preventCloseOnBlur && !window.POPUP_DEBUG && this.close()\n }\n }.bind(this)\n\n protected _onkeydown: (e: KeyboardEvent) => void = function (this: OxPopup, e: KeyboardEvent) {\n e.stopPropagation()\n\n switch (e.key) {\n case 'Esc': // for IE/Edge\n case 'Escape':\n this.close()\n break\n }\n }.bind(this)\n\n protected _onkeyup: (e: KeyboardEvent) => void = function (this: OxPopup, e: KeyboardEvent) {\n e.stopPropagation()\n }.bind(this)\n\n protected _onmouseup: (e: MouseEvent) => void = function (this: OxPopup, e: MouseEvent) {\n e.stopPropagation()\n }.bind(this)\n\n protected _onmousedown: (e: MouseEvent) => void = function (this: OxPopup, e: MouseEvent) {\n e.stopPropagation()\n }.bind(this)\n\n protected _oncontextmenu: (e: Event) => void = function (this: OxPopup, e: Event) {\n e.stopPropagation()\n // this.close()\n }.bind(this)\n\n protected _onclick: (e: MouseEvent) => void = function (this: OxPopup, e: MouseEvent) {\n e.stopPropagation()\n }.bind(this)\n\n protected _onclose: (e: Event) => void = function (this: OxPopup, e: Event) {\n this.close()\n }.bind(this)\n\n protected _oncollapse: (e: Event) => void = function (this: OxPopup, e: Event) {\n e.stopPropagation()\n this.close()\n }.bind(this)\n\n protected _onwindowblur: (e: Event) => void = function (this: OxPopup, e: Event) {\n !this.preventCloseOnBlur && !window.POPUP_DEBUG && this.close()\n }.bind(this)\n\n connectedCallback() {\n super.connectedCallback()\n\n this.addEventListener('focusout', this._onfocusout)\n this.addEventListener('keydown', this._onkeydown)\n this.addEventListener('keyup', this._onkeyup)\n this.addEventListener('click', this._onclick)\n this.addEventListener('mouseup', this._onmouseup)\n this.addEventListener('mousedown', this._onmousedown)\n this.addEventListener('contextmenu', this._oncontextmenu)\n this.addEventListener('ox-close', this._onclose)\n this.addEventListener('ox-collapse', this._oncollapse)\n\n this.setAttribute('tabindex', '0') // make this element focusable\n this.guaranteeFocus()\n }\n\n /**\n * Configuration for opening ox-popup\n *\n * @typedef {Object} PopupOpenOptions\n * @property {HTMLTemplate} template HTMLTemplate to be displayed inside the popup\n * @property {Number} top The position-top where the pop-up will be displayed\n * @property {Number} left The position-left where the pop-up will be displayed\n * @property {Number} right The position-right where the pop-up will be displayed\n * @property {Number} bottom The position-bottom where the pop-up will be displayed\n * @property {string} width The maximum width of the popup (CSS string)\n * @property {string} height The maximum height of the popup (CSS string)\n * @property {HTMLElement} parent Popup's parent element\n * @property {string} style Additional CSS styles for the popup\n * @property {boolean} preventCloseOnBlur Flag to prevent closing the popup on blur\n * @property {boolean} backdrop If true, a semi-transparent background will be applied behind the popup, dimming the rest of the page.\n */\n static open({\n template,\n top,\n left,\n right,\n bottom,\n width,\n height,\n parent,\n style,\n preventCloseOnBlur,\n backdrop\n }: {\n template: unknown\n top?: number\n left?: number\n right?: number\n bottom?: number\n width?: string\n height?: string\n parent?: Element | null\n style?: string\n preventCloseOnBlur?: boolean\n backdrop?: boolean\n }): OxPopup {\n const target = document.createElement('ox-popup') as OxPopup\n if (preventCloseOnBlur) {\n target.preventCloseOnBlur = preventCloseOnBlur\n }\n\n if (backdrop) {\n target.backdrop = backdrop\n }\n\n if (style) {\n target.style.cssText = style\n }\n\n render(template, target)\n\n if (parent) {\n var { left, top, right, bottom } = convertToFixedPosition({\n left,\n top,\n right,\n bottom,\n relativeElement: parent as HTMLElement\n })\n }\n\n document.body.appendChild(target)\n target.removeAfterUse = true\n target.open({ top, left, right, bottom, width, height })\n\n return target\n }\n\n /**\n * Opens the 'ox-popup' with the specified position and dimensions.\n *\n * @param {Object} options - An object specifying the position and dimensions of the popup.\n * @param {number} options.left - The left position (in pixels) where the popup should be displayed. If not provided, it will be centered horizontally.\n * @param {number} options.top - The top position (in pixels) where the popup should be displayed. If not provided, it will be centered vertically.\n * @param {number} options.right - The right position (in pixels) where the popup should be displayed. If provided, it will override the 'left' value.\n * @param {number} options.bottom - The bottom position (in pixels) where the popup should be displayed. If provided, it will override the 'top' value.\n * @param {string} options.width - The maximum width of the popup (CSS string). For example, '300px'.\n * @param {string} options.height - The maximum height of the popup (CSS string). For example, '200px'.\n * @param {boolean} [options.silent=false] - A flag indicating whether the popup should auto-focus or not. If set to true, the popup won't attempt to focus on any element.\n * @param {boolean} [options.fixed=false] - A flag indicating whether the popup should be positioned fixed relative to the viewport. If set to true, the popup will be fixed.\n */\n open({\n left,\n top,\n right,\n bottom,\n width,\n height,\n silent = false,\n fixed = false\n }: {\n left?: number\n top?: number\n right?: number\n bottom?: number\n width?: string\n height?: string\n silent?: boolean\n fixed?: boolean\n }) {\n if (width) {\n this.style.maxWidth = width\n this.style.overflowX = 'auto'\n }\n\n if (height) {\n this.style.maxHeight = height\n this.style.overflowY = 'auto'\n }\n\n if (left === undefined && top === undefined && right === undefined && bottom === undefined) {\n this.style.transform = 'translateX(-50%) translateY(-50%)'\n this.style.left = '50%'\n this.style.top = '50%'\n } else if (fixed) {\n const bounding = this.parentElement?.getBoundingClientRect() || {\n left: 0,\n right: 0,\n top: 0,\n bottom: 0\n }\n\n this.style.position = 'fixed'\n\n if (left !== undefined) {\n left += bounding.left\n this.style.left = `${left}px`\n }\n if (top !== undefined) {\n top += bounding.top\n this.style.top = `${top}px`\n }\n if (right !== undefined) {\n right = window.innerWidth - (bounding.right - right)\n this.style.right = `${right}px`\n }\n if (bottom !== undefined) {\n bottom = window.innerHeight - (bounding.bottom - bottom)\n this.style.bottom = `${bottom}px`\n }\n } else {\n if (left !== undefined) {\n this.style.left = `${left}px`\n }\n if (top !== undefined) {\n this.style.top = `${top}px`\n }\n if (right !== undefined) {\n this.style.right = `${right}px`\n }\n if (bottom !== undefined) {\n this.style.bottom = `${bottom}px`\n }\n }\n\n this.setAttribute('active', '')\n\n requestAnimationFrame(() => {\n const vh = window.innerHeight\n const vw = window.innerWidth\n\n var bounding = this.getBoundingClientRect()\n\n var h = bounding.height\n var w = bounding.width\n var t = bounding.top\n var l = bounding.left\n\n // If the popup is too large, it will cause overflow scrolling.\n if (vh < h) {\n this.style.height = `${Math.min(Math.max(Math.floor((vh * 2) / 3), vh - (t + 20)), vh)}px`\n this.style.overflow = 'auto'\n h = vh\n }\n\n if (vw < w) {\n this.style.width = `${Math.min(Math.max(Math.floor((vw * 2) / 3), vw - (l + 20)), vw)}px`\n this.style.overflow = 'auto'\n w = vw\n }\n\n // To prevent pop-ups from crossing screen boundaries, use the\n const computedStyle = getComputedStyle(this)\n\n if (t < 0) {\n this.style.top = '10px'\n this.style.bottom = ''\n } else if (vh <= t + h) {\n this.style.top = ''\n this.style.bottom = '10px'\n }\n\n if (l < 0) {\n this.style.left = `calc(${computedStyle.left} - ${l - 10}px)`\n this.style.right = ''\n } else if (vw < l + w) {\n this.style.left = `calc(${computedStyle.left} - ${l + w - vw + 10}px)`\n this.style.right = ''\n }\n })\n\n // auto focusing\n !silent && this.guaranteeFocus()\n\n /* When the window is out of focus, all pop-ups should disappear. */\n window.addEventListener('blur', this._onwindowblur)\n }\n\n guaranteeFocus(target?: HTMLElement) {\n const focusible = (target || this).querySelector(\n ':scope > button, :scope > [href], :scope > input, :scope > select, :scope > textarea, :scope > [tabindex]:not([tabindex=\"-1\"])'\n )\n\n if (focusible) {\n ;(focusible as HTMLElement).focus()\n } else {\n this.focus()\n }\n }\n\n /**\n * Closes the 'ox-popup'.\n */\n close() {\n this.removeAttribute('active')\n\n window.removeEventListener('blur', this._onwindowblur)\n\n if (this.removeAfterUse && this.parentElement) {\n /* this case is when the popup is opened by OxPopup.open(...) */\n this.removeEventListener('focusout', this._onfocusout)\n this.removeEventListener('keydown', this._onkeydown)\n this.removeEventListener('keyup', this._onkeyup)\n this.removeEventListener('click', this._onclick)\n this.removeEventListener('ox-close', this._onclose)\n this.removeEventListener('ox-collapse', this._oncollapse)\n this.removeEventListener('mouseup', this._onmouseup)\n this.removeEventListener('mousedown', this._onmousedown)\n this.removeEventListener('contextmenu', this._oncontextmenu)\n\n this.parentElement.removeChild(this)\n\n if (this.lastActive) {\n this.lastActive.focus && this.lastActive.focus()\n }\n }\n }\n}\n"]}