@xuda.io/xuda-worker-bundle 1.3.2691 → 1.3.2693
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.
- package/index.js +562 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2353,6 +2353,568 @@ 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
|
+
const get_first_defined = function (keys) {
|
|
2454
|
+
for (let index = 0; index < keys.length; index++) {
|
|
2455
|
+
const key = keys[index];
|
|
2456
|
+
if (Object.prototype.hasOwnProperty.call(attrs, key)) {
|
|
2457
|
+
return attrs[key];
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
return null;
|
|
2461
|
+
};
|
|
2462
|
+
return {
|
|
2463
|
+
xu_for: get_first_defined(['xu-for', 'xu-exp:xu-for']),
|
|
2464
|
+
xu_if: get_first_defined(['xu-if', 'xu-exp:xu-if']),
|
|
2465
|
+
xu_render: get_first_defined(['xu-render', 'xu-exp:xu-render']),
|
|
2466
|
+
};
|
|
2467
|
+
};
|
|
2468
|
+
func.runtime.render.get_tree_node_capabilities = async function (options) {
|
|
2469
|
+
const attributes = options?.attributes || {};
|
|
2470
|
+
const plugin_name = attributes['xu-widget'];
|
|
2471
|
+
if (!plugin_name) {
|
|
2472
|
+
return null;
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
const cache = func.runtime.render._tree_widget_capability_cache;
|
|
2476
|
+
if (cache[plugin_name]) {
|
|
2477
|
+
return func.runtime.render.safe_clone_tree_value(cache[plugin_name]);
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
let capabilities = {
|
|
2481
|
+
browser: true,
|
|
2482
|
+
headless: false,
|
|
2483
|
+
};
|
|
2484
|
+
|
|
2485
|
+
try {
|
|
2486
|
+
if (options.SESSION_ID && options.paramsP && func.runtime.widgets?.create_context && func.runtime.widgets?.get_definition) {
|
|
2487
|
+
const widget_context = func.runtime.widgets.create_context(options.SESSION_ID, options.paramsP, attributes);
|
|
2488
|
+
const definition = await func.runtime.widgets.get_definition(widget_context);
|
|
2489
|
+
capabilities = func.runtime.widgets.normalize_capabilities(definition);
|
|
2490
|
+
}
|
|
2491
|
+
} catch (_) {
|
|
2492
|
+
// Keep the safe browser-only default when the widget definition is unavailable.
|
|
2493
|
+
}
|
|
2494
|
+
|
|
2495
|
+
cache[plugin_name] = capabilities;
|
|
2496
|
+
return func.runtime.render.safe_clone_tree_value(capabilities);
|
|
2497
|
+
};
|
|
2498
|
+
func.runtime.render.ensure_tree_node = async function (options) {
|
|
2499
|
+
if (!options?.nodeP) {
|
|
2500
|
+
return null;
|
|
2501
|
+
}
|
|
2502
|
+
if (func.runtime.render.is_tree_node(options.nodeP)) {
|
|
2503
|
+
return options.nodeP;
|
|
2504
|
+
}
|
|
2505
|
+
return await func.runtime.render.build_tree(options);
|
|
2506
|
+
};
|
|
2507
|
+
func.runtime.render.build_tree = async function (options) {
|
|
2508
|
+
if (Array.isArray(options?.nodeP)) {
|
|
2509
|
+
return await func.runtime.render.build_tree_list({
|
|
2510
|
+
...options,
|
|
2511
|
+
nodesP: options.nodeP,
|
|
2512
|
+
});
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
const nodeP = options?.nodeP;
|
|
2516
|
+
if (!nodeP) {
|
|
2517
|
+
return null;
|
|
2518
|
+
}
|
|
2519
|
+
if (func.runtime.render.is_tree_node(nodeP)) {
|
|
2520
|
+
return nodeP;
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
const pathP = Array.isArray(options?.pathP) ? options.pathP.slice() : [];
|
|
2524
|
+
const tree_path = pathP.length ? pathP.slice() : [0];
|
|
2525
|
+
const attributes = func.runtime.render.safe_clone_tree_value(nodeP.attributes || {});
|
|
2526
|
+
if (typeof nodeP.content !== 'undefined' && typeof attributes['xu-content'] === 'undefined') {
|
|
2527
|
+
attributes['xu-content'] = func.runtime.render.safe_clone_tree_value(nodeP.content);
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
const widget_capabilities = await func.runtime.render.get_tree_node_capabilities({
|
|
2531
|
+
SESSION_ID: options?.SESSION_ID,
|
|
2532
|
+
paramsP: options?.paramsP,
|
|
2533
|
+
attributes,
|
|
2534
|
+
});
|
|
2535
|
+
const children = [];
|
|
2536
|
+
const child_nodes = Array.isArray(nodeP.children) ? nodeP.children : [];
|
|
2537
|
+
const parent_tree_id = tree_path.join('.');
|
|
2538
|
+
|
|
2539
|
+
for (let index = 0; index < child_nodes.length; index++) {
|
|
2540
|
+
const child_tree = await func.runtime.render.build_tree({
|
|
2541
|
+
...options,
|
|
2542
|
+
nodeP: child_nodes[index],
|
|
2543
|
+
pathP: tree_path.concat(index),
|
|
2544
|
+
parent_tree_id: parent_tree_id,
|
|
2545
|
+
keyP: index,
|
|
2546
|
+
parent_nodeP: nodeP,
|
|
2547
|
+
});
|
|
2548
|
+
if (child_tree) {
|
|
2549
|
+
children.push(child_tree);
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2553
|
+
const tree = {
|
|
2554
|
+
contract: func.runtime.render.TREE_CONTRACT_VERSION,
|
|
2555
|
+
id: func.runtime.render.get_tree_node_id(nodeP, tree_path),
|
|
2556
|
+
xu_tree_id: `tree.${tree_path.join('.')}`,
|
|
2557
|
+
kind: func.runtime.render.get_tree_node_kind(nodeP),
|
|
2558
|
+
tagName: nodeP.tagName || null,
|
|
2559
|
+
attributes,
|
|
2560
|
+
text: typeof nodeP.text !== 'undefined' ? func.runtime.render.safe_clone_tree_value(nodeP.text) : null,
|
|
2561
|
+
content: typeof nodeP.content !== 'undefined' ? func.runtime.render.safe_clone_tree_value(nodeP.content) : null,
|
|
2562
|
+
children,
|
|
2563
|
+
meta: {
|
|
2564
|
+
tree_id: tree_path.join('.'),
|
|
2565
|
+
path: tree_path,
|
|
2566
|
+
parent_tree_id: options?.parent_tree_id || null,
|
|
2567
|
+
key: typeof options?.keyP === 'undefined' ? null : options.keyP,
|
|
2568
|
+
recordid: nodeP?.recordid || null,
|
|
2569
|
+
dependency_fields: func.runtime.render.safe_clone_tree_value(nodeP?.dependency_fields || null),
|
|
2570
|
+
iterate_info: func.runtime.render.safe_clone_tree_value(options?.parent_infoP?.iterate_info || nodeP?.iterate_info || null),
|
|
2571
|
+
controls: func.runtime.render.get_tree_controls(attributes),
|
|
2572
|
+
capabilities: widget_capabilities,
|
|
2573
|
+
widget: attributes['xu-widget']
|
|
2574
|
+
? {
|
|
2575
|
+
plugin_name: attributes['xu-widget'],
|
|
2576
|
+
method: attributes['xu-method'] || '_default',
|
|
2577
|
+
capabilities: widget_capabilities,
|
|
2578
|
+
}
|
|
2579
|
+
: null,
|
|
2580
|
+
source_node_id: nodeP?.id || nodeP?.id_org || null,
|
|
2581
|
+
source_node: nodeP,
|
|
2582
|
+
source_snapshot: func.runtime.ui?.get_node_snapshot
|
|
2583
|
+
? func.runtime.ui.get_node_snapshot(nodeP)
|
|
2584
|
+
: func.runtime.render.safe_clone_tree_value(nodeP),
|
|
2585
|
+
},
|
|
2586
|
+
};
|
|
2587
|
+
|
|
2588
|
+
return tree;
|
|
2589
|
+
};
|
|
2590
|
+
func.runtime.render.build_tree_list = async function (options) {
|
|
2591
|
+
const nodes = Array.isArray(options?.nodesP) ? options.nodesP : [];
|
|
2592
|
+
const trees = [];
|
|
2593
|
+
|
|
2594
|
+
for (let index = 0; index < nodes.length; index++) {
|
|
2595
|
+
const tree = await func.runtime.render.build_tree({
|
|
2596
|
+
...options,
|
|
2597
|
+
nodeP: nodes[index],
|
|
2598
|
+
pathP: Array.isArray(options?.pathP) && options.pathP.length ? options.pathP.concat(index) : [index],
|
|
2599
|
+
keyP: index,
|
|
2600
|
+
});
|
|
2601
|
+
if (tree) {
|
|
2602
|
+
trees.push(tree);
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
return trees;
|
|
2607
|
+
};
|
|
2608
|
+
func.runtime.render.sanitize_tree_for_debug = function (treeP) {
|
|
2609
|
+
if (Array.isArray(treeP)) {
|
|
2610
|
+
return treeP.map(function (child) {
|
|
2611
|
+
return func.runtime.render.sanitize_tree_for_debug(child);
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
|
|
2615
|
+
if (!func.runtime.render.is_tree_node(treeP)) {
|
|
2616
|
+
return func.runtime.render.sort_tree_debug_value(func.runtime.render.safe_clone_tree_value(treeP));
|
|
2617
|
+
}
|
|
2618
|
+
|
|
2619
|
+
return {
|
|
2620
|
+
contract: treeP.contract,
|
|
2621
|
+
id: treeP.id,
|
|
2622
|
+
xu_tree_id: treeP.xu_tree_id || null,
|
|
2623
|
+
kind: treeP.kind,
|
|
2624
|
+
tagName: treeP.tagName,
|
|
2625
|
+
attributes: func.runtime.render.sort_tree_debug_value(treeP.attributes || {}),
|
|
2626
|
+
text: treeP.text,
|
|
2627
|
+
content: treeP.content,
|
|
2628
|
+
children: treeP.children.map(function (child) {
|
|
2629
|
+
return func.runtime.render.sanitize_tree_for_debug(child);
|
|
2630
|
+
}),
|
|
2631
|
+
meta: {
|
|
2632
|
+
tree_id: treeP.meta?.tree_id || null,
|
|
2633
|
+
path: func.runtime.render.safe_clone_tree_value(treeP.meta?.path || []),
|
|
2634
|
+
parent_tree_id: treeP.meta?.parent_tree_id || null,
|
|
2635
|
+
key: typeof treeP.meta?.key === 'undefined' ? null : treeP.meta.key,
|
|
2636
|
+
recordid: treeP.meta?.recordid || null,
|
|
2637
|
+
dependency_fields: func.runtime.render.sort_tree_debug_value(treeP.meta?.dependency_fields || null),
|
|
2638
|
+
iterate_info: func.runtime.render.sort_tree_debug_value(treeP.meta?.iterate_info || null),
|
|
2639
|
+
controls: func.runtime.render.sort_tree_debug_value(treeP.meta?.controls || null),
|
|
2640
|
+
capabilities: func.runtime.render.sort_tree_debug_value(treeP.meta?.capabilities || null),
|
|
2641
|
+
widget: treeP.meta?.widget
|
|
2642
|
+
? {
|
|
2643
|
+
plugin_name: treeP.meta.widget.plugin_name,
|
|
2644
|
+
method: treeP.meta.widget.method,
|
|
2645
|
+
capabilities: func.runtime.render.sort_tree_debug_value(treeP.meta.widget.capabilities || null),
|
|
2646
|
+
}
|
|
2647
|
+
: null,
|
|
2648
|
+
source_node_id: treeP.meta?.source_node_id || null,
|
|
2649
|
+
},
|
|
2650
|
+
};
|
|
2651
|
+
};
|
|
2652
|
+
func.runtime.render.serialize_tree = function (treeP, spacing = 2) {
|
|
2653
|
+
return JSON.stringify(func.runtime.render.sanitize_tree_for_debug(treeP), null, spacing);
|
|
2654
|
+
};
|
|
2655
|
+
func.runtime = func.runtime || {};
|
|
2656
|
+
func.runtime.ui = func.runtime.ui || {};
|
|
2657
|
+
func.runtime.render = func.runtime.render || {};
|
|
2658
|
+
func.runtime.widgets = func.runtime.widgets || {};
|
|
2659
|
+
|
|
2660
|
+
// Shared string-renderer helpers live here so headless/server runtimes can materialize the render tree without a DOM.
|
|
2661
|
+
|
|
2662
|
+
func.runtime.render.HTML_VOID_TAGS = func.runtime.render.HTML_VOID_TAGS || {
|
|
2663
|
+
area: true,
|
|
2664
|
+
base: true,
|
|
2665
|
+
br: true,
|
|
2666
|
+
col: true,
|
|
2667
|
+
embed: true,
|
|
2668
|
+
hr: true,
|
|
2669
|
+
img: true,
|
|
2670
|
+
input: true,
|
|
2671
|
+
link: true,
|
|
2672
|
+
meta: true,
|
|
2673
|
+
param: true,
|
|
2674
|
+
source: true,
|
|
2675
|
+
track: true,
|
|
2676
|
+
wbr: true,
|
|
2677
|
+
};
|
|
2678
|
+
func.runtime.render.escape_html = function (value) {
|
|
2679
|
+
return `${value ?? ''}`
|
|
2680
|
+
.replaceAll('&', '&')
|
|
2681
|
+
.replaceAll('<', '<')
|
|
2682
|
+
.replaceAll('>', '>')
|
|
2683
|
+
.replaceAll('"', '"')
|
|
2684
|
+
.replaceAll("'", ''');
|
|
2685
|
+
};
|
|
2686
|
+
func.runtime.render.escape_html_attribute = function (value) {
|
|
2687
|
+
return func.runtime.render.escape_html(value);
|
|
2688
|
+
};
|
|
2689
|
+
func.runtime.render.is_html_void_tag = function (tag_name) {
|
|
2690
|
+
return !!func.runtime.render.HTML_VOID_TAGS[(tag_name || '').toLowerCase()];
|
|
2691
|
+
};
|
|
2692
|
+
func.runtime.render.is_falsey_render_value = function (value) {
|
|
2693
|
+
if (value === false || value === null || typeof value === 'undefined') {
|
|
2694
|
+
return true;
|
|
2695
|
+
}
|
|
2696
|
+
if (typeof value === 'number') {
|
|
2697
|
+
return value === 0;
|
|
2698
|
+
}
|
|
2699
|
+
if (typeof value === 'string') {
|
|
2700
|
+
const normalized = value.trim().toLowerCase();
|
|
2701
|
+
return normalized === '' || normalized === 'false' || normalized === '0' || normalized === 'null' || normalized === 'undefined' || normalized === 'off' || normalized === 'no';
|
|
2702
|
+
}
|
|
2703
|
+
return false;
|
|
2704
|
+
};
|
|
2705
|
+
func.runtime.render.should_render_tree_node = function (treeP) {
|
|
2706
|
+
const controls = treeP?.meta?.controls || {};
|
|
2707
|
+
if (controls.xu_if !== null && controls.xu_if !== undefined && func.runtime.render.is_falsey_render_value(controls.xu_if)) {
|
|
2708
|
+
return false;
|
|
2709
|
+
}
|
|
2710
|
+
if (controls.xu_render !== null && controls.xu_render !== undefined && func.runtime.render.is_falsey_render_value(controls.xu_render)) {
|
|
2711
|
+
return false;
|
|
2712
|
+
}
|
|
2713
|
+
return true;
|
|
2714
|
+
};
|
|
2715
|
+
func.runtime.render.is_tree_control_attribute = function (key) {
|
|
2716
|
+
if (!key) {
|
|
2717
|
+
return false;
|
|
2718
|
+
}
|
|
2719
|
+
return (
|
|
2720
|
+
key.startsWith('xu-exp:') ||
|
|
2721
|
+
key === 'xu-widget' ||
|
|
2722
|
+
key === 'xu-method' ||
|
|
2723
|
+
key === 'xu-for' ||
|
|
2724
|
+
key === 'xu-for-key' ||
|
|
2725
|
+
key === 'xu-for-val' ||
|
|
2726
|
+
key === 'xu-if' ||
|
|
2727
|
+
key === 'xu-render' ||
|
|
2728
|
+
key === 'xu-bind' ||
|
|
2729
|
+
key === 'xu-content' ||
|
|
2730
|
+
key === 'xu-text' ||
|
|
2731
|
+
key === 'xu-html' ||
|
|
2732
|
+
key === 'xu-show' ||
|
|
2733
|
+
key === 'xu-panel-program' ||
|
|
2734
|
+
key === 'xu-teleport'
|
|
2735
|
+
);
|
|
2736
|
+
};
|
|
2737
|
+
func.runtime.render.get_string_renderer_tag_name = function (treeP) {
|
|
2738
|
+
switch (treeP?.kind) {
|
|
2739
|
+
case 'widget':
|
|
2740
|
+
case 'single_view':
|
|
2741
|
+
case 'multi_view':
|
|
2742
|
+
case 'panel':
|
|
2743
|
+
case 'teleport':
|
|
2744
|
+
return 'div';
|
|
2745
|
+
case 'placeholder':
|
|
2746
|
+
return null;
|
|
2747
|
+
case 'text':
|
|
2748
|
+
return null;
|
|
2749
|
+
default:
|
|
2750
|
+
return treeP?.tagName || 'div';
|
|
2751
|
+
}
|
|
2752
|
+
};
|
|
2753
|
+
func.runtime.render.get_tree_terminal_content = function (treeP) {
|
|
2754
|
+
const attributes = treeP?.attributes || {};
|
|
2755
|
+
if (typeof attributes['xu-html'] !== 'undefined' && attributes['xu-html'] !== null) {
|
|
2756
|
+
return {
|
|
2757
|
+
value: `${attributes['xu-html']}`,
|
|
2758
|
+
mode: 'html',
|
|
2759
|
+
};
|
|
2760
|
+
}
|
|
2761
|
+
if (typeof attributes['xu-content'] !== 'undefined' && attributes['xu-content'] !== null) {
|
|
2762
|
+
return {
|
|
2763
|
+
value: `${attributes['xu-content']}`,
|
|
2764
|
+
mode: 'html',
|
|
2765
|
+
};
|
|
2766
|
+
}
|
|
2767
|
+
if (typeof attributes['xu-text'] !== 'undefined' && attributes['xu-text'] !== null) {
|
|
2768
|
+
return {
|
|
2769
|
+
value: `${attributes['xu-text']}`,
|
|
2770
|
+
mode: 'text',
|
|
2771
|
+
};
|
|
2772
|
+
}
|
|
2773
|
+
if (treeP?.kind === 'text') {
|
|
2774
|
+
return {
|
|
2775
|
+
value: typeof treeP?.text !== 'undefined' && treeP?.text !== null ? `${treeP.text}` : `${treeP?.content || ''}`,
|
|
2776
|
+
mode: 'text',
|
|
2777
|
+
};
|
|
2778
|
+
}
|
|
2779
|
+
return null;
|
|
2780
|
+
};
|
|
2781
|
+
func.runtime.render.render_tree_terminal_content = function (treeP) {
|
|
2782
|
+
const terminal = func.runtime.render.get_tree_terminal_content(treeP);
|
|
2783
|
+
if (!terminal) {
|
|
2784
|
+
return null;
|
|
2785
|
+
}
|
|
2786
|
+
if (terminal.mode === 'html') {
|
|
2787
|
+
return terminal.value;
|
|
2788
|
+
}
|
|
2789
|
+
return func.runtime.render.escape_html(terminal.value);
|
|
2790
|
+
};
|
|
2791
|
+
func.runtime.render.get_widget_fallback_markup = function (treeP) {
|
|
2792
|
+
const widget_meta = treeP?.meta?.widget || {};
|
|
2793
|
+
const capability_state = widget_meta?.capabilities?.headless ? 'headless-capable' : 'browser-only';
|
|
2794
|
+
return `<!--xuda-widget:${func.runtime.render.escape_html(widget_meta.plugin_name || 'unknown')}:${capability_state}-->`;
|
|
2795
|
+
};
|
|
2796
|
+
func.runtime.render.get_tree_string_attributes = function (treeP, renderer_context) {
|
|
2797
|
+
const attributes = func.runtime.render.safe_clone_tree_value(treeP?.attributes || {});
|
|
2798
|
+
const attr_pairs = [];
|
|
2799
|
+
const keys = Object.keys(attributes);
|
|
2800
|
+
|
|
2801
|
+
for (let index = 0; index < keys.length; index++) {
|
|
2802
|
+
const key = keys[index];
|
|
2803
|
+
if (func.runtime.render.is_tree_control_attribute(key)) {
|
|
2804
|
+
continue;
|
|
2805
|
+
}
|
|
2806
|
+
const value = attributes[key];
|
|
2807
|
+
if (value === false || value === null || typeof value === 'undefined') {
|
|
2808
|
+
continue;
|
|
2809
|
+
}
|
|
2810
|
+
if (value === true) {
|
|
2811
|
+
attr_pairs.push(key);
|
|
2812
|
+
continue;
|
|
2813
|
+
}
|
|
2814
|
+
const normalized_value = typeof value === 'object' ? JSON.stringify(value) : `${value}`;
|
|
2815
|
+
attr_pairs.push(`${key}="${func.runtime.render.escape_html_attribute(normalized_value)}"`);
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
attr_pairs.push(`data-xuda-kind="${func.runtime.render.escape_html_attribute(treeP?.kind || 'element')}"`);
|
|
2819
|
+
attr_pairs.push(`data-xuda-node-id="${func.runtime.render.escape_html_attribute(treeP?.id || treeP?.meta?.source_node_id || '')}"`);
|
|
2820
|
+
attr_pairs.push(`data-xuda-tree-id="${func.runtime.render.escape_html_attribute(treeP?.meta?.tree_id || '')}"`);
|
|
2821
|
+
|
|
2822
|
+
if (treeP?.kind === 'widget' && treeP?.meta?.widget) {
|
|
2823
|
+
attr_pairs.push(`data-xuda-widget="${func.runtime.render.escape_html_attribute(treeP.meta.widget.plugin_name || '')}"`);
|
|
2824
|
+
attr_pairs.push(`data-xuda-widget-method="${func.runtime.render.escape_html_attribute(treeP.meta.widget.method || '_default')}"`);
|
|
2825
|
+
attr_pairs.push(`data-xuda-widget-capability="${func.runtime.render.escape_html_attribute(treeP.meta.widget.capabilities?.headless ? 'headless' : 'browser')}"`);
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
if (treeP?.kind === 'teleport' && treeP?.attributes?.['xu-teleport']) {
|
|
2829
|
+
attr_pairs.push(`data-xuda-teleport-target="${func.runtime.render.escape_html_attribute(treeP.attributes['xu-teleport'])}"`);
|
|
2830
|
+
}
|
|
2831
|
+
|
|
2832
|
+
if ((treeP?.meta?.controls?.xu_for !== null && treeP?.meta?.controls?.xu_for !== undefined) && !renderer_context?.strip_iteration_markers) {
|
|
2833
|
+
attr_pairs.push('data-xuda-xu-for="pending"');
|
|
2834
|
+
}
|
|
2835
|
+
|
|
2836
|
+
return attr_pairs.length ? ' ' + attr_pairs.join(' ') : '';
|
|
2837
|
+
};
|
|
2838
|
+
func.runtime.render.render_tree_children_to_string = async function (treeP, renderer_context) {
|
|
2839
|
+
if (!Array.isArray(treeP?.children) || !treeP.children.length) {
|
|
2840
|
+
return '';
|
|
2841
|
+
}
|
|
2842
|
+
let html = '';
|
|
2843
|
+
for (let index = 0; index < treeP.children.length; index++) {
|
|
2844
|
+
html += await func.runtime.render.render_tree_to_string(treeP.children[index], {
|
|
2845
|
+
...renderer_context,
|
|
2846
|
+
parent_tree: treeP,
|
|
2847
|
+
});
|
|
2848
|
+
}
|
|
2849
|
+
return html;
|
|
2850
|
+
};
|
|
2851
|
+
func.runtime.render.render_tree_to_string = async function (treeP, renderer_context = {}) {
|
|
2852
|
+
if (!treeP) {
|
|
2853
|
+
return '';
|
|
2854
|
+
}
|
|
2855
|
+
if (Array.isArray(treeP)) {
|
|
2856
|
+
let html = '';
|
|
2857
|
+
for (let index = 0; index < treeP.length; index++) {
|
|
2858
|
+
html += await func.runtime.render.render_tree_to_string(treeP[index], renderer_context);
|
|
2859
|
+
}
|
|
2860
|
+
return html;
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
const ensured_tree = await func.runtime.render.ensure_tree_node({
|
|
2864
|
+
SESSION_ID: renderer_context?.SESSION_ID,
|
|
2865
|
+
nodeP: treeP,
|
|
2866
|
+
paramsP: renderer_context?.paramsP,
|
|
2867
|
+
parent_infoP: renderer_context?.parent_infoP,
|
|
2868
|
+
keyP: renderer_context?.keyP,
|
|
2869
|
+
parent_nodeP: renderer_context?.parent_nodeP,
|
|
2870
|
+
});
|
|
2871
|
+
|
|
2872
|
+
if (!ensured_tree || !func.runtime.render.should_render_tree_node(ensured_tree)) {
|
|
2873
|
+
return '';
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
if (ensured_tree.kind === 'placeholder') {
|
|
2877
|
+
if (renderer_context?.include_placeholders) {
|
|
2878
|
+
return `<!--xuda-placeholder:${func.runtime.render.escape_html(ensured_tree.id || '')}-->`;
|
|
2879
|
+
}
|
|
2880
|
+
return '';
|
|
2881
|
+
}
|
|
2882
|
+
|
|
2883
|
+
if (ensured_tree.kind === 'text') {
|
|
2884
|
+
return func.runtime.render.render_tree_terminal_content(ensured_tree) || '';
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2887
|
+
const tag_name = func.runtime.render.get_string_renderer_tag_name(ensured_tree);
|
|
2888
|
+
if (!tag_name || tag_name.toLowerCase() === 'script') {
|
|
2889
|
+
return '';
|
|
2890
|
+
}
|
|
2891
|
+
|
|
2892
|
+
const attributes = func.runtime.render.get_tree_string_attributes(ensured_tree, renderer_context);
|
|
2893
|
+
const terminal_content = func.runtime.render.render_tree_terminal_content(ensured_tree);
|
|
2894
|
+
let children_html = terminal_content !== null ? terminal_content : await func.runtime.render.render_tree_children_to_string(ensured_tree, renderer_context);
|
|
2895
|
+
|
|
2896
|
+
if (ensured_tree.kind === 'widget' && !children_html) {
|
|
2897
|
+
children_html = func.runtime.render.get_widget_fallback_markup(ensured_tree);
|
|
2898
|
+
}
|
|
2899
|
+
|
|
2900
|
+
if (func.runtime.render.is_html_void_tag(tag_name)) {
|
|
2901
|
+
return `<${tag_name}${attributes}>`;
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2904
|
+
return `<${tag_name}${attributes}>${children_html}</${tag_name}>`;
|
|
2905
|
+
};
|
|
2906
|
+
func.runtime.render.render_to_string = async function (options = {}) {
|
|
2907
|
+
const treeP = await func.runtime.render.ensure_tree_node({
|
|
2908
|
+
SESSION_ID: options.SESSION_ID,
|
|
2909
|
+
nodeP: options.treeP || options.nodeP,
|
|
2910
|
+
paramsP: options.paramsP,
|
|
2911
|
+
parent_infoP: options.parent_infoP,
|
|
2912
|
+
keyP: options.keyP,
|
|
2913
|
+
parent_nodeP: options.parent_nodeP,
|
|
2914
|
+
});
|
|
2915
|
+
|
|
2916
|
+
return await func.runtime.render.render_tree_to_string(treeP, options);
|
|
2917
|
+
};
|
|
2356
2918
|
glb.DEBUG_INFO_OBJ = {};
|
|
2357
2919
|
// var CONNECTION_ATTEMPTS = 0;
|
|
2358
2920
|
glb.APP_INFO = {};
|