@gramlot/gramlot 0.3.24 → 0.3.26
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/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +20 -19
- 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 +68 -17
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +57 -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/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 +4910 -566
- package/dist/gramlot.min.js +1587 -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 +40 -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 +17 -6
- package/src/components/border-container.js +86 -8
- package/src/components/buttons.js +11 -1
- package/src/components/choice-editor.js +20 -7
- package/src/components/database-choices.js +4 -2
- package/src/components/editing-status-styles.js +26 -0
- package/src/components/editing-status.js +115 -0
- package/src/components/field-state.js +37 -58
- package/src/components/grid-cell-editor.js +181 -0
- package/src/components/grid-grammar.json +21 -0
- package/src/components/grid-structure.js +2 -1
- package/src/components/grid-styles.js +51 -1
- package/src/components/grid.js +87 -10
- 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 +2 -1
- package/src/components/jodit-engine.js +1 -1
- package/src/components/markdown-document.js +2 -2
- package/src/components/screen-capture.js +43 -0
- package/src/components/selected-container.js +6 -2
- package/src/components/tree.js +416 -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/editing-session.d.ts +25 -0
- package/src/editing-session.js +396 -0
- package/src/experiments/selection-trial.js +18 -2
- package/src/format.js +22 -7
- package/src/gramlot.d.ts +2 -0
- package/src/gramlot.js +2 -1
- 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 +13 -0
- 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 +2 -0
- package/src/renderer/gramlot-renderer.js +31 -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 +31 -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 +149 -0
- package/src/source-picker.d.ts +9 -0
- package/src/source-picker.js +57 -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-icons.js +10 -0
- package/src/visual-editor.d.ts +56 -0
- package/src/visual-editor.js +844 -0
- package/themes/gramlot-base/theme.css +99 -0
- 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
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {Bag} from '@gramlot/gramlot';
|
|
2
|
+
import {defineComponent} from './registry.js';
|
|
3
|
+
import {Container} from './container.js';
|
|
4
|
+
import {SVG_NS} from '../renderer/attributes.js';
|
|
5
|
+
import {positionPopup} from './popup.js';
|
|
6
|
+
import {editingStatusStyles} from './editing-status-styles.js';
|
|
7
|
+
|
|
8
|
+
/** Presentation of the nearest shared session. Registers and validation stay in EditingSession. */
|
|
9
|
+
export const EditingStatus = defineComponent({
|
|
10
|
+
name:'editingStatus', tag:'gramlot-editing-status', base:Container, sourceContext:true,
|
|
11
|
+
parameters:{},
|
|
12
|
+
implementation:Base => class extends Base {
|
|
13
|
+
#session; #release; #buttons = new Map(); #popup; #title; #list; #notice; #kind;
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
const doc = this.ownerDocument;
|
|
17
|
+
const style = doc.createElement('style'); style.textContent = editingStatusStyles;
|
|
18
|
+
this.shadowRoot.append(style);
|
|
19
|
+
this.control.replaceChildren();
|
|
20
|
+
this.control.setAttribute('role','group'); this.control.setAttribute('aria-label','Editing reports');
|
|
21
|
+
for (const [kind,caption,path] of [
|
|
22
|
+
['errors','Errors','M12 3L22 21H2ZM12 9V14M12 17V17.1'],
|
|
23
|
+
['changes','Changes','M4 5H14M4 10H10M4 15H8M13 20L20 13L17 10L10 17L9 21Z']
|
|
24
|
+
]) {
|
|
25
|
+
const button = doc.createElement('button'); button.type = 'button'; button.dataset.kind = kind;
|
|
26
|
+
button.setAttribute('aria-haspopup','dialog'); button.setAttribute('aria-expanded','false'); button.setAttribute('aria-controls','editing-report');
|
|
27
|
+
const svg = doc.createElementNS(SVG_NS,'svg'); svg.setAttribute('viewBox','0 0 24 24'); svg.setAttribute('aria-hidden','true');
|
|
28
|
+
const shape = doc.createElementNS(SVG_NS,'path'); shape.setAttribute('d',path); svg.append(shape);
|
|
29
|
+
const label = doc.createElement('span'); label.textContent = caption;
|
|
30
|
+
const count = doc.createElement('span'); count.className = 'count'; count.textContent = '0';
|
|
31
|
+
button.append(svg,label,count); this.control.append(button);
|
|
32
|
+
this.#buttons.set(kind,{button,count});
|
|
33
|
+
button.addEventListener('click',() => {
|
|
34
|
+
const open = this.#popup.matches(':popover-open');
|
|
35
|
+
if (open && this.#kind === kind) { this.#popup.hidePopover(); return; }
|
|
36
|
+
this.#kind = kind; this.#renderList();
|
|
37
|
+
if (!open) this.#popup.showPopover();
|
|
38
|
+
this.#expanded(); positionPopup(this.#popup,button,{align:'end'});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
this.#popup = doc.createElement('section'); this.#popup.id = 'editing-report';
|
|
42
|
+
this.#popup.className = 'report'; this.#popup.setAttribute('popover','auto');
|
|
43
|
+
this.#popup.setAttribute('role','dialog'); this.#popup.setAttribute('aria-labelledby','report-title');
|
|
44
|
+
const heading = doc.createElement('header');
|
|
45
|
+
this.#title = doc.createElement('strong'); this.#title.id = 'report-title';
|
|
46
|
+
const close = doc.createElement('button'); close.type = 'button'; close.textContent = '×'; close.setAttribute('aria-label','Close report');
|
|
47
|
+
close.addEventListener('click',() => this.#popup.hidePopover()); heading.append(this.#title,close);
|
|
48
|
+
this.#list = doc.createElement('ul');
|
|
49
|
+
this.#notice = doc.createElement('p'); this.#notice.className = 'notice'; this.#notice.setAttribute('role','status');
|
|
50
|
+
this.#popup.append(heading,this.#list,this.#notice); this.shadowRoot.append(this.#popup);
|
|
51
|
+
this.#popup.addEventListener('toggle',() => this.#expanded());
|
|
52
|
+
}
|
|
53
|
+
setSourceContext(context) {
|
|
54
|
+
this.#release?.(); this.#release = null;
|
|
55
|
+
this.#session = context.sourceNode.formState;
|
|
56
|
+
if (!this.#session) throw new Error('editingStatus requires a shared editing session.');
|
|
57
|
+
this.#connect();
|
|
58
|
+
}
|
|
59
|
+
connectedCallback() { this.#connect(); }
|
|
60
|
+
disconnectedCallback() {
|
|
61
|
+
this.#release?.(); this.#release = null;
|
|
62
|
+
if (this.#popup.matches(':popover-open')) this.#popup.hidePopover();
|
|
63
|
+
}
|
|
64
|
+
#connect() {
|
|
65
|
+
if (!this.#session || this.#release || !this.isConnected) return;
|
|
66
|
+
this.#release = this.#session.subscribe(() => this.#refresh()); this.#refresh();
|
|
67
|
+
}
|
|
68
|
+
#expanded() {
|
|
69
|
+
const open = this.#popup.matches(':popover-open');
|
|
70
|
+
for (const [kind,{button}] of this.#buttons) button.setAttribute('aria-expanded',String(open && kind === this.#kind));
|
|
71
|
+
}
|
|
72
|
+
#refresh() {
|
|
73
|
+
this.#buttons.get('errors').count.textContent = String(this.#session.errorEntries.length);
|
|
74
|
+
this.#buttons.get('changes').count.textContent = String(this.#session.changeEntries.length);
|
|
75
|
+
this.#buttons.get('errors').button.classList.toggle('invalid',this.#session.errorEntries.length > 0);
|
|
76
|
+
if (this.#popup.matches(':popover-open')) this.#renderList();
|
|
77
|
+
}
|
|
78
|
+
#value(value,exists) {
|
|
79
|
+
if (!exists) return 'Not present';
|
|
80
|
+
if (value == null) return '∅';
|
|
81
|
+
if (value instanceof Bag) return `${value.length} fields`;
|
|
82
|
+
if (value instanceof Date) return value.toLocaleString();
|
|
83
|
+
return String(value);
|
|
84
|
+
}
|
|
85
|
+
#renderList() {
|
|
86
|
+
const errors = this.#kind === 'errors';
|
|
87
|
+
const entries = errors ? this.#session.errorEntries : this.#session.changeEntries;
|
|
88
|
+
this.#title.textContent = errors ? 'Validation errors' : 'Unsaved changes';
|
|
89
|
+
this.#notice.textContent = entries.length ? 'Select an entry to return to its field.' : (errors ? 'No validation errors.' : 'No changes since the accepted snapshot.');
|
|
90
|
+
// Preserve list focus when asynchronous validation updates another entry.
|
|
91
|
+
const focusedPath = this.shadowRoot.activeElement?.dataset.path;
|
|
92
|
+
this.#list.replaceChildren();
|
|
93
|
+
for (const entry of entries) {
|
|
94
|
+
const doc = this.ownerDocument, item = doc.createElement('li'), button = doc.createElement('button');
|
|
95
|
+
button.type = 'button'; button.dataset.path = entry.path;
|
|
96
|
+
const field = doc.createElement('span'); field.className = 'field';
|
|
97
|
+
field.textContent = entry.path.slice(this.#session.path ? this.#session.path.length+1 : 0);
|
|
98
|
+
const detail = doc.createElement('span'); detail.className = 'detail';
|
|
99
|
+
if (errors) detail.textContent = entry.message;
|
|
100
|
+
else {
|
|
101
|
+
const before = doc.createElement('span'); before.className = 'previous'; before.textContent = this.#value(entry.previous,entry.existed);
|
|
102
|
+
const arrow = doc.createElement('span'); arrow.className = 'arrow'; arrow.textContent = '→';
|
|
103
|
+
const after = doc.createElement('span'); after.className = 'current'; after.textContent = this.#value(entry.current,entry.exists);
|
|
104
|
+
detail.append(before,arrow,after);
|
|
105
|
+
}
|
|
106
|
+
button.append(field,detail); item.append(button); this.#list.append(item);
|
|
107
|
+
button.addEventListener('click',() => {
|
|
108
|
+
if (this.#session.focusField(entry.path)) this.#popup.hidePopover();
|
|
109
|
+
else this.#notice.textContent = 'This field is not visible. Check the grid filter or whether the row still exists.';
|
|
110
|
+
});
|
|
111
|
+
if (entry.path === focusedPath) button.focus({preventScroll:true});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import {validateInput, validationParameters} from './validation.js';
|
|
2
|
+
import {ValidationRun} from '../validation-run.js';
|
|
2
3
|
import {positionPopup} from './popup.js';
|
|
3
4
|
|
|
4
5
|
const MESSAGE_DURATION = 1800;
|
|
5
6
|
const MESSAGE_FADE_DURATION = 200;
|
|
6
7
|
|
|
7
|
-
/**
|
|
8
|
+
/** Validation presentation; sessions own execution independently of mounted controls. */
|
|
8
9
|
export function FieldState(Base) {
|
|
9
10
|
return class extends Base {
|
|
10
11
|
get supportsFormValidation() { return true; }
|
|
12
|
+
get validationExecutor() { return validateInput; }
|
|
11
13
|
connectedCallback() { super.connectedCallback(); if (this.pageContext?.form) this.pageContext.formValidate(); }
|
|
12
14
|
#rejected = false;
|
|
13
15
|
#projected;
|
|
14
16
|
#messageTimer;
|
|
15
17
|
#messageEvents;
|
|
16
|
-
#validation;
|
|
17
|
-
#validationEpoch = 0;
|
|
18
|
+
#validation = new ValidationRun();
|
|
18
19
|
#validationCurrent;
|
|
19
20
|
#rules = {};
|
|
20
21
|
validationResult = null;
|
|
@@ -69,7 +70,7 @@ export function FieldState(Base) {
|
|
|
69
70
|
view.addEventListener('scroll', () => this.#hideMessage(), options);
|
|
70
71
|
view.addEventListener('resize', () => this.#hideMessage(), options);
|
|
71
72
|
}
|
|
72
|
-
releaseControl() { this.
|
|
73
|
+
releaseControl() { this.#validation.cancel(); this.#hideMessage(); super.releaseControl(); }
|
|
73
74
|
disconnectedCallback() { this.releaseControl(); }
|
|
74
75
|
setFieldState({invalid = false, pending = false} = {}) {
|
|
75
76
|
this.control.setAttribute('aria-invalid', String(invalid));
|
|
@@ -84,71 +85,49 @@ export function FieldState(Base) {
|
|
|
84
85
|
}
|
|
85
86
|
restoreFormValue(value) { this.error(''); this.#rejected = false; super.restoreFormValue(value); }
|
|
86
87
|
cancelValidation() {
|
|
87
|
-
if (this.pageContext?.form) this.pageContext.
|
|
88
|
-
this.#
|
|
89
|
-
this.#validation?.abort(); this.#validation = null; this.#validationCurrent = null;
|
|
88
|
+
if (this.pageContext?.form) this.pageContext.formCancelValidation();
|
|
89
|
+
this.#validation.cancel(); this.#validationCurrent = null;
|
|
90
90
|
this.control.setAttribute('aria-busy', 'false');
|
|
91
91
|
}
|
|
92
|
+
presentValidation(result) {
|
|
93
|
+
this.validationResult = result;
|
|
94
|
+
this.control.setAttribute('aria-busy','false');
|
|
95
|
+
this.error(result.error || '');
|
|
96
|
+
this.message.dataset.severity = result.error ? 'error' : 'warning';
|
|
97
|
+
this.#rejected = Boolean(result.error);
|
|
98
|
+
if (!result.error && result.warnings.length) {
|
|
99
|
+
this.message.textContent = result.warnings.join('\n'); this.#showMessage();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
92
102
|
validateCandidate(value, accept) {
|
|
93
|
-
this.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const current = this.pageContext.validationCurrent(); this.#validationCurrent = current;
|
|
99
|
-
const valid = () => this.#validationEpoch === epoch && !controller.signal.aborted && current();
|
|
100
|
-
const failure = error => ({value, modified:false, error:error.message, warnings:[], issues:[], datachanges:[]});
|
|
101
|
-
const finish = result => {
|
|
102
|
-
if (!valid()) {
|
|
103
|
-
if (this.#validation === controller) this.cancelValidation();
|
|
104
|
-
return {ok:false};
|
|
105
|
-
}
|
|
106
|
-
this.#validation = null; this.#validationCurrent = null;
|
|
107
|
-
this.control.setAttribute('aria-busy', 'false');
|
|
108
|
-
try { if (!result.error || this.pageContext.form) accept(result.value); }
|
|
109
|
-
catch (error) { result = failure(error); }
|
|
110
|
-
if (this.pageContext.form) this.pageContext.formResult(result);
|
|
111
|
-
this.validationResult = result;
|
|
112
|
-
this.error(result.error || ''); this.message.dataset.severity = result.error ? 'error' : 'warning'; this.#rejected = Boolean(result.error);
|
|
113
|
-
if (!result.error && result.warnings.length) {
|
|
114
|
-
this.message.textContent = result.warnings.join('\n'); this.#showMessage();
|
|
115
|
-
}
|
|
116
|
-
const outcome = {ok:!result.error, value:result.value, result, rules, isCurrent:valid};
|
|
117
|
-
if (!outcome.ok) this.finishValidation(outcome);
|
|
118
|
-
return outcome;
|
|
119
|
-
};
|
|
120
|
-
let result;
|
|
121
|
-
try {
|
|
122
|
-
if (rules.validate_timeout != null && (!Number.isInteger(rules.validate_timeout) || rules.validate_timeout <= 0)) throw new TypeError('validate_timeout must be a positive integer in milliseconds.');
|
|
123
|
-
result = validateInput(value, rules, {...this.pageContext, signal:controller.signal, selection:value => this.validateSelection(value)});
|
|
103
|
+
if (this.pageContext.form) {
|
|
104
|
+
// Capture selection evidence before accepting clears the choice's picked row.
|
|
105
|
+
const selection = this.validationSelection();
|
|
106
|
+
accept(value);
|
|
107
|
+
return this.pageContext.formValidateCandidate(value,selection);
|
|
124
108
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
};
|
|
137
|
-
if (rules.validate_timeout != null) timer = setTimeout(() => {
|
|
138
|
-
settle(failure(new Error('Validation timed out.'))); controller.abort();
|
|
139
|
-
}, rules.validate_timeout);
|
|
140
|
-
result.then(settle, error => settle(failure(error)));
|
|
141
|
-
});
|
|
109
|
+
this.cancelValidation();
|
|
110
|
+
this.#validationCurrent = this.pageContext.validationCurrent();
|
|
111
|
+
return this.#validation.start(value,this.#rules,
|
|
112
|
+
{...this.pageContext,selection:value => this.validateSelection(value)},validateInput,outcome => {
|
|
113
|
+
this.#validationCurrent = null;
|
|
114
|
+
if (outcome.ok) {
|
|
115
|
+
try { accept(outcome.value); }
|
|
116
|
+
catch (error) { outcome.ok = false; outcome.result.error = error.message; }
|
|
117
|
+
}
|
|
118
|
+
this.presentValidation(outcome.result);
|
|
119
|
+
if (!outcome.ok) this.finishValidation(outcome);
|
|
120
|
+
},() => this.control.setAttribute('aria-busy','true'));
|
|
142
121
|
}
|
|
143
122
|
finishValidation(outcome) {
|
|
144
123
|
if (!outcome.result) return;
|
|
145
124
|
this.pageContext.finishValidation(outcome);
|
|
146
125
|
}
|
|
147
126
|
shouldProjectControlValue(value) {
|
|
148
|
-
if (this.#validationCurrent && !this.#validationCurrent()) this.cancelValidation();
|
|
127
|
+
if (!this.pageContext?.form && this.#validationCurrent && !this.#validationCurrent()) this.cancelValidation();
|
|
149
128
|
const same = this.sameControlValue(value, this.#projected);
|
|
150
129
|
if (same && this.#rejected) return false;
|
|
151
|
-
if (!same) this.cancelValidation();
|
|
130
|
+
if (!same && !this.pageContext?.form) this.cancelValidation();
|
|
152
131
|
this.#projected = value;
|
|
153
132
|
if (!same && this.#rejected) this.error('');
|
|
154
133
|
return true;
|
|
@@ -157,7 +136,7 @@ export function FieldState(Base) {
|
|
|
157
136
|
const rest = super.projectAttributes(attrs, adapt);
|
|
158
137
|
const rules = Object.fromEntries(Object.entries(attrs).filter(([name]) => name.startsWith('validate_')));
|
|
159
138
|
const keys = new Set([...Object.keys(rules), ...Object.keys(this.#rules)]);
|
|
160
|
-
if ([...keys].some(key => !Object.is(rules[key], this.#rules[key])) || attrs.disabled || attrs.readonly) this.cancelValidation();
|
|
139
|
+
if (!this.pageContext?.form && ([...keys].some(key => !Object.is(rules[key], this.#rules[key])) || attrs.disabled || attrs.readonly)) this.cancelValidation();
|
|
161
140
|
const rulesChanged = [...keys].some(key => !Object.is(rules[key], this.#rules[key]));
|
|
162
141
|
this.#rules = rules;
|
|
163
142
|
if (rulesChanged && this.pageContext?.form) this.pageContext.formValidate();
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import {sourceTarget} from '@gramlot/gramlot';
|
|
2
|
+
|
|
3
|
+
/** Grid navigation and temporary Source controls; all editing registers belong to the shared session. */
|
|
4
|
+
export class GridCellEditor {
|
|
5
|
+
constructor(grid, context, cellFor, store, renderedRows, navigate, focusField) {
|
|
6
|
+
this.grid = grid;
|
|
7
|
+
this.context = context;
|
|
8
|
+
this.cellFor = cellFor;
|
|
9
|
+
this.store = store;
|
|
10
|
+
this.renderedRows = renderedRows;
|
|
11
|
+
this.navigate = navigate;
|
|
12
|
+
this.focusField = focusField;
|
|
13
|
+
this.retained = new Map();
|
|
14
|
+
this.declarations = new Map();
|
|
15
|
+
this.layer = grid.ownerDocument.createElement('div');
|
|
16
|
+
this.layer.className = 'cell-editor'; this.layer.hidden = true;
|
|
17
|
+
const slot = grid.ownerDocument.createElement('slot'); slot.name = 'cell-editor'; this.layer.append(slot);
|
|
18
|
+
grid.control.append(this.layer);
|
|
19
|
+
this.keydown = event => {
|
|
20
|
+
if (!this.active || event.isComposing) return;
|
|
21
|
+
if (event.key === 'Escape') {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
const cell = this.cellFor(this.active.row,this.active.column.field);
|
|
24
|
+
this.session.clearDraft(this.active.source);
|
|
25
|
+
this.close(); cell?.focus({preventScroll:true});
|
|
26
|
+
} else if (event.key === 'Enter' || event.key === 'Tab') {
|
|
27
|
+
if (event.key === 'Enter' && this.active.element.control.localName === 'textarea' && !event.ctrlKey && !event.metaKey) return;
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
const active = this.active;
|
|
30
|
+
this.session.commitField(active.path);
|
|
31
|
+
const cell = this.cellFor(active.row,active.column.field);
|
|
32
|
+
this.close(); cell?.focus({preventScroll:true});
|
|
33
|
+
if (event.key === 'Tab') this.navigate(active.row,active.column.field,event.shiftKey ? -1 : 1);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
this.arrowKeydown = event => {
|
|
37
|
+
if (!this.active || event.isComposing || !['ArrowUp','ArrowDown','ArrowLeft','ArrowRight'].includes(event.key) || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
38
|
+
const control = this.active.element.control;
|
|
39
|
+
if (control.localName === 'textarea' || ['range','date','time','datetime-local'].includes(control.type)) return;
|
|
40
|
+
// Composite controls own their popup arrows; date/time fields own their editing keys.
|
|
41
|
+
if (['gramlot-date-text-box','gramlot-time-text-box','gramlot-date-calendar'].includes(this.active.element.localName)) return;
|
|
42
|
+
if (control.getAttribute('aria-expanded') === 'true' || (event.key === 'ArrowDown' && control.getAttribute('role') === 'combobox')) return;
|
|
43
|
+
const horizontal = event.key === 'ArrowLeft' || event.key === 'ArrowRight';
|
|
44
|
+
const backwards = event.key === 'ArrowLeft' || event.key === 'ArrowUp';
|
|
45
|
+
if (horizontal) {
|
|
46
|
+
if (typeof control.selectionStart !== 'number' || control.selectionStart !== control.selectionEnd) return;
|
|
47
|
+
if (control.selectionStart !== (backwards ? 0 : control.value.length)) return;
|
|
48
|
+
}
|
|
49
|
+
event.preventDefault(); event.stopPropagation();
|
|
50
|
+
const active = this.active;
|
|
51
|
+
this.session.commitField(active.path);
|
|
52
|
+
this.navigate(active.row,active.column.field,horizontal ? (backwards ? -1 : 1) : {row:backwards ? -1 : 1});
|
|
53
|
+
if (horizontal && this.active && this.active !== active) {
|
|
54
|
+
const target = this.active.element.control;
|
|
55
|
+
if (typeof target.selectionStart === 'number') {
|
|
56
|
+
const caret = backwards ? target.value.length : 0;
|
|
57
|
+
target.setSelectionRange(caret,caret);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
this.connect();
|
|
62
|
+
context.sourceNode.rootBuilder.binding.bindingFor(context.sourceNode).track(() => this.dispose());
|
|
63
|
+
}
|
|
64
|
+
connect() {
|
|
65
|
+
this.grid.addEventListener('keydown',this.keydown);
|
|
66
|
+
this.grid.addEventListener('keydown',this.arrowKeydown,true);
|
|
67
|
+
if (this.session && !this.releaseNavigator) this.releaseNavigator = this.session.registerNavigator(this.focusField);
|
|
68
|
+
}
|
|
69
|
+
disconnect() {
|
|
70
|
+
this.close();
|
|
71
|
+
this.grid.removeEventListener('keydown',this.keydown);
|
|
72
|
+
this.grid.removeEventListener('keydown',this.arrowKeydown,true);
|
|
73
|
+
this.releaseNavigator?.(); this.releaseNavigator = null;
|
|
74
|
+
}
|
|
75
|
+
path(row, field) {
|
|
76
|
+
const {mode} = this.store();
|
|
77
|
+
return this.context.sourceNode.absDatapath(this.context.sourceNode.getAttr('storepath')) + '.' + row.label + (mode === 'attributes' ? '?' : '.') + field;
|
|
78
|
+
}
|
|
79
|
+
configure(columns) {
|
|
80
|
+
if (!columns.some(column => column.edit)) return;
|
|
81
|
+
if (this.store().window !== null) throw new Error('Editing requires a fully resident Bag; remote windows are read-only.');
|
|
82
|
+
const owner = this.context.sourceNode;
|
|
83
|
+
this.session = owner.editCollection(owner.absDatapath(owner.getAttr('storepath')));
|
|
84
|
+
if (!this.releaseStatus) this.releaseStatus = this.session.subscribe(() => this.refresh());
|
|
85
|
+
if (!this.releaseNavigator) this.releaseNavigator = this.session.registerNavigator(this.focusField);
|
|
86
|
+
}
|
|
87
|
+
open(row, column, cell) {
|
|
88
|
+
if (this.store().window !== null) throw new Error('Editing requires a fully resident Bag; remote windows are read-only.');
|
|
89
|
+
if (this.active?.row === row && this.active.column.field === column.field) { this.active.element.control.focus(); return; }
|
|
90
|
+
this.close();
|
|
91
|
+
const owner = this.context.sourceNode, path = this.path(row,column.field);
|
|
92
|
+
if (!this.retained.has(path)) { this.session.retainField(path); this.retained.set(path,row); }
|
|
93
|
+
let declaration = this.declarations.get(path);
|
|
94
|
+
if (!declaration) {
|
|
95
|
+
const options = column.edit === true ? {} : {...column.edit};
|
|
96
|
+
const tag = options.tag ?? ({L:'numberTextBox', R:'numberTextBox', N:'numberTextBox', D:'dateTextBox', H:'timeTextBox', B:'checkBox'}[column.dtype] ?? 'textbox');
|
|
97
|
+
delete options.tag;
|
|
98
|
+
if (column.dtype === 'DHZ' && !column.edit.tag) throw new Error('A datetime column requires an explicitly declared supported editor.');
|
|
99
|
+
if (!owner.rootBuilder.schemaTag(tag)) throw new Error(`Grid editor requires the ${tag} input collection.`);
|
|
100
|
+
const builder = owner.rootBuilder, id = `grid-cell-${crypto.randomUUID()}`;
|
|
101
|
+
const container = builder.wrapSource(owner).div({node_label:id, slot:'cell-editor'});
|
|
102
|
+
try {
|
|
103
|
+
const control = container[tag]({...options, value:'^'+path, dtype:column.dtype ?? 'T', id, width:'100%', margin:'0'});
|
|
104
|
+
declaration = {container:sourceTarget(container),source:sourceTarget(control),id};
|
|
105
|
+
if (!this.grid.ownerDocument.getElementById(id).supportsFormValidation) throw new TypeError('Grid editors require a Gramlot input with shared form validation.');
|
|
106
|
+
this.declarations.set(path,declaration);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
const node = sourceTarget(container); node.parentBag.popNode(node.label);
|
|
109
|
+
this.releaseCleanField(path);
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
} else owner.rootBuilder.binding.renderer.mountView(declaration.container);
|
|
113
|
+
const element = this.grid.ownerDocument.getElementById(declaration.id);
|
|
114
|
+
this.active = {row,column,path,...declaration,element};
|
|
115
|
+
this.layer.hidden = false;
|
|
116
|
+
this.position(cell);
|
|
117
|
+
element.control.focus();
|
|
118
|
+
}
|
|
119
|
+
close() {
|
|
120
|
+
const active = this.active;
|
|
121
|
+
this.active = null; this.layer.hidden = true;
|
|
122
|
+
if (active) {
|
|
123
|
+
this.context.sourceNode.rootBuilder.binding.renderer.unmountView(active.container);
|
|
124
|
+
this.releaseCleanField(active.path);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
releaseCleanField(path) {
|
|
128
|
+
const state = this.session.fieldStatus(path);
|
|
129
|
+
if (state.error === null && state.pending === null && state.draft === null && this.retained.has(path)) {
|
|
130
|
+
this.releaseField(path);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
releaseField(path) {
|
|
134
|
+
const declaration = this.declarations.get(path);
|
|
135
|
+
this.declarations.delete(path);
|
|
136
|
+
if (declaration?.container.parentBag) declaration.container.parentBag.popNode(declaration.container.label);
|
|
137
|
+
this.session.releaseField(path); this.retained.delete(path);
|
|
138
|
+
}
|
|
139
|
+
position(cell = null) {
|
|
140
|
+
if (!this.active) return;
|
|
141
|
+
cell ??= this.cellFor(this.active.row,this.active.column.field);
|
|
142
|
+
if (!cell) { this.close(); return; }
|
|
143
|
+
const rect = cell.getBoundingClientRect(), host = this.grid.control.getBoundingClientRect();
|
|
144
|
+
const viewport = this.grid.shadowRoot.querySelector('.body-viewport').getBoundingClientRect();
|
|
145
|
+
if (viewport.height && (rect.top < viewport.top || rect.bottom > viewport.bottom || rect.right <= viewport.left || rect.left >= viewport.right)) { this.close(); return; }
|
|
146
|
+
Object.assign(this.layer.style,{
|
|
147
|
+
left:`${rect.left-host.left-this.grid.control.clientLeft}px`,
|
|
148
|
+
top:`${rect.top-host.top-this.grid.control.clientTop}px`,width:`${rect.width}px`
|
|
149
|
+
});
|
|
150
|
+
this.layer.style.setProperty('--grid-editor-height',`${rect.height}px`);
|
|
151
|
+
}
|
|
152
|
+
decorate(tr, row) {
|
|
153
|
+
if (!this.session) return;
|
|
154
|
+
for (const cell of tr.querySelectorAll('td[data-field]')) {
|
|
155
|
+
const state = this.session.fieldStatus(this.path(row,cell.dataset.field));
|
|
156
|
+
cell.classList.toggle('invalid-cell',Boolean(state.error));
|
|
157
|
+
cell.classList.toggle('draft-cell',state.draft !== null);
|
|
158
|
+
if (state.error) { cell.setAttribute('aria-invalid','true'); cell.title = state.error.getNodes().map(n => n.value).join('\n'); }
|
|
159
|
+
else { cell.removeAttribute('aria-invalid'); cell.removeAttribute('title'); }
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
refresh() {
|
|
163
|
+
const bag = this.store().bag;
|
|
164
|
+
for (const [path,row] of this.retained) if (row.parentBag !== bag) {
|
|
165
|
+
this.releaseField(path);
|
|
166
|
+
if (this.active?.row === row) this.close();
|
|
167
|
+
}
|
|
168
|
+
for (const path of this.retained.keys()) if (path !== this.active?.path) this.releaseCleanField(path);
|
|
169
|
+
for (const [row,tr] of this.renderedRows()) this.decorate(tr,row);
|
|
170
|
+
}
|
|
171
|
+
replaceData() {
|
|
172
|
+
this.close();
|
|
173
|
+
if (this.session) {
|
|
174
|
+
for (const path of this.retained.keys()) this.releaseField(path);
|
|
175
|
+
this.retained.clear();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
dispose() {
|
|
179
|
+
this.disconnect(); this.replaceData(); this.releaseStatus?.(); this.layer.remove();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -153,6 +153,27 @@
|
|
|
153
153
|
},
|
|
154
154
|
"has_default": true,
|
|
155
155
|
"default": null
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"name": "edit",
|
|
159
|
+
"kind": "keyword_only",
|
|
160
|
+
"role": "attribute",
|
|
161
|
+
"annotation": {
|
|
162
|
+
"kind": "union",
|
|
163
|
+
"items": [
|
|
164
|
+
{
|
|
165
|
+
"kind": "dtype",
|
|
166
|
+
"dtype": "B"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"kind": "type",
|
|
170
|
+
"module": "builtins",
|
|
171
|
+
"name": "dict"
|
|
172
|
+
}
|
|
173
|
+
]
|
|
174
|
+
},
|
|
175
|
+
"has_default": true,
|
|
176
|
+
"default": false
|
|
156
177
|
}
|
|
157
178
|
],
|
|
158
179
|
"accepts_var_keyword": false,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Bag} from '@gramlot/gramlot';
|
|
2
2
|
|
|
3
3
|
const TYPES = new Set(['T', 'B', 'L', 'R', 'N', 'D', 'H', 'DHZ']);
|
|
4
|
-
const COLUMN_KEYS = new Set(['tag', 'field', 'name', 'dtype', 'width', 'align', 'format', 'columnset', 'white_space']);
|
|
4
|
+
const COLUMN_KEYS = new Set(['tag', 'field', 'name', 'dtype', 'width', 'align', 'format', 'columnset', 'white_space', 'edit']);
|
|
5
5
|
const GROUP_KEYS = new Set(['tag', 'code', 'name', 'background', 'color']);
|
|
6
6
|
|
|
7
7
|
/** Legacy Data contract: ordered cells and independent columnset definitions. */
|
|
@@ -41,6 +41,7 @@ export class GridStructure {
|
|
|
41
41
|
}
|
|
42
42
|
if (attrs.white_space != null && !['normal','nowrap','pre-wrap'].includes(attrs.white_space)) throw new TypeError('grid white_space requires normal, nowrap or pre-wrap');
|
|
43
43
|
for (const key of ['name', 'format']) if (attrs[key] != null && typeof attrs[key] !== 'string') throw new TypeError(`grid ${key} must be text`);
|
|
44
|
+
if (attrs.edit != null && typeof attrs.edit !== 'boolean' && (typeof attrs.edit !== 'object' || Array.isArray(attrs.edit))) throw new TypeError('grid edit requires a boolean or editor options');
|
|
44
45
|
const column = Object.freeze({...attrs, name: attrs.name ?? attrs.field,
|
|
45
46
|
align: attrs.align ?? (['L', 'R', 'N'].includes(attrs.dtype) ? 'end' : 'start')});
|
|
46
47
|
this.columns.push(column);
|
|
@@ -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:var(--grid-editor-height);
|
|
8
|
+
background:var(--gramlot-grid-background,var(--gramlot-surface,Canvas));
|
|
9
|
+
--gramlot-field-height:0px;
|
|
10
|
+
--gramlot-field-block-size: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;
|