@3mo/data-grid 0.5.13 → 0.5.14

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.
@@ -1 +1 @@
1
- {"version":3,"file":"CsvGenerator.d.ts","sourceRoot":"","sources":["../CsvGenerator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,qBAAa,YAAY;IACxB,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC;CAWrD"}
1
+ {"version":3,"file":"CsvGenerator.d.ts","sourceRoot":"","sources":["../CsvGenerator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,qBAAa,YAAY;IACxB,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC;CA0BrD"}
@@ -1,13 +1,26 @@
1
1
  import { Downloader } from '@3mo/downloader';
2
2
  export class CsvGenerator {
3
3
  static generate(dataGrid) {
4
- const csv = [
5
- dataGrid.visibleColumns.map(c => c.heading),
6
- ...dataGrid.data.map(data => dataGrid.visibleColumns.map(c => getValueByKeyPath(data, c.dataSelector)?.toString() ?? '').join(',')),
7
- ].join('\n');
4
+ const flattenedData = [...dataGrid['getFlattenedData']()];
5
+ const maxLevel = Math.max(...flattenedData.map(d => d.level));
6
+ const [firstHeading, ...restHeadings] = dataGrid.visibleColumns.map(c => c.heading);
7
+ const rows = [
8
+ [firstHeading, ...Array.from({ length: maxLevel }).fill(''), ...restHeadings],
9
+ ...flattenedData.map(d => {
10
+ const nestedPadding = Array.from({ length: d.level }).fill('');
11
+ const childrenPadding = Array.from({ length: maxLevel - d.level }).fill('');
12
+ const [first, ...rest] = dataGrid.visibleColumns.flatMap(column => getValueByKeyPath(d.data, column.dataSelector));
13
+ return [
14
+ ...nestedPadding,
15
+ first,
16
+ ...childrenPadding,
17
+ ...rest
18
+ ];
19
+ })
20
+ ];
21
+ const csv = rows.map(row => row.join(',')).join('\n');
8
22
  // @ts-expect-error manifest can be undefined
9
- const manifest = globalThis.manifest;
10
- const fileName = (manifest?.short_name ?? '') + 'Export'.replace(/ /g, '_');
23
+ const fileName = (globalThis.manifest?.short_name ?? '') + 'Export'.replace(/ /g, '_');
11
24
  Downloader.download(`data:text/csv;charset=utf-8,${encodeURIComponent(csv)}`, `${fileName}.csv`);
12
25
  }
13
26
  }
package/dist/DataGrid.js CHANGED
@@ -799,16 +799,16 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
799
799
  }
800
800
  *getFlattenedData() {
801
801
  if (!this.subDataGridDataSelector) {
802
- yield* this.data;
802
+ yield* this.data.map(d => ({ level: 0, data: d }));
803
803
  return;
804
804
  }
805
- const flatten = (data) => {
805
+ const flatten = (data, level = 0) => {
806
806
  const subData = getValueByKeyPath(data, this.subDataGridDataSelector);
807
807
  return [
808
- data,
808
+ { data, level },
809
809
  ...!Array.isArray(subData)
810
810
  ? []
811
- : subData.flatMap(flatten)
811
+ : subData.flatMap(d => flatten(d, level + 1))
812
812
  ];
813
813
  };
814
814
  for (const data of this.data) {
@@ -817,7 +817,7 @@ let DataGrid = DataGrid_1 = class DataGrid extends Component {
817
817
  return;
818
818
  }
819
819
  get flattenedData() {
820
- return [...this.getFlattenedData()];
820
+ return [...this.getFlattenedData()].map(({ data }) => data);
821
821
  }
822
822
  get sortedData() {
823
823
  const sorting = this.getSorting();
@@ -99,46 +99,46 @@ let DataGridCell = class DataGridCell extends Component {
99
99
  }
100
100
  }
101
101
  static get styles() {
102
- return css `
103
- :host {
104
- position: relative;
105
- padding-inline: var(--mo-data-grid-cell-padding, 3px);
106
- user-select: none;
107
- line-height: var(--mo-data-grid-row-height);
108
- white-space: nowrap;
109
- overflow: hidden !important;
110
- text-overflow: ellipsis;
111
- font-size: var(--mo-data-grid-cell-font-size);
112
- }
113
-
114
- :host(:not([isEditing]):focus) {
115
- outline: 2px solid var(--mo-color-accent);
116
- }
117
-
118
- :host([isEditing]) {
119
- display: grid;
120
- }
121
-
122
- :host([alignment=end]) {
123
- text-align: end;
124
- }
125
-
126
- :host([alignment=start]) {
127
- text-align: start
128
- }
129
-
130
- :host([alignment=center]) {
131
- text-align: center;
132
- }
133
-
134
- :host > :first-child {
135
- line-height: var(--mo-data-grid-row-height);
136
- }
137
-
138
- :host([isEditing]) > :first-child {
139
- align-self: center;
140
- justify-self: stretch;
141
- }
102
+ return css `
103
+ :host {
104
+ position: relative;
105
+ padding-inline: var(--mo-data-grid-cell-padding, 3px);
106
+ user-select: none;
107
+ line-height: var(--mo-data-grid-row-height);
108
+ white-space: nowrap;
109
+ overflow: hidden !important;
110
+ text-overflow: ellipsis;
111
+ font-size: var(--mo-data-grid-cell-font-size);
112
+ }
113
+
114
+ :host(:not([isEditing]):focus) {
115
+ outline: 2px solid var(--mo-color-accent);
116
+ }
117
+
118
+ :host([isEditing]) {
119
+ display: grid;
120
+ }
121
+
122
+ :host([alignment=end]) {
123
+ text-align: end;
124
+ }
125
+
126
+ :host([alignment=start]) {
127
+ text-align: start
128
+ }
129
+
130
+ :host([alignment=center]) {
131
+ text-align: center;
132
+ }
133
+
134
+ :host > :first-child {
135
+ line-height: var(--mo-data-grid-row-height);
136
+ }
137
+
138
+ :host([isEditing]) > :first-child {
139
+ align-self: center;
140
+ justify-self: stretch;
141
+ }
142
142
  `;
143
143
  }
144
144
  get tooltip() { return this.valueTextContent; }
@@ -40,45 +40,45 @@ let DataGridHeader = class DataGridHeader extends Component {
40
40
  this.dataGrid.selectionChange.unsubscribe(this.handleDataGridSelectionChange);
41
41
  }
42
42
  static get styles() {
43
- return css `
44
- :host {
45
- --mo-data-grid-header-separator-height: 15px;
46
- --mo-data-grid-header-separator-width: 2px;
47
- display: inherit;
48
- font-size: small;
49
- }
50
-
51
- #header {
52
- border-top: var(--mo-data-grid-border);
53
- border-bottom: var(--mo-data-grid-border);
54
- position: relative;
55
- height: var(--mo-data-grid-header-height);
56
- background: var(--mo-data-grid-header-background);
57
- }
58
-
59
- .headerContent {
60
- padding: 0 var(--mo-data-grid-cell-padding, 3px);
61
- display: inline-block;
62
- overflow: hidden !important;
63
- color: var(--mo-color-foreground);
64
- font-weight: 500;
65
- line-height: var(--mo-data-grid-header-height);
66
- white-space: nowrap;
67
- text-overflow: ellipsis;
68
- }
69
-
70
- .sort-rank {
71
- background: var(--mo-color-transparent-gray-3);
72
- color: var(--mo-color-foreground);
73
- border: 1px solid var(--mo-color-gray-transparent);
74
- border-radius: 50%;
75
- width: 20px;
76
- height: 20px;
77
- aspect-ratio: 1 / 1;
78
- display: flex;
79
- align-items: center;
80
- justify-content: center;
81
- }
43
+ return css `
44
+ :host {
45
+ --mo-data-grid-header-separator-height: 15px;
46
+ --mo-data-grid-header-separator-width: 2px;
47
+ display: inherit;
48
+ font-size: small;
49
+ }
50
+
51
+ #header {
52
+ border-top: var(--mo-data-grid-border);
53
+ border-bottom: var(--mo-data-grid-border);
54
+ position: relative;
55
+ height: var(--mo-data-grid-header-height);
56
+ background: var(--mo-data-grid-header-background);
57
+ }
58
+
59
+ .headerContent {
60
+ padding: 0 var(--mo-data-grid-cell-padding, 3px);
61
+ display: inline-block;
62
+ overflow: hidden !important;
63
+ color: var(--mo-color-foreground);
64
+ font-weight: 500;
65
+ line-height: var(--mo-data-grid-header-height);
66
+ white-space: nowrap;
67
+ text-overflow: ellipsis;
68
+ }
69
+
70
+ .sort-rank {
71
+ background: var(--mo-color-transparent-gray-3);
72
+ color: var(--mo-color-foreground);
73
+ border: 1px solid var(--mo-color-gray-transparent);
74
+ border-radius: 50%;
75
+ width: 20px;
76
+ height: 20px;
77
+ aspect-ratio: 1 / 1;
78
+ display: flex;
79
+ align-items: center;
80
+ justify-content: center;
81
+ }
82
82
  `;
83
83
  }
84
84
  get skeletonColumns() {
@@ -93,75 +93,75 @@ let DataGridHeader = class DataGridHeader extends Component {
93
93
  return this.dataGrid.dataColumnsWidths.join(' var(--mo-data-grid-columns-gap) ');
94
94
  }
95
95
  get template() {
96
- return html `
97
- <mo-grid id='header' columns=${this.skeletonColumns} columnGap='var(--mo-data-grid-columns-gap)'>
98
- ${this.detailsExpanderTemplate}
99
- ${this.selectionTemplate}
100
- ${this.contentTemplate}
101
- ${this.moreTemplate}
102
- </mo-grid>
96
+ return html `
97
+ <mo-grid id='header' columns=${this.skeletonColumns} columnGap='var(--mo-data-grid-columns-gap)'>
98
+ ${this.detailsExpanderTemplate}
99
+ ${this.selectionTemplate}
100
+ ${this.contentTemplate}
101
+ ${this.moreTemplate}
102
+ </mo-grid>
103
103
  `;
104
104
  }
105
105
  get detailsExpanderTemplate() {
106
- return this.dataGrid.hasDetails === false ? html.nothing : html `
107
- <mo-flex justifyContent='center' alignItems='center'>
108
- ${!this.dataGrid.hasDetails || !this.dataGrid.multipleDetails ? html.nothing : html `
109
- <mo-icon-button dense ${style({ padding: '-10px 0px 0 -10px' })}
110
- ${style({ display: 'inherit' })}
111
- icon=${this.dataGrid.allRowDetailsOpen ? 'unfold_less' : 'unfold_more'}
112
- @click=${() => this.toggleAllDetails()}
113
- ></mo-icon-button>
114
- `}
115
- </mo-flex>
106
+ return this.dataGrid.hasDetails === false ? html.nothing : html `
107
+ <mo-flex justifyContent='center' alignItems='center'>
108
+ ${!this.dataGrid.hasDetails || !this.dataGrid.multipleDetails ? html.nothing : html `
109
+ <mo-icon-button dense ${style({ padding: '-10px 0px 0 -10px' })}
110
+ ${style({ display: 'inherit' })}
111
+ icon=${this.dataGrid.allRowDetailsOpen ? 'unfold_less' : 'unfold_more'}
112
+ @click=${() => this.toggleAllDetails()}
113
+ ></mo-icon-button>
114
+ `}
115
+ </mo-flex>
116
116
  `;
117
117
  }
118
118
  get selectionTemplate() {
119
- return this.dataGrid.hasSelection === false || this.dataGrid.selectionCheckboxesHidden ? html.nothing : html `
120
- <mo-flex justifyContent='center' alignItems='center'>
121
- ${this.dataGrid.selectionMode !== DataGridSelectionMode.Multiple ? html.nothing : html `
122
- <mo-checkbox ${style({ position: 'absolute' })} .selected=${this.selection} @change=${this.handleSelectionChange}></mo-checkbox>
123
- `}
124
- </mo-flex>
119
+ return this.dataGrid.hasSelection === false || this.dataGrid.selectionCheckboxesHidden ? html.nothing : html `
120
+ <mo-flex justifyContent='center' alignItems='center'>
121
+ ${this.dataGrid.selectionMode !== DataGridSelectionMode.Multiple ? html.nothing : html `
122
+ <mo-checkbox ${style({ position: 'absolute' })} .selected=${this.selection} @change=${this.handleSelectionChange}></mo-checkbox>
123
+ `}
124
+ </mo-flex>
125
125
  `;
126
126
  }
127
127
  get contentTemplate() {
128
- return html `
129
- <mo-grid columns=${this.separatorAdjustedColumns}>
130
- ${join(this.dataGrid.visibleColumns.map(column => this.getHeaderCellTemplate(column)), index => html `
131
- <mo-data-grid-header-separator
132
- .dataGrid=${this.dataGrid}
133
- .column=${this.dataGrid.visibleColumns[index]}
134
- @columnUpdate=${() => this.dataGrid.requestUpdate()}
135
- ></mo-data-grid-header-separator>
136
- `)}
137
- </mo-grid>
128
+ return html `
129
+ <mo-grid columns=${this.separatorAdjustedColumns}>
130
+ ${join(this.dataGrid.visibleColumns.map(column => this.getHeaderCellTemplate(column)), index => html `
131
+ <mo-data-grid-header-separator
132
+ .dataGrid=${this.dataGrid}
133
+ .column=${this.dataGrid.visibleColumns[index]}
134
+ @columnUpdate=${() => this.dataGrid.requestUpdate()}
135
+ ></mo-data-grid-header-separator>
136
+ `)}
137
+ </mo-grid>
138
138
  `;
139
139
  }
140
140
  getHeaderCellTemplate(column) {
141
141
  const sortingDefinition = this.dataGrid.getSortingDefinition(column);
142
142
  const sortIcon = !sortingDefinition ? undefined : sortingDefinition.strategy === DataGridSortingStrategy.Ascending ? 'arrow_upward' : 'arrow_downward';
143
143
  const sortingRank = !sortingDefinition || this.dataGrid.getSorting().length <= 1 ? undefined : sortingDefinition.rank;
144
- return html `
145
- <mo-flex direction=${column.alignment === 'end' ? 'horizontal-reversed' : 'horizontal'} alignItems='center'
146
- ${style({ overflow: 'hidden', position: 'relative', cursor: 'pointer', userSelect: 'none' })}
147
- @click=${() => this.sort(column)}
148
- >
149
- <div class='headerContent' ${style({ width: '100%', textAlign: column.alignment })} title=${column.title || column.heading}>${column.heading}</div>
150
-
151
- ${sortIcon === undefined ? html.nothing : html `
152
- ${!sortingRank ? html.nothing : html `<span class='sort-rank'>${sortingRank}</span>`}
153
- <mo-icon ${style({ color: 'var(--mo-color-accent)' })} icon=${ifDefined(sortIcon)}></mo-icon>
154
- `}
155
- </mo-flex>
144
+ return html `
145
+ <mo-flex direction=${column.alignment === 'end' ? 'horizontal-reversed' : 'horizontal'} alignItems='center'
146
+ ${style({ overflow: 'hidden', position: 'relative', cursor: 'pointer', userSelect: 'none' })}
147
+ @click=${() => this.sort(column)}
148
+ >
149
+ <div class='headerContent' ${style({ width: '100%', textAlign: column.alignment })} title=${column.title || column.heading}>${column.heading}</div>
150
+
151
+ ${sortIcon === undefined ? html.nothing : html `
152
+ ${!sortingRank ? html.nothing : html `<span class='sort-rank'>${sortingRank}</span>`}
153
+ <mo-icon ${style({ color: 'var(--mo-color-accent)' })} icon=${ifDefined(sortIcon)}></mo-icon>
154
+ `}
155
+ </mo-flex>
156
156
  `;
157
157
  }
158
158
  get moreTemplate() {
159
- return this.dataGrid.hasToolbar || this.dataGrid.sidePanelHidden ? html.nothing : html `
160
- <mo-flex alignItems='center' justifyContent='center' ${style({ marginInlineEnd: '8px', cursor: 'pointer', position: 'relative' })}>
161
- <mo-icon-button dense icon='settings' ${style({ color: 'var(--mo-color-accent)', fontSize: 'large' })}
162
- @click=${() => this.dataGrid.navigateToSidePanelTab(this.dataGrid.sidePanelTab ? undefined : DataGridSidePanelTab.Settings)}
163
- ></mo-icon-button>
164
- </mo-flex>
159
+ return this.dataGrid.hasToolbar || this.dataGrid.sidePanelHidden ? html.nothing : html `
160
+ <mo-flex alignItems='center' justifyContent='center' ${style({ marginInlineEnd: '8px', cursor: 'pointer', position: 'relative' })}>
161
+ <mo-icon-button dense icon='settings' ${style({ color: 'var(--mo-color-accent)', fontSize: 'large' })}
162
+ @click=${() => this.dataGrid.navigateToSidePanelTab(this.dataGrid.sidePanelTab ? undefined : DataGridSidePanelTab.Settings)}
163
+ ></mo-icon-button>
164
+ </mo-flex>
165
165
  `;
166
166
  }
167
167
  sort(column) {
@@ -17,55 +17,55 @@ let DataGridHeaderSeparator = DataGridHeaderSeparator_1 = class DataGridHeaderSe
17
17
  };
18
18
  }
19
19
  static get styles() {
20
- return css `
21
- div.separator {
22
- display: flex;
23
- align-items: center;
24
- justify-content: center;
25
- inset-inline-start: calc(var(--mo-data-grid-columns-gap) * -1);
26
- width: var(--mo-data-grid-columns-gap);
27
- height: 100%;
28
- user-select: none;
29
- }
30
-
31
- .knob {
32
- height: var(--mo-data-grid-header-separator-height);
33
- width: var(--mo-data-grid-header-separator-width);
34
- border-radius: 100px;
35
- background-color: var(--mo-color-gray);
36
- transition: 0.2s;
37
- }
38
-
39
- :host(:not([disabled])) div.separator {
40
- cursor: col-resize;
41
- }
42
-
43
- :host(:not([disabled])) .separator:hover .knob {
44
- --mo-data-grid-header-separator-height: 30px;
45
- --mo-data-grid-header-separator-width: 8px;
46
- background-color: var(--mo-color-accent);
47
- cursor: col-resize;
48
- }
49
-
50
- :host(:not([disabled])) .resizerOverlay {
51
- position: fixed;
52
- top: 0;
53
- height: 100%;
54
- background: var(--mo-color-gray);
55
- width: 2px;
56
- }
20
+ return css `
21
+ div.separator {
22
+ display: flex;
23
+ align-items: center;
24
+ justify-content: center;
25
+ inset-inline-start: calc(var(--mo-data-grid-columns-gap) * -1);
26
+ width: var(--mo-data-grid-columns-gap);
27
+ height: 100%;
28
+ user-select: none;
29
+ }
30
+
31
+ .knob {
32
+ height: var(--mo-data-grid-header-separator-height);
33
+ width: var(--mo-data-grid-header-separator-width);
34
+ border-radius: 100px;
35
+ background-color: var(--mo-color-gray);
36
+ transition: 0.2s;
37
+ }
38
+
39
+ :host(:not([disabled])) div.separator {
40
+ cursor: col-resize;
41
+ }
42
+
43
+ :host(:not([disabled])) .separator:hover .knob {
44
+ --mo-data-grid-header-separator-height: 30px;
45
+ --mo-data-grid-header-separator-width: 8px;
46
+ background-color: var(--mo-color-accent);
47
+ cursor: col-resize;
48
+ }
49
+
50
+ :host(:not([disabled])) .resizerOverlay {
51
+ position: fixed;
52
+ top: 0;
53
+ height: 100%;
54
+ background: var(--mo-color-gray);
55
+ width: 2px;
56
+ }
57
57
  `;
58
58
  }
59
59
  get template() {
60
60
  this.toggleAttribute('disabled', DataGridHeaderSeparator_1.disableResizing);
61
- return html `
62
- <div class='separator' @mousedown=${this.handleMouseDown}>
63
- <div class='knob'></div>
64
- </div>
65
-
66
- ${this.isResizing === false ? html.nothing : html `
67
- <div class='resizerOverlay' ${style({ marginInlineStart: `${this.delta}px` })}></div>
68
- `}
61
+ return html `
62
+ <div class='separator' @mousedown=${this.handleMouseDown}>
63
+ <div class='knob'></div>
64
+ </div>
65
+
66
+ ${this.isResizing === false ? html.nothing : html `
67
+ <div class='resizerOverlay' ${style({ marginInlineStart: `${this.delta}px` })}></div>
68
+ `}
69
69
  `;
70
70
  }
71
71
  handleMouseUp() {