@jsudc/react 0.3.0 → 0.4.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 +561 -20
- package/dist/calendar/CalendarRenderer.js +1 -1
- package/dist/calendar/EventDetail.js +1 -1
- package/dist/calendar.js +1 -1
- package/dist/cards/CardRenderer.d.ts +2 -1
- package/dist/cards/CardRenderer.js +143 -109
- package/dist/cards/CardRenderer.js.map +1 -1
- package/dist/cells/registry.d.ts +60 -0
- package/dist/cells/registry.js +47 -0
- package/dist/cells/registry.js.map +1 -0
- package/dist/chart/ChartWindowControl.js +1 -1
- package/dist/components/ui/checkbox.js +1 -1
- package/dist/components/ui/dialog.js +4 -3
- package/dist/components/ui/dialog.js.map +1 -1
- package/dist/components/ui/dropdown-menu.js +2 -1
- package/dist/components/ui/dropdown-menu.js.map +1 -1
- package/dist/components/ui/popover.js +2 -1
- package/dist/components/ui/popover.js.map +1 -1
- package/dist/components/ui/select.js +2 -1
- package/dist/components/ui/select.js.map +1 -1
- package/dist/components/ui/toast.js +3 -2
- package/dist/components/ui/toast.js.map +1 -1
- package/dist/components/ui/tooltip.js +2 -1
- package/dist/components/ui/tooltip.js.map +1 -1
- package/dist/data-view/FilterBuilder.js +1 -1
- package/dist/data-view/FilterChips.js +1 -1
- package/dist/data-view/Freshness.js +1 -1
- package/dist/data-view/SearchBox.js +1 -1
- package/dist/data-view/UdcDataView.d.ts +83 -1
- package/dist/data-view/UdcDataView.js +171 -85
- package/dist/data-view/UdcDataView.js.map +1 -1
- package/dist/data-view/useDataViewState.d.ts +8 -0
- package/dist/data-view/useDataViewState.js +2 -1
- package/dist/data-view/useDataViewState.js.map +1 -1
- package/dist/headless.d.ts +3 -0
- package/dist/headless.js +5 -2
- package/dist/i18n/translations.js +8 -0
- package/dist/i18n/translations.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +7 -3
- package/dist/kanban/KanbanColumn.js +1 -1
- package/dist/kanban/KanbanRenderer.js +1 -1
- package/dist/kanban/model.d.ts +7 -0
- package/dist/kanban/model.js +19 -1
- package/dist/kanban/model.js.map +1 -1
- package/dist/kanban/useKanbanBoard.d.ts +5 -1
- package/dist/kanban/useKanbanBoard.js +6 -2
- package/dist/kanban/useKanbanBoard.js.map +1 -1
- package/dist/lib/scope.d.ts +8 -0
- package/dist/lib/scope.js +12 -0
- package/dist/lib/scope.js.map +1 -0
- package/dist/lookup/LookupCombobox.js +2 -2
- package/dist/lookup/LookupCombobox.js.map +1 -1
- package/dist/map/MapRenderer.js +1 -1
- package/dist/renderers/types.d.ts +12 -0
- package/dist/renderers/types.js.map +1 -1
- package/dist/rows/useRowActivation.d.ts +74 -0
- package/dist/rows/useRowActivation.js +225 -0
- package/dist/rows/useRowActivation.js.map +1 -0
- package/dist/schema-editor/DeleteFieldDialog.js +1 -1
- package/dist/schema-editor/FieldFormDialog.js +1 -1
- package/dist/schema-editor/TagInput.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.scoped.css +2 -0
- package/dist/table/CellEditor.js +1 -0
- package/dist/table/CellEditor.js.map +1 -1
- package/dist/table/TableRenderer.d.ts +2 -1
- package/dist/table/TableRenderer.js +41 -8
- package/dist/table/TableRenderer.js.map +1 -1
- package/dist/table/cells.d.ts +13 -2
- package/dist/table/cells.js +14 -1
- package/dist/table/cells.js.map +1 -1
- package/dist/table/states.d.ts +6 -0
- package/dist/table/states.js +14 -1
- package/dist/table/states.js.map +1 -1
- package/dist/tree/TreeNode.js +1 -1
- package/dist/tree/TreeRenderer.js +1 -1
- package/dist/udc/client.d.ts +15 -1
- package/dist/udc/client.js +31 -10
- package/dist/udc/client.js.map +1 -1
- package/dist/udc/hooks.d.ts +8 -3
- package/dist/udc/provider.d.ts +5 -2
- package/dist/udc/provider.js +6 -1
- package/dist/udc/provider.js.map +1 -1
- package/dist/ui-kit/ui.d.ts +1 -0
- package/dist/ui.js +2 -1
- package/dist/url-state/adapters.d.ts +23 -0
- package/dist/url-state/adapters.js +57 -0
- package/dist/url-state/adapters.js.map +1 -0
- package/dist/url-state/index.d.ts +1 -0
- package/package.json +6 -4
package/dist/udc/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":[],"sources":["../../src/udc/client.ts"],"sourcesContent":["import { isUdcError } from \"@jsudc/core\";\nimport type { UdcClient } from \"@jsudc/core/client\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { createContext, useContext } from \"react\";\n\n/** The client every hook talks to; `UdcProvider` sets it. */\nexport const UdcClientContext = createContext<UdcClient | null>(null);\n\nexport function useUdcClient(): UdcClient {\n const client = useContext(UdcClientContext);\n if (!client) throw new Error(\"useUdcClient needs a <UdcProvider client={...}> above it\");\n return client;\n}\n\n/**\n * A protocol error is the server's answer, not a hiccup: asking again gives\n * the same answer. Only transport failures are retried, twice.\n */\nexport function shouldRetry(failureCount: number, error: unknown): boolean {\n return !isUdcError(error) && failureCount < 2;\n}\n\nexport function createUdcQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: {\n queries: { retry: shouldRetry, refetchOnWindowFocus: false },\n mutations: { retry: false },\n },\n });\n}\n"],"mappings":";;;;;AAMA,IAAa,mBAAmB,cAAgC,IAAI;AAEpE,SAAgB,eAA0B;CACxC,MAAM,SAAS,WAAW,gBAAgB;CAC1C,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,0DAA0D;CACvF,OAAO;AACT;;;;;AAMA,SAAgB,YAAY,cAAsB,OAAyB;CACzE,OAAO,CAAC,WAAW,KAAK,KAAK,eAAe;AAC9C;AAEA,SAAgB,
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../../src/udc/client.ts"],"sourcesContent":["import { isUdcError, isUnauthenticated, type UdcError } from \"@jsudc/core\";\nimport type { UdcClient } from \"@jsudc/core/client\";\nimport { MutationCache, QueryCache, QueryClient } from \"@tanstack/react-query\";\nimport { createContext, useContext } from \"react\";\n\n/** The client every hook talks to; `UdcProvider` sets it. */\nexport const UdcClientContext = createContext<UdcClient | null>(null);\n\nexport function useUdcClient(): UdcClient {\n const client = useContext(UdcClientContext);\n if (!client) throw new Error(\"useUdcClient needs a <UdcProvider client={...}> above it\");\n return client;\n}\n\n/**\n * A protocol error is the server's answer, not a hiccup: asking again gives\n * the same answer. Only transport failures are retried, twice.\n */\nexport function shouldRetry(failureCount: number, error: unknown): boolean {\n return !isUdcError(error) && failureCount < 2;\n}\n\nexport interface UdcQueryClientOptions {\n /**\n * Called when a query or a mutation fails because the user is not signed in\n * (`isUnauthenticated`: an HTTP 401 in front of `/udc`, or the server's\n * in-protocol refusal) — the place to send the user to the host's login.\n * Once per burst: the failures that arrive together (every query of a page,\n * say) make one call; it fires again only after `unauthenticatedQuietMs`\n * without such a failure.\n */\n onUnauthenticated?: (error: UdcError) => void;\n /** The quiet time, in ms, that ends a burst of unauthenticated failures. Default 2000. */\n unauthenticatedQuietMs?: number;\n}\n\n/**\n * Calls `fn` on the first unauthenticated error and swallows the rest until\n * `quietMs` pass without one (each further error restarts that wait).\n */\nfunction unauthenticatedNotifier(\n fn: (error: UdcError) => void,\n quietMs: number,\n): (error: unknown) => void {\n let lastAt: number | null = null;\n return (error) => {\n if (!isUnauthenticated(error)) return;\n const now = Date.now();\n const inBurst = lastAt !== null && now - lastAt < quietMs;\n lastAt = now;\n if (!inBurst) fn(error as UdcError);\n };\n}\n\nexport function createUdcQueryClient(options: UdcQueryClientOptions = {}): QueryClient {\n const notify = options.onUnauthenticated\n ? unauthenticatedNotifier(options.onUnauthenticated, options.unauthenticatedQuietMs ?? 2000)\n : undefined;\n return new QueryClient({\n ...(notify\n ? {\n queryCache: new QueryCache({ onError: notify }),\n mutationCache: new MutationCache({ onError: notify }),\n }\n : {}),\n defaultOptions: {\n queries: { retry: shouldRetry, refetchOnWindowFocus: false },\n mutations: { retry: false },\n },\n });\n}\n"],"mappings":";;;;;AAMA,IAAa,mBAAmB,cAAgC,IAAI;AAEpE,SAAgB,eAA0B;CACxC,MAAM,SAAS,WAAW,gBAAgB;CAC1C,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,0DAA0D;CACvF,OAAO;AACT;;;;;AAMA,SAAgB,YAAY,cAAsB,OAAyB;CACzE,OAAO,CAAC,WAAW,KAAK,KAAK,eAAe;AAC9C;;;;;AAoBA,SAAS,wBACP,IACA,SAC0B;CAC1B,IAAI,SAAwB;CAC5B,QAAQ,UAAU;EAChB,IAAI,CAAC,kBAAkB,KAAK,GAAG;EAC/B,MAAM,MAAM,KAAK,IAAI;EACrB,MAAM,UAAU,WAAW,QAAQ,MAAM,SAAS;EAClD,SAAS;EACT,IAAI,CAAC,SAAS,GAAG,KAAiB;CACpC;AACF;AAEA,SAAgB,qBAAqB,UAAiC,CAAC,GAAgB;CACrF,MAAM,SAAS,QAAQ,oBACnB,wBAAwB,QAAQ,mBAAmB,QAAQ,0BAA0B,GAAI,IACzF,KAAA;CACJ,OAAO,IAAI,YAAY;EACrB,GAAI,SACA;GACE,YAAY,IAAI,WAAW,EAAE,SAAS,OAAO,CAAC;GAC9C,eAAe,IAAI,cAAc,EAAE,SAAS,OAAO,CAAC;EACtD,IACA,CAAC;EACL,gBAAgB;GACd,SAAS;IAAE,OAAO;IAAa,sBAAsB;GAAM;GAC3D,WAAW,EAAE,OAAO,MAAM;EAC5B;CACF,CAAC;AACH"}
|
package/dist/udc/hooks.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare function useUdcCollections(): import("@tanstack/react-query").Use
|
|
|
20
20
|
supported_filter_ops: ("eq" | "neq" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | "gt" | "gte" | "lt" | "lte" | "between" | "is_null" | "is_not_null")[];
|
|
21
21
|
paging?: ("cursor" | "offset")[] | undefined;
|
|
22
22
|
};
|
|
23
|
-
source_kind: "postgres_jsonb" | "memory" | "filesystem" | "http_api" | "yaml_menu";
|
|
23
|
+
source_kind: "postgres_jsonb" | "memory" | "filesystem" | "http_api" | "yaml_menu" | "postgres_table";
|
|
24
24
|
label?: string | undefined;
|
|
25
25
|
group?: "database" | "files" | "internet" | undefined;
|
|
26
26
|
}[];
|
|
@@ -42,7 +42,7 @@ export declare function useUdcDescribe(collection: string, opts?: {
|
|
|
42
42
|
supported_filter_ops: ("eq" | "neq" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | "gt" | "gte" | "lt" | "lte" | "between" | "is_null" | "is_not_null")[];
|
|
43
43
|
paging?: ("cursor" | "offset")[] | undefined;
|
|
44
44
|
};
|
|
45
|
-
source_kind: "postgres_jsonb" | "memory" | "filesystem" | "http_api" | "yaml_menu";
|
|
45
|
+
source_kind: "postgres_jsonb" | "memory" | "filesystem" | "http_api" | "yaml_menu" | "postgres_table";
|
|
46
46
|
schema: {
|
|
47
47
|
field_order: string[];
|
|
48
48
|
version: string;
|
|
@@ -278,7 +278,12 @@ export declare function useUdcDescribe(collection: string, opts?: {
|
|
|
278
278
|
icon_size: number;
|
|
279
279
|
radius_field?: string | undefined;
|
|
280
280
|
popup_fields?: string[] | undefined;
|
|
281
|
-
center
|
|
281
|
+
center
|
|
282
|
+
/**
|
|
283
|
+
* The three schema edits. Each answers the new schema; `describe` (which
|
|
284
|
+
* derives the columns) and the lists are refetched afterwards.
|
|
285
|
+
*/
|
|
286
|
+
?: [number, number] | undefined;
|
|
282
287
|
regions?: {
|
|
283
288
|
[x: string]: unknown;
|
|
284
289
|
id: string;
|
package/dist/udc/provider.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { UdcClient } from "@jsudc/core/client";
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
|
+
import { type CellRegistry } from "../cells/registry.js";
|
|
3
4
|
import { type UdcLinks } from "../lookup/links.js";
|
|
4
5
|
import type { RendererRegistry } from "../renderers/types.js";
|
|
5
6
|
import type { UiKit } from "../ui-kit/types.js";
|
|
6
|
-
export { createUdcQueryClient, shouldRetry, useUdcClient } from "./client.js";
|
|
7
|
+
export { createUdcQueryClient, shouldRetry, type UdcQueryClientOptions, useUdcClient, } from "./client.js";
|
|
7
8
|
/**
|
|
8
9
|
* The root provider: the client, the renderers `UdcDataView` draws its tabs
|
|
9
10
|
* with, and optionally the UI kit they draw with. Without `kit` the kit in
|
|
@@ -11,7 +12,7 @@ export { createUdcQueryClient, shouldRetry, useUdcClient } from "./client.js";
|
|
|
11
12
|
* `renderers` the outer `UdcRenderersProvider`'s registry is kept (else none:
|
|
12
13
|
* every tab says no renderer is registered).
|
|
13
14
|
*/
|
|
14
|
-
export declare function UdcProvider({ client, kit, renderers, links, children, }: {
|
|
15
|
+
export declare function UdcProvider({ client, kit, renderers, links, cells, children, }: {
|
|
15
16
|
client: UdcClient;
|
|
16
17
|
/**
|
|
17
18
|
* Where a lookup link and a `row_link` go: the address of a collection's
|
|
@@ -22,5 +23,7 @@ export declare function UdcProvider({ client, kit, renderers, links, children, }
|
|
|
22
23
|
kit?: UiKit;
|
|
23
24
|
/** `createRendererRegistry(tableRenderer, …)`, or `RENDERERS` from `@jsudc/react/all`. */
|
|
24
25
|
renderers?: RendererRegistry;
|
|
26
|
+
/** `createCellRegistry(...)`: the cell components a column's `render` may name (README "Custom cells"). */
|
|
27
|
+
cells?: CellRegistry;
|
|
25
28
|
children: ReactNode;
|
|
26
29
|
}): import("react").JSX.Element;
|
package/dist/udc/provider.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UdcCellsProvider } from "../cells/registry.js";
|
|
1
2
|
import { UdcLinksProvider } from "../lookup/links.js";
|
|
2
3
|
import { UdcRenderersProvider } from "../renderers/context.js";
|
|
3
4
|
import { UdcUiProvider } from "../ui-kit/context.js";
|
|
@@ -11,7 +12,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
11
12
|
* `renderers` the outer `UdcRenderersProvider`'s registry is kept (else none:
|
|
12
13
|
* every tab says no renderer is registered).
|
|
13
14
|
*/
|
|
14
|
-
function UdcProvider({ client, kit, renderers, links, children }) {
|
|
15
|
+
function UdcProvider({ client, kit, renderers, links, cells, children }) {
|
|
15
16
|
let inner = /* @__PURE__ */ jsx(UdcClientContext.Provider, {
|
|
16
17
|
value: client,
|
|
17
18
|
children
|
|
@@ -20,6 +21,10 @@ function UdcProvider({ client, kit, renderers, links, children }) {
|
|
|
20
21
|
links,
|
|
21
22
|
children: inner
|
|
22
23
|
});
|
|
24
|
+
if (cells) inner = /* @__PURE__ */ jsx(UdcCellsProvider, {
|
|
25
|
+
cells,
|
|
26
|
+
children: inner
|
|
27
|
+
});
|
|
23
28
|
if (renderers) inner = /* @__PURE__ */ jsx(UdcRenderersProvider, {
|
|
24
29
|
renderers,
|
|
25
30
|
children: inner
|
package/dist/udc/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","names":[],"sources":["../../src/udc/provider.tsx"],"sourcesContent":["import type { UdcClient } from \"@jsudc/core/client\";\nimport type { ReactNode } from \"react\";\nimport { type UdcLinks, UdcLinksProvider } from \"../lookup/links.js\";\nimport { UdcRenderersProvider } from \"../renderers/context.js\";\nimport type { RendererRegistry } from \"../renderers/types.js\";\nimport { UdcUiProvider } from \"../ui-kit/context.js\";\nimport type { UiKit } from \"../ui-kit/types.js\";\nimport { UdcClientContext } from \"./client.js\";\n\nexport {
|
|
1
|
+
{"version":3,"file":"provider.js","names":[],"sources":["../../src/udc/provider.tsx"],"sourcesContent":["import type { UdcClient } from \"@jsudc/core/client\";\nimport type { ReactNode } from \"react\";\nimport { type CellRegistry, UdcCellsProvider } from \"../cells/registry.js\";\nimport { type UdcLinks, UdcLinksProvider } from \"../lookup/links.js\";\nimport { UdcRenderersProvider } from \"../renderers/context.js\";\nimport type { RendererRegistry } from \"../renderers/types.js\";\nimport { UdcUiProvider } from \"../ui-kit/context.js\";\nimport type { UiKit } from \"../ui-kit/types.js\";\nimport { UdcClientContext } from \"./client.js\";\n\nexport {\n createUdcQueryClient,\n shouldRetry,\n type UdcQueryClientOptions,\n useUdcClient,\n} from \"./client.js\";\n\n/**\n * The root provider: the client, the renderers `UdcDataView` draws its tabs\n * with, and optionally the UI kit they draw with. Without `kit` the kit in\n * effect is kept (an outer `UdcUiProvider`'s, else `defaultUiKit`); without\n * `renderers` the outer `UdcRenderersProvider`'s registry is kept (else none:\n * every tab says no renderer is registered).\n */\nexport function UdcProvider({\n client,\n kit,\n renderers,\n links,\n cells,\n children,\n}: {\n client: UdcClient;\n /**\n * Where a lookup link and a `row_link` go: the address of a collection's\n * view, and how to navigate there. Default `defaultUdcLinks` (`/c/<name>`);\n * `UdcReactRouterUrlState collectionPath` sets it for react-router.\n */\n links?: UdcLinks;\n kit?: UiKit;\n /** `createRendererRegistry(tableRenderer, …)`, or `RENDERERS` from `@jsudc/react/all`. */\n renderers?: RendererRegistry;\n /** `createCellRegistry(...)`: the cell components a column's `render` may name (README \"Custom cells\"). */\n cells?: CellRegistry;\n children: ReactNode;\n}) {\n let inner = <UdcClientContext.Provider value={client}>{children}</UdcClientContext.Provider>;\n if (links) inner = <UdcLinksProvider links={links}>{inner}</UdcLinksProvider>;\n if (cells) inner = <UdcCellsProvider cells={cells}>{inner}</UdcCellsProvider>;\n if (renderers) inner = <UdcRenderersProvider renderers={renderers}>{inner}</UdcRenderersProvider>;\n return kit ? <UdcUiProvider kit={kit}>{inner}</UdcUiProvider> : inner;\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,SAAgB,YAAY,EAC1B,QACA,KACA,WACA,OACA,OACA,YAeC;CACD,IAAI,QAAQ,oBAAC,iBAAiB,UAAlB;EAA2B,OAAO;EAAS;CAAoC,CAAA;CAC3F,IAAI,OAAO,QAAQ,oBAAC,kBAAD;EAAyB;EAAQ,UAAA;CAAwB,CAAA;CAC5E,IAAI,OAAO,QAAQ,oBAAC,kBAAD;EAAyB;EAAQ,UAAA;CAAwB,CAAA;CAC5E,IAAI,WAAW,QAAQ,oBAAC,sBAAD;EAAiC;EAAY,UAAA;CAA4B,CAAA;CAChG,OAAO,MAAM,oBAAC,eAAD;EAAoB;EAAM,UAAA;CAAqB,CAAA,IAAI;AAClE"}
|
package/dist/ui-kit/ui.d.ts
CHANGED
|
@@ -9,4 +9,5 @@ export { Segmented, type SegmentedOption } from "../components/ui/segmented.js";
|
|
|
9
9
|
export { Select, type SelectOption } from "../components/ui/select.js";
|
|
10
10
|
export { Toaster, type ToastInput, type ToastVariant, useToast } from "../components/ui/toast.js";
|
|
11
11
|
export { Tip, TooltipProvider } from "../components/ui/tooltip.js";
|
|
12
|
+
export { UDC_SCOPE_CLASS } from "../lib/scope.js";
|
|
12
13
|
export { defaultUiKit } from "./default.js";
|
package/dist/ui.js
CHANGED
|
@@ -9,5 +9,6 @@ import { Segmented } from "./components/ui/segmented.js";
|
|
|
9
9
|
import { Select } from "./components/ui/select.js";
|
|
10
10
|
import { Toaster, useToast } from "./components/ui/toast.js";
|
|
11
11
|
import { Tip, TooltipProvider } from "./components/ui/tooltip.js";
|
|
12
|
+
import { UDC_SCOPE_CLASS } from "./lib/scope.js";
|
|
12
13
|
import { defaultUiKit } from "./ui-kit/default.js";
|
|
13
|
-
export { Button, Checkbox, Dialog, DialogBody, DialogClose, DialogContent, DialogFooter, DialogTrigger, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, Input, Kbd, NativeSelect, Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, Segmented, Select, Skeleton, Spinner, Tip, Toaster, TooltipProvider, defaultUiKit, inputClass, useToast };
|
|
14
|
+
export { Button, Checkbox, Dialog, DialogBody, DialogClose, DialogContent, DialogFooter, DialogTrigger, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, Input, Kbd, NativeSelect, Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, Segmented, Select, Skeleton, Spinner, Tip, Toaster, TooltipProvider, UDC_SCOPE_CLASS, defaultUiKit, inputClass, useToast };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { UrlStateAdapter } from "./adapter.js";
|
|
2
|
+
/**
|
|
3
|
+
* `inner`, seen through a key prefix: `get()` returns only the parameters whose
|
|
4
|
+
* name starts with `prefix`, with the prefix taken off, and `set()` rewrites
|
|
5
|
+
* only those, leaving every other parameter of `inner` as it was. A data view
|
|
6
|
+
* under it reads and writes `inbox.q`, `inbox.sort`, `inbox.board`, … while a
|
|
7
|
+
* host's own `?q=` is neither read nor removed, and a second view with another
|
|
8
|
+
* prefix keeps state of its own on the same page. End the prefix with a
|
|
9
|
+
* separator (`inbox.`, `list-`): every key that starts with it is the view's.
|
|
10
|
+
*/
|
|
11
|
+
export declare function prefixUrlStateAdapter(inner: UrlStateAdapter, prefix: string): UrlStateAdapter;
|
|
12
|
+
/** A `UrlStateAdapter` that keeps the query string in memory, plus a way to inspect it. */
|
|
13
|
+
export interface MemoryUrlStateAdapter extends UrlStateAdapter {
|
|
14
|
+
/** Every `set` so far, oldest first: what a push or a replace wrote (for tests and debugging). */
|
|
15
|
+
readonly history: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A query string that lives in memory only: the address bar is never read nor
|
|
19
|
+
* written, and back / forward do not touch it. For a view whose state should
|
|
20
|
+
* not survive a reload or be shared as a link (one pane of a host's screen).
|
|
21
|
+
* Each call is a store of its own; `initial` seeds it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createMemoryUrlStateAdapter(initial?: string | URLSearchParams | Record<string, string>): MemoryUrlStateAdapter;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/url-state/adapters.ts
|
|
2
|
+
/**
|
|
3
|
+
* `inner`, seen through a key prefix: `get()` returns only the parameters whose
|
|
4
|
+
* name starts with `prefix`, with the prefix taken off, and `set()` rewrites
|
|
5
|
+
* only those, leaving every other parameter of `inner` as it was. A data view
|
|
6
|
+
* under it reads and writes `inbox.q`, `inbox.sort`, `inbox.board`, … while a
|
|
7
|
+
* host's own `?q=` is neither read nor removed, and a second view with another
|
|
8
|
+
* prefix keeps state of its own on the same page. End the prefix with a
|
|
9
|
+
* separator (`inbox.`, `list-`): every key that starts with it is the view's.
|
|
10
|
+
*/
|
|
11
|
+
function prefixUrlStateAdapter(inner, prefix) {
|
|
12
|
+
if (!prefix) throw new Error("prefixUrlStateAdapter: the prefix must not be empty");
|
|
13
|
+
const own = (key) => key.startsWith(prefix);
|
|
14
|
+
return {
|
|
15
|
+
get() {
|
|
16
|
+
const out = new URLSearchParams();
|
|
17
|
+
for (const [key, value] of inner.get()) if (own(key)) out.append(key.slice(prefix.length), value);
|
|
18
|
+
return out;
|
|
19
|
+
},
|
|
20
|
+
set(next, opts) {
|
|
21
|
+
const out = new URLSearchParams();
|
|
22
|
+
for (const [key, value] of inner.get()) if (!own(key)) out.append(key, value);
|
|
23
|
+
for (const [key, value] of next) out.append(`${prefix}${key}`, value);
|
|
24
|
+
inner.set(out, opts);
|
|
25
|
+
},
|
|
26
|
+
subscribe: (listener) => inner.subscribe(listener)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A query string that lives in memory only: the address bar is never read nor
|
|
31
|
+
* written, and back / forward do not touch it. For a view whose state should
|
|
32
|
+
* not survive a reload or be shared as a link (one pane of a host's screen).
|
|
33
|
+
* Each call is a store of its own; `initial` seeds it.
|
|
34
|
+
*/
|
|
35
|
+
function createMemoryUrlStateAdapter(initial) {
|
|
36
|
+
let search = new URLSearchParams(initial ?? "").toString();
|
|
37
|
+
const history = [];
|
|
38
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
39
|
+
return {
|
|
40
|
+
get: () => new URLSearchParams(search),
|
|
41
|
+
set(next) {
|
|
42
|
+
search = next.toString();
|
|
43
|
+
history.push(search);
|
|
44
|
+
for (const listener of listeners) listener();
|
|
45
|
+
},
|
|
46
|
+
subscribe(listener) {
|
|
47
|
+
listeners.add(listener);
|
|
48
|
+
return () => {
|
|
49
|
+
listeners.delete(listener);
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
history
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export { createMemoryUrlStateAdapter, prefixUrlStateAdapter };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=adapters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.js","names":[],"sources":["../../src/url-state/adapters.ts"],"sourcesContent":["import type { UrlStateAdapter } from \"./adapter.js\";\n\n/**\n * `inner`, seen through a key prefix: `get()` returns only the parameters whose\n * name starts with `prefix`, with the prefix taken off, and `set()` rewrites\n * only those, leaving every other parameter of `inner` as it was. A data view\n * under it reads and writes `inbox.q`, `inbox.sort`, `inbox.board`, … while a\n * host's own `?q=` is neither read nor removed, and a second view with another\n * prefix keeps state of its own on the same page. End the prefix with a\n * separator (`inbox.`, `list-`): every key that starts with it is the view's.\n */\nexport function prefixUrlStateAdapter(inner: UrlStateAdapter, prefix: string): UrlStateAdapter {\n if (!prefix) throw new Error(\"prefixUrlStateAdapter: the prefix must not be empty\");\n const own = (key: string) => key.startsWith(prefix);\n return {\n get() {\n const out = new URLSearchParams();\n for (const [key, value] of inner.get()) {\n if (own(key)) out.append(key.slice(prefix.length), value);\n }\n return out;\n },\n set(next, opts) {\n const out = new URLSearchParams();\n for (const [key, value] of inner.get()) if (!own(key)) out.append(key, value);\n for (const [key, value] of next) out.append(`${prefix}${key}`, value);\n inner.set(out, opts);\n },\n subscribe: (listener) => inner.subscribe(listener),\n };\n}\n\n/** A `UrlStateAdapter` that keeps the query string in memory, plus a way to inspect it. */\nexport interface MemoryUrlStateAdapter extends UrlStateAdapter {\n /** Every `set` so far, oldest first: what a push or a replace wrote (for tests and debugging). */\n readonly history: readonly string[];\n}\n\n/**\n * A query string that lives in memory only: the address bar is never read nor\n * written, and back / forward do not touch it. For a view whose state should\n * not survive a reload or be shared as a link (one pane of a host's screen).\n * Each call is a store of its own; `initial` seeds it.\n */\nexport function createMemoryUrlStateAdapter(\n initial?: string | URLSearchParams | Record<string, string>,\n): MemoryUrlStateAdapter {\n let search = new URLSearchParams(initial ?? \"\").toString();\n const history: string[] = [];\n const listeners = new Set<() => void>();\n return {\n get: () => new URLSearchParams(search),\n set(next) {\n search = next.toString();\n history.push(search);\n for (const listener of listeners) listener();\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n history,\n };\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,sBAAsB,OAAwB,QAAiC;CAC7F,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,qDAAqD;CAClF,MAAM,OAAO,QAAgB,IAAI,WAAW,MAAM;CAClD,OAAO;EACL,MAAM;GACJ,MAAM,MAAM,IAAI,gBAAgB;GAChC,KAAK,MAAM,CAAC,KAAK,UAAU,MAAM,IAAI,GACnC,IAAI,IAAI,GAAG,GAAG,IAAI,OAAO,IAAI,MAAM,OAAO,MAAM,GAAG,KAAK;GAE1D,OAAO;EACT;EACA,IAAI,MAAM,MAAM;GACd,MAAM,MAAM,IAAI,gBAAgB;GAChC,KAAK,MAAM,CAAC,KAAK,UAAU,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,IAAI,OAAO,KAAK,KAAK;GAC5E,KAAK,MAAM,CAAC,KAAK,UAAU,MAAM,IAAI,OAAO,GAAG,SAAS,OAAO,KAAK;GACpE,MAAM,IAAI,KAAK,IAAI;EACrB;EACA,YAAY,aAAa,MAAM,UAAU,QAAQ;CACnD;AACF;;;;;;;AAcA,SAAgB,4BACd,SACuB;CACvB,IAAI,SAAS,IAAI,gBAAgB,WAAW,EAAE,CAAC,CAAC,SAAS;CACzD,MAAM,UAAoB,CAAC;CAC3B,MAAM,4BAAY,IAAI,IAAgB;CACtC,OAAO;EACL,WAAW,IAAI,gBAAgB,MAAM;EACrC,IAAI,MAAM;GACR,SAAS,KAAK,SAAS;GACvB,QAAQ,KAAK,MAAM;GACnB,KAAK,MAAM,YAAY,WAAW,SAAS;EAC7C;EACA,UAAU,UAAU;GAClB,UAAU,IAAI,QAAQ;GACtB,aAAa;IACX,UAAU,OAAO,QAAQ;GAC3B;EACF;EACA;CACF;AACF"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { type UrlStateAdapter, windowLocationAdapter } from "./adapter.js";
|
|
2
|
+
export { createMemoryUrlStateAdapter, type MemoryUrlStateAdapter, prefixUrlStateAdapter, } from "./adapters.js";
|
|
2
3
|
export { type SetUrlSearchParams, UdcUrlStateProvider, type UdcUrlStateProviderProps, useUrlSearchParams, useUrlStateAdapter, } from "./UrlState.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsudc/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "React components for UDC collections: the data view, its table, cards, kanban, calendar, tree, map and chart renderers (one subpath each), the schema editor, headless hooks and models, i18n, theme and a compiled, udc:-prefixed stylesheet.",
|
|
@@ -89,6 +89,7 @@
|
|
|
89
89
|
"default": "./dist/react-router.js"
|
|
90
90
|
},
|
|
91
91
|
"./styles.css": "./dist/styles.css",
|
|
92
|
+
"./styles.scoped.css": "./dist/styles.scoped.css",
|
|
92
93
|
"./tokens.css": "./dist/tokens.css",
|
|
93
94
|
"./package.json": "./package.json"
|
|
94
95
|
},
|
|
@@ -102,7 +103,7 @@
|
|
|
102
103
|
},
|
|
103
104
|
"scripts": {
|
|
104
105
|
"build": "vite build && tsc -p tsconfig.build.json && npm run build:css",
|
|
105
|
-
"build:css": "tailwindcss -i src/styles.css -o dist/styles.css --minify && node -e \"require('node:fs').copyFileSync('src/tokens.css', 'dist/tokens.css')\" && node scripts/check-css.mjs",
|
|
106
|
+
"build:css": "tailwindcss -i src/styles.css -o dist/styles.css --minify && node -e \"require('node:fs').copyFileSync('src/tokens.css', 'dist/tokens.css')\" && node scripts/check-css.mjs && node scripts/check-classes.mjs && tailwindcss -i src/styles.scoped.css -o dist/styles.scoped.css && node scripts/scope-css.mjs dist/styles.scoped.css && node scripts/check-scoped-css.mjs",
|
|
106
107
|
"prepare": "npm run build",
|
|
107
108
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
108
109
|
"check:types": "tsc -p smoke/tsconfig.nodenext.json && tsc -p smoke/tsconfig.bundler.json",
|
|
@@ -119,7 +120,7 @@
|
|
|
119
120
|
"@dnd-kit/core": "^6.3.1",
|
|
120
121
|
"@dnd-kit/sortable": "^10.0.0",
|
|
121
122
|
"@dnd-kit/utilities": "^3.2.2",
|
|
122
|
-
"@jsudc/core": "^0.
|
|
123
|
+
"@jsudc/core": "^0.4.0",
|
|
123
124
|
"@tanstack/react-query": "^5.104.4",
|
|
124
125
|
"@tanstack/react-table": "^8.21.3",
|
|
125
126
|
"leaflet": "^1.9.4",
|
|
@@ -158,7 +159,7 @@
|
|
|
158
159
|
"@dnd-kit/core": "^6.3.1",
|
|
159
160
|
"@dnd-kit/sortable": "^10.0.0",
|
|
160
161
|
"@dnd-kit/utilities": "^3.2.2",
|
|
161
|
-
"@jsudc/core": "^0.
|
|
162
|
+
"@jsudc/core": "^0.4.0",
|
|
162
163
|
"@tailwindcss/cli": "^4.3.3",
|
|
163
164
|
"@tanstack/react-query": "^5.104.4",
|
|
164
165
|
"@tanstack/react-table": "^8.21.3",
|
|
@@ -173,6 +174,7 @@
|
|
|
173
174
|
"@vitejs/plugin-react": "^6.1.2",
|
|
174
175
|
"jsdom": "^30.1.3",
|
|
175
176
|
"leaflet": "^1.9.4",
|
|
177
|
+
"lightningcss": "^1.33.0",
|
|
176
178
|
"lucide-react": "^1.59.0",
|
|
177
179
|
"radix-ui": "^1.8.1",
|
|
178
180
|
"react": "^19.3.1",
|