xmlui 0.12.1 → 0.12.3

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 (44) hide show
  1. package/dist/bin/index.cjs +51 -42
  2. package/dist/bin/index.js +51 -42
  3. package/dist/for-node/server.cjs +6 -1
  4. package/dist/for-node/server.js +6 -1
  5. package/dist/for-node/vite-xmlui-plugin.cjs +50 -42
  6. package/dist/for-node/vite-xmlui-plugin.js +50 -42
  7. package/dist/lib/extractParam-GS7LIVZM.js +4805 -0
  8. package/dist/lib/{index-CkXI-l7q.js → index-AgiUyuFm.js} +16116 -18396
  9. package/dist/lib/index.css +2 -2
  10. package/dist/{metadata/initMock-Cpy_qJ1V.js → lib/initMock-Cq2ebZpN.js} +2 -1
  11. package/dist/lib/{parser-Ck-3ozza.js → parser-C4e5pSIM.js} +68 -76
  12. package/dist/lib/scss/components-core/theming/_themes.scss +53 -36
  13. package/dist/lib/syntax-monaco.d.ts +2 -1
  14. package/dist/lib/syntax-textmate.d.ts +2 -1
  15. package/dist/lib/testing.d.ts +7 -1
  16. package/dist/lib/testing.js +14 -6
  17. package/dist/lib/{xmlui-parser-CZxYIZ3q.js → xmlui-parser-Dk9Ul7U9.js} +1 -1
  18. package/dist/lib/xmlui-parser.d.ts +252 -3
  19. package/dist/lib/xmlui-parser.js +4 -3
  20. package/dist/lib/xmlui.d.ts +119 -4
  21. package/dist/lib/xmlui.js +85 -85
  22. package/dist/metadata/TextBox-BJiWllqp.cjs +1 -0
  23. package/dist/metadata/{collectedComponentMetadata-CJco9icn.js → TextBox-BZVYQnAz.js} +13082 -18227
  24. package/dist/metadata/behavior-evaluator.cjs +1 -0
  25. package/dist/metadata/behavior-evaluator.js +61 -0
  26. package/dist/metadata/behaviors.cjs +1 -0
  27. package/dist/metadata/behaviors.js +14 -0
  28. package/dist/metadata/icons.cjs +1 -1
  29. package/dist/metadata/icons.js +1 -1
  30. package/dist/metadata/initMock-BgVjCiJ_.cjs +1 -0
  31. package/dist/{lib/initMock-eOGDnKDO.js → metadata/initMock-Btb5UJJR.js} +1 -1
  32. package/dist/metadata/metadata-utils.cjs +1 -0
  33. package/dist/metadata/metadata-utils.js +149 -0
  34. package/dist/metadata/transform-C6FwhNer.cjs +1 -0
  35. package/dist/metadata/transform-SCk0BLgv.js +6855 -0
  36. package/dist/metadata/xmlui-metadata.cjs +1 -1
  37. package/dist/metadata/xmlui-metadata.js +353 -3
  38. package/dist/metadata/xmlui.css +2 -2
  39. package/dist/standalone/xmlui-standalone.es.d.ts +120 -4
  40. package/dist/standalone/xmlui-standalone.umd.js +33 -33
  41. package/package.json +5 -1
  42. package/dist/lib/xmlui-serializer-DJVLKVvd.js +0 -667
  43. package/dist/metadata/collectedComponentMetadata-DCnnMRrp.cjs +0 -1
  44. package/dist/metadata/initMock-bKw7EX8i.cjs +0 -1
@@ -6816,6 +6816,28 @@ async function doParseModule(moduleName, source, moduleFetcher) {
6816
6816
  */
6817
6817
  const PARSED_MARK_PROP = "__PARSED__";
6818
6818
  /**
6819
+ * Marker property for arrow expression objects.
6820
+ * Used to identify executable arrow expressions in the expression tree.
6821
+ * These represent user-defined functions that can be called.
6822
+ *
6823
+ * @example
6824
+ * ```typescript
6825
+ * // Arrow functions created during script execution
6826
+ * const arrowFn = {
6827
+ * _ARROW_EXPR_: true,
6828
+ * args: ['x', 'y'],
6829
+ * statement: { ... },
6830
+ * closureContext: [...]
6831
+ * };
6832
+ *
6833
+ * // Check if a value is an arrow function
6834
+ * if (isArrowExpressionObject(value)) {
6835
+ * // Can be called as a function
6836
+ * }
6837
+ * ```
6838
+ */
6839
+ const ARROW_EXPR_MARK = "_ARROW_EXPR_";
6840
+ /**
6819
6841
  * Marker property for parsed event values.
6820
6842
  * Used to identify pre-parsed event handler syntax trees.
6821
6843
  *
@@ -7087,14 +7109,12 @@ async function collectCodeBehindFromSourceWithImports(moduleName, source, module
7087
7109
  const arrow = {
7088
7110
  type: T_ARROW_EXPRESSION,
7089
7111
  args: funcDecl.args.slice(),
7090
- statement: funcDecl.stmt
7091
- };
7092
- const codeDecl = {
7093
- [PARSED_MARK_PROP]: true,
7094
- tree: arrow
7112
+ statement: funcDecl.stmt,
7113
+ [ARROW_EXPR_MARK]: true,
7114
+ closureContext: []
7095
7115
  };
7096
- collectedFunctions[name] = codeDecl;
7097
- result.functions[name] = codeDecl;
7116
+ collectedFunctions[name] = arrow;
7117
+ result.functions[name] = arrow;
7098
7118
  }
7099
7119
  });
7100
7120
  return result;
@@ -7109,8 +7129,7 @@ function collectStatementFromModule(stmt, result, collectedFunctions) {
7109
7129
  if (decl.id.name in result.vars) throw new Error(`Duplicated var declaration: '${decl.id.name}'`);
7110
7130
  result.vars[decl.id.name] = {
7111
7131
  [PARSED_MARK_PROP]: true,
7112
- tree: decl.expr,
7113
- source: decl.expr?.source || null
7132
+ tree: decl.expr
7114
7133
  };
7115
7134
  });
7116
7135
  break;
@@ -7129,16 +7148,12 @@ function addFunctionDeclaration(stmt, result, collectedFunctions) {
7129
7148
  const arrow = {
7130
7149
  type: T_ARROW_EXPRESSION,
7131
7150
  args: stmt.args.slice(),
7132
- statement: stmt.stmt
7133
- };
7134
- collectedFunctions[stmt.id.name] = {
7135
- [PARSED_MARK_PROP]: true,
7136
- tree: arrow
7137
- };
7138
- result.functions[stmt.id.name] = {
7139
- [PARSED_MARK_PROP]: true,
7140
- tree: arrow
7151
+ statement: stmt.stmt,
7152
+ [ARROW_EXPR_MARK]: true,
7153
+ closureContext: []
7141
7154
  };
7155
+ collectedFunctions[stmt.id.name] = arrow;
7156
+ result.functions[stmt.id.name] = arrow;
7142
7157
  }
7143
7158
  function removeCodeBehindTokensFromTree(declarations) {
7144
7159
  if (!declarations) return;
@@ -7163,7 +7178,8 @@ function removeCodeBehindTokensFromTree(declarations) {
7163
7178
  }
7164
7179
  return state$1;
7165
7180
  };
7166
- visitNode(declaration.tree, state, nodeVisitor, nodeVisitor);
7181
+ const tree = declaration.tree || declaration;
7182
+ if (tree) visitNode(tree, state, nodeVisitor, nodeVisitor);
7167
7183
  }
7168
7184
  }
7169
7185
 
@@ -7711,6 +7727,7 @@ const ErrCodesTransform = {
7711
7727
  nsSchemeIncorrect: "T029",
7712
7728
  scriptParse: "T030",
7713
7729
  globalNotAllowedInNested: "T031",
7730
+ globalNotAllowedInComponent: "T032",
7714
7731
  ...ErrorCodes
7715
7732
  };
7716
7733
  const DIAGS_TRANSFORM = {
@@ -7798,7 +7815,11 @@ const DIAGS_TRANSFORM = {
7798
7815
  },
7799
7816
  globalNotAllowedInNested: {
7800
7817
  code: ErrCodesTransform.globalNotAllowedInNested,
7801
- message: "Global variables can only be declared in the root element or compound component definitions, not in nested regular components."
7818
+ message: "Global variables can only be declared in the root element of Main.xmlui, not in nested components."
7819
+ },
7820
+ globalNotAllowedInComponent: {
7821
+ code: ErrCodesTransform.globalNotAllowedInComponent,
7822
+ message: "Global variables cannot be declared in component definitions. Use Globals.xs or declare them in Main.xmlui instead."
7802
7823
  },
7803
7824
  cantHaveNameAttr: function(nodeName) {
7804
7825
  return {
@@ -8258,38 +8279,26 @@ function nodeToComponentDef(node, originalGetText, fileId, preResolvedImports) {
8258
8279
  vars[attr.name] = attr.value;
8259
8280
  });
8260
8281
  }
8261
- let globals;
8262
- const globalsAttrs = attrs.filter((attr) => attr.startSegment === "global");
8263
- if (globalsAttrs.length > 0) {
8264
- globals = {};
8265
- globalsAttrs.forEach((attr) => {
8266
- globals[attr.name] = attr.value;
8267
- });
8268
- }
8282
+ if (attrs.filter((attr) => attr.startSegment === "global").length > 0) reportError(DIAGS_TRANSFORM.globalNotAllowedInComponent);
8269
8283
  const children = getChildNodes(node$1);
8270
8284
  const nestedComponents = children.filter((child) => child.kind === SyntaxKind.ElementNode && !(getComponentName(child, getText) in HelperNode));
8271
8285
  if (nestedComponents.length === 0) nestedComponents.push(createTextNodeElement(""));
8272
8286
  const nonVarHelperNodes = [];
8273
8287
  const nestedVars = [];
8274
- const nestedGlobals = [];
8275
8288
  for (let child of children) if (child.kind === SyntaxKind.ElementNode) {
8276
8289
  const childName = getComponentName(child, getText);
8277
8290
  if (childName === HelperNode.variable) nestedVars.push(child);
8278
- else if (childName === HelperNode.global) nestedGlobals.push(child);
8291
+ else if (childName === HelperNode.global) reportError(DIAGS_TRANSFORM.globalNotAllowedInComponent, child.start, child.end);
8279
8292
  else if (childName in HelperNode) nonVarHelperNodes.push(child);
8280
8293
  }
8281
8294
  let element;
8282
- if (nestedComponents.length > 1 || nestedVars.length > 0 || nestedGlobals.length > 0) element = wrapWithFragment([
8283
- ...nestedVars,
8284
- ...nestedGlobals,
8285
- ...nestedComponents
8286
- ]);
8295
+ if (nestedComponents.length > 1 || nestedVars.length > 0) element = wrapWithFragment([...nestedVars, ...nestedComponents]);
8287
8296
  else element = nestedComponents[0];
8288
8297
  namespaceStack.push(/* @__PURE__ */ new Map());
8289
8298
  attrs.filter((attr) => attr.namespace === "xmlns").forEach((attr) => {
8290
8299
  addToNamespaces(namespaceStack, element, attr.unsegmentedName, attr.value);
8291
8300
  });
8292
- let nestedComponent = transformInnerElement(usesStack, element, true);
8301
+ let nestedComponent = transformInnerElement(usesStack, element, false);
8293
8302
  namespaceStack.pop();
8294
8303
  const component = {
8295
8304
  name: compoundName.value,
@@ -8305,10 +8314,6 @@ function nodeToComponentDef(node, originalGetText, fileId, preResolvedImports) {
8305
8314
  ...nestedComponent.vars,
8306
8315
  ...vars
8307
8316
  };
8308
- if (globals) nestedComponent.globalVars = {
8309
- ...nestedComponent.globalVars,
8310
- ...globals
8311
- };
8312
8317
  if (codeBehind) component.codeBehind = codeBehind.value;
8313
8318
  nestedComponent.debug = { source: {
8314
8319
  start: element.start,
@@ -10001,14 +10006,17 @@ const moduleScriptExtension = /* @__PURE__ */ new RegExp(`.${moduleFileExtension
10001
10006
  * Transform XMLUI files to JS objects.
10002
10007
  */
10003
10008
  function viteXmluiPlugin(pluginOptions = {}) {
10004
- let itemIndex = 0;
10009
+ let projectRoot = "";
10005
10010
  const normalizePath = (p) => p.replace(/\\/g, "/");
10006
10011
  return {
10007
10012
  name: "vite:transform-xmlui",
10013
+ configResolved(config) {
10014
+ projectRoot = normalizePath(config.root);
10015
+ },
10008
10016
  async transform(code, id, options) {
10009
10017
  const normalizedId = normalizePath(id);
10010
10018
  if (xmluiExtension.test(id)) {
10011
- const fileId = "" + itemIndex++;
10019
+ const fileId = projectRoot ? normalizedId.slice(projectRoot.length) : normalizedId;
10012
10020
  const scriptResult = ScriptExtractor.extractInlineScript(code);
10013
10021
  let codeBehind;
10014
10022
  if (scriptResult) {
@@ -10414,6 +10422,7 @@ const buildLib = async ({ watchMode, mode = "production" }) => {
10414
10422
  overrides = (await import(process.cwd() + `/vite.config-overrides`)).default || {};
10415
10423
  } catch (e) {}
10416
10424
  await (0, vite.build)((0, vite.defineConfig)({
10425
+ customLogger: overrides.customLogger,
10417
10426
  resolve: { extensions: [
10418
10427
  ".js",
10419
10428
  ".ts",
package/dist/bin/index.js CHANGED
@@ -6803,6 +6803,28 @@ async function doParseModule(moduleName, source, moduleFetcher) {
6803
6803
  */
6804
6804
  const PARSED_MARK_PROP = "__PARSED__";
6805
6805
  /**
6806
+ * Marker property for arrow expression objects.
6807
+ * Used to identify executable arrow expressions in the expression tree.
6808
+ * These represent user-defined functions that can be called.
6809
+ *
6810
+ * @example
6811
+ * ```typescript
6812
+ * // Arrow functions created during script execution
6813
+ * const arrowFn = {
6814
+ * _ARROW_EXPR_: true,
6815
+ * args: ['x', 'y'],
6816
+ * statement: { ... },
6817
+ * closureContext: [...]
6818
+ * };
6819
+ *
6820
+ * // Check if a value is an arrow function
6821
+ * if (isArrowExpressionObject(value)) {
6822
+ * // Can be called as a function
6823
+ * }
6824
+ * ```
6825
+ */
6826
+ const ARROW_EXPR_MARK = "_ARROW_EXPR_";
6827
+ /**
6806
6828
  * Marker property for parsed event values.
6807
6829
  * Used to identify pre-parsed event handler syntax trees.
6808
6830
  *
@@ -7074,14 +7096,12 @@ async function collectCodeBehindFromSourceWithImports(moduleName, source, module
7074
7096
  const arrow = {
7075
7097
  type: T_ARROW_EXPRESSION,
7076
7098
  args: funcDecl.args.slice(),
7077
- statement: funcDecl.stmt
7078
- };
7079
- const codeDecl = {
7080
- [PARSED_MARK_PROP]: true,
7081
- tree: arrow
7099
+ statement: funcDecl.stmt,
7100
+ [ARROW_EXPR_MARK]: true,
7101
+ closureContext: []
7082
7102
  };
7083
- collectedFunctions[name] = codeDecl;
7084
- result.functions[name] = codeDecl;
7103
+ collectedFunctions[name] = arrow;
7104
+ result.functions[name] = arrow;
7085
7105
  }
7086
7106
  });
7087
7107
  return result;
@@ -7096,8 +7116,7 @@ function collectStatementFromModule(stmt, result, collectedFunctions) {
7096
7116
  if (decl.id.name in result.vars) throw new Error(`Duplicated var declaration: '${decl.id.name}'`);
7097
7117
  result.vars[decl.id.name] = {
7098
7118
  [PARSED_MARK_PROP]: true,
7099
- tree: decl.expr,
7100
- source: decl.expr?.source || null
7119
+ tree: decl.expr
7101
7120
  };
7102
7121
  });
7103
7122
  break;
@@ -7116,16 +7135,12 @@ function addFunctionDeclaration(stmt, result, collectedFunctions) {
7116
7135
  const arrow = {
7117
7136
  type: T_ARROW_EXPRESSION,
7118
7137
  args: stmt.args.slice(),
7119
- statement: stmt.stmt
7120
- };
7121
- collectedFunctions[stmt.id.name] = {
7122
- [PARSED_MARK_PROP]: true,
7123
- tree: arrow
7124
- };
7125
- result.functions[stmt.id.name] = {
7126
- [PARSED_MARK_PROP]: true,
7127
- tree: arrow
7138
+ statement: stmt.stmt,
7139
+ [ARROW_EXPR_MARK]: true,
7140
+ closureContext: []
7128
7141
  };
7142
+ collectedFunctions[stmt.id.name] = arrow;
7143
+ result.functions[stmt.id.name] = arrow;
7129
7144
  }
7130
7145
  function removeCodeBehindTokensFromTree(declarations) {
7131
7146
  if (!declarations) return;
@@ -7150,7 +7165,8 @@ function removeCodeBehindTokensFromTree(declarations) {
7150
7165
  }
7151
7166
  return state$1;
7152
7167
  };
7153
- visitNode(declaration.tree, state, nodeVisitor, nodeVisitor);
7168
+ const tree = declaration.tree || declaration;
7169
+ if (tree) visitNode(tree, state, nodeVisitor, nodeVisitor);
7154
7170
  }
7155
7171
  }
7156
7172
 
@@ -7698,6 +7714,7 @@ const ErrCodesTransform = {
7698
7714
  nsSchemeIncorrect: "T029",
7699
7715
  scriptParse: "T030",
7700
7716
  globalNotAllowedInNested: "T031",
7717
+ globalNotAllowedInComponent: "T032",
7701
7718
  ...ErrorCodes
7702
7719
  };
7703
7720
  const DIAGS_TRANSFORM = {
@@ -7785,7 +7802,11 @@ const DIAGS_TRANSFORM = {
7785
7802
  },
7786
7803
  globalNotAllowedInNested: {
7787
7804
  code: ErrCodesTransform.globalNotAllowedInNested,
7788
- message: "Global variables can only be declared in the root element or compound component definitions, not in nested regular components."
7805
+ message: "Global variables can only be declared in the root element of Main.xmlui, not in nested components."
7806
+ },
7807
+ globalNotAllowedInComponent: {
7808
+ code: ErrCodesTransform.globalNotAllowedInComponent,
7809
+ message: "Global variables cannot be declared in component definitions. Use Globals.xs or declare them in Main.xmlui instead."
7789
7810
  },
7790
7811
  cantHaveNameAttr: function(nodeName) {
7791
7812
  return {
@@ -8245,38 +8266,26 @@ function nodeToComponentDef(node, originalGetText, fileId, preResolvedImports) {
8245
8266
  vars[attr.name] = attr.value;
8246
8267
  });
8247
8268
  }
8248
- let globals;
8249
- const globalsAttrs = attrs.filter((attr) => attr.startSegment === "global");
8250
- if (globalsAttrs.length > 0) {
8251
- globals = {};
8252
- globalsAttrs.forEach((attr) => {
8253
- globals[attr.name] = attr.value;
8254
- });
8255
- }
8269
+ if (attrs.filter((attr) => attr.startSegment === "global").length > 0) reportError(DIAGS_TRANSFORM.globalNotAllowedInComponent);
8256
8270
  const children = getChildNodes(node$1);
8257
8271
  const nestedComponents = children.filter((child) => child.kind === SyntaxKind.ElementNode && !(getComponentName(child, getText) in HelperNode));
8258
8272
  if (nestedComponents.length === 0) nestedComponents.push(createTextNodeElement(""));
8259
8273
  const nonVarHelperNodes = [];
8260
8274
  const nestedVars = [];
8261
- const nestedGlobals = [];
8262
8275
  for (let child of children) if (child.kind === SyntaxKind.ElementNode) {
8263
8276
  const childName = getComponentName(child, getText);
8264
8277
  if (childName === HelperNode.variable) nestedVars.push(child);
8265
- else if (childName === HelperNode.global) nestedGlobals.push(child);
8278
+ else if (childName === HelperNode.global) reportError(DIAGS_TRANSFORM.globalNotAllowedInComponent, child.start, child.end);
8266
8279
  else if (childName in HelperNode) nonVarHelperNodes.push(child);
8267
8280
  }
8268
8281
  let element;
8269
- if (nestedComponents.length > 1 || nestedVars.length > 0 || nestedGlobals.length > 0) element = wrapWithFragment([
8270
- ...nestedVars,
8271
- ...nestedGlobals,
8272
- ...nestedComponents
8273
- ]);
8282
+ if (nestedComponents.length > 1 || nestedVars.length > 0) element = wrapWithFragment([...nestedVars, ...nestedComponents]);
8274
8283
  else element = nestedComponents[0];
8275
8284
  namespaceStack.push(/* @__PURE__ */ new Map());
8276
8285
  attrs.filter((attr) => attr.namespace === "xmlns").forEach((attr) => {
8277
8286
  addToNamespaces(namespaceStack, element, attr.unsegmentedName, attr.value);
8278
8287
  });
8279
- let nestedComponent = transformInnerElement(usesStack, element, true);
8288
+ let nestedComponent = transformInnerElement(usesStack, element, false);
8280
8289
  namespaceStack.pop();
8281
8290
  const component = {
8282
8291
  name: compoundName.value,
@@ -8292,10 +8301,6 @@ function nodeToComponentDef(node, originalGetText, fileId, preResolvedImports) {
8292
8301
  ...nestedComponent.vars,
8293
8302
  ...vars
8294
8303
  };
8295
- if (globals) nestedComponent.globalVars = {
8296
- ...nestedComponent.globalVars,
8297
- ...globals
8298
- };
8299
8304
  if (codeBehind) component.codeBehind = codeBehind.value;
8300
8305
  nestedComponent.debug = { source: {
8301
8306
  start: element.start,
@@ -9988,14 +9993,17 @@ const moduleScriptExtension = /* @__PURE__ */ new RegExp(`.${moduleFileExtension
9988
9993
  * Transform XMLUI files to JS objects.
9989
9994
  */
9990
9995
  function viteXmluiPlugin(pluginOptions = {}) {
9991
- let itemIndex = 0;
9996
+ let projectRoot = "";
9992
9997
  const normalizePath = (p) => p.replace(/\\/g, "/");
9993
9998
  return {
9994
9999
  name: "vite:transform-xmlui",
10000
+ configResolved(config) {
10001
+ projectRoot = normalizePath(config.root);
10002
+ },
9995
10003
  async transform(code, id, options) {
9996
10004
  const normalizedId = normalizePath(id);
9997
10005
  if (xmluiExtension.test(id)) {
9998
- const fileId = "" + itemIndex++;
10006
+ const fileId = projectRoot ? normalizedId.slice(projectRoot.length) : normalizedId;
9999
10007
  const scriptResult = ScriptExtractor.extractInlineScript(code);
10000
10008
  let codeBehind;
10001
10009
  if (scriptResult) {
@@ -10401,6 +10409,7 @@ const buildLib = async ({ watchMode, mode = "production" }) => {
10401
10409
  overrides = (await import(process.cwd() + `/vite.config-overrides`)).default || {};
10402
10410
  } catch (e) {}
10403
10411
  await build(defineConfig({
10412
+ customLogger: overrides.customLogger,
10404
10413
  resolve: { extensions: [
10405
10414
  ".js",
10406
10415
  ".ts",
@@ -407,6 +407,7 @@ const ErrCodesTransform = {
407
407
  nsSchemeIncorrect: "T029",
408
408
  scriptParse: "T030",
409
409
  globalNotAllowedInNested: "T031",
410
+ globalNotAllowedInComponent: "T032",
410
411
  ...ErrorCodes
411
412
  };
412
413
  const DIAGS_TRANSFORM = {
@@ -494,7 +495,11 @@ const DIAGS_TRANSFORM = {
494
495
  },
495
496
  globalNotAllowedInNested: {
496
497
  code: ErrCodesTransform.globalNotAllowedInNested,
497
- message: "Global variables can only be declared in the root element or compound component definitions, not in nested regular components."
498
+ message: "Global variables can only be declared in the root element of Main.xmlui, not in nested components."
499
+ },
500
+ globalNotAllowedInComponent: {
501
+ code: ErrCodesTransform.globalNotAllowedInComponent,
502
+ message: "Global variables cannot be declared in component definitions. Use Globals.xs or declare them in Main.xmlui instead."
498
503
  },
499
504
  cantHaveNameAttr: function(nodeName) {
500
505
  return {
@@ -378,6 +378,7 @@ const ErrCodesTransform = {
378
378
  nsSchemeIncorrect: "T029",
379
379
  scriptParse: "T030",
380
380
  globalNotAllowedInNested: "T031",
381
+ globalNotAllowedInComponent: "T032",
381
382
  ...ErrorCodes
382
383
  };
383
384
  const DIAGS_TRANSFORM = {
@@ -465,7 +466,11 @@ const DIAGS_TRANSFORM = {
465
466
  },
466
467
  globalNotAllowedInNested: {
467
468
  code: ErrCodesTransform.globalNotAllowedInNested,
468
- message: "Global variables can only be declared in the root element or compound component definitions, not in nested regular components."
469
+ message: "Global variables can only be declared in the root element of Main.xmlui, not in nested components."
470
+ },
471
+ globalNotAllowedInComponent: {
472
+ code: ErrCodesTransform.globalNotAllowedInComponent,
473
+ message: "Global variables cannot be declared in component definitions. Use Globals.xs or declare them in Main.xmlui instead."
469
474
  },
470
475
  cantHaveNameAttr: function(nodeName) {
471
476
  return {
@@ -6784,6 +6784,28 @@ async function doParseModule(moduleName, source, moduleFetcher) {
6784
6784
  */
6785
6785
  const PARSED_MARK_PROP = "__PARSED__";
6786
6786
  /**
6787
+ * Marker property for arrow expression objects.
6788
+ * Used to identify executable arrow expressions in the expression tree.
6789
+ * These represent user-defined functions that can be called.
6790
+ *
6791
+ * @example
6792
+ * ```typescript
6793
+ * // Arrow functions created during script execution
6794
+ * const arrowFn = {
6795
+ * _ARROW_EXPR_: true,
6796
+ * args: ['x', 'y'],
6797
+ * statement: { ... },
6798
+ * closureContext: [...]
6799
+ * };
6800
+ *
6801
+ * // Check if a value is an arrow function
6802
+ * if (isArrowExpressionObject(value)) {
6803
+ * // Can be called as a function
6804
+ * }
6805
+ * ```
6806
+ */
6807
+ const ARROW_EXPR_MARK = "_ARROW_EXPR_";
6808
+ /**
6787
6809
  * Marker property for parsed event values.
6788
6810
  * Used to identify pre-parsed event handler syntax trees.
6789
6811
  *
@@ -7055,14 +7077,12 @@ async function collectCodeBehindFromSourceWithImports(moduleName, source, module
7055
7077
  const arrow = {
7056
7078
  type: T_ARROW_EXPRESSION,
7057
7079
  args: funcDecl.args.slice(),
7058
- statement: funcDecl.stmt
7059
- };
7060
- const codeDecl = {
7061
- [PARSED_MARK_PROP]: true,
7062
- tree: arrow
7080
+ statement: funcDecl.stmt,
7081
+ [ARROW_EXPR_MARK]: true,
7082
+ closureContext: []
7063
7083
  };
7064
- collectedFunctions[name] = codeDecl;
7065
- result.functions[name] = codeDecl;
7084
+ collectedFunctions[name] = arrow;
7085
+ result.functions[name] = arrow;
7066
7086
  }
7067
7087
  });
7068
7088
  return result;
@@ -7077,8 +7097,7 @@ function collectStatementFromModule(stmt, result, collectedFunctions) {
7077
7097
  if (decl.id.name in result.vars) throw new Error(`Duplicated var declaration: '${decl.id.name}'`);
7078
7098
  result.vars[decl.id.name] = {
7079
7099
  [PARSED_MARK_PROP]: true,
7080
- tree: decl.expr,
7081
- source: decl.expr?.source || null
7100
+ tree: decl.expr
7082
7101
  };
7083
7102
  });
7084
7103
  break;
@@ -7097,16 +7116,12 @@ function addFunctionDeclaration(stmt, result, collectedFunctions) {
7097
7116
  const arrow = {
7098
7117
  type: T_ARROW_EXPRESSION,
7099
7118
  args: stmt.args.slice(),
7100
- statement: stmt.stmt
7101
- };
7102
- collectedFunctions[stmt.id.name] = {
7103
- [PARSED_MARK_PROP]: true,
7104
- tree: arrow
7105
- };
7106
- result.functions[stmt.id.name] = {
7107
- [PARSED_MARK_PROP]: true,
7108
- tree: arrow
7119
+ statement: stmt.stmt,
7120
+ [ARROW_EXPR_MARK]: true,
7121
+ closureContext: []
7109
7122
  };
7123
+ collectedFunctions[stmt.id.name] = arrow;
7124
+ result.functions[stmt.id.name] = arrow;
7110
7125
  }
7111
7126
  function removeCodeBehindTokensFromTree(declarations) {
7112
7127
  if (!declarations) return;
@@ -7131,7 +7146,8 @@ function removeCodeBehindTokensFromTree(declarations) {
7131
7146
  }
7132
7147
  return state$1;
7133
7148
  };
7134
- visitNode(declaration.tree, state, nodeVisitor, nodeVisitor);
7149
+ const tree = declaration.tree || declaration;
7150
+ if (tree) visitNode(tree, state, nodeVisitor, nodeVisitor);
7135
7151
  }
7136
7152
  }
7137
7153
 
@@ -7679,6 +7695,7 @@ const ErrCodesTransform = {
7679
7695
  nsSchemeIncorrect: "T029",
7680
7696
  scriptParse: "T030",
7681
7697
  globalNotAllowedInNested: "T031",
7698
+ globalNotAllowedInComponent: "T032",
7682
7699
  ...ErrorCodes
7683
7700
  };
7684
7701
  const DIAGS_TRANSFORM = {
@@ -7766,7 +7783,11 @@ const DIAGS_TRANSFORM = {
7766
7783
  },
7767
7784
  globalNotAllowedInNested: {
7768
7785
  code: ErrCodesTransform.globalNotAllowedInNested,
7769
- message: "Global variables can only be declared in the root element or compound component definitions, not in nested regular components."
7786
+ message: "Global variables can only be declared in the root element of Main.xmlui, not in nested components."
7787
+ },
7788
+ globalNotAllowedInComponent: {
7789
+ code: ErrCodesTransform.globalNotAllowedInComponent,
7790
+ message: "Global variables cannot be declared in component definitions. Use Globals.xs or declare them in Main.xmlui instead."
7770
7791
  },
7771
7792
  cantHaveNameAttr: function(nodeName) {
7772
7793
  return {
@@ -8226,38 +8247,26 @@ function nodeToComponentDef(node, originalGetText, fileId, preResolvedImports) {
8226
8247
  vars[attr.name] = attr.value;
8227
8248
  });
8228
8249
  }
8229
- let globals;
8230
- const globalsAttrs = attrs.filter((attr) => attr.startSegment === "global");
8231
- if (globalsAttrs.length > 0) {
8232
- globals = {};
8233
- globalsAttrs.forEach((attr) => {
8234
- globals[attr.name] = attr.value;
8235
- });
8236
- }
8250
+ if (attrs.filter((attr) => attr.startSegment === "global").length > 0) reportError(DIAGS_TRANSFORM.globalNotAllowedInComponent);
8237
8251
  const children = getChildNodes(node$1);
8238
8252
  const nestedComponents = children.filter((child) => child.kind === SyntaxKind.ElementNode && !(getComponentName(child, getText) in HelperNode));
8239
8253
  if (nestedComponents.length === 0) nestedComponents.push(createTextNodeElement(""));
8240
8254
  const nonVarHelperNodes = [];
8241
8255
  const nestedVars = [];
8242
- const nestedGlobals = [];
8243
8256
  for (let child of children) if (child.kind === SyntaxKind.ElementNode) {
8244
8257
  const childName = getComponentName(child, getText);
8245
8258
  if (childName === HelperNode.variable) nestedVars.push(child);
8246
- else if (childName === HelperNode.global) nestedGlobals.push(child);
8259
+ else if (childName === HelperNode.global) reportError(DIAGS_TRANSFORM.globalNotAllowedInComponent, child.start, child.end);
8247
8260
  else if (childName in HelperNode) nonVarHelperNodes.push(child);
8248
8261
  }
8249
8262
  let element;
8250
- if (nestedComponents.length > 1 || nestedVars.length > 0 || nestedGlobals.length > 0) element = wrapWithFragment([
8251
- ...nestedVars,
8252
- ...nestedGlobals,
8253
- ...nestedComponents
8254
- ]);
8263
+ if (nestedComponents.length > 1 || nestedVars.length > 0) element = wrapWithFragment([...nestedVars, ...nestedComponents]);
8255
8264
  else element = nestedComponents[0];
8256
8265
  namespaceStack.push(/* @__PURE__ */ new Map());
8257
8266
  attrs.filter((attr) => attr.namespace === "xmlns").forEach((attr) => {
8258
8267
  addToNamespaces(namespaceStack, element, attr.unsegmentedName, attr.value);
8259
8268
  });
8260
- let nestedComponent = transformInnerElement(usesStack, element, true);
8269
+ let nestedComponent = transformInnerElement(usesStack, element, false);
8261
8270
  namespaceStack.pop();
8262
8271
  const component = {
8263
8272
  name: compoundName.value,
@@ -8273,10 +8282,6 @@ function nodeToComponentDef(node, originalGetText, fileId, preResolvedImports) {
8273
8282
  ...nestedComponent.vars,
8274
8283
  ...vars
8275
8284
  };
8276
- if (globals) nestedComponent.globalVars = {
8277
- ...nestedComponent.globalVars,
8278
- ...globals
8279
- };
8280
8285
  if (codeBehind) component.codeBehind = codeBehind.value;
8281
8286
  nestedComponent.debug = { source: {
8282
8287
  start: element.start,
@@ -9969,14 +9974,17 @@ const moduleScriptExtension = /* @__PURE__ */ new RegExp(`.${moduleFileExtension
9969
9974
  * Transform XMLUI files to JS objects.
9970
9975
  */
9971
9976
  function viteXmluiPlugin(pluginOptions = {}) {
9972
- let itemIndex = 0;
9977
+ let projectRoot = "";
9973
9978
  const normalizePath = (p) => p.replace(/\\/g, "/");
9974
9979
  return {
9975
9980
  name: "vite:transform-xmlui",
9981
+ configResolved(config) {
9982
+ projectRoot = normalizePath(config.root);
9983
+ },
9976
9984
  async transform(code, id, options) {
9977
9985
  const normalizedId = normalizePath(id);
9978
9986
  if (xmluiExtension.test(id)) {
9979
- const fileId = "" + itemIndex++;
9987
+ const fileId = projectRoot ? normalizedId.slice(projectRoot.length) : normalizedId;
9980
9988
  const scriptResult = ScriptExtractor.extractInlineScript(code);
9981
9989
  let codeBehind;
9982
9990
  if (scriptResult) {