@@ -6,29 +6,45 @@ 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'
919import { DATE_INPUT_MAX } from ' ~/utils/input'
1020
11- const props = defineProps <{
12- // For single package downloads history
13- weeklyDownloads? : WeeklyDataPoint []
14- inModal? : boolean
21+ const props = withDefaults (
22+ defineProps <{
23+ // For single package downloads history
24+ weeklyDownloads? : WeeklyDataPoint []
25+ inModal? : boolean
1526
16- /**
17- * Backward compatible single package mode.
18- * Used when `weeklyDownloads` is provided.
19- */
20- packageName? : string
27+ /**
28+ * Backward compatible single package mode.
29+ * Used when `weeklyDownloads` is provided.
30+ */
31+ packageName? : string
2132
22- /**
23- * Multi-package mode.
24- * Used when `weeklyDownloads` is not provided.
25- */
26- packageNames? : string []
27- createdIso? : string | null
33+ /**
34+ * Multi-package mode.
35+ * Used when `weeklyDownloads` is not provided.
36+ */
37+ packageNames? : string []
38+ createdIso? : string | null
2839
29- /** When true, shows facet selector (e.g. Downloads / Likes). */
30- showFacetSelector? : boolean
31- }>()
40+ /** When true, shows facet selector (e.g. Downloads / Likes). */
41+ showFacetSelector? : boolean
42+ permalink? : boolean
43+ }>(),
44+ {
45+ permalink: false ,
46+ },
47+ )
3248
3349const { locale } = useI18n ()
3450const { accentColors, selectedAccentColor } = useAccentColor ()
@@ -111,14 +127,7 @@ const watermarkColors = computed(() => ({
111127const mobileBreakpointWidth = 640
112128const isMobile = computed (() => width .value > 0 && width .value < mobileBreakpointWidth )
113129
114- type ChartTimeGranularity = ' daily' | ' weekly' | ' monthly' | ' yearly'
115130const DEFAULT_GRANULARITY: ChartTimeGranularity = ' weekly'
116- type EvolutionData = DailyDataPoint [] | WeeklyDataPoint [] | MonthlyDataPoint [] | YearlyDataPoint []
117-
118- type DateRangeFields = {
119- startDate? : string
120- endDate? : string
121- }
122131
123132function isRecord(value : unknown ): value is Record <string , unknown > {
124133 return typeof value === ' object' && value !== null
@@ -323,7 +332,10 @@ const effectivePackageNames = computed<string[]>(() => {
323332 return single ? [single ] : []
324333})
325334
326- const selectedGranularity = shallowRef <ChartTimeGranularity >(DEFAULT_GRANULARITY )
335+ const selectedGranularity = usePermalink <ChartTimeGranularity >(' granularity' , DEFAULT_GRANULARITY , {
336+ permanent: props .permalink ,
337+ })
338+
327339const displayedGranularity = shallowRef <ChartTimeGranularity >(DEFAULT_GRANULARITY )
328340
329341const isEndDateOnPeriodEnd = computed (() => {
@@ -353,8 +365,13 @@ const shouldRenderEstimationOverlay = computed(
353365 () => ! pending .value && isEstimationGranularity .value ,
354366)
355367
356- const startDate = shallowRef <string >(' ' ) // YYYY-MM-DD
357- const endDate = shallowRef <string >(' ' ) // YYYY-MM-DD
368+ const startDate = usePermalink <string >(' start' , ' ' , {
369+ permanent: props .permalink ,
370+ })
371+ const endDate = usePermalink <string >(' end' , ' ' , {
372+ permanent: props .permalink ,
373+ })
374+
358375const hasUserEditedDates = shallowRef (false )
359376
360377/**
@@ -579,7 +596,9 @@ const METRICS = computed<MetricDef[]>(() => [
579596 },
580597])
581598
582- const selectedMetric = shallowRef <MetricId >(DEFAULT_METRIC_ID )
599+ const selectedMetric = usePermalink <MetricId >(' facet' , DEFAULT_METRIC_ID , {
600+ permanent: props .permalink ,
601+ })
583602
584603// Per-metric state keyed by metric id
585604const metricStates = reactive <
0 commit comments