lupine.components 1.1.13 → 1.1.15

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.
Files changed (92) hide show
  1. package/README.md +3 -3
  2. package/package.json +42 -42
  3. package/src/components/action-sheet.tsx +419 -419
  4. package/src/components/button-push-animation.tsx +147 -138
  5. package/src/components/button.tsx +55 -55
  6. package/src/components/desktop-footer.tsx +17 -17
  7. package/src/components/desktop-header.tsx +52 -52
  8. package/src/components/drag-refresh.tsx +129 -129
  9. package/src/components/editable-label.tsx +83 -83
  10. package/src/components/float-window.tsx +233 -233
  11. package/src/components/grid.tsx +18 -18
  12. package/src/components/html-load.tsx +41 -41
  13. package/src/components/html-var.tsx +81 -81
  14. package/src/components/index.ts +43 -44
  15. package/src/components/input-with-title.tsx +24 -24
  16. package/src/components/link-item.tsx +13 -13
  17. package/src/components/link-list.tsx +62 -62
  18. package/src/components/menu-bar.tsx +219 -219
  19. package/src/components/menu-item-props.tsx +13 -13
  20. package/src/components/menu-sidebar.tsx +325 -318
  21. package/src/components/message-box.tsx +44 -44
  22. package/src/components/meta-data.tsx +36 -36
  23. package/src/components/meta-description.tsx +12 -12
  24. package/src/components/mobile-components/icon-menu-item-props.ts +6 -6
  25. package/src/components/mobile-components/index.ts +8 -9
  26. package/src/components/mobile-components/mobile-footer-menu.tsx +95 -95
  27. package/src/components/mobile-components/mobile-header-component.tsx +101 -101
  28. package/src/components/mobile-components/mobile-header-title-icon.tsx +109 -101
  29. package/src/components/mobile-components/mobile-header-with-back.tsx +127 -117
  30. package/src/components/mobile-components/mobile-side-menu.tsx +154 -154
  31. package/src/components/mobile-components/mobile-top-sys-icon.tsx +18 -18
  32. package/src/components/mobile-components/mobile-top-sys-menu.tsx +62 -62
  33. package/src/components/modal.tsx +33 -33
  34. package/src/components/notice-message.tsx +118 -118
  35. package/src/components/page-title.tsx +6 -6
  36. package/src/components/paging-link.tsx +175 -175
  37. package/src/components/panel.tsx +21 -21
  38. package/src/components/popup-menu.tsx +289 -289
  39. package/src/components/progress.tsx +91 -91
  40. package/src/components/radio-label-component.tsx +36 -36
  41. package/src/components/redirect.tsx +19 -19
  42. package/src/components/resizable-splitter.tsx +128 -128
  43. package/src/components/select-angle-component.tsx +127 -127
  44. package/src/components/select-with-title.tsx +37 -37
  45. package/src/components/slide-tab-component.tsx +144 -149
  46. package/src/components/spinner.tsx +106 -100
  47. package/src/components/stars-component.tsx +66 -66
  48. package/src/components/svg.tsx +24 -24
  49. package/src/components/tabs.tsx +279 -279
  50. package/src/components/text-glow.tsx +37 -37
  51. package/src/components/text-scale.tsx +42 -42
  52. package/src/components/text-wave.tsx +55 -55
  53. package/src/components/theme-selector.tsx +28 -28
  54. package/src/components/toggle-base.tsx +285 -269
  55. package/src/components/toggle-switch.tsx +160 -160
  56. package/src/frames/index.ts +3 -3
  57. package/src/frames/responsive-frame.tsx +83 -83
  58. package/src/frames/slider-frame.tsx +111 -111
  59. package/src/frames/top-frame.tsx +30 -30
  60. package/src/index.ts +5 -5
  61. package/src/lib/back-action-helper.ts +54 -54
  62. package/src/lib/base62.ts +23 -23
  63. package/src/lib/blob-utils.ts +23 -23
  64. package/src/lib/calculate-text-width.ts +13 -13
  65. package/src/lib/date-utils.ts +317 -317
  66. package/src/lib/deep-merge.ts +37 -37
  67. package/src/lib/document-ready.ts +34 -34
  68. package/src/lib/dom-utils.ts +32 -32
  69. package/src/lib/download-file.ts +118 -118
  70. package/src/lib/download-link.ts +12 -12
  71. package/src/lib/download-stream.ts +19 -19
  72. package/src/lib/drag-util.ts +118 -118
  73. package/src/lib/dynamical-load.ts +134 -134
  74. package/src/lib/encode-html.ts +27 -27
  75. package/src/lib/find-parent-tag.ts +8 -8
  76. package/src/lib/format-bytes.ts +11 -11
  77. package/src/lib/index.ts +24 -24
  78. package/src/lib/lite-dom.ts +225 -225
  79. package/src/lib/message-hub.ts +103 -104
  80. package/src/lib/observable.ts +188 -188
  81. package/src/lib/path-utils.ts +42 -42
  82. package/src/lib/promise-timeout.ts +1 -1
  83. package/src/lib/simple-storage.ts +40 -40
  84. package/src/lib/stop-propagation.ts +7 -7
  85. package/src/lib/upload-file.ts +101 -101
  86. package/src/styles/base-themes.ts +17 -17
  87. package/src/styles/dark-themes.ts +99 -99
  88. package/src/styles/index.ts +5 -5
  89. package/src/styles/light-themes.ts +106 -106
  90. package/src/styles/media-query.ts +93 -93
  91. package/src/styles/shared-themes.ts +57 -57
  92. package/tsconfig.json +113 -113
@@ -1,37 +1,37 @@
1
- /**
2
- * Simple object check.
3
- * @param item
4
- * @returns {boolean}
5
- */
6
- const needMerge = (item: any) => {
7
- return item && typeof item === 'object' && !Array.isArray(item);
8
- };
9
-
10
- /**
11
- * Deep merge two objects.
12
- * target must be a object, and array will be replaced
13
- * @param target
14
- * @param ...sources
15
- */
16
- export const deepMerge = (target: any, ...sources: any[]): any => {
17
- if (!sources.length) return target;
18
- const source = sources.shift();
19
-
20
- if (needMerge(target) && needMerge(source)) {
21
- for (const key in source) {
22
- if (needMerge(source[key])) {
23
- if (!target[key]) Object.assign(target, { [key]: {} });
24
- deepMerge(target[key], source[key]);
25
- } else {
26
- Object.assign(target, { [key]: source[key] });
27
- }
28
- }
29
- }
30
-
31
- return deepMerge(target, ...sources);
32
- };
33
-
34
- // Clone data object only, also defined in core.ts
35
- export const cloneJson = (json: any) => {
36
- return JSON.parse(JSON.stringify(json));
37
- };
1
+ /**
2
+ * Simple object check.
3
+ * @param item
4
+ * @returns {boolean}
5
+ */
6
+ const needMerge = (item: any) => {
7
+ return item && typeof item === 'object' && !Array.isArray(item);
8
+ };
9
+
10
+ /**
11
+ * Deep merge two objects.
12
+ * target must be a object, and array will be replaced
13
+ * @param target
14
+ * @param ...sources
15
+ */
16
+ export const deepMerge = (target: any, ...sources: any[]): any => {
17
+ if (!sources.length) return target;
18
+ const source = sources.shift();
19
+
20
+ if (needMerge(target) && needMerge(source)) {
21
+ for (const key in source) {
22
+ if (needMerge(source[key])) {
23
+ if (!target[key]) Object.assign(target, { [key]: {} });
24
+ deepMerge(target[key], source[key]);
25
+ } else {
26
+ Object.assign(target, { [key]: source[key] });
27
+ }
28
+ }
29
+ }
30
+
31
+ return deepMerge(target, ...sources);
32
+ };
33
+
34
+ // Clone data object only, also defined in core.ts
35
+ export const cloneJson = (json: any) => {
36
+ return JSON.parse(JSON.stringify(json));
37
+ };
@@ -1,34 +1,34 @@
1
- /*
2
- * for my-apps
3
- */
4
- export class DocumentReady {
5
- constructor() {}
6
-
7
- // code is from https://code.jquery.com/jquery-1.12.4.js
8
- // for document only (not for elements)
9
- ready(fn: Function): void {
10
- if (document.readyState === 'complete') {
11
- setTimeout(fn, 0);
12
- } else {
13
- // The ready event handler and self cleanup method
14
- const completed = function () {
15
- if (document.readyState === 'complete') {
16
- document.removeEventListener('DOMContentLoaded', completed);
17
- window.removeEventListener('load', completed);
18
- setTimeout(fn, 0);
19
- }
20
- };
21
-
22
- document.addEventListener('DOMContentLoaded', completed);
23
- window.addEventListener('load', completed);
24
- }
25
- }
26
-
27
- readyPromise(): Promise<void> {
28
- return new Promise((resolve, reject) => {
29
- this.ready(() => {
30
- resolve();
31
- });
32
- });
33
- }
34
- }
1
+ /*
2
+ * for my-apps
3
+ */
4
+ export class DocumentReady {
5
+ constructor() {}
6
+
7
+ // code is from https://code.jquery.com/jquery-1.12.4.js
8
+ // for document only (not for elements)
9
+ ready(fn: Function): void {
10
+ if (document.readyState === 'complete') {
11
+ setTimeout(fn, 0);
12
+ } else {
13
+ // The ready event handler and self cleanup method
14
+ const completed = function () {
15
+ if (document.readyState === 'complete') {
16
+ document.removeEventListener('DOMContentLoaded', completed);
17
+ window.removeEventListener('load', completed);
18
+ setTimeout(fn, 0);
19
+ }
20
+ };
21
+
22
+ document.addEventListener('DOMContentLoaded', completed);
23
+ window.addEventListener('load', completed);
24
+ }
25
+ }
26
+
27
+ readyPromise(): Promise<void> {
28
+ return new Promise((resolve, reject) => {
29
+ this.ready(() => {
30
+ resolve();
31
+ });
32
+ });
33
+ }
34
+ }
@@ -1,32 +1,32 @@
1
- // todo: tree-shaking
2
- export class DomUtils {
3
- public static getValue(cssSelector: string) {
4
- return (document.querySelector(cssSelector) as HTMLInputElement)?.value;
5
- }
6
-
7
- public static setValue(cssSelector: string, value: string) {
8
- const dom = document.querySelector(cssSelector) as HTMLInputElement;
9
- if (dom) dom.value = value;
10
- }
11
-
12
- public static getChecked(cssSelector: string) {
13
- return (document.querySelector(cssSelector) as HTMLInputElement)?.checked;
14
- }
15
-
16
- public static setChecked(cssSelector: string, checked: boolean) {
17
- const dom = document.querySelector(cssSelector) as HTMLInputElement;
18
- if (dom) dom.checked = checked;
19
- }
20
-
21
- public static joinValues(values: (string | undefined)[], joinChar = ' ') {
22
- return values.filter(Boolean).join(joinChar);
23
- }
24
-
25
- public static byId(id: string) {
26
- return document.querySelector(`#${id}`);
27
- }
28
-
29
- public static bySelector(selector: string) {
30
- return document.querySelector(selector);
31
- }
32
- }
1
+ // todo: tree-shaking
2
+ export class DomUtils {
3
+ public static getValue(cssSelector: string) {
4
+ return (document.querySelector(cssSelector) as HTMLInputElement)?.value;
5
+ }
6
+
7
+ public static setValue(cssSelector: string, value: string) {
8
+ const dom = document.querySelector(cssSelector) as HTMLInputElement;
9
+ if (dom) dom.value = value;
10
+ }
11
+
12
+ public static getChecked(cssSelector: string) {
13
+ return (document.querySelector(cssSelector) as HTMLInputElement)?.checked;
14
+ }
15
+
16
+ public static setChecked(cssSelector: string, checked: boolean) {
17
+ const dom = document.querySelector(cssSelector) as HTMLInputElement;
18
+ if (dom) dom.checked = checked;
19
+ }
20
+
21
+ public static joinValues(values: (string | undefined)[], joinChar = ' ') {
22
+ return values.filter(Boolean).join(joinChar);
23
+ }
24
+
25
+ public static byId(id: string) {
26
+ return document.querySelector(`#${id}`);
27
+ }
28
+
29
+ public static bySelector(selector: string) {
30
+ return document.querySelector(selector);
31
+ }
32
+ }
@@ -1,118 +1,118 @@
1
- import { NotificationColor, NotificationMessage } from 'lupine.components';
2
- import { getRenderPageProps } from 'lupine.web';
3
-
4
- const _saveChunkSize = {
5
- downloadSize: 1024 * 200,
6
- };
7
- export const setDownloadChunkSize = (chunkSize: number) => {
8
- _saveChunkSize.downloadSize = chunkSize;
9
- };
10
- export const getDownloadChunkSize = () => {
11
- return _saveChunkSize.downloadSize;
12
- };
13
-
14
- // should return { chunkNumber: number }
15
- export const downloadFileChunk = async (
16
- downloadUrl: string,
17
- rangeStart: number,
18
- rangeLength: number,
19
- retryCount = 3,
20
- retryMessage = '' // can have ${tryCount}
21
- ) => {
22
- let url = downloadUrl + (downloadUrl.indexOf('?') === -1 ? '?' : '');
23
- url += `&start=${rangeStart.toString()}`;
24
- url += `&length=${rangeLength.toString()}`;
25
- let tryCount = 0;
26
- while (tryCount < retryCount) {
27
- try {
28
- const rawData = (await getRenderPageProps().renderPageFunctions.fetchData(
29
- url,
30
- undefined,
31
- true,
32
- true
33
- )) as Response;
34
- // console.log('downloadFileChunk', rawData);
35
- const fileSize = rawData.headers.get('file-size');
36
- const partSize = rawData.headers.get('part-size');
37
- if (!fileSize || !partSize) {
38
- console.log(`downloadFileChunk error`, rawData);
39
- return null;
40
- }
41
- return {
42
- fileSize: parseInt(fileSize, 10),
43
- partSize: parseInt(partSize, 10),
44
- arrayBuffer: await rawData.arrayBuffer(),
45
- };
46
- } catch (error) {
47
- console.log(`downloadFileChunk error, try: ${tryCount}`, error);
48
- }
49
- tryCount++;
50
- if (retryMessage) {
51
- NotificationMessage.sendMessage(
52
- retryMessage.replace('${tryCount}', tryCount.toString()),
53
- NotificationColor.Warning
54
- );
55
- }
56
- }
57
- return null;
58
- };
59
-
60
- export interface DownloadFileProps {
61
- fileSize: number;
62
- partSize: number;
63
- arrayBuffer: ArrayBuffer;
64
- }
65
-
66
- /*
67
- A sample for text result:
68
- const decoder = new TextDecoder('utf-8');
69
- const chunks: string[] = [];
70
- let downloadSize = 0;
71
- const processResponse = (result: DownloadFileProps) => {
72
- if (!result || result.fileSize <= 0 || result.partSize < 0) {
73
- NotificationMessage.sendMessage('加载数据失败', NotificationColor.Error);
74
- return false;
75
- }
76
- const fileSize = result.fileSize;
77
- downloadSize += result.partSize;
78
- progressUpdate?.onProgress?.(Math.round((downloadSize / fileSize) * 100) / 100, downloadSize, fileSize);
79
- chunks.push(decoder.decode(result.arrayBuffer));
80
- return true;
81
- };
82
- */
83
-
84
- export const downloadFile = async (
85
- downloadUrl: string,
86
- processResponse: (result: DownloadFileProps) => boolean | undefined, // true: success, false: failed, undefined: continue
87
- chunkSize = 0,
88
- retryCount = 3,
89
- retryMessage = 'Downloading failed, try: ${tryCount}' // can have ${tryCount}
90
- ) => {
91
- if (chunkSize < 1) {
92
- chunkSize = _saveChunkSize.downloadSize;
93
- }
94
- let downloadSize = 0;
95
- let expectedFileSize: number | null = null;
96
- while (true) {
97
- const start = downloadSize;
98
- const length = chunkSize;
99
- const downloadResult = await downloadFileChunk(downloadUrl, start, length, retryCount, retryMessage);
100
- if (!downloadResult) {
101
- return false;
102
- }
103
- if (expectedFileSize === null) {
104
- expectedFileSize = downloadResult.fileSize;
105
- }
106
- downloadSize += downloadResult.partSize;
107
- // console.log(`downloadSize: ${downloadSize}, downloadFileChunk:`, downloadResult);
108
- const result = processResponse(downloadResult);
109
- if (result !== undefined) {
110
- // success or failed
111
- return result;
112
- }
113
- if (downloadSize >= expectedFileSize) {
114
- break;
115
- }
116
- }
117
- return true;
118
- };
1
+ import { NotificationColor, NotificationMessage } from 'lupine.components';
2
+ import { getRenderPageProps } from 'lupine.web';
3
+
4
+ const _saveChunkSize = {
5
+ downloadSize: 1024 * 200,
6
+ };
7
+ export const setDownloadChunkSize = (chunkSize: number) => {
8
+ _saveChunkSize.downloadSize = chunkSize;
9
+ };
10
+ export const getDownloadChunkSize = () => {
11
+ return _saveChunkSize.downloadSize;
12
+ };
13
+
14
+ // should return { chunkNumber: number }
15
+ export const downloadFileChunk = async (
16
+ downloadUrl: string,
17
+ rangeStart: number,
18
+ rangeLength: number,
19
+ retryCount = 3,
20
+ retryMessage = '' // can have ${tryCount}
21
+ ) => {
22
+ let url = downloadUrl + (downloadUrl.indexOf('?') === -1 ? '?' : '');
23
+ url += `&start=${rangeStart.toString()}`;
24
+ url += `&length=${rangeLength.toString()}`;
25
+ let tryCount = 0;
26
+ while (tryCount < retryCount) {
27
+ try {
28
+ const rawData = (await getRenderPageProps().renderPageFunctions.fetchData(
29
+ url,
30
+ undefined,
31
+ true,
32
+ true
33
+ )) as Response;
34
+ // console.log('downloadFileChunk', rawData);
35
+ const fileSize = rawData.headers.get('file-size');
36
+ const partSize = rawData.headers.get('part-size');
37
+ if (!fileSize || !partSize) {
38
+ console.log(`downloadFileChunk error`, rawData);
39
+ return null;
40
+ }
41
+ return {
42
+ fileSize: parseInt(fileSize, 10),
43
+ partSize: parseInt(partSize, 10),
44
+ arrayBuffer: await rawData.arrayBuffer(),
45
+ };
46
+ } catch (error) {
47
+ console.log(`downloadFileChunk error, try: ${tryCount}`, error);
48
+ }
49
+ tryCount++;
50
+ if (retryMessage) {
51
+ NotificationMessage.sendMessage(
52
+ retryMessage.replace('${tryCount}', tryCount.toString()),
53
+ NotificationColor.Warning
54
+ );
55
+ }
56
+ }
57
+ return null;
58
+ };
59
+
60
+ export interface DownloadFileProps {
61
+ fileSize: number;
62
+ partSize: number;
63
+ arrayBuffer: ArrayBuffer;
64
+ }
65
+
66
+ /*
67
+ A sample for text result:
68
+ const decoder = new TextDecoder('utf-8');
69
+ const chunks: string[] = [];
70
+ let downloadSize = 0;
71
+ const processResponse = (result: DownloadFileProps) => {
72
+ if (!result || result.fileSize <= 0 || result.partSize < 0) {
73
+ NotificationMessage.sendMessage('加载数据失败', NotificationColor.Error);
74
+ return false;
75
+ }
76
+ const fileSize = result.fileSize;
77
+ downloadSize += result.partSize;
78
+ progressUpdate?.onProgress?.(Math.round((downloadSize / fileSize) * 100) / 100, downloadSize, fileSize);
79
+ chunks.push(decoder.decode(result.arrayBuffer));
80
+ return true;
81
+ };
82
+ */
83
+
84
+ export const downloadFile = async (
85
+ downloadUrl: string,
86
+ processResponse: (result: DownloadFileProps) => boolean | undefined, // true: success, false: failed, undefined: continue
87
+ chunkSize = 0,
88
+ retryCount = 3,
89
+ retryMessage = 'Downloading failed, try: ${tryCount}' // can have ${tryCount}
90
+ ) => {
91
+ if (chunkSize < 1) {
92
+ chunkSize = _saveChunkSize.downloadSize;
93
+ }
94
+ let downloadSize = 0;
95
+ let expectedFileSize: number | null = null;
96
+ while (true) {
97
+ const start = downloadSize;
98
+ const length = chunkSize;
99
+ const downloadResult = await downloadFileChunk(downloadUrl, start, length, retryCount, retryMessage);
100
+ if (!downloadResult) {
101
+ return false;
102
+ }
103
+ if (expectedFileSize === null) {
104
+ expectedFileSize = downloadResult.fileSize;
105
+ }
106
+ downloadSize += downloadResult.partSize;
107
+ // console.log(`downloadSize: ${downloadSize}, downloadFileChunk:`, downloadResult);
108
+ const result = processResponse(downloadResult);
109
+ if (result !== undefined) {
110
+ // success or failed
111
+ return result;
112
+ }
113
+ if (downloadSize >= expectedFileSize) {
114
+ break;
115
+ }
116
+ }
117
+ return true;
118
+ };
@@ -1,12 +1,12 @@
1
- export const downloadLink = (link: string, filename?: string) => {
2
- const dom = document.createElement('a');
3
- dom.setAttribute('href', link);
4
- dom.setAttribute('download', filename || 'true');
5
- dom.style.display = 'none';
6
- document.body.appendChild(dom);
7
- dom.click();
8
- setTimeout(() => {
9
- document.body.removeChild(dom);
10
- }, 3000);
11
- return dom;
12
- };
1
+ export const downloadLink = (link: string, filename?: string) => {
2
+ const dom = document.createElement('a');
3
+ dom.setAttribute('href', link);
4
+ dom.setAttribute('download', filename || 'true');
5
+ dom.style.display = 'none';
6
+ document.body.appendChild(dom);
7
+ dom.click();
8
+ setTimeout(() => {
9
+ document.body.removeChild(dom);
10
+ }, 3000);
11
+ return dom;
12
+ };
@@ -1,19 +1,19 @@
1
- /*
2
- const response = await fetch('/api/admin/release/check-log', { ... });
3
- const blob = await response.blob();
4
- downloadStream(blob, filename);
5
- */
6
- export const downloadStream = (blob: Blob, filename?: string) => {
7
- const blobUrl = URL.createObjectURL(blob);
8
- const dom = document.createElement('a');
9
- dom.setAttribute('href', blobUrl);
10
- dom.setAttribute('download', filename || 'true');
11
- dom.style.display = 'none';
12
- document.body.appendChild(dom);
13
- dom.click();
14
- setTimeout(() => {
15
- document.body.removeChild(dom);
16
- URL.revokeObjectURL(blobUrl);
17
- }, 3000);
18
- return dom;
19
- };
1
+ /*
2
+ const response = await fetch('/api/admin/release/check-log', { ... });
3
+ const blob = await response.blob();
4
+ downloadStream(blob, filename);
5
+ */
6
+ export const downloadStream = (blob: Blob, filename?: string) => {
7
+ const blobUrl = URL.createObjectURL(blob);
8
+ const dom = document.createElement('a');
9
+ dom.setAttribute('href', blobUrl);
10
+ dom.setAttribute('download', filename || 'true');
11
+ dom.style.display = 'none';
12
+ document.body.appendChild(dom);
13
+ dom.click();
14
+ setTimeout(() => {
15
+ document.body.removeChild(dom);
16
+ URL.revokeObjectURL(blobUrl);
17
+ }, 3000);
18
+ return dom;
19
+ };