@operato/shell 8.0.0-alpha.51 → 8.0.0-beta.1

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.
@@ -1,62 +0,0 @@
1
- import { css, html } from 'lit'
2
- import { customElement } from 'lit/decorators.js'
3
-
4
- import { PageView } from './page-view'
5
-
6
- @customElement('page-404')
7
- export class Page404 extends PageView {
8
- static styles = css`
9
- :host {
10
- display: block;
11
- box-sizing: border-box;
12
- background-color: var(--md-sys-color-background);
13
- --spacing-large: 15%;
14
- }
15
-
16
- section {
17
- padding: var(--spacing-large) 0 0 0;
18
- text-align: center;
19
- color: var(--md-sys-color-on-background);
20
- }
21
-
22
- md-icon {
23
- --md-icon-size: 120px;
24
- color: var(--md-sys-color-error);
25
- text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
26
- }
27
-
28
- h2 {
29
- margin: 0 auto;
30
- font-size: 2.5em;
31
- text-transform: capitalize;
32
- color: var(--md-sys-color-primary);
33
- }
34
-
35
- @media only screen and (max-width: 460px) {
36
- md-icon {
37
- padding-top: 25%;
38
- --md-icon-size: 90px;
39
- }
40
-
41
- h2 {
42
- font-size: 2em;
43
- }
44
- }
45
- `
46
-
47
- get context() {
48
- return {
49
- title: 'Page Not Found'
50
- }
51
- }
52
-
53
- render() {
54
- return html`
55
- <section>
56
- <md-icon>error_outline</md-icon>
57
- <h2>page not found!</h2>
58
- The page you requested cannot be found.
59
- </section>
60
- `
61
- }
62
- }
@@ -1,215 +0,0 @@
1
- import { LitElement, PropertyValues } from 'lit'
2
- import { property } from 'lit/decorators.js'
3
- import isEqual from 'lodash-es/isEqual'
4
-
5
- import { UPDATE_CONTEXT } from '../../actions/const'
6
- import { store } from '../../store'
7
-
8
- export type PageLifecycle = {
9
- active: boolean
10
- params: object
11
- resourceId?: string
12
- page?: string
13
- }
14
-
15
- function diff(after: any, before: any): any {
16
- var changed = false
17
- var changes: { [key: string]: any } = {}
18
-
19
- Object.getOwnPropertyNames(after).forEach(function (key) {
20
- let before_val = before[key]
21
- let after_val = after[key]
22
-
23
- if (!isEqual(before_val, after_val)) {
24
- changes[key] = after_val
25
- changed = true
26
- }
27
- })
28
-
29
- return changed && changes
30
- }
31
-
32
- /**
33
- * PageView is a base class for creating page elements with lifecycle management.
34
- * Subclasses can extend PageView to define custom behavior and handle page lifecycle events.
35
- */
36
- export class PageView extends LitElement {
37
- /**
38
- * Determines whether the page can be deactivated. Subclasses can override this method
39
- * to implement custom deactivation logic.
40
- * @returns A Promise that resolves to true if the page can be deactivated, or false otherwise.
41
- */
42
- async canDeactivate(): Promise<boolean> {
43
- return true
44
- }
45
-
46
- /**
47
- * Determines whether the page should update. This method is called whenever there are
48
- * changes to the page's properties.
49
- * @param changes - A map of changed property values.
50
- * @returns True if the page should update, or false otherwise.
51
- */
52
- shouldUpdate(changes: PropertyValues<this>) {
53
- var active = String(this.active) == 'true'
54
- var { active: oldActive = false } = this._oldLifecycleInfo$ || {}
55
-
56
- /*
57
- * page lifecycle
58
- * case 1. page가 새로 activate 되었다.
59
- * case 2. page가 active 상태에서 lifecycle 정보가 바뀌었다.
60
- **/
61
- if (active) {
62
- this.pageUpdate({
63
- active
64
- })
65
- } else if (oldActive) {
66
- this.pageUpdate({
67
- active
68
- })
69
- }
70
-
71
- return active
72
- }
73
-
74
- /**
75
- * Indicates whether the page is currently active.
76
- */
77
- @property({ type: Boolean }) active: boolean = false
78
-
79
- /**
80
- * Stores information about the page's lifecycle.
81
- */
82
- @property({ type: Object }) lifecycle!: PageLifecycle
83
-
84
- /**
85
- * The context path for the page.
86
- */
87
- @property({ type: String, attribute: 'context-path' }) contextPath?: string
88
-
89
- _oldLifecycleInfo$: any
90
-
91
- /* lifecycle */
92
-
93
- /**
94
- * Handles page updates and lifecycle events. Subclasses can override this method
95
- * to implement custom logic for initializing, updating, and disposing of the page.
96
- * @param changes - A map of changed properties.
97
- * @param force - If true, forces an update of the page.
98
- */
99
- async pageUpdate(changes: any = {}, force: boolean = false) {
100
- var before = this._oldLifecycleInfo$ || {}
101
-
102
- var after = {
103
- ...before,
104
- ...this.lifecycle,
105
- contextPath: this.contextPath,
106
- ...changes
107
- }
108
-
109
- if (!('initialized' in changes) && after.active && !before.initialized) {
110
- after.initialized = true
111
- }
112
-
113
- if (force) {
114
- after.updated = Date.now()
115
- }
116
-
117
- var changed = diff(after, before)
118
- if (!changed) {
119
- return
120
- }
121
-
122
- this._oldLifecycleInfo$ = after
123
-
124
- /* page의 이미 초기화된 상태에서 contextPath가 바뀐다면, 무조건 page가 리셋되어야 한다. */
125
- if (before.initialized && changed.contextPath) {
126
- await this.pageReset()
127
- return
128
- }
129
-
130
- if (changed.initialized) {
131
- await this.pageInitialized(after)
132
- }
133
-
134
- if ('initialized' in changed) {
135
- if (changed.initialized) {
136
- /*
137
- * 방금 초기화된 경우라면, 엘리먼트들이 만들어지지 않았을 가능성이 있으므로,
138
- * 다음 animationFrame에서 pageUpdated 콜백을 호출한다.
139
- */
140
- requestAnimationFrame(async () => {
141
- await this.pageUpdated(changed, after, before)
142
- /* active page인 경우에는, page Context 갱신도 필요할 것이다. */
143
- after.active && this.updateContext()
144
- })
145
- } else {
146
- await this.pageDisposed(after)
147
- }
148
- } else {
149
- await this.pageUpdated(changed, after, before)
150
- /* active page인 경우에는, page Context 갱신도 필요할 것이다. */
151
- after.active && this.updateContext()
152
- }
153
- }
154
-
155
- /**
156
- * Resets the page. Subclasses can override this method to perform custom reset logic.
157
- */
158
- async pageReset() {
159
- var { initialized } = this._oldLifecycleInfo$ || {}
160
-
161
- if (initialized) {
162
- await this.pageDispose()
163
- await this.pageUpdate({}, true)
164
- }
165
- }
166
-
167
- /**
168
- * Disposes of the page. Subclasses can override this method to perform custom disposal logic.
169
- */
170
- async pageDispose() {
171
- await this.pageUpdate({
172
- initialized: false
173
- })
174
- }
175
-
176
- /**
177
- * Initializes the page. Subclasses can override this method to perform custom initialization logic.
178
- * @param pageInfo - Information about the page's state.
179
- */
180
- pageInitialized(pageInfo: any) {}
181
-
182
- /**
183
- * Handles page updates and changes in properties.
184
- * Subclasses can override this method to implement custom update logic.
185
- * @param changes - A map of changed properties.
186
- * @param after - The current state of the page.
187
- * @param before - The previous state of the page.
188
- */
189
- pageUpdated(changes: any, after: any, before: any) {}
190
-
191
- /**
192
- * Handles the disposal of the page. Subclasses can override this method
193
- * to implement custom disposal logic.
194
- * @param pageInfo - Information about the page's state.
195
- */
196
- pageDisposed(pageInfo: any) {}
197
-
198
- /* context */
199
- updateContext(override?: any) {
200
- store.dispatch({
201
- type: UPDATE_CONTEXT,
202
- context: override ? { ...this.context, ...override } : this.context
203
- })
204
- }
205
-
206
- /**
207
- * Updates the context of the page. Subclasses can override the `context` getter
208
- * to provide specific context information for the page. The context will be updated
209
- * using the `updateContext` method inherited from PageView.
210
- * @param override - An optional object with context properties to override.
211
- */
212
- get context() {
213
- return {}
214
- }
215
- }
@@ -1,43 +0,0 @@
1
- import { OxPrompt } from '@operato/popup'
2
-
3
- const TYPES_ICON: { [type: string]: string } = {
4
- success: 'verified',
5
- error: 'error',
6
- warning: 'warning',
7
- info: 'info',
8
- question: 'question_mark'
9
- }
10
-
11
- export async function CustomAlert({
12
- type,
13
- icon,
14
- title,
15
- text,
16
- confirmButton,
17
- cancelButton,
18
- callback
19
- }: {
20
- type?: 'info' | 'success' | 'error' | 'warning' | 'question'
21
- icon?: string
22
- title?: string
23
- text?: string
24
- confirmButton?: { color?: string; text: string } | string
25
- cancelButton?: { color?: string; text: string } | string
26
- callback?: (val: { isConfirmed: boolean; isDismissed: boolean; value: boolean }) => any
27
- }) {
28
- const result = await OxPrompt.open({
29
- type: type || 'info',
30
- icon: (icon && TYPES_ICON[icon]) || icon,
31
- title,
32
- text,
33
- confirmButton: typeof confirmButton == 'string' ? { text: confirmButton } : confirmButton,
34
- cancelButton: typeof cancelButton == 'string' ? { text: cancelButton } : cancelButton
35
- })
36
-
37
- const val = { isConfirmed: result, isDismissed: !result, value: result }
38
- if (callback && typeof callback === 'function') {
39
- callback(val)
40
- } else {
41
- return val
42
- }
43
- }
@@ -1,94 +0,0 @@
1
- import '@material/web/icon/icon.js'
2
-
3
- import { css, html, LitElement } from 'lit'
4
- import { customElement } from 'lit/decorators.js'
5
-
6
- @customElement('home-page')
7
- export class HomePage extends LitElement {
8
- static styles = css`
9
- :host {
10
- background-color: var(--md-sys-color-background);
11
-
12
- display: block;
13
- position: relative;
14
- }
15
-
16
- [home] {
17
- position: absolute;
18
- left: 20px;
19
- top: 20px;
20
- font-size: 2em;
21
- color: white;
22
- }
23
-
24
- [message] {
25
- background-color: rgba(50, 66, 97, 0.8);
26
- padding: 60px 50px 0 50px;
27
- color: #fff;
28
- text-align: center;
29
- font-size: 20px;
30
-
31
- strong {
32
- display: block;
33
- font-size: 2.5rem;
34
- }
35
-
36
- img {
37
- width: 450px;
38
- max-width: 90%;
39
- display: block;
40
- margin: auto;
41
- margin-top: 20px;
42
- }
43
- }
44
-
45
- @media screen and (max-width: 460px) {
46
- [message] {
47
- padding: 60px 30px 0 30px;
48
- color: #fff;
49
- text-align: center;
50
- font-size: 15px;
51
- }
52
-
53
- [message] strong {
54
- font-size: 1.6rem;
55
- }
56
- }
57
- `
58
-
59
- _applicationMeta?: {
60
- icon: string
61
- title: string
62
- description: string
63
- }
64
-
65
- render() {
66
- var { title, description } = this.applicationMeta
67
-
68
- return html`
69
- <md-icon home @click=${() => (window.location.href = '/')}>home</md-icon>
70
-
71
- <div message>
72
- <strong>${title}</strong>
73
- ${description}
74
- <img src="/assets/images/home.png" />
75
- </div>
76
- `
77
- }
78
-
79
- get applicationMeta() {
80
- if (!this._applicationMeta) {
81
- var iconLink = document.querySelector('link[rel="application-icon"]') as HTMLLinkElement
82
- var titleMeta = document.querySelector('meta[name="application-name"]') as HTMLMetaElement
83
- var descriptionMeta = document.querySelector('meta[name="application-description"]') as HTMLMetaElement
84
-
85
- this._applicationMeta = {
86
- icon: iconLink?.href,
87
- title: titleMeta ? titleMeta.content : 'Things Factory',
88
- description: descriptionMeta ? descriptionMeta.content : 'Reimagining Software'
89
- }
90
- }
91
-
92
- return this._applicationMeta
93
- }
94
- }
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- export * from './types'
2
- export * from './store'
3
- export * from './actions'
4
- export * from './app/pages/page-view'
5
- export * from './object-store'
6
- export * from './custom-alert'
File without changes
@@ -1,173 +0,0 @@
1
- /*
2
- * [ Caution ]
3
- * Since this module is being used by a service worker, be very careful about adding imports or using functions for browsers.
4
- */
5
-
6
- type OxObjectStore = {
7
- add: (value: any, key?: IDBValidKey | undefined) => IDBValidKey
8
- delete: (query: IDBValidKey | IDBKeyRange) => undefined
9
- clear: () => undefined
10
- get: (query: IDBValidKey | IDBKeyRange) => any
11
- getAll: (query?: IDBValidKey | IDBKeyRange | null | undefined, count?: number | undefined) => any[]
12
- getAllKeys: (query?: IDBValidKey | IDBKeyRange | null | undefined, count?: number | undefined) => IDBValidKey[]
13
- count: (query?: IDBValidKey | IDBKeyRange | undefined) => number
14
- put: (value: any, key?: IDBValidKey | undefined) => IDBValidKey
15
- openCursor: (
16
- query?: IDBValidKey | IDBKeyRange | null | undefined,
17
- direction?: IDBCursorDirection | undefined
18
- ) => IDBCursorWithValue | null
19
- openKeyCursor: (
20
- query?: IDBValidKey | IDBKeyRange | null | undefined,
21
- direction?: IDBCursorDirection | undefined
22
- ) => IDBCursor | null
23
- limit: (limit?: number) => undefined
24
- }
25
-
26
- /* promise queue */
27
- class Queue {
28
- private static queue: {
29
- promise: Promise<IDBDatabase>
30
- resolve: (db: IDBDatabase) => void
31
- reject: (reason?: any) => void
32
- }[] = []
33
-
34
- private static workingOnPromise: boolean = false
35
-
36
- static enqueue(promise: Promise<any>) {
37
- return new Promise((resolve, reject) => {
38
- this.queue.push({
39
- promise,
40
- resolve,
41
- reject
42
- })
43
- this.dequeue()
44
- })
45
- }
46
-
47
- static dequeue() {
48
- if (this.workingOnPromise) {
49
- return false
50
- }
51
- const item = this.queue.shift()
52
- if (!item) {
53
- return false
54
- }
55
- try {
56
- this.workingOnPromise = true
57
- item.promise
58
- .then(value => {
59
- this.workingOnPromise = false
60
- item.resolve(value)
61
- this.dequeue()
62
- })
63
- .catch(err => {
64
- this.workingOnPromise = false
65
- item.reject(err)
66
- this.dequeue()
67
- })
68
- } catch (err) {
69
- this.workingOnPromise = false
70
- item.reject(err)
71
- this.dequeue()
72
- }
73
- return true
74
- }
75
- }
76
-
77
- function getStore(storeName: string): OxObjectStore {
78
- return [
79
- 'add',
80
- 'delete',
81
- 'clear',
82
- 'get',
83
- 'getAll',
84
- 'getAllKeys',
85
- 'count',
86
- 'put',
87
- 'openCursor',
88
- 'openKeyCursor'
89
- ].reduce(
90
- (sum, m) => {
91
- sum[m] = async (...params: any) => {
92
- const db = (await getIndexDB()) as IDBDatabase
93
-
94
- const transaction = db.transaction(storeName, 'readwrite')
95
- const store = transaction.objectStore(storeName)
96
- const method: (...p: any) => any = (store as any)[m]
97
- const request = method.apply(store, params)
98
-
99
- return await new Promise((resolve, reject) => {
100
- request.onsuccess = (event: Event) => {
101
- resolve((event.target as IDBRequest)?.result)
102
- }
103
-
104
- request.onerror = (event: Event) => {
105
- reject(event)
106
- }
107
- })
108
- }
109
-
110
- return sum
111
- },
112
- {
113
- async limit(this: OxObjectStore, limit = 50) {
114
- const keys = (await this.getAllKeys()).slice(0, -limit)
115
- for (let i = 0; i < keys.length; i++) {
116
- await this.delete(keys[i])
117
- }
118
- }
119
- } as any
120
- )
121
- }
122
-
123
- function getIndexedDB(): IDBFactory {
124
- if (typeof window !== 'undefined') {
125
- return window.indexedDB
126
- } else {
127
- return self.indexedDB
128
- }
129
- }
130
-
131
- var db: IDBDatabase
132
-
133
- function getIndexDB() {
134
- if (db) {
135
- return db
136
- }
137
-
138
- return Queue.enqueue(
139
- new Promise(function (resolve, reject) {
140
- const indexedDB = getIndexedDB()
141
-
142
- if (!indexedDB) {
143
- reject('this browser does not support indexedDB')
144
- }
145
- const request = indexedDB.open('things-factory-database')
146
-
147
- request.onerror = function (event) {
148
- console.log("Why didn't you allow my web app to use IndexedDB?!")
149
- reject(event)
150
- }
151
-
152
- request.onupgradeneeded = function (event: IDBVersionChangeEvent) {
153
- var db: IDBDatabase = (event.target as IDBRequest)?.result
154
-
155
- var store = db.createObjectStore('notifications', { keyPath: 'id', autoIncrement: true })
156
- store.createIndex('notification_id_unqiue', 'id', { unique: true })
157
-
158
- var store = db.createObjectStore('client_settings', { keyPath: 'key', autoIncrement: true })
159
- store.createIndex('client_setting_key_unqiue', 'key', { unique: true })
160
- }
161
-
162
- request.onsuccess = function (event) {
163
- console.log('IndexedDB opened successfully')
164
- db = request.result
165
- resolve(db)
166
- }
167
- })
168
- )
169
- }
170
-
171
- /* ready indexedDB Stores */
172
- export const clientSettingStore: OxObjectStore = getStore('client_settings')
173
- export const notificationStore: OxObjectStore = getStore('notifications')
@@ -1,48 +0,0 @@
1
- import { getPathInfo } from '@operato/utils'
2
-
3
- import { SET_DOMAINS, UPDATE_BASE_URL, UPDATE_CONTEXT_PATH, UPDATE_MODULES } from '../actions/app.js'
4
-
5
- const INITIAL_STATE: {
6
- baseUrl: string
7
- contextPath: string
8
- domains: {
9
- name: string
10
- subdomain: string
11
- }[]
12
- } = {
13
- baseUrl: location.origin,
14
- contextPath: getPathInfo(location.pathname).contextPath,
15
- domains: []
16
- }
17
-
18
- const app = (state = INITIAL_STATE, action: any) => {
19
- switch (action.type) {
20
- case UPDATE_MODULES:
21
- return {
22
- ...state,
23
- modules: action.modules
24
- }
25
- case UPDATE_BASE_URL:
26
- return {
27
- ...state,
28
- baseUrl: action.baseUrl
29
- }
30
- case UPDATE_CONTEXT_PATH:
31
- return {
32
- ...state,
33
- contextPath: action.contextPath
34
- }
35
-
36
- case SET_DOMAINS:
37
- return {
38
- ...state,
39
- domains: action.domains,
40
- domain: action.domain
41
- }
42
-
43
- default:
44
- return state
45
- }
46
- }
47
-
48
- export default app
@@ -1,21 +0,0 @@
1
- import { UPDATE_BUSY } from '../actions/busy.js'
2
-
3
- const INITIAL_STATE: {
4
- busy: boolean
5
- } = {
6
- busy: false
7
- }
8
-
9
- const busy = (state = INITIAL_STATE, action: any) => {
10
- switch (action.type) {
11
- case UPDATE_BUSY:
12
- return {
13
- busy: action.busy
14
- }
15
-
16
- default:
17
- return state
18
- }
19
- }
20
-
21
- export default busy