@ai-table/state 0.3.3 → 0.4.0-1
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/group.d.ts +0 -15
- package/action/group.d.ts.map +1 -1
- package/action/index.d.ts +1 -8
- package/action/index.d.ts.map +1 -1
- package/action/view.d.ts +3 -2
- package/action/view.d.ts.map +1 -1
- package/constants/field-menu-item.d.ts +2 -2
- package/constants/field-menu-item.d.ts.map +1 -1
- package/fesm2022/ai-table-state.mjs +84 -141
- package/fesm2022/ai-table-state.mjs.map +1 -1
- package/package.json +1 -1
- package/utils/build.d.ts +1 -1
- package/utils/build.d.ts.map +1 -1
- package/utils/field/build-fields.d.ts +3 -0
- package/utils/field/build-fields.d.ts.map +1 -0
- package/utils/field/index.d.ts +1 -0
- package/utils/field/index.d.ts.map +1 -1
- package/utils/field/position-field.d.ts +1 -2
- package/utils/field/position-field.d.ts.map +1 -1
- package/utils/record/add-records.d.ts +2 -2
- package/utils/record/add-records.d.ts.map +1 -1
- package/utils/record/filter.d.ts.map +1 -1
- package/utils/record/update-field-value.d.ts.map +1 -1
- package/utils/field/stat-field.d.ts +0 -3
- package/utils/field/stat-field.d.ts.map +0 -1
package/action/group.d.ts
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
import { AITableGroupField, SortDirection } from '@ai-table/utils';
|
|
2
1
|
import { AIViewTable } from '../types/ai-table';
|
|
3
|
-
declare function setViewGroup(aiTable: AIViewTable, groups: AITableGroupField[] | null): void;
|
|
4
|
-
declare function setCollapsedGroup(aiTable: AIViewTable, collapsedGroupIds: string[]): void;
|
|
5
2
|
declare function toggleGroupCollapse(aiTable: AIViewTable, groupId: string): void;
|
|
6
|
-
declare function addGroupField(aiTable: AIViewTable, fieldId: string, direction?: SortDirection): void;
|
|
7
|
-
declare function removeGroupField(aiTable: AIViewTable, fieldId: string): void;
|
|
8
|
-
declare function updateGroupFieldDirection(aiTable: AIViewTable, fieldId: string, direction: SortDirection): void;
|
|
9
|
-
declare function reorderGroupFields(aiTable: AIViewTable, fromIndex: number, toIndex: number): void;
|
|
10
|
-
declare function clearAllGroups(aiTable: AIViewTable): void;
|
|
11
3
|
export declare const GroupActions: {
|
|
12
|
-
setViewGroup: typeof setViewGroup;
|
|
13
|
-
setCollapsedGroup: typeof setCollapsedGroup;
|
|
14
4
|
toggleGroupCollapse: typeof toggleGroupCollapse;
|
|
15
|
-
addGroupField: typeof addGroupField;
|
|
16
|
-
removeGroupField: typeof removeGroupField;
|
|
17
|
-
updateGroupFieldDirection: typeof updateGroupFieldDirection;
|
|
18
|
-
reorderGroupFields: typeof reorderGroupFields;
|
|
19
|
-
clearAllGroups: typeof clearAllGroups;
|
|
20
5
|
};
|
|
21
6
|
export {};
|
|
22
7
|
//# sourceMappingURL=group.d.ts.map
|
package/action/group.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/group.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/group.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAsBhD,iBAAS,mBAAmB,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,QAOjE;AAED,eAAO,MAAM,YAAY;;CAExB,CAAC"}
|
package/action/index.d.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
export declare const Actions: {
|
|
2
|
-
setViewGroup: (aiTable: import("@ai-table/state").AIViewTable, groups: import("@ai-table/utils").AITableGroupField[] | null) => void;
|
|
3
|
-
setCollapsedGroup: (aiTable: import("@ai-table/state").AIViewTable, collapsedGroupIds: string[]) => void;
|
|
4
2
|
toggleGroupCollapse: (aiTable: import("@ai-table/state").AIViewTable, groupId: string) => void;
|
|
5
|
-
addGroupField: (aiTable: import("@ai-table/state").AIViewTable, fieldId: string, direction?: import("@ai-table/utils").SortDirection) => void;
|
|
6
|
-
removeGroupField: (aiTable: import("@ai-table/state").AIViewTable, fieldId: string) => void;
|
|
7
|
-
updateGroupFieldDirection: (aiTable: import("@ai-table/state").AIViewTable, fieldId: string, direction: import("@ai-table/utils").SortDirection) => void;
|
|
8
|
-
reorderGroupFields: (aiTable: import("@ai-table/state").AIViewTable, fromIndex: number, toIndex: number) => void;
|
|
9
|
-
clearAllGroups: (aiTable: import("@ai-table/state").AIViewTable) => void;
|
|
10
3
|
setRecordPositions: typeof import("./position").setRecordPositions;
|
|
11
4
|
resetAllRecordsPositions: typeof import("./position").resetAllRecordsPositions;
|
|
12
5
|
resetAllFieldsPositions: typeof import("./position").resetAllFieldsPositions;
|
|
@@ -14,7 +7,7 @@ export declare const Actions: {
|
|
|
14
7
|
setView: (aiTable: import("@ai-table/state").AIViewTable, value: Partial<import("@ai-table/utils").AITableView>, path: [string]) => void;
|
|
15
8
|
addView: (aiTable: import("@ai-table/state").AIViewTable, originId: string, newView: import("@ai-table/utils").AITableView, isDuplicate?: boolean) => void;
|
|
16
9
|
removeView: (aiTable: import("@ai-table/state").AIViewTable, path: [string]) => void;
|
|
17
|
-
|
|
10
|
+
setRecordHeightType: (aiTable: import("@ai-table/state").AIViewTable, recordHeightType: import("@ai-table/utils").AITableRecordHeightType) => void;
|
|
18
11
|
addField: typeof import("./field").addField;
|
|
19
12
|
removeField: typeof import("./field").removeField;
|
|
20
13
|
setField: typeof import("./field").setField;
|
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":"AAOA,eAAO,MAAM,OAAO
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/index.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;CAOnB,CAAC;AAEF,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAE3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC"}
|
package/action/view.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { AITableView, SetViewAction } from '@ai-table/utils';
|
|
1
|
+
import { AITableRecordHeightType, AITableView, SetViewAction } from '@ai-table/utils';
|
|
2
2
|
import { AIViewTable } from '../types/ai-table';
|
|
3
3
|
export declare function buildSetViewAction(aiTable: AIViewTable, value: Partial<AITableView>, path: [string]): SetViewAction | null;
|
|
4
4
|
declare function setView(aiTable: AIViewTable, value: Partial<AITableView>, path: [string]): void;
|
|
5
5
|
declare function addView(aiTable: AIViewTable, originId: string, newView: AITableView, isDuplicate?: boolean): void;
|
|
6
6
|
declare function removeView(aiTable: AIViewTable, path: [string]): void;
|
|
7
|
+
declare function setRecordHeightType(aiTable: AIViewTable, recordHeightType: AITableRecordHeightType): void;
|
|
7
8
|
export declare const ViewActions: {
|
|
8
9
|
setView: typeof setView;
|
|
9
10
|
addView: typeof addView;
|
|
10
11
|
removeView: typeof removeView;
|
|
11
|
-
|
|
12
|
+
setRecordHeightType: typeof setRecordHeightType;
|
|
12
13
|
};
|
|
13
14
|
export {};
|
|
14
15
|
//# sourceMappingURL=view.d.ts.map
|
package/action/view.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/view.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../../packages/state/src/action/view.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,uBAAuB,EACvB,WAAW,EAIX,aAAa,EAEhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,wBA0BnG;AAED,iBAAS,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,QAKjF;AAED,iBAAS,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,CAAC,EAAE,OAAO,QAwCnG;AAED,iBAAS,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,QAMvD;AAED,iBAAS,mBAAmB,CAAC,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,uBAAuB,QAkB3F;AAED,eAAO,MAAM,WAAW;;;;;CAKvB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AITable, AITableActions } from '@ai-table/grid';
|
|
2
2
|
import { ElementRef, Signal } from '@angular/core';
|
|
3
3
|
import { AIViewTable } from '../types';
|
|
4
|
-
import {
|
|
4
|
+
import { AITableField, AITableReferences, SetFieldOptions } from '@ai-table/utils';
|
|
5
5
|
export declare const DividerMenuItem: {
|
|
6
6
|
type: string;
|
|
7
7
|
};
|
|
@@ -15,7 +15,7 @@ export declare const EditFieldPropertyItem: (aiTable: AITable, actions: AITableA
|
|
|
15
15
|
}) => import("ngx-tethys/popover").ThyPopoverRef<unknown, unknown, unknown> | undefined;
|
|
16
16
|
};
|
|
17
17
|
export declare const updateFieldAndValues: (aiTable: AIViewTable, references: AITableReferences, actions: AITableActions, options: SetFieldOptions) => void;
|
|
18
|
-
export declare const CopyFieldPropertyItem: (aiTable: AITable,
|
|
18
|
+
export declare const CopyFieldPropertyItem: (aiTable: AITable, actions: AITableActions) => {
|
|
19
19
|
type: string;
|
|
20
20
|
name: string;
|
|
21
21
|
icon: string;
|
|
@@ -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,EAEH,OAAO,EACP,cAAc,EAKjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGvC,OAAO,
|
|
1
|
+
{"version":3,"file":"field-menu-item.d.ts","sourceRoot":"","sources":["../../../packages/state/src/constants/field-menu-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,OAAO,EACP,cAAc,EAKjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGvC,OAAO,EAEH,YAAY,EACZ,iBAAiB,EAIjB,eAAe,EAIlB,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,eAAe;;CAE3B,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,EAAE,YAAY,iBAAiB;;;;oBAK7F,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;CAqBzC,CAAC;AAEH,eAAO,MAAM,oBAAoB,GAC7B,SAAS,WAAW,EACpB,YAAY,iBAAiB,EAC7B,SAAS,cAAc,EACvB,SAAS,eAAe,SA6C3B,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc;;;;oBAMvD,WAAW,SAAS,MAAM,CAAC,YAAY,CAAC;;CA2B/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, getValuesByCustomFieldValues, getPositionsBySystemFieldValues, getTrackableEntityBySystemFieldValues, getShortIdBySystemFieldValues, getIdBySystemFieldValues, AITableFilterLogical, AITableFilterOperation, AITableFieldType, isEmpty, sortByViewPosition, idCreator,
|
|
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, 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, shortIdCreator, generateNewName,
|
|
6
|
+
import { FieldModelMap, AITableQueries, isSystemField, AITableRowType, shortIdCreator, generateNewName, idsCreator, shortIdsCreator, closeExpendCell, setSelection, buildNormalLinearRows, AITable, getColumnIndicesSizeMap, getI18nTextByKey, AITableGridI18nKey, generateNewFieldName, AI_TABLE_GRID_FIELD_SERVICE_MAP, clearSelection, isMac } from '@ai-table/grid';
|
|
7
7
|
import { nanoid } from 'nanoid';
|
|
8
8
|
import * as _ from 'lodash';
|
|
9
9
|
import ___default, { map, unionBy } from 'lodash';
|
|
@@ -462,8 +462,8 @@ function getFilteredRecords(aiTable, records, fields, activeView) {
|
|
|
462
462
|
if (!conditions) {
|
|
463
463
|
return records;
|
|
464
464
|
}
|
|
465
|
-
const
|
|
466
|
-
if (!
|
|
465
|
+
const validConditions = conditions.filter((item) => item.operation) || [];
|
|
466
|
+
if (!validConditions.length) {
|
|
467
467
|
return records;
|
|
468
468
|
}
|
|
469
469
|
const recordsWillHidden = aiTable.recordsWillHidden();
|
|
@@ -471,13 +471,16 @@ function getFilteredRecords(aiTable, records, fields, activeView) {
|
|
|
471
471
|
if (recordsWillHidden && recordsWillHidden.length && recordsWillHidden.includes(record._id)) {
|
|
472
472
|
return true;
|
|
473
473
|
}
|
|
474
|
-
return checkConditions(aiTable, fields, record, { conditions:
|
|
474
|
+
return checkConditions(aiTable, fields, record, { conditions: validConditions, condition_logical });
|
|
475
475
|
});
|
|
476
476
|
}
|
|
477
477
|
function checkConditions(aiTable, fields, record, filterConditions) {
|
|
478
478
|
if (!record) {
|
|
479
479
|
return false;
|
|
480
480
|
}
|
|
481
|
+
if (!aiTable.activeViewId?.() || !aiTable.viewsMap?.()) {
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
481
484
|
if (!filterConditions?.conditions) {
|
|
482
485
|
const conditions = aiTable.viewsMap()[aiTable.activeViewId()].settings?.conditions;
|
|
483
486
|
const conditionLogical = aiTable.viewsMap()[aiTable.activeViewId()].settings?.condition_logical;
|
|
@@ -589,18 +592,19 @@ function getSortFields(aiTable, fields, activeView) {
|
|
|
589
592
|
return sortByViewPosition(fields, activeView);
|
|
590
593
|
}
|
|
591
594
|
|
|
592
|
-
function
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
}
|
|
595
|
+
function buildViewFields(fields, activeView) {
|
|
596
|
+
const activeViewId = activeView._id;
|
|
597
|
+
return fields.map((field) => {
|
|
598
|
+
const statType = field.stat_types?.[activeViewId];
|
|
599
|
+
const width = field.widths?.[activeViewId];
|
|
600
|
+
const newField = { ...field };
|
|
601
|
+
if (statType) {
|
|
602
|
+
newField.stat_type = statType;
|
|
603
|
+
}
|
|
604
|
+
if (width) {
|
|
605
|
+
newField.width = width;
|
|
606
|
+
}
|
|
607
|
+
return newField;
|
|
604
608
|
});
|
|
605
609
|
}
|
|
606
610
|
|
|
@@ -1068,7 +1072,7 @@ const GeneralActions = {
|
|
|
1068
1072
|
transform(aiTable, actions) {
|
|
1069
1073
|
const records = createDraft(aiTable.records());
|
|
1070
1074
|
const fields = createDraft(aiTable.fields());
|
|
1071
|
-
const views = createDraft(aiTable.views());
|
|
1075
|
+
const views = createDraft(aiTable.views?.() || []);
|
|
1072
1076
|
actions.forEach((action) => {
|
|
1073
1077
|
apply(aiTable, records, fields, views, action);
|
|
1074
1078
|
});
|
|
@@ -1081,8 +1085,8 @@ const GeneralActions = {
|
|
|
1081
1085
|
if (newRecords !== aiTable.records()) {
|
|
1082
1086
|
aiTable.records.set(newRecords);
|
|
1083
1087
|
}
|
|
1084
|
-
if (newViews !== aiTable.views()) {
|
|
1085
|
-
aiTable.views
|
|
1088
|
+
if (newViews !== (aiTable.views?.() || [])) {
|
|
1089
|
+
aiTable.views?.set(newViews);
|
|
1086
1090
|
}
|
|
1087
1091
|
}
|
|
1088
1092
|
};
|
|
@@ -1169,11 +1173,29 @@ function removeView$1(aiTable, path) {
|
|
|
1169
1173
|
};
|
|
1170
1174
|
aiTable.apply(operation);
|
|
1171
1175
|
}
|
|
1176
|
+
function setRecordHeightType(aiTable, recordHeightType) {
|
|
1177
|
+
const viewId = aiTable.activeViewId();
|
|
1178
|
+
const view = aiTable.views().find((v) => v._id === viewId);
|
|
1179
|
+
if (!view)
|
|
1180
|
+
return;
|
|
1181
|
+
const currentSettings = view.settings || {};
|
|
1182
|
+
const newSettings = {
|
|
1183
|
+
...currentSettings,
|
|
1184
|
+
record_height_type: recordHeightType
|
|
1185
|
+
};
|
|
1186
|
+
const operation = {
|
|
1187
|
+
type: ActionName.SetView,
|
|
1188
|
+
properties: { settings: currentSettings },
|
|
1189
|
+
newProperties: { settings: newSettings },
|
|
1190
|
+
path: [viewId]
|
|
1191
|
+
};
|
|
1192
|
+
aiTable.apply(operation);
|
|
1193
|
+
}
|
|
1172
1194
|
const ViewActions = {
|
|
1173
1195
|
setView,
|
|
1174
1196
|
addView: addView$1,
|
|
1175
1197
|
removeView: removeView$1,
|
|
1176
|
-
|
|
1198
|
+
setRecordHeightType
|
|
1177
1199
|
};
|
|
1178
1200
|
|
|
1179
1201
|
function buildSetRecordPositionsAction(aiTable, positions, path) {
|
|
@@ -1448,14 +1470,14 @@ function addView(aiTable, type, viewId) {
|
|
|
1448
1470
|
ViewActions.addView(aiTable, originViewId, newView, type === 'duplicate');
|
|
1449
1471
|
const actions = [];
|
|
1450
1472
|
aiTable.records().forEach((record, index) => {
|
|
1451
|
-
const action = buildSetRecordPositionsAction(aiTable, { [newId]: record
|
|
1473
|
+
const action = buildSetRecordPositionsAction(aiTable, { [newId]: record?.positions?.[originViewId] }, [index]);
|
|
1452
1474
|
actions.push(action);
|
|
1453
1475
|
});
|
|
1454
1476
|
aiTable.fields().forEach((field) => {
|
|
1455
1477
|
const action = buildSetFieldAction(aiTable, {
|
|
1456
1478
|
positions: {
|
|
1457
1479
|
...field.positions,
|
|
1458
|
-
[newId]: field
|
|
1480
|
+
[newId]: field?.positions?.[originViewId]
|
|
1459
1481
|
}
|
|
1460
1482
|
}, [field._id]);
|
|
1461
1483
|
if (action) {
|
|
@@ -1489,31 +1511,31 @@ function sortViews(data) {
|
|
|
1489
1511
|
}
|
|
1490
1512
|
|
|
1491
1513
|
function findNextItemByPosition(aiTable, targetId, items, itemsMap) {
|
|
1492
|
-
const viewId = aiTable.activeViewId();
|
|
1514
|
+
const viewId = aiTable.activeViewId?.();
|
|
1493
1515
|
const targetItem = itemsMap[targetId];
|
|
1494
|
-
const targetPosition = targetItem
|
|
1516
|
+
const targetPosition = targetItem?.positions?.[viewId] || 0;
|
|
1495
1517
|
let nextItem = null;
|
|
1496
1518
|
for (const item of items) {
|
|
1497
|
-
const pos = item
|
|
1498
|
-
if (pos > targetPosition && (nextItem === null || pos < nextItem
|
|
1519
|
+
const pos = item?.positions?.[viewId] || 0;
|
|
1520
|
+
if (pos > targetPosition && (nextItem === null || pos < nextItem?.positions?.[viewId])) {
|
|
1499
1521
|
nextItem = item;
|
|
1500
1522
|
}
|
|
1501
1523
|
}
|
|
1502
1524
|
return nextItem;
|
|
1503
1525
|
}
|
|
1504
1526
|
function findMaxItemByPosition(aiTable, items) {
|
|
1505
|
-
const viewId = aiTable.activeViewId();
|
|
1527
|
+
const viewId = aiTable.activeViewId?.();
|
|
1506
1528
|
let maxItem = items[0];
|
|
1507
1529
|
for (const item of items) {
|
|
1508
|
-
const pos = item
|
|
1509
|
-
if (pos > maxItem
|
|
1530
|
+
const pos = item?.positions?.[viewId] || 0;
|
|
1531
|
+
if (pos > maxItem?.positions?.[viewId]) {
|
|
1510
1532
|
maxItem = item;
|
|
1511
1533
|
}
|
|
1512
1534
|
}
|
|
1513
1535
|
return maxItem;
|
|
1514
1536
|
}
|
|
1515
1537
|
function findPrevItemByPosition(aiTable, targetId, items, itemsMap) {
|
|
1516
|
-
const viewId = aiTable.activeViewId();
|
|
1538
|
+
const viewId = aiTable.activeViewId?.();
|
|
1517
1539
|
const targetItem = itemsMap[targetId];
|
|
1518
1540
|
const targetPosition = targetItem.positions[viewId] || 0;
|
|
1519
1541
|
let prevItem = null;
|
|
@@ -1526,7 +1548,7 @@ function findPrevItemByPosition(aiTable, targetId, items, itemsMap) {
|
|
|
1526
1548
|
return prevItem;
|
|
1527
1549
|
}
|
|
1528
1550
|
function getPreviousAndNextPosition(aiTable, options, items, itemsMap) {
|
|
1529
|
-
const activeViewId = aiTable.activeViewId();
|
|
1551
|
+
const activeViewId = aiTable.activeViewId?.();
|
|
1530
1552
|
const { afterItemId, beforeItemId } = options;
|
|
1531
1553
|
let nextPosition = null;
|
|
1532
1554
|
let previousPosition = null;
|
|
@@ -1535,10 +1557,10 @@ function getPreviousAndNextPosition(aiTable, options, items, itemsMap) {
|
|
|
1535
1557
|
if (!previousItem) {
|
|
1536
1558
|
throw new Error(`Target item with id ${afterItemId} not found`);
|
|
1537
1559
|
}
|
|
1538
|
-
previousPosition = previousItem
|
|
1560
|
+
previousPosition = previousItem?.positions?.[activeViewId] || 0;
|
|
1539
1561
|
const nextItem = findNextItemByPosition(aiTable, afterItemId, items, itemsMap);
|
|
1540
1562
|
if (nextItem !== null) {
|
|
1541
|
-
nextPosition = nextItem
|
|
1563
|
+
nextPosition = nextItem?.positions?.[activeViewId] || 0;
|
|
1542
1564
|
}
|
|
1543
1565
|
}
|
|
1544
1566
|
else if (beforeItemId) {
|
|
@@ -1546,15 +1568,15 @@ function getPreviousAndNextPosition(aiTable, options, items, itemsMap) {
|
|
|
1546
1568
|
if (!nextItem) {
|
|
1547
1569
|
throw new Error(`Target item with id ${beforeItemId} not found`);
|
|
1548
1570
|
}
|
|
1549
|
-
nextPosition = nextItem
|
|
1571
|
+
nextPosition = nextItem?.positions?.[activeViewId] || 0;
|
|
1550
1572
|
const previousItem = findPrevItemByPosition(aiTable, beforeItemId, items, itemsMap);
|
|
1551
1573
|
if (previousItem !== null) {
|
|
1552
|
-
previousPosition = previousItem
|
|
1574
|
+
previousPosition = previousItem?.positions?.[activeViewId] || 0;
|
|
1553
1575
|
}
|
|
1554
1576
|
}
|
|
1555
1577
|
else {
|
|
1556
1578
|
const maxItem = findMaxItemByPosition(aiTable, items);
|
|
1557
|
-
previousPosition = maxItem
|
|
1579
|
+
previousPosition = maxItem?.positions?.[activeViewId] || 0;
|
|
1558
1580
|
}
|
|
1559
1581
|
return {
|
|
1560
1582
|
nextPosition,
|
|
@@ -1592,8 +1614,8 @@ function getNewItemsPosition(aiTable, options, items, itemsMap) {
|
|
|
1592
1614
|
if (positions.length === 0) {
|
|
1593
1615
|
return [];
|
|
1594
1616
|
}
|
|
1595
|
-
const views = aiTable.views();
|
|
1596
|
-
const activeViewId = aiTable.activeViewId();
|
|
1617
|
+
const views = aiTable.views?.() || [];
|
|
1618
|
+
const activeViewId = aiTable.activeViewId?.();
|
|
1597
1619
|
const viewsMaxPosition = {};
|
|
1598
1620
|
views.forEach((view) => {
|
|
1599
1621
|
viewsMaxPosition[view._id] = getMaxPosition(items, view._id);
|
|
@@ -1702,25 +1724,6 @@ const RecordActions = {
|
|
|
1702
1724
|
updateSystemFieldValues
|
|
1703
1725
|
};
|
|
1704
1726
|
|
|
1705
|
-
function setViewGroup(aiTable, groups) {
|
|
1706
|
-
const viewId = aiTable.activeViewId();
|
|
1707
|
-
const view = aiTable.views().find((v) => v._id === viewId);
|
|
1708
|
-
if (!view)
|
|
1709
|
-
return;
|
|
1710
|
-
const currentSettings = view.settings || {};
|
|
1711
|
-
const newSettings = {
|
|
1712
|
-
...currentSettings,
|
|
1713
|
-
groups: groups || [],
|
|
1714
|
-
collapsed_group_ids: [] // 重置折叠
|
|
1715
|
-
};
|
|
1716
|
-
const operation = {
|
|
1717
|
-
type: ActionName.SetView,
|
|
1718
|
-
properties: { settings: currentSettings },
|
|
1719
|
-
newProperties: { settings: newSettings },
|
|
1720
|
-
path: [viewId]
|
|
1721
|
-
};
|
|
1722
|
-
aiTable.apply(operation);
|
|
1723
|
-
}
|
|
1724
1727
|
function setCollapsedGroup(aiTable, collapsedGroupIds) {
|
|
1725
1728
|
const viewId = aiTable.activeViewId();
|
|
1726
1729
|
const view = aiTable.views().find((v) => v._id === viewId);
|
|
@@ -1739,7 +1742,6 @@ function setCollapsedGroup(aiTable, collapsedGroupIds) {
|
|
|
1739
1742
|
};
|
|
1740
1743
|
aiTable.apply(operation);
|
|
1741
1744
|
}
|
|
1742
|
-
// 折叠
|
|
1743
1745
|
function toggleGroupCollapse(aiTable, groupId) {
|
|
1744
1746
|
const activeView = aiTable.viewsMap()[aiTable.activeViewId()];
|
|
1745
1747
|
if (!activeView)
|
|
@@ -1748,68 +1750,8 @@ function toggleGroupCollapse(aiTable, groupId) {
|
|
|
1748
1750
|
const newCollapse = currentCollapse.includes(groupId) ? currentCollapse.filter((id) => id !== groupId) : [...currentCollapse, groupId];
|
|
1749
1751
|
setCollapsedGroup(aiTable, newCollapse);
|
|
1750
1752
|
}
|
|
1751
|
-
// 添加分组
|
|
1752
|
-
function addGroupField(aiTable, fieldId, direction = SortDirection.ascending) {
|
|
1753
|
-
const activeView = aiTable.viewsMap()[aiTable.activeViewId()];
|
|
1754
|
-
if (!activeView)
|
|
1755
|
-
return;
|
|
1756
|
-
const currentGroups = activeView.settings?.groups || [];
|
|
1757
|
-
// 是否已存在
|
|
1758
|
-
if (currentGroups.some((group) => group.field_id === fieldId)) {
|
|
1759
|
-
throw new Error('The field has been used for grouping.');
|
|
1760
|
-
}
|
|
1761
|
-
// 层级限制
|
|
1762
|
-
if (currentGroups.length >= AI_TABLE_GROUP_MAX_LEVEL) {
|
|
1763
|
-
throw new Error(`The maximum number of groups is ${AI_TABLE_GROUP_MAX_LEVEL}.`);
|
|
1764
|
-
}
|
|
1765
|
-
const newGroups = [...currentGroups, { field_id: fieldId, direction }];
|
|
1766
|
-
setViewGroup(aiTable, newGroups);
|
|
1767
|
-
}
|
|
1768
|
-
// 删除分组
|
|
1769
|
-
function removeGroupField(aiTable, fieldId) {
|
|
1770
|
-
const view = aiTable.views().find((v) => v._id === aiTable.activeViewId());
|
|
1771
|
-
if (!view)
|
|
1772
|
-
return;
|
|
1773
|
-
const currentGroups = view.settings?.groups || [];
|
|
1774
|
-
const newGroups = currentGroups.filter((group) => group.field_id !== fieldId);
|
|
1775
|
-
setViewGroup(aiTable, newGroups.length > 0 ? newGroups : null);
|
|
1776
|
-
}
|
|
1777
|
-
// 更新排序方向
|
|
1778
|
-
function updateGroupFieldDirection(aiTable, fieldId, direction) {
|
|
1779
|
-
const view = aiTable.views().find((v) => v._id === aiTable.activeViewId());
|
|
1780
|
-
if (!view)
|
|
1781
|
-
return;
|
|
1782
|
-
const currentGroups = view.settings?.groups || [];
|
|
1783
|
-
const newGroups = currentGroups.map((group) => (group.field_id === fieldId ? { ...group, direction } : group));
|
|
1784
|
-
setViewGroup(aiTable, newGroups);
|
|
1785
|
-
}
|
|
1786
|
-
// 重新排序,拖拽顺序
|
|
1787
|
-
function reorderGroupFields(aiTable, fromIndex, toIndex) {
|
|
1788
|
-
const view = aiTable.views().find((v) => v._id === aiTable.activeViewId());
|
|
1789
|
-
if (!view)
|
|
1790
|
-
return;
|
|
1791
|
-
const currentGroups = view.settings?.groups || [];
|
|
1792
|
-
if (fromIndex < 0 || fromIndex >= currentGroups.length || toIndex < 0 || toIndex >= currentGroups.length) {
|
|
1793
|
-
return;
|
|
1794
|
-
}
|
|
1795
|
-
const newGroups = [...currentGroups];
|
|
1796
|
-
const [movedItem] = newGroups.splice(fromIndex, 1);
|
|
1797
|
-
newGroups.splice(toIndex, 0, movedItem);
|
|
1798
|
-
setViewGroup(aiTable, newGroups);
|
|
1799
|
-
}
|
|
1800
|
-
// 清空分组
|
|
1801
|
-
function clearAllGroups(aiTable) {
|
|
1802
|
-
setViewGroup(aiTable, null);
|
|
1803
|
-
}
|
|
1804
1753
|
const GroupActions = {
|
|
1805
|
-
|
|
1806
|
-
setCollapsedGroup,
|
|
1807
|
-
toggleGroupCollapse,
|
|
1808
|
-
addGroupField,
|
|
1809
|
-
removeGroupField,
|
|
1810
|
-
updateGroupFieldDirection,
|
|
1811
|
-
reorderGroupFields,
|
|
1812
|
-
clearAllGroups
|
|
1754
|
+
toggleGroupCollapse
|
|
1813
1755
|
};
|
|
1814
1756
|
|
|
1815
1757
|
const Actions = {
|
|
@@ -1852,12 +1794,12 @@ function buildRecordsWithWillMoveRecords(records, willMoveRecordsMap) {
|
|
|
1852
1794
|
});
|
|
1853
1795
|
}
|
|
1854
1796
|
|
|
1855
|
-
function addRecords(aiTable,
|
|
1797
|
+
function addRecords(aiTable, options, recordCreatedInfo) {
|
|
1856
1798
|
options = options || {};
|
|
1857
1799
|
const newRecords = [];
|
|
1858
|
-
const activeViewId = aiTable.activeViewId();
|
|
1859
|
-
const activeView = aiTable.viewsMap()[activeViewId];
|
|
1860
|
-
const groups = activeView
|
|
1800
|
+
const activeViewId = aiTable.activeViewId?.();
|
|
1801
|
+
const activeView = aiTable.viewsMap?.()?.[activeViewId];
|
|
1802
|
+
const groups = activeView?.settings?.groups;
|
|
1861
1803
|
let { originId, isDuplicate, count = 1 } = options;
|
|
1862
1804
|
const recordCount = aiTable.records().length;
|
|
1863
1805
|
const maxRecordCount = aiTable.context?.maxRecords();
|
|
@@ -1884,7 +1826,7 @@ function addRecords(aiTable, trackableEntity, options) {
|
|
|
1884
1826
|
_id: id,
|
|
1885
1827
|
short_id: newRecordShortIds[index],
|
|
1886
1828
|
values: newRecordValues,
|
|
1887
|
-
...
|
|
1829
|
+
...recordCreatedInfo
|
|
1888
1830
|
};
|
|
1889
1831
|
if (needCopyGroupValuesMap) {
|
|
1890
1832
|
groups?.forEach((group) => {
|
|
@@ -1921,15 +1863,20 @@ function getDefaultRecordValues(aiTable, isDuplicate = false, recordId) {
|
|
|
1921
1863
|
newRecordValues = aiTable.recordsMap()[recordId].values;
|
|
1922
1864
|
}
|
|
1923
1865
|
else {
|
|
1924
|
-
|
|
1925
|
-
const
|
|
1866
|
+
let fields = aiTable.fields();
|
|
1867
|
+
const activeView = aiTable.viewsMap?.()?.[aiTable.activeViewId?.()];
|
|
1868
|
+
if (activeView) {
|
|
1869
|
+
fields = getSortFields(aiTable, fields, activeView);
|
|
1870
|
+
}
|
|
1926
1871
|
fields.map((field) => {
|
|
1927
1872
|
const defaultValue = FieldModelMap[field.type].getDefaultValue();
|
|
1928
1873
|
newRecordValues[field._id] = defaultValue;
|
|
1929
1874
|
});
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1875
|
+
if (activeView) {
|
|
1876
|
+
const { conditions, condition_logical } = activeView.settings || {};
|
|
1877
|
+
if (conditions && conditions.length) {
|
|
1878
|
+
newRecordValues = getDefaultRecordDataByFilter(newRecordValues, conditions, fields, condition_logical);
|
|
1879
|
+
}
|
|
1933
1880
|
}
|
|
1934
1881
|
}
|
|
1935
1882
|
return newRecordValues;
|
|
@@ -1963,6 +1910,9 @@ function updateWillHiddenRecordIds(aiTable, needUpdateOptions, updatedInfo) {
|
|
|
1963
1910
|
});
|
|
1964
1911
|
}
|
|
1965
1912
|
function updateWillMoveRecords(aiTable, needUpdateOptions, updatedInfo) {
|
|
1913
|
+
if (!aiTable.activeViewId?.() || !aiTable.viewsMap?.()) {
|
|
1914
|
+
return;
|
|
1915
|
+
}
|
|
1966
1916
|
const activeView = aiTable.viewsMap()[aiTable.activeViewId()];
|
|
1967
1917
|
const groups = activeView.settings?.groups ?? [];
|
|
1968
1918
|
const sorts = activeView.settings?.sorts ?? [];
|
|
@@ -2124,7 +2074,7 @@ function buildRecordsByView(aiTable, records, fields, activeView) {
|
|
|
2124
2074
|
}
|
|
2125
2075
|
function buildFieldsByView(aiTable, fields, activeView) {
|
|
2126
2076
|
const sortFields = getSortFields(aiTable, fields, activeView);
|
|
2127
|
-
return
|
|
2077
|
+
return buildViewFields(sortFields, activeView);
|
|
2128
2078
|
}
|
|
2129
2079
|
function buildLinearRows(aiTable, activeView, records) {
|
|
2130
2080
|
if (aiTable && activeView?.settings?.groups?.length) {
|
|
@@ -2445,13 +2395,6 @@ function getFieldPositionInView(viewId, fields, path, newPath) {
|
|
|
2445
2395
|
}
|
|
2446
2396
|
return newPosition;
|
|
2447
2397
|
}
|
|
2448
|
-
function getFieldsSizeMap(fields, activeView) {
|
|
2449
|
-
const fieldsSizeMap = {};
|
|
2450
|
-
fields?.forEach((field) => {
|
|
2451
|
-
fieldsSizeMap[field._id] = field.widths?.[activeView._id];
|
|
2452
|
-
});
|
|
2453
|
-
return fieldsSizeMap;
|
|
2454
|
-
}
|
|
2455
2398
|
|
|
2456
2399
|
function addFields(aiTable, options) {
|
|
2457
2400
|
const maxFieldsCount = aiTable.context?.maxFields();
|
|
@@ -2579,7 +2522,7 @@ const updateFieldAndValues = (aiTable, references, actions, options) => {
|
|
|
2579
2522
|
actions.updateFieldValues(fieldValueOptions);
|
|
2580
2523
|
}
|
|
2581
2524
|
};
|
|
2582
|
-
const CopyFieldPropertyItem = (aiTable,
|
|
2525
|
+
const CopyFieldPropertyItem = (aiTable, actions) => {
|
|
2583
2526
|
const name = getStateI18nTextByKey(aiTable, AITableStateI18nKey.copyField);
|
|
2584
2527
|
return {
|
|
2585
2528
|
type: 'copyFieldProperty',
|
|
@@ -2603,7 +2546,7 @@ const CopyFieldPropertyItem = (aiTable, addFieldFn) => {
|
|
|
2603
2546
|
name: newFieldName
|
|
2604
2547
|
}
|
|
2605
2548
|
};
|
|
2606
|
-
|
|
2549
|
+
actions.addField(fieldOptions);
|
|
2607
2550
|
},
|
|
2608
2551
|
disabled: () => {
|
|
2609
2552
|
const fieldLength = aiTable.fields()?.length || 0;
|
|
@@ -2712,5 +2655,5 @@ const VIEW_ACTIONS = [ActionName.SetView, ActionName.AddView, ActionName.RemoveV
|
|
|
2712
2655
|
* Generated bundle index. Do not edit.
|
|
2713
2656
|
*/
|
|
2714
2657
|
|
|
2715
|
-
export { AITableStateI18nKey, AITableStateI18nText, Actions, CopyCellsItem, CopyFieldPropertyItem, DEFAULT_INITIAL_GAP, DEFAULT_PRECISION_THRESHOLD, 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, buildSetRecordPositionsAction, buildSorts, calculateAdaptiveFrozenColumnCount, checkConditions, createMultiplePositions, createPositions, createSharedType, doFilter, freezeToThisColumn, generateCopyName, getDataBySharedType, getDefaultI18nTextByKey, getDefaultRecordDataByFilter, getDefaultRecordValues, getFieldPositionInView,
|
|
2658
|
+
export { AITableStateI18nKey, AITableStateI18nText, Actions, CopyCellsItem, CopyFieldPropertyItem, DEFAULT_INITIAL_GAP, DEFAULT_PRECISION_THRESHOLD, 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, buildSetRecordPositionsAction, buildSorts, calculateAdaptiveFrozenColumnCount, checkConditions, createMultiplePositions, createPositions, createSharedType, doFilter, freezeToThisColumn, generateCopyName, getDataBySharedType, getDefaultI18nTextByKey, getDefaultRecordDataByFilter, getDefaultRecordValues, getFieldPositionInView, 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 };
|
|
2716
2659
|
//# sourceMappingURL=ai-table-state.mjs.map
|