@varlet/ui 2.4.0 → 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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
3
3
  "framework": "vue",
4
- "version": "2.3.1",
4
+ "version": "2.4.0",
5
5
  "name": "VARLET",
6
6
  "contributions": {
7
7
  "html": {
@@ -26,8 +26,6 @@ var {
26
26
  n,
27
27
  classes
28
28
  } = (0, _components.createNamespace)('pull-refresh');
29
- var MAX_DISTANCE = 100;
30
- var CONTROL_POSITION = -50;
31
29
  var ICON_TRANSITION = 150;
32
30
 
33
31
  function render(_ctx, _cache) {
@@ -49,6 +47,7 @@ function render(_ctx, _cache) {
49
47
  return _ctx.touchEnd && _ctx.touchEnd(...arguments);
50
48
  })
51
49
  }, [(0, _vue.createElementVNode)("div", {
50
+ ref: "controlNode",
52
51
  class: (0, _vue.normalizeClass)(_ctx.classes(_ctx.n('control'), _ctx.n('$-elevation--2'), [_ctx.isSuccess, _ctx.n('control-success')])),
53
52
  style: (0, _vue.normalizeStyle)(_ctx.controlStyle)
54
53
  }, [(0, _vue.createVNode)(_component_var_icon, {
@@ -76,9 +75,11 @@ var _default = (0, _vue.defineComponent)({
76
75
  setup(props) {
77
76
  var scroller;
78
77
  var changing;
78
+ var controlPosition = (0, _vue.ref)(0);
79
79
  var freshNode = (0, _vue.ref)(null);
80
+ var controlNode = (0, _vue.ref)(null);
80
81
  var startPosition = (0, _vue.ref)(0);
81
- var distance = (0, _vue.ref)(CONTROL_POSITION);
82
+ var distance = (0, _vue.ref)(-999);
82
83
  var iconName = (0, _vue.ref)('arrow-down');
83
84
  var refreshStatus = (0, _vue.ref)('default');
84
85
  var isEnd = (0, _vue.ref)(false); // https://github.com/varletjs/varlet/issues/509
@@ -91,6 +92,7 @@ var _default = (0, _vue.defineComponent)({
91
92
  background: isSuccess.value ? props.successBgColor : props.bgColor,
92
93
  color: isSuccess.value ? props.successColor : props.color
93
94
  }));
95
+ var maxDistance = (0, _vue.computed)(() => Math.abs(2 * controlPosition.value));
94
96
  var isSuccess = (0, _vue.computed)(() => refreshStatus.value === 'success');
95
97
 
96
98
  var changeIcon = () => {
@@ -111,11 +113,11 @@ var _default = (0, _vue.defineComponent)({
111
113
  var touchMove = event => {
112
114
  var scrollTop = (0, _elements.getScrollTop)(scroller);
113
115
  if (scrollTop > 0 || !isTouchable.value) return;
114
- if (scrollTop === 0 && distance.value > CONTROL_POSITION) event.cancelable && event.preventDefault();
115
- var moveDistance = (event.touches[0].clientY - startPosition.value) / 2 + CONTROL_POSITION;
116
- distance.value = moveDistance >= MAX_DISTANCE ? MAX_DISTANCE : moveDistance;
116
+ if (scrollTop === 0 && distance.value > controlPosition.value) event.cancelable && event.preventDefault();
117
+ var moveDistance = (event.touches[0].clientY - startPosition.value) / 2 + controlPosition.value;
118
+ distance.value = moveDistance >= maxDistance.value ? maxDistance.value : moveDistance;
117
119
 
118
- if (distance.value >= MAX_DISTANCE * 0.2) {
120
+ if (distance.value >= maxDistance.value * 0.2) {
119
121
  iconHasChanged.value = false;
120
122
  iconName.value = 'refresh';
121
123
  changing = changeIcon();
@@ -129,18 +131,18 @@ var _default = (0, _vue.defineComponent)({
129
131
  if (!isTouchable.value) return;
130
132
  isEnd.value = true;
131
133
 
132
- if (distance.value >= MAX_DISTANCE * 0.2) {
134
+ if (distance.value >= maxDistance.value * 0.2) {
133
135
  var _props$onUpdateModel;
134
136
 
135
137
  yield changing;
136
138
  refreshStatus.value = 'loading';
137
- distance.value = MAX_DISTANCE * 0.3;
139
+ distance.value = maxDistance.value * 0.3;
138
140
  (_props$onUpdateModel = props['onUpdate:modelValue']) == null ? void 0 : _props$onUpdateModel.call(props, true);
139
141
  props.onRefresh == null ? void 0 : props.onRefresh();
140
142
  } else {
141
143
  refreshStatus.value = 'loosing';
142
144
  iconName.value = 'arrow-down';
143
- distance.value = CONTROL_POSITION;
145
+ distance.value = controlPosition.value;
144
146
  setTimeout(() => {
145
147
  isEnd.value = false;
146
148
  }, (0, _shared.toNumber)(props.animationDuration));
@@ -152,6 +154,14 @@ var _default = (0, _vue.defineComponent)({
152
154
  };
153
155
  }();
154
156
 
157
+ var setPosition = () => {
158
+ var {
159
+ width
160
+ } = controlNode.value.getBoundingClientRect();
161
+ distance.value = -(width + width * 0.25);
162
+ controlPosition.value = -(width + width * 0.25);
163
+ };
164
+
155
165
  var reset = () => {
156
166
  setTimeout(() => {
157
167
  refreshStatus.value = 'default';
@@ -166,13 +176,14 @@ var _default = (0, _vue.defineComponent)({
166
176
  refreshStatus.value = 'success';
167
177
  iconName.value = 'checkbox-marked-circle';
168
178
  setTimeout(() => {
169
- distance.value = CONTROL_POSITION;
179
+ distance.value = controlPosition.value;
170
180
  reset();
171
181
  }, (0, _shared.toNumber)(props.successDuration));
172
182
  }
173
183
  });
174
184
  (0, _vue.onMounted)(() => {
175
185
  scroller = (0, _elements.getParentScroller)(freshNode.value);
186
+ setPosition();
176
187
  });
177
188
  return {
178
189
  n,
@@ -181,6 +192,7 @@ var _default = (0, _vue.defineComponent)({
181
192
  ICON_TRANSITION,
182
193
  refreshStatus,
183
194
  freshNode,
195
+ controlNode,
184
196
  touchStart,
185
197
  touchMove,
186
198
  touchEnd,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/ui",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "A material like components library",
5
5
  "module": "es/index.js",
6
6
  "main": "lib/index.js",
@@ -47,8 +47,8 @@
47
47
  "@popperjs/core": "^2.11.6",
48
48
  "dayjs": "^1.10.4",
49
49
  "decimal.js": "^10.2.1",
50
- "@varlet/icons": "2.4.0",
51
- "@varlet/shared": "2.4.0"
50
+ "@varlet/icons": "2.4.1",
51
+ "@varlet/shared": "2.4.1"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/jest": "^26.0.15",
@@ -63,8 +63,8 @@
63
63
  "typescript": "^4.4.4",
64
64
  "vue": "3.2.25",
65
65
  "vue-router": "4.0.12",
66
- "@varlet/touch-emulator": "2.4.0",
67
- "@varlet/cli": "2.4.0"
66
+ "@varlet/cli": "2.4.1",
67
+ "@varlet/touch-emulator": "2.4.1"
68
68
  },
69
69
  "browserslist": [
70
70
  "Chrome >= 54",