@eightyfourthousand/data-access 2026.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/.babelrc +12 -0
  2. package/.eslintrc.json +18 -0
  3. package/README.md +7 -0
  4. package/jest.config.ts +10 -0
  5. package/package.json +30 -0
  6. package/project.json +21 -0
  7. package/src/index.ts +18 -0
  8. package/src/lib/auth.ts +203 -0
  9. package/src/lib/bibliography.ts +57 -0
  10. package/src/lib/canon.ts +111 -0
  11. package/src/lib/client-browser.ts +12 -0
  12. package/src/lib/client-server.ts +30 -0
  13. package/src/lib/client-ssr.ts +24 -0
  14. package/src/lib/client-token.ts +24 -0
  15. package/src/lib/feedback.ts +71 -0
  16. package/src/lib/folio.ts +43 -0
  17. package/src/lib/glossary.ts +147 -0
  18. package/src/lib/imprint.ts +42 -0
  19. package/src/lib/library.ts +209 -0
  20. package/src/lib/local-storage.ts +33 -0
  21. package/src/lib/lookup-entity.ts +122 -0
  22. package/src/lib/panel-url.ts +43 -0
  23. package/src/lib/passage.ts +122 -0
  24. package/src/lib/projects.ts +107 -0
  25. package/src/lib/proxy.ts +68 -0
  26. package/src/lib/publications.ts +213 -0
  27. package/src/lib/storage.ts +23 -0
  28. package/src/lib/types/alignment.ts +32 -0
  29. package/src/lib/types/annotation/abbreviation.ts +30 -0
  30. package/src/lib/types/annotation/annotation-type.ts +219 -0
  31. package/src/lib/types/annotation/annotation.ts +244 -0
  32. package/src/lib/types/annotation/audio.ts +33 -0
  33. package/src/lib/types/annotation/blockquote.ts +18 -0
  34. package/src/lib/types/annotation/code.ts +16 -0
  35. package/src/lib/types/annotation/deprecated.ts +18 -0
  36. package/src/lib/types/annotation/end-note-link.ts +35 -0
  37. package/src/lib/types/annotation/export.ts +69 -0
  38. package/src/lib/types/annotation/glossary-instance.ts +34 -0
  39. package/src/lib/types/annotation/has-abbreviation.ts +30 -0
  40. package/src/lib/types/annotation/heading.ts +37 -0
  41. package/src/lib/types/annotation/image.ts +29 -0
  42. package/src/lib/types/annotation/indent.ts +16 -0
  43. package/src/lib/types/annotation/index.ts +4 -0
  44. package/src/lib/types/annotation/inline-title.ts +34 -0
  45. package/src/lib/types/annotation/internal-link.ts +86 -0
  46. package/src/lib/types/annotation/leading-space.ts +18 -0
  47. package/src/lib/types/annotation/line-group.ts +18 -0
  48. package/src/lib/types/annotation/line.ts +16 -0
  49. package/src/lib/types/annotation/link.ts +38 -0
  50. package/src/lib/types/annotation/list-item.ts +16 -0
  51. package/src/lib/types/annotation/list.ts +43 -0
  52. package/src/lib/types/annotation/mantra.ts +31 -0
  53. package/src/lib/types/annotation/mention.ts +64 -0
  54. package/src/lib/types/annotation/paragraph.ts +18 -0
  55. package/src/lib/types/annotation/quote.ts +30 -0
  56. package/src/lib/types/annotation/quoted.ts +30 -0
  57. package/src/lib/types/annotation/reference.ts +18 -0
  58. package/src/lib/types/annotation/span.ts +39 -0
  59. package/src/lib/types/annotation/table-body-data.ts +18 -0
  60. package/src/lib/types/annotation/table-body-header.ts +18 -0
  61. package/src/lib/types/annotation/table-body-row.ts +18 -0
  62. package/src/lib/types/annotation/table.ts +16 -0
  63. package/src/lib/types/annotation/trailer.ts +16 -0
  64. package/src/lib/types/annotation/transform.ts +140 -0
  65. package/src/lib/types/annotation/unknown.ts +16 -0
  66. package/src/lib/types/bibliography.ts +86 -0
  67. package/src/lib/types/canon.ts +148 -0
  68. package/src/lib/types/client.ts +3 -0
  69. package/src/lib/types/contributor.ts +84 -0
  70. package/src/lib/types/editor-content.ts +21 -0
  71. package/src/lib/types/folio.ts +28 -0
  72. package/src/lib/types/glossary-page.ts +204 -0
  73. package/src/lib/types/glossary.ts +114 -0
  74. package/src/lib/types/imprint.ts +159 -0
  75. package/src/lib/types/index.ts +22 -0
  76. package/src/lib/types/language.ts +64 -0
  77. package/src/lib/types/layout.ts +37 -0
  78. package/src/lib/types/library.ts +29 -0
  79. package/src/lib/types/passage.ts +220 -0
  80. package/src/lib/types/project.ts +200 -0
  81. package/src/lib/types/semver.ts +1 -0
  82. package/src/lib/types/title.ts +47 -0
  83. package/src/lib/types/toh.ts +1 -0
  84. package/src/lib/types/translation.ts +15 -0
  85. package/src/lib/types/user.ts +15 -0
  86. package/src/lib/types/work.ts +38 -0
  87. package/src/lib/use-bookmark.ts +45 -0
  88. package/src/ssr.ts +5 -0
  89. package/tsconfig.json +20 -0
  90. package/tsconfig.lib.json +26 -0
  91. package/tsconfig.spec.json +22 -0
@@ -0,0 +1,43 @@
1
+ 'use server';
2
+
3
+ import { createServerClient } from './client-ssr';
4
+ import { TohokuCatalogEntry } from './types';
5
+ import { FolioDTO, folioFromDTO } from './types/folio';
6
+
7
+ export const getFolios = async ({
8
+ uuid,
9
+ toh,
10
+ page = 0,
11
+ size = 10,
12
+ }: {
13
+ uuid: string;
14
+ toh: TohokuCatalogEntry;
15
+ page?: number;
16
+ size?: number;
17
+ }) => {
18
+ const start = page * size;
19
+ const end = start + size - 1;
20
+ const client = await createServerClient();
21
+ const { data, error } = await client
22
+ .from('tibetan_works_folios')
23
+ .select(
24
+ `
25
+ folio_uuid,
26
+ content::text,
27
+ volume_number::int4,
28
+ folio_number::int4,
29
+ side::text`,
30
+ )
31
+ .eq('work_uuid', uuid)
32
+ .eq('toh', toh)
33
+ .order('folio_number', { ascending: true })
34
+ .order('side', { ascending: true })
35
+ .range(start, end);
36
+
37
+ if (error) {
38
+ console.error('Error fetching folios:', error);
39
+ return [];
40
+ }
41
+
42
+ return data.map((dto) => folioFromDTO(dto as FolioDTO));
43
+ };
@@ -0,0 +1,147 @@
1
+ import {
2
+ DataClient,
3
+ GlossaryDetailDTO,
4
+ GlossaryEntityDTO,
5
+ GlossaryInstanceDTO,
6
+ GlossaryTermInstanceDTO,
7
+ GlossaryLandingItem,
8
+ GlossaryLandingItemDTO,
9
+ glossaryTermInstanceFromDTO,
10
+ glossaryLandingItemFromDTO,
11
+ glossaryPageItemFromDTO,
12
+ GlossaryTermInstancesDTO,
13
+ } from './types';
14
+
15
+ export const getAllGlossaryTerms = async ({
16
+ client,
17
+ uuids,
18
+ }: {
19
+ client: DataClient;
20
+ uuids?: string[];
21
+ }): Promise<GlossaryLandingItem[]> => {
22
+ const pageSize = 1000;
23
+ let start = 0;
24
+ let end = pageSize - 1;
25
+ let count = pageSize;
26
+ const terms: GlossaryLandingItem[] = [];
27
+
28
+ while (count === pageSize) {
29
+ let rpc = client.rpc('scholar_glossary_get_all');
30
+
31
+ if (uuids?.length) {
32
+ rpc = rpc.in('authority_uuid', uuids);
33
+ }
34
+
35
+ const { data, error } = await rpc.range(start, end);
36
+
37
+ if (error) {
38
+ console.error('Error fetching glossary terms:', error);
39
+ return [];
40
+ }
41
+ if (!data || !data.length) {
42
+ break;
43
+ }
44
+
45
+ const dtos = data as GlossaryLandingItemDTO[];
46
+ const items = dtos
47
+ .map((item) => glossaryLandingItemFromDTO(item as GlossaryLandingItemDTO))
48
+ .flatMap((item) => (item ? [item] : []));
49
+
50
+ terms.push(...items);
51
+ start += pageSize;
52
+ end += pageSize;
53
+ count = data.length;
54
+ }
55
+
56
+ return terms;
57
+ };
58
+
59
+ export const getGlossaryInstances = async ({
60
+ client,
61
+ uuid,
62
+ withAttestations = false,
63
+ }: {
64
+ client: DataClient;
65
+ uuid: string;
66
+ withAttestations?: boolean;
67
+ }) => {
68
+ const { data, error } = await client.rpc('show_glossary_entries', {
69
+ v_work_uuid: uuid,
70
+ v_with_attestation: withAttestations,
71
+ });
72
+ if (error) {
73
+ console.error(
74
+ `Error fetching glossary instances for work: ${uuid} `,
75
+ error,
76
+ );
77
+ return [];
78
+ }
79
+
80
+ const dto = data as GlossaryTermInstancesDTO;
81
+ return dto.glossary_entries.map(glossaryTermInstanceFromDTO).sort((a, b) => {
82
+ const nameA = a.names.english || '';
83
+ const nameB = b.names.english || '';
84
+ return nameA.localeCompare(nameB);
85
+ });
86
+ };
87
+
88
+ export const getGlossaryInstance = async ({
89
+ client,
90
+ uuid,
91
+ }: {
92
+ client: DataClient;
93
+ uuid: string;
94
+ }) => {
95
+ const { data, error } = await client.rpc('show_glossary_entry', {
96
+ v_glossary_uuid: uuid,
97
+ });
98
+
99
+ if (error) {
100
+ console.error(`Error fetching glossary instance: ${uuid} `, error);
101
+ return undefined;
102
+ }
103
+
104
+ return glossaryTermInstanceFromDTO(data as GlossaryTermInstanceDTO);
105
+ };
106
+
107
+ export const getGlossaryEntry = async ({
108
+ client,
109
+ uuid,
110
+ }: {
111
+ client: DataClient;
112
+ uuid: string;
113
+ }) => {
114
+ const { data: details = [], error: detailError } = await client.rpc(
115
+ 'scholar_glossary_detail',
116
+ { v_uuid: uuid },
117
+ );
118
+
119
+ if (detailError || !details?.length) {
120
+ console.error('Error fetching glossary item:', detailError);
121
+ return null;
122
+ }
123
+
124
+ const detail = details[0];
125
+
126
+ const { data: entities = [], error: entitiesError } = await client.rpc(
127
+ 'scholar_glossary_detail_related_entities',
128
+ { v_uuid: uuid },
129
+ );
130
+ if (entitiesError) {
131
+ console.error('Error fetching related entities:', entitiesError);
132
+ }
133
+
134
+ const { data: glossaries = [], error: glossariesError } = await client.rpc(
135
+ 'scholar_glossary_detail_related_glossaries',
136
+ { v_uuid: uuid },
137
+ );
138
+ if (glossariesError) {
139
+ console.error('Error fetching related glossaries:', glossariesError);
140
+ }
141
+
142
+ return glossaryPageItemFromDTO(
143
+ detail as GlossaryDetailDTO,
144
+ glossaries as GlossaryInstanceDTO[],
145
+ entities as GlossaryEntityDTO[],
146
+ );
147
+ };
@@ -0,0 +1,42 @@
1
+ import { DataClient, imprintFromDTO, tocFromDTO } from './types';
2
+
3
+ export const getTranslationToc = async ({
4
+ client,
5
+ uuid,
6
+ }: {
7
+ client: DataClient;
8
+ uuid: string;
9
+ }) => {
10
+ const { data, error } = await client.rpc('get_work_toc', {
11
+ work_uuid_input: uuid,
12
+ });
13
+
14
+ if (error) {
15
+ console.error('Error fetching TOC:', error);
16
+ return undefined;
17
+ }
18
+
19
+ return tocFromDTO(data || []);
20
+ };
21
+
22
+ export const getTranslationImprint = async ({
23
+ client,
24
+ uuid,
25
+ toh,
26
+ }: {
27
+ client: DataClient;
28
+ uuid: string;
29
+ toh: string;
30
+ }) => {
31
+ const { data, error } = await client.rpc('get_imprint', {
32
+ work_uuid: uuid,
33
+ toh,
34
+ });
35
+
36
+ if (error || !data) {
37
+ console.error('Error fetching imprint:', error);
38
+ return undefined;
39
+ }
40
+
41
+ return imprintFromDTO(data);
42
+ };
@@ -0,0 +1,209 @@
1
+ import {
2
+ DataClient,
3
+ LibraryItemType,
4
+ UserLibraryItem,
5
+ UserPassageItem,
6
+ } from './types';
7
+
8
+ export const updateUserProfile = async ({
9
+ client,
10
+ userId,
11
+ avatar,
12
+ name,
13
+ username,
14
+ subscriptions,
15
+ }: {
16
+ client: DataClient;
17
+ userId: string;
18
+ subscriptions: string[];
19
+ avatar?: string;
20
+ name?: string;
21
+ username?: string;
22
+ }): Promise<boolean> => {
23
+ const { error } = await client
24
+ .from('user_profiles')
25
+ .update({
26
+ avatar_url: avatar,
27
+ full_name: name,
28
+ username: username,
29
+ subscriptions,
30
+ updated_at: new Date().toISOString(),
31
+ })
32
+ .eq('id', userId);
33
+
34
+ if (error) {
35
+ console.error('Error updating user subscriptions:', error);
36
+ return false;
37
+ }
38
+
39
+ return true;
40
+ };
41
+
42
+ export const getUserLibrary = async ({
43
+ client,
44
+ userId,
45
+ }: {
46
+ client: DataClient;
47
+ userId: string;
48
+ }): Promise<UserLibraryItem[]> => {
49
+ const { data, error } = await client
50
+ .from('user_libraries')
51
+ .select(
52
+ `
53
+ uuid:entity_id::uuid,
54
+ type:entity_type::text,
55
+ createdAt:created_at::text,
56
+ featured::bool
57
+ `,
58
+ )
59
+ .eq('user_id', userId);
60
+
61
+ if (error) {
62
+ console.error('Error fetching user library:', error);
63
+ return [];
64
+ }
65
+
66
+ return (data || []) as UserLibraryItem[];
67
+ };
68
+
69
+ export const addUserLibraryItem = async ({
70
+ client,
71
+ userId,
72
+ type,
73
+ entityId,
74
+ }: {
75
+ client: DataClient;
76
+ userId: string;
77
+ type: LibraryItemType;
78
+ entityId: string;
79
+ }): Promise<boolean> => {
80
+ const { error } = await client.from('user_libraries').insert({
81
+ user_id: userId,
82
+ entity_id: entityId,
83
+ entity_type: type,
84
+ featured: true,
85
+ });
86
+
87
+ if (error) {
88
+ console.error('Error adding to user library:', error);
89
+ return false;
90
+ }
91
+
92
+ return true;
93
+ };
94
+
95
+ export const removeUserLibraryItem = async ({
96
+ client,
97
+ entityId,
98
+ }: {
99
+ client: DataClient;
100
+ entityId: string;
101
+ }): Promise<boolean> => {
102
+ const { error } = await client
103
+ .from('user_libraries')
104
+ .delete()
105
+ .eq('entity_id', entityId);
106
+
107
+ if (error) {
108
+ console.error('Error removing from user library:', error);
109
+ return false;
110
+ }
111
+
112
+ return true;
113
+ };
114
+
115
+ export const getUserBibliographies = async ({
116
+ client,
117
+ uuids,
118
+ }: {
119
+ client: DataClient;
120
+ uuids: string[];
121
+ }) => {
122
+ const { data, error } = await client
123
+ .from('bibliographies')
124
+ .select(
125
+ `
126
+ uuid::text,
127
+ toh::text,
128
+ text:bibl_text::text
129
+ `,
130
+ )
131
+ .in('uuid', uuids);
132
+
133
+ if (error) {
134
+ console.error('Error fetching user bibliographies:', error);
135
+ return [];
136
+ }
137
+
138
+ return data || [];
139
+ };
140
+
141
+ export const getUserPassages = async ({
142
+ client,
143
+ uuids,
144
+ }: {
145
+ client: DataClient;
146
+ uuids: string[];
147
+ }) => {
148
+ const { data, error } = await client
149
+ .from('passages')
150
+ .select(
151
+ `
152
+ uuid::text,
153
+ content::text,
154
+ label::text,
155
+ work:works(
156
+ toh::text,
157
+ uuid::text
158
+ )
159
+ `,
160
+ )
161
+ .in('uuid', uuids);
162
+ if (error) {
163
+ console.error('Error fetching user passages:', error);
164
+ return [];
165
+ }
166
+
167
+ // NOTE: Supabase incorrectly infers `work` as an array. We have to jump
168
+ // though the hoop of casting to inknown first.
169
+ return (data || []) as unknown as UserPassageItem[];
170
+ };
171
+
172
+ export const getUserPublications = async ({
173
+ client,
174
+ uuids,
175
+ }: {
176
+ client: DataClient;
177
+ uuids: string[];
178
+ }) => {
179
+ const { data, error } = await client
180
+ .from('works')
181
+ .select(
182
+ `
183
+ uuid::text,
184
+ title::text,
185
+ toh::text,
186
+ titles(content::text,language::text),
187
+ sections:catalog_works(...catalogs(label::text))
188
+ `,
189
+ )
190
+ .like('titles.type', '%mainTitle')
191
+ .in('titles.language', ['bo', 'en'])
192
+ .in('uuid', uuids);
193
+
194
+ if (error) {
195
+ console.error('Error fetching user publications:', error);
196
+ return [];
197
+ }
198
+
199
+ return data || [];
200
+ };
201
+
202
+ export const getUserSearches = async (_: {
203
+ client: DataClient;
204
+ uuids: string[];
205
+ }) => {
206
+ // TODO: Support saving and retrieving user searches
207
+ console.warn('getUserSearches not implemented yet');
208
+ return [] as { uuid: string; name: string; query: string }[];
209
+ };
@@ -0,0 +1,33 @@
1
+ export type BookmarkItem = {
2
+ type: string;
3
+ subType?: string;
4
+ tab: string;
5
+ uuid: string;
6
+ };
7
+
8
+ const LIBRARY_KEY = 'library';
9
+
10
+ export function getBookmarks(): BookmarkItem[] {
11
+ try {
12
+ const raw = localStorage.getItem(LIBRARY_KEY);
13
+ if (!raw) return [];
14
+ return JSON.parse(raw) as BookmarkItem[];
15
+ } catch {
16
+ return [];
17
+ }
18
+ }
19
+
20
+ export function addBookmark(item: BookmarkItem): void {
21
+ const bookmarks = getBookmarks().filter((b) => b.uuid !== item.uuid);
22
+ bookmarks.push(item);
23
+ localStorage.setItem(LIBRARY_KEY, JSON.stringify(bookmarks));
24
+ }
25
+
26
+ export function removeBookmark(uuid: string): void {
27
+ const bookmarks = getBookmarks().filter((b) => b.uuid !== uuid);
28
+ localStorage.setItem(LIBRARY_KEY, JSON.stringify(bookmarks));
29
+ }
30
+
31
+ export function isBookmarked(uuid: string): boolean {
32
+ return getBookmarks().some((b) => b.uuid === uuid);
33
+ }
@@ -0,0 +1,122 @@
1
+ import { createServerClient } from './client-ssr';
2
+ import { getBibliographyEntry } from './bibliography';
3
+ import { getPassage, getPassageUuidByXmlId } from './passage';
4
+ import {
5
+ getTranslationMetadataByToh,
6
+ getTranslationMetadataByUuid,
7
+ } from './publications';
8
+ import { panelAndTabForContentType } from './panel-url';
9
+ import { getGlossaryInstance } from './glossary';
10
+
11
+ const ALLOWED_TYPES = ['bibliography', 'glossary', 'passage', 'translation', 'work'];
12
+
13
+ export const lookupEntity = async ({
14
+ type,
15
+ entity,
16
+ prefix = '',
17
+ xmlId,
18
+ searchParams,
19
+ }: {
20
+ type: string;
21
+ entity: string;
22
+ prefix?: string;
23
+ xmlId?: string;
24
+ searchParams?: URLSearchParams;
25
+ }) => {
26
+ if (!ALLOWED_TYPES.includes(type)) {
27
+ return;
28
+ }
29
+ const client = await createServerClient();
30
+ let path = '';
31
+ const query = searchParams || new URLSearchParams();
32
+
33
+ switch (type) {
34
+ case 'bibliography':
35
+ {
36
+ const item = await getBibliographyEntry({ client, uuid: entity });
37
+ if (!item?.workUuid || !item.uuid) {
38
+ return;
39
+ }
40
+
41
+ query.set('right', `open:bibliography:${item.uuid}`);
42
+ path = `${prefix}/${item.workUuid}?${query.toString()}`;
43
+ }
44
+ break;
45
+ case 'glossary':
46
+ {
47
+ const item = await getGlossaryInstance({ client, uuid: entity });
48
+ if (!item?.workUuid || !item.authority) {
49
+ return;
50
+ }
51
+
52
+ query.set('right', `open:glossary:${item.authority}`);
53
+ path = `${prefix}/${item.workUuid}?${query.toString()}`;
54
+ }
55
+ break;
56
+ case 'passage':
57
+ {
58
+ const item = await getPassage({ client, uuid: entity });
59
+ if (!item?.workUuid || !item.uuid) {
60
+ return;
61
+ }
62
+
63
+ const queryTab = query.get('tab') || undefined;
64
+ const { panel, tab } = panelAndTabForContentType(item.type, queryTab);
65
+
66
+ query.delete('tab');
67
+ query.set(panel, `open:${tab}:${item.uuid}`);
68
+ if (item.toh) {
69
+ query.set('toh', item.toh);
70
+ }
71
+
72
+ path = `${prefix}/${item.workUuid}?${query.toString()}`;
73
+ }
74
+ break;
75
+ case 'translation':
76
+ {
77
+ const toh = entity.replace('.html', '');
78
+ query.set('toh', toh);
79
+
80
+ if (xmlId) {
81
+ const item = await getPassageUuidByXmlId({ client, xmlId });
82
+ const queryTab = query.get('tab') || undefined;
83
+ const { panel, tab } = panelAndTabForContentType(item.type, queryTab);
84
+
85
+ if (item?.uuid && item?.workUuid) {
86
+ const { uuid, workUuid } = item;
87
+ query.delete('tab');
88
+ query.set(panel, `open:${tab}:${uuid}`);
89
+
90
+ path = `${prefix}/${workUuid}?${query.toString()}`;
91
+ return path;
92
+ }
93
+ }
94
+
95
+ const item = await getTranslationMetadataByToh({ client, toh });
96
+ if (!item?.uuid) {
97
+ return;
98
+ }
99
+
100
+ path = `${prefix}/${item.uuid}?${query.toString()}`;
101
+ }
102
+ break;
103
+ case 'work':
104
+ {
105
+ const item = await getTranslationMetadataByUuid({
106
+ client,
107
+ uuid: entity,
108
+ });
109
+ if (!item?.uuid) {
110
+ return;
111
+ }
112
+
113
+ path = `${prefix}/${item.uuid}?${query.toString()}`;
114
+ }
115
+ break;
116
+ default: {
117
+ return;
118
+ }
119
+ }
120
+
121
+ return path;
122
+ };
@@ -0,0 +1,43 @@
1
+ import {
2
+ PANEL_FOR_CONTENT_SECTION,
3
+ PanelContentType,
4
+ TAB_FOR_CONTENT_SECTION,
5
+ VARIANT_TABS_FOR_TAB,
6
+ } from './types';
7
+
8
+ export const panelAndTabForContentType = (
9
+ contentType: PanelContentType,
10
+ desiredTab?: string,
11
+ ): { panel: string; tab: string } => {
12
+ const section = contentType.replace('Header', '');
13
+ const panel = PANEL_FOR_CONTENT_SECTION[section] || 'main';
14
+ const defaultTab = TAB_FOR_CONTENT_SECTION[section] || 'translation';
15
+ const variantTabs = VARIANT_TABS_FOR_TAB[section] || [];
16
+ const tab =
17
+ desiredTab && variantTabs.includes(desiredTab) ? desiredTab : defaultTab;
18
+
19
+ return { panel, tab };
20
+ };
21
+
22
+ export const urlForPanelContent = ({
23
+ location,
24
+ hash,
25
+ contentType,
26
+ }: {
27
+ location: Location;
28
+ hash: string;
29
+ contentType?: PanelContentType;
30
+ }): string => {
31
+ const { href, search } = location;
32
+ const baseUrl = new URL(href);
33
+ const searchParams = new URLSearchParams(search);
34
+
35
+ if (!contentType) {
36
+ baseUrl.hash = `#${hash}`;
37
+ return baseUrl.toString();
38
+ }
39
+ const { panel, tab } = panelAndTabForContentType(contentType);
40
+ searchParams.set(panel, `open:${tab}:${hash}`);
41
+ baseUrl.search = searchParams.toString();
42
+ return baseUrl.toString();
43
+ };