@kdesigner/core 0.0.0-alpha.1

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/index.js ADDED
@@ -0,0 +1,2281 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
+ import { isArray, isBoolean, isInteger, isNumber, isObject, isPlainObject, isPromise, isString, parseUrlParams } from "@kdesigner/shared";
3
+ import { match } from "path-to-regexp";
4
+ import qs from "qs";
5
+ import { ref, shallowRef, toRaw } from "vue";
6
+ import { cloneDeep, omit } from "lodash-es";
7
+ import LRUCache from "lru-cache";
8
+ import axios from "axios";
9
+ //#region src/adapter/link.ts
10
+ function default_jumpTo(router, to) {
11
+ if (to.startsWith("open://")) {
12
+ openWindow(to.substring(7));
13
+ return;
14
+ }
15
+ if (to == "__forward") {
16
+ router.forward();
17
+ return;
18
+ }
19
+ if (to == "__back") {
20
+ router.back();
21
+ return;
22
+ }
23
+ function go(to, replace) {
24
+ if (replace) router.push(to);
25
+ else router.replace(to);
26
+ }
27
+ const replace = to.startsWith("replace://");
28
+ if (replace) to = to.substring(10);
29
+ if (isPageUrl(to)) {
30
+ const pos = to.indexOf("?");
31
+ const query = pos > 0 ? to.substring(pos + 1) : null;
32
+ const data = query ? parseUrlParams(query) : null;
33
+ go({
34
+ name: "jsonPage",
35
+ params: {
36
+ path: to,
37
+ data
38
+ }
39
+ }, replace);
40
+ } else go(to, replace);
41
+ }
42
+ function openWindow(url, opt) {
43
+ const { target = "__blank", noopener = true, noreferrer = true } = opt || {};
44
+ const feature = [];
45
+ if (noopener) feature.push("noopener=yes");
46
+ if (noreferrer) feature.push("noreferrer=yes");
47
+ window.open(url, target, feature.join(","));
48
+ }
49
+ function isPageUrl(url) {
50
+ const pos = url.indexOf("?");
51
+ if (pos > 0) url = url.substring(0, pos);
52
+ return url.endsWith(".page.json5") || url.endsWith(".page.yaml") || url.endsWith(".page.json");
53
+ }
54
+ function normalizeLink(to) {
55
+ if (to.startsWith("/api/")) return to;
56
+ to = to || "";
57
+ const location = window.location;
58
+ if (to && to[0] === "#") to = location.pathname + location.search + to;
59
+ else if (to && to[0] === "?") to = location.pathname + to;
60
+ const idx = to.indexOf("?");
61
+ const idx2 = to.indexOf("#");
62
+ let pathname = ~idx ? to.substring(0, idx) : ~idx2 ? to.substring(0, idx2) : to;
63
+ const search = ~idx ? to.substring(idx, ~idx2 ? idx2 : void 0) : "";
64
+ const hash = ~idx2 ? to.substring(idx2) : "";
65
+ if (!pathname) pathname = location.pathname;
66
+ else if (pathname[0] != "/" && !/^https?:\/\//.test(pathname)) {
67
+ const paths = location.pathname.split("/");
68
+ paths.pop();
69
+ let m;
70
+ while (m = /^\.\.?\//.exec(pathname)) {
71
+ if (m[0] === "../") paths.pop();
72
+ pathname = pathname.substring(m[0].length);
73
+ }
74
+ pathname = paths.concat(pathname).join("/");
75
+ }
76
+ return pathname + search + hash;
77
+ }
78
+ function default_updateLocation(to, replace) {
79
+ if (to === "goBack") return window.history.back();
80
+ if (replace && window.history.replaceState) {
81
+ window.history.replaceState("", document.title, to);
82
+ return;
83
+ }
84
+ location.href = normalizeLink(to);
85
+ }
86
+ function default_isCurrentUrl(to, ctx) {
87
+ const link = normalizeLink(to);
88
+ const location = window.location;
89
+ let pathname = link;
90
+ let search = "";
91
+ const idx = link.indexOf("?");
92
+ if (~idx) {
93
+ pathname = link.substring(0, idx);
94
+ search = link.substring(idx);
95
+ }
96
+ if (search) {
97
+ if (pathname !== location.pathname || !location.search) return false;
98
+ const query = qs.parse(search.substring(1));
99
+ const currentQuery = qs.parse(location.search.substring(1));
100
+ return Object.keys(query).every((key) => query[key] === currentQuery[key]);
101
+ } else if (pathname === location.pathname) return true;
102
+ else if (!~pathname.indexOf("http") && ~pathname.indexOf(":")) return match(link, {
103
+ decode: decodeURIComponent,
104
+ strict: ctx?.strict ?? true
105
+ })(location.pathname);
106
+ return false;
107
+ }
108
+ //#endregion
109
+ //#region src/adapter/index.ts
110
+ /**
111
+ * nop-chaos对外部框架的依赖都集中在adapter对象中
112
+ */
113
+ const adapter = {
114
+ globalVersion: "v3",
115
+ configUpgrade(_configName, _version, _prevVersion, _config) {},
116
+ /**
117
+ * 返回当前的locale
118
+ */
119
+ useLocale() {
120
+ throw new Error("not-impl");
121
+ },
122
+ useI18n() {
123
+ throw new Error("not-impl");
124
+ },
125
+ usePinia() {
126
+ throw new Error("not-impl");
127
+ },
128
+ /**
129
+ * 返回指定的Store
130
+ */
131
+ useStore(_name) {
132
+ throw new Error("not-impl");
133
+ },
134
+ useRouter() {
135
+ throw new Error("not-impl");
136
+ },
137
+ useSettings() {
138
+ return { apiUrl: "" };
139
+ },
140
+ /**
141
+ * 返回当前的认证token
142
+ */
143
+ useAuthToken() {
144
+ throw new Error("not-impl");
145
+ },
146
+ setAuthToken(_token) {},
147
+ isUserInRole(_role) {
148
+ throw new Error("not-impl");
149
+ },
150
+ useTenantId() {
151
+ throw new Error("not-impl");
152
+ },
153
+ useAppId() {
154
+ return "nop-chaos";
155
+ },
156
+ /**
157
+ * 自动退出时执行的回调
158
+ */
159
+ logout(_reason) {
160
+ throw new Error("not-impl");
161
+ },
162
+ /**
163
+ * 根据组件名加载Vue组件
164
+ */
165
+ resolveVueComponent(_name) {
166
+ throw new Error("not-impl");
167
+ },
168
+ processRequest(request) {
169
+ return request;
170
+ },
171
+ processResponse(response) {
172
+ return response;
173
+ },
174
+ compileFunction(code, page) {
175
+ return new Function("page", "return " + code).call(null, page);
176
+ },
177
+ jumpTo(to, _action, _ctx) {
178
+ return default_jumpTo(adapter.useRouter(), to);
179
+ },
180
+ isCurrentUrl: default_isCurrentUrl,
181
+ updateLocation: default_updateLocation,
182
+ notify(_type, _msg, _conf) {
183
+ throw new Error("not-impl");
184
+ },
185
+ alert(_msg, _title) {
186
+ throw new Error("not-impl");
187
+ },
188
+ confirm(_msg, _title) {
189
+ throw new Error("not-impl");
190
+ },
191
+ dataMapping(_to, _from = {}, _ignoreFunction = false, _convertKeyToPath, _ignoreIfNotMatch = false) {
192
+ throw new Error("not-impl");
193
+ },
194
+ fetchDict(_dictName, _options) {
195
+ throw new Error("not-impl");
196
+ },
197
+ fetchPageAndTransform(_pageName, _options) {
198
+ throw new Error("not-impl");
199
+ },
200
+ getPage(_pageUrl) {
201
+ throw new Error("not-impl");
202
+ }
203
+ };
204
+ function registerAdapter(data) {
205
+ Object.assign(adapter, data);
206
+ }
207
+ function useAdapter() {
208
+ return adapter;
209
+ }
210
+ //#endregion
211
+ //#region ../../node_modules/.pnpm/systemjs@6.15.1/node_modules/systemjs/dist/system.js
212
+ /*!
213
+ * SystemJS 6.15.1
214
+ */
215
+ (function() {
216
+ function errMsg(errCode, msg) {
217
+ return (msg || "") + " (SystemJS Error#" + errCode + " https://github.com/systemjs/systemjs/blob/main/docs/errors.md#" + errCode + ")";
218
+ }
219
+ var hasSymbol = typeof Symbol !== "undefined";
220
+ var hasSelf = typeof self !== "undefined";
221
+ var hasDocument = typeof document !== "undefined";
222
+ var envGlobal = hasSelf ? self : global;
223
+ var baseUrl;
224
+ if (hasDocument) {
225
+ var baseEl = document.querySelector("base[href]");
226
+ if (baseEl) baseUrl = baseEl.href;
227
+ }
228
+ if (!baseUrl && typeof location !== "undefined") {
229
+ baseUrl = location.href.split("#")[0].split("?")[0];
230
+ var lastSepIndex = baseUrl.lastIndexOf("/");
231
+ if (lastSepIndex !== -1) baseUrl = baseUrl.slice(0, lastSepIndex + 1);
232
+ }
233
+ var backslashRegEx = /\\/g;
234
+ function resolveIfNotPlainOrUrl(relUrl, parentUrl) {
235
+ if (relUrl.indexOf("\\") !== -1) relUrl = relUrl.replace(backslashRegEx, "/");
236
+ if (relUrl[0] === "/" && relUrl[1] === "/") return parentUrl.slice(0, parentUrl.indexOf(":") + 1) + relUrl;
237
+ else if (relUrl[0] === "." && (relUrl[1] === "/" || relUrl[1] === "." && (relUrl[2] === "/" || relUrl.length === 2 && (relUrl += "/")) || relUrl.length === 1 && (relUrl += "/")) || relUrl[0] === "/") {
238
+ var parentProtocol = parentUrl.slice(0, parentUrl.indexOf(":") + 1);
239
+ var pathname;
240
+ if (parentUrl[parentProtocol.length + 1] === "/") if (parentProtocol !== "file:") {
241
+ pathname = parentUrl.slice(parentProtocol.length + 2);
242
+ pathname = pathname.slice(pathname.indexOf("/") + 1);
243
+ } else pathname = parentUrl.slice(8);
244
+ else pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === "/"));
245
+ if (relUrl[0] === "/") return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
246
+ var segmented = pathname.slice(0, pathname.lastIndexOf("/") + 1) + relUrl;
247
+ var output = [];
248
+ var segmentIndex = -1;
249
+ for (var i = 0; i < segmented.length; i++) if (segmentIndex !== -1) {
250
+ if (segmented[i] === "/") {
251
+ output.push(segmented.slice(segmentIndex, i + 1));
252
+ segmentIndex = -1;
253
+ }
254
+ } else if (segmented[i] === ".") if (segmented[i + 1] === "." && (segmented[i + 2] === "/" || i + 2 === segmented.length)) {
255
+ output.pop();
256
+ i += 2;
257
+ } else if (segmented[i + 1] === "/" || i + 1 === segmented.length) i += 1;
258
+ else segmentIndex = i;
259
+ else segmentIndex = i;
260
+ if (segmentIndex !== -1) output.push(segmented.slice(segmentIndex));
261
+ return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join("");
262
+ }
263
+ }
264
+ function resolveUrl(relUrl, parentUrl) {
265
+ return resolveIfNotPlainOrUrl(relUrl, parentUrl) || (relUrl.indexOf(":") !== -1 ? relUrl : resolveIfNotPlainOrUrl("./" + relUrl, parentUrl));
266
+ }
267
+ function resolveAndComposePackages(packages, outPackages, baseUrl, parentMap, parentUrl) {
268
+ for (var p in packages) {
269
+ var resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
270
+ var rhs = packages[p];
271
+ if (typeof rhs !== "string") continue;
272
+ var mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(rhs, baseUrl) || rhs, parentUrl);
273
+ if (!mapped) targetWarning("W1", p, rhs, "bare specifier did not resolve");
274
+ else outPackages[resolvedLhs] = mapped;
275
+ }
276
+ }
277
+ function resolveAndComposeImportMap(json, baseUrl, outMap) {
278
+ if (json.imports) resolveAndComposePackages(json.imports, outMap.imports, baseUrl, outMap, null);
279
+ var u;
280
+ for (u in json.scopes || {}) {
281
+ var resolvedScope = resolveUrl(u, baseUrl);
282
+ resolveAndComposePackages(json.scopes[u], outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}), baseUrl, outMap, resolvedScope);
283
+ }
284
+ for (u in json.depcache || {}) outMap.depcache[resolveUrl(u, baseUrl)] = json.depcache[u];
285
+ for (u in json.integrity || {}) outMap.integrity[resolveUrl(u, baseUrl)] = json.integrity[u];
286
+ }
287
+ function getMatch(path, matchObj) {
288
+ if (matchObj[path]) return path;
289
+ var sepIndex = path.length;
290
+ do {
291
+ var segment = path.slice(0, sepIndex + 1);
292
+ if (segment in matchObj) return segment;
293
+ } while ((sepIndex = path.lastIndexOf("/", sepIndex - 1)) !== -1);
294
+ }
295
+ function applyPackages(id, packages) {
296
+ var pkgName = getMatch(id, packages);
297
+ if (pkgName) {
298
+ var pkg = packages[pkgName];
299
+ if (pkg === null) return;
300
+ if (id.length > pkgName.length && pkg[pkg.length - 1] !== "/") targetWarning("W2", pkgName, pkg, "should have a trailing '/'");
301
+ else return pkg + id.slice(pkgName.length);
302
+ }
303
+ }
304
+ function targetWarning(code, match, target, msg) {
305
+ console.warn(errMsg(code, "Package target " + msg + ", resolving target '" + target + "' for " + match));
306
+ }
307
+ function resolveImportMap(importMap, resolvedOrPlain, parentUrl) {
308
+ var scopes = importMap.scopes;
309
+ var scopeUrl = parentUrl && getMatch(parentUrl, scopes);
310
+ while (scopeUrl) {
311
+ var packageResolution = applyPackages(resolvedOrPlain, scopes[scopeUrl]);
312
+ if (packageResolution) return packageResolution;
313
+ scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf("/")), scopes);
314
+ }
315
+ return applyPackages(resolvedOrPlain, importMap.imports) || resolvedOrPlain.indexOf(":") !== -1 && resolvedOrPlain;
316
+ }
317
+ var toStringTag$1 = hasSymbol && Symbol.toStringTag;
318
+ var REGISTRY = hasSymbol ? Symbol() : "@";
319
+ function SystemJS() {
320
+ this[REGISTRY] = {};
321
+ }
322
+ var systemJSPrototype = SystemJS.prototype;
323
+ systemJSPrototype.import = function(id, parentUrl, meta) {
324
+ var loader = this;
325
+ parentUrl && typeof parentUrl === "object" && (meta = parentUrl, parentUrl = void 0);
326
+ return Promise.resolve(loader.prepareImport()).then(function() {
327
+ return loader.resolve(id, parentUrl, meta);
328
+ }).then(function(id) {
329
+ var load = getOrCreateLoad(loader, id, void 0, meta);
330
+ return load.C || topLevelLoad(loader, load);
331
+ });
332
+ };
333
+ systemJSPrototype.createContext = function(parentId) {
334
+ var loader = this;
335
+ return {
336
+ url: parentId,
337
+ resolve: function(id, parentUrl) {
338
+ return Promise.resolve(loader.resolve(id, parentUrl || parentId));
339
+ }
340
+ };
341
+ };
342
+ systemJSPrototype.onload = function() {};
343
+ function loadToId(load) {
344
+ return load.id;
345
+ }
346
+ function triggerOnload(loader, load, err, isErrSource) {
347
+ loader.onload(err, load.id, load.d && load.d.map(loadToId), !!isErrSource);
348
+ if (err) throw err;
349
+ }
350
+ var lastRegister;
351
+ systemJSPrototype.register = function(deps, declare, metas) {
352
+ lastRegister = [
353
+ deps,
354
+ declare,
355
+ metas
356
+ ];
357
+ };
358
+ systemJSPrototype.getRegister = function() {
359
+ var _lastRegister = lastRegister;
360
+ lastRegister = void 0;
361
+ return _lastRegister;
362
+ };
363
+ function getOrCreateLoad(loader, id, firstParentUrl, meta) {
364
+ var load = loader[REGISTRY][id];
365
+ if (load) return load;
366
+ var importerSetters = [];
367
+ var ns = Object.create(null);
368
+ if (toStringTag$1) Object.defineProperty(ns, toStringTag$1, { value: "Module" });
369
+ var instantiatePromise = Promise.resolve().then(function() {
370
+ return loader.instantiate(id, firstParentUrl, meta);
371
+ }).then(function(registration) {
372
+ if (!registration) throw Error(errMsg(2, "Module " + id + " did not instantiate"));
373
+ function _export(name, value) {
374
+ load.h = true;
375
+ var changed = false;
376
+ if (typeof name === "string") {
377
+ if (!(name in ns) || ns[name] !== value) {
378
+ ns[name] = value;
379
+ changed = true;
380
+ }
381
+ } else {
382
+ for (var p in name) {
383
+ var value = name[p];
384
+ if (!(p in ns) || ns[p] !== value) {
385
+ ns[p] = value;
386
+ changed = true;
387
+ }
388
+ }
389
+ if (name && name.__esModule) ns.__esModule = name.__esModule;
390
+ }
391
+ if (changed) for (var i = 0; i < importerSetters.length; i++) {
392
+ var setter = importerSetters[i];
393
+ if (setter) setter(ns);
394
+ }
395
+ return value;
396
+ }
397
+ var declared = registration[1](_export, registration[1].length === 2 ? {
398
+ import: function(importId, meta) {
399
+ return loader.import(importId, id, meta);
400
+ },
401
+ meta: loader.createContext(id)
402
+ } : void 0);
403
+ load.e = declared.execute || function() {};
404
+ return [
405
+ registration[0],
406
+ declared.setters || [],
407
+ registration[2] || []
408
+ ];
409
+ }, function(err) {
410
+ load.e = null;
411
+ load.er = err;
412
+ triggerOnload(loader, load, err, true);
413
+ throw err;
414
+ });
415
+ var linkPromise = instantiatePromise.then(function(instantiation) {
416
+ return Promise.all(instantiation[0].map(function(dep, i) {
417
+ var setter = instantiation[1][i];
418
+ var meta = instantiation[2][i];
419
+ return Promise.resolve(loader.resolve(dep, id)).then(function(depId) {
420
+ var depLoad = getOrCreateLoad(loader, depId, id, meta);
421
+ return Promise.resolve(depLoad.I).then(function() {
422
+ if (setter) {
423
+ depLoad.i.push(setter);
424
+ if (depLoad.h || !depLoad.I) setter(depLoad.n);
425
+ }
426
+ return depLoad;
427
+ });
428
+ });
429
+ })).then(function(depLoads) {
430
+ load.d = depLoads;
431
+ });
432
+ });
433
+ return load = loader[REGISTRY][id] = {
434
+ id,
435
+ i: importerSetters,
436
+ n: ns,
437
+ m: meta,
438
+ I: instantiatePromise,
439
+ L: linkPromise,
440
+ h: false,
441
+ d: void 0,
442
+ e: void 0,
443
+ er: void 0,
444
+ E: void 0,
445
+ C: void 0,
446
+ p: void 0
447
+ };
448
+ }
449
+ function instantiateAll(loader, load, parent, loaded) {
450
+ if (!loaded[load.id]) {
451
+ loaded[load.id] = true;
452
+ return Promise.resolve(load.L).then(function() {
453
+ if (!load.p || load.p.e === null) load.p = parent;
454
+ return Promise.all(load.d.map(function(dep) {
455
+ return instantiateAll(loader, dep, parent, loaded);
456
+ }));
457
+ }).catch(function(err) {
458
+ if (load.er) throw err;
459
+ load.e = null;
460
+ triggerOnload(loader, load, err, false);
461
+ throw err;
462
+ });
463
+ }
464
+ }
465
+ function topLevelLoad(loader, load) {
466
+ return load.C = instantiateAll(loader, load, load, {}).then(function() {
467
+ return postOrderExec(loader, load, {});
468
+ }).then(function() {
469
+ return load.n;
470
+ });
471
+ }
472
+ var nullContext = Object.freeze(Object.create(null));
473
+ function postOrderExec(loader, load, seen) {
474
+ if (seen[load.id]) return;
475
+ seen[load.id] = true;
476
+ if (!load.e) {
477
+ if (load.er) throw load.er;
478
+ if (load.E) return load.E;
479
+ return;
480
+ }
481
+ var exec = load.e;
482
+ load.e = null;
483
+ var depLoadPromises;
484
+ load.d.forEach(function(depLoad) {
485
+ try {
486
+ var depLoadPromise = postOrderExec(loader, depLoad, seen);
487
+ if (depLoadPromise) (depLoadPromises = depLoadPromises || []).push(depLoadPromise);
488
+ } catch (err) {
489
+ load.er = err;
490
+ triggerOnload(loader, load, err, false);
491
+ throw err;
492
+ }
493
+ });
494
+ if (depLoadPromises) return Promise.all(depLoadPromises).then(doExec);
495
+ return doExec();
496
+ function doExec() {
497
+ try {
498
+ var execPromise = exec.call(nullContext);
499
+ if (execPromise) {
500
+ execPromise = execPromise.then(function() {
501
+ load.C = load.n;
502
+ load.E = null;
503
+ triggerOnload(loader, load, null, true);
504
+ }, function(err) {
505
+ load.er = err;
506
+ load.E = null;
507
+ triggerOnload(loader, load, err, true);
508
+ throw err;
509
+ });
510
+ return load.E = execPromise;
511
+ }
512
+ load.C = load.n;
513
+ load.L = load.I = void 0;
514
+ } catch (err) {
515
+ load.er = err;
516
+ throw err;
517
+ } finally {
518
+ triggerOnload(loader, load, load.er, true);
519
+ }
520
+ }
521
+ }
522
+ envGlobal.System = new SystemJS();
523
+ var importMapPromise = Promise.resolve();
524
+ var importMap = {
525
+ imports: {},
526
+ scopes: {},
527
+ depcache: {},
528
+ integrity: {}
529
+ };
530
+ var processFirst = hasDocument;
531
+ systemJSPrototype.prepareImport = function(doProcessScripts) {
532
+ if (processFirst || doProcessScripts) {
533
+ processScripts();
534
+ processFirst = false;
535
+ }
536
+ return importMapPromise;
537
+ };
538
+ systemJSPrototype.getImportMap = function() {
539
+ return JSON.parse(JSON.stringify(importMap));
540
+ };
541
+ if (hasDocument) {
542
+ processScripts();
543
+ window.addEventListener("DOMContentLoaded", processScripts);
544
+ }
545
+ systemJSPrototype.addImportMap = function(newMap, mapBase) {
546
+ resolveAndComposeImportMap(newMap, mapBase || baseUrl, importMap);
547
+ };
548
+ function processScripts() {
549
+ [].forEach.call(document.querySelectorAll("script"), function(script) {
550
+ if (script.sp) return;
551
+ if (script.type === "systemjs-module") {
552
+ script.sp = true;
553
+ if (!script.src) return;
554
+ System.import(script.src.slice(0, 7) === "import:" ? script.src.slice(7) : resolveUrl(script.src, baseUrl)).catch(function(e) {
555
+ if (e.message.indexOf("https://github.com/systemjs/systemjs/blob/main/docs/errors.md#3") > -1) {
556
+ var event = document.createEvent("Event");
557
+ event.initEvent("error", false, false);
558
+ script.dispatchEvent(event);
559
+ }
560
+ return Promise.reject(e);
561
+ });
562
+ } else if (script.type === "systemjs-importmap") {
563
+ script.sp = true;
564
+ var fetchPromise = script.src ? (System.fetch || fetch)(script.src, {
565
+ integrity: script.integrity,
566
+ priority: script.fetchPriority,
567
+ passThrough: true
568
+ }).then(function(res) {
569
+ if (!res.ok) throw Error("Invalid status code: " + res.status);
570
+ return res.text();
571
+ }).catch(function(err) {
572
+ err.message = errMsg("W4", "Error fetching systemjs-import map " + script.src) + "\n" + err.message;
573
+ console.warn(err);
574
+ if (typeof script.onerror === "function") script.onerror();
575
+ return "{}";
576
+ }) : script.innerHTML;
577
+ importMapPromise = importMapPromise.then(function() {
578
+ return fetchPromise;
579
+ }).then(function(text) {
580
+ extendImportMap(importMap, text, script.src || baseUrl);
581
+ });
582
+ }
583
+ });
584
+ }
585
+ function extendImportMap(importMap, newMapText, newMapUrl) {
586
+ var newMap = {};
587
+ try {
588
+ newMap = JSON.parse(newMapText);
589
+ } catch (err) {
590
+ console.warn(Error(errMsg("W5", "systemjs-importmap contains invalid JSON") + "\n\n" + newMapText + "\n"));
591
+ }
592
+ resolveAndComposeImportMap(newMap, newMapUrl, importMap);
593
+ }
594
+ if (hasDocument) {
595
+ window.addEventListener("error", function(evt) {
596
+ lastWindowErrorUrl = evt.filename;
597
+ lastWindowError = evt.error;
598
+ });
599
+ var baseOrigin = location.origin;
600
+ }
601
+ systemJSPrototype.createScript = function(url) {
602
+ var script = document.createElement("script");
603
+ script.async = true;
604
+ if (url.indexOf(baseOrigin + "/")) script.crossOrigin = "anonymous";
605
+ var integrity = importMap.integrity[url];
606
+ if (integrity) script.integrity = integrity;
607
+ script.src = url;
608
+ return script;
609
+ };
610
+ var lastAutoImportDeps, lastAutoImportTimeout;
611
+ var autoImportCandidates = {};
612
+ var systemRegister = systemJSPrototype.register;
613
+ systemJSPrototype.register = function(deps, declare) {
614
+ if (hasDocument && document.readyState === "loading" && typeof deps !== "string") {
615
+ var scripts = document.querySelectorAll("script[src]");
616
+ var lastScript = scripts[scripts.length - 1];
617
+ if (lastScript) {
618
+ lastScript.src;
619
+ lastAutoImportDeps = deps;
620
+ var loader = this;
621
+ lastAutoImportTimeout = setTimeout(function() {
622
+ autoImportCandidates[lastScript.src] = [deps, declare];
623
+ loader.import(lastScript.src);
624
+ });
625
+ }
626
+ } else lastAutoImportDeps = void 0;
627
+ return systemRegister.call(this, deps, declare);
628
+ };
629
+ var lastWindowErrorUrl, lastWindowError;
630
+ systemJSPrototype.instantiate = function(url, firstParentUrl) {
631
+ var autoImportRegistration = autoImportCandidates[url];
632
+ if (autoImportRegistration) {
633
+ delete autoImportCandidates[url];
634
+ return autoImportRegistration;
635
+ }
636
+ var loader = this;
637
+ return Promise.resolve(systemJSPrototype.createScript(url)).then(function(script) {
638
+ return new Promise(function(resolve, reject) {
639
+ script.addEventListener("error", function() {
640
+ reject(Error(errMsg(3, "Error loading " + url + (firstParentUrl ? " from " + firstParentUrl : ""))));
641
+ });
642
+ script.addEventListener("load", function() {
643
+ document.head.removeChild(script);
644
+ if (lastWindowErrorUrl === url) reject(lastWindowError);
645
+ else {
646
+ var register = loader.getRegister(url);
647
+ if (register && register[0] === lastAutoImportDeps) clearTimeout(lastAutoImportTimeout);
648
+ resolve(register);
649
+ }
650
+ });
651
+ document.head.appendChild(script);
652
+ });
653
+ });
654
+ };
655
+ systemJSPrototype.shouldFetch = function() {
656
+ return false;
657
+ };
658
+ if (typeof fetch !== "undefined") systemJSPrototype.fetch = fetch;
659
+ var instantiate = systemJSPrototype.instantiate;
660
+ var jsContentTypeRegEx = /^(text|application)\/(x-)?javascript(;|$)/;
661
+ systemJSPrototype.instantiate = function(url, parent, meta) {
662
+ var loader = this;
663
+ if (!this.shouldFetch(url, parent, meta)) return instantiate.apply(this, arguments);
664
+ return this.fetch(url, {
665
+ credentials: "same-origin",
666
+ integrity: importMap.integrity[url],
667
+ meta
668
+ }).then(function(res) {
669
+ if (!res.ok) throw Error(errMsg(7, res.status + " " + res.statusText + ", loading " + url + (parent ? " from " + parent : "")));
670
+ var contentType = res.headers.get("content-type");
671
+ if (!contentType || !jsContentTypeRegEx.test(contentType)) throw Error(errMsg(4, "Unknown Content-Type \"" + contentType + "\", loading " + url + (parent ? " from " + parent : "")));
672
+ return res.text().then(function(source) {
673
+ if (source.indexOf("//# sourceURL=") < 0) source += "\n//# sourceURL=" + url;
674
+ (0, eval)(source);
675
+ return loader.getRegister(url);
676
+ });
677
+ });
678
+ };
679
+ systemJSPrototype.resolve = function(id, parentUrl) {
680
+ parentUrl = parentUrl || baseUrl;
681
+ return resolveImportMap(importMap, resolveIfNotPlainOrUrl(id, parentUrl) || id, parentUrl) || throwUnresolved(id, parentUrl);
682
+ };
683
+ function throwUnresolved(id, parentUrl) {
684
+ throw Error(errMsg(8, "Unable to resolve bare specifier '" + id + (parentUrl ? "' from " + parentUrl : "'")));
685
+ }
686
+ var systemInstantiate = systemJSPrototype.instantiate;
687
+ systemJSPrototype.instantiate = function(url, firstParentUrl, meta) {
688
+ var preloads = importMap.depcache[url];
689
+ if (preloads) for (var i = 0; i < preloads.length; i++) getOrCreateLoad(this, this.resolve(preloads[i], url), url);
690
+ return systemInstantiate.call(this, url, firstParentUrl, meta);
691
+ };
692
+ if (hasSelf && typeof importScripts === "function") systemJSPrototype.instantiate = function(url) {
693
+ var loader = this;
694
+ return Promise.resolve().then(function() {
695
+ importScripts(url);
696
+ return loader.getRegister(url);
697
+ });
698
+ };
699
+ (function(global) {
700
+ var systemJSPrototype = global.System.constructor.prototype;
701
+ var firstGlobalProp, secondGlobalProp, lastGlobalProp;
702
+ function getGlobalProp(useFirstGlobalProp) {
703
+ var cnt = 0;
704
+ var foundLastProp, result;
705
+ for (var p in global) {
706
+ if (shouldSkipProperty(p)) continue;
707
+ if (cnt === 0 && p !== firstGlobalProp || cnt === 1 && p !== secondGlobalProp) return p;
708
+ if (foundLastProp) {
709
+ lastGlobalProp = p;
710
+ result = useFirstGlobalProp && result || p;
711
+ } else foundLastProp = p === lastGlobalProp;
712
+ cnt++;
713
+ }
714
+ return result;
715
+ }
716
+ function noteGlobalProps() {
717
+ firstGlobalProp = secondGlobalProp = void 0;
718
+ for (var p in global) {
719
+ if (shouldSkipProperty(p)) continue;
720
+ if (!firstGlobalProp) firstGlobalProp = p;
721
+ else if (!secondGlobalProp) secondGlobalProp = p;
722
+ lastGlobalProp = p;
723
+ }
724
+ return lastGlobalProp;
725
+ }
726
+ var impt = systemJSPrototype.import;
727
+ systemJSPrototype.import = function(id, parentUrl, meta) {
728
+ noteGlobalProps();
729
+ return impt.call(this, id, parentUrl, meta);
730
+ };
731
+ var emptyInstantiation = [[], function() {
732
+ return {};
733
+ }];
734
+ var getRegister = systemJSPrototype.getRegister;
735
+ systemJSPrototype.getRegister = function() {
736
+ var lastRegister = getRegister.call(this);
737
+ if (lastRegister) return lastRegister;
738
+ var globalProp = getGlobalProp(this.firstGlobalProp);
739
+ if (!globalProp) return emptyInstantiation;
740
+ var globalExport;
741
+ try {
742
+ globalExport = global[globalProp];
743
+ } catch (e) {
744
+ return emptyInstantiation;
745
+ }
746
+ return [[], function(_export) {
747
+ return { execute: function() {
748
+ _export(globalExport);
749
+ _export({
750
+ default: globalExport,
751
+ __useDefault: true
752
+ });
753
+ } };
754
+ }];
755
+ };
756
+ var isIE11 = typeof navigator !== "undefined" && navigator.userAgent.indexOf("Trident") !== -1;
757
+ function shouldSkipProperty(p) {
758
+ return !global.hasOwnProperty(p) || !isNaN(p) && p < global.length || isIE11 && global[p] && typeof window !== "undefined" && global[p].parent === window;
759
+ }
760
+ })(typeof self !== "undefined" ? self : global);
761
+ (function(global) {
762
+ var systemJSPrototype = global.System.constructor.prototype;
763
+ var moduleTypesRegEx = /^[^#?]+\.(css|html|json|wasm)([?#].*)?$/;
764
+ var _shouldFetch = systemJSPrototype.shouldFetch.bind(systemJSPrototype);
765
+ systemJSPrototype.shouldFetch = function(url) {
766
+ return _shouldFetch(url) || moduleTypesRegEx.test(url);
767
+ };
768
+ var jsonContentType = /^application\/json(;|$)/;
769
+ var cssContentType = /^text\/css(;|$)/;
770
+ var wasmContentType = /^application\/wasm(;|$)/;
771
+ var fetch = systemJSPrototype.fetch;
772
+ systemJSPrototype.fetch = function(url, options) {
773
+ return fetch(url, options).then(function(res) {
774
+ if (options.passThrough) return res;
775
+ if (!res.ok) return res;
776
+ var contentType = res.headers.get("content-type");
777
+ if (jsonContentType.test(contentType)) return res.json().then(function(json) {
778
+ return new Response(new Blob(["System.register([],function(e){return{execute:function(){e(\"default\"," + JSON.stringify(json) + ")}}})"], { type: "application/javascript" }));
779
+ });
780
+ if (cssContentType.test(contentType)) return res.text().then(function(source) {
781
+ source = source.replace(/url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g, function(match, quotes, relUrl1, relUrl2) {
782
+ return [
783
+ "url(",
784
+ quotes,
785
+ resolveUrl(relUrl1 || relUrl2, url),
786
+ quotes,
787
+ ")"
788
+ ].join("");
789
+ });
790
+ return new Response(new Blob(["System.register([],function(e){return{execute:function(){var s=new CSSStyleSheet();s.replaceSync(" + JSON.stringify(source) + ");e(\"default\",s)}}})"], { type: "application/javascript" }));
791
+ });
792
+ if (wasmContentType.test(contentType)) return (WebAssembly.compileStreaming ? WebAssembly.compileStreaming(res) : res.arrayBuffer().then(WebAssembly.compile)).then(function(module) {
793
+ if (!global.System.wasmModules) global.System.wasmModules = Object.create(null);
794
+ global.System.wasmModules[url] = module;
795
+ var deps = [];
796
+ var setterSources = [];
797
+ if (WebAssembly.Module.imports) WebAssembly.Module.imports(module).forEach(function(impt) {
798
+ var key = JSON.stringify(impt.module);
799
+ if (deps.indexOf(key) === -1) {
800
+ deps.push(key);
801
+ setterSources.push("function(m){i[" + key + "]=m}");
802
+ }
803
+ });
804
+ return new Response(new Blob(["System.register([" + deps.join(",") + "],function(e){var i={};return{setters:[" + setterSources.join(",") + "],execute:function(){return WebAssembly.instantiate(System.wasmModules[" + JSON.stringify(url) + "],i).then(function(m){e(m.exports)})}}})"], { type: "application/javascript" }));
805
+ });
806
+ return res;
807
+ });
808
+ };
809
+ })(typeof self !== "undefined" ? self : global);
810
+ var toStringTag = typeof Symbol !== "undefined" && Symbol.toStringTag;
811
+ systemJSPrototype.get = function(id) {
812
+ var load = this[REGISTRY][id];
813
+ if (load && load.e === null && !load.E) {
814
+ if (load.er) return null;
815
+ return load.n;
816
+ }
817
+ };
818
+ systemJSPrototype.set = function(id, module) {
819
+ try {
820
+ new URL(id);
821
+ } catch (err) {
822
+ console.warn(Error(errMsg("W3", "\"" + id + "\" is not a valid URL to set in the module registry")));
823
+ }
824
+ var ns;
825
+ if (toStringTag && module[toStringTag] === "Module") ns = module;
826
+ else {
827
+ ns = Object.assign(Object.create(null), module);
828
+ if (toStringTag) Object.defineProperty(ns, toStringTag, { value: "Module" });
829
+ }
830
+ var done = Promise.resolve(ns);
831
+ var load = this[REGISTRY][id] || (this[REGISTRY][id] = {
832
+ id,
833
+ i: [],
834
+ h: false,
835
+ d: [],
836
+ e: null,
837
+ er: void 0,
838
+ E: void 0
839
+ });
840
+ if (load.e || load.E) return false;
841
+ Object.assign(load, {
842
+ n: ns,
843
+ I: void 0,
844
+ L: void 0,
845
+ C: done
846
+ });
847
+ return ns;
848
+ };
849
+ systemJSPrototype.has = function(id) {
850
+ return !!this[REGISTRY][id];
851
+ };
852
+ systemJSPrototype.delete = function(id) {
853
+ var registry = this[REGISTRY];
854
+ var load = registry[id];
855
+ if (!load || load.p && load.p.e !== null || load.E) return false;
856
+ var importerSetters = load.i;
857
+ if (load.d) load.d.forEach(function(depLoad) {
858
+ var importerIndex = depLoad.i.indexOf(load);
859
+ if (importerIndex !== -1) depLoad.i.splice(importerIndex, 1);
860
+ });
861
+ delete registry[id];
862
+ return function() {
863
+ var load = registry[id];
864
+ if (!load || !importerSetters || load.e !== null || load.E) return false;
865
+ importerSetters.forEach(function(setter) {
866
+ load.i.push(setter);
867
+ setter(load.n);
868
+ });
869
+ importerSetters = null;
870
+ };
871
+ };
872
+ var iterator = typeof Symbol !== "undefined" && Symbol.iterator;
873
+ systemJSPrototype.entries = function() {
874
+ var loader = this, keys = Object.keys(loader[REGISTRY]);
875
+ var index = 0, ns, key;
876
+ var result = { next: function() {
877
+ while ((key = keys[index++]) !== void 0 && (ns = loader.get(key)) === void 0);
878
+ return {
879
+ done: key === void 0,
880
+ value: key !== void 0 && [key, ns]
881
+ };
882
+ } };
883
+ result[iterator] = function() {
884
+ return this;
885
+ };
886
+ return result;
887
+ };
888
+ })();
889
+ //#endregion
890
+ //#region src/loader/module.ts
891
+ const System$1 = (typeof self !== "undefined" ? self : global).System;
892
+ /**
893
+ * 动态加载js文件
894
+ * @param path js文件路径
895
+ * @returns
896
+ */
897
+ function importModule(path) {
898
+ if (path.endsWith(".lib.js") && path.startsWith("/") && !path.startsWith("/p/")) path = "/p/SystemJsProvider__getJs?path=" + encodeURIComponent(path);
899
+ const url = System$1.resolve(path);
900
+ return System$1.import(
901
+ /* @vite-ignore*/
902
+ url
903
+ );
904
+ }
905
+ function deleteDynamicModules() {
906
+ for (const module of System$1.entries()) {
907
+ const moduleId = module[0];
908
+ if (moduleId.endsWith(".lib.js")) System$1.delete(moduleId);
909
+ }
910
+ }
911
+ function registerModule(name, lib) {
912
+ let libPath = name;
913
+ if (name.startsWith("./")) libPath = System$1.resolve(name);
914
+ else if (name.startsWith("@nop/")) libPath = System$1.resolve("./nop/" + name.substring(5) + ".js");
915
+ else {
916
+ libPath = System$1.resolve("./nop/" + name + ".js");
917
+ System$1.addImportMap({ imports: { [name]: libPath } });
918
+ }
919
+ System$1.set(libPath, lib);
920
+ }
921
+ function addSystemImportMap(imports) {
922
+ System$1.addImportMap({ imports });
923
+ }
924
+ //#endregion
925
+ //#region src/shared/constants.ts
926
+ var constants_exports = /* @__PURE__ */ __exportAll({
927
+ HEADER_ACCESS_TOKEN: () => HEADER_ACCESS_TOKEN,
928
+ HEADER_APP_ID: () => HEADER_APP_ID,
929
+ HEADER_TENANT_ID: () => HEADER_TENANT_ID,
930
+ HEADER_TIMESTAMP: () => HEADER_TIMESTAMP,
931
+ HEADER_VERSION: () => HEADER_VERSION
932
+ });
933
+ const HEADER_TENANT_ID = "x-tenant-id";
934
+ const HEADER_ACCESS_TOKEN = "x-access-token";
935
+ const HEADER_TIMESTAMP = "x-timestamp";
936
+ const HEADER_APP_ID = "nop-app-id";
937
+ const HEADER_VERSION = "x-version";
938
+ //#endregion
939
+ //#region src/shared/utils.ts
940
+ function normalizeArray(parts, allowAboveRoot) {
941
+ const res = [];
942
+ for (let i = 0; i < parts.length; i++) {
943
+ const p2 = parts[i];
944
+ if (!p2 || p2 === ".") continue;
945
+ if (p2 === "..") {
946
+ if (res.length && res[res.length - 1] !== "..") res.pop();
947
+ else if (allowAboveRoot) res.push("..");
948
+ } else res.push(p2);
949
+ }
950
+ return res;
951
+ }
952
+ function absolutePath(path, basePath) {
953
+ if (path.indexOf(":") > 0) return path;
954
+ let resolvedPath = path;
955
+ if (basePath && !resolvedPath.startsWith("/")) resolvedPath = basePath + "/../" + path;
956
+ resolvedPath = normalizeArray(resolvedPath.split("/"), false).join("/");
957
+ return "/" + resolvedPath;
958
+ }
959
+ function format(msg, placeholderStart, placeholdeEnd, resolver) {
960
+ let pos = msg.indexOf(placeholderStart);
961
+ if (pos < 0) return msg;
962
+ let ret = msg.substring(0, pos);
963
+ do {
964
+ pos += placeholderStart.length;
965
+ let pos2 = msg.indexOf(placeholdeEnd, pos);
966
+ if (pos2 < 0) {
967
+ ret += msg.substring(pos);
968
+ break;
969
+ } else {
970
+ const value = resolver(msg.substring(pos, pos2).trim());
971
+ if (value != null) ret += String(value);
972
+ pos2 += placeholdeEnd.length;
973
+ pos = msg.indexOf(placeholderStart, pos2);
974
+ if (pos < 0) ret += msg.substring(pos2);
975
+ else ret += msg.substring(pos2, pos);
976
+ }
977
+ } while (pos > 0);
978
+ return ret;
979
+ }
980
+ /**
981
+ * 从后台的TreeBean转换为前台Condition
982
+ * @param node
983
+ */
984
+ function treeToCondition(node) {
985
+ if (node.$type === "and" || node.$type == "or" || node.$type == "not") return {
986
+ condjunction: node.$type,
987
+ children: (node.$body || []).map(treeToCondition)
988
+ };
989
+ else return {
990
+ op: node.$type,
991
+ left: {
992
+ type: "field",
993
+ field: node.name
994
+ },
995
+ right: node.value
996
+ };
997
+ }
998
+ function conditionToTree(cond) {
999
+ if (cond.conjuction) return {
1000
+ $type: cond.conjuction,
1001
+ $body: (cond.children || []).map(conditionToTree)
1002
+ };
1003
+ else return {
1004
+ $type: cond.op,
1005
+ name: cond.left.field,
1006
+ value: cond.right
1007
+ };
1008
+ }
1009
+ function refHolder() {
1010
+ const value = shallowRef();
1011
+ return {
1012
+ getRaw() {
1013
+ return toRaw(value).value;
1014
+ },
1015
+ get() {
1016
+ return value.value;
1017
+ },
1018
+ set(t) {
1019
+ value.value = t;
1020
+ }
1021
+ };
1022
+ }
1023
+ //#endregion
1024
+ //#region src/shared/cache.ts
1025
+ function createAsyncCache(options) {
1026
+ const cache = new LRUCache(options);
1027
+ return {
1028
+ get(key, loader) {
1029
+ let promise = cache.get(key);
1030
+ if (promise) return promise.then((v) => v && cloneDeep(v));
1031
+ promise = loader(key);
1032
+ cache.set(key, promise);
1033
+ return promise.then((v) => v && cloneDeep(v)).catch((e) => {
1034
+ cache.delete(key);
1035
+ throw e;
1036
+ });
1037
+ },
1038
+ delete(key) {
1039
+ cache.delete(key);
1040
+ },
1041
+ clear() {
1042
+ cache.clear();
1043
+ }
1044
+ };
1045
+ }
1046
+ //#endregion
1047
+ //#region src/shared/index.ts
1048
+ function splitPrefixUrl(url) {
1049
+ if (url.startsWith("@")) {
1050
+ const pos = url.indexOf(":");
1051
+ if (pos < 0) return;
1052
+ return [url.substring(1, pos), url.substring(pos + 1).trim()];
1053
+ }
1054
+ const pos = url.indexOf("://");
1055
+ if (pos < 0) return;
1056
+ return [url.substring(0, pos), url.substring(pos + 3)];
1057
+ }
1058
+ //#endregion
1059
+ //#region src/api/cache.ts
1060
+ const pageCache = createAsyncCache({ max: 50 });
1061
+ const dictCache = createAsyncCache({ max: 100 });
1062
+ function buildLocaleKey(name) {
1063
+ const { useLocale } = useAdapter();
1064
+ return useLocale() + "|" + name;
1065
+ }
1066
+ function clearLocalCache() {
1067
+ pageCache.clear();
1068
+ dictCache.clear();
1069
+ deleteDynamicModules();
1070
+ }
1071
+ function clearPageCache() {
1072
+ pageCache.clear();
1073
+ }
1074
+ function clearDictCache() {
1075
+ dictCache.clear();
1076
+ }
1077
+ function deletePageCache(path) {
1078
+ const key = buildLocaleKey(path);
1079
+ pageCache.delete(key);
1080
+ }
1081
+ function withPageCache(path, fn) {
1082
+ const key = buildLocaleKey(path);
1083
+ return pageCache.get(key, fn);
1084
+ }
1085
+ function withDictCache(dictName, fn) {
1086
+ const key = buildLocaleKey(dictName);
1087
+ return dictCache.get(key, () => {
1088
+ return fn().then((res) => {
1089
+ if (!res.static) dictCache.delete(key);
1090
+ return res;
1091
+ });
1092
+ });
1093
+ }
1094
+ //#endregion
1095
+ //#region src/graphql/gql.ts
1096
+ function handleGraphQL(config, graphqlUrl, options) {
1097
+ const url = config.url;
1098
+ const [type, path] = splitPrefixUrl(url) || [];
1099
+ if (type == "query" || type == "mutation" || type == "subscription") {
1100
+ normalizeData(config);
1101
+ config.method = "post";
1102
+ handleGraphQLUrl(type, path, config, graphqlUrl, options);
1103
+ return true;
1104
+ } else if (url.endsWith("/graphql") || url.indexOf("/graphql?") >= 0) {
1105
+ normalizeData(config);
1106
+ config.transformResponse = transformGraphQLResponse;
1107
+ config.method = "post";
1108
+ return true;
1109
+ } else return false;
1110
+ }
1111
+ function transformGraphQLResponse(data) {
1112
+ data = JSON.parse(data);
1113
+ if (data.errors?.length > 0) {
1114
+ data.status = parseInt(data.extensions?.["nop-status"] || -1);
1115
+ data.msg = data.errors[0].message;
1116
+ } else {
1117
+ data.status = 0;
1118
+ data.msg = data.extensions?.["nop-msg"];
1119
+ }
1120
+ return data;
1121
+ }
1122
+ function handleGraphQLUrl(opType, url, config, graphql, options) {
1123
+ const pos = url.indexOf("?");
1124
+ if (pos > 0) url = url.substring(0, pos);
1125
+ const pos2 = url.indexOf("/");
1126
+ const action = pos2 > 0 ? url.substring(0, pos2) : url;
1127
+ let selection = pos2 > 0 ? url.substring(pos2 + 1) : void 0;
1128
+ if (selection) {
1129
+ selection = selection.replace(/%20/g, " ");
1130
+ selection = selection.replace(/%0A/g, "\n");
1131
+ }
1132
+ if (!selection) selection = options["gql:selection"];
1133
+ let stdAction = action;
1134
+ const pos3 = action.lastIndexOf("_");
1135
+ if (pos3 > 0) stdAction = action.substring(pos3 + 1);
1136
+ let data = config.data || {};
1137
+ if (stdAction === "findPage") {
1138
+ if (data.op === "loadOptions") {
1139
+ const values = toArray(data.value, options.delimiter);
1140
+ data = { ["filter_" + options.valueField + "__in"]: values };
1141
+ selection = "items{" + (options.valueField || "id") + "," + (options.labelField || "id") + "}";
1142
+ }
1143
+ }
1144
+ let def = operationRegistry[stdAction];
1145
+ if (!def) def = guessDefinition(config.data);
1146
+ const args = [...def.arguments, ...guessExtArgDefinitions(config.data)];
1147
+ let query = opType + " " + action;
1148
+ if (args.length > 0) {
1149
+ query += "(";
1150
+ query += args.map((arg) => "$" + arg.name + ":" + arg.type).join(",");
1151
+ query += ")";
1152
+ }
1153
+ query += "{\n";
1154
+ query += action + "(";
1155
+ if (args.length > 0) query += args.map((arg) => arg.name + ":$" + arg.name).join(",");
1156
+ query += ")";
1157
+ if (selection) {
1158
+ query += "{\n";
1159
+ query += selection;
1160
+ query += "\n}";
1161
+ }
1162
+ query += "\n}";
1163
+ const variables = {};
1164
+ args.forEach((arg) => {
1165
+ const builder = arg.builder || defaultArgBuilders[arg.type] || argValue;
1166
+ variables[arg.name] = builder(data, arg, options);
1167
+ });
1168
+ config.transformResponse = [transformGraphQLResponse, (res) => {
1169
+ if (res.data) res.data = res.data[action];
1170
+ return res;
1171
+ }];
1172
+ config.method = "post";
1173
+ config.url = graphql;
1174
+ config.data = {
1175
+ query,
1176
+ variables
1177
+ };
1178
+ }
1179
+ function toArray(value, delimiter) {
1180
+ if (isString(value)) value = value.split(delimiter || ",");
1181
+ return value;
1182
+ }
1183
+ function normalizeData(config) {
1184
+ const { data, params } = splitData(config.params);
1185
+ config.data = {
1186
+ ...filterData(config.data),
1187
+ ...data
1188
+ };
1189
+ config.params = params;
1190
+ }
1191
+ function filterData(data) {
1192
+ if (!data) return {};
1193
+ const ret = {};
1194
+ for (const k in data) {
1195
+ if (k.startsWith("__")) continue;
1196
+ ret[k] = data[k];
1197
+ }
1198
+ return ret;
1199
+ }
1200
+ function splitData(data) {
1201
+ if (!data) return {};
1202
+ const body = {};
1203
+ const params = {};
1204
+ for (const k in data) {
1205
+ if (k.startsWith("__")) continue;
1206
+ if (k.charAt(0) == "@" || k.charAt(0) == "_") params[k] = data[k];
1207
+ else body[k] = data[k];
1208
+ }
1209
+ return {
1210
+ data: body,
1211
+ params
1212
+ };
1213
+ }
1214
+ function guessDefinition(data) {
1215
+ const args = [];
1216
+ if (data) for (const k in data) {
1217
+ if (isSpecialVarName(k)) continue;
1218
+ args.push({
1219
+ name: k,
1220
+ type: guessType(data[k])
1221
+ });
1222
+ }
1223
+ return { arguments: args };
1224
+ }
1225
+ function guessExtArgDefinitions(data) {
1226
+ const args = [];
1227
+ if (data) {
1228
+ for (const k in data) if (k.startsWith("v_")) args.push({
1229
+ name: k,
1230
+ type: guessType(data[k])
1231
+ });
1232
+ }
1233
+ return args;
1234
+ }
1235
+ function isSpecialVarName(name) {
1236
+ return name.startsWith("__") || name.startsWith("@") || name.startsWith("v_");
1237
+ }
1238
+ function guessType(value) {
1239
+ if (isString(value)) return "String";
1240
+ if (isNumber(value)) {
1241
+ if (isInteger(value)) return "Int";
1242
+ return "Float";
1243
+ }
1244
+ if (isBoolean(value)) return "Boolean";
1245
+ if (isPlainObject(value)) return "Map";
1246
+ if (isArray(value)) return "[String]";
1247
+ return "String";
1248
+ }
1249
+ function registerOperation(name, op) {
1250
+ operationRegistry[name] = op;
1251
+ }
1252
+ /**
1253
+ * 缺省注册了CRUD操作所对应的GraphQL类型
1254
+ */
1255
+ const operationRegistry = {
1256
+ get: { arguments: [{
1257
+ name: "id",
1258
+ type: "String",
1259
+ builder: argString
1260
+ }, {
1261
+ name: "ignoreUnknown",
1262
+ type: "Boolean",
1263
+ builder: argBoolean
1264
+ }] },
1265
+ findPage: { arguments: [{
1266
+ name: "query",
1267
+ type: "QueryBeanInput",
1268
+ builder: argQuery
1269
+ }] },
1270
+ findList: { arguments: [{
1271
+ name: "query",
1272
+ type: "QueryBeanInput",
1273
+ builder: argQuery
1274
+ }] },
1275
+ findFirst: { arguments: [{
1276
+ name: "query",
1277
+ type: "QueryBeanInput",
1278
+ builder: argQuery
1279
+ }] },
1280
+ update: { arguments: [{
1281
+ name: "data",
1282
+ type: "Map",
1283
+ builder: argDataMap
1284
+ }] },
1285
+ save: { arguments: [{
1286
+ name: "data",
1287
+ type: "Map",
1288
+ builder: argDataMap
1289
+ }] },
1290
+ saveOrUpdate: { arguments: [{
1291
+ name: "data",
1292
+ type: "Map",
1293
+ builder: argDataMap
1294
+ }] },
1295
+ upsert: { arguments: [{
1296
+ name: "data",
1297
+ type: "Map",
1298
+ builder: argDataMap
1299
+ }] },
1300
+ copyForNew: { arguments: [{
1301
+ name: "data",
1302
+ type: "Map",
1303
+ builder: argDataMap
1304
+ }] },
1305
+ delete: { arguments: [{
1306
+ name: "id",
1307
+ type: "String",
1308
+ builder: argString
1309
+ }] },
1310
+ batchGet: { arguments: [{
1311
+ name: "ids",
1312
+ type: "[String]",
1313
+ builder: argStringList
1314
+ }] },
1315
+ batchDelete: { arguments: [{
1316
+ name: "ids",
1317
+ type: "[String]",
1318
+ builder: argStringList
1319
+ }] },
1320
+ batchModify: { arguments: [{
1321
+ name: "data",
1322
+ type: "[Map]",
1323
+ builder: argMapList
1324
+ }, {
1325
+ name: "delIds",
1326
+ type: "[String]",
1327
+ builder: argStringList
1328
+ }] }
1329
+ };
1330
+ const defaultArgBuilders = {
1331
+ String: argString,
1332
+ Boolean: argBoolean,
1333
+ Int: argInt,
1334
+ Float: argFloat,
1335
+ Map: argMap,
1336
+ "[String]": argStringList,
1337
+ "[Map]": argMapList,
1338
+ QueryBeanInput: argQuery
1339
+ };
1340
+ function argString(data, arg) {
1341
+ const v = data[arg.name];
1342
+ if (v == null) return null;
1343
+ return String(v);
1344
+ }
1345
+ function argBoolean(data, arg) {
1346
+ const v = data[arg.name];
1347
+ if (v == null) return null;
1348
+ if (v == "false" || v == "n" || v == "0" || v == "N") return false;
1349
+ return !!v;
1350
+ }
1351
+ function argInt(data, arg) {
1352
+ const v = data[arg.name];
1353
+ if (v == null) return null;
1354
+ return parseInt(v, 10);
1355
+ }
1356
+ function argFloat(data, arg) {
1357
+ const v = data[arg.name];
1358
+ if (v == null) return null;
1359
+ return parseFloat(v);
1360
+ }
1361
+ /**
1362
+ * 通过 filter_XX__ge=3来表达 <ge name="XX" value="3" />这种过滤条件
1363
+ */
1364
+ function argQuery(data, _arg, options) {
1365
+ const query = {};
1366
+ query.limit = data.limit ?? data.pageSize ?? data.perPage ?? 0;
1367
+ query.offset = data.offset ?? query.limit * ((data.page || 0) - 1);
1368
+ query.orderBy = toOrderBy(data.orderBy ?? data.orderField, data.orderDir);
1369
+ query.filter = toFilter(data);
1370
+ query.cursor = data.cursor;
1371
+ query.timeout = data.timeout;
1372
+ return query;
1373
+ function toOrderBy(v, orderDir) {
1374
+ if (v == null) return;
1375
+ if (isString(v)) {
1376
+ if (v.length == 0) return;
1377
+ if (v.endsWith("_label")) v = v.substring(0, v.length - 6);
1378
+ return [{
1379
+ name: v,
1380
+ desc: orderDir == "desc"
1381
+ }];
1382
+ }
1383
+ if (isArray(v)) return v;
1384
+ return [v];
1385
+ }
1386
+ function toFilter(data) {
1387
+ const filter = {
1388
+ $type: "and",
1389
+ $body: []
1390
+ };
1391
+ for (const k in data) if (k.startsWith("filter_")) {
1392
+ let [name, op] = k.substring(7).split("__");
1393
+ op = op || "eq";
1394
+ let value = data[k];
1395
+ if (value == null || value == "") continue;
1396
+ if (value == "__empty") value = "";
1397
+ else if (value == "__null") value = null;
1398
+ let min = void 0;
1399
+ let max = void 0;
1400
+ if (op.startsWith("between") && value != null) {
1401
+ const ary = toArray(value);
1402
+ min = ary[0];
1403
+ max = ary[1];
1404
+ value = void 0;
1405
+ }
1406
+ filter.$body.push({
1407
+ $type: op,
1408
+ name,
1409
+ value,
1410
+ min,
1411
+ max
1412
+ });
1413
+ }
1414
+ if (options.filter) if (options.filter.$type == "and" || options.filter.$type == "_" || options.filter.$type == "filter") filter.$body = filter.$body.concat(options.filter.$body || []);
1415
+ else filter.$body.push(options.filter);
1416
+ if (filter.$body.length == 0) return;
1417
+ return filter;
1418
+ }
1419
+ }
1420
+ function argDataMap(data, _arg) {
1421
+ if (data == null) return null;
1422
+ const ret = {};
1423
+ for (const k in data) {
1424
+ if (isSpecialVarName(k)) continue;
1425
+ ret[k] = data[k];
1426
+ }
1427
+ return ret;
1428
+ }
1429
+ function argMap(data, arg) {
1430
+ return data[arg.name];
1431
+ }
1432
+ function argStringList(data, arg) {
1433
+ const v = data[arg.name];
1434
+ if (v == null) return null;
1435
+ if (isString(v)) return v.split(",");
1436
+ return v;
1437
+ }
1438
+ function argMapList(data, arg) {
1439
+ return data[arg.name];
1440
+ }
1441
+ function argValue(data, arg) {
1442
+ return data[arg.name];
1443
+ }
1444
+ //#endregion
1445
+ //#region src/ajax/attachmentAdpator.ts
1446
+ /**
1447
+ * 处理接口返回附件的情况,好几个地方用
1448
+ * @param response HTTP响应对象
1449
+ * @param __ 国际化翻译函数
1450
+ * @returns 处理后的响应对象或Promise
1451
+ */
1452
+ function attachmentAdpator(response, __) {
1453
+ if (response && response.headers && response.headers["content-disposition"]) {
1454
+ const disposition = response.headers["content-disposition"];
1455
+ let filename = "";
1456
+ if (disposition && disposition.indexOf("attachment") !== -1) {
1457
+ const matches = disposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
1458
+ if (matches && matches.length) filename = matches[1].replace("UTF-8''", "").replace(/['"]/g, "");
1459
+ if (filename && filename.replace(/[^%]/g, "").length > 2) filename = decodeURIComponent(filename);
1460
+ const contentType = response.headers["content-type"] || "application/octet-stream";
1461
+ const blob = response.data instanceof Blob ? response.data : new Blob([response.data], { type: contentType });
1462
+ const navigator = window.navigator;
1463
+ if (typeof navigator.msSaveBlob !== "undefined") navigator.msSaveBlob(blob, filename);
1464
+ else {
1465
+ const URL = window.URL || window.webkitURL;
1466
+ const downloadUrl = URL.createObjectURL(blob);
1467
+ if (filename) {
1468
+ const anchor = document.createElement("a");
1469
+ if (typeof anchor.download === "undefined") window.location.href = downloadUrl;
1470
+ else {
1471
+ anchor.href = downloadUrl;
1472
+ anchor.download = filename;
1473
+ anchor.style.display = "none";
1474
+ document.body.appendChild(anchor);
1475
+ anchor.click();
1476
+ document.body.removeChild(anchor);
1477
+ }
1478
+ } else window.location.href = downloadUrl;
1479
+ setTimeout(() => {
1480
+ URL.revokeObjectURL(downloadUrl);
1481
+ }, 100);
1482
+ }
1483
+ return {
1484
+ ...response,
1485
+ data: {
1486
+ status: 0,
1487
+ msg: __("sys.api.downloading")
1488
+ }
1489
+ };
1490
+ }
1491
+ } else if (response.data instanceof Blob) return new Promise((resolve, reject) => {
1492
+ const reader = new FileReader();
1493
+ reader.addEventListener("loadend", () => {
1494
+ const text = reader.result;
1495
+ try {
1496
+ const parsedData = JSON.parse(text);
1497
+ resolve({
1498
+ ...response,
1499
+ data: { ...parsedData }
1500
+ });
1501
+ } catch (error) {
1502
+ reject(/* @__PURE__ */ new Error(`解析响应数据失败: ${error instanceof Error ? error.message : String(error)}`));
1503
+ }
1504
+ });
1505
+ reader.addEventListener("error", () => {
1506
+ reject(/* @__PURE__ */ new Error("读取Blob数据失败"));
1507
+ });
1508
+ reader.readAsText(response.data);
1509
+ });
1510
+ return response;
1511
+ }
1512
+ //#endregion
1513
+ //#region src/ajax/ajax.ts
1514
+ const GRAPHQL_URL = "/graphql";
1515
+ const ajax = axios.create({});
1516
+ ajax.interceptors.response.use((res) => {
1517
+ const token = res.headers[HEADER_ACCESS_TOKEN];
1518
+ if (token) useAdapter().setAuthToken(token);
1519
+ return res;
1520
+ });
1521
+ const isCancel = axios.isCancel;
1522
+ function createCancelToken(cancelExecutor) {
1523
+ return new axios.CancelToken(cancelExecutor);
1524
+ }
1525
+ function fetcherOk(data) {
1526
+ return {
1527
+ status: 200,
1528
+ headers: {},
1529
+ data: {
1530
+ status: 0,
1531
+ msg: "",
1532
+ data
1533
+ }
1534
+ };
1535
+ }
1536
+ function responseOk(data) {
1537
+ return {
1538
+ status: 0,
1539
+ msg: "",
1540
+ data
1541
+ };
1542
+ }
1543
+ function ajaxRequest(options) {
1544
+ const { notify, alert } = useAdapter();
1545
+ return ajaxFetch(options).then((d) => {
1546
+ const isUnauthorized = d.status == 401 || d.data?.status == 401;
1547
+ if (!options.silent && !isUnauthorized) {
1548
+ if (d.data?.msg) if (options.config?.useAlert) alert(d.data.msg);
1549
+ else notify(d.data?.status == 0 ? "info" : "error", d.data.msg);
1550
+ }
1551
+ if (d.data?.status != 0) throw new Error(d.data?.msg || "ajax-fail:\ncode=" + d.data?.code + ",status=" + d.data?.status);
1552
+ return d.data.data;
1553
+ });
1554
+ }
1555
+ /**
1556
+ * 提供的对外接口符合amis框架的要求
1557
+ */
1558
+ function ajaxFetch(options) {
1559
+ options.config = options.config || {};
1560
+ let url = options.url;
1561
+ if (!url || typeof url !== "string") return Promise.resolve({
1562
+ status: 500,
1563
+ data: {
1564
+ status: -1,
1565
+ msg: "sys.api.errMsg500"
1566
+ }
1567
+ });
1568
+ let query = options.query || {};
1569
+ const pos = url.indexOf("?");
1570
+ if (pos > 0) {
1571
+ query = {
1572
+ ...query,
1573
+ ...parseUrlParams(url.substring(pos + 1))
1574
+ };
1575
+ url = url.substring(0, pos);
1576
+ }
1577
+ options.query = query;
1578
+ const [type, path] = splitPrefixUrl(url) || [];
1579
+ if (type == "action") {
1580
+ const actionName = path;
1581
+ const action = options._page?.getAction(actionName);
1582
+ if (!action) return Promise.reject(/* @__PURE__ */ new Error("nop.err.unknown-action:" + actionName));
1583
+ try {
1584
+ const result = action(options);
1585
+ return Promise.resolve(result).then((res) => {
1586
+ if (res == null) return fetcherOk(res);
1587
+ return res;
1588
+ });
1589
+ } catch (e) {
1590
+ return Promise.reject(e);
1591
+ }
1592
+ } else if (type == "dict") return useAdapter().fetchDict(path, options);
1593
+ else if (type == "page") return useAdapter().fetchPageAndTransform(path, options);
1594
+ const globSetting = useAdapter().useSettings();
1595
+ if (globSetting.apiUrl && options.config.useApiUrl !== false) url = `${globSetting.apiUrl}${url}`;
1596
+ function normalizeData(data) {
1597
+ if (!data) return data;
1598
+ if (data instanceof FormData || data instanceof ArrayBuffer) return data;
1599
+ return Object.assign({}, data);
1600
+ }
1601
+ const data = normalizeData(options.data);
1602
+ const config = {
1603
+ withCredentials: options.config.withCredentials ?? true,
1604
+ url,
1605
+ method: options.method || "post",
1606
+ headers: options.headers || {},
1607
+ data,
1608
+ params: query,
1609
+ responseType: options.responseType
1610
+ };
1611
+ if (options.config?.cancelExecutor) {
1612
+ const controller = new AbortController();
1613
+ options.config.cancelExecutor(() => {
1614
+ controller.abort();
1615
+ });
1616
+ config.signal = controller.signal;
1617
+ }
1618
+ prepareHeaders(config, { withToken: options.config.withToken });
1619
+ handleGraphQL(config, GRAPHQL_URL, options);
1620
+ if (config.method?.toLowerCase() == "get") {
1621
+ config.params = {
1622
+ ...config.data,
1623
+ ...query
1624
+ };
1625
+ config.data = null;
1626
+ }
1627
+ const { useI18n, processRequest, processResponse } = useAdapter();
1628
+ return processResponse(ajax.request(processRequest(config)).then((res) => {
1629
+ if (res.status == 200 && options.config?.rawResponse) res.data = responseOk(res.data);
1630
+ return res;
1631
+ }).catch((error) => {
1632
+ if (axios.isCancel(error)) throw error;
1633
+ const { t } = useI18n();
1634
+ const { response } = error || {};
1635
+ if (!response?.status) throw new Error(t("sys.api.apiRequestFailed"));
1636
+ const err = error.toString();
1637
+ let errMessage = normalizeErrMessage(response.status, "");
1638
+ if (!errMessage && err?.includes("Network Error")) errMessage = t("sys.api.networkExceptionMsg");
1639
+ if (response.data?.status == null) return {
1640
+ status: response.status,
1641
+ data: {
1642
+ status: -1,
1643
+ msg: errMessage
1644
+ }
1645
+ };
1646
+ return response;
1647
+ }).then((response) => {
1648
+ if (options.responseType == "blob") {
1649
+ if (response.status == 401) {
1650
+ if (!isLogoutRequest(options)) doLogout("401");
1651
+ return response;
1652
+ }
1653
+ const __ = useI18n().t;
1654
+ return attachmentAdpator(response, __);
1655
+ }
1656
+ let data = response.data || {};
1657
+ if (response.status == 401 || data.status == 401) {
1658
+ if (!isLogoutRequest(options)) doLogout("401");
1659
+ } else if (data.status == 0 || data.status == 200) {
1660
+ if (options.responseKey) data = { [options.responseKey]: data.data };
1661
+ }
1662
+ response.data = data;
1663
+ return response;
1664
+ }));
1665
+ }
1666
+ function prepareHeaders(config, opts) {
1667
+ const { useAuthToken, useTenantId, useLocale, useAppId, globalVersion } = useAdapter();
1668
+ const token = useAuthToken();
1669
+ let tenantid = useTenantId();
1670
+ config.headers = config.headers || {};
1671
+ config.headers["nop-locale"] = useLocale()?.replace("_", "-");
1672
+ config.headers["x-requested-with"] = "XMLHttpRequest";
1673
+ if (token && opts.withToken !== false) {
1674
+ config.headers.Authorization = `Bearer ${token}`;
1675
+ config.headers[HEADER_TIMESTAMP] = (/* @__PURE__ */ new Date()).getTime();
1676
+ if (!tenantid) tenantid = "0";
1677
+ config.headers[HEADER_TENANT_ID] = tenantid;
1678
+ config.headers[HEADER_VERSION] = globalVersion;
1679
+ const appId = useAppId();
1680
+ if (appId) config.headers[HEADER_APP_ID] = appId;
1681
+ }
1682
+ }
1683
+ function normalizeErrMessage(status, msg) {
1684
+ const { t } = useAdapter().useI18n();
1685
+ let errMessage = "";
1686
+ switch (status) {
1687
+ case 401:
1688
+ errMessage = msg || t("sys.api.errMsg401");
1689
+ break;
1690
+ case 403:
1691
+ errMessage = t("sys.api.errMsg403");
1692
+ break;
1693
+ case 404:
1694
+ errMessage = t("sys.api.errMsg404");
1695
+ break;
1696
+ case 405:
1697
+ errMessage = t("sys.api.errMsg405");
1698
+ break;
1699
+ case 408:
1700
+ errMessage = t("sys.api.errMsg408");
1701
+ break;
1702
+ case 500:
1703
+ errMessage = t("sys.api.errMsg500");
1704
+ break;
1705
+ case 501:
1706
+ errMessage = t("sys.api.errMsg501");
1707
+ break;
1708
+ case 502:
1709
+ errMessage = t("sys.api.errMsg502");
1710
+ break;
1711
+ case 503:
1712
+ errMessage = t("sys.api.errMsg503");
1713
+ break;
1714
+ case 504:
1715
+ errMessage = t("sys.api.errMsg504");
1716
+ break;
1717
+ case 505: errMessage = t("sys.api.errMsg505");
1718
+ }
1719
+ return errMessage;
1720
+ }
1721
+ /** 是否为退出登录请求(其 401 不应再触发 logout) */
1722
+ function isLogoutRequest(options) {
1723
+ return typeof options.url === "string" && options.url.includes("LoginApi__logout");
1724
+ }
1725
+ /** 防止并发 401 / logout 回调再次发请求导致死循环 */
1726
+ let loggingOut = false;
1727
+ function doLogout(reason) {
1728
+ if (loggingOut) return;
1729
+ loggingOut = true;
1730
+ try {
1731
+ const { setAuthToken, logout } = useAdapter();
1732
+ setAuthToken(void 0);
1733
+ logout(reason);
1734
+ } finally {
1735
+ queueMicrotask(() => {
1736
+ loggingOut = false;
1737
+ });
1738
+ }
1739
+ }
1740
+ //#endregion
1741
+ //#region src/debug/debug.ts
1742
+ const debug$1 = ref(false);
1743
+ const supportDebug$1 = ref(false);
1744
+ function toggleDebug() {
1745
+ setDebug(!debug$1.value);
1746
+ }
1747
+ function setDebug(b) {
1748
+ debug$1.value = b;
1749
+ }
1750
+ /**
1751
+ * 是否进入开发调试状态。调试状态下显示在线编辑器按钮,并设置amisDebug=1,启用AMIS内置的调试器。
1752
+ * 根据后台返回的SiteMap.supportDebug属性进行初始化
1753
+ */
1754
+ function useDebug() {
1755
+ return {
1756
+ debug: debug$1,
1757
+ supportDebug: supportDebug$1,
1758
+ toggleDebug,
1759
+ setDebug
1760
+ };
1761
+ }
1762
+ //#endregion
1763
+ //#region src/api/page-api.ts
1764
+ const PageApis = {
1765
+ DevTool__clearComponentCache,
1766
+ PageProvider__getPage,
1767
+ PageProvider__getPageSource,
1768
+ PageProvider__rollbackPageSource,
1769
+ PageProvider__savePageSource,
1770
+ DictProvider__getDict
1771
+ };
1772
+ function DevTool__clearComponentCache() {
1773
+ const { debug } = useDebug();
1774
+ if (debug) return ajaxRequest({
1775
+ method: "post",
1776
+ url: "@mutation:DevTool__clearComponentCache"
1777
+ });
1778
+ return Promise.resolve({});
1779
+ }
1780
+ function PageProvider__getPage(path) {
1781
+ if (import.meta.env.VITE_USE_MOCK) return ajaxRequest({
1782
+ method: "get",
1783
+ url: `/mock${path}`,
1784
+ config: { rawResponse: true }
1785
+ });
1786
+ if (path.startsWith("/p/")) return withPageCache(path, () => {
1787
+ return ajaxRequest({
1788
+ method: "get",
1789
+ url: path
1790
+ });
1791
+ });
1792
+ return withPageCache(path, () => {
1793
+ return ajaxRequest({
1794
+ method: "post",
1795
+ url: "@query:PageProvider__getPage",
1796
+ data: { path }
1797
+ });
1798
+ });
1799
+ }
1800
+ function PageProvider__getPageSource(path, silent) {
1801
+ return ajaxRequest({
1802
+ method: "post",
1803
+ url: "@query:PageProvider__getPageSource",
1804
+ data: { path },
1805
+ silent
1806
+ }).then((page) => {
1807
+ page.__baseUrl = path;
1808
+ return page;
1809
+ });
1810
+ }
1811
+ function PageProvider__rollbackPageSource(path, silent) {
1812
+ return ajaxRequest({
1813
+ method: "post",
1814
+ url: "@mutation:PageProvider__rollbackPageSource",
1815
+ data: { path },
1816
+ silent
1817
+ });
1818
+ }
1819
+ function PageProvider__savePageSource(path, data, silent) {
1820
+ deletePageCache(path);
1821
+ return ajaxRequest({
1822
+ method: "post",
1823
+ url: "@mutation:PageProvider__savePageSource",
1824
+ data: {
1825
+ path,
1826
+ data: omit(data, "__baseUrl")
1827
+ },
1828
+ silent
1829
+ });
1830
+ }
1831
+ function DictProvider__getDict(dictName, silent) {
1832
+ return withDictCache(dictName, () => {
1833
+ return ajaxRequest({
1834
+ method: "post",
1835
+ url: "@query:DictProvider__getDict/static,options{value,label}",
1836
+ data: { dictName },
1837
+ silent
1838
+ });
1839
+ });
1840
+ }
1841
+ //#endregion
1842
+ //#region src/api/user-api.ts
1843
+ const { supportDebug, debug } = useDebug();
1844
+ const UserApis = {
1845
+ SiteMapApi__getSiteMap,
1846
+ LoginApi__login,
1847
+ LoginApi__getLoginUserInfo,
1848
+ LoginApi__logout,
1849
+ LoginApi__generateVerifyCode,
1850
+ CommonApi__getGlobalData
1851
+ };
1852
+ /** @deprecated 此功能已废弃,将在后续版本中移除 */
1853
+ async function CommonApi__getGlobalData() {
1854
+ return { ...await ajaxRequest({
1855
+ url: "/r/GlobalConfigBizModel__findGlobalConfigList",
1856
+ data: {}
1857
+ }).catch(() => {
1858
+ return {};
1859
+ }) };
1860
+ }
1861
+ function SiteMapApi__getSiteMap() {
1862
+ return ajaxRequest({
1863
+ url: "/r/SiteMapApi__getSiteMap",
1864
+ data: { siteId: "main" }
1865
+ }).then((data) => {
1866
+ supportDebug.value = data.supportDebug;
1867
+ debug.value = data.supportDebug;
1868
+ return data;
1869
+ });
1870
+ }
1871
+ function LoginApi__login(req) {
1872
+ return ajaxRequest({
1873
+ url: `/r/LoginApi__login?@selection=token:accessToken`,
1874
+ data: req,
1875
+ silent: true
1876
+ });
1877
+ }
1878
+ function LoginApi__getLoginUserInfo() {
1879
+ const { useAuthToken } = useAdapter();
1880
+ return ajaxRequest({
1881
+ url: "@query:LoginApi__getLoginUserInfo/userId,username:userName,realname:nickName",
1882
+ data: { accessToken: useAuthToken() }
1883
+ });
1884
+ }
1885
+ function LoginApi__logout() {
1886
+ const { useAuthToken } = useAdapter();
1887
+ return ajaxRequest({
1888
+ url: "@mutation:LoginApi__logout",
1889
+ data: { accessToken: useAuthToken() },
1890
+ silent: true
1891
+ });
1892
+ }
1893
+ function LoginApi__generateVerifyCode(verifySecret) {
1894
+ return ajaxRequest({
1895
+ url: "/r/LoginApi__generateVerifyCode",
1896
+ method: "get",
1897
+ data: { verifySecret }
1898
+ });
1899
+ }
1900
+ //#endregion
1901
+ //#region src/page/processor.ts
1902
+ /**
1903
+ * 查找所有具有typeProp指定的属性的节点,并调用processor进行处理,返回结果将会替换原节点。
1904
+ * 例如识别xui:roles属性,自动删除没有对应权限的节点
1905
+ *
1906
+ * @param json json对象
1907
+ * @param typeProp 类型字段名
1908
+ * @param processor 处理器
1909
+ * @returns 经过处理替换后得到的节点
1910
+ */
1911
+ async function processXuiDirective(json, typeProp, processor) {
1912
+ const futures = [];
1913
+ const ret = _processXuiDirective(json, typeProp, processor, futures);
1914
+ await Promise.all(futures);
1915
+ return ret;
1916
+ }
1917
+ function _processXuiDirective(json, typeProp, processor, futures) {
1918
+ if (!json) return json;
1919
+ function processProps(json) {
1920
+ for (const key in json) {
1921
+ let v = json[key];
1922
+ v = _processXuiDirective(v, typeProp, processor, futures);
1923
+ if (v === void 0) delete json[key];
1924
+ else if (v != json[key]) {
1925
+ json[key] = v;
1926
+ if (isPromise(v)) {
1927
+ v.then((ret) => {
1928
+ if (ret === void 0) delete json[key];
1929
+ else json[key] = ret;
1930
+ });
1931
+ json[key] = v;
1932
+ futures.push(v);
1933
+ }
1934
+ }
1935
+ }
1936
+ return json;
1937
+ }
1938
+ if (isArray(json)) for (let i = 0, n = json.length; i < n; i++) {
1939
+ const child = _processXuiDirective(json[i], typeProp, processor, futures);
1940
+ if (child === void 0) {
1941
+ json.splice(i, 1);
1942
+ i--;
1943
+ n--;
1944
+ } else if (child != json[i]) {
1945
+ json[i] = child;
1946
+ if (isPromise(child)) child.then((ret) => {
1947
+ const idx = json.indexOf(child);
1948
+ if (idx < 0) return;
1949
+ if (ret == void 0) json.splice(idx, 1);
1950
+ else json[idx] = ret;
1951
+ });
1952
+ }
1953
+ }
1954
+ else if (isObject(json)) {
1955
+ const type = json[typeProp];
1956
+ if (type) return processor(type, json, processProps);
1957
+ processProps(json);
1958
+ }
1959
+ return json;
1960
+ }
1961
+ /**
1962
+ * 对json对象中的字符串值调用processor来处理
1963
+ * @param json 待处理的对象
1964
+ * @param processor 处理器
1965
+ * @returns
1966
+ */
1967
+ function processXuiValue(json, processor) {
1968
+ if (!json) return json;
1969
+ function processProps(json) {
1970
+ for (const key in json) {
1971
+ let v = json[key];
1972
+ if (isString(v)) {
1973
+ v = processor(v, key, json);
1974
+ if (v === void 0) delete json[key];
1975
+ else if (v != json[key]) json[key] = v;
1976
+ } else processXuiValue(v, processor);
1977
+ }
1978
+ return json;
1979
+ }
1980
+ if (isArray(json)) for (let i = 0, n = json.length; i < n; i++) {
1981
+ const child = json[i];
1982
+ if (isString(child)) {
1983
+ const v = processor(child, i, json);
1984
+ if (v === void 0) {
1985
+ delete json[i];
1986
+ i--;
1987
+ n--;
1988
+ } else if (v != json[i]) json[i] = v;
1989
+ } else processXuiValue(child, processor);
1990
+ }
1991
+ else if (isObject(json)) processProps(json);
1992
+ return json;
1993
+ }
1994
+ //#endregion
1995
+ //#region src/page/action.ts
1996
+ /**
1997
+ * 通过xui:import可以引入SystemJs格式的js模块,通过@action:xxx,@fn:(a,b)=>expr这种形式可以调用js模块中的函数
1998
+ *
1999
+ * 例如 {
2000
+ * "xui:import": "a.lib"
2001
+ * "page": {
2002
+ * dialog: {
2003
+ * "xui:import": "b.lib"
2004
+ * api: "@action:a.f1"
2005
+ * }
2006
+ * }
2007
+ * }
2008
+ *
2009
+ * 上面的例子中@action:a.f1首先向上查找最近的xui:import引入的js库,如果没有找到,则继续向上查找直到顶层的节点。
2010
+ *
2011
+ * @action:xxx与 @fn:(a,b)=> expr的区别在于 @action:xxx对应函数名,@fn:(a,b)=>expr则是直接定义匿名函数实现
2012
+ *
2013
+ * @param json json schema
2014
+ */
2015
+ async function bindActions(pageUrl, json, page) {
2016
+ if (!json) return;
2017
+ page.resetActions();
2018
+ const promises = [];
2019
+ const fnStack = [];
2020
+ processXuiDirective(json, "xui:import", (modulePaths, obj, processProps) => {
2021
+ const fnScope = {
2022
+ standalone: obj["xui:standalone"],
2023
+ libs: {}
2024
+ };
2025
+ fnStack.push(fnScope);
2026
+ fetchModules(pageUrl, modulePaths, promises, fnScope);
2027
+ processProps(obj);
2028
+ return obj;
2029
+ });
2030
+ await Promise.all(promises);
2031
+ let stackIndex = -1;
2032
+ function process(json) {
2033
+ if (!isPlainObject(json)) return;
2034
+ const modulePaths = json["xui:import"];
2035
+ if (modulePaths) stackIndex++;
2036
+ for (const key in json) {
2037
+ const v = json[key];
2038
+ if (!v) continue;
2039
+ if (isString(v)) json[key] = processValue(key, v);
2040
+ else if (isArray(v)) for (let i = 0, n = v.length; i < n; i++) process(v[i]);
2041
+ else process(v);
2042
+ }
2043
+ if (modulePaths) stackIndex--;
2044
+ }
2045
+ function processValue(_key, v) {
2046
+ const [type, path] = splitPrefixUrl(v) || [];
2047
+ if (!type) return v;
2048
+ if ([
2049
+ "query",
2050
+ "mutation",
2051
+ "graphql",
2052
+ "dict",
2053
+ "page"
2054
+ ].includes(type)) return type + "://" + path;
2055
+ else if (type == "action") {
2056
+ const fnName = path.split("-")[0];
2057
+ const action = findAction(fnName, fnStack, stackIndex, page);
2058
+ for (let i = 0; i < 1e3; i++) {
2059
+ const actionName = i == 0 ? fnName : fnName + "-" + i;
2060
+ const existed = page.getAction(actionName);
2061
+ if (!existed) {
2062
+ page.registerAction(actionName, action);
2063
+ return "action://" + actionName;
2064
+ } else if (existed == action) return "action://" + actionName;
2065
+ }
2066
+ throw new Error("nop.err.action-name-conflict:" + v);
2067
+ } else if (type == "fn") return wrapFunc(buildFunction(path, page), v);
2068
+ return v;
2069
+ }
2070
+ process(json);
2071
+ }
2072
+ function buildFunction(fn, page) {
2073
+ return useAdapter().compileFunction(fn, page);
2074
+ }
2075
+ function fetchModules(pageUrl, modulePaths, promises, fnScope) {
2076
+ if (isString(modulePaths)) modulePaths = modulePaths.split(",").reduce((m, p) => {
2077
+ m[getPathName(p)] = p;
2078
+ return m;
2079
+ }, {});
2080
+ for (const moduleName in modulePaths) {
2081
+ const promise = importModule(absolutePath(modulePaths[moduleName], pageUrl)).then((mod) => {
2082
+ fnScope.libs[moduleName] = mod;
2083
+ });
2084
+ promises.push(promise);
2085
+ }
2086
+ }
2087
+ function getPathName(path) {
2088
+ const pos = path.lastIndexOf("/");
2089
+ if (pos >= 0) path = path.substring(pos + 1);
2090
+ const pos2 = path.indexOf(".");
2091
+ if (pos2 > 0) return path.substring(0, pos2);
2092
+ return path;
2093
+ }
2094
+ function findAction(fnName, fnStack, stackIndex, page) {
2095
+ const pos = fnName.indexOf(".");
2096
+ if (pos < 0) {
2097
+ const api = page.getAction(fnName);
2098
+ if (!api) throw new Error("nop.err.unknown-action:" + fnName);
2099
+ return api;
2100
+ }
2101
+ const libName = fnName.substring(0, pos);
2102
+ const methodName = fnName.substring(pos + 1);
2103
+ for (let i = stackIndex; i >= 0; i--) {
2104
+ const fnScope = fnStack[i];
2105
+ if (fnScope.standalone) break;
2106
+ const lib = fnScope.libs[libName];
2107
+ if (lib?.[methodName]) return lib[methodName];
2108
+ }
2109
+ throw new Error("nop.err.unknown-action:" + fnName);
2110
+ }
2111
+ /**
2112
+ * 将函数的JSON序列化结果固化为指定值
2113
+ */
2114
+ function wrapFunc(fn, text) {
2115
+ const ret = (...args) => fn(...args);
2116
+ ret.toJSON = () => text;
2117
+ return ret;
2118
+ }
2119
+ //#endregion
2120
+ //#region src/page/registry.ts
2121
+ const g_components = {};
2122
+ function registerXuiComponent(type, component) {
2123
+ g_components[type] = component;
2124
+ }
2125
+ function unregisterXuiComponent(type) {
2126
+ delete g_components[type];
2127
+ }
2128
+ function resolveXuiComponent(type, json) {
2129
+ const comp = g_components[type];
2130
+ if (!comp) throw new Error("nop.err.xui.unknown-component:" + type);
2131
+ return comp(json);
2132
+ }
2133
+ //#endregion
2134
+ //#region src/page/transform.ts
2135
+ async function transformPageJson(pageUrl, json) {
2136
+ json.__baseUrl = pageUrl;
2137
+ json = await processXuiDirective(json, "xui:roles", filterByAuth);
2138
+ json = await processXuiDirective(json, "xui:component", resolveXuiComponent);
2139
+ return json;
2140
+ }
2141
+ function filterByAuth(roles, json) {
2142
+ const { isUserInRole } = useAdapter();
2143
+ if (!isUserInRole(roles)) return;
2144
+ return json;
2145
+ }
2146
+ //#endregion
2147
+ //#region src/page/page.ts
2148
+ let g_nextIndex = 0;
2149
+ function createPage(options) {
2150
+ let actions = { ...options.actions };
2151
+ return {
2152
+ id: "page_" + String(g_nextIndex++),
2153
+ getAction(name) {
2154
+ return actions[name];
2155
+ },
2156
+ registerAction(name, fn) {
2157
+ actions[name] = fn;
2158
+ },
2159
+ resetActions() {
2160
+ actions = { ...options.actions };
2161
+ },
2162
+ getComponent: options.getComponent,
2163
+ getScopedStore: options.getScopedStore,
2164
+ getState: options.getState,
2165
+ setState: options.setState
2166
+ };
2167
+ }
2168
+ //#endregion
2169
+ //#region src/scope.ts
2170
+ let s_page;
2171
+ function usePage() {
2172
+ return s_page;
2173
+ }
2174
+ function providePage(page) {
2175
+ s_page = page;
2176
+ }
2177
+ let s_scoped;
2178
+ function useScoped() {
2179
+ return s_scoped;
2180
+ }
2181
+ function provideScoped(scoped) {
2182
+ s_scoped = scoped;
2183
+ }
2184
+ let s_scopedStore;
2185
+ function useScopedStore() {
2186
+ return s_scopedStore;
2187
+ }
2188
+ function provideScopedStore(store) {
2189
+ s_scopedStore = store;
2190
+ }
2191
+ function clearScoped() {
2192
+ s_page = void 0;
2193
+ s_scoped = void 0;
2194
+ s_scopedStore = void 0;
2195
+ }
2196
+ //#endregion
2197
+ //#region src/schema-type.ts
2198
+ const schemaProcessorTypes = {};
2199
+ function registerSchemaProcessorType(typeName, schemaProcessorType) {
2200
+ schemaProcessorTypes[typeName] = schemaProcessorType;
2201
+ }
2202
+ function getSchemaProcessorType(typeName) {
2203
+ return schemaProcessorTypes[typeName];
2204
+ }
2205
+ //#endregion
2206
+ //#region src/index.ts
2207
+ registerModule("@kdesigner/core", /* @__PURE__ */ __exportAll({
2208
+ CONSTANTS: () => constants_exports,
2209
+ PageApis: () => PageApis,
2210
+ UserApis: () => UserApis,
2211
+ absolutePath: () => absolutePath,
2212
+ addSystemImportMap: () => addSystemImportMap,
2213
+ ajax: () => ajax,
2214
+ ajaxFetch: () => ajaxFetch,
2215
+ ajaxRequest: () => ajaxRequest,
2216
+ bindActions: () => bindActions,
2217
+ clearDictCache: () => clearDictCache,
2218
+ clearLocalCache: () => clearLocalCache,
2219
+ clearPageCache: () => clearPageCache,
2220
+ clearScoped: () => clearScoped,
2221
+ conditionToTree: () => conditionToTree,
2222
+ createAsyncCache: () => createAsyncCache,
2223
+ createCancelToken: () => createCancelToken,
2224
+ createPage: () => createPage,
2225
+ default_isCurrentUrl: () => default_isCurrentUrl,
2226
+ default_jumpTo: () => default_jumpTo,
2227
+ default_updateLocation: () => default_updateLocation,
2228
+ deleteDynamicModules: () => deleteDynamicModules,
2229
+ deletePageCache: () => deletePageCache,
2230
+ fetcherOk: () => fetcherOk,
2231
+ format: () => format,
2232
+ getSchemaProcessorType: () => getSchemaProcessorType,
2233
+ handleGraphQL: () => handleGraphQL,
2234
+ importModule: () => importModule,
2235
+ isCancel: () => isCancel,
2236
+ isPageUrl: () => isPageUrl,
2237
+ openWindow: () => openWindow,
2238
+ processXuiDirective: () => processXuiDirective,
2239
+ processXuiValue: () => processXuiValue,
2240
+ providePage: () => providePage,
2241
+ provideScoped: () => provideScoped,
2242
+ provideScopedStore: () => provideScopedStore,
2243
+ refHolder: () => refHolder,
2244
+ registerAdapter: () => registerAdapter,
2245
+ registerModule: () => registerModule,
2246
+ registerOperation: () => registerOperation,
2247
+ registerSchemaProcessorType: () => registerSchemaProcessorType,
2248
+ registerXuiComponent: () => registerXuiComponent,
2249
+ resolveXuiComponent: () => resolveXuiComponent,
2250
+ responseOk: () => responseOk,
2251
+ splitPrefixUrl: () => splitPrefixUrl,
2252
+ transformPageJson: () => transformPageJson,
2253
+ treeToCondition: () => treeToCondition,
2254
+ unregisterXuiComponent: () => unregisterXuiComponent,
2255
+ useAdapter: () => useAdapter,
2256
+ useDebug: () => useDebug,
2257
+ usePage: () => usePage,
2258
+ useScoped: () => useScoped,
2259
+ useScopedStore: () => useScopedStore,
2260
+ withDictCache: () => withDictCache,
2261
+ withPageCache: () => withPageCache
2262
+ }));
2263
+ registerAdapter({
2264
+ fetchDict(dictName, options) {
2265
+ return PageApis.DictProvider__getDict(dictName, options.silent || false).then((res) => fetcherOk(res));
2266
+ },
2267
+ fetchPageAndTransform(pagePath, options) {
2268
+ return PageApis.PageProvider__getPage(pagePath).then(async (pageData) => {
2269
+ pageData = await transformPageJson(pagePath, pageData);
2270
+ if (options._page) bindActions(pagePath, pageData, options._page);
2271
+ return fetcherOk(pageData);
2272
+ });
2273
+ },
2274
+ getPage(pageUrl) {
2275
+ return PageApis.PageProvider__getPage(pageUrl);
2276
+ }
2277
+ });
2278
+ //#endregion
2279
+ export { constants_exports as CONSTANTS, PageApis, UserApis, absolutePath, addSystemImportMap, ajax, ajaxFetch, ajaxRequest, bindActions, clearDictCache, clearLocalCache, clearPageCache, clearScoped, conditionToTree, createAsyncCache, createCancelToken, createPage, default_isCurrentUrl, default_jumpTo, default_updateLocation, deleteDynamicModules, deletePageCache, fetcherOk, format, getSchemaProcessorType, handleGraphQL, importModule, isCancel, isPageUrl, openWindow, processXuiDirective, processXuiValue, providePage, provideScoped, provideScopedStore, refHolder, registerAdapter, registerModule, registerOperation, registerSchemaProcessorType, registerXuiComponent, resolveXuiComponent, responseOk, splitPrefixUrl, transformPageJson, treeToCondition, unregisterXuiComponent, useAdapter, useDebug, usePage, useScoped, useScopedStore, withDictCache, withPageCache };
2280
+
2281
+ //# sourceMappingURL=index.js.map