@ai-table/state 0.1.1 → 0.1.2
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 +2 -1
- package/action/field.d.ts.map +1 -1
- package/action/general.d.ts +1 -1
- package/action/general.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 +2 -1
- package/action/position.d.ts.map +1 -1
- package/action/record.d.ts +5 -1
- package/action/record.d.ts.map +1 -1
- package/constants/context-menu-item.d.ts +2 -0
- package/constants/context-menu-item.d.ts.map +1 -1
- package/fesm2022/ai-table-state.mjs +163 -60
- package/fesm2022/ai-table-state.mjs.map +1 -1
- package/package.json +1 -1
- package/plugins/state.plugin.d.ts.map +1 -1
- package/shared/to-table/index.d.ts +2 -1
- package/shared/to-table/index.d.ts.map +1 -1
- package/types/ai-table.d.ts +1 -1
- package/types/ai-table.d.ts.map +1 -1
- package/utils/field/add-fields.d.ts +2 -2
- package/utils/field/add-fields.d.ts.map +1 -1
- package/utils/field/move-fields.d.ts +2 -2
- package/utils/field/move-fields.d.ts.map +1 -1
- package/utils/i18n.d.ts +4 -1
- package/utils/i18n.d.ts.map +1 -1
- package/utils/record/add-records.d.ts.map +1 -1
- package/utils/view.d.ts +4 -2
- package/utils/view.d.ts.map +1 -1
package/action/field.d.ts
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
import { AITableViewField, AITableField, IdPath, NumberPath } from '@ai-table/utils';
|
1
|
+
import { SetFieldAction, AITableViewField, AITableField, IdPath, NumberPath } from '@ai-table/utils';
|
2
2
|
import { AIViewTable } from '../types/ai-table';
|
3
3
|
export declare function addField(aiTable: AIViewTable, field: AITableField, originId?: string, isDuplicate?: boolean): void;
|
4
4
|
export declare function moveField(aiTable: AIViewTable, path: NumberPath, newPath: NumberPath): void;
|
5
5
|
export declare function setFieldWidth(aiTable: AIViewTable, path: IdPath, width: number): void;
|
6
6
|
export declare function removeField(aiTable: AIViewTable, path: IdPath): void;
|
7
|
+
export declare function buildSetFieldAction<T extends AITableViewField = AITableViewField>(aiTable: AIViewTable, value: Partial<T>, path: IdPath): SetFieldAction | null;
|
7
8
|
export declare function setField<T extends AITableViewField = AITableViewField>(aiTable: AIViewTable, value: Partial<T>, path: IdPath): void;
|
8
9
|
export declare const FieldActions: {
|
9
10
|
addField: typeof addField;
|
package/action/field.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/field.ts"],"names":[],"mappings":"AACA,OAAO,
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/field.ts"],"names":[],"mappings":"AACA,OAAO,EAIH,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,MAAM,EACN,UAAU,EACb,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,OAAO,QAe3G;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,QASpF;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAI9E;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,QAM7D;AAED,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,gBAAgB,GAAG,gBAAgB,EAC7E,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EACjB,IAAI,EAAE,MAAM,GACb,cAAc,GAAG,IAAI,CAyBvB;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,gBAAgB,GAAG,gBAAgB,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,QAK5H;AAED,eAAO,MAAM,YAAY;;;;;;CAMxB,CAAC"}
|
package/action/general.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { AIViewTable } from '../types';
|
2
2
|
import { AITableAction } from '@ai-table/utils';
|
3
3
|
export declare const GeneralActions: {
|
4
|
-
transform(aiTable: AIViewTable,
|
4
|
+
transform(aiTable: AIViewTable, actions: AITableAction[]): void;
|
5
5
|
};
|
6
6
|
//# sourceMappingURL=general.d.ts.map
|
package/action/general.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/general.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;
|
1
|
+
{"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/general.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGvC,OAAO,EAEH,aAAa,EAQhB,MAAM,iBAAiB,CAAC;AA0IzB,eAAO,MAAM,cAAc;uBACJ,WAAW,WAAW,aAAa,EAAE,GAAG,IAAI;CAoBlE,CAAC"}
|
package/action/index.d.ts
CHANGED
@@ -9,9 +9,10 @@ export declare const Actions: {
|
|
9
9
|
setField: typeof import("./field").setField;
|
10
10
|
setFieldWidth: typeof import("./field").setFieldWidth;
|
11
11
|
addRecord: typeof import("./record").addRecord;
|
12
|
+
addRecords: typeof import("./record").addRecords;
|
12
13
|
updateFieldValue: typeof import("./record").updateFieldValue;
|
13
14
|
removeRecord: typeof import("./record").removeRecord;
|
14
15
|
updateSystemFieldValue: typeof import("./record").updateSystemFieldValue;
|
15
|
-
transform(aiTable: import("@ai-table/state").AIViewTable,
|
16
|
+
transform(aiTable: import("@ai-table/state").AIViewTable, actions: import("@ai-table/utils").AITableAction[]): void;
|
16
17
|
};
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
package/action/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,OAAO
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;CAMnB,CAAC"}
|
package/action/position.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { AIViewTable } from '../types';
|
2
|
-
import { NumberPath, Positions, RemovePositions } from '@ai-table/utils';
|
2
|
+
import { NumberPath, Positions, RemovePositions, SetRecordPositionAction } from '@ai-table/utils';
|
3
|
+
export declare function buildSetRecordPositionsActon(aiTable: AIViewTable, positions: Positions | RemovePositions, path: NumberPath): SetRecordPositionAction;
|
3
4
|
export declare function setRecordPositions(aiTable: AIViewTable, positions: Positions | RemovePositions, path: NumberPath): void;
|
4
5
|
export declare const PositionsActions: {
|
5
6
|
setRecordPositions: typeof setRecordPositions;
|
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,UAAU,EAAE,SAAS,EAAE,eAAe,
|
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,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE9G,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,GAAG,eAAe,EAAE,IAAI,EAAE,UAAU,2BAO1H;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,GAAG,eAAe,EAAE,IAAI,EAAE,UAAU,QAGhH;AAED,eAAO,MAAM,gBAAgB;;CAE5B,CAAC"}
|
package/action/record.d.ts
CHANGED
@@ -1,11 +1,15 @@
|
|
1
|
-
import { AIRecordFieldIdPath, AITableRecord, AITableRecordUpdatedInfo, IdPath } from '@ai-table/utils';
|
1
|
+
import { AIRecordFieldIdPath, AITableRecord, AITableRecordUpdatedInfo, IdPath, AITableViewRecords, AddRecordOptions } from '@ai-table/utils';
|
2
2
|
import { AIViewTable } from '../types/ai-table';
|
3
3
|
export declare function updateFieldValue(aiTable: AIViewTable, value: any, path: AIRecordFieldIdPath): void;
|
4
4
|
export declare function updateSystemFieldValue(aiTable: AIViewTable, path: IdPath, updatedInfo: AITableRecordUpdatedInfo): void;
|
5
5
|
export declare function addRecord(aiTable: AIViewTable, record: AITableRecord): void;
|
6
|
+
export declare function addRecords(aiTable: AIViewTable, records: AITableRecord[], options?: AddRecordOptions & {
|
7
|
+
sortRecords?: AITableViewRecords;
|
8
|
+
}): void;
|
6
9
|
export declare function removeRecord(aiTable: AIViewTable, path: IdPath): void;
|
7
10
|
export declare const RecordActions: {
|
8
11
|
addRecord: typeof addRecord;
|
12
|
+
addRecords: typeof addRecords;
|
9
13
|
updateFieldValue: typeof updateFieldValue;
|
10
14
|
removeRecord: typeof removeRecord;
|
11
15
|
updateSystemFieldValue: typeof updateSystemFieldValue;
|
package/action/record.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/record.ts"],"names":[],"mappings":"AACA,OAAO,EAMH,mBAAmB,EACnB,aAAa,EACb,wBAAwB,EACxB,MAAM,
|
1
|
+
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/record.ts"],"names":[],"mappings":"AACA,OAAO,EAMH,mBAAmB,EACnB,aAAa,EACb,wBAAwB,EACxB,MAAM,EACN,kBAAkB,EAElB,gBAAgB,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,mBAAmB,QAa3F;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,wBAAwB,QAO/G;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,QAEpE;AAED,wBAAgB,UAAU,CACtB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,aAAa,EAAE,EACxB,OAAO,CAAC,EAAE,gBAAgB,GAAG;IACzB,WAAW,CAAC,EAAE,kBAAkB,CAAC;CACpC,QA8CJ;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,QAM9D;AAED,eAAO,MAAM,aAAa;;;;;;CAMzB,CAAC"}
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import { AITable, AITableContextMenuItem, AITableActions } from '@ai-table/grid';
|
2
2
|
export declare const RemoveRecordsItem: (aiTable: AITable, actions: AITableActions) => AITableContextMenuItem;
|
3
|
+
export declare const InsertUpwardRecords: (aiTable: AITable, actions: AITableActions) => AITableContextMenuItem;
|
4
|
+
export declare const InsertDownwardRecords: (aiTable: AITable, actions: AITableActions) => AITableContextMenuItem;
|
3
5
|
export declare const CopyCellsItem: (aiTable: AITable, actions: AITableActions) => AITableContextMenuItem;
|
4
6
|
export declare const PasteCellsItem: (aiTable: AITable, actions: AITableActions) => AITableContextMenuItem;
|
5
7
|
//# sourceMappingURL=context-menu-item.d.ts.map
|
@@ -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;
|
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;AAMxB,eAAO,MAAM,iBAAiB,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,KAAG,sBAkB7E,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,KAAG,sBAwB/E,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,KAAG,sBAuBjF,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"}
|
@@ -103,20 +103,27 @@ function translateYjsEvent(aiTable, sharedType, event) {
|
|
103
103
|
return [];
|
104
104
|
}
|
105
105
|
function applyEvents(aiTable, sharedType, events) {
|
106
|
+
const actions = [];
|
106
107
|
events.forEach((event) => translateYjsEvent(aiTable, sharedType, event).forEach((item) => {
|
107
|
-
|
108
|
+
actions.push(item);
|
108
109
|
}));
|
110
|
+
return actions;
|
109
111
|
}
|
110
112
|
function applyYjsEvents(aiTable, sharedType, events) {
|
111
113
|
if (YjsAITable.isUndo(aiTable)) {
|
112
|
-
applyEvents(aiTable, sharedType, events);
|
114
|
+
const actions = applyEvents(aiTable, sharedType, events);
|
115
|
+
applyActions(actions, aiTable);
|
113
116
|
}
|
114
117
|
else {
|
115
118
|
YjsAITable.asRemote(aiTable, () => {
|
116
|
-
applyEvents(aiTable, sharedType, events);
|
119
|
+
const actions = applyEvents(aiTable, sharedType, events);
|
120
|
+
applyActions(actions, aiTable);
|
117
121
|
});
|
118
122
|
}
|
119
123
|
}
|
124
|
+
function applyActions(actions, aiTable) {
|
125
|
+
aiTable.apply(actions);
|
126
|
+
}
|
120
127
|
|
121
128
|
function updateFieldValue$2(aiTable, sharedType, action) {
|
122
129
|
const sharedRecords = sharedType.get('records');
|
@@ -414,6 +421,9 @@ var AITableStateI18nKey;
|
|
414
421
|
AITableStateI18nKey["removeField"] = "removeField";
|
415
422
|
AITableStateI18nKey["pasteOverMaxRecords"] = "pasteOverMaxRecords";
|
416
423
|
AITableStateI18nKey["pasteOverMaxFields"] = "pasteOverMaxFields";
|
424
|
+
AITableStateI18nKey["insertUpward"] = "insertUpward";
|
425
|
+
AITableStateI18nKey["insertDownward"] = "insertDownward";
|
426
|
+
AITableStateI18nKey["row"] = "row";
|
417
427
|
})(AITableStateI18nKey || (AITableStateI18nKey = {}));
|
418
428
|
const AITableI18nText = {
|
419
429
|
[AITableStateI18nKey.copyField]: '复制列',
|
@@ -426,7 +436,10 @@ const AITableI18nText = {
|
|
426
436
|
[AITableStateI18nKey.editField]: '编辑列',
|
427
437
|
[AITableStateI18nKey.removeField]: '删除列',
|
428
438
|
[AITableStateI18nKey.pasteOverMaxRecords]: '粘贴数据超过最大行数',
|
429
|
-
[AITableStateI18nKey.pasteOverMaxFields]: '粘贴数据超过最大列数'
|
439
|
+
[AITableStateI18nKey.pasteOverMaxFields]: '粘贴数据超过最大列数',
|
440
|
+
[AITableStateI18nKey.insertUpward]: '向上插入',
|
441
|
+
[AITableStateI18nKey.insertDownward]: '向下插入',
|
442
|
+
[AITableStateI18nKey.row]: '行'
|
430
443
|
};
|
431
444
|
const getDefaultI18nTextByKey = (key) => {
|
432
445
|
return AITableI18nText[key] || key;
|
@@ -706,7 +719,7 @@ function removeField(aiTable, path) {
|
|
706
719
|
};
|
707
720
|
aiTable.apply(operation);
|
708
721
|
}
|
709
|
-
function
|
722
|
+
function buildSetFieldAction(aiTable, value, path) {
|
710
723
|
const field = AITableQueries.getField(aiTable, path);
|
711
724
|
if (field) {
|
712
725
|
const properties = {};
|
@@ -728,7 +741,14 @@ function setField(aiTable, value, path) {
|
|
728
741
|
newProperties,
|
729
742
|
path
|
730
743
|
};
|
731
|
-
|
744
|
+
return operation;
|
745
|
+
}
|
746
|
+
return null;
|
747
|
+
}
|
748
|
+
function setField(aiTable, value, path) {
|
749
|
+
const action = buildSetFieldAction(aiTable, value, path);
|
750
|
+
if (action) {
|
751
|
+
aiTable.apply(action);
|
732
752
|
}
|
733
753
|
}
|
734
754
|
const FieldActions = {
|
@@ -763,9 +783,6 @@ const apply = (aiTable, records, fields, views, action) => {
|
|
763
783
|
break;
|
764
784
|
}
|
765
785
|
case ActionName.AddRecord: {
|
766
|
-
if (!action.record.positions) {
|
767
|
-
action.record.positions = createDefaultPositions(aiTable.views(), aiTable.activeViewId(), aiTable.records(), records.length);
|
768
|
-
}
|
769
786
|
records.push(action.record);
|
770
787
|
break;
|
771
788
|
}
|
@@ -878,11 +895,13 @@ const apply = (aiTable, records, fields, views, action) => {
|
|
878
895
|
};
|
879
896
|
};
|
880
897
|
const GeneralActions = {
|
881
|
-
transform(aiTable,
|
898
|
+
transform(aiTable, actions) {
|
882
899
|
const records = createDraft(aiTable.records());
|
883
900
|
const fields = createDraft(aiTable.fields());
|
884
901
|
const views = createDraft(aiTable.views());
|
885
|
-
|
902
|
+
actions.forEach((action) => {
|
903
|
+
apply(aiTable, records, fields, views, action);
|
904
|
+
});
|
886
905
|
const newFields = finishDraft(fields);
|
887
906
|
const newRecords = finishDraft(records);
|
888
907
|
const newViews = finishDraft(views);
|
@@ -898,12 +917,16 @@ const GeneralActions = {
|
|
898
917
|
}
|
899
918
|
};
|
900
919
|
|
901
|
-
function
|
902
|
-
const
|
920
|
+
function buildSetRecordPositionsActon(aiTable, positions, path) {
|
921
|
+
const action = {
|
903
922
|
type: ActionName.SetRecordPositions,
|
904
923
|
positions,
|
905
924
|
path
|
906
925
|
};
|
926
|
+
return action;
|
927
|
+
}
|
928
|
+
function setRecordPositions(aiTable, positions, path) {
|
929
|
+
const operation = buildSetRecordPositionsActon(aiTable, positions, path);
|
907
930
|
aiTable.apply(operation);
|
908
931
|
}
|
909
932
|
const PositionsActions = {
|
@@ -934,26 +957,39 @@ function updateSystemFieldValue(aiTable, path, updatedInfo) {
|
|
934
957
|
aiTable.apply(operation);
|
935
958
|
}
|
936
959
|
function addRecord(aiTable, record) {
|
960
|
+
addRecords$1(aiTable, [record]);
|
961
|
+
}
|
962
|
+
function addRecords$1(aiTable, records, options) {
|
937
963
|
const invalidFieldValues = [];
|
938
|
-
const
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
964
|
+
const sortRecords = options?.sortRecords ||
|
965
|
+
getSortRecords(aiTable, aiTable.records(), aiTable.views().find((item) => item._id === aiTable.activeViewId()));
|
966
|
+
const targetIndex = options?.targetId
|
967
|
+
? sortRecords.findIndex((item) => item._id === options.targetId)
|
968
|
+
: options?.targetIndex || sortRecords.length - 1;
|
969
|
+
const positions = createMultiplePositions(aiTable.views(), aiTable.activeViewId(), sortRecords, targetIndex, records.length, options?.isInsertBefore);
|
970
|
+
records.forEach((record, index) => {
|
971
|
+
Object.entries(record.values).every(([fieldId, value]) => {
|
972
|
+
const field = AITableQueries.getField(aiTable, [fieldId]);
|
973
|
+
const fieldModel = field && FieldModelMap[field.type];
|
974
|
+
const result = fieldModel ? fieldModel.isValid(value) : false;
|
975
|
+
if (!result) {
|
976
|
+
invalidFieldValues.push(`field_id: ${fieldId}, field_type: ${field?.type}, value: ${value}`);
|
977
|
+
}
|
978
|
+
return result;
|
979
|
+
});
|
946
980
|
});
|
947
|
-
if (
|
981
|
+
if (invalidFieldValues.length) {
|
982
|
+
console.error(`Invalid field values at add records. invalidFieldValues: ${invalidFieldValues}`);
|
983
|
+
return;
|
984
|
+
}
|
985
|
+
records.forEach((record, index) => {
|
986
|
+
record.positions = positions[index];
|
948
987
|
const operation = {
|
949
988
|
type: ActionName.AddRecord,
|
950
989
|
record
|
951
990
|
};
|
952
991
|
aiTable.apply(operation);
|
953
|
-
}
|
954
|
-
else {
|
955
|
-
console.error(`Invalid field values at add record. invalidFieldValues: ${invalidFieldValues}`);
|
956
|
-
}
|
992
|
+
});
|
957
993
|
}
|
958
994
|
function removeRecord(aiTable, path) {
|
959
995
|
const operation = {
|
@@ -964,6 +1000,7 @@ function removeRecord(aiTable, path) {
|
|
964
1000
|
}
|
965
1001
|
const RecordActions = {
|
966
1002
|
addRecord,
|
1003
|
+
addRecords: addRecords$1,
|
967
1004
|
updateFieldValue: updateFieldValue$1,
|
968
1005
|
removeRecord,
|
969
1006
|
updateSystemFieldValue
|
@@ -1032,31 +1069,49 @@ const Actions = {
|
|
1032
1069
|
...PositionsActions
|
1033
1070
|
};
|
1034
1071
|
|
1035
|
-
function
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1072
|
+
function createPositions(views, activeId, data, index) {
|
1073
|
+
return createMultiplePositions(views, activeId, data, index)[0];
|
1074
|
+
}
|
1075
|
+
function createMultiplePositions(views, activeId, data, targetIndex = data.length - 1, count = 1, isInsertUpward = false) {
|
1076
|
+
const positionsOfItems = getPositions(activeId, data, targetIndex, count, isInsertUpward);
|
1077
|
+
let maxPosition = getMaxPosition(data, activeId);
|
1078
|
+
const positions = positionsOfItems.map((itemPositions) => {
|
1079
|
+
const viewPositions = {};
|
1080
|
+
maxPosition += 1;
|
1081
|
+
views.forEach((element) => {
|
1082
|
+
if (element._id === activeId) {
|
1083
|
+
viewPositions[element._id] = itemPositions;
|
1084
|
+
}
|
1085
|
+
else {
|
1086
|
+
viewPositions[element._id] = maxPosition;
|
1087
|
+
}
|
1088
|
+
});
|
1089
|
+
return viewPositions;
|
1090
|
+
});
|
1091
|
+
return positions;
|
1092
|
+
}
|
1093
|
+
function getPositions(activeId, data, targetIndex = data.length - 1, count = 1, isInsertBefore = false) {
|
1094
|
+
let startPosition = data.length - 1;
|
1095
|
+
let endPosition = startPosition + count + 1;
|
1096
|
+
if (data[targetIndex]) {
|
1097
|
+
if (isInsertBefore) {
|
1098
|
+
endPosition = data[targetIndex].positions[activeId];
|
1099
|
+
startPosition = targetIndex - 1 >= 0 ? data[targetIndex - 1].positions[activeId] : endPosition - count - 1;
|
1041
1100
|
}
|
1042
1101
|
else {
|
1043
|
-
|
1102
|
+
startPosition = data[targetIndex].positions[activeId];
|
1103
|
+
endPosition =
|
1104
|
+
targetIndex + 1 < data.length
|
1105
|
+
? data[targetIndex + 1].positions[activeId]
|
1106
|
+
: data[targetIndex].positions[activeId] + count + 1;
|
1044
1107
|
}
|
1045
|
-
}
|
1108
|
+
}
|
1109
|
+
const step = (endPosition - startPosition) / (count + 1);
|
1110
|
+
const positions = ___default.range(startPosition + step, endPosition, step);
|
1046
1111
|
return positions;
|
1047
1112
|
}
|
1048
1113
|
function getPosition(data, activeViewId, index) {
|
1049
|
-
|
1050
|
-
if (index !== 0 && index !== data.length) {
|
1051
|
-
const previousViewPosition = data[index - 1].positions[activeViewId];
|
1052
|
-
const nextViewPosition = data[index].positions[activeViewId];
|
1053
|
-
position = (previousViewPosition + nextViewPosition) / 2;
|
1054
|
-
}
|
1055
|
-
else {
|
1056
|
-
const maxPosition = getMaxPosition(data, activeViewId);
|
1057
|
-
position = maxPosition + 1;
|
1058
|
-
}
|
1059
|
-
return position;
|
1114
|
+
return getPositions(activeViewId, data, index)[0];
|
1060
1115
|
}
|
1061
1116
|
function getMaxPosition(data, activeViewId) {
|
1062
1117
|
return data.reduce((maxPosition, item) => {
|
@@ -1091,37 +1146,49 @@ function addView(aiTable, type, viewId) {
|
|
1091
1146
|
};
|
1092
1147
|
}
|
1093
1148
|
ViewActions.addView(aiTable, originViewId, newView, type === 'duplicate');
|
1149
|
+
const actions = [];
|
1094
1150
|
aiTable.records().forEach((record, index) => {
|
1095
|
-
|
1151
|
+
const action = buildSetRecordPositionsActon(aiTable, { [newId]: record.positions[originViewId] }, [index]);
|
1152
|
+
actions.push(action);
|
1096
1153
|
});
|
1097
1154
|
aiTable.fields().forEach((field) => {
|
1098
|
-
|
1155
|
+
const action = buildSetFieldAction(aiTable, {
|
1099
1156
|
positions: {
|
1100
1157
|
...field.positions,
|
1101
1158
|
[newId]: field.positions[originViewId]
|
1102
1159
|
}
|
1103
1160
|
}, [field._id]);
|
1161
|
+
if (action) {
|
1162
|
+
actions.push(action);
|
1163
|
+
}
|
1104
1164
|
});
|
1165
|
+
aiTable.apply(actions);
|
1105
1166
|
return newView;
|
1106
1167
|
}
|
1107
1168
|
function removeView(aiTable, records, fields, activeViewId) {
|
1169
|
+
ViewActions.removeView(aiTable, [activeViewId]);
|
1170
|
+
const actions = [];
|
1108
1171
|
records.forEach((record, index) => {
|
1109
|
-
|
1172
|
+
const action = buildSetRecordPositionsActon(aiTable, { [activeViewId]: undefined }, [index]);
|
1173
|
+
actions.push(action);
|
1110
1174
|
});
|
1111
1175
|
fields.forEach((field) => {
|
1112
1176
|
const positions = { ...field.positions };
|
1113
1177
|
delete positions[activeViewId];
|
1114
|
-
|
1178
|
+
const action = buildSetFieldAction(aiTable, {
|
1115
1179
|
positions
|
1116
1180
|
}, [field._id]);
|
1181
|
+
if (action) {
|
1182
|
+
actions.push(action);
|
1183
|
+
}
|
1117
1184
|
});
|
1118
|
-
|
1185
|
+
aiTable.apply(actions);
|
1119
1186
|
}
|
1120
1187
|
function sortViews(data) {
|
1121
1188
|
return [...data].sort((a, b) => (a.position ?? data.indexOf(a)) - (b.position ?? data.indexOf(b)));
|
1122
1189
|
}
|
1123
1190
|
|
1124
|
-
function addFields(aiTable, options
|
1191
|
+
function addFields(aiTable, options) {
|
1125
1192
|
const { defaultValue, isDuplicate, originId } = options;
|
1126
1193
|
const fields = aiTable.gridData().fields;
|
1127
1194
|
const fieldsMap = aiTable.fieldsMap();
|
@@ -1134,11 +1201,11 @@ function addFields(aiTable, options, updatedInfo) {
|
|
1134
1201
|
const currentFieldIndex = fields.findIndex((item) => item._id === originId);
|
1135
1202
|
newField.positions = {
|
1136
1203
|
...newField.positions,
|
1137
|
-
[activeViewId]: getPosition(fields, activeViewId, currentFieldIndex
|
1204
|
+
[activeViewId]: getPosition(fields, activeViewId, currentFieldIndex - 1)
|
1138
1205
|
};
|
1139
1206
|
}
|
1140
1207
|
else {
|
1141
|
-
newField.positions =
|
1208
|
+
newField.positions = createPositions(aiTable.views(), aiTable.activeViewId(), aiTable.gridData().fields, fields.length);
|
1142
1209
|
}
|
1143
1210
|
Actions.addField(aiTable, newField, originId, isDuplicate);
|
1144
1211
|
}
|
@@ -1166,10 +1233,10 @@ function addRecords(aiTable, trackableEntity, options) {
|
|
1166
1233
|
return [...value];
|
1167
1234
|
});
|
1168
1235
|
}
|
1169
|
-
newRecordIds.
|
1170
|
-
|
1171
|
-
Actions.addRecord(aiTable, newRecord);
|
1236
|
+
const newRecords = newRecordIds.map((id, index) => {
|
1237
|
+
return { _id: id, short_id: newRecordShortIds[index], values: newRecordValues, ...trackableEntity };
|
1172
1238
|
});
|
1239
|
+
Actions.addRecords(aiTable, newRecords, options);
|
1173
1240
|
}
|
1174
1241
|
function getDefaultRecordValues(aiTable, isDuplicate = false, recordId) {
|
1175
1242
|
let newRecordValues = {};
|
@@ -1207,7 +1274,7 @@ function updateRecordsUpdatedInfo(aiTable, updatedInfo) {
|
|
1207
1274
|
|
1208
1275
|
const FLUSHING = new WeakMap();
|
1209
1276
|
|
1210
|
-
function moveFields(aiTable, options
|
1277
|
+
function moveFields(aiTable, options) {
|
1211
1278
|
const { path, newPath } = options;
|
1212
1279
|
Actions.moveField(aiTable, path, newPath);
|
1213
1280
|
}
|
@@ -1259,8 +1326,9 @@ const withState = (aiTable) => {
|
|
1259
1326
|
const viewTable = aiTable;
|
1260
1327
|
viewTable.actions = [];
|
1261
1328
|
viewTable.apply = (action) => {
|
1262
|
-
|
1263
|
-
|
1329
|
+
const actions = Array.isArray(action) ? action : [action];
|
1330
|
+
viewTable.actions.push(...actions);
|
1331
|
+
Actions.transform(viewTable, actions);
|
1264
1332
|
if (!FLUSHING.get(viewTable)) {
|
1265
1333
|
FLUSHING.set(viewTable, true);
|
1266
1334
|
Promise.resolve().then(() => {
|
@@ -1338,6 +1406,41 @@ const RemoveRecordsItem = (aiTable, actions) => {
|
|
1338
1406
|
}
|
1339
1407
|
};
|
1340
1408
|
};
|
1409
|
+
const InsertUpwardRecords = (aiTable, actions) => {
|
1410
|
+
return {
|
1411
|
+
type: 'insertUpwardRecords',
|
1412
|
+
name: getStateI18nTextByKey(aiTable, AITableStateI18nKey.insertUpward),
|
1413
|
+
nameSuffix: getStateI18nTextByKey(aiTable, AITableStateI18nKey.row),
|
1414
|
+
icon: 'table-insert-rows-top',
|
1415
|
+
isInputNumber: true,
|
1416
|
+
count: 1,
|
1417
|
+
exec: (aiTable, targetName, position, aiTableGridSelectionService, notifyService, count) => {
|
1418
|
+
let selectedRecordIds = AITable.getActiveRecordIds(aiTable);
|
1419
|
+
actions.addRecord({
|
1420
|
+
targetId: selectedRecordIds[0],
|
1421
|
+
count,
|
1422
|
+
isInsertBefore: true
|
1423
|
+
});
|
1424
|
+
}
|
1425
|
+
};
|
1426
|
+
};
|
1427
|
+
const InsertDownwardRecords = (aiTable, actions) => {
|
1428
|
+
return {
|
1429
|
+
type: 'insertDownwardRecords',
|
1430
|
+
name: getStateI18nTextByKey(aiTable, AITableStateI18nKey.insertDownward),
|
1431
|
+
nameSuffix: getStateI18nTextByKey(aiTable, AITableStateI18nKey.row),
|
1432
|
+
icon: 'table-insert-rows-down',
|
1433
|
+
count: 1,
|
1434
|
+
isInputNumber: true,
|
1435
|
+
exec: (aiTable, targetName, position, aiTableGridSelectionService, notifyService, count) => {
|
1436
|
+
let selectedRecordIds = AITable.getActiveRecordIds(aiTable);
|
1437
|
+
actions.addRecord({
|
1438
|
+
targetId: selectedRecordIds[0],
|
1439
|
+
count
|
1440
|
+
});
|
1441
|
+
}
|
1442
|
+
};
|
1443
|
+
};
|
1341
1444
|
const CopyCellsItem = (aiTable, actions) => {
|
1342
1445
|
return {
|
1343
1446
|
type: 'copyCells',
|
@@ -1394,5 +1497,5 @@ const VIEW_ACTIONS = [ActionName.SetView, ActionName.AddView, ActionName.RemoveV
|
|
1394
1497
|
* Generated bundle index. Do not edit.
|
1395
1498
|
*/
|
1396
1499
|
|
1397
|
-
export { AITableStateI18nKey, Actions, CopyCellsItem, CopyFieldPropertyItem, DividerMenuItem, EditFieldPropertyItem, FLUSHING, PasteCellsItem, RemoveRecordsItem, UndoManagerService, VIEW_ACTIONS, YjsAITable, actionMappers, addFields, addRecords, addView, applyActionOps, applyEvents, applyYjsEvents, buildFieldsByView, buildRecordsByView, buildRemoveFieldItem,
|
1500
|
+
export { AITableStateI18nKey, Actions, CopyCellsItem, CopyFieldPropertyItem, DividerMenuItem, EditFieldPropertyItem, FLUSHING, InsertDownwardRecords, InsertUpwardRecords, PasteCellsItem, RemoveRecordsItem, UndoManagerService, VIEW_ACTIONS, YjsAITable, actionMappers, addFields, addRecords, addView, applyActionOps, applyActions, applyEvents, applyYjsEvents, buildFieldsByView, buildRecordsByView, buildRemoveFieldItem, createMultiplePositions, createPositions, createSharedType, doFilter, generateCopyName, getDataBySharedType, getDefaultI18nTextByKey, getDefaultRecordDataByFilter, getDefaultRecordValues, getFieldPositionInView, getFieldsSizeMap, getFilteredRecords, getMaxPosition, getPosition, getPositions, getRecordsBySharedJson, getSharedTypeByData, getSortFields, getSortRecords, getStateI18nTextByKey, isPathEqual, moveFields, moveRecords, removeView, sortByViewPosition, sortRecordsBySortInfo, sortViews, toSharedType, translateYjsEvent, updateFieldValue, updateRecordsUpdatedInfo, withState };
|
1398
1501
|
//# sourceMappingURL=ai-table-state.mjs.map
|