@xuda.io/xuda-worker-bundle 1.3.2690 → 1.3.2692

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 (2) hide show
  1. package/index.js +290 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2353,6 +2353,296 @@ func.common.fastHash = function (inputString) {
2353
2353
  };
2354
2354
 
2355
2355
  glb.new_xu_render = false;
2356
+ func.runtime = func.runtime || {};
2357
+ func.runtime.ui = func.runtime.ui || {};
2358
+ func.runtime.render = func.runtime.render || {};
2359
+ func.runtime.widgets = func.runtime.widgets || {};
2360
+
2361
+ // Shared render-tree contract helpers live here so browser and headless runtimes can resolve the same UI structure.
2362
+
2363
+ func.runtime.render.TREE_CONTRACT_VERSION = func.runtime.render.TREE_CONTRACT_VERSION || 'xuda.render_tree.v1';
2364
+ func.runtime.render._tree_widget_capability_cache = func.runtime.render._tree_widget_capability_cache || {};
2365
+
2366
+ func.runtime.render.safe_clone_tree_value = function (value) {
2367
+ if (typeof structuredClone === 'function') {
2368
+ try {
2369
+ return structuredClone(value);
2370
+ } catch (_) {
2371
+ // Fall through to the recursive clone below.
2372
+ }
2373
+ }
2374
+
2375
+ if (Array.isArray(value)) {
2376
+ return value.map(function (item) {
2377
+ return func.runtime.render.safe_clone_tree_value(item);
2378
+ });
2379
+ }
2380
+
2381
+ if (value && typeof value === 'object') {
2382
+ const cloned = {};
2383
+ const keys = Object.keys(value);
2384
+ for (let index = 0; index < keys.length; index++) {
2385
+ const key = keys[index];
2386
+ cloned[key] = func.runtime.render.safe_clone_tree_value(value[key]);
2387
+ }
2388
+ return cloned;
2389
+ }
2390
+
2391
+ return value;
2392
+ };
2393
+ func.runtime.render.sort_tree_debug_value = function (value) {
2394
+ if (Array.isArray(value)) {
2395
+ return value.map(function (item) {
2396
+ return func.runtime.render.sort_tree_debug_value(item);
2397
+ });
2398
+ }
2399
+
2400
+ if (value && typeof value === 'object') {
2401
+ const sorted = {};
2402
+ const keys = Object.keys(value).sort();
2403
+ for (let index = 0; index < keys.length; index++) {
2404
+ const key = keys[index];
2405
+ sorted[key] = func.runtime.render.sort_tree_debug_value(value[key]);
2406
+ }
2407
+ return sorted;
2408
+ }
2409
+
2410
+ return value;
2411
+ };
2412
+ func.runtime.render.is_tree_node = function (nodeP) {
2413
+ return !!nodeP?.contract && nodeP.contract === func.runtime.render.TREE_CONTRACT_VERSION;
2414
+ };
2415
+ func.runtime.render.get_tree_source_node = function (nodeP) {
2416
+ if (!func.runtime.render.is_tree_node(nodeP)) {
2417
+ return nodeP || null;
2418
+ }
2419
+ return nodeP?.meta?.source_node || null;
2420
+ };
2421
+ func.runtime.render.get_tree_source_snapshot = function (nodeP) {
2422
+ if (!func.runtime.render.is_tree_node(nodeP)) {
2423
+ return func.runtime.render.safe_clone_tree_value(nodeP);
2424
+ }
2425
+ return nodeP?.meta?.source_snapshot || null;
2426
+ };
2427
+ func.runtime.render.get_tree_node_kind = function (nodeP) {
2428
+ const tag_name = typeof nodeP?.tagName === 'string' ? nodeP.tagName.toLowerCase() : '';
2429
+ const node_type = typeof nodeP?.type === 'string' ? nodeP.type.toLowerCase() : '';
2430
+
2431
+ if (tag_name === 'xu-widget') return 'widget';
2432
+ if (tag_name === 'xu-single-view') return 'single_view';
2433
+ if (tag_name === 'xu-multi-view') return 'multi_view';
2434
+ if (tag_name === 'xu-panel') return 'panel';
2435
+ if (tag_name === 'xu-teleport') return 'teleport';
2436
+ if (tag_name === 'xurender') return 'placeholder';
2437
+ if (tag_name === '#text' || node_type === 'text') return 'text';
2438
+ if (!tag_name && typeof nodeP?.content === 'string' && !Array.isArray(nodeP?.children)) return 'text';
2439
+ return 'element';
2440
+ };
2441
+ func.runtime.render.get_tree_node_id = function (nodeP, pathP) {
2442
+ if (nodeP?.id) {
2443
+ return nodeP.id;
2444
+ }
2445
+ if (nodeP?.id_org) {
2446
+ return nodeP.id_org;
2447
+ }
2448
+ const normalized_path = Array.isArray(pathP) && pathP.length ? pathP.join('.') : 'root';
2449
+ return `tree-node-${normalized_path}`;
2450
+ };
2451
+ func.runtime.render.get_tree_controls = function (attributes) {
2452
+ const attrs = attributes || {};
2453
+ return {
2454
+ xu_for: attrs['xu-for'] || attrs['xu-exp:xu-for'] || null,
2455
+ xu_if: attrs['xu-if'] || attrs['xu-exp:xu-if'] || null,
2456
+ xu_render: attrs['xu-render'] || attrs['xu-exp:xu-render'] || null,
2457
+ };
2458
+ };
2459
+ func.runtime.render.get_tree_node_capabilities = async function (options) {
2460
+ const attributes = options?.attributes || {};
2461
+ const plugin_name = attributes['xu-widget'];
2462
+ if (!plugin_name) {
2463
+ return null;
2464
+ }
2465
+
2466
+ const cache = func.runtime.render._tree_widget_capability_cache;
2467
+ if (cache[plugin_name]) {
2468
+ return func.runtime.render.safe_clone_tree_value(cache[plugin_name]);
2469
+ }
2470
+
2471
+ let capabilities = {
2472
+ browser: true,
2473
+ headless: false,
2474
+ };
2475
+
2476
+ try {
2477
+ if (options.SESSION_ID && options.paramsP && func.runtime.widgets?.create_context && func.runtime.widgets?.get_definition) {
2478
+ const widget_context = func.runtime.widgets.create_context(options.SESSION_ID, options.paramsP, attributes);
2479
+ const definition = await func.runtime.widgets.get_definition(widget_context);
2480
+ capabilities = func.runtime.widgets.normalize_capabilities(definition);
2481
+ }
2482
+ } catch (_) {
2483
+ // Keep the safe browser-only default when the widget definition is unavailable.
2484
+ }
2485
+
2486
+ cache[plugin_name] = capabilities;
2487
+ return func.runtime.render.safe_clone_tree_value(capabilities);
2488
+ };
2489
+ func.runtime.render.ensure_tree_node = async function (options) {
2490
+ if (!options?.nodeP) {
2491
+ return null;
2492
+ }
2493
+ if (func.runtime.render.is_tree_node(options.nodeP)) {
2494
+ return options.nodeP;
2495
+ }
2496
+ return await func.runtime.render.build_tree(options);
2497
+ };
2498
+ func.runtime.render.build_tree = async function (options) {
2499
+ if (Array.isArray(options?.nodeP)) {
2500
+ return await func.runtime.render.build_tree_list({
2501
+ ...options,
2502
+ nodesP: options.nodeP,
2503
+ });
2504
+ }
2505
+
2506
+ const nodeP = options?.nodeP;
2507
+ if (!nodeP) {
2508
+ return null;
2509
+ }
2510
+ if (func.runtime.render.is_tree_node(nodeP)) {
2511
+ return nodeP;
2512
+ }
2513
+
2514
+ const pathP = Array.isArray(options?.pathP) ? options.pathP.slice() : [];
2515
+ const tree_path = pathP.length ? pathP.slice() : [0];
2516
+ const attributes = func.runtime.render.safe_clone_tree_value(nodeP.attributes || {});
2517
+ if (typeof nodeP.content !== 'undefined' && typeof attributes['xu-content'] === 'undefined') {
2518
+ attributes['xu-content'] = func.runtime.render.safe_clone_tree_value(nodeP.content);
2519
+ }
2520
+
2521
+ const widget_capabilities = await func.runtime.render.get_tree_node_capabilities({
2522
+ SESSION_ID: options?.SESSION_ID,
2523
+ paramsP: options?.paramsP,
2524
+ attributes,
2525
+ });
2526
+ const children = [];
2527
+ const child_nodes = Array.isArray(nodeP.children) ? nodeP.children : [];
2528
+ const parent_tree_id = tree_path.join('.');
2529
+
2530
+ for (let index = 0; index < child_nodes.length; index++) {
2531
+ const child_tree = await func.runtime.render.build_tree({
2532
+ ...options,
2533
+ nodeP: child_nodes[index],
2534
+ pathP: tree_path.concat(index),
2535
+ parent_tree_id: parent_tree_id,
2536
+ keyP: index,
2537
+ parent_nodeP: nodeP,
2538
+ });
2539
+ if (child_tree) {
2540
+ children.push(child_tree);
2541
+ }
2542
+ }
2543
+
2544
+ const tree = {
2545
+ contract: func.runtime.render.TREE_CONTRACT_VERSION,
2546
+ id: func.runtime.render.get_tree_node_id(nodeP, tree_path),
2547
+ xu_tree_id: `tree.${tree_path.join('.')}`,
2548
+ kind: func.runtime.render.get_tree_node_kind(nodeP),
2549
+ tagName: nodeP.tagName || null,
2550
+ attributes,
2551
+ text: typeof nodeP.text !== 'undefined' ? func.runtime.render.safe_clone_tree_value(nodeP.text) : null,
2552
+ content: typeof nodeP.content !== 'undefined' ? func.runtime.render.safe_clone_tree_value(nodeP.content) : null,
2553
+ children,
2554
+ meta: {
2555
+ tree_id: tree_path.join('.'),
2556
+ path: tree_path,
2557
+ parent_tree_id: options?.parent_tree_id || null,
2558
+ key: typeof options?.keyP === 'undefined' ? null : options.keyP,
2559
+ recordid: nodeP?.recordid || null,
2560
+ dependency_fields: func.runtime.render.safe_clone_tree_value(nodeP?.dependency_fields || null),
2561
+ iterate_info: func.runtime.render.safe_clone_tree_value(options?.parent_infoP?.iterate_info || nodeP?.iterate_info || null),
2562
+ controls: func.runtime.render.get_tree_controls(attributes),
2563
+ capabilities: widget_capabilities,
2564
+ widget: attributes['xu-widget']
2565
+ ? {
2566
+ plugin_name: attributes['xu-widget'],
2567
+ method: attributes['xu-method'] || '_default',
2568
+ capabilities: widget_capabilities,
2569
+ }
2570
+ : null,
2571
+ source_node_id: nodeP?.id || nodeP?.id_org || null,
2572
+ source_node: nodeP,
2573
+ source_snapshot: func.runtime.ui?.get_node_snapshot
2574
+ ? func.runtime.ui.get_node_snapshot(nodeP)
2575
+ : func.runtime.render.safe_clone_tree_value(nodeP),
2576
+ },
2577
+ };
2578
+
2579
+ return tree;
2580
+ };
2581
+ func.runtime.render.build_tree_list = async function (options) {
2582
+ const nodes = Array.isArray(options?.nodesP) ? options.nodesP : [];
2583
+ const trees = [];
2584
+
2585
+ for (let index = 0; index < nodes.length; index++) {
2586
+ const tree = await func.runtime.render.build_tree({
2587
+ ...options,
2588
+ nodeP: nodes[index],
2589
+ pathP: Array.isArray(options?.pathP) && options.pathP.length ? options.pathP.concat(index) : [index],
2590
+ keyP: index,
2591
+ });
2592
+ if (tree) {
2593
+ trees.push(tree);
2594
+ }
2595
+ }
2596
+
2597
+ return trees;
2598
+ };
2599
+ func.runtime.render.sanitize_tree_for_debug = function (treeP) {
2600
+ if (Array.isArray(treeP)) {
2601
+ return treeP.map(function (child) {
2602
+ return func.runtime.render.sanitize_tree_for_debug(child);
2603
+ });
2604
+ }
2605
+
2606
+ if (!func.runtime.render.is_tree_node(treeP)) {
2607
+ return func.runtime.render.sort_tree_debug_value(func.runtime.render.safe_clone_tree_value(treeP));
2608
+ }
2609
+
2610
+ return {
2611
+ contract: treeP.contract,
2612
+ id: treeP.id,
2613
+ xu_tree_id: treeP.xu_tree_id || null,
2614
+ kind: treeP.kind,
2615
+ tagName: treeP.tagName,
2616
+ attributes: func.runtime.render.sort_tree_debug_value(treeP.attributes || {}),
2617
+ text: treeP.text,
2618
+ content: treeP.content,
2619
+ children: treeP.children.map(function (child) {
2620
+ return func.runtime.render.sanitize_tree_for_debug(child);
2621
+ }),
2622
+ meta: {
2623
+ tree_id: treeP.meta?.tree_id || null,
2624
+ path: func.runtime.render.safe_clone_tree_value(treeP.meta?.path || []),
2625
+ parent_tree_id: treeP.meta?.parent_tree_id || null,
2626
+ key: typeof treeP.meta?.key === 'undefined' ? null : treeP.meta.key,
2627
+ recordid: treeP.meta?.recordid || null,
2628
+ dependency_fields: func.runtime.render.sort_tree_debug_value(treeP.meta?.dependency_fields || null),
2629
+ iterate_info: func.runtime.render.sort_tree_debug_value(treeP.meta?.iterate_info || null),
2630
+ controls: func.runtime.render.sort_tree_debug_value(treeP.meta?.controls || null),
2631
+ capabilities: func.runtime.render.sort_tree_debug_value(treeP.meta?.capabilities || null),
2632
+ widget: treeP.meta?.widget
2633
+ ? {
2634
+ plugin_name: treeP.meta.widget.plugin_name,
2635
+ method: treeP.meta.widget.method,
2636
+ capabilities: func.runtime.render.sort_tree_debug_value(treeP.meta.widget.capabilities || null),
2637
+ }
2638
+ : null,
2639
+ source_node_id: treeP.meta?.source_node_id || null,
2640
+ },
2641
+ };
2642
+ };
2643
+ func.runtime.render.serialize_tree = function (treeP, spacing = 2) {
2644
+ return JSON.stringify(func.runtime.render.sanitize_tree_for_debug(treeP), null, spacing);
2645
+ };
2356
2646
  glb.DEBUG_INFO_OBJ = {};
2357
2647
  // var CONNECTION_ATTEMPTS = 0;
2358
2648
  glb.APP_INFO = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-worker-bundle",
3
- "version": "1.3.2690",
3
+ "version": "1.3.2692",
4
4
  "description": "xuda framework",
5
5
  "main": "index.js",
6
6
  "scripts": {