@bifrostui/utils 2.0.0-alpha.4 → 2.0.0-alpha.41
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/dist/context-selector/createContext.d.ts +26 -0
- package/dist/context-selector/createContext.js +83 -0
- package/dist/context-selector/index.d.ts +4 -0
- package/dist/context-selector/index.js +33 -0
- package/dist/context-selector/types.d.ts +24 -0
- package/dist/context-selector/types.js +15 -0
- package/dist/context-selector/useContextSelector.d.ts +29 -0
- package/dist/context-selector/useContextSelector.js +92 -0
- package/dist/context-selector/useHasParentContext.d.ts +26 -0
- package/dist/context-selector/useHasParentContext.js +46 -0
- package/dist/directionLocationUtil.d.ts +1 -0
- package/dist/getBoundingClientRect/index.js +1 -11
- package/dist/hooks/useDomReady/index.js +2 -2
- package/dist/hooks/useEventCallback.d.ts +12 -3
- package/dist/hooks/useEventCallback.js +14 -5
- package/dist/hooks/useIsomorphicLayoutEffect.d.ts +11 -0
- package/dist/hooks/useIsomorphicLayoutEffect.js +39 -0
- package/dist/hooks/useMemoizedFn.js +2 -2
- package/dist/hooks/useSize.js +2 -2
- package/dist/hooks/useTouch.d.ts +10 -10
- package/dist/hooks/useTouchEmulator.js +3 -3
- package/dist/hooks/useUniqueId.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/isMini.js +1 -1
- package/dist/render.d.ts +3 -3
- package/dist/render.js +15 -4
- package/dist/setRef.d.ts +1 -1
- package/dist/ssr/canUseDOM.d.ts +4 -0
- package/dist/ssr/canUseDOM.js +29 -0
- package/dist/ssr/index.d.ts +1 -0
- package/dist/ssr/index.js +27 -0
- package/dist/themeCreator/createTheme.js +1 -1
- package/dist/themeCreator/cssVarToValue.d.ts +16 -0
- package/dist/themeCreator/cssVarToValue.js +32 -4
- package/dist/toArray.d.ts +1 -1
- package/dist/toArray.js +6 -4
- package/dist/transitions.d.ts +1 -1
- package/dist/transitions.js +1 -1
- package/es/context-selector/createContext.d.ts +26 -0
- package/es/context-selector/createContext.js +53 -0
- package/es/context-selector/index.d.ts +4 -0
- package/es/context-selector/index.js +8 -0
- package/es/context-selector/types.d.ts +24 -0
- package/es/context-selector/types.js +0 -0
- package/es/context-selector/useContextSelector.d.ts +29 -0
- package/es/context-selector/useContextSelector.js +59 -0
- package/es/context-selector/useHasParentContext.d.ts +26 -0
- package/es/context-selector/useHasParentContext.js +13 -0
- package/es/directionLocationUtil.d.ts +1 -0
- package/es/getBoundingClientRect/index.js +1 -11
- package/es/hooks/useDomReady/index.js +1 -1
- package/es/hooks/useEventCallback.d.ts +12 -3
- package/es/hooks/useEventCallback.js +14 -5
- package/es/hooks/useIsomorphicLayoutEffect.d.ts +11 -0
- package/es/hooks/useIsomorphicLayoutEffect.js +6 -0
- package/es/hooks/useMemoizedFn.js +2 -2
- package/es/hooks/useSize.js +1 -1
- package/es/hooks/useTouch.d.ts +10 -10
- package/es/hooks/useTouchEmulator.js +3 -3
- package/es/hooks/useUniqueId.js +1 -1
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/isMini.js +1 -1
- package/es/render.d.ts +3 -3
- package/es/render.js +15 -4
- package/es/setRef.d.ts +1 -1
- package/es/ssr/canUseDOM.d.ts +4 -0
- package/es/ssr/canUseDOM.js +6 -0
- package/es/ssr/index.d.ts +1 -0
- package/es/ssr/index.js +4 -0
- package/es/themeCreator/createTheme.js +1 -1
- package/es/themeCreator/cssVarToValue.d.ts +16 -0
- package/es/themeCreator/cssVarToValue.js +31 -3
- package/es/toArray.d.ts +1 -1
- package/es/toArray.js +5 -3
- package/es/transitions.d.ts +1 -1
- package/es/transitions.js +1 -1
- package/package.json +15 -9
package/es/hooks/useTouch.d.ts
CHANGED
|
@@ -5,17 +5,17 @@ declare const useTouch: () => {
|
|
|
5
5
|
move: (event: React.TouchEvent<HTMLElement>) => void;
|
|
6
6
|
start: (event: React.TouchEvent<HTMLElement>) => void;
|
|
7
7
|
reset: () => void;
|
|
8
|
-
touchTime: React.
|
|
9
|
-
startX: React.
|
|
10
|
-
startY: React.
|
|
11
|
-
deltaX: React.
|
|
12
|
-
deltaY: React.
|
|
13
|
-
delta: React.
|
|
14
|
-
offsetX: React.
|
|
15
|
-
offsetY: React.
|
|
16
|
-
direction: React.
|
|
8
|
+
touchTime: React.RefObject<number>;
|
|
9
|
+
startX: React.RefObject<number>;
|
|
10
|
+
startY: React.RefObject<number>;
|
|
11
|
+
deltaX: React.RefObject<number>;
|
|
12
|
+
deltaY: React.RefObject<number>;
|
|
13
|
+
delta: React.RefObject<number>;
|
|
14
|
+
offsetX: React.RefObject<number>;
|
|
15
|
+
offsetY: React.RefObject<number>;
|
|
16
|
+
direction: React.RefObject<Direction>;
|
|
17
17
|
isVertical: () => boolean;
|
|
18
18
|
isHorizontal: () => boolean;
|
|
19
|
-
last: React.
|
|
19
|
+
last: React.RefObject<boolean>;
|
|
20
20
|
};
|
|
21
21
|
export default useTouch;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
2
|
let eventTarget;
|
|
3
|
-
const Touch = function Touch2(target, identifier, pos,
|
|
4
|
-
deltaX =
|
|
5
|
-
deltaY =
|
|
3
|
+
const Touch = function Touch2(target, identifier, pos, dx = 0, dy = 0) {
|
|
4
|
+
const deltaX = dx || 0;
|
|
5
|
+
const deltaY = dy || 0;
|
|
6
6
|
this.identifier = identifier;
|
|
7
7
|
this.target = target;
|
|
8
8
|
this.clientX = pos.clientX + deltaX;
|
package/es/hooks/useUniqueId.js
CHANGED
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
package/es/isMini.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const isMini = typeof process.env.TARO_ENV === "string";
|
|
1
|
+
const isMini = typeof process.env.TARO_ENV === "string" && ["weapp", "swan", "alipay", "tt", "qq", "jd"].includes(process.env.TARO_ENV);
|
|
2
2
|
const isWeapp = process.env.TARO_ENV === "weapp";
|
|
3
3
|
const isAlipay = process.env.TARO_ENV === "alipay";
|
|
4
4
|
const isTt = process.env.TARO_ENV === "tt";
|
package/es/render.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactElement } from 'react';
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
2
|
import type { Root } from 'react-dom/client';
|
|
3
3
|
declare const MARK = "__bifrostui_react_root__";
|
|
4
4
|
type ContainerType = (Element | DocumentFragment) & {
|
|
@@ -8,6 +8,6 @@ type ContainerType = (Element | DocumentFragment) & {
|
|
|
8
8
|
export declare function testModernRender(node: ReactElement, container: ContainerType, isTest: boolean): void;
|
|
9
9
|
export declare function render(node: ReactElement, container: ContainerType): void;
|
|
10
10
|
/** @private Test usage. Not work in prod */
|
|
11
|
-
export declare function testLegacyUnmount(container: ContainerType, isTest: boolean):
|
|
12
|
-
export declare function unmount(container: ContainerType):
|
|
11
|
+
export declare function testLegacyUnmount(container: ContainerType, isTest: boolean): boolean | Promise<void>;
|
|
12
|
+
export declare function unmount(container: ContainerType): boolean | Promise<void>;
|
|
13
13
|
export {};
|
package/es/render.js
CHANGED
|
@@ -35,13 +35,15 @@ var __async = (__this, __arguments, generator) => {
|
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
37
|
import * as ReactDOM from "react-dom";
|
|
38
|
+
import * as ReactDOMClient from "react-dom/client";
|
|
38
39
|
const MARK = "__bifrostui_react_root__";
|
|
39
40
|
const fullClone = __spreadValues({}, ReactDOM);
|
|
40
41
|
const { version, render: reactRender, unmountComponentAtNode } = fullClone;
|
|
41
42
|
let createRoot;
|
|
42
43
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
const majorVersion = Number((version || "").split(".")[0]);
|
|
45
|
+
if (majorVersion >= 18) {
|
|
46
|
+
createRoot = ReactDOMClient.createRoot || fullClone.createRoot;
|
|
45
47
|
}
|
|
46
48
|
} catch (e) {
|
|
47
49
|
}
|
|
@@ -64,7 +66,13 @@ function modernRender(node, container) {
|
|
|
64
66
|
container[MARK] = root;
|
|
65
67
|
}
|
|
66
68
|
function legacyRender(node, container) {
|
|
67
|
-
|
|
69
|
+
if (typeof reactRender === "function") {
|
|
70
|
+
reactRender(node, container);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (createRoot) {
|
|
74
|
+
modernRender(node, container);
|
|
75
|
+
}
|
|
68
76
|
}
|
|
69
77
|
function render(node, container) {
|
|
70
78
|
if (createRoot) {
|
|
@@ -88,7 +96,10 @@ function modernUnmount(container) {
|
|
|
88
96
|
});
|
|
89
97
|
}
|
|
90
98
|
function legacyUnmount(container) {
|
|
91
|
-
|
|
99
|
+
if (typeof unmountComponentAtNode === "function") {
|
|
100
|
+
return unmountComponentAtNode(container);
|
|
101
|
+
}
|
|
102
|
+
return modernUnmount(container);
|
|
92
103
|
}
|
|
93
104
|
function unmount(container) {
|
|
94
105
|
if (createRoot) {
|
package/es/setRef.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
export default function setRef<T>(ref: React.MutableRefObject<T | null> | ((instance: T | null) => void) | null | undefined, value: T | null): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { canUseDOM } from './canUseDOM';
|
package/es/ssr/index.js
ADDED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { CssVarToValueOptions } from './index.types';
|
|
2
|
+
/**
|
|
3
|
+
* 设置全局默认主题变量
|
|
4
|
+
* 建议在小程序入口文件(app.ts)中调用,设置后所有组件都会使用该主题
|
|
5
|
+
* 支持主题继承:如果设置的主题中某个变量不存在,会自动从 defaultLight 继承
|
|
6
|
+
* @param themeVars 主题CSS变量对象
|
|
7
|
+
* @example
|
|
8
|
+
* import { setDefaultThemeVars } from '@bifrostui/utils';
|
|
9
|
+
* import { pioneerLight } from '@bifrostui/styles/registry';
|
|
10
|
+
* setDefaultThemeVars(pioneerLight.cssVars);
|
|
11
|
+
*/
|
|
12
|
+
export declare const setDefaultThemeVars: (themeVars: Record<string, string> | undefined) => void;
|
|
13
|
+
/**
|
|
14
|
+
* 获取当前全局默认主题变量
|
|
15
|
+
* 返回合并后的主题变量(自定义主题 + defaultLight 基础主题)
|
|
16
|
+
*/
|
|
17
|
+
export declare const getDefaultThemeVars: () => Record<string, string> | undefined;
|
|
2
18
|
/**
|
|
3
19
|
* css变量转值
|
|
4
20
|
*/
|
|
@@ -1,9 +1,35 @@
|
|
|
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 { defaultLight } from "@bifrostui/styles/registry";
|
|
18
|
+
let globalDefaultThemeVars;
|
|
19
|
+
const setDefaultThemeVars = (themeVars) => {
|
|
20
|
+
globalDefaultThemeVars = themeVars;
|
|
21
|
+
};
|
|
22
|
+
const getDefaultThemeVars = () => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
if (!globalDefaultThemeVars) {
|
|
25
|
+
return (_a = defaultLight) == null ? void 0 : _a.cssVars;
|
|
26
|
+
}
|
|
27
|
+
return __spreadValues(__spreadValues({}, (_b = defaultLight) == null ? void 0 : _b.cssVars), globalDefaultThemeVars);
|
|
28
|
+
};
|
|
2
29
|
const cssVarToValue = (options) => {
|
|
3
|
-
var _a;
|
|
4
30
|
const {
|
|
5
31
|
cssVar,
|
|
6
|
-
themeVars = (
|
|
32
|
+
themeVars = getDefaultThemeVars(),
|
|
7
33
|
_visitedKeys = /* @__PURE__ */ new Set()
|
|
8
34
|
} = options || {};
|
|
9
35
|
if (!cssVar)
|
|
@@ -25,5 +51,7 @@ const cssVarToValue = (options) => {
|
|
|
25
51
|
return variableValue;
|
|
26
52
|
};
|
|
27
53
|
export {
|
|
28
|
-
cssVarToValue
|
|
54
|
+
cssVarToValue,
|
|
55
|
+
getDefaultThemeVars,
|
|
56
|
+
setDefaultThemeVars
|
|
29
57
|
};
|
package/es/toArray.d.ts
CHANGED
package/es/toArray.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
function isReactFragment(child) {
|
|
3
|
+
return React.isValidElement(child) && child.type === React.Fragment;
|
|
4
|
+
}
|
|
3
5
|
function toArray(children, option = {}) {
|
|
4
6
|
let ret = [];
|
|
5
7
|
React.Children.forEach(children, (child) => {
|
|
@@ -8,7 +10,7 @@ function toArray(children, option = {}) {
|
|
|
8
10
|
}
|
|
9
11
|
if (Array.isArray(child)) {
|
|
10
12
|
ret = ret.concat(toArray(child));
|
|
11
|
-
} else if (
|
|
13
|
+
} else if (isReactFragment(child)) {
|
|
12
14
|
ret = ret.concat(toArray(child.props.children, option));
|
|
13
15
|
} else {
|
|
14
16
|
ret.push(child);
|
package/es/transitions.d.ts
CHANGED
package/es/transitions.js
CHANGED
|
@@ -52,7 +52,7 @@ function formatMs(milliseconds) {
|
|
|
52
52
|
function createTransitions(inputTransitions = {}) {
|
|
53
53
|
const mergedEasing = __spreadValues(__spreadValues({}, easing), inputTransitions.easing);
|
|
54
54
|
const mergedDuration = __spreadValues(__spreadValues({}, duration), inputTransitions.duration);
|
|
55
|
-
const create = (props = ["all"], options) => {
|
|
55
|
+
const create = (props = ["all"], options = {}) => {
|
|
56
56
|
const {
|
|
57
57
|
duration: durationOption = mergedDuration.standard,
|
|
58
58
|
easing: easingOption = mergedEasing.easeInOut,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bifrostui/utils",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.41",
|
|
4
4
|
"description": "BUI React utilities for building components.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -10,20 +10,26 @@
|
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"devDependencies": {
|
|
13
|
+
"@tarojs/runtime": "^3.0.0",
|
|
14
|
+
"@tarojs/taro": "^3.0.0",
|
|
13
15
|
"esbuild": "^0.19.7",
|
|
14
|
-
"esbuild-plugin-less": "1.3.
|
|
15
|
-
"fs-extra": "^
|
|
16
|
-
"glob": "11.0.0"
|
|
16
|
+
"esbuild-plugin-less": "1.3.38",
|
|
17
|
+
"fs-extra": "^10.0.0",
|
|
18
|
+
"glob": "11.0.0",
|
|
19
|
+
"react": "^19.0.0",
|
|
20
|
+
"react-dom": "^19.0.0",
|
|
21
|
+
"scheduler": "0.27.0"
|
|
17
22
|
},
|
|
18
23
|
"dependencies": {
|
|
19
|
-
"react-is": "^18.0.0",
|
|
20
|
-
"@bifrostui/styles": "2.0.0-alpha.
|
|
24
|
+
"react-is": "^18.0.0 || ^19.0.0",
|
|
25
|
+
"@bifrostui/styles": "2.0.0-alpha.41"
|
|
21
26
|
},
|
|
22
27
|
"peerDependencies": {
|
|
23
28
|
"@tarojs/runtime": "^3.0.0",
|
|
24
29
|
"@tarojs/taro": "^3.0.0",
|
|
25
|
-
"react": "^17.0.0 || ^18.0.0",
|
|
26
|
-
"react-dom": "^17.0.0 || ^18.0.0"
|
|
30
|
+
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
31
|
+
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
32
|
+
"scheduler": ">=0.27.0"
|
|
27
33
|
},
|
|
28
34
|
"license": "MIT",
|
|
29
35
|
"publishConfig": {
|
|
@@ -32,6 +38,6 @@
|
|
|
32
38
|
},
|
|
33
39
|
"scripts": {
|
|
34
40
|
"build": "node esbuild.config.js",
|
|
35
|
-
"test": "
|
|
41
|
+
"test": "cd ../.. && vitest run --project bui-utils"
|
|
36
42
|
}
|
|
37
43
|
}
|