@ai-table/state 0.0.72 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/action/index.d.ts +1 -1
- package/action/position.d.ts +2 -2
- package/action/position.d.ts.map +1 -1
- package/constants/context-menu-item.d.ts.map +1 -1
- package/constants/field-menu-item.d.ts.map +1 -1
- package/fesm2022/ai-table-state.mjs +52 -23
- package/fesm2022/ai-table-state.mjs.map +1 -1
- package/package.json +1 -3
- package/plugins/state.plugin.d.ts.map +1 -1
- package/shared/utils/initialize.d.ts.map +1 -1
- package/utils/field/add-fields.d.ts.map +1 -1
- package/utils/field/remove-field.d.ts.map +1 -1
- package/utils/field/sort-fields.d.ts.map +1 -1
- package/utils/i18n.d.ts +3 -1
- package/utils/i18n.d.ts.map +1 -1
- package/utils/record/move-records.d.ts.map +1 -1
- package/esm2022/action/field.mjs +0 -75
- package/esm2022/action/general.mjs +0 -163
- package/esm2022/action/index.mjs +0 -13
- package/esm2022/action/position.mjs +0 -13
- package/esm2022/action/record.mjs +0 -61
- package/esm2022/action/view.mjs +0 -57
- package/esm2022/ai-table-state.mjs +0 -5
- package/esm2022/constants/context-menu-item.mjs +0 -56
- package/esm2022/constants/field-menu-item.mjs +0 -56
- package/esm2022/constants/index.mjs +0 -4
- package/esm2022/constants/view.mjs +0 -3
- package/esm2022/index.mjs +0 -2
- package/esm2022/plugins/state.plugin.mjs +0 -20
- package/esm2022/public-api.mjs +0 -7
- package/esm2022/shared/index.mjs +0 -6
- package/esm2022/shared/to-table/index.mjs +0 -29
- package/esm2022/shared/to-table/map-event.mjs +0 -48
- package/esm2022/shared/to-yjs/add-node.mjs +0 -63
- package/esm2022/shared/to-yjs/index.mjs +0 -33
- package/esm2022/shared/to-yjs/remove-node.mjs +0 -37
- package/esm2022/shared/to-yjs/set-node.mjs +0 -31
- package/esm2022/shared/to-yjs/update-field-value.mjs +0 -23
- package/esm2022/shared/undo-manager.service.mjs +0 -60
- package/esm2022/shared/utils/index.mjs +0 -2
- package/esm2022/shared/utils/initialize.mjs +0 -51
- package/esm2022/shared/yjs-table.mjs +0 -39
- package/esm2022/types/ai-table.mjs +0 -2
- package/esm2022/types/index.mjs +0 -2
- package/esm2022/utils/build.mjs +0 -11
- package/esm2022/utils/common.mjs +0 -22
- package/esm2022/utils/field/add-fields.mjs +0 -25
- package/esm2022/utils/field/move-fields.mjs +0 -6
- package/esm2022/utils/field/position-field.mjs +0 -38
- package/esm2022/utils/field/remove-field.mjs +0 -13
- package/esm2022/utils/field/sort-fields.mjs +0 -5
- package/esm2022/utils/i18n.mjs +0 -37
- package/esm2022/utils/index.mjs +0 -17
- package/esm2022/utils/record/add-records.mjs +0 -40
- package/esm2022/utils/record/filter.mjs +0 -121
- package/esm2022/utils/record/move-records.mjs +0 -33
- package/esm2022/utils/record/sort.mjs +0 -38
- package/esm2022/utils/record/update-field-value.mjs +0 -11
- package/esm2022/utils/record/update-system-field-value.mjs +0 -8
- package/esm2022/utils/view.mjs +0 -96
- package/esm2022/utils/weak-map.mjs +0 -2
package/action/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
export declare const Actions: {
|
2
2
|
setRecordPositions: typeof import("./position").setRecordPositions;
|
3
3
|
setView: (aiTable: import("@ai-table/state").AIViewTable, value: Partial<import("@ai-table/utils").AITableView>, path: [string]) => void;
|
4
|
-
addView: (aiTable: import("@ai-table/state").AIViewTable, originId: string, newView: import("@ai-table/utils").AITableView, isDuplicate?: boolean
|
4
|
+
addView: (aiTable: import("@ai-table/state").AIViewTable, originId: string, newView: import("@ai-table/utils").AITableView, isDuplicate?: boolean) => void;
|
5
5
|
removeView: (aiTable: import("@ai-table/state").AIViewTable, path: [string]) => void;
|
6
6
|
addField: typeof import("./field").addField;
|
7
7
|
moveField: typeof import("./field").moveField;
|
package/action/position.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { AIViewTable } from '../types';
|
2
|
-
import {
|
3
|
-
export declare function setRecordPositions(aiTable: AIViewTable, positions: Positions | RemovePositions, path:
|
2
|
+
import { NumberPath, Positions, RemovePositions } from '@ai-table/utils';
|
3
|
+
export declare function setRecordPositions(aiTable: AIViewTable, positions: Positions | RemovePositions, path: NumberPath): void;
|
4
4
|
export declare const PositionsActions: {
|
5
5
|
setRecordPositions: typeof setRecordPositions;
|
6
6
|
};
|
package/action/position.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/position.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAc,
|
1
|
+
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/position.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,SAAS,EAAE,eAAe,EAA2B,MAAM,iBAAiB,CAAC;AAE9G,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,GAAG,eAAe,EAAE,IAAI,EAAE,UAAU,QAOhH;AAED,eAAO,MAAM,gBAAgB;;CAE5B,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"context-menu-item.d.ts","sourceRoot":"","sources":["../../../packages/state/src/constants/context-menu-item.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,OAAO,EACP,sBAAsB,EAGtB,cAAc,EAIjB,MAAM,gBAAgB,CAAC;AAOxB,eAAO,MAAM,iBAAiB,
|
1
|
+
{"version":3,"file":"context-menu-item.d.ts","sourceRoot":"","sources":["../../../packages/state/src/constants/context-menu-item.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,OAAO,EACP,sBAAsB,EAGtB,cAAc,EAIjB,MAAM,gBAAgB,CAAC;AAOxB,eAAO,MAAM,iBAAiB,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,KAAG,sBAkB7E,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,KAAG,sBA4BzE,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,KAAK,sBAqC3E,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"field-menu-item.d.ts","sourceRoot":"","sources":["../../../packages/state/src/constants/field-menu-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,OAAO,EAAkC,MAAM,gBAAgB,CAAC;AAC1G,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGvC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEhE,eAAO,MAAM,eAAe;;CAE3B,CAAC;AAEF,eAAO,MAAM,qBAAqB,
|
1
|
+
{"version":3,"file":"field-menu-item.d.ts","sourceRoot":"","sources":["../../../packages/state/src/constants/field-menu-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,OAAO,EAAkC,MAAM,gBAAgB,CAAC;AAC1G,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGvC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEhE,eAAO,MAAM,eAAe;;CAE3B,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,SAAS,OAAO;;;;oBAKrC,WAAW,SACb,MAAM,CAAC,YAAY,CAAC,WAClB,WAAW,GAAG,UAAU,CAAC,GAAG,CAAC,aAC3B;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE;CAoBzC,CAAC;AAEH,eAAO,MAAM,qBAAqB,GAAI,SAAS,OAAO,EAAE,YAAY,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI;;;;oBAM3E,WAAW,SAAS,MAAM,CAAC,YAAY,CAAC;CAiB/D,CAAC"}
|
@@ -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,
|
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 } 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, getDefaultFieldValue, idCreator, shortIdCreator, generateNewName, idsCreator, shortIdsCreator, AI_TABLE_GRID_FIELD_SERVICE_MAP, AITable,
|
6
|
+
import { FieldModelMap, AITableQueries, isSystemField, getDefaultFieldValue, idCreator, shortIdCreator, generateNewName, idsCreator, shortIdsCreator, AI_TABLE_GRID_FIELD_SERVICE_MAP, AITable, buildClipboardData, writeToClipboard, getI18nTextByKey, AITableGridI18nKey, isMac, writeToAITable } from '@ai-table/grid';
|
7
7
|
import { createDraft, finishDraft } from 'immer';
|
8
8
|
import * as _ from 'lodash';
|
9
9
|
import ___default from 'lodash';
|
@@ -183,7 +183,7 @@ function addNode(aiTable, sharedType, action) {
|
|
183
183
|
break;
|
184
184
|
case ActionName.SetRecordPositions:
|
185
185
|
if (records) {
|
186
|
-
const recordIndex =
|
186
|
+
const recordIndex = action.path[0];
|
187
187
|
const record = records.get(recordIndex);
|
188
188
|
const positions = getPositionsByRecordSyncElement(record);
|
189
189
|
const newPositions = { ...positions };
|
@@ -394,10 +394,10 @@ class UndoManagerService {
|
|
394
394
|
this._canUndoCount.set(0);
|
395
395
|
this._canRedoCount.set(0);
|
396
396
|
}
|
397
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
398
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
397
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: UndoManagerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
398
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: UndoManagerService }); }
|
399
399
|
}
|
400
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
400
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: UndoManagerService, decorators: [{
|
401
401
|
type: Injectable
|
402
402
|
}] });
|
403
403
|
|
@@ -412,6 +412,8 @@ var AITableStateI18nKey;
|
|
412
412
|
AITableStateI18nKey["tableView"] = "tableView";
|
413
413
|
AITableStateI18nKey["editField"] = "editField";
|
414
414
|
AITableStateI18nKey["removeField"] = "removeField";
|
415
|
+
AITableStateI18nKey["pasteOverMaxRecords"] = "pasteOverMaxRecords";
|
416
|
+
AITableStateI18nKey["pasteOverMaxFields"] = "pasteOverMaxFields";
|
415
417
|
})(AITableStateI18nKey || (AITableStateI18nKey = {}));
|
416
418
|
const AITableI18nText = {
|
417
419
|
[AITableStateI18nKey.copyField]: '复制列',
|
@@ -422,7 +424,9 @@ const AITableI18nText = {
|
|
422
424
|
[AITableStateI18nKey.invalidPasteContent]: '粘贴内容不符合当前类型',
|
423
425
|
[AITableStateI18nKey.tableView]: '表格视图',
|
424
426
|
[AITableStateI18nKey.editField]: '编辑列',
|
425
|
-
[AITableStateI18nKey.removeField]: '删除列'
|
427
|
+
[AITableStateI18nKey.removeField]: '删除列',
|
428
|
+
[AITableStateI18nKey.pasteOverMaxRecords]: '粘贴数据超过最大行数',
|
429
|
+
[AITableStateI18nKey.pasteOverMaxFields]: '粘贴数据超过最大列数'
|
426
430
|
};
|
427
431
|
const getDefaultI18nTextByKey = (key) => {
|
428
432
|
return AITableI18nText[key] || key;
|
@@ -851,7 +855,7 @@ const apply = (aiTable, records, fields, views, action) => {
|
|
851
855
|
}
|
852
856
|
case ActionName.SetRecordPositions: {
|
853
857
|
const { positions, path } = action;
|
854
|
-
const record = records
|
858
|
+
const record = records[path[0]];
|
855
859
|
if (record) {
|
856
860
|
const newPositions = { ...record.positions };
|
857
861
|
for (const key in positions) {
|
@@ -1087,8 +1091,8 @@ function addView(aiTable, type, viewId) {
|
|
1087
1091
|
};
|
1088
1092
|
}
|
1089
1093
|
ViewActions.addView(aiTable, originViewId, newView, type === 'duplicate');
|
1090
|
-
aiTable.records().forEach((record) => {
|
1091
|
-
PositionsActions.setRecordPositions(aiTable, { [newId]: record.positions[originViewId] }, [
|
1094
|
+
aiTable.records().forEach((record, index) => {
|
1095
|
+
PositionsActions.setRecordPositions(aiTable, { [newId]: record.positions[originViewId] }, [index]);
|
1092
1096
|
});
|
1093
1097
|
aiTable.fields().forEach((field) => {
|
1094
1098
|
Actions.setField(aiTable, {
|
@@ -1101,8 +1105,8 @@ function addView(aiTable, type, viewId) {
|
|
1101
1105
|
return newView;
|
1102
1106
|
}
|
1103
1107
|
function removeView(aiTable, records, fields, activeViewId) {
|
1104
|
-
records.forEach((record) => {
|
1105
|
-
PositionsActions.setRecordPositions(aiTable, { [activeViewId]: undefined }, [
|
1108
|
+
records.forEach((record, index) => {
|
1109
|
+
PositionsActions.setRecordPositions(aiTable, { [activeViewId]: undefined }, [index]);
|
1106
1110
|
});
|
1107
1111
|
fields.forEach((field) => {
|
1108
1112
|
const positions = { ...field.positions };
|
@@ -1209,30 +1213,43 @@ function moveFields(aiTable, options, updatedInfo) {
|
|
1209
1213
|
}
|
1210
1214
|
|
1211
1215
|
function moveRecords(aiTable, options, updatedInfo) {
|
1212
|
-
const
|
1216
|
+
const gridRecords = aiTable.gridData().records;
|
1213
1217
|
const activeViewId = aiTable.activeViewId();
|
1214
1218
|
const activeView = aiTable.views().find((view) => view._id === activeViewId);
|
1215
1219
|
const { recordIds, newPath } = options;
|
1216
1220
|
let targetPosition = 0;
|
1217
1221
|
let prevPosition = 0;
|
1218
1222
|
if (newPath[0] === 0) {
|
1219
|
-
targetPosition =
|
1223
|
+
targetPosition = gridRecords[0].positions[activeViewId];
|
1220
1224
|
prevPosition = targetPosition - 1;
|
1221
1225
|
}
|
1222
|
-
else if (newPath[0] >=
|
1223
|
-
targetPosition = getMaxPosition(
|
1224
|
-
prevPosition =
|
1226
|
+
else if (newPath[0] >= gridRecords.length) {
|
1227
|
+
targetPosition = getMaxPosition(gridRecords, activeViewId) + 1;
|
1228
|
+
prevPosition = gridRecords[gridRecords.length - 1].positions[activeViewId];
|
1225
1229
|
}
|
1226
1230
|
else {
|
1227
|
-
targetPosition =
|
1228
|
-
prevPosition =
|
1231
|
+
targetPosition = gridRecords[newPath[0]].positions[activeViewId];
|
1232
|
+
prevPosition = gridRecords[newPath[0] - 1].positions[activeViewId];
|
1229
1233
|
}
|
1230
|
-
const
|
1234
|
+
const records = aiTable.records();
|
1235
|
+
const recordsIndexMap = new Map(records.map((row, index) => [row._id, index]));
|
1236
|
+
const sourceRecords = [];
|
1237
|
+
recordIds.forEach((idPath) => {
|
1238
|
+
const index = recordsIndexMap.get(idPath[0]);
|
1239
|
+
if (index === undefined) {
|
1240
|
+
throw new Error(`Record with id ${idPath[0]} not found`);
|
1241
|
+
}
|
1242
|
+
sourceRecords.push(records[index]);
|
1243
|
+
});
|
1231
1244
|
// 勾选多行顺序可能不一致,需要排序
|
1232
1245
|
const sortedSourceRecords = sortByViewPosition(sourceRecords, activeView);
|
1233
1246
|
let nextPosition = (prevPosition + targetPosition) / 2;
|
1234
1247
|
sortedSourceRecords.forEach((record) => {
|
1235
|
-
|
1248
|
+
const sourceIndex = recordsIndexMap.get(record._id);
|
1249
|
+
if (sourceIndex === undefined) {
|
1250
|
+
throw new Error(`Record with id ${record._id} not found`);
|
1251
|
+
}
|
1252
|
+
Actions.setRecordPositions(aiTable, { [activeViewId]: nextPosition }, [sourceIndex]);
|
1236
1253
|
prevPosition = nextPosition;
|
1237
1254
|
nextPosition = (prevPosition + targetPosition) / 2;
|
1238
1255
|
});
|
@@ -1348,12 +1365,24 @@ const PasteCellsItem = (aiTable, actions) => {
|
|
1348
1365
|
shortcutKey: isMac() ? `⌘ + V` : `Ctrl + V`,
|
1349
1366
|
icon: 'paste',
|
1350
1367
|
exec: async (aiTable, targetName, position, aiTableGridSelectionService, notifyService) => {
|
1351
|
-
writeToAITable(aiTable, actions).then((
|
1352
|
-
if (!isPasteSuccess) {
|
1368
|
+
writeToAITable(aiTable, actions).then((result) => {
|
1369
|
+
if (!result.isPasteSuccess) {
|
1353
1370
|
notifyService.error(getStateI18nTextByKey(aiTable, AITableStateI18nKey.invalidPasteContent), undefined, {
|
1354
1371
|
placement: 'bottomLeft'
|
1355
1372
|
});
|
1356
1373
|
}
|
1374
|
+
if (result.isPasteOverMaxRecords) {
|
1375
|
+
notifyService.error(getStateI18nTextByKey(aiTable, AITableStateI18nKey.pasteOverMaxRecords), undefined, {
|
1376
|
+
placement: 'bottomLeft'
|
1377
|
+
});
|
1378
|
+
console.warn('Pasting exceeds maximum records limit');
|
1379
|
+
}
|
1380
|
+
if (result.isPasteOverMaxFields) {
|
1381
|
+
notifyService.error(getStateI18nTextByKey(aiTable, AITableStateI18nKey.pasteOverMaxFields), undefined, {
|
1382
|
+
placement: 'bottomLeft'
|
1383
|
+
});
|
1384
|
+
console.warn('Pasting exceeds maximum fields limit');
|
1385
|
+
}
|
1357
1386
|
});
|
1358
1387
|
}
|
1359
1388
|
};
|