@things-factory/lite-menu 8.0.0-beta.9 → 8.0.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.
@@ -0,0 +1,146 @@
1
+ import '@material/web/icon/icon.js'
2
+ import '@operato/menu/ox-menu-part.js'
3
+
4
+ import gql from 'graphql-tag'
5
+ import { html } from 'lit'
6
+
7
+ import { store, InheritedValueType, clientSettingStore } from '@operato/shell'
8
+ import { client } from '@operato/graphql'
9
+ import { appendViewpart, toggleOverlay, TOOL_POSITION, VIEWPART_POSITION } from '@operato/layout'
10
+ import { isMobileDevice } from '@operato/utils'
11
+
12
+ import { APPEND_APP_TOOL, REMOVE_APP_TOOL } from '@things-factory/apptool-base/client'
13
+
14
+ export const UPDATE_ADDON_MENUS = 'UPDATE_ADDON_MENUS'
15
+ export const UPDATE_MENU_TEMPLATE = 'UPDATE_MENU_TEMPLATE'
16
+
17
+ var HAMBURGER
18
+
19
+ export async function setupMenuPart(options) {
20
+ var {
21
+ hovering = isMobileDevice() ? true : false,
22
+ slotTemplate,
23
+ portraitSlotTemplate,
24
+ landscapeSlotTemplate,
25
+ position = VIEWPART_POSITION.NAVBAR
26
+ } = options || {}
27
+
28
+ const { hovering: hoveringSetting } = (await clientSettingStore.get('lite-menu'))?.value || {}
29
+ if (hoveringSetting !== undefined) {
30
+ hovering = hoveringSetting
31
+ }
32
+
33
+ const orientation = position == VIEWPART_POSITION.HEADERBAR ? 'landscape' : 'portrait'
34
+ const orientatedSlotTemplate =
35
+ (orientation == 'landscape' ? landscapeSlotTemplate : portraitSlotTemplate) || slotTemplate || html``
36
+
37
+ appendViewpart({
38
+ name: 'ox-menu-part',
39
+ viewpart: {
40
+ show: !hovering,
41
+ resizable: true,
42
+ hovering: isMobileDevice() ? true : hovering,
43
+ template: html` <ox-menu-part .orientation=${orientation}>${orientatedSlotTemplate}</ox-menu-part> `
44
+ },
45
+ position
46
+ })
47
+
48
+ // hovering이 true거나 모바일 일때는 계속 햄버거 버튼 표시
49
+ if ((hovering || isMobileDevice()) && orientation == 'portrait') {
50
+ if (!HAMBURGER) {
51
+ HAMBURGER = {
52
+ name: 'hamburger',
53
+ template: html`
54
+ <md-icon
55
+ @click=${e =>
56
+ toggleOverlay('ox-menu-part', {
57
+ backdrop: true
58
+ })}
59
+ >view_headline</md-icon
60
+ >
61
+ `,
62
+ position: TOOL_POSITION.FRONT_END
63
+ }
64
+
65
+ store.dispatch({
66
+ /* incase of mobile : add hamburger tool */
67
+ type: APPEND_APP_TOOL,
68
+ tool: HAMBURGER
69
+ })
70
+ }
71
+ } else {
72
+ if (HAMBURGER) {
73
+ store.dispatch({
74
+ type: REMOVE_APP_TOOL,
75
+ name: 'hamburger'
76
+ })
77
+
78
+ HAMBURGER = null
79
+ }
80
+ }
81
+ }
82
+
83
+ export async function updateMenuTemplate(template) {
84
+ await fetchAddonMenus()
85
+
86
+ store.dispatch({
87
+ type: UPDATE_MENU_TEMPLATE,
88
+ template
89
+ })
90
+ }
91
+
92
+ export async function fetchAddonMenus() {
93
+ var applicationName = (document.querySelector('meta[name="application-name"]') as HTMLMetaElement)?.content
94
+
95
+ var liteMenus = (
96
+ await client.query({
97
+ query: gql`
98
+ query ($filters: [Filter!], $inherited: InheritedValueType) {
99
+ liteMenus: myLiteMenus(filters: $filters, inherited: $inherited) {
100
+ items {
101
+ id
102
+ name
103
+ label
104
+ description
105
+ appName
106
+ parent
107
+ rank
108
+ active
109
+ type
110
+ value
111
+ icon
112
+ help
113
+ }
114
+ total
115
+ }
116
+ }
117
+ `,
118
+ variables: {
119
+ filters: [
120
+ {
121
+ name: 'active',
122
+ operator: 'eq',
123
+ value: true
124
+ },
125
+ {
126
+ name: 'appName',
127
+ operator: 'in',
128
+ value: ['', applicationName]
129
+ }
130
+ ],
131
+ sortings: [
132
+ {
133
+ name: 'rank',
134
+ desc: false
135
+ }
136
+ ],
137
+ inherited: InheritedValueType.Include
138
+ }
139
+ })
140
+ ).data.liteMenus.items
141
+
142
+ store.dispatch({
143
+ type: UPDATE_ADDON_MENUS,
144
+ addon: liteMenus.filter(menu => !menu.appName || menu.appName === applicationName)
145
+ })
146
+ }
@@ -0,0 +1,16 @@
1
+ import '@material/web/icon/icon.js'
2
+ import '@operato/i18n/ox-i18n.js'
3
+ import './route'
4
+
5
+ import { store } from '@operato/shell'
6
+
7
+ import { registerEditor as registerGristEditor } from '@operato/data-grist'
8
+ import { OxGristEditorI18nLabel } from '@operato/grist-editor/ox-grist-editor-i18n-label.js'
9
+
10
+ import liteMenu from './reducers/lite-menu'
11
+
12
+ export default function bootstrap() {
13
+ registerGristEditor('i18n-label', OxGristEditorI18nLabel)
14
+
15
+ store.addReducers({ liteMenu })
16
+ }
@@ -0,0 +1,2 @@
1
+ export * from './actions/lite-menu'
2
+ export * from './lite-menu-setting-let'
@@ -0,0 +1,86 @@
1
+ import '@operato/i18n/ox-i18n.js'
2
+ import '@material/web/checkbox/checkbox.js'
3
+
4
+ import { css, html, LitElement } from 'lit'
5
+ import { customElement, query, property, state } from 'lit/decorators.js'
6
+
7
+ import { clientSettingStore } from '@operato/shell'
8
+ import { i18next, localize } from '@operato/i18n'
9
+
10
+ import { setupMenuPart } from './actions/lite-menu'
11
+
12
+ @customElement('lite-menu-setting-let')
13
+ export class LiteMenuSettingLet extends localize(i18next)(LitElement) {
14
+ static styles = [
15
+ css`
16
+ label {
17
+ display: flex;
18
+ gap: 10px;
19
+ align-items: center;
20
+
21
+ font: var(--label-font);
22
+ color: var(--md-sys-color-on-primary-container);
23
+ text-transform: var(--label-text-transform);
24
+ }
25
+ `
26
+ ]
27
+
28
+ @property({ type: Boolean }) hovering?: boolean
29
+
30
+ render() {
31
+ const checked = this.hovering === true
32
+ const indeterminate = this.hovering === undefined
33
+
34
+ return html`
35
+ <setting-let>
36
+ <ox-i18n slot="title" msgid="title.lite-menu-setting"></ox-i18n>
37
+
38
+ <div slot="content">
39
+ <label>
40
+ <md-checkbox
41
+ id="hovering"
42
+ @change=${e => this.onChange(e)}
43
+ ?checked=${checked}
44
+ ?indeterminate=${indeterminate}
45
+ ></md-checkbox>
46
+ hovering
47
+ </label>
48
+ </div>
49
+ </setting-let>
50
+ `
51
+ }
52
+
53
+ async firstUpdated() {
54
+ this.hovering = ((await clientSettingStore.get('lite-menu'))?.value || {}).hovering
55
+ }
56
+
57
+ async onChange(e: Event) {
58
+ if (this.hovering === true) {
59
+ this.hovering = false
60
+ } else if (this.hovering === false) {
61
+ this.hovering = undefined
62
+ } else {
63
+ this.hovering = true
64
+ }
65
+
66
+ const { hovering: valueFromStore } = (await clientSettingStore.get('lite-menu'))?.value || {}
67
+ if (this.hovering === valueFromStore) {
68
+ return
69
+ }
70
+
71
+ try {
72
+ await clientSettingStore.put({
73
+ key: 'lite-menu',
74
+ value: {
75
+ hovering: this.hovering
76
+ }
77
+ })
78
+ } catch (e) {
79
+ console.error(e)
80
+ }
81
+
82
+ setupMenuPart({
83
+ hovering: this.hovering
84
+ })
85
+ }
86
+ }