@varlet/ui 2.18.3-alpha.1699111361708 → 2.18.3

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,42 +1,120 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
1
17
  import dayjs from "dayjs/esm";
2
- import { defineComponent, computed, ref } from "vue";
18
+ import {
19
+ defineComponent,
20
+ computed,
21
+ ref,
22
+ watch,
23
+ reactive
24
+ } from "vue";
3
25
  import { toNumber } from "@varlet/shared";
26
+ import VarButton from "../../button/index.mjs";
27
+ import PanelHeader from "./panel-header.mjs";
4
28
  import { createNamespace } from "../../utils/components.mjs";
5
29
  import { onSmartMounted } from "@varlet/use";
6
30
  const { n, classes } = createNamespace("year-picker");
7
- import { renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, toDisplayString as _toDisplayString, normalizeClass as _normalizeClass, normalizeStyle as _normalizeStyle, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from "vue";
8
- const _withScopeId = (n2) => (_pushScopeId(""), n2 = n2(), _popScopeId(), n2);
9
- const _hoisted_1 = ["onClick"];
31
+ const { n: nDate } = createNamespace("date-picker");
32
+ import { resolveComponent as _resolveComponent, createVNode as _createVNode, withCtx as _withCtx, renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, mergeProps as _mergeProps, normalizeClass as _normalizeClass, Transition as _Transition } from "vue";
10
33
  function __render__(_ctx, _cache) {
11
- return _openBlock(), _createElementBlock(
12
- "ul",
13
- {
14
- ref: "panel",
15
- class: _normalizeClass(_ctx.n())
16
- },
17
- [
18
- (_openBlock(true), _createElementBlock(
19
- _Fragment,
20
- null,
21
- _renderList(_ctx.yearList, (year) => {
22
- return _openBlock(), _createElementBlock("li", {
23
- key: year,
24
- class: _normalizeClass(_ctx.classes(_ctx.n("item"), [year === _ctx.toNumber(_ctx.preview), _ctx.n("item--active")])),
25
- style: _normalizeStyle({ color: year === _ctx.toNumber(_ctx.preview) ? _ctx.componentProps.color : "" }),
26
- onClick: ($event) => _ctx.chooseYear(year)
27
- }, _toDisplayString(year), 15, _hoisted_1);
28
- }),
29
- 128
30
- /* KEYED_FRAGMENT */
31
- ))
32
- ],
33
- 2
34
- /* CLASS */
35
- );
34
+ const _component_panel_header = _resolveComponent("panel-header");
35
+ const _component_var_sticky = _resolveComponent("var-sticky");
36
+ const _component_var_button = _resolveComponent("var-button");
37
+ return _openBlock(), _createElementBlock("div", null, [
38
+ _createVNode(_component_var_sticky, { "css-mode": "" }, {
39
+ default: _withCtx(() => [
40
+ _createVNode(_component_panel_header, {
41
+ ref: "headerEl",
42
+ type: "year",
43
+ date: {
44
+ previewYear: `${_ctx.yearList[0]} ~ ${_ctx.yearList[_ctx.yearList.length - 1]}`
45
+ },
46
+ disabled: _ctx.panelBtnDisabled,
47
+ onCheckDate: _ctx.checkDate
48
+ }, null, 8, ["date", "disabled", "onCheckDate"])
49
+ ]),
50
+ _: 1
51
+ /* STABLE */
52
+ }),
53
+ _createVNode(_Transition, {
54
+ name: `${_ctx.nDate()}${_ctx.reverse ? "-reverse" : ""}-translatex`
55
+ }, {
56
+ default: _withCtx(() => [
57
+ (_openBlock(), _createElementBlock(
58
+ "ul",
59
+ {
60
+ ref: "panel",
61
+ class: _normalizeClass(_ctx.n()),
62
+ key: _ctx.panelKey
63
+ },
64
+ [
65
+ (_openBlock(true), _createElementBlock(
66
+ _Fragment,
67
+ null,
68
+ _renderList(_ctx.yearList, (year) => {
69
+ return _openBlock(), _createElementBlock("li", { key: year }, [
70
+ _createVNode(_component_var_button, _mergeProps({
71
+ type: "primary",
72
+ "var-year-picker-cover": "",
73
+ ripple: false,
74
+ elevation: _ctx.componentProps.buttonElevation
75
+ }, __spreadValues({}, _ctx.buttonProps(`${year}`)), {
76
+ onClick: (event) => _ctx.chooseYear(year, event)
77
+ }), {
78
+ default: _withCtx(() => [
79
+ _createTextVNode(
80
+ _toDisplayString(year),
81
+ 1
82
+ /* TEXT */
83
+ )
84
+ ]),
85
+ _: 2
86
+ /* DYNAMIC */
87
+ }, 1040, ["elevation", "onClick"])
88
+ ]);
89
+ }),
90
+ 128
91
+ /* KEYED_FRAGMENT */
92
+ ))
93
+ ],
94
+ 2
95
+ /* CLASS */
96
+ ))
97
+ ]),
98
+ _: 1
99
+ /* STABLE */
100
+ }, 8, ["name"])
101
+ ]);
36
102
  }
37
103
  const __sfc__ = defineComponent({
38
104
  name: "YearPickerPanel",
105
+ components: {
106
+ VarButton,
107
+ PanelHeader
108
+ },
39
109
  props: {
110
+ choose: {
111
+ type: Object,
112
+ required: true
113
+ },
114
+ current: {
115
+ type: String,
116
+ required: true
117
+ },
40
118
  preview: {
41
119
  type: String
42
120
  },
@@ -47,52 +125,171 @@ const __sfc__ = defineComponent({
47
125
  },
48
126
  emits: ["choose-year"],
49
127
  setup(props, { emit }) {
128
+ const [currentYear] = props.current.split("-");
50
129
  const panel = ref();
130
+ const headerEl = ref(null);
131
+ const reverse = ref(false);
132
+ const panelKey = ref(0);
133
+ const page = ref(0);
134
+ const panelBtnDisabled = reactive({
135
+ left: false,
136
+ right: false
137
+ });
51
138
  const yearList = computed(() => {
52
139
  const list = [];
53
- const {
54
- preview,
55
- componentProps: { max, min }
56
- } = props;
57
- if (!preview)
140
+ if (!props.preview)
58
141
  return list;
59
- let yearRange = [toNumber(preview) + 100, toNumber(preview) - 100];
60
- if (max) {
61
- const formatMax = dayjs(max).format("YYYY-MM-D");
62
- const year = toNumber(formatMax.split("-")[0]);
63
- if (year < yearRange[0] && year > yearRange[1])
64
- yearRange = [year, yearRange[1]];
65
- if (year <= yearRange[1])
66
- return [year];
67
- }
68
- if (min) {
69
- const formatMin = dayjs(min).format("YYYY-MM-D");
70
- const year = toNumber(formatMin.split("-")[0]);
71
- if (year < yearRange[0] && year > yearRange[1])
72
- yearRange = [yearRange[0], year];
73
- if (year >= yearRange[0])
74
- return [year];
75
- }
76
- for (let i = yearRange[0]; i >= yearRange[1]; i--) {
142
+ let startYear = Math.floor(toNumber(props.preview) / 100 + page.value) * 100;
143
+ startYear = startYear < 0 ? 0 : startYear;
144
+ const yearRange = [startYear, startYear + 100];
145
+ for (let i = yearRange[0]; i < yearRange[1]; i++) {
77
146
  list.push(i);
78
147
  }
79
148
  return list;
80
149
  });
81
- const chooseYear = (year) => {
150
+ const shouldChoose = (val) => {
151
+ const {
152
+ choose: { chooseMonths, chooseDays, chooseYears, chooseRangeYear },
153
+ componentProps: { type, range }
154
+ } = props;
155
+ if (range) {
156
+ if (!chooseRangeYear.length)
157
+ return false;
158
+ const isBeforeMax = dayjs(val).isSameOrBefore(dayjs(chooseRangeYear[1]), "year");
159
+ const isAfterMin = dayjs(val).isSameOrAfter(dayjs(chooseRangeYear[0]), "year");
160
+ return isBeforeMax && isAfterMin;
161
+ }
162
+ if (type === "year")
163
+ return chooseYears.includes(val);
164
+ if (type === "month")
165
+ return chooseMonths.some((value) => value.includes(val));
166
+ return chooseDays.some((value) => value.includes(val));
167
+ };
168
+ const inRange = (year) => {
169
+ const {
170
+ componentProps: { min, max }
171
+ } = props;
172
+ let isBeforeMax = true;
173
+ let isAfterMin = true;
174
+ if (max)
175
+ isBeforeMax = dayjs(year).isSameOrBefore(dayjs(max), "year");
176
+ if (min)
177
+ isAfterMin = dayjs(year).isSameOrAfter(dayjs(min), "year");
178
+ return isBeforeMax && isAfterMin;
179
+ };
180
+ const buttonProps = (year) => {
181
+ const {
182
+ choose: { chooseYear: chooseYear2 },
183
+ componentProps: { allowedDates, color, multiple, range }
184
+ } = props;
185
+ const yearExist = () => {
186
+ if (range || multiple)
187
+ return shouldChoose(year);
188
+ return chooseYear2 === year;
189
+ };
190
+ const computeDisabled = () => {
191
+ if (!inRange(year))
192
+ return true;
193
+ if (!allowedDates)
194
+ return false;
195
+ return !allowedDates(year);
196
+ };
197
+ const disabled = computeDisabled();
198
+ const computeText = () => {
199
+ if (disabled)
200
+ return true;
201
+ if (range || multiple)
202
+ return !shouldChoose(year);
203
+ return chooseYear2 !== year;
204
+ };
205
+ const computeOutline = () => {
206
+ if (!(currentYear === year && props.componentProps.showCurrent))
207
+ return false;
208
+ if ((range || multiple) && disabled)
209
+ return true;
210
+ if (range || multiple)
211
+ return !shouldChoose(year);
212
+ return chooseYear2 !== currentYear;
213
+ };
214
+ const textColorOrCover = () => {
215
+ if (disabled)
216
+ return "";
217
+ if (computeOutline())
218
+ return color != null ? color : "";
219
+ if (yearExist())
220
+ return "";
221
+ return `${nDate()}-color-cover`;
222
+ };
223
+ const isCover = textColorOrCover().startsWith(nDate());
224
+ return {
225
+ outline: computeOutline(),
226
+ text: computeText(),
227
+ color: !computeText() ? color : "",
228
+ textColor: isCover ? "" : textColorOrCover(),
229
+ [`${nDate()}-color-cover`]: isCover,
230
+ class: classes(n("button"), [disabled, n("button--disabled")]),
231
+ disabled
232
+ };
233
+ };
234
+ const chooseYear = (year, event) => {
235
+ const buttonEl = event.currentTarget;
236
+ if (buttonEl.classList.contains(n("button--disabled")))
237
+ return;
82
238
  emit("choose-year", year);
83
239
  };
84
- onSmartMounted(() => {
85
- const activeEl = panel.value.querySelector(`.${n("item--active")}`);
240
+ const scrollToView = () => {
241
+ var _a;
242
+ const activeEl = (_a = panel.value.querySelector(".var-button--primary")) != null ? _a : panel.value.querySelector(".var-button--outline");
86
243
  activeEl == null ? void 0 : activeEl.scrollIntoView({
87
244
  block: "center"
88
245
  });
89
- });
246
+ };
247
+ const checkDate = (checkType) => {
248
+ reverse.value = checkType === "prev";
249
+ panelKey.value += checkType === "prev" ? -1 : 1;
250
+ page.value += checkType === "prev" ? -1 : 1;
251
+ };
252
+ const forwardRef = (checkType) => {
253
+ headerEl.value.checkDate(checkType);
254
+ };
255
+ onSmartMounted(scrollToView);
256
+ watch(
257
+ () => props.preview,
258
+ () => {
259
+ page.value = 0;
260
+ }
261
+ );
262
+ watch(
263
+ yearList,
264
+ (list) => {
265
+ const {
266
+ componentProps: { min, max }
267
+ } = props;
268
+ if (max)
269
+ panelBtnDisabled.right = !dayjs(`${toNumber(list[list.length - 1])}`).isSameOrBefore(dayjs(max), "year");
270
+ if (min)
271
+ panelBtnDisabled.left = !dayjs(`${toNumber(list[0])}`).isSameOrAfter(dayjs(min), "year");
272
+ if (toNumber(list[0] <= 0))
273
+ panelBtnDisabled.left = false;
274
+ },
275
+ {
276
+ immediate: true
277
+ }
278
+ );
90
279
  return {
91
280
  n,
92
281
  classes,
282
+ buttonProps,
93
283
  panel,
284
+ headerEl,
94
285
  yearList,
286
+ reverse,
287
+ panelKey,
288
+ panelBtnDisabled,
289
+ nDate,
290
+ checkDate,
95
291
  chooseYear,
292
+ forwardRef,
96
293
  toNumber
97
294
  };
98
295
  }
@@ -2,6 +2,7 @@ import '../../styles/common.css'
2
2
  import '../../styles/elevation.css'
3
3
  import '../../ripple/ripple.css'
4
4
  import '../../button/button.css'
5
+ import '../../sticky/sticky.css'
5
6
  import '../../icon/icon.css'
6
7
  import '../date-picker.css'
7
8
  import '../DatePickerSfc.css'
@@ -13,6 +13,7 @@ const EVENT_DELAY = 200;
13
13
  const TAP_DELAY = 350;
14
14
  const ANIMATION_DURATION = 200;
15
15
  const LONG_PRESS_DELAY = 500;
16
+ const BASE_RATIO = 1;
16
17
  import { renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, normalizeClass as _normalizeClass, createElementVNode as _createElementVNode, normalizeStyle as _normalizeStyle, resolveComponent as _resolveComponent, withCtx as _withCtx, createBlock as _createBlock, renderSlot as _renderSlot, toDisplayString as _toDisplayString, createCommentVNode as _createCommentVNode, mergeProps as _mergeProps, createVNode as _createVNode, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from "vue";
17
18
  const _withScopeId = (n2) => (_pushScopeId(""), n2 = n2(), _popScopeId(), n2);
18
19
  const _hoisted_1 = ["onTouchstart"];
@@ -178,8 +179,8 @@ const __sfc__ = defineComponent({
178
179
  },
179
180
  { immediate: true }
180
181
  );
181
- function zoomIn() {
182
- scale.value = toNumber(props2.zoom);
182
+ function zoomIn(ratio) {
183
+ scale.value = toNumber(ratio);
183
184
  canSwipe.value = false;
184
185
  targets.prev = null;
185
186
  window.setTimeout(() => {
@@ -237,7 +238,7 @@ const __sfc__ = defineComponent({
237
238
  call(props2.onLongPress, idx);
238
239
  }, LONG_PRESS_DELAY);
239
240
  if (isDoubleTouch(target)) {
240
- scale.value > 1 ? zoomOut() : zoomIn();
241
+ scale.value > BASE_RATIO ? zoomOut() : zoomIn(props2.zoom);
241
242
  return;
242
243
  }
243
244
  startTouch(event);
@@ -255,20 +256,20 @@ const __sfc__ = defineComponent({
255
256
  };
256
257
  }
257
258
  function getLimitX(target) {
258
- const { zoom, imageRadio, rootRadio, width, height } = getZoom(target);
259
+ const { zoom: zoom2, imageRadio, rootRadio, width, height } = getZoom(target);
259
260
  if (!imageRadio) {
260
261
  return 0;
261
262
  }
262
263
  const displayWidth = imageRadio > rootRadio ? height / imageRadio : width;
263
- return Math.max(0, (zoom * displayWidth - width) / 2) / zoom;
264
+ return Math.max(0, (zoom2 * displayWidth - width) / 2) / zoom2;
264
265
  }
265
266
  function getLimitY(target) {
266
- const { zoom, imageRadio, rootRadio, width, height } = getZoom(target);
267
+ const { zoom: zoom2, imageRadio, rootRadio, width, height } = getZoom(target);
267
268
  if (!imageRadio) {
268
269
  return 0;
269
270
  }
270
271
  const displayHeight = imageRadio > rootRadio ? height : width * imageRadio;
271
- return Math.max(0, (zoom * displayHeight - height) / 2) / zoom;
272
+ return Math.max(0, (zoom2 * displayHeight - height) / 2) / zoom2;
272
273
  }
273
274
  function handleTouchmove(event) {
274
275
  if (!targets.prev) {
@@ -279,7 +280,7 @@ const __sfc__ = defineComponent({
279
280
  if (distance.value > DISTANCE_OFFSET) {
280
281
  window.clearTimeout(longPressRunner);
281
282
  }
282
- if (scale.value > 1) {
283
+ if (scale.value > BASE_RATIO) {
283
284
  const limitX = getLimitX(target);
284
285
  const limitY = getLimitY(target);
285
286
  translateX.value = clamp(translateX.value + moveX.value, -limitX, limitX);
@@ -288,13 +289,18 @@ const __sfc__ = defineComponent({
288
289
  targets.prev = target;
289
290
  }
290
291
  function close() {
291
- if (scale.value > 1) {
292
+ if (scale.value > BASE_RATIO) {
292
293
  zoomOut();
293
294
  setTimeout(() => call(props2["onUpdate:show"], false), ANIMATION_DURATION);
294
295
  return;
295
296
  }
296
297
  call(props2["onUpdate:show"], false);
297
298
  }
299
+ function preventImageDefault(event) {
300
+ if (isPreventDefault.value) {
301
+ preventDefault(event);
302
+ }
303
+ }
298
304
  function prev(options) {
299
305
  var _a;
300
306
  (_a = swipeRef.value) == null ? void 0 : _a.prev(options);
@@ -307,8 +313,8 @@ const __sfc__ = defineComponent({
307
313
  var _a;
308
314
  (_a = swipeRef.value) == null ? void 0 : _a.to(idx, options);
309
315
  }
310
- function preventImageDefault(event) {
311
- props2.imagePreventDefault && props2.show && preventDefault(event);
316
+ function zoom(ratio) {
317
+ ratio <= BASE_RATIO ? zoomOut() : zoomIn(ratio);
312
318
  }
313
319
  return {
314
320
  swipeRef,
@@ -330,7 +336,8 @@ const __sfc__ = defineComponent({
330
336
  close,
331
337
  prev,
332
338
  next,
333
- to
339
+ to,
340
+ zoom
334
341
  };
335
342
  }
336
343
  });
@@ -259,7 +259,7 @@ import './tooltip/style/index.mjs'
259
259
  import './uploader/style/index.mjs'
260
260
  import './watermark/style/index.mjs'
261
261
 
262
- const version = '2.18.3-alpha.1699111361708'
262
+ const version = '2.18.3'
263
263
 
264
264
  function install(app) {
265
265
  ActionSheet.install && app.use(ActionSheet)
package/es/index.mjs CHANGED
@@ -172,7 +172,7 @@ export * from './tooltip/index.mjs'
172
172
  export * from './uploader/index.mjs'
173
173
  export * from './watermark/index.mjs'
174
174
 
175
- const version = '2.18.3-alpha.1699111361708'
175
+ const version = '2.18.3'
176
176
 
177
177
  function install(app) {
178
178
  ActionSheet.install && app.use(ActionSheet)