@mptw/skylens-ui 1.4.95 → 1.4.97

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.
@@ -2,13 +2,11 @@
2
2
  .checkbox(:class='[checkboxClass, { inactive: !interactive }]')
3
3
  input(
4
4
  type='checkbox',
5
- :id='uid',
6
5
  :checked='isChecked',
7
6
  :value='value',
8
7
  :disabled='disabled',
9
- @change='onChanged'
10
8
  )
11
- label(:for='uid', :class='{ "is-check-some": isCheckSome }')
9
+ label(:class='{ "is-check-some": isCheckSome }', @click='onClickedLabel')
12
10
  SLIcon.icon-square(:icon='falseIcon')
13
11
  SLIcon.icon-check-square(:icon='trueIcon')
14
12
  SLIcon.icon-minus-square(icon='minus-square')
@@ -18,6 +16,7 @@
18
16
 
19
17
  <script lang="ts">
20
18
  import { isEqual } from "lodash-es";
19
+ import type IInputOption from "~ui/interface/IInputOption";
21
20
  import { getUID } from "~ui/utils";
22
21
 
23
22
  export default defineComponent({
@@ -69,10 +68,18 @@ export default defineComponent({
69
68
  type: Boolean,
70
69
  default: true,
71
70
  },
71
+ options: {
72
+ type: Array as PropType<IInputOption[] | undefined>,
73
+ default: () => undefined,
74
+ },
75
+ lastCheckValue: {
76
+ type: [Number, String, Boolean, Object],
77
+ default: null,
78
+ },
72
79
  },
73
- emits: ["update:modelValue"],
80
+ emits: ["update:modelValue", 'update:lastCheckValue'],
74
81
  setup(props, { emit }) {
75
- const { size, disabled, modelValue, trueValue, falseValue, value } =
82
+ const { size, disabled, modelValue, trueValue, falseValue, value, options, lastCheckValue } =
76
83
  toRefs(props);
77
84
  const uid = ref<string | undefined>(undefined);
78
85
 
@@ -94,29 +101,42 @@ export default defineComponent({
94
101
  return modelValue.value === trueValue.value;
95
102
  });
96
103
 
97
- function onChanged(e: Event) {
104
+ function onClickedLabel(e: MouseEvent) {
98
105
  if (disabled.value) {
99
106
  return;
100
107
  }
101
108
 
102
- const isChecked = (e.target as HTMLInputElement).checked;
103
-
104
109
  if (Array.isArray(modelValue.value)) {
105
- let newValue = [...modelValue.value];
106
-
107
- if (isChecked) {
108
- newValue.push(value.value);
110
+ const valueSet: Set<any> = new Set(modelValue.value);
111
+
112
+ const lastCheckIndex = lastCheckValue.value === null || lastCheckValue.value === undefined || !options.value ? -1 : options.value.findIndex((o) => isEqual(o.value, lastCheckValue.value));
113
+ const currentCheckIndex = options.value?.findIndex((o) => isEqual(o.value, value.value)) || -1;
114
+
115
+ if (!options.value || lastCheckIndex === -1 || lastCheckIndex === currentCheckIndex || !e.shiftKey) {
116
+ if (isChecked.value) {
117
+ valueSet.delete(value.value);
118
+ emit("update:lastCheckValue", null);
119
+ } else {
120
+ valueSet.add(value.value);
121
+ emit('update:lastCheckValue', value.value);
122
+ }
109
123
  } else {
110
- newValue = newValue.filter((v) => v !== value.value);
124
+ emit("update:lastCheckValue", null);
125
+ const start = lastCheckIndex < currentCheckIndex ? lastCheckIndex : currentCheckIndex;
126
+ const end = lastCheckIndex < currentCheckIndex ? currentCheckIndex : lastCheckIndex;
127
+ options.value.slice(start, end + 1).forEach((o) => {
128
+ if (o.disabled) return;
129
+ valueSet.add(o.value);
130
+ });
111
131
  }
112
-
113
- emit("update:modelValue", newValue);
114
- } else {
115
- emit(
116
- "update:modelValue",
117
- isChecked ? trueValue.value : falseValue.value
118
- );
132
+ emit("update:modelValue", Array.from(valueSet.values()));
133
+ return;
119
134
  }
135
+
136
+ emit(
137
+ "update:modelValue",
138
+ isChecked ? trueValue.value : falseValue.value
139
+ );
120
140
  }
121
141
 
122
142
  onMounted(() => {
@@ -127,7 +147,7 @@ export default defineComponent({
127
147
  uid,
128
148
  checkboxClass,
129
149
  isChecked,
130
- onChanged,
150
+ onClickedLabel,
131
151
  };
132
152
  },
133
153
  });
@@ -73,7 +73,6 @@ export default defineComponent({
73
73
  const tabsContentBody = shallowRef<HTMLElement | null>(null);
74
74
  const tabsNavLeftEl = shallowRef<HTMLElement | null>(null);
75
75
  const navComp = shallowRef<SLDistributorType | null>(null);
76
- const activeTabIndex = ref(activeTab.value || 0);
77
76
  const tabTitles = ref<Array<string>>([]);
78
77
  const showDropdown = ref(false);
79
78
  const tabItemsOversizeProxy = ref(false);
@@ -81,6 +80,7 @@ export default defineComponent({
81
80
  let observer: MutationObserver | null = null;
82
81
  let resizeSubscriber: Subscription | null = null;
83
82
 
83
+ const activeTabIndex = computed(() => activeTab.value || 0);
84
84
  const tabsClass = computed(() => {
85
85
  const classes: Array<string> = [`tabs-type-${type.value}`];
86
86
 
@@ -130,7 +130,6 @@ export default defineComponent({
130
130
  }
131
131
 
132
132
  function changeTabTo(newTab: number) {
133
- activeTabIndex.value = newTab;
134
133
  emit("update:activeTab", newTab);
135
134
  }
136
135
 
@@ -138,10 +137,6 @@ export default defineComponent({
138
137
  changeTabTo(i);
139
138
  }
140
139
 
141
- watch(activeTab, () => {
142
- activeTabIndex.value = activeTab.value || 0;
143
- });
144
-
145
140
  onMounted(() => {
146
141
  resizeSubscriber = fromEvent(window, "resize")
147
142
  .pipe(debounce(() => interval(500)))
@@ -477,5 +472,4 @@ export default defineComponent({
477
472
  .tabs
478
473
  & > .tabs-content
479
474
  @apply shadow-md
480
- </style>
481
-
475
+ </style>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mptw/skylens-ui",
3
3
  "type": "module",
4
- "version": "1.4.95",
4
+ "version": "1.4.97",
5
5
  "main": "./nuxt.config.ts",
6
6
  "scripts": {
7
7
  "dev": "nuxi dev .playground",