@gramlot/gramlot 0.3.24 → 0.3.27

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.
Files changed (144) hide show
  1. package/dist/components/chat/__init__.py +1 -1
  2. package/dist/components/chat/assets/collection.js +3 -3
  3. package/dist/components/chat/assets/index.js +1 -1
  4. package/dist/components/editors/__init__.py +2 -2
  5. package/dist/components/editors/assets/collection.js +21 -20
  6. package/dist/components/editors/assets/index.js +1 -1
  7. package/dist/components/editors/assets/modules/chunk-74O4WKIV.js +1 -0
  8. package/dist/components/editors/assets/modules/{code-mirror-engine-QX4A5FVO.js → code-mirror-engine-RWQTR5G5.js} +29 -29
  9. package/dist/components/editors/assets/modules/{jodit-engine-MMSPIWM7.js → jodit-engine-MTSA4GZ3.js} +292 -292
  10. package/dist/components/editors/assets/modules/markdown-document-VFC23FAY.js +1 -0
  11. package/dist/components/editors/assets/modules/{prose-mirror-engine-IXTRTG6B.js → prose-mirror-engine-GMZPJPNN.js} +13 -13
  12. package/dist/components/grid/__init__.py +3 -2
  13. package/dist/components/grid/assets/collection.js +77 -17
  14. package/dist/components/grid/assets/index.js +1 -1
  15. package/dist/components/grid/grammar.json +78 -1
  16. package/dist/components/grouplets/__init__.py +2 -2
  17. package/dist/components/grouplets/assets/collection.js +3 -20
  18. package/dist/components/grouplets/assets/index.js +1 -1
  19. package/dist/components/grouplets/assets/modules/chunk-BLMUM44K.js +1 -0
  20. package/dist/components/grouplets/assets/modules/markdown-document-YWNZTOKK.js +1 -0
  21. package/dist/components/inputs/__init__.py +1 -1
  22. package/dist/components/inputs/assets/collection.js +59 -34
  23. package/dist/components/inputs/assets/index.js +1 -1
  24. package/dist/components/inputs/grammar.json +64 -0
  25. package/dist/components/layout/__init__.py +1 -1
  26. package/dist/components/layout/assets/collection.js +67 -57
  27. package/dist/components/layout/assets/index.js +1 -1
  28. package/dist/components/layout/grammar.json +35 -0
  29. package/dist/components/selection_trial/__init__.py +1 -1
  30. package/dist/components/selection_trial/assets/collection.js +3 -3
  31. package/dist/components/selection_trial/assets/index.js +1 -1
  32. package/dist/components/selection_trial/grammar.json +35 -0
  33. package/dist/components/tree/__init__.py +1 -1
  34. package/dist/components/tree/assets/collection.js +26 -23
  35. package/dist/components/tree/assets/index.js +1 -1
  36. package/dist/components/tree/grammar.json +341 -1
  37. package/dist/components/typst/__init__.py +1 -1
  38. package/dist/components/typst/assets/collection.js +3 -3
  39. package/dist/components/typst/assets/index.js +1 -1
  40. package/dist/components/uploads/__init__.py +13 -0
  41. package/dist/components/uploads/assets/collection.js +67 -0
  42. package/dist/components/uploads/assets/index.js +3 -0
  43. package/dist/components/uploads/commands.json +7 -0
  44. package/dist/components/uploads/grammar.json +789 -0
  45. package/dist/{components/editors/assets/modules/chunk-OCFLP2K4.js → gramlot-markdown.js} +12 -12
  46. package/dist/gramlot.js +5455 -573
  47. package/dist/gramlot.min.js +1588 -43
  48. package/dist/runtime-notices.json +28 -0
  49. package/package.json +4 -2
  50. package/src/binding/grid-struct.js +1 -1
  51. package/src/binding/providers.js +4 -1
  52. package/src/binding/remote-resolver.js +1 -8
  53. package/src/binding/runtime.js +40 -1
  54. package/src/binding/validation-context.js +41 -0
  55. package/src/browser-camera-provider.d.ts +8 -0
  56. package/src/browser-camera-provider.js +104 -0
  57. package/src/builder/source.js +13 -2
  58. package/src/components/attachment-manager.js +160 -0
  59. package/src/components/bases.js +19 -6
  60. package/src/components/border-container.js +86 -8
  61. package/src/components/buttons.js +11 -1
  62. package/src/components/choice-editor.js +44 -16
  63. package/src/components/database-choices.js +13 -8
  64. package/src/components/editing-status-styles.js +26 -0
  65. package/src/components/editing-status.js +115 -0
  66. package/src/components/field-state.js +44 -58
  67. package/src/components/grid-cell-editor.js +245 -0
  68. package/src/components/grid-grammar.json +42 -0
  69. package/src/components/grid-structure.js +5 -1
  70. package/src/components/grid-styles.js +60 -1
  71. package/src/components/grid.js +103 -11
  72. package/src/components/grouplet-card.js +11 -3
  73. package/src/components/html-preview.js +17 -4
  74. package/src/components/image-crop-dialog.js +272 -0
  75. package/src/components/image-crop.js +79 -0
  76. package/src/components/image-uploader.js +252 -0
  77. package/src/components/inputs.js +4 -3
  78. package/src/components/jodit-engine.js +1 -1
  79. package/src/components/markdown-document.js +2 -2
  80. package/src/components/parameters.js +6 -2
  81. package/src/components/screen-capture.js +43 -0
  82. package/src/components/selected-container.js +6 -2
  83. package/src/components/tree.js +417 -17
  84. package/src/components/typed-editor.js +19 -9
  85. package/src/components/upload-engine.js +156 -0
  86. package/src/components/uploader.js +208 -0
  87. package/src/components/uploads.js +7 -0
  88. package/src/components/validation.js +1 -1
  89. package/src/editing-session.d.ts +26 -0
  90. package/src/editing-session.js +494 -0
  91. package/src/editor-values.js +57 -0
  92. package/src/experiments/selection-trial.js +18 -2
  93. package/src/format.js +22 -7
  94. package/src/gramlot.d.ts +3 -0
  95. package/src/gramlot.js +9 -5
  96. package/src/handlers/device-handler.d.ts +2 -1
  97. package/src/handlers/rpc-handler.d.ts +3 -3
  98. package/src/index-page-styles.js +1 -0
  99. package/src/index.d.ts +14 -1
  100. package/src/index.js +13 -0
  101. package/src/inout.d.ts +2 -0
  102. package/src/inout.js +6 -0
  103. package/src/markdown-loader.d.ts +1 -0
  104. package/src/markdown-loader.js +4 -0
  105. package/src/markdown.d.ts +1 -0
  106. package/src/markdown.js +2 -0
  107. package/src/media-frame.js +9 -0
  108. package/src/renderer/attributes.js +7 -1
  109. package/src/renderer/gramlot-renderer.d.ts +3 -0
  110. package/src/renderer/gramlot-renderer.js +42 -2
  111. package/src/server/assets.d.ts +1 -1
  112. package/src/server/assets.js +1 -1
  113. package/src/server/gramlot-server.d.ts +8 -1
  114. package/src/server/gramlot-server.js +83 -7
  115. package/src/server/index.d.ts +2 -0
  116. package/src/server/index.js +2 -0
  117. package/src/server/page-base.js +17 -4
  118. package/src/server/page.d.ts +13 -1
  119. package/src/server/page.js +6 -0
  120. package/src/server/source-import.d.ts +2 -0
  121. package/src/server/source-import.js +35 -0
  122. package/src/server/upload.d.ts +20 -0
  123. package/src/server/upload.js +142 -0
  124. package/src/server/visual-editor.d.ts +11 -0
  125. package/src/server/visual-editor.js +159 -0
  126. package/src/source-picker.d.ts +9 -0
  127. package/src/source-picker.js +56 -0
  128. package/src/tree-store.d.ts +24 -0
  129. package/src/tree-store.js +193 -0
  130. package/src/validation-run.js +50 -0
  131. package/src/view/button.js +8 -5
  132. package/src/view/controls.js +9 -42
  133. package/src/view/html.js +10 -2
  134. package/src/visual-editor-canvas.js +29 -0
  135. package/src/visual-editor-catalogue.js +34 -0
  136. package/src/visual-editor-icons.js +10 -0
  137. package/src/visual-editor.d.ts +61 -0
  138. package/src/visual-editor.js +1062 -0
  139. package/themes/gramlot-base/theme.css +141 -0
  140. package/tools/gramlot-tools-inspector.js +1 -1
  141. package/tools/inspector-agent.js +1 -1
  142. package/dist/components/editors/assets/modules/chunk-MMJXUHRQ.js +0 -3
  143. package/src/form-state.d.ts +0 -20
  144. package/src/form-state.js +0 -198
@@ -0,0 +1,160 @@
1
+ /** Application-owned attachment operations, composed with the shared upload queue. */
2
+ import {Bag} from '@gramlot/gramlot';
3
+ import {toTytx} from '@genrojs/tytx';
4
+ import {defineComponent} from './registry.js';
5
+ import {Container} from './container.js';
6
+ import {readUploadContext} from './upload-engine.js';
7
+ import {randomId} from '../random-id.js';
8
+
9
+ export const AttachmentManager = defineComponent({
10
+ name:'attachmentManager', tag:'gramlot-attachment-manager', base:Container, sourceContext:true, bagStore:true,
11
+ parameters:{operation:{dtype:'T'},storepath:{dtype:'T'},contextPath:{dtype:'T'},
12
+ ready:{dtype:'B',default:false,binding:'read'},listMethod:{dtype:'T'},readMethod:{dtype:'T'},removeMethod:{dtype:'T'},
13
+ accept:{dtype:'T',default:'',binding:'read'},disabled:{dtype:'B',default:false,binding:'read'},
14
+ selectedPath:{dtype:'T',nullable:true,default:null,binding:'twoWay'}},
15
+ implementation: Base => class extends Base {
16
+ #context; #store; #subscription; #generation=0; #listSequence=0; #previewSequence=0; #disposed=false; #removeToken=null;
17
+ get #state() { return this.#context.sourceNode.attachmentState; }
18
+ get #contextKey() { return this.#state.getItem('contextKey'); }
19
+ set #contextKey(value) { this.#state.setItem('contextKey', value); }
20
+ get #selected() { return this.#state.getItem('selected'); }
21
+ set #selected(value) { this.#state.setItem('selected', value); }
22
+ get #list() { return this.#state.getItem('items'); }
23
+ set #list(value) { this.#state.setItem('items', value); }
24
+ constructor() {
25
+ super(); this.control.replaceChildren(); const doc=this.ownerDocument;
26
+ const style=doc.createElement('style');
27
+ style.textContent=':host{display:block} .attachments{display:grid;gap:.75em} .attachment-list{padding-inline-start:1.2em} .preview img{max-width:100%;max-height:240px} button{font:inherit}';
28
+ const box=doc.createElement('div'); box.className='attachments';
29
+ this.uploader=doc.createElement('gramlot-uploader');
30
+ const heading=doc.createElement('strong'); heading.textContent='Attachments';
31
+ this.list=doc.createElement('ul'); this.list.className='attachment-list'; this.list.setAttribute('aria-label','Attachments');
32
+ this.preview=doc.createElement('div'); this.preview.className='preview'; this.preview.setAttribute('aria-label','Attachment preview');
33
+ this.removeButton=doc.createElement('button'); this.removeButton.type='button'; this.removeButton.textContent='Remove attachment';
34
+ this.message=doc.createElement('div'); this.message.setAttribute('role','status');
35
+ box.append(this.uploader,heading,this.list,this.preview,this.removeButton,this.message); this.control.append(box); this.shadowRoot.append(style);
36
+ this.removeButton.addEventListener('click',()=>void this.#remove());
37
+ }
38
+ setSourceContext(context) {
39
+ this.#context=context;
40
+ if (!context.sourceNode.attachmentState) {
41
+ Object.defineProperty(context.sourceNode, 'attachmentState', {value:new Bag({
42
+ contextKey:null, selected:null, items:new Bag(), preview:null, message:''
43
+ }), configurable:true});
44
+ }
45
+ this.#message(this.#state.getItem('message'));
46
+ this.#renderPreview();
47
+ this.uploader.setSourceContext({...context,callLogic:()=>this.#refresh()});
48
+ }
49
+ setStoreBag(store) {
50
+ if (!(store instanceof Bag)) throw new TypeError('attachmentManager storepath must resolve to a Bag');
51
+ this.#store=store; this.uploader.setStoreBag(store);
52
+ }
53
+ projectAttributes(attrs,adapt) {
54
+ const rest=super.projectAttributes(attrs,adapt), p=this.parameters;
55
+ for (const name of ['operation','contextPath','listMethod','readMethod','removeMethod']) {
56
+ if (typeof p[name] !== 'string' || !p[name]) throw new TypeError(`attachmentManager requires ${name}`);
57
+ }
58
+ this.uploader.projectAttributes({operation:p.operation,storepath:p.storepath,contextPath:p.contextPath,
59
+ accept:p.accept,multiple:true,autoUpload:Boolean(p.ready),manualUpload:false,disabled:p.disabled,
60
+ selectedPath:p.selectedPath,onComplete:'attachmentComplete'},adapt);
61
+ this.#syncContext(); this.#render(); return rest;
62
+ }
63
+ connectedCallback() {
64
+ this.#disposed=false;
65
+ if (this.#context && !this.#subscription) {
66
+ const {gramlot}=this.#context.upload(); this.#subscription=`attachment-manager-${randomId()}`;
67
+ gramlot.data.subscribe(this.#subscription,{any:()=>this.#syncContext()});
68
+ }
69
+ this.#syncContext();
70
+ }
71
+ disconnectedCallback() {
72
+ // DOM relocation into a floating keeps the same Source owner and resources.
73
+ this.ownerDocument.defaultView.queueMicrotask(() => {
74
+ if (this.isConnected) return;
75
+ this.#disposed=true; this.#generation++;
76
+ if (this.#subscription) { this.#context.upload().gramlot.data.unsubscribe(this.#subscription,{any:true}); this.#subscription=null; }
77
+ });
78
+ }
79
+ #message(value) { this.#state.setItem('message',value); this.message.textContent=value; }
80
+ #renderPreview() {
81
+ this.preview.replaceChildren();
82
+ const result=this.#state.getItem('preview');
83
+ if (!result) return;
84
+ if (result.getItem('kind') === 'image') {
85
+ const image=this.ownerDocument.createElement('img'); image.src=result.getItem('src');
86
+ image.alt='Attachment preview'; this.preview.append(image);
87
+ } else {
88
+ const pre=this.ownerDocument.createElement('pre'); pre.textContent=result.getItem('text'); this.preview.append(pre);
89
+ }
90
+ }
91
+ #value() { return readUploadContext(this.#context.sourceNode,this.parameters.contextPath); }
92
+ #syncContext() {
93
+ if (!this.parameters || !this.#context || !this.isConnected || this.#disposed) return;
94
+ if (!this.parameters.ready) {
95
+ if (this.#contextKey !== null) { this.#contextKey=null; this.#generation++; this.#removeToken=null; this.#selected=null; this.#list=new Bag(); this.#state.setItem('preview',null); this.#renderPreview(); this.#render(); }
96
+ return;
97
+ }
98
+ try {
99
+ const context=this.#value(), key=toTytx(context);
100
+ if (key !== this.#contextKey) { this.#contextKey=key; this.#generation++; this.#removeToken=null; this.#selected=null; this.#list=new Bag(); this.#state.setItem('preview',null); this.#renderPreview(); this.#render(); void this.#refresh(); }
101
+ } catch (error) {
102
+ if (this.#contextKey !== null) {
103
+ this.#contextKey=null; this.#generation++; this.#removeToken=null; this.#selected=null;
104
+ this.#list=new Bag(); this.#state.setItem('preview',null); this.#renderPreview(); this.#render();
105
+ }
106
+ this.#message(error.message);
107
+ }
108
+ }
109
+ async #refresh() {
110
+ if (!this.parameters.ready || this.#disposed || !this.isConnected) return;
111
+ const generation=this.#generation, sequence=++this.#listSequence;
112
+ try {
113
+ const result=await this.#context.upload().gramlot.rpc.call('data',this.parameters.listMethod,{context:this.#value()});
114
+ if (generation !== this.#generation || sequence !== this.#listSequence || this.#disposed) return;
115
+ if (!(result instanceof Bag)) throw new TypeError('Attachment list must be a Bag');
116
+ for (const node of result.getNodes()) if (typeof node.getAttr('caption') !== 'string') throw new TypeError('Attachment caption must be text');
117
+ this.#list=result;
118
+ if (this.#selected && !this.#list.getNode(this.#selected)) { this.#selected=null; this.#previewSequence++; this.#state.setItem('preview',null); this.#renderPreview(); }
119
+ this.#message(''); this.#render();
120
+ } catch (error) { if (generation === this.#generation && sequence === this.#listSequence && !this.#disposed) this.#message(`Attachments: ${error.message}`); }
121
+ }
122
+ #render() {
123
+ if (!this.parameters || !this.#context) return;
124
+ this.list.replaceChildren();
125
+ for (const node of this.#list.getNodes()) {
126
+ const item=this.ownerDocument.createElement('li'), button=this.ownerDocument.createElement('button');
127
+ button.type='button'; button.textContent=node.getAttr('caption'); button.setAttribute('aria-pressed',String(node.label===this.#selected));
128
+ button.disabled=Boolean(this.parameters.disabled || !this.parameters.ready || this.#removeToken);
129
+ button.addEventListener('click',()=>void this.#read(node.label)); item.append(button); this.list.append(item);
130
+ }
131
+ this.removeButton.disabled=Boolean(this.parameters.disabled || !this.parameters.ready || !this.#selected || this.#removeToken);
132
+ }
133
+ async #read(selected) {
134
+ if (!this.parameters.ready || this.parameters.disabled) return;
135
+ this.#selected=selected; this.#render(); this.#state.setItem('preview',null); this.#renderPreview(); const generation=this.#generation, sequence=++this.#previewSequence;
136
+ try {
137
+ const result=await this.#context.upload().gramlot.rpc.call('data',this.parameters.readMethod,{context:this.#value(),selected});
138
+ if (generation !== this.#generation || sequence !== this.#previewSequence || this.#disposed) return;
139
+ if (!(result instanceof Bag)) throw new TypeError('Attachment preview must be a Bag');
140
+ const kind=result.getItem('kind'), text=result.getItem('text'), src=result.getItem('src');
141
+ if (!((kind === 'image' && typeof src === 'string' && src) ||
142
+ (['text','message'].includes(kind) && typeof text === 'string'))) throw new TypeError('Invalid attachment preview');
143
+ this.#state.setItem('preview',result); this.#renderPreview();
144
+ this.#message('');
145
+ } catch (error) { if (generation === this.#generation && sequence === this.#previewSequence && !this.#disposed) this.#message(`Preview: ${error.message}`); }
146
+ }
147
+ async #remove() {
148
+ if (!this.#selected || !this.parameters.ready || this.parameters.disabled || this.#removeToken) return;
149
+ const selected=this.#selected, generation=this.#generation, token=this.#removeToken={};
150
+ this.#previewSequence++; this.#render();
151
+ try {
152
+ const removed=await this.#context.upload().gramlot.rpc.call('data',this.parameters.removeMethod,{context:this.#value(),selected});
153
+ if (generation !== this.#generation || this.#disposed) return;
154
+ if (removed !== true) throw new Error('Attachment was not removed');
155
+ this.#selected=null; this.#state.setItem('preview',null); this.#renderPreview(); await this.#refresh();
156
+ } catch (error) { if (generation === this.#generation && !this.#disposed) this.#message(`Remove: ${error.message}`); }
157
+ finally { if (this.#removeToken === token) { this.#removeToken=null; this.#render(); } }
158
+ }
159
+ }
160
+ });
@@ -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)}
@@ -40,16 +41,28 @@ export function controlElement(HTMLElement) {
40
41
  return {ok:true, value, isCurrent:() => this.pageContext.isActive()};
41
42
  }
42
43
  finishValidation() {}
43
- validateSelection() { throw new TypeError('validate_select requires a constrained choice editor.'); }
44
+ validationValueCheck() { return this.constructor.validationValueCheck(this.pageContext); }
45
+ static validationValueCheck() {
46
+ const nullable = this.gramlotComponent.parameters.value.nullable;
47
+ return (value, original) => {
48
+ if (value == null && !nullable) throw new TypeError('This component requires a non-null value.');
49
+ if (value != null && original != null && typeof value !== typeof original) throw new TypeError('Validation must preserve the component value type.');
50
+ };
51
+ }
52
+ validationSelection() { return this.constructor.validationSelection(this.parameters,this.pageContext); }
53
+ static validationSelection() {
54
+ return () => { throw new TypeError('validate_select requires a constrained choice editor.'); };
55
+ }
56
+ validateSelection(value) { return this.validationSelection()(value); }
44
57
  shouldProjectControlValue() { return true; }
45
58
  acceptControlValue() {
46
59
  const value = this.readControlValue();
47
60
  return this.validateCandidate(value, accepted => {
48
- if (accepted == null && !this.constructor.gramlotComponent.parameters.value.nullable) throw new TypeError('This component requires a non-null value.');
49
- if (accepted != null && value != null && typeof accepted !== typeof value) throw new TypeError('Validation must preserve the component value type.');
61
+ this.validationValueCheck()(accepted,value);
50
62
  if (!this.sameControlValue(value, accepted)) this.writeControlValue(accepted);
51
63
  });
52
64
  }
65
+ restoreFormDraft(text) { this.control.value = text; }
53
66
  restoreFormValue(value) { this.writeControlValue(value); }
54
67
  sameControlValue(a, b) { return Object.is(a, b); }
55
68
  focus(options) { this.control.focus(options); }
@@ -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 createDOMPurify from 'dompurify';
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'}
@@ -82,7 +82,8 @@ export function ChoiceEditor(HTMLElement) {
82
82
  input.setAttribute('aria-controls', 'choices'); input.setAttribute('aria-expanded', 'false');
83
83
  input.autocomplete = 'off'; return input;
84
84
  }
85
- get constrained() { return true; }
85
+ static get constrained() { return true; }
86
+ get constrained() { return this.constructor.constrained; }
86
87
  get revalidateDraftOnSourceChange() { return false; }
87
88
  get autoHighlight() { return true; }
88
89
  get matchTypedChoice() { return true; }
@@ -122,16 +123,35 @@ export function ChoiceEditor(HTMLElement) {
122
123
  this.#value = value; this.#dirty = false; this.#picked = null;
123
124
  this.closeChoices({cancelLookup: true}); this.resolveValue();
124
125
  }
126
+ restoreFormDraft(text) {
127
+ this.closeChoices({cancelLookup:true}); this.#dirty = true; this.#picked = null; this.control.value = text;
128
+ }
125
129
  restoreFormValue(value) {
126
130
  this.#value = value; this.#dirty = false; this.#picked = null;
127
131
  this.closeChoices({cancelLookup:true}); this.resolveValue();
128
132
  }
129
- validateSelection(value) {
130
- if (!this.constrained) return super.validateSelection(value);
131
- const row = this.#picked?.id === value ? this.#picked : this.#rows.find(row => row.id === value);
132
- if (row?.error) return {errorcode:'condition', message:row.error};
133
- if (value == null || row) return true;
134
- return {errorcode:'missing', message:'Choose a value from the list.'};
133
+ static validationValueCheck() {
134
+ const constrained = this.constrained;
135
+ return (value, original) => {
136
+ if (constrained && value !== original) throw new Error('Validation cannot replace a selected code; update the Data explicitly.');
137
+ };
138
+ }
139
+ static validationSelection(parameters,context) {
140
+ if (!this.constrained) return super.validationSelection(parameters,context);
141
+ return async (value,signal) => {
142
+ if (value == null) return true;
143
+ const rows = await this.loadChoices(parameters,context,{_id:value},signal);
144
+ return selectionResult(rows.find(row => row.id === value),value);
145
+ };
146
+ }
147
+ validationSelection() {
148
+ if (!this.constrained) return super.validationSelection();
149
+ const rows = this.#rows.map(({id,error}) => ({id,error}));
150
+ const picked = this.#picked ? {id:this.#picked.id,error:this.#picked.error} : null;
151
+ return value => {
152
+ const row = picked?.id === value ? picked : rows.find(row => row.id === value);
153
+ return selectionResult(row,value);
154
+ };
135
155
  }
136
156
  acceptControlValue() {
137
157
  if (!this.#dirty) return this.validateCandidate(this.#value, accepted => this.writeControlValue(accepted));
@@ -144,7 +164,7 @@ export function ChoiceEditor(HTMLElement) {
144
164
  }
145
165
  const value = this.constrained ? (text === '' ? null : matches[0].id) : this.textValue(text);
146
166
  return this.validateCandidate(value, accepted => {
147
- if (accepted !== value && this.constrained) throw new Error('Validation cannot replace a selected code; update the Data explicitly.');
167
+ this.validationValueCheck()(accepted,value);
148
168
  this.#value = accepted; this.#dirty = false; this.#picked = null;
149
169
  if (accepted == null || !this.constrained) this.control.value = accepted ?? '';
150
170
  this.selectionAccepted(matches.length === 1 && accepted === value && matches[0].id !== null ? matches[0] : null);
@@ -277,19 +297,20 @@ ChoiceEditor.parameters = {...NativeControl.parameters,
277
297
 
278
298
  export function localChoices(Base) {
279
299
  return class extends Base {
280
- loadChoices(keywords) {
300
+ loadChoices(keywords) { return this.constructor.loadChoices(this.parameters,this.pageContext,keywords); }
301
+ static loadChoices(parameters,context,keywords) {
281
302
  let rows;
282
- if (this.parameters.store != null) {
283
- if (!(this.parameters.store instanceof Bag)) throw new TypeError('store must be a Bag');
284
- if (this.parameters.values) throw new TypeError('store and values are mutually exclusive');
303
+ if (parameters.store != null) {
304
+ if (!(parameters.store instanceof Bag)) throw new TypeError('store must be a Bag');
305
+ if (parameters.values) throw new TypeError('store and values are mutually exclusive');
285
306
  const ids = new Set();
286
- rows = this.parameters.store.getNodes().map(node => {
307
+ rows = parameters.store.getNodes().map(node => {
287
308
  const id = node.staticValue, caption = node.attr.caption;
288
309
  if (typeof id !== 'string' || !id || typeof caption !== 'string' || ids.has(id)) throw new TypeError('Invalid or duplicate store choice');
289
310
  ids.add(id);
290
311
  return {id, caption};
291
312
  });
292
- } else rows = parseChoices(this.parameters.values ?? '', this.parameters.separator);
313
+ } else rows = parseChoices(parameters.values ?? '', parameters.separator);
293
314
  return rows.filter(row => Object.hasOwn(keywords, '_id') ? row.id === keywords._id
294
315
  : row.caption.toLocaleLowerCase().includes(keywords._querystring.toLocaleLowerCase()));
295
316
  }
@@ -297,8 +318,9 @@ export function localChoices(Base) {
297
318
  }
298
319
  export function callbackChoices(Base) {
299
320
  return class extends Base {
300
- async loadChoices(keywords) {
301
- const result = await this.pageContext.callLogic(this.parameters.callback, keywords);
321
+ loadChoices(keywords) { return this.constructor.loadChoices(this.parameters,this.pageContext,keywords); }
322
+ static async loadChoices(parameters,context,keywords) {
323
+ const result = await context.callLogic(parameters.callback, keywords);
302
324
  if (!result || !Array.isArray(result.rows) || typeof result.identifier !== 'string' || typeof result.caption !== 'string') {
303
325
  throw new TypeError('callbackSelect requires {rows, identifier, caption}');
304
326
  }
@@ -311,3 +333,9 @@ export function callbackChoices(Base) {
311
333
  }
312
334
  };
313
335
  }
336
+
337
+ function selectionResult(row,value) {
338
+ if (row?.error) return {errorcode:'condition',message:row.error};
339
+ if (value == null || row) return true;
340
+ return {errorcode:'missing',message:'Choose a value from the list.'};
341
+ }
@@ -1,8 +1,9 @@
1
- import createDOMPurify from 'dompurify';
1
+ import {createDOMPurify} from '@gramlot/gramlot';
2
2
 
3
3
  /** Database suggestions share the choice editor and the ordinary data RPC. */
4
4
  export const databaseParameters = {
5
5
  dbtable: {dtype:'T', binding:'read'},
6
+ caption_field: {dtype:'T', binding:'read'},
6
7
  condition: {dtype:'T', binding:'read'},
7
8
  weakCondition: {dtype:['B','T'], default:false, binding:'read'},
8
9
  method: {dtype:'T', default:'dbSelect', binding:'read'},
@@ -21,7 +22,7 @@ export const databaseParameters = {
21
22
  selectedRecord: {dtype:'T'},
22
23
  selectedCb: {dtype:'T'}
23
24
  };
24
- const requestParameters = ['dbtable','method','columns','hiddenColumns','auxColumns','order_by','limit','ignoreCase','condition','weakCondition'];
25
+ const requestParameters = ['dbtable','method','caption_field','columns','hiddenColumns','auxColumns','order_by','limit','ignoreCase','condition','weakCondition'];
25
26
 
26
27
  export function databaseChoices(Base) {
27
28
  return class extends Base {
@@ -79,6 +80,7 @@ export function databaseChoices(Base) {
79
80
  }
80
81
  this.choices.style.minWidth = this.#template
81
82
  ? 'min(var(--gramlot-choice-popup-min-width,28rem),var(--gramlot-popup-available-width,100vw))' : '';
83
+ if (this.parameters.caption_field != null && !this.parameters.caption_field.trim()) throw new TypeError('caption_field must be a nonempty field name.');
82
84
  if (this.parameters.condition != null && !this.parameters.condition.trim()) throw new TypeError('condition must be a nonempty expression.');
83
85
  if (typeof this.parameters.weakCondition !== 'boolean' &&
84
86
  (typeof this.parameters.weakCondition !== 'string' || !this.parameters.weakCondition.trim())) {
@@ -92,10 +94,7 @@ export function databaseChoices(Base) {
92
94
  for (const key of Object.keys(rest)) if (key.startsWith('condition_') || key.startsWith('selected_')) delete rest[key];
93
95
  return rest;
94
96
  }
95
- async loadChoices(keywords, signal) {
96
- const parameters = Object.fromEntries(requestParameters.filter(key => key !== 'method' && this.parameters[key] != null)
97
- .map(key => [key, this.parameters[key]]));
98
- if (parameters.weakCondition === false) delete parameters.weakCondition;
97
+ loadChoices(keywords, signal) {
99
98
  const required = new Set(Object.entries(this.#outputs).filter(([, path]) => path).map(([name]) => name.slice(9)));
100
99
  if (this.#template) {
101
100
  const walker = this.ownerDocument.createTreeWalker(this.#template, 4);
@@ -103,17 +102,23 @@ export function databaseChoices(Base) {
103
102
  for (const match of walker.currentNode.data.matchAll(/\{([A-Za-z0-9_]+)\}/g)) required.add(match[1]);
104
103
  }
105
104
  }
105
+ return this.constructor.loadChoices({...this.parameters,...this.#configuration},this.pageContext,keywords,signal,required);
106
+ }
107
+ static async loadChoices(configuration,context,keywords,signal,required = new Set()) {
108
+ const parameters = Object.fromEntries(requestParameters.filter(key => key !== 'method' && configuration[key] != null)
109
+ .map(key => [key, configuration[key]]));
110
+ if (parameters.weakCondition === false) delete parameters.weakCondition;
106
111
  if (required.size) parameters.hiddenColumns = [...new Set([
107
112
  ...(parameters.hiddenColumns ?? '').split(',').map(name => name.trim()).filter(Boolean), ...required
108
113
  ])].join(',');
109
- for (const [key, value] of Object.entries(this.#configuration)) {
114
+ for (const [key, value] of Object.entries(configuration)) {
110
115
  if (key.startsWith('condition_')) {
111
116
  const name = key.slice(10);
112
117
  if (!name || name.startsWith('_') || requestParameters.includes(name)) throw new TypeError('Invalid condition parameter.');
113
118
  parameters[name] = value;
114
119
  }
115
120
  }
116
- const result = await this.pageContext.remote(this.parameters.method, {...parameters, ...keywords}, signal);
121
+ const result = await context.remote(configuration.method, {...parameters, ...keywords}, signal);
117
122
  if (!result || !Array.isArray(result.rows) || typeof result.identifier !== 'string' || typeof result.caption !== 'string') {
118
123
  throw new TypeError('Database selectors require {rows, identifier, caption}.');
119
124
  }