@oml/markdown 0.10.0 → 0.11.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.
@@ -27,6 +27,14 @@ type TableEditorActionContext = {
27
27
  pointerY?: number;
28
28
  };
29
29
 
30
+ type TableRootWithAiContext = HTMLDivElement & {
31
+ __omlAiContext?: {
32
+ columns: string[];
33
+ rows: Array<{ iri: string; cells: string[] }>;
34
+ blockSource?: string;
35
+ };
36
+ };
37
+
30
38
  export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
31
39
  protected readonly tableKinds: ReadonlyArray<TableBlockKind> = ['table'];
32
40
 
@@ -92,7 +100,7 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
92
100
  options: Record<string, unknown> | undefined,
93
101
  blockSource?: string
94
102
  ): HTMLElement {
95
- const root = document.createElement('div');
103
+ const root = document.createElement('div') as TableRootWithAiContext;
96
104
  root.className = 'table-root graph-root';
97
105
  const isTree = this.tableKinds.includes('tree');
98
106
  const allRowsWithIndex = rows.map((cells, index) => ({ index, cells }));
@@ -114,6 +122,16 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
114
122
  ...row,
115
123
  cells: visibleColumnIndexes.map((columnIndex) => row.cells[columnIndex] ?? ''),
116
124
  }));
125
+ root.__omlAiContext = {
126
+ columns: visibleColumns.slice(),
127
+ rows: rowsWithIndex
128
+ .map((row) => ({
129
+ iri: (row.cells[0] ?? '').trim(),
130
+ cells: row.cells.slice(),
131
+ }))
132
+ .filter((row) => row.iri.length > 0),
133
+ blockSource,
134
+ };
117
135
  const columnContexts = createColumnContexts(visibleColumns, rowsWithIndex);
118
136
  const treeModel = isTree
119
137
  ? this.createTreeModel(columns, allRowsWithIndex, visibleColumnIndexes, options)
@@ -218,10 +236,16 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
218
236
  return;
219
237
  }
220
238
  const filtered = this.applyFiltersAndSorting(columns, sourceRows, state);
221
- this.requestCsvDownload(visibleColumns, filtered.map((entry) => entry.cells));
239
+ const csvExport = this.transformCsvDownloadData(visibleColumns, filtered.map((entry) => entry.cells));
240
+ this.requestCsvDownload(csvExport.columns, csvExport.rows);
222
241
  });
223
242
  controlsRight.appendChild(downloadButton);
224
243
 
244
+ const uploadButton = this.createUploadCsvButton(visibleColumns, rowsWithIndex, isTree, blockSource);
245
+ if (uploadButton) {
246
+ controlsRight.appendChild(uploadButton);
247
+ }
248
+
225
249
  controls.appendChild(controlsLeft);
226
250
  controls.appendChild(controlsRight);
227
251
  root.appendChild(controls);
@@ -957,6 +981,19 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
957
981
  return value;
958
982
  }
959
983
 
984
+ protected createUploadCsvButton(
985
+ _columns: string[],
986
+ _rows: Array<{ index: number; cells: string[] }>,
987
+ _isTree: boolean,
988
+ _blockSource: string | undefined
989
+ ): HTMLElement | undefined {
990
+ return undefined;
991
+ }
992
+
993
+ protected transformCsvDownloadData(columns: string[], rows: string[][]): { columns: string[]; rows: string[][] } {
994
+ return { columns, rows };
995
+ }
996
+
960
997
  private requestCsvDownload(columns: string[], rows: string[][]): void {
961
998
  if (columns.length === 0) {
962
999
  return;