@declarion/react 0.22.0 → 0.23.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/dist-lib/index.js +19 -19
- package/dist-lib/testing.d.ts +19 -1
- package/dist-lib/testing.js +51 -29
- package/package.json +1 -1
package/dist-lib/index.js
CHANGED
|
@@ -12455,7 +12455,7 @@ function _l({ screenCode: e }) {
|
|
|
12455
12455
|
return document.addEventListener("keydown", e), () => document.removeEventListener("keydown", e);
|
|
12456
12456
|
}, []);
|
|
12457
12457
|
let Bt = Y(null), { rows: Vt } = At.getRowModel(), Ht = I((e) => e.density), Ut = I((e) => e.zebra), Wt = Wn({
|
|
12458
|
-
count:
|
|
12458
|
+
count: Vt.length,
|
|
12459
12459
|
getScrollElement: () => Bt.current,
|
|
12460
12460
|
estimateSize: () => 48,
|
|
12461
12461
|
overscan: 10
|
|
@@ -12602,25 +12602,25 @@ function _l({ screenCode: e }) {
|
|
|
12602
12602
|
search: n?.search
|
|
12603
12603
|
}),
|
|
12604
12604
|
runActionApi: (e, t) => Tt(e, t)
|
|
12605
|
-
}, dn = (e, t
|
|
12606
|
-
let
|
|
12605
|
+
}, dn = (e, t) => {
|
|
12606
|
+
let n = de && e.original[P.soft_delete] != null, r = e.getIsSelected(), i = Ut && t % 2 == 1, a = r ? "var(--row-selected-bg)" : i ? "var(--surface-2)" : "transparent";
|
|
12607
12607
|
return /* @__PURE__ */ Q("tr", {
|
|
12608
|
-
"data-index":
|
|
12609
|
-
ref:
|
|
12608
|
+
"data-index": t,
|
|
12609
|
+
ref: (e) => Wt.measureElement(e),
|
|
12610
12610
|
style: {
|
|
12611
12611
|
height: "var(--row-h)",
|
|
12612
12612
|
cursor: Yt || St ? "pointer" : "default",
|
|
12613
|
-
opacity:
|
|
12614
|
-
fontStyle:
|
|
12615
|
-
background:
|
|
12616
|
-
boxShadow:
|
|
12613
|
+
opacity: n ? .5 : 1,
|
|
12614
|
+
fontStyle: n ? "italic" : "normal",
|
|
12615
|
+
background: a,
|
|
12616
|
+
boxShadow: r ? "inset 2px 0 0 var(--accent)" : "none",
|
|
12617
12617
|
transition: "background-color 120ms"
|
|
12618
12618
|
},
|
|
12619
12619
|
onMouseEnter: (e) => {
|
|
12620
|
-
|
|
12620
|
+
r || (e.currentTarget.style.background = "var(--surface-3)");
|
|
12621
12621
|
},
|
|
12622
12622
|
onMouseLeave: (e) => {
|
|
12623
|
-
e.currentTarget.style.background =
|
|
12623
|
+
e.currentTarget.style.background = a;
|
|
12624
12624
|
},
|
|
12625
12625
|
onClick: Yt || St ? (t) => Zt(t, e.original) : void 0,
|
|
12626
12626
|
onDoubleClick: Yt ? () => {
|
|
@@ -12643,7 +12643,7 @@ function _l({ screenCode: e }) {
|
|
|
12643
12643
|
style: {
|
|
12644
12644
|
display: "flex",
|
|
12645
12645
|
flexDirection: "column",
|
|
12646
|
-
height:
|
|
12646
|
+
height: "100%",
|
|
12647
12647
|
background: "var(--bg)"
|
|
12648
12648
|
},
|
|
12649
12649
|
children: [
|
|
@@ -12874,7 +12874,7 @@ function _l({ screenCode: e }) {
|
|
|
12874
12874
|
})()
|
|
12875
12875
|
}) : /* @__PURE__ */ Q("div", {
|
|
12876
12876
|
style: {
|
|
12877
|
-
flex:
|
|
12877
|
+
flex: 1,
|
|
12878
12878
|
minHeight: 0,
|
|
12879
12879
|
padding: "0 20px 16px",
|
|
12880
12880
|
display: "flex",
|
|
@@ -12889,14 +12889,14 @@ function _l({ screenCode: e }) {
|
|
|
12889
12889
|
boxShadow: "var(--shadow-xs)",
|
|
12890
12890
|
display: "flex",
|
|
12891
12891
|
flexDirection: "column",
|
|
12892
|
-
flex:
|
|
12892
|
+
flex: 1,
|
|
12893
12893
|
minHeight: 0
|
|
12894
12894
|
},
|
|
12895
12895
|
children: [/* @__PURE__ */ Q("div", {
|
|
12896
12896
|
ref: Bt,
|
|
12897
12897
|
style: {
|
|
12898
|
-
overflow:
|
|
12899
|
-
flex:
|
|
12898
|
+
overflow: "auto",
|
|
12899
|
+
flex: 1,
|
|
12900
12900
|
minHeight: 0
|
|
12901
12901
|
},
|
|
12902
12902
|
children: /* @__PURE__ */ $("table", {
|
|
@@ -12998,17 +12998,17 @@ function _l({ screenCode: e }) {
|
|
|
12998
12998
|
}) : Vn(e.column.columnDef.header, e.getContext())
|
|
12999
12999
|
}, e.id);
|
|
13000
13000
|
})
|
|
13001
|
-
}, e.id)) }), /* @__PURE__ */
|
|
13001
|
+
}, e.id)) }), /* @__PURE__ */ $("tbody", { children: [
|
|
13002
13002
|
Wt.getVirtualItems().length > 0 && /* @__PURE__ */ Q("tr", { children: /* @__PURE__ */ Q("td", {
|
|
13003
13003
|
style: { height: Wt.getVirtualItems()[0]?.start ?? 0 },
|
|
13004
13004
|
colSpan: Ct.length
|
|
13005
13005
|
}) }),
|
|
13006
|
-
Wt.getVirtualItems().map((e) => dn(Vt[e.index], e.index
|
|
13006
|
+
Wt.getVirtualItems().map((e) => dn(Vt[e.index], e.index)),
|
|
13007
13007
|
Wt.getVirtualItems().length > 0 && /* @__PURE__ */ Q("tr", { children: /* @__PURE__ */ Q("td", {
|
|
13008
13008
|
style: { height: Wt.getTotalSize() - (Wt.getVirtualItems().at(-1)?.end ?? 0) },
|
|
13009
13009
|
colSpan: Ct.length
|
|
13010
13010
|
}) })
|
|
13011
|
-
] })
|
|
13011
|
+
] })]
|
|
13012
13012
|
})
|
|
13013
13013
|
}), Et && /* @__PURE__ */ $("div", {
|
|
13014
13014
|
style: {
|
package/dist-lib/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ReactElement } from "react";
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
2
|
import { type RenderResult } from "@testing-library/react";
|
|
3
3
|
import { QueryClient } from "@tanstack/react-query";
|
|
4
4
|
import { type ActionExecuteRequest, type ActionExecuteResponse } from "./api/data";
|
|
@@ -64,3 +64,21 @@ export declare function cleanupDeclarion(): void;
|
|
|
64
64
|
* live queryClient.
|
|
65
65
|
*/
|
|
66
66
|
export declare function renderWithDeclarion(ui: ReactElement, opts?: RenderWithDeclarionOptions): RenderWithDeclarionResult;
|
|
67
|
+
export interface PreviewHarnessProps extends RenderWithDeclarionOptions {
|
|
68
|
+
children: ReactNode;
|
|
69
|
+
/** Default true: seeds an admin user so useSchema's auth gate opens and the
|
|
70
|
+
* screen renders authenticated. Set false to render a pre-login screen
|
|
71
|
+
* (SignIn / SignUp / Forgot / Reset / TwoFA / AuthShell) in its logged-out
|
|
72
|
+
* state, where useSchema stays disabled (no fetch) as in production. */
|
|
73
|
+
authenticated?: boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Component form of {@link renderWithDeclarion} for live previews / stories /
|
|
77
|
+
* Storybook: wraps `children` in the SDK's real providers (QueryClient +
|
|
78
|
+
* MemoryRouter + ActionRunnerProvider + the Sonner outlet) and seeds the same
|
|
79
|
+
* read/action seams from props, so an SDK screen renders against fixtures with
|
|
80
|
+
* no network. Unlike renderWithDeclarion (which calls testing-library's render),
|
|
81
|
+
* this returns an element you compose directly. Providers + seeds are created
|
|
82
|
+
* once per mount (useState initializer) so a static snapshot is deterministic.
|
|
83
|
+
*/
|
|
84
|
+
export declare function PreviewHarness({ children, authenticated, ...opts }: PreviewHarnessProps): ReactElement;
|
package/dist-lib/testing.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Pt as e, ct as t, lt as n, t as r, tt as i, ut as a } from "./ActionRunner-C2A73D9b.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { useState as o } from "react";
|
|
3
|
+
import { MemoryRouter as s } from "react-router-dom";
|
|
4
|
+
import { QueryClient as c, QueryClientProvider as l } from "@tanstack/react-query";
|
|
5
|
+
import { Toaster as u } from "sonner";
|
|
6
|
+
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
7
|
+
import { render as p } from "@testing-library/react";
|
|
7
8
|
//#region src/testing.tsx
|
|
8
|
-
function
|
|
9
|
+
function m(e = {}) {
|
|
9
10
|
return {
|
|
10
11
|
languages: [],
|
|
11
12
|
structures: {},
|
|
@@ -18,7 +19,7 @@ function p(e = {}) {
|
|
|
18
19
|
...e
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
+
function h(e, t = {}, n) {
|
|
22
23
|
return {
|
|
23
24
|
data: e,
|
|
24
25
|
meta: {
|
|
@@ -32,27 +33,27 @@ function m(e, t = {}, n) {
|
|
|
32
33
|
...n === void 0 ? {} : { $refs: n }
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
|
-
function
|
|
36
|
+
function g(e) {
|
|
36
37
|
return e;
|
|
37
38
|
}
|
|
38
|
-
var
|
|
39
|
-
function
|
|
39
|
+
var _ = Symbol("declarion.testing.actionEnvelope");
|
|
40
|
+
function v(e) {
|
|
40
41
|
return {
|
|
41
42
|
...e,
|
|
42
|
-
[
|
|
43
|
+
[_]: !0
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
|
-
function
|
|
46
|
-
if (e && typeof e == "object" && e[
|
|
46
|
+
function y(e) {
|
|
47
|
+
if (e && typeof e == "object" && e[_]) {
|
|
47
48
|
let t = { ...e };
|
|
48
|
-
return delete t[
|
|
49
|
+
return delete t[_], t;
|
|
49
50
|
}
|
|
50
51
|
return {
|
|
51
52
|
status: "success",
|
|
52
53
|
result: e
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
|
-
function
|
|
56
|
+
function b() {
|
|
56
57
|
let t = {
|
|
57
58
|
id: "test-tenant",
|
|
58
59
|
code: "test",
|
|
@@ -71,7 +72,7 @@ function y() {
|
|
|
71
72
|
};
|
|
72
73
|
e.getState().setUser(n, t);
|
|
73
74
|
}
|
|
74
|
-
function
|
|
75
|
+
function x(e) {
|
|
75
76
|
if (e === void 0) return { rows: [] };
|
|
76
77
|
if (Array.isArray(e)) return { rows: e };
|
|
77
78
|
if (Array.isArray(e.data)) {
|
|
@@ -84,10 +85,10 @@ function b(e) {
|
|
|
84
85
|
}
|
|
85
86
|
return e;
|
|
86
87
|
}
|
|
87
|
-
function
|
|
88
|
+
function S(e) {
|
|
88
89
|
let r = e.entityData ?? {};
|
|
89
90
|
a((e, t) => {
|
|
90
|
-
let n = r[e], i =
|
|
91
|
+
let n = r[e], i = x(n), a = i.meta?.per_page ?? 50, o = i.meta?.total ?? i.rows.length;
|
|
91
92
|
return t.count === "only" ? {
|
|
92
93
|
data: [],
|
|
93
94
|
meta: {
|
|
@@ -116,10 +117,10 @@ function x(e) {
|
|
|
116
117
|
t(async (e, t) => {
|
|
117
118
|
if (!(e in s)) throw Error(`renderWithDeclarion: no action result registered for "${e}" (seed it via actionResults)`);
|
|
118
119
|
let n = s[e];
|
|
119
|
-
return
|
|
120
|
+
return y(typeof n == "function" ? await n(t) : n);
|
|
120
121
|
});
|
|
121
122
|
}
|
|
122
|
-
function
|
|
123
|
+
function C() {
|
|
123
124
|
a(null), n(null), t(null), e.setState({
|
|
124
125
|
user: null,
|
|
125
126
|
isAuthenticated: !1,
|
|
@@ -127,21 +128,42 @@ function S() {
|
|
|
127
128
|
tenants: []
|
|
128
129
|
});
|
|
129
130
|
}
|
|
130
|
-
function
|
|
131
|
-
let n = new
|
|
131
|
+
function w(e, t = {}) {
|
|
132
|
+
let n = new c({ defaultOptions: { queries: {
|
|
132
133
|
retry: !1,
|
|
133
134
|
gcTime: Infinity
|
|
134
135
|
} } });
|
|
135
|
-
|
|
136
|
-
let i =
|
|
136
|
+
b(), n.setQueryData(["schema", !0], t.schema ?? m()), S(t);
|
|
137
|
+
let i = p(/* @__PURE__ */ f(l, {
|
|
137
138
|
client: n,
|
|
138
|
-
children: [/* @__PURE__ */
|
|
139
|
+
children: [/* @__PURE__ */ d(s, {
|
|
139
140
|
initialEntries: [t.route ?? "/"],
|
|
140
|
-
children: /* @__PURE__ */
|
|
141
|
-
}), /* @__PURE__ */ u
|
|
141
|
+
children: /* @__PURE__ */ d(r, { children: e })
|
|
142
|
+
}), /* @__PURE__ */ d(u, {})]
|
|
142
143
|
}));
|
|
143
144
|
return Object.assign(i, { queryClient: n });
|
|
144
145
|
}
|
|
145
|
-
|
|
146
|
+
function T({ children: t, authenticated: n = !0, ...i }) {
|
|
147
|
+
let [a] = o(() => {
|
|
148
|
+
let t = new c({ defaultOptions: { queries: {
|
|
149
|
+
retry: !1,
|
|
150
|
+
gcTime: Infinity
|
|
151
|
+
} } });
|
|
152
|
+
return n ? (b(), t.setQueryData(["schema", !0], i.schema ?? m())) : e.setState({
|
|
153
|
+
user: null,
|
|
154
|
+
isAuthenticated: !1,
|
|
155
|
+
activeTenant: null,
|
|
156
|
+
tenants: []
|
|
157
|
+
}), S(i), t;
|
|
158
|
+
});
|
|
159
|
+
return /* @__PURE__ */ f(l, {
|
|
160
|
+
client: a,
|
|
161
|
+
children: [/* @__PURE__ */ d(s, {
|
|
162
|
+
initialEntries: [i.route ?? "/"],
|
|
163
|
+
children: /* @__PURE__ */ d(r, { children: t })
|
|
164
|
+
}), /* @__PURE__ */ d(u, {})]
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
typeof afterEach == "function" && afterEach(() => C());
|
|
146
168
|
//#endregion
|
|
147
|
-
export {
|
|
169
|
+
export { T as PreviewHarness, v as actionEnvelope, g as actionResults, C as cleanupDeclarion, h as entityDataFixture, w as renderWithDeclarion, m as schemaFixture };
|