@bfrs/agentic-components 0.8.7 → 0.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BFRS_AGENTIC_COMPONENTS.md +1 -0
- package/dist/components/data-display/DataTable/TableSaveView.d.ts +14 -1
- package/dist/components/data-display/DataTable/TableSaveView.js +164 -144
- package/dist/components/data-display/DataTable/TableSaveView.js.map +1 -1
- package/dist/components/data-display/DataTable/TableViewSelector.d.ts +15 -1
- package/dist/components/data-display/DataTable/TableViewSelector.js +304 -296
- package/dist/components/data-display/DataTable/TableViewSelector.js.map +1 -1
- package/dist/components/data-display/DataTable/index.d.ts +1 -0
- package/dist/components/data-display/DataTable/savedViewAnalytics.d.ts +109 -0
- package/dist/components/data-display/DataTable/savedViewAnalytics.js +140 -0
- package/dist/components/data-display/DataTable/savedViewAnalytics.js.map +1 -0
- package/dist/components/ui/index.d.ts +2 -0
- package/dist/components/ui/patterns/ChatComposer/ChatComposer.d.ts +10 -0
- package/dist/components/ui/patterns/ChatComposer/ChatComposer.js +79 -78
- package/dist/components/ui/patterns/ChatComposer/ChatComposer.js.map +1 -1
- package/dist/components/ui/providers/BfrsAnalyticsProvider/BfrsAnalyticsProvider.d.ts +18 -0
- package/dist/components/ui/providers/BfrsAnalyticsProvider/BfrsAnalyticsProvider.js +12 -0
- package/dist/components/ui/providers/BfrsAnalyticsProvider/BfrsAnalyticsProvider.js.map +1 -0
- package/dist/components/ui/providers/BfrsAnalyticsProvider/analyticsContext.d.ts +78 -0
- package/dist/components/ui/providers/BfrsAnalyticsProvider/analyticsContext.js +41 -0
- package/dist/components/ui/providers/BfrsAnalyticsProvider/analyticsContext.js.map +1 -0
- package/dist/components/ui/providers/BfrsAnalyticsProvider/index.d.ts +4 -0
- package/dist/components/ui/providers/BfrsProvider/BfrsProvider.d.ts +25 -0
- package/dist/components/ui/providers/BfrsProvider/BfrsProvider.js +42 -41
- package/dist/components/ui/providers/BfrsProvider/BfrsProvider.js.map +1 -1
- package/dist/custom-elements.js +9330 -9141
- package/dist/custom-elements.js.map +1 -1
- package/dist/index.js +224 -213
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/scripts/lint/cli.cjs +6 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"savedViewAnalytics.js","sources":["../../../../src/components/data-display/DataTable/savedViewAnalytics.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport {\n emitBfrsAnalytics,\n useBfrsAnalyticsSink,\n type BfrsAnalyticsSink\n} from \"@/components/ui/providers/BfrsAnalyticsProvider/analyticsContext\";\nimport { ViewApiError } from \"./saveViewApi\";\n\n/**\n * The saved-view cluster's instrumentation.\n *\n * One place decides which moment is which event, so the four apps that render\n * these components report the same shape instead of four hand-wired\n * approximations of it. The apps supply the registered ids; see\n * `BfrsAnalyticsProvider` for why the moments live here and the names do not.\n *\n * Deliberately NOT emitted:\n * - the selector popover opening and closing. It is a dropdown trigger, not a\n * surface with content worth a reach metric, and it would be the highest\n * volume event in the cluster for no answerable question.\n * - the primary view the selector restores on mount. It is not an action the\n * seller took, and it arrives through the same callback as a real pick —\n * which is exactly why consumers could not tell them apart.\n * - a submission blocked by an empty or reserved name. Both dialogs DISABLE\n * their submit button in those states, and a disabled default button also\n * takes implicit submission (Enter) out of play, so the submit handler's\n * guard is unreachable from the UI. `form_validation_failed` would be an\n * event no seller could fire. The reserved-name warning the dialog shows is\n * field-level feedback, which that event's own definition excludes.\n */\n\n/** Per-moment id overrides. Each defaults to a suffix on the base `id`. */\nexport type SavedViewAnalyticsIds = {\n /** The selector control. Default: `id`. */\n view?: string;\n /** The save dialog and its form. Default: `${id}_save`. */\n save?: string;\n /** The rename dialog and its form. Default: `${id}_rename`. */\n rename?: string;\n /** The delete confirmation. Default: `${id}_delete`. */\n remove?: string;\n /** \"Reset saved filters\". Default: `${id}_reset`. */\n reset?: string;\n /** \"Set as primary\". Default: `${id}_set_primary`. */\n setPrimary?: string;\n /** \"Unset primary\". Default: `${id}_unset_primary`. */\n unsetPrimary?: string;\n};\n\n/**\n * What a component accepts for `analytics`.\n *\n * The string form is the one to reach for: `analytics=\"finance_saved_view\"` is\n * the registered id, and every other id derives from it. The object form exists\n * for the cases that genuinely differ — an app keeping ids it already ships, a\n * funnel name that is not the control's id, or a per-instance sink.\n */\nexport type SavedViewAnalyticsInput = string | SavedViewAnalyticsConfig;\n\nexport type SavedViewAnalyticsConfig = {\n /**\n * Stable registered id for this saved-view control, e.g. `finance_saved_view`.\n * A code from the app's analytics vocabulary — never a label or a screen title.\n */\n id: string;\n /**\n * Registered funnel id for saving a view. Defaults to `id`, so the outcome\n * events work out of the box; pass `null` to turn them off when the app has\n * no funnel registered under that name.\n */\n flow?: string | null;\n /** Containing surface, sent as `parent_element`. */\n parentElement?: string;\n /** Where this instance sits, sent as `entry_point`. */\n entryPoint?: string;\n /** Id overrides for individual moments. */\n ids?: SavedViewAnalyticsIds;\n /** Sink override. Defaults to the nearest `BfrsProvider`/`BfrsAnalyticsProvider`. */\n emit?: BfrsAnalyticsSink;\n};\n\n/** How an overlay in this cluster was dismissed. */\nexport type SavedViewCloseMethod = \"close_icon\" | \"cancel\" | \"outside\" | \"esc\" | \"completed\";\n\nexport type SavedViewAnalytics = {\n /** A seller picked a saved view. Never the mount-time restore. */\n viewSelected: () => void;\n /** A seller picked the built-in, unsaved default view. */\n defaultViewSelected: () => void;\n setPrimary: () => void;\n unsetPrimary: () => void;\n renameOpened: () => void;\n renameDismissed: (closeMethod: SavedViewCloseMethod) => void;\n renameSubmitted: () => void;\n deleteOpened: () => void;\n deleteDismissed: (closeMethod: SavedViewCloseMethod) => void;\n deleteConfirmed: () => void;\n resetFilters: () => void;\n saveOpened: () => void;\n saveDismissed: (closeMethod: SavedViewCloseMethod) => void;\n /** The save request was dispatched. Intent — it asserts nothing about the result. */\n saveSubmitted: () => void;\n saveCompleted: () => void;\n /** The backend answered with an existing view instead of creating one. */\n saveRejectedAsDuplicate: () => void;\n saveFailed: (error: unknown) => void;\n};\n\n/**\n * Observed outcome of a failed save.\n *\n * Mirrors the platform's own classification: an answered refusal is `rejected`,\n * an answer we cannot read as a verdict (408 or 5xx) is `unknown` because the\n * view may well have been created server-side, and no readable response at all\n * is `network_error`. The distinction matters here specifically — a 504 that\n * created the view must not be counted as a confirmed failure.\n */\nfunction resultStateForError(error: unknown): \"rejected\" | \"unknown\" | \"network_error\" {\n const status = error instanceof ViewApiError ? error.status : undefined;\n\n if (status === undefined) return \"network_error\";\n if (status === 408 || status >= 500) return \"unknown\";\n if (status >= 400) return \"rejected\";\n return \"unknown\";\n}\n\nconst noop = () => {};\n\n/** An emitter that does nothing, for a component with no analytics config. */\nconst SILENT: SavedViewAnalytics = {\n viewSelected: noop,\n defaultViewSelected: noop,\n setPrimary: noop,\n unsetPrimary: noop,\n renameOpened: noop,\n renameDismissed: noop,\n renameSubmitted: noop,\n deleteOpened: noop,\n deleteDismissed: noop,\n deleteConfirmed: noop,\n resetFilters: noop,\n saveOpened: noop,\n saveDismissed: noop,\n saveSubmitted: noop,\n saveCompleted: noop,\n saveRejectedAsDuplicate: noop,\n saveFailed: noop\n};\n\n/** A code these components can use as an id: lower_snake_case, bounded. */\nconst DERIVABLE_SCREEN_NAME = /^[a-z0-9]+(?:[._-][a-z0-9]+)*$/;\n\n/**\n * The id to report under when the app passed nothing.\n *\n * Adoption should be an `npm upgrade` and nothing else, so an app that passes\n * no `analytics` at all still reports — under an id derived from the\n * `screenName` these components already require for their store. `.` and `-`\n * become `_`, because a GA4 parameter value is a lower_snake_case code.\n *\n * screenName \"finance_invoices\" → finance_invoices_saved_view\n * screenName \"ndr_unsuccessful\" → ndr_unsuccessful_saved_view\n *\n * Two consequences worth knowing, both fixed by passing `analytics` explicitly:\n * - the id follows the screen, so a per-tab `screenName` produces a per-tab id.\n * An app that wants ONE id across its tabs passes one (`analytics=\"ndr_saved_view\"`).\n * - the derived id is not something anyone registered in the app's analytics\n * vocabulary. It reports from the moment of the upgrade; registering it (or\n * replacing it with a registered one) is the follow-up, not a blocker.\n */\nfunction deriveIdFromScreenName(screenName: string | undefined): string | undefined {\n if (!screenName) return undefined;\n const code = screenName.trim().toLowerCase();\n if (!DERIVABLE_SCREEN_NAME.test(code)) return undefined;\n const normalized = code.replace(/[.-]/g, \"_\");\n return `${normalized}_saved_view`.length <= 60 ? `${normalized}_saved_view` : undefined;\n}\n\n/**\n * `\"finance_saved_view\"` → `{ id: \"finance_saved_view\" }`, and nothing at all →\n * an id derived from `screenName` so an upgrade is the whole integration.\n */\nexport function toSavedViewAnalyticsConfig(\n input: SavedViewAnalyticsInput | undefined,\n screenName?: string\n): SavedViewAnalyticsConfig | undefined {\n if (typeof input === \"string\") return { id: input };\n if (input) return input.id ? input : { ...input, id: deriveIdFromScreenName(screenName) ?? \"\" };\n\n const derived = deriveIdFromScreenName(screenName);\n return derived ? { id: derived } : undefined;\n}\n\nexport function createSavedViewAnalytics(\n input: SavedViewAnalyticsInput | undefined,\n contextSink: BfrsAnalyticsSink | null,\n screenName?: string\n): SavedViewAnalytics {\n const config = toSavedViewAnalyticsConfig(input, screenName);\n const sink = config?.emit ?? contextSink;\n if (!config || !config.id || !sink) return SILENT;\n\n const { id, parentElement, entryPoint, ids } = config;\n // The funnel defaults to the control's own id, so the outcome events are not\n // something a caller has to remember to switch on. `flow: null` opts out.\n const flow = config.flow === null ? undefined : (config.flow ?? id);\n const viewId = ids?.view ?? id;\n const saveId = ids?.save ?? `${id}_save`;\n const renameId = ids?.rename ?? `${id}_rename`;\n const removeId = ids?.remove ?? `${id}_delete`;\n const resetId = ids?.reset ?? `${id}_reset`;\n const setPrimaryId = ids?.setPrimary ?? `${id}_set_primary`;\n const unsetPrimaryId = ids?.unsetPrimary ?? `${id}_unset_primary`;\n\n const cta = (elementName: string, ctaAction?: string) =>\n emitBfrsAnalytics(sink, \"cta_clicked\", {\n element_name: elementName,\n element_type: \"cta\",\n cta_action: ctaAction,\n parent_element: parentElement ?? viewId,\n entry_point: entryPoint\n });\n\n const overlayShown = (elementName: string) =>\n emitBfrsAnalytics(sink, \"modal_displayed\", {\n element_name: elementName,\n element_type: \"modal\",\n parent_element: parentElement ?? viewId,\n entry_point: entryPoint\n });\n\n const overlayDismissed = (elementName: string, closeMethod: SavedViewCloseMethod) =>\n emitBfrsAnalytics(sink, \"modal_dismissed\", {\n element_name: elementName,\n element_type: \"modal\",\n close_method: closeMethod\n });\n\n const formSubmitted = (elementName: string) =>\n emitBfrsAnalytics(sink, \"form_submitted\", {\n element_name: elementName,\n element_type: \"form\",\n parent_element: parentElement ?? viewId\n });\n\n const picked = (selectedOption: string) =>\n emitBfrsAnalytics(sink, \"dropdown_option_selected\", {\n element_name: viewId,\n element_type: \"dropdown\",\n selected_option: selectedOption,\n parent_element: parentElement,\n entry_point: entryPoint\n });\n\n return {\n // `selected_option` is which KIND of view was applied, never its name: a\n // saved view's name is the seller's own words.\n viewSelected: () => picked(\"saved_view\"),\n defaultViewSelected: () => picked(\"default_view\"),\n setPrimary: () => cta(setPrimaryId, \"set_primary\"),\n unsetPrimary: () => cta(unsetPrimaryId, \"unset_primary\"),\n renameOpened: () => overlayShown(renameId),\n renameDismissed: (closeMethod) => overlayDismissed(renameId, closeMethod),\n renameSubmitted: () => formSubmitted(renameId),\n deleteOpened: () => overlayShown(removeId),\n deleteDismissed: (closeMethod) => overlayDismissed(removeId, closeMethod),\n deleteConfirmed: () => cta(removeId, \"delete\"),\n resetFilters: () => cta(resetId, \"reset\"),\n saveOpened: () => overlayShown(saveId),\n saveDismissed: (closeMethod) => overlayDismissed(saveId, closeMethod),\n saveSubmitted: () => formSubmitted(saveId),\n saveCompleted: () => {\n if (!flow) return;\n emitBfrsAnalytics(sink, \"workflow_completed\", { flow_name: flow, result_state: \"success\" });\n },\n // A backend \"soft duplicate\" echoes back a pre-existing view instead of\n // creating one. It is an answered refusal, not a save — counting it as a\n // success would overstate the funnel it completes.\n saveRejectedAsDuplicate: () => {\n if (!flow) return;\n emitBfrsAnalytics(sink, \"workflow_failed\", {\n flow_name: flow,\n result_state: \"rejected\",\n error_code: \"duplicate_name\"\n });\n },\n saveFailed: (error) => {\n if (!flow) return;\n emitBfrsAnalytics(sink, \"workflow_failed\", {\n flow_name: flow,\n result_state: resultStateForError(error)\n });\n }\n };\n}\n\n/**\n * The saved-view emitter for one component instance.\n *\n * `screenName` is the component's own prop. Passing it here is what makes the\n * zero-config case work: with no `analytics` prop and a host bridge installed,\n * the id is derived from it.\n */\nexport function useSavedViewAnalytics(\n input: SavedViewAnalyticsInput | undefined,\n screenName?: string\n): SavedViewAnalytics {\n const contextSink = useBfrsAnalyticsSink();\n const config = toSavedViewAnalyticsConfig(input, screenName);\n\n return useMemo(\n () => createSavedViewAnalytics(config, contextSink),\n // The config is an inline object at every call site, so depend on its\n // fields rather than its identity: a new object each render would otherwise\n // rebuild the emitter on every keystroke in the name field.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n contextSink,\n screenName,\n config?.emit,\n config?.id,\n config?.flow,\n config?.parentElement,\n config?.entryPoint,\n config?.ids?.view,\n config?.ids?.save,\n config?.ids?.rename,\n config?.ids?.remove,\n config?.ids?.reset,\n config?.ids?.setPrimary,\n config?.ids?.unsetPrimary\n ]\n );\n}\n"],"names":["resultStateForError","error","status","ViewApiError","noop","SILENT","DERIVABLE_SCREEN_NAME","deriveIdFromScreenName","screenName","code","normalized","toSavedViewAnalyticsConfig","input","derived","createSavedViewAnalytics","contextSink","config","sink","id","parentElement","entryPoint","ids","flow","viewId","saveId","renameId","removeId","resetId","setPrimaryId","unsetPrimaryId","cta","elementName","ctaAction","emitBfrsAnalytics","overlayShown","overlayDismissed","closeMethod","formSubmitted","picked","selectedOption","useSavedViewAnalytics","useBfrsAnalyticsSink","useMemo","_a","_b","_c","_d","_e","_f","_g"],"mappings":";;;AAqHA,SAASA,EAAoBC,GAA0D;AACrF,QAAMC,IAASD,aAAiBE,IAAeF,EAAM,SAAS;AAE9D,SAAIC,MAAW,SAAkB,kBAC7BA,MAAW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D,CAAW;AAAA;AAAA;AAAA;AAAA;AAAA,IAKlD;AAAA,MACEA;AAAA,MACAP;AAAA,MACAQ,KAAA,gBAAAA,EAAQ;AAAA,MACRA,KAAA,gBAAAA,EAAQ;AAAA,MACRA,KAAA,gBAAAA,EAAQ;AAAA,MACRA,KAAA,gBAAAA,EAAQ;AAAA,MACRA,KAAA,gBAAAA,EAAQ;AAAA,OACR2B,IAAA3B,KAAA,gBAAAA,EAAQ,QAAR,gBAAA2B,EAAa;AAAA,OACbC,IAAA5B,KAAA,gBAAAA,EAAQ,QAAR,gBAAA4B,EAAa;AAAA,OACbC,IAAA7B,KAAA,gBAAAA,EAAQ,QAAR,gBAAA6B,EAAa;AAAA,OACbC,IAAA9B,KAAA,gBAAAA,EAAQ,QAAR,gBAAA8B,EAAa;AAAA,OACbC,IAAA/B,KAAA,gBAAAA,EAAQ,QAAR,gBAAA+B,EAAa;AAAA,OACbC,IAAAhC,KAAA,gBAAAA,EAAQ,QAAR,gBAAAgC,EAAa;AAAA,OACbC,IAAAjC,KAAA,gBAAAA,EAAQ,QAAR,gBAAAiC,EAAa;AAAA,IAAA;AAAA,EACf;AAEJ;"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { BfrsProvider } from './providers/BfrsProvider';
|
|
2
2
|
export type { BfrsColorScheme, BfrsProviderProps } from './providers/BfrsProvider';
|
|
3
|
+
export { BfrsAnalyticsProvider, emitBfrsAnalytics, getBfrsAnalyticsSink, setBfrsAnalyticsSink, useBfrsAnalyticsSink } from './providers/BfrsAnalyticsProvider';
|
|
4
|
+
export type { BfrsAnalyticsEvent, BfrsAnalyticsEventName, BfrsAnalyticsProperties, BfrsAnalyticsProviderProps, BfrsAnalyticsSink } from './providers/BfrsAnalyticsProvider';
|
|
3
5
|
export * from './primitives/Box';
|
|
4
6
|
export * from './primitives/Container';
|
|
5
7
|
export * from './primitives/Paper';
|
|
@@ -3,6 +3,11 @@ export type ChatComposerProps = Omit<TextareaHTMLAttributes<HTMLTextAreaElement>
|
|
|
3
3
|
value: string;
|
|
4
4
|
onValueChange: (value: string) => void;
|
|
5
5
|
onSubmit?: () => void;
|
|
6
|
+
/**
|
|
7
|
+
* Whether there is something to send. Defaults to a non-blank `value`; pass it
|
|
8
|
+
* when something else counts too, e.g. an attached file with no message.
|
|
9
|
+
*/
|
|
10
|
+
canSubmit?: boolean;
|
|
6
11
|
loading?: boolean;
|
|
7
12
|
disabled?: boolean;
|
|
8
13
|
/** `"sm"` is a compact composer for inline/sidebar placements; `"md"` is the default. */
|
|
@@ -20,6 +25,11 @@ export declare const ChatComposer: import('react').ForwardRefExoticComponent<Omi
|
|
|
20
25
|
value: string;
|
|
21
26
|
onValueChange: (value: string) => void;
|
|
22
27
|
onSubmit?: () => void;
|
|
28
|
+
/**
|
|
29
|
+
* Whether there is something to send. Defaults to a non-blank `value`; pass it
|
|
30
|
+
* when something else counts too, e.g. an attached file with no message.
|
|
31
|
+
*/
|
|
32
|
+
canSubmit?: boolean;
|
|
23
33
|
loading?: boolean;
|
|
24
34
|
disabled?: boolean;
|
|
25
35
|
/** `"sm"` is a compact composer for inline/sidebar placements; `"md"` is the default. */
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { ArrowUp as
|
|
3
|
-
import { Plus as
|
|
4
|
-
import { forwardRef as
|
|
5
|
-
import
|
|
6
|
-
import { twRing as
|
|
7
|
-
import { IconButton as
|
|
8
|
-
const
|
|
1
|
+
import { jsxs as R, jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import { ArrowUp as P } from "../../../../node_modules/@phosphor-icons/react/dist/csr/ArrowUp.es.js";
|
|
3
|
+
import { Plus as S } from "../../../../node_modules/@phosphor-icons/react/dist/csr/Plus.es.js";
|
|
4
|
+
import { forwardRef as k } from "react";
|
|
5
|
+
import c from "@emotion/styled";
|
|
6
|
+
import { twRing as F } from "../../../../lib/emotionTw.js";
|
|
7
|
+
import { IconButton as m } from "../../../primitives/Button/Button.js";
|
|
8
|
+
const D = /* @__PURE__ */ c("form", {
|
|
9
9
|
label: "AgenticChatComposer-root",
|
|
10
|
-
shouldForwardProp: (
|
|
11
|
-
})(({ ownerState:
|
|
10
|
+
shouldForwardProp: (o) => o !== "ownerState"
|
|
11
|
+
})(({ ownerState: o }) => [
|
|
12
12
|
{
|
|
13
13
|
display: "flex",
|
|
14
14
|
alignItems: "flex-end",
|
|
@@ -24,27 +24,27 @@ const k = /* @__PURE__ */ p("form", {
|
|
|
24
24
|
"&:focus-within": {
|
|
25
25
|
"--tw-border-opacity": "1",
|
|
26
26
|
borderColor: "hsl(var(--bfrs-color-border-focus) / var(--tw-border-opacity, 1))",
|
|
27
|
-
...
|
|
27
|
+
...F("2px", "hsl(var(--bfrs-color-border-focus) / .2)")
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
// The compact variant's arbitrary 12px shadow class sat EARLIER in the
|
|
31
31
|
// compiled stylesheet than shadow-low, so shadow-low always won the cascade
|
|
32
32
|
// and the 12px shadow never took effect. Reproduced by not overriding the
|
|
33
33
|
// base shadow here.
|
|
34
|
-
|
|
35
|
-
height:
|
|
36
|
-
alignItems:
|
|
34
|
+
o.compact ? {
|
|
35
|
+
height: o.autoHeight ? "auto" : "42px",
|
|
36
|
+
alignItems: o.autoHeight ? "flex-end" : "center",
|
|
37
37
|
gap: ".5rem",
|
|
38
|
-
padding:
|
|
38
|
+
padding: o.compactPadding ?? "6px"
|
|
39
39
|
} : {
|
|
40
40
|
minHeight: "3.5rem",
|
|
41
41
|
gap: ".5rem",
|
|
42
42
|
padding: ".5rem"
|
|
43
43
|
}
|
|
44
|
-
]),
|
|
44
|
+
]), I = /* @__PURE__ */ c("textarea", {
|
|
45
45
|
label: "AgenticChatComposer-textarea",
|
|
46
|
-
shouldForwardProp: (
|
|
47
|
-
})(({ ownerState:
|
|
46
|
+
shouldForwardProp: (o) => o !== "ownerState"
|
|
47
|
+
})(({ ownerState: o }) => [
|
|
48
48
|
{
|
|
49
49
|
flex: "1 1 0%",
|
|
50
50
|
resize: "none",
|
|
@@ -68,7 +68,7 @@ const k = /* @__PURE__ */ p("form", {
|
|
|
68
68
|
cursor: "not-allowed"
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
|
-
|
|
71
|
+
o.compact ? {
|
|
72
72
|
maxHeight: "7rem",
|
|
73
73
|
minHeight: "1.5rem",
|
|
74
74
|
paddingTop: "1px",
|
|
@@ -83,8 +83,8 @@ const k = /* @__PURE__ */ p("form", {
|
|
|
83
83
|
fontSize: "1rem",
|
|
84
84
|
lineHeight: "1.5rem"
|
|
85
85
|
},
|
|
86
|
-
|
|
87
|
-
...
|
|
86
|
+
o.placeholderVariant === "large" ? {
|
|
87
|
+
...o.compact ? { paddingLeft: "10px" } : {},
|
|
88
88
|
"&::-moz-placeholder": {
|
|
89
89
|
fontSize: "14px",
|
|
90
90
|
lineHeight: "20px",
|
|
@@ -100,25 +100,25 @@ const k = /* @__PURE__ */ p("form", {
|
|
|
100
100
|
opacity: 1
|
|
101
101
|
}
|
|
102
102
|
} : null
|
|
103
|
-
]),
|
|
103
|
+
]), N = /* @__PURE__ */ c(m, {
|
|
104
104
|
label: "AgenticChatComposer-attachButton",
|
|
105
|
-
shouldForwardProp: (
|
|
106
|
-
})(({ ownerState:
|
|
107
|
-
|
|
105
|
+
shouldForwardProp: (o) => o !== "ownerState"
|
|
106
|
+
})(({ ownerState: o }) => [
|
|
107
|
+
o.compact && {
|
|
108
108
|
"&&": {
|
|
109
109
|
width: "1.5rem",
|
|
110
110
|
height: "1.5rem",
|
|
111
111
|
borderRadius: "var(--bfrs-radius-lg)"
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
]),
|
|
114
|
+
]), T = /* @__PURE__ */ c(m, {
|
|
115
115
|
label: "AgenticChatComposer-sendButton",
|
|
116
|
-
shouldForwardProp: (
|
|
117
|
-
})(({ ownerState:
|
|
118
|
-
|
|
116
|
+
shouldForwardProp: (o) => o !== "ownerState"
|
|
117
|
+
})(({ ownerState: o }) => [
|
|
118
|
+
o.compact && {
|
|
119
119
|
"&&": {
|
|
120
|
-
width:
|
|
121
|
-
height:
|
|
120
|
+
width: o.compactActionButtonSize === void 0 ? "1.5rem" : typeof o.compactActionButtonSize == "number" ? `${o.compactActionButtonSize}px` : o.compactActionButtonSize,
|
|
121
|
+
height: o.compactActionButtonSize === void 0 ? "1.5rem" : typeof o.compactActionButtonSize == "number" ? `${o.compactActionButtonSize}px` : o.compactActionButtonSize,
|
|
122
122
|
borderRadius: "var(--bfrs-radius-lg)"
|
|
123
123
|
},
|
|
124
124
|
"&&:disabled": {
|
|
@@ -127,79 +127,80 @@ const k = /* @__PURE__ */ p("form", {
|
|
|
127
127
|
opacity: 1
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
]),
|
|
130
|
+
]), j = k(
|
|
131
131
|
({
|
|
132
|
-
className:
|
|
133
|
-
value:
|
|
134
|
-
onValueChange:
|
|
132
|
+
className: o,
|
|
133
|
+
value: s,
|
|
134
|
+
onValueChange: h,
|
|
135
135
|
onSubmit: e,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
136
|
+
canSubmit: f,
|
|
137
|
+
loading: l,
|
|
138
|
+
disabled: i,
|
|
139
|
+
size: g = "md",
|
|
140
|
+
attachmentSlot: x,
|
|
141
|
+
actionSlot: u,
|
|
142
|
+
autoHeight: b = !1,
|
|
143
|
+
compactPadding: w,
|
|
144
|
+
compactActionButtonSize: y,
|
|
145
|
+
placeholderVariant: v = "default",
|
|
146
|
+
textareaClassName: C,
|
|
147
|
+
sendButtonClassName: z,
|
|
148
|
+
placeholder: A = "Ask me anything",
|
|
149
|
+
...B
|
|
150
|
+
}, H) => {
|
|
151
|
+
const t = g === "sm", n = t ? 14 : 18, d = t ? "xs" : "sm", p = f ?? s.trim() !== "";
|
|
152
|
+
return /* @__PURE__ */ R(D, { onSubmit: (r) => {
|
|
153
|
+
r.preventDefault(), !i && !l && p && (e == null || e());
|
|
154
|
+
}, ownerState: { compact: t, autoHeight: b, compactPadding: w }, className: o, children: [
|
|
155
|
+
x ?? /* @__PURE__ */ a(
|
|
156
|
+
N,
|
|
156
157
|
{
|
|
157
158
|
"aria-label": "Attach file",
|
|
158
159
|
type: "button",
|
|
159
|
-
icon: /* @__PURE__ */ a(
|
|
160
|
-
variant:
|
|
160
|
+
icon: /* @__PURE__ */ a(S, { size: n }),
|
|
161
|
+
variant: t ? "secondary" : "ghost",
|
|
161
162
|
size: d,
|
|
162
|
-
ownerState: { compact:
|
|
163
|
-
disabled:
|
|
163
|
+
ownerState: { compact: t },
|
|
164
|
+
disabled: i
|
|
164
165
|
}
|
|
165
166
|
),
|
|
166
167
|
/* @__PURE__ */ a(
|
|
167
|
-
|
|
168
|
+
I,
|
|
168
169
|
{
|
|
169
|
-
ref:
|
|
170
|
-
value:
|
|
171
|
-
disabled:
|
|
172
|
-
placeholder:
|
|
170
|
+
ref: H,
|
|
171
|
+
value: s,
|
|
172
|
+
disabled: i,
|
|
173
|
+
placeholder: A,
|
|
173
174
|
rows: 1,
|
|
174
|
-
ownerState: { compact:
|
|
175
|
-
className:
|
|
176
|
-
onChange: (r) =>
|
|
175
|
+
ownerState: { compact: t, placeholderVariant: v },
|
|
176
|
+
className: C,
|
|
177
|
+
onChange: (r) => h(r.target.value),
|
|
177
178
|
onKeyDown: (r) => {
|
|
178
|
-
r.key === "Enter" && !r.shiftKey && (r.preventDefault(),
|
|
179
|
+
r.key === "Enter" && !r.shiftKey && (r.preventDefault(), p && (e == null || e()));
|
|
179
180
|
},
|
|
180
|
-
...
|
|
181
|
+
...B
|
|
181
182
|
}
|
|
182
183
|
),
|
|
183
|
-
|
|
184
|
+
u,
|
|
184
185
|
/* @__PURE__ */ a(
|
|
185
|
-
|
|
186
|
+
T,
|
|
186
187
|
{
|
|
187
188
|
"aria-label": "Send message",
|
|
188
189
|
type: "submit",
|
|
189
|
-
icon: /* @__PURE__ */ a(
|
|
190
|
+
icon: /* @__PURE__ */ a(P, { size: n, weight: "bold" }),
|
|
190
191
|
variant: "primary",
|
|
191
192
|
size: d,
|
|
192
|
-
ownerState: { compact:
|
|
193
|
-
className:
|
|
194
|
-
loading:
|
|
195
|
-
disabled:
|
|
193
|
+
ownerState: { compact: t, compactActionButtonSize: y },
|
|
194
|
+
className: z,
|
|
195
|
+
loading: l,
|
|
196
|
+
disabled: i || !p
|
|
196
197
|
}
|
|
197
198
|
)
|
|
198
199
|
] });
|
|
199
200
|
}
|
|
200
201
|
);
|
|
201
|
-
|
|
202
|
+
j.displayName = "ChatComposer";
|
|
202
203
|
export {
|
|
203
|
-
|
|
204
|
+
j as ChatComposer
|
|
204
205
|
};
|
|
205
206
|
//# sourceMappingURL=ChatComposer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatComposer.js","sources":["../../../../../src/components/ui/patterns/ChatComposer/ChatComposer.tsx"],"sourcesContent":["import { ArrowUp, Plus } from \"@phosphor-icons/react\";\nimport { forwardRef, type FormEvent, type ReactNode, type TextareaHTMLAttributes } from \"react\";\nimport styled from \"@emotion/styled\";\nimport { twRing } from \"@/lib/emotionTw\";\nimport { IconButton } from \"../../actions/IconButton\";\n\nexport type ChatComposerProps = Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, \"onSubmit\"> & {\n value: string;\n onValueChange: (value: string) => void;\n onSubmit?: () => void;\n loading?: boolean;\n disabled?: boolean;\n /** `\"sm\"` is a compact composer for inline/sidebar placements; `\"md\"` is the default. */\n size?: \"sm\" | \"md\";\n attachmentSlot?: ReactNode;\n actionSlot?: ReactNode;\n autoHeight?: boolean;\n compactPadding?: string;\n compactActionButtonSize?: number | string;\n placeholderVariant?: \"default\" | \"large\";\n textareaClassName?: string;\n sendButtonClassName?: string;\n};\n\n/* Exact compiled output of the pre-migration Tailwind utilities. The compact\n * icon-button overrides use `&&` so they beat the Button's own size/disabled\n * rules — the same result tailwind-merge produced pre-migration. */\n\nconst ChatComposerRoot = /*#__PURE__*/ styled(\"form\", {\n label: \"AgenticChatComposer-root\",\n shouldForwardProp: (propName) => propName !== \"ownerState\"\n})<{ ownerState: { compact: boolean; autoHeight: boolean; compactPadding?: string } }>(({ ownerState }) => [\n {\n display: \"flex\",\n alignItems: \"flex-end\",\n borderRadius: \"var(--bfrs-radius-lg)\",\n borderWidth: \"1px\",\n \"--tw-border-opacity\": \"1\",\n borderColor: \"hsl(var(--bfrs-color-border) / var(--tw-border-opacity, 1))\",\n \"--tw-bg-opacity\": \"1\",\n backgroundColor: \"hsl(var(--bfrs-color-surface-card) / var(--tw-bg-opacity, 1))\",\n \"--tw-shadow\": \"var(--bfrs-shadow-low)\",\n \"--tw-shadow-colored\": \"var(--bfrs-shadow-low)\",\n boxShadow: \"var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)\",\n \"&:focus-within\": {\n \"--tw-border-opacity\": \"1\",\n borderColor: \"hsl(var(--bfrs-color-border-focus) / var(--tw-border-opacity, 1))\",\n ...twRing(\"2px\", \"hsl(var(--bfrs-color-border-focus) / .2)\")\n }\n },\n // The compact variant's arbitrary 12px shadow class sat EARLIER in the\n // compiled stylesheet than shadow-low, so shadow-low always won the cascade\n // and the 12px shadow never took effect. Reproduced by not overriding the\n // base shadow here.\n ownerState.compact\n ? {\n height: ownerState.autoHeight ? \"auto\" : \"42px\",\n alignItems: ownerState.autoHeight ? \"flex-end\" : \"center\",\n gap: \".5rem\",\n padding: ownerState.compactPadding ?? \"6px\"\n }\n : {\n minHeight: \"3.5rem\",\n gap: \".5rem\",\n padding: \".5rem\"\n }\n]);\n\nconst ChatComposerTextarea = /*#__PURE__*/ styled(\"textarea\", {\n label: \"AgenticChatComposer-textarea\",\n shouldForwardProp: (propName) => propName !== \"ownerState\"\n})<{ ownerState: { compact: boolean; placeholderVariant: \"default\" | \"large\" } }>(({ ownerState }) => [\n {\n flex: \"1 1 0%\",\n resize: \"none\",\n backgroundColor: \"transparent\",\n paddingLeft: \".25rem\",\n paddingRight: \".25rem\",\n lineHeight: \"1.25rem\",\n \"--tw-text-opacity\": \"1\",\n color: \"hsl(var(--bfrs-color-text-primary) / var(--tw-text-opacity, 1))\",\n outline: \"2px solid transparent\",\n outlineOffset: \"2px\",\n \"&::-moz-placeholder\": {\n \"--tw-text-opacity\": \"1\",\n color: \"rgb(var(--bfrs-color-text-placeholder) / var(--tw-text-opacity, 1))\"\n },\n \"&::placeholder\": {\n \"--tw-text-opacity\": \"1\",\n color: \"rgb(var(--bfrs-color-text-placeholder) / var(--tw-text-opacity, 1))\"\n },\n \"&:disabled\": {\n cursor: \"not-allowed\"\n }\n },\n ownerState.compact\n ? {\n maxHeight: \"7rem\",\n minHeight: \"1.5rem\",\n paddingTop: \"1px\",\n paddingBottom: \"1px\",\n fontSize: \"12px\",\n lineHeight: \"22.4px\"\n }\n : {\n maxHeight: \"9rem\",\n minHeight: \"2.25rem\",\n paddingTop: \".5rem\",\n paddingBottom: \".5rem\",\n fontSize: \"1rem\",\n lineHeight: \"1.5rem\"\n },\n ownerState.placeholderVariant === \"large\"\n ? {\n ...(ownerState.compact ? { paddingLeft: \"10px\" } : {}),\n \"&::-moz-placeholder\": {\n fontSize: \"14px\",\n lineHeight: \"20px\",\n \"--tw-text-opacity\": \"1\",\n color: \"hsl(var(--bfrs-color-text-muted) / var(--tw-text-opacity, 1))\",\n opacity: 1\n },\n \"&::placeholder\": {\n fontSize: \"14px\",\n lineHeight: \"20px\",\n \"--tw-text-opacity\": \"1\",\n color: \"hsl(var(--bfrs-color-text-muted) / var(--tw-text-opacity, 1))\",\n opacity: 1\n }\n }\n : null\n]);\n\nconst ChatComposerAttachButton = /*#__PURE__*/ styled(IconButton, {\n label: \"AgenticChatComposer-attachButton\",\n shouldForwardProp: (propName) => propName !== \"ownerState\"\n})<{ ownerState: { compact: boolean } }>(({ ownerState }) => [\n ownerState.compact && {\n \"&&\": {\n width: \"1.5rem\",\n height: \"1.5rem\",\n borderRadius: \"var(--bfrs-radius-lg)\"\n }\n }\n]);\n\nconst ChatComposerSendButton = /*#__PURE__*/ styled(IconButton, {\n label: \"AgenticChatComposer-sendButton\",\n shouldForwardProp: (propName) => propName !== \"ownerState\"\n})<{ ownerState: { compact: boolean; compactActionButtonSize?: number | string } }>(({ ownerState }) => [\n ownerState.compact && {\n \"&&\": {\n width:\n ownerState.compactActionButtonSize === undefined\n ? \"1.5rem\"\n : typeof ownerState.compactActionButtonSize === \"number\"\n ? `${ownerState.compactActionButtonSize}px`\n : ownerState.compactActionButtonSize,\n height:\n ownerState.compactActionButtonSize === undefined\n ? \"1.5rem\"\n : typeof ownerState.compactActionButtonSize === \"number\"\n ? `${ownerState.compactActionButtonSize}px`\n : ownerState.compactActionButtonSize,\n borderRadius: \"var(--bfrs-radius-lg)\"\n },\n \"&&:disabled\": {\n \"--tw-bg-opacity\": \"1\",\n backgroundColor: \"hsl(var(--bfrs-color-surface-muted) / var(--tw-bg-opacity, 1))\",\n opacity: 1\n }\n }\n]);\n\nexport const ChatComposer = forwardRef<HTMLTextAreaElement, ChatComposerProps>(\n (\n {\n className,\n value,\n onValueChange,\n onSubmit,\n loading,\n disabled,\n size = \"md\",\n attachmentSlot,\n actionSlot,\n autoHeight = false,\n compactPadding,\n compactActionButtonSize,\n placeholderVariant = \"default\",\n textareaClassName,\n sendButtonClassName,\n placeholder = \"Ask me anything\",\n ...props\n },\n ref\n ) => {\n const compact = size === \"sm\";\n const iconSize = compact ? 14 : 18;\n const iconButtonSize = compact ? \"xs\" : \"sm\";\n\n const handleSubmit = (event: FormEvent) => {\n event.preventDefault();\n if (!disabled && !loading && value.trim()) onSubmit?.();\n };\n\n return (\n <ChatComposerRoot onSubmit={handleSubmit} ownerState={{ compact, autoHeight, compactPadding }} className={className}>\n {attachmentSlot ?? (\n <ChatComposerAttachButton\n aria-label=\"Attach file\"\n type=\"button\"\n icon={<Plus size={iconSize} />}\n variant={compact ? \"secondary\" : \"ghost\"}\n size={iconButtonSize}\n ownerState={{ compact }}\n disabled={disabled}\n />\n )}\n <ChatComposerTextarea\n ref={ref}\n value={value}\n disabled={disabled}\n placeholder={placeholder}\n rows={1}\n ownerState={{ compact, placeholderVariant }}\n className={textareaClassName}\n onChange={(event) => onValueChange(event.target.value)}\n onKeyDown={(event) => {\n if (event.key === \"Enter\" && !event.shiftKey) {\n event.preventDefault();\n if (value.trim()) onSubmit?.();\n }\n }}\n {...props}\n />\n {actionSlot}\n <ChatComposerSendButton\n aria-label=\"Send message\"\n type=\"submit\"\n icon={<ArrowUp size={iconSize} weight=\"bold\" />}\n variant=\"primary\"\n size={iconButtonSize}\n ownerState={{ compact, compactActionButtonSize }}\n className={sendButtonClassName}\n loading={loading}\n disabled={disabled || !value.trim()}\n />\n </ChatComposerRoot>\n );\n }\n);\n\nChatComposer.displayName = \"ChatComposer\";\n"],"names":["ChatComposerRoot","propName","ownerState","twRing","ChatComposerTextarea","ChatComposerAttachButton","IconButton","ChatComposerSendButton","ChatComposer","forwardRef","className","value","onValueChange","onSubmit","loading","disabled","size","attachmentSlot","actionSlot","autoHeight","compactPadding","compactActionButtonSize","placeholderVariant","textareaClassName","sendButtonClassName","placeholder","props","ref","compact","iconSize","iconButtonSize","jsxs","event","jsx","Plus","ArrowUp"],"mappings":";;;;;;;AA4BA,MAAMA,sBAAwC,QAAQ;AAAA,EACpD,OAAO;AAAA,EACP,mBAAmB,CAACC,MAAaA,MAAa;AAChD,CAAC,EAAsF,CAAC,EAAE,YAAAC,QAAiB;AAAA,EACzG;AAAA,IACE,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,aAAa;AAAA,IACb,uBAAuB;AAAA,IACvB,aAAa;AAAA,IACb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U;AACpB,YAAIA,EAAM,QAAQ,WAAW,CAACA,EAAM,aAClCA,EAAM,eAAA,GACFrB,EAAM,KAAA,MAAQE,KAAA,QAAAA;AAAA,UAEtB;AAAA,UACC,GAAGa;AAAA,QAAA;AAAA,MAAA;AAAA,MAELR;AAAA,MACD,gBAAAe;AAAA,QAAC1B;AAAA,QAAA;AAAA,UACC,cAAW;AAAA,UACX,MAAK;AAAA,UACL,MAAM,gBAAA0B,EAACE,GAAA,EAAQ,MAAMN,GAAU,QAAO,QAAO;AAAA,UAC7C,SAAQ;AAAA,UACR,MAAMC;AAAA,UACN,YAAY,EAAE,SAAAF,GAAS,yBAAAP,EAAA;AAAA,UACvB,WAAWG;AAAA,UACX,SAAAV;AAAA,UACA,UAAUC,KAAY,CAACJ,EAAM,KAAA;AAAA,QAAK;AAAA,MAAA;AAAA,IACpC,GACF;AAAA,EAEJ;AACF;AAEAH,EAAa,cAAc;"}
|
|
1
|
+
{"version":3,"file":"ChatComposer.js","sources":["../../../../../src/components/ui/patterns/ChatComposer/ChatComposer.tsx"],"sourcesContent":["import { ArrowUp, Plus } from \"@phosphor-icons/react\";\nimport { forwardRef, type FormEvent, type ReactNode, type TextareaHTMLAttributes } from \"react\";\nimport styled from \"@emotion/styled\";\nimport { twRing } from \"@/lib/emotionTw\";\nimport { IconButton } from \"../../actions/IconButton\";\n\nexport type ChatComposerProps = Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, \"onSubmit\"> & {\n value: string;\n onValueChange: (value: string) => void;\n onSubmit?: () => void;\n /**\n * Whether there is something to send. Defaults to a non-blank `value`; pass it\n * when something else counts too, e.g. an attached file with no message.\n */\n canSubmit?: boolean;\n loading?: boolean;\n disabled?: boolean;\n /** `\"sm\"` is a compact composer for inline/sidebar placements; `\"md\"` is the default. */\n size?: \"sm\" | \"md\";\n attachmentSlot?: ReactNode;\n actionSlot?: ReactNode;\n autoHeight?: boolean;\n compactPadding?: string;\n compactActionButtonSize?: number | string;\n placeholderVariant?: \"default\" | \"large\";\n textareaClassName?: string;\n sendButtonClassName?: string;\n};\n\n/* Exact compiled output of the pre-migration Tailwind utilities. The compact\n * icon-button overrides use `&&` so they beat the Button's own size/disabled\n * rules — the same result tailwind-merge produced pre-migration. */\n\nconst ChatComposerRoot = /*#__PURE__*/ styled(\"form\", {\n label: \"AgenticChatComposer-root\",\n shouldForwardProp: (propName) => propName !== \"ownerState\"\n})<{ ownerState: { compact: boolean; autoHeight: boolean; compactPadding?: string } }>(({ ownerState }) => [\n {\n display: \"flex\",\n alignItems: \"flex-end\",\n borderRadius: \"var(--bfrs-radius-lg)\",\n borderWidth: \"1px\",\n \"--tw-border-opacity\": \"1\",\n borderColor: \"hsl(var(--bfrs-color-border) / var(--tw-border-opacity, 1))\",\n \"--tw-bg-opacity\": \"1\",\n backgroundColor: \"hsl(var(--bfrs-color-surface-card) / var(--tw-bg-opacity, 1))\",\n \"--tw-shadow\": \"var(--bfrs-shadow-low)\",\n \"--tw-shadow-colored\": \"var(--bfrs-shadow-low)\",\n boxShadow: \"var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)\",\n \"&:focus-within\": {\n \"--tw-border-opacity\": \"1\",\n borderColor: \"hsl(var(--bfrs-color-border-focus) / var(--tw-border-opacity, 1))\",\n ...twRing(\"2px\", \"hsl(var(--bfrs-color-border-focus) / .2)\")\n }\n },\n // The compact variant's arbitrary 12px shadow class sat EARLIER in the\n // compiled stylesheet than shadow-low, so shadow-low always won the cascade\n // and the 12px shadow never took effect. Reproduced by not overriding the\n // base shadow here.\n ownerState.compact\n ? {\n height: ownerState.autoHeight ? \"auto\" : \"42px\",\n alignItems: ownerState.autoHeight ? \"flex-end\" : \"center\",\n gap: \".5rem\",\n padding: ownerState.compactPadding ?? \"6px\"\n }\n : {\n minHeight: \"3.5rem\",\n gap: \".5rem\",\n padding: \".5rem\"\n }\n]);\n\nconst ChatComposerTextarea = /*#__PURE__*/ styled(\"textarea\", {\n label: \"AgenticChatComposer-textarea\",\n shouldForwardProp: (propName) => propName !== \"ownerState\"\n})<{ ownerState: { compact: boolean; placeholderVariant: \"default\" | \"large\" } }>(({ ownerState }) => [\n {\n flex: \"1 1 0%\",\n resize: \"none\",\n backgroundColor: \"transparent\",\n paddingLeft: \".25rem\",\n paddingRight: \".25rem\",\n lineHeight: \"1.25rem\",\n \"--tw-text-opacity\": \"1\",\n color: \"hsl(var(--bfrs-color-text-primary) / var(--tw-text-opacity, 1))\",\n outline: \"2px solid transparent\",\n outlineOffset: \"2px\",\n \"&::-moz-placeholder\": {\n \"--tw-text-opacity\": \"1\",\n color: \"rgb(var(--bfrs-color-text-placeholder) / var(--tw-text-opacity, 1))\"\n },\n \"&::placeholder\": {\n \"--tw-text-opacity\": \"1\",\n color: \"rgb(var(--bfrs-color-text-placeholder) / var(--tw-text-opacity, 1))\"\n },\n \"&:disabled\": {\n cursor: \"not-allowed\"\n }\n },\n ownerState.compact\n ? {\n maxHeight: \"7rem\",\n minHeight: \"1.5rem\",\n paddingTop: \"1px\",\n paddingBottom: \"1px\",\n fontSize: \"12px\",\n lineHeight: \"22.4px\"\n }\n : {\n maxHeight: \"9rem\",\n minHeight: \"2.25rem\",\n paddingTop: \".5rem\",\n paddingBottom: \".5rem\",\n fontSize: \"1rem\",\n lineHeight: \"1.5rem\"\n },\n ownerState.placeholderVariant === \"large\"\n ? {\n ...(ownerState.compact ? { paddingLeft: \"10px\" } : {}),\n \"&::-moz-placeholder\": {\n fontSize: \"14px\",\n lineHeight: \"20px\",\n \"--tw-text-opacity\": \"1\",\n color: \"hsl(var(--bfrs-color-text-muted) / var(--tw-text-opacity, 1))\",\n opacity: 1\n },\n \"&::placeholder\": {\n fontSize: \"14px\",\n lineHeight: \"20px\",\n \"--tw-text-opacity\": \"1\",\n color: \"hsl(var(--bfrs-color-text-muted) / var(--tw-text-opacity, 1))\",\n opacity: 1\n }\n }\n : null\n]);\n\nconst ChatComposerAttachButton = /*#__PURE__*/ styled(IconButton, {\n label: \"AgenticChatComposer-attachButton\",\n shouldForwardProp: (propName) => propName !== \"ownerState\"\n})<{ ownerState: { compact: boolean } }>(({ ownerState }) => [\n ownerState.compact && {\n \"&&\": {\n width: \"1.5rem\",\n height: \"1.5rem\",\n borderRadius: \"var(--bfrs-radius-lg)\"\n }\n }\n]);\n\nconst ChatComposerSendButton = /*#__PURE__*/ styled(IconButton, {\n label: \"AgenticChatComposer-sendButton\",\n shouldForwardProp: (propName) => propName !== \"ownerState\"\n})<{ ownerState: { compact: boolean; compactActionButtonSize?: number | string } }>(({ ownerState }) => [\n ownerState.compact && {\n \"&&\": {\n width:\n ownerState.compactActionButtonSize === undefined\n ? \"1.5rem\"\n : typeof ownerState.compactActionButtonSize === \"number\"\n ? `${ownerState.compactActionButtonSize}px`\n : ownerState.compactActionButtonSize,\n height:\n ownerState.compactActionButtonSize === undefined\n ? \"1.5rem\"\n : typeof ownerState.compactActionButtonSize === \"number\"\n ? `${ownerState.compactActionButtonSize}px`\n : ownerState.compactActionButtonSize,\n borderRadius: \"var(--bfrs-radius-lg)\"\n },\n \"&&:disabled\": {\n \"--tw-bg-opacity\": \"1\",\n backgroundColor: \"hsl(var(--bfrs-color-surface-muted) / var(--tw-bg-opacity, 1))\",\n opacity: 1\n }\n }\n]);\n\nexport const ChatComposer = forwardRef<HTMLTextAreaElement, ChatComposerProps>(\n (\n {\n className,\n value,\n onValueChange,\n onSubmit,\n canSubmit,\n loading,\n disabled,\n size = \"md\",\n attachmentSlot,\n actionSlot,\n autoHeight = false,\n compactPadding,\n compactActionButtonSize,\n placeholderVariant = \"default\",\n textareaClassName,\n sendButtonClassName,\n placeholder = \"Ask me anything\",\n ...props\n },\n ref\n ) => {\n const compact = size === \"sm\";\n const iconSize = compact ? 14 : 18;\n const iconButtonSize = compact ? \"xs\" : \"sm\";\n const sendable = canSubmit ?? value.trim() !== \"\";\n\n const handleSubmit = (event: FormEvent) => {\n event.preventDefault();\n if (!disabled && !loading && sendable) onSubmit?.();\n };\n\n return (\n <ChatComposerRoot onSubmit={handleSubmit} ownerState={{ compact, autoHeight, compactPadding }} className={className}>\n {attachmentSlot ?? (\n <ChatComposerAttachButton\n aria-label=\"Attach file\"\n type=\"button\"\n icon={<Plus size={iconSize} />}\n variant={compact ? \"secondary\" : \"ghost\"}\n size={iconButtonSize}\n ownerState={{ compact }}\n disabled={disabled}\n />\n )}\n <ChatComposerTextarea\n ref={ref}\n value={value}\n disabled={disabled}\n placeholder={placeholder}\n rows={1}\n ownerState={{ compact, placeholderVariant }}\n className={textareaClassName}\n onChange={(event) => onValueChange(event.target.value)}\n onKeyDown={(event) => {\n if (event.key === \"Enter\" && !event.shiftKey) {\n event.preventDefault();\n if (sendable) onSubmit?.();\n }\n }}\n {...props}\n />\n {actionSlot}\n <ChatComposerSendButton\n aria-label=\"Send message\"\n type=\"submit\"\n icon={<ArrowUp size={iconSize} weight=\"bold\" />}\n variant=\"primary\"\n size={iconButtonSize}\n ownerState={{ compact, compactActionButtonSize }}\n className={sendButtonClassName}\n loading={loading}\n disabled={disabled || !sendable}\n />\n </ChatComposerRoot>\n );\n }\n);\n\nChatComposer.displayName = \"ChatComposer\";\n"],"names":["ChatComposerRoot","propName","ownerState","twRing","ChatComposerTextarea","ChatComposerAttachButton","IconButton","ChatComposerSendButton","ChatComposer","forwardRef","className","value","onValueChange","onSubmit","canSubmit","loading","disabled","size","attachmentSlot","actionSlot","autoHeight","compactPadding","compactActionButtonSize","placeholderVariant","textareaClassName","sendButtonClassName","placeholder","props","ref","compact","iconSize","iconButtonSize","sendable","jsxs","event","jsx","Plus","ArrowUp"],"mappings":";;;;;;;AAiCA,MAAMA,sBAAwC,QAAQ;AAAA,EACpD,OAAO;AAAA,EACP,mBAAmB,CAACC,MAAaA,MAAa;AAChD,CAAC,EAAsF,CAAC,EAAE,YAAAC,QAAiB;AAAA,EACzG;AAAA,IACE,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,aAAa;AAAA,IACb,uBA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AAA,UACX,UAAU,CAACU,MAAUtB,EAAcsB,EAAM,OAAO,KAAK;AAAA,UACrD,WAAW,CAACA,MAAU;AACpB,YAAIA,EAAM,QAAQ,WAAW,CAACA,EAAM,aAClCA,EAAM,eAAA,GACFF,MAAUnB,KAAA,QAAAA;AAAA,UAElB;AAAA,UACC,GAAGc;AAAA,QAAA;AAAA,MAAA;AAAA,MAELR;AAAA,MACD,gBAAAgB;AAAA,QAAC5B;AAAA,QAAA;AAAA,UACC,cAAW;AAAA,UACX,MAAK;AAAA,UACL,MAAM,gBAAA4B,EAACE,GAAA,EAAQ,MAAMP,GAAU,QAAO,QAAO;AAAA,UAC7C,SAAQ;AAAA,UACR,MAAMC;AAAA,UACN,YAAY,EAAE,SAAAF,GAAS,yBAAAP,EAAA;AAAA,UACvB,WAAWG;AAAA,UACX,SAAAV;AAAA,UACA,UAAUC,KAAY,CAACgB;AAAA,QAAA;AAAA,MAAA;AAAA,IACzB,GACF;AAAA,EAEJ;AACF;AAEAxB,EAAa,cAAc;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { BfrsAnalyticsSink } from './analyticsContext';
|
|
3
|
+
export type BfrsAnalyticsProviderProps = {
|
|
4
|
+
/** Where to send library events. Omitted or null inherits the nearest provider. */
|
|
5
|
+
emit?: BfrsAnalyticsSink | null;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Makes a sink available to every library component below it.
|
|
10
|
+
*
|
|
11
|
+
* `BfrsProvider` renders this for its `analytics` prop, so an app that already
|
|
12
|
+
* has a provider wires reporting in one place. See `analyticsContext.ts` for
|
|
13
|
+
* why library components emit at all.
|
|
14
|
+
*/
|
|
15
|
+
export declare function BfrsAnalyticsProvider({ emit, children }: BfrsAnalyticsProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare namespace BfrsAnalyticsProvider {
|
|
17
|
+
var displayName: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as s } from "react/jsx-runtime";
|
|
2
|
+
import { useContext as n, useMemo as f } from "react";
|
|
3
|
+
import { BfrsAnalyticsContext as t } from "./analyticsContext.js";
|
|
4
|
+
function m({ emit: r, children: e }) {
|
|
5
|
+
const o = n(t), i = f(() => r ?? o, [r, o]);
|
|
6
|
+
return /* @__PURE__ */ s(t.Provider, { value: i, children: e });
|
|
7
|
+
}
|
|
8
|
+
m.displayName = "BfrsAnalyticsProvider";
|
|
9
|
+
export {
|
|
10
|
+
m as BfrsAnalyticsProvider
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=BfrsAnalyticsProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BfrsAnalyticsProvider.js","sources":["../../../../../src/components/ui/providers/BfrsAnalyticsProvider/BfrsAnalyticsProvider.tsx"],"sourcesContent":["import { useContext, useMemo, type ReactNode } from \"react\";\nimport { BfrsAnalyticsContext, type BfrsAnalyticsSink } from \"./analyticsContext\";\n\nexport type BfrsAnalyticsProviderProps = {\n /** Where to send library events. Omitted or null inherits the nearest provider. */\n emit?: BfrsAnalyticsSink | null;\n children: ReactNode;\n};\n\n/**\n * Makes a sink available to every library component below it.\n *\n * `BfrsProvider` renders this for its `analytics` prop, so an app that already\n * has a provider wires reporting in one place. See `analyticsContext.ts` for\n * why library components emit at all.\n */\nexport function BfrsAnalyticsProvider({ emit, children }: BfrsAnalyticsProviderProps) {\n const inherited = useContext(BfrsAnalyticsContext);\n // An omitted `emit` inherits rather than blanking the sink, so nesting a\n // provider for theming cannot silently switch reporting off.\n const value = useMemo(() => emit ?? inherited, [emit, inherited]);\n\n return <BfrsAnalyticsContext.Provider value={value}>{children}</BfrsAnalyticsContext.Provider>;\n}\n\nBfrsAnalyticsProvider.displayName = \"BfrsAnalyticsProvider\";\n"],"names":["BfrsAnalyticsProvider","emit","children","inherited","useContext","BfrsAnalyticsContext","value","useMemo","jsx"],"mappings":";;;AAgBO,SAASA,EAAsB,EAAE,MAAAC,GAAM,UAAAC,KAAwC;AACpF,QAAMC,IAAYC,EAAWC,CAAoB,GAG3CC,IAAQC,EAAQ,MAAMN,KAAQE,GAAW,CAACF,GAAME,CAAS,CAAC;AAEhE,SAAO,gBAAAK,EAACH,EAAqB,UAArB,EAA8B,OAAAC,GAAe,UAAAJ,EAAA,CAAS;AAChE;AAEAF,EAAsB,cAAc;"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics for library-owned interactions.
|
|
3
|
+
*
|
|
4
|
+
* ## Why the library emits at all
|
|
5
|
+
*
|
|
6
|
+
* The usage guide's rule — "the library should not know analytics events" —
|
|
7
|
+
* holds for anything the consumer can observe for itself. Saved views are the
|
|
8
|
+
* case where it cannot:
|
|
9
|
+
*
|
|
10
|
+
* - `TableSaveView` dispatches the request through its own store when
|
|
11
|
+
* `screenName` is supplied, so `onSave` never fires and the consumer cannot
|
|
12
|
+
* see the submit at all. Reporting a submission from `onSaved` would be a
|
|
13
|
+
* different fact (an outcome) wearing the submit's name.
|
|
14
|
+
* - A submission blocked by the component's own validation (empty or reserved
|
|
15
|
+
* name) produces no callback at all, so nobody could count it.
|
|
16
|
+
* - `TableViewSelector` calls `onValueChange` for BOTH a seller's pick and its
|
|
17
|
+
* own mount-time restore of the primary view, in an identical shape. Every
|
|
18
|
+
* consumer had to guess with a heuristic; the component knows for certain.
|
|
19
|
+
*
|
|
20
|
+
* So the component owns the MOMENTS, which only it can observe correctly, and
|
|
21
|
+
* the consumer owns the VOCABULARY: it passes the registered element ids and a
|
|
22
|
+
* sink, and nothing here ever touches `gtag`, `dataLayer` or a provider SDK.
|
|
23
|
+
* There is exactly one GA4 tag in the platform and it belongs to the host; this
|
|
24
|
+
* module hands the host an event and is finished.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* The canonical event names the library may emit — a closed set, matching the
|
|
28
|
+
* platform registry. The host validates every name and property it receives, so
|
|
29
|
+
* an unknown name here would be dropped there with a diagnostic rather than
|
|
30
|
+
* silently reported.
|
|
31
|
+
*
|
|
32
|
+
* `form_validation_failed` is deliberately absent: the only validation these
|
|
33
|
+
* components apply disables the submit control, so no blocked attempt can
|
|
34
|
+
* occur. Add it when a component can actually observe one.
|
|
35
|
+
*/
|
|
36
|
+
export type BfrsAnalyticsEventName = "cta_clicked" | "element_clicked" | "modal_displayed" | "modal_dismissed" | "dropdown_option_selected" | "form_submitted" | "workflow_completed" | "workflow_failed";
|
|
37
|
+
/**
|
|
38
|
+
* Event properties. Values are codes, counts and booleans only.
|
|
39
|
+
*
|
|
40
|
+
* Nothing in this file may pass a view NAME, a seller's typed text, a label, a
|
|
41
|
+
* URL or an identifier from an unbounded list: the ids are registered codes the
|
|
42
|
+
* consumer supplies, and a saved view's name is the seller's own words.
|
|
43
|
+
*/
|
|
44
|
+
export type BfrsAnalyticsProperties = Record<string, string | number | boolean | undefined>;
|
|
45
|
+
export type BfrsAnalyticsEvent = {
|
|
46
|
+
name: BfrsAnalyticsEventName;
|
|
47
|
+
properties: BfrsAnalyticsProperties;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Where library events go. A consumer wires this once:
|
|
51
|
+
*
|
|
52
|
+
* ```tsx
|
|
53
|
+
* <BfrsProvider analytics={(event) => analytics.track(event.name, event.properties)}>
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export type BfrsAnalyticsSink = (event: BfrsAnalyticsEvent) => void;
|
|
57
|
+
export declare const BfrsAnalyticsContext: import('react').Context<BfrsAnalyticsSink | null>;
|
|
58
|
+
export declare function setBfrsAnalyticsSink(sink: BfrsAnalyticsSink | null): void;
|
|
59
|
+
export declare function getBfrsAnalyticsSink(): BfrsAnalyticsSink | null;
|
|
60
|
+
/**
|
|
61
|
+
* The sink to use, most specific first:
|
|
62
|
+
*
|
|
63
|
+
* 1. the nearest `BfrsProvider`/`BfrsAnalyticsProvider`
|
|
64
|
+
* 2. `setBfrsAnalyticsSink`, if an app chose to set one
|
|
65
|
+
* 3. the host bridge, discovered — which is why a platform app needs neither
|
|
66
|
+
* of the above
|
|
67
|
+
*
|
|
68
|
+
* Null when none of them is present, and then nothing is emitted.
|
|
69
|
+
*/
|
|
70
|
+
export declare function useBfrsAnalyticsSink(): BfrsAnalyticsSink | null;
|
|
71
|
+
/**
|
|
72
|
+
* Send one event, swallowing anything the sink throws.
|
|
73
|
+
*
|
|
74
|
+
* Reporting is never allowed to break the interaction it is reporting: a sink
|
|
75
|
+
* that throws (a mis-wired host, a consent gate, a provider SDK that is not
|
|
76
|
+
* loaded yet) must not take the save dialog down with it.
|
|
77
|
+
*/
|
|
78
|
+
export declare function emitBfrsAnalytics(sink: BfrsAnalyticsSink | null | undefined, name: BfrsAnalyticsEventName, properties: BfrsAnalyticsProperties): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useContext as s, createContext as f } from "react";
|
|
2
|
+
const l = f(null), u = ["__shiprocketAnalyticsBridge", "__bfrsAnalytics"];
|
|
3
|
+
function a() {
|
|
4
|
+
if (typeof globalThis > "u") return null;
|
|
5
|
+
for (const t of u) {
|
|
6
|
+
const n = globalThis[t], e = n == null ? void 0 : n.trackLibraryEvent;
|
|
7
|
+
if (typeof e == "function")
|
|
8
|
+
return (r) => {
|
|
9
|
+
e.call(n, r.name, r.properties);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
let o = null;
|
|
15
|
+
function p(t) {
|
|
16
|
+
o = t;
|
|
17
|
+
}
|
|
18
|
+
function k() {
|
|
19
|
+
return o;
|
|
20
|
+
}
|
|
21
|
+
function A() {
|
|
22
|
+
return s(l) ?? o ?? a();
|
|
23
|
+
}
|
|
24
|
+
function B(t, n, e) {
|
|
25
|
+
if (!t) return;
|
|
26
|
+
const r = {};
|
|
27
|
+
for (const [c, i] of Object.entries(e))
|
|
28
|
+
i !== void 0 && (r[c] = i);
|
|
29
|
+
try {
|
|
30
|
+
t({ name: n, properties: r });
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
l as BfrsAnalyticsContext,
|
|
36
|
+
B as emitBfrsAnalytics,
|
|
37
|
+
k as getBfrsAnalyticsSink,
|
|
38
|
+
p as setBfrsAnalyticsSink,
|
|
39
|
+
A as useBfrsAnalyticsSink
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=analyticsContext.js.map
|
|
@@ -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;
|