@dxos/lit-grid 0.6.12-main.5cc132e → 0.6.12-main.78ddbdf
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/dist/lib/browser/index.mjs +406 -143
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/dx-grid-axis-resize-handle.d.ts +15 -0
- package/dist/types/src/dx-grid-axis-resize-handle.d.ts.map +1 -0
- package/dist/types/src/dx-grid.d.ts +55 -39
- package/dist/types/src/dx-grid.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +38 -4
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +7 -0
- package/dist/types/src/util.d.ts.map +1 -0
- package/package.json +2 -1
- package/src/dx-grid-axis-resize-handle.ts +83 -0
- package/src/dx-grid.lit-stories.ts +2 -2
- package/src/dx-grid.pcss +32 -12
- package/src/dx-grid.ts +278 -138
- package/src/types.ts +50 -4
- package/src/util.ts +12 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
6
|
+
import { disableNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/disable-native-drag-preview';
|
|
7
|
+
import { preventUnhandled } from '@atlaskit/pragmatic-drag-and-drop/prevent-unhandled';
|
|
8
|
+
import { type CleanupFn, type DragLocationHistory } from '@atlaskit/pragmatic-drag-and-drop/types';
|
|
9
|
+
import { html, LitElement } from 'lit';
|
|
10
|
+
import { customElement, property } from 'lit/decorators.js';
|
|
11
|
+
import { ref } from 'lit/directives/ref.js';
|
|
12
|
+
|
|
13
|
+
import { DxAxisResizeInternal, type DxGridAxis } from './types';
|
|
14
|
+
|
|
15
|
+
@customElement('dx-grid-axis-resize-handle')
|
|
16
|
+
export class DxGridAxisResizeHandle extends LitElement {
|
|
17
|
+
@property({ type: String })
|
|
18
|
+
axis: DxGridAxis = 'row';
|
|
19
|
+
|
|
20
|
+
@property({ type: String })
|
|
21
|
+
index: string = '-1';
|
|
22
|
+
|
|
23
|
+
@property({ type: Number })
|
|
24
|
+
size: number = 128;
|
|
25
|
+
|
|
26
|
+
private dragStartSize: number = 128;
|
|
27
|
+
|
|
28
|
+
override render() {
|
|
29
|
+
return html`<button class="dx-grid__resize-handle" ${ref(this.mount)}>
|
|
30
|
+
<span class="sr-only">Resize</span>
|
|
31
|
+
</button>`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private cleanup: CleanupFn | null = null;
|
|
35
|
+
|
|
36
|
+
private dispatchResize(location: DragLocationHistory, state: 'dragging' | 'dropped') {
|
|
37
|
+
const client = this.axis === 'row' ? 'clientY' : 'clientX';
|
|
38
|
+
const event = new DxAxisResizeInternal({
|
|
39
|
+
axis: this.axis,
|
|
40
|
+
size: this.dragStartSize,
|
|
41
|
+
index: this.index,
|
|
42
|
+
delta: location.current.input[client] - location.initial.input[client],
|
|
43
|
+
state,
|
|
44
|
+
});
|
|
45
|
+
this.dispatchEvent(event);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private mount(element?: Element) {
|
|
49
|
+
this.cleanup?.();
|
|
50
|
+
const host = this;
|
|
51
|
+
if (element) {
|
|
52
|
+
this.cleanup = draggable({
|
|
53
|
+
element: element as HTMLButtonElement,
|
|
54
|
+
onGenerateDragPreview: ({ nativeSetDragImage }) => {
|
|
55
|
+
// we will be moving the line to indicate a drag
|
|
56
|
+
// we can disable the native drag preview
|
|
57
|
+
disableNativeDragPreview({ nativeSetDragImage });
|
|
58
|
+
// we don't want any native drop animation for when the user
|
|
59
|
+
// does not drop on a drop target. we want the drag to finish immediately
|
|
60
|
+
preventUnhandled.start();
|
|
61
|
+
},
|
|
62
|
+
onDragStart() {
|
|
63
|
+
host.dragStartSize = host.size;
|
|
64
|
+
},
|
|
65
|
+
onDrag({ location }) {
|
|
66
|
+
host.dispatchResize(location, 'dragging');
|
|
67
|
+
},
|
|
68
|
+
onDrop({ location }) {
|
|
69
|
+
host.dispatchResize(location, 'dropped');
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
override disconnectedCallback() {
|
|
76
|
+
super.disconnectedCallback();
|
|
77
|
+
this.cleanup?.();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
override createRenderRoot() {
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -17,7 +17,7 @@ export default {
|
|
|
17
17
|
export const Basic = (props: DxGridProps) => {
|
|
18
18
|
return html`<div style="position:fixed;inset:0;">
|
|
19
19
|
<dx-grid
|
|
20
|
-
cells=${props.
|
|
20
|
+
cells=${props.initialCells ?? nothing}
|
|
21
21
|
columnDefault=${props.columnDefault ?? nothing}
|
|
22
22
|
rowDefault=${props.rowDefault ?? nothing}
|
|
23
23
|
columns=${props.columns ?? nothing}
|
|
@@ -31,7 +31,7 @@ Basic.args = {
|
|
|
31
31
|
// end: '8,1',
|
|
32
32
|
value: 'Weekly sales report',
|
|
33
33
|
},
|
|
34
|
-
} satisfies DxGridProps['
|
|
34
|
+
} satisfies DxGridProps['initialCells']),
|
|
35
35
|
columnDefault: JSON.stringify({
|
|
36
36
|
size: 180,
|
|
37
37
|
resizeable: true,
|
package/src/dx-grid.pcss
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
dx-grid {
|
|
1
|
+
dx-grid, dx-grid-axis-resize-handle {
|
|
2
2
|
display: contents;
|
|
3
3
|
}
|
|
4
4
|
|
|
@@ -27,6 +27,8 @@ dx-grid {
|
|
|
27
27
|
block-size: 100%;
|
|
28
28
|
max-inline-size: 100dvw;
|
|
29
29
|
max-block-size: 100dvh;
|
|
30
|
+
|
|
31
|
+
user-select: none;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
.dx-grid__scrollbar__thumb {
|
|
@@ -84,10 +86,13 @@ dx-grid {
|
|
|
84
86
|
box-sizing: border-box;
|
|
85
87
|
cursor: pointer;
|
|
86
88
|
border: 1px solid transparent;
|
|
89
|
+
overflow: hidden;
|
|
90
|
+
text-overflow: ellipsis;
|
|
91
|
+
white-space: nowrap;
|
|
87
92
|
&[inert] {
|
|
88
93
|
visibility: hidden;
|
|
89
94
|
}
|
|
90
|
-
&:focus, &:focus-visible {
|
|
95
|
+
&:focus, &:focus-visible, &.dx-grid__cell--active {
|
|
91
96
|
cursor: text;
|
|
92
97
|
position: relative;
|
|
93
98
|
z-index: 2;
|
|
@@ -95,32 +100,47 @@ dx-grid {
|
|
|
95
100
|
outline: none;
|
|
96
101
|
}
|
|
97
102
|
}
|
|
103
|
+
&[data-grid-mode="edit"] {
|
|
104
|
+
[role='gridcell'], [role='columnheader'], [role='rowheader'] {
|
|
105
|
+
&.dx-grid__cell--active {
|
|
106
|
+
color: transparent !important;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
&[data-grid-select] {
|
|
111
|
+
[role='gridcell'], [role='columnheader'], [role='rowheader'] {
|
|
112
|
+
&[aria-selected] {
|
|
113
|
+
background: var(--dx-gridSelectionOverlay);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
98
117
|
}
|
|
99
118
|
|
|
100
119
|
.dx-grid__columnheader__content,
|
|
101
120
|
.dx-grid__rowheader__content {
|
|
102
121
|
& > [role='columnheader'], &> [role='rowheader'] {
|
|
103
122
|
position: relative;
|
|
104
|
-
& > button.dx-grid__resize-handle {
|
|
105
|
-
position: absolute;
|
|
106
|
-
background: transparent;
|
|
107
|
-
&:hover {
|
|
108
|
-
background: var(--dx-grid-resizeHandleHover, var(--dx-hoverSurface));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
123
|
}
|
|
112
124
|
}
|
|
113
125
|
|
|
114
|
-
.dx-
|
|
126
|
+
.dx-grid__resize-handle {
|
|
127
|
+
position: absolute;
|
|
128
|
+
background: transparent;
|
|
129
|
+
&:hover {
|
|
130
|
+
background: var(--dx-grid-resizeHandleHover, var(--dx-hoverSurface));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.dx-grid__columnheader__content > [role='columnheader'] .dx-grid__resize-handle {
|
|
115
135
|
inset-block: 0;
|
|
116
136
|
inset-inline-end: 0;
|
|
117
137
|
inline-size: .5rem;
|
|
118
138
|
cursor: col-resize;
|
|
119
139
|
}
|
|
120
140
|
|
|
121
|
-
.dx-grid__rowheader__content > [role='rowheader']
|
|
141
|
+
.dx-grid__rowheader__content > [role='rowheader'] .dx-grid__resize-handle {
|
|
122
142
|
inset-inline: 0;
|
|
123
143
|
inset-block-end: 0;
|
|
124
144
|
block-size: .5rem;
|
|
125
145
|
cursor: row-resize;
|
|
126
|
-
}
|
|
146
|
+
}
|