@kizenapps/engine 1.4.0-01344a3 → 1.5.0-53bcfe4

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 (53) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/{ThirdPartyScript-CoMDaLsq.d.ts → ThirdPartyScript-cM_3Ut1L.d.ts} +31 -3
  3. package/dist/{automation-CWET9vfs.d.ts → automation-DdbPK8-Z.d.ts} +20 -3
  4. package/dist/{chunk-AY5OQ5KM.js → chunk-36G3L5ZV.js} +184 -4
  5. package/dist/chunk-36G3L5ZV.js.map +1 -0
  6. package/dist/{chunk-GVATLHW3.js → chunk-4MQ4E7D6.js} +3 -3
  7. package/dist/{chunk-GVATLHW3.js.map → chunk-4MQ4E7D6.js.map} +1 -1
  8. package/dist/{chunk-MRN746YD.js → chunk-6EG3BV5X.js} +52 -6
  9. package/dist/chunk-6EG3BV5X.js.map +1 -0
  10. package/dist/{chunk-PPRZFBZZ.js → chunk-ANAHYJTV.js} +5 -3
  11. package/dist/chunk-ANAHYJTV.js.map +1 -0
  12. package/dist/{chunk-ZMIF22NR.js → chunk-D54DBKHM.js} +78 -8
  13. package/dist/chunk-D54DBKHM.js.map +1 -0
  14. package/dist/{chunk-IGHBWLIS.js → chunk-DQECJSHA.js} +7 -4
  15. package/dist/chunk-DQECJSHA.js.map +1 -0
  16. package/dist/{chunk-5ZVIHUN4.js → chunk-ETFBGH26.js} +3 -3
  17. package/dist/{chunk-5ZVIHUN4.js.map → chunk-ETFBGH26.js.map} +1 -1
  18. package/dist/{chunk-YBCIIIAP.js → chunk-MQCYS74W.js} +4 -4
  19. package/dist/{chunk-YBCIIIAP.js.map → chunk-MQCYS74W.js.map} +1 -1
  20. package/dist/{chunk-V6JXKTHL.js → chunk-Q7UJXNJH.js} +3 -3
  21. package/dist/{chunk-V6JXKTHL.js.map → chunk-Q7UJXNJH.js.map} +1 -1
  22. package/dist/communication.d.ts +2 -2
  23. package/dist/communication.js +2 -2
  24. package/dist/contexts/base.d.ts +10 -3
  25. package/dist/contexts/base.js +4 -4
  26. package/dist/contexts/floatingFrame.d.ts +1 -1
  27. package/dist/contexts/floatingFrame.js +5 -5
  28. package/dist/contexts/recordDetail.d.ts +1 -1
  29. package/dist/contexts/recordDetail.js +5 -5
  30. package/dist/{generic-CQyBACwP.d.ts → generic-CCLPwofS.d.ts} +1 -1
  31. package/dist/index.d.ts +6 -6
  32. package/dist/index.js +4 -4
  33. package/dist/react.d.ts +19 -6
  34. package/dist/react.js +118 -74
  35. package/dist/react.js.map +1 -1
  36. package/dist/types.d.ts +5 -5
  37. package/dist/util.d.ts +3 -3
  38. package/dist/util.js +5 -5
  39. package/dist/{values-BwAd85Ee.d.ts → values-BA8dwWnM.d.ts} +2 -2
  40. package/dist/workers/calendarSource.worker.js +11 -6
  41. package/dist/workers/calendarSource.worker.js.map +1 -1
  42. package/dist/workers/floatingFrame.worker.js +9 -7
  43. package/dist/workers/floatingFrame.worker.js.map +1 -1
  44. package/dist/workers/generic.worker.js +8 -6
  45. package/dist/workers/generic.worker.js.map +1 -1
  46. package/dist/workers/recordDetail.worker.js +9 -7
  47. package/dist/workers/recordDetail.worker.js.map +1 -1
  48. package/package.json +1 -1
  49. package/dist/chunk-AY5OQ5KM.js.map +0 -1
  50. package/dist/chunk-IGHBWLIS.js.map +0 -1
  51. package/dist/chunk-MRN746YD.js.map +0 -1
  52. package/dist/chunk-PPRZFBZZ.js.map +0 -1
  53. package/dist/chunk-ZMIF22NR.js.map +0 -1
package/dist/react.js CHANGED
@@ -1,12 +1,12 @@
1
- import { runScript, getPluginSafeHTML, runExpression, getStableHash, isFlagEnabled } from './chunk-ZMIF22NR.js';
1
+ import { runScript, getPluginSafeHTML, runExpression, getStableHash, isFlagEnabled } from './chunk-D54DBKHM.js';
2
2
  import './chunk-LGJYUPYZ.js';
3
- import { generateExecutionKey } from './chunk-PPRZFBZZ.js';
4
- import { getAllNestedInputsFromConfig, getFieldFromAction } from './chunk-AY5OQ5KM.js';
5
- import { runFrameScriptEventName } from './chunk-GVATLHW3.js';
6
- import { QUERY_KEYS, ROUTE_CHANGE_INTERNAL_EVENT, IFRAME_PREFIX, ROUTE_CHANGE_IFRAME_EVENT } from './chunk-IGHBWLIS.js';
3
+ import { generateExecutionKey } from './chunk-ANAHYJTV.js';
4
+ import { getAllNestedInputsFromConfig, getFieldFromAction } from './chunk-36G3L5ZV.js';
5
+ import { runFrameScriptEventName } from './chunk-4MQ4E7D6.js';
6
+ import { QUERY_KEYS, ROUTE_CHANGE_INTERNAL_EVENT, IFRAME_PREFIX, ROUTE_CHANGE_IFRAME_EVENT } from './chunk-DQECJSHA.js';
7
7
  import './chunk-5WRI5ZAA.js';
8
8
  import { QueryClient, useQueries, useQueryClient, QueryClientContext, QueryClientProvider } from '@tanstack/react-query';
9
- import { createContext, useContext, useState, useCallback, useMemo, useRef, useEffect } from 'react';
9
+ import { createContext, useContext, useState, useCallback, useMemo, useRef, useEffect, useImperativeHandle } from 'react';
10
10
  import { jsx, Fragment } from 'react/jsx-runtime';
11
11
  import { formatInTimeZone } from 'date-fns-tz';
12
12
  import { startOfDay, endOfDay } from 'date-fns';
@@ -232,6 +232,20 @@ var ModalsWrapper = ({
232
232
  cbRef.current = void 0;
233
233
  setModalQueue((prev) => prev.slice(1));
234
234
  }, []);
235
+ const closeCurrentModal = useCallback(
236
+ (values, canceled) => {
237
+ if (cbRef.current) {
238
+ cbRef.current({ canceled: canceled ?? false, values: values ?? {}, eventSource: "script" });
239
+ if (!canceled) {
240
+ onConfirm();
241
+ } else {
242
+ onHide("script");
243
+ }
244
+ completeModal();
245
+ }
246
+ },
247
+ [completeModal, onConfirm, onHide]
248
+ );
235
249
  const derivedModalState = useMemo(() => {
236
250
  return {
237
251
  props: {
@@ -263,7 +277,8 @@ var ModalsWrapper = ({
263
277
  showCreateRecordModal: handleShowCreateRecordModal,
264
278
  showCreateRelatedRecordModal: handleShowCreateRelatedRecordModal,
265
279
  onCreateRecordComplete: handleCreateRecordComplete,
266
- onCreateRelatedRecordComplete: handleCreateRelatedRecordComplete
280
+ onCreateRelatedRecordComplete: handleCreateRelatedRecordComplete,
281
+ closeCurrentModal
267
282
  },
268
283
  children: children({
269
284
  showPluginModal: derivedModalState.props.show,
@@ -274,6 +289,7 @@ var ModalsWrapper = ({
274
289
  derivedModalState,
275
290
  handleCreateRecordComplete,
276
291
  handleCreateRelatedRecordComplete,
292
+ closeCurrentModal,
277
293
  showCreateRecordModal: createRecordModalQueue.length > 0,
278
294
  createRecordModalObjectId: createRecordModalQueue[0]?.objectId ?? "",
279
295
  showCreateRelatedRecordModal: createRelatedRecordModalQueue.length > 0,
@@ -446,7 +462,7 @@ var useCalendarSourceCustomScript = ({
446
462
  appPath
447
463
  } = useAppState();
448
464
  const { getRunnerState, getRunnerStateUpdater } = useRunnerState();
449
- const { showModal, showCreateRecordModal } = useModals();
465
+ const { showModal, showCreateRecordModal, closeCurrentModal } = useModals();
450
466
  const { sendException } = useMonitoring();
451
467
  const history = useHistory();
452
468
  const { performRequest, createFileId, performFileUpload, getPendingCacheCount, invalidateCache } = useNetwork();
@@ -506,6 +522,7 @@ var useCalendarSourceCustomScript = ({
506
522
  sessionData,
507
523
  setSessionData,
508
524
  onShowModal: showModal,
525
+ onCloseModal: closeCurrentModal,
509
526
  onShowCreateRecordModal: showCreateRecordModal,
510
527
  onShowCreateRelatedRecordModal: () => {
511
528
  },
@@ -555,7 +572,8 @@ var useCalendarSourceCustomScript = ({
555
572
  performFileUpload,
556
573
  getPendingCacheCount,
557
574
  invalidateCache,
558
- t
575
+ t,
576
+ closeCurrentModal
559
577
  ]
560
578
  );
561
579
  return [
@@ -830,7 +848,7 @@ var useFloatingFrameCustomScript = ({
830
848
  clientObject,
831
849
  appPath
832
850
  } = useAppState();
833
- const { showModal, showCreateRecordModal, showCreateRelatedRecordModal } = useModals();
851
+ const { showModal, showCreateRecordModal, showCreateRelatedRecordModal, closeCurrentModal } = useModals();
834
852
  const { sendException } = useMonitoring();
835
853
  const { showToast, clearToasts } = useToast();
836
854
  const history = useHistory();
@@ -908,6 +926,7 @@ var useFloatingFrameCustomScript = ({
908
926
  sessionData,
909
927
  setSessionData,
910
928
  onShowModal: showModal,
929
+ onCloseModal: closeCurrentModal,
911
930
  onShowCreateRecordModal: showCreateRecordModal,
912
931
  onShowCreateRelatedRecordModal: showCreateRelatedRecordModal,
913
932
  appPath,
@@ -945,7 +964,8 @@ var useFloatingFrameCustomScript = ({
945
964
  performFileUpload,
946
965
  getPendingCacheCount,
947
966
  invalidateCache,
948
- t
967
+ t,
968
+ closeCurrentModal
949
969
  ]
950
970
  );
951
971
  return [
@@ -973,7 +993,7 @@ var useGenericAppCustomScript = ({
973
993
  appPath
974
994
  } = useAppState();
975
995
  const { getRunnerState, getRunnerStateUpdater } = useRunnerState();
976
- const { showModal, showCreateRecordModal } = useModals();
996
+ const { showModal, showCreateRecordModal, closeCurrentModal } = useModals();
977
997
  const { sendException } = useMonitoring();
978
998
  const { showToast, clearToasts } = useToast();
979
999
  const history = useHistory();
@@ -1036,6 +1056,7 @@ var useGenericAppCustomScript = ({
1036
1056
  sessionData,
1037
1057
  setSessionData,
1038
1058
  onShowModal: showModal,
1059
+ onCloseModal: closeCurrentModal,
1039
1060
  onShowCreateRecordModal: showCreateRecordModal,
1040
1061
  onShowCreateRelatedRecordModal: () => {
1041
1062
  },
@@ -1072,7 +1093,8 @@ var useGenericAppCustomScript = ({
1072
1093
  performFileUpload,
1073
1094
  getPendingCacheCount,
1074
1095
  invalidateCache,
1075
- t
1096
+ t,
1097
+ closeCurrentModal
1076
1098
  ]
1077
1099
  );
1078
1100
  return [
@@ -1102,7 +1124,7 @@ var useRecordDetailCustomScript = ({
1102
1124
  appPath
1103
1125
  } = useAppState();
1104
1126
  const { getRunnerState, getRunnerStateUpdater } = useRunnerState();
1105
- const { showModal, showCreateRecordModal, showCreateRelatedRecordModal } = useModals();
1127
+ const { showModal, showCreateRecordModal, showCreateRelatedRecordModal, closeCurrentModal } = useModals();
1106
1128
  const { sendException } = useMonitoring();
1107
1129
  const { showToast, clearToasts } = useToast();
1108
1130
  const history = useHistory();
@@ -1173,6 +1195,7 @@ var useRecordDetailCustomScript = ({
1173
1195
  sessionData,
1174
1196
  setSessionData,
1175
1197
  onShowModal: showModal,
1198
+ onCloseModal: closeCurrentModal,
1176
1199
  onShowCreateRecordModal: showCreateRecordModal,
1177
1200
  onShowCreateRelatedRecordModal: showCreateRelatedRecordModal,
1178
1201
  appPath,
@@ -1211,7 +1234,8 @@ var useRecordDetailCustomScript = ({
1211
1234
  performFileUpload,
1212
1235
  getPendingCacheCount,
1213
1236
  invalidateCache,
1214
- t
1237
+ t,
1238
+ closeCurrentModal
1215
1239
  ]
1216
1240
  );
1217
1241
  return [
@@ -1222,56 +1246,85 @@ var useRecordDetailCustomScript = ({
1222
1246
  }
1223
1247
  ];
1224
1248
  };
1225
- var usePluginSafeHTML = (html) => {
1226
- return useMemo(() => getPluginSafeHTML(html), [html]);
1227
- };
1228
-
1229
- // src/react/hooks/useAppCustomHTML.ts
1230
- var useAppCustomHTML = (currentPage, args) => {
1231
- const { showToast } = useToast();
1232
- const { t } = useTranslation();
1233
- const outputUIRef = useRef(null);
1234
- const interactableScriptRef = useRef(null);
1235
- const css = currentPage?.css;
1236
- const { html } = usePluginSafeHTML(currentPage?.html);
1249
+ var useManualInteraction = (execute, currentPage, elementRef, pending, args = {}) => {
1237
1250
  const interactableScripts = useMemo(() => {
1238
1251
  return currentPage?.event_scripts ?? {};
1239
1252
  }, [currentPage]);
1240
- const [executeInline, { pending: inlinePending }] = useGenericAppCustomScript({
1241
- onError: (e) => {
1242
- showToast({
1243
- message: `${t("Script could not be executed:")} ${e?.message ?? "Unknown Error"}`,
1244
- variant: "failure"
1245
- });
1246
- },
1247
- scriptUIRef: outputUIRef,
1248
- plugin: currentPage
1249
- });
1250
1253
  const handleClick = useCallback(
1254
+ (e) => {
1255
+ if (!pending) {
1256
+ const target = e.target;
1257
+ const scriptName = target.getAttribute("data-script");
1258
+ if (scriptName && interactableScripts[scriptName]) {
1259
+ e.preventDefault();
1260
+ e.stopPropagation();
1261
+ void execute(interactableScripts[scriptName], { ...args });
1262
+ }
1263
+ }
1264
+ },
1265
+ [pending, execute, interactableScripts, args]
1266
+ );
1267
+ const handleSubmit = useCallback(
1251
1268
  (e) => {
1252
1269
  e.preventDefault();
1253
1270
  e.stopPropagation();
1254
- if (!inlinePending) {
1271
+ if (!pending) {
1255
1272
  const target = e.target;
1256
1273
  const scriptName = target.getAttribute("data-script");
1257
1274
  if (scriptName && interactableScripts[scriptName]) {
1258
- void executeInline(interactableScripts[scriptName], args);
1275
+ const rawFormData = new FormData(target);
1276
+ const formData = Object.fromEntries(
1277
+ [...new Set(rawFormData.keys())].map((key) => [key, rawFormData.getAll(key)])
1278
+ );
1279
+ void execute(interactableScripts[scriptName], { ...args, formData });
1259
1280
  }
1260
1281
  }
1261
1282
  },
1262
- [inlinePending, executeInline, interactableScripts, args]
1283
+ [pending, execute, interactableScripts, args]
1263
1284
  );
1264
1285
  useEffect(() => {
1265
- const e = interactableScriptRef.current;
1286
+ const e = elementRef?.current;
1266
1287
  if (e) {
1267
1288
  e.addEventListener("click", handleClick);
1289
+ e.addEventListener("submit", handleSubmit);
1268
1290
  }
1269
1291
  return () => {
1270
1292
  if (e) {
1271
1293
  e.removeEventListener("click", handleClick);
1294
+ e.removeEventListener("submit", handleSubmit);
1272
1295
  }
1273
1296
  };
1274
- }, [handleClick, currentPage]);
1297
+ }, [handleClick, handleSubmit, currentPage, elementRef]);
1298
+ };
1299
+ var usePluginSafeHTML = (html) => {
1300
+ return useMemo(() => getPluginSafeHTML(html), [html]);
1301
+ };
1302
+
1303
+ // src/react/hooks/useAppCustomHTML.ts
1304
+ var useAppCustomHTML = (currentPage, args) => {
1305
+ const { showToast } = useToast();
1306
+ const { t } = useTranslation();
1307
+ const outputUIRef = useRef(null);
1308
+ const interactableScriptRef = useRef(null);
1309
+ const css = currentPage?.css;
1310
+ const { html } = usePluginSafeHTML(currentPage?.html);
1311
+ const [executeInline, { pending: inlinePending }] = useGenericAppCustomScript({
1312
+ onError: (e) => {
1313
+ showToast({
1314
+ message: `${t("Script could not be executed:")} ${e?.message ?? "Unknown Error"}`,
1315
+ variant: "failure"
1316
+ });
1317
+ },
1318
+ scriptUIRef: outputUIRef,
1319
+ plugin: currentPage
1320
+ });
1321
+ useManualInteraction(
1322
+ executeInline,
1323
+ currentPage,
1324
+ interactableScriptRef,
1325
+ inlinePending,
1326
+ args
1327
+ );
1275
1328
  return {
1276
1329
  scopedCss: `
1277
1330
  @scope {
@@ -1296,36 +1349,6 @@ var useCalendarSourceReset = () => {
1296
1349
  );
1297
1350
  return resetFn;
1298
1351
  };
1299
- var useManualInteraction = (execute, currentPage, elementRef, pending, args = {}) => {
1300
- const interactableScripts = useMemo(() => {
1301
- return currentPage?.event_scripts ?? {};
1302
- }, [currentPage]);
1303
- const handleClick = useCallback(
1304
- (e) => {
1305
- e.preventDefault();
1306
- e.stopPropagation();
1307
- if (!pending) {
1308
- const target = e.target;
1309
- const scriptName = target.getAttribute("data-script");
1310
- if (scriptName && interactableScripts[scriptName]) {
1311
- void execute(interactableScripts[scriptName], { ...args });
1312
- }
1313
- }
1314
- },
1315
- [pending, execute, interactableScripts, args]
1316
- );
1317
- useEffect(() => {
1318
- const e = elementRef?.current;
1319
- if (e) {
1320
- e.addEventListener("click", handleClick);
1321
- }
1322
- return () => {
1323
- if (e) {
1324
- e.removeEventListener("click", handleClick);
1325
- }
1326
- };
1327
- }, [handleClick, currentPage, elementRef]);
1328
- };
1329
1352
  var useAppCallback = (search) => {
1330
1353
  useEffect(() => {
1331
1354
  const queryString = new URLSearchParams(search);
@@ -1389,6 +1412,23 @@ var useAppPage = (currentPage, search, isLoading) => {
1389
1412
  window.removeEventListener("message", handleMessage);
1390
1413
  };
1391
1414
  }, [handleMessage]);
1415
+ const collectFormData = useCallback(() => {
1416
+ const data = {};
1417
+ let ready = true;
1418
+ [scriptUIRef.current, interactableScriptRef.current].filter(Boolean).forEach((container) => {
1419
+ container?.querySelectorAll("form").forEach((form) => {
1420
+ if (!form.checkValidity()) {
1421
+ form.reportValidity();
1422
+ ready = false;
1423
+ }
1424
+ const formData = new FormData(form);
1425
+ for (const key of new Set(formData.keys())) {
1426
+ data[key] = formData.getAll(key);
1427
+ }
1428
+ });
1429
+ });
1430
+ return { data, ready };
1431
+ }, [interactableScriptRef]);
1392
1432
  return {
1393
1433
  scriptUIRef,
1394
1434
  outputUIRef,
@@ -1396,7 +1436,8 @@ var useAppPage = (currentPage, search, isLoading) => {
1396
1436
  sanitizedHtml,
1397
1437
  interactableScriptRef,
1398
1438
  iframeURL,
1399
- pending
1439
+ pending,
1440
+ collectFormData
1400
1441
  };
1401
1442
  };
1402
1443
  var FloatingFrameContext = createContext(null);
@@ -1975,6 +2016,9 @@ var useFloatingFrame = (params) => {
1975
2016
  scriptUIRef
1976
2017
  };
1977
2018
  };
2019
+ var useRegisterFormDataCollection = (ref, collectFormData) => {
2020
+ useImperativeHandle(ref, () => ({ collectFormData }), [collectFormData]);
2021
+ };
1978
2022
  var useLocationChange = () => {
1979
2023
  useEffect(() => {
1980
2024
  let previousEventHash = null;
@@ -2748,6 +2792,6 @@ var useSetupAssistant = () => {
2748
2792
  return context;
2749
2793
  };
2750
2794
 
2751
- export { AppBootstrapSuccess, AppEngineProvider, RouteScriptRunner, SetupAssistantController, TranslationWrapper, useAppCallback, useAppCustomHTML, useAppPage, useCalendarEvents, useCalendarOptions, useCalendarSourceCustomScript, useCalendarSourceReset, useFloatingFrame, useFloatingFrameCustomScript, useGenericAppCustomScript, useManualInteraction, usePluginSafeHTML, useRecordDetailCustomScript, useSetupAssistant, useTranslation };
2795
+ export { AppBootstrapSuccess, AppEngineProvider, RouteScriptRunner, SetupAssistantController, TranslationWrapper, useAppCallback, useAppCustomHTML, useAppPage, useCalendarEvents, useCalendarOptions, useCalendarSourceCustomScript, useCalendarSourceReset, useFloatingFrame, useFloatingFrameCustomScript, useGenericAppCustomScript, useManualInteraction, usePluginSafeHTML, useRecordDetailCustomScript, useRegisterFormDataCollection, useSetupAssistant, useTranslation };
2752
2796
  //# sourceMappingURL=react.js.map
2753
2797
  //# sourceMappingURL=react.js.map