@xuda.io/xuda-worker-bundle 1.3.2622 → 1.3.2624

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 +390 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2259,6 +2259,395 @@ glb.run_xu_before = [
2259
2259
  glb.run_xu_after = ['xu-bind', 'xu-class', 'xu-script', 'xu-ui-plugin', 'xu-ref'];
2260
2260
  glb.attr_abbreviations_arr = ['xu-click', 'xu-dblclick', 'xu-contextmenu', 'xu-focus', 'xu-keyup', 'xu-change', 'xu-blur', 'xu-init'];
2261
2261
  glb.solid_attributes = ['disabled'];
2262
+ // ── Headless/SSR DOM adapter ──
2263
+ // Provides a no-op / in-memory implementation of func.runtime.ui
2264
+ // for environments without a DOM (Node.js, workers, SSR).
2265
+ // Elements are plain objects; metadata lives in _meta_store.
2266
+
2267
+ func.runtime = func.runtime || {};
2268
+ func.runtime.ui = func.runtime.ui || {};
2269
+ func.runtime.render = func.runtime.render || {};
2270
+ func.runtime.widgets = func.runtime.widgets || {};
2271
+ func.runtime.ui.ui_id_hash_cache = func.runtime.ui.ui_id_hash_cache || new Map();
2272
+ func.runtime.ui.node_snapshot_cache = func.runtime.ui.node_snapshot_cache || new WeakMap();
2273
+ func.runtime.ui.node_child_items_cache = func.runtime.ui.node_child_items_cache || new WeakMap();
2274
+ func.runtime.ui.node_children_by_id_cache = func.runtime.ui.node_children_by_id_cache || new WeakMap();
2275
+
2276
+ // ── Metadata store (shared with browser adapter) ──
2277
+ func.runtime.ui._meta_store = func.runtime.ui._meta_store || {};
2278
+ func.runtime.ui._element_id_to_xu_ui_id = func.runtime.ui._element_id_to_xu_ui_id || {};
2279
+
2280
+ func.runtime.ui.set_meta = function (xu_ui_id, key, value) {
2281
+ if (!xu_ui_id) return;
2282
+ if (!func.runtime.ui._meta_store[xu_ui_id]) {
2283
+ func.runtime.ui._meta_store[xu_ui_id] = {};
2284
+ }
2285
+ func.runtime.ui._meta_store[xu_ui_id][key] = value;
2286
+ };
2287
+ func.runtime.ui.get_meta = function (xu_ui_id, key) {
2288
+ const entry = func.runtime.ui._meta_store[xu_ui_id];
2289
+ if (!entry) return undefined;
2290
+ return key ? entry[key] : entry;
2291
+ };
2292
+ func.runtime.ui.delete_meta = function (xu_ui_id) {
2293
+ delete func.runtime.ui._meta_store[xu_ui_id];
2294
+ for (const id in func.runtime.ui._element_id_to_xu_ui_id) {
2295
+ if (func.runtime.ui._element_id_to_xu_ui_id[id] === xu_ui_id) {
2296
+ delete func.runtime.ui._element_id_to_xu_ui_id[id];
2297
+ }
2298
+ }
2299
+ };
2300
+ func.runtime.ui.register_element_id = function (element_id, xu_ui_id) {
2301
+ if (element_id && xu_ui_id) {
2302
+ func.runtime.ui._element_id_to_xu_ui_id[element_id] = xu_ui_id;
2303
+ }
2304
+ };
2305
+ func.runtime.ui.get_meta_by_element_id = function (element_id) {
2306
+ if (!element_id) return undefined;
2307
+ const clean_id = element_id.startsWith('#') ? element_id.substring(1) : element_id;
2308
+ const xu_ui_id = func.runtime.ui._element_id_to_xu_ui_id[clean_id];
2309
+ if (xu_ui_id) {
2310
+ return func.runtime.ui._meta_store[xu_ui_id];
2311
+ }
2312
+ return undefined;
2313
+ };
2314
+ func.runtime.ui.find_element_by_id = function () {
2315
+ return null;
2316
+ };
2317
+ func.runtime.ui.get_session_root = function () {
2318
+ return null;
2319
+ };
2320
+ func.runtime.ui.clear_screen_blockers = function () {
2321
+ // no-op in headless
2322
+ };
2323
+
2324
+ // ── Virtual element representation ──
2325
+ var _next_id = 1;
2326
+ function create_virtual_element(tag, attrs) {
2327
+ return {
2328
+ _v_id: _next_id++,
2329
+ tag: tag || 'div',
2330
+ attrs: attrs || {},
2331
+ children: [],
2332
+ parent: null,
2333
+ style: {},
2334
+ classList: [],
2335
+ textContent: '',
2336
+ innerHTML: '',
2337
+ hidden: false,
2338
+ _data: {},
2339
+ };
2340
+ }
2341
+
2342
+ // ── Core adapter methods ──
2343
+ func.runtime.ui.as_jquery = function (target) {
2344
+ if (!target) return { length: 0, data: function () { return {}; }, toArray: function () { return []; }, attr: function () { return undefined; } };
2345
+ if (target._v_id) return target;
2346
+ return target;
2347
+ };
2348
+ func.runtime.ui.get_first_node = function (target) {
2349
+ if (!target) return null;
2350
+ if (target._v_id) return target;
2351
+ if (Array.isArray(target)) return target[0] || null;
2352
+ return null;
2353
+ };
2354
+ func.runtime.ui.get_data = function (target) {
2355
+ if (!target) return {};
2356
+ if (target._v_id) {
2357
+ const xu_ui_id = target.attrs?.['xu-ui-id'];
2358
+ if (xu_ui_id) {
2359
+ const meta = func.runtime.ui._meta_store[xu_ui_id];
2360
+ if (meta) return meta;
2361
+ }
2362
+ return target._data;
2363
+ }
2364
+ return {};
2365
+ };
2366
+ func.runtime.ui.get_parent = function (target) {
2367
+ if (target?._v_id) return target.parent;
2368
+ return null;
2369
+ };
2370
+ func.runtime.ui.get_children = function (target) {
2371
+ if (target?._v_id) return target.children.slice();
2372
+ return [];
2373
+ };
2374
+ func.runtime.ui.find_by_selector = function () {
2375
+ return { length: 0, toArray: function () { return []; } };
2376
+ };
2377
+ func.runtime.ui.insert_before = function ($element) { return $element; };
2378
+ func.runtime.ui.insert_after = function ($element) { return $element; };
2379
+ func.runtime.ui.has_selector = function () { return false; };
2380
+ func.runtime.ui.append_html = function (target) { return target; };
2381
+ func.runtime.ui.set_style = function (target, prop, value) {
2382
+ if (target?._v_id) target.style[prop] = value;
2383
+ return target;
2384
+ };
2385
+ func.runtime.ui.get_attr = function (target, key) {
2386
+ if (target?._v_id) return target.attrs[key];
2387
+ return undefined;
2388
+ };
2389
+ func.runtime.ui.set_attr = function (target, key, value) {
2390
+ if (target?._v_id) target.attrs[key] = value;
2391
+ return target;
2392
+ };
2393
+ func.runtime.ui.set_data = function (target, key, value) {
2394
+ if (target?._v_id) {
2395
+ target._data[key] = value;
2396
+ const xu_ui_id = target.attrs?.['xu-ui-id'];
2397
+ if (xu_ui_id) {
2398
+ func.runtime.ui.set_meta(xu_ui_id, key, value);
2399
+ }
2400
+ }
2401
+ return target;
2402
+ };
2403
+ func.runtime.ui.clear_data = function (target) {
2404
+ if (target?._v_id) {
2405
+ target._data = {};
2406
+ const xu_ui_id = target.attrs?.['xu-ui-id'];
2407
+ if (xu_ui_id) func.runtime.ui.delete_meta(xu_ui_id);
2408
+ }
2409
+ return target;
2410
+ };
2411
+ func.runtime.ui.add_class = function (target, cls) {
2412
+ if (target?._v_id && cls && !target.classList.includes(cls)) target.classList.push(cls);
2413
+ return target;
2414
+ };
2415
+ func.runtime.ui.remove_class = function (target, cls) {
2416
+ if (target?._v_id) {
2417
+ const idx = target.classList.indexOf(cls);
2418
+ if (idx !== -1) target.classList.splice(idx, 1);
2419
+ }
2420
+ return target;
2421
+ };
2422
+ func.runtime.ui.set_html = function (target, value) {
2423
+ if (target?._v_id) target.innerHTML = value;
2424
+ return target;
2425
+ };
2426
+ func.runtime.ui.set_text = function (target, value) {
2427
+ if (target?._v_id) target.textContent = value;
2428
+ return target;
2429
+ };
2430
+ func.runtime.ui.show = function (target) {
2431
+ if (target?._v_id) target.hidden = false;
2432
+ return target;
2433
+ };
2434
+ func.runtime.ui.hide = function (target) {
2435
+ if (target?._v_id) target.hidden = true;
2436
+ return target;
2437
+ };
2438
+ func.runtime.ui.append = function ($target, $element) {
2439
+ if ($target?._v_id && $element?._v_id) {
2440
+ $target.children.push($element);
2441
+ $element.parent = $target;
2442
+ }
2443
+ return $element;
2444
+ };
2445
+ func.runtime.ui.append_to = function ($element, $target) {
2446
+ return func.runtime.ui.append($target, $element);
2447
+ };
2448
+ func.runtime.ui.empty = function (target) {
2449
+ if (target?._v_id) target.children = [];
2450
+ return target;
2451
+ };
2452
+ func.runtime.ui.remove = function (target) {
2453
+ if (target?._v_id) {
2454
+ const xu_ui_id = target.attrs?.['xu-ui-id'];
2455
+ if (xu_ui_id) func.runtime.ui.delete_meta(xu_ui_id);
2456
+ if (target.parent?._v_id) {
2457
+ const idx = target.parent.children.indexOf(target);
2458
+ if (idx !== -1) target.parent.children.splice(idx, 1);
2459
+ }
2460
+ }
2461
+ return true;
2462
+ };
2463
+ func.runtime.ui.set_display_contents = function ($element) {
2464
+ return func.runtime.ui.set_style($element, 'display', 'contents');
2465
+ };
2466
+ func.runtime.ui.create_xurender = function (xu_ui_id, $target, hidden) {
2467
+ const el = create_virtual_element('xurender', { 'xu-ui-id': xu_ui_id });
2468
+ if (hidden) el.hidden = true;
2469
+ return func.runtime.ui.append_to(el, $target);
2470
+ };
2471
+ func.runtime.ui.replace_with = function ($source, $target) {
2472
+ if ($source?._v_id && $source.parent?._v_id) {
2473
+ const idx = $source.parent.children.indexOf($source);
2474
+ if (idx !== -1 && $target?._v_id) {
2475
+ $source.parent.children[idx] = $target;
2476
+ $target.parent = $source.parent;
2477
+ }
2478
+ }
2479
+ return $target;
2480
+ };
2481
+ func.runtime.ui.remove_xu_ui = function (xu_ui_id) {
2482
+ func.runtime.ui.delete_meta(xu_ui_id);
2483
+ return true;
2484
+ };
2485
+ func.runtime.ui.build_debug_info = function (nodeP, $container, items) {
2486
+ const container_data = func.runtime.ui.get_data($container);
2487
+ return {
2488
+ id: nodeP.id,
2489
+ parent_id: container_data?.xuData?.ui_id,
2490
+ items: items,
2491
+ };
2492
+ };
2493
+ func.runtime.ui.get_node_snapshot = function (nodeP) {
2494
+ if (!nodeP) return nodeP;
2495
+ if (func.runtime.ui.node_snapshot_cache.has(nodeP)) {
2496
+ return func.runtime.ui.node_snapshot_cache.get(nodeP);
2497
+ }
2498
+ const snapshot = typeof _ !== 'undefined' ? _.cloneDeep(nodeP) : JSON.parse(JSON.stringify(nodeP));
2499
+ func.runtime.ui.node_snapshot_cache.set(nodeP, snapshot);
2500
+ return snapshot;
2501
+ };
2502
+ func.runtime.ui.get_node_child_items = function (nodeP) {
2503
+ if (!nodeP?.children?.length) return [];
2504
+ if (func.runtime.ui.node_child_items_cache.has(nodeP)) {
2505
+ return func.runtime.ui.node_child_items_cache.get(nodeP);
2506
+ }
2507
+ const items = nodeP.children.map(function (val) { return val.xu_tree_id || val.id; });
2508
+ func.runtime.ui.node_child_items_cache.set(nodeP, items);
2509
+ return items;
2510
+ };
2511
+ func.runtime.ui.get_node_children_by_id = function (nodeP) {
2512
+ if (!nodeP?.children?.length) return {};
2513
+ if (func.runtime.ui.node_children_by_id_cache.has(nodeP)) {
2514
+ return func.runtime.ui.node_children_by_id_cache.get(nodeP);
2515
+ }
2516
+ const children_by_id = {};
2517
+ for (let i = 0; i < nodeP.children.length; i++) {
2518
+ const child = nodeP.children[i];
2519
+ if (child?.id) children_by_id[child.id] = child;
2520
+ }
2521
+ func.runtime.ui.node_children_by_id_cache.set(nodeP, children_by_id);
2522
+ return children_by_id;
2523
+ };
2524
+ func.runtime.ui.build_container_xu_data = function (options) {
2525
+ const container_data = func.runtime.ui.get_data(options.$container);
2526
+ const containerXuData = container_data?.xuData;
2527
+ return {
2528
+ SESSION_ID: options.SESSION_ID,
2529
+ prog_id: options.paramsP.prog_id,
2530
+ nodeid: options.nodeP.id,
2531
+ ui_type: options.nodeP.tagName,
2532
+ recordid: options.currentRecordId,
2533
+ paramsP: options.paramsP,
2534
+ key: options.keyP,
2535
+ key_path: options.key_path,
2536
+ screenId: options.paramsP.screenId,
2537
+ parent_container: containerXuData?.ui_id,
2538
+ elem_key: options.elem_key,
2539
+ properties: options.prop,
2540
+ node: options.nodeP,
2541
+ node_org: func.runtime.ui.get_node_snapshot(options.nodeP),
2542
+ is_panelP: options.paramsP.is_panelP,
2543
+ ui_id: options.ui_id,
2544
+ elem_prop: options.elem_propP,
2545
+ debug_info: func.runtime.ui.build_debug_info(options.nodeP, options.$container, options.items),
2546
+ parent_node: options.parent_nodeP,
2547
+ currentRecordId: options.currentRecordId,
2548
+ $root_container: options.$root_container,
2549
+ parent_element_ui_id: containerXuData?.ui_id,
2550
+ is_placeholder: !!options.is_placeholder,
2551
+ };
2552
+ };
2553
+ func.runtime.ui.apply_container_meta = function ($div, options) {
2554
+ if ($div?._v_id) $div.attrs['xu-ui-id'] = options.ui_id;
2555
+ const xuData = func.runtime.ui.build_container_xu_data(options);
2556
+ if (options.parent_infoP?.iterate_info) {
2557
+ xuData.iterate_info = options.parent_infoP.iterate_info;
2558
+ }
2559
+ if ($div?._v_id) {
2560
+ $div._data.xuData = xuData;
2561
+ $div._data.xuAttributes = {};
2562
+ }
2563
+ func.runtime.ui.set_meta(options.ui_id, 'xuData', xuData);
2564
+ func.runtime.ui.set_meta(options.ui_id, 'xuAttributes', {});
2565
+ if (options.is_placeholder && $div?._v_id) $div.classList.push('display_none');
2566
+ if (options.classP && $div?._v_id) $div.classList.push(options.classP);
2567
+ return $div;
2568
+ };
2569
+ func.runtime.ui.get_append_target = function ($container, $appendToP) {
2570
+ return $appendToP || $container || null;
2571
+ };
2572
+ func.runtime.ui.create_element = function (tag_name) {
2573
+ return create_virtual_element(tag_name);
2574
+ };
2575
+ func.runtime.ui.create_svg_element = function () {
2576
+ return create_virtual_element('svg');
2577
+ };
2578
+ func.runtime.ui.create_container_element = function (div_typeP) {
2579
+ return create_virtual_element(div_typeP || 'div');
2580
+ };
2581
+ func.runtime.ui.build_xu_ui_id_seed = function (nodeP, dsSessionP, key_path, currentRecordId) {
2582
+ const nodeId = nodeP.xu_tree_id || nodeP.id;
2583
+ const elem_key = `${nodeId}-${key_path}-${currentRecordId}`;
2584
+ return `${nodeP.id}-${elem_key}-${dsSessionP?.toString() || ''}`;
2585
+ };
2586
+ func.runtime.ui.generate_xu_ui_id = async function (SESSION_ID, nodeP, $container, paramsP, keyP, precomputed) {
2587
+ precomputed = precomputed || {};
2588
+ const dsSessionP = paramsP.dsSessionP;
2589
+ const _ds = SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];
2590
+ const containerXuData = precomputed.container_xu_data || func.runtime.ui.get_data($container)?.xuData;
2591
+ const currentRecordId = typeof precomputed.currentRecordId !== 'undefined' ? precomputed.currentRecordId : containerXuData?.recordid || _ds?.currentRecordId || '';
2592
+ const key_path = precomputed.key_path || `${containerXuData?.key_path || '0'}-${keyP || '0'}`;
2593
+ const ui_id = func.runtime.ui.build_xu_ui_id_seed(nodeP, dsSessionP, key_path, currentRecordId);
2594
+
2595
+ if (func.runtime.ui.ui_id_hash_cache.has(ui_id)) {
2596
+ return func.runtime.ui.ui_id_hash_cache.get(ui_id);
2597
+ }
2598
+
2599
+ const hashed_ui_id = await func.common.fastHash(ui_id);
2600
+ func.runtime.ui.ui_id_hash_cache.set(ui_id, hashed_ui_id);
2601
+ return hashed_ui_id;
2602
+ };
2603
+ func.runtime.ui.create_container = async function (options) {
2604
+ const _paramsP = typeof klona !== 'undefined' ? klona.klona(options.paramsP) : JSON.parse(JSON.stringify(options.paramsP));
2605
+ const _ds = SESSION_OBJ[options.SESSION_ID].DS_GLB[_paramsP.dsSessionP];
2606
+ const $appendTo = func.runtime.ui.get_append_target(options.$container, options.$appendToP);
2607
+ if (!$appendTo) return null;
2608
+ const container_data = func.runtime.ui.get_data(options.$container);
2609
+ const container_xu_data = container_data?.xuData;
2610
+ const items = func.runtime.ui.get_node_child_items(options.nodeP);
2611
+ const currentRecordId = container_xu_data?.recordid || (_ds ? _ds.currentRecordId : '');
2612
+
2613
+ try {
2614
+ const key_path = `${container_xu_data?.key_path || '0'}-${options.keyP || '0'}`;
2615
+ const elem_key = `${options.nodeP.xu_tree_id || options.nodeP.id}-${key_path}-${currentRecordId}`;
2616
+ const $div = func.runtime.ui.create_container_element(options.div_typeP);
2617
+ const new_ui_id = await func.runtime.ui.generate_xu_ui_id(options.SESSION_ID, options.nodeP, options.$container, options.paramsP, options.keyP, {
2618
+ container_xu_data,
2619
+ currentRecordId,
2620
+ key_path,
2621
+ });
2622
+
2623
+ func.runtime.ui.apply_container_meta($div, {
2624
+ ui_id: new_ui_id,
2625
+ paramsP: _paramsP,
2626
+ nodeP: options.nodeP,
2627
+ currentRecordId,
2628
+ keyP: options.keyP,
2629
+ key_path,
2630
+ $container: options.$container,
2631
+ prop: options.prop,
2632
+ elem_key,
2633
+ elem_propP: options.elem_propP,
2634
+ items,
2635
+ parent_nodeP: options.parent_nodeP,
2636
+ $root_container: options.$root_container,
2637
+ parent_infoP: options.parent_infoP,
2638
+ is_placeholder: options.is_placeholder,
2639
+ classP: options.classP,
2640
+ SESSION_ID: options.SESSION_ID,
2641
+ });
2642
+
2643
+ func.runtime.ui.append_to($div, $appendTo);
2644
+ return $div;
2645
+ } catch (e) {
2646
+ console.error(e);
2647
+ }
2648
+
2649
+ return null;
2650
+ };
2262
2651
  func.datasource = {};
2263
2652
  func.datasource.create = async function (
2264
2653
  SESSION_ID,
@@ -7576,7 +7965,7 @@ func.events.execute = async function (
7576
7965
  var field_elm = elementP;
7577
7966
 
7578
7967
  var calling_field_id = field_elm;
7579
- if (field_elm && typeof field_elm === 'object') calling_field_id = field_elm.attr('xu-ui-id');
7968
+ if (field_elm && typeof field_elm === 'object') calling_field_id = func.runtime.ui.get_attr(field_elm, 'xu-ui-id');
7580
7969
 
7581
7970
  var log_nodeId;
7582
7971
  var log_prog_id;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-worker-bundle",
3
- "version": "1.3.2622",
3
+ "version": "1.3.2624",
4
4
  "description": "xuda framework",
5
5
  "main": "index.js",
6
6
  "scripts": {