@hairy/vue-lib 1.47.0 → 1.49.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/dist/index.cjs CHANGED
@@ -1,422 +1,427 @@
1
- "use strict";
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region \0rolldown/runtime.js
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __getProtoOf = Object.getPrototypeOf;
7
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
9
  var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
20
+ }
21
+ return to;
19
22
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
29
27
 
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- CollapseTransition: () => CollapseTransition,
34
- Field: () => Field,
35
- ehr: () => ehr,
36
- propertyToRef: () => propertyToRef,
37
- syncElementSize: () => syncElementSize,
38
- syncElementSyncScroll: () => syncElementSyncScroll,
39
- useChecked: () => useChecked,
40
- useSelectedMultiple: () => useSelectedMultiple,
41
- useSelectedSingle: () => useSelectedSingle,
42
- useServerPagination: () => useServerPagination
43
- });
44
- module.exports = __toCommonJS(index_exports);
28
+ //#endregion
29
+ let vue_demi = require("vue-demi");
30
+ let css_render = require("css-render");
31
+ css_render = __toESM(css_render);
32
+ let _vueuse_core = require("@vueuse/core");
33
+ let lodash_debounce = require("lodash/debounce");
34
+ lodash_debounce = __toESM(lodash_debounce);
35
+ let lodash_throttle = require("lodash/throttle");
36
+ lodash_throttle = __toESM(lodash_throttle);
37
+ let vue = require("vue");
38
+ let _hairy_utils = require("@hairy/utils");
45
39
 
46
- // src/components/c-field.ts
47
- var import_vue_demi = require("vue-demi");
48
- var Field = (0, import_vue_demi.defineComponent)({
49
- name: "Field",
50
- props: {
51
- is: {
52
- type: [String, Number, Object],
53
- default: ""
54
- }
55
- },
56
- setup(props) {
57
- return () => {
58
- if (typeof props.is === "string" || typeof props.is === "number")
59
- return props.is;
60
- return props.is ? (0, import_vue_demi.h)(props.is) : null;
61
- };
62
- }
40
+ //#region src/components/c-field.ts
41
+ const Field = (0, vue_demi.defineComponent)({
42
+ name: "Field",
43
+ props: { is: {
44
+ type: [
45
+ String,
46
+ Number,
47
+ Object
48
+ ],
49
+ default: ""
50
+ } },
51
+ setup(props) {
52
+ return () => {
53
+ if (typeof props.is === "string" || typeof props.is === "number") return props.is;
54
+ return props.is ? (0, vue_demi.h)(props.is) : null;
55
+ };
56
+ }
63
57
  });
64
58
 
65
- // src/components/collapse-transition.ts
66
- var import_css_render = __toESM(require("css-render"), 1);
67
- var import_vue_demi2 = require("vue-demi");
68
- var { c } = (0, import_css_render.default)();
69
- var CollapseTransition = (0, import_vue_demi2.defineComponent)({
70
- name: "CollapseTransition",
71
- setup(_, { slots }) {
72
- const on = {
73
- onBeforeEnter(el) {
74
- el.classList.add("collapse-transition");
75
- if (!el.dataset)
76
- el.dataset = {};
77
- el.dataset.oldPaddingTop = el.style.paddingTop;
78
- el.dataset.oldPaddingBottom = el.style.paddingBottom;
79
- el.style.height = "0";
80
- el.style.paddingTop = "0";
81
- el.style.paddingBottom = "0";
82
- },
83
- onEnter(el) {
84
- el.dataset.oldOverflow = el.style.overflow;
85
- if (el.scrollHeight !== 0) {
86
- el.style.height = `${el.scrollHeight}px`;
87
- el.style.paddingTop = el.dataset.oldPaddingTop || "0";
88
- el.style.paddingBottom = el.dataset.oldPaddingBottom || "0";
89
- } else {
90
- el.style.height = "";
91
- el.style.paddingTop = el.dataset.oldPaddingTop || "0";
92
- el.style.paddingBottom = el.dataset.oldPaddingBottom || "0";
93
- }
94
- el.style.overflow = "hidden";
95
- },
96
- onAfterEnter(el) {
97
- el.classList.remove("collapse-transition");
98
- el.style.height = "";
99
- el.style.overflow = el.dataset.oldOverflow || "0";
100
- },
101
- onBeforeLeave(el) {
102
- if (!el.dataset)
103
- el.dataset = {};
104
- el.dataset.oldPaddingTop = el.style.paddingTop;
105
- el.dataset.oldPaddingBottom = el.style.paddingBottom;
106
- el.dataset.oldOverflow = el.style.overflow;
107
- el.style.height = `${el.scrollHeight}px`;
108
- el.style.overflow = "hidden";
109
- },
110
- onLeave(el) {
111
- if (el.scrollHeight !== 0) {
112
- el.classList.add("collapse-transition");
113
- el.style.transitionProperty = "height";
114
- el.style.height = "0";
115
- el.style.paddingTop = "0";
116
- el.style.paddingBottom = "0";
117
- }
118
- },
119
- onAfterLeave(el) {
120
- el.classList.remove("collapse-transition");
121
- el.style.height = "";
122
- el.style.overflow = el.dataset.oldOverflow || "0";
123
- el.style.paddingTop = el.dataset.oldPaddingTop || "0";
124
- el.style.paddingBottom = el.dataset.oldPaddingBottom || "0";
125
- }
126
- };
127
- style.mount();
128
- return () => (0, import_vue_demi2.h)(import_vue_demi2.Transition, on, slots);
129
- }
130
- });
131
- var style = c(".collapse-transition", {
132
- transition: "0.2s height ease-in-out, 0.2s padding-top ease-in-out,0.2s padding-bottom ease-in-out"
59
+ //#endregion
60
+ //#region src/components/collapse-transition.ts
61
+ const { c } = (0, css_render.default)();
62
+ const CollapseTransition = (0, vue_demi.defineComponent)({
63
+ name: "CollapseTransition",
64
+ setup(_, { slots }) {
65
+ const on = {
66
+ onBeforeEnter(el) {
67
+ el.classList.add("collapse-transition");
68
+ if (!el.dataset) el.dataset = {};
69
+ el.dataset.oldPaddingTop = el.style.paddingTop;
70
+ el.dataset.oldPaddingBottom = el.style.paddingBottom;
71
+ el.style.height = "0";
72
+ el.style.paddingTop = "0";
73
+ el.style.paddingBottom = "0";
74
+ },
75
+ onEnter(el) {
76
+ el.dataset.oldOverflow = el.style.overflow;
77
+ if (el.scrollHeight !== 0) {
78
+ el.style.height = `${el.scrollHeight}px`;
79
+ el.style.paddingTop = el.dataset.oldPaddingTop || "0";
80
+ el.style.paddingBottom = el.dataset.oldPaddingBottom || "0";
81
+ } else {
82
+ el.style.height = "";
83
+ el.style.paddingTop = el.dataset.oldPaddingTop || "0";
84
+ el.style.paddingBottom = el.dataset.oldPaddingBottom || "0";
85
+ }
86
+ el.style.overflow = "hidden";
87
+ },
88
+ onAfterEnter(el) {
89
+ el.classList.remove("collapse-transition");
90
+ el.style.height = "";
91
+ el.style.overflow = el.dataset.oldOverflow || "0";
92
+ },
93
+ onBeforeLeave(el) {
94
+ if (!el.dataset) el.dataset = {};
95
+ el.dataset.oldPaddingTop = el.style.paddingTop;
96
+ el.dataset.oldPaddingBottom = el.style.paddingBottom;
97
+ el.dataset.oldOverflow = el.style.overflow;
98
+ el.style.height = `${el.scrollHeight}px`;
99
+ el.style.overflow = "hidden";
100
+ },
101
+ onLeave(el) {
102
+ if (el.scrollHeight !== 0) {
103
+ el.classList.add("collapse-transition");
104
+ el.style.transitionProperty = "height";
105
+ el.style.height = "0";
106
+ el.style.paddingTop = "0";
107
+ el.style.paddingBottom = "0";
108
+ }
109
+ },
110
+ onAfterLeave(el) {
111
+ el.classList.remove("collapse-transition");
112
+ el.style.height = "";
113
+ el.style.overflow = el.dataset.oldOverflow || "0";
114
+ el.style.paddingTop = el.dataset.oldPaddingTop || "0";
115
+ el.style.paddingBottom = el.dataset.oldPaddingBottom || "0";
116
+ }
117
+ };
118
+ style.mount();
119
+ return () => (0, vue_demi.h)(vue_demi.Transition, on, slots);
120
+ }
133
121
  });
122
+ const style = c(".collapse-transition", { transition: "0.2s height ease-in-out, 0.2s padding-top ease-in-out,0.2s padding-bottom ease-in-out" });
134
123
 
135
- // src/hooks/syncElementScroll/index.ts
136
- var import_core = require("@vueuse/core");
137
- var import_debounce = __toESM(require("lodash/debounce"), 1);
138
- var import_throttle = __toESM(require("lodash/throttle"), 1);
139
- var import_vue = require("vue");
124
+ //#endregion
125
+ //#region src/hooks/syncElementScroll/index.ts
126
+ /**
127
+ * Synchronize scrolling between two DOM with the same scrollbar
128
+ * @param fromTarget DOM-A
129
+ * @param toTarget DOM-B
130
+ * @param options
131
+ * @todo optimizes the reuse of useEventListener
132
+ * @todo may have bugs when using wait
133
+ */
140
134
  function syncElementSyncScroll(fromTarget, toTarget, options = {}) {
141
- const { left = true, top = true, wait, immediate = true } = options;
142
- const debounceScrollLocks = (0, import_vue.reactive)({ from: false, to: false });
143
- const onChangeLockScrollListener = (0, import_debounce.default)(
144
- (type) => {
145
- debounceScrollLocks[type] = true;
146
- },
147
- 20,
148
- { leading: true, trailing: false }
149
- );
150
- const offChangeLockScrollListener = (0, import_debounce.default)(
151
- (type) => {
152
- debounceScrollLocks[type] = false;
153
- },
154
- 20,
155
- { leading: false, trailing: true }
156
- );
157
- const syncScroll = (type) => {
158
- const positive = type;
159
- const opposite = type === "from" ? "to" : "from";
160
- const elements = (0, import_vue.reactive)({
161
- from: fromTarget,
162
- to: toTarget
163
- });
164
- if (debounceScrollLocks[type])
165
- return;
166
- onChangeLockScrollListener(opposite);
167
- const aElement = elements[positive];
168
- const bElement = elements[opposite];
169
- const options2 = {};
170
- if (left)
171
- options2.left = aElement.scrollLeft;
172
- if (top)
173
- options2.top = aElement.scrollTop;
174
- if (!aElement || !bElement)
175
- return;
176
- bElement?.scroll(options2);
177
- offChangeLockScrollListener(opposite);
178
- };
179
- const syncFromTo = () => syncScroll("from");
180
- const syncToFrom = () => syncScroll("to");
181
- let toStopHandle;
182
- let formStopHandle;
183
- const stop = () => {
184
- toStopHandle?.();
185
- formStopHandle?.();
186
- };
187
- const start = () => {
188
- toStopHandle = (0, import_core.useEventListener)(fromTarget, "scroll", (0, import_throttle.default)(syncFromTo, wait));
189
- formStopHandle = (0, import_core.useEventListener)(toTarget, "scroll", (0, import_throttle.default)(syncToFrom, wait));
190
- };
191
- if (immediate)
192
- start();
193
- return { stop, start, syncFromTo, syncToFrom };
135
+ const { left = true, top = true, wait, immediate = true } = options;
136
+ const debounceScrollLocks = (0, vue.reactive)({
137
+ from: false,
138
+ to: false
139
+ });
140
+ const onChangeLockScrollListener = (0, lodash_debounce.default)((type) => {
141
+ debounceScrollLocks[type] = true;
142
+ }, 20, {
143
+ leading: true,
144
+ trailing: false
145
+ });
146
+ const offChangeLockScrollListener = (0, lodash_debounce.default)((type) => {
147
+ debounceScrollLocks[type] = false;
148
+ }, 20, {
149
+ leading: false,
150
+ trailing: true
151
+ });
152
+ const syncScroll = (type) => {
153
+ const positive = type;
154
+ const opposite = type === "from" ? "to" : "from";
155
+ const elements = (0, vue.reactive)({
156
+ from: fromTarget,
157
+ to: toTarget
158
+ });
159
+ if (debounceScrollLocks[type]) return;
160
+ onChangeLockScrollListener(opposite);
161
+ const aElement = elements[positive];
162
+ const bElement = elements[opposite];
163
+ const options = {};
164
+ if (left) options.left = aElement.scrollLeft;
165
+ if (top) options.top = aElement.scrollTop;
166
+ if (!aElement || !bElement) return;
167
+ bElement?.scroll(options);
168
+ offChangeLockScrollListener(opposite);
169
+ };
170
+ const syncFromTo = () => syncScroll("from");
171
+ const syncToFrom = () => syncScroll("to");
172
+ let toStopHandle;
173
+ let formStopHandle;
174
+ const stop = () => {
175
+ toStopHandle?.();
176
+ formStopHandle?.();
177
+ };
178
+ const start = () => {
179
+ toStopHandle = (0, _vueuse_core.useEventListener)(fromTarget, "scroll", (0, lodash_throttle.default)(syncFromTo, wait));
180
+ formStopHandle = (0, _vueuse_core.useEventListener)(toTarget, "scroll", (0, lodash_throttle.default)(syncToFrom, wait));
181
+ };
182
+ if (immediate) start();
183
+ return {
184
+ stop,
185
+ start,
186
+ syncFromTo,
187
+ syncToFrom
188
+ };
194
189
  }
195
190
 
196
- // src/hooks/syncElementSize/index.ts
197
- var import_utils = require("@hairy/utils");
198
- var import_core2 = require("@vueuse/core");
199
- var import_vue2 = require("vue");
191
+ //#endregion
192
+ //#region src/hooks/syncElementSize/index.ts
193
+ /**
194
+ * Synchronize the width or height of from DOM to the specified to DOM
195
+ * @param fromTarget width and height source element
196
+ * @param toTarget width and height setting elements
197
+ * @param options
198
+ */
200
199
  function syncElementSize(fromTarget, toTarget, options = {}) {
201
- const { width: isOnWidth = true, height: isOnHeight = false } = options;
202
- const defaultSize = { width: "", height: "" };
203
- const fromSize = (0, import_core2.useElementSize)(fromTarget);
204
- let widthStopHandle;
205
- let heightStopHandle;
206
- const sync = (type) => {
207
- const sources = [fromSize[type], toTarget];
208
- const callback = () => {
209
- const element = (0, import_core2.unrefElement)(toTarget);
210
- if (!element)
211
- return void 0;
212
- element.style[type] = (0, import_utils.unit)(fromSize[type].value);
213
- };
214
- return (0, import_vue2.watch)(sources, callback, { immediate: true, ...options });
215
- };
216
- const stop = () => {
217
- widthStopHandle?.();
218
- heightStopHandle?.();
219
- const element = (0, import_core2.unrefElement)(toTarget);
220
- element.style.width = defaultSize.width;
221
- element.style.height = defaultSize.height;
222
- };
223
- const start = () => {
224
- if (isOnWidth)
225
- widthStopHandle = sync("width");
226
- if (isOnHeight)
227
- heightStopHandle = sync("height");
228
- };
229
- (0, import_vue2.watch)(
230
- () => (0, import_vue2.unref)(toTarget),
231
- () => {
232
- const element = (0, import_core2.unrefElement)(toTarget);
233
- defaultSize.width = element.style.width;
234
- defaultSize.height = element.style.height;
235
- }
236
- );
237
- start();
238
- return { start, stop };
200
+ const { width: isOnWidth = true, height: isOnHeight = false } = options;
201
+ const defaultSize = {
202
+ width: "",
203
+ height: ""
204
+ };
205
+ const fromSize = (0, _vueuse_core.useElementSize)(fromTarget);
206
+ let widthStopHandle;
207
+ let heightStopHandle;
208
+ const sync = (type) => {
209
+ const sources = [fromSize[type], toTarget];
210
+ const callback = () => {
211
+ const element = (0, _vueuse_core.unrefElement)(toTarget);
212
+ if (!element) return void 0;
213
+ element.style[type] = (0, _hairy_utils.unit)(fromSize[type].value);
214
+ };
215
+ return (0, vue.watch)(sources, callback, {
216
+ immediate: true,
217
+ ...options
218
+ });
219
+ };
220
+ const stop = () => {
221
+ widthStopHandle?.();
222
+ heightStopHandle?.();
223
+ const element = (0, _vueuse_core.unrefElement)(toTarget);
224
+ element.style.width = defaultSize.width;
225
+ element.style.height = defaultSize.height;
226
+ };
227
+ const start = () => {
228
+ if (isOnWidth) widthStopHandle = sync("width");
229
+ if (isOnHeight) heightStopHandle = sync("height");
230
+ };
231
+ (0, vue.watch)(() => (0, vue.unref)(toTarget), () => {
232
+ const element = (0, _vueuse_core.unrefElement)(toTarget);
233
+ defaultSize.width = element.style.width;
234
+ defaultSize.height = element.style.height;
235
+ });
236
+ start();
237
+ return {
238
+ start,
239
+ stop
240
+ };
239
241
  }
240
242
 
241
- // src/hooks/useChecked/index.ts
242
- var import_vue3 = require("vue");
243
+ //#endregion
244
+ //#region src/hooks/useChecked/index.ts
245
+ /**
246
+ * Get the status of checked and customize the value of checked | unchecked
247
+ * @param target
248
+ * @param checked
249
+ * @param unchecked
250
+ */
243
251
  function useChecked(target, checked = true, unchecked = false) {
244
- return (0, import_vue3.computed)({
245
- get: () => target.value === (0, import_vue3.unref)(checked),
246
- set: (_value) => {
247
- target.value = _value ? (0, import_vue3.unref)(checked) : (0, import_vue3.unref)(unchecked);
248
- }
249
- });
252
+ return (0, vue.computed)({
253
+ get: () => target.value === (0, vue.unref)(checked),
254
+ set: (_value) => {
255
+ target.value = _value ? (0, vue.unref)(checked) : (0, vue.unref)(unchecked);
256
+ }
257
+ });
250
258
  }
251
259
 
252
- // src/hooks/usePaginationServer/index.ts
253
- var import_core3 = require("@vueuse/core");
254
- var import_debounce2 = __toESM(require("lodash/debounce"), 1);
255
- var import_vue4 = require("vue");
260
+ //#endregion
261
+ //#region src/hooks/usePaginationServer/index.ts
256
262
  function useServerPagination(options) {
257
- const total = (0, import_vue4.ref)(Infinity);
258
- const pagination = (0, import_core3.useOffsetPagination)({ total, ...options });
259
- const resolveOptions = (0, import_vue4.reactive)({
260
- currentPage: pagination.currentPage,
261
- currentPageSize: pagination.currentPageSize,
262
- total
263
- });
264
- const paginationRef = (0, import_vue4.reactive)({
265
- currentPage: pagination.currentPage,
266
- currentPageSize: pagination.currentPageSize,
267
- pageCount: pagination.pageCount,
268
- isFirstPage: pagination.isFirstPage,
269
- isLastPage: pagination.isLastPage,
270
- total
271
- });
272
- const state = (0, import_vue4.ref)([]);
273
- const {
274
- execute: _execute,
275
- isLoading: loading,
276
- error
277
- } = (0, import_core3.useAsyncState)(async () => {
278
- const resolved = await options.resolve(resolveOptions);
279
- return resolved;
280
- }, []);
281
- const execute = (0, import_debounce2.default)(async () => {
282
- state.value = await _execute();
283
- }, 100);
284
- (0, import_vue4.nextTick)(() => {
285
- (0, import_vue4.watch)([pagination.currentPageSize, ...options.sources || []], execute, { immediate: true, ...options });
286
- (0, import_vue4.watch)(pagination.currentPage, (newValue, oldValue) => newValue !== oldValue && execute());
287
- });
288
- return {
289
- state,
290
- loading,
291
- error,
292
- execute,
293
- pagination: paginationRef,
294
- next: pagination.next,
295
- prev: pagination.prev
296
- };
263
+ const total = (0, vue.ref)(Infinity);
264
+ const pagination = (0, _vueuse_core.useOffsetPagination)({
265
+ total,
266
+ ...options
267
+ });
268
+ const resolveOptions = (0, vue.reactive)({
269
+ currentPage: pagination.currentPage,
270
+ currentPageSize: pagination.currentPageSize,
271
+ total
272
+ });
273
+ const paginationRef = (0, vue.reactive)({
274
+ currentPage: pagination.currentPage,
275
+ currentPageSize: pagination.currentPageSize,
276
+ pageCount: pagination.pageCount,
277
+ isFirstPage: pagination.isFirstPage,
278
+ isLastPage: pagination.isLastPage,
279
+ total
280
+ });
281
+ const state = (0, vue.ref)([]);
282
+ const { execute: _execute, isLoading: loading, error } = (0, _vueuse_core.useAsyncState)(async () => {
283
+ return await options.resolve(resolveOptions);
284
+ }, []);
285
+ const execute = (0, lodash_debounce.default)(async () => {
286
+ state.value = await _execute();
287
+ }, 100);
288
+ (0, vue.nextTick)(() => {
289
+ (0, vue.watch)([pagination.currentPageSize, ...options.sources || []], execute, {
290
+ immediate: true,
291
+ ...options
292
+ });
293
+ (0, vue.watch)(pagination.currentPage, (newValue, oldValue) => newValue !== oldValue && execute());
294
+ });
295
+ return {
296
+ state,
297
+ loading,
298
+ error,
299
+ execute,
300
+ pagination: paginationRef,
301
+ next: pagination.next,
302
+ prev: pagination.prev
303
+ };
297
304
  }
298
305
 
299
- // src/hooks/useSelectedMultiple/index.ts
300
- var import_vue6 = require("vue");
301
-
302
- // src/hooks/utils/extendSelected.ts
303
- var import_core4 = require("@vueuse/core");
304
- var import_vue5 = require("vue");
306
+ //#endregion
307
+ //#region src/hooks/utils/extendSelected.ts
305
308
  function extendSelected(array, fieldName) {
306
- (0, import_vue5.watch)(
307
- array,
308
- (items) => {
309
- for (const item of items) {
310
- if (typeof item[fieldName] === "undefined")
311
- (0, import_core4.extendRef)(item, { [fieldName]: (0, import_vue5.ref)(false) });
312
- }
313
- },
314
- { immediate: true, flush: "sync" }
315
- );
309
+ (0, vue.watch)(array, (items) => {
310
+ for (const item of items) if (typeof item[fieldName] === "undefined") (0, _vueuse_core.extendRef)(item, { [fieldName]: (0, vue.ref)(false) });
311
+ }, {
312
+ immediate: true,
313
+ flush: "sync"
314
+ });
316
315
  }
317
316
 
318
- // src/hooks/useSelectedMultiple/index.ts
317
+ //#endregion
318
+ //#region src/hooks/useSelectedMultiple/index.ts
319
319
  function useSelectedMultiple(array, options = {}) {
320
- const { fieldName = "select", disabled } = options;
321
- extendSelected(array, fieldName);
322
- const selected = (0, import_vue6.computed)(() => (0, import_vue6.unref)(array).filter((item) => item[fieldName]));
323
- const isSelectedAll = (0, import_vue6.computed)({
324
- get: () => !selected.value?.length && !(0, import_vue6.unref)(array).some((item) => !item[fieldName]),
325
- set: (value) => (0, import_vue6.unref)(array).forEach((item, index) => {
326
- if (!disabled?.(item, index))
327
- item[fieldName] = value;
328
- })
329
- });
330
- const isSelected = (0, import_vue6.computed)(() => !!(0, import_vue6.unref)(array).some((item) => item[fieldName]));
331
- const isIndeterminate = (0, import_vue6.computed)(() => {
332
- const selectCount = selected.value.length;
333
- return selectCount > 0 && selectCount < (0, import_vue6.unref)(array).length;
334
- });
335
- return { selected, isSelectedAll, isSelected, isIndeterminate };
320
+ const { fieldName = "select", disabled } = options;
321
+ extendSelected(array, fieldName);
322
+ /** 当前选中的项列表 */
323
+ const selected = (0, vue.computed)(() => (0, vue.unref)(array).filter((item) => item[fieldName]));
324
+ return {
325
+ selected,
326
+ isSelectedAll: (0, vue.computed)({
327
+ get: () => !selected.value?.length && !(0, vue.unref)(array).some((item) => !item[fieldName]),
328
+ set: (value) => (0, vue.unref)(array).forEach((item, index) => {
329
+ if (!disabled?.(item, index)) item[fieldName] = value;
330
+ })
331
+ }),
332
+ isSelected: (0, vue.computed)(() => !!(0, vue.unref)(array).some((item) => item[fieldName])),
333
+ isIndeterminate: (0, vue.computed)(() => {
334
+ const selectCount = selected.value.length;
335
+ return selectCount > 0 && selectCount < (0, vue.unref)(array).length;
336
+ })
337
+ };
336
338
  }
337
339
 
338
- // src/hooks/useSelectedSingle/index.ts
339
- var import_vue7 = require("vue");
340
+ //#endregion
341
+ //#region src/hooks/useSelectedSingle/index.ts
340
342
  function useSelectedSingle(array, options = {}) {
341
- const fieldName = options.fieldName ?? "select";
342
- const required = options.required ?? false;
343
- extendSelected(array, fieldName);
344
- const SELECTED_SINGLE_KEY = "selected_single_key";
345
- const isLocked = (0, import_vue7.ref)(false);
346
- const isSelected = (0, import_vue7.computed)(() => !!(0, import_vue7.unref)(array).some((item) => item.select));
347
- if (required) {
348
- const recover = (bool) => {
349
- const index = required === true ? 0 : required;
350
- if (!bool && (0, import_vue7.unref)(array).length > 0)
351
- (0, import_vue7.unref)(array)[index][fieldName] = true;
352
- };
353
- (0, import_vue7.watch)(isSelected, recover, { flush: "sync", immediate: true });
354
- }
355
- const itemChange = (neglect) => {
356
- if (isLocked.value)
357
- return;
358
- isLocked.value = true;
359
- const _array = (0, import_vue7.unref)(array);
360
- const _value = !_array[neglect][fieldName];
361
- if (required && !_value)
362
- _array[neglect][fieldName] = true;
363
- _array.forEach((target, index) => {
364
- if (neglect === index)
365
- return void 0;
366
- if (!target[fieldName])
367
- return void 0;
368
- target[fieldName] = false;
369
- });
370
- isLocked.value = false;
371
- };
372
- const targetEffect = (target, index) => {
373
- if (!target[SELECTED_SINGLE_KEY]) {
374
- return (0, import_vue7.watch)(
375
- () => target[fieldName],
376
- () => itemChange(index),
377
- { flush: "sync" }
378
- );
379
- }
380
- Object.defineProperty(target, SELECTED_SINGLE_KEY, { value: true });
381
- };
382
- (0, import_vue7.watch)(
383
- array,
384
- () => {
385
- (0, import_vue7.unref)(array).forEach(targetEffect);
386
- },
387
- { immediate: true, flush: "sync" }
388
- );
389
- const selected = (0, import_vue7.computed)(() => (0, import_vue7.unref)(array).find((v) => v[fieldName]));
390
- return { selected, isSelected };
343
+ const fieldName = options.fieldName ?? "select";
344
+ const required = options.required ?? false;
345
+ extendSelected(array, fieldName);
346
+ const SELECTED_SINGLE_KEY = "selected_single_key";
347
+ const isLocked = (0, vue.ref)(false);
348
+ /** 当前是否已经选择 */
349
+ const isSelected = (0, vue.computed)(() => !!(0, vue.unref)(array).some((item) => item.select));
350
+ if (required) {
351
+ const recover = (bool) => {
352
+ const index = required === true ? 0 : required;
353
+ if (!bool && (0, vue.unref)(array).length > 0) (0, vue.unref)(array)[index][fieldName] = true;
354
+ };
355
+ (0, vue.watch)(isSelected, recover, {
356
+ flush: "sync",
357
+ immediate: true
358
+ });
359
+ }
360
+ const itemChange = (neglect) => {
361
+ if (isLocked.value) return;
362
+ isLocked.value = true;
363
+ const _array = (0, vue.unref)(array);
364
+ const _value = !_array[neglect][fieldName];
365
+ if (required && !_value) _array[neglect][fieldName] = true;
366
+ _array.forEach((target, index) => {
367
+ if (neglect === index) return void 0;
368
+ if (!target[fieldName]) return void 0;
369
+ target[fieldName] = false;
370
+ });
371
+ isLocked.value = false;
372
+ };
373
+ const targetEffect = (target, index) => {
374
+ if (!target[SELECTED_SINGLE_KEY]) return (0, vue.watch)(() => target[fieldName], () => itemChange(index), { flush: "sync" });
375
+ Object.defineProperty(target, SELECTED_SINGLE_KEY, { value: true });
376
+ };
377
+ (0, vue.watch)(array, () => {
378
+ (0, vue.unref)(array).forEach(targetEffect);
379
+ }, {
380
+ immediate: true,
381
+ flush: "sync"
382
+ });
383
+ return {
384
+ selected: (0, vue.computed)(() => (0, vue.unref)(array).find((v) => v[fieldName])),
385
+ isSelected
386
+ };
391
387
  }
392
388
 
393
- // src/utils/index.ts
394
- var import_vue_demi3 = require("vue-demi");
389
+ //#endregion
390
+ //#region src/utils/index.ts
391
+ /**
392
+ * Directly render the incoming function components
393
+ * @param component
394
+ * @param tag Rendering container (default div)
395
+ */
395
396
  function ehr(component, tag) {
396
- const container = document.createElement(tag || "dev");
397
- (0, import_vue_demi3.render)((0, import_vue_demi3.h)(component), container);
398
- return container;
397
+ const container = document.createElement(tag || "dev");
398
+ (0, vue_demi.render)((0, vue_demi.h)(component), container);
399
+ return container;
399
400
  }
401
+ /**
402
+ * Convert the properties of an object to ref
403
+ * @param data
404
+ * @param prop
405
+ */
400
406
  function propertyToRef(data, prop) {
401
- return (0, import_vue_demi3.computed)({
402
- get() {
403
- return data[prop];
404
- },
405
- set(v) {
406
- data[prop] = v;
407
- }
408
- });
407
+ return (0, vue_demi.computed)({
408
+ get() {
409
+ return data[prop];
410
+ },
411
+ set(v) {
412
+ data[prop] = v;
413
+ }
414
+ });
409
415
  }
410
- // Annotate the CommonJS export names for ESM import in node:
411
- 0 && (module.exports = {
412
- CollapseTransition,
413
- Field,
414
- ehr,
415
- propertyToRef,
416
- syncElementSize,
417
- syncElementSyncScroll,
418
- useChecked,
419
- useSelectedMultiple,
420
- useSelectedSingle,
421
- useServerPagination
422
- });
416
+
417
+ //#endregion
418
+ exports.CollapseTransition = CollapseTransition;
419
+ exports.Field = Field;
420
+ exports.ehr = ehr;
421
+ exports.propertyToRef = propertyToRef;
422
+ exports.syncElementSize = syncElementSize;
423
+ exports.syncElementSyncScroll = syncElementSyncScroll;
424
+ exports.useChecked = useChecked;
425
+ exports.useSelectedMultiple = useSelectedMultiple;
426
+ exports.useSelectedSingle = useSelectedSingle;
427
+ exports.useServerPagination = useServerPagination;