lupine.web 1.0.16 → 1.0.17
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/package.json +1 -5
- package/src/core/bind-lang.ts +6 -5
- package/src/core/bind-links.ts +2 -2
- package/src/core/bind-theme.ts +6 -5
- package/src/core/export-lupine.ts +64 -0
- package/src/core/index.ts +2 -1
- package/src/core/{core.ts → initialize.ts} +9 -67
- package/src/core/page-router.ts +3 -2
- package/src/core/server-cookie.ts +5 -3
- package/src/index.ts +0 -1
- package/src/lib/index.ts +2 -13
- package/src/lib/is-frontend.ts +3 -0
- package/src/styles/index.ts +0 -5
- package/src/components/button-push-animation.tsx +0 -138
- package/src/components/button.tsx +0 -55
- package/src/components/drag-refresh.tsx +0 -110
- package/src/components/editable-label.tsx +0 -83
- package/src/components/float-window.tsx +0 -226
- package/src/components/grid.tsx +0 -18
- package/src/components/html-var.tsx +0 -41
- package/src/components/index.ts +0 -36
- package/src/components/input-with-title.tsx +0 -24
- package/src/components/link-item.tsx +0 -13
- package/src/components/link-list.tsx +0 -62
- package/src/components/menu-bar.tsx +0 -220
- package/src/components/menu-item-props.tsx +0 -10
- package/src/components/menu-sidebar.tsx +0 -289
- package/src/components/message-box.tsx +0 -44
- package/src/components/meta-data.tsx +0 -36
- package/src/components/meta-description.tsx +0 -12
- package/src/components/modal.tsx +0 -29
- package/src/components/notice-message.tsx +0 -119
- package/src/components/page-title.tsx +0 -6
- package/src/components/paging-link.tsx +0 -100
- package/src/components/panel.tsx +0 -21
- package/src/components/popup-menu.tsx +0 -218
- package/src/components/progress.tsx +0 -91
- package/src/components/redirect.tsx +0 -19
- package/src/components/resizable-splitter.tsx +0 -129
- package/src/components/select-with-title.tsx +0 -37
- package/src/components/spinner.tsx +0 -100
- package/src/components/svg.tsx +0 -24
- package/src/components/tabs.tsx +0 -252
- package/src/components/text-glow.tsx +0 -36
- package/src/components/text-wave.tsx +0 -54
- package/src/components/theme-selector.tsx +0 -32
- package/src/components/toggle-base.tsx +0 -260
- package/src/components/toggle-switch.tsx +0 -156
- package/src/lib/date-utils.ts +0 -317
- package/src/lib/deep-merge.ts +0 -37
- package/src/lib/document-ready.ts +0 -36
- package/src/lib/dom/calculate-text-width.ts +0 -13
- package/src/lib/dom/download-stream.ts +0 -17
- package/src/lib/dom/download.ts +0 -12
- package/src/lib/dom/index.ts +0 -71
- package/src/lib/dynamical-load.ts +0 -138
- package/src/lib/format-bytes.ts +0 -11
- package/src/lib/lite-dom.ts +0 -227
- package/src/lib/message-hub.ts +0 -105
- package/src/lib/observable.ts +0 -188
- package/src/lib/promise-timeout.ts +0 -1
- package/src/lib/simple-storage.ts +0 -40
- package/src/lib/stop-propagation.ts +0 -7
- package/src/lib/upload-file.ts +0 -68
- package/src/styles/base-themes.ts +0 -17
- package/src/styles/dark-themes.ts +0 -86
- package/src/styles/light-themes.ts +0 -93
- package/src/styles/media-query.ts +0 -93
- package/src/styles/shared-themes.ts +0 -52
- /package/src/lib/{dom/cookie.ts → cookie.ts} +0 -0
package/src/lib/lite-dom.ts
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
// Lite Dom Utils
|
|
2
|
-
/*
|
|
3
|
-
Don't judge whether this.node is valid, so it throws error when this.node is not found or undefined
|
|
4
|
-
*/
|
|
5
|
-
export class LiteDom {
|
|
6
|
-
private node: Element;
|
|
7
|
-
|
|
8
|
-
static queryOne(selector?: string | Element | LiteDom, docRoot?: Element): LiteDom | null {
|
|
9
|
-
if (!selector) {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
if (selector instanceof LiteDom) {
|
|
13
|
-
return selector;
|
|
14
|
-
}
|
|
15
|
-
if (selector instanceof Element) {
|
|
16
|
-
return new LiteDom(selector);
|
|
17
|
-
}
|
|
18
|
-
const el = (docRoot || document).querySelector(selector) as Element;
|
|
19
|
-
return el ? new LiteDom(el) : null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static queryAll(selector?: string | Element | LiteDom, docRoot?: Element): LiteDom[] {
|
|
23
|
-
if (!selector) {
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
26
|
-
if (selector instanceof LiteDom) {
|
|
27
|
-
return [selector];
|
|
28
|
-
}
|
|
29
|
-
if (selector instanceof Element) {
|
|
30
|
-
return [new LiteDom(selector)];
|
|
31
|
-
}
|
|
32
|
-
const el = (docRoot || document).querySelectorAll(selector);
|
|
33
|
-
const ret = [];
|
|
34
|
-
for (let i in el) {
|
|
35
|
-
ret.push(new LiteDom(el[i] as Element));
|
|
36
|
-
}
|
|
37
|
-
return ret;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static createElement(html: string, docRoot?: Document): LiteDom {
|
|
41
|
-
const dom = (docRoot || document).createElement(html);
|
|
42
|
-
const domLib = new LiteDom(dom);
|
|
43
|
-
return domLib;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
constructor(selector?: string | Element | LiteDom, docRoot?: Element) {
|
|
47
|
-
if (selector instanceof LiteDom) {
|
|
48
|
-
this.node = selector.node;
|
|
49
|
-
} else if (selector instanceof Element) {
|
|
50
|
-
this.node = selector;
|
|
51
|
-
} else {
|
|
52
|
-
const el = selector && ((docRoot || document).querySelector(selector) as Element);
|
|
53
|
-
if (el) {
|
|
54
|
-
this.node = el;
|
|
55
|
-
} else {
|
|
56
|
-
throw new TypeError('Element is not defined for a new LibDom');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
getElement(): Element {
|
|
62
|
-
return this.node;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// query children and set value or innerHTML
|
|
66
|
-
$(selector: string, value?: string | number | boolean | null): LiteDom | null {
|
|
67
|
-
const dom = LiteDom.queryOne(selector, this.node);
|
|
68
|
-
if (dom && typeof value !== 'undefined') {
|
|
69
|
-
if ('checked' in dom.node) {
|
|
70
|
-
dom.node.checked = !!value;
|
|
71
|
-
} else if ('value' in dom.node) {
|
|
72
|
-
dom.node.value = value;
|
|
73
|
-
} else if ('innerHTML' in dom.node) {
|
|
74
|
-
dom.node.innerHTML = '' + value;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return dom;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// query children
|
|
81
|
-
query(selector: string): LiteDom | null {
|
|
82
|
-
return LiteDom.queryOne(selector, this.node);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// query children
|
|
86
|
-
queryAll(selector: string): LiteDom[] {
|
|
87
|
-
return LiteDom.queryAll(selector, this.node);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
on(eventName: string, eventHandler: (this: Element, ev: any) => any) {
|
|
91
|
-
this.node.addEventListener(eventName, eventHandler, false);
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
off(eventName: string, eventHandler: (this: Element, ev: any) => any) {
|
|
96
|
-
this.node.removeEventListener(eventName, eventHandler, false);
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
fire(event: Event) {
|
|
101
|
-
this.node.dispatchEvent(event);
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
isCheckbox(): boolean {
|
|
106
|
-
return this.tagName === 'INPUT' && (this.node as any).type === 'checkbox';
|
|
107
|
-
}
|
|
108
|
-
isRadio(): boolean {
|
|
109
|
-
return this.tagName === 'INPUT' && (this.node as any).type === 'radio';
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
val(value?: string): string | LiteDom {
|
|
113
|
-
if (typeof value === 'undefined') {
|
|
114
|
-
return (<any>this.node).value;
|
|
115
|
-
}
|
|
116
|
-
'value' in this.node && (this.node.value = value);
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
checked(value?: boolean) {
|
|
121
|
-
if (typeof value === 'undefined') {
|
|
122
|
-
return (<any>this.node).checked;
|
|
123
|
-
}
|
|
124
|
-
'checked' in this.node && (this.node.checked = !!value);
|
|
125
|
-
return this;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
selectedIndex(value?: number) {
|
|
129
|
-
if (typeof value === 'undefined') {
|
|
130
|
-
return (<any>this.node).selectedIndex;
|
|
131
|
-
}
|
|
132
|
-
'selectedIndex' in this.node && (this.node.selectedIndex = value);
|
|
133
|
-
return this;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
html(value?: string): string | LiteDom {
|
|
137
|
-
if (typeof value === 'undefined') {
|
|
138
|
-
return this.node.innerHTML;
|
|
139
|
-
}
|
|
140
|
-
'innerHTML' in this.node && (this.node.innerHTML = value);
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/*
|
|
145
|
-
element.style.backgroundColor = 'blue' // works
|
|
146
|
-
element.style['backgroundColor'] = 'blue' // works
|
|
147
|
-
element.style['background-color'] = 'blue' // does not work
|
|
148
|
-
|
|
149
|
-
element.style.setProperty('background-color','blue') // works
|
|
150
|
-
element.style.setProperty('backgroundColor','blue') // does not work
|
|
151
|
-
*/
|
|
152
|
-
css(propertyName: string, value?: string): string | false | LiteDom {
|
|
153
|
-
if (typeof value === 'undefined') {
|
|
154
|
-
return this.node instanceof HTMLElement && this.node.style.getPropertyValue(propertyName);
|
|
155
|
-
}
|
|
156
|
-
if (this.node instanceof HTMLElement) {
|
|
157
|
-
if (value === null) {
|
|
158
|
-
this.node.style.removeProperty(propertyName);
|
|
159
|
-
} else {
|
|
160
|
-
this.node.style.setProperty(propertyName, value);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return this;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
attribute(attributeName: string, value?: string): string | null | LiteDom {
|
|
167
|
-
if (typeof value === 'undefined') {
|
|
168
|
-
return this.node.getAttribute(attributeName);
|
|
169
|
-
}
|
|
170
|
-
if (value === null) {
|
|
171
|
-
this.node.removeAttribute(attributeName);
|
|
172
|
-
} else {
|
|
173
|
-
this.node.setAttribute(attributeName, value);
|
|
174
|
-
}
|
|
175
|
-
return this;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
class(addClass?: string | string[], removeClass?: string | string[]): string | LiteDom {
|
|
179
|
-
if (!addClass && !removeClass) {
|
|
180
|
-
return (<any>this.node).className;
|
|
181
|
-
}
|
|
182
|
-
const classList = this.node.classList;
|
|
183
|
-
if (addClass) {
|
|
184
|
-
addClass instanceof Array ? classList.add(...addClass) : classList.add(addClass);
|
|
185
|
-
}
|
|
186
|
-
if (removeClass) {
|
|
187
|
-
removeClass instanceof Array ? classList.remove(...removeClass) : classList.remove(removeClass);
|
|
188
|
-
}
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
appendChild(child: Element | LiteDom) {
|
|
193
|
-
const dom = child instanceof LiteDom ? child.getElement() : child;
|
|
194
|
-
dom && this.node.appendChild(dom);
|
|
195
|
-
return this;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
removeChild(child: Element | LiteDom) {
|
|
199
|
-
const dom = child instanceof LiteDom ? child.getElement() : child;
|
|
200
|
-
dom && this.node.removeChild(dom);
|
|
201
|
-
return this;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
removeSelf() {
|
|
205
|
-
// this.node.parentElement!.removeChild(this.node);
|
|
206
|
-
this.node.remove();
|
|
207
|
-
return this;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
get children(): LiteDom[] {
|
|
211
|
-
if (!this.node.children) {
|
|
212
|
-
return [];
|
|
213
|
-
}
|
|
214
|
-
const ret = [];
|
|
215
|
-
for (let i = 0; i < this.node.children.length; i++) {
|
|
216
|
-
ret.push(new LiteDom(this.node.children[i]));
|
|
217
|
-
}
|
|
218
|
-
return ret;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// originally returns the HTML-uppercased qualified name.
|
|
222
|
-
get tagName(): string {
|
|
223
|
-
return this.node.tagName.toUpperCase();
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export default LiteDom.queryOne;
|
package/src/lib/message-hub.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
export class MessageHubData<T> {
|
|
2
|
-
constructor(public actionId: string, public message: string, public extraData?: T) {}
|
|
3
|
-
}
|
|
4
|
-
export class MessageHub {
|
|
5
|
-
private subscriptions: { [key: string]: { [key: string]: Function } } = {};
|
|
6
|
-
private subscriptionValues: { [key: string]: any } = {};
|
|
7
|
-
private lastId = 0;
|
|
8
|
-
constructor(public passLastMsgWhenSubscribe = false) {}
|
|
9
|
-
|
|
10
|
-
// * for listening to all events
|
|
11
|
-
public subscribe(targetType: string, fn: Function, recessiveLassMsg = true) {
|
|
12
|
-
const id = this.lastId++;
|
|
13
|
-
if (!this.subscriptions[targetType]) {
|
|
14
|
-
this.subscriptions[targetType] = {};
|
|
15
|
-
}
|
|
16
|
-
this.subscriptions[targetType][id] = fn;
|
|
17
|
-
if (recessiveLassMsg && this.passLastMsgWhenSubscribe && this.subscriptionValues[targetType]) {
|
|
18
|
-
this.notify(fn, this.subscriptionValues[targetType]);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return () => {
|
|
22
|
-
delete this.subscriptions[targetType][id];
|
|
23
|
-
var needDestroy = true;
|
|
24
|
-
for (var key in this.subscriptions[targetType]) {
|
|
25
|
-
needDestroy = false;
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
if (needDestroy) {
|
|
29
|
-
delete this.subscriptions[targetType];
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public send(targetType: string, arg: any) {
|
|
35
|
-
if (targetType === '*') {
|
|
36
|
-
for (var groupKey in this.subscriptions) {
|
|
37
|
-
for (var key in this.subscriptions[groupKey]) {
|
|
38
|
-
this.notify(this.subscriptions[groupKey][key], arg);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (this.passLastMsgWhenSubscribe) {
|
|
45
|
-
this.subscriptionValues[targetType] = arg;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (this.subscriptions[targetType]) {
|
|
49
|
-
for (var key in this.subscriptions[targetType]) {
|
|
50
|
-
this.notify(this.subscriptions[targetType][key], arg);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (this.subscriptions['*']) {
|
|
54
|
-
for (var key in this.subscriptions['*']) {
|
|
55
|
-
this.notify(this.subscriptions['*'][key], arg);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public hasListener(targetType: string): boolean {
|
|
61
|
-
if (targetType === '*') {
|
|
62
|
-
// if has any subscriptions
|
|
63
|
-
for (var groupKey in this.subscriptions) {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
} else {
|
|
67
|
-
// if has any subscriptions of eventType
|
|
68
|
-
for (var groupKey in this.subscriptions[targetType]) {
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private notify(fn: Function, arg: any) {
|
|
76
|
-
setTimeout(() => {
|
|
77
|
-
fn(arg);
|
|
78
|
-
}, 0);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export const defaultMessageHub = new MessageHub();
|
|
83
|
-
|
|
84
|
-
// /*[TEST-START]*/
|
|
85
|
-
// function TEST_sample() {
|
|
86
|
-
// var mHub = new MessageHub(true);
|
|
87
|
-
// var unsubscribeA = mHub.subscribe('test', (msg: string) => {
|
|
88
|
-
// console.log('MessageHub test', msg);
|
|
89
|
-
// });
|
|
90
|
-
// var unsubscribeB = mHub.subscribe('*', (msg: string) => {
|
|
91
|
-
// console.log('MessageHub *', msg);
|
|
92
|
-
// });
|
|
93
|
-
// console.log(mHub.hasListener('test'));
|
|
94
|
-
|
|
95
|
-
// mHub.send('test', new MessageHubData('aa', 'bb'));
|
|
96
|
-
// mHub.send('*', new MessageHubData('aa*', 'bb*'));
|
|
97
|
-
|
|
98
|
-
// unsubscribeA();
|
|
99
|
-
// mHub.send('test', new MessageHubData('aa', 'bb'));
|
|
100
|
-
// unsubscribeB();
|
|
101
|
-
// mHub.send('*', new MessageHubData<string>('aa to * 2', 'bb', 'extra message'));
|
|
102
|
-
// console.log(mHub.hasListener('test'));
|
|
103
|
-
// }
|
|
104
|
-
// // TEST_sample();
|
|
105
|
-
// /*[TEST-END]*/
|
package/src/lib/observable.ts
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
// inspired by rxjs
|
|
2
|
-
|
|
3
|
-
export class Subscription {
|
|
4
|
-
private _unsubscribe;
|
|
5
|
-
constructor(unsubscribe: () => void) {
|
|
6
|
-
this._unsubscribe = unsubscribe;
|
|
7
|
-
}
|
|
8
|
-
unsubscribe(): void {
|
|
9
|
-
if (this._unsubscribe) {
|
|
10
|
-
this._unsubscribe();
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class Observable<T> {
|
|
16
|
-
constructor() {}
|
|
17
|
-
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription {
|
|
18
|
-
throw new Error('subscribe is not implemented');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class Subject<T> extends Observable<T> {
|
|
23
|
-
private observers: {
|
|
24
|
-
next?: (value: T) => void;
|
|
25
|
-
error?: (error: any) => void;
|
|
26
|
-
complete?: () => void;
|
|
27
|
-
}[] = [];
|
|
28
|
-
private isStopped = false;
|
|
29
|
-
private _hasError = false;
|
|
30
|
-
private passLastMsgWhenSubscribe;
|
|
31
|
-
private lastSaved: { [key: string]: T } = {};
|
|
32
|
-
|
|
33
|
-
constructor(passLastMsgWhenSubscribe = false) {
|
|
34
|
-
super();
|
|
35
|
-
this.passLastMsgWhenSubscribe = passLastMsgWhenSubscribe;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
next(value?: T) {
|
|
39
|
-
if (this.isStopped) {
|
|
40
|
-
throw new Error('Subject is closed');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const len = this.observers.length;
|
|
44
|
-
const copy = this.observers.slice();
|
|
45
|
-
for (let i = 0; i < len; i++) {
|
|
46
|
-
const item = copy[i].next;
|
|
47
|
-
if (typeof item !== 'undefined' && typeof value !== 'undefined') {
|
|
48
|
-
item(value);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (this.passLastMsgWhenSubscribe) {
|
|
52
|
-
if (typeof value !== 'undefined') {
|
|
53
|
-
this.lastSaved['value'] = value;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
error(err: any) {
|
|
59
|
-
if (this.isStopped) {
|
|
60
|
-
throw new Error('Subject is closed');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
this._hasError = true;
|
|
64
|
-
this.isStopped = true;
|
|
65
|
-
const len = this.observers.length;
|
|
66
|
-
const copy = this.observers.slice();
|
|
67
|
-
for (let i = 0; i < len; i++) {
|
|
68
|
-
const item = copy[i].error;
|
|
69
|
-
if (typeof item !== 'undefined' && typeof err !== 'undefined') {
|
|
70
|
-
item(err);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
this.observers.length = 0;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
complete() {
|
|
77
|
-
if (this.isStopped) {
|
|
78
|
-
throw new Error('Subject is closed');
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
this.isStopped = true;
|
|
82
|
-
const copy = this.observers.slice();
|
|
83
|
-
const len = copy.length;
|
|
84
|
-
for (let i = 0; i < len; i++) {
|
|
85
|
-
const item = copy[i].complete;
|
|
86
|
-
if (typeof item !== 'undefined') {
|
|
87
|
-
item();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (this.observers.length != len) {
|
|
91
|
-
console.warn(`Subscribe count changed from ${len} to ${this.observers.length}`);
|
|
92
|
-
}
|
|
93
|
-
this.observers.length = 0;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
hasError() {
|
|
97
|
-
return this._hasError;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
private unsubscribe(observer: {}) {
|
|
101
|
-
const index = this.observers.findIndex((item) => item === observer);
|
|
102
|
-
if (index > -1) {
|
|
103
|
-
this.observers.splice(index, 1);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription {
|
|
108
|
-
if (this.isStopped) {
|
|
109
|
-
throw new Error('Subject is stopped');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const observer = {
|
|
113
|
-
next,
|
|
114
|
-
error,
|
|
115
|
-
complete,
|
|
116
|
-
};
|
|
117
|
-
this.observers.push(observer);
|
|
118
|
-
if (this.passLastMsgWhenSubscribe) {
|
|
119
|
-
if (typeof observer.next !== 'undefined' && typeof this.lastSaved['value'] !== 'undefined') {
|
|
120
|
-
observer.next(this.lastSaved['value']);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
const ret = new Subscription(() => {
|
|
124
|
-
this.unsubscribe(observer);
|
|
125
|
-
});
|
|
126
|
-
return ret;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
asObservable(): Observable<T> {
|
|
130
|
-
return this as Observable<T>;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// /*[TEST-START]*/
|
|
135
|
-
// function TEST_sample() {
|
|
136
|
-
// const flag = new Subject(true);
|
|
137
|
-
// const observable1 = flag.asObservable();
|
|
138
|
-
// const unsubscribeA = observable1.subscribe(
|
|
139
|
-
// (next) => {
|
|
140
|
-
// console.log('A', next);
|
|
141
|
-
// },
|
|
142
|
-
// (error) => {
|
|
143
|
-
// console.log('A error:', error);
|
|
144
|
-
// }
|
|
145
|
-
// );
|
|
146
|
-
// const unsubscribeB = observable1.subscribe(
|
|
147
|
-
// (next) => {
|
|
148
|
-
// console.log('B', next);
|
|
149
|
-
// },
|
|
150
|
-
// (error) => {
|
|
151
|
-
// console.log('B error:', error);
|
|
152
|
-
// }
|
|
153
|
-
// );
|
|
154
|
-
|
|
155
|
-
// flag.next('test 1');
|
|
156
|
-
// unsubscribeA.unsubscribe();
|
|
157
|
-
// flag.next('test 2');
|
|
158
|
-
// flag.error('error 1');
|
|
159
|
-
// }
|
|
160
|
-
// TEST_sample();
|
|
161
|
-
/*[TEST-END]*/
|
|
162
|
-
|
|
163
|
-
// const flag: BehaviorSubject<Date>;
|
|
164
|
-
// getFlag(): Observable<Date> {
|
|
165
|
-
// return this.flag.asObservable();
|
|
166
|
-
// }
|
|
167
|
-
// setFlag(flag) {
|
|
168
|
-
// this.flag.next(flag);
|
|
169
|
-
// }
|
|
170
|
-
|
|
171
|
-
// getAll(): Observable<string[]> {
|
|
172
|
-
// this.labelsSubject = new ReplaySubject(1);
|
|
173
|
-
// this.http.get().subscribe(result => {
|
|
174
|
-
// this.labelsSubject.next(result);
|
|
175
|
-
// });
|
|
176
|
-
|
|
177
|
-
// return new Observable<string[]>(observer => {
|
|
178
|
-
// this.labelsSubject.subscribe(result => {
|
|
179
|
-
// observer.next(result);
|
|
180
|
-
// observer.complete();
|
|
181
|
-
// }, error => {
|
|
182
|
-
// observer.error(error);
|
|
183
|
-
// });
|
|
184
|
-
// });
|
|
185
|
-
// }
|
|
186
|
-
|
|
187
|
-
// getAll().subscribe(labels => labels.push(res));
|
|
188
|
-
// sub.unsubscribe()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const promiseTimeout = (delayMs: number) => new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// This class is used by both BE and FE (cookie for SSR).
|
|
2
|
-
export class SimpleStorage {
|
|
3
|
-
private settings: { [key: string]: string } = {};
|
|
4
|
-
|
|
5
|
-
constructor(settings: { [key: string]: string }) {
|
|
6
|
-
this.settings = settings;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
contains(key: string): boolean {
|
|
10
|
-
return key in this.settings;
|
|
11
|
-
}
|
|
12
|
-
set(key: string, value: string) {
|
|
13
|
-
return (this.settings[key] = value);
|
|
14
|
-
}
|
|
15
|
-
get(key: string, defaultValue: string): string {
|
|
16
|
-
return key in this.settings ? this.settings[key] : defaultValue;
|
|
17
|
-
}
|
|
18
|
-
getInt(key: string, defaultValue: number): number {
|
|
19
|
-
if (key in this.settings) {
|
|
20
|
-
const i = parseInt(this.settings[key]);
|
|
21
|
-
if (!isNaN(i)) {
|
|
22
|
-
return i;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return defaultValue;
|
|
26
|
-
}
|
|
27
|
-
getBoolean(key: string, defaultValue: boolean): boolean {
|
|
28
|
-
return key in this.settings
|
|
29
|
-
? this.settings[key] === '1' || this.settings[key].toLowerCase() === 'true'
|
|
30
|
-
: defaultValue;
|
|
31
|
-
}
|
|
32
|
-
getJson(key: string, defaultValue: object): object {
|
|
33
|
-
if (key in this.settings) {
|
|
34
|
-
try {
|
|
35
|
-
return JSON.parse(this.settings[key]);
|
|
36
|
-
} catch (error) {}
|
|
37
|
-
}
|
|
38
|
-
return defaultValue;
|
|
39
|
-
}
|
|
40
|
-
}
|
package/src/lib/upload-file.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const _saveChunkSize = {
|
|
2
|
-
size: 1024 * 500,
|
|
3
|
-
};
|
|
4
|
-
export const setChunkSize = (chunkSize: number) => {
|
|
5
|
-
_saveChunkSize.size = chunkSize;
|
|
6
|
-
};
|
|
7
|
-
export const getChunkSize = () => {
|
|
8
|
-
return _saveChunkSize.size;
|
|
9
|
-
};
|
|
10
|
-
export const checkUploadedFileSize = async (uploadUrl: string) => {
|
|
11
|
-
const response = await fetch(uploadUrl + '?check-size=1', {
|
|
12
|
-
method: 'POST',
|
|
13
|
-
});
|
|
14
|
-
const json = await response.json();
|
|
15
|
-
return json && json.size ? json.size : 0;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// should return { chunkNumber: number }
|
|
19
|
-
export const uploadFileChunk = async (
|
|
20
|
-
chunk: any,
|
|
21
|
-
chunkNumber: number,
|
|
22
|
-
totalChunks: number,
|
|
23
|
-
uploadUrl: string,
|
|
24
|
-
key: string
|
|
25
|
-
) => {
|
|
26
|
-
// this must be the FE so we can use fetch
|
|
27
|
-
let url = uploadUrl + (uploadUrl.indexOf('?') === -1 ? '?' : '');
|
|
28
|
-
url += `&chunkNumber=${chunkNumber.toString()}`;
|
|
29
|
-
url += `&totalChunks=${totalChunks.toString()}`;
|
|
30
|
-
if (key) {
|
|
31
|
-
url += `&key=${key}`;
|
|
32
|
-
}
|
|
33
|
-
const response = await fetch(url, {
|
|
34
|
-
method: 'POST',
|
|
35
|
-
body: chunk,
|
|
36
|
-
});
|
|
37
|
-
const json = await response.json();
|
|
38
|
-
return json;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const uploadFile = async (
|
|
42
|
-
file: File,
|
|
43
|
-
uploadUrl: string,
|
|
44
|
-
progressFn?: (percentage: number, chunkNumber: number, totalChunks: number) => void,
|
|
45
|
-
chunkSize = _saveChunkSize.size
|
|
46
|
-
) => {
|
|
47
|
-
// const uploadedSize = await checkUploadedFileSize(uploadUrl);
|
|
48
|
-
let key = '';
|
|
49
|
-
if (file.size <= chunkSize) {
|
|
50
|
-
return await uploadFileChunk(file, 0, 1, uploadUrl, key);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const totalChunks = Math.ceil(file.size / chunkSize);
|
|
54
|
-
for (let i = 0; i < totalChunks; i++) {
|
|
55
|
-
const start = i * chunkSize;
|
|
56
|
-
const end = Math.min((i + 1) * chunkSize, file.size);
|
|
57
|
-
const chunk = file.slice(start, end);
|
|
58
|
-
const uploaded = await uploadFileChunk(chunk, i, totalChunks, uploadUrl, key);
|
|
59
|
-
if (!uploaded || uploaded.chunkNumber === i.toString() || !uploaded.key) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
key = uploaded.key;
|
|
63
|
-
if (progressFn) {
|
|
64
|
-
progressFn(Math.round(((i + 1) / totalChunks) * 100) / 100, i, totalChunks);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return true;
|
|
68
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ThemesProps } from '../models';
|
|
2
|
-
import { darkThemes } from './dark-themes';
|
|
3
|
-
import { lightThemes } from './light-themes';
|
|
4
|
-
|
|
5
|
-
export const baseThemes: ThemesProps = {
|
|
6
|
-
light: lightThemes,
|
|
7
|
-
dark: darkThemes,
|
|
8
|
-
lightGreen: {
|
|
9
|
-
...lightThemes,
|
|
10
|
-
'--background-primary': '#d8ffe3', // Primary background
|
|
11
|
-
'--color-primary': '#303030', // Primary text color
|
|
12
|
-
backgroundPrimary: '', // Primary background
|
|
13
|
-
backgroundOnPrimary: '', // Background for surfaces on top of primary background
|
|
14
|
-
backgroundSecondary: '#f5f5f7', // Secondary background
|
|
15
|
-
backgroundOnSecondary: '#e5e5e7', // Background for surfaces on top of secondary background
|
|
16
|
-
},
|
|
17
|
-
};
|