@behindthemusictree/app-kit 34.0.0 → 34.1.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.
- package/dist/{chunk-3PITD62C.js → chunk-QZXZHP4R.js} +84 -22
- package/dist/chunk-QZXZHP4R.js.map +1 -0
- package/dist/genre-tree/index.cjs +143 -79
- package/dist/genre-tree/index.cjs.map +1 -1
- package/dist/genre-tree/index.d.ts +11 -1
- package/dist/genre-tree/index.js +5 -1
- package/dist/index.cjs +140 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -1
- package/package.json +1 -1
- package/dist/chunk-3PITD62C.js.map +0 -1
|
@@ -964,6 +964,9 @@ function useArtistGenreCounts(artistUuid, getBackendBaseUrl) {
|
|
|
964
964
|
});
|
|
965
965
|
}
|
|
966
966
|
|
|
967
|
+
// src/genre-tree/useGenreSearch.ts
|
|
968
|
+
import { useDeferredValue, useMemo } from "react";
|
|
969
|
+
|
|
967
970
|
// src/genre-tree/lib/search-text.ts
|
|
968
971
|
var foldSearchText = (text) => text.normalize("NFD").replace(/\p{M}+/gu, "").toLowerCase().replace(/\s+/g, " ").trim();
|
|
969
972
|
var trigrams = (folded) => {
|
|
@@ -1009,9 +1012,54 @@ function rankByName(items, query, getName, getViews) {
|
|
|
1009
1012
|
);
|
|
1010
1013
|
return scored.map((entry) => entry.item);
|
|
1011
1014
|
}
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
+
function createNameIndex(items, getName, getViews) {
|
|
1016
|
+
return items.map((item) => {
|
|
1017
|
+
const name = foldSearchText(getName(item));
|
|
1018
|
+
return { item, name, grams: trigrams(name), views: getViews?.(item) ?? 0 };
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
function rankNameIndex(index, query, limit = Infinity) {
|
|
1022
|
+
if (limit !== Infinity && (!Number.isInteger(limit) || limit < 0)) {
|
|
1023
|
+
throw new RangeError("Search limit must be a nonnegative integer or Infinity");
|
|
1024
|
+
}
|
|
1025
|
+
const folded = foldSearchText(query);
|
|
1026
|
+
if (!folded || limit === 0) return [];
|
|
1027
|
+
const queryGrams = trigrams(folded);
|
|
1028
|
+
const scored = [];
|
|
1029
|
+
const compare = (a, b) => a.tier - b.tier || b.similarity - a.similarity || b.views - a.views || a.name.localeCompare(b.name);
|
|
1030
|
+
for (const entry of index) {
|
|
1031
|
+
let tier;
|
|
1032
|
+
let similarity = 0;
|
|
1033
|
+
if (entry.name === folded) tier = TIER_EXACT;
|
|
1034
|
+
else if (entry.name.startsWith(folded)) tier = TIER_PREFIX;
|
|
1035
|
+
else if (entry.name.includes(folded)) tier = TIER_SUBSTRING;
|
|
1036
|
+
else {
|
|
1037
|
+
let shared = 0;
|
|
1038
|
+
for (const gram of queryGrams) if (entry.grams.has(gram)) shared++;
|
|
1039
|
+
const union = entry.grams.size + queryGrams.size - shared;
|
|
1040
|
+
similarity = union === 0 ? 0 : shared / union;
|
|
1041
|
+
if (similarity < FUZZY_MIN_SIMILARITY) continue;
|
|
1042
|
+
tier = TIER_FUZZY;
|
|
1043
|
+
}
|
|
1044
|
+
const candidate = { ...entry, tier, similarity };
|
|
1045
|
+
if (limit === Infinity) scored.push(candidate);
|
|
1046
|
+
else {
|
|
1047
|
+
let low = 0;
|
|
1048
|
+
let high = scored.length;
|
|
1049
|
+
while (low < high) {
|
|
1050
|
+
const mid = low + high >>> 1;
|
|
1051
|
+
if (compare(candidate, scored[mid]) < 0) high = mid;
|
|
1052
|
+
else low = mid + 1;
|
|
1053
|
+
}
|
|
1054
|
+
if (low < limit) {
|
|
1055
|
+
scored.splice(low, 0, candidate);
|
|
1056
|
+
if (scored.length > limit) scored.pop();
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
if (limit === Infinity) scored.sort(compare);
|
|
1061
|
+
return scored.map((entry) => entry.item);
|
|
1062
|
+
}
|
|
1015
1063
|
|
|
1016
1064
|
// src/genre-tree/useSearchQueryState.ts
|
|
1017
1065
|
import { useState as useState2 } from "react";
|
|
@@ -1045,7 +1093,15 @@ function useGenreSearch({
|
|
|
1045
1093
|
onClear
|
|
1046
1094
|
}) {
|
|
1047
1095
|
const { query, setQuery, isTyping, canClear, clear, notifyPick } = useSearchQueryState({ selectedName, onClear });
|
|
1048
|
-
const
|
|
1096
|
+
const index = useMemo(
|
|
1097
|
+
() => createNameIndex(genrePlaylists, (playlist) => playlist.name, (playlist) => playlist.viewsCount ?? 0),
|
|
1098
|
+
[genrePlaylists]
|
|
1099
|
+
);
|
|
1100
|
+
const deferredQuery = useDeferredValue(query);
|
|
1101
|
+
const results = useMemo(
|
|
1102
|
+
() => isTyping ? rankNameIndex(index, deferredQuery) : [],
|
|
1103
|
+
[index, deferredQuery, isTyping]
|
|
1104
|
+
);
|
|
1049
1105
|
return {
|
|
1050
1106
|
query,
|
|
1051
1107
|
setQuery,
|
|
@@ -1104,6 +1160,7 @@ function useGenreRemoteSearch(getBackendBaseUrl, text, { treeName, limit = DEFAU
|
|
|
1104
1160
|
}
|
|
1105
1161
|
|
|
1106
1162
|
// src/genre-tree/useRegionGenreLexicon.ts
|
|
1163
|
+
var EMPTY_ENTRIES = [];
|
|
1107
1164
|
function useRegionGenreLexicon(getBackendBaseUrl, enabled) {
|
|
1108
1165
|
const { fetch } = useFetchWrapper(getBackendBaseUrl);
|
|
1109
1166
|
const { data, isError, isPending } = useQueryWithParse({
|
|
@@ -1114,15 +1171,15 @@ function useRegionGenreLexicon(getBackendBaseUrl, enabled) {
|
|
|
1114
1171
|
enabled,
|
|
1115
1172
|
staleTime: Infinity
|
|
1116
1173
|
});
|
|
1117
|
-
const entries = data ??
|
|
1174
|
+
const entries = data ?? EMPTY_ENTRIES;
|
|
1118
1175
|
return { entries, isError, isPending: enabled && isPending };
|
|
1119
1176
|
}
|
|
1120
1177
|
|
|
1121
1178
|
// src/genre-tree/useGenreTreeViewState.ts
|
|
1122
|
-
import { useCallback as useCallback2, useEffect as useEffect2, useMemo as
|
|
1179
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo3, useRef as useRef2, useState as useState3 } from "react";
|
|
1123
1180
|
|
|
1124
1181
|
// src/genre-tree/useVisibleGenrePlaylists.ts
|
|
1125
|
-
import { useMemo } from "react";
|
|
1182
|
+
import { useMemo as useMemo2 } from "react";
|
|
1126
1183
|
|
|
1127
1184
|
// src/genre-tree/lib/prune-genre-playlists-for-artist.ts
|
|
1128
1185
|
var POP_ROOT_NAME = "Mainstream Pop";
|
|
@@ -1164,7 +1221,7 @@ function useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid = null
|
|
|
1164
1221
|
const counts = useArtistGenreCounts(artistUuid, getBackendBaseUrl);
|
|
1165
1222
|
const artistCounts = artistUuid !== null ? counts.data : void 0;
|
|
1166
1223
|
const isCountsLoading = artistUuid !== null && (counts.isPending || counts.isPlaceholderData);
|
|
1167
|
-
const genrePlaylists =
|
|
1224
|
+
const genrePlaylists = useMemo2(() => {
|
|
1168
1225
|
if (!tree) return [];
|
|
1169
1226
|
return artistCounts ? pruneGenrePlaylistsForArtist(tree, artistCounts) : tree;
|
|
1170
1227
|
}, [tree, artistCounts]);
|
|
@@ -1205,8 +1262,8 @@ function useGenreTreeViewState({
|
|
|
1205
1262
|
[isSelectionControlled, onSelectedNodeIdChange]
|
|
1206
1263
|
);
|
|
1207
1264
|
const { isLoading, isFetching, genrePlaylists } = useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid });
|
|
1208
|
-
const genrePlaylistByNodeId =
|
|
1209
|
-
const selectedGenrePlaylist =
|
|
1265
|
+
const genrePlaylistByNodeId = useMemo3(() => new Map(genrePlaylists.map((gp) => [gp.uuid, gp])), [genrePlaylists]);
|
|
1266
|
+
const selectedGenrePlaylist = useMemo3(
|
|
1210
1267
|
() => genrePlaylists.find((gp) => gp.uuid === requestedSelectedNodeId) ?? // Older shared links stored the criteria UUID in `genre`; resolve that alias while preserving
|
|
1211
1268
|
// the playlist UUID as the canonical tree selection identity.
|
|
1212
1269
|
genrePlaylists.find((gp) => gp.criteria?.uuid === requestedSelectedNodeId),
|
|
@@ -1244,8 +1301,8 @@ function useGenreTreeViewState({
|
|
|
1244
1301
|
},
|
|
1245
1302
|
[genrePlaylistByNodeId, prefetchGenreOverview]
|
|
1246
1303
|
);
|
|
1247
|
-
const groupedGenrePlaylistsByRoot =
|
|
1248
|
-
const canShowPopCore =
|
|
1304
|
+
const groupedGenrePlaylistsByRoot = useMemo3(() => getGenrePlaylistsGroupedByRoot(genrePlaylists), [genrePlaylists]);
|
|
1305
|
+
const canShowPopCore = useMemo3(
|
|
1249
1306
|
() => hasMainstreamPopRoot(
|
|
1250
1307
|
genrePlaylists.map((genrePlaylist) => ({
|
|
1251
1308
|
parentId: genrePlaylist.parent?.uuid ?? null,
|
|
@@ -1261,7 +1318,7 @@ function useGenreTreeViewState({
|
|
|
1261
1318
|
}, [isLoading, canShowPopCore, internalViewMode]);
|
|
1262
1319
|
const selectedViewMode = controlledViewMode ?? internalViewMode;
|
|
1263
1320
|
const viewMode = needsPopCore(selectedViewMode) && !canShowPopCore ? "wheel" : selectedViewMode;
|
|
1264
|
-
const visibleGenrePlaylists =
|
|
1321
|
+
const visibleGenrePlaylists = useMemo3(() => {
|
|
1265
1322
|
if (viewMode === "stacked") return genrePlaylists;
|
|
1266
1323
|
const unacceptedRootUuids = new Set(genrePlaylists.filter((gp) => gp.isUnacceptedRoot).map((gp) => gp.uuid));
|
|
1267
1324
|
const accepted = genrePlaylists.filter((gp) => !gp.isUnacceptedRoot && !unacceptedRootUuids.has(gp.root.uuid));
|
|
@@ -1290,7 +1347,7 @@ function useGenreTreeViewState({
|
|
|
1290
1347
|
}
|
|
1291
1348
|
|
|
1292
1349
|
// src/genre-tree/TrackListContext.tsx
|
|
1293
|
-
import { createContext as createContext2, useState as useState5, useContext as useContext2, useCallback as useCallback4, useEffect as useEffect3, useMemo as
|
|
1350
|
+
import { createContext as createContext2, useState as useState5, useContext as useContext2, useCallback as useCallback4, useEffect as useEffect3, useMemo as useMemo5, useRef as useRef3 } from "react";
|
|
1294
1351
|
|
|
1295
1352
|
// src/genre-tree/schemas/track-playlist-rel/without-playlist.ts
|
|
1296
1353
|
import { z as z30 } from "zod";
|
|
@@ -1422,7 +1479,7 @@ var TrackListOriginFromGenreCatalogue = class extends TrackListOrigin {
|
|
|
1422
1479
|
};
|
|
1423
1480
|
|
|
1424
1481
|
// src/genre-tree/TrackListSidebarVisibilityContext.tsx
|
|
1425
|
-
import { createContext, useContext, useState as useState4, useCallback as useCallback3, useMemo as
|
|
1482
|
+
import { createContext, useContext, useState as useState4, useCallback as useCallback3, useMemo as useMemo4 } from "react";
|
|
1426
1483
|
import { jsx } from "react/jsx-runtime";
|
|
1427
1484
|
var TrackListSidebarVisibilityContext = createContext(void 0);
|
|
1428
1485
|
function TrackListSidebarVisibilityProvider({ children }) {
|
|
@@ -1436,7 +1493,7 @@ function TrackListSidebarVisibilityProvider({ children }) {
|
|
|
1436
1493
|
const hideTrackListSidebar = useCallback3(() => {
|
|
1437
1494
|
setIsTrackListSidebarVisible(false);
|
|
1438
1495
|
}, []);
|
|
1439
|
-
const value =
|
|
1496
|
+
const value = useMemo4(
|
|
1440
1497
|
() => ({
|
|
1441
1498
|
isTrackListSidebarVisible,
|
|
1442
1499
|
toggleTrackListSidebar,
|
|
@@ -1493,13 +1550,13 @@ function TrackListProvider({
|
|
|
1493
1550
|
const timer = setInterval(() => setFailureClock((tick) => tick + 1), 3e4);
|
|
1494
1551
|
return () => clearInterval(timer);
|
|
1495
1552
|
}, []);
|
|
1496
|
-
const runtimeUnplayableTrackIds =
|
|
1553
|
+
const runtimeUnplayableTrackIds = useMemo5(() => new Set(
|
|
1497
1554
|
(trackList?.tracks ?? []).filter((track) => isSong(track) && track.youtubeVideo && hasPlaybackFailure(track.youtubeVideo.id)).map((track) => track.uuid)
|
|
1498
1555
|
), [trackList, hasPlaybackFailure, playerTrackObject, failureClock]);
|
|
1499
1556
|
const { showTrackListSidebar } = useTrackListSidebarVisibility();
|
|
1500
1557
|
const playback = usePlaybackContext();
|
|
1501
1558
|
const { fetch } = useFetchWrapper(getBackendBaseUrl);
|
|
1502
|
-
const pageSchema =
|
|
1559
|
+
const pageSchema = useMemo5(() => makeTrackPlaylistRelPageSchema(schema), [schema]);
|
|
1503
1560
|
const latestPlayRequestRef = useRef3(0);
|
|
1504
1561
|
const startingPlaybackRef = useRef3(false);
|
|
1505
1562
|
const loadedContextRef = useRef3(playback.key);
|
|
@@ -1541,7 +1598,7 @@ function TrackListProvider({
|
|
|
1541
1598
|
},
|
|
1542
1599
|
[fetch, pageSchema]
|
|
1543
1600
|
);
|
|
1544
|
-
const cataloguePageSchema =
|
|
1601
|
+
const cataloguePageSchema = useMemo5(() => PaginatedResponseSchema(schema), [schema]);
|
|
1545
1602
|
const fetchCatalogueTracksPage = useCallback4(
|
|
1546
1603
|
async (origin, page) => {
|
|
1547
1604
|
const params = {
|
|
@@ -1866,7 +1923,7 @@ function TrackListProvider({
|
|
|
1866
1923
|
loadMore().catch((error) => console.error("Failed to load more tracks:", error));
|
|
1867
1924
|
}
|
|
1868
1925
|
}, [trackList, selectedTrack, loadMore]);
|
|
1869
|
-
const value =
|
|
1926
|
+
const value = useMemo5(
|
|
1870
1927
|
() => ({
|
|
1871
1928
|
trackList,
|
|
1872
1929
|
selectedTrack,
|
|
@@ -1977,6 +2034,9 @@ var capitalizeFirstLetter = (string) => {
|
|
|
1977
2034
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
1978
2035
|
};
|
|
1979
2036
|
|
|
2037
|
+
// src/genre-tree/lib/genre-search.ts
|
|
2038
|
+
var searchGenrePlaylistsByName = (genrePlaylists, query) => rankByName(genrePlaylists, query, (genrePlaylist) => genrePlaylist.name, (genrePlaylist) => genrePlaylist.viewsCount ?? 0);
|
|
2039
|
+
|
|
1980
2040
|
// src/genre-tree/lib/reparent-candidates.ts
|
|
1981
2041
|
var hasCriteria = (genrePlaylist) => genrePlaylist.criteria !== null;
|
|
1982
2042
|
var getReparentCandidates = (genrePlaylists, genrePlaylistUuid) => {
|
|
@@ -2096,7 +2156,8 @@ export {
|
|
|
2096
2156
|
trigramSimilarity,
|
|
2097
2157
|
FUZZY_MIN_SIMILARITY,
|
|
2098
2158
|
rankByName,
|
|
2099
|
-
|
|
2159
|
+
createNameIndex,
|
|
2160
|
+
rankNameIndex,
|
|
2100
2161
|
useSearchQueryState,
|
|
2101
2162
|
useGenreSearch,
|
|
2102
2163
|
GenreSearchTreeNameSchema,
|
|
@@ -2134,7 +2195,8 @@ export {
|
|
|
2134
2195
|
FORM_RATING_NULL_VALUE,
|
|
2135
2196
|
formatTime,
|
|
2136
2197
|
capitalizeFirstLetter,
|
|
2198
|
+
searchGenrePlaylistsByName,
|
|
2137
2199
|
getReparentCandidates,
|
|
2138
2200
|
editGenreSongPages
|
|
2139
2201
|
};
|
|
2140
|
-
//# sourceMappingURL=chunk-
|
|
2202
|
+
//# sourceMappingURL=chunk-QZXZHP4R.js.map
|