@cbjwwwcode/common 0.0.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/es/api.d.mts +14 -0
- package/dist/es/api.mjs +26 -0
- package/dist/es/common.d.mts +20 -0
- package/dist/es/common.mjs +112 -0
- package/dist/es/crypto.d.mts +5 -0
- package/dist/es/crypto.mjs +7 -0
- package/dist/es/dayjs.d.mts +7 -0
- package/dist/es/dayjs.mjs +47 -0
- package/dist/es/es-toolkit.d.mts +3 -0
- package/dist/es/es-toolkit.mjs +3 -0
- package/dist/es/idb-keyval.d.mts +16 -0
- package/dist/es/idb-keyval.mjs +63 -0
- package/dist/es/index.d.mts +21 -0
- package/dist/es/index.mjs +21 -0
- package/dist/es/loader.d.mts +6 -0
- package/dist/es/loader.mjs +44 -0
- package/dist/es/lowlight/common.mjs +81 -0
- package/dist/es/lowlight/hljs.d.mts +2 -0
- package/dist/es/lowlight/hljs.mjs +9 -0
- package/dist/es/lowlight/index.d.mts +159 -0
- package/dist/es/lowlight/index.mjs +16 -0
- package/dist/es/lowlight/lowlights.d.mts +66 -0
- package/dist/es/lowlight/lowlights.mjs +153 -0
- package/dist/es/nprogress.d.mts +5 -0
- package/dist/es/nprogress.mjs +16 -0
- package/dist/es/toastify.d.mts +7 -0
- package/dist/es/toastify.mjs +13 -0
- package/dist/es/vee-validate.d.mts +2 -0
- package/dist/es/vee-validate.mjs +2 -0
- package/dist/es/vtj/index.d.mts +3 -0
- package/dist/es/vtj/index.mjs +3 -0
- package/dist/es/vtj/node.d.mts +33 -0
- package/dist/es/vtj/node.mjs +70 -0
- package/dist/es/vtj/provider.d.mts +32 -0
- package/dist/es/vtj/provider.mjs +65 -0
- package/dist/es/vtj/request.d.mts +2 -0
- package/dist/es/vtj/request.mjs +22 -0
- package/dist/es/vtj/service.mjs +63 -0
- package/dist/es/vtj/stores.d.mts +11 -0
- package/dist/es/vtj/stores.mjs +103 -0
- package/dist/es/vue-router.d.mts +2 -0
- package/dist/es/vue-router.mjs +2 -0
- package/dist/es/vue.d.mts +2 -0
- package/dist/es/vue.mjs +2 -0
- package/dist/es/vueuse.d.mts +3 -0
- package/dist/es/vueuse.mjs +3 -0
- package/dist/es/window.d.mts +6 -0
- package/dist/es/window.mjs +39 -0
- package/dist/es/zod.d.mts +2 -0
- package/dist/es/zod.mjs +2 -0
- package/dist/umd/common.min.js +371 -0
- package/dist/umd/common.min.js.map +1 -0
- package/dist/umd/style.css +59 -0
- package/package.json +89 -0
- package/src/api.ts +83 -0
- package/src/common.ts +201 -0
- package/src/crypto.ts +7 -0
- package/src/dayjs.ts +60 -0
- package/src/es-toolkit.ts +4 -0
- package/src/highlight.ts +0 -0
- package/src/idb-keyval.ts +115 -0
- package/src/index.ts +20 -0
- package/src/loader.ts +62 -0
- package/src/lowlight/common.ts +79 -0
- package/src/lowlight/hljs.ts +11 -0
- package/src/lowlight/index.ts +22 -0
- package/src/lowlight/lowlights.ts +231 -0
- package/src/nprogress.ts +20 -0
- package/src/sortablejs.ts +1 -0
- package/src/tippy.ts +3 -0
- package/src/toastify.ts +19 -0
- package/src/vee-validate.ts +1 -0
- package/src/vtj/index.ts +2 -0
- package/src/vtj/node.ts +158 -0
- package/src/vtj/provider.ts +113 -0
- package/src/vtj/request.ts +34 -0
- package/src/vtj/service.ts +93 -0
- package/src/vtj/stores.ts +144 -0
- package/src/vue-router.ts +1 -0
- package/src/vue.ts +3 -0
- package/src/vueuse.ts +13 -0
- package/src/window.ts +60 -0
- package/src/zod.ts +1 -0
package/src/loader.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { UseScriptTagOptions } from '@vueuse/core';
|
|
2
|
+
|
|
3
|
+
import { useScriptTag } from '@vueuse/core';
|
|
4
|
+
|
|
5
|
+
import { md5 } from './crypto';
|
|
6
|
+
import { loadJsStore } from './idb-keyval';
|
|
7
|
+
|
|
8
|
+
export async function loaderScript(
|
|
9
|
+
cdnUrl: string,
|
|
10
|
+
onLoaded?: (el: HTMLScriptElement) => void,
|
|
11
|
+
options?: UseScriptTagOptions,
|
|
12
|
+
) {
|
|
13
|
+
const { load } = useScriptTag(cdnUrl, onLoaded, {
|
|
14
|
+
attrs: { id: `remoteJs-${md5(cdnUrl)}` },
|
|
15
|
+
immediate: false,
|
|
16
|
+
...options,
|
|
17
|
+
});
|
|
18
|
+
await load();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function useStyleLink(
|
|
22
|
+
link: string,
|
|
23
|
+
onLoaded?: (el: Element) => void,
|
|
24
|
+
) {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const linkId = `remoteCss-${md5(link)}`;
|
|
27
|
+
let el = document.querySelector<HTMLLinkElement>(`#${linkId}`);
|
|
28
|
+
let shouldAppend = false;
|
|
29
|
+
if (!el) {
|
|
30
|
+
el = document.createElement('link');
|
|
31
|
+
el.setAttribute('rel', 'stylesheet');
|
|
32
|
+
el.setAttribute('id', linkId);
|
|
33
|
+
el.setAttribute('href', link);
|
|
34
|
+
shouldAppend = true;
|
|
35
|
+
}
|
|
36
|
+
el.addEventListener('error', (event: any) => reject(event));
|
|
37
|
+
el.addEventListener('abort', (event: any) => reject(event));
|
|
38
|
+
el.addEventListener('load', () => {
|
|
39
|
+
onLoaded?.(el);
|
|
40
|
+
resolve(el);
|
|
41
|
+
});
|
|
42
|
+
if (shouldAppend) {
|
|
43
|
+
document.head.append(el);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function loadRemoteModule(moduleName: string, url: string) {
|
|
49
|
+
const cacheId = `${moduleName}-${md5(url)}`;
|
|
50
|
+
const content = await loadJsStore(cacheId, async () => {
|
|
51
|
+
// 发送 HTTP GET 请求获取模块
|
|
52
|
+
const response = await fetch(url);
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
throw new Error(`无法加载远程模块: ${response.statusText}`);
|
|
55
|
+
}
|
|
56
|
+
return await response.text();
|
|
57
|
+
});
|
|
58
|
+
return new Function('module', 'exports', `${content}\nreturn exports;`)(
|
|
59
|
+
{ exports: {} },
|
|
60
|
+
{},
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import arduino from 'highlight.js/lib/languages/arduino';
|
|
2
|
+
import bash from 'highlight.js/lib/languages/bash';
|
|
3
|
+
import c from 'highlight.js/lib/languages/c';
|
|
4
|
+
import cpp from 'highlight.js/lib/languages/cpp';
|
|
5
|
+
import csharp from 'highlight.js/lib/languages/csharp';
|
|
6
|
+
import css from 'highlight.js/lib/languages/css';
|
|
7
|
+
import diff from 'highlight.js/lib/languages/diff';
|
|
8
|
+
import go from 'highlight.js/lib/languages/go';
|
|
9
|
+
import graphql from 'highlight.js/lib/languages/graphql';
|
|
10
|
+
import ini from 'highlight.js/lib/languages/ini';
|
|
11
|
+
import java from 'highlight.js/lib/languages/java';
|
|
12
|
+
import javascript from 'highlight.js/lib/languages/javascript';
|
|
13
|
+
import json from 'highlight.js/lib/languages/json';
|
|
14
|
+
import kotlin from 'highlight.js/lib/languages/kotlin';
|
|
15
|
+
import less from 'highlight.js/lib/languages/less';
|
|
16
|
+
import lua from 'highlight.js/lib/languages/lua';
|
|
17
|
+
import makefile from 'highlight.js/lib/languages/makefile';
|
|
18
|
+
import markdown from 'highlight.js/lib/languages/markdown';
|
|
19
|
+
import objectivec from 'highlight.js/lib/languages/objectivec';
|
|
20
|
+
import perl from 'highlight.js/lib/languages/perl';
|
|
21
|
+
import php from 'highlight.js/lib/languages/php';
|
|
22
|
+
import phpTemplate from 'highlight.js/lib/languages/php-template';
|
|
23
|
+
import plaintext from 'highlight.js/lib/languages/plaintext';
|
|
24
|
+
import python from 'highlight.js/lib/languages/python';
|
|
25
|
+
import pythonRepl from 'highlight.js/lib/languages/python-repl';
|
|
26
|
+
import r from 'highlight.js/lib/languages/r';
|
|
27
|
+
import ruby from 'highlight.js/lib/languages/ruby';
|
|
28
|
+
import rust from 'highlight.js/lib/languages/rust';
|
|
29
|
+
import scss from 'highlight.js/lib/languages/scss';
|
|
30
|
+
import shell from 'highlight.js/lib/languages/shell';
|
|
31
|
+
import sql from 'highlight.js/lib/languages/sql';
|
|
32
|
+
import swift from 'highlight.js/lib/languages/swift';
|
|
33
|
+
import typescript from 'highlight.js/lib/languages/typescript';
|
|
34
|
+
import vbnet from 'highlight.js/lib/languages/vbnet';
|
|
35
|
+
import wasm from 'highlight.js/lib/languages/wasm';
|
|
36
|
+
import xml from 'highlight.js/lib/languages/xml';
|
|
37
|
+
import yaml from 'highlight.js/lib/languages/yaml';
|
|
38
|
+
|
|
39
|
+
export const grammars = {
|
|
40
|
+
arduino,
|
|
41
|
+
bash,
|
|
42
|
+
c,
|
|
43
|
+
cpp,
|
|
44
|
+
csharp,
|
|
45
|
+
css,
|
|
46
|
+
diff,
|
|
47
|
+
go,
|
|
48
|
+
graphql,
|
|
49
|
+
html: xml,
|
|
50
|
+
ini,
|
|
51
|
+
java,
|
|
52
|
+
javascript,
|
|
53
|
+
json,
|
|
54
|
+
kotlin,
|
|
55
|
+
less,
|
|
56
|
+
lua,
|
|
57
|
+
makefile,
|
|
58
|
+
markdown,
|
|
59
|
+
objectivec,
|
|
60
|
+
perl,
|
|
61
|
+
php,
|
|
62
|
+
'php-template': phpTemplate,
|
|
63
|
+
plaintext,
|
|
64
|
+
text: plaintext,
|
|
65
|
+
python,
|
|
66
|
+
'python-repl': pythonRepl,
|
|
67
|
+
r,
|
|
68
|
+
ruby,
|
|
69
|
+
rust,
|
|
70
|
+
scss,
|
|
71
|
+
shell,
|
|
72
|
+
sql,
|
|
73
|
+
swift,
|
|
74
|
+
typescript,
|
|
75
|
+
vbnet,
|
|
76
|
+
wasm,
|
|
77
|
+
xml,
|
|
78
|
+
yaml,
|
|
79
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import hljs from 'highlight.js/lib/core';
|
|
2
|
+
|
|
3
|
+
import { grammars } from './common';
|
|
4
|
+
|
|
5
|
+
Object.entries(grammars).forEach(([lang, languageFn]) => {
|
|
6
|
+
if (Reflect.has(grammars, lang)) {
|
|
7
|
+
hljs.registerLanguage(lang, languageFn);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export default hljs;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { grammars } from './common';
|
|
2
|
+
import { createLowlight } from './lowlights.ts';
|
|
3
|
+
|
|
4
|
+
import 'highlight.js/styles/atom-one-dark.min.css';
|
|
5
|
+
|
|
6
|
+
import { default as hljs } from './hljs';
|
|
7
|
+
export const highlightLanguages = Object.keys(grammars);
|
|
8
|
+
export const lowlight = createLowlight(grammars);
|
|
9
|
+
export const VueLowlight = {
|
|
10
|
+
hljs,
|
|
11
|
+
common: grammars,
|
|
12
|
+
all: grammars,
|
|
13
|
+
createLowlight,
|
|
14
|
+
highlightLanguages
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
hljs
|
|
18
|
+
}
|
|
19
|
+
export type Lowlight = typeof lowlight;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import HighlightJs from './hljs';
|
|
2
|
+
|
|
3
|
+
const emptyOptions: Record<string, any> = {};
|
|
4
|
+
|
|
5
|
+
const defaultPrefix = 'hljs-';
|
|
6
|
+
|
|
7
|
+
export function createLowlight(grammars: any) {
|
|
8
|
+
const high = HighlightJs.newInstance();
|
|
9
|
+
|
|
10
|
+
if (grammars) {
|
|
11
|
+
register(grammars);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function highlight(language: any, value: any, options: any) {
|
|
15
|
+
// assert(typeof language === 'string', 'expected `string` as `name`')
|
|
16
|
+
// assert(typeof value === 'string', 'expected `string` as `value`')
|
|
17
|
+
const settings = options || emptyOptions;
|
|
18
|
+
const prefix =
|
|
19
|
+
typeof settings.prefix === 'string' ? settings.prefix : defaultPrefix;
|
|
20
|
+
|
|
21
|
+
if (!high.getLanguage(language)) {
|
|
22
|
+
throw new Error(`Unknown language: \`${language}\` is not registered`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// See: <https://github.com/highlightjs/highlight.js/issues/3621#issuecomment-1528841888>
|
|
26
|
+
high.configure({ __emitter: HastEmitter, classPrefix: prefix });
|
|
27
|
+
|
|
28
|
+
const result: any =
|
|
29
|
+
/** @type {HighlightResult & { _emitter: HastEmitter }} */ high.highlight(
|
|
30
|
+
value,
|
|
31
|
+
{
|
|
32
|
+
ignoreIllegals: true,
|
|
33
|
+
language,
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// `highlight.js` seems to use this (currently) for broken grammars, so let’s
|
|
38
|
+
// keep it in there just to be sure.
|
|
39
|
+
/* c8 ignore next 5 */
|
|
40
|
+
if (result.errorRaised) {
|
|
41
|
+
throw new Error('Could not highlight with `Highlight.js`', {
|
|
42
|
+
cause: result.errorRaised,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const root = result._emitter.root;
|
|
47
|
+
|
|
48
|
+
// Cast because it is always defined.
|
|
49
|
+
const data = /** @type {RootData} */ root.data;
|
|
50
|
+
|
|
51
|
+
data.language = result.language;
|
|
52
|
+
data.relevance = result.relevance;
|
|
53
|
+
|
|
54
|
+
return root;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function highlightAuto(value: any, options: any) {
|
|
58
|
+
// assert(typeof value === 'string', 'expected `string` as `value`')
|
|
59
|
+
const settings = options || emptyOptions;
|
|
60
|
+
const subset = settings.subset || listLanguages();
|
|
61
|
+
|
|
62
|
+
let index = -1;
|
|
63
|
+
let relevance = 0;
|
|
64
|
+
/** @type {Root | undefined} */
|
|
65
|
+
let result;
|
|
66
|
+
|
|
67
|
+
while (++index < subset.length) {
|
|
68
|
+
const name = subset[index];
|
|
69
|
+
|
|
70
|
+
if (!high.getLanguage(name)) continue;
|
|
71
|
+
|
|
72
|
+
const current = highlight(name, value, options);
|
|
73
|
+
|
|
74
|
+
if (
|
|
75
|
+
current.data &&
|
|
76
|
+
current.data.relevance !== undefined &&
|
|
77
|
+
current.data.relevance > relevance
|
|
78
|
+
) {
|
|
79
|
+
relevance = current.data.relevance;
|
|
80
|
+
result = current;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
result || {
|
|
86
|
+
type: 'root',
|
|
87
|
+
children: [],
|
|
88
|
+
data: { language: undefined, relevance },
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function listLanguages() {
|
|
94
|
+
return high.listLanguages();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function register(grammarsOrName: any, grammar?: any) {
|
|
98
|
+
if (typeof grammarsOrName === 'string') {
|
|
99
|
+
// assert(grammar !== undefined, 'expected `grammar`')
|
|
100
|
+
high.registerLanguage(grammarsOrName, grammar);
|
|
101
|
+
} else {
|
|
102
|
+
/** @type {string} */
|
|
103
|
+
let name;
|
|
104
|
+
|
|
105
|
+
for (name in grammarsOrName) {
|
|
106
|
+
if (grammarsOrName[name]) {
|
|
107
|
+
high.registerLanguage(name, grammarsOrName[name]);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function registerAlias(aliasesOrName: any, alias: any) {
|
|
114
|
+
if (typeof aliasesOrName === 'string') {
|
|
115
|
+
// assert(alias !== undefined)
|
|
116
|
+
high.registerAliases(
|
|
117
|
+
// Note: copy needed because hljs doesn’t accept readonly arrays yet.
|
|
118
|
+
typeof alias === 'string' ? alias : [...alias],
|
|
119
|
+
{ languageName: aliasesOrName },
|
|
120
|
+
);
|
|
121
|
+
} else {
|
|
122
|
+
/** @type {string} */
|
|
123
|
+
let key;
|
|
124
|
+
|
|
125
|
+
for (key in aliasesOrName) {
|
|
126
|
+
if (aliasesOrName[key]) {
|
|
127
|
+
const aliases = aliasesOrName[key];
|
|
128
|
+
high.registerAliases(
|
|
129
|
+
// Note: copy needed because hljs doesn’t accept readonly arrays yet.
|
|
130
|
+
typeof aliases === 'string' ? aliases : [...aliases],
|
|
131
|
+
{ languageName: key },
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function registered(aliasOrName: any) {
|
|
139
|
+
return Boolean(high.getLanguage(aliasOrName));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
...high,
|
|
144
|
+
highlight,
|
|
145
|
+
highlightAuto,
|
|
146
|
+
listLanguages,
|
|
147
|
+
register,
|
|
148
|
+
registerAlias,
|
|
149
|
+
registered,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
class HastEmitter {
|
|
154
|
+
options: any;
|
|
155
|
+
root: Record<string, any>;
|
|
156
|
+
stack: any[] = [];
|
|
157
|
+
constructor(options: any) {
|
|
158
|
+
this.options = options;
|
|
159
|
+
this.root = {
|
|
160
|
+
type: 'root',
|
|
161
|
+
children: [],
|
|
162
|
+
data: { language: undefined, relevance: 0 },
|
|
163
|
+
};
|
|
164
|
+
this.stack = [this.root];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
__addSublanguage(other: any, name: any) {
|
|
168
|
+
const current = this.stack[this.stack.length - 1];
|
|
169
|
+
// Assume only element content.
|
|
170
|
+
const results = other.root.children;
|
|
171
|
+
if (name) {
|
|
172
|
+
current.children.push({
|
|
173
|
+
type: 'element',
|
|
174
|
+
tagName: 'span',
|
|
175
|
+
properties: { className: [name] },
|
|
176
|
+
children: results,
|
|
177
|
+
});
|
|
178
|
+
} else {
|
|
179
|
+
current.children.push(...results);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
addText(value: any) {
|
|
184
|
+
if (value === '') return;
|
|
185
|
+
const current = this.stack[this.stack.length - 1];
|
|
186
|
+
const tail = current.children[current.children.length - 1];
|
|
187
|
+
|
|
188
|
+
if (tail && tail.type === 'text') {
|
|
189
|
+
tail.value += value;
|
|
190
|
+
} else {
|
|
191
|
+
current.children.push({ type: 'text', value });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
closeNode() {
|
|
196
|
+
this.stack.pop();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
endScope() {
|
|
200
|
+
this.closeNode();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
finalize() {}
|
|
204
|
+
|
|
205
|
+
openNode(name: string) {
|
|
206
|
+
// First “class” gets the prefix. Rest gets a repeated underscore suffix.
|
|
207
|
+
// See: <https://github.com/highlightjs/highlight.js/commit/51806aa>
|
|
208
|
+
// See: <https://github.com/wooorm/lowlight/issues/43>
|
|
209
|
+
const className = name.split('.').map((d, i) => {
|
|
210
|
+
return i ? d + '_'.repeat(i) : this.options.classPrefix + d;
|
|
211
|
+
});
|
|
212
|
+
const current = this.stack[this.stack.length - 1];
|
|
213
|
+
const child = {
|
|
214
|
+
type: 'element',
|
|
215
|
+
tagName: 'span',
|
|
216
|
+
properties: { className },
|
|
217
|
+
children: [],
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
current.children.push(child);
|
|
221
|
+
this.stack.push(child);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
startScope(rawName: any) {
|
|
225
|
+
this.openNode(String(rawName));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
toHTML() {
|
|
229
|
+
return '';
|
|
230
|
+
}
|
|
231
|
+
}
|
package/src/nprogress.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import type { NProgressOptions } from 'nprogress';
|
|
3
|
+
import nProgress from 'nprogress';
|
|
4
|
+
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const options: Partial<NProgressOptions> = {
|
|
7
|
+
minimum: 0.1, // 初始最小进度
|
|
8
|
+
showSpinner: false, // 关闭右上角旋转loading(推荐false)
|
|
9
|
+
speed: 300, // 动画时长 ms
|
|
10
|
+
trickle: true, // 是否自动递增
|
|
11
|
+
trickleRate: 0.02,
|
|
12
|
+
trickleSpeed: 800,
|
|
13
|
+
}
|
|
14
|
+
const progress = nProgress.configure(options)
|
|
15
|
+
export function useProgress(options?: Partial<NProgressOptions>){
|
|
16
|
+
if (options){ progress.configure(options) }
|
|
17
|
+
return progress
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { type NProgress, type NProgressOptions } from 'nprogress';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// export { default as Sortable, type SortableOptions } from 'sortablejs';
|
package/src/tippy.ts
ADDED
package/src/toastify.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { App } from 'vue';
|
|
2
|
+
|
|
3
|
+
import Toastify, { toast } from 'vue3-toastify';
|
|
4
|
+
|
|
5
|
+
export { toast };
|
|
6
|
+
|
|
7
|
+
export type { Toast, ToastOptions } from 'vue3-toastify';
|
|
8
|
+
|
|
9
|
+
export function setupToast(app: App, useHandler?: (app: App) => void) {
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
app.use(Toastify, {
|
|
12
|
+
theme: 'colored',
|
|
13
|
+
autoClose: 2000,
|
|
14
|
+
useHandler,
|
|
15
|
+
});
|
|
16
|
+
app.provide('toast', toast);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export * as ToastApi from 'vue3-toastify';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as VeeValidate from 'vee-validate';
|
package/src/vtj/index.ts
ADDED
package/src/vtj/node.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ApiSchema,
|
|
3
|
+
BlockSchema,
|
|
4
|
+
Dependencie,
|
|
5
|
+
MetaSchema,
|
|
6
|
+
ProjectSchema
|
|
7
|
+
} from '@vtj/core';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
computed,
|
|
11
|
+
getCurrentInstance,
|
|
12
|
+
inject,
|
|
13
|
+
onBeforeUnmount,
|
|
14
|
+
onMounted,
|
|
15
|
+
provide,
|
|
16
|
+
ref,
|
|
17
|
+
shallowReactive,
|
|
18
|
+
shallowRef
|
|
19
|
+
} from 'vue';
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
createFunction,
|
|
23
|
+
loaderScript,
|
|
24
|
+
md5,
|
|
25
|
+
useStyleLink,
|
|
26
|
+
} from '../index';
|
|
27
|
+
|
|
28
|
+
import { useGlobalProvider } from './provider';
|
|
29
|
+
// import { parseVue } from "@vtj/parser";
|
|
30
|
+
|
|
31
|
+
export interface JsonNodeProps {
|
|
32
|
+
apis?: ApiSchema[];
|
|
33
|
+
assets?: {
|
|
34
|
+
css: string[];
|
|
35
|
+
js: string[];
|
|
36
|
+
script: string[];
|
|
37
|
+
};
|
|
38
|
+
blocks?: BlockSchema[];
|
|
39
|
+
dependencies?: Dependencie[];
|
|
40
|
+
id?: string;
|
|
41
|
+
meta?: MetaSchema[];
|
|
42
|
+
mock?: boolean;
|
|
43
|
+
mode?: 'Design' | 'Raw' | 'Runtime' | 'VNode';
|
|
44
|
+
refreshKey?: string;
|
|
45
|
+
schema?: BlockSchema;
|
|
46
|
+
url?: string;
|
|
47
|
+
sources?: string
|
|
48
|
+
project?: Partial<ProjectSchema>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const setupJsonNode = function (props: JsonNodeProps) {
|
|
52
|
+
const schema = shallowRef({});
|
|
53
|
+
// const sfcId = useId()
|
|
54
|
+
const { proxy } = getCurrentInstance()!;
|
|
55
|
+
const cacheId = computed(() => md5(JSON.stringify(props)));
|
|
56
|
+
const refreshKey = ref(0);
|
|
57
|
+
const dsl = shallowRef<BlockSchema | null>(props.schema || null);
|
|
58
|
+
const loading = ref(false);
|
|
59
|
+
const { cacheNodes, provider, initProject } = useGlobalProvider();
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
const renderer = computed(() => schema.value?.renderer || null);
|
|
62
|
+
const assets = shallowReactive({
|
|
63
|
+
css: [],
|
|
64
|
+
js: [],
|
|
65
|
+
script: [],
|
|
66
|
+
...props.assets,
|
|
67
|
+
});
|
|
68
|
+
const removes = ref<Element[]>([]);
|
|
69
|
+
|
|
70
|
+
const loadAssets = async () => {
|
|
71
|
+
const promiseList: Promise<any>[] = [];
|
|
72
|
+
if (assets.css && assets.css.length > 0) {
|
|
73
|
+
for (const link of assets.css) {
|
|
74
|
+
promiseList.push(
|
|
75
|
+
useStyleLink(link, (el) => {
|
|
76
|
+
removes.value.push(el);
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (assets.js && assets.js.length > 0) {
|
|
82
|
+
for (const link of assets.js) {
|
|
83
|
+
promiseList.push(loaderScript(link));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (assets.script && assets.script.length > 0) {
|
|
87
|
+
for (const script of assets.script) {
|
|
88
|
+
const fnRes = createFunction(`return async ()=>{ ${script} }`, {
|
|
89
|
+
proxy,
|
|
90
|
+
});
|
|
91
|
+
if (fnRes) {
|
|
92
|
+
promiseList.push(fnRes.call({ proxy }));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (promiseList.length > 0) {
|
|
97
|
+
await Promise.all(promiseList);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
onMounted(async () => {
|
|
102
|
+
await initProject(props);
|
|
103
|
+
loading.value = true;
|
|
104
|
+
await loadAssets();
|
|
105
|
+
if (cacheNodes[cacheId.value]) {
|
|
106
|
+
schema.value = cacheNodes[cacheId.value];
|
|
107
|
+
} else {
|
|
108
|
+
if (props.url && !dsl.value) {
|
|
109
|
+
dsl.value = await provider.getDslByUrl(props.url);
|
|
110
|
+
}
|
|
111
|
+
// if (props.sources && !dsl.value){
|
|
112
|
+
// dsl.value = await parseVue({
|
|
113
|
+
// id: sfcId,
|
|
114
|
+
// name: 'SfcParse',
|
|
115
|
+
// source: props.sources,
|
|
116
|
+
// project: {
|
|
117
|
+
// id: "",
|
|
118
|
+
// name: "",
|
|
119
|
+
// ...provider.project
|
|
120
|
+
// },
|
|
121
|
+
// })
|
|
122
|
+
// console.log('sfc',dsl.value)
|
|
123
|
+
// }
|
|
124
|
+
if (dsl.value) {
|
|
125
|
+
schema.value = provider.createDslRenderer(dsl.value);
|
|
126
|
+
}
|
|
127
|
+
cacheNodes[cacheId.value] = schema.value;
|
|
128
|
+
}
|
|
129
|
+
refreshKey.value++;
|
|
130
|
+
loading.value = false;
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
onBeforeUnmount(() => {
|
|
134
|
+
if (removes.value.length > 0) {
|
|
135
|
+
removes.value.forEach((el) => {
|
|
136
|
+
el.remove();
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const store = {
|
|
142
|
+
schema,
|
|
143
|
+
renderer,
|
|
144
|
+
cacheNodes,
|
|
145
|
+
provider,
|
|
146
|
+
loading,
|
|
147
|
+
cacheId,
|
|
148
|
+
refreshKey,
|
|
149
|
+
};
|
|
150
|
+
provide('JsonNode', store);
|
|
151
|
+
return store;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
declare type JsonNodeType = ReturnType<typeof setupJsonNode>;
|
|
155
|
+
|
|
156
|
+
export const useJsonNode = () => {
|
|
157
|
+
return inject('JsonNode', null as unknown) as JsonNodeType;
|
|
158
|
+
};
|