@hoci/core 0.4.2 → 0.5.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
@@ -19,7 +19,10 @@ const affixProps = shared.defineHookProps(
19
19
  type: Number,
20
20
  default: 0
21
21
  },
22
- offsetType: {
22
+ /**
23
+ * @zh 固定的相对方向
24
+ */
25
+ position: {
23
26
  type: String,
24
27
  default: "top"
25
28
  },
@@ -52,6 +55,7 @@ const useAffix = shared.defineHookComponent({
52
55
  props: affixProps,
53
56
  setup(props, { emit }) {
54
57
  const wrapperRef = vue.ref(null);
58
+ const wrapperRect = core.toReactive(core.useElementBounding(wrapperRef));
55
59
  const parentRef = vue.inject(AFFIX_TARGET_KEY, void 0);
56
60
  const targetRef = shared.useElement(props.target, parentRef);
57
61
  const isFixed = vue.ref(false);
@@ -71,27 +75,30 @@ const useAffix = shared.defineHookComponent({
71
75
  if (!wrapperRef.value || !containerRef.value) {
72
76
  return;
73
77
  }
74
- const wrapperRect = wrapperRef.value.getBoundingClientRect();
78
+ const area = wrapperRect.width * wrapperRect.height;
79
+ if (area === 0) {
80
+ return;
81
+ }
82
+ const newPlaceholderStyles = {
83
+ width: tslx.px(wrapperRect.width),
84
+ height: tslx.px(wrapperRect.height)
85
+ };
75
86
  const targetRect = getTargetRect(containerRef.value);
76
87
  let newIsFixed = false;
77
88
  let newFixedStyles = {};
78
- const newPlaceholderStyles = {
79
- width: `${wrapperRef.value.offsetWidth}px`,
80
- height: `${wrapperRef.value.offsetHeight}px`
81
- };
82
89
  const offset = props.offset;
83
- if (props.offsetType === "top") {
90
+ if (props.position === "top") {
84
91
  newIsFixed = wrapperRect.top - targetRect.top < offset && offset >= 0;
85
92
  newFixedStyles = newIsFixed ? {
86
93
  position: "fixed",
87
94
  zIndex: props.zIndex,
88
- top: `${targetRect.top + (offset || 0)}px`
95
+ top: tslx.px(targetRect.top + offset)
89
96
  } : {};
90
97
  } else {
91
- newIsFixed = targetRect.bottom - wrapperRect.bottom < (offset || 0);
98
+ newIsFixed = targetRect.bottom - wrapperRect.bottom < offset;
92
99
  newFixedStyles = newIsFixed ? {
93
100
  position: "fixed",
94
- bottom: `${window.innerHeight - targetRect.bottom + (offset || 0)}px`
101
+ bottom: tslx.px(window.innerHeight - targetRect.bottom + offset)
95
102
  } : {};
96
103
  }
97
104
  if (newIsFixed !== isFixed.value) {
@@ -201,7 +208,7 @@ function useSelectionContext() {
201
208
  const useSelectionList = shared.defineHookComponent({
202
209
  props: selectionProps,
203
210
  emits: selectionEmits,
204
- setup(props, { emit }) {
211
+ setup(props, { emit, slots }) {
205
212
  const options = vue.reactive([]);
206
213
  function toArray(value) {
207
214
  if (!core.isDefined(value)) {
@@ -289,16 +296,25 @@ const useSelectionList = shared.defineHookComponent({
289
296
  isActive,
290
297
  init
291
298
  }));
292
- function renderItem() {
299
+ const renderItem = () => {
293
300
  const children = options.filter((e) => actives.includes(e.value)).map((e) => e.render());
294
301
  return props.multiple ? children : children[0];
295
- }
302
+ };
303
+ const slotData = {
304
+ isActive,
305
+ changeActive,
306
+ renderItem
307
+ };
308
+ const render = () => {
309
+ return vue.renderSlot(slots, "default", slotData);
310
+ };
296
311
  return {
297
312
  options,
298
313
  actives,
299
314
  isActive,
300
315
  changeActive,
301
- renderItem
316
+ renderItem,
317
+ render
302
318
  };
303
319
  }
304
320
  });
@@ -338,16 +354,19 @@ const useSelectionItem = shared.defineHookComponent({
338
354
  }
339
355
  context.changeActive(props.value);
340
356
  };
357
+ const label = vue.computed(() => {
358
+ let label2 = props.label ?? context.label;
359
+ if (label2 && typeof label2 == "function") {
360
+ label2 = label2(props.value);
361
+ }
362
+ return Array.isArray(label2) ? label2 : [label2];
363
+ });
341
364
  function render() {
342
365
  return vue.renderSlot(slots, "default", {
343
366
  active: context.isActive(props.value),
344
367
  activate
345
368
  }, () => {
346
- let label = props.label ?? context.label;
347
- if (label && typeof label == "function") {
348
- label = label(props.value);
349
- }
350
- return Array.isArray(label) ? label : [label];
369
+ return label.value;
351
370
  });
352
371
  }
353
372
  let remove = () => {
@@ -387,7 +406,8 @@ const useSelectionItem = shared.defineHookComponent({
387
406
  isActive,
388
407
  isDisabled,
389
408
  className,
390
- activateEvent
409
+ activateEvent,
410
+ label
391
411
  };
392
412
  }
393
413
  });
@@ -490,11 +510,12 @@ const useIcon = shared.defineHookComponent({
490
510
  const sharedConfig = shared.useSharedConfig("icon");
491
511
  const sizeStyle = vue.computed(() => {
492
512
  const s = props.size ?? sharedConfig.size;
493
- const size = s ? tslx.unit_f(s, sharedConfig.sizeUnit) : void 0;
513
+ const unit = tslx.createUnitFormat(sharedConfig.sizeUnit ?? "px");
514
+ const size = s ? unit(s) : void 0;
494
515
  const w = props.width ?? size;
495
516
  const h = props.height ?? size;
496
- const width = w ? tslx.unit_f(w, sharedConfig.sizeUnit) : void 0;
497
- const height = h ? tslx.unit_f(h, sharedConfig.sizeUnit) : void 0;
517
+ const width = w ? unit(w) : void 0;
518
+ const height = h ? unit(h) : void 0;
498
519
  return {
499
520
  width,
500
521
  height
package/dist/index.d.cts CHANGED
@@ -18,7 +18,10 @@ declare const affixProps: {
18
18
  type: NumberConstructor;
19
19
  default: number;
20
20
  };
21
- offsetType: {
21
+ /**
22
+ * @zh 固定的相对方向
23
+ */
24
+ position: {
22
25
  type: PropType<"top" | "bottom">;
23
26
  default: string;
24
27
  };
@@ -62,7 +65,10 @@ declare const useAffix: _hoci_shared.HookComponent<{
62
65
  type: NumberConstructor;
63
66
  default: number;
64
67
  };
65
- offsetType: {
68
+ /**
69
+ * @zh 固定的相对方向
70
+ */
71
+ position: {
66
72
  type: PropType<"top" | "bottom">;
67
73
  default: string;
68
74
  };
@@ -94,7 +100,10 @@ declare const useAffix: _hoci_shared.HookComponent<{
94
100
  type: NumberConstructor;
95
101
  default: number;
96
102
  };
97
- offsetType: {
103
+ /**
104
+ * @zh 固定的相对方向
105
+ */
106
+ position: {
98
107
  type: PropType<"top" | "bottom">;
99
108
  default: string;
100
109
  };
@@ -116,7 +125,7 @@ declare const useAffix: _hoci_shared.HookComponent<{
116
125
  }>, {
117
126
  fixedClass: string;
118
127
  offset: number;
119
- offsetType: "top" | "bottom";
128
+ position: "top" | "bottom";
120
129
  zIndex: number;
121
130
  }>;
122
131
  declare function provideAffixTarget(target: MaybeRefOrGetter<Element | null | undefined>): void;
@@ -205,6 +214,9 @@ declare const useSelectionList: _hoci_shared.HookComponent<{
205
214
  isActive: (value: any) => boolean;
206
215
  changeActive: (value: any) => void;
207
216
  renderItem: () => ElementLike;
217
+ render: () => vue.VNode<vue.RendererNode, vue.RendererElement, {
218
+ [key: string]: any;
219
+ }>;
208
220
  }, ("change" | "load" | "unload" | "update:modelValue")[], {
209
221
  modelValue: {
210
222
  type: PropType<any>;
@@ -353,6 +365,7 @@ declare const useSelectionItem: _hoci_shared.HookComponent<{
353
365
  isDisabled: vue.ComputedRef<boolean>;
354
366
  className: vue.ComputedRef<string>;
355
367
  activateEvent: vue.ComputedRef<ActivateEvent>;
368
+ label: vue.ComputedRef<ElementLike[] | (string | JSX.Element | null | undefined)[]>;
356
369
  }, vue.EmitsOptions, {
357
370
  value: {
358
371
  type: PropType<any>;
package/dist/index.d.mts CHANGED
@@ -18,7 +18,10 @@ declare const affixProps: {
18
18
  type: NumberConstructor;
19
19
  default: number;
20
20
  };
21
- offsetType: {
21
+ /**
22
+ * @zh 固定的相对方向
23
+ */
24
+ position: {
22
25
  type: PropType<"top" | "bottom">;
23
26
  default: string;
24
27
  };
@@ -62,7 +65,10 @@ declare const useAffix: _hoci_shared.HookComponent<{
62
65
  type: NumberConstructor;
63
66
  default: number;
64
67
  };
65
- offsetType: {
68
+ /**
69
+ * @zh 固定的相对方向
70
+ */
71
+ position: {
66
72
  type: PropType<"top" | "bottom">;
67
73
  default: string;
68
74
  };
@@ -94,7 +100,10 @@ declare const useAffix: _hoci_shared.HookComponent<{
94
100
  type: NumberConstructor;
95
101
  default: number;
96
102
  };
97
- offsetType: {
103
+ /**
104
+ * @zh 固定的相对方向
105
+ */
106
+ position: {
98
107
  type: PropType<"top" | "bottom">;
99
108
  default: string;
100
109
  };
@@ -116,7 +125,7 @@ declare const useAffix: _hoci_shared.HookComponent<{
116
125
  }>, {
117
126
  fixedClass: string;
118
127
  offset: number;
119
- offsetType: "top" | "bottom";
128
+ position: "top" | "bottom";
120
129
  zIndex: number;
121
130
  }>;
122
131
  declare function provideAffixTarget(target: MaybeRefOrGetter<Element | null | undefined>): void;
@@ -205,6 +214,9 @@ declare const useSelectionList: _hoci_shared.HookComponent<{
205
214
  isActive: (value: any) => boolean;
206
215
  changeActive: (value: any) => void;
207
216
  renderItem: () => ElementLike;
217
+ render: () => vue.VNode<vue.RendererNode, vue.RendererElement, {
218
+ [key: string]: any;
219
+ }>;
208
220
  }, ("change" | "load" | "unload" | "update:modelValue")[], {
209
221
  modelValue: {
210
222
  type: PropType<any>;
@@ -353,6 +365,7 @@ declare const useSelectionItem: _hoci_shared.HookComponent<{
353
365
  isDisabled: vue.ComputedRef<boolean>;
354
366
  className: vue.ComputedRef<string>;
355
367
  activateEvent: vue.ComputedRef<ActivateEvent>;
368
+ label: vue.ComputedRef<ElementLike[] | (string | JSX.Element | null | undefined)[]>;
356
369
  }, vue.EmitsOptions, {
357
370
  value: {
358
371
  type: PropType<any>;
package/dist/index.d.ts CHANGED
@@ -18,7 +18,10 @@ declare const affixProps: {
18
18
  type: NumberConstructor;
19
19
  default: number;
20
20
  };
21
- offsetType: {
21
+ /**
22
+ * @zh 固定的相对方向
23
+ */
24
+ position: {
22
25
  type: PropType<"top" | "bottom">;
23
26
  default: string;
24
27
  };
@@ -62,7 +65,10 @@ declare const useAffix: _hoci_shared.HookComponent<{
62
65
  type: NumberConstructor;
63
66
  default: number;
64
67
  };
65
- offsetType: {
68
+ /**
69
+ * @zh 固定的相对方向
70
+ */
71
+ position: {
66
72
  type: PropType<"top" | "bottom">;
67
73
  default: string;
68
74
  };
@@ -94,7 +100,10 @@ declare const useAffix: _hoci_shared.HookComponent<{
94
100
  type: NumberConstructor;
95
101
  default: number;
96
102
  };
97
- offsetType: {
103
+ /**
104
+ * @zh 固定的相对方向
105
+ */
106
+ position: {
98
107
  type: PropType<"top" | "bottom">;
99
108
  default: string;
100
109
  };
@@ -116,7 +125,7 @@ declare const useAffix: _hoci_shared.HookComponent<{
116
125
  }>, {
117
126
  fixedClass: string;
118
127
  offset: number;
119
- offsetType: "top" | "bottom";
128
+ position: "top" | "bottom";
120
129
  zIndex: number;
121
130
  }>;
122
131
  declare function provideAffixTarget(target: MaybeRefOrGetter<Element | null | undefined>): void;
@@ -205,6 +214,9 @@ declare const useSelectionList: _hoci_shared.HookComponent<{
205
214
  isActive: (value: any) => boolean;
206
215
  changeActive: (value: any) => void;
207
216
  renderItem: () => ElementLike;
217
+ render: () => vue.VNode<vue.RendererNode, vue.RendererElement, {
218
+ [key: string]: any;
219
+ }>;
208
220
  }, ("change" | "load" | "unload" | "update:modelValue")[], {
209
221
  modelValue: {
210
222
  type: PropType<any>;
@@ -353,6 +365,7 @@ declare const useSelectionItem: _hoci_shared.HookComponent<{
353
365
  isDisabled: vue.ComputedRef<boolean>;
354
366
  className: vue.ComputedRef<string>;
355
367
  activateEvent: vue.ComputedRef<ActivateEvent>;
368
+ label: vue.ComputedRef<ElementLike[] | (string | JSX.Element | null | undefined)[]>;
356
369
  }, vue.EmitsOptions, {
357
370
  value: {
358
371
  type: PropType<any>;
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { ref, inject, computed, watchPostEffect, provide, reactive, watch, renderSlot } from 'vue';
2
- import { useElementVisibility, useEventListener, syncRef, toReactive, isDefined, tryOnScopeDispose, useVModel } from '@vueuse/core';
1
+ import { ref, inject, computed, watchPostEffect, provide, reactive, renderSlot, watch } from 'vue';
2
+ import { toReactive, useElementBounding, useElementVisibility, useEventListener, syncRef, isDefined, tryOnScopeDispose, useVModel } from '@vueuse/core';
3
3
  import { defineHookProps, defineHookEmits, defineHookComponent, useElement, throttleByRaf, isWindow, valuePropType, classPropType, labelPropType, useSharedConfig } from '@hoci/shared';
4
4
  export * from '@hoci/shared';
5
- import { cls, unit_f } from 'tslx';
5
+ import { px, cls, createUnitFormat } from 'tslx';
6
6
 
7
7
  const affixProps = defineHookProps(
8
8
  {
@@ -18,7 +18,10 @@ const affixProps = defineHookProps(
18
18
  type: Number,
19
19
  default: 0
20
20
  },
21
- offsetType: {
21
+ /**
22
+ * @zh 固定的相对方向
23
+ */
24
+ position: {
22
25
  type: String,
23
26
  default: "top"
24
27
  },
@@ -51,6 +54,7 @@ const useAffix = defineHookComponent({
51
54
  props: affixProps,
52
55
  setup(props, { emit }) {
53
56
  const wrapperRef = ref(null);
57
+ const wrapperRect = toReactive(useElementBounding(wrapperRef));
54
58
  const parentRef = inject(AFFIX_TARGET_KEY, void 0);
55
59
  const targetRef = useElement(props.target, parentRef);
56
60
  const isFixed = ref(false);
@@ -70,27 +74,30 @@ const useAffix = defineHookComponent({
70
74
  if (!wrapperRef.value || !containerRef.value) {
71
75
  return;
72
76
  }
73
- const wrapperRect = wrapperRef.value.getBoundingClientRect();
77
+ const area = wrapperRect.width * wrapperRect.height;
78
+ if (area === 0) {
79
+ return;
80
+ }
81
+ const newPlaceholderStyles = {
82
+ width: px(wrapperRect.width),
83
+ height: px(wrapperRect.height)
84
+ };
74
85
  const targetRect = getTargetRect(containerRef.value);
75
86
  let newIsFixed = false;
76
87
  let newFixedStyles = {};
77
- const newPlaceholderStyles = {
78
- width: `${wrapperRef.value.offsetWidth}px`,
79
- height: `${wrapperRef.value.offsetHeight}px`
80
- };
81
88
  const offset = props.offset;
82
- if (props.offsetType === "top") {
89
+ if (props.position === "top") {
83
90
  newIsFixed = wrapperRect.top - targetRect.top < offset && offset >= 0;
84
91
  newFixedStyles = newIsFixed ? {
85
92
  position: "fixed",
86
93
  zIndex: props.zIndex,
87
- top: `${targetRect.top + (offset || 0)}px`
94
+ top: px(targetRect.top + offset)
88
95
  } : {};
89
96
  } else {
90
- newIsFixed = targetRect.bottom - wrapperRect.bottom < (offset || 0);
97
+ newIsFixed = targetRect.bottom - wrapperRect.bottom < offset;
91
98
  newFixedStyles = newIsFixed ? {
92
99
  position: "fixed",
93
- bottom: `${window.innerHeight - targetRect.bottom + (offset || 0)}px`
100
+ bottom: px(window.innerHeight - targetRect.bottom + offset)
94
101
  } : {};
95
102
  }
96
103
  if (newIsFixed !== isFixed.value) {
@@ -200,7 +207,7 @@ function useSelectionContext() {
200
207
  const useSelectionList = defineHookComponent({
201
208
  props: selectionProps,
202
209
  emits: selectionEmits,
203
- setup(props, { emit }) {
210
+ setup(props, { emit, slots }) {
204
211
  const options = reactive([]);
205
212
  function toArray(value) {
206
213
  if (!isDefined(value)) {
@@ -288,16 +295,25 @@ const useSelectionList = defineHookComponent({
288
295
  isActive,
289
296
  init
290
297
  }));
291
- function renderItem() {
298
+ const renderItem = () => {
292
299
  const children = options.filter((e) => actives.includes(e.value)).map((e) => e.render());
293
300
  return props.multiple ? children : children[0];
294
- }
301
+ };
302
+ const slotData = {
303
+ isActive,
304
+ changeActive,
305
+ renderItem
306
+ };
307
+ const render = () => {
308
+ return renderSlot(slots, "default", slotData);
309
+ };
295
310
  return {
296
311
  options,
297
312
  actives,
298
313
  isActive,
299
314
  changeActive,
300
- renderItem
315
+ renderItem,
316
+ render
301
317
  };
302
318
  }
303
319
  });
@@ -337,16 +353,19 @@ const useSelectionItem = defineHookComponent({
337
353
  }
338
354
  context.changeActive(props.value);
339
355
  };
356
+ const label = computed(() => {
357
+ let label2 = props.label ?? context.label;
358
+ if (label2 && typeof label2 == "function") {
359
+ label2 = label2(props.value);
360
+ }
361
+ return Array.isArray(label2) ? label2 : [label2];
362
+ });
340
363
  function render() {
341
364
  return renderSlot(slots, "default", {
342
365
  active: context.isActive(props.value),
343
366
  activate
344
367
  }, () => {
345
- let label = props.label ?? context.label;
346
- if (label && typeof label == "function") {
347
- label = label(props.value);
348
- }
349
- return Array.isArray(label) ? label : [label];
368
+ return label.value;
350
369
  });
351
370
  }
352
371
  let remove = () => {
@@ -386,7 +405,8 @@ const useSelectionItem = defineHookComponent({
386
405
  isActive,
387
406
  isDisabled,
388
407
  className,
389
- activateEvent
408
+ activateEvent,
409
+ label
390
410
  };
391
411
  }
392
412
  });
@@ -489,11 +509,12 @@ const useIcon = defineHookComponent({
489
509
  const sharedConfig = useSharedConfig("icon");
490
510
  const sizeStyle = computed(() => {
491
511
  const s = props.size ?? sharedConfig.size;
492
- const size = s ? unit_f(s, sharedConfig.sizeUnit) : void 0;
512
+ const unit = createUnitFormat(sharedConfig.sizeUnit ?? "px");
513
+ const size = s ? unit(s) : void 0;
493
514
  const w = props.width ?? size;
494
515
  const h = props.height ?? size;
495
- const width = w ? unit_f(w, sharedConfig.sizeUnit) : void 0;
496
- const height = h ? unit_f(h, sharedConfig.sizeUnit) : void 0;
516
+ const width = w ? unit(w) : void 0;
517
+ const height = h ? unit(h) : void 0;
497
518
  return {
498
519
  width,
499
520
  height
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hoci/core",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "",
5
5
  "author": "chizuki",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "@vueuse/core": "^10.5.0",
27
27
  "maybe-types": "^0.1.0",
28
28
  "tslx": "^0.1.1",
29
- "@hoci/shared": "0.4.2"
29
+ "@hoci/shared": "0.5.0"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "unbuild",