@declarion/react 0.429.0 → 0.442.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.
@@ -1,9 +1,10 @@
1
1
  import { EntityClient as e } from "../api/entities.js";
2
- import { useEffect as t, useMemo as n } from "react";
3
- import { useInfiniteQuery as r, useQueryClient as i } from "@tanstack/react-query";
2
+ import { bindRowReferences as t } from "../lib/reference.js";
3
+ import { useEffect as n, useMemo as r } from "react";
4
+ import { useInfiniteQuery as i, useQueryClient as a } from "@tanstack/react-query";
4
5
  // src/hooks/useCursorEntityData.ts
5
- var a = "entity-data-cursor";
6
- function o(e) {
6
+ var o = "entity-data-cursor";
7
+ function s(e) {
7
8
  return JSON.stringify({
8
9
  sort: e.sort,
9
10
  filters: e.filters,
@@ -16,61 +17,61 @@ function o(e) {
16
17
  limit: e.limit
17
18
  });
18
19
  }
19
- function s(e, t) {
20
+ function c(e, t) {
20
21
  return [
21
- a,
22
+ o,
22
23
  e,
23
- o(t)
24
+ s(t)
24
25
  ];
25
26
  }
26
- function c(s, c, l) {
27
- let u = i(), d = n(() => new e(s ?? ""), [s]), f = n(() => o(c), [c]), p = n(() => [
28
- a,
29
- s,
30
- f
31
- ], [s, f]), m = r({
32
- queryKey: p,
33
- queryFn: ({ pageParam: e }) => d.list({
34
- sort: c.sort,
35
- filters: c.filters,
36
- search: c.search,
37
- select: c.select,
38
- expand: c.expand,
39
- include_deleted: c.includeDeleted || void 0,
40
- screen: c.screen,
41
- preview: c.preview,
42
- limit: c.limit,
27
+ function l(c, l, u) {
28
+ let d = a(), f = r(() => new e(c ?? ""), [c]), p = r(() => s(l), [l]), m = r(() => [
29
+ o,
30
+ c,
31
+ p
32
+ ], [c, p]), h = i({
33
+ queryKey: m,
34
+ queryFn: ({ pageParam: e }) => f.list({
35
+ sort: l.sort,
36
+ filters: l.filters,
37
+ search: l.search,
38
+ select: l.select,
39
+ expand: l.expand,
40
+ include_deleted: l.includeDeleted || void 0,
41
+ screen: l.screen,
42
+ preview: l.preview,
43
+ limit: l.limit,
43
44
  after: e ?? void 0,
44
45
  count: !e || void 0
45
46
  }),
46
47
  getNextPageParam: (e) => e.meta?.has_more ? e.meta.cursor : void 0,
47
48
  initialPageParam: void 0,
48
- enabled: !!s && l,
49
- placeholderData: (e, t) => t?.queryKey?.[1] === s ? e : void 0
50
- }), h = m.data?.pages, g = h && h.length > 1 ? h[h.length - 1]?.reset : !1;
51
- t(() => {
52
- g && u.resetQueries({ queryKey: p });
49
+ enabled: !!c && u,
50
+ placeholderData: (e, t) => t?.queryKey?.[1] === c ? e : void 0
51
+ }), g = h.data?.pages, _ = g && g.length > 1 ? g[g.length - 1]?.reset : !1;
52
+ n(() => {
53
+ _ && d.resetQueries({ queryKey: m });
53
54
  }, [
54
- g,
55
- u,
56
- p
55
+ _,
56
+ d,
57
+ m
57
58
  ]);
58
- let _ = n(() => (m.data?.pages ?? []).flatMap((e) => e.data), [m.data?.pages]), v = m.data?.pages?.[0]?.meta;
59
+ let v = r(() => (h.data?.pages ?? []).flatMap((e) => t(e.data, e.$refs)), [h.data?.pages]), y = h.data?.pages?.[0]?.meta;
59
60
  return {
60
- rows: _,
61
- refs: m.data?.pages?.[m.data.pages.length - 1]?.$refs,
62
- total: v && !v.count_unknown ? v.total : void 0,
63
- countMode: v?.count_mode,
64
- countUnknown: v?.count_unknown ?? !1,
65
- hasMore: m.hasNextPage,
66
- fetchNextPage: m.fetchNextPage,
67
- isFetchingNextPage: m.isFetchingNextPage,
68
- isLoading: m.isLoading,
69
- isFetching: m.isFetching,
70
- isPlaceholderData: m.isPlaceholderData,
71
- isError: m.isError,
72
- error: m.error,
73
- refetch: m.refetch
61
+ rows: v,
62
+ refs: h.data?.pages?.[h.data.pages.length - 1]?.$refs,
63
+ total: y && !y.count_unknown ? y.total : void 0,
64
+ countMode: y?.count_mode,
65
+ countUnknown: y?.count_unknown ?? !1,
66
+ hasMore: h.hasNextPage,
67
+ fetchNextPage: h.fetchNextPage,
68
+ isFetchingNextPage: h.isFetchingNextPage,
69
+ isLoading: h.isLoading,
70
+ isFetching: h.isFetching,
71
+ isPlaceholderData: h.isPlaceholderData,
72
+ isError: h.isError,
73
+ error: h.error,
74
+ refetch: h.refetch
74
75
  };
75
76
  }
76
- export { a as CURSOR_ENTITY_DATA_KEY, s as cursorEntityDataQueryKey, o as cursorEntityStableKey, c as useCursorEntityData };
77
+ export { o as CURSOR_ENTITY_DATA_KEY, c as cursorEntityDataQueryKey, s as cursorEntityStableKey, l as useCursorEntityData };
@@ -9,6 +9,7 @@ function o(e, t) {
9
9
  return e.field || (r ? n(r)[0] : "id") || "id";
10
10
  }
11
11
  function s(e, n, i, a, o) {
12
+ if (!i.entity) return;
12
13
  let s = t(a), c = n[i.entity]?.[s];
13
14
  if (!c) return;
14
15
  let l = i.display?.field ?? o?.[i.entity]?.display?.display_field;
@@ -17,6 +18,7 @@ function s(e, n, i, a, o) {
17
18
  function c(n, r, s) {
18
19
  let c = /* @__PURE__ */ new Map();
19
20
  for (let { ref: e, value: i } of n) {
21
+ if (!e.entity) continue;
20
22
  let n = t(i);
21
23
  if (!n || r?.[e.entity]?.[n]) continue;
22
24
  let a = o(e, s), l = `${e.entity}::${a}`, u = c.get(l);
@@ -1,4 +1,4 @@
1
- import { $ as Action, $t as FileFieldValue, A as EnrichedRow, At as resolveDetailRoute, B as Refs, Bt as FilterURLState, C as ApiErrorBody, Ct as extractPkValues, D as CURSOR_SEMANTICS_MISMATCH, Dt as pkValuesFromId, E as CURSOR_LANGUAGE_CHANGED, Et as pkValuePartsToId, F as LoginResponse, Ft as pickLocalized, G as V2ListParams, Gt as hasOrGroups, H as StatusInfo, Ht as NO_VALUE_OPS, I as ParamLookup, It as pluralText, J as V2ParamInstance, Jt as setFiltersInURL, K as V2ListResponse, Kt as parseFilterURLState, L as PropertyValue, Lt as textWithNodes, M as ListMeta, Mt as TextFn, N as ListParams, Nt as TextVars, O as CheckSetupResponse, Ot as pkValuesToDetailId, P as ListResponse, Pt as makeTextFn, Q as isCursorStaleError, Qt as FileFieldMode, R as PublicParam, Rt as FilterNode, S as ApiError, St as buildRowDetailHref, T as BrandingIdentity, Tt as getPrimaryKeyFields, U as Tenant, Ut as OP_LABELS, V as SignupResponse, Vt as FilterValueResolver, W as TenantEnv, Wt as countActiveFilters, X as V2StatusInstance, Xt as FileFieldDef, Y as V2PropertyInstance, Yt as FileAddress, Z as errorCodeOf, Zt as FileFieldDisplay, _ as executeAction, _t as StatusDef, a as ResponsiveMode, at as EnumDef, b as AggregateParams, bt as buildDetailHrefFromId, c as resolveViewportCategory, ct as LocalizedString, d as ActionExecuteResponse, dt as PkValues, en as HydratedFile, et as AreaDef, f as ActionItemError, ft as PropertyDef, g as deleteObject, gt as SpecialValue, h as buildActionBody, ht as Screen, i as ResponsiveBreakpoints, it as EntityField, j as ImpersonationInfo, jt as MANDATORY_LANGUAGE, k as DataResponse, kt as pkValuesToId, l as ActionBatchError, lt as NavNode, m as GetEntityOptions, mt as Schema, n as useResponsiveMode, nn as UploadedFile, nt as ClassificationTierDef, o as ResponsiveViewport, ot as FieldAccessInfo, p as ActionItemSkip, pt as RefConfig, q as V2Meta, qt as parseFiltersFromURL, r as DEFAULT_RESPONSIVE_BREAKPOINTS, rn as OrderedMap, rt as Entity, s as ViewportCategory, st as LanguageDef, t as ResponsiveModeProvider, tn as UploadProgress, tt as ChildRelation, u as ActionExecuteRequest, ut as ParameterDef, v as restoreObject, vt as StatusGroupDef, w as AuthUser, wt as fieldDisplayName, x as AggregateResponse, xt as buildEntityDetailHref, y as AggregateGroup, yt as StructureDef, z as PublicParamsResponse, zt as FilterOp } from "./useResponsiveMode-Yo2rIWFA.js";
1
+ import { $ as Action, $t as FileFieldValue, A as EnrichedRow, At as resolveDetailRoute, B as Refs, Bt as FilterURLState, C as ApiErrorBody, Ct as extractPkValues, D as CURSOR_SEMANTICS_MISMATCH, Dt as pkValuesFromId, E as CURSOR_LANGUAGE_CHANGED, Et as pkValuePartsToId, F as LoginResponse, Ft as pickLocalized, G as V2ListParams, Gt as hasOrGroups, H as StatusInfo, Ht as NO_VALUE_OPS, I as ParamLookup, It as pluralText, J as V2ParamInstance, Jt as setFiltersInURL, K as V2ListResponse, Kt as parseFilterURLState, L as PropertyValue, Lt as textWithNodes, M as ListMeta, Mt as TextFn, N as ListParams, Nt as TextVars, O as CheckSetupResponse, Ot as pkValuesToDetailId, P as ListResponse, Pt as makeTextFn, Q as isCursorStaleError, Qt as FileFieldMode, R as PublicParam, Rt as FilterNode, S as ApiError, St as buildRowDetailHref, T as BrandingIdentity, Tt as getPrimaryKeyFields, U as Tenant, Ut as OP_LABELS, V as SignupResponse, Vt as FilterValueResolver, W as TenantEnv, Wt as countActiveFilters, X as V2StatusInstance, Xt as FileFieldDef, Y as V2PropertyInstance, Yt as FileAddress, Z as errorCodeOf, Zt as FileFieldDisplay, _ as executeAction, _t as StatusDef, a as ResponsiveMode, at as EnumDef, b as AggregateParams, bt as buildDetailHrefFromId, c as resolveViewportCategory, ct as LocalizedString, d as ActionExecuteResponse, dt as PkValues, en as HydratedFile, et as AreaDef, f as ActionItemError, ft as PropertyDef, g as deleteObject, gt as SpecialValue, h as buildActionBody, ht as Screen, i as ResponsiveBreakpoints, it as EntityField, j as ImpersonationInfo, jt as MANDATORY_LANGUAGE, k as DataResponse, kt as pkValuesToId, l as ActionBatchError, lt as NavNode, m as GetEntityOptions, mt as Schema, n as useResponsiveMode, nn as UploadedFile, nt as ClassificationTierDef, o as ResponsiveViewport, ot as FieldAccessInfo, p as ActionItemSkip, pt as RefConfig, q as V2Meta, qt as parseFiltersFromURL, r as DEFAULT_RESPONSIVE_BREAKPOINTS, rn as OrderedMap, rt as Entity, s as ViewportCategory, st as LanguageDef, t as ResponsiveModeProvider, tn as UploadProgress, tt as ChildRelation, u as ActionExecuteRequest, ut as ParameterDef, v as restoreObject, vt as StatusGroupDef, w as AuthUser, wt as fieldDisplayName, x as AggregateResponse, xt as buildEntityDetailHref, y as AggregateGroup, yt as StructureDef, z as PublicParamsResponse, zt as FilterOp } from "./useResponsiveMode-3hOLBkey.js";
2
2
  import { i as setIconRegistry, n as getIcon, t as IconDef } from "./icon-registry-BY2tt-GF.js";
3
3
  import { i as DynamicIcon, n as IconName, r as IconProps, t as Icon } from "./Icons-BdXCxyw3.js";
4
4
  import { ButtonHTMLAttributes, CSSProperties, ComponentType, InputHTMLAttributes, MouseEvent, ReactNode, RefObject } from "react";
@@ -1300,6 +1300,8 @@ interface QuickPeekProps<R extends Record<string, unknown> = Record<string, unkn
1300
1300
  fields: QuickPeekFieldSpec[];
1301
1301
  /** $refs payload from the list/detail API; used by RefField-style renderers. */
1302
1302
  refs?: Refs;
1303
+ entities?: Record<string, Entity>;
1304
+ screens?: Record<string, Screen>;
1303
1305
  /** Full screen YAML — honors `screen.quick_peek.width`. */
1304
1306
  screen?: Screen;
1305
1307
  /** All actions available on this record. */
@@ -1325,7 +1327,7 @@ interface QuickPeekProps<R extends Record<string, unknown> = Record<string, unkn
1325
1327
  /** Fires once per explicit user commit — never on keystroke. */
1326
1328
  onSave?: (next: R) => void;
1327
1329
  }
1328
- export declare function QuickPeek<R extends Record<string, unknown>>({ entity, entityCode, record, title, recordId, avatarName, fields, refs, screen, actions, screenActionLayout, entityActionLayout, executeAction, onClose, onOpen, onSave }: QuickPeekProps<R>): import("react").JSX.Element;
1330
+ export declare function QuickPeek<R extends Record<string, unknown>>({ entity, entityCode, record, title, recordId, avatarName, fields, refs, entities, screens, screen, actions, screenActionLayout, entityActionLayout, executeAction, onClose, onOpen, onSave }: QuickPeekProps<R>): import("react").JSX.Element;
1329
1331
  interface QEFieldProps {
1330
1332
  label: string;
1331
1333
  children: ReactNode;
@@ -0,0 +1,53 @@
1
+ import { coerceDisplayString as e } from "./display-value.js";
2
+ import { DISPLAY_KEY as t, getPrimaryKeyFields as n, resolveRefRecordLabel as r } from "../types/schema.js";
3
+ // src/lib/reference.ts
4
+ var i = /* @__PURE__ */ new WeakMap();
5
+ function a(e) {
6
+ return e.includes("@");
7
+ }
8
+ function o(e, t) {
9
+ for (let n of e) i.set(n, t);
10
+ return e;
11
+ }
12
+ function s(e, t) {
13
+ return i.has(e) && i.set(t, i.get(e)), t;
14
+ }
15
+ function c(e, t) {
16
+ return e && Object.hasOwn(e, t) ? e[t] : void 0;
17
+ }
18
+ function l(e, t) {
19
+ return i.has(e) ? i.get(e) : c(e, "$refs") ?? t;
20
+ }
21
+ function u(i) {
22
+ let a = i.field.ref, o = !!a?.entity_field, s = /* @__PURE__ */ new Map();
23
+ function u(e) {
24
+ let t = s.get(e);
25
+ if (t) return t;
26
+ let r = c(i.entities, e), a = i.detailScreen || r?.detail_screen, l = a ? c(i.screens, a) : void 0, u = {
27
+ route: o && (!r || l?.entity !== e || l.type !== "detail") ? void 0 : l?.route,
28
+ icon: r?.display?.icon,
29
+ key: r ? n(r)[0] ?? "id" : "id"
30
+ };
31
+ return s.set(e, u), u;
32
+ }
33
+ return (n, s, d) => {
34
+ let f = n == null || n === "" ? "" : e(n), p = a?.entity_field ? c(s, a.entity_field) : a?.entity;
35
+ if (!f || typeof p != "string" || !p) return {
36
+ label: f || "—",
37
+ resolved: !1
38
+ };
39
+ let m = o ? `${i.fieldName}@${p}` : p, h = c(c(o ? l(s, d) : d, m), f);
40
+ if (o && !h) return {
41
+ label: f,
42
+ resolved: !1
43
+ };
44
+ let g = o ? t : i.field.display?.ref_display_field || "$display", _ = h ? r(i.t, h, g, f) : f, v = u(p), y = h ? c(h, v.key) : void 0, b = o || y == null ? f : e(y), x = !o || b !== "new" && b !== "." && b !== ".." && !b.includes("%2F") && v.route?.split("/").includes(":id");
45
+ return {
46
+ label: _,
47
+ resolved: !!h,
48
+ icon: v.icon,
49
+ href: x ? v.route?.replace(":id", encodeURIComponent(b)) : void 0
50
+ };
51
+ };
52
+ }
53
+ export { o as bindRowReferences, s as inheritRowReferences, a as isPolymorphicReferenceBucket, l as referenceBucketsForRow, u as referenceResolver };
@@ -1,4 +1,4 @@
1
- import { B as Refs, M as ListMeta, Mt as TextFn, P as ListResponse, ct as LocalizedString, d as ActionExecuteResponse, k as DataResponse, mt as Schema, o as ResponsiveViewport, u as ActionExecuteRequest } from "./useResponsiveMode-Yo2rIWFA.js";
1
+ import { B as Refs, M as ListMeta, Mt as TextFn, P as ListResponse, ct as LocalizedString, d as ActionExecuteResponse, k as DataResponse, mt as Schema, o as ResponsiveViewport, u as ActionExecuteRequest } from "./useResponsiveMode-3hOLBkey.js";
2
2
  import { ReactElement, ReactNode } from "react";
3
3
  import { QueryClient } from "@tanstack/react-query";
4
4
  import { RenderResult } from "@testing-library/react";
@@ -27,7 +27,7 @@ function a(e, r, a) {
27
27
  return typeof c == "object" && !Array.isArray(c) ? e(c) || void 0 : t(c);
28
28
  }
29
29
  function o(e, n, r, i) {
30
- if (!r) return i;
30
+ if (!r || !Object.hasOwn(n, r)) return i;
31
31
  let a = n[r];
32
32
  return a == null ? i : typeof a == "object" && !Array.isArray(a) ? e(a) || i : t(a);
33
33
  }
@@ -224,13 +224,25 @@ declare function fieldDisplayName(t: TextFn, field: EntityField, fieldName: stri
224
224
  interface RefDisplay {
225
225
  field: string;
226
226
  }
227
- interface RefConfig {
227
+ interface StaticRefConfig {
228
228
  entity: string;
229
+ entity_field?: never;
229
230
  field?: string;
230
231
  display?: RefDisplay;
231
232
  fields?: string[];
233
+ db_column_type?: string;
232
234
  options_filter?: FilterNode[];
233
235
  }
236
+ interface PolymorphicRefConfig {
237
+ entity_field: string;
238
+ entity?: never;
239
+ db_column_type?: "text" | "uuid";
240
+ field?: never;
241
+ display?: never;
242
+ fields?: never;
243
+ options_filter?: never;
244
+ }
245
+ type RefConfig = StaticRefConfig | PolymorphicRefConfig;
234
246
  /** One declared special value ({code, label}), offered in the list filter and in
235
247
  * the create and edit forms of its field. `code` is the value the choice
236
248
  * stands for (a literal or a supported token); the server resolves it on
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@declarion/react",
3
- "version": "0.429.0",
3
+ "version": "0.442.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "React SDK for Declarion, the schema-driven business apps platform.",