@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,13 @@
1
+
2
+ import { Dictionary } from '../types';
3
+ import { Stack, stack } from '@lyrasoft/ts-toolkit/generic';
4
+
5
+ const stacks: Dictionary<Stack> = {};
6
+
7
+ export function useStack<T = any>(name: string = 'default', store: any[] = []): Stack<T> {
8
+ return stacks[name] ??= createStack<T>(store);
9
+ }
10
+
11
+ export function createStack<T = any>(store: any[] = []): Stack<T> {
12
+ return stack<T>(store);
13
+ }
@@ -0,0 +1,29 @@
1
+ import type { TinymceController, TinymceModule } from '../module/tinymce';
2
+ import type { MaybePromise } from '../types';
3
+ import type { TinyMCE } from 'tinymce';
4
+
5
+ export async function useTinymce(): Promise<TinymceModule>
6
+ export async function useTinymce(
7
+ selector?: string,
8
+ options?: Record<string, any>
9
+ ): Promise<TinymceController>;
10
+ export async function useTinymce(
11
+ selector?: string,
12
+ options: Record<string, any> = {}
13
+ ): Promise<any> {
14
+ const module = await import('../module/tinymce');
15
+
16
+ if (selector) {
17
+ return module.get(selector, options);
18
+ }
19
+
20
+ return module;
21
+ }
22
+
23
+ export async function useTinymceHook(
24
+ handler: ((tinymce: TinyMCE) => MaybePromise<any>)
25
+ ): Promise<void> {
26
+ const { addHook } = await import('../module/tinymce');
27
+
28
+ return addHook(handler);
29
+ }
@@ -0,0 +1,72 @@
1
+ import { module, useCssImport, useCssIncludes, useImport, wait } from '../service';
2
+ import type { Nullable } from '../types';
3
+ import { mergeDeep } from '../utilities';
4
+
5
+ /**
6
+ * @see https://tom-select.js.org/
7
+ */
8
+ export async function useTomSelect(
9
+ selector?: Nullable<string | HTMLElement | NodeListOf<HTMLElement>>,
10
+ options: Record<string, any> = {},
11
+ theme: string = 'bootstrap5'
12
+ ) {
13
+ const [m] = await wait(
14
+ useImport('@vendor/tom-select/dist/js/tom-select.complete.min.js'),
15
+ useCssImport(`@vendor/tom-select/dist/css/tom-select.${theme}.min.css`)
16
+ );
17
+
18
+ if (selector) {
19
+ module<any, HTMLSelectElement>(
20
+ selector,
21
+ 'tom.select',
22
+ (ele) => {
23
+ options = mergeDeep({
24
+ allowEmptyOption: true,
25
+ maxOptions: null,
26
+ plugins: {
27
+ caret_position: {},
28
+ clear_button: {},
29
+ }
30
+ }, options);
31
+
32
+ if ((ele as HTMLSelectElement).multiple) {
33
+ options.plugins.remove_button = {};
34
+ } else {
35
+ options.plugins.dropdown_input = {};
36
+ }
37
+
38
+ // Auto select first if options changed.
39
+ // @see https://github.com/orchidjs/tom-select/issues/362
40
+ class UnicornTomSelect extends TomSelect {
41
+ syncOptionsWithoutKeepSelected() {
42
+ const oldValue = ele.value;
43
+
44
+ this.clear();
45
+ this.clearOptions();
46
+ this.sync();
47
+
48
+ if (ele.value !== oldValue) {
49
+ this.setValue(
50
+ ele.querySelector<HTMLOptionElement>(`option[value="${oldValue}"]`)?.value
51
+ ?? ele.querySelector<HTMLOptionElement>('option')?.value
52
+ ?? '',
53
+ true
54
+ );
55
+ }
56
+ }
57
+ }
58
+
59
+ // @ts-ignore
60
+ const t = new UnicornTomSelect(ele as TomInput, options);
61
+
62
+ ele.addEventListener('list:updated', () => {
63
+ t.syncOptionsWithoutKeepSelected();
64
+ });
65
+
66
+ return t;
67
+ }
68
+ );
69
+ }
70
+
71
+ return m;
72
+ }
@@ -0,0 +1,48 @@
1
+ import type { Tooltip } from 'bootstrap';
2
+ import { ButtonRadioOptions } from '../bootstrap/button-radio';
3
+ import type { KeepTabOptions } from '../bootstrap/keep-tab';
4
+ import type { UIBootstrap5 } from '../module/ui-bootstrap5';
5
+ import { useUITheme } from '../service';
6
+
7
+ export async function useUIBootstrap5(install = false, pushToGlobal = false): Promise<UIBootstrap5> {
8
+ const { UIBootstrap5 } = await import('../module/ui-bootstrap5');
9
+
10
+ const theme = UIBootstrap5.get();
11
+
12
+ if (install) {
13
+ useUITheme(theme);
14
+
15
+ if (pushToGlobal) {
16
+ theme.pushBootstrapToGlobal();
17
+ }
18
+ }
19
+
20
+ return theme;
21
+ }
22
+
23
+ export async function useBs5Tooltip(
24
+ selector: NodeListOf<Element> | Element | string = '[data-bs-toggle="tooltip"]',
25
+ config: Partial<Tooltip.Options> = {}
26
+ ): Promise<Tooltip[]> {
27
+ const bs5 = await useUIBootstrap5();
28
+
29
+ return bs5.tooltip(selector, config);
30
+ }
31
+
32
+ export const useBs5KeepTab: typeof UIBootstrap5.prototype.keepTab = async (
33
+ selector?: string | HTMLElement,
34
+ options: KeepTabOptions = {}
35
+ ): Promise<any> => {
36
+ const bs5 = await useUIBootstrap5();
37
+
38
+ return bs5.keepTab(selector, options);
39
+ };
40
+
41
+ export const useBs5ButtonRadio: typeof UIBootstrap5.prototype.buttonRadio = async (
42
+ selector?: string | HTMLElement,
43
+ options: ButtonRadioOptions = {}
44
+ ): Promise<any> => {
45
+ const bs5 = await useUIBootstrap5();
46
+
47
+ return bs5.buttonRadio(selector, options);
48
+ };
@@ -0,0 +1,32 @@
1
+ import { Dictionary } from '../types';
2
+ import type { default as WebDirective } from 'web-directive';
3
+ import type { WebDirectiveHandler, WebDirectiveOptions } from 'web-directive/src/types';
4
+
5
+ let instances: Dictionary<WebDirective> = {};
6
+
7
+ export async function useWebDirective(
8
+ name: string = 'unicorn',
9
+ options: Partial<WebDirectiveOptions> = {}
10
+ ): Promise<WebDirective> {
11
+ return instances[name] ??= await createWebDirective(Object.assign({}, options, { prefix: 'uni-' }));
12
+ }
13
+
14
+ export async function useUniDirective<T extends Element = HTMLElement>(
15
+ name: string,
16
+ handler: WebDirectiveHandler<T>,
17
+ wdInstance: WebDirective | string = 'unicorn'
18
+ ): Promise<void> {
19
+ const wd = typeof wdInstance === 'string' ? await useWebDirective(wdInstance) : wdInstance;
20
+
21
+ // Todo: Should fix web-directive types
22
+ wd.register(name, handler as WebDirectiveHandler<any>);
23
+ }
24
+
25
+ async function createWebDirective(options: Partial<WebDirectiveOptions> = {}): Promise<WebDirective> {
26
+ const WebDirective = (await import('web-directive')).default;
27
+
28
+ const wd = new WebDirective(options);
29
+ wd.listen();
30
+
31
+ return wd;
32
+ }
@@ -0,0 +1,39 @@
1
+ import type {
2
+ UnicornFieldValidation,
3
+ UnicornFormValidation,
4
+ ValidationHandler,
5
+ ValidationModule
6
+ } from '../module/validation';
7
+ import { getBoundedInstance } from '../service';
8
+
9
+ export async function useFormValidation(): Promise<ValidationModule>;
10
+ export async function useFormValidation(selector: string | Element): Promise<UnicornFormValidation | null>;
11
+ export async function useFormValidation(selector?: string | Element): Promise<any> {
12
+ const module = await import('../module/validation');
13
+
14
+ await module.ready;
15
+
16
+ if (!selector) {
17
+ return module;
18
+ }
19
+
20
+ return useFormValidationSync(selector);
21
+ }
22
+
23
+ export function useFormValidationSync(selector: string | Element): UnicornFormValidation | null {
24
+ return getBoundedInstance<UnicornFormValidation>(selector, 'form.validation');
25
+ }
26
+
27
+ export function useFieldValidationSync(selector: string | Element): UnicornFieldValidation | null {
28
+ return getBoundedInstance<UnicornFieldValidation>(selector, 'field.validation');
29
+ }
30
+
31
+ export async function addGlobalValidator(
32
+ name: string,
33
+ validator: ValidationHandler,
34
+ options: Record<string, any> = {}
35
+ ): Promise<void> {
36
+ const { UnicornFormValidation } = await useFormValidation();
37
+
38
+ UnicornFormValidation.addGlobalValidator(name, validator, options);
39
+ }
package/src/data.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { getData, setData, removeData as rmdata } from './utilities';
2
+
3
+ export function data(name: string, data: any): any;
4
+ export function data(name: string): any;
5
+ export function data(ele: Element, name: string): any;
6
+ export function data(ele: Element, name: string, data?: any): any;
7
+ export function data(ele: Element | string, name: any = undefined, value: any = undefined) {
8
+ if (!(ele instanceof HTMLElement)) {
9
+ value = name;
10
+ name = ele;
11
+ ele = document as any as Element;
12
+ }
13
+
14
+ if (name === undefined) {
15
+ return getData(ele);
16
+ }
17
+
18
+ if (value === undefined) {
19
+ const res = getData(ele, name);
20
+
21
+ return res;
22
+ }
23
+
24
+ setData(ele, name, value);
25
+ }
26
+
27
+ export function removeData(name: string): any;
28
+ export function removeData(ele: Element, name: string): any;
29
+ export function removeData(ele: Element|string, name: any = undefined) {
30
+ if (!(ele instanceof HTMLElement)) {
31
+ name = ele;
32
+ ele = document as any as Element;
33
+ }
34
+
35
+ rmdata(ele, name);
36
+ }
package/src/events.ts ADDED
@@ -0,0 +1,73 @@
1
+ export abstract class EventMixin implements EventAwareInterface {
2
+ _listeners: Record<string, EventHandler[]> = {};
3
+
4
+ on(event: string | string[], handler: EventHandler): this {
5
+ if (Array.isArray(event)) {
6
+ for (const e of event) {
7
+ this.on(e, handler);
8
+ }
9
+ return this;
10
+ }
11
+
12
+ this._listeners[event] ??= [];
13
+
14
+ this._listeners[event].push(handler);
15
+
16
+ return this;
17
+ }
18
+
19
+ once(event: string | string[], handler: EventHandler): this {
20
+ handler.once = true;
21
+ return this.on(event, handler);
22
+ }
23
+
24
+ off(event: string, handler?: EventHandler): this {
25
+ if (handler) {
26
+ this._listeners[event] = this.listeners(event).filter((listener) => listener !== handler);
27
+ return this;
28
+ }
29
+
30
+ delete this._listeners[event];
31
+
32
+ return this;
33
+ }
34
+
35
+ trigger(event: string | string[], ...args: any[]): this {
36
+ if (Array.isArray(event)) {
37
+ for (const e of event) {
38
+ this.trigger(e);
39
+ }
40
+ return this;
41
+ }
42
+
43
+ for (const listener of this.listeners(event)) {
44
+ listener(...args);
45
+ }
46
+
47
+ // Remove once
48
+ this._listeners[event] = this.listeners(event).filter((listener) => listener?.once !== true);
49
+
50
+ return this;
51
+ }
52
+
53
+ listeners(event: string): EventHandler[] {
54
+ return this._listeners[event] === undefined ? [] : this._listeners[event];
55
+ }
56
+ }
57
+
58
+ // export class EventBus extends Mixin(EventMixin) {
59
+ // }
60
+
61
+ export type EventHandler = ((...event: any[]) => void) & { once?: boolean };
62
+
63
+ export interface EventAwareInterface {
64
+ on(event: string | string[], handler: EventHandler): this;
65
+
66
+ once(event: string | string[], handler: EventHandler): this;
67
+
68
+ off(event: string, handler?: EventHandler): this;
69
+
70
+ trigger(event: string | string[], ...args: any[]): this;
71
+
72
+ listeners(event: string): EventHandler[];
73
+ }
@@ -0,0 +1,186 @@
1
+ import { numberFormat } from '@lyrasoft/ts-toolkit/generic';
2
+ import { sprintf, vsprintf } from 'sprintf-js';
3
+ import {
4
+ addGlobalValidator,
5
+ useBs5Tooltip,
6
+ useCheckboxesMultiSelect,
7
+ useFieldValidationSync,
8
+ useForm,
9
+ useFormAsync,
10
+ useFormValidation,
11
+ useFormValidationSync,
12
+ useGrid,
13
+ useGridAsync,
14
+ useHttpClient,
15
+ useQueue,
16
+ useStack,
17
+ useTomSelect,
18
+ useUniDirective
19
+ } from '../composable';
20
+ import {
21
+ __,
22
+ animateTo,
23
+ base64UrlDecode,
24
+ base64UrlEncode,
25
+ clearMessages,
26
+ clearNotifies,
27
+ debounce,
28
+ delegate,
29
+ domready,
30
+ fadeIn,
31
+ fadeOut,
32
+ getBoundedInstance,
33
+ getBoundedInstanceList,
34
+ h,
35
+ highlight,
36
+ html,
37
+ initAlpineComponent,
38
+ isDebug,
39
+ loadAlpine,
40
+ mark,
41
+ module,
42
+ notify,
43
+ prepareAlpine,
44
+ renderMessage,
45
+ route,
46
+ selectAll,
47
+ selectOne,
48
+ serial,
49
+ simpleAlert,
50
+ simpleConfirm,
51
+ slideDown,
52
+ slideToggle,
53
+ slideUp,
54
+ throttle,
55
+ tid,
56
+ uid,
57
+ useAssetUri,
58
+ useColorPicker,
59
+ useDisableIfStackNotEmpty,
60
+ useDisableOnSubmit,
61
+ useKeepAlive,
62
+ useSystemUri
63
+ } from '../service';
64
+ import { LegacyLoader } from './loader';
65
+
66
+ export async function useLegacyMethods(app: any) {
67
+ const http = await useHttpClient();
68
+
69
+ app.use(LegacyLoader);
70
+
71
+ handleUri(app);
72
+ handlerHelper(app);
73
+ handleCrypto(app);
74
+
75
+ app.__ = __;
76
+ app.trans = __;
77
+ app.route = route;
78
+ app.$http = http;
79
+ app.directive = useUniDirective;
80
+
81
+ app.animate = animateTo;
82
+ app.$animation = { to: animateTo };
83
+
84
+ app.addMessage = renderMessage;
85
+ app.clearMessages = clearMessages;
86
+ app.notify = notify;
87
+ app.clearNotifies = clearNotifies;
88
+
89
+ app.loadAlpine = loadAlpine;
90
+ app.initAlpine = initAlpineComponent;
91
+ app.beforeAlpineInit = prepareAlpine;
92
+ app.prepareAlpine = prepareAlpine;
93
+
94
+ handleUI(app);
95
+
96
+ await handleFormGrid(app);
97
+
98
+ app.formValidation = useFormValidation;
99
+ app.$validation = {
100
+ get: useFormValidationSync,
101
+ getField: useFieldValidationSync,
102
+ addGlobalValidator: addGlobalValidator,
103
+ import: () => useFormValidation()
104
+ };
105
+
106
+ app.stack = useStack;
107
+ app.queue = useQueue;
108
+ }
109
+
110
+ function handleCrypto(app: any) {
111
+ app.base64Encode = base64UrlEncode;
112
+ app.base64Decode = base64UrlDecode;
113
+ // app.uuid4 = uuid4;
114
+ app.uid = uid;
115
+ app.tid = tid;
116
+ // app.md5 = md5;
117
+ app.serial = serial;
118
+ }
119
+
120
+ function handleUri(app: any) {
121
+ app.uri = useSystemUri;
122
+ app.asset = useAssetUri;
123
+ }
124
+
125
+ function handlerHelper(app: any) {
126
+ app.domready = domready;
127
+ app.selectOne = selectOne;
128
+ app.selectAll = selectAll;
129
+ app.each = selectAll;
130
+ app.getBoundedInstance = getBoundedInstance;
131
+ app.getBoundedInstanceList = getBoundedInstanceList;
132
+ app.module = module;
133
+ app.h = h;
134
+ app.html = html;
135
+ // app.$get = get;
136
+ // app.$set = set;
137
+ app.delegate = delegate;
138
+ app.debounce = debounce;
139
+ app.throttle = throttle;
140
+ app.isDebug = isDebug;
141
+ app.confirm = simpleConfirm;
142
+ app.alert = simpleAlert;
143
+ app.numberFormat = numberFormat;
144
+ app.sprintf = sprintf;
145
+ app.vsprintf = vsprintf;
146
+ // app.genRandomString = genRandomString;
147
+ // app.defaultsDeep = defaultsDeep;
148
+ }
149
+
150
+ function handleUI(app: any) {
151
+ app.$ui ??= {};
152
+ app.$ui.addMessage = renderMessage;
153
+ app.$ui.clearMessages = clearMessages;
154
+ app.$ui.notify = notify;
155
+ app.$ui.clearNotifies = clearNotifies;
156
+
157
+ app.$ui.loadAlpine = loadAlpine;
158
+ app.$ui.initAlpine = initAlpineComponent;
159
+ app.$ui.beforeAlpineInit = prepareAlpine;
160
+ app.$ui.prepareAlpine = prepareAlpine;
161
+
162
+ app.$ui.mark = mark;
163
+ app.$ui.tomSelect = useTomSelect;
164
+ app.$ui.slideUp = slideUp;
165
+ app.$ui.slideDown = slideDown;
166
+ app.$ui.slideToggle = slideToggle;
167
+ app.$ui.fadeOut = fadeOut;
168
+ app.$ui.fadeIn = fadeIn;
169
+ app.$ui.highlight = highlight;
170
+ app.$ui.colorPicker = useColorPicker;
171
+ app.$ui.disableOnSubmit = useDisableOnSubmit;
172
+ app.$ui.disableIfStackNotEmpty = useDisableIfStackNotEmpty;
173
+ app.$ui.checkboxesMultiSelect = useCheckboxesMultiSelect;
174
+ app.$ui.keepAlive = useKeepAlive;
175
+ app.$ui.bootstrap = {
176
+ tooltip: useBs5Tooltip
177
+ };
178
+ }
179
+
180
+ async function handleFormGrid(app: any) {
181
+ await useFormAsync();
182
+ await useGridAsync();
183
+
184
+ app.form = useForm;
185
+ app.grid = useGrid;
186
+ }
@@ -0,0 +1,125 @@
1
+ import { isDebug } from '../service';
2
+
3
+ const imports: Record<string, { promise: Promise<any>; resolve?: Function; }> = {};
4
+
5
+ export class LegacyLoader {
6
+ static install(app: any) {
7
+ const loader = app.$loader = new this(app);
8
+
9
+ app.import = loader.import.bind(loader);
10
+ app.importSync = loader.importSync.bind(loader);
11
+ app.importCSS = loader.importCSS.bind(loader);
12
+ app.minFileName = loader.minFileName.bind(loader);
13
+ app.afterImported = loader.afterImported.bind(loader);
14
+ }
15
+
16
+ constructor(protected app: any) {
17
+ //
18
+ }
19
+
20
+ doImport(src: string): Promise<any> {
21
+ return S.import(src);
22
+ }
23
+
24
+ /**
25
+ * Import modules or scripts.
26
+ */
27
+ import(...src: any[]): Promise<any|any[]> {
28
+ if (src.length === 1) {
29
+ return this.doImport(src[0]);
30
+ }
31
+
32
+ const promises: Promise<any>[] = [];
33
+
34
+ src.forEach((link) => {
35
+ promises.push(
36
+ link instanceof Promise ? link : this.doImport(link)
37
+ );
38
+ });
39
+
40
+ return Promise.all(promises);
41
+ }
42
+
43
+ /**
44
+ * Import sync.
45
+ */
46
+ importSync(...src: any): Promise<any|any[]> {
47
+ let promise: Promise<any> = Promise.resolve();
48
+ let url: string[];
49
+ const modules: any[] = [];
50
+
51
+ while (url = src.shift()) {
52
+ if (!Array.isArray(url)) {
53
+ url = [ url ];
54
+ }
55
+
56
+ const target = url;
57
+ promise = promise.then(
58
+ () => this.import(...target).then((m) => {
59
+ modules.push(m);
60
+ return modules;
61
+ })
62
+ );
63
+ }
64
+
65
+ return promise;
66
+ }
67
+
68
+ /**
69
+ * Import CSS files.
70
+ */
71
+ async importCSS(...src: any): Promise<any|any[]> {
72
+ let modules: any = await this.import(...src);
73
+
74
+ if (!Array.isArray(modules)) {
75
+ modules = [modules];
76
+ }
77
+
78
+ const styles: CSSStyleSheet[] = (modules as any[]).map(module => module.default);
79
+
80
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, ...styles];
81
+ }
82
+
83
+ minFileName(fileName: string): string {
84
+ const segments = fileName.split('.');
85
+ const ext = segments.pop();
86
+
87
+ if (isDebug()) {
88
+ return segments.join('.') + '.min.' + ext;
89
+ }
90
+
91
+ return fileName;
92
+ }
93
+
94
+ asImported(name: string) {
95
+ if (!imports[name]) {
96
+ imports[name] = {
97
+ promise: Promise.resolve(),
98
+ resolve: undefined
99
+ };
100
+ } else {
101
+ imports[name]?.resolve?.();
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Add after import hook for some url or id.
107
+ */
108
+ afterImported(name: string, callback: (resolve: Function, reject?: Function) => void): Promise<any> {
109
+ if (!imports[name]) {
110
+ let r;
111
+ imports[name] = {
112
+ promise: new Promise((resolve) => {
113
+ r = resolve;
114
+ }),
115
+ };
116
+
117
+ imports[name].resolve = r;
118
+ }
119
+
120
+ imports[name].promise.then(callback);
121
+
122
+ return imports[name].promise;
123
+ }
124
+ }
125
+