@fuentis/phoenix-ui 0.0.9-alpha.566 → 0.0.9-alpha.567

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.
@@ -3336,13 +3336,116 @@ class TableComponent {
3336
3336
  skeletonRowCount = 8;
3337
3337
  /** Array used by Angular @for (must be iterable) */
3338
3338
  skeletonRows = Array.from({ length: this.skeletonRowCount });
3339
+ createSortWorkerInline() {
3340
+ const code = `
3341
+ const compareStringsNatural = (a,b) => a.localeCompare(b, undefined, { numeric:true, sensitivity:'base' });
3342
+
3343
+ const getNestedValue = (obj, path) => {
3344
+ try {
3345
+ if (!obj || !path) return undefined;
3346
+ if (Object.prototype.hasOwnProperty.call(obj, path)) {
3347
+ const v = obj[path];
3348
+ return (v && v.key !== undefined) ? v.key : v;
3349
+ }
3350
+ return path.split('.').reduce((acc, k) => (acc == null ? undefined : acc[k]), obj);
3351
+ } catch { return undefined; }
3352
+ };
3353
+
3354
+ const getComparableValue = (val, field, columnTypeMap, dateTypeKey='DATE') => {
3355
+ if (val === null || val === undefined) return '';
3356
+ const columnType = columnTypeMap?.[field];
3357
+
3358
+ if ((columnType || '').toString().toUpperCase() === 'BOOLEAN') {
3359
+ if (typeof val === 'boolean') return val ? 1 : 0;
3360
+ if (typeof val === 'number') return val ? 1 : 0;
3361
+ if (typeof val === 'string') {
3362
+ const s = val.trim().toLowerCase();
3363
+ if (['true','1','yes'].includes(s)) return 1;
3364
+ if (['false','0','no'].includes(s)) return 0;
3365
+ return '';
3366
+ }
3367
+ if (typeof val === 'object') {
3368
+ const v = val.value ?? val.key ?? val.enabled ?? val.checked;
3369
+ return getComparableValue(v, field, columnTypeMap, dateTypeKey);
3370
+ }
3371
+ return '';
3372
+ }
3373
+
3374
+ if (typeof val === 'number') return val;
3375
+
3376
+ if (typeof val === 'string') {
3377
+ if (columnType === dateTypeKey) {
3378
+ const t = Date.parse(val);
3379
+ return Number.isNaN(t) ? val.toLowerCase() : t;
3380
+ }
3381
+ return val.toLowerCase();
3382
+ }
3383
+
3384
+ if (val instanceof Date) return val.getTime();
3385
+
3386
+ if (typeof val === 'object') {
3387
+ if (val.from && val.to) {
3388
+ const from = Date.parse(val.from);
3389
+ const to = Date.parse(val.to);
3390
+ return (Number.isNaN(from) || Number.isNaN(to)) ? '' : (from + to);
3391
+ }
3392
+ if (Array.isArray(val) && val.length) return getComparableValue(val[0], field, columnTypeMap, dateTypeKey);
3393
+
3394
+ for (const k of ['name','value','label','key','date']) {
3395
+ if (val[k] !== undefined && val[k] !== null) return getComparableValue(val[k], field, columnTypeMap, dateTypeKey);
3396
+ }
3397
+ for (const v of Object.values(val)) {
3398
+ if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean') {
3399
+ return getComparableValue(v, field, columnTypeMap, dateTypeKey);
3400
+ }
3401
+ }
3402
+ }
3403
+ return '';
3404
+ };
3405
+
3406
+ const sortData = (data, meta, columnTypeMap, dateTypeKey='DATE') => {
3407
+ const sorted = (data || []).slice();
3408
+ if (!meta?.length) return sorted;
3409
+
3410
+ sorted.sort((a,b) => {
3411
+ for (const s of meta) {
3412
+ const field = s.field;
3413
+ const order = s.order ?? 1;
3414
+
3415
+ const A = getComparableValue(getNestedValue(a, field), field, columnTypeMap, dateTypeKey);
3416
+ const B = getComparableValue(getNestedValue(b, field), field, columnTypeMap, dateTypeKey);
3417
+
3418
+ if (typeof A === 'string' && typeof B === 'string') {
3419
+ const c = compareStringsNatural(A,B);
3420
+ if (c !== 0) return c * order;
3421
+ } else {
3422
+ if (A < B) return -1 * order;
3423
+ if (A > B) return 1 * order;
3424
+ }
3425
+ }
3426
+ return 0;
3427
+ });
3428
+
3429
+ return sorted;
3430
+ };
3431
+
3432
+ self.addEventListener('message', (ev) => {
3433
+ const data = ev.data || {};
3434
+ const sorted = sortData(data.data, data.multiSortMeta, data.columnTypeMap, data.dateTypeKey || 'DATE');
3435
+ self.postMessage({ reqId: data.reqId, sorted });
3436
+ });
3437
+ `;
3438
+ const blob = new Blob([code], { type: 'text/javascript' });
3439
+ const url = URL.createObjectURL(blob);
3440
+ return new Worker(url); // classic worker, nema module MIME problema
3441
+ }
3339
3442
  constructor() {
3340
3443
  /**
3341
3444
  * Create sorting worker if supported.
3342
3445
  * Fallback is synchronous sort (still works, but can freeze on huge arrays).
3343
3446
  */
3344
3447
  if (typeof Worker !== 'undefined') {
3345
- this.sortWorker = new Worker(new URL('./table-sort.worker', import.meta.url), { type: 'module' });
3448
+ this.sortWorker = this.createSortWorkerInline();
3346
3449
  this.sortWorker.onmessage = (e) => {
3347
3450
  const { reqId, sorted } = e.data ?? {};
3348
3451
  if (reqId !== this.latestWorkerReqId)