@gramlot/gramlot 0.3.24 → 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.
Files changed (131) hide show
  1. package/dist/components/editors/__init__.py +2 -2
  2. package/dist/components/editors/assets/collection.js +20 -19
  3. package/dist/components/editors/assets/index.js +1 -1
  4. package/dist/components/editors/assets/modules/chunk-74O4WKIV.js +1 -0
  5. package/dist/components/editors/assets/modules/{code-mirror-engine-QX4A5FVO.js → code-mirror-engine-RWQTR5G5.js} +29 -29
  6. package/dist/components/editors/assets/modules/{jodit-engine-MMSPIWM7.js → jodit-engine-MTSA4GZ3.js} +292 -292
  7. package/dist/components/editors/assets/modules/markdown-document-VFC23FAY.js +1 -0
  8. package/dist/components/editors/assets/modules/{prose-mirror-engine-IXTRTG6B.js → prose-mirror-engine-GMZPJPNN.js} +13 -13
  9. package/dist/components/grid/__init__.py +3 -2
  10. package/dist/components/grid/assets/collection.js +68 -17
  11. package/dist/components/grid/assets/index.js +1 -1
  12. package/dist/components/grid/grammar.json +57 -1
  13. package/dist/components/grouplets/__init__.py +2 -2
  14. package/dist/components/grouplets/assets/collection.js +3 -20
  15. package/dist/components/grouplets/assets/index.js +1 -1
  16. package/dist/components/grouplets/assets/modules/chunk-BLMUM44K.js +1 -0
  17. package/dist/components/grouplets/assets/modules/markdown-document-YWNZTOKK.js +1 -0
  18. package/dist/components/inputs/__init__.py +1 -1
  19. package/dist/components/inputs/assets/collection.js +59 -34
  20. package/dist/components/inputs/assets/index.js +1 -1
  21. package/dist/components/inputs/grammar.json +64 -0
  22. package/dist/components/layout/__init__.py +1 -1
  23. package/dist/components/layout/assets/collection.js +67 -57
  24. package/dist/components/layout/assets/index.js +1 -1
  25. package/dist/components/layout/grammar.json +35 -0
  26. package/dist/components/selection_trial/__init__.py +1 -1
  27. package/dist/components/selection_trial/assets/collection.js +3 -3
  28. package/dist/components/selection_trial/assets/index.js +1 -1
  29. package/dist/components/selection_trial/grammar.json +35 -0
  30. package/dist/components/tree/__init__.py +1 -1
  31. package/dist/components/tree/assets/collection.js +26 -23
  32. package/dist/components/tree/assets/index.js +1 -1
  33. package/dist/components/tree/grammar.json +341 -1
  34. package/dist/components/uploads/__init__.py +13 -0
  35. package/dist/components/uploads/assets/collection.js +67 -0
  36. package/dist/components/uploads/assets/index.js +3 -0
  37. package/dist/components/uploads/commands.json +7 -0
  38. package/dist/components/uploads/grammar.json +789 -0
  39. package/dist/{components/editors/assets/modules/chunk-OCFLP2K4.js → gramlot-markdown.js} +12 -12
  40. package/dist/gramlot.js +4910 -566
  41. package/dist/gramlot.min.js +1587 -43
  42. package/dist/runtime-notices.json +28 -0
  43. package/package.json +4 -2
  44. package/src/binding/grid-struct.js +1 -1
  45. package/src/binding/providers.js +4 -1
  46. package/src/binding/remote-resolver.js +1 -8
  47. package/src/binding/runtime.js +40 -1
  48. package/src/binding/validation-context.js +40 -0
  49. package/src/browser-camera-provider.d.ts +8 -0
  50. package/src/browser-camera-provider.js +104 -0
  51. package/src/builder/source.js +13 -2
  52. package/src/components/attachment-manager.js +160 -0
  53. package/src/components/bases.js +17 -6
  54. package/src/components/border-container.js +86 -8
  55. package/src/components/buttons.js +11 -1
  56. package/src/components/choice-editor.js +20 -7
  57. package/src/components/database-choices.js +4 -2
  58. package/src/components/editing-status-styles.js +26 -0
  59. package/src/components/editing-status.js +115 -0
  60. package/src/components/field-state.js +37 -58
  61. package/src/components/grid-cell-editor.js +181 -0
  62. package/src/components/grid-grammar.json +21 -0
  63. package/src/components/grid-structure.js +2 -1
  64. package/src/components/grid-styles.js +51 -1
  65. package/src/components/grid.js +87 -10
  66. package/src/components/grouplet-card.js +11 -3
  67. package/src/components/html-preview.js +17 -4
  68. package/src/components/image-crop-dialog.js +272 -0
  69. package/src/components/image-crop.js +79 -0
  70. package/src/components/image-uploader.js +252 -0
  71. package/src/components/inputs.js +2 -1
  72. package/src/components/jodit-engine.js +1 -1
  73. package/src/components/markdown-document.js +2 -2
  74. package/src/components/screen-capture.js +43 -0
  75. package/src/components/selected-container.js +6 -2
  76. package/src/components/tree.js +416 -17
  77. package/src/components/typed-editor.js +19 -9
  78. package/src/components/upload-engine.js +156 -0
  79. package/src/components/uploader.js +208 -0
  80. package/src/components/uploads.js +7 -0
  81. package/src/editing-session.d.ts +25 -0
  82. package/src/editing-session.js +396 -0
  83. package/src/experiments/selection-trial.js +18 -2
  84. package/src/format.js +22 -7
  85. package/src/gramlot.d.ts +2 -0
  86. package/src/gramlot.js +2 -1
  87. package/src/handlers/device-handler.d.ts +2 -1
  88. package/src/handlers/rpc-handler.d.ts +3 -3
  89. package/src/index-page-styles.js +1 -0
  90. package/src/index.d.ts +13 -0
  91. package/src/index.js +13 -0
  92. package/src/inout.d.ts +2 -0
  93. package/src/inout.js +6 -0
  94. package/src/markdown-loader.d.ts +1 -0
  95. package/src/markdown-loader.js +4 -0
  96. package/src/markdown.d.ts +1 -0
  97. package/src/markdown.js +2 -0
  98. package/src/media-frame.js +9 -0
  99. package/src/renderer/attributes.js +7 -1
  100. package/src/renderer/gramlot-renderer.d.ts +2 -0
  101. package/src/renderer/gramlot-renderer.js +31 -2
  102. package/src/server/assets.d.ts +1 -1
  103. package/src/server/assets.js +1 -1
  104. package/src/server/gramlot-server.d.ts +8 -1
  105. package/src/server/gramlot-server.js +83 -7
  106. package/src/server/index.d.ts +2 -0
  107. package/src/server/index.js +2 -0
  108. package/src/server/page-base.js +17 -4
  109. package/src/server/page.d.ts +13 -1
  110. package/src/server/page.js +6 -0
  111. package/src/server/source-import.d.ts +2 -0
  112. package/src/server/source-import.js +31 -0
  113. package/src/server/upload.d.ts +20 -0
  114. package/src/server/upload.js +142 -0
  115. package/src/server/visual-editor.d.ts +11 -0
  116. package/src/server/visual-editor.js +149 -0
  117. package/src/source-picker.d.ts +9 -0
  118. package/src/source-picker.js +57 -0
  119. package/src/tree-store.d.ts +24 -0
  120. package/src/tree-store.js +193 -0
  121. package/src/validation-run.js +50 -0
  122. package/src/view/button.js +8 -5
  123. package/src/view/controls.js +9 -42
  124. package/src/view/html.js +10 -2
  125. package/src/visual-editor-icons.js +10 -0
  126. package/src/visual-editor.d.ts +56 -0
  127. package/src/visual-editor.js +844 -0
  128. package/themes/gramlot-base/theme.css +99 -0
  129. package/dist/components/editors/assets/modules/chunk-MMJXUHRQ.js +0 -3
  130. package/src/form-state.d.ts +0 -20
  131. 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,26 @@ 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() {
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); }
44
55
  shouldProjectControlValue() { return true; }
45
56
  acceptControlValue() {
46
57
  const value = this.readControlValue();
47
58
  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.');
59
+ this.validationValueCheck()(accepted,value);
50
60
  if (!this.sameControlValue(value, accepted)) this.writeControlValue(accepted);
51
61
  });
52
62
  }
63
+ restoreFormDraft(text) { this.control.value = text; }
53
64
  restoreFormValue(value) { this.writeControlValue(value); }
54
65
  sameControlValue(a, b) { return Object.is(a, b); }
55
66
  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'}
@@ -122,16 +122,29 @@ export function ChoiceEditor(HTMLElement) {
122
122
  this.#value = value; this.#dirty = false; this.#picked = null;
123
123
  this.closeChoices({cancelLookup: true}); this.resolveValue();
124
124
  }
125
+ restoreFormDraft(text) {
126
+ this.closeChoices({cancelLookup:true}); this.#dirty = true; this.#picked = null; this.control.value = text;
127
+ }
125
128
  restoreFormValue(value) {
126
129
  this.#value = value; this.#dirty = false; this.#picked = null;
127
130
  this.closeChoices({cancelLookup:true}); this.resolveValue();
128
131
  }
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.'};
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
+ };
135
148
  }
136
149
  acceptControlValue() {
137
150
  if (!this.#dirty) return this.validateCandidate(this.#value, accepted => this.writeControlValue(accepted));
@@ -144,7 +157,7 @@ export function ChoiceEditor(HTMLElement) {
144
157
  }
145
158
  const value = this.constrained ? (text === '' ? null : matches[0].id) : this.textValue(text);
146
159
  return this.validateCandidate(value, accepted => {
147
- if (accepted !== value && this.constrained) throw new Error('Validation cannot replace a selected code; update the Data explicitly.');
160
+ this.validationValueCheck()(accepted,value);
148
161
  this.#value = accepted; this.#dirty = false; this.#picked = null;
149
162
  if (accepted == null || !this.constrained) this.control.value = accepted ?? '';
150
163
  this.selectionAccepted(matches.length === 1 && accepted === value && matches[0].id !== null ? matches[0] : null);
@@ -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())) {
@@ -0,0 +1,26 @@
1
+ /** Theme-owned colors; compact reports are shared by forms and grids. */
2
+ export const editingStatusStyles = `
3
+ :host{display:inline-block;font:inherit;color:var(--gramlot-ink,CanvasText)}
4
+ .control-box{display:flex;align-items:center;gap:.35rem}
5
+ button{font:inherit;color:inherit;cursor:pointer;border:0;background:transparent;border-radius:var(--gramlot-radius-sm,4px)}
6
+ .control-box>button{display:inline-flex;align-items:center;gap:.4rem;padding:.3rem .5rem;white-space:nowrap}
7
+ button:hover{background:var(--gramlot-surface-subtle,ButtonFace)}
8
+ button:focus-visible{outline:1px solid var(--gramlot-focus-ring,Highlight);outline-offset:-1px}
9
+ svg{width:1rem;height:1rem;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linejoin:round;stroke-linecap:round}
10
+ .count{font-variant-numeric:tabular-nums;color:var(--gramlot-text-secondary,GrayText)}
11
+ .invalid{color:var(--gramlot-error,#b3261e)}
12
+ .report{position:fixed;inset:auto;margin:0;padding:.65rem;min-width:15rem;width:28rem;
13
+ max-width:var(--gramlot-popup-available-width,calc(100vw - 16px));max-height:var(--gramlot-popup-available-height,60vh);overflow:auto;
14
+ border:1px solid var(--gramlot-border,ButtonBorder);border-radius:var(--gramlot-radius-md,8px);
15
+ background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);box-shadow:0 6px 24px #0002;font:inherit}
16
+ header{display:flex;align-items:center;justify-content:space-between;gap:1rem;padding:0 .35rem .45rem}
17
+ header button{font-size:1.2em;line-height:1;padding:.25rem .4rem}
18
+ ul{list-style:none;margin:0;padding:0}
19
+ li+li{border-top:1px solid var(--gramlot-border,ButtonBorder)}
20
+ li button{display:block;width:100%;text-align:start;padding:.55rem .35rem}
21
+ .field{display:block;font-weight:600;overflow-wrap:anywhere}
22
+ .detail{display:block;white-space:pre-wrap;overflow-wrap:anywhere;margin-top:.2rem}
23
+ .previous,.notice{color:var(--gramlot-text-secondary,GrayText)}
24
+ .arrow{padding:0 .5rem}
25
+ .notice{font-size:.9em;margin:.5rem .35rem .15rem}
26
+ `;