@bifrostui/utils 2.0.0-alpha.32 → 2.0.0-alpha.33

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.
@@ -43,7 +43,7 @@ function useMemoizedFn(fn) {
43
43
  }
44
44
  const fnRef = (0, import_react.useRef)(fn);
45
45
  fnRef.current = (0, import_react.useMemo)(() => fn, [fn]);
46
- const memoizedFn = (0, import_react.useRef)();
46
+ const memoizedFn = (0, import_react.useRef)(null);
47
47
  if (!memoizedFn.current) {
48
48
  memoizedFn.current = function memoized(...args) {
49
49
  return fnRef.current.apply(this, args);
@@ -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.MutableRefObject<number>;
9
- startX: React.MutableRefObject<number>;
10
- startY: React.MutableRefObject<number>;
11
- deltaX: React.MutableRefObject<number>;
12
- deltaY: React.MutableRefObject<number>;
13
- delta: React.MutableRefObject<number>;
14
- offsetX: React.MutableRefObject<number>;
15
- offsetY: React.MutableRefObject<number>;
16
- direction: React.MutableRefObject<Direction>;
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.MutableRefObject<boolean>;
19
+ last: React.RefObject<boolean>;
20
20
  };
21
21
  export default useTouch;
@@ -23,7 +23,7 @@ module.exports = __toCommonJS(useUniqueId_exports);
23
23
  var import_react = require("react");
24
24
  let globalClientIdCounter = 0;
25
25
  function useUniqueId() {
26
- const idRef = (0, import_react.useRef)();
26
+ const idRef = (0, import_react.useRef)(null);
27
27
  if (!idRef.current) {
28
28
  globalClientIdCounter += 1;
29
29
  idRef.current = `b${globalClientIdCounter.toString(32)}`;
package/dist/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): boolean;
11
+ export declare function testLegacyUnmount(container: ContainerType, isTest: boolean): boolean | Promise<void>;
12
12
  export declare function unmount(container: ContainerType): boolean | Promise<void>;
13
13
  export {};
package/dist/render.js CHANGED
@@ -68,13 +68,15 @@ __export(render_exports, {
68
68
  });
69
69
  module.exports = __toCommonJS(render_exports);
70
70
  var ReactDOM = __toESM(require("react-dom"));
71
+ var ReactDOMClient = __toESM(require("react-dom/client"));
71
72
  const MARK = "__bifrostui_react_root__";
72
73
  const fullClone = __spreadValues({}, ReactDOM);
73
74
  const { version, render: reactRender, unmountComponentAtNode } = fullClone;
74
75
  let createRoot;
75
76
  try {
76
- if (Number((version || "").split(".")[0]) >= 18 && fullClone.createRoot) {
77
- createRoot = fullClone.createRoot;
77
+ const majorVersion = Number((version || "").split(".")[0]);
78
+ if (majorVersion >= 18) {
79
+ createRoot = ReactDOMClient.createRoot || fullClone.createRoot;
78
80
  }
79
81
  } catch (e) {
80
82
  }
@@ -97,7 +99,13 @@ function modernRender(node, container) {
97
99
  container[MARK] = root;
98
100
  }
99
101
  function legacyRender(node, container) {
100
- reactRender(node, container);
102
+ if (typeof reactRender === "function") {
103
+ reactRender(node, container);
104
+ return;
105
+ }
106
+ if (createRoot) {
107
+ modernRender(node, container);
108
+ }
101
109
  }
102
110
  function render(node, container) {
103
111
  if (createRoot) {
@@ -121,7 +129,10 @@ function modernUnmount(container) {
121
129
  });
122
130
  }
123
131
  function legacyUnmount(container) {
124
- return unmountComponentAtNode(container);
132
+ if (typeof unmountComponentAtNode === "function") {
133
+ return unmountComponentAtNode(container);
134
+ }
135
+ return modernUnmount(container);
125
136
  }
126
137
  function unmount(container) {
127
138
  if (createRoot) {
package/dist/toArray.js CHANGED
@@ -31,7 +31,9 @@ __export(toArray_exports, {
31
31
  });
32
32
  module.exports = __toCommonJS(toArray_exports);
33
33
  var React = __toESM(require("react"));
34
- var import_react_is = require("react-is");
34
+ function isReactFragment(child) {
35
+ return React.isValidElement(child) && child.type === React.Fragment;
36
+ }
35
37
  function toArray(children, option = {}) {
36
38
  let ret = [];
37
39
  React.Children.forEach(children, (child) => {
@@ -40,7 +42,7 @@ function toArray(children, option = {}) {
40
42
  }
41
43
  if (Array.isArray(child)) {
42
44
  ret = ret.concat(toArray(child));
43
- } else if ((0, import_react_is.isFragment)(child) && React.isValidElement(child)) {
45
+ } else if (isReactFragment(child)) {
44
46
  ret = ret.concat(toArray(child.props.children, option));
45
47
  } else {
46
48
  ret.push(child);
@@ -11,7 +11,7 @@ function useMemoizedFn(fn) {
11
11
  }
12
12
  const fnRef = useRef(fn);
13
13
  fnRef.current = useMemo(() => fn, [fn]);
14
- const memoizedFn = useRef();
14
+ const memoizedFn = useRef(null);
15
15
  if (!memoizedFn.current) {
16
16
  memoizedFn.current = function memoized(...args) {
17
17
  return fnRef.current.apply(this, args);
@@ -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.MutableRefObject<number>;
9
- startX: React.MutableRefObject<number>;
10
- startY: React.MutableRefObject<number>;
11
- deltaX: React.MutableRefObject<number>;
12
- deltaY: React.MutableRefObject<number>;
13
- delta: React.MutableRefObject<number>;
14
- offsetX: React.MutableRefObject<number>;
15
- offsetY: React.MutableRefObject<number>;
16
- direction: React.MutableRefObject<Direction>;
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.MutableRefObject<boolean>;
19
+ last: React.RefObject<boolean>;
20
20
  };
21
21
  export default useTouch;
@@ -1,7 +1,7 @@
1
1
  import { useRef } from "react";
2
2
  let globalClientIdCounter = 0;
3
3
  function useUniqueId() {
4
- const idRef = useRef();
4
+ const idRef = useRef(null);
5
5
  if (!idRef.current) {
6
6
  globalClientIdCounter += 1;
7
7
  idRef.current = `b${globalClientIdCounter.toString(32)}`;
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): boolean;
11
+ export declare function testLegacyUnmount(container: ContainerType, isTest: boolean): boolean | Promise<void>;
12
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
- if (Number((version || "").split(".")[0]) >= 18 && fullClone.createRoot) {
44
- createRoot = fullClone.createRoot;
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
- reactRender(node, container);
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
- return unmountComponentAtNode(container);
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/toArray.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import * as React from "react";
2
- import { isFragment } from "react-is";
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 (isFragment(child) && React.isValidElement(child)) {
13
+ } else if (isReactFragment(child)) {
12
14
  ret = ret.concat(toArray(child.props.children, option));
13
15
  } else {
14
16
  ret.push(child);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifrostui/utils",
3
- "version": "2.0.0-alpha.32",
3
+ "version": "2.0.0-alpha.33",
4
4
  "description": "BUI React utilities for building components.",
5
5
  "main": "dist/index.js",
6
6
  "module": "es/index.js",
@@ -10,20 +10,25 @@
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.10",
15
- "fs-extra": "^11.2.0",
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.32"
24
+ "react-is": "^18.0.0 || ^19.0.0",
25
+ "@bifrostui/styles": "2.0.0-alpha.33"
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",
27
32
  "scheduler": ">=0.27.0"
28
33
  },
29
34
  "license": "MIT",