vira 26.5.2 → 26.5.4
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.
|
@@ -95,9 +95,9 @@ export const ViraPopUpTrigger = defineViraElement()({
|
|
|
95
95
|
position: absolute;
|
|
96
96
|
pointer-events: none;
|
|
97
97
|
display: flex;
|
|
98
|
+
box-sizing: border-box;
|
|
98
99
|
flex-direction: column;
|
|
99
100
|
align-items: flex-start;
|
|
100
|
-
overflow: hidden;
|
|
101
101
|
|
|
102
102
|
/* highest possible z-index */
|
|
103
103
|
z-index: 2147483647;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { type ArrayElement, type PartialWithUndefined } from '@augment-vir/common';
|
|
2
|
+
import { type HtmlInterpolation } from 'element-vir';
|
|
3
|
+
/**
|
|
4
|
+
* An individual key definition in {@link ViraTableHeaders}.
|
|
5
|
+
*
|
|
6
|
+
* @category Internal
|
|
7
|
+
*/
|
|
8
|
+
export type ViraTableKey = Readonly<{
|
|
9
|
+
/** The key that cells must set a value to. */
|
|
10
|
+
key: string | number;
|
|
11
|
+
} & PartialWithUndefined<{
|
|
12
|
+
/** If this is not provided, `key` will be used directly. */
|
|
13
|
+
content: HtmlInterpolation;
|
|
14
|
+
}>>;
|
|
15
|
+
/**
|
|
16
|
+
* All header definitions for a {@link ViraTable} instance.
|
|
17
|
+
*
|
|
18
|
+
* @category Internal
|
|
19
|
+
*/
|
|
20
|
+
export type ViraTableHeaders = ReadonlyArray<ViraTableKey>;
|
|
21
|
+
/**
|
|
22
|
+
* An individual entry in {@link ViraTable}. In default table orientation, this will be a row. In
|
|
23
|
+
* horizontal orientation, this will be a column.
|
|
24
|
+
*
|
|
25
|
+
* @category Internal
|
|
26
|
+
*/
|
|
27
|
+
export type ViraTableEntry<Headers extends ViraTableHeaders | undefined = undefined> = Record<HeaderKey<Headers>, HtmlInterpolation>;
|
|
28
|
+
/**
|
|
29
|
+
* An individual cell in {@link ViraTableRow}.
|
|
30
|
+
*
|
|
31
|
+
* @category Internal
|
|
32
|
+
*/
|
|
33
|
+
export type ViraTableCell<Headers extends ViraTableHeaders | undefined = undefined, CellData = any> = {
|
|
34
|
+
content: HtmlInterpolation;
|
|
35
|
+
key: HeaderKey<Headers>;
|
|
36
|
+
/**
|
|
37
|
+
* The original entry that created this row (in default or vertical table orientation) or column
|
|
38
|
+
* (in horizontal table orientation). This is `undefined` in header cells.
|
|
39
|
+
*/
|
|
40
|
+
data: CellData;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* An individual row in {@link ViraTable}.
|
|
44
|
+
*
|
|
45
|
+
* @category Internal
|
|
46
|
+
*/
|
|
47
|
+
export type ViraTableRow<Headers extends ViraTableHeaders | undefined = undefined, CellData = any, RowData = CellData> = {
|
|
48
|
+
cells: ViraTableCell<Headers, CellData>[];
|
|
49
|
+
data: RowData;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* All keys for the given headers.
|
|
53
|
+
*
|
|
54
|
+
* @category Internal
|
|
55
|
+
*/
|
|
56
|
+
export type HeaderKey<Headers extends ViraTableHeaders | undefined = undefined> = undefined extends Headers ? string | number : ArrayElement<Exclude<Headers, undefined>>['key'];
|
|
57
|
+
/**
|
|
58
|
+
* Table information that can easily be mapped into a `<table>` element.
|
|
59
|
+
*
|
|
60
|
+
* @category Internal
|
|
61
|
+
*/
|
|
62
|
+
export type ViraTable<Headers extends ViraTableHeaders | undefined = undefined, Orientation extends ViraTableOrientation = ViraTableOrientation.Vertical, OriginalData extends ReadonlyArray<any> = any[]> = Orientation extends ViraTableOrientation.Horizontal ? {
|
|
63
|
+
headerRow: undefined;
|
|
64
|
+
orientation: Orientation;
|
|
65
|
+
rows: ViraTableRow<Headers, ArrayElement<OriginalData> | undefined, undefined>[];
|
|
66
|
+
} : {
|
|
67
|
+
headerRow: ViraTableCell<Headers, undefined>[];
|
|
68
|
+
orientation: Orientation;
|
|
69
|
+
rows: ViraTableRow<Headers, ArrayElement<OriginalData>>[];
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Orientation options for {@link ViraTable}.
|
|
73
|
+
*
|
|
74
|
+
* @category Internal
|
|
75
|
+
*/
|
|
76
|
+
export declare enum ViraTableOrientation {
|
|
77
|
+
/**
|
|
78
|
+
* This corresponds to a _vertical_ entry sequence (as you move from entry to entry, you move
|
|
79
|
+
* across the table vertically). This is the default table layout. Each entry becomes a new row.
|
|
80
|
+
* Headers are in a separate row.
|
|
81
|
+
*/
|
|
82
|
+
Vertical = "vertical",
|
|
83
|
+
/**
|
|
84
|
+
* This corresponds to a _horizontal_ entry sequence (as you move from entry to entry, you move
|
|
85
|
+
* across the table horizontally). Each entry becomes a column. Headers are the left most
|
|
86
|
+
* column.
|
|
87
|
+
*/
|
|
88
|
+
Horizontal = "horizontal"
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Options for {@link defineTable}.
|
|
92
|
+
*
|
|
93
|
+
* @category Internal
|
|
94
|
+
*/
|
|
95
|
+
export type ViraTableOptions<Orientation extends ViraTableOrientation = ViraTableOrientation> = PartialWithUndefined<{
|
|
96
|
+
orientation: Orientation;
|
|
97
|
+
hideHeaders: boolean;
|
|
98
|
+
}>;
|
|
99
|
+
/**
|
|
100
|
+
* Accepts headers and entries and lays them out into rows according to the given
|
|
101
|
+
* `options.orientation` (defaulting to vertical). This does not itself create a `<table>` element,
|
|
102
|
+
* but makes it easy to loop over rows to (with `.map()`) to generate rows in a table.
|
|
103
|
+
*
|
|
104
|
+
* @category Table
|
|
105
|
+
*/
|
|
106
|
+
export declare function defineTable<const Headers extends ViraTableHeaders, OriginalData extends ReadonlyArray<any>, const Orientation extends ViraTableOrientation = ViraTableOrientation.Vertical>(
|
|
107
|
+
/** The order of these keys determines the order that they render in. */
|
|
108
|
+
headers: Readonly<Headers>, originalData: OriginalData, dataMap: (entry: ArrayElement<OriginalData>) => ViraTableEntry<Headers> | undefined, options?: ViraTableOptions<Orientation>): ViraTable<Headers, Orientation, OriginalData>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { filterMap } from '@augment-vir/common';
|
|
3
|
+
/**
|
|
4
|
+
* Orientation options for {@link ViraTable}.
|
|
5
|
+
*
|
|
6
|
+
* @category Internal
|
|
7
|
+
*/
|
|
8
|
+
export var ViraTableOrientation;
|
|
9
|
+
(function (ViraTableOrientation) {
|
|
10
|
+
/**
|
|
11
|
+
* This corresponds to a _vertical_ entry sequence (as you move from entry to entry, you move
|
|
12
|
+
* across the table vertically). This is the default table layout. Each entry becomes a new row.
|
|
13
|
+
* Headers are in a separate row.
|
|
14
|
+
*/
|
|
15
|
+
ViraTableOrientation["Vertical"] = "vertical";
|
|
16
|
+
/**
|
|
17
|
+
* This corresponds to a _horizontal_ entry sequence (as you move from entry to entry, you move
|
|
18
|
+
* across the table horizontally). Each entry becomes a column. Headers are the left most
|
|
19
|
+
* column.
|
|
20
|
+
*/
|
|
21
|
+
ViraTableOrientation["Horizontal"] = "horizontal";
|
|
22
|
+
})(ViraTableOrientation || (ViraTableOrientation = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Accepts headers and entries and lays them out into rows according to the given
|
|
25
|
+
* `options.orientation` (defaulting to vertical). This does not itself create a `<table>` element,
|
|
26
|
+
* but makes it easy to loop over rows to (with `.map()`) to generate rows in a table.
|
|
27
|
+
*
|
|
28
|
+
* @category Table
|
|
29
|
+
*/
|
|
30
|
+
export function defineTable(
|
|
31
|
+
/** The order of these keys determines the order that they render in. */
|
|
32
|
+
headers, originalData, dataMap, options = {}) {
|
|
33
|
+
const mappedData = originalData.map((dataRow) => {
|
|
34
|
+
return {
|
|
35
|
+
cells: dataMap(dataRow),
|
|
36
|
+
data: dataRow,
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
if (options.orientation === ViraTableOrientation.Horizontal) {
|
|
40
|
+
const rows = headers.map((header) => {
|
|
41
|
+
const headerCellArray = options.hideHeaders
|
|
42
|
+
? []
|
|
43
|
+
: [
|
|
44
|
+
{
|
|
45
|
+
content: header.content ?? header.key,
|
|
46
|
+
key: header.key,
|
|
47
|
+
data: undefined,
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
const cells = filterMap(mappedData, ({ data, cells, }) => {
|
|
51
|
+
if (!cells) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
content: cells[header.key],
|
|
56
|
+
key: header.key,
|
|
57
|
+
data,
|
|
58
|
+
};
|
|
59
|
+
}, check.isTruthy);
|
|
60
|
+
const allCells = [
|
|
61
|
+
...headerCellArray,
|
|
62
|
+
...cells,
|
|
63
|
+
];
|
|
64
|
+
return {
|
|
65
|
+
cells: allCells,
|
|
66
|
+
data: undefined,
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
headerRow: undefined,
|
|
71
|
+
rows,
|
|
72
|
+
orientation: ViraTableOrientation.Horizontal,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const headerRow = options.hideHeaders
|
|
77
|
+
? []
|
|
78
|
+
: headers.map((header) => {
|
|
79
|
+
return {
|
|
80
|
+
content: header.content ?? header.key,
|
|
81
|
+
key: header.key,
|
|
82
|
+
data: undefined,
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
const rows = filterMap(mappedData, ({ cells, data }) => {
|
|
86
|
+
if (!cells) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
cells: headers.map((header) => {
|
|
91
|
+
return {
|
|
92
|
+
content: cells[header.key],
|
|
93
|
+
key: header.key,
|
|
94
|
+
data,
|
|
95
|
+
};
|
|
96
|
+
}),
|
|
97
|
+
data,
|
|
98
|
+
};
|
|
99
|
+
}, check.isTruthy);
|
|
100
|
+
return {
|
|
101
|
+
headerRow,
|
|
102
|
+
rows,
|
|
103
|
+
orientation: ViraTableOrientation.Vertical,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -155,8 +155,8 @@ export class PopUpManager {
|
|
|
155
155
|
? {
|
|
156
156
|
top: 0,
|
|
157
157
|
left: 0,
|
|
158
|
-
right:
|
|
159
|
-
bottom:
|
|
158
|
+
right: containerRect.width,
|
|
159
|
+
bottom: containerRect.height,
|
|
160
160
|
}
|
|
161
161
|
: {
|
|
162
162
|
top: containerRect.top,
|
|
@@ -170,13 +170,7 @@ export class PopUpManager {
|
|
|
170
170
|
const diff = mapObjectValues(emptyPositionRect, (key) => {
|
|
171
171
|
const containerDimension = containerPosition[key];
|
|
172
172
|
const hostDimension = rootPosition[key];
|
|
173
|
-
|
|
174
|
-
* Chrome will trigger a scroll bar sometimes if the PopUp is too close to the bottom,
|
|
175
|
-
* even if clearly isn't overflowing. The value here was found by experimentation to be
|
|
176
|
-
* the lowest value that wouldn't trigger that.
|
|
177
|
-
*/
|
|
178
|
-
const additionalOffset = key === 'bottom' ? -51 : 0;
|
|
179
|
-
return Math.abs(containerDimension - hostDimension + additionalOffset);
|
|
173
|
+
return Math.abs(containerDimension - hostDimension);
|
|
180
174
|
});
|
|
181
175
|
const useUp = diff.top > diff.bottom + currentOptions.verticalDiffThreshold &&
|
|
182
176
|
diff.bottom < currentOptions.minDownSpace;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vira",
|
|
3
|
-
"version": "26.5.
|
|
3
|
+
"version": "26.5.4",
|
|
4
4
|
"description": "A simple and highly versatile design system using element-vir.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"design",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"vite-tsconfig-paths": "^5.1.4"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"element-vir": "^26.5.
|
|
70
|
+
"element-vir": "^26.5.4"
|
|
71
71
|
},
|
|
72
72
|
"engines": {
|
|
73
73
|
"node": ">=22"
|