@varlet/ui 2.4.0-alpha.1670766368590 → 2.4.1

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.
@@ -12,8 +12,6 @@ var {
12
12
  n,
13
13
  classes
14
14
  } = createNamespace('pull-refresh');
15
- var MAX_DISTANCE = 100;
16
- var CONTROL_POSITION = -50;
17
15
  var ICON_TRANSITION = 150;
18
16
  import { resolveComponent as _resolveComponent, normalizeClass as _normalizeClass, createVNode as _createVNode, normalizeStyle as _normalizeStyle, createElementVNode as _createElementVNode, renderSlot as _renderSlot, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue";
19
17
  export function render(_ctx, _cache) {
@@ -35,6 +33,7 @@ export function render(_ctx, _cache) {
35
33
  return _ctx.touchEnd && _ctx.touchEnd(...arguments);
36
34
  })
37
35
  }, [_createElementVNode("div", {
36
+ ref: "controlNode",
38
37
  class: _normalizeClass(_ctx.classes(_ctx.n('control'), _ctx.n('$-elevation--2'), [_ctx.isSuccess, _ctx.n('control-success')])),
39
38
  style: _normalizeStyle(_ctx.controlStyle)
40
39
  }, [_createVNode(_component_var_icon, {
@@ -61,9 +60,11 @@ export default defineComponent({
61
60
  setup(props) {
62
61
  var scroller;
63
62
  var changing;
63
+ var controlPosition = ref(0);
64
64
  var freshNode = ref(null);
65
+ var controlNode = ref(null);
65
66
  var startPosition = ref(0);
66
- var distance = ref(CONTROL_POSITION);
67
+ var distance = ref(-999);
67
68
  var iconName = ref('arrow-down');
68
69
  var refreshStatus = ref('default');
69
70
  var isEnd = ref(false); // https://github.com/varletjs/varlet/issues/509
@@ -76,6 +77,7 @@ export default defineComponent({
76
77
  background: isSuccess.value ? props.successBgColor : props.bgColor,
77
78
  color: isSuccess.value ? props.successColor : props.color
78
79
  }));
80
+ var maxDistance = computed(() => Math.abs(2 * controlPosition.value));
79
81
  var isSuccess = computed(() => refreshStatus.value === 'success');
80
82
 
81
83
  var changeIcon = () => {
@@ -96,11 +98,11 @@ export default defineComponent({
96
98
  var touchMove = event => {
97
99
  var scrollTop = getScrollTop(scroller);
98
100
  if (scrollTop > 0 || !isTouchable.value) return;
99
- if (scrollTop === 0 && distance.value > CONTROL_POSITION) event.cancelable && event.preventDefault();
100
- var moveDistance = (event.touches[0].clientY - startPosition.value) / 2 + CONTROL_POSITION;
101
- distance.value = moveDistance >= MAX_DISTANCE ? MAX_DISTANCE : moveDistance;
101
+ if (scrollTop === 0 && distance.value > controlPosition.value) event.cancelable && event.preventDefault();
102
+ var moveDistance = (event.touches[0].clientY - startPosition.value) / 2 + controlPosition.value;
103
+ distance.value = moveDistance >= maxDistance.value ? maxDistance.value : moveDistance;
102
104
 
103
- if (distance.value >= MAX_DISTANCE * 0.2) {
105
+ if (distance.value >= maxDistance.value * 0.2) {
104
106
  iconHasChanged.value = false;
105
107
  iconName.value = 'refresh';
106
108
  changing = changeIcon();
@@ -114,18 +116,18 @@ export default defineComponent({
114
116
  if (!isTouchable.value) return;
115
117
  isEnd.value = true;
116
118
 
117
- if (distance.value >= MAX_DISTANCE * 0.2) {
119
+ if (distance.value >= maxDistance.value * 0.2) {
118
120
  var _props$onUpdateModel;
119
121
 
120
122
  yield changing;
121
123
  refreshStatus.value = 'loading';
122
- distance.value = MAX_DISTANCE * 0.3;
124
+ distance.value = maxDistance.value * 0.3;
123
125
  (_props$onUpdateModel = props['onUpdate:modelValue']) == null ? void 0 : _props$onUpdateModel.call(props, true);
124
126
  props.onRefresh == null ? void 0 : props.onRefresh();
125
127
  } else {
126
128
  refreshStatus.value = 'loosing';
127
129
  iconName.value = 'arrow-down';
128
- distance.value = CONTROL_POSITION;
130
+ distance.value = controlPosition.value;
129
131
  setTimeout(() => {
130
132
  isEnd.value = false;
131
133
  }, toNumber(props.animationDuration));
@@ -137,6 +139,14 @@ export default defineComponent({
137
139
  };
138
140
  }();
139
141
 
142
+ var setPosition = () => {
143
+ var {
144
+ width
145
+ } = controlNode.value.getBoundingClientRect();
146
+ distance.value = -(width + width * 0.25);
147
+ controlPosition.value = -(width + width * 0.25);
148
+ };
149
+
140
150
  var reset = () => {
141
151
  setTimeout(() => {
142
152
  refreshStatus.value = 'default';
@@ -151,13 +161,14 @@ export default defineComponent({
151
161
  refreshStatus.value = 'success';
152
162
  iconName.value = 'checkbox-marked-circle';
153
163
  setTimeout(() => {
154
- distance.value = CONTROL_POSITION;
164
+ distance.value = controlPosition.value;
155
165
  reset();
156
166
  }, toNumber(props.successDuration));
157
167
  }
158
168
  });
159
169
  onMounted(() => {
160
170
  scroller = getParentScroller(freshNode.value);
171
+ setPosition();
161
172
  });
162
173
  return {
163
174
  n,
@@ -166,6 +177,7 @@ export default defineComponent({
166
177
  ICON_TRANSITION,
167
178
  refreshStatus,
168
179
  freshNode,
180
+ controlNode,
169
181
  touchStart,
170
182
  touchMove,
171
183
  touchEnd,
@@ -1,8 +1,8 @@
1
1
  import '../../styles/common.css'
2
+ import '../SnackbarSfc.css'
2
3
  import '../../styles/elevation.css'
3
4
  import '../../loading/loading.css'
4
5
  import '../../button/button.css'
5
6
  import '../../icon/icon.css'
6
7
  import '../snackbar.css'
7
8
  import '../coreSfc.css'
8
- import '../SnackbarSfc.css'