@ftjs/core 1.0.0 → 1.1.0
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/LICENSE +21 -0
- package/dist/index.js +56 -5
- package/dist/utils.d.ts +6 -0
- package/package.json +20 -21
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 yuhengshen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.js
CHANGED
|
@@ -97,6 +97,43 @@ const setStorage = (key, value, cache) => {
|
|
|
97
97
|
localStorage.setItem(key, JSON.stringify(obj));
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
|
+
const isEqual = (a, b) => {
|
|
101
|
+
if (a === b) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
if (a == null || b == null) {
|
|
105
|
+
return a === b;
|
|
106
|
+
}
|
|
107
|
+
if (typeof a !== typeof b) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (Number.isNaN(a) && Number.isNaN(b)) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
if (typeof a !== "object") {
|
|
114
|
+
return a === b;
|
|
115
|
+
}
|
|
116
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
117
|
+
return a.length === b.length && a.every((item, index) => isEqual(item, b[index]));
|
|
118
|
+
}
|
|
119
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
if (a instanceof Date && b instanceof Date) {
|
|
123
|
+
return a.getTime() === b.getTime();
|
|
124
|
+
}
|
|
125
|
+
if (a instanceof Date || b instanceof Date) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
const keysA = Object.keys(a);
|
|
129
|
+
const keysB = Object.keys(b);
|
|
130
|
+
if (keysA.length !== keysB.length) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
return keysA.every(
|
|
134
|
+
(key) => Object.prototype.hasOwnProperty.call(b, key) && isEqual(a[key], b[key])
|
|
135
|
+
);
|
|
136
|
+
};
|
|
100
137
|
const provideFormKey = Symbol("@ftjs/core-form-provide");
|
|
101
138
|
const useFormInject = () => {
|
|
102
139
|
return inject(provideFormKey);
|
|
@@ -105,8 +142,7 @@ const useColumnsChecked = (columns, cache) => {
|
|
|
105
142
|
const storageKey = `ftjs-form-columns-checked-obj`;
|
|
106
143
|
const columnsV = computed(() => {
|
|
107
144
|
const entries = columns.value.map((e) => {
|
|
108
|
-
|
|
109
|
-
const field = e.field ?? ((_a = e.fields) == null ? void 0 : _a[0]);
|
|
145
|
+
const field = getField(e);
|
|
110
146
|
return [field, !toValue(e.hide)];
|
|
111
147
|
});
|
|
112
148
|
return Object.fromEntries(entries);
|
|
@@ -279,6 +315,8 @@ const useForm = (props) => {
|
|
|
279
315
|
const control = column.control;
|
|
280
316
|
if (!watchObj && !control) return;
|
|
281
317
|
const field = getField(column);
|
|
318
|
+
const watchArr = column.fields ?? [column.field];
|
|
319
|
+
const isSingleWatch = watchArr.length === 1;
|
|
282
320
|
const cancel = [];
|
|
283
321
|
if (typeof watchObj === "function") {
|
|
284
322
|
watchObj = {
|
|
@@ -289,9 +327,13 @@ const useForm = (props) => {
|
|
|
289
327
|
cancel.push(
|
|
290
328
|
watch(
|
|
291
329
|
() => {
|
|
292
|
-
return get(form.value,
|
|
330
|
+
return watchArr.map((f) => get(form.value, f));
|
|
293
331
|
},
|
|
294
332
|
(val, oldVal) => {
|
|
333
|
+
if (isSingleWatch) {
|
|
334
|
+
val = val == null ? void 0 : val[0];
|
|
335
|
+
oldVal = oldVal == null ? void 0 : oldVal[0];
|
|
336
|
+
}
|
|
295
337
|
watchObj.handler({ val, oldVal, form: form.value });
|
|
296
338
|
},
|
|
297
339
|
{
|
|
@@ -304,7 +346,7 @@ const useForm = (props) => {
|
|
|
304
346
|
if (control) {
|
|
305
347
|
cancel.push(
|
|
306
348
|
watch(
|
|
307
|
-
() => get(form.value,
|
|
349
|
+
() => watchArr.map((f) => get(form.value, f)),
|
|
308
350
|
(val) => {
|
|
309
351
|
control.forEach(({ field: targetField, value }) => {
|
|
310
352
|
let show = true;
|
|
@@ -314,7 +356,15 @@ const useForm = (props) => {
|
|
|
314
356
|
val
|
|
315
357
|
});
|
|
316
358
|
} else {
|
|
317
|
-
|
|
359
|
+
if (Array.isArray(value)) {
|
|
360
|
+
if (isSingleWatch) {
|
|
361
|
+
show = value.some((v) => isEqual(v, val[0]));
|
|
362
|
+
} else {
|
|
363
|
+
show = isEqual(value, val);
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
show = isEqual(value, val[0]);
|
|
367
|
+
}
|
|
318
368
|
}
|
|
319
369
|
if (!fieldControlMap.value.has(targetField)) {
|
|
320
370
|
fieldControlMap.value.set(targetField, /* @__PURE__ */ new Map());
|
|
@@ -497,6 +547,7 @@ export {
|
|
|
497
547
|
has,
|
|
498
548
|
isBrowser,
|
|
499
549
|
isEmptyStrOrNull,
|
|
550
|
+
isEqual,
|
|
500
551
|
set,
|
|
501
552
|
setStorage,
|
|
502
553
|
unrefs,
|
package/dist/utils.d.ts
CHANGED
|
@@ -29,3 +29,9 @@ export declare const getStorage: (key: string, cache?: string) => {};
|
|
|
29
29
|
* @param cache 缓存名称
|
|
30
30
|
*/
|
|
31
31
|
export declare const setStorage: (key: string, value: any, cache?: string) => void;
|
|
32
|
+
/**
|
|
33
|
+
* 简单判断两个值是否相等
|
|
34
|
+
*
|
|
35
|
+
* 不考虑循环引用
|
|
36
|
+
*/
|
|
37
|
+
export declare const isEqual: (a: any, b: any) => any;
|
package/package.json
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ftjs/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "vite build",
|
|
10
|
-
"minify": "pnpm dlx esbuild ./dist/index.js --minify --outfile=./dist/index.min.js",
|
|
11
|
-
"test": "vitest --typecheck",
|
|
12
|
-
"test:coverage": "vitest run --coverage",
|
|
13
|
-
"semantic-release": "semantic-release"
|
|
14
|
-
},
|
|
15
8
|
"exports": {
|
|
16
9
|
".": {
|
|
17
10
|
"import": "./dist/index.js",
|
|
@@ -25,20 +18,26 @@
|
|
|
25
18
|
],
|
|
26
19
|
"dependencies": {},
|
|
27
20
|
"devDependencies": {
|
|
28
|
-
"@types/node": "
|
|
29
|
-
"@vitejs/plugin-vue-jsx": "
|
|
30
|
-
"@vitest/coverage-v8": "
|
|
31
|
-
"@vitest/ui": "
|
|
32
|
-
"@vue/test-utils": "
|
|
33
|
-
"happy-dom": "
|
|
34
|
-
"typescript": "
|
|
35
|
-
"vite": "
|
|
36
|
-
"vite-plugin-dts": "
|
|
37
|
-
"vitest": "
|
|
38
|
-
"vue-tsc": "
|
|
39
|
-
"vue": "
|
|
21
|
+
"@types/node": "^22.10.9",
|
|
22
|
+
"@vitejs/plugin-vue-jsx": "^4.1.1",
|
|
23
|
+
"@vitest/coverage-v8": "^3.0.5",
|
|
24
|
+
"@vitest/ui": "^3.0.5",
|
|
25
|
+
"@vue/test-utils": "^2.4.6",
|
|
26
|
+
"happy-dom": "^17.0.2",
|
|
27
|
+
"typescript": "^5.8.3",
|
|
28
|
+
"vite": "^6.1.0",
|
|
29
|
+
"vite-plugin-dts": "^4.5.0",
|
|
30
|
+
"vitest": "^3.0.5",
|
|
31
|
+
"vue-tsc": "2.2.0",
|
|
32
|
+
"vue": "^3.5.13"
|
|
40
33
|
},
|
|
41
34
|
"peerDependencies": {
|
|
42
35
|
"vue": ">=3.3.0"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "vite build",
|
|
39
|
+
"minify": "pnpm dlx esbuild ./dist/index.js --minify --outfile=./dist/index.min.js",
|
|
40
|
+
"test": "vitest --typecheck",
|
|
41
|
+
"test:coverage": "vitest run --coverage"
|
|
43
42
|
}
|
|
44
|
-
}
|
|
43
|
+
}
|