@dxos/web-context-react 0.8.4-main.9735255 → 0.8.4-main.ef1bc66f44

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.
@@ -130,10 +130,9 @@ var ContextProtocolProvider = ({ context, value, children }) => {
130
130
  return /* @__PURE__ */ React.createElement(ContextRequestHandlerContext.Provider, {
131
131
  value: handleRequest
132
132
  }, /* @__PURE__ */ React.createElement("div", {
133
- ref: containerRef,
134
- style: {
135
- display: "contents"
136
- }
133
+ role: "none",
134
+ className: "contents",
135
+ ref: containerRef
137
136
  }, children));
138
137
  };
139
138
 
@@ -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 ref={containerRef} style={{ display: 'contents' }}>\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,qBAAqBC,cAAuCC,MAAAA;;;ACNzE,OAAOC,SAGLC,iBAAAA,gBACAC,aACAC,YACAC,WACAC,cACK;AAEP,SACEC,wBACAC,uBAEAC,sBACAC,2BAGK;AAWP,IAAMC,+BAA+BC,gBAAAA,eAAiDC,MAAAA;AAO/E,SAASC,wBAAwBC,OAA0C;AAKhF,SAAO;AACT;AAMO,SAASC,2BAAAA;AACd,SAAOC,WAAWN,4BAAAA;AACpB;AAmBO,IAAMO,0BAA0B,CAA2B,EAChEC,SACAC,OACAC,SAAQ,MAC2C;AAEnD,QAAMC,gBAAgBL,WAAWN,4BAAAA;AAUjC,QAAMY,gBAAgBC,OAAO,oBAAIC,QAAAA,CAAAA,EAA8DC;AAC/F,QAAMC,mBAAmBH,OAAO,oBAAII,IAAAA,CAAAA,EAAiDF;AACrF,QAAMG,WAAWL,OAAOJ,KAAAA;AAGxBU,YAAU,MAAA;AACRD,aAASH,UAAUN;EACrB,GAAG;IAACA;GAAM;AAGV,QAAMW,gBAAgBC,YACpB,CAACjB,UAAAA;AACC,QAAIA,MAAMI,YAAYA,SAAS;AAC7B,UAAIG,eAAe;AACjB,eAAOA,cAAcP,KAAAA;MACvB;AACA,aAAO;IACT;AAEA,UAAMkB,eAAeJ,SAASH;AAE9B,QAAIX,MAAMmB,WAAW;AACnB,YAAMC,WAAWpB,MAAMoB;AACvB,YAAMC,eAAerB,MAAMsB,iBA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;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", "createContext", "undefined", "React", "createContext", "useCallback", "useContext", "useEffect", "useRef", "CONTEXT_PROVIDER_EVENT", "CONTEXT_REQUEST_EVENT", "ContextProviderEvent", "ContextRequestEvent", "ContextRequestHandlerContext", "createContext", "undefined", "tryHandleContextRequest", "event", "useContextRequestHandler", "useContext", "ContextProtocolProvider", "context", "value", "children", "parentHandler", "subscriptions", "useRef", "WeakMap", "current", "subscriptionRefs", "Set", "valueRef", "useEffect", "handleRequest", "useCallback", "currentValue", "subscribe", "callback", "consumerHost", "contextTarget", "composedPath", "unsubscribe", "info", "get", "delete", "ref", "WeakRef", "set", "add", "handleContextRequestEvent", "e", "stopImmediatePropagation", "handleContextProviderEvent", "containerRef", "seen", "deref", "has", "dispatchEvent", "ContextRequestEvent", "target", "stopPropagation", "el", "addEventListener", "CONTEXT_REQUEST_EVENT", "CONTEXT_PROVIDER_EVENT", "ContextProviderEvent", "removeEventListener", "clear", "Provider", "div", "style", "display", "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"]
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,qBAAqBC,cAAuCC,MAAAA;;;ACNzE,OAAOC,SAGLC,iBAAAA,gBACAC,aACAC,YACAC,WACAC,cACK;AAEP,SACEC,wBACAC,uBAEAC,sBACAC,2BAGK;AAW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E,wBAAwBZ,0BAAAA;AAG5CS,OAAGJ,cAAc,IAAIQ,qBAAqB5C,SAASwC,EAAAA,CAAAA;AAEnD,WAAO,MAAA;AACLA,SAAGK,oBAAoBH,uBAAuBd,yBAAAA;AAC9CY,SAAGK,oBAAoBF,wBAAwBZ,0BAAAA;AAC/CvB,uBAAiBsC,MAAK;IACxB;EACF,GAAG;IAAClB;IAA2BG;IAA4B/B;GAAQ;AAEnE,SACE,sBAAA,cAACR,6BAA6BuD,UAAQ;IAAC9C,OAAOW;KAC5C,sBAAA,cAACoC,OAAAA;IAAIC,MAAK;IAAOC,WAAU;IAAW1B,KAAKQ;KACxC9B,QAAAA,CAAAA;AAIT;;;AFrLO,SAASiD,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", "createContext", "undefined", "React", "createContext", "useCallback", "useContext", "useEffect", "useRef", "CONTEXT_PROVIDER_EVENT", "CONTEXT_REQUEST_EVENT", "ContextProviderEvent", "ContextRequestEvent", "ContextRequestHandlerContext", "createContext", "undefined", "tryHandleContextRequest", "event", "useContextRequestHandler", "useContext", "ContextProtocolProvider", "context", "value", "children", "parentHandler", "subscriptions", "useRef", "WeakMap", "current", "subscriptionRefs", "Set", "valueRef", "useEffect", "handleRequest", "useCallback", "currentValue", "subscribe", "callback", "consumerHost", "contextTarget", "composedPath", "unsubscribe", "info", "get", "delete", "ref", "WeakRef", "set", "add", "handleContextRequestEvent", "e", "stopImmediatePropagation", "handleContextProviderEvent", "containerRef", "seen", "deref", "has", "dispatchEvent", "ContextRequestEvent", "target", "stopPropagation", "el", "addEventListener", "CONTEXT_REQUEST_EVENT", "CONTEXT_PROVIDER_EVENT", "ContextProviderEvent", "removeEventListener", "clear", "Provider", "div", "role", "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":1209,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"src/provider.tsx":{"bytes":20828,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true}],"format":"esm"},"src/consumer.ts":{"bytes":6591,"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":659,"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":15104},"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":3932}},"bytes":5401}}}
1
+ {"inputs":{"src/internal.ts":{"bytes":1209,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"src/provider.tsx":{"bytes":20824,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true}],"format":"esm"},"src/consumer.ts":{"bytes":6591,"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":659,"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":15103},"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":3931}},"bytes":5400}}}
@@ -132,10 +132,9 @@ var ContextProtocolProvider = ({ context, value, children }) => {
132
132
  return /* @__PURE__ */ React.createElement(ContextRequestHandlerContext.Provider, {
133
133
  value: handleRequest
134
134
  }, /* @__PURE__ */ React.createElement("div", {
135
- ref: containerRef,
136
- style: {
137
- display: "contents"
138
- }
135
+ role: "none",
136
+ className: "contents",
137
+ ref: containerRef
139
138
  }, children));
140
139
  };
141
140
 
@@ -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 ref={containerRef} style={{ display: 'contents' }}>\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,qBAAqBC,cAAuCC,MAAAA;;;ACNzE,OAAOC,SAGLC,iBAAAA,gBACAC,aACAC,YACAC,WACAC,cACK;AAEP,SACEC,wBACAC,uBAEAC,sBACAC,2BAGK;AAWP,IAAMC,+BAA+BC,gBAAAA,eAAiDC,MAAAA;AAO/E,SAASC,wBAAwBC,OAA0C;AAKhF,SAAO;AACT;AAMO,SAASC,2BAAAA;AACd,SAAOC,WAAWN,4BAAAA;AACpB;AAmBO,IAAMO,0BAA0B,CAA2B,EAChEC,SACAC,OACAC,SAAQ,MAC2C;AAEnD,QAAMC,gBAAgBL,WAAWN,4BAAAA;AAUjC,QAAMY,gBAAgBC,OAAO,oBAAIC,QAAAA,CAAAA,EAA8DC;AAC/F,QAAMC,mBAAmBH,OAAO,oBAAII,IAAAA,CAAAA,EAAiDF;AACrF,QAAMG,WAAWL,OAAOJ,KAAAA;AAGxBU,YAAU,MAAA;AACRD,aAASH,UAAUN;EACrB,GAAG;IAACA;GAAM;AAGV,QAAMW,gBAAgBC,YACpB,CAACjB,UAAAA;AACC,QAAIA,MAAMI,YAAYA,SAAS;AAC7B,UAAIG,eAAe;AACjB,eAAOA,cAAcP,KAAAA;MACvB;AACA,aAAO;IACT;AAEA,UAAMkB,eAAeJ,SAASH;AAE9B,QAAIX,MAAMmB,WAAW;A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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", "createContext", "undefined", "React", "createContext", "useCallback", "useContext", "useEffect", "useRef", "CONTEXT_PROVIDER_EVENT", "CONTEXT_REQUEST_EVENT", "ContextProviderEvent", "ContextRequestEvent", "ContextRequestHandlerContext", "createContext", "undefined", "tryHandleContextRequest", "event", "useContextRequestHandler", "useContext", "ContextProtocolProvider", "context", "value", "children", "parentHandler", "subscriptions", "useRef", "WeakMap", "current", "subscriptionRefs", "Set", "valueRef", "useEffect", "handleRequest", "useCallback", "currentValue", "subscribe", "callback", "consumerHost", "contextTarget", "composedPath", "unsubscribe", "info", "get", "delete", "ref", "WeakRef", "set", "add", "handleContextRequestEvent", "e", "stopImmediatePropagation", "handleContextProviderEvent", "containerRef", "seen", "deref", "has", "dispatchEvent", "ContextRequestEvent", "target", "stopPropagation", "el", "addEventListener", "CONTEXT_REQUEST_EVENT", "CONTEXT_PROVIDER_EVENT", "ContextProviderEvent", "removeEventListener", "clear", "Provider", "div", "style", "display", "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"]
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,qBAAqBC,cAAuCC,MAAAA;;;ACNzE,OAAOC,SAGLC,iBAAAA,gBACAC,aACAC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useState", "ContextRequestEvent", "createContext", "HostElementContext", "createContext", "undefined", "React", "createContext", "useCallback", "useContext", "useEffect", "useRef", "CONTEXT_PROVIDER_EVENT", "CONTEXT_REQUEST_EVENT", "ContextProviderEvent", "ContextRequestEvent", "ContextRequestHandlerContext", "createContext", "undefined", "tryHandleContextRequest", "event", "useContextRequestHandler", "useContext", "ContextProtocolProvider", "context", "value", "children", "parentHandler", "subscriptions", "useRef", "WeakMap", "current", "subscriptionRefs", "Set", "valueRef", "useEffect", "handleRequest", "useCallback", "currentValue", "subscribe", "callback", "consumerHost", "contextTarget", "composedPath", "unsubscribe", "info", "get", "delete", "ref", "WeakRef", "set", "add", "handleContextRequestEvent", "e", "stopImmediatePropagation", "handleContextProviderEvent", "containerRef", "seen", "deref", "has", "dispatchEvent", "ContextRequestEvent", "target", "stopPropagation", "el", "addEventListener", "CONTEXT_REQUEST_EVENT", "CONTEXT_PROVIDER_EVENT", "ContextProviderEvent", "removeEventListener", "clear", "Provider", "div", "role", "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":1209,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"src/provider.tsx":{"bytes":20828,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true}],"format":"esm"},"src/consumer.ts":{"bytes":6591,"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":659,"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":15106},"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":3932}},"bytes":5494}}}
1
+ {"inputs":{"src/internal.ts":{"bytes":1209,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"src/provider.tsx":{"bytes":20824,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true}],"format":"esm"},"src/consumer.ts":{"bytes":6591,"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":659,"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":15105},"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":3931}},"bytes":5493}}}