@verikit/ui-core 0.24.4 → 0.25.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 CHANGED
@@ -4,7 +4,11 @@ Framework-neutral form, layout, and query logic for VeriKit UI bindings.
4
4
 
5
5
  See the [VeriKit documentation](https://verikit.dev) for setup and usage.
6
6
 
7
- ## Cache identity
7
+ ## Production
8
+
9
+ You don't need this to get started. Read it before you deploy.
10
+
11
+ ### Cache identity
8
12
 
9
13
  Queries, mutations, and optimistic updates are isolated by client. Keep the client
10
14
  stable during a session; replace it when the account, tenant, or access identity
package/dist/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export * from "./actions/index.js";
2
2
  export * from "./form/index.js";
3
3
  export * from "./layout/index.js";
4
4
  export * from "./query/index.js";
5
+ export * from "./routing/index.js";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -2,3 +2,4 @@ export * from "./actions/index.js";
2
2
  export * from "./form/index.js";
3
3
  export * from "./layout/index.js";
4
4
  export * from "./query/index.js";
5
+ export * from "./routing/index.js";
@@ -1,4 +1,6 @@
1
1
  export { getValueAtPath, hasValueAtPath, pathKey, setValueAtPath, unsetValueAtPath, } from "./path.js";
2
2
  export type { SchemaPath } from "./path.js";
3
3
  export { formatFieldValue } from "./format-value.js";
4
+ export { needsRelationshipLabels, relationshipCellText, resourceColumnSpecs, } from "./table-columns.js";
5
+ export type { ResourceColumnSpecOptions, FieldColumnSpec, RelationshipColumnSpec, RelationshipLabelMap, ResourceColumnSpec, } from "./table-columns.js";
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,OAAO,EACP,cAAc,EACd,gBAAgB,GACjB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,OAAO,EACP,cAAc,EACd,gBAAgB,GACjB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,yBAAyB,EACzB,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export { getValueAtPath, hasValueAtPath, pathKey, setValueAtPath, unsetValueAtPath, } from "./path.js";
2
2
  export { formatFieldValue } from "./format-value.js";
3
+ export { needsRelationshipLabels, relationshipCellText, resourceColumnSpecs, } from "./table-columns.js";
@@ -0,0 +1,51 @@
1
+ import type { FieldSchema, Resource, ResourceSchema } from "@verikit/core";
2
+ /** Display labels from a list's `relationships`, keyed by relationship name then foreign-key value. */
3
+ export type RelationshipLabelMap = Record<string, Record<string, string>>;
4
+ /** A table column backed by one of the resource's fields. */
5
+ export interface FieldColumnSpec {
6
+ kind: "field";
7
+ field: FieldSchema;
8
+ }
9
+ /**
10
+ * A table column showing a `belongsTo` relationship's related record, in
11
+ * place of its foreign-key field.
12
+ */
13
+ export interface RelationshipColumnSpec {
14
+ kind: "relationship";
15
+ /** Relationship name, used as the column id. */
16
+ name: string;
17
+ /** Column header: the relationship's label, else its foreign key's, else its name. */
18
+ label: string;
19
+ /** Field on this resource holding the related record's id. */
20
+ foreignKey: string;
21
+ }
22
+ export type ResourceColumnSpec = FieldColumnSpec | RelationshipColumnSpec;
23
+ /** Options for {@link resourceColumnSpecs}. */
24
+ export interface ResourceColumnSpecOptions {
25
+ /**
26
+ * `"table"` (the default) leaves out fields marked `.hidden()` or
27
+ * `.tableHidden()`; `"detail"`, for a record page, leaves out only
28
+ * `.hidden()` ones.
29
+ */
30
+ view?: "table" | "detail";
31
+ }
32
+ /**
33
+ * The columns a resource table (or the rows a record page) shows, in field
34
+ * order. A `belongsTo` relationship whose foreign key is one of the
35
+ * resource's fields gets a column where that field is, replacing the field's
36
+ * own column, and is shown even when the field is hidden (as generated
37
+ * foreign keys are). Other hidden fields are left out; see
38
+ * {@link ResourceColumnSpecOptions.view}.
39
+ */
40
+ export declare function resourceColumnSpecs(source: Resource | ResourceSchema, { view }?: ResourceColumnSpecOptions): ResourceColumnSpec[];
41
+ /**
42
+ * True when a table of `source` should ask the server for relationship
43
+ * labels: it has a relationship column with a `displayField` to show.
44
+ */
45
+ export declare function needsRelationshipLabels(source: Resource | ResourceSchema): boolean;
46
+ /**
47
+ * The text a relationship cell shows: the related record's label when the
48
+ * server sent one, otherwise the raw foreign key (empty when there is none).
49
+ */
50
+ export declare function relationshipCellText(labels: RelationshipLabelMap | undefined, spec: RelationshipColumnSpec, record: Record<string, unknown>): string;
51
+ //# sourceMappingURL=table-columns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-columns.d.ts","sourceRoot":"","sources":["../../src/layout/table-columns.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EACX,QAAQ,EACR,cAAc,EACf,MAAM,eAAe,CAAC;AAEvB,uGAAuG;AACvG,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE1E,6DAA6D;AAC7D,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,WAAW,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,cAAc,CAAC;IACrB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,sFAAsF;IACtF,KAAK,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,kBAAkB,GAAG,eAAe,GAAG,sBAAsB,CAAC;AAQ1E,+CAA+C;AAC/C,MAAM,WAAW,yBAAyB;IACxC;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,QAAQ,GAAG,cAAc,EACjC,EAAE,IAAc,EAAE,GAAE,yBAA8B,GACjD,kBAAkB,EAAE,CAmCtB;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,QAAQ,GAAG,cAAc,GAChC,OAAO,CAQT;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,oBAAoB,GAAG,SAAS,EACxC,IAAI,EAAE,sBAAsB,EAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAQR"}
@@ -0,0 +1,61 @@
1
+ function resourceSchema(source) {
2
+ return "toSchema" in source && typeof source.toSchema === "function"
3
+ ? source.toSchema()
4
+ : source;
5
+ }
6
+ /**
7
+ * The columns a resource table (or the rows a record page) shows, in field
8
+ * order. A `belongsTo` relationship whose foreign key is one of the
9
+ * resource's fields gets a column where that field is, replacing the field's
10
+ * own column, and is shown even when the field is hidden (as generated
11
+ * foreign keys are). Other hidden fields are left out; see
12
+ * {@link ResourceColumnSpecOptions.view}.
13
+ */
14
+ export function resourceColumnSpecs(source, { view = "table" } = {}) {
15
+ const schema = resourceSchema(source);
16
+ const byForeignKey = new Map();
17
+ for (const [name, relationship] of Object.entries(schema.relationships)) {
18
+ if (relationship.relationshipType === "belongsTo" &&
19
+ typeof relationship.foreignKey === "string" &&
20
+ Object.hasOwn(schema.fields, relationship.foreignKey) &&
21
+ !byForeignKey.has(relationship.foreignKey)) {
22
+ byForeignKey.set(relationship.foreignKey, { ...relationship, name });
23
+ }
24
+ }
25
+ return Object.values(schema.fields).flatMap((field) => {
26
+ const relationship = byForeignKey.get(field.name);
27
+ if (relationship) {
28
+ return [
29
+ {
30
+ kind: "relationship",
31
+ name: relationship.name,
32
+ label: relationship.label ?? field.label ?? relationship.name,
33
+ foreignKey: field.name,
34
+ },
35
+ ];
36
+ }
37
+ return field.hidden || (view === "table" && field.tableHidden)
38
+ ? []
39
+ : [{ kind: "field", field }];
40
+ });
41
+ }
42
+ /**
43
+ * True when a table of `source` should ask the server for relationship
44
+ * labels: it has a relationship column with a `displayField` to show.
45
+ */
46
+ export function needsRelationshipLabels(source) {
47
+ const schema = resourceSchema(source);
48
+ return resourceColumnSpecs(schema).some((spec) => spec.kind === "relationship" &&
49
+ schema.relationships[spec.name].displayField !== undefined);
50
+ }
51
+ /**
52
+ * The text a relationship cell shows: the related record's label when the
53
+ * server sent one, otherwise the raw foreign key (empty when there is none).
54
+ */
55
+ export function relationshipCellText(labels, spec, record) {
56
+ const value = record[spec.foreignKey];
57
+ if (value === null || value === undefined) {
58
+ return "";
59
+ }
60
+ return labels?.[spec.name]?.[String(value)] ?? String(value);
61
+ }
@@ -6,6 +6,18 @@ export interface ResourceQueryKeys {
6
6
  /** Kept apart from `find` because its cached data has a different shape. */
7
7
  findWithActions: (id: string) => readonly [string, string, string, "findWithActions", string];
8
8
  relationship: (relationshipName: string, params?: ListParams) => readonly [string, string, string, "relationship", string, ListParams];
9
+ /**
10
+ * A relationship picker's pages, loaded one after another. Kept apart from
11
+ * `relationship` because its cached data holds every loaded page.
12
+ */
13
+ relationshipPages: (relationshipName: string, params?: ListParams) => readonly [
14
+ string,
15
+ string,
16
+ string,
17
+ "relationshipPages",
18
+ string,
19
+ ListParams
20
+ ];
9
21
  }
10
22
  /**
11
23
  * Builds keys scoped to a client or explicit cache namespace. Pass the same
@@ -1 +1 @@
1
- {"version":3,"file":"query-keys.d.ts","sourceRoot":"","sources":["../../src/query/query-keys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEjE,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,IAAI,EAAE,CACJ,MAAM,CAAC,EAAE,UAAU,KAChB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC3D,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACxE,4EAA4E;IAC5E,eAAe,EAAE,CACf,EAAE,EAAE,MAAM,KACP,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAClE,YAAY,EAAE,CACZ,gBAAgB,EAAE,MAAM,EACxB,MAAM,CAAC,EAAE,UAAU,KAChB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;CAC5E;AAID;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,aAAa,GAAG,MAAM,GAC7B,iBAAiB,CA4BnB"}
1
+ {"version":3,"file":"query-keys.d.ts","sourceRoot":"","sources":["../../src/query/query-keys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEjE,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,IAAI,EAAE,CACJ,MAAM,CAAC,EAAE,UAAU,KAChB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC3D,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACxE,4EAA4E;IAC5E,eAAe,EAAE,CACf,EAAE,EAAE,MAAM,KACP,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAClE,YAAY,EAAE,CACZ,gBAAgB,EAAE,MAAM,EACxB,MAAM,CAAC,EAAE,UAAU,KAChB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC3E;;;OAGG;IACH,iBAAiB,EAAE,CACjB,gBAAgB,EAAE,MAAM,EACxB,MAAM,CAAC,EAAE,UAAU,KAChB,SAAS;QACZ,MAAM;QACN,MAAM;QACN,MAAM;QACN,mBAAmB;QACnB,MAAM;QACN,UAAU;KACX,CAAC;CACH;AAID;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,aAAa,GAAG,MAAM,GAC7B,iBAAiB,CAqCnB"}
@@ -29,5 +29,13 @@ export function resourceQueryKeys(name, client) {
29
29
  relationshipName,
30
30
  params,
31
31
  ],
32
+ relationshipPages: (relationshipName, params = {}) => [
33
+ "verikit",
34
+ namespace,
35
+ name,
36
+ "relationshipPages",
37
+ relationshipName,
38
+ params,
39
+ ],
32
40
  };
33
41
  }
@@ -0,0 +1,4 @@
1
+ export { currentPathname, isPlainLeftClick, navigate, subscribeToLocation, } from "./location.js";
2
+ export { matchPanelRoute, normalizeBasePath, panelHref } from "./routes.js";
3
+ export type { PanelRoute } from "./routes.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC5E,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { currentPathname, isPlainLeftClick, navigate, subscribeToLocation, } from "./location.js";
2
+ export { matchPanelRoute, normalizeBasePath, panelHref } from "./routes.js";
@@ -0,0 +1,22 @@
1
+ /** Changes the URL with the History API and tells mounted panels to re-render. */
2
+ export declare function navigate(to: string, options?: {
3
+ replace?: boolean;
4
+ }): void;
5
+ /**
6
+ * Calls `onChange` when the URL changes, through back/forward or
7
+ * {@link navigate}. Returns a function that stops listening. Framework
8
+ * bindings pair it with {@link currentPathname}.
9
+ */
10
+ export declare function subscribeToLocation(onChange: () => void): () => void;
11
+ /** The current `location.pathname`. */
12
+ export declare function currentPathname(): string;
13
+ /** True for a click the browser would otherwise handle as "open here". */
14
+ export declare function isPlainLeftClick(event: {
15
+ button: number;
16
+ defaultPrevented: boolean;
17
+ metaKey: boolean;
18
+ ctrlKey: boolean;
19
+ shiftKey: boolean;
20
+ altKey: boolean;
21
+ }): boolean;
22
+ //# sourceMappingURL=location.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../../src/routing/location.ts"],"names":[],"mappings":"AAGA,kFAAkF;AAClF,wBAAgB,QAAQ,CACtB,EAAE,EAAE,MAAM,EACV,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,GAClC,IAAI,CAQN;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAQpE;AAED,uCAAuC;AACvC,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,0EAA0E;AAC1E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,OAAO,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;CACjB,GAAG,OAAO,CASV"}
@@ -0,0 +1,38 @@
1
+ /** Fired on `window` after a panel changes the URL itself. */
2
+ const NAVIGATE_EVENT = "verikit:navigate";
3
+ /** Changes the URL with the History API and tells mounted panels to re-render. */
4
+ export function navigate(to, options = {}) {
5
+ if (options.replace) {
6
+ window.history.replaceState(null, "", to);
7
+ }
8
+ else {
9
+ window.history.pushState(null, "", to);
10
+ }
11
+ window.dispatchEvent(new Event(NAVIGATE_EVENT));
12
+ }
13
+ /**
14
+ * Calls `onChange` when the URL changes, through back/forward or
15
+ * {@link navigate}. Returns a function that stops listening. Framework
16
+ * bindings pair it with {@link currentPathname}.
17
+ */
18
+ export function subscribeToLocation(onChange) {
19
+ window.addEventListener("popstate", onChange);
20
+ window.addEventListener(NAVIGATE_EVENT, onChange);
21
+ return () => {
22
+ window.removeEventListener("popstate", onChange);
23
+ window.removeEventListener(NAVIGATE_EVENT, onChange);
24
+ };
25
+ }
26
+ /** The current `location.pathname`. */
27
+ export function currentPathname() {
28
+ return window.location.pathname;
29
+ }
30
+ /** True for a click the browser would otherwise handle as "open here". */
31
+ export function isPlainLeftClick(event) {
32
+ return (event.button === 0 &&
33
+ !event.defaultPrevented &&
34
+ !event.metaKey &&
35
+ !event.ctrlKey &&
36
+ !event.shiftKey &&
37
+ !event.altKey);
38
+ }
@@ -0,0 +1,36 @@
1
+ /** A parsed panel URL. `resource` is the resource's panel path segment. */
2
+ export type PanelRoute = {
3
+ kind: "home";
4
+ } | {
5
+ kind: "list";
6
+ resource: string;
7
+ } | {
8
+ kind: "create";
9
+ resource: string;
10
+ } | {
11
+ kind: "view";
12
+ resource: string;
13
+ id: string;
14
+ } | {
15
+ kind: "edit";
16
+ resource: string;
17
+ id: string;
18
+ } | {
19
+ kind: "notFound";
20
+ };
21
+ /**
22
+ * Normalizes a mount path to `""` (mounted at the site root) or a path with a
23
+ * leading slash and no trailing slash, such as `"/admin"`.
24
+ */
25
+ export declare function normalizeBasePath(basePath: string): string;
26
+ /**
27
+ * Matches `pathname` against the panel's routes:
28
+ * `{base}`, `{base}/{resource}`, `{base}/{resource}/create`,
29
+ * `{base}/{resource}/{id}`, and `{base}/{resource}/{id}/edit`. A record whose
30
+ * id is literally `create` has no view page (that path is the create page),
31
+ * but its edit page still works.
32
+ */
33
+ export declare function matchPanelRoute(pathname: string, basePath: string, resourcePaths: ReadonlySet<string>): PanelRoute;
34
+ /** Builds a panel URL from path segments, encoding each one. */
35
+ export declare function panelHref(basePath: string, ...segments: string[]): string;
36
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/routing/routes.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAEzB;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG1D;AAWD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,WAAW,CAAC,MAAM,CAAC,GACjC,UAAU,CAsCZ;AAED,gEAAgE;AAChE,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAQzE"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Normalizes a mount path to `""` (mounted at the site root) or a path with a
3
+ * leading slash and no trailing slash, such as `"/admin"`.
4
+ */
5
+ export function normalizeBasePath(basePath) {
6
+ const trimmed = basePath.replace(/^\/+|\/+$/g, "");
7
+ return trimmed === "" ? "" : `/${trimmed}`;
8
+ }
9
+ function decodeSegments(path) {
10
+ try {
11
+ return path.split("/").filter(Boolean).map(decodeURIComponent);
12
+ }
13
+ catch {
14
+ // A malformed escape such as "%E0%A4%A" can't name any page.
15
+ return undefined;
16
+ }
17
+ }
18
+ /**
19
+ * Matches `pathname` against the panel's routes:
20
+ * `{base}`, `{base}/{resource}`, `{base}/{resource}/create`,
21
+ * `{base}/{resource}/{id}`, and `{base}/{resource}/{id}/edit`. A record whose
22
+ * id is literally `create` has no view page (that path is the create page),
23
+ * but its edit page still works.
24
+ */
25
+ export function matchPanelRoute(pathname, basePath, resourcePaths) {
26
+ const base = normalizeBasePath(basePath);
27
+ if (base && pathname !== base && !pathname.startsWith(`${base}/`)) {
28
+ return { kind: "notFound" };
29
+ }
30
+ const segments = decodeSegments(pathname.slice(base.length));
31
+ if (!segments) {
32
+ return { kind: "notFound" };
33
+ }
34
+ if (segments.length === 0) {
35
+ return { kind: "home" };
36
+ }
37
+ const [resource, second, third] = segments;
38
+ if (!resourcePaths.has(resource)) {
39
+ return { kind: "notFound" };
40
+ }
41
+ if (segments.length === 1) {
42
+ return { kind: "list", resource };
43
+ }
44
+ if (segments.length === 2) {
45
+ return second === "create"
46
+ ? { kind: "create", resource }
47
+ : { kind: "view", resource, id: second };
48
+ }
49
+ if (segments.length === 3 && third === "edit") {
50
+ return { kind: "edit", resource, id: second };
51
+ }
52
+ return { kind: "notFound" };
53
+ }
54
+ /** Builds a panel URL from path segments, encoding each one. */
55
+ export function panelHref(basePath, ...segments) {
56
+ const base = normalizeBasePath(basePath);
57
+ if (segments.length === 0) {
58
+ return base || "/";
59
+ }
60
+ return `${base}/${segments.map(encodeURIComponent).join("/")}`;
61
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verikit/ui-core",
3
- "version": "0.24.4",
3
+ "version": "0.25.0",
4
4
  "description": "Framework-neutral form, layout, and query logic shared by Verikit UI bindings.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -45,6 +45,10 @@
45
45
  "./query/*": {
46
46
  "types": "./dist/query/*.d.ts",
47
47
  "default": "./dist/query/*.js"
48
+ },
49
+ "./routing/*": {
50
+ "types": "./dist/routing/*.d.ts",
51
+ "default": "./dist/routing/*.js"
48
52
  }
49
53
  },
50
54
  "files": [
@@ -52,9 +56,9 @@
52
56
  ],
53
57
  "dependencies": {
54
58
  "@tanstack/query-core": "^5.101.4",
55
- "@verikit/core": "0.24.4",
56
- "@verikit/runtime": "0.24.4",
57
- "@verikit/client": "0.24.4"
59
+ "@verikit/core": "0.25.0",
60
+ "@verikit/client": "0.25.0",
61
+ "@verikit/runtime": "0.25.0"
58
62
  },
59
63
  "devDependencies": {
60
64
  "@types/node": "^26.1.1",