@gramlot/gramlot 0.3.24 → 0.3.27
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/components/chat/__init__.py +1 -1
- package/dist/components/chat/assets/collection.js +3 -3
- package/dist/components/chat/assets/index.js +1 -1
- package/dist/components/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +21 -20
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/modules/chunk-74O4WKIV.js +1 -0
- package/dist/components/editors/assets/modules/{code-mirror-engine-QX4A5FVO.js → code-mirror-engine-RWQTR5G5.js} +29 -29
- package/dist/components/editors/assets/modules/{jodit-engine-MMSPIWM7.js → jodit-engine-MTSA4GZ3.js} +292 -292
- package/dist/components/editors/assets/modules/markdown-document-VFC23FAY.js +1 -0
- package/dist/components/editors/assets/modules/{prose-mirror-engine-IXTRTG6B.js → prose-mirror-engine-GMZPJPNN.js} +13 -13
- package/dist/components/grid/__init__.py +3 -2
- package/dist/components/grid/assets/collection.js +77 -17
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +78 -1
- package/dist/components/grouplets/__init__.py +2 -2
- package/dist/components/grouplets/assets/collection.js +3 -20
- package/dist/components/grouplets/assets/index.js +1 -1
- package/dist/components/grouplets/assets/modules/chunk-BLMUM44K.js +1 -0
- package/dist/components/grouplets/assets/modules/markdown-document-YWNZTOKK.js +1 -0
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +59 -34
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +64 -0
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +67 -57
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +35 -0
- package/dist/components/selection_trial/__init__.py +1 -1
- package/dist/components/selection_trial/assets/collection.js +3 -3
- package/dist/components/selection_trial/assets/index.js +1 -1
- package/dist/components/selection_trial/grammar.json +35 -0
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +26 -23
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +341 -1
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +3 -3
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/components/uploads/__init__.py +13 -0
- package/dist/components/uploads/assets/collection.js +67 -0
- package/dist/components/uploads/assets/index.js +3 -0
- package/dist/components/uploads/commands.json +7 -0
- package/dist/components/uploads/grammar.json +789 -0
- package/dist/{components/editors/assets/modules/chunk-OCFLP2K4.js → gramlot-markdown.js} +12 -12
- package/dist/gramlot.js +5455 -573
- package/dist/gramlot.min.js +1588 -43
- package/dist/runtime-notices.json +28 -0
- package/package.json +4 -2
- package/src/binding/grid-struct.js +1 -1
- package/src/binding/providers.js +4 -1
- package/src/binding/remote-resolver.js +1 -8
- package/src/binding/runtime.js +40 -1
- package/src/binding/validation-context.js +41 -0
- package/src/browser-camera-provider.d.ts +8 -0
- package/src/browser-camera-provider.js +104 -0
- package/src/builder/source.js +13 -2
- package/src/components/attachment-manager.js +160 -0
- package/src/components/bases.js +19 -6
- package/src/components/border-container.js +86 -8
- package/src/components/buttons.js +11 -1
- package/src/components/choice-editor.js +44 -16
- package/src/components/database-choices.js +13 -8
- package/src/components/editing-status-styles.js +26 -0
- package/src/components/editing-status.js +115 -0
- package/src/components/field-state.js +44 -58
- package/src/components/grid-cell-editor.js +245 -0
- package/src/components/grid-grammar.json +42 -0
- package/src/components/grid-structure.js +5 -1
- package/src/components/grid-styles.js +60 -1
- package/src/components/grid.js +103 -11
- package/src/components/grouplet-card.js +11 -3
- package/src/components/html-preview.js +17 -4
- package/src/components/image-crop-dialog.js +272 -0
- package/src/components/image-crop.js +79 -0
- package/src/components/image-uploader.js +252 -0
- package/src/components/inputs.js +4 -3
- package/src/components/jodit-engine.js +1 -1
- package/src/components/markdown-document.js +2 -2
- package/src/components/parameters.js +6 -2
- package/src/components/screen-capture.js +43 -0
- package/src/components/selected-container.js +6 -2
- package/src/components/tree.js +417 -17
- package/src/components/typed-editor.js +19 -9
- package/src/components/upload-engine.js +156 -0
- package/src/components/uploader.js +208 -0
- package/src/components/uploads.js +7 -0
- package/src/components/validation.js +1 -1
- package/src/editing-session.d.ts +26 -0
- package/src/editing-session.js +494 -0
- package/src/editor-values.js +57 -0
- package/src/experiments/selection-trial.js +18 -2
- package/src/format.js +22 -7
- package/src/gramlot.d.ts +3 -0
- package/src/gramlot.js +9 -5
- package/src/handlers/device-handler.d.ts +2 -1
- package/src/handlers/rpc-handler.d.ts +3 -3
- package/src/index-page-styles.js +1 -0
- package/src/index.d.ts +14 -1
- package/src/index.js +13 -0
- package/src/inout.d.ts +2 -0
- package/src/inout.js +6 -0
- package/src/markdown-loader.d.ts +1 -0
- package/src/markdown-loader.js +4 -0
- package/src/markdown.d.ts +1 -0
- package/src/markdown.js +2 -0
- package/src/media-frame.js +9 -0
- package/src/renderer/attributes.js +7 -1
- package/src/renderer/gramlot-renderer.d.ts +3 -0
- package/src/renderer/gramlot-renderer.js +42 -2
- package/src/server/assets.d.ts +1 -1
- package/src/server/assets.js +1 -1
- package/src/server/gramlot-server.d.ts +8 -1
- package/src/server/gramlot-server.js +83 -7
- package/src/server/index.d.ts +2 -0
- package/src/server/index.js +2 -0
- package/src/server/page-base.js +17 -4
- package/src/server/page.d.ts +13 -1
- package/src/server/page.js +6 -0
- package/src/server/source-import.d.ts +2 -0
- package/src/server/source-import.js +35 -0
- package/src/server/upload.d.ts +20 -0
- package/src/server/upload.js +142 -0
- package/src/server/visual-editor.d.ts +11 -0
- package/src/server/visual-editor.js +159 -0
- package/src/source-picker.d.ts +9 -0
- package/src/source-picker.js +56 -0
- package/src/tree-store.d.ts +24 -0
- package/src/tree-store.js +193 -0
- package/src/validation-run.js +50 -0
- package/src/view/button.js +8 -5
- package/src/view/controls.js +9 -42
- package/src/view/html.js +10 -2
- package/src/visual-editor-canvas.js +29 -0
- package/src/visual-editor-catalogue.js +34 -0
- package/src/visual-editor-icons.js +10 -0
- package/src/visual-editor.d.ts +61 -0
- package/src/visual-editor.js +1062 -0
- package/themes/gramlot-base/theme.css +141 -0
- package/tools/gramlot-tools-inspector.js +1 -1
- package/tools/inspector-agent.js +1 -1
- package/dist/components/editors/assets/modules/chunk-MMJXUHRQ.js +0 -3
- package/src/form-state.d.ts +0 -20
- package/src/form-state.js +0 -198
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
* A JS stylesheet module keeps the same source usable in Node and browser builds.
|
|
3
3
|
*/
|
|
4
4
|
export const gridStyles = `
|
|
5
|
+
.control-box{position:relative}
|
|
6
|
+
.cell-editor{
|
|
7
|
+
position:absolute;z-index:4;height:min(var(--grid-editor-height),var(--grid-cell-max-height,var(--grid-editor-height)));
|
|
8
|
+
background:var(--gramlot-grid-background,var(--gramlot-surface,Canvas));
|
|
9
|
+
--gramlot-field-height:0px;
|
|
10
|
+
--gramlot-field-block-size:min(var(--grid-editor-height),var(--grid-cell-max-height,var(--grid-editor-height)));
|
|
11
|
+
--gramlot-field-padding:var(--gramlot-grid-cell-padding,.3rem .6rem);
|
|
12
|
+
--gramlot-field-font-size:1em;
|
|
13
|
+
--gramlot-field-line-height:var(--gramlot-grid-line-height,1.35);
|
|
14
|
+
--gramlot-field-radius:0px;
|
|
15
|
+
--gramlot-field-focus-outline:1px solid var(--gramlot-focus-ring,Highlight);
|
|
16
|
+
--gramlot-field-focus-offset:-1px;
|
|
17
|
+
--gramlot-field-resize:none;
|
|
18
|
+
}
|
|
19
|
+
.cell-editor[hidden]{display:none}
|
|
20
|
+
.invalid-cell{background:var(--gramlot-error-background,#fff1f0)!important}
|
|
21
|
+
.draft-cell{box-shadow:inset 0 -2px var(--gramlot-warning,#805600)}
|
|
22
|
+
|
|
5
23
|
:host {
|
|
6
24
|
min-block-size: 0;
|
|
7
25
|
color: var(--gramlot-grid-color, var(--gramlot-ink, CanvasText));
|
|
@@ -27,10 +45,42 @@ export const gridStyles = `
|
|
|
27
45
|
border-block-end: 1px solid var(--gramlot-grid-border-color, var(--gramlot-border, ButtonBorder));
|
|
28
46
|
}
|
|
29
47
|
.header-viewport { overflow: hidden; min-inline-size: 0; }
|
|
30
|
-
.body-
|
|
48
|
+
.body-frame {
|
|
31
49
|
flex: 1 1 auto;
|
|
32
50
|
min-block-size: 0;
|
|
33
51
|
min-inline-size: 0;
|
|
52
|
+
display: grid;
|
|
53
|
+
grid-template: minmax(0, 1fr) / minmax(0, 1fr);
|
|
54
|
+
}
|
|
55
|
+
.loading-status {
|
|
56
|
+
grid-area: 1 / 1;
|
|
57
|
+
place-self: center;
|
|
58
|
+
z-index: 3;
|
|
59
|
+
padding: .5rem;
|
|
60
|
+
border-radius: 50%;
|
|
61
|
+
background: var(--gramlot-grid-background, var(--gramlot-surface, Canvas));
|
|
62
|
+
color: var(--gramlot-text-secondary, GrayText);
|
|
63
|
+
pointer-events: none;
|
|
64
|
+
opacity: 0;
|
|
65
|
+
animation: grid-loading-reveal 0s 200ms forwards;
|
|
66
|
+
}
|
|
67
|
+
.loading-status svg {
|
|
68
|
+
display: block;
|
|
69
|
+
inline-size: 1.5rem;
|
|
70
|
+
block-size: 1.5rem;
|
|
71
|
+
fill: none;
|
|
72
|
+
stroke: currentColor;
|
|
73
|
+
stroke-width: 2;
|
|
74
|
+
stroke-linecap: round;
|
|
75
|
+
animation: grid-loading-spin .9s linear infinite;
|
|
76
|
+
}
|
|
77
|
+
@keyframes grid-loading-reveal { to { opacity: 1; } }
|
|
78
|
+
@keyframes grid-loading-spin { to { transform: rotate(360deg); } }
|
|
79
|
+
@media (prefers-reduced-motion: reduce) { .loading-status svg { animation: none; } }
|
|
80
|
+
.body-viewport {
|
|
81
|
+
grid-area: 1 / 1;
|
|
82
|
+
min-block-size: 0;
|
|
83
|
+
min-inline-size: 0;
|
|
34
84
|
overflow: auto;
|
|
35
85
|
background: var(--gramlot-surface-subtle, Canvas);
|
|
36
86
|
scrollbar-gutter: stable;
|
|
@@ -90,6 +140,15 @@ export const gridStyles = `
|
|
|
90
140
|
block-size: var(--gramlot-grid-row-height, 2rem);
|
|
91
141
|
border-block-end: 1px solid var(--gramlot-grid-row-border-color, var(--gramlot-border, ButtonBorder));
|
|
92
142
|
}
|
|
143
|
+
td[data-field] { padding: 0; }
|
|
144
|
+
.cell-content {
|
|
145
|
+
padding: var(--gramlot-grid-cell-padding, .3rem .6rem);
|
|
146
|
+
overflow: hidden;
|
|
147
|
+
text-overflow: ellipsis;
|
|
148
|
+
max-height: var(--grid-cell-max-height, none);
|
|
149
|
+
}
|
|
150
|
+
.cell-scroll { overflow: auto; overscroll-behavior: contain; }
|
|
151
|
+
.cell-scroll:focus-visible { outline: 1px solid var(--gramlot-focus-ring, Highlight); outline-offset: -1px; }
|
|
93
152
|
tbody tr { background: var(--gramlot-grid-background, var(--gramlot-surface, Canvas)); }
|
|
94
153
|
tbody tr.alternate { background: var(--gramlot-grid-row-alt-background, var(--gramlot-surface-subtle, Canvas)); }
|
|
95
154
|
tbody tr:hover { background: var(--gramlot-grid-row-hover-background, var(--gramlot-selected, Highlight)); }
|
package/src/components/grid.js
CHANGED
|
@@ -3,6 +3,8 @@ import {SVG_NS} from '../renderer/attributes.js';
|
|
|
3
3
|
import {defineComponent, ComponentCollection} from './registry.js';
|
|
4
4
|
import {Container} from './container.js';
|
|
5
5
|
import {parseSort} from '../stores/bag-collection-view.js';
|
|
6
|
+
import inputs from './inputs.js';
|
|
7
|
+
import {GridCellEditor} from './grid-cell-editor.js';
|
|
6
8
|
import {GridRows} from './grid-rows.js';
|
|
7
9
|
import {GridStructure} from './grid-structure.js';
|
|
8
10
|
import {GridHeaderInteraction} from './grid-header-interaction.js';
|
|
@@ -15,8 +17,9 @@ import structureGrammar from './grid-grammar.json' with {type: 'json'};
|
|
|
15
17
|
|
|
16
18
|
/** First grid: explicit Bag row representation and a separately observable Data struct. */
|
|
17
19
|
export const Grid = defineComponent({
|
|
18
|
-
name: 'grid', tag: 'gramlot-grid', base: Container, bagStore: true, bagStruct: true, sourceContext: true, subTags: 'struct',
|
|
20
|
+
name: 'grid', tag: 'gramlot-grid', base: Container, bagStore: true, bagStruct: true, sourceContext: true, subTags: 'struct,div',
|
|
19
21
|
parameters: {windowInfo: {dtype:'X', nullable:true, default:null, binding:'read'},
|
|
22
|
+
loading: {dtype:'B', default:false, binding:'read'},
|
|
20
23
|
viewport: {dtype:'X', nullable:true, default:null, binding:'write'},
|
|
21
24
|
sortRequest: {dtype:'T', default:'', binding:'write'},
|
|
22
25
|
storepath: {dtype: 'T'}, structpath: {dtype: 'T'}, rowMode: {dtype: 'T'},
|
|
@@ -27,6 +30,19 @@ export const Grid = defineComponent({
|
|
|
27
30
|
filter: {annotation:{kind:'type',module:'builtins',name:'dict'}, nullable:true, default:null, binding:'read'}},
|
|
28
31
|
implementation: Base => class extends Base {
|
|
29
32
|
#store;
|
|
33
|
+
#cellEditor;
|
|
34
|
+
#editCell = event => {
|
|
35
|
+
if (event.type === 'keydown' && !['Enter','F2'].includes(event.key)) return;
|
|
36
|
+
const cell = event.target.closest('td[data-field]');
|
|
37
|
+
if (!cell || !this.#structure) return;
|
|
38
|
+
const row = [...this.#rows].find(([, tr]) => tr === cell.parentElement)?.[0];
|
|
39
|
+
const column = this.#structure.columns.find(column => column.field === cell.dataset.field);
|
|
40
|
+
if (row && column.edit) {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
try { this.#cellEditor.open(row, column, cell); }
|
|
43
|
+
catch (error) { this.#context.reportError(error,'Grid editor'); }
|
|
44
|
+
}
|
|
45
|
+
};
|
|
30
46
|
#windowRevision;
|
|
31
47
|
#windowRequest;
|
|
32
48
|
#context;
|
|
@@ -41,6 +57,7 @@ export const Grid = defineComponent({
|
|
|
41
57
|
#bodyTable;
|
|
42
58
|
#headerViewport;
|
|
43
59
|
#bodyViewport;
|
|
60
|
+
#loadingStatus;
|
|
44
61
|
#resizeObserver;
|
|
45
62
|
#layoutFrame = null;
|
|
46
63
|
#headerRows = 1;
|
|
@@ -112,7 +129,22 @@ export const Grid = defineComponent({
|
|
|
112
129
|
space.className = 'row-space'; space.setAttribute('aria-hidden', 'true');
|
|
113
130
|
}
|
|
114
131
|
this.#bodyViewport.append(this.#topSpace, this.#bodyTable, this.#bottomSpace);
|
|
115
|
-
|
|
132
|
+
const bodyFrame = doc.createElement('div'); bodyFrame.className = 'body-frame';
|
|
133
|
+
this.#loadingStatus = doc.createElement('div');
|
|
134
|
+
this.#loadingStatus.className = 'loading-status';
|
|
135
|
+
this.#loadingStatus.setAttribute('role', 'status');
|
|
136
|
+
this.#loadingStatus.setAttribute('aria-label', 'Loading…');
|
|
137
|
+
this.#loadingStatus.hidden = true;
|
|
138
|
+
const spinner = doc.createElementNS(SVG_NS, 'svg');
|
|
139
|
+
spinner.setAttribute('viewBox', '0 0 24 24'); spinner.setAttribute('aria-hidden', 'true');
|
|
140
|
+
const track = doc.createElementNS(SVG_NS, 'circle');
|
|
141
|
+
track.setAttribute('cx', '12'); track.setAttribute('cy', '12'); track.setAttribute('r', '9');
|
|
142
|
+
track.setAttribute('opacity', '.2');
|
|
143
|
+
const arc = doc.createElementNS(SVG_NS, 'path');
|
|
144
|
+
arc.setAttribute('d', 'M12 3a9 9 0 0 1 9 9');
|
|
145
|
+
spinner.append(track, arc); this.#loadingStatus.append(spinner);
|
|
146
|
+
bodyFrame.append(this.#bodyViewport, this.#loadingStatus);
|
|
147
|
+
this.control.replaceChildren(headerFrame, bodyFrame); this.shadowRoot.append(style);
|
|
116
148
|
this.#interaction = new GridHeaderInteraction(this.#head, this.control, () => this.#structure, (field, multiple) => this.#sort(field, multiple),
|
|
117
149
|
() => this.#rowLayout, () => this.#scheduleLayout());
|
|
118
150
|
this.#rowInteraction = new GridRowInteraction(this.#body, this.control, () => this.#rowLayout, row => {
|
|
@@ -122,6 +154,9 @@ export const Grid = defineComponent({
|
|
|
122
154
|
this.#resizeObserver = new doc.defaultView.ResizeObserver(() => this.#scheduleLayout());
|
|
123
155
|
}
|
|
124
156
|
connectedCallback() {
|
|
157
|
+
this.#body.addEventListener('dblclick', this.#editCell);
|
|
158
|
+
this.#body.addEventListener('keydown', this.#editCell);
|
|
159
|
+
this.#cellEditor?.connect();
|
|
125
160
|
this.#observeStore();
|
|
126
161
|
if (this.#collectionView) this.#invalidate({full:true, rows:[]});
|
|
127
162
|
this.#interaction.connect();
|
|
@@ -133,6 +168,9 @@ export const Grid = defineComponent({
|
|
|
133
168
|
this.#scheduleLayout();
|
|
134
169
|
}
|
|
135
170
|
disconnectedCallback() {
|
|
171
|
+
this.#body.removeEventListener('dblclick', this.#editCell);
|
|
172
|
+
this.#body.removeEventListener('keydown', this.#editCell);
|
|
173
|
+
this.#cellEditor?.disconnect();
|
|
136
174
|
this.#cancelRefresh();
|
|
137
175
|
this.#collectionView?.disconnect();
|
|
138
176
|
this.#unsubscribeStore?.(); this.#unsubscribeStore = null;
|
|
@@ -163,7 +201,7 @@ export const Grid = defineComponent({
|
|
|
163
201
|
}
|
|
164
202
|
this.#headerViewport.scrollLeft = this.#bodyViewport.scrollLeft;
|
|
165
203
|
if (!this.#structure) return;
|
|
166
|
-
try { this.#layoutWindow(); }
|
|
204
|
+
try { this.#layoutWindow(); this.#cellEditor.position(); }
|
|
167
205
|
catch (error) { this.#context.reportError(error, 'Grid viewport'); }
|
|
168
206
|
});
|
|
169
207
|
}
|
|
@@ -231,14 +269,15 @@ export const Grid = defineComponent({
|
|
|
231
269
|
this.#windowRequest = key;
|
|
232
270
|
this.#context.writeParameter('viewport', {start:requestedStart, count});
|
|
233
271
|
}
|
|
234
|
-
|
|
235
|
-
} else {
|
|
236
|
-
this.#windowRequest = null;
|
|
237
|
-
this.control.removeAttribute('aria-busy');
|
|
238
|
-
}
|
|
272
|
+
} else this.#windowRequest = null;
|
|
239
273
|
start = Math.max(start, info.start);
|
|
240
274
|
end = Math.max(start, Math.min(end, loadedEnd));
|
|
241
275
|
}
|
|
276
|
+
if (!info) this.#windowRequest = null;
|
|
277
|
+
const loading = this.parameters.loading || this.#windowRequest !== null;
|
|
278
|
+
this.#loadingStatus.hidden = !loading;
|
|
279
|
+
if (loading) this.control.setAttribute('aria-busy', 'true');
|
|
280
|
+
else this.control.removeAttribute('aria-busy');
|
|
242
281
|
if (force || start !== this.#windowStart || end !== this.#windowEnd) {
|
|
243
282
|
const rows = new GridRows(this.#collectionView, this.#context.format)
|
|
244
283
|
.read(this.#structure.columns, this.#visibleNodes.slice(start-(info?.start ?? 0), end-(info?.start ?? 0)));
|
|
@@ -255,8 +294,47 @@ export const Grid = defineComponent({
|
|
|
255
294
|
if (!(value instanceof Bag)) throw new TypeError('Grid windowInfo requires a Bag');
|
|
256
295
|
return Object.fromEntries(['start', 'total', 'revision', 'sortedBy'].map(key => [key, value.getItem(key)]));
|
|
257
296
|
}
|
|
297
|
+
#nextEditor(row,field,step) {
|
|
298
|
+
const rows = this.#collectionView.getRows(), columns = this.#structure.columns.filter(column => column.edit);
|
|
299
|
+
const index = rows.indexOf(row) * columns.length + columns.findIndex(column => column.field === field) + (typeof step === 'object' ? step.row * columns.length : step);
|
|
300
|
+
if (index < 0 || index >= rows.length * columns.length) return;
|
|
301
|
+
this.#openEditorAt(Math.floor(index / columns.length),columns[index % columns.length]);
|
|
302
|
+
}
|
|
303
|
+
#openEditorAt(rowIndex,column) {
|
|
304
|
+
const next = this.#collectionView.getRows()[rowIndex];
|
|
305
|
+
this.#endPinned = false;
|
|
306
|
+
const top = this.#rowLayout.offset(rowIndex), bottom = this.#rowLayout.offset(rowIndex + 1);
|
|
307
|
+
if (top < this.#bodyViewport.scrollTop) this.#scrollTo(top);
|
|
308
|
+
else if (bottom > this.#bodyViewport.scrollTop + this.#bodyViewport.clientHeight) this.#scrollTo(Math.max(0,bottom-this.#bodyViewport.clientHeight));
|
|
309
|
+
this.#renderWindow(true);
|
|
310
|
+
// An unseen row still has an estimated height. Measure the materialized window
|
|
311
|
+
// before revealing its cell, so opening an error cannot leave it below the viewport.
|
|
312
|
+
this.#layoutWindow();
|
|
313
|
+
const cell = this.#rows.get(next).querySelector(`td[data-field="${column.field}"]`);
|
|
314
|
+
const rect = cell.getBoundingClientRect(), viewport = this.#bodyViewport.getBoundingClientRect();
|
|
315
|
+
if (rect.top < viewport.top) this.#scrollTo(Math.floor(this.#bodyViewport.scrollTop + rect.top-viewport.top));
|
|
316
|
+
else if (rect.bottom > viewport.bottom) this.#scrollTo(Math.ceil(this.#bodyViewport.scrollTop + Math.min(rect.top-viewport.top,rect.bottom-viewport.bottom)));
|
|
317
|
+
if (rect.left < viewport.left) this.#bodyViewport.scrollLeft += rect.left-viewport.left;
|
|
318
|
+
else if (rect.right > viewport.right) this.#bodyViewport.scrollLeft += Math.min(rect.left-viewport.left,rect.right-viewport.right);
|
|
319
|
+
this.#headerViewport.scrollLeft = this.#bodyViewport.scrollLeft;
|
|
320
|
+
this.#cellEditor.open(next,column,cell);
|
|
321
|
+
}
|
|
322
|
+
#focusField(path) {
|
|
323
|
+
const prefix = this.#context.sourceNode.absDatapath(this.parameters.storepath) + '.';
|
|
324
|
+
if (!path.startsWith(prefix)) return false;
|
|
325
|
+
const relative = path.slice(prefix.length), separator = this.parameters.rowMode === 'attributes' ? '?' : '.';
|
|
326
|
+
const split = relative.indexOf(separator);
|
|
327
|
+
if (split < 0) return false;
|
|
328
|
+
const row = this.#store.getNode(relative.slice(0,split));
|
|
329
|
+
const column = this.#structure.columns.find(column => column.field === relative.slice(split+1) && column.edit);
|
|
330
|
+
const index = this.#collectionView.getRows().indexOf(row);
|
|
331
|
+
if (!column || index < 0) return false;
|
|
332
|
+
this.#openEditorAt(index,column);
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
258
335
|
setSourceContext(context) {
|
|
259
336
|
this.#context = context;
|
|
337
|
+
this.#cellEditor = new GridCellEditor(this, context, (row, field) => this.#rows.get(row)?.querySelector(`td[data-field="${field}"]`), () => ({bag:this.#store, mode:this.parameters.rowMode, window:this.parameters.windowInfo}), () => this.#rows, (row,field,step) => this.#nextEditor(row,field,step), path => this.#focusField(path));
|
|
260
338
|
const node = context.sourceNode;
|
|
261
339
|
if (!Object.hasOwn(node, 'gridRowLayout')) {
|
|
262
340
|
Object.defineProperty(node, 'gridRowLayout', {value:new GridRowLayout(), configurable:true});
|
|
@@ -265,6 +343,7 @@ export const Grid = defineComponent({
|
|
|
265
343
|
}
|
|
266
344
|
setStoreBag(bag) {
|
|
267
345
|
if (!(bag instanceof Bag)) throw new TypeError('grid storepath must resolve to a Bag');
|
|
346
|
+
if (bag !== this.#store) this.#cellEditor?.replaceData();
|
|
268
347
|
this.#store = bag;
|
|
269
348
|
this.#rowLayout.bindStore(bag);
|
|
270
349
|
}
|
|
@@ -333,6 +412,7 @@ export const Grid = defineComponent({
|
|
|
333
412
|
}
|
|
334
413
|
#project() {
|
|
335
414
|
const model = this.#structureDirty ? new GridStructure(this.#structBag) : this.#structure;
|
|
415
|
+
this.#cellEditor.configure(model.columns);
|
|
336
416
|
const nodes = this.#collectionView.getRows();
|
|
337
417
|
this.#rowInteraction.cancel(); this.#rowInteraction.cancelDrag();
|
|
338
418
|
this.#rowLayout.retain(this.#store.getNodes());
|
|
@@ -538,7 +618,17 @@ export const Grid = defineComponent({
|
|
|
538
618
|
if (!td) {
|
|
539
619
|
td = this.ownerDocument.createElement('td'); td.setAttribute('part', 'cell');
|
|
540
620
|
td.dataset.field = column.field; td.setAttribute('role', 'cell');
|
|
621
|
+
const content = this.ownerDocument.createElement('div');
|
|
622
|
+
content.className = 'cell-content'; content.setAttribute('part','cell-content');
|
|
623
|
+
td.append(content);
|
|
541
624
|
}
|
|
625
|
+
if (column.edit) td.tabIndex = 0; else td.removeAttribute('tabindex');
|
|
626
|
+
const content = td.firstElementChild;
|
|
627
|
+
const capped = column.max_height != null;
|
|
628
|
+
if (capped) td.style.setProperty('--grid-cell-max-height',column.max_height);
|
|
629
|
+
else td.style.removeProperty('--grid-cell-max-height');
|
|
630
|
+
content.classList.toggle('cell-scroll',capped);
|
|
631
|
+
if (capped) content.tabIndex = 0; else content.removeAttribute('tabindex');
|
|
542
632
|
td.style.textAlign = column.align;
|
|
543
633
|
td.style.whiteSpace = column.white_space ?? '';
|
|
544
634
|
td.style.overflowWrap = column.white_space === 'pre-wrap' || column.white_space === 'normal' ? 'anywhere' : '';
|
|
@@ -550,13 +640,14 @@ export const Grid = defineComponent({
|
|
|
550
640
|
for (const td of existing.values()) td.remove();
|
|
551
641
|
tr.setAttribute('aria-rowindex', String(this.#headerRows + start + keep.size + 1));
|
|
552
642
|
this.#renderCells(tr, cells);
|
|
643
|
+
this.#cellEditor.decorate(tr, node);
|
|
553
644
|
const next = previous ? previous.nextSibling : this.#body.firstChild;
|
|
554
645
|
if (next !== tr) this.#body.insertBefore(tr, next);
|
|
555
646
|
this.#rowInteraction.project(tr, node);
|
|
556
647
|
previous = tr; keep.add(node);
|
|
557
648
|
}
|
|
558
649
|
for (const [node, tr] of this.#rows) if (!keep.has(node)) { tr.remove(); this.#rows.delete(node); }
|
|
559
|
-
if (!rows.length) {
|
|
650
|
+
if (!rows.length && this.#rowLayout.count === 0 && !this.parameters.loading) {
|
|
560
651
|
const tr = this.ownerDocument.createElement('tr'), td = this.ownerDocument.createElement('td');
|
|
561
652
|
tr.setAttribute('role', 'row'); tr.setAttribute('aria-rowindex', String(this.#headerRows + 1));
|
|
562
653
|
td.setAttribute('role', 'cell'); td.setAttribute('aria-colspan', String(columns.length + Number(this.#rowHeaders)));
|
|
@@ -566,7 +657,8 @@ export const Grid = defineComponent({
|
|
|
566
657
|
#renderCells(row, cells) {
|
|
567
658
|
const offset = Number(this.#rowHeaders);
|
|
568
659
|
cells.forEach((text, index) => {
|
|
569
|
-
|
|
660
|
+
const content = row.cells[index + offset].firstElementChild;
|
|
661
|
+
if (content.textContent !== text) content.textContent = text;
|
|
570
662
|
});
|
|
571
663
|
}
|
|
572
664
|
}
|
|
@@ -586,4 +678,4 @@ class GridCollection extends ComponentCollection {
|
|
|
586
678
|
return document;
|
|
587
679
|
}
|
|
588
680
|
}
|
|
589
|
-
export default new GridCollection({name: 'grid', components: [Grid, SearchBox]});
|
|
681
|
+
export default new GridCollection({name: 'grid', components: [Grid, SearchBox], dependencies:[inputs]});
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import {defineComponent} from './registry.js';
|
|
3
3
|
import {Container} from './container.js';
|
|
4
4
|
import {labelboxContent} from '../view/labelbox.js';
|
|
5
|
-
import {markdownRenderer} from './markdown-document.js';
|
|
6
5
|
import {positionPopup} from './popup.js';
|
|
7
6
|
|
|
8
7
|
export const GroupletCard = defineComponent({
|
|
@@ -26,6 +25,7 @@ export const GroupletCard = defineComponent({
|
|
|
26
25
|
#ownMenu;
|
|
27
26
|
#docEvents;
|
|
28
27
|
#docText;
|
|
28
|
+
#markdown;
|
|
29
29
|
constructor() {
|
|
30
30
|
super();
|
|
31
31
|
const doc = this.ownerDocument;
|
|
@@ -359,9 +359,16 @@ export const GroupletCard = defineComponent({
|
|
|
359
359
|
this.docButton.hidden = !present;
|
|
360
360
|
this.docButton.setAttribute('aria-label', `Guide for ${this.parameters.title || 'card'}`);
|
|
361
361
|
this.docTitle.textContent = this.parameters.title || 'Card guide';
|
|
362
|
-
if (this.#
|
|
362
|
+
if (this.#docEvents && !this.#markdown && !this.docReady) {
|
|
363
|
+
this.docReady = import('./markdown-document.js').then(module => {
|
|
364
|
+
this.#markdown = module.markdownRenderer;
|
|
365
|
+
if (this.isConnected && this.#docEvents) this.refreshDoc();
|
|
366
|
+
});
|
|
367
|
+
this.docReady.catch(error => console.error(error));
|
|
368
|
+
}
|
|
369
|
+
if (this.#docEvents && this.#markdown && this.#docText !== content) {
|
|
363
370
|
// The shared Markdown renderer escapes raw HTML and rejects unsafe URL schemes.
|
|
364
|
-
this.docBody.innerHTML =
|
|
371
|
+
this.docBody.innerHTML = this.#markdown.render(content);
|
|
365
372
|
this.#docText = content;
|
|
366
373
|
}
|
|
367
374
|
if (this.#docEvents) positionPopup(this.docPopup, this.docButton, {align: 'end'});
|
|
@@ -373,6 +380,7 @@ export const GroupletCard = defineComponent({
|
|
|
373
380
|
if (this.#docEvents) return;
|
|
374
381
|
this.docPopup.showPopover();
|
|
375
382
|
this.#docEvents = new this.ownerDocument.defaultView.AbortController();
|
|
383
|
+
this.refreshDoc();
|
|
376
384
|
const options = {signal: this.#docEvents.signal};
|
|
377
385
|
const place = () => positionPopup(this.docPopup, this.docButton, {align: 'end'});
|
|
378
386
|
this.ownerDocument.addEventListener('keydown', event => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {defineComponent} from './registry.js';
|
|
2
2
|
import {projectParameters} from './parameters.js';
|
|
3
|
-
import {renderMarkdownDocument} from './markdown-document.js';
|
|
4
3
|
|
|
5
4
|
function PreviewElement(HTMLElement) {
|
|
6
5
|
return class extends HTMLElement {
|
|
@@ -15,10 +14,13 @@ function PreviewElement(HTMLElement) {
|
|
|
15
14
|
root.append(style,this.frame);
|
|
16
15
|
}
|
|
17
16
|
renderDocument(value) {return value;}
|
|
18
|
-
|
|
19
|
-
const rest=projectParameters(this,attrs);
|
|
17
|
+
render() {
|
|
20
18
|
const html=this.renderDocument(this.parameters.value);
|
|
21
19
|
if (this.frame.srcdoc !== html) this.frame.srcdoc=html;
|
|
20
|
+
}
|
|
21
|
+
projectAttributes(attrs) {
|
|
22
|
+
const rest=projectParameters(this,attrs);
|
|
23
|
+
this.render();
|
|
22
24
|
return rest;
|
|
23
25
|
}
|
|
24
26
|
};
|
|
@@ -28,6 +30,17 @@ export const HtmlPreview=defineComponent({name:'htmlPreview',tag:'gramlot-html-p
|
|
|
28
30
|
|
|
29
31
|
export const MarkdownPreview=defineComponent({name:'markdownPreview',tag:'gramlot-markdown-preview',base:PreviewElement,
|
|
30
32
|
parameters:{value:{dtype:'T',default:'',binding:'read'},allowHtml:{dtype:'B',default:false,binding:'read'}},implementation:Base=>class extends Base {
|
|
33
|
+
#renderDocument;
|
|
31
34
|
constructor(){super();this.frame.title='Markdown preview';}
|
|
32
|
-
|
|
35
|
+
connectedCallback(){this.render();}
|
|
36
|
+
render() {
|
|
37
|
+
if (this.#renderDocument) {super.render();return;}
|
|
38
|
+
if (this.ready) return;
|
|
39
|
+
this.ready=import('./markdown-document.js').then(module=>{
|
|
40
|
+
this.#renderDocument=module.renderMarkdownDocument;
|
|
41
|
+
if(this.isConnected) this.render();
|
|
42
|
+
});
|
|
43
|
+
this.ready.catch(error=>console.error(error));
|
|
44
|
+
}
|
|
45
|
+
renderDocument(value){return this.#renderDocument(value,{allowHtml:this.parameters.allowHtml,document:this.ownerDocument});}
|
|
33
46
|
}});
|