x-essential-lib 0.1.0 → 0.1.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/.editorconfig +5 -0
- package/.eslintignore +1 -0
- package/.eslintrc.cjs +18 -0
- package/.husky/pre-commit +1 -0
- package/.prettierignore +7 -0
- package/.prettierrc +16 -0
- package/dist/index.d.ts +89 -0
- package/dist/index.js +513 -0
- package/index.html +12 -0
- package/package.json +11 -10
- package/public/index.d.ts +89 -0
- package/src/App.vue +9 -0
- package/src/components/confirmDlg/index.vue +98 -0
- package/src/components/loading/index.vue +131 -0
- package/src/components/message/index.vue +70 -0
- package/src/components/message/item.vue +75 -0
- package/src/components/promptDlg/index.vue +119 -0
- package/src/components/waitDlg/index.vue +41 -0
- package/src/index.ts +38 -0
- package/src/main.ts +5 -0
- package/src/plugins/vuetify.ts +4 -0
- package/src/utils/core.ts +31 -0
- package/src/utils/dialog.ts +87 -0
- package/src/utils/message.ts +17 -0
- package/src/utils/misc.ts +23 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +25 -0
- package/tsconfig.node.json +9 -0
- package/vite.config.ts +37 -0
- package/dist/index.es.js +0 -36
- package/types/index.d.ts +0 -2
- package/types/utils/core.d.ts +0 -3
package/src/index.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import XConfirmDlg from './components/confirmDlg/index.vue'
|
|
2
|
+
import XLoading from './components/loading/index.vue'
|
|
3
|
+
import XMessage from './components/message/index.vue'
|
|
4
|
+
import XPromptDlg from './components/promptDlg/index.vue'
|
|
5
|
+
import XWaitDlg from './components/waitDlg/index.vue'
|
|
6
|
+
import { waitMs, waitUtil } from './utils/core'
|
|
7
|
+
import {
|
|
8
|
+
openConfirmDlg,
|
|
9
|
+
openPromptDlg,
|
|
10
|
+
openWaitDlg,
|
|
11
|
+
closeWaitDlg
|
|
12
|
+
} from './utils/dialog'
|
|
13
|
+
import {
|
|
14
|
+
messageError,
|
|
15
|
+
messageInfo,
|
|
16
|
+
messageSuccess,
|
|
17
|
+
messageWarning
|
|
18
|
+
} from './utils/message'
|
|
19
|
+
import { appAppear } from './utils/misc'
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
XConfirmDlg,
|
|
23
|
+
XLoading,
|
|
24
|
+
XMessage,
|
|
25
|
+
XPromptDlg,
|
|
26
|
+
XWaitDlg,
|
|
27
|
+
waitMs,
|
|
28
|
+
waitUtil,
|
|
29
|
+
openConfirmDlg,
|
|
30
|
+
openPromptDlg,
|
|
31
|
+
openWaitDlg,
|
|
32
|
+
closeWaitDlg,
|
|
33
|
+
messageError,
|
|
34
|
+
messageInfo,
|
|
35
|
+
messageSuccess,
|
|
36
|
+
messageWarning,
|
|
37
|
+
appAppear
|
|
38
|
+
}
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import mitt from 'mitt'
|
|
2
|
+
|
|
3
|
+
export const eventBus = mitt()
|
|
4
|
+
|
|
5
|
+
export async function waitMs(ms: number): Promise<void> {
|
|
6
|
+
return new Promise(resolve => {
|
|
7
|
+
setTimeout(resolve, ms)
|
|
8
|
+
})
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function waitUtil(
|
|
12
|
+
conditionFunc: () => boolean,
|
|
13
|
+
timeout?: number,
|
|
14
|
+
interval?: number
|
|
15
|
+
): Promise<boolean> {
|
|
16
|
+
const timestamp = Date.now()
|
|
17
|
+
return new Promise((resolve: any) => {
|
|
18
|
+
const check = async () => {
|
|
19
|
+
if (conditionFunc()) {
|
|
20
|
+
resolve(true)
|
|
21
|
+
} else {
|
|
22
|
+
if (timeout && Date.now() - timestamp > timeout) {
|
|
23
|
+
resolve(false)
|
|
24
|
+
} else {
|
|
25
|
+
setTimeout(check, interval ?? 30)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
check()
|
|
30
|
+
})
|
|
31
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { eventBus, waitUtil } from './core'
|
|
2
|
+
|
|
3
|
+
let lastTime: number = Date.now()
|
|
4
|
+
|
|
5
|
+
function tryCooldown(): boolean {
|
|
6
|
+
const now = Date.now()
|
|
7
|
+
if (now - lastTime > 500) {
|
|
8
|
+
lastTime = now
|
|
9
|
+
return true
|
|
10
|
+
}
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let sequence: number = 0
|
|
15
|
+
|
|
16
|
+
function getSequence(): number {
|
|
17
|
+
return ++sequence
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface ButtonOptions {
|
|
21
|
+
color?: string
|
|
22
|
+
text?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface ConfirmParams {
|
|
26
|
+
title: string
|
|
27
|
+
text: string
|
|
28
|
+
cancel?: ButtonOptions
|
|
29
|
+
confirm?: ButtonOptions
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function openConfirmDlg(
|
|
33
|
+
params: ConfirmParams
|
|
34
|
+
): Promise<boolean | undefined> {
|
|
35
|
+
if (!tryCooldown()) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
let resp: boolean = false
|
|
39
|
+
let result: boolean | undefined
|
|
40
|
+
const onResult = (res: unknown) => {
|
|
41
|
+
result = res as boolean
|
|
42
|
+
resp = true
|
|
43
|
+
}
|
|
44
|
+
const seq = getSequence()
|
|
45
|
+
eventBus.on('confirmDlgResult' + seq, onResult)
|
|
46
|
+
eventBus.emit('confirmDlg', { ...params, seq })
|
|
47
|
+
await waitUtil(() => resp)
|
|
48
|
+
eventBus.off('confirmDlgResult' + seq, onResult)
|
|
49
|
+
return result
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface PromptParams {
|
|
53
|
+
title: string
|
|
54
|
+
text?: string
|
|
55
|
+
label?: string
|
|
56
|
+
placeholder?: string
|
|
57
|
+
rules?: ((val: string) => string | boolean)[]
|
|
58
|
+
value?: string
|
|
59
|
+
cancel?: ButtonOptions
|
|
60
|
+
confirm?: ButtonOptions
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function openPromptDlg(params: PromptParams): Promise<any> {
|
|
64
|
+
if (!tryCooldown()) {
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
let resp: boolean = false
|
|
68
|
+
let result: any
|
|
69
|
+
const onResult = (res: any) => {
|
|
70
|
+
result = res
|
|
71
|
+
resp = true
|
|
72
|
+
}
|
|
73
|
+
const seq = getSequence()
|
|
74
|
+
eventBus.on('promptDlgResult' + seq, onResult)
|
|
75
|
+
eventBus.emit('promptDlg', { ...params, seq })
|
|
76
|
+
await waitUtil(() => resp)
|
|
77
|
+
eventBus.off('promptDlgResult' + seq, onResult)
|
|
78
|
+
return result
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function openWaitDlg() {
|
|
82
|
+
eventBus.emit('openWaitDlg')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function closeWaitDlg() {
|
|
86
|
+
eventBus.emit('closeWaitDlg')
|
|
87
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { eventBus } from './core'
|
|
2
|
+
|
|
3
|
+
export function messageError(text: string, timeout?: number) {
|
|
4
|
+
eventBus.emit('message', { type: 'error', text, timeout })
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function messageInfo(text: string, timeout?: number) {
|
|
8
|
+
eventBus.emit('message', { type: 'info', text, timeout })
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function messageSuccess(text: string, timeout?: number) {
|
|
12
|
+
eventBus.emit('message', { type: 'success', text, timeout })
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function messageWarning(text: string, timeout?: number) {
|
|
16
|
+
eventBus.emit('message', { type: 'warning', text, timeout })
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare let window: any
|
|
2
|
+
|
|
3
|
+
export function appAppear(name: string) {
|
|
4
|
+
// 忽略第一次动画
|
|
5
|
+
if (!window.appAppear) {
|
|
6
|
+
window.appAppear = true
|
|
7
|
+
return
|
|
8
|
+
}
|
|
9
|
+
const fullname = 'single-spa-application:' + name
|
|
10
|
+
const classList = document.getElementById(fullname)?.classList
|
|
11
|
+
if (!classList) {
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
classList.remove('app-left', 'app-right', 'app-reset')
|
|
15
|
+
if (window.routeExtras?.forward) {
|
|
16
|
+
classList.add('app-left')
|
|
17
|
+
} else {
|
|
18
|
+
classList.add('app-right')
|
|
19
|
+
}
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
classList.add('app-reset')
|
|
22
|
+
}, 0)
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
/* Bundler mode */
|
|
10
|
+
"moduleResolution": "Node",
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"jsx": "preserve",
|
|
16
|
+
|
|
17
|
+
/* Linting */
|
|
18
|
+
"strict": true,
|
|
19
|
+
"noUnusedLocals": true,
|
|
20
|
+
"noUnusedParameters": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true
|
|
22
|
+
},
|
|
23
|
+
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
|
|
24
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
25
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import { fileURLToPath, URL } from 'node:url'
|
|
3
|
+
import vue from '@vitejs/plugin-vue'
|
|
4
|
+
import cssInjectedByJs from 'vite-plugin-css-injected-by-js'
|
|
5
|
+
|
|
6
|
+
// https://vitejs.dev/config/
|
|
7
|
+
export default () => {
|
|
8
|
+
return defineConfig({
|
|
9
|
+
plugins: [vue(), cssInjectedByJs()],
|
|
10
|
+
define: { 'process.env': {} },
|
|
11
|
+
resolve: {
|
|
12
|
+
alias: {
|
|
13
|
+
'@': fileURLToPath(new URL('./src', import.meta.url))
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
server: {
|
|
17
|
+
port: 3333
|
|
18
|
+
},
|
|
19
|
+
build: {
|
|
20
|
+
lib: {
|
|
21
|
+
entry: 'src/index.ts',
|
|
22
|
+
formats: ['es'],
|
|
23
|
+
fileName: 'index'
|
|
24
|
+
},
|
|
25
|
+
rollupOptions: {
|
|
26
|
+
external: ['vue', 'vuetify'],
|
|
27
|
+
output: {
|
|
28
|
+
globals: {
|
|
29
|
+
vue: 'Vue',
|
|
30
|
+
vuetify: 'Vuetify'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
emptyOutDir: true
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
}
|
package/dist/index.es.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
function o(i) {
|
|
2
|
-
return { all: i = i || /* @__PURE__ */ new Map(), on: function(t, n) {
|
|
3
|
-
var e = i.get(t);
|
|
4
|
-
e ? e.push(n) : i.set(t, [n]);
|
|
5
|
-
}, off: function(t, n) {
|
|
6
|
-
var e = i.get(t);
|
|
7
|
-
e && (n ? e.splice(e.indexOf(n) >>> 0, 1) : i.set(t, []));
|
|
8
|
-
}, emit: function(t, n) {
|
|
9
|
-
var e = i.get(t);
|
|
10
|
-
e && e.slice().map(function(s) {
|
|
11
|
-
s(n);
|
|
12
|
-
}), (e = i.get("*")) && e.slice().map(function(s) {
|
|
13
|
-
s(t, n);
|
|
14
|
-
});
|
|
15
|
-
} };
|
|
16
|
-
}
|
|
17
|
-
const a = o();
|
|
18
|
-
async function u(i) {
|
|
19
|
-
return new Promise((t) => {
|
|
20
|
-
setTimeout(t, i);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
async function f(i, t, n) {
|
|
24
|
-
const e = Date.now();
|
|
25
|
-
return new Promise((s) => {
|
|
26
|
-
const c = async () => {
|
|
27
|
-
i() ? s(!0) : t && Date.now() - e > t ? s(!1) : setTimeout(c, n ?? 30);
|
|
28
|
-
};
|
|
29
|
-
c();
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
export {
|
|
33
|
-
a as eventBus,
|
|
34
|
-
u as waitMs,
|
|
35
|
-
f as waitUtil
|
|
36
|
-
};
|
package/types/index.d.ts
DELETED
package/types/utils/core.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare const eventBus: import("mitt").Emitter<Record<import("mitt").EventType, unknown>>;
|
|
2
|
-
export declare function waitMs(ms: number): Promise<void>;
|
|
3
|
-
export declare function waitUtil(conditionFunc: () => boolean, timeout?: number, interval?: number): Promise<boolean>;
|