@operato/layout 0.2.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +29 -0
- package/.storybook/main.js +3 -0
- package/.storybook/server.mjs +8 -0
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +75 -0
- package/demo/index.html +142 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/ox-layout.d.ts +45 -0
- package/dist/src/ox-layout.js +148 -0
- package/dist/src/ox-layout.js.map +1 -0
- package/dist/src/ox-toolbar-style.d.ts +4 -0
- package/dist/src/ox-toolbar-style.js +226 -0
- package/dist/src/ox-toolbar-style.js.map +1 -0
- package/dist/src/ox-toolbar.d.ts +4 -0
- package/dist/src/ox-toolbar.js +122 -0
- package/dist/src/ox-toolbar.js.map +1 -0
- package/dist/stories/index.stories.d.ts +33 -0
- package/dist/stories/index.stories.js +33 -0
- package/dist/stories/index.stories.js.map +1 -0
- package/dist/test/ox-layout.test.d.ts +1 -0
- package/dist/test/ox-layout.test.js +24 -0
- package/dist/test/ox-layout.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +71 -0
- package/src/index.ts +1 -0
- package/src/ox-layout.ts +191 -0
- package/src/ox-toolbar-style.ts +227 -0
- package/src/ox-toolbar.ts +135 -0
- package/stories/index.stories.ts +52 -0
- package/test/ox-layout.test.ts +35 -0
- package/tsconfig.json +22 -0
- package/web-dev-server.config.mjs +27 -0
- package/web-test-runner.config.mjs +41 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# EditorConfig helps developers define and maintain consistent
|
|
2
|
+
# coding styles between different editors and IDEs
|
|
3
|
+
# editorconfig.org
|
|
4
|
+
|
|
5
|
+
root = true
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
[*]
|
|
9
|
+
|
|
10
|
+
# Change these settings to your own preference
|
|
11
|
+
indent_style = space
|
|
12
|
+
indent_size = 2
|
|
13
|
+
|
|
14
|
+
# We recommend you to keep these unchanged
|
|
15
|
+
end_of_line = lf
|
|
16
|
+
charset = utf-8
|
|
17
|
+
trim_trailing_whitespace = true
|
|
18
|
+
insert_final_newline = true
|
|
19
|
+
|
|
20
|
+
[*.md]
|
|
21
|
+
trim_trailing_whitespace = false
|
|
22
|
+
|
|
23
|
+
[*.json]
|
|
24
|
+
indent_size = 2
|
|
25
|
+
|
|
26
|
+
[*.{html,js,md}]
|
|
27
|
+
block_comment_start = /**
|
|
28
|
+
block_comment = *
|
|
29
|
+
block_comment_end = */
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { storybookPlugin } from '@web/dev-server-storybook';
|
|
2
|
+
import baseConfig from '../web-dev-server.config.mjs';
|
|
3
|
+
|
|
4
|
+
export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
|
|
5
|
+
...baseConfig,
|
|
6
|
+
open: '/',
|
|
7
|
+
plugins: [storybookPlugin({ type: 'web-components' }), ...baseConfig.plugins],
|
|
8
|
+
});
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
### [0.2.46](https://github.com/hatiolab/operato/compare/v0.2.45...v0.2.46) (2021-12-12)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### :rocket: New Features
|
|
10
|
+
|
|
11
|
+
* add layout and oops ([56737fa](https://github.com/hatiolab/operato/commit/56737fa117ed2135e279ca0f1e4c969daddf7b34))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### :bug: Bug Fix
|
|
15
|
+
|
|
16
|
+
* set all module version to 0.2.45 ([40cea11](https://github.com/hatiolab/operato/commit/40cea11fab09ab3fb96bcd7db797abd13b23c216))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) hatiolab.com
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# \<mini-layout>
|
|
2
|
+
|
|
3
|
+
This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i mini-layout
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<script type="module">
|
|
15
|
+
import 'mini-layout/mini-layout.js'
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<mini-layout></mini-layout>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Linting and formatting
|
|
22
|
+
|
|
23
|
+
To scan the project for linting and formatting errors, run
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm run lint
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
To automatically fix linting and formatting errors, run
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm run format
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Testing with Web Test Runner
|
|
36
|
+
|
|
37
|
+
To execute a single test run:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm run test
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
To run the tests in interactive watch mode run:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm run test:watch
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Demoing with Storybook
|
|
50
|
+
|
|
51
|
+
To run a local instance of Storybook for your component, run
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm run storybook
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
To build a production version of Storybook, run
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm run storybook:build
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Tooling configs
|
|
64
|
+
|
|
65
|
+
For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
|
|
66
|
+
|
|
67
|
+
If you customize the configuration a lot, you can consider moving them to individual files.
|
|
68
|
+
|
|
69
|
+
## Local Demo with `web-dev-server`
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm start
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
To run a local development server that serves the basic demo located in `demo/index.html`
|
package/demo/index.html
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en-GB">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<style>
|
|
6
|
+
body {
|
|
7
|
+
background: #fafafa;
|
|
8
|
+
--ox-checkbox-size: 12px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
#demo {
|
|
12
|
+
position: relative;
|
|
13
|
+
height: 300px;
|
|
14
|
+
background-color: lightgray;
|
|
15
|
+
vertical-align: middle;
|
|
16
|
+
}
|
|
17
|
+
</style>
|
|
18
|
+
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet" />
|
|
19
|
+
<link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
|
|
20
|
+
</head>
|
|
21
|
+
<body>
|
|
22
|
+
<div id="demo"></div>
|
|
23
|
+
|
|
24
|
+
<script type="module">
|
|
25
|
+
import { html, render } from 'lit'
|
|
26
|
+
import '../dist/src/ox-layout-menu.js'
|
|
27
|
+
import '../dist/src/ox-layout-menuitem.js'
|
|
28
|
+
import '@material/mwc-icon'
|
|
29
|
+
import '@operato/input'
|
|
30
|
+
|
|
31
|
+
import { OxPopupMenu } from '../dist/src/ox-layout-menu.js'
|
|
32
|
+
|
|
33
|
+
const parent = document.querySelector('#demo')
|
|
34
|
+
|
|
35
|
+
parent.addEventListener('click', function (e) {
|
|
36
|
+
OxPopupMenu.open({
|
|
37
|
+
template: html`
|
|
38
|
+
<ox-layout-menuitem
|
|
39
|
+
label="article - click me"
|
|
40
|
+
@selected=${function (e) {
|
|
41
|
+
console.log('first level article selected')
|
|
42
|
+
}}
|
|
43
|
+
>
|
|
44
|
+
<mwc-icon slot="icon">article</mwc-icon>
|
|
45
|
+
</ox-layout-menuitem>
|
|
46
|
+
|
|
47
|
+
<ox-layout-menuitem label="home">
|
|
48
|
+
<mwc-icon slot="icon">home</mwc-icon>
|
|
49
|
+
</ox-layout-menuitem>
|
|
50
|
+
|
|
51
|
+
<ox-layout-menuitem label="empty"> </ox-layout-menuitem>
|
|
52
|
+
|
|
53
|
+
<ox-layout-menuitem
|
|
54
|
+
label="click me to toggle"
|
|
55
|
+
@selected=${function (e) {
|
|
56
|
+
const icon = this.querySelector('mwc-icon')
|
|
57
|
+
icon.innerHTML = icon.innerHTML == 'check' ? '' : 'check'
|
|
58
|
+
}}
|
|
59
|
+
alive-on-select
|
|
60
|
+
>
|
|
61
|
+
<mwc-icon slot="icon" style="width: 20px;height: 20px;"></mwc-icon>
|
|
62
|
+
</ox-layout-menuitem>
|
|
63
|
+
|
|
64
|
+
<ox-layout-menuitem label="verified" @selected=${e => console.log('selected verified')}>
|
|
65
|
+
<mwc-icon slot="icon">verified</mwc-icon>
|
|
66
|
+
<ox-layout-menu>
|
|
67
|
+
<ox-layout-menuitem
|
|
68
|
+
label="article"
|
|
69
|
+
@selected=${function (e) {
|
|
70
|
+
console.log('article selected')
|
|
71
|
+
}}
|
|
72
|
+
alive-on-select
|
|
73
|
+
>
|
|
74
|
+
<mwc-icon slot="icon">article</mwc-icon>
|
|
75
|
+
</ox-layout-menuitem>
|
|
76
|
+
|
|
77
|
+
<ox-layout-menuitem label="home">
|
|
78
|
+
<mwc-icon slot="icon">home</mwc-icon>
|
|
79
|
+
</ox-layout-menuitem>
|
|
80
|
+
|
|
81
|
+
<ox-layout-menuitem label="verified">
|
|
82
|
+
<mwc-icon slot="icon">verified</mwc-icon>
|
|
83
|
+
<ox-layout-menu>
|
|
84
|
+
<ox-layout-menuitem label="article">
|
|
85
|
+
<mwc-icon slot="icon">article</mwc-icon>
|
|
86
|
+
</ox-layout-menuitem>
|
|
87
|
+
|
|
88
|
+
<ox-layout-menuitem label="home">
|
|
89
|
+
<mwc-icon slot="icon">home</mwc-icon>
|
|
90
|
+
</ox-layout-menuitem>
|
|
91
|
+
|
|
92
|
+
<ox-layout-menuitem label="verified">
|
|
93
|
+
<mwc-icon slot="icon">verified</mwc-icon>
|
|
94
|
+
</ox-layout-menuitem>
|
|
95
|
+
|
|
96
|
+
<ox-layout-menuitem label="checkbox">
|
|
97
|
+
<input type="checkbox" slot="icon" />
|
|
98
|
+
</ox-layout-menuitem>
|
|
99
|
+
|
|
100
|
+
<div separator></div>
|
|
101
|
+
</ox-layout-menu>
|
|
102
|
+
</ox-layout-menuitem>
|
|
103
|
+
|
|
104
|
+
<div separator></div>
|
|
105
|
+
|
|
106
|
+
<ox-layout-menuitem label="checkbox">
|
|
107
|
+
<input type="checkbox" slot="icon" />
|
|
108
|
+
</ox-layout-menuitem>
|
|
109
|
+
</ox-layout-menu>
|
|
110
|
+
</ox-layout-menuitem>
|
|
111
|
+
|
|
112
|
+
<ox-layout-menuitem label="checkbox in icon area" alive-on-select>
|
|
113
|
+
<input type="checkbox" slot="icon" />
|
|
114
|
+
</ox-layout-menuitem>
|
|
115
|
+
|
|
116
|
+
<div separator></div>
|
|
117
|
+
|
|
118
|
+
<div menu>Plain Text</div>
|
|
119
|
+
|
|
120
|
+
<div menu alive-on-select>
|
|
121
|
+
<ox-checkbox label="checkbox" slot="icon" checked />checkbox</ox-checkbox>
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
<div menu alive-on-select>
|
|
125
|
+
<input id="checkbox-01" type="checkbox" />
|
|
126
|
+
<label for="checkbox-01">custom menu</label>
|
|
127
|
+
</div>
|
|
128
|
+
<div menu alive-on-select>
|
|
129
|
+
<label for="text-01">value</label>
|
|
130
|
+
<input id="text-01" type="text" value="Plain text input" />
|
|
131
|
+
</div>
|
|
132
|
+
`,
|
|
133
|
+
top: e.pageY,
|
|
134
|
+
left: e.pageX,
|
|
135
|
+
parent
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
render(html`clike anywhere in this box to layout mini.`, parent)
|
|
140
|
+
</script>
|
|
141
|
+
</body>
|
|
142
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ox-layout';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA","sourcesContent":["export * from './ox-layout'\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
export declare class OxLayout extends LitElement {
|
|
3
|
+
static styles: import("lit").CSSResult[];
|
|
4
|
+
_parent?: Element;
|
|
5
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
6
|
+
protected _onfocusout: (e: FocusEvent) => void;
|
|
7
|
+
protected _onkeydown: (e: KeyboardEvent) => void;
|
|
8
|
+
protected _onkeyup: (e: KeyboardEvent) => void;
|
|
9
|
+
protected _onclick: (e: MouseEvent) => void;
|
|
10
|
+
protected _onclose: (e: Event) => void;
|
|
11
|
+
protected _oncollapse: (e: Event) => void;
|
|
12
|
+
protected _onwindowblur: (e: Event) => void;
|
|
13
|
+
connectedCallback(): void;
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for opening ox-layout
|
|
16
|
+
*
|
|
17
|
+
* @typedef {Object} PopupOpenOptions
|
|
18
|
+
* @property {HTMLTemplate} template HTMLTemplate to be displayed inside the layout
|
|
19
|
+
* @property {Number} top The position-top where the pop-up will be displayed
|
|
20
|
+
* @property {Number} left The position-left where the pop-up will be displayed
|
|
21
|
+
* @property {HTMLElement} parent Popup's parent element
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Open Popup
|
|
25
|
+
*
|
|
26
|
+
* @param {PopupOpenOptions}
|
|
27
|
+
*/
|
|
28
|
+
static open({ template, top, left, right, bottom, parent }: {
|
|
29
|
+
template: unknown;
|
|
30
|
+
top?: number;
|
|
31
|
+
left?: number;
|
|
32
|
+
right?: number;
|
|
33
|
+
bottom?: number;
|
|
34
|
+
parent?: Element | null;
|
|
35
|
+
}): void;
|
|
36
|
+
open({ left, top, right, bottom, silent }: {
|
|
37
|
+
left?: number;
|
|
38
|
+
top?: number;
|
|
39
|
+
right?: number;
|
|
40
|
+
bottom?: number;
|
|
41
|
+
silent?: boolean;
|
|
42
|
+
}): void;
|
|
43
|
+
guaranteeFocus(): void;
|
|
44
|
+
close(): void;
|
|
45
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { css, html, LitElement } from 'lit';
|
|
3
|
+
import { render } from 'lit-html';
|
|
4
|
+
import { customElement, state } from 'lit/decorators.js';
|
|
5
|
+
import { ScrollbarStyles } from '@operato/styles';
|
|
6
|
+
let OxLayout = class OxLayout extends LitElement {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this._onfocusout = function (e) {
|
|
10
|
+
const to = e.relatedTarget;
|
|
11
|
+
if (!this.contains(to)) {
|
|
12
|
+
/* 분명히 내 범위가 아닌 엘리먼트로 포커스가 옮겨졌다면, ox-popup은 닫혀야 한다. */
|
|
13
|
+
// @ts-ignore for debug
|
|
14
|
+
!window.POPUP_DEBUG && this.close();
|
|
15
|
+
}
|
|
16
|
+
}.bind(this);
|
|
17
|
+
this._onkeydown = function (e) {
|
|
18
|
+
e.stopPropagation();
|
|
19
|
+
switch (e.key) {
|
|
20
|
+
case 'Esc': // for IE/Edge
|
|
21
|
+
case 'Escape':
|
|
22
|
+
this.close();
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}.bind(this);
|
|
26
|
+
this._onkeyup = function (e) {
|
|
27
|
+
e.stopPropagation();
|
|
28
|
+
}.bind(this);
|
|
29
|
+
this._onclick = function (e) {
|
|
30
|
+
e.stopPropagation();
|
|
31
|
+
}.bind(this);
|
|
32
|
+
this._onclose = function (e) {
|
|
33
|
+
this.close();
|
|
34
|
+
}.bind(this);
|
|
35
|
+
this._oncollapse = function (e) {
|
|
36
|
+
e.stopPropagation();
|
|
37
|
+
this.close();
|
|
38
|
+
}.bind(this);
|
|
39
|
+
this._onwindowblur = function (e) {
|
|
40
|
+
// @ts-ignore for debug
|
|
41
|
+
!window.POPUP_DEBUG && this.close();
|
|
42
|
+
}.bind(this);
|
|
43
|
+
}
|
|
44
|
+
render() {
|
|
45
|
+
return html ` <slot> </slot> `;
|
|
46
|
+
}
|
|
47
|
+
connectedCallback() {
|
|
48
|
+
super.connectedCallback();
|
|
49
|
+
this.addEventListener('focusout', this._onfocusout);
|
|
50
|
+
this.addEventListener('keydown', this._onkeydown);
|
|
51
|
+
this.addEventListener('keyup', this._onkeyup);
|
|
52
|
+
this.addEventListener('click', this._onclick);
|
|
53
|
+
this.addEventListener('ox-close', this._onclose);
|
|
54
|
+
this.addEventListener('ox-collapse', this._oncollapse);
|
|
55
|
+
this.setAttribute('tabindex', '0'); // make this element focusable
|
|
56
|
+
this.guaranteeFocus();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Configuration for opening ox-layout
|
|
60
|
+
*
|
|
61
|
+
* @typedef {Object} PopupOpenOptions
|
|
62
|
+
* @property {HTMLTemplate} template HTMLTemplate to be displayed inside the layout
|
|
63
|
+
* @property {Number} top The position-top where the pop-up will be displayed
|
|
64
|
+
* @property {Number} left The position-left where the pop-up will be displayed
|
|
65
|
+
* @property {HTMLElement} parent Popup's parent element
|
|
66
|
+
*/
|
|
67
|
+
/**
|
|
68
|
+
* Open Popup
|
|
69
|
+
*
|
|
70
|
+
* @param {PopupOpenOptions}
|
|
71
|
+
*/
|
|
72
|
+
static open({ template, top, left, right, bottom, parent }) {
|
|
73
|
+
const owner = parent || document.body;
|
|
74
|
+
const target = document.createElement('ox-layout');
|
|
75
|
+
render(template, target);
|
|
76
|
+
target._parent = owner;
|
|
77
|
+
owner.appendChild(target);
|
|
78
|
+
target.open({ top, left, right, bottom });
|
|
79
|
+
}
|
|
80
|
+
open({ left, top, right, bottom, silent = false }) {
|
|
81
|
+
if (left !== undefined)
|
|
82
|
+
this.style.left = `${left}px`;
|
|
83
|
+
if (top !== undefined)
|
|
84
|
+
this.style.top = `${top}px`;
|
|
85
|
+
if (right !== undefined)
|
|
86
|
+
this.style.right = `${right}px`;
|
|
87
|
+
if (bottom !== undefined)
|
|
88
|
+
this.style.bottom = `${bottom}px`;
|
|
89
|
+
this.setAttribute('active', '');
|
|
90
|
+
!silent && this.guaranteeFocus();
|
|
91
|
+
/* When the window is out of focus, all pop-ups should disappear. */
|
|
92
|
+
window.addEventListener('blur', this._onwindowblur);
|
|
93
|
+
}
|
|
94
|
+
guaranteeFocus() {
|
|
95
|
+
const focusible = this.querySelector(':scope > button, :scope > [href], :scope > input, :scope > select, :scope > textarea, :scope > [tabindex]:not([tabindex="-1"])');
|
|
96
|
+
if (focusible) {
|
|
97
|
+
;
|
|
98
|
+
focusible.focus();
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
this.focus();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
close() {
|
|
105
|
+
this.removeAttribute('active');
|
|
106
|
+
window.removeEventListener('blur', this._onwindowblur);
|
|
107
|
+
if (this._parent) {
|
|
108
|
+
/* this case is when the layout is opened by OxLayout.open(...) */
|
|
109
|
+
this.removeEventListener('focusout', this._onfocusout);
|
|
110
|
+
this.removeEventListener('keydown', this._onkeydown);
|
|
111
|
+
this.removeEventListener('keyup', this._onkeyup);
|
|
112
|
+
this.removeEventListener('click', this._onclick);
|
|
113
|
+
this.removeEventListener('ox-close', this._onclose);
|
|
114
|
+
this.removeEventListener('ox-collapse', this._oncollapse);
|
|
115
|
+
this._parent.removeChild(this);
|
|
116
|
+
delete this._parent;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
OxLayout.styles = [
|
|
121
|
+
ScrollbarStyles,
|
|
122
|
+
css `
|
|
123
|
+
:host {
|
|
124
|
+
position: absolute;
|
|
125
|
+
display: none;
|
|
126
|
+
background-color: white;
|
|
127
|
+
z-index: 100;
|
|
128
|
+
box-sizing: border-box;
|
|
129
|
+
min-width: fit-content;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
:host([active]) {
|
|
133
|
+
display: block;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
:host(*:focus) {
|
|
137
|
+
outline: none;
|
|
138
|
+
}
|
|
139
|
+
`
|
|
140
|
+
];
|
|
141
|
+
__decorate([
|
|
142
|
+
state()
|
|
143
|
+
], OxLayout.prototype, "_parent", void 0);
|
|
144
|
+
OxLayout = __decorate([
|
|
145
|
+
customElement('ox-layout')
|
|
146
|
+
], OxLayout);
|
|
147
|
+
export { OxLayout };
|
|
148
|
+
//# sourceMappingURL=ox-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ox-layout.js","sourceRoot":"","sources":["../../src/ox-layout.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,IAAa,QAAQ,GAArB,MAAa,QAAS,SAAQ,UAAU;IAAxC;;QA6BY,gBAAW,GAA4B,UAA0B,CAAa;YACtF,MAAM,EAAE,GAAG,CAAC,CAAC,aAA4B,CAAA;YAEzC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE;gBACtB,sDAAsD;gBACtD,uBAAuB;gBACvB,CAAC,MAAM,CAAC,WAAW,IAAI,IAAI,CAAC,KAAK,EAAE,CAAA;aACpC;QACH,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEF,eAAU,GAA+B,UAA0B,CAAgB;YAC3F,CAAC,CAAC,eAAe,EAAE,CAAA;YAEnB,QAAQ,CAAC,CAAC,GAAG,EAAE;gBACb,KAAK,KAAK,CAAC,CAAC,cAAc;gBAC1B,KAAK,QAAQ;oBACX,IAAI,CAAC,KAAK,EAAE,CAAA;oBACZ,MAAK;aACR;QACH,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAE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AAQ;IADpB,aAAa,CAAC,WAAW,CAAC;GACd,QAAQ,CAuLpB;SAvLY,QAAQ","sourcesContent":["import { css, html, LitElement } from 'lit';\nimport { render } from 'lit-html';\nimport { customElement, state } from 'lit/decorators.js';\n\nimport { ScrollbarStyles } from '@operato/styles';\n\n@customElement('ox-layout')\nexport class OxLayout extends LitElement {\n static styles = [\n ScrollbarStyles,\n css`\n :host {\n position: absolute;\n display: none;\n background-color: white;\n z-index: 100;\n box-sizing: border-box;\n min-width: fit-content;\n }\n\n :host([active]) {\n display: block;\n }\n\n :host(*:focus) {\n outline: none;\n }\n `\n ]\n\n @state() _parent?: Element\n\n render() {\n return html` <slot> </slot> `\n }\n\n protected _onfocusout: (e: FocusEvent) => void = function (this: OxLayout, e: FocusEvent) {\n const to = e.relatedTarget as HTMLElement\n\n if (!this.contains(to)) {\n /* 분명히 내 범위가 아닌 엘리먼트로 포커스가 옮겨졌다면, ox-popup은 닫혀야 한다. */\n // @ts-ignore for debug\n !window.POPUP_DEBUG && this.close()\n }\n }.bind(this)\n\n protected _onkeydown: (e: KeyboardEvent) => void = function (this: OxLayout, 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: OxLayout, e: KeyboardEvent) {\n e.stopPropagation()\n }.bind(this)\n\n protected _onclick: (e: MouseEvent) => void = function (this: OxLayout, e: MouseEvent) {\n e.stopPropagation()\n }.bind(this)\n\n protected _onclose: (e: Event) => void = function (this: OxLayout, e: Event) {\n this.close()\n }.bind(this)\n\n protected _oncollapse: (e: Event) => void = function (this: OxLayout, e: Event) {\n e.stopPropagation()\n this.close()\n }.bind(this)\n\n protected _onwindowblur: (e: Event) => void = function (this: OxLayout, e: Event) {\n // @ts-ignore for debug\n !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('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-layout\n *\n * @typedef {Object} PopupOpenOptions\n * @property {HTMLTemplate} template HTMLTemplate to be displayed inside the layout\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 {HTMLElement} parent Popup's parent element\n */\n\n /**\n * Open Popup\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 }) {\n const owner = parent || document.body\n const target = document.createElement('ox-layout') as OxLayout\n\n render(template, target)\n\n target._parent = owner\n owner.appendChild(target)\n\n target.open({ top, left, right, bottom })\n }\n\n open({\n left,\n top,\n right,\n bottom,\n silent = false\n }: {\n left?: number\n top?: number\n right?: number\n bottom?: number\n silent?: boolean\n }) {\n if (left !== undefined) this.style.left = `${left}px`\n if (top !== undefined) this.style.top = `${top}px`\n if (right !== undefined) this.style.right = `${right}px`\n if (bottom !== undefined) this.style.bottom = `${bottom}px`\n\n this.setAttribute('active', '')\n\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() {\n const focusible = 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 close() {\n this.removeAttribute('active')\n\n window.removeEventListener('blur', this._onwindowblur)\n\n if (this._parent) {\n /* this case is when the layout is opened by OxLayout.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\n this._parent.removeChild(this)\n delete this._parent\n }\n }\n}\n"]}
|