@varlet/ui 2.18.0-alpha.1697511280107 → 2.18.0-alpha.1697559303154
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/es/back-top/BackTop.mjs +2 -10
- package/es/floating-panel/FloatingPanel.mjs +179 -0
- package/es/floating-panel/FloatingPanelSfc.css +0 -0
- package/es/floating-panel/floatingPanel.css +1 -0
- package/es/floating-panel/index.mjs +9 -0
- package/es/floating-panel/props.mjs +27 -0
- package/es/floating-panel/style/index.mjs +4 -0
- package/es/index-bar/IndexBar.mjs +11 -2
- package/es/index.bundle.mjs +7 -1
- package/es/index.mjs +6 -1
- package/es/pull-refresh/PullRefresh.mjs +19 -22
- package/es/style.css +1 -1
- package/es/style.mjs +1 -0
- package/es/themes/dark/floatingPanel.mjs +6 -0
- package/es/themes/dark/index.mjs +3 -2
- package/es/utils/elements.mjs +3 -11
- package/es/varlet.esm.js +5187 -5010
- package/highlight/web-types.en-US.json +81 -1
- package/highlight/web-types.zh-CN.json +82 -2
- package/lib/style.css +1 -1
- package/lib/varlet.cjs.js +1453 -1224
- package/package.json +7 -7
- package/types/floatingPanel.d.ts +24 -0
- package/types/index.d.ts +2 -0
- package/umd/varlet.js +6 -6
package/es/back-top/BackTop.mjs
CHANGED
|
@@ -2,17 +2,9 @@ import VarButton from "../button/index.mjs";
|
|
|
2
2
|
import VarIcon from "../icon/index.mjs";
|
|
3
3
|
import { defineComponent, ref, onMounted, onActivated } from "vue";
|
|
4
4
|
import { props } from "./props.mjs";
|
|
5
|
-
import { throttle } from "@varlet/shared";
|
|
5
|
+
import { throttle, getScrollTop, getScrollLeft } from "@varlet/shared";
|
|
6
6
|
import { easeInOutCubic } from "../utils/shared.mjs";
|
|
7
|
-
import {
|
|
8
|
-
getScrollTop,
|
|
9
|
-
getScrollLeft,
|
|
10
|
-
scrollTo,
|
|
11
|
-
getParentScroller,
|
|
12
|
-
toPxNum,
|
|
13
|
-
toSizeUnit,
|
|
14
|
-
getTarget
|
|
15
|
-
} from "../utils/elements.mjs";
|
|
7
|
+
import { scrollTo, getParentScroller, toPxNum, toSizeUnit, getTarget } from "../utils/elements.mjs";
|
|
16
8
|
import { call, createNamespace } from "../utils/components.mjs";
|
|
17
9
|
import { onSmartUnmounted } from "@varlet/use";
|
|
18
10
|
const { name, n, classes } = createNamespace("back-top");
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { defineComponent, ref, computed, watch } from "vue";
|
|
2
|
+
import { props } from "./props.mjs";
|
|
3
|
+
import { useLock } from "../context/lock.mjs";
|
|
4
|
+
import { call, createNamespace, useVModel, formatElevation, useTeleport } from "../utils/components.mjs";
|
|
5
|
+
import { toSizeUnit } from "../utils/elements.mjs";
|
|
6
|
+
import { useTouch, useWindowSize } from "@varlet/use";
|
|
7
|
+
import { toNumber, isEmpty, preventDefault } from "@varlet/shared";
|
|
8
|
+
const { name, n, classes } = createNamespace("floating-panel");
|
|
9
|
+
const DEFAULT_START_ANCHOR = 100;
|
|
10
|
+
const OVERFLOW_REDUCE_RATIO = 0.2;
|
|
11
|
+
import { normalizeClass as _normalizeClass, createElementVNode as _createElementVNode, renderSlot as _renderSlot, normalizeStyle as _normalizeStyle, Teleport as _Teleport, openBlock as _openBlock, createBlock as _createBlock } from "vue";
|
|
12
|
+
function __render__(_ctx, _cache) {
|
|
13
|
+
return _openBlock(), _createBlock(_Teleport, {
|
|
14
|
+
to: _ctx.teleport === false ? void 0 : _ctx.teleport,
|
|
15
|
+
disabled: _ctx.teleportDisabled || _ctx.teleport === false
|
|
16
|
+
}, [
|
|
17
|
+
_createElementVNode(
|
|
18
|
+
"div",
|
|
19
|
+
{
|
|
20
|
+
class: _normalizeClass(_ctx.classes(_ctx.n(), [_ctx.safeArea, _ctx.n("--safe-area")], _ctx.formatElevation(_ctx.elevation, 2))),
|
|
21
|
+
style: _normalizeStyle({
|
|
22
|
+
height: `${_ctx.toSizeUnit(_ctx.maxAnchor)}`,
|
|
23
|
+
transform: `translateY(calc(100% - ${_ctx.toSizeUnit(_ctx.visibleHeight)}))`,
|
|
24
|
+
transition: _ctx.touching ? "none" : `transform ${_ctx.toNumber(_ctx.duration)}ms var(--floating-panel-transition-timing-function)`
|
|
25
|
+
}),
|
|
26
|
+
onTouchstart: _cache[0] || (_cache[0] = (...args) => _ctx.handleTouchstart && _ctx.handleTouchstart(...args)),
|
|
27
|
+
onTouchmove: _cache[1] || (_cache[1] = (...args) => _ctx.handleTouchmove && _ctx.handleTouchmove(...args)),
|
|
28
|
+
onTouchend: _cache[2] || (_cache[2] = (...args) => _ctx.handleTouchend && _ctx.handleTouchend(...args)),
|
|
29
|
+
onTouchcancel: _cache[3] || (_cache[3] = (...args) => _ctx.handleTouchend && _ctx.handleTouchend(...args))
|
|
30
|
+
},
|
|
31
|
+
[
|
|
32
|
+
_createElementVNode(
|
|
33
|
+
"div",
|
|
34
|
+
{
|
|
35
|
+
class: _normalizeClass(_ctx.n("header"))
|
|
36
|
+
},
|
|
37
|
+
[
|
|
38
|
+
_createElementVNode(
|
|
39
|
+
"div",
|
|
40
|
+
{
|
|
41
|
+
class: _normalizeClass(_ctx.n("header-toolbar"))
|
|
42
|
+
},
|
|
43
|
+
null,
|
|
44
|
+
2
|
|
45
|
+
/* CLASS */
|
|
46
|
+
)
|
|
47
|
+
],
|
|
48
|
+
2
|
|
49
|
+
/* CLASS */
|
|
50
|
+
),
|
|
51
|
+
_createElementVNode(
|
|
52
|
+
"div",
|
|
53
|
+
{
|
|
54
|
+
class: _normalizeClass(_ctx.n("content")),
|
|
55
|
+
ref: "contentRef"
|
|
56
|
+
},
|
|
57
|
+
[
|
|
58
|
+
_renderSlot(_ctx.$slots, "default")
|
|
59
|
+
],
|
|
60
|
+
2
|
|
61
|
+
/* CLASS */
|
|
62
|
+
)
|
|
63
|
+
],
|
|
64
|
+
38
|
|
65
|
+
/* CLASS, STYLE, HYDRATE_EVENTS */
|
|
66
|
+
)
|
|
67
|
+
], 8, ["to", "disabled"]);
|
|
68
|
+
}
|
|
69
|
+
const __sfc__ = defineComponent({
|
|
70
|
+
name,
|
|
71
|
+
props,
|
|
72
|
+
setup(props2) {
|
|
73
|
+
const visibleHeight = ref(0);
|
|
74
|
+
const contentRef = ref(null);
|
|
75
|
+
const { height: windowHeight } = useWindowSize();
|
|
76
|
+
const defaultEndAnchor = computed(() => windowHeight.value * 0.6);
|
|
77
|
+
const anchor = useVModel(props2, "anchor");
|
|
78
|
+
const anchors = computed(() => {
|
|
79
|
+
const defaultAnchors = [DEFAULT_START_ANCHOR, defaultEndAnchor.value];
|
|
80
|
+
const { anchors: anchors2 } = props2;
|
|
81
|
+
return isEmpty(anchors2) ? defaultAnchors : anchors2;
|
|
82
|
+
});
|
|
83
|
+
const minAnchor = computed(() => Math.min(...anchors.value));
|
|
84
|
+
const maxAnchor = computed(() => Math.max(...anchors.value));
|
|
85
|
+
const { disabled: teleportDisabled } = useTeleport();
|
|
86
|
+
const { deltaY, touching, startTouch, moveTouch, endTouch, isReachTop, isReachBottom } = useTouch();
|
|
87
|
+
let startVisibleHeight;
|
|
88
|
+
useLock(() => touching.value);
|
|
89
|
+
watch(() => anchor.value, matchAnchor, { immediate: true });
|
|
90
|
+
watch(
|
|
91
|
+
() => anchors.value,
|
|
92
|
+
() => {
|
|
93
|
+
matchAnchor(anchor.value);
|
|
94
|
+
},
|
|
95
|
+
{ immediate: true }
|
|
96
|
+
);
|
|
97
|
+
function matchAnchor(anchor2) {
|
|
98
|
+
setVisibleHeight(anchor2 != null ? anchor2 : minAnchor.value);
|
|
99
|
+
}
|
|
100
|
+
function handleTouchstart(event) {
|
|
101
|
+
startTouch(event);
|
|
102
|
+
startVisibleHeight = visibleHeight.value;
|
|
103
|
+
}
|
|
104
|
+
function handleTouchmove(event) {
|
|
105
|
+
var _a;
|
|
106
|
+
moveTouch(event);
|
|
107
|
+
const target = event.target;
|
|
108
|
+
const eventFromContent = contentRef.value === target || ((_a = contentRef.value) == null ? void 0 : _a.contains(target));
|
|
109
|
+
if (eventFromContent && !props2.contentDraggable) {
|
|
110
|
+
if (isReachTop(contentRef.value) || isReachBottom(contentRef.value)) {
|
|
111
|
+
preventDefault(event);
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const targetVisibleHeight = startVisibleHeight - deltaY.value;
|
|
116
|
+
setVisibleHeight(clampVisibleHeight(targetVisibleHeight));
|
|
117
|
+
preventDefault(event);
|
|
118
|
+
}
|
|
119
|
+
function handleTouchend() {
|
|
120
|
+
endTouch();
|
|
121
|
+
const oldAnchor = anchor.value;
|
|
122
|
+
setVisibleHeight(visibleHeight.value);
|
|
123
|
+
anchor.value = visibleHeight.value;
|
|
124
|
+
if (anchor.value !== oldAnchor) {
|
|
125
|
+
call(props2.onAnchorChange, visibleHeight.value);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function setVisibleHeight(targetVisibleHeight) {
|
|
129
|
+
visibleHeight.value = touching.value ? targetVisibleHeight : findNearestAnchor(targetVisibleHeight);
|
|
130
|
+
}
|
|
131
|
+
function clampVisibleHeight(visibleHeight2) {
|
|
132
|
+
if (visibleHeight2 > maxAnchor.value) {
|
|
133
|
+
const overflowHeight = visibleHeight2 - maxAnchor.value;
|
|
134
|
+
return maxAnchor.value + overflowHeight * OVERFLOW_REDUCE_RATIO;
|
|
135
|
+
}
|
|
136
|
+
if (visibleHeight2 < minAnchor.value) {
|
|
137
|
+
const overflowHeight = minAnchor.value - visibleHeight2;
|
|
138
|
+
return minAnchor.value - overflowHeight * OVERFLOW_REDUCE_RATIO;
|
|
139
|
+
}
|
|
140
|
+
return visibleHeight2;
|
|
141
|
+
}
|
|
142
|
+
function findNearestAnchor(targetAnchor) {
|
|
143
|
+
if (anchors.value.includes(targetAnchor)) {
|
|
144
|
+
return targetAnchor;
|
|
145
|
+
}
|
|
146
|
+
let minDifference = Infinity;
|
|
147
|
+
let nearestAnchor = 0;
|
|
148
|
+
anchors.value.forEach((anchor2) => {
|
|
149
|
+
const difference = Math.abs(anchor2 - targetAnchor);
|
|
150
|
+
if (difference < minDifference) {
|
|
151
|
+
minDifference = difference;
|
|
152
|
+
nearestAnchor = anchor2;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
return nearestAnchor;
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
contentRef,
|
|
159
|
+
teleportDisabled,
|
|
160
|
+
touching,
|
|
161
|
+
minAnchor,
|
|
162
|
+
maxAnchor,
|
|
163
|
+
visibleHeight,
|
|
164
|
+
n,
|
|
165
|
+
classes,
|
|
166
|
+
toSizeUnit,
|
|
167
|
+
toNumber,
|
|
168
|
+
formatElevation,
|
|
169
|
+
handleTouchstart,
|
|
170
|
+
handleTouchmove,
|
|
171
|
+
handleTouchend
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
__sfc__.render = __render__;
|
|
176
|
+
var stdin_default = __sfc__;
|
|
177
|
+
export {
|
|
178
|
+
stdin_default as default
|
|
179
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:root { --floating-panel-z-index: 999; --floating-panel-border-top: none; --floating-panel-border-radius: 0; --floating-panel-background: #fff; --floating-panel-header-height: 40px; --floating-panel-toolbar-width: 20px; --floating-panel-toolbar-height: 3px; --floating-panel-toolbar-border-radius: 10px; --floating-panel-toolbar-background: #ddd; --floating-panel-transition-timing-function: cubic-bezier(0.18, 0.89, 0.32, 1.28);}.var-floating-panel { position: fixed; left: 0; bottom: 0; width: 100%; display: flex; flex-direction: column; z-index: var(--floating-panel-z-index); border-top: var(--floating-panel-border-top); border-top-left-radius: var(--floating-panel-border-radius); border-top-right-radius: var(--floating-panel-border-radius); border-bottom-right-radius: 0; border-bottom-left-radius: 0; background-color: var(--floating-panel-background); will-change: transform; touch-action: none;}.var-floating-panel::after { content: ''; display: block; position: absolute; bottom: -100vh; height: 100vh; width: 100vw; background-color: inherit;}.var-floating-panel__header { height: var(--floating-panel-header-height); display: flex; justify-content: center; align-items: center; cursor: grab; user-select: none;}.var-floating-panel__header-toolbar { width: var(--floating-panel-toolbar-width); height: var(--floating-panel-toolbar-height); border-radius: var(--floating-panel-toolbar-border-radius); background: var(--floating-panel-toolbar-background);}.var-floating-panel__content { flex: 1; overflow-y: auto;}.var-floating-panel--safe-area { padding-bottom: constant(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom);}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import FloatingPanel from "./FloatingPanel.mjs";
|
|
2
|
+
import { withInstall } from "../utils/components.mjs";
|
|
3
|
+
withInstall(FloatingPanel);
|
|
4
|
+
const _FloatingPanelComponent = FloatingPanel;
|
|
5
|
+
var stdin_default = FloatingPanel;
|
|
6
|
+
export {
|
|
7
|
+
_FloatingPanelComponent,
|
|
8
|
+
stdin_default as default
|
|
9
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineListenerProp } from "../utils/components.mjs";
|
|
2
|
+
const props = {
|
|
3
|
+
anchor: Number,
|
|
4
|
+
anchors: Array,
|
|
5
|
+
contentDraggable: {
|
|
6
|
+
type: Boolean,
|
|
7
|
+
default: true
|
|
8
|
+
},
|
|
9
|
+
duration: {
|
|
10
|
+
type: [Number, String],
|
|
11
|
+
default: 300
|
|
12
|
+
},
|
|
13
|
+
elevation: {
|
|
14
|
+
type: [Boolean, Number, String],
|
|
15
|
+
default: true
|
|
16
|
+
},
|
|
17
|
+
teleport: {
|
|
18
|
+
type: [String, Object, Boolean],
|
|
19
|
+
default: "body"
|
|
20
|
+
},
|
|
21
|
+
safeArea: Boolean,
|
|
22
|
+
"onUpdate:anchor": defineListenerProp(),
|
|
23
|
+
onAnchorChange: defineListenerProp()
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
props
|
|
27
|
+
};
|
|
@@ -19,9 +19,18 @@ var __async = (__this, __arguments, generator) => {
|
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
21
|
import { computed, defineComponent, ref, watch, onBeforeUnmount, onDeactivated, onActivated } from "vue";
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
isPlainObject,
|
|
24
|
+
isWindow,
|
|
25
|
+
toNumber,
|
|
26
|
+
doubleRaf,
|
|
27
|
+
requestAnimationFrame,
|
|
28
|
+
getRect,
|
|
29
|
+
getScrollLeft,
|
|
30
|
+
getScrollTop
|
|
31
|
+
} from "@varlet/shared";
|
|
23
32
|
import { easeInOutCubic } from "../utils/shared.mjs";
|
|
24
|
-
import { getParentScroller,
|
|
33
|
+
import { getParentScroller, scrollTo as varScrollTo, toPxNum } from "../utils/elements.mjs";
|
|
25
34
|
import { useIndexAnchors } from "./provide.mjs";
|
|
26
35
|
import { props } from "./props.mjs";
|
|
27
36
|
import { createNamespace, call } from "../utils/components.mjs";
|
package/es/index.bundle.mjs
CHANGED
|
@@ -28,6 +28,7 @@ import Drag from './drag/index.mjs'
|
|
|
28
28
|
import Ellipsis from './ellipsis/index.mjs'
|
|
29
29
|
import Fab from './fab/index.mjs'
|
|
30
30
|
import FieldDecorator from './field-decorator/index.mjs'
|
|
31
|
+
import FloatingPanel from './floating-panel/index.mjs'
|
|
31
32
|
import Form from './form/index.mjs'
|
|
32
33
|
import FormDetails from './form-details/index.mjs'
|
|
33
34
|
import Hover from './hover/index.mjs'
|
|
@@ -114,6 +115,7 @@ export * from './drag/index.mjs'
|
|
|
114
115
|
export * from './ellipsis/index.mjs'
|
|
115
116
|
export * from './fab/index.mjs'
|
|
116
117
|
export * from './field-decorator/index.mjs'
|
|
118
|
+
export * from './floating-panel/index.mjs'
|
|
117
119
|
export * from './form/index.mjs'
|
|
118
120
|
export * from './form-details/index.mjs'
|
|
119
121
|
export * from './hover/index.mjs'
|
|
@@ -200,6 +202,7 @@ import './drag/style/index.mjs'
|
|
|
200
202
|
import './ellipsis/style/index.mjs'
|
|
201
203
|
import './fab/style/index.mjs'
|
|
202
204
|
import './field-decorator/style/index.mjs'
|
|
205
|
+
import './floating-panel/style/index.mjs'
|
|
203
206
|
import './form/style/index.mjs'
|
|
204
207
|
import './form-details/style/index.mjs'
|
|
205
208
|
import './hover/style/index.mjs'
|
|
@@ -256,7 +259,7 @@ import './tooltip/style/index.mjs'
|
|
|
256
259
|
import './uploader/style/index.mjs'
|
|
257
260
|
import './watermark/style/index.mjs'
|
|
258
261
|
|
|
259
|
-
const version = '2.18.0-alpha.
|
|
262
|
+
const version = '2.18.0-alpha.1697559303154'
|
|
260
263
|
|
|
261
264
|
function install(app) {
|
|
262
265
|
ActionSheet.install && app.use(ActionSheet)
|
|
@@ -289,6 +292,7 @@ function install(app) {
|
|
|
289
292
|
Ellipsis.install && app.use(Ellipsis)
|
|
290
293
|
Fab.install && app.use(Fab)
|
|
291
294
|
FieldDecorator.install && app.use(FieldDecorator)
|
|
295
|
+
FloatingPanel.install && app.use(FloatingPanel)
|
|
292
296
|
Form.install && app.use(Form)
|
|
293
297
|
FormDetails.install && app.use(FormDetails)
|
|
294
298
|
Hover.install && app.use(Hover)
|
|
@@ -379,6 +383,7 @@ export {
|
|
|
379
383
|
Ellipsis,
|
|
380
384
|
Fab,
|
|
381
385
|
FieldDecorator,
|
|
386
|
+
FloatingPanel,
|
|
382
387
|
Form,
|
|
383
388
|
FormDetails,
|
|
384
389
|
Hover,
|
|
@@ -469,6 +474,7 @@ export default {
|
|
|
469
474
|
Ellipsis,
|
|
470
475
|
Fab,
|
|
471
476
|
FieldDecorator,
|
|
477
|
+
FloatingPanel,
|
|
472
478
|
Form,
|
|
473
479
|
FormDetails,
|
|
474
480
|
Hover,
|
package/es/index.mjs
CHANGED
|
@@ -28,6 +28,7 @@ import Drag from './drag/index.mjs'
|
|
|
28
28
|
import Ellipsis from './ellipsis/index.mjs'
|
|
29
29
|
import Fab from './fab/index.mjs'
|
|
30
30
|
import FieldDecorator from './field-decorator/index.mjs'
|
|
31
|
+
import FloatingPanel from './floating-panel/index.mjs'
|
|
31
32
|
import Form from './form/index.mjs'
|
|
32
33
|
import FormDetails from './form-details/index.mjs'
|
|
33
34
|
import Hover from './hover/index.mjs'
|
|
@@ -114,6 +115,7 @@ export * from './drag/index.mjs'
|
|
|
114
115
|
export * from './ellipsis/index.mjs'
|
|
115
116
|
export * from './fab/index.mjs'
|
|
116
117
|
export * from './field-decorator/index.mjs'
|
|
118
|
+
export * from './floating-panel/index.mjs'
|
|
117
119
|
export * from './form/index.mjs'
|
|
118
120
|
export * from './form-details/index.mjs'
|
|
119
121
|
export * from './hover/index.mjs'
|
|
@@ -170,7 +172,7 @@ export * from './tooltip/index.mjs'
|
|
|
170
172
|
export * from './uploader/index.mjs'
|
|
171
173
|
export * from './watermark/index.mjs'
|
|
172
174
|
|
|
173
|
-
const version = '2.18.0-alpha.
|
|
175
|
+
const version = '2.18.0-alpha.1697559303154'
|
|
174
176
|
|
|
175
177
|
function install(app) {
|
|
176
178
|
ActionSheet.install && app.use(ActionSheet)
|
|
@@ -203,6 +205,7 @@ function install(app) {
|
|
|
203
205
|
Ellipsis.install && app.use(Ellipsis)
|
|
204
206
|
Fab.install && app.use(Fab)
|
|
205
207
|
FieldDecorator.install && app.use(FieldDecorator)
|
|
208
|
+
FloatingPanel.install && app.use(FloatingPanel)
|
|
206
209
|
Form.install && app.use(Form)
|
|
207
210
|
FormDetails.install && app.use(FormDetails)
|
|
208
211
|
Hover.install && app.use(Hover)
|
|
@@ -293,6 +296,7 @@ export {
|
|
|
293
296
|
Ellipsis,
|
|
294
297
|
Fab,
|
|
295
298
|
FieldDecorator,
|
|
299
|
+
FloatingPanel,
|
|
296
300
|
Form,
|
|
297
301
|
FormDetails,
|
|
298
302
|
Hover,
|
|
@@ -383,6 +387,7 @@ export default {
|
|
|
383
387
|
Ellipsis,
|
|
384
388
|
Fab,
|
|
385
389
|
FieldDecorator,
|
|
390
|
+
FloatingPanel,
|
|
386
391
|
Form,
|
|
387
392
|
FormDetails,
|
|
388
393
|
Hover,
|
|
@@ -20,11 +20,11 @@ var __async = (__this, __arguments, generator) => {
|
|
|
20
20
|
};
|
|
21
21
|
import VarIcon from "../icon/index.mjs";
|
|
22
22
|
import { defineComponent, ref, computed, watch, nextTick } from "vue";
|
|
23
|
-
import { getParentScroller,
|
|
23
|
+
import { getParentScroller, getTarget } from "../utils/elements.mjs";
|
|
24
24
|
import { props } from "./props.mjs";
|
|
25
|
-
import { isNumber, isString, toNumber, getRect, preventDefault } from "@varlet/shared";
|
|
25
|
+
import { isNumber, isString, toNumber, getRect, preventDefault, getScrollTop } from "@varlet/shared";
|
|
26
26
|
import { call, createNamespace } from "../utils/components.mjs";
|
|
27
|
-
import { useEventListener, onSmartMounted } from "@varlet/use";
|
|
27
|
+
import { useEventListener, onSmartMounted, useTouch } from "@varlet/use";
|
|
28
28
|
const { name, n, classes } = createNamespace("pull-refresh");
|
|
29
29
|
const ICON_TRANSITION = 150;
|
|
30
30
|
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";
|
|
@@ -35,9 +35,9 @@ function __render__(_ctx, _cache) {
|
|
|
35
35
|
{
|
|
36
36
|
ref: "freshNode",
|
|
37
37
|
class: _normalizeClass(_ctx.n()),
|
|
38
|
-
onTouchstart: _cache[0] || (_cache[0] = (...args) => _ctx.
|
|
39
|
-
onTouchend: _cache[1] || (_cache[1] = (...args) => _ctx.
|
|
40
|
-
onTouchcancel: _cache[2] || (_cache[2] = (...args) => _ctx.
|
|
38
|
+
onTouchstart: _cache[0] || (_cache[0] = (...args) => _ctx.handleTouchstart && _ctx.handleTouchstart(...args)),
|
|
39
|
+
onTouchend: _cache[1] || (_cache[1] = (...args) => _ctx.handleTouchend && _ctx.handleTouchend(...args)),
|
|
40
|
+
onTouchcancel: _cache[2] || (_cache[2] = (...args) => _ctx.handleTouchend && _ctx.handleTouchend(...args))
|
|
41
41
|
},
|
|
42
42
|
[
|
|
43
43
|
_createElementVNode(
|
|
@@ -88,10 +88,9 @@ const __sfc__ = defineComponent({
|
|
|
88
88
|
background: isSuccess.value ? props2.successBgColor : props2.bgColor,
|
|
89
89
|
color: isSuccess.value ? props2.successColor : props2.color
|
|
90
90
|
}));
|
|
91
|
+
const { startTouch, moveTouch, endTouch, isReachTop } = useTouch();
|
|
91
92
|
let scroller;
|
|
92
93
|
let eventTargetScroller;
|
|
93
|
-
let startY = 0;
|
|
94
|
-
let deltaY = 0;
|
|
95
94
|
watch(
|
|
96
95
|
() => props2.modelValue,
|
|
97
96
|
(newValue) => {
|
|
@@ -107,7 +106,7 @@ const __sfc__ = defineComponent({
|
|
|
107
106
|
}
|
|
108
107
|
);
|
|
109
108
|
onSmartMounted(setScroller);
|
|
110
|
-
useEventListener(freshNode, "touchmove",
|
|
109
|
+
useEventListener(freshNode, "touchmove", handleTouchmove);
|
|
111
110
|
function startIconTransition(name2) {
|
|
112
111
|
return __async(this, null, function* () {
|
|
113
112
|
if (iconName.value === name2) {
|
|
@@ -123,16 +122,16 @@ const __sfc__ = defineComponent({
|
|
|
123
122
|
const el = "classList" in scroller ? scroller : document.body;
|
|
124
123
|
el.classList[action](`${n()}--lock`);
|
|
125
124
|
}
|
|
126
|
-
function
|
|
125
|
+
function handleTouchstart(event) {
|
|
126
|
+
startTouch(event);
|
|
127
127
|
if (controlPosition.value === 0) {
|
|
128
128
|
const { width } = getRect(controlNode.value);
|
|
129
129
|
controlPosition.value = -(width + width * 0.25);
|
|
130
130
|
}
|
|
131
|
-
startY = event.touches[0].clientY;
|
|
132
|
-
deltaY = 0;
|
|
133
131
|
eventTargetScroller = getParentScroller(event.target);
|
|
134
132
|
}
|
|
135
|
-
function
|
|
133
|
+
function handleTouchmove(event) {
|
|
134
|
+
moveTouch(event);
|
|
136
135
|
if (!isTouchable.value || !eventTargetScroller) {
|
|
137
136
|
return;
|
|
138
137
|
}
|
|
@@ -143,25 +142,23 @@ const __sfc__ = defineComponent({
|
|
|
143
142
|
if (scrollTop > 0) {
|
|
144
143
|
return;
|
|
145
144
|
}
|
|
146
|
-
|
|
147
|
-
const touch = event.touches[0];
|
|
148
|
-
deltaY = touch.clientY - startY;
|
|
149
|
-
if (isReachTop && deltaY >= 0) {
|
|
145
|
+
if (isReachTop(scroller)) {
|
|
150
146
|
preventDefault(event);
|
|
151
147
|
}
|
|
152
148
|
if (refreshStatus.value !== "pulling") {
|
|
153
149
|
refreshStatus.value = "pulling";
|
|
154
150
|
startPosition.value = event.touches[0].clientY;
|
|
155
151
|
}
|
|
156
|
-
if (isReachTop && isNumber(distance.value) && distance.value > controlPosition.value) {
|
|
152
|
+
if (isReachTop(scroller) && isNumber(distance.value) && distance.value > controlPosition.value) {
|
|
157
153
|
lockEvent("add");
|
|
158
154
|
}
|
|
159
155
|
const moveDistance = (event.touches[0].clientY - startPosition.value) / 2 + controlPosition.value;
|
|
160
156
|
distance.value = moveDistance >= maxDistance.value ? maxDistance.value : moveDistance;
|
|
161
157
|
startIconTransition(distance.value >= maxDistance.value * 0.2 ? "refresh" : "arrow-down");
|
|
162
158
|
}
|
|
163
|
-
function
|
|
159
|
+
function handleTouchend() {
|
|
164
160
|
return __async(this, null, function* () {
|
|
161
|
+
endTouch();
|
|
165
162
|
if (!isTouchable.value) {
|
|
166
163
|
return;
|
|
167
164
|
}
|
|
@@ -207,9 +204,9 @@ const __sfc__ = defineComponent({
|
|
|
207
204
|
isSuccess,
|
|
208
205
|
n,
|
|
209
206
|
classes,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
207
|
+
handleTouchstart,
|
|
208
|
+
handleTouchmove,
|
|
209
|
+
handleTouchend
|
|
213
210
|
};
|
|
214
211
|
}
|
|
215
212
|
});
|