@btst/plugin-form-builder 0.0.0-stage → 1.0.0-beta.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/LICENSE.md +17 -0
- package/dist/api/getters.cjs +154 -0
- package/dist/api/getters.mjs +145 -0
- package/dist/api/index.cjs +25 -0
- package/dist/api/index.d.cts +119 -0
- package/dist/api/index.d.mts +119 -0
- package/dist/api/index.d.ts +119 -0
- package/dist/api/index.mjs +6 -0
- package/dist/api/lifecycle-migrations.cjs +15 -0
- package/dist/api/lifecycle-migrations.mjs +13 -0
- package/dist/api/operations.cjs +1093 -0
- package/dist/api/operations.mjs +1082 -0
- package/dist/api/plugin.cjs +201 -0
- package/dist/api/plugin.mjs +192 -0
- package/dist/api/query-key-defs.cjs +43 -0
- package/dist/api/query-key-defs.mjs +39 -0
- package/dist/client/components/forms/form-renderer.cjs +193 -0
- package/dist/client/components/forms/form-renderer.mjs +191 -0
- package/dist/client/components/index.cjs +29 -0
- package/dist/client/components/index.d.cts +97 -0
- package/dist/client/components/index.d.mts +97 -0
- package/dist/client/components/index.d.ts +97 -0
- package/dist/client/components/index.mjs +18 -0
- package/dist/client/components/loading/form-builder-skeleton.cjs +32 -0
- package/dist/client/components/loading/form-builder-skeleton.mjs +30 -0
- package/dist/client/components/loading/form-list-skeleton.cjs +21 -0
- package/dist/client/components/loading/form-list-skeleton.mjs +19 -0
- package/dist/client/components/loading/submissions-skeleton.cjs +34 -0
- package/dist/client/components/loading/submissions-skeleton.mjs +32 -0
- package/dist/client/components/pages/404-page.cjs +28 -0
- package/dist/client/components/pages/404-page.mjs +26 -0
- package/dist/client/components/pages/form-builder-page.cjs +77 -0
- package/dist/client/components/pages/form-builder-page.internal.cjs +217 -0
- package/dist/client/components/pages/form-builder-page.internal.mjs +215 -0
- package/dist/client/components/pages/form-builder-page.mjs +75 -0
- package/dist/client/components/pages/form-list-page.cjs +44 -0
- package/dist/client/components/pages/form-list-page.internal.cjs +282 -0
- package/dist/client/components/pages/form-list-page.internal.mjs +280 -0
- package/dist/client/components/pages/form-list-page.mjs +42 -0
- package/dist/client/components/pages/submissions-page.cjs +64 -0
- package/dist/client/components/pages/submissions-page.internal.cjs +255 -0
- package/dist/client/components/pages/submissions-page.internal.mjs +253 -0
- package/dist/client/components/pages/submissions-page.mjs +62 -0
- package/dist/client/components/shared/default-error.cjs +17 -0
- package/dist/client/components/shared/default-error.mjs +15 -0
- package/dist/client/components/shared/empty-state.cjs +16 -0
- package/dist/client/components/shared/empty-state.mjs +14 -0
- package/dist/client/components/shared/page-wrapper.cjs +29 -0
- package/dist/client/components/shared/page-wrapper.mjs +27 -0
- package/dist/client/components/shared/pagination.cjs +49 -0
- package/dist/client/components/shared/pagination.mjs +47 -0
- package/dist/client/constants.cjs +5 -0
- package/dist/client/constants.mjs +3 -0
- package/dist/client/hooks/form-builder-hooks.cjs +203 -0
- package/dist/client/hooks/form-builder-hooks.mjs +186 -0
- package/dist/client/hooks/form-builder-resource.cjs +13 -0
- package/dist/client/hooks/form-builder-resource.mjs +11 -0
- package/dist/client/hooks/index.cjs +22 -0
- package/dist/client/hooks/index.d.cts +378 -0
- package/dist/client/hooks/index.d.mts +378 -0
- package/dist/client/hooks/index.d.ts +378 -0
- package/dist/client/hooks/index.mjs +1 -0
- package/dist/client/index.cjs +13 -0
- package/dist/client/index.d.cts +410 -0
- package/dist/client/index.d.mts +410 -0
- package/dist/client/index.d.ts +410 -0
- package/dist/client/index.mjs +2 -0
- package/dist/client/plugin.cjs +311 -0
- package/dist/client/plugin.mjs +309 -0
- package/dist/client.css +3 -0
- package/dist/db.cjs +99 -0
- package/dist/db.mjs +97 -0
- package/dist/permissions.cjs +95 -0
- package/dist/permissions.d.cts +94 -0
- package/dist/permissions.d.mts +94 -0
- package/dist/permissions.d.ts +94 -0
- package/dist/permissions.mjs +93 -0
- package/dist/query-keys.cjs +140 -0
- package/dist/query-keys.d.cts +392 -0
- package/dist/query-keys.d.mts +392 -0
- package/dist/query-keys.d.ts +392 -0
- package/dist/query-keys.mjs +137 -0
- package/dist/schemas.cjs +91 -0
- package/dist/schemas.mjs +82 -0
- package/dist/shared/plugin-form-builder.BZYGyFgT.d.mts +351 -0
- package/dist/shared/plugin-form-builder.Bbl9NufB.d.cts +408 -0
- package/dist/shared/plugin-form-builder.CSP5HR2O.d.ts +408 -0
- package/dist/shared/plugin-form-builder.Cmk083dA.d.cts +351 -0
- package/dist/shared/plugin-form-builder.D258Qpb8.d.ts +351 -0
- package/dist/shared/plugin-form-builder.DWrQ3lRX.d.cts +118 -0
- package/dist/shared/plugin-form-builder.DWrQ3lRX.d.mts +118 -0
- package/dist/shared/plugin-form-builder.DWrQ3lRX.d.ts +118 -0
- package/dist/shared/plugin-form-builder.lp98rFNl.d.mts +408 -0
- package/dist/style.css +6 -0
- package/dist/types.cjs +2 -0
- package/dist/types.d.cts +6 -0
- package/dist/types.d.mts +6 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.mjs +1 -0
- package/dist/ui/src/components/accordion.cjs +81 -0
- package/dist/ui/src/components/accordion.mjs +62 -0
- package/dist/ui/src/components/alert-dialog.cjs +157 -0
- package/dist/ui/src/components/alert-dialog.mjs +132 -0
- package/dist/ui/src/components/auto-form/common/label.cjs +18 -0
- package/dist/ui/src/components/auto-form/common/label.mjs +16 -0
- package/dist/ui/src/components/auto-form/common/tooltip.cjs +9 -0
- package/dist/ui/src/components/auto-form/common/tooltip.mjs +7 -0
- package/dist/ui/src/components/auto-form/config.cjs +40 -0
- package/dist/ui/src/components/auto-form/config.mjs +37 -0
- package/dist/ui/src/components/auto-form/dependencies.cjs +48 -0
- package/dist/ui/src/components/auto-form/dependencies.mjs +46 -0
- package/dist/ui/src/components/auto-form/fields/array.cjs +266 -0
- package/dist/ui/src/components/auto-form/fields/array.mjs +264 -0
- package/dist/ui/src/components/auto-form/fields/checkbox.cjs +38 -0
- package/dist/ui/src/components/auto-form/fields/checkbox.mjs +36 -0
- package/dist/ui/src/components/auto-form/fields/date.cjs +67 -0
- package/dist/ui/src/components/auto-form/fields/date.mjs +65 -0
- package/dist/ui/src/components/auto-form/fields/enum.cjs +73 -0
- package/dist/ui/src/components/auto-form/fields/enum.mjs +71 -0
- package/dist/ui/src/components/auto-form/fields/input.cjs +32 -0
- package/dist/ui/src/components/auto-form/fields/input.mjs +30 -0
- package/dist/ui/src/components/auto-form/fields/number.cjs +31 -0
- package/dist/ui/src/components/auto-form/fields/number.mjs +29 -0
- package/dist/ui/src/components/auto-form/fields/object.cjs +233 -0
- package/dist/ui/src/components/auto-form/fields/object.mjs +217 -0
- package/dist/ui/src/components/auto-form/fields/radio-group.cjs +67 -0
- package/dist/ui/src/components/auto-form/fields/radio-group.mjs +65 -0
- package/dist/ui/src/components/auto-form/fields/switch.cjs +38 -0
- package/dist/ui/src/components/auto-form/fields/switch.mjs +36 -0
- package/dist/ui/src/components/auto-form/fields/textarea.cjs +31 -0
- package/dist/ui/src/components/auto-form/fields/textarea.mjs +29 -0
- package/dist/ui/src/components/auto-form/helpers.cjs +270 -0
- package/dist/ui/src/components/auto-form/helpers.mjs +259 -0
- package/dist/ui/src/components/auto-form/index.cjs +92 -0
- package/dist/ui/src/components/auto-form/index.mjs +86 -0
- package/dist/ui/src/components/auto-form/stepped-auto-form.cjs +374 -0
- package/dist/ui/src/components/auto-form/stepped-auto-form.mjs +368 -0
- package/dist/ui/src/components/auto-form/types.cjs +11 -0
- package/dist/ui/src/components/auto-form/types.mjs +9 -0
- package/dist/ui/src/components/button.cjs +56 -0
- package/dist/ui/src/components/button.mjs +53 -0
- package/dist/ui/src/components/calendar.cjs +207 -0
- package/dist/ui/src/components/calendar.mjs +190 -0
- package/dist/ui/src/components/checkbox.cjs +48 -0
- package/dist/ui/src/components/checkbox.mjs +32 -0
- package/dist/ui/src/components/date-picker.cjs +41 -0
- package/dist/ui/src/components/date-picker.mjs +39 -0
- package/dist/ui/src/components/dialog.cjs +141 -0
- package/dist/ui/src/components/dialog.mjs +118 -0
- package/dist/ui/src/components/dropdown-menu.cjs +81 -0
- package/dist/ui/src/components/dropdown-menu.mjs +62 -0
- package/dist/ui/src/components/form-builder/canvas.cjs +111 -0
- package/dist/ui/src/components/form-builder/canvas.mjs +109 -0
- package/dist/ui/src/components/form-builder/components/index.cjs +571 -0
- package/dist/ui/src/components/form-builder/components/index.mjs +554 -0
- package/dist/ui/src/components/form-builder/edit-field-dialog.cjs +131 -0
- package/dist/ui/src/components/form-builder/edit-field-dialog.mjs +129 -0
- package/dist/ui/src/components/form-builder/form-preview.cjs +73 -0
- package/dist/ui/src/components/form-builder/form-preview.mjs +71 -0
- package/dist/ui/src/components/form-builder/index.cjs +350 -0
- package/dist/ui/src/components/form-builder/index.mjs +344 -0
- package/dist/ui/src/components/form-builder/nested-field-editor-dialog.cjs +263 -0
- package/dist/ui/src/components/form-builder/nested-field-editor-dialog.mjs +261 -0
- package/dist/ui/src/components/form-builder/palette.cjs +52 -0
- package/dist/ui/src/components/form-builder/palette.mjs +49 -0
- package/dist/ui/src/components/form-builder/schema-utils.cjs +128 -0
- package/dist/ui/src/components/form-builder/schema-utils.mjs +122 -0
- package/dist/ui/src/components/form-builder/sortable-field.cjs +151 -0
- package/dist/ui/src/components/form-builder/sortable-field.mjs +148 -0
- package/dist/ui/src/components/form-builder/step-tabs.cjs +180 -0
- package/dist/ui/src/components/form-builder/step-tabs.mjs +178 -0
- package/dist/ui/src/components/form-builder/types.cjs +7 -0
- package/dist/ui/src/components/form-builder/types.mjs +5 -0
- package/dist/ui/src/components/form-builder/validation-schemas.cjs +67 -0
- package/dist/ui/src/components/form-builder/validation-schemas.mjs +56 -0
- package/dist/ui/src/components/form.cjs +120 -0
- package/dist/ui/src/components/form.mjs +98 -0
- package/dist/ui/src/components/input.cjs +23 -0
- package/dist/ui/src/components/input.mjs +21 -0
- package/dist/ui/src/components/label.cjs +39 -0
- package/dist/ui/src/components/label.mjs +23 -0
- package/dist/ui/src/components/page-layout.cjs +25 -0
- package/dist/ui/src/components/page-layout.mjs +23 -0
- package/dist/ui/src/components/page-wrapper.cjs +20 -0
- package/dist/ui/src/components/page-wrapper.mjs +18 -0
- package/dist/ui/src/components/popover.cjs +60 -0
- package/dist/ui/src/components/popover.mjs +42 -0
- package/dist/ui/src/components/radio-group.cjs +62 -0
- package/dist/ui/src/components/radio-group.mjs +45 -0
- package/dist/ui/src/components/select.cjs +161 -0
- package/dist/ui/src/components/select.mjs +139 -0
- package/dist/ui/src/components/separator.cjs +43 -0
- package/dist/ui/src/components/separator.mjs +27 -0
- package/dist/ui/src/components/skeleton.cjs +17 -0
- package/dist/ui/src/components/skeleton.mjs +15 -0
- package/dist/ui/src/components/stack-attribution.cjs +24 -0
- package/dist/ui/src/components/stack-attribution.mjs +22 -0
- package/dist/ui/src/components/switch.cjs +48 -0
- package/dist/ui/src/components/switch.mjs +32 -0
- package/dist/ui/src/components/table.cjs +89 -0
- package/dist/ui/src/components/table.mjs +82 -0
- package/dist/ui/src/components/tabs.cjs +84 -0
- package/dist/ui/src/components/tabs.mjs +65 -0
- package/dist/ui/src/components/textarea.cjs +20 -0
- package/dist/ui/src/components/textarea.mjs +18 -0
- package/dist/ui/src/lib/schema-converter.cjs +133 -0
- package/dist/ui/src/lib/schema-converter.mjs +127 -0
- package/dist/ui/src/lib/utils.cjs +10 -0
- package/dist/ui/src/lib/utils.mjs +8 -0
- package/dist/utils.cjs +41 -0
- package/dist/utils.mjs +32 -0
- package/package.json +175 -3
- package/README.md +0 -3
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
const React = require('react');
|
|
5
|
+
const client = require('@btst/stack/plugins/client');
|
|
6
|
+
const yar = require('@btst/yar');
|
|
7
|
+
const queryKeys = require('../query-keys.cjs');
|
|
8
|
+
const constants = require('./constants.cjs');
|
|
9
|
+
|
|
10
|
+
const FormListPageComponent = React.lazy(
|
|
11
|
+
() => import('./components/pages/form-list-page.cjs').then((m) => ({
|
|
12
|
+
default: m.FormListPageComponent
|
|
13
|
+
}))
|
|
14
|
+
);
|
|
15
|
+
const FormBuilderPageComponent = React.lazy(
|
|
16
|
+
() => import('./components/pages/form-builder-page.cjs').then((m) => ({
|
|
17
|
+
default: m.FormBuilderPageComponent
|
|
18
|
+
}))
|
|
19
|
+
);
|
|
20
|
+
const SubmissionsPageComponent = React.lazy(
|
|
21
|
+
() => import('./components/pages/submissions-page.cjs').then((m) => ({
|
|
22
|
+
default: m.SubmissionsPageComponent
|
|
23
|
+
}))
|
|
24
|
+
);
|
|
25
|
+
function resolveFormBuilderClientConfig(config, runtime) {
|
|
26
|
+
return {
|
|
27
|
+
hooks: config.hooks,
|
|
28
|
+
pageComponents: config.pageComponents,
|
|
29
|
+
apiBaseURL: runtime.api.baseURL,
|
|
30
|
+
apiBasePath: runtime.api.basePath,
|
|
31
|
+
siteBaseURL: runtime.site.baseURL,
|
|
32
|
+
siteBasePath: runtime.site.basePath,
|
|
33
|
+
queryClient: runtime.queryClient,
|
|
34
|
+
...runtime.api.headers ? { headers: runtime.api.headers } : {},
|
|
35
|
+
...runtime.api.credentials ? { credentials: runtime.api.credentials } : {}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function createFormBuilderApiClient(config) {
|
|
39
|
+
return client.createApiClient({
|
|
40
|
+
baseURL: config.apiBaseURL,
|
|
41
|
+
basePath: config.apiBasePath,
|
|
42
|
+
headers: config.headers,
|
|
43
|
+
credentials: config.credentials
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function createLoadErrorReporter(hooks, context) {
|
|
47
|
+
let reported = false;
|
|
48
|
+
return async (error) => {
|
|
49
|
+
if (reported || !hooks?.onErrorLoad) return;
|
|
50
|
+
reported = true;
|
|
51
|
+
try {
|
|
52
|
+
await hooks.onErrorLoad(
|
|
53
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
54
|
+
context
|
|
55
|
+
);
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function createFormListLoader(config) {
|
|
61
|
+
return async () => {
|
|
62
|
+
if (typeof window === "undefined") {
|
|
63
|
+
const { queryClient, apiBasePath, apiBaseURL, headers, hooks } = config;
|
|
64
|
+
const context = {
|
|
65
|
+
path: "/forms",
|
|
66
|
+
isSSR: true,
|
|
67
|
+
apiBaseURL,
|
|
68
|
+
apiBasePath,
|
|
69
|
+
headers
|
|
70
|
+
};
|
|
71
|
+
const reportError = createLoadErrorReporter(hooks, context);
|
|
72
|
+
const queries = queryKeys.createFormBuilderQueryKeys(
|
|
73
|
+
createFormBuilderApiClient(config)
|
|
74
|
+
);
|
|
75
|
+
const limit = 20;
|
|
76
|
+
const listQuery = queries.forms.list({ limit });
|
|
77
|
+
try {
|
|
78
|
+
if (hooks?.beforeLoadFormList) {
|
|
79
|
+
await hooks.beforeLoadFormList(context);
|
|
80
|
+
}
|
|
81
|
+
await queryClient.prefetchInfiniteQuery({
|
|
82
|
+
...listQuery,
|
|
83
|
+
initialPageParam: 0
|
|
84
|
+
});
|
|
85
|
+
if (hooks?.afterLoadFormList) {
|
|
86
|
+
await hooks.afterLoadFormList(context);
|
|
87
|
+
}
|
|
88
|
+
const queryState = queryClient.getQueryState(listQuery.queryKey);
|
|
89
|
+
if (queryState?.error) {
|
|
90
|
+
await reportError(queryState.error);
|
|
91
|
+
}
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (client.isConnectionError(error)) {
|
|
94
|
+
console.warn(
|
|
95
|
+
"[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.raw.formBuilder.prefetchForRoute() for SSG data prefetching."
|
|
96
|
+
);
|
|
97
|
+
} else {
|
|
98
|
+
const errToStore = client.createSanitizedSSRLoaderError();
|
|
99
|
+
await queryClient.prefetchInfiniteQuery({
|
|
100
|
+
queryKey: listQuery.queryKey,
|
|
101
|
+
queryFn: () => {
|
|
102
|
+
throw errToStore;
|
|
103
|
+
},
|
|
104
|
+
initialPageParam: 0,
|
|
105
|
+
retry: false
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
await reportError(error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function createFormBuilderLoader(id, config) {
|
|
114
|
+
return async () => {
|
|
115
|
+
if (typeof window === "undefined") {
|
|
116
|
+
const { queryClient, apiBasePath, apiBaseURL, headers, hooks } = config;
|
|
117
|
+
const context = {
|
|
118
|
+
path: id ? `/forms/${id}/edit` : "/forms/new",
|
|
119
|
+
params: id ? { id } : {},
|
|
120
|
+
isSSR: true,
|
|
121
|
+
apiBaseURL,
|
|
122
|
+
apiBasePath,
|
|
123
|
+
headers
|
|
124
|
+
};
|
|
125
|
+
const reportError = createLoadErrorReporter(hooks, context);
|
|
126
|
+
const queries = queryKeys.createFormBuilderQueryKeys(
|
|
127
|
+
createFormBuilderApiClient(config)
|
|
128
|
+
);
|
|
129
|
+
const formQuery = id ? queries.forms.forUpdate(id) : void 0;
|
|
130
|
+
try {
|
|
131
|
+
if (hooks?.beforeLoadFormBuilder) {
|
|
132
|
+
await hooks.beforeLoadFormBuilder(id, context);
|
|
133
|
+
}
|
|
134
|
+
if (id) {
|
|
135
|
+
await queryClient.prefetchQuery(formQuery);
|
|
136
|
+
}
|
|
137
|
+
if (hooks?.afterLoadFormBuilder) {
|
|
138
|
+
await hooks.afterLoadFormBuilder(id, context);
|
|
139
|
+
}
|
|
140
|
+
if (id) {
|
|
141
|
+
const queryState = queryClient.getQueryState(formQuery.queryKey);
|
|
142
|
+
if (queryState?.error) {
|
|
143
|
+
await reportError(queryState.error);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} catch (error) {
|
|
147
|
+
if (client.isConnectionError(error)) {
|
|
148
|
+
console.warn(
|
|
149
|
+
"[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.raw.formBuilder.prefetchForRoute() for SSG data prefetching."
|
|
150
|
+
);
|
|
151
|
+
} else if (formQuery) {
|
|
152
|
+
const errToStore = client.createSanitizedSSRLoaderError();
|
|
153
|
+
await queryClient.prefetchQuery({
|
|
154
|
+
queryKey: formQuery.queryKey,
|
|
155
|
+
queryFn: () => {
|
|
156
|
+
throw errToStore;
|
|
157
|
+
},
|
|
158
|
+
retry: false
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
await reportError(error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function createSubmissionsLoader(formId, config) {
|
|
167
|
+
return async () => {
|
|
168
|
+
if (typeof window === "undefined") {
|
|
169
|
+
const { queryClient, apiBasePath, apiBaseURL, headers, hooks } = config;
|
|
170
|
+
const context = {
|
|
171
|
+
path: `/forms/${formId}/submissions`,
|
|
172
|
+
params: { formId },
|
|
173
|
+
isSSR: true,
|
|
174
|
+
apiBaseURL,
|
|
175
|
+
apiBasePath,
|
|
176
|
+
headers
|
|
177
|
+
};
|
|
178
|
+
const reportError = createLoadErrorReporter(hooks, context);
|
|
179
|
+
const queries = queryKeys.createFormBuilderQueryKeys(
|
|
180
|
+
createFormBuilderApiClient(config)
|
|
181
|
+
);
|
|
182
|
+
const limit = 20;
|
|
183
|
+
const submissionsQuery = queries.formSubmissions.list({ formId, limit });
|
|
184
|
+
try {
|
|
185
|
+
if (hooks?.beforeLoadSubmissions) {
|
|
186
|
+
await hooks.beforeLoadSubmissions(formId, context);
|
|
187
|
+
}
|
|
188
|
+
await queryClient.prefetchInfiniteQuery({
|
|
189
|
+
...submissionsQuery,
|
|
190
|
+
initialPageParam: 0
|
|
191
|
+
});
|
|
192
|
+
if (hooks?.afterLoadSubmissions) {
|
|
193
|
+
await hooks.afterLoadSubmissions(formId, context);
|
|
194
|
+
}
|
|
195
|
+
const submissionsState = queryClient.getQueryState(
|
|
196
|
+
submissionsQuery.queryKey
|
|
197
|
+
);
|
|
198
|
+
const queryError = submissionsState?.error;
|
|
199
|
+
if (queryError) {
|
|
200
|
+
await reportError(queryError);
|
|
201
|
+
}
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (client.isConnectionError(error)) {
|
|
204
|
+
console.warn(
|
|
205
|
+
"[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.raw.formBuilder.prefetchForRoute() for SSG data prefetching."
|
|
206
|
+
);
|
|
207
|
+
} else {
|
|
208
|
+
const errToStore = client.createSanitizedSSRLoaderError();
|
|
209
|
+
await queryClient.prefetchInfiniteQuery({
|
|
210
|
+
queryKey: submissionsQuery.queryKey,
|
|
211
|
+
queryFn: () => {
|
|
212
|
+
throw errToStore;
|
|
213
|
+
},
|
|
214
|
+
initialPageParam: 0,
|
|
215
|
+
retry: false
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
await reportError(error);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function createFormListMeta() {
|
|
224
|
+
return () => {
|
|
225
|
+
const title = "Forms";
|
|
226
|
+
return [
|
|
227
|
+
{ title },
|
|
228
|
+
{ name: "title", content: title },
|
|
229
|
+
{ name: "robots", content: "noindex" }
|
|
230
|
+
];
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function createFormBuilderMeta(id, config) {
|
|
234
|
+
return () => {
|
|
235
|
+
const { queryClient } = config;
|
|
236
|
+
let formName = "";
|
|
237
|
+
if (id) {
|
|
238
|
+
const queries = queryKeys.createFormBuilderQueryKeys(
|
|
239
|
+
createFormBuilderApiClient(config)
|
|
240
|
+
);
|
|
241
|
+
const form = queryClient.getQueryData(
|
|
242
|
+
queries.forms.forUpdate(id).queryKey
|
|
243
|
+
);
|
|
244
|
+
formName = form?.name || "";
|
|
245
|
+
}
|
|
246
|
+
const title = id ? `Edit ${formName || "Form"}` : "New Form";
|
|
247
|
+
return [
|
|
248
|
+
{ title },
|
|
249
|
+
{ name: "title", content: title },
|
|
250
|
+
{ name: "robots", content: "noindex" }
|
|
251
|
+
];
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function createSubmissionsMeta(formId, config) {
|
|
255
|
+
return () => {
|
|
256
|
+
const { queryClient } = config;
|
|
257
|
+
const queries = queryKeys.createFormBuilderQueryKeys(
|
|
258
|
+
createFormBuilderApiClient(config)
|
|
259
|
+
);
|
|
260
|
+
const data = queryClient.getQueryData(
|
|
261
|
+
queries.formSubmissions.list({ formId, limit: 20 }).queryKey
|
|
262
|
+
);
|
|
263
|
+
const form = data?.pages?.[0]?.form;
|
|
264
|
+
const title = form?.name ? `${form.name} Submissions` : "Submissions";
|
|
265
|
+
return [
|
|
266
|
+
{ title },
|
|
267
|
+
{ name: "title", content: title },
|
|
268
|
+
{ name: "robots", content: "noindex" }
|
|
269
|
+
];
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function createResolvedFormBuilderPlugin(config) {
|
|
273
|
+
return {
|
|
274
|
+
routes: () => yar.defineRoutes(
|
|
275
|
+
{
|
|
276
|
+
formList: yar.defineRoute("/forms", {
|
|
277
|
+
page: FormListPageComponent,
|
|
278
|
+
loader: createFormListLoader(config),
|
|
279
|
+
meta: createFormListMeta()
|
|
280
|
+
}),
|
|
281
|
+
newForm: yar.defineRoute("/forms/new", {
|
|
282
|
+
page: () => /* @__PURE__ */ jsxRuntime.jsx(FormBuilderPageComponent, {}),
|
|
283
|
+
loader: createFormBuilderLoader(void 0, config),
|
|
284
|
+
meta: createFormBuilderMeta(void 0, config)
|
|
285
|
+
}),
|
|
286
|
+
editForm: yar.defineRoute("/forms/:id/edit", {
|
|
287
|
+
page: ({ params }) => /* @__PURE__ */ jsxRuntime.jsx(FormBuilderPageComponent, { id: params.id }),
|
|
288
|
+
loader: ({ params }) => createFormBuilderLoader(params.id, config)(),
|
|
289
|
+
meta: ({ params }) => createFormBuilderMeta(params.id, config)()
|
|
290
|
+
}),
|
|
291
|
+
submissions: yar.defineRoute("/forms/:id/submissions", {
|
|
292
|
+
page: ({ params }) => /* @__PURE__ */ jsxRuntime.jsx(SubmissionsPageComponent, { formId: params.id }),
|
|
293
|
+
loader: ({ params }) => createSubmissionsLoader(params.id, config)(),
|
|
294
|
+
meta: ({ params }) => createSubmissionsMeta(params.id, config)()
|
|
295
|
+
})
|
|
296
|
+
},
|
|
297
|
+
{ pages: config.pageComponents }
|
|
298
|
+
),
|
|
299
|
+
sitemap: async () => {
|
|
300
|
+
return [];
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
const formBuilderClientPlugin = (config = {}) => client.defineClientPlugin()({
|
|
305
|
+
id: constants.FORM_BUILDER_PLUGIN_ID,
|
|
306
|
+
resolve: (runtime) => createResolvedFormBuilderPlugin(
|
|
307
|
+
resolveFormBuilderClientConfig(config, runtime)
|
|
308
|
+
)
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
exports.formBuilderClientPlugin = formBuilderClientPlugin;
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { lazy } from 'react';
|
|
3
|
+
import { defineClientPlugin, isConnectionError, createSanitizedSSRLoaderError, createApiClient } from '@btst/stack/plugins/client';
|
|
4
|
+
import { defineRoutes, defineRoute } from '@btst/yar';
|
|
5
|
+
import { createFormBuilderQueryKeys } from '../query-keys.mjs';
|
|
6
|
+
import { FORM_BUILDER_PLUGIN_ID } from './constants.mjs';
|
|
7
|
+
|
|
8
|
+
const FormListPageComponent = lazy(
|
|
9
|
+
() => import('./components/pages/form-list-page.mjs').then((m) => ({
|
|
10
|
+
default: m.FormListPageComponent
|
|
11
|
+
}))
|
|
12
|
+
);
|
|
13
|
+
const FormBuilderPageComponent = lazy(
|
|
14
|
+
() => import('./components/pages/form-builder-page.mjs').then((m) => ({
|
|
15
|
+
default: m.FormBuilderPageComponent
|
|
16
|
+
}))
|
|
17
|
+
);
|
|
18
|
+
const SubmissionsPageComponent = lazy(
|
|
19
|
+
() => import('./components/pages/submissions-page.mjs').then((m) => ({
|
|
20
|
+
default: m.SubmissionsPageComponent
|
|
21
|
+
}))
|
|
22
|
+
);
|
|
23
|
+
function resolveFormBuilderClientConfig(config, runtime) {
|
|
24
|
+
return {
|
|
25
|
+
hooks: config.hooks,
|
|
26
|
+
pageComponents: config.pageComponents,
|
|
27
|
+
apiBaseURL: runtime.api.baseURL,
|
|
28
|
+
apiBasePath: runtime.api.basePath,
|
|
29
|
+
siteBaseURL: runtime.site.baseURL,
|
|
30
|
+
siteBasePath: runtime.site.basePath,
|
|
31
|
+
queryClient: runtime.queryClient,
|
|
32
|
+
...runtime.api.headers ? { headers: runtime.api.headers } : {},
|
|
33
|
+
...runtime.api.credentials ? { credentials: runtime.api.credentials } : {}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function createFormBuilderApiClient(config) {
|
|
37
|
+
return createApiClient({
|
|
38
|
+
baseURL: config.apiBaseURL,
|
|
39
|
+
basePath: config.apiBasePath,
|
|
40
|
+
headers: config.headers,
|
|
41
|
+
credentials: config.credentials
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function createLoadErrorReporter(hooks, context) {
|
|
45
|
+
let reported = false;
|
|
46
|
+
return async (error) => {
|
|
47
|
+
if (reported || !hooks?.onErrorLoad) return;
|
|
48
|
+
reported = true;
|
|
49
|
+
try {
|
|
50
|
+
await hooks.onErrorLoad(
|
|
51
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
52
|
+
context
|
|
53
|
+
);
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function createFormListLoader(config) {
|
|
59
|
+
return async () => {
|
|
60
|
+
if (typeof window === "undefined") {
|
|
61
|
+
const { queryClient, apiBasePath, apiBaseURL, headers, hooks } = config;
|
|
62
|
+
const context = {
|
|
63
|
+
path: "/forms",
|
|
64
|
+
isSSR: true,
|
|
65
|
+
apiBaseURL,
|
|
66
|
+
apiBasePath,
|
|
67
|
+
headers
|
|
68
|
+
};
|
|
69
|
+
const reportError = createLoadErrorReporter(hooks, context);
|
|
70
|
+
const queries = createFormBuilderQueryKeys(
|
|
71
|
+
createFormBuilderApiClient(config)
|
|
72
|
+
);
|
|
73
|
+
const limit = 20;
|
|
74
|
+
const listQuery = queries.forms.list({ limit });
|
|
75
|
+
try {
|
|
76
|
+
if (hooks?.beforeLoadFormList) {
|
|
77
|
+
await hooks.beforeLoadFormList(context);
|
|
78
|
+
}
|
|
79
|
+
await queryClient.prefetchInfiniteQuery({
|
|
80
|
+
...listQuery,
|
|
81
|
+
initialPageParam: 0
|
|
82
|
+
});
|
|
83
|
+
if (hooks?.afterLoadFormList) {
|
|
84
|
+
await hooks.afterLoadFormList(context);
|
|
85
|
+
}
|
|
86
|
+
const queryState = queryClient.getQueryState(listQuery.queryKey);
|
|
87
|
+
if (queryState?.error) {
|
|
88
|
+
await reportError(queryState.error);
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (isConnectionError(error)) {
|
|
92
|
+
console.warn(
|
|
93
|
+
"[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.raw.formBuilder.prefetchForRoute() for SSG data prefetching."
|
|
94
|
+
);
|
|
95
|
+
} else {
|
|
96
|
+
const errToStore = createSanitizedSSRLoaderError();
|
|
97
|
+
await queryClient.prefetchInfiniteQuery({
|
|
98
|
+
queryKey: listQuery.queryKey,
|
|
99
|
+
queryFn: () => {
|
|
100
|
+
throw errToStore;
|
|
101
|
+
},
|
|
102
|
+
initialPageParam: 0,
|
|
103
|
+
retry: false
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
await reportError(error);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function createFormBuilderLoader(id, config) {
|
|
112
|
+
return async () => {
|
|
113
|
+
if (typeof window === "undefined") {
|
|
114
|
+
const { queryClient, apiBasePath, apiBaseURL, headers, hooks } = config;
|
|
115
|
+
const context = {
|
|
116
|
+
path: id ? `/forms/${id}/edit` : "/forms/new",
|
|
117
|
+
params: id ? { id } : {},
|
|
118
|
+
isSSR: true,
|
|
119
|
+
apiBaseURL,
|
|
120
|
+
apiBasePath,
|
|
121
|
+
headers
|
|
122
|
+
};
|
|
123
|
+
const reportError = createLoadErrorReporter(hooks, context);
|
|
124
|
+
const queries = createFormBuilderQueryKeys(
|
|
125
|
+
createFormBuilderApiClient(config)
|
|
126
|
+
);
|
|
127
|
+
const formQuery = id ? queries.forms.forUpdate(id) : void 0;
|
|
128
|
+
try {
|
|
129
|
+
if (hooks?.beforeLoadFormBuilder) {
|
|
130
|
+
await hooks.beforeLoadFormBuilder(id, context);
|
|
131
|
+
}
|
|
132
|
+
if (id) {
|
|
133
|
+
await queryClient.prefetchQuery(formQuery);
|
|
134
|
+
}
|
|
135
|
+
if (hooks?.afterLoadFormBuilder) {
|
|
136
|
+
await hooks.afterLoadFormBuilder(id, context);
|
|
137
|
+
}
|
|
138
|
+
if (id) {
|
|
139
|
+
const queryState = queryClient.getQueryState(formQuery.queryKey);
|
|
140
|
+
if (queryState?.error) {
|
|
141
|
+
await reportError(queryState.error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (isConnectionError(error)) {
|
|
146
|
+
console.warn(
|
|
147
|
+
"[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.raw.formBuilder.prefetchForRoute() for SSG data prefetching."
|
|
148
|
+
);
|
|
149
|
+
} else if (formQuery) {
|
|
150
|
+
const errToStore = createSanitizedSSRLoaderError();
|
|
151
|
+
await queryClient.prefetchQuery({
|
|
152
|
+
queryKey: formQuery.queryKey,
|
|
153
|
+
queryFn: () => {
|
|
154
|
+
throw errToStore;
|
|
155
|
+
},
|
|
156
|
+
retry: false
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
await reportError(error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function createSubmissionsLoader(formId, config) {
|
|
165
|
+
return async () => {
|
|
166
|
+
if (typeof window === "undefined") {
|
|
167
|
+
const { queryClient, apiBasePath, apiBaseURL, headers, hooks } = config;
|
|
168
|
+
const context = {
|
|
169
|
+
path: `/forms/${formId}/submissions`,
|
|
170
|
+
params: { formId },
|
|
171
|
+
isSSR: true,
|
|
172
|
+
apiBaseURL,
|
|
173
|
+
apiBasePath,
|
|
174
|
+
headers
|
|
175
|
+
};
|
|
176
|
+
const reportError = createLoadErrorReporter(hooks, context);
|
|
177
|
+
const queries = createFormBuilderQueryKeys(
|
|
178
|
+
createFormBuilderApiClient(config)
|
|
179
|
+
);
|
|
180
|
+
const limit = 20;
|
|
181
|
+
const submissionsQuery = queries.formSubmissions.list({ formId, limit });
|
|
182
|
+
try {
|
|
183
|
+
if (hooks?.beforeLoadSubmissions) {
|
|
184
|
+
await hooks.beforeLoadSubmissions(formId, context);
|
|
185
|
+
}
|
|
186
|
+
await queryClient.prefetchInfiniteQuery({
|
|
187
|
+
...submissionsQuery,
|
|
188
|
+
initialPageParam: 0
|
|
189
|
+
});
|
|
190
|
+
if (hooks?.afterLoadSubmissions) {
|
|
191
|
+
await hooks.afterLoadSubmissions(formId, context);
|
|
192
|
+
}
|
|
193
|
+
const submissionsState = queryClient.getQueryState(
|
|
194
|
+
submissionsQuery.queryKey
|
|
195
|
+
);
|
|
196
|
+
const queryError = submissionsState?.error;
|
|
197
|
+
if (queryError) {
|
|
198
|
+
await reportError(queryError);
|
|
199
|
+
}
|
|
200
|
+
} catch (error) {
|
|
201
|
+
if (isConnectionError(error)) {
|
|
202
|
+
console.warn(
|
|
203
|
+
"[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.raw.formBuilder.prefetchForRoute() for SSG data prefetching."
|
|
204
|
+
);
|
|
205
|
+
} else {
|
|
206
|
+
const errToStore = createSanitizedSSRLoaderError();
|
|
207
|
+
await queryClient.prefetchInfiniteQuery({
|
|
208
|
+
queryKey: submissionsQuery.queryKey,
|
|
209
|
+
queryFn: () => {
|
|
210
|
+
throw errToStore;
|
|
211
|
+
},
|
|
212
|
+
initialPageParam: 0,
|
|
213
|
+
retry: false
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
await reportError(error);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function createFormListMeta() {
|
|
222
|
+
return () => {
|
|
223
|
+
const title = "Forms";
|
|
224
|
+
return [
|
|
225
|
+
{ title },
|
|
226
|
+
{ name: "title", content: title },
|
|
227
|
+
{ name: "robots", content: "noindex" }
|
|
228
|
+
];
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function createFormBuilderMeta(id, config) {
|
|
232
|
+
return () => {
|
|
233
|
+
const { queryClient } = config;
|
|
234
|
+
let formName = "";
|
|
235
|
+
if (id) {
|
|
236
|
+
const queries = createFormBuilderQueryKeys(
|
|
237
|
+
createFormBuilderApiClient(config)
|
|
238
|
+
);
|
|
239
|
+
const form = queryClient.getQueryData(
|
|
240
|
+
queries.forms.forUpdate(id).queryKey
|
|
241
|
+
);
|
|
242
|
+
formName = form?.name || "";
|
|
243
|
+
}
|
|
244
|
+
const title = id ? `Edit ${formName || "Form"}` : "New Form";
|
|
245
|
+
return [
|
|
246
|
+
{ title },
|
|
247
|
+
{ name: "title", content: title },
|
|
248
|
+
{ name: "robots", content: "noindex" }
|
|
249
|
+
];
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function createSubmissionsMeta(formId, config) {
|
|
253
|
+
return () => {
|
|
254
|
+
const { queryClient } = config;
|
|
255
|
+
const queries = createFormBuilderQueryKeys(
|
|
256
|
+
createFormBuilderApiClient(config)
|
|
257
|
+
);
|
|
258
|
+
const data = queryClient.getQueryData(
|
|
259
|
+
queries.formSubmissions.list({ formId, limit: 20 }).queryKey
|
|
260
|
+
);
|
|
261
|
+
const form = data?.pages?.[0]?.form;
|
|
262
|
+
const title = form?.name ? `${form.name} Submissions` : "Submissions";
|
|
263
|
+
return [
|
|
264
|
+
{ title },
|
|
265
|
+
{ name: "title", content: title },
|
|
266
|
+
{ name: "robots", content: "noindex" }
|
|
267
|
+
];
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
function createResolvedFormBuilderPlugin(config) {
|
|
271
|
+
return {
|
|
272
|
+
routes: () => defineRoutes(
|
|
273
|
+
{
|
|
274
|
+
formList: defineRoute("/forms", {
|
|
275
|
+
page: FormListPageComponent,
|
|
276
|
+
loader: createFormListLoader(config),
|
|
277
|
+
meta: createFormListMeta()
|
|
278
|
+
}),
|
|
279
|
+
newForm: defineRoute("/forms/new", {
|
|
280
|
+
page: () => /* @__PURE__ */ jsx(FormBuilderPageComponent, {}),
|
|
281
|
+
loader: createFormBuilderLoader(void 0, config),
|
|
282
|
+
meta: createFormBuilderMeta(void 0, config)
|
|
283
|
+
}),
|
|
284
|
+
editForm: defineRoute("/forms/:id/edit", {
|
|
285
|
+
page: ({ params }) => /* @__PURE__ */ jsx(FormBuilderPageComponent, { id: params.id }),
|
|
286
|
+
loader: ({ params }) => createFormBuilderLoader(params.id, config)(),
|
|
287
|
+
meta: ({ params }) => createFormBuilderMeta(params.id, config)()
|
|
288
|
+
}),
|
|
289
|
+
submissions: defineRoute("/forms/:id/submissions", {
|
|
290
|
+
page: ({ params }) => /* @__PURE__ */ jsx(SubmissionsPageComponent, { formId: params.id }),
|
|
291
|
+
loader: ({ params }) => createSubmissionsLoader(params.id, config)(),
|
|
292
|
+
meta: ({ params }) => createSubmissionsMeta(params.id, config)()
|
|
293
|
+
})
|
|
294
|
+
},
|
|
295
|
+
{ pages: config.pageComponents }
|
|
296
|
+
),
|
|
297
|
+
sitemap: async () => {
|
|
298
|
+
return [];
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
const formBuilderClientPlugin = (config = {}) => defineClientPlugin()({
|
|
303
|
+
id: FORM_BUILDER_PLUGIN_ID,
|
|
304
|
+
resolve: (runtime) => createResolvedFormBuilderPlugin(
|
|
305
|
+
resolveFormBuilderClientConfig(config, runtime)
|
|
306
|
+
)
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
export { formBuilderClientPlugin };
|
package/dist/client.css
ADDED