@universe-platform/ui 0.1.0-beta.3 → 0.1.0-beta.4

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
@@ -417,16 +417,22 @@ function getRelationDisplayLabel(opt, column) {
417
417
  if (val !== void 0 && val !== null && val !== "") {
418
418
  return String(val);
419
419
  }
420
+ if (opt.label && opt.label !== opt.id) {
421
+ return String(opt.label);
422
+ }
420
423
  if (opt.data) {
421
424
  const fallbackField = Object.keys(opt.data).find((k) => {
422
425
  if (k === "_id" || k === "id") return false;
423
426
  const v = opt.data[k];
424
427
  if (typeof v === "string" && v.trim() !== "") return true;
425
- if (typeof v === "number") return true;
428
+ if (typeof v === "number" && !isNaN(v)) return true;
426
429
  return false;
427
430
  });
428
431
  if (fallbackField) return String(opt.data[fallbackField]);
429
432
  }
433
+ if (opt.label) {
434
+ return String(opt.label);
435
+ }
430
436
  return "\u05E2\u05E8\u05DA \u05E8\u05D9\u05E7";
431
437
  }
432
438
  var FORM_INPUTS = {
@@ -686,7 +692,7 @@ function TableBlockClient({
686
692
  }
687
693
  }, [initialRecords]);
688
694
  (0, import_react5.useEffect)(() => {
689
- const tableId = (schema == null ? void 0 : schema.tableMetaId) || (schema == null ? void 0 : schema.id) || (schema == null ? void 0 : schema.tableId);
695
+ const tableId = (schema == null ? void 0 : schema.tableMetaId) || (schema == null ? void 0 : schema.tableId) || (schema == null ? void 0 : schema.id);
690
696
  if (!tableId || !executeAction) return;
691
697
  if (!(schema == null ? void 0 : schema.columns) || schema.columns.length === 0 || (!initialRecords || initialRecords.length === 0)) {
692
698
  executeAction("FETCH_TABLE_DATA", { tableId }).then((res) => {
@@ -707,7 +713,7 @@ function TableBlockClient({
707
713
  console.error("[TableBlock] Failed to auto-fetch table data:", err);
708
714
  });
709
715
  }
710
- }, [schema == null ? void 0 : schema.tableMetaId, schema == null ? void 0 : schema.id, schema == null ? void 0 : schema.tableId, schema == null ? void 0 : schema.columns, initialRecords, executeAction, mergeWithDirty]);
716
+ }, [schema == null ? void 0 : schema.tableMetaId, schema == null ? void 0 : schema.tableId, schema == null ? void 0 : schema.id, schema == null ? void 0 : schema.columns, initialRecords, executeAction, mergeWithDirty]);
711
717
  (0, import_react5.useEffect)(() => {
712
718
  if (error) {
713
719
  showError(error, "\u05E9\u05D2\u05D9\u05D0\u05D4 \u05D1\u05E8\u05DB\u05D9\u05D1");
@@ -731,7 +737,7 @@ function TableBlockClient({
731
737
  if (!col || ((_a = col.type) == null ? void 0 : _a.toUpperCase()) !== "RELATION" || !col.referencedTableId) return;
732
738
  try {
733
739
  if (executeAction) {
734
- const options = await executeAction("FETCH_RELATION", { referencedTableId: col.referencedTableId });
740
+ const options = await executeAction("FETCH_RELATION", { referencedTableId: col.referencedTableId, displayField: col.displayField });
735
741
  if (options && Array.isArray(options)) {
736
742
  setRelationOptions((prev) => __spreadProps(__spreadValues({}, prev), { [colName]: options }));
737
743
  }
@@ -926,19 +932,58 @@ function TableBlockClient({
926
932
  showError("\u05E8\u05DB\u05D9\u05D1 \u05D4\u05EA\u05E7\u05E9\u05D5\u05E8\u05EA \u05DC\u05D0 \u05D0\u05D5\u05EA\u05D7\u05DC", "\u05E9\u05D2\u05D9\u05D0\u05EA \u05EA\u05E7\u05E9\u05D5\u05E8\u05EA");
927
933
  return;
928
934
  }
929
- const targetTableId = (schema == null ? void 0 : schema.tableMetaId) || (schema == null ? void 0 : schema.id) || (schema == null ? void 0 : schema.tableId);
935
+ const targetTableId = (schema == null ? void 0 : schema.tableMetaId) || (schema == null ? void 0 : schema.tableId) || (schema == null ? void 0 : schema.id);
930
936
  if (!targetTableId) {
931
937
  showError("\u05DC\u05D0 \u05E0\u05D9\u05EA\u05DF \u05DC\u05E9\u05DE\u05D5\u05E8: \u05DE\u05D6\u05D4\u05D4 \u05D4\u05D8\u05D1\u05DC\u05D4 \u05D7\u05E1\u05E8 (tableId)", "\u05E9\u05D2\u05D9\u05D0\u05EA \u05E9\u05DE\u05D9\u05E8\u05D4");
932
938
  return;
933
939
  }
940
+ const tempToRealMap = {};
941
+ const realRecordDataMap = {};
934
942
  if (dirty.added.length > 0) {
935
943
  const payload = dirty.added.map((row) => formatPayload(row.data));
936
- await executeAction("CREATE_RECORD", { tableId: targetTableId, tableMetaId: targetTableId, records: payload });
944
+ const res = await executeAction("CREATE_RECORD", { tableId: targetTableId, tableMetaId: targetTableId, records: payload });
945
+ const createdList = Array.isArray(res) ? res : (res == null ? void 0 : res.data) && Array.isArray(res.data) ? res.data : res ? [res] : [];
946
+ if (createdList && createdList.length > 0) {
947
+ dirty.added.forEach((addedRow, idx) => {
948
+ const created = createdList[idx];
949
+ if (created) {
950
+ const realId = String(created.id || created._id || "");
951
+ if (realId) {
952
+ tempToRealMap[addedRow.id] = realId;
953
+ const createdData = created.data && typeof created.data === "object" ? created.data : addedRow.data;
954
+ realRecordDataMap[realId] = __spreadValues(__spreadValues({}, addedRow.data), createdData);
955
+ }
956
+ }
957
+ });
958
+ setData((prev) => prev.map((row) => {
959
+ if (tempToRealMap[row.id]) {
960
+ const realId = tempToRealMap[row.id];
961
+ return __spreadProps(__spreadValues({}, row), {
962
+ id: realId,
963
+ data: realRecordDataMap[realId] || row.data
964
+ });
965
+ }
966
+ return row;
967
+ }));
968
+ setSelectedIds((prev) => {
969
+ let changed = false;
970
+ const next = new Set(prev);
971
+ Object.entries(tempToRealMap).forEach(([tempId, realId]) => {
972
+ if (next.has(tempId)) {
973
+ next.delete(tempId);
974
+ next.add(realId);
975
+ changed = true;
976
+ }
977
+ });
978
+ return changed ? next : prev;
979
+ });
980
+ }
937
981
  }
938
982
  if (Object.keys(dirty.modified).length > 0) {
939
983
  const payload = {};
940
984
  for (const [id, modData] of Object.entries(dirty.modified)) {
941
- payload[id] = formatPayload(modData);
985
+ const targetId = tempToRealMap[id] || id;
986
+ payload[targetId] = formatPayload(modData);
942
987
  }
943
988
  await executeAction("UPDATE_RECORD", { tableId: targetTableId, tableMetaId: targetTableId, modifications: payload });
944
989
  }
@@ -954,10 +999,15 @@ function TableBlockClient({
954
999
  }
955
1000
  setBaseRecordsMap((prev) => {
956
1001
  const next = new Map(prev);
957
- dirty.added.forEach((r) => next.set(r.id, __spreadValues({}, r.data)));
1002
+ dirty.added.forEach((r) => {
1003
+ const realId = tempToRealMap[r.id] || r.id;
1004
+ const dataToStore = realRecordDataMap[realId] || __spreadValues({}, r.data);
1005
+ next.set(realId, dataToStore);
1006
+ });
958
1007
  Object.entries(dirty.modified).forEach(([id, mods]) => {
959
- const existing = next.get(id) || {};
960
- next.set(id, __spreadValues(__spreadValues({}, existing), mods));
1008
+ const realId = tempToRealMap[id] || id;
1009
+ const existing = next.get(realId) || {};
1010
+ next.set(realId, __spreadValues(__spreadValues({}, existing), mods));
961
1011
  });
962
1012
  dirty.deleted.forEach((id) => next.delete(id));
963
1013
  return next;
package/dist/index.mjs CHANGED
@@ -379,16 +379,22 @@ function getRelationDisplayLabel(opt, column) {
379
379
  if (val !== void 0 && val !== null && val !== "") {
380
380
  return String(val);
381
381
  }
382
+ if (opt.label && opt.label !== opt.id) {
383
+ return String(opt.label);
384
+ }
382
385
  if (opt.data) {
383
386
  const fallbackField = Object.keys(opt.data).find((k) => {
384
387
  if (k === "_id" || k === "id") return false;
385
388
  const v = opt.data[k];
386
389
  if (typeof v === "string" && v.trim() !== "") return true;
387
- if (typeof v === "number") return true;
390
+ if (typeof v === "number" && !isNaN(v)) return true;
388
391
  return false;
389
392
  });
390
393
  if (fallbackField) return String(opt.data[fallbackField]);
391
394
  }
395
+ if (opt.label) {
396
+ return String(opt.label);
397
+ }
392
398
  return "\u05E2\u05E8\u05DA \u05E8\u05D9\u05E7";
393
399
  }
394
400
  var FORM_INPUTS = {
@@ -648,7 +654,7 @@ function TableBlockClient({
648
654
  }
649
655
  }, [initialRecords]);
650
656
  useEffect(() => {
651
- const tableId = (schema == null ? void 0 : schema.tableMetaId) || (schema == null ? void 0 : schema.id) || (schema == null ? void 0 : schema.tableId);
657
+ const tableId = (schema == null ? void 0 : schema.tableMetaId) || (schema == null ? void 0 : schema.tableId) || (schema == null ? void 0 : schema.id);
652
658
  if (!tableId || !executeAction) return;
653
659
  if (!(schema == null ? void 0 : schema.columns) || schema.columns.length === 0 || (!initialRecords || initialRecords.length === 0)) {
654
660
  executeAction("FETCH_TABLE_DATA", { tableId }).then((res) => {
@@ -669,7 +675,7 @@ function TableBlockClient({
669
675
  console.error("[TableBlock] Failed to auto-fetch table data:", err);
670
676
  });
671
677
  }
672
- }, [schema == null ? void 0 : schema.tableMetaId, schema == null ? void 0 : schema.id, schema == null ? void 0 : schema.tableId, schema == null ? void 0 : schema.columns, initialRecords, executeAction, mergeWithDirty]);
678
+ }, [schema == null ? void 0 : schema.tableMetaId, schema == null ? void 0 : schema.tableId, schema == null ? void 0 : schema.id, schema == null ? void 0 : schema.columns, initialRecords, executeAction, mergeWithDirty]);
673
679
  useEffect(() => {
674
680
  if (error) {
675
681
  showError(error, "\u05E9\u05D2\u05D9\u05D0\u05D4 \u05D1\u05E8\u05DB\u05D9\u05D1");
@@ -693,7 +699,7 @@ function TableBlockClient({
693
699
  if (!col || ((_a = col.type) == null ? void 0 : _a.toUpperCase()) !== "RELATION" || !col.referencedTableId) return;
694
700
  try {
695
701
  if (executeAction) {
696
- const options = await executeAction("FETCH_RELATION", { referencedTableId: col.referencedTableId });
702
+ const options = await executeAction("FETCH_RELATION", { referencedTableId: col.referencedTableId, displayField: col.displayField });
697
703
  if (options && Array.isArray(options)) {
698
704
  setRelationOptions((prev) => __spreadProps(__spreadValues({}, prev), { [colName]: options }));
699
705
  }
@@ -888,19 +894,58 @@ function TableBlockClient({
888
894
  showError("\u05E8\u05DB\u05D9\u05D1 \u05D4\u05EA\u05E7\u05E9\u05D5\u05E8\u05EA \u05DC\u05D0 \u05D0\u05D5\u05EA\u05D7\u05DC", "\u05E9\u05D2\u05D9\u05D0\u05EA \u05EA\u05E7\u05E9\u05D5\u05E8\u05EA");
889
895
  return;
890
896
  }
891
- const targetTableId = (schema == null ? void 0 : schema.tableMetaId) || (schema == null ? void 0 : schema.id) || (schema == null ? void 0 : schema.tableId);
897
+ const targetTableId = (schema == null ? void 0 : schema.tableMetaId) || (schema == null ? void 0 : schema.tableId) || (schema == null ? void 0 : schema.id);
892
898
  if (!targetTableId) {
893
899
  showError("\u05DC\u05D0 \u05E0\u05D9\u05EA\u05DF \u05DC\u05E9\u05DE\u05D5\u05E8: \u05DE\u05D6\u05D4\u05D4 \u05D4\u05D8\u05D1\u05DC\u05D4 \u05D7\u05E1\u05E8 (tableId)", "\u05E9\u05D2\u05D9\u05D0\u05EA \u05E9\u05DE\u05D9\u05E8\u05D4");
894
900
  return;
895
901
  }
902
+ const tempToRealMap = {};
903
+ const realRecordDataMap = {};
896
904
  if (dirty.added.length > 0) {
897
905
  const payload = dirty.added.map((row) => formatPayload(row.data));
898
- await executeAction("CREATE_RECORD", { tableId: targetTableId, tableMetaId: targetTableId, records: payload });
906
+ const res = await executeAction("CREATE_RECORD", { tableId: targetTableId, tableMetaId: targetTableId, records: payload });
907
+ const createdList = Array.isArray(res) ? res : (res == null ? void 0 : res.data) && Array.isArray(res.data) ? res.data : res ? [res] : [];
908
+ if (createdList && createdList.length > 0) {
909
+ dirty.added.forEach((addedRow, idx) => {
910
+ const created = createdList[idx];
911
+ if (created) {
912
+ const realId = String(created.id || created._id || "");
913
+ if (realId) {
914
+ tempToRealMap[addedRow.id] = realId;
915
+ const createdData = created.data && typeof created.data === "object" ? created.data : addedRow.data;
916
+ realRecordDataMap[realId] = __spreadValues(__spreadValues({}, addedRow.data), createdData);
917
+ }
918
+ }
919
+ });
920
+ setData((prev) => prev.map((row) => {
921
+ if (tempToRealMap[row.id]) {
922
+ const realId = tempToRealMap[row.id];
923
+ return __spreadProps(__spreadValues({}, row), {
924
+ id: realId,
925
+ data: realRecordDataMap[realId] || row.data
926
+ });
927
+ }
928
+ return row;
929
+ }));
930
+ setSelectedIds((prev) => {
931
+ let changed = false;
932
+ const next = new Set(prev);
933
+ Object.entries(tempToRealMap).forEach(([tempId, realId]) => {
934
+ if (next.has(tempId)) {
935
+ next.delete(tempId);
936
+ next.add(realId);
937
+ changed = true;
938
+ }
939
+ });
940
+ return changed ? next : prev;
941
+ });
942
+ }
899
943
  }
900
944
  if (Object.keys(dirty.modified).length > 0) {
901
945
  const payload = {};
902
946
  for (const [id, modData] of Object.entries(dirty.modified)) {
903
- payload[id] = formatPayload(modData);
947
+ const targetId = tempToRealMap[id] || id;
948
+ payload[targetId] = formatPayload(modData);
904
949
  }
905
950
  await executeAction("UPDATE_RECORD", { tableId: targetTableId, tableMetaId: targetTableId, modifications: payload });
906
951
  }
@@ -916,10 +961,15 @@ function TableBlockClient({
916
961
  }
917
962
  setBaseRecordsMap((prev) => {
918
963
  const next = new Map(prev);
919
- dirty.added.forEach((r) => next.set(r.id, __spreadValues({}, r.data)));
964
+ dirty.added.forEach((r) => {
965
+ const realId = tempToRealMap[r.id] || r.id;
966
+ const dataToStore = realRecordDataMap[realId] || __spreadValues({}, r.data);
967
+ next.set(realId, dataToStore);
968
+ });
920
969
  Object.entries(dirty.modified).forEach(([id, mods]) => {
921
- const existing = next.get(id) || {};
922
- next.set(id, __spreadValues(__spreadValues({}, existing), mods));
970
+ const realId = tempToRealMap[id] || id;
971
+ const existing = next.get(realId) || {};
972
+ next.set(realId, __spreadValues(__spreadValues({}, existing), mods));
923
973
  });
924
974
  dirty.deleted.forEach((id) => next.delete(id));
925
975
  return next;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@universe-platform/ui",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.4",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",