@ai-table/state 0.2.3 → 0.2.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/action/field.d.ts +1 -3
- package/action/field.d.ts.map +1 -1
- package/action/index.d.ts +2 -1
- package/action/index.d.ts.map +1 -1
- package/action/position.d.ts +4 -0
- package/action/position.d.ts.map +1 -1
- package/action/record.d.ts.map +1 -1
- package/fesm2022/ai-table-state.mjs +685 -557
- package/fesm2022/ai-table-state.mjs.map +1 -1
- package/package.json +1 -1
- package/utils/field/add-fields.d.ts.map +1 -1
- package/utils/field/move-fields.d.ts.map +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.d.ts.map +1 -1
- package/utils/position-in-view.d.ts +30 -0
- package/utils/position-in-view.d.ts.map +1 -0
- package/utils/position-precision.d.ts +18 -0
- package/utils/position-precision.d.ts.map +1 -0
- package/utils/record/common.d.ts +1 -15
- package/utils/record/common.d.ts.map +1 -1
- package/utils/record/move-records.d.ts +2 -2
- package/utils/record/move-records.d.ts.map +1 -1
@@ -1,9 +1,9 @@
|
|
1
1
|
import * as Y from 'yjs';
|
2
2
|
import { UndoManager } from 'yjs';
|
3
|
-
import { getShareTypeNumberPath, ActionName, translateArrayEvent, getSharedRecordIndex, getSharedMapValueIndex, toMapSyncElement, getIdBySystemFieldValuesType, setRecordUpdatedInfo, getPositionsByRecordSyncElement, setRecordPositions as setRecordPositions$1, toRecordSyncElement, AI_TABLE_CONTENT_FIELD_NAME, getValuesByCustomFieldValues, getPositionsBySystemFieldValues, getTrackableEntityBySystemFieldValues, getShortIdBySystemFieldValues, getIdBySystemFieldValues, AITableFilterLogical, AITableFilterOperation, AITableFieldType, isEmpty, sortByViewPosition,
|
3
|
+
import { getShareTypeNumberPath, ActionName, translateArrayEvent, getSharedRecordIndex, getSharedMapValueIndex, toMapSyncElement, getIdBySystemFieldValuesType, setRecordUpdatedInfo, getPositionsByRecordSyncElement, setRecordPositions as setRecordPositions$1, toRecordSyncElement, AI_TABLE_CONTENT_FIELD_NAME, getValuesByCustomFieldValues, getPositionsBySystemFieldValues, getTrackableEntityBySystemFieldValues, getShortIdBySystemFieldValues, getIdBySystemFieldValues, AITableFilterLogical, AITableFilterOperation, AITableFieldType, isEmpty, sortByViewPosition, idCreator, SortDirection, AI_TABLE_DEFAULT_MIN_UNFROZEN_WIDTH, AI_TABLE_MIN_FROZEN_COLUMN_COUNT } from '@ai-table/utils';
|
4
4
|
import * as i0 from '@angular/core';
|
5
5
|
import { signal, Injectable } from '@angular/core';
|
6
|
-
import { FieldModelMap, AITableQueries, isSystemField, AITableRowType,
|
6
|
+
import { FieldModelMap, AITableQueries, isSystemField, AITableRowType, shortIdCreator, generateNewName, AI_TABLE_GROUP_MAX_LEVEL, idsCreator, shortIdsCreator, closeExpendCell, setSelection, buildNormalLinearRows, AITable, getColumnIndicesSizeMap, AI_TABLE_GRID_FIELD_SERVICE_MAP, clearSelection, buildClipboardData, writeToClipboard, getI18nTextByKey, AITableGridI18nKey, isMac, writeToAITable } from '@ai-table/grid';
|
7
7
|
import { nanoid } from 'nanoid';
|
8
8
|
import * as _ from 'lodash';
|
9
9
|
import ___default, { map, unionBy } from 'lodash';
|
@@ -858,97 +858,6 @@ function getGroupRecordLength(aiTable, recordId, linearRows) {
|
|
858
858
|
return 0;
|
859
859
|
}
|
860
860
|
|
861
|
-
function getFieldPositionInView(viewId, fields, path, newPath) {
|
862
|
-
const targetPosition = fields[newPath[0]].positions[viewId];
|
863
|
-
let newPosition = 0;
|
864
|
-
if (path[0] > newPath[0]) {
|
865
|
-
const prevPath = newPath[0] - 1;
|
866
|
-
if (prevPath >= 0) {
|
867
|
-
const targetPrevField = fields[prevPath];
|
868
|
-
const targetPrevPosition = targetPrevField.positions[viewId];
|
869
|
-
newPosition = (targetPosition + targetPrevPosition) / 2;
|
870
|
-
}
|
871
|
-
else {
|
872
|
-
const firstField = fields[0];
|
873
|
-
newPosition = firstField.positions[viewId] - 0.1;
|
874
|
-
}
|
875
|
-
}
|
876
|
-
else {
|
877
|
-
const nextPath = newPath[0] + 1;
|
878
|
-
if (fields.length > nextPath) {
|
879
|
-
const targetNextField = fields[nextPath];
|
880
|
-
const targetNextPosition = targetNextField.positions[viewId];
|
881
|
-
newPosition = (targetPosition + targetNextPosition) / 2;
|
882
|
-
}
|
883
|
-
else {
|
884
|
-
const lastField = fields[fields.length - 1];
|
885
|
-
const lastPosition = lastField.positions[viewId] + 1;
|
886
|
-
newPosition = (targetPosition + lastPosition) / 2;
|
887
|
-
}
|
888
|
-
}
|
889
|
-
return newPosition;
|
890
|
-
}
|
891
|
-
function getFieldsSizeMap(fields, activeView) {
|
892
|
-
const fieldsSizeMap = {};
|
893
|
-
fields?.forEach((field) => {
|
894
|
-
fieldsSizeMap[field._id] = field.widths?.[activeView._id];
|
895
|
-
});
|
896
|
-
return fieldsSizeMap;
|
897
|
-
}
|
898
|
-
|
899
|
-
var AITableStateI18nKey;
|
900
|
-
(function (AITableStateI18nKey) {
|
901
|
-
AITableStateI18nKey["copyField"] = "copyField";
|
902
|
-
AITableStateI18nKey["removeRecords"] = "removeRecords";
|
903
|
-
AITableStateI18nKey["copy"] = "copy";
|
904
|
-
AITableStateI18nKey["copySuffix"] = "copySuffix";
|
905
|
-
AITableStateI18nKey["paste"] = "paste";
|
906
|
-
AITableStateI18nKey["invalidPasteContent"] = "invalidPasteContent";
|
907
|
-
AITableStateI18nKey["tableView"] = "tableView";
|
908
|
-
AITableStateI18nKey["editField"] = "editField";
|
909
|
-
AITableStateI18nKey["removeField"] = "removeField";
|
910
|
-
AITableStateI18nKey["pasteOverMaxRecords"] = "pasteOverMaxRecords";
|
911
|
-
AITableStateI18nKey["pasteOverMaxFields"] = "pasteOverMaxFields";
|
912
|
-
AITableStateI18nKey["insertUpward"] = "insertUpward";
|
913
|
-
AITableStateI18nKey["insertDownward"] = "insertDownward";
|
914
|
-
AITableStateI18nKey["upward"] = "upward";
|
915
|
-
AITableStateI18nKey["downward"] = "downward";
|
916
|
-
AITableStateI18nKey["freezeToThisColumn"] = "freezeToThisColumn";
|
917
|
-
AITableStateI18nKey["restoreDefaultFrozenColumn"] = "restoreDefaultFrozenColumn";
|
918
|
-
})(AITableStateI18nKey || (AITableStateI18nKey = {}));
|
919
|
-
const AITableStateI18nText = {
|
920
|
-
[AITableStateI18nKey.copyField]: '复制列',
|
921
|
-
[AITableStateI18nKey.removeRecords]: '删除行',
|
922
|
-
[AITableStateI18nKey.copy]: '复制',
|
923
|
-
[AITableStateI18nKey.copySuffix]: '副本',
|
924
|
-
[AITableStateI18nKey.paste]: '粘贴',
|
925
|
-
[AITableStateI18nKey.invalidPasteContent]: '粘贴内容不符合当前类型',
|
926
|
-
[AITableStateI18nKey.tableView]: '表格视图',
|
927
|
-
[AITableStateI18nKey.editField]: '编辑列',
|
928
|
-
[AITableStateI18nKey.removeField]: '删除列',
|
929
|
-
[AITableStateI18nKey.pasteOverMaxRecords]: '粘贴数据超过最大行数',
|
930
|
-
[AITableStateI18nKey.pasteOverMaxFields]: '粘贴数据超过最大列数',
|
931
|
-
[AITableStateI18nKey.insertUpward]: '向上插入',
|
932
|
-
[AITableStateI18nKey.insertDownward]: '向下插入',
|
933
|
-
[AITableStateI18nKey.upward]: '行',
|
934
|
-
[AITableStateI18nKey.downward]: '行',
|
935
|
-
[AITableStateI18nKey.freezeToThisColumn]: '冻结至此列',
|
936
|
-
[AITableStateI18nKey.restoreDefaultFrozenColumn]: '恢复默认冻结列'
|
937
|
-
};
|
938
|
-
const getDefaultI18nTextByKey = (key) => {
|
939
|
-
return AITableStateI18nText[key] || key;
|
940
|
-
};
|
941
|
-
const getStateI18nTextByKey = (aiTable, key) => {
|
942
|
-
if (aiTable.getI18nTextByKey) {
|
943
|
-
const customText = aiTable.getI18nTextByKey(key);
|
944
|
-
if (customText) {
|
945
|
-
return customText;
|
946
|
-
}
|
947
|
-
}
|
948
|
-
const defaultText = getDefaultI18nTextByKey(key);
|
949
|
-
return defaultText;
|
950
|
-
};
|
951
|
-
|
952
861
|
function setView(aiTable, value, path) {
|
953
862
|
const view = aiTable.views().find((item) => item._id === path[0]);
|
954
863
|
if (view) {
|
@@ -1018,159 +927,6 @@ const ViewActions = {
|
|
1018
927
|
setViewFrozenField
|
1019
928
|
};
|
1020
929
|
|
1021
|
-
function getFrozenFieldId(aiTable) {
|
1022
|
-
try {
|
1023
|
-
const viewTable = aiTable;
|
1024
|
-
const activeViewId = viewTable.activeViewId();
|
1025
|
-
const activeView = viewTable.viewsMap()[activeViewId];
|
1026
|
-
return activeView?.settings?.frozen_field_id;
|
1027
|
-
}
|
1028
|
-
catch (error) {
|
1029
|
-
return undefined;
|
1030
|
-
}
|
1031
|
-
}
|
1032
|
-
function calculateAdaptiveFrozenColumnCountCore(config) {
|
1033
|
-
const { containerWidth, rowHeadWidth, visibleFields, columnIndicesSizeMap, frozenFieldId, minUnfrozenWidth = AI_TABLE_DEFAULT_MIN_UNFROZEN_WIDTH } = config;
|
1034
|
-
if (visibleFields.length === 0) {
|
1035
|
-
return AI_TABLE_MIN_FROZEN_COLUMN_COUNT;
|
1036
|
-
}
|
1037
|
-
let targetFrozenCount;
|
1038
|
-
if (frozenFieldId) {
|
1039
|
-
const frozenFieldIndex = visibleFields.findIndex((field) => field._id === frozenFieldId);
|
1040
|
-
if (frozenFieldIndex >= 0) {
|
1041
|
-
targetFrozenCount = frozenFieldIndex + 1;
|
1042
|
-
}
|
1043
|
-
else {
|
1044
|
-
targetFrozenCount = AI_TABLE_MIN_FROZEN_COLUMN_COUNT;
|
1045
|
-
}
|
1046
|
-
}
|
1047
|
-
else {
|
1048
|
-
targetFrozenCount = AI_TABLE_MIN_FROZEN_COLUMN_COUNT;
|
1049
|
-
}
|
1050
|
-
const availableWidth = containerWidth - rowHeadWidth;
|
1051
|
-
const maxFrozenWidth = Math.max(0, availableWidth - minUnfrozenWidth);
|
1052
|
-
let currentFrozenWidth = 0;
|
1053
|
-
let actualFrozenCount = 0;
|
1054
|
-
const maxPossibleCount = Math.min(targetFrozenCount, visibleFields.length);
|
1055
|
-
for (let i = 0; i < maxPossibleCount; i++) {
|
1056
|
-
const fieldWidth = columnIndicesSizeMap[i];
|
1057
|
-
const newFrozenWidth = currentFrozenWidth + fieldWidth;
|
1058
|
-
if (newFrozenWidth > maxFrozenWidth) {
|
1059
|
-
if (i === 0) {
|
1060
|
-
currentFrozenWidth = newFrozenWidth;
|
1061
|
-
actualFrozenCount = AI_TABLE_MIN_FROZEN_COLUMN_COUNT;
|
1062
|
-
}
|
1063
|
-
break;
|
1064
|
-
}
|
1065
|
-
currentFrozenWidth = newFrozenWidth;
|
1066
|
-
actualFrozenCount = i + 1;
|
1067
|
-
}
|
1068
|
-
// 至少有一列冻结
|
1069
|
-
if (actualFrozenCount < AI_TABLE_MIN_FROZEN_COLUMN_COUNT) {
|
1070
|
-
actualFrozenCount = AI_TABLE_MIN_FROZEN_COLUMN_COUNT;
|
1071
|
-
if (visibleFields.length > 0) {
|
1072
|
-
currentFrozenWidth = columnIndicesSizeMap[0];
|
1073
|
-
}
|
1074
|
-
}
|
1075
|
-
return actualFrozenCount;
|
1076
|
-
}
|
1077
|
-
function calculateAdaptiveFrozenColumnCount(aiTable, containerWidth, minUnfrozenWidth = 200) {
|
1078
|
-
try {
|
1079
|
-
if (containerWidth <= 0) {
|
1080
|
-
return AI_TABLE_MIN_FROZEN_COLUMN_COUNT;
|
1081
|
-
}
|
1082
|
-
const frozenFieldId = getFrozenFieldId(aiTable);
|
1083
|
-
const visibleFields = AITable.getVisibleFields(aiTable);
|
1084
|
-
const columnIndicesSizeMap = getColumnIndicesSizeMap(aiTable, visibleFields);
|
1085
|
-
const rowHeadWidth = aiTable.context?.rowHeadWidth?.() || 0;
|
1086
|
-
return calculateAdaptiveFrozenColumnCountCore({
|
1087
|
-
containerWidth,
|
1088
|
-
rowHeadWidth,
|
1089
|
-
visibleFields,
|
1090
|
-
columnIndicesSizeMap,
|
1091
|
-
frozenFieldId,
|
1092
|
-
minUnfrozenWidth
|
1093
|
-
});
|
1094
|
-
}
|
1095
|
-
catch (error) {
|
1096
|
-
return AI_TABLE_MIN_FROZEN_COLUMN_COUNT;
|
1097
|
-
}
|
1098
|
-
}
|
1099
|
-
const freezeToThisColumn = (aiTable) => {
|
1100
|
-
return {
|
1101
|
-
type: 'freezeToThisColumn',
|
1102
|
-
name: getStateI18nTextByKey(aiTable, AITableStateI18nKey.freezeToThisColumn),
|
1103
|
-
icon: 'frozen',
|
1104
|
-
exec: (aiTable, field) => {
|
1105
|
-
const currentField = field();
|
1106
|
-
const viewTable = aiTable;
|
1107
|
-
setViewFrozenField(viewTable, currentField._id);
|
1108
|
-
},
|
1109
|
-
hidden: (aiTable, field) => {
|
1110
|
-
if (aiTable.context?.readonly?.()) {
|
1111
|
-
return true;
|
1112
|
-
}
|
1113
|
-
const currentField = field();
|
1114
|
-
const currentFrozenFieldId = getFrozenFieldId(aiTable);
|
1115
|
-
return currentFrozenFieldId === currentField._id;
|
1116
|
-
},
|
1117
|
-
disabled: (aiTable, field) => {
|
1118
|
-
try {
|
1119
|
-
const currentField = field();
|
1120
|
-
const fields = aiTable.gridData().fields;
|
1121
|
-
const currentFieldIndex = fields.findIndex((f) => f._id === currentField._id);
|
1122
|
-
const visibleFields = AITable.getVisibleFields(aiTable);
|
1123
|
-
const columnIndicesSizeMap = getColumnIndicesSizeMap(aiTable, visibleFields);
|
1124
|
-
const containerWidth = aiTable.context?.containerRect()?.width || 0;
|
1125
|
-
const rowHeadWidth = aiTable.context?.rowHeadWidth?.() || 0;
|
1126
|
-
const actualFrozenCount = calculateAdaptiveFrozenColumnCountCore({
|
1127
|
-
containerWidth,
|
1128
|
-
rowHeadWidth,
|
1129
|
-
visibleFields,
|
1130
|
-
columnIndicesSizeMap,
|
1131
|
-
frozenFieldId: currentField._id,
|
1132
|
-
minUnfrozenWidth: AI_TABLE_DEFAULT_MIN_UNFROZEN_WIDTH
|
1133
|
-
});
|
1134
|
-
if (actualFrozenCount < currentFieldIndex + 1) {
|
1135
|
-
// 超过可视区域禁用
|
1136
|
-
return true;
|
1137
|
-
}
|
1138
|
-
const currentFrozenFieldId = getFrozenFieldId(aiTable);
|
1139
|
-
if (!currentFrozenFieldId && currentFieldIndex === 0) {
|
1140
|
-
// 默认第一列冻结列禁用
|
1141
|
-
return true;
|
1142
|
-
}
|
1143
|
-
return false;
|
1144
|
-
}
|
1145
|
-
catch (error) {
|
1146
|
-
return false;
|
1147
|
-
}
|
1148
|
-
}
|
1149
|
-
};
|
1150
|
-
};
|
1151
|
-
const restoreDefaultFrozenColumn = (aiTable) => {
|
1152
|
-
return {
|
1153
|
-
type: 'restoreDefaultFrozenColumn',
|
1154
|
-
name: getStateI18nTextByKey(aiTable, AITableStateI18nKey.restoreDefaultFrozenColumn),
|
1155
|
-
icon: 'frozen',
|
1156
|
-
exec: (aiTable, field) => {
|
1157
|
-
const viewTable = aiTable;
|
1158
|
-
setViewFrozenField(viewTable, undefined);
|
1159
|
-
},
|
1160
|
-
hidden: (aiTable, field) => {
|
1161
|
-
if (aiTable.context?.readonly?.()) {
|
1162
|
-
return true;
|
1163
|
-
}
|
1164
|
-
const currentField = field();
|
1165
|
-
const currentFrozenFieldId = getFrozenFieldId(aiTable);
|
1166
|
-
if (!currentFrozenFieldId) {
|
1167
|
-
return true;
|
1168
|
-
}
|
1169
|
-
return currentField._id !== currentFrozenFieldId;
|
1170
|
-
}
|
1171
|
-
};
|
1172
|
-
};
|
1173
|
-
|
1174
930
|
function addField(aiTable, field, originId, isDuplicate) {
|
1175
931
|
const operation = {
|
1176
932
|
type: ActionName.AddField,
|
@@ -1187,18 +943,6 @@ function addField(aiTable, field, originId, isDuplicate) {
|
|
1187
943
|
}
|
1188
944
|
aiTable.apply(operation);
|
1189
945
|
}
|
1190
|
-
function moveField(aiTable, path, newPath) {
|
1191
|
-
if (isPathEqual(path, newPath)) {
|
1192
|
-
return;
|
1193
|
-
}
|
1194
|
-
const fields = aiTable.gridData().fields;
|
1195
|
-
const activeView = aiTable.views().find((item) => item._id === aiTable.activeViewId());
|
1196
|
-
const sourceField = fields[path[0]];
|
1197
|
-
const currentFrozenFieldId = getFrozenFieldId(aiTable);
|
1198
|
-
adjustFrozenFieldAfterMove(aiTable, path[0], newPath[0], currentFrozenFieldId);
|
1199
|
-
const position = getFieldPositionInView(activeView._id, fields, path, newPath);
|
1200
|
-
setField(aiTable, { positions: { ...sourceField.positions, [activeView._id]: position } }, [sourceField._id]);
|
1201
|
-
}
|
1202
946
|
function adjustFrozenFieldAfterMove(aiTable, sourceIndex, targetIndex, currentFrozenFieldId) {
|
1203
947
|
if (!currentFrozenFieldId) {
|
1204
948
|
return;
|
@@ -1277,7 +1021,6 @@ function setField(aiTable, value, path) {
|
|
1277
1021
|
}
|
1278
1022
|
const FieldActions = {
|
1279
1023
|
addField,
|
1280
|
-
moveField,
|
1281
1024
|
removeField,
|
1282
1025
|
setField,
|
1283
1026
|
setFieldWidth,
|
@@ -1450,207 +1193,149 @@ function buildSetRecordPositionsActon(aiTable, positions, path) {
|
|
1450
1193
|
};
|
1451
1194
|
return action;
|
1452
1195
|
}
|
1453
|
-
function
|
1454
|
-
const
|
1455
|
-
aiTable.
|
1456
|
-
|
1457
|
-
const
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
const field = AITableQueries.getField(aiTable, [option.path[1]]);
|
1465
|
-
const fieldModel = field && FieldModelMap[field.type];
|
1466
|
-
if (fieldModel && fieldModel.isValid(option.value)) {
|
1467
|
-
const operation = {
|
1468
|
-
type: ActionName.UpdateFieldValue,
|
1469
|
-
newFieldValue: option.value,
|
1470
|
-
path: option.path
|
1471
|
-
};
|
1472
|
-
operations.push(operation);
|
1473
|
-
}
|
1474
|
-
else {
|
1475
|
-
console.error(`Invalid field value at update field value. invalidFieldType: ${field?.type}, value: ${option.value}, field_id: ${option.path[1]}`);
|
1476
|
-
}
|
1477
|
-
});
|
1478
|
-
aiTable.apply(operations);
|
1479
|
-
}
|
1480
|
-
function updateSystemFieldValues(aiTable, options) {
|
1481
|
-
const operations = [];
|
1482
|
-
(options || []).forEach((option) => {
|
1483
|
-
const operation = {
|
1484
|
-
type: ActionName.UpdateSystemFieldValue,
|
1485
|
-
updatedInfo: option.updatedInfo,
|
1486
|
-
path: option.path
|
1487
|
-
};
|
1488
|
-
operations.push(operation);
|
1196
|
+
function resetAllRecordsPositions(aiTable) {
|
1197
|
+
const activeViewId = aiTable.activeViewId();
|
1198
|
+
const activeView = aiTable.views().find((view) => view._id === activeViewId);
|
1199
|
+
const records = aiTable.records();
|
1200
|
+
const recordsIndexMap = new Map(records.map((item, index) => [item._id, index]));
|
1201
|
+
const sortedRecords = sortRecordsByConditions(aiTable, records, activeView, []);
|
1202
|
+
const actions = [];
|
1203
|
+
const positions = insertAtEnd(0, sortedRecords.length);
|
1204
|
+
sortedRecords.forEach((record, index) => {
|
1205
|
+
const action = buildSetRecordPositionsActon(aiTable, { [activeView._id]: positions[index] }, [recordsIndexMap.get(record._id)]);
|
1206
|
+
actions.push(action);
|
1489
1207
|
});
|
1490
|
-
aiTable.apply(
|
1491
|
-
}
|
1492
|
-
function addRecord(aiTable, record) {
|
1493
|
-
addRecords$1(aiTable, [record]);
|
1208
|
+
aiTable.apply(actions);
|
1494
1209
|
}
|
1495
|
-
function
|
1496
|
-
const
|
1497
|
-
const
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
});
|
1508
|
-
});
|
1509
|
-
if (invalidFieldValues.length) {
|
1510
|
-
console.error(`Invalid field values at add records. invalidFieldValues: ${invalidFieldValues}`);
|
1511
|
-
return;
|
1512
|
-
}
|
1513
|
-
records.forEach((record, index) => {
|
1514
|
-
record.positions = positions[index];
|
1515
|
-
const operation = {
|
1516
|
-
type: ActionName.AddRecord,
|
1517
|
-
record
|
1518
|
-
};
|
1519
|
-
aiTable.apply(operation);
|
1210
|
+
function resetAllFieldsPositions(aiTable) {
|
1211
|
+
const activeViewId = aiTable.activeViewId();
|
1212
|
+
const activeView = aiTable.views().find((view) => view._id === activeViewId);
|
1213
|
+
const fields = aiTable.fields();
|
1214
|
+
const sortedFields = getSortFields(aiTable, fields, activeView);
|
1215
|
+
const actions = [];
|
1216
|
+
const positions = insertAtEnd(0, sortedFields.length);
|
1217
|
+
sortedFields.forEach((item, index) => {
|
1218
|
+
const action = buildSetFieldAction(aiTable, { positions: { ...item.positions, [activeView._id]: positions[index] } }, [item._id]);
|
1219
|
+
if (action) {
|
1220
|
+
actions.push(action);
|
1221
|
+
}
|
1520
1222
|
});
|
1223
|
+
aiTable.apply(actions);
|
1521
1224
|
}
|
1522
|
-
function
|
1523
|
-
const operation =
|
1524
|
-
type: ActionName.RemoveRecord,
|
1525
|
-
path
|
1526
|
-
};
|
1225
|
+
function setRecordPositions(aiTable, positions, path) {
|
1226
|
+
const operation = buildSetRecordPositionsActon(aiTable, positions, path);
|
1527
1227
|
aiTable.apply(operation);
|
1528
1228
|
}
|
1529
|
-
const
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
updateFieldValues: updateFieldValues$1,
|
1534
|
-
updateSystemFieldValues
|
1229
|
+
const PositionsActions = {
|
1230
|
+
setRecordPositions,
|
1231
|
+
resetAllRecordsPositions,
|
1232
|
+
resetAllFieldsPositions
|
1535
1233
|
};
|
1536
1234
|
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
groups: groups || [],
|
1546
|
-
collapsed_group_ids: [] // 重置折叠
|
1547
|
-
};
|
1548
|
-
const operation = {
|
1549
|
-
type: ActionName.SetView,
|
1550
|
-
properties: { settings: currentSettings },
|
1551
|
-
newProperties: { settings: newSettings },
|
1552
|
-
path: [viewId]
|
1553
|
-
};
|
1554
|
-
aiTable.apply(operation);
|
1555
|
-
}
|
1556
|
-
function setCollapsedGroup(aiTable, collapsedGroupIds) {
|
1557
|
-
const viewId = aiTable.activeViewId();
|
1558
|
-
const view = aiTable.views().find((v) => v._id === viewId);
|
1559
|
-
if (!view)
|
1560
|
-
return;
|
1561
|
-
const currentSettings = view.settings || {};
|
1562
|
-
const newSettings = {
|
1563
|
-
...currentSettings,
|
1564
|
-
collapsed_group_ids: collapsedGroupIds
|
1565
|
-
};
|
1566
|
-
const operation = {
|
1567
|
-
type: ActionName.SetView,
|
1568
|
-
properties: { settings: currentSettings },
|
1569
|
-
newProperties: { settings: newSettings },
|
1570
|
-
path: [viewId]
|
1571
|
-
};
|
1572
|
-
aiTable.apply(operation);
|
1235
|
+
const DEFAULT_INITIAL_GAP = 65536;
|
1236
|
+
const DEFAULT_PRECISION_THRESHOLD = 1;
|
1237
|
+
function insertAtStart(firstPosition, count = 1, initialGap = DEFAULT_INITIAL_GAP) {
|
1238
|
+
const positions = [];
|
1239
|
+
for (let i = 0; i < count; i++) {
|
1240
|
+
positions.push(firstPosition - (count - i) * initialGap);
|
1241
|
+
}
|
1242
|
+
return positions;
|
1573
1243
|
}
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
const newCollapse = currentCollapse.includes(groupId) ? currentCollapse.filter((id) => id !== groupId) : [...currentCollapse, groupId];
|
1581
|
-
setCollapsedGroup(aiTable, newCollapse);
|
1244
|
+
function insertAtEnd(lastPosition, count = 1, initialGap = DEFAULT_INITIAL_GAP) {
|
1245
|
+
const positions = [];
|
1246
|
+
for (let i = 0; i < count; i++) {
|
1247
|
+
positions.push(lastPosition + (i + 1) * initialGap);
|
1248
|
+
}
|
1249
|
+
return positions;
|
1582
1250
|
}
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1251
|
+
function insertBetween(prevPosition, nextPosition, count = 1, precisionThreshold = DEFAULT_PRECISION_THRESHOLD) {
|
1252
|
+
const gap = nextPosition - prevPosition;
|
1253
|
+
if (gap <= 0) {
|
1254
|
+
return {
|
1255
|
+
success: false,
|
1256
|
+
positions: [],
|
1257
|
+
needsReorganization: true,
|
1258
|
+
reason: `Invalid gap: ${gap}, previous position ${prevPosition} must be less than next position ${nextPosition}`
|
1259
|
+
};
|
1592
1260
|
}
|
1593
|
-
|
1594
|
-
if (
|
1595
|
-
|
1261
|
+
const subGap = gap / (count + 1);
|
1262
|
+
if (subGap < precisionThreshold) {
|
1263
|
+
return {
|
1264
|
+
success: false,
|
1265
|
+
positions: [],
|
1266
|
+
needsReorganization: true,
|
1267
|
+
reason: `Insufficient precision: current gap ${subGap}, but threshold is ${precisionThreshold}`
|
1268
|
+
};
|
1596
1269
|
}
|
1597
|
-
const
|
1598
|
-
|
1599
|
-
|
1600
|
-
// 删除分组
|
1601
|
-
function removeGroupField(aiTable, fieldId) {
|
1602
|
-
const view = aiTable.views().find((v) => v._id === aiTable.activeViewId());
|
1603
|
-
if (!view)
|
1604
|
-
return;
|
1605
|
-
const currentGroups = view.settings?.groups || [];
|
1606
|
-
const newGroups = currentGroups.filter((group) => group.field_id !== fieldId);
|
1607
|
-
setViewGroup(aiTable, newGroups.length > 0 ? newGroups : null);
|
1608
|
-
}
|
1609
|
-
// 更新排序方向
|
1610
|
-
function updateGroupFieldDirection(aiTable, fieldId, direction) {
|
1611
|
-
const view = aiTable.views().find((v) => v._id === aiTable.activeViewId());
|
1612
|
-
if (!view)
|
1613
|
-
return;
|
1614
|
-
const currentGroups = view.settings?.groups || [];
|
1615
|
-
const newGroups = currentGroups.map((group) => (group.field_id === fieldId ? { ...group, direction } : group));
|
1616
|
-
setViewGroup(aiTable, newGroups);
|
1617
|
-
}
|
1618
|
-
// 重新排序,拖拽顺序
|
1619
|
-
function reorderGroupFields(aiTable, fromIndex, toIndex) {
|
1620
|
-
const view = aiTable.views().find((v) => v._id === aiTable.activeViewId());
|
1621
|
-
if (!view)
|
1622
|
-
return;
|
1623
|
-
const currentGroups = view.settings?.groups || [];
|
1624
|
-
if (fromIndex < 0 || fromIndex >= currentGroups.length || toIndex < 0 || toIndex >= currentGroups.length) {
|
1625
|
-
return;
|
1270
|
+
const positions = [];
|
1271
|
+
for (let i = 0; i < count; i++) {
|
1272
|
+
positions.push(prevPosition + (i + 1) * subGap);
|
1626
1273
|
}
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1274
|
+
return {
|
1275
|
+
success: true,
|
1276
|
+
positions,
|
1277
|
+
needsReorganization: false,
|
1278
|
+
context: {
|
1279
|
+
prevPosition,
|
1280
|
+
nextPosition,
|
1281
|
+
availableGap: gap,
|
1282
|
+
subGap,
|
1283
|
+
requestedCount: count
|
1284
|
+
}
|
1285
|
+
};
|
1635
1286
|
}
|
1636
|
-
const GroupActions = {
|
1637
|
-
setViewGroup,
|
1638
|
-
setCollapsedGroup,
|
1639
|
-
toggleGroupCollapse,
|
1640
|
-
addGroupField,
|
1641
|
-
removeGroupField,
|
1642
|
-
updateGroupFieldDirection,
|
1643
|
-
reorderGroupFields,
|
1644
|
-
clearAllGroups
|
1645
|
-
};
|
1646
1287
|
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1288
|
+
var AITableStateI18nKey;
|
1289
|
+
(function (AITableStateI18nKey) {
|
1290
|
+
AITableStateI18nKey["copyField"] = "copyField";
|
1291
|
+
AITableStateI18nKey["removeRecords"] = "removeRecords";
|
1292
|
+
AITableStateI18nKey["copy"] = "copy";
|
1293
|
+
AITableStateI18nKey["copySuffix"] = "copySuffix";
|
1294
|
+
AITableStateI18nKey["paste"] = "paste";
|
1295
|
+
AITableStateI18nKey["invalidPasteContent"] = "invalidPasteContent";
|
1296
|
+
AITableStateI18nKey["tableView"] = "tableView";
|
1297
|
+
AITableStateI18nKey["editField"] = "editField";
|
1298
|
+
AITableStateI18nKey["removeField"] = "removeField";
|
1299
|
+
AITableStateI18nKey["pasteOverMaxRecords"] = "pasteOverMaxRecords";
|
1300
|
+
AITableStateI18nKey["pasteOverMaxFields"] = "pasteOverMaxFields";
|
1301
|
+
AITableStateI18nKey["insertUpward"] = "insertUpward";
|
1302
|
+
AITableStateI18nKey["insertDownward"] = "insertDownward";
|
1303
|
+
AITableStateI18nKey["upward"] = "upward";
|
1304
|
+
AITableStateI18nKey["downward"] = "downward";
|
1305
|
+
AITableStateI18nKey["freezeToThisColumn"] = "freezeToThisColumn";
|
1306
|
+
AITableStateI18nKey["restoreDefaultFrozenColumn"] = "restoreDefaultFrozenColumn";
|
1307
|
+
})(AITableStateI18nKey || (AITableStateI18nKey = {}));
|
1308
|
+
const AITableStateI18nText = {
|
1309
|
+
[AITableStateI18nKey.copyField]: '复制列',
|
1310
|
+
[AITableStateI18nKey.removeRecords]: '删除行',
|
1311
|
+
[AITableStateI18nKey.copy]: '复制',
|
1312
|
+
[AITableStateI18nKey.copySuffix]: '副本',
|
1313
|
+
[AITableStateI18nKey.paste]: '粘贴',
|
1314
|
+
[AITableStateI18nKey.invalidPasteContent]: '粘贴内容不符合当前类型',
|
1315
|
+
[AITableStateI18nKey.tableView]: '表格视图',
|
1316
|
+
[AITableStateI18nKey.editField]: '编辑列',
|
1317
|
+
[AITableStateI18nKey.removeField]: '删除列',
|
1318
|
+
[AITableStateI18nKey.pasteOverMaxRecords]: '粘贴数据超过最大行数',
|
1319
|
+
[AITableStateI18nKey.pasteOverMaxFields]: '粘贴数据超过最大列数',
|
1320
|
+
[AITableStateI18nKey.insertUpward]: '向上插入',
|
1321
|
+
[AITableStateI18nKey.insertDownward]: '向下插入',
|
1322
|
+
[AITableStateI18nKey.upward]: '行',
|
1323
|
+
[AITableStateI18nKey.downward]: '行',
|
1324
|
+
[AITableStateI18nKey.freezeToThisColumn]: '冻结至此列',
|
1325
|
+
[AITableStateI18nKey.restoreDefaultFrozenColumn]: '恢复默认冻结列'
|
1326
|
+
};
|
1327
|
+
const getDefaultI18nTextByKey = (key) => {
|
1328
|
+
return AITableStateI18nText[key] || key;
|
1329
|
+
};
|
1330
|
+
const getStateI18nTextByKey = (aiTable, key) => {
|
1331
|
+
if (aiTable.getI18nTextByKey) {
|
1332
|
+
const customText = aiTable.getI18nTextByKey(key);
|
1333
|
+
if (customText) {
|
1334
|
+
return customText;
|
1335
|
+
}
|
1336
|
+
}
|
1337
|
+
const defaultText = getDefaultI18nTextByKey(key);
|
1338
|
+
return defaultText;
|
1654
1339
|
};
|
1655
1340
|
|
1656
1341
|
function isPathEqual(path, another) {
|
@@ -1720,7 +1405,7 @@ function getMaxPosition(data, activeViewId) {
|
|
1720
1405
|
maxPosition = item.positions[activeViewId];
|
1721
1406
|
}
|
1722
1407
|
return maxPosition;
|
1723
|
-
},
|
1408
|
+
}, Number.MIN_SAFE_INTEGER);
|
1724
1409
|
}
|
1725
1410
|
function addView(aiTable, type, viewId) {
|
1726
1411
|
const newId = idCreator();
|
@@ -1789,115 +1474,335 @@ function sortViews(data) {
|
|
1789
1474
|
return [...data].sort((a, b) => (a.position ?? data.indexOf(a)) - (b.position ?? data.indexOf(b)));
|
1790
1475
|
}
|
1791
1476
|
|
1792
|
-
function
|
1477
|
+
function findNextItemByPosition(aiTable, targetId, items, itemsMap) {
|
1793
1478
|
const viewId = aiTable.activeViewId();
|
1794
|
-
const
|
1795
|
-
const
|
1796
|
-
|
1797
|
-
const
|
1798
|
-
|
1799
|
-
|
1800
|
-
|
1801
|
-
// 找到所有position大于目标position的记录中最小的
|
1802
|
-
if (pos > targetPosition && (nextRecord === null || pos < nextRecord.positions[viewId])) {
|
1803
|
-
nextRecord = record;
|
1479
|
+
const targetItem = itemsMap[targetId];
|
1480
|
+
const targetPosition = targetItem.positions[viewId] || 0;
|
1481
|
+
let nextItem = null;
|
1482
|
+
for (const item of items) {
|
1483
|
+
const pos = item.positions[viewId] || 0;
|
1484
|
+
if (pos > targetPosition && (nextItem === null || pos < nextItem.positions[viewId])) {
|
1485
|
+
nextItem = item;
|
1804
1486
|
}
|
1805
1487
|
}
|
1806
|
-
return
|
1488
|
+
return nextItem;
|
1807
1489
|
}
|
1808
|
-
function
|
1490
|
+
function findMaxItemByPosition(aiTable, items) {
|
1809
1491
|
const viewId = aiTable.activeViewId();
|
1810
|
-
|
1811
|
-
const
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1818
|
-
|
1819
|
-
|
1492
|
+
let maxItem = items[0];
|
1493
|
+
for (const item of items) {
|
1494
|
+
const pos = item.positions[viewId] || 0;
|
1495
|
+
if (pos > maxItem.positions[viewId]) {
|
1496
|
+
maxItem = item;
|
1497
|
+
}
|
1498
|
+
}
|
1499
|
+
return maxItem;
|
1500
|
+
}
|
1501
|
+
function findPrevItemByPosition(aiTable, targetId, items, itemsMap) {
|
1502
|
+
const viewId = aiTable.activeViewId();
|
1503
|
+
const targetItem = itemsMap[targetId];
|
1504
|
+
const targetPosition = targetItem.positions[viewId] || 0;
|
1505
|
+
let prevItem = null;
|
1506
|
+
for (const item of items) {
|
1507
|
+
const pos = item.positions[viewId] || 0;
|
1508
|
+
if (pos < targetPosition && (prevItem === null || pos > prevItem.positions[viewId])) {
|
1509
|
+
prevItem = item;
|
1820
1510
|
}
|
1821
1511
|
}
|
1822
|
-
return
|
1512
|
+
return prevItem;
|
1823
1513
|
}
|
1824
|
-
function
|
1825
|
-
const recordsMap = aiTable.recordsMap();
|
1514
|
+
function getPreviousAndNextPosition(aiTable, options, items, itemsMap) {
|
1826
1515
|
const activeViewId = aiTable.activeViewId();
|
1827
|
-
const
|
1828
|
-
|
1829
|
-
let
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
if (!targetRecord) {
|
1835
|
-
throw new Error(`Target record with id ${afterRecordId} not found`);
|
1836
|
-
}
|
1837
|
-
prevPosition = targetRecord.positions[activeViewId] || 0;
|
1838
|
-
const nextPosition = findNextRecordForTargetInOriginalRecords(aiTable, afterRecordId);
|
1839
|
-
if (nextPosition !== null) {
|
1840
|
-
targetPosition = nextPosition.positions[activeViewId] || 0;
|
1516
|
+
const { afterItemId, beforeItemId } = options;
|
1517
|
+
let nextPosition = null;
|
1518
|
+
let previousPosition = null;
|
1519
|
+
if (afterItemId) {
|
1520
|
+
const previousItem = itemsMap[afterItemId];
|
1521
|
+
if (!previousItem) {
|
1522
|
+
throw new Error(`Target item with id ${afterItemId} not found`);
|
1841
1523
|
}
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1524
|
+
previousPosition = previousItem.positions[activeViewId] || 0;
|
1525
|
+
const nextItem = findNextItemByPosition(aiTable, afterItemId, items, itemsMap);
|
1526
|
+
if (nextItem !== null) {
|
1527
|
+
nextPosition = nextItem.positions[activeViewId] || 0;
|
1845
1528
|
}
|
1846
1529
|
}
|
1847
|
-
else if (
|
1848
|
-
|
1849
|
-
|
1850
|
-
|
1851
|
-
throw new Error(`Target record with id ${beforeRecordId} not found`);
|
1530
|
+
else if (beforeItemId) {
|
1531
|
+
const nextItem = itemsMap[beforeItemId];
|
1532
|
+
if (!nextItem) {
|
1533
|
+
throw new Error(`Target item with id ${beforeItemId} not found`);
|
1852
1534
|
}
|
1853
|
-
|
1854
|
-
const
|
1855
|
-
if (
|
1856
|
-
|
1857
|
-
}
|
1858
|
-
else {
|
1859
|
-
// 第一个
|
1860
|
-
prevPosition = targetPosition - 1;
|
1535
|
+
nextPosition = nextItem.positions[activeViewId] || 0;
|
1536
|
+
const previousItem = findPrevItemByPosition(aiTable, beforeItemId, items, itemsMap);
|
1537
|
+
if (previousItem !== null) {
|
1538
|
+
previousPosition = previousItem.positions[activeViewId] || 0;
|
1861
1539
|
}
|
1862
1540
|
}
|
1863
1541
|
else {
|
1864
|
-
|
1542
|
+
const maxItem = findMaxItemByPosition(aiTable, items);
|
1543
|
+
previousPosition = maxItem.positions[activeViewId] || 0;
|
1865
1544
|
}
|
1866
1545
|
return {
|
1867
|
-
|
1868
|
-
|
1546
|
+
nextPosition,
|
1547
|
+
previousPosition
|
1548
|
+
};
|
1549
|
+
}
|
1550
|
+
function getCurrentViewPositions(aiTable, options, items, itemsMap) {
|
1551
|
+
const { previousPosition, nextPosition } = getPreviousAndNextPosition(aiTable, options, items, itemsMap);
|
1552
|
+
const count = options.count || 1;
|
1553
|
+
let positions = [];
|
1554
|
+
if (options.beforeItemId && previousPosition === null && nextPosition !== null) {
|
1555
|
+
positions = insertAtStart(nextPosition, count);
|
1556
|
+
}
|
1557
|
+
else if (options.afterItemId && nextPosition === null && previousPosition !== null) {
|
1558
|
+
positions = insertAtEnd(previousPosition, count);
|
1559
|
+
}
|
1560
|
+
else if (!options.afterItemId && !options.beforeItemId && nextPosition === null && previousPosition !== null) {
|
1561
|
+
positions = insertAtEnd(previousPosition, count);
|
1562
|
+
}
|
1563
|
+
else {
|
1564
|
+
const result = insertBetween(previousPosition, nextPosition, count);
|
1565
|
+
positions = result.positions;
|
1566
|
+
if (result.reason) {
|
1567
|
+
console.log(result.reason);
|
1568
|
+
}
|
1569
|
+
}
|
1570
|
+
return positions;
|
1571
|
+
}
|
1572
|
+
function getNewItemsPosition(aiTable, options, items, itemsMap) {
|
1573
|
+
let positions = getCurrentViewPositions(aiTable, options, items, itemsMap);
|
1574
|
+
if (positions.length === 0) {
|
1575
|
+
return [];
|
1576
|
+
}
|
1577
|
+
const views = aiTable.views();
|
1578
|
+
const activeViewId = aiTable.activeViewId();
|
1579
|
+
const viewsMaxPosition = {};
|
1580
|
+
views.forEach((view) => {
|
1581
|
+
viewsMaxPosition[view._id] = getMaxPosition(items, view._id);
|
1582
|
+
});
|
1583
|
+
const viewPositions = positions.map((itemPosition) => {
|
1584
|
+
const viewPositions = {};
|
1585
|
+
views.forEach((view) => {
|
1586
|
+
if (view._id === activeViewId) {
|
1587
|
+
viewPositions[view._id] = itemPosition;
|
1588
|
+
}
|
1589
|
+
else {
|
1590
|
+
const maxPosition = viewsMaxPosition[view._id];
|
1591
|
+
const newMaxPosition = insertAtEnd(maxPosition, 1);
|
1592
|
+
viewsMaxPosition[view._id] += newMaxPosition[0];
|
1593
|
+
viewPositions[view._id] = viewsMaxPosition[view._id];
|
1594
|
+
}
|
1595
|
+
});
|
1596
|
+
return viewPositions;
|
1597
|
+
});
|
1598
|
+
return viewPositions;
|
1599
|
+
}
|
1600
|
+
|
1601
|
+
function updateFieldValues$1(aiTable, options) {
|
1602
|
+
let operations = [];
|
1603
|
+
(options || []).forEach((option) => {
|
1604
|
+
const field = AITableQueries.getField(aiTable, [option.path[1]]);
|
1605
|
+
const fieldModel = field && FieldModelMap[field.type];
|
1606
|
+
if (fieldModel && fieldModel.isValid(option.value)) {
|
1607
|
+
const operation = {
|
1608
|
+
type: ActionName.UpdateFieldValue,
|
1609
|
+
newFieldValue: option.value,
|
1610
|
+
path: option.path
|
1611
|
+
};
|
1612
|
+
operations.push(operation);
|
1613
|
+
}
|
1614
|
+
else {
|
1615
|
+
console.error(`Invalid field value at update field value. invalidFieldType: ${field?.type}, value: ${option.value}, field_id: ${option.path[1]}`);
|
1616
|
+
}
|
1617
|
+
});
|
1618
|
+
aiTable.apply(operations);
|
1619
|
+
}
|
1620
|
+
function updateSystemFieldValues(aiTable, options) {
|
1621
|
+
const operations = [];
|
1622
|
+
(options || []).forEach((option) => {
|
1623
|
+
const operation = {
|
1624
|
+
type: ActionName.UpdateSystemFieldValue,
|
1625
|
+
updatedInfo: option.updatedInfo,
|
1626
|
+
path: option.path
|
1627
|
+
};
|
1628
|
+
operations.push(operation);
|
1629
|
+
});
|
1630
|
+
aiTable.apply(operations);
|
1631
|
+
}
|
1632
|
+
function addRecord(aiTable, record) {
|
1633
|
+
addRecords$1(aiTable, [record]);
|
1634
|
+
}
|
1635
|
+
function addRecords$1(aiTable, records, options) {
|
1636
|
+
const invalidFieldValues = [];
|
1637
|
+
const viewPositionOptions = {
|
1638
|
+
afterItemId: options?.afterRecordId,
|
1639
|
+
beforeItemId: options?.beforeRecordId,
|
1640
|
+
count: options?.count
|
1641
|
+
};
|
1642
|
+
let positions = getNewItemsPosition(aiTable, viewPositionOptions, aiTable.records(), aiTable.recordsMap());
|
1643
|
+
if (positions.length === 0) {
|
1644
|
+
PositionsActions.resetAllRecordsPositions(aiTable);
|
1645
|
+
positions = getNewItemsPosition(aiTable, viewPositionOptions, aiTable.records(), aiTable.recordsMap());
|
1646
|
+
console.log('Reset all records positions');
|
1647
|
+
}
|
1648
|
+
records.forEach((record, index) => {
|
1649
|
+
Object.entries(record.values).every(([fieldId, value]) => {
|
1650
|
+
const field = AITableQueries.getField(aiTable, [fieldId]);
|
1651
|
+
const fieldModel = field && FieldModelMap[field.type];
|
1652
|
+
const result = fieldModel ? fieldModel.isValid(value) : false;
|
1653
|
+
if (!result) {
|
1654
|
+
invalidFieldValues.push(`field_id: ${fieldId}, field_type: ${field?.type}, value: ${value}`);
|
1655
|
+
}
|
1656
|
+
return result;
|
1657
|
+
});
|
1658
|
+
});
|
1659
|
+
if (invalidFieldValues.length) {
|
1660
|
+
console.error(`Invalid field values at add records. invalidFieldValues: ${invalidFieldValues}`);
|
1661
|
+
return;
|
1662
|
+
}
|
1663
|
+
records.forEach((record, index) => {
|
1664
|
+
record.positions = positions[index];
|
1665
|
+
const operation = {
|
1666
|
+
type: ActionName.AddRecord,
|
1667
|
+
record
|
1668
|
+
};
|
1669
|
+
aiTable.apply(operation);
|
1670
|
+
});
|
1671
|
+
}
|
1672
|
+
function removeRecord(aiTable, path) {
|
1673
|
+
const operation = {
|
1674
|
+
type: ActionName.RemoveRecord,
|
1675
|
+
path
|
1676
|
+
};
|
1677
|
+
aiTable.apply(operation);
|
1678
|
+
}
|
1679
|
+
const RecordActions = {
|
1680
|
+
addRecord,
|
1681
|
+
addRecords: addRecords$1,
|
1682
|
+
removeRecord,
|
1683
|
+
updateFieldValues: updateFieldValues$1,
|
1684
|
+
updateSystemFieldValues
|
1685
|
+
};
|
1686
|
+
|
1687
|
+
function setViewGroup(aiTable, groups) {
|
1688
|
+
const viewId = aiTable.activeViewId();
|
1689
|
+
const view = aiTable.views().find((v) => v._id === viewId);
|
1690
|
+
if (!view)
|
1691
|
+
return;
|
1692
|
+
const currentSettings = view.settings || {};
|
1693
|
+
const newSettings = {
|
1694
|
+
...currentSettings,
|
1695
|
+
groups: groups || [],
|
1696
|
+
collapsed_group_ids: [] // 重置折叠
|
1697
|
+
};
|
1698
|
+
const operation = {
|
1699
|
+
type: ActionName.SetView,
|
1700
|
+
properties: { settings: currentSettings },
|
1701
|
+
newProperties: { settings: newSettings },
|
1702
|
+
path: [viewId]
|
1703
|
+
};
|
1704
|
+
aiTable.apply(operation);
|
1705
|
+
}
|
1706
|
+
function setCollapsedGroup(aiTable, collapsedGroupIds) {
|
1707
|
+
const viewId = aiTable.activeViewId();
|
1708
|
+
const view = aiTable.views().find((v) => v._id === viewId);
|
1709
|
+
if (!view)
|
1710
|
+
return;
|
1711
|
+
const currentSettings = view.settings || {};
|
1712
|
+
const newSettings = {
|
1713
|
+
...currentSettings,
|
1714
|
+
collapsed_group_ids: collapsedGroupIds
|
1715
|
+
};
|
1716
|
+
const operation = {
|
1717
|
+
type: ActionName.SetView,
|
1718
|
+
properties: { settings: currentSettings },
|
1719
|
+
newProperties: { settings: newSettings },
|
1720
|
+
path: [viewId]
|
1869
1721
|
};
|
1722
|
+
aiTable.apply(operation);
|
1723
|
+
}
|
1724
|
+
// 折叠
|
1725
|
+
function toggleGroupCollapse(aiTable, groupId) {
|
1726
|
+
const activeView = aiTable.viewsMap()[aiTable.activeViewId()];
|
1727
|
+
if (!activeView)
|
1728
|
+
return;
|
1729
|
+
const currentCollapse = activeView.settings?.collapsed_group_ids || [];
|
1730
|
+
const newCollapse = currentCollapse.includes(groupId) ? currentCollapse.filter((id) => id !== groupId) : [...currentCollapse, groupId];
|
1731
|
+
setCollapsedGroup(aiTable, newCollapse);
|
1732
|
+
}
|
1733
|
+
// 添加分组
|
1734
|
+
function addGroupField(aiTable, fieldId, direction = SortDirection.ascending) {
|
1735
|
+
const activeView = aiTable.viewsMap()[aiTable.activeViewId()];
|
1736
|
+
if (!activeView)
|
1737
|
+
return;
|
1738
|
+
const currentGroups = activeView.settings?.groups || [];
|
1739
|
+
// 是否已存在
|
1740
|
+
if (currentGroups.some((group) => group.field_id === fieldId)) {
|
1741
|
+
throw new Error('The field has been used for grouping.');
|
1742
|
+
}
|
1743
|
+
// 层级限制
|
1744
|
+
if (currentGroups.length >= AI_TABLE_GROUP_MAX_LEVEL) {
|
1745
|
+
throw new Error(`The maximum number of groups is ${AI_TABLE_GROUP_MAX_LEVEL}.`);
|
1746
|
+
}
|
1747
|
+
const newGroups = [...currentGroups, { field_id: fieldId, direction }];
|
1748
|
+
setViewGroup(aiTable, newGroups);
|
1749
|
+
}
|
1750
|
+
// 删除分组
|
1751
|
+
function removeGroupField(aiTable, fieldId) {
|
1752
|
+
const view = aiTable.views().find((v) => v._id === aiTable.activeViewId());
|
1753
|
+
if (!view)
|
1754
|
+
return;
|
1755
|
+
const currentGroups = view.settings?.groups || [];
|
1756
|
+
const newGroups = currentGroups.filter((group) => group.field_id !== fieldId);
|
1757
|
+
setViewGroup(aiTable, newGroups.length > 0 ? newGroups : null);
|
1758
|
+
}
|
1759
|
+
// 更新排序方向
|
1760
|
+
function updateGroupFieldDirection(aiTable, fieldId, direction) {
|
1761
|
+
const view = aiTable.views().find((v) => v._id === aiTable.activeViewId());
|
1762
|
+
if (!view)
|
1763
|
+
return;
|
1764
|
+
const currentGroups = view.settings?.groups || [];
|
1765
|
+
const newGroups = currentGroups.map((group) => (group.field_id === fieldId ? { ...group, direction } : group));
|
1766
|
+
setViewGroup(aiTable, newGroups);
|
1767
|
+
}
|
1768
|
+
// 重新排序,拖拽顺序
|
1769
|
+
function reorderGroupFields(aiTable, fromIndex, toIndex) {
|
1770
|
+
const view = aiTable.views().find((v) => v._id === aiTable.activeViewId());
|
1771
|
+
if (!view)
|
1772
|
+
return;
|
1773
|
+
const currentGroups = view.settings?.groups || [];
|
1774
|
+
if (fromIndex < 0 || fromIndex >= currentGroups.length || toIndex < 0 || toIndex >= currentGroups.length) {
|
1775
|
+
return;
|
1776
|
+
}
|
1777
|
+
const newGroups = [...currentGroups];
|
1778
|
+
const [movedItem] = newGroups.splice(fromIndex, 1);
|
1779
|
+
newGroups.splice(toIndex, 0, movedItem);
|
1780
|
+
setViewGroup(aiTable, newGroups);
|
1870
1781
|
}
|
1871
|
-
|
1872
|
-
|
1873
|
-
|
1874
|
-
options.afterRecordId = aiTable.gridData().records[aiTable.gridData().records.length - 1]._id;
|
1875
|
-
}
|
1876
|
-
options.count = options.count || 1;
|
1877
|
-
const { targetPosition, prevPosition } = getPositionByAfterOrBeforeRecordId(aiTable, options);
|
1878
|
-
const interval = (targetPosition - prevPosition) / ((options.count || 1) + 1);
|
1879
|
-
const positionsOfItems = ___default.range(prevPosition + interval, targetPosition, interval);
|
1880
|
-
const views = aiTable.views();
|
1881
|
-
const activeViewId = aiTable.activeViewId();
|
1882
|
-
const viewsMaxPosition = {};
|
1883
|
-
views.forEach((view) => {
|
1884
|
-
viewsMaxPosition[view._id] = getMaxPosition(aiTable.records(), view._id);
|
1885
|
-
});
|
1886
|
-
const viewPositions = positionsOfItems.map((itemPositions) => {
|
1887
|
-
const viewPositions = {};
|
1888
|
-
views.forEach((view) => {
|
1889
|
-
if (view._id === activeViewId) {
|
1890
|
-
viewPositions[view._id] = itemPositions;
|
1891
|
-
}
|
1892
|
-
else {
|
1893
|
-
viewsMaxPosition[view._id] += 1;
|
1894
|
-
viewPositions[view._id] = viewsMaxPosition[view._id];
|
1895
|
-
}
|
1896
|
-
});
|
1897
|
-
return viewPositions;
|
1898
|
-
});
|
1899
|
-
return viewPositions;
|
1782
|
+
// 清空分组
|
1783
|
+
function clearAllGroups(aiTable) {
|
1784
|
+
setViewGroup(aiTable, null);
|
1900
1785
|
}
|
1786
|
+
const GroupActions = {
|
1787
|
+
setViewGroup,
|
1788
|
+
setCollapsedGroup,
|
1789
|
+
toggleGroupCollapse,
|
1790
|
+
addGroupField,
|
1791
|
+
removeGroupField,
|
1792
|
+
updateGroupFieldDirection,
|
1793
|
+
reorderGroupFields,
|
1794
|
+
clearAllGroups
|
1795
|
+
};
|
1796
|
+
|
1797
|
+
const Actions = {
|
1798
|
+
...GeneralActions,
|
1799
|
+
...RecordActions,
|
1800
|
+
...FieldActions,
|
1801
|
+
...ViewActions,
|
1802
|
+
...PositionsActions,
|
1803
|
+
...GroupActions
|
1804
|
+
};
|
1805
|
+
|
1901
1806
|
function getParentGroupValuesByGroupId(aiTable, groupId) {
|
1902
1807
|
const parentGroups = getParentLinearRowGroups(aiTable, groupId);
|
1903
1808
|
return parentGroups.reduce((pre, cur) => {
|
@@ -2143,7 +2048,18 @@ function updateFieldValues(aiTable, options, updatedInfo) {
|
|
2143
2048
|
}
|
2144
2049
|
}
|
2145
2050
|
|
2146
|
-
function moveRecords(aiTable, options
|
2051
|
+
function moveRecords(aiTable, options) {
|
2052
|
+
const viewPositionOptions = {
|
2053
|
+
afterItemId: options.afterRecordId,
|
2054
|
+
beforeItemId: options.beforeRecordId,
|
2055
|
+
count: options.recordIds.length
|
2056
|
+
};
|
2057
|
+
let positions = getCurrentViewPositions(aiTable, viewPositionOptions, aiTable.records(), aiTable.recordsMap());
|
2058
|
+
if (positions.length === 0) {
|
2059
|
+
PositionsActions.resetAllRecordsPositions(aiTable);
|
2060
|
+
positions = getCurrentViewPositions(aiTable, viewPositionOptions, aiTable.records(), aiTable.recordsMap());
|
2061
|
+
console.log('Reset all records positions');
|
2062
|
+
}
|
2147
2063
|
const activeViewId = aiTable.activeViewId();
|
2148
2064
|
const activeView = aiTable.views().find((view) => view._id === activeViewId);
|
2149
2065
|
const { recordIds, afterRecordId, beforeRecordId } = options;
|
@@ -2157,19 +2073,13 @@ function moveRecords(aiTable, options, updatedInfo) {
|
|
2157
2073
|
}
|
2158
2074
|
sourceRecords.push(originalRecords[index]);
|
2159
2075
|
});
|
2160
|
-
let { targetPosition, prevPosition } = getPositionByAfterOrBeforeRecordId(aiTable, {
|
2161
|
-
afterRecordId,
|
2162
|
-
beforeRecordId
|
2163
|
-
});
|
2164
2076
|
const groups = activeView.settings?.groups;
|
2165
2077
|
let needCopyGroupValuesMap = null;
|
2166
2078
|
if (groups?.length && (afterRecordId || beforeRecordId)) {
|
2167
2079
|
needCopyGroupValuesMap = getParentGroupValuesByGroupId(aiTable, (afterRecordId || beforeRecordId));
|
2168
2080
|
}
|
2169
|
-
// 勾选多行顺序可能不一致,需要排序
|
2170
2081
|
const sortedSourceRecords = sortByViewPosition(sourceRecords, activeView);
|
2171
|
-
|
2172
|
-
sortedSourceRecords.forEach((record) => {
|
2082
|
+
sortedSourceRecords.forEach((record, index) => {
|
2173
2083
|
const sourceIndex = recordsIndexMap.get(record._id);
|
2174
2084
|
if (sourceIndex === undefined) {
|
2175
2085
|
throw new Error(`Record with id ${record._id} not found`);
|
@@ -2184,9 +2094,7 @@ function moveRecords(aiTable, options, updatedInfo) {
|
|
2184
2094
|
});
|
2185
2095
|
Actions.updateFieldValues(aiTable, updateFieldValues);
|
2186
2096
|
}
|
2187
|
-
Actions.setRecordPositions(aiTable, { [activeViewId]:
|
2188
|
-
prevPosition = nextPosition;
|
2189
|
-
nextPosition = (prevPosition + targetPosition) / 2;
|
2097
|
+
Actions.setRecordPositions(aiTable, { [activeViewId]: positions[index] }, [sourceIndex]);
|
2190
2098
|
});
|
2191
2099
|
}
|
2192
2100
|
|
@@ -2248,29 +2156,96 @@ function mergeSorts(activeView) {
|
|
2248
2156
|
const FLUSHING = new WeakMap();
|
2249
2157
|
|
2250
2158
|
function moveFields(aiTable, options) {
|
2251
|
-
const
|
2252
|
-
|
2159
|
+
const viewPositionOptions = {
|
2160
|
+
afterItemId: options.afterFieldId,
|
2161
|
+
beforeItemId: options.beforeFieldId,
|
2162
|
+
count: options.fieldIds.length
|
2163
|
+
};
|
2164
|
+
let positions = getCurrentViewPositions(aiTable, viewPositionOptions, aiTable.fields(), aiTable.fieldsMap());
|
2165
|
+
if (positions.length === 0) {
|
2166
|
+
PositionsActions.resetAllFieldsPositions(aiTable);
|
2167
|
+
positions = getCurrentViewPositions(aiTable, viewPositionOptions, aiTable.fields(), aiTable.fieldsMap());
|
2168
|
+
console.log('Reset all fields positions');
|
2169
|
+
}
|
2170
|
+
const activeViewId = aiTable.activeViewId();
|
2171
|
+
const activeView = aiTable.views().find((view) => view._id === activeViewId);
|
2172
|
+
const { fieldIds, afterFieldId, beforeFieldId } = options;
|
2173
|
+
const originalFields = aiTable.fields();
|
2174
|
+
const fieldsIndexMap = new Map(originalFields.map((field, index) => [field._id, index]));
|
2175
|
+
const sourceFields = [];
|
2176
|
+
fieldIds.forEach((id) => {
|
2177
|
+
const index = fieldsIndexMap.get(id);
|
2178
|
+
if (index === undefined) {
|
2179
|
+
return;
|
2180
|
+
}
|
2181
|
+
sourceFields.push(originalFields[index]);
|
2182
|
+
});
|
2183
|
+
const sortedSourceFields = sortByViewPosition(sourceFields, activeView);
|
2184
|
+
const actions = [];
|
2185
|
+
sortedSourceFields.forEach((field, index) => {
|
2186
|
+
const action = buildSetFieldAction(aiTable, { positions: { ...field.positions, [activeViewId]: positions[index] } }, [field._id]);
|
2187
|
+
if (action) {
|
2188
|
+
actions.push(action);
|
2189
|
+
}
|
2190
|
+
});
|
2191
|
+
aiTable.apply(actions);
|
2192
|
+
}
|
2193
|
+
|
2194
|
+
function getFieldPositionInView(viewId, fields, path, newPath) {
|
2195
|
+
const targetPosition = fields[newPath[0]].positions[viewId];
|
2196
|
+
let newPosition = 0;
|
2197
|
+
if (path[0] > newPath[0]) {
|
2198
|
+
const prevPath = newPath[0] - 1;
|
2199
|
+
if (prevPath >= 0) {
|
2200
|
+
const targetPrevField = fields[prevPath];
|
2201
|
+
const targetPrevPosition = targetPrevField.positions[viewId];
|
2202
|
+
newPosition = (targetPosition + targetPrevPosition) / 2;
|
2203
|
+
}
|
2204
|
+
else {
|
2205
|
+
const firstField = fields[0];
|
2206
|
+
newPosition = firstField.positions[viewId] - 0.1;
|
2207
|
+
}
|
2208
|
+
}
|
2209
|
+
else {
|
2210
|
+
const nextPath = newPath[0] + 1;
|
2211
|
+
if (fields.length > nextPath) {
|
2212
|
+
const targetNextField = fields[nextPath];
|
2213
|
+
const targetNextPosition = targetNextField.positions[viewId];
|
2214
|
+
newPosition = (targetPosition + targetNextPosition) / 2;
|
2215
|
+
}
|
2216
|
+
else {
|
2217
|
+
const lastField = fields[fields.length - 1];
|
2218
|
+
const lastPosition = lastField.positions[viewId] + 1;
|
2219
|
+
newPosition = (targetPosition + lastPosition) / 2;
|
2220
|
+
}
|
2221
|
+
}
|
2222
|
+
return newPosition;
|
2223
|
+
}
|
2224
|
+
function getFieldsSizeMap(fields, activeView) {
|
2225
|
+
const fieldsSizeMap = {};
|
2226
|
+
fields?.forEach((field) => {
|
2227
|
+
fieldsSizeMap[field._id] = field.widths?.[activeView._id];
|
2228
|
+
});
|
2229
|
+
return fieldsSizeMap;
|
2253
2230
|
}
|
2254
2231
|
|
2255
2232
|
function addFields(aiTable, options) {
|
2256
2233
|
const { defaultValue, isDuplicate, originId } = options;
|
2257
|
-
const fields = aiTable.gridData().fields;
|
2258
2234
|
const fieldsMap = aiTable.fieldsMap();
|
2259
|
-
const activeViewId = aiTable.activeViewId();
|
2260
2235
|
const newField = { ...defaultValue };
|
2261
2236
|
if (fieldsMap[newField._id]) {
|
2262
2237
|
newField._id = idCreator();
|
2263
2238
|
}
|
2239
|
+
const viewPositionOptions = { count: options.count || 1 };
|
2264
2240
|
if (isDuplicate) {
|
2265
|
-
|
2266
|
-
newField.positions = {
|
2267
|
-
...newField.positions,
|
2268
|
-
[activeViewId]: getPosition(fields, activeViewId, currentFieldIndex)
|
2269
|
-
};
|
2241
|
+
viewPositionOptions.afterItemId = originId;
|
2270
2242
|
}
|
2271
|
-
|
2272
|
-
|
2243
|
+
let positions = getNewItemsPosition(aiTable, viewPositionOptions, aiTable.fields(), aiTable.fieldsMap());
|
2244
|
+
if (positions.length === 0) {
|
2245
|
+
PositionsActions.resetAllFieldsPositions(aiTable);
|
2246
|
+
positions = getNewItemsPosition(aiTable, viewPositionOptions, aiTable.fields(), aiTable.fieldsMap());
|
2273
2247
|
}
|
2248
|
+
newField.positions = positions[0];
|
2274
2249
|
Actions.addField(aiTable, newField, originId, isDuplicate);
|
2275
2250
|
}
|
2276
2251
|
|
@@ -2285,6 +2260,159 @@ const buildRemoveFieldItem = (aiTable, getUpdatedInfo) => {
|
|
2285
2260
|
};
|
2286
2261
|
};
|
2287
2262
|
|
2263
|
+
function getFrozenFieldId(aiTable) {
|
2264
|
+
try {
|
2265
|
+
const viewTable = aiTable;
|
2266
|
+
const activeViewId = viewTable.activeViewId();
|
2267
|
+
const activeView = viewTable.viewsMap()[activeViewId];
|
2268
|
+
return activeView?.settings?.frozen_field_id;
|
2269
|
+
}
|
2270
|
+
catch (error) {
|
2271
|
+
return undefined;
|
2272
|
+
}
|
2273
|
+
}
|
2274
|
+
function calculateAdaptiveFrozenColumnCountCore(config) {
|
2275
|
+
const { containerWidth, rowHeadWidth, visibleFields, columnIndicesSizeMap, frozenFieldId, minUnfrozenWidth = AI_TABLE_DEFAULT_MIN_UNFROZEN_WIDTH } = config;
|
2276
|
+
if (visibleFields.length === 0) {
|
2277
|
+
return AI_TABLE_MIN_FROZEN_COLUMN_COUNT;
|
2278
|
+
}
|
2279
|
+
let targetFrozenCount;
|
2280
|
+
if (frozenFieldId) {
|
2281
|
+
const frozenFieldIndex = visibleFields.findIndex((field) => field._id === frozenFieldId);
|
2282
|
+
if (frozenFieldIndex >= 0) {
|
2283
|
+
targetFrozenCount = frozenFieldIndex + 1;
|
2284
|
+
}
|
2285
|
+
else {
|
2286
|
+
targetFrozenCount = AI_TABLE_MIN_FROZEN_COLUMN_COUNT;
|
2287
|
+
}
|
2288
|
+
}
|
2289
|
+
else {
|
2290
|
+
targetFrozenCount = AI_TABLE_MIN_FROZEN_COLUMN_COUNT;
|
2291
|
+
}
|
2292
|
+
const availableWidth = containerWidth - rowHeadWidth;
|
2293
|
+
const maxFrozenWidth = Math.max(0, availableWidth - minUnfrozenWidth);
|
2294
|
+
let currentFrozenWidth = 0;
|
2295
|
+
let actualFrozenCount = 0;
|
2296
|
+
const maxPossibleCount = Math.min(targetFrozenCount, visibleFields.length);
|
2297
|
+
for (let i = 0; i < maxPossibleCount; i++) {
|
2298
|
+
const fieldWidth = columnIndicesSizeMap[i];
|
2299
|
+
const newFrozenWidth = currentFrozenWidth + fieldWidth;
|
2300
|
+
if (newFrozenWidth > maxFrozenWidth) {
|
2301
|
+
if (i === 0) {
|
2302
|
+
currentFrozenWidth = newFrozenWidth;
|
2303
|
+
actualFrozenCount = AI_TABLE_MIN_FROZEN_COLUMN_COUNT;
|
2304
|
+
}
|
2305
|
+
break;
|
2306
|
+
}
|
2307
|
+
currentFrozenWidth = newFrozenWidth;
|
2308
|
+
actualFrozenCount = i + 1;
|
2309
|
+
}
|
2310
|
+
// 至少有一列冻结
|
2311
|
+
if (actualFrozenCount < AI_TABLE_MIN_FROZEN_COLUMN_COUNT) {
|
2312
|
+
actualFrozenCount = AI_TABLE_MIN_FROZEN_COLUMN_COUNT;
|
2313
|
+
if (visibleFields.length > 0) {
|
2314
|
+
currentFrozenWidth = columnIndicesSizeMap[0];
|
2315
|
+
}
|
2316
|
+
}
|
2317
|
+
return actualFrozenCount;
|
2318
|
+
}
|
2319
|
+
function calculateAdaptiveFrozenColumnCount(aiTable, containerWidth, minUnfrozenWidth = 200) {
|
2320
|
+
try {
|
2321
|
+
if (containerWidth <= 0) {
|
2322
|
+
return AI_TABLE_MIN_FROZEN_COLUMN_COUNT;
|
2323
|
+
}
|
2324
|
+
const frozenFieldId = getFrozenFieldId(aiTable);
|
2325
|
+
const visibleFields = AITable.getVisibleFields(aiTable);
|
2326
|
+
const columnIndicesSizeMap = getColumnIndicesSizeMap(aiTable, visibleFields);
|
2327
|
+
const rowHeadWidth = aiTable.context?.rowHeadWidth?.() || 0;
|
2328
|
+
return calculateAdaptiveFrozenColumnCountCore({
|
2329
|
+
containerWidth,
|
2330
|
+
rowHeadWidth,
|
2331
|
+
visibleFields,
|
2332
|
+
columnIndicesSizeMap,
|
2333
|
+
frozenFieldId,
|
2334
|
+
minUnfrozenWidth
|
2335
|
+
});
|
2336
|
+
}
|
2337
|
+
catch (error) {
|
2338
|
+
return AI_TABLE_MIN_FROZEN_COLUMN_COUNT;
|
2339
|
+
}
|
2340
|
+
}
|
2341
|
+
const freezeToThisColumn = (aiTable) => {
|
2342
|
+
return {
|
2343
|
+
type: 'freezeToThisColumn',
|
2344
|
+
name: getStateI18nTextByKey(aiTable, AITableStateI18nKey.freezeToThisColumn),
|
2345
|
+
icon: 'frozen',
|
2346
|
+
exec: (aiTable, field) => {
|
2347
|
+
const currentField = field();
|
2348
|
+
const viewTable = aiTable;
|
2349
|
+
setViewFrozenField(viewTable, currentField._id);
|
2350
|
+
},
|
2351
|
+
hidden: (aiTable, field) => {
|
2352
|
+
if (aiTable.context?.readonly?.()) {
|
2353
|
+
return true;
|
2354
|
+
}
|
2355
|
+
const currentField = field();
|
2356
|
+
const currentFrozenFieldId = getFrozenFieldId(aiTable);
|
2357
|
+
return currentFrozenFieldId === currentField._id;
|
2358
|
+
},
|
2359
|
+
disabled: (aiTable, field) => {
|
2360
|
+
try {
|
2361
|
+
const currentField = field();
|
2362
|
+
const fields = aiTable.gridData().fields;
|
2363
|
+
const currentFieldIndex = fields.findIndex((f) => f._id === currentField._id);
|
2364
|
+
const visibleFields = AITable.getVisibleFields(aiTable);
|
2365
|
+
const columnIndicesSizeMap = getColumnIndicesSizeMap(aiTable, visibleFields);
|
2366
|
+
const containerWidth = aiTable.context?.containerRect()?.width || 0;
|
2367
|
+
const rowHeadWidth = aiTable.context?.rowHeadWidth?.() || 0;
|
2368
|
+
const actualFrozenCount = calculateAdaptiveFrozenColumnCountCore({
|
2369
|
+
containerWidth,
|
2370
|
+
rowHeadWidth,
|
2371
|
+
visibleFields,
|
2372
|
+
columnIndicesSizeMap,
|
2373
|
+
frozenFieldId: currentField._id,
|
2374
|
+
minUnfrozenWidth: AI_TABLE_DEFAULT_MIN_UNFROZEN_WIDTH
|
2375
|
+
});
|
2376
|
+
if (actualFrozenCount < currentFieldIndex + 1) {
|
2377
|
+
// 超过可视区域禁用
|
2378
|
+
return true;
|
2379
|
+
}
|
2380
|
+
const currentFrozenFieldId = getFrozenFieldId(aiTable);
|
2381
|
+
if (!currentFrozenFieldId && currentFieldIndex === 0) {
|
2382
|
+
// 默认第一列冻结列禁用
|
2383
|
+
return true;
|
2384
|
+
}
|
2385
|
+
return false;
|
2386
|
+
}
|
2387
|
+
catch (error) {
|
2388
|
+
return false;
|
2389
|
+
}
|
2390
|
+
}
|
2391
|
+
};
|
2392
|
+
};
|
2393
|
+
const restoreDefaultFrozenColumn = (aiTable) => {
|
2394
|
+
return {
|
2395
|
+
type: 'restoreDefaultFrozenColumn',
|
2396
|
+
name: getStateI18nTextByKey(aiTable, AITableStateI18nKey.restoreDefaultFrozenColumn),
|
2397
|
+
icon: 'frozen',
|
2398
|
+
exec: (aiTable, field) => {
|
2399
|
+
const viewTable = aiTable;
|
2400
|
+
setViewFrozenField(viewTable, undefined);
|
2401
|
+
},
|
2402
|
+
hidden: (aiTable, field) => {
|
2403
|
+
if (aiTable.context?.readonly?.()) {
|
2404
|
+
return true;
|
2405
|
+
}
|
2406
|
+
const currentField = field();
|
2407
|
+
const currentFrozenFieldId = getFrozenFieldId(aiTable);
|
2408
|
+
if (!currentFrozenFieldId) {
|
2409
|
+
return true;
|
2410
|
+
}
|
2411
|
+
return currentField._id !== currentFrozenFieldId;
|
2412
|
+
}
|
2413
|
+
};
|
2414
|
+
};
|
2415
|
+
|
2288
2416
|
const withState = (aiTable) => {
|
2289
2417
|
const viewTable = aiTable;
|
2290
2418
|
viewTable.actions = [];
|
@@ -2512,5 +2640,5 @@ const VIEW_ACTIONS = [ActionName.SetView, ActionName.AddView, ActionName.RemoveV
|
|
2512
2640
|
* Generated bundle index. Do not edit.
|
2513
2641
|
*/
|
2514
2642
|
|
2515
|
-
export { AITableStateI18nKey, AITableStateI18nText, Actions, CopyCellsItem, CopyFieldPropertyItem, DividerMenuItem, EditFieldPropertyItem, FLUSHING, GroupCalculator, InsertDownwardRecords, InsertUpwardRecords, PasteCellsItem, RemoveRecordsItem, UndoManagerService, VIEW_ACTIONS, YjsAITable, actionMappers, addFields, addRecords, addView, applyActionOps, applyActions, applyEvents, applyYjsEvents, buildFieldsByView, buildLinearRows, buildRecordsByView, buildRecordsWithWillMoveRecords, buildRemoveFieldItem, buildSetFieldAction, buildSetRecordPositionsActon, buildSorts, calculateAdaptiveFrozenColumnCount, checkConditions, createMultiplePositions, createPositions, createSharedType, doFilter,
|
2643
|
+
export { AITableStateI18nKey, AITableStateI18nText, Actions, CopyCellsItem, CopyFieldPropertyItem, DividerMenuItem, EditFieldPropertyItem, FLUSHING, GroupCalculator, InsertDownwardRecords, InsertUpwardRecords, PasteCellsItem, RemoveRecordsItem, UndoManagerService, VIEW_ACTIONS, YjsAITable, actionMappers, addFields, addRecords, addView, applyActionOps, applyActions, applyEvents, applyYjsEvents, buildFieldsByView, buildLinearRows, buildRecordsByView, buildRecordsWithWillMoveRecords, buildRemoveFieldItem, buildSetFieldAction, buildSetRecordPositionsActon, buildSorts, calculateAdaptiveFrozenColumnCount, checkConditions, createMultiplePositions, createPositions, createSharedType, doFilter, freezeToThisColumn, generateCopyName, getDataBySharedType, getDefaultI18nTextByKey, getDefaultRecordDataByFilter, getDefaultRecordValues, getFieldPositionInView, getFieldsSizeMap, getFilteredRecords, getFrozenFieldId, getGroupRecordLength, getMaxPosition, getParentGroupValuesByGroupId, getParentLinearRowGroups, getPosition, getPositions, getPrevRecordIdByAddGroupId, getRecordsBySharedJson, getSharedTypeByData, getSortFields, getStateI18nTextByKey, insertAtEnd, insertAtStart, insertBetween, isPathEqual, isSameParentGroup, mergeSorts, moveFields, moveRecords, removeView, restoreDefaultFrozenColumn, sortRecordsByConditions, sortViews, toSharedType, translateYjsEvent, updateFieldAndValues, updateFieldValues, withState };
|
2516
2644
|
//# sourceMappingURL=ai-table-state.mjs.map
|