@ostack.tech/ui 0.15.4 → 0.15.5

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/dist/ostack-ui.js CHANGED
@@ -401,6 +401,69 @@ function combineEventHandlers(handler1, handler2, { checkDefaultPrevented = fals
401
401
  return combinedHandler;
402
402
  }
403
403
  //#endregion
404
+ //#region src/providers/LocalizationProvider/LocalizationContext.ts
405
+ /** Localisation context. */
406
+ var LocalizationContext = createContext(null);
407
+ //#endregion
408
+ //#region src/utils/useSafeLayoutEffect.ts
409
+ /** `useLayoutEffect` hook which runs `useEffect` on the server. */
410
+ var useSafeLayoutEffect = typeof document !== "undefined" ? useLayoutEffect : useEffect;
411
+ //#endregion
412
+ //#region src/utils/useLatestRef.ts
413
+ /**
414
+ * Hook providing a reference which is continuously updated with the latest
415
+ * provided `value`.
416
+ *
417
+ * @param value Value to store in the reference.
418
+ * @returns Reference to the latest provided value.
419
+ */
420
+ function useLatestRef(value) {
421
+ const ref = useRef(value);
422
+ useSafeLayoutEffect(() => {
423
+ ref.current = value;
424
+ }, [value]);
425
+ return ref;
426
+ }
427
+ //#endregion
428
+ //#region src/utils/useControllableState.ts
429
+ /** Helper hook to handle controlled or uncontrolled values. */
430
+ function useControllableState(initialValue, controlledValue) {
431
+ const [uncontrolledValue, setUncontrolledValue] = useState(initialValue);
432
+ const latestRef = useLatestRef({ controlledValue });
433
+ const setValue = useCallback((nextValue) => {
434
+ const { controlledValue } = latestRef.current;
435
+ if (controlledValue === void 0) setUncontrolledValue(nextValue);
436
+ else if (typeof nextValue === "function") setUncontrolledValue(nextValue(controlledValue));
437
+ else setUncontrolledValue(controlledValue);
438
+ }, [latestRef]);
439
+ return useMemo(() => [controlledValue === void 0 ? uncontrolledValue : controlledValue, setValue], [
440
+ controlledValue,
441
+ setValue,
442
+ uncontrolledValue
443
+ ]);
444
+ }
445
+ //#endregion
446
+ //#region src/providers/LocalizationProvider/LocalizationProvider.tsx
447
+ /** Localisation provider. */
448
+ function LocalizationProvider({ defaultLocale, locale: controlledLocale, onLocaleChange, children }) {
449
+ const [locale, setLocale] = useControllableState(defaultLocale, controlledLocale);
450
+ return locale === void 0 ? children : /* @__PURE__ */ jsx(LocalizationContext.Provider, {
451
+ value: {
452
+ locale,
453
+ setLocale: combineEventHandlers(setLocale, onLocaleChange)
454
+ },
455
+ children
456
+ });
457
+ }
458
+ //#endregion
459
+ //#region src/providers/LocalizationProvider/useLocale.ts
460
+ /** Hook used to get and set the current locale. */
461
+ function useLocale() {
462
+ const localizationContext = useContext(LocalizationContext);
463
+ if (localizationContext === null) throw new Error("No locale has been provided. Please provide a `defaultLocale`/`locale`property to the `Root` or `LocalizationProvider` components.");
464
+ return useMemo(() => [localizationContext.locale, localizationContext.setLocale], [localizationContext.locale, localizationContext.setLocale]);
465
+ }
466
+ //#endregion
404
467
  //#region src/utils/promiseUtils.ts
405
468
  /**
406
469
  * Whether a given value is [promise-like]{@link PromiseLike}.
@@ -423,26 +486,6 @@ function useConstant(fn) {
423
486
  return useState(fn)[0];
424
487
  }
425
488
  //#endregion
426
- //#region src/utils/useSafeLayoutEffect.ts
427
- /** `useLayoutEffect` hook which runs `useEffect` on the server. */
428
- var useSafeLayoutEffect = typeof document !== "undefined" ? useLayoutEffect : useEffect;
429
- //#endregion
430
- //#region src/utils/useLatestRef.ts
431
- /**
432
- * Hook providing a reference which is continuously updated with the latest
433
- * provided `value`.
434
- *
435
- * @param value Value to store in the reference.
436
- * @returns Reference to the latest provided value.
437
- */
438
- function useLatestRef(value) {
439
- const ref = useRef(value);
440
- useSafeLayoutEffect(() => {
441
- ref.current = value;
442
- }, [value]);
443
- return ref;
444
- }
445
- //#endregion
446
489
  //#region src/utils/zustandUtils.ts
447
490
  /** Empty Zustand store. */
448
491
  var EMPTY_STORE = createStore(() => ({}));
@@ -502,19 +545,23 @@ function useStartPrintingTask({ enabled = true } = {}) {
502
545
  */
503
546
  function matchAgainstFilter(value, filter, locale) {
504
547
  if (value === "" || filter === "") return null;
505
- const normalizedField = value.toLocaleLowerCase(locale);
506
- const normalizedFilter = filter.toLocaleLowerCase(locale);
507
- const index = normalizedField.indexOf(normalizedFilter);
508
- return index === -1 ? null : {
509
- before: value.slice(0, index),
510
- matched: value.slice(index, index + filter.length),
511
- after: value.slice(index + filter.length)
548
+ const sanitize = (value) => value.normalize("NFD").replace(/\p{M}/gu, "").toLocaleLowerCase(locale);
549
+ const nfcValue = value.normalize("NFC");
550
+ const sanitizedValue = sanitize(nfcValue);
551
+ const sanitizedFilter = sanitize(filter);
552
+ const startIndex = sanitizedValue.indexOf(sanitizedFilter);
553
+ if (startIndex === -1) return null;
554
+ const endIndex = startIndex + sanitizedFilter.length;
555
+ return {
556
+ before: nfcValue.slice(0, startIndex),
557
+ matched: nfcValue.slice(startIndex, endIndex),
558
+ after: nfcValue.slice(endIndex)
512
559
  };
513
560
  }
514
561
  //#endregion
515
562
  //#region src/utils/sorting.ts
516
563
  /** Stable sort implementation. */
517
- function stableSort(array, comparator = compare, sortDirection = "asc") {
564
+ function stableSort(array, comparator, sortDirection = "asc") {
518
565
  const orderSign = sortDirection === "asc" ? 1 : -1;
519
566
  const arrayWithIndex = array.map((el, idx) => [el, idx]);
520
567
  arrayWithIndex.sort((a, b) => (comparator(a[0], b[0], a[1], b[1]) || a[1] - b[1]) * orderSign);
@@ -524,7 +571,7 @@ function stableSort(array, comparator = compare, sortDirection = "asc") {
524
571
  * Comparison function allowing comparison of values of multiple types,
525
572
  * including all primitive types, as well as dates.
526
573
  */
527
- function compare(v1, v2) {
574
+ function compare(v1, v2, locale, options) {
528
575
  const t1 = customTypeOf(v1);
529
576
  const t2 = customTypeOf(v2);
530
577
  if (t1 !== t2) return customTypes.indexOf(t1) - customTypes.indexOf(t2);
@@ -542,7 +589,7 @@ function compare(v1, v2) {
542
589
  if (v1IsInvalid || v2IsInvalid) return +v2IsInvalid - +v1IsInvalid;
543
590
  return +v1 - +v2;
544
591
  }
545
- return String(v1).localeCompare(String(v2));
592
+ return String(v1).localeCompare(String(v2), locale, options);
546
593
  }
547
594
  var customTypes = [
548
595
  "null",
@@ -562,7 +609,7 @@ function customTypeOf(value) {
562
609
  }
563
610
  //#endregion
564
611
  //#region src/components/DataTable/processRows.ts
565
- function filterRows(leafColumns, rows, filter) {
612
+ function filterRows(leafColumns, rows, filter, locale) {
566
613
  if (!rows || filter === "") return rows;
567
614
  return rows.filter((row, index) => Object.entries(leafColumns).some(([columnId, column]) => {
568
615
  if (!column.filterable) return false;
@@ -570,26 +617,32 @@ function filterRows(leafColumns, rows, filter) {
570
617
  row,
571
618
  index
572
619
  }) : row[columnId];
573
- return matchAgainstFilter(column.format ? column.format({
620
+ const formattedValue = column.format ? column.format({
574
621
  value,
575
622
  row,
576
623
  index
577
- }) : value?.toString() ?? "", filter, column.locale ?? "pt-PT") != null;
624
+ }) : value?.toString() ?? "";
625
+ return (column.match ? column.match(formattedValue, filter) : matchAgainstFilter(formattedValue, filter, column.locale ?? locale)) != null;
578
626
  }));
579
627
  }
580
- function sortRows(leafColumns, rows, sortBy, sortDirection) {
628
+ function sortRows(leafColumns, rows, sortBy, sortDirection, locale) {
581
629
  if (!rows) return rows;
582
630
  if (sortBy === null) return sortDirection === "asc" ? rows : rows.slice().reverse();
583
631
  const column = leafColumns[sortBy];
584
632
  const getValue = column.getValue ?? (({ row }) => row[sortBy]);
585
- const compareFn = column.compare ?? compare;
586
- return stableSort(rows, (r1, r2, i1, i2) => compareFn(getValue({
633
+ return stableSort(rows, column.compare ? (r1, r2, i1, i2) => column.compare(getValue({
634
+ row: r1,
635
+ index: i1
636
+ }), getValue({
637
+ row: r2,
638
+ index: i2
639
+ })) : (r1, r2, i1, i2) => compare(getValue({
587
640
  row: r1,
588
641
  index: i1
589
642
  }), getValue({
590
643
  row: r2,
591
644
  index: i2
592
- })), sortDirection ?? column.defaultSortDirection ?? "asc");
645
+ }), locale, column.sortOptions), sortDirection ?? column.defaultSortDirection ?? "asc");
593
646
  }
594
647
  //#endregion
595
648
  //#region src/components/DataTable/spliceWindow.ts
@@ -646,6 +699,7 @@ function spliceWindow(totalCount, offset, limit, window, startIndex, deleted = 0
646
699
  var DataTableContext = createContext(null);
647
700
  /** Hook which creates the data table context value. */
648
701
  function useCreateDataTableContext({ displayMode, columns, rows, onVisibleRowsChange, onProcessedRowsChange, getRows, rowKey, loadingCount, required, loading, renderRow, renderCell, dynamicRowHeight, estimatedRowHeight, overscan, showAllRowsWhilePrinting, apiRef, leafColumns, headCount, defaultOffset, offset, onOffsetChange, defaultLimit, limit, onLimitChange, defaultFilter, filter, onFilterChange, defaultSortBy, sortBy, defaultSortDirection, sortDirection, onSort, showSelectionColumn, selectionMode, defaultSelectedRows, selectedRows, onSelectedRowsChange, selectAllChecked, onSelectAll, disabledSelections, selectAllRowsLabel, selectRowLabel }) {
702
+ const [locale] = useLocale();
649
703
  const { startPrintingTask, finishPrintingTask } = usePrinterContentContext();
650
704
  const latestRef = useLatestRef({
651
705
  startPrintingTask,
@@ -699,14 +753,16 @@ function useCreateDataTableContext({ displayMode, columns, rows, onVisibleRowsCh
699
753
  _filteredRows: computed(() => [
700
754
  get().leafColumns,
701
755
  get()._rows,
702
- get().filter
703
- ], (leafColumns, rows, filter) => filterRows(leafColumns, rows, filter)),
756
+ get().filter,
757
+ get().locale
758
+ ], (leafColumns, rows, filter, locale) => filterRows(leafColumns, rows, filter, locale)),
704
759
  processedRows: computed(() => [
705
760
  get().leafColumns,
706
761
  get()._filteredRows(),
707
762
  get().sortBy,
708
- get().sortDirection
709
- ], (leafColumns, filteredRows, sortBy, sortDirection) => sortRows(leafColumns, filteredRows, sortBy, sortDirection)),
763
+ get().sortDirection,
764
+ get().locale
765
+ ], (leafColumns, filteredRows, sortBy, sortDirection, locale) => sortRows(leafColumns, filteredRows, sortBy, sortDirection, locale)),
710
766
  getRows,
711
767
  loading,
712
768
  loadingCount,
@@ -743,6 +799,7 @@ function useCreateDataTableContext({ displayMode, columns, rows, onVisibleRowsCh
743
799
  scrolledRangeEnd: 1,
744
800
  tableHeadHeight: void 0,
745
801
  tableFootHeight: void 0,
802
+ locale: locale.languageTag,
746
803
  actions: {
747
804
  getRowsWindow: (offset, limit) => {
748
805
  return get()._rows ? get().processedRows().slice(offset, offset + limit) : Array.from({ length: limit }, (_, i) => get().cachedRows?.[offset + i]);
@@ -950,7 +1007,8 @@ function useCreateDataTableContext({ displayMode, columns, rows, onVisibleRowsCh
950
1007
  headCount,
951
1008
  selectionMode,
952
1009
  ...selectedRows === void 0 ? {} : { selectedRows: [new Set(selectedRows)] },
953
- disabledSelections: disabledSelections && new Set(disabledSelections)
1010
+ disabledSelections: disabledSelections && new Set(disabledSelections),
1011
+ locale: locale.languageTag
954
1012
  });
955
1013
  }, [
956
1014
  columns,
@@ -964,7 +1022,8 @@ function useCreateDataTableContext({ displayMode, columns, rows, onVisibleRowsCh
964
1022
  rows,
965
1023
  selectedRows,
966
1024
  store,
967
- selectionMode
1025
+ selectionMode,
1026
+ locale.languageTag
968
1027
  ]);
969
1028
  useEffect(() => {
970
1029
  if (store.getState()._rows) {
@@ -1676,49 +1735,6 @@ function unsetRef(ref, cleanupsRef) {
1676
1735
  } else ref.current = null;
1677
1736
  }
1678
1737
  //#endregion
1679
- //#region src/providers/LocalizationProvider/LocalizationContext.ts
1680
- /** Localisation context. */
1681
- var LocalizationContext = createContext(null);
1682
- //#endregion
1683
- //#region src/utils/useControllableState.ts
1684
- /** Helper hook to handle controlled or uncontrolled values. */
1685
- function useControllableState(initialValue, controlledValue) {
1686
- const [uncontrolledValue, setUncontrolledValue] = useState(initialValue);
1687
- const latestRef = useLatestRef({ controlledValue });
1688
- const setValue = useCallback((nextValue) => {
1689
- const { controlledValue } = latestRef.current;
1690
- if (controlledValue === void 0) setUncontrolledValue(nextValue);
1691
- else if (typeof nextValue === "function") setUncontrolledValue(nextValue(controlledValue));
1692
- else setUncontrolledValue(controlledValue);
1693
- }, [latestRef]);
1694
- return useMemo(() => [controlledValue === void 0 ? uncontrolledValue : controlledValue, setValue], [
1695
- controlledValue,
1696
- setValue,
1697
- uncontrolledValue
1698
- ]);
1699
- }
1700
- //#endregion
1701
- //#region src/providers/LocalizationProvider/LocalizationProvider.tsx
1702
- /** Localisation provider. */
1703
- function LocalizationProvider({ defaultLocale, locale: controlledLocale, onLocaleChange, children }) {
1704
- const [locale, setLocale] = useControllableState(defaultLocale, controlledLocale);
1705
- return locale === void 0 ? children : /* @__PURE__ */ jsx(LocalizationContext.Provider, {
1706
- value: {
1707
- locale,
1708
- setLocale: combineEventHandlers(setLocale, onLocaleChange)
1709
- },
1710
- children
1711
- });
1712
- }
1713
- //#endregion
1714
- //#region src/providers/LocalizationProvider/useLocale.ts
1715
- /** Hook used to get and set the current locale. */
1716
- function useLocale() {
1717
- const localizationContext = useContext(LocalizationContext);
1718
- if (localizationContext === null) throw new Error("No locale has been provided. Please provide a `defaultLocale`/`locale`property to the `Root` or `LocalizationProvider` components.");
1719
- return useMemo(() => [localizationContext.locale, localizationContext.setLocale], [localizationContext.locale, localizationContext.setLocale]);
1720
- }
1721
- //#endregion
1722
1738
  //#region src/utils/boolDataAttr.ts
1723
1739
  /** Value for a data attribute given a condition. */
1724
1740
  function boolDataAttr(condition) {
@@ -5865,6 +5881,7 @@ function useDataTableSelectionColumnId() {
5865
5881
  //#region src/components/DataTable/DataTableRow.tsx
5866
5882
  /** Data table row. */
5867
5883
  var DataTableRow = memo(forwardRef(function DataTableRow({ row, index, className, ...otherProps }, forwardedRef) {
5884
+ const [locale] = useLocale();
5868
5885
  const prefix = usePrefix();
5869
5886
  const { rowKey, renderCell, generatedId, estimatedRowHeight, store } = useDataTableContext();
5870
5887
  const selectionColumn = useDataTableSelectionColumn();
@@ -5883,7 +5900,7 @@ var DataTableRow = memo(forwardRef(function DataTableRow({ row, index, className
5883
5900
  "aria-rowindex": headCount + index + 1,
5884
5901
  ref: forwardedRef,
5885
5902
  ...otherProps,
5886
- children: Object.entries(leafColumns).map(([columnName, { filterable, locale, subColumns: _subColumns, getValue, format, render, compare: _compare, footer: _footer, label, labelText: _labelText, helperText: _helperText, helperButtonLabel: _helperButtonLabel, width: _width, fixed: _fixed, sortable: _sortable, defaultSortDirection: _defaultSortDirection, containerProps: _containerProps, labelProps, footerProps: _footerProps, sortButtonProps: _sortButtonProps, sortIconContainerProps: _sortIconContainerProps, sortAscIconProps: _sortAscIconProps, sortDescIconProps: _sortDescIconProps, helperButtonProps: _helperButtonProps, helperPopoverProps: _helperPopoverProps, helperPopoverContentProps: _helperPopoverContentProps, ...otherProps }], i) => {
5903
+ children: Object.entries(leafColumns).map(([columnName, { filterable, locale: columnLocale, subColumns: _subColumns, getValue, format, render, compare: _compare, match, footer: _footer, label, labelText: _labelText, helperText: _helperText, helperButtonLabel: _helperButtonLabel, width: _width, fixed: _fixed, sortable: _sortable, defaultSortDirection: _defaultSortDirection, containerProps: _containerProps, labelProps, footerProps: _footerProps, sortButtonProps: _sortButtonProps, sortIconContainerProps: _sortIconContainerProps, sortAscIconProps: _sortAscIconProps, sortDescIconProps: _sortDescIconProps, helperButtonProps: _helperButtonProps, helperPopoverProps: _helperPopoverProps, helperPopoverContentProps: _helperPopoverContentProps, ...otherProps }], i) => {
5887
5904
  const loadingRow = row === void 0;
5888
5905
  const value = !loadingRow && (getValue ? getValue({
5889
5906
  row,
@@ -5894,11 +5911,11 @@ var DataTableRow = memo(forwardRef(function DataTableRow({ row, index, className
5894
5911
  row,
5895
5912
  index
5896
5913
  }) : value?.toString() ?? "");
5897
- const match = !loadingRow && filterable ? matchAgainstFilter(formattedValue, filter, locale ?? "pt-PT") : null;
5898
- const markedValue = match == null ? formattedValue : /* @__PURE__ */ jsxs(Fragment$1, { children: [
5899
- match.before,
5900
- /* @__PURE__ */ jsx(Mark, { children: match.matched }),
5901
- match.after
5914
+ const matchObj = !loadingRow && filterable ? match ? match(formattedValue, filter) : matchAgainstFilter(formattedValue, filter, columnLocale ?? locale.languageTag) : null;
5915
+ const markedValue = matchObj == null ? formattedValue : /* @__PURE__ */ jsxs(Fragment$1, { children: [
5916
+ matchObj.before,
5917
+ /* @__PURE__ */ jsx(Mark, { children: matchObj.matched }),
5918
+ matchObj.after
5902
5919
  ] });
5903
5920
  const props = {
5904
5921
  "data-loading": boolDataAttr(loadingRow),
@@ -5911,7 +5928,7 @@ var DataTableRow = memo(forwardRef(function DataTableRow({ row, index, className
5911
5928
  columnLabelId: label ? labelProps?.id ?? `data-table-column-label-${columnName}-${generatedId}` : void 0,
5912
5929
  children: loadingRow ? /* @__PURE__ */ jsx(Spinner, { className: cx(prefix("data-table__cell-spinner")) }) : render ? render({
5913
5930
  formattedValue,
5914
- match,
5931
+ match: matchObj,
5915
5932
  markedValue,
5916
5933
  value,
5917
5934
  row,