v-dict 1.2.0 → 1.2.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.cjs +10 -7
- package/dist/index.js +10 -7
- package/dist/types/dict.d.ts +4 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -97,15 +97,15 @@ function createDictManager(managerOptions = {}) {
|
|
|
97
97
|
clearObj(maps);
|
|
98
98
|
}
|
|
99
99
|
function _defineDict(internalOptions, code, defineDictOptions) {
|
|
100
|
+
const { pickValues, omitValues, extendCode } = internalOptions;
|
|
100
101
|
if (maps[code]) {
|
|
101
102
|
warn(`code "${code}" already exists`);
|
|
102
103
|
}
|
|
103
|
-
const { pickValues, omitValues } = internalOptions;
|
|
104
104
|
const options = Object.assign(
|
|
105
105
|
{ data: {}, remote: false, fetch: managerFetch },
|
|
106
106
|
lodashEs.isFunction(defineDictOptions) ? defineDictOptions() : defineDictOptions
|
|
107
107
|
);
|
|
108
|
-
defineDictOptionsMap.set(code, options);
|
|
108
|
+
defineDictOptionsMap.set(code, lodashEs.cloneDeep(options));
|
|
109
109
|
const { data, remote, fetch, extra } = options;
|
|
110
110
|
const globalLoadPromise = vue.shallowRef(null);
|
|
111
111
|
maps[code] = /* @__PURE__ */ new Map();
|
|
@@ -113,7 +113,7 @@ function createDictManager(managerOptions = {}) {
|
|
|
113
113
|
var _a;
|
|
114
114
|
const dataMap = toMap(lodashEs.cloneDeep(data), { pickValues, omitValues });
|
|
115
115
|
if (remote) {
|
|
116
|
-
const res = (_a = await (fetch == null ? void 0 : fetch(code, options2))) != null ? _a : [];
|
|
116
|
+
const res = (_a = await (fetch == null ? void 0 : fetch(extendCode != null ? extendCode : code, options2))) != null ? _a : [];
|
|
117
117
|
mapRef.value = toMap(res, { pickValues, omitValues });
|
|
118
118
|
dataMap.forEach((value, key) => {
|
|
119
119
|
if (mapRef.value.has(key)) {
|
|
@@ -179,12 +179,16 @@ function createDictManager(managerOptions = {}) {
|
|
|
179
179
|
}
|
|
180
180
|
return result;
|
|
181
181
|
});
|
|
182
|
+
function getItem(value) {
|
|
183
|
+
return value ? objRef.value[value] : null;
|
|
184
|
+
}
|
|
182
185
|
const ctx = {
|
|
183
186
|
map: objRef,
|
|
184
187
|
list: listRef,
|
|
185
188
|
E,
|
|
186
189
|
loadPromise,
|
|
187
190
|
load,
|
|
191
|
+
getItem,
|
|
188
192
|
clear: _clear
|
|
189
193
|
};
|
|
190
194
|
const reactiveCtx = vue.reactive(ctx);
|
|
@@ -194,11 +198,10 @@ function createDictManager(managerOptions = {}) {
|
|
|
194
198
|
...extra == null ? void 0 : extra(reactiveCtx)
|
|
195
199
|
});
|
|
196
200
|
}
|
|
197
|
-
|
|
198
|
-
useDict.extend = (code2, extendOptions) => {
|
|
201
|
+
useDict.extend = (extendCode2, extendOptions) => {
|
|
199
202
|
const { pickValues: pickValues2, omitValues: omitValues2 } = extendOptions != null ? extendOptions : {};
|
|
200
|
-
const options2 = defineDictOptionsMap.get(
|
|
201
|
-
return _defineDict
|
|
203
|
+
const options2 = defineDictOptionsMap.get(code);
|
|
204
|
+
return _defineDict({ pickValues: pickValues2, omitValues: omitValues2, extendCode: code }, extendCode2, options2);
|
|
202
205
|
};
|
|
203
206
|
return useDict;
|
|
204
207
|
}
|
package/dist/index.js
CHANGED
|
@@ -95,15 +95,15 @@ function createDictManager(managerOptions = {}) {
|
|
|
95
95
|
clearObj(maps);
|
|
96
96
|
}
|
|
97
97
|
function _defineDict(internalOptions, code, defineDictOptions) {
|
|
98
|
+
const { pickValues, omitValues, extendCode } = internalOptions;
|
|
98
99
|
if (maps[code]) {
|
|
99
100
|
warn(`code "${code}" already exists`);
|
|
100
101
|
}
|
|
101
|
-
const { pickValues, omitValues } = internalOptions;
|
|
102
102
|
const options = Object.assign(
|
|
103
103
|
{ data: {}, remote: false, fetch: managerFetch },
|
|
104
104
|
isFunction(defineDictOptions) ? defineDictOptions() : defineDictOptions
|
|
105
105
|
);
|
|
106
|
-
defineDictOptionsMap.set(code, options);
|
|
106
|
+
defineDictOptionsMap.set(code, cloneDeep(options));
|
|
107
107
|
const { data, remote, fetch, extra } = options;
|
|
108
108
|
const globalLoadPromise = shallowRef(null);
|
|
109
109
|
maps[code] = /* @__PURE__ */ new Map();
|
|
@@ -111,7 +111,7 @@ function createDictManager(managerOptions = {}) {
|
|
|
111
111
|
var _a;
|
|
112
112
|
const dataMap = toMap(cloneDeep(data), { pickValues, omitValues });
|
|
113
113
|
if (remote) {
|
|
114
|
-
const res = (_a = await (fetch == null ? void 0 : fetch(code, options2))) != null ? _a : [];
|
|
114
|
+
const res = (_a = await (fetch == null ? void 0 : fetch(extendCode != null ? extendCode : code, options2))) != null ? _a : [];
|
|
115
115
|
mapRef.value = toMap(res, { pickValues, omitValues });
|
|
116
116
|
dataMap.forEach((value, key) => {
|
|
117
117
|
if (mapRef.value.has(key)) {
|
|
@@ -177,12 +177,16 @@ function createDictManager(managerOptions = {}) {
|
|
|
177
177
|
}
|
|
178
178
|
return result;
|
|
179
179
|
});
|
|
180
|
+
function getItem(value) {
|
|
181
|
+
return value ? objRef.value[value] : null;
|
|
182
|
+
}
|
|
180
183
|
const ctx = {
|
|
181
184
|
map: objRef,
|
|
182
185
|
list: listRef,
|
|
183
186
|
E,
|
|
184
187
|
loadPromise,
|
|
185
188
|
load,
|
|
189
|
+
getItem,
|
|
186
190
|
clear: _clear
|
|
187
191
|
};
|
|
188
192
|
const reactiveCtx = reactive(ctx);
|
|
@@ -192,11 +196,10 @@ function createDictManager(managerOptions = {}) {
|
|
|
192
196
|
...extra == null ? void 0 : extra(reactiveCtx)
|
|
193
197
|
});
|
|
194
198
|
}
|
|
195
|
-
|
|
196
|
-
useDict.extend = (code2, extendOptions) => {
|
|
199
|
+
useDict.extend = (extendCode2, extendOptions) => {
|
|
197
200
|
const { pickValues: pickValues2, omitValues: omitValues2 } = extendOptions != null ? extendOptions : {};
|
|
198
|
-
const options2 = defineDictOptionsMap.get(
|
|
199
|
-
return _defineDict
|
|
201
|
+
const options2 = defineDictOptionsMap.get(code);
|
|
202
|
+
return _defineDict({ pickValues: pickValues2, omitValues: omitValues2, extendCode: code }, extendCode2, options2);
|
|
200
203
|
};
|
|
201
204
|
return useDict;
|
|
202
205
|
}
|
package/dist/types/dict.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ type ExtractFetchOptions<F extends Fetch> = Parameters<F>[1] extends infer T ? T
|
|
|
27
27
|
type ExtractFetchReturn<F extends Fetch> = UnwrapArray<Awaited<ReturnType<F>>> extends infer Item ? Item extends never ? {} : Item : never;
|
|
28
28
|
type _UseDict<ME extends ExtraGetter, E extends ExtraGetter, D extends Recordable, F extends Fetch> = (options?: Simplify<UseDictOptions & ExtractFetchOptions<F>>) => Simplify<CreateDict<D, F> & ReturnType<ME> & ReturnType<E>>;
|
|
29
29
|
type UseDict<ME extends ExtraGetter, E extends ExtraGetter, D extends Recordable, F extends Fetch> = _UseDict<ME, E, D, F> & {
|
|
30
|
-
extend: (
|
|
30
|
+
extend: (extendCode: string, extendOptions?: {
|
|
31
31
|
pickValues?: Simplify<keyof D>[];
|
|
32
32
|
omitValues?: Simplify<keyof D>[];
|
|
33
33
|
}) => UseDict<ME, E, D, F>;
|
|
@@ -60,5 +60,8 @@ export type Dict<Key extends PropertyKey = PropertyKey, Item extends Recordable
|
|
|
60
60
|
loadPromise: LoadPromise;
|
|
61
61
|
load: (options?: Options) => LoadPromise;
|
|
62
62
|
clear: () => void;
|
|
63
|
+
getItem: (value?: string | null) => Simplify<{
|
|
64
|
+
value: string;
|
|
65
|
+
} & Item> | null;
|
|
63
66
|
};
|
|
64
67
|
export {};
|