@gramlot/gramlot 0.3.41 → 0.5.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/align-center.svg +4 -0
- package/assets/icons/align-justify.svg +4 -0
- package/assets/icons/align-left.svg +4 -0
- package/assets/icons/align-right.svg +4 -0
- package/assets/icons/applications.svg +4 -0
- package/assets/icons/archive.svg +4 -0
- package/assets/icons/attachment.svg +4 -0
- package/assets/icons/bold.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/eraser.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/horizontal-rule.svg +4 -0
- package/assets/icons/image.svg +4 -0
- package/assets/icons/import.svg +4 -0
- package/assets/icons/indent.svg +4 -0
- package/assets/icons/info.svg +4 -0
- package/assets/icons/inspector.svg +4 -0
- package/assets/icons/italic.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-bulleted.svg +4 -0
- package/assets/icons/list-numbered.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/outdent.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/paragraph.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/select-all.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/strikethrough.svg +4 -0
- package/assets/icons/table.svg +4 -0
- package/assets/icons/tree.svg +4 -0
- package/assets/icons/underline.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/charts/grammar.json +2032 -72
- package/dist/components/editors/__init__.py +1 -1
- package/dist/components/editors/assets/collection.js +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 +453 -447
- package/dist/components/editors/commands.json +113 -1
- package/dist/components/editors/grammar.json +12 -5
- 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 +112 -0
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +5165 -359
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +1 -0
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +433 -4
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +51 -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 +5486 -2029
- package/dist/gramlot.min.js +361 -138
- package/dist/libraries.json +6 -4
- package/dist/standard-collections.js +1 -1
- package/dist/standard-grammar.js +1 -1
- package/package.json +6 -2
- package/src/binding/ask-dialog.js +17 -3
- package/src/binding/providers.js +3 -2
- package/src/binding/remote.js +41 -6
- package/src/binding/runtime.js +30 -3
- package/src/builder/gramlot-builder.d.ts +3 -1
- package/src/builder/gramlot-builder.js +77 -26
- package/src/builder/source.js +78 -15
- package/src/builder/xml-recipe.js +144 -0
- package/src/chat-file-types.js +13 -0
- package/src/chat.d.ts +1 -0
- package/src/chat.js +35 -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-bar3d-options.js +0 -1
- package/src/components/chart-boxplot-options.js +1 -1
- package/src/components/chart-candlestick-options.js +1 -1
- package/src/components/chart-engines/echarts-options.js +6 -5
- package/src/components/chart-engines/echarts.js +27 -10
- package/src/components/chart-engines/plotly-map.js +1 -1
- package/src/components/chart-engines/plotly.js +21 -14
- package/src/components/chart-engines/uplot.js +17 -11
- package/src/components/chart-engines/vega.js +17 -11
- package/src/components/chart-funnel-options.js +1 -1
- package/src/components/chart-geographic-options.js +2 -2
- package/src/components/chart-heatmap-options.js +1 -1
- package/src/components/chart-map-bar3d-options.js +2 -2
- package/src/components/chart-map-options.js +2 -2
- package/src/components/chart-pane.js +5 -5
- package/src/components/chart-parallel-options.js +1 -1
- package/src/components/chart-radar-options.js +1 -1
- package/src/components/chart-renderer.js +6 -1
- package/src/components/chart-sankey-options.js +1 -1
- package/src/components/chart-spatial-options.js +6 -2
- package/src/components/chart-sunburst-options.js +13 -1
- package/src/components/chart-theme.js +14 -0
- package/src/components/chart-treemap-options.js +1 -1
- package/src/components/chart-type-data.js +24 -4
- package/src/components/charts.js +7 -6
- package/src/components/check-box-text-editor.js +1 -0
- package/src/components/check-box-text.js +2 -0
- package/src/components/check-box-tree.js +1 -1
- package/src/components/choice-editor.js +5 -4
- package/src/components/choice-field-styles.js +9 -1
- package/src/components/code-mirror-engine.js +19 -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-commands.js +69 -0
- package/src/components/editor-options.js +1 -1
- package/src/components/editors.js +5 -3
- package/src/components/form-tray-pane.js +18 -0
- package/src/components/graphical-ranges.js +190 -0
- package/src/components/grid-check-sets.js +39 -3
- package/src/components/grid-footer.js +6 -1
- package/src/components/grid-header-interaction.js +3 -3
- package/src/components/grid-styles.js +30 -5
- package/src/components/grid-tools.js +15 -7
- package/src/components/grid.js +109 -15
- package/src/components/html-editor-commands.js +61 -0
- package/src/components/html-editor.js +18 -3
- package/src/components/inputs.js +94 -23
- package/src/components/jodit-engine.js +110 -7
- package/src/components/layout.js +3 -2
- package/src/components/menus.js +89 -26
- package/src/components/numeric-range.js +39 -0
- package/src/components/selected-container.js +123 -64
- package/src/components/tab-bar.js +389 -0
- package/src/components/toolbar-icon-style.js +22 -0
- package/src/components/toolbar-overflow.js +74 -12
- package/src/components/tray-base.js +528 -0
- package/src/components/tray-pane.js +41 -518
- package/src/components/tree.js +56 -4
- package/src/components/typed-editor.js +5 -2
- 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/editing-session.js +2 -1
- 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/ide-runtime.js +3 -1
- package/src/index-page-runtime.js +20 -5
- package/src/index-page-styles.js +1 -1
- package/src/index-theme.js +210 -3
- package/src/index.d.ts +7 -2
- package/src/index.js +7 -2
- package/src/libraries.js +4 -4
- package/src/object-extract.d.ts +7 -0
- package/src/object-extract.js +31 -0
- package/src/renderer/attributes.js +1 -1
- package/src/renderer/gramlot-renderer.d.ts +2 -2
- package/src/renderer/gramlot-renderer.js +4 -1
- package/src/server/chat-attachments.js +139 -0
- package/src/server/chat.d.ts +33 -0
- package/src/server/chat.js +168 -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 +149 -19
- package/src/server/index-page.d.ts +10 -0
- package/src/server/index-page.js +92 -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 +93 -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/labelbox.js +6 -1
- package/src/view/menu.js +9 -3
- package/src/visual-editor.d.ts +1 -0
- package/src/visual-editor.js +10 -5
- package/themes/gramlot-base/theme.css +60 -28
- package/themes/gramlot-compact/theme.css +2 -0
- package/themes/gramlot-index/icons/align-center.svg +4 -0
- package/themes/gramlot-index/icons/align-justify.svg +4 -0
- package/themes/gramlot-index/icons/align-left.svg +4 -0
- package/themes/gramlot-index/icons/align-right.svg +4 -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/bold.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/eraser.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/horizontal-rule.svg +4 -0
- package/themes/gramlot-index/icons/image.svg +4 -0
- package/themes/gramlot-index/icons/import.svg +4 -0
- package/themes/gramlot-index/icons/indent.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/italic.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-bulleted.svg +4 -0
- package/themes/gramlot-index/icons/list-numbered.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/outdent.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/paragraph.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/select-all.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/strikethrough.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/underline.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 +93 -0
- package/themes/gramlot-index/theme.css +24 -0
- package/themes/joanna/theme.css +2 -0
- package/themes/mela/theme.css +2 -0
- package/themes/mimi/theme.css +2 -0
- package/tools/gramlot-tools-inspector.js +11 -3
|
@@ -8,17 +8,37 @@ import 'jodit/esm/plugins/drag-and-drop/drag-and-drop.js';
|
|
|
8
8
|
import 'jodit/esm/plugins/fullsize/fullsize.js';
|
|
9
9
|
import 'jodit/esm/plugins/hr/hr.js';
|
|
10
10
|
import 'jodit/esm/plugins/indent/indent.js';
|
|
11
|
+
import 'jodit/esm/plugins/justify/justify.js';
|
|
11
12
|
import 'jodit/esm/plugins/search/search.js';
|
|
12
13
|
import 'jodit/esm/plugins/select/select.js';
|
|
13
14
|
import 'jodit/esm/plugins/select-cells/select-cells.js';
|
|
14
15
|
import 'jodit/esm/plugins/resize-cells/resize-cells.js';
|
|
15
16
|
import 'jodit/esm/plugins/table-keyboard-navigation/table-keyboard-navigation.js';
|
|
17
|
+
import {isEditorEmpty, placeholder} from 'jodit/esm/plugins/placeholder/placeholder.js';
|
|
16
18
|
import css from 'jodit/es2021/jodit.min.css';
|
|
17
19
|
import {randomId} from '../random-id.js';
|
|
18
20
|
import {prepareHtmlDocument} from './html-document.js';
|
|
19
21
|
|
|
20
|
-
const theme=`.jodit-container,.jodit-popup,.jodit-dialog{--jd-color-background-default:var(--gramlot-surface,white);--jd-color-panel:var(--gramlot-surface-subtle,#eee);--jd-color-text-icons:var(--gramlot-ink,#222);--jd-color-separator:var(--gramlot-border-control,#aaa);--jd-color-button-background-hover:var(--gramlot-selected,#ddd);--jd-color-background-active:var(--gramlot-selected,#ddd);--jd-color-background-gray:var(--gramlot-surface-subtle,#eee);--jd-color-background-light-gray:var(--gramlot-surface-subtle,#eee);--jd-color-background-button-hover:var(--gramlot-selected,#ddd);--jd-color-border:var(--gramlot-border-control,#aaa);--jd-color-text:var(--gramlot-ink,#222);--jd-color-icon:var(--gramlot-ink,#222);--jd-border-radius-default:var(--gramlot-radius-sm,4px)}
|
|
22
|
+
const theme=`.jodit-container,.jodit-popup,.jodit-dialog{--jd-color-background-default:var(--gramlot-surface,white);--jd-color-panel:var(--gramlot-surface-subtle,#eee);--jd-color-text-icons:var(--gramlot-ink,#222);--jd-color-separator:var(--gramlot-border-control,#aaa);--jd-color-button-background-hover:var(--gramlot-selected,#ddd);--jd-color-background-active:var(--gramlot-selected,#ddd);--jd-color-background-gray:var(--gramlot-surface-subtle,#eee);--jd-color-background-light-gray:var(--gramlot-surface-subtle,#eee);--jd-color-background-button-hover:var(--gramlot-selected,#ddd);--jd-color-border:var(--gramlot-border-control,#aaa);--jd-color-text:var(--gramlot-ink,#222);--jd-color-icon:var(--gramlot-ink,#222);--jd-border-radius-default:var(--gramlot-radius-sm,4px)}
|
|
23
|
+
.jodit-popup .jodit-ui-input{--jd-color-white:var(--gramlot-field-background,Field);color:var(--gramlot-ink,FieldText)}
|
|
24
|
+
.jodit-toolbar-button__button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight)}`;
|
|
21
25
|
const styles=new WeakSet();
|
|
26
|
+
// Prefix of the inert history marker that starts each projected document (prepare in createHtmlEditor).
|
|
27
|
+
const MARKER_PREFIX='gramlot-document-';
|
|
28
|
+
/** Jodit's placeholder plugin. Its emptiness test does not see the history marker.
|
|
29
|
+
* The marker comment is the first body node, so Jodit's own test never finds an empty document. */
|
|
30
|
+
class GramlotPlaceholder extends placeholder {
|
|
31
|
+
toggle() {
|
|
32
|
+
const editor=this.j;
|
|
33
|
+
if(!editor.editor||editor.isInDestruct)return;
|
|
34
|
+
if(editor.getRealMode()!==Jodit.constants.MODE_WYSIWYG){this.hide();return;}
|
|
35
|
+
const body=editor.editor, first=body.firstChild;
|
|
36
|
+
let content=body;
|
|
37
|
+
if(first?.nodeType===8&&first.data.startsWith(MARKER_PREFIX)){content=body.cloneNode(true);content.firstChild.remove();}
|
|
38
|
+
if(isEditorEmpty(content))this.show();else this.hide();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
Jodit.plugins.add('gramlotPlaceholder',GramlotPlaceholder);
|
|
22
42
|
export function createHtmlEditor(host) {
|
|
23
43
|
const document=host.ownerDocument, window=document.defaultView;
|
|
24
44
|
if (!styles.has(host.shadowRoot)) {
|
|
@@ -40,7 +60,7 @@ export function createHtmlEditor(host) {
|
|
|
40
60
|
if(node.nodeType===8)data.allowedTags['#comment']=documents.has(`<!--${node.data}-->`);
|
|
41
61
|
});
|
|
42
62
|
const prepare=value=>{
|
|
43
|
-
const content=prepareHtmlDocument(value,window), marker
|
|
63
|
+
const content=prepareHtmlDocument(value,window), marker=`<!--${MARKER_PREFIX}${randomId()}-->`;
|
|
44
64
|
const record={content,value,marker,initialHtml:null};
|
|
45
65
|
documents.set(marker,record);
|
|
46
66
|
return record;
|
|
@@ -57,9 +77,9 @@ export function createHtmlEditor(host) {
|
|
|
57
77
|
FORBID_TAGS:['style','form','input','button','select','textarea','iframe','object','embed','noscript'],
|
|
58
78
|
FORBID_ATTR:['autofocus','srcdoc']
|
|
59
79
|
})},
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
80
|
+
// The commands are Gramlot menulines of the htmlEditor namespace (html-editor-commands.js).
|
|
81
|
+
toolbar:false,showXPathInStatusbar:false,showCharsCounter:false,showWordsCounter:false,
|
|
82
|
+
sourceEditor:'area',beautifyHTML:false,disablePlugins:['mobile','placeholder'],
|
|
63
83
|
uploader:{insertImageAsBase64URI:true}
|
|
64
84
|
});
|
|
65
85
|
const frameDoc=editor.editor.ownerDocument;
|
|
@@ -104,12 +124,95 @@ export function createHtmlEditor(host) {
|
|
|
104
124
|
});
|
|
105
125
|
editor.events.on('blur',()=>host.editorBlurred());
|
|
106
126
|
editor.events.on('changeStack',history);
|
|
127
|
+
// Jodit's backspace cases take a comment with text as a neighbor and put the cursor in it (#169).
|
|
128
|
+
// The history marker is out of the body while the cases run, and it is the first body node again after them.
|
|
129
|
+
let detachedMarker=null;
|
|
130
|
+
editor.events.on('backSpaceBeforeCases',()=>{
|
|
131
|
+
const first=editor.editor.firstChild;
|
|
132
|
+
if(first?.nodeType===8&&documents.has(`<!--${first.data}-->`)){detachedMarker=first;first.remove();}
|
|
133
|
+
});
|
|
134
|
+
editor.events.on('backSpaceAfterDelete',()=>{
|
|
135
|
+
if(!detachedMarker)return;
|
|
136
|
+
editor.editor.prepend(detachedMarker);detachedMarker=null;
|
|
137
|
+
});
|
|
107
138
|
const resize=new window.ResizeObserver(entries=>{
|
|
108
139
|
if(!disposed && entries.some(entry=>entry.contentRect.width>0 && entry.contentRect.height>0)) editor.events.fire('resize');
|
|
109
140
|
});
|
|
110
141
|
resize.observe(host.control);
|
|
111
142
|
history();
|
|
143
|
+
// Command state follows the selection and the history, as Jodit's own toolbar does (ToolbarCollection).
|
|
144
|
+
let stateTimer=null;
|
|
145
|
+
const stateChanged=()=>{
|
|
146
|
+
if(disposed||stateTimer!==null)return;
|
|
147
|
+
stateTimer=window.setTimeout(()=>{stateTimer=null;if(!disposed)host.editorStateChanged();},50);
|
|
148
|
+
};
|
|
149
|
+
editor.events.on('updateToolbar changeStack mouseup keyup change readonly afterSetMode focus',stateChanged);
|
|
150
|
+
frameDoc.addEventListener('selectionchange',stateChanged,options);
|
|
151
|
+
const {Dom,Helpers,Popup}=Jodit.modules, controls=Jodit.defaultOptions.controls;
|
|
152
|
+
// Jodit's active rule of a control (ToolbarEditorCollection.shouldBeActive): its tags or its css,
|
|
153
|
+
// from the current node up to the editing area.
|
|
154
|
+
const matchesCss=(rules,node)=>Object.entries(rules).every(([property,value])=>{
|
|
155
|
+
const actual=Helpers.css(node,property).toString();
|
|
156
|
+
return typeof value==='function' ? value(editor,actual) : value.indexOf(actual)!==-1;
|
|
157
|
+
});
|
|
158
|
+
const active=name=>{
|
|
159
|
+
const control=controls[name], current=editor.s.current();
|
|
160
|
+
if(!current)return false;
|
|
161
|
+
if(control.isActive)return Boolean(control.isActive(editor,{control,state:{}}));
|
|
162
|
+
if(control.tags&&Dom.up(current,node=>node&&control.tags.includes(node.nodeName.toLowerCase()),editor.editor))return true;
|
|
163
|
+
return Boolean(control.css&&Dom.up(current,node=>node&&!Dom.isText(node)&&!Dom.isComment(node)&&matchesCss(control.css,node),editor.editor));
|
|
164
|
+
};
|
|
165
|
+
const block=()=>{
|
|
166
|
+
const current=editor.s.current();
|
|
167
|
+
return current ? Dom.closest(current,Dom.isBlock,editor.editor) : null;
|
|
168
|
+
};
|
|
169
|
+
const alignment=()=>{
|
|
170
|
+
const value=Helpers.css(block()||editor.editor,'text-align').toString();
|
|
171
|
+
return controls.align.defaultValue.includes(value) ? 'left' : value;
|
|
172
|
+
};
|
|
173
|
+
const ALIGN_COMMANDS={left:'justifyLeft',center:'justifyCenter',right:'justifyRight',justify:'justifyFull'};
|
|
174
|
+
const TOGGLES=new Set(['bold','italic','underline','strikethrough','ul','ol','link']);
|
|
175
|
+
const POPUPS=new Set(['color','image','link','table']);
|
|
176
|
+
// Jodit control names of the htmlEditor commands, where they differ.
|
|
177
|
+
const CONTROLS={color:'brush'};
|
|
178
|
+
// The last popup stays referenced until the next one or destroy: Jodit can close it itself on an outside click.
|
|
179
|
+
let openPopup=null;
|
|
180
|
+
const closePopup=()=>{if(openPopup){const popup=openPopup;openPopup=null;popup.close();popup.destruct();}};
|
|
181
|
+
const showPopup=(name,sender)=>{
|
|
182
|
+
closePopup();
|
|
183
|
+
const control={name:CONTROLS[name]??name,...controls[CONTROLS[name]??name]};
|
|
184
|
+
const anchor=host.commandAnchor(sender);
|
|
185
|
+
const popup=new Popup(editor);openPopup=popup;
|
|
186
|
+
// The control receives the button argument of a Jodit toolbar button: its control, its state and a parent
|
|
187
|
+
// (the table form draws its size grid only for a button inside a toolbar).
|
|
188
|
+
const content=control.popup(editor,editor.s.current(),closePopup,{control,state:{icon:{}},parentElement:popup});
|
|
189
|
+
if(!content){closePopup();return;}
|
|
190
|
+
popup.setContent(typeof content==='string' ? editor.c.fromHTML(content) : content)
|
|
191
|
+
.open(()=>Helpers.position(anchor,editor));
|
|
192
|
+
};
|
|
193
|
+
const execute=(name,message)=>{
|
|
194
|
+
if(name==='undo')return editor.history.canUndo()&&!locked()&&editor.history.undo();
|
|
195
|
+
if(name==='redo')return editor.history.canRedo()&&!locked()&&editor.history.redo();
|
|
196
|
+
if(POPUPS.has(name))return showPopup(name,message.sender);
|
|
197
|
+
if(name==='paragraph')return editor.execCommand('formatBlock',false,message.parameters.tag);
|
|
198
|
+
if(name==='align')return editor.execCommand(ALIGN_COMMANDS[message.parameters.value]);
|
|
199
|
+
const commands={eraser:'removeFormat',ul:'insertUnorderedList',ol:'insertOrderedList',hr:'insertHorizontalRule',
|
|
200
|
+
find:'openSearchDialog'};
|
|
201
|
+
editor.execCommand(commands[name]??name);
|
|
202
|
+
};
|
|
203
|
+
const commandState=(name,parameters)=>{
|
|
204
|
+
if(host.parameters.disabled)return TOGGLES.has(name) ? {disabled:true,checked:false} : {disabled:true};
|
|
205
|
+
if(name==='undo'||name==='redo')
|
|
206
|
+
return {disabled:locked()||!(name==='undo' ? editor.history.canUndo() : editor.history.canRedo())};
|
|
207
|
+
// Jodit keeps Select all active in read-only mode (activeButtonsInReadOnly).
|
|
208
|
+
const disabled=host.parameters.readonly&&name!=='selectall';
|
|
209
|
+
if(TOGGLES.has(name))return {disabled,checked:active(name)};
|
|
210
|
+
if(name==='paragraph')return {disabled,checked:block()?.nodeName.toLowerCase()===parameters.tag};
|
|
211
|
+
if(name==='align')return {disabled,checked:alignment()===parameters.value};
|
|
212
|
+
return {disabled};
|
|
213
|
+
};
|
|
112
214
|
return {
|
|
215
|
+
execute,commandState,
|
|
113
216
|
replace(value){
|
|
114
217
|
const record=prepare(value), active=document.activeElement;
|
|
115
218
|
restoring=true;
|
|
@@ -141,10 +244,10 @@ export function createHtmlEditor(host) {
|
|
|
141
244
|
}
|
|
142
245
|
history();
|
|
143
246
|
},
|
|
144
|
-
configure(){editor.setReadOnly(locked());history();},
|
|
247
|
+
configure(){editor.setReadOnly(locked());history();stateChanged();},
|
|
145
248
|
undo(){if(locked()||!editor.history.canUndo())return false;editor.history.undo();return true;},
|
|
146
249
|
redo(){if(locked()||!editor.history.canRedo())return false;editor.history.redo();return true;},
|
|
147
250
|
focus(){editor.selection.focus();},
|
|
148
|
-
destroy(){disposed=true;resize.disconnect();events.abort();editor.destruct();sanitizer.removeAllHooks();documents.clear();}
|
|
251
|
+
destroy(){disposed=true;window.clearTimeout(stateTimer);closePopup();resize.disconnect();events.abort();editor.destruct();sanitizer.removeAllHooks();documents.clear();}
|
|
149
252
|
};
|
|
150
253
|
}
|
package/src/components/layout.js
CHANGED
|
@@ -12,7 +12,8 @@ import {FormletLabels} from './formlet-labels.js';
|
|
|
12
12
|
import {Dialog, FloatingPane} from './windows.js';
|
|
13
13
|
export {Dialog, FloatingPane};
|
|
14
14
|
import {TrayPane} from './tray-pane.js';
|
|
15
|
-
|
|
15
|
+
import {FormTrayPane} from './form-tray-pane.js';
|
|
16
|
+
export {TrayPane, FormTrayPane};
|
|
16
17
|
|
|
17
18
|
import {TransformPane} from './transform-pane.js';
|
|
18
19
|
export {TransformPane};
|
|
@@ -184,4 +185,4 @@ export const GroupBox = defineComponent({
|
|
|
184
185
|
}
|
|
185
186
|
}
|
|
186
187
|
});
|
|
187
|
-
export default defineCollection({name: 'layout', components: [TransformPane, Dialog, FloatingPane, FramePane, TrayPane, Formlet, GroupBox, ContentPane, BorderContainer, StackContainer, TabContainer]});
|
|
188
|
+
export default defineCollection({name: 'layout', components: [TransformPane, Dialog, FloatingPane, FramePane, TrayPane, FormTrayPane, Formlet, GroupBox, ContentPane, BorderContainer, StackContainer, TabContainer]});
|
package/src/components/menus.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
/** Shared popup/permanent menu presentation. Source and execution stay in bindings. */
|
|
2
2
|
import {labelboxContent, labelboxPresentation} from '../view/labelbox.js';
|
|
3
|
+
import {projectToolbarIconStyle} from './toolbar-icon-style.js';
|
|
3
4
|
import {projectParameters} from './parameters.js';
|
|
4
5
|
import {positionPopup} from './popup.js';
|
|
5
6
|
import {ToolbarOverflow} from './toolbar-overflow.js';
|
|
6
7
|
|
|
8
|
+
// Keyboard navigation and presentation follow the visible bar. Command binding
|
|
9
|
+
// and Source ownership continue to follow the original menu hierarchy.
|
|
10
|
+
function containingMenu(element) {
|
|
11
|
+
const menu = element.parentElement?.closest('gramlot-menu');
|
|
12
|
+
return menu?.hasAttribute('data-menu-inline') ? menu.parentMenu : menu ?? null;
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
export function MenuContainer(HTMLElement) {
|
|
8
16
|
return class extends HTMLElement {
|
|
9
17
|
#events; #observer; #active = null; #previous = []; #opener = null;
|
|
@@ -20,6 +28,10 @@ export function MenuContainer(HTMLElement) {
|
|
|
20
28
|
:host([role=toolbar]){display:flex;gap:var(--gramlot-toolbar-gap,4px);align-items:center}
|
|
21
29
|
:host([role=menu]) ::slotted([role=separator]){margin:5px 7px 5px 2.5rem;border-top:1px solid var(--gramlot-border-control,#888)}
|
|
22
30
|
:host([role=toolbar][aria-orientation=horizontal]) ::slotted([role=separator]){border-top:0;border-left:1px solid var(--gramlot-border-control,#888);align-self:stretch;margin:4px}
|
|
31
|
+
:host([role=toolbar][aria-orientation=vertical]) ::slotted([role=separator]){border-left:0;border-top:1px solid var(--gramlot-border-control,#888);align-self:stretch;margin:4px}
|
|
32
|
+
:host([data-menu-inline]){display:inline-flex;position:static;inset:auto;align-items:center;gap:var(--gramlot-toolbar-gap,4px);margin:0;padding:0;border:0;box-shadow:none;background:transparent;width:max-content;max-width:none;max-height:none;overflow:visible}
|
|
33
|
+
:host([data-menu-inline=vertical]){flex-direction:column}
|
|
34
|
+
:host([data-menu-inline]) ::slotted(*){flex-shrink:0}
|
|
23
35
|
:host([hidden]){display:none!important} slot{display:contents} .status{padding:.4em;opacity:.75}
|
|
24
36
|
.status:empty{display:none} button{font:inherit}`;
|
|
25
37
|
this.#slot = doc.createElement('slot');
|
|
@@ -36,12 +48,12 @@ export function MenuContainer(HTMLElement) {
|
|
|
36
48
|
}
|
|
37
49
|
get permanent() { return this.parameters.presentation === 'bar'; }
|
|
38
50
|
get opened() { return this.permanent || this.#opened; }
|
|
39
|
-
get items() { return [...this.querySelectorAll('gramlot-menu-line')].filter(item => item.menuOwner===this && !item.parameters.group); }
|
|
51
|
+
get items() { return [...this.querySelectorAll('gramlot-menu-line')].filter(item => item.menuOwner===this && !item.parameters.group && !item.hasAttribute('data-menu-expanded')); }
|
|
40
52
|
get overflow() { return this.#overflow; }
|
|
41
53
|
isOverflowed(item) { return this.#overflow.contains(item); }
|
|
42
54
|
get visibleItems() { return this.items.filter(item => labelboxPresentation(item).slot!=='suppressed' && !item.hidden && !item.closest('[hidden]') && item.getAttribute('role') !== 'separator'); }
|
|
43
55
|
get usableItems() { return this.visibleItems.filter(item => !item.disabled); }
|
|
44
|
-
get parentMenu() { return this
|
|
56
|
+
get parentMenu() { return containingMenu(this); }
|
|
45
57
|
connectedCallback() {
|
|
46
58
|
this.#observer = new this.ownerDocument.defaultView.MutationObserver(() => {this.refreshItems();this.#overflow.schedule();});
|
|
47
59
|
this.#observer.observe(this, {childList:true, subtree:true, characterData:true, attributes:true, attributeFilter:['hidden','disabled']});
|
|
@@ -54,7 +66,7 @@ export function MenuContainer(HTMLElement) {
|
|
|
54
66
|
projectAttributes(attrs) {
|
|
55
67
|
const rest = projectParameters(this, attrs);
|
|
56
68
|
this.#modifierKeys();
|
|
57
|
-
if(!Number.isFinite(this.parameters.
|
|
69
|
+
if(!Number.isFinite(this.parameters.icon_size)||this.parameters.icon_size<=0)throw new TypeError('menu icon_size must be positive');
|
|
58
70
|
this.setAttribute('role', this.permanent ? 'toolbar' : 'menu');
|
|
59
71
|
this.setAttribute('aria-orientation', this.permanent ? this.parameters.orientation : 'vertical');
|
|
60
72
|
this.tabIndex = -1;
|
|
@@ -62,7 +74,7 @@ export function MenuContainer(HTMLElement) {
|
|
|
62
74
|
else this.setAttribute('popover','manual');
|
|
63
75
|
this.refreshItems();
|
|
64
76
|
this.#overflow.schedule();
|
|
65
|
-
return rest;
|
|
77
|
+
return projectToolbarIconStyle(this, rest);
|
|
66
78
|
}
|
|
67
79
|
#modifierKeys() {
|
|
68
80
|
const value=this.parameters.modifiers;
|
|
@@ -112,6 +124,7 @@ export function MenuContainer(HTMLElement) {
|
|
|
112
124
|
this.refreshItems();
|
|
113
125
|
}
|
|
114
126
|
refreshItems() {
|
|
127
|
+
if (this.hasAttribute('data-menu-inline')) return;
|
|
115
128
|
for(const group of this.querySelectorAll('gramlot-menu-line'))if(group.menuOwner===this && group.parameters.group)group.refreshAvailability();
|
|
116
129
|
for(const item of this.items)item.refreshAvailability();
|
|
117
130
|
const usable = this.usableItems;
|
|
@@ -126,7 +139,7 @@ export function MenuContainer(HTMLElement) {
|
|
|
126
139
|
const next = this.#previous.slice(index+1).find(item => usable.includes(item))
|
|
127
140
|
?? this.#previous.slice(0,index).reverse().find(item => usable.includes(item));
|
|
128
141
|
this.#active = next ?? null;
|
|
129
|
-
if (this.opened && this.status !== 'loading') {
|
|
142
|
+
if (this.opened && this.contains(this.ownerDocument.activeElement) && this.status !== 'loading') {
|
|
130
143
|
if (next) next.focus();
|
|
131
144
|
else if (this.permanent) this.focus(); else this.close();
|
|
132
145
|
}
|
|
@@ -145,8 +158,13 @@ export function MenuContainer(HTMLElement) {
|
|
|
145
158
|
const options = {signal:this.#events.signal};
|
|
146
159
|
const place = () => positionPopup(this, opener, {point,placement:this.parentMenu && (!this.parentMenu.permanent || this.parentMenu.parameters.orientation==='vertical' || this.parentMenu.isOverflowed(this.parentElement)) ? 'side' : 'bottom'});
|
|
147
160
|
place();
|
|
148
|
-
this.ownerDocument.defaultView.addEventListener('resize',place,options);
|
|
149
161
|
this.ownerDocument.addEventListener('scroll',place,{...options,capture:true});
|
|
162
|
+
// The open chain closes when the window resizes, loses focus or becomes hidden.
|
|
163
|
+
this.ownerDocument.defaultView.addEventListener('resize',() => this.closeChain(false),options);
|
|
164
|
+
this.ownerDocument.defaultView.addEventListener('blur',() => this.closeChain(false),options);
|
|
165
|
+
this.ownerDocument.addEventListener('visibilitychange',() => {
|
|
166
|
+
if (this.ownerDocument.visibilityState==='hidden') this.closeChain(false);
|
|
167
|
+
},options);
|
|
150
168
|
this.ownerDocument.addEventListener('pointerdown',event => {
|
|
151
169
|
if (!event.composedPath().includes(this) && (opener===this.#attachment || !event.composedPath().includes(opener))) this.closeChain(false);
|
|
152
170
|
},options);
|
|
@@ -159,7 +177,8 @@ export function MenuContainer(HTMLElement) {
|
|
|
159
177
|
focusEntry(last = false) {
|
|
160
178
|
const usable = this.usableItems;
|
|
161
179
|
const target = usable[last ? usable.length-1 : 0];
|
|
162
|
-
if (target) { this.#active=target; target.focus(); }
|
|
180
|
+
if (target) { this.#active=target; target.focus(); }
|
|
181
|
+
else (this.querySelector('[autofocus]') ?? this).focus();
|
|
163
182
|
}
|
|
164
183
|
close(restore = true) {
|
|
165
184
|
for (const child of this.querySelectorAll('gramlot-menu')) if (!child.permanent) child.close(false);
|
|
@@ -177,10 +196,10 @@ export function MenuContainer(HTMLElement) {
|
|
|
177
196
|
else if (restore && this.#opener?.isConnected) this.#opener.focus();
|
|
178
197
|
}
|
|
179
198
|
#key(event) {
|
|
180
|
-
if (event.defaultPrevented || event.composedPath().find(node => node.localName === 'gramlot-menu') !== this) return;
|
|
199
|
+
if (event.defaultPrevented || event.composedPath().find(node => node.localName === 'gramlot-menu' && !node.hasAttribute('data-menu-inline')) !== this) return;
|
|
181
200
|
const item = event.composedPath().find(node => this.items.includes(node));
|
|
182
201
|
// Embedded editors retain their editing and Tab behavior.
|
|
183
|
-
if (!item && event.target !== this) return;
|
|
202
|
+
if (!item && event.target !== this && (event.key !== 'Escape' || this.permanent)) return;
|
|
184
203
|
const inOverflow=item && this.isOverflowed(item);
|
|
185
204
|
const items=this.usableItems.filter(entry=>this.isOverflowed(entry)===Boolean(inOverflow)), index=items.indexOf(item);
|
|
186
205
|
const nextKey=this.permanent && !inOverflow && this.parameters.orientation==='horizontal' ? 'ArrowRight':'ArrowDown';
|
|
@@ -230,21 +249,33 @@ export function menuLine(Base) {
|
|
|
230
249
|
background:transparent;cursor:pointer;line-height:1.2;white-space:nowrap}
|
|
231
250
|
:host button.toolbar-button .icon{display:inline-flex;align-items:center;justify-content:center;
|
|
232
251
|
width:var(--gramlot-toolbar-icon-size);height:var(--gramlot-toolbar-icon-size);font-size:var(--gramlot-toolbar-icon-size);line-height:1}
|
|
233
|
-
#control.toolbar-button.icon-only{--gramlot-button-icon-size:var(--gramlot-toolbar-icon-size)}
|
|
252
|
+
#control.toolbar-button.icon-only{--gramlot-button-icon-size:var(--gramlot-toolbar-icon-size);border:0;background:transparent}
|
|
253
|
+
:host(:not([data-menu-group-rows])) #control.toolbar-button.icon-only{
|
|
254
|
+
min-height:max(calc(var(--gramlot-toolbar-icon-size) + 8px),var(--gramlot-touch-target,0px));padding-block:3px}
|
|
255
|
+
#control.toolbar-button.icon-only:hover:not(:disabled){background:color-mix(in srgb,currentColor 17%,transparent)}
|
|
256
|
+
#control.toolbar-button.icon-only:is([aria-checked=true],[aria-expanded=true]){background:var(--gramlot-selected,Highlight)}
|
|
257
|
+
@media(forced-colors:active){#control.toolbar-button.icon-only{background:ButtonFace;border:1px solid ButtonText}#control.toolbar-button.icon-only[aria-checked=true]{background:Highlight;color:HighlightText}}
|
|
258
|
+
:host button.toolbar-button:not([aria-checked=true]):not([aria-expanded=true]) .icon img{color-scheme:var(--gramlot-toolbar-icon-scheme,inherit)}
|
|
259
|
+
.icon{position:relative;color:var(--gramlot-toolbar-icon-color,inherit)}
|
|
260
|
+
.menu-caption{opacity:var(--gramlot-icon-opacity,1)}
|
|
261
|
+
.icon[data-badge]::after{content:attr(data-badge);position:absolute;inset-block-start:-.3em;inset-inline-end:-.6em;
|
|
262
|
+
min-width:1.3em;padding:0 .22em;box-sizing:border-box;border-radius:1em;text-align:center;font:600 10px/1.3 system-ui;
|
|
263
|
+
background:var(--gramlot-icon-badge-background,var(--gramlot-tab-badge-background,var(--gramlot-brand-blue,#3766b5)));color:var(--gramlot-tab-badge-color,white);pointer-events:none}
|
|
234
264
|
:host button.toolbar-button .icon:empty{display:none}
|
|
235
265
|
:host button.toolbar-button:hover:not(:disabled){background:color-mix(in srgb,currentColor 10%,transparent)}
|
|
236
|
-
:host button.toolbar-button:focus-visible{outline:
|
|
266
|
+
:host button.toolbar-button:focus-visible{outline:1px solid var(--gramlot-focus-ring,Highlight);outline-offset:-1px}
|
|
237
267
|
:host button.toolbar-button[aria-checked=true],:host button.toolbar-button[aria-expanded=true]{background:var(--gramlot-selected,color-mix(in srgb,currentColor 14%,transparent))}
|
|
238
268
|
:host button.toolbar-button:disabled{opacity:.45;cursor:default}
|
|
239
269
|
:host button.toolbar-below{flex-direction:column;gap:3px;min-width:54px}
|
|
240
270
|
:host button.toolbar-below .menu-caption{font-size:11px;line-height:1.2}
|
|
241
271
|
:host button.toolbar-tooltip .menu-caption{display:none}
|
|
242
272
|
:host button.toolbar-button .menu-check{display:none}
|
|
243
|
-
:host button.toolbar-
|
|
244
|
-
|
|
273
|
+
:host button.toolbar-button .icon > .menu-arrow{position:absolute;right:0;bottom:1px;
|
|
274
|
+
width:0;height:0;border-inline:4px solid transparent;border-top:5px solid currentColor;
|
|
275
|
+
filter:drop-shadow(0 0 1px var(--gramlot-field-background,Canvas));font-size:0;pointer-events:none}`;
|
|
245
276
|
style.textContent+=`
|
|
246
277
|
:host([role=group]){display:block;min-width:0}
|
|
247
|
-
:host([role=group]) .control-box{display:none}
|
|
278
|
+
:host([role=group]) .control-box,:host([role=separator]) .control-box,:host([data-menu-expanded]) .control-box{display:none}
|
|
248
279
|
.menu-group{display:flex;align-items:center;gap:var(--gramlot-toolbar-gap,4px);flex-wrap:nowrap}
|
|
249
280
|
.menu-group ::slotted(*){flex-shrink:0}
|
|
250
281
|
.menu-group[hidden]{display:none}
|
|
@@ -270,11 +301,10 @@ export function menuLine(Base) {
|
|
|
270
301
|
});
|
|
271
302
|
this.addEventListener('pointerleave',()=>clearTimeout(this.#hover));
|
|
272
303
|
}
|
|
273
|
-
get menuOwner() { return this
|
|
304
|
+
get menuOwner() { return containingMenu(this); }
|
|
274
305
|
get submenu() { return [...this.children].map(labelboxContent).find(child=>child?.localName==='gramlot-menu') ?? null; }
|
|
275
306
|
get entryCaption() { return this.parameters.caption ?? this.#registry?.label ?? ''; }
|
|
276
|
-
get entryIcon() { return this.parameters.icon || this
|
|
277
|
-
get entryIconSrc() { return this.parameters.icon || this.parameters.iconSrc ? this.parameters.iconSrc : this.#registry?.iconSrc; }
|
|
307
|
+
get entryIcon() { return this.parameters.icon || this.#registry?.icon; }
|
|
278
308
|
get occurrence() { return this.parameters.code ?? this.sourceLabel; }
|
|
279
309
|
setCommandDefinition(definition, sourceLabel) {
|
|
280
310
|
this.#registry=definition; this.sourceLabel=sourceLabel; this.#render();
|
|
@@ -282,14 +312,18 @@ export function menuLine(Base) {
|
|
|
282
312
|
projectAttributes(attrs,adapt) {
|
|
283
313
|
const rest=super.projectAttributes(attrs,adapt);
|
|
284
314
|
this.#accessibleLabel=attrs['aria-label'];
|
|
285
|
-
if(this.parameters.
|
|
315
|
+
if(this.parameters.icon_size!=null&&(!Number.isFinite(this.parameters.icon_size)||this.parameters.icon_size<=0))throw new TypeError('menuline icon_size must be positive');
|
|
316
|
+
if (this.parameters.expandInBar != null && !Number.isFinite(this.parameters.expandInBar)) throw new TypeError('menuline expandInBar must be finite');
|
|
286
317
|
this.#authoredDisabled=Boolean(this.parameters.disabled);
|
|
287
|
-
this.#render(); this.menuOwner?.refreshItems(); this.menuOwner
|
|
318
|
+
this.#render(); this.menuOwner?.refreshItems(); const owner = this.menuOwner;
|
|
319
|
+
owner?.overflow.schedule();
|
|
320
|
+
if (owner && !owner.permanent) owner.parentMenu?.overflow.schedule();
|
|
321
|
+
return projectToolbarIconStyle(this, rest);
|
|
288
322
|
}
|
|
289
323
|
#render() {
|
|
290
324
|
const separator=[...this.childNodes].filter(node=>node.nodeType===3)
|
|
291
325
|
.map(node=>node.textContent).join('').trim()==='-' && !this.parameters.command;
|
|
292
|
-
this.setAttribute('role',this.parameters.group?'group':separator?'separator':this.parameters.checked==null?'menuitem':'menuitemcheckbox');
|
|
326
|
+
this.setAttribute('role',this.hasAttribute('data-menu-expanded')?'presentation':this.parameters.group?'group':separator?'separator':this.parameters.checked==null?'menuitem':'menuitemcheckbox');
|
|
293
327
|
this.#group.hidden=!this.parameters.group;
|
|
294
328
|
this.setAttribute('aria-disabled',String(this.#authoredDisabled));
|
|
295
329
|
if (this.parameters.checked!=null) {
|
|
@@ -299,10 +333,14 @@ export function menuLine(Base) {
|
|
|
299
333
|
this.#check.textContent=this.parameters.checked ? '✓':'';
|
|
300
334
|
this.#caption.textContent=this.parameters.command && !this.#registry ? '???':this.entryCaption;
|
|
301
335
|
this.caption.hidden=true;
|
|
302
|
-
this.renderIcon(this.entryIcon
|
|
336
|
+
this.renderIcon(this.entryIcon);
|
|
337
|
+
const badge = this.parameters.badge;
|
|
338
|
+
if (badge == null || badge === '') this.icon.removeAttribute('data-badge');
|
|
339
|
+
else this.icon.dataset.badge = String(badge);
|
|
340
|
+
this.icon.style.setProperty('--gramlot-icon-badge-background', this.parameters.badge_color ?? '');
|
|
303
341
|
const tooltip=this.parameters.tooltip ?? this.#registry?.tooltip ?? this.entryCaption;
|
|
304
|
-
this.
|
|
305
|
-
this.control.setAttribute('aria-label',
|
|
342
|
+
const label = this.#accessibleLabel ?? (this.entryCaption || tooltip);
|
|
343
|
+
this.control.setAttribute('aria-label', this.icon.hasAttribute('data-badge') ? label + ' ' + badge : label);
|
|
306
344
|
if (this.submenu) this.control.setAttribute('aria-haspopup','menu');
|
|
307
345
|
else this.control.removeAttribute('aria-haspopup');
|
|
308
346
|
this.refreshAvailability();
|
|
@@ -316,18 +354,26 @@ export function menuLine(Base) {
|
|
|
316
354
|
}
|
|
317
355
|
return owner?.parameters[name];
|
|
318
356
|
};
|
|
357
|
+
const tooltipOwner = this.closest('gramlot-menu')?.closest('gramlot-menu[role=toolbar]');
|
|
358
|
+
const showTooltip = owner?.parameters.showTooltip ?? tooltipOwner?.parameters.showTooltip ?? true;
|
|
359
|
+
this.control.title = showTooltip ? (this.parameters.tooltip ?? this.#registry?.tooltip ?? this.entryCaption) : '';
|
|
319
360
|
const toolbar=Boolean(owner?.permanent && !popup);
|
|
320
361
|
const labelPosition=inherited('labelPosition');
|
|
321
|
-
this.
|
|
362
|
+
const standardButton = toolbar && this.classList.contains('button--standard');
|
|
363
|
+
this.control.classList.toggle('standard-button', standardButton);
|
|
364
|
+
this.control.classList.toggle('toolbar-button',toolbar && !standardButton);
|
|
322
365
|
this.control.classList.toggle('toolbar-below',toolbar && labelPosition==='below');
|
|
323
366
|
this.control.classList.toggle('toolbar-tooltip',toolbar && labelPosition==='tooltip');
|
|
324
|
-
if(toolbar)this.control.style.setProperty('--gramlot-toolbar-icon-size',`${inherited('
|
|
367
|
+
if(toolbar)this.control.style.setProperty('--gramlot-toolbar-icon-size',`${inherited('icon_size')}px`);
|
|
325
368
|
else this.control.style.removeProperty('--gramlot-toolbar-icon-size');
|
|
326
369
|
this.toggleAttribute('data-menu-group-rows',Boolean(popup || owner?.parameters.orientation==='vertical'));
|
|
327
370
|
this.control.classList.toggle('menu-row', popup);
|
|
328
|
-
this.#arrow.textContent = this.submenu ? (
|
|
371
|
+
this.#arrow.textContent = this.submenu ? (popup ? '›' : '▾') : '';
|
|
372
|
+
const arrowParent = toolbar && this.submenu && (this.entryIcon || this.entryIconSrc) ? this.icon : this.control;
|
|
373
|
+
if (this.#arrow.parentNode !== arrowParent) arrowParent.append(this.#arrow);
|
|
329
374
|
const disabled=this.#authoredDisabled || this.getAttribute('role')==='separator'
|
|
330
375
|
|| Boolean(this.parameters.command && !this.#registry)
|
|
376
|
+
|| Boolean(this.parentElement?.closest('gramlot-menu-line[data-menu-expanded]')?.disabled)
|
|
331
377
|
|| ['loading','error'].includes(owner?.status)
|
|
332
378
|
|| Boolean(this.closest('gramlot-drop-down-button')?.parameters.disabled);
|
|
333
379
|
if(this.control.disabled!==disabled)this.control.disabled=disabled;
|
|
@@ -336,6 +382,23 @@ export function menuLine(Base) {
|
|
|
336
382
|
get disabled() {
|
|
337
383
|
for(let p=this.parentElement;p && p!==this.menuOwner;p=p.parentElement)if(p.localName==='gramlot-menu-line' && p.parameters.disabled)return true;
|
|
338
384
|
return this.control.disabled || Boolean(this.closest('gramlot-drop-down-button')?.parameters.disabled); }
|
|
385
|
+
showInBar(expanded, orientation) {
|
|
386
|
+
const submenu = this.submenu;
|
|
387
|
+
this.toggleAttribute('data-menu-expanded', expanded);
|
|
388
|
+
if (expanded) {
|
|
389
|
+
submenu.setAttribute('data-menu-inline', orientation);
|
|
390
|
+
this.setAttribute('role', 'presentation');
|
|
391
|
+
submenu.setAttribute('role', 'group');
|
|
392
|
+
} else {
|
|
393
|
+
submenu?.removeAttribute('data-menu-inline');
|
|
394
|
+
submenu?.setAttribute('role', 'menu');
|
|
395
|
+
this.setAttribute('role', this.parameters.checked == null ? 'menuitem' : 'menuitemcheckbox');
|
|
396
|
+
}
|
|
397
|
+
const owner = expanded ? this.menuOwner : submenu;
|
|
398
|
+
for (const child of submenu?.querySelectorAll('gramlot-menu-line') ?? []) {
|
|
399
|
+
if (child.menuOwner === owner) child.refreshAvailability();
|
|
400
|
+
}
|
|
401
|
+
}
|
|
339
402
|
set disabled(value) { this.control.disabled=Boolean(value); }
|
|
340
403
|
attachCommand() { this.#render(); }
|
|
341
404
|
releaseCommand() { clearTimeout(this.#hover); this.submenu?.close(false); }
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const numericRangeParameters = {
|
|
2
|
+
value: {dtype: 'R', default: 0, binding: 'twoWay'},
|
|
3
|
+
min: {dtype: 'R', default: 0, binding: 'read', target: 'control'},
|
|
4
|
+
max: {dtype: 'R', default: 100, binding: 'read', target: 'control'},
|
|
5
|
+
step: {dtype: 'R', default: 1, binding: 'read', target: 'control'}
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// The native range owns step rounding, clamping and keyboard interaction.
|
|
9
|
+
export function numericRange(Base) {
|
|
10
|
+
return class extends Base {
|
|
11
|
+
#sourceContext;
|
|
12
|
+
#correcting = false;
|
|
13
|
+
|
|
14
|
+
setSourceContext(context) { this.#sourceContext = context; }
|
|
15
|
+
createControl() {
|
|
16
|
+
const control = this.ownerDocument.createElement('input');
|
|
17
|
+
control.type = 'range';
|
|
18
|
+
return control;
|
|
19
|
+
}
|
|
20
|
+
readControlValue() { return this.control.valueAsNumber; }
|
|
21
|
+
writeControlValue(value) {
|
|
22
|
+
this.control.value = String(value);
|
|
23
|
+
const corrected = this.control.valueAsNumber;
|
|
24
|
+
if (!this.#correcting && Number.isFinite(value) && corrected !== value) {
|
|
25
|
+
this.#correcting = true;
|
|
26
|
+
try { this.#sourceContext.writeParameter('value', corrected); }
|
|
27
|
+
finally { this.#correcting = false; }
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
projectAttributes(attrs, adapt) {
|
|
31
|
+
const previous = this.parameters;
|
|
32
|
+
const rest = super.projectAttributes(attrs, adapt);
|
|
33
|
+
if (previous && ['min', 'max', 'step'].some(name => previous[name] !== this.parameters[name])) {
|
|
34
|
+
this.writeControlValue(this.parameters.value);
|
|
35
|
+
}
|
|
36
|
+
return rest;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|