@dxos/web-context-react 0.8.4-main.ef1bc66f44 → 0.8.4-main.f466a3d56e
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/browser/index.mjs +15 -6
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +15 -6
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/provider.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -7
- package/src/consumer.test.tsx +5 -5
- package/src/provider.tsx +16 -6
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2025 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ import { useWebComponentContext } from '@dxos/web-context-react';
|
|
|
40
40
|
|
|
41
41
|
const MyComponent = () => {
|
|
42
42
|
const theme = useWebComponentContext(ThemeContext, { subscribe: true });
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
return <div style={{ color: theme?.color }}>Hello World</div>;
|
|
45
45
|
};
|
|
46
46
|
```
|
|
@@ -73,8 +73,12 @@ var ContextProtocolProvider = ({ context, value, children }) => {
|
|
|
73
73
|
]);
|
|
74
74
|
const handleContextProviderEvent = useCallback((e) => {
|
|
75
75
|
const event = e;
|
|
76
|
-
if (event.context !== context)
|
|
77
|
-
|
|
76
|
+
if (event.context !== context) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (containerRef.current && event.contextTarget === containerRef.current) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
78
82
|
const seen = /* @__PURE__ */ new Set();
|
|
79
83
|
for (const ref of subscriptionRefs) {
|
|
80
84
|
const callback = ref.deref();
|
|
@@ -83,8 +87,12 @@ var ContextProtocolProvider = ({ context, value, children }) => {
|
|
|
83
87
|
continue;
|
|
84
88
|
}
|
|
85
89
|
const info = subscriptions.get(callback);
|
|
86
|
-
if (!info)
|
|
87
|
-
|
|
90
|
+
if (!info) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (seen.has(callback)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
88
96
|
seen.add(callback);
|
|
89
97
|
info.consumerHost.dispatchEvent(new ContextRequestEvent(context, callback, {
|
|
90
98
|
subscribe: true,
|
|
@@ -113,7 +121,9 @@ var ContextProtocolProvider = ({ context, value, children }) => {
|
|
|
113
121
|
const containerRef = useRef(null);
|
|
114
122
|
useEffect(() => {
|
|
115
123
|
const el = containerRef.current;
|
|
116
|
-
if (!el)
|
|
124
|
+
if (!el) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
117
127
|
el.addEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);
|
|
118
128
|
el.addEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);
|
|
119
129
|
el.dispatchEvent(new ContextProviderEvent(context, el));
|
|
@@ -130,7 +140,6 @@ var ContextProtocolProvider = ({ context, value, children }) => {
|
|
|
130
140
|
return /* @__PURE__ */ React.createElement(ContextRequestHandlerContext.Provider, {
|
|
131
141
|
value: handleRequest
|
|
132
142
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
133
|
-
role: "none",
|
|
134
143
|
className: "contents",
|
|
135
144
|
ref: containerRef
|
|
136
145
|
}, children));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts", "../../../src/consumer.ts", "../../../src/internal.ts", "../../../src/provider.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport * from '@dxos/web-context';\n\nexport * from './consumer';\nexport * from './provider';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useContext, useEffect, useState } from 'react';\n\nimport { ContextRequestEvent, type ContextType, type UnknownContext } from '@dxos/web-context';\n\nimport { HostElementContext } from './internal';\nimport { useContextRequestHandler } from './provider';\n\n/**\n * Options for useWebComponentContext hook\n */\nexport interface UseWebComponentContextOptions {\n /**\n * Whether to subscribe to context updates.\n * If true, the returned value will update when the provider's value changes.\n * Default: false\n */\n subscribe?: boolean;\n\n /**\n * The element to dispatch the context-request event from.\n * This is only used when there's no React provider in the tree.\n * Default: document.body\n */\n element?: HTMLElement;\n}\n\n/**\n * A React hook that requests context using the Web Component Context Protocol.\n *\n * This first tries to use the React context chain (for providers in the same\n * React tree), then falls back to dispatching a DOM event (for web component\n * providers).\n *\n * @param context - The context key to request\n * @param options - Optional configuration\n * @returns The context value or undefined\n */\nexport function useWebComponentContext<T extends UnknownContext>(\n context: T,\n options?: UseWebComponentContextOptions,\n): ContextType<T> | undefined {\n const [value, setValue] = useState<ContextType<T> | undefined>(undefined);\n\n const handler = useContextRequestHandler();\n const hostElement = useContext(HostElementContext);\n\n useEffect(() => {\n let unsubscribeFn: (() => void) | undefined;\n\n const callback = (newValue: ContextType<T>, unsubscribe?: () => void) => {\n setValue(newValue);\n if (unsubscribe) {\n unsubscribeFn = unsubscribe;\n }\n };\n\n const targetElement = options?.element ?? hostElement ?? document.body;\n\n const event = new ContextRequestEvent(context, callback, {\n subscribe: options?.subscribe,\n target: targetElement,\n });\n\n let handled = false;\n if (handler) {\n handled = handler(event);\n }\n\n if (!handled) {\n targetElement.dispatchEvent(event);\n }\n\n return () => {\n unsubscribeFn?.();\n };\n }, [context, options?.subscribe, options?.element, handler, hostElement]);\n\n return value;\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { createContext } from 'react';\n\n/**\n * Internal React context for passing the host element to nested components.\n * This allows useWebComponentContext to dispatch events from the custom element.\n */\nexport const HostElementContext = createContext<HTMLElement | undefined>(undefined);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport React, {\n type JSX,\n type PropsWithChildren,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n} from 'react';\n\nimport {\n CONTEXT_PROVIDER_EVENT,\n CONTEXT_REQUEST_EVENT,\n type ContextCallback,\n ContextProviderEvent,\n ContextRequestEvent,\n type ContextType,\n type UnknownContext,\n} from '@dxos/web-context';\n\n/**\n * Handler function type for context requests passed via React context\n */\ntype ContextRequestHandler = (event: ContextRequestEvent<UnknownContext>) => boolean;\n\n/**\n * Internal React context for passing context request handlers down the tree.\n * This allows useWebComponentContext to work synchronously in React.\n */\nconst ContextRequestHandlerContext = createContext<ContextRequestHandler | undefined>(undefined);\n\n/**\n * Try to handle a context request using the React context chain.\n * Returns true if handled, false otherwise.\n * Used internally by useWebComponentContext.\n */\nexport function tryHandleContextRequest(event: ContextRequestEvent<UnknownContext>): boolean {\n // This function is intended to be used where useContext is invalid (outside component),\n // but context handling in React MUST happen inside components.\n // So this helper might be less useful in React than in Solid if not used inside a hook/component.\n // However, we can export the context itself for consumers to use `useContext`.\n return false;\n}\n\n/**\n * Get the context request handler from React context.\n * Used internally by useWebComponentContext.\n */\nexport function useContextRequestHandler(): ContextRequestHandler | undefined {\n return useContext(ContextRequestHandlerContext);\n}\n\n/**\n * Props for the ContextProtocolProvider component\n */\nexport interface ContextProtocolProviderProps<T extends UnknownContext> {\n /** The context key to provide */\n context: T;\n /** The value to provide */\n value: ContextType<T>;\n}\n\n/**\n * A provider component that:\n * 1. Handles context-request events from web components (via DOM events)\n * 2. Handles context requests from React consumers (via React context)\n * 3. Supports subscriptions for reactive updates\n * 4. Uses WeakRef for subscriptions to prevent memory leaks\n */\nexport const ContextProtocolProvider = <T extends UnknownContext>({\n context,\n value,\n children,\n}: PropsWithChildren<ContextProtocolProviderProps<T>>): JSX.Element => {\n // Get parent handler if one exists (for nested providers)\n const parentHandler = useContext(ContextRequestHandlerContext);\n\n // Track subscriptions with their stable unsubscribe functions and consumer host elements\n interface SubscriptionInfo {\n unsubscribe: () => void;\n consumerHost: Element;\n ref: WeakRef<ContextCallback<ContextType<T>>>;\n }\n\n // We use refs for mutable state that doesn't trigger re-renders\n const subscriptions = useRef(new WeakMap<ContextCallback<ContextType<T>>, SubscriptionInfo>()).current;\n const subscriptionRefs = useRef(new Set<WeakRef<ContextCallback<ContextType<T>>>>()).current;\n const valueRef = useRef(value);\n\n // Update value ref when prop changes\n useEffect(() => {\n valueRef.current = value;\n }, [value]);\n\n // Core handler logic\n const handleRequest = useCallback(\n (event: ContextRequestEvent<UnknownContext>): boolean => {\n if (event.context !== context) {\n if (parentHandler) {\n return parentHandler(event);\n }\n return false;\n }\n\n const currentValue = valueRef.current; // Use latest value\n\n if (event.subscribe) {\n const callback = event.callback as ContextCallback<ContextType<T>>;\n const consumerHost = event.contextTarget || (event.composedPath()[0] as Element);\n\n const unsubscribe = () => {\n const info = subscriptions.get(callback);\n if (info) {\n subscriptionRefs.delete(info.ref);\n subscriptions.delete(callback);\n }\n };\n\n const ref = new WeakRef(callback);\n subscriptions.set(callback, { unsubscribe, consumerHost, ref });\n subscriptionRefs.add(ref);\n\n event.callback(currentValue, unsubscribe);\n } else {\n event.callback(currentValue);\n }\n\n return true;\n },\n [context, parentHandler], // Dependencies\n );\n\n // Handle DOM context-request events\n const handleContextRequestEvent = useCallback(\n (e: Event) => {\n const event = e as ContextRequestEvent<UnknownContext>;\n if (handleRequest(event)) {\n event.stopImmediatePropagation();\n }\n },\n [handleRequest],\n );\n\n // Handle context-provider events\n const handleContextProviderEvent = useCallback(\n (e: Event) => {\n const event = e as ContextProviderEvent<UnknownContext>;\n if (event.context !== context) return;\n if (containerRef.current && event.contextTarget === containerRef.current) return;\n\n const seen = new Set<ContextCallback<ContextType<T>>>();\n for (const ref of subscriptionRefs) {\n const callback = ref.deref();\n if (!callback) {\n subscriptionRefs.delete(ref);\n continue;\n }\n\n const info = subscriptions.get(callback);\n if (!info) continue;\n\n if (seen.has(callback)) continue;\n seen.add(callback);\n\n info.consumerHost.dispatchEvent(\n new ContextRequestEvent(context, callback, { subscribe: true, target: info.consumerHost }),\n );\n }\n event.stopPropagation();\n },\n [context],\n );\n\n // Notify subscribers when value changes.\n useEffect(() => {\n // Skip notification if value hasn't changed? React does this for us if we use dependencies correctly?\n // No, we need to imperatively call callbacks.\n // value constraint is in the dependency array.\n\n for (const ref of subscriptionRefs) {\n const callback = ref.deref();\n if (!callback) {\n subscriptionRefs.delete(ref);\n continue;\n }\n const info = subscriptions.get(callback);\n if (info) {\n callback(value, info.unsubscribe);\n }\n }\n }, [value]);\n\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return;\n\n el.addEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);\n el.addEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);\n\n // Announce provider.\n el.dispatchEvent(new ContextProviderEvent(context, el));\n\n return () => {\n el.removeEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);\n el.removeEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);\n subscriptionRefs.clear();\n };\n }, [handleContextRequestEvent, handleContextProviderEvent, context]);\n\n return (\n <ContextRequestHandlerContext.Provider value={handleRequest}>\n <div role='none' className='contents' ref={containerRef}>\n {children}\n </div>\n </ContextRequestHandlerContext.Provider>\n );\n};\n"],
|
|
5
|
-
"mappings": ";AAIA,cAAc;;;ACAd,SAASA,cAAAA,aAAYC,aAAAA,YAAWC,gBAAgB;AAEhD,SAASC,uBAAAA,4BAAkE;;;ACF3E,SAASC,qBAAqB;AAMvB,IAAMC,
|
|
6
|
-
"names": ["useContext", "useEffect", "useState", "ContextRequestEvent", "createContext", "HostElementContext", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport * from '@dxos/web-context';\n\nexport * from './consumer';\nexport * from './provider';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useContext, useEffect, useState } from 'react';\n\nimport { ContextRequestEvent, type ContextType, type UnknownContext } from '@dxos/web-context';\n\nimport { HostElementContext } from './internal';\nimport { useContextRequestHandler } from './provider';\n\n/**\n * Options for useWebComponentContext hook\n */\nexport interface UseWebComponentContextOptions {\n /**\n * Whether to subscribe to context updates.\n * If true, the returned value will update when the provider's value changes.\n * Default: false\n */\n subscribe?: boolean;\n\n /**\n * The element to dispatch the context-request event from.\n * This is only used when there's no React provider in the tree.\n * Default: document.body\n */\n element?: HTMLElement;\n}\n\n/**\n * A React hook that requests context using the Web Component Context Protocol.\n *\n * This first tries to use the React context chain (for providers in the same\n * React tree), then falls back to dispatching a DOM event (for web component\n * providers).\n *\n * @param context - The context key to request\n * @param options - Optional configuration\n * @returns The context value or undefined\n */\nexport function useWebComponentContext<T extends UnknownContext>(\n context: T,\n options?: UseWebComponentContextOptions,\n): ContextType<T> | undefined {\n const [value, setValue] = useState<ContextType<T> | undefined>(undefined);\n\n const handler = useContextRequestHandler();\n const hostElement = useContext(HostElementContext);\n\n useEffect(() => {\n let unsubscribeFn: (() => void) | undefined;\n\n const callback = (newValue: ContextType<T>, unsubscribe?: () => void) => {\n setValue(newValue);\n if (unsubscribe) {\n unsubscribeFn = unsubscribe;\n }\n };\n\n const targetElement = options?.element ?? hostElement ?? document.body;\n\n const event = new ContextRequestEvent(context, callback, {\n subscribe: options?.subscribe,\n target: targetElement,\n });\n\n let handled = false;\n if (handler) {\n handled = handler(event);\n }\n\n if (!handled) {\n targetElement.dispatchEvent(event);\n }\n\n return () => {\n unsubscribeFn?.();\n };\n }, [context, options?.subscribe, options?.element, handler, hostElement]);\n\n return value;\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { createContext } from 'react';\n\n/**\n * Internal React context for passing the host element to nested components.\n * This allows useWebComponentContext to dispatch events from the custom element.\n */\nexport const HostElementContext = createContext<HTMLElement | undefined>(undefined);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport React, {\n type JSX,\n type PropsWithChildren,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n} from 'react';\n\nimport {\n CONTEXT_PROVIDER_EVENT,\n CONTEXT_REQUEST_EVENT,\n type ContextCallback,\n ContextProviderEvent,\n ContextRequestEvent,\n type ContextType,\n type UnknownContext,\n} from '@dxos/web-context';\n\n/**\n * Handler function type for context requests passed via React context\n */\ntype ContextRequestHandler = (event: ContextRequestEvent<UnknownContext>) => boolean;\n\n/**\n * Internal React context for passing context request handlers down the tree.\n * This allows useWebComponentContext to work synchronously in React.\n */\nconst ContextRequestHandlerContext = createContext<ContextRequestHandler | undefined>(undefined);\n\n/**\n * Try to handle a context request using the React context chain.\n * Returns true if handled, false otherwise.\n * Used internally by useWebComponentContext.\n */\nexport function tryHandleContextRequest(event: ContextRequestEvent<UnknownContext>): boolean {\n // This function is intended to be used where useContext is invalid (outside component),\n // but context handling in React MUST happen inside components.\n // So this helper might be less useful in React than in Solid if not used inside a hook/component.\n // However, we can export the context itself for consumers to use `useContext`.\n return false;\n}\n\n/**\n * Get the context request handler from React context.\n * Used internally by useWebComponentContext.\n */\nexport function useContextRequestHandler(): ContextRequestHandler | undefined {\n return useContext(ContextRequestHandlerContext);\n}\n\n/**\n * Props for the ContextProtocolProvider component\n */\nexport interface ContextProtocolProviderProps<T extends UnknownContext> {\n /** The context key to provide */\n context: T;\n /** The value to provide */\n value: ContextType<T>;\n}\n\n/**\n * A provider component that:\n * 1. Handles context-request events from web components (via DOM events)\n * 2. Handles context requests from React consumers (via React context)\n * 3. Supports subscriptions for reactive updates\n * 4. Uses WeakRef for subscriptions to prevent memory leaks\n */\nexport const ContextProtocolProvider = <T extends UnknownContext>({\n context,\n value,\n children,\n}: PropsWithChildren<ContextProtocolProviderProps<T>>): JSX.Element => {\n // Get parent handler if one exists (for nested providers)\n const parentHandler = useContext(ContextRequestHandlerContext);\n\n // Track subscriptions with their stable unsubscribe functions and consumer host elements\n interface SubscriptionInfo {\n unsubscribe: () => void;\n consumerHost: Element;\n ref: WeakRef<ContextCallback<ContextType<T>>>;\n }\n\n // We use refs for mutable state that doesn't trigger re-renders\n const subscriptions = useRef(new WeakMap<ContextCallback<ContextType<T>>, SubscriptionInfo>()).current;\n const subscriptionRefs = useRef(new Set<WeakRef<ContextCallback<ContextType<T>>>>()).current;\n const valueRef = useRef(value);\n\n // Update value ref when prop changes\n useEffect(() => {\n valueRef.current = value;\n }, [value]);\n\n // Core handler logic\n const handleRequest = useCallback(\n (event: ContextRequestEvent<UnknownContext>): boolean => {\n if (event.context !== context) {\n if (parentHandler) {\n return parentHandler(event);\n }\n return false;\n }\n\n const currentValue = valueRef.current; // Use latest value\n\n if (event.subscribe) {\n const callback = event.callback as ContextCallback<ContextType<T>>;\n const consumerHost = event.contextTarget || (event.composedPath()[0] as Element);\n\n const unsubscribe = () => {\n const info = subscriptions.get(callback);\n if (info) {\n subscriptionRefs.delete(info.ref);\n subscriptions.delete(callback);\n }\n };\n\n const ref = new WeakRef(callback);\n subscriptions.set(callback, { unsubscribe, consumerHost, ref });\n subscriptionRefs.add(ref);\n\n event.callback(currentValue, unsubscribe);\n } else {\n event.callback(currentValue);\n }\n\n return true;\n },\n [context, parentHandler], // Dependencies\n );\n\n // Handle DOM context-request events\n const handleContextRequestEvent = useCallback(\n (e: Event) => {\n const event = e as ContextRequestEvent<UnknownContext>;\n if (handleRequest(event)) {\n event.stopImmediatePropagation();\n }\n },\n [handleRequest],\n );\n\n // Handle context-provider events\n const handleContextProviderEvent = useCallback(\n (e: Event) => {\n const event = e as ContextProviderEvent<UnknownContext>;\n if (event.context !== context) {\n return;\n }\n if (containerRef.current && event.contextTarget === containerRef.current) {\n return;\n }\n\n const seen = new Set<ContextCallback<ContextType<T>>>();\n for (const ref of subscriptionRefs) {\n const callback = ref.deref();\n if (!callback) {\n subscriptionRefs.delete(ref);\n continue;\n }\n\n const info = subscriptions.get(callback);\n if (!info) {\n continue;\n }\n\n if (seen.has(callback)) {\n continue;\n }\n seen.add(callback);\n\n info.consumerHost.dispatchEvent(\n new ContextRequestEvent(context, callback, { subscribe: true, target: info.consumerHost }),\n );\n }\n event.stopPropagation();\n },\n [context],\n );\n\n // Notify subscribers when value changes.\n useEffect(() => {\n // Skip notification if value hasn't changed? React does this for us if we use dependencies correctly?\n // No, we need to imperatively call callbacks.\n // value constraint is in the dependency array.\n\n for (const ref of subscriptionRefs) {\n const callback = ref.deref();\n if (!callback) {\n subscriptionRefs.delete(ref);\n continue;\n }\n const info = subscriptions.get(callback);\n if (info) {\n callback(value, info.unsubscribe);\n }\n }\n }, [value]);\n\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const el = containerRef.current;\n if (!el) {\n return;\n }\n\n el.addEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);\n el.addEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);\n\n // Announce provider.\n el.dispatchEvent(new ContextProviderEvent(context, el));\n\n return () => {\n el.removeEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);\n el.removeEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);\n subscriptionRefs.clear();\n };\n }, [handleContextRequestEvent, handleContextProviderEvent, context]);\n\n return (\n <ContextRequestHandlerContext.Provider value={handleRequest}>\n <div className='contents' ref={containerRef}>\n {children}\n </div>\n </ContextRequestHandlerContext.Provider>\n );\n};\n"],
|
|
5
|
+
"mappings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AACXkB,gBAAUlB,QAAQc,KAAAA;IACpB;AAEA,QAAI,CAACI,SAAS;AACZR,oBAAcS,cAAcL,KAAAA;IAC9B;AAEA,WAAO,MAAA;AACLR,sBAAAA;IACF;EACF,GAAG;IAACZ;IAASC,SAASqB;IAAWrB,SAASgB;IAASX;IAASE;GAAY;AAExE,SAAON;AACT;",
|
|
6
|
+
"names": ["useContext", "useEffect", "useState", "ContextRequestEvent", "createContext", "HostElementContext", "undefined", "React", "createContext", "useCallback", "useContext", "useEffect", "useRef", "CONTEXT_PROVIDER_EVENT", "CONTEXT_REQUEST_EVENT", "ContextProviderEvent", "ContextRequestEvent", "ContextRequestHandlerContext", "undefined", "tryHandleContextRequest", "event", "useContextRequestHandler", "ContextProtocolProvider", "context", "value", "children", "parentHandler", "subscriptions", "WeakMap", "current", "subscriptionRefs", "Set", "valueRef", "handleRequest", "currentValue", "subscribe", "callback", "consumerHost", "contextTarget", "composedPath", "unsubscribe", "info", "get", "delete", "ref", "WeakRef", "set", "add", "handleContextRequestEvent", "e", "stopImmediatePropagation", "handleContextProviderEvent", "containerRef", "seen", "deref", "has", "dispatchEvent", "target", "stopPropagation", "el", "addEventListener", "removeEventListener", "clear", "Provider", "div", "className", "useWebComponentContext", "context", "options", "value", "setValue", "useState", "undefined", "handler", "useContextRequestHandler", "hostElement", "useContext", "HostElementContext", "useEffect", "unsubscribeFn", "callback", "newValue", "unsubscribe", "targetElement", "element", "document", "body", "event", "ContextRequestEvent", "subscribe", "target", "handled", "dispatchEvent"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/internal.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/internal.ts":{"bytes":1122,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"src/provider.tsx":{"bytes":21018,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true}],"format":"esm"},"src/consumer.ts":{"bytes":6500,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true},{"path":"src/internal.ts","kind":"import-statement","original":"./internal"},{"path":"src/provider.tsx","kind":"import-statement","original":"./provider"}],"format":"esm"},"src/index.ts":{"bytes":575,"imports":[{"path":"@dxos/web-context","kind":"import-statement","external":true},{"path":"src/consumer.ts","kind":"import-statement","original":"./consumer"},{"path":"src/provider.tsx","kind":"import-statement","original":"./provider"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15044},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/web-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true}],"exports":["ContextProtocolProvider","tryHandleContextRequest","useContextRequestHandler","useWebComponentContext"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":35},"src/consumer.ts":{"bytesInOutput":1096},"src/internal.ts":{"bytesInOutput":87},"src/provider.tsx":{"bytesInOutput":3991}},"bytes":5460}}}
|
|
@@ -75,8 +75,12 @@ var ContextProtocolProvider = ({ context, value, children }) => {
|
|
|
75
75
|
]);
|
|
76
76
|
const handleContextProviderEvent = useCallback((e) => {
|
|
77
77
|
const event = e;
|
|
78
|
-
if (event.context !== context)
|
|
79
|
-
|
|
78
|
+
if (event.context !== context) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (containerRef.current && event.contextTarget === containerRef.current) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
80
84
|
const seen = /* @__PURE__ */ new Set();
|
|
81
85
|
for (const ref of subscriptionRefs) {
|
|
82
86
|
const callback = ref.deref();
|
|
@@ -85,8 +89,12 @@ var ContextProtocolProvider = ({ context, value, children }) => {
|
|
|
85
89
|
continue;
|
|
86
90
|
}
|
|
87
91
|
const info = subscriptions.get(callback);
|
|
88
|
-
if (!info)
|
|
89
|
-
|
|
92
|
+
if (!info) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (seen.has(callback)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
90
98
|
seen.add(callback);
|
|
91
99
|
info.consumerHost.dispatchEvent(new ContextRequestEvent(context, callback, {
|
|
92
100
|
subscribe: true,
|
|
@@ -115,7 +123,9 @@ var ContextProtocolProvider = ({ context, value, children }) => {
|
|
|
115
123
|
const containerRef = useRef(null);
|
|
116
124
|
useEffect(() => {
|
|
117
125
|
const el = containerRef.current;
|
|
118
|
-
if (!el)
|
|
126
|
+
if (!el) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
119
129
|
el.addEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);
|
|
120
130
|
el.addEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);
|
|
121
131
|
el.dispatchEvent(new ContextProviderEvent(context, el));
|
|
@@ -132,7 +142,6 @@ var ContextProtocolProvider = ({ context, value, children }) => {
|
|
|
132
142
|
return /* @__PURE__ */ React.createElement(ContextRequestHandlerContext.Provider, {
|
|
133
143
|
value: handleRequest
|
|
134
144
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
135
|
-
role: "none",
|
|
136
145
|
className: "contents",
|
|
137
146
|
ref: containerRef
|
|
138
147
|
}, children));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts", "../../../src/consumer.ts", "../../../src/internal.ts", "../../../src/provider.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport * from '@dxos/web-context';\n\nexport * from './consumer';\nexport * from './provider';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useContext, useEffect, useState } from 'react';\n\nimport { ContextRequestEvent, type ContextType, type UnknownContext } from '@dxos/web-context';\n\nimport { HostElementContext } from './internal';\nimport { useContextRequestHandler } from './provider';\n\n/**\n * Options for useWebComponentContext hook\n */\nexport interface UseWebComponentContextOptions {\n /**\n * Whether to subscribe to context updates.\n * If true, the returned value will update when the provider's value changes.\n * Default: false\n */\n subscribe?: boolean;\n\n /**\n * The element to dispatch the context-request event from.\n * This is only used when there's no React provider in the tree.\n * Default: document.body\n */\n element?: HTMLElement;\n}\n\n/**\n * A React hook that requests context using the Web Component Context Protocol.\n *\n * This first tries to use the React context chain (for providers in the same\n * React tree), then falls back to dispatching a DOM event (for web component\n * providers).\n *\n * @param context - The context key to request\n * @param options - Optional configuration\n * @returns The context value or undefined\n */\nexport function useWebComponentContext<T extends UnknownContext>(\n context: T,\n options?: UseWebComponentContextOptions,\n): ContextType<T> | undefined {\n const [value, setValue] = useState<ContextType<T> | undefined>(undefined);\n\n const handler = useContextRequestHandler();\n const hostElement = useContext(HostElementContext);\n\n useEffect(() => {\n let unsubscribeFn: (() => void) | undefined;\n\n const callback = (newValue: ContextType<T>, unsubscribe?: () => void) => {\n setValue(newValue);\n if (unsubscribe) {\n unsubscribeFn = unsubscribe;\n }\n };\n\n const targetElement = options?.element ?? hostElement ?? document.body;\n\n const event = new ContextRequestEvent(context, callback, {\n subscribe: options?.subscribe,\n target: targetElement,\n });\n\n let handled = false;\n if (handler) {\n handled = handler(event);\n }\n\n if (!handled) {\n targetElement.dispatchEvent(event);\n }\n\n return () => {\n unsubscribeFn?.();\n };\n }, [context, options?.subscribe, options?.element, handler, hostElement]);\n\n return value;\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { createContext } from 'react';\n\n/**\n * Internal React context for passing the host element to nested components.\n * This allows useWebComponentContext to dispatch events from the custom element.\n */\nexport const HostElementContext = createContext<HTMLElement | undefined>(undefined);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport React, {\n type JSX,\n type PropsWithChildren,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n} from 'react';\n\nimport {\n CONTEXT_PROVIDER_EVENT,\n CONTEXT_REQUEST_EVENT,\n type ContextCallback,\n ContextProviderEvent,\n ContextRequestEvent,\n type ContextType,\n type UnknownContext,\n} from '@dxos/web-context';\n\n/**\n * Handler function type for context requests passed via React context\n */\ntype ContextRequestHandler = (event: ContextRequestEvent<UnknownContext>) => boolean;\n\n/**\n * Internal React context for passing context request handlers down the tree.\n * This allows useWebComponentContext to work synchronously in React.\n */\nconst ContextRequestHandlerContext = createContext<ContextRequestHandler | undefined>(undefined);\n\n/**\n * Try to handle a context request using the React context chain.\n * Returns true if handled, false otherwise.\n * Used internally by useWebComponentContext.\n */\nexport function tryHandleContextRequest(event: ContextRequestEvent<UnknownContext>): boolean {\n // This function is intended to be used where useContext is invalid (outside component),\n // but context handling in React MUST happen inside components.\n // So this helper might be less useful in React than in Solid if not used inside a hook/component.\n // However, we can export the context itself for consumers to use `useContext`.\n return false;\n}\n\n/**\n * Get the context request handler from React context.\n * Used internally by useWebComponentContext.\n */\nexport function useContextRequestHandler(): ContextRequestHandler | undefined {\n return useContext(ContextRequestHandlerContext);\n}\n\n/**\n * Props for the ContextProtocolProvider component\n */\nexport interface ContextProtocolProviderProps<T extends UnknownContext> {\n /** The context key to provide */\n context: T;\n /** The value to provide */\n value: ContextType<T>;\n}\n\n/**\n * A provider component that:\n * 1. Handles context-request events from web components (via DOM events)\n * 2. Handles context requests from React consumers (via React context)\n * 3. Supports subscriptions for reactive updates\n * 4. Uses WeakRef for subscriptions to prevent memory leaks\n */\nexport const ContextProtocolProvider = <T extends UnknownContext>({\n context,\n value,\n children,\n}: PropsWithChildren<ContextProtocolProviderProps<T>>): JSX.Element => {\n // Get parent handler if one exists (for nested providers)\n const parentHandler = useContext(ContextRequestHandlerContext);\n\n // Track subscriptions with their stable unsubscribe functions and consumer host elements\n interface SubscriptionInfo {\n unsubscribe: () => void;\n consumerHost: Element;\n ref: WeakRef<ContextCallback<ContextType<T>>>;\n }\n\n // We use refs for mutable state that doesn't trigger re-renders\n const subscriptions = useRef(new WeakMap<ContextCallback<ContextType<T>>, SubscriptionInfo>()).current;\n const subscriptionRefs = useRef(new Set<WeakRef<ContextCallback<ContextType<T>>>>()).current;\n const valueRef = useRef(value);\n\n // Update value ref when prop changes\n useEffect(() => {\n valueRef.current = value;\n }, [value]);\n\n // Core handler logic\n const handleRequest = useCallback(\n (event: ContextRequestEvent<UnknownContext>): boolean => {\n if (event.context !== context) {\n if (parentHandler) {\n return parentHandler(event);\n }\n return false;\n }\n\n const currentValue = valueRef.current; // Use latest value\n\n if (event.subscribe) {\n const callback = event.callback as ContextCallback<ContextType<T>>;\n const consumerHost = event.contextTarget || (event.composedPath()[0] as Element);\n\n const unsubscribe = () => {\n const info = subscriptions.get(callback);\n if (info) {\n subscriptionRefs.delete(info.ref);\n subscriptions.delete(callback);\n }\n };\n\n const ref = new WeakRef(callback);\n subscriptions.set(callback, { unsubscribe, consumerHost, ref });\n subscriptionRefs.add(ref);\n\n event.callback(currentValue, unsubscribe);\n } else {\n event.callback(currentValue);\n }\n\n return true;\n },\n [context, parentHandler], // Dependencies\n );\n\n // Handle DOM context-request events\n const handleContextRequestEvent = useCallback(\n (e: Event) => {\n const event = e as ContextRequestEvent<UnknownContext>;\n if (handleRequest(event)) {\n event.stopImmediatePropagation();\n }\n },\n [handleRequest],\n );\n\n // Handle context-provider events\n const handleContextProviderEvent = useCallback(\n (e: Event) => {\n const event = e as ContextProviderEvent<UnknownContext>;\n if (event.context !== context) return;\n if (containerRef.current && event.contextTarget === containerRef.current) return;\n\n const seen = new Set<ContextCallback<ContextType<T>>>();\n for (const ref of subscriptionRefs) {\n const callback = ref.deref();\n if (!callback) {\n subscriptionRefs.delete(ref);\n continue;\n }\n\n const info = subscriptions.get(callback);\n if (!info) continue;\n\n if (seen.has(callback)) continue;\n seen.add(callback);\n\n info.consumerHost.dispatchEvent(\n new ContextRequestEvent(context, callback, { subscribe: true, target: info.consumerHost }),\n );\n }\n event.stopPropagation();\n },\n [context],\n );\n\n // Notify subscribers when value changes.\n useEffect(() => {\n // Skip notification if value hasn't changed? React does this for us if we use dependencies correctly?\n // No, we need to imperatively call callbacks.\n // value constraint is in the dependency array.\n\n for (const ref of subscriptionRefs) {\n const callback = ref.deref();\n if (!callback) {\n subscriptionRefs.delete(ref);\n continue;\n }\n const info = subscriptions.get(callback);\n if (info) {\n callback(value, info.unsubscribe);\n }\n }\n }, [value]);\n\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return;\n\n el.addEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);\n el.addEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);\n\n // Announce provider.\n el.dispatchEvent(new ContextProviderEvent(context, el));\n\n return () => {\n el.removeEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);\n el.removeEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);\n subscriptionRefs.clear();\n };\n }, [handleContextRequestEvent, handleContextProviderEvent, context]);\n\n return (\n <ContextRequestHandlerContext.Provider value={handleRequest}>\n <div role='none' className='contents' ref={containerRef}>\n {children}\n </div>\n </ContextRequestHandlerContext.Provider>\n );\n};\n"],
|
|
5
|
-
"mappings": ";;;AAIA,cAAc;;;ACAd,SAASA,cAAAA,aAAYC,aAAAA,YAAWC,gBAAgB;AAEhD,SAASC,uBAAAA,4BAAkE;;;ACF3E,SAASC,qBAAqB;AAMvB,IAAMC,
|
|
6
|
-
"names": ["useContext", "useEffect", "useState", "ContextRequestEvent", "createContext", "HostElementContext", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport * from '@dxos/web-context';\n\nexport * from './consumer';\nexport * from './provider';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useContext, useEffect, useState } from 'react';\n\nimport { ContextRequestEvent, type ContextType, type UnknownContext } from '@dxos/web-context';\n\nimport { HostElementContext } from './internal';\nimport { useContextRequestHandler } from './provider';\n\n/**\n * Options for useWebComponentContext hook\n */\nexport interface UseWebComponentContextOptions {\n /**\n * Whether to subscribe to context updates.\n * If true, the returned value will update when the provider's value changes.\n * Default: false\n */\n subscribe?: boolean;\n\n /**\n * The element to dispatch the context-request event from.\n * This is only used when there's no React provider in the tree.\n * Default: document.body\n */\n element?: HTMLElement;\n}\n\n/**\n * A React hook that requests context using the Web Component Context Protocol.\n *\n * This first tries to use the React context chain (for providers in the same\n * React tree), then falls back to dispatching a DOM event (for web component\n * providers).\n *\n * @param context - The context key to request\n * @param options - Optional configuration\n * @returns The context value or undefined\n */\nexport function useWebComponentContext<T extends UnknownContext>(\n context: T,\n options?: UseWebComponentContextOptions,\n): ContextType<T> | undefined {\n const [value, setValue] = useState<ContextType<T> | undefined>(undefined);\n\n const handler = useContextRequestHandler();\n const hostElement = useContext(HostElementContext);\n\n useEffect(() => {\n let unsubscribeFn: (() => void) | undefined;\n\n const callback = (newValue: ContextType<T>, unsubscribe?: () => void) => {\n setValue(newValue);\n if (unsubscribe) {\n unsubscribeFn = unsubscribe;\n }\n };\n\n const targetElement = options?.element ?? hostElement ?? document.body;\n\n const event = new ContextRequestEvent(context, callback, {\n subscribe: options?.subscribe,\n target: targetElement,\n });\n\n let handled = false;\n if (handler) {\n handled = handler(event);\n }\n\n if (!handled) {\n targetElement.dispatchEvent(event);\n }\n\n return () => {\n unsubscribeFn?.();\n };\n }, [context, options?.subscribe, options?.element, handler, hostElement]);\n\n return value;\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { createContext } from 'react';\n\n/**\n * Internal React context for passing the host element to nested components.\n * This allows useWebComponentContext to dispatch events from the custom element.\n */\nexport const HostElementContext = createContext<HTMLElement | undefined>(undefined);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport React, {\n type JSX,\n type PropsWithChildren,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n} from 'react';\n\nimport {\n CONTEXT_PROVIDER_EVENT,\n CONTEXT_REQUEST_EVENT,\n type ContextCallback,\n ContextProviderEvent,\n ContextRequestEvent,\n type ContextType,\n type UnknownContext,\n} from '@dxos/web-context';\n\n/**\n * Handler function type for context requests passed via React context\n */\ntype ContextRequestHandler = (event: ContextRequestEvent<UnknownContext>) => boolean;\n\n/**\n * Internal React context for passing context request handlers down the tree.\n * This allows useWebComponentContext to work synchronously in React.\n */\nconst ContextRequestHandlerContext = createContext<ContextRequestHandler | undefined>(undefined);\n\n/**\n * Try to handle a context request using the React context chain.\n * Returns true if handled, false otherwise.\n * Used internally by useWebComponentContext.\n */\nexport function tryHandleContextRequest(event: ContextRequestEvent<UnknownContext>): boolean {\n // This function is intended to be used where useContext is invalid (outside component),\n // but context handling in React MUST happen inside components.\n // So this helper might be less useful in React than in Solid if not used inside a hook/component.\n // However, we can export the context itself for consumers to use `useContext`.\n return false;\n}\n\n/**\n * Get the context request handler from React context.\n * Used internally by useWebComponentContext.\n */\nexport function useContextRequestHandler(): ContextRequestHandler | undefined {\n return useContext(ContextRequestHandlerContext);\n}\n\n/**\n * Props for the ContextProtocolProvider component\n */\nexport interface ContextProtocolProviderProps<T extends UnknownContext> {\n /** The context key to provide */\n context: T;\n /** The value to provide */\n value: ContextType<T>;\n}\n\n/**\n * A provider component that:\n * 1. Handles context-request events from web components (via DOM events)\n * 2. Handles context requests from React consumers (via React context)\n * 3. Supports subscriptions for reactive updates\n * 4. Uses WeakRef for subscriptions to prevent memory leaks\n */\nexport const ContextProtocolProvider = <T extends UnknownContext>({\n context,\n value,\n children,\n}: PropsWithChildren<ContextProtocolProviderProps<T>>): JSX.Element => {\n // Get parent handler if one exists (for nested providers)\n const parentHandler = useContext(ContextRequestHandlerContext);\n\n // Track subscriptions with their stable unsubscribe functions and consumer host elements\n interface SubscriptionInfo {\n unsubscribe: () => void;\n consumerHost: Element;\n ref: WeakRef<ContextCallback<ContextType<T>>>;\n }\n\n // We use refs for mutable state that doesn't trigger re-renders\n const subscriptions = useRef(new WeakMap<ContextCallback<ContextType<T>>, SubscriptionInfo>()).current;\n const subscriptionRefs = useRef(new Set<WeakRef<ContextCallback<ContextType<T>>>>()).current;\n const valueRef = useRef(value);\n\n // Update value ref when prop changes\n useEffect(() => {\n valueRef.current = value;\n }, [value]);\n\n // Core handler logic\n const handleRequest = useCallback(\n (event: ContextRequestEvent<UnknownContext>): boolean => {\n if (event.context !== context) {\n if (parentHandler) {\n return parentHandler(event);\n }\n return false;\n }\n\n const currentValue = valueRef.current; // Use latest value\n\n if (event.subscribe) {\n const callback = event.callback as ContextCallback<ContextType<T>>;\n const consumerHost = event.contextTarget || (event.composedPath()[0] as Element);\n\n const unsubscribe = () => {\n const info = subscriptions.get(callback);\n if (info) {\n subscriptionRefs.delete(info.ref);\n subscriptions.delete(callback);\n }\n };\n\n const ref = new WeakRef(callback);\n subscriptions.set(callback, { unsubscribe, consumerHost, ref });\n subscriptionRefs.add(ref);\n\n event.callback(currentValue, unsubscribe);\n } else {\n event.callback(currentValue);\n }\n\n return true;\n },\n [context, parentHandler], // Dependencies\n );\n\n // Handle DOM context-request events\n const handleContextRequestEvent = useCallback(\n (e: Event) => {\n const event = e as ContextRequestEvent<UnknownContext>;\n if (handleRequest(event)) {\n event.stopImmediatePropagation();\n }\n },\n [handleRequest],\n );\n\n // Handle context-provider events\n const handleContextProviderEvent = useCallback(\n (e: Event) => {\n const event = e as ContextProviderEvent<UnknownContext>;\n if (event.context !== context) {\n return;\n }\n if (containerRef.current && event.contextTarget === containerRef.current) {\n return;\n }\n\n const seen = new Set<ContextCallback<ContextType<T>>>();\n for (const ref of subscriptionRefs) {\n const callback = ref.deref();\n if (!callback) {\n subscriptionRefs.delete(ref);\n continue;\n }\n\n const info = subscriptions.get(callback);\n if (!info) {\n continue;\n }\n\n if (seen.has(callback)) {\n continue;\n }\n seen.add(callback);\n\n info.consumerHost.dispatchEvent(\n new ContextRequestEvent(context, callback, { subscribe: true, target: info.consumerHost }),\n );\n }\n event.stopPropagation();\n },\n [context],\n );\n\n // Notify subscribers when value changes.\n useEffect(() => {\n // Skip notification if value hasn't changed? React does this for us if we use dependencies correctly?\n // No, we need to imperatively call callbacks.\n // value constraint is in the dependency array.\n\n for (const ref of subscriptionRefs) {\n const callback = ref.deref();\n if (!callback) {\n subscriptionRefs.delete(ref);\n continue;\n }\n const info = subscriptions.get(callback);\n if (info) {\n callback(value, info.unsubscribe);\n }\n }\n }, [value]);\n\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const el = containerRef.current;\n if (!el) {\n return;\n }\n\n el.addEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);\n el.addEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);\n\n // Announce provider.\n el.dispatchEvent(new ContextProviderEvent(context, el));\n\n return () => {\n el.removeEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);\n el.removeEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);\n subscriptionRefs.clear();\n };\n }, [handleContextRequestEvent, handleContextProviderEvent, context]);\n\n return (\n <ContextRequestHandlerContext.Provider value={handleRequest}>\n <div className='contents' ref={containerRef}>\n {children}\n </div>\n </ContextRequestHandlerContext.Provider>\n );\n};\n"],
|
|
5
|
+
"mappings": ";;;AAIA,cAAc;;;ACAd,SAASA,cAAAA,aAAYC,aAAAA,YAAWC,gBAAgB;AAEhD,SAASC,uBAAAA,4BAAkE;;;ACF3E,SAASC,qBAAqB;AAMvB,IAAMC,qBAAqBD,cAAuCE,MAAAA;;;ACNzE,OAAOC,SAGLC,iBAAAA,gBACAC,aACAC,YACAC,WACAC,cACK;AAEP,SACEC,wBACAC,uBAEAC,sBACAC,2BAGK;AAWP,IAAMC,+BAA+BT,gBAAAA,eAAiDU,MAAAA;AAO/E,SAASC,wBAAwBC,OAA0C;AAKhF,SAAO;AACT;AAMO,SAASC,2BAAAA;AACd,SAAOX,WAAWO,4BAAAA;AACpB;AAmBO,IAAMK,0BAA0B,CAA2B,EAChEC,SACAC,OACAC,SAAQ,MAC2C;AAEnD,QAAMC,gBAAgBhB,WAAWO,4B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/CrB,uBAAiBgC,MAAK;IACxB;EACF,GAAG;IAACd;IAA2BG;IAA4B5B;GAAQ;AAEnE,SACE,sBAAA,cAACN,6BAA6B8C,UAAQ;IAACvC,OAAOS;KAC5C,sBAAA,cAAC+B,OAAAA;IAAIC,WAAU;IAAWrB,KAAKQ;KAC5B3B,QAAAA,CAAAA;AAIT;;;AF/LO,SAASyC,uBACdC,SACAC,SAAuC;AAEvC,QAAM,CAACC,OAAOC,QAAAA,IAAYC,SAAqCC,MAAAA;AAE/D,QAAMC,UAAUC,yBAAAA;AAChB,QAAMC,cAAcC,YAAWC,kBAAAA;AAE/BC,EAAAA,WAAU,MAAA;AACR,QAAIC;AAEJ,UAAMC,WAAW,CAACC,UAA0BC,gBAAAA;AAC1CZ,eAASW,QAAAA;AACT,UAAIC,aAAa;AACfH,wBAAgBG;MAClB;IACF;AAEA,UAAMC,gBAAgBf,SAASgB,WAAWT,eAAeU,SAASC;AAElE,UAAMC,QAAQ,IAAIC,qBAAoBrB,SAASa,UAAU;MACvDS,WAAWrB,SAASqB;MACpBC,QAAQP;IACV,CAAA;AAEA,QAAIQ,UAAU;AACd,QAAIlB,SAAS;AACXkB,gBAAUlB,QAAQc,KAAAA;IACpB;AAEA,QAAI,CAACI,SAAS;AACZR,oBAAcS,cAAcL,KAAAA;IAC9B;AAEA,WAAO,MAAA;AACLR,sBAAAA;IACF;EACF,GAAG;IAACZ;IAASC,SAASqB;IAAWrB,SAASgB;IAASX;IAASE;GAAY;AAExE,SAAON;AACT;",
|
|
6
|
+
"names": ["useContext", "useEffect", "useState", "ContextRequestEvent", "createContext", "HostElementContext", "undefined", "React", "createContext", "useCallback", "useContext", "useEffect", "useRef", "CONTEXT_PROVIDER_EVENT", "CONTEXT_REQUEST_EVENT", "ContextProviderEvent", "ContextRequestEvent", "ContextRequestHandlerContext", "undefined", "tryHandleContextRequest", "event", "useContextRequestHandler", "ContextProtocolProvider", "context", "value", "children", "parentHandler", "subscriptions", "WeakMap", "current", "subscriptionRefs", "Set", "valueRef", "handleRequest", "currentValue", "subscribe", "callback", "consumerHost", "contextTarget", "composedPath", "unsubscribe", "info", "get", "delete", "ref", "WeakRef", "set", "add", "handleContextRequestEvent", "e", "stopImmediatePropagation", "handleContextProviderEvent", "containerRef", "seen", "deref", "has", "dispatchEvent", "target", "stopPropagation", "el", "addEventListener", "removeEventListener", "clear", "Provider", "div", "className", "useWebComponentContext", "context", "options", "value", "setValue", "useState", "undefined", "handler", "useContextRequestHandler", "hostElement", "useContext", "HostElementContext", "useEffect", "unsubscribeFn", "callback", "newValue", "unsubscribe", "targetElement", "element", "document", "body", "event", "ContextRequestEvent", "subscribe", "target", "handled", "dispatchEvent"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/internal.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/internal.ts":{"bytes":1122,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"src/provider.tsx":{"bytes":21018,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true}],"format":"esm"},"src/consumer.ts":{"bytes":6500,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true},{"path":"src/internal.ts","kind":"import-statement","original":"./internal"},{"path":"src/provider.tsx","kind":"import-statement","original":"./provider"}],"format":"esm"},"src/index.ts":{"bytes":575,"imports":[{"path":"@dxos/web-context","kind":"import-statement","external":true},{"path":"src/consumer.ts","kind":"import-statement","original":"./consumer"},{"path":"src/provider.tsx","kind":"import-statement","original":"./provider"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15046},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/web-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true}],"exports":["ContextProtocolProvider","tryHandleContextRequest","useContextRequestHandler","useWebComponentContext"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":35},"src/consumer.ts":{"bytesInOutput":1096},"src/internal.ts":{"bytesInOutput":87},"src/provider.tsx":{"bytesInOutput":3991}},"bytes":5553}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/provider.tsx"],"names":[],"mappings":"AAIA,OAAc,EACZ,KAAK,GAAG,EACR,KAAK,iBAAiB,EAMvB,MAAM,OAAO,CAAC;AAEf,OAAO,EAKL,mBAAmB,EACnB,KAAK,WAAW,EAChB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,KAAK,qBAAqB,GAAG,CAAC,KAAK,EAAE,mBAAmB,CAAC,cAAc,CAAC,KAAK,OAAO,CAAC;AAQrF;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,mBAAmB,CAAC,cAAc,CAAC,GAAG,OAAO,CAM3F;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,IAAI,qBAAqB,GAAG,SAAS,CAE5E;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B,CAAC,CAAC,SAAS,cAAc;IACpE,iCAAiC;IACjC,OAAO,EAAE,CAAC,CAAC;IACX,2BAA2B;IAC3B,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;CACvB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAAI,CAAC,SAAS,cAAc,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/provider.tsx"],"names":[],"mappings":"AAIA,OAAc,EACZ,KAAK,GAAG,EACR,KAAK,iBAAiB,EAMvB,MAAM,OAAO,CAAC;AAEf,OAAO,EAKL,mBAAmB,EACnB,KAAK,WAAW,EAChB,KAAK,cAAc,EACpB,MAA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