next-recomponents 1.2.6 → 1.2.8

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.mjs CHANGED
@@ -11128,13 +11128,19 @@ function TD(_a) {
11128
11128
  item,
11129
11129
  index,
11130
11130
  color: color2,
11131
- symbols
11131
+ symbols,
11132
+ handlers,
11133
+ mapedData,
11134
+ setMapedData
11132
11135
  } = _b, props = __objRest(_b, [
11133
11136
  "className",
11134
11137
  "item",
11135
11138
  "index",
11136
11139
  "color",
11137
- "symbols"
11140
+ "symbols",
11141
+ "handlers",
11142
+ "mapedData",
11143
+ "setMapedData"
11138
11144
  ]);
11139
11145
  const [isHidded, setIsHidded] = useState4(false);
11140
11146
  const isNode = useMemo6(() => {
@@ -11170,10 +11176,37 @@ function TD(_a) {
11170
11176
  "border-b max-w-[200px] p-5 ",
11171
11177
  ["number", "money"].includes(item == null ? void 0 : item.cellTypeOf) && "text-right"
11172
11178
  ].join(" "),
11173
- children: /* @__PURE__ */ jsxs6("div", { className: symbols && symbols[item == null ? void 0 : item.name] && "flex justify-between", children: [
11174
- /* @__PURE__ */ jsx8("div", { children: symbols && symbols[item == null ? void 0 : item.name] && (isNode ? React3.cloneElement(symbols[item == null ? void 0 : item.name], __spreadValues({}, newProps)) : symbols[item == null ? void 0 : item.name]) }),
11175
- /* @__PURE__ */ jsx8("div", { children: item == null ? void 0 : item.content })
11176
- ] })
11179
+ children: handlers && handlers[item == null ? void 0 : item.name] ? /* @__PURE__ */ jsx8("div", { children: React3.Children.map(handlers[item == null ? void 0 : item.name], (child) => {
11180
+ if (React3.isValidElement(child)) {
11181
+ const oldProps = (child == null ? void 0 : child.props) || {};
11182
+ const alteredProps = __spreadProps(__spreadValues({}, oldProps), {
11183
+ value: item == null ? void 0 : item.content,
11184
+ onChange: (e) => {
11185
+ var _a2;
11186
+ const newData = [...mapedData];
11187
+ newData[index][item == null ? void 0 : item.name].content = e.target.value;
11188
+ setMapedData == null ? void 0 : setMapedData(newData);
11189
+ e.item = item;
11190
+ (_a2 = oldProps == null ? void 0 : oldProps.onChange) == null ? void 0 : _a2.call(oldProps, e);
11191
+ }
11192
+ });
11193
+ return React3.cloneElement(child, __spreadValues({}, alteredProps));
11194
+ }
11195
+ }) }) : /* @__PURE__ */ jsxs6(
11196
+ "div",
11197
+ {
11198
+ className: symbols && symbols[item == null ? void 0 : item.name] && "flex justify-between",
11199
+ children: [
11200
+ /* @__PURE__ */ jsx8("div", { children: symbols && React3.Children.map(symbols[item == null ? void 0 : item.name], (child) => {
11201
+ if (React3.isValidElement(child)) {
11202
+ return React3.cloneElement(child, __spreadValues({}, newProps));
11203
+ }
11204
+ return child;
11205
+ }) }),
11206
+ /* @__PURE__ */ jsx8("div", { children: item == null ? void 0 : item.content })
11207
+ ]
11208
+ }
11209
+ )
11177
11210
  }
11178
11211
  );
11179
11212
  }
@@ -11217,26 +11250,22 @@ import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs7 } from "react/jsx-ru
11217
11250
  function FilterMenu({
11218
11251
  h,
11219
11252
  mapedData,
11253
+ setMapedData,
11220
11254
  selectedFilter,
11221
11255
  index,
11222
- filters,
11223
- setFilters,
11224
- setSelectedFilter,
11225
- items
11256
+ setSelectedFilter
11226
11257
  }) {
11227
- const [visibleFloat, setVisibleFloat] = useState5(false);
11228
11258
  const [text, setText] = useState5("");
11229
11259
  const [newMapedData, setNewMapedData] = useState5([]);
11230
11260
  useEffect6(() => {
11231
11261
  setNewMapedData(
11232
- [...new Set(mapedData.map((md) => {
11233
- var _a;
11234
- return (_a = md[h]) == null ? void 0 : _a.content;
11235
- }))].filter(
11236
- (item) => {
11237
- return item && `${item}`.toLowerCase().includes(text.toLowerCase());
11238
- }
11239
- )
11262
+ [
11263
+ ...new Set(
11264
+ mapedData.filter((md) => md.__visible__ === true).map((md) => md[h])
11265
+ )
11266
+ ].filter((item) => {
11267
+ return item && `${item}`.toLowerCase().includes(text.toLowerCase());
11268
+ })
11240
11269
  );
11241
11270
  }, [mapedData, text]);
11242
11271
  useEffect6(() => {
@@ -11249,21 +11278,25 @@ function FilterMenu({
11249
11278
  className: "absolute bg-white border rounded min-w-[200px] ",
11250
11279
  style: { zIndex: 9999999 },
11251
11280
  children: /* @__PURE__ */ jsxs7("div", { className: "flex flex-col items-start text-black", children: [
11252
- filters[h].length != items.length && /* @__PURE__ */ jsxs7(
11281
+ /* @__PURE__ */ jsxs7(
11253
11282
  "div",
11254
11283
  {
11255
11284
  className: "flex gap-1 w-full hover:bg-gray-100 p-3 cursor-pointer",
11256
11285
  onClick: (e) => {
11257
- const newFilters = __spreadValues({}, filters);
11258
- newFilters[h] = [...items];
11259
- setFilters(newFilters);
11286
+ const nmd = [...mapedData];
11287
+ setMapedData(
11288
+ nmd.map((d) => {
11289
+ const newd = __spreadValues({}, d);
11290
+ newd[h].exclude = false;
11291
+ return newd;
11292
+ })
11293
+ );
11294
+ setSelectedFilter(null);
11260
11295
  },
11261
11296
  children: [
11262
11297
  /* @__PURE__ */ jsx10("div", { className: "text-red-500", children: /* @__PURE__ */ jsx10(FilterOffIcon, {}) }),
11263
11298
  " ",
11264
- 'Limpiar filtro de "',
11265
- h,
11266
- '"'
11299
+ "Limpiar filtros"
11267
11300
  ]
11268
11301
  }
11269
11302
  ),
@@ -11275,7 +11308,6 @@ function FilterMenu({
11275
11308
  placeholder: "Buscar...",
11276
11309
  value: text,
11277
11310
  onChange: (e) => {
11278
- setFilters(__spreadProps(__spreadValues({}, filters), { [h]: [] }));
11279
11311
  setText(e.target.value);
11280
11312
  }
11281
11313
  }
@@ -11291,15 +11323,16 @@ function FilterMenu({
11291
11323
  "input",
11292
11324
  {
11293
11325
  type: "checkbox",
11294
- checked: filters[h].length == items.length,
11326
+ checked: mapedData.map((d) => d[h].exclude).every((d) => d === false),
11295
11327
  onChange: (e) => {
11296
- const newFilters = __spreadValues({}, filters);
11297
- if (filters[h].length == items.length) {
11298
- newFilters[h] = [];
11299
- } else {
11300
- newFilters[h] = [...items];
11301
- }
11302
- setFilters(newFilters);
11328
+ const nmd = [...mapedData];
11329
+ setMapedData(
11330
+ nmd.map((d) => {
11331
+ const newd = __spreadValues({}, d);
11332
+ newd[h].exclude = false;
11333
+ return newd;
11334
+ })
11335
+ );
11303
11336
  }
11304
11337
  }
11305
11338
  ),
@@ -11307,8 +11340,20 @@ function FilterMenu({
11307
11340
  "(Seleccionar todo)"
11308
11341
  ] }) }),
11309
11342
  newMapedData.map((item, key) => {
11310
- var _a;
11311
- const checked = (_a = filters[h]) == null ? void 0 : _a.find((i) => i == item);
11343
+ const excludeds = mapedData.filter((d) => {
11344
+ const obj = Object.keys(d).map((i) => {
11345
+ return d[i].exclude === true;
11346
+ });
11347
+ return obj.some((o) => o === true);
11348
+ });
11349
+ const finded = excludeds.find(
11350
+ (e) => e[item.name].content == item.content
11351
+ );
11352
+ const disabled = finded && Object.keys(finded).map((k) => {
11353
+ var _a;
11354
+ if (k == item.name) return false;
11355
+ return (_a = finded[k]) == null ? void 0 : _a.exclude;
11356
+ }).some((i) => i === true);
11312
11357
  return /* @__PURE__ */ jsx10(
11313
11358
  "div",
11314
11359
  {
@@ -11318,27 +11363,20 @@ function FilterMenu({
11318
11363
  "input",
11319
11364
  {
11320
11365
  type: "checkbox",
11321
- checked: !!checked,
11366
+ checked: !item.exclude,
11367
+ disabled,
11322
11368
  onChange: (e) => {
11323
- const newFilters = __spreadValues({}, filters);
11324
- newFilters[h] = newFilters[h] || [];
11325
- const index2 = newFilters[h].findIndex(
11326
- (nf) => nf == item
11327
- );
11328
- if (index2 >= 0) {
11329
- newFilters[h].splice(index2, 1);
11330
- } else {
11331
- newFilters[h].push(item);
11332
- }
11333
- setFilters(newFilters);
11369
+ const n = [...newMapedData];
11370
+ n[key].exclude = !item.exclude;
11371
+ setNewMapedData(n);
11334
11372
  }
11335
11373
  }
11336
11374
  ),
11337
11375
  " ",
11338
- item
11376
+ item.content
11339
11377
  ] })
11340
11378
  },
11341
- item
11379
+ item.content
11342
11380
  );
11343
11381
  })
11344
11382
  ]
@@ -11347,7 +11385,9 @@ function FilterMenu({
11347
11385
  /* @__PURE__ */ jsx10("div", { className: "w-full p-1", children: /* @__PURE__ */ jsx10("div", { className: "flex flex-row gap-2 justify-end w-full ", children: /* @__PURE__ */ jsx10(
11348
11386
  "button",
11349
11387
  {
11350
- onClick: (e) => setSelectedFilter(null),
11388
+ onClick: (e) => {
11389
+ setSelectedFilter(null);
11390
+ },
11351
11391
  className: "p-1 border rounded shadow hover:bg-gray-100",
11352
11392
  children: "Aceptar"
11353
11393
  }
@@ -11370,7 +11410,7 @@ function FilterMenu({
11370
11410
  }
11371
11411
 
11372
11412
  // src/table/h.tsx
11373
- import { jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
11413
+ import { Fragment as Fragment4, jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
11374
11414
  function HTable(_a) {
11375
11415
  var _b = _a, {
11376
11416
  data,
@@ -11390,12 +11430,11 @@ function HTable(_a) {
11390
11430
  const [selected, setSelected] = useState6(null);
11391
11431
  const [selectedFilter, setSelectedFilter] = useState6(null);
11392
11432
  const modalRef = useRef4(null);
11393
- const [filters, setFilters] = useState6({});
11394
11433
  const head = useMemo7(() => {
11395
11434
  return [...new Set(data.map((d) => Object.keys(d)).flat())];
11396
11435
  }, [data]);
11397
11436
  const mapedTotals = useMemo7(() => {
11398
- return mapedData.reduce((acc, md) => {
11437
+ return mapedData == null ? void 0 : mapedData.reduce((acc, md) => {
11399
11438
  head.forEach((h) => {
11400
11439
  var _a2, _b2;
11401
11440
  const value = isNaN(+((_a2 = md[h]) == null ? void 0 : _a2.content)) ? 0 : +((_b2 = md[h]) == null ? void 0 : _b2.content);
@@ -11408,21 +11447,9 @@ function HTable(_a) {
11408
11447
  return acc;
11409
11448
  }, {});
11410
11449
  }, [mapedData]);
11411
- useEffect7(() => {
11412
- setFilters(__spreadValues({}, head.reduce((acc, hh) => {
11413
- const newAcc = __spreadValues({}, acc);
11414
- newAcc[hh] = [
11415
- ...new Set(mapedData.map((md) => {
11416
- var _a2;
11417
- return (_a2 = md[hh]) == null ? void 0 : _a2.content;
11418
- }))
11419
- ];
11420
- return newAcc;
11421
- }, {})));
11422
- }, [mapedData, head]);
11423
11450
  useEffect7(() => {
11424
11451
  const newData = data.map((d, trkey) => {
11425
- const obj = {};
11452
+ const obj = { __visible__: true };
11426
11453
  for (let key in d) {
11427
11454
  const typeOf = typeof d[key];
11428
11455
  const isObject2 = typeOf == "object";
@@ -11430,28 +11457,21 @@ function HTable(_a) {
11430
11457
  const cellTypeOf = isDate ? "date" : isObject2 ? "object" : typeOf;
11431
11458
  const content = cellTypeOf == "date" ? d[key].split("T").join(" ").split(".")[0] : cellTypeOf == "object" ? React4.isValidElement(d[key]) ? d[key] : JSON.stringify(d[key]) : d[key];
11432
11459
  obj[key] = {
11460
+ index: trkey,
11433
11461
  originalData: content,
11434
11462
  cellTypeOf,
11435
11463
  title: content,
11436
11464
  content,
11437
- name: key
11465
+ name: key,
11466
+ exclude: false
11438
11467
  };
11439
11468
  }
11440
11469
  return obj;
11441
11470
  });
11442
11471
  setMapedData(newData);
11443
11472
  }, [data]);
11444
- return /* @__PURE__ */ jsxs8("table", __spreadProps(__spreadValues({}, props), { className: "w-full border-collapse table-auto", children: [
11473
+ return /* @__PURE__ */ jsx11(Fragment4, { children: /* @__PURE__ */ jsxs8("table", __spreadProps(__spreadValues({}, props), { className: "w-full border-collapse table-auto", children: [
11445
11474
  /* @__PURE__ */ jsx11("thead", { className: "bg-gray-800 text-white", children: /* @__PURE__ */ jsx11("tr", { children: head.map((h, key) => {
11446
- var _a2;
11447
- const items = [
11448
- ...new Set(
11449
- mapedData.map((item) => {
11450
- var _a3;
11451
- return (_a3 = item[h]) == null ? void 0 : _a3.content;
11452
- })
11453
- )
11454
- ];
11455
11475
  return /* @__PURE__ */ jsxs8(
11456
11476
  "th",
11457
11477
  {
@@ -11467,18 +11487,16 @@ function HTable(_a) {
11467
11487
  children: /* @__PURE__ */ jsxs8("div", { className: "text-white w-full bg-black rounded p-1 flex justify-center", children: [
11468
11488
  h,
11469
11489
  " ",
11470
- ((_a2 = filters[h]) == null ? void 0 : _a2.length) != items.length && /* @__PURE__ */ jsx11("div", { className: "text-red-300", children: /* @__PURE__ */ jsx11(FilterOffIcon, {}) })
11490
+ !mapedData.map((d) => d[h].exclude).every((d) => d === false) && /* @__PURE__ */ jsx11("div", { className: "text-red-300", children: /* @__PURE__ */ jsx11(FilterOffIcon, {}) })
11471
11491
  ] })
11472
11492
  }
11473
11493
  ),
11474
11494
  /* @__PURE__ */ jsx11(
11475
11495
  FilterMenu,
11476
11496
  {
11477
- filters,
11478
- setFilters,
11479
- items,
11480
11497
  h,
11481
11498
  mapedData,
11499
+ setMapedData,
11482
11500
  index: key,
11483
11501
  selectedFilter,
11484
11502
  setSelectedFilter
@@ -11486,25 +11504,23 @@ function HTable(_a) {
11486
11504
  )
11487
11505
  ]
11488
11506
  },
11489
- key
11507
+ h
11490
11508
  );
11491
11509
  }) }) }),
11492
- /* @__PURE__ */ jsx11("tbody", { className: "divide-y divide-gray-200", children: mapedData.filter((md) => {
11510
+ /* @__PURE__ */ jsx11("tbody", { className: "divide-y divide-gray-200", children: mapedData.map((md, trKey) => {
11493
11511
  var _a2;
11494
- for (let datum of Object.keys(md)) {
11495
- if (!filters[datum].map((d) => `${d}`.toLowerCase()).includes(`${(_a2 = md[datum]) == null ? void 0 : _a2.content}`.toLowerCase())) {
11496
- return false;
11512
+ const color2 = trKey % 2 == 0 ? "bg-white" : "bg-gray-100";
11513
+ for (let d in md) {
11514
+ if (md[d].exclude === true) {
11515
+ return null;
11497
11516
  }
11498
11517
  }
11499
- return true;
11500
- }).map((md, trKey) => {
11501
- const color2 = trKey % 2 == 0 ? "bg-white" : "bg-gray-100";
11502
11518
  return /* @__PURE__ */ jsx11(
11503
11519
  "tr",
11504
11520
  {
11505
11521
  onDoubleClick: (e) => {
11506
- var _a2;
11507
- (_a2 = modalRef.current) == null ? void 0 : _a2.showModal();
11522
+ var _a3;
11523
+ (_a3 = modalRef.current) == null ? void 0 : _a3.showModal();
11508
11524
  },
11509
11525
  onClick: (e) => setSelected(trKey),
11510
11526
  className: [
@@ -11513,28 +11529,41 @@ function HTable(_a) {
11513
11529
  selected == trKey && "bg-green-200 hover:bg-green-300"
11514
11530
  ].join(" "),
11515
11531
  children: head.map((h, tdKey) => {
11532
+ var _a3;
11533
+ const item = md[h];
11534
+ const id3 = trKey + "-" + (((_a3 = md == null ? void 0 : md.id) == null ? void 0 : _a3.content) || tdKey) + "-" + h;
11516
11535
  return /* @__PURE__ */ jsx11(
11517
11536
  TD,
11518
11537
  {
11519
11538
  index: trKey,
11520
11539
  symbols,
11521
- item: md[h],
11522
- color: color2
11540
+ handlers: props.handlers,
11541
+ item,
11542
+ color: color2,
11543
+ mapedData,
11544
+ setMapedData
11523
11545
  },
11524
- tdKey
11546
+ id3
11525
11547
  );
11526
11548
  })
11527
11549
  },
11528
- trKey
11550
+ ((_a2 = md == null ? void 0 : md.id) == null ? void 0 : _a2.content) || trKey
11529
11551
  );
11530
11552
  }) }),
11531
11553
  /* @__PURE__ */ jsx11("tfoot", { className: "bg-gray-800 text-white", children: /* @__PURE__ */ jsx11("tr", { children: head.map((h, fkey) => {
11532
- return /* @__PURE__ */ jsx11("th", { className: "text-right border-b max-w-[200px] p-5 ", children: totals && totals.includes(h) && /* @__PURE__ */ jsxs8("div", { className: "flex justify-between text-white w-full bg-black rounded p-1", children: [
11533
- /* @__PURE__ */ jsx11("div", { className: "p-1", children: symbols && symbols[h] && symbols[h] }),
11534
- /* @__PURE__ */ jsx11("div", { className: "p-1", children: mapedTotals[h] })
11535
- ] }) }, fkey);
11554
+ return /* @__PURE__ */ jsx11(
11555
+ "th",
11556
+ {
11557
+ className: "text-right border-b max-w-[200px] p-5 ",
11558
+ children: totals && totals.includes(h) && /* @__PURE__ */ jsxs8("div", { className: "flex justify-between text-white w-full bg-black rounded p-1", children: [
11559
+ /* @__PURE__ */ jsx11("div", { className: "p-1", children: symbols && symbols[h] && symbols[h] }),
11560
+ /* @__PURE__ */ jsx11("div", { className: "p-1", children: mapedTotals[h] })
11561
+ ] })
11562
+ },
11563
+ fkey
11564
+ );
11536
11565
  }) }) })
11537
- ] }));
11566
+ ] })) });
11538
11567
  }
11539
11568
 
11540
11569
  // ../../node_modules/xlsx/xlsx.mjs
@@ -32039,22 +32068,23 @@ function useExportdata() {
32039
32068
  }
32040
32069
 
32041
32070
  // src/table/index.tsx
32042
- import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
32071
+ import { Fragment as Fragment5, jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
32043
32072
  function Table(props) {
32044
32073
  const [mapedData, setMapedData] = useState7([]);
32045
32074
  const isArray = Array.isArray(props.data);
32046
32075
  const exported = useExportdata();
32047
32076
  return /* @__PURE__ */ jsxs9("div", { className: "bg-gray-200 border rounded shadow p-1", children: [
32048
- (props == null ? void 0 : props.exportName) && props.data.length > 0 && /* @__PURE__ */ jsxs9(
32077
+ (props == null ? void 0 : props.exportName) && props.data.length > 0 && /* @__PURE__ */ jsx12(Fragment5, { children: /* @__PURE__ */ jsxs9(
32049
32078
  "button",
32050
32079
  {
32051
32080
  className: "p-2 border rounded shadow bg-green-800 text-white flex gap-1",
32052
32081
  onClick: (e) => exported.export(
32053
32082
  mapedData.map((md) => {
32054
- for (let i of Object.keys(md)) {
32055
- md[i] = md[i].content;
32083
+ const _a = md, { __visible__ } = _a, newMd = __objRest(_a, ["__visible__"]);
32084
+ for (let i of Object.keys(newMd)) {
32085
+ newMd[i] = newMd[i].content;
32056
32086
  }
32057
- return md;
32087
+ return newMd;
32058
32088
  }),
32059
32089
  props.exportName
32060
32090
  ),
@@ -32063,14 +32093,14 @@ function Table(props) {
32063
32093
  " Exportar"
32064
32094
  ]
32065
32095
  }
32066
- ),
32067
- isArray && /* @__PURE__ */ jsx12(
32096
+ ) }),
32097
+ isArray ? /* @__PURE__ */ jsx12(
32068
32098
  HTable,
32069
32099
  __spreadValues({}, __spreadProps(__spreadValues({}, props), {
32070
32100
  mapedData,
32071
32101
  setMapedData
32072
32102
  }))
32073
- )
32103
+ ) : /* @__PURE__ */ jsx12("div", { className: " p-5 border rounded shadow bg-yellw-500", children: "No es un array" })
32074
32104
  ] });
32075
32105
  }
32076
32106
 
@@ -32701,7 +32731,7 @@ function Select(_a) {
32701
32731
 
32702
32732
  // src/modal/index.tsx
32703
32733
  import React7, { useRef as useRef6 } from "react";
32704
- import { Fragment as Fragment4, jsx as jsx17, jsxs as jsxs12 } from "react/jsx-runtime";
32734
+ import { Fragment as Fragment6, jsx as jsx17, jsxs as jsxs12 } from "react/jsx-runtime";
32705
32735
  function Modal({ button, children, ref }) {
32706
32736
  const modalRef = ref || useRef6(null);
32707
32737
  function show() {
@@ -32712,7 +32742,7 @@ function Modal({ button, children, ref }) {
32712
32742
  var _a;
32713
32743
  typeof modalRef == "object" && ((_a = modalRef.current) == null ? void 0 : _a.close());
32714
32744
  }
32715
- return /* @__PURE__ */ jsxs12(Fragment4, { children: [
32745
+ return /* @__PURE__ */ jsxs12(Fragment6, { children: [
32716
32746
  React7.Children.map(button, (child) => {
32717
32747
  if (React7.isValidElement(child)) {
32718
32748
  return React7.cloneElement(child, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-recomponents",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",