hoci 0.0.2 → 0.0.4

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
@@ -56,7 +56,8 @@ const useSelectionItem = defineHookComponent({
56
56
  const parentLabel = core.resolveRef(vue.inject(ItemLabelSymbol));
57
57
  function render() {
58
58
  return vue.renderSlot(slots, "default", {}, () => {
59
- let label = props.label ?? parentLabel.value;
59
+ var _a;
60
+ let label = (_a = props.label) != null ? _a : parentLabel.value;
60
61
  if (label) {
61
62
  if (typeof label == "function") {
62
63
  label = label(props.value);
@@ -86,14 +87,22 @@ const useSelectionItem = defineHookComponent({
86
87
  }
87
88
  const isActive = vue.inject(IsActiveSymbol, () => false);
88
89
  const changeActive = vue.inject(ChangeActiveSymbol, () => false);
89
- const activeClass = vue.computed(() => vue.inject(ActiveClassSymbol)?.value ?? "active");
90
- const unactiveClass = vue.computed(() => vue.inject(UnactiveSymbol)?.value ?? "unactive");
90
+ const activeClass = vue.computed(() => {
91
+ var _a, _b;
92
+ return (_b = (_a = vue.inject(ActiveClassSymbol)) == null ? void 0 : _a.value) != null ? _b : "active";
93
+ });
94
+ const unactiveClass = vue.computed(() => {
95
+ var _a, _b;
96
+ return (_b = (_a = vue.inject(UnactiveSymbol)) == null ? void 0 : _a.value) != null ? _b : "unactive";
97
+ });
91
98
  const itemClass = vue.computed(() => {
92
- return [vue.inject(ItemClassSymbol)?.value ?? ""].concat(isActive(props.value) ? activeClass.value : unactiveClass.value);
99
+ var _a, _b;
100
+ return [(_b = (_a = vue.inject(ItemClassSymbol)) == null ? void 0 : _a.value) != null ? _b : ""].concat(isActive(props.value) ? activeClass.value : unactiveClass.value);
93
101
  });
94
102
  const activateEvent = core.resolveRef(() => {
103
+ var _a, _b;
95
104
  const event = vue.inject(ActivateEventSymbol);
96
- return props.activateEvent ?? event?.value ?? "click";
105
+ return (_b = (_a = props.activateEvent) != null ? _a : event == null ? void 0 : event.value) != null ? _b : "click";
97
106
  });
98
107
  return {
99
108
  activate() {
@@ -147,6 +156,9 @@ const selectionListProps = defineHookProps({
147
156
  type: [Boolean, Number],
148
157
  default: () => false
149
158
  },
159
+ clearable: {
160
+ type: Boolean
161
+ },
150
162
  defaultValue: {
151
163
  type: valuePropType
152
164
  },
@@ -160,6 +172,7 @@ const useSelectionList = defineHookComponent({
160
172
  props: selectionListProps,
161
173
  emits: selectionListEmits,
162
174
  setup(props, { slots, emit }) {
175
+ var _a;
163
176
  const options = vue.reactive([]);
164
177
  function toArray(value) {
165
178
  if (value === void 0) {
@@ -170,7 +183,7 @@ const useSelectionList = defineHookComponent({
170
183
  }
171
184
  return [value];
172
185
  }
173
- const actives = vue.reactive([...toArray(props.modelValue ?? props.defaultValue)]);
186
+ const actives = vue.reactive([...toArray((_a = props.modelValue) != null ? _a : props.defaultValue)]);
174
187
  const currentValue = vue.computed({
175
188
  get() {
176
189
  return props.multiple ? actives : actives[0];
@@ -185,16 +198,15 @@ const useSelectionList = defineHookComponent({
185
198
  });
186
199
  const modelValue = vue.computed({
187
200
  get() {
188
- return props.modelValue ?? props.defaultValue;
201
+ var _a2;
202
+ return (_a2 = props.modelValue) != null ? _a2 : props.defaultValue;
189
203
  },
190
204
  set(val) {
191
205
  emit("update:modelValue", val);
206
+ emit("change", val);
192
207
  }
193
208
  });
194
209
  core.syncRef(currentValue, modelValue, { immediate: true, deep: true });
195
- vue.watch(currentValue, (val) => {
196
- emit("change", val);
197
- }, { deep: true });
198
210
  vue.provide(
199
211
  ActiveClassSymbol,
200
212
  vue.computed(() => props.activeClass)
@@ -214,7 +226,7 @@ const useSelectionList = defineHookComponent({
214
226
  }
215
227
  function changeActive(option) {
216
228
  if (isActive(option)) {
217
- if (props.multiple) {
229
+ if (props.multiple || props.clearable) {
218
230
  actives.splice(actives.indexOf(option), 1);
219
231
  }
220
232
  } else {
@@ -315,7 +327,8 @@ const useSwitch = defineHookComponent({
315
327
  );
316
328
  const modelValue = vue.computed({
317
329
  get() {
318
- return !!(props.modelValue ?? checked.value);
330
+ var _a;
331
+ return !!((_a = props.modelValue) != null ? _a : checked.value);
319
332
  },
320
333
  set(val) {
321
334
  checked.value = val;
@@ -365,6 +378,7 @@ exports.defineHookProps = defineHookProps;
365
378
  exports.selectionItemProps = selectionItemProps;
366
379
  exports.selectionListEmits = selectionListEmits;
367
380
  exports.selectionListProps = selectionListProps;
381
+ exports.switchEmits = switchEmits;
368
382
  exports.switchProps = switchProps;
369
383
  exports.useSelectionItem = useSelectionItem;
370
384
  exports.useSelectionList = useSelectionList;
package/dist/index.d.ts CHANGED
@@ -133,10 +133,16 @@ declare const selectionListProps: {
133
133
  modelValue: {
134
134
  type: PropType<any>;
135
135
  };
136
+ /**
137
+ * 选中时的 class
138
+ */
136
139
  activeClass: {
137
140
  type: PropType<string | string[]>;
138
141
  default: string;
139
142
  };
143
+ /**
144
+ * 每个选项的 class
145
+ */
140
146
  itemClass: {
141
147
  type: PropType<string | string[]>;
142
148
  default: string;
@@ -155,6 +161,12 @@ declare const selectionListProps: {
155
161
  type: (BooleanConstructor | NumberConstructor)[];
156
162
  default: () => false;
157
163
  };
164
+ /**
165
+ * 可清除
166
+ */
167
+ clearable: {
168
+ type: BooleanConstructor;
169
+ };
158
170
  defaultValue: {
159
171
  type: PropType<any>;
160
172
  };
@@ -186,10 +198,16 @@ declare const useSelectionList: HookComponent<{
186
198
  modelValue: {
187
199
  type: PropType<any>;
188
200
  };
201
+ /**
202
+ * 选中时的 class
203
+ */
189
204
  activeClass: {
190
205
  type: PropType<string | string[]>;
191
206
  default: string;
192
207
  };
208
+ /**
209
+ * 每个选项的 class
210
+ */
193
211
  itemClass: {
194
212
  type: PropType<string | string[]>;
195
213
  default: string;
@@ -208,6 +226,12 @@ declare const useSelectionList: HookComponent<{
208
226
  type: (BooleanConstructor | NumberConstructor)[];
209
227
  default: () => false;
210
228
  };
229
+ /**
230
+ * 可清除
231
+ */
232
+ clearable: {
233
+ type: BooleanConstructor;
234
+ };
211
235
  defaultValue: {
212
236
  type: PropType<any>;
213
237
  };
@@ -223,10 +247,16 @@ declare const useSelectionList: HookComponent<{
223
247
  modelValue: {
224
248
  type: PropType<any>;
225
249
  };
250
+ /**
251
+ * 选中时的 class
252
+ */
226
253
  activeClass: {
227
254
  type: PropType<string | string[]>;
228
255
  default: string;
229
256
  };
257
+ /**
258
+ * 每个选项的 class
259
+ */
230
260
  itemClass: {
231
261
  type: PropType<string | string[]>;
232
262
  default: string;
@@ -245,6 +275,12 @@ declare const useSelectionList: HookComponent<{
245
275
  type: (BooleanConstructor | NumberConstructor)[];
246
276
  default: () => false;
247
277
  };
278
+ /**
279
+ * 可清除
280
+ */
281
+ clearable: {
282
+ type: BooleanConstructor;
283
+ };
248
284
  defaultValue: {
249
285
  type: PropType<any>;
250
286
  };
@@ -261,10 +297,16 @@ declare const HiSelection: vue.DefineComponent<{
261
297
  modelValue: {
262
298
  type: PropType<any>;
263
299
  };
300
+ /**
301
+ * 选中时的 class
302
+ */
264
303
  activeClass: {
265
304
  type: PropType<string | string[]>;
266
305
  default: string;
267
306
  };
307
+ /**
308
+ * 每个选项的 class
309
+ */
268
310
  itemClass: {
269
311
  type: PropType<string | string[]>;
270
312
  default: string;
@@ -283,6 +325,12 @@ declare const HiSelection: vue.DefineComponent<{
283
325
  type: (BooleanConstructor | NumberConstructor)[];
284
326
  default: () => false;
285
327
  };
328
+ /**
329
+ * 可清除
330
+ */
331
+ clearable: {
332
+ type: BooleanConstructor;
333
+ };
286
334
  defaultValue: {
287
335
  type: PropType<any>;
288
336
  };
@@ -300,10 +348,16 @@ declare const HiSelection: vue.DefineComponent<{
300
348
  modelValue: {
301
349
  type: PropType<any>;
302
350
  };
351
+ /**
352
+ * 选中时的 class
353
+ */
303
354
  activeClass: {
304
355
  type: PropType<string | string[]>;
305
356
  default: string;
306
357
  };
358
+ /**
359
+ * 每个选项的 class
360
+ */
307
361
  itemClass: {
308
362
  type: PropType<string | string[]>;
309
363
  default: string;
@@ -322,6 +376,12 @@ declare const HiSelection: vue.DefineComponent<{
322
376
  type: (BooleanConstructor | NumberConstructor)[];
323
377
  default: () => false;
324
378
  };
379
+ /**
380
+ * 可清除
381
+ */
382
+ clearable: {
383
+ type: BooleanConstructor;
384
+ };
325
385
  defaultValue: {
326
386
  type: PropType<any>;
327
387
  };
@@ -341,6 +401,7 @@ declare const HiSelection: vue.DefineComponent<{
341
401
  tag: string;
342
402
  activeClass: string | string[];
343
403
  unactiveClass: string | string[];
404
+ clearable: boolean;
344
405
  }>;
345
406
 
346
407
  declare const switchProps: {
@@ -369,6 +430,7 @@ declare const switchProps: {
369
430
  default: string;
370
431
  };
371
432
  };
433
+ declare const switchEmits: ("update:modelValue" | "change")[];
372
434
  declare const useSwitch: HookComponent<{
373
435
  toggle: (value?: any) => void;
374
436
  modelValue: vue.WritableComputedRef<boolean>;
@@ -488,4 +550,4 @@ declare const HiSwitch: vue.DefineComponent<{
488
550
  unactiveClass: string | string[];
489
551
  }>;
490
552
 
491
- export { HiItem, HiSelection, HiSwitch, HookComponent, HookComponentOptions, defineHookComponent, defineHookEmits, defineHookProps, selectionItemProps, selectionListEmits, selectionListProps, switchProps, useSelectionItem, useSelectionList, useSwitch };
553
+ export { HiItem, HiSelection, HiSwitch, HookComponent, HookComponentOptions, defineHookComponent, defineHookEmits, defineHookProps, selectionItemProps, selectionListEmits, selectionListProps, switchEmits, switchProps, useSelectionItem, useSelectionList, useSwitch };
@@ -54,7 +54,8 @@ const useSelectionItem = defineHookComponent({
54
54
  const parentLabel = resolveRef(inject(ItemLabelSymbol));
55
55
  function render() {
56
56
  return renderSlot(slots, "default", {}, () => {
57
- let label = props.label ?? parentLabel.value;
57
+ var _a;
58
+ let label = (_a = props.label) != null ? _a : parentLabel.value;
58
59
  if (label) {
59
60
  if (typeof label == "function") {
60
61
  label = label(props.value);
@@ -84,14 +85,22 @@ const useSelectionItem = defineHookComponent({
84
85
  }
85
86
  const isActive = inject(IsActiveSymbol, () => false);
86
87
  const changeActive = inject(ChangeActiveSymbol, () => false);
87
- const activeClass = computed(() => inject(ActiveClassSymbol)?.value ?? "active");
88
- const unactiveClass = computed(() => inject(UnactiveSymbol)?.value ?? "unactive");
88
+ const activeClass = computed(() => {
89
+ var _a, _b;
90
+ return (_b = (_a = inject(ActiveClassSymbol)) == null ? void 0 : _a.value) != null ? _b : "active";
91
+ });
92
+ const unactiveClass = computed(() => {
93
+ var _a, _b;
94
+ return (_b = (_a = inject(UnactiveSymbol)) == null ? void 0 : _a.value) != null ? _b : "unactive";
95
+ });
89
96
  const itemClass = computed(() => {
90
- return [inject(ItemClassSymbol)?.value ?? ""].concat(isActive(props.value) ? activeClass.value : unactiveClass.value);
97
+ var _a, _b;
98
+ return [(_b = (_a = inject(ItemClassSymbol)) == null ? void 0 : _a.value) != null ? _b : ""].concat(isActive(props.value) ? activeClass.value : unactiveClass.value);
91
99
  });
92
100
  const activateEvent = resolveRef(() => {
101
+ var _a, _b;
93
102
  const event = inject(ActivateEventSymbol);
94
- return props.activateEvent ?? event?.value ?? "click";
103
+ return (_b = (_a = props.activateEvent) != null ? _a : event == null ? void 0 : event.value) != null ? _b : "click";
95
104
  });
96
105
  return {
97
106
  activate() {
@@ -145,6 +154,9 @@ const selectionListProps = defineHookProps({
145
154
  type: [Boolean, Number],
146
155
  default: () => false
147
156
  },
157
+ clearable: {
158
+ type: Boolean
159
+ },
148
160
  defaultValue: {
149
161
  type: valuePropType
150
162
  },
@@ -158,6 +170,7 @@ const useSelectionList = defineHookComponent({
158
170
  props: selectionListProps,
159
171
  emits: selectionListEmits,
160
172
  setup(props, { slots, emit }) {
173
+ var _a;
161
174
  const options = reactive([]);
162
175
  function toArray(value) {
163
176
  if (value === void 0) {
@@ -168,7 +181,7 @@ const useSelectionList = defineHookComponent({
168
181
  }
169
182
  return [value];
170
183
  }
171
- const actives = reactive([...toArray(props.modelValue ?? props.defaultValue)]);
184
+ const actives = reactive([...toArray((_a = props.modelValue) != null ? _a : props.defaultValue)]);
172
185
  const currentValue = computed({
173
186
  get() {
174
187
  return props.multiple ? actives : actives[0];
@@ -183,16 +196,15 @@ const useSelectionList = defineHookComponent({
183
196
  });
184
197
  const modelValue = computed({
185
198
  get() {
186
- return props.modelValue ?? props.defaultValue;
199
+ var _a2;
200
+ return (_a2 = props.modelValue) != null ? _a2 : props.defaultValue;
187
201
  },
188
202
  set(val) {
189
203
  emit("update:modelValue", val);
204
+ emit("change", val);
190
205
  }
191
206
  });
192
207
  syncRef(currentValue, modelValue, { immediate: true, deep: true });
193
- watch(currentValue, (val) => {
194
- emit("change", val);
195
- }, { deep: true });
196
208
  provide(
197
209
  ActiveClassSymbol,
198
210
  computed(() => props.activeClass)
@@ -212,7 +224,7 @@ const useSelectionList = defineHookComponent({
212
224
  }
213
225
  function changeActive(option) {
214
226
  if (isActive(option)) {
215
- if (props.multiple) {
227
+ if (props.multiple || props.clearable) {
216
228
  actives.splice(actives.indexOf(option), 1);
217
229
  }
218
230
  } else {
@@ -313,7 +325,8 @@ const useSwitch = defineHookComponent({
313
325
  );
314
326
  const modelValue = computed({
315
327
  get() {
316
- return !!(props.modelValue ?? checked.value);
328
+ var _a;
329
+ return !!((_a = props.modelValue) != null ? _a : checked.value);
317
330
  },
318
331
  set(val) {
319
332
  checked.value = val;
@@ -354,4 +367,4 @@ const HiSwitch = defineComponent({
354
367
  }
355
368
  });
356
369
 
357
- export { HiItem, HiSelection, HiSwitch, defineHookComponent, defineHookEmits, defineHookProps, selectionItemProps, selectionListEmits, selectionListProps, switchProps, useSelectionItem, useSelectionList, useSwitch };
370
+ export { HiItem, HiSelection, HiSwitch, defineHookComponent, defineHookEmits, defineHookProps, selectionItemProps, selectionListEmits, selectionListProps, switchEmits, switchProps, useSelectionItem, useSelectionList, useSwitch };
package/package.json CHANGED
@@ -1,21 +1,28 @@
1
1
  {
2
2
  "name": "hoci",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs",
6
- "module": "dist/index.mjs",
6
+ "module": "dist/index.esm.js",
7
7
  "types": "dist/index.d.ts",
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
+ },
11
18
  "author": "chizuki",
12
19
  "license": "MIT",
13
20
  "dependencies": {
14
- "@vueuse/core": "^9.5.0",
21
+ "@vueuse/core": "^9.1.0",
15
22
  "maybe-types": "^0.0.3"
16
23
  },
17
- "peerDependencies": {
18
- "vue": "^3.2.45"
24
+ "devDependencies": {
25
+ "vue": "^3.2.31"
19
26
  },
20
27
  "scripts": {
21
28
  "build": "unbuild",