xmlui 0.9.74 → 0.9.76

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 (30) hide show
  1. package/dist/lib/{apiInterceptorWorker-DXW_XKKI.mjs → apiInterceptorWorker-DH8wqOVq.mjs} +1382 -1919
  2. package/dist/lib/{index-D1pmdW3I.mjs → index-mdlNmhj_.mjs} +7717 -7683
  3. package/dist/lib/initMock-BXQ0HzU7.mjs +565 -0
  4. package/dist/lib/xmlui-parser.d.ts +1 -0
  5. package/dist/lib/xmlui.d.ts +20 -2
  6. package/dist/lib/xmlui.mjs +1 -1
  7. package/dist/metadata/{apiInterceptorWorker-BFjqjbag.mjs → apiInterceptorWorker-Bb5-fQup.mjs} +1258 -1795
  8. package/dist/metadata/{collectedComponentMetadata-BVLAibj_.mjs → collectedComponentMetadata-CWaLbEQz.mjs} +9509 -9475
  9. package/dist/metadata/initMock-BLnKtG1C.mjs +565 -0
  10. package/dist/metadata/xmlui-metadata.mjs +1 -1
  11. package/dist/metadata/xmlui-metadata.umd.js +113 -113
  12. package/dist/scripts/package.json +1 -1
  13. package/dist/scripts/src/components/Charts/BarChart/BarChart.js +13 -9
  14. package/dist/scripts/src/components/Charts/BarChart/BarChartNative.js +4 -3
  15. package/dist/scripts/src/components/FormItem/FormItem.js +2 -2
  16. package/dist/scripts/src/components/NestedApp/NestedAppNative.js +0 -1
  17. package/dist/scripts/src/components/TreeDisplay/TreeDisplay.js +1 -1
  18. package/dist/scripts/src/components-core/RestApiProxy.js +11 -3
  19. package/dist/scripts/src/components-core/action/APICall.js +2 -2
  20. package/dist/scripts/src/components-core/interception/ApiInterceptor.js +42 -0
  21. package/dist/scripts/src/components-core/interception/ApiInterceptorProvider.js +63 -22
  22. package/dist/scripts/src/components-core/interception/apiInterceptorWorker.js +3 -6
  23. package/dist/scripts/src/components-core/interception/initMock.js +20 -0
  24. package/dist/scripts/src/components-core/loader/DataLoader.js +4 -2
  25. package/dist/scripts/src/components-core/rendering/Container.js +3 -0
  26. package/dist/scripts/src/components-core/theming/transformThemeVars.js +1 -1
  27. package/dist/scripts/src/syntax/grammar.tmLanguage.json +1 -1
  28. package/dist/standalone/xmlui-standalone.es.d.ts +21 -3
  29. package/dist/standalone/xmlui-standalone.umd.js +267 -267
  30. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xmlui",
3
- "version": "0.9.74",
3
+ "version": "0.9.76",
4
4
  "sideEffects": false,
5
5
  "scripts": {
6
6
  "start-test-bed": "cd src/testing/infrastructure && xmlui start",
@@ -42,28 +42,32 @@ exports.BarChartMd = (0, metadata_helpers_1.createMetadata)({
42
42
  valueType: "string",
43
43
  },
44
44
  hideX: {
45
- description: "Determines whether the X-axis should be hidden. If set to \`true\`, the axis will not be rendered.",
45
+ description: "Determines whether the X-axis should be hidden. If set to `true`, the axis will not be rendered.",
46
46
  valueType: "boolean",
47
47
  defaultValue: BarChartNative_1.defaultProps.hideX,
48
48
  },
49
49
  hideY: {
50
- description: "Determines whether the Y-axis should be hidden. If set to \`true\`, the axis will not be rendered.",
50
+ description: "Determines whether the Y-axis should be hidden. If set to `true`, the axis will not be rendered.",
51
51
  valueType: "boolean",
52
52
  defaultValue: BarChartNative_1.defaultProps.hideY,
53
53
  },
54
54
  hideTickX: {
55
- description: "Controls the visibility of the X-axis ticks. If set to \`true\`, tick labels on the X-axis will be hidden.",
55
+ description: "Controls the visibility of the X-axis ticks. If set to `true`, tick labels on the X-axis will be hidden.",
56
56
  valueType: "boolean",
57
57
  defaultValue: BarChartNative_1.defaultProps.hideTickX,
58
58
  },
59
59
  hideTickY: {
60
- description: "Controls the visibility of the Y-axis ticks. If set to \`true\`, tick labels on the Y-axis will be hidden.",
60
+ description: "Controls the visibility of the Y-axis ticks. If set to `true`, tick labels on the Y-axis will be hidden.",
61
61
  valueType: "boolean",
62
62
  defaultValue: BarChartNative_1.defaultProps.hideTickY,
63
63
  },
64
- tickFormatter: {
65
- description: "A function that formats the axis tick labels. It receives a tick value and returns a formatted string.",
66
- defaultValue: JSON.stringify(BarChartNative_1.defaultProps.tickFormatter),
64
+ tickFormatterX: {
65
+ description: "A function that formats the tick labels on the X-axis. ",
66
+ defaultValue: JSON.stringify(BarChartNative_1.defaultProps.tickFormatterX),
67
+ },
68
+ tickFormatterY: {
69
+ description: "A function that formats the tick labels on the Y-axis. ",
70
+ defaultValue: JSON.stringify(BarChartNative_1.defaultProps.tickFormatterY),
67
71
  },
68
72
  showLegend: {
69
73
  description: "Determines whether the legend should be displayed.",
@@ -73,6 +77,6 @@ exports.BarChartMd = (0, metadata_helpers_1.createMetadata)({
73
77
  },
74
78
  });
75
79
  exports.barChartComponentRenderer = (0, renderers_1.createComponentRenderer)(COMP, exports.BarChartMd, ({ extractValue, node, layoutCss, lookupSyncCallback, renderChild }) => {
76
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
77
- return ((0, jsx_runtime_1.jsx)(BarChartNative_1.BarChart, { style: layoutCss, tickFormatter: lookupSyncCallback((_a = node.props) === null || _a === void 0 ? void 0 : _a.tickFormatter), data: extractValue((_b = node.props) === null || _b === void 0 ? void 0 : _b.data), layout: extractValue((_c = node.props) === null || _c === void 0 ? void 0 : _c.layout), nameKey: extractValue((_d = node.props) === null || _d === void 0 ? void 0 : _d.nameKey), dataKeys: extractValue((_e = node.props) === null || _e === void 0 ? void 0 : _e.dataKeys), stacked: extractValue.asOptionalBoolean((_f = node.props) === null || _f === void 0 ? void 0 : _f.stacked), hideX: extractValue.asOptionalBoolean((_g = node.props) === null || _g === void 0 ? void 0 : _g.hideX), hideY: extractValue.asOptionalBoolean((_h = node.props) === null || _h === void 0 ? void 0 : _h.hideY), hideTickX: extractValue.asOptionalBoolean((_j = node.props) === null || _j === void 0 ? void 0 : _j.hideTickX), hideTickY: extractValue.asOptionalBoolean((_k = node.props) === null || _k === void 0 ? void 0 : _k.hideTickY), showLegend: extractValue.asOptionalBoolean((_l = node.props) === null || _l === void 0 ? void 0 : _l.showLegend), children: renderChild(node.children) }));
80
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
81
+ return ((0, jsx_runtime_1.jsx)(BarChartNative_1.BarChart, { style: layoutCss, tickFormatterX: lookupSyncCallback((_a = node.props) === null || _a === void 0 ? void 0 : _a.tickFormatterX), tickFormatterY: lookupSyncCallback((_b = node.props) === null || _b === void 0 ? void 0 : _b.tickFormatterY), data: extractValue((_c = node.props) === null || _c === void 0 ? void 0 : _c.data), layout: extractValue((_d = node.props) === null || _d === void 0 ? void 0 : _d.layout), nameKey: extractValue((_e = node.props) === null || _e === void 0 ? void 0 : _e.nameKey), dataKeys: extractValue((_f = node.props) === null || _f === void 0 ? void 0 : _f.dataKeys), stacked: extractValue.asOptionalBoolean((_g = node.props) === null || _g === void 0 ? void 0 : _g.stacked), hideX: extractValue.asOptionalBoolean((_h = node.props) === null || _h === void 0 ? void 0 : _h.hideX), hideY: extractValue.asOptionalBoolean((_j = node.props) === null || _j === void 0 ? void 0 : _j.hideY), hideTickX: extractValue.asOptionalBoolean((_k = node.props) === null || _k === void 0 ? void 0 : _k.hideTickX), hideTickY: extractValue.asOptionalBoolean((_l = node.props) === null || _l === void 0 ? void 0 : _l.hideTickY), showLegend: extractValue.asOptionalBoolean((_m = node.props) === null || _m === void 0 ? void 0 : _m.showLegend), children: renderChild(node.children) }));
78
82
  });
@@ -49,10 +49,11 @@ exports.defaultProps = {
49
49
  hideTickY: false,
50
50
  hideX: false,
51
51
  hideY: false,
52
- tickFormatter: (value) => value,
52
+ tickFormatterX: (value) => value,
53
+ tickFormatterY: (value) => value,
53
54
  showLegend: false,
54
55
  };
55
- function BarChart({ data = [], layout = exports.defaultProps.layout, nameKey, stacked = exports.defaultProps.stacked, dataKeys = [], hideTickX = exports.defaultProps.hideTickX, hideTickY = exports.defaultProps.hideTickY, hideY = exports.defaultProps.hideY, hideX = exports.defaultProps.hideX, tickFormatter = exports.defaultProps.tickFormatter, style, children, showLegend = exports.defaultProps.showLegend, }) {
56
+ function BarChart({ data = [], layout = exports.defaultProps.layout, nameKey, stacked = exports.defaultProps.stacked, dataKeys = [], hideTickX = exports.defaultProps.hideTickX, hideTickY = exports.defaultProps.hideTickY, hideY = exports.defaultProps.hideY, hideX = exports.defaultProps.hideX, tickFormatterX = exports.defaultProps.tickFormatterX, tickFormatterY = exports.defaultProps.tickFormatterY, style, children, showLegend = exports.defaultProps.showLegend, }) {
56
57
  const { getThemeVar } = (0, ThemeContext_1.useTheme)();
57
58
  const colorValues = (0, react_2.useMemo)(() => {
58
59
  return [
@@ -180,7 +181,7 @@ function BarChart({ data = [], layout = exports.defaultProps.layout, nameKey, st
180
181
  height: style.height || "100%",
181
182
  padding: 0,
182
183
  margin: 0,
183
- }, children: (0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { ref: containerRef, width: "100%", height: "100%", debounce: 100, children: (0, jsx_runtime_1.jsxs)(recharts_1.BarChart, { style: style, accessibilityLayer: true, data: data, layout: layout, margin: miniMode ? { left: 0, right: 0, top: 0, bottom: 0 } : chartMargin, children: [(0, jsx_runtime_1.jsx)(recharts_1.CartesianGrid, { vertical: true, strokeDasharray: "3 3" }), layout === "vertical" ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(recharts_1.XAxis, { type: "number", axisLine: false, hide: miniMode || hideX, tick: miniMode ? false : { fill: "currentColor", fontSize } }), (0, jsx_runtime_1.jsx)(recharts_1.YAxis, { hide: miniMode || hideY, dataKey: nameKey, type: "category", interval: "equidistantPreserveStart", tickLine: false, tickFormatter: miniMode ? undefined : tickFormatter, tick: miniMode ? false : { fill: "currentColor", fontSize } })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(recharts_1.XAxis, { dataKey: nameKey, type: "category", interval: interval, tickLine: false, angle: tickAngle, textAnchor: tickAnchor, tick: miniMode ? false : { fill: "currentColor", fontSize }, tickFormatter: miniMode ? undefined : tickFormatter, height: miniMode || hideX ? 0 : xAxisHeight, hide: miniMode || hideX }), (0, jsx_runtime_1.jsx)(recharts_1.YAxis, { type: "number", axisLine: false, tick: miniMode ? false : !hideTickY && { fill: "currentColor", fontSize }, hide: miniMode || hideY, tickCount: yTickCount, width: miniMode || hideY || hideTickY ? 0 : 40 })] })), !miniMode && (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { content: (0, jsx_runtime_1.jsx)(TooltipContent_1.TooltipContent, {}) }), Object.keys(config).map((key, index) => ((0, jsx_runtime_1.jsx)(recharts_1.Bar, { dataKey: key, fill: config[key].color, radius: stacked ? 0 : 8, stackId: stacked ? "stacked" : undefined, strokeWidth: 1 }, index))), showLegend && ((0, jsx_runtime_1.jsx)(recharts_1.Legend, { wrapperStyle: {
184
+ }, children: (0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { style: style, ref: containerRef, width: "100%", height: "100%", debounce: 100, children: (0, jsx_runtime_1.jsxs)(recharts_1.BarChart, { accessibilityLayer: true, data: data, layout: layout, margin: miniMode ? { left: 0, right: 0, top: 0, bottom: 0 } : chartMargin, children: [(0, jsx_runtime_1.jsx)(recharts_1.CartesianGrid, { vertical: true, strokeDasharray: "3 3" }), layout === "vertical" ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(recharts_1.XAxis, { type: "number", axisLine: false, hide: miniMode || hideX, tickFormatter: miniMode ? undefined : tickFormatterX, tick: miniMode ? false : { fill: "currentColor", fontSize } }), (0, jsx_runtime_1.jsx)(recharts_1.YAxis, { hide: miniMode || hideY, dataKey: nameKey, type: "category", interval: "equidistantPreserveStart", tickLine: false, tickFormatter: miniMode ? undefined : tickFormatterY, tick: miniMode ? false : !hideTickX && { fill: "currentColor", fontSize } })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(recharts_1.XAxis, { dataKey: nameKey, type: "category", interval: interval, tickLine: false, angle: tickAngle, textAnchor: tickAnchor, tick: miniMode ? false : !hideTickX && { fill: "currentColor", fontSize }, tickFormatter: miniMode ? undefined : tickFormatterX, height: miniMode || hideX ? 0 : xAxisHeight, hide: miniMode || hideX }), (0, jsx_runtime_1.jsx)(recharts_1.YAxis, { type: "number", axisLine: false, tick: miniMode ? false : !hideTickY && { fill: "currentColor", fontSize }, hide: miniMode || hideY, tickCount: yTickCount, tickFormatter: miniMode ? undefined : tickFormatterY, width: miniMode || hideY || hideTickY ? 0 : 40 })] })), !miniMode && (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { content: (0, jsx_runtime_1.jsx)(TooltipContent_1.TooltipContent, {}) }), Object.keys(config).map((key, index) => ((0, jsx_runtime_1.jsx)(recharts_1.Bar, { dataKey: key, fill: config[key].color, radius: stacked ? 0 : 8, stackId: stacked ? "stacked" : undefined, strokeWidth: 1 }, index))), showLegend && ((0, jsx_runtime_1.jsx)(recharts_1.Legend, { wrapperStyle: {
184
185
  bottom: 0,
185
186
  left: 0,
186
187
  right: 0,
@@ -193,7 +193,7 @@ exports.formItemComponentRenderer = (0, renderers_1.createComponentRenderer)(COM
193
193
  var _a;
194
194
  const _b = node.props, { bindTo, autoFocus, label, labelPosition, labelWidth, labelBreak, enabled, required, type, requiredInvalidMessage, minLength, maxLength, lengthInvalidMessage, lengthInvalidSeverity, minValue, maxValue, rangeInvalidMessage, rangeInvalidSeverity, pattern, patternInvalidMessage, patternInvalidSeverity, regex, regexInvalidMessage, regexInvalidSeverity, customValidationsDebounce, validationMode, maxTextLength, gap } = _b, rest = __rest(_b, ["bindTo", "autoFocus", "label", "labelPosition", "labelWidth", "labelBreak", "enabled", "required", "type", "requiredInvalidMessage", "minLength", "maxLength", "lengthInvalidMessage", "lengthInvalidSeverity", "minValue", "maxValue", "rangeInvalidMessage", "rangeInvalidSeverity", "pattern", "patternInvalidMessage", "patternInvalidSeverity", "regex", "regexInvalidMessage", "regexInvalidSeverity", "customValidationsDebounce", "validationMode", "maxTextLength", "gap"]);
195
195
  //extractValue works as a memoization mechanism too (if there's nothing to resolve, it won't produce a new object every time)
196
- const resolvedValidationPropsAndEvents = extractValue({
196
+ const resolvedValidationPropsAndEvents = {
197
197
  required: extractValue.asOptionalBoolean(required),
198
198
  requiredInvalidMessage: extractValue.asOptionalString(requiredInvalidMessage),
199
199
  minLength: extractValue.asOptionalNumber(minLength),
@@ -210,7 +210,7 @@ exports.formItemComponentRenderer = (0, renderers_1.createComponentRenderer)(COM
210
210
  regex: extractValue.asOptionalString(regex),
211
211
  regexInvalidMessage: extractValue.asOptionalString(regexInvalidMessage),
212
212
  regexInvalidSeverity: (0, Validations_1.parseSeverity)(extractValue.asOptionalString(regexInvalidSeverity)),
213
- });
213
+ };
214
214
  const nonLayoutCssProps = !layoutCss
215
215
  ? rest
216
216
  : Object.fromEntries(Object.entries(rest).filter(([key, _]) => {
@@ -47,7 +47,6 @@ function AnimatedLogo() {
47
47
  function LazyNestedApp(_a) {
48
48
  var { immediate } = _a, restProps = __rest(_a, ["immediate"]);
49
49
  const [shouldRender, setShouldRender] = (0, react_1.useState)(immediate || false);
50
- console.log("Rendering NestedApp with props:", restProps);
51
50
  (0, react_1.useEffect)(() => {
52
51
  if (!immediate) {
53
52
  (0, react_1.startTransition)(() => {
@@ -31,7 +31,7 @@ exports.TreeDisplayMd = (0, metadata_helpers_1.createMetadata)({
31
31
  },
32
32
  themeVars: (0, themeVars_1.parseScssVar)(TreeDisplay_module_scss_1.default.themeVars),
33
33
  defaultThemeVars: {
34
- [`backgroundColor-${COMP}`]: "$color-primary-50",
34
+ [`backgroundColor-${COMP}`]: "$backgroundColor-CodeBlock",
35
35
  [`borderRadius-${COMP}`]: "8px",
36
36
  [`padding-${COMP}`]: "$space-4",
37
37
  [`paddingLeft-${COMP}`]: "$space-2",
@@ -103,7 +103,7 @@ function appendFormFieldValue({ key, value }, formData, prevKey = key) {
103
103
  }
104
104
  }
105
105
  class RestApiProxy {
106
- constructor(appContext) {
106
+ constructor(appContext, apiInstance) {
107
107
  var _a;
108
108
  this.execute = (_a) => __awaiter(this, [_a], void 0, function* ({ abortSignal, operation, params, parseOptions, resolveBindingExpressions = false, transactionId = (0, misc_1.randomUUID)(), onProgress, }) {
109
109
  return yield this.executeOperation({
@@ -270,12 +270,13 @@ class RestApiProxy {
270
270
  signal: abortSignal,
271
271
  body: requestBody,
272
272
  };
273
+ let url = this.generateFullApiUrl(relativePath, queryParams);
273
274
  if (onUploadProgress) {
274
275
  console.log("Falling back to axios. Reason: onUploadProgress specified");
275
276
  const axios = (yield Promise.resolve().then(() => __importStar(require("axios")))).default;
276
277
  try {
277
278
  const response = yield axios.request({
278
- url: this.generateFullApiUrl(relativePath, queryParams),
279
+ url: url,
279
280
  method: options.method,
280
281
  headers: aggregatedHeaders,
281
282
  data: options.body,
@@ -293,7 +294,13 @@ class RestApiProxy {
293
294
  }
294
295
  }
295
296
  else {
296
- const response = yield fetch(this.generateFullApiUrl(relativePath, queryParams), options);
297
+ let response;
298
+ if (this.apiInstance && this.apiInstance.hasMockForRequest(url, options)) {
299
+ response = yield this.apiInstance.executeMockedFetch(url, options);
300
+ }
301
+ else {
302
+ response = yield fetch(url, options);
303
+ }
297
304
  if (!response.clone().ok) {
298
305
  throw yield this.raiseError(response);
299
306
  }
@@ -334,6 +341,7 @@ class RestApiProxy {
334
341
  const conf = (appContext === null || appContext === void 0 ? void 0 : appContext.appGlobals) || { apiUrl: "" };
335
342
  const { apiUrl, errorResponseTransform } = conf;
336
343
  this.appContext = appContext;
344
+ this.apiInstance = apiInstance;
337
345
  // const xsrfToken = readCookie("XSRF-TOKEN");
338
346
  const xsrfHeaders =
339
347
  // xsrfToken
@@ -176,7 +176,7 @@ function updateQueriesWithOptimisticValue(_a) {
176
176
  });
177
177
  }
178
178
  function callApi(_a, _b) {
179
- return __awaiter(this, arguments, void 0, function* ({ state, appContext, lookupAction, getCurrentState }, { confirmTitle, confirmMessage, confirmButtonLabel, params = {}, onBeforeRequest, onSuccess, onError, invalidates, updates, optimisticValue, payloadType, when, getOptimisticValue, inProgressNotificationMessage, completedNotificationMessage, errorNotificationMessage, uid: actionUid, onProgress,
179
+ return __awaiter(this, arguments, void 0, function* ({ state, appContext, lookupAction, getCurrentState, apiInstance }, { confirmTitle, confirmMessage, confirmButtonLabel, params = {}, onBeforeRequest, onSuccess, onError, invalidates, updates, optimisticValue, payloadType, when, getOptimisticValue, inProgressNotificationMessage, completedNotificationMessage, errorNotificationMessage, uid: actionUid, onProgress,
180
180
  //operation
181
181
  headers, url, queryParams, rawBody, method, body, }, { resolveBindingExpressions } = {}) {
182
182
  const uid = typeof actionUid === "symbol" ? actionUid : Symbol(actionUid);
@@ -228,7 +228,7 @@ function callApi(_a, _b) {
228
228
  const _onProgress = lookupAction(onProgress, uid, {
229
229
  eventName: "progress",
230
230
  });
231
- const result = yield new RestApiProxy_1.default(appContext).execute({
231
+ const result = yield new RestApiProxy_1.default(appContext, apiInstance).execute({
232
232
  operation,
233
233
  params: stateContext,
234
234
  transactionId: clientTxId,
@@ -76,6 +76,7 @@ function initDb(apiDef) {
76
76
  }
77
77
  // An API interceptor implementation
78
78
  class ApiInterceptor {
79
+ // public id = crypto.randomUUID();
79
80
  constructor(apiDef) {
80
81
  this.apiDef = apiDef;
81
82
  this.backend = null;
@@ -200,5 +201,46 @@ class ApiInterceptor {
200
201
  convertRequestParams(params, operation) {
201
202
  return Object.assign(Object.assign({}, params), { pathParams: (0, request_params_1.convertRequestParamPart)(params.pathParams, operation.pathParamTypes), queryParams: (0, request_params_1.convertRequestParamPart)(params.queryParams, operation.queryParamTypes) });
202
203
  }
204
+ hasMockForRequest(url, options) {
205
+ return this.getMockForRequest(url, options) !== undefined;
206
+ }
207
+ getMockForRequest(url, options) {
208
+ return Object.entries(this.getOperations()).find(([operationId, operationDef]) => {
209
+ if ((0, msw_1.matchRequestUrl)(new URL(url, window.location.href), `${this.getApiUrl()}${operationDef.url}`, `${window.location.href}`).matches &&
210
+ (options.method || "get").toLowerCase() === operationDef.method.toLowerCase()) {
211
+ return true;
212
+ }
213
+ return false;
214
+ });
215
+ }
216
+ executeMockedFetch(url, options) {
217
+ return __awaiter(this, void 0, void 0, function* () {
218
+ const mockForRequest = this.getMockForRequest(url, options);
219
+ if (!mockForRequest) {
220
+ throw new Error(`No mock found for request: ${url} with options: ${JSON.stringify(options)}`);
221
+ }
222
+ const [operationId, operationDef] = mockForRequest;
223
+ const match = (0, msw_1.matchRequestUrl)(new URL(url, window.location.href), `${this.getApiUrl()}${operationDef.url}`, `${window.location.href}`);
224
+ return this.executeOperation(operationId, new Request(url, options), getCookiesAsObject(), match.params);
225
+ });
226
+ }
203
227
  }
204
228
  exports.ApiInterceptor = ApiInterceptor;
229
+ function getCookiesAsObject() {
230
+ // 1. Get the cookie string
231
+ const cookieString = document.cookie;
232
+ // 2. Handle the case of no cookies
233
+ if (cookieString === "") {
234
+ return {};
235
+ }
236
+ // 3. Split into individual "key=value" pairs
237
+ const cookiePairs = cookieString.split('; ');
238
+ // 4. Use reduce to build the final object
239
+ const cookieObject = cookiePairs.reduce((acc, currentPair) => {
240
+ const [key, value] = currentPair.split('=');
241
+ // Decode the key and value to handle special characters
242
+ acc[decodeURIComponent(key)] = decodeURIComponent(value);
243
+ return acc;
244
+ }, {});
245
+ return cookieObject;
246
+ }
@@ -48,13 +48,37 @@ const react_1 = require("react");
48
48
  const misc_1 = require("../utils/misc");
49
49
  const useApiInterceptorContext_1 = require("./useApiInterceptorContext");
50
50
  // This React component injects the API interceptor into the application's context
51
- function ApiInterceptorProvider({ interceptor, children, useHashBasedRouting, parentInterceptorContext = null, waitForApiInterceptor = false, }) {
51
+ function ApiInterceptorProvider({ interceptor, children, parentInterceptorContext = null, waitForApiInterceptor = false, }) {
52
+ var _a;
52
53
  const hasParentInterceptorContext = parentInterceptorContext !== null;
53
54
  const [initialized, setInitialized] = (0, react_1.useState)(!interceptor);
54
55
  const [forceInitialize, setForceInitialize] = (0, react_1.useState)(false);
55
56
  const [interceptorWorker, setInterceptorWorker] = (0, react_1.useState)(null);
57
+ const [apiInstance, setApiInstance] = (0, react_1.useState)(null);
58
+ const useWorker = (_a = interceptor === null || interceptor === void 0 ? void 0 : interceptor.useWorker) !== null && _a !== void 0 ? _a : true;
56
59
  // --- Whenever the interceptor changes, update the provider accordingly
60
+ let forceInitializeParent = parentInterceptorContext === null || parentInterceptorContext === void 0 ? void 0 : parentInterceptorContext.forceInitialize;
61
+ let parentInterceptorWorker = parentInterceptorContext === null || parentInterceptorContext === void 0 ? void 0 : parentInterceptorContext.interceptorWorker;
62
+ //// if we don't use a worker, we initialize the api instance directly
57
63
  (0, react_1.useEffect)(() => {
64
+ if (useWorker) {
65
+ return;
66
+ }
67
+ if (!interceptor) {
68
+ return;
69
+ }
70
+ (() => __awaiter(this, void 0, void 0, function* () {
71
+ const { initMock } = yield Promise.resolve().then(() => __importStar(require("./initMock")));
72
+ const apiInstance = yield initMock(interceptor);
73
+ setApiInstance(apiInstance);
74
+ setInitialized(true);
75
+ }))();
76
+ }, [interceptor, useWorker]);
77
+ //// if we use a worker, we initialize the worker with the api instance
78
+ (0, react_1.useEffect)(() => {
79
+ if (!useWorker) {
80
+ return;
81
+ }
58
82
  if (!hasParentInterceptorContext) {
59
83
  if (interceptor || forceInitialize) {
60
84
  // setInitialized(false);
@@ -63,17 +87,22 @@ function ApiInterceptorProvider({ interceptor, children, useHashBasedRouting, pa
63
87
  (() => __awaiter(this, void 0, void 0, function* () {
64
88
  // --- Create the worker on the fly
65
89
  if (process.env.VITE_MOCK_ENABLED) {
66
- const { createApiInterceptorWorker } = yield Promise.resolve().then(() => __importStar(require("./apiInterceptorWorker")));
90
+ const [{ createApiInterceptorWorker }, { initMock }] = yield Promise.all([
91
+ useWorker
92
+ ? Promise.resolve().then(() => __importStar(require("./apiInterceptorWorker"))) : Promise.resolve({ createApiInterceptorWorker: () => null }),
93
+ Promise.resolve().then(() => __importStar(require("./initMock"))),
94
+ ]);
67
95
  if (interceptor || forceInitialize) {
68
- interceptorWorker = yield createApiInterceptorWorker(interceptor || {}, null);
96
+ const apiInstance = yield initMock(interceptor || {});
97
+ interceptorWorker = yield createApiInterceptorWorker(apiInstance);
69
98
  // if the apiWorker comes from the outside, we don't handle the lifecycle here
70
99
  const workerFileLocation = (0, misc_1.normalizePath)(process.env.VITE_MOCK_WORKER_LOCATION || "mockServiceWorker.js");
71
100
  yield interceptorWorker.start({
72
101
  onUnhandledRequest: "bypass",
73
102
  quiet: true,
74
103
  serviceWorker: {
75
- url: workerFileLocation
76
- }
104
+ url: workerFileLocation,
105
+ },
77
106
  });
78
107
  setInterceptorWorker(interceptorWorker);
79
108
  }
@@ -82,7 +111,7 @@ function ApiInterceptorProvider({ interceptor, children, useHashBasedRouting, pa
82
111
  }))();
83
112
  return () => {
84
113
  // if the apiWorker comes from the outside, we don't handle the lifecycle here
85
- if (!(parentInterceptorContext === null || parentInterceptorContext === void 0 ? void 0 : parentInterceptorContext.interceptorWorker)) {
114
+ if (!parentInterceptorWorker) {
86
115
  interceptorWorker === null || interceptorWorker === void 0 ? void 0 : interceptorWorker.stop();
87
116
  }
88
117
  setInitialized(false);
@@ -93,22 +122,34 @@ function ApiInterceptorProvider({ interceptor, children, useHashBasedRouting, pa
93
122
  }
94
123
  }
95
124
  else {
96
- if (interceptor) {
97
- if (parentInterceptorContext === null || parentInterceptorContext === void 0 ? void 0 : parentInterceptorContext.interceptorWorker) {
98
- (() => __awaiter(this, void 0, void 0, function* () {
99
- const { createApiInterceptorWorker } = yield Promise.resolve().then(() => __importStar(require("./apiInterceptorWorker")));
100
- yield createApiInterceptorWorker(interceptor, parentInterceptorContext === null || parentInterceptorContext === void 0 ? void 0 : parentInterceptorContext.interceptorWorker);
101
- setTimeout(() => {
102
- setInitialized(true);
103
- }, 0);
104
- }))();
105
- }
106
- else {
107
- parentInterceptorContext === null || parentInterceptorContext === void 0 ? void 0 : parentInterceptorContext.forceInitialize();
108
- }
125
+ if (!interceptor) {
126
+ return;
127
+ }
128
+ if (parentInterceptorWorker) {
129
+ (() => __awaiter(this, void 0, void 0, function* () {
130
+ const [{ createApiInterceptorWorker }, { initMock }] = yield Promise.all([
131
+ Promise.resolve().then(() => __importStar(require("./apiInterceptorWorker"))),
132
+ Promise.resolve().then(() => __importStar(require("./initMock"))),
133
+ ]);
134
+ const apiInstance = yield initMock(interceptor);
135
+ yield createApiInterceptorWorker(apiInstance, parentInterceptorWorker);
136
+ setTimeout(() => {
137
+ setInitialized(true);
138
+ }, 0);
139
+ }))();
140
+ }
141
+ else {
142
+ forceInitializeParent === null || forceInitializeParent === void 0 ? void 0 : forceInitializeParent();
109
143
  }
110
144
  }
111
- }, [forceInitialize, hasParentInterceptorContext, interceptor, parentInterceptorContext === null || parentInterceptorContext === void 0 ? void 0 : parentInterceptorContext.forceInitialize, parentInterceptorContext === null || parentInterceptorContext === void 0 ? void 0 : parentInterceptorContext.interceptorWorker]);
145
+ }, [
146
+ useWorker,
147
+ forceInitialize,
148
+ hasParentInterceptorContext,
149
+ interceptor,
150
+ forceInitializeParent,
151
+ parentInterceptorWorker,
152
+ ]);
112
153
  const isMocked = (0, react_1.useCallback)((url) => interceptor !== undefined && !!process.env.VITE_MOCK_ENABLED, [interceptor]);
113
154
  const doForceInitialize = (0, react_1.useCallback)(() => {
114
155
  setForceInitialize(true);
@@ -116,11 +157,11 @@ function ApiInterceptorProvider({ interceptor, children, useHashBasedRouting, pa
116
157
  const contextValue = (0, react_1.useMemo)(() => {
117
158
  return {
118
159
  interceptorWorker,
160
+ apiInstance,
119
161
  initialized: initialized,
120
162
  forceInitialize: doForceInitialize,
121
163
  isMocked: isMocked,
122
164
  };
123
- }, [interceptorWorker, initialized, doForceInitialize, isMocked]);
124
- // console.log("[ApiInterceptorProvider] Initialized:", initialized, "Interceptor:", interceptor, "Has parent", hasParentInterceptorContext, "waitForApiInterceptor", waitForApiInterceptor);
165
+ }, [interceptorWorker, apiInstance, initialized, doForceInitialize, isMocked]);
125
166
  return ((0, jsx_runtime_1.jsx)(useApiInterceptorContext_1.ApiInterceptorContext.Provider, { value: contextValue, children: waitForApiInterceptor && !initialized ? null : children }));
126
167
  }
@@ -13,7 +13,6 @@ exports.createApiInterceptorWorker = void 0;
13
13
  const browser_1 = require("msw/browser");
14
14
  const msw_1 = require("msw");
15
15
  const lodash_es_1 = require("lodash-es");
16
- const ApiInterceptor_1 = require("./ApiInterceptor");
17
16
  // Create handlers for the specified API interceptor
18
17
  function createHandlers(api) {
19
18
  const operations = api.getOperations();
@@ -32,12 +31,10 @@ function createHandlers(api) {
32
31
  return handlers;
33
32
  }
34
33
  // Create the worker for the ApiInterceptorProvider
35
- const createApiInterceptorWorker = (apiInterceptorDefinition, apiWorker) => __awaiter(void 0, void 0, void 0, function* () {
36
- const apiInstance = new ApiInterceptor_1.ApiInterceptor(apiInterceptorDefinition);
37
- yield apiInstance.initialize();
34
+ const createApiInterceptorWorker = (apiInstance, parentWorker) => __awaiter(void 0, void 0, void 0, function* () {
38
35
  const handlers = createHandlers(apiInstance);
39
- let worker = apiWorker;
40
- if (!worker) {
36
+ let worker = parentWorker;
37
+ if (!parentWorker) {
41
38
  worker = (0, browser_1.setupWorker)();
42
39
  }
43
40
  // https://github.com/mswjs/msw/issues/2495
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.initMock = void 0;
13
+ const ApiInterceptor_1 = require("./ApiInterceptor");
14
+ // Create the worker for the ApiInterceptorProvider
15
+ const initMock = (apiInterceptorDefinition) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const apiInstance = new ApiInterceptor_1.ApiInterceptor(apiInterceptorDefinition);
17
+ yield apiInstance.initialize();
18
+ return apiInstance;
19
+ });
20
+ exports.initMock = initMock;
@@ -27,6 +27,7 @@ const AppContext_1 = require("../AppContext");
27
27
  const hooks_1 = require("../utils/hooks");
28
28
  const IndexerContext_1 = require("../../components/App/IndexerContext");
29
29
  const metadata_helpers_1 = require("../../components/metadata-helpers");
30
+ const useApiInterceptorContext_1 = require("../interception/useApiInterceptorContext");
30
31
  function DataLoader({ loader, state, registerComponentApi, onLoaded, onError, loaderInProgressChanged, loaderIsRefetchingChanged, loaderLoaded, loaderError, transformResult, structuralSharing = true, }) {
31
32
  const appContext = (0, AppContext_1.useAppContext)();
32
33
  const url = (0, extractParam_1.extractParam)(state, loader.props.url, appContext);
@@ -55,9 +56,10 @@ function DataLoader({ loader, state, registerComponentApi, onLoaded, onError, lo
55
56
  return null;
56
57
  }, [loader.props.nextPageSelector, loader.props.prevPageSelector]);
57
58
  const hasPaging = pagingDirection !== null;
59
+ const { apiInstance } = (0, useApiInterceptorContext_1.useApiInterceptorContext)();
58
60
  const api = (0, react_1.useMemo)(() => {
59
- return new RestApiProxy_1.default(appContext);
60
- }, [appContext]);
61
+ return new RestApiProxy_1.default(appContext, apiInstance);
62
+ }, [apiInstance, appContext]);
61
63
  const doLoad = (0, react_1.useCallback)((abortSignal, pageParams) => __awaiter(this, void 0, void 0, function* () {
62
64
  // For CSV data type, handle directly rather than using RestApiProxy
63
65
  if (loader.props.dataType === "csv") {
@@ -66,6 +66,7 @@ const renderChild_1 = require("./renderChild");
66
66
  const ThemeContext_1 = require("../theming/ThemeContext");
67
67
  const LoaderComponent_1 = require("../LoaderComponent");
68
68
  const constants_1 = require("../constants");
69
+ const useApiInterceptorContext_1 = require("../interception/useApiInterceptorContext");
69
70
  // React component to display a view container and implement its behavior
70
71
  exports.Container = (0, react_1.memo)((0, react_1.forwardRef)(function Container({ node, componentState, dispatch: containerDispatch, parentDispatch, resolvedKey, version, setVersion, statePartChanged, registerComponentApi: containerRegisterComponentApi, parentRegisterComponentApi, layoutContextRef, parentRenderContext, memoedVarsRef, isImplicit, uidInfoRef: parentUidInfoRef, children, }, ref) {
71
72
  var _a;
@@ -106,6 +107,7 @@ exports.Container = (0, react_1.memo)((0, react_1.forwardRef)(function Container
106
107
  }
107
108
  };
108
109
  }, []);
110
+ const { apiInstance } = (0, useApiInterceptorContext_1.useApiInterceptorContext)();
109
111
  const runCodeAsync = (0, misc_1.useEvent)((source, componentUid, options, ...eventArgs) => __awaiter(this, void 0, void 0, function* () {
110
112
  var _a, _b, _c;
111
113
  // --- Check if the event handler can sign its lifecycle state
@@ -136,6 +138,7 @@ exports.Container = (0, react_1.memo)((0, react_1.forwardRef)(function Container
136
138
  getCurrentState: () => stateRef.current,
137
139
  dispatch,
138
140
  appContext: evalAppContext,
141
+ apiInstance,
139
142
  navigate,
140
143
  location,
141
144
  lookupAction: (action, uid, actionOptions = {}) => {
@@ -660,7 +660,7 @@ function generateBaseTonesForColor(varName, theme, options = { distributeEven: f
660
660
  color200 = baseColor.lightness(baseL + lightStep * 3);
661
661
  color300 = baseColor.lightness(baseL + lightStep * 2);
662
662
  color400 = baseColor.lightness(baseL + lightStep * 1);
663
- color500 = baseColor;
663
+ color500 = baseColor.lightness(baseL);
664
664
  color600 = baseColor.lightness(baseL - darkStep * 1);
665
665
  color700 = baseColor.lightness(baseL - darkStep * 2);
666
666
  color800 = baseColor.lightness(baseL - darkStep * 3);
@@ -223,7 +223,7 @@
223
223
  "patterns": [{ "include": "source.js" }]
224
224
  },
225
225
  "textWithBindingExpr": {
226
- "patterns": [{ "include": "#entity" }, { "include": "#bindingExpr" }]
226
+ "patterns": [{ "include": "#entity" }, { "match": "\\\\{" }, { "include": "#bindingExpr" }]
227
227
  },
228
228
  "propOrVarTag": {
229
229
  "begin": "(</?)([a-zA-Z_][\\w\\.\\-]*?:)?((?:variable)|(?:property)|(?:prop))",
@@ -8,6 +8,7 @@ import { ForwardedRef } from 'react';
8
8
  import { ForwardRefExoticComponent } from 'react';
9
9
  import { JSX as JSX_2 } from 'react/jsx-runtime';
10
10
  import { NavigateOptions } from 'react-router-dom';
11
+ import { PathParams } from 'msw';
11
12
  import { QueryClient } from '@tanstack/react-query';
12
13
  import { ReactNode } from 'react';
13
14
  import { RefAttributes } from 'react';
@@ -15,6 +16,7 @@ import { RefObject } from 'react';
15
16
  import { Renderable } from 'react-hot-toast';
16
17
  import { Root } from 'react-dom/client';
17
18
  import { SetupWorker } from 'msw/browser';
19
+ import { StrictRequest } from 'msw';
18
20
  import { To } from 'react-router-dom';
19
21
  import { Toast } from 'react-hot-toast';
20
22
  import { ToastOptions } from 'react-hot-toast';
@@ -25,6 +27,7 @@ declare interface ActionExecutionContext {
25
27
  state: ContainerState;
26
28
  getCurrentState: () => ContainerState;
27
29
  appContext: AppContextObject;
30
+ apiInstance?: ApiInterceptor;
28
31
  lookupAction: LookupAsyncFnInner;
29
32
  navigate: any;
30
33
  location: any;
@@ -36,6 +39,20 @@ declare type AlignmentOptions = (typeof alignmentOptionValues)[number];
36
39
 
37
40
  declare const alignmentOptionValues: readonly ["start", "center", "end"];
38
41
 
42
+ declare class ApiInterceptor {
43
+ private readonly apiDef;
44
+ private backend;
45
+ constructor(apiDef: ApiInterceptorDefinition);
46
+ initialize(): Promise<void>;
47
+ getOperations(): Record<string, InterceptorOperationDef>;
48
+ getApiUrl(): string;
49
+ executeOperation(operationId: string, req: StrictRequest<any> | null, cookies: Record<string, string | Array<string>>, params: PathParams<string>): Promise<Response>;
50
+ private convertRequestParams;
51
+ hasMockForRequest(url: string, options: RequestInit): boolean;
52
+ private getMockForRequest;
53
+ executeMockedFetch(url: string, options: RequestInit): Promise<Response>;
54
+ }
55
+
39
56
  declare type ApiInterceptorDefinition = {
40
57
  type?: string;
41
58
  config?: Record<string, any>;
@@ -47,13 +64,13 @@ declare type ApiInterceptorDefinition = {
47
64
  initialize?: string;
48
65
  operations?: Record<string, InterceptorOperationDef>;
49
66
  auth?: AuthDefinition;
67
+ useWorker?: boolean;
50
68
  };
51
69
 
52
- declare function ApiInterceptorProvider({ interceptor, children, useHashBasedRouting, parentInterceptorContext, waitForApiInterceptor, }: {
70
+ declare function ApiInterceptorProvider({ interceptor, children, parentInterceptorContext, waitForApiInterceptor, }: {
53
71
  interceptor?: ApiInterceptorDefinition;
54
72
  children: ReactNode;
55
73
  apiWorker?: SetupWorker;
56
- useHashBasedRouting?: boolean;
57
74
  parentInterceptorContext?: IApiInterceptorContext;
58
75
  waitForApiInterceptor?: boolean;
59
76
  }): JSX_2.Element;
@@ -745,6 +762,7 @@ declare interface IApiInterceptorContext {
745
762
  initialized: boolean;
746
763
  forceInitialize: () => void;
747
764
  interceptorWorker: SetupWorker | null;
765
+ apiInstance: ApiInterceptor | null;
748
766
  }
749
767
 
750
768
  declare interface IAppLayoutContext {
@@ -1317,7 +1335,7 @@ declare const standaloneExports: {
1317
1335
  [variantSpecificProps: string]: any;
1318
1336
  uid?: string;
1319
1337
  children?: default_2.ReactNode;
1320
- variant?: "small" | "sub" | "sup" | "abbr" | "caption" | "cite" | "code" | "em" | "strong" | "title" | "var" | "inherit" | "mono" | "secondary" | "codefence" | "deleted" | "inserted" | "keyboard" | "marked" | "sample" | "subtitle" | "placeholder" | "paragraph" | "subheading" | "tableheading";
1338
+ variant?: "var" | "small" | "sub" | "sup" | "abbr" | "caption" | "cite" | "code" | "em" | "strong" | "title" | "inherit" | "mono" | "secondary" | "codefence" | "deleted" | "inserted" | "keyboard" | "marked" | "sample" | "subtitle" | "placeholder" | "paragraph" | "subheading" | "tableheading";
1321
1339
  maxLines?: number;
1322
1340
  preserveLinebreaks?: boolean;
1323
1341
  ellipses?: boolean;