@instructure/platform-modules 0.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/README.md +75 -0
- package/dist/adapters/canvasGraphql/index.d.ts +54 -0
- package/dist/adapters/canvasGraphql/index.d.ts.map +1 -0
- package/dist/adapters/canvasGraphql/normalize.d.ts +345 -0
- package/dist/adapters/canvasGraphql/normalize.d.ts.map +1 -0
- package/dist/adapters/canvasGraphql/queries.d.ts +69 -0
- package/dist/adapters/canvasGraphql/queries.d.ts.map +1 -0
- package/dist/adapters/inMemory.d.ts +63 -0
- package/dist/adapters/inMemory.d.ts.map +1 -0
- package/dist/adapters/index.d.ts +3 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/limits.d.ts +86 -0
- package/dist/adapters/limits.d.ts.map +1 -0
- package/dist/adapters/types.d.ts +87 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/cache/index.d.ts +3 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/invalidate.d.ts +52 -0
- package/dist/cache/invalidate.d.ts.map +1 -0
- package/dist/cache/keys.d.ts +86 -0
- package/dist/cache/keys.d.ts.map +1 -0
- package/dist/components/FilterChips.d.ts +19 -0
- package/dist/components/FilterChips.d.ts.map +1 -0
- package/dist/components/ModuleCard.d.ts +32 -0
- package/dist/components/ModuleCard.d.ts.map +1 -0
- package/dist/components/ModuleItemRow.d.ts +17 -0
- package/dist/components/ModuleItemRow.d.ts.map +1 -0
- package/dist/components/ModulesList.d.ts +69 -0
- package/dist/components/ModulesList.d.ts.map +1 -0
- package/dist/components/ModulesList.stories.d.ts +138 -0
- package/dist/components/ModulesList.stories.d.ts.map +1 -0
- package/dist/components/StatusPill.d.ts +18 -0
- package/dist/components/StatusPill.d.ts.map +1 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/labels.d.ts +89 -0
- package/dist/components/labels.d.ts.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/registry.d.ts +38 -0
- package/dist/config/registry.d.ts.map +1 -0
- package/dist/config/schemas.d.ts +16 -0
- package/dist/config/schemas.d.ts.map +1 -0
- package/dist/fixtures/generate.d.ts +48 -0
- package/dist/fixtures/generate.d.ts.map +1 -0
- package/dist/fixtures/index.d.ts +3 -0
- package/dist/fixtures/index.d.ts.map +1 -0
- package/dist/fixtures/scenarios.d.ts +42 -0
- package/dist/fixtures/scenarios.d.ts.map +1 -0
- package/dist/hooks/constants.d.ts +49 -0
- package/dist/hooks/constants.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/queryOptions.d.ts +58 -0
- package/dist/hooks/queryOptions.d.ts.map +1 -0
- package/dist/hooks/useItemsMode.d.ts +114 -0
- package/dist/hooks/useItemsMode.d.ts.map +1 -0
- package/dist/hooks/useModuleItemQueries.d.ts +56 -0
- package/dist/hooks/useModuleItemQueries.d.ts.map +1 -0
- package/dist/hooks/useModuleItems.d.ts +41 -0
- package/dist/hooks/useModuleItems.d.ts.map +1 -0
- package/dist/hooks/useModules.d.ts +50 -0
- package/dist/hooks/useModules.d.ts.map +1 -0
- package/dist/hooks/useModulesPageData.d.ts +78 -0
- package/dist/hooks/useModulesPageData.d.ts.map +1 -0
- package/dist/i18n.d.ts +92 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1966 -0
- package/dist/types/domain.d.ts +147 -0
- package/dist/types/domain.d.ts.map +1 -0
- package/dist/types/enums.d.ts +93 -0
- package/dist/types/enums.d.ts.map +1 -0
- package/dist/types/extensions.d.ts +48 -0
- package/dist/types/extensions.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/schemas.d.ts +38 -0
- package/dist/types/schemas.d.ts.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { TranslateFunction } from '../i18n';
|
|
3
|
+
import { ModuleItemStatus, ModuleStatus } from '../types';
|
|
4
|
+
/** Exhaustive: a new `ModuleStatus` is a compile error until it has a label. */
|
|
5
|
+
export declare function moduleStatusLabel(t: TranslateFunction, status: ModuleStatus): string;
|
|
6
|
+
/** @see moduleStatusLabel */
|
|
7
|
+
export declare function moduleItemStatusLabel(t: TranslateFunction, status: ModuleItemStatus): string;
|
|
8
|
+
export interface ModuleStatusPillProps {
|
|
9
|
+
status: ModuleStatus;
|
|
10
|
+
}
|
|
11
|
+
/** @see ModuleStatusPillProps */
|
|
12
|
+
export declare function ModuleStatusPill({ status }: ModuleStatusPillProps): ReactElement;
|
|
13
|
+
export interface ModuleItemStatusPillProps {
|
|
14
|
+
status: ModuleItemStatus;
|
|
15
|
+
}
|
|
16
|
+
/** @see ModuleItemStatusPillProps */
|
|
17
|
+
export declare function ModuleItemStatusPill({ status }: ModuleItemStatusPillProps): ReactElement;
|
|
18
|
+
//# sourceMappingURL=StatusPill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatusPill.d.ts","sourceRoot":"","sources":["../../src/components/StatusPill.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,EAAE,KAAK,iBAAiB,EAAkB,MAAM,SAAS,CAAA;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AA4C9D,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,iBAAiB,EAAE,MAAM,EAAE,YAAY,GAAG,MAAM,CAepF;AAED,6BAA6B;AAC7B,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,iBAAiB,EAAE,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAe5F;AAUD,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,YAAY,CAAA;CACrB;AAED,iCAAiC;AACjC,wBAAgB,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAAE,qBAAqB,GAAG,YAAY,CAOhF;AAED,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,gBAAgB,CAAA;CACzB;AAED,qCAAqC;AACrC,wBAAgB,oBAAoB,CAAC,EAAE,MAAM,EAAE,EAAE,yBAAyB,GAAG,YAAY,CAOxF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { FilterChips, type FilterChipsProps } from './FilterChips';
|
|
2
|
+
export { calendarDayDiff, DUE_THIS_WEEK_DAYS, filterLabel, formatDateTime, formatDueByline, formatModuleNumber, formatPoints, formatUnlockByline, itemTypeLabel, moduleMatchesFilter, moduleMatchesSearch, MODULES_FILTER_IDS, type ModulesFilterId, progressSummary, requirementLabel, } from './labels';
|
|
3
|
+
export { ModuleCard, type ModuleCardProps } from './ModuleCard';
|
|
4
|
+
export { ModuleItemRow, type ModuleItemRowProps } from './ModuleItemRow';
|
|
5
|
+
export { ModulesList, type ModulesListProps, type ModulesRequestCounts } from './ModulesList';
|
|
6
|
+
export { moduleItemStatusLabel, ModuleItemStatusPill, type ModuleItemStatusPillProps, moduleStatusLabel, ModuleStatusPill, type ModuleStatusPillProps, } from './StatusPill';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAClE,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,eAAe,EACpB,eAAe,EACf,gBAAgB,GACjB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAC7F,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,KAAK,yBAAyB,EAC9B,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { TranslateFunction } from '../i18n';
|
|
2
|
+
import { CompletionRequirement, Module, ModuleItemType } from '../types';
|
|
3
|
+
/** A locale-aware number formatter, cached. Exported so components share the cache. */
|
|
4
|
+
export declare function numberFormatterFor(locale?: string): Intl.NumberFormat;
|
|
5
|
+
/** Whole calendar days between two dates, ignoring the time of day. */
|
|
6
|
+
export declare function calendarDayDiff(a: Date, b: Date): number;
|
|
7
|
+
/**
|
|
8
|
+
* "today, 11:59 PM" / "yesterday, 11:59 PM" / "January 12, 11:59 PM".
|
|
9
|
+
*
|
|
10
|
+
* The relative words are separate keys rather than one string with a placeholder,
|
|
11
|
+
* because a language that puts the time first, or inflects "yesterday" by what
|
|
12
|
+
* follows it, needs to move the pieces independently.
|
|
13
|
+
*
|
|
14
|
+
* No timezone suffix. The domain model carries none and this package may not read
|
|
15
|
+
* one off the host, so printing one would be a guess — see `src/i18n.tsx`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatDateTime(t: TranslateFunction, iso: string, today: Date, locale?: string): string;
|
|
18
|
+
/** The module header byline when the module is open: "Due yesterday, 11:59 PM". */
|
|
19
|
+
export declare function formatDueByline(t: TranslateFunction, iso: string, today: Date, locale?: string): string;
|
|
20
|
+
/** The module header byline when the module is locked. */
|
|
21
|
+
export declare function formatUnlockByline(t: TranslateFunction, iso: string, today: Date, locale?: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* "01", "02", … "120". Two-digit minimum, matching the design's badge.
|
|
24
|
+
*
|
|
25
|
+
* Localised through `Intl.NumberFormat` rather than `String(n).padStart`, because
|
|
26
|
+
* the badge is a number and locales that use different digits should show theirs.
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatModuleNumber(position: number, locale?: string): string;
|
|
29
|
+
export declare function itemTypeLabel(t: TranslateFunction, type: ModuleItemType): string;
|
|
30
|
+
/** "10 pts". Null/undefined points render nothing at all, not "0 pts". */
|
|
31
|
+
export declare function formatPoints(t: TranslateFunction, pointsPossible: number | null | undefined, locale?: string): string | null;
|
|
32
|
+
/**
|
|
33
|
+
* The requirement column, e.g. "Submit the assignment".
|
|
34
|
+
*
|
|
35
|
+
* Exhaustive over `CompletionRequirementType` — no `default`, so adding a member
|
|
36
|
+
* to the enum is a compile error here rather than a silently unlabelled row. The
|
|
37
|
+
* `unknown` member is what absorbs a seventh Canvas type, and it still renders
|
|
38
|
+
* something: an unlabelled requirement would look like *no* requirement, which
|
|
39
|
+
* is the wrong failure.
|
|
40
|
+
*/
|
|
41
|
+
export declare function requirementLabel(t: TranslateFunction, requirement: CompletionRequirement, locale?: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* "75% | 3 of 4 requirements met", straight off the design.
|
|
44
|
+
*
|
|
45
|
+
* The `|` is baked into the translatable string, which is not ideal — a translator
|
|
46
|
+
* cannot tell it is a divider rather than punctuation, and a screen reader may
|
|
47
|
+
* either skip it or announce "vertical bar". Left as one key because splitting it
|
|
48
|
+
* changes the design's copy; flagged rather than quietly restructured.
|
|
49
|
+
*/
|
|
50
|
+
export declare function progressSummary(t: TranslateFunction, percentComplete: number, met: number, total: number, locale?: string): string;
|
|
51
|
+
export type ModulesFilterId = 'all' | 'in_progress' | 'complete' | 'due_this_week' | 'missing';
|
|
52
|
+
/**
|
|
53
|
+
* The chip order the design draws, as ids only.
|
|
54
|
+
*
|
|
55
|
+
* Ids rather than `{ id, label }` pairs because a label is now a function of the
|
|
56
|
+
* host's `t`, and a module-level constant cannot call one. `filterLabel` supplies
|
|
57
|
+
* the text.
|
|
58
|
+
*/
|
|
59
|
+
export declare const MODULES_FILTER_IDS: readonly ModulesFilterId[];
|
|
60
|
+
export declare function filterLabel(t: TranslateFunction, id: ModulesFilterId): string;
|
|
61
|
+
/** How far ahead "Due this week" looks. */
|
|
62
|
+
export declare const DUE_THIS_WEEK_DAYS = 7;
|
|
63
|
+
/**
|
|
64
|
+
* Filter chips are **module-level only**, by design.
|
|
65
|
+
*
|
|
66
|
+
* Every predicate reads `module.progress`, which the adapter returns with the
|
|
67
|
+
* module list. None of them touch items. That is deliberate: in `onDemand` mode
|
|
68
|
+
* the items of a collapsed module have not been fetched, so an item-level
|
|
69
|
+
* filter would either lie or cost one request per module. The designer's
|
|
70
|
+
* annotation says the filters describe the *module's* overall status, which is
|
|
71
|
+
* exactly the cheap version.
|
|
72
|
+
*
|
|
73
|
+
* A module with no `progress` (teacher/anonymous view) matches only "All" —
|
|
74
|
+
* "we did not fetch progress" is not the same as "not in progress".
|
|
75
|
+
*/
|
|
76
|
+
export declare function moduleMatchesFilter(module: Module, filter: ModulesFilterId, today: Date): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Search matches **module names only**, never item titles.
|
|
79
|
+
*
|
|
80
|
+
* Same reason as the filters: with `onDemand` pagination the items of collapsed
|
|
81
|
+
* modules are not in memory, so an item-level search would silently under-report
|
|
82
|
+
* — the one thing this package exists to prevent. The input is labelled
|
|
83
|
+
* "Search module names" so the limit is on screen rather than in a comment.
|
|
84
|
+
*
|
|
85
|
+
* `toLocaleLowerCase` rather than `toLowerCase`: the Turkish dotless i is the
|
|
86
|
+
* standard counterexample, and a course in Turkish should find its own modules.
|
|
87
|
+
*/
|
|
88
|
+
export declare function moduleMatchesSearch(module: Module, query: string, locale?: string): boolean;
|
|
89
|
+
//# sourceMappingURL=labels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labels.d.ts","sourceRoot":"","sources":["../../src/components/labels.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AA0D7E,uFAAuF;AACvF,wBAAgB,kBAAkB,CAAC,MAAM,GAAE,MAAuB,GAAG,IAAI,CAAC,YAAY,CAErF;AAeD,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,MAAM,CAIxD;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,CAAC,EAAE,iBAAiB,EACpB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,IAAI,EACX,MAAM,GAAE,MAAuB,GAC9B,MAAM,CAiBR;AAED,mFAAmF;AACnF,wBAAgB,eAAe,CAC7B,CAAC,EAAE,iBAAiB,EACpB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,IAAI,EACX,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAER;AAED,0DAA0D;AAC1D,wBAAgB,kBAAkB,CAChC,CAAC,EAAE,iBAAiB,EACpB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,IAAI,EACX,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAER;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,MAAuB,GAAG,MAAM,CAE5F;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,iBAAiB,EAAE,IAAI,EAAE,cAAc,GAAG,MAAM,CAmBhF;AAED,0EAA0E;AAC1E,wBAAgB,YAAY,CAC1B,CAAC,EAAE,iBAAiB,EACpB,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACzC,MAAM,GAAE,MAAuB,GAC9B,MAAM,GAAG,IAAI,CAGf;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,CAAC,EAAE,iBAAiB,EACpB,WAAW,EAAE,qBAAqB,EAClC,MAAM,GAAE,MAAuB,GAC9B,MAAM,CAuBR;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,CAAC,EAAE,iBAAiB,EACpB,eAAe,EAAE,MAAM,EACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAuB,GAC9B,MAAM,CAOR;AAID,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,aAAa,GAAG,UAAU,GAAG,eAAe,GAAG,SAAS,CAAA;AAE9F;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAAS,eAAe,EAMxD,CAAA;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,iBAAiB,EAAE,EAAE,EAAE,eAAe,GAAG,MAAM,CAa7E;AAED,2CAA2C;AAC3C,eAAO,MAAM,kBAAkB,IAAI,CAAA;AAEnC;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,CAqCjG;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAI3F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { RegistryEntry } from './schemas';
|
|
2
|
+
/**
|
|
3
|
+
* The registry primitive: merge one over another, then read the visible entries
|
|
4
|
+
* in a deterministic order. No React, no validation — the schemas in
|
|
5
|
+
* `./schemas` validate once, at config resolution.
|
|
6
|
+
*/
|
|
7
|
+
export type Registry<E extends RegistryEntry = RegistryEntry> = Record<string, E>;
|
|
8
|
+
/** `Partial<E>` because an overlay states only what it changes. An addition still needs a whole entry, which only the schema can enforce. */
|
|
9
|
+
export type RegistryOverride<E extends RegistryEntry = RegistryEntry> = Record<string, Partial<E>>;
|
|
10
|
+
export type VisibleEntry<E extends RegistryEntry = RegistryEntry> = E & {
|
|
11
|
+
key: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Fold an override over a base registry, one entry at a time:
|
|
15
|
+
* `{ ...base[key], ...override[key] }`. A key the base has is an overlay; a key
|
|
16
|
+
* it doesn't is an addition.
|
|
17
|
+
*
|
|
18
|
+
* Key order of the result is what `visibleEntries` breaks ties on: base keys in
|
|
19
|
+
* base order, then additions sorted by key so a host cannot change the rendered
|
|
20
|
+
* order by reordering its own literal.
|
|
21
|
+
*
|
|
22
|
+
* Copies every entry, so neither argument is mutated or shared. Built by spread
|
|
23
|
+
* rather than assignment, and keyed by own properties only, so an override
|
|
24
|
+
* parsed from host JSON cannot reach `Object.prototype` through a `__proto__`
|
|
25
|
+
* or `constructor` key.
|
|
26
|
+
*/
|
|
27
|
+
export declare function mergeRegistry<E extends RegistryEntry>(base: Registry<E>, override?: RegistryOverride<E>): Registry<E>;
|
|
28
|
+
/**
|
|
29
|
+
* The entries a host has left switched on, sorted by `order` ascending.
|
|
30
|
+
*
|
|
31
|
+
* Ties fall through to key order, per `mergeRegistry` above — `Array#sort` is
|
|
32
|
+
* stable by specification from ES2019.
|
|
33
|
+
*
|
|
34
|
+
* Filtering `hidden` here rather than at the merge is what lets a host inspect
|
|
35
|
+
* what it turned off.
|
|
36
|
+
*/
|
|
37
|
+
export declare function visibleEntries<E extends RegistryEntry>(registry: Registry<E>): ReadonlyArray<VisibleEntry<E>>;
|
|
38
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/config/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAE9C;;;;GAIG;AAEH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;AAEjF,6IAA6I;AAC7I,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AAElG,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,IAAI,CAAC,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAavF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,aAAa,EACnD,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EACjB,QAAQ,GAAE,gBAAgB,CAAC,CAAC,CAAM,GACjC,QAAQ,CAAC,CAAC,CAAC,CAYb;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,aAAa,EACpD,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GACpB,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAKhC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The shape every registry entry shares, schema first so the type is inferred
|
|
4
|
+
* from one list of fields — same inversion as `types/enums.ts`.
|
|
5
|
+
*
|
|
6
|
+
* Registries are validated at runtime rather than typed with generics, because
|
|
7
|
+
* a host may fetch one. See `docs/adr/0001-customization.md`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const RegistryEntrySchema: z.ZodObject<{
|
|
10
|
+
label: z.ZodString;
|
|
11
|
+
order: z.ZodNumber;
|
|
12
|
+
hidden: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
}>;
|
|
14
|
+
export type RegistryEntry = z.infer<typeof RegistryEntrySchema>;
|
|
15
|
+
export declare function registrySchema<E extends RegistryEntry>(entrySchema: z.ZodType<E>): z.ZodRecord<z.ZodString, z.ZodType<E>>;
|
|
16
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/config/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,SAAS,CAAC;IAC5C,KAAK,EAAE,CAAC,CAAC,SAAS,CAAA;IAClB,KAAK,EAAE,CAAC,CAAC,SAAS,CAAA;IAClB,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAA;CACpC,CASC,CAAA;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAE/D,wBAAgB,cAAc,CAAC,CAAC,SAAS,aAAa,EACpD,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GACxB,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAExC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { InMemoryFixture } from '../adapters/inMemory';
|
|
2
|
+
import { ModuleStatus } from '../types/domain';
|
|
3
|
+
/**
|
|
4
|
+
* The full `ModuleStatus` enum, one per module, cycled.
|
|
5
|
+
*
|
|
6
|
+
* Exported because it is also the reason `SMALL_MODULE_COUNT` is what it is:
|
|
7
|
+
* a fixture shorter than this cycle cannot show every state.
|
|
8
|
+
*/
|
|
9
|
+
export declare const MODULE_STATUS_CYCLE: readonly ModuleStatus[];
|
|
10
|
+
/** The course every fixture belongs to; only used to build plausible URLs. */
|
|
11
|
+
export declare const FIXTURE_COURSE_ID = "1";
|
|
12
|
+
/**
|
|
13
|
+
* Build a fixture from a per-module item count, e.g. `[8, 250, 8]` is three
|
|
14
|
+
* modules where the middle one is far past the inline limit.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Which audience the fixture describes.
|
|
18
|
+
*
|
|
19
|
+
* Not cosmetic: the two shapes are mutually exclusive in Canvas, and a fixture
|
|
20
|
+
* that mixes them describes a page no host can ever render.
|
|
21
|
+
*
|
|
22
|
+
* - `student` — everything is published, and every module carries a `progress`
|
|
23
|
+
* with every item a `status`. A student's module list contains no unpublished
|
|
24
|
+
* content at all; that is exactly why normalisation rule 2 reads a null
|
|
25
|
+
* `published` as `true` for a viewer without manage permission.
|
|
26
|
+
* - `teacher` — publish state varies, and nothing carries progress. Canvas
|
|
27
|
+
* resolves `progression` to null for a viewer with no progression record, so a
|
|
28
|
+
* teacher fixture with a `progress` would be describing a student.
|
|
29
|
+
*
|
|
30
|
+
* The bug this fixes: the generator used to emit unpublished modules *and*
|
|
31
|
+
* student progress on the same module, so `courseSmall`'s module 4 rendered as
|
|
32
|
+
* "(unpublished)" next to a progress bar — a combination that cannot occur.
|
|
33
|
+
*/
|
|
34
|
+
export type FixtureView = 'student' | 'teacher';
|
|
35
|
+
export interface BuildFixtureOptions {
|
|
36
|
+
/** Defaults to `student`. */
|
|
37
|
+
view?: FixtureView;
|
|
38
|
+
/**
|
|
39
|
+
* Which course the fixture is for. Defaults to `FIXTURE_COURSE_ID` ('1').
|
|
40
|
+
*
|
|
41
|
+
* Override it to prove a hook actually threads `courseId` through: with every
|
|
42
|
+
* fixture on course '1', a hook that hardcoded '1' internally would be
|
|
43
|
+
* indistinguishable from one that passed the caller's value.
|
|
44
|
+
*/
|
|
45
|
+
courseId?: string;
|
|
46
|
+
}
|
|
47
|
+
export declare function buildFixture(itemCounts: readonly number[], options?: BuildFixtureOptions): InMemoryFixture;
|
|
48
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/fixtures/generate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAQV,YAAY,EACb,MAAM,iBAAiB,CAAA;AA4DxB;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,YAAY,EAOtD,CAAA;AA0BD,8EAA8E;AAC9E,eAAO,MAAM,iBAAiB,MAAM,CAAA;AA2PpC;;;GAGG;AACH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,CAAA;AAE/C,MAAM,WAAW,mBAAmB;IAClC,6BAA6B;IAC7B,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAgBD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,OAAO,GAAE,mBAAwB,GAChC,eAAe,CAiBjB"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { buildFixture, type BuildFixtureOptions, FIXTURE_COURSE_ID, type FixtureView, MODULE_STATUS_CYCLE, } from './generate';
|
|
2
|
+
export { courseEmpty, courseFatModule, courseLarge, courseSmall, FAT_MODULE_ITEM_COUNT, FAT_MODULE_SIBLING_ITEM_COUNT, LARGE_ITEMS_PER_MODULE, LARGE_MODULE_COUNT, SMALL_ITEMS_PER_MODULE, SMALL_MODULE_COUNT, } from './scenarios';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fixtures/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,EACxB,iBAAiB,EACjB,KAAK,WAAW,EAChB,mBAAmB,GACpB,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,WAAW,EACX,eAAe,EACf,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,6BAA6B,EAC7B,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { InMemoryFixture } from '../adapters/inMemory';
|
|
2
|
+
/**
|
|
3
|
+
* Four named scales. Each one exists to make a specific failure impossible to
|
|
4
|
+
* ship silently, so they are sized against real Canvas limits rather than
|
|
5
|
+
* chosen for convenience.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 6 modules × 8 items. Inline mode resolves; the whole course in ~2 requests.
|
|
9
|
+
*
|
|
10
|
+
* The module count is `MODULE_STATUS_CYCLE.length` rather than a round number:
|
|
11
|
+
* this is the fixture a story reaches for by default, and at five modules it
|
|
12
|
+
* would silently omit one of the six `ModuleStatus` states.
|
|
13
|
+
*/
|
|
14
|
+
export declare const SMALL_MODULE_COUNT: number;
|
|
15
|
+
export declare const SMALL_ITEMS_PER_MODULE = 8;
|
|
16
|
+
/** 120 modules × 25 items. Past the 100-per-page module limit Career truncates at. */
|
|
17
|
+
export declare const LARGE_MODULE_COUNT = 120;
|
|
18
|
+
export declare const LARGE_ITEMS_PER_MODULE = 25;
|
|
19
|
+
/** 3 modules, the middle one 250 items — 2.5× `INLINE_ITEM_LIMIT`. */
|
|
20
|
+
export declare const FAT_MODULE_ITEM_COUNT = 250;
|
|
21
|
+
export declare const FAT_MODULE_SIBLING_ITEM_COUNT = 8;
|
|
22
|
+
/**
|
|
23
|
+
* The happy path: everything fits in one page of modules with items inlined,
|
|
24
|
+
* so a correct implementation renders the course in about two requests.
|
|
25
|
+
*/
|
|
26
|
+
export declare function courseSmall(): InMemoryFixture;
|
|
27
|
+
/**
|
|
28
|
+
* Module-list pagination past 100. Canvas caps `per_page` at 100, so a client
|
|
29
|
+
* that ignores the next cursor shows 100 of 120 modules and says nothing —
|
|
30
|
+
* which is what Canvas Career does today.
|
|
31
|
+
*/
|
|
32
|
+
export declare function courseLarge(): InMemoryFixture;
|
|
33
|
+
/**
|
|
34
|
+
* Item pagination past `INLINE_ITEM_LIMIT`. Canvas omits the `items` key
|
|
35
|
+
* entirely for the fat module, so the client must fall back to a per-module
|
|
36
|
+
* fetch and then page it. The "renders exactly 100 items and stops" bug lives
|
|
37
|
+
* here and cannot recur while this fixture is in the suite.
|
|
38
|
+
*/
|
|
39
|
+
export declare function courseFatModule(): InMemoryFixture;
|
|
40
|
+
/** No modules at all. The empty state exists before the designs specify it. */
|
|
41
|
+
export declare function courseEmpty(): InMemoryFixture;
|
|
42
|
+
//# sourceMappingURL=scenarios.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scenarios.d.ts","sourceRoot":"","sources":["../../src/fixtures/scenarios.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAG3D;;;;GAIG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAmC,CAAA;AACpE,eAAO,MAAM,sBAAsB,IAAI,CAAA;AAEvC,sFAAsF;AACtF,eAAO,MAAM,kBAAkB,MAAM,CAAA;AACrC,eAAO,MAAM,sBAAsB,KAAK,CAAA;AAExC,sEAAsE;AACtE,eAAO,MAAM,qBAAqB,MAAM,CAAA;AACxC,eAAO,MAAM,6BAA6B,IAAI,CAAA;AAE9C;;;GAGG;AACH,wBAAgB,WAAW,IAAI,eAAe,CAE7C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,eAAe,CAE7C;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,eAAe,CAMjD;AAED,+EAA+E;AAC/E,wBAAgB,WAAW,IAAI,eAAe,CAE7C"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { PageInfo } from '../types/domain';
|
|
2
|
+
/** Canvas's `Api::MAX_PER_PAGE`. One page of modules per request by default. */
|
|
3
|
+
export declare const DEFAULT_PAGE_SIZE: number;
|
|
4
|
+
/** Items are paged separately; same ceiling. */
|
|
5
|
+
export declare const DEFAULT_ITEM_PAGE_SIZE: number;
|
|
6
|
+
/**
|
|
7
|
+
* Per-module ceiling above which inlining stops being worthwhile.
|
|
8
|
+
*
|
|
9
|
+
* Matches `Api::MAX_PER_PAGE` and `INLINE_ITEM_LIMIT`. On REST that is Canvas's
|
|
10
|
+
* own rule — the `items` key is simply absent above it. On GraphQL it is this
|
|
11
|
+
* package's policy rather than a server constraint. @see INLINE_ITEM_LIMIT
|
|
12
|
+
*/
|
|
13
|
+
export declare const DEFAULT_INLINE_THRESHOLD: number;
|
|
14
|
+
/**
|
|
15
|
+
* How many per-module item requests may be in flight at once.
|
|
16
|
+
*
|
|
17
|
+
* Expanding "all modules" on a 40-module course should not open 40 sockets;
|
|
18
|
+
* browsers queue them anyway, but the server sees the whole burst.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_ITEM_CONCURRENCY: number;
|
|
21
|
+
/**
|
|
22
|
+
* Why this is not zero.
|
|
23
|
+
*
|
|
24
|
+
* With `staleTime: 0` every re-enable of a query — which is what re-expanding a
|
|
25
|
+
* module is — counts as stale and refetches. That is the behaviour this package
|
|
26
|
+
* exists to remove. Five minutes is long enough that expand/collapse within a
|
|
27
|
+
* sitting is free, short enough that coming back to the tab later is honest.
|
|
28
|
+
*/
|
|
29
|
+
export declare const DEFAULT_STALE_TIME_MS: number;
|
|
30
|
+
/**
|
|
31
|
+
* How many *collapsed* modules keep their item query subscribed.
|
|
32
|
+
*
|
|
33
|
+
* A collapsed module's observer is retained on purpose — that is what makes
|
|
34
|
+
* re-expanding a guaranteed cache hit rather than a lucky one. But retention has
|
|
35
|
+
* to stop somewhere: "Expand all" followed by "Collapse all" on a 120-module
|
|
36
|
+
* course would otherwise leave 120 subscriptions alive for the life of the page,
|
|
37
|
+
* each pinning its own pages of items past any `gcTime`.
|
|
38
|
+
*
|
|
39
|
+
* Twenty is chosen against the interaction rather than the data: a reader moving
|
|
40
|
+
* through a course revisits the handful of modules around where they are, and
|
|
41
|
+
* twenty covers that with room to spare while keeping the retained set a fixed
|
|
42
|
+
* cost instead of one that grows with course size. Above the cap the
|
|
43
|
+
* least-recently-active collapsed module is evicted, and re-expanding it may
|
|
44
|
+
* refetch.
|
|
45
|
+
*/
|
|
46
|
+
export declare const DEFAULT_RETAIN_COLLAPSED_LIMIT: number;
|
|
47
|
+
/** The pageInfo of a query that has not resolved yet. Never truncates silently. */
|
|
48
|
+
export declare const EMPTY_PAGE_INFO: PageInfo;
|
|
49
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/hooks/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAE/C,gFAAgF;AAChF,eAAO,MAAM,iBAAiB,EAAE,MAAY,CAAA;AAE5C,gDAAgD;AAChD,eAAO,MAAM,sBAAsB,EAAE,MAAY,CAAA;AAEjD;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAY,CAAA;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAU,CAAA;AAEjD;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAsB,CAAA;AAE1D;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,8BAA8B,EAAE,MAAW,CAAA;AAExD,mFAAmF;AACnF,eAAO,MAAM,eAAe,EAAE,QAAkD,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { DEFAULT_INLINE_THRESHOLD, DEFAULT_ITEM_CONCURRENCY, DEFAULT_ITEM_PAGE_SIZE, DEFAULT_PAGE_SIZE, DEFAULT_RETAIN_COLLAPSED_LIMIT, DEFAULT_STALE_TIME_MS, EMPTY_PAGE_INFO, } from './constants';
|
|
2
|
+
export { moduleItemsQueryOptions, modulesQueryOptions, type ModuleItemsQueryArgs, type ModuleItemsQueryOptions, type ModulesCursor, type ModulesQueryArgs, type ModulesQueryOptions, } from './queryOptions';
|
|
3
|
+
export { useModules, type UseModulesOptions, type UseModulesResult } from './useModules';
|
|
4
|
+
export { useModuleItems, type UseModuleItemsOptions, type UseModuleItemsResult, } from './useModuleItems';
|
|
5
|
+
export { resolveItemsMode, inlineShapeOf, type InlineQueryShape, useItemsMode, type ItemsMode, type ResolvedItemsMode, type UseItemsModeOptions, type UseItemsModeResult, } from './useItemsMode';
|
|
6
|
+
export { useModulesPageData, type ModuleItemsSource, type ModuleItemsState, type UseModulesPageDataOptions, type UseModulesPageDataResult, } from './useModulesPageData';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,iBAAiB,EACjB,8BAA8B,EAC9B,qBAAqB,EACrB,eAAe,GAChB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,GACzB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACxF,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,GAC1B,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,KAAK,gBAAgB,EACrB,YAAY,EACZ,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,GACxB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,GAC9B,MAAM,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { InfiniteData, InfiniteQueryObserverOptions } from '@tanstack/react-query';
|
|
2
|
+
import { LimitFunction } from 'p-limit';
|
|
3
|
+
import { ModulesDataAdapter } from '../adapters/types';
|
|
4
|
+
import { ModuleItemsKey, ModulesListKey, ModulesView } from '../cache/keys';
|
|
5
|
+
import { ModuleItemsPage, ModulesPage } from '../types/domain';
|
|
6
|
+
/**
|
|
7
|
+
* The two query definitions this package has, factored out of the hooks.
|
|
8
|
+
*
|
|
9
|
+
* They live here because the same definition is consumed two ways: through
|
|
10
|
+
* `useInfiniteQuery` (one module, one hook) and through a raw
|
|
11
|
+
* `InfiniteQueryObserver` (a dynamic set of expanded modules, which React's
|
|
12
|
+
* rules of hooks will not let you express as N `useInfiniteQuery` calls).
|
|
13
|
+
* Sharing the factory is what guarantees both paths land on the *same* cache
|
|
14
|
+
* entry, so a module fetched by one is a cache hit for the other.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The page cursor. `null` is the first page — the adapter contract forbids
|
|
18
|
+
* synthesising cursors, so this is only ever `null` or something a server said.
|
|
19
|
+
*/
|
|
20
|
+
export type ModulesCursor = string | null;
|
|
21
|
+
export type ModulesQueryOptions = InfiniteQueryObserverOptions<ModulesPage, Error, InfiniteData<ModulesPage, ModulesCursor>, ModulesListKey, ModulesCursor>;
|
|
22
|
+
export type ModuleItemsQueryOptions = InfiniteQueryObserverOptions<ModuleItemsPage, Error, InfiniteData<ModuleItemsPage, ModulesCursor>, ModuleItemsKey, ModulesCursor>;
|
|
23
|
+
export interface ModulesQueryArgs {
|
|
24
|
+
courseId: string;
|
|
25
|
+
adapter: ModulesDataAdapter;
|
|
26
|
+
pageSize: number;
|
|
27
|
+
includeItems: boolean;
|
|
28
|
+
/** Items to request per module when inlining. @see ListModulesArgs.inlineItemsFirst */
|
|
29
|
+
inlineItemsFirst?: number;
|
|
30
|
+
/** Modules to request when inlining. @see ListModulesArgs.inlineFirst */
|
|
31
|
+
inlineFirst?: number;
|
|
32
|
+
view?: ModulesView;
|
|
33
|
+
staleTime: number;
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface ModuleItemsQueryArgs {
|
|
37
|
+
courseId: string;
|
|
38
|
+
moduleId: string;
|
|
39
|
+
adapter: ModulesDataAdapter;
|
|
40
|
+
pageSize: number;
|
|
41
|
+
/**
|
|
42
|
+
* The audience this page is rendered for. Not sent to the adapter — a host
|
|
43
|
+
* configures its adapter for the current user — but it partitions the key,
|
|
44
|
+
* because `published` is a per-item field. See `ModuleItemsKeyOptions`.
|
|
45
|
+
*/
|
|
46
|
+
view?: ModulesView;
|
|
47
|
+
staleTime: number;
|
|
48
|
+
enabled: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Shared concurrency gate. Every expanded module's item fetch goes through
|
|
51
|
+
* the same limiter instance, so "expand all" is a trickle rather than a
|
|
52
|
+
* thundering herd.
|
|
53
|
+
*/
|
|
54
|
+
limit?: LimitFunction;
|
|
55
|
+
}
|
|
56
|
+
export declare function modulesQueryOptions(args: ModulesQueryArgs): ModulesQueryOptions;
|
|
57
|
+
export declare function moduleItemsQueryOptions(args: ModuleItemsQueryArgs): ModuleItemsQueryOptions;
|
|
58
|
+
//# sourceMappingURL=queryOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryOptions.d.ts","sourceRoot":"","sources":["../../src/hooks/queryOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAA;AACvF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,WAAW,EACjB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAEnE;;;;;;;;;GASG;AAEH;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,IAAI,CAAA;AAEzC,MAAM,MAAM,mBAAmB,GAAG,4BAA4B,CAC5D,WAAW,EACX,KAAK,EACL,YAAY,CAAC,WAAW,EAAE,aAAa,CAAC,EACxC,cAAc,EACd,aAAa,CACd,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG,4BAA4B,CAChE,eAAe,EACf,KAAK,EACL,YAAY,CAAC,eAAe,EAAE,aAAa,CAAC,EAC5C,cAAc,EACd,aAAa,CACd,CAAA;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,kBAAkB,CAAA;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,OAAO,CAAA;IACrB,uFAAuF;IACvF,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,kBAAkB,CAAA;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB;;;;OAIG;IACH,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAYD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,mBAAmB,CAmC/E;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,oBAAoB,GAAG,uBAAuB,CAyB3F"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { ModulesDataAdapter } from '../adapters/types';
|
|
2
|
+
import { ModulesView } from '../cache/keys';
|
|
3
|
+
import { ModulesPage } from '../types/domain';
|
|
4
|
+
/**
|
|
5
|
+
* How a course's module items get fetched.
|
|
6
|
+
*
|
|
7
|
+
* - `inline` — ask for items alongside the module list. One round trip for the
|
|
8
|
+
* whole page. Great for a small course, ruinous for a big one: the response
|
|
9
|
+
* grows with the number of items, and no module over `inlineThreshold` is
|
|
10
|
+
* inlined on either transport anyway (@see INLINE_ITEM_LIMIT).
|
|
11
|
+
* - `onDemand` — fetch a module's items when it is expanded. Constant-cost
|
|
12
|
+
* first paint, one extra request per module the user actually opens.
|
|
13
|
+
* - `auto` — probe, then pick. The default.
|
|
14
|
+
*/
|
|
15
|
+
export type ItemsMode = 'auto' | 'inline' | 'onDemand';
|
|
16
|
+
/** What `auto` collapses to. */
|
|
17
|
+
export type ResolvedItemsMode = 'inline' | 'onDemand';
|
|
18
|
+
export interface UseItemsModeOptions {
|
|
19
|
+
courseId: string;
|
|
20
|
+
adapter: ModulesDataAdapter;
|
|
21
|
+
mode?: ItemsMode;
|
|
22
|
+
/** Per-module ceiling for inlining. Defaults to 100. @see INLINE_ITEM_LIMIT */
|
|
23
|
+
inlineThreshold?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Ceiling on the implied request's node product.
|
|
26
|
+
*
|
|
27
|
+
* Defaults to what the adapter declares (`inlineNodeBudget`), then to
|
|
28
|
+
* `INLINE_QUERY_NODE_BUDGET`. Pass it only to override both.
|
|
29
|
+
*/
|
|
30
|
+
nodeBudget?: number;
|
|
31
|
+
pageSize?: number;
|
|
32
|
+
view?: ModulesView;
|
|
33
|
+
staleTime?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface UseItemsModeResult {
|
|
36
|
+
/** `null` while the `auto` probe is still in flight. */
|
|
37
|
+
resolvedMode: ResolvedItemsMode | null;
|
|
38
|
+
isResolving: boolean;
|
|
39
|
+
/** True when a probe request was actually needed — i.e. `mode` was `auto`. */
|
|
40
|
+
probed: boolean;
|
|
41
|
+
error: Error | null;
|
|
42
|
+
/**
|
|
43
|
+
* How many items to actually ask for per module when inlining, and how many
|
|
44
|
+
* modules to ask for — both measured from the probe rather than assumed.
|
|
45
|
+
*
|
|
46
|
+
* `null` when unknown (probe unresolved, or an explicit mode skipped it), in
|
|
47
|
+
* which case the adapter falls back to its own defaults.
|
|
48
|
+
*
|
|
49
|
+
* It exists because a transport can charge for the shape of the request rather
|
|
50
|
+
* than the size of the result, so asking for what the probe actually saw is
|
|
51
|
+
* what keeps an inline page deliverable. @see INLINE_QUERY_NODE_BUDGET
|
|
52
|
+
*/
|
|
53
|
+
inlineShape: InlineQueryShape | null;
|
|
54
|
+
}
|
|
55
|
+
/** What an inline `listModules` should request, measured from the probe. */
|
|
56
|
+
export interface InlineQueryShape {
|
|
57
|
+
/** Modules on page 1. */
|
|
58
|
+
moduleCount: number;
|
|
59
|
+
/** The largest `itemCount` among them. */
|
|
60
|
+
maxItemCount: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The policy itself, as a pure function over the probe's first page.
|
|
64
|
+
*
|
|
65
|
+
* Inline is chosen only when all three hold:
|
|
66
|
+
*
|
|
67
|
+
* 1. The first page is the whole list. If there is a second page of modules,
|
|
68
|
+
* the course total is unknown, and guessing from a partial view is how you
|
|
69
|
+
* end up inlining a 3000-item course. Conservative on purpose.
|
|
70
|
+
* 2. No single module exceeds `inlineThreshold`. Above it no adapter inlines
|
|
71
|
+
* the module — REST because Canvas drops the `items` key, GraphQL because
|
|
72
|
+
* this package declines to — so inlining buys nothing there and it would
|
|
73
|
+
* need an on-demand fetch regardless.
|
|
74
|
+
* 3. The course total is within `inlineThreshold * 2`. One module at the
|
|
75
|
+
* ceiling is fine; forty of them is a payload nobody asked for.
|
|
76
|
+
* 4. The implied request fits Canvas's complexity budget. Rules 1-3 bound the
|
|
77
|
+
* *data*; this one bounds the *query*, and they are not the same thing.
|
|
78
|
+
* @see INLINE_QUERY_NODE_BUDGET
|
|
79
|
+
*
|
|
80
|
+
* Exported so the policy can be unit-tested without React.
|
|
81
|
+
*/
|
|
82
|
+
export declare function resolveItemsMode(firstPage: ModulesPage, inlineThreshold: number, nodeBudget?: number): ResolvedItemsMode;
|
|
83
|
+
/**
|
|
84
|
+
* Resolves the items mode for a course.
|
|
85
|
+
*
|
|
86
|
+
* An explicit `mode` skips the probe entirely — the probe query is disabled, so
|
|
87
|
+
* it costs zero requests.
|
|
88
|
+
*
|
|
89
|
+
* For `auto`, the probe *is* the module list query with `includeItems: false`.
|
|
90
|
+
* That matters: if the probe resolves to `onDemand`, the page's own list query
|
|
91
|
+
* has the identical cache key and the probe becomes the first page for free. A
|
|
92
|
+
* second request happens only when the answer is `inline`, because inlined
|
|
93
|
+
* modules are a genuinely different payload and get their own key.
|
|
94
|
+
*
|
|
95
|
+
* Known cost of that shape, in the `auto -> inline` case only: the probe query
|
|
96
|
+
* stays mounted and enabled on its own key alongside the list query's, since
|
|
97
|
+
* `cache/keys.ts` partitions on `includeItems`. So `invalidateModuleList` refetches
|
|
98
|
+
* both where one would do, and a course that changes shape between refetches can
|
|
99
|
+
* flip the resolved mode mid-session. Neither is wrong, but neither is free —
|
|
100
|
+
* disabling the probe once it has answered would fix the first and make the second
|
|
101
|
+
* explicit.
|
|
102
|
+
*
|
|
103
|
+
* The decision is read from page 1 only, so paging further into the list can
|
|
104
|
+
* never flip the mode out from under a rendered page.
|
|
105
|
+
*/
|
|
106
|
+
export declare function useItemsMode(options: UseItemsModeOptions): UseItemsModeResult;
|
|
107
|
+
/**
|
|
108
|
+
* The smallest request that still returns the whole page inline.
|
|
109
|
+
*
|
|
110
|
+
* `maxItemCount` is at least 1 because `first: 0` is not a meaningful request,
|
|
111
|
+
* and a course of entirely empty modules should still round-trip.
|
|
112
|
+
*/
|
|
113
|
+
export declare function inlineShapeOf(firstPage: ModulesPage): InlineQueryShape;
|
|
114
|
+
//# sourceMappingURL=useItemsMode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useItemsMode.d.ts","sourceRoot":"","sources":["../../src/hooks/useItemsMode.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAIlD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAA;AAEtD,gCAAgC;AAChC,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,UAAU,CAAA;AAErD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,kBAAkB,CAAA;IAC3B,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,+EAA+E;IAC/E,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,wDAAwD;IACxD,YAAY,EAAE,iBAAiB,GAAG,IAAI,CAAA;IACtC,WAAW,EAAE,OAAO,CAAA;IACpB,8EAA8E;IAC9E,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB;;;;;;;;;;OAUG;IACH,WAAW,EAAE,gBAAgB,GAAG,IAAI,CAAA;CACrC;AAED,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAC/B,yBAAyB;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,0CAA0C;IAC1C,YAAY,EAAE,MAAM,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,WAAW,EACtB,eAAe,EAAE,MAAM,EACvB,UAAU,GAAE,MAAiC,GAC5C,iBAAiB,CAuBnB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,kBAAkB,CA6D7E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,WAAW,GAAG,gBAAgB,CAMtE"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { InfiniteData, InfiniteQueryObserverResult } from '@tanstack/react-query';
|
|
2
|
+
import { ModuleItemsPage } from '../types/domain';
|
|
3
|
+
import { ModuleItemsQueryOptions, ModulesCursor } from './queryOptions';
|
|
4
|
+
/**
|
|
5
|
+
* A dynamic set of module-item infinite queries.
|
|
6
|
+
*
|
|
7
|
+
* ## Why this is not N `useModuleItems` calls
|
|
8
|
+
*
|
|
9
|
+
* The number of expanded modules changes at runtime, and React's rules of hooks
|
|
10
|
+
* forbid a variable number of hook calls. `useQueries` would solve it for plain
|
|
11
|
+
* queries, but it builds `QueryObserver`s, not `InfiniteQueryObserver`s — there
|
|
12
|
+
* is no `useInfiniteQueries`. So this hook does what `useQueries` does
|
|
13
|
+
* internally: it owns a map of observers keyed by module id, subscribes to each,
|
|
14
|
+
* and republishes their results into React state.
|
|
15
|
+
*
|
|
16
|
+
* The observers are built from the same `moduleItemsQueryOptions` factory
|
|
17
|
+
* `useModuleItems` uses, so both paths hit the same cache entry.
|
|
18
|
+
*
|
|
19
|
+
* ## Why a collapsed module keeps its observer
|
|
20
|
+
*
|
|
21
|
+
* Collapsing flips a module's options to `enabled: false` and leaves the
|
|
22
|
+
* subscription in place, which pins the cache entry no matter how aggressive the
|
|
23
|
+
* host's `gcTime` is. Re-expanding is then a cache hit by construction rather
|
|
24
|
+
* than by luck.
|
|
25
|
+
*
|
|
26
|
+
* ## Why the retained set is nevertheless bounded
|
|
27
|
+
*
|
|
28
|
+
* "Bounded by the modules a user actually opened" is only reassuring while
|
|
29
|
+
* opening a module is a click. `ModulesList` has an "Expand all", which on the
|
|
30
|
+
* 120-module fixture would leave 120 subscribed `InfiniteQueryObserver`s alive
|
|
31
|
+
* for the life of the page — each pinning its own pages of items — even after
|
|
32
|
+
* the user collapsed the lot.
|
|
33
|
+
*
|
|
34
|
+
* So retention is capped at `retainCollapsedLimit` *collapsed* observers, evicted
|
|
35
|
+
* least-recently-active first. Active observers are never evicted, whatever the
|
|
36
|
+
* limit: they are the ones with something on screen. Eviction destroys the
|
|
37
|
+
* observer, which unpins its cache entry and lets the host's `gcTime` apply —
|
|
38
|
+
* meaning re-expanding an evicted module may refetch. That is the trade, and it
|
|
39
|
+
* is the right way round: a guaranteed cache hit on the last N modules touched
|
|
40
|
+
* beats an unbounded set of subscriptions.
|
|
41
|
+
*/
|
|
42
|
+
type ItemsData = InfiniteData<ModuleItemsPage, ModulesCursor>;
|
|
43
|
+
export type ModuleItemsObserverResult = InfiniteQueryObserverResult<ItemsData, Error>;
|
|
44
|
+
export interface ModuleItemQueries {
|
|
45
|
+
results: ReadonlyMap<string, ModuleItemsObserverResult>;
|
|
46
|
+
fetchNextPage: (moduleId: string) => void;
|
|
47
|
+
}
|
|
48
|
+
export declare function useModuleItemQueries(
|
|
49
|
+
/** Modules whose items should be fetching right now. */
|
|
50
|
+
activeModuleIds: readonly string[],
|
|
51
|
+
/** Must be referentially stable — memoise it in the caller. */
|
|
52
|
+
buildOptions: (moduleId: string, enabled: boolean) => ModuleItemsQueryOptions,
|
|
53
|
+
/** @see DEFAULT_RETAIN_COLLAPSED_LIMIT */
|
|
54
|
+
retainCollapsedLimit?: number): ModuleItemQueries;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=useModuleItemQueries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useModuleItemQueries.d.ts","sourceRoot":"","sources":["../../src/hooks/useModuleItemQueries.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,2BAA2B,EACjC,MAAM,uBAAuB,CAAA;AAG9B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD,OAAO,KAAK,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,KAAK,SAAS,GAAG,YAAY,CAAC,eAAe,EAAE,aAAa,CAAC,CAAA;AAE7D,MAAM,MAAM,yBAAyB,GAAG,2BAA2B,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;AAUrF,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAA;IACvD,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CAC1C;AAOD,wBAAgB,oBAAoB;AAClC,wDAAwD;AACxD,eAAe,EAAE,SAAS,MAAM,EAAE;AAClC,+DAA+D;AAC/D,YAAY,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,uBAAuB;AAC7E,0CAA0C;AAC1C,oBAAoB,GAAE,MAAuC,GAC5D,iBAAiB,CAoGnB"}
|