@gramlot/gramlot 0.3.41 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/icons/applications.svg +4 -0
- package/assets/icons/archive.svg +4 -0
- package/assets/icons/attachment.svg +4 -0
- package/assets/icons/book.svg +4 -0
- package/assets/icons/bookmark.svg +4 -0
- package/assets/icons/calendar.svg +4 -0
- package/assets/icons/cancel.svg +4 -0
- package/assets/icons/chart.svg +4 -1
- package/assets/icons/chat.svg +4 -0
- package/assets/icons/clock.svg +4 -0
- package/assets/icons/code.svg +4 -0
- package/assets/icons/collapse.svg +4 -0
- package/assets/icons/columns.svg +4 -0
- package/assets/icons/confirm.svg +4 -0
- package/assets/icons/copy.svg +4 -0
- package/assets/icons/cut.svg +4 -0
- package/assets/icons/database.svg +4 -0
- package/assets/icons/delete.svg +4 -0
- package/assets/icons/detach.svg +4 -0
- package/assets/icons/document.svg +4 -0
- package/assets/icons/download.svg +4 -0
- package/assets/icons/duplicate.svg +4 -0
- package/assets/icons/edit.svg +4 -0
- package/assets/icons/expand.svg +4 -0
- package/assets/icons/export.svg +4 -0
- package/assets/icons/eye.svg +4 -0
- package/assets/icons/filter.svg +4 -0
- package/assets/icons/first.svg +4 -0
- package/assets/icons/folder.svg +4 -0
- package/assets/icons/group.svg +4 -0
- package/assets/icons/help.svg +4 -0
- package/assets/icons/home.svg +4 -0
- package/assets/icons/import.svg +4 -0
- package/assets/icons/info.svg +4 -0
- package/assets/icons/inspector.svg +4 -0
- package/assets/icons/last.svg +4 -0
- package/assets/icons/layers.svg +4 -0
- package/assets/icons/link.svg +4 -0
- package/assets/icons/list.svg +4 -0
- package/assets/icons/lock.svg +4 -0
- package/assets/icons/logout.svg +4 -0
- package/assets/icons/navigation.svg +4 -0
- package/assets/icons/new.svg +4 -0
- package/assets/icons/next.svg +4 -0
- package/assets/icons/open.svg +4 -0
- package/assets/icons/palette.svg +4 -0
- package/assets/icons/panel-bottom.svg +4 -0
- package/assets/icons/panel-left.svg +4 -0
- package/assets/icons/panel-right.svg +4 -0
- package/assets/icons/panel-top.svg +4 -0
- package/assets/icons/paste.svg +4 -0
- package/assets/icons/pause.svg +4 -0
- package/assets/icons/pin.svg +4 -0
- package/assets/icons/play.svg +4 -0
- package/assets/icons/previous.svg +4 -0
- package/assets/icons/print.svg +4 -0
- package/assets/icons/redo.svg +4 -0
- package/assets/icons/refresh.svg +4 -0
- package/assets/icons/save.svg +4 -0
- package/assets/icons/search.svg +4 -0
- package/assets/icons/send.svg +4 -0
- package/assets/icons/settings.svg +4 -0
- package/assets/icons/sort-ascending.svg +4 -0
- package/assets/icons/sort-descending.svg +4 -0
- package/assets/icons/stop.svg +4 -0
- package/assets/icons/table.svg +4 -0
- package/assets/icons/tree.svg +4 -0
- package/assets/icons/undo.svg +4 -0
- package/assets/icons/unlock.svg +4 -0
- package/assets/icons/upload.svg +4 -0
- package/assets/icons/user.svg +4 -0
- package/assets/icons/warning.svg +4 -0
- package/assets/icons/zoom-in.svg +4 -0
- package/assets/icons/zoom-out.svg +4 -0
- package/dist/components/charts/__init__.py +1 -1
- package/dist/components/charts/assets/index.js +1 -1
- package/dist/components/charts/assets/libraries/vega.js +11 -11
- package/dist/components/editors/__init__.py +1 -1
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/libraries/codemirror.js +30 -31
- package/dist/components/editors/assets/libraries/jodit.js +3 -1
- package/dist/components/editors/grammar.json +6 -1
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/commands.json +4 -6
- package/dist/components/grid/grammar.json +51 -0
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +4987 -216
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +69 -4
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +16 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +6 -6
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/uploads/grammar.json +66 -0
- package/dist/declared-collections.js +1 -1
- package/dist/gramlot.js +3961 -1249
- package/dist/gramlot.min.js +329 -131
- package/dist/libraries.json +1 -0
- package/dist/standard-collections.js +1 -1
- package/dist/standard-grammar.js +1 -1
- package/package.json +3 -1
- package/src/binding/ask-dialog.js +17 -3
- package/src/binding/providers.js +1 -1
- package/src/binding/runtime.js +6 -3
- package/src/builder/chart-icon.js +2 -0
- package/src/builder/gramlot-builder.d.ts +3 -1
- package/src/builder/gramlot-builder.js +26 -9
- package/src/builder/source.js +12 -3
- package/src/builder/xml-recipe.js +144 -0
- package/src/chat-file-types.js +13 -0
- package/src/chat.js +23 -25
- package/src/commands.d.ts +1 -1
- package/src/commands.js +1 -1
- package/src/components/border-container.js +64 -6
- package/src/components/buttons.js +26 -31
- package/src/components/chart-geographic-options.js +1 -1
- package/src/components/chart-pane.js +5 -5
- package/src/components/chart-spatial-options.js +5 -1
- package/src/components/check-box-text-editor.js +1 -0
- package/src/components/check-box-text.js +2 -0
- package/src/components/choice-editor.js +3 -2
- package/src/components/choice-field-styles.js +9 -1
- package/src/components/code-mirror-engine.js +18 -5
- package/src/components/code-mirror-gramlot.js +85 -0
- package/src/components/code-mirror.js +3 -2
- package/src/components/drawing.js +43 -14
- package/src/components/editor-options.js +1 -1
- package/src/components/graphical-ranges.js +177 -0
- package/src/components/grid-footer.js +6 -1
- package/src/components/grid-styles.js +11 -2
- package/src/components/grid-tools.js +15 -7
- package/src/components/grid.js +69 -8
- package/src/components/inputs.js +93 -23
- package/src/components/jodit-engine.js +3 -1
- package/src/components/menus.js +83 -25
- package/src/components/numeric-range.js +39 -0
- package/src/components/selected-container.js +109 -63
- package/src/components/tab-bar.js +371 -0
- package/src/components/toolbar-icon-style.js +22 -0
- package/src/components/toolbar-overflow.js +74 -12
- package/src/components/tree.js +12 -3
- package/src/components/typst-preview.js +3 -3
- package/src/components/upload-blocks.js +88 -0
- package/src/components/upload-engine.js +21 -31
- package/src/components/uploader.js +168 -47
- package/src/gramlot.js +6 -3
- package/src/handlers/dom-handler.d.ts +2 -0
- package/src/handlers/dom-handler.js +9 -0
- package/src/handlers/rpc-handler.d.ts +1 -1
- package/src/handlers/rpc-handler.js +2 -0
- package/src/handlers/source-handler.d.ts +5 -3
- package/src/handlers/source-handler.js +31 -13
- package/src/icons.js +84 -0
- package/src/index-page-runtime.js +9 -2
- package/src/index-page-styles.js +1 -1
- package/src/index-theme.js +210 -3
- package/src/index.d.ts +5 -1
- package/src/index.js +5 -1
- package/src/libraries.js +1 -1
- package/src/renderer/gramlot-renderer.js +4 -1
- package/src/server/chat-attachments.js +139 -0
- package/src/server/chat.d.ts +31 -0
- package/src/server/chat.js +157 -0
- package/src/server/database-selectors.d.ts +6 -0
- package/src/server/database-selectors.js +13 -0
- package/src/server/gramlot-file-server.js +6 -1
- package/src/server/gramlot-server.d.ts +19 -3
- package/src/server/gramlot-server.js +144 -18
- package/src/server/index-page.d.ts +10 -0
- package/src/server/index-page.js +73 -8
- package/src/server/index.d.ts +1 -1
- package/src/server/index.js +1 -1
- package/src/server/page-base.js +4 -0
- package/src/server/page-store.d.ts +21 -0
- package/src/server/page-store.js +219 -0
- package/src/server/page.d.ts +6 -1
- package/src/server/page.js +5 -1
- package/src/server/store-recipe.js +102 -0
- package/src/server/toolbar-icon-name.d.ts +76 -0
- package/src/server/upload.d.ts +2 -0
- package/src/server/upload.js +36 -18
- package/src/server/visual-editor.js +4 -2
- package/src/tree-store.d.ts +5 -1
- package/src/tree-store.js +11 -2
- package/src/view/choice-focus.js +17 -0
- package/src/view/html.js +21 -1
- package/src/view/menu.js +9 -3
- package/src/visual-editor.js +6 -2
- package/themes/gramlot-base/theme.css +53 -28
- package/themes/gramlot-compact/theme.css +2 -0
- package/themes/gramlot-index/icons/applications.svg +4 -0
- package/themes/gramlot-index/icons/archive.svg +4 -0
- package/themes/gramlot-index/icons/attachment.svg +4 -0
- package/themes/gramlot-index/icons/book.svg +4 -0
- package/themes/gramlot-index/icons/bookmark.svg +4 -0
- package/themes/gramlot-index/icons/calendar.svg +4 -0
- package/themes/gramlot-index/icons/cancel.svg +4 -0
- package/themes/gramlot-index/icons/chart.svg +4 -0
- package/themes/gramlot-index/icons/chat.svg +4 -0
- package/themes/gramlot-index/icons/clock.svg +4 -0
- package/themes/gramlot-index/icons/code.svg +4 -0
- package/themes/gramlot-index/icons/collapse.svg +4 -0
- package/themes/gramlot-index/icons/columns.svg +4 -0
- package/themes/gramlot-index/icons/confirm.svg +4 -0
- package/themes/gramlot-index/icons/copy.svg +4 -0
- package/themes/gramlot-index/icons/cut.svg +4 -0
- package/themes/gramlot-index/icons/database.svg +4 -0
- package/themes/gramlot-index/icons/delete.svg +4 -0
- package/themes/gramlot-index/icons/detach.svg +4 -0
- package/themes/gramlot-index/icons/document.svg +4 -0
- package/themes/gramlot-index/icons/download.svg +4 -0
- package/themes/gramlot-index/icons/duplicate.svg +4 -0
- package/themes/gramlot-index/icons/edit.svg +4 -0
- package/themes/gramlot-index/icons/expand.svg +4 -0
- package/themes/gramlot-index/icons/export.svg +4 -0
- package/themes/gramlot-index/icons/eye.svg +4 -0
- package/themes/gramlot-index/icons/filter.svg +4 -0
- package/themes/gramlot-index/icons/first.svg +4 -0
- package/themes/gramlot-index/icons/folder.svg +4 -0
- package/themes/gramlot-index/icons/group.svg +4 -0
- package/themes/gramlot-index/icons/help.svg +4 -0
- package/themes/gramlot-index/icons/home.svg +4 -0
- package/themes/gramlot-index/icons/import.svg +4 -0
- package/themes/gramlot-index/icons/info.svg +4 -0
- package/themes/gramlot-index/icons/inspector.svg +4 -0
- package/themes/gramlot-index/icons/last.svg +4 -0
- package/themes/gramlot-index/icons/layers.svg +4 -0
- package/themes/gramlot-index/icons/link.svg +4 -0
- package/themes/gramlot-index/icons/list.svg +4 -0
- package/themes/gramlot-index/icons/lock.svg +4 -0
- package/themes/gramlot-index/icons/logout.svg +4 -0
- package/themes/gramlot-index/icons/navigation.svg +4 -0
- package/themes/gramlot-index/icons/new.svg +4 -0
- package/themes/gramlot-index/icons/next.svg +4 -0
- package/themes/gramlot-index/icons/open.svg +4 -0
- package/themes/gramlot-index/icons/palette.svg +4 -0
- package/themes/gramlot-index/icons/panel-bottom.svg +4 -0
- package/themes/gramlot-index/icons/panel-left.svg +4 -0
- package/themes/gramlot-index/icons/panel-right.svg +4 -0
- package/themes/gramlot-index/icons/panel-top.svg +4 -0
- package/themes/gramlot-index/icons/paste.svg +4 -0
- package/themes/gramlot-index/icons/pause.svg +4 -0
- package/themes/gramlot-index/icons/pin.svg +4 -0
- package/themes/gramlot-index/icons/play.svg +4 -0
- package/themes/gramlot-index/icons/previous.svg +4 -0
- package/themes/gramlot-index/icons/print.svg +4 -0
- package/themes/gramlot-index/icons/redo.svg +4 -0
- package/themes/gramlot-index/icons/refresh.svg +4 -0
- package/themes/gramlot-index/icons/save.svg +4 -0
- package/themes/gramlot-index/icons/search.svg +4 -0
- package/themes/gramlot-index/icons/send.svg +4 -0
- package/themes/gramlot-index/icons/settings.svg +4 -0
- package/themes/gramlot-index/icons/sort-ascending.svg +4 -0
- package/themes/gramlot-index/icons/sort-descending.svg +4 -0
- package/themes/gramlot-index/icons/stop.svg +4 -0
- package/themes/gramlot-index/icons/table.svg +4 -0
- package/themes/gramlot-index/icons/tree.svg +4 -0
- package/themes/gramlot-index/icons/undo.svg +4 -0
- package/themes/gramlot-index/icons/unlock.svg +4 -0
- package/themes/gramlot-index/icons/upload.svg +4 -0
- package/themes/gramlot-index/icons/user.svg +4 -0
- package/themes/gramlot-index/icons/warning.svg +4 -0
- package/themes/gramlot-index/icons/zoom-in.svg +4 -0
- package/themes/gramlot-index/icons/zoom-out.svg +4 -0
- package/themes/gramlot-index/icons.json +76 -0
- package/themes/gramlot-index/theme.css +21 -0
- package/themes/joanna/theme.css +2 -0
- package/themes/mela/theme.css +2 -0
- package/themes/mimi/theme.css +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gramlot/gramlot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Declarative HTML/SVG interfaces with live data binding, authored in JavaScript or Python.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"@codemirror/lang-json": "^6.0.2",
|
|
25
25
|
"@codemirror/lang-markdown": "^6.5.2",
|
|
26
26
|
"@codemirror/lang-python": "^6.2.1",
|
|
27
|
+
"@codemirror/lang-rust": "^6.0.2",
|
|
27
28
|
"@codemirror/lang-sql": "^6.10.0",
|
|
28
29
|
"@codemirror/lang-xml": "^6.1.0",
|
|
29
30
|
"@codemirror/language": "^6.13.1",
|
|
@@ -72,6 +73,7 @@
|
|
|
72
73
|
"./build-plugins": "./src/build-plugins.js",
|
|
73
74
|
"./markdown": "./src/markdown.js",
|
|
74
75
|
"./page": "./src/server/page.js",
|
|
76
|
+
"./db": "./src/server/database-selectors.js",
|
|
75
77
|
"./gramlot-server": "./src/server/gramlot-server.js",
|
|
76
78
|
"./themes/*": "./themes/*",
|
|
77
79
|
"./assets/branding/*": "./assets/branding/*",
|
|
@@ -37,7 +37,7 @@ export class AskDialog {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/** Show the dialog of `specification`; resolves with the values of its fields, or null when cancelled. */
|
|
40
|
-
show(binding, specification, parameters, title = 'Parameters') {
|
|
40
|
+
show(binding, specification, parameters, title = 'Parameters', {interpolate = false} = {}) {
|
|
41
41
|
const spec = typeof specification === 'string' ? {msg: specification, title} : specification;
|
|
42
42
|
if (!spec || typeof spec !== 'object' || Array.isArray(spec)) throw new TypeError('ask requires text or a parameter description');
|
|
43
43
|
for (const key of Object.keys(spec)) {
|
|
@@ -86,8 +86,22 @@ export class AskDialog {
|
|
|
86
86
|
connect_oncancel: `${group}.cancel`, connect_onclose: `${group}.cancel`,
|
|
87
87
|
class: 'gramlot-ask', 'aria-labelledby': `${id}_title`,
|
|
88
88
|
style: 'border:1px solid #aab4c2;border-radius:8px;padding:16px;max-width:32rem;width:calc(100% - 48px);font:inherit;'});
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
const dialogText = (key, text) => {
|
|
90
|
+
if (!interpolate || typeof text !== 'string' || /^[=^]/.test(text)) return text;
|
|
91
|
+
let substituted = false;
|
|
92
|
+
const formatted = text.replace(/\{([A-Za-z_]\w*)\}/g, (token, name) => {
|
|
93
|
+
if (!Object.hasOwn(parameters, name)) return token;
|
|
94
|
+
substituted = true;
|
|
95
|
+
return String(parameters[name] ?? '');
|
|
96
|
+
});
|
|
97
|
+
if (!substituted) return text;
|
|
98
|
+
// Bind the result as Data so argument values are always displayed as text.
|
|
99
|
+
const path = `.ask-text.${key}`;
|
|
100
|
+
app.data.setItem(id + path, formatted);
|
|
101
|
+
return '^' + path;
|
|
102
|
+
};
|
|
103
|
+
dialog.h2(dialogText('title', spec.title ?? title), {id: `${id}_title`, style: 'font-size:1.1em;margin:0 0 12px;'});
|
|
104
|
+
if (spec.msg) dialog.p(dialogText('msg', spec.msg));
|
|
91
105
|
const form = dialog.form({request: id, connect_onsubmit: `${group}.confirm`});
|
|
92
106
|
for (const field of fields) {
|
|
93
107
|
form.dataSetter({destination_path: `.${field.name}`,
|
package/src/binding/providers.js
CHANGED
|
@@ -182,7 +182,7 @@ export class Provider {
|
|
|
182
182
|
const ask = node.getAttr('_ask');
|
|
183
183
|
const askDialog = this.binding.runtime.askDialog;
|
|
184
184
|
if (ask && !trigger.askDone && askDialog.required(this.binding, ask, kwargs, '_ask')) {
|
|
185
|
-
return askDialog.show(this.binding, ask, kwargs, node.getAttr('_ask_title') ?? 'Warning').then(result => {
|
|
185
|
+
return askDialog.show(this.binding, ask, kwargs, node.getAttr('_ask_title') ?? 'Warning', {interpolate: true}).then(result => {
|
|
186
186
|
if (this.binding.closed) return;
|
|
187
187
|
if (result === null) {
|
|
188
188
|
const cancel = node.getAttr('_ask_onCancel');
|
package/src/binding/runtime.js
CHANGED
|
@@ -763,7 +763,7 @@ export class NodeBinding {
|
|
|
763
763
|
|
|
764
764
|
/**
|
|
765
765
|
* Send `request`, the request of this node in flight (NodeRequests), through `gramlot.rpc.call` as
|
|
766
|
-
* `contentType`;
|
|
766
|
+
* `contentType`; returns the envelope for Source and the value for Data. The close of the node aborts it until the answer arrives, also
|
|
767
767
|
* when the answer arrived and was not yet received here: the call then rejects with the abort reason.
|
|
768
768
|
* Used by `dataRpc`, `dataRemote` and `remoteSource`.
|
|
769
769
|
*/
|
|
@@ -771,8 +771,11 @@ export class NodeBinding {
|
|
|
771
771
|
const {controller} = request;
|
|
772
772
|
const release = this.track(() => controller.abort());
|
|
773
773
|
try {
|
|
774
|
-
const
|
|
775
|
-
|
|
774
|
+
const rpc = this.runtime.gramlot.rpc;
|
|
775
|
+
const options = {signal: controller.signal};
|
|
776
|
+
const value = contentType === 'source'
|
|
777
|
+
? await rpc.callEnvelope(contentType, request.method, request.params, options)
|
|
778
|
+
: await rpc.call(contentType, request.method, request.params, options);
|
|
776
779
|
if (controller.signal.aborted) throw controller.signal.reason;
|
|
777
780
|
return value;
|
|
778
781
|
} finally {
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// Generated from assets/icons/chart.svg.
|
|
2
|
+
export default "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgc3R5bGU9ImNvbG9yLXNjaGVtZTpsaWdodCBkYXJrIgogICAgIGZpbGw9Im5vbmUiIHN0cm9rZT0iQnV0dG9uVGV4dCIgc3Ryb2tlLXdpZHRoPSIxLjciIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCI+CiAgPHBhdGggZD0iTTQgM3YxN2gxN004IDE2di01TTEzIDE2VjZNMTggMTZ2LTgiLz4KPC9zdmc+Cg==";
|
|
@@ -24,9 +24,11 @@ export class GramlotBuilder extends HtmlBuilder {
|
|
|
24
24
|
/** The dialect name, `'gramlot'`. */
|
|
25
25
|
static _name: string;
|
|
26
26
|
static containers: string[];
|
|
27
|
+
codeMirrorWithOptions(parent: SourceBag | SourceBagNode, options: Parameters<typeof import('../components/editor-options.js').codeMirrorWithOptions>[1]): void;
|
|
28
|
+
VisualEditor(parent: SourceBag | SourceBagNode, options: ConstructorParameters<typeof import('../server/visual-editor.js').VisualEditor>[1]): void;
|
|
27
29
|
/** Build an ordinary framePane containing center.grid; requires layout and grid. */
|
|
28
30
|
frameGrid(parent: SourceBag | SourceBagNode, options: SourceAttributes & {
|
|
29
|
-
storepath: string; rowMode: 'values' | 'attributes'; structpath?: string; searchOn?: boolean | string; searchHelp?: boolean; chart?: boolean | string;
|
|
31
|
+
storepath: string; rowMode: 'values' | 'attributes'; structpath?: string; searchOn?: boolean | string; searchHelp?: boolean; addrow?: boolean; addrow_label?: string; delrow?: boolean | 'row'; delrow_label?: string; chart?: boolean | string;
|
|
30
32
|
}): SourceBagNode;
|
|
31
33
|
/** Tag prefixes of the parent dialects, from the names of the classes above `GramlotBuilder`. */
|
|
32
34
|
static get dialectPrefixes(): string[];
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
+
import {codeMirrorWithOptions} from '../components/editor-options.js';
|
|
8
|
+
import {VisualEditor} from '../server/visual-editor.js';
|
|
7
9
|
import buttons from '../components/buttons.js';
|
|
8
10
|
import {ComponentCollection} from '../components/registry.js';
|
|
9
11
|
import {Bag} from '@genrojs/bag';
|
|
@@ -102,17 +104,25 @@ function excludedAttribute(attrs) {
|
|
|
102
104
|
/** Gramlot vocabulary and inert authoring on the shared builder grammar. */
|
|
103
105
|
export class GramlotBuilder extends HtmlBuilder {
|
|
104
106
|
static _name = 'gramlot';
|
|
105
|
-
static containers = ['frameGrid'];
|
|
107
|
+
static containers = ['frameGrid', 'codeMirrorWithOptions', 'VisualEditor'];
|
|
106
108
|
static _sourceClass = GramlotBuilderBag;
|
|
107
109
|
// Composed on the inherited HtmlBuilder grammar; its data-elements replace Builder's.
|
|
108
110
|
static { this.defineGrammar(BINDING); }
|
|
109
111
|
static { this.defineGrammar(WEBCOMPONENT); }
|
|
110
112
|
static { this.defineGrammar(buttons.toDocument()); }
|
|
111
113
|
|
|
114
|
+
codeMirrorWithOptions(parent, options) {
|
|
115
|
+
codeMirrorWithOptions(parent, options);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
VisualEditor(parent, options) {
|
|
119
|
+
return new VisualEditor(parent, options);
|
|
120
|
+
}
|
|
121
|
+
|
|
112
122
|
/** Compose real Source nodes; frame/grid/menu retain their existing runtime owners. */
|
|
113
123
|
frameGrid(parent, {storepath, rowMode, structpath, searchOn = false, searchHelp = false, chart = false,
|
|
114
|
-
export: exportRows = false, printRows = false, advancedTools = false, addrow = false, addrow_defaults = null,
|
|
115
|
-
duprow = false, delrow = false, gridsemaphore = false, ...attrs} = {}) {
|
|
124
|
+
export: exportRows = false, printRows = false, advancedTools = false, addrow = false, addrow_defaults = null, addrow_label = null,
|
|
125
|
+
duprow = false, delrow = false, delrow_label = null, gridsemaphore = false, ...attrs} = {}) {
|
|
116
126
|
for (const tag of ['framePane', 'grid']) {
|
|
117
127
|
if (!this.schemaTag(tag)) throw new TypeError(`frameGrid requires the ${tag} collection`);
|
|
118
128
|
}
|
|
@@ -130,9 +140,10 @@ export class GramlotBuilder extends HtmlBuilder {
|
|
|
130
140
|
if (typeof chart === 'string') chartOptions.chartType = chart;
|
|
131
141
|
} else if (Object.keys(chartOptions).length) throw new TypeError('chart_* options require chart');
|
|
132
142
|
const exportFormats = frameGridExportFormats(exportRows);
|
|
133
|
-
for (const [name, value] of Object.entries({printRows, advancedTools, addrow, duprow,
|
|
143
|
+
for (const [name, value] of Object.entries({printRows, advancedTools, addrow, duprow, gridsemaphore})) {
|
|
134
144
|
if (typeof value !== 'boolean') throw new TypeError(`frameGrid ${name} requires a boolean`);
|
|
135
145
|
}
|
|
146
|
+
if (typeof delrow !== 'boolean' && delrow !== 'row') throw new TypeError('frameGrid delrow requires a boolean or row');
|
|
136
147
|
if (addrow_defaults !== null && (!addrow || typeof addrow_defaults !== 'object' || Array.isArray(addrow_defaults))) {
|
|
137
148
|
throw new TypeError('addrow_defaults requires addrow and a mapping');
|
|
138
149
|
}
|
|
@@ -145,6 +156,10 @@ export class GramlotBuilder extends HtmlBuilder {
|
|
|
145
156
|
node_label: 'grid', frameTarget: true, height: '100%', width: '100%',
|
|
146
157
|
// Legacy frameGrid default: the current row identity at .selectedId of the frame's own datapath.
|
|
147
158
|
...(frameAttrs.datapath ? {selectedId: '^.selectedId'} : {}), ...routed};
|
|
159
|
+
if (delrow === 'row') {
|
|
160
|
+
gridAttrs.delrow = delrow;
|
|
161
|
+
if (delrow_label !== null) gridAttrs.delrow_label = delrow_label;
|
|
162
|
+
}
|
|
148
163
|
if (chart !== false) gridAttrs.nodeId = randomId();
|
|
149
164
|
this.validateNodeValues('grid', null, gridAttrs);
|
|
150
165
|
if (searchOn !== false) this.validateNodeValues('searchBox', null, {searchOn, searchHelp});
|
|
@@ -152,24 +167,26 @@ export class GramlotBuilder extends HtmlBuilder {
|
|
|
152
167
|
frame.center.grid(gridAttrs);
|
|
153
168
|
const bar = frame.top.menu({presentation:'bar', node_label:'bar', aria_label:'Grid toolbar', class:'gramlot-grid-toolbar'});
|
|
154
169
|
if (searchOn !== false) bar.menuline({group:true, node_label:'search', class:'gramlot-grid-search'}).searchBox({searchOn, searchHelp});
|
|
155
|
-
if (addrow) bar.menuline({command:'grid:addrow', node_label:'addrow',
|
|
170
|
+
if (addrow) bar.menuline({command:'grid:addrow', node_label:'addrow', class:'button--standard',
|
|
171
|
+
...(addrow_label === null ? {} : {caption:addrow_label}), ...(addrow_defaults === null ? {} : {parameters:{defaults:addrow_defaults}})});
|
|
156
172
|
if (duprow) bar.menuline({command:'grid:duprow', node_label:'duprow'});
|
|
157
|
-
if (delrow) bar.menuline({command:'grid:delrow', node_label:'delrow'
|
|
173
|
+
if (delrow === true) bar.menuline({command:'grid:delrow', node_label:'delrow', disabled:true, class:'button--standard',
|
|
174
|
+
...(delrow_label === null ? {} : {caption:delrow_label})});
|
|
158
175
|
const exportMenu = parent => {
|
|
159
|
-
const menu = parent.menuline({caption:'Export', icon:'
|
|
176
|
+
const menu = parent.menuline({caption:'Export', icon:'download', labelPosition:'tooltip', node_label:'export'}).menu();
|
|
160
177
|
for (const name of exportFormats) menu.menuline({command:'grid:export', caption:EXPORT_FORMATS[name], parameters:{format:name}, node_label:name});
|
|
161
178
|
};
|
|
162
179
|
if (exportFormats.length) exportMenu(bar);
|
|
163
180
|
if (printRows) bar.menuline({command:'grid:printRows', node_label:'printRows'});
|
|
164
181
|
if (advancedTools) {
|
|
165
|
-
const tools = bar.menuline({caption:'Advanced tools', icon:'
|
|
182
|
+
const tools = bar.menuline({caption:'Advanced tools', icon:'list', labelPosition:'tooltip', node_label:'advancedTools'}).menu();
|
|
166
183
|
tools.menuline({command:'grid:lineNumbers', node_label:'lineNumbers'});
|
|
167
184
|
if (exportFormats.length) exportMenu(tools);
|
|
168
185
|
if (printRows) tools.menuline({command:'grid:printRows', node_label:'printRows'});
|
|
169
186
|
}
|
|
170
187
|
if (gridsemaphore) bar.menuline({group:true, node_label:'semaphore'}).editingStatus();
|
|
171
188
|
if (chart !== false) {
|
|
172
|
-
bar.menuline({caption:'Chart', icon:'
|
|
189
|
+
bar.menuline({caption:'Chart', icon:'chart', labelPosition:'tooltip', node_label:'chart', action:"this.SET('._chart.open',true)"});
|
|
173
190
|
const window = frame.center.floatingPane({title:'Chart', open:'^._chart.open', width:'820px', height:'560px',
|
|
174
191
|
movable:true, resizable:true, maximizable:true, node_label:'chartWindow'});
|
|
175
192
|
window.frame.center.chartPane({storepath,rowMode,gridId:gridAttrs.nodeId,configpath:'._chart',
|
package/src/builder/source.js
CHANGED
|
@@ -204,6 +204,15 @@ export function stringHash(text) {
|
|
|
204
204
|
return Math.abs(hash);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
// Resolver captions are data even when their text starts with a pointer symbol.
|
|
208
|
+
export const resolverMenuLines = new WeakSet();
|
|
209
|
+
|
|
210
|
+
function literalMenuField(node, name, value) {
|
|
211
|
+
if (node.nodeTag !== 'menuline') return false;
|
|
212
|
+
if (name === 'caption') return resolverMenuLines.has(node) || typeof value !== 'string' || !value.startsWith('^');
|
|
213
|
+
return ['tooltip','command'].includes(name);
|
|
214
|
+
}
|
|
215
|
+
|
|
207
216
|
/** The nearest node of `bag` whose `childname` is `name`: direct children first, then unnamed children's descendants. */
|
|
208
217
|
function namedChild(bag, name) {
|
|
209
218
|
const nodes = bag.getNodes();
|
|
@@ -288,7 +297,7 @@ export class GramlotBuilderBagNode extends SourceBagNode {
|
|
|
288
297
|
frameRegion(region) {
|
|
289
298
|
if (this.nodeTag !== 'framePane') throw new TypeError('Region accessors require framePane');
|
|
290
299
|
const existing = this.value instanceof SourceBag
|
|
291
|
-
? this.value.getNodes().find(child => child.getAttr('region') === region) : null;
|
|
300
|
+
? this.value.getNodes().find(child => child.nodeTag === 'contentPane' && child.getAttr('region') === region) : null;
|
|
292
301
|
if (existing) return this.builder.wrapSource(existing);
|
|
293
302
|
const attrs = {region, node_label: region};
|
|
294
303
|
if (region !== 'center') Object.assign(attrs, {display: 'flex', flex_direction: ['top', 'bottom'].includes(region) ? 'column' : 'row'});
|
|
@@ -405,7 +414,7 @@ export class GramlotBuilderBagNode extends SourceBagNode {
|
|
|
405
414
|
pointers() {
|
|
406
415
|
const datapath = this.getAttr('datapath');
|
|
407
416
|
const dependencies = pointerTransform(datapath) ? pointerDependencies(this, datapath) : new Set();
|
|
408
|
-
const result = super.pointers().filter(([name, pointer]) => !(this
|
|
417
|
+
const result = super.pointers().filter(([name, pointer]) => !literalMenuField(this, name, pointer) && !dependencies.has(name) && !this.#isPathAttribute(name, pointer))
|
|
409
418
|
.map(([name, pointer]) => [name, pointerTransform(pointer)?.pointer ?? pointer]);
|
|
410
419
|
for (const name of dependencies) {
|
|
411
420
|
const value = this.getAttr(name);
|
|
@@ -422,7 +431,7 @@ export class GramlotBuilderBagNode extends SourceBagNode {
|
|
|
422
431
|
runtimeToEvaluate() {
|
|
423
432
|
const items = super.runtimeToEvaluate();
|
|
424
433
|
for (const [name, value] of items) {
|
|
425
|
-
if (this
|
|
434
|
+
if (literalMenuField(this, name, value)) {
|
|
426
435
|
items.set(name, new BagCbResolver(() => value));
|
|
427
436
|
continue;
|
|
428
437
|
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import {fromTytx, fromTytxIter} from '@genrojs/tytx';
|
|
2
|
+
import {Bag} from '@genrojs/bag';
|
|
3
|
+
import {SourceBagNode, sourceTarget} from '@genrojs/builders';
|
|
4
|
+
import {GramlotBuilderBag} from './source.js';
|
|
5
|
+
|
|
6
|
+
// Decode a scalar using the registered TYTX suffix, preserving unsuffixed XML text.
|
|
7
|
+
function scalar(text) {
|
|
8
|
+
const [value] = fromTytxIter([text]);
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function isCompound(value) {
|
|
13
|
+
if (Array.isArray(value)) return true;
|
|
14
|
+
if (!value || typeof value !== 'object') return false;
|
|
15
|
+
const prototype = Object.getPrototypeOf(value);
|
|
16
|
+
return prototype === Object.prototype || prototype === null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function attributeValue(text) {
|
|
20
|
+
if (!text.endsWith('::JS')) return scalar(text);
|
|
21
|
+
const value = fromTytx(text);
|
|
22
|
+
if (!isCompound(value)) throw new TypeError('A ::JS recipe attribute requires a JSON object or array');
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The element children of `element`; text other than whitespace is an error. */
|
|
27
|
+
function elementChildren(element, where) {
|
|
28
|
+
const children = [];
|
|
29
|
+
for (const child of element.childNodes) {
|
|
30
|
+
if (child.nodeType === 1) children.push(child);
|
|
31
|
+
else if ((child.nodeType === 3 || child.nodeType === 4) && child.data.trim()) {
|
|
32
|
+
throw new TypeError(`Unexpected text inside ${where}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return children;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A builder container (a method that writes Source, such as frameGrid) runs on `parent` with the
|
|
40
|
+
* attributes, as `parent.frameGrid(attrs)` does in JS. Each child element names an accessor of the
|
|
41
|
+
* returned node (`grid`, `top`, `bottom`, `toolbar`); its own children go into that node.
|
|
42
|
+
*/
|
|
43
|
+
function appendContainer(element, method, attrs, parent, builder) {
|
|
44
|
+
const name = element.tagName;
|
|
45
|
+
const result = builder[method](builder.wrapSource(parent), attrs);
|
|
46
|
+
for (const accessor of elementChildren(element, `<${name}>`)) {
|
|
47
|
+
if (accessor.namespaceURI || accessor.attributes.length) {
|
|
48
|
+
throw new TypeError(`<${accessor.tagName}> inside <${name}> names an accessor and takes no attributes`);
|
|
49
|
+
}
|
|
50
|
+
if (result === undefined) throw new TypeError(`<${name}> does not accept accessors`);
|
|
51
|
+
const target = sourceTarget(result[accessor.tagName]);
|
|
52
|
+
if (!(target instanceof SourceBagNode)) {
|
|
53
|
+
throw new TypeError(`<${name}> has no accessor <${accessor.tagName}>`);
|
|
54
|
+
}
|
|
55
|
+
for (const child of elementChildren(accessor, `<${name}><${accessor.tagName}>`)) {
|
|
56
|
+
appendElement(child, target, target.builder);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function appendElement(element, parent, builder) {
|
|
62
|
+
if (element.namespaceURI) throw new TypeError(`Unknown recipe element <${element.tagName}>`);
|
|
63
|
+
const tag = builder.schemaTag(element.tagName);
|
|
64
|
+
const attrs = Object.fromEntries(Array.from(element.attributes, attr => [attr.name, attributeValue(attr.value)]));
|
|
65
|
+
if (!tag) {
|
|
66
|
+
const method = builder.containerMethod(element.tagName);
|
|
67
|
+
if (!method) throw new TypeError(`Unknown recipe element <${element.tagName}>`);
|
|
68
|
+
appendContainer(element, method, attrs, parent, builder);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const children = [];
|
|
72
|
+
let text = '';
|
|
73
|
+
for (const child of element.childNodes) {
|
|
74
|
+
if (child.nodeType === 1) children.push(child);
|
|
75
|
+
else if (child.nodeType === 3 || child.nodeType === 4) {
|
|
76
|
+
if (!children.length) text += child.data;
|
|
77
|
+
else if (child.data.trim()) throw new TypeError(`Unexpected text after a child of <${tag}>`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Builder preserves a scalar prefix when the first child promotes its parent to a branch.
|
|
81
|
+
const value = text.length && (!children.length || text.trim()) ? scalar(text) : null;
|
|
82
|
+
const node = parent instanceof GramlotBuilderBag
|
|
83
|
+
? builder.bagCall(parent, tag, value, attrs)
|
|
84
|
+
: builder.commandOnNode(parent, tag, value, attrs);
|
|
85
|
+
for (const child of children) appendElement(child, node, node.builder);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function recipeSections(xml, DOMParser) {
|
|
89
|
+
if (typeof xml !== 'string') throw new TypeError('XML Source requires a document string');
|
|
90
|
+
const document = new DOMParser().parseFromString(xml, 'application/xml');
|
|
91
|
+
const root = document.documentElement;
|
|
92
|
+
if (document.doctype || root.namespaceURI || root.tagName !== 'gramlot' ||
|
|
93
|
+
document.getElementsByTagNameNS('*', 'parsererror').length) {
|
|
94
|
+
throw new TypeError('Expected a well-formed Gramlot XML Recipe with a <gramlot> root');
|
|
95
|
+
}
|
|
96
|
+
const sections = name => Array.from(root.children).filter(child => !child.namespaceURI && child.tagName === name);
|
|
97
|
+
const mains = sections('main'), data = sections('data');
|
|
98
|
+
if (mains.length !== 1) throw new TypeError('Gramlot XML Recipe requires one direct <main> section');
|
|
99
|
+
if (data.length > 1) throw new TypeError('Gramlot XML Recipe accepts one direct <data> section');
|
|
100
|
+
return {main:mains[0], data:data[0]};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function readSource(main, builder) {
|
|
104
|
+
const source = new GramlotBuilderBag(null, builder);
|
|
105
|
+
source.setBackref();
|
|
106
|
+
for (const child of main.childNodes) {
|
|
107
|
+
if (child.nodeType === 1) appendElement(child, source, builder);
|
|
108
|
+
else if ((child.nodeType === 3 || child.nodeType === 4) && child.data.trim()) {
|
|
109
|
+
throw new TypeError('Expected Source elements inside <main>');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return source;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** A remote fragment contributes only Source. Initial Data belongs to the page document. */
|
|
116
|
+
export function readXmlRecipe(xml, builder, DOMParser) {
|
|
117
|
+
return readSource(recipeSections(xml, DOMParser).main, builder);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function readData(element) {
|
|
121
|
+
// Use Bag's XML label, attribute and nested Bag conventions. Recipe leaf values
|
|
122
|
+
// and scalar attributes use the same TYTX suffixes as Source attributes.
|
|
123
|
+
const bag = Bag.fromXml(element.outerHTML);
|
|
124
|
+
function decode(branch) {
|
|
125
|
+
for (const node of branch.getNodes()) {
|
|
126
|
+
const attrs = Object.fromEntries(Object.entries(node.attr ?? {}).map(([key, value]) =>
|
|
127
|
+
[key, typeof value === 'string' ? scalar(value) : value]));
|
|
128
|
+
node.setAttr(attrs, false, false, false);
|
|
129
|
+
if (node.staticValue instanceof Bag) decode(node.staticValue);
|
|
130
|
+
else if (typeof node.staticValue === 'string') node.setValue(scalar(node.staticValue), false);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
decode(bag);
|
|
134
|
+
return bag;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Decode a complete startup or editor document before applying any page state. */
|
|
138
|
+
export function readXmlRecipeDocument(xml, builder, DOMParser) {
|
|
139
|
+
const {main, data} = recipeSections(xml, DOMParser);
|
|
140
|
+
return {
|
|
141
|
+
source:readSource(main, builder),
|
|
142
|
+
data:data ? readData(data) : null,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const textExtensions = [
|
|
2
|
+
'txt', 'md', 'csv', 'json', 'py', 'js', 'ts', 'jsx', 'tsx', 'html', 'css',
|
|
3
|
+
'sql', 'yaml', 'yml', 'xml', 'sh', 'toml', 'log',
|
|
4
|
+
];
|
|
5
|
+
|
|
6
|
+
export const fileTypes = {
|
|
7
|
+
png: 'image/png',
|
|
8
|
+
jpg: 'image/jpeg',
|
|
9
|
+
jpeg: 'image/jpeg',
|
|
10
|
+
webp: 'image/webp',
|
|
11
|
+
pdf: 'application/pdf',
|
|
12
|
+
...Object.fromEntries(textExtensions.map(extension => [extension, 'text/plain'])),
|
|
13
|
+
};
|
package/src/chat.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
import {fileTypes} from './chat-file-types.js';
|
|
1
2
|
/** Shared chat behavior. Pages delegate their named Logic methods here. */
|
|
2
3
|
import {Bag} from '@genrojs/bag';
|
|
3
4
|
import {SourceBag, sourceTarget} from '@genrojs/builders';
|
|
4
5
|
import {GramlotBuilderBag} from './builder/source.js';
|
|
5
6
|
import {GramlotBuilder} from './builder/gramlot-builder.js';
|
|
6
7
|
import {fromTytx, toTytx} from '@genrojs/tytx';
|
|
8
|
+
import {sendUploadBlocks} from './components/upload-blocks.js';
|
|
7
9
|
import {randomId} from './random-id.js';
|
|
8
10
|
|
|
9
11
|
const LABEL = /^m_[a-f0-9]+$/;
|
|
10
12
|
|
|
11
13
|
/** Reconcile message Source, preserving older fragments and their interactive Data. */
|
|
12
14
|
export function chatRender(page, node, {messages}) {
|
|
15
|
+
// A suspended binder removes its local snapshot until the page reconnects.
|
|
16
|
+
if (messages == null && page._pageStore?.reconnecting) return;
|
|
13
17
|
if (!(messages instanceof Bag) || messages instanceof SourceBag) throw new TypeError('Chat messages require a Data Bag');
|
|
14
18
|
const target = node.parentNode;
|
|
15
19
|
const viewport = page.dom.getDomNode(target);
|
|
@@ -79,7 +83,11 @@ function send(node, action, text=null) {
|
|
|
79
83
|
const id=randomId();
|
|
80
84
|
node.SET('.requestId',id); node.SET('.pending',true); node.SET('.error','');
|
|
81
85
|
// One atomic Data write; the normal binder carries it to the PageStore recipe.
|
|
82
|
-
|
|
86
|
+
const attachments=new Bag();
|
|
87
|
+
if(action === 'send') for(const file of node.getRelativeData('.attachments').getNodes()) {
|
|
88
|
+
attachments.setItem(file.label,new Bag({ref:file.staticValue.getItem('ref')}));
|
|
89
|
+
}
|
|
90
|
+
node.SET('.conversation.request',new Bag({id,action,text,attachments}));
|
|
83
91
|
}
|
|
84
92
|
export function chatSend(page,node) {
|
|
85
93
|
const text=node.getRelativeData('.draft');
|
|
@@ -133,16 +141,6 @@ export function chatResize(page,node) {
|
|
|
133
141
|
layout.schedule();
|
|
134
142
|
}
|
|
135
143
|
|
|
136
|
-
const textExtensions=['txt','md','csv','json','py','js','ts','jsx','tsx','html','css','sql','yaml','yml','xml','sh','toml','log'];
|
|
137
|
-
const fileTypes={png:'image/png',jpg:'image/jpeg',jpeg:'image/jpeg',webp:'image/webp',pdf:'application/pdf',...Object.fromEntries(textExtensions.map(ext=>[ext,'text/plain']))};
|
|
138
|
-
function readFile(file,win) {
|
|
139
|
-
return new Promise((resolve,reject)=>{
|
|
140
|
-
const reader=new win.FileReader();
|
|
141
|
-
reader.onload=()=>resolve(reader.result.slice(reader.result.indexOf(',')+1));
|
|
142
|
-
reader.onerror=()=>reject(new Error('Could not read the selected file.'));
|
|
143
|
-
reader.readAsDataURL(file);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
144
|
export async function chatPickAttachments(page,node) {
|
|
147
145
|
if(node.getRelativeData('.pending')||node.getRelativeData('.picking'))return;
|
|
148
146
|
const doc=page.dom.getDomNode(node.parentNode).ownerDocument;
|
|
@@ -150,7 +148,8 @@ export async function chatPickAttachments(page,node) {
|
|
|
150
148
|
input.accept=Object.keys(fileTypes).map(ext=>'.'+ext).join(',');
|
|
151
149
|
input.style.display='none';doc.body.append(input);
|
|
152
150
|
let active=true,finish;
|
|
153
|
-
const
|
|
151
|
+
const controller=new AbortController();
|
|
152
|
+
const release=page.src.renderer.onDispose(node.parentNode,()=>{active=false;controller.abort();input.remove();finish([]);});
|
|
154
153
|
node.SET('.picking',true);node.SET('.error','');
|
|
155
154
|
try {
|
|
156
155
|
const files=await new Promise(resolve=>{
|
|
@@ -162,20 +161,19 @@ export async function chatPickAttachments(page,node) {
|
|
|
162
161
|
if(!active||!files.length)return;
|
|
163
162
|
const attachments=fromTytx(toTytx(node.getRelativeData('.attachments')));
|
|
164
163
|
if(attachments.length+files.length>5)throw new Error('Choose at most 5 files.');
|
|
165
|
-
let total=attachments.getNodes().reduce((n,file)=>n+file.staticValue.getItem('size'),0);
|
|
166
164
|
for(const file of files) {
|
|
167
165
|
const mediaType=fileTypes[file.name.split('.').pop().toLowerCase()];
|
|
168
|
-
if(!mediaType)throw new Error('
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
166
|
+
if(!mediaType || !file.size)throw new Error('Choose a nonempty PNG, JPEG, WebP, PDF or UTF-8 text file.');
|
|
167
|
+
const grant=await page.rpc.call('upload','prepare',{operation:'chat_files.receive',
|
|
168
|
+
metadata:{name:file.name,mediaType,size:file.size,fields:{},context:{}}});
|
|
169
|
+
try {
|
|
170
|
+
const outcome=await sendUploadBlocks(page,file,grant,{window:doc.defaultView,signal:controller.signal});
|
|
171
|
+
if(outcome.state !== 'completed')throw new Error('Could not save the attachment.');
|
|
172
|
+
attachments.setItem('a_'+randomId(),new Bag(outcome.result));
|
|
173
|
+
} catch(error) {
|
|
174
|
+
await page.rpc.call('upload','cancel',{transferId:grant.transferId});
|
|
175
|
+
throw error;
|
|
177
176
|
}
|
|
178
|
-
attachments.setItem('a_'+randomId(),new Bag({name:file.name,mediaType,size:file.size,data}));
|
|
179
177
|
}
|
|
180
178
|
if(active)node.SET('.attachments',attachments);
|
|
181
179
|
} catch(error) {if(active)node.SET('.error',error.message);}
|
|
@@ -192,10 +190,10 @@ export function chatRenderAttachments(page,node,{attachments}) {
|
|
|
192
190
|
const file=attachment.staticValue;
|
|
193
191
|
const item=builder.root.div({node_label:attachment.label,display:'flex',align_items:'center',gap:'6px',
|
|
194
192
|
padding:'4px 8px',border:'1px solid var(--gramlot-border-control,#aaa)',border_radius:'10px',flex_shrink:0});
|
|
195
|
-
if(file.getItem('mediaType').startsWith('image/')) item.img({src:
|
|
193
|
+
if(file.getItem('mediaType').startsWith('image/')) item.img({src:file.getItem('url'),
|
|
196
194
|
alt:'Attachment preview',width:'36px',height:'36px',object_fit:'cover',border_radius:'6px'});
|
|
197
195
|
item.span('=='+JSON.stringify(file.getItem('name')),{font_size:'12px',max_width:'180px',overflow:'hidden',text_overflow:'ellipsis',white_space:'nowrap'});
|
|
198
|
-
item.button({icon:'
|
|
196
|
+
item.button({icon:'cancel','aria-label':'Remove '+file.getItem('name'),disabled:'^.pending',class:'button--quiet'})
|
|
199
197
|
.dataController({func:'chatRemoveAttachment',attachment_id:attachment.label});
|
|
200
198
|
}
|
|
201
199
|
const prepared=page.src.prepareSource(builder.source);
|
package/src/commands.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Command metadata authored by a collection and isolated per page instance. */
|
|
2
|
-
export interface CommandDefinition {label:string; publish:string; icon?:string;
|
|
2
|
+
export interface CommandDefinition {label:string; publish:string; icon?:string; tooltip?:string;}
|
|
3
3
|
export interface CommandGroupMetadata {author?:string; description?:string;}
|
|
4
4
|
export class CommandRegistry {
|
|
5
5
|
registerGroup(namespace:string, metadata?:CommandGroupMetadata): Readonly<{register(name:string,definition:CommandDefinition):void}>;
|
package/src/commands.js
CHANGED
|
@@ -17,7 +17,7 @@ export class CommandRegistry {
|
|
|
17
17
|
if (commands.has(name)) throw new Error(`Duplicate command: ${namespace}:${name}`);
|
|
18
18
|
if (!definition || typeof definition !== 'object' || Array.isArray(definition) ||
|
|
19
19
|
!Object.hasOwn(definition, 'label') || !Object.hasOwn(definition, 'publish') ||
|
|
20
|
-
Object.keys(definition).some(key => !['label', 'publish', 'icon', '
|
|
20
|
+
Object.keys(definition).some(key => !['label', 'publish', 'icon', 'tooltip'].includes(key)) ||
|
|
21
21
|
Object.values(definition).some(value => typeof value !== 'string')) {
|
|
22
22
|
throw new TypeError(`Invalid command definition: ${namespace}:${name}`);
|
|
23
23
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import {renderIcon} from '../icons.js';
|
|
1
2
|
/** Parent-owned regions. Layout changes never move or recreate slotted content. */
|
|
3
|
+
import {labelboxContent} from '../view/labelbox.js';
|
|
4
|
+
import {toolbarIconParameters, projectToolbarIconStyle} from './toolbar-icon-style.js';
|
|
2
5
|
import {defineComponent} from './registry.js';
|
|
3
6
|
import {Container} from './container.js';
|
|
4
7
|
import {WindowSurface} from './window-surface.js';
|
|
@@ -194,8 +197,6 @@ export const BorderContainer = defineComponent({
|
|
|
194
197
|
max-height var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
|
|
195
198
|
margin var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out)}
|
|
196
199
|
.drawer:hover,.drawer:focus-visible{opacity:var(--gramlot-drawer-active-opacity,1)}
|
|
197
|
-
[data-axis=x]>.drawer[data-resizable]{cursor:col-resize}
|
|
198
|
-
[data-axis=y]>.drawer[data-resizable]{cursor:row-resize}
|
|
199
200
|
@media (hover:hover){
|
|
200
201
|
[data-axis=x]>.drawer:hover{transform:scale(var(--gramlot-drawer-hover-cross-scale,1.75),var(--gramlot-drawer-hover-length-scale,1.12))}
|
|
201
202
|
[data-axis=y]>.drawer:hover{transform:scale(var(--gramlot-drawer-hover-length-scale,1.12),var(--gramlot-drawer-hover-cross-scale,1.75))}
|
|
@@ -281,7 +282,7 @@ export const BorderContainer = defineComponent({
|
|
|
281
282
|
separator.setAttribute('aria-controls', viewport.id);
|
|
282
283
|
const drawer = doc.createElement('button'); drawer.type = 'button'; drawer.className = 'drawer';
|
|
283
284
|
drawer.setAttribute('aria-controls', viewport.id);
|
|
284
|
-
const drawerIcon = doc.createElement('span'); drawerIcon.className = 'drawer-icon'; drawerIcon.setAttribute('aria-hidden', 'true');
|
|
285
|
+
const drawerIcon = doc.createElement('span'); drawerIcon.className = 'drawer-icon'; drawerIcon.setAttribute('iconslot', ''); drawerIcon.setAttribute('aria-hidden', 'true');
|
|
285
286
|
const drawerLabel = doc.createElement('span'); drawerLabel.className = 'drawer-label';
|
|
286
287
|
const drawerContent = doc.createElement('span'); drawerContent.className = 'drawer-content';
|
|
287
288
|
const drawerViewport = doc.createElement('span'); drawerViewport.className = 'drawer-viewport';
|
|
@@ -376,7 +377,7 @@ export const BorderContainer = defineComponent({
|
|
|
376
377
|
USE_PROFILES: {html: true}, FORBID_TAGS: ['style', 'form', 'input', 'button', 'select', 'textarea'],
|
|
377
378
|
RETURN_DOM_FRAGMENT: true,
|
|
378
379
|
}));
|
|
379
|
-
state.drawerIcon
|
|
380
|
+
renderIcon(this, state.drawerIcon, config.icon);
|
|
380
381
|
state.drawerIcon.hidden = !config.icon;
|
|
381
382
|
state.drawer.toggleAttribute('data-icon', !!config.icon);
|
|
382
383
|
state.drawer.toggleAttribute('data-labelled', !!config.label);
|
|
@@ -545,6 +546,63 @@ export const BorderContainer = defineComponent({
|
|
|
545
546
|
/** Five-region command frame; the existing border engine owns layout. */
|
|
546
547
|
export const FramePane = defineComponent({
|
|
547
548
|
name: 'framePane', tag: 'gramlot-frame-pane', base: BorderContainer.base,
|
|
548
|
-
parameters: BorderContainer.parameters,
|
|
549
|
-
|
|
549
|
+
parameters: {...BorderContainer.parameters, ...toolbarIconParameters},
|
|
550
|
+
childParameters: {...BorderContainer.childParameters, region:{required:true, enum:REGIONS, binding:'read'}},
|
|
551
|
+
subTags: 'contentPane,menu',
|
|
552
|
+
implementation: Base => class extends BorderContainer.implementation(Base) {
|
|
553
|
+
static projectChild(element, attrs, context) {
|
|
554
|
+
if (labelboxContent(element).localName !== 'gramlot-menu') return super.projectChild(element, attrs, context);
|
|
555
|
+
const {region, ...rest} = attrs;
|
|
556
|
+
if (rest.presentation !== 'bar' || !REGIONS.includes(region)) {
|
|
557
|
+
throw new TypeError('A direct framePane menu requires presentation="bar" and a frame region');
|
|
558
|
+
}
|
|
559
|
+
return {...rest, slot:'bars-' + region, orientation:['left','right'].includes(region) ? 'vertical' : 'horizontal'};
|
|
560
|
+
}
|
|
561
|
+
constructor() {
|
|
562
|
+
super();
|
|
563
|
+
const doc = this.ownerDocument;
|
|
564
|
+
const style = doc.createElement('style');
|
|
565
|
+
style.textContent = `
|
|
566
|
+
.frame-bars{display:flex;min-width:0;min-height:0;flex-direction:column;overflow:hidden}
|
|
567
|
+
.frame-bars[data-side=left],.frame-bars[data-side=right]{flex-direction:row}
|
|
568
|
+
::slotted(:nth-child(n+2 of [slot=bars-top]:not([hidden]))),
|
|
569
|
+
::slotted(:nth-child(n+2 of [slot=bars-bottom]:not([hidden]))){
|
|
570
|
+
border-block-start:1px solid color-mix(in srgb,var(--gramlot-border) 45%,transparent)}
|
|
571
|
+
::slotted(:nth-child(n+2 of [slot=bars-left]:not([hidden]))),
|
|
572
|
+
::slotted(:nth-child(n+2 of [slot=bars-right]:not([hidden]))){
|
|
573
|
+
border-inline-start:1px solid color-mix(in srgb,var(--gramlot-border) 45%,transparent)}
|
|
574
|
+
.control-box.has-bars{
|
|
575
|
+
grid-template-columns:var(--left,0px) auto minmax(0,1fr) auto var(--right,0px);
|
|
576
|
+
grid-template-rows:var(--top,0px) auto auto minmax(0,1fr) auto var(--bottom,0px);
|
|
577
|
+
grid-template-areas:'top top top top top' 'bars-top bars-top bars-top bars-top bars-top'
|
|
578
|
+
'left bars-left bars-center bars-right right' 'left bars-left center bars-right right'
|
|
579
|
+
'bars-bottom bars-bottom bars-bottom bars-bottom bars-bottom' 'bottom bottom bottom bottom bottom'}
|
|
580
|
+
.control-box.has-bars[data-design=sidebar]{
|
|
581
|
+
grid-template-areas:'left bars-left top bars-right right' 'left bars-left bars-top bars-right right'
|
|
582
|
+
'left bars-left bars-center bars-right right' 'left bars-left center bars-right right'
|
|
583
|
+
'left bars-left bars-bottom bars-right right' 'left bars-left bottom bars-right right'}
|
|
584
|
+
`;
|
|
585
|
+
this.shadowRoot.append(style);
|
|
586
|
+
const slots = [];
|
|
587
|
+
for (const side of REGIONS) {
|
|
588
|
+
const strip = doc.createElement('div'), slot = doc.createElement('slot');
|
|
589
|
+
strip.className = 'frame-bars';
|
|
590
|
+
strip.dataset.side = side;
|
|
591
|
+
slot.name = 'bars-' + side;
|
|
592
|
+
strip.style.gridArea = slot.name;
|
|
593
|
+
strip.hidden = true;
|
|
594
|
+
slots.push(slot);
|
|
595
|
+
slot.addEventListener('slotchange', () => {
|
|
596
|
+
strip.hidden = !slot.assignedElements().length;
|
|
597
|
+
this.control.classList.toggle('has-bars', slots.some(s => !s.parentElement.hidden));
|
|
598
|
+
});
|
|
599
|
+
strip.append(slot);
|
|
600
|
+
this.control.append(strip);
|
|
601
|
+
}
|
|
602
|
+
style.textContent += '.frame-bars[hidden]{display:none}';
|
|
603
|
+
}
|
|
604
|
+
projectAttributes(attrs, adapt) {
|
|
605
|
+
return projectToolbarIconStyle(this, super.projectAttributes(attrs, adapt));
|
|
606
|
+
}
|
|
607
|
+
}
|
|
550
608
|
});
|