@xuda.io/runtime-bundle 1.0.1430 → 1.0.1432

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.
@@ -36695,8 +36695,23 @@ func.runtime.render.handle_xu_bind = async function (options) {
36695
36695
  };
36696
36696
  func.runtime.render.apply_xu_class = async function (options) {
36697
36697
  try {
36698
- const classes_obj = typeof options.val.value === 'string' ? JSON.parse(options.val.value) : Object.assign({}, {}, options.val.value);
36698
+ const raw_value = options?.val?.value;
36699
36699
  const xuData = func.runtime.ui.get_data(options.$elm)?.xuData;
36700
+ if (typeof raw_value === 'string') {
36701
+ const trimmed = raw_value.trim();
36702
+ const looks_like_object = trimmed.startsWith('{') && trimmed.endsWith('}');
36703
+
36704
+ if (!looks_like_object) {
36705
+ func.runtime.render.apply_expression_class(options.$elm, raw_value);
36706
+ xuData.debug_info.attribute_stat['xu-class'] = func.runtime.ui.get_first_node(options.$elm)?.className || func.runtime.ui.get_attr(options.$elm, 'class');
36707
+ return {};
36708
+ }
36709
+ }
36710
+
36711
+ const classes_obj = typeof raw_value === 'string' ? JSON5.parse(raw_value) : Object.assign({}, {}, raw_value);
36712
+ if (typeof classes_obj !== 'object' || classes_obj === null || Array.isArray(classes_obj)) {
36713
+ throw new Error('xu-class expects an object map or a class string');
36714
+ }
36700
36715
  const class_names = Object.keys(classes_obj);
36701
36716
 
36702
36717
  for (let index = 0; index < class_names.length; index++) {
@@ -36725,7 +36740,18 @@ func.runtime.render.apply_xu_class = async function (options) {
36725
36740
  xuData.debug_info.attribute_stat['xu-class'] = func.runtime.ui.get_first_node(options.$elm)?.className || func.runtime.ui.get_attr(options.$elm, 'class');
36726
36741
  return {};
36727
36742
  } catch (e) {
36728
- console.warn('parse error:' + options.val.value);
36743
+ await func.runtime.render.report_xu_runtime_error(
36744
+ {
36745
+ ...options,
36746
+ xu_func: 'xu-class',
36747
+ val: {
36748
+ key: 'xu-class',
36749
+ value: options?.val?.value,
36750
+ },
36751
+ },
36752
+ e,
36753
+ 'xu-class has invalid syntax',
36754
+ );
36729
36755
  return { abort: true };
36730
36756
  }
36731
36757
  };
@@ -37406,14 +37432,43 @@ func.runtime.widgets = func.runtime.widgets || {};
37406
37432
  // Browser-only common xu handler factories live here so registry composition can stay small.
37407
37433
 
37408
37434
  func.runtime.render.build_base_xu_handlers = function (options, _ds) {
37435
+ const parse_object_value = function (attr_name, val, shape = 'object') {
37436
+ let parsed_value = val?.value;
37437
+ if (typeof parsed_value === 'string') {
37438
+ try {
37439
+ parsed_value = JSON5.parse(parsed_value);
37440
+ } catch (error) {
37441
+ throw func.runtime.render.build_xu_runtime_error(
37442
+ { ...options, xu_func: attr_name, val: { key: attr_name, value: val?.value } },
37443
+ error,
37444
+ `${attr_name} has invalid ${shape} syntax`,
37445
+ );
37446
+ }
37447
+ }
37448
+
37449
+ const valid =
37450
+ shape === 'array'
37451
+ ? Array.isArray(parsed_value)
37452
+ : typeof parsed_value === 'object' && parsed_value !== null && !Array.isArray(parsed_value);
37453
+
37454
+ if (!valid) {
37455
+ throw func.runtime.render.build_xu_runtime_error(
37456
+ { ...options, xu_func: attr_name, val: { key: attr_name, value: val?.value } },
37457
+ null,
37458
+ `${attr_name} expects a ${shape} value`,
37459
+ );
37460
+ }
37461
+
37462
+ return parsed_value;
37463
+ };
37409
37464
  return {
37410
37465
  'xu-attrs': async function ($elm, val) {
37411
37466
  if (!val.value) return {};
37412
- if (!(typeof val.value === 'object' && val.value !== null)) throw 'xu-attrs value us not an object';
37413
- const attr_keys = Object.keys(val.value);
37467
+ const attrs_obj = parse_object_value('xu-attrs', val, 'object');
37468
+ const attr_keys = Object.keys(attrs_obj);
37414
37469
  for (let index = 0; index < attr_keys.length; index++) {
37415
37470
  const attr_key = attr_keys[index];
37416
- options.nodeP.attributes[attr_key] = val.value[attr_key];
37471
+ options.nodeP.attributes[attr_key] = attrs_obj[attr_key];
37417
37472
  }
37418
37473
  return {};
37419
37474
  },
@@ -37533,7 +37588,7 @@ func.runtime.render.build_base_xu_handlers = function (options, _ds) {
37533
37588
  return {};
37534
37589
  },
37535
37590
  'xu-cdn': async function ($elm, val) {
37536
- const resources_obj = val.value || {};
37591
+ const resources_obj = parse_object_value('xu-cdn', val, 'object');
37537
37592
  const resource_keys = Object.keys(resources_obj);
37538
37593
  for (let index = 0; index < resource_keys.length; index++) {
37539
37594
  const resource = resources_obj[resource_keys[index]];
@@ -37542,7 +37597,7 @@ func.runtime.render.build_base_xu_handlers = function (options, _ds) {
37542
37597
  return {};
37543
37598
  },
37544
37599
  'xu-ui-plugin': async function ($elm, val) {
37545
- const plugins_obj = val.value || {};
37600
+ const plugins_obj = parse_object_value('xu-ui-plugin', val, 'object');
37546
37601
  const plugin_names = Object.keys(plugins_obj);
37547
37602
  for (let index = 0; index < plugin_names.length; index++) {
37548
37603
  const plugin_name = plugin_names[index];
@@ -37553,14 +37608,14 @@ func.runtime.render.build_base_xu_handlers = function (options, _ds) {
37553
37608
  },
37554
37609
  'xu-store': async function ($elm, val) {
37555
37610
  try {
37556
- const fields_obj = JSON5.parse(val.value);
37611
+ const fields_obj = parse_object_value('xu-store', val, 'object');
37557
37612
  const field_ids = Object.keys(fields_obj);
37558
37613
  for (let index = 0; index < field_ids.length; index++) {
37559
37614
  const field_id = field_ids[index];
37560
37615
  func.datasource.add_dynamic_field_to_ds(options.SESSION_ID, options.paramsP.dsSessionP, field_id, fields_obj[field_id]);
37561
37616
  }
37562
37617
  } catch (err) {
37563
- console.error(err);
37618
+ throw err;
37564
37619
  }
37565
37620
  return {};
37566
37621
  },
@@ -37683,6 +37738,36 @@ func.runtime.render = func.runtime.render || {};
37683
37738
  func.runtime.widgets = func.runtime.widgets || {};
37684
37739
 
37685
37740
  // Browser-only xu-attribute dispatch lives here so the attribute phase engine can stay focused.
37741
+ func.runtime.render.build_xu_runtime_error = function (options, error, fallback_message) {
37742
+ const raw_message = error?.message || error || fallback_message || 'Unknown runtime error';
37743
+ const err = error instanceof Error ? error : new Error(raw_message);
37744
+ err.xu_func = options?.xu_func;
37745
+ err.node_tag = options?.nodeP?.tagName;
37746
+ err.raw_value = options?.val?.value;
37747
+ err.ui_id = func.runtime?.ui?.get_attr ? func.runtime.ui.get_attr(options?.$elm, 'xu-ui-id') : null;
37748
+ return err;
37749
+ };
37750
+ func.runtime.render.report_xu_runtime_error = async function (options, error, fallback_message) {
37751
+ const err = func.runtime.render.build_xu_runtime_error(options, error, fallback_message);
37752
+ const attr_name = options?.val?.key || options?.xu_func || 'xu-*';
37753
+ const tag_name = options?.nodeP?.tagName || 'unknown';
37754
+ const raw_value = typeof err.raw_value === 'string' ? err.raw_value : JSON.stringify(err.raw_value);
37755
+ const message = [`${attr_name} failed on <${tag_name}>`, err.message];
37756
+
37757
+ if (raw_value) {
37758
+ message.push(`Value: ${raw_value}`);
37759
+ }
37760
+
37761
+ if (err.ui_id) {
37762
+ message.push(`xu-ui-id: ${err.ui_id}`);
37763
+ }
37764
+
37765
+ console.error('XUDA RUNTIME', message.join(' | '), err);
37766
+ if (func.utils?.debug_report) {
37767
+ await func.utils.debug_report(options?.SESSION_ID, 'Slim runtime', message.join(' | '), 'E', err);
37768
+ }
37769
+ return {};
37770
+ };
37686
37771
  func.runtime.render.execute_xu_function = async function (options) {
37687
37772
  if (options.is_skeleton) return;
37688
37773
 
@@ -37714,13 +37799,13 @@ func.runtime.render.execute_xu_function = async function (options) {
37714
37799
 
37715
37800
  try {
37716
37801
  if (!common_fx[options.xu_func]) {
37717
- console.warn('invalid xu-tag', options.xu_func);
37802
+ await func.runtime.render.report_xu_runtime_error(options, null, `Unknown xu directive: ${options.xu_func}`);
37718
37803
  return {};
37719
37804
  }
37720
37805
 
37721
37806
  return await common_fx[options.xu_func](options.$elm, options.val);
37722
37807
  } catch (error) {
37723
- debugger;
37808
+ return await func.runtime.render.report_xu_runtime_error(options, error);
37724
37809
  }
37725
37810
  };
37726
37811
  func.datasource = {};