@windwalker-io/unicorn-next 0.1.18 → 0.1.21
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.
- package/dist/chunks/_arrayPush.js +325 -108
- package/dist/chunks/_arrayPush.js.map +1 -1
- package/dist/chunks/_baseRest.js +155 -60
- package/dist/chunks/_baseRest.js.map +1 -1
- package/dist/chunks/_baseUnary.js +463 -0
- package/dist/chunks/_baseUnary.js.map +1 -0
- package/dist/chunks/_getPrototype.js +292 -100
- package/dist/chunks/_getPrototype.js.map +1 -1
- package/dist/chunks/alert-adapter.js +29 -0
- package/dist/chunks/alert-adapter.js.map +1 -0
- package/dist/chunks/alert.js +21 -0
- package/dist/chunks/alert.js.map +1 -0
- package/dist/chunks/arr.js +24 -0
- package/dist/chunks/arr.js.map +1 -0
- package/dist/chunks/button-radio.js +127 -145
- package/dist/chunks/button-radio.js.map +1 -1
- package/dist/chunks/checkboxes-multi-select.js +44 -43
- package/dist/chunks/checkboxes-multi-select.js.map +1 -1
- package/dist/chunks/chunk.js +24 -0
- package/dist/chunks/cloneDeep.js +679 -212
- package/dist/chunks/cloneDeep.js.map +1 -1
- package/dist/chunks/cropper.min.js +6 -5
- package/dist/chunks/cropper.min.js.map +1 -1
- package/dist/chunks/crypto.js +26 -0
- package/dist/chunks/crypto.js.map +1 -0
- package/dist/chunks/data.js +49 -0
- package/dist/chunks/data.js.map +1 -0
- package/dist/chunks/dom.js +128 -0
- package/dist/chunks/dom.js.map +1 -0
- package/dist/chunks/events.js +270 -0
- package/dist/chunks/events.js.map +1 -0
- package/dist/chunks/field-cascade-select.js +207 -250
- package/dist/chunks/field-cascade-select.js.map +1 -1
- package/dist/chunks/field-file-drag.js +175 -209
- package/dist/chunks/field-file-drag.js.map +1 -1
- package/dist/chunks/field-flatpickr.js +94 -898
- package/dist/chunks/field-flatpickr.js.map +1 -1
- package/dist/chunks/field-modal-select.js +728 -467
- package/dist/chunks/field-modal-select.js.map +1 -1
- package/dist/chunks/field-modal-tree.js +771 -766
- package/dist/chunks/field-modal-tree.js.map +1 -1
- package/dist/chunks/field-multi-uploader.js +249 -256
- package/dist/chunks/field-multi-uploader.js.map +1 -1
- package/dist/chunks/field-repeatable.js +111 -127
- package/dist/chunks/field-repeatable.js.map +1 -1
- package/dist/chunks/field-single-image-drag.js +286 -338
- package/dist/chunks/field-single-image-drag.js.map +1 -1
- package/dist/chunks/form.js +146 -159
- package/dist/chunks/form.js.map +1 -1
- package/dist/chunks/grid.js +349 -418
- package/dist/chunks/grid.js.map +1 -1
- package/dist/chunks/helper.js +39 -0
- package/dist/chunks/helper.js.map +1 -0
- package/dist/chunks/http-client.js +221 -211
- package/dist/chunks/http-client.js.map +1 -1
- package/dist/chunks/iframe-modal.js +95 -115
- package/dist/chunks/iframe-modal.js.map +1 -1
- package/dist/chunks/keep-tab.js +92 -101
- package/dist/chunks/keep-tab.js.map +1 -1
- package/dist/chunks/lang.js +250 -0
- package/dist/chunks/lang.js.map +1 -0
- package/dist/chunks/legacy.js +197 -201
- package/dist/chunks/legacy.js.map +1 -1
- package/dist/chunks/list-dependent.js +195 -228
- package/dist/chunks/list-dependent.js.map +1 -1
- package/dist/chunks/loader.js +106 -0
- package/dist/chunks/loader.js.map +1 -0
- package/dist/chunks/monthSelect.js +251 -0
- package/dist/chunks/monthSelect.js.map +1 -0
- package/dist/chunks/router.js +111 -0
- package/dist/chunks/router.js.map +1 -0
- package/dist/chunks/s3-multipart-uploader.js +183 -210
- package/dist/chunks/s3-multipart-uploader.js.map +1 -1
- package/dist/chunks/s3-uploader.js +106 -128
- package/dist/chunks/s3-uploader.js.map +1 -1
- package/dist/chunks/show-on.js +358 -205
- package/dist/chunks/show-on.js.map +1 -1
- package/dist/chunks/timing.js +10 -0
- package/dist/chunks/timing.js.map +1 -0
- package/dist/chunks/tinymce.js +153 -203
- package/dist/chunks/tinymce.js.map +1 -1
- package/dist/chunks/ui-bootstrap5.js +58 -72
- package/dist/chunks/ui-bootstrap5.js.map +1 -1
- package/dist/chunks/ui.js +320 -0
- package/dist/chunks/ui.js.map +1 -0
- package/dist/chunks/unicorn.js.map +1 -1
- package/dist/chunks/useQueue.js +111 -0
- package/dist/chunks/useQueue.js.map +1 -0
- package/dist/chunks/useStack.js +76 -0
- package/dist/chunks/useStack.js.map +1 -0
- package/dist/chunks/validation.js +761 -853
- package/dist/chunks/validation.js.map +1 -1
- package/dist/editor.css +1 -1
- package/dist/index.d.ts +27 -15
- package/dist/multi-level-menu.css +1 -1
- package/dist/switcher.css +1 -1
- package/dist/unicorn.js +805 -130
- package/dist/unicorn.js.map +1 -1
- package/package.json +3 -3
- package/src/composable/useBsModalAlert.ts +92 -12
- package/src/composable/useHttp.ts +13 -1
- package/src/module/s3-uploader.ts +1 -1
- package/src/service/ui.ts +31 -15
- package/vite.config.ts +5 -1
- package/dist/chunks/_commonjsHelpers.js +0 -7
- package/dist/chunks/index.js +0 -314
- package/dist/chunks/isArguments.js +0 -146
- package/dist/chunks/unicorn.js +0 -2580
package/dist/chunks/unicorn.js
DELETED
|
@@ -1,2580 +0,0 @@
|
|
|
1
|
-
import { Modal } from "bootstrap";
|
|
2
|
-
const copyProps = (dest, src, exclude = []) => {
|
|
3
|
-
const props = Object.getOwnPropertyDescriptors(src);
|
|
4
|
-
for (let prop of exclude)
|
|
5
|
-
delete props[prop];
|
|
6
|
-
Object.defineProperties(dest, props);
|
|
7
|
-
};
|
|
8
|
-
const protoChain = (obj, currentChain = [obj]) => {
|
|
9
|
-
const proto = Object.getPrototypeOf(obj);
|
|
10
|
-
if (proto === null)
|
|
11
|
-
return currentChain;
|
|
12
|
-
return protoChain(proto, [...currentChain, proto]);
|
|
13
|
-
};
|
|
14
|
-
const nearestCommonProto = (...objs) => {
|
|
15
|
-
if (objs.length === 0)
|
|
16
|
-
return void 0;
|
|
17
|
-
let commonProto = void 0;
|
|
18
|
-
const protoChains = objs.map((obj) => protoChain(obj));
|
|
19
|
-
while (protoChains.every((protoChain2) => protoChain2.length > 0)) {
|
|
20
|
-
const protos = protoChains.map((protoChain2) => protoChain2.pop());
|
|
21
|
-
const potentialCommonProto = protos[0];
|
|
22
|
-
if (protos.every((proto) => proto === potentialCommonProto))
|
|
23
|
-
commonProto = potentialCommonProto;
|
|
24
|
-
else
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
return commonProto;
|
|
28
|
-
};
|
|
29
|
-
const hardMixProtos = (ingredients, constructor, exclude = []) => {
|
|
30
|
-
var _a;
|
|
31
|
-
const base = (_a = nearestCommonProto(...ingredients)) !== null && _a !== void 0 ? _a : Object.prototype;
|
|
32
|
-
const mixedProto = Object.create(base);
|
|
33
|
-
const visitedProtos = protoChain(base);
|
|
34
|
-
for (let prototype of ingredients) {
|
|
35
|
-
let protos = protoChain(prototype);
|
|
36
|
-
for (let i = protos.length - 1; i >= 0; i--) {
|
|
37
|
-
let newProto = protos[i];
|
|
38
|
-
if (visitedProtos.indexOf(newProto) === -1) {
|
|
39
|
-
copyProps(mixedProto, newProto, ["constructor", ...exclude]);
|
|
40
|
-
visitedProtos.push(newProto);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
mixedProto.constructor = constructor;
|
|
45
|
-
return mixedProto;
|
|
46
|
-
};
|
|
47
|
-
const unique = (arr) => arr.filter((e, i) => arr.indexOf(e) == i);
|
|
48
|
-
const mixins = /* @__PURE__ */ new WeakMap();
|
|
49
|
-
const getMixinsForClass = (clazz) => mixins.get(clazz);
|
|
50
|
-
const registerMixins = (mixedClass, constituents) => mixins.set(mixedClass, constituents);
|
|
51
|
-
const mergeObjectsOfDecorators = (o1, o2) => {
|
|
52
|
-
var _a, _b;
|
|
53
|
-
const allKeys = unique([...Object.getOwnPropertyNames(o1), ...Object.getOwnPropertyNames(o2)]);
|
|
54
|
-
const mergedObject = {};
|
|
55
|
-
for (let key of allKeys)
|
|
56
|
-
mergedObject[key] = unique([...(_a = o1 === null || o1 === void 0 ? void 0 : o1[key]) !== null && _a !== void 0 ? _a : [], ...(_b = o2 === null || o2 === void 0 ? void 0 : o2[key]) !== null && _b !== void 0 ? _b : []]);
|
|
57
|
-
return mergedObject;
|
|
58
|
-
};
|
|
59
|
-
const mergePropertyAndMethodDecorators = (d1, d2) => {
|
|
60
|
-
var _a, _b, _c, _d;
|
|
61
|
-
return {
|
|
62
|
-
property: mergeObjectsOfDecorators((_a = d1 === null || d1 === void 0 ? void 0 : d1.property) !== null && _a !== void 0 ? _a : {}, (_b = d2 === null || d2 === void 0 ? void 0 : d2.property) !== null && _b !== void 0 ? _b : {}),
|
|
63
|
-
method: mergeObjectsOfDecorators((_c = d1 === null || d1 === void 0 ? void 0 : d1.method) !== null && _c !== void 0 ? _c : {}, (_d = d2 === null || d2 === void 0 ? void 0 : d2.method) !== null && _d !== void 0 ? _d : {})
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
const mergeDecorators = (d1, d2) => {
|
|
67
|
-
var _a, _b, _c, _d, _e, _f;
|
|
68
|
-
return {
|
|
69
|
-
class: unique([...(_a = d1 === null || d1 === void 0 ? void 0 : d1.class) !== null && _a !== void 0 ? _a : [], ...(_b = d2 === null || d2 === void 0 ? void 0 : d2.class) !== null && _b !== void 0 ? _b : []]),
|
|
70
|
-
static: mergePropertyAndMethodDecorators((_c = d1 === null || d1 === void 0 ? void 0 : d1.static) !== null && _c !== void 0 ? _c : {}, (_d = d2 === null || d2 === void 0 ? void 0 : d2.static) !== null && _d !== void 0 ? _d : {}),
|
|
71
|
-
instance: mergePropertyAndMethodDecorators((_e = d1 === null || d1 === void 0 ? void 0 : d1.instance) !== null && _e !== void 0 ? _e : {}, (_f = d2 === null || d2 === void 0 ? void 0 : d2.instance) !== null && _f !== void 0 ? _f : {})
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
const decorators = /* @__PURE__ */ new Map();
|
|
75
|
-
const findAllConstituentClasses = (...classes) => {
|
|
76
|
-
var _a;
|
|
77
|
-
const allClasses = /* @__PURE__ */ new Set();
|
|
78
|
-
const frontier = /* @__PURE__ */ new Set([...classes]);
|
|
79
|
-
while (frontier.size > 0) {
|
|
80
|
-
for (let clazz of frontier) {
|
|
81
|
-
const protoChainClasses = protoChain(clazz.prototype).map((proto) => proto.constructor);
|
|
82
|
-
const mixinClasses = (_a = getMixinsForClass(clazz)) !== null && _a !== void 0 ? _a : [];
|
|
83
|
-
const potentiallyNewClasses = [...protoChainClasses, ...mixinClasses];
|
|
84
|
-
const newClasses = potentiallyNewClasses.filter((c) => !allClasses.has(c));
|
|
85
|
-
for (let newClass of newClasses)
|
|
86
|
-
frontier.add(newClass);
|
|
87
|
-
allClasses.add(clazz);
|
|
88
|
-
frontier.delete(clazz);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return [...allClasses];
|
|
92
|
-
};
|
|
93
|
-
const deepDecoratorSearch = (...classes) => {
|
|
94
|
-
const decoratorsForClassChain = findAllConstituentClasses(...classes).map((clazz) => decorators.get(clazz)).filter((decorators2) => !!decorators2);
|
|
95
|
-
if (decoratorsForClassChain.length == 0)
|
|
96
|
-
return {};
|
|
97
|
-
if (decoratorsForClassChain.length == 1)
|
|
98
|
-
return decoratorsForClassChain[0];
|
|
99
|
-
return decoratorsForClassChain.reduce((d1, d2) => mergeDecorators(d1, d2));
|
|
100
|
-
};
|
|
101
|
-
function Mixin(...constructors) {
|
|
102
|
-
var _a, _b, _c;
|
|
103
|
-
const prototypes = constructors.map((constructor) => constructor.prototype);
|
|
104
|
-
function MixedClass(...args) {
|
|
105
|
-
for (const constructor of constructors)
|
|
106
|
-
copyProps(this, new constructor(...args));
|
|
107
|
-
}
|
|
108
|
-
MixedClass.prototype = hardMixProtos(prototypes, MixedClass);
|
|
109
|
-
Object.setPrototypeOf(
|
|
110
|
-
MixedClass,
|
|
111
|
-
hardMixProtos(constructors, null, ["prototype"])
|
|
112
|
-
);
|
|
113
|
-
let DecoratedMixedClass = MixedClass;
|
|
114
|
-
{
|
|
115
|
-
const classDecorators = deepDecoratorSearch(...constructors);
|
|
116
|
-
for (let decorator of (_a = classDecorators === null || classDecorators === void 0 ? void 0 : classDecorators.class) !== null && _a !== void 0 ? _a : []) {
|
|
117
|
-
const result = decorator(DecoratedMixedClass);
|
|
118
|
-
if (result) {
|
|
119
|
-
DecoratedMixedClass = result;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
applyPropAndMethodDecorators((_b = classDecorators === null || classDecorators === void 0 ? void 0 : classDecorators.static) !== null && _b !== void 0 ? _b : {}, DecoratedMixedClass);
|
|
123
|
-
applyPropAndMethodDecorators((_c = classDecorators === null || classDecorators === void 0 ? void 0 : classDecorators.instance) !== null && _c !== void 0 ? _c : {}, DecoratedMixedClass.prototype);
|
|
124
|
-
}
|
|
125
|
-
registerMixins(DecoratedMixedClass, constructors);
|
|
126
|
-
return DecoratedMixedClass;
|
|
127
|
-
}
|
|
128
|
-
const applyPropAndMethodDecorators = (propAndMethodDecorators, target) => {
|
|
129
|
-
const propDecorators = propAndMethodDecorators.property;
|
|
130
|
-
const methodDecorators = propAndMethodDecorators.method;
|
|
131
|
-
if (propDecorators)
|
|
132
|
-
for (let key in propDecorators)
|
|
133
|
-
for (let decorator of propDecorators[key])
|
|
134
|
-
decorator(target, key);
|
|
135
|
-
if (methodDecorators)
|
|
136
|
-
for (let key in methodDecorators)
|
|
137
|
-
for (let decorator of methodDecorators[key])
|
|
138
|
-
decorator(target, key, Object.getOwnPropertyDescriptor(target, key));
|
|
139
|
-
};
|
|
140
|
-
function isPlainObject(val) {
|
|
141
|
-
return val && typeof val === "object" && !Array.isArray(val);
|
|
142
|
-
}
|
|
143
|
-
function mergeDeep(target, ...sources) {
|
|
144
|
-
let out = isPlainObject(target) ? { ...target } : target;
|
|
145
|
-
for (const source of sources) {
|
|
146
|
-
if (Array.isArray(source)) {
|
|
147
|
-
out = Array.isArray(out) ? out.concat(source) : source;
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
if (isPlainObject(source)) {
|
|
151
|
-
out = { ...isPlainObject(out) ? out : {} };
|
|
152
|
-
for (const key of Object.keys(source)) {
|
|
153
|
-
out[key] = key in out ? mergeDeep(out[key], source[key]) : source[key];
|
|
154
|
-
}
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
out = source;
|
|
158
|
-
}
|
|
159
|
-
return out;
|
|
160
|
-
}
|
|
161
|
-
function getData(element, name) {
|
|
162
|
-
prepareData(element);
|
|
163
|
-
if (name === void 0) {
|
|
164
|
-
return element.__unicorn;
|
|
165
|
-
}
|
|
166
|
-
return element.__unicorn[name];
|
|
167
|
-
}
|
|
168
|
-
function setData(element, name, value) {
|
|
169
|
-
prepareData(element);
|
|
170
|
-
element.__unicorn[name] = value;
|
|
171
|
-
}
|
|
172
|
-
function defData(element, name, defCallback) {
|
|
173
|
-
prepareData(element);
|
|
174
|
-
element.__unicorn[name] = element.__unicorn[name] || defCallback(element);
|
|
175
|
-
return element.__unicorn[name];
|
|
176
|
-
}
|
|
177
|
-
function removeData$1(element, name) {
|
|
178
|
-
prepareData(element);
|
|
179
|
-
const v = element.__unicorn[name];
|
|
180
|
-
delete element.__unicorn[name];
|
|
181
|
-
return v;
|
|
182
|
-
}
|
|
183
|
-
function prepareData(element) {
|
|
184
|
-
if (!element) {
|
|
185
|
-
return element;
|
|
186
|
-
}
|
|
187
|
-
element.__unicorn = element.__unicorn || {};
|
|
188
|
-
return element;
|
|
189
|
-
}
|
|
190
|
-
function domready(callback) {
|
|
191
|
-
let promise = new Promise((resolve) => {
|
|
192
|
-
if (document.readyState === "complete" || document.readyState === "interactive") {
|
|
193
|
-
setTimeout(resolve, 0);
|
|
194
|
-
} else {
|
|
195
|
-
document.addEventListener("DOMContentLoaded", () => resolve());
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
if (callback) {
|
|
199
|
-
promise = promise.then(callback);
|
|
200
|
-
}
|
|
201
|
-
return promise;
|
|
202
|
-
}
|
|
203
|
-
function selectOne(ele) {
|
|
204
|
-
let r;
|
|
205
|
-
if (typeof ele === "string") {
|
|
206
|
-
r = document.querySelector(ele);
|
|
207
|
-
} else {
|
|
208
|
-
r = ele;
|
|
209
|
-
}
|
|
210
|
-
if (!r) {
|
|
211
|
-
return r;
|
|
212
|
-
}
|
|
213
|
-
return r;
|
|
214
|
-
}
|
|
215
|
-
function selectAll(ele, callback = void 0) {
|
|
216
|
-
if (typeof ele === "string") {
|
|
217
|
-
ele = document.querySelectorAll(ele);
|
|
218
|
-
}
|
|
219
|
-
const resultSet = [].slice.call(ele);
|
|
220
|
-
if (callback) {
|
|
221
|
-
return resultSet.map((el) => callback(el) || el);
|
|
222
|
-
}
|
|
223
|
-
return resultSet;
|
|
224
|
-
}
|
|
225
|
-
function getBoundedInstance(selector, name, callback = () => null) {
|
|
226
|
-
const element = typeof selector === "string" ? document.querySelector(selector) : selector;
|
|
227
|
-
if (!element) {
|
|
228
|
-
return null;
|
|
229
|
-
}
|
|
230
|
-
return defData(element, name, callback);
|
|
231
|
-
}
|
|
232
|
-
function getBoundedInstanceList(selector, name, callback = () => null) {
|
|
233
|
-
const items = typeof selector === "string" ? document.querySelectorAll(selector) : selector;
|
|
234
|
-
return Array.from(items).map((ele) => getBoundedInstance(ele, name, callback));
|
|
235
|
-
}
|
|
236
|
-
function removeBoundedInstance(selector, name) {
|
|
237
|
-
const element = typeof selector === "string" ? document.querySelector(selector) : selector;
|
|
238
|
-
if (element) {
|
|
239
|
-
removeData(element, name);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
function module$1(ele, name, callback = () => null) {
|
|
243
|
-
if (callback === false) {
|
|
244
|
-
if (typeof ele === "string" || ele instanceof Element) {
|
|
245
|
-
removeBoundedInstance(ele, name);
|
|
246
|
-
return null;
|
|
247
|
-
}
|
|
248
|
-
Array.from(ele).forEach((el) => removeBoundedInstance(el, name));
|
|
249
|
-
return null;
|
|
250
|
-
}
|
|
251
|
-
if (typeof ele === "string") {
|
|
252
|
-
return getBoundedInstanceList(ele, name, callback);
|
|
253
|
-
}
|
|
254
|
-
if (ele instanceof HTMLElement) {
|
|
255
|
-
return getBoundedInstance(ele, name, callback);
|
|
256
|
-
}
|
|
257
|
-
return getBoundedInstanceList(ele, name, callback);
|
|
258
|
-
}
|
|
259
|
-
function h(element, attrs = {}, content = void 0) {
|
|
260
|
-
const ele = document.createElement(element);
|
|
261
|
-
for (let i in attrs) {
|
|
262
|
-
const v = attrs[i];
|
|
263
|
-
ele.setAttribute(i, v);
|
|
264
|
-
}
|
|
265
|
-
if (content !== null) {
|
|
266
|
-
ele.innerHTML = content;
|
|
267
|
-
}
|
|
268
|
-
return ele;
|
|
269
|
-
}
|
|
270
|
-
function html(html2) {
|
|
271
|
-
const div = document.createElement("div");
|
|
272
|
-
div.innerHTML = html2;
|
|
273
|
-
return div.children[0];
|
|
274
|
-
}
|
|
275
|
-
function delegate(wrapper, selector, eventName, callback) {
|
|
276
|
-
if (typeof selector === "undefined" || selector === "") {
|
|
277
|
-
throw new Error("The provided selector is empty.");
|
|
278
|
-
}
|
|
279
|
-
if (typeof callback === "undefined" || typeof callback !== "function") {
|
|
280
|
-
throw new Error("Please specify an callback.");
|
|
281
|
-
}
|
|
282
|
-
const delegationSelectorsMap = {};
|
|
283
|
-
const wrapperElement = selectOne(wrapper);
|
|
284
|
-
wrapperElement?.addEventListener(eventName, function(event) {
|
|
285
|
-
let element = event.target;
|
|
286
|
-
let forceBreak = false;
|
|
287
|
-
while (element && element !== wrapperElement) {
|
|
288
|
-
for (const selector2 in delegationSelectorsMap) {
|
|
289
|
-
if (element.matches(selector2)) {
|
|
290
|
-
event.stopPropagation = function() {
|
|
291
|
-
forceBreak = true;
|
|
292
|
-
};
|
|
293
|
-
Object.defineProperty(
|
|
294
|
-
event,
|
|
295
|
-
"currentTarget",
|
|
296
|
-
{
|
|
297
|
-
get() {
|
|
298
|
-
return element;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
);
|
|
302
|
-
const callbackList = delegationSelectorsMap[selector2];
|
|
303
|
-
callbackList.forEach(function(callback2) {
|
|
304
|
-
callback2(event);
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
if (forceBreak) {
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
element = element.parentElement;
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
if (!delegationSelectorsMap[selector]) {
|
|
315
|
-
delegationSelectorsMap[selector] = [callback];
|
|
316
|
-
} else {
|
|
317
|
-
delegationSelectorsMap[selector].push(callback);
|
|
318
|
-
}
|
|
319
|
-
return function unsubscribe() {
|
|
320
|
-
if (!delegationSelectorsMap[selector]) {
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
if (delegationSelectorsMap[selector].length >= 2) {
|
|
324
|
-
delegationSelectorsMap[selector] = delegationSelectorsMap[selector].filter((cb) => cb !== callback);
|
|
325
|
-
} else {
|
|
326
|
-
delete delegationSelectorsMap[selector];
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
async function injectCssToDocument(doc, ...css) {
|
|
331
|
-
if (!(doc instanceof Document)) {
|
|
332
|
-
css.push(doc);
|
|
333
|
-
doc = document;
|
|
334
|
-
}
|
|
335
|
-
const promises = [];
|
|
336
|
-
for (let cssItem of css) {
|
|
337
|
-
promises.push(
|
|
338
|
-
new Promise((resolve, reject) => {
|
|
339
|
-
if (cssItem instanceof CSSStyleSheet) {
|
|
340
|
-
resolve(cssItem);
|
|
341
|
-
} else if (typeof cssItem === "string") {
|
|
342
|
-
const style = new CSSStyleSheet();
|
|
343
|
-
style.replace(cssItem).then(() => resolve(style)).catch(reject);
|
|
344
|
-
} else if (typeof cssItem === "function") {
|
|
345
|
-
cssItem().then(({ default: result }) => {
|
|
346
|
-
const style = new CSSStyleSheet();
|
|
347
|
-
style.replace(result).then(() => resolve(style)).catch(reject);
|
|
348
|
-
}).catch(reject);
|
|
349
|
-
} else {
|
|
350
|
-
reject(new Error("Invalid CSS source"));
|
|
351
|
-
}
|
|
352
|
-
})
|
|
353
|
-
);
|
|
354
|
-
}
|
|
355
|
-
const styles = await Promise.all(promises);
|
|
356
|
-
doc.adoptedStyleSheets = [...doc.adoptedStyleSheets, ...styles];
|
|
357
|
-
return styles;
|
|
358
|
-
}
|
|
359
|
-
function animateTo(element, styles, options = {}) {
|
|
360
|
-
element = selectOne(element);
|
|
361
|
-
const currentStyles = window.getComputedStyle(element);
|
|
362
|
-
const transitions = {};
|
|
363
|
-
for (const name in styles) {
|
|
364
|
-
const value = styles[name];
|
|
365
|
-
transitions[name] = Array.isArray(value) ? value : [
|
|
366
|
-
currentStyles.getPropertyValue(name),
|
|
367
|
-
value
|
|
368
|
-
];
|
|
369
|
-
}
|
|
370
|
-
if (typeof options === "number") {
|
|
371
|
-
options = { duration: options };
|
|
372
|
-
}
|
|
373
|
-
options = Object.assign(
|
|
374
|
-
{
|
|
375
|
-
duration: 400,
|
|
376
|
-
easing: "linear",
|
|
377
|
-
fill: "both"
|
|
378
|
-
},
|
|
379
|
-
options
|
|
380
|
-
);
|
|
381
|
-
const animation = element.animate(
|
|
382
|
-
transitions,
|
|
383
|
-
options
|
|
384
|
-
);
|
|
385
|
-
animation.addEventListener("finish", () => {
|
|
386
|
-
for (const name in styles) {
|
|
387
|
-
const value = styles[name];
|
|
388
|
-
element.style.setProperty(
|
|
389
|
-
name,
|
|
390
|
-
Array.isArray(value) ? value[value.length - 1] : value
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
animation.cancel();
|
|
394
|
-
});
|
|
395
|
-
return animation;
|
|
396
|
-
}
|
|
397
|
-
const _AlertAdapter = class _AlertAdapter {
|
|
398
|
-
};
|
|
399
|
-
_AlertAdapter.alert = async (title, text) => {
|
|
400
|
-
if (text) {
|
|
401
|
-
title += " | " + text;
|
|
402
|
-
}
|
|
403
|
-
return window.alert(title);
|
|
404
|
-
};
|
|
405
|
-
_AlertAdapter.confirm = async (title, text) => {
|
|
406
|
-
return new Promise((resolve) => {
|
|
407
|
-
if (text) {
|
|
408
|
-
title += " | " + text;
|
|
409
|
-
}
|
|
410
|
-
const v = confirm(title);
|
|
411
|
-
resolve(v);
|
|
412
|
-
});
|
|
413
|
-
};
|
|
414
|
-
_AlertAdapter.deleteConfirm = async (title, text) => _AlertAdapter.confirm(title, text);
|
|
415
|
-
_AlertAdapter.notify = async (title, text, type = "log") => {
|
|
416
|
-
if (text) {
|
|
417
|
-
title += " | " + text;
|
|
418
|
-
}
|
|
419
|
-
if (type === "error") {
|
|
420
|
-
console.error(title);
|
|
421
|
-
} else if (type === "warn") {
|
|
422
|
-
console.warn(title);
|
|
423
|
-
} else {
|
|
424
|
-
console.log(title);
|
|
425
|
-
}
|
|
426
|
-
return async () => {
|
|
427
|
-
};
|
|
428
|
-
};
|
|
429
|
-
_AlertAdapter.clearNotifies = async () => {
|
|
430
|
-
};
|
|
431
|
-
_AlertAdapter.confirmText = () => "OK";
|
|
432
|
-
_AlertAdapter.cancelText = () => "Cancel";
|
|
433
|
-
_AlertAdapter.deleteText = () => "Delete";
|
|
434
|
-
let AlertAdapter = _AlertAdapter;
|
|
435
|
-
async function simpleAlert(title, text = "", icon = "info", extra) {
|
|
436
|
-
return AlertAdapter.alert(title, text, icon, extra);
|
|
437
|
-
}
|
|
438
|
-
async function simpleConfirm(title, text = "", icon = "info", extra) {
|
|
439
|
-
return AlertAdapter.confirm(title, text, icon, extra);
|
|
440
|
-
}
|
|
441
|
-
async function deleteConfirm(title, text = "", icon = "info", extra) {
|
|
442
|
-
return AlertAdapter.deleteConfirm(title, text, icon, extra);
|
|
443
|
-
}
|
|
444
|
-
async function simpleNotify(title, text = "", type = "info", extra) {
|
|
445
|
-
return AlertAdapter.notify(title, text, type, extra);
|
|
446
|
-
}
|
|
447
|
-
async function clearNotifies() {
|
|
448
|
-
return AlertAdapter.clearNotifies();
|
|
449
|
-
}
|
|
450
|
-
function isNode() {
|
|
451
|
-
return typeof window === "undefined";
|
|
452
|
-
}
|
|
453
|
-
function uid(prefix = "", timebase = false) {
|
|
454
|
-
if (timebase) {
|
|
455
|
-
const start = performance?.timeOrigin ? Math.round(performance.timeOrigin) : performance.timing.navigationStart;
|
|
456
|
-
const time = start * 1e5 + performance.now() * 100;
|
|
457
|
-
return prefix + time.toString(12) + randomBytesString(4);
|
|
458
|
-
}
|
|
459
|
-
return prefix + randomBytesString(12);
|
|
460
|
-
}
|
|
461
|
-
function tid(prefix = "") {
|
|
462
|
-
return uid(prefix, true);
|
|
463
|
-
}
|
|
464
|
-
function randomBytesString(size = 12) {
|
|
465
|
-
if (!isNode() && !globalThis.crypto) {
|
|
466
|
-
return String(Math.floor(Math.random() * size ** 10));
|
|
467
|
-
}
|
|
468
|
-
return Array.from(randomBytes(size)).map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
469
|
-
}
|
|
470
|
-
function randomBytes(size = 12) {
|
|
471
|
-
const arr = new Uint8Array(size);
|
|
472
|
-
globalThis.crypto.getRandomValues(arr);
|
|
473
|
-
return arr;
|
|
474
|
-
}
|
|
475
|
-
function promiseWithResolvers() {
|
|
476
|
-
let resolve;
|
|
477
|
-
let reject;
|
|
478
|
-
const promise = new Promise((rs, rj) => {
|
|
479
|
-
resolve = rs;
|
|
480
|
-
reject = rj;
|
|
481
|
-
});
|
|
482
|
-
return { promise, resolve, reject };
|
|
483
|
-
}
|
|
484
|
-
class TaskQueue {
|
|
485
|
-
constructor(maxRunning = 1) {
|
|
486
|
-
this.maxRunning = maxRunning;
|
|
487
|
-
this.items = [];
|
|
488
|
-
this.currentRunning = 0;
|
|
489
|
-
this.running = false;
|
|
490
|
-
this.observers = [];
|
|
491
|
-
}
|
|
492
|
-
push(callback) {
|
|
493
|
-
const p = new Promise((resolve, reject) => {
|
|
494
|
-
this.items.push(() => {
|
|
495
|
-
return Promise.resolve(callback()).then(resolve).catch(reject);
|
|
496
|
-
});
|
|
497
|
-
});
|
|
498
|
-
this.run();
|
|
499
|
-
return p;
|
|
500
|
-
}
|
|
501
|
-
run() {
|
|
502
|
-
if (!this.running) {
|
|
503
|
-
this.running = true;
|
|
504
|
-
}
|
|
505
|
-
this.pop();
|
|
506
|
-
}
|
|
507
|
-
async pop() {
|
|
508
|
-
const callback = this.items.shift();
|
|
509
|
-
if (!callback) {
|
|
510
|
-
this.running = false;
|
|
511
|
-
return Promise.resolve();
|
|
512
|
-
}
|
|
513
|
-
if (this.currentRunning >= this.maxRunning) {
|
|
514
|
-
this.items.unshift(callback);
|
|
515
|
-
return Promise.resolve();
|
|
516
|
-
}
|
|
517
|
-
this.currentRunning++;
|
|
518
|
-
this.notice();
|
|
519
|
-
try {
|
|
520
|
-
return await callback();
|
|
521
|
-
} catch (e) {
|
|
522
|
-
throw e;
|
|
523
|
-
} finally {
|
|
524
|
-
this.endPop();
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
endPop() {
|
|
528
|
-
this.currentRunning--;
|
|
529
|
-
this.notice();
|
|
530
|
-
this.pop();
|
|
531
|
-
}
|
|
532
|
-
clear() {
|
|
533
|
-
this.items = [];
|
|
534
|
-
this.notice();
|
|
535
|
-
return this;
|
|
536
|
-
}
|
|
537
|
-
isEmpty() {
|
|
538
|
-
return this.items.length === 0;
|
|
539
|
-
}
|
|
540
|
-
get length() {
|
|
541
|
-
return this.items.length;
|
|
542
|
-
}
|
|
543
|
-
peek() {
|
|
544
|
-
return this.items;
|
|
545
|
-
}
|
|
546
|
-
observe(handler, options = {}) {
|
|
547
|
-
this.observers.push({
|
|
548
|
-
handler,
|
|
549
|
-
once: options.once || false
|
|
550
|
-
});
|
|
551
|
-
return () => {
|
|
552
|
-
this.off(handler);
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
once(handler, options = {}) {
|
|
556
|
-
options.once = true;
|
|
557
|
-
return this.observe(handler, options);
|
|
558
|
-
}
|
|
559
|
-
onEnd(callback, options = {}) {
|
|
560
|
-
return this.observe((queue2, length, running) => {
|
|
561
|
-
if (length === 0 && running === 0) {
|
|
562
|
-
callback(queue2, length, running);
|
|
563
|
-
}
|
|
564
|
-
}, options);
|
|
565
|
-
}
|
|
566
|
-
notice() {
|
|
567
|
-
this.observers.forEach((observer) => {
|
|
568
|
-
observer.handler(this, this.length, this.currentRunning);
|
|
569
|
-
});
|
|
570
|
-
this.observers = this.observers.filter((observer) => !observer.once);
|
|
571
|
-
return this;
|
|
572
|
-
}
|
|
573
|
-
off(callback) {
|
|
574
|
-
if (callback == null) {
|
|
575
|
-
this.observers = [];
|
|
576
|
-
return this;
|
|
577
|
-
}
|
|
578
|
-
this.observers = this.observers.filter((observer) => observer.handler !== callback);
|
|
579
|
-
return this;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
function queue(maxRunning = 1) {
|
|
583
|
-
return new TaskQueue(maxRunning);
|
|
584
|
-
}
|
|
585
|
-
class Stack {
|
|
586
|
-
constructor(store = []) {
|
|
587
|
-
this.store = store;
|
|
588
|
-
this.observers = [];
|
|
589
|
-
}
|
|
590
|
-
push(value) {
|
|
591
|
-
const r = this.store.push(value ?? true);
|
|
592
|
-
this.notice();
|
|
593
|
-
return r;
|
|
594
|
-
}
|
|
595
|
-
pop() {
|
|
596
|
-
const r = this.store.pop();
|
|
597
|
-
this.notice();
|
|
598
|
-
return r;
|
|
599
|
-
}
|
|
600
|
-
clear() {
|
|
601
|
-
this.store = [];
|
|
602
|
-
this.notice();
|
|
603
|
-
return this;
|
|
604
|
-
}
|
|
605
|
-
isEmpty() {
|
|
606
|
-
return this.store.length === 0;
|
|
607
|
-
}
|
|
608
|
-
get length() {
|
|
609
|
-
return this.store.length;
|
|
610
|
-
}
|
|
611
|
-
peek() {
|
|
612
|
-
return this.store;
|
|
613
|
-
}
|
|
614
|
-
observe(handler) {
|
|
615
|
-
this.observers.push({
|
|
616
|
-
handler,
|
|
617
|
-
once: false
|
|
618
|
-
});
|
|
619
|
-
return () => {
|
|
620
|
-
this.off(handler);
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
once(handler) {
|
|
624
|
-
this.observers.push({
|
|
625
|
-
handler,
|
|
626
|
-
once: true
|
|
627
|
-
});
|
|
628
|
-
return () => {
|
|
629
|
-
this.off(handler);
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
notice() {
|
|
633
|
-
this.observers.forEach((observer) => {
|
|
634
|
-
observer.handler(this, this.length);
|
|
635
|
-
});
|
|
636
|
-
this.observers = this.observers.filter((observer) => observer.once !== true);
|
|
637
|
-
return this;
|
|
638
|
-
}
|
|
639
|
-
off(callback) {
|
|
640
|
-
this.observers = this.observers.filter((observer) => observer.handler !== callback);
|
|
641
|
-
return this;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
function stack(store = []) {
|
|
645
|
-
return new Stack(store);
|
|
646
|
-
}
|
|
647
|
-
function sleep(time) {
|
|
648
|
-
return new Promise((resolve) => {
|
|
649
|
-
setTimeout(resolve, time);
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
|
-
function base64UrlEncode(string) {
|
|
653
|
-
return btoa(String(string)).replace(/\+/, "-").replace(new RegExp("\\/"), "_").replace(/=+$/, "");
|
|
654
|
-
}
|
|
655
|
-
function base64UrlDecode(string) {
|
|
656
|
-
return atob(
|
|
657
|
-
String(string).replace(/-/, "+").replace(/_/, "/")
|
|
658
|
-
);
|
|
659
|
-
}
|
|
660
|
-
let globalSerial = 1;
|
|
661
|
-
function serial() {
|
|
662
|
-
return globalSerial++;
|
|
663
|
-
}
|
|
664
|
-
function watchAttributes(el, callback) {
|
|
665
|
-
return new AttributeMutationObserver(el, callback);
|
|
666
|
-
}
|
|
667
|
-
class AttributeMutationObserver {
|
|
668
|
-
constructor(element, callback) {
|
|
669
|
-
this.element = element;
|
|
670
|
-
this.callback = callback;
|
|
671
|
-
this.element = element;
|
|
672
|
-
this.observer = new MutationObserver((mutations) => {
|
|
673
|
-
for (const mutation of mutations) {
|
|
674
|
-
if (mutation.type === "attributes") {
|
|
675
|
-
const attrName = mutation.attributeName;
|
|
676
|
-
const target = mutation.target;
|
|
677
|
-
const value = target.getAttribute(attrName);
|
|
678
|
-
this.callback?.(
|
|
679
|
-
target,
|
|
680
|
-
attrName,
|
|
681
|
-
value,
|
|
682
|
-
mutation.oldValue
|
|
683
|
-
);
|
|
684
|
-
if (this.watches[attrName]) {
|
|
685
|
-
for (const watch of this.watches[attrName]) {
|
|
686
|
-
watch(target, value, mutation.oldValue);
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
});
|
|
692
|
-
this.observe();
|
|
693
|
-
}
|
|
694
|
-
observer;
|
|
695
|
-
watches = {};
|
|
696
|
-
watch(name, callback) {
|
|
697
|
-
this.watches[name] ??= [];
|
|
698
|
-
this.watches[name].push(callback);
|
|
699
|
-
return () => {
|
|
700
|
-
this.watches[name] = this.watches[name].filter((fn) => fn !== callback);
|
|
701
|
-
};
|
|
702
|
-
}
|
|
703
|
-
observe() {
|
|
704
|
-
this.observer.observe(this.element, {
|
|
705
|
-
attributes: true,
|
|
706
|
-
attributeOldValue: true
|
|
707
|
-
});
|
|
708
|
-
}
|
|
709
|
-
disconnect() {
|
|
710
|
-
this.observer.disconnect();
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
function forceArray(item) {
|
|
714
|
-
if (Array.isArray(item)) {
|
|
715
|
-
return item;
|
|
716
|
-
} else {
|
|
717
|
-
return [item];
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
function debounce(handler, wait2 = 1) {
|
|
721
|
-
let timer, result;
|
|
722
|
-
return function(...args) {
|
|
723
|
-
clearTimeout(timer);
|
|
724
|
-
timer = setTimeout(() => result = handler.call(this, ...args), wait2);
|
|
725
|
-
return result;
|
|
726
|
-
};
|
|
727
|
-
}
|
|
728
|
-
function throttle(handler, wait2 = 1) {
|
|
729
|
-
return function(...args) {
|
|
730
|
-
{
|
|
731
|
-
return handler.call(this, ...args);
|
|
732
|
-
}
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
function isDebug() {
|
|
736
|
-
return Boolean(data("windwalker.debug"));
|
|
737
|
-
}
|
|
738
|
-
function nextTick(callback) {
|
|
739
|
-
return Promise.resolve().then(callback ?? (() => null));
|
|
740
|
-
}
|
|
741
|
-
function wait(...promisee) {
|
|
742
|
-
return Promise.all(promisee);
|
|
743
|
-
}
|
|
744
|
-
function isError(e) {
|
|
745
|
-
return e instanceof Error;
|
|
746
|
-
}
|
|
747
|
-
var sprintf = {};
|
|
748
|
-
var hasRequiredSprintf;
|
|
749
|
-
function requireSprintf() {
|
|
750
|
-
if (hasRequiredSprintf) return sprintf;
|
|
751
|
-
hasRequiredSprintf = 1;
|
|
752
|
-
(function(exports$1) {
|
|
753
|
-
!(function() {
|
|
754
|
-
var re = {
|
|
755
|
-
not_type: /[^T]/,
|
|
756
|
-
not_primitive: /[^v]/,
|
|
757
|
-
number: /[diefg]/,
|
|
758
|
-
numeric_arg: /[bcdiefguxX]/,
|
|
759
|
-
json: /[j]/,
|
|
760
|
-
text: /^[^\x25]+/,
|
|
761
|
-
modulo: /^\x25{2}/,
|
|
762
|
-
placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
|
|
763
|
-
key: /^([a-z_][a-z_\d]*)/i,
|
|
764
|
-
key_access: /^\.([a-z_][a-z_\d]*)/i,
|
|
765
|
-
index_access: /^\[(\d+)\]/,
|
|
766
|
-
sign: /^[+-]/
|
|
767
|
-
};
|
|
768
|
-
function sprintf2(key) {
|
|
769
|
-
return sprintf_format(sprintf_parse(key), arguments);
|
|
770
|
-
}
|
|
771
|
-
function vsprintf(fmt, argv) {
|
|
772
|
-
return sprintf2.apply(null, [fmt].concat(argv || []));
|
|
773
|
-
}
|
|
774
|
-
function sprintf_format(parse_tree, argv) {
|
|
775
|
-
var cursor = 1, tree_length = parse_tree.length, arg, output = "", i, k, ph, pad, pad_character, pad_length, is_positive, sign;
|
|
776
|
-
for (i = 0; i < tree_length; i++) {
|
|
777
|
-
if (typeof parse_tree[i] === "string") {
|
|
778
|
-
output += parse_tree[i];
|
|
779
|
-
} else if (typeof parse_tree[i] === "object") {
|
|
780
|
-
ph = parse_tree[i];
|
|
781
|
-
if (ph.keys) {
|
|
782
|
-
arg = argv[cursor];
|
|
783
|
-
for (k = 0; k < ph.keys.length; k++) {
|
|
784
|
-
if (arg == void 0) {
|
|
785
|
-
throw new Error(sprintf2('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k - 1]));
|
|
786
|
-
}
|
|
787
|
-
arg = arg[ph.keys[k]];
|
|
788
|
-
}
|
|
789
|
-
} else if (ph.param_no) {
|
|
790
|
-
arg = argv[ph.param_no];
|
|
791
|
-
} else {
|
|
792
|
-
arg = argv[cursor++];
|
|
793
|
-
}
|
|
794
|
-
if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) {
|
|
795
|
-
arg = arg();
|
|
796
|
-
}
|
|
797
|
-
if (re.numeric_arg.test(ph.type) && (typeof arg !== "number" && isNaN(arg))) {
|
|
798
|
-
throw new TypeError(sprintf2("[sprintf] expecting number but found %T", arg));
|
|
799
|
-
}
|
|
800
|
-
if (re.number.test(ph.type)) {
|
|
801
|
-
is_positive = arg >= 0;
|
|
802
|
-
}
|
|
803
|
-
switch (ph.type) {
|
|
804
|
-
case "b":
|
|
805
|
-
arg = parseInt(arg, 10).toString(2);
|
|
806
|
-
break;
|
|
807
|
-
case "c":
|
|
808
|
-
arg = String.fromCharCode(parseInt(arg, 10));
|
|
809
|
-
break;
|
|
810
|
-
case "d":
|
|
811
|
-
case "i":
|
|
812
|
-
arg = parseInt(arg, 10);
|
|
813
|
-
break;
|
|
814
|
-
case "j":
|
|
815
|
-
arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0);
|
|
816
|
-
break;
|
|
817
|
-
case "e":
|
|
818
|
-
arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential();
|
|
819
|
-
break;
|
|
820
|
-
case "f":
|
|
821
|
-
arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg);
|
|
822
|
-
break;
|
|
823
|
-
case "g":
|
|
824
|
-
arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg);
|
|
825
|
-
break;
|
|
826
|
-
case "o":
|
|
827
|
-
arg = (parseInt(arg, 10) >>> 0).toString(8);
|
|
828
|
-
break;
|
|
829
|
-
case "s":
|
|
830
|
-
arg = String(arg);
|
|
831
|
-
arg = ph.precision ? arg.substring(0, ph.precision) : arg;
|
|
832
|
-
break;
|
|
833
|
-
case "t":
|
|
834
|
-
arg = String(!!arg);
|
|
835
|
-
arg = ph.precision ? arg.substring(0, ph.precision) : arg;
|
|
836
|
-
break;
|
|
837
|
-
case "T":
|
|
838
|
-
arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase();
|
|
839
|
-
arg = ph.precision ? arg.substring(0, ph.precision) : arg;
|
|
840
|
-
break;
|
|
841
|
-
case "u":
|
|
842
|
-
arg = parseInt(arg, 10) >>> 0;
|
|
843
|
-
break;
|
|
844
|
-
case "v":
|
|
845
|
-
arg = arg.valueOf();
|
|
846
|
-
arg = ph.precision ? arg.substring(0, ph.precision) : arg;
|
|
847
|
-
break;
|
|
848
|
-
case "x":
|
|
849
|
-
arg = (parseInt(arg, 10) >>> 0).toString(16);
|
|
850
|
-
break;
|
|
851
|
-
case "X":
|
|
852
|
-
arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase();
|
|
853
|
-
break;
|
|
854
|
-
}
|
|
855
|
-
if (re.json.test(ph.type)) {
|
|
856
|
-
output += arg;
|
|
857
|
-
} else {
|
|
858
|
-
if (re.number.test(ph.type) && (!is_positive || ph.sign)) {
|
|
859
|
-
sign = is_positive ? "+" : "-";
|
|
860
|
-
arg = arg.toString().replace(re.sign, "");
|
|
861
|
-
} else {
|
|
862
|
-
sign = "";
|
|
863
|
-
}
|
|
864
|
-
pad_character = ph.pad_char ? ph.pad_char === "0" ? "0" : ph.pad_char.charAt(1) : " ";
|
|
865
|
-
pad_length = ph.width - (sign + arg).length;
|
|
866
|
-
pad = ph.width ? pad_length > 0 ? pad_character.repeat(pad_length) : "" : "";
|
|
867
|
-
output += ph.align ? sign + arg + pad : pad_character === "0" ? sign + pad + arg : pad + sign + arg;
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
return output;
|
|
872
|
-
}
|
|
873
|
-
var sprintf_cache = /* @__PURE__ */ Object.create(null);
|
|
874
|
-
function sprintf_parse(fmt) {
|
|
875
|
-
if (sprintf_cache[fmt]) {
|
|
876
|
-
return sprintf_cache[fmt];
|
|
877
|
-
}
|
|
878
|
-
var _fmt = fmt, match, parse_tree = [], arg_names = 0;
|
|
879
|
-
while (_fmt) {
|
|
880
|
-
if ((match = re.text.exec(_fmt)) !== null) {
|
|
881
|
-
parse_tree.push(match[0]);
|
|
882
|
-
} else if ((match = re.modulo.exec(_fmt)) !== null) {
|
|
883
|
-
parse_tree.push("%");
|
|
884
|
-
} else if ((match = re.placeholder.exec(_fmt)) !== null) {
|
|
885
|
-
if (match[2]) {
|
|
886
|
-
arg_names |= 1;
|
|
887
|
-
var field_list = [], replacement_field = match[2], field_match = [];
|
|
888
|
-
if ((field_match = re.key.exec(replacement_field)) !== null) {
|
|
889
|
-
field_list.push(field_match[1]);
|
|
890
|
-
while ((replacement_field = replacement_field.substring(field_match[0].length)) !== "") {
|
|
891
|
-
if ((field_match = re.key_access.exec(replacement_field)) !== null) {
|
|
892
|
-
field_list.push(field_match[1]);
|
|
893
|
-
} else if ((field_match = re.index_access.exec(replacement_field)) !== null) {
|
|
894
|
-
field_list.push(field_match[1]);
|
|
895
|
-
} else {
|
|
896
|
-
throw new SyntaxError("[sprintf] failed to parse named argument key");
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
} else {
|
|
900
|
-
throw new SyntaxError("[sprintf] failed to parse named argument key");
|
|
901
|
-
}
|
|
902
|
-
match[2] = field_list;
|
|
903
|
-
} else {
|
|
904
|
-
arg_names |= 2;
|
|
905
|
-
}
|
|
906
|
-
if (arg_names === 3) {
|
|
907
|
-
throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");
|
|
908
|
-
}
|
|
909
|
-
parse_tree.push(
|
|
910
|
-
{
|
|
911
|
-
placeholder: match[0],
|
|
912
|
-
param_no: match[1],
|
|
913
|
-
keys: match[2],
|
|
914
|
-
sign: match[3],
|
|
915
|
-
pad_char: match[4],
|
|
916
|
-
align: match[5],
|
|
917
|
-
width: match[6],
|
|
918
|
-
precision: match[7],
|
|
919
|
-
type: match[8]
|
|
920
|
-
}
|
|
921
|
-
);
|
|
922
|
-
} else {
|
|
923
|
-
throw new SyntaxError("[sprintf] unexpected placeholder");
|
|
924
|
-
}
|
|
925
|
-
_fmt = _fmt.substring(match[0].length);
|
|
926
|
-
}
|
|
927
|
-
return sprintf_cache[fmt] = parse_tree;
|
|
928
|
-
}
|
|
929
|
-
{
|
|
930
|
-
exports$1["sprintf"] = sprintf2;
|
|
931
|
-
exports$1["vsprintf"] = vsprintf;
|
|
932
|
-
}
|
|
933
|
-
if (typeof window !== "undefined") {
|
|
934
|
-
window["sprintf"] = sprintf2;
|
|
935
|
-
window["vsprintf"] = vsprintf;
|
|
936
|
-
}
|
|
937
|
-
})();
|
|
938
|
-
})(sprintf);
|
|
939
|
-
return sprintf;
|
|
940
|
-
}
|
|
941
|
-
var sprintfExports = /* @__PURE__ */ requireSprintf();
|
|
942
|
-
let lang;
|
|
943
|
-
function useLang() {
|
|
944
|
-
return lang ??= new UnicornLang();
|
|
945
|
-
}
|
|
946
|
-
function trans(id, ...args) {
|
|
947
|
-
return useLang().trans(id, ...args);
|
|
948
|
-
}
|
|
949
|
-
function __(id, ...args) {
|
|
950
|
-
return trans(id, ...args);
|
|
951
|
-
}
|
|
952
|
-
class UnicornLang {
|
|
953
|
-
/**
|
|
954
|
-
* Translate a string.
|
|
955
|
-
*/
|
|
956
|
-
trans(id, ...args) {
|
|
957
|
-
const key = this.normalize(id);
|
|
958
|
-
let translated = this.get(key) || "";
|
|
959
|
-
translated = this.replace(translated, args);
|
|
960
|
-
return translated !== "" ? translated : this.wrapDebug(id, false);
|
|
961
|
-
}
|
|
962
|
-
replace(str, args) {
|
|
963
|
-
let replacements = {};
|
|
964
|
-
let values = [];
|
|
965
|
-
for (const arg of args) {
|
|
966
|
-
if (typeof arg === "object") {
|
|
967
|
-
replacements = { ...replacements, ...arg };
|
|
968
|
-
} else {
|
|
969
|
-
values.push(arg);
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
if (values.length) {
|
|
973
|
-
str = sprintfExports.vsprintf(str, values);
|
|
974
|
-
}
|
|
975
|
-
if (Object.values(replacements).length) {
|
|
976
|
-
for (const key in replacements) {
|
|
977
|
-
let value = replacements[key];
|
|
978
|
-
if (typeof value === "function") {
|
|
979
|
-
value = value();
|
|
980
|
-
}
|
|
981
|
-
str = str.replace(new RegExp(":" + key, "g"), String(value));
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
return str;
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* Find text.
|
|
988
|
-
*/
|
|
989
|
-
get(id) {
|
|
990
|
-
const strings = this.getStrings();
|
|
991
|
-
if (strings[id]) {
|
|
992
|
-
return strings[id];
|
|
993
|
-
}
|
|
994
|
-
return null;
|
|
995
|
-
}
|
|
996
|
-
/**
|
|
997
|
-
* Has language key.
|
|
998
|
-
*/
|
|
999
|
-
has(key) {
|
|
1000
|
-
const strings = this.getStrings();
|
|
1001
|
-
return strings[key] !== void 0;
|
|
1002
|
-
}
|
|
1003
|
-
/**
|
|
1004
|
-
* Add language key.
|
|
1005
|
-
*/
|
|
1006
|
-
add(key, value) {
|
|
1007
|
-
const strings = this.getStrings();
|
|
1008
|
-
strings[this.normalize(key)] = value;
|
|
1009
|
-
data("unicorn.languages", strings);
|
|
1010
|
-
return this;
|
|
1011
|
-
}
|
|
1012
|
-
/**
|
|
1013
|
-
* Replace all symbols to dot(.).
|
|
1014
|
-
*/
|
|
1015
|
-
normalize(text) {
|
|
1016
|
-
return text.replace(/[^A-Z0-9]+/ig, ".");
|
|
1017
|
-
}
|
|
1018
|
-
wrapDebug(text, success) {
|
|
1019
|
-
if (isDebug()) {
|
|
1020
|
-
if (success) {
|
|
1021
|
-
return "**" + text + "**";
|
|
1022
|
-
}
|
|
1023
|
-
return "??" + text + "??";
|
|
1024
|
-
}
|
|
1025
|
-
return text;
|
|
1026
|
-
}
|
|
1027
|
-
getStrings() {
|
|
1028
|
-
return data("unicorn.languages") || {};
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
async function useScriptImport(src, attrs = {}) {
|
|
1032
|
-
if (typeof src === "function") {
|
|
1033
|
-
src = (await src()).default;
|
|
1034
|
-
}
|
|
1035
|
-
const script = document.createElement("script");
|
|
1036
|
-
script.src = resolveUrl(src);
|
|
1037
|
-
for (const key in attrs) {
|
|
1038
|
-
script.setAttribute(key, attrs[key]);
|
|
1039
|
-
}
|
|
1040
|
-
return new Promise((resolve, reject) => {
|
|
1041
|
-
script.onload = () => {
|
|
1042
|
-
resolve();
|
|
1043
|
-
document.body.removeChild(script);
|
|
1044
|
-
};
|
|
1045
|
-
script.onerror = (e) => {
|
|
1046
|
-
reject(e);
|
|
1047
|
-
document.body.removeChild(script);
|
|
1048
|
-
};
|
|
1049
|
-
document.body.appendChild(script);
|
|
1050
|
-
});
|
|
1051
|
-
}
|
|
1052
|
-
function doImport(src) {
|
|
1053
|
-
return import(
|
|
1054
|
-
/* @vite-ignore */
|
|
1055
|
-
src
|
|
1056
|
-
);
|
|
1057
|
-
}
|
|
1058
|
-
async function useImport(...src) {
|
|
1059
|
-
if (src.length === 1) {
|
|
1060
|
-
return doImport(src[0]);
|
|
1061
|
-
}
|
|
1062
|
-
const promises = [];
|
|
1063
|
-
src.forEach((link) => {
|
|
1064
|
-
promises.push(
|
|
1065
|
-
link instanceof Promise ? link : doImport(link)
|
|
1066
|
-
);
|
|
1067
|
-
});
|
|
1068
|
-
return Promise.all(promises);
|
|
1069
|
-
}
|
|
1070
|
-
async function useSeriesImport(...src) {
|
|
1071
|
-
const modules = [];
|
|
1072
|
-
for (const source of src) {
|
|
1073
|
-
if (Array.isArray(source)) {
|
|
1074
|
-
const m2 = await useImport(...source);
|
|
1075
|
-
modules.push(m2);
|
|
1076
|
-
continue;
|
|
1077
|
-
}
|
|
1078
|
-
const m = await useImport(source);
|
|
1079
|
-
modules.push(m);
|
|
1080
|
-
}
|
|
1081
|
-
return modules;
|
|
1082
|
-
}
|
|
1083
|
-
async function useCssIncludes(...hrefs) {
|
|
1084
|
-
const promises = hrefs.map((href) => {
|
|
1085
|
-
return new Promise((resolve, reject) => {
|
|
1086
|
-
resolveSource(href).then((href2) => {
|
|
1087
|
-
href2 = resolveUrl(href2);
|
|
1088
|
-
const link = document.createElement("link");
|
|
1089
|
-
link.rel = "stylesheet";
|
|
1090
|
-
link.href = href2;
|
|
1091
|
-
link.onload = () => resolve();
|
|
1092
|
-
link.onerror = (e) => reject(e);
|
|
1093
|
-
document.head.appendChild(link);
|
|
1094
|
-
});
|
|
1095
|
-
});
|
|
1096
|
-
});
|
|
1097
|
-
return Promise.all(promises);
|
|
1098
|
-
}
|
|
1099
|
-
const importedSheets = {};
|
|
1100
|
-
async function useCssImport(...hrefs) {
|
|
1101
|
-
const modules = await Promise.all(
|
|
1102
|
-
hrefs.map((href) => {
|
|
1103
|
-
return new Promise((resolve) => {
|
|
1104
|
-
resolveSource(href).then((href2) => {
|
|
1105
|
-
href2 = resolveUrl(href2);
|
|
1106
|
-
if (!importedSheets[href2]) {
|
|
1107
|
-
importedSheets[href2] = simulateCssImport(href2);
|
|
1108
|
-
}
|
|
1109
|
-
resolve(importedSheets[href2]);
|
|
1110
|
-
});
|
|
1111
|
-
});
|
|
1112
|
-
})
|
|
1113
|
-
);
|
|
1114
|
-
const styles = modules.map((module) => module.default);
|
|
1115
|
-
return injectCssToDocument(...styles);
|
|
1116
|
-
}
|
|
1117
|
-
async function simulateCssImport(href) {
|
|
1118
|
-
const response = await fetch(href);
|
|
1119
|
-
if (!response.ok) {
|
|
1120
|
-
throw new Error(`Failed to load CSS: ${href}`);
|
|
1121
|
-
}
|
|
1122
|
-
const cssText = await response.text();
|
|
1123
|
-
const sheet = new CSSStyleSheet();
|
|
1124
|
-
await sheet.replace(cssText);
|
|
1125
|
-
return { default: sheet };
|
|
1126
|
-
}
|
|
1127
|
-
let importMap;
|
|
1128
|
-
function parseImportMap() {
|
|
1129
|
-
const importMapScript = document.querySelector('script[type="importmap"]');
|
|
1130
|
-
if (importMapScript) {
|
|
1131
|
-
try {
|
|
1132
|
-
return JSON.parse(importMapScript.textContent || "{}").imports || {};
|
|
1133
|
-
} catch (e) {
|
|
1134
|
-
console.error("Failed to parse import map:", e);
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
return {};
|
|
1138
|
-
}
|
|
1139
|
-
function resolveUrl(specifier) {
|
|
1140
|
-
importMap ??= parseImportMap();
|
|
1141
|
-
for (const [prefix, target] of Object.entries(importMap)) {
|
|
1142
|
-
if (specifier === prefix) {
|
|
1143
|
-
return target;
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
for (const [prefix, target] of Object.entries(importMap)) {
|
|
1147
|
-
if (specifier.startsWith(prefix)) {
|
|
1148
|
-
return specifier.replace(prefix, target);
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
return specifier;
|
|
1152
|
-
}
|
|
1153
|
-
async function resolveSource(src) {
|
|
1154
|
-
if (typeof src === "function") {
|
|
1155
|
-
return (await src()).default;
|
|
1156
|
-
}
|
|
1157
|
-
return src;
|
|
1158
|
-
}
|
|
1159
|
-
async function useUIBootstrap5(install = false, pushToGlobal = false) {
|
|
1160
|
-
const { UIBootstrap5 } = await import("./ui-bootstrap5.js");
|
|
1161
|
-
const theme = UIBootstrap5.get();
|
|
1162
|
-
if (install) {
|
|
1163
|
-
useUITheme(theme);
|
|
1164
|
-
if (pushToGlobal) {
|
|
1165
|
-
theme.pushBootstrapToGlobal();
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
return theme;
|
|
1169
|
-
}
|
|
1170
|
-
async function useBs5Tooltip(selector = '[data-bs-toggle="tooltip"]', config = {}) {
|
|
1171
|
-
const bs5 = await useUIBootstrap5();
|
|
1172
|
-
return bs5.tooltip(selector, config);
|
|
1173
|
-
}
|
|
1174
|
-
const useBs5KeepTab = async (selector, options = {}) => {
|
|
1175
|
-
const bs5 = await useUIBootstrap5();
|
|
1176
|
-
return bs5.keepTab(selector, options);
|
|
1177
|
-
};
|
|
1178
|
-
const useBs5ButtonRadio = async (selector, options = {}) => {
|
|
1179
|
-
const bs5 = await useUIBootstrap5();
|
|
1180
|
-
return bs5.buttonRadio(selector, options);
|
|
1181
|
-
};
|
|
1182
|
-
const defaultOptions = {
|
|
1183
|
-
buttons: [
|
|
1184
|
-
"OK"
|
|
1185
|
-
]
|
|
1186
|
-
};
|
|
1187
|
-
async function useBsModalAlert(id, options) {
|
|
1188
|
-
await useUIBootstrap5();
|
|
1189
|
-
let modalElement = void 0;
|
|
1190
|
-
if (typeof id !== "string" && !(id instanceof HTMLElement)) {
|
|
1191
|
-
options = id;
|
|
1192
|
-
id = "uni-modal-alert";
|
|
1193
|
-
modalElement = document.getElementById(id);
|
|
1194
|
-
} else {
|
|
1195
|
-
modalElement = typeof id === "string" ? document.getElementById(id) : id;
|
|
1196
|
-
}
|
|
1197
|
-
if (!modalElement) {
|
|
1198
|
-
modalElement = html(`<div id="${id}" class="uni-modal-alert modal fade" tabindex="-1" role="dialog">
|
|
1199
|
-
<div class="modal-dialog" role="document">
|
|
1200
|
-
<div class="modal-content">
|
|
1201
|
-
<div class="modal-body text-center p-4"></div>
|
|
1202
|
-
<div class="modal-footer"></div>
|
|
1203
|
-
</div>
|
|
1204
|
-
</div>
|
|
1205
|
-
</div>`);
|
|
1206
|
-
document.body.appendChild(modalElement);
|
|
1207
|
-
}
|
|
1208
|
-
const modal = Modal.getOrCreateInstance(modalElement, options);
|
|
1209
|
-
return {
|
|
1210
|
-
show: (title, text, icon, options2) => {
|
|
1211
|
-
if (typeof title === "string") {
|
|
1212
|
-
options2 = options2 || {};
|
|
1213
|
-
options2.title = title;
|
|
1214
|
-
options2.text = text;
|
|
1215
|
-
options2.icon = icon;
|
|
1216
|
-
} else {
|
|
1217
|
-
options2 = title;
|
|
1218
|
-
}
|
|
1219
|
-
return new Promise((resolve) => {
|
|
1220
|
-
prepareModalElement(modalElement, resolve, options2);
|
|
1221
|
-
modal.show(options2?.relatedTarget);
|
|
1222
|
-
});
|
|
1223
|
-
},
|
|
1224
|
-
hide: () => {
|
|
1225
|
-
modal.hide();
|
|
1226
|
-
},
|
|
1227
|
-
dispose: () => {
|
|
1228
|
-
modal.dispose();
|
|
1229
|
-
},
|
|
1230
|
-
toggle: (relatedTarget) => {
|
|
1231
|
-
modal.toggle(relatedTarget);
|
|
1232
|
-
},
|
|
1233
|
-
destroy: () => {
|
|
1234
|
-
modal.dispose();
|
|
1235
|
-
modalElement.remove();
|
|
1236
|
-
},
|
|
1237
|
-
instance: modal,
|
|
1238
|
-
el: modalElement
|
|
1239
|
-
};
|
|
1240
|
-
}
|
|
1241
|
-
async function prepareModalElement(modalElement, handler, options) {
|
|
1242
|
-
options = Object.assign({}, defaultOptions, options || {});
|
|
1243
|
-
let header = options.header;
|
|
1244
|
-
const content = options.content;
|
|
1245
|
-
modalElement.querySelector(".modal-header")?.remove();
|
|
1246
|
-
modalElement.querySelector(".modal-body").innerHTML = "";
|
|
1247
|
-
modalElement.querySelector(".modal-footer").innerHTML = "";
|
|
1248
|
-
const dialog = modalElement.querySelector(".modal-dialog");
|
|
1249
|
-
dialog?.classList.remove("modal-sm", "modal-lg", "modal-xl", "modal-xxl");
|
|
1250
|
-
if (header) {
|
|
1251
|
-
if (typeof header === "string") {
|
|
1252
|
-
header = `<div class="modal-header">
|
|
1253
|
-
<h5 class="modal-title">${header}</h5>
|
|
1254
|
-
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
1255
|
-
</div>`;
|
|
1256
|
-
}
|
|
1257
|
-
header = await anyToElement(header);
|
|
1258
|
-
modalElement.querySelector(".modal-content").insertAdjacentElement("afterbegin", header);
|
|
1259
|
-
}
|
|
1260
|
-
if (content) {
|
|
1261
|
-
let contentElement = await anyToElement(content);
|
|
1262
|
-
modalElement.querySelector(".modal-body").appendChild(contentElement);
|
|
1263
|
-
} else {
|
|
1264
|
-
const title = options.title;
|
|
1265
|
-
const text = options.text;
|
|
1266
|
-
let icon = options.icon;
|
|
1267
|
-
if (icon) {
|
|
1268
|
-
if (typeof icon === "string") {
|
|
1269
|
-
icon = `<div class="uni-modal-alert__icon text-center mb-4"><span class="${icon}" style="font-size: 48px;"></span></div>`;
|
|
1270
|
-
}
|
|
1271
|
-
icon = await anyToElement(icon);
|
|
1272
|
-
modalElement.querySelector(".modal-body").appendChild(icon);
|
|
1273
|
-
}
|
|
1274
|
-
if (title) {
|
|
1275
|
-
const titleEl = html(`<h4 class="uni-modal-alert__title">${title}</h4>`);
|
|
1276
|
-
modalElement.querySelector(".modal-body").appendChild(titleEl);
|
|
1277
|
-
}
|
|
1278
|
-
if (text) {
|
|
1279
|
-
const textEl = html(`<div class="uni-modal-alert__text">${text}</div>`);
|
|
1280
|
-
modalElement.querySelector(".modal-body").appendChild(textEl);
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
const buttons = options.buttons;
|
|
1284
|
-
for (const i in buttons) {
|
|
1285
|
-
const button = buttons[i];
|
|
1286
|
-
const isConfirm = buttons.length === 1 || buttons.length === 2 && Number(i) === 1;
|
|
1287
|
-
const buttonElement = createButton(
|
|
1288
|
-
button,
|
|
1289
|
-
handler,
|
|
1290
|
-
isConfirm
|
|
1291
|
-
);
|
|
1292
|
-
modalElement.querySelector(".modal-footer").appendChild(await buttonElement);
|
|
1293
|
-
}
|
|
1294
|
-
if (options.size) {
|
|
1295
|
-
modalElement.querySelector(".modal-dialog").classList.add(`modal-${options.size}`);
|
|
1296
|
-
}
|
|
1297
|
-
return modalElement;
|
|
1298
|
-
}
|
|
1299
|
-
async function anyToElement(content) {
|
|
1300
|
-
if (typeof content === "function") {
|
|
1301
|
-
return content();
|
|
1302
|
-
}
|
|
1303
|
-
return typeof content === "string" ? html(content) : content;
|
|
1304
|
-
}
|
|
1305
|
-
async function createButton(buttonOption, handler, isConfirm) {
|
|
1306
|
-
if (typeof buttonOption === "function") {
|
|
1307
|
-
return await buttonOption();
|
|
1308
|
-
}
|
|
1309
|
-
if (typeof buttonOption === "string") {
|
|
1310
|
-
buttonOption = {
|
|
1311
|
-
text: buttonOption,
|
|
1312
|
-
value: isConfirm ?? false,
|
|
1313
|
-
class: isConfirm ? "btn btn-primary is-confirm" : "btn btn-outline-secondary",
|
|
1314
|
-
styles: isConfirm ? { width: "150px" } : {},
|
|
1315
|
-
dismiss: true
|
|
1316
|
-
};
|
|
1317
|
-
}
|
|
1318
|
-
let button;
|
|
1319
|
-
if (buttonOption instanceof HTMLElement) {
|
|
1320
|
-
button = buttonOption;
|
|
1321
|
-
} else {
|
|
1322
|
-
const {
|
|
1323
|
-
text,
|
|
1324
|
-
class: className = "btn btn-secondary",
|
|
1325
|
-
attrs = {},
|
|
1326
|
-
styles = {},
|
|
1327
|
-
dismiss = true,
|
|
1328
|
-
value,
|
|
1329
|
-
href,
|
|
1330
|
-
target,
|
|
1331
|
-
onClick
|
|
1332
|
-
} = buttonOption;
|
|
1333
|
-
const tag = href ? "a" : "button";
|
|
1334
|
-
const el = document.createElement(tag);
|
|
1335
|
-
if (el instanceof HTMLAnchorElement) {
|
|
1336
|
-
el.href = href;
|
|
1337
|
-
el.target = target || "_self";
|
|
1338
|
-
}
|
|
1339
|
-
if (el instanceof HTMLButtonElement) {
|
|
1340
|
-
el.type = "button";
|
|
1341
|
-
}
|
|
1342
|
-
el.setAttribute("class", className);
|
|
1343
|
-
for (let attr in attrs) {
|
|
1344
|
-
el.setAttribute(attr, attrs[attr]);
|
|
1345
|
-
}
|
|
1346
|
-
for (let style in styles) {
|
|
1347
|
-
el.style[style] = styles[style];
|
|
1348
|
-
}
|
|
1349
|
-
if (dismiss) {
|
|
1350
|
-
el.setAttribute("data-bs-dismiss", "modal");
|
|
1351
|
-
}
|
|
1352
|
-
if (typeof text === "string") {
|
|
1353
|
-
el.textContent = text;
|
|
1354
|
-
} else if (typeof text === "function") {
|
|
1355
|
-
text(el);
|
|
1356
|
-
}
|
|
1357
|
-
el.addEventListener("click", (e) => {
|
|
1358
|
-
onClick?.(value, e);
|
|
1359
|
-
handler(value);
|
|
1360
|
-
});
|
|
1361
|
-
button = el;
|
|
1362
|
-
}
|
|
1363
|
-
return button;
|
|
1364
|
-
}
|
|
1365
|
-
async function useCheckboxesMultiSelect(selector, options = {}) {
|
|
1366
|
-
const m = await import("./checkboxes-multi-select.js");
|
|
1367
|
-
if (selector) {
|
|
1368
|
-
m.CheckboxesMultiSelect.handle(selector, options);
|
|
1369
|
-
}
|
|
1370
|
-
return m;
|
|
1371
|
-
}
|
|
1372
|
-
async function useFieldCascadeSelect() {
|
|
1373
|
-
const module = await import("./field-cascade-select.js");
|
|
1374
|
-
await module.ready;
|
|
1375
|
-
return module;
|
|
1376
|
-
}
|
|
1377
|
-
async function useFieldFileDrag() {
|
|
1378
|
-
const module = await import("./field-file-drag.js");
|
|
1379
|
-
await module.ready;
|
|
1380
|
-
return module;
|
|
1381
|
-
}
|
|
1382
|
-
function useFieldFlatpickr() {
|
|
1383
|
-
return import("./field-flatpickr.js");
|
|
1384
|
-
}
|
|
1385
|
-
function useFieldModalSelect() {
|
|
1386
|
-
return import("./field-modal-select.js");
|
|
1387
|
-
}
|
|
1388
|
-
function useFieldModalTree() {
|
|
1389
|
-
return import("./field-modal-tree.js");
|
|
1390
|
-
}
|
|
1391
|
-
async function useFieldRepeatable() {
|
|
1392
|
-
const module = await import("./field-repeatable.js");
|
|
1393
|
-
await module.ready;
|
|
1394
|
-
return module;
|
|
1395
|
-
}
|
|
1396
|
-
async function useFieldSingleImageDrag() {
|
|
1397
|
-
const module = await import("./field-single-image-drag.js");
|
|
1398
|
-
await module.ready;
|
|
1399
|
-
return module;
|
|
1400
|
-
}
|
|
1401
|
-
let formElement;
|
|
1402
|
-
function useFormAsync(ele, options = {}) {
|
|
1403
|
-
const promise = import("./form.js").then(({ UnicornFormElement }) => {
|
|
1404
|
-
formElement ??= UnicornFormElement;
|
|
1405
|
-
return useForm(ele, options);
|
|
1406
|
-
});
|
|
1407
|
-
const proxy = new Proxy({}, {
|
|
1408
|
-
get(target, prop) {
|
|
1409
|
-
return (...args) => {
|
|
1410
|
-
if (prop === "then" || prop === "catch") {
|
|
1411
|
-
return promise[prop].apply(promise, args);
|
|
1412
|
-
}
|
|
1413
|
-
return promise.then((form) => {
|
|
1414
|
-
const p = form[prop];
|
|
1415
|
-
if (typeof p === "function") {
|
|
1416
|
-
return p.apply(form, args);
|
|
1417
|
-
}
|
|
1418
|
-
return p;
|
|
1419
|
-
});
|
|
1420
|
-
};
|
|
1421
|
-
}
|
|
1422
|
-
});
|
|
1423
|
-
return proxy;
|
|
1424
|
-
}
|
|
1425
|
-
function useForm(ele, options = {}) {
|
|
1426
|
-
if (!formElement) {
|
|
1427
|
-
throw new Error("Form module is not loaded. Please use useFormAsync() to load the module before using useForm().");
|
|
1428
|
-
}
|
|
1429
|
-
if (ele == null) {
|
|
1430
|
-
return new formElement(void 0, void 0, options);
|
|
1431
|
-
}
|
|
1432
|
-
let selector = void 0;
|
|
1433
|
-
let el = void 0;
|
|
1434
|
-
if (typeof ele === "string") {
|
|
1435
|
-
selector = ele;
|
|
1436
|
-
el = selectOne(ele) ?? void 0;
|
|
1437
|
-
} else {
|
|
1438
|
-
el = ele;
|
|
1439
|
-
}
|
|
1440
|
-
if (!el) {
|
|
1441
|
-
return new formElement(selector, el, options);
|
|
1442
|
-
}
|
|
1443
|
-
return module$1(
|
|
1444
|
-
el,
|
|
1445
|
-
"unicorn.form",
|
|
1446
|
-
() => new formElement(selector, el, options)
|
|
1447
|
-
);
|
|
1448
|
-
}
|
|
1449
|
-
async function useFormComponent(ele, options = {}) {
|
|
1450
|
-
const form = await useFormAsync(ele, options);
|
|
1451
|
-
await form?.initComponent();
|
|
1452
|
-
return form;
|
|
1453
|
-
}
|
|
1454
|
-
async function useFormSubmit(options = {}) {
|
|
1455
|
-
const form = await useFormAsync(options.form);
|
|
1456
|
-
const func = options.method?.toLowerCase() || "post";
|
|
1457
|
-
return form[func](options.url, options.data);
|
|
1458
|
-
}
|
|
1459
|
-
let gridElement;
|
|
1460
|
-
async function useGridAsync(ele, options = {}) {
|
|
1461
|
-
await useFormAsync();
|
|
1462
|
-
const { UnicornGridElement } = await import("./grid.js");
|
|
1463
|
-
gridElement ??= UnicornGridElement;
|
|
1464
|
-
if (!ele) {
|
|
1465
|
-
return null;
|
|
1466
|
-
}
|
|
1467
|
-
return useGrid(ele, options);
|
|
1468
|
-
}
|
|
1469
|
-
function useGrid(ele, options = {}) {
|
|
1470
|
-
const selector = typeof ele === "string" ? ele : "";
|
|
1471
|
-
const element = selectOne(ele);
|
|
1472
|
-
if (!element) {
|
|
1473
|
-
throw new Error("Element is empty");
|
|
1474
|
-
}
|
|
1475
|
-
const form = useForm(selector || element);
|
|
1476
|
-
if (!form) {
|
|
1477
|
-
throw new Error("UnicornGrid is depends on UnicornForm");
|
|
1478
|
-
}
|
|
1479
|
-
return module$1(
|
|
1480
|
-
element,
|
|
1481
|
-
"grid.plugin",
|
|
1482
|
-
() => new gridElement(selector, element, form, options)
|
|
1483
|
-
);
|
|
1484
|
-
}
|
|
1485
|
-
async function useGridComponent(ele, options = {}) {
|
|
1486
|
-
const grid = await useGridAsync(ele, options);
|
|
1487
|
-
await grid?.initComponent();
|
|
1488
|
-
return grid;
|
|
1489
|
-
}
|
|
1490
|
-
function useHttpClient(config) {
|
|
1491
|
-
const promise = import("./http-client.js").then(({ createHttpClient }) => {
|
|
1492
|
-
return createHttpClient(config);
|
|
1493
|
-
});
|
|
1494
|
-
const data2 = {
|
|
1495
|
-
request: (options) => {
|
|
1496
|
-
return promise.then((client) => client.request(options));
|
|
1497
|
-
},
|
|
1498
|
-
get: (url, options) => {
|
|
1499
|
-
return promise.then((client) => client.get(url, options));
|
|
1500
|
-
},
|
|
1501
|
-
post: (url, data22, options) => {
|
|
1502
|
-
return promise.then((client) => client.post(url, data22, options));
|
|
1503
|
-
},
|
|
1504
|
-
put: (url, data22, options) => {
|
|
1505
|
-
return promise.then((client) => client.put(url, data22, options));
|
|
1506
|
-
},
|
|
1507
|
-
patch: (url, data22, options) => {
|
|
1508
|
-
return promise.then((client) => client.patch(url, data22, options));
|
|
1509
|
-
},
|
|
1510
|
-
delete: (url, data22, options) => {
|
|
1511
|
-
return promise.then((client) => client.delete(url, data22, options));
|
|
1512
|
-
},
|
|
1513
|
-
head: (url, options) => {
|
|
1514
|
-
return promise.then((client) => client.head(url, options));
|
|
1515
|
-
},
|
|
1516
|
-
options: (url, options) => {
|
|
1517
|
-
return promise.then((client) => client.options(url, options));
|
|
1518
|
-
},
|
|
1519
|
-
http: promise
|
|
1520
|
-
};
|
|
1521
|
-
Object.assign(data2, {
|
|
1522
|
-
then: promise.then.bind(promise),
|
|
1523
|
-
catch: promise.catch.bind(promise)
|
|
1524
|
-
});
|
|
1525
|
-
return data2;
|
|
1526
|
-
}
|
|
1527
|
-
async function useIframeModal() {
|
|
1528
|
-
const module = await import("./iframe-modal.js");
|
|
1529
|
-
await module.ready;
|
|
1530
|
-
return module;
|
|
1531
|
-
}
|
|
1532
|
-
async function useListDependent(element, dependent, options = {}) {
|
|
1533
|
-
const module = await import("./list-dependent.js");
|
|
1534
|
-
await module.ready;
|
|
1535
|
-
if (element) {
|
|
1536
|
-
const { ListDependent } = module;
|
|
1537
|
-
return ListDependent.handle(element, dependent ?? void 0, options);
|
|
1538
|
-
}
|
|
1539
|
-
return module;
|
|
1540
|
-
}
|
|
1541
|
-
const queues = {};
|
|
1542
|
-
function useQueue(name = "default", maxRunning = 1) {
|
|
1543
|
-
return queues[name] ??= createQueue(maxRunning);
|
|
1544
|
-
}
|
|
1545
|
-
function createQueue(maxRunning = 1) {
|
|
1546
|
-
return queue(maxRunning);
|
|
1547
|
-
}
|
|
1548
|
-
async function useS3Uploader(name, options = {}) {
|
|
1549
|
-
const module = await import("./s3-uploader.js");
|
|
1550
|
-
if (!name) {
|
|
1551
|
-
return module;
|
|
1552
|
-
}
|
|
1553
|
-
const { get } = module;
|
|
1554
|
-
return get(name, options);
|
|
1555
|
-
}
|
|
1556
|
-
async function useS3MultipartUploader(options) {
|
|
1557
|
-
const module = await import("./s3-multipart-uploader.js");
|
|
1558
|
-
if (options != null) {
|
|
1559
|
-
return new module.S3MultipartUploader(options);
|
|
1560
|
-
}
|
|
1561
|
-
return module;
|
|
1562
|
-
}
|
|
1563
|
-
async function useShowOn() {
|
|
1564
|
-
const module = await import("./show-on.js");
|
|
1565
|
-
await module.ready;
|
|
1566
|
-
return module;
|
|
1567
|
-
}
|
|
1568
|
-
const stacks = {};
|
|
1569
|
-
function useStack(name = "default", store = []) {
|
|
1570
|
-
return stacks[name] ??= createStack(store);
|
|
1571
|
-
}
|
|
1572
|
-
function createStack(store = []) {
|
|
1573
|
-
return stack(store);
|
|
1574
|
-
}
|
|
1575
|
-
async function useTomSelect(selector, options = {}, theme = "bootstrap5") {
|
|
1576
|
-
const [m] = await wait(
|
|
1577
|
-
useImport("@vendor/tom-select/dist/js/tom-select.complete.min.js"),
|
|
1578
|
-
useCssImport(`@vendor/tom-select/dist/css/tom-select.${theme}.min.css`)
|
|
1579
|
-
);
|
|
1580
|
-
if (selector) {
|
|
1581
|
-
module$1(
|
|
1582
|
-
selector,
|
|
1583
|
-
"tom.select",
|
|
1584
|
-
(ele) => {
|
|
1585
|
-
options = mergeDeep({
|
|
1586
|
-
allowEmptyOption: true,
|
|
1587
|
-
maxOptions: null,
|
|
1588
|
-
plugins: {
|
|
1589
|
-
caret_position: {},
|
|
1590
|
-
clear_button: {}
|
|
1591
|
-
}
|
|
1592
|
-
}, options);
|
|
1593
|
-
if (ele.multiple) {
|
|
1594
|
-
options.plugins.remove_button = {};
|
|
1595
|
-
} else {
|
|
1596
|
-
options.plugins.dropdown_input = {};
|
|
1597
|
-
}
|
|
1598
|
-
class UnicornTomSelect extends TomSelect {
|
|
1599
|
-
syncOptionsWithoutKeepSelected() {
|
|
1600
|
-
const oldValue = ele.value;
|
|
1601
|
-
this.clear();
|
|
1602
|
-
this.clearOptions();
|
|
1603
|
-
this.sync();
|
|
1604
|
-
if (ele.value !== oldValue) {
|
|
1605
|
-
this.setValue(
|
|
1606
|
-
ele.querySelector(`option[value="${oldValue}"]`)?.value ?? ele.querySelector("option")?.value ?? "",
|
|
1607
|
-
true
|
|
1608
|
-
);
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
const t = new UnicornTomSelect(ele, options);
|
|
1613
|
-
ele.addEventListener("list:updated", () => {
|
|
1614
|
-
t.syncOptionsWithoutKeepSelected();
|
|
1615
|
-
});
|
|
1616
|
-
return t;
|
|
1617
|
-
}
|
|
1618
|
-
);
|
|
1619
|
-
}
|
|
1620
|
-
return m;
|
|
1621
|
-
}
|
|
1622
|
-
async function useTinymce(selector, options = {}) {
|
|
1623
|
-
const module = await import("./tinymce.js");
|
|
1624
|
-
if (selector) {
|
|
1625
|
-
return module.get(selector, options);
|
|
1626
|
-
}
|
|
1627
|
-
return module;
|
|
1628
|
-
}
|
|
1629
|
-
async function useTinymceHook(handler) {
|
|
1630
|
-
const { addHook } = await import("./tinymce.js");
|
|
1631
|
-
return addHook(handler);
|
|
1632
|
-
}
|
|
1633
|
-
let instances = {};
|
|
1634
|
-
async function useWebDirective(name = "unicorn", options = {}) {
|
|
1635
|
-
if (options === false) {
|
|
1636
|
-
delete instances[name];
|
|
1637
|
-
return;
|
|
1638
|
-
}
|
|
1639
|
-
return instances[name] ??= await createWebDirective(Object.assign({}, options, { prefix: "uni-" }));
|
|
1640
|
-
}
|
|
1641
|
-
async function useUniDirective(name, handler, wdInstance = "unicorn") {
|
|
1642
|
-
const wd = typeof wdInstance === "string" ? await useWebDirective(wdInstance) : wdInstance;
|
|
1643
|
-
wd.register(name, handler);
|
|
1644
|
-
}
|
|
1645
|
-
async function createWebDirective(options = {}) {
|
|
1646
|
-
const WebDirective = (await import("web-directive")).default;
|
|
1647
|
-
const wd = new WebDirective(options);
|
|
1648
|
-
wd.listen();
|
|
1649
|
-
return wd;
|
|
1650
|
-
}
|
|
1651
|
-
async function useFormValidation(selector) {
|
|
1652
|
-
const module = await import("./validation.js");
|
|
1653
|
-
await module.ready;
|
|
1654
|
-
if (!selector) {
|
|
1655
|
-
return module;
|
|
1656
|
-
}
|
|
1657
|
-
return useFormValidationInstance(selector);
|
|
1658
|
-
}
|
|
1659
|
-
function useFormValidationInstance(selector) {
|
|
1660
|
-
return getBoundedInstance(selector, "form.validation");
|
|
1661
|
-
}
|
|
1662
|
-
function useFieldValidationInstance(selector) {
|
|
1663
|
-
return getBoundedInstance(selector, "field.validation");
|
|
1664
|
-
}
|
|
1665
|
-
async function addGlobalValidator(name, validator, options = {}) {
|
|
1666
|
-
const { UnicornFormValidation } = await useFormValidation();
|
|
1667
|
-
UnicornFormValidation.addGlobalValidator(name, validator, options);
|
|
1668
|
-
}
|
|
1669
|
-
let ui;
|
|
1670
|
-
AlertAdapter.alert = (title, text = "", type = "info") => {
|
|
1671
|
-
if (text) {
|
|
1672
|
-
title += " | " + text;
|
|
1673
|
-
}
|
|
1674
|
-
window.alert(title);
|
|
1675
|
-
return Promise.resolve();
|
|
1676
|
-
};
|
|
1677
|
-
AlertAdapter.confirm = (message, text = "", type = "info") => {
|
|
1678
|
-
message = message || "Are you sure?";
|
|
1679
|
-
if (text) {
|
|
1680
|
-
message += " | " + text;
|
|
1681
|
-
}
|
|
1682
|
-
return new Promise((resolve) => {
|
|
1683
|
-
resolve(window.confirm(message));
|
|
1684
|
-
});
|
|
1685
|
-
};
|
|
1686
|
-
AlertAdapter.notify = async (title, text, type = "log") => {
|
|
1687
|
-
if (text) {
|
|
1688
|
-
title += " | " + text;
|
|
1689
|
-
}
|
|
1690
|
-
return ui.theme?.renderMessage(title, type) ?? (() => null);
|
|
1691
|
-
};
|
|
1692
|
-
AlertAdapter.clearNotifies = async () => {
|
|
1693
|
-
ui.theme?.clearMessages();
|
|
1694
|
-
};
|
|
1695
|
-
AlertAdapter.confirmText = () => "OK";
|
|
1696
|
-
AlertAdapter.cancelText = () => "Cancel";
|
|
1697
|
-
AlertAdapter.deleteText = () => "Delete";
|
|
1698
|
-
function useAlertAdapter(config) {
|
|
1699
|
-
if (config) {
|
|
1700
|
-
Object.assign(AlertAdapter, config);
|
|
1701
|
-
}
|
|
1702
|
-
return AlertAdapter;
|
|
1703
|
-
}
|
|
1704
|
-
function useUI(instance) {
|
|
1705
|
-
if (instance) {
|
|
1706
|
-
ui = instance;
|
|
1707
|
-
}
|
|
1708
|
-
return ui ??= new UnicornUI();
|
|
1709
|
-
}
|
|
1710
|
-
function useUITheme(theme) {
|
|
1711
|
-
const ui2 = useUI();
|
|
1712
|
-
if (ui2.theme && !theme) {
|
|
1713
|
-
return ui2.theme;
|
|
1714
|
-
}
|
|
1715
|
-
if (typeof theme === "function") {
|
|
1716
|
-
theme = new theme();
|
|
1717
|
-
}
|
|
1718
|
-
ui2.installTheme(theme);
|
|
1719
|
-
return ui2.theme;
|
|
1720
|
-
}
|
|
1721
|
-
class UnicornUI {
|
|
1722
|
-
theme;
|
|
1723
|
-
static get defaultOptions() {
|
|
1724
|
-
return {
|
|
1725
|
-
messageSelector: ".message-wrap"
|
|
1726
|
-
};
|
|
1727
|
-
}
|
|
1728
|
-
installTheme(theme) {
|
|
1729
|
-
this.theme = theme;
|
|
1730
|
-
}
|
|
1731
|
-
// confirm(message: string): Promise<boolean> {
|
|
1732
|
-
// message = message || 'Are you sure?';
|
|
1733
|
-
//
|
|
1734
|
-
// return new Promise((resolve) => {
|
|
1735
|
-
// resolve(window.confirm(message));
|
|
1736
|
-
// });
|
|
1737
|
-
// }
|
|
1738
|
-
//
|
|
1739
|
-
// alert(title: string, text = '', type = 'info'): Promise<boolean> {
|
|
1740
|
-
// if (text) {
|
|
1741
|
-
// title += ' | ' + text;
|
|
1742
|
-
// }
|
|
1743
|
-
//
|
|
1744
|
-
// window.alert(title);
|
|
1745
|
-
//
|
|
1746
|
-
// return Promise.resolve(true);
|
|
1747
|
-
// }
|
|
1748
|
-
}
|
|
1749
|
-
const prepares = [];
|
|
1750
|
-
const { promise: alpineLoaded, resolve: alpineResolve } = /* @__PURE__ */ promiseWithResolvers();
|
|
1751
|
-
async function loadAlpine(callback) {
|
|
1752
|
-
if (callback && !window.Alpine) {
|
|
1753
|
-
prepares.push(callback);
|
|
1754
|
-
}
|
|
1755
|
-
const { default: Alpine } = await useImport("@alpinejs");
|
|
1756
|
-
if (!window.Alpine) {
|
|
1757
|
-
await Promise.all(prepares.map((callback2) => Promise.resolve(callback2(Alpine))));
|
|
1758
|
-
Alpine.start();
|
|
1759
|
-
window.Alpine = Alpine;
|
|
1760
|
-
alpineResolve(Alpine);
|
|
1761
|
-
} else if (callback) {
|
|
1762
|
-
await callback(Alpine);
|
|
1763
|
-
}
|
|
1764
|
-
return Alpine;
|
|
1765
|
-
}
|
|
1766
|
-
async function initAlpineComponent(directive) {
|
|
1767
|
-
const Alpine = await alpineLoaded;
|
|
1768
|
-
await nextTick();
|
|
1769
|
-
selectAll(`[${directive}]`, (el) => {
|
|
1770
|
-
const code = el.getAttribute(directive) || "";
|
|
1771
|
-
el.removeAttribute(directive);
|
|
1772
|
-
Alpine.mutateDom(() => {
|
|
1773
|
-
el.setAttribute("x-data", code);
|
|
1774
|
-
});
|
|
1775
|
-
Alpine.initTree(el);
|
|
1776
|
-
});
|
|
1777
|
-
}
|
|
1778
|
-
async function prepareAlpine(callback) {
|
|
1779
|
-
if (window.Alpine) {
|
|
1780
|
-
await callback(window.Alpine);
|
|
1781
|
-
} else {
|
|
1782
|
-
prepares.push(callback);
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
async function prepareAlpineDefer(callback) {
|
|
1786
|
-
await alpineLoaded;
|
|
1787
|
-
await callback(window.Alpine);
|
|
1788
|
-
}
|
|
1789
|
-
function renderMessage(messages, type = "info") {
|
|
1790
|
-
return ui.theme?.renderMessage(messages, type);
|
|
1791
|
-
}
|
|
1792
|
-
function clearMessages() {
|
|
1793
|
-
ui.theme?.clearMessages();
|
|
1794
|
-
}
|
|
1795
|
-
async function mark(selector, keyword = "", options = {}) {
|
|
1796
|
-
const modules = await useImport("@vendor/mark.js/dist/mark.min.js");
|
|
1797
|
-
if (selector != null) {
|
|
1798
|
-
const instance = new Mark(selector);
|
|
1799
|
-
instance.mark(keyword, options);
|
|
1800
|
-
}
|
|
1801
|
-
return modules;
|
|
1802
|
-
}
|
|
1803
|
-
async function slideUp(target, duration = 300) {
|
|
1804
|
-
const ele = selectOne(target);
|
|
1805
|
-
if (!ele) {
|
|
1806
|
-
return Promise.resolve();
|
|
1807
|
-
}
|
|
1808
|
-
ele.style.overflow = "hidden";
|
|
1809
|
-
const animation = animateTo(
|
|
1810
|
-
ele,
|
|
1811
|
-
{ height: 0, paddingTop: 0, paddingBottom: 0 },
|
|
1812
|
-
{ duration, easing: "ease-out" }
|
|
1813
|
-
);
|
|
1814
|
-
data(ele, "animation.sliding.up", true);
|
|
1815
|
-
const r = await animation.finished;
|
|
1816
|
-
if (!data(ele, "animation.sliding.down")) {
|
|
1817
|
-
ele.style.display = "none";
|
|
1818
|
-
}
|
|
1819
|
-
removeData(ele, "animation.sliding.up");
|
|
1820
|
-
return r;
|
|
1821
|
-
}
|
|
1822
|
-
function slideDown(target, duration = 300, display = "block") {
|
|
1823
|
-
const ele = selectOne(target);
|
|
1824
|
-
if (!ele) {
|
|
1825
|
-
return Promise.resolve();
|
|
1826
|
-
}
|
|
1827
|
-
data(ele, "animation.sliding.down", true);
|
|
1828
|
-
ele.style.display = display;
|
|
1829
|
-
ele.style.overflow = "hidden";
|
|
1830
|
-
let maxHeight = 0;
|
|
1831
|
-
for (const child of Array.from(ele.children)) {
|
|
1832
|
-
maxHeight = Math.max(child.offsetHeight, maxHeight);
|
|
1833
|
-
}
|
|
1834
|
-
const animation = animateTo(
|
|
1835
|
-
ele,
|
|
1836
|
-
{
|
|
1837
|
-
height: [
|
|
1838
|
-
0,
|
|
1839
|
-
maxHeight + "px"
|
|
1840
|
-
]
|
|
1841
|
-
},
|
|
1842
|
-
{ duration, easing: "ease-out" }
|
|
1843
|
-
);
|
|
1844
|
-
animation.addEventListener("finish", () => {
|
|
1845
|
-
ele.style.height = "";
|
|
1846
|
-
if (!data(ele, "animation.sliding.up")) {
|
|
1847
|
-
ele.style.overflow = "visible";
|
|
1848
|
-
}
|
|
1849
|
-
removeData(ele, "animation.sliding.down");
|
|
1850
|
-
});
|
|
1851
|
-
return animation.finished;
|
|
1852
|
-
}
|
|
1853
|
-
function slideToggle(target, duration = 500, display = "block") {
|
|
1854
|
-
const ele = selectOne(target);
|
|
1855
|
-
if (!ele) {
|
|
1856
|
-
return Promise.resolve();
|
|
1857
|
-
}
|
|
1858
|
-
if (window.getComputedStyle(ele).display === "none") {
|
|
1859
|
-
return slideDown(ele, duration, display);
|
|
1860
|
-
} else {
|
|
1861
|
-
return slideUp(ele, duration);
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
async function fadeOut(selector, duration = 500) {
|
|
1865
|
-
const el = selectOne(selector);
|
|
1866
|
-
if (!el) {
|
|
1867
|
-
return;
|
|
1868
|
-
}
|
|
1869
|
-
const animation = animateTo(el, { opacity: 0 }, { duration, easing: "ease-out" });
|
|
1870
|
-
const p = await animation.finished;
|
|
1871
|
-
el.style.display = "none";
|
|
1872
|
-
return p;
|
|
1873
|
-
}
|
|
1874
|
-
async function fadeIn(selector, duration = 500, display = "block") {
|
|
1875
|
-
const el = selectOne(selector);
|
|
1876
|
-
if (!el) {
|
|
1877
|
-
return;
|
|
1878
|
-
}
|
|
1879
|
-
el.style.display = "";
|
|
1880
|
-
if (window.getComputedStyle(el).display !== display) {
|
|
1881
|
-
el.style.display = display;
|
|
1882
|
-
}
|
|
1883
|
-
const animation = animateTo(el, { opacity: 1 }, { duration, easing: "ease-out" });
|
|
1884
|
-
return animation.finished;
|
|
1885
|
-
}
|
|
1886
|
-
async function highlight(selector, color = "#ffff99", duration = 600) {
|
|
1887
|
-
const ele = selectOne(selector);
|
|
1888
|
-
if (!ele) {
|
|
1889
|
-
return;
|
|
1890
|
-
}
|
|
1891
|
-
duration /= 2;
|
|
1892
|
-
const bg = window.getComputedStyle(ele).backgroundColor;
|
|
1893
|
-
const animation = animateTo(ele, { backgroundColor: color }, { duration });
|
|
1894
|
-
await animation.finished;
|
|
1895
|
-
return animateTo(ele, { backgroundColor: bg }, { duration });
|
|
1896
|
-
}
|
|
1897
|
-
async function useColorPicker(selector, options = {}) {
|
|
1898
|
-
if (options?.theme === "dark") {
|
|
1899
|
-
useCssImport("@spectrum/spectrum-dark.min.css");
|
|
1900
|
-
} else if (!options?.theme) {
|
|
1901
|
-
useCssImport("@spectrum/spectrum.min.css");
|
|
1902
|
-
}
|
|
1903
|
-
const m = await useImport("@spectrum");
|
|
1904
|
-
if (typeof options.locale === "string") {
|
|
1905
|
-
let ls = options.locale.split("-").map((l) => l.toLowerCase());
|
|
1906
|
-
if (ls[0] === ls[1]) {
|
|
1907
|
-
ls = [ls];
|
|
1908
|
-
}
|
|
1909
|
-
ls = ls.join("-");
|
|
1910
|
-
try {
|
|
1911
|
-
await useImport(`@spectrum/i18n/${ls}.js`);
|
|
1912
|
-
} catch (e) {
|
|
1913
|
-
console.warn(`Unable to load Spectrum locale "${ls}" (${options.locale})`);
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
if (selector) {
|
|
1917
|
-
return module$1(selector, "spectrum", (ele) => Spectrum.getInstance(ele, options));
|
|
1918
|
-
}
|
|
1919
|
-
return m;
|
|
1920
|
-
}
|
|
1921
|
-
function useDisableOnSubmit(formSelector = "#admin-form", buttonSelector = "", options = {}) {
|
|
1922
|
-
buttonSelector = buttonSelector || [
|
|
1923
|
-
"#admin-toolbar button",
|
|
1924
|
-
"#admin-toolbar a",
|
|
1925
|
-
formSelector + " .disable-on-submit",
|
|
1926
|
-
formSelector + " .js-dos",
|
|
1927
|
-
formSelector + " [data-dos]"
|
|
1928
|
-
].join(",");
|
|
1929
|
-
const iconSelector = options.iconSelector || [
|
|
1930
|
-
'[class*="fa-"]',
|
|
1931
|
-
"[data-spin]",
|
|
1932
|
-
"[data-spinner]"
|
|
1933
|
-
].join(",");
|
|
1934
|
-
const event = options.event || "submit";
|
|
1935
|
-
const spinnerClass = options.spinnerClass || "spinner-border spinner-border-sm";
|
|
1936
|
-
const loadingClass = options.loadingCass || "is-loading";
|
|
1937
|
-
selectAll(buttonSelector, (button) => {
|
|
1938
|
-
button.addEventListener("click", (e) => {
|
|
1939
|
-
button.dataset.clicked = "1";
|
|
1940
|
-
setTimeout(() => {
|
|
1941
|
-
delete button.dataset.clicked;
|
|
1942
|
-
}, 1500);
|
|
1943
|
-
});
|
|
1944
|
-
});
|
|
1945
|
-
const form = selectOne(formSelector);
|
|
1946
|
-
form?.addEventListener(event, (e) => {
|
|
1947
|
-
setTimeout(() => {
|
|
1948
|
-
if (!form.checkValidity()) {
|
|
1949
|
-
return;
|
|
1950
|
-
}
|
|
1951
|
-
selectAll(buttonSelector, (button) => {
|
|
1952
|
-
button.style.pointerEvents = "none";
|
|
1953
|
-
button.setAttribute("disabled", "disabled");
|
|
1954
|
-
button.classList.add("disabled");
|
|
1955
|
-
if (button.dataset.clicked) {
|
|
1956
|
-
let icon = button.querySelector(iconSelector);
|
|
1957
|
-
button.classList.add(loadingClass);
|
|
1958
|
-
if (icon) {
|
|
1959
|
-
const i = html("<i></i>");
|
|
1960
|
-
icon.parentNode.replaceChild(i, icon);
|
|
1961
|
-
i.setAttribute("class", spinnerClass);
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
});
|
|
1965
|
-
}, 0);
|
|
1966
|
-
});
|
|
1967
|
-
}
|
|
1968
|
-
function useDisableIfStackNotEmpty(buttonSelector = "[data-task=save]", stackName = "uploading") {
|
|
1969
|
-
const stack2 = useStack(stackName);
|
|
1970
|
-
stack2.observe((stack22, length) => {
|
|
1971
|
-
for (const button of selectAll(buttonSelector)) {
|
|
1972
|
-
if (length > 0) {
|
|
1973
|
-
button.setAttribute("disabled", "disabled");
|
|
1974
|
-
button.classList.add("disabled");
|
|
1975
|
-
} else {
|
|
1976
|
-
button.removeAttribute("disabled");
|
|
1977
|
-
button.classList.remove("disabled");
|
|
1978
|
-
}
|
|
1979
|
-
}
|
|
1980
|
-
});
|
|
1981
|
-
}
|
|
1982
|
-
function useKeepAlive(url, time = 6e4) {
|
|
1983
|
-
const aliveHandle = window.setInterval(() => fetch(url), time);
|
|
1984
|
-
return () => {
|
|
1985
|
-
clearInterval(aliveHandle);
|
|
1986
|
-
};
|
|
1987
|
-
}
|
|
1988
|
-
async function useVueComponentField(selector, value, options = {}) {
|
|
1989
|
-
const m = await useImport("@unicorn/field/vue-component-field.js");
|
|
1990
|
-
if (selector) {
|
|
1991
|
-
m.VueComponentField.init(selector, value, options);
|
|
1992
|
-
}
|
|
1993
|
-
return m;
|
|
1994
|
-
}
|
|
1995
|
-
function useSystemUri(type, path) {
|
|
1996
|
-
const uri2 = UnicornSystemUri.get();
|
|
1997
|
-
if (type) {
|
|
1998
|
-
return uri2[type](path);
|
|
1999
|
-
}
|
|
2000
|
-
return uri2;
|
|
2001
|
-
}
|
|
2002
|
-
function useAssetUri(type, path) {
|
|
2003
|
-
const asset2 = UnicornAssetUri.get();
|
|
2004
|
-
if (type) {
|
|
2005
|
-
return asset2[type](path);
|
|
2006
|
-
}
|
|
2007
|
-
return asset2;
|
|
2008
|
-
}
|
|
2009
|
-
function uri(type) {
|
|
2010
|
-
return data("unicorn.uri")[type];
|
|
2011
|
-
}
|
|
2012
|
-
function asset(type) {
|
|
2013
|
-
return uri("asset")[type];
|
|
2014
|
-
}
|
|
2015
|
-
function addUriBase(uri2, type = "path") {
|
|
2016
|
-
if (uri2.substring(0, 2) === "//" || uri2.substring(0, 4) === "http") {
|
|
2017
|
-
return uri2;
|
|
2018
|
-
}
|
|
2019
|
-
return asset(type) + "/" + uri2;
|
|
2020
|
-
}
|
|
2021
|
-
class UnicornSystemUri extends URL {
|
|
2022
|
-
static instance;
|
|
2023
|
-
static get() {
|
|
2024
|
-
return this.instance ??= new this(uri("full"));
|
|
2025
|
-
}
|
|
2026
|
-
path(path = "") {
|
|
2027
|
-
return uri("path") + path;
|
|
2028
|
-
}
|
|
2029
|
-
root(path = "") {
|
|
2030
|
-
return uri("root") + path;
|
|
2031
|
-
}
|
|
2032
|
-
current() {
|
|
2033
|
-
return uri("current") || "";
|
|
2034
|
-
}
|
|
2035
|
-
full() {
|
|
2036
|
-
return uri("full") || "";
|
|
2037
|
-
}
|
|
2038
|
-
route() {
|
|
2039
|
-
return uri("route") || "";
|
|
2040
|
-
}
|
|
2041
|
-
script() {
|
|
2042
|
-
return uri("script") || "";
|
|
2043
|
-
}
|
|
2044
|
-
routeWithQuery() {
|
|
2045
|
-
const route2 = this.route();
|
|
2046
|
-
const query = this.searchParams.toString();
|
|
2047
|
-
return query ? `${route2}?${query}` : route2;
|
|
2048
|
-
}
|
|
2049
|
-
routeAndQuery() {
|
|
2050
|
-
const route2 = this.route();
|
|
2051
|
-
const query = this.searchParams.toString();
|
|
2052
|
-
return [route2, query];
|
|
2053
|
-
}
|
|
2054
|
-
}
|
|
2055
|
-
class UnicornAssetUri {
|
|
2056
|
-
static instance;
|
|
2057
|
-
static get() {
|
|
2058
|
-
return this.instance ??= new this();
|
|
2059
|
-
}
|
|
2060
|
-
path(path = "") {
|
|
2061
|
-
return asset("path") + path;
|
|
2062
|
-
}
|
|
2063
|
-
root(path = "") {
|
|
2064
|
-
return asset("root") + path;
|
|
2065
|
-
}
|
|
2066
|
-
}
|
|
2067
|
-
function encode(obj, pfx) {
|
|
2068
|
-
var k, i, tmp, str = "";
|
|
2069
|
-
for (k in obj) {
|
|
2070
|
-
if ((tmp = obj[k]) !== void 0) {
|
|
2071
|
-
if (Array.isArray(tmp)) {
|
|
2072
|
-
for (i = 0; i < tmp.length; i++) {
|
|
2073
|
-
str && (str += "&");
|
|
2074
|
-
str += encodeURIComponent(k) + "=" + encodeURIComponent(tmp[i]);
|
|
2075
|
-
}
|
|
2076
|
-
} else {
|
|
2077
|
-
str && (str += "&");
|
|
2078
|
-
str += encodeURIComponent(k) + "=" + encodeURIComponent(tmp);
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
return "" + str;
|
|
2083
|
-
}
|
|
2084
|
-
function toValue(mix) {
|
|
2085
|
-
if (!mix) return "";
|
|
2086
|
-
var str = decodeURIComponent(mix);
|
|
2087
|
-
if (str === "false") return false;
|
|
2088
|
-
if (str === "true") return true;
|
|
2089
|
-
return +str * 0 === 0 ? +str : str;
|
|
2090
|
-
}
|
|
2091
|
-
function decode(str) {
|
|
2092
|
-
var tmp, k, out = {}, arr = str.split("&");
|
|
2093
|
-
while (tmp = arr.shift()) {
|
|
2094
|
-
tmp = tmp.split("=");
|
|
2095
|
-
k = tmp.shift();
|
|
2096
|
-
if (out[k] !== void 0) {
|
|
2097
|
-
out[k] = [].concat(out[k], toValue(tmp.shift()));
|
|
2098
|
-
} else {
|
|
2099
|
-
out[k] = toValue(tmp.shift());
|
|
2100
|
-
}
|
|
2101
|
-
}
|
|
2102
|
-
return out;
|
|
2103
|
-
}
|
|
2104
|
-
function addRoute(route2, url) {
|
|
2105
|
-
const routes = data("unicorn.routes") || {};
|
|
2106
|
-
routes[route2] = url;
|
|
2107
|
-
data("unicorn.routes", routes);
|
|
2108
|
-
}
|
|
2109
|
-
function route(route2, query) {
|
|
2110
|
-
const source = route2;
|
|
2111
|
-
const extract = extractRoute(source);
|
|
2112
|
-
route2 = extract.route;
|
|
2113
|
-
let path = extract.path;
|
|
2114
|
-
const routes = data("unicorn.routes") || {};
|
|
2115
|
-
let url = routes[route2];
|
|
2116
|
-
if (url == null) {
|
|
2117
|
-
if (!route2.startsWith("@")) {
|
|
2118
|
-
route2 = "@" + route2;
|
|
2119
|
-
} else {
|
|
2120
|
-
route2 = route2.substring(1);
|
|
2121
|
-
}
|
|
2122
|
-
}
|
|
2123
|
-
url = routes[route2];
|
|
2124
|
-
if (url == null) {
|
|
2125
|
-
throw new Error(`Route: "${source}" not found`);
|
|
2126
|
-
}
|
|
2127
|
-
if (path) {
|
|
2128
|
-
const { route: u1, path: u1q } = extractRoute(url, "?");
|
|
2129
|
-
const { route: u2, path: u2q } = extractRoute(path, "?");
|
|
2130
|
-
url = u1 + "/" + u2;
|
|
2131
|
-
if (u1q || u2q) {
|
|
2132
|
-
const q = [u1q, u2q].filter((u) => u).join("&");
|
|
2133
|
-
url += "?" + q;
|
|
2134
|
-
}
|
|
2135
|
-
}
|
|
2136
|
-
return addQuery(url, query);
|
|
2137
|
-
}
|
|
2138
|
-
function extractRoute(route2, sep = "/") {
|
|
2139
|
-
if (route2.indexOf(sep) === -1) {
|
|
2140
|
-
return { route: route2, path: "" };
|
|
2141
|
-
}
|
|
2142
|
-
const segments = route2.split(sep);
|
|
2143
|
-
route2 = segments.shift() || "";
|
|
2144
|
-
const path = segments.join(sep);
|
|
2145
|
-
return { route: route2, path };
|
|
2146
|
-
}
|
|
2147
|
-
function hasRoute(route2) {
|
|
2148
|
-
return void 0 !== data("unicorn.routes")[route2];
|
|
2149
|
-
}
|
|
2150
|
-
function addQuery(url, query) {
|
|
2151
|
-
if (query == null) {
|
|
2152
|
-
return url;
|
|
2153
|
-
}
|
|
2154
|
-
for (let k in query) {
|
|
2155
|
-
const v = query[k];
|
|
2156
|
-
const placeholder = `{${k}}`;
|
|
2157
|
-
if (url.indexOf(placeholder) !== -1) {
|
|
2158
|
-
url = url.replace(
|
|
2159
|
-
new RegExp(`${placeholder}`, "g"),
|
|
2160
|
-
v
|
|
2161
|
-
);
|
|
2162
|
-
delete query[k];
|
|
2163
|
-
}
|
|
2164
|
-
const encodedPlaceholder = encodeURIComponent(`{${k}}`);
|
|
2165
|
-
if (url.indexOf(encodedPlaceholder) !== -1) {
|
|
2166
|
-
url = url.replace(
|
|
2167
|
-
new RegExp(`${encodedPlaceholder}`, "g"),
|
|
2168
|
-
v
|
|
2169
|
-
);
|
|
2170
|
-
delete query[k];
|
|
2171
|
-
}
|
|
2172
|
-
}
|
|
2173
|
-
if (Object.keys(query).length === 0) {
|
|
2174
|
-
return url;
|
|
2175
|
-
}
|
|
2176
|
-
const queryString = encode(query);
|
|
2177
|
-
return url + (/\?/.test(url) ? `&${queryString}` : `?${queryString}`);
|
|
2178
|
-
}
|
|
2179
|
-
function parseQuery(queryString) {
|
|
2180
|
-
return decode(queryString);
|
|
2181
|
-
}
|
|
2182
|
-
function buildQuery(query) {
|
|
2183
|
-
return encode(query);
|
|
2184
|
-
}
|
|
2185
|
-
function removeCloak() {
|
|
2186
|
-
if (globalThis.document == null) {
|
|
2187
|
-
return;
|
|
2188
|
-
}
|
|
2189
|
-
selectAll("[uni-cloak]", (el) => el.removeAttribute("uni-cloak"));
|
|
2190
|
-
}
|
|
2191
|
-
function data(ele, name, value) {
|
|
2192
|
-
if (!(ele instanceof HTMLElement)) {
|
|
2193
|
-
value = name;
|
|
2194
|
-
name = ele;
|
|
2195
|
-
ele = document;
|
|
2196
|
-
}
|
|
2197
|
-
if (name === void 0) {
|
|
2198
|
-
return getData(ele);
|
|
2199
|
-
}
|
|
2200
|
-
if (value === void 0) {
|
|
2201
|
-
return getData(ele, name);
|
|
2202
|
-
}
|
|
2203
|
-
setData(ele, name, value);
|
|
2204
|
-
}
|
|
2205
|
-
function removeData(ele, name = void 0) {
|
|
2206
|
-
if (!(ele instanceof HTMLElement)) {
|
|
2207
|
-
name = ele;
|
|
2208
|
-
ele = document;
|
|
2209
|
-
}
|
|
2210
|
-
removeData$1(ele, name);
|
|
2211
|
-
}
|
|
2212
|
-
class EventMixin {
|
|
2213
|
-
_listeners = {};
|
|
2214
|
-
on(event, handler) {
|
|
2215
|
-
if (Array.isArray(event)) {
|
|
2216
|
-
for (const e of event) {
|
|
2217
|
-
this.on(e, handler);
|
|
2218
|
-
}
|
|
2219
|
-
return this;
|
|
2220
|
-
}
|
|
2221
|
-
this._listeners[event] ??= [];
|
|
2222
|
-
this._listeners[event].push(handler);
|
|
2223
|
-
return this;
|
|
2224
|
-
}
|
|
2225
|
-
once(event, handler) {
|
|
2226
|
-
handler.once = true;
|
|
2227
|
-
return this.on(event, handler);
|
|
2228
|
-
}
|
|
2229
|
-
off(event, handler) {
|
|
2230
|
-
if (handler) {
|
|
2231
|
-
this._listeners[event] = this.listeners(event).filter((listener) => listener !== handler);
|
|
2232
|
-
return this;
|
|
2233
|
-
}
|
|
2234
|
-
delete this._listeners[event];
|
|
2235
|
-
return this;
|
|
2236
|
-
}
|
|
2237
|
-
trigger(event, ...args) {
|
|
2238
|
-
if (Array.isArray(event)) {
|
|
2239
|
-
for (const e of event) {
|
|
2240
|
-
this.trigger(e);
|
|
2241
|
-
}
|
|
2242
|
-
return this;
|
|
2243
|
-
}
|
|
2244
|
-
for (const listener of this.listeners(event)) {
|
|
2245
|
-
listener(...args);
|
|
2246
|
-
}
|
|
2247
|
-
this._listeners[event] = this.listeners(event).filter((listener) => listener?.once !== true);
|
|
2248
|
-
return this;
|
|
2249
|
-
}
|
|
2250
|
-
listeners(event) {
|
|
2251
|
-
return this._listeners[event] === void 0 ? [] : this._listeners[event];
|
|
2252
|
-
}
|
|
2253
|
-
}
|
|
2254
|
-
class UnicornApp extends (/* @__PURE__ */ Mixin(EventMixin)) {
|
|
2255
|
-
registry = /* @__PURE__ */ new Map();
|
|
2256
|
-
plugins = /* @__PURE__ */ new Map();
|
|
2257
|
-
// _listeners = {};
|
|
2258
|
-
waits = [];
|
|
2259
|
-
options;
|
|
2260
|
-
defaultOptions = {};
|
|
2261
|
-
domready = domready;
|
|
2262
|
-
data = data;
|
|
2263
|
-
constructor(options = {}) {
|
|
2264
|
-
super();
|
|
2265
|
-
this.options = Object.assign({}, this.defaultOptions, options);
|
|
2266
|
-
if (typeof document !== "undefined") {
|
|
2267
|
-
this.wait((resolve) => {
|
|
2268
|
-
document.addEventListener("DOMContentLoaded", () => resolve());
|
|
2269
|
-
});
|
|
2270
|
-
document.addEventListener("DOMContentLoaded", () => {
|
|
2271
|
-
this.completed().then(() => this.trigger("loaded"));
|
|
2272
|
-
});
|
|
2273
|
-
}
|
|
2274
|
-
}
|
|
2275
|
-
use(plugin, options = {}) {
|
|
2276
|
-
if (Array.isArray(plugin)) {
|
|
2277
|
-
plugin.forEach((p) => this.use(p));
|
|
2278
|
-
return this;
|
|
2279
|
-
}
|
|
2280
|
-
plugin?.install?.(this, options);
|
|
2281
|
-
this.trigger("plugin.installed", plugin);
|
|
2282
|
-
this.plugins.set(plugin, plugin);
|
|
2283
|
-
return this;
|
|
2284
|
-
}
|
|
2285
|
-
detach(plugin) {
|
|
2286
|
-
if (plugin.uninstall) {
|
|
2287
|
-
plugin.uninstall(this);
|
|
2288
|
-
}
|
|
2289
|
-
this.trigger("plugin.uninstalled", plugin);
|
|
2290
|
-
return this;
|
|
2291
|
-
}
|
|
2292
|
-
inject(id, def) {
|
|
2293
|
-
if (!this.registry.has(id)) {
|
|
2294
|
-
if (def !== void 0) {
|
|
2295
|
-
return def;
|
|
2296
|
-
}
|
|
2297
|
-
throw new Error(`Injectable: "${id.name ?? id}" not found.`);
|
|
2298
|
-
}
|
|
2299
|
-
return this.registry.get(id);
|
|
2300
|
-
}
|
|
2301
|
-
provide(id, value) {
|
|
2302
|
-
this.registry.set(id, value);
|
|
2303
|
-
return this;
|
|
2304
|
-
}
|
|
2305
|
-
// trigger(event, ...args) {
|
|
2306
|
-
// return this.tap(super.trigger(event, ...args), () => {
|
|
2307
|
-
// if (this.data('windwalker.debug')) {
|
|
2308
|
-
// console.debug(`[Unicorn Event] ${event}`, args, this.listeners(event));
|
|
2309
|
-
// }
|
|
2310
|
-
// });
|
|
2311
|
-
// }
|
|
2312
|
-
wait(callback) {
|
|
2313
|
-
const p = new Promise((resolve, reject) => {
|
|
2314
|
-
const promise = callback(resolve, reject);
|
|
2315
|
-
if (promise && "then" in promise) {
|
|
2316
|
-
promise.then(resolve).catch(reject);
|
|
2317
|
-
}
|
|
2318
|
-
});
|
|
2319
|
-
this.waits.push(p);
|
|
2320
|
-
return p;
|
|
2321
|
-
}
|
|
2322
|
-
completed() {
|
|
2323
|
-
const promise = Promise.all(this.waits);
|
|
2324
|
-
this.waits = [];
|
|
2325
|
-
return promise;
|
|
2326
|
-
}
|
|
2327
|
-
macro(name, prop) {
|
|
2328
|
-
if (this[name]) {
|
|
2329
|
-
throw new Error(`Macro: ${name} already exists.`);
|
|
2330
|
-
}
|
|
2331
|
-
this[name] = prop;
|
|
2332
|
-
return this;
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
function formRequestSubmit(prototype) {
|
|
2336
|
-
if (typeof prototype.requestSubmit == "function") {
|
|
2337
|
-
return;
|
|
2338
|
-
}
|
|
2339
|
-
prototype.requestSubmit = function(submitter) {
|
|
2340
|
-
if (submitter) {
|
|
2341
|
-
validateSubmitter(submitter, this);
|
|
2342
|
-
submitter.click();
|
|
2343
|
-
} else {
|
|
2344
|
-
submitter = document.createElement("input");
|
|
2345
|
-
submitter.type = "submit";
|
|
2346
|
-
submitter.hidden = true;
|
|
2347
|
-
this.appendChild(submitter);
|
|
2348
|
-
submitter.click();
|
|
2349
|
-
this.removeChild(submitter);
|
|
2350
|
-
}
|
|
2351
|
-
};
|
|
2352
|
-
function validateSubmitter(submitter, form) {
|
|
2353
|
-
submitter instanceof HTMLElement || raise(TypeError, "parameter 1 is not of type 'HTMLElement'");
|
|
2354
|
-
submitter.type == "submit" || raise(TypeError, "The specified element is not a submit button");
|
|
2355
|
-
submitter.form == form || raise(DOMException, "The specified element is not owned by this form element", "NotFoundError");
|
|
2356
|
-
}
|
|
2357
|
-
function raise(errorConstructor, message, name) {
|
|
2358
|
-
throw new errorConstructor("Failed to execute 'requestSubmit' on 'HTMLFormElement': " + message + ".", name);
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
function polyfill() {
|
|
2362
|
-
if (typeof window !== "undefined") {
|
|
2363
|
-
formRequestSubmit(HTMLFormElement.prototype);
|
|
2364
|
-
}
|
|
2365
|
-
}
|
|
2366
|
-
async function useFieldMultiUploader() {
|
|
2367
|
-
const module = await import("./field-multi-uploader.js");
|
|
2368
|
-
await module.ready;
|
|
2369
|
-
return module;
|
|
2370
|
-
}
|
|
2371
|
-
function useUnicornPhpAdapter(app2) {
|
|
2372
|
-
app2 ??= useUnicorn();
|
|
2373
|
-
app2.use(UnicornPhpAdapter);
|
|
2374
|
-
return app2.$ui;
|
|
2375
|
-
}
|
|
2376
|
-
const methods = {
|
|
2377
|
-
repeatable: useFieldRepeatable,
|
|
2378
|
-
flatpickr: useFieldFlatpickr,
|
|
2379
|
-
fileDrag: useFieldFileDrag,
|
|
2380
|
-
modalField: useFieldModalSelect,
|
|
2381
|
-
cascadeSelect: useFieldCascadeSelect,
|
|
2382
|
-
sid: useFieldSingleImageDrag,
|
|
2383
|
-
tinymce: {
|
|
2384
|
-
init: useTinymce
|
|
2385
|
-
},
|
|
2386
|
-
s3Uploader: useS3Uploader,
|
|
2387
|
-
iframeModal: useIframeModal,
|
|
2388
|
-
initShowOn: useShowOn,
|
|
2389
|
-
modalTree: useFieldModalTree,
|
|
2390
|
-
multiUploader: useFieldMultiUploader,
|
|
2391
|
-
tomSelect: useTomSelect,
|
|
2392
|
-
listDependent: useListDependent,
|
|
2393
|
-
bootstrap: {
|
|
2394
|
-
tooltip: useBs5Tooltip,
|
|
2395
|
-
buttonRadio: useBs5ButtonRadio,
|
|
2396
|
-
keepTab: useBs5KeepTab
|
|
2397
|
-
}
|
|
2398
|
-
};
|
|
2399
|
-
class UnicornPhpAdapter {
|
|
2400
|
-
static install(app2) {
|
|
2401
|
-
if (app2.$ui) {
|
|
2402
|
-
app2.$ui = { ...app2.$ui, ...methods };
|
|
2403
|
-
} else {
|
|
2404
|
-
app2.$ui = methods;
|
|
2405
|
-
}
|
|
2406
|
-
}
|
|
2407
|
-
}
|
|
2408
|
-
let app;
|
|
2409
|
-
function createUnicorn() {
|
|
2410
|
-
polyfill();
|
|
2411
|
-
removeCloak();
|
|
2412
|
-
return app = new UnicornApp();
|
|
2413
|
-
}
|
|
2414
|
-
function createUnicornWithPlugins() {
|
|
2415
|
-
const app2 = createUnicorn();
|
|
2416
|
-
return app2;
|
|
2417
|
-
}
|
|
2418
|
-
function useUnicorn(instance) {
|
|
2419
|
-
if (instance) {
|
|
2420
|
-
app = instance;
|
|
2421
|
-
}
|
|
2422
|
-
return app ??= createUnicorn();
|
|
2423
|
-
}
|
|
2424
|
-
const useInject = (id, def) => {
|
|
2425
|
-
return useUnicorn().inject(id, def);
|
|
2426
|
-
};
|
|
2427
|
-
function pushUnicornToGlobal(app2) {
|
|
2428
|
-
window.u = app2 ?? useUnicorn();
|
|
2429
|
-
}
|
|
2430
|
-
function useMacro(name, prop) {
|
|
2431
|
-
const app2 = useUnicorn();
|
|
2432
|
-
if (typeof name === "string") {
|
|
2433
|
-
app2.macro(name, prop);
|
|
2434
|
-
} else {
|
|
2435
|
-
for (const k in name) {
|
|
2436
|
-
app2.macro(k, name[k]);
|
|
2437
|
-
}
|
|
2438
|
-
}
|
|
2439
|
-
return app2;
|
|
2440
|
-
}
|
|
2441
|
-
async function useLegacy(app2) {
|
|
2442
|
-
app2 ??= useUnicorn();
|
|
2443
|
-
pushUnicornToGlobal(app2);
|
|
2444
|
-
const { useLegacyMethods } = await import("./legacy.js");
|
|
2445
|
-
await useLegacyMethods(app2);
|
|
2446
|
-
return app2;
|
|
2447
|
-
}
|
|
2448
|
-
export {
|
|
2449
|
-
useBs5KeepTab as $,
|
|
2450
|
-
h as A,
|
|
2451
|
-
html as B,
|
|
2452
|
-
delegate as C,
|
|
2453
|
-
debounce as D,
|
|
2454
|
-
throttle as E,
|
|
2455
|
-
simpleConfirm as F,
|
|
2456
|
-
simpleAlert as G,
|
|
2457
|
-
sprintfExports as H,
|
|
2458
|
-
base64UrlEncode as I,
|
|
2459
|
-
base64UrlDecode as J,
|
|
2460
|
-
uid as K,
|
|
2461
|
-
tid as L,
|
|
2462
|
-
serial as M,
|
|
2463
|
-
mark as N,
|
|
2464
|
-
useTomSelect as O,
|
|
2465
|
-
slideUp as P,
|
|
2466
|
-
slideDown as Q,
|
|
2467
|
-
slideToggle as R,
|
|
2468
|
-
fadeOut as S,
|
|
2469
|
-
fadeIn as T,
|
|
2470
|
-
highlight as U,
|
|
2471
|
-
useColorPicker as V,
|
|
2472
|
-
useDisableOnSubmit as W,
|
|
2473
|
-
useDisableIfStackNotEmpty as X,
|
|
2474
|
-
useCheckboxesMultiSelect as Y,
|
|
2475
|
-
useKeepAlive as Z,
|
|
2476
|
-
__ as _,
|
|
2477
|
-
useUniDirective as a,
|
|
2478
|
-
useS3MultipartUploader as a$,
|
|
2479
|
-
useBs5ButtonRadio as a0,
|
|
2480
|
-
useBs5Tooltip as a1,
|
|
2481
|
-
useFormAsync as a2,
|
|
2482
|
-
useGridAsync as a3,
|
|
2483
|
-
useForm as a4,
|
|
2484
|
-
useGrid as a5,
|
|
2485
|
-
mergeDeep as a6,
|
|
2486
|
-
trans as a7,
|
|
2487
|
-
useUITheme as a8,
|
|
2488
|
-
prepareAlpineDefer as a9,
|
|
2489
|
-
isError as aA,
|
|
2490
|
-
nextTick as aB,
|
|
2491
|
-
parseQuery as aC,
|
|
2492
|
-
pushUnicornToGlobal as aD,
|
|
2493
|
-
randomBytes as aE,
|
|
2494
|
-
randomBytesString as aF,
|
|
2495
|
-
removeBoundedInstance as aG,
|
|
2496
|
-
removeData as aH,
|
|
2497
|
-
useAlertAdapter as aI,
|
|
2498
|
-
useBsModalAlert as aJ,
|
|
2499
|
-
useCssIncludes as aK,
|
|
2500
|
-
useFieldCascadeSelect as aL,
|
|
2501
|
-
useFieldFileDrag as aM,
|
|
2502
|
-
useFieldFlatpickr as aN,
|
|
2503
|
-
useFieldModalSelect as aO,
|
|
2504
|
-
useFieldModalTree as aP,
|
|
2505
|
-
useFieldRepeatable as aQ,
|
|
2506
|
-
useFieldSingleImageDrag as aR,
|
|
2507
|
-
useFormComponent as aS,
|
|
2508
|
-
useFormSubmit as aT,
|
|
2509
|
-
useGridComponent as aU,
|
|
2510
|
-
useIframeModal as aV,
|
|
2511
|
-
useInject as aW,
|
|
2512
|
-
useLang as aX,
|
|
2513
|
-
useLegacy as aY,
|
|
2514
|
-
useListDependent as aZ,
|
|
2515
|
-
useMacro as a_,
|
|
2516
|
-
watchAttributes as aa,
|
|
2517
|
-
injectCssToDocument as ab,
|
|
2518
|
-
useImport as ac,
|
|
2519
|
-
useCssImport as ad,
|
|
2520
|
-
data as ae,
|
|
2521
|
-
forceArray as af,
|
|
2522
|
-
deleteConfirm as ag,
|
|
2523
|
-
Mixin as ah,
|
|
2524
|
-
EventMixin as ai,
|
|
2525
|
-
createQueue as aj,
|
|
2526
|
-
useScriptImport as ak,
|
|
2527
|
-
sleep as al,
|
|
2528
|
-
AttributeMutationObserver as am,
|
|
2529
|
-
UnicornAssetUri as an,
|
|
2530
|
-
UnicornPhpAdapter as ao,
|
|
2531
|
-
UnicornSystemUri as ap,
|
|
2532
|
-
UnicornUI as aq,
|
|
2533
|
-
addQuery as ar,
|
|
2534
|
-
addRoute as as,
|
|
2535
|
-
addUriBase as at,
|
|
2536
|
-
buildQuery as au,
|
|
2537
|
-
createStack as av,
|
|
2538
|
-
createUnicorn as aw,
|
|
2539
|
-
createUnicornWithPlugins as ax,
|
|
2540
|
-
doImport as ay,
|
|
2541
|
-
hasRoute as az,
|
|
2542
|
-
animateTo as b,
|
|
2543
|
-
useS3Uploader as b0,
|
|
2544
|
-
useSeriesImport as b1,
|
|
2545
|
-
useShowOn as b2,
|
|
2546
|
-
useTinymce as b3,
|
|
2547
|
-
useTinymceHook as b4,
|
|
2548
|
-
useUI as b5,
|
|
2549
|
-
useUIBootstrap5 as b6,
|
|
2550
|
-
useUnicorn as b7,
|
|
2551
|
-
useUnicornPhpAdapter as b8,
|
|
2552
|
-
useVueComponentField as b9,
|
|
2553
|
-
useWebDirective as ba,
|
|
2554
|
-
wait as bb,
|
|
2555
|
-
renderMessage as c,
|
|
2556
|
-
clearMessages as d,
|
|
2557
|
-
clearNotifies as e,
|
|
2558
|
-
initAlpineComponent as f,
|
|
2559
|
-
useFormValidation as g,
|
|
2560
|
-
addGlobalValidator as h,
|
|
2561
|
-
isDebug as i,
|
|
2562
|
-
useFieldValidationInstance as j,
|
|
2563
|
-
useFormValidationInstance as k,
|
|
2564
|
-
loadAlpine as l,
|
|
2565
|
-
useStack as m,
|
|
2566
|
-
useQueue as n,
|
|
2567
|
-
useSystemUri as o,
|
|
2568
|
-
prepareAlpine as p,
|
|
2569
|
-
useAssetUri as q,
|
|
2570
|
-
route as r,
|
|
2571
|
-
simpleNotify as s,
|
|
2572
|
-
domready as t,
|
|
2573
|
-
useHttpClient as u,
|
|
2574
|
-
selectOne as v,
|
|
2575
|
-
selectAll as w,
|
|
2576
|
-
getBoundedInstance as x,
|
|
2577
|
-
getBoundedInstanceList as y,
|
|
2578
|
-
module$1 as z
|
|
2579
|
-
};
|
|
2580
|
-
//# sourceMappingURL=unicorn.js.map
|