@varlet/ui 2.12.3 → 2.13.0-alpha.1689346411483

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.
@@ -0,0 +1,257 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
3
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
4
+ import { defineComponent, ref, reactive, watch } from 'vue';
5
+ import { props } from './props.mjs';
6
+ import { createNamespace } from '../utils/components.mjs';
7
+ import { getRect, toPxNum } from '../utils/elements.mjs';
8
+ import { onSmartMounted, onWindowResize } from '@varlet/use';
9
+ import { clamp } from '@varlet/shared';
10
+ var {
11
+ n,
12
+ classes
13
+ } = createNamespace('drag');
14
+ import { renderSlot as _renderSlot, mergeProps as _mergeProps, createElementVNode as _createElementVNode, Teleport as _Teleport, openBlock as _openBlock, createBlock as _createBlock } from "vue";
15
+ function __render__(_ctx, _cache) {
16
+ return _openBlock(), _createBlock(_Teleport, {
17
+ to: _ctx.teleport
18
+ }, [_createElementVNode("div", _mergeProps({
19
+ ref: "drag",
20
+ class: _ctx.classes(_ctx.n(), _ctx.n('$--box'), [_ctx.enableTransition, _ctx.n('--transition')]),
21
+ style: {
22
+ 'z-index': _ctx.zIndex
23
+ },
24
+ onTouchstart: _cache[0] || (_cache[0] = function () {
25
+ return _ctx.handleTouchstart && _ctx.handleTouchstart(...arguments);
26
+ }),
27
+ onTouchmove: _cache[1] || (_cache[1] = function () {
28
+ return _ctx.handleTouchmove && _ctx.handleTouchmove(...arguments);
29
+ }),
30
+ onTouchend: _cache[2] || (_cache[2] = function () {
31
+ return _ctx.handleTouchend && _ctx.handleTouchend(...arguments);
32
+ }),
33
+ onTouchcancel: _cache[3] || (_cache[3] = function () {
34
+ return _ctx.handleTouchend && _ctx.handleTouchend(...arguments);
35
+ })
36
+ }, _ctx.getAttrs()), [_renderSlot(_ctx.$slots, "default")], 16 /* FULL_PROPS */)], 8 /* PROPS */, ["to"]);
37
+ }
38
+ var __sfc__ = defineComponent({
39
+ name: 'VarDrag',
40
+ inheritAttrs: false,
41
+ props,
42
+ setup(props, _ref) {
43
+ var {
44
+ attrs
45
+ } = _ref;
46
+ var drag = ref(null);
47
+ var x = ref(0);
48
+ var y = ref(0);
49
+ var boundary = reactive({
50
+ top: 0,
51
+ bottom: 0,
52
+ left: 0,
53
+ right: 0
54
+ });
55
+ var mounted = ref(false);
56
+ var enableTransition = ref(false);
57
+ var touching = false;
58
+ var prevX = 0;
59
+ var prevY = 0;
60
+ var saveXY = () => {
61
+ var {
62
+ left,
63
+ top
64
+ } = getOffset();
65
+ x.value = left;
66
+ y.value = top;
67
+ };
68
+ var handleTouchstart = event => {
69
+ if (props.disabled) {
70
+ return;
71
+ }
72
+ var {
73
+ clientX,
74
+ clientY
75
+ } = event.touches[0];
76
+ saveXY();
77
+ prevX = clientX;
78
+ prevY = clientY;
79
+ touching = true;
80
+ };
81
+ var handleTouchmove = /*#__PURE__*/function () {
82
+ var _ref2 = _asyncToGenerator(function* (event) {
83
+ if (!touching || props.disabled) {
84
+ return;
85
+ }
86
+ event.preventDefault();
87
+ enableTransition.value = false;
88
+ var {
89
+ clientX,
90
+ clientY
91
+ } = event.touches[0];
92
+ var deltaX = clientX - prevX;
93
+ var deltaY = clientY - prevY;
94
+ prevX = clientX;
95
+ prevY = clientY;
96
+ if (props.direction.includes('x')) {
97
+ x.value += deltaX;
98
+ }
99
+ if (props.direction.includes('y')) {
100
+ y.value += deltaY;
101
+ }
102
+ clampToBoundary();
103
+ });
104
+ return function handleTouchmove(_x) {
105
+ return _ref2.apply(this, arguments);
106
+ };
107
+ }();
108
+ var handleTouchend = () => {
109
+ if (props.disabled) {
110
+ return;
111
+ }
112
+ touching = false;
113
+ attract();
114
+ };
115
+ var getOffset = () => {
116
+ var dragRect = getRect(drag.value);
117
+ var windowRect = getRect(window);
118
+ var top = dragRect.top - windowRect.top;
119
+ var bottom = windowRect.bottom - dragRect.bottom;
120
+ var left = dragRect.left - windowRect.left;
121
+ var right = windowRect.right - dragRect.right;
122
+ var {
123
+ width,
124
+ height
125
+ } = dragRect;
126
+ var {
127
+ width: windowWidth,
128
+ height: windowHeight
129
+ } = windowRect;
130
+ return {
131
+ top,
132
+ bottom,
133
+ left,
134
+ right,
135
+ width,
136
+ height,
137
+ halfWidth: width / 2,
138
+ halfHeight: height / 2,
139
+ windowWidth,
140
+ windowHeight
141
+ };
142
+ };
143
+ var getRange = () => {
144
+ var offset = getOffset();
145
+ var x1 = boundary.left;
146
+ var x2 = offset.windowWidth - boundary.right - offset.width;
147
+ var y1 = boundary.top;
148
+ var y2 = offset.windowHeight - boundary.bottom - offset.height;
149
+ return {
150
+ minX: x1,
151
+ minY: y1,
152
+ // fallback the drag element overflows boundary
153
+ maxX: x1 < x2 ? x2 : x1,
154
+ maxY: y1 < y2 ? y2 : y1
155
+ };
156
+ };
157
+ var attract = () => {
158
+ if (props.attraction == null) {
159
+ return;
160
+ }
161
+ enableTransition.value = true;
162
+ var {
163
+ halfWidth,
164
+ halfHeight,
165
+ top,
166
+ bottom,
167
+ left,
168
+ right
169
+ } = getOffset();
170
+ var {
171
+ minX,
172
+ minY,
173
+ maxX,
174
+ maxY
175
+ } = getRange();
176
+ var leftDistance = left + halfWidth - boundary.left;
177
+ var rightDistance = right + halfWidth - boundary.right;
178
+ var topDistance = top + halfHeight - boundary.top;
179
+ var bottomDistance = bottom + halfHeight - boundary.bottom;
180
+ var nearLeft = leftDistance <= rightDistance;
181
+ var nearTop = topDistance <= bottomDistance;
182
+ if (props.attraction.includes('x')) {
183
+ x.value = nearLeft ? minX : maxX;
184
+ }
185
+ if (props.attraction.includes('y')) {
186
+ y.value = nearTop ? minY : maxY;
187
+ }
188
+ };
189
+ var clampToBoundary = () => {
190
+ if (props.disabled) {
191
+ return;
192
+ }
193
+ var {
194
+ minX,
195
+ minY,
196
+ maxX,
197
+ maxY
198
+ } = getRange();
199
+ x.value = clamp(x.value, minX, maxX);
200
+ y.value = clamp(y.value, minY, maxY);
201
+ };
202
+ var toPxBoundary = () => {
203
+ var {
204
+ top = 0,
205
+ bottom = 0,
206
+ left = 0,
207
+ right = 0
208
+ } = props.boundary;
209
+ boundary.top = toPxNum(top);
210
+ boundary.bottom = toPxNum(bottom);
211
+ boundary.left = toPxNum(left);
212
+ boundary.right = toPxNum(right);
213
+ };
214
+ var getAttrs = () => {
215
+ var _ref3;
216
+ var style = (_ref3 = attrs.style) != null ? _ref3 : {};
217
+ return _extends({}, attrs, {
218
+ style: _extends({}, style, {
219
+ // when the drag element is mounted for the first time, the inset should be cleared to avoid affecting translateX and translateY.
220
+ top: mounted.value ? 0 : style.top,
221
+ left: mounted.value ? 0 : style.left,
222
+ right: mounted.value ? 'auto' : style.right,
223
+ bottom: mounted.value ? 'auto' : style.bottom,
224
+ transform: mounted.value ? "translate(" + x.value + "px, " + y.value + "px)" : style.transform
225
+ })
226
+ });
227
+ };
228
+
229
+ // expose
230
+ var resize = () => {
231
+ toPxBoundary();
232
+ saveXY();
233
+ clampToBoundary();
234
+ };
235
+ watch(() => props.boundary, resize);
236
+ onWindowResize(resize);
237
+ onSmartMounted(() => {
238
+ resize();
239
+ mounted.value = true;
240
+ });
241
+ return {
242
+ drag,
243
+ x,
244
+ y,
245
+ enableTransition,
246
+ n,
247
+ classes,
248
+ getAttrs,
249
+ handleTouchstart,
250
+ handleTouchmove,
251
+ handleTouchend,
252
+ resize
253
+ };
254
+ }
255
+ });
256
+ __sfc__.render = __render__;
257
+ export default __sfc__;
File without changes
@@ -0,0 +1 @@
1
+ .var-drag { position: fixed; display: inline-flex;}.var-drag--transition { transition: transform 0.2s linear;}
@@ -0,0 +1,7 @@
1
+ import Drag from './Drag.mjs';
2
+ Drag.install = function (app) {
3
+ app.component(Drag.name, Drag);
4
+ };
5
+ export { props as dragProps } from './props.mjs';
6
+ export var _DragComponent = Drag;
7
+ export default Drag;
@@ -0,0 +1,30 @@
1
+ export var props = {
2
+ direction: {
3
+ type: String,
4
+ default: 'xy'
5
+ },
6
+ attraction: {
7
+ type: String
8
+ },
9
+ disabled: {
10
+ type: Boolean,
11
+ default: false
12
+ },
13
+ boundary: {
14
+ type: Object,
15
+ default: () => ({
16
+ top: 0,
17
+ bottom: 0,
18
+ left: 0,
19
+ right: 0
20
+ })
21
+ },
22
+ zIndex: {
23
+ type: [Number, String],
24
+ default: 90
25
+ },
26
+ teleport: {
27
+ type: [String, Object],
28
+ default: 'body'
29
+ }
30
+ };
@@ -0,0 +1,3 @@
1
+ import '../../styles/common.css'
2
+ import '../drag.css'
3
+ import '../DragSfc.css'
@@ -4,7 +4,7 @@ import { props } from './props.mjs';
4
4
  var {
5
5
  n
6
6
  } = createNamespace('form-details');
7
- import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock, createCommentVNode as _createCommentVNode, Transition as _Transition, withCtx as _withCtx, createVNode as _createVNode, normalizeClass as _normalizeClass, createElementVNode as _createElementVNode, createBlock as _createBlock, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from "vue";
7
+ import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock, createCommentVNode as _createCommentVNode, Transition as _Transition, withCtx as _withCtx, createVNode as _createVNode, normalizeClass as _normalizeClass, createElementVNode as _createElementVNode, renderSlot as _renderSlot, createBlock as _createBlock, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from "vue";
8
8
  var _withScopeId = n => (_pushScopeId(""), n = n(), _popScopeId(), n);
9
9
  var _hoisted_1 = {
10
10
  key: 0
@@ -16,7 +16,7 @@ function __render__(_ctx, _cache) {
16
16
  return _openBlock(), _createBlock(_Transition, {
17
17
  name: _ctx.n()
18
18
  }, {
19
- default: _withCtx(() => [_ctx.errorMessage || _ctx.extraMessage ? (_openBlock(), _createElementBlock("div", {
19
+ default: _withCtx(() => [_ctx.errorMessage || _ctx.extraMessage || _ctx.$slots['extra-message'] ? (_openBlock(), _createElementBlock("div", {
20
20
  key: 0,
21
21
  class: _normalizeClass(_ctx.n())
22
22
  }, [_createElementVNode("div", {
@@ -31,10 +31,10 @@ function __render__(_ctx, _cache) {
31
31
  }, [_createVNode(_Transition, {
32
32
  name: _ctx.n('message')
33
33
  }, {
34
- default: _withCtx(() => [_ctx.extraMessage ? (_openBlock(), _createElementBlock("div", _hoisted_2, _toDisplayString(_ctx.extraMessage), 1 /* TEXT */)) : _createCommentVNode("v-if", true)]),
35
- _: 1 /* STABLE */
34
+ default: _withCtx(() => [_renderSlot(_ctx.$slots, "extra-message", {}, () => [_ctx.extraMessage ? (_openBlock(), _createElementBlock("div", _hoisted_2, _toDisplayString(_ctx.extraMessage), 1 /* TEXT */)) : _createCommentVNode("v-if", true)])]),
35
+ _: 3 /* FORWARDED */
36
36
  }, 8 /* PROPS */, ["name"])], 2 /* CLASS */)], 2 /* CLASS */)) : _createCommentVNode("v-if", true)]),
37
- _: 1 /* STABLE */
37
+ _: 3 /* FORWARDED */
38
38
  }, 8 /* PROPS */, ["name"]);
39
39
  }
40
40
  var __sfc__ = defineComponent({
@@ -24,6 +24,7 @@ import Counter from './counter/index.mjs'
24
24
  import DatePicker from './date-picker/index.mjs'
25
25
  import Dialog from './dialog/index.mjs'
26
26
  import Divider from './divider/index.mjs'
27
+ import Drag from './drag/index.mjs'
27
28
  import Ellipsis from './ellipsis/index.mjs'
28
29
  import Fab from './fab/index.mjs'
29
30
  import Form from './form/index.mjs'
@@ -105,6 +106,7 @@ export * from './counter/index.mjs'
105
106
  export * from './date-picker/index.mjs'
106
107
  export * from './dialog/index.mjs'
107
108
  export * from './divider/index.mjs'
109
+ export * from './drag/index.mjs'
108
110
  export * from './ellipsis/index.mjs'
109
111
  export * from './fab/index.mjs'
110
112
  export * from './form/index.mjs'
@@ -186,6 +188,7 @@ import './counter/style/index.mjs'
186
188
  import './date-picker/style/index.mjs'
187
189
  import './dialog/style/index.mjs'
188
190
  import './divider/style/index.mjs'
191
+ import './drag/style/index.mjs'
189
192
  import './ellipsis/style/index.mjs'
190
193
  import './fab/style/index.mjs'
191
194
  import './form/style/index.mjs'
@@ -241,7 +244,7 @@ import './time-picker/style/index.mjs'
241
244
  import './tooltip/style/index.mjs'
242
245
  import './uploader/style/index.mjs'
243
246
 
244
- const version = '2.12.3'
247
+ const version = '2.13.0-alpha.1689346411483'
245
248
 
246
249
  function install(app) {
247
250
  ActionSheet.install && app.use(ActionSheet)
@@ -270,6 +273,7 @@ function install(app) {
270
273
  DatePicker.install && app.use(DatePicker)
271
274
  Dialog.install && app.use(Dialog)
272
275
  Divider.install && app.use(Divider)
276
+ Drag.install && app.use(Drag)
273
277
  Ellipsis.install && app.use(Ellipsis)
274
278
  Fab.install && app.use(Fab)
275
279
  Form.install && app.use(Form)
@@ -355,6 +359,7 @@ export {
355
359
  DatePicker,
356
360
  Dialog,
357
361
  Divider,
362
+ Drag,
358
363
  Ellipsis,
359
364
  Fab,
360
365
  Form,
@@ -440,6 +445,7 @@ export default {
440
445
  DatePicker,
441
446
  Dialog,
442
447
  Divider,
448
+ Drag,
443
449
  Ellipsis,
444
450
  Fab,
445
451
  Form,
package/es/index.mjs CHANGED
@@ -24,6 +24,7 @@ import Counter from './counter/index.mjs'
24
24
  import DatePicker from './date-picker/index.mjs'
25
25
  import Dialog from './dialog/index.mjs'
26
26
  import Divider from './divider/index.mjs'
27
+ import Drag from './drag/index.mjs'
27
28
  import Ellipsis from './ellipsis/index.mjs'
28
29
  import Fab from './fab/index.mjs'
29
30
  import Form from './form/index.mjs'
@@ -105,6 +106,7 @@ export * from './counter/index.mjs'
105
106
  export * from './date-picker/index.mjs'
106
107
  export * from './dialog/index.mjs'
107
108
  export * from './divider/index.mjs'
109
+ export * from './drag/index.mjs'
108
110
  export * from './ellipsis/index.mjs'
109
111
  export * from './fab/index.mjs'
110
112
  export * from './form/index.mjs'
@@ -160,7 +162,7 @@ export * from './time-picker/index.mjs'
160
162
  export * from './tooltip/index.mjs'
161
163
  export * from './uploader/index.mjs'
162
164
 
163
- const version = '2.12.3'
165
+ const version = '2.13.0-alpha.1689346411483'
164
166
 
165
167
  function install(app) {
166
168
  ActionSheet.install && app.use(ActionSheet)
@@ -189,6 +191,7 @@ function install(app) {
189
191
  DatePicker.install && app.use(DatePicker)
190
192
  Dialog.install && app.use(Dialog)
191
193
  Divider.install && app.use(Divider)
194
+ Drag.install && app.use(Drag)
192
195
  Ellipsis.install && app.use(Ellipsis)
193
196
  Fab.install && app.use(Fab)
194
197
  Form.install && app.use(Form)
@@ -274,6 +277,7 @@ export {
274
277
  DatePicker,
275
278
  Dialog,
276
279
  Divider,
280
+ Drag,
277
281
  Ellipsis,
278
282
  Fab,
279
283
  Form,
@@ -359,6 +363,7 @@ export default {
359
363
  DatePicker,
360
364
  Dialog,
361
365
  Divider,
366
+ Drag,
362
367
  Ellipsis,
363
368
  Fab,
364
369
  Form,
@@ -144,7 +144,13 @@ function __render__(_ctx, _cache) {
144
144
  "error-message": _ctx.errorMessage,
145
145
  "extra-message": _ctx.maxlengthText,
146
146
  onMousedown: _cache[14] || (_cache[14] = _withModifiers(() => {}, ["stop"]))
147
- }, null, 8 /* PROPS */, ["error-message", "extra-message"])], 34 /* CLASS, HYDRATE_EVENTS */);
147
+ }, _createSlots({
148
+ _: 2 /* DYNAMIC */
149
+ }, [_ctx.$slots['extra-message'] ? {
150
+ name: "extra-message",
151
+ fn: _withCtx(() => [_renderSlot(_ctx.$slots, "extra-message")]),
152
+ key: "0"
153
+ } : undefined]), 1032 /* PROPS, DYNAMIC_SLOTS */, ["error-message", "extra-message"])], 34 /* CLASS, HYDRATE_EVENTS */);
148
154
  }
149
155
 
150
156
  var __sfc__ = defineComponent({
@@ -46,7 +46,7 @@ export var props = {
46
46
  default: false
47
47
  },
48
48
  teleport: {
49
- type: String,
49
+ type: [String, Object],
50
50
  default: 'body'
51
51
  },
52
52
  onOpen: defineListenerProp(),
@@ -21,7 +21,7 @@ function __render__(_ctx, _cache) {
21
21
  var _component_var_form_details = _resolveComponent("var-form-details");
22
22
  var _directive_hover = _resolveDirective("hover");
23
23
  return _openBlock(), _createElementBlock("div", {
24
- class: _normalizeClass(_ctx.n(_ctx.direction))
24
+ class: _normalizeClass(_ctx.classes(_ctx.n(_ctx.direction), _ctx.n('$--box')))
25
25
  }, [_createElementVNode("div", {
26
26
  class: _normalizeClass(_ctx.classes(_ctx.n(_ctx.direction + "-block"), [_ctx.isDisabled, _ctx.n('--disabled')], [_ctx.errorMessage, _ctx.n(_ctx.direction + "--error")])),
27
27
  ref: "sliderEl",
@@ -14,26 +14,21 @@ export var props = {
14
14
  type: String,
15
15
  validator: typeValidator
16
16
  },
17
- // snackbar显示的位置
18
17
  position: {
19
18
  type: String,
20
19
  default: 'top',
21
20
  validator: positionValidator
22
21
  },
23
- // content内容
24
22
  content: {
25
23
  type: [String, Function, Object]
26
24
  },
27
- // 为snackbar content添加自定义类名
28
25
  contentClass: {
29
26
  type: String
30
27
  },
31
- // snackbar 持续时间
32
28
  duration: {
33
29
  type: Number,
34
30
  default: 3000
35
31
  },
36
- // 是否将消息条内容堆叠在操作(按钮)之上
37
32
  vertical: {
38
33
  type: Boolean,
39
34
  default: false
@@ -44,33 +39,25 @@ export var props = {
44
39
  loadingColor: _extends({}, pickProps(loadingProps, 'color'), {
45
40
  default: 'currentColor'
46
41
  }),
47
- // 是否禁止滚动穿透
48
42
  lockScroll: {
49
43
  type: Boolean,
50
44
  default: false
51
45
  },
52
- // 控制组件可见还是隐藏
53
46
  show: {
54
47
  type: Boolean,
55
48
  default: false
56
49
  },
57
- // teleport
58
50
  teleport: {
59
- type: String,
51
+ type: [String, Object],
60
52
  default: 'body'
61
53
  },
62
- // 是否禁止点击背景
63
54
  forbidClick: {
64
55
  type: Boolean,
65
56
  default: false
66
57
  },
67
- // 打开时的回调函数
68
58
  onOpen: defineListenerProp(),
69
- // 打开动画结束时的回调
70
59
  onOpened: defineListenerProp(),
71
- // 关闭时的回调函数
72
60
  onClose: defineListenerProp(),
73
- // 关闭动画结束时的回调
74
61
  onClosed: defineListenerProp(),
75
62
  'onUpdate:show': defineListenerProp(),
76
63
  _update: {