next-recomponents 2.0.42 → 2.0.44

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.js CHANGED
@@ -37185,13 +37185,16 @@ function usePopup() {
37185
37185
  );
37186
37186
  const close = (0, import_react10.useCallback)(
37187
37187
  async (confirmed, value) => {
37188
- var _a, _b;
37188
+ var _a, _b, _c;
37189
37189
  const prev = { ...popup };
37190
37190
  let visible = false;
37191
37191
  if (confirmed) {
37192
37192
  (_a = prev.onConfirm) == null ? void 0 : _a.call(prev, value);
37193
- } else if (prev == null ? void 0 : prev.onCancel) {
37194
- visible = !Boolean(await ((_b = prev.onCancel) == null ? void 0 : _b.call(prev)));
37193
+ } else if (prev == null ? void 0 : prev.onClose) {
37194
+ visible = !Boolean(await ((_b = prev.onClose) == null ? void 0 : _b.call(prev)));
37195
+ } else {
37196
+ (_c = prev.onCancel) == null ? void 0 : _c.call(prev);
37197
+ visible = false;
37195
37198
  }
37196
37199
  const data = { ...prev, visible, inputValue: "" };
37197
37200
  setPopup(data);
@@ -37216,12 +37219,11 @@ function usePopup() {
37216
37219
  type: "modal",
37217
37220
  message,
37218
37221
  color,
37219
- // onConfirm: () => {
37220
- // resolve();
37221
- // },
37222
- onCancel: async () => {
37222
+ onConfirm: () => resolve(),
37223
+ onCancel: () => resolve(),
37224
+ onClose: onClose ? async () => {
37223
37225
  return await (onClose == null ? void 0 : onClose());
37224
- },
37226
+ } : void 0,
37225
37227
  icons,
37226
37228
  full
37227
37229
  })
@@ -39019,6 +39021,30 @@ var regularExpresions2 = {
39019
39021
  };
39020
39022
  var types_default = regularExpresions2;
39021
39023
 
39024
+ // src/table-advanced/formatter.ts
39025
+ function valueFormatter({
39026
+ value,
39027
+ currentCoin = ""
39028
+ }) {
39029
+ if (value == null || value === "") return "";
39030
+ const isDate = /(\d{4}-\d{2}-\d{2})(T[\d:,.+-]*(Z)?)?/;
39031
+ if (`${value}`.match(isDate)) {
39032
+ return value.toString().split("T")[0].split("-").reverse().join("/");
39033
+ }
39034
+ const splited = `${value}`.split(".");
39035
+ const hasDecimals = splited.length == 2 && splited.every((v) => `${v}`.match(types_default.number));
39036
+ if (hasDecimals) {
39037
+ return [
39038
+ currentCoin,
39039
+ (+`${value}`).toLocaleString("en-US", {
39040
+ minimumFractionDigits: 2,
39041
+ maximumFractionDigits: 2
39042
+ })
39043
+ ].join(" ");
39044
+ }
39045
+ return value;
39046
+ }
39047
+
39022
39048
  // src/table-advanced/h.table.tsx
39023
39049
  var import_jsx_runtime36 = require("react/jsx-runtime");
39024
39050
  function HTable({
@@ -39067,7 +39093,10 @@ function HTable({
39067
39093
  );
39068
39094
  const gridTemplateColumns2 = headers2.filter((h) => {
39069
39095
  var _a, _b;
39070
- return !((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, h));
39096
+ if (["__modal__", "__select__"].includes(h)) {
39097
+ return true;
39098
+ }
39099
+ return !((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, h)) && !h.startsWith("_");
39071
39100
  }).map((h) => {
39072
39101
  var _a;
39073
39102
  return `${(_a = widths2[h]) != null ? _a : defaultWidth}px`;
@@ -39078,28 +39107,27 @@ function HTable({
39078
39107
  (0, import_react19.useEffect)(() => {
39079
39108
  if (!tableRef.current) return;
39080
39109
  const observer = new ResizeObserver(([entry]) => {
39081
- const sizeados = headers.filter(
39082
- (h) => [
39083
- "__select__",
39084
- "__modal__"
39085
- // ...(context?.hideColumns || []),
39086
- // ...(context?.colSize ? Object.keys(context.colSize) : []),
39087
- ].includes(h)
39110
+ const ocultos = headers.filter(
39111
+ (h) => {
39112
+ var _a, _b;
39113
+ return !h.startsWith("__") && (h.startsWith("_") || ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, h)));
39114
+ }
39088
39115
  );
39116
+ const sizeados = headers.filter((h) => h.startsWith("__"));
39089
39117
  const personalizados = (context == null ? void 0 : context.colSize) ? Object.values(context.colSize) : [];
39090
39118
  const personalizadosSum = personalizados.length > 0 ? personalizados.reduce((acc, i) => acc + i, 0) : 0;
39091
39119
  const ancho = +entry.contentRect.width;
39092
39120
  const sizeadosLength = sizeados.length;
39093
39121
  const sizeadosWidth = sizeadosLength * 60;
39094
- const w = (ancho - sizeadosWidth - personalizadosSum) / (headers.length - sizeadosLength - personalizados.length);
39122
+ const w = (ancho - sizeadosWidth - personalizadosSum) / (headers.length - sizeadosLength - personalizados.length - ocultos.length);
39095
39123
  console.log({
39096
39124
  w,
39097
39125
  ancho,
39098
39126
  sizeadosWidth,
39099
- sizeadosLength,
39100
39127
  personalizadosSum,
39101
- headers: headers.length,
39102
- personalizados: personalizados.length
39128
+ headers,
39129
+ sizeadosLength,
39130
+ personalizados
39103
39131
  });
39104
39132
  setWidths(
39105
39133
  Object.fromEntries(
@@ -39137,8 +39165,13 @@ function HTable({
39137
39165
  onClick: (e) => {
39138
39166
  context.excel.export(
39139
39167
  context.data.map((d) => {
39140
- const { __select__, __modal__, ...datums } = d;
39141
- return datums;
39168
+ const obj = {};
39169
+ for (let key in d) {
39170
+ if (!key.startsWith("_")) {
39171
+ obj[key] = d[key];
39172
+ }
39173
+ }
39174
+ return obj;
39142
39175
  })
39143
39176
  );
39144
39177
  },
@@ -39188,6 +39221,7 @@ function HTable({
39188
39221
  headers.map((header, i) => {
39189
39222
  var _a, _b;
39190
39223
  if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, header)) return null;
39224
+ if (header.startsWith("_") && !header.startsWith("__")) return null;
39191
39225
  return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
39192
39226
  "div",
39193
39227
  {
@@ -39230,6 +39264,7 @@ function HTable({
39230
39264
  return items.map(([key, item], i) => {
39231
39265
  var _a, _b, _c, _d, _e, _f, _g;
39232
39266
  if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, key)) return null;
39267
+ if (key.startsWith("_") && !key.startsWith("__")) return null;
39233
39268
  if (key == "__modal__") {
39234
39269
  return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39235
39270
  "div",
@@ -39322,7 +39357,10 @@ function HTable({
39322
39357
  children: ((_e = (_d = context.buttons[key]) == null ? void 0 : _d.props) == null ? void 0 : _e.children) ? item : null,
39323
39358
  onClick: async (e) => {
39324
39359
  var _a2, _b2;
39325
- const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onClick) == null ? void 0 : _b2.call(_a2, e)) || {};
39360
+ const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onClick) == null ? void 0 : _b2.call(_a2, {
39361
+ e,
39362
+ row
39363
+ })) || {};
39326
39364
  const newData = [...context.data];
39327
39365
  const index = newData.findIndex((f) => f.id == (row == null ? void 0 : row.id));
39328
39366
  newData[index] = { ...newData[index], ...ret };
@@ -39331,7 +39369,10 @@ function HTable({
39331
39369
  onChange: async (e) => {
39332
39370
  var _a2, _b2, _c2;
39333
39371
  const value = e.target.value;
39334
- const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onChange) == null ? void 0 : _b2.call(_a2, e)) || {};
39372
+ const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onChange) == null ? void 0 : _b2.call(_a2, {
39373
+ e,
39374
+ row
39375
+ })) || {};
39335
39376
  const newData = [...context.data];
39336
39377
  const index = newData.findIndex((f) => f.id == (row == null ? void 0 : row.id));
39337
39378
  if (index >= 0) {
@@ -39349,7 +39390,7 @@ function HTable({
39349
39390
  }) : ["number", "string"].includes(typeof item) ? valueFormatter({
39350
39391
  value: item,
39351
39392
  currentCoin: context.currentCoin
39352
- }) : JSON.stringify(item)
39393
+ }) : import_react19.default.isValidElement(item) ? item : JSON.stringify(item)
39353
39394
  },
39354
39395
  row.id + i
39355
39396
  );
@@ -39381,8 +39422,14 @@ function HTable({
39381
39422
  color: "white",
39382
39423
  onClose: async () => {
39383
39424
  var _a;
39384
- const c = await ((_a = context == null ? void 0 : context.onCloseModal) == null ? void 0 : _a.call(context, searchedData[currentIndex]));
39385
- return c;
39425
+ if (context == null ? void 0 : context.onCloseModal) {
39426
+ const c = await ((_a = context == null ? void 0 : context.onCloseModal) == null ? void 0 : _a.call(
39427
+ context,
39428
+ searchedData[currentIndex]
39429
+ ));
39430
+ return c;
39431
+ }
39432
+ return true;
39386
39433
  },
39387
39434
  children: /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "relative", children: [
39388
39435
  /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "fixed top-0 left-0 p-10 ", children: [
@@ -39425,28 +39472,6 @@ function HTable({
39425
39472
  }
39426
39473
  );
39427
39474
  }
39428
- function valueFormatter({
39429
- value,
39430
- currentCoin = ""
39431
- }) {
39432
- if (value == null || value === "") return "";
39433
- const isDate = /(\d{4}-\d{2}-\d{2})(T[\d:,.+-]*(Z)?)?/;
39434
- if (`${value}`.match(isDate)) {
39435
- return value.toString().split("T")[0].split("-").reverse().join("/");
39436
- }
39437
- const splited = `${value}`.split(".");
39438
- const hasDecimals = splited.length == 2 && splited.every((v) => `${v}`.match(types_default.number));
39439
- if (hasDecimals) {
39440
- return [
39441
- currentCoin,
39442
- (+`${value}`).toLocaleString("en-US", {
39443
- minimumFractionDigits: 2,
39444
- maximumFractionDigits: 2
39445
- })
39446
- ].join(" ");
39447
- }
39448
- return value;
39449
- }
39450
39475
 
39451
39476
  // src/table-advanced/context.ts
39452
39477
  var import_react20 = require("react");
package/dist/index.mjs CHANGED
@@ -37170,13 +37170,16 @@ function usePopup() {
37170
37170
  );
37171
37171
  const close = useCallback(
37172
37172
  async (confirmed, value) => {
37173
- var _a, _b;
37173
+ var _a, _b, _c;
37174
37174
  const prev = { ...popup };
37175
37175
  let visible = false;
37176
37176
  if (confirmed) {
37177
37177
  (_a = prev.onConfirm) == null ? void 0 : _a.call(prev, value);
37178
- } else if (prev == null ? void 0 : prev.onCancel) {
37179
- visible = !Boolean(await ((_b = prev.onCancel) == null ? void 0 : _b.call(prev)));
37178
+ } else if (prev == null ? void 0 : prev.onClose) {
37179
+ visible = !Boolean(await ((_b = prev.onClose) == null ? void 0 : _b.call(prev)));
37180
+ } else {
37181
+ (_c = prev.onCancel) == null ? void 0 : _c.call(prev);
37182
+ visible = false;
37180
37183
  }
37181
37184
  const data = { ...prev, visible, inputValue: "" };
37182
37185
  setPopup(data);
@@ -37201,12 +37204,11 @@ function usePopup() {
37201
37204
  type: "modal",
37202
37205
  message,
37203
37206
  color,
37204
- // onConfirm: () => {
37205
- // resolve();
37206
- // },
37207
- onCancel: async () => {
37207
+ onConfirm: () => resolve(),
37208
+ onCancel: () => resolve(),
37209
+ onClose: onClose ? async () => {
37208
37210
  return await (onClose == null ? void 0 : onClose());
37209
- },
37211
+ } : void 0,
37210
37212
  icons,
37211
37213
  full
37212
37214
  })
@@ -39017,6 +39019,30 @@ var regularExpresions2 = {
39017
39019
  };
39018
39020
  var types_default = regularExpresions2;
39019
39021
 
39022
+ // src/table-advanced/formatter.ts
39023
+ function valueFormatter({
39024
+ value,
39025
+ currentCoin = ""
39026
+ }) {
39027
+ if (value == null || value === "") return "";
39028
+ const isDate = /(\d{4}-\d{2}-\d{2})(T[\d:,.+-]*(Z)?)?/;
39029
+ if (`${value}`.match(isDate)) {
39030
+ return value.toString().split("T")[0].split("-").reverse().join("/");
39031
+ }
39032
+ const splited = `${value}`.split(".");
39033
+ const hasDecimals = splited.length == 2 && splited.every((v) => `${v}`.match(types_default.number));
39034
+ if (hasDecimals) {
39035
+ return [
39036
+ currentCoin,
39037
+ (+`${value}`).toLocaleString("en-US", {
39038
+ minimumFractionDigits: 2,
39039
+ maximumFractionDigits: 2
39040
+ })
39041
+ ].join(" ");
39042
+ }
39043
+ return value;
39044
+ }
39045
+
39020
39046
  // src/table-advanced/h.table.tsx
39021
39047
  import { jsx as jsx33, jsxs as jsxs25 } from "react/jsx-runtime";
39022
39048
  function HTable({
@@ -39065,7 +39091,10 @@ function HTable({
39065
39091
  );
39066
39092
  const gridTemplateColumns2 = headers2.filter((h) => {
39067
39093
  var _a, _b;
39068
- return !((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, h));
39094
+ if (["__modal__", "__select__"].includes(h)) {
39095
+ return true;
39096
+ }
39097
+ return !((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, h)) && !h.startsWith("_");
39069
39098
  }).map((h) => {
39070
39099
  var _a;
39071
39100
  return `${(_a = widths2[h]) != null ? _a : defaultWidth}px`;
@@ -39076,28 +39105,27 @@ function HTable({
39076
39105
  useEffect11(() => {
39077
39106
  if (!tableRef.current) return;
39078
39107
  const observer = new ResizeObserver(([entry]) => {
39079
- const sizeados = headers.filter(
39080
- (h) => [
39081
- "__select__",
39082
- "__modal__"
39083
- // ...(context?.hideColumns || []),
39084
- // ...(context?.colSize ? Object.keys(context.colSize) : []),
39085
- ].includes(h)
39108
+ const ocultos = headers.filter(
39109
+ (h) => {
39110
+ var _a, _b;
39111
+ return !h.startsWith("__") && (h.startsWith("_") || ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, h)));
39112
+ }
39086
39113
  );
39114
+ const sizeados = headers.filter((h) => h.startsWith("__"));
39087
39115
  const personalizados = (context == null ? void 0 : context.colSize) ? Object.values(context.colSize) : [];
39088
39116
  const personalizadosSum = personalizados.length > 0 ? personalizados.reduce((acc, i) => acc + i, 0) : 0;
39089
39117
  const ancho = +entry.contentRect.width;
39090
39118
  const sizeadosLength = sizeados.length;
39091
39119
  const sizeadosWidth = sizeadosLength * 60;
39092
- const w = (ancho - sizeadosWidth - personalizadosSum) / (headers.length - sizeadosLength - personalizados.length);
39120
+ const w = (ancho - sizeadosWidth - personalizadosSum) / (headers.length - sizeadosLength - personalizados.length - ocultos.length);
39093
39121
  console.log({
39094
39122
  w,
39095
39123
  ancho,
39096
39124
  sizeadosWidth,
39097
- sizeadosLength,
39098
39125
  personalizadosSum,
39099
- headers: headers.length,
39100
- personalizados: personalizados.length
39126
+ headers,
39127
+ sizeadosLength,
39128
+ personalizados
39101
39129
  });
39102
39130
  setWidths(
39103
39131
  Object.fromEntries(
@@ -39135,8 +39163,13 @@ function HTable({
39135
39163
  onClick: (e) => {
39136
39164
  context.excel.export(
39137
39165
  context.data.map((d) => {
39138
- const { __select__, __modal__, ...datums } = d;
39139
- return datums;
39166
+ const obj = {};
39167
+ for (let key in d) {
39168
+ if (!key.startsWith("_")) {
39169
+ obj[key] = d[key];
39170
+ }
39171
+ }
39172
+ return obj;
39140
39173
  })
39141
39174
  );
39142
39175
  },
@@ -39186,6 +39219,7 @@ function HTable({
39186
39219
  headers.map((header, i) => {
39187
39220
  var _a, _b;
39188
39221
  if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, header)) return null;
39222
+ if (header.startsWith("_") && !header.startsWith("__")) return null;
39189
39223
  return /* @__PURE__ */ jsxs25(
39190
39224
  "div",
39191
39225
  {
@@ -39228,6 +39262,7 @@ function HTable({
39228
39262
  return items.map(([key, item], i) => {
39229
39263
  var _a, _b, _c, _d, _e, _f, _g;
39230
39264
  if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, key)) return null;
39265
+ if (key.startsWith("_") && !key.startsWith("__")) return null;
39231
39266
  if (key == "__modal__") {
39232
39267
  return /* @__PURE__ */ jsx33(
39233
39268
  "div",
@@ -39320,7 +39355,10 @@ function HTable({
39320
39355
  children: ((_e = (_d = context.buttons[key]) == null ? void 0 : _d.props) == null ? void 0 : _e.children) ? item : null,
39321
39356
  onClick: async (e) => {
39322
39357
  var _a2, _b2;
39323
- const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onClick) == null ? void 0 : _b2.call(_a2, e)) || {};
39358
+ const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onClick) == null ? void 0 : _b2.call(_a2, {
39359
+ e,
39360
+ row
39361
+ })) || {};
39324
39362
  const newData = [...context.data];
39325
39363
  const index = newData.findIndex((f) => f.id == (row == null ? void 0 : row.id));
39326
39364
  newData[index] = { ...newData[index], ...ret };
@@ -39329,7 +39367,10 @@ function HTable({
39329
39367
  onChange: async (e) => {
39330
39368
  var _a2, _b2, _c2;
39331
39369
  const value = e.target.value;
39332
- const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onChange) == null ? void 0 : _b2.call(_a2, e)) || {};
39370
+ const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onChange) == null ? void 0 : _b2.call(_a2, {
39371
+ e,
39372
+ row
39373
+ })) || {};
39333
39374
  const newData = [...context.data];
39334
39375
  const index = newData.findIndex((f) => f.id == (row == null ? void 0 : row.id));
39335
39376
  if (index >= 0) {
@@ -39347,7 +39388,7 @@ function HTable({
39347
39388
  }) : ["number", "string"].includes(typeof item) ? valueFormatter({
39348
39389
  value: item,
39349
39390
  currentCoin: context.currentCoin
39350
- }) : JSON.stringify(item)
39391
+ }) : React10.isValidElement(item) ? item : JSON.stringify(item)
39351
39392
  },
39352
39393
  row.id + i
39353
39394
  );
@@ -39379,8 +39420,14 @@ function HTable({
39379
39420
  color: "white",
39380
39421
  onClose: async () => {
39381
39422
  var _a;
39382
- const c = await ((_a = context == null ? void 0 : context.onCloseModal) == null ? void 0 : _a.call(context, searchedData[currentIndex]));
39383
- return c;
39423
+ if (context == null ? void 0 : context.onCloseModal) {
39424
+ const c = await ((_a = context == null ? void 0 : context.onCloseModal) == null ? void 0 : _a.call(
39425
+ context,
39426
+ searchedData[currentIndex]
39427
+ ));
39428
+ return c;
39429
+ }
39430
+ return true;
39384
39431
  },
39385
39432
  children: /* @__PURE__ */ jsxs25("div", { className: "relative", children: [
39386
39433
  /* @__PURE__ */ jsxs25("div", { className: "fixed top-0 left-0 p-10 ", children: [
@@ -39423,28 +39470,6 @@ function HTable({
39423
39470
  }
39424
39471
  );
39425
39472
  }
39426
- function valueFormatter({
39427
- value,
39428
- currentCoin = ""
39429
- }) {
39430
- if (value == null || value === "") return "";
39431
- const isDate = /(\d{4}-\d{2}-\d{2})(T[\d:,.+-]*(Z)?)?/;
39432
- if (`${value}`.match(isDate)) {
39433
- return value.toString().split("T")[0].split("-").reverse().join("/");
39434
- }
39435
- const splited = `${value}`.split(".");
39436
- const hasDecimals = splited.length == 2 && splited.every((v) => `${v}`.match(types_default.number));
39437
- if (hasDecimals) {
39438
- return [
39439
- currentCoin,
39440
- (+`${value}`).toLocaleString("en-US", {
39441
- minimumFractionDigits: 2,
39442
- maximumFractionDigits: 2
39443
- })
39444
- ].join(" ");
39445
- }
39446
- return value;
39447
- }
39448
39473
 
39449
39474
  // src/table-advanced/context.ts
39450
39475
  import { useEffect as useEffect12, useMemo as useMemo9, useReducer as useReducer3, useState as useState16 } from "react";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-recomponents",
3
- "version": "2.0.42",
3
+ "version": "2.0.44",
4
4
  "description": "description nueva",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/pop/index.tsx CHANGED
@@ -24,6 +24,7 @@ export default function usePopup() {
24
24
  const open = useCallback(
25
25
  (partial: Omit<PopupState, "visible" | "inputValue">) => {
26
26
  const { message, ...rest } = partial;
27
+
27
28
  messageRef.current = message as any;
28
29
  setPopup({ ...rest, visible: true, inputValue: "" });
29
30
  },
@@ -36,11 +37,15 @@ export default function usePopup() {
36
37
  let visible = false;
37
38
  if (confirmed) {
38
39
  prev.onConfirm?.(value);
39
- } else if (prev?.onCancel) {
40
- visible = !Boolean(await prev.onCancel?.());
40
+ } else if (prev?.onClose) {
41
+ visible = !Boolean(await prev.onClose?.());
42
+ } else {
43
+ prev.onCancel?.();
44
+ visible = false;
41
45
  }
42
46
 
43
47
  const data = { ...prev, visible, inputValue: "" };
48
+
44
49
  setPopup(data);
45
50
  },
46
51
  [popup],
@@ -73,12 +78,13 @@ export default function usePopup() {
73
78
  type: "modal",
74
79
  message,
75
80
  color,
76
- // onConfirm: () => {
77
- // resolve();
78
- // },
79
- onCancel: async () => {
80
- return await onClose?.();
81
- },
81
+ onConfirm: () => resolve(),
82
+ onCancel: () => resolve(),
83
+ onClose: onClose
84
+ ? async () => {
85
+ return await onClose?.();
86
+ }
87
+ : undefined,
82
88
  icons,
83
89
  full,
84
90
  }),
package/src/pop/types.ts CHANGED
@@ -41,6 +41,7 @@ export interface PopupState {
41
41
  color: PopupColor;
42
42
  onConfirm?: (value?: string) => void;
43
43
  onCancel?: () => void | Promise<boolean | void>;
44
+ onClose?: () => void | Promise<boolean | void>;
44
45
  icons?: boolean;
45
46
  full?: boolean;
46
47
  }
@@ -0,0 +1,36 @@
1
+ import { ReactNode } from "react";
2
+ import regularExpresions from "./types";
3
+
4
+ export function valueFormatter({
5
+ value,
6
+ currentCoin = "",
7
+ }: {
8
+ value: any;
9
+ currentCoin?: ReactNode;
10
+ }) {
11
+ if (value == null || value === "") return "";
12
+
13
+ const isDate = /(\d{4}-\d{2}-\d{2})(T[\d:,.+-]*(Z)?)?/;
14
+
15
+ if (`${value}`.match(isDate)) {
16
+ return value.toString().split("T")[0].split("-").reverse().join("/");
17
+ }
18
+
19
+ const splited = `${value}`.split(".");
20
+
21
+ const hasDecimals =
22
+ splited.length == 2 &&
23
+ splited.every((v: any) => `${v}`.match(regularExpresions.number));
24
+
25
+ if (hasDecimals) {
26
+ return [
27
+ currentCoin,
28
+ (+`${value}`).toLocaleString("en-US", {
29
+ minimumFractionDigits: 2,
30
+ maximumFractionDigits: 2,
31
+ }),
32
+ ].join(" ");
33
+ }
34
+
35
+ return value;
36
+ }
@@ -14,6 +14,7 @@ import Searchable from "./searchable";
14
14
  import Modal from "../modal";
15
15
  import { EditIcon } from "./icons";
16
16
  import regularExpresions, { TableProps } from "./types";
17
+ import { valueFormatter } from "./formatter";
17
18
  type Widths = Record<string, number>;
18
19
  export default function HTable({
19
20
  context,
@@ -51,18 +52,6 @@ export default function HTable({
51
52
  }
52
53
  const [widths, setWidths] = useState<Widths>({});
53
54
 
54
- // si headers cambia dinámicamente, hay que rellenar los que falten
55
- // useEffect(() => {
56
- // setWidths((prev) => {
57
- // const missing = headers.filter((h) => !(h in prev));
58
- // if (missing.length === 0) return prev;
59
- // return {
60
- // ...prev,
61
- // ...Object.fromEntries(missing.map((h) => [h, getWidth(h)])),
62
- // };
63
- // });
64
- // }, [headers, defaultWidth]);
65
-
66
55
  const startDrag = useCallback(
67
56
  (e: React.MouseEvent, headerKey: string) => {
68
57
  e.preventDefault();
@@ -87,7 +76,13 @@ export default function HTable({
87
76
  );
88
77
 
89
78
  const gridTemplateColumns = headers
90
- .filter((h) => !context?.hideColumns?.includes?.(h))
79
+ .filter((h) => {
80
+ if (["__modal__", "__select__"].includes(h)) {
81
+ return true;
82
+ }
83
+
84
+ return !context?.hideColumns?.includes?.(h) && !h.startsWith("_");
85
+ })
91
86
  .map((h) => `${widths[h] ?? defaultWidth}px`)
92
87
  .join(" ");
93
88
 
@@ -99,14 +94,12 @@ export default function HTable({
99
94
  useEffect(() => {
100
95
  if (!tableRef.current) return;
101
96
  const observer = new ResizeObserver(([entry]) => {
102
- const sizeados = headers.filter((h) =>
103
- [
104
- "__select__",
105
- "__modal__",
106
- // ...(context?.hideColumns || []),
107
- // ...(context?.colSize ? Object.keys(context.colSize) : []),
108
- ].includes(h),
97
+ const ocultos = headers.filter(
98
+ (h) =>
99
+ !h.startsWith("__") &&
100
+ (h.startsWith("_") || context?.hideColumns?.includes?.(h)),
109
101
  );
102
+ const sizeados = headers.filter((h) => h.startsWith("__"));
110
103
 
111
104
  const personalizados = context?.colSize
112
105
  ? (Object.values(context.colSize) as number[])
@@ -122,15 +115,18 @@ export default function HTable({
122
115
 
123
116
  const w =
124
117
  (ancho - sizeadosWidth - personalizadosSum) /
125
- (headers.length - sizeadosLength - personalizados.length);
118
+ (headers.length -
119
+ sizeadosLength -
120
+ personalizados.length -
121
+ ocultos.length);
126
122
  console.log({
127
123
  w,
128
124
  ancho,
129
125
  sizeadosWidth,
130
- sizeadosLength,
131
126
  personalizadosSum,
132
- headers: headers.length,
133
- personalizados: personalizados.length,
127
+ headers,
128
+ sizeadosLength,
129
+ personalizados,
134
130
  });
135
131
  setWidths(
136
132
  Object.fromEntries(
@@ -168,8 +164,14 @@ export default function HTable({
168
164
  onClick={(e) => {
169
165
  context.excel.export(
170
166
  context.data.map((d) => {
171
- const { __select__, __modal__, ...datums } = d;
172
- return datums;
167
+ const obj: any = {};
168
+
169
+ for (let key in d) {
170
+ if (!key.startsWith("_")) {
171
+ obj[key] = d[key];
172
+ }
173
+ }
174
+ return obj;
173
175
  }),
174
176
  );
175
177
  }}
@@ -228,6 +230,7 @@ export default function HTable({
228
230
  <div className="grid " style={{ gridTemplateColumns }}>
229
231
  {headers.map((header, i) => {
230
232
  if (context?.hideColumns?.includes?.(header)) return null;
233
+ if (header.startsWith("_") && !header.startsWith("__")) return null;
231
234
  return (
232
235
  <div
233
236
  key={header}
@@ -269,6 +272,7 @@ export default function HTable({
269
272
 
270
273
  return items.map(([key, item], i) => {
271
274
  if (context?.hideColumns?.includes?.(key)) return null;
275
+ if (key.startsWith("_") && !key.startsWith("__")) return null;
272
276
 
273
277
  if (key == "__modal__") {
274
278
  return (
@@ -407,7 +411,10 @@ export default function HTable({
407
411
  : null,
408
412
  onClick: async (e: any) => {
409
413
  const ret =
410
- (await context.buttons[key].props?.onClick?.(e)) || {};
414
+ (await context.buttons[key].props?.onClick?.({
415
+ e,
416
+ row,
417
+ })) || {};
411
418
  const newData = [...context.data];
412
419
  const index = newData.findIndex((f) => f.id == row?.id);
413
420
  newData[index] = { ...newData[index], ...ret };
@@ -416,7 +423,10 @@ export default function HTable({
416
423
  onChange: async (e: { target: { value: string } }) => {
417
424
  const value = e.target.value;
418
425
  const ret =
419
- (await context.buttons[key].props?.onChange?.(e)) || {};
426
+ (await context.buttons[key].props?.onChange?.({
427
+ e,
428
+ row,
429
+ })) || {};
420
430
 
421
431
  const newData = [...context.data];
422
432
  const index = newData.findIndex((f) => f.id == row?.id);
@@ -441,6 +451,8 @@ export default function HTable({
441
451
  value: item,
442
452
  currentCoin: context.currentCoin,
443
453
  })
454
+ ) : React.isValidElement(item) ? (
455
+ item
444
456
  ) : (
445
457
  JSON.stringify(item)
446
458
  )}
@@ -493,9 +505,15 @@ export default function HTable({
493
505
  button={<button ref={modalRef}></button>}
494
506
  color={"white"}
495
507
  onClose={async () => {
496
- const c = await context?.onCloseModal?.(searchedData[currentIndex]);
508
+ if (context?.onCloseModal) {
509
+ const c = await context?.onCloseModal?.(
510
+ searchedData[currentIndex],
511
+ );
512
+
513
+ return c;
514
+ }
497
515
 
498
- return c;
516
+ return true;
499
517
  }}
500
518
  >
501
519
  <div className="relative">
@@ -543,37 +561,3 @@ export default function HTable({
543
561
  </div>
544
562
  );
545
563
  }
546
-
547
- function valueFormatter({
548
- value,
549
- currentCoin = "",
550
- }: {
551
- value: any;
552
- currentCoin?: ReactNode;
553
- }) {
554
- if (value == null || value === "") return "";
555
-
556
- const isDate = /(\d{4}-\d{2}-\d{2})(T[\d:,.+-]*(Z)?)?/;
557
-
558
- if (`${value}`.match(isDate)) {
559
- return value.toString().split("T")[0].split("-").reverse().join("/");
560
- }
561
-
562
- const splited = `${value}`.split(".");
563
-
564
- const hasDecimals =
565
- splited.length == 2 &&
566
- splited.every((v: any) => `${v}`.match(regularExpresions.number));
567
-
568
- if (hasDecimals) {
569
- return [
570
- currentCoin,
571
- (+`${value}`).toLocaleString("en-US", {
572
- minimumFractionDigits: 2,
573
- maximumFractionDigits: 2,
574
- }),
575
- ].join(" ");
576
- }
577
-
578
- return value;
579
- }