@things-factory/context-ui 4.1.27 → 5.0.0-alpha.2
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/client/bootstrap.js +7 -7
- package/client/layouts/context-toolbar.js +3 -4
- package/client/styles/context-toolbar-overlay-style.js +1 -1
- package/client/themes/context-theme.css +9 -0
- package/client/tools/page-action-context-bar.js +75 -15
- package/client/tools/page-action-overlay-template.js +115 -0
- package/client/tools/title-bar.js +1 -1
- package/package.json +6 -6
package/client/bootstrap.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import './tools/title-bar'
|
|
2
|
+
import './tools/page-action-context-bar'
|
|
3
|
+
import './layouts/context-toolbar'
|
|
4
|
+
|
|
1
5
|
import { html } from 'lit-html'
|
|
2
6
|
|
|
3
|
-
import { store } from '@things-factory/shell'
|
|
4
|
-
import { appendViewpart, VIEWPART_POSITION, TOOL_POSITION } from '@things-factory/layout-base'
|
|
5
7
|
import { APPEND_APP_TOOL } from '@things-factory/apptool-base'
|
|
6
8
|
import { APPEND_CONTEXT_TOOL } from '@things-factory/context-base'
|
|
7
|
-
|
|
8
|
-
import '
|
|
9
|
-
import './tools/page-action-context-bar'
|
|
10
|
-
import './layouts/context-toolbar'
|
|
9
|
+
import { appendViewpart, TOOL_POSITION, VIEWPART_POSITION } from '@things-factory/layout-base'
|
|
10
|
+
import { store } from '@things-factory/shell'
|
|
11
11
|
|
|
12
12
|
export default function bootstrap() {
|
|
13
13
|
/* add title app-tool */
|
|
@@ -49,7 +49,7 @@ export default function bootstrap() {
|
|
|
49
49
|
type: APPEND_CONTEXT_TOOL,
|
|
50
50
|
tool: {
|
|
51
51
|
template: html` <page-action-context-bar></page-action-context-bar> `,
|
|
52
|
-
position: TOOL_POSITION.
|
|
52
|
+
position: TOOL_POSITION.CENTER,
|
|
53
53
|
context: 'actions'
|
|
54
54
|
}
|
|
55
55
|
})
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import '@material/mwc-icon'
|
|
2
2
|
|
|
3
|
-
import { LitElement, css, html } from 'lit
|
|
3
|
+
import { LitElement, css, html } from 'lit'
|
|
4
|
+
import { connect } from 'pwa-helpers/connect-mixin.js'
|
|
4
5
|
|
|
5
6
|
import { TOOL_POSITION } from '@things-factory/layout-base'
|
|
6
|
-
import { connect } from 'pwa-helpers/connect-mixin.js'
|
|
7
7
|
import { store } from '@things-factory/shell'
|
|
8
8
|
|
|
9
9
|
class ContextToolbar extends connect(store)(LitElement) {
|
|
@@ -65,12 +65,11 @@ class ContextToolbar extends connect(store)(LitElement) {
|
|
|
65
65
|
|
|
66
66
|
#center {
|
|
67
67
|
flex: 1;
|
|
68
|
-
justify-content: center;
|
|
69
68
|
align-items: center;
|
|
69
|
+
justify-content: end;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
#center > * {
|
|
73
|
-
justify-content: center;
|
|
74
73
|
align-items: center;
|
|
75
74
|
}
|
|
76
75
|
#rear-end > *,
|
|
@@ -41,6 +41,12 @@ body {
|
|
|
41
41
|
--context-ui-button-background-color: #fff;
|
|
42
42
|
--context-ui-button-background-hover-color: var(--primary-color);
|
|
43
43
|
|
|
44
|
+
--context-action-bar-button-margin: 5px 0 5px var(--margin-narrow);
|
|
45
|
+
--context-action-bar-more-button-background-color:var(--context-ui-background-color);
|
|
46
|
+
--context-action-bar-more-button-padding:6px var(--padding-default);
|
|
47
|
+
--context-action-bar-more-button-color:var(--theme-white-color);
|
|
48
|
+
--context-action-bar-more-button-border-radius:4px;
|
|
49
|
+
|
|
44
50
|
/* button style */
|
|
45
51
|
--button-background-color: var(--secondary-color);
|
|
46
52
|
--button-active-background-color: var(--primary-color);
|
|
@@ -71,5 +77,8 @@ body {
|
|
|
71
77
|
--context-toolbar-side-padding: 0;
|
|
72
78
|
--context-toolbar-shadow-line: inset 0px 2px 2px 0px rgba(0, 0, 0, 0.1);
|
|
73
79
|
--context-toolbar-button-padding: 0 10px 0 0;
|
|
80
|
+
|
|
81
|
+
--context-action-bar-button-margin: 0 0 0 -1px;
|
|
82
|
+
--context-action-bar-more-button-border-radius:0;
|
|
74
83
|
}
|
|
75
84
|
}
|
|
@@ -1,43 +1,60 @@
|
|
|
1
1
|
import '@material/mwc-button'
|
|
2
|
+
import '@material/mwc-icon'
|
|
3
|
+
import './page-action-overlay-template'
|
|
2
4
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
+
import { css, html, LitElement } from 'lit'
|
|
6
|
+
import throttle from 'lodash-es/throttle'
|
|
5
7
|
import { connect } from 'pwa-helpers/connect-mixin'
|
|
6
|
-
|
|
7
|
-
import { store } from '@
|
|
8
|
+
|
|
9
|
+
import { store } from '@operato/shell'
|
|
10
|
+
import { sleep } from '@operato/utils'
|
|
11
|
+
import { openOverlay } from '@things-factory/layout-base'
|
|
8
12
|
|
|
9
13
|
class PageActionContextBar extends connect(store)(LitElement) {
|
|
10
14
|
static get properties() {
|
|
11
15
|
return {
|
|
12
|
-
_actions: Array
|
|
16
|
+
_actions: Array,
|
|
17
|
+
_overflown: Boolean
|
|
13
18
|
}
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
static get styles() {
|
|
17
22
|
return [
|
|
18
23
|
css`
|
|
24
|
+
:host {
|
|
25
|
+
display: flex;
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
position: relative;
|
|
28
|
+
}
|
|
29
|
+
|
|
19
30
|
:host *:focus {
|
|
20
31
|
outline: none;
|
|
21
32
|
}
|
|
33
|
+
|
|
22
34
|
mwc-button {
|
|
23
|
-
|
|
35
|
+
white-space: nowrap;
|
|
36
|
+
margin: var(--context-action-bar-button-margin);
|
|
37
|
+
border-radius: var(--context-action-bar-more-button-border-radius);
|
|
24
38
|
}
|
|
39
|
+
|
|
25
40
|
[danger] {
|
|
26
41
|
--mdc-theme-primary: var(--mdc-danger-button-primary-color);
|
|
27
42
|
--mdc-button-outline-color: var(--mdc-danger-button-outline-color);
|
|
28
43
|
}
|
|
44
|
+
|
|
45
|
+
[more] {
|
|
46
|
+
position: absolute;
|
|
47
|
+
right: 0;
|
|
48
|
+
background-color: var(--context-action-bar-more-button-background-color);
|
|
49
|
+
box-shadow: -2px 0px 2px 1px rgba(0, 0, 0, 0.2);
|
|
50
|
+
padding: var(--context-action-bar-more-button-padding);
|
|
51
|
+
color: var(--context-action-bar-more-button-color);
|
|
52
|
+
}
|
|
53
|
+
|
|
29
54
|
@media screen and (max-width: 460px) {
|
|
30
|
-
:host {
|
|
31
|
-
border: 1px solid var(--primary-color);
|
|
32
|
-
border-width: 0 1px;
|
|
33
|
-
}
|
|
34
55
|
mwc-button {
|
|
35
|
-
margin-left: -5px;
|
|
36
|
-
overflow: hidden;
|
|
37
|
-
max-width: 80px;
|
|
38
|
-
--mdc-shape-small: 0;
|
|
39
|
-
--mdc-typography-button-font-size: 0.6em;
|
|
40
56
|
--mdc-button-horizontal-padding: var(--padding-default);
|
|
57
|
+
--mdc-shape-small: var(--context-action-bar-more-button-border-radius);
|
|
41
58
|
}
|
|
42
59
|
}
|
|
43
60
|
|
|
@@ -53,7 +70,38 @@ class PageActionContextBar extends connect(store)(LitElement) {
|
|
|
53
70
|
]
|
|
54
71
|
}
|
|
55
72
|
|
|
73
|
+
get overflownUpdater() {
|
|
74
|
+
if (!this._overflownUpdater) {
|
|
75
|
+
this._overflownUpdater = throttle(() => {
|
|
76
|
+
this._overflown = this.scrollWidth > this.clientWidth
|
|
77
|
+
}, 100)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return this._overflownUpdater
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
connectedCallback() {
|
|
84
|
+
super.connectedCallback()
|
|
85
|
+
|
|
86
|
+
this._resizeCallback = () => this.overflownUpdater()
|
|
87
|
+
|
|
88
|
+
window.addEventListener('resize', this._resizeCallback)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
disconnectedCallback() {
|
|
92
|
+
super.disconnectedCallback()
|
|
93
|
+
|
|
94
|
+
window.removeEventListener('resize', this._resizeCallback)
|
|
95
|
+
}
|
|
96
|
+
|
|
56
97
|
render() {
|
|
98
|
+
return html`
|
|
99
|
+
${this.renderActions()}
|
|
100
|
+
${this._overflown ? html` <mwc-icon more @click=${this.showMore.bind(this)}>more_horiz</mwc-icon> ` : html``}
|
|
101
|
+
`
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
renderActions() {
|
|
57
105
|
return html`
|
|
58
106
|
${this._actions.map(($action, idx) => {
|
|
59
107
|
let { type, title, icon, action, select, href, emphasis } = $action
|
|
@@ -100,9 +148,21 @@ class PageActionContextBar extends connect(store)(LitElement) {
|
|
|
100
148
|
`
|
|
101
149
|
}
|
|
102
150
|
|
|
151
|
+
updated(changed) {
|
|
152
|
+
if (changed.has('_actions')) {
|
|
153
|
+
requestAnimationFrame(this.overflownUpdater)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
103
157
|
stateChanged(state) {
|
|
104
158
|
this._actions = state.route?.context?.actions?.filter(action => !!action) || []
|
|
105
159
|
}
|
|
160
|
+
|
|
161
|
+
showMore() {
|
|
162
|
+
openOverlay('context-toolbar-overlay', {
|
|
163
|
+
template: html`<page-action-overlay-template></page-action-overlay-template>`
|
|
164
|
+
})
|
|
165
|
+
}
|
|
106
166
|
}
|
|
107
167
|
|
|
108
168
|
customElements.define('page-action-context-bar', PageActionContextBar)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import '@material/mwc-icon'
|
|
2
|
+
|
|
3
|
+
import { css, html, LitElement } from 'lit-element'
|
|
4
|
+
import { connect } from 'pwa-helpers'
|
|
5
|
+
|
|
6
|
+
import { store } from '@operato/shell'
|
|
7
|
+
import { ScrollbarStyles } from '@operato/styles'
|
|
8
|
+
import { sleep } from '@operato/utils'
|
|
9
|
+
import { ContextToolbarOverlayStyle } from '@things-factory/context-ui'
|
|
10
|
+
|
|
11
|
+
class PageActionOverlayTemplate extends connect(store)(LitElement) {
|
|
12
|
+
static get properties() {
|
|
13
|
+
return {
|
|
14
|
+
_actions: Array
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static get styles() {
|
|
19
|
+
return [
|
|
20
|
+
ScrollbarStyles,
|
|
21
|
+
ContextToolbarOverlayStyle,
|
|
22
|
+
css`
|
|
23
|
+
:host {
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-wrap: wrap;
|
|
26
|
+
gap: var(--margin-narrow);
|
|
27
|
+
}
|
|
28
|
+
:host *:focus {
|
|
29
|
+
outline: none;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
mwc-button {
|
|
33
|
+
background-color: var(--main-section-background-color);
|
|
34
|
+
border-radius: var(--context-action-bar-more-button-border-radius);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
[danger] {
|
|
38
|
+
--mdc-theme-primary: var(--mdc-danger-button-primary-color);
|
|
39
|
+
--mdc-button-outline-color: var(--mdc-danger-button-outline-color);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@media screen and (max-width: 460px) {
|
|
43
|
+
mwc-button {
|
|
44
|
+
--mdc-button-horizontal-padding: var(--padding-default);
|
|
45
|
+
border-radius: 4px;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@keyframes rotate {
|
|
50
|
+
from {
|
|
51
|
+
transform: rotate(0deg);
|
|
52
|
+
}
|
|
53
|
+
to {
|
|
54
|
+
transform: rotate(360deg);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
`
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
render() {
|
|
62
|
+
return html`
|
|
63
|
+
${this._actions.map(($action, idx) => {
|
|
64
|
+
let { type, title, icon, action, select, href, emphasis } = $action
|
|
65
|
+
let { outlined, raised, dense, danger } = emphasis || {}
|
|
66
|
+
|
|
67
|
+
return type == 'text'
|
|
68
|
+
? html` <span>${title}</span> `
|
|
69
|
+
: type == 'select' || (select && select.length > 0)
|
|
70
|
+
? html`
|
|
71
|
+
<select @change=${action}>
|
|
72
|
+
${select.map(option => html` <option>${option}</option> `)}
|
|
73
|
+
</select>
|
|
74
|
+
`
|
|
75
|
+
: type == 'link'
|
|
76
|
+
? html` <a href=${href}>${title}</a> `
|
|
77
|
+
: html`
|
|
78
|
+
<mwc-button
|
|
79
|
+
label=${title}
|
|
80
|
+
icon=${icon || 'done_all'}
|
|
81
|
+
?dense=${dense}
|
|
82
|
+
?raised=${raised}
|
|
83
|
+
?outlined=${outlined}
|
|
84
|
+
?danger=${danger}
|
|
85
|
+
@click=${async e => {
|
|
86
|
+
/* all actions should be bloked for a second */
|
|
87
|
+
const button = e.currentTarget
|
|
88
|
+
button.icon = 'rotate_right'
|
|
89
|
+
button.setAttribute('working', true)
|
|
90
|
+
button.disabled = true
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
await action()
|
|
94
|
+
} finally {
|
|
95
|
+
await sleep(1000)
|
|
96
|
+
button.disabled = false
|
|
97
|
+
/* because icon can be changed after sleep, don't use closure 'icon'. */
|
|
98
|
+
button.icon = this._actions[idx]?.icon || 'done_all'
|
|
99
|
+
button.removeAttribute('working')
|
|
100
|
+
|
|
101
|
+
window.history.back()
|
|
102
|
+
}
|
|
103
|
+
}}
|
|
104
|
+
></mwc-button>
|
|
105
|
+
`
|
|
106
|
+
})}
|
|
107
|
+
`
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
stateChanged(state) {
|
|
111
|
+
this._actions = state.route?.context?.actions?.filter(action => !!action) || []
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
window.customElements.define('page-action-overlay-template', PageActionOverlayTemplate)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/context-ui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-alpha.2",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@material/mwc-icon": "^0.25.3",
|
|
28
|
-
"@operato/help": "^0.3
|
|
29
|
-
"@things-factory/apptool-base": "^
|
|
30
|
-
"@things-factory/context-base": "^
|
|
31
|
-
"@things-factory/layout-ui": "^
|
|
28
|
+
"@operato/help": "^0.4.3",
|
|
29
|
+
"@things-factory/apptool-base": "^5.0.0-alpha.2",
|
|
30
|
+
"@things-factory/context-base": "^5.0.0-alpha.2",
|
|
31
|
+
"@things-factory/layout-ui": "^5.0.0-alpha.2"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "055536f981d229d51ae63f46585036b35fa86602"
|
|
34
34
|
}
|