@gramlot/gramlot 0.3.20 → 0.3.26
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/dist/components/chat/__init__.py +13 -0
- package/dist/components/chat/assets/collection.js +9 -0
- package/dist/components/chat/assets/index.js +3 -0
- package/dist/components/chat/commands.json +7 -0
- package/dist/components/chat/grammar.json +48 -0
- package/dist/components/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +26 -120912
- package/dist/components/editors/assets/index.js +2 -1
- package/dist/components/editors/assets/modules/chunk-74O4WKIV.js +1 -0
- package/dist/components/editors/assets/modules/chunk-AU4HFPIY.js +1 -0
- package/dist/components/editors/assets/modules/chunk-YSGSC7KM.js +1 -0
- package/dist/components/editors/assets/modules/code-mirror-engine-RWQTR5G5.js +92 -0
- package/dist/components/editors/assets/modules/jodit-engine-MTSA4GZ3.js +1853 -0
- package/dist/components/editors/assets/modules/markdown-document-VFC23FAY.js +1 -0
- package/dist/components/editors/assets/modules/prose-mirror-engine-GMZPJPNN.js +24 -0
- package/dist/components/grid/__init__.py +14 -0
- package/dist/components/grid/assets/collection.js +262 -0
- package/dist/components/grid/assets/index.js +3 -0
- package/dist/components/grid/commands.json +7 -0
- package/dist/components/grid/grammar.json +770 -0
- package/dist/components/grouplets/__init__.py +13 -0
- package/dist/components/grouplets/assets/collection.js +185 -0
- package/dist/components/grouplets/assets/index.js +3 -0
- package/dist/components/grouplets/assets/modules/chunk-BLMUM44K.js +1 -0
- package/dist/components/grouplets/assets/modules/markdown-document-YWNZTOKK.js +1 -0
- package/dist/components/grouplets/commands.json +7 -0
- package/dist/components/grouplets/grammar.json +355 -0
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +65 -24511
- package/dist/components/inputs/assets/index.js +2 -1
- package/dist/components/inputs/grammar.json +278 -6
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +68 -26732
- package/dist/components/layout/assets/index.js +2 -1
- package/dist/components/layout/grammar.json +39 -0
- package/dist/components/selection_trial/__init__.py +13 -0
- package/dist/components/selection_trial/assets/collection.js +4 -0
- package/dist/components/selection_trial/assets/index.js +3 -0
- package/dist/components/selection_trial/commands.json +7 -0
- package/dist/components/selection_trial/grammar.json +587 -0
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +27 -24612
- package/dist/components/tree/assets/index.js +2 -1
- package/dist/components/tree/grammar.json +341 -1
- package/dist/components/typst/__init__.py +2 -2
- package/dist/components/typst/assets/collection.js +12 -4
- package/dist/components/typst/assets/index.js +2 -1
- package/dist/components/typst/assets/modules/chunk-BLMUM44K.js +1 -0
- package/dist/components/typst/assets/modules/typst-client-JHC6UVYG.js +4 -0
- package/dist/components/uploads/__init__.py +13 -0
- package/dist/components/uploads/assets/collection.js +67 -0
- package/dist/components/uploads/assets/index.js +3 -0
- package/dist/components/uploads/commands.json +7 -0
- package/dist/components/uploads/grammar.json +789 -0
- package/dist/gramlot-markdown.js +16 -0
- package/dist/gramlot.js +6861 -1395
- package/dist/gramlot.min.js +1595 -46
- package/dist/runtime-notices.json +28 -0
- package/package.json +10 -3
- package/src/binding/grid-struct.js +63 -0
- package/src/binding/installation.js +5 -2
- package/src/binding/providers.js +4 -1
- package/src/binding/remote-resolver.js +1 -8
- package/src/binding/runtime.js +90 -6
- package/src/binding/validation-context.js +40 -0
- package/src/browser-camera-provider.d.ts +8 -0
- package/src/browser-camera-provider.js +104 -0
- package/src/builder/gramlot-builder.d.ts +5 -0
- package/src/builder/gramlot-builder.js +16 -0
- package/src/builder/source.js +34 -0
- package/src/chat.d.ts +12 -0
- package/src/chat.js +198 -0
- package/src/collection-artifact.js +1 -1
- package/src/components/attachment-manager.js +160 -0
- package/src/components/bases.js +19 -6
- package/src/components/border-container.js +86 -8
- package/src/components/buttons.js +11 -1
- package/src/components/chat.js +28 -0
- package/src/components/choice-editor.js +106 -38
- package/src/components/database-choices.js +133 -9
- package/src/components/editing-status-styles.js +26 -0
- package/src/components/editing-status.js +115 -0
- package/src/components/field-state.js +42 -54
- package/src/components/grid-cell-editor.js +181 -0
- package/src/components/grid-grammar.json +258 -0
- package/src/components/grid-header-interaction.js +196 -0
- package/src/components/grid-row-interaction.js +184 -0
- package/src/components/grid-row-layout.js +96 -0
- package/src/components/grid-rows.js +28 -0
- package/src/components/grid-search-box.js +142 -0
- package/src/components/grid-search-styles.js +42 -0
- package/src/components/grid-search.js +37 -0
- package/src/components/grid-structure.js +85 -0
- package/src/components/grid-styles.js +201 -0
- package/src/components/grid.js +666 -0
- package/src/components/grouplet-card.js +445 -0
- package/src/components/grouplets.js +17 -0
- package/src/components/html-preview.js +17 -4
- package/src/components/image-crop-dialog.js +272 -0
- package/src/components/image-crop.js +79 -0
- package/src/components/image-uploader.js +252 -0
- package/src/components/inputs.js +2 -1
- package/src/components/jodit-engine.js +1 -1
- package/src/components/markdown-document.js +2 -2
- package/src/components/menus.js +1 -0
- package/src/components/registry.js +4 -3
- package/src/components/screen-capture.js +43 -0
- package/src/components/selected-container.js +6 -2
- package/src/components/tray-pane.js +32 -4
- package/src/components/tree.js +416 -17
- package/src/components/typed-editor.js +23 -11
- package/src/components/upload-engine.js +156 -0
- package/src/components/uploader.js +208 -0
- package/src/components/uploads.js +7 -0
- package/src/editing-session.d.ts +25 -0
- package/src/editing-session.js +396 -0
- package/src/experiments/selection-transfer.js +78 -0
- package/src/experiments/selection-trial.js +64 -0
- package/src/experiments/window-selection.js +124 -0
- package/src/format.js +22 -7
- package/src/gramlot.d.ts +2 -0
- package/src/gramlot.js +2 -1
- package/src/handlers/device-handler.d.ts +2 -1
- package/src/handlers/rpc-handler.d.ts +3 -3
- package/src/index-page-styles.js +2 -1
- package/src/index.d.ts +16 -1
- package/src/index.js +16 -1
- package/src/inout.d.ts +2 -0
- package/src/inout.js +6 -0
- package/src/markdown-loader.d.ts +1 -0
- package/src/markdown-loader.js +4 -0
- package/src/markdown.d.ts +1 -0
- package/src/markdown.js +2 -0
- package/src/media-frame.js +9 -0
- package/src/renderer/attributes.js +7 -1
- package/src/renderer/gramlot-renderer.d.ts +2 -0
- package/src/renderer/gramlot-renderer.js +39 -3
- package/src/server/assets.d.ts +1 -1
- package/src/server/assets.js +1 -1
- package/src/server/gramlot-server.d.ts +10 -1
- package/src/server/gramlot-server.js +96 -8
- package/src/server/index.d.ts +2 -0
- package/src/server/index.js +2 -0
- package/src/server/page-base.js +17 -4
- package/src/server/page.d.ts +13 -1
- package/src/server/page.js +6 -0
- package/src/server/source-import.d.ts +2 -0
- package/src/server/source-import.js +31 -0
- package/src/server/upload.d.ts +20 -0
- package/src/server/upload.js +142 -0
- package/src/server/visual-editor.d.ts +11 -0
- package/src/server/visual-editor.js +149 -0
- package/src/source-picker.d.ts +9 -0
- package/src/source-picker.js +57 -0
- package/src/stores/bag-collection-store.js +51 -0
- package/src/stores/bag-collection-view.js +127 -0
- package/src/stores/collection-filter.js +77 -0
- package/src/tree-store.d.ts +24 -0
- package/src/tree-store.js +193 -0
- package/src/validation-run.js +50 -0
- package/src/view/button.js +8 -5
- package/src/view/controls.js +31 -32
- package/src/view/grouplet-card.js +54 -0
- package/src/view/html.js +29 -4
- package/src/view/labelbox.js +7 -3
- package/src/visual-editor-icons.js +10 -0
- package/src/visual-editor.d.ts +56 -0
- package/src/visual-editor.js +844 -0
- package/themes/gramlot-base/theme.css +127 -0
- package/themes/gramlot-compact/theme.css +8 -0
- package/themes/joanna/theme.css +8 -0
- package/themes/mimi/theme.css +8 -0
package/src/components/bases.js
CHANGED
|
@@ -12,13 +12,14 @@ export function controlElement(HTMLElement) {
|
|
|
12
12
|
input,textarea{font:inherit;max-width:100%} .control-box{min-width:0;color:var(--gramlot-ink,CanvasText)}
|
|
13
13
|
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]),textarea{
|
|
14
14
|
appearance:none;box-sizing:border-box;width:100%;border:1px solid var(--gramlot-border-control,#7a8798);
|
|
15
|
-
border-radius:var(--gramlot-radius-sm,4px);background:var(--gramlot-field-background,Canvas);color:var(--gramlot-ink,CanvasText);
|
|
16
|
-
min-height:var(--gramlot-field-height,28px);padding:var(--gramlot-field-padding,.25em .5em);font-size:var(--gramlot-field-font-size,1em);line-height:var(--gramlot-field-line-height,inherit)}
|
|
15
|
+
border-radius:var(--gramlot-field-radius,var(--gramlot-radius-sm,4px));background:var(--gramlot-field-background,Canvas);color:var(--gramlot-ink,CanvasText);
|
|
16
|
+
height:var(--gramlot-field-block-size,auto);min-height:var(--gramlot-field-height,28px);padding:var(--gramlot-field-padding,.25em .5em);font-size:var(--gramlot-field-font-size,1em);line-height:var(--gramlot-field-line-height,inherit)}
|
|
17
17
|
input:read-only:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]),textarea:read-only{
|
|
18
18
|
background:var(--gramlot-field-readonly-background,Canvas)}
|
|
19
19
|
input:disabled,textarea:disabled{opacity:.6;cursor:not-allowed}
|
|
20
20
|
input::placeholder,textarea::placeholder{color:var(--gramlot-text-secondary,GrayText)}
|
|
21
|
-
input:focus-visible,textarea:focus-visible,button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:1px}
|
|
21
|
+
input:focus-visible,textarea:focus-visible,button:focus-visible{outline:var(--gramlot-field-focus-outline,2px solid var(--gramlot-focus-ring,Highlight));outline-offset:var(--gramlot-field-focus-offset,1px)}
|
|
22
|
+
textarea{resize:var(--gramlot-field-resize,both)}
|
|
22
23
|
input[type=checkbox],input[type=radio],input[type=range]{accent-color:var(--gramlot-brand-blue,Highlight)}
|
|
23
24
|
input[type=range],input[type=color],button{min-width:var(--gramlot-touch-target,0px);min-height:var(--gramlot-touch-target,0px)}
|
|
24
25
|
input[type=checkbox],input[type=radio]{min-width:calc(var(--gramlot-touch-target,0px) / 2);min-height:calc(var(--gramlot-touch-target,0px) / 2)}
|
|
@@ -32,6 +33,7 @@ export function controlElement(HTMLElement) {
|
|
|
32
33
|
return projectParameters(this, attrs);
|
|
33
34
|
}
|
|
34
35
|
setPageContext(context) { this.pageContext = context; }
|
|
36
|
+
connectedCallback() {}
|
|
35
37
|
releaseControl() {}
|
|
36
38
|
get liveWrites() { return this.control.localName === 'textarea' || ['text', 'password', 'range', 'color'].includes(this.control.type); }
|
|
37
39
|
validateCandidate(value, accept) {
|
|
@@ -39,16 +41,27 @@ export function controlElement(HTMLElement) {
|
|
|
39
41
|
return {ok:true, value, isCurrent:() => this.pageContext.isActive()};
|
|
40
42
|
}
|
|
41
43
|
finishValidation() {}
|
|
42
|
-
|
|
44
|
+
validationValueCheck() {
|
|
45
|
+
const nullable = this.constructor.gramlotComponent.parameters.value.nullable;
|
|
46
|
+
return (value, original) => {
|
|
47
|
+
if (value == null && !nullable) throw new TypeError('This component requires a non-null value.');
|
|
48
|
+
if (value != null && original != null && typeof value !== typeof original) throw new TypeError('Validation must preserve the component value type.');
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
validationSelection() {
|
|
52
|
+
return () => { throw new TypeError('validate_select requires a constrained choice editor.'); };
|
|
53
|
+
}
|
|
54
|
+
validateSelection(value) { return this.validationSelection()(value); }
|
|
43
55
|
shouldProjectControlValue() { return true; }
|
|
44
56
|
acceptControlValue() {
|
|
45
57
|
const value = this.readControlValue();
|
|
46
58
|
return this.validateCandidate(value, accepted => {
|
|
47
|
-
|
|
48
|
-
if (accepted != null && value != null && typeof accepted !== typeof value) throw new TypeError('Validation must preserve the component value type.');
|
|
59
|
+
this.validationValueCheck()(accepted,value);
|
|
49
60
|
if (!this.sameControlValue(value, accepted)) this.writeControlValue(accepted);
|
|
50
61
|
});
|
|
51
62
|
}
|
|
63
|
+
restoreFormDraft(text) { this.control.value = text; }
|
|
64
|
+
restoreFormValue(value) { this.writeControlValue(value); }
|
|
52
65
|
sameControlValue(a, b) { return Object.is(a, b); }
|
|
53
66
|
focus(options) { this.control.focus(options); }
|
|
54
67
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/** Parent-owned regions. Layout changes never move or recreate slotted content. */
|
|
2
2
|
import {defineComponent} from './registry.js';
|
|
3
3
|
import {Container} from './container.js';
|
|
4
|
-
import
|
|
4
|
+
import {WindowSurface} from './window-surface.js';
|
|
5
|
+
import {SVG_NS} from '../renderer/attributes.js';
|
|
6
|
+
import {createDOMPurify} from '@gramlot/gramlot';
|
|
5
7
|
|
|
6
8
|
const SIDES = ['top', 'bottom', 'left', 'right'];
|
|
7
9
|
const REGIONS = [...SIDES, 'center'];
|
|
@@ -19,6 +21,8 @@ function projectBorderChild(element, attrs, {adapt, invoke, publish, publishPare
|
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
const region = rest.region;
|
|
24
|
+
const detachable = rest.detachable ?? false;
|
|
25
|
+
if (typeof detachable !== 'boolean') throw new TypeError('detachable must be a boolean');
|
|
22
26
|
if (!REGIONS.includes(region)) throw new TypeError(`Invalid border region: ${region}`);
|
|
23
27
|
const min = rest.minSize ?? 0, max = rest.maxSize ?? Infinity;
|
|
24
28
|
if (typeof min !== 'number' || typeof max !== 'number' || !Number.isFinite(min) || min < 0 || max < min || Number.isNaN(max)) {
|
|
@@ -46,7 +50,7 @@ function projectBorderChild(element, attrs, {adapt, invoke, publish, publishPare
|
|
|
46
50
|
const background = drawerProbe.style.backgroundColor;
|
|
47
51
|
if (background) drawerProbe.style.setProperty('--gramlot-drawer-background', background);
|
|
48
52
|
if (drawerAttrs.style != null) drawerAttrs.style = drawerProbe.style.cssText;
|
|
49
|
-
const config = {region, size, min, max, splitter: rest.splitter === true,
|
|
53
|
+
const config = {region, size, min, max, detachable, title:rest.title ?? '', splitter: rest.splitter === true,
|
|
50
54
|
drawer: rest.drawer, hidden: rest.hidden === true,
|
|
51
55
|
splitterAttrs: adapt(splitter), drawerAttrs, label, icon, minimize,
|
|
52
56
|
writeParameter: size => { if (numeric) writeParameter(dimension, size); }, notifications: {
|
|
@@ -54,7 +58,7 @@ function projectBorderChild(element, attrs, {adapt, invoke, publish, publishPare
|
|
|
54
58
|
splitterResize: payload => publishParent('splitter_resize', payload),
|
|
55
59
|
},
|
|
56
60
|
onToggle: onclick ? (evt, show) => invoke('drawer_onclick', onclick, {evt, show}) : null};
|
|
57
|
-
for (const key of ['region', 'splitter', 'drawer', 'minSize', 'maxSize']) delete rest[key];
|
|
61
|
+
for (const key of ['region', 'splitter', 'drawer', 'minSize', 'maxSize', 'detachable', 'title']) delete rest[key];
|
|
58
62
|
rest.slot = region;
|
|
59
63
|
return {rest, config};
|
|
60
64
|
}
|
|
@@ -98,7 +102,7 @@ export const ContentPane = defineComponent({
|
|
|
98
102
|
|
|
99
103
|
export const BorderContainer = defineComponent({
|
|
100
104
|
name: 'borderContainer', tag: 'gramlot-border-container', base: Container, subTags: '*',
|
|
101
|
-
childParameters: {region: {required: true, enum: REGIONS, unique: true}, width: {}, height: {}, drawer_onclick: {inline: ['evt', 'show']}},
|
|
105
|
+
childParameters: {detachable:{dtype:'B',default:false}, title:{dtype:'T',default:''}, region: {required: true, enum: REGIONS, unique: true}, width: {}, height: {}, drawer_onclick: {inline: ['evt', 'show']}},
|
|
102
106
|
parameters: {
|
|
103
107
|
design: {dtype: 'T', default: 'headline', binding: 'read', enum: ['headline', 'sidebar']},
|
|
104
108
|
persist: {dtype: 'B', default: false, binding: 'read'},
|
|
@@ -145,6 +149,18 @@ export const BorderContainer = defineComponent({
|
|
|
145
149
|
.region[data-side=top]>.viewport{padding-bottom:var(--region-splitter,0px)}
|
|
146
150
|
.region[data-side=bottom]>.viewport{padding-top:var(--region-splitter,0px)}
|
|
147
151
|
.viewport[hidden]{display:none}
|
|
152
|
+
.viewport.has-tools{flex-direction:column;overflow:hidden}
|
|
153
|
+
.viewport.has-tools:not([hidden]){display:flex}
|
|
154
|
+
.viewport.has-tools>slot{display:block;flex:1;min-height:0;overflow:auto}
|
|
155
|
+
.region-tools{display:flex;flex:none;align-items:center;gap:6px;padding:var(--gramlot-region-header-padding,3px 7px);
|
|
156
|
+
border-bottom:1px solid var(--gramlot-region-header-border,var(--gramlot-border,#d5dce5));background:var(--gramlot-region-header-background,var(--gramlot-surface-subtle,var(--gramlot-surface,#fff)))}
|
|
157
|
+
.region-tools[hidden]{display:none}
|
|
158
|
+
.region-title{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:var(--gramlot-region-title-size,12px);font-weight:600}
|
|
159
|
+
.detach{display:flex;align-items:center;justify-content:center;touch-action:none;cursor:grab;
|
|
160
|
+
color:inherit;background:transparent;border:0;border-radius:4px;padding:3px;min-width:24px;min-height:24px}
|
|
161
|
+
.detach:hover{background:var(--gramlot-selected,#e8f1fc)}
|
|
162
|
+
.detach:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}
|
|
163
|
+
.detach svg{width:16px;height:16px;pointer-events:none}
|
|
148
164
|
.control-box[data-drawer-motion] .viewport{transition:opacity var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out);opacity:1;visibility:visible}
|
|
149
165
|
.control-box[data-drawer-motion] .viewport[hidden]{display:block;opacity:0;visibility:hidden;
|
|
150
166
|
transition:opacity var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),visibility 0s var(--gramlot-drawer-duration,.24s)}::slotted(*){min-height:0}
|
|
@@ -232,7 +248,31 @@ export const BorderContainer = defineComponent({
|
|
|
232
248
|
const cell = doc.createElement('div'); cell.className = 'region'; cell.style.gridArea = side;
|
|
233
249
|
const viewport = doc.createElement('div'); viewport.className = 'viewport'; cell.dataset.side = side; viewport.id = `region-${side}`;
|
|
234
250
|
const slot = doc.createElement('slot'); slot.name = side; viewport.append(slot); cell.append(viewport);
|
|
235
|
-
const state = {cell, viewport, child:null, config:null, visibility:null, closed:false, suppressDrawerClick:false, size:null, splitterAttrs:{}, drawerAttrs:{}};
|
|
251
|
+
const state = {cell, viewport, child:null, config:null, visibility:null, closed:false, suppressDrawerClick:false, size:null, splitterAttrs:{}, drawerAttrs:{}, surface:null};
|
|
252
|
+
const tools = doc.createElement('div'), title = doc.createElement('span'), detach = doc.createElement('button');
|
|
253
|
+
tools.className = 'region-tools'; tools.hidden = true; title.className = 'region-title';
|
|
254
|
+
detach.type = 'button'; detach.className = 'detach';
|
|
255
|
+
const svg = doc.createElementNS(SVG_NS,'svg'), path = doc.createElementNS(SVG_NS,'path');
|
|
256
|
+
svg.setAttribute('viewBox','0 0 20 20'); svg.setAttribute('aria-hidden','true');
|
|
257
|
+
path.setAttribute('d','M11 3h6v6M17 3l-8 8M8 4H4v12h12v-4');
|
|
258
|
+
path.setAttribute('fill','none'); path.setAttribute('stroke','currentColor'); path.setAttribute('stroke-width','1.8');
|
|
259
|
+
path.setAttribute('stroke-linecap','round'); path.setAttribute('stroke-linejoin','round'); svg.append(path); detach.append(svg);
|
|
260
|
+
tools.append(title,detach); viewport.prepend(tools); Object.assign(state,{tools,title,detach});
|
|
261
|
+
let gesture = null, dragged = false;
|
|
262
|
+
detach.addEventListener('pointerdown', event => {
|
|
263
|
+
if (event.button !== 0) return;
|
|
264
|
+
gesture = {id:event.pointerId,x:event.clientX,y:event.clientY}; dragged = false;
|
|
265
|
+
detach.setPointerCapture(event.pointerId);
|
|
266
|
+
});
|
|
267
|
+
detach.addEventListener('pointerup', event => {
|
|
268
|
+
if (!gesture || gesture.id !== event.pointerId) return;
|
|
269
|
+
const start = gesture; gesture = null;
|
|
270
|
+
if (detach.hasPointerCapture(event.pointerId)) detach.releasePointerCapture(event.pointerId);
|
|
271
|
+
dragged = Math.hypot(event.clientX-start.x,event.clientY-start.y) > 5;
|
|
272
|
+
if (dragged) this.detachRegion(side,{left:event.clientX,top:event.clientY});
|
|
273
|
+
});
|
|
274
|
+
detach.addEventListener('pointercancel', () => {gesture=null;dragged=false;});
|
|
275
|
+
detach.addEventListener('click', () => {if (!dragged) this.detachRegion(side); dragged=false;});
|
|
236
276
|
if (side !== 'center') {
|
|
237
277
|
const separator = doc.createElement('div'); separator.className = 'separator';
|
|
238
278
|
separator.dataset.side = side; separator.dataset.axis = horizontal(side) ? 'y' : 'x';
|
|
@@ -283,7 +323,7 @@ export const BorderContainer = defineComponent({
|
|
|
283
323
|
for (const state of this.#regions.values()) if (state.drawerContent) this.#contentObserver.observe(state.drawerContent);
|
|
284
324
|
this.#sync();
|
|
285
325
|
}
|
|
286
|
-
disconnectedCallback() { this.#observer.disconnect(); this.#contentObserver.disconnect(); this.#stopDrag(); }
|
|
326
|
+
disconnectedCallback() { this.#observer.disconnect(); this.#contentObserver.disconnect(); this.#stopDrag(); for (const side of REGIONS) this.reattachRegion(side, false); }
|
|
287
327
|
projectAttributes(attrs, adapt) {
|
|
288
328
|
const rest = super.projectAttributes(attrs, adapt);
|
|
289
329
|
if (!['headline', 'sidebar'].includes(this.parameters.design)) throw new TypeError('Invalid border design');
|
|
@@ -304,6 +344,7 @@ export const BorderContainer = defineComponent({
|
|
|
304
344
|
const child = children.get(side) ?? null;
|
|
305
345
|
if (state.child !== child) {
|
|
306
346
|
if (this.#drag?.side === side) this.#stopDrag();
|
|
347
|
+
this.reattachRegion(side, false);
|
|
307
348
|
state.child = child; state.config = null; state.visibility = null; state.size = null; state.closed = false;
|
|
308
349
|
}
|
|
309
350
|
if (child) this.projectRegion(child);
|
|
@@ -323,6 +364,8 @@ export const BorderContainer = defineComponent({
|
|
|
323
364
|
}
|
|
324
365
|
if (!before || before.drawer !== config.drawer) state.closed = config.drawer === 'close';
|
|
325
366
|
state.config = config;
|
|
367
|
+
if (!config.detachable || config.hidden || state.closed) this.reattachRegion(side, false);
|
|
368
|
+
if (state.surface) state.surface.configure({...state.surface.parameters, title:config.title || side});
|
|
326
369
|
if (side !== 'center') {
|
|
327
370
|
state.splitterAttrs = applyAttributes(state.separator, config.splitterAttrs, state.splitterAttrs);
|
|
328
371
|
state.drawerAttrs = applyAttributes(state.drawer, config.drawerAttrs, state.drawerAttrs);
|
|
@@ -357,9 +400,14 @@ export const BorderContainer = defineComponent({
|
|
|
357
400
|
}
|
|
358
401
|
}
|
|
359
402
|
state.viewport.hidden = !visible;
|
|
403
|
+
state.viewport.classList.toggle('has-tools', !!c?.detachable);
|
|
404
|
+
state.tools.hidden = !c?.detachable || !!state.surface;
|
|
405
|
+
state.title.textContent = c?.title || side;
|
|
406
|
+
state.detach.setAttribute('aria-label', `Detach ${c?.title || side}`);
|
|
407
|
+
state.detach.title = state.detach.getAttribute('aria-label');
|
|
360
408
|
if (side === 'center') return;
|
|
361
|
-
this.control.style.setProperty(`--${side}`, visible ? state.size : '0px');
|
|
362
|
-
state.separator.hidden = !c || c.hidden || (!c.splitter && !c.drawer);
|
|
409
|
+
this.control.style.setProperty(`--${side}`, visible && !state.surface ? state.size : '0px');
|
|
410
|
+
state.separator.hidden = !!state.surface || !c || c.hidden || (!c.splitter && !c.drawer);
|
|
363
411
|
const draggable = visible && c.splitter;
|
|
364
412
|
state.cell.style.setProperty('--region-splitter', draggable ? (state.separator.style[horizontal(side) ? 'height' : 'width'] || 'var(--gramlot-splitter-size,1px)') : '0px');
|
|
365
413
|
state.separator.dataset.draggable = String(!!draggable);
|
|
@@ -378,6 +426,36 @@ export const BorderContainer = defineComponent({
|
|
|
378
426
|
c.notifications.closableChange({open: visible, region: side});
|
|
379
427
|
}
|
|
380
428
|
}
|
|
429
|
+
detachRegion(side, position = null) {
|
|
430
|
+
const state = this.#regions.get(side), config = state.config;
|
|
431
|
+
if (!config?.detachable || config.hidden || state.closed) return;
|
|
432
|
+
if (state.surface) {state.surface.focus();return;}
|
|
433
|
+
const rect = state.viewport.getBoundingClientRect(), mount = this.ownerDocument.createElement('div');
|
|
434
|
+
this.shadowRoot.append(mount);
|
|
435
|
+
const surface = new WindowSurface(this,mount,{modal:false,validateContent:()=>{
|
|
436
|
+
if (state.viewport.parentNode !== surface.body) throw new Error('Detached region lost its presentation');
|
|
437
|
+
}});
|
|
438
|
+
state.surface = surface; state.mount = mount;
|
|
439
|
+
surface.body.replaceChildren(state.viewport);
|
|
440
|
+
state.viewport.style.cssText = 'flex:1;min-width:0;height:100%;';
|
|
441
|
+
surface.setSourceContext({writeParameter:(name,value)=>{surface.parameters[name]=value;},
|
|
442
|
+
publish:topic=>{if(topic==='closed')this.reattachRegion(side);}});
|
|
443
|
+
surface.configure({title:config.title || side,open:true,movable:true,resizable:true,
|
|
444
|
+
collapsible:false,maximizable:false,maximized:false,collapsed:false,closable:true,beforeClose:null,
|
|
445
|
+
width:`${Math.max(320,Math.min(rect.width,720))}px`,height:`${Math.max(240,Math.min(rect.height,560))}px`,
|
|
446
|
+
left:position ? `${position.left}px` : null,top:position ? `${position.top}px` : null,
|
|
447
|
+
minWidth:'220px',minHeight:'140px'});
|
|
448
|
+
this.#render(side); surface.connect();
|
|
449
|
+
}
|
|
450
|
+
reattachRegion(side, focus = true) {
|
|
451
|
+
const state = this.#regions.get(side);
|
|
452
|
+
if (!state.surface) return;
|
|
453
|
+
const surface = state.surface; state.surface = null;
|
|
454
|
+
state.cell.prepend(state.viewport); state.viewport.style.cssText = '';
|
|
455
|
+
surface.disconnect(); state.mount.remove(); state.mount = null;
|
|
456
|
+
this.#render(side);
|
|
457
|
+
if (focus && state.child?.isConnected && !state.closed) state.detach.focus();
|
|
458
|
+
}
|
|
381
459
|
#extent(side) { const box = this.#regions.get(side).cell.getBoundingClientRect(); return horizontal(side) ? box.height : box.width; }
|
|
382
460
|
#resize(side, desired) {
|
|
383
461
|
this.control.removeAttribute('data-drawer-motion');
|
|
@@ -7,6 +7,7 @@ import {MenuContainer, menuLine} from './menus.js';
|
|
|
7
7
|
|
|
8
8
|
function Command(HTMLElement) {
|
|
9
9
|
return class extends controlElement(HTMLElement) {
|
|
10
|
+
#actionPresentation = null;
|
|
10
11
|
constructor() {
|
|
11
12
|
super();
|
|
12
13
|
const doc = this.ownerDocument;
|
|
@@ -20,7 +21,7 @@ function Command(HTMLElement) {
|
|
|
20
21
|
this.control.append(this.icon, this.caption);
|
|
21
22
|
this.controlBox.append(this.control);
|
|
22
23
|
const style = doc.createElement('style');
|
|
23
|
-
style.textContent = `:host{vertical-align:middle} .control-box{display:flex;align-items:stretch}
|
|
24
|
+
style.textContent = `:host{vertical-align:middle} :host([hidden]){display:none} .control-box{display:flex;align-items:stretch}
|
|
24
25
|
button{display:inline-flex;align-items:center;justify-content:center;gap:var(--gramlot-button-gap,.35em);font:inherit;
|
|
25
26
|
color:var(--gramlot-button-color,var(--gramlot-ink,CanvasText));background:var(--gramlot-button-background,var(--gramlot-field-background,Canvas));
|
|
26
27
|
border:1px solid var(--gramlot-border-control,#888);border-radius:var(--gramlot-radius-sm,4px);
|
|
@@ -59,6 +60,7 @@ function Command(HTMLElement) {
|
|
|
59
60
|
this.renderIcon(this.parameters.icon, this.parameters.iconSrc);
|
|
60
61
|
if (attrs['aria-label'] != null) this.control.setAttribute('aria-label', attrs['aria-label']);
|
|
61
62
|
else this.control.removeAttribute('aria-label');
|
|
63
|
+
if (this.#actionPresentation) this.setActionPresentation(this.#actionPresentation);
|
|
62
64
|
return rest;
|
|
63
65
|
}
|
|
64
66
|
renderIcon(icon, iconSrc) {
|
|
@@ -73,6 +75,13 @@ function Command(HTMLElement) {
|
|
|
73
75
|
}
|
|
74
76
|
get entryIcon() { return this.parameters.icon; }
|
|
75
77
|
get entryIconSrc() { return this.parameters.iconSrc; }
|
|
78
|
+
setActionPresentation(presentation) {
|
|
79
|
+
this.#actionPresentation = presentation;
|
|
80
|
+
this.hidden = presentation.hidden;
|
|
81
|
+
this.icon.textContent = presentation.icon;
|
|
82
|
+
this.title = presentation.title;
|
|
83
|
+
this.control.setAttribute('aria-label', presentation.title);
|
|
84
|
+
}
|
|
76
85
|
attachCommand() {}
|
|
77
86
|
releaseCommand() {}
|
|
78
87
|
commandTarget() { return this; }
|
|
@@ -80,6 +89,7 @@ function Command(HTMLElement) {
|
|
|
80
89
|
};
|
|
81
90
|
}
|
|
82
91
|
Command.parameters = {
|
|
92
|
+
action: {dtype: 'T', nullable: true},
|
|
83
93
|
disabled: {dtype: 'B', default: false, binding: 'read'},
|
|
84
94
|
icon: {dtype: 'T', default: '', binding: 'read'},
|
|
85
95
|
iconSrc: {dtype: 'T', default: '', binding: 'read'}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Optional chat viewport; interactive contents are ordinary live Source children. */
|
|
2
|
+
import {defineCollection, defineComponent} from './registry.js';
|
|
3
|
+
import {Container} from './container.js';
|
|
4
|
+
|
|
5
|
+
export const ChatMessages = defineComponent({
|
|
6
|
+
name: 'chatMessages', tag: 'gramlot-chat-messages', base: Container, subTags: '*',
|
|
7
|
+
implementation: Base => class extends Base {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
const style = this.ownerDocument.createElement('style');
|
|
11
|
+
style.textContent = `:host{height:100%;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable}
|
|
12
|
+
.control-box{padding:20px max(20px,calc((100% - 880px)/2))}
|
|
13
|
+
::slotted(article){box-sizing:border-box;margin:0 0 24px;padding:16px 20px;border-radius:18px;
|
|
14
|
+
line-height:1.6;overflow-wrap:anywhere;background:var(--gramlot-chat-assistant-background,
|
|
15
|
+
color-mix(in srgb,var(--gramlot-surface-subtle,#eee) 88%,#628099))}
|
|
16
|
+
::slotted(article[data-role=user]){width:fit-content;max-width:85%;margin-left:auto;padding:12px 18px;
|
|
17
|
+
border-radius:20px;background:var(--gramlot-chat-bubble,var(--gramlot-surface-subtle,#eee))}`;
|
|
18
|
+
this.shadowRoot.append(style);
|
|
19
|
+
}
|
|
20
|
+
connectedCallback() {
|
|
21
|
+
this.setAttribute('role','log');
|
|
22
|
+
this.setAttribute('aria-label','Conversation messages');
|
|
23
|
+
this.setAttribute('aria-live','polite');
|
|
24
|
+
this.tabIndex=0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
export default defineCollection({name:'chat', components:[ChatMessages]});
|
|
@@ -17,6 +17,7 @@ export function ChoiceEditor(HTMLElement) {
|
|
|
17
17
|
#separator;
|
|
18
18
|
#cleanup;
|
|
19
19
|
#requestController;
|
|
20
|
+
#resolvingValue = false;
|
|
20
21
|
#searchTimer;
|
|
21
22
|
constructor() {
|
|
22
23
|
super();
|
|
@@ -25,9 +26,11 @@ export function ChoiceEditor(HTMLElement) {
|
|
|
25
26
|
style.textContent = `.option{position:relative} #control{width:100%;padding-right:calc(var(--gramlot-choice-toggle-width,1.6em) + .2em)}
|
|
26
27
|
#control:focus-visible{outline:1px solid var(--gramlot-border-control,#7a8798);outline-offset:-3px}
|
|
27
28
|
.toggle{position:absolute;right:0;top:0;bottom:0;width:var(--gramlot-choice-toggle-width,1.6em);min-width:0;min-height:0;font:inherit;font-size:var(--gramlot-field-font-size,1em);padding:0;border:0;background:transparent;color:inherit}
|
|
28
|
-
.choices{max-width:var(--gramlot-popup-available-width,100vw);position:fixed;inset:auto;margin:0;padding:var(--gramlot-popup-padding,4px);box-sizing:border-box;max-height:min(var(--gramlot-choice-max-height,
|
|
29
|
-
border:1px solid var(--gramlot-border-control,#aab4c2);border-radius:var(--gramlot-radius-sm,4px);background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);font:inherit;box-shadow:var(--gramlot-shadow,0 3px 9px #0002)}
|
|
30
|
-
.choices[hidden]{display:none} .choice{min-height:var(--gramlot-touch-target,0px);display:flex;align-items:center;padding
|
|
29
|
+
.choices{min-width:min(var(--gramlot-choice-popup-min-width,0px),var(--gramlot-popup-available-width,100vw));max-width:var(--gramlot-popup-available-width,100vw);position:fixed;inset:auto;margin:0;padding:var(--gramlot-popup-padding,4px);box-sizing:border-box;max-height:min(var(--gramlot-choice-max-height,20rem),var(--gramlot-popup-available-height,100vh));overflow:auto;
|
|
30
|
+
border:1px solid var(--gramlot-border-control,#aab4c2);border-radius:var(--gramlot-radius-sm,4px);background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);font:inherit;font-size:var(--gramlot-field-font-size,1em);line-height:1.4;box-shadow:var(--gramlot-shadow,0 3px 9px #0002)}
|
|
31
|
+
.choices[hidden]{display:none} .choice{min-height:var(--gramlot-touch-target,0px);display:flex;align-items:center;padding:var(--gramlot-choice-item-padding,.25em .5em);border-radius:var(--gramlot-radius-sm,4px);cursor:pointer}
|
|
32
|
+
.choice:nth-child(even){background:var(--gramlot-choice-alternate-background,var(--gramlot-surface-subtle,transparent))}
|
|
33
|
+
.choice:hover{background:var(--gramlot-selected,Highlight)}
|
|
31
34
|
.choice-detail{margin-inline-start:var(--gramlot-space-3,.75rem);color:var(--gramlot-text-secondary,GrayText)}
|
|
32
35
|
.choice[aria-selected=true]{background:var(--gramlot-selected,Highlight);color:var(--gramlot-ink,HighlightText)}`;
|
|
33
36
|
this.toggle = doc.createElement('button');
|
|
@@ -54,18 +57,24 @@ export function ChoiceEditor(HTMLElement) {
|
|
|
54
57
|
if (event.isComposing || this.locked) return;
|
|
55
58
|
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
56
59
|
event.preventDefault();
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
const direction = event.key === 'ArrowDown' ? 1 : -1;
|
|
61
|
+
if (!this.#opened) this.search('', direction);
|
|
62
|
+
else this.activate(this.#active < 0 ? (direction > 0 ? 0 : this.#rows.length - 1) : Math.max(0, this.#active + direction));
|
|
59
63
|
} else if (event.key === 'Enter') {
|
|
60
64
|
event.preventDefault();
|
|
61
65
|
if (this.#opened && this.#rows[this.#active]) this.choose(this.#rows[this.#active]);
|
|
62
66
|
else this.commitDraft();
|
|
63
67
|
} else if (event.key === 'Escape') {
|
|
64
68
|
this.closeChoices(); this.#dirty = false; this.#picked = null;
|
|
65
|
-
this.resolveValue();
|
|
69
|
+
if (this.constrained) this.resolveValue();
|
|
70
|
+
else { this.control.value = this.#value ?? ''; this.error(''); }
|
|
66
71
|
}
|
|
67
72
|
});
|
|
68
|
-
this.control.addEventListener('blur', () => {
|
|
73
|
+
this.control.addEventListener('blur', () => {
|
|
74
|
+
if (!this.autoHighlight && this.#opened && this.#rows[this.#active]) this.choose(this.#rows[this.#active]);
|
|
75
|
+
else if (this.#dirty) this.commitDraft();
|
|
76
|
+
this.closeChoices();
|
|
77
|
+
});
|
|
69
78
|
}
|
|
70
79
|
createControl() {
|
|
71
80
|
const input = this.ownerDocument.createElement('input'); input.type = 'text';
|
|
@@ -74,6 +83,10 @@ export function ChoiceEditor(HTMLElement) {
|
|
|
74
83
|
input.autocomplete = 'off'; return input;
|
|
75
84
|
}
|
|
76
85
|
get constrained() { return true; }
|
|
86
|
+
get revalidateDraftOnSourceChange() { return false; }
|
|
87
|
+
get autoHighlight() { return true; }
|
|
88
|
+
get matchTypedChoice() { return true; }
|
|
89
|
+
get emptyChoice() { return null; }
|
|
77
90
|
get choiceSource() { return this.parameters.store ?? this.parameters.callback ?? this.parameters.values; }
|
|
78
91
|
get searchDelay() { return 0; }
|
|
79
92
|
textValue(text) { return text; }
|
|
@@ -95,51 +108,78 @@ export function ChoiceEditor(HTMLElement) {
|
|
|
95
108
|
this.#separator = this.parameters.separator;
|
|
96
109
|
this.#source = source;
|
|
97
110
|
this.toggle.disabled = this.locked;
|
|
111
|
+
if (changed && this.revalidateDraftOnSourceChange) this.#dirty = false;
|
|
98
112
|
if (changed) { this.#rows = []; this.#picked = null; }
|
|
99
|
-
if (changed || this.locked) this.closeChoices();
|
|
113
|
+
if (changed || this.locked) this.closeChoices({cancelLookup: changed});
|
|
100
114
|
if (changed && this.active && !this.#dirty) this.resolveValue();
|
|
101
115
|
return rest;
|
|
102
116
|
}
|
|
103
117
|
setPageContext(context) { super.setPageContext(context); this.resolveValue(); }
|
|
104
|
-
connectedCallback() { this.resolveValue(); }
|
|
118
|
+
connectedCallback() { super.connectedCallback(); this.resolveValue(); }
|
|
105
119
|
readControlValue() { return this.#value; }
|
|
106
120
|
writeControlValue(value) {
|
|
107
121
|
if (Object.is(value, this.#value)) return;
|
|
108
122
|
this.#value = value; this.#dirty = false; this.#picked = null;
|
|
109
|
-
this.closeChoices(); this.resolveValue();
|
|
123
|
+
this.closeChoices({cancelLookup: true}); this.resolveValue();
|
|
124
|
+
}
|
|
125
|
+
restoreFormDraft(text) {
|
|
126
|
+
this.closeChoices({cancelLookup:true}); this.#dirty = true; this.#picked = null; this.control.value = text;
|
|
127
|
+
}
|
|
128
|
+
restoreFormValue(value) {
|
|
129
|
+
this.#value = value; this.#dirty = false; this.#picked = null;
|
|
130
|
+
this.closeChoices({cancelLookup:true}); this.resolveValue();
|
|
110
131
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
132
|
+
validationValueCheck() {
|
|
133
|
+
const constrained = this.constrained;
|
|
134
|
+
return (value, original) => {
|
|
135
|
+
if (constrained && value !== original) throw new Error('Validation cannot replace a selected code; update the Data explicitly.');
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
validationSelection() {
|
|
139
|
+
if (!this.constrained) return super.validationSelection();
|
|
140
|
+
const rows = this.#rows.map(({id,error}) => ({id,error}));
|
|
141
|
+
const picked = this.#picked ? {id:this.#picked.id,error:this.#picked.error} : null;
|
|
142
|
+
return value => {
|
|
143
|
+
const row = picked?.id === value ? picked : rows.find(row => row.id === value);
|
|
144
|
+
if (row?.error) return {errorcode:'condition',message:row.error};
|
|
145
|
+
if (value == null || row) return true;
|
|
146
|
+
return {errorcode:'missing',message:'Choose a value from the list.'};
|
|
147
|
+
};
|
|
115
148
|
}
|
|
116
149
|
acceptControlValue() {
|
|
117
150
|
if (!this.#dirty) return this.validateCandidate(this.#value, accepted => this.writeControlValue(accepted));
|
|
118
|
-
const
|
|
119
|
-
const
|
|
151
|
+
const picked = this.#picked ?? (!this.autoHighlight && this.#opened ? this.#rows[this.#active] : null);
|
|
152
|
+
const text = picked && !this.constrained ? picked.caption : this.control.value;
|
|
153
|
+
const matches = picked ? [picked] : this.matchTypedChoice
|
|
154
|
+
? this.#rows.filter(row => row.caption === text) : [];
|
|
120
155
|
if (this.constrained && text !== '' && matches.length !== 1) {
|
|
121
156
|
this.error('Choose a value from the list.'); return {ok: false};
|
|
122
157
|
}
|
|
123
158
|
const value = this.constrained ? (text === '' ? null : matches[0].id) : this.textValue(text);
|
|
124
159
|
return this.validateCandidate(value, accepted => {
|
|
125
|
-
|
|
160
|
+
this.validationValueCheck()(accepted,value);
|
|
126
161
|
this.#value = accepted; this.#dirty = false; this.#picked = null;
|
|
127
|
-
if (!this.constrained) this.control.value = accepted ?? '';
|
|
128
|
-
this.selectionAccepted(matches.length === 1 && accepted === value ? matches[0] : null);
|
|
162
|
+
if (accepted == null || !this.constrained) this.control.value = accepted ?? '';
|
|
163
|
+
this.selectionAccepted(matches.length === 1 && accepted === value && matches[0].id !== null ? matches[0] : null);
|
|
164
|
+
if (picked && !this.autoHighlight) this.closeChoices();
|
|
129
165
|
});
|
|
130
166
|
}
|
|
131
167
|
commitDraft() {
|
|
168
|
+
this.closeChoices();
|
|
132
169
|
const Event = this.ownerDocument.defaultView.Event;
|
|
133
170
|
this.control.dispatchEvent(new Event('change', {bubbles: true}));
|
|
134
171
|
}
|
|
135
172
|
choose(row) {
|
|
136
173
|
if (this.locked || !this.active) return;
|
|
137
|
-
|
|
174
|
+
if (this.pageContext.form) this.pageContext.formSelectionError(row.error ?? '');
|
|
175
|
+
this.#picked = row; this.#dirty = true; this.control.value = row.id === null ? '' : row.caption;
|
|
138
176
|
this.closeChoices(); this.commitDraft();
|
|
139
177
|
}
|
|
140
|
-
async request(keywords) {
|
|
178
|
+
async request(keywords, {selection = false} = {}) {
|
|
141
179
|
this.#requestController?.abort();
|
|
142
180
|
const controller = new AbortController(); this.#requestController = controller;
|
|
181
|
+
this.#resolvingValue = selection || Object.hasOwn(keywords, '_id');
|
|
182
|
+
if (this.pageContext.form && this.#resolvingValue) this.pageContext.formSelectionPending(true);
|
|
143
183
|
const generation = ++this.#generation;
|
|
144
184
|
this.control.setAttribute('aria-busy', 'true'); this.error('');
|
|
145
185
|
try {
|
|
@@ -147,43 +187,65 @@ export function ChoiceEditor(HTMLElement) {
|
|
|
147
187
|
if (generation !== this.#generation || !this.active) return null;
|
|
148
188
|
return rows;
|
|
149
189
|
} catch (error) {
|
|
150
|
-
if (generation === this.#generation && this.active)
|
|
190
|
+
if (generation === this.#generation && this.active) {
|
|
191
|
+
this.error(error.message);
|
|
192
|
+
if (this.pageContext.form && this.#resolvingValue) this.pageContext.formSelectionError(error.message);
|
|
193
|
+
}
|
|
151
194
|
return null;
|
|
152
195
|
} finally {
|
|
153
|
-
if (generation === this.#generation) {
|
|
196
|
+
if (generation === this.#generation) {
|
|
197
|
+
if (this.pageContext.form && this.#resolvingValue) this.pageContext.formSelectionPending(false);
|
|
198
|
+
this.#requestController = null; this.#resolvingValue = false; this.control.setAttribute('aria-busy', 'false'); }
|
|
154
199
|
}
|
|
155
200
|
}
|
|
156
201
|
async resolveValue() {
|
|
157
|
-
if (this.#value == null || this.#value === '') {
|
|
202
|
+
if (this.#value == null || this.#value === '') {
|
|
203
|
+
if (this.pageContext?.form) { this.pageContext.formSelectionPending(false); this.pageContext.formSelectionError(''); }
|
|
204
|
+
this.control.value = ''; this.error(''); if (this.active) this.selectionResolved(null); return; }
|
|
158
205
|
if (!this.active) return;
|
|
159
206
|
this.control.value = this.#value;
|
|
160
207
|
if (!this.constrained) { this.error(''); this.selectionResolved(null); return; }
|
|
161
|
-
const
|
|
162
|
-
|
|
208
|
+
const pending = this.request({_id: this.#value});
|
|
209
|
+
const generation = this.#generation;
|
|
210
|
+
const rows = await pending;
|
|
211
|
+
if (!rows) {
|
|
212
|
+
if (generation === this.#generation && this.active) {
|
|
213
|
+
this.selectionResolved(null);
|
|
214
|
+
if (this.pageContext.form) this.pageContext.formValidate();
|
|
215
|
+
}
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
163
218
|
const row = rows.find(item => item.id === this.#value);
|
|
164
219
|
this.#rows = rows;
|
|
165
220
|
this.control.value = row ? row.caption : this.#value;
|
|
166
|
-
|
|
221
|
+
const error = row ? row.error ?? '' : 'Value is not in the list.';
|
|
222
|
+
this.error(error);
|
|
223
|
+
if (this.pageContext.form) { this.pageContext.formSelectionError(error); this.pageContext.formValidate(); }
|
|
167
224
|
this.selectionResolved(row ?? null);
|
|
168
225
|
}
|
|
169
|
-
async search(query) {
|
|
226
|
+
async search(query, navigation = 0) {
|
|
170
227
|
if (this.locked || !this.active) return;
|
|
171
228
|
this.closeChoices(); this.#rows = [];
|
|
172
229
|
const rows = await this.request({_querystring: query});
|
|
173
230
|
if (!rows || this.locked || this.shadowRoot.activeElement !== this.control) return;
|
|
174
|
-
|
|
231
|
+
const emptyChoice = this.emptyChoice;
|
|
232
|
+
this.#rows = emptyChoice ? [emptyChoice, ...rows] : rows;
|
|
175
233
|
const doc = this.ownerDocument;
|
|
176
|
-
this.choices.replaceChildren(...rows.map((row, index) => {
|
|
234
|
+
this.choices.replaceChildren(...this.#rows.map((row, index) => {
|
|
177
235
|
const item = doc.createElement('div'); item.id = `choice-${index}`;
|
|
178
236
|
item.className = 'choice'; item.setAttribute('role', 'option'); this.renderChoice(row, item);
|
|
179
237
|
item.addEventListener('click', () => this.choose(row)); return item;
|
|
180
238
|
}));
|
|
181
|
-
if (!rows.length) this.choices.textContent = 'No results';
|
|
239
|
+
if (!this.#rows.length) this.choices.textContent = 'No results';
|
|
182
240
|
const view = doc.defaultView;
|
|
183
241
|
this.choices.hidden = false; this.choices.showPopover(); this.#opened = true;
|
|
184
242
|
const inset = parseFloat(view.getComputedStyle(this).getPropertyValue('--gramlot-choice-popup-inset') || '2');
|
|
185
243
|
positionPopup(this.choices, this.control, {matchWidth: true, inset});
|
|
186
|
-
this.control.setAttribute('aria-expanded', 'true');
|
|
244
|
+
this.control.setAttribute('aria-expanded', 'true');
|
|
245
|
+
const reopening = this.constrained && !this.#dirty && query === '' && this.#value != null;
|
|
246
|
+
this.activate(reopening ? this.#rows.findIndex(row => row.id === this.#value)
|
|
247
|
+
: navigation < 0 ? this.#rows.length - 1 : navigation > 0 ? 0
|
|
248
|
+
: this.autoHighlight && rows.length ? (emptyChoice ? 1 : 0) : -1);
|
|
187
249
|
const close = () => this.closeChoices();
|
|
188
250
|
const outside = event => { if (!event.composedPath().includes(this)) close(); };
|
|
189
251
|
const scroll = event => { if (!event.composedPath().includes(this.choices)) close(); };
|
|
@@ -195,7 +257,7 @@ export function ChoiceEditor(HTMLElement) {
|
|
|
195
257
|
};
|
|
196
258
|
}
|
|
197
259
|
activate(index) {
|
|
198
|
-
this.#active = this.#rows.length
|
|
260
|
+
this.#active = this.#rows.length && index >= 0 ? Math.min(index, this.#rows.length - 1) : -1;
|
|
199
261
|
for (const [i, item] of [...this.choices.children].entries()) {
|
|
200
262
|
item.setAttribute('aria-selected', String(i === this.#active));
|
|
201
263
|
if (i === this.#active) item.scrollIntoView({block: 'nearest'});
|
|
@@ -203,16 +265,22 @@ export function ChoiceEditor(HTMLElement) {
|
|
|
203
265
|
if (this.#active < 0) this.control.removeAttribute('aria-activedescendant');
|
|
204
266
|
else this.control.setAttribute('aria-activedescendant', `choice-${this.#active}`);
|
|
205
267
|
}
|
|
206
|
-
closeChoices() {
|
|
268
|
+
closeChoices({cancelLookup = false} = {}) {
|
|
207
269
|
clearTimeout(this.#searchTimer); this.#searchTimer = null;
|
|
208
|
-
|
|
209
|
-
|
|
270
|
+
// Closing suggestions must not cancel resolution of the selected Data value.
|
|
271
|
+
if (cancelLookup || !this.#resolvingValue) {
|
|
272
|
+
if (this.pageContext?.form && this.#resolvingValue) this.pageContext.formSelectionPending(false);
|
|
273
|
+
this.#requestController?.abort(); this.#requestController = null;
|
|
274
|
+
this.#resolvingValue = false; ++this.#generation;
|
|
275
|
+
this.control.setAttribute('aria-busy', 'false');
|
|
276
|
+
}
|
|
277
|
+
this.#cleanup?.(); this.#cleanup = null;
|
|
210
278
|
if (this.#opened) this.choices.hidePopover();
|
|
211
279
|
this.#opened = false; this.choices.hidden = true;
|
|
212
|
-
this.control.setAttribute('aria-expanded', 'false');
|
|
280
|
+
this.control.setAttribute('aria-expanded', 'false');
|
|
213
281
|
this.control.removeAttribute('aria-activedescendant');
|
|
214
282
|
}
|
|
215
|
-
releaseControl() { this.closeChoices(); }
|
|
283
|
+
releaseControl() { this.closeChoices({cancelLookup: true}); }
|
|
216
284
|
disconnectedCallback() { this.releaseControl(); }
|
|
217
285
|
};
|
|
218
286
|
}
|