@gramlot/gramlot 0.3.26 → 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 +1 -1
- package/dist/components/editors/assets/collection.js +16 -16
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/collection.js +28 -19
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +21 -0
- package/dist/components/grouplets/__init__.py +1 -1
- package/dist/components/grouplets/assets/collection.js +2 -2
- package/dist/components/grouplets/assets/index.js +1 -1
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +21 -21
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +15 -15
- package/dist/components/layout/assets/index.js +1 -1
- 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/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +11 -11
- package/dist/components/tree/assets/index.js +1 -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 +1 -1
- package/dist/components/uploads/assets/collection.js +8 -8
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/gramlot.js +624 -86
- package/dist/gramlot.min.js +47 -46
- package/package.json +1 -1
- package/src/binding/grid-struct.js +1 -1
- package/src/binding/validation-context.js +2 -1
- package/src/components/bases.js +5 -3
- package/src/components/choice-editor.js +28 -13
- package/src/components/database-choices.js +9 -6
- package/src/components/field-state.js +8 -1
- package/src/components/grid-cell-editor.js +83 -19
- package/src/components/grid-grammar.json +21 -0
- package/src/components/grid-structure.js +4 -1
- package/src/components/grid-styles.js +11 -2
- package/src/components/grid.js +16 -1
- package/src/components/inputs.js +2 -2
- package/src/components/parameters.js +6 -2
- package/src/components/tree.js +1 -0
- package/src/components/typed-editor.js +4 -4
- package/src/components/validation.js +1 -1
- package/src/editing-session.d.ts +1 -0
- package/src/editing-session.js +113 -15
- package/src/editor-values.js +57 -0
- package/src/gramlot.d.ts +1 -0
- package/src/gramlot.js +7 -4
- package/src/index.d.ts +1 -1
- package/src/renderer/gramlot-renderer.d.ts +1 -0
- package/src/renderer/gramlot-renderer.js +11 -0
- package/src/server/source-import.d.ts +1 -1
- package/src/server/source-import.js +5 -1
- package/src/server/visual-editor.d.ts +1 -1
- package/src/server/visual-editor.js +30 -20
- package/src/source-picker.d.ts +1 -1
- package/src/source-picker.js +1 -2
- package/src/visual-editor-canvas.js +29 -0
- package/src/visual-editor-catalogue.js +34 -0
- package/src/visual-editor.d.ts +5 -0
- package/src/visual-editor.js +244 -26
- package/themes/gramlot-base/theme.css +78 -36
- package/tools/gramlot-tools-inspector.js +1 -1
- package/tools/inspector-agent.js +1 -1
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@ function structureData(source) {
|
|
|
13
13
|
node.builder.validateNode(node);
|
|
14
14
|
if (node.nodeTag !== 'column' || node.staticValue != null) throw new TypeError('grid column must be a scalar declaration');
|
|
15
15
|
const attrs = {tag:'cell'};
|
|
16
|
-
for (const key of ['field', 'name', 'dtype', 'width', 'align', 'format', 'white_space', 'edit']) {
|
|
16
|
+
for (const key of ['field', 'name', 'dtype', 'width', 'align', 'format', 'white_space', 'max_height', 'edit']) {
|
|
17
17
|
if (node.getAttr(key) != null) attrs[key] = node.getAttr(key);
|
|
18
18
|
}
|
|
19
19
|
const label = `cell_${attrs.field}`;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Bag} from '@genrojs/bag';
|
|
2
2
|
import {isDecimal} from '@genrojs/tytx';
|
|
3
|
-
import {invokeHook} from './hooks.js';
|
|
3
|
+
import {invokeHook, callLogic} from './hooks.js';
|
|
4
4
|
|
|
5
5
|
/** Source-scoped validation services, retained independently of the control view. */
|
|
6
6
|
export function validationContext(binding) {
|
|
@@ -12,6 +12,7 @@ export function validationContext(binding) {
|
|
|
12
12
|
};
|
|
13
13
|
return {
|
|
14
14
|
isDecimal, invoke,
|
|
15
|
+
callLogic:(method,keywords) => callLogic(binding.runtime,node,method,keywords),
|
|
15
16
|
remote:(method, keywords, signal) => app.rpc.call('data', method, keywords, {signal}),
|
|
16
17
|
reportError:(error, title) => { if (!binding.closed) binding.runtime.reportError(error,title); },
|
|
17
18
|
validationCurrent:() => {
|
package/src/components/bases.js
CHANGED
|
@@ -41,14 +41,16 @@ export function controlElement(HTMLElement) {
|
|
|
41
41
|
return {ok:true, value, isCurrent:() => this.pageContext.isActive()};
|
|
42
42
|
}
|
|
43
43
|
finishValidation() {}
|
|
44
|
-
validationValueCheck() {
|
|
45
|
-
|
|
44
|
+
validationValueCheck() { return this.constructor.validationValueCheck(this.pageContext); }
|
|
45
|
+
static validationValueCheck() {
|
|
46
|
+
const nullable = this.gramlotComponent.parameters.value.nullable;
|
|
46
47
|
return (value, original) => {
|
|
47
48
|
if (value == null && !nullable) throw new TypeError('This component requires a non-null value.');
|
|
48
49
|
if (value != null && original != null && typeof value !== typeof original) throw new TypeError('Validation must preserve the component value type.');
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
|
-
validationSelection() {
|
|
52
|
+
validationSelection() { return this.constructor.validationSelection(this.parameters,this.pageContext); }
|
|
53
|
+
static validationSelection() {
|
|
52
54
|
return () => { throw new TypeError('validate_select requires a constrained choice editor.'); };
|
|
53
55
|
}
|
|
54
56
|
validateSelection(value) { return this.validationSelection()(value); }
|
|
@@ -82,7 +82,8 @@ export function ChoiceEditor(HTMLElement) {
|
|
|
82
82
|
input.setAttribute('aria-controls', 'choices'); input.setAttribute('aria-expanded', 'false');
|
|
83
83
|
input.autocomplete = 'off'; return input;
|
|
84
84
|
}
|
|
85
|
-
get constrained() { return true; }
|
|
85
|
+
static get constrained() { return true; }
|
|
86
|
+
get constrained() { return this.constructor.constrained; }
|
|
86
87
|
get revalidateDraftOnSourceChange() { return false; }
|
|
87
88
|
get autoHighlight() { return true; }
|
|
88
89
|
get matchTypedChoice() { return true; }
|
|
@@ -129,21 +130,27 @@ export function ChoiceEditor(HTMLElement) {
|
|
|
129
130
|
this.#value = value; this.#dirty = false; this.#picked = null;
|
|
130
131
|
this.closeChoices({cancelLookup:true}); this.resolveValue();
|
|
131
132
|
}
|
|
132
|
-
validationValueCheck() {
|
|
133
|
+
static validationValueCheck() {
|
|
133
134
|
const constrained = this.constrained;
|
|
134
135
|
return (value, original) => {
|
|
135
136
|
if (constrained && value !== original) throw new Error('Validation cannot replace a selected code; update the Data explicitly.');
|
|
136
137
|
};
|
|
137
138
|
}
|
|
139
|
+
static validationSelection(parameters,context) {
|
|
140
|
+
if (!this.constrained) return super.validationSelection(parameters,context);
|
|
141
|
+
return async (value,signal) => {
|
|
142
|
+
if (value == null) return true;
|
|
143
|
+
const rows = await this.loadChoices(parameters,context,{_id:value},signal);
|
|
144
|
+
return selectionResult(rows.find(row => row.id === value),value);
|
|
145
|
+
};
|
|
146
|
+
}
|
|
138
147
|
validationSelection() {
|
|
139
148
|
if (!this.constrained) return super.validationSelection();
|
|
140
149
|
const rows = this.#rows.map(({id,error}) => ({id,error}));
|
|
141
150
|
const picked = this.#picked ? {id:this.#picked.id,error:this.#picked.error} : null;
|
|
142
151
|
return value => {
|
|
143
152
|
const row = picked?.id === value ? picked : rows.find(row => row.id === value);
|
|
144
|
-
|
|
145
|
-
if (value == null || row) return true;
|
|
146
|
-
return {errorcode:'missing',message:'Choose a value from the list.'};
|
|
153
|
+
return selectionResult(row,value);
|
|
147
154
|
};
|
|
148
155
|
}
|
|
149
156
|
acceptControlValue() {
|
|
@@ -290,19 +297,20 @@ ChoiceEditor.parameters = {...NativeControl.parameters,
|
|
|
290
297
|
|
|
291
298
|
export function localChoices(Base) {
|
|
292
299
|
return class extends Base {
|
|
293
|
-
loadChoices(keywords) {
|
|
300
|
+
loadChoices(keywords) { return this.constructor.loadChoices(this.parameters,this.pageContext,keywords); }
|
|
301
|
+
static loadChoices(parameters,context,keywords) {
|
|
294
302
|
let rows;
|
|
295
|
-
if (
|
|
296
|
-
if (!(
|
|
297
|
-
if (
|
|
303
|
+
if (parameters.store != null) {
|
|
304
|
+
if (!(parameters.store instanceof Bag)) throw new TypeError('store must be a Bag');
|
|
305
|
+
if (parameters.values) throw new TypeError('store and values are mutually exclusive');
|
|
298
306
|
const ids = new Set();
|
|
299
|
-
rows =
|
|
307
|
+
rows = parameters.store.getNodes().map(node => {
|
|
300
308
|
const id = node.staticValue, caption = node.attr.caption;
|
|
301
309
|
if (typeof id !== 'string' || !id || typeof caption !== 'string' || ids.has(id)) throw new TypeError('Invalid or duplicate store choice');
|
|
302
310
|
ids.add(id);
|
|
303
311
|
return {id, caption};
|
|
304
312
|
});
|
|
305
|
-
} else rows = parseChoices(
|
|
313
|
+
} else rows = parseChoices(parameters.values ?? '', parameters.separator);
|
|
306
314
|
return rows.filter(row => Object.hasOwn(keywords, '_id') ? row.id === keywords._id
|
|
307
315
|
: row.caption.toLocaleLowerCase().includes(keywords._querystring.toLocaleLowerCase()));
|
|
308
316
|
}
|
|
@@ -310,8 +318,9 @@ export function localChoices(Base) {
|
|
|
310
318
|
}
|
|
311
319
|
export function callbackChoices(Base) {
|
|
312
320
|
return class extends Base {
|
|
313
|
-
|
|
314
|
-
|
|
321
|
+
loadChoices(keywords) { return this.constructor.loadChoices(this.parameters,this.pageContext,keywords); }
|
|
322
|
+
static async loadChoices(parameters,context,keywords) {
|
|
323
|
+
const result = await context.callLogic(parameters.callback, keywords);
|
|
315
324
|
if (!result || !Array.isArray(result.rows) || typeof result.identifier !== 'string' || typeof result.caption !== 'string') {
|
|
316
325
|
throw new TypeError('callbackSelect requires {rows, identifier, caption}');
|
|
317
326
|
}
|
|
@@ -324,3 +333,9 @@ export function callbackChoices(Base) {
|
|
|
324
333
|
}
|
|
325
334
|
};
|
|
326
335
|
}
|
|
336
|
+
|
|
337
|
+
function selectionResult(row,value) {
|
|
338
|
+
if (row?.error) return {errorcode:'condition',message:row.error};
|
|
339
|
+
if (value == null || row) return true;
|
|
340
|
+
return {errorcode:'missing',message:'Choose a value from the list.'};
|
|
341
|
+
}
|
|
@@ -94,10 +94,7 @@ export function databaseChoices(Base) {
|
|
|
94
94
|
for (const key of Object.keys(rest)) if (key.startsWith('condition_') || key.startsWith('selected_')) delete rest[key];
|
|
95
95
|
return rest;
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
const parameters = Object.fromEntries(requestParameters.filter(key => key !== 'method' && this.parameters[key] != null)
|
|
99
|
-
.map(key => [key, this.parameters[key]]));
|
|
100
|
-
if (parameters.weakCondition === false) delete parameters.weakCondition;
|
|
97
|
+
loadChoices(keywords, signal) {
|
|
101
98
|
const required = new Set(Object.entries(this.#outputs).filter(([, path]) => path).map(([name]) => name.slice(9)));
|
|
102
99
|
if (this.#template) {
|
|
103
100
|
const walker = this.ownerDocument.createTreeWalker(this.#template, 4);
|
|
@@ -105,17 +102,23 @@ export function databaseChoices(Base) {
|
|
|
105
102
|
for (const match of walker.currentNode.data.matchAll(/\{([A-Za-z0-9_]+)\}/g)) required.add(match[1]);
|
|
106
103
|
}
|
|
107
104
|
}
|
|
105
|
+
return this.constructor.loadChoices({...this.parameters,...this.#configuration},this.pageContext,keywords,signal,required);
|
|
106
|
+
}
|
|
107
|
+
static async loadChoices(configuration,context,keywords,signal,required = new Set()) {
|
|
108
|
+
const parameters = Object.fromEntries(requestParameters.filter(key => key !== 'method' && configuration[key] != null)
|
|
109
|
+
.map(key => [key, configuration[key]]));
|
|
110
|
+
if (parameters.weakCondition === false) delete parameters.weakCondition;
|
|
108
111
|
if (required.size) parameters.hiddenColumns = [...new Set([
|
|
109
112
|
...(parameters.hiddenColumns ?? '').split(',').map(name => name.trim()).filter(Boolean), ...required
|
|
110
113
|
])].join(',');
|
|
111
|
-
for (const [key, value] of Object.entries(
|
|
114
|
+
for (const [key, value] of Object.entries(configuration)) {
|
|
112
115
|
if (key.startsWith('condition_')) {
|
|
113
116
|
const name = key.slice(10);
|
|
114
117
|
if (!name || name.startsWith('_') || requestParameters.includes(name)) throw new TypeError('Invalid condition parameter.');
|
|
115
118
|
parameters[name] = value;
|
|
116
119
|
}
|
|
117
120
|
}
|
|
118
|
-
const result = await
|
|
121
|
+
const result = await context.remote(configuration.method, {...parameters, ...keywords}, signal);
|
|
119
122
|
if (!result || !Array.isArray(result.rows) || typeof result.identifier !== 'string' || typeof result.caption !== 'string') {
|
|
120
123
|
throw new TypeError('Database selectors require {rows, identifier, caption}.');
|
|
121
124
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {validateInput, validationParameters} from './validation.js';
|
|
2
2
|
import {ValidationRun} from '../validation-run.js';
|
|
3
3
|
import {positionPopup} from './popup.js';
|
|
4
|
+
import {parameterValues} from './parameters.js';
|
|
4
5
|
|
|
5
6
|
const MESSAGE_DURATION = 1800;
|
|
6
7
|
const MESSAGE_FADE_DURATION = 200;
|
|
@@ -9,7 +10,13 @@ const MESSAGE_FADE_DURATION = 200;
|
|
|
9
10
|
export function FieldState(Base) {
|
|
10
11
|
return class extends Base {
|
|
11
12
|
get supportsFormValidation() { return true; }
|
|
12
|
-
|
|
13
|
+
static validationParameters(attrs) {
|
|
14
|
+
const parameters = {...parameterValues(this.gramlotComponent,attrs),...attrs};
|
|
15
|
+
if (this.constrained && parameters.validate_select == null) parameters.validate_select = true;
|
|
16
|
+
return parameters;
|
|
17
|
+
}
|
|
18
|
+
static get validationExecutor() { return validateInput; }
|
|
19
|
+
get validationExecutor() { return this.constructor.validationExecutor; }
|
|
13
20
|
connectedCallback() { super.connectedCallback(); if (this.pageContext?.form) this.pageContext.formValidate(); }
|
|
14
21
|
#rejected = false;
|
|
15
22
|
#projected;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {sourceTarget} from '@gramlot/gramlot';
|
|
1
|
+
import {sourceTarget, toTytx} from '@gramlot/gramlot';
|
|
2
2
|
|
|
3
3
|
/** Grid navigation and temporary Source controls; all editing registers belong to the shared session. */
|
|
4
4
|
export class GridCellEditor {
|
|
@@ -12,6 +12,8 @@ export class GridCellEditor {
|
|
|
12
12
|
this.focusField = focusField;
|
|
13
13
|
this.retained = new Map();
|
|
14
14
|
this.declarations = new Map();
|
|
15
|
+
this.checking = new Set();
|
|
16
|
+
this.columns = [];
|
|
15
17
|
this.layer = grid.ownerDocument.createElement('div');
|
|
16
18
|
this.layer.className = 'cell-editor'; this.layer.hidden = true;
|
|
17
19
|
const slot = grid.ownerDocument.createElement('slot'); slot.name = 'cell-editor'; this.layer.append(slot);
|
|
@@ -77,44 +79,100 @@ export class GridCellEditor {
|
|
|
77
79
|
return this.context.sourceNode.absDatapath(this.context.sourceNode.getAttr('storepath')) + '.' + row.label + (mode === 'attributes' ? '?' : '.') + field;
|
|
78
80
|
}
|
|
79
81
|
configure(columns) {
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
const editable = columns.filter(column => column.edit);
|
|
83
|
+
if (editable.length) {
|
|
84
|
+
if (this.store().window !== null) throw new Error('Editing requires a fully resident Bag; remote windows are read-only.');
|
|
85
|
+
const owner = this.context.sourceNode;
|
|
86
|
+
this.session = owner.editCollection(owner.absDatapath(owner.getAttr('storepath')));
|
|
87
|
+
}
|
|
88
|
+
const signature = toTytx(editable.map(({field,dtype,edit}) => ({field,dtype,edit})));
|
|
89
|
+
if (signature === this.validationSignature) return;
|
|
90
|
+
this.validationSignature = signature;
|
|
91
|
+
this.columns = editable;
|
|
92
|
+
for (const [path,declaration] of this.declarations) {
|
|
93
|
+
const column = editable.find(column => column.field === declaration.field);
|
|
94
|
+
if (!column) {
|
|
95
|
+
if (this.active?.path === path) this.close();
|
|
96
|
+
this.releaseField(path);
|
|
97
|
+
} else {
|
|
98
|
+
const {tag,options} = this.definition(column);
|
|
99
|
+
if (tag !== declaration.tag) {
|
|
100
|
+
if (this.active?.path === path) this.close();
|
|
101
|
+
this.releaseField(path);
|
|
102
|
+
} else {
|
|
103
|
+
declaration.source.setAttr({...Object.fromEntries(Object.keys(declaration.options).map(key => [key,null])),...options});
|
|
104
|
+
declaration.options = options;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (!editable.length) {
|
|
109
|
+
this.releaseValidation?.(); this.releaseValidation = null;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
84
112
|
if (!this.releaseStatus) this.releaseStatus = this.session.subscribe(() => this.refresh());
|
|
85
113
|
if (!this.releaseNavigator) this.releaseNavigator = this.session.registerNavigator(this.focusField);
|
|
114
|
+
if (!this.releaseValidation) this.releaseValidation = this.session.registerValidationSource(() => this.validationFields());
|
|
115
|
+
else this.session.invalidateValidation();
|
|
116
|
+
}
|
|
117
|
+
definition(column) {
|
|
118
|
+
const options = column.edit === true ? {} : {...column.edit};
|
|
119
|
+
const tag = options.tag ?? ({L:'numberTextBox',R:'numberTextBox',N:'numberTextBox',D:'dateTextBox',H:'timeTextBox',B:'checkBox'}[column.dtype] ?? 'textbox');
|
|
120
|
+
if (column.dtype === 'DHZ' && !options.tag) throw new Error('A datetime column requires an explicitly declared supported editor.');
|
|
121
|
+
delete options.tag;
|
|
122
|
+
return {tag,options:{...options,dtype:column.dtype ?? 'T'}};
|
|
123
|
+
}
|
|
124
|
+
*validationFields() {
|
|
125
|
+
const owner = this.context.sourceNode;
|
|
126
|
+
this.session.trackValidationDependency(owner.absDatapath(owner.getAttr('structpath')));
|
|
127
|
+
const bag = this.store().bag;
|
|
128
|
+
for (const row of bag.getNodes()) for (const column of this.columns) {
|
|
129
|
+
if (row.parentBag !== bag) continue;
|
|
130
|
+
const path = this.path(row,column.field);
|
|
131
|
+
this.checking.add(path);
|
|
132
|
+
try {
|
|
133
|
+
const declaration = this.declare(row,column,false);
|
|
134
|
+
yield {node:declaration.source,release:() => {
|
|
135
|
+
this.checking.delete(path);
|
|
136
|
+
if (path !== this.active?.path) this.releaseCleanField(path);
|
|
137
|
+
}};
|
|
138
|
+
} catch (error) { this.checking.delete(path); this.releaseCleanField(path); throw error; }
|
|
139
|
+
}
|
|
86
140
|
}
|
|
87
141
|
open(row, column, cell) {
|
|
88
142
|
if (this.store().window !== null) throw new Error('Editing requires a fully resident Bag; remote windows are read-only.');
|
|
89
143
|
if (this.active?.row === row && this.active.column.field === column.field) { this.active.element.control.focus(); return; }
|
|
90
144
|
this.close();
|
|
145
|
+
const path = this.path(row,column.field), declaration = this.declare(row,column,true);
|
|
146
|
+
const element = this.grid.ownerDocument.getElementById(declaration.id);
|
|
147
|
+
this.active = {row,column,path,...declaration,element};
|
|
148
|
+
this.layer.hidden = false;
|
|
149
|
+
this.position(cell);
|
|
150
|
+
element.control.focus();
|
|
151
|
+
}
|
|
152
|
+
declare(row,column,mount) {
|
|
91
153
|
const owner = this.context.sourceNode, path = this.path(row,column.field);
|
|
92
154
|
if (!this.retained.has(path)) { this.session.retainField(path); this.retained.set(path,row); }
|
|
93
155
|
let declaration = this.declarations.get(path);
|
|
94
156
|
if (!declaration) {
|
|
95
|
-
const options =
|
|
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.');
|
|
157
|
+
const {tag,options} = this.definition(column);
|
|
99
158
|
if (!owner.rootBuilder.schemaTag(tag)) throw new Error(`Grid editor requires the ${tag} input collection.`);
|
|
100
159
|
const builder = owner.rootBuilder, id = `grid-cell-${crypto.randomUUID()}`;
|
|
101
160
|
const container = builder.wrapSource(owner).div({node_label:id, slot:'cell-editor'});
|
|
161
|
+
// Unmount the branch before declaring a control: no editor element is constructed.
|
|
162
|
+
if (!mount) builder.binding.renderer.unmountView(sourceTarget(container));
|
|
102
163
|
try {
|
|
103
|
-
const control = container[tag]({...options, value:'^'+path,
|
|
104
|
-
declaration = {container:sourceTarget(container),source:sourceTarget(control),id};
|
|
105
|
-
|
|
164
|
+
const control = container[tag]({...options, value:'^'+path, id, width:'100%', margin:'0'});
|
|
165
|
+
declaration = {container:sourceTarget(container),source:sourceTarget(control),id,tag,options,field:column.field};
|
|
166
|
+
const component = this.grid.ownerDocument.defaultView.customElements.get(declaration.source._getMeta('render_tag'));
|
|
167
|
+
this.session.registerField(declaration.source,component,mount);
|
|
106
168
|
this.declarations.set(path,declaration);
|
|
107
169
|
} catch (error) {
|
|
108
170
|
const node = sourceTarget(container); node.parentBag.popNode(node.label);
|
|
109
171
|
this.releaseCleanField(path);
|
|
110
172
|
throw error;
|
|
111
173
|
}
|
|
112
|
-
} else owner.rootBuilder.binding.renderer.mountView(declaration.container);
|
|
113
|
-
|
|
114
|
-
this.active = {row,column,path,...declaration,element};
|
|
115
|
-
this.layer.hidden = false;
|
|
116
|
-
this.position(cell);
|
|
117
|
-
element.control.focus();
|
|
174
|
+
} else if (mount) owner.rootBuilder.binding.renderer.mountView(declaration.container);
|
|
175
|
+
return declaration;
|
|
118
176
|
}
|
|
119
177
|
close() {
|
|
120
178
|
const active = this.active;
|
|
@@ -125,6 +183,7 @@ export class GridCellEditor {
|
|
|
125
183
|
}
|
|
126
184
|
}
|
|
127
185
|
releaseCleanField(path) {
|
|
186
|
+
if (this.checking.has(path)) return;
|
|
128
187
|
const state = this.session.fieldStatus(path);
|
|
129
188
|
if (state.error === null && state.pending === null && state.draft === null && this.retained.has(path)) {
|
|
130
189
|
this.releaseField(path);
|
|
@@ -142,12 +201,16 @@ export class GridCellEditor {
|
|
|
142
201
|
if (!cell) { this.close(); return; }
|
|
143
202
|
const rect = cell.getBoundingClientRect(), host = this.grid.control.getBoundingClientRect();
|
|
144
203
|
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
204
|
Object.assign(this.layer.style,{
|
|
147
205
|
left:`${rect.left-host.left-this.grid.control.clientLeft}px`,
|
|
148
206
|
top:`${rect.top-host.top-this.grid.control.clientTop}px`,width:`${rect.width}px`
|
|
149
207
|
});
|
|
150
208
|
this.layer.style.setProperty('--grid-editor-height',`${rect.height}px`);
|
|
209
|
+
const maxHeight = cell.style.getPropertyValue('--grid-cell-max-height');
|
|
210
|
+
if (maxHeight) this.layer.style.setProperty('--grid-cell-max-height',maxHeight);
|
|
211
|
+
else this.layer.style.removeProperty('--grid-cell-max-height');
|
|
212
|
+
const editor = this.layer.getBoundingClientRect();
|
|
213
|
+
if (viewport.height && (editor.top < viewport.top || editor.bottom > viewport.bottom || editor.right <= viewport.left || editor.left >= viewport.right)) this.close();
|
|
151
214
|
}
|
|
152
215
|
decorate(tr, row) {
|
|
153
216
|
if (!this.session) return;
|
|
@@ -176,6 +239,7 @@ export class GridCellEditor {
|
|
|
176
239
|
}
|
|
177
240
|
}
|
|
178
241
|
dispose() {
|
|
242
|
+
this.releaseValidation?.(); this.releaseValidation = null;
|
|
179
243
|
this.disconnect(); this.replaceData(); this.releaseStatus?.(); this.layer.remove();
|
|
180
244
|
}
|
|
181
245
|
}
|
|
@@ -101,6 +101,27 @@
|
|
|
101
101
|
"has_default": true,
|
|
102
102
|
"default": null
|
|
103
103
|
},
|
|
104
|
+
{
|
|
105
|
+
"name": "max_height",
|
|
106
|
+
"kind": "keyword_only",
|
|
107
|
+
"role": "attribute",
|
|
108
|
+
"annotation": {
|
|
109
|
+
"kind": "annotated",
|
|
110
|
+
"base": {
|
|
111
|
+
"kind": "dtype",
|
|
112
|
+
"dtype": "T"
|
|
113
|
+
},
|
|
114
|
+
"metadata": [
|
|
115
|
+
{
|
|
116
|
+
"kind": "regex",
|
|
117
|
+
"pattern": "^[0-9]+([.][0-9]+)?(px|em|rem)$",
|
|
118
|
+
"flags": 0
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
"has_default": true,
|
|
123
|
+
"default": null
|
|
124
|
+
},
|
|
104
125
|
{
|
|
105
126
|
"name": "align",
|
|
106
127
|
"kind": "keyword_only",
|
|
@@ -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', 'edit']);
|
|
4
|
+
const COLUMN_KEYS = new Set(['tag', 'field', 'name', 'dtype', 'width', 'align', 'format', 'columnset', 'white_space', 'max_height', '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. */
|
|
@@ -39,6 +39,9 @@ export class GridStructure {
|
|
|
39
39
|
if (attrs.width != null && (typeof attrs.width !== 'string' || !/^(?:\d+(?:\.\d+)?)(?:px|em|rem|ch|%)$/.test(attrs.width))) {
|
|
40
40
|
throw new TypeError('grid width requires a nonnegative CSS length (px, em, rem, ch or %)');
|
|
41
41
|
}
|
|
42
|
+
if (attrs.max_height != null && (typeof attrs.max_height !== 'string' || !/^(?:\d+(?:\.\d+)?)(?:px|em|rem)$/.test(attrs.max_height))) {
|
|
43
|
+
throw new TypeError('grid max_height requires a nonnegative CSS length (px, em or rem)');
|
|
44
|
+
}
|
|
42
45
|
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
46
|
for (const key of ['name', 'format']) if (attrs[key] != null && typeof attrs[key] !== 'string') throw new TypeError(`grid ${key} must be text`);
|
|
44
47
|
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');
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
export const gridStyles = `
|
|
5
5
|
.control-box{position:relative}
|
|
6
6
|
.cell-editor{
|
|
7
|
-
position:absolute;z-index:4;height:var(--grid-editor-height);
|
|
7
|
+
position:absolute;z-index:4;height:min(var(--grid-editor-height),var(--grid-cell-max-height,var(--grid-editor-height)));
|
|
8
8
|
background:var(--gramlot-grid-background,var(--gramlot-surface,Canvas));
|
|
9
9
|
--gramlot-field-height:0px;
|
|
10
|
-
--gramlot-field-block-size:var(--grid-editor-height);
|
|
10
|
+
--gramlot-field-block-size:min(var(--grid-editor-height),var(--grid-cell-max-height,var(--grid-editor-height)));
|
|
11
11
|
--gramlot-field-padding:var(--gramlot-grid-cell-padding,.3rem .6rem);
|
|
12
12
|
--gramlot-field-font-size:1em;
|
|
13
13
|
--gramlot-field-line-height:var(--gramlot-grid-line-height,1.35);
|
|
@@ -140,6 +140,15 @@ export const gridStyles = `
|
|
|
140
140
|
block-size: var(--gramlot-grid-row-height, 2rem);
|
|
141
141
|
border-block-end: 1px solid var(--gramlot-grid-row-border-color, var(--gramlot-border, ButtonBorder));
|
|
142
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; }
|
|
143
152
|
tbody tr { background: var(--gramlot-grid-background, var(--gramlot-surface, Canvas)); }
|
|
144
153
|
tbody tr.alternate { background: var(--gramlot-grid-row-alt-background, var(--gramlot-surface-subtle, Canvas)); }
|
|
145
154
|
tbody tr:hover { background: var(--gramlot-grid-row-hover-background, var(--gramlot-selected, Highlight)); }
|
package/src/components/grid.js
CHANGED
|
@@ -307,8 +307,13 @@ export const Grid = defineComponent({
|
|
|
307
307
|
if (top < this.#bodyViewport.scrollTop) this.#scrollTo(top);
|
|
308
308
|
else if (bottom > this.#bodyViewport.scrollTop + this.#bodyViewport.clientHeight) this.#scrollTo(Math.max(0,bottom-this.#bodyViewport.clientHeight));
|
|
309
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();
|
|
310
313
|
const cell = this.#rows.get(next).querySelector(`td[data-field="${column.field}"]`);
|
|
311
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)));
|
|
312
317
|
if (rect.left < viewport.left) this.#bodyViewport.scrollLeft += rect.left-viewport.left;
|
|
313
318
|
else if (rect.right > viewport.right) this.#bodyViewport.scrollLeft += Math.min(rect.left-viewport.left,rect.right-viewport.right);
|
|
314
319
|
this.#headerViewport.scrollLeft = this.#bodyViewport.scrollLeft;
|
|
@@ -613,8 +618,17 @@ export const Grid = defineComponent({
|
|
|
613
618
|
if (!td) {
|
|
614
619
|
td = this.ownerDocument.createElement('td'); td.setAttribute('part', 'cell');
|
|
615
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);
|
|
616
624
|
}
|
|
617
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');
|
|
618
632
|
td.style.textAlign = column.align;
|
|
619
633
|
td.style.whiteSpace = column.white_space ?? '';
|
|
620
634
|
td.style.overflowWrap = column.white_space === 'pre-wrap' || column.white_space === 'normal' ? 'anywhere' : '';
|
|
@@ -643,7 +657,8 @@ export const Grid = defineComponent({
|
|
|
643
657
|
#renderCells(row, cells) {
|
|
644
658
|
const offset = Number(this.#rowHeaders);
|
|
645
659
|
cells.forEach((text, index) => {
|
|
646
|
-
|
|
660
|
+
const content = row.cells[index + offset].firstElementChild;
|
|
661
|
+
if (content.textContent !== text) content.textContent = text;
|
|
647
662
|
});
|
|
648
663
|
}
|
|
649
664
|
}
|
package/src/components/inputs.js
CHANGED
|
@@ -198,7 +198,7 @@ export const ComboBox = defineComponent({
|
|
|
198
198
|
parameters: {values: {dtype: 'T', default: '', binding: 'read'}, separator: {dtype: 'T', default: ',', binding: 'read'},
|
|
199
199
|
store: {dtype: 'X', nullable: true, default: null, binding: 'read'}},
|
|
200
200
|
implementation: Base => class extends localChoices(Base) {
|
|
201
|
-
get constrained() { return false; }
|
|
201
|
+
static get constrained() { return false; }
|
|
202
202
|
}
|
|
203
203
|
});
|
|
204
204
|
export const DbSelect = defineComponent({
|
|
@@ -209,7 +209,7 @@ export const DbSelect = defineComponent({
|
|
|
209
209
|
export const DbComboBox = defineComponent({
|
|
210
210
|
name:'dbComboBox', tag:'gramlot-db-combo-box', base:ChoiceEditor, mixins:[Labelbox, FieldState],
|
|
211
211
|
parameters:databaseParameters, implementation:Base => class extends databaseChoices(Base) {
|
|
212
|
-
get constrained() { return false; }
|
|
212
|
+
static get constrained() { return false; }
|
|
213
213
|
}
|
|
214
214
|
});
|
|
215
215
|
export const CheckBoxText = defineComponent({
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/** Resolve descriptor defaults once and return attributes owned by other layers. */
|
|
2
2
|
export function projectParameters(element, attrs) {
|
|
3
|
-
element.parameters =
|
|
4
|
-
.map(([name, spec]) => [name, Object.hasOwn(attrs, name) ? attrs[name] : spec.default]));
|
|
3
|
+
element.parameters = parameterValues(element.constructor.gramlotComponent,attrs);
|
|
5
4
|
return Object.fromEntries(Object.entries(attrs).filter(([name]) => !Object.hasOwn(element.parameters, name)));
|
|
6
5
|
}
|
|
6
|
+
|
|
7
|
+
export function parameterValues(component,attrs) {
|
|
8
|
+
return Object.fromEntries(Object.entries(component.parameters)
|
|
9
|
+
.map(([name,spec]) => [name,Object.hasOwn(attrs,name) ? attrs[name] : spec.default]));
|
|
10
|
+
}
|
package/src/components/tree.js
CHANGED
|
@@ -295,6 +295,7 @@ export const Tree = defineComponent({
|
|
|
295
295
|
const initial = this.#checkedPaths === undefined;
|
|
296
296
|
this.#checkedPaths = this.parameters.checkedPaths;
|
|
297
297
|
for (const {node} of items.values()) {
|
|
298
|
+
if (node.attr.checked === 'disabled:on' || node.attr.checked === 'disabled:off') continue;
|
|
298
299
|
if (!initial || this.#checkedPaths !== null) node.setAttr({checked: false});
|
|
299
300
|
}
|
|
300
301
|
for (const path of (this.#checkedPaths || '').split(this.parameters.checkedPaths_joiner).filter(Boolean)) {
|
|
@@ -119,8 +119,8 @@ TypedEditor.parameters = {...NativeControl.parameters,
|
|
|
119
119
|
|
|
120
120
|
export const numberEditor = Base => class extends Base {
|
|
121
121
|
createControl() { const control = super.createControl(); control.inputMode = 'decimal'; return control; }
|
|
122
|
-
validationValueCheck() {
|
|
123
|
-
const isDecimal =
|
|
122
|
+
static validationValueCheck(context) {
|
|
123
|
+
const isDecimal = context.isDecimal;
|
|
124
124
|
return value => checkNumber(value,isDecimal);
|
|
125
125
|
}
|
|
126
126
|
checkValue(value) { checkNumber(value,this.pageContext.isDecimal); }
|
|
@@ -231,7 +231,7 @@ export const dateEditor = Base => class extends Base {
|
|
|
231
231
|
}
|
|
232
232
|
releaseControl() { this.closeCalendar(); super.releaseControl(); }
|
|
233
233
|
context() { return {...super.context(), dtype: 'D', pattern: this.parameters.format ?? 'short'}; }
|
|
234
|
-
validationValueCheck() { return checkCivilDate; }
|
|
234
|
+
static validationValueCheck() { return checkCivilDate; }
|
|
235
235
|
checkValue(value) { checkCivilDate(value); }
|
|
236
236
|
editText(value, context) { return this.pageContext.format(value, {...context, pattern: 'short'}); }
|
|
237
237
|
parse(text, context) {
|
|
@@ -248,7 +248,7 @@ export const dateEditor = Base => class extends Base {
|
|
|
248
248
|
|
|
249
249
|
export const timeEditor = Base => class extends Base {
|
|
250
250
|
context() { return {...super.context(), dtype: 'H', pattern: this.parameters.format ?? 'short'}; }
|
|
251
|
-
validationValueCheck() { return checkTime; }
|
|
251
|
+
static validationValueCheck() { return checkTime; }
|
|
252
252
|
checkValue(value) { checkTime(value); }
|
|
253
253
|
editText(value) {
|
|
254
254
|
return `${pad(value.getUTCHours())}:${pad(value.getUTCMinutes())}:${pad(value.getUTCSeconds())}` +
|
|
@@ -72,7 +72,7 @@ function remoteArguments(parameters) {
|
|
|
72
72
|
}
|
|
73
73
|
function fail(errorcode, message, extra = {}) { return {errorcode, message, ...extra}; }
|
|
74
74
|
function localRule(rule, param, value, context) {
|
|
75
|
-
if (rule === 'select') return context.selection(value);
|
|
75
|
+
if (rule === 'select') return context.selection(value,context.signal);
|
|
76
76
|
if (rule === 'notnull') return empty(value) && param ? fail('notnull', 'A value is required.', {required:true}) : null;
|
|
77
77
|
if (rule === 'empty') return empty(value) ? {value:param} : null;
|
|
78
78
|
if (rule === 'len') {
|
package/src/editing-session.d.ts
CHANGED