hoci 0.0.4 → 0.0.6

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
@@ -86,7 +86,8 @@ const useSelectionItem = defineHookComponent({
86
86
  vue.onDeactivated(() => remove());
87
87
  }
88
88
  const isActive = vue.inject(IsActiveSymbol, () => false);
89
- const changeActive = vue.inject(ChangeActiveSymbol, () => false);
89
+ const changeActive = vue.inject(ChangeActiveSymbol, () => {
90
+ });
90
91
  const activeClass = vue.computed(() => {
91
92
  var _a, _b;
92
93
  return (_b = (_a = vue.inject(ActiveClassSymbol)) == null ? void 0 : _a.value) != null ? _b : "active";
@@ -129,18 +130,45 @@ const HiItem = vue.defineComponent({
129
130
  }
130
131
  });
131
132
 
133
+ var __async = (__this, __arguments, generator) => {
134
+ return new Promise((resolve, reject) => {
135
+ var fulfilled = (value) => {
136
+ try {
137
+ step(generator.next(value));
138
+ } catch (e) {
139
+ reject(e);
140
+ }
141
+ };
142
+ var rejected = (value) => {
143
+ try {
144
+ step(generator.throw(value));
145
+ } catch (e) {
146
+ reject(e);
147
+ }
148
+ };
149
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
150
+ step((generator = generator.apply(__this, __arguments)).next());
151
+ });
152
+ };
132
153
  const selectionListProps = defineHookProps({
133
154
  tag: {
134
155
  type: String,
135
156
  default: "div"
136
157
  },
137
158
  modelValue: {
138
- type: valuePropType
159
+ type: valuePropType,
160
+ default: () => null
139
161
  },
162
+ /**
163
+ * 选中时的 class
164
+ */
140
165
  activeClass: {
141
166
  type: classPropType,
142
- default: ""
167
+ default: "active"
143
168
  },
169
+ /**
170
+ * 每个选项的 class
171
+ */
144
172
  itemClass: {
145
173
  type: classPropType,
146
174
  default: ""
@@ -152,15 +180,22 @@ const selectionListProps = defineHookProps({
152
180
  label: {
153
181
  type: labelPropType
154
182
  },
183
+ /**
184
+ * 多选模式
185
+ */
155
186
  multiple: {
156
187
  type: [Boolean, Number],
157
188
  default: () => false
158
189
  },
190
+ /**
191
+ * 可清除
192
+ */
159
193
  clearable: {
160
194
  type: Boolean
161
195
  },
162
196
  defaultValue: {
163
- type: valuePropType
197
+ type: valuePropType,
198
+ default: () => null
164
199
  },
165
200
  activateEvent: {
166
201
  type: String,
@@ -175,7 +210,7 @@ const useSelectionList = defineHookComponent({
175
210
  var _a;
176
211
  const options = vue.reactive([]);
177
212
  function toArray(value) {
178
- if (value === void 0) {
213
+ if (!core.isDefined(value)) {
179
214
  return [];
180
215
  }
181
216
  if (props.multiple && Array.isArray(value)) {
@@ -189,11 +224,7 @@ const useSelectionList = defineHookComponent({
189
224
  return props.multiple ? actives : actives[0];
190
225
  },
191
226
  set(val) {
192
- if (props.multiple) {
193
- actives.splice(0, actives.length, ...toArray(val));
194
- } else {
195
- actives.splice(0, actives.length, val);
196
- }
227
+ actives.splice(0, actives.length, ...toArray(val));
197
228
  }
198
229
  });
199
230
  const modelValue = vue.computed({
@@ -203,7 +234,6 @@ const useSelectionList = defineHookComponent({
203
234
  },
204
235
  set(val) {
205
236
  emit("update:modelValue", val);
206
- emit("change", val);
207
237
  }
208
238
  });
209
239
  core.syncRef(currentValue, modelValue, { immediate: true, deep: true });
@@ -225,20 +255,25 @@ const useSelectionList = defineHookComponent({
225
255
  return actives.includes(value);
226
256
  }
227
257
  function changeActive(option) {
228
- if (isActive(option)) {
229
- if (props.multiple || props.clearable) {
230
- actives.splice(actives.indexOf(option), 1);
231
- }
232
- } else {
233
- if (props.multiple) {
234
- const limit = typeof props.multiple === "number" ? props.multiple : Infinity;
235
- if (actives.length < limit) {
236
- actives.push(option);
258
+ return __async(this, null, function* () {
259
+ const stopWatch = vue.watch(currentValue, (val) => emit("change", val), { deep: true });
260
+ if (isActive(option)) {
261
+ if (props.multiple || props.clearable) {
262
+ actives.splice(actives.indexOf(option), 1);
237
263
  }
238
264
  } else {
239
- actives.splice(0, actives.length, option);
265
+ if (props.multiple) {
266
+ const limit = typeof props.multiple === "number" ? props.multiple : Infinity;
267
+ if (actives.length < limit) {
268
+ actives.push(option);
269
+ }
270
+ } else {
271
+ actives.splice(0, actives.length, option);
272
+ }
240
273
  }
241
- }
274
+ yield vue.nextTick();
275
+ stopWatch();
276
+ });
242
277
  }
243
278
  vue.provide(IsActiveSymbol, isActive);
244
279
  vue.provide(ChangeActiveSymbol, changeActive);
@@ -333,14 +368,13 @@ const useSwitch = defineHookComponent({
333
368
  set(val) {
334
369
  checked.value = val;
335
370
  emit("update:modelValue", val);
336
- emit("change", val);
337
371
  }
338
372
  });
339
373
  const toggle = function(value) {
340
- if (typeof value === "boolean") {
341
- modelValue.value = value;
342
- } else {
343
- modelValue.value = !modelValue.value;
374
+ const oldValue = modelValue.value;
375
+ const newValue = typeof value === "boolean" ? value : !oldValue;
376
+ if (newValue !== oldValue) {
377
+ emit("change", newValue);
344
378
  }
345
379
  };
346
380
  const switchClass = vue.computed(() => {
package/dist/index.d.ts CHANGED
@@ -132,6 +132,7 @@ declare const selectionListProps: {
132
132
  };
133
133
  modelValue: {
134
134
  type: PropType<any>;
135
+ default: () => null;
135
136
  };
136
137
  /**
137
138
  * 选中时的 class
@@ -169,6 +170,7 @@ declare const selectionListProps: {
169
170
  };
170
171
  defaultValue: {
171
172
  type: PropType<any>;
173
+ default: () => null;
172
174
  };
173
175
  activateEvent: {
174
176
  type: PropType<ActivateEvent>;
@@ -185,7 +187,7 @@ declare const useSelectionList: HookComponent<{
185
187
  }[];
186
188
  actives: any[];
187
189
  isActive: (value: any) => boolean;
188
- changeActive: (option: any) => void;
190
+ changeActive: (option: any) => Promise<void>;
189
191
  renderItem: () => ElementLike;
190
192
  render: () => vue.VNode<vue.RendererNode, vue.RendererElement, {
191
193
  [key: string]: any;
@@ -197,6 +199,7 @@ declare const useSelectionList: HookComponent<{
197
199
  };
198
200
  modelValue: {
199
201
  type: PropType<any>;
202
+ default: () => null;
200
203
  };
201
204
  /**
202
205
  * 选中时的 class
@@ -234,6 +237,7 @@ declare const useSelectionList: HookComponent<{
234
237
  };
235
238
  defaultValue: {
236
239
  type: PropType<any>;
240
+ default: () => null;
237
241
  };
238
242
  activateEvent: {
239
243
  type: PropType<ActivateEvent>;
@@ -246,6 +250,7 @@ declare const useSelectionList: HookComponent<{
246
250
  };
247
251
  modelValue: {
248
252
  type: PropType<any>;
253
+ default: () => null;
249
254
  };
250
255
  /**
251
256
  * 选中时的 class
@@ -283,6 +288,7 @@ declare const useSelectionList: HookComponent<{
283
288
  };
284
289
  defaultValue: {
285
290
  type: PropType<any>;
291
+ default: () => null;
286
292
  };
287
293
  activateEvent: {
288
294
  type: PropType<ActivateEvent>;
@@ -296,6 +302,7 @@ declare const HiSelection: vue.DefineComponent<{
296
302
  };
297
303
  modelValue: {
298
304
  type: PropType<any>;
305
+ default: () => null;
299
306
  };
300
307
  /**
301
308
  * 选中时的 class
@@ -333,6 +340,7 @@ declare const HiSelection: vue.DefineComponent<{
333
340
  };
334
341
  defaultValue: {
335
342
  type: PropType<any>;
343
+ default: () => null;
336
344
  };
337
345
  activateEvent: {
338
346
  type: PropType<ActivateEvent>;
@@ -347,6 +355,7 @@ declare const HiSelection: vue.DefineComponent<{
347
355
  };
348
356
  modelValue: {
349
357
  type: PropType<any>;
358
+ default: () => null;
350
359
  };
351
360
  /**
352
361
  * 选中时的 class
@@ -384,6 +393,7 @@ declare const HiSelection: vue.DefineComponent<{
384
393
  };
385
394
  defaultValue: {
386
395
  type: PropType<any>;
396
+ default: () => null;
387
397
  };
388
398
  activateEvent: {
389
399
  type: PropType<ActivateEvent>;
@@ -397,7 +407,9 @@ declare const HiSelection: vue.DefineComponent<{
397
407
  }, {
398
408
  activateEvent: ActivateEvent;
399
409
  itemClass: string | string[];
410
+ modelValue: any;
400
411
  multiple: number | boolean;
412
+ defaultValue: any;
401
413
  tag: string;
402
414
  activeClass: string | string[];
403
415
  unactiveClass: string | string[];
@@ -544,8 +556,8 @@ declare const HiSwitch: vue.DefineComponent<{
544
556
  }, {
545
557
  activateEvent: ActivateEvent;
546
558
  class: string | string[];
547
- tag: string;
548
559
  modelValue: boolean;
560
+ tag: string;
549
561
  activeClass: string | string[];
550
562
  unactiveClass: string | string[];
551
563
  }>;
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- import { reactiveComputed, resolveRef, syncRef } from '@vueuse/core';
2
- import { defineComponent, h, capitalize, inject, watch, onDeactivated, computed, renderSlot, reactive, provide, ref } from 'vue';
1
+ import { reactiveComputed, resolveRef, syncRef, isDefined } from '@vueuse/core';
2
+ import { defineComponent, h, capitalize, inject, watch, onDeactivated, computed, renderSlot, reactive, provide, nextTick, ref } from 'vue';
3
3
 
4
4
  function defineHookProps(props) {
5
5
  return props;
@@ -84,7 +84,8 @@ const useSelectionItem = defineHookComponent({
84
84
  onDeactivated(() => remove());
85
85
  }
86
86
  const isActive = inject(IsActiveSymbol, () => false);
87
- const changeActive = inject(ChangeActiveSymbol, () => false);
87
+ const changeActive = inject(ChangeActiveSymbol, () => {
88
+ });
88
89
  const activeClass = computed(() => {
89
90
  var _a, _b;
90
91
  return (_b = (_a = inject(ActiveClassSymbol)) == null ? void 0 : _a.value) != null ? _b : "active";
@@ -127,18 +128,45 @@ const HiItem = defineComponent({
127
128
  }
128
129
  });
129
130
 
131
+ var __async = (__this, __arguments, generator) => {
132
+ return new Promise((resolve, reject) => {
133
+ var fulfilled = (value) => {
134
+ try {
135
+ step(generator.next(value));
136
+ } catch (e) {
137
+ reject(e);
138
+ }
139
+ };
140
+ var rejected = (value) => {
141
+ try {
142
+ step(generator.throw(value));
143
+ } catch (e) {
144
+ reject(e);
145
+ }
146
+ };
147
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
148
+ step((generator = generator.apply(__this, __arguments)).next());
149
+ });
150
+ };
130
151
  const selectionListProps = defineHookProps({
131
152
  tag: {
132
153
  type: String,
133
154
  default: "div"
134
155
  },
135
156
  modelValue: {
136
- type: valuePropType
157
+ type: valuePropType,
158
+ default: () => null
137
159
  },
160
+ /**
161
+ * 选中时的 class
162
+ */
138
163
  activeClass: {
139
164
  type: classPropType,
140
- default: ""
165
+ default: "active"
141
166
  },
167
+ /**
168
+ * 每个选项的 class
169
+ */
142
170
  itemClass: {
143
171
  type: classPropType,
144
172
  default: ""
@@ -150,15 +178,22 @@ const selectionListProps = defineHookProps({
150
178
  label: {
151
179
  type: labelPropType
152
180
  },
181
+ /**
182
+ * 多选模式
183
+ */
153
184
  multiple: {
154
185
  type: [Boolean, Number],
155
186
  default: () => false
156
187
  },
188
+ /**
189
+ * 可清除
190
+ */
157
191
  clearable: {
158
192
  type: Boolean
159
193
  },
160
194
  defaultValue: {
161
- type: valuePropType
195
+ type: valuePropType,
196
+ default: () => null
162
197
  },
163
198
  activateEvent: {
164
199
  type: String,
@@ -173,7 +208,7 @@ const useSelectionList = defineHookComponent({
173
208
  var _a;
174
209
  const options = reactive([]);
175
210
  function toArray(value) {
176
- if (value === void 0) {
211
+ if (!isDefined(value)) {
177
212
  return [];
178
213
  }
179
214
  if (props.multiple && Array.isArray(value)) {
@@ -187,11 +222,7 @@ const useSelectionList = defineHookComponent({
187
222
  return props.multiple ? actives : actives[0];
188
223
  },
189
224
  set(val) {
190
- if (props.multiple) {
191
- actives.splice(0, actives.length, ...toArray(val));
192
- } else {
193
- actives.splice(0, actives.length, val);
194
- }
225
+ actives.splice(0, actives.length, ...toArray(val));
195
226
  }
196
227
  });
197
228
  const modelValue = computed({
@@ -201,7 +232,6 @@ const useSelectionList = defineHookComponent({
201
232
  },
202
233
  set(val) {
203
234
  emit("update:modelValue", val);
204
- emit("change", val);
205
235
  }
206
236
  });
207
237
  syncRef(currentValue, modelValue, { immediate: true, deep: true });
@@ -223,20 +253,25 @@ const useSelectionList = defineHookComponent({
223
253
  return actives.includes(value);
224
254
  }
225
255
  function changeActive(option) {
226
- if (isActive(option)) {
227
- if (props.multiple || props.clearable) {
228
- actives.splice(actives.indexOf(option), 1);
229
- }
230
- } else {
231
- if (props.multiple) {
232
- const limit = typeof props.multiple === "number" ? props.multiple : Infinity;
233
- if (actives.length < limit) {
234
- actives.push(option);
256
+ return __async(this, null, function* () {
257
+ const stopWatch = watch(currentValue, (val) => emit("change", val), { deep: true });
258
+ if (isActive(option)) {
259
+ if (props.multiple || props.clearable) {
260
+ actives.splice(actives.indexOf(option), 1);
235
261
  }
236
262
  } else {
237
- actives.splice(0, actives.length, option);
263
+ if (props.multiple) {
264
+ const limit = typeof props.multiple === "number" ? props.multiple : Infinity;
265
+ if (actives.length < limit) {
266
+ actives.push(option);
267
+ }
268
+ } else {
269
+ actives.splice(0, actives.length, option);
270
+ }
238
271
  }
239
- }
272
+ yield nextTick();
273
+ stopWatch();
274
+ });
240
275
  }
241
276
  provide(IsActiveSymbol, isActive);
242
277
  provide(ChangeActiveSymbol, changeActive);
@@ -331,14 +366,13 @@ const useSwitch = defineHookComponent({
331
366
  set(val) {
332
367
  checked.value = val;
333
368
  emit("update:modelValue", val);
334
- emit("change", val);
335
369
  }
336
370
  });
337
371
  const toggle = function(value) {
338
- if (typeof value === "boolean") {
339
- modelValue.value = value;
340
- } else {
341
- modelValue.value = !modelValue.value;
372
+ const oldValue = modelValue.value;
373
+ const newValue = typeof value === "boolean" ? value : !oldValue;
374
+ if (newValue !== oldValue) {
375
+ emit("change", newValue);
342
376
  }
343
377
  };
344
378
  const switchClass = computed(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hoci",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.esm.js",
@@ -8,17 +8,10 @@
8
8
  "files": [
9
9
  "dist/"
10
10
  ],
11
- "exports": {
12
- ".": {
13
- "import": "./dist/index.esm.js",
14
- "require": "./dist/index.cjs"
15
- },
16
- "./package.json": "./package.json"
17
- },
18
11
  "author": "chizuki",
19
12
  "license": "MIT",
20
13
  "dependencies": {
21
- "@vueuse/core": "^9.1.0",
14
+ "@vueuse/core": "^9.12.0",
22
15
  "maybe-types": "^0.0.3"
23
16
  },
24
17
  "devDependencies": {