@bfrs/agentic-components 0.8.6 → 0.8.8

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.
Files changed (32) hide show
  1. package/dist/components/data-display/DataTable/TableSaveView.d.ts +14 -1
  2. package/dist/components/data-display/DataTable/TableSaveView.js +164 -144
  3. package/dist/components/data-display/DataTable/TableSaveView.js.map +1 -1
  4. package/dist/components/data-display/DataTable/TableViewSelector.d.ts +15 -1
  5. package/dist/components/data-display/DataTable/TableViewSelector.js +304 -296
  6. package/dist/components/data-display/DataTable/TableViewSelector.js.map +1 -1
  7. package/dist/components/data-display/DataTable/index.d.ts +1 -0
  8. package/dist/components/data-display/DataTable/savedViewAnalytics.d.ts +109 -0
  9. package/dist/components/data-display/DataTable/savedViewAnalytics.js +140 -0
  10. package/dist/components/data-display/DataTable/savedViewAnalytics.js.map +1 -0
  11. package/dist/components/feedback/Toast/Toast.js +48 -48
  12. package/dist/components/feedback/Toast/Toast.js.map +1 -1
  13. package/dist/components/ui/feedback/warningVisual.d.ts +1 -0
  14. package/dist/components/ui/feedback/warningVisual.js +20 -16
  15. package/dist/components/ui/feedback/warningVisual.js.map +1 -1
  16. package/dist/components/ui/index.d.ts +2 -0
  17. package/dist/components/ui/providers/BfrsAnalyticsProvider/BfrsAnalyticsProvider.d.ts +18 -0
  18. package/dist/components/ui/providers/BfrsAnalyticsProvider/BfrsAnalyticsProvider.js +12 -0
  19. package/dist/components/ui/providers/BfrsAnalyticsProvider/BfrsAnalyticsProvider.js.map +1 -0
  20. package/dist/components/ui/providers/BfrsAnalyticsProvider/analyticsContext.d.ts +78 -0
  21. package/dist/components/ui/providers/BfrsAnalyticsProvider/analyticsContext.js +41 -0
  22. package/dist/components/ui/providers/BfrsAnalyticsProvider/analyticsContext.js.map +1 -0
  23. package/dist/components/ui/providers/BfrsAnalyticsProvider/index.d.ts +4 -0
  24. package/dist/components/ui/providers/BfrsProvider/BfrsProvider.d.ts +25 -0
  25. package/dist/components/ui/providers/BfrsProvider/BfrsProvider.js +42 -41
  26. package/dist/components/ui/providers/BfrsProvider/BfrsProvider.js.map +1 -1
  27. package/dist/custom-elements.js +9124 -8933
  28. package/dist/custom-elements.js.map +1 -1
  29. package/dist/index.js +224 -213
  30. package/dist/index.js.map +1 -1
  31. package/package.json +1 -1
  32. package/scripts/lint/cli.cjs +6 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyticsContext.js","sources":["../../../../../src/components/ui/providers/BfrsAnalyticsProvider/analyticsContext.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\n\n/**\n * Analytics for library-owned interactions.\n *\n * ## Why the library emits at all\n *\n * The usage guide's rule — \"the library should not know analytics events\" —\n * holds for anything the consumer can observe for itself. Saved views are the\n * case where it cannot:\n *\n * - `TableSaveView` dispatches the request through its own store when\n * `screenName` is supplied, so `onSave` never fires and the consumer cannot\n * see the submit at all. Reporting a submission from `onSaved` would be a\n * different fact (an outcome) wearing the submit's name.\n * - A submission blocked by the component's own validation (empty or reserved\n * name) produces no callback at all, so nobody could count it.\n * - `TableViewSelector` calls `onValueChange` for BOTH a seller's pick and its\n * own mount-time restore of the primary view, in an identical shape. Every\n * consumer had to guess with a heuristic; the component knows for certain.\n *\n * So the component owns the MOMENTS, which only it can observe correctly, and\n * the consumer owns the VOCABULARY: it passes the registered element ids and a\n * sink, and nothing here ever touches `gtag`, `dataLayer` or a provider SDK.\n * There is exactly one GA4 tag in the platform and it belongs to the host; this\n * module hands the host an event and is finished.\n */\n\n/**\n * The canonical event names the library may emit — a closed set, matching the\n * platform registry. The host validates every name and property it receives, so\n * an unknown name here would be dropped there with a diagnostic rather than\n * silently reported.\n *\n * `form_validation_failed` is deliberately absent: the only validation these\n * components apply disables the submit control, so no blocked attempt can\n * occur. Add it when a component can actually observe one.\n */\nexport type BfrsAnalyticsEventName =\n | \"cta_clicked\"\n | \"element_clicked\"\n | \"modal_displayed\"\n | \"modal_dismissed\"\n | \"dropdown_option_selected\"\n | \"form_submitted\"\n | \"workflow_completed\"\n | \"workflow_failed\";\n\n/**\n * Event properties. Values are codes, counts and booleans only.\n *\n * Nothing in this file may pass a view NAME, a seller's typed text, a label, a\n * URL or an identifier from an unbounded list: the ids are registered codes the\n * consumer supplies, and a saved view's name is the seller's own words.\n */\nexport type BfrsAnalyticsProperties = Record<string, string | number | boolean | undefined>;\n\nexport type BfrsAnalyticsEvent = {\n name: BfrsAnalyticsEventName;\n properties: BfrsAnalyticsProperties;\n};\n\n/**\n * Where library events go. A consumer wires this once:\n *\n * ```tsx\n * <BfrsProvider analytics={(event) => analytics.track(event.name, event.properties)}>\n * ```\n */\nexport type BfrsAnalyticsSink = (event: BfrsAnalyticsEvent) => void;\n\nexport const BfrsAnalyticsContext = createContext<BfrsAnalyticsSink | null>(null);\n\n/**\n * The host bridge a platform app installs at bootstrap, as far as this library\n * needs to know it.\n *\n * `trackLibraryEvent` takes no origin: the host derives `module` and\n * `screen_name` from the live route, because a component library is rendered on\n * every module's screens from one build and cannot state an origin of its own.\n */\ntype HostAnalyticsBridgeLike = {\n trackLibraryEvent?: (event: string, properties?: Record<string, unknown>) => void;\n};\n\nconst HOST_BRIDGE_KEYS = [\"__shiprocketAnalyticsBridge\", \"__bfrsAnalytics\"] as const;\n\n/**\n * Find the host's own analytics entry point, so an app wires NOTHING.\n *\n * This is the last resort in the precedence list below, and it is deliberately\n * narrow: it looks only for a named method on a known host bridge, calls it\n * with an event the components already validate against the canonical names,\n * and does nothing at all when no bridge is there (a standalone Storybook, a\n * consumer that is not a platform app, a unit test).\n *\n * The honest tradeoff: a library reading a global is less explicit than a prop.\n * It is justified here because the alternative is every app repeating one line\n * that can only have one answer, and because the thing it reaches for is a\n * documented host contract rather than `gtag` or `dataLayer` — the library\n * still never touches a tag.\n */\nfunction discoverHostSink(): BfrsAnalyticsSink | null {\n if (typeof globalThis === \"undefined\") return null;\n\n for (const key of HOST_BRIDGE_KEYS) {\n const bridge = (globalThis as unknown as Record<string, HostAnalyticsBridgeLike | undefined>)[key];\n const track = bridge?.trackLibraryEvent;\n if (typeof track !== \"function\") continue;\n return (event) => {\n track.call(bridge, event.name, event.properties);\n };\n }\n\n return null;\n}\n\n/**\n * The app-wide sink, set once by the host instead of threaded through props.\n *\n * Why a global and not just the provider prop: an app mounts these components\n * in several trees (a filter row, a table toolbar, a portaled drawer), and some\n * of those are portaled outside the provider. Making every one of them carry an\n * `analytics` prop — or wrapping each in a provider — is friction that buys\n * nothing, because there is exactly one answer per app anyway.\n *\n * The host sets it once at bootstrap:\n *\n * ```ts\n * setBfrsAnalyticsSink((event) => analytics.track(event.name, event.properties));\n * ```\n *\n * Precedence, most specific first: a component's own `analytics.emit` → the\n * nearest `BfrsProvider`/`BfrsAnalyticsProvider` → this. Pass `null` to clear\n * it (tests, teardown). It is module state, not `window`, so two bundles on one\n * page keep their own and nothing leaks between them.\n */\nlet appSink: BfrsAnalyticsSink | null = null;\n\nexport function setBfrsAnalyticsSink(sink: BfrsAnalyticsSink | null): void {\n appSink = sink;\n}\n\nexport function getBfrsAnalyticsSink(): BfrsAnalyticsSink | null {\n return appSink;\n}\n\n/**\n * The sink to use, most specific first:\n *\n * 1. the nearest `BfrsProvider`/`BfrsAnalyticsProvider`\n * 2. `setBfrsAnalyticsSink`, if an app chose to set one\n * 3. the host bridge, discovered — which is why a platform app needs neither\n * of the above\n *\n * Null when none of them is present, and then nothing is emitted.\n */\nexport function useBfrsAnalyticsSink(): BfrsAnalyticsSink | null {\n return useContext(BfrsAnalyticsContext) ?? appSink ?? discoverHostSink();\n}\n\n/**\n * Send one event, swallowing anything the sink throws.\n *\n * Reporting is never allowed to break the interaction it is reporting: a sink\n * that throws (a mis-wired host, a consent gate, a provider SDK that is not\n * loaded yet) must not take the save dialog down with it.\n */\nexport function emitBfrsAnalytics(\n sink: BfrsAnalyticsSink | null | undefined,\n name: BfrsAnalyticsEventName,\n properties: BfrsAnalyticsProperties\n): void {\n if (!sink) return;\n\n const payload: BfrsAnalyticsProperties = {};\n for (const [key, value] of Object.entries(properties)) {\n if (value !== undefined) payload[key] = value;\n }\n\n try {\n sink({ name, properties: payload });\n } catch {\n /* reporting must never throw into a product interaction */\n }\n}\n"],"names":["BfrsAnalyticsContext","createContext","HOST_BRIDGE_KEYS","discoverHostSink","key","bridge","track","event","appSink","setBfrsAnalyticsSink","sink","getBfrsAnalyticsSink","useBfrsAnalyticsSink","useContext","emitBfrsAnalytics","name","properties","payload","value"],"mappings":";AAuEO,MAAMA,IAAuBC,EAAwC,IAAI,GAc1EC,IAAmB,CAAC,+BAA+B,iBAAiB;AAiB1E,SAASC,IAA6C;AACpD,MAAI,OAAO,aAAe,IAAa,QAAO;AAE9C,aAAWC,KAAOF,GAAkB;AAClC,UAAMG,IAAU,WAA8ED,CAAG,GAC3FE,IAAQD,KAAA,gBAAAA,EAAQ;AACtB,QAAI,OAAOC,KAAU;AACrB,aAAO,CAACC,MAAU;AAChB,QAAAD,EAAM,KAAKD,GAAQE,EAAM,MAAMA,EAAM,UAAU;AAAA,MACjD;AAAA,EACF;AAEA,SAAO;AACT;AAsBA,IAAIC,IAAoC;AAEjC,SAASC,EAAqBC,GAAsC;AACzE,EAAAF,IAAUE;AACZ;AAEO,SAASC,IAAiD;AAC/D,SAAOH;AACT;AAYO,SAASI,IAAiD;AAC/D,SAAOC,EAAWb,CAAoB,KAAKQ,KAAWL,EAAA;AACxD;AASO,SAASW,EACdJ,GACAK,GACAC,GACM;AACN,MAAI,CAACN,EAAM;AAEX,QAAMO,IAAmC,CAAA;AACzC,aAAW,CAACb,GAAKc,CAAK,KAAK,OAAO,QAAQF,CAAU;AAClD,IAAIE,MAAU,WAAWD,EAAQb,CAAG,IAAIc;AAG1C,MAAI;AACF,IAAAR,EAAK,EAAE,MAAAK,GAAM,YAAYE,EAAA,CAAS;AAAA,EACpC,QAAQ;AAAA,EAER;AACF;"}
@@ -0,0 +1,4 @@
1
+ export { BfrsAnalyticsProvider } from './BfrsAnalyticsProvider';
2
+ export type { BfrsAnalyticsProviderProps } from './BfrsAnalyticsProvider';
3
+ export { emitBfrsAnalytics, getBfrsAnalyticsSink, setBfrsAnalyticsSink, useBfrsAnalyticsSink } from './analyticsContext';
4
+ export type { BfrsAnalyticsEvent, BfrsAnalyticsEventName, BfrsAnalyticsProperties, BfrsAnalyticsSink } from './analyticsContext';
@@ -1,13 +1,38 @@
1
1
  import { HTMLAttributes, ReactNode } from 'react';
2
2
  import { AgenticThemeOverrides } from '../../../../theme';
3
+ import { BfrsAnalyticsSink } from '../BfrsAnalyticsProvider/analyticsContext';
3
4
  export type BfrsColorScheme = "light" | "dark";
4
5
  export type BfrsProviderProps = HTMLAttributes<HTMLDivElement> & {
5
6
  theme?: AgenticThemeOverrides;
6
7
  colorScheme?: BfrsColorScheme;
8
+ /**
9
+ * Where library-owned interactions are reported, wired once per app:
10
+ *
11
+ * ```tsx
12
+ * <BfrsProvider analytics={(event) => analytics.track(event.name, event.properties)}>
13
+ * ```
14
+ *
15
+ * Nothing in the library touches `gtag`, `dataLayer` or a provider SDK — it
16
+ * hands the event here and the app decides what happens to it. Omitted, the
17
+ * library reports nothing.
18
+ */
19
+ analytics?: BfrsAnalyticsSink;
7
20
  };
8
21
  export declare const BfrsProvider: import('react').ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & {
9
22
  theme?: AgenticThemeOverrides;
10
23
  colorScheme?: BfrsColorScheme;
24
+ /**
25
+ * Where library-owned interactions are reported, wired once per app:
26
+ *
27
+ * ```tsx
28
+ * <BfrsProvider analytics={(event) => analytics.track(event.name, event.properties)}>
29
+ * ```
30
+ *
31
+ * Nothing in the library touches `gtag`, `dataLayer` or a provider SDK — it
32
+ * hands the event here and the app decides what happens to it. Omitted, the
33
+ * library reports nothing.
34
+ */
35
+ analytics?: BfrsAnalyticsSink;
11
36
  } & import('react').RefAttributes<HTMLDivElement>>;
12
37
  export declare function BfrsStyleScope({ children, root, colorScheme }: {
13
38
  children: ReactNode;
@@ -1,73 +1,74 @@
1
- import { jsx as i } from "react/jsx-runtime";
2
- import { forwardRef as v, useState as m, useMemo as l, useCallback as S, useContext as g, useEffect as x, createContext as P } from "react";
3
- import { cn as B } from "../../../../lib/cn.js";
4
- import { ensureDocumentStyles as C } from "../../../../lib/documentStyles.js";
5
- import { createAgenticThemeVariables as R } from "../../../../theme/overrides.js";
6
- const d = P({
1
+ import { jsx as l } from "react/jsx-runtime";
2
+ import { forwardRef as S, useState as d, useMemo as i, useCallback as g, useContext as P, useEffect as x, createContext as B } from "react";
3
+ import { cn as C } from "../../../../lib/cn.js";
4
+ import { ensureDocumentStyles as R } from "../../../../lib/documentStyles.js";
5
+ import { createAgenticThemeVariables as M } from "../../../../theme/overrides.js";
6
+ import { BfrsAnalyticsProvider as N } from "../BfrsAnalyticsProvider/BfrsAnalyticsProvider.js";
7
+ const y = B({
7
8
  root: null
8
9
  });
9
- function M(e, t) {
10
- if (e) {
11
- if (typeof e == "function") {
12
- e(t);
10
+ function T(t, e) {
11
+ if (t) {
12
+ if (typeof t == "function") {
13
+ t(e);
13
14
  return;
14
15
  }
15
- e.current = t;
16
+ t.current = e;
16
17
  }
17
18
  }
18
- const N = (e) => e, a = (e, t) => {
19
+ const V = (t) => t, a = (t, e) => {
19
20
  const r = {
20
21
  display: "contents"
21
22
  };
22
- if (t && (r.colorScheme = t), !e)
23
+ if (e && (r.colorScheme = e), !t)
23
24
  return r;
24
- for (let o = 0; o < e.style.length; o += 1) {
25
- const s = e.style.item(o);
26
- s.startsWith("--bfrs-") && (r[s] = e.style.getPropertyValue(s));
25
+ for (let s = 0; s < t.style.length; s += 1) {
26
+ const o = t.style.item(s);
27
+ o.startsWith("--bfrs-") && (r[o] = t.style.getPropertyValue(o));
27
28
  }
28
29
  return r;
29
- }, T = v(({ className: e, colorScheme: t = "light", theme: r, style: o, ...s }, n) => {
30
- const [c, y] = m(null), f = l(() => N(R(r ?? {})), [r]), b = l(() => ({ ...f, ...o }), [o, f]), p = S(
31
- (u) => {
32
- y(u), M(n, u);
30
+ }, w = S(({ analytics: t, className: e, colorScheme: r = "light", theme: s, style: o, ...n }, c) => {
31
+ const [f, b] = d(null), u = i(() => V(M(s ?? {})), [s]), p = i(() => ({ ...u, ...o }), [o, u]), h = g(
32
+ (m) => {
33
+ b(m), T(c, m);
33
34
  },
34
- [n]
35
- ), h = l(
35
+ [c]
36
+ ), v = i(
36
37
  () => ({
37
- root: c,
38
- colorScheme: t
38
+ root: f,
39
+ colorScheme: r
39
40
  }),
40
- [t, c]
41
+ [r, f]
41
42
  );
42
- return /* @__PURE__ */ i(d.Provider, { value: h, children: /* @__PURE__ */ i(
43
+ return /* @__PURE__ */ l(N, { emit: t, children: /* @__PURE__ */ l(y.Provider, { value: v, children: /* @__PURE__ */ l(
43
44
  "div",
44
45
  {
45
- ref: p,
46
+ ref: h,
46
47
  "data-bfrs-root": "",
47
- "data-bfrs-color-scheme": t,
48
- className: B("bfrs", e),
49
- style: b,
50
- ...s
48
+ "data-bfrs-color-scheme": r,
49
+ className: C("bfrs", e),
50
+ style: p,
51
+ ...n
51
52
  }
52
- ) });
53
+ ) }) });
53
54
  });
54
- T.displayName = "BfrsProvider";
55
- function A({ children: e }) {
56
- const { root: t, colorScheme: r } = g(d), [o, s] = m(() => a(t, r));
55
+ w.displayName = "BfrsProvider";
56
+ function F({ children: t }) {
57
+ const { root: e, colorScheme: r } = P(y), [s, o] = d(() => a(e, r));
57
58
  return x(() => {
58
- if (C(), s(a(t, r)), !t || typeof globalThis.MutationObserver > "u")
59
+ if (R(), o(a(e, r)), !e || typeof globalThis.MutationObserver > "u")
59
60
  return;
60
61
  const n = new globalThis.MutationObserver(() => {
61
- s(a(t, r));
62
+ o(a(e, r));
62
63
  });
63
- return n.observe(t, {
64
+ return n.observe(e, {
64
65
  attributes: !0,
65
66
  attributeFilter: ["style", "data-bfrs-color-scheme"]
66
67
  }), () => n.disconnect();
67
- }, [r, t]), /* @__PURE__ */ i("div", { className: "bfrs", "data-bfrs-portal": "", "data-bfrs-color-scheme": r, style: o, children: e });
68
+ }, [r, e]), /* @__PURE__ */ l("div", { className: "bfrs", "data-bfrs-portal": "", "data-bfrs-color-scheme": r, style: s, children: t });
68
69
  }
69
70
  export {
70
- A as BfrsPortalScope,
71
- T as BfrsProvider
71
+ F as BfrsPortalScope,
72
+ w as BfrsProvider
72
73
  };
73
74
  //# sourceMappingURL=BfrsProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BfrsProvider.js","sources":["../../../../../src/components/ui/providers/BfrsProvider/BfrsProvider.tsx"],"sourcesContent":["import {\n createContext,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n type CSSProperties,\n type HTMLAttributes,\n type MutableRefObject,\n type ReactNode,\n type Ref\n} from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { ensureDocumentStyles } from \"@/lib/documentStyles\";\nimport { createAgenticThemeVariables, type AgenticThemeOverrides } from \"@/theme\";\n\nexport type BfrsColorScheme = \"light\" | \"dark\";\n\nexport type BfrsProviderProps = HTMLAttributes<HTMLDivElement> & {\n theme?: AgenticThemeOverrides;\n colorScheme?: BfrsColorScheme;\n};\n\ntype BfrsStyleScopeContextValue = {\n root: HTMLElement | null;\n colorScheme?: BfrsColorScheme;\n};\n\nconst BfrsStyleScopeContext = createContext<BfrsStyleScopeContextValue>({\n root: null\n});\n\nfunction assignRef<T>(ref: Ref<T> | undefined, value: T | null) {\n if (!ref) {\n return;\n }\n\n if (typeof ref === \"function\") {\n ref(value);\n return;\n }\n\n (ref as MutableRefObject<T | null>).current = value;\n}\n\nconst toStyleProperties = (variables: Record<string, string | undefined>) => variables as CSSProperties;\n\nconst collectBfrsInlineStyle = (root: HTMLElement | null, colorScheme?: BfrsColorScheme): CSSProperties => {\n const style: Record<string, string> = {\n display: \"contents\"\n };\n\n if (colorScheme) {\n style.colorScheme = colorScheme;\n }\n\n if (!root) {\n return style as CSSProperties;\n }\n\n for (let index = 0; index < root.style.length; index += 1) {\n const name = root.style.item(index);\n\n if (name.startsWith(\"--bfrs-\")) {\n style[name] = root.style.getPropertyValue(name);\n }\n }\n\n return style as CSSProperties;\n};\n\nexport const BfrsProvider = forwardRef<HTMLDivElement, BfrsProviderProps>(({ className, colorScheme = \"light\", theme, style, ...props }, ref) => {\n const [root, setRoot] = useState<HTMLDivElement | null>(null);\n const themeStyle = useMemo(() => toStyleProperties(createAgenticThemeVariables(theme ?? {})), [theme]);\n const mergedStyle = useMemo(() => ({ ...themeStyle, ...style }), [style, themeStyle]);\n\n const handleRef = useCallback(\n (node: HTMLDivElement | null) => {\n setRoot(node);\n assignRef(ref, node);\n },\n [ref]\n );\n\n const contextValue = useMemo(\n () => ({\n root,\n colorScheme\n }),\n [colorScheme, root]\n );\n\n return (\n <BfrsStyleScopeContext.Provider value={contextValue}>\n <div\n ref={handleRef}\n data-bfrs-root=\"\"\n data-bfrs-color-scheme={colorScheme}\n className={cn(\"bfrs\", className)}\n style={mergedStyle}\n {...props}\n />\n </BfrsStyleScopeContext.Provider>\n );\n});\n\nBfrsProvider.displayName = \"BfrsProvider\";\n\nexport function BfrsStyleScope({ children, root, colorScheme = \"light\" }: { children: ReactNode; root: HTMLElement | null; colorScheme?: BfrsColorScheme }) {\n const contextValue = useMemo(\n () => ({\n root,\n colorScheme\n }),\n [colorScheme, root]\n );\n\n return <BfrsStyleScopeContext.Provider value={contextValue}>{children}</BfrsStyleScopeContext.Provider>;\n}\n\nexport function BfrsPortalScope({ children }: { children: ReactNode }) {\n const { root, colorScheme } = useContext(BfrsStyleScopeContext);\n const [portalStyle, setPortalStyle] = useState<CSSProperties>(() => collectBfrsInlineStyle(root, colorScheme));\n\n useEffect(() => {\n // Overlays portal to <body>; make sure the document carries the library\n // stylesheet so portaled content stays styled.\n ensureDocumentStyles();\n setPortalStyle(collectBfrsInlineStyle(root, colorScheme));\n\n if (!root || typeof globalThis.MutationObserver === \"undefined\") {\n return undefined;\n }\n\n const observer = new globalThis.MutationObserver(() => {\n setPortalStyle(collectBfrsInlineStyle(root, colorScheme));\n });\n\n observer.observe(root, {\n attributes: true,\n attributeFilter: [\"style\", \"data-bfrs-color-scheme\"]\n });\n\n return () => observer.disconnect();\n }, [colorScheme, root]);\n\n return (\n <div className=\"bfrs\" data-bfrs-portal=\"\" data-bfrs-color-scheme={colorScheme} style={portalStyle}>\n {children}\n </div>\n );\n}\n"],"names":["BfrsStyleScopeContext","createContext","assignRef","ref","value","toStyleProperties","variables","collectBfrsInlineStyle","root","colorScheme","style","index","name","BfrsProvider","forwardRef","className","theme","props","setRoot","useState","themeStyle","useMemo","createAgenticThemeVariables","mergedStyle","handleRef","useCallback","node","contextValue","jsx","cn","BfrsPortalScope","children","useContext","portalStyle","setPortalStyle","useEffect","ensureDocumentStyles","observer"],"mappings":";;;;;AA8BA,MAAMA,IAAwBC,EAA0C;AAAA,EACtE,MAAM;AACR,CAAC;AAED,SAASC,EAAaC,GAAyBC,GAAiB;AAC9D,MAAKD,GAIL;AAAA,QAAI,OAAOA,KAAQ,YAAY;AAC7B,MAAAA,EAAIC,CAAK;AACT;AAAA,IACF;AAEC,IAAAD,EAAmC,UAAUC;AAAA;AAChD;AAEA,MAAMC,IAAoB,CAACC,MAAkDA,GAEvEC,IAAyB,CAACC,GAA0BC,MAAiD;AACzG,QAAMC,IAAgC;AAAA,IACpC,SAAS;AAAA,EAAA;AAOX,MAJID,MACFC,EAAM,cAAcD,IAGlB,CAACD;AACH,WAAOE;AAGT,WAASC,IAAQ,GAAGA,IAAQH,EAAK,MAAM,QAAQG,KAAS,GAAG;AACzD,UAAMC,IAAOJ,EAAK,MAAM,KAAKG,CAAK;AAElC,IAAIC,EAAK,WAAW,SAAS,MAC3BF,EAAME,CAAI,IAAIJ,EAAK,MAAM,iBAAiBI,CAAI;AAAA,EAElD;AAEA,SAAOF;AACT,GAEaG,IAAeC,EAA8C,CAAC,EAAE,WAAAC,GAAW,aAAAN,IAAc,SAAS,OAAAO,GAAO,OAAAN,GAAO,GAAGO,EAAA,GAASd,MAAQ;AAC/I,QAAM,CAACK,G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WAAA4B,EAAS,QAAQ7B,GAAM;AAAA,MACrB,YAAY;AAAA,MACZ,iBAAiB,CAAC,SAAS,wBAAwB;AAAA,IAAA,CACpD,GAEM,MAAM6B,EAAS,WAAA;AAAA,EACxB,GAAG,CAAC5B,GAAaD,CAAI,CAAC,GAGpB,gBAAAoB,EAAC,OAAA,EAAI,WAAU,QAAO,oBAAiB,IAAG,0BAAwBnB,GAAa,OAAOwB,GACnF,UAAAF,EAAA,CACH;AAEJ;"}
1
+ {"version":3,"file":"BfrsProvider.js","sources":["../../../../../src/components/ui/providers/BfrsProvider/BfrsProvider.tsx"],"sourcesContent":["import {\n createContext,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n type CSSProperties,\n type HTMLAttributes,\n type MutableRefObject,\n type ReactNode,\n type Ref\n} from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { ensureDocumentStyles } from \"@/lib/documentStyles\";\nimport { createAgenticThemeVariables, type AgenticThemeOverrides } from \"@/theme\";\nimport { BfrsAnalyticsProvider } from \"../BfrsAnalyticsProvider/BfrsAnalyticsProvider\";\nimport type { BfrsAnalyticsSink } from \"../BfrsAnalyticsProvider/analyticsContext\";\n\nexport type BfrsColorScheme = \"light\" | \"dark\";\n\nexport type BfrsProviderProps = HTMLAttributes<HTMLDivElement> & {\n theme?: AgenticThemeOverrides;\n colorScheme?: BfrsColorScheme;\n /**\n * Where library-owned interactions are reported, wired once per app:\n *\n * ```tsx\n * <BfrsProvider analytics={(event) => analytics.track(event.name, event.properties)}>\n * ```\n *\n * Nothing in the library touches `gtag`, `dataLayer` or a provider SDK — it\n * hands the event here and the app decides what happens to it. Omitted, the\n * library reports nothing.\n */\n analytics?: BfrsAnalyticsSink;\n};\n\ntype BfrsStyleScopeContextValue = {\n root: HTMLElement | null;\n colorScheme?: BfrsColorScheme;\n};\n\nconst BfrsStyleScopeContext = createContext<BfrsStyleScopeContextValue>({\n root: null\n});\n\nfunction assignRef<T>(ref: Ref<T> | undefined, value: T | null) {\n if (!ref) {\n return;\n }\n\n if (typeof ref === \"function\") {\n ref(value);\n return;\n }\n\n (ref as MutableRefObject<T | null>).current = value;\n}\n\nconst toStyleProperties = (variables: Record<string, string | undefined>) => variables as CSSProperties;\n\nconst collectBfrsInlineStyle = (root: HTMLElement | null, colorScheme?: BfrsColorScheme): CSSProperties => {\n const style: Record<string, string> = {\n display: \"contents\"\n };\n\n if (colorScheme) {\n style.colorScheme = colorScheme;\n }\n\n if (!root) {\n return style as CSSProperties;\n }\n\n for (let index = 0; index < root.style.length; index += 1) {\n const name = root.style.item(index);\n\n if (name.startsWith(\"--bfrs-\")) {\n style[name] = root.style.getPropertyValue(name);\n }\n }\n\n return style as CSSProperties;\n};\n\nexport const BfrsProvider = forwardRef<HTMLDivElement, BfrsProviderProps>(({ analytics, className, colorScheme = \"light\", theme, style, ...props }, ref) => {\n const [root, setRoot] = useState<HTMLDivElement | null>(null);\n const themeStyle = useMemo(() => toStyleProperties(createAgenticThemeVariables(theme ?? {})), [theme]);\n const mergedStyle = useMemo(() => ({ ...themeStyle, ...style }), [style, themeStyle]);\n\n const handleRef = useCallback(\n (node: HTMLDivElement | null) => {\n setRoot(node);\n assignRef(ref, node);\n },\n [ref]\n );\n\n const contextValue = useMemo(\n () => ({\n root,\n colorScheme\n }),\n [colorScheme, root]\n );\n\n return (\n <BfrsAnalyticsProvider emit={analytics}>\n <BfrsStyleScopeContext.Provider value={contextValue}>\n <div\n ref={handleRef}\n data-bfrs-root=\"\"\n data-bfrs-color-scheme={colorScheme}\n className={cn(\"bfrs\", className)}\n style={mergedStyle}\n {...props}\n />\n </BfrsStyleScopeContext.Provider>\n </BfrsAnalyticsProvider>\n );\n});\n\nBfrsProvider.displayName = \"BfrsProvider\";\n\nexport function BfrsStyleScope({ children, root, colorScheme = \"light\" }: { children: ReactNode; root: HTMLElement | null; colorScheme?: BfrsColorScheme }) {\n const contextValue = useMemo(\n () => ({\n root,\n colorScheme\n }),\n [colorScheme, root]\n );\n\n return <BfrsStyleScopeContext.Provider value={contextValue}>{children}</BfrsStyleScopeContext.Provider>;\n}\n\nexport function BfrsPortalScope({ children }: { children: ReactNode }) {\n const { root, colorScheme } = useContext(BfrsStyleScopeContext);\n const [portalStyle, setPortalStyle] = useState<CSSProperties>(() => collectBfrsInlineStyle(root, colorScheme));\n\n useEffect(() => {\n // Overlays portal to <body>; make sure the document carries the library\n // stylesheet so portaled content stays styled.\n ensureDocumentStyles();\n setPortalStyle(collectBfrsInlineStyle(root, colorScheme));\n\n if (!root || typeof globalThis.MutationObserver === \"undefined\") {\n return undefined;\n }\n\n const observer = new globalThis.MutationObserver(() => {\n setPortalStyle(collectBfrsInlineStyle(root, colorScheme));\n });\n\n observer.observe(root, {\n attributes: true,\n attributeFilter: [\"style\", \"data-bfrs-color-scheme\"]\n });\n\n return () => observer.disconnect();\n }, [colorScheme, root]);\n\n return (\n <div className=\"bfrs\" data-bfrs-portal=\"\" data-bfrs-color-scheme={colorScheme} style={portalStyle}>\n {children}\n </div>\n );\n}\n"],"names":["BfrsStyleScopeContext","createContext","assignRef","ref","value","toStyleProperties","variables","collectBfrsInlineStyle","root","colorScheme","style","index","name","BfrsProvider","forwardRef","analytics","className","theme","props","setRoot","useState","themeStyle","useMemo","createAgenticThemeVariables","mergedStyle","handleRef","useCallback","node","contextValue","jsx","BfrsAnalyticsProvider","cn","BfrsPortalScope","children","useContext","portalStyle","setPortalStyle","useEffect","ensureDocumentStyles","observer"],"mappings":";;;;;;AA4CA,MAAMA,IAAwBC,EAA0C;AAAA,EACtE,MAAM;AACR,CAAC;AAED,SAASC,EAAaC,GAAyBC,GAAiB;AAC9D,MAAKD,GAIL;AAAA,QAAI,OAAOA,KAAQ,YAAY;AAC7B,MAAAA,EAAIC,CAAK;AACT;AAAA,IACF;AAEC,IAAAD,EAAmC,UAAUC;AAAA;AAChD;AAEA,MAAMC,IAAoB,CAACC,MAAkDA,GAEvEC,IAAyB,CAACC,GAA0BC,MAAiD;AACzG,QAAM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