@nuxtseo/pro-indexing 0.0.0-stage → 0.1.5

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.
@@ -0,0 +1,237 @@
1
+ <script setup lang="ts" generic="T extends object">
2
+ import type { UiTableColumn, UiTableRowId, UiTableSize } from '@nuxtseo/design-system/app/shared/table'
3
+ import { useHumanFriendlyNumber } from '@nuxtseo/design-system/app/composables/formatting'
4
+ import { fillCopy } from '@nuxtseo/pro-shell/shared/copy'
5
+ import { refDebounced } from '@vueuse/core'
6
+ import { computed, ref, watch } from 'vue'
7
+ import { UiAlert, UiButton, UiEmptyState, UiFilterMenu, UiInput, UiSkeleton, UiTable, UiTablePagination } from '#components'
8
+ import { useProIndexingCopy } from '../composables/useProIndexingCopy'
9
+
10
+ // The default table shell of `IndexingUrlsTable`: search, the status filter,
11
+ // loading, error, empty, the table, and the pager. A site with its own shell
12
+ // passes it as the table's `shell` prop; that shell takes these props, emits
13
+ // these events, and fills the same slots (`toolbar`, `notices`,
14
+ // `expanded-component`).
15
+
16
+ export interface IndexingUrlsTableFilter {
17
+ key: string
18
+ label: string
19
+ icon?: string
20
+ tooltip?: string
21
+ }
22
+
23
+ const {
24
+ filters = [],
25
+ searchPlaceholder,
26
+ emptyIcon = 'file-search',
27
+ emptyTitle,
28
+ emptyDefaultDescription = '',
29
+ itemLabel,
30
+ pageSize = 25,
31
+ hasExternalFilter = false,
32
+ hasCachedData,
33
+ rowClickable = false,
34
+ tableSize = 'md',
35
+ q,
36
+ filter,
37
+ page,
38
+ error,
39
+ rows,
40
+ } = defineProps<{
41
+ filters?: IndexingUrlsTableFilter[]
42
+ searchPlaceholder?: string
43
+ emptyIcon?: string
44
+ emptyTitle?: string
45
+ emptyDefaultDescription?: string
46
+ itemLabel?: string
47
+ pageSize?: number
48
+ /** Another filter the table owns is active, such as an issue. */
49
+ hasExternalFilter?: boolean
50
+ /** Accepted for parity with a site shell. The default shell saves no filters. */
51
+ showSavedFilters?: boolean
52
+ /** A successful response is present, including a valid empty one. */
53
+ hasCachedData?: boolean
54
+ rowClickable?: boolean
55
+ rowId?: UiTableRowId<T>
56
+ initialExpandedRowId?: string
57
+ tableSize?: UiTableSize
58
+ tableLabel: string
59
+ q: string
60
+ filter: string | undefined
61
+ isLoading: boolean
62
+ error: Error | null | undefined
63
+ rows: T[]
64
+ total: number
65
+ page: number
66
+ columns: UiTableColumn<T>[]
67
+ tableData: T[]
68
+ }>()
69
+
70
+ const emit = defineEmits<{
71
+ 'update:q': [value: string]
72
+ 'update:page': [value: number]
73
+ 'toggleFilter': [key: string]
74
+ 'clearFilters': []
75
+ 'retry': []
76
+ }>()
77
+
78
+ const copy = useProIndexingCopy().urlsShell
79
+ const placeholder = computed(() => searchPlaceholder ?? copy.searchPlaceholder)
80
+ const items = computed(() => itemLabel ?? copy.itemLabel)
81
+
82
+ const localQ = ref(q)
83
+ const debouncedQ = refDebounced(localQ, 300)
84
+ const localPage = computed({
85
+ get: () => page,
86
+ set: (value: number) => emit('update:page', value),
87
+ })
88
+
89
+ const cachedEvidence = computed(() => hasCachedData ?? rows.length > 0)
90
+ const blockingError = computed(() => error && !cachedEvidence.value ? error : null)
91
+ const refreshError = computed(() => error && cachedEvidence.value ? error : null)
92
+ const hasActiveFilter = computed(() => Boolean(q || (filter && filter !== 'default') || hasExternalFilter))
93
+ const emptyDescription = computed(() => {
94
+ if (q)
95
+ return fillCopy(copy.emptySearch, { items: items.value, q })
96
+ if ((filter && filter !== 'default') || hasExternalFilter)
97
+ return fillCopy(copy.emptyFilter, { items: items.value })
98
+ return emptyDefaultDescription
99
+ })
100
+
101
+ watch(() => q, (value) => {
102
+ if (value !== localQ.value)
103
+ localQ.value = value
104
+ })
105
+ watch(debouncedQ, (value) => {
106
+ if (value === q)
107
+ return
108
+ emit('update:q', value)
109
+ emit('update:page', 1)
110
+ })
111
+
112
+ function commitQ(value = localQ.value) {
113
+ localQ.value = value
114
+ if (value !== q)
115
+ emit('update:q', value)
116
+ emit('update:page', 1)
117
+ }
118
+
119
+ const presetFilters = computed(() => filters.map(entry => ({ id: entry.key, label: entry.label, icon: entry.icon })))
120
+ const activeCount = computed(() => filter && filter !== 'default' ? 1 : 0)
121
+
122
+ function clearOwnedFilters() {
123
+ commitQ('')
124
+ if (filter && filter !== 'default')
125
+ emit('toggleFilter', filter)
126
+ }
127
+ function clearAllFilters() {
128
+ if (hasExternalFilter)
129
+ emit('clearFilters')
130
+ else
131
+ clearOwnedFilters()
132
+ }
133
+ </script>
134
+
135
+ <template>
136
+ <div class="space-y-4" :aria-busy="isLoading || undefined">
137
+ <div class="flex items-center justify-between gap-2">
138
+ <div class="flex-1 sm:flex-none sm:w-64">
139
+ <UiInput
140
+ v-model="localQ"
141
+ :placeholder="placeholder"
142
+ :aria-label="placeholder"
143
+ icon="search"
144
+ autocomplete="off"
145
+ size="sm"
146
+ :ui="{ base: 'min-h-11 sm:min-h-10' }"
147
+ @keydown.enter="commitQ()"
148
+ >
149
+ <template #trailing>
150
+ <UiButton
151
+ v-if="localQ !== ''"
152
+ purpose="quiet"
153
+ icon="close"
154
+ size="xs"
155
+ class="min-h-11 min-w-11 sm:min-h-0 sm:min-w-0"
156
+ :aria-label="copy.clearSearch"
157
+ @click="commitQ('')"
158
+ />
159
+ </template>
160
+ </UiInput>
161
+ </div>
162
+ <div class="flex items-center gap-1">
163
+ <slot name="toolbar" />
164
+ <UiFilterMenu
165
+ v-if="filters.length"
166
+ :searchable="false"
167
+ :preset-filters="presetFilters"
168
+ :active-preset="filter"
169
+ :saved-filters="[]"
170
+ :active-count="activeCount"
171
+ :show-saved="false"
172
+ @apply-preset="emit('toggleFilter', $event)"
173
+ @clear="clearOwnedFilters"
174
+ />
175
+ </div>
176
+ </div>
177
+
178
+ <slot name="notices" />
179
+
180
+ <UiAlert v-if="refreshError" status="warning" :title="copy.refreshFailedTitle" :description="copy.refreshFailedBody">
181
+ <template #action>
182
+ <UiButton purpose="secondary" size="xs" class="min-h-11 sm:min-h-0" @click="emit('retry')">
183
+ {{ copy.retry }}
184
+ </UiButton>
185
+ </template>
186
+ </UiAlert>
187
+
188
+ <div v-if="isLoading" class="rounded-xl border border-default overflow-hidden">
189
+ <div class="divide-y divide-default">
190
+ <div v-for="i in Math.min(pageSize, 10)" :key="i" class="px-5 py-4 flex items-center gap-6">
191
+ <div class="flex-1">
192
+ <UiSkeleton class="h-4" :index="i" :base="180" :range="80" />
193
+ </div>
194
+ <UiSkeleton class="h-4" :index="i + 10" :base="48" :range="16" />
195
+ <UiSkeleton class="h-4" :index="i + 20" :base="56" :range="18" />
196
+ </div>
197
+ </div>
198
+ </div>
199
+
200
+ <UiAlert v-else-if="blockingError" status="error" icon="caution" :title="blockingError.message || copy.loadFailed">
201
+ <template #action>
202
+ <UiButton purpose="secondary" size="xs" class="min-h-11 sm:min-h-0" @click="emit('retry')">
203
+ {{ copy.retry }}
204
+ </UiButton>
205
+ </template>
206
+ </UiAlert>
207
+
208
+ <UiEmptyState v-else-if="!rows.length" compact heading-tag="h3" :icon="emptyIcon" :title="emptyTitle ?? copy.emptyTitle" :description="emptyDescription">
209
+ <UiButton v-if="hasActiveFilter" size="sm" purpose="secondary" @click="clearAllFilters">
210
+ {{ copy.clearFilters }}
211
+ </UiButton>
212
+ </UiEmptyState>
213
+
214
+ <UiTable
215
+ v-else
216
+ :data="tableData"
217
+ :columns="columns"
218
+ :page-size="pageSize"
219
+ bordered
220
+ :row-clickable="rowClickable"
221
+ :row-id="rowId"
222
+ :initial-expanded-row-id="initialExpandedRowId"
223
+ :size="tableSize"
224
+ :label="tableLabel"
225
+ disable-pagination
226
+ row-hover
227
+ >
228
+ <template v-if="$slots['expanded-component']" #expanded-component="{ row }">
229
+ <slot name="expanded-component" :row="row" />
230
+ </template>
231
+ </UiTable>
232
+
233
+ <UiTablePagination v-if="total > pageSize" v-model:page="localPage" :page-size="pageSize" :total="total">
234
+ <span class="font-medium text-default">{{ useHumanFriendlyNumber(total) }}</span> {{ fillCopy(copy.total, { items }) }}
235
+ </UiTablePagination>
236
+ </div>
237
+ </template>
@@ -0,0 +1,27 @@
1
+ import type { InjectionKey } from 'vue'
2
+ import type { IndexingCapability, IndexingSource } from '../../shared/source'
3
+ import { inject, provide } from 'vue'
4
+ import { hasIndexingCapability } from '../../shared/source'
5
+
6
+ export const PRO_INDEXING_SOURCE_KEY: InjectionKey<IndexingSource> = Symbol('pro-indexing-source')
7
+
8
+ /**
9
+ * Provides the site's IndexingSource to every indexing section below. Call it
10
+ * in the setup of a component above the sections, such as the site's
11
+ * dashboard layout. To provide it app-wide, call
12
+ * `nuxtApp.vueApp.provide(PRO_INDEXING_SOURCE_KEY, source)` in a plugin.
13
+ */
14
+ export function provideIndexingSource(source: IndexingSource): IndexingSource {
15
+ provide(PRO_INDEXING_SOURCE_KEY, source)
16
+ return source
17
+ }
18
+
19
+ /** The IndexingSource a site provided, or null. A section draws nothing that needs a source when it is null. */
20
+ export function useIndexingSource(): IndexingSource | null {
21
+ return inject(PRO_INDEXING_SOURCE_KEY, null)
22
+ }
23
+
24
+ /** True when the provided source has the capability. Call it in setup. */
25
+ export function useIndexingCapability(capability: IndexingCapability): boolean {
26
+ return hasIndexingCapability(useIndexingSource(), capability)
27
+ }
@@ -0,0 +1,10 @@
1
+ import type { IndexedShareTone, ProIndexingAppConfig } from '../../shared/config'
2
+ import { tryUseNuxtApp, useAppConfig } from 'nuxt/app'
3
+ import { DEFAULT_INDEXED_SHARE_TONE } from '../../shared/config'
4
+
5
+ /** The Indexed tile's tone from app.config `proIndexing.indexedShareTone`. Call it in setup. */
6
+ export function useProIndexingIndexedShareTone(): IndexedShareTone {
7
+ const appConfig = tryUseNuxtApp() ? useAppConfig() : null
8
+ const tone = (appConfig?.proIndexing as ProIndexingAppConfig | undefined)?.indexedShareTone
9
+ return tone?._tag === 'neutral' || tone?._tag === 'health' ? tone : DEFAULT_INDEXED_SHARE_TONE
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { ProIndexingAppConfig } from '../../shared/config'
2
+ import type { ProIndexingCopy } from '../../shared/copy'
3
+ import { tryUseNuxtApp, useAppConfig } from 'nuxt/app'
4
+ import { resolveProIndexingCopy } from '../../shared/copy'
5
+
6
+ /** The indexing copy with the site's `proIndexing.copy` overrides applied. Call it in setup. */
7
+ export function useProIndexingCopy(): ProIndexingCopy {
8
+ const appConfig = tryUseNuxtApp() ? useAppConfig() : null
9
+ return resolveProIndexingCopy((appConfig?.proIndexing as ProIndexingAppConfig | undefined)?.copy)
10
+ }
@@ -0,0 +1,23 @@
1
+ import type { ProIndexingAppConfig } from '../../shared/config'
2
+ import type { ProIndexingAppRoute, ProIndexingQuery, ProIndexingSiteRoute } from '../../shared/routes'
3
+ import { tryUseNuxtApp, useAppConfig } from 'nuxt/app'
4
+ import { resolveIndexingAppRoute, resolveIndexingSiteRoute } from '../../shared/routes'
5
+
6
+ export interface ProIndexingRouteResolver {
7
+ readonly app: (name: ProIndexingAppRoute, query?: ProIndexingQuery) => string | null
8
+ readonly site: (name: ProIndexingSiteRoute, site: string, query?: ProIndexingQuery) => string | null
9
+ }
10
+
11
+ /**
12
+ * Resolves the sections' logical routes against app.config
13
+ * `proIndexing.routes`. Null means the site maps no such route: hide the link.
14
+ * Call it in setup; each call reads the map again.
15
+ */
16
+ export function useProIndexingRoute(): ProIndexingRouteResolver {
17
+ const appConfig = tryUseNuxtApp() ? useAppConfig() : null
18
+ const routes = () => (appConfig?.proIndexing as ProIndexingAppConfig | undefined)?.routes ?? {}
19
+ return {
20
+ app: (name, query) => resolveIndexingAppRoute(routes(), name, query),
21
+ site: (name, site, query) => resolveIndexingSiteRoute(routes(), name, site, query),
22
+ }
23
+ }
package/nuxt.config.ts ADDED
@@ -0,0 +1,33 @@
1
+ import { join } from 'node:path'
2
+ import { defineNuxtConfig } from 'nuxt/config'
3
+
4
+ const currentDir = import.meta.dirname
5
+
6
+ // Pro indexing layer: the dashboard indexing sections that nuxtseo.com,
7
+ // gscdump.com and Request Indexing share. It extends the shell and adds no
8
+ // module of its own.
9
+ //
10
+ // Per ADR-0042, ADR-0166 and ADR-0167: it MUST NOT import runtime services (no
11
+ // useFetch, $fetch, Drizzle, Caller, billing, auth, useRuntimeConfig). Every
12
+ // read and action goes through the IndexingSource the site provides
13
+ // (`provideIndexingSource`). An optional capability the source leaves out
14
+ // hides the section that needs it. Links come from the route map in
15
+ // app.config `proIndexing.routes`. The maths is `@gscdump/sdk/indexing`.
16
+ export default defineNuxtConfig({
17
+ extends: ['@nuxtseo/pro-shell'],
18
+
19
+ imports: { autoImport: false },
20
+
21
+ components: {
22
+ dirs: [
23
+ {
24
+ path: join(currentDir, './app/components'),
25
+ pathPrefix: false,
26
+ // The same priority as the shell and the design system, so a site
27
+ // component with a layer name loses. Sites change the layer through
28
+ // props, slots, the source and app.config instead.
29
+ priority: 10,
30
+ },
31
+ ],
32
+ },
33
+ })
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
2
  "name": "@nuxtseo/pro-indexing",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "type": "module",
4
+ "version": "0.1.5",
5
+ "description": "Nuxt SEO Pro indexing layer: the dashboard indexing sections (Portfolio overview, issues and changes, the per-Site diagnosis panel, coverage trend, Index cohorts, and the indexing URLs table) over one IndexingSource adapter and a route map. Extends @nuxtseo/pro-shell.",
6
+ "license": "MIT",
7
+ "homepage": "https://nuxtseo.com",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/harlan-zw/nuxtseo.com.git",
11
+ "directory": "layers/pro-indexing"
12
+ },
13
+ "keywords": [
14
+ "nuxt",
15
+ "nuxt-layer",
16
+ "dashboard",
17
+ "search-console",
18
+ "indexing"
19
+ ],
20
+ "exports": {
21
+ ".": "./nuxt.config.ts",
22
+ "./*": "./*",
23
+ "./app/*": "./app/*.ts",
24
+ "./app/*.vue": "./app/*.vue",
25
+ "./components/*.vue": "./app/components/*.vue",
26
+ "./composables/*": "./app/composables/*.ts",
27
+ "./package.json": "./package.json",
28
+ "./shared/*": "./shared/*.ts"
29
+ },
30
+ "main": "./nuxt.config.ts",
31
+ "files": [
32
+ "app",
33
+ "nuxt.config.ts",
34
+ "shared"
35
+ ],
36
+ "peerDependencies": {
37
+ "@gscdump/contracts": "^7.13.0",
38
+ "@gscdump/sdk": "^7.13.0",
39
+ "@nuxt/ui": "^4.11.1",
40
+ "@nuxtseo/design-system": "^0.1.5",
41
+ "@nuxtseo/pro-shell": "^0.1.5",
42
+ "@vueuse/core": "^14.0.0 || ^15.0.0",
43
+ "nuxt": "^4.6.0",
44
+ "typescript": ">=5.8.0 <7",
45
+ "vue": "^3.5.0"
46
+ },
47
+ "dependencies": {
48
+ "@unovis/ts": "^1.6.7",
49
+ "@unovis/vue": "^1.6.7"
50
+ },
51
+ "devDependencies": {
52
+ "@gscdump/contracts": "7.13.0",
53
+ "@gscdump/sdk": "7.13.0",
54
+ "@nuxt/ui": "^4.11.1",
55
+ "@nuxtseo/design-system": "0.1.5",
56
+ "@nuxtseo/pro-shell": "0.1.5",
57
+ "@vueuse/core": "^14.4.0",
58
+ "nuxt": "4.6.1",
59
+ "site-typecheck": "0.0.0",
60
+ "vue": "^3.5.43"
61
+ },
62
+ "publishConfig": {
63
+ "access": "public"
64
+ },
65
+ "scripts": {
66
+ "nuxt:prepare": "nuxt prepare",
67
+ "typecheck": "nuxt prepare && site-typecheck -b --noEmit --force",
68
+ "typecheck:legacy": "nuxt typecheck"
69
+ }
6
70
  }
@@ -0,0 +1,124 @@
1
+ // Portfolio indexing Changes. Pure: the roll-up carries every Site the source
2
+ // covers, and the group scope narrows it here.
3
+ //
4
+ // Moved from nuxtseo.com `layers/pro/gsc/app/utils/indexing-changes.ts`.
5
+ //
6
+ // Two sources with different strengths. A Site's trend counts every URL, so it
7
+ // owns the not-indexed change. The roll-up reads a page issue index, which can
8
+ // hold a sample of URLs per reason on a large Site: its counts are floors, and
9
+ // a URL can enter that sample long after Google reported it. So first recorded
10
+ // minus cleared is never presented as a change in level.
11
+
12
+ import type { IndexingTrendReading } from '@gscdump/sdk/indexing'
13
+ import { notIndexedCount } from '@gscdump/sdk/indexing'
14
+
15
+ /** One Site on one UTC day of the roll-up. */
16
+ export interface IndexingChangesRow {
17
+ readonly siteId: string
18
+ /** UTC day, `YYYY-MM-DD`. */
19
+ readonly day: string
20
+ /** Issues the source first reported on this day. */
21
+ readonly opened: number
22
+ /** Issues the source stopped reporting on this day. This says nothing about a repair. */
23
+ readonly cleared: number
24
+ }
25
+
26
+ /** What the `changesRollup` capability returns. */
27
+ export interface IndexingChangesRollup {
28
+ readonly windowDays: number
29
+ /** The source's last UTC day of the window, so the axis cannot follow a browser clock. */
30
+ readonly through: string
31
+ /** Only days with a change. */
32
+ readonly rows: readonly IndexingChangesRow[]
33
+ }
34
+
35
+ export interface IndexingChangesSite {
36
+ id: string
37
+ label: string
38
+ /** Absent until the Site has a coverage observation. Missing is not zero. */
39
+ trend?: readonly IndexingTrendReading[]
40
+ }
41
+ export interface IndexingLevelChange {
42
+ notIndexed: number
43
+ /** Positive means more URLs are not indexed. */
44
+ change: number
45
+ /** The first day of the trend inside the window. */
46
+ since: string
47
+ }
48
+
49
+ export interface IndexingChangesDay {
50
+ day: string
51
+ opened: number
52
+ cleared: number
53
+ }
54
+
55
+ export interface IndexingChangesSiteRow {
56
+ siteId: string
57
+ label: string
58
+ opened: number
59
+ cleared: number
60
+ level: IndexingLevelChange | null
61
+ }
62
+
63
+ export interface IndexingChanges {
64
+ /** One entry per UTC day of the window, oldest first, zero filled. */
65
+ days: IndexingChangesDay[]
66
+ /** Sites with a change, largest not-indexed rise first. Unknown levels sort last. */
67
+ sites: IndexingChangesSiteRow[]
68
+ }
69
+
70
+ const DAY_MS = 86_400_000
71
+
72
+ function windowAxis(through: string, windowDays: number): string[] {
73
+ const last = Date.parse(`${through}T00:00:00Z`)
74
+ return Array.from({ length: windowDays }, (_, index) =>
75
+ new Date(last - (windowDays - 1 - index) * DAY_MS).toISOString().slice(0, 10))
76
+ }
77
+
78
+ /** The not-indexed change across the window, or null without two days to compare. */
79
+ export function indexingLevelChange(trend: readonly IndexingTrendReading[], from: string): IndexingLevelChange | null {
80
+ const points = trend.filter(point => point.totalUrls > 0 && point.date >= from).toSorted((a, b) => a.date.localeCompare(b.date))
81
+ const first = points[0]
82
+ const last = points.at(-1)
83
+ if (!first || !last || first === last)
84
+ return null
85
+ const notIndexed = notIndexedCount(last)
86
+ return { notIndexed, change: notIndexed - notIndexedCount(first), since: first.date }
87
+ }
88
+
89
+ /**
90
+ * The chart and the list read one set of rows, so their totals agree. A row
91
+ * outside the scoped Sites or outside the window reaches neither.
92
+ */
93
+ export function summarizeIndexingChanges(rollup: IndexingChangesRollup, sites: readonly IndexingChangesSite[]): IndexingChanges {
94
+ const axis = windowAxis(rollup.through, rollup.windowDays)
95
+ const days = new Map(axis.map(day => [day, { day, opened: 0, cleared: 0 }]))
96
+ const bySite = new Map<string, IndexingChangesSiteRow>(sites.map(site => [site.id, {
97
+ siteId: site.id,
98
+ label: site.label,
99
+ opened: 0,
100
+ cleared: 0,
101
+ level: site.trend ? indexingLevelChange(site.trend, axis[0]!) : null,
102
+ }]))
103
+
104
+ const withTrend = new Set(sites.filter(site => site.trend?.length).map(site => site.id))
105
+ for (const row of rollup.rows) {
106
+ const day = days.get(row.day)
107
+ const site = bySite.get(row.siteId)
108
+ if (!day || !site)
109
+ continue
110
+ day.opened += row.opened
111
+ day.cleared += row.cleared
112
+ site.opened += row.opened
113
+ site.cleared += row.cleared
114
+ }
115
+
116
+ return {
117
+ days: [...days.values()],
118
+ sites: [...bySite.values()]
119
+ // A Site with a trend but nothing to compare stays, as unknown. Dropping it
120
+ // would read as no change.
121
+ .filter(site => site.opened > 0 || site.cleared > 0 || !!site.level?.change || (!site.level && withTrend.has(site.siteId)))
122
+ .sort((a, b) => (b.level?.change ?? Number.NEGATIVE_INFINITY) - (a.level?.change ?? Number.NEGATIVE_INFINITY) || b.opened - a.opened || a.label.localeCompare(b.label)),
123
+ }
124
+ }
@@ -0,0 +1,36 @@
1
+ // `proIndexing` in app.config: the route map, copy overrides, and the Indexed
2
+ // tile's tone. Write app.config as a plain object and wrap this key in
3
+ // `defineProIndexingConfig` to type-check it.
4
+
5
+ import type { ProIndexingCopyOverrides } from './copy'
6
+ import type { ProIndexingRouteMap } from './routes'
7
+
8
+ /**
9
+ * How the Portfolio Overview's Indexed tile colours its share. `health` draws
10
+ * a share below `warningBelow` as a warning and below `errorBelow` as an
11
+ * error. `neutral` draws every share in the default text colour.
12
+ */
13
+ export type IndexedShareTone
14
+ = | { readonly _tag: 'health', readonly warningBelow: number, readonly errorBelow: number }
15
+ | { readonly _tag: 'neutral' }
16
+
17
+ export const DEFAULT_INDEXED_SHARE_TONE: IndexedShareTone = { _tag: 'health', warningBelow: 80, errorBelow: 50 }
18
+
19
+ export interface ProIndexingAppConfig {
20
+ readonly routes?: ProIndexingRouteMap
21
+ readonly copy?: ProIndexingCopyOverrides
22
+ /** Defaults to `DEFAULT_INDEXED_SHARE_TONE`. */
23
+ readonly indexedShareTone?: IndexedShareTone
24
+ }
25
+
26
+ /** Identity function that type-checks `proIndexing` in a plain-object app.config. */
27
+ export function defineProIndexingConfig(config: ProIndexingAppConfig): ProIndexingAppConfig {
28
+ return config
29
+ }
30
+
31
+ /** The text class for an indexed share, in percent, under a tone. */
32
+ export function indexedShareTextClass(percent: number, tone: IndexedShareTone = DEFAULT_INDEXED_SHARE_TONE): string {
33
+ if (tone._tag === 'neutral' || percent >= tone.warningBelow)
34
+ return 'text-default'
35
+ return percent >= tone.errorBelow ? 'text-warning' : 'text-error'
36
+ }