@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.
- package/dist/components/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +20 -19
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/modules/chunk-74O4WKIV.js +1 -0
- package/dist/components/editors/assets/modules/{code-mirror-engine-QX4A5FVO.js → code-mirror-engine-RWQTR5G5.js} +29 -29
- package/dist/components/editors/assets/modules/{jodit-engine-MMSPIWM7.js → jodit-engine-MTSA4GZ3.js} +292 -292
- package/dist/components/editors/assets/modules/markdown-document-VFC23FAY.js +1 -0
- package/dist/components/editors/assets/modules/{prose-mirror-engine-IXTRTG6B.js → prose-mirror-engine-GMZPJPNN.js} +13 -13
- package/dist/components/grid/__init__.py +3 -2
- package/dist/components/grid/assets/collection.js +68 -17
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +57 -1
- package/dist/components/grouplets/__init__.py +2 -2
- package/dist/components/grouplets/assets/collection.js +3 -20
- package/dist/components/grouplets/assets/index.js +1 -1
- package/dist/components/grouplets/assets/modules/chunk-BLMUM44K.js +1 -0
- package/dist/components/grouplets/assets/modules/markdown-document-YWNZTOKK.js +1 -0
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +59 -34
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +64 -0
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +67 -57
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +35 -0
- package/dist/components/selection_trial/__init__.py +1 -1
- package/dist/components/selection_trial/assets/collection.js +3 -3
- package/dist/components/selection_trial/assets/index.js +1 -1
- package/dist/components/selection_trial/grammar.json +35 -0
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +26 -23
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +341 -1
- package/dist/components/uploads/__init__.py +13 -0
- package/dist/components/uploads/assets/collection.js +67 -0
- package/dist/components/uploads/assets/index.js +3 -0
- package/dist/components/uploads/commands.json +7 -0
- package/dist/components/uploads/grammar.json +789 -0
- package/dist/{components/editors/assets/modules/chunk-OCFLP2K4.js → gramlot-markdown.js} +12 -12
- package/dist/gramlot.js +4910 -566
- package/dist/gramlot.min.js +1587 -43
- package/dist/runtime-notices.json +28 -0
- package/package.json +4 -2
- package/src/binding/grid-struct.js +1 -1
- package/src/binding/providers.js +4 -1
- package/src/binding/remote-resolver.js +1 -8
- package/src/binding/runtime.js +40 -1
- package/src/binding/validation-context.js +40 -0
- package/src/browser-camera-provider.d.ts +8 -0
- package/src/browser-camera-provider.js +104 -0
- package/src/builder/source.js +13 -2
- package/src/components/attachment-manager.js +160 -0
- package/src/components/bases.js +17 -6
- package/src/components/border-container.js +86 -8
- package/src/components/buttons.js +11 -1
- package/src/components/choice-editor.js +20 -7
- package/src/components/database-choices.js +4 -2
- package/src/components/editing-status-styles.js +26 -0
- package/src/components/editing-status.js +115 -0
- package/src/components/field-state.js +37 -58
- package/src/components/grid-cell-editor.js +181 -0
- package/src/components/grid-grammar.json +21 -0
- package/src/components/grid-structure.js +2 -1
- package/src/components/grid-styles.js +51 -1
- package/src/components/grid.js +87 -10
- package/src/components/grouplet-card.js +11 -3
- package/src/components/html-preview.js +17 -4
- package/src/components/image-crop-dialog.js +272 -0
- package/src/components/image-crop.js +79 -0
- package/src/components/image-uploader.js +252 -0
- package/src/components/inputs.js +2 -1
- package/src/components/jodit-engine.js +1 -1
- package/src/components/markdown-document.js +2 -2
- package/src/components/screen-capture.js +43 -0
- package/src/components/selected-container.js +6 -2
- package/src/components/tree.js +416 -17
- package/src/components/typed-editor.js +19 -9
- package/src/components/upload-engine.js +156 -0
- package/src/components/uploader.js +208 -0
- package/src/components/uploads.js +7 -0
- package/src/editing-session.d.ts +25 -0
- package/src/editing-session.js +396 -0
- package/src/experiments/selection-trial.js +18 -2
- package/src/format.js +22 -7
- package/src/gramlot.d.ts +2 -0
- package/src/gramlot.js +2 -1
- package/src/handlers/device-handler.d.ts +2 -1
- package/src/handlers/rpc-handler.d.ts +3 -3
- package/src/index-page-styles.js +1 -0
- package/src/index.d.ts +13 -0
- package/src/index.js +13 -0
- package/src/inout.d.ts +2 -0
- package/src/inout.js +6 -0
- package/src/markdown-loader.d.ts +1 -0
- package/src/markdown-loader.js +4 -0
- package/src/markdown.d.ts +1 -0
- package/src/markdown.js +2 -0
- package/src/media-frame.js +9 -0
- package/src/renderer/attributes.js +7 -1
- package/src/renderer/gramlot-renderer.d.ts +2 -0
- package/src/renderer/gramlot-renderer.js +31 -2
- package/src/server/assets.d.ts +1 -1
- package/src/server/assets.js +1 -1
- package/src/server/gramlot-server.d.ts +8 -1
- package/src/server/gramlot-server.js +83 -7
- package/src/server/index.d.ts +2 -0
- package/src/server/index.js +2 -0
- package/src/server/page-base.js +17 -4
- package/src/server/page.d.ts +13 -1
- package/src/server/page.js +6 -0
- package/src/server/source-import.d.ts +2 -0
- package/src/server/source-import.js +31 -0
- package/src/server/upload.d.ts +20 -0
- package/src/server/upload.js +142 -0
- package/src/server/visual-editor.d.ts +11 -0
- package/src/server/visual-editor.js +149 -0
- package/src/source-picker.d.ts +9 -0
- package/src/source-picker.js +57 -0
- package/src/tree-store.d.ts +24 -0
- package/src/tree-store.js +193 -0
- package/src/validation-run.js +50 -0
- package/src/view/button.js +8 -5
- package/src/view/controls.js +9 -42
- package/src/view/html.js +10 -2
- package/src/visual-editor-icons.js +10 -0
- package/src/visual-editor.d.ts +56 -0
- package/src/visual-editor.js +844 -0
- package/themes/gramlot-base/theme.css +99 -0
- package/dist/components/editors/assets/modules/chunk-MMJXUHRQ.js +0 -3
- package/src/form-state.d.ts +0 -20
- package/src/form-state.js +0 -198
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/** Editable image value backed by the shared upload engine when an operation is supplied. */
|
|
2
|
+
import {Bag} from '@gramlot/gramlot';
|
|
3
|
+
import {defineComponent} from './registry.js';
|
|
4
|
+
import {controlElement} from './bases.js';
|
|
5
|
+
import {UploadEngine, readUploadContext} from './upload-engine.js';
|
|
6
|
+
import {ImageCropDialog} from './image-crop-dialog.js';
|
|
7
|
+
import {randomId} from '../random-id.js';
|
|
8
|
+
import {captureScreen} from './screen-capture.js';
|
|
9
|
+
|
|
10
|
+
export const ImageUploader = defineComponent({
|
|
11
|
+
name:'imageUploader', tag:'gramlot-image-uploader', base:controlElement, sourceContext:true, bagStore:true,
|
|
12
|
+
parameters:{value:{dtype:'T', nullable:true, default:null, binding:'twoWay'},
|
|
13
|
+
storepath:{dtype:'T'}, contextPath:{dtype:'T',nullable:true,default:null}, operation:{dtype:'T', nullable:true, default:null},
|
|
14
|
+
cropWidth:{dtype:'L', default:256}, cropHeight:{dtype:'L', default:256},
|
|
15
|
+
outputWidth:{dtype:'L', default:512}, outputHeight:{dtype:'L', default:512},
|
|
16
|
+
disabled:{dtype:'B', default:false, binding:'read'}, onComplete:{dtype:'T', nullable:true, default:null}},
|
|
17
|
+
implementation: Base => class extends Base {
|
|
18
|
+
#context; #store; #engine; #original; #dialog; #pending; #generation = 0; #projected; #written;
|
|
19
|
+
#cameraSubscription; #cameraToken = null; #cameraPending = false; #cameraAvailable = false; #cameraStatus; #screenRequest = null;
|
|
20
|
+
constructor() {
|
|
21
|
+
super();
|
|
22
|
+
const doc = this.ownerDocument;
|
|
23
|
+
this.control = doc.createElement('div'); this.controlBox.append(this.control);
|
|
24
|
+
const style = doc.createElement('style');
|
|
25
|
+
style.textContent = ':host{display:block} .image-uploader{display:grid;gap:.5em;justify-items:start} img{max-width:100%;max-height:240px} .actions{display:flex;gap:.5em;flex-wrap:wrap} button{font:inherit} .image-uploader[data-drag-over]{outline:2px dashed var(--gramlot-action,#3766b5);outline-offset:4px}';
|
|
26
|
+
const box = doc.createElement('div'); box.className = 'image-uploader';
|
|
27
|
+
this.preview = doc.createElement('img'); this.preview.alt = 'Selected image';
|
|
28
|
+
this.input = doc.createElement('input'); this.input.type = 'file'; this.input.accept = 'image/png,image/jpeg,image/webp'; this.input.hidden = true;
|
|
29
|
+
const actions = doc.createElement('div'); actions.className = 'actions';
|
|
30
|
+
const button = caption => { const el = doc.createElement('button'); el.type = 'button'; el.textContent = caption; actions.append(el); return el; };
|
|
31
|
+
this.chooseButton = button('Choose image'); this.cameraButton = button('Take photo'); this.screenButton = button('Capture screen'); this.editButton = button('Edit'); this.clearButton = button('Clear');
|
|
32
|
+
this.cancelScreenButton = button('Cancel capture'); this.cancelButton = button('Cancel upload'); this.checkButton = button('Check status');
|
|
33
|
+
this.message = doc.createElement('div'); this.message.setAttribute('role','status');
|
|
34
|
+
box.append(this.preview,this.input,actions,this.message); this.control.append(box); this.shadowRoot.append(style);
|
|
35
|
+
this.chooseButton.addEventListener('click', () => this.input.click());
|
|
36
|
+
box.addEventListener('dragover', event => {
|
|
37
|
+
if (!this.parameters?.disabled && !this.#pending && this.#cameraToken === null && !this.#screenRequest && [...event.dataTransfer.types].includes('Files')) {
|
|
38
|
+
event.preventDefault(); event.stopPropagation(); event.dataTransfer.dropEffect = 'copy'; box.setAttribute('data-drag-over','');
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
box.addEventListener('dragleave', () => box.removeAttribute('data-drag-over'));
|
|
42
|
+
box.addEventListener('drop', event => {
|
|
43
|
+
box.removeAttribute('data-drag-over');
|
|
44
|
+
if (this.parameters?.disabled || this.#pending || this.#cameraToken !== null || this.#screenRequest || ![...event.dataTransfer.types].includes('Files')) return;
|
|
45
|
+
event.preventDefault(); event.stopPropagation();
|
|
46
|
+
const files = [...event.dataTransfer.files];
|
|
47
|
+
if (files.length !== 1) { this.message.textContent = 'Select one image'; return; }
|
|
48
|
+
void this.#choose(files[0]);
|
|
49
|
+
});
|
|
50
|
+
this.cameraButton.addEventListener('click', () => this.#capture());
|
|
51
|
+
this.screenButton.addEventListener('click', () => this.#captureScreen());
|
|
52
|
+
this.cancelScreenButton.addEventListener('click', () => this.#screenRequest?.abort());
|
|
53
|
+
this.input.addEventListener('change', event => { event.stopPropagation(); const file = this.input.files[0]; this.input.value = ''; if (file) void this.#choose(file); });
|
|
54
|
+
this.editButton.addEventListener('click', () => void this.#edit());
|
|
55
|
+
this.clearButton.addEventListener('click', () => { this.#invalidate(); this.#write(null); });
|
|
56
|
+
this.cancelButton.addEventListener('click', () => { if (this.#pending) this.#engine.cancel(this.#pending.id); });
|
|
57
|
+
this.checkButton.addEventListener('click', () => void this.#check());
|
|
58
|
+
}
|
|
59
|
+
setSourceContext(context) {
|
|
60
|
+
this.#context = context;
|
|
61
|
+
if (!context.sourceNode.imageCropState) Object.defineProperty(context.sourceNode,
|
|
62
|
+
'imageCropState', {value:new Bag(), configurable:true});
|
|
63
|
+
}
|
|
64
|
+
readControlValue() { return this.parameters?.value ?? null; }
|
|
65
|
+
writeControlValue(value) { if (this.parameters) { this.parameters.value = value; this.#render(); } }
|
|
66
|
+
setStoreBag(store) {
|
|
67
|
+
if (!(store instanceof Bag)) throw new TypeError('imageUploader storepath must resolve to a Bag');
|
|
68
|
+
if (this.#store && this.#store !== store) { this.#invalidate(); this.#engine?.dispose(); this.#engine = null; }
|
|
69
|
+
this.#store = store;
|
|
70
|
+
}
|
|
71
|
+
projectAttributes(attrs, adapt) {
|
|
72
|
+
const rest = super.projectAttributes(attrs, adapt);
|
|
73
|
+
const p = this.parameters;
|
|
74
|
+
for (const key of ['cropWidth','cropHeight','outputWidth','outputHeight']) {
|
|
75
|
+
if (!Number.isSafeInteger(p[key]) || p[key] <= 0) throw new RangeError(`${key} must be a positive integer`);
|
|
76
|
+
}
|
|
77
|
+
if (p.cropWidth * p.outputHeight !== p.cropHeight * p.outputWidth) throw new RangeError('Crop and output aspect ratios must match');
|
|
78
|
+
if (this.#projected !== undefined && p.value !== this.#projected && p.value !== this.#written) this.#invalidate();
|
|
79
|
+
this.#projected = p.value; this.#written = undefined;
|
|
80
|
+
this.#ensureEngine(); if (this.#engine) this.#engine.operation = p.operation;
|
|
81
|
+
this.#render(); return rest;
|
|
82
|
+
}
|
|
83
|
+
connectedCallback() { this.#ensureEngine(); this.#observeCamera(); }
|
|
84
|
+
disconnectedCallback() {
|
|
85
|
+
// DOM relocation into a floating keeps the same Source owner and resources.
|
|
86
|
+
this.ownerDocument.defaultView.queueMicrotask(() => {
|
|
87
|
+
if (this.isConnected) return;
|
|
88
|
+
if (this.#cameraSubscription) {
|
|
89
|
+
this.#context.upload().gramlot.data.unsubscribe(this.#cameraSubscription,{any:true}); this.#cameraSubscription = null;
|
|
90
|
+
}
|
|
91
|
+
this.#invalidate(); this.#engine?.dispose(); this.#engine = null;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
#observeCamera() {
|
|
95
|
+
if (this.#cameraSubscription || !this.#context) return;
|
|
96
|
+
const {gramlot} = this.#context.upload();
|
|
97
|
+
this.#cameraSubscription = `image-uploader-camera-${randomId()}`;
|
|
98
|
+
gramlot.data.subscribe(this.#cameraSubscription,{any:event => this.#syncCamera(event)});
|
|
99
|
+
this.#syncCamera();
|
|
100
|
+
}
|
|
101
|
+
#syncCamera(event = null) {
|
|
102
|
+
const {gramlot} = this.#context.upload();
|
|
103
|
+
const available = Boolean(gramlot.dvc.provider && gramlot.dvc.provider.capabilities.includes('camera'));
|
|
104
|
+
const camera = gramlot.data.getNode('gramlot.device.camera');
|
|
105
|
+
const status = camera?.attr.status;
|
|
106
|
+
if (available !== this.#cameraAvailable || status !== this.#cameraStatus) {
|
|
107
|
+
this.#cameraAvailable = available; this.#cameraStatus = status; this.#render();
|
|
108
|
+
}
|
|
109
|
+
if (this.#cameraToken === null || event?.node !== camera) return;
|
|
110
|
+
if (status === 'pending') { this.#cameraPending = true; return; }
|
|
111
|
+
if (!this.#cameraPending || !['success','cancelled','denied','unavailable','error'].includes(status)) return;
|
|
112
|
+
const token = this.#cameraToken; this.#cameraToken = null; this.#cameraPending = false; this.#render();
|
|
113
|
+
if (status === 'success') void this.#usePhoto(camera.staticValue.getItem('url'),token);
|
|
114
|
+
else if (status !== 'cancelled') this.message.textContent = camera.attr.error?.message || 'Camera is unavailable';
|
|
115
|
+
}
|
|
116
|
+
#capture() {
|
|
117
|
+
if (!this.#cameraAvailable || this.#cameraStatus === 'pending' || this.parameters.disabled || this.#pending || this.#cameraToken !== null || this.#screenRequest) return;
|
|
118
|
+
this.#cameraToken = ++this.#generation; this.#cameraPending = false;
|
|
119
|
+
try { this.#context.sourceNode.FIRE('gramlot.device.camera?capture'); }
|
|
120
|
+
catch (error) { this.#cameraToken = null; this.message.textContent = `Camera failed: ${error.message}`; this.#render(); }
|
|
121
|
+
}
|
|
122
|
+
#captureScreen() {
|
|
123
|
+
if (this.parameters.disabled || this.#pending || this.#cameraToken !== null || this.#screenRequest || this.#dialog) return;
|
|
124
|
+
const win=this.ownerDocument.defaultView, controller=new win.AbortController(), token=++this.#generation;
|
|
125
|
+
this.#screenRequest=controller; this.message.textContent=''; this.#render();
|
|
126
|
+
const request=captureScreen({document:this.ownerDocument,signal:controller.signal});
|
|
127
|
+
void request.then(blob=>{
|
|
128
|
+
if (token !== this.#generation) return;
|
|
129
|
+
this.#screenRequest=null; this.#render();
|
|
130
|
+
return this.#choose(new win.File([blob],'screen.png',{type:'image/png'}));
|
|
131
|
+
}).catch(error=>{
|
|
132
|
+
if (token !== this.#generation) return;
|
|
133
|
+
this.#screenRequest=null; this.#render();
|
|
134
|
+
if (error.name !== 'AbortError') this.message.textContent = error.name === 'NotAllowedError' ?
|
|
135
|
+
'Screen capture was cancelled or not permitted' : `Screen capture failed: ${error.message}`;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async #usePhoto(url,token) {
|
|
139
|
+
try {
|
|
140
|
+
const candidate = await this.#load(url);
|
|
141
|
+
if (token !== this.#generation) { this.#release(candidate); return; }
|
|
142
|
+
await this.#crop(candidate,token);
|
|
143
|
+
} catch (error) { if (token === this.#generation) this.message.textContent = `Image failed: ${error.message}`; }
|
|
144
|
+
}
|
|
145
|
+
#ensureEngine() {
|
|
146
|
+
if (!this.#engine && this.#context && this.#store && this.parameters) {
|
|
147
|
+
const {gramlot,window} = this.#context.upload();
|
|
148
|
+
this.#engine = new UploadEngine({gramlot,window,store:this.#store,operation:this.parameters.operation,
|
|
149
|
+
onChange:() => this.#render(), getContext:() => readUploadContext(this.#context.sourceNode,this.parameters.contextPath), onComplete:(item,result) => this.#complete(item,result)});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
#release(candidate) { if (candidate?.objectUrl) this.ownerDocument.defaultView.URL.revokeObjectURL(candidate.objectUrl); }
|
|
153
|
+
#invalidate() {
|
|
154
|
+
this.#generation++; this.#screenRequest?.abort(); this.#screenRequest=null; this.#cameraToken = null; this.#cameraPending = false; this.#dialog?.cancel(); this.#dialog = null;
|
|
155
|
+
if (this.#pending) { this.#engine?.cancel(this.#pending.id); if (this.#pending.candidate !== this.#original) this.#release(this.#pending.candidate); this.#pending = null; }
|
|
156
|
+
this.#release(this.#original); this.#original = null;
|
|
157
|
+
}
|
|
158
|
+
#write(value) { this.#written = value; this.#context.writeParameter('value', value); }
|
|
159
|
+
#render() {
|
|
160
|
+
if (!this.parameters) return;
|
|
161
|
+
const value = this.parameters.value;
|
|
162
|
+
if (value) { this.preview.src = value; this.preview.hidden = false; } else { this.preview.removeAttribute('src'); this.preview.hidden = true; }
|
|
163
|
+
const state = this.#pending && this.#store.getItem(this.#pending.id)?.getItem('status');
|
|
164
|
+
const busy = Boolean(this.#pending || this.#cameraToken !== null || this.#screenRequest);
|
|
165
|
+
this.screenButton.hidden = !this.ownerDocument.defaultView.navigator.mediaDevices?.getDisplayMedia;
|
|
166
|
+
this.screenButton.disabled = Boolean(this.parameters.disabled || busy);
|
|
167
|
+
this.cancelScreenButton.hidden = !this.#screenRequest;
|
|
168
|
+
this.cameraButton.hidden = !this.#cameraAvailable;
|
|
169
|
+
this.cameraButton.disabled = Boolean(this.parameters.disabled || busy || this.#cameraStatus === 'pending');
|
|
170
|
+
this.chooseButton.disabled = this.editButton.disabled = this.clearButton.disabled = Boolean(this.parameters.disabled || busy);
|
|
171
|
+
this.editButton.disabled ||= !value && !this.#original;
|
|
172
|
+
this.clearButton.disabled ||= !value;
|
|
173
|
+
this.cancelButton.hidden = !['preparing','uploading'].includes(state);
|
|
174
|
+
this.checkButton.hidden = state !== 'uncertain';
|
|
175
|
+
if (state) this.message.textContent = `Upload: ${state}${this.#store.getItem(this.#pending.id).getItem('error') ? ' — ' + this.#store.getItem(this.#pending.id).getItem('error') : ''}`;
|
|
176
|
+
}
|
|
177
|
+
async #load(source, objectUrl = null) {
|
|
178
|
+
const win = this.ownerDocument.defaultView, image = new win.Image();
|
|
179
|
+
if (!objectUrl) image.crossOrigin = 'anonymous';
|
|
180
|
+
image.src = objectUrl || source;
|
|
181
|
+
try { await image.decode(); }
|
|
182
|
+
catch (error) { if (objectUrl) win.URL.revokeObjectURL(objectUrl); throw error; }
|
|
183
|
+
if (!image.naturalWidth || !image.naturalHeight) { if (objectUrl) win.URL.revokeObjectURL(objectUrl); throw new Error('Image has no dimensions'); }
|
|
184
|
+
const {cropWidth,cropHeight} = this.parameters;
|
|
185
|
+
return {image, original:source, objectUrl, transform:{x:0,y:0,zoom:Math.max(cropWidth/image.naturalWidth,cropHeight/image.naturalHeight),rotate:0}};
|
|
186
|
+
}
|
|
187
|
+
async #choose(file) {
|
|
188
|
+
if (this.parameters.disabled || this.#pending || this.#screenRequest) return;
|
|
189
|
+
if (!['image/png','image/jpeg','image/webp'].includes(file.type)) { this.message.textContent = 'Choose a PNG, JPEG or WebP image'; return; }
|
|
190
|
+
const token = ++this.#generation;
|
|
191
|
+
try {
|
|
192
|
+
const candidate = await this.#load(file, this.ownerDocument.defaultView.URL.createObjectURL(file));
|
|
193
|
+
if (token !== this.#generation) { this.#release(candidate); return; }
|
|
194
|
+
await this.#crop(candidate,token);
|
|
195
|
+
} catch (error) { if (token === this.#generation) this.message.textContent = `Image failed: ${error.message}`; }
|
|
196
|
+
}
|
|
197
|
+
async #edit() {
|
|
198
|
+
if (this.parameters.disabled || this.#pending || this.#screenRequest) return;
|
|
199
|
+
const token = ++this.#generation;
|
|
200
|
+
try {
|
|
201
|
+
const candidate = this.#original || await this.#load(this.parameters.value);
|
|
202
|
+
if (token !== this.#generation) { if (candidate !== this.#original) this.#release(candidate); return; }
|
|
203
|
+
await this.#crop(candidate,token);
|
|
204
|
+
} catch (error) { if (token === this.#generation) this.message.textContent = `Image failed: ${error.message}`; }
|
|
205
|
+
}
|
|
206
|
+
async #crop(candidate,token) {
|
|
207
|
+
const p = this.parameters;
|
|
208
|
+
const dialog = this.#dialog = new ImageCropDialog({state:this.#context.sourceNode.imageCropState,document:this.ownerDocument, original:candidate.original, image:candidate.image,
|
|
209
|
+
sourceWidth:candidate.image.naturalWidth, sourceHeight:candidate.image.naturalHeight,
|
|
210
|
+
width:p.cropWidth,height:p.cropHeight,outputWidth:p.outputWidth,outputHeight:p.outputHeight,type:'image/png',...candidate.transform});
|
|
211
|
+
let result;
|
|
212
|
+
try { result = await dialog.open(); } catch (error) { if (candidate !== this.#original) this.#release(candidate); throw error; }
|
|
213
|
+
if (this.#dialog === dialog) this.#dialog = null;
|
|
214
|
+
if (!result || token !== this.#generation) { if (candidate !== this.#original) this.#release(candidate); return; }
|
|
215
|
+
if (p.operation === null) {
|
|
216
|
+
try {
|
|
217
|
+
const data = await new Promise((resolve,reject) => { const reader = new this.ownerDocument.defaultView.FileReader();
|
|
218
|
+
reader.onload = () => resolve(reader.result); reader.onerror = () => reject(reader.error); reader.readAsDataURL(result.blob); });
|
|
219
|
+
if (token !== this.#generation) { if (candidate !== this.#original) this.#release(candidate); return; }
|
|
220
|
+
this.#commit(candidate,result.transform,data); this.message.textContent = 'Image updated';
|
|
221
|
+
} catch (error) { if (candidate !== this.#original) this.#release(candidate); throw error; }
|
|
222
|
+
} else {
|
|
223
|
+
const name = typeof candidate.original === 'string' ? 'image.png' : candidate.original.name.replace(/\.[^.]*$/, '') + '.png';
|
|
224
|
+
const file = new this.ownerDocument.defaultView.File([result.blob], name, {type:'image/png'});
|
|
225
|
+
const id = this.#engine.add(file); this.#pending = {id,candidate,transform:result.transform,token};
|
|
226
|
+
await this.#engine.start(id); this.#settle(id);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
#commit(candidate,transform,value) {
|
|
230
|
+
if (this.#original !== candidate) this.#release(this.#original);
|
|
231
|
+
candidate.transform = transform; this.#original = candidate; this.#write(value);
|
|
232
|
+
}
|
|
233
|
+
async #complete(item,result) {
|
|
234
|
+
const pending = this.#pending;
|
|
235
|
+
if (!pending || pending.id !== item.label || pending.token !== this.#generation) return;
|
|
236
|
+
if (typeof result !== 'string' || !result) throw new TypeError('Image upload must return a displayable URL');
|
|
237
|
+
this.#commit(pending.candidate,pending.transform,result);
|
|
238
|
+
this.#pending = null; this.#render();
|
|
239
|
+
if (this.parameters.onComplete) await this.#context.callLogic(this.parameters.onComplete,{item,result});
|
|
240
|
+
}
|
|
241
|
+
#settle(id) {
|
|
242
|
+
if (!this.#pending || this.#pending.id !== id) return;
|
|
243
|
+
const row = this.#store.getItem(id), state = row.getItem('status');
|
|
244
|
+
if (['failed','cancelled','completed'].includes(state)) {
|
|
245
|
+
const error = row.getItem('error');
|
|
246
|
+
if (this.#pending.candidate !== this.#original) this.#release(this.#pending.candidate);
|
|
247
|
+
this.#pending = null; this.#render(); this.message.textContent = error || `Upload: ${state}`;
|
|
248
|
+
} else this.#render();
|
|
249
|
+
}
|
|
250
|
+
async #check() { if (!this.#pending) return; const id = this.#pending.id; await this.#engine.reconcile(id); this.#settle(id); }
|
|
251
|
+
}
|
|
252
|
+
});
|
package/src/components/inputs.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {EditingStatus} from './editing-status.js';
|
|
1
2
|
import {defineComponent, defineCollection} from './registry.js';
|
|
2
3
|
import {NativeControl, ChoiceGroup} from './bases.js';
|
|
3
4
|
import {Labelbox} from './labelbox.js';
|
|
@@ -223,6 +224,6 @@ export const CheckBoxText = defineComponent({
|
|
|
223
224
|
get multiple() { return true; }
|
|
224
225
|
}
|
|
225
226
|
});
|
|
226
|
-
export default defineCollection({name: 'inputs', components: [Textbox, Checkbox, RadioButtonText,
|
|
227
|
+
export default defineCollection({name: 'inputs', components: [EditingStatus, Textbox, Checkbox, RadioButtonText,
|
|
227
228
|
TextBoxArea, Passwordbox, RadioButton, Colorpicker, HorizontalSlider, VerticalSlider,
|
|
228
229
|
NumberTextBox, DateTextBox, TimeTextBox, FilteringSelect, CallbackSelect, ComboBox, DbSelect, DbComboBox, CheckBoxText, DateCalendar]});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Locally bundled optional Jodit engine, initialized only by htmlEditor. */
|
|
2
2
|
import {Jodit} from 'jodit';
|
|
3
|
-
import createDOMPurify from '
|
|
3
|
+
import {createDOMPurify} from '@gramlot/gramlot';
|
|
4
4
|
import 'jodit/esm/plugins/clean-html/clean-html.js';
|
|
5
5
|
import 'jodit/esm/plugins/clipboard/clipboard.js';
|
|
6
6
|
import 'jodit/esm/plugins/paste/paste.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import MarkdownIt from 'markdown
|
|
2
|
-
import createDOMPurify from '
|
|
1
|
+
import MarkdownIt from '@gramlot/gramlot/markdown';
|
|
2
|
+
import {createDOMPurify} from '@gramlot/gramlot';
|
|
3
3
|
|
|
4
4
|
// Keep the rich-editor codec and ordinary previews in HTML-as-text mode.
|
|
5
5
|
export const markdownRenderer = new MarkdownIt({html:false});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Capture one frame from a user-selected browser display surface. */
|
|
2
|
+
import {captureVideoFrame} from '../media-frame.js';
|
|
3
|
+
|
|
4
|
+
export function captureScreen({document, signal}) {
|
|
5
|
+
if (signal.aborted) return Promise.reject(new DOMException('Screen capture cancelled','AbortError'));
|
|
6
|
+
const win=document.defaultView;
|
|
7
|
+
let request;
|
|
8
|
+
// Invoke synchronously in the click handler: display selection requires user activation.
|
|
9
|
+
try { request=win.navigator.mediaDevices.getDisplayMedia({video:true,audio:false}); }
|
|
10
|
+
catch (error) { return Promise.reject(error); }
|
|
11
|
+
return new Promise((resolve,reject)=>{
|
|
12
|
+
let settled=false, stream=null, drawing=false;
|
|
13
|
+
const events=new win.AbortController(), listen={signal:events.signal};
|
|
14
|
+
const video=document.createElement('video'); video.muted=true; video.autoplay=true; video.playsInline=true;
|
|
15
|
+
Object.assign(video.style,{position:'fixed',width:'1px',height:'1px',opacity:'0',pointerEvents:'none'});
|
|
16
|
+
const stop=value=>{for(const track of value.getTracks())track.stop();};
|
|
17
|
+
const release=()=>{if(stream){stop(stream);stream=null;}video.srcObject=null;video.remove();};
|
|
18
|
+
const finish=(error,blob)=>{if(settled)return;settled=true;events.abort();signal.removeEventListener('abort',abort);release();
|
|
19
|
+
if(error)reject(error);else resolve(blob);};
|
|
20
|
+
const abort=()=>finish(new DOMException('Screen capture cancelled','AbortError'));
|
|
21
|
+
signal.addEventListener('abort',abort,{once:true});
|
|
22
|
+
const draw=()=>{
|
|
23
|
+
if(settled || drawing || video.readyState < 2 || !video.videoWidth || !video.videoHeight)return;
|
|
24
|
+
drawing=true;
|
|
25
|
+
try {
|
|
26
|
+
const canvas=captureVideoFrame(document,video);release();
|
|
27
|
+
canvas.toBlob(blob=>{
|
|
28
|
+
if(!blob || blob.type!=='image/png')finish(new Error('Screen image encoding failed'));
|
|
29
|
+
else finish(null,blob);
|
|
30
|
+
},'image/png');
|
|
31
|
+
} catch(error) {finish(error);}
|
|
32
|
+
};
|
|
33
|
+
video.addEventListener('loadeddata',draw,listen);
|
|
34
|
+
if(signal.aborted){abort();}
|
|
35
|
+
request.then(async acquired=>{
|
|
36
|
+
if(settled){stop(acquired);return;}
|
|
37
|
+
stream=acquired;
|
|
38
|
+
for(const track of stream.getTracks())track.addEventListener('ended',()=>{if(!drawing)finish(new Error('Screen sharing ended'));},listen);
|
|
39
|
+
document.body.append(video);video.srcObject=stream;
|
|
40
|
+
try{await video.play();draw();}catch(error){if(!drawing)finish(error);}
|
|
41
|
+
},error=>finish(error));
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -199,7 +199,11 @@ SelectedContainer.parameters = {
|
|
|
199
199
|
selected: {dtype:'L', default:null, nullable:true, binding:'twoWay'},
|
|
200
200
|
};
|
|
201
201
|
|
|
202
|
-
const selectionChildParameters = {
|
|
202
|
+
const selectionChildParameters = {
|
|
203
|
+
pageName: {dtype:'T', nullable:true, unique:true},
|
|
204
|
+
title: {dtype:'T', default:''},
|
|
205
|
+
onClose: {inline: []},
|
|
206
|
+
};
|
|
203
207
|
|
|
204
208
|
export const StackContainer = defineComponent({
|
|
205
209
|
name:'stackContainer', tag:'gramlot-stack-container', base:SelectedContainer, subTags:'*',
|
|
@@ -209,7 +213,7 @@ export const StackContainer = defineComponent({
|
|
|
209
213
|
|
|
210
214
|
export const TabContainer = defineComponent({
|
|
211
215
|
name:'tabContainer', tag:'gramlot-tab-container', base:SelectedContainer, subTags:'*',
|
|
212
|
-
sourceContext: true, childParameters: {...selectionChildParameters, detachable:{dtype:'B'}},
|
|
216
|
+
sourceContext: true, childParameters: {...selectionChildParameters, title:{...selectionChildParameters.title, required:true}, detachable:{dtype:'B'}},
|
|
213
217
|
parameters: {
|
|
214
218
|
tabMode: {dtype:'T', default:'tabs', binding:'read', enum:['tabs','underline']},
|
|
215
219
|
tabPosition: {dtype:'T', default:'top', binding:'read', enum:['top','bottom','left','right']},
|