@weavy/uikit-react 29.2.1 → 29.3.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,4 +1,3 @@
1
- import { default as React } from 'react';
2
1
  import { WeavyContext } from '@weavy/uikit-web';
3
2
  import { Context } from '@weavy/uikit-web/dist/types/contexts/index.js';
4
3
  /**
@@ -6,8 +5,8 @@ import { Context } from '@weavy/uikit-web/dist/types/contexts/index.js';
6
5
  * The useWeavyContext(ref) must be used with an element reference from any child from the DOM tree since it relies on standard events in the DOM.
7
6
  *
8
7
  * @see https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md
9
- * @param ref { React.RefObject | HTMLElement } - Reference object that needs to be placed in the DOM.
10
- * @param context { Context } - The context to use. Defaults to WeavyContext from ukit-web.
8
+ * @param ref { (() => HTMLElement) | HTMLElement } - Reference object or function returning a reference object. The object needs to be placed in the DOM.
9
+ * @param context { Context } - The context to use. Defaults to WeavyContext from uikit-web.
11
10
  * @returns Weavy instance
12
11
  * @example
13
12
  * import React, { useRef } from "react"
@@ -15,7 +14,7 @@ import { Context } from '@weavy/uikit-web/dist/types/contexts/index.js';
15
14
  *
16
15
  * export const MyComponent = () => {
17
16
  * const domRef = useRef(null)
18
- * const weavy = useWeavyContext(domRef)
17
+ * const weavy = useWeavyContext(() => domRef.current)
19
18
  *
20
19
  * useEffect(() => {
21
20
  * if (weavy) {
@@ -31,5 +30,5 @@ import { Context } from '@weavy/uikit-web/dist/types/contexts/index.js';
31
30
  * )
32
31
  * }
33
32
  */
34
- export declare function useWeavyContext<TContext extends Context<unknown, unknown> = typeof WeavyContext, TElement extends HTMLElement = HTMLElement>(ref: React.RefObject<TElement> | TElement | null, context?: TContext): import('@weavy/uikit-web').WeavyType | import('@weavy/uikit-web/dist/types/utils/context/create-context.js').ContextType<TContext> | undefined;
33
+ export declare function useWeavyContext<TContext extends Context<unknown, unknown> = typeof WeavyContext, TElement extends HTMLElement = HTMLElement>(ref: (() => TElement | null) | TElement | null, context?: TContext): import('@weavy/uikit-web').WeavyType | import('@weavy/uikit-web/dist/types/utils/context/create-context.js').ContextType<TContext> | undefined;
35
34
  export type { Context };
@@ -27,7 +27,7 @@ export function WyContext({
27
27
  ...props
28
28
  }: React.ComponentProps<typeof WyContextComponent>) {
29
29
  const contextRef = useRef(null);
30
- const weavy = useWeavyContext(contextRef.current);
30
+ const weavy = useWeavyContext(() => contextRef.current);
31
31
  return (
32
32
  <WyContextComponent ref={contextRef} {...props}>
33
33
  <WeavyContext.Provider value={weavy ?? null}>
@@ -8,8 +8,8 @@ import { Context } from "@weavy/uikit-web/dist/types/contexts/index.js";
8
8
  * The useWeavyContext(ref) must be used with an element reference from any child from the DOM tree since it relies on standard events in the DOM.
9
9
  *
10
10
  * @see https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md
11
- * @param ref { React.RefObject | HTMLElement } - Reference object that needs to be placed in the DOM.
12
- * @param context { Context } - The context to use. Defaults to WeavyContext from ukit-web.
11
+ * @param ref { (() => HTMLElement) | HTMLElement } - Reference object or function returning a reference object. The object needs to be placed in the DOM.
12
+ * @param context { Context } - The context to use. Defaults to WeavyContext from uikit-web.
13
13
  * @returns Weavy instance
14
14
  * @example
15
15
  * import React, { useRef } from "react"
@@ -17,7 +17,7 @@ import { Context } from "@weavy/uikit-web/dist/types/contexts/index.js";
17
17
  *
18
18
  * export const MyComponent = () => {
19
19
  * const domRef = useRef(null)
20
- * const weavy = useWeavyContext(domRef)
20
+ * const weavy = useWeavyContext(() => domRef.current)
21
21
  *
22
22
  * useEffect(() => {
23
23
  * if (weavy) {
@@ -34,13 +34,13 @@ import { Context } from "@weavy/uikit-web/dist/types/contexts/index.js";
34
34
  * }
35
35
  */
36
36
  export function useWeavyContext<TContext extends Context<unknown, unknown> = typeof WeavyContext, TElement extends HTMLElement = HTMLElement>(
37
- ref: React.RefObject<TElement> | TElement | null,
37
+ ref: (() => TElement | null) | TElement | null,
38
38
  context?: TContext
39
39
  ) {
40
- const isRef = (r: typeof ref): r is React.RefObject<TElement> => {
41
- return Boolean(r) && (r as React.RefObject<TElement>).current !== undefined
42
- }
43
- const domRef = (isRef(ref) ? ref.current : ref) || undefined;
40
+ // Using ref.current for backward compatibility only
41
+
42
+ // eslint-disable-next-line react-hooks/refs
43
+ const domRef = (typeof ref === "function" ? ref() : (ref && "current" in ref) ? ref.current as HTMLElement : ref) || undefined;
44
44
 
45
45
  const controller = useController(
46
46
  React,
@@ -49,8 +49,9 @@ export function useWeavyContext<TContext extends Context<unknown, unknown> = typ
49
49
 
50
50
  useEffect(() => {
51
51
  if (domRef) {
52
- controller.ref = domRef;
52
+ controller.setRef(domRef);
53
53
  }
54
+ // eslint-disable-next-line react-hooks/refs
54
55
  }, [controller, domRef]);
55
56
 
56
57
  return controller.context?.value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weavy/uikit-react",
3
- "version": "29.2.1",
3
+ "version": "29.3.0",
4
4
  "author": "Weavy",
5
5
  "description": "React components UI-kit for Weavy",
6
6
  "homepage": "https://github.com/weavy/weavy-uikit-react",
@@ -39,38 +39,38 @@
39
39
  "lint": "eslint lib"
40
40
  },
41
41
  "dependencies": {
42
- "@lit/react": "^1.0.7",
43
- "@weavy/uikit-web": "^29.2.1"
42
+ "@lit/react": "^1.0.8",
43
+ "@weavy/uikit-web": "^29.3.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "react": ">=16",
47
47
  "react-dom": ">=16"
48
48
  },
49
49
  "devDependencies": {
50
- "@babel/preset-env": "^7.27.2",
51
- "@babel/preset-react": "^7.27.1",
50
+ "@babel/preset-env": "^7.28.5",
51
+ "@babel/preset-react": "^7.28.5",
52
52
  "@eslint/js": "^9.29.0",
53
- "@rollup/plugin-babel": "^6.0.4",
54
- "@rollup/plugin-node-resolve": "^16.0.1",
55
- "@types/node": "^22.15.32",
56
- "@types/react": "^18.3.23",
53
+ "@rollup/plugin-babel": "^6.1.0",
54
+ "@rollup/plugin-node-resolve": "^16.0.3",
55
+ "@types/node": "^22.19.0",
56
+ "@types/react": "^18.3.26",
57
57
  "@types/react-dom": "^18.3.7",
58
- "@vitejs/plugin-react": "^4.5.2",
59
- "dotenv": "^16.5.0",
60
- "eslint": "^9.29.0",
58
+ "@vitejs/plugin-react": "^5.1.0",
59
+ "dotenv": "^17.2.3",
60
+ "eslint": "^9.39.1",
61
61
  "eslint-plugin-react": "^7.37.5",
62
- "eslint-plugin-react-hooks": "^5.2.0",
63
- "eslint-plugin-react-refresh": "^0.4.20",
64
- "globals": "^16.2.0",
62
+ "eslint-plugin-react-hooks": "^7.0.1",
63
+ "eslint-plugin-react-refresh": "^0.4.24",
64
+ "globals": "^16.5.0",
65
65
  "npm-run-all": "^4.1.5",
66
66
  "react": "^18.3.1",
67
67
  "react-dom": "^18.3.1",
68
- "rimraf": "^6.0.1",
68
+ "rimraf": "^6.1.0",
69
69
  "rollup-preserve-directives": "^1.1.3",
70
- "sass": "^1.89.2",
71
- "typescript": "^5.8.3",
72
- "typescript-eslint": "^8.34.1",
73
- "vite": "^6.3.5",
70
+ "sass": "^1.93.3",
71
+ "typescript": "^5.9.3",
72
+ "typescript-eslint": "^8.46.3",
73
+ "vite": "^7.2.0",
74
74
  "vite-plugin-dts": "^4.5.4"
75
75
  }
76
76
  }