@gramlot/gramlot 0.3.41 → 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/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 +3961 -1249
- 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/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/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,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'},
|
|
@@ -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'});
|