@windwalker-io/unicorn-next 0.1.7 → 0.1.8

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 (125) hide show
  1. package/.editorconfig +18 -18
  2. package/.gulp.json +7 -7
  3. package/bin/release.mjs +47 -47
  4. package/dist/chunks/button-radio.js.map +1 -1
  5. package/dist/chunks/checkboxes-multi-select.js.map +1 -1
  6. package/dist/chunks/field-cascade-select.js.map +1 -1
  7. package/dist/chunks/field-file-drag.js.map +1 -1
  8. package/dist/chunks/field-flatpickr.js.map +1 -1
  9. package/dist/chunks/field-modal-select.js.map +1 -1
  10. package/dist/chunks/field-modal-tree.js +2 -2
  11. package/dist/chunks/field-modal-tree.js.map +1 -1
  12. package/dist/chunks/field-multi-uploader.js.map +1 -1
  13. package/dist/chunks/field-repeatable.js.map +1 -1
  14. package/dist/chunks/field-single-image-drag.js.map +1 -1
  15. package/dist/chunks/form.js.map +1 -1
  16. package/dist/chunks/grid.js.map +1 -1
  17. package/dist/chunks/http-client.js.map +1 -1
  18. package/dist/chunks/iframe-modal.js.map +1 -1
  19. package/dist/chunks/keep-tab.js.map +1 -1
  20. package/dist/chunks/legacy.js.map +1 -1
  21. package/dist/chunks/list-dependent.js.map +1 -1
  22. package/dist/chunks/s3-multipart-uploader.js +23 -2
  23. package/dist/chunks/s3-multipart-uploader.js.map +1 -1
  24. package/dist/chunks/s3-uploader.js.map +1 -1
  25. package/dist/chunks/show-on.js.map +1 -1
  26. package/dist/chunks/tinymce.js.map +1 -1
  27. package/dist/chunks/ui-bootstrap5.js.map +1 -1
  28. package/dist/chunks/unicorn.js.map +1 -1
  29. package/dist/chunks/validation.js.map +1 -1
  30. package/dist/index.d.ts +29 -13
  31. package/fusionfile.mjs +155 -155
  32. package/package.json +104 -104
  33. package/scss/bootstrap/multi-level-menu.scss +121 -121
  34. package/scss/editor.scss +116 -116
  35. package/scss/field/file-drag.scss +102 -102
  36. package/scss/field/single-image-drag.scss +88 -88
  37. package/scss/field/vue-drag-uploader.scss +160 -160
  38. package/scss/switcher.scss +156 -156
  39. package/src/app.ts +128 -128
  40. package/src/bootstrap/button-radio.ts +208 -208
  41. package/src/bootstrap/keep-tab.ts +155 -155
  42. package/src/composable/index.ts +22 -22
  43. package/src/composable/useCheckboxesMultiSelect.ts +22 -22
  44. package/src/composable/useFieldCascadeSelect.ts +9 -9
  45. package/src/composable/useFieldFileDrag.ts +9 -9
  46. package/src/composable/useFieldFlatpickr.ts +3 -3
  47. package/src/composable/useFieldModalSelect.ts +6 -6
  48. package/src/composable/useFieldModalTree.ts +3 -3
  49. package/src/composable/useFieldMultiUploader.ts +9 -9
  50. package/src/composable/useFieldRepeatable.ts +9 -9
  51. package/src/composable/useFieldSingleImageDrag.ts +9 -9
  52. package/src/composable/useForm.ts +43 -43
  53. package/src/composable/useGrid.ts +57 -57
  54. package/src/composable/useHttp.ts +9 -9
  55. package/src/composable/useIframeModal.ts +10 -10
  56. package/src/composable/useListDependent.ts +26 -26
  57. package/src/composable/useQueue.ts +13 -13
  58. package/src/composable/useS3Uploader.ts +32 -32
  59. package/src/composable/useShowOn.ts +9 -9
  60. package/src/composable/useStack.ts +13 -13
  61. package/src/composable/useTinymce.ts +29 -29
  62. package/src/composable/useTomSelect.ts +72 -72
  63. package/src/composable/useUIBootstrap5.ts +48 -48
  64. package/src/composable/useUniDirective.ts +43 -43
  65. package/src/composable/useValidation.ts +50 -50
  66. package/src/data.ts +34 -34
  67. package/src/events.ts +82 -82
  68. package/src/legacy/legacy.ts +190 -190
  69. package/src/legacy/loader.ts +125 -125
  70. package/src/module/checkboxes-multi-select.ts +54 -54
  71. package/src/module/field-cascade-select.ts +292 -292
  72. package/src/module/field-file-drag.ts +295 -295
  73. package/src/module/field-flatpickr.ts +130 -130
  74. package/src/module/field-modal-select.ts +179 -179
  75. package/src/module/field-modal-tree.ts +31 -31
  76. package/src/module/field-multi-uploader.ts +368 -368
  77. package/src/module/field-repeatable.ts +202 -202
  78. package/src/module/field-single-image-drag.ts +477 -477
  79. package/src/module/form.ts +223 -223
  80. package/src/module/grid.ts +479 -479
  81. package/src/module/http-client.ts +248 -248
  82. package/src/module/iframe-modal.ts +170 -170
  83. package/src/module/list-dependent.ts +321 -321
  84. package/src/module/s3-multipart-uploader.ts +330 -300
  85. package/src/module/s3-uploader.ts +234 -234
  86. package/src/module/show-on.ts +175 -175
  87. package/src/module/tinymce.ts +276 -276
  88. package/src/module/ui-bootstrap5.ts +116 -116
  89. package/src/module/validation.ts +1046 -1046
  90. package/src/plugin/index.ts +1 -1
  91. package/src/plugin/php-adapter.ts +72 -72
  92. package/src/polyfill/form-request-submit.ts +31 -31
  93. package/src/polyfill/index.ts +9 -9
  94. package/src/service/animate.ts +58 -58
  95. package/src/service/crypto.ts +27 -27
  96. package/src/service/dom-watcher.ts +62 -62
  97. package/src/service/dom.ts +265 -265
  98. package/src/service/helper.ts +48 -48
  99. package/src/service/index.ts +10 -10
  100. package/src/service/lang.ts +122 -122
  101. package/src/service/loader.ts +152 -152
  102. package/src/service/router.ts +118 -118
  103. package/src/service/ui.ts +525 -525
  104. package/src/service/uri.ts +106 -106
  105. package/src/types/base.ts +9 -9
  106. package/src/types/index.ts +4 -4
  107. package/src/types/modal-tree.ts +12 -12
  108. package/src/types/plugin.ts +6 -6
  109. package/src/types/shims.d.ts +18 -18
  110. package/src/types/ui.ts +6 -6
  111. package/src/unicorn.ts +79 -79
  112. package/src/utilities/arr.ts +25 -25
  113. package/src/utilities/base.ts +9 -9
  114. package/src/utilities/data.ts +48 -48
  115. package/src/utilities/index.ts +5 -5
  116. package/src/utilities/tree.ts +20 -20
  117. package/src/vue/components/ModalTree/ModalTreeApp.vue +175 -175
  118. package/src/vue/components/ModalTree/TreeItem.vue +262 -262
  119. package/src/vue/components/ModalTree/TreeModal.vue +225 -225
  120. package/tests/test.js +4 -4
  121. package/tsconfig.js.json +25 -25
  122. package/tsconfig.json +17 -17
  123. package/vite.assets.config.ts +61 -61
  124. package/vite.config.test.ts +36 -36
  125. package/vite.config.ts +112 -112
@@ -1,190 +1,190 @@
1
- import { numberFormat } from '@lyrasoft/ts-toolkit/generic';
2
- import { sprintf, vsprintf } from 'sprintf-js';
3
- import {
4
- addGlobalValidator,
5
- useBs5ButtonRadio,
6
- useBs5KeepTab,
7
- useBs5Tooltip,
8
- useCheckboxesMultiSelect,
9
- useFieldValidationInstance,
10
- useForm,
11
- useFormAsync,
12
- useFormValidation,
13
- useFormValidationInstance,
14
- useGrid,
15
- useGridAsync,
16
- useHttpClient,
17
- useQueue,
18
- useStack,
19
- useTomSelect,
20
- useUniDirective
21
- } from '../composable';
22
- import {
23
- __,
24
- animateTo,
25
- base64UrlDecode,
26
- base64UrlEncode,
27
- clearMessages,
28
- clearNotifies,
29
- debounce,
30
- delegate,
31
- domready,
32
- fadeIn,
33
- fadeOut,
34
- getBoundedInstance,
35
- getBoundedInstanceList,
36
- h,
37
- highlight,
38
- html,
39
- initAlpineComponent,
40
- isDebug,
41
- loadAlpine,
42
- mark,
43
- module,
44
- prepareAlpine,
45
- renderMessage,
46
- route,
47
- selectAll,
48
- selectOne,
49
- serial,
50
- simpleAlert,
51
- simpleConfirm,
52
- simpleNotify,
53
- slideDown,
54
- slideToggle,
55
- slideUp,
56
- throttle,
57
- tid,
58
- uid,
59
- useAssetUri,
60
- useColorPicker,
61
- useDisableIfStackNotEmpty,
62
- useDisableOnSubmit,
63
- useKeepAlive,
64
- useSystemUri
65
- } from '../service';
66
- import { LegacyLoader } from './loader';
67
-
68
- export async function useLegacyMethods(app: any) {
69
- const http = await useHttpClient();
70
-
71
- app.use(LegacyLoader);
72
-
73
- handleUri(app);
74
- handlerHelper(app);
75
- handleCrypto(app);
76
-
77
- app.__ = __;
78
- app.trans = __;
79
- app.route = route;
80
- app.$http = http;
81
- app.directive = useUniDirective;
82
-
83
- app.animate = animateTo;
84
- app.$animation = { to: animateTo };
85
-
86
- app.addMessage = renderMessage;
87
- app.clearMessages = clearMessages;
88
- app.notify = simpleNotify;
89
- app.clearNotifies = clearNotifies;
90
-
91
- app.loadAlpine = loadAlpine;
92
- app.initAlpine = initAlpineComponent;
93
- app.beforeAlpineInit = prepareAlpine;
94
- app.prepareAlpine = prepareAlpine;
95
-
96
- handleUI(app);
97
-
98
- await handleFormGrid(app);
99
-
100
- app.formValidation = useFormValidation;
101
- app.$validation = {
102
- get: useFormValidationInstance,
103
- getField: useFieldValidationInstance,
104
- addGlobalValidator: addGlobalValidator,
105
- import: () => useFormValidation()
106
- };
107
-
108
- app.stack = useStack;
109
- app.queue = useQueue;
110
- }
111
-
112
- function handleCrypto(app: any) {
113
- app.base64Encode = base64UrlEncode;
114
- app.base64Decode = base64UrlDecode;
115
- // app.uuid4 = uuid4;
116
- app.uid = uid;
117
- app.tid = tid;
118
- // app.md5 = md5;
119
- app.serial = serial;
120
- }
121
-
122
- function handleUri(app: any) {
123
- app.uri = useSystemUri;
124
- app.asset = useAssetUri;
125
- }
126
-
127
- function handlerHelper(app: any) {
128
- app.domready = domready;
129
- app.selectOne = selectOne;
130
- app.selectAll = selectAll;
131
- app.each = selectAll;
132
- app.getBoundedInstance = getBoundedInstance;
133
- app.getBoundedInstanceList = getBoundedInstanceList;
134
- app.module = module;
135
- app.h = h;
136
- app.html = html;
137
- // app.$get = get;
138
- // app.$set = set;
139
- app.delegate = delegate;
140
- app.debounce = debounce;
141
- app.throttle = throttle;
142
- app.isDebug = isDebug;
143
- app.confirm = simpleConfirm;
144
- app.alert = simpleAlert;
145
- app.numberFormat = numberFormat;
146
- app.sprintf = sprintf;
147
- app.vsprintf = vsprintf;
148
- // app.genRandomString = genRandomString;
149
- // app.defaultsDeep = defaultsDeep;
150
- }
151
-
152
- function handleUI(app: any) {
153
- app.$ui ??= {};
154
- app.$ui.addMessage = renderMessage;
155
- app.$ui.clearMessages = clearMessages;
156
- app.$ui.notify = simpleNotify;
157
- app.$ui.clearNotifies = clearNotifies;
158
-
159
- app.$ui.loadAlpine = loadAlpine;
160
- app.$ui.initAlpine = initAlpineComponent;
161
- app.$ui.beforeAlpineInit = prepareAlpine;
162
- app.$ui.prepareAlpine = prepareAlpine;
163
-
164
- app.$ui.mark = mark;
165
- app.$ui.tomSelect = useTomSelect;
166
- app.$ui.slideUp = slideUp;
167
- app.$ui.slideDown = slideDown;
168
- app.$ui.slideToggle = slideToggle;
169
- app.$ui.fadeOut = fadeOut;
170
- app.$ui.fadeIn = fadeIn;
171
- app.$ui.highlight = highlight;
172
- app.$ui.colorPicker = useColorPicker;
173
- app.$ui.disableOnSubmit = useDisableOnSubmit;
174
- app.$ui.disableIfStackNotEmpty = useDisableIfStackNotEmpty;
175
- app.$ui.checkboxesMultiSelect = useCheckboxesMultiSelect;
176
- app.$ui.keepAlive = useKeepAlive;
177
- app.$ui.bootstrap = {
178
- tooltip: useBs5Tooltip,
179
- buttonRadio: useBs5ButtonRadio,
180
- keepTab: useBs5KeepTab,
181
- };
182
- }
183
-
184
- async function handleFormGrid(app: any) {
185
- await useFormAsync();
186
- await useGridAsync();
187
-
188
- app.form = useForm;
189
- app.grid = useGrid;
190
- }
1
+ import { numberFormat } from '@lyrasoft/ts-toolkit/generic';
2
+ import { sprintf, vsprintf } from 'sprintf-js';
3
+ import {
4
+ addGlobalValidator,
5
+ useBs5ButtonRadio,
6
+ useBs5KeepTab,
7
+ useBs5Tooltip,
8
+ useCheckboxesMultiSelect,
9
+ useFieldValidationInstance,
10
+ useForm,
11
+ useFormAsync,
12
+ useFormValidation,
13
+ useFormValidationInstance,
14
+ useGrid,
15
+ useGridAsync,
16
+ useHttpClient,
17
+ useQueue,
18
+ useStack,
19
+ useTomSelect,
20
+ useUniDirective
21
+ } from '../composable';
22
+ import {
23
+ __,
24
+ animateTo,
25
+ base64UrlDecode,
26
+ base64UrlEncode,
27
+ clearMessages,
28
+ clearNotifies,
29
+ debounce,
30
+ delegate,
31
+ domready,
32
+ fadeIn,
33
+ fadeOut,
34
+ getBoundedInstance,
35
+ getBoundedInstanceList,
36
+ h,
37
+ highlight,
38
+ html,
39
+ initAlpineComponent,
40
+ isDebug,
41
+ loadAlpine,
42
+ mark,
43
+ module,
44
+ prepareAlpine,
45
+ renderMessage,
46
+ route,
47
+ selectAll,
48
+ selectOne,
49
+ serial,
50
+ simpleAlert,
51
+ simpleConfirm,
52
+ simpleNotify,
53
+ slideDown,
54
+ slideToggle,
55
+ slideUp,
56
+ throttle,
57
+ tid,
58
+ uid,
59
+ useAssetUri,
60
+ useColorPicker,
61
+ useDisableIfStackNotEmpty,
62
+ useDisableOnSubmit,
63
+ useKeepAlive,
64
+ useSystemUri
65
+ } from '../service';
66
+ import { LegacyLoader } from './loader';
67
+
68
+ export async function useLegacyMethods(app: any) {
69
+ const http = await useHttpClient();
70
+
71
+ app.use(LegacyLoader);
72
+
73
+ handleUri(app);
74
+ handlerHelper(app);
75
+ handleCrypto(app);
76
+
77
+ app.__ = __;
78
+ app.trans = __;
79
+ app.route = route;
80
+ app.$http = http;
81
+ app.directive = useUniDirective;
82
+
83
+ app.animate = animateTo;
84
+ app.$animation = { to: animateTo };
85
+
86
+ app.addMessage = renderMessage;
87
+ app.clearMessages = clearMessages;
88
+ app.notify = simpleNotify;
89
+ app.clearNotifies = clearNotifies;
90
+
91
+ app.loadAlpine = loadAlpine;
92
+ app.initAlpine = initAlpineComponent;
93
+ app.beforeAlpineInit = prepareAlpine;
94
+ app.prepareAlpine = prepareAlpine;
95
+
96
+ handleUI(app);
97
+
98
+ await handleFormGrid(app);
99
+
100
+ app.formValidation = useFormValidation;
101
+ app.$validation = {
102
+ get: useFormValidationInstance,
103
+ getField: useFieldValidationInstance,
104
+ addGlobalValidator: addGlobalValidator,
105
+ import: () => useFormValidation()
106
+ };
107
+
108
+ app.stack = useStack;
109
+ app.queue = useQueue;
110
+ }
111
+
112
+ function handleCrypto(app: any) {
113
+ app.base64Encode = base64UrlEncode;
114
+ app.base64Decode = base64UrlDecode;
115
+ // app.uuid4 = uuid4;
116
+ app.uid = uid;
117
+ app.tid = tid;
118
+ // app.md5 = md5;
119
+ app.serial = serial;
120
+ }
121
+
122
+ function handleUri(app: any) {
123
+ app.uri = useSystemUri;
124
+ app.asset = useAssetUri;
125
+ }
126
+
127
+ function handlerHelper(app: any) {
128
+ app.domready = domready;
129
+ app.selectOne = selectOne;
130
+ app.selectAll = selectAll;
131
+ app.each = selectAll;
132
+ app.getBoundedInstance = getBoundedInstance;
133
+ app.getBoundedInstanceList = getBoundedInstanceList;
134
+ app.module = module;
135
+ app.h = h;
136
+ app.html = html;
137
+ // app.$get = get;
138
+ // app.$set = set;
139
+ app.delegate = delegate;
140
+ app.debounce = debounce;
141
+ app.throttle = throttle;
142
+ app.isDebug = isDebug;
143
+ app.confirm = simpleConfirm;
144
+ app.alert = simpleAlert;
145
+ app.numberFormat = numberFormat;
146
+ app.sprintf = sprintf;
147
+ app.vsprintf = vsprintf;
148
+ // app.genRandomString = genRandomString;
149
+ // app.defaultsDeep = defaultsDeep;
150
+ }
151
+
152
+ function handleUI(app: any) {
153
+ app.$ui ??= {};
154
+ app.$ui.addMessage = renderMessage;
155
+ app.$ui.clearMessages = clearMessages;
156
+ app.$ui.notify = simpleNotify;
157
+ app.$ui.clearNotifies = clearNotifies;
158
+
159
+ app.$ui.loadAlpine = loadAlpine;
160
+ app.$ui.initAlpine = initAlpineComponent;
161
+ app.$ui.beforeAlpineInit = prepareAlpine;
162
+ app.$ui.prepareAlpine = prepareAlpine;
163
+
164
+ app.$ui.mark = mark;
165
+ app.$ui.tomSelect = useTomSelect;
166
+ app.$ui.slideUp = slideUp;
167
+ app.$ui.slideDown = slideDown;
168
+ app.$ui.slideToggle = slideToggle;
169
+ app.$ui.fadeOut = fadeOut;
170
+ app.$ui.fadeIn = fadeIn;
171
+ app.$ui.highlight = highlight;
172
+ app.$ui.colorPicker = useColorPicker;
173
+ app.$ui.disableOnSubmit = useDisableOnSubmit;
174
+ app.$ui.disableIfStackNotEmpty = useDisableIfStackNotEmpty;
175
+ app.$ui.checkboxesMultiSelect = useCheckboxesMultiSelect;
176
+ app.$ui.keepAlive = useKeepAlive;
177
+ app.$ui.bootstrap = {
178
+ tooltip: useBs5Tooltip,
179
+ buttonRadio: useBs5ButtonRadio,
180
+ keepTab: useBs5KeepTab,
181
+ };
182
+ }
183
+
184
+ async function handleFormGrid(app: any) {
185
+ await useFormAsync();
186
+ await useGridAsync();
187
+
188
+ app.form = useForm;
189
+ app.grid = useGrid;
190
+ }
@@ -1,125 +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
-
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
+