@zvndev/yable-react 0.1.1 → 0.2.0

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/index.cjs CHANGED
@@ -69,6 +69,8 @@ function useTable(options) {
69
69
  prevOptionsRef.current = options;
70
70
  return options;
71
71
  }, [options]);
72
+ const onStateChangeRef = React3.useRef(options.onStateChange);
73
+ onStateChangeRef.current = options.onStateChange;
72
74
  const resolvedState = React3.useMemo(
73
75
  () => ({
74
76
  ...state,
@@ -78,13 +80,14 @@ function useTable(options) {
78
80
  );
79
81
  const onStateChange = React3.useCallback(
80
82
  (updater) => {
81
- if (stableOptions.onStateChange) {
82
- stableOptions.onStateChange(updater);
83
+ const latest = onStateChangeRef.current;
84
+ if (latest) {
85
+ latest(updater);
83
86
  } else {
84
87
  setState((prev) => yableCore.functionalUpdate(updater, prev));
85
88
  }
86
89
  },
87
- [stableOptions.onStateChange]
90
+ []
88
91
  );
89
92
  const resolvedOptions = React3.useMemo(
90
93
  () => ({
@@ -1720,19 +1723,20 @@ function Spinner() {
1720
1723
  function LoadingOverlay({
1721
1724
  loading,
1722
1725
  loadingComponent,
1723
- loadingText = "Loading..."
1726
+ loadingText
1724
1727
  }) {
1725
1728
  if (!loading) return null;
1729
+ const resolvedText = loadingText ?? yableCore.getDefaultLocale().loadingText;
1726
1730
  return /* @__PURE__ */ jsxRuntime.jsx(
1727
1731
  "div",
1728
1732
  {
1729
1733
  className: "yable-overlay-loading",
1730
1734
  role: "alert",
1731
1735
  "aria-busy": "true",
1732
- "aria-label": loadingText,
1736
+ "aria-label": resolvedText,
1733
1737
  children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "yable-overlay-loading-content", children: loadingComponent ?? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1734
1738
  /* @__PURE__ */ jsxRuntime.jsx(Spinner, {}),
1735
- loadingText && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "yable-overlay-loading-text", children: loadingText })
1739
+ resolvedText && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "yable-overlay-loading-text", children: resolvedText })
1736
1740
  ] }) })
1737
1741
  }
1738
1742
  );
@@ -1850,8 +1854,9 @@ function NoRowsOverlay({
1850
1854
  if (emptyComponent) {
1851
1855
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "yable-overlay-empty", children: emptyComponent });
1852
1856
  }
1853
- const defaultMessage = isFiltered ? "No results found" : "No data";
1854
- const defaultDetail = isFiltered ? "Try adjusting your search or filter criteria." : "There are no rows to display.";
1857
+ const locale = yableCore.getDefaultLocale();
1858
+ const defaultMessage = isFiltered ? locale.emptyNoResults : locale.emptyNoData;
1859
+ const defaultDetail = isFiltered ? locale.emptyNoResultsDetail : locale.emptyNoDataDetail;
1855
1860
  const icon = emptyIcon ?? (isFiltered ? /* @__PURE__ */ jsxRuntime.jsx(DefaultFilteredIcon, {}) : /* @__PURE__ */ jsxRuntime.jsx(DefaultEmptyIcon, {}));
1856
1861
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "yable-overlay-empty", role: "status", children: [
1857
1862
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "yable-overlay-empty-icon-wrapper", children: icon }),
@@ -2840,7 +2845,7 @@ function Table({
2840
2845
  loading,
2841
2846
  loadingComponent,
2842
2847
  loadingText,
2843
- emptyMessage = "No data",
2848
+ emptyMessage,
2844
2849
  emptyComponent,
2845
2850
  emptyIcon,
2846
2851
  emptyDetail,
@@ -2992,9 +2997,10 @@ function Pagination({
2992
2997
  const to = Math.min((pageIndex + 1) * pageSize, totalRows);
2993
2998
  const canPrev = table.getCanPreviousPage();
2994
2999
  const canNext = table.getCanNextPage();
3000
+ const locale = yableCore.getDefaultLocale();
2995
3001
  return /* @__PURE__ */ jsxRuntime.jsxs("nav", { className: "yable-pagination", role: "navigation", "aria-label": "Table pagination", children: [
2996
3002
  showInfo && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "yable-pagination-info", children: [
2997
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "yable-pagination-info-text", children: totalRows > 0 ? `${from}\u2013${to} of ${totalRows}` : "No results" }),
3003
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "yable-pagination-info-text", children: totalRows > 0 ? `${from}\u2013${to} ${locale.paginationOf} ${totalRows}` : locale.paginationNoResults }),
2998
3004
  showPageSize && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "yable-pagination-select-wrapper", children: [
2999
3005
  /* @__PURE__ */ jsxRuntime.jsx(
3000
3006
  "select",
@@ -3007,7 +3013,8 @@ function Pagination({
3007
3013
  "aria-label": "Rows per page",
3008
3014
  children: pageSizes.map((size) => /* @__PURE__ */ jsxRuntime.jsxs("option", { value: size, children: [
3009
3015
  size,
3010
- " rows"
3016
+ " ",
3017
+ locale.paginationRows
3011
3018
  ] }, size))
3012
3019
  }
3013
3020
  ),
@@ -3022,8 +3029,8 @@ function Pagination({
3022
3029
  className: "yable-pagination-btn yable-pagination-btn--nav",
3023
3030
  onClick: () => table.setPageIndex(0),
3024
3031
  disabled: !canPrev,
3025
- "aria-label": "First page",
3026
- title: "First page",
3032
+ "aria-label": locale.paginationFirstPage,
3033
+ title: locale.paginationFirstPage,
3027
3034
  children: /* @__PURE__ */ jsxRuntime.jsx(ChevronFirstIcon, {})
3028
3035
  }
3029
3036
  ),
@@ -3034,8 +3041,8 @@ function Pagination({
3034
3041
  className: "yable-pagination-btn yable-pagination-btn--nav",
3035
3042
  onClick: () => table.previousPage(),
3036
3043
  disabled: !canPrev,
3037
- "aria-label": "Previous page",
3038
- title: "Previous page",
3044
+ "aria-label": locale.paginationPreviousPage,
3045
+ title: locale.paginationPreviousPage,
3039
3046
  children: /* @__PURE__ */ jsxRuntime.jsx(ChevronLeftIcon, {})
3040
3047
  }
3041
3048
  ),
@@ -3059,7 +3066,7 @@ function Pagination({
3059
3066
  className: `yable-pagination-btn yable-pagination-btn--page${page === pageIndex ? " yable-pagination-btn--active" : ""}`,
3060
3067
  "data-active": page === pageIndex ? "true" : void 0,
3061
3068
  onClick: () => table.setPageIndex(page),
3062
- "aria-label": `Page ${page + 1}`,
3069
+ "aria-label": `${locale.paginationPage} ${page + 1}`,
3063
3070
  "aria-current": page === pageIndex ? "page" : void 0,
3064
3071
  children: page + 1
3065
3072
  },
@@ -3073,8 +3080,8 @@ function Pagination({
3073
3080
  className: "yable-pagination-btn yable-pagination-btn--nav",
3074
3081
  onClick: () => table.nextPage(),
3075
3082
  disabled: !canNext,
3076
- "aria-label": "Next page",
3077
- title: "Next page",
3083
+ "aria-label": locale.paginationNextPage,
3084
+ title: locale.paginationNextPage,
3078
3085
  children: /* @__PURE__ */ jsxRuntime.jsx(ChevronRightIcon, {})
3079
3086
  }
3080
3087
  ),
@@ -3085,8 +3092,8 @@ function Pagination({
3085
3092
  className: "yable-pagination-btn yable-pagination-btn--nav",
3086
3093
  onClick: () => table.setPageIndex(pageCount - 1),
3087
3094
  disabled: !canNext,
3088
- "aria-label": "Last page",
3089
- title: "Last page",
3095
+ "aria-label": locale.paginationLastPage,
3096
+ title: locale.paginationLastPage,
3090
3097
  children: /* @__PURE__ */ jsxRuntime.jsx(ChevronLastIcon, {})
3091
3098
  }
3092
3099
  )
@@ -3135,10 +3142,12 @@ function ClearIcon() {
3135
3142
  }
3136
3143
  function GlobalFilter({
3137
3144
  table,
3138
- placeholder = "Search...",
3145
+ placeholder,
3139
3146
  debounce = 300,
3140
3147
  className
3141
3148
  }) {
3149
+ const locale = yableCore.getDefaultLocale();
3150
+ const resolvedPlaceholder = placeholder ?? locale.searchPlaceholder;
3142
3151
  const [value, setValue] = React3.useState(
3143
3152
  table.getState().globalFilter ?? ""
3144
3153
  );
@@ -3195,8 +3204,8 @@ function GlobalFilter({
3195
3204
  value,
3196
3205
  onChange: handleChange,
3197
3206
  onKeyDown: handleKeyDown,
3198
- placeholder,
3199
- "aria-label": "Search table",
3207
+ placeholder: resolvedPlaceholder,
3208
+ "aria-label": locale.searchAriaLabel,
3200
3209
  role: "searchbox"
3201
3210
  }
3202
3211
  ),
@@ -3283,10 +3292,25 @@ function CellSelect({
3283
3292
  const isAlwaysEditable = cell.getIsAlwaysEditable();
3284
3293
  const pending = table.getPendingValue(row.id, column.id);
3285
3294
  const currentValue = pending !== void 0 ? pending : cell.getValue();
3295
+ const commitTimerRef = React3.useRef(null);
3296
+ React3.useEffect(() => {
3297
+ return () => {
3298
+ if (commitTimerRef.current !== null) {
3299
+ clearTimeout(commitTimerRef.current);
3300
+ commitTimerRef.current = null;
3301
+ }
3302
+ };
3303
+ }, []);
3286
3304
  const handleChange = (e) => {
3287
3305
  table.setPendingValue(row.id, column.id, e.target.value);
3288
3306
  if (isEditing && !isAlwaysEditable) {
3289
- setTimeout(() => table.commitEdit(), 0);
3307
+ if (commitTimerRef.current !== null) {
3308
+ clearTimeout(commitTimerRef.current);
3309
+ }
3310
+ commitTimerRef.current = setTimeout(() => {
3311
+ commitTimerRef.current = null;
3312
+ table.commitEdit();
3313
+ }, 0);
3290
3314
  }
3291
3315
  };
3292
3316
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -4839,6 +4863,22 @@ Object.defineProperty(exports, "CommitError", {
4839
4863
  enumerable: true,
4840
4864
  get: function () { return yableCore.CommitError; }
4841
4865
  });
4866
+ Object.defineProperty(exports, "FormulaEngine", {
4867
+ enumerable: true,
4868
+ get: function () { return yableCore.FormulaEngine; }
4869
+ });
4870
+ Object.defineProperty(exports, "FormulaError", {
4871
+ enumerable: true,
4872
+ get: function () { return yableCore.FormulaError; }
4873
+ });
4874
+ Object.defineProperty(exports, "PivotEngine", {
4875
+ enumerable: true,
4876
+ get: function () { return yableCore.PivotEngine; }
4877
+ });
4878
+ Object.defineProperty(exports, "UndoStack", {
4879
+ enumerable: true,
4880
+ get: function () { return yableCore.UndoStack; }
4881
+ });
4842
4882
  Object.defineProperty(exports, "aggregationFns", {
4843
4883
  enumerable: true,
4844
4884
  get: function () { return yableCore.aggregationFns; }
@@ -4851,6 +4891,10 @@ Object.defineProperty(exports, "createLocale", {
4851
4891
  enumerable: true,
4852
4892
  get: function () { return yableCore.createLocale; }
4853
4893
  });
4894
+ Object.defineProperty(exports, "createUndoRedoIntegration", {
4895
+ enumerable: true,
4896
+ get: function () { return yableCore.createUndoRedoIntegration; }
4897
+ });
4854
4898
  Object.defineProperty(exports, "en", {
4855
4899
  enumerable: true,
4856
4900
  get: function () { return yableCore.en; }
@@ -4859,14 +4903,30 @@ Object.defineProperty(exports, "filterFns", {
4859
4903
  enumerable: true,
4860
4904
  get: function () { return yableCore.filterFns; }
4861
4905
  });
4906
+ Object.defineProperty(exports, "formulaFunctions", {
4907
+ enumerable: true,
4908
+ get: function () { return yableCore.formulaFunctions; }
4909
+ });
4862
4910
  Object.defineProperty(exports, "functionalUpdate", {
4863
4911
  enumerable: true,
4864
4912
  get: function () { return yableCore.functionalUpdate; }
4865
4913
  });
4914
+ Object.defineProperty(exports, "generatePivotColumnDefs", {
4915
+ enumerable: true,
4916
+ get: function () { return yableCore.generatePivotColumnDefs; }
4917
+ });
4866
4918
  Object.defineProperty(exports, "getDefaultLocale", {
4867
4919
  enumerable: true,
4868
4920
  get: function () { return yableCore.getDefaultLocale; }
4869
4921
  });
4922
+ Object.defineProperty(exports, "getInitialPivotState", {
4923
+ enumerable: true,
4924
+ get: function () { return yableCore.getInitialPivotState; }
4925
+ });
4926
+ Object.defineProperty(exports, "getPivotRowModel", {
4927
+ enumerable: true,
4928
+ get: function () { return yableCore.getPivotRowModel; }
4929
+ });
4870
4930
  Object.defineProperty(exports, "resetLocale", {
4871
4931
  enumerable: true,
4872
4932
  get: function () { return yableCore.resetLocale; }