@macrostrat/data-sheet 2.2.4 → 3.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/CHANGELOG.md +12 -0
- package/dist/components/actions.cjs +16 -0
- package/dist/components/actions.cjs.map +1 -0
- package/dist/components/actions.d.ts +2 -0
- package/dist/components/actions.js +14 -0
- package/dist/components/actions.js.map +1 -0
- package/dist/components/actions.module.sass.cjs +7 -0
- package/dist/components/actions.module.sass.cjs.map +1 -0
- package/dist/components/actions.module.sass.js +8 -0
- package/dist/components/actions.module.sass.js.map +1 -0
- package/dist/components/colors.cjs +105 -0
- package/dist/components/colors.cjs.map +1 -0
- package/dist/components/colors.d.ts +27 -0
- package/dist/components/colors.js +102 -0
- package/dist/components/colors.js.map +1 -0
- package/dist/components/editor-popup.cjs +79 -0
- package/dist/components/editor-popup.cjs.map +1 -0
- package/dist/components/editor-popup.d.ts +1 -0
- package/dist/components/editor-popup.js +77 -0
- package/dist/components/editor-popup.js.map +1 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/main.module.sass.cjs +18 -0
- package/dist/components/main.module.sass.cjs.map +1 -0
- package/dist/components/main.module.sass.js +18 -0
- package/dist/components/main.module.sass.js.map +1 -0
- package/dist/components/text-areas.cjs +43 -0
- package/dist/components/text-areas.cjs.map +1 -0
- package/dist/components/text-areas.d.ts +4 -0
- package/dist/components/text-areas.js +41 -0
- package/dist/components/text-areas.js.map +1 -0
- package/dist/core.cjs +480 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.ts +31 -0
- package/dist/core.js +475 -0
- package/dist/core.js.map +1 -0
- package/dist/data-sheet.css +1336 -0
- package/dist/index.cjs +51 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/main.module.sass.cjs +19 -0
- package/dist/main.module.sass.cjs.map +1 -0
- package/dist/main.module.sass.js +19 -0
- package/dist/main.module.sass.js.map +1 -0
- package/dist/postgrest-table/data-loaders.cjs +191 -0
- package/dist/postgrest-table/data-loaders.cjs.map +1 -0
- package/dist/postgrest-table/data-loaders.d.ts +55 -0
- package/dist/postgrest-table/data-loaders.js +189 -0
- package/dist/postgrest-table/data-loaders.js.map +1 -0
- package/dist/postgrest-table/index.cjs +214 -0
- package/dist/postgrest-table/index.cjs.map +1 -0
- package/dist/postgrest-table/index.d.ts +56 -0
- package/dist/postgrest-table/index.js +212 -0
- package/dist/postgrest-table/index.js.map +1 -0
- package/dist/postgrest-table/main.module.sass.cjs +22 -0
- package/dist/postgrest-table/main.module.sass.cjs.map +1 -0
- package/dist/postgrest-table/main.module.sass.js +22 -0
- package/dist/postgrest-table/main.module.sass.js.map +1 -0
- package/dist/provider.cjs +379 -0
- package/dist/provider.cjs.map +1 -0
- package/dist/provider.d.ts +69 -0
- package/dist/provider.js +376 -0
- package/dist/provider.js.map +1 -0
- package/dist/utils/column-spec.cjs +99 -0
- package/dist/utils/column-spec.cjs.map +1 -0
- package/dist/utils/column-spec.d.ts +31 -0
- package/dist/utils/column-spec.js +99 -0
- package/dist/utils/column-spec.js.map +1 -0
- package/dist/utils/index.cjs +9 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/key-handling.cjs +85 -0
- package/dist/utils/key-handling.cjs.map +1 -0
- package/dist/utils/key-handling.d.ts +5 -0
- package/dist/utils/key-handling.js +85 -0
- package/dist/utils/key-handling.js.map +1 -0
- package/package.json +44 -38
- package/src/components/colors.ts +1 -1
- package/src/components/editor-popup.ts +2 -2
- package/src/components/text-areas.ts +1 -1
- package/src/core.ts +2 -8
- package/src/main.module.sass +7 -7
- package/src/postgrest-table/index.ts +6 -6
- package/src/postgrest-table/main.module.sass +1 -1
- package/src/provider.ts +1 -1
- package/dist/esm/data-sheet.186dcac8.js +0 -86
- package/dist/esm/data-sheet.186dcac8.js.map +0 -1
- package/dist/esm/data-sheet.2e11f097.js +0 -13
- package/dist/esm/data-sheet.2e11f097.js.map +0 -1
- package/dist/esm/data-sheet.37e35216.js +0 -40
- package/dist/esm/data-sheet.37e35216.js.map +0 -1
- package/dist/esm/data-sheet.403b9693.js +0 -429
- package/dist/esm/data-sheet.403b9693.js.map +0 -1
- package/dist/esm/data-sheet.40866550.js +0 -58
- package/dist/esm/data-sheet.40866550.js.map +0 -1
- package/dist/esm/data-sheet.410c5122.js +0 -83
- package/dist/esm/data-sheet.410c5122.js.map +0 -1
- package/dist/esm/data-sheet.48635112.js +0 -40
- package/dist/esm/data-sheet.48635112.js.map +0 -1
- package/dist/esm/data-sheet.53ee5bf7.js +0 -102
- package/dist/esm/data-sheet.53ee5bf7.js.map +0 -1
- package/dist/esm/data-sheet.54cfa8e8.js +0 -16
- package/dist/esm/data-sheet.54cfa8e8.js.map +0 -1
- package/dist/esm/data-sheet.560943e5.js +0 -237
- package/dist/esm/data-sheet.560943e5.js.map +0 -1
- package/dist/esm/data-sheet.706f955d.css +0 -11
- package/dist/esm/data-sheet.706f955d.css.map +0 -1
- package/dist/esm/data-sheet.8dbfccef.js +0 -16
- package/dist/esm/data-sheet.8dbfccef.js.map +0 -1
- package/dist/esm/data-sheet.9a4e4e01.js +0 -77
- package/dist/esm/data-sheet.9a4e4e01.js.map +0 -1
- package/dist/esm/data-sheet.a3eb6088.js +0 -21
- package/dist/esm/data-sheet.a3eb6088.js.map +0 -1
- package/dist/esm/data-sheet.a7230b2f.css +0 -69
- package/dist/esm/data-sheet.a7230b2f.css.map +0 -1
- package/dist/esm/data-sheet.b3ccc91b.css +0 -65
- package/dist/esm/data-sheet.b3ccc91b.css.map +0 -1
- package/dist/esm/data-sheet.c9b6b6f2.js +0 -439
- package/dist/esm/data-sheet.c9b6b6f2.js.map +0 -1
- package/dist/esm/data-sheet.d2160988.js +0 -218
- package/dist/esm/data-sheet.d2160988.js.map +0 -1
- package/dist/esm/data-sheet.d570ef95.js +0 -43
- package/dist/esm/data-sheet.d570ef95.js.map +0 -1
- package/dist/esm/data-sheet.ef63e366.css +0 -110
- package/dist/esm/data-sheet.ef63e366.css.map +0 -1
- package/dist/esm/index.d.ts +0 -292
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -15
- package/dist/esm/index.js.map +0 -1
- package/dist/node/data-sheet.28641e23.css +0 -2
- package/dist/node/data-sheet.28641e23.css.map +0 -1
- package/dist/node/data-sheet.2cac1a8c.js +0 -2
- package/dist/node/data-sheet.2cac1a8c.js.map +0 -1
- package/dist/node/data-sheet.3680e59d.js +0 -2
- package/dist/node/data-sheet.3680e59d.js.map +0 -1
- package/dist/node/data-sheet.3c728e09.js +0 -2
- package/dist/node/data-sheet.3c728e09.js.map +0 -1
- package/dist/node/data-sheet.474755ec.js +0 -2
- package/dist/node/data-sheet.474755ec.js.map +0 -1
- package/dist/node/data-sheet.648db7af.js +0 -2
- package/dist/node/data-sheet.648db7af.js.map +0 -1
- package/dist/node/data-sheet.7b95fbc1.css +0 -2
- package/dist/node/data-sheet.7b95fbc1.css.map +0 -1
- package/dist/node/data-sheet.945becc3.js +0 -2
- package/dist/node/data-sheet.945becc3.js.map +0 -1
- package/dist/node/data-sheet.97ac1b50.js +0 -2
- package/dist/node/data-sheet.97ac1b50.js.map +0 -1
- package/dist/node/data-sheet.ae543670.js +0 -2
- package/dist/node/data-sheet.ae543670.js.map +0 -1
- package/dist/node/data-sheet.afb25a47.js +0 -2
- package/dist/node/data-sheet.afb25a47.js.map +0 -1
- package/dist/node/data-sheet.bb45401c.js +0 -2
- package/dist/node/data-sheet.bb45401c.js.map +0 -1
- package/dist/node/data-sheet.c90cb14b.css +0 -2
- package/dist/node/data-sheet.c90cb14b.css.map +0 -1
- package/dist/node/data-sheet.cbbc8d31.js +0 -2
- package/dist/node/data-sheet.cbbc8d31.js.map +0 -1
- package/dist/node/data-sheet.d971095a.js +0 -2
- package/dist/node/data-sheet.d971095a.js.map +0 -1
- package/dist/node/data-sheet.dffdda71.js +0 -2
- package/dist/node/data-sheet.dffdda71.js.map +0 -1
- package/dist/node/data-sheet.e472411d.js +0 -2
- package/dist/node/data-sheet.e472411d.js.map +0 -1
- package/dist/node/data-sheet.ef0c95f4.js +0 -2
- package/dist/node/data-sheet.ef0c95f4.js.map +0 -1
- package/dist/node/data-sheet.f0223f39.js +0 -2
- package/dist/node/data-sheet.f0223f39.js.map +0 -1
- package/dist/node/data-sheet.ffaf8ac7.css +0 -2
- package/dist/node/data-sheet.ffaf8ac7.css.map +0 -1
- package/dist/node/index.js +0 -2
- package/dist/node/index.js.map +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const defaultRenderers = {
|
|
2
|
+
string: (d) => d,
|
|
3
|
+
number: (d) => d?.toFixed(2),
|
|
4
|
+
boolean: (d) => d ? "T" : "F",
|
|
5
|
+
object: (d) => JSON.stringify(d),
|
|
6
|
+
integer: (d) => d?.toFixed(0),
|
|
7
|
+
array: (d) => d?.join(", ")
|
|
8
|
+
};
|
|
9
|
+
const defaultWidthForValue = (val) => String(val).length * 8;
|
|
10
|
+
function generateDefaultColumnSpec(data, options = {}) {
|
|
11
|
+
if (data == null) return [];
|
|
12
|
+
const {
|
|
13
|
+
defaultWidth = 150,
|
|
14
|
+
calculateWidths = true,
|
|
15
|
+
getWidthForValue = defaultWidthForValue
|
|
16
|
+
} = options;
|
|
17
|
+
const keys = /* @__PURE__ */ new Set();
|
|
18
|
+
const types = /* @__PURE__ */ new Map();
|
|
19
|
+
const columnWidths = /* @__PURE__ */ new Map();
|
|
20
|
+
for (const row of data) {
|
|
21
|
+
if (row == null) continue;
|
|
22
|
+
for (const key of Object.keys(row)) {
|
|
23
|
+
const val = row[key];
|
|
24
|
+
keys.add(key);
|
|
25
|
+
if (val == null) continue;
|
|
26
|
+
if (calculateWidths) {
|
|
27
|
+
let width = getWidthForValue(val);
|
|
28
|
+
if (width != null && width >= 0) {
|
|
29
|
+
columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
let type = typeof val;
|
|
33
|
+
if (Number.isInteger(val)) {
|
|
34
|
+
type = "integer";
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(val) && val.every((d) => typeof d === "string" || typeof d === "number")) {
|
|
37
|
+
type = "array";
|
|
38
|
+
}
|
|
39
|
+
if (types.has(key)) {
|
|
40
|
+
if (types.get(key) !== type) {
|
|
41
|
+
if (type === "number" && types.get(key) === "integer") {
|
|
42
|
+
types.set(key, "number");
|
|
43
|
+
}
|
|
44
|
+
if (type === "object" && types.get(key) === "array") {
|
|
45
|
+
types.set(key, "object");
|
|
46
|
+
}
|
|
47
|
+
types.set(key, "string");
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
types.set(key, type);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const spec = [];
|
|
55
|
+
for (const key of keys) {
|
|
56
|
+
let width = null;
|
|
57
|
+
if (calculateWidths) {
|
|
58
|
+
width = Math.min(
|
|
59
|
+
Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),
|
|
60
|
+
defaultWidth * 1.5
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
spec.push({
|
|
64
|
+
name: key,
|
|
65
|
+
key,
|
|
66
|
+
valueRenderer: defaultRenderers[types.get(key)],
|
|
67
|
+
width
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return spec;
|
|
71
|
+
}
|
|
72
|
+
function generateColumnSpec(data, options) {
|
|
73
|
+
const { overrides = {}, nRows = 10, omitColumns, includeColumns } = options;
|
|
74
|
+
if (data == null) return [];
|
|
75
|
+
const _nRows = Math.min(nRows, data.length);
|
|
76
|
+
let columnSpec = generateDefaultColumnSpec(data.slice(0, _nRows));
|
|
77
|
+
let filteredSpec = columnSpec.filter((col) => {
|
|
78
|
+
if (omitColumns != null && omitColumns.includes(col.key)) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (includeColumns != null && !includeColumns.includes(col.key)) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
});
|
|
86
|
+
return filteredSpec.map((col) => {
|
|
87
|
+
let ovr = overrides[col.key];
|
|
88
|
+
if (ovr == null) return col;
|
|
89
|
+
if (typeof ovr === "string") {
|
|
90
|
+
return { ...col, name: ovr };
|
|
91
|
+
}
|
|
92
|
+
return { ...col, ...ovr };
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
export {
|
|
96
|
+
generateColumnSpec,
|
|
97
|
+
generateDefaultColumnSpec
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=column-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-spec.js","sources":["../../src/utils/column-spec.ts"],"sourcesContent":["import React from \"react\";\n\nconst defaultRenderers = {\n string: (d) => d,\n number: (d) => d?.toFixed(2),\n boolean: (d) => (d ? \"T\" : \"F\"),\n object: (d) => JSON.stringify(d),\n integer: (d) => d?.toFixed(0),\n array: (d) => d?.join(\", \"),\n};\n\ninterface ColumnSpecGenerateOptions {\n calculateWidths?: boolean;\n defaultWidth?: number;\n getWidthForValue?: (value: any) => number;\n}\n\nconst defaultWidthForValue = (val) => String(val).length * 8;\n\nexport interface ColumnSpec {\n name: string;\n key: string;\n required?: boolean;\n isValid?: (d: any) => boolean;\n transformValue?: (d: any) => any;\n valueRenderer?: (d: any) => string | React.ReactNode;\n dataEditor?: any;\n cellComponent?: any;\n category?: string;\n editable?: boolean;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n style?: React.CSSProperties;\n width?: number;\n}\n\nexport interface ColumnSpecOptions<T> {\n overrides: Record<string, Partial<ColumnSpec> | string>;\n data?: T[]; // Data to use for type inference\n nRows?: number; // Number of rows to use for type inference\n omitColumns?: string[]; // Columns to omit. Takes precedence over includeColumns.\n includeColumns?: string[]; // Columns to include.\n}\n\nexport function generateDefaultColumnSpec<T>(\n data: Array<T>,\n options: ColumnSpecGenerateOptions = {},\n): ColumnSpec[] {\n /** Build a default column spec from a dataset based on the first n rows */\n if (data == null) return [];\n // Get the keys\n\n const {\n defaultWidth = 150,\n calculateWidths = true,\n getWidthForValue = defaultWidthForValue,\n } = options;\n\n const keys = new Set<string>();\n const types = new Map();\n\n const columnWidths = new Map<string, number>();\n\n for (const row of data) {\n if (row == null) continue;\n for (const key of Object.keys(row)) {\n const val = row[key];\n keys.add(key);\n\n if (val == null) continue;\n\n if (calculateWidths) {\n let width = getWidthForValue(val);\n if (width != null && width >= 0) {\n columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));\n }\n }\n\n let type: string = typeof val;\n // Special 'type' for integers\n if (Number.isInteger(val)) {\n type = \"integer\";\n }\n\n // Special 'type' for arrays of simple values\n if (\n Array.isArray(val) &&\n val.every((d) => typeof d === \"string\" || typeof d === \"number\")\n ) {\n type = \"array\";\n }\n\n if (types.has(key)) {\n if (types.get(key) !== type) {\n if (type === \"number\" && types.get(key) === \"integer\") {\n types.set(key, \"number\");\n }\n if (type === \"object\" && types.get(key) === \"array\") {\n types.set(key, \"object\");\n }\n\n types.set(key, \"string\");\n }\n } else {\n types.set(key, type);\n }\n }\n }\n\n // Build a column spec\n const spec = [];\n for (const key of keys) {\n let width = null;\n if (calculateWidths) {\n // If we are calculating widths, use the value lengths\n width = Math.min(\n Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),\n defaultWidth * 1.5,\n );\n }\n\n spec.push({\n name: key,\n key,\n valueRenderer: defaultRenderers[types.get(key)],\n width,\n });\n }\n return spec;\n}\n\nexport function generateColumnSpec<T>(\n data: T[],\n options: ColumnSpecOptions<T>,\n): ColumnSpec[] {\n /** Generate a column spec from a dataset */\n const { overrides = {}, nRows = 10, omitColumns, includeColumns } = options;\n\n if (data == null) return [];\n\n const _nRows = Math.min(nRows, data.length);\n\n let columnSpec = generateDefaultColumnSpec(data.slice(0, _nRows));\n let filteredSpec = columnSpec.filter((col) => {\n if (omitColumns != null && omitColumns.includes(col.key)) {\n return false;\n }\n if (includeColumns != null && !includeColumns.includes(col.key)) {\n return false;\n }\n return true;\n });\n\n // Apply overrides\n return filteredSpec.map((col) => {\n let ovr = overrides[col.key];\n if (ovr == null) return col;\n if (typeof ovr === \"string\") {\n return { ...col, name: ovr };\n }\n return { ...col, ...ovr };\n });\n}\n"],"names":[],"mappings":"AAEA,MAAM,mBAAmB;AAAA,EACvB,QAAQ,CAAC,MAAM;AAAA,EACf,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC3B,SAAS,CAAC,MAAO,IAAI,MAAM;AAAA,EAC3B,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC;AAAA,EAC/B,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC5B,OAAO,CAAC,MAAM,GAAG,KAAK,IAAI;AAC5B;AAQA,MAAM,uBAAuB,CAAC,QAAQ,OAAO,GAAG,EAAE,SAAS;AA0BpD,SAAS,0BACd,MACA,UAAqC,IACvB;AAEd,MAAI,QAAQ,KAAM,QAAO,CAAA;AAGzB,QAAM;AAAA,IACJ,eAAe;AAAA,IACf,kBAAkB;AAAA,IAClB,mBAAmB;AAAA,EAAA,IACjB;AAEJ,QAAM,2BAAW,IAAA;AACjB,QAAM,4BAAY,IAAA;AAElB,QAAM,mCAAmB,IAAA;AAEzB,aAAW,OAAO,MAAM;AACtB,QAAI,OAAO,KAAM;AACjB,eAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,YAAM,MAAM,IAAI,GAAG;AACnB,WAAK,IAAI,GAAG;AAEZ,UAAI,OAAO,KAAM;AAEjB,UAAI,iBAAiB;AACnB,YAAI,QAAQ,iBAAiB,GAAG;AAChC,YAAI,SAAS,QAAQ,SAAS,GAAG;AAC/B,uBAAa,IAAI,KAAK,KAAK,IAAI,OAAO,aAAa,IAAI,GAAG,KAAK,CAAC,CAA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;AAChE,MAAI,eAAe,WAAW,OAAO,CAAC,QAAQ;AAC5C,QAAI,eAAe,QAAQ,YAAY,SAAS,IAAI,GAAG,GAAG;AACxD,aAAO;AAAA,IACT;AACA,QAAI,kBAAkB,QAAQ,CAAC,eAAe,SAAS,IAAI,GAAG,GAAG;AAC/D,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,CAAC;AAGD,SAAO,aAAa,IAAI,CAAC,QAAQ;AAC/B,QAAI,MAAM,UAAU,IAAI,GAAG;AAC3B,QAAI,OAAO,KAAM,QAAO;AACxB,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,EAAE,GAAG,KAAK,MAAM,IAAA;AAAA,IACzB;AACA,WAAO,EAAE,GAAG,KAAK,GAAG,IAAA;AAAA,EACtB,CAAC;AACH;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function range(arr) {
|
|
4
|
+
if (arr.length != 2) throw new Error("Range must have two elements");
|
|
5
|
+
const [start, end] = arr;
|
|
6
|
+
return Array.from({ length: end - start + 1 }, (_, i) => i + start);
|
|
7
|
+
}
|
|
8
|
+
exports.range = range;
|
|
9
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./column-spec\";\nexport * from \"./key-handling\";\n\nexport function range(arr: number[]) {\n if (arr.length != 2) throw new Error(\"Range must have two elements\");\n const [start, end] = arr;\n return Array.from({ length: end - start + 1 }, (_, i) => i + start);\n}\n"],"names":[],"mappings":";;AAGO,SAAS,MAAM,KAAe;AACnC,MAAI,IAAI,UAAU,EAAG,OAAM,IAAI,MAAM,8BAA8B;AACnE,QAAM,CAAC,OAAO,GAAG,IAAI;AACrB,SAAO,MAAM,KAAK,EAAE,QAAQ,MAAM,QAAQ,EAAA,GAAK,CAAC,GAAG,MAAM,IAAI,KAAK;AACpE;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./column-spec\";\nexport * from \"./key-handling\";\n\nexport function range(arr: number[]) {\n if (arr.length != 2) throw new Error(\"Range must have two elements\");\n const [start, end] = arr;\n return Array.from({ length: end - start + 1 }, (_, i) => i + start);\n}\n"],"names":[],"mappings":"AAGO,SAAS,MAAM,KAAe;AACnC,MAAI,IAAI,UAAU,EAAG,OAAM,IAAI,MAAM,8BAA8B;AACnE,QAAM,CAAC,OAAO,GAAG,IAAI;AACrB,SAAO,MAAM,KAAK,EAAE,QAAQ,MAAM,QAAQ,EAAA,GAAK,CAAC,GAAG,MAAM,IAAI,KAAK;AACpE;"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function tableKeyHandler(e, state) {
|
|
4
|
+
if (e.key === "Escape") {
|
|
5
|
+
state.setSelection([]);
|
|
6
|
+
e.preventDefault();
|
|
7
|
+
e.stopPropagation();
|
|
8
|
+
}
|
|
9
|
+
if (e.key === "Backspace" || e.key === "Delete") {
|
|
10
|
+
state.clearSelection();
|
|
11
|
+
e.preventDefault();
|
|
12
|
+
}
|
|
13
|
+
if (e.key in directionMap) {
|
|
14
|
+
const direction = directionMap[e.key];
|
|
15
|
+
state.moveFocusedCell(direction);
|
|
16
|
+
e.preventDefault();
|
|
17
|
+
}
|
|
18
|
+
if (e.key === "Tab") {
|
|
19
|
+
state.moveFocusedCell(e.shiftKey ? "left" : "right");
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
}
|
|
22
|
+
if (e.key === "Enter") {
|
|
23
|
+
state.moveFocusedCell("down");
|
|
24
|
+
e.preventDefault();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const directionMap = {
|
|
28
|
+
ArrowUp: "up",
|
|
29
|
+
ArrowDown: "down",
|
|
30
|
+
ArrowLeft: "left",
|
|
31
|
+
ArrowRight: "right"
|
|
32
|
+
};
|
|
33
|
+
function editorKeyHandler(e, isSingleCellSelection) {
|
|
34
|
+
let shouldCaptureEventForInlineEditing = true;
|
|
35
|
+
if (e.key == "Enter") {
|
|
36
|
+
shouldCaptureEventForInlineEditing = e.shiftKey;
|
|
37
|
+
}
|
|
38
|
+
if (e.key == "Escape" || e.key == "Tab") {
|
|
39
|
+
shouldCaptureEventForInlineEditing = false;
|
|
40
|
+
}
|
|
41
|
+
if (e.key == "Backspace" || e.key == "Delete") {
|
|
42
|
+
shouldCaptureEventForInlineEditing = isSingleCellSelection && !e.shiftKey;
|
|
43
|
+
}
|
|
44
|
+
if (!shouldCaptureEventForInlineEditing) {
|
|
45
|
+
e.target.blur();
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const shouldPropagate = handleSpecialKeys(e);
|
|
50
|
+
if (!shouldPropagate) {
|
|
51
|
+
e.stopPropagation();
|
|
52
|
+
} else {
|
|
53
|
+
e.target.blur();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function multiLineTextKeyHandler(evt) {
|
|
57
|
+
if (evt.key === "Enter") {
|
|
58
|
+
evt.stopPropagation();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (evt.key === "Escape") {
|
|
62
|
+
evt.preventDefault();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const shouldPropagate = handleSpecialKeys(evt);
|
|
66
|
+
if (!shouldPropagate) {
|
|
67
|
+
evt.stopPropagation();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function handleSpecialKeys(evt) {
|
|
71
|
+
const target = evt.target;
|
|
72
|
+
if ((evt.key === "ArrowLeft" || evt.key === "ArrowUp" || evt.key === "ArrowDown") && target.selectionStart === 0) {
|
|
73
|
+
target.blur();
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
if ((evt.key === "ArrowRight" || evt.key === "ArrowUp" || evt.key === "Tab" || evt.key === "Enter" || evt.key === "ArrowDown") && target.selectionStart === evt.target.value.length) {
|
|
77
|
+
target.blur();
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
exports.editorKeyHandler = editorKeyHandler;
|
|
83
|
+
exports.multiLineTextKeyHandler = multiLineTextKeyHandler;
|
|
84
|
+
exports.tableKeyHandler = tableKeyHandler;
|
|
85
|
+
//# sourceMappingURL=key-handling.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-handling.cjs","sources":["../../src/utils/key-handling.ts"],"sourcesContent":["import type { KeyboardEvent } from \"react\";\nimport { DataSheetStoreMain } from \"@macrostrat/data-sheet\";\n\nexport function tableKeyHandler<T>(\n e: KeyboardEvent,\n state: DataSheetStoreMain<T>,\n) {\n // General key event\n if (e.key === \"Escape\") {\n // Clear selection on Escape\n state.setSelection([]);\n e.preventDefault();\n e.stopPropagation();\n }\n // Clear selection on Backspace or Delete\n if (e.key === \"Backspace\" || e.key === \"Delete\") {\n // Clear selection on Backspace or Delete\n state.clearSelection();\n e.preventDefault();\n }\n // Handle arrow keys for navigation\n if (e.key in directionMap) {\n // Handle arrow key navigation\n const direction = directionMap[e.key];\n state.moveFocusedCell(direction);\n // Prevent default scrolling behavior\n e.preventDefault();\n }\n if (e.key === \"Tab\") {\n state.moveFocusedCell(e.shiftKey ? \"left\" : \"right\");\n e.preventDefault();\n }\n if (e.key === \"Enter\") {\n state.moveFocusedCell(\"down\");\n e.preventDefault();\n }\n}\n\nconst directionMap = {\n ArrowUp: \"up\",\n ArrowDown: \"down\",\n ArrowLeft: \"left\",\n ArrowRight: \"right\",\n};\n\nexport function editorKeyHandler(\n e: KeyboardEvent,\n isSingleCellSelection: boolean,\n) {\n /** Get a key handler for inline cell editing */\n\n // if (e.key == \"Enter\" || e.key == \"Tab\") {\n // e.target.blur();\n // return;\n // }\n\n let shouldCaptureEventForInlineEditing = true;\n\n if (e.key == \"Enter\") {\n shouldCaptureEventForInlineEditing = e.shiftKey;\n }\n\n if (e.key == \"Escape\" || e.key == \"Tab\") {\n shouldCaptureEventForInlineEditing = false;\n }\n\n if (e.key == \"Backspace\" || e.key == \"Delete\") {\n /** Clear selection on Backspace or Delete on a multi-cell selection\n * (if shift is held, we allow deletion in a single cell)\n */\n shouldCaptureEventForInlineEditing = isSingleCellSelection && !e.shiftKey;\n }\n\n if (!shouldCaptureEventForInlineEditing) {\n e.target.blur();\n e.preventDefault();\n return;\n }\n\n const shouldPropagate = handleSpecialKeys(e);\n if (!shouldPropagate) {\n e.stopPropagation();\n } else {\n e.target.blur();\n //e.target.parentNode.dispatchEvent(new KeyboardEvent(\"keydown\", e));\n }\n}\n\nexport function multiLineTextKeyHandler(evt: InputEvent) {\n if (evt.key === \"Enter\") {\n //evt.preventDefault();\n evt.stopPropagation();\n return;\n }\n\n if (evt.key === \"Escape\") {\n evt.preventDefault();\n return;\n }\n\n const shouldPropagate = handleSpecialKeys(evt);\n if (!shouldPropagate) {\n evt.stopPropagation();\n }\n}\n\nfunction handleSpecialKeys(evt: KeyboardEvent): boolean {\n const target = evt.target;\n if (\n (evt.key === \"ArrowLeft\" ||\n evt.key === \"ArrowUp\" ||\n evt.key === \"ArrowDown\") &&\n target.selectionStart === 0\n ) {\n target.blur();\n return true;\n }\n\n if (\n (evt.key === \"ArrowRight\" ||\n evt.key === \"ArrowUp\" ||\n evt.key === \"Tab\" ||\n evt.key === \"Enter\" ||\n evt.key === \"ArrowDown\") &&\n target.selectionStart === evt.target.value.length\n ) {\n target.blur();\n return true;\n }\n\n return false;\n}\n"],"names":[],"mappings":";;AAGO,SAAS,gBACd,GACA,OACA;AAEA,MAAI,EAAE,QAAQ,UAAU;AAEtB,UAAM,aAAa,EAAE;AACrB,MAAE,eAAA;AACF,MAAE,gBAAA;AAAA,EACJ;AAEA,MAAI,E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ACpB,QAAI,gBAAA;AAAA,EACN;AACF;AAEA,SAAS,kBAAkB,KAA6B;AACtD,QAAM,SAAS,IAAI;AACnB,OACG,IAAI,QAAQ,eACX,IAAI,QAAQ,aACZ,IAAI,QAAQ,gBACd,OAAO,mBAAmB,GAC1B;AACA,WAAO,KAAA;AACP,WAAO;AAAA,EACT;AAEA,OACG,IAAI,QAAQ,gBACX,IAAI,QAAQ,aACZ,IAAI,QAAQ,SACZ,IAAI,QAAQ,WACZ,IAAI,QAAQ,gBACd,OAAO,mBAAmB,IAAI,OAAO,MAAM,QAC3C;AACA,WAAO,KAAA;AACP,WAAO;AAAA,EACT;AAEA,SAAO;AACT;;;;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { KeyboardEvent } from 'react';
|
|
2
|
+
import { DataSheetStoreMain } from '@macrostrat/data-sheet';
|
|
3
|
+
export declare function tableKeyHandler<T>(e: KeyboardEvent, state: DataSheetStoreMain<T>): void;
|
|
4
|
+
export declare function editorKeyHandler(e: KeyboardEvent, isSingleCellSelection: boolean): void;
|
|
5
|
+
export declare function multiLineTextKeyHandler(evt: InputEvent): void;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
function tableKeyHandler(e, state) {
|
|
2
|
+
if (e.key === "Escape") {
|
|
3
|
+
state.setSelection([]);
|
|
4
|
+
e.preventDefault();
|
|
5
|
+
e.stopPropagation();
|
|
6
|
+
}
|
|
7
|
+
if (e.key === "Backspace" || e.key === "Delete") {
|
|
8
|
+
state.clearSelection();
|
|
9
|
+
e.preventDefault();
|
|
10
|
+
}
|
|
11
|
+
if (e.key in directionMap) {
|
|
12
|
+
const direction = directionMap[e.key];
|
|
13
|
+
state.moveFocusedCell(direction);
|
|
14
|
+
e.preventDefault();
|
|
15
|
+
}
|
|
16
|
+
if (e.key === "Tab") {
|
|
17
|
+
state.moveFocusedCell(e.shiftKey ? "left" : "right");
|
|
18
|
+
e.preventDefault();
|
|
19
|
+
}
|
|
20
|
+
if (e.key === "Enter") {
|
|
21
|
+
state.moveFocusedCell("down");
|
|
22
|
+
e.preventDefault();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const directionMap = {
|
|
26
|
+
ArrowUp: "up",
|
|
27
|
+
ArrowDown: "down",
|
|
28
|
+
ArrowLeft: "left",
|
|
29
|
+
ArrowRight: "right"
|
|
30
|
+
};
|
|
31
|
+
function editorKeyHandler(e, isSingleCellSelection) {
|
|
32
|
+
let shouldCaptureEventForInlineEditing = true;
|
|
33
|
+
if (e.key == "Enter") {
|
|
34
|
+
shouldCaptureEventForInlineEditing = e.shiftKey;
|
|
35
|
+
}
|
|
36
|
+
if (e.key == "Escape" || e.key == "Tab") {
|
|
37
|
+
shouldCaptureEventForInlineEditing = false;
|
|
38
|
+
}
|
|
39
|
+
if (e.key == "Backspace" || e.key == "Delete") {
|
|
40
|
+
shouldCaptureEventForInlineEditing = isSingleCellSelection && !e.shiftKey;
|
|
41
|
+
}
|
|
42
|
+
if (!shouldCaptureEventForInlineEditing) {
|
|
43
|
+
e.target.blur();
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const shouldPropagate = handleSpecialKeys(e);
|
|
48
|
+
if (!shouldPropagate) {
|
|
49
|
+
e.stopPropagation();
|
|
50
|
+
} else {
|
|
51
|
+
e.target.blur();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function multiLineTextKeyHandler(evt) {
|
|
55
|
+
if (evt.key === "Enter") {
|
|
56
|
+
evt.stopPropagation();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (evt.key === "Escape") {
|
|
60
|
+
evt.preventDefault();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const shouldPropagate = handleSpecialKeys(evt);
|
|
64
|
+
if (!shouldPropagate) {
|
|
65
|
+
evt.stopPropagation();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function handleSpecialKeys(evt) {
|
|
69
|
+
const target = evt.target;
|
|
70
|
+
if ((evt.key === "ArrowLeft" || evt.key === "ArrowUp" || evt.key === "ArrowDown") && target.selectionStart === 0) {
|
|
71
|
+
target.blur();
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
if ((evt.key === "ArrowRight" || evt.key === "ArrowUp" || evt.key === "Tab" || evt.key === "Enter" || evt.key === "ArrowDown") && target.selectionStart === evt.target.value.length) {
|
|
75
|
+
target.blur();
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
editorKeyHandler,
|
|
82
|
+
multiLineTextKeyHandler,
|
|
83
|
+
tableKeyHandler
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=key-handling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-handling.js","sources":["../../src/utils/key-handling.ts"],"sourcesContent":["import type { KeyboardEvent } from \"react\";\nimport { DataSheetStoreMain } from \"@macrostrat/data-sheet\";\n\nexport function tableKeyHandler<T>(\n e: KeyboardEvent,\n state: DataSheetStoreMain<T>,\n) {\n // General key event\n if (e.key === \"Escape\") {\n // Clear selection on Escape\n state.setSelection([]);\n e.preventDefault();\n e.stopPropagation();\n }\n // Clear selection on Backspace or Delete\n if (e.key === \"Backspace\" || e.key === \"Delete\") {\n // Clear selection on Backspace or Delete\n state.clearSelection();\n e.preventDefault();\n }\n // Handle arrow keys for navigation\n if (e.key in directionMap) {\n // Handle arrow key navigation\n const direction = directionMap[e.key];\n state.moveFocusedCell(direction);\n // Prevent default scrolling behavior\n e.preventDefault();\n }\n if (e.key === \"Tab\") {\n state.moveFocusedCell(e.shiftKey ? \"left\" : \"right\");\n e.preventDefault();\n }\n if (e.key === \"Enter\") {\n state.moveFocusedCell(\"down\");\n e.preventDefault();\n }\n}\n\nconst directionMap = {\n ArrowUp: \"up\",\n ArrowDown: \"down\",\n ArrowLeft: \"left\",\n ArrowRight: \"right\",\n};\n\nexport function editorKeyHandler(\n e: KeyboardEvent,\n isSingleCellSelection: boolean,\n) {\n /** Get a key handler for inline cell editing */\n\n // if (e.key == \"Enter\" || e.key == \"Tab\") {\n // e.target.blur();\n // return;\n // }\n\n let shouldCaptureEventForInlineEditing = true;\n\n if (e.key == \"Enter\") {\n shouldCaptureEventForInlineEditing = e.shiftKey;\n }\n\n if (e.key == \"Escape\" || e.key == \"Tab\") {\n shouldCaptureEventForInlineEditing = false;\n }\n\n if (e.key == \"Backspace\" || e.key == \"Delete\") {\n /** Clear selection on Backspace or Delete on a multi-cell selection\n * (if shift is held, we allow deletion in a single cell)\n */\n shouldCaptureEventForInlineEditing = isSingleCellSelection && !e.shiftKey;\n }\n\n if (!shouldCaptureEventForInlineEditing) {\n e.target.blur();\n e.preventDefault();\n return;\n }\n\n const shouldPropagate = handleSpecialKeys(e);\n if (!shouldPropagate) {\n e.stopPropagation();\n } else {\n e.target.blur();\n //e.target.parentNode.dispatchEvent(new KeyboardEvent(\"keydown\", e));\n }\n}\n\nexport function multiLineTextKeyHandler(evt: InputEvent) {\n if (evt.key === \"Enter\") {\n //evt.preventDefault();\n evt.stopPropagation();\n return;\n }\n\n if (evt.key === \"Escape\") {\n evt.preventDefault();\n return;\n }\n\n const shouldPropagate = handleSpecialKeys(evt);\n if (!shouldPropagate) {\n evt.stopPropagation();\n }\n}\n\nfunction handleSpecialKeys(evt: KeyboardEvent): boolean {\n const target = evt.target;\n if (\n (evt.key === \"ArrowLeft\" ||\n evt.key === \"ArrowUp\" ||\n evt.key === \"ArrowDown\") &&\n target.selectionStart === 0\n ) {\n target.blur();\n return true;\n }\n\n if (\n (evt.key === \"ArrowRight\" ||\n evt.key === \"ArrowUp\" ||\n evt.key === \"Tab\" ||\n evt.key === \"Enter\" ||\n evt.key === \"ArrowDown\") &&\n target.selectionStart === evt.target.value.length\n ) {\n target.blur();\n return true;\n }\n\n return false;\n}\n"],"names":[],"mappings":"AAGO,SAAS,gBACd,GACA,OACA;AAEA,MAA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Q,UAAU;AACxB,QAAI,eAAA;AACJ;AAAA,EACF;AAEA,QAAM,kBAAkB,kBAAkB,GAAG;AAC7C,MAAI,CAAC,iBAAiB;AACpB,QAAI,gBAAA;AAAA,EACN;AACF;AAEA,SAAS,kBAAkB,KAA6B;AACtD,QAAM,SAAS,IAAI;AACnB,OACG,IAAI,QAAQ,eACX,IAAI,QAAQ,aACZ,IAAI,QAAQ,gBACd,OAAO,mBAAmB,GAC1B;AACA,WAAO,KAAA;AACP,WAAO;AAAA,EACT;AAEA,OACG,IAAI,QAAQ,gBACX,IAAI,QAAQ,aACZ,IAAI,QAAQ,SACZ,IAAI,QAAQ,WACZ,IAAI,QAAQ,gBACd,OAAO,mBAAmB,IAAI,OAAO,MAAM,QAC3C;AACA,WAAO,KAAA;AACP,WAAO;AAAA,EACT;AAEA,SAAO;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,60 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@macrostrat/data-sheet",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Scalable data sheet with optional editing capabilities",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/UW-Macrostrat/web-components.git",
|
|
8
|
+
"directory": "packages/data-sheet"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": "Daven Quinn",
|
|
5
12
|
"type": "module",
|
|
6
13
|
"source": "src/index.ts",
|
|
7
|
-
"main": "dist/
|
|
8
|
-
"
|
|
9
|
-
"
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"node": "dist/index.cjs",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"style": "dist/data-sheet.css",
|
|
18
|
+
"files": [
|
|
19
|
+
"src",
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"sideEffects": [
|
|
23
|
+
"**/*.css"
|
|
24
|
+
],
|
|
10
25
|
"exports": {
|
|
11
26
|
".": {
|
|
12
27
|
"source": "./src/index.ts",
|
|
13
|
-
"import": "./dist/
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"node": ">=14"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"require": "./dist/index.cjs",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"style": "./dist/data-sheet.css"
|
|
32
|
+
},
|
|
33
|
+
"./package.json": "./package.json",
|
|
34
|
+
"./style.css": "./dist/data-sheet.css",
|
|
35
|
+
"./dist/data-sheet.css": "./dist/data-sheet.css"
|
|
24
36
|
},
|
|
25
37
|
"scripts": {
|
|
26
|
-
"build": "
|
|
38
|
+
"build": "bundle-library ."
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": "^18.0.0||^19.0.0"
|
|
27
42
|
},
|
|
28
|
-
"author": "Daven Quinn",
|
|
29
|
-
"license": "ISC",
|
|
30
43
|
"dependencies": {
|
|
31
|
-
"@blueprintjs/core": "^
|
|
32
|
-
"@blueprintjs/table": "^
|
|
33
|
-
"@macrostrat/color-utils": "^1.
|
|
34
|
-
"@macrostrat/data-components": "^0.
|
|
44
|
+
"@blueprintjs/core": "^6.6.1",
|
|
45
|
+
"@blueprintjs/table": "^6.0.13",
|
|
46
|
+
"@macrostrat/color-utils": "^1.2.0",
|
|
47
|
+
"@macrostrat/data-components": "^1.0.0",
|
|
35
48
|
"@macrostrat/hyper": "^3.0.6",
|
|
36
|
-
"@macrostrat/ui-components": "^
|
|
49
|
+
"@macrostrat/ui-components": "^5.0.3",
|
|
37
50
|
"@supabase/postgrest-js": "^1.17.7",
|
|
38
|
-
"@
|
|
39
|
-
"
|
|
40
|
-
"
|
|
51
|
+
"@types/underscore": "^1.13.0",
|
|
52
|
+
"@uiw/react-color": "^2.9.2",
|
|
53
|
+
"chroma-js": "^3.2.0",
|
|
54
|
+
"classnames": "^2.5.1",
|
|
41
55
|
"immutability-helper": "^3.1.1",
|
|
42
|
-
"react": "^17.0.2||^18 ||^19",
|
|
43
56
|
"underscore": "^1.13.7",
|
|
44
57
|
"zustand": "^5.0.2",
|
|
45
58
|
"zustand-computed": "^2.1.0"
|
|
46
59
|
},
|
|
47
|
-
"files": [
|
|
48
|
-
"src",
|
|
49
|
-
"dist"
|
|
50
|
-
],
|
|
51
|
-
"repository": {
|
|
52
|
-
"type": "git",
|
|
53
|
-
"url": "https://github.com/UW-Macrostrat/web-components.git",
|
|
54
|
-
"directory": "packages/data-sheet"
|
|
55
|
-
},
|
|
56
60
|
"devDependencies": {
|
|
57
|
-
"@
|
|
58
|
-
|
|
61
|
+
"@macrostrat/web-components-bundler": "1.0.0"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
59
65
|
}
|
|
60
66
|
}
|
package/src/components/colors.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "@macrostrat/color-utils";
|
|
9
9
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
10
10
|
import { memoize } from "underscore";
|
|
11
|
-
import Sketch from "@uiw/react-color
|
|
11
|
+
import { Sketch } from "@uiw/react-color";
|
|
12
12
|
import classNames from "classnames";
|
|
13
13
|
|
|
14
14
|
const h = hyper.styled(styles);
|
|
@@ -23,7 +23,7 @@ export function EditorPopup(props) {
|
|
|
23
23
|
const ref = useRef(null);
|
|
24
24
|
|
|
25
25
|
const inlineEditor = h([
|
|
26
|
-
h("span.editor-value.
|
|
26
|
+
h("span.editor-value.bp6-table-cell", valueViewer),
|
|
27
27
|
h("input.hidden-editor", {
|
|
28
28
|
value: "",
|
|
29
29
|
autoFocus: true,
|
|
@@ -67,7 +67,7 @@ export function EditorPopup(props) {
|
|
|
67
67
|
usePortal: true,
|
|
68
68
|
},
|
|
69
69
|
h(
|
|
70
|
-
"span.editor-popup-target.
|
|
70
|
+
"span.editor-popup-target.bp6-table-cell",
|
|
71
71
|
{
|
|
72
72
|
className: targetClassName,
|
|
73
73
|
onClick: () => setIsOpen(!isOpen),
|
package/src/core.ts
CHANGED
|
@@ -5,13 +5,7 @@ import {
|
|
|
5
5
|
InputGroup,
|
|
6
6
|
Intent,
|
|
7
7
|
} from "@blueprintjs/core";
|
|
8
|
-
import {
|
|
9
|
-
Cell,
|
|
10
|
-
Column,
|
|
11
|
-
Region,
|
|
12
|
-
RowHeaderCell,
|
|
13
|
-
Table2,
|
|
14
|
-
} from "@blueprintjs/table";
|
|
8
|
+
import { Cell, Column, Region, RowHeaderCell, Table } from "@blueprintjs/table";
|
|
15
9
|
import "@blueprintjs/table/lib/css/table.css";
|
|
16
10
|
import hyper from "@macrostrat/hyper";
|
|
17
11
|
import update from "immutability-helper";
|
|
@@ -270,7 +264,7 @@ function _DataSheet<T>({
|
|
|
270
264
|
{ onKeyDown },
|
|
271
265
|
h(
|
|
272
266
|
// @ts-expect-error
|
|
273
|
-
|
|
267
|
+
Table,
|
|
274
268
|
{
|
|
275
269
|
ref,
|
|
276
270
|
numRows,
|
package/src/main.module.sass
CHANGED
|
@@ -6,18 +6,18 @@
|
|
|
6
6
|
line-height: var(--data-sheet-row-height, 20px)
|
|
7
7
|
|
|
8
8
|
:global
|
|
9
|
-
.
|
|
10
|
-
&:not([class*="
|
|
9
|
+
.bp6-table-cell
|
|
10
|
+
&:not([class*="bp6-intent-"]):not(.bp6-loading)
|
|
11
11
|
color: var(--text-color)
|
|
12
12
|
|
|
13
|
-
.
|
|
13
|
+
.bp6-table-cell, .bp6-table-row-name
|
|
14
14
|
font-size: var(--data-sheet-font-size)
|
|
15
15
|
line-height: var(--data-sheet-row-height)
|
|
16
16
|
|
|
17
|
-
.
|
|
17
|
+
.bp6-table-row-name
|
|
18
18
|
color: var(--secondary-color)
|
|
19
19
|
|
|
20
|
-
.
|
|
20
|
+
.bp6-table-column-name
|
|
21
21
|
font-size: 1.2em
|
|
22
22
|
|
|
23
23
|
.data-sheet-container
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
.data-sheet
|
|
32
32
|
height: 100%
|
|
33
|
-
:global(.
|
|
33
|
+
:global(.bp6-table-quadrant)
|
|
34
34
|
background-color: var(--panel-secondary-background-color)
|
|
35
35
|
|
|
36
36
|
.input-cell
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
outline: none
|
|
54
54
|
|
|
55
55
|
// Make sure popover target fills the entire cell
|
|
56
|
-
.editor-cell :global(.
|
|
56
|
+
.editor-cell :global(.bp6-popover-target)
|
|
57
57
|
//pointer-events: none
|
|
58
58
|
position: absolute
|
|
59
59
|
top: 0
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HotkeysProvider, OverlayToaster } from "@blueprintjs/core";
|
|
2
2
|
import hyper from "@macrostrat/hyper";
|
|
3
3
|
import styles from "./main.module.sass";
|
|
4
4
|
import { DataSheet, getRowsToDelete } from "../core"; //getRowsToDelete
|
|
@@ -21,7 +21,7 @@ import type {
|
|
|
21
21
|
GenericFunction,
|
|
22
22
|
GenericTable,
|
|
23
23
|
GenericView,
|
|
24
|
-
} from "@supabase/postgrest-js/dist/cjs/
|
|
24
|
+
} from "@supabase/postgrest-js/dist/cjs/index";
|
|
25
25
|
import { ColorCell } from "../components";
|
|
26
26
|
|
|
27
27
|
const h = hyper.styled(styles);
|
|
@@ -173,7 +173,7 @@ function _PostgRESTTableView<T>({
|
|
|
173
173
|
]);
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
export function notifyOnError(toaster:
|
|
176
|
+
export function notifyOnError(toaster: OverlayToaster, error: any) {
|
|
177
177
|
console.error(error);
|
|
178
178
|
const { message, status, code, details } = error;
|
|
179
179
|
|
|
@@ -192,8 +192,8 @@ export function notifyOnError(toaster: Toaster, error: any) {
|
|
|
192
192
|
|
|
193
193
|
toaster.show({
|
|
194
194
|
message: h([
|
|
195
|
-
h.if(status != null)([h("code.
|
|
196
|
-
h.if(code != null)([h("code.
|
|
195
|
+
h.if(status != null)([h("code.bp6-code", status), " "]),
|
|
196
|
+
h.if(code != null)([h("code.bp6-code", code), " "]),
|
|
197
197
|
message ?? "An error occurred",
|
|
198
198
|
errorDetails,
|
|
199
199
|
]),
|
|
@@ -206,7 +206,7 @@ interface PromiseResult {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
export async function wrapWithErrorHandling<T extends PromiseResult>(
|
|
209
|
-
toaster:
|
|
209
|
+
toaster: OverlayToaster,
|
|
210
210
|
fnPromise: Promise<T>,
|
|
211
211
|
): Promise<T | null> {
|
|
212
212
|
try {
|
package/src/provider.ts
CHANGED
|
@@ -400,7 +400,7 @@ export function useStoreAPI<T>(): StoreApi<DataSheetStore<T>> {
|
|
|
400
400
|
}
|
|
401
401
|
|
|
402
402
|
export function useSelector<T = any, A = any>(
|
|
403
|
-
selector: (state: DataSheetStore<T> &
|
|
403
|
+
selector: (state: DataSheetStore<T> & DataSheetComputedVals) => A,
|
|
404
404
|
): A {
|
|
405
405
|
const store = useStoreAPI<T>();
|
|
406
406
|
return useStore(store, selector);
|