@gramlot/gramlot 0.3.40 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/icons/applications.svg +4 -0
- package/assets/icons/archive.svg +4 -0
- package/assets/icons/attachment.svg +4 -0
- package/assets/icons/book.svg +4 -0
- package/assets/icons/bookmark.svg +4 -0
- package/assets/icons/calendar.svg +4 -0
- package/assets/icons/cancel.svg +4 -0
- package/assets/icons/chart.svg +4 -1
- package/assets/icons/chat.svg +4 -0
- package/assets/icons/clock.svg +4 -0
- package/assets/icons/code.svg +4 -0
- package/assets/icons/collapse.svg +4 -0
- package/assets/icons/columns.svg +4 -0
- package/assets/icons/confirm.svg +4 -0
- package/assets/icons/copy.svg +4 -0
- package/assets/icons/cut.svg +4 -0
- package/assets/icons/database.svg +4 -0
- package/assets/icons/delete.svg +4 -0
- package/assets/icons/detach.svg +4 -0
- package/assets/icons/document.svg +4 -0
- package/assets/icons/download.svg +4 -0
- package/assets/icons/duplicate.svg +4 -0
- package/assets/icons/edit.svg +4 -0
- package/assets/icons/expand.svg +4 -0
- package/assets/icons/export.svg +4 -0
- package/assets/icons/eye.svg +4 -0
- package/assets/icons/filter.svg +4 -0
- package/assets/icons/first.svg +4 -0
- package/assets/icons/folder.svg +4 -0
- package/assets/icons/group.svg +4 -0
- package/assets/icons/help.svg +4 -0
- package/assets/icons/home.svg +4 -0
- package/assets/icons/import.svg +4 -0
- package/assets/icons/info.svg +4 -0
- package/assets/icons/inspector.svg +4 -0
- package/assets/icons/last.svg +4 -0
- package/assets/icons/layers.svg +4 -0
- package/assets/icons/link.svg +4 -0
- package/assets/icons/list.svg +4 -0
- package/assets/icons/lock.svg +4 -0
- package/assets/icons/logout.svg +4 -0
- package/assets/icons/navigation.svg +4 -0
- package/assets/icons/new.svg +4 -0
- package/assets/icons/next.svg +4 -0
- package/assets/icons/open.svg +4 -0
- package/assets/icons/palette.svg +4 -0
- package/assets/icons/panel-bottom.svg +4 -0
- package/assets/icons/panel-left.svg +4 -0
- package/assets/icons/panel-right.svg +4 -0
- package/assets/icons/panel-top.svg +4 -0
- package/assets/icons/paste.svg +4 -0
- package/assets/icons/pause.svg +4 -0
- package/assets/icons/pin.svg +4 -0
- package/assets/icons/play.svg +4 -0
- package/assets/icons/previous.svg +4 -0
- package/assets/icons/print.svg +4 -0
- package/assets/icons/redo.svg +4 -0
- package/assets/icons/refresh.svg +4 -0
- package/assets/icons/save.svg +4 -0
- package/assets/icons/search.svg +4 -0
- package/assets/icons/send.svg +4 -0
- package/assets/icons/settings.svg +4 -0
- package/assets/icons/sort-ascending.svg +4 -0
- package/assets/icons/sort-descending.svg +4 -0
- package/assets/icons/stop.svg +4 -0
- package/assets/icons/table.svg +4 -0
- package/assets/icons/tree.svg +4 -0
- package/assets/icons/undo.svg +4 -0
- package/assets/icons/unlock.svg +4 -0
- package/assets/icons/upload.svg +4 -0
- package/assets/icons/user.svg +4 -0
- package/assets/icons/warning.svg +4 -0
- package/assets/icons/zoom-in.svg +4 -0
- package/assets/icons/zoom-out.svg +4 -0
- package/dist/components/charts/__init__.py +1 -1
- package/dist/components/charts/assets/index.js +1 -1
- package/dist/components/charts/assets/libraries/vega.js +11 -11
- package/dist/components/editors/__init__.py +1 -1
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/libraries/codemirror.js +30 -31
- package/dist/components/editors/assets/libraries/jodit.js +3 -1
- package/dist/components/editors/assets/libraries/prosemirror.js +1 -1
- package/dist/components/editors/grammar.json +6 -1
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/commands.json +4 -6
- package/dist/components/grid/grammar.json +51 -0
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +4987 -216
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +69 -4
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +16 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +6 -6
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/uploads/grammar.json +66 -0
- package/dist/declared-collections.js +1 -1
- package/dist/gramlot.js +4007 -1256
- package/dist/gramlot.min.js +329 -131
- package/dist/libraries.json +1 -0
- package/dist/standard-collections.js +1 -1
- package/dist/standard-grammar.js +1 -1
- package/package.json +3 -1
- package/src/binding/ask-dialog.js +17 -3
- package/src/binding/data-binder.js +5 -0
- package/src/binding/providers.js +1 -1
- package/src/binding/runtime.js +6 -3
- package/src/builder/chart-icon.js +2 -0
- package/src/builder/gramlot-builder.d.ts +3 -1
- package/src/builder/gramlot-builder.js +26 -9
- package/src/builder/source.js +12 -3
- package/src/builder/xml-recipe.js +144 -0
- package/src/chat-file-types.js +13 -0
- package/src/chat.js +23 -25
- package/src/commands.d.ts +1 -1
- package/src/commands.js +1 -1
- package/src/components/border-container.js +64 -6
- package/src/components/buttons.js +26 -31
- package/src/components/chart-geographic-options.js +1 -1
- package/src/components/chart-pane.js +5 -5
- package/src/components/chart-spatial-options.js +5 -1
- package/src/components/check-box-text-editor.js +1 -0
- package/src/components/check-box-text.js +2 -0
- package/src/components/choice-editor.js +3 -2
- package/src/components/choice-field-styles.js +9 -1
- package/src/components/code-mirror-engine.js +18 -5
- package/src/components/code-mirror-gramlot.js +85 -0
- package/src/components/code-mirror.js +3 -2
- package/src/components/drawing.js +43 -14
- package/src/components/editor-options.js +1 -1
- package/src/components/graphical-ranges.js +177 -0
- package/src/components/grid-footer.js +6 -1
- package/src/components/grid-styles.js +11 -2
- package/src/components/grid-tools.js +15 -7
- package/src/components/grid.js +69 -8
- package/src/components/inputs.js +93 -23
- package/src/components/jodit-engine.js +3 -1
- package/src/components/menus.js +83 -25
- package/src/components/numeric-range.js +39 -0
- package/src/components/selected-container.js +109 -63
- package/src/components/tab-bar.js +371 -0
- package/src/components/toolbar-icon-style.js +22 -0
- package/src/components/toolbar-overflow.js +74 -12
- package/src/components/tree.js +12 -3
- package/src/components/typst-preview.js +3 -3
- package/src/components/upload-blocks.js +88 -0
- package/src/components/upload-engine.js +21 -31
- package/src/components/uploader.js +168 -47
- package/src/gramlot.js +6 -3
- package/src/handlers/dom-handler.d.ts +2 -0
- package/src/handlers/dom-handler.js +9 -0
- package/src/handlers/rpc-handler.d.ts +1 -1
- package/src/handlers/rpc-handler.js +2 -0
- package/src/handlers/source-handler.d.ts +5 -3
- package/src/handlers/source-handler.js +31 -13
- package/src/icons.js +84 -0
- package/src/index-page-runtime.js +9 -2
- package/src/index-page-styles.js +1 -1
- package/src/index-theme.js +210 -3
- package/src/index.d.ts +5 -1
- package/src/index.js +5 -1
- package/src/libraries.js +1 -1
- package/src/page-store-connection.js +44 -7
- package/src/renderer/gramlot-renderer.js +4 -1
- package/src/server/chat-attachments.js +139 -0
- package/src/server/chat.d.ts +31 -0
- package/src/server/chat.js +157 -0
- package/src/server/database-selectors.d.ts +6 -0
- package/src/server/database-selectors.js +13 -0
- package/src/server/gramlot-file-server.js +6 -1
- package/src/server/gramlot-server.d.ts +19 -3
- package/src/server/gramlot-server.js +144 -18
- package/src/server/index-page.d.ts +10 -0
- package/src/server/index-page.js +73 -8
- package/src/server/index.d.ts +1 -1
- package/src/server/index.js +1 -1
- package/src/server/page-base.js +4 -0
- package/src/server/page-store.d.ts +21 -0
- package/src/server/page-store.js +219 -0
- package/src/server/page.d.ts +6 -1
- package/src/server/page.js +5 -1
- package/src/server/store-recipe.js +102 -0
- package/src/server/toolbar-icon-name.d.ts +76 -0
- package/src/server/upload.d.ts +2 -0
- package/src/server/upload.js +36 -18
- package/src/server/visual-editor.js +4 -2
- package/src/tree-store.d.ts +5 -1
- package/src/tree-store.js +11 -2
- package/src/view/choice-focus.js +17 -0
- package/src/view/html.js +21 -1
- package/src/view/menu.js +9 -3
- package/src/visual-editor.js +6 -2
- package/themes/gramlot-base/theme.css +53 -28
- package/themes/gramlot-compact/theme.css +2 -0
- package/themes/gramlot-index/icons/applications.svg +4 -0
- package/themes/gramlot-index/icons/archive.svg +4 -0
- package/themes/gramlot-index/icons/attachment.svg +4 -0
- package/themes/gramlot-index/icons/book.svg +4 -0
- package/themes/gramlot-index/icons/bookmark.svg +4 -0
- package/themes/gramlot-index/icons/calendar.svg +4 -0
- package/themes/gramlot-index/icons/cancel.svg +4 -0
- package/themes/gramlot-index/icons/chart.svg +4 -0
- package/themes/gramlot-index/icons/chat.svg +4 -0
- package/themes/gramlot-index/icons/clock.svg +4 -0
- package/themes/gramlot-index/icons/code.svg +4 -0
- package/themes/gramlot-index/icons/collapse.svg +4 -0
- package/themes/gramlot-index/icons/columns.svg +4 -0
- package/themes/gramlot-index/icons/confirm.svg +4 -0
- package/themes/gramlot-index/icons/copy.svg +4 -0
- package/themes/gramlot-index/icons/cut.svg +4 -0
- package/themes/gramlot-index/icons/database.svg +4 -0
- package/themes/gramlot-index/icons/delete.svg +4 -0
- package/themes/gramlot-index/icons/detach.svg +4 -0
- package/themes/gramlot-index/icons/document.svg +4 -0
- package/themes/gramlot-index/icons/download.svg +4 -0
- package/themes/gramlot-index/icons/duplicate.svg +4 -0
- package/themes/gramlot-index/icons/edit.svg +4 -0
- package/themes/gramlot-index/icons/expand.svg +4 -0
- package/themes/gramlot-index/icons/export.svg +4 -0
- package/themes/gramlot-index/icons/eye.svg +4 -0
- package/themes/gramlot-index/icons/filter.svg +4 -0
- package/themes/gramlot-index/icons/first.svg +4 -0
- package/themes/gramlot-index/icons/folder.svg +4 -0
- package/themes/gramlot-index/icons/group.svg +4 -0
- package/themes/gramlot-index/icons/help.svg +4 -0
- package/themes/gramlot-index/icons/home.svg +4 -0
- package/themes/gramlot-index/icons/import.svg +4 -0
- package/themes/gramlot-index/icons/info.svg +4 -0
- package/themes/gramlot-index/icons/inspector.svg +4 -0
- package/themes/gramlot-index/icons/last.svg +4 -0
- package/themes/gramlot-index/icons/layers.svg +4 -0
- package/themes/gramlot-index/icons/link.svg +4 -0
- package/themes/gramlot-index/icons/list.svg +4 -0
- package/themes/gramlot-index/icons/lock.svg +4 -0
- package/themes/gramlot-index/icons/logout.svg +4 -0
- package/themes/gramlot-index/icons/navigation.svg +4 -0
- package/themes/gramlot-index/icons/new.svg +4 -0
- package/themes/gramlot-index/icons/next.svg +4 -0
- package/themes/gramlot-index/icons/open.svg +4 -0
- package/themes/gramlot-index/icons/palette.svg +4 -0
- package/themes/gramlot-index/icons/panel-bottom.svg +4 -0
- package/themes/gramlot-index/icons/panel-left.svg +4 -0
- package/themes/gramlot-index/icons/panel-right.svg +4 -0
- package/themes/gramlot-index/icons/panel-top.svg +4 -0
- package/themes/gramlot-index/icons/paste.svg +4 -0
- package/themes/gramlot-index/icons/pause.svg +4 -0
- package/themes/gramlot-index/icons/pin.svg +4 -0
- package/themes/gramlot-index/icons/play.svg +4 -0
- package/themes/gramlot-index/icons/previous.svg +4 -0
- package/themes/gramlot-index/icons/print.svg +4 -0
- package/themes/gramlot-index/icons/redo.svg +4 -0
- package/themes/gramlot-index/icons/refresh.svg +4 -0
- package/themes/gramlot-index/icons/save.svg +4 -0
- package/themes/gramlot-index/icons/search.svg +4 -0
- package/themes/gramlot-index/icons/send.svg +4 -0
- package/themes/gramlot-index/icons/settings.svg +4 -0
- package/themes/gramlot-index/icons/sort-ascending.svg +4 -0
- package/themes/gramlot-index/icons/sort-descending.svg +4 -0
- package/themes/gramlot-index/icons/stop.svg +4 -0
- package/themes/gramlot-index/icons/table.svg +4 -0
- package/themes/gramlot-index/icons/tree.svg +4 -0
- package/themes/gramlot-index/icons/undo.svg +4 -0
- package/themes/gramlot-index/icons/unlock.svg +4 -0
- package/themes/gramlot-index/icons/upload.svg +4 -0
- package/themes/gramlot-index/icons/user.svg +4 -0
- package/themes/gramlot-index/icons/warning.svg +4 -0
- package/themes/gramlot-index/icons/zoom-in.svg +4 -0
- package/themes/gramlot-index/icons/zoom-out.svg +4 -0
- package/themes/gramlot-index/icons.json +76 -0
- package/themes/gramlot-index/theme.css +21 -0
- package/themes/joanna/theme.css +2 -0
- package/themes/mela/theme.css +2 -0
- package/themes/mimi/theme.css +2 -0
|
@@ -28,7 +28,7 @@ export const DrawingPane = defineComponent({
|
|
|
28
28
|
slot{display:contents} ::slotted(gramlot-menu){flex:0 0 56px;box-sizing:border-box;padding:6px;background:var(--gramlot-surface,Canvas);border-right:1px solid var(--gramlot-border-control,#a8b2bf);overflow:hidden}
|
|
29
29
|
.canvas{display:block;flex:1;width:0;height:100%;min-width:0;min-height:0;background:var(--gramlot-drawing-background,var(--gramlot-surface-subtle,#eee));touch-action:none;user-select:none}
|
|
30
30
|
.text-editor{position:absolute;z-index:2;min-width:120px;padding:2px 4px;border:1px solid #3977bc;border-radius:3px;background:white;color:#222;box-shadow:0 2px 8px #0003}
|
|
31
|
-
.text-editor[hidden]{display:none}.shape{cursor:pointer}.selected{
|
|
31
|
+
.text-editor[hidden]{display:none}.shape{cursor:pointer}.shape.selected{outline:2px dashed var(--gramlot-action,Highlight);outline-offset:2px}`;
|
|
32
32
|
this.shadowRoot.append(style);this.control.replaceChildren();
|
|
33
33
|
this.#editor=d.createElement('input');this.#editor.type='text';this.#editor.className='text-editor';this.#editor.hidden=true;this.#editor.setAttribute('aria-label','Annotation text');
|
|
34
34
|
this.#svg=d.createElementNS(SVG_NS,'svg');this.#svg.setAttribute('role','img');this.#svg.setAttribute('aria-label','Annotated image');
|
|
@@ -101,27 +101,27 @@ export const DrawingPane = defineComponent({
|
|
|
101
101
|
this.#tool=this.#state('tool');this.#lastColor=this.#state('color');this.#lastSize=this.#state('size');
|
|
102
102
|
if(this.parameters.toolbar===false){this.#built=true;return;}
|
|
103
103
|
const fragment=new builder.source.constructor(null,builder),root=builder.wrapSource(fragment);
|
|
104
|
-
const bar=root.menu({node_label:'bar',presentation:'bar',orientation:'vertical',labelPosition:'tooltip',
|
|
104
|
+
const bar=root.menu({node_label:'bar',presentation:'bar',orientation:'vertical',labelPosition:'tooltip',icon_size:20,aria_label:'Image annotations'});
|
|
105
105
|
sourceTarget(bar)._internal.drawingController=this;
|
|
106
106
|
const paths={select:'M5 3l13 11-6 .5-3 5z',freehand:'M4 20l3.5-.7L19 7.8 16.2 5 4.7 16.5z M14.7 6.5l2.8 2.8',arrow:'M4 19L19 4 M12 4h7v7',circle:'M20 12a8 8 0 1 1-16 0 8 8 0 0 1 16 0z',text:'M4 5h16 M12 5v14 M8 19h8',delete:'M4 7h16 M9 7V4h6v3 M7 7l1 13h8l1-13 M10 10v7 M14 10v7'};
|
|
107
107
|
const icon=key=>'data:image/svg+xml,'+encodeURIComponent(`<svg xmlns="${SVG_NS}" viewBox="0 0 24 24" fill="none" stroke="#7e93ad" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="${paths[key]}"/></svg>`);
|
|
108
108
|
for(const [tool,label] of [['select','Select'],['freehand','Draw'],['arrow','Arrow'],['circle','Circle'],['text','Text']]){
|
|
109
|
-
bar.menuline({caption:label,tooltip:label,
|
|
109
|
+
bar.menuline({caption:label,tooltip:label,icon:icon(tool),checked:`^${this.#statePath}.tool:={} === '${tool}'`,action:`this.parentBag.parentNode._internal.drawingController.setTool('${tool}')`});
|
|
110
110
|
}
|
|
111
111
|
bar.contentPane({height:'1px',margin:'6px 4px',background:'var(--gramlot-border-control,#a8b2bf)'});
|
|
112
112
|
const circleIcon=color=>'data:image/svg+xml,'+encodeURIComponent(`<svg xmlns="${SVG_NS}" viewBox="0 0 24 24"><circle cx="12" cy="12" r="8" fill="${color}" stroke="#8793a3" stroke-width="1.5"/></svg>`);
|
|
113
|
-
const colorMenu=bar.menuline({caption:'Color',tooltip:'Color',
|
|
113
|
+
const colorMenu=bar.menuline({caption:'Color',tooltip:'Color',icon:`^${this.#statePath}.color:='data:image/svg+xml,' + encodeURIComponent('<svg xmlns="${SVG_NS}" viewBox="0 0 24 24"><circle cx="12" cy="12" r="8" fill="' + {} + '" stroke="#8793a3" stroke-width="1.5"/></svg>')`}).menu({aria_label:'Annotation colors'});
|
|
114
114
|
for(const [color,label] of [['#dd2222','Red'],['#e6a700','Yellow'],['#16834a','Green'],['#1677d2','Blue'],['#ffffff','White'],['#202733','Black']]){
|
|
115
|
-
colorMenu.menuline({caption:label,
|
|
115
|
+
colorMenu.menuline({caption:label,icon:circleIcon(color),checked:`^${this.#statePath}.color:={} === '${color}'`,
|
|
116
116
|
action:`this.SET('${this.#statePath}.color', '${color}');`});
|
|
117
117
|
}
|
|
118
118
|
colorMenu.contentPane({padding:'8px'}).colorpicker({value:`^${this.#statePath}.color`,lbl:'Custom color',aria_label:'Color',width:'140px'});
|
|
119
119
|
const strokeIcon=size=>'data:image/svg+xml,'+encodeURIComponent(`<svg xmlns="${SVG_NS}" viewBox="0 0 24 24"><path d="M4 12h16" stroke="#7e93ad" stroke-width="${size}" stroke-linecap="round"/></svg>`);
|
|
120
|
-
const sizeMenu=bar.menuline({caption:'Pen size',tooltip:'Pen size',
|
|
121
|
-
for(const size of [1,3,5,7,12,20])sizeMenu.menuline({caption:`${size} px`,
|
|
120
|
+
const sizeMenu=bar.menuline({caption:'Pen size',tooltip:'Pen size',icon:`^${this.#statePath}.size:='data:image/svg+xml,' + encodeURIComponent('<svg xmlns="${SVG_NS}" viewBox="0 0 24 24"><path d="M4 12h16" stroke="#7e93ad" stroke-width="' + Math.min({}, 12) + '" stroke-linecap="round"/></svg>')`}).menu({aria_label:'Pen size'});
|
|
121
|
+
for(const size of [1,3,5,7,12,20])sizeMenu.menuline({caption:`${size} px`,icon:strokeIcon(Math.min(size,12)),checked:`^${this.#statePath}.size:={} === ${size}`,action:`this.SET('${this.#statePath}.size', ${size});`});
|
|
122
122
|
sizeMenu.contentPane({padding:'8px'}).numberTextBox({value:`^${this.#statePath}.size`,lbl:'Custom size',aria_label:'Pen size',dtype:'L',min:1,max:20,width:'140px'});
|
|
123
123
|
bar.contentPane({flex:'1',min_height:'12px'});
|
|
124
|
-
bar.menuline({caption:'Delete',tooltip:'Delete',
|
|
124
|
+
bar.menuline({caption:'Delete',tooltip:'Delete',icon:icon('delete'),action:'this.parentBag.parentNode._internal.drawingController.deleteSelection()'});
|
|
125
125
|
const app=builder.binding.gramlot,source=app.src.prepareSource(fragment);
|
|
126
126
|
app.src.renderer.validateCandidate(source);this.#built=true;node.setValue(source);
|
|
127
127
|
}
|
|
@@ -131,7 +131,8 @@ export const DrawingPane = defineComponent({
|
|
|
131
131
|
const tool=this.#state('tool');this.#tool=tool;
|
|
132
132
|
const color=this.#state('color'),size=this.#state('size');
|
|
133
133
|
const changed=color!==this.#lastColor||size!==this.#lastSize;this.#lastColor=color;this.#lastSize=size;
|
|
134
|
-
if(
|
|
134
|
+
if(this.#syncing)return;
|
|
135
|
+
if(changed)this.#styleSelection();
|
|
135
136
|
this.#render();
|
|
136
137
|
}
|
|
137
138
|
#point(event){
|
|
@@ -143,17 +144,44 @@ export const DrawingPane = defineComponent({
|
|
|
143
144
|
if(event.button!==0||!this.#dimensions)return;const point=this.#point(event);if(!point)return;
|
|
144
145
|
const id=event.target.closest('[data-id]')?.getAttribute('data-id');
|
|
145
146
|
if(this.#tool==='select'){
|
|
147
|
+
this.#svg.querySelector('.selected')?.classList.remove('selected');
|
|
146
148
|
this.#selected=id||null;
|
|
147
|
-
if(id){
|
|
148
|
-
|
|
149
|
+
if(id){
|
|
150
|
+
event.target.closest('[data-id]').classList.add('selected');
|
|
151
|
+
const row=this.#read(this.#annotations().getItem(id));
|
|
152
|
+
this.#syncing=true;
|
|
153
|
+
try{this.#setState('color',row.color);this.#setState('size',row.width);}
|
|
154
|
+
finally{this.#syncing=false;}
|
|
155
|
+
this.#gesture={id,start:point,original:row};
|
|
156
|
+
event.target.setPointerCapture(event.pointerId);
|
|
157
|
+
}
|
|
158
|
+
// Keep the hit shape mounted until a drag starts so the browser can dispatch dblclick.
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if(this.#tool==='text'){
|
|
149
162
|
const value=id?this.#annotations().getItem(id):null;
|
|
150
163
|
this.#editText(value instanceof Bag&&value.getItem('type')==='text'?id:null,point);
|
|
151
164
|
}else {this.#selected=null;this.#gesture={start:point,current:point,points:[point]};}
|
|
152
165
|
if(this.#gesture)this.#svg.setPointerCapture(event.pointerId);this.#render();event.preventDefault();
|
|
153
166
|
}
|
|
154
|
-
#move(event){
|
|
167
|
+
#move(event){
|
|
168
|
+
const gesture=this.#gesture;
|
|
169
|
+
if(!gesture||!this.#dimensions)return;
|
|
170
|
+
const point=this.#point(event);
|
|
171
|
+
if(!point)return;
|
|
172
|
+
if(gesture.id&&!gesture.current){
|
|
173
|
+
if(point.x===gesture.start.x&&point.y===gesture.start.y)return;
|
|
174
|
+
this.#svg.setPointerCapture(event.pointerId);
|
|
175
|
+
}
|
|
176
|
+
gesture.current=point;
|
|
177
|
+
if(this.#tool==='freehand')gesture.points.push(point);
|
|
178
|
+
this.#render();
|
|
179
|
+
}
|
|
155
180
|
#up(event){
|
|
156
|
-
if(!this.#gesture)return;
|
|
181
|
+
if(!this.#gesture)return;
|
|
182
|
+
this.#move(event);
|
|
183
|
+
const gesture=this.#gesture;this.#gesture=null;
|
|
184
|
+
if(gesture.id&&!gesture.current)return;
|
|
157
185
|
if(gesture.id){const delta={x:gesture.current.x-gesture.start.x,y:gesture.current.y-gesture.start.y};const row=this.#translate(gesture.original,delta);this.#annotations().setItem(gesture.id,new Bag(row));}
|
|
158
186
|
else {const {start,current,points}=gesture;let row;
|
|
159
187
|
if(this.#tool==='arrow')row={type:'arrow',x:start.x,y:start.y,x2:current.x,y2:current.y};
|
|
@@ -182,6 +210,7 @@ export const DrawingPane = defineComponent({
|
|
|
182
210
|
this.#render();
|
|
183
211
|
}
|
|
184
212
|
#read(row){
|
|
213
|
+
if(!(row instanceof Bag))throw new TypeError('Annotation must be a Bag');
|
|
185
214
|
const result=Object.fromEntries(row.getNodes().map(node=>[node.label,node.getValue()]));
|
|
186
215
|
if(result.type==='freehand')result.points=result.points.getNodes().map(node=>({x:node.getValue().getItem('x'),y:node.getValue().getItem('y')}));
|
|
187
216
|
return result;
|
|
@@ -206,7 +235,7 @@ export const DrawingPane = defineComponent({
|
|
|
206
235
|
const [width,height]=this.#dimensions;this.#svg.setAttribute('viewBox',`0 0 ${width} ${height}`);
|
|
207
236
|
if(this.#url)this.#svg.append(this.#element('image',{href:this.#url,x:0,y:0,width,height,'pointer-events':'none'}));
|
|
208
237
|
for(const node of this.#annotations().getNodes()){
|
|
209
|
-
|
|
238
|
+
let row=this.#read(node.getValue());
|
|
210
239
|
if(this.#gesture?.id===node.label&&this.#gesture.current)row=this.#translate(this.#gesture.original,{x:this.#gesture.current.x-this.#gesture.start.x,y:this.#gesture.current.y-this.#gesture.start.y});
|
|
211
240
|
const shape=this.#shape(row,node.label);this.#svg.append(shape);
|
|
212
241
|
if(row.type==='text'){const bounds=shape.querySelector('text').getBBox(),hit=shape.querySelector('[data-text-hit]');for(const name of ['x','y','width','height'])hit.setAttribute(name,bounds[name]);}
|
|
@@ -5,7 +5,7 @@ export function codeMirrorWithOptions(parent, {datapath, value, language = 'text
|
|
|
5
5
|
const defaults = {language, indentUnit:4, fontSize:14, fontFamily:'monospace', lineNumbers:true, lineWrapping:true,
|
|
6
6
|
folding:true, bracketMatching:true, autoCloseBrackets:true, autoIndent:true, autocompletion:true, highlightActiveLine:true, highlightSelectionMatches:true};
|
|
7
7
|
for (const [name, setting] of Object.entries(defaults)) pane.dataSetter({destination_path:`.settings.${name}`, value:setting});
|
|
8
|
-
const options = pane.contentPane({region:'right', width:'250px', drawer:'close', drawer_label:'Options', drawer_icon:'
|
|
8
|
+
const options = pane.contentPane({region:'right', width:'250px', drawer:'close', drawer_label:'Options', drawer_icon:'settings', drawer_minimize:false,
|
|
9
9
|
padding:'12px', overflow:'auto', class:'gramlot-editor-settings'});
|
|
10
10
|
options.h3('Editor options');
|
|
11
11
|
options.filteringSelect({value:'^.settings.language', lbl:'Language', values:'text:Plain text,python:Python,javascript:JavaScript,typescript:TypeScript,json:JSON,html:HTML,css:CSS,xml:XML,markdown:Markdown,sql:SQL,typst:Typst'});
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {SVG_NS} from '../renderer/attributes.js';
|
|
2
|
+
import {NativeControl} from './bases.js';
|
|
3
|
+
import {FieldState} from './field-state.js';
|
|
4
|
+
import {Labelbox} from './labelbox.js';
|
|
5
|
+
import {numericRange, numericRangeParameters} from './numeric-range.js';
|
|
6
|
+
import {defineComponent} from './registry.js';
|
|
7
|
+
|
|
8
|
+
function svg(doc, tag, attrs) {
|
|
9
|
+
const node = doc.createElementNS(SVG_NS, tag);
|
|
10
|
+
for (const [name, value] of Object.entries(attrs)) node.setAttribute(name, value);
|
|
11
|
+
return node;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Pointer geometry belongs to the illustrated surface. The underlying range still
|
|
15
|
+
// provides the single focus stop, accessible value, keyboard steps and Data events.
|
|
16
|
+
function graphicalRange(Base) {
|
|
17
|
+
return class extends numericRange(Base) {
|
|
18
|
+
#drag;
|
|
19
|
+
|
|
20
|
+
constructor() {
|
|
21
|
+
super();
|
|
22
|
+
const doc = this.ownerDocument;
|
|
23
|
+
const style = doc.createElement('style');
|
|
24
|
+
style.textContent = `
|
|
25
|
+
.option{position:relative;display:inline-flex;max-width:100%;vertical-align:middle;
|
|
26
|
+
border-radius:var(--gramlot-radius-sm,4px);color:var(--gramlot-action,Highlight);
|
|
27
|
+
touch-action:none;user-select:none;cursor:pointer}
|
|
28
|
+
.option:has(.knob){border-radius:50%}
|
|
29
|
+
.option:not(.pointer-focus):has(input:focus-visible){outline:1px solid var(--gramlot-focus-ring,Highlight);outline-offset:-1px}
|
|
30
|
+
.option:has(:disabled){opacity:.45;cursor:default}
|
|
31
|
+
.option input[type=range]{position:absolute;inset:0;margin:0;width:100%;height:100%;opacity:0;pointer-events:none}
|
|
32
|
+
.range-art{display:block;pointer-events:none;max-width:100%}
|
|
33
|
+
.knob{width:5rem;height:5rem;border-radius:50%}
|
|
34
|
+
.dial-track{stroke:var(--gramlot-border-control,GrayText)}
|
|
35
|
+
.dial-face{fill:var(--gramlot-field-background,Canvas);stroke:var(--gramlot-border,GrayText)}
|
|
36
|
+
.dial-value{fill:var(--gramlot-ink,CanvasText);font:600 12px system-ui;font-variant-numeric:tabular-nums}
|
|
37
|
+
.rating{border-radius:var(--gramlot-radius-sm,4px);display:inline-flex;align-items:center;min-height:max(2rem,var(--gramlot-touch-target,0px))}
|
|
38
|
+
.rating svg{width:1.65rem;height:1.65rem;stroke-width:1.6;stroke-linejoin:round;stroke:var(--gramlot-border-control,GrayText);fill:none}
|
|
39
|
+
.rating svg[data-filled]{stroke:currentColor;fill:currentColor}
|
|
40
|
+
`;
|
|
41
|
+
this.shadowRoot.append(style);
|
|
42
|
+
this.surface = this.control.parentElement;
|
|
43
|
+
this.surface.append(this.createArt(doc));
|
|
44
|
+
this.control.addEventListener('input', () => this.paint());
|
|
45
|
+
this.control.addEventListener('blur', () => this.surface.classList.remove('pointer-focus'));
|
|
46
|
+
this.control.addEventListener('keydown', event => {
|
|
47
|
+
this.surface.classList.remove('pointer-focus');
|
|
48
|
+
if (this.control.readOnly && ['ArrowLeft','ArrowRight','ArrowUp','ArrowDown','Home','End','PageUp','PageDown'].includes(event.key)) event.preventDefault();
|
|
49
|
+
});
|
|
50
|
+
this.surface.addEventListener('pointerdown', event => {
|
|
51
|
+
if (this.#drag || !event.isPrimary || event.button !== 0 || this.control.disabled || this.control.readOnly) return;
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
this.surface.classList.add('pointer-focus');
|
|
54
|
+
this.control.focus({preventScroll:true});
|
|
55
|
+
this.surface.setPointerCapture(event.pointerId);
|
|
56
|
+
this.#drag = {id:event.pointerId, start:this.control.value};
|
|
57
|
+
this.#move(event);
|
|
58
|
+
});
|
|
59
|
+
this.surface.addEventListener('pointermove', event => this.#move(event));
|
|
60
|
+
this.surface.addEventListener('pointerup', event => {
|
|
61
|
+
if (this.#drag?.id !== event.pointerId) return;
|
|
62
|
+
this.#move(event);
|
|
63
|
+
const changed = this.control.value !== this.#drag.start;
|
|
64
|
+
this.#drag = null;
|
|
65
|
+
if (changed) this.#emit('change');
|
|
66
|
+
});
|
|
67
|
+
for (const type of ['pointercancel','lostpointercapture']) this.surface.addEventListener(type, event => {
|
|
68
|
+
if (this.#drag?.id === event.pointerId) this.#cancel();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
#emit(type) {
|
|
72
|
+
this.control.dispatchEvent(new this.ownerDocument.defaultView.Event(type, {bubbles:true}));
|
|
73
|
+
}
|
|
74
|
+
#move(event) {
|
|
75
|
+
if (this.#drag?.id !== event.pointerId) return;
|
|
76
|
+
const value = this.valueAt(event, this.surface.getBoundingClientRect());
|
|
77
|
+
if (value == null) return;
|
|
78
|
+
const previous = this.control.value;
|
|
79
|
+
this.control.valueAsNumber = value;
|
|
80
|
+
if (this.control.value !== previous) this.#emit('input');
|
|
81
|
+
}
|
|
82
|
+
#cancel() {
|
|
83
|
+
if (!this.#drag) return;
|
|
84
|
+
const {id,start} = this.#drag;
|
|
85
|
+
this.#drag = null;
|
|
86
|
+
if (this.surface.hasPointerCapture(id)) this.surface.releasePointerCapture(id);
|
|
87
|
+
if (this.control.value !== start) {
|
|
88
|
+
this.control.value = start;
|
|
89
|
+
this.#emit('input');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
releaseControl() {
|
|
93
|
+
this.#cancel();
|
|
94
|
+
super.releaseControl();
|
|
95
|
+
}
|
|
96
|
+
projectAttributes(attrs, adapt) {
|
|
97
|
+
const rest = super.projectAttributes(attrs, adapt);
|
|
98
|
+
if (this.control.disabled || this.control.readOnly) this.#cancel();
|
|
99
|
+
this.paint();
|
|
100
|
+
return rest;
|
|
101
|
+
}
|
|
102
|
+
writeControlValue(value) {
|
|
103
|
+
super.writeControlValue(value);
|
|
104
|
+
this.paint();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const Knob = defineComponent({
|
|
110
|
+
name:'knob', tag:'gramlot-knob', base:NativeControl, mixins:[Labelbox, FieldState], sourceContext:true,
|
|
111
|
+
parameters:{...numericRangeParameters, showValue:{dtype:'B', default:false, binding:'read'}},
|
|
112
|
+
implementation:Base => class extends graphicalRange(Base) {
|
|
113
|
+
createArt(doc) {
|
|
114
|
+
const art = svg(doc,'svg',{class:'range-art knob',viewBox:'0 0 72 72','aria-hidden':true});
|
|
115
|
+
const arc = {d:'M16.201 55.799a28 28 0 1 1 39.598 0',fill:'none','stroke-width':4,'stroke-linecap':'round',pathLength:1};
|
|
116
|
+
this.progress = svg(doc,'path',{...arc,stroke:'currentColor'});
|
|
117
|
+
this.indicator = svg(doc,'path',{d:'M36 16v5',stroke:'currentColor','stroke-width':3,'stroke-linecap':'round'});
|
|
118
|
+
this.number = svg(doc,'text',{class:'dial-value',x:36,y:40,'text-anchor':'middle'});
|
|
119
|
+
art.append(svg(doc,'path',{...arc,class:'dial-track'}),this.progress,
|
|
120
|
+
svg(doc,'circle',{class:'dial-face',cx:36,cy:36,r:23}),this.indicator,this.number);
|
|
121
|
+
return art;
|
|
122
|
+
}
|
|
123
|
+
valueAt(event, box) {
|
|
124
|
+
const x = event.clientX - box.left - box.width / 2;
|
|
125
|
+
const y = box.top + box.height / 2 - event.clientY;
|
|
126
|
+
if (Math.hypot(x,y) < Math.min(box.width,box.height) * 0.12) return null;
|
|
127
|
+
const angle = Math.atan2(x,y) * 180 / Math.PI;
|
|
128
|
+
const fraction = (Math.max(-135, Math.min(135,angle)) + 135) / 270;
|
|
129
|
+
return Number(this.control.min) + fraction * (Number(this.control.max) - Number(this.control.min));
|
|
130
|
+
}
|
|
131
|
+
paint() {
|
|
132
|
+
const value = this.control.valueAsNumber, min = Number(this.control.min), max = Number(this.control.max);
|
|
133
|
+
const fraction = max > min ? (value - min) / (max - min) : 0;
|
|
134
|
+
this.progress.setAttribute('stroke-dasharray', fraction + ' 1');
|
|
135
|
+
this.indicator.setAttribute('transform', 'rotate(' + (fraction*270-135) + ' 36 36)');
|
|
136
|
+
this.number.textContent = this.parameters.showValue ? value.toLocaleString(this.closest('[lang]')?.lang || this.pageContext?.locale,
|
|
137
|
+
{maximumSignificantDigits:21}) : '';
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
export const StarRating = defineComponent({
|
|
143
|
+
name:'starRating', tag:'gramlot-star-rating', base:NativeControl, mixins:[Labelbox,FieldState], sourceContext:true,
|
|
144
|
+
parameters:{
|
|
145
|
+
value:{dtype:'L', default:0, binding:'twoWay'},
|
|
146
|
+
max:{dtype:'L', default:5, binding:'read', target:'control'}
|
|
147
|
+
},
|
|
148
|
+
implementation:Base => class extends graphicalRange(Base) {
|
|
149
|
+
createArt(doc) {
|
|
150
|
+
this.control.min = '0';
|
|
151
|
+
this.control.step = '1';
|
|
152
|
+
this.stars = doc.createElement('span');
|
|
153
|
+
this.stars.className = 'range-art rating';
|
|
154
|
+
this.stars.setAttribute('aria-hidden','true');
|
|
155
|
+
return this.stars;
|
|
156
|
+
}
|
|
157
|
+
valueAt(event, box) {
|
|
158
|
+
const x = this.matches(':dir(rtl)') ? box.right - event.clientX : event.clientX - box.left;
|
|
159
|
+
const count = this.stars.childElementCount;
|
|
160
|
+
return Math.max(0, Math.min(count, Math.ceil(x * count / box.width)));
|
|
161
|
+
}
|
|
162
|
+
paint() {
|
|
163
|
+
const count = Number(this.control.max);
|
|
164
|
+
if (!Number.isSafeInteger(count) || count < 1) throw new RangeError('starRating max must be a positive integer');
|
|
165
|
+
while (this.stars.childElementCount > count) this.stars.lastElementChild.remove();
|
|
166
|
+
while (this.stars.childElementCount < count) {
|
|
167
|
+
const star = svg(this.ownerDocument, 'svg', {viewBox:'0 0 24 24'});
|
|
168
|
+
star.append(svg(this.ownerDocument, 'path', {
|
|
169
|
+
d:'m12 2.8 2.8 5.7 6.3.9-4.6 4.5 1.1 6.3-5.6-3-5.6 3 1.1-6.3-4.6-4.5 6.3-.9z'
|
|
170
|
+
}));
|
|
171
|
+
this.stars.append(star);
|
|
172
|
+
}
|
|
173
|
+
const value = this.control.valueAsNumber;
|
|
174
|
+
Array.from(this.stars.children).forEach((star,index) => star.toggleAttribute('data-filled', index < value));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
});
|
|
@@ -53,7 +53,7 @@ export class GridFooter {
|
|
|
53
53
|
cell(field) { return this.#row.querySelector(`td[data-field="${field}"]`); }
|
|
54
54
|
|
|
55
55
|
/** `footer` is false, true or a caption; `columns` are the displayed columns. */
|
|
56
|
-
configure(footer, columns, rowHeaders) {
|
|
56
|
+
configure(footer, columns, rowHeaders, rowDelete) {
|
|
57
57
|
this.#caption = footer;
|
|
58
58
|
this.#columns = columns;
|
|
59
59
|
if (footer === false) this.#frame.remove();
|
|
@@ -73,6 +73,11 @@ export class GridFooter {
|
|
|
73
73
|
cell.classList.toggle('numeric', Boolean(column.totalize));
|
|
74
74
|
cells.push(cell);
|
|
75
75
|
}
|
|
76
|
+
if (rowDelete) {
|
|
77
|
+
const action = document.createElement('td');
|
|
78
|
+
action.setAttribute('role', 'cell');
|
|
79
|
+
cells.push(action);
|
|
80
|
+
}
|
|
76
81
|
this.#row.replaceChildren(...cells);
|
|
77
82
|
}
|
|
78
83
|
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
* A JS stylesheet module keeps the same source usable in Node and browser builds.
|
|
3
3
|
*/
|
|
4
4
|
export const gridStyles = `
|
|
5
|
+
.row-delete{text-align:center}
|
|
6
|
+
.row-delete button{display:inline-grid;place-items:center;padding:.15em .3em;border:0;border-radius:var(--gramlot-radius-sm,4px);background:transparent;color:inherit;cursor:pointer}
|
|
7
|
+
.row-delete button:hover{background:var(--gramlot-button-hover,ButtonFace)}
|
|
8
|
+
.row-delete button:focus-visible{outline:1px solid var(--gramlot-focus-ring,Highlight);outline-offset:-1px}
|
|
9
|
+
.row-delete img{width:1em;height:1em}
|
|
5
10
|
.column-filter{position:absolute;inset-inline-end:8px;top:50%;transform:translateY(-50%);border:0;background:transparent;color:inherit;cursor:pointer;padding:2px;margin-inline-start:4px;vertical-align:middle;line-height:0;opacity:.6}
|
|
6
11
|
th:has(.column-filter){padding-inline-end:28px}
|
|
7
12
|
.column-filter svg{width:13px;height:13px;fill:none;stroke:currentColor;stroke-width:1.5}
|
|
@@ -183,8 +188,12 @@ th:has(.column-filter){padding-inline-end:28px}
|
|
|
183
188
|
.cell-scroll:focus-visible { outline: 1px solid var(--gramlot-focus-ring, Highlight); outline-offset: -1px; }
|
|
184
189
|
tbody tr { background: var(--gramlot-grid-background, var(--gramlot-surface, Canvas)); }
|
|
185
190
|
tbody tr.alternate { background: var(--gramlot-grid-row-alt-background, var(--gramlot-surface-subtle, Canvas)); }
|
|
186
|
-
tbody tr[aria-selected=true] {
|
|
187
|
-
|
|
191
|
+
tbody tr[aria-selected=true] {
|
|
192
|
+
background: var(--gramlot-grid-selected-background, var(--gramlot-selected, Highlight));
|
|
193
|
+
outline: 2px solid var(--gramlot-action, Highlight);
|
|
194
|
+
outline-offset: -2px;
|
|
195
|
+
}
|
|
196
|
+
tbody tr:hover:not([aria-selected=true]) { background: var(--gramlot-grid-row-hover-background, var(--gramlot-selected, Highlight)); }
|
|
188
197
|
th[data-field] { padding-inline-end: 14px; cursor: grab; user-select: none; }
|
|
189
198
|
th[data-field]:hover { background-color: color-mix(in srgb, var(--gramlot-grid-header-background) 92%, var(--gramlot-grid-header-color)); }
|
|
190
199
|
th:focus-visible, .column-resize:focus-visible { outline: 2px solid var(--gramlot-focus-ring, Highlight); outline-offset: -2px; }
|
|
@@ -17,12 +17,12 @@ let excelEngine = null;
|
|
|
17
17
|
|
|
18
18
|
/** Grid toolbar commands of the `grid` namespace, delivered to the frame's target grid by publication. */
|
|
19
19
|
export const GRID_COMMANDS = Object.freeze({
|
|
20
|
-
export: {label:'Export', publish:'export', icon:'
|
|
21
|
-
printRows: {label:'Print', publish:'printRows', icon:'
|
|
20
|
+
export: {label:'Export', publish:'export', icon:'download', tooltip:'Export the visible rows'},
|
|
21
|
+
printRows: {label:'Print', publish:'printRows', icon:'print', tooltip:'Print the visible rows'},
|
|
22
22
|
lineNumbers: {label:'Line numbers', publish:'lineNumbers', tooltip:'Show or hide the row numbers'},
|
|
23
|
-
addrow: {label:'
|
|
24
|
-
duprow: {label:'Duplicate', publish:'duprow', icon:'
|
|
25
|
-
delrow: {label:'Delete', publish:'delrow',
|
|
23
|
+
addrow: {label:'New row', publish:'addrow', tooltip:'Add a row'},
|
|
24
|
+
duprow: {label:'Duplicate', publish:'duprow', icon:'duplicate', tooltip:'Duplicate the selected rows'},
|
|
25
|
+
delrow: {label:'Delete', publish:'delrow', tooltip:'Delete the selected rows'},
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
// Commands that change rows: they require at least one editable column.
|
|
@@ -33,7 +33,13 @@ const SELECTION_COMMANDS = new Set(['grid:duprow', 'grid:delrow']);
|
|
|
33
33
|
/** Register the grid command group on one Gramlot page. */
|
|
34
34
|
export function registerGridCommands(gramlot) {
|
|
35
35
|
const group = gramlot.commands.registerGroup('grid', {description:'Grid toolbar tools'});
|
|
36
|
-
|
|
36
|
+
const italian = gramlot.locale?.split('-')[0].toLowerCase() === 'it';
|
|
37
|
+
const labels = italian ? {
|
|
38
|
+
addrow:{label:'Nuova riga', tooltip:'Aggiungi una riga'},
|
|
39
|
+
delrow:{label:'Cancella', tooltip:'Cancella le righe selezionate'},
|
|
40
|
+
duprow:{label:'Duplica', tooltip:'Duplica le righe selezionate'},
|
|
41
|
+
} : {};
|
|
42
|
+
for (const [name, definition] of Object.entries(GRID_COMMANDS)) group.register(name, {...definition, ...labels[name]});
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
function csvField(text) {
|
|
@@ -206,8 +212,10 @@ export class GridTools {
|
|
|
206
212
|
}
|
|
207
213
|
|
|
208
214
|
/** Remove the selected rows at their paths in the store; an editing session records each removal. */
|
|
215
|
+
deleteRow(label) { this.source.data.popNode(this.#rowPath(label)); }
|
|
216
|
+
|
|
209
217
|
deleteRows() {
|
|
210
|
-
for (const
|
|
218
|
+
for (const node of this.#host.selected()) this.deleteRow(node.label);
|
|
211
219
|
}
|
|
212
220
|
|
|
213
221
|
/** Edit tools declared in the grid's frame require an editable column; selection tools a selection mode. */
|
package/src/components/grid.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import icons from '../../themes/gramlot-index/icons.json' with {type:'json'};
|
|
1
2
|
import {GridColumnFilters} from './grid-column-filters.js';
|
|
2
3
|
import {Bag} from '@genrojs/bag';
|
|
3
4
|
import {SVG_NS} from '../renderer/attributes.js';
|
|
@@ -29,6 +30,8 @@ export const Grid = defineComponent({
|
|
|
29
30
|
viewport: {dtype:'X', nullable:true, default:null, binding:'write'},
|
|
30
31
|
sortRequest: {dtype:'T', default:'', binding:'write'},
|
|
31
32
|
storepath: {dtype: 'T'}, structpath: {dtype: 'T'}, rowMode: {dtype: 'T'},
|
|
33
|
+
delrow: {dtype:'T', nullable:true, default:null},
|
|
34
|
+
delrow_label: {dtype:'T', nullable:true, default:null, binding:'read'},
|
|
32
35
|
rowHeaders: {dtype:'B', default:false, binding:'read'},
|
|
33
36
|
footer: {dtype:['B','T'], default:false, binding:'read'},
|
|
34
37
|
selectionMode: {dtype:'T', default:'multi', binding:'read'},
|
|
@@ -253,8 +256,8 @@ export const Grid = defineComponent({
|
|
|
253
256
|
this.control.style.setProperty('--grid-scrollbar-width', width);
|
|
254
257
|
}
|
|
255
258
|
this.#sizeRowHeader();
|
|
256
|
-
for (const
|
|
257
|
-
|
|
259
|
+
for (const handle of this.#head.querySelectorAll('.column-resize')) {
|
|
260
|
+
handle.setAttribute('aria-valuenow', String(Math.round(handle.parentElement.getBoundingClientRect().width)));
|
|
258
261
|
}
|
|
259
262
|
for (const row of this.#rows.values()) {
|
|
260
263
|
const handle = row.querySelector('.row-height-handle');
|
|
@@ -511,6 +514,10 @@ export const Grid = defineComponent({
|
|
|
511
514
|
const store = this.#collectionStore();
|
|
512
515
|
this.#formulas.configure(model, this.#collectionView, store);
|
|
513
516
|
this.#requireStoredCriteria();
|
|
517
|
+
if (this.parameters.delrow !== null && this.parameters.delrow !== 'row') throw new TypeError("grid delrow requires 'row'");
|
|
518
|
+
if (this.parameters.delrow === 'row' && !model.columns.some(column => column.edit)) {
|
|
519
|
+
throw new TypeError("grid tool 'grid:delrow' requires an editable column");
|
|
520
|
+
}
|
|
514
521
|
this.#tools.requireEditableTools(model.columns);
|
|
515
522
|
this.#selection.prune();
|
|
516
523
|
const structureChanged = this.#structureDirty;
|
|
@@ -536,10 +543,10 @@ export const Grid = defineComponent({
|
|
|
536
543
|
gridSearch(this.#context.sourceNode).update(this.#collectionView,
|
|
537
544
|
model.columns.filter(column => !column.check && !this.#formulas.viewFields.has(column.field)));
|
|
538
545
|
const rowHeaders = this.parameters.rowHeaders || this.parameters.rowResize;
|
|
539
|
-
const signature = JSON.stringify([model.groups, rowHeaders, this.parameters.columnFilters, this.parameters.footer]);
|
|
546
|
+
const signature = JSON.stringify([model.groups, rowHeaders, this.parameters.delrow, this.parameters.delrow_label, this.parameters.columnFilters, this.parameters.footer]);
|
|
540
547
|
this.#rowHeaders = rowHeaders;
|
|
541
548
|
if (signature !== this.#signature) {
|
|
542
|
-
this.#footer.configure(this.parameters.footer, model.columns, rowHeaders);
|
|
549
|
+
this.#footer.configure(this.parameters.footer, model.columns, rowHeaders, this.parameters.delrow === 'row');
|
|
543
550
|
this.#renderHeader(model);
|
|
544
551
|
this.#signature = signature;
|
|
545
552
|
}
|
|
@@ -549,7 +556,7 @@ export const Grid = defineComponent({
|
|
|
549
556
|
this.#renderSort();
|
|
550
557
|
this.#renderWindow(true);
|
|
551
558
|
this.#renderSelection();
|
|
552
|
-
this.control.setAttribute('aria-colcount', String(model.columns
|
|
559
|
+
this.control.setAttribute('aria-colcount', String(this.#columnCount(model.columns)));
|
|
553
560
|
this.control.setAttribute('aria-rowcount', String(this.#headerRows + Math.max(this.#rowLayout.count, 1)));
|
|
554
561
|
this.#scheduleLayout();
|
|
555
562
|
}
|
|
@@ -587,6 +594,14 @@ export const Grid = defineComponent({
|
|
|
587
594
|
return Object.fromEntries(node.staticValue.getNodes().filter(cell => !(cell.staticValue instanceof Bag)).map(cell => [cell.label, cell.staticValue]));
|
|
588
595
|
}
|
|
589
596
|
#renderSelection() {
|
|
597
|
+
const source = this.#context.sourceNode;
|
|
598
|
+
if (source.getAttr('frameTarget')) {
|
|
599
|
+
const remove = source.parentNode.parentNode?.value.getNode('top.bar.delrow');
|
|
600
|
+
if (remove?.getAttr('command') === 'grid:delrow') {
|
|
601
|
+
const disabled = this.#selection.current === null;
|
|
602
|
+
if (remove.getAttr('disabled') !== disabled) remove.setAttr({disabled});
|
|
603
|
+
}
|
|
604
|
+
}
|
|
590
605
|
const mode = this.#selectionMode();
|
|
591
606
|
if (mode === 'multi') this.control.setAttribute('aria-multiselectable', 'true');
|
|
592
607
|
else this.control.removeAttribute('aria-multiselectable');
|
|
@@ -638,7 +653,7 @@ export const Grid = defineComponent({
|
|
|
638
653
|
#renderSort() {
|
|
639
654
|
const criteria = this.#windowInfo() ? parseSort(this.#windowInfo().sortedBy) : this.#collectionView.criteria;
|
|
640
655
|
this.#sizeRowHeader();
|
|
641
|
-
for (const header of this.#head.querySelectorAll('th[
|
|
656
|
+
for (const header of this.#head.querySelectorAll('th[data-field]')) {
|
|
642
657
|
const index = criteria.findIndex(item => item.field === header.dataset.field);
|
|
643
658
|
header.removeAttribute('aria-sort');
|
|
644
659
|
if (index < 0) {
|
|
@@ -729,9 +744,17 @@ export const Grid = defineComponent({
|
|
|
729
744
|
(grouped ? bottom : top).append(header(col.name, 1, 1, 'col', index++, col.align));
|
|
730
745
|
}
|
|
731
746
|
}
|
|
747
|
+
if (this.parameters.delrow === 'row') {
|
|
748
|
+
const action = doc.createElement('th');
|
|
749
|
+
action.scope = 'col'; action.rowSpan = this.#headerRows;
|
|
750
|
+
action.setAttribute('role', 'columnheader');
|
|
751
|
+
action.setAttribute('aria-label', this.#deleteCaption());
|
|
752
|
+
top.append(action);
|
|
753
|
+
}
|
|
732
754
|
this.#head.replaceChildren(top, ...(grouped ? [bottom] : []));
|
|
733
755
|
if (focusedField) this.#head.querySelector(`th[data-field="${focusedField}"]${resizeFocused ? ' .column-resize' : ''}`)?.focus({preventScroll:true});
|
|
734
756
|
const widths = model.columns.map(column => column.width ?? 'var(--gramlot-grid-column-width, 10rem)');
|
|
757
|
+
if (this.parameters.delrow === 'row') widths.push('var(--gramlot-grid-action-width, 2.5rem)');
|
|
735
758
|
if (this.#rowHeaders) widths.unshift('max(var(--grid-row-header-min-width, 0px), var(--grid-row-header-width, var(--gramlot-grid-row-header-width, 44px)))');
|
|
736
759
|
this.control.style.setProperty('--grid-columns-width', `calc(${widths.join(' + ')})`);
|
|
737
760
|
// Identical colgroups and table constraints keep one CSS sizing policy for both areas.
|
|
@@ -747,6 +770,11 @@ export const Grid = defineComponent({
|
|
|
747
770
|
}
|
|
748
771
|
return element;
|
|
749
772
|
}));
|
|
773
|
+
if (this.parameters.delrow === 'row') {
|
|
774
|
+
const group = doc.createElement('colgroup'), col = doc.createElement('col');
|
|
775
|
+
col.style.width = 'var(--gramlot-grid-action-width, 2.5rem)';
|
|
776
|
+
group.append(col); table.insertBefore(group, table.querySelector('thead,tbody,tfoot'));
|
|
777
|
+
}
|
|
750
778
|
if (this.#rowHeaders) {
|
|
751
779
|
const group = doc.createElement('colgroup'), col = doc.createElement('col');
|
|
752
780
|
col.style.width = 'max(var(--grid-row-header-min-width, 0px), var(--grid-row-header-width, var(--gramlot-grid-row-header-width, 44px)))';
|
|
@@ -754,6 +782,38 @@ export const Grid = defineComponent({
|
|
|
754
782
|
}
|
|
755
783
|
}
|
|
756
784
|
}
|
|
785
|
+
#columnCount(columns) {
|
|
786
|
+
return columns.length + Number(this.#rowHeaders) + Number(this.parameters.delrow === 'row');
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
#deleteCaption() {
|
|
790
|
+
return this.parameters.delrow_label ?? (this.#context.locale.split('-')[0].toLowerCase() === 'it' ? 'Cancella riga' : 'Delete row');
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
#renderRowAction(tr, label, columnCount) {
|
|
794
|
+
let cell = tr.querySelector('.row-delete');
|
|
795
|
+
if (this.parameters.delrow !== 'row') { cell?.remove(); return; }
|
|
796
|
+
if (!cell) {
|
|
797
|
+
cell = this.ownerDocument.createElement('td');
|
|
798
|
+
cell.className = 'row-delete';
|
|
799
|
+
cell.setAttribute('role', 'cell');
|
|
800
|
+
const button = this.ownerDocument.createElement('button');
|
|
801
|
+
button.type = 'button';
|
|
802
|
+
const icon = this.ownerDocument.createElement('img');
|
|
803
|
+
icon.src = icons.delete; icon.alt = '';
|
|
804
|
+
button.append(icon);
|
|
805
|
+
button.addEventListener('click', event => {
|
|
806
|
+
event.stopPropagation();
|
|
807
|
+
this.#tools.deleteRow(label);
|
|
808
|
+
});
|
|
809
|
+
cell.append(button); tr.append(cell);
|
|
810
|
+
}
|
|
811
|
+
cell.setAttribute('aria-colindex', String(columnCount));
|
|
812
|
+
const button = cell.firstElementChild;
|
|
813
|
+
button.title = this.#deleteCaption();
|
|
814
|
+
button.setAttribute('aria-label', button.title);
|
|
815
|
+
}
|
|
816
|
+
|
|
757
817
|
#renderRows(rows, columns, start) {
|
|
758
818
|
this.#rowInteraction.cancel();
|
|
759
819
|
|
|
@@ -828,6 +888,7 @@ export const Grid = defineComponent({
|
|
|
828
888
|
existing.delete(column.field);
|
|
829
889
|
}
|
|
830
890
|
for (const td of existing.values()) td.remove();
|
|
891
|
+
this.#renderRowAction(tr, label, this.#columnCount(columns));
|
|
831
892
|
tr.setAttribute('aria-rowindex', String(this.#headerRows + start + keep.size + 1));
|
|
832
893
|
this.#renderCells(tr, cells, node);
|
|
833
894
|
this.#cellEditor.decorate(tr, label);
|
|
@@ -840,8 +901,8 @@ export const Grid = defineComponent({
|
|
|
840
901
|
if (!rows.length && this.#rowLayout.count === 0 && !this.parameters.loading) {
|
|
841
902
|
const tr = this.ownerDocument.createElement('tr'), td = this.ownerDocument.createElement('td');
|
|
842
903
|
tr.setAttribute('role', 'row'); tr.setAttribute('aria-rowindex', String(this.#headerRows + 1));
|
|
843
|
-
td.setAttribute('role', 'cell'); td.setAttribute('aria-colspan', String(
|
|
844
|
-
td.className = 'empty'; td.colSpan =
|
|
904
|
+
td.setAttribute('role', 'cell'); td.setAttribute('aria-colspan', String(this.#columnCount(columns)));
|
|
905
|
+
td.className = 'empty'; td.colSpan = this.#columnCount(columns); td.textContent = 'No rows'; tr.append(td); this.#body.append(tr);
|
|
845
906
|
}
|
|
846
907
|
}
|
|
847
908
|
#renderCells(row, cells, node) {
|