@3mo/data-grid 0.26.4 → 0.27.0

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.
@@ -50,250 +50,252 @@ export class DataGridRow extends Component {
50
50
  return this.dataGrid.detailsController.hasDetail(this.dataRecord);
51
51
  }
52
52
  static get styles() {
53
- return css `
54
- :host {
55
- display: block;
56
- position: relative;
57
- height: auto;
58
- width: 100%;
59
- }
60
-
61
- :host([data-reorderability=${unsafeCSS(ReorderabilityState.Dragging)}]) {
62
- opacity: 0.5;
63
- }
64
-
65
- :host([data-reorderability=${unsafeCSS(ReorderabilityState.DropBefore)}]) {
66
- border-top: 2px solid var(--mo-color-accent);
67
- }
68
-
69
- :host([data-reorderability=${unsafeCSS(ReorderabilityState.DropAfter)}]) {
70
- border-bottom: 2px solid var(--mo-color-accent);
71
- }
72
-
73
- #reorderability {
74
- position: sticky;
75
- z-index: 2;
76
- width: var(--mo-data-grid-column-reorder-width);
77
- height: 100%;
78
- background: var(--mo-data-grid-sticky-part-color);
79
-
80
- mo-icon-button {
81
- cursor: grab;
82
- opacity: 0.5;
83
- }
84
- }
85
-
86
- #detailsExpanderContainer {
87
- position: sticky;
88
- z-index: 2;
89
- inset-inline-start: 0px;
90
- background: var(--mo-data-grid-sticky-expander-part-color, var(--mo-data-grid-sticky-part-color));
91
- }
92
-
93
- #selectionContainer {
94
- width: var(--mo-data-grid-column-selection-width);
95
- position: sticky;
96
- z-index: 2;
97
- height: 100%;
98
- background: var(--mo-data-grid-sticky-part-color);
99
- }
100
-
101
- :host(:hover) {
102
- #contentContainer {
103
- --mo-data-grid-sticky-part-color: color-mix(in srgb, var(--mo-color-surface), var(--mo-color-accent) 25%) !important;
104
- color: inherit;
105
- background: var(--mo-color-accent-transparent) !important;
106
- }
107
-
108
- #contentContainer, #detailsContainer {
109
- &::before {
110
- content: '';
111
- width: 2px;
112
- height: 100%;
113
- top: 0;
114
- position: absolute;
115
- background-color: var(--mo-color-accent);
116
- z-index: 2;
117
- }
118
- }
119
- }
120
-
121
- :host([data-has-alternating-background]) {
122
- #contentContainer, #detailsContainer:not(:has([instanceof*=mo-data-grid])) {
123
- background: var(--mo-data-grid-alternating-background);
124
- --mo-data-grid-sticky-part-color: color-mix(in srgb, var(--mo-color-surface), black var(--mo-data-grid-alternating-background-transparency));
125
- }
126
- }
127
-
128
- #contentContainer {
129
- grid-column: -1 / 1;
130
- }
131
-
132
- #contextMenuIconButtonContainer {
133
- height: 100%;
134
- place-self: end;
135
- position: sticky;
136
- inset-inline-end: 0px;
137
- z-index: 3;
138
- background: var(--mo-data-grid-sticky-part-color);
139
- }
140
-
141
- #contextMenuIconButton {
142
- opacity: 0.5;
143
- color: var(--mo-color-gray);
144
- }
145
-
146
- :host([selected]), :host([data-context-menu-open]) {
147
- #contentContainer {
148
- --mo-data-grid-sticky-part-color: color-mix(in srgb, var(--mo-color-surface), var(--mo-color-accent)) !important;
149
- background: var(--mo-data-grid-selection-background) !important;
150
- }
151
-
152
- #contextMenuIconButton {
153
- color: currentColor;
154
- opacity: 1;
155
- }
156
- }
157
-
158
- #contentContainer:hover #contextMenuIconButton {
159
- color: currentColor;
160
- opacity: 1;
161
- }
162
-
163
- #detailsExpanderIconButton {
164
- transition: transform 250ms;
165
-
166
- &[data-rtl] {
167
- transform: rotate(180deg);
168
- }
169
- }
170
-
171
- :host([detailsOpen]) #detailsExpanderIconButton {
172
- transform: rotate(90deg);
173
- }
174
-
175
- #detailsContainer {
176
- display: grid;
177
- grid-template-columns: subgrid;
178
- grid-column: -1 / 1;
179
-
180
- &:empty {
181
- display: none;
182
- }
183
-
184
- & > * {
185
- grid-column: data / -1;
186
- box-sizing: border-box;
187
- padding-inline: var(--mo-data-grid-cell-padding);
188
- padding-block: 1rem;
189
-
190
- &[mo-data-grid-row] {
191
- grid-column: -1 / 1;
192
- padding: 0;
193
- }
194
-
195
- &[instanceof*=mo-data-grid] {
196
- padding-inline: 0;
197
- --mo-data-grid-header-background: color-mix(in srgb, var(--mo-color-foreground), transparent 96%);
198
- --mo-data-grid-alternating-background: transparent;
199
- --mo-data-grid-alternating-background-transparency: 0;
200
- --_content-min-height-default: 0px;
201
-
202
- &::part(row) {
203
- border-block-end: var(--mo-data-grid-border);
204
- }
205
- }
206
- }
207
- }
208
-
209
- mo-data-grid-cell:first-of-type:not([alignment=end]), mo-data-grid-cell[alignment=end]:first-of-type + mo-data-grid-cell {
210
- margin-inline-start: calc(var(--_level, 0) * var(--mo-data-grid-column-sub-row-indentation, 20px));
211
- }
53
+ return css `
54
+ :host {
55
+ display: block;
56
+ position: relative;
57
+ height: auto;
58
+ width: 100%;
59
+ }
60
+
61
+ :host([data-reorderability=${unsafeCSS(ReorderabilityState.Dragging)}]) {
62
+ opacity: 0.5;
63
+ }
64
+
65
+ :host([data-reorderability=${unsafeCSS(ReorderabilityState.DropBefore)}]) {
66
+ border-top: 2px solid var(--mo-color-accent);
67
+ }
68
+
69
+ :host([data-reorderability=${unsafeCSS(ReorderabilityState.DropAfter)}]) {
70
+ border-bottom: 2px solid var(--mo-color-accent);
71
+ }
72
+
73
+ #reorderability {
74
+ position: sticky;
75
+ z-index: 2;
76
+ width: var(--mo-data-grid-column-reorder-width);
77
+ height: 100%;
78
+ background: var(--mo-data-grid-sticky-part-color);
79
+
80
+ mo-icon-button {
81
+ cursor: grab;
82
+ opacity: 0.5;
83
+ }
84
+ }
85
+
86
+ #detailsExpanderContainer {
87
+ position: sticky;
88
+ z-index: 2;
89
+ inset-inline-start: 0px;
90
+ background: var(--mo-data-grid-sticky-expander-part-color, var(--mo-data-grid-sticky-part-color));
91
+ }
92
+
93
+ #selectionContainer {
94
+ width: var(--mo-data-grid-column-selection-width);
95
+ position: sticky;
96
+ z-index: 2;
97
+ height: 100%;
98
+ background: var(--mo-data-grid-sticky-part-color);
99
+ }
100
+
101
+ :host(:hover) {
102
+ #contentContainer {
103
+ --mo-data-grid-sticky-part-color: color-mix(in srgb, var(--mo-color-surface), var(--mo-color-accent) 25%) !important;
104
+ color: inherit;
105
+ background: var(--mo-color-accent-transparent) !important;
106
+ }
107
+
108
+ #contentContainer, #detailsContainer {
109
+ &::before {
110
+ content: '';
111
+ width: 2px;
112
+ height: 100%;
113
+ top: 0;
114
+ position: absolute;
115
+ background-color: var(--mo-color-accent);
116
+ z-index: 2;
117
+ }
118
+ }
119
+ }
120
+
121
+ :host([data-has-alternating-background]) {
122
+ #contentContainer, #detailsContainer:not(:has([instanceof*=mo-data-grid])) {
123
+ background: var(--mo-data-grid-alternating-background);
124
+ --mo-data-grid-sticky-part-color: light-dark(
125
+ color-mix(in srgb, var(--mo-color-surface), black 5%),
126
+ color-mix(in srgb, var(--mo-color-surface), black 20%)
127
+ );
128
+ }
129
+ }
130
+
131
+ #contentContainer {
132
+ grid-column: -1 / 1;
133
+ }
134
+
135
+ #contextMenuIconButtonContainer {
136
+ height: 100%;
137
+ place-self: end;
138
+ position: sticky;
139
+ inset-inline-end: 0px;
140
+ z-index: 3;
141
+ background: var(--mo-data-grid-sticky-part-color);
142
+ }
143
+
144
+ #contextMenuIconButton {
145
+ opacity: 0.5;
146
+ color: var(--mo-color-gray);
147
+ }
148
+
149
+ :host([selected]), :host([data-context-menu-open]) {
150
+ #contentContainer {
151
+ --mo-data-grid-sticky-part-color: color-mix(in srgb, var(--mo-color-surface), var(--mo-color-accent)) !important;
152
+ background: var(--mo-data-grid-selection-background) !important;
153
+ }
154
+
155
+ #contextMenuIconButton {
156
+ color: currentColor;
157
+ opacity: 1;
158
+ }
159
+ }
160
+
161
+ #contentContainer:hover #contextMenuIconButton {
162
+ color: currentColor;
163
+ opacity: 1;
164
+ }
165
+
166
+ #detailsExpanderIconButton {
167
+ transition: transform 250ms;
168
+
169
+ &[data-rtl] {
170
+ transform: rotate(180deg);
171
+ }
172
+ }
173
+
174
+ :host([detailsOpen]) #detailsExpanderIconButton {
175
+ transform: rotate(90deg);
176
+ }
177
+
178
+ #detailsContainer {
179
+ display: grid;
180
+ grid-template-columns: subgrid;
181
+ grid-column: -1 / 1;
182
+
183
+ &:empty {
184
+ display: none;
185
+ }
186
+
187
+ & > * {
188
+ grid-column: data / -1;
189
+ box-sizing: border-box;
190
+ padding-inline: var(--mo-data-grid-cell-padding);
191
+ padding-block: 1rem;
192
+
193
+ &[mo-data-grid-row] {
194
+ grid-column: -1 / 1;
195
+ padding: 0;
196
+ }
197
+
198
+ &[instanceof*=mo-data-grid] {
199
+ padding-inline: 0;
200
+ --mo-data-grid-header-background: color-mix(in srgb, var(--mo-color-foreground), transparent 96%);
201
+ --mo-data-grid-alternating-background: transparent;
202
+ --_content-min-height-default: 0px;
203
+
204
+ &::part(row) {
205
+ border-block-end: var(--mo-data-grid-border);
206
+ }
207
+ }
208
+ }
209
+ }
210
+
211
+ mo-data-grid-cell:first-of-type:not([alignment=end]), mo-data-grid-cell[alignment=end]:first-of-type + mo-data-grid-cell {
212
+ margin-inline-start: calc(var(--_level, 0) * var(--mo-data-grid-column-sub-row-indentation, 20px));
213
+ }
212
214
  `;
213
215
  }
214
216
  get template() {
215
217
  this.style.setProperty('--_level', this.level.toString());
216
218
  this.toggleAttribute('selected', this.dataRecord.isSelected);
217
219
  this.toggleAttribute('detailsOpen', this.dataRecord.detailsOpen);
218
- return !this.isIntersecting ? html.nothing : html `
219
- <mo-grid id='contentContainer' columns='subgrid'
220
- @click=${() => this.handleContentClick()}
221
- @dblclick=${() => this.handleContentDoubleClick()}
222
- @auxclick=${(e) => e.button !== 1 ? void 0 : this.handleContentMiddleClick()}
223
- ${this.contextMenuTemplate === html.nothing ? html.nothing : popover(() => html `
224
- <mo-context-menu @openChange=${(e) => this.handleContextMenuOpenChange(e.detail)}>
225
- ${this.contextMenuTemplate}
226
- </mo-context-menu>
227
- `)}
228
- >
229
- ${this.rowTemplate}
230
- </mo-grid>
231
- <slot id='detailsContainer'>${this.detailsOpen ? this.detailsTemplate : html.nothing}</slot>
220
+ return !this.isIntersecting ? html.nothing : html `
221
+ <mo-grid id='contentContainer' columns='subgrid'
222
+ @click=${() => this.handleContentClick()}
223
+ @dblclick=${() => this.handleContentDoubleClick()}
224
+ @auxclick=${(e) => e.button !== 1 ? void 0 : this.handleContentMiddleClick()}
225
+ ${this.contextMenuTemplate === html.nothing ? html.nothing : popover(() => html `
226
+ <mo-context-menu @openChange=${(e) => this.handleContextMenuOpenChange(e.detail)}>
227
+ ${this.contextMenuTemplate}
228
+ </mo-context-menu>
229
+ `)}
230
+ >
231
+ ${this.rowTemplate}
232
+ </mo-grid>
233
+ <slot id='detailsContainer'>${this.detailsOpen ? this.detailsTemplate : html.nothing}</slot>
232
234
  `;
233
235
  }
234
236
  get reorderabilityTemplate() {
235
- return !this.dataGrid.reorderabilityController.enabled ? html.nothing : html `
236
- <mo-flex id='reorderability' justifyContent='center' alignItems='center' ${style({ insetInlineStart: this.dataGrid.columnsController.getStickyColumnInsetInline('reordering') })}>
237
- <mo-icon-button icon='drag_handle'></mo-icon-button>
238
- </mo-flex>
237
+ return !this.dataGrid.reorderabilityController.enabled ? html.nothing : html `
238
+ <mo-flex id='reorderability' justifyContent='center' alignItems='center' ${style({ insetInlineStart: this.dataGrid.columnsController.getStickyColumnInsetInline('reordering') })}>
239
+ <mo-icon-button icon='drag_handle'></mo-icon-button>
240
+ </mo-flex>
239
241
  `;
240
242
  }
241
243
  get detailsExpanderTemplate() {
242
- return this.dataGrid.hasDetails === false ? html.nothing : html `
243
- <mo-flex id='detailsExpanderContainer' justifyContent='center' alignItems='center'
244
- ${style({ insetInlineStart: this.dataGrid.columnsController.getStickyColumnInsetInline('details') })}
245
- @click=${(e) => e.stopPropagation()}
246
- @dblclick=${(e) => e.stopPropagation()}
247
- >
248
- ${this.hasDetails === false ? html.nothing : html `
249
- <mo-icon-button id='detailsExpanderIconButton'
250
- icon='keyboard_arrow_right'
251
- ?data-rtl=${DirectionsByLanguage.get() === 'rtl'}
252
- @click=${() => this.toggleDetails()}
253
- ></mo-icon-button>
254
- `}
255
- </mo-flex>
244
+ return this.dataGrid.hasDetails === false ? html.nothing : html `
245
+ <mo-flex id='detailsExpanderContainer' justifyContent='center' alignItems='center'
246
+ ${style({ insetInlineStart: this.dataGrid.columnsController.getStickyColumnInsetInline('details') })}
247
+ @click=${(e) => e.stopPropagation()}
248
+ @dblclick=${(e) => e.stopPropagation()}
249
+ >
250
+ ${this.hasDetails === false ? html.nothing : html `
251
+ <mo-icon-button id='detailsExpanderIconButton'
252
+ icon='keyboard_arrow_right'
253
+ ?data-rtl=${DirectionsByLanguage.get() === 'rtl'}
254
+ @click=${() => this.toggleDetails()}
255
+ ></mo-icon-button>
256
+ `}
257
+ </mo-flex>
256
258
  `;
257
259
  }
258
260
  get selectionTemplate() {
259
- return !this.dataGrid.hasSelection ? html.nothing : html `
260
- <mo-flex id='selectionContainer' justifyContent='center' alignItems='center'
261
- ?data-has-details=${this.dataGrid.hasDetails}
262
- ${style({ insetInlineStart: this.dataGrid.columnsController.getStickyColumnInsetInline('selection') })}
263
- @click=${(e) => e.stopPropagation()}
264
- @dblclick=${(e) => e.stopPropagation()}
265
- >
266
- <mo-checkbox
267
- tabindex='-1'
268
- ?disabled=${this.dataRecord.isSelectable === false}
269
- .selected=${live(this.selected)}
270
- @change=${(e) => this.dataGrid.selectionController.setSelection(this.data, e.detail, true)}
271
- ></mo-checkbox>
272
- </mo-flex>
261
+ return !this.dataGrid.hasSelection ? html.nothing : html `
262
+ <mo-flex id='selectionContainer' justifyContent='center' alignItems='center'
263
+ ?data-has-details=${this.dataGrid.hasDetails}
264
+ ${style({ insetInlineStart: this.dataGrid.columnsController.getStickyColumnInsetInline('selection') })}
265
+ @click=${(e) => e.stopPropagation()}
266
+ @dblclick=${(e) => e.stopPropagation()}
267
+ >
268
+ <mo-checkbox
269
+ tabindex='-1'
270
+ ?disabled=${this.dataRecord.isSelectable === false}
271
+ .selected=${live(this.selected)}
272
+ @change=${(e) => this.dataGrid.selectionController.setSelection(this.data, e.detail, true)}
273
+ ></mo-checkbox>
274
+ </mo-flex>
273
275
  `;
274
276
  }
275
277
  getCellTemplate(column) {
276
- return column.hidden ? html.nothing : html `
277
- <mo-data-grid-cell
278
- .row=${this}
279
- .column=${column}
280
- .value=${KeyPath.get(this.data, column.dataSelector)}
281
- @keydown=${this.delegateToCell('handleKeyDown')}
282
- @dblclick=${this.delegateToCell('handleDoubleClick')}
283
- ></mo-data-grid-cell>
278
+ return column.hidden ? html.nothing : html `
279
+ <mo-data-grid-cell
280
+ .row=${this}
281
+ .column=${column}
282
+ .value=${KeyPath.get(this.data, column.dataSelector)}
283
+ @keydown=${this.delegateToCell('handleKeyDown')}
284
+ @dblclick=${this.delegateToCell('handleDoubleClick')}
285
+ ></mo-data-grid-cell>
284
286
  `;
285
287
  }
286
288
  get fillerTemplate() {
287
289
  return html `<span></span>`;
288
290
  }
289
291
  get contextMenuIconButtonTemplate() {
290
- return this.dataGrid.hasContextMenu === false ? html.nothing : html `
291
- <mo-flex id='contextMenuIconButtonContainer' justifyContent='center'>
292
- <mo-icon-button id='contextMenuIconButton' icon='more_vert' dense
293
- @click=${this.openContextMenu}
294
- @dblclick=${(e) => e.stopPropagation()}
295
- ></mo-icon-button>
296
- </mo-flex>
292
+ return this.dataGrid.hasContextMenu === false ? html.nothing : html `
293
+ <mo-flex id='contextMenuIconButtonContainer' justifyContent='center'>
294
+ <mo-icon-button id='contextMenuIconButton' icon='more_vert' dense
295
+ @click=${this.openContextMenu}
296
+ @dblclick=${(e) => e.stopPropagation()}
297
+ ></mo-icon-button>
298
+ </mo-flex>
297
299
  `;
298
300
  }
299
301
  get detailsTemplate() {
@@ -303,8 +305,8 @@ export class DataGridRow extends Component {
303
305
  if (this.dataGrid.getRowDetailsTemplate) {
304
306
  return this.dataGrid.getRowDetailsTemplate(this.data);
305
307
  }
306
- return !this.dataRecord.hasSubData ? html.nothing : html `
307
- ${this.dataRecord.getSubDataByLevel(this.level + 1)?.map(data => this.dataGrid.getRowTemplate(data))}
308
+ return !this.dataRecord.hasSubData ? html.nothing : html `
309
+ ${this.dataRecord.getSubDataByLevel(this.level + 1)?.map(data => this.dataGrid.getRowTemplate(data))}
308
310
  `;
309
311
  }
310
312
  handleContentClick() {