@dxos/web-context-solid 0.0.0 → 0.8.4-main.21d9917

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.
@@ -0,0 +1,203 @@
1
+ // src/index.ts
2
+ export * from "@dxos/web-context";
3
+
4
+ // src/consumer.ts
5
+ import { createSignal, onCleanup as onCleanup2 } from "solid-js";
6
+ import { ContextRequestEvent as ContextRequestEvent2 } from "@dxos/web-context";
7
+
8
+ // src/internal.ts
9
+ import { createContext as createSolidContext, useContext } from "solid-js";
10
+ var HostElementContext = createSolidContext();
11
+ function getHostElement() {
12
+ return useContext(HostElementContext);
13
+ }
14
+
15
+ // src/provider.tsx
16
+ import { jsx as _jsx } from "solid-js/jsx-runtime";
17
+ import { createEffect, createContext as createSolidContext2, onCleanup, onMount, useContext as useContext2 } from "solid-js";
18
+ import { CONTEXT_PROVIDER_EVENT, CONTEXT_REQUEST_EVENT, ContextProviderEvent, ContextRequestEvent } from "@dxos/web-context";
19
+ var ContextRequestHandlerContext = createSolidContext2();
20
+ function tryHandleContextRequest(event) {
21
+ const handler = useContext2(ContextRequestHandlerContext);
22
+ if (handler) {
23
+ return handler(event);
24
+ }
25
+ return false;
26
+ }
27
+ function getContextRequestHandler() {
28
+ return useContext2(ContextRequestHandlerContext);
29
+ }
30
+ function ContextProtocolProvider(props) {
31
+ const parentHandler = useContext2(ContextRequestHandlerContext);
32
+ const subscriptions = /* @__PURE__ */ new WeakMap();
33
+ const subscriptionRefs = /* @__PURE__ */ new Set();
34
+ const getValue = () => {
35
+ const v = props.value;
36
+ return typeof v === "function" ? v() : v;
37
+ };
38
+ const handleRequest = (event) => {
39
+ if (event.context !== props.context) {
40
+ if (parentHandler) {
41
+ return parentHandler(event);
42
+ }
43
+ return false;
44
+ }
45
+ const currentValue = getValue();
46
+ if (event.subscribe) {
47
+ const callback = event.callback;
48
+ const consumerHost = event.contextTarget || event.composedPath()[0];
49
+ const unsubscribe = () => {
50
+ const info = subscriptions.get(callback);
51
+ if (info) {
52
+ subscriptionRefs.delete(info.ref);
53
+ subscriptions.delete(callback);
54
+ }
55
+ };
56
+ const ref = new WeakRef(callback);
57
+ subscriptions.set(callback, {
58
+ unsubscribe,
59
+ consumerHost,
60
+ ref
61
+ });
62
+ subscriptionRefs.add(ref);
63
+ event.callback(currentValue, unsubscribe);
64
+ } else {
65
+ event.callback(currentValue);
66
+ }
67
+ return true;
68
+ };
69
+ const handleContextRequestEvent = (e) => {
70
+ const event = e;
71
+ if (handleRequest(event)) {
72
+ event.stopImmediatePropagation();
73
+ }
74
+ };
75
+ const handleContextProviderEvent = (e) => {
76
+ const event = e;
77
+ if (event.context !== props.context) {
78
+ return;
79
+ }
80
+ if (containerRef && event.contextTarget === containerRef) {
81
+ return;
82
+ }
83
+ const seen = /* @__PURE__ */ new Set();
84
+ for (const ref of subscriptionRefs) {
85
+ const callback = ref.deref();
86
+ if (!callback) {
87
+ subscriptionRefs.delete(ref);
88
+ continue;
89
+ }
90
+ const info = subscriptions.get(callback);
91
+ if (!info) continue;
92
+ const { consumerHost } = info;
93
+ if (seen.has(callback)) {
94
+ continue;
95
+ }
96
+ seen.add(callback);
97
+ consumerHost.dispatchEvent(new ContextRequestEvent(props.context, callback, {
98
+ subscribe: true,
99
+ target: consumerHost
100
+ }));
101
+ }
102
+ event.stopPropagation();
103
+ };
104
+ let isFirstRun = true;
105
+ createEffect(() => {
106
+ const v = props.value;
107
+ const newValue = typeof v === "function" ? v() : v;
108
+ if (isFirstRun) {
109
+ isFirstRun = false;
110
+ return;
111
+ }
112
+ for (const ref of subscriptionRefs) {
113
+ const callback = ref.deref();
114
+ if (!callback) {
115
+ subscriptionRefs.delete(ref);
116
+ continue;
117
+ }
118
+ const info = subscriptions.get(callback);
119
+ if (info) {
120
+ callback(newValue, info.unsubscribe);
121
+ }
122
+ }
123
+ });
124
+ let containerRef;
125
+ const setupListeners = (el) => {
126
+ containerRef = el;
127
+ el.addEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);
128
+ el.addEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);
129
+ };
130
+ onMount(() => {
131
+ if (containerRef) {
132
+ containerRef.dispatchEvent(new ContextProviderEvent(props.context, containerRef));
133
+ }
134
+ });
135
+ onCleanup(() => {
136
+ if (containerRef) {
137
+ containerRef.removeEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);
138
+ containerRef.removeEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);
139
+ }
140
+ subscriptionRefs.clear();
141
+ });
142
+ return /* @__PURE__ */ _jsx(ContextRequestHandlerContext.Provider, {
143
+ value: handleRequest,
144
+ children: /* @__PURE__ */ _jsx("div", {
145
+ ref: setupListeners,
146
+ style: {
147
+ display: "contents"
148
+ },
149
+ children: props.children
150
+ })
151
+ });
152
+ }
153
+
154
+ // src/consumer.ts
155
+ function useWebComponentContext(context, options) {
156
+ const [value, setValue] = createSignal(void 0);
157
+ let unsubscribeFn;
158
+ const callback = (newValue, unsubscribe) => {
159
+ setValue(() => newValue);
160
+ if (unsubscribe) {
161
+ unsubscribeFn = unsubscribe;
162
+ }
163
+ };
164
+ const hostElement = getHostElement();
165
+ const targetElement = options?.element ?? hostElement ?? document.body;
166
+ const event = new ContextRequestEvent2(context, callback, {
167
+ subscribe: options?.subscribe,
168
+ target: targetElement
169
+ });
170
+ const handler = getContextRequestHandler();
171
+ let handled = false;
172
+ if (handler) {
173
+ handled = handler(event);
174
+ }
175
+ if (!handled) {
176
+ targetElement.dispatchEvent(event);
177
+ }
178
+ onCleanup2(() => {
179
+ unsubscribeFn?.();
180
+ });
181
+ return value;
182
+ }
183
+
184
+ // src/solid-element.tsx
185
+ import { jsx as _jsx2 } from "solid-js/jsx-runtime";
186
+ function withContextProvider(component) {
187
+ const wrappedComponent = (props, options) => {
188
+ const WrappedContent = () => component(props, options);
189
+ return /* @__PURE__ */ _jsx2(HostElementContext.Provider, {
190
+ value: options.element,
191
+ children: /* @__PURE__ */ _jsx2(WrappedContent, {})
192
+ });
193
+ };
194
+ return wrappedComponent;
195
+ }
196
+ export {
197
+ ContextProtocolProvider,
198
+ getContextRequestHandler,
199
+ tryHandleContextRequest,
200
+ useWebComponentContext,
201
+ withContextProvider
202
+ };
203
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/index.ts", "../../../src/consumer.ts", "../../../src/internal.ts", "../../../src/provider.tsx", "../../../src/solid-element.tsx"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport * from '@dxos/web-context';\n\nexport * from './consumer';\nexport * from './provider';\nexport * from './solid-element';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Accessor, createSignal, onCleanup } from 'solid-js';\n\nimport { ContextRequestEvent, type ContextType, type UnknownContext } from '@dxos/web-context';\n\nimport { getHostElement } from './internal';\nimport { getContextRequestHandler } 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 signal 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 SolidJS provider in the tree.\n * Default: document.body\n */\n element?: HTMLElement;\n}\n\n/**\n * A SolidJS hook that requests context using the Web Component Context Protocol.\n *\n * This first tries to use the SolidJS context chain (for providers in the same\n * SolidJS 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 An accessor that returns the context value or undefined\n *\n * @example\n * ```tsx\n * const theme = useWebComponentContext(themeContext);\n * return <div style={{ color: theme()?.primary }}>Hello</div>;\n * ```\n *\n * @example\n * ```tsx\n * // Subscribe to updates\n * const theme = useWebComponentContext(themeContext, { subscribe: true });\n * return <div style={{ color: theme()?.primary }}>Hello</div>;\n * ```\n */\nexport function useWebComponentContext<T extends UnknownContext>(\n context: T,\n options?: UseWebComponentContextOptions,\n): Accessor<ContextType<T> | undefined> {\n const [value, setValue] = createSignal<ContextType<T> | undefined>(undefined);\n let unsubscribeFn: (() => void) | undefined;\n\n // Create callback that updates our signal\n const callback = (newValue: ContextType<T>, unsubscribe?: () => void): void => {\n setValue(() => newValue);\n // Store the latest unsubscribe function\n if (unsubscribe) {\n unsubscribeFn = unsubscribe;\n }\n };\n\n // Determine the target element for the context request\n // Use: 1) explicit element option, 2) host element from custom element context, 3) document.body\n const hostElement = getHostElement();\n const targetElement = options?.element ?? hostElement ?? document.body;\n\n // Create the context request event with contextTarget for proper re-parenting support\n const event = new ContextRequestEvent(context, callback, {\n subscribe: options?.subscribe,\n target: targetElement,\n });\n\n // First, try to handle via SolidJS context chain (synchronous)\n const handler = getContextRequestHandler();\n let handled = false;\n\n if (handler) {\n handled = handler(event);\n }\n\n // If not handled by SolidJS providers, try DOM event dispatch\n if (!handled) {\n targetElement.dispatchEvent(event);\n }\n\n // Cleanup: unsubscribe when component unmounts\n // Cleanup: unsubscribe when component unmounts\n onCleanup(() => {\n unsubscribeFn?.();\n });\n\n return value;\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { createContext as createSolidContext, useContext } from 'solid-js';\n\n/**\n * Internal SolidJS context for passing the host element to nested components.\n * This allows useWebComponentContext to dispatch events from the custom element.\n */\nexport const HostElementContext = createSolidContext<HTMLElement | undefined>();\n\n/**\n * Get the host custom element from SolidJS context.\n * Used internally by useWebComponentContext when called from a custom element.\n */\nexport function getHostElement(): HTMLElement | undefined {\n return useContext(HostElementContext);\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport {\n type Accessor,\n type JSX,\n createEffect,\n createContext as createSolidContext,\n onCleanup,\n onMount,\n useContext,\n} from 'solid-js';\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 SolidJS context\n */\ntype ContextRequestHandler = (event: ContextRequestEvent<UnknownContext>) => boolean;\n\n/**\n * Internal SolidJS context for passing context request handlers down the tree.\n * This allows useWebComponentContext to work synchronously in SolidJS.\n */\nconst ContextRequestHandlerContext = createSolidContext<ContextRequestHandler | undefined>();\n\n/**\n * Try to handle a context request using the SolidJS context chain.\n * Returns true if handled, false otherwise.\n * Used internally by useWebComponentContext.\n */\nexport function tryHandleContextRequest(event: ContextRequestEvent<UnknownContext>): boolean {\n const handler = useContext(ContextRequestHandlerContext);\n if (handler) {\n return handler(event);\n }\n return false;\n}\n\n/**\n * Get the context request handler from SolidJS context.\n * Used internally by useWebComponentContext.\n */\nexport function getContextRequestHandler(): 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 - can be a static value or an accessor for reactive updates */\n value: ContextType<T> | Accessor<ContextType<T>>;\n /** Child elements */\n children: JSX.Element;\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 SolidJS consumers (via SolidJS context)\n * 3. Supports subscriptions for reactive updates\n * 4. Uses WeakRef for subscriptions to prevent memory leaks\n */\nexport function ContextProtocolProvider<T extends UnknownContext>(props: 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 // We use WeakMap to hold callbacks weakly. This ensures that if a consumer\n // drops the callback, we don't leak memory.\n //\n // NOTE: This means consumers MUST retain the callback reference as long as they\n // want to receive updates (e.g. implicitly via closure in a retained component).\n interface SubscriptionInfo {\n unsubscribe: () => void;\n consumerHost: Element;\n // Store ref to allow cleaning up the Set when unsubscribing\n ref: WeakRef<ContextCallback<ContextType<T>>>;\n }\n const subscriptions = new WeakMap<ContextCallback<ContextType<T>>, SubscriptionInfo>();\n const subscriptionRefs = new Set<WeakRef<ContextCallback<ContextType<T>>>>();\n\n // Helper to get current value (handles both static and accessor)\n const getValue = (): ContextType<T> => {\n const v = props.value;\n return typeof v === 'function' ? (v as Accessor<ContextType<T>>)() : v;\n };\n\n // Core handler logic - used by both DOM events and SolidJS context\n const handleRequest = (event: ContextRequestEvent<UnknownContext>): boolean => {\n // Check if this provider handles this context (strict equality per spec)\n if (event.context !== props.context) {\n // Pass to parent handler if we don't handle this context\n if (parentHandler) {\n return parentHandler(event);\n }\n return false;\n }\n\n const currentValue = getValue();\n\n if (event.subscribe) {\n // Store the callback for future updates\n const callback = event.callback as ContextCallback<ContextType<T>>;\n\n // Get the consumer host element from the event\n // Fallback to composedPath()[0] if contextTarget is missing (standard compliance)\n const consumerHost = event.contextTarget || (event.composedPath()[0] as Element);\n\n // Create a stable unsubscribe function for this callback\n // IMPORTANT: We must pass the SAME unsubscribe function each time we call the callback\n // Lit's ContextConsumer compares unsubscribe functions and calls the old one if different\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 // Invoke callback with current value and unsubscribe function\n event.callback(currentValue, unsubscribe);\n } else {\n // One-time request - just provide the value\n event.callback(currentValue);\n }\n\n return true;\n };\n\n // Handle DOM context-request events (for web components)\n const handleContextRequestEvent = (e: Event) => {\n const event = e as ContextRequestEvent<UnknownContext>;\n if (handleRequest(event)) {\n // Stop propagation per spec recommendation\n event.stopImmediatePropagation();\n }\n };\n\n // Handle context-provider events from child providers\n // When a new provider appears below us, we re-dispatch our subscriptions\n // so consumers can re-parent to the closer provider\n const handleContextProviderEvent = (e: Event) => {\n const event = e as ContextProviderEvent<UnknownContext>;\n\n // Only handle events for our context\n if (event.context !== props.context) {\n return;\n }\n\n // Don't handle our own event\n if (containerRef && event.contextTarget === containerRef) {\n return;\n }\n\n // Re-dispatch context requests from our subscribers\n // They may now have a closer provider\n // Iterate over weak refs to re-dispatch\n // We use a separate Set of WeakRefs because WeakMap is not iterable.\n // This allows us to re-parent subscriptions when a new provider appears.\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 const { consumerHost } = info;\n\n // Prevent infinite loops with duplicate callbacks\n if (seen.has(callback)) {\n continue;\n }\n seen.add(callback);\n\n // Re-dispatch the context request from the consumer\n // We explicitly pass the original consumerHost as the target to preserve the causal chain\n consumerHost.dispatchEvent(\n new ContextRequestEvent(props.context, callback, { subscribe: true, target: consumerHost }),\n );\n }\n\n // Stop propagation - we've handled the re-parenting\n event.stopPropagation();\n };\n\n // Set up effect to notify subscribers when value changes\n let isFirstRun = true;\n createEffect(() => {\n // IMPORTANT: We must call the accessor DIRECTLY inside the effect to establish tracking\n // Reading props.value gives us the accessor, then we must call it to track the signal\n const v = props.value;\n const newValue = typeof v === 'function' ? (v as Accessor<ContextType<T>>)() : v;\n\n // Skip first run - only notify on changes after initial subscription\n if (isFirstRun) {\n isFirstRun = false;\n return;\n }\n\n // Notify all subscribers with their stable unsubscribe functions\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 callback(newValue, info.unsubscribe);\n }\n }\n });\n\n // Reference to container element for event listener\n let containerRef: HTMLDivElement | undefined;\n\n // Set up event listeners when element is created\n const setupListeners = (el: HTMLDivElement) => {\n containerRef = el;\n el.addEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);\n el.addEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);\n };\n\n // Announce this provider when mounted\n // This allows ContextRoot implementations to replay pending requests\n // and allows parent providers to re-parent their subscriptions\n onMount(() => {\n if (containerRef) {\n containerRef.dispatchEvent(new ContextProviderEvent(props.context, containerRef));\n }\n });\n\n // Cleanup on unmount\n onCleanup(() => {\n if (containerRef) {\n containerRef.removeEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);\n containerRef.removeEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);\n }\n // WeakMap clears itself, but we should clear the Set of refs\n subscriptionRefs.clear();\n });\n\n return (\n <ContextRequestHandlerContext.Provider value={handleRequest}>\n <div ref={setupListeners} style={{ display: 'contents' }}>\n {props.children}\n </div>\n </ContextRequestHandlerContext.Provider>\n );\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type { ComponentType } from 'solid-element';\nimport type { JSX } from 'solid-js';\n\nimport { HostElementContext } from './internal';\n\n/**\n * Integration utilities for using Web Component Context Protocol with solid-element.\n *\n * This module provides utilities to integrate our context protocol implementation\n * with the solid-element library for creating web components.\n *\n * @example\n * ```tsx\n * import { customElement } from 'solid-element';\n * import { withContextProvider } from './context/solid-element';\n *\n * customElement('my-button', {}, withContextProvider((props, { element }) => {\n * const theme = useWebComponentContext(themeContext, { subscribe: true });\n * return <button style={{ background: theme()?.primary }}>Click me</button>;\n * }));\n * ```\n */\n\n/**\n * Options passed by solid-element to component functions.\n * The element extends HTMLElement with additional custom element methods.\n */\nexport interface SolidElementOptions {\n element: HTMLElement & {\n renderRoot: Element | Document | ShadowRoot | DocumentFragment;\n addReleaseCallback(fn: () => void): void;\n addPropertyChangedCallback(fn: (name: string, value: unknown) => void): void;\n };\n}\n\n/**\n * Function component type for solid-element.\n * Receives props and an options object containing the host element.\n */\nexport type SolidElementComponent<P extends object = object> = (props: P, options: SolidElementOptions) => JSX.Element;\n\n/**\n * Wraps a solid-element component to provide the host element context.\n * This enables useWebComponentContext to dispatch events from the custom element\n * rather than document.body.\n *\n * @param component - The solid-element component function\n * @returns A wrapped component that provides HostElementContext\n *\n * @example\n * ```tsx\n * import { customElement } from 'solid-element';\n * import { withContextProvider, useWebComponentContext } from './context';\n *\n * customElement('themed-button', {}, withContextProvider((props, { element }) => {\n * const theme = useWebComponentContext(themeContext, { subscribe: true });\n * return (\n * <button style={{ background: theme()?.primary }}>\n * Themed Button\n * </button>\n * );\n * }));\n * ```\n */\nexport function withContextProvider<P extends object>(component: SolidElementComponent<P>): ComponentType<P> {\n // Return a new component function that wraps the original with HostElementContext\n // This enables useWebComponentContext to dispatch events from the custom element\n const wrappedComponent = (props: P, options: SolidElementOptions) => {\n // Create a child component that renders within the context\n const WrappedContent = () => component(props, options);\n\n return (\n <HostElementContext.Provider value={options.element}>\n <WrappedContent />\n </HostElementContext.Provider>\n );\n };\n\n return wrappedComponent as unknown as ComponentType<P>;\n}\n"],
5
+ "mappings": ";AAIA,cAAc;;;ACAd,SAAwBA,cAAcC,aAAAA,kBAAiB;AAEvD,SAASC,uBAAAA,4BAAkE;;;ACF3E,SAASC,iBAAiBC,oBAAoBC,kBAAkB;AAMzD,IAAMC,qBAAqBC,mBAAAA;AAM3B,SAASC,iBAAAA;AACd,SAAOC,WAAWH,kBAAAA;AACpB;;;;ACdA,SAGEI,cACAC,iBAAiBC,qBACjBC,WACAC,SACAC,cAAAA,mBACK;AAEP,SACEC,wBACAC,uBAEAC,sBACAC,2BAGK;AAWP,IAAMC,+BAA+BC,oBAAAA;AAO9B,SAASC,wBAAwBC,OAA0C;AAChF,QAAMC,UAAUC,YAAWL,4BAAAA;AAC3B,MAAII,SAAS;AACX,WAAOA,QAAQD,KAAAA;EACjB;AACA,SAAO;AACT;AAMO,SAASG,2BAAAA;AACd,SAAOD,YAAWL,4BAAAA;AACpB;AAqBO,SAASO,wBAAkDC,OAAsC;AAEtG,QAAMC,gBAAgBJ,YAAWL,4BAAAA;AAcjC,QAAMU,gBAAgB,oBAAIC,QAAAA;AAC1B,QAAMC,mBAAmB,oBAAIC,IAAAA;AAG7B,QAAMC,WAAW,MAAA;AACf,UAAMC,IAA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;AAEA,SACE,qBAACzD,6BAA6B0D,UAAQ;IAAC1C,OAAOC;cAC5C,qBAAC0C,OAAAA;MAAI9B,KAAKmB;MAAgBY,OAAO;QAAEC,SAAS;MAAW;gBACpDrD,MAAMsD;;;AAIf;;;AFzNO,SAASC,uBACdC,SACAC,SAAuC;AAEvC,QAAM,CAACC,OAAOC,QAAAA,IAAYC,aAAyCC,MAAAA;AACnE,MAAIC;AAGJ,QAAMC,WAAW,CAACC,UAA0BC,gBAAAA;AAC1CN,aAAS,MAAMK,QAAAA;AAEf,QAAIC,aAAa;AACfH,sBAAgBG;IAClB;EACF;AAIA,QAAMC,cAAcC,eAAAA;AACpB,QAAMC,gBAAgBX,SAASY,WAAWH,eAAeI,SAASC;AAGlE,QAAMC,QAAQ,IAAIC,qBAAoBjB,SAASO,UAAU;IACvDW,WAAWjB,SAASiB;IACpBC,QAAQP;EACV,CAAA;AAGA,QAAMQ,UAAUC,yBAAAA;AAChB,MAAIC,UAAU;AAEd,MAAIF,SAAS;AACXE,cAAUF,QAAQJ,KAAAA;EACpB;AAGA,MAAI,CAACM,SAAS;AACZV,kBAAcW,cAAcP,KAAAA;EAC9B;AAIAQ,EAAAA,WAAU,MAAA;AACRlB,oBAAAA;EACF,CAAA;AAEA,SAAOJ;AACT;A;;;AGjCO,SAASuB,oBAAsCC,WAAmC;AAGvF,QAAMC,mBAAmB,CAACC,OAAUC,YAAAA;AAElC,UAAMC,iBAAiB,MAAMJ,UAAUE,OAAOC,OAAAA;AAE9C,WACE,gBAAAE,MAACC,mBAAmBC,UAAQ;MAACC,OAAOL,QAAQM;gBAC1C,gBAAAJ,MAACD,gBAAAA,CAAAA,CAAAA;;EAGP;AAEA,SAAOH;AACT;",
6
+ "names": ["createSignal", "onCleanup", "ContextRequestEvent", "createContext", "createSolidContext", "useContext", "HostElementContext", "createSolidContext", "getHostElement", "useContext", "createEffect", "createContext", "createSolidContext", "onCleanup", "onMount", "useContext", "CONTEXT_PROVIDER_EVENT", "CONTEXT_REQUEST_EVENT", "ContextProviderEvent", "ContextRequestEvent", "ContextRequestHandlerContext", "createSolidContext", "tryHandleContextRequest", "event", "handler", "useContext", "getContextRequestHandler", "ContextProtocolProvider", "props", "parentHandler", "subscriptions", "WeakMap", "subscriptionRefs", "Set", "getValue", "v", "value", "handleRequest", "context", "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", "isFirstRun", "createEffect", "newValue", "setupListeners", "el", "addEventListener", "CONTEXT_REQUEST_EVENT", "CONTEXT_PROVIDER_EVENT", "onMount", "ContextProviderEvent", "onCleanup", "removeEventListener", "clear", "Provider", "div", "style", "display", "children", "useWebComponentContext", "context", "options", "value", "setValue", "createSignal", "undefined", "unsubscribeFn", "callback", "newValue", "unsubscribe", "hostElement", "getHostElement", "targetElement", "element", "document", "body", "event", "ContextRequestEvent", "subscribe", "target", "handler", "getContextRequestHandler", "handled", "dispatchEvent", "onCleanup", "withContextProvider", "component", "wrappedComponent", "props", "options", "WrappedContent", "_jsx", "HostElementContext", "Provider", "value", "element"]
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"src/internal.ts":{"bytes":1993,"imports":[{"path":"solid-js","kind":"import-statement","external":true}],"format":"esm"},"src/provider.tsx":{"bytes":26875,"imports":[{"path":"solid-js/jsx-runtime","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true}],"format":"esm"},"src/consumer.ts":{"bytes":8500,"imports":[{"path":"solid-js","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/solid-element.tsx":{"bytes":6420,"imports":[{"path":"solid-js/jsx-runtime","kind":"import-statement","external":true},{"path":"src/internal.ts","kind":"import-statement","original":"./internal"}],"format":"esm"},"src/index.ts":{"bytes":760,"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"},{"path":"src/solid-element.tsx","kind":"import-statement","original":"./solid-element"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":22331},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/web-context","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"solid-js/jsx-runtime","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true},{"path":"solid-js/jsx-runtime","kind":"import-statement","external":true}],"exports":["ContextProtocolProvider","getContextRequestHandler","tryHandleContextRequest","useWebComponentContext","withContextProvider"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":35},"src/consumer.ts":{"bytesInOutput":910},"src/internal.ts":{"bytesInOutput":194},"src/provider.tsx":{"bytesInOutput":4178},"src/solid-element.tsx":{"bytesInOutput":398}},"bytes":6015}}}
@@ -0,0 +1,205 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+
3
+ // src/index.ts
4
+ export * from "@dxos/web-context";
5
+
6
+ // src/consumer.ts
7
+ import { createSignal, onCleanup as onCleanup2 } from "solid-js";
8
+ import { ContextRequestEvent as ContextRequestEvent2 } from "@dxos/web-context";
9
+
10
+ // src/internal.ts
11
+ import { createContext as createSolidContext, useContext } from "solid-js";
12
+ var HostElementContext = createSolidContext();
13
+ function getHostElement() {
14
+ return useContext(HostElementContext);
15
+ }
16
+
17
+ // src/provider.tsx
18
+ import { jsx as _jsx } from "solid-js/jsx-runtime";
19
+ import { createEffect, createContext as createSolidContext2, onCleanup, onMount, useContext as useContext2 } from "solid-js";
20
+ import { CONTEXT_PROVIDER_EVENT, CONTEXT_REQUEST_EVENT, ContextProviderEvent, ContextRequestEvent } from "@dxos/web-context";
21
+ var ContextRequestHandlerContext = createSolidContext2();
22
+ function tryHandleContextRequest(event) {
23
+ const handler = useContext2(ContextRequestHandlerContext);
24
+ if (handler) {
25
+ return handler(event);
26
+ }
27
+ return false;
28
+ }
29
+ function getContextRequestHandler() {
30
+ return useContext2(ContextRequestHandlerContext);
31
+ }
32
+ function ContextProtocolProvider(props) {
33
+ const parentHandler = useContext2(ContextRequestHandlerContext);
34
+ const subscriptions = /* @__PURE__ */ new WeakMap();
35
+ const subscriptionRefs = /* @__PURE__ */ new Set();
36
+ const getValue = () => {
37
+ const v = props.value;
38
+ return typeof v === "function" ? v() : v;
39
+ };
40
+ const handleRequest = (event) => {
41
+ if (event.context !== props.context) {
42
+ if (parentHandler) {
43
+ return parentHandler(event);
44
+ }
45
+ return false;
46
+ }
47
+ const currentValue = getValue();
48
+ if (event.subscribe) {
49
+ const callback = event.callback;
50
+ const consumerHost = event.contextTarget || event.composedPath()[0];
51
+ const unsubscribe = () => {
52
+ const info = subscriptions.get(callback);
53
+ if (info) {
54
+ subscriptionRefs.delete(info.ref);
55
+ subscriptions.delete(callback);
56
+ }
57
+ };
58
+ const ref = new WeakRef(callback);
59
+ subscriptions.set(callback, {
60
+ unsubscribe,
61
+ consumerHost,
62
+ ref
63
+ });
64
+ subscriptionRefs.add(ref);
65
+ event.callback(currentValue, unsubscribe);
66
+ } else {
67
+ event.callback(currentValue);
68
+ }
69
+ return true;
70
+ };
71
+ const handleContextRequestEvent = (e) => {
72
+ const event = e;
73
+ if (handleRequest(event)) {
74
+ event.stopImmediatePropagation();
75
+ }
76
+ };
77
+ const handleContextProviderEvent = (e) => {
78
+ const event = e;
79
+ if (event.context !== props.context) {
80
+ return;
81
+ }
82
+ if (containerRef && event.contextTarget === containerRef) {
83
+ return;
84
+ }
85
+ const seen = /* @__PURE__ */ new Set();
86
+ for (const ref of subscriptionRefs) {
87
+ const callback = ref.deref();
88
+ if (!callback) {
89
+ subscriptionRefs.delete(ref);
90
+ continue;
91
+ }
92
+ const info = subscriptions.get(callback);
93
+ if (!info) continue;
94
+ const { consumerHost } = info;
95
+ if (seen.has(callback)) {
96
+ continue;
97
+ }
98
+ seen.add(callback);
99
+ consumerHost.dispatchEvent(new ContextRequestEvent(props.context, callback, {
100
+ subscribe: true,
101
+ target: consumerHost
102
+ }));
103
+ }
104
+ event.stopPropagation();
105
+ };
106
+ let isFirstRun = true;
107
+ createEffect(() => {
108
+ const v = props.value;
109
+ const newValue = typeof v === "function" ? v() : v;
110
+ if (isFirstRun) {
111
+ isFirstRun = false;
112
+ return;
113
+ }
114
+ for (const ref of subscriptionRefs) {
115
+ const callback = ref.deref();
116
+ if (!callback) {
117
+ subscriptionRefs.delete(ref);
118
+ continue;
119
+ }
120
+ const info = subscriptions.get(callback);
121
+ if (info) {
122
+ callback(newValue, info.unsubscribe);
123
+ }
124
+ }
125
+ });
126
+ let containerRef;
127
+ const setupListeners = (el) => {
128
+ containerRef = el;
129
+ el.addEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);
130
+ el.addEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);
131
+ };
132
+ onMount(() => {
133
+ if (containerRef) {
134
+ containerRef.dispatchEvent(new ContextProviderEvent(props.context, containerRef));
135
+ }
136
+ });
137
+ onCleanup(() => {
138
+ if (containerRef) {
139
+ containerRef.removeEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);
140
+ containerRef.removeEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);
141
+ }
142
+ subscriptionRefs.clear();
143
+ });
144
+ return /* @__PURE__ */ _jsx(ContextRequestHandlerContext.Provider, {
145
+ value: handleRequest,
146
+ children: /* @__PURE__ */ _jsx("div", {
147
+ ref: setupListeners,
148
+ style: {
149
+ display: "contents"
150
+ },
151
+ children: props.children
152
+ })
153
+ });
154
+ }
155
+
156
+ // src/consumer.ts
157
+ function useWebComponentContext(context, options) {
158
+ const [value, setValue] = createSignal(void 0);
159
+ let unsubscribeFn;
160
+ const callback = (newValue, unsubscribe) => {
161
+ setValue(() => newValue);
162
+ if (unsubscribe) {
163
+ unsubscribeFn = unsubscribe;
164
+ }
165
+ };
166
+ const hostElement = getHostElement();
167
+ const targetElement = options?.element ?? hostElement ?? document.body;
168
+ const event = new ContextRequestEvent2(context, callback, {
169
+ subscribe: options?.subscribe,
170
+ target: targetElement
171
+ });
172
+ const handler = getContextRequestHandler();
173
+ let handled = false;
174
+ if (handler) {
175
+ handled = handler(event);
176
+ }
177
+ if (!handled) {
178
+ targetElement.dispatchEvent(event);
179
+ }
180
+ onCleanup2(() => {
181
+ unsubscribeFn?.();
182
+ });
183
+ return value;
184
+ }
185
+
186
+ // src/solid-element.tsx
187
+ import { jsx as _jsx2 } from "solid-js/jsx-runtime";
188
+ function withContextProvider(component) {
189
+ const wrappedComponent = (props, options) => {
190
+ const WrappedContent = () => component(props, options);
191
+ return /* @__PURE__ */ _jsx2(HostElementContext.Provider, {
192
+ value: options.element,
193
+ children: /* @__PURE__ */ _jsx2(WrappedContent, {})
194
+ });
195
+ };
196
+ return wrappedComponent;
197
+ }
198
+ export {
199
+ ContextProtocolProvider,
200
+ getContextRequestHandler,
201
+ tryHandleContextRequest,
202
+ useWebComponentContext,
203
+ withContextProvider
204
+ };
205
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/index.ts", "../../../src/consumer.ts", "../../../src/internal.ts", "../../../src/provider.tsx", "../../../src/solid-element.tsx"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport * from '@dxos/web-context';\n\nexport * from './consumer';\nexport * from './provider';\nexport * from './solid-element';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Accessor, createSignal, onCleanup } from 'solid-js';\n\nimport { ContextRequestEvent, type ContextType, type UnknownContext } from '@dxos/web-context';\n\nimport { getHostElement } from './internal';\nimport { getContextRequestHandler } 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 signal 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 SolidJS provider in the tree.\n * Default: document.body\n */\n element?: HTMLElement;\n}\n\n/**\n * A SolidJS hook that requests context using the Web Component Context Protocol.\n *\n * This first tries to use the SolidJS context chain (for providers in the same\n * SolidJS 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 An accessor that returns the context value or undefined\n *\n * @example\n * ```tsx\n * const theme = useWebComponentContext(themeContext);\n * return <div style={{ color: theme()?.primary }}>Hello</div>;\n * ```\n *\n * @example\n * ```tsx\n * // Subscribe to updates\n * const theme = useWebComponentContext(themeContext, { subscribe: true });\n * return <div style={{ color: theme()?.primary }}>Hello</div>;\n * ```\n */\nexport function useWebComponentContext<T extends UnknownContext>(\n context: T,\n options?: UseWebComponentContextOptions,\n): Accessor<ContextType<T> | undefined> {\n const [value, setValue] = createSignal<ContextType<T> | undefined>(undefined);\n let unsubscribeFn: (() => void) | undefined;\n\n // Create callback that updates our signal\n const callback = (newValue: ContextType<T>, unsubscribe?: () => void): void => {\n setValue(() => newValue);\n // Store the latest unsubscribe function\n if (unsubscribe) {\n unsubscribeFn = unsubscribe;\n }\n };\n\n // Determine the target element for the context request\n // Use: 1) explicit element option, 2) host element from custom element context, 3) document.body\n const hostElement = getHostElement();\n const targetElement = options?.element ?? hostElement ?? document.body;\n\n // Create the context request event with contextTarget for proper re-parenting support\n const event = new ContextRequestEvent(context, callback, {\n subscribe: options?.subscribe,\n target: targetElement,\n });\n\n // First, try to handle via SolidJS context chain (synchronous)\n const handler = getContextRequestHandler();\n let handled = false;\n\n if (handler) {\n handled = handler(event);\n }\n\n // If not handled by SolidJS providers, try DOM event dispatch\n if (!handled) {\n targetElement.dispatchEvent(event);\n }\n\n // Cleanup: unsubscribe when component unmounts\n // Cleanup: unsubscribe when component unmounts\n onCleanup(() => {\n unsubscribeFn?.();\n });\n\n return value;\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { createContext as createSolidContext, useContext } from 'solid-js';\n\n/**\n * Internal SolidJS context for passing the host element to nested components.\n * This allows useWebComponentContext to dispatch events from the custom element.\n */\nexport const HostElementContext = createSolidContext<HTMLElement | undefined>();\n\n/**\n * Get the host custom element from SolidJS context.\n * Used internally by useWebComponentContext when called from a custom element.\n */\nexport function getHostElement(): HTMLElement | undefined {\n return useContext(HostElementContext);\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport {\n type Accessor,\n type JSX,\n createEffect,\n createContext as createSolidContext,\n onCleanup,\n onMount,\n useContext,\n} from 'solid-js';\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 SolidJS context\n */\ntype ContextRequestHandler = (event: ContextRequestEvent<UnknownContext>) => boolean;\n\n/**\n * Internal SolidJS context for passing context request handlers down the tree.\n * This allows useWebComponentContext to work synchronously in SolidJS.\n */\nconst ContextRequestHandlerContext = createSolidContext<ContextRequestHandler | undefined>();\n\n/**\n * Try to handle a context request using the SolidJS context chain.\n * Returns true if handled, false otherwise.\n * Used internally by useWebComponentContext.\n */\nexport function tryHandleContextRequest(event: ContextRequestEvent<UnknownContext>): boolean {\n const handler = useContext(ContextRequestHandlerContext);\n if (handler) {\n return handler(event);\n }\n return false;\n}\n\n/**\n * Get the context request handler from SolidJS context.\n * Used internally by useWebComponentContext.\n */\nexport function getContextRequestHandler(): 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 - can be a static value or an accessor for reactive updates */\n value: ContextType<T> | Accessor<ContextType<T>>;\n /** Child elements */\n children: JSX.Element;\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 SolidJS consumers (via SolidJS context)\n * 3. Supports subscriptions for reactive updates\n * 4. Uses WeakRef for subscriptions to prevent memory leaks\n */\nexport function ContextProtocolProvider<T extends UnknownContext>(props: 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 // We use WeakMap to hold callbacks weakly. This ensures that if a consumer\n // drops the callback, we don't leak memory.\n //\n // NOTE: This means consumers MUST retain the callback reference as long as they\n // want to receive updates (e.g. implicitly via closure in a retained component).\n interface SubscriptionInfo {\n unsubscribe: () => void;\n consumerHost: Element;\n // Store ref to allow cleaning up the Set when unsubscribing\n ref: WeakRef<ContextCallback<ContextType<T>>>;\n }\n const subscriptions = new WeakMap<ContextCallback<ContextType<T>>, SubscriptionInfo>();\n const subscriptionRefs = new Set<WeakRef<ContextCallback<ContextType<T>>>>();\n\n // Helper to get current value (handles both static and accessor)\n const getValue = (): ContextType<T> => {\n const v = props.value;\n return typeof v === 'function' ? (v as Accessor<ContextType<T>>)() : v;\n };\n\n // Core handler logic - used by both DOM events and SolidJS context\n const handleRequest = (event: ContextRequestEvent<UnknownContext>): boolean => {\n // Check if this provider handles this context (strict equality per spec)\n if (event.context !== props.context) {\n // Pass to parent handler if we don't handle this context\n if (parentHandler) {\n return parentHandler(event);\n }\n return false;\n }\n\n const currentValue = getValue();\n\n if (event.subscribe) {\n // Store the callback for future updates\n const callback = event.callback as ContextCallback<ContextType<T>>;\n\n // Get the consumer host element from the event\n // Fallback to composedPath()[0] if contextTarget is missing (standard compliance)\n const consumerHost = event.contextTarget || (event.composedPath()[0] as Element);\n\n // Create a stable unsubscribe function for this callback\n // IMPORTANT: We must pass the SAME unsubscribe function each time we call the callback\n // Lit's ContextConsumer compares unsubscribe functions and calls the old one if different\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 // Invoke callback with current value and unsubscribe function\n event.callback(currentValue, unsubscribe);\n } else {\n // One-time request - just provide the value\n event.callback(currentValue);\n }\n\n return true;\n };\n\n // Handle DOM context-request events (for web components)\n const handleContextRequestEvent = (e: Event) => {\n const event = e as ContextRequestEvent<UnknownContext>;\n if (handleRequest(event)) {\n // Stop propagation per spec recommendation\n event.stopImmediatePropagation();\n }\n };\n\n // Handle context-provider events from child providers\n // When a new provider appears below us, we re-dispatch our subscriptions\n // so consumers can re-parent to the closer provider\n const handleContextProviderEvent = (e: Event) => {\n const event = e as ContextProviderEvent<UnknownContext>;\n\n // Only handle events for our context\n if (event.context !== props.context) {\n return;\n }\n\n // Don't handle our own event\n if (containerRef && event.contextTarget === containerRef) {\n return;\n }\n\n // Re-dispatch context requests from our subscribers\n // They may now have a closer provider\n // Iterate over weak refs to re-dispatch\n // We use a separate Set of WeakRefs because WeakMap is not iterable.\n // This allows us to re-parent subscriptions when a new provider appears.\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 const { consumerHost } = info;\n\n // Prevent infinite loops with duplicate callbacks\n if (seen.has(callback)) {\n continue;\n }\n seen.add(callback);\n\n // Re-dispatch the context request from the consumer\n // We explicitly pass the original consumerHost as the target to preserve the causal chain\n consumerHost.dispatchEvent(\n new ContextRequestEvent(props.context, callback, { subscribe: true, target: consumerHost }),\n );\n }\n\n // Stop propagation - we've handled the re-parenting\n event.stopPropagation();\n };\n\n // Set up effect to notify subscribers when value changes\n let isFirstRun = true;\n createEffect(() => {\n // IMPORTANT: We must call the accessor DIRECTLY inside the effect to establish tracking\n // Reading props.value gives us the accessor, then we must call it to track the signal\n const v = props.value;\n const newValue = typeof v === 'function' ? (v as Accessor<ContextType<T>>)() : v;\n\n // Skip first run - only notify on changes after initial subscription\n if (isFirstRun) {\n isFirstRun = false;\n return;\n }\n\n // Notify all subscribers with their stable unsubscribe functions\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 callback(newValue, info.unsubscribe);\n }\n }\n });\n\n // Reference to container element for event listener\n let containerRef: HTMLDivElement | undefined;\n\n // Set up event listeners when element is created\n const setupListeners = (el: HTMLDivElement) => {\n containerRef = el;\n el.addEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);\n el.addEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);\n };\n\n // Announce this provider when mounted\n // This allows ContextRoot implementations to replay pending requests\n // and allows parent providers to re-parent their subscriptions\n onMount(() => {\n if (containerRef) {\n containerRef.dispatchEvent(new ContextProviderEvent(props.context, containerRef));\n }\n });\n\n // Cleanup on unmount\n onCleanup(() => {\n if (containerRef) {\n containerRef.removeEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);\n containerRef.removeEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);\n }\n // WeakMap clears itself, but we should clear the Set of refs\n subscriptionRefs.clear();\n });\n\n return (\n <ContextRequestHandlerContext.Provider value={handleRequest}>\n <div ref={setupListeners} style={{ display: 'contents' }}>\n {props.children}\n </div>\n </ContextRequestHandlerContext.Provider>\n );\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type { ComponentType } from 'solid-element';\nimport type { JSX } from 'solid-js';\n\nimport { HostElementContext } from './internal';\n\n/**\n * Integration utilities for using Web Component Context Protocol with solid-element.\n *\n * This module provides utilities to integrate our context protocol implementation\n * with the solid-element library for creating web components.\n *\n * @example\n * ```tsx\n * import { customElement } from 'solid-element';\n * import { withContextProvider } from './context/solid-element';\n *\n * customElement('my-button', {}, withContextProvider((props, { element }) => {\n * const theme = useWebComponentContext(themeContext, { subscribe: true });\n * return <button style={{ background: theme()?.primary }}>Click me</button>;\n * }));\n * ```\n */\n\n/**\n * Options passed by solid-element to component functions.\n * The element extends HTMLElement with additional custom element methods.\n */\nexport interface SolidElementOptions {\n element: HTMLElement & {\n renderRoot: Element | Document | ShadowRoot | DocumentFragment;\n addReleaseCallback(fn: () => void): void;\n addPropertyChangedCallback(fn: (name: string, value: unknown) => void): void;\n };\n}\n\n/**\n * Function component type for solid-element.\n * Receives props and an options object containing the host element.\n */\nexport type SolidElementComponent<P extends object = object> = (props: P, options: SolidElementOptions) => JSX.Element;\n\n/**\n * Wraps a solid-element component to provide the host element context.\n * This enables useWebComponentContext to dispatch events from the custom element\n * rather than document.body.\n *\n * @param component - The solid-element component function\n * @returns A wrapped component that provides HostElementContext\n *\n * @example\n * ```tsx\n * import { customElement } from 'solid-element';\n * import { withContextProvider, useWebComponentContext } from './context';\n *\n * customElement('themed-button', {}, withContextProvider((props, { element }) => {\n * const theme = useWebComponentContext(themeContext, { subscribe: true });\n * return (\n * <button style={{ background: theme()?.primary }}>\n * Themed Button\n * </button>\n * );\n * }));\n * ```\n */\nexport function withContextProvider<P extends object>(component: SolidElementComponent<P>): ComponentType<P> {\n // Return a new component function that wraps the original with HostElementContext\n // This enables useWebComponentContext to dispatch events from the custom element\n const wrappedComponent = (props: P, options: SolidElementOptions) => {\n // Create a child component that renders within the context\n const WrappedContent = () => component(props, options);\n\n return (\n <HostElementContext.Provider value={options.element}>\n <WrappedContent />\n </HostElementContext.Provider>\n );\n };\n\n return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AASC;AAGlE,QAAMC,QAAQ,IAAIC,qBAAoBjB,SAASO,UAAU;IACvDW,WAAWjB,SAASiB;IACpBC,QAAQP;EACV,CAAA;AAGA,QAAMQ,UAAUC,yBAAAA;AAChB,MAAIC,UAAU;AAEd,MAAIF,SAAS;AACXE,cAAUF,QAAQJ,KAAAA;EACpB;AAGA,MAAI,CAACM,SAAS;AACZV,kBAAcW,cAAcP,KAAAA;EAC9B;AAIAQ,EAAAA,WAAU,MAAA;AACRlB,oBAAAA;EACF,CAAA;AAEA,SAAOJ;AACT;A;;;AGjCO,SAASuB,oBAAsCC,WAAmC;AAGvF,QAAMC,mBAAmB,CAACC,OAAUC,YAAAA;AAElC,UAAMC,iBAAiB,MAAMJ,UAAUE,OAAOC,OAAAA;AAE9C,WACE,gBAAAE,MAACC,mBAAmBC,UAAQ;MAACC,OAAOL,QAAQM;gBAC1C,gBAAAJ,MAACD,gBAAAA,CAAAA,CAAAA;;EAGP;AAEA,SAAOH;AACT;",
6
+ "names": ["createSignal", "onCleanup", "ContextRequestEvent", "createContext", "createSolidContext", "useContext", "HostElementContext", "createSolidContext", "getHostElement", "useContext", "createEffect", "createContext", "createSolidContext", "onCleanup", "onMount", "useContext", "CONTEXT_PROVIDER_EVENT", "CONTEXT_REQUEST_EVENT", "ContextProviderEvent", "ContextRequestEvent", "ContextRequestHandlerContext", "createSolidContext", "tryHandleContextRequest", "event", "handler", "useContext", "getContextRequestHandler", "ContextProtocolProvider", "props", "parentHandler", "subscriptions", "WeakMap", "subscriptionRefs", "Set", "getValue", "v", "value", "handleRequest", "context", "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", "isFirstRun", "createEffect", "newValue", "setupListeners", "el", "addEventListener", "CONTEXT_REQUEST_EVENT", "CONTEXT_PROVIDER_EVENT", "onMount", "ContextProviderEvent", "onCleanup", "removeEventListener", "clear", "Provider", "div", "style", "display", "children", "useWebComponentContext", "context", "options", "value", "setValue", "createSignal", "undefined", "unsubscribeFn", "callback", "newValue", "unsubscribe", "hostElement", "getHostElement", "targetElement", "element", "document", "body", "event", "ContextRequestEvent", "subscribe", "target", "handler", "getContextRequestHandler", "handled", "dispatchEvent", "onCleanup", "withContextProvider", "component", "wrappedComponent", "props", "options", "WrappedContent", "_jsx", "HostElementContext", "Provider", "value", "element"]
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"src/internal.ts":{"bytes":1993,"imports":[{"path":"solid-js","kind":"import-statement","external":true}],"format":"esm"},"src/provider.tsx":{"bytes":26875,"imports":[{"path":"solid-js/jsx-runtime","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true}],"format":"esm"},"src/consumer.ts":{"bytes":8500,"imports":[{"path":"solid-js","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/solid-element.tsx":{"bytes":6420,"imports":[{"path":"solid-js/jsx-runtime","kind":"import-statement","external":true},{"path":"src/internal.ts","kind":"import-statement","original":"./internal"}],"format":"esm"},"src/index.ts":{"bytes":760,"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"},{"path":"src/solid-element.tsx","kind":"import-statement","original":"./solid-element"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":22333},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/web-context","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"solid-js/jsx-runtime","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/web-context","kind":"import-statement","external":true},{"path":"solid-js/jsx-runtime","kind":"import-statement","external":true}],"exports":["ContextProtocolProvider","getContextRequestHandler","tryHandleContextRequest","useWebComponentContext","withContextProvider"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":35},"src/consumer.ts":{"bytesInOutput":910},"src/internal.ts":{"bytesInOutput":194},"src/provider.tsx":{"bytesInOutput":4178},"src/solid-element.tsx":{"bytesInOutput":398}},"bytes":6108}}}
@@ -0,0 +1,45 @@
1
+ import { type Accessor } from 'solid-js';
2
+ import { type ContextType, type UnknownContext } from '@dxos/web-context';
3
+ /**
4
+ * Options for useWebComponentContext hook
5
+ */
6
+ export interface UseWebComponentContextOptions {
7
+ /**
8
+ * Whether to subscribe to context updates.
9
+ * If true, the returned signal will update when the provider's value changes.
10
+ * Default: false
11
+ */
12
+ subscribe?: boolean;
13
+ /**
14
+ * The element to dispatch the context-request event from.
15
+ * This is only used when there's no SolidJS provider in the tree.
16
+ * Default: document.body
17
+ */
18
+ element?: HTMLElement;
19
+ }
20
+ /**
21
+ * A SolidJS hook that requests context using the Web Component Context Protocol.
22
+ *
23
+ * This first tries to use the SolidJS context chain (for providers in the same
24
+ * SolidJS tree), then falls back to dispatching a DOM event (for web component
25
+ * providers).
26
+ *
27
+ * @param context - The context key to request
28
+ * @param options - Optional configuration
29
+ * @returns An accessor that returns the context value or undefined
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * const theme = useWebComponentContext(themeContext);
34
+ * return <div style={{ color: theme()?.primary }}>Hello</div>;
35
+ * ```
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * // Subscribe to updates
40
+ * const theme = useWebComponentContext(themeContext, { subscribe: true });
41
+ * return <div style={{ color: theme()?.primary }}>Hello</div>;
42
+ * ```
43
+ */
44
+ export declare function useWebComponentContext<T extends UnknownContext>(context: T, options?: UseWebComponentContextOptions): Accessor<ContextType<T> | undefined>;
45
+ //# sourceMappingURL=consumer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumer.d.ts","sourceRoot":"","sources":["../../../src/consumer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,QAAQ,EAA2B,MAAM,UAAU,CAAC;AAElE,OAAO,EAAuB,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAK/F;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,cAAc,EAC7D,OAAO,EAAE,CAAC,EACV,OAAO,CAAC,EAAE,6BAA6B,GACtC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CA4CtC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=consumer.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumer.test.d.ts","sourceRoot":"","sources":["../../../src/consumer.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export * from '@dxos/web-context';
2
+ export * from './consumer';
3
+ export * from './provider';
4
+ export * from './solid-element';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,mBAAmB,CAAC;AAElC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Internal SolidJS context for passing the host element to nested components.
3
+ * This allows useWebComponentContext to dispatch events from the custom element.
4
+ */
5
+ export declare const HostElementContext: import("solid-js").Context<HTMLElement | undefined>;
6
+ /**
7
+ * Get the host custom element from SolidJS context.
8
+ * Used internally by useWebComponentContext when called from a custom element.
9
+ */
10
+ export declare function getHostElement(): HTMLElement | undefined;
11
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/internal.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,eAAO,MAAM,kBAAkB,qDAAgD,CAAC;AAEhF;;;GAGG;AACH,wBAAgB,cAAc,IAAI,WAAW,GAAG,SAAS,CAExD"}