@windwalker-io/unicorn-next 0.1.0

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 (175) hide show
  1. package/.editorconfig +18 -0
  2. package/.gulp.json +7 -0
  3. package/bin/release.mjs +47 -0
  4. package/dist/chunks/_arrayPush.js +168 -0
  5. package/dist/chunks/_arrayPush.js.map +1 -0
  6. package/dist/chunks/_baseRest.js +73 -0
  7. package/dist/chunks/_baseRest.js.map +1 -0
  8. package/dist/chunks/_commonjsHelpers.js +7 -0
  9. package/dist/chunks/_commonjsHelpers.js.map +1 -0
  10. package/dist/chunks/_getPrototype.js +130 -0
  11. package/dist/chunks/_getPrototype.js.map +1 -0
  12. package/dist/chunks/button-radio.js +147 -0
  13. package/dist/chunks/button-radio.js.map +1 -0
  14. package/dist/chunks/checkboxes-multi-select.js +44 -0
  15. package/dist/chunks/checkboxes-multi-select.js.map +1 -0
  16. package/dist/chunks/cloneDeep.js +287 -0
  17. package/dist/chunks/cloneDeep.js.map +1 -0
  18. package/dist/chunks/cropper.min.js +5 -0
  19. package/dist/chunks/cropper.min.js.map +1 -0
  20. package/dist/chunks/field-cascade-select.js +256 -0
  21. package/dist/chunks/field-cascade-select.js.map +1 -0
  22. package/dist/chunks/field-file-drag.js +218 -0
  23. package/dist/chunks/field-file-drag.js.map +1 -0
  24. package/dist/chunks/field-flatpickr.js +893 -0
  25. package/dist/chunks/field-flatpickr.js.map +1 -0
  26. package/dist/chunks/field-modal-select.js +403 -0
  27. package/dist/chunks/field-modal-select.js.map +1 -0
  28. package/dist/chunks/field-modal-tree.js +790 -0
  29. package/dist/chunks/field-modal-tree.js.map +1 -0
  30. package/dist/chunks/field-multi-uploader.js +256 -0
  31. package/dist/chunks/field-multi-uploader.js.map +1 -0
  32. package/dist/chunks/field-repeatable.js +132 -0
  33. package/dist/chunks/field-repeatable.js.map +1 -0
  34. package/dist/chunks/field-single-image-drag.js +338 -0
  35. package/dist/chunks/field-single-image-drag.js.map +1 -0
  36. package/dist/chunks/form.js +154 -0
  37. package/dist/chunks/form.js.map +1 -0
  38. package/dist/chunks/grid.js +345 -0
  39. package/dist/chunks/grid.js.map +1 -0
  40. package/dist/chunks/http-client.js +229 -0
  41. package/dist/chunks/http-client.js.map +1 -0
  42. package/dist/chunks/iframe-modal.js +124 -0
  43. package/dist/chunks/iframe-modal.js.map +1 -0
  44. package/dist/chunks/index.js +309 -0
  45. package/dist/chunks/index.js.map +1 -0
  46. package/dist/chunks/isArguments.js +146 -0
  47. package/dist/chunks/isArguments.js.map +1 -0
  48. package/dist/chunks/keep-tab.js +101 -0
  49. package/dist/chunks/keep-tab.js.map +1 -0
  50. package/dist/chunks/legacy.js +210 -0
  51. package/dist/chunks/legacy.js.map +1 -0
  52. package/dist/chunks/list-dependent.js +231 -0
  53. package/dist/chunks/list-dependent.js.map +1 -0
  54. package/dist/chunks/s3-multipart-uploader.js +172 -0
  55. package/dist/chunks/s3-multipart-uploader.js.map +1 -0
  56. package/dist/chunks/s3-uploader.js +136 -0
  57. package/dist/chunks/s3-uploader.js.map +1 -0
  58. package/dist/chunks/show-on.js +237 -0
  59. package/dist/chunks/show-on.js.map +1 -0
  60. package/dist/chunks/tinymce.js +196 -0
  61. package/dist/chunks/tinymce.js.map +1 -0
  62. package/dist/chunks/ui-bootstrap5.js +71 -0
  63. package/dist/chunks/ui-bootstrap5.js.map +1 -0
  64. package/dist/chunks/unicorn.js +2202 -0
  65. package/dist/chunks/unicorn.js.map +1 -0
  66. package/dist/chunks/validation.js +854 -0
  67. package/dist/chunks/validation.js.map +1 -0
  68. package/dist/editor.css +1 -0
  69. package/dist/index.d.ts +1427 -0
  70. package/dist/multi-level-menu.css +1 -0
  71. package/dist/switcher.css +1 -0
  72. package/dist/unicorn-next.css +12 -0
  73. package/dist/unicorn.js +125 -0
  74. package/dist/unicorn.js.map +1 -0
  75. package/fusionfile.mjs +155 -0
  76. package/images/ajax-loader.gif +0 -0
  77. package/images/placeholder/avatar.png +0 -0
  78. package/images/placeholder/image-16x10.png +0 -0
  79. package/images/placeholder/image-16x9.png +0 -0
  80. package/images/placeholder/image-1x1.png +0 -0
  81. package/images/placeholder/image-4x3.png +0 -0
  82. package/package.json +102 -0
  83. package/scss/bootstrap/multi-level-menu.scss +121 -0
  84. package/scss/editor.scss +116 -0
  85. package/scss/field/file-drag.scss +102 -0
  86. package/scss/field/single-image-drag.scss +88 -0
  87. package/scss/field/vue-drag-uploader.scss +160 -0
  88. package/scss/switcher.scss +156 -0
  89. package/src/app.ts +128 -0
  90. package/src/bootstrap/button-radio.ts +208 -0
  91. package/src/bootstrap/keep-tab.ts +155 -0
  92. package/src/composable/index.ts +21 -0
  93. package/src/composable/useCheckboxesMultiSelect.ts +22 -0
  94. package/src/composable/useFieldCascadeSelect.ts +9 -0
  95. package/src/composable/useFieldFileDrag.ts +9 -0
  96. package/src/composable/useFieldFlatpickr.ts +3 -0
  97. package/src/composable/useFieldModalSelect.ts +6 -0
  98. package/src/composable/useFieldModalTree.ts +3 -0
  99. package/src/composable/useFieldMultiUploader.ts +3 -0
  100. package/src/composable/useFieldRepeatable.ts +9 -0
  101. package/src/composable/useFieldSingleImageDrag.ts +5 -0
  102. package/src/composable/useForm.ts +43 -0
  103. package/src/composable/useGrid.ts +57 -0
  104. package/src/composable/useHttp.ts +8 -0
  105. package/src/composable/useIframeModal.ts +9 -0
  106. package/src/composable/useListDependent.ts +26 -0
  107. package/src/composable/useQueue.ts +13 -0
  108. package/src/composable/useS3Uploader.ts +32 -0
  109. package/src/composable/useShowOn.ts +9 -0
  110. package/src/composable/useStack.ts +13 -0
  111. package/src/composable/useTinymce.ts +29 -0
  112. package/src/composable/useTomSelect.ts +72 -0
  113. package/src/composable/useUIBootstrap5.ts +48 -0
  114. package/src/composable/useUniDirective.ts +32 -0
  115. package/src/composable/useValidation.ts +39 -0
  116. package/src/data.ts +36 -0
  117. package/src/events.ts +73 -0
  118. package/src/legacy/legacy.ts +186 -0
  119. package/src/legacy/loader.ts +125 -0
  120. package/src/module/checkboxes-multi-select.ts +54 -0
  121. package/src/module/field-cascade-select.ts +292 -0
  122. package/src/module/field-file-drag.ts +292 -0
  123. package/src/module/field-flatpickr.ts +127 -0
  124. package/src/module/field-modal-select.ts +174 -0
  125. package/src/module/field-modal-tree.ts +27 -0
  126. package/src/module/field-multi-uploader.ts +361 -0
  127. package/src/module/field-repeatable.ts +202 -0
  128. package/src/module/field-single-image-drag.ts +468 -0
  129. package/src/module/form.ts +223 -0
  130. package/src/module/grid.ts +465 -0
  131. package/src/module/http-client.ts +243 -0
  132. package/src/module/iframe-modal.ts +167 -0
  133. package/src/module/list-dependent.ts +321 -0
  134. package/src/module/s3-multipart-uploader.ts +300 -0
  135. package/src/module/s3-uploader.ts +234 -0
  136. package/src/module/show-on.ts +173 -0
  137. package/src/module/tinymce.ts +263 -0
  138. package/src/module/ui-bootstrap5.ts +107 -0
  139. package/src/module/validation.ts +1019 -0
  140. package/src/plugin/index.ts +1 -0
  141. package/src/plugin/php-adapter.ts +65 -0
  142. package/src/polyfill/form-request-submit.ts +31 -0
  143. package/src/polyfill/index.ts +9 -0
  144. package/src/service/animate.ts +58 -0
  145. package/src/service/crypto.ts +27 -0
  146. package/src/service/dom-watcher.ts +62 -0
  147. package/src/service/dom.ts +265 -0
  148. package/src/service/helper.ts +48 -0
  149. package/src/service/index.ts +10 -0
  150. package/src/service/lang.ts +122 -0
  151. package/src/service/loader.ts +152 -0
  152. package/src/service/router.ts +118 -0
  153. package/src/service/ui.ts +497 -0
  154. package/src/service/uri.ts +106 -0
  155. package/src/types/base.ts +9 -0
  156. package/src/types/index.ts +4 -0
  157. package/src/types/modal-tree.ts +12 -0
  158. package/src/types/plugin.ts +6 -0
  159. package/src/types/shims.d.ts +18 -0
  160. package/src/types/ui.ts +6 -0
  161. package/src/unicorn.ts +63 -0
  162. package/src/utilities/arr.ts +25 -0
  163. package/src/utilities/base.ts +9 -0
  164. package/src/utilities/data.ts +48 -0
  165. package/src/utilities/index.ts +5 -0
  166. package/src/utilities/tree.ts +20 -0
  167. package/src/vue/components/ModalTree/ModalTreeApp.vue +175 -0
  168. package/src/vue/components/ModalTree/TreeItem.vue +262 -0
  169. package/src/vue/components/ModalTree/TreeModal.vue +225 -0
  170. package/tests/test.js +4 -0
  171. package/tsconfig.js.json +25 -0
  172. package/tsconfig.json +17 -0
  173. package/vite.assets.config.ts +61 -0
  174. package/vite.config.test.ts +36 -0
  175. package/vite.config.ts +112 -0
@@ -0,0 +1,497 @@
1
+ import { AlertAdapter, deleteConfirm, simpleAlert, simpleConfirm } from '@lyrasoft/ts-toolkit/generic';
2
+ import type { Alpine as AlpineGlobal } from 'alpinejs';
3
+ import type { default as SpectrumGlobal } from 'spectrum-vanilla';
4
+ import type { SpectrumOptions } from 'spectrum-vanilla/dist/types/types';
5
+ import type { default as TomSelectGlobal } from 'tom-select';
6
+ import { useStack } from '../composable';
7
+ import { data, removeData } from '../data';
8
+ import type { Constructor, MaybePromise, Nullable, UIThemeInterface } from '../types';
9
+ import { animateTo } from './animate';
10
+ import { html, module, selectAll, selectOne } from './dom';
11
+ import { nextTick } from './helper';
12
+ import { useCssImport, useImport } from './loader';
13
+
14
+ let ui: UnicornUI;
15
+
16
+ AlertAdapter.alert = (title: string, text = '', type = 'info'): Promise<void> => {
17
+ if (text) {
18
+ title += ' | ' + text;
19
+ }
20
+
21
+ window.alert(title);
22
+
23
+ return Promise.resolve();
24
+ };
25
+
26
+ AlertAdapter.confirm = (message: string): Promise<boolean> => {
27
+ message = message || 'Are you sure?';
28
+
29
+ return new Promise((resolve) => {
30
+ resolve(window.confirm(message));
31
+ });
32
+ };
33
+
34
+ AlertAdapter.confirmText = () => 'OK';
35
+ AlertAdapter.cancelText = () => 'Cancel';
36
+ AlertAdapter.deleteText = () => 'Delete';
37
+
38
+ export { simpleAlert, simpleConfirm, deleteConfirm, AlertAdapter };
39
+
40
+ export function useUI(instance?: UnicornUI): UnicornUI {
41
+ if (instance) {
42
+ ui = instance;
43
+ }
44
+
45
+ return ui ??= new UnicornUI();
46
+ }
47
+
48
+ export function useUITheme<T extends UIThemeInterface>(theme?: T | Constructor<T>): T {
49
+ const ui = useUI();
50
+
51
+ if (ui.theme && !theme) {
52
+ return ui.theme;
53
+ }
54
+
55
+ if (typeof theme === 'function') {
56
+ theme = new theme();
57
+ }
58
+
59
+ ui.installTheme(theme);
60
+
61
+ return ui.theme;
62
+ }
63
+
64
+ export class UnicornUI {
65
+ theme?: any;
66
+ aliveHandle?: any;
67
+
68
+ static get defaultOptions() {
69
+ return {
70
+ messageSelector: '.message-wrap',
71
+ };
72
+ }
73
+
74
+ installTheme(theme: any) {
75
+ this.theme = theme;
76
+ }
77
+
78
+ // confirm(message: string): Promise<boolean> {
79
+ // message = message || 'Are you sure?';
80
+ //
81
+ // return new Promise((resolve) => {
82
+ // resolve(window.confirm(message));
83
+ // });
84
+ // }
85
+ //
86
+ // alert(title: string, text = '', type = 'info'): Promise<boolean> {
87
+ // if (text) {
88
+ // title += ' | ' + text;
89
+ // }
90
+ //
91
+ // window.alert(title);
92
+ //
93
+ // return Promise.resolve(true);
94
+ // }
95
+ }
96
+
97
+ const prepares: AlpinePrepareCallback[] = [];
98
+ type AlpinePrepareCallback = (Alpine: AlpineGlobal) => MaybePromise<any>;
99
+ const { promise: alpineLoaded, resolve: alpineResolve } = Promise.withResolvers<AlpineGlobal>();
100
+
101
+ export async function loadAlpine(callback?: Nullable<AlpinePrepareCallback>): Promise<AlpineGlobal> {
102
+ if (callback && !window.Alpine) {
103
+ prepares.push(callback);
104
+ }
105
+
106
+ const { default: Alpine }: { default: AlpineGlobal } = await useImport('@alpinejs');
107
+
108
+ if (!window.Alpine) {
109
+ await Promise.all(prepares.map((callback) => Promise.resolve(callback(Alpine))));
110
+
111
+ Alpine.start();
112
+
113
+ window.Alpine = Alpine;
114
+
115
+ alpineResolve(Alpine);
116
+ } else if (callback) {
117
+ await callback(Alpine);
118
+ }
119
+
120
+ return Alpine;
121
+ }
122
+
123
+ export async function initAlpineComponent(directive: string) {
124
+ const Alpine = await alpineLoaded;
125
+
126
+ await nextTick();
127
+
128
+ selectAll<HTMLElement>(`[${directive}]`, (el) => {
129
+ const code = el.getAttribute(directive) || '';
130
+ el.removeAttribute(directive);
131
+
132
+ // @see https://github.com/alpinejs/alpine/issues/359#issuecomment-973688464
133
+ Alpine.mutateDom(() => {
134
+ el.setAttribute('x-data', code);
135
+ });
136
+
137
+ Alpine.initTree(el);
138
+ });
139
+ }
140
+
141
+ /**
142
+ * Before Alpine init
143
+ */
144
+ export async function prepareAlpine(callback: AlpinePrepareCallback) {
145
+ if (window.Alpine) {
146
+ await callback(window.Alpine);
147
+ } else {
148
+ prepares.push(callback);
149
+ }
150
+ }
151
+ export async function prepareAlpineDefer(callback: AlpinePrepareCallback) {
152
+ const Alpine = await alpineLoaded;
153
+
154
+ await callback(window.Alpine);
155
+ }
156
+
157
+ /**
158
+ * Render Messages.
159
+ */
160
+ export function renderMessage(messages: string | string[], type: string = 'info') {
161
+ ui.theme.renderMessage(messages, type);
162
+ }
163
+
164
+ /**
165
+ * Clear messages.
166
+ */
167
+ export function clearMessages() {
168
+ ui.theme.clearMessages();
169
+ }
170
+
171
+ /**
172
+ * Show notify.
173
+ */
174
+ export function notify(messages: string | string[], type: string = 'info') {
175
+ ui.theme.renderMessage(messages, type);
176
+ }
177
+
178
+ /**
179
+ * Clear notifies.
180
+ */
181
+ export function clearNotifies() {
182
+ ui.theme.clearMessages();
183
+ }
184
+
185
+ export async function mark(selector?: string | HTMLElement, keyword: string = '', options: Record<string, any> = {}) {
186
+ const modules = await useImport('@vendor/mark.js/dist/mark.min.js');
187
+
188
+ if (selector != null) {
189
+ const instance = new Mark(selector);
190
+ instance.mark(keyword, options);
191
+ }
192
+
193
+ return modules;
194
+ }
195
+
196
+ export async function slideUp(target: string | HTMLElement, duration: number = 300): Promise<Animation | void> {
197
+ const ele = selectOne(target);
198
+
199
+ if (!ele) {
200
+ return Promise.resolve();
201
+ }
202
+
203
+ ele.style.overflow = 'hidden';
204
+
205
+ const animation = animateTo(
206
+ ele,
207
+ { height: 0, paddingTop: 0, paddingBottom: 0 },
208
+ { duration, easing: 'ease-out' }
209
+ );
210
+
211
+ data(ele, 'animation.sliding.up', true);
212
+
213
+ const r = await animation.finished;
214
+
215
+ if (!data(ele, 'animation.sliding.down')) {
216
+ ele.style.display = 'none';
217
+ }
218
+
219
+ removeData(ele, 'animation.sliding.up');
220
+
221
+ return r;
222
+ }
223
+
224
+ export function slideDown(
225
+ target: string | HTMLElement,
226
+ duration: number = 300,
227
+ display: string = 'block'): Promise<Animation | void> {
228
+ const ele = selectOne(target);
229
+
230
+ if (!ele) {
231
+ return Promise.resolve();
232
+ }
233
+
234
+ data(ele, 'animation.sliding.down', true);
235
+
236
+ ele.style.display = display;
237
+
238
+ // Get height
239
+ let maxHeight = 0;
240
+ for (const child of Array.from(ele.children) as HTMLElement[]) {
241
+ maxHeight = Math.max(child.offsetHeight, maxHeight);
242
+ }
243
+
244
+ const animation = animateTo(
245
+ ele,
246
+ {
247
+ height: [
248
+ 0,
249
+ maxHeight + 'px'
250
+ ]
251
+ },
252
+ { duration, easing: 'ease-out' }
253
+ );
254
+
255
+ animation.addEventListener('finish', () => {
256
+ ele.style.height = '';
257
+
258
+ if (!data(ele, 'animation.sliding.up')) {
259
+ ele.style.overflow = 'visible';
260
+ }
261
+
262
+ removeData(ele, 'animation.sliding.down');
263
+ });
264
+
265
+ return animation.finished;
266
+ }
267
+
268
+ /**
269
+ * slideToggle
270
+ */
271
+ export function slideToggle(
272
+ target: string | HTMLElement,
273
+ duration: number = 500,
274
+ display: string = 'block'): Promise<Animation | void> {
275
+ const ele = selectOne(target);
276
+
277
+ if (!ele) {
278
+ return Promise.resolve();
279
+ }
280
+
281
+ if (window.getComputedStyle(ele).display === 'none') {
282
+ return slideDown(ele, duration, display);
283
+ } else {
284
+ return slideUp(ele, duration);
285
+ }
286
+ }
287
+
288
+ export async function fadeOut(selector: string | HTMLElement, duration: number = 500): Promise<Animation | void> {
289
+ const el = selectOne(selector);
290
+
291
+ if (!el) {
292
+ return;
293
+ }
294
+
295
+ const animation = animateTo(el, { opacity: 0 }, { duration, easing: 'ease-out' });
296
+
297
+ const p = await animation.finished;
298
+ el.style.display = 'none';
299
+
300
+ return p;
301
+ };
302
+
303
+ export async function fadeIn(
304
+ selector: string | HTMLElement,
305
+ duration: number = 500,
306
+ display: string = 'block'
307
+ ): Promise<Animation | void> {
308
+ const el = selectOne(selector);
309
+
310
+ if (!el) {
311
+ return;
312
+ }
313
+
314
+ el.style.display = '';
315
+
316
+ if (window.getComputedStyle(el).display !== display) {
317
+ el.style.display = display;
318
+ }
319
+
320
+ const animation = animateTo(el, { opacity: 1 }, { duration, easing: 'ease-out' });
321
+
322
+ return animation.finished;
323
+ };
324
+
325
+ export async function highlight(
326
+ selector: string | HTMLElement,
327
+ color: string = '#ffff99',
328
+ duration: number = 600
329
+ ): Promise<Animation | void> {
330
+ const ele = selectOne(selector);
331
+
332
+ if (!ele) {
333
+ return;
334
+ }
335
+
336
+ duration /= 2;
337
+ const bg = window.getComputedStyle(ele).backgroundColor;
338
+
339
+ const animation = animateTo(ele, { backgroundColor: color }, { duration });
340
+
341
+ await animation.finished;
342
+
343
+ return animateTo(ele, { backgroundColor: bg }, { duration });
344
+ }
345
+
346
+ /**
347
+ * Color Picker.
348
+ */
349
+ export async function useColorPicker(
350
+ selector?: Nullable<string | HTMLElement | NodeListOf<HTMLElement>>,
351
+ options: Partial<SpectrumOptions> = {}
352
+ ): Promise<any> {
353
+ if (options?.theme === 'dark') {
354
+ useCssImport('@spectrum/spectrum-dark.min.css');
355
+ } else if (!options?.theme) {
356
+ useCssImport('@spectrum/spectrum.min.css');
357
+ }
358
+
359
+ const m = await useImport('@spectrum');
360
+
361
+ // Locale
362
+ if (typeof options.locale === 'string') {
363
+ let ls: any = options.locale.split('-').map((l) => l.toLowerCase());
364
+
365
+ if (ls[0] === ls[1]) {
366
+ ls = [ls];
367
+ }
368
+
369
+ ls = ls.join('-');
370
+ try {
371
+ await useImport(`@spectrum/i18n/${ls}.js`);
372
+ } catch (e) {
373
+ console.warn(`Unable to load Spectrum locale "${ls}" (${options.locale})`);
374
+ }
375
+ }
376
+
377
+ if (selector) {
378
+ module<any, HTMLElement>(selector, 'spectrum', (ele) => Spectrum.getInstance(ele, options));
379
+ }
380
+
381
+ return m;
382
+ }
383
+
384
+ export function useDisableOnSubmit(
385
+ formSelector: string | HTMLFormElement = '#admin-form',
386
+ buttonSelector: string = '',
387
+ options: Record<string, any> = {}
388
+ ) {
389
+ // Todo: Use object to handle it
390
+ buttonSelector = buttonSelector || [
391
+ '#admin-toolbar button',
392
+ '#admin-toolbar a',
393
+ formSelector + ' .disable-on-submit',
394
+ formSelector + ' .js-dos',
395
+ formSelector + ' [data-dos]',
396
+ ].join(',');
397
+
398
+ const iconSelector = options.iconSelector || [
399
+ '[class*="fa-"]',
400
+ '[data-spin]',
401
+ '[data-spinner]',
402
+ ].join(',');
403
+
404
+ const event = options.event || 'submit';
405
+ const spinnerClass = options.spinnerClass || 'spinner-border spinner-border-sm';
406
+
407
+ selectAll<HTMLElement>(buttonSelector, (button) => {
408
+ button.addEventListener('click', (e) => {
409
+ button.dataset.clicked = '1';
410
+
411
+ setTimeout(() => {
412
+ delete button.dataset.clicked;
413
+ }, 1500);
414
+ });
415
+ });
416
+
417
+ const form = selectOne<HTMLFormElement>(formSelector);
418
+ form?.addEventListener(event, (e: SubmitEvent) => {
419
+ setTimeout(() => {
420
+ if (!form.checkValidity()) {
421
+ return;
422
+ }
423
+
424
+ selectAll<HTMLElement>(buttonSelector, (button) => {
425
+ button.style.pointerEvents = 'none';
426
+ button.setAttribute('disabled', 'disabled');
427
+ button.classList.add('disabled');
428
+
429
+ if (button.dataset.clicked) {
430
+ let icon = button.querySelector(iconSelector);
431
+
432
+ if (icon) {
433
+ const i = html('<i></i>');
434
+ icon.parentNode.replaceChild(i, icon);
435
+
436
+ i.setAttribute('class', spinnerClass);
437
+ // icon.styles.width = '1em';
438
+ // icon.styles.height = '1em';
439
+ // icon.styles.borderWith = '.15em';
440
+ }
441
+ }
442
+ });
443
+ }, 0);
444
+ });
445
+ }
446
+
447
+ export function useDisableIfStackNotEmpty(buttonSelector: string = '[data-task=save]',
448
+ stackName: string = 'uploading') {
449
+ const stack = useStack(stackName);
450
+
451
+ stack.observe((stack, length) => {
452
+ for (const button of selectAll<HTMLElement>(buttonSelector)) {
453
+ if (length > 0) {
454
+ button.setAttribute('disabled', 'disabled');
455
+ button.classList.add('disabled');
456
+ } else {
457
+ button.removeAttribute('disabled');
458
+ button.classList.remove('disabled');
459
+ }
460
+ }
461
+ });
462
+ }
463
+
464
+ /**
465
+ * Keep alive.
466
+ */
467
+ export function useKeepAlive(url: string, time: number = 60000): () => void {
468
+ const aliveHandle = window.setInterval(() => fetch(url), time);
469
+
470
+ return () => {
471
+ clearInterval(aliveHandle);
472
+ };
473
+ }
474
+
475
+ /**
476
+ * Vue component field.
477
+ */
478
+ export async function useVueComponentField(
479
+ selector?: Nullable<string | HTMLElement>,
480
+ value?: any,
481
+ options: Record<string, any> = {}
482
+ ): Promise<any> {
483
+ const m = await useImport('@unicorn/field/vue-component-field.js');
484
+
485
+ if (selector) {
486
+ m.VueComponentField.init(selector, value, options);
487
+ }
488
+
489
+ return m;
490
+ }
491
+
492
+ declare global {
493
+ var Alpine: AlpineGlobal;
494
+ var TomSelect: typeof TomSelectGlobal;
495
+ var Spectrum: typeof SpectrumGlobal;
496
+ var Mark: any;
497
+ }
@@ -0,0 +1,106 @@
1
+ import { data } from '../data';
2
+
3
+ type UriTypes = 'full' | 'path' | 'root' | 'current' | 'route' | 'script';
4
+ type AssetTypes = 'root' | 'path';
5
+
6
+ export function useSystemUri(): UnicornSystemUri;
7
+ export function useSystemUri(type: UriTypes): string;
8
+ export function useSystemUri(type?: UriTypes, path?: string): UnicornSystemUri | string {
9
+ const uri = UnicornSystemUri.get();
10
+
11
+ if (type) {
12
+ return uri[type](path);
13
+ }
14
+
15
+ return uri;
16
+ }
17
+
18
+ export function useAssetUri(): UnicornAssetUri;
19
+ export function useAssetUri(type?: AssetTypes, path?: string): string;
20
+ export function useAssetUri(type?: AssetTypes, path?: string): UnicornAssetUri | string {
21
+ const asset = UnicornAssetUri.get();
22
+
23
+ if (type) {
24
+ return asset[type](path);
25
+ }
26
+
27
+ return asset;
28
+ }
29
+
30
+ function uri(type: string) {
31
+ return data('unicorn.uri')[type];
32
+ }
33
+
34
+ function asset(type: string) {
35
+ return uri('asset')[type];
36
+ }
37
+
38
+ export function addUriBase(uri: string, type = 'path') {
39
+ if (uri.substring(0, 2) === '/\/' || uri.substring(0, 4) === 'http') {
40
+ return uri;
41
+ }
42
+
43
+ return asset(type) + '/' + uri;
44
+ }
45
+
46
+ export class UnicornSystemUri extends URL {
47
+ static instance: UnicornSystemUri;
48
+
49
+ static get() {
50
+ return this.instance ??= new this(uri('full'));
51
+ }
52
+
53
+ path(path: string = ''): string {
54
+ return uri('path') + path;
55
+ }
56
+
57
+ root(path: string = ''): string {
58
+ return uri('root') + path;
59
+ }
60
+
61
+ current(): string {
62
+ return uri('current') || '';
63
+ }
64
+
65
+ full(): string {
66
+ return uri('full') || '';
67
+ }
68
+
69
+ route(): string {
70
+ return uri('route') || '';
71
+ }
72
+
73
+ script(): string {
74
+ return uri('script') || '';
75
+ }
76
+
77
+ routeWithQuery() {
78
+ const route = this.route();
79
+ const query = this.searchParams.toString();
80
+
81
+ return query ? `${route}?${query}` : route;
82
+ }
83
+
84
+ routeAndQuery() {
85
+ const route = this.route();
86
+ const query = this.searchParams.toString();
87
+
88
+ return [route, query];
89
+ }
90
+ }
91
+
92
+ export class UnicornAssetUri {
93
+ static instance: UnicornAssetUri;
94
+
95
+ static get() {
96
+ return this.instance ??= new this();
97
+ }
98
+
99
+ path(path: string = ''): string {
100
+ return asset('path') + path;
101
+ }
102
+
103
+ root(path: string = ''): string {
104
+ return asset('root') + path;
105
+ }
106
+ }
@@ -0,0 +1,9 @@
1
+ export type Nullable<T> = T | null | undefined;
2
+ export type MaybeArray<T> = T | T[];
3
+ export type MaybePromise<T> = T | Promise<T>;
4
+
5
+ export interface Dictionary<T = any> {
6
+ [key: string]: T;
7
+ }
8
+
9
+ export type Constructor<T> = new (...args: any[]) => T;
@@ -0,0 +1,4 @@
1
+ export * from './base';
2
+ export * from './plugin';
3
+ export * from './ui';
4
+ export * from './modal-tree';
@@ -0,0 +1,12 @@
1
+
2
+ export type TreeNode<T = any> = {
3
+ key: string | number;
4
+ value: T;
5
+ children: TreeNode<T>[];
6
+ indeterminate?: boolean;
7
+ selected?: boolean;
8
+ };
9
+ export type ModalTreeSource = TreeNode | TreeNode[] | string | (() => any);
10
+ export type ValueGetter = (item: any) => any;
11
+ export type TitleGetter = (item: any) => string;
12
+ export type SearchMatcher = (item: any, q: string) => boolean;
@@ -0,0 +1,6 @@
1
+ import { UnicornApp } from '../app';
2
+
3
+ export interface UnicornPlugin {
4
+ install?(app: UnicornApp, options?: Record<string, any>): void;
5
+ uninstall?(app: UnicornApp): void;
6
+ }
@@ -0,0 +1,18 @@
1
+ declare module '*.scss' {
2
+ const content: { [className: string]: string }
3
+ export default content
4
+ }
5
+
6
+ declare module '*.scss?inline' {
7
+ export default string;
8
+ }
9
+
10
+ declare module '*.css?inline' {
11
+ export default string;
12
+ }
13
+
14
+ declare module '*.vue' {
15
+ import { defineComponent } from 'vue'
16
+ const component: ReturnType<typeof defineComponent>
17
+ export default component;
18
+ }
@@ -0,0 +1,6 @@
1
+ export interface UIThemeInterface {
2
+ renderMessage(messages: string | string[], type?: string): void;
3
+
4
+ clearMessages(): void;
5
+ }
6
+