@@ -6,28 +6,44 @@ import { useCssVariables } from '~/composables/useColors'
66import { OKLCH_NEUTRAL_FALLBACK , transparentizeOklch } from ' ~/utils/colors'
77import { getFrameworkColor , isListedFramework } from ' ~/utils/frameworks'
88import { drawNpmxLogoAndTaglineWatermark } from ' ~/composables/useChartWatermark'
9+ import type {
10+ ChartTimeGranularity ,
11+ DailyDataPoint ,
12+ DateRangeFields ,
13+ EvolutionData ,
14+ EvolutionOptions ,
15+ MonthlyDataPoint ,
16+ WeeklyDataPoint ,
17+ YearlyDataPoint ,
18+ } from ' ~/types/chart'
19+
20+ const props = withDefaults (
21+ defineProps <{
22+ // For single package downloads history
23+ weeklyDownloads? : WeeklyDataPoint []
24+ inModal? : boolean
925
10- const props = defineProps <{
11- // For single package downloads history
12- weeklyDownloads? : WeeklyDataPoint []
13- inModal? : boolean
14-
15- /**
16- * Backward compatible single package mode.
17- * Used when `weeklyDownloads` is provided.
18- */
19- packageName? : string
26+ /**
27+ * Backward compatible single package mode.
28+ * Used when `weeklyDownloads` is provided.
29+ */
30+ packageName? : string
2031
21- /**
22- * Multi-package mode.
23- * Used when `weeklyDownloads` is not provided.
24- */
25- packageNames? : string []
26- createdIso? : string | null
32+ /**
33+ * Multi-package mode.
34+ * Used when `weeklyDownloads` is not provided.
35+ */
36+ packageNames? : string []
37+ createdIso? : string | null
2738
28- /** When true, shows facet selector (e.g. Downloads / Likes). */
29- showFacetSelector? : boolean
30- }>()
39+ /** When true, shows facet selector (e.g. Downloads / Likes). */
40+ showFacetSelector? : boolean
41+ permalink? : boolean
42+ }>(),
43+ {
44+ permalink: false ,
45+ },
46+ )
3147
3248const { locale } = useI18n ()
3349const { accentColors, selectedAccentColor } = useAccentColor ()
@@ -110,14 +126,7 @@ const watermarkColors = computed(() => ({
110126const mobileBreakpointWidth = 640
111127const isMobile = computed (() => width .value > 0 && width .value < mobileBreakpointWidth )
112128
113- type ChartTimeGranularity = ' daily' | ' weekly' | ' monthly' | ' yearly'
114129const DEFAULT_GRANULARITY: ChartTimeGranularity = ' weekly'
115- type EvolutionData = DailyDataPoint [] | WeeklyDataPoint [] | MonthlyDataPoint [] | YearlyDataPoint []
116-
117- type DateRangeFields = {
118- startDate? : string
119- endDate? : string
120- }
121130
122131function isRecord(value : unknown ): value is Record <string , unknown > {
123132 return typeof value === ' object' && value !== null
@@ -322,7 +331,10 @@ const effectivePackageNames = computed<string[]>(() => {
322331 return single ? [single ] : []
323332})
324333
325- const selectedGranularity = shallowRef <ChartTimeGranularity >(DEFAULT_GRANULARITY )
334+ const selectedGranularity = usePermalink <ChartTimeGranularity >(' granularity' , DEFAULT_GRANULARITY , {
335+ permanent: props .permalink ,
336+ })
337+
326338const displayedGranularity = shallowRef <ChartTimeGranularity >(DEFAULT_GRANULARITY )
327339
328340const isEndDateOnPeriodEnd = computed (() => {
@@ -352,8 +364,13 @@ const shouldRenderEstimationOverlay = computed(
352364 () => ! pending .value && isEstimationGranularity .value ,
353365)
354366
355- const startDate = shallowRef <string >(' ' ) // YYYY-MM-DD
356- const endDate = shallowRef <string >(' ' ) // YYYY-MM-DD
367+ const startDate = usePermalink <string >(' start' , ' ' , {
368+ permanent: props .permalink ,
369+ })
370+ const endDate = usePermalink <string >(' end' , ' ' , {
371+ permanent: props .permalink ,
372+ })
373+
357374const hasUserEditedDates = shallowRef (false )
358375
359376/**
@@ -578,7 +595,9 @@ const METRICS = computed<MetricDef[]>(() => [
578595 },
579596])
580597
581- const selectedMetric = shallowRef <MetricId >(DEFAULT_METRIC_ID )
598+ const selectedMetric = usePermalink <MetricId >(' facet' , DEFAULT_METRIC_ID , {
599+ permanent: props .permalink ,
600+ })
582601
583602// Per-metric state keyed by metric id
584603const metricStates = reactive <
0 commit comments