@teselagen/ui 0.8.6-beta.24 → 0.8.6-beta.25
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/DataTable/utils/formatPasteData.d.ts +11 -5
- package/DataTable/utils/getAllRows.d.ts +4 -1
- package/DataTable/utils/getCellCopyText.d.ts +1 -1
- package/DataTable/utils/getCellInfo.d.ts +20 -15
- package/DataTable/utils/getFieldPathToField.d.ts +5 -1
- package/DataTable/utils/getIdOrCodeOrIndex.d.ts +2 -1
- package/DataTable/utils/getLastSelectedEntity.d.ts +7 -1
- package/DataTable/utils/getNewEntToSelect.d.ts +7 -6
- package/DataTable/utils/getRowCopyText.d.ts +1 -1
- package/DataTable/utils/initializeHasuraWhereAndFilter.d.ts +22 -1
- package/DataTable/utils/types/Entity.d.ts +5 -0
- package/DataTable/utils/types/Field.d.ts +4 -0
- package/DataTable/utils/types/OrderBy.d.ts +11 -0
- package/DataTable/utils/types/Schema.d.ts +4 -0
- package/DataTable/utils/utils.d.ts +16 -5
- package/index.cjs.js +23 -13
- package/index.es.js +23 -13
- package/package.json +1 -1
- package/src/DataTable/utils/formatPasteData.ts +34 -0
- package/src/DataTable/utils/getAllRows.ts +11 -0
- package/src/DataTable/utils/getCellCopyText.ts +7 -0
- package/src/DataTable/utils/getCellInfo.ts +46 -0
- package/src/DataTable/utils/getFieldPathToField.ts +10 -0
- package/src/DataTable/utils/getIdOrCodeOrIndex.ts +14 -0
- package/src/DataTable/utils/getLastSelectedEntity.ts +15 -0
- package/src/DataTable/utils/getNewEntToSelect.ts +32 -0
- package/src/DataTable/utils/initializeHasuraWhereAndFilter.ts +35 -0
- package/src/DataTable/utils/types/Entity.ts +7 -0
- package/src/DataTable/utils/types/Field.ts +4 -0
- package/src/DataTable/utils/types/OrderBy.ts +15 -0
- package/src/DataTable/utils/types/Schema.ts +5 -0
- package/src/DataTable/utils/utils.ts +39 -0
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
1
|
+
import { Schema } from './types/Schema';
|
|
2
|
+
type GenericSelectValue = {
|
|
3
|
+
__strVal: string;
|
|
4
|
+
__genSelCol: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const formatPasteData: ({ schema, newVal, path }: {
|
|
7
|
+
schema: Schema;
|
|
8
|
+
newVal: GenericSelectValue | string | number | boolean | null | undefined;
|
|
9
|
+
path: string;
|
|
10
|
+
}) => string | number | boolean | null | undefined;
|
|
11
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare const getCellCopyText: (cellWrapper: HTMLElement | null) => (string | null | undefined)[];
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
1
|
+
import { Entity } from './types/Entity';
|
|
2
|
+
export declare const getCellInfo: <T extends Entity>({ columnIndex, columnPath, rowId, schema, entities, rowIndex, isEntityDisabled, entity }: {
|
|
3
|
+
columnIndex: number;
|
|
4
|
+
columnPath: string;
|
|
5
|
+
rowId: string | number;
|
|
6
|
+
schema: {
|
|
7
|
+
fields: {
|
|
8
|
+
path: string;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
11
|
+
entities: T[];
|
|
12
|
+
rowIndex: number;
|
|
13
|
+
isEntityDisabled: (entity: T) => boolean;
|
|
14
|
+
entity: T;
|
|
15
|
+
}) => {
|
|
11
16
|
cellId: string;
|
|
12
|
-
cellIdAbove:
|
|
13
|
-
cellIdToRight:
|
|
14
|
-
cellIdBelow:
|
|
15
|
-
cellIdToLeft:
|
|
16
|
-
rowDisabled:
|
|
17
|
+
cellIdAbove: string | 0;
|
|
18
|
+
cellIdToRight: string;
|
|
19
|
+
cellIdBelow: string | 0;
|
|
20
|
+
cellIdToLeft: string;
|
|
21
|
+
rowDisabled: boolean;
|
|
17
22
|
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { Entity } from './types/Entity';
|
|
2
|
+
export declare const getIdOrCodeOrIndex: (record: Entity, rowIndex?: number) => string | number;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Entity } from './types/Entity';
|
|
2
|
+
export declare const getNewEntToSelect: ({ type, lastSelectedIndex, entities, isEntityDisabled }: {
|
|
3
|
+
type: "up" | "down";
|
|
4
|
+
lastSelectedIndex: number;
|
|
5
|
+
entities: Entity[];
|
|
6
|
+
isEntityDisabled?: (entity: Entity) => boolean;
|
|
7
|
+
}) => Entity | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function getRowCopyText(rowEl: any, { specificColumn }?: {}): (string |
|
|
1
|
+
export function getRowCopyText(rowEl: any, { specificColumn }?: {}): (string | (string | null | undefined)[])[];
|
|
@@ -1 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
type Filter = {
|
|
2
|
+
[key: string]: {
|
|
3
|
+
_eq: string | number | boolean;
|
|
4
|
+
} | {
|
|
5
|
+
_in: (string | number | boolean)[];
|
|
6
|
+
} | {
|
|
7
|
+
_gt: number;
|
|
8
|
+
} | {
|
|
9
|
+
_lt: number;
|
|
10
|
+
} | {
|
|
11
|
+
_gte: number;
|
|
12
|
+
} | {
|
|
13
|
+
_lte: number;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
type Where = {
|
|
17
|
+
_and?: Filter[];
|
|
18
|
+
_or?: Filter[];
|
|
19
|
+
};
|
|
20
|
+
type CurrentParams = object;
|
|
21
|
+
export declare function initializeHasuraWhereAndFilter(additionalFilter: ((where: Where, currentParams: CurrentParams) => Filter | void) | Filter | undefined | null, where: Where | undefined, currentParams: CurrentParams): void;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type OrderByClause<T = {
|
|
2
|
+
id: string;
|
|
3
|
+
}> = {
|
|
4
|
+
path?: string;
|
|
5
|
+
direction?: "asc" | "desc";
|
|
6
|
+
type?: string;
|
|
7
|
+
sortFn?: ((record: T) => unknown) | string | Array<((record: T) => unknown) | string>;
|
|
8
|
+
getValueToFilterOn?: (record: T) => unknown;
|
|
9
|
+
};
|
|
10
|
+
export type OrderBy = OrderByClause | OrderByClause[] | Record<string, "asc" | "desc">;
|
|
11
|
+
export {};
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Entity } from './types/Entity';
|
|
2
|
+
import { Field } from './types/Field';
|
|
3
|
+
export declare const getFieldPathToIndex: (schema: {
|
|
4
|
+
fields: Field[];
|
|
5
|
+
}) => {
|
|
6
|
+
[path: string]: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const defaultParsePaste: (str: string) => string[][];
|
|
9
|
+
export declare const getEntityIdToEntity: (entities: Entity[]) => {
|
|
10
|
+
[id: string]: {
|
|
11
|
+
e: Entity;
|
|
12
|
+
i: number;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare const getNumberStrAtEnd: (str: string) => string | null | undefined;
|
|
16
|
+
export declare const stripNumberAtEnd: (str: string) => string;
|
package/index.cjs.js
CHANGED
|
@@ -16546,11 +16546,14 @@ function isEntityClean(e) {
|
|
|
16546
16546
|
}
|
|
16547
16547
|
__name(isEntityClean, "isEntityClean");
|
|
16548
16548
|
const getIdOrCodeOrIndex = /* @__PURE__ */ __name((record, rowIndex) => {
|
|
16549
|
-
if (record.id || record.id === 0) {
|
|
16549
|
+
if ("id" in record && (record.id || record.id === 0)) {
|
|
16550
16550
|
return record.id;
|
|
16551
|
-
} else if (record.code) {
|
|
16551
|
+
} else if ("code" in record && record.code) {
|
|
16552
16552
|
return record.code;
|
|
16553
16553
|
} else {
|
|
16554
|
+
if (rowIndex === void 0 || rowIndex === null) {
|
|
16555
|
+
throw new Error("id, code, or rowIndex must be provided");
|
|
16556
|
+
}
|
|
16554
16557
|
return rowIndex;
|
|
16555
16558
|
}
|
|
16556
16559
|
}, "getIdOrCodeOrIndex");
|
|
@@ -16637,17 +16640,22 @@ const getFieldPathToField = /* @__PURE__ */ __name((schema) => {
|
|
|
16637
16640
|
});
|
|
16638
16641
|
return fieldPathToField;
|
|
16639
16642
|
}, "getFieldPathToField");
|
|
16640
|
-
const formatPasteData = /* @__PURE__ */ __name(({
|
|
16643
|
+
const formatPasteData = /* @__PURE__ */ __name(({
|
|
16644
|
+
schema,
|
|
16645
|
+
newVal,
|
|
16646
|
+
path: path2
|
|
16647
|
+
}) => {
|
|
16641
16648
|
const pathToField = getFieldPathToField(schema);
|
|
16642
16649
|
const column = pathToField[path2];
|
|
16643
16650
|
if (column.type === "genericSelect") {
|
|
16644
|
-
|
|
16645
|
-
|
|
16651
|
+
const value = newVal;
|
|
16652
|
+
if (value.__genSelCol === path2) {
|
|
16653
|
+
newVal = value.__strVal;
|
|
16646
16654
|
} else {
|
|
16647
16655
|
newVal = void 0;
|
|
16648
16656
|
}
|
|
16649
16657
|
} else {
|
|
16650
|
-
newVal =
|
|
16658
|
+
newVal = typeof newVal === "object" && newVal !== null && "__strVal" in newVal ? newVal.__strVal : newVal;
|
|
16651
16659
|
}
|
|
16652
16660
|
return newVal;
|
|
16653
16661
|
}, "formatPasteData");
|
|
@@ -16672,14 +16680,15 @@ const endsWithNumber = /* @__PURE__ */ __name((str) => {
|
|
|
16672
16680
|
return /[0-9]+$/.test(str);
|
|
16673
16681
|
}, "endsWithNumber");
|
|
16674
16682
|
const getNumberStrAtEnd = /* @__PURE__ */ __name((str) => {
|
|
16683
|
+
var _a;
|
|
16675
16684
|
if (endsWithNumber(str)) {
|
|
16676
|
-
return str.match(/[0-9]+$/)[0];
|
|
16685
|
+
return (_a = str.match(/[0-9]+$/)) == null ? void 0 : _a[0];
|
|
16677
16686
|
}
|
|
16678
16687
|
return null;
|
|
16679
16688
|
}, "getNumberStrAtEnd");
|
|
16680
16689
|
const stripNumberAtEnd = /* @__PURE__ */ __name((str) => {
|
|
16681
16690
|
var _a;
|
|
16682
|
-
return (_a = str == null ? void 0 : str.replace) == null ? void 0 : _a.call(str, getNumberStrAtEnd(str), "");
|
|
16691
|
+
return (_a = str == null ? void 0 : str.replace) == null ? void 0 : _a.call(str, getNumberStrAtEnd(str) || "", "");
|
|
16683
16692
|
}, "stripNumberAtEnd");
|
|
16684
16693
|
const getAllRows = /* @__PURE__ */ __name((tableRef) => {
|
|
16685
16694
|
var _a, _b;
|
|
@@ -16716,7 +16725,7 @@ const getNewEntToSelect = /* @__PURE__ */ __name(({
|
|
|
16716
16725
|
}, "getNewEntToSelect");
|
|
16717
16726
|
const getLastSelectedEntity = /* @__PURE__ */ __name((idMap) => {
|
|
16718
16727
|
let lastSelectedEnt;
|
|
16719
|
-
let latestTime;
|
|
16728
|
+
let latestTime = null;
|
|
16720
16729
|
Object.values(idMap).forEach(({ time, entity }) => {
|
|
16721
16730
|
if (!latestTime || time > latestTime) {
|
|
16722
16731
|
lastSelectedEnt = entity;
|
|
@@ -16756,9 +16765,9 @@ const getCellInfo = /* @__PURE__ */ __name(({
|
|
|
16756
16765
|
};
|
|
16757
16766
|
}, "getCellInfo");
|
|
16758
16767
|
const getCellCopyText = /* @__PURE__ */ __name((cellWrapper) => {
|
|
16759
|
-
const text2 = cellWrapper
|
|
16760
|
-
const jsonText = cellWrapper
|
|
16761
|
-
const textContent = text2 || cellWrapper.textContent || "";
|
|
16768
|
+
const text2 = cellWrapper == null ? void 0 : cellWrapper.getAttribute("data-copy-text");
|
|
16769
|
+
const jsonText = cellWrapper == null ? void 0 : cellWrapper.getAttribute("data-copy-json");
|
|
16770
|
+
const textContent = text2 || (cellWrapper == null ? void 0 : cellWrapper.textContent) || "";
|
|
16762
16771
|
return [textContent, jsonText];
|
|
16763
16772
|
}, "getCellCopyText");
|
|
16764
16773
|
const getRowCopyText = /* @__PURE__ */ __name((rowEl, { specificColumn } = {}) => {
|
|
@@ -19907,8 +19916,9 @@ function initializeHasuraWhereAndFilter(additionalFilter, where = {}, currentPar
|
|
|
19907
19916
|
if (newWhere) {
|
|
19908
19917
|
Object.assign(where, newWhere);
|
|
19909
19918
|
}
|
|
19910
|
-
} else if (typeof additionalFilter === "object")
|
|
19919
|
+
} else if (typeof additionalFilter === "object" && additionalFilter !== null) {
|
|
19911
19920
|
where._and.push(additionalFilter);
|
|
19921
|
+
}
|
|
19912
19922
|
}
|
|
19913
19923
|
__name(initializeHasuraWhereAndFilter, "initializeHasuraWhereAndFilter");
|
|
19914
19924
|
const defaultPageSizes = [5, 10, 15, 25, 50, 100, 200, 400];
|
package/index.es.js
CHANGED
|
@@ -16528,11 +16528,14 @@ function isEntityClean(e) {
|
|
|
16528
16528
|
}
|
|
16529
16529
|
__name(isEntityClean, "isEntityClean");
|
|
16530
16530
|
const getIdOrCodeOrIndex = /* @__PURE__ */ __name((record, rowIndex) => {
|
|
16531
|
-
if (record.id || record.id === 0) {
|
|
16531
|
+
if ("id" in record && (record.id || record.id === 0)) {
|
|
16532
16532
|
return record.id;
|
|
16533
|
-
} else if (record.code) {
|
|
16533
|
+
} else if ("code" in record && record.code) {
|
|
16534
16534
|
return record.code;
|
|
16535
16535
|
} else {
|
|
16536
|
+
if (rowIndex === void 0 || rowIndex === null) {
|
|
16537
|
+
throw new Error("id, code, or rowIndex must be provided");
|
|
16538
|
+
}
|
|
16536
16539
|
return rowIndex;
|
|
16537
16540
|
}
|
|
16538
16541
|
}, "getIdOrCodeOrIndex");
|
|
@@ -16619,17 +16622,22 @@ const getFieldPathToField = /* @__PURE__ */ __name((schema) => {
|
|
|
16619
16622
|
});
|
|
16620
16623
|
return fieldPathToField;
|
|
16621
16624
|
}, "getFieldPathToField");
|
|
16622
|
-
const formatPasteData = /* @__PURE__ */ __name(({
|
|
16625
|
+
const formatPasteData = /* @__PURE__ */ __name(({
|
|
16626
|
+
schema,
|
|
16627
|
+
newVal,
|
|
16628
|
+
path: path2
|
|
16629
|
+
}) => {
|
|
16623
16630
|
const pathToField = getFieldPathToField(schema);
|
|
16624
16631
|
const column = pathToField[path2];
|
|
16625
16632
|
if (column.type === "genericSelect") {
|
|
16626
|
-
|
|
16627
|
-
|
|
16633
|
+
const value = newVal;
|
|
16634
|
+
if (value.__genSelCol === path2) {
|
|
16635
|
+
newVal = value.__strVal;
|
|
16628
16636
|
} else {
|
|
16629
16637
|
newVal = void 0;
|
|
16630
16638
|
}
|
|
16631
16639
|
} else {
|
|
16632
|
-
newVal =
|
|
16640
|
+
newVal = typeof newVal === "object" && newVal !== null && "__strVal" in newVal ? newVal.__strVal : newVal;
|
|
16633
16641
|
}
|
|
16634
16642
|
return newVal;
|
|
16635
16643
|
}, "formatPasteData");
|
|
@@ -16654,14 +16662,15 @@ const endsWithNumber = /* @__PURE__ */ __name((str) => {
|
|
|
16654
16662
|
return /[0-9]+$/.test(str);
|
|
16655
16663
|
}, "endsWithNumber");
|
|
16656
16664
|
const getNumberStrAtEnd = /* @__PURE__ */ __name((str) => {
|
|
16665
|
+
var _a;
|
|
16657
16666
|
if (endsWithNumber(str)) {
|
|
16658
|
-
return str.match(/[0-9]+$/)[0];
|
|
16667
|
+
return (_a = str.match(/[0-9]+$/)) == null ? void 0 : _a[0];
|
|
16659
16668
|
}
|
|
16660
16669
|
return null;
|
|
16661
16670
|
}, "getNumberStrAtEnd");
|
|
16662
16671
|
const stripNumberAtEnd = /* @__PURE__ */ __name((str) => {
|
|
16663
16672
|
var _a;
|
|
16664
|
-
return (_a = str == null ? void 0 : str.replace) == null ? void 0 : _a.call(str, getNumberStrAtEnd(str), "");
|
|
16673
|
+
return (_a = str == null ? void 0 : str.replace) == null ? void 0 : _a.call(str, getNumberStrAtEnd(str) || "", "");
|
|
16665
16674
|
}, "stripNumberAtEnd");
|
|
16666
16675
|
const getAllRows = /* @__PURE__ */ __name((tableRef) => {
|
|
16667
16676
|
var _a, _b;
|
|
@@ -16698,7 +16707,7 @@ const getNewEntToSelect = /* @__PURE__ */ __name(({
|
|
|
16698
16707
|
}, "getNewEntToSelect");
|
|
16699
16708
|
const getLastSelectedEntity = /* @__PURE__ */ __name((idMap) => {
|
|
16700
16709
|
let lastSelectedEnt;
|
|
16701
|
-
let latestTime;
|
|
16710
|
+
let latestTime = null;
|
|
16702
16711
|
Object.values(idMap).forEach(({ time, entity }) => {
|
|
16703
16712
|
if (!latestTime || time > latestTime) {
|
|
16704
16713
|
lastSelectedEnt = entity;
|
|
@@ -16738,9 +16747,9 @@ const getCellInfo = /* @__PURE__ */ __name(({
|
|
|
16738
16747
|
};
|
|
16739
16748
|
}, "getCellInfo");
|
|
16740
16749
|
const getCellCopyText = /* @__PURE__ */ __name((cellWrapper) => {
|
|
16741
|
-
const text2 = cellWrapper
|
|
16742
|
-
const jsonText = cellWrapper
|
|
16743
|
-
const textContent = text2 || cellWrapper.textContent || "";
|
|
16750
|
+
const text2 = cellWrapper == null ? void 0 : cellWrapper.getAttribute("data-copy-text");
|
|
16751
|
+
const jsonText = cellWrapper == null ? void 0 : cellWrapper.getAttribute("data-copy-json");
|
|
16752
|
+
const textContent = text2 || (cellWrapper == null ? void 0 : cellWrapper.textContent) || "";
|
|
16744
16753
|
return [textContent, jsonText];
|
|
16745
16754
|
}, "getCellCopyText");
|
|
16746
16755
|
const getRowCopyText = /* @__PURE__ */ __name((rowEl, { specificColumn } = {}) => {
|
|
@@ -19889,8 +19898,9 @@ function initializeHasuraWhereAndFilter(additionalFilter, where = {}, currentPar
|
|
|
19889
19898
|
if (newWhere) {
|
|
19890
19899
|
Object.assign(where, newWhere);
|
|
19891
19900
|
}
|
|
19892
|
-
} else if (typeof additionalFilter === "object")
|
|
19901
|
+
} else if (typeof additionalFilter === "object" && additionalFilter !== null) {
|
|
19893
19902
|
where._and.push(additionalFilter);
|
|
19903
|
+
}
|
|
19894
19904
|
}
|
|
19895
19905
|
__name(initializeHasuraWhereAndFilter, "initializeHasuraWhereAndFilter");
|
|
19896
19906
|
const defaultPageSizes = [5, 10, 15, 25, 50, 100, 200, 400];
|
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getFieldPathToField } from "./getFieldPathToField";
|
|
2
|
+
import type { Schema } from "./types/Schema";
|
|
3
|
+
|
|
4
|
+
type GenericSelectValue = {
|
|
5
|
+
__strVal: string;
|
|
6
|
+
__genSelCol: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const formatPasteData = ({
|
|
10
|
+
schema,
|
|
11
|
+
newVal,
|
|
12
|
+
path
|
|
13
|
+
}: {
|
|
14
|
+
schema: Schema;
|
|
15
|
+
newVal: GenericSelectValue | string | number | boolean | null | undefined;
|
|
16
|
+
path: string;
|
|
17
|
+
}) => {
|
|
18
|
+
const pathToField = getFieldPathToField(schema);
|
|
19
|
+
const column = pathToField[path];
|
|
20
|
+
if (column.type === "genericSelect") {
|
|
21
|
+
const value = newVal as GenericSelectValue;
|
|
22
|
+
if (value.__genSelCol === path) {
|
|
23
|
+
newVal = value.__strVal;
|
|
24
|
+
} else {
|
|
25
|
+
newVal = undefined;
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
newVal =
|
|
29
|
+
typeof newVal === "object" && newVal !== null && "__strVal" in newVal
|
|
30
|
+
? newVal.__strVal
|
|
31
|
+
: newVal;
|
|
32
|
+
}
|
|
33
|
+
return newVal;
|
|
34
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
|
|
3
|
+
export const getAllRows = (
|
|
4
|
+
tableRef: RefObject<{ tableRef: HTMLDivElement }>
|
|
5
|
+
) => {
|
|
6
|
+
const allRowEls = tableRef.current?.tableRef?.querySelectorAll(".rt-tr");
|
|
7
|
+
if (!allRowEls || !allRowEls.length) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
return allRowEls;
|
|
11
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const getCellCopyText = (cellWrapper: HTMLElement | null) => {
|
|
2
|
+
const text = cellWrapper?.getAttribute("data-copy-text");
|
|
3
|
+
const jsonText = cellWrapper?.getAttribute("data-copy-json");
|
|
4
|
+
|
|
5
|
+
const textContent = text || cellWrapper?.textContent || "";
|
|
6
|
+
return [textContent, jsonText];
|
|
7
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getIdOrCodeOrIndex } from "./getIdOrCodeOrIndex";
|
|
2
|
+
import { Entity } from "./types/Entity";
|
|
3
|
+
|
|
4
|
+
export const getCellInfo = <T extends Entity>({
|
|
5
|
+
columnIndex,
|
|
6
|
+
columnPath,
|
|
7
|
+
rowId,
|
|
8
|
+
schema,
|
|
9
|
+
entities,
|
|
10
|
+
rowIndex,
|
|
11
|
+
isEntityDisabled,
|
|
12
|
+
entity
|
|
13
|
+
}: {
|
|
14
|
+
columnIndex: number;
|
|
15
|
+
columnPath: string;
|
|
16
|
+
rowId: string | number;
|
|
17
|
+
schema: { fields: { path: string }[] };
|
|
18
|
+
entities: T[];
|
|
19
|
+
rowIndex: number;
|
|
20
|
+
isEntityDisabled: (entity: T) => boolean;
|
|
21
|
+
entity: T;
|
|
22
|
+
}) => {
|
|
23
|
+
const leftpath = schema.fields[columnIndex - 1]?.path;
|
|
24
|
+
const rightpath = schema.fields[columnIndex + 1]?.path;
|
|
25
|
+
const cellIdToLeft = leftpath && `${rowId}:${leftpath}`;
|
|
26
|
+
const cellIdToRight = rightpath && `${rowId}:${rightpath}`;
|
|
27
|
+
const rowAboveId =
|
|
28
|
+
entities[rowIndex - 1] &&
|
|
29
|
+
getIdOrCodeOrIndex(entities[rowIndex - 1], rowIndex - 1);
|
|
30
|
+
const rowBelowId =
|
|
31
|
+
entities[rowIndex + 1] &&
|
|
32
|
+
getIdOrCodeOrIndex(entities[rowIndex + 1], rowIndex + 1);
|
|
33
|
+
const cellIdAbove = rowAboveId && `${rowAboveId}:${columnPath}`;
|
|
34
|
+
const cellIdBelow = rowBelowId && `${rowBelowId}:${columnPath}`;
|
|
35
|
+
|
|
36
|
+
const cellId = `${rowId}:${columnPath}`;
|
|
37
|
+
const rowDisabled = isEntityDisabled(entity);
|
|
38
|
+
return {
|
|
39
|
+
cellId,
|
|
40
|
+
cellIdAbove,
|
|
41
|
+
cellIdToRight,
|
|
42
|
+
cellIdBelow,
|
|
43
|
+
cellIdToLeft,
|
|
44
|
+
rowDisabled
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Field } from "./types/Field";
|
|
2
|
+
import { Schema } from "./types/Schema";
|
|
3
|
+
|
|
4
|
+
export const getFieldPathToField = (schema: Schema) => {
|
|
5
|
+
const fieldPathToField: { [path: string]: Field } = {};
|
|
6
|
+
schema.fields.forEach(f => {
|
|
7
|
+
fieldPathToField[f.path] = f;
|
|
8
|
+
});
|
|
9
|
+
return fieldPathToField;
|
|
10
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Entity } from "./types/Entity";
|
|
2
|
+
|
|
3
|
+
export const getIdOrCodeOrIndex = (record: Entity, rowIndex?: number) => {
|
|
4
|
+
if ("id" in record && (record.id || record.id === 0)) {
|
|
5
|
+
return record.id;
|
|
6
|
+
} else if ("code" in record && record.code) {
|
|
7
|
+
return record.code;
|
|
8
|
+
} else {
|
|
9
|
+
if (rowIndex === undefined || rowIndex === null) {
|
|
10
|
+
throw new Error("id, code, or rowIndex must be provided");
|
|
11
|
+
}
|
|
12
|
+
return rowIndex;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Entity } from "./types/Entity";
|
|
2
|
+
|
|
3
|
+
export const getLastSelectedEntity = (idMap: {
|
|
4
|
+
[id: string]: { time: number; entity: Entity };
|
|
5
|
+
}) => {
|
|
6
|
+
let lastSelectedEnt;
|
|
7
|
+
let latestTime: number | null = null;
|
|
8
|
+
Object.values(idMap).forEach(({ time, entity }) => {
|
|
9
|
+
if (!latestTime || time > latestTime) {
|
|
10
|
+
lastSelectedEnt = entity;
|
|
11
|
+
latestTime = time;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return lastSelectedEnt;
|
|
15
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Entity } from "./types/Entity";
|
|
2
|
+
|
|
3
|
+
export const getNewEntToSelect = ({
|
|
4
|
+
type,
|
|
5
|
+
lastSelectedIndex,
|
|
6
|
+
entities,
|
|
7
|
+
isEntityDisabled
|
|
8
|
+
}: {
|
|
9
|
+
type: "up" | "down";
|
|
10
|
+
lastSelectedIndex: number;
|
|
11
|
+
entities: Entity[];
|
|
12
|
+
isEntityDisabled?: (entity: Entity) => boolean;
|
|
13
|
+
}): Entity | undefined => {
|
|
14
|
+
let newIndexToSelect;
|
|
15
|
+
if (type === "up") {
|
|
16
|
+
newIndexToSelect = lastSelectedIndex - 1;
|
|
17
|
+
} else {
|
|
18
|
+
newIndexToSelect = lastSelectedIndex + 1;
|
|
19
|
+
}
|
|
20
|
+
const newEntToSelect = entities[newIndexToSelect];
|
|
21
|
+
if (!newEntToSelect) return;
|
|
22
|
+
if (isEntityDisabled && isEntityDisabled(newEntToSelect)) {
|
|
23
|
+
return getNewEntToSelect({
|
|
24
|
+
type,
|
|
25
|
+
lastSelectedIndex: newIndexToSelect,
|
|
26
|
+
entities,
|
|
27
|
+
isEntityDisabled
|
|
28
|
+
}) as Entity;
|
|
29
|
+
} else {
|
|
30
|
+
return newEntToSelect;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
type Filter = {
|
|
2
|
+
[key: string]:
|
|
3
|
+
| { _eq: string | number | boolean }
|
|
4
|
+
| { _in: (string | number | boolean)[] }
|
|
5
|
+
| { _gt: number }
|
|
6
|
+
| { _lt: number }
|
|
7
|
+
| { _gte: number }
|
|
8
|
+
| { _lte: number };
|
|
9
|
+
};
|
|
10
|
+
type Where = { _and?: Filter[]; _or?: Filter[] };
|
|
11
|
+
type CurrentParams = object;
|
|
12
|
+
|
|
13
|
+
export function initializeHasuraWhereAndFilter(
|
|
14
|
+
additionalFilter:
|
|
15
|
+
| ((where: Where, currentParams: CurrentParams) => Filter | void)
|
|
16
|
+
| Filter
|
|
17
|
+
| undefined
|
|
18
|
+
| null,
|
|
19
|
+
where: Where = {},
|
|
20
|
+
currentParams: CurrentParams
|
|
21
|
+
) {
|
|
22
|
+
where._and = where._and || [];
|
|
23
|
+
where._or = where._or || [];
|
|
24
|
+
if (typeof additionalFilter === "function") {
|
|
25
|
+
const newWhere = additionalFilter(where, currentParams);
|
|
26
|
+
if (newWhere) {
|
|
27
|
+
Object.assign(where, newWhere);
|
|
28
|
+
}
|
|
29
|
+
} else if (
|
|
30
|
+
typeof additionalFilter === "object" &&
|
|
31
|
+
additionalFilter !== null
|
|
32
|
+
) {
|
|
33
|
+
where._and.push(additionalFilter);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type OrderByClause<T = { id: string }> = {
|
|
2
|
+
path?: string;
|
|
3
|
+
direction?: "asc" | "desc";
|
|
4
|
+
type?: string;
|
|
5
|
+
sortFn?:
|
|
6
|
+
| ((record: T) => unknown)
|
|
7
|
+
| string
|
|
8
|
+
| Array<((record: T) => unknown) | string>;
|
|
9
|
+
getValueToFilterOn?: (record: T) => unknown;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type OrderBy =
|
|
13
|
+
| OrderByClause
|
|
14
|
+
| OrderByClause[]
|
|
15
|
+
| Record<string, "asc" | "desc">;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getIdOrCodeOrIndex } from "./getIdOrCodeOrIndex";
|
|
2
|
+
import { Entity } from "./types/Entity";
|
|
3
|
+
import { Field } from "./types/Field";
|
|
4
|
+
|
|
5
|
+
export const getFieldPathToIndex = (schema: { fields: Field[] }) => {
|
|
6
|
+
const fieldToIndex: { [path: string]: number } = {};
|
|
7
|
+
schema.fields.forEach((f, i) => {
|
|
8
|
+
fieldToIndex[f.path] = i;
|
|
9
|
+
});
|
|
10
|
+
return fieldToIndex;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const defaultParsePaste = (str: string) => {
|
|
14
|
+
return str.split(/\r\n|\n|\r/).map(row => row.split("\t"));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const getEntityIdToEntity = (entities: Entity[]) => {
|
|
18
|
+
const entityIdToEntity: { [id: string]: { e: Entity; i: number } } = {};
|
|
19
|
+
entities.forEach((e, i) => {
|
|
20
|
+
entityIdToEntity[getIdOrCodeOrIndex(e, i)] = { e, i };
|
|
21
|
+
});
|
|
22
|
+
return entityIdToEntity;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const endsWithNumber = (str: string) => {
|
|
26
|
+
return /[0-9]+$/.test(str);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const getNumberStrAtEnd = (str: string) => {
|
|
30
|
+
if (endsWithNumber(str)) {
|
|
31
|
+
return str.match(/[0-9]+$/)?.[0];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const stripNumberAtEnd = (str: string) => {
|
|
38
|
+
return str?.replace?.(getNumberStrAtEnd(str) || "", "");
|
|
39
|
+
};
|