@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
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {validateCatalogue} from '../visual-editor-catalogue.js';
|
|
2
|
+
import {Bag} from '@genrojs/bag';
|
|
3
|
+
import {sourceTarget} from '@genrojs/builders';
|
|
4
|
+
import {toolIcons} from '../visual-editor-icons.js';
|
|
5
|
+
|
|
6
|
+
export class VisualEditor {
|
|
7
|
+
constructor(root, {datapath = '__editor', dataRoot = '', editorId = 'visual', uploadOperation = 'import_source', codeDocument = null, catalogue = null, fileCommands = true, canvasCss = null, ...attributes} = {}) {
|
|
8
|
+
if (!/^[A-Za-z][A-Za-z0-9_]*$/.test(editorId)) throw new Error('editorId must be a literal identifier');
|
|
9
|
+
if (!dataRoot && datapath !== '__editor' && !datapath.startsWith('__editor.')) throw new Error('Root Data editing requires an __editor datapath');
|
|
10
|
+
validateCatalogue(catalogue);
|
|
11
|
+
if (canvasCss != null && (!Array.isArray(canvasCss) || canvasCss.some(text => typeof text !== 'string')))
|
|
12
|
+
throw new TypeError('canvasCss must be a list of CSS texts');
|
|
13
|
+
this.dataRoot = dataRoot;
|
|
14
|
+
const pane = this.pane = root.main({node_label:editorId, datapath, visualEditorId:editorId, ...attributes, nodeId:`${editorId}Editor`, class:`visual-editor-shell ${attributes.class ?? ''}`, overflow:'hidden', tabindex:0, connect_onkeydown:'clipboardShortcut'});
|
|
15
|
+
pane.dataSetter({destination_path:'.catalogueScope', value:catalogue});
|
|
16
|
+
pane.dataSetter({destination_path:'.canvasCss', value:canvasCss});
|
|
17
|
+
pane.dataSetter({destination_path:'.uploadQueue', value:new Bag()});
|
|
18
|
+
pane.dataController({func:'initializeEditor', dataRoot:this.dataRoot, _init:true});
|
|
19
|
+
pane.dataController({func:'showProperties', path:'^.selection', _init:true});
|
|
20
|
+
pane.dataController({func:'initializeCanvasSelection', _onBuilt:true});
|
|
21
|
+
pane.dataController({func:'initializeDocument', _onBuilt:true});
|
|
22
|
+
pane.dataController({func:'highlightSelection', path:'^.selection', _init:true});
|
|
23
|
+
pane.style('^.appearanceCss');
|
|
24
|
+
pane.dataController({func:'initializeEditorAppearance', _onBuilt:true});
|
|
25
|
+
pane.dataController({func:'applyEditorAppearance', profile:'^.appearanceProfile', palette:'^.appearancePalette', mode:'^.appearanceMode'});
|
|
26
|
+
const rail = this.rail = pane.menu({presentation:'bar', orientation:'vertical', aria_label:'Editor panels', class:'visual-editor-rail'});
|
|
27
|
+
this.toolButton(rail.menuline({group:true, overflowable:false}), 'Source / Data', 'toggleNavigation', toolIcons.navigation);
|
|
28
|
+
this.toolButton(rail.menuline({group:true, overflowable:false}), 'Catalogue', 'openCatalogue', toolIcons.catalogue);
|
|
29
|
+
this.toolButton(rail.menuline({group:true, overflowable:false}), 'Properties', 'openProperties', toolIcons.properties);
|
|
30
|
+
this.toolButton(rail.menuline({group:true, overflowable:false}), 'Clipboard', "this.SET('.clipboardVisible', !this.GET('.clipboardVisible'))", toolIcons.paste,
|
|
31
|
+
{dropTarget:true, dropTypes:'app/source', dropTags:`${editorId}Source`, dropEffect:'^.clipboardDropEffect',
|
|
32
|
+
connect_ondragover:'clipboardModifiers', connect_ondrop:'clipboardModifiers', onDrop:'dropClipboard'});
|
|
33
|
+
rail.spacer({flex:1});
|
|
34
|
+
this.toolButton(rail.menuline({group:true, overflowable:false}), 'Appearance', "this.SET('.appearanceOpen', !this.GET('.appearanceOpen'))", toolIcons.appearance);
|
|
35
|
+
const layoutRoot = pane.framePane({node_label:'layout', height:'100%', id:`${editorId}-editor-frame`, class:'visual-editor-layout'});
|
|
36
|
+
layoutRoot.top.setAttr({height:'30px'});
|
|
37
|
+
const toolbar = layoutRoot.top.menu({presentation:'bar', aria_label:'Editor tools', class:'visual-editor-toolbar'});
|
|
38
|
+
toolbar.menuline({group:true, overflowable:false}).span('Source editor', {class:'visual-editor-brand'});
|
|
39
|
+
const files = toolbar.menuline({group:true, overflowable:false, gap:'4px', hidden:!fileCommands});
|
|
40
|
+
for (const [caption,action,icon] of [['New','newPage','new'],['Open','openUpload','open'],['Download','downloadPage','download'],['Copy Source','copySource','copy']])
|
|
41
|
+
this.toolButton(files,caption,action,toolIcons[icon],{id:`${editorId}-${icon}`});
|
|
42
|
+
toolbar.menuline({group:true, overflowable:false}).span({class:'visual-toolbar-divider', aria_hidden:'true'});
|
|
43
|
+
const edit = toolbar.menuline({group:true, overflowable:false, gap:'2px'});
|
|
44
|
+
this.toolButton(edit,'Cut branch','cutBranch',toolIcons.cut,{title:'Cut branch (F8)'});
|
|
45
|
+
this.toolButton(edit,'Copy branch','copyBranch',toolIcons.copy);
|
|
46
|
+
this.toolButton(edit,'Paste branch','pasteBranch',toolIcons.paste,{title:'Paste branch (F9)'});
|
|
47
|
+
toolbar.spacer({flex:1});
|
|
48
|
+
toolbar.menuline({group:true, overflowable:false, hidden:'^.modified:=!{}'}).span('Unsaved changes', {role:'status', class:'visual-editor-hint'});
|
|
49
|
+
toolbar.menuline({group:true, overflowable:false}).span('^.fileStatus', {role:'status', class:'visual-editor-file-status'});
|
|
50
|
+
toolbar.menuline({group:true, overflowable:false}).span('^.filename', {class:'visual-editor-filename'});
|
|
51
|
+
const left = layoutRoot.left;
|
|
52
|
+
left.setAttr({width:'min(240px, 34vw)', splitter:true,
|
|
53
|
+
drawer:'^.navigationOpen', default_drawer:true, drawer_label:'Source / Data',
|
|
54
|
+
drawer_onclick:"this.SET('.navigationOpen', show ? true : 'close')",
|
|
55
|
+
display:'flex', flex_direction:'column', min_height:0, class:'visual-editor-sidebar'});
|
|
56
|
+
const sidebar = left.borderContainer({height:'100%', flex:1, min_height:0});
|
|
57
|
+
const navigation = sidebar.contentPane({region:'center'}).borderContainer({height:'100%', min_height:0});
|
|
58
|
+
const sourceStack = navigation.contentPane({region:'center'}).borderContainer({height:'100%', min_height:0});
|
|
59
|
+
const source = sourceStack.contentPane({node_label:'source', region:'center', title:'Source', detachable:true,
|
|
60
|
+
display:'flex', flex_direction:'column', min_height:0, overflow:'hidden'});
|
|
61
|
+
this.search(source, 'sourceSearch', 'Search Source');
|
|
62
|
+
source.tree({storepath:`*S.${sourceTarget(pane).fullpath.split('.').slice(1).join('.')}.layout.center.design`, hideValues:true, getLabel:'sourceLabel', searchText:'^.sourceSearch', selectedPath:'^.selection',
|
|
63
|
+
draggable:true, dragTags:`${editorId}Source`, effectAllowed:'all', onDrag:'prepareSource', dropTarget:true,
|
|
64
|
+
dropTypes:'app/widget,app/source,app/clipboard', dropTags:`widget,${editorId}Source,${editorId}Clipboard`, dropEffect:'^.sourceDropEffect', onDrop:'dropNode',
|
|
65
|
+
id:`${editorId}-source-tree`, class:'visual-source-tree', flex:1, min_height:0});
|
|
66
|
+
const shelf = sourceStack.contentPane({node_label:'clipboard', region:'bottom', height:'112px', splitter:true, minSize:80, title:'Clipboard', detachable:true, hidden:'^.clipboardVisible:=!{}', display:'flex', flex_direction:'column',
|
|
67
|
+
min_height:0, overflow:'hidden', dropTarget:true, dropTypes:'app/source', dropTags:`${editorId}Source`,
|
|
68
|
+
dropEffect:'^.clipboardDropEffect', connect_ondragover:'clipboardModifiers', connect_ondrop:'clipboardModifiers',
|
|
69
|
+
onDrop:'dropClipboard', class:'visual-clipboard'});
|
|
70
|
+
shelf.span('Drop a branch here · Option to copy', {class:'visual-editor-hint'});
|
|
71
|
+
shelf.tree({storepath:'.clipboard', hideValues:true, labelAttribute:'name', selectedPath:'^.clipboardSelection',
|
|
72
|
+
draggable:true, dragTags:`${editorId}Clipboard`, effectAllowed:'copy', onDrag:'prepareClipboard',
|
|
73
|
+
id:`${editorId}-clipboard-tree`, class:'visual-clipboard-tree', flex:1, min_height:0});
|
|
74
|
+
shelf.p('^.error', {role:'alert', class:'visual-editor-hint'});
|
|
75
|
+
const data = navigation.contentPane({node_label:'data', region:'bottom', title:'Data', detachable:true, height:'108px', splitter:true, minSize:80, display:'flex', flex_direction:'column', min_height:0, overflow:'hidden'});
|
|
76
|
+
this.search(data, 'dataSearch', 'Search Data');
|
|
77
|
+
data.tree({storepath:this.dataRoot ? `*D.${this.dataRoot}` : '*D', excludeRoot:this.dataRoot ? null : '__editor', searchText:'^.dataSearch', id:`${editorId}-data-tree`, flex:1, min_height:0});
|
|
78
|
+
const center = layoutRoot.center;
|
|
79
|
+
center.setAttr({overflow:'auto', class:'visual-editor-workspace'});
|
|
80
|
+
const design = center.div({node_label:'design', class:'visual-editor-canvas'});
|
|
81
|
+
design.div({node_label:'pageRoot', ...(this.dataRoot ? {datapath:this.dataRoot} : {})});
|
|
82
|
+
const window = pane.floatingPane({title:'Widget catalogue', open:'^.catalogueOpen', default_open:false, width:'280px', height:'400px', class:'visual-editor-popup', movable:true, resizable:true});
|
|
83
|
+
this.search(window.frame.top, 'catalogueSearch', 'Search widgets');
|
|
84
|
+
window.frame.center.tree({storepath:'.catalogue', hideValues:true, labelAttribute:'caption', searchText:'^.catalogueSearch',
|
|
85
|
+
draggable:true, dragTags:'widget', effectAllowed:'all', onDrag:'prepareWidget', id:`${editorId}-widget-tree`});
|
|
86
|
+
const properties = sidebar.contentPane({region:'bottom', height:'^.propertiesHeight', default_height:'200px', minSize:140, splitter:true,
|
|
87
|
+
title:'^.propertiesTitle', detachable:true, hidden:'^.propertiesOpen:=!{}',
|
|
88
|
+
display:'flex', flex_direction:'column', overflow:'hidden', min_height:0});
|
|
89
|
+
properties.div({nodeId:`${editorId}EditorFields`, class:'visual-editor-fields', display:'flex', flex_direction:'column', flex:1, min_height:0}).span('');
|
|
90
|
+
properties.p('^.propertyError', {role:'alert', class:'visual-editor-hint', margin:'3px'});
|
|
91
|
+
const uploader = pane.dialog({class:'visual-editor-popup', title:'Open Source', open:'^.uploadOpen', width:'480px', height:'300px', movable:true, resizable:true});
|
|
92
|
+
uploader.frame.center.uploader({operation:uploadOperation, storepath:'.uploadQueue', accept:'.grmlt',
|
|
93
|
+
multiple:false, autoUpload:true, onComplete:'sourceUploaded', id:`${editorId}-uploader`});
|
|
94
|
+
const naming = pane.dialog({class:'visual-editor-popup', title:'Save branch to clipboard', open:'^.clipboardOpen', width:'380px', height:'210px'});
|
|
95
|
+
naming.frame.center.textbox({value:'^.clipboardDraft.name', lbl:'Name', margin:'12px'});
|
|
96
|
+
naming.frame.center.p('^.error', {role:'alert', margin:'12px'});
|
|
97
|
+
const namingBar = naming.frame.bottom.menu({presentation:'bar', aria_label:'Clipboard commands', padding:'3px 6px'});
|
|
98
|
+
namingBar.spacer({flex:1});
|
|
99
|
+
const namingButtons = namingBar.menuline({group:true, overflowable:false, gap:'8px'});
|
|
100
|
+
namingButtons.button('Cancel', {action:"this.SET('.clipboardOpen', false)"});
|
|
101
|
+
namingButtons.button('Save branch', {action:'saveClipboard'});
|
|
102
|
+
const dialog = pane.dialog({class:'visual-editor-popup', title:'Required parameters', open:'^.insertionOpen', width:'400px', height:'280px', movable:true, resizable:true});
|
|
103
|
+
dialog.frame.center.div({nodeId:`${editorId}InsertFields`, class:'visual-editor-fields', padding:'6px'}).span('');
|
|
104
|
+
dialog.frame.center.p('^.error', {role:'alert'});
|
|
105
|
+
const bar = dialog.frame.bottom.menu({presentation:'bar', aria_label:'Insertion commands', padding:'3px 6px', border_top:'1px solid var(--gramlot-border)'});
|
|
106
|
+
bar.spacer({flex:1});
|
|
107
|
+
const buttons = bar.menuline({group:true, overflowable:false, gap:'8px'});
|
|
108
|
+
buttons.button('Cancel', {action:"this.SET('.insertionOpen', false)"});
|
|
109
|
+
buttons.button('Insert', {action:'insertWidget'});
|
|
110
|
+
const settings = pane.floatingPane({class:'visual-editor-popup', title:'Appearance', open:'^.appearanceOpen', default_open:false, width:'280px', height:'260px', movable:true, resizable:true});
|
|
111
|
+
const form = settings.frame.center.formlet({columns:1, lbl_position:'TL', gap:'4px', padding:'6px'});
|
|
112
|
+
form.filteringSelect({validate_notnull:true, lbl:'Theme', value:'^.appearanceProfile', values:'base:Base,compact:Compact,mimi:Mimi,joanna:Joanna,mela:Mela'});
|
|
113
|
+
form.filteringSelect({validate_notnull:true, lbl:'Colors', value:'^.appearancePalette', values:'default:Theme default,compact:Blue & slate,mimi:Sage & green,joanna:Warm gray & blue'});
|
|
114
|
+
form.filteringSelect({validate_notnull:true, lbl:'Mode', value:'^.appearanceMode', values:'light:Light,dark:Dark'});
|
|
115
|
+
pane.p('^.error', {role:'alert', class:'visual-editor-error', hidden:'^.error:=!{}'});
|
|
116
|
+
this.frame = layoutRoot; this.toolbar = toolbar; this.design = design;
|
|
117
|
+
if (codeDocument !== null) this.codeDocument(codeDocument);
|
|
118
|
+
}
|
|
119
|
+
toolButton(parent, caption, action, icon, attributes = {}) {
|
|
120
|
+
const button = parent.button({aria_label:caption, title:caption, action, class:'button--quiet visual-editor-tool', ...attributes});
|
|
121
|
+
button.span({class:'visual-tool-icon', aria_hidden:'true', style:`mask-image:url("${icon}")`});
|
|
122
|
+
return button;
|
|
123
|
+
}
|
|
124
|
+
codeDocument(document, frame = this.frame) {
|
|
125
|
+
if (!['python', 'javascript'].includes(document.language)) throw new TypeError('Expected a Python or JavaScript page document');
|
|
126
|
+
const pane = this.pane;
|
|
127
|
+
pane.setAttr({codeDocumentKey:document.key});
|
|
128
|
+
pane.dataSetter({destination_path:'.codeDocument', value:new Bag({...document, saved:document.content, busy:false, status:''})});
|
|
129
|
+
const anchor = `#${pane.getAttr('visualEditorId')}Editor`;
|
|
130
|
+
const opener = frame === this.frame ? this.toolbar : frame.top.menu({presentation:'bar', aria_label:'Code drawer'});
|
|
131
|
+
opener.menuline({group:true, overflowable:false}).button('Code', {action:'openCode', class:'button--quiet'});
|
|
132
|
+
const drawer = frame.right;
|
|
133
|
+
drawer.setAttr({class:'visual-editor-code', datapath:anchor, title:'Page code', detachable:true, width:'60%', minSize:240, splitter:true,
|
|
134
|
+
drawer:'^.codeOpen', default_drawer:'close', drawer_label:'Code', drawer_minimize:false,
|
|
135
|
+
drawer_onclick:"this.SET('.codeOpen', show ? true : 'close')", min_height:0, overflow:'hidden'});
|
|
136
|
+
const code = drawer.framePane({height:'100%', width:'100%', min_width:0, flex:1});
|
|
137
|
+
code.top.setAttr({height:'26px'}); code.bottom.setAttr({height:'48px'});
|
|
138
|
+
code.center.setAttr({display:'flex', flex_direction:'column', min_height:0, overflow:'hidden'});
|
|
139
|
+
code.top.div(document.path, {padding:'3px 6px', font_size:'12px', overflow:'hidden', text_overflow:'ellipsis', white_space:'nowrap'});
|
|
140
|
+
code.center.codeMirror({value:'^.codeDocument.content', language:document.language, live:true, readonly:'^.codeDocument.writable:=!{}', height:'100%', box_height:'100%', box_c_height:'100%', box_min_height:0, box_c_min_height:0, fontSize:13, flex:1, min_height:0});
|
|
141
|
+
code.bottom.div('^.codeDocument.status', {role:'status', font_size:'12px', padding:'4px 10px'});
|
|
142
|
+
const bar = code.bottom.menu({presentation:'bar', aria_label:'Page code commands', padding:'3px 6px'});
|
|
143
|
+
bar.spacer({flex:1});
|
|
144
|
+
const commands = bar.menuline({group:true, overflowable:false, gap:'6px'});
|
|
145
|
+
commands.button('Close', {action:"this.SET('.codeOpen', 'close')"});
|
|
146
|
+
commands.button('Preview saved', {action:'codePreview', disabled:'^.codeDocument.busy'});
|
|
147
|
+
commands.button('Save', {action:'codeSave', disabled:'^.codeSaveDisabled'});
|
|
148
|
+
pane.dataFormula({result_path:'.codeSaveDisabled', formula:'!writable || busy || content === saved',
|
|
149
|
+
writable:'^.codeDocument.writable', busy:'^.codeDocument.busy', content:'^.codeDocument.content', saved:'^.codeDocument.saved', _init:true});
|
|
150
|
+
}
|
|
151
|
+
search(pane, path, label) {
|
|
152
|
+
const bar = pane.menu({presentation:'bar', aria_label:label, class:'visual-search-toolbar'});
|
|
153
|
+
const field = bar.menuline({group:true, overflowable:false, flex:1, min_width:0}).div({class:'visual-search-field'});
|
|
154
|
+
field.span({class:'visual-search-icon', aria_hidden:'true'});
|
|
155
|
+
field.input({type:'search', value:`^.${path}`, default:'', live:true, placeholder:label, aria_label:label});
|
|
156
|
+
field.html_button({type:'button', class:'visual-search-clear', aria_label:`Clear ${label.toLowerCase()}`,
|
|
157
|
+
hidden:`^.${path}:={} === ''`, connect_onclick:`this.SET('.${path}', '')`});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type {SourceBagNode} from '@genrojs/builders';
|
|
2
|
+
import type {GramlotRenderer} from './renderer/gramlot-renderer.js';
|
|
3
|
+
|
|
4
|
+
/** Reusable, lifecycle-bound selection of rendered Source nodes in an editor preview. */
|
|
5
|
+
export class SourcePicker {
|
|
6
|
+
constructor(options: {renderer: GramlotRenderer; root: SourceBagNode; canvas?:Element; onSelect: (node: SourceBagNode) => void});
|
|
7
|
+
select(node: SourceBagNode | null): void;
|
|
8
|
+
dispose(): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Select rendered Source descendants in an editor preview without activating them. */
|
|
2
|
+
export class SourcePicker {
|
|
3
|
+
#renderer; #root; #canvas; #onSelect; #observer; #selectedPath = null;
|
|
4
|
+
#highlighted = null; #release = null; #disposed = false;
|
|
5
|
+
constructor({renderer, root, onSelect, canvas = renderer.records.get(root.parentNode)?.presentation}) {
|
|
6
|
+
if (!root?.parentNode || typeof onSelect !== 'function') throw new TypeError('SourcePicker requires a mounted Source root and onSelect');
|
|
7
|
+
if (!canvas || canvas.nodeType !== 1) throw new TypeError('SourcePicker requires a mounted preview');
|
|
8
|
+
this.#renderer = renderer; this.#root = root; this.#canvas = canvas; this.#onSelect = onSelect;
|
|
9
|
+
canvas.addEventListener('pointerdown', this, true);
|
|
10
|
+
canvas.addEventListener('click', this, true);
|
|
11
|
+
this.#observer = new canvas.ownerDocument.defaultView.MutationObserver(() => this.#paint());
|
|
12
|
+
this.#observer.observe(canvas, {subtree:true, childList:true, attributes:true, attributeFilter:['class']});
|
|
13
|
+
this.#release = renderer.onDispose(root.parentNode, () => this.dispose());
|
|
14
|
+
}
|
|
15
|
+
handleEvent(event) {
|
|
16
|
+
if (this.#disposed) return;
|
|
17
|
+
const prefix = this.#root.fullpath + '.';
|
|
18
|
+
const record = event.composedPath().map(element => this.#renderer.elements.get(element)).find(item =>
|
|
19
|
+
item?.node.fullpath.startsWith(prefix));
|
|
20
|
+
if (!record) return;
|
|
21
|
+
const editing = event.composedPath().some(element => element.nodeType === 1 && (
|
|
22
|
+
element.matches('input:not([type=button]):not([type=submit]):not([type=reset]):not([type=image]), textarea, select, label') ||
|
|
23
|
+
element.isContentEditable));
|
|
24
|
+
if (!editing) { event.preventDefault(); event.stopImmediatePropagation(); }
|
|
25
|
+
this.#onSelect(record.node);
|
|
26
|
+
}
|
|
27
|
+
select(node) {
|
|
28
|
+
if (this.#disposed) return;
|
|
29
|
+
if (node === null) this.#selectedPath = null;
|
|
30
|
+
else {
|
|
31
|
+
const prefix = this.#root.fullpath + '.';
|
|
32
|
+
if (!node.fullpath.startsWith(prefix)) throw new TypeError('Selected node must be inside the preview Source root');
|
|
33
|
+
this.#selectedPath = node.fullpath.slice(prefix.length);
|
|
34
|
+
}
|
|
35
|
+
this.#paint();
|
|
36
|
+
}
|
|
37
|
+
#paint() {
|
|
38
|
+
if (this.#disposed) return;
|
|
39
|
+
const node = this.#selectedPath ? this.#root.staticValue.getNode(this.#selectedPath) : null;
|
|
40
|
+
const element = node ? this.#renderer.records.get(node)?.presentation : null;
|
|
41
|
+
const next = element?.nodeType === 1 ? element : null;
|
|
42
|
+
if (this.#highlighted !== next) {
|
|
43
|
+
this.#highlighted?.classList.remove('gramlot-source-selected');
|
|
44
|
+
this.#highlighted = next;
|
|
45
|
+
}
|
|
46
|
+
if (next && !next.classList.contains('gramlot-source-selected')) next.classList.add('gramlot-source-selected');
|
|
47
|
+
}
|
|
48
|
+
dispose() {
|
|
49
|
+
if (this.#disposed) return;
|
|
50
|
+
this.#disposed = true; this.#observer.disconnect();
|
|
51
|
+
this.#canvas.removeEventListener('pointerdown', this, true);
|
|
52
|
+
this.#canvas.removeEventListener('click', this, true);
|
|
53
|
+
this.#highlighted?.classList.remove('gramlot-source-selected');
|
|
54
|
+
this.#release?.(); this.#release = null; this.#highlighted = null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {BagResolver} from '@genrojs/bag';
|
|
2
|
+
import type {Bag, BagNode} from '@genrojs/bag';
|
|
3
|
+
import type {SourceBagNode} from '@genrojs/builders';
|
|
4
|
+
import type {Gramlot} from './gramlot.js';
|
|
5
|
+
|
|
6
|
+
export class TreeStoreResolver extends BagResolver {
|
|
7
|
+
constructor(options?: {readOnly?: boolean});
|
|
8
|
+
bind(store: TreeStore, path: string): void;
|
|
9
|
+
load(): Promise<Bag>;
|
|
10
|
+
}
|
|
11
|
+
export class TreeStore {
|
|
12
|
+
constructor(options: {gramlot: Gramlot; method: string; params?: Record<string, unknown>});
|
|
13
|
+
pathFor(node: BagNode): string;
|
|
14
|
+
load(path?: string, label?: string | null, attributes?: Record<string, unknown>): Promise<Bag>;
|
|
15
|
+
dispose(): void;
|
|
16
|
+
}
|
|
17
|
+
export class TreeStoreLogic {
|
|
18
|
+
treeStoreMount(node: SourceBagNode, args: {storeMethod: string; storeParams: Record<string, unknown>}): Promise<void>;
|
|
19
|
+
treeFavoritesMount(node: SourceBagNode, args: {favoriteKey: string}): void;
|
|
20
|
+
treeFavoriteActionState(node: SourceBagNode, args: {item: BagNode; state: Bag}): {hidden: boolean; icon: string; title: string};
|
|
21
|
+
treeFavoriteToggle(node: SourceBagNode, args: {item: BagNode; path: string; favoriteKey: string}): void;
|
|
22
|
+
treeInspect(node: SourceBagNode, args: {item: BagNode; path: string}): void;
|
|
23
|
+
treeInspectClose(node: SourceBagNode, event: Event): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {Bag, BagResolver, registerResolver} from '@genrojs/bag';
|
|
2
|
+
import {fromTytx, toTytx} from '@genrojs/tytx';
|
|
3
|
+
import {GramlotBuilder} from './builder/gramlot-builder.js';
|
|
4
|
+
import {randomId} from './random-id.js';
|
|
5
|
+
|
|
6
|
+
/** A branch whose loader is supplied by its owning TreeStore after transport. */
|
|
7
|
+
export class TreeStoreResolver extends BagResolver {
|
|
8
|
+
constructor({readOnly = false} = {}) {
|
|
9
|
+
super({cacheTime: -1, readOnly});
|
|
10
|
+
this.store = null;
|
|
11
|
+
this.path = null;
|
|
12
|
+
this.pending = null;
|
|
13
|
+
}
|
|
14
|
+
bind(store, path) {
|
|
15
|
+
if (this.store !== null) throw new Error('TreeStoreResolver is already bound');
|
|
16
|
+
this.store = store;
|
|
17
|
+
this.path = path;
|
|
18
|
+
}
|
|
19
|
+
load() {
|
|
20
|
+
if (this.store === null) throw new Error('TreeStoreResolver is not bound to a store');
|
|
21
|
+
if (this.pending !== null) return this.pending;
|
|
22
|
+
const node = this.node;
|
|
23
|
+
const path = this.path ? this.store.pathFor(node) : '';
|
|
24
|
+
const pending = this.store.load(path, path ? node.label : null, path ? {...node.attr} : {});
|
|
25
|
+
this.pending = pending;
|
|
26
|
+
pending.finally(() => { if (this.pending === pending) this.pending = null; }).catch(() => {});
|
|
27
|
+
return pending;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
registerResolver(TreeStoreResolver, {
|
|
32
|
+
module: 'gramlot.tree_store', name: 'TreeStoreResolver',
|
|
33
|
+
encode: () => ({args: [], kwargs: {}}),
|
|
34
|
+
decode: () => new TreeStoreResolver(),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/** One RPC method supplies the root and every lazy branch of a Data Bag. */
|
|
38
|
+
export class TreeStore {
|
|
39
|
+
constructor({gramlot, method, params = {}}) {
|
|
40
|
+
if (!gramlot || typeof method !== 'string' || !method) throw new TypeError('TreeStore requires a page and method');
|
|
41
|
+
for (const key of ['path', 'label', 'attributes']) {
|
|
42
|
+
if (Object.hasOwn(params, key)) throw new TypeError(`TreeStore params reserves ${key}`);
|
|
43
|
+
}
|
|
44
|
+
this.gramlot = gramlot;
|
|
45
|
+
this.method = method;
|
|
46
|
+
this.params = {...params};
|
|
47
|
+
this.controller = new AbortController();
|
|
48
|
+
this.root = null;
|
|
49
|
+
}
|
|
50
|
+
pathFor(node) {
|
|
51
|
+
const labels = [];
|
|
52
|
+
while (node && node.parentBag !== this.root) {
|
|
53
|
+
labels.unshift(node.label);
|
|
54
|
+
node = node.parentNode;
|
|
55
|
+
}
|
|
56
|
+
if (!node || this.root === null) throw new Error('TreeStore node is outside its root');
|
|
57
|
+
labels.unshift(node.label);
|
|
58
|
+
return labels.join('.');
|
|
59
|
+
}
|
|
60
|
+
async load(path = '', label = null, attributes = {}) {
|
|
61
|
+
if (this.controller.signal.aborted) throw this.controller.signal.reason;
|
|
62
|
+
const result = await this.gramlot.rpc.call('data', this.method,
|
|
63
|
+
{...this.params, path, label, attributes}, {signal: this.controller.signal});
|
|
64
|
+
if (this.controller.signal.aborted) throw this.controller.signal.reason;
|
|
65
|
+
if (!(result instanceof Bag)) throw new TypeError('TreeStore method must return a Bag');
|
|
66
|
+
if (!path) {
|
|
67
|
+
this.root = result;
|
|
68
|
+
result.setBackref();
|
|
69
|
+
}
|
|
70
|
+
const bind = (bag, prefix) => {
|
|
71
|
+
for (const node of bag.getNodes()) {
|
|
72
|
+
const nodePath = prefix ? `${prefix}.${node.label}` : node.label;
|
|
73
|
+
if (node.resolver instanceof TreeStoreResolver) node.resolver.bind(this, nodePath);
|
|
74
|
+
if (node.staticValue instanceof Bag) bind(node.staticValue, nodePath);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
bind(result, path);
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
dispose() { this.controller.abort(); }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Source lifecycle for the Python tree_store composition. */
|
|
84
|
+
export class TreeStoreLogic {
|
|
85
|
+
treeFavoriteActionState(node, {item, state}) {
|
|
86
|
+
const hidden = item.resolver !== null || item.staticValue instanceof Bag;
|
|
87
|
+
if (item.getAttr('favoriteEntry') === true) return {hidden: false, icon: '✕', title: 'Remove favorite'};
|
|
88
|
+
const saved = !hidden && state.getNodes().some(favorite => favorite.getAttr('fieldpath') === item.getAttr('fieldpath'));
|
|
89
|
+
return {hidden, icon: saved ? '♥' : '♡', title: saved ? 'Remove favorite' : 'Add favorite'};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
treeFavoritesMount(node, {favoriteKey}) {
|
|
93
|
+
const storage = this.page.src.renderer.destination.ownerDocument.defaultView.localStorage;
|
|
94
|
+
const saved = storage.getItem(favoriteKey);
|
|
95
|
+
this.setTreeFavorites(node.getRelativeData('.'), saved === null ? [] : fromTytx(saved));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
setTreeFavorites(state, records) {
|
|
99
|
+
if (!Array.isArray(records)) throw new TypeError('Tree favorites must be an array');
|
|
100
|
+
const favorites = new Bag();
|
|
101
|
+
records.forEach((record, index) => {
|
|
102
|
+
if (!record || typeof record.fieldpath !== 'string' || typeof record.path !== 'string' ||
|
|
103
|
+
typeof record.caption !== 'string' || !record.attrs || typeof record.attrs !== 'object') {
|
|
104
|
+
throw new TypeError('Invalid tree favorite');
|
|
105
|
+
}
|
|
106
|
+
const attrs = {...record.attrs};
|
|
107
|
+
for (const name of ['caption', 'fullcaption']) {
|
|
108
|
+
if (typeof attrs[name] === 'string')
|
|
109
|
+
attrs[name] = attrs[name].replace(/(^|\.)!!(?:\[[^\]]+\])?/g, '$1');
|
|
110
|
+
}
|
|
111
|
+
favorites.setItem(`favorite_${index}`, null, {...attrs,
|
|
112
|
+
favoriteEntry: true, originalPath: record.path});
|
|
113
|
+
});
|
|
114
|
+
state.setItem('favorites', favorites);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
treeFavoriteToggle(node, {item, path, favoriteKey}) {
|
|
118
|
+
if (item.resolver || item.staticValue instanceof Bag) return;
|
|
119
|
+
const attrs = item.getAttr();
|
|
120
|
+
const state = node.getRelativeData('.');
|
|
121
|
+
const records = state.getItem('favorites').getNodes().map(favorite => {
|
|
122
|
+
const {favoriteEntry, originalPath, ...attributes} = favorite.getAttr();
|
|
123
|
+
return {fieldpath: attributes.fieldpath, path: originalPath, caption: attributes.caption, attrs: attributes};
|
|
124
|
+
});
|
|
125
|
+
const index = records.findIndex(record => record.fieldpath === attrs.fieldpath);
|
|
126
|
+
if (index === -1) records.push({fieldpath: attrs.fieldpath, path, caption: attrs.caption, attrs: {...attrs}});
|
|
127
|
+
else records.splice(index, 1);
|
|
128
|
+
const storage = this.page.src.renderer.destination.ownerDocument.defaultView.localStorage;
|
|
129
|
+
storage.setItem(favoriteKey, toTytx(records));
|
|
130
|
+
this.setTreeFavorites(state, records);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
treeStoreMount(node, {storeMethod, storeParams}) {
|
|
134
|
+
const scope = node.parentNode;
|
|
135
|
+
const state = node.getRelativeData('.');
|
|
136
|
+
const store = new TreeStore({gramlot: this.page, method: storeMethod, params: storeParams});
|
|
137
|
+
this.page.src.renderer.onDispose(scope, () => store.dispose());
|
|
138
|
+
const resolver = new TreeStoreResolver({readOnly: true});
|
|
139
|
+
resolver.bind(store, '');
|
|
140
|
+
state.setResolver('store', resolver);
|
|
141
|
+
return Promise.resolve(state.getItem('store')).then(value => {
|
|
142
|
+
if (!store.controller.signal.aborted) state.setItem('store', value);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
treeInspect(node, {item, path}) {
|
|
147
|
+
const binding = this.page.src.binding.bindingFor(node);
|
|
148
|
+
let closed = false;
|
|
149
|
+
const id = `tree_inspect_${randomId()}`;
|
|
150
|
+
let release = () => {};
|
|
151
|
+
const close = () => {
|
|
152
|
+
if (closed) return;
|
|
153
|
+
closed = true;
|
|
154
|
+
release();
|
|
155
|
+
if (this.page.src.source.getNode(id)) this.page.src.source.popNode(id);
|
|
156
|
+
};
|
|
157
|
+
release = binding.track(close);
|
|
158
|
+
try {
|
|
159
|
+
const builder = new GramlotBuilder();
|
|
160
|
+
const dialog = builder.root.html_dialog({nodeId: id, request: id,
|
|
161
|
+
connect_oncancel: 'treeInspectClose', connect_onclose: 'treeInspectClose',
|
|
162
|
+
'aria-labelledby': `${id}_title`,
|
|
163
|
+
style: 'width:min(36rem,calc(100% - 48px));max-height:80vh;overflow:auto;'});
|
|
164
|
+
dialog.h2('Attributes', {id: `${id}_title`});
|
|
165
|
+
dialog.p(`==${JSON.stringify(path)}`);
|
|
166
|
+
dialog.html_button('Close', {type: 'button', autofocus: true, request: id, connect_onclick: 'treeInspectClose'});
|
|
167
|
+
const table = dialog.table();
|
|
168
|
+
for (const [name, value] of Object.entries(item.getAttr())) {
|
|
169
|
+
const row = table.tr();
|
|
170
|
+
row.th(`==${JSON.stringify(name)}`, {scope: 'row'});
|
|
171
|
+
const text = typeof value === 'string' ? value : value === undefined ? 'undefined' : toTytx(value);
|
|
172
|
+
row.td(`==${JSON.stringify(text)}`);
|
|
173
|
+
}
|
|
174
|
+
this.page.src.source.setItem(id, this.page.src.prepareSource(builder.source));
|
|
175
|
+
const dialogNode = this.page.src.binding.nodeIds.get(id);
|
|
176
|
+
Object.defineProperty(dialogNode, 'treeInspectClose', {value: close, configurable: true});
|
|
177
|
+
this.page.src.renderer.onDispose(dialogNode, () => {
|
|
178
|
+
close();
|
|
179
|
+
delete dialogNode.treeInspectClose;
|
|
180
|
+
});
|
|
181
|
+
this.page.dom.getDomNode(dialogNode).showModal();
|
|
182
|
+
} catch (error) {
|
|
183
|
+
close();
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
treeInspectClose(node, event) {
|
|
189
|
+
event.preventDefault();
|
|
190
|
+
const dialog = this.page.src.binding.nodeIds.get(node.getAttr('request'));
|
|
191
|
+
if (dialog) dialog.treeInspectClose();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** One validation attempt lifecycle, independent of a mounted control. */
|
|
2
|
+
export class ValidationRun {
|
|
3
|
+
epoch = 0;
|
|
4
|
+
controller = null;
|
|
5
|
+
cancel() {
|
|
6
|
+
this.epoch++;
|
|
7
|
+
this.controller?.abort();
|
|
8
|
+
this.controller = null;
|
|
9
|
+
}
|
|
10
|
+
start(value, rules, context, execute, complete, pending = () => {}) {
|
|
11
|
+
this.cancel();
|
|
12
|
+
const controller = new AbortController(), epoch = this.epoch;
|
|
13
|
+
this.controller = controller;
|
|
14
|
+
const current = context.validationCurrent();
|
|
15
|
+
const isCurrent = () => epoch === this.epoch && !controller.signal.aborted && current();
|
|
16
|
+
const failure = error => ({value, modified:false, error:error.message, warnings:[], issues:[], datachanges:[]});
|
|
17
|
+
let settled = false;
|
|
18
|
+
const finish = result => {
|
|
19
|
+
if (settled || !isCurrent()) return {ok:false};
|
|
20
|
+
settled = true;
|
|
21
|
+
this.controller = null;
|
|
22
|
+
const outcome = {ok:!result.error, value:result.value, result, rules, isCurrent};
|
|
23
|
+
complete(outcome);
|
|
24
|
+
return outcome;
|
|
25
|
+
};
|
|
26
|
+
let result;
|
|
27
|
+
try {
|
|
28
|
+
if (rules.validate_timeout != null && (!Number.isInteger(rules.validate_timeout) || rules.validate_timeout <= 0)) {
|
|
29
|
+
throw new TypeError('validate_timeout must be a positive integer in milliseconds.');
|
|
30
|
+
}
|
|
31
|
+
result = execute(value, rules, {...context, signal:controller.signal});
|
|
32
|
+
} catch (error) { return finish(failure(error)); }
|
|
33
|
+
if (!(result instanceof Promise)) return finish(result);
|
|
34
|
+
pending();
|
|
35
|
+
return new Promise(resolve => {
|
|
36
|
+
let timer;
|
|
37
|
+
const abort = () => { clearTimeout(timer); resolve({ok:false}); };
|
|
38
|
+
controller.signal.addEventListener('abort', abort, {once:true});
|
|
39
|
+
const settle = answer => {
|
|
40
|
+
clearTimeout(timer);
|
|
41
|
+
controller.signal.removeEventListener('abort', abort);
|
|
42
|
+
try { resolve(finish(answer)); } catch (error) { context.reportError(error, 'Validation completion failed'); resolve({ok:false}); }
|
|
43
|
+
};
|
|
44
|
+
if (rules.validate_timeout != null) timer = setTimeout(() => {
|
|
45
|
+
settle(failure(new Error('Validation timed out.'))); controller.abort();
|
|
46
|
+
}, rules.validate_timeout);
|
|
47
|
+
result.then(settle, error => settle(failure(error)));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/view/button.js
CHANGED
|
@@ -122,6 +122,9 @@ export class ButtonBinding {
|
|
|
122
122
|
event.stopPropagation();
|
|
123
123
|
return target.activateCommand(event);
|
|
124
124
|
}
|
|
125
|
+
const rowActions = this.element.closest('gramlot-row-actions');
|
|
126
|
+
const rowContext = rowActions ? rowActions.getRowContext() : null;
|
|
127
|
+
if (rowActions && rowContext === null) return;
|
|
125
128
|
if (!this.element.prepareCommand(event)) return;
|
|
126
129
|
const mechanism = this.mechanism;
|
|
127
130
|
if (!mechanism) return;
|
|
@@ -143,7 +146,7 @@ export class ButtonBinding {
|
|
|
143
146
|
release();
|
|
144
147
|
this.#cancelDelay = null;
|
|
145
148
|
this.#pendingCount = 0;
|
|
146
|
-
this.#execute(event, count, activation);
|
|
149
|
+
this.#execute(event, count, activation, rowContext);
|
|
147
150
|
}, delay);
|
|
148
151
|
const release = this.binding.track(() => this.#cancelDelay?.());
|
|
149
152
|
this.#cancelDelay = () => {
|
|
@@ -156,7 +159,7 @@ export class ButtonBinding {
|
|
|
156
159
|
return;
|
|
157
160
|
}
|
|
158
161
|
this.#cancelDelay?.();
|
|
159
|
-
return this.#execute(event, counter, activation);
|
|
162
|
+
return this.#execute(event, counter, activation, rowContext);
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
async #executeRegistered(activation) {
|
|
@@ -175,7 +178,7 @@ export class ButtonBinding {
|
|
|
175
178
|
}
|
|
176
179
|
|
|
177
180
|
/** Deliver the last event once; arguments are read when the mechanism executes. */
|
|
178
|
-
#execute(event, counter, activation = null) {
|
|
181
|
+
#execute(event, counter, activation = null, rowContext = null) {
|
|
179
182
|
if (activation) return this.#executeRegistered(activation);
|
|
180
183
|
if (this.binding.closed || this.element.disabled) return;
|
|
181
184
|
const mechanism = this.mechanism;
|
|
@@ -184,12 +187,12 @@ export class ButtonBinding {
|
|
|
184
187
|
const modifiers = eventToString(event);
|
|
185
188
|
if (mechanism === 'controller') {
|
|
186
189
|
const provider = this.binding.runtime.bindingFor(this.controllers[0])?.providers[0];
|
|
187
|
-
provider?.invoke({kind: 'click', event, counter});
|
|
190
|
+
provider?.invoke({kind: 'click', event, counter, rowContext});
|
|
188
191
|
} else if (mechanism === 'action') {
|
|
189
192
|
const read = () => {
|
|
190
193
|
const [, attrs] = node.rootBuilder.runtimeValues(node);
|
|
191
194
|
const authored = Object.fromEntries(Object.entries(attrs).filter(([name]) => name !== 'ask'));
|
|
192
|
-
return {...this.binding.runtime.renderer.references.resolveArguments(authored), event, _counter: counter, modifiers};
|
|
195
|
+
return {...this.binding.runtime.renderer.references.resolveArguments(authored), ...rowContext, event, _counter: counter, modifiers};
|
|
193
196
|
};
|
|
194
197
|
const execute = result => {
|
|
195
198
|
if (this.binding.closed || this.element.disabled || result === null) return;
|