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,233 +1,233 @@
1
- import { CssProps, RefProps, VNode, mountInnerComponent } from 'lupine.web';
2
- import { stopPropagation } from '../lib';
3
-
4
- export type FloatWindowCloseProps = () => void;
5
-
6
- export type FloatWindowShowProps = {
7
- title: string;
8
- children: VNode<any>;
9
- buttons?: string[];
10
- contentMaxHeight?: string;
11
- contentMinWidth?: string;
12
- noMoving?: boolean;
13
- noModal?: boolean;
14
- closeEvent?: () => void;
15
- handleClicked: (index: number, close: FloatWindowCloseProps) => void;
16
- closeWhenClickOutside?: boolean; // default false
17
- zIndex?: string;
18
- contentOverflowY?: string;
19
- };
20
-
21
- // because it's over a mask, so it can use primary colors
22
- export class FloatWindow {
23
- static hostNode: HTMLElement;
24
-
25
- private static initialized = false;
26
- private static pressed = false;
27
- private static startX = 0;
28
- private static startY = 0;
29
- private static startTop = 0;
30
- private static startLeft = 0;
31
-
32
- static init() {
33
- window.addEventListener('mousemove', FloatWindow.onMousemove.bind(FloatWindow), false);
34
- document.documentElement.addEventListener('mouseup', FloatWindow.onMouseup.bind(FloatWindow), false);
35
- }
36
-
37
- static async show({
38
- title,
39
- children,
40
- contentMaxHeight,
41
- contentMinWidth,
42
- buttons,
43
- noMoving = false,
44
- noModal = false,
45
- closeEvent,
46
- handleClicked,
47
- closeWhenClickOutside = false,
48
- zIndex,
49
- contentOverflowY = 'auto', // set to unset for having popup menu inside
50
- }: FloatWindowShowProps): Promise<FloatWindowCloseProps> {
51
- const onClickContainer = (event: any) => {
52
- if (closeWhenClickOutside !== false && event.target.classList.contains('fwin-box')) {
53
- handleClose();
54
- }
55
- };
56
- const handleClose = () => {
57
- closeEvent?.();
58
- ref.current.classList.add('transition');
59
- ref.current.classList.remove('animation');
60
- setTimeout(() => {
61
- base.remove();
62
- }, 300);
63
- };
64
-
65
- const base = document.createElement('div');
66
- const onMousedown = (event: any) => {
67
- if (noMoving) return;
68
-
69
- if (!this.initialized) {
70
- this.initialized = true;
71
- this.init();
72
- }
73
-
74
- FloatWindow.hostNode = ref.current;
75
- FloatWindow.onMousedown.bind(FloatWindow)(event);
76
- };
77
-
78
- const newButtons = !buttons || buttons.length === 0 ? ['OK', 'Cancel'] : buttons;
79
- const onClickButtons = (index: number) => {
80
- handleClicked(index, handleClose);
81
- };
82
-
83
- const ref: RefProps = {
84
- onLoad: async () => {
85
- ref.current.classList.add('transition');
86
- setTimeout(() => {
87
- ref.current.classList.add('animation');
88
- }, 1);
89
- setTimeout(() => {
90
- // don't need transition for moving
91
- ref.current.classList.remove('transition');
92
- }, 300);
93
- },
94
- };
95
- const cssContainer: CssProps = {
96
- position: noModal ? '' : 'fixed',
97
- top: 0,
98
- left: 0,
99
- width: '100%',
100
- height: '100%',
101
- backgroundColor: noModal ? '' : 'var(--cover-mask-bg-color)',
102
- '.fwin-body': {
103
- position: 'fixed',
104
- top: '50%',
105
- left: '50%',
106
- transform: 'translate(-50%, -50%) scale(0.1)',
107
- color: 'var(--primary-color)',
108
- backgroundColor: 'var(--cover-bg-color)', //'#fefefe',
109
- border: 'var(--primary-border)', //'1px solid #888',
110
- borderRadius: '6px',
111
- minWidth: contentMinWidth ? contentMinWidth : '',
112
- maxWidth: '90%',
113
- boxShadow: 'var(--cover-box-shadow)', //'#0000004c 0px 19px 38px, #00000038 0px 15px 12px',
114
- opacity: 0,
115
- // zIndex: 'var(--layer-float-window)',
116
- '&.transition': {
117
- transition: 'all 0.3s',
118
- },
119
- '&.animation': {
120
- transform: 'translate(-50%, -50%) scale(1)',
121
- opacity: 1,
122
- },
123
- '&.animation-close': {
124
- transition: 'all 0.3s',
125
- transform: 'translate(-50%, -50%) scale(0)',
126
- opacity: 0,
127
- },
128
- '.fwin-title': {
129
- padding: '10px 15px 5px',
130
- borderBottom: 'var(--primary-border)', //'1px solid #e9ecef',
131
- '.fwin-close': {
132
- color: '#aaaaaa',
133
- float: 'right',
134
- fontSize: '26px',
135
- fontWeight: 'bold',
136
- cursor: 'pointer',
137
- marginTop: '-8px',
138
- marginRight: '-10px',
139
- },
140
- '.fwin-close:hover': {
141
- transition: 'all 300ms ease',
142
- color: '#555555',
143
- },
144
- },
145
- '.fwin-content': {
146
- padding: '15px',
147
- maxHeight: contentMaxHeight ? `min(${contentMaxHeight}, calc(100% - 100px))` : 'calc(100% - 100px)',
148
- overflowY: contentOverflowY,
149
- },
150
- '.fwin-bottom': {
151
- display: 'flex',
152
- padding: '5px 15px',
153
- borderTop: 'var(--primary-border)', //'1px solid #e9ecef',
154
- justifyContent: 'end',
155
- '>div': {
156
- marginLeft: '5px',
157
- },
158
- },
159
- },
160
- };
161
- const component = (
162
- <div css={cssContainer} class='fwin-box' onClick={onClickContainer}>
163
- <div ref={ref} class='fwin-body' onMouseDown={onMousedown}>
164
- <div class='fwin-title'>
165
- {title}
166
- <span class='fwin-close' onClick={handleClose}>
167
- ×
168
- </span>
169
- </div>
170
- <div class='fwin-content'>{children}</div>
171
- <div class='fwin-bottom'>
172
- {newButtons.map((i, index) => (
173
- <button
174
- class='button-base button-s mr-m'
175
- onClick={() => {
176
- onClickButtons(index);
177
- }}
178
- >
179
- {i}
180
- </button>
181
- ))}
182
- </div>
183
- </div>
184
- </div>
185
- );
186
- base.style.position = 'fixed';
187
- base.style.zIndex = zIndex || 'var(--layer-float-window)';
188
- document.body.appendChild(base);
189
- await mountInnerComponent(base, component);
190
- return handleClose;
191
- }
192
-
193
- static onMousedown(event: any) {
194
- if (event.buttons !== 1 || event.button !== 0) return;
195
- if (event.srcElement.className !== 'fwin-title') return;
196
-
197
- this.pressed = true;
198
- this.startX = event.clientX;
199
- this.startY = event.clientY;
200
- const nodeStyle = document.defaultView!.getComputedStyle(this.hostNode);
201
- this.startTop = parseInt(nodeStyle['top'], 10);
202
- this.startLeft = parseInt(nodeStyle['left'], 10);
203
- }
204
-
205
- static onMousemove(event: any) {
206
- if (!this.pressed || event.buttons !== 1 || event.button !== 0) {
207
- return;
208
- }
209
-
210
- // prevent text/element selection when drag
211
- stopPropagation(event);
212
- if (
213
- event.clientX < 0 ||
214
- event.clientY < 0 ||
215
- event.clientX > window.innerWidth ||
216
- event.clientY > window.innerHeight
217
- ) {
218
- return;
219
- }
220
-
221
- let movedX = this.startLeft + (event.clientX - this.startX);
222
- let movedY = this.startTop + (event.clientY - this.startY);
223
- if (movedY <= 0) movedY = 0;
224
- if (movedX <= 0) movedX = 0;
225
-
226
- this.hostNode.style.top = movedY + 'px';
227
- this.hostNode.style.left = movedX + 'px';
228
- }
229
-
230
- static onMouseup() {
231
- if (this.pressed) this.pressed = false;
232
- }
233
- }
1
+ import { CssProps, RefProps, VNode, mountInnerComponent } from 'lupine.web';
2
+ import { stopPropagation } from '../lib';
3
+
4
+ export type FloatWindowCloseProps = () => void;
5
+
6
+ export type FloatWindowShowProps = {
7
+ title: string;
8
+ children: VNode<any>;
9
+ buttons?: string[];
10
+ contentMaxHeight?: string;
11
+ contentMinWidth?: string;
12
+ noMoving?: boolean;
13
+ noModal?: boolean;
14
+ closeEvent?: () => void;
15
+ handleClicked: (index: number, close: FloatWindowCloseProps) => void;
16
+ closeWhenClickOutside?: boolean; // default false
17
+ zIndex?: string;
18
+ contentOverflowY?: string;
19
+ };
20
+
21
+ // because it's over a mask, so it can use primary colors
22
+ export class FloatWindow {
23
+ static hostNode: HTMLElement;
24
+
25
+ private static initialized = false;
26
+ private static pressed = false;
27
+ private static startX = 0;
28
+ private static startY = 0;
29
+ private static startTop = 0;
30
+ private static startLeft = 0;
31
+
32
+ static init() {
33
+ window.addEventListener('mousemove', FloatWindow.onMousemove.bind(FloatWindow), false);
34
+ document.documentElement.addEventListener('mouseup', FloatWindow.onMouseup.bind(FloatWindow), false);
35
+ }
36
+
37
+ static async show({
38
+ title,
39
+ children,
40
+ contentMaxHeight,
41
+ contentMinWidth,
42
+ buttons,
43
+ noMoving = false,
44
+ noModal = false,
45
+ closeEvent,
46
+ handleClicked,
47
+ closeWhenClickOutside = false,
48
+ zIndex,
49
+ contentOverflowY = 'auto', // set to unset for having popup menu inside
50
+ }: FloatWindowShowProps): Promise<FloatWindowCloseProps> {
51
+ const onClickContainer = (event: any) => {
52
+ if (closeWhenClickOutside !== false && event.target.classList.contains('fwin-box')) {
53
+ handleClose();
54
+ }
55
+ };
56
+ const handleClose = () => {
57
+ closeEvent?.();
58
+ ref.current.classList.add('transition');
59
+ ref.current.classList.remove('animation');
60
+ setTimeout(() => {
61
+ base.remove();
62
+ }, 300);
63
+ };
64
+
65
+ const base = document.createElement('div');
66
+ const onMousedown = (event: any) => {
67
+ if (noMoving) return;
68
+
69
+ if (!this.initialized) {
70
+ this.initialized = true;
71
+ this.init();
72
+ }
73
+
74
+ FloatWindow.hostNode = ref.current;
75
+ FloatWindow.onMousedown.bind(FloatWindow)(event);
76
+ };
77
+
78
+ const newButtons = !buttons || buttons.length === 0 ? ['OK', 'Cancel'] : buttons;
79
+ const onClickButtons = (index: number) => {
80
+ handleClicked(index, handleClose);
81
+ };
82
+
83
+ const ref: RefProps = {
84
+ onLoad: async () => {
85
+ ref.current.classList.add('transition');
86
+ setTimeout(() => {
87
+ ref.current.classList.add('animation');
88
+ }, 1);
89
+ setTimeout(() => {
90
+ // don't need transition for moving
91
+ ref.current.classList.remove('transition');
92
+ }, 300);
93
+ },
94
+ };
95
+ const cssContainer: CssProps = {
96
+ position: noModal ? '' : 'fixed',
97
+ top: 0,
98
+ left: 0,
99
+ width: '100%',
100
+ height: '100%',
101
+ backgroundColor: noModal ? '' : 'var(--cover-mask-bg-color)',
102
+ '.fwin-body': {
103
+ position: 'fixed',
104
+ top: '50%',
105
+ left: '50%',
106
+ transform: 'translate(-50%, -50%) scale(0.1)',
107
+ color: 'var(--primary-color)',
108
+ backgroundColor: 'var(--cover-bg-color)', //'#fefefe',
109
+ border: 'var(--primary-border)', //'1px solid #888',
110
+ borderRadius: '6px',
111
+ minWidth: contentMinWidth ? contentMinWidth : '',
112
+ maxWidth: '90%',
113
+ boxShadow: 'var(--cover-box-shadow)', //'#0000004c 0px 19px 38px, #00000038 0px 15px 12px',
114
+ opacity: 0,
115
+ // zIndex: 'var(--layer-float-window)',
116
+ '&.transition': {
117
+ transition: 'all 0.3s',
118
+ },
119
+ '&.animation': {
120
+ transform: 'translate(-50%, -50%) scale(1)',
121
+ opacity: 1,
122
+ },
123
+ '&.animation-close': {
124
+ transition: 'all 0.3s',
125
+ transform: 'translate(-50%, -50%) scale(0)',
126
+ opacity: 0,
127
+ },
128
+ '.fwin-title': {
129
+ padding: '10px 15px 5px',
130
+ borderBottom: 'var(--primary-border)', //'1px solid #e9ecef',
131
+ '.fwin-close': {
132
+ color: '#aaaaaa',
133
+ float: 'right',
134
+ fontSize: '26px',
135
+ fontWeight: 'bold',
136
+ cursor: 'pointer',
137
+ marginTop: '-8px',
138
+ marginRight: '-10px',
139
+ },
140
+ '.fwin-close:hover': {
141
+ transition: 'all 300ms ease',
142
+ color: '#555555',
143
+ },
144
+ },
145
+ '.fwin-content': {
146
+ padding: '15px',
147
+ maxHeight: contentMaxHeight ? `min(${contentMaxHeight}, calc(100% - 100px))` : 'calc(100% - 100px)',
148
+ overflowY: contentOverflowY,
149
+ },
150
+ '.fwin-bottom': {
151
+ display: 'flex',
152
+ padding: '5px 15px',
153
+ borderTop: 'var(--primary-border)', //'1px solid #e9ecef',
154
+ justifyContent: 'end',
155
+ '>div': {
156
+ marginLeft: '5px',
157
+ },
158
+ },
159
+ },
160
+ };
161
+ const component = (
162
+ <div css={cssContainer} class='fwin-box' onClick={onClickContainer}>
163
+ <div ref={ref} class='fwin-body' onMouseDown={onMousedown}>
164
+ <div class='fwin-title'>
165
+ {title}
166
+ <span class='fwin-close' onClick={handleClose}>
167
+ ×
168
+ </span>
169
+ </div>
170
+ <div class='fwin-content'>{children}</div>
171
+ <div class='fwin-bottom'>
172
+ {newButtons.map((i, index) => (
173
+ <button
174
+ class='button-base button-s mr-m'
175
+ onClick={() => {
176
+ onClickButtons(index);
177
+ }}
178
+ >
179
+ {i}
180
+ </button>
181
+ ))}
182
+ </div>
183
+ </div>
184
+ </div>
185
+ );
186
+ base.style.position = 'fixed';
187
+ base.style.zIndex = zIndex || 'var(--layer-float-window)';
188
+ document.body.appendChild(base);
189
+ await mountInnerComponent(base, component);
190
+ return handleClose;
191
+ }
192
+
193
+ static onMousedown(event: any) {
194
+ if (event.buttons !== 1 || event.button !== 0) return;
195
+ if (event.srcElement.className !== 'fwin-title') return;
196
+
197
+ this.pressed = true;
198
+ this.startX = event.clientX;
199
+ this.startY = event.clientY;
200
+ const nodeStyle = document.defaultView!.getComputedStyle(this.hostNode);
201
+ this.startTop = parseInt(nodeStyle['top'], 10);
202
+ this.startLeft = parseInt(nodeStyle['left'], 10);
203
+ }
204
+
205
+ static onMousemove(event: any) {
206
+ if (!this.pressed || event.buttons !== 1 || event.button !== 0) {
207
+ return;
208
+ }
209
+
210
+ // prevent text/element selection when drag
211
+ stopPropagation(event);
212
+ if (
213
+ event.clientX < 0 ||
214
+ event.clientY < 0 ||
215
+ event.clientX > window.innerWidth ||
216
+ event.clientY > window.innerHeight
217
+ ) {
218
+ return;
219
+ }
220
+
221
+ let movedX = this.startLeft + (event.clientX - this.startX);
222
+ let movedY = this.startTop + (event.clientY - this.startY);
223
+ if (movedY <= 0) movedY = 0;
224
+ if (movedX <= 0) movedX = 0;
225
+
226
+ this.hostNode.style.top = movedY + 'px';
227
+ this.hostNode.style.left = movedX + 'px';
228
+ }
229
+
230
+ static onMouseup() {
231
+ if (this.pressed) this.pressed = false;
232
+ }
233
+ }
@@ -1,18 +1,18 @@
1
- export const Grid = ({ gridOption }: { gridOption: any }) => {
2
- const cssContainer: any = {
3
- display: 'grid',
4
- ...gridOption.options,
5
- };
6
- const cells: any = [];
7
- gridOption.cells.forEach((cell: any, index: number) => {
8
- const name = cell.name || 'cell' + index;
9
- cssContainer[`.${name}`] = cell.option;
10
- cells.push(<div class={name}>{cell.component}</div>);
11
- });
12
- const className = 'grid-box' + (gridOption.className ? ` ${gridOption.className}` : '');
13
- return (
14
- <div css={cssContainer} class={className}>
15
- {cells}
16
- </div>
17
- );
18
- };
1
+ export const Grid = ({ gridOption }: { gridOption: any }) => {
2
+ const cssContainer: any = {
3
+ display: 'grid',
4
+ ...gridOption.options,
5
+ };
6
+ const cells: any = [];
7
+ gridOption.cells.forEach((cell: any, index: number) => {
8
+ const name = cell.name || 'cell' + index;
9
+ cssContainer[`.${name}`] = cell.option;
10
+ cells.push(<div class={name}>{cell.component}</div>);
11
+ });
12
+ const className = 'grid-box' + (gridOption.className ? ` ${gridOption.className}` : '');
13
+ return (
14
+ <div css={cssContainer} class={className}>
15
+ {cells}
16
+ </div>
17
+ );
18
+ };
@@ -1,41 +1,41 @@
1
- import { RefProps, VNode } from 'lupine.web';
2
-
3
- // load async html
4
- /*
5
- <HtmlLoad
6
- html={async () => {
7
- return <Footer title={await WebConfig.get('footer', `XXX`)}></Footer>;
8
- }}
9
- ></HtmlLoad>
10
- */
11
- export type HtmlLoadHookProps = {
12
- getRef?: () => RefProps;
13
- render?: (html: string | VNode<any>) => void;
14
- };
15
- export type HtmlLoadProps = {
16
- html: () => Promise<VNode<any>>;
17
- initialHtml?: string | VNode<any>;
18
- hook?: HtmlLoadHookProps;
19
- };
20
- export const HtmlLoad = (props: HtmlLoadProps) => {
21
- const ref: RefProps = {
22
- onLoad: async (el: Element) => {
23
- const dom = await props.html();
24
- await ref.mountInnerComponent!(dom);
25
- },
26
- };
27
- if (props.hook) {
28
- props.hook.getRef = () => ref;
29
- props.hook.render = (html: string | VNode<any>) => {
30
- ref.mountInnerComponent!(html);
31
- };
32
- }
33
- return {
34
- type: 'Fragment',
35
- props: {
36
- ref: ref,
37
- children: props.initialHtml || '',
38
- },
39
- html: [],
40
- };
41
- };
1
+ import { RefProps, VNode } from 'lupine.web';
2
+
3
+ // load async html
4
+ /*
5
+ <HtmlLoad
6
+ html={async () => {
7
+ return <Footer title={await WebConfig.get('footer', `XXX`)}></Footer>;
8
+ }}
9
+ ></HtmlLoad>
10
+ */
11
+ export type HtmlLoadHookProps = {
12
+ getRef?: () => RefProps;
13
+ render?: (html: string | VNode<any>) => void;
14
+ };
15
+ export type HtmlLoadProps = {
16
+ html: () => Promise<VNode<any>>;
17
+ initialHtml?: string | VNode<any>;
18
+ hook?: HtmlLoadHookProps;
19
+ };
20
+ export const HtmlLoad = (props: HtmlLoadProps) => {
21
+ const ref: RefProps = {
22
+ onLoad: async (el: Element) => {
23
+ const dom = await props.html();
24
+ await ref.mountInnerComponent!(dom);
25
+ },
26
+ };
27
+ if (props.hook) {
28
+ props.hook.getRef = () => ref;
29
+ props.hook.render = (html: string | VNode<any>) => {
30
+ ref.mountInnerComponent!(html);
31
+ };
32
+ }
33
+ return {
34
+ type: 'Fragment',
35
+ props: {
36
+ ref: ref,
37
+ children: props.initialHtml || '',
38
+ },
39
+ html: [],
40
+ };
41
+ };