@ray-js/framework-shared 1.3.22 → 1.3.23

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ Copyright © 2014-2022 Tuya.inc
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,4 +1,4 @@
1
- declare type Func = (...args: any[]) => void;
1
+ type Func = (...args: any[]) => void;
2
2
  export declare class Emitter {
3
3
  private readonly listeners;
4
4
  constructor();
@@ -1,57 +1,33 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import "core-js/modules/es.array.splice.js";
4
- import "core-js/modules/es.array.index-of.js";
5
- import "core-js/modules/es.object.to-string.js";
6
- import "core-js/modules/web.dom-collections.for-each.js";
7
- export var Emitter = /*#__PURE__*/function () {
8
- function Emitter() {
9
- _classCallCheck(this, Emitter);
10
-
1
+ export class Emitter {
2
+ constructor() {
11
3
  this.listeners = {};
12
4
  }
13
-
14
- _createClass(Emitter, [{
15
- key: "on",
16
- value: function on(name, fn) {
17
- var _this = this;
18
-
19
- if (!this.listeners[name]) {
20
- this.listeners[name] = [];
21
- }
22
-
23
- this.listeners[name].push(fn);
24
- return function () {
25
- _this.off(name, fn);
26
- };
5
+ on(name, fn) {
6
+ if (!this.listeners[name]) {
7
+ this.listeners[name] = [];
27
8
  }
28
- }, {
29
- key: "off",
30
- value: function off(name, fn) {
31
- var fns = this.listeners[name];
32
-
33
- if (fns) {
34
- fns.splice(fns.indexOf(fn), 1);
35
- }
9
+ this.listeners[name].push(fn);
10
+ return () => {
11
+ this.off(name, fn);
12
+ };
13
+ }
14
+ off(name, fn) {
15
+ const fns = this.listeners[name];
16
+ if (fns) {
17
+ fns.splice(fns.indexOf(fn), 1);
18
+ }
19
+ }
20
+ emit(name) {
21
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
22
+ args[_key - 1] = arguments[_key];
36
23
  }
37
- }, {
38
- key: "emit",
39
- value: function emit(name) {
40
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
41
- args[_key - 1] = arguments[_key];
42
- }
43
-
44
- var fns = this.listeners[name];
45
-
46
- if (fns) {
47
- var result;
48
- fns.forEach(function (fn) {
49
- result = fn.apply(void 0, args);
50
- });
51
- return result;
52
- }
24
+ const fns = this.listeners[name];
25
+ if (fns) {
26
+ let result;
27
+ fns.forEach(fn => {
28
+ result = fn(...args);
29
+ });
30
+ return result;
53
31
  }
54
- }]);
55
-
56
- return Emitter;
57
- }();
32
+ }
33
+ }
@@ -1,29 +1,16 @@
1
- import "core-js/modules/es.regexp.exec.js";
2
- import "core-js/modules/es.string.match.js";
3
- import "core-js/modules/es.string.replace.js";
4
- import "core-js/modules/es.array.reduce.js";
5
- import "core-js/modules/es.object.to-string.js";
6
- import "core-js/modules/es.object.keys.js";
7
- export var isPlatformSpecifyProp = function (prop) {
8
- return prop.match(/^(ali|wechat|toutiao)-/);
9
- };
10
-
11
- var normalizeWebSpecifyProp = function (prop) {
12
- return prop.replace(/^web-/, '');
13
- };
14
-
1
+ export const isPlatformSpecifyProp = prop => prop.match(/^(ali|wechat|toutiao)-/);
2
+ const normalizeWebSpecifyProp = prop => prop.replace(/^web-/, '');
15
3
  export function filterProps(props) {
16
- return Object.keys(props).reduce(function (acc, cur) {
17
- var prop = cur; // web 平台没有 cli 帮助处理属性名称,直接去掉平台前缀
4
+ return Object.keys(props).reduce((acc, cur) => {
5
+ let prop = cur;
18
6
 
7
+ // web 平台没有 cli 帮助处理属性名称,直接去掉平台前缀
19
8
  if (process.env.PLATFORM === 'web') {
20
9
  prop = normalizeWebSpecifyProp(cur);
21
10
  }
22
-
23
11
  if (isPlatformSpecifyProp(prop)) {
24
12
  return acc;
25
13
  }
26
-
27
14
  acc[prop] = props[cur];
28
15
  return acc;
29
16
  }, {});
@@ -1,10 +1,9 @@
1
- import "core-js/modules/es.object.to-string.js";
2
1
  // https://github.com/facebook/react/blob/master/packages/react-dom/src/shared/CSSProperty.js
3
2
 
4
3
  /**
5
4
  * CSS properties which accept numbers but are not in units of "px".
6
5
  */
7
- export var isUnitlessNumber = {
6
+ export const isUnitlessNumber = {
8
7
  animationIterationCount: true,
9
8
  borderImageOutset: true,
10
9
  borderImageSlice: true,
@@ -49,30 +48,24 @@ export var isUnitlessNumber = {
49
48
  strokeOpacity: true,
50
49
  strokeWidth: true
51
50
  };
51
+
52
52
  /**
53
53
  * @param {string} prefix vendor-specific prefix, eg: Webkit
54
54
  * @param {string} key style name, eg: transitionDuration
55
55
  * @return {string} style name prefixed with `prefix`, properly camelCased, eg:
56
56
  * WebkitTransitionDuration
57
57
  */
58
-
59
58
  function prefixKey(prefix, key) {
60
59
  return prefix + key.charAt(0).toUpperCase() + key.substring(1);
61
60
  }
61
+
62
62
  /**
63
63
  * Support style names that may come passed in prefixed by adding permutations
64
64
  * of vendor prefixes.
65
65
  */
66
-
67
-
68
- var prefixes = ['Webkit', 'ms', 'Moz', 'O'];
69
-
70
- var _loop = function (prop) {
66
+ const prefixes = ['Webkit', 'ms', 'Moz', 'O'];
67
+ for (const prop in isUnitlessNumber) {
71
68
  prefixes.forEach(function (prefix) {
72
69
  isUnitlessNumber[prefixKey(prefix, prop)] = isUnitlessNumber[prop];
73
70
  });
74
- };
75
-
76
- for (var prop in isUnitlessNumber) {
77
- _loop(prop);
78
71
  }
@@ -1,48 +1,36 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import "core-js/modules/es.array.filter.js";
3
- import "core-js/modules/es.object.to-string.js";
4
- import "core-js/modules/es.object.assign.js";
5
- import "core-js/modules/es.array.concat.js";
6
- import "core-js/modules/web.dom-collections.for-each.js";
7
- import "core-js/modules/es.object.keys.js";
8
- import "core-js/modules/es.number.constructor.js";
9
- import "core-js/modules/es.regexp.exec.js";
10
- import "core-js/modules/es.regexp.test.js";
11
- import "core-js/modules/es.string.replace.js";
12
1
  import { isWeb } from '@ray-js/env';
13
2
  import { isUnitlessNumber } from './CSSProperty';
3
+
14
4
  /**
15
5
  * 根据平台转换内敛样式单位, 自适应单位
16
6
  * 需要关闭 ray 的内敛样式转换规则
17
7
  * @param int 内敛样式
18
8
  */
19
-
20
9
  export function inlineStyle() {
21
10
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
22
11
  args[_key] = arguments[_key];
23
12
  }
24
-
25
- var allStyle = args.filter(Boolean);
13
+ const allStyle = args.filter(Boolean);
26
14
  if (allStyle.length == 0) return undefined;
27
- var style = Object.assign.apply(Object, [{}].concat(_toConsumableArray(allStyle)));
28
- Object.keys(style).forEach(function (key) {
29
- var value = style[key];
30
-
15
+ const style = Object.assign({}, ...allStyle);
16
+ Object.keys(style).forEach(key => {
17
+ const value = style[key];
31
18
  if (typeof value === 'undefined') {
32
19
  delete style[key];
33
- } // 整数类型替换为
20
+ }
21
+ // 整数类型替换为
34
22
  else if (!(key in isUnitlessNumber)) {
35
23
  if (!Number.isNaN(Number(value))) {
36
24
  if (isWeb) {
37
- style[key] = "".concat(value / 100, "rem");
25
+ style[key] = `${value / 100}rem`;
38
26
  } else {
39
- style[key] = "".concat(value, "rpx");
27
+ style[key] = `${value}rpx`;
40
28
  }
41
29
  } else if (/\b([.\d]+)rpx\b/.test(value) && isWeb) {
42
30
  // TODO: 支持 native 的样式抹平
43
- style[key] = value.replace(/\b([.\d]+)rpx\b/g, function (match, x) {
44
- var size = Number(x);
45
- return "".concat(size / 100, "rem");
31
+ style[key] = value.replace(/\b([.\d]+)rpx\b/g, (match, x) => {
32
+ const size = Number(x);
33
+ return `${size / 100}rem`;
46
34
  });
47
35
  }
48
36
  }
@@ -1,99 +1,59 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
- import "core-js/modules/es.array.map.js";
4
- import "core-js/modules/es.array.filter.js";
5
- import "core-js/modules/es.object.to-string.js";
6
- import "core-js/modules/es.array.find.js";
7
- import "core-js/modules/es.array.concat.js";
8
- import "core-js/modules/es.json.stringify.js";
9
2
  import { match, parse } from 'path-to-regexp';
10
3
  export function normalizeTabBar(tabBar, routes) {
11
- var list = tabBar.list;
12
-
4
+ let list = tabBar.list;
13
5
  if (Array.isArray(list)) {
14
- list = list.map(function (tab) {
6
+ list = list.map(tab => {
15
7
  if (tab.id === undefined) {
16
8
  return tab;
17
9
  }
18
-
19
- var _iterator = _createForOfIteratorHelper(routes),
20
- _step;
21
-
22
- try {
23
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
24
- var r = _step.value;
25
-
26
- // 兼容老项目,将老数据格式到新数据
27
- if (tab.id === r.id) {
28
- return _objectSpread(_objectSpread({}, tab), {}, {
29
- pagePath: r.path
30
- });
31
- }
10
+ for (const r of routes) {
11
+ // 兼容老项目,将老数据格式到新数据
12
+ if (tab.id === r.id) {
13
+ return _objectSpread(_objectSpread({}, tab), {}, {
14
+ pagePath: r.path
15
+ });
32
16
  }
33
- } catch (err) {
34
- _iterator.e(err);
35
- } finally {
36
- _iterator.f();
37
17
  }
38
-
39
18
  return tab;
40
- }); // tabBar.list[number].pagePath 必须在 routes[number].page 中,即tab.pagePath === routes[number].page
19
+ });
20
+ // tabBar.list[number].pagePath 必须在 routes[number].page 中,即tab.pagePath === routes[number].page
41
21
  // tabBar.list[number].route 可不配置
42
22
  // tabBar.list[number].route 若未配置,则设置 tabBar.list[number].route = routes[number].page(非模式匹配)或tabBar.list[number].pagePath
43
23
  // tabBar.list[number].route 不能用模式,如不能用/xxx/:id等,必须是明确的 如/xxx/123
44
24
  // tabBar.list[number].route 必须要能命中对应routes[number].route 路由规则,规则详见 path-to-regexp 模块
45
-
46
- tabBar.list = list.map(function (tab, index) {
25
+ tabBar.list = list.map((tab, index) => {
47
26
  var _m$route;
48
-
49
27
  tab = _objectSpread({}, tab);
50
- var m = routes.find(function (i) {
51
- return tab.pagePath === i.path;
52
- });
53
-
28
+ const m = routes.find(i => tab.pagePath === i.path);
54
29
  if (!m) {
55
- throw new Error("tabBar.list[".concat(index, "].pagePath: ").concat(tab.pagePath, " \u9700\u8981\u5728\u8DEF\u7531\u914D\u7F6E\u4E2D: ").concat(JSON.stringify(routes, null, 2)));
30
+ throw new Error(`tabBar.list[${index}].pagePath: ${tab.pagePath} 需要在路由配置中: ${JSON.stringify(routes, null, 2)}`);
56
31
  }
57
-
58
32
  if (!tab.route) {
59
33
  // 判断 routes[number].route 是否为模式匹配规则
60
34
  tab.route = m.route && parse(m.route).length === 1 ? m.route : m.path;
61
- } // 判断是否能被路由命中
62
-
63
-
64
- var matched = match((_m$route = m.route) !== null && _m$route !== void 0 ? _m$route : m.path)(tab.route);
65
-
35
+ }
36
+ // 判断是否能被路由命中
37
+ const matched = match((_m$route = m.route) !== null && _m$route !== void 0 ? _m$route : m.path)(tab.route);
66
38
  if (!matched) {
67
- console.warn("tabBar.list[".concat(index, "]\n.route: ").concat(tab.route, "\n.pagePath: ").concat(tab.pagePath, "\n\u5E94\u88AB\u8DEF\u7531\u547D\u4E2D: \n").concat(JSON.stringify(m, null, 2)));
39
+ console.warn(`tabBar.list[${index}]\n.route: ${tab.route}\n.pagePath: ${tab.pagePath}\n应被路由命中: \n${JSON.stringify(m, null, 2)}`);
68
40
  return;
69
- } // 判断是否还被其他路由命中
70
-
71
-
72
- var otherMatched = routes.filter(function (r) {
73
- return tab.pagePath !== r.path;
74
- }).filter(function (r) {
41
+ }
42
+ // 判断是否还被其他路由命中
43
+ const otherMatched = routes.filter(r => tab.pagePath !== r.path).filter(r => {
75
44
  var _r$route;
76
-
77
45
  return match((_r$route = r.route) !== null && _r$route !== void 0 ? _r$route : r.path)(tab.route);
78
46
  });
79
- var unusable = otherMatched.filter(function (r) {
80
- return r.path !== tab.pagePath;
81
- });
82
-
47
+ const unusable = otherMatched.filter(r => r.path !== tab.pagePath);
83
48
  if (unusable.length) {
84
- console.warn("tabBar.list[".concat(index, "]\n.route: ").concat(tab.route, "\n%c.pagePath: ").concat(tab.pagePath, "\n%c\u88AB\u5176\u5B83\u8DEF\u7531\u547D\u4E2D\uFF1A\n").concat(JSON.stringify(unusable, null, 2)), 'background:#290000;color:green', 'background:#290000;color:green', 'color:red');
49
+ console.warn(`tabBar.list[${index}]\n.route: ${tab.route}\n%c.pagePath: ${tab.pagePath}\n%c被其它路由命中:\n${JSON.stringify(unusable, null, 2)}`, 'background:#290000;color:green', 'background:#290000;color:green', 'color:red');
85
50
  return;
86
51
  }
87
-
88
52
  return tab;
89
- }).filter(function (tab) {
90
- return !!tab;
91
- });
92
-
53
+ }).filter(tab => !!tab);
93
54
  if (!tabBar.list.length) {
94
55
  return {};
95
56
  }
96
57
  }
97
-
98
58
  return tabBar;
99
59
  }
@@ -1,50 +1,30 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import "core-js/modules/es.string.starts-with.js";
3
- import "core-js/modules/es.regexp.exec.js";
4
- import "core-js/modules/es.string.replace.js";
5
- import "core-js/modules/es.array.filter.js";
6
- import "core-js/modules/es.object.to-string.js";
7
- import "core-js/modules/es.array.find.js";
8
- import "core-js/modules/es.array.reduce.js";
9
- import "core-js/modules/es.object.keys.js";
10
- import "core-js/modules/es.array.concat.js";
11
- var vendorPrefixes = ['webkit', 'moz', 'ms', 'o'];
12
-
13
- var transformReactStyleKey = function (key) {
1
+ const vendorPrefixes = ['webkit', 'moz', 'ms', 'o'];
2
+ const transformReactStyleKey = key => {
14
3
  var _styleValue;
15
-
16
4
  // css3 var
17
5
  if (key !== null && key !== void 0 && key.startsWith('--')) {
18
6
  return key;
19
7
  }
8
+ let styleValue = key.replace(/\.?([A-Z]+)/g, function (_x, y) {
9
+ return `-${y.toLowerCase()}`;
10
+ });
20
11
 
21
- var styleValue = key.replace(/\.?([A-Z]+)/g, function (_x, y) {
22
- return "-".concat(y.toLowerCase());
23
- }); // vendor prefix
24
-
12
+ // vendor prefix
25
13
  if ((_styleValue = styleValue) !== null && _styleValue !== void 0 && _styleValue.startsWith('-')) {
26
- var firstWord = styleValue.split('-').filter(function (s) {
27
- return s;
28
- })[0];
14
+ const firstWord = styleValue.split('-').filter(s => s)[0];
29
15
  styleValue = styleValue.replace(/^-/, '');
30
-
31
- if (vendorPrefixes.find(function (prefix) {
32
- return prefix === firstWord;
33
- })) {
34
- styleValue = "-".concat(styleValue);
16
+ if (vendorPrefixes.find(prefix => prefix === firstWord)) {
17
+ styleValue = `-${styleValue}`;
35
18
  }
36
19
  }
37
-
38
20
  return styleValue;
39
21
  };
40
-
41
- export var plainStyle = function (style) {
22
+ export const plainStyle = style => {
42
23
  if (!style) {
43
24
  return '';
44
25
  }
45
-
46
- return Object.keys(style).reduce(function (acc, key) {
47
- var value = style[key];
48
- return [].concat(_toConsumableArray(acc), ["".concat(transformReactStyleKey(key), ":").concat(value, ";")]);
26
+ return Object.keys(style).reduce((acc, key) => {
27
+ const value = style[key];
28
+ return [...acc, `${transformReactStyleKey(key)}:${value};`];
49
29
  }, []).join('\n');
50
30
  };
@@ -1,21 +1,22 @@
1
1
  import { useEffect, useRef } from 'react';
2
+
2
3
  /**
3
4
  * Hooks版本setInterval
4
5
  */
5
-
6
6
  export function useInterval(callback) {
7
- var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
8
- var intervalFn = useRef({});
9
- useEffect(function () {
7
+ let delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
8
+ const intervalFn = useRef({});
9
+ useEffect(() => {
10
10
  intervalFn.current.callback = callback;
11
- }, [callback]); // set the interval
11
+ }, [callback]);
12
12
 
13
- useEffect(function () {
13
+ // set the interval
14
+ useEffect(() => {
14
15
  if (delay !== null) {
15
- intervalFn.current.timer = setInterval(function () {
16
+ intervalFn.current.timer = setInterval(() => {
16
17
  intervalFn.current.callback();
17
18
  }, delay);
18
- return function () {
19
+ return () => {
19
20
  clearInterval(intervalFn.current.timer);
20
21
  };
21
22
  }
@@ -1,22 +1,18 @@
1
- import "core-js/modules/es.array.concat.js";
2
1
  import React from 'react';
3
2
  import { plainStyle } from '../plainStyle';
4
- var clsxId = 0;
5
-
6
- var generateClassName = function () {
7
- return "placeholder-style-".concat(clsxId++);
8
- };
9
-
3
+ let clsxId = 0;
4
+ const generateClassName = () => `placeholder-style-${clsxId++}`;
10
5
  export function useStylesheet(css) {
11
- var className = React.useRef(generateClassName());
12
- React.useEffect(function () {
13
- var styleContent = ".".concat(className.current, "::placeholder {\n").concat(plainStyle(css), "}");
14
- var style = window.document.createElement('style');
6
+ const className = React.useRef(generateClassName());
7
+ React.useEffect(() => {
8
+ const styleContent = `.${className.current}::placeholder {
9
+ ${plainStyle(css)}}`;
10
+ const style = window.document.createElement('style');
15
11
  style.type = 'text/css';
16
12
  style.appendChild(document.createTextNode(styleContent));
17
- var head = window.document.head || window.document.getElementsByTagName('head')[0];
13
+ const head = window.document.head || window.document.getElementsByTagName('head')[0];
18
14
  head.appendChild(style);
19
- return function () {
15
+ return () => {
20
16
  head.removeChild(style);
21
17
  };
22
18
  }, [css]);
@@ -1,29 +1,21 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
1
  import { useRef, useState } from 'react';
2
+
3
3
  /**
4
4
  * 节流的 useState
5
5
  */
6
-
7
6
  export function useThrottle(value) {
8
- var ms = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
9
-
10
- var _useState = useState(value),
11
- _useState2 = _slicedToArray(_useState, 2),
12
- state = _useState2[0],
13
- setState = _useState2[1];
14
-
15
- var now = useRef(0);
16
- var last = useRef(0);
17
- var timer = useRef();
18
- return [state, function setValue(value) {
7
+ let ms = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
8
+ const [state, setState] = useState(value);
9
+ const now = useRef(0);
10
+ const last = useRef(0);
11
+ const timer = useRef();
12
+ return [state, value => {
19
13
  now.current = Date.now();
20
-
21
14
  if (last && now.current < last.current + ms) {
22
15
  if (timer.current) {
23
16
  clearTimeout(timer.current);
24
- } // 保证在当前时间区间结束后,再执行一次 fn
25
-
26
-
17
+ }
18
+ // 保证在当前时间区间结束后,再执行一次 fn
27
19
  timer.current = setTimeout(function () {
28
20
  last.current = now.current;
29
21
  setState(value);
@@ -1,42 +1,33 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
- var _excluded = ["hoverDuration", "hoverDelay"];
5
- import "core-js/modules/es.array.filter.js";
6
- import "core-js/modules/es.object.to-string.js";
7
- import "core-js/modules/es.array.map.js";
8
- import "core-js/modules/web.dom-collections.for-each.js";
9
- import "core-js/modules/es.array.reduce.js";
10
- import "core-js/modules/es.object.keys.js";
3
+ const _excluded = ["hoverDuration", "hoverDelay"];
11
4
  import * as React from 'react';
12
5
  import { isWeb } from '@ray-js/env';
13
- var LONG_TAP_DURATION = 350;
14
- export function useTouch(_ref) {
15
- var hoverDuration = _ref.hoverDuration,
16
- hoverDelay = _ref.hoverDelay,
17
- handles = _objectWithoutProperties(_ref, _excluded);
18
-
19
- var _React$useState = React.useState(false),
20
- _React$useState2 = _slicedToArray(_React$useState, 2),
21
- touching = _React$useState2[0],
22
- setTouching = _React$useState2[1];
6
+ const LONG_TAP_DURATION = 350;
23
7
 
24
- var hoveringRef = React.useRef(false);
25
- var timers = React.useRef([]);
8
+ /**
9
+ * 多端通用事件
10
+ */
26
11
 
12
+ export function useTouch(_ref) {
13
+ let {
14
+ hoverDuration,
15
+ hoverDelay
16
+ } = _ref,
17
+ handles = _objectWithoutProperties(_ref, _excluded);
18
+ const [touching, setTouching] = React.useState(false);
19
+ const hoveringRef = React.useRef(false);
20
+ const timers = React.useRef([]);
27
21
  function executeTimeout(callback, time) {
28
- var timer = setTimeout(function () {
22
+ const timer = setTimeout(() => {
29
23
  callback();
30
- timers.current.filter(function (t) {
31
- return t !== timer;
32
- });
24
+ timers.current.filter(t => t !== timer);
33
25
  }, time);
34
26
  timers.current.push(timer);
35
27
  }
36
-
37
28
  function formatTouches(touchs) {
38
29
  if (Array.isArray(touchs)) {
39
- return touchs && touchs.map(function (item) {
30
+ return touchs && touchs.map(item => {
40
31
  return {
41
32
  identifier: item.identifier,
42
33
  pageX: item.pageX,
@@ -47,7 +38,6 @@ export function useTouch(_ref) {
47
38
  return [_objectSpread({}, touchs)];
48
39
  }
49
40
  }
50
-
51
41
  function formatRayEvent(e, touchType) {
52
42
  return {
53
43
  type: (e === null || e === void 0 ? void 0 : e.type) || touchType || '',
@@ -57,7 +47,6 @@ export function useTouch(_ref) {
57
47
  origin: e
58
48
  };
59
49
  }
60
-
61
50
  function formatRayClickEvent(e, clickType) {
62
51
  return {
63
52
  type: (e === null || e === void 0 ? void 0 : e.type) || clickType || '',
@@ -67,49 +56,37 @@ export function useTouch(_ref) {
67
56
  origin: e
68
57
  };
69
58
  }
70
-
71
- React.useEffect(function () {
72
- return function () {
73
- timers.current.forEach(function (t) {
74
- return clearTimeout(t);
75
- });
76
- };
59
+ React.useEffect(() => () => {
60
+ timers.current.forEach(t => clearTimeout(t));
77
61
  }, []);
78
-
79
62
  function onLongClick(e) {
80
63
  var _handles$onLongClick;
81
-
82
64
  return (_handles$onLongClick = handles.onLongClick) === null || _handles$onLongClick === void 0 ? void 0 : _handles$onLongClick.call(handles, formatRayClickEvent(e, 'longclick'));
83
65
  }
84
-
85
- var processedHandles = {
66
+ const processedHandles = {
86
67
  onTouchStart: function (e) {
87
68
  var _handles$onTouchStart;
88
-
89
69
  hoveringRef.current = true;
90
- executeTimeout(function () {
70
+ executeTimeout(() => {
91
71
  if (hoveringRef.current) {
92
72
  setTouching(true);
93
73
  }
94
74
  }, hoverDelay);
95
-
96
75
  if (isWeb) {
97
76
  if (typeof handles.onLongClick === 'function') {
98
- executeTimeout(function () {
77
+ executeTimeout(() => {
99
78
  if (hoveringRef.current) {
100
79
  onLongClick(e);
101
80
  }
102
81
  }, LONG_TAP_DURATION);
103
82
  }
104
83
  }
105
-
106
84
  return (_handles$onTouchStart = handles.onTouchStart) === null || _handles$onTouchStart === void 0 ? void 0 : _handles$onTouchStart.call(handles, formatRayEvent(e, 'touchstart'));
107
85
  },
108
86
  onTouchMove: function (e) {
109
87
  var _handles$onTouchMove;
110
-
111
88
  hoveringRef.current = false;
112
- executeTimeout(function () {
89
+ executeTimeout(() => {
113
90
  if (touching) {
114
91
  setTouching(false);
115
92
  }
@@ -118,9 +95,8 @@ export function useTouch(_ref) {
118
95
  },
119
96
  onTouchEnd: function (e) {
120
97
  var _handles$onTouchEnd;
121
-
122
98
  hoveringRef.current = false;
123
- executeTimeout(function () {
99
+ executeTimeout(() => {
124
100
  if (touching) {
125
101
  setTouching(false);
126
102
  }
@@ -129,9 +105,8 @@ export function useTouch(_ref) {
129
105
  },
130
106
  onTouchCancel: function (e) {
131
107
  var _handles$onTouchCance;
132
-
133
108
  hoveringRef.current = false;
134
- executeTimeout(function () {
109
+ executeTimeout(() => {
135
110
  if (touching) {
136
111
  setTouching(false);
137
112
  }
@@ -140,16 +115,14 @@ export function useTouch(_ref) {
140
115
  },
141
116
  onClick: function (e) {
142
117
  var _handles$onClick;
143
-
144
118
  return (_handles$onClick = handles.onClick) === null || _handles$onClick === void 0 ? void 0 : _handles$onClick.call(handles, formatRayClickEvent(e, 'click'));
145
119
  },
146
- onLongClick: onLongClick
120
+ onLongClick
147
121
  };
148
- var finalRes = Object.keys(processedHandles).reduce(function (o, k) {
122
+ const finalRes = Object.keys(processedHandles).reduce((o, k) => {
149
123
  if (handles[k]) {
150
124
  o[k] = processedHandles[k];
151
125
  }
152
-
153
126
  return o;
154
127
  }, {});
155
128
  return [touching, finalRes];
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
- declare type TransitionClassName = string | string[] | {
2
+ type TransitionClassName = string | string[] | {
3
3
  [key: string]: string | string[];
4
4
  };
5
- declare type TransitionStatus = 'showStart' | 'showComplete' | 'hideStart' | 'hideComplete';
5
+ type TransitionStatus = 'showStart' | 'showComplete' | 'hideStart' | 'hideComplete';
6
6
  interface TransitionOptions<P> {
7
7
  duration?: number;
8
8
  onStart?: (show: boolean) => void;
@@ -1,53 +1,37 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import "core-js/modules/es.object.to-string.js";
3
- import "core-js/modules/es.promise.js";
4
1
  import { useEffect, useRef, useState } from 'react';
5
-
6
- var nextFrame = function () {
7
- var duration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000 / 30;
8
- return new Promise(function (resolve) {
9
- return setTimeout(resolve, duration);
10
- });
2
+ const nextFrame = function () {
3
+ let duration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000 / 30;
4
+ return new Promise(resolve => setTimeout(resolve, duration));
11
5
  };
6
+
12
7
  /**
13
8
  * 用于执行动画的时序管理
14
9
  * @param options transition 选项
15
10
  * @param visible 是否可见
16
11
  */
17
-
18
-
19
12
  export function useTransition(options, deps) {
20
- var _options$duration = options.duration,
21
- duration = _options$duration === void 0 ? 200 : _options$duration,
22
- onFinish = options.onFinish,
23
- onStart = options.onStart;
24
-
25
- var _deps = _slicedToArray(deps, 1),
26
- _deps$ = _deps[0],
27
- visible = _deps$ === void 0 ? false : _deps$;
28
-
29
- var showRef = useRef(visible);
30
-
31
- var _useState = useState(visible ? 'showComplete' : 'hideComplete'),
32
- _useState2 = _slicedToArray(_useState, 2),
33
- status = _useState2[0],
34
- setStatus = _useState2[1];
35
-
13
+ const {
14
+ duration = 200,
15
+ onFinish,
16
+ onStart
17
+ } = options;
18
+ const [visible = false] = deps;
19
+ const showRef = useRef(visible);
20
+ const [status, setStatus] = useState(visible ? 'showComplete' : 'hideComplete');
36
21
  function updateShow(show) {
37
22
  if (showRef.current === show) return false;
38
23
  showRef.current = show;
39
24
  onStart === null || onStart === void 0 ? void 0 : onStart(showRef.current);
40
25
  setStatus(showRef.current ? 'showStart' : 'hideStart');
41
- nextFrame(duration).then(function () {
26
+ nextFrame(duration).then(() => {
42
27
  setStatus(showRef.current ? 'showComplete' : 'hideComplete');
43
28
  onFinish === null || onFinish === void 0 ? void 0 : onFinish(showRef.current);
44
29
  });
45
30
  }
46
-
47
- useEffect(function () {
31
+ useEffect(() => {
48
32
  updateShow(visible);
49
33
  }, [visible]);
50
34
  return [status, {
51
- animationDuration: "".concat(duration / 1000, "s")
35
+ animationDuration: `${duration / 1000}s`
52
36
  }, updateShow];
53
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/framework-shared",
3
- "version": "1.3.22",
3
+ "version": "1.3.23",
4
4
  "description": "Ray shared for framework",
5
5
  "keywords": [
6
6
  "ray"
@@ -20,13 +20,13 @@
20
20
  "watch": "ray start --type=component --emit-declaration-dev"
21
21
  },
22
22
  "dependencies": {
23
- "@ray-core/wechat": "^0.3.5",
24
- "@ray-js/env": "1.3.22",
25
- "@ray-js/types": "1.3.22",
23
+ "@ray-core/wechat": "^0.3.9",
24
+ "@ray-js/env": "1.3.23",
25
+ "@ray-js/types": "1.3.23",
26
26
  "path-to-regexp": "^6.2.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@ray-js/cli": "1.3.22"
29
+ "@ray-js/cli": "1.3.23"
30
30
  },
31
31
  "maintainers": [
32
32
  {
@@ -34,6 +34,6 @@
34
34
  "email": "tuyafe@tuya.com"
35
35
  }
36
36
  ],
37
- "gitHead": "14cb935df10f020e714b44bb41d4899646db751c",
37
+ "gitHead": "04708bb394d817a7a522fcde178f19f170d5d364",
38
38
  "repository": {}
39
39
  }