@10x-media/analytics 1.0.0-beta.8 → 1.0.0-beta.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.
Files changed (239) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/LICENSE +21 -21
  3. package/README.md +3 -3
  4. package/dist/adapters/ga4/eventName.d.ts +15 -0
  5. package/dist/adapters/ga4/eventName.js +19 -0
  6. package/dist/adapters/ga4/eventName.js.map +1 -0
  7. package/dist/adapters/ga4/ga4.d.ts +5 -0
  8. package/dist/adapters/ga4/ga4.js +178 -70
  9. package/dist/adapters/ga4/ga4.js.map +1 -1
  10. package/dist/adapters/ga4/measurementId.js +15 -0
  11. package/dist/adapters/ga4/measurementId.js.map +1 -0
  12. package/dist/adapters/goalRead.js +126 -0
  13. package/dist/adapters/goalRead.js.map +1 -0
  14. package/dist/adapters/plausible/plausible.d.ts +15 -0
  15. package/dist/adapters/plausible/plausible.js +110 -42
  16. package/dist/adapters/plausible/plausible.js.map +1 -1
  17. package/dist/adapters/posthog/posthog.js +47 -25
  18. package/dist/adapters/posthog/posthog.js.map +1 -1
  19. package/dist/adapters/umami/umami.d.ts +8 -0
  20. package/dist/adapters/umami/umami.js +237 -28
  21. package/dist/adapters/umami/umami.js.map +1 -1
  22. package/dist/charts/BarList.js +8 -2
  23. package/dist/charts/BarList.js.map +1 -1
  24. package/dist/core/cacheKey.js +11 -1
  25. package/dist/core/cacheKey.js.map +1 -1
  26. package/dist/core/capabilities.js +7 -2
  27. package/dist/core/capabilities.js.map +1 -1
  28. package/dist/core/capture.d.ts +1 -1
  29. package/dist/core/contract.d.ts +32 -2
  30. package/dist/core/contract.js.map +1 -1
  31. package/dist/core/options.d.ts +8 -2
  32. package/dist/core/options.js +4 -2
  33. package/dist/core/options.js.map +1 -1
  34. package/dist/core/serverEvent.d.ts +4 -2
  35. package/dist/core/serverEvent.js.map +1 -1
  36. package/dist/exports/adapters/ga4.d.ts +2 -1
  37. package/dist/exports/adapters/ga4.js +2 -1
  38. package/dist/exports/client.d.ts +5 -2
  39. package/dist/exports/client.js +4 -1
  40. package/dist/exports/rsc.d.ts +2 -1
  41. package/dist/exports/tracker.d.ts +3 -2
  42. package/dist/exports/tracker.js +2 -1
  43. package/dist/exports/types.d.ts +2 -1
  44. package/dist/exports/types.js +2 -1
  45. package/dist/fields/config/FilterDimensionSelectField.d.ts +14 -0
  46. package/dist/fields/config/FilterDimensionSelectField.js +77 -0
  47. package/dist/fields/config/FilterDimensionSelectField.js.map +1 -0
  48. package/dist/fields/config/FilterOperatorSelectField.d.ts +14 -0
  49. package/dist/fields/config/FilterOperatorSelectField.js +75 -0
  50. package/dist/fields/config/FilterOperatorSelectField.js.map +1 -0
  51. package/dist/fields/config/MetricSelectField.js +1 -1
  52. package/dist/fields/config/SourceSelectField.js +1 -1
  53. package/dist/fields/config/sourcesState.js +19 -3
  54. package/dist/fields/config/sourcesState.js.map +1 -1
  55. package/dist/fields/config/useAnalyticsSources.d.ts +8 -3
  56. package/dist/fields/config/useAnalyticsSources.js +9 -6
  57. package/dist/fields/config/useAnalyticsSources.js.map +1 -1
  58. package/dist/fields/config/useFilterCapabilities.d.ts +28 -0
  59. package/dist/fields/config/useFilterCapabilities.js +52 -0
  60. package/dist/fields/config/useFilterCapabilities.js.map +1 -0
  61. package/dist/fields/readForDocument.js +16 -4
  62. package/dist/fields/readForDocument.js.map +1 -1
  63. package/dist/index.d.ts +3 -1
  64. package/dist/index.js +2 -1
  65. package/dist/index.js.map +1 -1
  66. package/dist/native/collections/events.js +36 -0
  67. package/dist/native/collections/events.js.map +1 -1
  68. package/dist/native/eventScan.js +25 -0
  69. package/dist/native/eventScan.js.map +1 -0
  70. package/dist/native/ingest/browser.js +47 -0
  71. package/dist/native/ingest/browser.js.map +1 -0
  72. package/dist/native/ingest/flushBatch.js +26 -26
  73. package/dist/native/ingest/flushBatch.js.map +1 -1
  74. package/dist/native/ingest/language.js +14 -0
  75. package/dist/native/ingest/language.js.map +1 -0
  76. package/dist/native/ingest/normalizeEvent.d.ts +6 -0
  77. package/dist/native/ingest/normalizeEvent.js +32 -5
  78. package/dist/native/ingest/normalizeEvent.js.map +1 -1
  79. package/dist/native/ingest/referrer.js +48 -0
  80. package/dist/native/ingest/referrer.js.map +1 -0
  81. package/dist/native/ingest/serverTrack.js +1 -0
  82. package/dist/native/ingest/serverTrack.js.map +1 -1
  83. package/dist/native/ingest/source.d.ts +7 -0
  84. package/dist/native/ingest/source.js +139 -14
  85. package/dist/native/ingest/source.js.map +1 -1
  86. package/dist/native/ingest/utm.js +33 -0
  87. package/dist/native/ingest/utm.js.map +1 -0
  88. package/dist/native/nativeAdapter.js +32 -26
  89. package/dist/native/nativeAdapter.js.map +1 -1
  90. package/dist/native/query/eventAgg.js +14 -1
  91. package/dist/native/query/eventAgg.js.map +1 -1
  92. package/dist/native/rollups/bucketKey.js +15 -0
  93. package/dist/native/rollups/bucketKey.js.map +1 -0
  94. package/dist/native/rollups/bumpRollups.js +116 -0
  95. package/dist/native/rollups/bumpRollups.js.map +1 -0
  96. package/dist/native/rollups/deltas.js +30 -15
  97. package/dist/native/rollups/deltas.js.map +1 -1
  98. package/dist/native/rollups/insertManyIfNew.js +93 -0
  99. package/dist/native/rollups/insertManyIfNew.js.map +1 -0
  100. package/dist/next/captureRewrites.d.ts +3 -2
  101. package/dist/next/captureRewrites.js +3 -2
  102. package/dist/next/captureRewrites.js.map +1 -1
  103. package/dist/plugin/documentEndpoint.js +26 -7
  104. package/dist/plugin/documentEndpoint.js.map +1 -1
  105. package/dist/plugin/goalHint.d.ts +1 -0
  106. package/dist/plugin/goalHint.js +24 -0
  107. package/dist/plugin/goalHint.js.map +1 -0
  108. package/dist/plugin/queryEndpoint.js +19 -12
  109. package/dist/plugin/queryEndpoint.js.map +1 -1
  110. package/dist/plugin/realtimeEndpoint.js +40 -15
  111. package/dist/plugin/realtimeEndpoint.js.map +1 -1
  112. package/dist/plugin/responses.js +17 -0
  113. package/dist/plugin/responses.js.map +1 -0
  114. package/dist/plugin/sourcesEndpoint.js +10 -3
  115. package/dist/plugin/sourcesEndpoint.js.map +1 -1
  116. package/dist/providers/collection.js +14 -4
  117. package/dist/providers/collection.js.map +1 -1
  118. package/dist/providers/factory.js +4 -2
  119. package/dist/providers/factory.js.map +1 -1
  120. package/dist/query/response.d.ts +4 -1
  121. package/dist/query/response.js +11 -0
  122. package/dist/query/response.js.map +1 -0
  123. package/dist/surfacing/engine.js +1 -1
  124. package/dist/surfacing/engine.js.map +1 -1
  125. package/dist/testing/memoryAdapter.js +0 -1
  126. package/dist/testing/memoryAdapter.js.map +1 -1
  127. package/dist/tracker/createTracker.js +13 -1
  128. package/dist/tracker/createTracker.js.map +1 -1
  129. package/dist/tracker/sinks/ga4.d.ts +21 -0
  130. package/dist/tracker/sinks/ga4.js +26 -0
  131. package/dist/tracker/sinks/ga4.js.map +1 -0
  132. package/dist/tracker/types.d.ts +5 -0
  133. package/dist/translations/ar.js +30 -1
  134. package/dist/translations/ar.js.map +1 -1
  135. package/dist/translations/de.js +30 -1
  136. package/dist/translations/de.js.map +1 -1
  137. package/dist/translations/en.js +30 -1
  138. package/dist/translations/en.js.map +1 -1
  139. package/dist/translations/es.js +30 -1
  140. package/dist/translations/es.js.map +1 -1
  141. package/dist/translations/fr.js +30 -1
  142. package/dist/translations/fr.js.map +1 -1
  143. package/dist/translations/id.js +30 -1
  144. package/dist/translations/id.js.map +1 -1
  145. package/dist/translations/keys.d.ts +29 -0
  146. package/dist/translations/keys.js +30 -1
  147. package/dist/translations/keys.js.map +1 -1
  148. package/dist/translations/ko.js +30 -1
  149. package/dist/translations/ko.js.map +1 -1
  150. package/dist/translations/metricKeys.js +7 -1
  151. package/dist/translations/metricKeys.js.map +1 -1
  152. package/dist/translations/pt.js +30 -1
  153. package/dist/translations/pt.js.map +1 -1
  154. package/dist/translations/ru.js +30 -1
  155. package/dist/translations/ru.js.map +1 -1
  156. package/dist/translations/server.js.map +1 -1
  157. package/dist/translations/uk.js +30 -1
  158. package/dist/translations/uk.js.map +1 -1
  159. package/dist/translations/zh.js +30 -1
  160. package/dist/translations/zh.js.map +1 -1
  161. package/dist/view/AnalyticsViewClient.js +13 -2
  162. package/dist/view/AnalyticsViewClient.js.map +1 -1
  163. package/dist/view/gating.js +40 -3
  164. package/dist/view/gating.js.map +1 -1
  165. package/dist/view/labels.js +21 -1
  166. package/dist/view/labels.js.map +1 -1
  167. package/dist/view/sections/Breakdowns.js +78 -38
  168. package/dist/view/sections/Breakdowns.js.map +1 -1
  169. package/dist/view/sections/FilterChips.js +8 -3
  170. package/dist/view/sections/FilterChips.js.map +1 -1
  171. package/dist/view/sections/GoalsPanel.js +2 -1
  172. package/dist/view/sections/GoalsPanel.js.map +1 -1
  173. package/dist/view/sections/RealtimeStrip.js +4 -1
  174. package/dist/view/sections/RealtimeStrip.js.map +1 -1
  175. package/dist/view/sections/Toolbar.js +10 -3
  176. package/dist/view/sections/Toolbar.js.map +1 -1
  177. package/dist/view/sections/Trend.js +8 -2
  178. package/dist/view/sections/Trend.js.map +1 -1
  179. package/dist/view/state.js +7 -2
  180. package/dist/view/state.js.map +1 -1
  181. package/dist/view/useViewQueries.js +6 -3
  182. package/dist/view/useViewQueries.js.map +1 -1
  183. package/dist/widgets/AnalyticsBreakdownWidget.js +59 -10
  184. package/dist/widgets/AnalyticsBreakdownWidget.js.map +1 -1
  185. package/dist/widgets/AnalyticsGoalsWidget.js +10 -2
  186. package/dist/widgets/AnalyticsGoalsWidget.js.map +1 -1
  187. package/dist/widgets/AnalyticsMetricWidget.js +30 -3
  188. package/dist/widgets/AnalyticsMetricWidget.js.map +1 -1
  189. package/dist/widgets/AnalyticsRealtimeWidget.js +3 -1
  190. package/dist/widgets/AnalyticsRealtimeWidget.js.map +1 -1
  191. package/dist/widgets/AnalyticsTrendWidget.js +30 -3
  192. package/dist/widgets/AnalyticsTrendWidget.js.map +1 -1
  193. package/dist/widgets/RealtimeCounter.d.ts +4 -0
  194. package/dist/widgets/RealtimeCounter.js +10 -1
  195. package/dist/widgets/RealtimeCounter.js.map +1 -1
  196. package/dist/widgets/breakdownTypes.js.map +1 -1
  197. package/dist/widgets/comparison.js +15 -1
  198. package/dist/widgets/comparison.js.map +1 -1
  199. package/dist/widgets/defaults.d.ts +6 -2
  200. package/dist/widgets/defaults.js +72 -25
  201. package/dist/widgets/defaults.js.map +1 -1
  202. package/dist/widgets/filterCaption.js +27 -0
  203. package/dist/widgets/filterCaption.js.map +1 -0
  204. package/dist/widgets/filterField.d.ts +19 -0
  205. package/dist/widgets/filterField.js +75 -0
  206. package/dist/widgets/filterField.js.map +1 -0
  207. package/dist/widgets/prepareWidgetRead.d.ts +7 -0
  208. package/dist/widgets/prepareWidgetRead.js +74 -0
  209. package/dist/widgets/prepareWidgetRead.js.map +1 -0
  210. package/dist/widgets/readForWidget.d.ts +12 -2
  211. package/dist/widgets/readForWidget.js +34 -49
  212. package/dist/widgets/readForWidget.js.map +1 -1
  213. package/dist/widgets/readForWidgetBreakdown.d.ts +17 -1
  214. package/dist/widgets/readForWidgetBreakdown.js +29 -42
  215. package/dist/widgets/readForWidgetBreakdown.js.map +1 -1
  216. package/dist/widgets/readForWidgetGoals.d.ts +11 -1
  217. package/dist/widgets/readForWidgetGoals.js +44 -30
  218. package/dist/widgets/readForWidgetGoals.js.map +1 -1
  219. package/dist/widgets/readForWidgetRealtime.d.ts +8 -0
  220. package/dist/widgets/readForWidgetRealtime.js +21 -20
  221. package/dist/widgets/readForWidgetRealtime.js.map +1 -1
  222. package/dist/widgets/readForWidgetSeries.d.ts +11 -1
  223. package/dist/widgets/readForWidgetSeries.js +38 -49
  224. package/dist/widgets/readForWidgetSeries.js.map +1 -1
  225. package/dist/widgets/readMeta.js +18 -0
  226. package/dist/widgets/readMeta.js.map +1 -0
  227. package/dist/widgets/registerWidgets.js +5 -2
  228. package/dist/widgets/registerWidgets.js.map +1 -1
  229. package/dist/widgets/types.d.ts +15 -0
  230. package/dist/widgets/types.js.map +1 -1
  231. package/dist/widgets/viewLink.js +5 -2
  232. package/dist/widgets/viewLink.js.map +1 -1
  233. package/package.json +5 -5
  234. package/dist/native/rollups/applyDistinctDeltas.js +0 -9
  235. package/dist/native/rollups/applyDistinctDeltas.js.map +0 -1
  236. package/dist/native/rollups/bumpRollup.js +0 -73
  237. package/dist/native/rollups/bumpRollup.js.map +0 -1
  238. package/dist/native/rollups/insertIfNew.js +0 -53
  239. package/dist/native/rollups/insertIfNew.js.map +0 -1
@@ -1,2 +1,3 @@
1
+ import { ga4EventName } from "../../adapters/ga4/eventName.js";
1
2
  import { Ga4Config, ga4 } from "../../adapters/ga4/ga4.js";
2
- export { type Ga4Config, ga4 };
3
+ export { type Ga4Config, ga4, ga4EventName };
@@ -1,2 +1,3 @@
1
+ import { ga4EventName } from "../../adapters/ga4/eventName.js";
1
2
  import { ga4 } from "../../adapters/ga4/ga4.js";
2
- export { ga4 };
3
+ export { ga4, ga4EventName };
@@ -1,9 +1,12 @@
1
1
  import { BarList, BarListProps } from "../charts/BarList.js";
2
2
  import { TrendChart, TrendChartProps, TrendPoint } from "../charts/TrendChart.js";
3
+ import { FilterDimensionSelectField, FilterDimensionSelectFieldProps } from "../fields/config/FilterDimensionSelectField.js";
4
+ import { FilterOperatorSelectField, FilterOperatorSelectFieldProps } from "../fields/config/FilterOperatorSelectField.js";
3
5
  import { WireSource } from "../fields/config/fetchSources.js";
4
6
  import { MetricSelectField, MetricSelectFieldProps } from "../fields/config/MetricSelectField.js";
5
7
  import { SourceSelectField } from "../fields/config/SourceSelectField.js";
6
- import { useAnalyticsSources } from "../fields/config/useAnalyticsSources.js";
8
+ import { AnalyticsSources, useAnalyticsSources } from "../fields/config/useAnalyticsSources.js";
9
+ import { FilterCapabilities, useFilterCapabilities } from "../fields/config/useFilterCapabilities.js";
7
10
  import { DateRangeField } from "../fields/dateRange/ui.js";
8
11
  import { GoalsResponse, WireGoal } from "../goals/fetchGoals.js";
9
12
  import { GoalSelectField } from "../goals/GoalSelectField.js";
@@ -12,4 +15,4 @@ import { QueryFetchError, QueryRequest, buildQueryUrl, fetchQuery } from "../que
12
15
  import { AnalyticsNavLink, AnalyticsNavLinkProps } from "../view/AnalyticsNavLink.js";
13
16
  import { AnalyticsViewClient } from "../view/AnalyticsViewClient.js";
14
17
  import { RealtimeCounter } from "../widgets/RealtimeCounter.js";
15
- export { AnalyticsNavLink, type AnalyticsNavLinkProps, AnalyticsViewClient, BarList, type BarListProps, DateRangeField, GoalSelectField, type GoalsResponse, MetricSelectField, type MetricSelectFieldProps, QueryFetchError, type QueryRequest, RealtimeCounter, SourceSelectField, TrendChart, type TrendChartProps, type TrendPoint, type WireGoal, type WireSource, buildQueryUrl, fetchQuery, useAnalyticsGoals, useAnalyticsSources };
18
+ export { AnalyticsNavLink, type AnalyticsNavLinkProps, type AnalyticsSources, AnalyticsViewClient, BarList, type BarListProps, DateRangeField, type FilterCapabilities, FilterDimensionSelectField, type FilterDimensionSelectFieldProps, FilterOperatorSelectField, type FilterOperatorSelectFieldProps, GoalSelectField, type GoalsResponse, MetricSelectField, type MetricSelectFieldProps, QueryFetchError, type QueryRequest, RealtimeCounter, SourceSelectField, TrendChart, type TrendChartProps, type TrendPoint, type WireGoal, type WireSource, buildQueryUrl, fetchQuery, useAnalyticsGoals, useAnalyticsSources, useFilterCapabilities };
@@ -2,6 +2,9 @@
2
2
  import { BarList } from "../charts/BarList.js";
3
3
  import { TrendChart } from "../charts/TrendChart.js";
4
4
  import { useAnalyticsSources } from "../fields/config/useAnalyticsSources.js";
5
+ import { useFilterCapabilities } from "../fields/config/useFilterCapabilities.js";
6
+ import { FilterDimensionSelectField } from "../fields/config/FilterDimensionSelectField.js";
7
+ import { FilterOperatorSelectField } from "../fields/config/FilterOperatorSelectField.js";
5
8
  import { MetricSelectField } from "../fields/config/MetricSelectField.js";
6
9
  import { SourceSelectField } from "../fields/config/SourceSelectField.js";
7
10
  import { DateRangeField } from "../fields/dateRange/ui.js";
@@ -11,4 +14,4 @@ import { QueryFetchError, buildQueryUrl, fetchQuery } from "../query/fetchQuery.
11
14
  import { AnalyticsNavLink } from "../view/AnalyticsNavLink.js";
12
15
  import { RealtimeCounter } from "../widgets/RealtimeCounter.js";
13
16
  import { AnalyticsViewClient } from "../view/AnalyticsViewClient.js";
14
- export { AnalyticsNavLink, AnalyticsViewClient, BarList, DateRangeField, GoalSelectField, MetricSelectField, QueryFetchError, RealtimeCounter, SourceSelectField, TrendChart, buildQueryUrl, fetchQuery, useAnalyticsGoals, useAnalyticsSources };
17
+ export { AnalyticsNavLink, AnalyticsViewClient, BarList, DateRangeField, FilterDimensionSelectField, FilterOperatorSelectField, GoalSelectField, MetricSelectField, QueryFetchError, RealtimeCounter, SourceSelectField, TrendChart, buildQueryUrl, fetchQuery, useAnalyticsGoals, useAnalyticsSources, useFilterCapabilities };
@@ -7,7 +7,7 @@ import { getTrackerConfig } from "../capture/getTrackerConfig.js";
7
7
  import { AnalyticsStatField } from "../fields/AnalyticsStatField.js";
8
8
  import { AnalyticsPanelField } from "../fields/AnalyticsPanelField.js";
9
9
  import { formatMetricValue } from "../fields/format.js";
10
- import { ReadForWidgetArgs, WidgetReadResult, WidgetReadStatus, readForWidget } from "../widgets/readForWidget.js";
10
+ import { WidgetReadStatus } from "../widgets/prepareWidgetRead.js";
11
11
  import { ReadForWidgetSeriesArgs, SeriesPoint, WidgetSeriesResult, readForWidgetSeries } from "../widgets/readForWidgetSeries.js";
12
12
  import { FieldReadResult, FieldReadStatus, ReadForFieldArgs, readForField } from "../fields/readForDocument.js";
13
13
  import { AnalyticsScripts, AnalyticsScriptsProps } from "../rsc/AnalyticsScripts.js";
@@ -18,6 +18,7 @@ import { AnalyticsMetricWidget } from "../widgets/AnalyticsMetricWidget.js";
18
18
  import { AnalyticsRealtimeWidget } from "../widgets/AnalyticsRealtimeWidget.js";
19
19
  import { AnalyticsTrendWidget } from "../widgets/AnalyticsTrendWidget.js";
20
20
  import { cardStyle, labelStyle } from "../widgets/cardChrome.js";
21
+ import { ReadForWidgetArgs, WidgetReadResult, readForWidget } from "../widgets/readForWidget.js";
21
22
  import { BreakdownRow, ReadForWidgetBreakdownArgs, WidgetBreakdownResult, readForWidgetBreakdown } from "../widgets/readForWidgetBreakdown.js";
22
23
  import { GoalRow, ReadForWidgetGoalsArgs, WidgetGoalsResult, readForWidgetGoals } from "../widgets/readForWidgetGoals.js";
23
24
  export { AnalyticsBreakdownWidget, type AnalyticsFilter, AnalyticsGoalsWidget, AnalyticsMetricWidget, AnalyticsPanelField, AnalyticsRealtimeWidget, AnalyticsScripts, type AnalyticsScriptsProps, AnalyticsStatField, AnalyticsTrendWidget, AnalyticsView, type AnalyticsViewClientProps, type AnalyticsViewProps, type BreakdownRow, type CapabilityRequirement, type DateRange, type DimensionKey, type FieldReadResult, type FieldReadStatus, type GoalRow, type MetricKey, type ReadForFieldArgs, type ReadForWidgetArgs, type ReadForWidgetBreakdownArgs, type ReadForWidgetGoalsArgs, type ReadForWidgetRealtimeArgs, type ReadForWidgetSeriesArgs, type RealtimePoint, type SeriesPoint, type TrackerConfig, type TrackerSlotConfig, type ViewGoal, type WidgetBreakdownResult, type WidgetGoalsResult, type WidgetReadResult, type WidgetReadStatus, type WidgetRealtimeResult, type WidgetRealtimeStatus, type WidgetSeriesResult, formatMetricValue, getTrackerConfig, readForField, readForWidget, readForWidgetBreakdown, readForWidgetGoals, readForWidgetRealtime, readForWidgetSeries, cardStyle as widgetCardStyle, labelStyle as widgetLabelStyle };
@@ -10,9 +10,10 @@ import { DEFAULT_TRACKER_ENDPOINT, InitTrackerArgs, initTracker } from "../track
10
10
  import { createScriptLoader } from "../tracker/loadScript.js";
11
11
  import { PageTracking, createPageTracking } from "../tracker/pageTracking.js";
12
12
  import { TrackerLease, acquireTracker } from "../tracker/registry.js";
13
- import { PAGEVIEW_BUFFER_MS, createNativeSink } from "../tracker/sinks/native.js";
14
13
  import { VendorSinkArgs } from "../tracker/sinks/vendor.js";
14
+ import { createGa4Sink } from "../tracker/sinks/ga4.js";
15
+ import { PAGEVIEW_BUFFER_MS, createNativeSink } from "../tracker/sinks/native.js";
15
16
  import { createPlausibleSink } from "../tracker/sinks/plausible.js";
16
17
  import { createPosthogSink } from "../tracker/sinks/posthog.js";
17
18
  import { createUmamiSink } from "../tracker/sinks/umami.js";
18
- export { type AutoCapture, type AutoCaptureHandlers, CONSENT_QUEUE_LIMIT, CONSENT_STORAGE_KEY, type CaptureSnippet, type ConsentState, DEFAULT_TRACKER_ENDPOINT, DOWNLOAD_EVENT, GOAL_ATTRIBUTE, type InitTrackerArgs, type LoadScript, OUTBOUND_EVENT, PAGEVIEW_BUFFER_MS, type PageTracking, type ResolvedAutoCapture, SCROLL_EVENT, type Sink, type SnippetScript, type Tracker, type TrackerConfig, type TrackerEvent, type TrackerGoal, type TrackerLease, type TrackerOptions, type TrackerSlotConfig, type TrackerWindow, type VendorSinkArgs, acquireTracker, createAutoCapture, createConsentQueue, createNativeSink, createNoopTracker, createPageTracking, createPlausibleSink, createPosthogSink, createScriptLoader, createTracker, createUmamiSink, initTracker, readConsent, writeConsent };
19
+ export { type AutoCapture, type AutoCaptureHandlers, CONSENT_QUEUE_LIMIT, CONSENT_STORAGE_KEY, type CaptureSnippet, type ConsentState, DEFAULT_TRACKER_ENDPOINT, DOWNLOAD_EVENT, GOAL_ATTRIBUTE, type InitTrackerArgs, type LoadScript, OUTBOUND_EVENT, PAGEVIEW_BUFFER_MS, type PageTracking, type ResolvedAutoCapture, SCROLL_EVENT, type Sink, type SnippetScript, type Tracker, type TrackerConfig, type TrackerEvent, type TrackerGoal, type TrackerLease, type TrackerOptions, type TrackerSlotConfig, type TrackerWindow, type VendorSinkArgs, acquireTracker, createAutoCapture, createConsentQueue, createGa4Sink, createNativeSink, createNoopTracker, createPageTracking, createPlausibleSink, createPosthogSink, createScriptLoader, createTracker, createUmamiSink, initTracker, readConsent, writeConsent };
@@ -2,6 +2,7 @@ import { DOWNLOAD_EVENT, GOAL_ATTRIBUTE, OUTBOUND_EVENT, SCROLL_EVENT, createAut
2
2
  import { CONSENT_QUEUE_LIMIT, CONSENT_STORAGE_KEY, createConsentQueue, readConsent, writeConsent } from "../tracker/consent.js";
3
3
  import { createScriptLoader } from "../tracker/loadScript.js";
4
4
  import { createPageTracking } from "../tracker/pageTracking.js";
5
+ import { createGa4Sink } from "../tracker/sinks/ga4.js";
5
6
  import { PAGEVIEW_BUFFER_MS, createNativeSink } from "../tracker/sinks/native.js";
6
7
  import { createPlausibleSink } from "../tracker/sinks/plausible.js";
7
8
  import { createPosthogSink } from "../tracker/sinks/posthog.js";
@@ -9,4 +10,4 @@ import { createUmamiSink } from "../tracker/sinks/umami.js";
9
10
  import { createNoopTracker, createTracker } from "../tracker/createTracker.js";
10
11
  import { acquireTracker } from "../tracker/registry.js";
11
12
  import { DEFAULT_TRACKER_ENDPOINT, initTracker } from "../tracker/initTracker.js";
12
- export { CONSENT_QUEUE_LIMIT, CONSENT_STORAGE_KEY, DEFAULT_TRACKER_ENDPOINT, DOWNLOAD_EVENT, GOAL_ATTRIBUTE, OUTBOUND_EVENT, PAGEVIEW_BUFFER_MS, SCROLL_EVENT, acquireTracker, createAutoCapture, createConsentQueue, createNativeSink, createNoopTracker, createPageTracking, createPlausibleSink, createPosthogSink, createScriptLoader, createTracker, createUmamiSink, initTracker, readConsent, writeConsent };
13
+ export { CONSENT_QUEUE_LIMIT, CONSENT_STORAGE_KEY, DEFAULT_TRACKER_ENDPOINT, DOWNLOAD_EVENT, GOAL_ATTRIBUTE, OUTBOUND_EVENT, PAGEVIEW_BUFFER_MS, SCROLL_EVENT, acquireTracker, createAutoCapture, createConsentQueue, createGa4Sink, createNativeSink, createNoopTracker, createPageTracking, createPlausibleSink, createPosthogSink, createScriptLoader, createTracker, createUmamiSink, initTracker, readConsent, writeConsent };
@@ -14,5 +14,6 @@ import { TrackerConfig, TrackerSlotConfig } from "../capture/trackerConfig.js";
14
14
  import { AnalyticsFieldsOptions, AnalyticsMetricLabel, AnalyticsMetricLabels, AnalyticsStatOptions, AnalyticsStatRowOptions, AnalyticsTabOptions } from "../fields/factories.js";
15
15
  import { GoalFieldOptions } from "../goals/goalField.js";
16
16
  import { GoalActionDefinition, GoalActionRunArgs, TrackGoalActionOptions } from "../goals/trackGoalAction.js";
17
+ import { TRAFFIC_CHANNELS, TrafficChannel } from "../native/ingest/source.js";
17
18
  import { ParseResult, ParsedQuery } from "../query/parse.js";
18
- export { AdapterContext, AdapterRegisterContext, AnalyticsAdapter, AnalyticsAdapterFactory, type AnalyticsBinding, AnalyticsCapabilities, type AnalyticsFieldsOptions, AnalyticsFilter, type AnalyticsMetricLabel, type AnalyticsMetricLabels, type AnalyticsPluginOptions, AnalyticsQuery, AnalyticsResult, AnalyticsRow, type AnalyticsStatOptions, type AnalyticsStatRowOptions, type AnalyticsTabOptions, type AnalyticsViewAccess, type AnalyticsViewClientProps, type AnalyticsViewOptions, type BindingContext, CaptureClientKind, CaptureSnippet, CaptureSupport, DIMENSION_KEYS, DateRange, DimensionKey, FILTER_OPERATORS, FilterOperator, type Goal, type GoalActionDefinition, type GoalActionRunArgs, type GoalFieldOptions, type GoalMatch, Granularity, type HostnameResolver, MetricKey, PLATFORM_SCOPE, type ParseResult, type ParsedQuery, type PathResolver, ProxyDescriptor, ProxyRoute, type QueryError, type QueryErrorCode, type QueryErrorResponse, type QueryRequest, type QueryResponse, type QuerySourceRef, RateLimitDescriptor, type ResolvedAutoCapture, type SerializedAnalyticsQuery, type SerializedCapabilities, type ServerEventInput, type ServerTrack, type ServerTrackOptions, SnippetScript, type TimeframePreset, type TrackGoalActionOptions, type TrackerConfig, type TrackerGoal, type TrackerSlotConfig, type ViewGoal };
19
+ export { AdapterContext, AdapterRegisterContext, AnalyticsAdapter, AnalyticsAdapterFactory, type AnalyticsBinding, AnalyticsCapabilities, type AnalyticsFieldsOptions, AnalyticsFilter, type AnalyticsMetricLabel, type AnalyticsMetricLabels, type AnalyticsPluginOptions, AnalyticsQuery, AnalyticsResult, AnalyticsRow, type AnalyticsStatOptions, type AnalyticsStatRowOptions, type AnalyticsTabOptions, type AnalyticsViewAccess, type AnalyticsViewClientProps, type AnalyticsViewOptions, type BindingContext, CaptureClientKind, CaptureSnippet, CaptureSupport, DIMENSION_KEYS, DateRange, DimensionKey, FILTER_OPERATORS, FilterOperator, type Goal, type GoalActionDefinition, type GoalActionRunArgs, type GoalFieldOptions, type GoalMatch, Granularity, type HostnameResolver, MetricKey, PLATFORM_SCOPE, type ParseResult, type ParsedQuery, type PathResolver, ProxyDescriptor, ProxyRoute, type QueryError, type QueryErrorCode, type QueryErrorResponse, type QueryRequest, type QueryResponse, type QuerySourceRef, RateLimitDescriptor, type ResolvedAutoCapture, type SerializedAnalyticsQuery, type SerializedCapabilities, type ServerEventInput, type ServerTrack, type ServerTrackOptions, SnippetScript, TRAFFIC_CHANNELS, type TimeframePreset, type TrackGoalActionOptions, type TrackerConfig, type TrackerGoal, type TrackerSlotConfig, type TrafficChannel, type ViewGoal };
@@ -1,2 +1,3 @@
1
1
  import { DIMENSION_KEYS, FILTER_OPERATORS, PLATFORM_SCOPE } from "../core/contract.js";
2
- export { DIMENSION_KEYS, FILTER_OPERATORS, PLATFORM_SCOPE };
2
+ import { TRAFFIC_CHANNELS } from "../native/ingest/source.js";
3
+ export { DIMENSION_KEYS, FILTER_OPERATORS, PLATFORM_SCOPE, TRAFFIC_CHANNELS };
@@ -0,0 +1,14 @@
1
+ import { TextFieldClientProps } from "payload";
2
+
3
+ //#region src/fields/config/FilterDimensionSelectField.d.ts
4
+ type FilterDimensionSelectFieldProps = TextFieldClientProps & {
5
+ /**
6
+ * Path of the sibling source select this picker narrows against, for custom widgets
7
+ * whose source field is named differently. Defaults to `'dataSource'`.
8
+ */
9
+ sourceFieldPath?: string;
10
+ };
11
+ declare const FilterDimensionSelectField: import("react").FC<FilterDimensionSelectFieldProps>;
12
+ //#endregion
13
+ export { FilterDimensionSelectField, FilterDimensionSelectFieldProps };
14
+ //# sourceMappingURL=FilterDimensionSelectField.d.ts.map
@@ -0,0 +1,77 @@
1
+ "use client";
2
+ import { DIMENSION_KEYS } from "../../core/contract.js";
3
+ import { keys } from "../../translations/keys.js";
4
+ import { useTranslation as useTranslation$1 } from "../../translations/useTranslation.js";
5
+ import { DIMENSION_LABELS } from "../../view/labels.js";
6
+ import { useFilterCapabilities } from "./useFilterCapabilities.js";
7
+ import { useMemo } from "react";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ import { FieldDescription, SelectInput, useField, withCondition } from "@payloadcms/ui";
10
+ import { mergeFieldStyles } from "@payloadcms/ui/shared";
11
+ //#region src/fields/config/FilterDimensionSelectField.tsx
12
+ const asDimension = (value) => DIMENSION_KEYS.find((key) => key === value);
13
+ /**
14
+ * Dimension picker for a widget's filter group: offers only the dimensions the widget's
15
+ * chosen source can filter by, unioned over the request's sources while none is chosen.
16
+ * A stored dimension the source dropped stays in the list so it reads as the filter it is
17
+ * and can be cleared; the read path renders the unsupported state for it either way.
18
+ * While the source list is in flight the picker offers nothing rather than a wrong list,
19
+ * and says so once it settles empty or failed.
20
+ */
21
+ const FilterDimensionSelectFieldComponent = (props) => {
22
+ const { field, path: pathFromProps, readOnly, sourceFieldPath } = props;
23
+ const { t } = useTranslation$1();
24
+ const { dimensions, error, resolved } = useFilterCapabilities(sourceFieldPath);
25
+ const { customComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {}, disabled, path, setValue, showError, value } = useField({ potentiallyStalePath: pathFromProps });
26
+ const options = useMemo(() => {
27
+ const offered = dimensions.map((key) => ({
28
+ label: t(DIMENSION_LABELS[key]),
29
+ value: key
30
+ }));
31
+ if (!value || dimensions.some((key) => key === value)) return offered;
32
+ const known = asDimension(value);
33
+ return [{
34
+ label: known ? t(DIMENSION_LABELS[known]) : value,
35
+ value
36
+ }, ...offered];
37
+ }, [
38
+ dimensions,
39
+ t,
40
+ value
41
+ ]);
42
+ const style = useMemo(() => mergeFieldStyles(field), [field]);
43
+ const notice = error ? t(keys.fieldFilterError) : resolved && dimensions.length === 0 ? t(keys.fieldFilterEmpty) : null;
44
+ return /* @__PURE__ */ jsx(SelectInput, {
45
+ AfterInput,
46
+ BeforeInput,
47
+ className: field.admin?.className,
48
+ Description: notice ? /* @__PURE__ */ jsxs(Fragment, { children: [Description ?? /* @__PURE__ */ jsx(FieldDescription, {
49
+ description: field.admin?.description,
50
+ path
51
+ }), /* @__PURE__ */ jsx("div", {
52
+ className: "field-description",
53
+ children: notice
54
+ })] }) : Description,
55
+ description: field.admin?.description,
56
+ Error: ErrorComponent,
57
+ isClearable: true,
58
+ Label,
59
+ label: field.label,
60
+ name: field.name,
61
+ onChange: (selected) => {
62
+ const option = Array.isArray(selected) ? selected[0] : selected;
63
+ setValue(option?.value ? String(option.value) : null);
64
+ },
65
+ options,
66
+ path,
67
+ readOnly: readOnly || disabled || field.admin?.readOnly,
68
+ showError,
69
+ style,
70
+ value
71
+ });
72
+ };
73
+ const FilterDimensionSelectField = withCondition(FilterDimensionSelectFieldComponent);
74
+ //#endregion
75
+ export { FilterDimensionSelectField };
76
+
77
+ //# sourceMappingURL=FilterDimensionSelectField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilterDimensionSelectField.js","names":["useTranslation"],"sources":["../../../src/fields/config/FilterDimensionSelectField.tsx"],"sourcesContent":["'use client'\n\nimport {\n\tFieldDescription,\n\ttype ReactSelectOption,\n\tSelectInput,\n\tuseField,\n\twithCondition,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { TextFieldClientProps } from 'payload'\nimport { useMemo } from 'react'\nimport { DIMENSION_KEYS, type DimensionKey } from '../../core/contract'\nimport { keys } from '../../translations/keys'\nimport { useTranslation } from '../../translations/useTranslation'\nimport { DIMENSION_LABELS } from '../../view/labels'\nimport { useFilterCapabilities } from './useFilterCapabilities'\n\nexport type FilterDimensionSelectFieldProps = TextFieldClientProps & {\n\t/**\n\t * Path of the sibling source select this picker narrows against, for custom widgets\n\t * whose source field is named differently. Defaults to `'dataSource'`.\n\t */\n\tsourceFieldPath?: string\n}\n\nconst asDimension = (value: string): DimensionKey | undefined =>\n\tDIMENSION_KEYS.find((key) => key === value)\n\n/**\n * Dimension picker for a widget's filter group: offers only the dimensions the widget's\n * chosen source can filter by, unioned over the request's sources while none is chosen.\n * A stored dimension the source dropped stays in the list so it reads as the filter it is\n * and can be cleared; the read path renders the unsupported state for it either way.\n * While the source list is in flight the picker offers nothing rather than a wrong list,\n * and says so once it settles empty or failed.\n */\nconst FilterDimensionSelectFieldComponent = (props: FilterDimensionSelectFieldProps) => {\n\tconst { field, path: pathFromProps, readOnly, sourceFieldPath } = props\n\tconst { t } = useTranslation()\n\tconst { dimensions, error, resolved } = useFilterCapabilities(sourceFieldPath)\n\tconst {\n\t\tcustomComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {},\n\t\tdisabled,\n\t\tpath,\n\t\tsetValue,\n\t\tshowError,\n\t\tvalue,\n\t} = useField<string>({ potentiallyStalePath: pathFromProps })\n\n\tconst options = useMemo(() => {\n\t\tconst offered = dimensions.map((key) => ({ label: t(DIMENSION_LABELS[key]), value: key }))\n\t\tif (!value || dimensions.some((key) => key === value)) return offered\n\t\tconst known = asDimension(value)\n\t\treturn [{ label: known ? t(DIMENSION_LABELS[known]) : value, value }, ...offered]\n\t}, [dimensions, t, value])\n\tconst style = useMemo(() => mergeFieldStyles(field), [field])\n\n\tconst notice = error\n\t\t? t(keys.fieldFilterError)\n\t\t: resolved && dimensions.length === 0\n\t\t\t? t(keys.fieldFilterEmpty)\n\t\t\t: null\n\n\treturn (\n\t\t<SelectInput\n\t\t\tAfterInput={AfterInput}\n\t\t\tBeforeInput={BeforeInput}\n\t\t\tclassName={field.admin?.className}\n\t\t\tDescription={\n\t\t\t\tnotice ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{Description ?? <FieldDescription description={field.admin?.description} path={path} />}\n\t\t\t\t\t\t<div className=\"field-description\">{notice}</div>\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\tDescription\n\t\t\t\t)\n\t\t\t}\n\t\t\tdescription={field.admin?.description}\n\t\t\tError={ErrorComponent}\n\t\t\tisClearable\n\t\t\tLabel={Label}\n\t\t\tlabel={field.label}\n\t\t\tname={field.name}\n\t\t\tonChange={(selected: ReactSelectOption | ReactSelectOption[]) => {\n\t\t\t\tconst option = Array.isArray(selected) ? selected[0] : selected\n\t\t\t\tsetValue(option?.value ? String(option.value) : null)\n\t\t\t}}\n\t\t\toptions={options}\n\t\t\tpath={path}\n\t\t\treadOnly={readOnly || disabled || field.admin?.readOnly}\n\t\t\tshowError={showError}\n\t\t\tstyle={style}\n\t\t\tvalue={value}\n\t\t/>\n\t)\n}\n\nexport const FilterDimensionSelectField = withCondition(FilterDimensionSelectFieldComponent)\n"],"mappings":";;;;;;;;;;;AA0BA,MAAM,eAAe,UACpB,eAAe,MAAM,QAAQ,QAAQ,KAAK;;;;;;;;;AAU3C,MAAM,uCAAuC,UAA2C;CACvF,MAAM,EAAE,OAAO,MAAM,eAAe,UAAU,oBAAoB;CAClE,MAAM,EAAE,MAAMA,iBAAe;CAC7B,MAAM,EAAE,YAAY,OAAO,aAAa,sBAAsB,eAAe;CAC7E,MAAM,EACL,kBAAkB,EAAE,YAAY,aAAa,aAAa,OAAO,gBAAgB,UAAU,CAAC,GAC5F,UACA,MACA,UACA,WACA,UACG,SAAiB,EAAE,sBAAsB,cAAc,CAAC;CAE5D,MAAM,UAAU,cAAc;EAC7B,MAAM,UAAU,WAAW,KAAK,SAAS;GAAE,OAAO,EAAE,iBAAiB,IAAI;GAAG,OAAO;EAAI,EAAE;EACzF,IAAI,CAAC,SAAS,WAAW,MAAM,QAAQ,QAAQ,KAAK,GAAG,OAAO;EAC9D,MAAM,QAAQ,YAAY,KAAK;EAC/B,OAAO,CAAC;GAAE,OAAO,QAAQ,EAAE,iBAAiB,MAAM,IAAI;GAAO;EAAM,GAAG,GAAG,OAAO;CACjF,GAAG;EAAC;EAAY;EAAG;CAAK,CAAC;CACzB,MAAM,QAAQ,cAAc,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;CAE5D,MAAM,SAAS,QACZ,EAAE,KAAK,gBAAgB,IACvB,YAAY,WAAW,WAAW,IACjC,EAAE,KAAK,gBAAgB,IACvB;CAEJ,OACC,oBAAC,aAAD;EACa;EACC;EACb,WAAW,MAAM,OAAO;EACxB,aACC,SACC,qBAAA,UAAA,EAAA,UAAA,CACE,eAAe,oBAAC,kBAAD;GAAkB,aAAa,MAAM,OAAO;GAAmB;EAAO,CAAA,GACtF,oBAAC,OAAD;GAAK,WAAU;aAAqB;EAAY,CAAA,CAC/C,EAAA,CAAA,IAEF;EAGF,aAAa,MAAM,OAAO;EAC1B,OAAO;EACP,aAAA;EACO;EACP,OAAO,MAAM;EACb,MAAM,MAAM;EACZ,WAAW,aAAsD;GAChE,MAAM,SAAS,MAAM,QAAQ,QAAQ,IAAI,SAAS,KAAK;GACvD,SAAS,QAAQ,QAAQ,OAAO,OAAO,KAAK,IAAI,IAAI;EACrD;EACS;EACH;EACN,UAAU,YAAY,YAAY,MAAM,OAAO;EACpC;EACJ;EACA;CACP,CAAA;AAEH;AAEA,MAAa,6BAA6B,cAAc,mCAAmC"}
@@ -0,0 +1,14 @@
1
+ import { TextFieldClientProps } from "payload";
2
+
3
+ //#region src/fields/config/FilterOperatorSelectField.d.ts
4
+ type FilterOperatorSelectFieldProps = TextFieldClientProps & {
5
+ /**
6
+ * Path of the sibling source select this picker narrows against, for custom widgets
7
+ * whose source field is named differently. Defaults to `'dataSource'`.
8
+ */
9
+ sourceFieldPath?: string;
10
+ };
11
+ declare const FilterOperatorSelectField: import("react").FC<FilterOperatorSelectFieldProps>;
12
+ //#endregion
13
+ export { FilterOperatorSelectField, FilterOperatorSelectFieldProps };
14
+ //# sourceMappingURL=FilterOperatorSelectField.d.ts.map
@@ -0,0 +1,75 @@
1
+ "use client";
2
+ import { FILTER_OPERATORS } from "../../core/contract.js";
3
+ import { keys } from "../../translations/keys.js";
4
+ import { FILTER_OPERATOR_KEYS } from "../../translations/metricKeys.js";
5
+ import { useTranslation as useTranslation$1 } from "../../translations/useTranslation.js";
6
+ import { useFilterCapabilities } from "./useFilterCapabilities.js";
7
+ import { useMemo } from "react";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ import { FieldDescription, SelectInput, useField, withCondition } from "@payloadcms/ui";
10
+ import { mergeFieldStyles } from "@payloadcms/ui/shared";
11
+ //#region src/fields/config/FilterOperatorSelectField.tsx
12
+ const asOperator = (value) => FILTER_OPERATORS.find((op) => op === value);
13
+ /**
14
+ * Operator picker for a widget's filter group: offers only the operators the widget's
15
+ * chosen source supports, unioned over the request's sources while none is chosen. It is
16
+ * not clearable, because a filter always compares somehow; the dimension is the gate that
17
+ * turns the filter off.
18
+ */
19
+ const FilterOperatorSelectFieldComponent = (props) => {
20
+ const { field, path: pathFromProps, readOnly, sourceFieldPath } = props;
21
+ const { t } = useTranslation$1();
22
+ const { error, operators, resolved } = useFilterCapabilities(sourceFieldPath);
23
+ const { customComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {}, disabled, path, setValue, showError, value } = useField({ potentiallyStalePath: pathFromProps });
24
+ const options = useMemo(() => {
25
+ const offered = operators.map((op) => ({
26
+ label: t(FILTER_OPERATOR_KEYS[op]),
27
+ value: op
28
+ }));
29
+ if (!value || operators.some((op) => op === value)) return offered;
30
+ const known = asOperator(value);
31
+ return [{
32
+ label: known ? t(FILTER_OPERATOR_KEYS[known]) : value,
33
+ value
34
+ }, ...offered];
35
+ }, [
36
+ operators,
37
+ t,
38
+ value
39
+ ]);
40
+ const style = useMemo(() => mergeFieldStyles(field), [field]);
41
+ const notice = error ? t(keys.fieldFilterError) : resolved && operators.length === 0 ? t(keys.fieldFilterEmpty) : null;
42
+ return /* @__PURE__ */ jsx(SelectInput, {
43
+ AfterInput,
44
+ BeforeInput,
45
+ className: field.admin?.className,
46
+ Description: notice ? /* @__PURE__ */ jsxs(Fragment, { children: [Description ?? /* @__PURE__ */ jsx(FieldDescription, {
47
+ description: field.admin?.description,
48
+ path
49
+ }), /* @__PURE__ */ jsx("div", {
50
+ className: "field-description",
51
+ children: notice
52
+ })] }) : Description,
53
+ description: field.admin?.description,
54
+ Error: ErrorComponent,
55
+ isClearable: false,
56
+ Label,
57
+ label: field.label,
58
+ name: field.name,
59
+ onChange: (selected) => {
60
+ const option = Array.isArray(selected) ? selected[0] : selected;
61
+ setValue(option?.value ? String(option.value) : null);
62
+ },
63
+ options,
64
+ path,
65
+ readOnly: readOnly || disabled || field.admin?.readOnly,
66
+ showError,
67
+ style,
68
+ value
69
+ });
70
+ };
71
+ const FilterOperatorSelectField = withCondition(FilterOperatorSelectFieldComponent);
72
+ //#endregion
73
+ export { FilterOperatorSelectField };
74
+
75
+ //# sourceMappingURL=FilterOperatorSelectField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilterOperatorSelectField.js","names":["useTranslation"],"sources":["../../../src/fields/config/FilterOperatorSelectField.tsx"],"sourcesContent":["'use client'\n\nimport {\n\tFieldDescription,\n\ttype ReactSelectOption,\n\tSelectInput,\n\tuseField,\n\twithCondition,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { TextFieldClientProps } from 'payload'\nimport { useMemo } from 'react'\nimport { FILTER_OPERATORS, type FilterOperator } from '../../core/contract'\nimport { keys } from '../../translations/keys'\nimport { FILTER_OPERATOR_KEYS } from '../../translations/metricKeys'\nimport { useTranslation } from '../../translations/useTranslation'\nimport { useFilterCapabilities } from './useFilterCapabilities'\n\nexport type FilterOperatorSelectFieldProps = TextFieldClientProps & {\n\t/**\n\t * Path of the sibling source select this picker narrows against, for custom widgets\n\t * whose source field is named differently. Defaults to `'dataSource'`.\n\t */\n\tsourceFieldPath?: string\n}\n\nconst asOperator = (value: string): FilterOperator | undefined =>\n\tFILTER_OPERATORS.find((op) => op === value)\n\n/**\n * Operator picker for a widget's filter group: offers only the operators the widget's\n * chosen source supports, unioned over the request's sources while none is chosen. It is\n * not clearable, because a filter always compares somehow; the dimension is the gate that\n * turns the filter off.\n */\nconst FilterOperatorSelectFieldComponent = (props: FilterOperatorSelectFieldProps) => {\n\tconst { field, path: pathFromProps, readOnly, sourceFieldPath } = props\n\tconst { t } = useTranslation()\n\tconst { error, operators, resolved } = useFilterCapabilities(sourceFieldPath)\n\tconst {\n\t\tcustomComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {},\n\t\tdisabled,\n\t\tpath,\n\t\tsetValue,\n\t\tshowError,\n\t\tvalue,\n\t} = useField<string>({ potentiallyStalePath: pathFromProps })\n\n\tconst options = useMemo(() => {\n\t\tconst offered = operators.map((op) => ({ label: t(FILTER_OPERATOR_KEYS[op]), value: op }))\n\t\tif (!value || operators.some((op) => op === value)) return offered\n\t\tconst known = asOperator(value)\n\t\treturn [{ label: known ? t(FILTER_OPERATOR_KEYS[known]) : value, value }, ...offered]\n\t}, [operators, t, value])\n\tconst style = useMemo(() => mergeFieldStyles(field), [field])\n\n\tconst notice = error\n\t\t? t(keys.fieldFilterError)\n\t\t: resolved && operators.length === 0\n\t\t\t? t(keys.fieldFilterEmpty)\n\t\t\t: null\n\n\treturn (\n\t\t<SelectInput\n\t\t\tAfterInput={AfterInput}\n\t\t\tBeforeInput={BeforeInput}\n\t\t\tclassName={field.admin?.className}\n\t\t\tDescription={\n\t\t\t\tnotice ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{Description ?? <FieldDescription description={field.admin?.description} path={path} />}\n\t\t\t\t\t\t<div className=\"field-description\">{notice}</div>\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\tDescription\n\t\t\t\t)\n\t\t\t}\n\t\t\tdescription={field.admin?.description}\n\t\t\tError={ErrorComponent}\n\t\t\tisClearable={false}\n\t\t\tLabel={Label}\n\t\t\tlabel={field.label}\n\t\t\tname={field.name}\n\t\t\tonChange={(selected: ReactSelectOption | ReactSelectOption[]) => {\n\t\t\t\tconst option = Array.isArray(selected) ? selected[0] : selected\n\t\t\t\tsetValue(option?.value ? String(option.value) : null)\n\t\t\t}}\n\t\t\toptions={options}\n\t\t\tpath={path}\n\t\t\treadOnly={readOnly || disabled || field.admin?.readOnly}\n\t\t\tshowError={showError}\n\t\t\tstyle={style}\n\t\t\tvalue={value}\n\t\t/>\n\t)\n}\n\nexport const FilterOperatorSelectField = withCondition(FilterOperatorSelectFieldComponent)\n"],"mappings":";;;;;;;;;;;AA0BA,MAAM,cAAc,UACnB,iBAAiB,MAAM,OAAO,OAAO,KAAK;;;;;;;AAQ3C,MAAM,sCAAsC,UAA0C;CACrF,MAAM,EAAE,OAAO,MAAM,eAAe,UAAU,oBAAoB;CAClE,MAAM,EAAE,MAAMA,iBAAe;CAC7B,MAAM,EAAE,OAAO,WAAW,aAAa,sBAAsB,eAAe;CAC5E,MAAM,EACL,kBAAkB,EAAE,YAAY,aAAa,aAAa,OAAO,gBAAgB,UAAU,CAAC,GAC5F,UACA,MACA,UACA,WACA,UACG,SAAiB,EAAE,sBAAsB,cAAc,CAAC;CAE5D,MAAM,UAAU,cAAc;EAC7B,MAAM,UAAU,UAAU,KAAK,QAAQ;GAAE,OAAO,EAAE,qBAAqB,GAAG;GAAG,OAAO;EAAG,EAAE;EACzF,IAAI,CAAC,SAAS,UAAU,MAAM,OAAO,OAAO,KAAK,GAAG,OAAO;EAC3D,MAAM,QAAQ,WAAW,KAAK;EAC9B,OAAO,CAAC;GAAE,OAAO,QAAQ,EAAE,qBAAqB,MAAM,IAAI;GAAO;EAAM,GAAG,GAAG,OAAO;CACrF,GAAG;EAAC;EAAW;EAAG;CAAK,CAAC;CACxB,MAAM,QAAQ,cAAc,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;CAE5D,MAAM,SAAS,QACZ,EAAE,KAAK,gBAAgB,IACvB,YAAY,UAAU,WAAW,IAChC,EAAE,KAAK,gBAAgB,IACvB;CAEJ,OACC,oBAAC,aAAD;EACa;EACC;EACb,WAAW,MAAM,OAAO;EACxB,aACC,SACC,qBAAA,UAAA,EAAA,UAAA,CACE,eAAe,oBAAC,kBAAD;GAAkB,aAAa,MAAM,OAAO;GAAmB;EAAO,CAAA,GACtF,oBAAC,OAAD;GAAK,WAAU;aAAqB;EAAY,CAAA,CAC/C,EAAA,CAAA,IAEF;EAGF,aAAa,MAAM,OAAO;EAC1B,OAAO;EACP,aAAa;EACN;EACP,OAAO,MAAM;EACb,MAAM,MAAM;EACZ,WAAW,aAAsD;GAChE,MAAM,SAAS,MAAM,QAAQ,QAAQ,IAAI,SAAS,KAAK;GACvD,SAAS,QAAQ,QAAQ,OAAO,OAAO,KAAK,IAAI,IAAI;EACrD;EACS;EACH;EACN,UAAU,YAAY,YAAY,MAAM,OAAO;EACpC;EACJ;EACA;CACP,CAAA;AAEH;AAEA,MAAa,4BAA4B,cAAc,kCAAkC"}
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import { useTranslation as useTranslation$1 } from "../../translations/useTranslation.js";
3
+ import { useAnalyticsSources } from "./useAnalyticsSources.js";
3
4
  import { narrowMetricOptions } from "./narrow.js";
4
5
  import { toSelectOption } from "./toSelectOption.js";
5
- import { useAnalyticsSources } from "./useAnalyticsSources.js";
6
6
  import { useMemo } from "react";
7
7
  import { jsx } from "react/jsx-runtime";
8
8
  import { SelectInput, useField, useFormFields } from "@payloadcms/ui";
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { useTranslation as useTranslation$1 } from "../../translations/useTranslation.js";
3
- import { toSelectOption } from "./toSelectOption.js";
4
3
  import { useAnalyticsSources } from "./useAnalyticsSources.js";
4
+ import { toSelectOption } from "./toSelectOption.js";
5
5
  import { useMemo } from "react";
6
6
  import { jsx } from "react/jsx-runtime";
7
7
  import { SelectInput, useField } from "@payloadcms/ui";
@@ -1,11 +1,27 @@
1
1
  //#region src/fields/config/sourcesState.ts
2
2
  const EMPTY_SOURCES = {
3
3
  defaultId: null,
4
+ error: false,
5
+ loading: false,
4
6
  sources: null
5
7
  };
6
- /** Sources fetched for another user never render: a key mismatch reads as not-yet-loaded. */
7
- const resolveSourcesState = (state, userKey) => state.key === userKey ? state.data : EMPTY_SOURCES;
8
+ const LOADING_SOURCES = {
9
+ ...EMPTY_SOURCES,
10
+ loading: true
11
+ };
12
+ const FAILED_SOURCES = {
13
+ ...EMPTY_SOURCES,
14
+ error: true
15
+ };
16
+ /**
17
+ * Sources fetched for another user never render: a key mismatch reads as not-yet-loaded,
18
+ * and as still loading whenever there is a user whose fetch has yet to answer.
19
+ */
20
+ const resolveSourcesState = (state, userKey) => {
21
+ if (state.key === userKey) return state.data;
22
+ return userKey ? LOADING_SOURCES : EMPTY_SOURCES;
23
+ };
8
24
  //#endregion
9
- export { EMPTY_SOURCES, resolveSourcesState };
25
+ export { EMPTY_SOURCES, FAILED_SOURCES, resolveSourcesState };
10
26
 
11
27
  //# sourceMappingURL=sourcesState.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sourcesState.js","names":[],"sources":["../../../src/fields/config/sourcesState.ts"],"sourcesContent":["import type { AnalyticsSources } from './useAnalyticsSources'\n\nexport interface KeyedSources {\n\tkey: string\n\tdata: AnalyticsSources\n}\n\nexport const EMPTY_SOURCES: AnalyticsSources = { defaultId: null, sources: null }\n\n/** Sources fetched for another user never render: a key mismatch reads as not-yet-loaded. */\nexport const resolveSourcesState = (state: KeyedSources, userKey: string): AnalyticsSources =>\n\tstate.key === userKey ? state.data : EMPTY_SOURCES\n"],"mappings":";AAOA,MAAa,gBAAkC;CAAE,WAAW;CAAM,SAAS;AAAK;;AAGhF,MAAa,uBAAuB,OAAqB,YACxD,MAAM,QAAQ,UAAU,MAAM,OAAO"}
1
+ {"version":3,"file":"sourcesState.js","names":[],"sources":["../../../src/fields/config/sourcesState.ts"],"sourcesContent":["import type { AnalyticsSources } from './useAnalyticsSources'\n\nexport interface KeyedSources {\n\tkey: string\n\tdata: AnalyticsSources\n}\n\nexport const EMPTY_SOURCES: AnalyticsSources = {\n\tdefaultId: null,\n\terror: false,\n\tloading: false,\n\tsources: null,\n}\n\nexport const LOADING_SOURCES: AnalyticsSources = { ...EMPTY_SOURCES, loading: true }\n\nexport const FAILED_SOURCES: AnalyticsSources = { ...EMPTY_SOURCES, error: true }\n\n/**\n * Sources fetched for another user never render: a key mismatch reads as not-yet-loaded,\n * and as still loading whenever there is a user whose fetch has yet to answer.\n */\nexport const resolveSourcesState = (state: KeyedSources, userKey: string): AnalyticsSources => {\n\tif (state.key === userKey) return state.data\n\treturn userKey ? LOADING_SOURCES : EMPTY_SOURCES\n}\n"],"mappings":";AAOA,MAAa,gBAAkC;CAC9C,WAAW;CACX,OAAO;CACP,SAAS;CACT,SAAS;AACV;AAEA,MAAa,kBAAoC;CAAE,GAAG;CAAe,SAAS;AAAK;AAEnF,MAAa,iBAAmC;CAAE,GAAG;CAAe,OAAO;AAAK;;;;;AAMhF,MAAa,uBAAuB,OAAqB,YAAsC;CAC9F,IAAI,MAAM,QAAQ,SAAS,OAAO,MAAM;CACxC,OAAO,UAAU,kBAAkB;AACpC"}
@@ -4,16 +4,21 @@ import { WireSource } from "./fetchSources.js";
4
4
  interface AnalyticsSources {
5
5
  sources: WireSource[] | null;
6
6
  defaultId: string | null;
7
+ /** The fetch has yet to answer: not the same thing as a scope with no sources. */
8
+ loading: boolean;
9
+ /** The fetch settled in failure, so a picker can say so instead of claiming none exist. */
10
+ error: boolean;
7
11
  }
8
12
  /**
9
13
  * Fetches the caller-scope source list for widget config pickers, sharing the
10
14
  * per-user cache `fetchSources` already keeps. `sources` and `defaultId` stay
11
15
  * null until the fetch resolves, on a failed fetch, or when there is no
12
16
  * authenticated user yet; consumers fall back to their static option list in
13
- * that window. Sources fetched for a previous user are never returned while
14
- * a new user's fetch is pending.
17
+ * that window, and `loading`/`error` tell those two windows apart. Sources
18
+ * fetched for a previous user are never returned while a new user's fetch is
19
+ * pending.
15
20
  */
16
21
  declare const useAnalyticsSources: () => AnalyticsSources;
17
22
  //#endregion
18
- export { useAnalyticsSources };
23
+ export { AnalyticsSources, useAnalyticsSources };
19
24
  //# sourceMappingURL=useAnalyticsSources.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { fetchSources } from "./fetchSources.js";
3
- import { EMPTY_SOURCES, resolveSourcesState } from "./sourcesState.js";
3
+ import { EMPTY_SOURCES, FAILED_SOURCES, resolveSourcesState } from "./sourcesState.js";
4
4
  import { useEffect, useState } from "react";
5
5
  import { useAuth, useConfig } from "@payloadcms/ui";
6
6
  //#region src/fields/config/useAnalyticsSources.ts
@@ -9,8 +9,9 @@ import { useAuth, useConfig } from "@payloadcms/ui";
9
9
  * per-user cache `fetchSources` already keeps. `sources` and `defaultId` stay
10
10
  * null until the fetch resolves, on a failed fetch, or when there is no
11
11
  * authenticated user yet; consumers fall back to their static option list in
12
- * that window. Sources fetched for a previous user are never returned while
13
- * a new user's fetch is pending.
12
+ * that window, and `loading`/`error` tell those two windows apart. Sources
13
+ * fetched for a previous user are never returned while a new user's fetch is
14
+ * pending.
14
15
  */
15
16
  const useAnalyticsSources = () => {
16
17
  const { user } = useAuth();
@@ -33,14 +34,16 @@ const useAnalyticsSources = () => {
33
34
  if (!cancelled) setState({
34
35
  key: userKey,
35
36
  data: {
36
- sources,
37
- defaultId
37
+ defaultId,
38
+ error: false,
39
+ loading: false,
40
+ sources
38
41
  }
39
42
  });
40
43
  }).catch(() => {
41
44
  if (!cancelled) setState({
42
45
  key: userKey,
43
- data: EMPTY_SOURCES
46
+ data: FAILED_SOURCES
44
47
  });
45
48
  });
46
49
  return () => {
@@ -1 +1 @@
1
- {"version":3,"file":"useAnalyticsSources.js","names":[],"sources":["../../../src/fields/config/useAnalyticsSources.ts"],"sourcesContent":["'use client'\n\nimport { useAuth, useConfig } from '@payloadcms/ui'\nimport { useEffect, useState } from 'react'\nimport { fetchSources, type WireSource } from './fetchSources'\nimport { EMPTY_SOURCES, type KeyedSources, resolveSourcesState } from './sourcesState'\n\nexport interface AnalyticsSources {\n\tsources: WireSource[] | null\n\tdefaultId: string | null\n}\n\n/**\n * Fetches the caller-scope source list for widget config pickers, sharing the\n * per-user cache `fetchSources` already keeps. `sources` and `defaultId` stay\n * null until the fetch resolves, on a failed fetch, or when there is no\n * authenticated user yet; consumers fall back to their static option list in\n * that window. Sources fetched for a previous user are never returned while\n * a new user's fetch is pending.\n */\nexport const useAnalyticsSources = (): AnalyticsSources => {\n\tconst { user } = useAuth()\n\tconst {\n\t\tconfig: {\n\t\t\troutes: { api },\n\t\t\tserverURL,\n\t\t},\n\t} = useConfig()\n\tconst userKey = String(user?.id ?? '')\n\tconst [state, setState] = useState<KeyedSources>({ key: '', data: EMPTY_SOURCES })\n\n\tuseEffect(() => {\n\t\tif (!userKey) {\n\t\t\tsetState({ key: '', data: EMPTY_SOURCES })\n\t\t\treturn\n\t\t}\n\t\tlet cancelled = false\n\t\tfetchSources(serverURL ?? '', api, userKey)\n\t\t\t.then(({ defaultId, sources }) => {\n\t\t\t\tif (!cancelled) setState({ key: userKey, data: { sources, defaultId } })\n\t\t\t})\n\t\t\t.catch(() => {\n\t\t\t\tif (!cancelled) setState({ key: userKey, data: EMPTY_SOURCES })\n\t\t\t})\n\t\treturn () => {\n\t\t\tcancelled = true\n\t\t}\n\t}, [api, serverURL, userKey])\n\n\treturn resolveSourcesState(state, userKey)\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,MAAa,4BAA8C;CAC1D,MAAM,EAAE,SAAS,QAAQ;CACzB,MAAM,EACL,QAAQ,EACP,QAAQ,EAAE,OACV,gBAEE,UAAU;CACd,MAAM,UAAU,OAAO,MAAM,MAAM,EAAE;CACrC,MAAM,CAAC,OAAO,YAAY,SAAuB;EAAE,KAAK;EAAI,MAAM;CAAc,CAAC;CAEjF,gBAAgB;EACf,IAAI,CAAC,SAAS;GACb,SAAS;IAAE,KAAK;IAAI,MAAM;GAAc,CAAC;GACzC;EACD;EACA,IAAI,YAAY;EAChB,aAAa,aAAa,IAAI,KAAK,OAAO,EACxC,MAAM,EAAE,WAAW,cAAc;GACjC,IAAI,CAAC,WAAW,SAAS;IAAE,KAAK;IAAS,MAAM;KAAE;KAAS;IAAU;GAAE,CAAC;EACxE,CAAC,EACA,YAAY;GACZ,IAAI,CAAC,WAAW,SAAS;IAAE,KAAK;IAAS,MAAM;GAAc,CAAC;EAC/D,CAAC;EACF,aAAa;GACZ,YAAY;EACb;CACD,GAAG;EAAC;EAAK;EAAW;CAAO,CAAC;CAE5B,OAAO,oBAAoB,OAAO,OAAO;AAC1C"}
1
+ {"version":3,"file":"useAnalyticsSources.js","names":[],"sources":["../../../src/fields/config/useAnalyticsSources.ts"],"sourcesContent":["'use client'\n\nimport { useAuth, useConfig } from '@payloadcms/ui'\nimport { useEffect, useState } from 'react'\nimport { fetchSources, type WireSource } from './fetchSources'\nimport {\n\tEMPTY_SOURCES,\n\tFAILED_SOURCES,\n\ttype KeyedSources,\n\tresolveSourcesState,\n} from './sourcesState'\n\nexport interface AnalyticsSources {\n\tsources: WireSource[] | null\n\tdefaultId: string | null\n\t/** The fetch has yet to answer: not the same thing as a scope with no sources. */\n\tloading: boolean\n\t/** The fetch settled in failure, so a picker can say so instead of claiming none exist. */\n\terror: boolean\n}\n\n/**\n * Fetches the caller-scope source list for widget config pickers, sharing the\n * per-user cache `fetchSources` already keeps. `sources` and `defaultId` stay\n * null until the fetch resolves, on a failed fetch, or when there is no\n * authenticated user yet; consumers fall back to their static option list in\n * that window, and `loading`/`error` tell those two windows apart. Sources\n * fetched for a previous user are never returned while a new user's fetch is\n * pending.\n */\nexport const useAnalyticsSources = (): AnalyticsSources => {\n\tconst { user } = useAuth()\n\tconst {\n\t\tconfig: {\n\t\t\troutes: { api },\n\t\t\tserverURL,\n\t\t},\n\t} = useConfig()\n\tconst userKey = String(user?.id ?? '')\n\tconst [state, setState] = useState<KeyedSources>({ key: '', data: EMPTY_SOURCES })\n\n\tuseEffect(() => {\n\t\tif (!userKey) {\n\t\t\tsetState({ key: '', data: EMPTY_SOURCES })\n\t\t\treturn\n\t\t}\n\t\tlet cancelled = false\n\t\tfetchSources(serverURL ?? '', api, userKey)\n\t\t\t.then(({ defaultId, sources }) => {\n\t\t\t\tif (!cancelled) {\n\t\t\t\t\tsetState({ key: userKey, data: { defaultId, error: false, loading: false, sources } })\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch(() => {\n\t\t\t\tif (!cancelled) setState({ key: userKey, data: FAILED_SOURCES })\n\t\t\t})\n\t\treturn () => {\n\t\t\tcancelled = true\n\t\t}\n\t}, [api, serverURL, userKey])\n\n\treturn resolveSourcesState(state, userKey)\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8BA,MAAa,4BAA8C;CAC1D,MAAM,EAAE,SAAS,QAAQ;CACzB,MAAM,EACL,QAAQ,EACP,QAAQ,EAAE,OACV,gBAEE,UAAU;CACd,MAAM,UAAU,OAAO,MAAM,MAAM,EAAE;CACrC,MAAM,CAAC,OAAO,YAAY,SAAuB;EAAE,KAAK;EAAI,MAAM;CAAc,CAAC;CAEjF,gBAAgB;EACf,IAAI,CAAC,SAAS;GACb,SAAS;IAAE,KAAK;IAAI,MAAM;GAAc,CAAC;GACzC;EACD;EACA,IAAI,YAAY;EAChB,aAAa,aAAa,IAAI,KAAK,OAAO,EACxC,MAAM,EAAE,WAAW,cAAc;GACjC,IAAI,CAAC,WACJ,SAAS;IAAE,KAAK;IAAS,MAAM;KAAE;KAAW,OAAO;KAAO,SAAS;KAAO;IAAQ;GAAE,CAAC;EAEvF,CAAC,EACA,YAAY;GACZ,IAAI,CAAC,WAAW,SAAS;IAAE,KAAK;IAAS,MAAM;GAAe,CAAC;EAChE,CAAC;EACF,aAAa;GACZ,YAAY;EACb;CACD,GAAG;EAAC;EAAK;EAAW;CAAO,CAAC;CAE5B,OAAO,oBAAoB,OAAO,OAAO;AAC1C"}
@@ -0,0 +1,28 @@
1
+ import { DimensionKey, FilterOperator } from "../../core/contract.js";
2
+ //#region src/fields/config/useFilterCapabilities.d.ts
3
+ interface FilterCapabilities {
4
+ /** Dimensions the widget may filter on, in contract order. */
5
+ dimensions: DimensionKey[];
6
+ /** Operators the widget may filter with, in contract order. */
7
+ operators: FilterOperator[];
8
+ /** The source list has yet to answer; offer nothing rather than a wrong list. */
9
+ loading: boolean;
10
+ /** The source list could not be fetched, so an empty offer is not a verdict. */
11
+ error: boolean;
12
+ /**
13
+ * A source list actually answered. False covers both the pending fetch and the window
14
+ * before there is a user to fetch for, where nothing offered is not yet a verdict.
15
+ */
16
+ resolved: boolean;
17
+ }
18
+ /**
19
+ * Filter capabilities for the source a widget's config form currently points at, read
20
+ * from that field's value in form state. `dataSourcePath` is a form path, not a relative
21
+ * sibling lookup: it defaults to the top-level `dataSource` the widget config forms use,
22
+ * and a custom widget whose source field sits elsewhere passes its own path, exactly as
23
+ * `MetricSelectField` does.
24
+ */
25
+ declare const useFilterCapabilities: (dataSourcePath?: string) => FilterCapabilities;
26
+ //#endregion
27
+ export { FilterCapabilities, useFilterCapabilities };
28
+ //# sourceMappingURL=useFilterCapabilities.d.ts.map
@@ -0,0 +1,52 @@
1
+ "use client";
2
+ import { DIMENSION_KEYS, FILTER_OPERATORS } from "../../core/contract.js";
3
+ import { useAnalyticsSources } from "./useAnalyticsSources.js";
4
+ import { useMemo } from "react";
5
+ import { useFormFields } from "@payloadcms/ui";
6
+ //#region src/fields/config/useFilterCapabilities.ts
7
+ const EMPTY = {
8
+ dimensions: [],
9
+ operators: []
10
+ };
11
+ /**
12
+ * What the widget's chosen source can filter by. An unknown source id (a stale value, a
13
+ * runtime source the endpoint could not list) falls back to the union, mirroring the
14
+ * metric picker's narrowing; the union is also what a single-provider install sees, where
15
+ * there is no source field to read.
16
+ */
17
+ const deriveFilterCapabilities = (args) => {
18
+ const { sourceId, sources } = args;
19
+ if (!sources || sources.length === 0) return EMPTY;
20
+ const picked = sourceId ? sources.find((s) => s.id === sourceId) : void 0;
21
+ const scope = picked ? [picked] : sources;
22
+ return {
23
+ dimensions: DIMENSION_KEYS.filter((d) => scope.some((s) => s.capabilities.filters.includes(d))),
24
+ operators: FILTER_OPERATORS.filter((op) => scope.some((s) => s.capabilities.filterOperators.includes(op)))
25
+ };
26
+ };
27
+ /**
28
+ * Filter capabilities for the source a widget's config form currently points at, read
29
+ * from that field's value in form state. `dataSourcePath` is a form path, not a relative
30
+ * sibling lookup: it defaults to the top-level `dataSource` the widget config forms use,
31
+ * and a custom widget whose source field sits elsewhere passes its own path, exactly as
32
+ * `MetricSelectField` does.
33
+ */
34
+ const useFilterCapabilities = (dataSourcePath = "dataSource") => {
35
+ const { error, loading, sources } = useAnalyticsSources();
36
+ const sourceId = useFormFields(([fields]) => fields?.[dataSourcePath]?.value);
37
+ const { dimensions, operators } = useMemo(() => deriveFilterCapabilities({
38
+ sourceId,
39
+ sources
40
+ }), [sourceId, sources]);
41
+ return {
42
+ dimensions,
43
+ error,
44
+ loading,
45
+ operators,
46
+ resolved: sources !== null
47
+ };
48
+ };
49
+ //#endregion
50
+ export { useFilterCapabilities };
51
+
52
+ //# sourceMappingURL=useFilterCapabilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFilterCapabilities.js","names":[],"sources":["../../../src/fields/config/useFilterCapabilities.ts"],"sourcesContent":["'use client'\n\nimport { useFormFields } from '@payloadcms/ui'\nimport { useMemo } from 'react'\nimport {\n\tDIMENSION_KEYS,\n\ttype DimensionKey,\n\tFILTER_OPERATORS,\n\ttype FilterOperator,\n} from '../../core/contract'\nimport type { WireSource } from './fetchSources'\nimport { useAnalyticsSources } from './useAnalyticsSources'\n\nexport interface FilterCapabilities {\n\t/** Dimensions the widget may filter on, in contract order. */\n\tdimensions: DimensionKey[]\n\t/** Operators the widget may filter with, in contract order. */\n\toperators: FilterOperator[]\n\t/** The source list has yet to answer; offer nothing rather than a wrong list. */\n\tloading: boolean\n\t/** The source list could not be fetched, so an empty offer is not a verdict. */\n\terror: boolean\n\t/**\n\t * A source list actually answered. False covers both the pending fetch and the window\n\t * before there is a user to fetch for, where nothing offered is not yet a verdict.\n\t */\n\tresolved: boolean\n}\n\nconst EMPTY: Pick<FilterCapabilities, 'dimensions' | 'operators'> = {\n\tdimensions: [],\n\toperators: [],\n}\n\n/**\n * What the widget's chosen source can filter by. An unknown source id (a stale value, a\n * runtime source the endpoint could not list) falls back to the union, mirroring the\n * metric picker's narrowing; the union is also what a single-provider install sees, where\n * there is no source field to read.\n */\nexport const deriveFilterCapabilities = (args: {\n\tsources: WireSource[] | null\n\tsourceId: string | undefined\n}): Pick<FilterCapabilities, 'dimensions' | 'operators'> => {\n\tconst { sourceId, sources } = args\n\tif (!sources || sources.length === 0) return EMPTY\n\tconst picked = sourceId ? sources.find((s) => s.id === sourceId) : undefined\n\tconst scope = picked ? [picked] : sources\n\treturn {\n\t\tdimensions: DIMENSION_KEYS.filter((d) => scope.some((s) => s.capabilities.filters.includes(d))),\n\t\toperators: FILTER_OPERATORS.filter((op) =>\n\t\t\tscope.some((s) => s.capabilities.filterOperators.includes(op))\n\t\t),\n\t}\n}\n\n/**\n * Filter capabilities for the source a widget's config form currently points at, read\n * from that field's value in form state. `dataSourcePath` is a form path, not a relative\n * sibling lookup: it defaults to the top-level `dataSource` the widget config forms use,\n * and a custom widget whose source field sits elsewhere passes its own path, exactly as\n * `MetricSelectField` does.\n */\nexport const useFilterCapabilities = (dataSourcePath = 'dataSource'): FilterCapabilities => {\n\tconst { error, loading, sources } = useAnalyticsSources()\n\tconst sourceId = useFormFields(\n\t\t([fields]) => fields?.[dataSourcePath]?.value as string | undefined\n\t)\n\tconst { dimensions, operators } = useMemo(\n\t\t() => deriveFilterCapabilities({ sourceId, sources }),\n\t\t[sourceId, sources]\n\t)\n\treturn { dimensions, error, loading, operators, resolved: sources !== null }\n}\n"],"mappings":";;;;;;AA6BA,MAAM,QAA8D;CACnE,YAAY,CAAC;CACb,WAAW,CAAC;AACb;;;;;;;AAQA,MAAa,4BAA4B,SAGmB;CAC3D,MAAM,EAAE,UAAU,YAAY;CAC9B,IAAI,CAAC,WAAW,QAAQ,WAAW,GAAG,OAAO;CAC7C,MAAM,SAAS,WAAW,QAAQ,MAAM,MAAM,EAAE,OAAO,QAAQ,IAAI,KAAA;CACnE,MAAM,QAAQ,SAAS,CAAC,MAAM,IAAI;CAClC,OAAO;EACN,YAAY,eAAe,QAAQ,MAAM,MAAM,MAAM,MAAM,EAAE,aAAa,QAAQ,SAAS,CAAC,CAAC,CAAC;EAC9F,WAAW,iBAAiB,QAAQ,OACnC,MAAM,MAAM,MAAM,EAAE,aAAa,gBAAgB,SAAS,EAAE,CAAC,CAC9D;CACD;AACD;;;;;;;;AASA,MAAa,yBAAyB,iBAAiB,iBAAqC;CAC3F,MAAM,EAAE,OAAO,SAAS,YAAY,oBAAoB;CACxD,MAAM,WAAW,eACf,CAAC,YAAY,SAAS,iBAAiB,KACzC;CACA,MAAM,EAAE,YAAY,cAAc,cAC3B,yBAAyB;EAAE;EAAU;CAAQ,CAAC,GACpD,CAAC,UAAU,OAAO,CACnB;CACA,OAAO;EAAE;EAAY;EAAO;EAAS;EAAW,UAAU,YAAY;CAAK;AAC5E"}
@@ -1,10 +1,11 @@
1
1
  import { getRuntime, resolveTimezoneFor } from "../plugin/runtime.js";
2
2
  import { resolveTimeframe } from "../timeframe/presets.js";
3
3
  import { resolveHostname, resolvePathCached } from "../binding/resolvePath.js";
4
- import { satisfiesCapabilities } from "../core/capabilities.js";
4
+ import { comparisonOf, satisfiesCapabilities } from "../core/capabilities.js";
5
5
  import { supportsGranularity } from "../core/granularity.js";
6
6
  import { resolveReadContext } from "../core/scopedRead.js";
7
- import { previousWindow } from "../widgets/comparison.js";
7
+ import { goalSlugsFor } from "../plugin/goalHint.js";
8
+ import { previousWindow, withinLookback } from "../widgets/comparison.js";
8
9
  import { fillDailySeries } from "../widgets/readForWidgetSeries.js";
9
10
  //#region src/fields/readForDocument.ts
10
11
  /**
@@ -97,13 +98,24 @@ const readForField = async (args) => {
97
98
  droppedMetrics: metrics
98
99
  };
99
100
  const hostname = await resolveHostname(binding, data, bindingCtx);
101
+ const goalSlugs = await goalSlugsFor({
102
+ runtime,
103
+ req,
104
+ scope: ctx.scope,
105
+ metrics: supportedMetrics
106
+ });
100
107
  const base = {
101
108
  path,
102
109
  hostname,
103
110
  timezone: tz,
104
- scope: ctx.queryScope
111
+ scope: ctx.queryScope,
112
+ ...goalSlugs === void 0 ? {} : { goalSlugs }
105
113
  };
106
- const comparisonRange = args.compare && runtime.comparison && adapter.capabilities.comparison ? previousWindow(dateRange, tz) ?? void 0 : void 0;
114
+ const previousRange = args.compare && runtime.comparison && comparisonOf(adapter.capabilities) ? previousWindow(dateRange, tz) : null;
115
+ const comparisonRange = previousRange && withinLookback(previousRange, adapter.capabilities.maxLookbackDays, {
116
+ tz,
117
+ now
118
+ }) ? previousRange : void 0;
107
119
  const wantsSeries = args.series && supportsGranularity(adapter.capabilities, "day");
108
120
  const [result, previous, seriesResult] = await Promise.all([
109
121
  runtime.engine.read(adapter, {