@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/src/ox-layout.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { css, html, LitElement } from 'lit';
|
|
2
|
+
import { render } from 'lit-html';
|
|
3
|
+
import { customElement, state } from 'lit/decorators.js';
|
|
4
|
+
|
|
5
|
+
import { ScrollbarStyles } from '@operato/styles';
|
|
6
|
+
|
|
7
|
+
@customElement('ox-layout')
|
|
8
|
+
export class OxLayout extends LitElement {
|
|
9
|
+
static styles = [
|
|
10
|
+
ScrollbarStyles,
|
|
11
|
+
css`
|
|
12
|
+
:host {
|
|
13
|
+
position: absolute;
|
|
14
|
+
display: none;
|
|
15
|
+
background-color: white;
|
|
16
|
+
z-index: 100;
|
|
17
|
+
box-sizing: border-box;
|
|
18
|
+
min-width: fit-content;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
:host([active]) {
|
|
22
|
+
display: block;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
:host(*:focus) {
|
|
26
|
+
outline: none;
|
|
27
|
+
}
|
|
28
|
+
`
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
@state() _parent?: Element
|
|
32
|
+
|
|
33
|
+
render() {
|
|
34
|
+
return html` <slot> </slot> `
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
protected _onfocusout: (e: FocusEvent) => void = function (this: OxLayout, e: FocusEvent) {
|
|
38
|
+
const to = e.relatedTarget as HTMLElement
|
|
39
|
+
|
|
40
|
+
if (!this.contains(to)) {
|
|
41
|
+
/* 분명히 내 범위가 아닌 엘리먼트로 포커스가 옮겨졌다면, ox-popup은 닫혀야 한다. */
|
|
42
|
+
// @ts-ignore for debug
|
|
43
|
+
!window.POPUP_DEBUG && this.close()
|
|
44
|
+
}
|
|
45
|
+
}.bind(this)
|
|
46
|
+
|
|
47
|
+
protected _onkeydown: (e: KeyboardEvent) => void = function (this: OxLayout, e: KeyboardEvent) {
|
|
48
|
+
e.stopPropagation()
|
|
49
|
+
|
|
50
|
+
switch (e.key) {
|
|
51
|
+
case 'Esc': // for IE/Edge
|
|
52
|
+
case 'Escape':
|
|
53
|
+
this.close()
|
|
54
|
+
break
|
|
55
|
+
}
|
|
56
|
+
}.bind(this)
|
|
57
|
+
|
|
58
|
+
protected _onkeyup: (e: KeyboardEvent) => void = function (this: OxLayout, e: KeyboardEvent) {
|
|
59
|
+
e.stopPropagation()
|
|
60
|
+
}.bind(this)
|
|
61
|
+
|
|
62
|
+
protected _onclick: (e: MouseEvent) => void = function (this: OxLayout, e: MouseEvent) {
|
|
63
|
+
e.stopPropagation()
|
|
64
|
+
}.bind(this)
|
|
65
|
+
|
|
66
|
+
protected _onclose: (e: Event) => void = function (this: OxLayout, e: Event) {
|
|
67
|
+
this.close()
|
|
68
|
+
}.bind(this)
|
|
69
|
+
|
|
70
|
+
protected _oncollapse: (e: Event) => void = function (this: OxLayout, e: Event) {
|
|
71
|
+
e.stopPropagation()
|
|
72
|
+
this.close()
|
|
73
|
+
}.bind(this)
|
|
74
|
+
|
|
75
|
+
protected _onwindowblur: (e: Event) => void = function (this: OxLayout, e: Event) {
|
|
76
|
+
// @ts-ignore for debug
|
|
77
|
+
!window.POPUP_DEBUG && this.close()
|
|
78
|
+
}.bind(this)
|
|
79
|
+
|
|
80
|
+
connectedCallback() {
|
|
81
|
+
super.connectedCallback()
|
|
82
|
+
|
|
83
|
+
this.addEventListener('focusout', this._onfocusout)
|
|
84
|
+
this.addEventListener('keydown', this._onkeydown)
|
|
85
|
+
this.addEventListener('keyup', this._onkeyup)
|
|
86
|
+
this.addEventListener('click', this._onclick)
|
|
87
|
+
this.addEventListener('ox-close', this._onclose)
|
|
88
|
+
this.addEventListener('ox-collapse', this._oncollapse)
|
|
89
|
+
|
|
90
|
+
this.setAttribute('tabindex', '0') // make this element focusable
|
|
91
|
+
this.guaranteeFocus()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Configuration for opening ox-layout
|
|
96
|
+
*
|
|
97
|
+
* @typedef {Object} PopupOpenOptions
|
|
98
|
+
* @property {HTMLTemplate} template HTMLTemplate to be displayed inside the layout
|
|
99
|
+
* @property {Number} top The position-top where the pop-up will be displayed
|
|
100
|
+
* @property {Number} left The position-left where the pop-up will be displayed
|
|
101
|
+
* @property {HTMLElement} parent Popup's parent element
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Open Popup
|
|
106
|
+
*
|
|
107
|
+
* @param {PopupOpenOptions}
|
|
108
|
+
*/
|
|
109
|
+
static open({
|
|
110
|
+
template,
|
|
111
|
+
top,
|
|
112
|
+
left,
|
|
113
|
+
right,
|
|
114
|
+
bottom,
|
|
115
|
+
parent
|
|
116
|
+
}: {
|
|
117
|
+
template: unknown
|
|
118
|
+
top?: number
|
|
119
|
+
left?: number
|
|
120
|
+
right?: number
|
|
121
|
+
bottom?: number
|
|
122
|
+
parent?: Element | null
|
|
123
|
+
}) {
|
|
124
|
+
const owner = parent || document.body
|
|
125
|
+
const target = document.createElement('ox-layout') as OxLayout
|
|
126
|
+
|
|
127
|
+
render(template, target)
|
|
128
|
+
|
|
129
|
+
target._parent = owner
|
|
130
|
+
owner.appendChild(target)
|
|
131
|
+
|
|
132
|
+
target.open({ top, left, right, bottom })
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
open({
|
|
136
|
+
left,
|
|
137
|
+
top,
|
|
138
|
+
right,
|
|
139
|
+
bottom,
|
|
140
|
+
silent = false
|
|
141
|
+
}: {
|
|
142
|
+
left?: number
|
|
143
|
+
top?: number
|
|
144
|
+
right?: number
|
|
145
|
+
bottom?: number
|
|
146
|
+
silent?: boolean
|
|
147
|
+
}) {
|
|
148
|
+
if (left !== undefined) this.style.left = `${left}px`
|
|
149
|
+
if (top !== undefined) this.style.top = `${top}px`
|
|
150
|
+
if (right !== undefined) this.style.right = `${right}px`
|
|
151
|
+
if (bottom !== undefined) this.style.bottom = `${bottom}px`
|
|
152
|
+
|
|
153
|
+
this.setAttribute('active', '')
|
|
154
|
+
|
|
155
|
+
!silent && this.guaranteeFocus()
|
|
156
|
+
|
|
157
|
+
/* When the window is out of focus, all pop-ups should disappear. */
|
|
158
|
+
window.addEventListener('blur', this._onwindowblur)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
guaranteeFocus() {
|
|
162
|
+
const focusible = this.querySelector(
|
|
163
|
+
':scope > button, :scope > [href], :scope > input, :scope > select, :scope > textarea, :scope > [tabindex]:not([tabindex="-1"])'
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
if (focusible) {
|
|
167
|
+
;(focusible as HTMLElement).focus()
|
|
168
|
+
} else {
|
|
169
|
+
this.focus()
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
close() {
|
|
174
|
+
this.removeAttribute('active')
|
|
175
|
+
|
|
176
|
+
window.removeEventListener('blur', this._onwindowblur)
|
|
177
|
+
|
|
178
|
+
if (this._parent) {
|
|
179
|
+
/* this case is when the layout is opened by OxLayout.open(...) */
|
|
180
|
+
this.removeEventListener('focusout', this._onfocusout)
|
|
181
|
+
this.removeEventListener('keydown', this._onkeydown)
|
|
182
|
+
this.removeEventListener('keyup', this._onkeyup)
|
|
183
|
+
this.removeEventListener('click', this._onclick)
|
|
184
|
+
this.removeEventListener('ox-close', this._onclose)
|
|
185
|
+
this.removeEventListener('ox-collapse', this._oncollapse)
|
|
186
|
+
|
|
187
|
+
this._parent.removeChild(this)
|
|
188
|
+
delete this._parent
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { css } from 'lit-element'
|
|
6
|
+
|
|
7
|
+
export const style = css`
|
|
8
|
+
:host {
|
|
9
|
+
background-color: var(--edit-toolbar-background-color, #394e64);
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
[tools] {
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
overflow: none;
|
|
17
|
+
padding: 0px 10px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
[tools] > * {
|
|
21
|
+
padding: 0px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
[tools] > span[button] {
|
|
25
|
+
min-width: 30px;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
[tools] > span[padding] {
|
|
29
|
+
flex: 1;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
[tools] > .vline {
|
|
33
|
+
display: block;
|
|
34
|
+
flex: none;
|
|
35
|
+
border-left: 1px solid rgba(255, 255, 255, 0.2);
|
|
36
|
+
border-right: 1px solid rgba(0, 0, 0, 0.15);
|
|
37
|
+
width: 0px;
|
|
38
|
+
height: 18px;
|
|
39
|
+
margin: 0 3px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
span[button] {
|
|
43
|
+
min-height: 35px;
|
|
44
|
+
|
|
45
|
+
background: url('/assets/images/icon-htoolbar.png') no-repeat;
|
|
46
|
+
background-position-x: 50%;
|
|
47
|
+
opacity: 0.8;
|
|
48
|
+
}
|
|
49
|
+
span[button]:hover {
|
|
50
|
+
opacity: 1;
|
|
51
|
+
background-color: rgba(0, 0, 0, 0.1);
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#fullscreen,
|
|
56
|
+
#toggle-property {
|
|
57
|
+
flex: none;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#align-left {
|
|
61
|
+
background-position-y: 8px;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#align-center {
|
|
65
|
+
background-position-y: -42px;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#align-right {
|
|
69
|
+
background-position-y: -92px;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#align-top {
|
|
73
|
+
background-position-y: -142px;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#align-middle {
|
|
77
|
+
background-position-y: -192px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#align-bottom {
|
|
81
|
+
background-position-y: -242px;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
#undo {
|
|
85
|
+
background-position-y: -592px;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#redo {
|
|
89
|
+
background-position-y: -642px;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#front {
|
|
93
|
+
background-position-y: -292px;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#back {
|
|
97
|
+
background-position-y: -342px;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#forward {
|
|
101
|
+
background-position-y: -392px;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
#backward {
|
|
105
|
+
background-position-y: -442px;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
#symmetry-x {
|
|
109
|
+
background-position-y: -492px;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#symmetry-y {
|
|
113
|
+
background-position-y: -542px;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#group {
|
|
117
|
+
background-position-y: -492px;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#ungroup {
|
|
121
|
+
background-position-y: -542px;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#fullscreen {
|
|
125
|
+
background-position-y: -692px;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
#toggle-property {
|
|
129
|
+
background-position-y: -692px;
|
|
130
|
+
float: right;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
#zoomin {
|
|
134
|
+
background-position-y: -742px;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
#zoomout {
|
|
138
|
+
background-position-y: -792px;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#fit-scene {
|
|
142
|
+
background-position-y: -1492px;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
#cut {
|
|
146
|
+
background-position-y: -842px;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
#copy {
|
|
150
|
+
background-position-y: -892px;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
#paste {
|
|
154
|
+
background-position-y: -942px;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
#delete {
|
|
158
|
+
background-position-y: -992px;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
#font-increase {
|
|
162
|
+
background-position-y: -1042px;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
#font-decrease {
|
|
166
|
+
background-position-y: -1092px;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
#style-copy {
|
|
170
|
+
background-position-y: -1142px;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
#context-menu {
|
|
174
|
+
background-position-y: -692px;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
#symmetry-x {
|
|
178
|
+
background-position-y: -1192px;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
#symmetry-y {
|
|
182
|
+
background-position-y: -1242px;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
#rotate-cw {
|
|
186
|
+
background-position-y: -1292px;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
#rotate-ccw {
|
|
190
|
+
background-position-y: -1342px;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
#distribute-horizontal {
|
|
194
|
+
background-position-y: -1542px;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
#distribute-vertical {
|
|
198
|
+
background-position-y: -1593px;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
#toggle-property {
|
|
202
|
+
background-position-y: -1392px;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
#preview {
|
|
206
|
+
background-position-y: -1640px;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/* bigger buttons */
|
|
210
|
+
#fullscreen {
|
|
211
|
+
background: url('/assets/images/icon-fullscreen.png') 50% 10px no-repeat;
|
|
212
|
+
width: var(--edit-toolbar-bigger-icon-size);
|
|
213
|
+
height: var(--edit-toolbar-bigger-icon-size);
|
|
214
|
+
border-left: var(--edit-toolbar-bigger-icon-line);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
#toggle-property {
|
|
218
|
+
background: url('/assets/images/icon-collapse.png') 80% 10px no-repeat;
|
|
219
|
+
width: var(--edit-toolbar-bigger-icon-size);
|
|
220
|
+
height: var(--edit-toolbar-bigger-icon-size);
|
|
221
|
+
border-left: var(--edit-toolbar-bigger-icon-line);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
#toggle-property[active] {
|
|
225
|
+
background: url(/assets/images/icon-collapse-active.png) 80% 10px no-repeat;
|
|
226
|
+
}
|
|
227
|
+
`
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { css, html, LitElement } from 'lit'
|
|
6
|
+
import { customElement } from 'lit/decorators.js'
|
|
7
|
+
|
|
8
|
+
const _isMacOS = navigator.userAgent.indexOf('Mac') != -1
|
|
9
|
+
|
|
10
|
+
@customElement('ox-toolbar')
|
|
11
|
+
class OxToolbar extends LitElement {
|
|
12
|
+
static styles = [css`
|
|
13
|
+
:host {
|
|
14
|
+
background-color: var(--edit-toolbar-background-color, #394e64);
|
|
15
|
+
overflow: hidden;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
[tools] {
|
|
19
|
+
display: flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
overflow: none;
|
|
22
|
+
padding: 0px 10px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
[tools] > * {
|
|
26
|
+
padding: 0px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
[tools] > span[button] {
|
|
30
|
+
min-width: 30px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
[tools] > span[padding] {
|
|
34
|
+
flex: 1;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
[tools] > .vline {
|
|
38
|
+
display: block;
|
|
39
|
+
flex: none;
|
|
40
|
+
border-left: 1px solid rgba(255, 255, 255, 0.2);
|
|
41
|
+
border-right: 1px solid rgba(0, 0, 0, 0.15);
|
|
42
|
+
width: 0px;
|
|
43
|
+
height: 18px;
|
|
44
|
+
margin: 0 3px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
span[button] {
|
|
48
|
+
min-height: 35px;
|
|
49
|
+
|
|
50
|
+
background: url('/assets/images/icon-htoolbar.png') no-repeat;
|
|
51
|
+
background-position-x: 50%;
|
|
52
|
+
opacity: 0.8;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
span[button]:hover {
|
|
56
|
+
opacity: 1;
|
|
57
|
+
background-color: rgba(0, 0, 0, 0.1);
|
|
58
|
+
cursor: pointer;
|
|
59
|
+
}
|
|
60
|
+
`]
|
|
61
|
+
|
|
62
|
+
render() {
|
|
63
|
+
return html`
|
|
64
|
+
<slot></slot>
|
|
65
|
+
`
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
firstUpdated() {
|
|
69
|
+
this.addEventListener('mousewheel', this.onWheelEvent.bind(this), false)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
onWheelEvent(e: Event) {
|
|
73
|
+
var delta = Math.max(-1, Math.min(1, (e as WheelEvent).deltaY || -(e as WheelEvent).detail))
|
|
74
|
+
this.scrollLeft -= delta * 40
|
|
75
|
+
|
|
76
|
+
e.preventDefault()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getSymbol(key: string) {
|
|
80
|
+
var symbol
|
|
81
|
+
switch (key) {
|
|
82
|
+
case 'cmd':
|
|
83
|
+
case 'ctrl':
|
|
84
|
+
symbol = _isMacOS ? '⌘' : 'Ctrl'
|
|
85
|
+
break
|
|
86
|
+
case 'shift':
|
|
87
|
+
symbol = _isMacOS ? '⇧' : 'Shift'
|
|
88
|
+
break
|
|
89
|
+
case 'alt':
|
|
90
|
+
case 'option':
|
|
91
|
+
symbol = _isMacOS ? '⌥' : 'Alt'
|
|
92
|
+
break
|
|
93
|
+
case 'backspace':
|
|
94
|
+
symbol = _isMacOS ? '⌫' : 'BackSpace'
|
|
95
|
+
break
|
|
96
|
+
case 'delete':
|
|
97
|
+
symbol = _isMacOS ? '⌦' : 'Del'
|
|
98
|
+
break
|
|
99
|
+
default:
|
|
100
|
+
symbol = key.toUpperCase()
|
|
101
|
+
break
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return symbol
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
getShortcutString() {
|
|
108
|
+
var symbols = []
|
|
109
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
110
|
+
symbols.push(this.getSymbol(arguments[i]))
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return symbols.join(_isMacOS ? '' : '+')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
onShortcut(e: KeyboardEvent) {
|
|
117
|
+
var ctrlKey = _isMacOS ? e.metaKey : e.ctrlKey
|
|
118
|
+
var altKey = e.altKey
|
|
119
|
+
var shiftKey = e.shiftKey
|
|
120
|
+
|
|
121
|
+
var defaultPrevent = ctrlKey || altKey
|
|
122
|
+
|
|
123
|
+
switch (e.code) {
|
|
124
|
+
|
|
125
|
+
default:
|
|
126
|
+
return false
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (defaultPrevent) e.preventDefault()
|
|
130
|
+
return true
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
customElements.define('process-edit-toolbar', OxToolbar)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import '../src/ox-layout';
|
|
2
|
+
|
|
3
|
+
import { html, TemplateResult } from 'lit';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'ContextMenu',
|
|
7
|
+
component: 'ox-layout',
|
|
8
|
+
argTypes: {
|
|
9
|
+
title: { control: 'text' },
|
|
10
|
+
counter: { control: 'number' },
|
|
11
|
+
textColor: { control: 'color' }
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface Story<T> {
|
|
16
|
+
(args: T): TemplateResult
|
|
17
|
+
args?: Partial<T>
|
|
18
|
+
argTypes?: Record<string, unknown>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface ArgTypes {
|
|
22
|
+
title?: string
|
|
23
|
+
counter?: number
|
|
24
|
+
textColor?: string
|
|
25
|
+
slot?: TemplateResult
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const Template: Story<ArgTypes> = ({ title = 'Hello world', counter = 5, textColor, slot }: ArgTypes) => html`
|
|
29
|
+
<ox-layout style="--ox-layout-text-color: ${textColor || 'black'}" .title=${title} .counter=${counter}>
|
|
30
|
+
${slot}
|
|
31
|
+
</ox-layout>
|
|
32
|
+
`
|
|
33
|
+
|
|
34
|
+
export const Regular = Template.bind({})
|
|
35
|
+
|
|
36
|
+
export const CustomTitle = Template.bind({})
|
|
37
|
+
CustomTitle.args = {
|
|
38
|
+
title: 'My title'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const CustomCounter = Template.bind({})
|
|
42
|
+
CustomCounter.args = {
|
|
43
|
+
counter: 123456
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const SlottedContent = Template.bind({})
|
|
47
|
+
SlottedContent.args = {
|
|
48
|
+
slot: html`<p>Slotted content</p>`
|
|
49
|
+
}
|
|
50
|
+
SlottedContent.argTypes = {
|
|
51
|
+
slot: { table: { disable: true } }
|
|
52
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import '../src/ox-layout';
|
|
2
|
+
|
|
3
|
+
import { html } from 'lit';
|
|
4
|
+
|
|
5
|
+
import { expect, fixture } from '@open-wc/testing';
|
|
6
|
+
|
|
7
|
+
import { OxLayout } from '../src/ox-layout';
|
|
8
|
+
|
|
9
|
+
describe('Layout', () => {
|
|
10
|
+
it('has a default title "Hey there" and counter 5', async () => {
|
|
11
|
+
const el = await fixture<OxLayout>(html`<ox-layout></ox-layout>`)
|
|
12
|
+
|
|
13
|
+
expect(el.title).to.equal('Hey there')
|
|
14
|
+
// expect(el.counter).to.equal(5)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('increases the counter on button click', async () => {
|
|
18
|
+
const el = await fixture<OxLayout>(html`<ox-layout></ox-layout>`)
|
|
19
|
+
el.shadowRoot!.querySelector('button')!.click()
|
|
20
|
+
|
|
21
|
+
// expect(el.counter).to.equal(6)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('can override the title via attribute', async () => {
|
|
25
|
+
const el = await fixture<OxLayout>(html`<ox-layout title="attribute title"></ox-layout>`)
|
|
26
|
+
|
|
27
|
+
expect(el.title).to.equal('attribute title')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('passes the a11y audit', async () => {
|
|
31
|
+
const el = await fixture<OxLayout>(html`<ox-layout></ox-layout>`)
|
|
32
|
+
|
|
33
|
+
await expect(el).shadowDom.to.be.accessible()
|
|
34
|
+
})
|
|
35
|
+
})
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2018",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"noEmitOnError": true,
|
|
7
|
+
"lib": ["es2017", "dom"],
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": false,
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
"experimentalDecorators": true,
|
|
12
|
+
"importHelpers": true,
|
|
13
|
+
"outDir": "dist",
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"inlineSources": true,
|
|
16
|
+
"rootDir": "./",
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"incremental": true,
|
|
19
|
+
"types": ["node", "mocha"]
|
|
20
|
+
},
|
|
21
|
+
"include": ["**/*.ts"]
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
|
|
2
|
+
|
|
3
|
+
/** Use Hot Module replacement by adding --hmr to the start command */
|
|
4
|
+
const hmr = process.argv.includes('--hmr');
|
|
5
|
+
|
|
6
|
+
export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
|
|
7
|
+
open: '/demo/',
|
|
8
|
+
/** Use regular watch mode if HMR is not enabled. */
|
|
9
|
+
watch: !hmr,
|
|
10
|
+
/** Resolve bare module imports */
|
|
11
|
+
nodeResolve: {
|
|
12
|
+
exportConditions: ['browser', 'development'],
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
/** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
|
|
16
|
+
// esbuildTarget: 'auto'
|
|
17
|
+
|
|
18
|
+
/** Set appIndex to enable SPA routing */
|
|
19
|
+
// appIndex: 'demo/index.html',
|
|
20
|
+
|
|
21
|
+
plugins: [
|
|
22
|
+
/** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */
|
|
23
|
+
// hmr && hmrPlugin({ exclude: ['**/*/node_modules/**/*'], presets: [presets.litElement] }),
|
|
24
|
+
],
|
|
25
|
+
|
|
26
|
+
// See documentation for all available options
|
|
27
|
+
});
|