@torpor/ui 1.3.5 → 1.3.6
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/ComboBox/index.js +1 -1
- package/dist/DataGrid/DataGrid.torp +19 -1
- package/dist/SelectBox/index.js +1 -1
- package/dist/{loader-DEeG5vFY.js → loader-CBGbVpkN.js} +9 -2
- package/dist/{loader-DEeG5vFY.js.map → loader-CBGbVpkN.js.map} +1 -1
- package/dist/utils/loader.ts +20 -3
- package/package.json +5 -5
package/dist/ComboBox/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as normalizeLoadResult, t as createItemLoader } from "../loader-
|
|
1
|
+
import { n as normalizeLoadResult, t as createItemLoader } from "../loader-CBGbVpkN.js";
|
|
2
2
|
import ComboBox from "./ComboBox.torp";
|
|
3
3
|
import ComboBoxContent from "./ComboBoxContent.torp";
|
|
4
4
|
import ComboBoxInput from "./ComboBoxInput.torp";
|
|
@@ -228,6 +228,11 @@ export default function DataGrid($props: DataGridProps) {
|
|
|
228
228
|
// Incremented on every load; only the latest load's settle updates
|
|
229
229
|
// the pending flag
|
|
230
230
|
let loadGeneration = 0;
|
|
231
|
+
// The in-flight load's controller: starting a new load aborts it, so
|
|
232
|
+
// loaders that take the signal can cancel the wire request. Loaders that
|
|
233
|
+
// ignore it still work — the generation check discards stale results
|
|
234
|
+
// application-side either way.
|
|
235
|
+
let loadAbort: AbortController | null = null;
|
|
231
236
|
|
|
232
237
|
function runLoad(): Promise<LoadResult> {
|
|
233
238
|
const request: LoadRequest = {};
|
|
@@ -243,9 +248,22 @@ export default function DataGrid($props: DataGridProps) {
|
|
|
243
248
|
// only the latest load's settle clears the flag, so a reload that
|
|
244
249
|
// overtakes an older request doesn't drop the indicator early
|
|
245
250
|
const generation = ++loadGeneration;
|
|
251
|
+
loadAbort?.abort();
|
|
252
|
+
const controller = new AbortController();
|
|
253
|
+
loadAbort = controller;
|
|
246
254
|
$state.reloading = true;
|
|
247
255
|
$props.onloadstart?.();
|
|
248
|
-
const result = Promise.resolve(($props.load as Loader)(request))
|
|
256
|
+
const result = Promise.resolve(($props.load as Loader)(request, controller.signal))
|
|
257
|
+
.then(normalizeLoadResult)
|
|
258
|
+
.catch((error) => {
|
|
259
|
+
// Our own abort is not an error — the superseding load owns the
|
|
260
|
+
// UI, so this one never settles instead of rejecting into the
|
|
261
|
+
// error boundary
|
|
262
|
+
if (controller.signal.aborted) {
|
|
263
|
+
return new Promise<LoadResult>(() => {});
|
|
264
|
+
}
|
|
265
|
+
throw error;
|
|
266
|
+
});
|
|
249
267
|
// Report successful loads to the consumer; failures surface through
|
|
250
268
|
// the component's error boundary, not this notification chain
|
|
251
269
|
result.then(
|
package/dist/SelectBox/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as normalizeLoadResult, t as createItemLoader } from "../loader-
|
|
1
|
+
import { n as normalizeLoadResult, t as createItemLoader } from "../loader-CBGbVpkN.js";
|
|
2
2
|
import SelectBox from "./SelectBox.torp";
|
|
3
3
|
import SelectBoxContent from "./SelectBoxContent.torp";
|
|
4
4
|
import SelectBoxTrigger from "./SelectBoxTrigger.torp";
|
|
@@ -25,10 +25,17 @@ function normalizeLoadResult(result) {
|
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
function createItemLoader(options) {
|
|
28
|
+
let abort = null;
|
|
28
29
|
return $watch({
|
|
29
30
|
get result() {
|
|
30
31
|
return $async(() => {
|
|
31
|
-
|
|
32
|
+
abort?.abort();
|
|
33
|
+
const controller = new AbortController();
|
|
34
|
+
abort = controller;
|
|
35
|
+
const promise = Promise.resolve(options.load(options.getRequest(), controller.signal)).then(normalizeLoadResult).catch((error) => {
|
|
36
|
+
if (controller.signal.aborted) return new Promise(() => {});
|
|
37
|
+
throw error;
|
|
38
|
+
});
|
|
32
39
|
promise.then((r) => options.onload?.(r), () => {});
|
|
33
40
|
return promise;
|
|
34
41
|
});
|
|
@@ -41,4 +48,4 @@ function createItemLoader(options) {
|
|
|
41
48
|
//#endregion
|
|
42
49
|
export { normalizeLoadResult as n, createItemLoader as t };
|
|
43
50
|
|
|
44
|
-
//# sourceMappingURL=loader-
|
|
51
|
+
//# sourceMappingURL=loader-CBGbVpkN.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-
|
|
1
|
+
{"version":3,"file":"loader-CBGbVpkN.js","names":[],"sources":["../src/utils/loader.ts"],"sourcesContent":["import { $async, $watch } from \"@torpor/view\";\n\n/**\n * Shared contract for loading data from the network, used by components that\n * can take either static data or a loader function (DataGrid now, ComboBox\n * auto-complete and others later).\n *\n * A loader receives a request object describing what to fetch -- paging,\n * search text and sorting are standard; components extend it with their own\n * fields -- plus an AbortSignal so stale requests can be cancelled.\n */\n\n/** The base shape of a load request. Components extend this with their own fields. */\nexport interface LoadRequest {\n\t/** 1-based page number to load */\n\tpage?: number;\n\t/** Number of items per page */\n\tpageSize?: number;\n\t/** Search or filter text entered by the user */\n\tsearchText?: string;\n\t/** The field to sort by */\n\tsortBy?: string;\n\t/** The direction to sort in */\n\tsortDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * The result of a load: the items for the current request, and optionally\n * the total count (needed for paged components to show a pager).\n */\nexport interface LoadResult<T = any> {\n\titems: T[];\n\t/** The total number of items across all pages, if known */\n\ttotal?: number;\n}\n\n/**\n * Reads data for a request. May return a promise or a plain result, and may\n * return just an array of items when no total is available.\n */\nexport type Loader<T = any, TRequest extends LoadRequest = LoadRequest> = (\n\trequest: TRequest,\n\tsignal?: AbortSignal,\n) => Promise<LoadResult<T> | T[]> | LoadResult<T> | T[];\n\n/** Wraps a bare array in a LoadResult so consumers always get the same shape */\nexport function normalizeLoadResult<T>(result: LoadResult<T> | T[]): LoadResult<T> {\n\treturn Array.isArray(result) ? { items: result } : result;\n}\n\nexport interface ItemLoaderOptions<T = any, TRequest extends LoadRequest = LoadRequest> {\n\t/** The loader function to fetch items */\n\tload: Loader<T, TRequest>;\n\t/**\n\t * Builds the request for the current fetch. Called inside the async\n\t * getter, so reads of reactive state here re-fetch when they change.\n\t */\n\tgetRequest: () => TRequest;\n\t/** Called after each successful load with the normalized result */\n\tonload?: (result: LoadResult<T>) => void;\n}\n\n/** Reactive loading state returned by createItemLoader */\nexport interface ItemLoaderState<T = any> {\n\t/** The full result of the current load; suspends while a fetch is pending */\n\treadonly result: LoadResult<T> | undefined;\n\t/** The loaded items; suspends while a fetch is pending */\n\treadonly items: T[];\n}\n\n/**\n * Shared loading state for components that read items from a network loader\n * (DataGrid, ComboBox auto-complete etc). Read the returned state's `items`\n * or `result` inside an `@await` boundary: while a fetch is pending the read\n * suspends, and when dependencies read inside `getRequest` change the fetch\n * re-runs.\n *\n * For lazy loading (fetch only once some condition is met), gate the whole\n * rendering of the region that reads this loader behind that condition\n * (`@if`), so the `@await` boundary -- and with it the first fetch --\n * comes into existence when the condition flips.\n *\n * ```\n * let $load = createItemLoader({\n * \tload: $props.load,\n * \tgetRequest: () => ({ searchText: $state.searchText }),\n * });\n * @await { ...$load.items... } with { <span>Loading…</span> }\n * ```\n */\nexport function createItemLoader<T = any, TRequest extends LoadRequest = LoadRequest>(\n\toptions: ItemLoaderOptions<T, TRequest>,\n): ItemLoaderState<T> {\n\t// The in-flight fetch's controller: a re-run (search text changed, item\n\t// expanded) aborts it, so loaders that take the signal can cancel the\n\t// wire request. The $async generation guard discards stale results\n\t// application-side either way.\n\tlet abort: AbortController | null = null;\n\n\treturn $watch({\n\t\tget result(): LoadResult<T> | undefined {\n\t\t\treturn $async(() => {\n\t\t\t\tabort?.abort();\n\t\t\t\tconst controller = new AbortController();\n\t\t\t\tabort = controller;\n\t\t\t\tconst promise = Promise.resolve(options.load(options.getRequest(), controller.signal))\n\t\t\t\t\t.then(normalizeLoadResult)\n\t\t\t\t\t.catch((error) => {\n\t\t\t\t\t\t// Our own abort is not an error — the superseding fetch\n\t\t\t\t\t\t// owns the UI, so this one never settles instead of\n\t\t\t\t\t\t// rejecting into the await boundary\n\t\t\t\t\t\tif (controller.signal.aborted) {\n\t\t\t\t\t\t\treturn new Promise<LoadResult<T>>(() => {});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t});\n\t\t\t\t// Report successful loads to the consumer; failures surface\n\t\t\t\t// through the component's error boundary, not this chain\n\t\t\t\tpromise.then(\n\t\t\t\t\t(r) => options.onload?.(r),\n\t\t\t\t\t() => {},\n\t\t\t\t);\n\t\t\t\treturn promise as Promise<LoadResult<T>>;\n\t\t\t});\n\t\t},\n\t\tget items(): T[] {\n\t\t\treturn this.result?.items ?? [];\n\t\t},\n\t});\n}\n"],"mappings":";;;AA8CA,SAAgB,oBAAuB,QAA4C;CAClF,OAAO,MAAM,QAAQ,MAAM,IAAI,EAAE,OAAO,OAAO,IAAI;AACpD;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,iBACf,SACqB;CAKrB,IAAI,QAAgC;CAEpC,OAAO,OAAO;EACb,IAAI,SAAoC;GACvC,OAAO,aAAa;IACnB,OAAO,MAAM;IACb,MAAM,aAAa,IAAI,gBAAgB;IACvC,QAAQ;IACR,MAAM,UAAU,QAAQ,QAAQ,QAAQ,KAAK,QAAQ,WAAW,GAAG,WAAW,MAAM,CAAC,CAAC,CACpF,KAAK,mBAAmB,CAAC,CACzB,OAAO,UAAU;KAIjB,IAAI,WAAW,OAAO,SACrB,OAAO,IAAI,cAA6B,CAAC,CAAC;KAE3C,MAAM;IACP,CAAC;IAGF,QAAQ,MACN,MAAM,QAAQ,SAAS,CAAC,SACnB,CAAC,CACR;IACA,OAAO;GACR,CAAC;EACF;EACA,IAAI,QAAa;GAChB,OAAO,KAAK,QAAQ,SAAS,CAAC;EAC/B;CACD,CAAC;AACF"}
|
package/dist/utils/loader.ts
CHANGED
|
@@ -91,12 +91,29 @@ export interface ItemLoaderState<T = any> {
|
|
|
91
91
|
export function createItemLoader<T = any, TRequest extends LoadRequest = LoadRequest>(
|
|
92
92
|
options: ItemLoaderOptions<T, TRequest>,
|
|
93
93
|
): ItemLoaderState<T> {
|
|
94
|
+
// The in-flight fetch's controller: a re-run (search text changed, item
|
|
95
|
+
// expanded) aborts it, so loaders that take the signal can cancel the
|
|
96
|
+
// wire request. The $async generation guard discards stale results
|
|
97
|
+
// application-side either way.
|
|
98
|
+
let abort: AbortController | null = null;
|
|
99
|
+
|
|
94
100
|
return $watch({
|
|
95
101
|
get result(): LoadResult<T> | undefined {
|
|
96
102
|
return $async(() => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
abort?.abort();
|
|
104
|
+
const controller = new AbortController();
|
|
105
|
+
abort = controller;
|
|
106
|
+
const promise = Promise.resolve(options.load(options.getRequest(), controller.signal))
|
|
107
|
+
.then(normalizeLoadResult)
|
|
108
|
+
.catch((error) => {
|
|
109
|
+
// Our own abort is not an error — the superseding fetch
|
|
110
|
+
// owns the UI, so this one never settles instead of
|
|
111
|
+
// rejecting into the await boundary
|
|
112
|
+
if (controller.signal.aborted) {
|
|
113
|
+
return new Promise<LoadResult<T>>(() => {});
|
|
114
|
+
}
|
|
115
|
+
throw error;
|
|
116
|
+
});
|
|
100
117
|
// Report successful loads to the consumer; failures surface
|
|
101
118
|
// through the component's error boundary, not this chain
|
|
102
119
|
promise.then(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@torpor/ui",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "Accessible, unstyled components for use in your Torpor front-end",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"torpor": true,
|
|
@@ -181,15 +181,15 @@
|
|
|
181
181
|
"author": "",
|
|
182
182
|
"license": "ISC",
|
|
183
183
|
"dependencies": {
|
|
184
|
-
"@torpor/unplugin": "^1.2.
|
|
185
|
-
"@torpor/view": "^1.3.
|
|
184
|
+
"@torpor/unplugin": "^1.2.11",
|
|
185
|
+
"@torpor/view": "^1.3.1"
|
|
186
186
|
},
|
|
187
187
|
"devDependencies": {
|
|
188
188
|
"@testing-library/dom": "^10.4.2",
|
|
189
189
|
"@testing-library/jest-dom": "^7.0.1",
|
|
190
190
|
"@testing-library/user-event": "^14.6.8",
|
|
191
|
-
"@torpor/check": "^1.0.
|
|
192
|
-
"@torpor/prettier": "^1.0.
|
|
191
|
+
"@torpor/check": "^1.0.16",
|
|
192
|
+
"@torpor/prettier": "^1.0.16",
|
|
193
193
|
"@types/jsdom": "^30.0.0",
|
|
194
194
|
"@types/node": "^26.6.5",
|
|
195
195
|
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|