@varlet/ui 2.9.0-alpha.1678431541952 → 2.9.0

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,14 +1,11 @@
1
- import { useAtChildrenCounter, useChildren } from '../utils/components.mjs';
1
+ import { useChildren } from '@varlet/use';
2
2
  export var BOTTOM_NAVIGATION_BIND_BOTTOM_NAVIGATION_ITEM_KEY = Symbol('BOTTOM_NAVIGATION_BIND_BOTTOM_NAVIGATION_ITEM_KEY');
3
- export var BOTTOM_NAVIGATION_COUNT_BOTTOM_NAVIGATION_ITEM_KEY = Symbol('BOTTOM_NAVIGATION_COUNT_BOTTOM_NAVIGATION_ITEM_KEY');
4
3
  export function useBottomNavigationItems() {
5
4
  var {
6
5
  childProviders,
6
+ length,
7
7
  bindChildren
8
8
  } = useChildren(BOTTOM_NAVIGATION_BIND_BOTTOM_NAVIGATION_ITEM_KEY);
9
- var {
10
- length
11
- } = useAtChildrenCounter(BOTTOM_NAVIGATION_COUNT_BOTTOM_NAVIGATION_ITEM_KEY);
12
9
  return {
13
10
  length,
14
11
  bottomNavigationItems: childProviders,
@@ -1,15 +1,13 @@
1
- import { useAtParentIndex, useParent } from '../utils/components.mjs';
2
- import { BOTTOM_NAVIGATION_BIND_BOTTOM_NAVIGATION_ITEM_KEY, BOTTOM_NAVIGATION_COUNT_BOTTOM_NAVIGATION_ITEM_KEY } from '../bottom-navigation/provide.mjs';
1
+ import { useParent } from '@varlet/use';
2
+ import { BOTTOM_NAVIGATION_BIND_BOTTOM_NAVIGATION_ITEM_KEY } from '../bottom-navigation/provide.mjs';
3
3
  export function useBottomNavigation() {
4
4
  var {
5
5
  parentProvider,
6
+ index,
6
7
  bindParent
7
8
  } = useParent(BOTTOM_NAVIGATION_BIND_BOTTOM_NAVIGATION_ITEM_KEY);
8
- var {
9
- index
10
- } = useAtParentIndex(BOTTOM_NAVIGATION_COUNT_BOTTOM_NAVIGATION_ITEM_KEY);
11
9
 
12
- if (!parentProvider || !bindParent || !index) {
10
+ if (!bindParent) {
13
11
  throw Error('<var-bottom-navigation-item/> must in <var-bottom-navigation/>');
14
12
  }
15
13
 
package/es/form/Form.mjs CHANGED
@@ -34,7 +34,7 @@ var __sfc__ = defineComponent({
34
34
  bindFormItems
35
35
  } = useFormItems();
36
36
 
37
- var scroll = (errorIndex, formItemElement) => {
37
+ var scroll = formItemElement => {
38
38
  // wait form-details animation end
39
39
  setTimeout(() => {
40
40
  var scroller = getParentScroller(formItemElement);
@@ -65,7 +65,7 @@ var __sfc__ = defineComponent({
65
65
  var _formItems$errorIndex;
66
66
 
67
67
  var formItemElement = (_formItems$errorIndex = formItems[errorIndex].instance.proxy) == null ? void 0 : _formItems$errorIndex.$el;
68
- scroll(errorIndex, formItemElement);
68
+ scroll(formItemElement);
69
69
  }
70
70
 
71
71
  return !hasError;
@@ -1,12 +1,13 @@
1
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
2
 
3
+ import { useChildren, useParent } from '@varlet/use';
3
4
  import { getCurrentInstance } from 'vue';
4
- import { useChildren, useParent } from '../utils/components.mjs';
5
5
  export var FORM_BIND_FORM_ITEM_KEY = Symbol('FORM_BIND_FORM_ITEM_KEY');
6
6
  export function useForm() {
7
7
  var {
8
- bindParent,
9
- parentProvider
8
+ parentProvider,
9
+ index,
10
+ bindParent
10
11
  } = useParent(FORM_BIND_FORM_ITEM_KEY);
11
12
  var instance = getCurrentInstance();
12
13
  var bindForm = bindParent ? formItemProvider => {
@@ -15,16 +16,19 @@ export function useForm() {
15
16
  }));
16
17
  } : null;
17
18
  return {
18
- bindForm,
19
- form: parentProvider
19
+ index,
20
+ form: parentProvider,
21
+ bindForm
20
22
  };
21
23
  }
22
24
  export function useFormItems() {
23
25
  var {
24
- bindChildren,
25
- childProviders
26
+ childProviders,
27
+ length,
28
+ bindChildren
26
29
  } = useChildren(FORM_BIND_FORM_ITEM_KEY);
27
30
  return {
31
+ length,
28
32
  formItems: childProviders,
29
33
  bindFormItems: bindChildren
30
34
  };
@@ -1,15 +1,13 @@
1
- import { useAtParentIndex, useParent } from '../utils/components.mjs';
2
- import { INDEX_BAR_BIND_INDEX_ANCHOR_KEY, INDEX_BAR_COUNT_INDEX_ANCHOR_KEY } from '../index-bar/provide.mjs';
1
+ import { useParent } from '@varlet/use';
2
+ import { INDEX_BAR_BIND_INDEX_ANCHOR_KEY } from '../index-bar/provide.mjs';
3
3
  export function useIndexBar() {
4
4
  var {
5
5
  parentProvider,
6
+ index,
6
7
  bindParent
7
8
  } = useParent(INDEX_BAR_BIND_INDEX_ANCHOR_KEY);
8
- var {
9
- index
10
- } = useAtParentIndex(INDEX_BAR_COUNT_INDEX_ANCHOR_KEY);
11
9
 
12
- if (!parentProvider || !bindParent) {
10
+ if (!bindParent) {
13
11
  throw Error('[Varlet] IndexAnchor: You should use this component in "IndexBar"');
14
12
  }
15
13
 
@@ -1,14 +1,11 @@
1
- import { useAtChildrenCounter, useChildren } from '../utils/components.mjs';
1
+ import { useChildren } from '@varlet/use';
2
2
  export var INDEX_BAR_BIND_INDEX_ANCHOR_KEY = Symbol('INDEX_BAR_BIND_INDEX_ANCHOR_KEY');
3
- export var INDEX_BAR_COUNT_INDEX_ANCHOR_KEY = Symbol('INDEX_BAR_COUNT_INDEX_ANCHOR_KEY');
4
3
  export function useIndexAnchors() {
5
4
  var {
6
5
  bindChildren,
6
+ length,
7
7
  childProviders
8
8
  } = useChildren(INDEX_BAR_BIND_INDEX_ANCHOR_KEY);
9
- var {
10
- length
11
- } = useAtChildrenCounter(INDEX_BAR_COUNT_INDEX_ANCHOR_KEY);
12
9
  return {
13
10
  length,
14
11
  indexAnchors: childProviders,
@@ -238,7 +238,7 @@ import './time-picker/style/index.mjs'
238
238
  import './tooltip/style/index.mjs'
239
239
  import './uploader/style/index.mjs'
240
240
 
241
- const version = '2.9.0-alpha.1678431541952'
241
+ const version = '2.9.0'
242
242
 
243
243
  function install(app) {
244
244
  ActionSheet.install && app.use(ActionSheet)
package/es/index.mjs CHANGED
@@ -158,7 +158,7 @@ export * from './time-picker/index.mjs'
158
158
  export * from './tooltip/index.mjs'
159
159
  export * from './uploader/index.mjs'
160
160
 
161
- const version = '2.9.0-alpha.1678431541952'
161
+ const version = '2.9.0'
162
162
 
163
163
  function install(app) {
164
164
  ActionSheet.install && app.use(ActionSheet)
@@ -1,7 +1,10 @@
1
1
  import LoadingBarComponent from './LoadingBar.mjs';
2
2
  import { reactive } from 'vue';
3
3
  import { mountInstance } from '../utils/components.mjs';
4
- var timer;
4
+ var valueTimer;
5
+ var errorTimer;
6
+ var opacityTimer;
7
+ var finishTimer;
5
8
  var isMount;
6
9
  var setOptions = {};
7
10
  var internalProps = {
@@ -28,47 +31,66 @@ var resetDefaultOptions = () => {
28
31
  });
29
32
  };
30
33
 
31
- var changeValue = () => {
32
- timer = window.setTimeout(() => {
34
+ var mount = () => {
35
+ if (!isMount) {
36
+ isMount = true;
37
+ mountInstance(LoadingBarComponent, props);
38
+ }
39
+ };
40
+
41
+ var tickValue = () => {
42
+ valueTimer = window.setTimeout(() => {
33
43
  if (props.value >= 95) return;
34
44
  var num = Math.random();
35
45
  if (props.value < 70) num = Math.round(5 * Math.random());
36
46
  props.value += num;
37
- changeValue();
47
+ tickValue();
38
48
  }, 200);
39
49
  };
40
50
 
41
- var start = () => {
42
- if (!isMount) {
43
- isMount = true;
44
- mountInstance(LoadingBarComponent, props);
45
- }
46
-
47
- if (!props.error || props.value === 100) {
48
- props.value = 0;
49
- }
51
+ var clearTimer = () => {
52
+ window.clearTimeout(errorTimer);
53
+ window.clearTimeout(valueTimer);
54
+ window.clearTimeout(opacityTimer);
55
+ window.clearTimeout(finishTimer);
56
+ };
50
57
 
51
- setTimeout(() => {
58
+ var start = () => {
59
+ clearTimer();
60
+ props.error = false;
61
+ props.value = 0;
62
+ mount();
63
+ opacityTimer = window.setTimeout(() => {
52
64
  props.opacity = 1;
53
65
  }, 200);
54
- changeValue();
66
+ tickValue();
55
67
  };
56
68
 
57
69
  var finish = () => {
70
+ clearTimer();
58
71
  props.value = 100;
59
- setTimeout(() => {
72
+ opacityTimer = window.setTimeout(() => {
60
73
  props.opacity = 0;
61
- setTimeout(() => {
74
+ errorTimer = window.setTimeout(() => {
62
75
  props.error = false;
63
76
  }, 250);
64
77
  }, 300);
65
- window.clearTimeout(timer);
66
78
  };
67
79
 
68
80
  var error = () => {
81
+ clearTimer();
69
82
  props.error = true;
70
- LoadingBar.start();
71
- setTimeout(LoadingBar.finish, 300);
83
+
84
+ if (props.value === 100) {
85
+ props.value = 0;
86
+ }
87
+
88
+ mount();
89
+ opacityTimer = window.setTimeout(() => {
90
+ props.opacity = 1;
91
+ }, 200);
92
+ tickValue();
93
+ finishTimer = window.setTimeout(finish, 300);
72
94
  };
73
95
 
74
96
  var LoadingBar = {
@@ -1,15 +1,13 @@
1
- import { useAtParentIndex, useParent } from '../utils/components.mjs';
2
- import { SELECT_BIND_OPTION_KEY, SELECT_COUNT_OPTION_KEY } from '../select/provide.mjs';
1
+ import { useParent } from '@varlet/use';
2
+ import { SELECT_BIND_OPTION_KEY } from '../select/provide.mjs';
3
3
  export function useSelect() {
4
4
  var {
5
- bindParent,
6
- parentProvider
5
+ index,
6
+ parentProvider,
7
+ bindParent
7
8
  } = useParent(SELECT_BIND_OPTION_KEY);
8
- var {
9
- index
10
- } = useAtParentIndex(SELECT_COUNT_OPTION_KEY);
11
9
 
12
- if (!bindParent || !parentProvider) {
10
+ if (!bindParent) {
13
11
  throw Error('<var-option/> must in <var-select/>');
14
12
  }
15
13
 
@@ -1,14 +1,11 @@
1
- import { useAtChildrenCounter, useChildren } from '../utils/components.mjs';
1
+ import { useChildren } from '@varlet/use';
2
2
  export var SELECT_BIND_OPTION_KEY = Symbol('SELECT_BIND_OPTION_KEY');
3
- export var SELECT_COUNT_OPTION_KEY = Symbol('SELECT_COUNT_OPTION_KEY');
4
3
  export function useOptions() {
5
4
  var {
6
- bindChildren,
7
- childProviders
5
+ length,
6
+ childProviders,
7
+ bindChildren
8
8
  } = useChildren(SELECT_BIND_OPTION_KEY);
9
- var {
10
- length
11
- } = useAtChildrenCounter(SELECT_COUNT_OPTION_KEY);
12
9
  return {
13
10
  length,
14
11
  options: childProviders,
@@ -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'
@@ -1,15 +1,13 @@
1
- import { useAtParentIndex, useParent } from '../utils/components.mjs';
2
- import { STEPS_BIND_STEP_KEY, STEPS_COUNT_STEP_KEY } from '../steps/provide.mjs';
1
+ import { useParent } from '@varlet/use';
2
+ import { STEPS_BIND_STEP_KEY } from '../steps/provide.mjs';
3
3
  export function useSteps() {
4
4
  var {
5
5
  parentProvider,
6
+ index,
6
7
  bindParent
7
8
  } = useParent(STEPS_BIND_STEP_KEY);
8
- var {
9
- index
10
- } = useAtParentIndex(STEPS_COUNT_STEP_KEY);
11
9
 
12
- if (!parentProvider || !bindParent || !index) {
10
+ if (!bindParent) {
13
11
  throw Error('[Varlet] Steps: <step/> must in <steps>');
14
12
  }
15
13
 
@@ -1,14 +1,11 @@
1
- import { useAtChildrenCounter, useChildren } from '../utils/components.mjs';
1
+ import { useChildren } from '@varlet/use';
2
2
  export var STEPS_BIND_STEP_KEY = Symbol('STEPS_BIND_STEP_KEY');
3
- export var STEPS_COUNT_STEP_KEY = Symbol('STEPS_COUNT_STEP_KEY');
4
3
  export function useStep() {
5
4
  var {
6
5
  bindChildren,
6
+ length,
7
7
  childProviders
8
8
  } = useChildren(STEPS_BIND_STEP_KEY);
9
- var {
10
- length
11
- } = useAtChildrenCounter(STEPS_COUNT_STEP_KEY);
12
9
  return {
13
10
  length,
14
11
  step: childProviders,
@@ -1,14 +1,11 @@
1
- import { useAtChildrenCounter, useChildren } from '../utils/components.mjs';
1
+ import { useChildren } from '@varlet/use';
2
2
  export var SWIPE_BIND_SWIPE_ITEM_KEY = Symbol('SWIPE_BIND_SWIPE_ITEM_KEY');
3
- export var SWIPE_COUNT_SWIPE_ITEM_KEY = Symbol('SWIPE_COUNT_SWIPE_ITEM_KEY');
4
3
  export function useSwipeItems() {
5
4
  var {
6
5
  childProviders,
6
+ length,
7
7
  bindChildren
8
8
  } = useChildren(SWIPE_BIND_SWIPE_ITEM_KEY);
9
- var {
10
- length
11
- } = useAtChildrenCounter(SWIPE_COUNT_SWIPE_ITEM_KEY);
12
9
  return {
13
10
  length,
14
11
  swipeItems: childProviders,
@@ -1,15 +1,13 @@
1
- import { useAtParentIndex, useParent } from '../utils/components.mjs';
2
- import { SWIPE_BIND_SWIPE_ITEM_KEY, SWIPE_COUNT_SWIPE_ITEM_KEY } from '../swipe/provide.mjs';
1
+ import { useParent } from '@varlet/use';
2
+ import { SWIPE_BIND_SWIPE_ITEM_KEY } from '../swipe/provide.mjs';
3
3
  export function useSwipe() {
4
4
  var {
5
5
  bindParent,
6
+ index,
6
7
  parentProvider
7
8
  } = useParent(SWIPE_BIND_SWIPE_ITEM_KEY);
8
- var {
9
- index
10
- } = useAtParentIndex(SWIPE_COUNT_SWIPE_ITEM_KEY);
11
9
 
12
- if (!bindParent || !parentProvider || !index) {
10
+ if (!bindParent) {
13
11
  throw Error('<var-swipe-item/> must in <var-swipe/>');
14
12
  }
15
13
 
@@ -1,16 +1,12 @@
1
- var _excluded = ["collect", "clear"];
2
-
3
1
  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); } }
4
2
 
5
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); }); }; }
6
4
 
7
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
8
-
9
5
  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); }
10
6
 
11
7
  import { useEventListener } from '@varlet/use';
12
- import { createApp, h, getCurrentInstance, inject, onUnmounted, computed, provide, reactive, isVNode, onMounted, onBeforeUnmount, nextTick, ref, onActivated, onDeactivated, Comment, Fragment } from 'vue';
13
- import { isArray, removeItem } from '@varlet/shared';
8
+ import { createApp, h, getCurrentInstance, isVNode, ref, onActivated, onDeactivated, Comment, Fragment } from 'vue';
9
+ import { isArray } from '@varlet/shared';
14
10
  export function pickProps(props, propsKey) {
15
11
  return Array.isArray(propsKey) ? propsKey.reduce((pickedProps, key) => {
16
12
  pickedProps[key] = props[key];
@@ -93,110 +89,6 @@ export function flatVNodes(subTree) {
93
89
  flat(subTree);
94
90
  return vNodes;
95
91
  }
96
- export function useAtChildrenCounter(key) {
97
- var instances = reactive([]);
98
- var parentInstance = getCurrentInstance();
99
-
100
- var sortInstances = () => {
101
- var vNodes = flatVNodes(parentInstance.subTree);
102
- instances.sort((a, b) => {
103
- return vNodes.indexOf(a.vnode) - vNodes.indexOf(b.vnode);
104
- });
105
- };
106
-
107
- var collect = instance => {
108
- instances.push(instance);
109
- sortInstances();
110
- };
111
-
112
- var clear = instance => {
113
- removeItem(instances, instance);
114
- };
115
-
116
- provide(key, {
117
- collect,
118
- clear,
119
- instances
120
- });
121
- var length = computed(() => instances.length);
122
- return {
123
- length
124
- };
125
- }
126
- export function useAtParentIndex(key) {
127
- if (!keyInProvides(key)) {
128
- return {
129
- index: null
130
- };
131
- }
132
-
133
- var childrenCounter = inject(key);
134
- var {
135
- collect,
136
- clear,
137
- instances
138
- } = childrenCounter;
139
- var instance = getCurrentInstance();
140
- onMounted(() => {
141
- nextTick().then(() => collect(instance));
142
- });
143
- onUnmounted(() => {
144
- nextTick().then(() => clear(instance));
145
- });
146
- var index = computed(() => instances.indexOf(instance));
147
- return {
148
- index
149
- };
150
- }
151
- export function useChildren(key) {
152
- var childProviders = [];
153
-
154
- var collect = childProvider => {
155
- childProviders.push(childProvider);
156
- };
157
-
158
- var clear = childProvider => {
159
- removeItem(childProviders, childProvider);
160
- };
161
-
162
- var bindChildren = parentProvider => {
163
- provide(key, _extends({
164
- collect,
165
- clear
166
- }, parentProvider));
167
- };
168
-
169
- return {
170
- childProviders,
171
- bindChildren
172
- };
173
- }
174
- export function useParent(key) {
175
- if (!keyInProvides(key)) {
176
- return {
177
- parentProvider: null,
178
- bindParent: null
179
- };
180
- }
181
-
182
- var rawParentProvider = inject(key);
183
-
184
- var {
185
- collect,
186
- clear
187
- } = rawParentProvider,
188
- parentProvider = _objectWithoutPropertiesLoose(rawParentProvider, _excluded);
189
-
190
- var bindParent = childProvider => {
191
- onMounted(() => collect(childProvider));
192
- onBeforeUnmount(() => clear(childProvider));
193
- };
194
-
195
- return {
196
- parentProvider,
197
- bindParent
198
- };
199
- }
200
92
  export function keyInProvides(key) {
201
93
  var instance = getCurrentInstance();
202
94
  return key in instance.provides;