@acoustte-digital-services/digitalstore-controls-dev 0.8.1-dev.20260704091052 → 0.8.1-dev.20260706114046
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/CopyButton-UPJPMJUB.mjs +57 -0
- package/dist/DateTimeViewClient-R3M6ISVK.mjs +16 -0
- package/dist/DateViewClient-VLTRN47D.mjs +9 -0
- package/dist/{chunk-SDNYBQSI.mjs → HlsPlayer-57543DTW.mjs} +3 -2
- package/dist/HlsPlayer-5AWFZ2P6.mjs +601 -0
- package/dist/IframeClient-RGJFZ5P2.mjs +98 -0
- package/dist/InputControlClient-NJV6B65M.mjs +604 -0
- package/dist/InputControlClient-OQDLYA4S.mjs +604 -0
- package/dist/InputControlClient-TW664WIJ.mjs +602 -0
- package/dist/{LinkNodeButton-WDDPNYWI.mjs → LinkNodeButton-FUL3J5HR.mjs} +6 -5
- package/dist/LinkNodeButton-IGJOGOKI.mjs +362 -0
- package/dist/LinkNodeButton-ZONM74OO.mjs +174 -0
- package/dist/Pagination-6OFACRMQ.mjs +229 -0
- package/dist/Pagination-FSYLYKUA.mjs +181 -0
- package/dist/Pagination-YCD5CU2L.mjs +183 -0
- package/dist/Slider-554BKC7N.mjs +322 -0
- package/dist/Slider-PEIVH6A5.mjs +320 -0
- package/dist/chunk-2GSYECIS.mjs +109 -0
- package/dist/chunk-3GWLDT7C.mjs +204 -0
- package/dist/chunk-3R4VVVNK.mjs +903 -0
- package/dist/chunk-47HD7QP7.mjs +199 -0
- package/dist/chunk-56HSDML5.mjs +22 -0
- package/dist/chunk-67IG5NBU.mjs +200 -0
- package/dist/chunk-7ZFZLN56.mjs +903 -0
- package/dist/chunk-CM7LUGCH.mjs +107 -0
- package/dist/chunk-IKIXEQPV.mjs +198 -0
- package/dist/chunk-IMNQO57B.mjs +25 -0
- package/dist/chunk-R2HV35IB.mjs +201 -0
- package/dist/chunk-SPRVN5IM.mjs +118 -0
- package/dist/chunk-TVL6KVD5.mjs +229 -0
- package/dist/chunk-WEV5U33G.mjs +207 -0
- package/dist/chunk-YG6FKKQJ.mjs +900 -0
- package/dist/index.d.mts +56 -169
- package/dist/index.d.ts +56 -169
- package/dist/index.js +3940 -3807
- package/dist/index.mjs +591 -2923
- package/dist/server.d.mts +72 -0
- package/dist/server.d.ts +72 -0
- package/dist/server.js +5126 -0
- package/dist/server.mjs +2698 -0
- package/package.json +18 -4
- package/dist/HlsPlayer-DZNDKG2P.mjs +0 -7
- package/dist/chunk-DOKQUUH3.mjs +0 -414
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
ServiceClient_default
|
|
4
|
+
} from "./chunk-3GWLDT7C.mjs";
|
|
5
|
+
import {
|
|
6
|
+
buttonClasses,
|
|
7
|
+
progressClasses
|
|
8
|
+
} from "./chunk-56HSDML5.mjs";
|
|
9
|
+
|
|
10
|
+
// src/components/pageRenderingEngine/nodes/LinkNodeButton.tsx
|
|
11
|
+
import { useCallback, useState as useState3 } from "react";
|
|
12
|
+
|
|
13
|
+
// src/components/Button.tsx
|
|
14
|
+
import React3, { useState as useState2 } from "react";
|
|
15
|
+
|
|
16
|
+
// src/components/ToastService.tsx
|
|
17
|
+
var ToastService = class _ToastService {
|
|
18
|
+
static initialize(showToast, closeToast) {
|
|
19
|
+
_ToastService.showToast = showToast;
|
|
20
|
+
_ToastService.closeToast = closeToast;
|
|
21
|
+
}
|
|
22
|
+
static showError(message) {
|
|
23
|
+
if (_ToastService.showToast) {
|
|
24
|
+
_ToastService.showToast(message, "error");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
static showInfo(message) {
|
|
28
|
+
if (_ToastService.showToast) {
|
|
29
|
+
_ToastService.showToast(message, "info");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
static showWarning(message) {
|
|
33
|
+
if (_ToastService.showToast) {
|
|
34
|
+
_ToastService.showToast(message, "warning");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
static showSuccess(message) {
|
|
38
|
+
if (_ToastService.showToast) {
|
|
39
|
+
_ToastService.showToast(message, "success");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
static close() {
|
|
43
|
+
if (_ToastService.closeToast) {
|
|
44
|
+
_ToastService.closeToast();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var ToastService_default = ToastService;
|
|
49
|
+
|
|
50
|
+
// src/components/Confirm.tsx
|
|
51
|
+
import { useState } from "react";
|
|
52
|
+
|
|
53
|
+
// src/components/ClientButton.tsx
|
|
54
|
+
import React from "react";
|
|
55
|
+
import { jsx } from "react/jsx-runtime";
|
|
56
|
+
var ClientButton = (props) => {
|
|
57
|
+
const execute = async (event) => {
|
|
58
|
+
if (props.onClick !== void 0) {
|
|
59
|
+
props.onClick();
|
|
60
|
+
} else {
|
|
61
|
+
ToastService_default.showError("No action defined.");
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
let buttonClass = props.ButtonType ? buttonClasses.get(props.ButtonType) : buttonClasses.get("Primary" /* Solid */);
|
|
65
|
+
return /* @__PURE__ */ jsx(React.Fragment, { children: /* @__PURE__ */ jsx(
|
|
66
|
+
"button",
|
|
67
|
+
{
|
|
68
|
+
type: "button",
|
|
69
|
+
onClick: execute,
|
|
70
|
+
className: buttonClass + " " + props.className,
|
|
71
|
+
children: props.children
|
|
72
|
+
}
|
|
73
|
+
) });
|
|
74
|
+
};
|
|
75
|
+
var ClientButton_default = ClientButton;
|
|
76
|
+
|
|
77
|
+
// src/components/Confirm.tsx
|
|
78
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
79
|
+
var Confirm = ({ message, onConfirm, onCancel }) => {
|
|
80
|
+
const [showModal, setShowModal] = useState(true);
|
|
81
|
+
const handleConfirmAction = () => {
|
|
82
|
+
setShowModal(false);
|
|
83
|
+
if (onConfirm) {
|
|
84
|
+
onConfirm();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const handleCancelAction = () => {
|
|
88
|
+
setShowModal(false);
|
|
89
|
+
if (onCancel) {
|
|
90
|
+
onCancel();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
return /* @__PURE__ */ jsx2(Fragment, { children: showModal && /* @__PURE__ */ jsxs("div", { className: "fixed inset-0 flex items-center justify-center z-50", children: [
|
|
94
|
+
/* @__PURE__ */ jsx2("div", { className: "absolute inset-0 bg-black opacity-70" }),
|
|
95
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-white rounded-md p-6 w-2/6 shadow border z-50", children: [
|
|
96
|
+
/* @__PURE__ */ jsx2("p", { className: "text-xl font-medium mb-4", children: "Confirmation" }),
|
|
97
|
+
/* @__PURE__ */ jsx2("p", { className: "mb-4", children: message }),
|
|
98
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-8", children: [
|
|
99
|
+
/* @__PURE__ */ jsx2(
|
|
100
|
+
ClientButton_default,
|
|
101
|
+
{
|
|
102
|
+
onClick: handleCancelAction,
|
|
103
|
+
ButtonType: "PrimaryHollow" /* Hollow */,
|
|
104
|
+
children: "Cancel"
|
|
105
|
+
}
|
|
106
|
+
),
|
|
107
|
+
/* @__PURE__ */ jsx2(
|
|
108
|
+
ClientButton_default,
|
|
109
|
+
{
|
|
110
|
+
onClick: handleConfirmAction,
|
|
111
|
+
children: "Confirm"
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
] })
|
|
115
|
+
] })
|
|
116
|
+
] }) });
|
|
117
|
+
};
|
|
118
|
+
var Confirm_default = Confirm;
|
|
119
|
+
{
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/components/Button.tsx
|
|
123
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
124
|
+
var Button = (props) => {
|
|
125
|
+
const [inProgress, setInProgress] = useState2(false);
|
|
126
|
+
const [isActionPerformed, setIsActionPerformed] = useState2(false);
|
|
127
|
+
const [responseMessage, setResponseMessage] = useState2(null);
|
|
128
|
+
const [showModal, setShowModal] = useState2(null);
|
|
129
|
+
const execute = async (event) => {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
event.stopPropagation();
|
|
132
|
+
if (props.confirm) {
|
|
133
|
+
const confirmed = await showConfirmation("Are you sure you want to delete this item?");
|
|
134
|
+
setShowModal(null);
|
|
135
|
+
if (!confirmed) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (props.oneTimeAction && isActionPerformed) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
setInProgress(true);
|
|
143
|
+
let isValid = true;
|
|
144
|
+
if (props.onValidate !== void 0) {
|
|
145
|
+
isValid = await props.onValidate();
|
|
146
|
+
if (!isValid) {
|
|
147
|
+
setInProgress(false);
|
|
148
|
+
ToastService_default.showError("There are errors in the form. Please fix them before proceeding.");
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (props.onClick !== void 0) {
|
|
153
|
+
let response = await props.onClick();
|
|
154
|
+
if (response.isSuccessful) {
|
|
155
|
+
setIsActionPerformed(true);
|
|
156
|
+
setResponseMessage(response.message);
|
|
157
|
+
if (props.showToast) {
|
|
158
|
+
ToastService_default.showInfo(response.message || "");
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
ToastService_default.showError(response.message || "");
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
ToastService_default.showError("No action defined.");
|
|
165
|
+
}
|
|
166
|
+
setInProgress(false);
|
|
167
|
+
};
|
|
168
|
+
const showConfirmation = (message) => {
|
|
169
|
+
return new Promise((resolve) => {
|
|
170
|
+
const onConfirm = () => resolve(true);
|
|
171
|
+
const onCancel = () => resolve(false);
|
|
172
|
+
setShowModal(/* @__PURE__ */ jsx3(Confirm_default, { message: props.confirmationMessage, onConfirm, onCancel }));
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
let buttonClass = props.ButtonType ? buttonClasses.get(props.ButtonType) : buttonClasses.get("Primary" /* Solid */);
|
|
176
|
+
let progressClass = props.ButtonType ? progressClasses.get(props.ButtonType) : progressClasses.get("Primary" /* Solid */);
|
|
177
|
+
const isDisabled = inProgress || isActionPerformed && props.oneTimeAction;
|
|
178
|
+
return /* @__PURE__ */ jsxs2(React3.Fragment, { children: [
|
|
179
|
+
/* @__PURE__ */ jsxs2(
|
|
180
|
+
"button",
|
|
181
|
+
{
|
|
182
|
+
type: "submit",
|
|
183
|
+
onClick: execute,
|
|
184
|
+
disabled: props.disabled,
|
|
185
|
+
title: isDisabled ? "The button is disabled to prevent any action" : "",
|
|
186
|
+
className: buttonClass + " relative " + props.className,
|
|
187
|
+
children: [
|
|
188
|
+
isActionPerformed && props.oneTimeAction && responseMessage ? responseMessage : props.children,
|
|
189
|
+
inProgress && /* @__PURE__ */ jsx3(React3.Fragment, { children: props.hideProgressIndicator === true ? /* @__PURE__ */ jsx3("div", { className: "absolute bottom-0 left-0 h-0.5 bg-gray-400 rounded animate-progress" }) : /* @__PURE__ */ jsxs2("svg", { className: "animate-spin ml-2 mr-3 h-5 w-5 " + progressClass, xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
|
|
190
|
+
/* @__PURE__ */ jsx3("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
|
|
191
|
+
/* @__PURE__ */ jsx3("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })
|
|
192
|
+
] }) })
|
|
193
|
+
]
|
|
194
|
+
}
|
|
195
|
+
),
|
|
196
|
+
showModal
|
|
197
|
+
] });
|
|
198
|
+
};
|
|
199
|
+
var Button_default = Button;
|
|
200
|
+
|
|
201
|
+
// src/components/pageRenderingEngine/nodes/LinkNodeButton.tsx
|
|
202
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
203
|
+
var LinkNodeButton = (props) => {
|
|
204
|
+
const { node, dataitem, children, linkText, linkType, linkUrl } = props;
|
|
205
|
+
const [isLoading, setIsLoading] = useState3(false);
|
|
206
|
+
const [error, setError] = useState3(null);
|
|
207
|
+
const extractFieldNames = useCallback((template) => {
|
|
208
|
+
if (!template) return [];
|
|
209
|
+
const regex = /\{(\{\})?([a-zA-Z_$][a-zA-Z0-9_$]*)(?:\}\})?\}/g;
|
|
210
|
+
const matches = Array.from(template.matchAll(regex));
|
|
211
|
+
const fieldNames = matches.map((match) => match[2] || match[1]).filter((name, index, self) => self.indexOf(name) === index);
|
|
212
|
+
return fieldNames;
|
|
213
|
+
}, []);
|
|
214
|
+
const replaceTemplateVariables = useCallback((template, responseData) => {
|
|
215
|
+
if (!template) return template;
|
|
216
|
+
let result = template;
|
|
217
|
+
const fieldNames = extractFieldNames(template);
|
|
218
|
+
if (responseData) {
|
|
219
|
+
fieldNames.forEach((fieldName) => {
|
|
220
|
+
const value = getNestedValue(responseData, fieldName);
|
|
221
|
+
if (value !== void 0) {
|
|
222
|
+
const regex1 = new RegExp(`\\{${fieldName}\\}`, "g");
|
|
223
|
+
const regex2 = new RegExp(`\\{\\{${fieldName}\\}\\}`, "g");
|
|
224
|
+
result = result.replace(regex1, String(value));
|
|
225
|
+
result = result.replace(regex2, String(value));
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
if (props.routeParameters) {
|
|
230
|
+
Object.entries(props.routeParameters).forEach(([key, value]) => {
|
|
231
|
+
const regex = new RegExp(`\\{\\{${key}\\}\\}`, "g");
|
|
232
|
+
result = result.replace(regex, String(value));
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (dataitem) {
|
|
236
|
+
Object.entries(dataitem).forEach(([key, value]) => {
|
|
237
|
+
const regex = new RegExp(`\\{\\{${key}\\}\\}`, "g");
|
|
238
|
+
result = result.replace(regex, String(value));
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
}, [props.routeParameters, dataitem, extractFieldNames]);
|
|
243
|
+
const getNestedValue = useCallback((obj, path) => {
|
|
244
|
+
if (!obj || !path) return void 0;
|
|
245
|
+
if (obj[path] !== void 0) {
|
|
246
|
+
return obj[path];
|
|
247
|
+
}
|
|
248
|
+
const keys = path.split(".");
|
|
249
|
+
let current = obj;
|
|
250
|
+
for (const key of keys) {
|
|
251
|
+
if (current[key] === void 0) {
|
|
252
|
+
return void 0;
|
|
253
|
+
}
|
|
254
|
+
current = current[key];
|
|
255
|
+
}
|
|
256
|
+
return current;
|
|
257
|
+
}, []);
|
|
258
|
+
const onClick = useCallback(async (e) => {
|
|
259
|
+
if (!node.postUrl) {
|
|
260
|
+
setError("No POST URL configured for this button");
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
setIsLoading(true);
|
|
264
|
+
setError(null);
|
|
265
|
+
try {
|
|
266
|
+
const resolvedPostUrl = replaceTemplateVariables(node.postUrl);
|
|
267
|
+
let parsedPayload = {};
|
|
268
|
+
if (node.payload) {
|
|
269
|
+
try {
|
|
270
|
+
const payloadStr = replaceTemplateVariables(node.payload);
|
|
271
|
+
parsedPayload = JSON.parse(payloadStr);
|
|
272
|
+
console.log("Parsed payload:", parsedPayload);
|
|
273
|
+
} catch (err) {
|
|
274
|
+
console.error("Failed to parse payload JSON:", err);
|
|
275
|
+
parsedPayload = { error: "Invalid payload JSON" };
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const serviceClient = new ServiceClient_default(props.apiBaseUrl, props.session);
|
|
279
|
+
const response = await serviceClient.post(resolvedPostUrl, parsedPayload);
|
|
280
|
+
console.log("API Response:", response);
|
|
281
|
+
if (response && !response.isSuccessful) {
|
|
282
|
+
const errorMessage = response.message || "API request failed";
|
|
283
|
+
setError(errorMessage);
|
|
284
|
+
setIsLoading(false);
|
|
285
|
+
return { isSuccessful: false, message: errorMessage };
|
|
286
|
+
}
|
|
287
|
+
if (response && node.redirectUrl) {
|
|
288
|
+
const fieldNames = extractFieldNames(node.redirectUrl);
|
|
289
|
+
console.log("Field names in redirect URL:", fieldNames);
|
|
290
|
+
const fieldValueMap = {};
|
|
291
|
+
fieldNames.forEach((fieldName) => {
|
|
292
|
+
const value = getNestedValue(response, fieldName);
|
|
293
|
+
if (value !== void 0) {
|
|
294
|
+
fieldValueMap[fieldName] = String(value);
|
|
295
|
+
} else {
|
|
296
|
+
const resultValue = getNestedValue(response, `result.${fieldName}`);
|
|
297
|
+
if (resultValue !== void 0) {
|
|
298
|
+
fieldValueMap[fieldName] = String(resultValue);
|
|
299
|
+
} else {
|
|
300
|
+
const dataValue = getNestedValue(response, `data.${fieldName}`);
|
|
301
|
+
if (dataValue !== void 0) {
|
|
302
|
+
fieldValueMap[fieldName] = String(dataValue);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
console.log("Field value map:", fieldValueMap);
|
|
308
|
+
const missingFields = fieldNames.filter((fieldName) => !fieldValueMap[fieldName]);
|
|
309
|
+
if (missingFields.length > 0) {
|
|
310
|
+
console.warn(`Missing field values for: ${missingFields.join(", ")}`);
|
|
311
|
+
}
|
|
312
|
+
let resolvedRedirectUrl = node.redirectUrl;
|
|
313
|
+
Object.entries(fieldValueMap).forEach(([fieldName, value]) => {
|
|
314
|
+
const regex1 = new RegExp(`\\{${fieldName}\\}`, "g");
|
|
315
|
+
const regex2 = new RegExp(`\\{\\{${fieldName}\\}\\}`, "g");
|
|
316
|
+
resolvedRedirectUrl = resolvedRedirectUrl.replace(regex1, value);
|
|
317
|
+
resolvedRedirectUrl = resolvedRedirectUrl.replace(regex2, value);
|
|
318
|
+
});
|
|
319
|
+
resolvedRedirectUrl = replaceTemplateVariables(resolvedRedirectUrl, response);
|
|
320
|
+
console.log("Final redirect URL:", resolvedRedirectUrl);
|
|
321
|
+
if (resolvedRedirectUrl && !resolvedRedirectUrl.includes("{")) {
|
|
322
|
+
window.location.href = resolvedRedirectUrl;
|
|
323
|
+
}
|
|
324
|
+
} else if (response && !response.result && response.message) {
|
|
325
|
+
setError(response.message);
|
|
326
|
+
throw new Error(response.message);
|
|
327
|
+
} else if (!response) {
|
|
328
|
+
setError("No response from server");
|
|
329
|
+
}
|
|
330
|
+
setIsLoading(false);
|
|
331
|
+
return { isSuccessful: true, response };
|
|
332
|
+
} catch (err) {
|
|
333
|
+
console.error("Button API call failed:", err);
|
|
334
|
+
setError(err.message || "An unexpected error occurred");
|
|
335
|
+
setIsLoading(false);
|
|
336
|
+
return { isSuccessful: false, message: err.message };
|
|
337
|
+
}
|
|
338
|
+
}, [node.postUrl, node.payload, node.redirectUrl, replaceTemplateVariables, extractFieldNames, getNestedValue, props.apiBaseUrl, props.session]);
|
|
339
|
+
const renderButtonContent = () => {
|
|
340
|
+
if (children) {
|
|
341
|
+
return children;
|
|
342
|
+
}
|
|
343
|
+
if (linkText) {
|
|
344
|
+
return /* @__PURE__ */ jsx4("span", { children: linkText });
|
|
345
|
+
}
|
|
346
|
+
return node.title || "Button";
|
|
347
|
+
};
|
|
348
|
+
return /* @__PURE__ */ jsx4("div", { className: "link-button-wrapper", children: /* @__PURE__ */ jsx4(
|
|
349
|
+
Button_default,
|
|
350
|
+
{
|
|
351
|
+
ButtonType: linkType,
|
|
352
|
+
onClick,
|
|
353
|
+
disabled: isLoading,
|
|
354
|
+
className: "w-full",
|
|
355
|
+
children: renderButtonContent()
|
|
356
|
+
}
|
|
357
|
+
) });
|
|
358
|
+
};
|
|
359
|
+
var LinkNodeButton_default = LinkNodeButton;
|
|
360
|
+
export {
|
|
361
|
+
LinkNodeButton_default as default
|
|
362
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
"use client";
|
|
4
|
+
import {
|
|
5
|
+
ServiceClient_default
|
|
6
|
+
} from "./chunk-WEV5U33G.mjs";
|
|
7
|
+
import {
|
|
8
|
+
Button_default
|
|
9
|
+
} from "./chunk-67IG5NBU.mjs";
|
|
10
|
+
import "./chunk-IMNQO57B.mjs";
|
|
11
|
+
|
|
12
|
+
// src/components/pageRenderingEngine/nodes/LinkNodeButton.tsx
|
|
13
|
+
import { useCallback, useState } from "react";
|
|
14
|
+
import { jsx } from "react/jsx-runtime";
|
|
15
|
+
var LinkNodeButton = (props) => {
|
|
16
|
+
const { node, dataitem, children, linkText, linkType, linkUrl } = props;
|
|
17
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
18
|
+
const [error, setError] = useState(null);
|
|
19
|
+
const extractFieldNames = useCallback((template) => {
|
|
20
|
+
if (!template) return [];
|
|
21
|
+
const regex = /\{(\{\})?([a-zA-Z_$][a-zA-Z0-9_$]*)(?:\}\})?\}/g;
|
|
22
|
+
const matches = Array.from(template.matchAll(regex));
|
|
23
|
+
const fieldNames = matches.map((match) => match[2] || match[1]).filter((name, index, self) => self.indexOf(name) === index);
|
|
24
|
+
return fieldNames;
|
|
25
|
+
}, []);
|
|
26
|
+
const replaceTemplateVariables = useCallback((template, responseData) => {
|
|
27
|
+
if (!template) return template;
|
|
28
|
+
let result = template;
|
|
29
|
+
const fieldNames = extractFieldNames(template);
|
|
30
|
+
if (responseData) {
|
|
31
|
+
fieldNames.forEach((fieldName) => {
|
|
32
|
+
const value = getNestedValue(responseData, fieldName);
|
|
33
|
+
if (value !== void 0) {
|
|
34
|
+
const regex1 = new RegExp(`\\{${fieldName}\\}`, "g");
|
|
35
|
+
const regex2 = new RegExp(`\\{\\{${fieldName}\\}\\}`, "g");
|
|
36
|
+
result = result.replace(regex1, String(value));
|
|
37
|
+
result = result.replace(regex2, String(value));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (props.routeParameters) {
|
|
42
|
+
Object.entries(props.routeParameters).forEach(([key, value]) => {
|
|
43
|
+
const regex = new RegExp(`\\{\\{${key}\\}\\}`, "g");
|
|
44
|
+
result = result.replace(regex, String(value));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (dataitem) {
|
|
48
|
+
Object.entries(dataitem).forEach(([key, value]) => {
|
|
49
|
+
const regex = new RegExp(`\\{\\{${key}\\}\\}`, "g");
|
|
50
|
+
result = result.replace(regex, String(value));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}, [props.routeParameters, dataitem, extractFieldNames]);
|
|
55
|
+
const getNestedValue = useCallback((obj, path) => {
|
|
56
|
+
if (!obj || !path) return void 0;
|
|
57
|
+
if (obj[path] !== void 0) {
|
|
58
|
+
return obj[path];
|
|
59
|
+
}
|
|
60
|
+
const keys = path.split(".");
|
|
61
|
+
let current = obj;
|
|
62
|
+
for (const key of keys) {
|
|
63
|
+
if (current[key] === void 0) {
|
|
64
|
+
return void 0;
|
|
65
|
+
}
|
|
66
|
+
current = current[key];
|
|
67
|
+
}
|
|
68
|
+
return current;
|
|
69
|
+
}, []);
|
|
70
|
+
const onClick = useCallback(async (e) => {
|
|
71
|
+
if (!node.postUrl) {
|
|
72
|
+
setError("No POST URL configured for this button");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
setIsLoading(true);
|
|
76
|
+
setError(null);
|
|
77
|
+
try {
|
|
78
|
+
const resolvedPostUrl = replaceTemplateVariables(node.postUrl);
|
|
79
|
+
let parsedPayload = {};
|
|
80
|
+
if (node.payload) {
|
|
81
|
+
try {
|
|
82
|
+
const payloadStr = replaceTemplateVariables(node.payload);
|
|
83
|
+
parsedPayload = JSON.parse(payloadStr);
|
|
84
|
+
console.log("Parsed payload:", parsedPayload);
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.error("Failed to parse payload JSON:", err);
|
|
87
|
+
parsedPayload = { error: "Invalid payload JSON" };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const serviceClient = new ServiceClient_default(props.apiBaseUrl, props.session);
|
|
91
|
+
const response = await serviceClient.post(resolvedPostUrl, parsedPayload);
|
|
92
|
+
console.log("API Response:", response);
|
|
93
|
+
if (response && !response.isSuccessful) {
|
|
94
|
+
const errorMessage = response.message || "API request failed";
|
|
95
|
+
setError(errorMessage);
|
|
96
|
+
setIsLoading(false);
|
|
97
|
+
return { isSuccessful: false, message: errorMessage };
|
|
98
|
+
}
|
|
99
|
+
if (response && node.redirectUrl) {
|
|
100
|
+
const fieldNames = extractFieldNames(node.redirectUrl);
|
|
101
|
+
console.log("Field names in redirect URL:", fieldNames);
|
|
102
|
+
const fieldValueMap = {};
|
|
103
|
+
fieldNames.forEach((fieldName) => {
|
|
104
|
+
const value = getNestedValue(response, fieldName);
|
|
105
|
+
if (value !== void 0) {
|
|
106
|
+
fieldValueMap[fieldName] = String(value);
|
|
107
|
+
} else {
|
|
108
|
+
const resultValue = getNestedValue(response, `result.${fieldName}`);
|
|
109
|
+
if (resultValue !== void 0) {
|
|
110
|
+
fieldValueMap[fieldName] = String(resultValue);
|
|
111
|
+
} else {
|
|
112
|
+
const dataValue = getNestedValue(response, `data.${fieldName}`);
|
|
113
|
+
if (dataValue !== void 0) {
|
|
114
|
+
fieldValueMap[fieldName] = String(dataValue);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
console.log("Field value map:", fieldValueMap);
|
|
120
|
+
const missingFields = fieldNames.filter((fieldName) => !fieldValueMap[fieldName]);
|
|
121
|
+
if (missingFields.length > 0) {
|
|
122
|
+
console.warn(`Missing field values for: ${missingFields.join(", ")}`);
|
|
123
|
+
}
|
|
124
|
+
let resolvedRedirectUrl = node.redirectUrl;
|
|
125
|
+
Object.entries(fieldValueMap).forEach(([fieldName, value]) => {
|
|
126
|
+
const regex1 = new RegExp(`\\{${fieldName}\\}`, "g");
|
|
127
|
+
const regex2 = new RegExp(`\\{\\{${fieldName}\\}\\}`, "g");
|
|
128
|
+
resolvedRedirectUrl = resolvedRedirectUrl.replace(regex1, value);
|
|
129
|
+
resolvedRedirectUrl = resolvedRedirectUrl.replace(regex2, value);
|
|
130
|
+
});
|
|
131
|
+
resolvedRedirectUrl = replaceTemplateVariables(resolvedRedirectUrl, response);
|
|
132
|
+
console.log("Final redirect URL:", resolvedRedirectUrl);
|
|
133
|
+
if (resolvedRedirectUrl && !resolvedRedirectUrl.includes("{")) {
|
|
134
|
+
window.location.href = resolvedRedirectUrl;
|
|
135
|
+
}
|
|
136
|
+
} else if (response && !response.result && response.message) {
|
|
137
|
+
setError(response.message);
|
|
138
|
+
throw new Error(response.message);
|
|
139
|
+
} else if (!response) {
|
|
140
|
+
setError("No response from server");
|
|
141
|
+
}
|
|
142
|
+
setIsLoading(false);
|
|
143
|
+
return { isSuccessful: true, response };
|
|
144
|
+
} catch (err) {
|
|
145
|
+
console.error("Button API call failed:", err);
|
|
146
|
+
setError(err.message || "An unexpected error occurred");
|
|
147
|
+
setIsLoading(false);
|
|
148
|
+
return { isSuccessful: false, message: err.message };
|
|
149
|
+
}
|
|
150
|
+
}, [node.postUrl, node.payload, node.redirectUrl, replaceTemplateVariables, extractFieldNames, getNestedValue, props.apiBaseUrl, props.session]);
|
|
151
|
+
const renderButtonContent = () => {
|
|
152
|
+
if (children) {
|
|
153
|
+
return children;
|
|
154
|
+
}
|
|
155
|
+
if (linkText) {
|
|
156
|
+
return /* @__PURE__ */ jsx("span", { children: linkText });
|
|
157
|
+
}
|
|
158
|
+
return node.title || "Button";
|
|
159
|
+
};
|
|
160
|
+
return /* @__PURE__ */ jsx("div", { className: "link-button-wrapper", children: /* @__PURE__ */ jsx(
|
|
161
|
+
Button_default,
|
|
162
|
+
{
|
|
163
|
+
ButtonType: linkType,
|
|
164
|
+
onClick,
|
|
165
|
+
disabled: isLoading,
|
|
166
|
+
className: "w-full",
|
|
167
|
+
children: renderButtonContent()
|
|
168
|
+
}
|
|
169
|
+
) });
|
|
170
|
+
};
|
|
171
|
+
var LinkNodeButton_default = LinkNodeButton;
|
|
172
|
+
export {
|
|
173
|
+
LinkNodeButton_default as default
|
|
174
|
+
};
|