@cbjwwwcode/common 0.0.6 → 0.0.8
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/copy.d.mts +14 -0
- package/dist/es/copy.mjs +38 -0
- package/dist/es/format.d.mts +5 -0
- package/dist/es/format.mjs +72 -0
- package/dist/es/index.d.mts +4 -3
- package/dist/es/index.mjs +4 -3
- package/dist/es/vtj/index.d.mts +5 -2
- package/dist/es/vtj/index.mjs +4 -1
- package/dist/es/vueuse.d.mts +2 -2
- package/dist/es/vueuse.mjs +2 -2
- package/dist/umd/common.min.js +244 -231
- package/dist/umd/common.min.js.map +1 -1
- package/package.json +2 -1
- package/src/copy.ts +56 -0
- package/src/format.ts +71 -0
- package/src/index.ts +3 -1
- package/src/vtj/index.ts +4 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/copy.d.ts
|
|
2
|
+
interface UseCopyOptions {
|
|
3
|
+
successMessage?: string;
|
|
4
|
+
errorMessage?: string;
|
|
5
|
+
showMessage?: boolean;
|
|
6
|
+
onSuccess?: (text: string) => void;
|
|
7
|
+
onError?: (error: Error) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function useCopy(options?: UseCopyOptions): {
|
|
10
|
+
copy: (text: string | number) => Promise<boolean>;
|
|
11
|
+
copied: Readonly<import("vue").ShallowRef<boolean>>;
|
|
12
|
+
isSupported: import("vue").ComputedRef<boolean>;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
package/dist/es/copy.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { toast } from "./toastify.mjs";
|
|
2
|
+
import { useClipboard } from "@vueuse/core";
|
|
3
|
+
//#region src/copy.ts
|
|
4
|
+
function useCopy(options = {}) {
|
|
5
|
+
const { successMessage = "复制成功", errorMessage = "复制失败", showMessage = true, onSuccess, onError } = options;
|
|
6
|
+
const { copy, copied, isSupported } = useClipboard();
|
|
7
|
+
/**
|
|
8
|
+
* 复制文本
|
|
9
|
+
*/
|
|
10
|
+
const handleCopy = async (text) => {
|
|
11
|
+
if (!isSupported.value) {
|
|
12
|
+
showMessage && toast.warning("当前环境不支持复制");
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const content = String(text ?? "");
|
|
16
|
+
if (!content) {
|
|
17
|
+
showMessage && toast.warning("复制内容为空");
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
await copy(content);
|
|
22
|
+
showMessage && toast.success(successMessage);
|
|
23
|
+
onSuccess?.(content);
|
|
24
|
+
return true;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
showMessage && toast.error(errorMessage);
|
|
27
|
+
onError?.(error);
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
copy: handleCopy,
|
|
33
|
+
copied,
|
|
34
|
+
isSupported
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { useCopy };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { isString } from "es-toolkit/compat";
|
|
2
|
+
import esthetic from "esthetic";
|
|
3
|
+
//#region src/format.ts
|
|
4
|
+
const formatMsps = /* @__PURE__ */ new Set([
|
|
5
|
+
"text",
|
|
6
|
+
"html",
|
|
7
|
+
"liquid",
|
|
8
|
+
"javascript",
|
|
9
|
+
"markdown",
|
|
10
|
+
"jsx",
|
|
11
|
+
"typescript",
|
|
12
|
+
"tsx",
|
|
13
|
+
"json",
|
|
14
|
+
"css",
|
|
15
|
+
"scss",
|
|
16
|
+
"sass",
|
|
17
|
+
"less",
|
|
18
|
+
"xml",
|
|
19
|
+
"unknown"
|
|
20
|
+
]);
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param code
|
|
24
|
+
* @param language
|
|
25
|
+
* @param rules
|
|
26
|
+
* indentSize number 缩进空格数,默认 2
|
|
27
|
+
* indentChar string 缩进字符,默认空格 " "
|
|
28
|
+
* wrap number 换行宽度控制,0 表示不自动换行
|
|
29
|
+
* preserveLine number 保留连续空行的最大数量,默认 3
|
|
30
|
+
* crlf boolean 是否使用 CRLF 换行符,默认 false
|
|
31
|
+
* endNewline boolean 文件末尾是否添加换行符
|
|
32
|
+
* markup.forceAttribute boolean 是否强制将属性换行显示(从代码片段看有这个选项)
|
|
33
|
+
* markup.attributeSort boolean 是否对 HTML 属性排序
|
|
34
|
+
*/
|
|
35
|
+
function formatCode(code, language, rules) {
|
|
36
|
+
language = isString(language) && formatMsps.has(language) ? language : language == "vue" ? "html" : "auto";
|
|
37
|
+
return esthetic.format(code, {
|
|
38
|
+
language,
|
|
39
|
+
preset: "recommended",
|
|
40
|
+
preserveLine: 0,
|
|
41
|
+
markup: {
|
|
42
|
+
attributeSort: true,
|
|
43
|
+
forceAttribute: 120,
|
|
44
|
+
quoteConvert: "double",
|
|
45
|
+
attributeCasing: "preserve",
|
|
46
|
+
selfCloseSpace: false,
|
|
47
|
+
ignoreCSS: false,
|
|
48
|
+
ignoreJS: false,
|
|
49
|
+
preserveText: false
|
|
50
|
+
},
|
|
51
|
+
script: {
|
|
52
|
+
styleGuide: "airbnb",
|
|
53
|
+
quoteConvert: "single",
|
|
54
|
+
endComma: "always",
|
|
55
|
+
variableList: "each",
|
|
56
|
+
braceStyle: "collapse",
|
|
57
|
+
noSemicolon: false
|
|
58
|
+
},
|
|
59
|
+
style: {
|
|
60
|
+
commentIndent: true,
|
|
61
|
+
preserveComment: true,
|
|
62
|
+
atRuleSpace: true,
|
|
63
|
+
sortProperties: false,
|
|
64
|
+
sortSelectors: false,
|
|
65
|
+
noLeadZero: true,
|
|
66
|
+
quoteConvert: "double"
|
|
67
|
+
},
|
|
68
|
+
...rules
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { esthetic, formatCode };
|
package/dist/es/index.d.mts
CHANGED
|
@@ -15,9 +15,10 @@ import { $mitt, axios, isModuleObject, registerWindow } from "./window.mjs";
|
|
|
15
15
|
import { zod } from "./zod.mjs";
|
|
16
16
|
import { JsonNodeProps, setupJsonNode, useJsonNode } from "./vtj/node.mjs";
|
|
17
17
|
import { BlockSchema, ContextMode, initProvider, useGlobalProvider, vtjSymbol } from "./vtj/provider.mjs";
|
|
18
|
-
import "./vtj/index.mjs";
|
|
18
|
+
import { VtjCore, VtjRenderer, VtjUtils } from "./vtj/index.mjs";
|
|
19
19
|
import hljs from "./lowlight/hljs.mjs";
|
|
20
20
|
import { Lowlight, VueLowlight, highlightLanguages, lowlight } from "./lowlight/index.mjs";
|
|
21
21
|
import { Hucre } from "./hucre.mjs";
|
|
22
|
-
import
|
|
23
|
-
|
|
22
|
+
import { useCopy } from "./copy.mjs";
|
|
23
|
+
import { FormatRule as Rules, esthetic, formatCode } from "./format.mjs";
|
|
24
|
+
export { $http, $mitt, AlovaAxiosRequestConfig, ApiConfig, type BlockSchema, ContextMode, CryptoJS, type Rules as FormatRule, Hucre, IDBKeyValReturn, IDBOptions, JsonNodeProps, Lowlight, type NProgress, type NProgressOptions, type Toast, ToastApi, type ToastOptions, Toolkit, type UseStore, VeeValidate, VtjCore, VtjRenderer, VtjUtils, Vue, VueLowlight, VueRouter, VueUse, axios, createClientTokenAuthentication, createFunction, createGlobalState, createNaiveStore, createReusableTemplate, dayjs, determineTextColor, esthetic, formatCode, hasProperty, highlightLanguages, hljs, idb, initProvider, isComponentRegistered, isHttpUrl, isModuleObject, isNotNil, isPromise, isStringNumber, keepProps, loadJsStore, loadRemoteModule, loaderScript, lowlight, makeRawComponent, makeUuid, makeVueId, md5, mergeOmitBy, mergePropsOmitBy, mergeUrlWithParams, onClickOutside, randomId, registerWindow, setDayjsLocale, setupJsonNode, setupRequest, setupToast, toast, transformPx, useCaptcha, useClipboard, useCopy, useGlobalProvider, useIdb, useJsonNode, useProgress, useRequest, useScriptTag, useStorage, useStyleLink, useStyleTag, useToggle, useUploader, vtjSymbol, zod };
|
package/dist/es/index.mjs
CHANGED
|
@@ -17,7 +17,8 @@ import { ToastApi, setupToast, toast } from "./toastify.mjs";
|
|
|
17
17
|
import { VeeValidate } from "./vee-validate.mjs";
|
|
18
18
|
import { ContextMode, initProvider, useGlobalProvider, vtjSymbol } from "./vtj/provider.mjs";
|
|
19
19
|
import { setupJsonNode, useJsonNode } from "./vtj/node.mjs";
|
|
20
|
-
import "./vtj/index.mjs";
|
|
20
|
+
import { VtjCore, VtjRenderer, VtjUtils } from "./vtj/index.mjs";
|
|
21
21
|
import { Hucre } from "./hucre.mjs";
|
|
22
|
-
import
|
|
23
|
-
|
|
22
|
+
import { useCopy } from "./copy.mjs";
|
|
23
|
+
import { esthetic, formatCode } from "./format.mjs";
|
|
24
|
+
export { $http, $mitt, ContextMode, CryptoJS, Hucre, ToastApi, Toolkit, VeeValidate, VtjCore, VtjRenderer, VtjUtils, Vue, VueLowlight, VueRouter, VueUse, axios, createClientTokenAuthentication, createFunction, createGlobalState, createNaiveStore, createReusableTemplate, dayjs, determineTextColor, esthetic, formatCode, hasProperty, highlightLanguages, hljs_default as hljs, idb, initProvider, isComponentRegistered, isHttpUrl, isModuleObject, isNotNil, isPromise, isStringNumber, keepProps, loadJsStore, loadRemoteModule, loaderScript, lowlight, makeRawComponent, makeUuid, makeVueId, md5, mergeOmitBy, mergePropsOmitBy, mergeUrlWithParams, onClickOutside, randomId, registerWindow, setDayjsLocale, setupJsonNode, setupRequest, setupToast, toast, transformPx, useCaptcha, useClipboard, useCopy, useGlobalProvider, useIdb, useJsonNode, useProgress, useRequest, useScriptTag, useStorage, useStyleLink, useStyleTag, useToggle, useUploader, vtjSymbol, zod };
|
package/dist/es/vtj/index.d.mts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { JsonNodeProps, setupJsonNode, useJsonNode } from "./node.mjs";
|
|
2
|
-
import { BlockSchema, ContextMode, initProvider, useGlobalProvider, vtjSymbol } from "./provider.mjs";
|
|
3
|
-
|
|
2
|
+
import { BlockSchema as BlockSchema$1, ContextMode, initProvider, useGlobalProvider, vtjSymbol } from "./provider.mjs";
|
|
3
|
+
import * as VtjRenderer from "@vtj/renderer";
|
|
4
|
+
import * as VtjUtils from "@vtj/utils";
|
|
5
|
+
import * as VtjCore from "@vtj/core";
|
|
6
|
+
export { type BlockSchema$1 as BlockSchema, ContextMode, JsonNodeProps, VtjCore, VtjRenderer, VtjUtils, initProvider, setupJsonNode, useGlobalProvider, useJsonNode, vtjSymbol };
|
package/dist/es/vtj/index.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { ContextMode, initProvider, useGlobalProvider, vtjSymbol } from "./provider.mjs";
|
|
2
2
|
import { setupJsonNode, useJsonNode } from "./node.mjs";
|
|
3
|
-
|
|
3
|
+
import * as VtjRenderer from "@vtj/renderer";
|
|
4
|
+
import * as VtjUtils from "@vtj/utils";
|
|
5
|
+
import * as VtjCore from "@vtj/core";
|
|
6
|
+
export { ContextMode, VtjCore, VtjRenderer, VtjUtils, initProvider, setupJsonNode, useGlobalProvider, useJsonNode, vtjSymbol };
|
package/dist/es/vueuse.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as VueUse from "@vueuse/core";
|
|
2
|
-
import { createGlobalState, createReusableTemplate, onClickOutside, useClipboard, useScriptTag as useScriptTag$1, useStorage, useStyleTag, useToggle } from "@vueuse/core";
|
|
3
|
-
export { VueUse, createGlobalState, createReusableTemplate, onClickOutside, useClipboard, useScriptTag$1 as useScriptTag, useStorage, useStyleTag, useToggle };
|
|
2
|
+
import { createGlobalState, createReusableTemplate, onClickOutside, useClipboard as useClipboard$1, useScriptTag as useScriptTag$1, useStorage, useStyleTag, useToggle } from "@vueuse/core";
|
|
3
|
+
export { VueUse, createGlobalState, createReusableTemplate, onClickOutside, useClipboard$1 as useClipboard, useScriptTag$1 as useScriptTag, useStorage, useStyleTag, useToggle };
|
package/dist/es/vueuse.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as VueUse from "@vueuse/core";
|
|
2
|
-
import { createGlobalState, createReusableTemplate, onClickOutside, useClipboard, useScriptTag as useScriptTag$1, useStorage, useStyleTag, useToggle } from "@vueuse/core";
|
|
3
|
-
export { VueUse, createGlobalState, createReusableTemplate, onClickOutside, useClipboard, useScriptTag$1 as useScriptTag, useStorage, useStyleTag, useToggle };
|
|
2
|
+
import { createGlobalState, createReusableTemplate, onClickOutside, useClipboard as useClipboard$1, useScriptTag as useScriptTag$1, useStorage, useStyleTag, useToggle } from "@vueuse/core";
|
|
3
|
+
export { VueUse, createGlobalState, createReusableTemplate, onClickOutside, useClipboard$1 as useClipboard, useScriptTag$1 as useScriptTag, useStorage, useStyleTag, useToggle };
|