xmlui 0.9.6 → 0.9.8

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.
@@ -12,7 +12,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
12
12
  var _executor, _DeferredPromise_instances, decorate_fn, _a2;
13
13
  import { delay as delay$1, HttpResponse, http } from "msw";
14
14
  import { isArray, isObject as isObject$1, mapValues } from "lodash-es";
15
- import { r as runEventHandlerCode, g as getDate, d as delay, m as miscellaneousUtils, a as dateFunctions, o as orderBy, T as ThrowStatementError } from "./index-B18vblD8.mjs";
15
+ import { r as runEventHandlerCode, g as getDate, d as delay, m as miscellaneousUtils, a as dateFunctions, o as orderBy, T as ThrowStatementError } from "./index-CUYSE1U7.mjs";
16
16
  import Dexie from "dexie";
17
17
  var POSITIONALS_EXP = /(%?)(%([sdijo]))/g;
18
18
  function serializePositional(positional, flag) {
@@ -7,7 +7,7 @@ import { useQuery, useInfiniteQuery, QueryClientProvider, QueryClient } from "@t
7
7
  import produce, { createDraft, finishDraft, enableMapSet } from "immer";
8
8
  import { throttle, get, isNil, omitBy, isUndefined, noop as noop$2, isPlainObject, isEqual, union, uniq, orderBy as orderBy$1, isEmpty, isObject, isArray, groupBy, sortBy, omit, isNumber, isString, cloneDeep, merge, defaultTo, capitalize, unset, setWith, keyBy, pick } from "lodash-es";
9
9
  import { formatDistanceToNow, parse, format, parseISO, isValid, isTomorrow, isYesterday, isToday, isThisWeek, formatRelative, isThisYear, isSameDay, differenceInMinutes } from "date-fns";
10
- import { v as validationStatusMd, l as labelPositionMd, o as orientationOptionMd, a as alignmentOptionValues, L as LinkTargetMd, b as alignmentOptionMd, i as iconPositionMd, c as buttonTypesMd, s as sizeMd, d as buttonThemeMd, e as buttonVariantMd, P as Parser, T as T_CALCULATED_MEMBER_ACCESS_EXPRESSION, f as T_MEMBER_ACCESS_EXPRESSION, g as T_IDENTIFIER, h as T_PREFIX_OP_EXPRESSION, j as T_FUNCTION_DECLARATION, k as T_ARROW_EXPRESSION, m as createXmlUiTreeNodeId, n as T_EMPTY_STATEMENT, p as T_SWITCH_STATEMENT, q as T_TRY_STATEMENT, r as T_THROW_STATEMENT, t as T_FOR_OF_STATEMENT, u as T_FOR_IN_STATEMENT, w as T_FOR_STATEMENT, x as T_EXPRESSION_STATEMENT, y as T_BREAK_STATEMENT, z as T_CONTINUE_STATEMENT, A as T_DO_WHILE_STATEMENT, B as T_WHILE_STATEMENT, C as T_RETURN_STATEMENT, D as T_IF_STATEMENT, E as T_CONST_STATEMENT, F as T_LET_STATEMENT, G as T_ARROW_EXPRESSION_STATEMENT, H as T_BLOCK_STATEMENT, I as T_VAR_STATEMENT, J as T_ASSIGNMENT_EXPRESSION, K as T_LITERAL, M as T_SPREAD_EXPRESSION, N as T_FUNCTION_INVOCATION_EXPRESSION, O as T_POSTFIX_OP_EXPRESSION, Q as T_CONDITIONAL_EXPRESSION, R as T_BINARY_EXPRESSION, S as T_UNARY_EXPRESSION, U as T_OBJECT_LITERAL, V as T_ARRAY_LITERAL, W as T_SEQUENCE_EXPRESSION, X as T_TEMPLATE_LITERAL_EXPRESSION, Y as T_VAR_DECLARATION, Z as T_DESTRUCTURE, _ as TextVariantElement, $ as VariantPropsKeys, a0 as variantOptionsMd, a1 as scrollAnchoringValues, a2 as buttonThemeNames, a3 as iconPositionNames, a4 as buttonVariantNames, a5 as nodeToComponentDef, a6 as triggerPositionNames, a7 as statusColorMd, a8 as placementMd, a9 as httpMethodNames, aa as PARSED_MARK_PROP, ab as layoutOptionKeys, ac as viewportSizeNames, ad as componentFileExtension, ae as codeBehindFileExtension, af as getLintSeverity, ag as LintSeverity, ah as lintApp, ai as printComponentLints, aj as lintErrorsComponent, ak as collectCodeBehindFromSource, al as removeCodeBehindTokensFromTree } from "./lint-gX2osbkz.mjs";
10
+ import { v as validationStatusMd, l as labelPositionMd, o as orientationOptionMd, a as alignmentOptionValues, L as LinkTargetMd, b as alignmentOptionMd, i as iconPositionMd, c as buttonTypesMd, s as sizeMd, d as buttonThemeMd, e as buttonVariantMd, P as Parser, T as T_CALCULATED_MEMBER_ACCESS_EXPRESSION, f as T_MEMBER_ACCESS_EXPRESSION, g as T_IDENTIFIER, h as T_PREFIX_OP_EXPRESSION, j as T_FUNCTION_DECLARATION, k as T_ARROW_EXPRESSION, m as createXmlUiTreeNodeId, n as T_EMPTY_STATEMENT, p as T_SWITCH_STATEMENT, q as T_TRY_STATEMENT, r as T_THROW_STATEMENT, t as T_FOR_OF_STATEMENT, u as T_FOR_IN_STATEMENT, w as T_FOR_STATEMENT, x as T_EXPRESSION_STATEMENT, y as T_BREAK_STATEMENT, z as T_CONTINUE_STATEMENT, A as T_DO_WHILE_STATEMENT, B as T_WHILE_STATEMENT, C as T_RETURN_STATEMENT, D as T_IF_STATEMENT, E as T_CONST_STATEMENT, F as T_LET_STATEMENT, G as T_ARROW_EXPRESSION_STATEMENT, H as T_BLOCK_STATEMENT, I as T_VAR_STATEMENT, J as T_ASSIGNMENT_EXPRESSION, K as T_LITERAL, M as T_SPREAD_EXPRESSION, N as T_FUNCTION_INVOCATION_EXPRESSION, O as T_POSTFIX_OP_EXPRESSION, Q as T_CONDITIONAL_EXPRESSION, R as T_BINARY_EXPRESSION, S as T_UNARY_EXPRESSION, U as T_OBJECT_LITERAL, V as T_ARRAY_LITERAL, W as T_SEQUENCE_EXPRESSION, X as T_TEMPLATE_LITERAL_EXPRESSION, Y as T_VAR_DECLARATION, Z as T_DESTRUCTURE, _ as TextVariantElement, $ as VariantPropsKeys, a0 as variantOptionsMd, a1 as scrollAnchoringValues, a2 as buttonThemeNames, a3 as iconPositionNames, a4 as buttonVariantNames, a5 as nodeToComponentDef, a6 as triggerPositionNames, a7 as statusColorMd, a8 as placementMd, a9 as httpMethodNames, aa as PARSED_MARK_PROP, ab as layoutOptionKeys, ac as viewportSizeNames, ad as componentFileExtension, ae as codeBehindFileExtension, af as getLintSeverity, ag as LintSeverity, ah as lintApp, ai as printComponentLints, aj as lintErrorsComponent, ak as collectCodeBehindFromSource, al as removeCodeBehindTokensFromTree } from "./lint-B9tKGcOX.mjs";
11
11
  import classnames from "classnames";
12
12
  import Color from "color";
13
13
  import TextareaAutosize from "react-textarea-autosize";
@@ -24487,7 +24487,8 @@ function Theme({
24487
24487
  tone,
24488
24488
  toastDuration = 5e3,
24489
24489
  themeVars: themeVars2 = EMPTY_OBJECT,
24490
- layoutContext
24490
+ layoutContext,
24491
+ children
24491
24492
  }) {
24492
24493
  const generatedId2 = useId();
24493
24494
  const { themes, resources, resourceMap, activeThemeId, setRoot, root: root2 } = useThemes();
@@ -24594,7 +24595,10 @@ function Theme({
24594
24595
  }
24595
24596
  },
24596
24597
  children: [
24597
- /* @__PURE__ */ jsx(ErrorBoundary, { node, location: "theme-root", children: renderChild2(node.children) }),
24598
+ /* @__PURE__ */ jsxs(ErrorBoundary, { node, location: "theme-root", children: [
24599
+ renderChild2(node.children),
24600
+ children
24601
+ ] }),
24598
24602
  /* @__PURE__ */ jsx(NotificationToast, { toastDuration })
24599
24603
  ]
24600
24604
  }
@@ -31671,7 +31675,7 @@ function IconProvider({ children }) {
31671
31675
  /* @__PURE__ */ jsx("svg", { style: { display: "none" }, ref: spriteRootRef })
31672
31676
  ] });
31673
31677
  }
31674
- const version = "0.9.6";
31678
+ const version = "0.9.8";
31675
31679
  const ApiInterceptorContext = createContext(null);
31676
31680
  function useApiInterceptorContext() {
31677
31681
  return useContext(ApiInterceptorContext);
@@ -33433,7 +33437,8 @@ const Container = memo(
33433
33437
  parentRenderContext,
33434
33438
  memoedVarsRef,
33435
33439
  isImplicit,
33436
- uidInfoRef: parentUidInfoRef
33440
+ uidInfoRef: parentUidInfoRef,
33441
+ children
33437
33442
  }, ref) {
33438
33443
  var _a;
33439
33444
  const { apiBoundContainer } = node;
@@ -33522,6 +33527,15 @@ const Container = memo(
33522
33527
  );
33523
33528
  }
33524
33529
  statements = parsedStatementsRef.current[source];
33530
+ } else if (isParsedEventValue(source)) {
33531
+ const parseId = source.parseId.toString();
33532
+ if (!parsedStatementsRef.current[parseId]) {
33533
+ parsedStatementsRef.current[parseId] = prepareHandlerStatements(
33534
+ source.statements,
33535
+ evalContext
33536
+ );
33537
+ }
33538
+ statements = parsedStatementsRef.current[parseId];
33525
33539
  } else {
33526
33540
  statements = [
33527
33541
  {
@@ -33639,23 +33653,44 @@ const Container = memo(
33639
33653
  );
33640
33654
  const getOrCreateEventHandlerFn = useEvent(
33641
33655
  (src, uid, options2) => {
33642
- var _a2;
33656
+ var _a2, _b;
33643
33657
  if (Array.isArray(src)) {
33644
33658
  throw new Error("Multiple event handlers are not supported");
33645
33659
  }
33646
- const stringSrc = typeof src === "string" ? src : src.statement.nodeId;
33647
- const fnCacheKey = `${options2 == null ? void 0 : options2.eventName};${stringSrc}`;
33648
- const handler = (...eventArgs) => {
33649
- return runCodeAsync(src, uid, options2, ...cloneDeep(eventArgs));
33650
- };
33651
- if (options2 == null ? void 0 : options2.ephemeral) {
33652
- return handler;
33660
+ if (typeof src === "string") {
33661
+ const fnCacheKey = `${options2 == null ? void 0 : options2.eventName};${src}`;
33662
+ const handler = (...eventArgs) => {
33663
+ return runCodeAsync(src, uid, options2, ...cloneDeep(eventArgs));
33664
+ };
33665
+ if (options2 == null ? void 0 : options2.ephemeral) {
33666
+ return handler;
33667
+ }
33668
+ if (!((_a2 = fnsRef.current[uid]) == null ? void 0 : _a2[fnCacheKey])) {
33669
+ fnsRef.current[uid] = fnsRef.current[uid] || {};
33670
+ fnsRef.current[uid][fnCacheKey] = handler;
33671
+ }
33672
+ return fnsRef.current[uid][fnCacheKey];
33653
33673
  }
33654
- if (!((_a2 = fnsRef.current[uid]) == null ? void 0 : _a2[fnCacheKey])) {
33655
- fnsRef.current[uid] = fnsRef.current[uid] || {};
33656
- fnsRef.current[uid][fnCacheKey] = handler;
33674
+ if (isParsedEventValue(src)) {
33675
+ return (...eventArgs) => {
33676
+ return runCodeAsync(src, uid, options2, ...cloneDeep(eventArgs));
33677
+ };
33657
33678
  }
33658
- return fnsRef.current[uid][fnCacheKey];
33679
+ if (isArrowExpression(src)) {
33680
+ const fnCacheKey = `${options2 == null ? void 0 : options2.eventName};${src.statement.nodeId}`;
33681
+ const handler = (...eventArgs) => {
33682
+ return runCodeAsync(src, uid, options2, ...cloneDeep(eventArgs));
33683
+ };
33684
+ if (options2 == null ? void 0 : options2.ephemeral) {
33685
+ return handler;
33686
+ }
33687
+ if (!((_b = fnsRef.current[uid]) == null ? void 0 : _b[fnCacheKey])) {
33688
+ fnsRef.current[uid] = fnsRef.current[uid] || {};
33689
+ fnsRef.current[uid][fnCacheKey] = handler;
33690
+ }
33691
+ return fnsRef.current[uid][fnCacheKey];
33692
+ }
33693
+ throw new Error("Invalid event handler");
33659
33694
  }
33660
33695
  );
33661
33696
  const getOrCreateSyncCallbackFn = useCallback(
@@ -33752,12 +33787,12 @@ const Container = memo(
33752
33787
  if (typeof childNode === "string") {
33753
33788
  throw Error("should be resolved for now");
33754
33789
  }
33755
- const children = isArray(childNode) ? childNode : [childNode];
33756
- if (!children || !children.length) {
33790
+ const children2 = isArray(childNode) ? childNode : [childNode];
33791
+ if (!children2 || !children2.length) {
33757
33792
  return null;
33758
33793
  }
33759
- const wrapWithFragment = children.length > 1;
33760
- const renderedChildren2 = children.map((child, childIndex) => {
33794
+ const wrapWithFragment = children2.length > 1;
33795
+ const renderedChildren2 = children2.map((child, childIndex) => {
33761
33796
  if (!child) {
33762
33797
  return void 0;
33763
33798
  }
@@ -33845,7 +33880,7 @@ const Container = memo(
33845
33880
  });
33846
33881
  const containerContent = /* @__PURE__ */ jsxs(Fragment, { children: [
33847
33882
  renderedLoaders,
33848
- renderedChildren
33883
+ !!children && isValidElement(renderedChildren) ? cloneElement(renderedChildren, null, children) : renderedChildren
33849
33884
  ] });
33850
33885
  return /* @__PURE__ */ jsxs(
33851
33886
  Fragment$1,
@@ -33943,6 +33978,12 @@ function renderLoaders({
33943
33978
  );
33944
33979
  }
33945
33980
  }
33981
+ function isParsedEventValue(value) {
33982
+ return value.__PARSED === true;
33983
+ }
33984
+ function isArrowExpression(value) {
33985
+ return value.type === T_ARROW_EXPRESSION;
33986
+ }
33946
33987
  const StateContainer = memo(
33947
33988
  forwardRef(function StateContainer2({
33948
33989
  node,
@@ -33954,7 +33995,9 @@ const StateContainer = memo(
33954
33995
  parentRenderContext,
33955
33996
  layoutContextRef,
33956
33997
  uidInfoRef,
33957
- isImplicit
33998
+ isImplicit,
33999
+ children,
34000
+ ...rest
33958
34001
  }, ref) {
33959
34002
  const [version2, setVersion] = useState(0);
33960
34003
  const routingParams = useRoutingParams();
@@ -34094,7 +34137,9 @@ const StateContainer = memo(
34094
34137
  memoedVarsRef: memoedVars,
34095
34138
  isImplicit,
34096
34139
  ref,
34097
- uidInfoRef
34140
+ uidInfoRef,
34141
+ ...rest,
34142
+ children
34098
34143
  }
34099
34144
  ) });
34100
34145
  })
@@ -34299,7 +34344,9 @@ const ContainerWrapper = memo(
34299
34344
  parentDispatch,
34300
34345
  parentRenderContext,
34301
34346
  layoutContextRef,
34302
- uidInfoRef
34347
+ uidInfoRef,
34348
+ children,
34349
+ ...rest
34303
34350
  }, ref) {
34304
34351
  const containerizedNode = useMemo(() => getWrappedWithContainer(node), [node]);
34305
34352
  return /* @__PURE__ */ jsx(ErrorBoundary, { node, location: "container", children: /* @__PURE__ */ jsx(
@@ -34315,7 +34362,9 @@ const ContainerWrapper = memo(
34315
34362
  layoutContextRef,
34316
34363
  uidInfoRef,
34317
34364
  isImplicit: node.type !== "Container" && containerizedNode.uses === void 0,
34318
- ref
34365
+ ref,
34366
+ ...rest,
34367
+ children
34319
34368
  }
34320
34369
  ) });
34321
34370
  })
@@ -34679,6 +34728,7 @@ const ComponentAdapter = forwardRef(function ComponentAdapter2({
34679
34728
  memoedVarsRef,
34680
34729
  onUnmount,
34681
34730
  uidInfoRef,
34731
+ children,
34682
34732
  ...rest
34683
34733
  }, ref) {
34684
34734
  var _a;
@@ -34730,9 +34780,9 @@ const ComponentAdapter = forwardRef(function ComponentAdapter2({
34730
34780
  [lookupAction, uid]
34731
34781
  );
34732
34782
  const memoedRenderChild = useCallback(
34733
- (children, layoutContext, pRenderContext) => {
34783
+ (children2, layoutContext, pRenderContext) => {
34734
34784
  return renderChild2(
34735
- children,
34785
+ children2,
34736
34786
  layoutContext,
34737
34787
  pRenderContext || parentRenderContext,
34738
34788
  uidInfoRef
@@ -34870,12 +34920,13 @@ const ComponentAdapter = forwardRef(function ComponentAdapter2({
34870
34920
  return /* @__PURE__ */ jsx(InvalidComponent, { errors: [renderingError], node: safeNode, children: renderedNode });
34871
34921
  }
34872
34922
  if ((ref || !isEmpty(mouseEventHandlers)) && renderedNode && React__default.isValidElement(renderedNode)) {
34923
+ const childrenArray = !children ? [] : Array.isArray(children) ? children : [children];
34873
34924
  return cloneElement(renderedNode, {
34874
34925
  ref: ref ? composeRefs(ref, renderedNode.ref) : renderedNode.ref,
34875
34926
  ...mergeProps({ ...renderedNode.props, ...mouseEventHandlers }, rest)
34876
- });
34927
+ }, ...childrenArray);
34877
34928
  }
34878
- return React__default.isValidElement(renderedNode) ? renderedNode : /* @__PURE__ */ jsx(Fragment, { children: renderedNode });
34929
+ return React__default.isValidElement(renderedNode) && !!children ? cloneElement(renderedNode, null, children) : renderedNode;
34879
34930
  });
34880
34931
  function slotRenderer({ node, extractValue, renderChild: renderChild2, lookupAction, layoutContext }, parentRenderContext) {
34881
34932
  const templateName = extractValue.asOptionalString(node.props.name);
@@ -34976,6 +35027,7 @@ const ComponentWrapper = memo(
34976
35027
  memoedVarsRef,
34977
35028
  cleanup,
34978
35029
  uidInfoRef,
35030
+ children,
34979
35031
  ...rest
34980
35032
  }, ref) {
34981
35033
  var _a;
@@ -35016,7 +35068,9 @@ const ComponentWrapper = memo(
35016
35068
  parentStatePartChanged: statePartChanged,
35017
35069
  parentRegisterComponentApi: registerComponentApi,
35018
35070
  uidInfoRef,
35019
- ref
35071
+ ref,
35072
+ ...rest,
35073
+ children
35020
35074
  }
35021
35075
  );
35022
35076
  } else {
@@ -35037,7 +35091,8 @@ const ComponentWrapper = memo(
35037
35091
  layoutContextRef: stableLayoutContext,
35038
35092
  ref,
35039
35093
  uidInfoRef,
35040
- ...rest
35094
+ ...rest,
35095
+ children
35041
35096
  }
35042
35097
  );
35043
35098
  }
@@ -35516,10 +35571,7 @@ function AppContent({
35516
35571
  cleanup: noop$1,
35517
35572
  memoedVarsRef
35518
35573
  });
35519
- return /* @__PURE__ */ jsx(AppContext.Provider, { value: appContextValue, children: /* @__PURE__ */ jsxs(AppStateContext.Provider, { value: appStateContextValue, children: [
35520
- renderedRoot,
35521
- children
35522
- ] }) });
35574
+ return /* @__PURE__ */ jsx(AppContext.Provider, { value: appContextValue, children: /* @__PURE__ */ jsx(AppStateContext.Provider, { value: appStateContextValue, children: !!children && isValidElement(renderedRoot) ? cloneElement(renderedRoot, null, children) : renderedRoot }) });
35523
35575
  }
35524
35576
  function signError(error2) {
35525
35577
  toast.error(typeof error2 === "string" ? error2 : error2.message || "Something went wrong");
@@ -35663,7 +35715,7 @@ function ApiInterceptorProvider({
35663
35715
  let interceptorWorker;
35664
35716
  (async () => {
35665
35717
  if (process.env.VITE_MOCK_ENABLED) {
35666
- const { createApiInterceptorWorker } = await import("./apiInterceptorWorker-BPCEQ5nI.mjs");
35718
+ const { createApiInterceptorWorker } = await import("./apiInterceptorWorker-DOyaK_s_.mjs");
35667
35719
  if (interceptor) {
35668
35720
  interceptorWorker = await createApiInterceptorWorker(interceptor, apiWorker);
35669
35721
  if (!apiWorker) {
@@ -1552,7 +1552,11 @@ class Parser {
1552
1552
  case TokenType.Function:
1553
1553
  return this.parseFunctionDeclaration();
1554
1554
  default:
1555
- return this.isExpressionStart(startToken) ? this.parseExpressionStatement(allowSequence) : null;
1555
+ if (this.isExpressionStart(startToken)) {
1556
+ return this.parseExpressionStatement(allowSequence);
1557
+ }
1558
+ this.reportError("W002", startToken, startToken.text);
1559
+ return null;
1556
1560
  }
1557
1561
  } finally {
1558
1562
  this._statementLevel--;
@@ -3701,7 +3705,9 @@ class Parser {
3701
3705
  }
3702
3706
  this._parseErrors.push({
3703
3707
  code: errorCode,
3704
- text: errorText
3708
+ text: errorText,
3709
+ line: token.startLine,
3710
+ column: token.startColumn
3705
3711
  });
3706
3712
  throw new ParserError$1(errorText, errorCode);
3707
3713
  function replace(input, placeholder, replacement) {
@@ -4808,8 +4814,7 @@ function parseScriptModule(moduleName, source) {
4808
4814
  exports,
4809
4815
  functions,
4810
4816
  statements,
4811
- sources: /* @__PURE__ */ new Map(),
4812
- executed: false
4817
+ sources: /* @__PURE__ */ new Map()
4813
4818
  };
4814
4819
  parsedModules.set(moduleName2, parsedModule2);
4815
4820
  if (errors.length > 0) {
@@ -4864,7 +4869,7 @@ function collectCodeBehindFromSource(moduleName, source) {
4864
4869
  addFunctionDeclaration(stmt);
4865
4870
  break;
4866
4871
  default:
4867
- throw new Error(`'${stmt.type}' is not allowed in a code-behind module.`);
4872
+ throw new Error(`Only reactive variable and function definitions are allowed in a code-behind module.`);
4868
4873
  }
4869
4874
  });
4870
4875
  return result;
@@ -4995,6 +5000,7 @@ const HelperNode = {
4995
5000
  item: "item",
4996
5001
  field: "field"
4997
5002
  };
5003
+ let lastParseId = 0;
4998
5004
  function nodeToComponentDef(node, originalGetText, fileId) {
4999
5005
  const getText = (node2) => {
5000
5006
  return node2.text ?? originalGetText(node2);
@@ -5202,7 +5208,7 @@ function nodeToComponentDef(node, originalGetText, fileId) {
5202
5208
  (name, value) => {
5203
5209
  if (!isComponent(comp)) return;
5204
5210
  comp.events ?? (comp.events = {});
5205
- comp.events[name] = value;
5211
+ comp.events[name] = parseEvent(value);
5206
5212
  },
5207
5213
  (name) => {
5208
5214
  if (onPrefixRegex.test(name)) {
@@ -5311,11 +5317,11 @@ function nodeToComponentDef(node, originalGetText, fileId) {
5311
5317
  comp.api[name] = value;
5312
5318
  } else if (startSegment === "event") {
5313
5319
  comp.events ?? (comp.events = {});
5314
- comp.events[name] = value;
5320
+ comp.events[name] = parseEvent(value);
5315
5321
  } else if (onPrefixRegex.test(name)) {
5316
5322
  comp.events ?? (comp.events = {});
5317
5323
  const eventName = name[2].toLowerCase() + name.substring(3);
5318
- comp.events[eventName] = value;
5324
+ comp.events[eventName] = parseEvent(value);
5319
5325
  } else {
5320
5326
  comp.props ?? (comp.props = {});
5321
5327
  comp.props[name] = value;
@@ -5734,6 +5740,27 @@ function nodeToComponentDef(node, originalGetText, fileId) {
5734
5740
  }
5735
5741
  }
5736
5742
  }
5743
+ function parseEvent(value) {
5744
+ if (typeof value !== "string") {
5745
+ return value;
5746
+ }
5747
+ const parser = new Parser(value);
5748
+ try {
5749
+ const statements = parser.parseStatements();
5750
+ return {
5751
+ __PARSED: true,
5752
+ statements,
5753
+ parseId: ++lastParseId,
5754
+ // TODO: retrieve the event source code only in dev mode
5755
+ source: value
5756
+ };
5757
+ } catch {
5758
+ if (parser.errors.length > 0) {
5759
+ const errMsg = parser.errors[0];
5760
+ throw new ParserError2(`${errMsg.text} [${errMsg.line}: ${errMsg.column}]`, errMsg.code);
5761
+ }
5762
+ }
5763
+ }
5737
5764
  }
5738
5765
  function createTextNodeCDataElement(textValue) {
5739
5766
  return {
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -31,7 +31,7 @@ function calculateHash(str) {
31
31
  }
32
32
  return hash;
33
33
  }
34
- function Theme({ id, isRoot = false, renderChild, node, tone, toastDuration = 5000, themeVars = constants_1.EMPTY_OBJECT, layoutContext, }) {
34
+ function Theme({ id, isRoot = false, renderChild, node, tone, toastDuration = 5000, themeVars = constants_1.EMPTY_OBJECT, layoutContext, children }) {
35
35
  const generatedId = (0, react_1.useId)();
36
36
  const { themes, resources, resourceMap, activeThemeId, setRoot, root } = (0, ThemeContext_1.useThemes)();
37
37
  const { activeTheme, activeThemeTone } = (0, ThemeContext_1.useTheme)();
@@ -126,7 +126,7 @@ function Theme({ id, isRoot = false, renderChild, node, tone, toastDuration = 50
126
126
  if (el) {
127
127
  setRoot(el);
128
128
  }
129
- }, children: [(0, jsx_runtime_1.jsx)(ErrorBoundary_1.ErrorBoundary, { node: node, location: "theme-root", children: renderChild(node.children) }), (0, jsx_runtime_1.jsx)(NotificationToast_1.NotificationToast, { toastDuration: toastDuration })] })] }));
129
+ }, children: [(0, jsx_runtime_1.jsxs)(ErrorBoundary_1.ErrorBoundary, { node: node, location: "theme-root", children: [renderChild(node.children), children] }), (0, jsx_runtime_1.jsx)(NotificationToast_1.NotificationToast, { toastDuration: toastDuration })] })] }));
130
130
  }
131
131
  return ((0, jsx_runtime_1.jsxs)(ThemeContext_1.ThemeContext.Provider, { value: currentThemeContextValue, children: [(0, jsx_runtime_1.jsx)("style", { children: `.${rangeClassName} {${css}}` }), (0, jsx_runtime_1.jsx)("style", { children: `.${className} {${css}}` }), (0, jsx_runtime_1.jsx)("div", { className: (0, classnames_1.default)(Theme_module_scss_1.default.from, fromClass) }), renderChild(node.children, Object.assign(Object.assign({}, layoutContext), { themeClassName: className })), (0, jsx_runtime_1.jsx)("div", { className: (0, classnames_1.default)(Theme_module_scss_1.default.to, toClass) }), root &&
132
132
  (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)("div", { className: (0, classnames_1.default)(className), ref: (el) => {
@@ -78,7 +78,7 @@ const layout_resolver_1 = require("../theming/layout-resolver");
78
78
  */
79
79
  const ComponentAdapter = (0, react_1.forwardRef)(function ComponentAdapter(_a, ref) {
80
80
  var _b;
81
- var { node, state, appContext, dispatch, lookupAction, lookupSyncCallback, renderChild, registerComponentApi, layoutContextRef, parentRenderContext, memoedVarsRef, onUnmount, uidInfoRef } = _a, rest = __rest(_a, ["node", "state", "appContext", "dispatch", "lookupAction", "lookupSyncCallback", "renderChild", "registerComponentApi", "layoutContextRef", "parentRenderContext", "memoedVarsRef", "onUnmount", "uidInfoRef"]);
81
+ var { node, state, appContext, dispatch, lookupAction, lookupSyncCallback, renderChild, registerComponentApi, layoutContextRef, parentRenderContext, memoedVarsRef, onUnmount, uidInfoRef, children } = _a, rest = __rest(_a, ["node", "state", "appContext", "dispatch", "lookupAction", "lookupSyncCallback", "renderChild", "registerComponentApi", "layoutContextRef", "parentRenderContext", "memoedVarsRef", "onUnmount", "uidInfoRef", "children"]);
82
82
  // --- Make sure the component definition has `props` and `events` properties
83
83
  // --- (even if they are empty)
84
84
  const safeNode = (0, react_1.useMemo)(() => {
@@ -247,10 +247,11 @@ const ComponentAdapter = (0, react_1.forwardRef)(function ComponentAdapter(_a, r
247
247
  if ((ref || !(0, lodash_es_1.isEmpty)(mouseEventHandlers)) && renderedNode && react_1.default.isValidElement(renderedNode)) {
248
248
  // --- For radix UI/accessibility, read more here:
249
249
  // --- https://www.radix-ui.com/primitives/docs/guides/composition
250
- return (0, react_1.cloneElement)(renderedNode, Object.assign({ ref: ref ? (0, react_compose_refs_1.composeRefs)(ref, renderedNode.ref) : renderedNode.ref }, (0, mergeProps_1.mergeProps)(Object.assign(Object.assign({}, renderedNode.props), mouseEventHandlers), rest)));
250
+ const childrenArray = !children ? [] : Array.isArray(children) ? children : [children];
251
+ return (0, react_1.cloneElement)(renderedNode, Object.assign({ ref: ref ? (0, react_compose_refs_1.composeRefs)(ref, renderedNode.ref) : renderedNode.ref }, (0, mergeProps_1.mergeProps)(Object.assign(Object.assign({}, renderedNode.props), mouseEventHandlers), rest)), ...(childrenArray));
251
252
  }
252
253
  // --- If the rendering resulted in multiple React nodes, wrap them in a fragment.
253
- return react_1.default.isValidElement(renderedNode) ? renderedNode : (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: renderedNode });
254
+ return (react_1.default.isValidElement(renderedNode) && !!children) ? (0, react_1.cloneElement)(renderedNode, null, children) : renderedNode;
254
255
  });
255
256
  /**
256
257
  * This function renders the content of a slot. If the slot is named, it looks for a template
@@ -25,7 +25,7 @@ const ComponentAdapter_1 = __importDefault(require("./ComponentAdapter"));
25
25
  */
26
26
  exports.ComponentWrapper = (0, react_1.memo)((0, react_1.forwardRef)(function ComponentWrapper(_a, ref) {
27
27
  var _b;
28
- var { node, resolvedKey, state, dispatch, appContext, lookupAction, lookupSyncCallback, registerComponentApi, renderChild, statePartChanged, layoutContext, parentRenderContext, memoedVarsRef, cleanup, uidInfoRef } = _a, rest = __rest(_a, ["node", "resolvedKey", "state", "dispatch", "appContext", "lookupAction", "lookupSyncCallback", "registerComponentApi", "renderChild", "statePartChanged", "layoutContext", "parentRenderContext", "memoedVarsRef", "cleanup", "uidInfoRef"]);
28
+ var { node, resolvedKey, state, dispatch, appContext, lookupAction, lookupSyncCallback, registerComponentApi, renderChild, statePartChanged, layoutContext, parentRenderContext, memoedVarsRef, cleanup, uidInfoRef, children } = _a, rest = __rest(_a, ["node", "resolvedKey", "state", "dispatch", "appContext", "lookupAction", "lookupSyncCallback", "registerComponentApi", "renderChild", "statePartChanged", "layoutContext", "parentRenderContext", "memoedVarsRef", "cleanup", "uidInfoRef", "children"]);
29
29
  // --- We pass the layout context to the child components, so we need to
30
30
  // --- make sure that it is stable
31
31
  const stableLayoutContext = (0, react_1.useRef)(layoutContext);
@@ -51,11 +51,11 @@ exports.ComponentWrapper = (0, react_1.memo)((0, react_1.forwardRef)(function Co
51
51
  }, [nodeWithTransformedLoaders, resolvedDataPropIsString, uidInfoRef]);
52
52
  if ((0, ContainerWrapper_1.isContainerLike)(nodeWithTransformedDatasourceProp)) {
53
53
  // --- This component should be rendered as a container
54
- return ((0, jsx_runtime_1.jsx)(ContainerWrapper_1.ContainerWrapper, { resolvedKey: resolvedKey, node: nodeWithTransformedDatasourceProp, parentState: state, parentDispatch: dispatch, layoutContextRef: stableLayoutContext, parentRenderContext: parentRenderContext, parentStatePartChanged: statePartChanged, parentRegisterComponentApi: registerComponentApi, uidInfoRef: uidInfoRef, ref: ref }));
54
+ return ((0, jsx_runtime_1.jsx)(ContainerWrapper_1.ContainerWrapper, Object.assign({ resolvedKey: resolvedKey, node: nodeWithTransformedDatasourceProp, parentState: state, parentDispatch: dispatch, layoutContextRef: stableLayoutContext, parentRenderContext: parentRenderContext, parentStatePartChanged: statePartChanged, parentRegisterComponentApi: registerComponentApi, uidInfoRef: uidInfoRef, ref: ref }, rest, { children: children })));
55
55
  }
56
56
  else {
57
57
  // --- This component should be rendered as a regular component
58
- return ((0, jsx_runtime_1.jsx)(ComponentAdapter_1.default, Object.assign({ onUnmount: cleanup, memoedVarsRef: memoedVarsRef, node: nodeWithTransformedDatasourceProp, state: state, dispatch: dispatch, appContext: appContext, lookupAction: lookupAction, lookupSyncCallback: lookupSyncCallback, registerComponentApi: registerComponentApi, renderChild: renderChild, parentRenderContext: parentRenderContext, layoutContextRef: stableLayoutContext, ref: ref, uidInfoRef: uidInfoRef }, rest)));
58
+ return ((0, jsx_runtime_1.jsx)(ComponentAdapter_1.default, Object.assign({ onUnmount: cleanup, memoedVarsRef: memoedVarsRef, node: nodeWithTransformedDatasourceProp, state: state, dispatch: dispatch, appContext: appContext, lookupAction: lookupAction, lookupSyncCallback: lookupSyncCallback, registerComponentApi: registerComponentApi, renderChild: renderChild, parentRenderContext: parentRenderContext, layoutContextRef: stableLayoutContext, ref: ref, uidInfoRef: uidInfoRef }, rest, { children: children })));
59
59
  }
60
60
  }));
61
61
  // --- Create a DataLoader component for each DataSource child within the
@@ -69,7 +69,7 @@ const ThemeContext_1 = require("../theming/ThemeContext");
69
69
  const LoaderComponent_1 = require("../LoaderComponent");
70
70
  const constants_1 = require("../constants");
71
71
  // React component to display a view container and implement its behavior
72
- 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, }, ref) {
72
+ 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) {
73
73
  var _a;
74
74
  const { apiBoundContainer } = node;
75
75
  const dispatch = isImplicit ? parentDispatch : containerDispatch;
@@ -160,6 +160,13 @@ exports.Container = (0, react_1.memo)((0, react_1.forwardRef)(function Container
160
160
  }
161
161
  statements = parsedStatementsRef.current[source];
162
162
  }
163
+ else if (isParsedEventValue(source)) {
164
+ const parseId = source.parseId.toString();
165
+ if (!parsedStatementsRef.current[parseId]) {
166
+ parsedStatementsRef.current[parseId] = (0, statementUtils_1.prepareHandlerStatements)(source.statements, evalContext);
167
+ }
168
+ statements = parsedStatementsRef.current[parseId];
169
+ }
163
170
  else {
164
171
  statements = [
165
172
  {
@@ -293,23 +300,48 @@ exports.Container = (0, react_1.memo)((0, react_1.forwardRef)(function Container
293
300
  }
294
301
  }, [appContext]);
295
302
  const getOrCreateEventHandlerFn = (0, misc_1.useEvent)((src, uid, options) => {
296
- var _a;
303
+ var _a, _b;
297
304
  if (Array.isArray(src)) {
298
305
  throw new Error("Multiple event handlers are not supported");
299
306
  }
300
- const stringSrc = typeof src === "string" ? src : src.statement.nodeId;
301
- const fnCacheKey = `${options === null || options === void 0 ? void 0 : options.eventName};${stringSrc}`;
302
- const handler = (...eventArgs) => {
303
- return runCodeAsync(src, uid, options, ...(0, lodash_es_1.cloneDeep)(eventArgs));
304
- };
305
- if (options === null || options === void 0 ? void 0 : options.ephemeral) {
306
- return handler;
307
+ if (typeof src === "string") {
308
+ // --- We have a string event handler
309
+ const fnCacheKey = `${options === null || options === void 0 ? void 0 : options.eventName};${src}`;
310
+ const handler = (...eventArgs) => {
311
+ return runCodeAsync(src, uid, options, ...(0, lodash_es_1.cloneDeep)(eventArgs));
312
+ };
313
+ if (options === null || options === void 0 ? void 0 : options.ephemeral) {
314
+ return handler;
315
+ }
316
+ if (!((_a = fnsRef.current[uid]) === null || _a === void 0 ? void 0 : _a[fnCacheKey])) {
317
+ fnsRef.current[uid] = fnsRef.current[uid] || {};
318
+ fnsRef.current[uid][fnCacheKey] = handler;
319
+ }
320
+ return fnsRef.current[uid][fnCacheKey];
307
321
  }
308
- if (!((_a = fnsRef.current[uid]) === null || _a === void 0 ? void 0 : _a[fnCacheKey])) {
309
- fnsRef.current[uid] = fnsRef.current[uid] || {};
310
- fnsRef.current[uid][fnCacheKey] = handler;
322
+ if (isParsedEventValue(src)) {
323
+ // --- We have the syntax tree to execute, no need to cache
324
+ return (...eventArgs) => {
325
+ return runCodeAsync(src, uid, options, ...(0, lodash_es_1.cloneDeep)(eventArgs));
326
+ };
327
+ }
328
+ if (isArrowExpression(src)) {
329
+ // --- We have an arrow expression to execute
330
+ const fnCacheKey = `${options === null || options === void 0 ? void 0 : options.eventName};${src.statement.nodeId}`;
331
+ const handler = (...eventArgs) => {
332
+ return runCodeAsync(src, uid, options, ...(0, lodash_es_1.cloneDeep)(eventArgs));
333
+ };
334
+ if (options === null || options === void 0 ? void 0 : options.ephemeral) {
335
+ return handler;
336
+ }
337
+ if (!((_b = fnsRef.current[uid]) === null || _b === void 0 ? void 0 : _b[fnCacheKey])) {
338
+ fnsRef.current[uid] = fnsRef.current[uid] || {};
339
+ fnsRef.current[uid][fnCacheKey] = handler;
340
+ }
341
+ return fnsRef.current[uid][fnCacheKey];
311
342
  }
312
- return fnsRef.current[uid][fnCacheKey];
343
+ // --- We have an unknown event handler
344
+ throw new Error("Invalid event handler");
313
345
  });
314
346
  const getOrCreateSyncCallbackFn = (0, react_1.useCallback)((arrowExpression, uid) => {
315
347
  var _a;
@@ -512,7 +544,10 @@ exports.Container = (0, react_1.memo)((0, react_1.forwardRef)(function Container
512
544
  lookupSyncCallback,
513
545
  cleanup,
514
546
  });
515
- const containerContent = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [renderedLoaders, renderedChildren] }));
547
+ //TODO illesg
548
+ const containerContent = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [renderedLoaders, !!children && (0, react_1.isValidElement)(renderedChildren)
549
+ ? (0, react_1.cloneElement)(renderedChildren, null, children)
550
+ : renderedChildren] }));
516
551
  return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [showContainer && ((0, jsx_runtime_1.jsx)(StateViewerNative_1.StateViewer, { state: componentState, showBoundary: stateViewProps === null || stateViewProps === void 0 ? void 0 : stateViewProps.showBoundary, blink: stateViewProps === null || stateViewProps === void 0 ? void 0 : stateViewProps.blink, children: containerContent })), !showContainer && containerContent] }, node.uid
517
552
  ? `${resolvedKey}>${(0, extractParam_1.extractParam)(componentState, node.uid, appContext, true)}`
518
553
  : undefined));
@@ -565,3 +600,9 @@ function renderLoaders({ uidInfo, uidInfoRef, loaders = constants_1.EMPTY_ARRAY,
565
600
  return ((0, jsx_runtime_1.jsx)(LoaderComponent_1.LoaderComponent, { onUnmount: cleanup, node: loader, state: componentState, dispatch: dispatch, registerComponentApi: registerComponentApi, lookupAction: lookupAction, lookupSyncCallback: lookupSyncCallback, memoedVarsRef: memoedVarsRef, appContext: appContext }));
566
601
  }
567
602
  }
603
+ function isParsedEventValue(value) {
604
+ return value.__PARSED === true;
605
+ }
606
+ function isArrowExpression(value) {
607
+ return value.type === ScriptingSourceTree_1.T_ARROW_EXPRESSION;
608
+ }
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.ContainerWrapper = void 0;
4
15
  exports.isContainerLike = isContainerLike;
@@ -30,10 +41,11 @@ function isContainerLike(node) {
30
41
  * provides a context for the children to access the state and the API of the
31
42
  * parent component.
32
43
  */
33
- exports.ContainerWrapper = (0, react_1.memo)((0, react_1.forwardRef)(function ContainerWrapper({ node, resolvedKey, parentState, parentStatePartChanged, parentRegisterComponentApi, parentDispatch, parentRenderContext, layoutContextRef, uidInfoRef, }, ref) {
44
+ exports.ContainerWrapper = (0, react_1.memo)((0, react_1.forwardRef)(function ContainerWrapper(_a, ref) {
45
+ var { node, resolvedKey, parentState, parentStatePartChanged, parentRegisterComponentApi, parentDispatch, parentRenderContext, layoutContextRef, uidInfoRef, children } = _a, rest = __rest(_a, ["node", "resolvedKey", "parentState", "parentStatePartChanged", "parentRegisterComponentApi", "parentDispatch", "parentRenderContext", "layoutContextRef", "uidInfoRef", "children"]);
34
46
  // --- Make sure the component node is wrapped with a container
35
47
  const containerizedNode = (0, react_1.useMemo)(() => getWrappedWithContainer(node), [node]);
36
- return ((0, jsx_runtime_1.jsx)(ErrorBoundary_1.ErrorBoundary, { node: node, location: "container", children: (0, jsx_runtime_1.jsx)(StateContainer_1.StateContainer, { node: containerizedNode, resolvedKey: resolvedKey, parentState: parentState, parentStatePartChanged: parentStatePartChanged, parentRegisterComponentApi: parentRegisterComponentApi, parentDispatch: parentDispatch, parentRenderContext: parentRenderContext, layoutContextRef: layoutContextRef, uidInfoRef: uidInfoRef, isImplicit: node.type !== "Container" && containerizedNode.uses === undefined, ref: ref }) }));
48
+ return ((0, jsx_runtime_1.jsx)(ErrorBoundary_1.ErrorBoundary, { node: node, location: "container", children: (0, jsx_runtime_1.jsx)(StateContainer_1.StateContainer, Object.assign({ node: containerizedNode, resolvedKey: resolvedKey, parentState: parentState, parentStatePartChanged: parentStatePartChanged, parentRegisterComponentApi: parentRegisterComponentApi, parentDispatch: parentDispatch, parentRenderContext: parentRenderContext, layoutContextRef: layoutContextRef, uidInfoRef: uidInfoRef, isImplicit: node.type !== "Container" && containerizedNode.uses === undefined, ref: ref }, rest, { children: children })) }));
37
49
  }));
38
50
  /**
39
51
  * Wraps the specified component node with a container