@oml/markdown 0.11.0 → 0.13.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.
- package/out/md/md-execution.d.ts +16 -0
- package/out/md/md-executor.d.ts +1 -0
- package/out/md/md-executor.js +219 -35
- package/out/md/md-executor.js.map +1 -1
- package/out/renderers/diagram-renderer.js +160 -1
- package/out/renderers/diagram-renderer.js.map +1 -1
- package/out/renderers/graph-renderer.js +452 -18
- package/out/renderers/graph-renderer.js.map +1 -1
- package/out/renderers/matrix-renderer.d.ts +0 -2
- package/out/renderers/matrix-renderer.js +45 -40
- package/out/renderers/matrix-renderer.js.map +1 -1
- package/out/renderers/renderer.d.ts +4 -1
- package/out/renderers/renderer.js +98 -0
- package/out/renderers/renderer.js.map +1 -1
- package/out/renderers/table-renderer.d.ts +4 -2
- package/out/renderers/table-renderer.js +104 -38
- package/out/renderers/table-renderer.js.map +1 -1
- package/out/renderers/types.d.ts +16 -0
- package/out/renderers/wikilink-utils.d.ts +1 -0
- package/out/renderers/wikilink-utils.js +60 -32
- package/out/renderers/wikilink-utils.js.map +1 -1
- package/out/static/browser-runtime.bundle.js +7452 -1297
- package/out/static/browser-runtime.bundle.js.map +4 -4
- package/out/static/browser-runtime.js +15 -2
- package/out/static/browser-runtime.js.map +1 -1
- package/package.json +2 -2
- package/src/md/md-execution.ts +20 -0
- package/src/md/md-executor.ts +268 -40
- package/src/renderers/diagram-renderer.ts +167 -1
- package/src/renderers/graph-renderer.ts +512 -12
- package/src/renderers/matrix-renderer.ts +57 -44
- package/src/renderers/renderer.ts +105 -1
- package/src/renderers/table-renderer.ts +151 -39
- package/src/renderers/types.ts +20 -0
- package/src/renderers/wikilink-utils.ts +66 -31
- package/src/static/browser-runtime.ts +20 -2
- package/src/static/markdown-webview.css +44 -15
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Copyright (c) 2026 Modelware. All rights reserved.
|
|
2
|
+
import { appendInlineValue, createWikiLinkElement, isUrlValue, shortLabelFromIri } from './wikilink-utils.js';
|
|
2
3
|
let iriLabelSnapshot;
|
|
3
4
|
export function setIriLabelSnapshot(snapshot) {
|
|
4
5
|
if (!snapshot) {
|
|
@@ -88,6 +89,41 @@ export class BaseMarkdownBlockRenderer {
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
export class QueryMarkdownBlockRenderer extends BaseMarkdownBlockRenderer {
|
|
92
|
+
renderCellValue(raw, typedValue) {
|
|
93
|
+
const value = document.createElement('span');
|
|
94
|
+
value.className = 'table-value';
|
|
95
|
+
const entries = typedValue?.values ?? [];
|
|
96
|
+
if (entries.length > 0) {
|
|
97
|
+
entries.forEach((entry, index) => {
|
|
98
|
+
if (index > 0) {
|
|
99
|
+
value.appendChild(document.createTextNode(' '));
|
|
100
|
+
}
|
|
101
|
+
value.appendChild(this.renderValueToken(entry));
|
|
102
|
+
});
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
const display = this.formatCellDisplayText(raw, typedValue);
|
|
106
|
+
const fragment = document.createElement('span');
|
|
107
|
+
fragment.className = 'table-value-part';
|
|
108
|
+
fragment.dataset.value = display;
|
|
109
|
+
appendInlineValue(fragment, display);
|
|
110
|
+
value.appendChild(fragment);
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
formatCellDisplayText(raw, typedValue) {
|
|
114
|
+
if (typedValue?.values?.length) {
|
|
115
|
+
return typedValue.values.map((entry) => {
|
|
116
|
+
if (entry.kind === 'iri') {
|
|
117
|
+
return shortLabelFromIri(entry.value);
|
|
118
|
+
}
|
|
119
|
+
if (entry.kind === 'bnode') {
|
|
120
|
+
return `_:${entry.value}`;
|
|
121
|
+
}
|
|
122
|
+
return entry.value;
|
|
123
|
+
}).join(' ');
|
|
124
|
+
}
|
|
125
|
+
return raw;
|
|
126
|
+
}
|
|
91
127
|
getBlockSource(result) {
|
|
92
128
|
return result.blockSource;
|
|
93
129
|
}
|
|
@@ -97,6 +133,33 @@ export class QueryMarkdownBlockRenderer extends BaseMarkdownBlockRenderer {
|
|
|
97
133
|
getBlockRange(result) {
|
|
98
134
|
return { start: result.blockLineStart, end: result.blockLineEnd };
|
|
99
135
|
}
|
|
136
|
+
renderValueToken(entry) {
|
|
137
|
+
const fragment = document.createElement('span');
|
|
138
|
+
fragment.className = 'table-value-part';
|
|
139
|
+
fragment.dataset.value = entry.value;
|
|
140
|
+
if (entry.kind === 'iri') {
|
|
141
|
+
if (isBuiltInOntologyIri(entry.value)) {
|
|
142
|
+
appendInlineValue(fragment, shortLabelFromIri(entry.value));
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
fragment.appendChild(createWikiLinkElement(entry.value, shortLabelFromIri(entry.value)));
|
|
146
|
+
}
|
|
147
|
+
return fragment;
|
|
148
|
+
}
|
|
149
|
+
if (entry.kind === 'bnode') {
|
|
150
|
+
appendInlineValue(fragment, `_:${entry.value}`);
|
|
151
|
+
return fragment;
|
|
152
|
+
}
|
|
153
|
+
if (isUrlValue(entry.value)) {
|
|
154
|
+
const link = document.createElement('a');
|
|
155
|
+
link.href = entry.value;
|
|
156
|
+
link.textContent = entry.value;
|
|
157
|
+
fragment.appendChild(link);
|
|
158
|
+
return fragment;
|
|
159
|
+
}
|
|
160
|
+
appendInlineValue(fragment, entry.value);
|
|
161
|
+
return fragment;
|
|
162
|
+
}
|
|
100
163
|
}
|
|
101
164
|
export class CanvasMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
102
165
|
canRender(result) {
|
|
@@ -111,4 +174,39 @@ export class CanvasMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
111
174
|
return container;
|
|
112
175
|
}
|
|
113
176
|
}
|
|
177
|
+
const BUILT_IN_ONTOLOGY_IRIS = new Set([
|
|
178
|
+
'http://opencaesar.io/oml',
|
|
179
|
+
'http://www.w3.org/2001/XMLSchema',
|
|
180
|
+
'http://www.w3.org/1999/02/22-rdf-syntax-ns',
|
|
181
|
+
'http://www.w3.org/2000/01/rdf-schema',
|
|
182
|
+
'http://www.w3.org/2002/07/owl',
|
|
183
|
+
'http://www.w3.org/2003/11/swrl',
|
|
184
|
+
'http://www.w3.org/2003/11/swrlb',
|
|
185
|
+
]);
|
|
186
|
+
function ontologyLookupKeyFromIri(value) {
|
|
187
|
+
const iri = String(value ?? '').trim().replace(/^<|>$/g, '');
|
|
188
|
+
if (!iri || !/^[A-Za-z][A-Za-z0-9+.-]*:[^\s]+$/.test(iri)) {
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
const hashIndex = iri.indexOf('#');
|
|
192
|
+
if (hashIndex >= 0) {
|
|
193
|
+
return normalizeOntologyLookupKey(iri.slice(0, hashIndex + 1));
|
|
194
|
+
}
|
|
195
|
+
const schemeIndex = iri.indexOf('://');
|
|
196
|
+
const slashIndex = iri.lastIndexOf('/');
|
|
197
|
+
if (slashIndex > schemeIndex + 2) {
|
|
198
|
+
return normalizeOntologyLookupKey(iri.slice(0, slashIndex + 1));
|
|
199
|
+
}
|
|
200
|
+
return normalizeOntologyLookupKey(iri);
|
|
201
|
+
}
|
|
202
|
+
function normalizeOntologyLookupKey(value) {
|
|
203
|
+
return value.trim().replace(/^<|>$/g, '').replace(/[\/#]+$/, '');
|
|
204
|
+
}
|
|
205
|
+
function isBuiltInOntologyIri(iri) {
|
|
206
|
+
const key = ontologyLookupKeyFromIri(iri);
|
|
207
|
+
if (!key) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
return BUILT_IN_ONTOLOGY_IRIS.has(normalizeOntologyLookupKey(key));
|
|
211
|
+
}
|
|
114
212
|
//# sourceMappingURL=renderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../src/renderers/renderer.ts"],"names":[],"mappings":"AAAA,qDAAqD;
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../src/renderers/renderer.ts"],"names":[],"mappings":"AAAA,qDAAqD;A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A0B,CAAC,KAAa;IAC7C,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,oBAAoB,CAAC,GAAW;IACrC,MAAM,GAAG,GAAG,wBAAwB,CAAC,GAAG,CAAC,CAAC;IAC1C,IAAI,CAAC,GAAG,EAAE,CAAC;QACP,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,sBAAsB,CAAC,GAAG,CAAC,0BAA0B,CAAC,GAAG,CAAC,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryMarkdownBlockRenderer, type TableBlockKind } from './renderer.js';
|
|
2
|
-
import type { MdBlockExecutionResult } from './types.js';
|
|
2
|
+
import type { MdBlockExecutionResult, MdTableCell } from './types.js';
|
|
3
3
|
type TableEditorActionKind = 'add' | 'remove' | 'validate' | 'link' | 'undo' | 'redo' | 'ai' | 'properties';
|
|
4
4
|
type TableEditorActionContext = {
|
|
5
5
|
action: TableEditorActionKind;
|
|
@@ -48,7 +48,7 @@ export declare class TableMarkdownBlockRenderer extends QueryMarkdownBlockRender
|
|
|
48
48
|
protected shouldIgnoreRowDoubleClick(_event: MouseEvent): boolean;
|
|
49
49
|
protected onRowDoubleClick(_context: Omit<TableEditorActionContext, 'action'>): void;
|
|
50
50
|
protected dispatchTableEditorAction(context: TableEditorActionContext): void;
|
|
51
|
-
protected renderInteractiveTable(columns: string[], rows: string[][], stylesheet: CompiledTableStyleRule[], options: Record<string, unknown> | undefined, blockSource?: string): HTMLElement;
|
|
51
|
+
protected renderInteractiveTable(columns: string[], rows: string[][], rowsTyped: MdTableCell[][] | undefined, stylesheet: CompiledTableStyleRule[], options: Record<string, unknown> | undefined, blockSource?: string, blockId?: string): HTMLElement;
|
|
52
52
|
protected extractTypeOptions(_blockSource: string | undefined): string[];
|
|
53
53
|
private resolveTreeSourceRows;
|
|
54
54
|
private filterTreeRowsBySearch;
|
|
@@ -58,6 +58,7 @@ export declare class TableMarkdownBlockRenderer extends QueryMarkdownBlockRender
|
|
|
58
58
|
private renderTreeCell;
|
|
59
59
|
private createTreeActionButton;
|
|
60
60
|
private applyFiltersAndSorting;
|
|
61
|
+
private getDisplayFilterCells;
|
|
61
62
|
private applyStylesheet;
|
|
62
63
|
private matchesRule;
|
|
63
64
|
private resolveValueTargets;
|
|
@@ -67,6 +68,7 @@ export declare class TableMarkdownBlockRenderer extends QueryMarkdownBlockRender
|
|
|
67
68
|
private installColumnResizeHandle;
|
|
68
69
|
private autosizeColumnWidth;
|
|
69
70
|
private measureTreePrefixWidth;
|
|
71
|
+
private measureRenderedCellContentWidth;
|
|
70
72
|
private resolveFont;
|
|
71
73
|
private measureTextWidth;
|
|
72
74
|
protected formatCellDisplayValue(raw: string, _context: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright (c) 2026 Modelware. All rights reserved.
|
|
2
2
|
import { QueryMarkdownBlockRenderer } from './renderer.js';
|
|
3
|
-
import {
|
|
3
|
+
import { shortLabelFromIri } from './wikilink-utils.js';
|
|
4
4
|
export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
5
5
|
constructor() {
|
|
6
6
|
super(...arguments);
|
|
@@ -16,7 +16,7 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
16
16
|
const container = this.createResultContainer(result.status);
|
|
17
17
|
container.classList.add('oml-md-result-table');
|
|
18
18
|
const stylesheet = compileTableStylesheet(result.options);
|
|
19
|
-
const tableRoot = this.renderInteractiveTable(result.payload?.columns ?? [], result.payload?.rows ?? [], stylesheet, result.options, result.blockSource);
|
|
19
|
+
const tableRoot = this.renderInteractiveTable(result.payload?.columns ?? [], result.payload?.rows ?? [], result.payload?.rowsTyped, stylesheet, result.options, result.blockSource, result.blockId);
|
|
20
20
|
if (typeof result.blockId === 'string' && result.blockId.length > 0) {
|
|
21
21
|
tableRoot.dataset.tableBlockId = result.blockId;
|
|
22
22
|
}
|
|
@@ -39,11 +39,15 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
39
39
|
const event = new CustomEvent('oml-table-editor-action', { detail: context });
|
|
40
40
|
window.dispatchEvent(event);
|
|
41
41
|
}
|
|
42
|
-
renderInteractiveTable(columns, rows, stylesheet, options, blockSource) {
|
|
42
|
+
renderInteractiveTable(columns, rows, rowsTyped, stylesheet, options, blockSource, blockId) {
|
|
43
43
|
const root = document.createElement('div');
|
|
44
44
|
root.className = 'table-root graph-root';
|
|
45
45
|
const isTree = this.tableKinds.includes('tree');
|
|
46
|
-
const allRowsWithIndex = rows.map((cells, index) => ({
|
|
46
|
+
const allRowsWithIndex = rows.map((cells, index) => ({
|
|
47
|
+
index,
|
|
48
|
+
cells,
|
|
49
|
+
typedCells: rowsTyped?.[index],
|
|
50
|
+
}));
|
|
47
51
|
const containmentColumns = isTree ? resolveContainmentColumns(columns, options) : [];
|
|
48
52
|
const baseVisibleColumnIndexes = isTree
|
|
49
53
|
? columns.map((_, index) => index).filter((index) => !containmentColumns.includes(index))
|
|
@@ -52,6 +56,7 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
52
56
|
const baseRowsWithIndex = allRowsWithIndex.map((row) => ({
|
|
53
57
|
...row,
|
|
54
58
|
cells: baseVisibleColumnIndexes.map((columnIndex) => row.cells[columnIndex] ?? ''),
|
|
59
|
+
typedCells: baseVisibleColumnIndexes.map((columnIndex) => row.typedCells?.[columnIndex]),
|
|
55
60
|
}));
|
|
56
61
|
const selectorRowsByIndex = new Map(baseRowsWithIndex.map((row) => [row.index, row]));
|
|
57
62
|
const baseColumnContexts = createColumnContexts(baseVisibleColumns, baseRowsWithIndex);
|
|
@@ -61,6 +66,7 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
61
66
|
const rowsWithIndex = allRowsWithIndex.map((row) => ({
|
|
62
67
|
...row,
|
|
63
68
|
cells: visibleColumnIndexes.map((columnIndex) => row.cells[columnIndex] ?? ''),
|
|
69
|
+
typedCells: visibleColumnIndexes.map((columnIndex) => row.typedCells?.[columnIndex]),
|
|
64
70
|
}));
|
|
65
71
|
root.__omlAiContext = {
|
|
66
72
|
columns: visibleColumns.slice(),
|
|
@@ -79,17 +85,33 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
79
85
|
const fullyExpandedTreeRows = isTree && treeModel
|
|
80
86
|
? this.flattenAllTreeRows(treeModel)
|
|
81
87
|
: undefined;
|
|
88
|
+
const persistedState = blockId
|
|
89
|
+
? window.__omlGetPersistedTableUiState?.(blockId)
|
|
90
|
+
: undefined;
|
|
82
91
|
const state = {
|
|
83
|
-
search: '',
|
|
84
|
-
pageSize: 50,
|
|
85
|
-
page: 0,
|
|
86
|
-
sortKey: '',
|
|
87
|
-
sortDir: 'asc',
|
|
88
|
-
hasUserSort: false,
|
|
92
|
+
search: persistedState?.search ?? '',
|
|
93
|
+
pageSize: persistedState?.pageSize ?? 50,
|
|
94
|
+
page: persistedState?.page ?? 0,
|
|
95
|
+
sortKey: persistedState?.sortKey ?? '',
|
|
96
|
+
sortDir: persistedState?.sortDir ?? 'asc',
|
|
97
|
+
hasUserSort: persistedState?.hasUserSort ?? false,
|
|
89
98
|
columnWidths: new Array(columns.length).fill(undefined),
|
|
90
99
|
initialAutosizeApplied: false,
|
|
91
100
|
expanded: new Set(treeModel?.expandableNodes ?? []),
|
|
92
101
|
};
|
|
102
|
+
const persistUiState = () => {
|
|
103
|
+
if (!blockId) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
window.__omlSetPersistedTableUiState?.(blockId, {
|
|
107
|
+
search: state.search,
|
|
108
|
+
pageSize: state.pageSize,
|
|
109
|
+
page: state.page,
|
|
110
|
+
sortKey: state.sortKey,
|
|
111
|
+
sortDir: state.sortDir,
|
|
112
|
+
hasUserSort: state.hasUserSort,
|
|
113
|
+
});
|
|
114
|
+
};
|
|
93
115
|
const controls = document.createElement('div');
|
|
94
116
|
controls.className = 'table-controls';
|
|
95
117
|
const controlsLeft = document.createElement('div');
|
|
@@ -105,9 +127,11 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
105
127
|
}
|
|
106
128
|
pageSize.appendChild(option);
|
|
107
129
|
}
|
|
130
|
+
pageSize.value = String(state.pageSize);
|
|
108
131
|
pageSize.addEventListener('change', () => {
|
|
109
132
|
state.pageSize = Number.parseInt(pageSize.value, 10);
|
|
110
133
|
state.page = 0;
|
|
134
|
+
persistUiState();
|
|
111
135
|
renderPage();
|
|
112
136
|
});
|
|
113
137
|
if (!isTree) {
|
|
@@ -133,9 +157,11 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
133
157
|
searchInput.type = 'search';
|
|
134
158
|
searchInput.className = 'tree-filter';
|
|
135
159
|
searchInput.placeholder = 'Filter...';
|
|
160
|
+
searchInput.value = state.search;
|
|
136
161
|
searchInput.addEventListener('input', () => {
|
|
137
162
|
state.search = searchInput.value.trim().toLowerCase();
|
|
138
163
|
state.page = 0;
|
|
164
|
+
persistUiState();
|
|
139
165
|
renderPage();
|
|
140
166
|
});
|
|
141
167
|
controlsRight.appendChild(searchInput);
|
|
@@ -156,13 +182,13 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
156
182
|
downloadButton.appendChild(iconSvg);
|
|
157
183
|
downloadButton.addEventListener('click', () => {
|
|
158
184
|
const sourceRows = isTree && treeModel
|
|
159
|
-
? this.resolveTreeSourceRows(treeModel, visibleColumns, state.expanded, state.search)
|
|
185
|
+
? this.resolveTreeSourceRows(treeModel, visibleColumns, state.expanded, state.search, blockSource, options)
|
|
160
186
|
: rowsWithIndex;
|
|
161
187
|
if (isTree && treeModel) {
|
|
162
188
|
this.requestTreeJsonDownload(visibleColumns, treeModel, sourceRows);
|
|
163
189
|
return;
|
|
164
190
|
}
|
|
165
|
-
const filtered = this.applyFiltersAndSorting(
|
|
191
|
+
const filtered = this.applyFiltersAndSorting(visibleColumns, sourceRows, state, blockSource, options);
|
|
166
192
|
const csvExport = this.transformCsvDownloadData(visibleColumns, filtered.map((entry) => entry.cells));
|
|
167
193
|
this.requestCsvDownload(csvExport.columns, csvExport.rows);
|
|
168
194
|
});
|
|
@@ -206,6 +232,7 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
206
232
|
}
|
|
207
233
|
if (state.page > 0) {
|
|
208
234
|
state.page -= 1;
|
|
235
|
+
persistUiState();
|
|
209
236
|
renderPage();
|
|
210
237
|
}
|
|
211
238
|
});
|
|
@@ -213,10 +240,11 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
213
240
|
if (isTree) {
|
|
214
241
|
return;
|
|
215
242
|
}
|
|
216
|
-
const filtered = this.applyFiltersAndSorting(
|
|
243
|
+
const filtered = this.applyFiltersAndSorting(visibleColumns, rowsWithIndex, state, blockSource, options);
|
|
217
244
|
const totalPages = Math.max(1, Math.ceil(filtered.length / state.pageSize));
|
|
218
245
|
if (state.page < totalPages - 1) {
|
|
219
246
|
state.page += 1;
|
|
247
|
+
persistUiState();
|
|
220
248
|
renderPage();
|
|
221
249
|
}
|
|
222
250
|
});
|
|
@@ -233,9 +261,11 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
233
261
|
root.appendChild(footer);
|
|
234
262
|
const renderPage = () => {
|
|
235
263
|
const sourceRows = isTree && treeModel
|
|
236
|
-
? this.resolveTreeSourceRows(treeModel, visibleColumns, state.expanded, state.search)
|
|
264
|
+
? this.resolveTreeSourceRows(treeModel, visibleColumns, state.expanded, state.search, blockSource, options)
|
|
237
265
|
: rowsWithIndex;
|
|
238
|
-
const filtered = isTree
|
|
266
|
+
const filtered = isTree
|
|
267
|
+
? sourceRows.slice()
|
|
268
|
+
: this.applyFiltersAndSorting(visibleColumns, sourceRows, state, blockSource, options);
|
|
239
269
|
const total = filtered.length;
|
|
240
270
|
const totalTreeRows = isTree
|
|
241
271
|
? (fullyExpandedTreeRows?.length ?? total)
|
|
@@ -243,6 +273,7 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
243
273
|
const totalPages = isTree ? 1 : Math.max(1, Math.ceil(total / state.pageSize));
|
|
244
274
|
if (!isTree && state.page >= totalPages) {
|
|
245
275
|
state.page = totalPages - 1;
|
|
276
|
+
persistUiState();
|
|
246
277
|
}
|
|
247
278
|
const gridTemplateColumns = this.buildGridTemplate(visibleColumns.length, state.columnWidths);
|
|
248
279
|
headerRow.innerHTML = '';
|
|
@@ -270,6 +301,7 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
270
301
|
}
|
|
271
302
|
state.hasUserSort = true;
|
|
272
303
|
state.page = 0;
|
|
304
|
+
persistUiState();
|
|
273
305
|
renderPage();
|
|
274
306
|
});
|
|
275
307
|
}
|
|
@@ -296,6 +328,7 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
296
328
|
const rowContext = createRowContext(baseVisibleColumns, selectorRow);
|
|
297
329
|
for (let columnIndex = 0; columnIndex < visibleColumns.length; columnIndex += 1) {
|
|
298
330
|
const value = rowEntry.cells[columnIndex] ?? '';
|
|
331
|
+
const typedValue = rowEntry.typedCells?.[columnIndex];
|
|
299
332
|
const td = document.createElement('div');
|
|
300
333
|
td.className = 'table-cell';
|
|
301
334
|
const valueElement = this.renderValue(this.formatCellDisplayValue(value, {
|
|
@@ -303,7 +336,7 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
303
336
|
columns: visibleColumns,
|
|
304
337
|
blockSource,
|
|
305
338
|
options,
|
|
306
|
-
}));
|
|
339
|
+
}), typedValue);
|
|
307
340
|
if (isTree && columnIndex === 0) {
|
|
308
341
|
const treeCell = this.renderTreeCell(valueElement, rowEntry, treeModel, state.expanded, () => renderPage());
|
|
309
342
|
td.appendChild(treeCell);
|
|
@@ -370,13 +403,13 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
370
403
|
extractTypeOptions(_blockSource) {
|
|
371
404
|
return [];
|
|
372
405
|
}
|
|
373
|
-
resolveTreeSourceRows(model, columns, expanded, search) {
|
|
406
|
+
resolveTreeSourceRows(model, columns, expanded, search, blockSource, options) {
|
|
374
407
|
if (search) {
|
|
375
|
-
return this.filterTreeRowsBySearch(model, columns, search);
|
|
408
|
+
return this.filterTreeRowsBySearch(model, columns, search, blockSource, options);
|
|
376
409
|
}
|
|
377
410
|
return this.flattenTreeRows(model, expanded);
|
|
378
411
|
}
|
|
379
|
-
filterTreeRowsBySearch(model, columns, search) {
|
|
412
|
+
filterTreeRowsBySearch(model, columns, search, blockSource, options) {
|
|
380
413
|
const fullyExpanded = this.flattenTreeRows(model, new Set(model.expandableNodes));
|
|
381
414
|
const matchedIds = new Set();
|
|
382
415
|
for (const row of fullyExpanded) {
|
|
@@ -384,7 +417,7 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
384
417
|
if (!nodeId) {
|
|
385
418
|
continue;
|
|
386
419
|
}
|
|
387
|
-
if (matchesFilterQuery(columns, row
|
|
420
|
+
if (matchesFilterQuery(columns, this.getDisplayFilterCells(row, columns, blockSource, options), search)) {
|
|
388
421
|
matchedIds.add(nodeId);
|
|
389
422
|
}
|
|
390
423
|
}
|
|
@@ -420,6 +453,7 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
420
453
|
const projectRow = (row) => ({
|
|
421
454
|
...row,
|
|
422
455
|
cells: visibleColumnIndexes.map((columnIndex) => row.cells[columnIndex] ?? ''),
|
|
456
|
+
typedCells: visibleColumnIndexes.map((columnIndex) => row.typedCells?.[columnIndex]),
|
|
423
457
|
});
|
|
424
458
|
for (const row of allRows) {
|
|
425
459
|
const id = row.cells[idColumnIndex] ?? '';
|
|
@@ -464,7 +498,7 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
464
498
|
const syntheticAll = new Array(allColumns.length).fill('');
|
|
465
499
|
syntheticAll[idColumnIndex] = child;
|
|
466
500
|
const synthetic = visibleColumnIndexes.map((columnIndex) => syntheticAll[columnIndex] ?? '');
|
|
467
|
-
const syntheticRow = { index: allRows.length + rowsById.size, cells: synthetic };
|
|
501
|
+
const syntheticRow = { index: allRows.length + rowsById.size, cells: synthetic, typedCells: new Array(visibleColumnIndexes.length).fill(undefined) };
|
|
468
502
|
rowsById.set(child, syntheticRow);
|
|
469
503
|
order.push(child);
|
|
470
504
|
}
|
|
@@ -603,9 +637,9 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
603
637
|
button.appendChild(iconSvg);
|
|
604
638
|
return button;
|
|
605
639
|
}
|
|
606
|
-
applyFiltersAndSorting(columns, rows, state) {
|
|
640
|
+
applyFiltersAndSorting(columns, rows, state, blockSource, options) {
|
|
607
641
|
const filtered = state.search
|
|
608
|
-
? rows.filter((row) => matchesFilterQuery(columns, row
|
|
642
|
+
? rows.filter((row) => matchesFilterQuery(columns, this.getDisplayFilterCells(row, columns, blockSource, options), state.search))
|
|
609
643
|
: rows.slice();
|
|
610
644
|
if (!state.hasUserSort) {
|
|
611
645
|
return filtered;
|
|
@@ -621,6 +655,21 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
621
655
|
return a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' }) * dir;
|
|
622
656
|
});
|
|
623
657
|
}
|
|
658
|
+
getDisplayFilterCells(row, columns, blockSource, options) {
|
|
659
|
+
return columns.map((_, columnIndex) => {
|
|
660
|
+
const raw = row.cells[columnIndex] ?? '';
|
|
661
|
+
const typedValue = row.typedCells?.[columnIndex];
|
|
662
|
+
if (typedValue?.values?.length) {
|
|
663
|
+
return this.formatCellDisplayText(raw, typedValue);
|
|
664
|
+
}
|
|
665
|
+
return this.formatCellDisplayValue(raw, {
|
|
666
|
+
columnIndex,
|
|
667
|
+
columns,
|
|
668
|
+
blockSource,
|
|
669
|
+
options,
|
|
670
|
+
});
|
|
671
|
+
});
|
|
672
|
+
}
|
|
624
673
|
applyStylesheet(cellElement, valueElement, rules, contexts) {
|
|
625
674
|
for (const rule of rules) {
|
|
626
675
|
if (rule.target !== 'value') {
|
|
@@ -755,13 +804,12 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
755
804
|
}
|
|
756
805
|
autosizeColumnWidth(columnIndex, columns, rows, referenceCellOrFont, headerFontOverride) {
|
|
757
806
|
const headerText = `${columns[columnIndex] ?? ''} ▲`;
|
|
758
|
-
const values = rows.map((row) => formatCellDisplayText(row.cells[columnIndex] ?? ''));
|
|
759
807
|
const valueFont = typeof referenceCellOrFont === 'string'
|
|
760
808
|
? referenceCellOrFont
|
|
761
809
|
: this.resolveFont(referenceCellOrFont);
|
|
762
810
|
const headerFont = headerFontOverride ?? valueFont;
|
|
763
|
-
const widestValue =
|
|
764
|
-
const width = this.
|
|
811
|
+
const widestValue = rows.reduce((max, row) => {
|
|
812
|
+
const width = this.measureRenderedCellContentWidth(row, columnIndex, columns, valueFont);
|
|
765
813
|
return Math.max(max, width);
|
|
766
814
|
}, 0);
|
|
767
815
|
const headerWidth = this.measureTextWidth(headerText, headerFont);
|
|
@@ -789,6 +837,34 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
789
837
|
return Math.max(max, prefix);
|
|
790
838
|
}, 0);
|
|
791
839
|
}
|
|
840
|
+
measureRenderedCellContentWidth(row, columnIndex, columns, font) {
|
|
841
|
+
const rawValue = row.cells[columnIndex] ?? '';
|
|
842
|
+
const typedValue = row.typedCells?.[columnIndex];
|
|
843
|
+
const formattedValue = this.formatCellDisplayValue(rawValue, {
|
|
844
|
+
columnIndex,
|
|
845
|
+
columns,
|
|
846
|
+
});
|
|
847
|
+
const valueElement = this.renderValue(formattedValue, typedValue);
|
|
848
|
+
const decorated = this.decorateCellValueElement({
|
|
849
|
+
row: { index: row.index, cells: row.cells },
|
|
850
|
+
columnIndex,
|
|
851
|
+
columns,
|
|
852
|
+
value: rawValue,
|
|
853
|
+
valueElement,
|
|
854
|
+
});
|
|
855
|
+
const probe = document.createElement('div');
|
|
856
|
+
probe.style.position = 'fixed';
|
|
857
|
+
probe.style.left = '-10000px';
|
|
858
|
+
probe.style.top = '-10000px';
|
|
859
|
+
probe.style.visibility = 'hidden';
|
|
860
|
+
probe.style.whiteSpace = 'nowrap';
|
|
861
|
+
probe.style.font = font;
|
|
862
|
+
probe.appendChild(decorated);
|
|
863
|
+
document.body.appendChild(probe);
|
|
864
|
+
const width = probe.getBoundingClientRect().width;
|
|
865
|
+
probe.remove();
|
|
866
|
+
return width;
|
|
867
|
+
}
|
|
792
868
|
resolveFont(referenceCell) {
|
|
793
869
|
const computed = window.getComputedStyle(referenceCell);
|
|
794
870
|
const lineHeight = computed.lineHeight && computed.lineHeight !== 'normal' ? computed.lineHeight : computed.fontSize;
|
|
@@ -806,11 +882,8 @@ export class TableMarkdownBlockRenderer extends QueryMarkdownBlockRenderer {
|
|
|
806
882
|
formatCellDisplayValue(raw, _context) {
|
|
807
883
|
return raw;
|
|
808
884
|
}
|
|
809
|
-
renderValue(raw) {
|
|
810
|
-
|
|
811
|
-
value.className = 'table-value';
|
|
812
|
-
appendTokenizedValueParts(value, raw, 'table-value-part');
|
|
813
|
-
return value;
|
|
885
|
+
renderValue(raw, typedValue) {
|
|
886
|
+
return this.renderCellValue(raw, typedValue);
|
|
814
887
|
}
|
|
815
888
|
createUploadCsvButton(_columns, _rows, _isTree, _blockSource) {
|
|
816
889
|
return undefined;
|
|
@@ -1145,13 +1218,6 @@ function resolveHiddenColumns(columns, columnContexts, rules) {
|
|
|
1145
1218
|
}
|
|
1146
1219
|
return hidden;
|
|
1147
1220
|
}
|
|
1148
|
-
function formatCellDisplayText(raw) {
|
|
1149
|
-
const parts = raw.split(/[\s,]+/).filter((entry) => entry.length > 0);
|
|
1150
|
-
if (parts.length === 0) {
|
|
1151
|
-
return raw;
|
|
1152
|
-
}
|
|
1153
|
-
return parts.map((part) => isIriValue(part) ? shortLabelFromIri(part) : part).join(' ');
|
|
1154
|
-
}
|
|
1155
1221
|
function matchesFilterQuery(columns, cells, rawQuery) {
|
|
1156
1222
|
const terms = parseFilterTerms(rawQuery);
|
|
1157
1223
|
if (terms.length === 0) {
|