@10x-media/analytics 0.1.0-beta.4 → 1.0.0-beta.10
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/CHANGELOG.md +280 -0
- package/LICENSE +21 -21
- package/README.md +15 -4
- package/dist/adapters/ga4/disableKey.d.ts +9 -0
- package/dist/adapters/ga4/disableKey.js +21 -0
- package/dist/adapters/ga4/disableKey.js.map +1 -0
- package/dist/adapters/ga4/eventName.d.ts +15 -0
- package/dist/adapters/ga4/eventName.js +19 -0
- package/dist/adapters/ga4/eventName.js.map +1 -0
- package/dist/adapters/ga4/ga4.d.ts +5 -0
- package/dist/adapters/ga4/ga4.js +186 -58
- package/dist/adapters/ga4/ga4.js.map +1 -1
- package/dist/adapters/ga4/measurementId.js +15 -0
- package/dist/adapters/ga4/measurementId.js.map +1 -0
- package/dist/adapters/goalRead.js +126 -0
- package/dist/adapters/goalRead.js.map +1 -0
- package/dist/adapters/http/fetchJson.js +1 -1
- package/dist/adapters/plausible/plausible.d.ts +25 -0
- package/dist/adapters/plausible/plausible.js +159 -38
- package/dist/adapters/plausible/plausible.js.map +1 -1
- package/dist/adapters/posthog/posthog.d.ts +10 -1
- package/dist/adapters/posthog/posthog.js +130 -21
- package/dist/adapters/posthog/posthog.js.map +1 -1
- package/dist/adapters/series.js +11 -1
- package/dist/adapters/series.js.map +1 -1
- package/dist/adapters/umami/umami.d.ts +13 -1
- package/dist/adapters/umami/umami.js +278 -26
- package/dist/adapters/umami/umami.js.map +1 -1
- package/dist/binding/resolvePath.js +18 -2
- package/dist/binding/resolvePath.js.map +1 -1
- package/dist/capture/getTrackerConfig.d.ts +20 -0
- package/dist/capture/getTrackerConfig.js +31 -0
- package/dist/capture/getTrackerConfig.js.map +1 -0
- package/dist/capture/mountPath.js +14 -0
- package/dist/capture/mountPath.js.map +1 -0
- package/dist/capture/proxyEndpoint.js +127 -0
- package/dist/capture/proxyEndpoint.js.map +1 -0
- package/dist/capture/proxyRoutes.js +108 -0
- package/dist/capture/proxyRoutes.js.map +1 -0
- package/dist/capture/requestBody.js +68 -0
- package/dist/capture/requestBody.js.map +1 -0
- package/dist/capture/slots.d.ts +8 -0
- package/dist/capture/slots.js +54 -0
- package/dist/capture/slots.js.map +1 -0
- package/dist/capture/trackerConfig.d.ts +33 -0
- package/dist/capture/trackerConfig.js +95 -0
- package/dist/capture/trackerConfig.js.map +1 -0
- package/dist/capture/trackerEndpoint.js +35 -0
- package/dist/capture/trackerEndpoint.js.map +1 -0
- package/dist/charts/BarList.d.ts +16 -1
- package/dist/charts/BarList.js +41 -19
- package/dist/charts/BarList.js.map +1 -1
- package/dist/charts/TrendChart.d.ts +16 -3
- package/dist/charts/TrendChart.js +172 -106
- package/dist/charts/TrendChart.js.map +1 -1
- package/dist/charts/bars.d.ts +4 -0
- package/dist/charts/bars.js +3 -1
- package/dist/charts/bars.js.map +1 -1
- package/dist/charts/bucket.js +10 -1
- package/dist/charts/bucket.js.map +1 -1
- package/dist/charts/spline.js +2 -2
- package/dist/charts/spline.js.map +1 -1
- package/dist/charts/styles.js +18 -1
- package/dist/charts/styles.js.map +1 -1
- package/dist/core/cacheKey.js +26 -3
- package/dist/core/cacheKey.js.map +1 -1
- package/dist/core/capabilities.d.ts +17 -2
- package/dist/core/capabilities.js +20 -1
- package/dist/core/capabilities.js.map +1 -1
- package/dist/core/capture.d.ts +49 -0
- package/dist/core/contract.d.ts +74 -5
- package/dist/core/contract.js +30 -1
- package/dist/core/contract.js.map +1 -1
- package/dist/core/granularity.js +1 -1
- package/dist/core/options.d.ts +168 -8
- package/dist/core/options.js +132 -4
- package/dist/core/options.js.map +1 -1
- package/dist/core/registry.d.ts +1 -0
- package/dist/core/scopeList.js +32 -0
- package/dist/core/scopeList.js.map +1 -0
- package/dist/core/scopedRead.js +101 -29
- package/dist/core/scopedRead.js.map +1 -1
- package/dist/core/serverEvent.d.ts +60 -0
- package/dist/core/serverEvent.js +12 -0
- package/dist/core/serverEvent.js.map +1 -0
- package/dist/exports/adapters/ga4.d.ts +2 -1
- package/dist/exports/adapters/ga4.js +2 -1
- package/dist/exports/adapters/native.d.ts +3 -1
- package/dist/exports/adapters/native.js +2 -1
- package/dist/exports/client.d.ts +16 -2
- package/dist/exports/client.js +13 -1
- package/dist/exports/geo.d.ts +2 -2
- package/dist/exports/next.d.ts +2 -1
- package/dist/exports/next.js +2 -1
- package/dist/exports/react.d.ts +4 -0
- package/dist/exports/react.js +5 -0
- package/dist/exports/rsc.d.ts +12 -4
- package/dist/exports/rsc.js +7 -2
- package/dist/exports/tracker.d.ts +21 -0
- package/dist/exports/tracker.js +15 -0
- package/dist/exports/types.d.ts +17 -3
- package/dist/exports/types.js +4 -2
- package/dist/fields/AnalyticsPanelClient.js +2 -2
- package/dist/fields/AnalyticsPanelField.js +1 -1
- package/dist/fields/AnalyticsStatField.js +2 -2
- package/dist/fields/config/FilterDimensionSelectField.d.ts +14 -0
- package/dist/fields/config/FilterDimensionSelectField.js +77 -0
- package/dist/fields/config/FilterDimensionSelectField.js.map +1 -0
- package/dist/fields/config/FilterOperatorSelectField.d.ts +14 -0
- package/dist/fields/config/FilterOperatorSelectField.js +75 -0
- package/dist/fields/config/FilterOperatorSelectField.js.map +1 -0
- package/dist/fields/config/MetricSelectField.d.ts +23 -0
- package/dist/fields/config/MetricSelectField.js +51 -0
- package/dist/fields/config/MetricSelectField.js.map +1 -0
- package/dist/fields/config/SourceSelectField.d.ts +14 -0
- package/dist/fields/config/SourceSelectField.js +46 -0
- package/dist/fields/config/SourceSelectField.js.map +1 -0
- package/dist/fields/config/fetchSources.d.ts +16 -0
- package/dist/fields/config/fetchSources.js +33 -0
- package/dist/fields/config/fetchSources.js.map +1 -0
- package/dist/fields/config/narrow.js +32 -0
- package/dist/fields/config/narrow.js.map +1 -0
- package/dist/fields/config/sourcesState.js +27 -0
- package/dist/fields/config/sourcesState.js.map +1 -0
- package/dist/fields/config/toSelectOption.js +27 -0
- package/dist/fields/config/toSelectOption.js.map +1 -0
- package/dist/fields/config/useAnalyticsSources.d.ts +24 -0
- package/dist/fields/config/useAnalyticsSources.js +62 -0
- package/dist/fields/config/useAnalyticsSources.js.map +1 -0
- package/dist/fields/config/useFilterCapabilities.d.ts +28 -0
- package/dist/fields/config/useFilterCapabilities.js +52 -0
- package/dist/fields/config/useFilterCapabilities.js.map +1 -0
- package/dist/fields/readForDocument.d.ts +5 -0
- package/dist/fields/readForDocument.js +22 -10
- package/dist/fields/readForDocument.js.map +1 -1
- package/dist/goals/GoalSelectField.d.ts +7 -0
- package/dist/goals/GoalSelectField.js +77 -0
- package/dist/goals/GoalSelectField.js.map +1 -0
- package/dist/goals/collection.js +254 -0
- package/dist/goals/collection.js.map +1 -0
- package/dist/goals/currency.js +14 -0
- package/dist/goals/currency.js.map +1 -0
- package/dist/goals/fetchGoals.d.ts +18 -0
- package/dist/goals/fetchGoals.js +33 -0
- package/dist/goals/fetchGoals.js.map +1 -0
- package/dist/goals/goalField.d.ts +31 -0
- package/dist/goals/goalField.js +56 -0
- package/dist/goals/goalField.js.map +1 -0
- package/dist/goals/goalsEndpoint.d.ts +1 -0
- package/dist/goals/goalsEndpoint.js +58 -0
- package/dist/goals/goalsEndpoint.js.map +1 -0
- package/dist/goals/match.js +64 -0
- package/dist/goals/match.js.map +1 -0
- package/dist/goals/resolver.d.ts +8 -0
- package/dist/goals/resolver.js +147 -0
- package/dist/goals/resolver.js.map +1 -0
- package/dist/goals/trackGoalAction.d.ts +76 -0
- package/dist/goals/trackGoalAction.js +158 -0
- package/dist/goals/trackGoalAction.js.map +1 -0
- package/dist/goals/types.d.ts +33 -0
- package/dist/goals/types.js +7 -0
- package/dist/goals/types.js.map +1 -0
- package/dist/goals/useAnalyticsGoals.d.ts +20 -0
- package/dist/goals/useAnalyticsGoals.js +67 -0
- package/dist/goals/useAnalyticsGoals.js.map +1 -0
- package/dist/index.d.ts +14 -3
- package/dist/index.js +185 -19
- package/dist/index.js.map +1 -1
- package/dist/native/collections/events.js +65 -1
- package/dist/native/collections/events.js.map +1 -1
- package/dist/native/collections/rollups.js +39 -3
- package/dist/native/collections/rollups.js.map +1 -1
- package/dist/native/eventScan.js +25 -0
- package/dist/native/eventScan.js.map +1 -0
- package/dist/native/geo/composeGeoResolvers.js +2 -2
- package/dist/native/geo/composeGeoResolvers.js.map +1 -1
- package/dist/native/geo/geoResolver.d.ts +9 -2
- package/dist/native/geo/geoResolver.js.map +1 -1
- package/dist/native/geo/maxmindResolver.js +3 -5
- package/dist/native/geo/maxmindResolver.js.map +1 -1
- package/dist/native/ingest/bots.d.ts +11 -0
- package/dist/native/ingest/bots.js +71 -0
- package/dist/native/ingest/bots.js.map +1 -0
- package/dist/native/ingest/browser.js +47 -0
- package/dist/native/ingest/browser.js.map +1 -0
- package/dist/native/ingest/clientIp.js +20 -0
- package/dist/native/ingest/clientIp.js.map +1 -0
- package/dist/native/ingest/device.js +11 -3
- package/dist/native/ingest/device.js.map +1 -1
- package/dist/native/ingest/endpoint.d.ts +1 -0
- package/dist/native/ingest/endpoint.js +107 -21
- package/dist/native/ingest/endpoint.js.map +1 -1
- package/dist/native/ingest/flushBatch.js +29 -38
- package/dist/native/ingest/flushBatch.js.map +1 -1
- package/dist/native/ingest/language.js +14 -0
- package/dist/native/ingest/language.js.map +1 -0
- package/dist/native/ingest/normalizeEvent.d.ts +30 -0
- package/dist/native/ingest/normalizeEvent.js +115 -16
- package/dist/native/ingest/normalizeEvent.js.map +1 -1
- package/dist/native/ingest/referrer.js +48 -0
- package/dist/native/ingest/referrer.js.map +1 -0
- package/dist/native/ingest/requestHost.js +57 -0
- package/dist/native/ingest/requestHost.js.map +1 -0
- package/dist/native/ingest/resolveHostname.d.ts +29 -0
- package/dist/native/ingest/resolveHostname.js +52 -0
- package/dist/native/ingest/resolveHostname.js.map +1 -0
- package/dist/native/ingest/salt.js +27 -2
- package/dist/native/ingest/salt.js.map +1 -1
- package/dist/native/ingest/serverTrack.d.ts +20 -0
- package/dist/native/ingest/serverTrack.js +109 -0
- package/dist/native/ingest/serverTrack.js.map +1 -0
- package/dist/native/ingest/source.d.ts +11 -0
- package/dist/native/ingest/source.js +264 -16
- package/dist/native/ingest/source.js.map +1 -1
- package/dist/native/ingest/utm.js +33 -0
- package/dist/native/ingest/utm.js.map +1 -0
- package/dist/native/ingest/validate.js +26 -0
- package/dist/native/ingest/validate.js.map +1 -0
- package/dist/native/nativeAdapter.d.ts +37 -1
- package/dist/native/nativeAdapter.js +175 -22
- package/dist/native/nativeAdapter.js.map +1 -1
- package/dist/native/query/eventAgg.js +175 -0
- package/dist/native/query/eventAgg.js.map +1 -0
- package/dist/native/retention/pruneTask.js +53 -13
- package/dist/native/retention/pruneTask.js.map +1 -1
- package/dist/native/rollupAcc.js +12 -1
- package/dist/native/rollupAcc.js.map +1 -1
- package/dist/native/rollups/bucketKey.js +15 -0
- package/dist/native/rollups/bucketKey.js.map +1 -0
- package/dist/native/rollups/bumpRollups.js +116 -0
- package/dist/native/rollups/bumpRollups.js.map +1 -0
- package/dist/native/rollups/deltas.js +86 -11
- package/dist/native/rollups/deltas.js.map +1 -1
- package/dist/native/rollups/insertManyIfNew.js +93 -0
- package/dist/native/rollups/insertManyIfNew.js.map +1 -0
- package/dist/next/captureRewrites.d.ts +42 -0
- package/dist/next/captureRewrites.js +57 -0
- package/dist/next/captureRewrites.js.map +1 -0
- package/dist/next/posthogProxyRewrites.d.ts +5 -0
- package/dist/next/posthogProxyRewrites.js +16 -21
- package/dist/next/posthogProxyRewrites.js.map +1 -1
- package/dist/plugin/documentEndpoint.js +71 -24
- package/dist/plugin/documentEndpoint.js.map +1 -1
- package/dist/plugin/errors.d.ts +31 -0
- package/dist/plugin/errors.js +79 -0
- package/dist/plugin/errors.js.map +1 -0
- package/dist/plugin/goalHint.d.ts +1 -0
- package/dist/plugin/goalHint.js +24 -0
- package/dist/plugin/goalHint.js.map +1 -0
- package/dist/plugin/paths.js +19 -1
- package/dist/plugin/paths.js.map +1 -1
- package/dist/plugin/queryEndpoint.js +124 -0
- package/dist/plugin/queryEndpoint.js.map +1 -0
- package/dist/plugin/readContextForRequest.js +73 -0
- package/dist/plugin/readContextForRequest.js.map +1 -0
- package/dist/plugin/realtimeEndpoint.js +39 -18
- package/dist/plugin/realtimeEndpoint.js.map +1 -1
- package/dist/plugin/refreshEndpoint.js +113 -0
- package/dist/plugin/refreshEndpoint.js.map +1 -0
- package/dist/plugin/runtime.d.ts +1 -0
- package/dist/plugin/runtime.js +33 -1
- package/dist/plugin/runtime.js.map +1 -1
- package/dist/plugin/scopeChange.js +22 -0
- package/dist/plugin/scopeChange.js.map +1 -0
- package/dist/plugin/scopeFieldBoot.js +22 -0
- package/dist/plugin/scopeFieldBoot.js.map +1 -0
- package/dist/plugin/sourcesEndpoint.js +28 -0
- package/dist/plugin/sourcesEndpoint.js.map +1 -0
- package/dist/plugin/warmTask.js +0 -0
- package/dist/plugin/warmTask.js.map +1 -1
- package/dist/providers/access.js +2 -1
- package/dist/providers/access.js.map +1 -1
- package/dist/providers/collection.js +90 -29
- package/dist/providers/collection.js.map +1 -1
- package/dist/providers/factory.js +11 -3
- package/dist/providers/factory.js.map +1 -1
- package/dist/providers/resolver.js.map +1 -1
- package/dist/query/dates.js +64 -0
- package/dist/query/dates.js.map +1 -0
- package/dist/query/errors.d.ts +14 -0
- package/dist/query/fetchQuery.d.ts +79 -0
- package/dist/query/fetchQuery.js +117 -0
- package/dist/query/fetchQuery.js.map +1 -0
- package/dist/query/parse.d.ts +22 -0
- package/dist/query/parse.js +168 -0
- package/dist/query/parse.js.map +1 -0
- package/dist/query/response.d.ts +39 -0
- package/dist/query/response.js +11 -0
- package/dist/query/response.js.map +1 -0
- package/dist/react/AnalyticsProvider.d.ts +50 -0
- package/dist/react/AnalyticsProvider.js +67 -0
- package/dist/react/AnalyticsProvider.js.map +1 -0
- package/dist/react/TrackerBoot.d.ts +22 -0
- package/dist/react/TrackerBoot.js +30 -0
- package/dist/react/TrackerBoot.js.map +1 -0
- package/dist/react/useAnalytics.d.ts +20 -0
- package/dist/react/useAnalytics.js +52 -0
- package/dist/react/useAnalytics.js.map +1 -0
- package/dist/rsc/AnalyticsScripts.d.ts +30 -0
- package/dist/rsc/AnalyticsScripts.js +41 -0
- package/dist/rsc/AnalyticsScripts.js.map +1 -0
- package/dist/surfacing/cacheStore.d.ts +1 -0
- package/dist/surfacing/cacheStore.js +18 -2
- package/dist/surfacing/cacheStore.js.map +1 -1
- package/dist/surfacing/engine.d.ts +1 -0
- package/dist/surfacing/engine.js +47 -6
- package/dist/surfacing/engine.js.map +1 -1
- package/dist/surfacing/epoch.d.ts +1 -0
- package/dist/surfacing/epoch.js +72 -0
- package/dist/surfacing/epoch.js.map +1 -0
- package/dist/surfacing/queue.js +22 -6
- package/dist/surfacing/queue.js.map +1 -1
- package/dist/surfacing/rateLimiter.js +130 -0
- package/dist/surfacing/rateLimiter.js.map +1 -0
- package/dist/surfacing/retryPolicy.js +15 -0
- package/dist/surfacing/retryPolicy.js.map +1 -0
- package/dist/sync/collection.js +23 -7
- package/dist/sync/collection.js.map +1 -1
- package/dist/sync/syncTask.js +68 -33
- package/dist/sync/syncTask.js.map +1 -1
- package/dist/testing/memoryAdapter.d.ts +2 -0
- package/dist/testing/memoryAdapter.js +17 -1
- package/dist/testing/memoryAdapter.js.map +1 -1
- package/dist/timeframe/tz.js +17 -6
- package/dist/timeframe/tz.js.map +1 -1
- package/dist/tracker/autoCapture.d.ts +48 -0
- package/dist/tracker/autoCapture.js +129 -0
- package/dist/tracker/autoCapture.js.map +1 -0
- package/dist/tracker/consent.d.ts +24 -0
- package/dist/tracker/consent.js +48 -0
- package/dist/tracker/consent.js.map +1 -0
- package/dist/tracker/createTracker.d.ts +18 -0
- package/dist/tracker/createTracker.js +215 -0
- package/dist/tracker/createTracker.js.map +1 -0
- package/dist/tracker/exclusion.d.ts +28 -0
- package/dist/tracker/exclusion.js +50 -0
- package/dist/tracker/exclusion.js.map +1 -0
- package/dist/tracker/initTracker.d.ts +22 -0
- package/dist/tracker/initTracker.js +33 -0
- package/dist/tracker/initTracker.js.map +1 -0
- package/dist/tracker/loadScript.d.ts +14 -0
- package/dist/tracker/loadScript.js +41 -0
- package/dist/tracker/loadScript.js.map +1 -0
- package/dist/tracker/pageTracking.d.ts +17 -0
- package/dist/tracker/pageTracking.js +38 -0
- package/dist/tracker/pageTracking.js.map +1 -0
- package/dist/tracker/registry.d.ts +27 -0
- package/dist/tracker/registry.js +73 -0
- package/dist/tracker/registry.js.map +1 -0
- package/dist/tracker/sinks/ga4.d.ts +29 -0
- package/dist/tracker/sinks/ga4.js +30 -0
- package/dist/tracker/sinks/ga4.js.map +1 -0
- package/dist/tracker/sinks/native.d.ts +22 -0
- package/dist/tracker/sinks/native.js +56 -0
- package/dist/tracker/sinks/native.js.map +1 -0
- package/dist/tracker/sinks/plausible.d.ts +20 -0
- package/dist/tracker/sinks/plausible.js +32 -0
- package/dist/tracker/sinks/plausible.js.map +1 -0
- package/dist/tracker/sinks/posthog.d.ts +18 -0
- package/dist/tracker/sinks/posthog.js +30 -0
- package/dist/tracker/sinks/posthog.js.map +1 -0
- package/dist/tracker/sinks/umami.d.ts +18 -0
- package/dist/tracker/sinks/umami.js +23 -0
- package/dist/tracker/sinks/umami.js.map +1 -0
- package/dist/tracker/sinks/vendor.d.ts +14 -0
- package/dist/tracker/sinks/vendor.js +81 -0
- package/dist/tracker/sinks/vendor.js.map +1 -0
- package/dist/tracker/transport.js +28 -0
- package/dist/tracker/transport.js.map +1 -0
- package/dist/tracker/types.d.ts +91 -0
- package/dist/translations/ar.js +221 -0
- package/dist/translations/ar.js.map +1 -0
- package/dist/translations/de.js +145 -1
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +145 -1
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.js +221 -0
- package/dist/translations/es.js.map +1 -0
- package/dist/translations/fr.js +221 -0
- package/dist/translations/fr.js.map +1 -0
- package/dist/translations/id.js +221 -0
- package/dist/translations/id.js.map +1 -0
- package/dist/translations/index.d.ts +10 -1
- package/dist/translations/index.js +19 -1
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/keys.d.ts +144 -0
- package/dist/translations/keys.js +145 -1
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.js +221 -0
- package/dist/translations/ko.js.map +1 -0
- package/dist/translations/metricKeys.js +8 -2
- package/dist/translations/metricKeys.js.map +1 -1
- package/dist/translations/pt.js +221 -0
- package/dist/translations/pt.js.map +1 -0
- package/dist/translations/ru.js +221 -0
- package/dist/translations/ru.js.map +1 -0
- package/dist/translations/server.js.map +1 -1
- package/dist/translations/uk.js +221 -0
- package/dist/translations/uk.js.map +1 -0
- package/dist/translations/zh.js +221 -0
- package/dist/translations/zh.js.map +1 -0
- package/dist/view/AnalyticsNavLink.d.ts +19 -0
- package/dist/view/AnalyticsNavLink.js +40 -0
- package/dist/view/AnalyticsNavLink.js.map +1 -0
- package/dist/view/AnalyticsView.d.ts +23 -0
- package/dist/view/AnalyticsView.js +45 -0
- package/dist/view/AnalyticsView.js.map +1 -0
- package/dist/view/AnalyticsViewClient.d.ts +15 -0
- package/dist/view/AnalyticsViewClient.js +244 -0
- package/dist/view/AnalyticsViewClient.js.map +1 -0
- package/dist/view/authRedirect.js +32 -0
- package/dist/view/authRedirect.js.map +1 -0
- package/dist/view/conversionRate.js +18 -0
- package/dist/view/conversionRate.js.map +1 -0
- package/dist/view/dayRange.js +68 -0
- package/dist/view/dayRange.js.map +1 -0
- package/dist/view/gating.d.ts +1 -0
- package/dist/view/gating.js +142 -0
- package/dist/view/gating.js.map +1 -0
- package/dist/view/labels.js +76 -0
- package/dist/view/labels.js.map +1 -0
- package/dist/view/registerView.js +48 -0
- package/dist/view/registerView.js.map +1 -0
- package/dist/view/sections/Breakdowns.js +198 -0
- package/dist/view/sections/Breakdowns.js.map +1 -0
- package/dist/view/sections/EmptyStates.js +92 -0
- package/dist/view/sections/EmptyStates.js.map +1 -0
- package/dist/view/sections/FilterChips.js +46 -0
- package/dist/view/sections/FilterChips.js.map +1 -0
- package/dist/view/sections/GoalsPanel.js +82 -0
- package/dist/view/sections/GoalsPanel.js.map +1 -0
- package/dist/view/sections/OverviewCards.js +65 -0
- package/dist/view/sections/OverviewCards.js.map +1 -0
- package/dist/view/sections/RealtimeStrip.js +80 -0
- package/dist/view/sections/RealtimeStrip.js.map +1 -0
- package/dist/view/sections/Toolbar.js +207 -0
- package/dist/view/sections/Toolbar.js.map +1 -0
- package/dist/view/sections/Trend.js +125 -0
- package/dist/view/sections/Trend.js.map +1 -0
- package/dist/view/sections/styles.js +76 -0
- package/dist/view/sections/styles.js.map +1 -0
- package/dist/view/state.js +211 -0
- package/dist/view/state.js.map +1 -0
- package/dist/view/useViewQueries.js +153 -0
- package/dist/view/useViewQueries.js.map +1 -0
- package/dist/view/viewProps.d.ts +40 -0
- package/dist/view/viewProps.js +90 -0
- package/dist/view/viewProps.js.map +1 -0
- package/dist/widgets/AnalyticsBreakdownWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsBreakdownWidget.js +78 -11
- package/dist/widgets/AnalyticsBreakdownWidget.js.map +1 -1
- package/dist/widgets/AnalyticsGoalsWidget.d.ts +14 -0
- package/dist/widgets/AnalyticsGoalsWidget.js +196 -0
- package/dist/widgets/AnalyticsGoalsWidget.js.map +1 -0
- package/dist/widgets/AnalyticsMetricWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsMetricWidget.js +63 -13
- package/dist/widgets/AnalyticsMetricWidget.js.map +1 -1
- package/dist/widgets/AnalyticsRealtimeWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsRealtimeWidget.js +45 -23
- package/dist/widgets/AnalyticsRealtimeWidget.js.map +1 -1
- package/dist/widgets/AnalyticsTrendWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsTrendWidget.js +79 -16
- package/dist/widgets/AnalyticsTrendWidget.js.map +1 -1
- package/dist/widgets/RealtimeCounter.d.ts +4 -0
- package/dist/widgets/RealtimeCounter.js +18 -4
- package/dist/widgets/RealtimeCounter.js.map +1 -1
- package/dist/widgets/WidgetViewLink.js +17 -0
- package/dist/widgets/WidgetViewLink.js.map +1 -0
- package/dist/widgets/breakdownTypes.js +38 -0
- package/dist/widgets/breakdownTypes.js.map +1 -1
- package/dist/widgets/cardChrome.js +31 -7
- package/dist/widgets/cardChrome.js.map +1 -1
- package/dist/widgets/comparison.js +15 -1
- package/dist/widgets/comparison.js.map +1 -1
- package/dist/widgets/defaults.d.ts +6 -2
- package/dist/widgets/defaults.js +78 -23
- package/dist/widgets/defaults.js.map +1 -1
- package/dist/widgets/filterCaption.js +27 -0
- package/dist/widgets/filterCaption.js.map +1 -0
- package/dist/widgets/filterField.d.ts +19 -0
- package/dist/widgets/filterField.js +75 -0
- package/dist/widgets/filterField.js.map +1 -0
- package/dist/widgets/prepareWidgetRead.d.ts +7 -0
- package/dist/widgets/prepareWidgetRead.js +74 -0
- package/dist/widgets/prepareWidgetRead.js.map +1 -0
- package/dist/widgets/range.js +43 -12
- package/dist/widgets/range.js.map +1 -1
- package/dist/widgets/readForWidget.d.ts +26 -3
- package/dist/widgets/readForWidget.js +48 -44
- package/dist/widgets/readForWidget.js.map +1 -1
- package/dist/widgets/readForWidgetBreakdown.d.ts +34 -2
- package/dist/widgets/readForWidgetBreakdown.js +53 -49
- package/dist/widgets/readForWidgetBreakdown.js.map +1 -1
- package/dist/widgets/readForWidgetGoals.d.ts +67 -0
- package/dist/widgets/readForWidgetGoals.js +140 -0
- package/dist/widgets/readForWidgetGoals.js.map +1 -0
- package/dist/widgets/readForWidgetRealtime.d.ts +8 -0
- package/dist/widgets/readForWidgetRealtime.js +23 -21
- package/dist/widgets/readForWidgetRealtime.js.map +1 -1
- package/dist/widgets/readForWidgetSeries.d.ts +26 -2
- package/dist/widgets/readForWidgetSeries.js +78 -53
- package/dist/widgets/readForWidgetSeries.js.map +1 -1
- package/dist/widgets/readMeta.js +18 -0
- package/dist/widgets/readMeta.js.map +1 -0
- package/dist/widgets/realtimePoll.js +16 -1
- package/dist/widgets/realtimePoll.js.map +1 -1
- package/dist/widgets/registerWidgets.js +76 -14
- package/dist/widgets/registerWidgets.js.map +1 -1
- package/dist/widgets/types.d.ts +15 -0
- package/dist/widgets/types.js +16 -2
- package/dist/widgets/types.js.map +1 -1
- package/dist/widgets/viewLink.d.ts +22 -0
- package/dist/widgets/viewLink.js +86 -0
- package/dist/widgets/viewLink.js.map +1 -0
- package/package.json +27 -7
- package/dist/native/rollups/applyDistinctDeltas.js +0 -9
- package/dist/native/rollups/applyDistinctDeltas.js.map +0 -1
- package/dist/native/rollups/bumpRollup.js +0 -68
- package/dist/native/rollups/bumpRollup.js.map +0 -1
- package/dist/native/rollups/insertIfNew.js +0 -19
- package/dist/native/rollups/insertIfNew.js.map +0 -1
|
@@ -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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CapabilityRequirement } from "../../core/capabilities.js";
|
|
2
|
+
import { SelectFieldClientProps } from "payload";
|
|
3
|
+
|
|
4
|
+
//#region src/fields/config/MetricSelectField.d.ts
|
|
5
|
+
type MetricSelectFieldProps = SelectFieldClientProps & {
|
|
6
|
+
/** Extra capability requirement (beyond the picked metric) a widget's other config imposes, e.g. a breakdown dimension. */requires?: Omit<CapabilityRequirement, 'metrics'>;
|
|
7
|
+
/**
|
|
8
|
+
* Path of the sibling source select this picker narrows against, for
|
|
9
|
+
* custom widgets whose source field is named differently. Defaults to
|
|
10
|
+
* `'dataSource'`.
|
|
11
|
+
*/
|
|
12
|
+
sourceFieldPath?: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Metric picker for scoped widget config: narrows the static option list to
|
|
16
|
+
* what the sibling source field's selected source can actually serve, once
|
|
17
|
+
* the sources endpoint answers. Never clears an already-picked value that
|
|
18
|
+
* narrowing filters out; the read path degrades that case on its own.
|
|
19
|
+
*/
|
|
20
|
+
declare const MetricSelectField: (props: MetricSelectFieldProps) => import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { MetricSelectField, MetricSelectFieldProps };
|
|
23
|
+
//# sourceMappingURL=MetricSelectField.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useTranslation as useTranslation$1 } from "../../translations/useTranslation.js";
|
|
3
|
+
import { useAnalyticsSources } from "./useAnalyticsSources.js";
|
|
4
|
+
import { narrowMetricOptions } from "./narrow.js";
|
|
5
|
+
import { toSelectOption } from "./toSelectOption.js";
|
|
6
|
+
import { useMemo } from "react";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
import { SelectInput, useField, useFormFields } from "@payloadcms/ui";
|
|
9
|
+
//#region src/fields/config/MetricSelectField.tsx
|
|
10
|
+
/**
|
|
11
|
+
* Metric picker for scoped widget config: narrows the static option list to
|
|
12
|
+
* what the sibling source field's selected source can actually serve, once
|
|
13
|
+
* the sources endpoint answers. Never clears an already-picked value that
|
|
14
|
+
* narrowing filters out; the read path degrades that case on its own.
|
|
15
|
+
*/
|
|
16
|
+
const MetricSelectField = (props) => {
|
|
17
|
+
const { field, path: pathFromProps, readOnly, requires, sourceFieldPath = "dataSource" } = props;
|
|
18
|
+
const { i18n } = useTranslation$1();
|
|
19
|
+
const locale = i18n.language;
|
|
20
|
+
const { path, setValue, showError, value } = useField({ potentiallyStalePath: pathFromProps });
|
|
21
|
+
const { sources } = useAnalyticsSources();
|
|
22
|
+
const sourceId = useFormFields(([fields]) => fields?.[sourceFieldPath]?.value);
|
|
23
|
+
const options = narrowMetricOptions({
|
|
24
|
+
options: useMemo(() => field.options.map((option) => toSelectOption(option, locale)), [field.options, locale]),
|
|
25
|
+
requires,
|
|
26
|
+
sourceId,
|
|
27
|
+
sources: sources ?? []
|
|
28
|
+
}).map((option) => ({
|
|
29
|
+
label: option.label,
|
|
30
|
+
value: option.value
|
|
31
|
+
}));
|
|
32
|
+
return /* @__PURE__ */ jsx(SelectInput, {
|
|
33
|
+
isClearable: false,
|
|
34
|
+
label: field.label,
|
|
35
|
+
name: field.name,
|
|
36
|
+
onChange: (selected) => {
|
|
37
|
+
const option = Array.isArray(selected) ? selected[0] : selected;
|
|
38
|
+
setValue(option ? String(option.value) : null);
|
|
39
|
+
},
|
|
40
|
+
options,
|
|
41
|
+
path,
|
|
42
|
+
readOnly,
|
|
43
|
+
required: field.required,
|
|
44
|
+
showError,
|
|
45
|
+
value
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { MetricSelectField };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=MetricSelectField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetricSelectField.js","names":["useTranslation"],"sources":["../../../src/fields/config/MetricSelectField.tsx"],"sourcesContent":["'use client'\n\nimport { type ReactSelectOption, SelectInput, useField, useFormFields } from '@payloadcms/ui'\nimport type { SelectFieldClientProps } from 'payload'\nimport { useMemo } from 'react'\nimport type { CapabilityRequirement } from '../../core/capabilities'\nimport { useTranslation } from '../../translations/useTranslation'\nimport { narrowMetricOptions } from './narrow'\nimport { toSelectOption } from './toSelectOption'\nimport { useAnalyticsSources } from './useAnalyticsSources'\n\nexport type MetricSelectFieldProps = SelectFieldClientProps & {\n\t/** Extra capability requirement (beyond the picked metric) a widget's other config imposes, e.g. a breakdown dimension. */\n\trequires?: Omit<CapabilityRequirement, 'metrics'>\n\t/**\n\t * Path of the sibling source select this picker narrows against, for\n\t * custom widgets whose source field is named differently. Defaults to\n\t * `'dataSource'`.\n\t */\n\tsourceFieldPath?: string\n}\n\n/**\n * Metric picker for scoped widget config: narrows the static option list to\n * what the sibling source field's selected source can actually serve, once\n * the sources endpoint answers. Never clears an already-picked value that\n * narrowing filters out; the read path degrades that case on its own.\n */\nexport const MetricSelectField = (props: MetricSelectFieldProps) => {\n\tconst { field, path: pathFromProps, readOnly, requires, sourceFieldPath = 'dataSource' } = props\n\tconst { i18n } = useTranslation()\n\tconst locale = i18n.language\n\tconst { path, setValue, showError, value } = useField<string>({\n\t\tpotentiallyStalePath: pathFromProps,\n\t})\n\tconst { sources } = useAnalyticsSources()\n\tconst sourceId = useFormFields(\n\t\t([fields]) => fields?.[sourceFieldPath]?.value as string | undefined\n\t)\n\n\tconst staticOptions = useMemo(\n\t\t() => field.options.map((option) => toSelectOption(option, locale)),\n\t\t[field.options, locale]\n\t)\n\n\tconst options = narrowMetricOptions({\n\t\toptions: staticOptions,\n\t\trequires,\n\t\tsourceId,\n\t\tsources: sources ?? [],\n\t}).map((option) => ({ label: option.label as string, value: option.value }))\n\n\treturn (\n\t\t<SelectInput\n\t\t\tisClearable={false}\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 ? String(option.value) : null)\n\t\t\t}}\n\t\t\toptions={options}\n\t\t\tpath={path}\n\t\t\treadOnly={readOnly}\n\t\t\trequired={field.required}\n\t\t\tshowError={showError}\n\t\t\tvalue={value}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,MAAa,qBAAqB,UAAkC;CACnE,MAAM,EAAE,OAAO,MAAM,eAAe,UAAU,UAAU,kBAAkB,iBAAiB;CAC3F,MAAM,EAAE,SAASA,iBAAe;CAChC,MAAM,SAAS,KAAK;CACpB,MAAM,EAAE,MAAM,UAAU,WAAW,UAAU,SAAiB,EAC7D,sBAAsB,cACvB,CAAC;CACD,MAAM,EAAE,YAAY,oBAAoB;CACxC,MAAM,WAAW,eACf,CAAC,YAAY,SAAS,kBAAkB,KAC1C;CAOA,MAAM,UAAU,oBAAoB;EACnC,SANqB,cACf,MAAM,QAAQ,KAAK,WAAW,eAAe,QAAQ,MAAM,CAAC,GAClE,CAAC,MAAM,SAAS,MAAM,CAID;EACrB;EACA;EACA,SAAS,WAAW,CAAC;CACtB,CAAC,EAAE,KAAK,YAAY;EAAE,OAAO,OAAO;EAAiB,OAAO,OAAO;CAAM,EAAE;CAE3E,OACC,oBAAC,aAAD;EACC,aAAa;EACb,OAAO,MAAM;EACb,MAAM,MAAM;EACZ,WAAW,aAAsD;GAChE,MAAM,SAAS,MAAM,QAAQ,QAAQ,IAAI,SAAS,KAAK;GACvD,SAAS,SAAS,OAAO,OAAO,KAAK,IAAI,IAAI;EAC9C;EACS;EACH;EACI;EACV,UAAU,MAAM;EACL;EACJ;CACP,CAAA;AAEH"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SelectFieldClientProps } from "payload";
|
|
2
|
+
|
|
3
|
+
//#region src/fields/config/SourceSelectField.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Source picker for scoped widget config: starts from the field's static
|
|
6
|
+
* option list and, once the caller-scope sources endpoint answers, replaces
|
|
7
|
+
* it with the live adapter list so a tenant only ever sees sources it can
|
|
8
|
+
* actually read from. A failed fetch keeps the static list rather than
|
|
9
|
+
* emptying the picker.
|
|
10
|
+
*/
|
|
11
|
+
declare const SourceSelectField: (props: SelectFieldClientProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { SourceSelectField };
|
|
14
|
+
//# sourceMappingURL=SourceSelectField.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useTranslation as useTranslation$1 } from "../../translations/useTranslation.js";
|
|
3
|
+
import { useAnalyticsSources } from "./useAnalyticsSources.js";
|
|
4
|
+
import { toSelectOption } from "./toSelectOption.js";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { SelectInput, useField } from "@payloadcms/ui";
|
|
8
|
+
//#region src/fields/config/SourceSelectField.tsx
|
|
9
|
+
/**
|
|
10
|
+
* Source picker for scoped widget config: starts from the field's static
|
|
11
|
+
* option list and, once the caller-scope sources endpoint answers, replaces
|
|
12
|
+
* it with the live adapter list so a tenant only ever sees sources it can
|
|
13
|
+
* actually read from. A failed fetch keeps the static list rather than
|
|
14
|
+
* emptying the picker.
|
|
15
|
+
*/
|
|
16
|
+
const SourceSelectField = (props) => {
|
|
17
|
+
const { field, path: pathFromProps, readOnly } = props;
|
|
18
|
+
const { i18n } = useTranslation$1();
|
|
19
|
+
const locale = i18n.language;
|
|
20
|
+
const { path, setValue, showError, value } = useField({ potentiallyStalePath: pathFromProps });
|
|
21
|
+
const { sources } = useAnalyticsSources();
|
|
22
|
+
const staticOptions = useMemo(() => field.options.map((option) => toSelectOption(option, locale)), [field.options, locale]);
|
|
23
|
+
const options = sources && sources.length > 0 ? sources.map((source) => ({
|
|
24
|
+
value: source.id,
|
|
25
|
+
label: source.label
|
|
26
|
+
})) : staticOptions;
|
|
27
|
+
return /* @__PURE__ */ jsx(SelectInput, {
|
|
28
|
+
isClearable: false,
|
|
29
|
+
label: field.label,
|
|
30
|
+
name: field.name,
|
|
31
|
+
onChange: (selected) => {
|
|
32
|
+
const option = Array.isArray(selected) ? selected[0] : selected;
|
|
33
|
+
setValue(option ? String(option.value) : null);
|
|
34
|
+
},
|
|
35
|
+
options,
|
|
36
|
+
path,
|
|
37
|
+
readOnly,
|
|
38
|
+
required: field.required,
|
|
39
|
+
showError,
|
|
40
|
+
value
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { SourceSelectField };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=SourceSelectField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SourceSelectField.js","names":["useTranslation"],"sources":["../../../src/fields/config/SourceSelectField.tsx"],"sourcesContent":["'use client'\n\nimport { type ReactSelectOption, SelectInput, useField } from '@payloadcms/ui'\nimport type { SelectFieldClientProps } from 'payload'\nimport { useMemo } from 'react'\nimport { useTranslation } from '../../translations/useTranslation'\nimport { toSelectOption } from './toSelectOption'\nimport { useAnalyticsSources } from './useAnalyticsSources'\n\n/**\n * Source picker for scoped widget config: starts from the field's static\n * option list and, once the caller-scope sources endpoint answers, replaces\n * it with the live adapter list so a tenant only ever sees sources it can\n * actually read from. A failed fetch keeps the static list rather than\n * emptying the picker.\n */\nexport const SourceSelectField = (props: SelectFieldClientProps) => {\n\tconst { field, path: pathFromProps, readOnly } = props\n\tconst { i18n } = useTranslation()\n\tconst locale = i18n.language\n\tconst { path, setValue, showError, value } = useField<string>({\n\t\tpotentiallyStalePath: pathFromProps,\n\t})\n\tconst { sources } = useAnalyticsSources()\n\n\tconst staticOptions = useMemo(\n\t\t() => field.options.map((option) => toSelectOption(option, locale)),\n\t\t[field.options, locale]\n\t)\n\n\tconst options =\n\t\tsources && sources.length > 0\n\t\t\t? sources.map((source) => ({ value: source.id, label: source.label }))\n\t\t\t: staticOptions\n\n\treturn (\n\t\t<SelectInput\n\t\t\tisClearable={false}\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 ? String(option.value) : null)\n\t\t\t}}\n\t\t\toptions={options}\n\t\t\tpath={path}\n\t\t\treadOnly={readOnly}\n\t\t\trequired={field.required}\n\t\t\tshowError={showError}\n\t\t\tvalue={value}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAa,qBAAqB,UAAkC;CACnE,MAAM,EAAE,OAAO,MAAM,eAAe,aAAa;CACjD,MAAM,EAAE,SAASA,iBAAe;CAChC,MAAM,SAAS,KAAK;CACpB,MAAM,EAAE,MAAM,UAAU,WAAW,UAAU,SAAiB,EAC7D,sBAAsB,cACvB,CAAC;CACD,MAAM,EAAE,YAAY,oBAAoB;CAExC,MAAM,gBAAgB,cACf,MAAM,QAAQ,KAAK,WAAW,eAAe,QAAQ,MAAM,CAAC,GAClE,CAAC,MAAM,SAAS,MAAM,CACvB;CAEA,MAAM,UACL,WAAW,QAAQ,SAAS,IACzB,QAAQ,KAAK,YAAY;EAAE,OAAO,OAAO;EAAI,OAAO,OAAO;CAAM,EAAE,IACnE;CAEJ,OACC,oBAAC,aAAD;EACC,aAAa;EACb,OAAO,MAAM;EACb,MAAM,MAAM;EACZ,WAAW,aAAsD;GAChE,MAAM,SAAS,MAAM,QAAQ,QAAQ,IAAI,SAAS,KAAK;GACvD,SAAS,SAAS,OAAO,OAAO,KAAK,IAAI,IAAI;EAC9C;EACS;EACH;EACI;EACV,UAAU,MAAM;EACL;EACJ;CACP,CAAA;AAEH"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SerializedCapabilities } from "../../core/capabilities.js";
|
|
2
|
+
|
|
3
|
+
//#region src/fields/config/fetchSources.d.ts
|
|
4
|
+
interface WireSource {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
kind: 'config' | 'runtime';
|
|
8
|
+
capabilities: SerializedCapabilities;
|
|
9
|
+
}
|
|
10
|
+
interface SourcesResponse {
|
|
11
|
+
defaultId: string | null;
|
|
12
|
+
sources: WireSource[];
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { SourcesResponse, WireSource };
|
|
16
|
+
//# sourceMappingURL=fetchSources.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SOURCES_PATH } from "../../plugin/paths.js";
|
|
2
|
+
import { readResponseError } from "../../plugin/errors.js";
|
|
3
|
+
//#region src/fields/config/fetchSources.ts
|
|
4
|
+
const cache = /* @__PURE__ */ new Map();
|
|
5
|
+
/**
|
|
6
|
+
* Fetch the caller-scope source list once per user per admin session and share
|
|
7
|
+
* it between every picker instance on the page; a failed fetch clears its cache
|
|
8
|
+
* entry so a later mount retries instead of pinning the error. Keying by user
|
|
9
|
+
* id keeps a soft-navigation logout/login from serving the previous user's
|
|
10
|
+
* cached sources.
|
|
11
|
+
*/
|
|
12
|
+
const fetchSources = (serverURL, apiRoute, userKey) => {
|
|
13
|
+
const url = `${serverURL}${apiRoute}${SOURCES_PATH}`;
|
|
14
|
+
const key = `${userKey}:${url}`;
|
|
15
|
+
const hit = cache.get(key);
|
|
16
|
+
if (hit) return hit;
|
|
17
|
+
const p = fetch(url, { credentials: "include" }).then(async (res) => {
|
|
18
|
+
if (!res.ok) {
|
|
19
|
+
const code = (await readResponseError(res))?.code;
|
|
20
|
+
throw new Error(`analytics: sources ${res.status}${code ? ` ${code}` : ""}`);
|
|
21
|
+
}
|
|
22
|
+
return await res.json();
|
|
23
|
+
}).catch((err) => {
|
|
24
|
+
cache.delete(key);
|
|
25
|
+
throw err;
|
|
26
|
+
});
|
|
27
|
+
cache.set(key, p);
|
|
28
|
+
return p;
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { fetchSources };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=fetchSources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchSources.js","names":[],"sources":["../../../src/fields/config/fetchSources.ts"],"sourcesContent":["import type { SerializedCapabilities } from '../../core/capabilities'\nimport { readResponseError } from '../../plugin/errors'\nimport { SOURCES_PATH } from '../../plugin/paths'\n\nexport interface WireSource {\n\tid: string\n\tlabel: string\n\tkind: 'config' | 'runtime'\n\tcapabilities: SerializedCapabilities\n}\n\nexport interface SourcesResponse {\n\tdefaultId: string | null\n\tsources: WireSource[]\n}\n\nconst cache = new Map<string, Promise<SourcesResponse>>()\n\n/**\n * Fetch the caller-scope source list once per user per admin session and share\n * it between every picker instance on the page; a failed fetch clears its cache\n * entry so a later mount retries instead of pinning the error. Keying by user\n * id keeps a soft-navigation logout/login from serving the previous user's\n * cached sources.\n */\nexport const fetchSources = (\n\tserverURL: string,\n\tapiRoute: string,\n\tuserKey: string\n): Promise<SourcesResponse> => {\n\tconst url = `${serverURL}${apiRoute}${SOURCES_PATH}`\n\tconst key = `${userKey}:${url}`\n\tconst hit = cache.get(key)\n\tif (hit) return hit\n\tconst p = fetch(url, { credentials: 'include' })\n\t\t.then(async (res) => {\n\t\t\tif (!res.ok) {\n\t\t\t\t// The picker shows one failed state either way, so the code rides in the message\n\t\t\t\t// rather than inventing a second: a denied listing and a down one read alike in\n\t\t\t\t// the console otherwise.\n\t\t\t\tconst code = (await readResponseError(res))?.code\n\t\t\t\tthrow new Error(`analytics: sources ${res.status}${code ? ` ${code}` : ''}`)\n\t\t\t}\n\t\t\treturn (await res.json()) as SourcesResponse\n\t\t})\n\t\t.catch((err) => {\n\t\t\tcache.delete(key)\n\t\t\tthrow err\n\t\t})\n\tcache.set(key, p)\n\treturn p\n}\n"],"mappings":";;;AAgBA,MAAM,wBAAQ,IAAI,IAAsC;;;;;;;;AASxD,MAAa,gBACZ,WACA,UACA,YAC8B;CAC9B,MAAM,MAAM,GAAG,YAAY,WAAW;CACtC,MAAM,MAAM,GAAG,QAAQ,GAAG;CAC1B,MAAM,MAAM,MAAM,IAAI,GAAG;CACzB,IAAI,KAAK,OAAO;CAChB,MAAM,IAAI,MAAM,KAAK,EAAE,aAAa,UAAU,CAAC,EAC7C,KAAK,OAAO,QAAQ;EACpB,IAAI,CAAC,IAAI,IAAI;GAIZ,MAAM,QAAQ,MAAM,kBAAkB,GAAG,IAAI;GAC7C,MAAM,IAAI,MAAM,sBAAsB,IAAI,SAAS,OAAO,IAAI,SAAS,IAAI;EAC5E;EACA,OAAQ,MAAM,IAAI,KAAK;CACxB,CAAC,EACA,OAAO,QAAQ;EACf,MAAM,OAAO,GAAG;EAChB,MAAM;CACP,CAAC;CACF,MAAM,IAAI,KAAK,CAAC;CAChB,OAAO;AACR"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/fields/config/narrow.ts
|
|
2
|
+
/** satisfiesCapabilities over the wire form (arrays instead of Sets). */
|
|
3
|
+
const satisfiesSerialized = (caps, req) => {
|
|
4
|
+
if (req.realtime && !caps.realtime) return false;
|
|
5
|
+
if (req.perPageQuery && !caps.perPageQuery) return false;
|
|
6
|
+
if (req.metrics?.some((m) => !caps.metrics.includes(m))) return false;
|
|
7
|
+
if (req.dimensions?.some((d) => !caps.dimensions.includes(d))) return false;
|
|
8
|
+
if (req.filters?.some((d) => !caps.filters.includes(d))) return false;
|
|
9
|
+
if (req.filterOperators?.some((op) => !caps.filterOperators.includes(op))) return false;
|
|
10
|
+
return true;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Options for the metric picker, narrowed to what the selected source can
|
|
14
|
+
* serve. An unknown source id (a stale value, a source the endpoint could not
|
|
15
|
+
* list) keeps the full static list, mirroring the server-side filterOptions
|
|
16
|
+
* fallback, and a source that cannot meet the widget's extra requirements at
|
|
17
|
+
* all falls back to the full list rather than an empty picker.
|
|
18
|
+
*/
|
|
19
|
+
const narrowMetricOptions = (args) => {
|
|
20
|
+
const src = args.sourceId ? args.sources.find((s) => s.id === args.sourceId) : void 0;
|
|
21
|
+
if (!src) return args.options;
|
|
22
|
+
if (args.requires && !satisfiesSerialized(src.capabilities, args.requires)) return args.options;
|
|
23
|
+
const narrowed = args.options.filter((o) => satisfiesSerialized(src.capabilities, {
|
|
24
|
+
...args.requires,
|
|
25
|
+
metrics: [o.value]
|
|
26
|
+
}));
|
|
27
|
+
return narrowed.length > 0 ? narrowed : args.options;
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { narrowMetricOptions };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=narrow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"narrow.js","names":[],"sources":["../../../src/fields/config/narrow.ts"],"sourcesContent":["import type { CapabilityRequirement, SerializedCapabilities } from '../../core/capabilities'\nimport type { WireSource } from './fetchSources'\n\nexport interface SelectOption {\n\tvalue: string\n\tlabel: unknown\n}\n\n/** satisfiesCapabilities over the wire form (arrays instead of Sets). */\nexport const satisfiesSerialized = (\n\tcaps: SerializedCapabilities,\n\treq: CapabilityRequirement\n): boolean => {\n\tif (req.realtime && !caps.realtime) return false\n\tif (req.perPageQuery && !caps.perPageQuery) return false\n\tif (req.metrics?.some((m) => !caps.metrics.includes(m))) return false\n\tif (req.dimensions?.some((d) => !caps.dimensions.includes(d))) return false\n\tif (req.filters?.some((d) => !caps.filters.includes(d))) return false\n\tif (req.filterOperators?.some((op) => !caps.filterOperators.includes(op))) return false\n\treturn true\n}\n\n/**\n * Options for the metric picker, narrowed to what the selected source can\n * serve. An unknown source id (a stale value, a source the endpoint could not\n * list) keeps the full static list, mirroring the server-side filterOptions\n * fallback, and a source that cannot meet the widget's extra requirements at\n * all falls back to the full list rather than an empty picker.\n */\nexport const narrowMetricOptions = (args: {\n\toptions: SelectOption[]\n\tsources: WireSource[]\n\tsourceId: string | undefined\n\trequires?: Omit<CapabilityRequirement, 'metrics'>\n}): SelectOption[] => {\n\tconst src = args.sourceId ? args.sources.find((s) => s.id === args.sourceId) : undefined\n\tif (!src) return args.options\n\tif (args.requires && !satisfiesSerialized(src.capabilities, args.requires)) {\n\t\treturn args.options\n\t}\n\tconst narrowed = args.options.filter((o) =>\n\t\tsatisfiesSerialized(src.capabilities, { ...args.requires, metrics: [o.value as never] })\n\t)\n\treturn narrowed.length > 0 ? narrowed : args.options\n}\n"],"mappings":";;AASA,MAAa,uBACZ,MACA,QACa;CACb,IAAI,IAAI,YAAY,CAAC,KAAK,UAAU,OAAO;CAC3C,IAAI,IAAI,gBAAgB,CAAC,KAAK,cAAc,OAAO;CACnD,IAAI,IAAI,SAAS,MAAM,MAAM,CAAC,KAAK,QAAQ,SAAS,CAAC,CAAC,GAAG,OAAO;CAChE,IAAI,IAAI,YAAY,MAAM,MAAM,CAAC,KAAK,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;CACtE,IAAI,IAAI,SAAS,MAAM,MAAM,CAAC,KAAK,QAAQ,SAAS,CAAC,CAAC,GAAG,OAAO;CAChE,IAAI,IAAI,iBAAiB,MAAM,OAAO,CAAC,KAAK,gBAAgB,SAAS,EAAE,CAAC,GAAG,OAAO;CAClF,OAAO;AACR;;;;;;;;AASA,MAAa,uBAAuB,SAKd;CACrB,MAAM,MAAM,KAAK,WAAW,KAAK,QAAQ,MAAM,MAAM,EAAE,OAAO,KAAK,QAAQ,IAAI,KAAA;CAC/E,IAAI,CAAC,KAAK,OAAO,KAAK;CACtB,IAAI,KAAK,YAAY,CAAC,oBAAoB,IAAI,cAAc,KAAK,QAAQ,GACxE,OAAO,KAAK;CAEb,MAAM,WAAW,KAAK,QAAQ,QAAQ,MACrC,oBAAoB,IAAI,cAAc;EAAE,GAAG,KAAK;EAAU,SAAS,CAAC,EAAE,KAAc;CAAE,CAAC,CACxF;CACA,OAAO,SAAS,SAAS,IAAI,WAAW,KAAK;AAC9C"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/fields/config/sourcesState.ts
|
|
2
|
+
const EMPTY_SOURCES = {
|
|
3
|
+
defaultId: null,
|
|
4
|
+
error: false,
|
|
5
|
+
loading: false,
|
|
6
|
+
sources: null
|
|
7
|
+
};
|
|
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
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { EMPTY_SOURCES, FAILED_SOURCES, resolveSourcesState };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=sourcesState.js.map
|
|
@@ -0,0 +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 = {\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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/fields/config/toSelectOption.ts
|
|
2
|
+
/**
|
|
3
|
+
* Static select options in this plugin carry per-locale label maps
|
|
4
|
+
* (Record<string, string>) from registerWidgets. Resolve an `Option` to a
|
|
5
|
+
* plain `{ value, label }` pair for the current locale, falling back to
|
|
6
|
+
* English, then to the raw value.
|
|
7
|
+
*/
|
|
8
|
+
const toSelectOption = (option, locale) => {
|
|
9
|
+
if (typeof option === "string") return {
|
|
10
|
+
label: option,
|
|
11
|
+
value: option
|
|
12
|
+
};
|
|
13
|
+
const { label, value } = option;
|
|
14
|
+
if (typeof label === "string") return {
|
|
15
|
+
label,
|
|
16
|
+
value
|
|
17
|
+
};
|
|
18
|
+
const map = label;
|
|
19
|
+
return {
|
|
20
|
+
label: map?.[locale] ?? map?.en ?? value,
|
|
21
|
+
value
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { toSelectOption };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=toSelectOption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toSelectOption.js","names":[],"sources":["../../../src/fields/config/toSelectOption.ts"],"sourcesContent":["import type { Option } from 'payload'\n\n/**\n * Static select options in this plugin carry per-locale label maps\n * (Record<string, string>) from registerWidgets. Resolve an `Option` to a\n * plain `{ value, label }` pair for the current locale, falling back to\n * English, then to the raw value.\n */\nexport const toSelectOption = (\n\toption: Option,\n\tlocale: string\n): { label: string; value: string } => {\n\tif (typeof option === 'string') return { label: option, value: option }\n\tconst { label, value } = option\n\tif (typeof label === 'string') return { label, value }\n\tconst map = label as Record<string, string> | undefined\n\treturn { label: map?.[locale] ?? map?.en ?? value, value }\n}\n"],"mappings":";;;;;;;AAQA,MAAa,kBACZ,QACA,WACsC;CACtC,IAAI,OAAO,WAAW,UAAU,OAAO;EAAE,OAAO;EAAQ,OAAO;CAAO;CACtE,MAAM,EAAE,OAAO,UAAU;CACzB,IAAI,OAAO,UAAU,UAAU,OAAO;EAAE;EAAO;CAAM;CACrD,MAAM,MAAM;CACZ,OAAO;EAAE,OAAO,MAAM,WAAW,KAAK,MAAM;EAAO;CAAM;AAC1D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WireSource } from "./fetchSources.js";
|
|
2
|
+
|
|
3
|
+
//#region src/fields/config/useAnalyticsSources.d.ts
|
|
4
|
+
interface AnalyticsSources {
|
|
5
|
+
sources: WireSource[] | null;
|
|
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;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Fetches the caller-scope source list for widget config pickers, sharing the
|
|
14
|
+
* per-user cache `fetchSources` already keeps. `sources` and `defaultId` stay
|
|
15
|
+
* null until the fetch resolves, on a failed fetch, or when there is no
|
|
16
|
+
* authenticated user yet; consumers fall back to their static option list in
|
|
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.
|
|
20
|
+
*/
|
|
21
|
+
declare const useAnalyticsSources: () => AnalyticsSources;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { AnalyticsSources, useAnalyticsSources };
|
|
24
|
+
//# sourceMappingURL=useAnalyticsSources.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { fetchSources } from "./fetchSources.js";
|
|
3
|
+
import { EMPTY_SOURCES, FAILED_SOURCES, resolveSourcesState } from "./sourcesState.js";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
import { useAuth, useConfig } from "@payloadcms/ui";
|
|
6
|
+
//#region src/fields/config/useAnalyticsSources.ts
|
|
7
|
+
/**
|
|
8
|
+
* Fetches the caller-scope source list for widget config pickers, sharing the
|
|
9
|
+
* per-user cache `fetchSources` already keeps. `sources` and `defaultId` stay
|
|
10
|
+
* null until the fetch resolves, on a failed fetch, or when there is no
|
|
11
|
+
* authenticated user yet; consumers fall back to their static option list in
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
const useAnalyticsSources = () => {
|
|
17
|
+
const { user } = useAuth();
|
|
18
|
+
const { config: { routes: { api }, serverURL } } = useConfig();
|
|
19
|
+
const userKey = String(user?.id ?? "");
|
|
20
|
+
const [state, setState] = useState({
|
|
21
|
+
key: "",
|
|
22
|
+
data: EMPTY_SOURCES
|
|
23
|
+
});
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!userKey) {
|
|
26
|
+
setState({
|
|
27
|
+
key: "",
|
|
28
|
+
data: EMPTY_SOURCES
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
let cancelled = false;
|
|
33
|
+
fetchSources(serverURL ?? "", api, userKey).then(({ defaultId, sources }) => {
|
|
34
|
+
if (!cancelled) setState({
|
|
35
|
+
key: userKey,
|
|
36
|
+
data: {
|
|
37
|
+
defaultId,
|
|
38
|
+
error: false,
|
|
39
|
+
loading: false,
|
|
40
|
+
sources
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}).catch(() => {
|
|
44
|
+
if (!cancelled) setState({
|
|
45
|
+
key: userKey,
|
|
46
|
+
data: FAILED_SOURCES
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
return () => {
|
|
50
|
+
cancelled = true;
|
|
51
|
+
};
|
|
52
|
+
}, [
|
|
53
|
+
api,
|
|
54
|
+
serverURL,
|
|
55
|
+
userKey
|
|
56
|
+
]);
|
|
57
|
+
return resolveSourcesState(state, userKey);
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
export { useAnalyticsSources };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=useAnalyticsSources.js.map
|
|
@@ -0,0 +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 {\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"}
|