@declarion/react 0.29.0 → 0.31.1

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.
Files changed (32) hide show
  1. package/dist-lib/{ActionRunner-DtUDeH4F.js → ActionRunner-BzaZQtiI.js} +1150 -993
  2. package/dist-lib/{DraggableChildrenTable-D4WoV6ck.js → DraggableChildrenTable-DILqStHQ.js} +29 -29
  3. package/dist-lib/{Grid-CsK_TuK_.js → Grid-BIsiUwPh.js} +2 -2
  4. package/dist-lib/LayoutRenderer-3RvIsC9M.js +2885 -0
  5. package/dist-lib/{MarkdownRenderer-CwlNQju5.js → MarkdownRenderer-CaHhWrfm.js} +1 -1
  6. package/dist-lib/SmartDetailPage.impl--EO-9fos.js +1494 -0
  7. package/dist-lib/SmartRecordListPage.impl-B1iws8yf.js +763 -0
  8. package/dist-lib/components/detail-layout/DraggableChildrenTable.d.ts +1 -0
  9. package/dist-lib/components/detail-layout/EditableChildrenTable.d.ts +2 -1
  10. package/dist-lib/components/detail-layout/FieldRow.d.ts +2 -1
  11. package/dist-lib/components/detail-layout/LayoutRenderer.d.ts +2 -0
  12. package/dist-lib/components/layout/TenantChip.d.ts +2 -1
  13. package/dist-lib/components/layout/TopBar.d.ts +9 -1
  14. package/dist-lib/components/pages/SmartDetailPage.d.ts +2 -5
  15. package/dist-lib/components/pages/SmartDetailPage.impl.d.ts +4 -0
  16. package/dist-lib/components/pages/SmartRecordListPage.d.ts +2 -5
  17. package/dist-lib/components/pages/SmartRecordListPage.impl.d.ts +4 -0
  18. package/dist-lib/components/pages/list/ListHeader.d.ts +6 -1
  19. package/dist-lib/components/pages/list/cardProjection.d.ts +66 -0
  20. package/dist-lib/declarion-react.css +1 -1
  21. package/dist-lib/hooks/useResponsiveMode.d.ts +30 -0
  22. package/dist-lib/index.d.ts +2 -0
  23. package/dist-lib/index.js +6748 -15502
  24. package/dist-lib/lib/actions.d.ts +10 -0
  25. package/dist-lib/peekDraftStore-yyzMbaiI.js +468 -0
  26. package/dist-lib/registry-2KliNTHB.js +5177 -0
  27. package/dist-lib/testing.d.ts +3 -0
  28. package/dist-lib/testing.js +55 -52
  29. package/dist-lib/types/schema.d.ts +50 -4
  30. package/dist-lib/useProperties-Co3RdtuT.js +453 -0
  31. package/dist-lib/{value-CNUbJNK-.js → value-BooGwUik.js} +1 -1
  32. package/package.json +1 -1
@@ -0,0 +1,453 @@
1
+ import { $ as e, Ot as t, U as n, Yt as r, gn as i, kt as a, lt as o, on as s } from "./ActionRunner-BzaZQtiI.js";
2
+ import { ht as c } from "./registry-2KliNTHB.js";
3
+ import { useEffect as l, useMemo as u } from "react";
4
+ import { useSearchParams as d } from "react-router-dom";
5
+ import { useInfiniteQuery as f, useMutation as p, useQueryClient as m } from "@tanstack/react-query";
6
+ //#region src/api/entities.ts
7
+ function h(e, t) {
8
+ return e.$statuses?.find((e) => e.group_code === t);
9
+ }
10
+ function g(e, t) {
11
+ return e.$properties?.find((e) => e.property_code === t);
12
+ }
13
+ function _(e) {
14
+ let t = { ...e };
15
+ return t.$status = (e) => h(t, e), t.$property = (e) => g(t, e), t;
16
+ }
17
+ var v = class {
18
+ cache = {};
19
+ merge(e) {
20
+ if (e) for (let t of Object.keys(e)) {
21
+ this.cache[t] || (this.cache[t] = {});
22
+ let n = e[t];
23
+ for (let e of Object.keys(n)) this.cache[t][e] = {
24
+ ...this.cache[t][e],
25
+ ...n[e]
26
+ };
27
+ }
28
+ }
29
+ all() {
30
+ return this.cache;
31
+ }
32
+ get(e, t) {
33
+ return this.cache[e]?.[t];
34
+ }
35
+ clear() {
36
+ this.cache = {};
37
+ }
38
+ };
39
+ function y(e, t) {
40
+ let n = new URL(`/api/data/${e}`, window.location.origin);
41
+ return t.select && t.select.length > 0 && n.searchParams.set("select", t.select.join(",")), t.expand && t.expand.length > 0 && n.searchParams.set("expand", t.expand.join(",")), t.sort && n.searchParams.set("sort", t.sort), t.search && n.searchParams.set("search", t.search), t.limit && n.searchParams.set("limit", String(t.limit)), t.after && n.searchParams.set("after", t.after), t.count && n.searchParams.set("count", "with"), t.screen && n.searchParams.set("screen", t.screen), t.preview && n.searchParams.set("preview", "true"), t.include_deleted && n.searchParams.set("include_deleted", "true"), t.filters && t.filters.length > 0 && n.searchParams.set("filters", JSON.stringify(t.filters)), n.pathname + n.search;
42
+ }
43
+ var b = class {
44
+ entity;
45
+ refs;
46
+ constructor(e, t) {
47
+ this.entity = e, this.refs = t ?? new v();
48
+ }
49
+ async get(e) {
50
+ let n = new URLSearchParams(typeof e == "string" ? { id: e } : e);
51
+ return _((await t(`/api/data/${this.entity}?${n.toString()}`)).data);
52
+ }
53
+ async list(e = {}) {
54
+ let n, i = !1;
55
+ try {
56
+ n = await t(y(this.entity, e));
57
+ } catch (a) {
58
+ if (e.after && r(a)) {
59
+ let { after: r, ...a } = e;
60
+ n = await t(y(this.entity, a)), i = !0;
61
+ } else throw a;
62
+ }
63
+ return this.refs.merge(n.$refs), {
64
+ data: n.data.map((e) => _(e)),
65
+ meta: n.meta,
66
+ $refs: this.refs.all(),
67
+ reset: i
68
+ };
69
+ }
70
+ async create(e) {
71
+ return (await this.createMany([e]))[0];
72
+ }
73
+ async createMany(e) {
74
+ if (e.length === 0) return [];
75
+ let t = await a("system.batch", {
76
+ actions: e.map((e) => ({
77
+ action: `${this.entity}.__create`,
78
+ params: {
79
+ entity: this.entity,
80
+ fields: e
81
+ }
82
+ })),
83
+ atomic: !0
84
+ });
85
+ return x(t, `${this.entity}.__create`), t.results.map((e) => _(S(e)));
86
+ }
87
+ async update(e, t) {
88
+ return (await this.updateMany([{
89
+ id: e,
90
+ ...t
91
+ }]))[0];
92
+ }
93
+ async updateMany(e) {
94
+ if (e.length === 0) return [];
95
+ let t = await a("system.batch", {
96
+ actions: e.map(({ id: e, ...t }) => ({
97
+ action: `${this.entity}.__update`,
98
+ params: {
99
+ object_ids: [e],
100
+ entity: this.entity,
101
+ fields: t
102
+ }
103
+ })),
104
+ atomic: !0
105
+ });
106
+ return x(t, `${this.entity}.__update`), t.results.map((e) => _(S(e)));
107
+ }
108
+ async delete(e) {
109
+ await this.deleteMany([e]);
110
+ }
111
+ async deleteMany(e) {
112
+ return e.length === 0 ? { count: 0 } : { count: (await n(`${this.entity}.__delete`, {
113
+ object_ids: e,
114
+ entity: this.entity
115
+ })).object_count ?? e.length };
116
+ }
117
+ async restore(e) {
118
+ await this.restoreMany([e]);
119
+ }
120
+ async restoreMany(e) {
121
+ return e.length === 0 ? { count: 0 } : { count: (await n(`${this.entity}.__restore`, {
122
+ object_ids: e,
123
+ entity: this.entity
124
+ })).object_count ?? e.length };
125
+ }
126
+ async upsert(e, t) {
127
+ return (await this.upsertMany([e], t))[0];
128
+ }
129
+ async upsertMany(e, t) {
130
+ if (e.length === 0) return [];
131
+ let n = await a("system.batch", {
132
+ actions: e.map((e) => ({
133
+ action: `${this.entity}.__upsert`,
134
+ params: {
135
+ entity: this.entity,
136
+ fields: e,
137
+ unique_by: t
138
+ }
139
+ })),
140
+ atomic: !0
141
+ });
142
+ return x(n, `${this.entity}.__upsert`), n.results.map((e) => _(C(e)));
143
+ }
144
+ };
145
+ function x(e, t) {
146
+ if (e.committed) return;
147
+ let n = e.results.find((e) => !e.ok), r = n ? `${n.error_code ?? "ERROR"}: ${n.error ?? "unknown"}` : "batch did not commit";
148
+ throw Error(`${t} batch failed: ${r}`);
149
+ }
150
+ function S(e) {
151
+ let t = e.result ?? {};
152
+ return (Array.isArray(t.rows) ? t.rows[0] : void 0) ?? {};
153
+ }
154
+ function C(e) {
155
+ let t = e.result ?? {};
156
+ return (Array.isArray(t.rows) ? t.rows[0] : void 0)?.row ?? {};
157
+ }
158
+ function w(e, t) {
159
+ return new b(e, t);
160
+ }
161
+ //#endregion
162
+ //#region src/hooks/useCursorEntityData.ts
163
+ var T = "entity-data-cursor";
164
+ function E(e) {
165
+ return JSON.stringify({
166
+ sort: e.sort,
167
+ filters: e.filters,
168
+ search: e.search,
169
+ select: e.select,
170
+ expand: e.expand,
171
+ includeDeleted: e.includeDeleted,
172
+ screen: e.screen,
173
+ preview: e.preview,
174
+ limit: e.limit
175
+ });
176
+ }
177
+ function D(e, t) {
178
+ return [
179
+ T,
180
+ e,
181
+ E(t)
182
+ ];
183
+ }
184
+ function O(e, t, n) {
185
+ let r = m(), i = u(() => new b(e ?? ""), [e]), a = u(() => E(t), [t]), o = u(() => [
186
+ T,
187
+ e,
188
+ a
189
+ ], [e, a]), s = f({
190
+ queryKey: o,
191
+ queryFn: ({ pageParam: e }) => i.list({
192
+ sort: t.sort,
193
+ filters: t.filters,
194
+ search: t.search,
195
+ select: t.select,
196
+ expand: t.expand,
197
+ include_deleted: t.includeDeleted || void 0,
198
+ screen: t.screen,
199
+ preview: t.preview,
200
+ limit: t.limit,
201
+ after: e ?? void 0,
202
+ count: e ? void 0 : !0
203
+ }),
204
+ getNextPageParam: (e) => e.meta?.has_more ? e.meta.cursor : void 0,
205
+ initialPageParam: void 0,
206
+ enabled: !!e && n,
207
+ placeholderData: (t, n) => n?.queryKey?.[1] === e ? t : void 0
208
+ }), c = s.data?.pages, d = c && c.length > 1 ? c[c.length - 1]?.reset : !1;
209
+ l(() => {
210
+ d && r.resetQueries({ queryKey: o });
211
+ }, [
212
+ d,
213
+ r,
214
+ o
215
+ ]);
216
+ let p = u(() => (s.data?.pages ?? []).flatMap((e) => e.data), [s.data?.pages]), h = s.data?.pages?.[0]?.meta;
217
+ return {
218
+ rows: p,
219
+ refs: s.data?.pages?.[s.data.pages.length - 1]?.$refs,
220
+ total: h && !h.count_unknown ? h.total : void 0,
221
+ countMode: h?.count_mode,
222
+ countUnknown: h?.count_unknown ?? !1,
223
+ hasMore: s.hasNextPage,
224
+ fetchNextPage: s.fetchNextPage,
225
+ isFetchingNextPage: s.isFetchingNextPage,
226
+ isLoading: s.isLoading,
227
+ isFetching: s.isFetching,
228
+ isError: s.isError,
229
+ error: s.error,
230
+ refetch: s.refetch
231
+ };
232
+ }
233
+ //#endregion
234
+ //#region src/hooks/useTabSearchMirror.ts
235
+ function k(e) {
236
+ let t = o(), [n] = d();
237
+ l(() => {
238
+ if (!e || t.enabled) return;
239
+ let r = c.getState(), i = r.findTabByPathname(e);
240
+ i && r.updateTabSearch(i.id, n.toString());
241
+ }, [
242
+ n,
243
+ e,
244
+ t.enabled
245
+ ]);
246
+ }
247
+ //#endregion
248
+ //#region src/hooks/useRegisterScreenTab.ts
249
+ function A(e, t, n, r) {
250
+ let i = o();
251
+ l(() => {
252
+ !e || i.enabled || c.getState().openTab({
253
+ pathname: e,
254
+ search: r,
255
+ title: t,
256
+ icon: n,
257
+ closable: !0
258
+ });
259
+ }, [
260
+ e,
261
+ t,
262
+ n,
263
+ i.enabled
264
+ ]);
265
+ }
266
+ function j(e, t, n) {
267
+ let r = e?.route, i = t ? s(e?.display?.name) || s(t.display.name_plural) : "", a = e?.display?.icon || t?.display.icon;
268
+ A(t ? r : void 0, i, a, n);
269
+ }
270
+ //#endregion
271
+ //#region src/lib/filters.ts
272
+ var M = /* @__PURE__ */ new Set([
273
+ "is_empty",
274
+ "is_not_empty",
275
+ "today",
276
+ "this_week",
277
+ "this_month",
278
+ "last_7_days",
279
+ "last_30_days",
280
+ "last_hour",
281
+ "last_24_hours"
282
+ ]), N = {
283
+ eq: "is",
284
+ not_eq: "is not",
285
+ gt: ">",
286
+ gte: ">=",
287
+ lt: "<",
288
+ lte: "<=",
289
+ in: "is any of",
290
+ not_in: "is none of",
291
+ between: "between",
292
+ contains: "contains",
293
+ starts_with: "starts with",
294
+ is_empty: "is empty",
295
+ is_not_empty: "is not empty",
296
+ today: "today",
297
+ this_week: "this week",
298
+ this_month: "this month",
299
+ last_7_days: "last 7 days",
300
+ last_30_days: "last 30 days",
301
+ last_hour: "last hour",
302
+ last_24_hours: "last 24 hours"
303
+ };
304
+ function P(e) {
305
+ let t = e.get("filters");
306
+ if (!t) return [];
307
+ try {
308
+ let e = JSON.parse(t);
309
+ return Array.isArray(e) ? e.filter((e) => typeof e == "object" && !!e) : [];
310
+ } catch {
311
+ return [];
312
+ }
313
+ }
314
+ function F(e, t) {
315
+ e.length === 0 ? t.delete("filters") : t.set("filters", JSON.stringify(e));
316
+ }
317
+ function I(e) {
318
+ return e.some((e) => e.or != null);
319
+ }
320
+ function L(e) {
321
+ let t = [];
322
+ for (let n of e) if (!(!n || typeof n != "object")) {
323
+ if (n.field && n.op && t.push(n), n.or) for (let e of n.or) t.push(...L(e));
324
+ n.and && t.push(...L(n.and));
325
+ }
326
+ return t;
327
+ }
328
+ function R(e) {
329
+ return L(e).length;
330
+ }
331
+ function z(e, t) {
332
+ if (!e.field || !e.op) return "";
333
+ let n = N[e.op] || e.op;
334
+ if (M.has(e.op)) return `${n}`;
335
+ let r = e.field, a = (e) => {
336
+ if (t) {
337
+ let n = t(r, e);
338
+ return n.label != null && (n.status === "special" || n.status === "resolved") ? n.label : n.raw;
339
+ }
340
+ return i(e);
341
+ };
342
+ return `${n} ${Array.isArray(e.value) ? e.value.map(a).join(", ") : a(e.value)}`;
343
+ }
344
+ function B(e, t) {
345
+ return {
346
+ field: e,
347
+ op: "eq",
348
+ value: t
349
+ };
350
+ }
351
+ function V(e, t) {
352
+ let n = [];
353
+ for (let r of e) if (r.field !== t) {
354
+ if (r.or) {
355
+ let e = r.or.map((e) => V(e, t)).filter((e) => e.length > 0);
356
+ e.length > 0 && n.push({
357
+ ...r,
358
+ or: e
359
+ });
360
+ continue;
361
+ }
362
+ if (r.and) {
363
+ let e = V(r.and, t);
364
+ e.length > 0 && n.push({
365
+ ...r,
366
+ and: e
367
+ });
368
+ continue;
369
+ }
370
+ n.push(r);
371
+ }
372
+ return n;
373
+ }
374
+ //#endregion
375
+ //#region src/api/status.ts
376
+ async function H(e, t, r, i, a) {
377
+ let o = {
378
+ status_group_code: r,
379
+ status_code: i
380
+ };
381
+ a != null && (o.note = a);
382
+ let s = (await n(`${e}.__update`, {
383
+ object_ids: [t],
384
+ entity: e,
385
+ fields: { $statuses: [o] }
386
+ })).result?.rows?.[0]?.$statuses ?? [];
387
+ return s.find((e) => e.group_code === r) ?? s[0];
388
+ }
389
+ //#endregion
390
+ //#region src/hooks/useObjectStatus.ts
391
+ function U(t, n) {
392
+ let r = m();
393
+ return p({
394
+ mutationFn: ({ groupCode: e, statusCode: r, note: i }) => H(t, n, e, r, i),
395
+ onSuccess: () => {
396
+ r.invalidateQueries({ queryKey: ["entity-item", t] });
397
+ },
398
+ onError: (t) => {
399
+ e.error(t.message);
400
+ }
401
+ });
402
+ }
403
+ //#endregion
404
+ //#region src/api/properties.ts
405
+ async function W(e, t, r, i) {
406
+ let a = (await n(`${e}.__update`, {
407
+ object_ids: [t],
408
+ entity: e,
409
+ fields: { $properties: [{
410
+ property_code: r,
411
+ value: i
412
+ }] }
413
+ })).result?.rows?.[0]?.$properties ?? [];
414
+ return a.find((e) => e.property_code === r) ?? a[0];
415
+ }
416
+ async function G(e, t, r) {
417
+ await n(`${e}.__update`, {
418
+ object_ids: [t],
419
+ entity: e,
420
+ fields: { $properties: [{
421
+ property_code: r,
422
+ value: null
423
+ }] }
424
+ });
425
+ }
426
+ //#endregion
427
+ //#region src/hooks/useProperties.ts
428
+ function K(t, n) {
429
+ let r = m();
430
+ return p({
431
+ mutationFn: ({ propertyCode: e, value: r }) => W(t, n, e, r),
432
+ onSuccess: () => {
433
+ r.invalidateQueries({ queryKey: ["entity-item", t] });
434
+ },
435
+ onError: (t) => {
436
+ e.error(t.message);
437
+ }
438
+ });
439
+ }
440
+ function q(t, n) {
441
+ let r = m();
442
+ return p({
443
+ mutationFn: (e) => G(t, n, e),
444
+ onSuccess: () => {
445
+ r.invalidateQueries({ queryKey: ["entity-item", t] });
446
+ },
447
+ onError: (t) => {
448
+ e.error(t.message);
449
+ }
450
+ });
451
+ }
452
+ //#endregion
453
+ export { w as C, v as S, T as _, N as a, O as b, L as c, P as d, V as f, k as g, A as h, M as i, z as l, j as m, K as n, R as o, F as p, U as r, B as s, q as t, I as u, D as v, b as x, E as y };
@@ -1,4 +1,4 @@
1
- import { Ft as e, It as t, zt as n } from "./ActionRunner-DtUDeH4F.js";
1
+ import { Ft as e, It as t, zt as n } from "./ActionRunner-BzaZQtiI.js";
2
2
  import { useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
3
3
  //#region src/components/file-widgets/helpers.ts
4
4
  var s = ["thumb_200", "thumb_300"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@declarion/react",
3
- "version": "0.29.0",
3
+ "version": "0.31.1",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "React SDK for Declarion, the schema-driven business apps platform.",