x-essential-lib 0.11.0 → 0.11.2

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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as EventType, t as Emitter } from "./vendor.nm6zptdy.js";
1
+ import { n as EventType, t as Emitter } from "./vendor.go3lw3gz.js";
2
2
  import { Ref } from "vue";
3
3
  import { AxiosInstance } from "axios";
4
4
  //#region src/composables/color.d.ts
@@ -23,60 +23,6 @@ interface Options {
23
23
  }
24
24
  export declare function createAxios(options: Options): AxiosInstance;
25
25
  //#endregion
26
- //#region src/utils/dialog.d.ts
27
- interface ButtonOptions {
28
- color?: string;
29
- text?: string;
30
- }
31
- interface ConfirmParams {
32
- title: string;
33
- subtitle?: string;
34
- text: string;
35
- cancel?: ButtonOptions;
36
- ok?: ButtonOptions;
37
- }
38
- export declare function openConfirmDlg(params: ConfirmParams): Promise<boolean | undefined>;
39
- interface NumberParams {
40
- title: string;
41
- subtitle?: string;
42
- value: number;
43
- precision?: number;
44
- min?: number;
45
- max?: number;
46
- step?: number;
47
- }
48
- export declare function openNumberDlg(params: NumberParams): Promise<number | undefined>;
49
- interface PromptParams {
50
- title: string;
51
- subtitle?: string;
52
- text?: string;
53
- label?: string;
54
- placeholder?: string;
55
- rules?: ((val: string) => string | boolean)[];
56
- value?: string;
57
- cancel?: ButtonOptions;
58
- ok?: ButtonOptions;
59
- }
60
- export declare function openPromptDlg(params: PromptParams): Promise<string | undefined>;
61
- export declare function openWaitDlg(text?: string): void;
62
- export declare function closeWaitDlg(): void;
63
- //#endregion
64
- //#region src/utils/message.d.ts
65
- export declare function messageError(text: string, timeout?: number): void;
66
- export declare function messageInfo(text: string, timeout?: number): void;
67
- export declare function messageSuccess(text: string, timeout?: number): void;
68
- export declare function messageWarning(text: string, timeout?: number): void;
69
- //#endregion
70
- //#region src/utils/misc.d.ts
71
- export declare const globalObjects: {
72
- router: any;
73
- i18n: any;
74
- };
75
- export declare const eventBus: Emitter<Record<EventType, unknown>>;
76
- export declare function waitMs(ms: number): Promise<void>;
77
- export declare function waitUtil(conditionFunc: () => boolean, timeout?: number, interval?: number): Promise<boolean>;
78
- export declare function appAppear(name: string, diff: number): void;
79
- //#endregion
80
26
  //#region src/pb/orgbase/v1/permission.d.ts
81
27
  export declare enum Permission {
82
28
  unknown_permission = "unknown_permission",
@@ -254,6 +200,68 @@ export declare function toPermissionObjects(permissions: {
254
200
  export declare function isExist(instanceTree: InstanceTree | undefined, instance: string): boolean;
255
201
  export declare function verifyPermission(permissionObjects: PermissionObjects, permission: Permission, instance: string): boolean;
256
202
  //#endregion
203
+ //#region src/utils/rules/index.d.ts
204
+ type Rule = (value: unknown) => true | string;
205
+ export declare function required(value: unknown): true | string;
206
+ export declare function email(value: unknown): true | string;
207
+ export declare function minLength(length: number): Rule;
208
+ export declare function maxLength(length: number): Rule;
209
+ export declare function length(length: number): Rule;
210
+ //#endregion
211
+ //#region src/utils/dialog.d.ts
212
+ interface ButtonOptions {
213
+ color?: string;
214
+ text?: string;
215
+ }
216
+ interface ConfirmParams {
217
+ title: string;
218
+ subtitle?: string;
219
+ text: string;
220
+ cancel?: ButtonOptions;
221
+ ok?: ButtonOptions;
222
+ }
223
+ export declare function openConfirmDlg(params: ConfirmParams): Promise<boolean | undefined>;
224
+ interface NumberParams {
225
+ title: string;
226
+ subtitle?: string;
227
+ value: number;
228
+ precision?: number;
229
+ min?: number;
230
+ max?: number;
231
+ step?: number;
232
+ }
233
+ export declare function openNumberDlg(params: NumberParams): Promise<number | undefined>;
234
+ interface PromptParams {
235
+ title: string;
236
+ subtitle?: string;
237
+ text?: string;
238
+ label?: string;
239
+ placeholder?: string;
240
+ rules?: ((val: string) => string | boolean)[];
241
+ value?: string;
242
+ cancel?: ButtonOptions;
243
+ ok?: ButtonOptions;
244
+ }
245
+ export declare function openPromptDlg(params: PromptParams): Promise<string | undefined>;
246
+ export declare function openWaitDlg(text?: string): void;
247
+ export declare function closeWaitDlg(): void;
248
+ //#endregion
249
+ //#region src/utils/message.d.ts
250
+ export declare function messageError(text: string, timeout?: number): void;
251
+ export declare function messageInfo(text: string, timeout?: number): void;
252
+ export declare function messageSuccess(text: string, timeout?: number): void;
253
+ export declare function messageWarning(text: string, timeout?: number): void;
254
+ //#endregion
255
+ //#region src/utils/misc.d.ts
256
+ export declare const globalObjects: {
257
+ router: any;
258
+ i18n: any;
259
+ };
260
+ export declare const eventBus: Emitter<Record<EventType, unknown>>;
261
+ export declare function waitMs(ms: number): Promise<void>;
262
+ export declare function waitUtil(conditionFunc: () => boolean, timeout?: number, interval?: number): Promise<boolean>;
263
+ export declare function appAppear(name: string, diff: number): void;
264
+ //#endregion
257
265
  //#region src/utils/provideInject.d.ts
258
266
  export declare function provideDark(dark: Ref<boolean>): void;
259
267
  export declare function injectDark(): Ref<boolean>;
package/dist/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  (function(){try{document.getElementById(`x-essential-lib`)?.remove();const e = document.createElement(`style`);e.setAttribute(`id`, `x-essential-lib`);const t = document.createTextNode(`.fade-leave-active[data-v-x-essential-lib-c3545c8d]{transition:opacity .5s}.fade-leave-to[data-v-x-essential-lib-c3545c8d]{opacity:0}.x-cont[data-v-x-essential-lib-c3545c8d]{justify-content:center;align-items:center;display:flex;position:absolute;inset:0}.lds-spinner[data-v-x-essential-lib-c3545c8d]{color:official;width:40px;height:40px;display:inline-block;position:relative}.lds-spinner div[data-v-x-essential-lib-c3545c8d]{transform-origin:20px 20px;animation:1.2s linear infinite lds-spinner-x-essential-lib-c3545c8d}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:after{content:" ";background:#9e9e9e;border-radius:5%;width:2px;height:6px;display:block;position:absolute;top:3px;left:18px}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:first-child{animation-delay:-1.1s;transform:rotate(0)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(2){animation-delay:-1s;transform:rotate(30deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(3){animation-delay:-.9s;transform:rotate(60deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(4){animation-delay:-.8s;transform:rotate(90deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(5){animation-delay:-.7s;transform:rotate(120deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(6){animation-delay:-.6s;transform:rotate(150deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(7){animation-delay:-.5s;transform:rotate(180deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(8){animation-delay:-.4s;transform:rotate(210deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(9){animation-delay:-.3s;transform:rotate(240deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(10){animation-delay:-.2s;transform:rotate(270deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(11){animation-delay:-.1s;transform:rotate(300deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(12){animation-delay:0s;transform:rotate(330deg)}@keyframes lds-spinner-x-essential-lib-c3545c8d{0%{opacity:1}to{opacity:0}}.x-item[data-v-x-essential-lib-cfcda9d9]{width:600px}@media (width<=600px){.x-item[data-v-x-essential-lib-cfcda9d9]{width:calc(100vw - 16px)}}.x-cont[data-v-x-essential-lib-b973907d]{z-index:9999;position:fixed;bottom:50px;left:50%;transform:translate(-50%)}`);e.appendChild(t);document.head.appendChild(e);}catch(e){console.error('rolldown-plugin-inject-css', e);}})()
2
- import { a as mitt_default, i as api, o as usePreferredDark, r as toLower } from "./vendor.nm6zptdy.js";
2
+ import { a as email$1, c as mitt_default, i as custom, l as usePreferredDark, o as string, r as toLower, s as api } from "./vendor.go3lw3gz.js";
3
3
  import { Fragment, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, inject, isRef, normalizeStyle, onBeforeMount, onBeforeUnmount, onMounted, openBlock, provide, ref, renderList, resolveComponent, toDisplayString, unref, useTemplateRef, watch, watchEffect, withCtx, withKeys, withModifiers } from "vue";
4
4
  import { useI18n } from "vue-i18n";
5
5
  import { useDisplay, useTheme } from "vuetify";
6
6
  import axios from "axios";
7
+ import { globalObjects as globalObjects$1 } from "x-essential-lib";
7
8
  import { useRoute, useRouter } from "vue-router";
8
9
 
9
10
  //#region src/composables/color.ts
@@ -172,113 +173,6 @@ function onUnauthorized() {
172
173
  router.replace({ path: `/passport/login` });
173
174
  }
174
175
 
175
- //#endregion
176
- //#region src/utils/dialog.ts
177
- let lastTime = Date.now();
178
- function tryCooldown() {
179
- const now = Date.now();
180
- if (now - lastTime > 500) {
181
- lastTime = now;
182
- return true;
183
- }
184
- return false;
185
- }
186
- let sequence = 0;
187
- function getSequence() {
188
- return ++sequence;
189
- }
190
- async function openConfirmDlg(params) {
191
- if (!tryCooldown()) return;
192
- let resp = false;
193
- let result;
194
- const onResult = (res) => {
195
- result = res;
196
- resp = true;
197
- };
198
- const seq = getSequence();
199
- eventBus.on("confirmDlgResult" + seq, onResult);
200
- eventBus.emit("confirmDlg", {
201
- ...params,
202
- seq
203
- });
204
- await waitUtil(() => resp);
205
- eventBus.off("confirmDlgResult" + seq, onResult);
206
- return result;
207
- }
208
- async function openNumberDlg(params) {
209
- if (!tryCooldown()) return;
210
- let resp = false;
211
- let result;
212
- const onResult = (res) => {
213
- result = res;
214
- resp = true;
215
- };
216
- const seq = getSequence();
217
- eventBus.on("numberDlgResult" + seq, onResult);
218
- eventBus.emit("numberDlg", {
219
- ...params,
220
- seq
221
- });
222
- await waitUtil(() => resp);
223
- eventBus.off("numberDlgResult" + seq, onResult);
224
- return result;
225
- }
226
- async function openPromptDlg(params) {
227
- if (!tryCooldown()) return;
228
- let resp = false;
229
- let result;
230
- const onResult = (res) => {
231
- result = res;
232
- resp = true;
233
- };
234
- const seq = getSequence();
235
- eventBus.on("promptDlgResult" + seq, onResult);
236
- eventBus.emit("promptDlg", {
237
- ...params,
238
- seq
239
- });
240
- await waitUtil(() => resp);
241
- eventBus.off("promptDlgResult" + seq, onResult);
242
- return result;
243
- }
244
- function openWaitDlg(text) {
245
- eventBus.emit("waitDlg", { text });
246
- }
247
- function closeWaitDlg() {
248
- eventBus.emit("closeWaitDlg");
249
- }
250
-
251
- //#endregion
252
- //#region src/utils/message.ts
253
- function messageError(text, timeout) {
254
- eventBus.emit("message", {
255
- type: "error",
256
- text,
257
- timeout
258
- });
259
- }
260
- function messageInfo(text, timeout) {
261
- eventBus.emit("message", {
262
- type: "info",
263
- text,
264
- timeout
265
- });
266
- }
267
- function messageSuccess(text, timeout) {
268
- eventBus.emit("message", {
269
- type: "success",
270
- text,
271
- timeout
272
- });
273
- }
274
- function messageWarning(text, timeout) {
275
- eventBus.emit("message", {
276
- type: "warning",
277
- text,
278
- timeout
279
- });
280
- }
281
-
282
176
  //#endregion
283
177
  //#region src/pb/orgbase/v1/permission.ts
284
178
  let Permission = /* @__PURE__ */ function(Permission) {
@@ -1214,6 +1108,146 @@ function verifyPermission(permissionObjects, permission, instance) {
1214
1108
  return true;
1215
1109
  }
1216
1110
 
1111
+ //#endregion
1112
+ //#region src/utils/rules/index.ts
1113
+ function i18n(key, obj) {
1114
+ const { i18n } = globalObjects$1;
1115
+ return i18n.global.t(`x-essential-lib.rule.${key}`, obj);
1116
+ }
1117
+ function required(value) {
1118
+ const { success } = custom((v) => v === 0 || !!v).safeParse(value);
1119
+ return success ? success : i18n("required");
1120
+ }
1121
+ function email(value) {
1122
+ const { success } = email$1().safeParse(value);
1123
+ return success ? success : i18n("email");
1124
+ }
1125
+ function minLength(length) {
1126
+ return (value) => {
1127
+ const { success } = string().min(length).safeParse(value);
1128
+ return success ? success : i18n("minLength", { length });
1129
+ };
1130
+ }
1131
+ function maxLength(length) {
1132
+ return (value) => {
1133
+ const { success } = string().max(length).safeParse(value);
1134
+ return success ? success : i18n("maxLength", { length });
1135
+ };
1136
+ }
1137
+ function length(length) {
1138
+ return (value) => {
1139
+ const { success } = string().length(length).safeParse(value);
1140
+ return success ? success : i18n("length", { length });
1141
+ };
1142
+ }
1143
+
1144
+ //#endregion
1145
+ //#region src/utils/dialog.ts
1146
+ let lastTime = Date.now();
1147
+ function tryCooldown() {
1148
+ const now = Date.now();
1149
+ if (now - lastTime > 500) {
1150
+ lastTime = now;
1151
+ return true;
1152
+ }
1153
+ return false;
1154
+ }
1155
+ let sequence = 0;
1156
+ function getSequence() {
1157
+ return ++sequence;
1158
+ }
1159
+ async function openConfirmDlg(params) {
1160
+ if (!tryCooldown()) return;
1161
+ let resp = false;
1162
+ let result;
1163
+ const onResult = (res) => {
1164
+ result = res;
1165
+ resp = true;
1166
+ };
1167
+ const seq = getSequence();
1168
+ eventBus.on("confirmDlgResult" + seq, onResult);
1169
+ eventBus.emit("confirmDlg", {
1170
+ ...params,
1171
+ seq
1172
+ });
1173
+ await waitUtil(() => resp);
1174
+ eventBus.off("confirmDlgResult" + seq, onResult);
1175
+ return result;
1176
+ }
1177
+ async function openNumberDlg(params) {
1178
+ if (!tryCooldown()) return;
1179
+ let resp = false;
1180
+ let result;
1181
+ const onResult = (res) => {
1182
+ result = res;
1183
+ resp = true;
1184
+ };
1185
+ const seq = getSequence();
1186
+ eventBus.on("numberDlgResult" + seq, onResult);
1187
+ eventBus.emit("numberDlg", {
1188
+ ...params,
1189
+ seq
1190
+ });
1191
+ await waitUtil(() => resp);
1192
+ eventBus.off("numberDlgResult" + seq, onResult);
1193
+ return result;
1194
+ }
1195
+ async function openPromptDlg(params) {
1196
+ if (!tryCooldown()) return;
1197
+ let resp = false;
1198
+ let result;
1199
+ const onResult = (res) => {
1200
+ result = res;
1201
+ resp = true;
1202
+ };
1203
+ const seq = getSequence();
1204
+ eventBus.on("promptDlgResult" + seq, onResult);
1205
+ eventBus.emit("promptDlg", {
1206
+ ...params,
1207
+ seq
1208
+ });
1209
+ await waitUtil(() => resp);
1210
+ eventBus.off("promptDlgResult" + seq, onResult);
1211
+ return result;
1212
+ }
1213
+ function openWaitDlg(text) {
1214
+ eventBus.emit("waitDlg", { text });
1215
+ }
1216
+ function closeWaitDlg() {
1217
+ eventBus.emit("closeWaitDlg");
1218
+ }
1219
+
1220
+ //#endregion
1221
+ //#region src/utils/message.ts
1222
+ function messageError(text, timeout) {
1223
+ eventBus.emit("message", {
1224
+ type: "error",
1225
+ text,
1226
+ timeout
1227
+ });
1228
+ }
1229
+ function messageInfo(text, timeout) {
1230
+ eventBus.emit("message", {
1231
+ type: "info",
1232
+ text,
1233
+ timeout
1234
+ });
1235
+ }
1236
+ function messageSuccess(text, timeout) {
1237
+ eventBus.emit("message", {
1238
+ type: "success",
1239
+ text,
1240
+ timeout
1241
+ });
1242
+ }
1243
+ function messageWarning(text, timeout) {
1244
+ eventBus.emit("message", {
1245
+ type: "warning",
1246
+ text,
1247
+ timeout
1248
+ });
1249
+ }
1250
+
1217
1251
  //#endregion
1218
1252
  //#region src/utils/provideInject.ts
1219
1253
  function provideDark(dark) {
@@ -2418,4 +2452,4 @@ async function loadLocaleMessageEssential(locale) {
2418
2452
  var src_default = { install };
2419
2453
 
2420
2454
  //#endregion
2421
- export { Permission, addView, allPermissionMetas, appAppear, categories, clearViews, closeWaitDlg, createAxios, src_default as default, delView, eventBus, getCategoryPermissionMetas, getErrorMessage, getPermissionMeta, getTypeColor, getTypeDefault, globalObjects, groups, hasView, injectDark, injectLocale, injectPermissionObjects, injectViews, isEmpty, isExist, lastView, layers, loadLocaleMessageEssential, matchRouteMeta, messageError, messageInfo, messageSuccess, messageWarning, onBeforeEnter, openConfirmDlg, openNumberDlg, openPromptDlg, openWaitDlg, planes, popView, provideDark, provideLocale, providePermissionObjects, provideViews, routeTransName, toPermissionObjects, types, useColor, useGlobalStates, useMicroApp, usePageRoute, usePermission, useSystem, useViewStack, verifyPermission, waitMs, waitUtil };
2455
+ export { Permission, addView, allPermissionMetas, appAppear, categories, clearViews, closeWaitDlg, createAxios, src_default as default, delView, email, eventBus, getCategoryPermissionMetas, getErrorMessage, getPermissionMeta, getTypeColor, getTypeDefault, globalObjects, groups, hasView, injectDark, injectLocale, injectPermissionObjects, injectViews, isEmpty, isExist, lastView, layers, length, loadLocaleMessageEssential, matchRouteMeta, maxLength, messageError, messageInfo, messageSuccess, messageWarning, minLength, onBeforeEnter, openConfirmDlg, openNumberDlg, openPromptDlg, openWaitDlg, planes, popView, provideDark, provideLocale, providePermissionObjects, provideViews, required, routeTransName, toPermissionObjects, types, useColor, useGlobalStates, useMicroApp, usePageRoute, usePermission, useSystem, useViewStack, verifyPermission, waitMs, waitUtil };