@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
|
@@ -13,6 +13,8 @@ import {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
|
13
13
|
import {NAME_SYNTAX} from '../builder/name-syntax.js';
|
|
14
14
|
import {gramlotDev} from './assets.js';
|
|
15
15
|
import {ENDPOINT_METHOD, Page, SOURCE_METHOD, UPLOAD_METHOD, resolveDeclared} from './page.js';
|
|
16
|
+
import {PageStore} from './page-store.js';
|
|
17
|
+
import {ChatPageStore} from './chat.js';
|
|
16
18
|
import {UploadRegistry, UploadTarget} from './upload.js';
|
|
17
19
|
import {InvalidResourceName, SEGMENT, loadOrder} from './resources.js';
|
|
18
20
|
import {libraries} from '../libraries.js';
|
|
@@ -116,9 +118,9 @@ const prefixed = (prefix, url) => url.startsWith('/') && !url.startsWith('//') ?
|
|
|
116
118
|
export class GramlotServer {
|
|
117
119
|
get markdownUrl() { return this.runtimeUrl.replace(/[^/]+$/, 'gramlot-markdown.js'); }
|
|
118
120
|
|
|
119
|
-
constructor({runtimeUrl = '/assets/gramlot.js', rpcUrl = '/gramlot/rpc', closeUrl = '/gramlot/close',
|
|
121
|
+
constructor({runtimeUrl = '/assets/gramlot.js', rpcUrl = '/gramlot/rpc', closeUrl = '/gramlot/close', uploadUrl = null,
|
|
120
122
|
rootId = 'gramlot-root', pageTtl = 1800, maxPages = 1000, collections = [], uploadsEnabled = false,
|
|
121
|
-
cssTheme = 'gramlot-base', librarySource = 'cdn'} = {}) {
|
|
123
|
+
cssTheme = 'gramlot-base', librarySource = 'cdn', websocketUrl = null} = {}) {
|
|
122
124
|
if (!['cdn', 'local'].includes(librarySource)) {
|
|
123
125
|
throw new TypeError(`The library source must be 'cdn' or 'local', not ${JSON.stringify(librarySource)}`);
|
|
124
126
|
}
|
|
@@ -130,9 +132,10 @@ export class GramlotServer {
|
|
|
130
132
|
!Number.isSafeInteger(maxPages) || maxPages < 1) {
|
|
131
133
|
throw new TypeError('Page TTL must be finite and positive; capacity must be a positive safe integer');
|
|
132
134
|
}
|
|
133
|
-
Object.assign(this, {runtimeUrl, rpcUrl, closeUrl, rootId, pageTtl, maxPages, cssTheme, librarySource});
|
|
135
|
+
Object.assign(this, {runtimeUrl, rpcUrl, closeUrl, rootId, pageTtl, maxPages, cssTheme, librarySource, websocketUrl, uploadUrl});
|
|
134
136
|
this.libraries = libraries;
|
|
135
137
|
this.pages = new Map();
|
|
138
|
+
this.sharedStores = new Map();
|
|
136
139
|
this.uploads = uploadsEnabled ? new UploadRegistry() : null;
|
|
137
140
|
this.collections = this.collectionGraph([...standardCollections, ...collections]);
|
|
138
141
|
this.preparedGrammars = new WeakMap();
|
|
@@ -243,9 +246,100 @@ export class GramlotServer {
|
|
|
243
246
|
/** Optional initial Data Bag for this page path; no companion in the neutral server. */
|
|
244
247
|
async resolveData(path) { return null; }
|
|
245
248
|
|
|
249
|
+
resolvePageStore(PageClass, path) { return PageStore; }
|
|
250
|
+
|
|
251
|
+
createPageStore(StoreClass, {pageId, owner}) { return new StoreClass(); }
|
|
252
|
+
|
|
253
|
+
/** Resolve and renew the store only within its page owner's session. */
|
|
254
|
+
pageStore(pageId, {owner} = {}) {
|
|
255
|
+
this.prune();
|
|
256
|
+
const record = this.pages.get(pageId);
|
|
257
|
+
if (!record?.store || owner == null || record.owner !== owner) throw new PageExpired('Unknown, expired or unowned page');
|
|
258
|
+
record.expires = this.#expiry();
|
|
259
|
+
return record.store;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async openChatImage(pageId, ref, {owner}) {
|
|
263
|
+
const store = this.pageStore(pageId, {owner});
|
|
264
|
+
return store instanceof ChatPageStore ? store.attachments.openImage(ref) : null;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
connectPageChannel(pageId, send, {owner}) {
|
|
268
|
+
this.pageStore(pageId, {owner});
|
|
269
|
+
if (typeof send !== 'function') throw new TypeError('Page channel requires a send callback');
|
|
270
|
+
const record = this.pages.get(pageId);
|
|
271
|
+
if (record.send) throw new Error('Page already has a channel');
|
|
272
|
+
record.send = send;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
disconnectPageChannel(pageId, {owner}) {
|
|
276
|
+
const record = this.pages.get(pageId);
|
|
277
|
+
if (record && record.owner === owner) delete record.send;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
sharedStore(key, factory) {
|
|
281
|
+
if (!Array.isArray(key) || !key.length || key.some(part => typeof part !== 'string' || !part)) {
|
|
282
|
+
throw new TypeError('Shared store keys must be nonempty arrays of nonempty strings');
|
|
283
|
+
}
|
|
284
|
+
const encoded = JSON.stringify(key);
|
|
285
|
+
if (!this.sharedStores.has(encoded)) {
|
|
286
|
+
if (this.sharedStores.size >= this.maxPages) throw new ServerCapacity('Shared store registry capacity reached');
|
|
287
|
+
const store = factory();
|
|
288
|
+
if (!(store instanceof PageStore)) throw new TypeError('Shared stores must subclass PageStore');
|
|
289
|
+
store.start();
|
|
290
|
+
this.sharedStores.set(encoded, store);
|
|
291
|
+
}
|
|
292
|
+
return this.sharedStores.get(encoded);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
closeSharedStore(key) {
|
|
296
|
+
const encoded = JSON.stringify(key);
|
|
297
|
+
const store = this.sharedStores.get(encoded);
|
|
298
|
+
if (store) { this.sharedStores.delete(encoded); store.close(); }
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
publishToPage(topic, payload, {sourcePageId, pageId, owner}) {
|
|
302
|
+
if (typeof pageId !== 'string' || !pageId || typeof topic !== 'string' || !topic || !isMapping(payload)) {
|
|
303
|
+
throw new InvalidRequest('Publication requires a destination, topic and named payload');
|
|
304
|
+
}
|
|
305
|
+
this.pageStore(sourcePageId, {owner});
|
|
306
|
+
this.pageStore(pageId, {owner});
|
|
307
|
+
const {send} = this.pages.get(pageId);
|
|
308
|
+
if (!send) throw new PageExpired('Page has no connected channel');
|
|
309
|
+
send(toTytx({op:'publish', pageId, topic, payload, metadata:{pageId:sourcePageId}}));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** The adapter sends the acceptance before invoking the returned dispatch. */
|
|
313
|
+
preparePublish(text, {owner}) {
|
|
314
|
+
let message;
|
|
315
|
+
try { message = fromTytx(text); } catch (cause) { throw new InvalidRequest('Publication is not TYTX text', {cause}); }
|
|
316
|
+
if (!isMapping(message) || message.op !== 'publish' || typeof message.id !== 'string' || !message.id) {
|
|
317
|
+
throw new InvalidRequest('Expected a publication envelope with a nonempty id');
|
|
318
|
+
}
|
|
319
|
+
const response = {id:message.id, contentType:'data'};
|
|
320
|
+
let dispatch = null;
|
|
321
|
+
try {
|
|
322
|
+
const {pageId, targetPageId = pageId, topic, payload} = message;
|
|
323
|
+
if (Object.keys(message).some(key => !['op','id','pageId','targetPageId','topic','payload'].includes(key)) ||
|
|
324
|
+
[pageId,targetPageId,topic].some(value => typeof value !== 'string' || !value) || !isMapping(payload)) {
|
|
325
|
+
throw new InvalidRequest('Invalid publication fields');
|
|
326
|
+
}
|
|
327
|
+
this.pageStore(pageId, {owner});
|
|
328
|
+
const destination = this.pageStore(targetPageId, {owner});
|
|
329
|
+
dispatch = () => destination.publish(topic, payload, {metadata:{pageId}});
|
|
330
|
+
response.value = 'ok';
|
|
331
|
+
} catch (error) {
|
|
332
|
+
response.error = {code:error instanceof InvalidRequest ? 'invalid_request' :
|
|
333
|
+
OUTCOME_CODES.get(error.constructor) ?? 'application_error', name:error.name, message:error.message};
|
|
334
|
+
if (gramlotDev() === 'DEBUG') response.error.details = error.stack;
|
|
335
|
+
}
|
|
336
|
+
return [toTytx(response), dispatch];
|
|
337
|
+
}
|
|
338
|
+
|
|
246
339
|
/** The capabilities announced in the bootstrap; none in the base server. */
|
|
247
340
|
get capabilities() {
|
|
248
|
-
return [];
|
|
341
|
+
if (!this.uploads) return [];
|
|
342
|
+
return this.websocketUrl ? ['upload', 'pageStoreReconnect'] : ['upload'];
|
|
249
343
|
}
|
|
250
344
|
|
|
251
345
|
/** The NameSyntax of the method names a request may carry, announced in the bootstrap
|
|
@@ -288,8 +382,7 @@ export class GramlotServer {
|
|
|
288
382
|
prune() {
|
|
289
383
|
const now = performance.now();
|
|
290
384
|
for (const [id, record] of this.pages) if (record.expires <= now) {
|
|
291
|
-
this.
|
|
292
|
-
void this.uploads?.closePage(id, record.owner);
|
|
385
|
+
this.closePage(id, {owner:record.owner});
|
|
293
386
|
}
|
|
294
387
|
}
|
|
295
388
|
|
|
@@ -328,12 +421,13 @@ export class GramlotServer {
|
|
|
328
421
|
* `<path>/index.html` registers the page `<path>/` and `/index.html` the index. The CSS of the
|
|
329
422
|
* page is its theme (themeCss), then the CSS of resolveResources, each URL once in its last
|
|
330
423
|
* position. */
|
|
331
|
-
async registerPage(path, {owner = null} = {}) {
|
|
424
|
+
async registerPage(path, {owner = null, prefix = '', websocketUrl = this.websocketUrl} = {}) {
|
|
332
425
|
if (path.endsWith('/index.html')) path = path.slice(0, -'index.html'.length);
|
|
333
426
|
let PageClass = await this.resolvePage(path);
|
|
334
427
|
if (typeof PageClass !== 'function' || !(PageClass.prototype instanceof Page)) {
|
|
335
428
|
throw new TypeError('Page modules must export a subclass of Page');
|
|
336
429
|
}
|
|
430
|
+
const StoreClass = await this.resolvePageStore(PageClass, path);
|
|
337
431
|
PageClass = this.environmentPage(PageClass);
|
|
338
432
|
const selected = this.pageCollections(PageClass);
|
|
339
433
|
const resolved = await this.resolveResources(path, PageClass);
|
|
@@ -347,7 +441,26 @@ export class GramlotServer {
|
|
|
347
441
|
this.prune();
|
|
348
442
|
if (this.pages.size >= this.maxPages) throw new ServerCapacity('Page registry capacity reached');
|
|
349
443
|
const pageId = crypto.randomUUID().replaceAll('-', '');
|
|
350
|
-
|
|
444
|
+
const record = {PageClass, path, owner, expires:this.#expiry()};
|
|
445
|
+
this.pages.set(pageId, record);
|
|
446
|
+
try {
|
|
447
|
+
if (websocketUrl !== null || StoreClass !== PageStore) {
|
|
448
|
+
if (StoreClass !== PageStore && !(StoreClass?.prototype instanceof PageStore)) {
|
|
449
|
+
throw new TypeError('PageStore must subclass gramlot.PageStore');
|
|
450
|
+
}
|
|
451
|
+
const store = this.createPageStore(StoreClass, {pageId, owner});
|
|
452
|
+
record.store = store;
|
|
453
|
+
if (store instanceof ChatPageStore) store.attachments.url = prefix + '/gramlot/attachment/' + pageId + '/';
|
|
454
|
+
store._sourceBuilder = () => {
|
|
455
|
+
const builder = new PageClass.sourceBuilder(null, {nameSyntax:this.nameSyntax});
|
|
456
|
+
this.loadCollections(builder, selected);
|
|
457
|
+
return builder;
|
|
458
|
+
};
|
|
459
|
+
store._sharedStore = (key, factory) => this.sharedStore(key, factory);
|
|
460
|
+
store._publishToPage = (topic, payload, target) => this.publishToPage(topic, payload, {sourcePageId:pageId, pageId:target, owner});
|
|
461
|
+
store.start();
|
|
462
|
+
}
|
|
463
|
+
} catch (error) { this.closePage(pageId, {owner}); throw error; }
|
|
351
464
|
return {pageId, title: PageClass.title, resources, nameSyntax: this.nameSyntax.toJSON(),
|
|
352
465
|
...(PageClass.devices.length ? {devices: [...PageClass.devices]} : {}),
|
|
353
466
|
...(PageClass.locale == null ? {} : {locale: PageClass.locale}),
|
|
@@ -356,15 +469,17 @@ export class GramlotServer {
|
|
|
356
469
|
|
|
357
470
|
/** Register the page (registerPage) and return its bootstrap. prefix is the mount prefix chosen
|
|
358
471
|
* by the adapter, added once to the root-relative bootstrap URLs. */
|
|
359
|
-
async openPage(path, {owner = null, prefix = ''} = {}) {
|
|
472
|
+
async openPage(path, {owner = null, prefix = '', websocketUrl = this.websocketUrl} = {}) {
|
|
360
473
|
if (typeof prefix !== 'string') throw new TypeError('Mount prefix must be a string');
|
|
361
|
-
const {pageId, title, resources, nameSyntax, locale, timeZone, devices} = await this.registerPage(path, {owner});
|
|
474
|
+
const {pageId, title, resources, nameSyntax, locale, timeZone, devices} = await this.registerPage(path, {owner, prefix, websocketUrl});
|
|
362
475
|
try {
|
|
363
476
|
const nonce = createNonce();
|
|
364
477
|
// The CSS links and the JS modules reach the page through PageBootstrap (§4.12, D9).
|
|
365
478
|
const bootstrap = scriptJson({
|
|
366
479
|
config: {pageId, rpcUrl: prefixed(prefix, this.rpcUrl), closeUrl: prefixed(prefix, this.closeUrl),
|
|
367
480
|
rootId: this.rootId, capabilities: this.capabilities, nameSyntax,
|
|
481
|
+
...(websocketUrl !== null ? {websocketUrl:prefixed(prefix, websocketUrl)} : {}),
|
|
482
|
+
...(this.uploadUrl !== null ? {uploadUrl:prefixed(prefix,this.uploadUrl)} : {}),
|
|
368
483
|
...(devices === undefined ? {} : {devices}),
|
|
369
484
|
...(locale === undefined ? {} : {locale}), ...(timeZone === undefined ? {} : {timeZone})},
|
|
370
485
|
resources: {...(resources.collections ? {collections: resources.collections.map(record => ({...record,url:prefixed(prefix,record.url)}))} : {}),
|
|
@@ -373,7 +488,8 @@ export class GramlotServer {
|
|
|
373
488
|
...(resources.serverAdapter ? {serverAdapter: prefixed(prefix, resources.serverAdapter)} : {})},
|
|
374
489
|
});
|
|
375
490
|
const document = new GramlotBuilder();
|
|
376
|
-
const root = document.root.html({'data-gramlot-library-source': this.librarySource
|
|
491
|
+
const root = document.root.html({'data-gramlot-library-source': this.librarySource,
|
|
492
|
+
'data-gramlot-theme-root': prefixed(prefix, '/themes/')});
|
|
377
493
|
const head = root.head();
|
|
378
494
|
head.meta({charset: 'utf-8'});
|
|
379
495
|
head.meta({name: 'viewport', content: 'width=device-width,initial-scale=1'});
|
|
@@ -427,7 +543,7 @@ export class GramlotServer {
|
|
|
427
543
|
const request = parseRequest(text);
|
|
428
544
|
const response = {id: request.id, contentType: request.contentType};
|
|
429
545
|
try {
|
|
430
|
-
response.value = (await this.#run(request, owner, identity)) ?? null;
|
|
546
|
+
response.value = (await this.#run(request, owner, identity, response)) ?? null;
|
|
431
547
|
if (request.contentType === 'source' && request.name === 'main') {
|
|
432
548
|
const data = await this.resolveData(this.pages.get(request.pageId).path);
|
|
433
549
|
if (data !== null) {
|
|
@@ -439,6 +555,7 @@ export class GramlotServer {
|
|
|
439
555
|
} catch (error) {
|
|
440
556
|
delete response.value;
|
|
441
557
|
delete response.data;
|
|
558
|
+
delete response.icons;
|
|
442
559
|
response.error = {code: OUTCOME_CODES.get(error?.constructor) ?? 'application_error',
|
|
443
560
|
name: error?.name ?? 'Error', message: error?.message ?? String(error)};
|
|
444
561
|
if (gramlotDev() === 'DEBUG') response.error.details = error?.stack;
|
|
@@ -453,13 +570,14 @@ export class GramlotServer {
|
|
|
453
570
|
* owner that has not expired renews the page, whatever the outcome of the method; any other call renews
|
|
454
571
|
* nothing (GC-230 §010).
|
|
455
572
|
*/
|
|
456
|
-
async #run({pageId, contentType, name, params}, owner, identity) {
|
|
573
|
+
async #run({pageId, contentType, name, params}, owner, identity, response) {
|
|
457
574
|
this.prune();
|
|
458
575
|
const record = this.pages.get(pageId);
|
|
459
576
|
if (!record || record.owner !== owner) throw new PageExpired('Unknown, expired or unowned page');
|
|
460
577
|
record.expires = this.#expiry();
|
|
461
578
|
const page = new record.PageClass();
|
|
462
579
|
page.pageId = pageId;
|
|
580
|
+
if (record.store instanceof ChatPageStore) page.chat_files = record.store.attachments;
|
|
463
581
|
Object.defineProperty(page, 'requestIdentity', {value:identity, writable:false});
|
|
464
582
|
if (contentType === 'upload') return this.#uploadControl(page, pageId, owner, identity, name, params);
|
|
465
583
|
const source = contentType === 'source';
|
|
@@ -482,11 +600,17 @@ export class GramlotServer {
|
|
|
482
600
|
throw new Refusal(`Access refused: ${name}`);
|
|
483
601
|
}
|
|
484
602
|
if (!source) return callable.call(instance, params);
|
|
603
|
+
const {_inheritedAttributes: inherited, ...sourceParams} = params;
|
|
485
604
|
const builder = new record.PageClass.sourceBuilder(name,
|
|
486
605
|
{auth: elementRule => this.#authOutcome(elementRule, owner, identity), nameSyntax: this.nameSyntax});
|
|
606
|
+
// remote with sendInheritedAttributes: the _root_ node above the fragment carries them, so every
|
|
607
|
+
// node of the fragment inherits them, as the root_wrapper of legacy makeRoot.
|
|
608
|
+
if (inherited !== undefined) builder.source.parentNode.setAttr(inherited, false);
|
|
487
609
|
this.loadCollections(builder, this.pageCollections(record.PageClass));
|
|
488
|
-
const result = await callable.call(instance, builder.root,
|
|
610
|
+
const result = await callable.call(instance, builder.root, sourceParams);
|
|
489
611
|
if (result !== undefined && result !== null) throw new TypeError('Source methods populate root and return no value');
|
|
612
|
+
const icons = page._icons.definitions();
|
|
613
|
+
if (Object.keys(icons).length) response.icons = icons;
|
|
490
614
|
return builder.toTytx();
|
|
491
615
|
}
|
|
492
616
|
|
|
@@ -535,7 +659,7 @@ export class GramlotServer {
|
|
|
535
659
|
if (!['status','cancel'].includes(name) || Object.keys(params).join(',') !== 'transferId') throw new TypeError('Invalid upload control');
|
|
536
660
|
const record = this.uploads.record(params.transferId, pageId, owner);
|
|
537
661
|
this.#uploadOperation(page, record.operation, owner, identity);
|
|
538
|
-
return name === 'status' ? record.transfer.
|
|
662
|
+
return name === 'status' ? record.transfer.checkpoint() : record.transfer.abort();
|
|
539
663
|
}
|
|
540
664
|
|
|
541
665
|
/** Admit a single binary upload; adapters provide the current request identity. */
|
|
@@ -546,10 +670,13 @@ export class GramlotServer {
|
|
|
546
670
|
if (!record || record.owner !== owner) throw new PageExpired('Unknown, expired or unowned page');
|
|
547
671
|
const page = new record.PageClass();
|
|
548
672
|
page.pageId = pageId;
|
|
673
|
+
if (record.store instanceof ChatPageStore) page.chat_files = record.store.attachments;
|
|
549
674
|
Object.defineProperty(page, 'requestIdentity', {value:identity, writable:false});
|
|
550
675
|
const upload = this.uploads.record(transferId, pageId, owner);
|
|
551
676
|
this.#uploadOperation(page, upload.operation, owner, identity);
|
|
552
|
-
|
|
677
|
+
const transfer = this.uploads.admit(transferId, pageId, owner, authorization);
|
|
678
|
+
record.expires = this.#expiry();
|
|
679
|
+
return transfer;
|
|
553
680
|
}
|
|
554
681
|
|
|
555
682
|
/** Close the page named by the close message `text`, `{"pageId": string}` as JSON, when `owner`
|
|
@@ -569,16 +696,19 @@ export class GramlotServer {
|
|
|
569
696
|
}
|
|
570
697
|
|
|
571
698
|
closePage(pageId, {owner = null} = {}) {
|
|
572
|
-
|
|
699
|
+
const record = this.pages.get(pageId);
|
|
700
|
+
if (record && record.owner === owner) {
|
|
573
701
|
this.pages.delete(pageId);
|
|
702
|
+
record.store?.close();
|
|
574
703
|
void this.uploads?.closePage(pageId, owner);
|
|
575
704
|
}
|
|
576
705
|
}
|
|
577
706
|
|
|
578
707
|
/** Forget every registered page; adapters call it on shutdown. */
|
|
579
708
|
closeAll() {
|
|
580
|
-
for (const [pageId, record] of this.pages)
|
|
581
|
-
|
|
709
|
+
for (const [pageId, record] of this.pages) this.closePage(pageId, {owner:record.owner});
|
|
710
|
+
for (const store of this.sharedStores.values()) store.close();
|
|
711
|
+
this.sharedStores.clear();
|
|
582
712
|
}
|
|
583
713
|
|
|
584
714
|
}
|
|
@@ -4,6 +4,16 @@ import type {Bag, BagNode} from '@genrojs/bag';
|
|
|
4
4
|
export class IndexPage extends FramePage {
|
|
5
5
|
static navigation: Bag;
|
|
6
6
|
static datapath: string;
|
|
7
|
+
static navigationSelection: string | null;
|
|
8
|
+
static logoUrl: string | null;
|
|
9
|
+
static sidebarTools: ReadonlyArray<'navigation' | 'toolbar' | 'settings' | Record<string, unknown>>;
|
|
10
|
+
static settingsId: string | null;
|
|
11
|
+
static themeGroup: string | null;
|
|
12
|
+
commandBar(frame: any): void;
|
|
13
|
+
toolbar(rail: any): void;
|
|
14
|
+
top(pane: any): void;
|
|
15
|
+
header(pane: any): any;
|
|
16
|
+
settings(pane: any): any;
|
|
7
17
|
left(pane: any): void;
|
|
8
18
|
center(pane: any): void;
|
|
9
19
|
panel(pane: any, node: BagNode): void;
|
package/src/server/index-page.js
CHANGED
|
@@ -3,28 +3,112 @@
|
|
|
3
3
|
import {Bag} from '@genrojs/bag';
|
|
4
4
|
import {FramePage} from './frame-page.js';
|
|
5
5
|
|
|
6
|
+
// Built-in texts by language of the page locale; English when the language has none.
|
|
7
|
+
const TEXTS = {
|
|
8
|
+
en: {navigation:'Navigation', settings:'Settings', tools:'Application tools',
|
|
9
|
+
appearance:'Theme', palette:'Colors', theme:'Color mode',
|
|
10
|
+
palettes:'default:Theme default,compact:Blue & slate,mimi:Sage & green,joanna:Warm gray & blue',
|
|
11
|
+
themes:'auto:System,light:Light,dark:Dark'},
|
|
12
|
+
it: {navigation:'Navigazione', settings:'Impostazioni', tools:"Strumenti dell'applicazione",
|
|
13
|
+
appearance:'Tema', palette:'Colori', theme:'Modalità colore',
|
|
14
|
+
palettes:'default:Predefiniti del tema,compact:Blu e ardesia,mimi:Salvia e verde,joanna:Grigio caldo e blu',
|
|
15
|
+
themes:'auto:Sistema,light:Chiaro,dark:Scuro'},
|
|
16
|
+
};
|
|
17
|
+
|
|
6
18
|
export class IndexPage extends FramePage {
|
|
7
19
|
static title = 'Application';
|
|
8
20
|
static shellId = 'index';
|
|
9
21
|
static datapath = 'index';
|
|
10
22
|
static navigation = null;
|
|
23
|
+
static navigationSelection = null;
|
|
24
|
+
static logoUrl = null;
|
|
25
|
+
static sidebarTools = ['navigation', 'toolbar', 'settings'];
|
|
26
|
+
static settingsId = null;
|
|
27
|
+
static themeGroup = null;
|
|
28
|
+
static css = ['/themes/gramlot-index/theme.css'];
|
|
29
|
+
|
|
30
|
+
#language() {
|
|
31
|
+
const language = (this.constructor.locale ?? '').split('-')[0].toLowerCase();
|
|
32
|
+
return TEXTS[language] ? language : 'en';
|
|
33
|
+
}
|
|
34
|
+
#texts() { return TEXTS[this.#language()]; }
|
|
11
35
|
|
|
12
36
|
main(root) {
|
|
13
|
-
const {navigation, datapath} = this.constructor;
|
|
37
|
+
const {navigation, datapath, shellId, navigationSelection, themeGroup} = this.constructor;
|
|
14
38
|
if (!(navigation instanceof Bag)) throw new TypeError('IndexPage.navigation must be a Bag');
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
root.
|
|
19
|
-
|
|
39
|
+
if (themeGroup !== null && (typeof themeGroup !== 'string' || !themeGroup.trim())) {
|
|
40
|
+
throw new TypeError('IndexPage.themeGroup must be nonempty text');
|
|
41
|
+
}
|
|
42
|
+
const frame = root.framePane({id:`${shellId}-frame`, class:'gramlot-index-frame', height:'100%', min_height:0});
|
|
43
|
+
for (const [destination_path,value] of Object.entries({
|
|
44
|
+
'.navigation':navigation, '.navigationSelection':navigationSelection,
|
|
45
|
+
'.active':null, '.opened':new Bag(), '.navigationOpen':true,
|
|
46
|
+
'.settingsOpen':false, '.themeGroup':themeGroup,
|
|
47
|
+
})) frame.dataSetter({datapath,destination_path,value});
|
|
48
|
+
this.commandBar(frame);
|
|
49
|
+
super.main(frame.center);
|
|
50
|
+
const settings = frame.center.floatingPane({id:`${shellId}-settings`, title:this.#texts().settings, datapath,
|
|
51
|
+
open:'^.settingsOpen', width:'390px', height:'420px'});
|
|
52
|
+
settings.frame.center.setAttr({padding:'12px', overflow:'auto'});
|
|
53
|
+
this.settings(settings.frame.center);
|
|
54
|
+
}
|
|
55
|
+
commandBar(frame) {
|
|
56
|
+
const {shellId, datapath, sidebarTools} = this.constructor;
|
|
57
|
+
if (!sidebarTools.length) return;
|
|
58
|
+
const region = frame.left;
|
|
59
|
+
region.setAttr({id:`${shellId}-rail-region`, width:'42px', class:'gramlot-index-rail-region', datapath});
|
|
60
|
+
const rail = region.menu({id:`${shellId}-rail`, class:'gramlot-index-rail',
|
|
61
|
+
presentation:'bar', orientation:'vertical', labelPosition:'tooltip', icon_size:24,
|
|
62
|
+
width:'100%', height:'100%', aria_label:this.#texts().tools});
|
|
63
|
+
for (const tool of sidebarTools) {
|
|
64
|
+
if (tool && typeof tool === 'object' && !Array.isArray(tool)) {
|
|
65
|
+
rail.menuline(tool);
|
|
66
|
+
} else if (tool === 'toolbar') {
|
|
67
|
+
this.toolbar(rail);
|
|
68
|
+
} else if (tool === 'navigation') {
|
|
69
|
+
rail.menuline({id:`${shellId}-navigation-button`, caption:this.#texts().navigation, icon:'navigation',
|
|
70
|
+
checked:'^.navigationOpen', action:"this.SET('.navigationOpen', !this.GET('.navigationOpen'))"});
|
|
71
|
+
} else if (tool === 'settings') {
|
|
72
|
+
rail.menuline({id:`${shellId}-settings-button`, caption:this.#texts().settings, icon:'settings',
|
|
73
|
+
checked:'^.settingsOpen', action:"this.SET('.settingsOpen', !this.GET('.settingsOpen'))"});
|
|
74
|
+
} else {
|
|
75
|
+
throw new TypeError(`Unknown IndexPage sidebar tool: ${tool}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
toolbar(rail) { rail.spacer({flex:1}); }
|
|
80
|
+
top(pane) {
|
|
81
|
+
pane.setAttr({height:'42px'});
|
|
82
|
+
this.header(pane);
|
|
83
|
+
}
|
|
84
|
+
header(pane) {
|
|
85
|
+
const header = pane.header({class:'gramlot-index-header'});
|
|
86
|
+
if (this.constructor.logoUrl) header.img({src:this.constructor.logoUrl, alt:''});
|
|
87
|
+
header.h1(this.constructor.title);
|
|
88
|
+
return header;
|
|
89
|
+
}
|
|
90
|
+
settings(pane) {
|
|
91
|
+
const fields = pane.formlet({columns:1, lbl_position:'L', lbl_text_align:'right',
|
|
92
|
+
box_c_width:'100%', gap:'8px 12px'});
|
|
93
|
+
const prefix = this.constructor.settingsId ?? this.constructor.shellId;
|
|
94
|
+
const texts = this.#texts();
|
|
95
|
+
for (const [name,lbl,values] of [
|
|
96
|
+
['appearance',texts.appearance,'base:Base,compact:Compact,mimi:Mimi,joanna:Joanna,mela:Mela'],
|
|
97
|
+
['palette',texts.palette,texts.palettes],
|
|
98
|
+
['theme',texts.theme,texts.themes],
|
|
99
|
+
]) fields.filteringSelect({id:`${prefix}-${name}`, lbl, value:`^.${name}`, values, validate_notnull:true});
|
|
100
|
+
return fields;
|
|
20
101
|
}
|
|
21
102
|
left(pane) {
|
|
22
|
-
pane.setAttr({width: '240px', splitter: true,
|
|
103
|
+
pane.setAttr({width: '240px', splitter: true, nodeId:`${this.constructor.shellId}Navigation`,
|
|
104
|
+
drawer: "^.navigationOpen:={} ? true : 'close'", drawer_label: this.#texts().navigation});
|
|
105
|
+
pane.dataController({script: "this.SET('.navigationOpen', open)",
|
|
106
|
+
[`subscribe_${this.constructor.shellId}Navigation_closable_change`]: true});
|
|
23
107
|
pane.tree({node_label: 'tree', storepath: '.navigation',
|
|
24
108
|
labelAttribute: 'title', hideValues: true, selectedPath: '^.navigationSelection'});
|
|
25
109
|
}
|
|
26
110
|
center(pane) {
|
|
27
|
-
pane.tabContainer({node_label: 'tabs', height: '100%', selectedPage: '^.active'});
|
|
111
|
+
pane.tabContainer({node_label: 'tabs', tabMode: 'tabBar', height: '100%', selectedPage: '^.active'});
|
|
28
112
|
}
|
|
29
113
|
behavior(shell) {
|
|
30
114
|
shell.dataController({func: 'indexMount', _onStart: true});
|
package/src/server/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
-
export {Exposed, Page} from './page.js';
|
|
7
|
+
export {Exposed, Page, PageStore} from './page.js';
|
|
8
8
|
export {GramlotServer, EndpointNotFound, InvalidRequest, NotAuthenticated, NotAuthorized, PageExpired, PageNotFound,
|
|
9
9
|
SourceNotFound, ServerCapacity} from './gramlot-server.js';
|
|
10
10
|
export type {GramlotServerOptions, OpenedPage, RegisteredPage} from './gramlot-server.js';
|
package/src/server/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @module
|
|
7
7
|
*/
|
|
8
8
|
// Server entry point: deliberately not re-exported by the browser entry point.
|
|
9
|
-
export {Exposed, Page} from './page.js';
|
|
9
|
+
export {Exposed, Page, PageStore} from './page.js';
|
|
10
10
|
export {GramlotServer, EndpointNotFound, InvalidRequest, NotAuthenticated, NotAuthorized, PageExpired, PageNotFound,
|
|
11
11
|
SourceNotFound, ServerCapacity} from './gramlot-server.js';
|
|
12
12
|
export {GramlotBuilder} from '../builder/gramlot-builder.js';
|
package/src/server/page-base.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {IconRegistry} from '../icons.js';
|
|
1
2
|
/* @ts-self-types="./page.d.ts" */
|
|
2
3
|
/**
|
|
3
4
|
* Server-side page base class, the `Exposed` base of the classes reached by a method path, and the
|
|
@@ -109,6 +110,9 @@ export class Exposed {
|
|
|
109
110
|
|
|
110
111
|
/** Server-side page base; unrelated to browser view components. */
|
|
111
112
|
export class Page extends Exposed {
|
|
113
|
+
_icons = new IconRegistry();
|
|
114
|
+
addIcon(name, asset) { this._icons.add(name, asset); }
|
|
115
|
+
|
|
112
116
|
static gramlots = [];
|
|
113
117
|
static title = 'Gramlot';
|
|
114
118
|
static devices = [];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type {Bag} from '@genrojs/bag';
|
|
2
|
+
import type {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
3
|
+
|
|
4
|
+
export class PageStore {
|
|
5
|
+
readonly builder: GramlotBuilder;
|
|
6
|
+
readonly data: Bag;
|
|
7
|
+
readonly closed: boolean;
|
|
8
|
+
main(root: GramlotBuilder['root']): void;
|
|
9
|
+
start(): void;
|
|
10
|
+
close(): void;
|
|
11
|
+
sourceBuilder(): GramlotBuilder;
|
|
12
|
+
sharedStore<T extends PageStore>(key: string[], factory: () => T): T;
|
|
13
|
+
bindPath(path: string, target: PageStore, targetPath: string, options: {authorize: () => boolean; writable?: boolean}): string;
|
|
14
|
+
isPathBound(path: string): boolean;
|
|
15
|
+
unbindPath(path: string): void;
|
|
16
|
+
unbindPaths(): void;
|
|
17
|
+
subscribe(binderId: string, path: string, send: (wire: string) => void): void;
|
|
18
|
+
unsubscribe(binderId: string): void;
|
|
19
|
+
change(binderId: string, message: {path: string; evt: string; value?: unknown; attr?: Record<string, unknown>; index?: number | null; fired?: boolean}): void;
|
|
20
|
+
publish(topic: string, payload?: Record<string, unknown>, options?: {metadata?: Record<string, unknown>; pageId?: string}): void;
|
|
21
|
+
}
|