@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
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import {renderIcon} from '../icons.js';
|
|
1
2
|
/** Parent-owned regions. Layout changes never move or recreate slotted content. */
|
|
3
|
+
import {labelboxContent} from '../view/labelbox.js';
|
|
4
|
+
import {toolbarIconParameters, projectToolbarIconStyle} from './toolbar-icon-style.js';
|
|
2
5
|
import {defineComponent} from './registry.js';
|
|
3
6
|
import {Container} from './container.js';
|
|
4
7
|
import {WindowSurface} from './window-surface.js';
|
|
@@ -194,8 +197,6 @@ export const BorderContainer = defineComponent({
|
|
|
194
197
|
max-height var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
|
|
195
198
|
margin var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out)}
|
|
196
199
|
.drawer:hover,.drawer:focus-visible{opacity:var(--gramlot-drawer-active-opacity,1)}
|
|
197
|
-
[data-axis=x]>.drawer[data-resizable]{cursor:col-resize}
|
|
198
|
-
[data-axis=y]>.drawer[data-resizable]{cursor:row-resize}
|
|
199
200
|
@media (hover:hover){
|
|
200
201
|
[data-axis=x]>.drawer:hover{transform:scale(var(--gramlot-drawer-hover-cross-scale,1.75),var(--gramlot-drawer-hover-length-scale,1.12))}
|
|
201
202
|
[data-axis=y]>.drawer:hover{transform:scale(var(--gramlot-drawer-hover-length-scale,1.12),var(--gramlot-drawer-hover-cross-scale,1.75))}
|
|
@@ -281,7 +282,7 @@ export const BorderContainer = defineComponent({
|
|
|
281
282
|
separator.setAttribute('aria-controls', viewport.id);
|
|
282
283
|
const drawer = doc.createElement('button'); drawer.type = 'button'; drawer.className = 'drawer';
|
|
283
284
|
drawer.setAttribute('aria-controls', viewport.id);
|
|
284
|
-
const drawerIcon = doc.createElement('span'); drawerIcon.className = 'drawer-icon'; drawerIcon.setAttribute('aria-hidden', 'true');
|
|
285
|
+
const drawerIcon = doc.createElement('span'); drawerIcon.className = 'drawer-icon'; drawerIcon.setAttribute('iconslot', ''); drawerIcon.setAttribute('aria-hidden', 'true');
|
|
285
286
|
const drawerLabel = doc.createElement('span'); drawerLabel.className = 'drawer-label';
|
|
286
287
|
const drawerContent = doc.createElement('span'); drawerContent.className = 'drawer-content';
|
|
287
288
|
const drawerViewport = doc.createElement('span'); drawerViewport.className = 'drawer-viewport';
|
|
@@ -376,7 +377,7 @@ export const BorderContainer = defineComponent({
|
|
|
376
377
|
USE_PROFILES: {html: true}, FORBID_TAGS: ['style', 'form', 'input', 'button', 'select', 'textarea'],
|
|
377
378
|
RETURN_DOM_FRAGMENT: true,
|
|
378
379
|
}));
|
|
379
|
-
state.drawerIcon
|
|
380
|
+
renderIcon(this, state.drawerIcon, config.icon);
|
|
380
381
|
state.drawerIcon.hidden = !config.icon;
|
|
381
382
|
state.drawer.toggleAttribute('data-icon', !!config.icon);
|
|
382
383
|
state.drawer.toggleAttribute('data-labelled', !!config.label);
|
|
@@ -545,6 +546,63 @@ export const BorderContainer = defineComponent({
|
|
|
545
546
|
/** Five-region command frame; the existing border engine owns layout. */
|
|
546
547
|
export const FramePane = defineComponent({
|
|
547
548
|
name: 'framePane', tag: 'gramlot-frame-pane', base: BorderContainer.base,
|
|
548
|
-
parameters: BorderContainer.parameters,
|
|
549
|
-
|
|
549
|
+
parameters: {...BorderContainer.parameters, ...toolbarIconParameters},
|
|
550
|
+
childParameters: {...BorderContainer.childParameters, region:{required:true, enum:REGIONS, binding:'read'}},
|
|
551
|
+
subTags: 'contentPane,menu',
|
|
552
|
+
implementation: Base => class extends BorderContainer.implementation(Base) {
|
|
553
|
+
static projectChild(element, attrs, context) {
|
|
554
|
+
if (labelboxContent(element).localName !== 'gramlot-menu') return super.projectChild(element, attrs, context);
|
|
555
|
+
const {region, ...rest} = attrs;
|
|
556
|
+
if (rest.presentation !== 'bar' || !REGIONS.includes(region)) {
|
|
557
|
+
throw new TypeError('A direct framePane menu requires presentation="bar" and a frame region');
|
|
558
|
+
}
|
|
559
|
+
return {...rest, slot:'bars-' + region, orientation:['left','right'].includes(region) ? 'vertical' : 'horizontal'};
|
|
560
|
+
}
|
|
561
|
+
constructor() {
|
|
562
|
+
super();
|
|
563
|
+
const doc = this.ownerDocument;
|
|
564
|
+
const style = doc.createElement('style');
|
|
565
|
+
style.textContent = `
|
|
566
|
+
.frame-bars{display:flex;min-width:0;min-height:0;flex-direction:column;overflow:hidden}
|
|
567
|
+
.frame-bars[data-side=left],.frame-bars[data-side=right]{flex-direction:row}
|
|
568
|
+
::slotted(:nth-child(n+2 of [slot=bars-top]:not([hidden]))),
|
|
569
|
+
::slotted(:nth-child(n+2 of [slot=bars-bottom]:not([hidden]))){
|
|
570
|
+
border-block-start:1px solid color-mix(in srgb,var(--gramlot-border) 45%,transparent)}
|
|
571
|
+
::slotted(:nth-child(n+2 of [slot=bars-left]:not([hidden]))),
|
|
572
|
+
::slotted(:nth-child(n+2 of [slot=bars-right]:not([hidden]))){
|
|
573
|
+
border-inline-start:1px solid color-mix(in srgb,var(--gramlot-border) 45%,transparent)}
|
|
574
|
+
.control-box.has-bars{
|
|
575
|
+
grid-template-columns:var(--left,0px) auto minmax(0,1fr) auto var(--right,0px);
|
|
576
|
+
grid-template-rows:var(--top,0px) auto auto minmax(0,1fr) auto var(--bottom,0px);
|
|
577
|
+
grid-template-areas:'top top top top top' 'bars-top bars-top bars-top bars-top bars-top'
|
|
578
|
+
'left bars-left bars-center bars-right right' 'left bars-left center bars-right right'
|
|
579
|
+
'bars-bottom bars-bottom bars-bottom bars-bottom bars-bottom' 'bottom bottom bottom bottom bottom'}
|
|
580
|
+
.control-box.has-bars[data-design=sidebar]{
|
|
581
|
+
grid-template-areas:'left bars-left top bars-right right' 'left bars-left bars-top bars-right right'
|
|
582
|
+
'left bars-left bars-center bars-right right' 'left bars-left center bars-right right'
|
|
583
|
+
'left bars-left bars-bottom bars-right right' 'left bars-left bottom bars-right right'}
|
|
584
|
+
`;
|
|
585
|
+
this.shadowRoot.append(style);
|
|
586
|
+
const slots = [];
|
|
587
|
+
for (const side of REGIONS) {
|
|
588
|
+
const strip = doc.createElement('div'), slot = doc.createElement('slot');
|
|
589
|
+
strip.className = 'frame-bars';
|
|
590
|
+
strip.dataset.side = side;
|
|
591
|
+
slot.name = 'bars-' + side;
|
|
592
|
+
strip.style.gridArea = slot.name;
|
|
593
|
+
strip.hidden = true;
|
|
594
|
+
slots.push(slot);
|
|
595
|
+
slot.addEventListener('slotchange', () => {
|
|
596
|
+
strip.hidden = !slot.assignedElements().length;
|
|
597
|
+
this.control.classList.toggle('has-bars', slots.some(s => !s.parentElement.hidden));
|
|
598
|
+
});
|
|
599
|
+
strip.append(slot);
|
|
600
|
+
this.control.append(strip);
|
|
601
|
+
}
|
|
602
|
+
style.textContent += '.frame-bars[hidden]{display:none}';
|
|
603
|
+
}
|
|
604
|
+
projectAttributes(attrs, adapt) {
|
|
605
|
+
return projectToolbarIconStyle(this, super.projectAttributes(attrs, adapt));
|
|
606
|
+
}
|
|
607
|
+
}
|
|
550
608
|
});
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import {renderIcon, iconSource} from '../icons.js';
|
|
1
2
|
import {labelboxContent} from '../view/labelbox.js';
|
|
2
3
|
import {choiceFieldStyles} from './choice-field-styles.js';
|
|
3
4
|
/** Built-in command surfaces. Execution stays in ButtonBinding, state in ControlAdapter. */
|
|
4
5
|
import {defineComponent, defineCollection} from './registry.js';
|
|
5
6
|
import {controlElement} from './bases.js';
|
|
6
7
|
import {projectParameters} from './parameters.js';
|
|
8
|
+
import {toolbarIconParameters} from './toolbar-icon-style.js';
|
|
7
9
|
import {MenuContainer, menuLine} from './menus.js';
|
|
8
10
|
|
|
9
11
|
function Command(HTMLElement) {
|
|
@@ -17,26 +19,26 @@ function Command(HTMLElement) {
|
|
|
17
19
|
this.control.type = 'button';
|
|
18
20
|
this.control.id = 'control';
|
|
19
21
|
this.icon = doc.createElement('span');
|
|
20
|
-
this.icon.className = 'icon';
|
|
22
|
+
this.icon.className = 'icon'; this.icon.setAttribute('iconslot', '');
|
|
21
23
|
this.icon.setAttribute('aria-hidden', 'true');
|
|
22
24
|
this.caption = doc.createElement('slot');
|
|
23
25
|
this.control.append(this.icon, this.caption);
|
|
24
26
|
this.controlBox.append(this.control);
|
|
25
27
|
const style = doc.createElement('style');
|
|
26
28
|
style.textContent = `:host{vertical-align:middle} :host([hidden]){display:none} .control-box{display:flex;align-items:stretch}
|
|
27
|
-
button{display:inline-flex;align-items:center;justify-content:center;gap:var(--gramlot-button-gap,.35em);font:inherit;
|
|
28
|
-
color:var(--gramlot-button-color,var(--gramlot-ink,CanvasText));background:var(--gramlot-button-background,var(--gramlot-
|
|
29
|
-
border:
|
|
30
|
-
min-
|
|
31
|
-
padding:var(--gramlot-button-padding
|
|
32
|
-
button:hover:not(:disabled){background:var(--gramlot-button-hover,var(--gramlot-
|
|
29
|
+
button{display:inline-flex;align-items:center;justify-content:center;gap:var(--gramlot-button-gap,.35em);font:inherit;font-size:var(--gramlot-field-font-size,inherit);line-height:1.25;box-sizing:border-box;
|
|
30
|
+
color:var(--gramlot-button-color,var(--gramlot-ink,CanvasText));background:var(--gramlot-button-background,color-mix(in srgb,var(--gramlot-surface,Canvas) 84%,currentColor));
|
|
31
|
+
border:0;border-radius:var(--gramlot-radius-sm,4px);
|
|
32
|
+
min-block-size:max(var(--gramlot-button-height,24px),var(--gramlot-touch-target,0px));min-inline-size:var(--gramlot-touch-target,0px);
|
|
33
|
+
padding:var(--gramlot-button-padding,2px 8px);cursor:pointer}
|
|
34
|
+
button:hover:not(:disabled){background:var(--gramlot-button-hover,color-mix(in srgb,var(--gramlot-surface,Canvas) 74%,currentColor))}
|
|
33
35
|
:host(.button--secondary) button{background:var(--gramlot-selected,Highlight);color:var(--gramlot-action,CanvasText);border-color:transparent}
|
|
34
36
|
:host(.button--secondary) button:hover:not(:disabled){background:var(--gramlot-selected,Highlight);color:var(--gramlot-action-hover,CanvasText);border-color:var(--gramlot-action,CanvasText)}
|
|
35
37
|
button:active:not(:disabled){filter:brightness(.9)}
|
|
36
38
|
@media(prefers-contrast:more){button{border:2px solid currentColor}}
|
|
37
39
|
:host(.button--quiet) button{background:transparent;color:var(--gramlot-action,CanvasText);border-color:transparent}
|
|
38
40
|
:host(.button--quiet) button:hover:not(:disabled){background:var(--gramlot-selected,Highlight);color:var(--gramlot-action-hover,CanvasText);border-color:transparent}
|
|
39
|
-
button:focus-visible{outline:
|
|
41
|
+
button:focus-visible{outline:1px solid var(--gramlot-focus-ring,Highlight);outline-offset:-1px}
|
|
40
42
|
button:disabled{opacity:.55;cursor:not-allowed} .icon:empty{display:none} .icon img{display:block;width:100%;height:100%;object-fit:contain} .icon:has(img){width:1em;height:1em}
|
|
41
43
|
.led{display:inline-block;width:.6em;height:.6em;border-radius:50%;background:var(--gramlot-button-led-off,#888)}
|
|
42
44
|
[aria-pressed=true] .led{background:var(--gramlot-button-led-on,#2b9a46)}
|
|
@@ -46,10 +48,10 @@ function Command(HTMLElement) {
|
|
|
46
48
|
max-width:var(--gramlot-popup-available-width);max-height:var(--gramlot-popup-available-height);
|
|
47
49
|
border:1px solid var(--gramlot-border-control,#888);border-radius:var(--gramlot-radius-sm,4px);
|
|
48
50
|
color:var(--gramlot-ink,CanvasText);background:var(--gramlot-field-background,Canvas);box-shadow:0 3px 12px #0003}
|
|
49
|
-
:host(:is([role=menuitem],[role=menuitemcheckbox])){display:block} :host(:is([role=menuitem],[role=menuitemcheckbox])) button{width:100%;justify-content:start;border:0;background:transparent}
|
|
51
|
+
:host(:is([role=menuitem],[role=menuitemcheckbox])){display:block} :host(:is([role=menuitem],[role=menuitemcheckbox])) button:not(.standard-button){width:100%;justify-content:start;border:0;background:transparent}
|
|
50
52
|
:host([role=separator]){display:block;border-top:1px solid var(--gramlot-border-control,#888);margin:.25em}
|
|
51
53
|
:host([role=separator]) button{display:none}
|
|
52
|
-
@media(forced-colors:active){button,:host(.button--secondary) button,:host(.button--quiet) button{background:ButtonFace;color:ButtonText;border
|
|
54
|
+
@media(forced-colors:active){button,:host(.button--secondary) button,:host(.button--quiet) button{background:ButtonFace;color:ButtonText;border:1px solid ButtonText;filter:none}}
|
|
53
55
|
`;
|
|
54
56
|
style.textContent += `
|
|
55
57
|
#control.icon-only{gap:0;padding:var(--gramlot-button-icon-padding,5px);
|
|
@@ -95,29 +97,19 @@ function Command(HTMLElement) {
|
|
|
95
97
|
const rest = super.projectAttributes(attrs, adapt);
|
|
96
98
|
this.control.disabled = Boolean(this.parameters.disabled);
|
|
97
99
|
this.control.readOnly = Boolean(this.parameters.readonly);
|
|
98
|
-
this.renderIcon(this.parameters.icon
|
|
100
|
+
this.renderIcon(this.parameters.icon);
|
|
99
101
|
if (attrs['aria-label'] != null) this.control.setAttribute('aria-label', attrs['aria-label']);
|
|
100
102
|
else this.control.removeAttribute('aria-label');
|
|
101
103
|
if (this.#actionPresentation) this.setActionPresentation(this.#actionPresentation);
|
|
102
104
|
return rest;
|
|
103
105
|
}
|
|
104
|
-
renderIcon(icon,
|
|
105
|
-
if (!iconSrc) { this.icon.textContent = icon ?? ''; this.refreshIconOnly(); return; }
|
|
106
|
-
let image = this.icon.firstElementChild;
|
|
107
|
-
if (!image) {
|
|
108
|
-
image = this.ownerDocument.createElement('img');
|
|
109
|
-
image.alt = ''; image.draggable = false;
|
|
110
|
-
this.icon.replaceChildren(image);
|
|
111
|
-
}
|
|
112
|
-
if (image.getAttribute('src') !== iconSrc) image.setAttribute('src', iconSrc);
|
|
113
|
-
this.refreshIconOnly();
|
|
114
|
-
}
|
|
106
|
+
renderIcon(icon) { renderIcon(this, this.icon, icon); this.refreshIconOnly(); }
|
|
115
107
|
get entryIcon() { return this.parameters.icon; }
|
|
116
|
-
get entryIconSrc() { return this.
|
|
108
|
+
get entryIconSrc() { return iconSource(this, this.entryIcon); }
|
|
117
109
|
setActionPresentation(presentation) {
|
|
118
110
|
this.#actionPresentation = presentation;
|
|
119
111
|
this.hidden = presentation.hidden;
|
|
120
|
-
this.
|
|
112
|
+
this.renderIcon(presentation.icon);
|
|
121
113
|
this.title = presentation.title;
|
|
122
114
|
this.control.setAttribute('aria-label', presentation.title);
|
|
123
115
|
this.refreshIconOnly();
|
|
@@ -131,8 +123,7 @@ function Command(HTMLElement) {
|
|
|
131
123
|
Command.parameters = {
|
|
132
124
|
action: {dtype: 'T', nullable: true},
|
|
133
125
|
disabled: {dtype: 'B', default: false, binding: 'read'},
|
|
134
|
-
icon: {dtype: 'T', default: '', binding: 'read'}
|
|
135
|
-
iconSrc: {dtype: 'T', default: '', binding: 'read'}
|
|
126
|
+
icon: {dtype: 'T', default: '', binding: 'read'}
|
|
136
127
|
};
|
|
137
128
|
export const Button = defineComponent({name: 'button', tag: 'gramlot-button', base: Command,
|
|
138
129
|
command: true, subTags: '*', implementation: Base => class extends Base {}});
|
|
@@ -165,18 +156,22 @@ export const ToggleButton = defineComponent({name: 'toggleButton', tag: 'gramlot
|
|
|
165
156
|
|
|
166
157
|
export const Menu = defineComponent({name:'menu',tag:'gramlot-menu',base:MenuContainer,
|
|
167
158
|
subTags:'menuline,spacer,contentPane',parameters:{
|
|
159
|
+
...toolbarIconParameters,
|
|
160
|
+
showTooltip:{dtype:'B',nullable:true,binding:'read'},
|
|
168
161
|
presentation:{dtype:'T',default:'popup',enum:['popup','bar']},
|
|
169
162
|
orientation:{dtype:'T',default:'horizontal',enum:['horizontal','vertical']},
|
|
170
163
|
modifiers:{dtype:'T',nullable:true},
|
|
171
|
-
labelPosition:{dtype:'T',binding:'read',default:'beside',enum:['beside','below','tooltip']},
|
|
164
|
+
labelPosition:{dtype:'T',binding:'read',default:'beside',enum:['beside','below','tooltip']},icon_size:{dtype:'R',binding:'read',default:24},
|
|
172
165
|
resolver:{dtype:'T',nullable:true},cacheTime:{dtype:'R',default:-1},sync:{dtype:'B',default:false}
|
|
173
166
|
},implementation:Base=>class extends Base {}});
|
|
174
167
|
export const MenuLine = defineComponent({name:'menuline',tag:'gramlot-menu-line',base:Command,
|
|
175
168
|
command:true,subTags:'*',parameters:{
|
|
176
|
-
command:{dtype:'T',nullable:true},caption:{dtype:'T',nullable:true},code:{dtype:'T',nullable:true},
|
|
177
|
-
checked:{dtype:'B',nullable:true,binding:'read'},tooltip:{dtype:'T',nullable:true},
|
|
178
|
-
labelPosition:{dtype:'T',binding:'read',nullable:true,enum:['beside','below','tooltip']},
|
|
179
|
-
|
|
169
|
+
command:{dtype:'T',nullable:true},caption:{dtype:'T',nullable:true,binding:'read'},code:{dtype:'T',nullable:true},
|
|
170
|
+
checked:{dtype:'B',nullable:true,binding:'read'},tooltip:{dtype:'T',nullable:true,binding:'read'},
|
|
171
|
+
labelPosition:{dtype:'T',binding:'read',nullable:true,enum:['beside','below','tooltip']},icon_size:{dtype:'R',binding:'read',nullable:true},
|
|
172
|
+
...toolbarIconParameters,
|
|
173
|
+
badge:{dtype:['T','L','R'],nullable:true,binding:'read'},badge_color:{dtype:'T',nullable:true,binding:'read'},
|
|
174
|
+
expandInBar:{dtype:'R',nullable:true},group:{dtype:'B',default:false},
|
|
180
175
|
parameters:{annotation:{kind:'type',module:'builtins',name:'dict'},nullable:true},favorite:{dtype:'B',default:false}
|
|
181
176
|
},implementation:menuLine});
|
|
182
177
|
export const Spacer = defineComponent({name:'spacer',tag:'gramlot-spacer',base:HTMLElement=>class extends HTMLElement {
|
|
@@ -43,5 +43,5 @@ export function chartGeographicOptions(view,type,nameField,geometryField,fields,
|
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
return {backgroundColor:'#fff',title,legend:{type:'scroll',data:fields,left:12,right:12,bottom:10},
|
|
46
|
-
tooltip:{renderMode:'richText'},geo3D,series};
|
|
46
|
+
tooltip:{renderMode:'richText',formatter:({name,seriesName,value})=>`${name}\n${seriesName}: ${value}`},geo3D,series};
|
|
47
47
|
}
|
|
@@ -52,7 +52,7 @@ export const ChartPane = defineComponent({
|
|
|
52
52
|
options:`^${configpath}.seriesOptions`,roles:`^${configpath}.measureRoles`,type:`^${configpath}.chartType`,_onBuilt:true});
|
|
53
53
|
const toolbar=frame.top.contentPane({display:'flex',justify_content:'flex-end',align_items:'center',padding:'2px 6px'});
|
|
54
54
|
const path=JSON.stringify(`${configpath}.drawer`);
|
|
55
|
-
toolbar.button({icon:'
|
|
55
|
+
toolbar.button({icon:'settings',aria_label:'Chart settings',title:'Chart settings',action:`this.SET(${path},this.GET(${path}) === 'close' ? true : 'close');`});
|
|
56
56
|
const prefix=node.getAttr('id') ?? `chart-${randomId()}`;
|
|
57
57
|
const layout=frame.center.borderContainer({id:`${prefix}-layout`,height:'100%'});
|
|
58
58
|
const config=layout.contentPane({region:'right',width:'260px',drawer:`^${configpath}.drawer`,
|
|
@@ -72,14 +72,14 @@ export const ChartPane = defineComponent({
|
|
|
72
72
|
background:'var(--gramlot-surface-subtle)',border_top:'1px solid var(--gramlot-border)'});
|
|
73
73
|
const get=key=>JSON.stringify(`${configpath}.${key}`);
|
|
74
74
|
const transport=timeline.div({display:'flex',align_items:'center',gap:'2px',flex_shrink:'0'});
|
|
75
|
-
transport.button({icon:'
|
|
75
|
+
transport.button({icon:'previous',aria_label:'Previous period',title:'Previous period',id:`${prefix}-time-previous`,
|
|
76
76
|
disabled:`^${configpath}.timeIndex:={} <= 0`,action:`this.SET(${get('timePlaying')},false);this.SET(${get('timeIndex')},Math.max(0,this.GET(${get('timeIndex')})-1));`});
|
|
77
|
-
transport.button({icon:`^${configpath}.timePlaying:={} ? '
|
|
77
|
+
transport.button({icon:`^${configpath}.timePlaying:={} ? 'pause' : 'play'`,
|
|
78
78
|
aria_label:`^${configpath}.timePlaying:={} ? 'Pause' : 'Play'`,title:`^${configpath}.timePlaying:={} ? 'Pause' : 'Play'`,aria_pressed:`^${configpath}.timePlaying`,id:`${prefix}-time-play`,disabled:`^${configpath}.timeMax:={} === 0`,
|
|
79
79
|
action:`if(!this.GET(${get('timePlaying')}) && this.GET(${get('timeIndex')}) >= this.GET(${get('timeMax')}))this.SET(${get('timeIndex')},0);this.SET(${get('timePlaying')},!this.GET(${get('timePlaying')}));`});
|
|
80
|
-
transport.button({icon:'
|
|
80
|
+
transport.button({icon:'stop',aria_label:'Stop',title:'Stop and return to the beginning',id:`${prefix}-time-stop`,
|
|
81
81
|
disabled:`^${configpath}.timeMax:={} === 0`,action:`this.SET(${get('timePlaying')},false);this.SET(${get('timeIndex')},0);`});
|
|
82
|
-
transport.button({icon:'
|
|
82
|
+
transport.button({icon:'next',aria_label:'Next period',title:'Next period',id:`${prefix}-time-next`,
|
|
83
83
|
disabled:`^${configpath}.timeAtEnd`,action:`this.SET(${get('timePlaying')},false);this.SET(${get('timeIndex')},Math.min(this.GET(${get('timeMax')}),this.GET(${get('timeIndex')})+1));`});
|
|
84
84
|
const scrubber=timeline.div({flex:'1',min_width:'120px'});
|
|
85
85
|
scrubber.horizontalSlider({width:'100%',id:`${prefix}-time-slider`,aria_label:'Temporal snapshot',value:`^${configpath}.timeIndex`,min:0,max:`^${configpath}.timeMax`,step:1,live:true,flex:'1',
|
|
@@ -16,6 +16,10 @@ export function chartSpatialOptions(view,type,first,second,fields,settings,domai
|
|
|
16
16
|
const axisOptions=index=>({type:axes[index].numeric?'value':'category',name:[first,second][index],nameGap:35,
|
|
17
17
|
...(axes[index].numeric?(domains?{min:domains.dimensions[index].range[0],max:domains.dimensions[index].range[1]}:{}):{data:dimensions[index]}),
|
|
18
18
|
...(axes[index].date?{axisLabel:{formatter:value=>new Date(value).toISOString().slice(0,10)}}:{})});
|
|
19
|
+
const axisValue=(index,value)=>axes[index].date ? new Date(value).toISOString()
|
|
20
|
+
: axes[index].numeric ? value : dimensions[index][value];
|
|
21
|
+
const tooltip={renderMode:'richText',formatter:({seriesName,value:[x,y,z]})=>
|
|
22
|
+
`${first}: ${axisValue(0,x)}\n${second}: ${axisValue(1,y)}\n${seriesName}: ${z}`};
|
|
19
23
|
const series=[];
|
|
20
24
|
datasets.forEach((dataset,index)=>{
|
|
21
25
|
const common={name:fields[index],type,itemStyle:{color:settings[index].color},lineStyle:{color:settings[index].color,width:3}};
|
|
@@ -35,6 +39,6 @@ export function chartSpatialOptions(view,type,first,second,fields,settings,domai
|
|
|
35
39
|
} else series.push({...common,id:fields[index],symbolSize:9,data:mapped});
|
|
36
40
|
});
|
|
37
41
|
return {backgroundColor:'#fff',legend:{type:'scroll',left:12,right:12,bottom:10,data:fields},
|
|
38
|
-
tooltip
|
|
42
|
+
tooltip,xAxis3D:axisOptions(0),yAxis3D:axisOptions(1),zAxis3D:{type:'value',name:'Value',nameGap:40,...(domains?{min:domains.z[0],max:domains.z[1]}:{})},
|
|
39
43
|
grid3D:{top:8,bottom:64,height:null,left:16,right:16,width:null,boxWidth:100,boxDepth:80,viewControl:{projection:'perspective'}},series};
|
|
40
44
|
}
|
|
@@ -13,6 +13,7 @@ export class CheckBoxTextEditor {
|
|
|
13
13
|
this.toggle.className = 'choice-toggle'; this.toggle.setAttribute('aria-label', 'Show options');
|
|
14
14
|
this.element = doc.createElement('div'); this.element.className = 'summary-row choice-field';
|
|
15
15
|
this.element.append(this.input, this.toggle, this.list);
|
|
16
|
+
this.toggle.addEventListener('mousedown', event => event.preventDefault());
|
|
16
17
|
this.toggle.addEventListener('click', () => owner.openChoices());
|
|
17
18
|
this.input.addEventListener('input', event => {
|
|
18
19
|
if (this.locked) return;
|
|
@@ -4,6 +4,7 @@ import {positionPopup} from './popup.js';
|
|
|
4
4
|
import {CheckBoxTree} from './check-box-tree.js';
|
|
5
5
|
import {CheckBoxTextEditor} from './check-box-text-editor.js';
|
|
6
6
|
import {choiceFieldStyles} from './choice-field-styles.js';
|
|
7
|
+
import {trackChoiceFocus} from '../view/choice-focus.js';
|
|
7
8
|
|
|
8
9
|
/** Multiple choices keep the existing group's commit and validation lifecycle. */
|
|
9
10
|
export function checkBoxChoices(Base) {
|
|
@@ -22,6 +23,7 @@ export function checkBoxChoices(Base) {
|
|
|
22
23
|
super();
|
|
23
24
|
const doc = this.ownerDocument;
|
|
24
25
|
this.#text = new CheckBoxTextEditor(this);
|
|
26
|
+
trackChoiceFocus(this.#text.element);
|
|
25
27
|
this.summary = this.#text.input; this.summary.hidden = true;
|
|
26
28
|
this.summary.className = 'summary';
|
|
27
29
|
this.summary.setAttribute('aria-haspopup', 'dialog');
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {NativeControl} from './bases.js';
|
|
2
2
|
import {parseChoices} from './choices.js';
|
|
3
3
|
import {choiceFieldStyles} from './choice-field-styles.js';
|
|
4
|
+
import {trackChoiceFocus} from '../view/choice-focus.js';
|
|
4
5
|
import {positionPopup} from './popup.js';
|
|
5
6
|
import {Bag} from '@genrojs/bag';
|
|
6
7
|
|
|
@@ -25,18 +26,18 @@ export function ChoiceEditor(HTMLElement) {
|
|
|
25
26
|
const doc = this.ownerDocument;
|
|
26
27
|
const style = doc.createElement('style');
|
|
27
28
|
style.textContent = choiceFieldStyles + `.option{position:relative} #control{width:100%;padding-right:calc(var(--gramlot-choice-toggle-width,1.6em) + .2em)}
|
|
28
|
-
#control:focus-visible{outline:1px solid var(--gramlot-border-control,#7a8798);outline-offset:-3px}
|
|
29
29
|
|
|
30
30
|
.choices{min-width:min(var(--gramlot-choice-popup-min-width,0px),var(--gramlot-popup-available-width,100vw));max-width:var(--gramlot-popup-available-width,100vw);position:fixed;inset:auto;margin:0;padding:var(--gramlot-popup-padding,4px);box-sizing:border-box;max-height:min(var(--gramlot-choice-max-height,20rem),var(--gramlot-popup-available-height,100vh));overflow:auto;
|
|
31
31
|
border:1px solid var(--gramlot-border-control,#aab4c2);border-radius:var(--gramlot-radius-sm,4px);background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);font:inherit;font-size:var(--gramlot-field-font-size,1em);line-height:1.4;box-shadow:var(--gramlot-shadow,0 3px 9px #0002)}
|
|
32
32
|
.choices[hidden]{display:none} .choice{min-height:var(--gramlot-touch-target,0px);display:flex;align-items:center;padding:var(--gramlot-choice-item-padding,.25em .5em);border-radius:var(--gramlot-radius-sm,4px);cursor:pointer}
|
|
33
33
|
.choice:nth-child(even){background:var(--gramlot-choice-alternate-background,var(--gramlot-surface-subtle,transparent))}
|
|
34
|
-
.choice:hover
|
|
34
|
+
.choice:hover:not([aria-selected=true]){text-decoration:underline;text-underline-offset:.15em}
|
|
35
35
|
.choice-detail{margin-inline-start:var(--gramlot-space-3,.75rem);color:var(--gramlot-text-secondary,GrayText)}
|
|
36
36
|
.choice[aria-selected=true]{background:var(--gramlot-selected,Highlight);color:var(--gramlot-ink,HighlightText)}`;
|
|
37
37
|
this.toggle = doc.createElement('button');
|
|
38
38
|
this.toggle.className = 'toggle choice-toggle'; this.toggle.type = 'button'; this.toggle.tabIndex = -1;
|
|
39
39
|
this.control.parentElement.classList.add('choice-field');
|
|
40
|
+
trackChoiceFocus(this.control.parentElement);
|
|
40
41
|
this.toggle.setAttribute('aria-label', 'Show options');
|
|
41
42
|
this.control.parentElement.append(this.toggle);
|
|
42
43
|
this.choices = doc.createElement('div');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Shared
|
|
1
|
+
/** Shared dropdown surface and inset chevron. */
|
|
2
2
|
export const choiceFieldStyles = `
|
|
3
3
|
.choice-field{position:relative;min-width:0}
|
|
4
4
|
.choice-field>input{box-sizing:border-box;width:100%;padding-inline-end:calc(var(--gramlot-choice-toggle-width,1.6em) + .4em)}
|
|
@@ -10,5 +10,13 @@ export const choiceFieldStyles = `
|
|
|
10
10
|
border-block-end:1.5px solid currentColor;transform:translateY(-.1em) rotate(45deg);pointer-events:none}
|
|
11
11
|
.choice-toggle:disabled{opacity:.5;cursor:default}
|
|
12
12
|
.choice-toggle:focus-visible{outline:1px solid var(--gramlot-focus-ring,Highlight);outline-offset:-3px}
|
|
13
|
+
.choice-field>:is(input#control,input.summary){border-width:var(--gramlot-choice-border-width,1px)}
|
|
14
|
+
.choice-field>:is(input#control,input.summary):not([aria-invalid=true]){background:var(--gramlot-choice-background,var(--gramlot-field-background,Canvas))}
|
|
15
|
+
.choice-field>input.summary[aria-invalid=true]{background:var(--gramlot-error-background,Canvas)}
|
|
16
|
+
.choice-field:not(.pointer-focus)>:is(input#control,input.summary):focus-visible,
|
|
17
|
+
.choice-field:not(.pointer-focus):has(>.choice-toggle:focus-visible)>:is(input#control,input.summary){
|
|
18
|
+
outline:1px solid var(--gramlot-focus-ring,Highlight);outline-offset:-1px}
|
|
19
|
+
.choice-field.pointer-focus>:is(input#control,input.summary):focus,.choice-field:has(>input)>.choice-toggle:focus{outline:none}
|
|
20
|
+
@media(forced-colors:active){.choice-field>:is(input#control,input.summary){border:1px solid ButtonText}}
|
|
13
21
|
.choice-field>input::-webkit-calendar-picker-indicator{opacity:0}
|
|
14
22
|
`;
|
|
@@ -8,6 +8,8 @@ import {closeBrackets, closeBracketsKeymap, autocompletion, completionKeymap} fr
|
|
|
8
8
|
import {setDiagnostics} from '@codemirror/lint';
|
|
9
9
|
import {tags} from '@lezer/highlight';
|
|
10
10
|
import {python} from '@codemirror/lang-python';
|
|
11
|
+
import {gramlotHighlighting} from './code-mirror-gramlot.js';
|
|
12
|
+
import {rust} from '@codemirror/lang-rust';
|
|
11
13
|
import {javascript} from '@codemirror/lang-javascript';
|
|
12
14
|
import {json} from '@codemirror/lang-json';
|
|
13
15
|
import {html} from '@codemirror/lang-html';
|
|
@@ -17,7 +19,15 @@ import {markdown} from '@codemirror/lang-markdown';
|
|
|
17
19
|
import {typst_lezer} from 'codemirror-lang-typst/lezer';
|
|
18
20
|
import {sql} from '@codemirror/lang-sql';
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
// Rust macro arguments are token trees. The parser classifies their bare names
|
|
23
|
+
// as identifiers, including the component and attribute names inside gramlot!().
|
|
24
|
+
const rustNames = syntaxHighlighting(HighlightStyle.define([
|
|
25
|
+
{tag:[tags.variableName, tags.propertyName], color:'var(--gramlot-editor-function, #5499cb)'},
|
|
26
|
+
{tag:[tags.typeName, tags.namespace], color:'light-dark(#65428c, #c9a6ee)'},
|
|
27
|
+
{tag:tags.macroName, color:'var(--gramlot-editor-keyword, #9677d9)', fontWeight:'bold'}
|
|
28
|
+
]));
|
|
29
|
+
const gramlotModes = {'gramlot-py':'python', 'gramlot-js':'javascript', 'gramlot-rs':'rust'};
|
|
30
|
+
const languages = {text: () => [], python, rust: () => [rust(), rustNames], javascript, typescript: () => javascript({typescript:true}), json, html, css, xml, markdown, sql, typst:typst_lezer};
|
|
21
31
|
const colors = syntaxHighlighting(HighlightStyle.define([
|
|
22
32
|
{tag:[tags.keyword, tags.modifier], color:'var(--gramlot-editor-keyword, #9677d9)'},
|
|
23
33
|
{tag:[tags.string, tags.regexp], color:'var(--gramlot-editor-string, #318f74)'},
|
|
@@ -37,8 +47,11 @@ const theme = EditorView.theme({
|
|
|
37
47
|
'.cm-textfield, .cm-button': {color:'inherit', background:'var(--gramlot-field-background, Canvas)', borderColor:'var(--gramlot-border-control, GrayText)'},
|
|
38
48
|
'.cm-search': {fontFamily:'system-ui', fontSize:'13px'}
|
|
39
49
|
});
|
|
40
|
-
function configuration(
|
|
41
|
-
|
|
50
|
+
function configuration(host) {
|
|
51
|
+
const p = host.parameters;
|
|
52
|
+
const baseLanguage = gramlotModes[p.language];
|
|
53
|
+
return [languages[baseLanguage ?? p.language](),
|
|
54
|
+
baseLanguage ? gramlotHighlighting(host.componentBuilder, p.language) : [], indentUnit.of(' '.repeat(p.indentUnit)),
|
|
42
55
|
EditorState.tabSize.of(p.indentUnit), EditorState.readOnly.of(Boolean(p.readonly || p.disabled)),
|
|
43
56
|
EditorView.editable.of(!p.disabled), EditorView.contentAttributes.of({'aria-readonly':String(p.readonly), 'aria-disabled':String(p.disabled), tabindex:p.disabled ? '-1' : '0', 'aria-label':p.lbl || 'Code editor'}),
|
|
44
57
|
p.lineNumbers ? lineNumbers() : [], p.lineWrapping ? EditorView.lineWrapping : [],
|
|
@@ -77,10 +90,10 @@ export function createEditor(host) {
|
|
|
77
90
|
if (update.docChanged || update.transactions.some(transaction => transaction.reconfigured)) publishHistory();
|
|
78
91
|
})];
|
|
79
92
|
let projecting = false;
|
|
80
|
-
const state = doc => EditorState.create({doc, extensions:[options.of(configuration(host
|
|
93
|
+
const state = doc => EditorState.create({doc, extensions:[options.of(configuration(host)), ...extensions]});
|
|
81
94
|
const view = new EditorView({state:state(host.readControlValue()), parent:host.control, root:host.shadowRoot});
|
|
82
95
|
return {view,
|
|
83
|
-
configure() {view.dispatch({effects:options.reconfigure(configuration(host
|
|
96
|
+
configure() {view.dispatch({effects:options.reconfigure(configuration(host))});},
|
|
84
97
|
replace(value) {
|
|
85
98
|
const current = view.state.doc.toString();
|
|
86
99
|
let from = 0, end = current.length, nextEnd = value.length;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Highlight authored component names against the collections of this editor's page.
|
|
2
|
+
import {Prec} from '@codemirror/state';
|
|
3
|
+
import {syntaxTree} from '@codemirror/language';
|
|
4
|
+
import {Decoration, EditorView, ViewPlugin} from '@codemirror/view';
|
|
5
|
+
|
|
6
|
+
const component = Decoration.mark({class: 'cm-gramlot-component'});
|
|
7
|
+
const attribute = Decoration.mark({class: 'cm-gramlot-attribute'});
|
|
8
|
+
|
|
9
|
+
function highlight(view, builder, mode) {
|
|
10
|
+
const marks = [];
|
|
11
|
+
const text = node => view.state.sliceDoc(node.from, node.to);
|
|
12
|
+
function markComponent(name) {
|
|
13
|
+
const tag = builder.schemaTagNames[text(name).toLowerCase()];
|
|
14
|
+
const definition = builder.schema[tag]?._meta?.gramlot_component;
|
|
15
|
+
if (definition) marks.push(component.range(name.from, name.to));
|
|
16
|
+
return definition;
|
|
17
|
+
}
|
|
18
|
+
function markAttribute(name, definition) {
|
|
19
|
+
if (definition && Object.hasOwn(definition.parameters, text(name))) {
|
|
20
|
+
marks.push(attribute.range(name.from, name.to));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function call(expression) {
|
|
24
|
+
const member = expression.firstChild;
|
|
25
|
+
if (member?.name !== 'MemberExpression' || member.lastChild?.name !== 'PropertyName') return;
|
|
26
|
+
const args = expression.getChild('ArgList');
|
|
27
|
+
if (!args) return;
|
|
28
|
+
const definition = markComponent(member.lastChild);
|
|
29
|
+
if (!definition) return;
|
|
30
|
+
if (mode === 'gramlot-py') {
|
|
31
|
+
for (const key of args.getChildren('VariableName')) {
|
|
32
|
+
if (key.nextSibling?.name === 'AssignOp') markAttribute(key, definition);
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
for (const object of args.getChildren('ObjectExpression')) {
|
|
36
|
+
for (const prop of object.getChildren('Property')) {
|
|
37
|
+
const key = prop.getChild('PropertyDefinition');
|
|
38
|
+
if (key) markAttribute(key, definition);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function nextToken(node) {
|
|
44
|
+
let next = node.nextSibling;
|
|
45
|
+
while (next && ['LineComment', 'BlockComment'].includes(next.name)) next = next.nextSibling;
|
|
46
|
+
return next;
|
|
47
|
+
}
|
|
48
|
+
function rustCall(expression) {
|
|
49
|
+
const field = expression.firstChild;
|
|
50
|
+
if (field?.name !== 'FieldExpression' || field.lastChild?.name !== 'FieldIdentifier') return;
|
|
51
|
+
const definition = markComponent(field.lastChild);
|
|
52
|
+
const kwargs = expression.getChild('ArgList')?.getChild('MacroInvocation');
|
|
53
|
+
if (!definition || !kwargs || text(kwargs.firstChild) !== 'kw') return;
|
|
54
|
+
const body = kwargs.getChild('BracedTokens');
|
|
55
|
+
if (!body) return;
|
|
56
|
+
let keyPosition = true;
|
|
57
|
+
for (let key = nextToken(body.firstChild); key; key = nextToken(key)) {
|
|
58
|
+
if (keyPosition && key.name === 'Identifier' && nextToken(key)?.name === ':') {
|
|
59
|
+
markAttribute(key, definition);
|
|
60
|
+
}
|
|
61
|
+
keyPosition = key.name === ',';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const tree = syntaxTree(view.state);
|
|
65
|
+
tree.iterate({from:view.viewport.from, to:view.viewport.to, enter(ref) {
|
|
66
|
+
if (ref.name !== 'CallExpression') return;
|
|
67
|
+
if (mode === 'gramlot-rs') rustCall(ref.node);
|
|
68
|
+
else call(ref.node);
|
|
69
|
+
}});
|
|
70
|
+
return Decoration.set(marks, true);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function gramlotHighlighting(builder, mode) {
|
|
74
|
+
return [EditorView.baseTheme({
|
|
75
|
+
'.cm-gramlot-component': {fontWeight:'bold', color:'light-dark(#155c72, #8cd8e8)'},
|
|
76
|
+
'.cm-gramlot-attribute': {color:'light-dark(#80552d, #e3be93)'}
|
|
77
|
+
}), Prec.highest(ViewPlugin.fromClass(class {
|
|
78
|
+
constructor(view) { this.decorations = highlight(view, builder, mode); }
|
|
79
|
+
update(update) {
|
|
80
|
+
if (update.docChanged || update.viewportChanged || syntaxTree(update.startState) !== syntaxTree(update.state)) {
|
|
81
|
+
this.decorations = highlight(update.view, builder, mode);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}, {decorations: plugin => plugin.decorations}))];
|
|
85
|
+
}
|
|
@@ -4,7 +4,7 @@ import {defineComponent} from './registry.js';
|
|
|
4
4
|
import {Labelbox} from './labelbox.js';
|
|
5
5
|
import {FieldState} from './field-state.js';
|
|
6
6
|
|
|
7
|
-
const languages = ['text', 'python', 'javascript', 'typescript', 'json', 'html', 'css', 'xml', 'markdown', 'sql', 'typst'];
|
|
7
|
+
const languages = ['text', 'gramlot-py', 'gramlot-js', 'gramlot-rs', 'python', 'rust', 'javascript', 'typescript', 'json', 'html', 'css', 'xml', 'markdown', 'sql', 'typst'];
|
|
8
8
|
let engineModule;
|
|
9
9
|
function EditorControl(HTMLElement) {
|
|
10
10
|
return class extends controlElement(HTMLElement) {
|
|
@@ -29,6 +29,7 @@ function EditorControl(HTMLElement) {
|
|
|
29
29
|
});
|
|
30
30
|
this.control.addEventListener('focusout', () => this.#emit('change'));
|
|
31
31
|
}
|
|
32
|
+
setSourceContext(context) { this.componentBuilder = context.sourceNode.rootBuilder; }
|
|
32
33
|
get liveWrites() { return true; }
|
|
33
34
|
connectedCallback() {
|
|
34
35
|
const generation = ++this.#generation;
|
|
@@ -79,7 +80,7 @@ EditorControl.parameters = {
|
|
|
79
80
|
live:{dtype:'B', default:true, binding:'read'}
|
|
80
81
|
};
|
|
81
82
|
const toggle = {dtype:'B', default:true, binding:'read'};
|
|
82
|
-
export const CodeMirror = defineComponent({name:'codeMirror', tag:'gramlot-code-mirror', base:EditorControl, mixins:[Labelbox,FieldState],
|
|
83
|
+
export const CodeMirror = defineComponent({name:'codeMirror', tag:'gramlot-code-mirror', base:EditorControl, sourceContext:true, mixins:[Labelbox,FieldState],
|
|
83
84
|
parameters:{value:{dtype:'T', default:'', binding:'twoWay'}, language:{dtype:'T', default:'text', binding:'read', enum:languages},
|
|
84
85
|
lineNumbers:toggle, lineWrapping:toggle, indentUnit:{dtype:'L',default:4,binding:'read'},
|
|
85
86
|
fontSize:{dtype:'L',default:14,binding:'read'}, fontFamily:{dtype:'T',default:'monospace',binding:'read'},
|