bge-ui 1.4.3 → 1.4.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.js CHANGED
@@ -10590,14 +10590,22 @@ function toFixedPoint(str, e, z) {
10590
10590
  return str;
10591
10591
  }
10592
10592
  var BigNumber = clone();
10593
- const _hoisted_1$e = { class: "bge-slider__scale" };
10593
+ const _hoisted_1$e = {
10594
+ key: 0,
10595
+ class: "bge-slider__scale"
10596
+ };
10594
10597
  const _sfc_main$l = /* @__PURE__ */ defineComponent({
10595
10598
  __name: "index",
10596
10599
  props: {
10597
10600
  marks: {
10598
10601
  type: Object,
10599
- default: () => {
10600
- }
10602
+ default: () => ({
10603
+ 0: "",
10604
+ 25: "",
10605
+ 50: "",
10606
+ 75: "",
10607
+ 100: ""
10608
+ })
10601
10609
  },
10602
10610
  modelValue: {
10603
10611
  type: Number,
@@ -10632,7 +10640,6 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
10632
10640
  currentY: 0,
10633
10641
  startPosition: 0,
10634
10642
  newPosition: 0,
10635
- stopValue: 0,
10636
10643
  newValue: 0
10637
10644
  });
10638
10645
  function onDragStart(event) {
@@ -10704,21 +10711,51 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
10704
10711
  setTimeout(() => emit("blur"));
10705
10712
  }
10706
10713
  const tooltip = ref();
10714
+ const maxValue = computed(() => {
10715
+ if (props.marks) {
10716
+ return Object.keys(props.marks)[Object.keys(props.marks).length - 1];
10717
+ }
10718
+ return 100;
10719
+ });
10720
+ const minValue = computed(() => {
10721
+ if (props.marks) {
10722
+ return Object.keys(props.marks)[0];
10723
+ }
10724
+ return 0;
10725
+ });
10726
+ const marksPercents = computed(() => {
10727
+ const result = {};
10728
+ Object.keys(props.marks).forEach((mark) => {
10729
+ const percent = new BigNumber(new BigNumber(mark).minus(minValue.value)).div(new BigNumber(maxValue.value).minus(minValue.value)).multipliedBy(100).toFixed(0);
10730
+ result[mark] = percent;
10731
+ });
10732
+ return result;
10733
+ });
10734
+ const stopValue = computed(() => {
10735
+ let value = 0;
10736
+ Object.keys(props.marks).forEach((item, index2) => {
10737
+ if (props.modelValue >= Number(item)) {
10738
+ value = index2;
10739
+ }
10740
+ });
10741
+ return value;
10742
+ });
10707
10743
  function setPosition(percent) {
10708
10744
  state2.sliderBarStyle = `width: ${percent}%`;
10709
10745
  state2.sliderButtonStyle = `left: ${percent}%`;
10710
- state2.stopValue = Math.floor(percent / 100 * (Object.values(props.marks).length - 1));
10711
- state2.newValue = Math.floor(percent);
10746
+ state2.newValue = Math.floor(Number(new BigNumber(percent).div(100).multipliedBy(new BigNumber(maxValue.value).minus(minValue.value)).plus(minValue.value).toFixed(0)));
10712
10747
  emit("input", state2.newValue);
10713
10748
  emit("update:modelValue", state2.newValue);
10749
+ const newPercent = new BigNumber(new BigNumber(state2.newValue).minus(minValue.value)).div(new BigNumber(maxValue.value).minus(minValue.value)).multipliedBy(100).toFixed(0);
10750
+ if (newPercent !== percent) {
10751
+ setPosition(newPercent);
10752
+ }
10714
10753
  setTimeout(() => {
10715
10754
  tooltip.value && tooltip.value.popper.value && tooltip.value.popper.value.update();
10716
10755
  }, 50);
10717
10756
  }
10718
- watch(() => props.modelValue, (val) => {
10719
- let percent = val;
10720
- percent = percent > 100 ? 100 : percent;
10721
- percent = percent < 0 ? 0 : percent;
10757
+ watch(() => props.modelValue, () => {
10758
+ const percent = new BigNumber(new BigNumber(props.modelValue).minus(minValue.value)).div(new BigNumber(maxValue.value).minus(minValue.value)).multipliedBy(100).toFixed(0);
10722
10759
  setPosition(percent);
10723
10760
  }, {
10724
10761
  immediate: true
@@ -10771,15 +10808,15 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
10771
10808
  }, null, 32))
10772
10809
  ], 36),
10773
10810
  createElementVNode("div", {
10774
- class: normalizeClass(`bge-slider__stops bge-slider__stop-${state2.stopValue}`)
10811
+ class: normalizeClass(`bge-slider__stops bge-slider__stop-${stopValue.value}`)
10775
10812
  }, [
10776
10813
  (openBlock(true), createElementBlock(Fragment, null, renderList(__props.marks, (mark, key) => {
10777
10814
  return openBlock(), createElementBlock("div", {
10778
10815
  key,
10779
10816
  class: "bge-slider__stop",
10780
- style: normalizeStyle(`left: ${key}%;`)
10817
+ style: normalizeStyle(`left: ${marksPercents.value[key]}%;`)
10781
10818
  }, [
10782
- createElementVNode("div", _hoisted_1$e, toDisplayString(mark), 1)
10819
+ mark ? (openBlock(), createElementBlock("div", _hoisted_1$e, toDisplayString(mark), 1)) : createCommentVNode("", true)
10783
10820
  ], 4);
10784
10821
  }), 128))
10785
10822
  ], 2)
@@ -1,7 +1,13 @@
1
1
  declare const _default: import("vue").DefineComponent<{
2
2
  marks: {
3
3
  type: ObjectConstructor;
4
- default: () => void;
4
+ default: () => {
5
+ 0: string;
6
+ 25: string;
7
+ 50: string;
8
+ 75: string;
9
+ 100: string;
10
+ };
5
11
  };
6
12
  modelValue: {
7
13
  type: NumberConstructor;
@@ -27,7 +33,13 @@ declare const _default: import("vue").DefineComponent<{
27
33
  }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
28
34
  marks: {
29
35
  type: ObjectConstructor;
30
- default: () => void;
36
+ default: () => {
37
+ 0: string;
38
+ 25: string;
39
+ 50: string;
40
+ 75: string;
41
+ 100: string;
42
+ };
31
43
  };
32
44
  modelValue: {
33
45
  type: NumberConstructor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bge-ui",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -15,23 +15,29 @@
15
15
 
16
16
  <div v-else class="slider-button" @mouseover="state.hovering = true" @mouseleave="state.hovering = false"></div>
17
17
  </div>
18
- <div :class="`bge-slider__stops bge-slider__stop-${state.stopValue}`">
19
- <div v-for="(mark, key) in marks" :key="key" class="bge-slider__stop" :style="`left: ${key}%;`">
20
- <div class="bge-slider__scale">{{ mark }}</div>
18
+ <div :class="`bge-slider__stops bge-slider__stop-${stopValue}`">
19
+ <div v-for="(mark, key) in marks" :key="key" class="bge-slider__stop" :style="`left: ${marksPercents[key]}%;`">
20
+ <div v-if="mark" class="bge-slider__scale">{{ mark }} </div>
21
21
  </div>
22
22
  </div>
23
23
  </div>
24
24
  </div>
25
25
  </template>
26
26
  <script lang="ts" setup>
27
- import { ref, reactive, watch } from 'vue'
27
+ import { ref, reactive, watch, computed } from 'vue'
28
28
  import UiTooltip from '../tooltip/index.vue'
29
29
  import BigNumber from 'bignumber.js'
30
30
 
31
31
  const props = defineProps({
32
32
  marks: {
33
33
  type: Object,
34
- default: () => {}
34
+ default: () => ({
35
+ 0: '',
36
+ 25: '',
37
+ 50: '',
38
+ 75: '',
39
+ 100: ''
40
+ })
35
41
  },
36
42
  modelValue: {
37
43
  type: Number,
@@ -63,7 +69,6 @@ const state = reactive({
63
69
  currentY: 0,
64
70
  startPosition: 0,
65
71
  newPosition: 0,
66
- stopValue: 0,
67
72
  newValue: 0
68
73
  })
69
74
 
@@ -149,22 +154,63 @@ function onSliderClick (event: any) {
149
154
 
150
155
  const tooltip = ref()
151
156
 
152
- function setPosition (percent: any) {
157
+ const maxValue = computed(() => {
158
+ if (props.marks) {
159
+ return Object.keys(props.marks)[Object.keys(props.marks).length - 1]
160
+ }
161
+ return 100
162
+ })
163
+
164
+ const minValue = computed(() => {
165
+ if (props.marks) {
166
+ return Object.keys(props.marks)[0]
167
+ }
168
+ return 0
169
+ })
170
+
171
+ const marksPercents = computed(() => {
172
+ const result: any = {}
173
+ Object.keys(props.marks).forEach((mark: string) => {
174
+ const percent = new BigNumber(new BigNumber(mark).minus(minValue.value)).div(new BigNumber(maxValue.value).minus(minValue.value)).multipliedBy(100).toFixed(0)
175
+ result[mark] = percent
176
+ })
177
+ return result
178
+ })
179
+
180
+ // const percent = computed(() => {
181
+ // return new BigNumber(new BigNumber(props.modelValue).minus(minValue.value)).div(new BigNumber(maxValue.value).minus(minValue.value)).multipliedBy(100).toFixed(0)
182
+ // })
183
+
184
+ const stopValue = computed(() => {
185
+ let value = 0
186
+ Object.keys(props.marks).forEach(((item: string, index: number) => {
187
+ if (props.modelValue >= Number(item)) {
188
+ value = index
189
+ }
190
+ }))
191
+ return value
192
+ })
193
+
194
+ function setPosition (percent: string) {
153
195
  state.sliderBarStyle = `width: ${percent}%`
154
196
  state.sliderButtonStyle = `left: ${percent}%`
155
- state.stopValue = Math.floor(percent / 100 * (Object.values(props.marks).length - 1))
156
- state.newValue = Math.floor(percent)
197
+ // state.stopValue = Math.floor(Number(percent.value) / 100 * (Object.values(props.marks).length - 1))
198
+ // state.newValue = Math.floor(Number(percent.value))
199
+ // state.stopValue = Number(new BigNumber(percent).div(100).multipliedBy(new BigNumber(maxValue.value).minus(minValue.value)).plus(minValue.value).toFixed(0))
200
+ state.newValue = Math.floor(Number(new BigNumber(percent).div(100).multipliedBy(new BigNumber(maxValue.value).minus(minValue.value)).plus(minValue.value).toFixed(0)))
157
201
  emit('input', state.newValue)
158
202
  emit('update:modelValue', state.newValue)
203
+ const newPercent = new BigNumber(new BigNumber(state.newValue).minus(minValue.value)).div(new BigNumber(maxValue.value).minus(minValue.value)).multipliedBy(100).toFixed(0)
204
+ if (newPercent !== percent) {
205
+ setPosition(newPercent)
206
+ }
159
207
  setTimeout(() => {
160
208
  tooltip.value && tooltip.value.popper.value && tooltip.value.popper.value.update()
161
209
  }, 50)
162
210
  }
163
211
 
164
- watch(() => props.modelValue, (val: number) => {
165
- let percent = val
166
- percent = percent > 100 ? 100 : percent
167
- percent = percent < 0 ? 0 : percent
212
+ watch(() => props.modelValue, () => {
213
+ const percent = new BigNumber(new BigNumber(props.modelValue).minus(minValue.value)).div(new BigNumber(maxValue.value).minus(minValue.value)).multipliedBy(100).toFixed(0)
168
214
  setPosition(percent)
169
215
  }, {
170
216
  immediate: true