@svgrid/enterprise 3.1.55 → 3.1.57
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/SvGridScheduler.svelte +1 -1
- package/dist/cdn/svgrid-enterprise.svelte-external.js +365 -364
- package/dist/designer/assets/{index-QNilG6Vf.js → index-DfYT4Bxh.js} +21 -21
- package/dist/designer/index.html +1 -1
- package/dist/fields/AttachmentDialog.svelte +155 -77
- package/dist/fields/attachments.d.ts +48 -0
- package/dist/fields/attachments.js +1 -1
- package/dist/fields/base-sync.d.ts +6 -0
- package/dist/fields/base-sync.js +1 -1
- package/dist/fields/index.d.ts +1 -1
- package/dist/fields/index.js +1 -1
- package/dist/fields/messages/record.d.ts +15 -0
- package/dist/fields/messages/record.js +1 -1
- package/dist/fields/messages/viewbar.d.ts +1 -0
- package/dist/fields/messages/viewbar.js +1 -1
- package/dist/fields/messages.svelte.d.ts +16 -0
- package/dist/fields/view-model.js +1 -1
- package/dist/gantt/SvGridGantt.svelte +14 -2
- package/dist/gantt/gantt-config.d.ts +25 -0
- package/dist/gantt/gantt-model.d.ts +2 -0
- package/dist/gantt/gantt-model.js +1 -1
- package/dist/node/studio.js +1 -1
- package/dist/scheduler-config.d.ts +6 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wc/gantt-DBRJiYsr.js +115 -0
- package/dist/wc/scheduler-DJZRC1fj.js +160 -0
- package/dist/wc/sv-base-element.js +99 -91
- package/package.json +1 -1
- package/dist/wc/gantt-DkHZhrMS.js +0 -114
- package/dist/wc/scheduler-B_wTJSH8.js +0 -160
package/dist/designer/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>SvGrid Studio - Designer</title>
|
|
7
|
-
<script type="module" crossorigin src="./assets/index-
|
|
7
|
+
<script type="module" crossorigin src="./assets/index-DfYT4Bxh.js"></script>
|
|
8
8
|
<link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-Dd_uD5pT.js">
|
|
9
9
|
<link rel="modulepreload" crossorigin href="./assets/index-client-CwjHmKgT.js">
|
|
10
10
|
<link rel="modulepreload" crossorigin href="./assets/disclose-version-xihTtKlq.js">
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import{SvModal,announce}from"@svgrid/grid";import AttachmentPreview from"./AttachmentPreview.svelte";import{attachmentsFromText,formatBytes,isImage,limitAttachments,rejectReason,safeUrl,toAttachments,uploadAttachment,shrinkPhoto,takesImages}from"./attachments";import{bm}from"./messages.svelte";let{value,title,props,row,columnId,onDone,onCancel}=$props();let items=$state(toAttachments(value));let pending=$state([]);let rejected=$state([]);let urlText=$state("");let previewIndex=$state(null);let dragFrom=$state(null);let dropping=$state(false);let fileInput=$state(null);let open=$state(true);let finished=false;const busy=$derived(pending.some(p=>!p.error));
|
|
2
|
+
import{onMount}from"svelte";import{SvModal,announce}from"@svgrid/grid";import AttachmentPreview from"./AttachmentPreview.svelte";import{attachmentSources,attachmentsFromText,formatBytes,guessType,isImage,limitAttachments,newAttachmentId,rejectReason,safeUrl,toAttachments,uploadAttachment,shrinkPhoto,takesImages}from"./attachments";import{bm}from"./messages.svelte";let{value,title,props,row,columnId,onDone,onCancel}=$props();let items=$state(toAttachments(value));let pending=$state([]);let rejected=$state([]);let urlText=$state("");let previewIndex=$state(null);let dragFrom=$state(null);let dropping=$state(false);let fileInput=$state(null);let open=$state(true);let finished=false;let view=$state(items.length?"files":"add");let place=$state("device");let picking=$state(null);let pickCtl=null;const busy=$derived(pending.some(p=>!p.error));const sources=attachmentSources(props);const source=$derived(sources.find(s=>s.id===place)??null);onMount(()=>{for(const s of sources){try{s.prepare?.()}catch{}}return()=>pickCtl?.abort()});const count=()=>items.length+pending.length;function queue(name,file,load,meta){const why=rejectReason({name,type:meta.type||guessType(name),size:meta.size},props,count());if(why){rejected=[...rejected,`${name}: ${why}`];return}start({key:`${name}-${meta.size??""}-${Math.random()}`,name,file,load,getting:false,progress:0,error:null,ctl:new AbortController})}function addFiles(files){rejected=[];for(const file of files)queue(file.name,file,null,file)}function addPicked(list){rejected=[];for(const it of list){if(typeof File!=="undefined"&&it instanceof File)queue(it.name,it,null,it);else if("load"in it&&typeof it.load==="function")queue(it.name,null,it.load,it);else{const a=it;const why=rejectReason(a,props,count());if(why)rejected=[...rejected,`${a.name}: ${why}`];else items=[...items,{...a,id:a.id||newAttachmentId()}]}}}function start(p){pending=[...pending.filter(x=>x.key!==p.key),p];const set=patch=>pending=pending.map(x=>x.key===p.key?{...x,...patch}:x);const run=async()=>{let file=p.file;if(!file&&p.load){set({getting:true});file=await p.load(p.ctl.signal);if(p.ctl.signal.aborted)throw new DOMException("Stopped","AbortError");const why=rejectReason(file,props,0);if(why)throw new Error(why);set({file,getting:false})}return uploadAttachment(file,props,{row,columnId,signal:p.ctl.signal,onProgress:f=>set({progress:Math.max(0,Math.min(1,f))})})};run().then(att=>{if(p.ctl.signal.aborted)return;items=[...items,att];pending=pending.filter(x=>x.key!==p.key)},err=>{if(p.ctl.signal.aborted)return;set({getting:false,error:err instanceof Error&&err.message?err.message:bm("record.uploadFailed")})})}function retry(p){start({...p,progress:0,error:null,ctl:new AbortController})}function drop(p){p.ctl.abort();pending=pending.filter(x=>x.key!==p.key)}const touch=typeof window!=="undefined"&&typeof window.matchMedia==="function"&&window.matchMedia("(pointer: coarse)").matches;const camera=touch&&takesImages(props);let cameraInput=$state(null);async function onPhoto(e){const input=e.currentTarget;const picked=input.files?[...input.files]:[];input.value="";if(!picked.length)return;addFiles(await Promise.all(picked.map(f=>shrinkPhoto(f))));view="files"}function onPick(e){const input=e.currentTarget;const picked=input.files?[...input.files]:[];input.value="";if(!picked.length)return;addFiles(picked);view="files"}function addUrls(){const found=attachmentsFromText(urlText);if(!found.length){rejected=[bm("record.noUrlFound")];return}const{kept,rejected:refused}=limitAttachments(found,props,count());items=[...items,...kept];urlText="";rejected=refused;if(kept.length)view="files"}function openSource(s){place=s.id;if(picking)return;rejected=[];const ctl=new AbortController;pickCtl=ctl;picking=s.id;const failed=err=>{if(ctl.signal.aborted)return;picking=null;rejected=[`${s.label}: ${err instanceof Error&&err.message?err.message:bm("record.uploadFailed")}`]};let answer;try{answer=Promise.resolve(s.pick({accept:props.accept,multiple:true,max:Math.max(0,(props.maxFiles??20)-count()),signal:ctl.signal}))}catch(err){failed(err);return}answer.then(list=>{if(ctl.signal.aborted)return;picking=null;if(!list?.length)return;addPicked(list);if(count()>0)view="files"},failed)}function choose(id){const s=sources.find(x=>x.id===id);if(s)openSource(s);else place=id}function onRailKey(e,i){const keys=["ArrowDown","ArrowUp","ArrowRight","ArrowLeft","Home","End"];if(!keys.includes(e.key))return;e.preventDefault();const n=places.length;const to=e.key==="Home"?0:e.key==="End"?n-1:(i+(e.key==="ArrowDown"||e.key==="ArrowRight"?1:-1)+n)%n;const el=e.currentTarget.parentElement?.parentElement?.querySelectorAll(".sv-attd-place")[to];el?.focus()}const places=$derived([{id:"device",label:bm("record.sourceDevice"),own:"device"},{id:"link",label:bm("record.sourceLink"),own:"link"},...camera?[{id:"camera",label:bm("record.takePhoto"),own:"camera"}]:[],...sources.map(s=>({id:s.id,label:s.label,icon:s.icon}))]);function remove(i){const gone=items[i];items=items.filter((_,j)=>j!==i);if(gone)announce(bm("record.fileRemoved",{file:gone.name}))}function move(from,to){if(to<0||to>=items.length||from===to)return;const next=items.slice();const[it]=next.splice(from,1);next.splice(to,0,it);items=next}function onTileKey(e,i){if(e.target!==e.currentTarget&&(e.key==="Enter"||e.key===" "))return;if(e.altKey&&(e.key==="ArrowLeft"||e.key==="ArrowRight")){e.preventDefault();const to=i+(e.key==="ArrowRight"?1:-1);move(i,to);queueMicrotask(()=>document.querySelectorAll(".sv-attd-tile")[to]?.focus())}else if(e.key==="Delete"||e.key==="Backspace"){e.preventDefault();remove(i)}else if(e.key==="Enter"||e.key===" "){e.preventDefault();previewIndex=i}}function onPaste(e){const files=[...e.clipboardData?.files??[]];if(files.length){e.preventDefault();addFiles(files);view="files";return}const text=e.clipboardData?.getData("text")??"";if(!e.target.closest("input")&&attachmentsFromText(text).length){e.preventDefault();urlText=text;addUrls()}}function done(){if(busy)return;finished=true;pickCtl?.abort();open=false;onDone(items)}function cancel(){if(finished)return;finished=true;pickCtl?.abort();for(const p of pending)p.ctl.abort();open=false;onCancel()}const ext=a=>(a.name.split(".").pop()??"").slice(0,4).toUpperCase()||bm("record.fileBadge");
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
|
-
<SvModal bind:open title={title ?? bm('record.attachments')} width={
|
|
5
|
+
<SvModal bind:open title={title ?? bm('record.attachments')} width={720} onClose={cancel} closeOnBackdrop={!picking} closeOnEsc={!picking}>
|
|
6
6
|
|
|
7
7
|
<div
|
|
8
8
|
class="sv-attd"
|
|
9
9
|
class:is-dropping={dropping}
|
|
10
|
+
class:is-adding={view === 'add'}
|
|
10
11
|
onpaste={onPaste}
|
|
11
12
|
ondragover={(e) => {
|
|
12
13
|
if (dragFrom !== null || !e.dataTransfer?.types.includes('Files')) return
|
|
@@ -21,69 +22,156 @@ import{SvModal,announce}from"@svgrid/grid";import AttachmentPreview from"./Attac
|
|
|
21
22
|
if (dragFrom !== null || !e.dataTransfer?.files.length) return
|
|
22
23
|
e.preventDefault()
|
|
23
24
|
addFiles(e.dataTransfer.files)
|
|
25
|
+
view = 'files'
|
|
24
26
|
}}
|
|
25
27
|
>
|
|
26
|
-
{#if
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
28
|
+
{#if view === 'add'}
|
|
29
|
+
<div class="sv-attd-add">
|
|
30
|
+
<ul class="sv-attd-rail" role="tablist" aria-label={bm('record.addFrom')} aria-orientation="vertical">
|
|
31
|
+
{#each places as pl, i (pl.id)}
|
|
32
|
+
<li role="presentation">
|
|
33
|
+
<button
|
|
34
|
+
type="button"
|
|
35
|
+
role="tab"
|
|
36
|
+
class="sv-attd-place"
|
|
37
|
+
class:is-on={place === pl.id}
|
|
38
|
+
aria-selected={place === pl.id}
|
|
39
|
+
aria-controls="sv-attd-panel"
|
|
40
|
+
tabindex={place === pl.id ? 0 : -1}
|
|
41
|
+
onclick={() => choose(pl.id)}
|
|
42
|
+
onkeydown={(e) => onRailKey(e, i)}
|
|
43
|
+
>
|
|
44
|
+
<span class="sv-attd-place-icon" aria-hidden="true">
|
|
45
|
+
{#if pl.icon && safeUrl(pl.icon, true)}
|
|
46
|
+
<img src={safeUrl(pl.icon, true)} alt="" width="18" height="18" />
|
|
47
|
+
{:else if pl.own === 'device'}
|
|
48
|
+
<svg viewBox="0 0 24 24" width="18" height="18"><path d="M4 5h16v10H4zM9 19h6M12 15v4" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round" stroke-linecap="round" /></svg>
|
|
49
|
+
{:else if pl.own === 'link'}
|
|
50
|
+
<svg viewBox="0 0 24 24" width="18" height="18"><path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" /></svg>
|
|
51
|
+
{:else if pl.own === 'camera'}
|
|
52
|
+
<svg viewBox="0 0 24 24" width="18" height="18"><path d="M4 8h3l2-2h6l2 2h3v11H4z" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round" /><circle cx="12" cy="13" r="3.5" fill="none" stroke="currentColor" stroke-width="1.8" /></svg>
|
|
53
|
+
{:else}
|
|
54
|
+
<svg viewBox="0 0 24 24" width="18" height="18"><path d="M7 18a4 4 0 0 1-.6-8A6 6 0 0 1 18 9a4.5 4.5 0 0 1-.5 9z" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round" /></svg>
|
|
55
|
+
{/if}
|
|
56
|
+
</span>
|
|
57
|
+
<span class="sv-attd-place-name">{pl.label}</span>
|
|
58
|
+
</button>
|
|
59
|
+
</li>
|
|
60
|
+
{/each}
|
|
61
|
+
</ul>
|
|
62
|
+
<div class="sv-attd-panel" id="sv-attd-panel" role="tabpanel">
|
|
63
|
+
{#if place === 'link'}
|
|
64
|
+
<div class="sv-attd-center">
|
|
65
|
+
<p class="sv-attd-lead">{bm('record.linkHint')}</p>
|
|
66
|
+
<div class="sv-attd-linkrow">
|
|
67
|
+
<input
|
|
68
|
+
class="sv-attd-url"
|
|
69
|
+
type="url"
|
|
70
|
+
placeholder="https://"
|
|
71
|
+
aria-label={bm('record.addByUrl')}
|
|
72
|
+
bind:value={urlText}
|
|
73
|
+
onkeydown={(e) => {
|
|
74
|
+
if (e.key === 'Enter') {
|
|
75
|
+
e.preventDefault()
|
|
76
|
+
addUrls()
|
|
77
|
+
}
|
|
78
|
+
}}
|
|
79
|
+
/>
|
|
80
|
+
<button type="button" class="sv-attd-btn is-primary" onclick={addUrls}>{bm('record.addLink')}</button>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
{:else if place === 'camera'}
|
|
84
|
+
<div class="sv-attd-center">
|
|
85
|
+
<p class="sv-attd-lead">{bm('record.photoHint')}</p>
|
|
86
|
+
<button type="button" class="sv-attd-btn is-primary" onclick={() => cameraInput?.click()}>{bm('record.takePhoto')}</button>
|
|
87
|
+
</div>
|
|
88
|
+
{:else if source}
|
|
89
|
+
<div class="sv-attd-center">
|
|
90
|
+
{#if source.icon && safeUrl(source.icon, true)}
|
|
91
|
+
<img class="sv-attd-source-logo" src={safeUrl(source.icon, true)} alt="" width="40" height="40" />
|
|
92
|
+
{/if}
|
|
93
|
+
{#if picking === source.id}
|
|
94
|
+
<p class="sv-attd-lead" role="status">{bm('record.sourceWaiting', { source: source.label })}</p>
|
|
95
|
+
{:else}
|
|
96
|
+
<p class="sv-attd-lead">{bm('record.sourceHint', { source: source.label })}</p>
|
|
97
|
+
{/if}
|
|
98
|
+
<button type="button" class="sv-attd-btn is-primary" disabled={!!picking} onclick={() => openSource(source)}>{bm('record.openSource', { source: source.label })}</button>
|
|
99
|
+
{#if source.hint}<p class="sv-attd-note">{source.hint}</p>{/if}
|
|
100
|
+
</div>
|
|
78
101
|
{:else}
|
|
79
|
-
<
|
|
80
|
-
|
|
102
|
+
<div class="sv-attd-drop">
|
|
103
|
+
<svg viewBox="0 0 24 24" width="36" height="36" aria-hidden="true"><path d="M12 16V5M7 10l5-5 5 5M5 19h14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" /></svg>
|
|
104
|
+
<p class="sv-attd-lead">{bm('record.dropHere')}</p>
|
|
105
|
+
<p class="sv-attd-or">{bm('record.dropOr')}</p>
|
|
106
|
+
<button type="button" class="sv-attd-btn is-primary" onclick={() => fileInput?.click()}>{bm('record.chooseFiles')}</button>
|
|
107
|
+
<p class="sv-attd-note">{bm('record.pasteHint')}</p>
|
|
108
|
+
</div>
|
|
109
|
+
{/if}
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
{:else}
|
|
113
|
+
{#if items.length === 0 && pending.length === 0}
|
|
114
|
+
<p class="sv-attd-empty">{bm('record.noFilesYet')}</p>
|
|
115
|
+
{/if}
|
|
116
|
+
<ul class="sv-attd-tiles" aria-label={bm('record.files')}>
|
|
117
|
+
{#each items as a, i (a.id)}
|
|
118
|
+
<li
|
|
119
|
+
class="sv-attd-tile"
|
|
120
|
+
class:is-dragging={dragFrom === i}
|
|
121
|
+
tabindex="0"
|
|
122
|
+
draggable="true"
|
|
123
|
+
aria-label={bm('record.fileTile', { file: `${a.name}${a.size ? `, ${formatBytes(a.size)}` : ''}` })}
|
|
124
|
+
onkeydown={(e) => onTileKey(e, i)}
|
|
125
|
+
ondragstart={(e) => {
|
|
126
|
+
dragFrom = i
|
|
127
|
+
e.dataTransfer?.setData('text/plain', a.name)
|
|
128
|
+
}}
|
|
129
|
+
ondragend={() => (dragFrom = null)}
|
|
130
|
+
ondragover={(e) => {
|
|
131
|
+
if (dragFrom === null) return
|
|
132
|
+
e.preventDefault()
|
|
133
|
+
}}
|
|
134
|
+
ondrop={(e) => {
|
|
135
|
+
if (dragFrom === null) return
|
|
136
|
+
e.preventDefault()
|
|
137
|
+
move(dragFrom, i)
|
|
138
|
+
dragFrom = null
|
|
139
|
+
}}
|
|
140
|
+
>
|
|
141
|
+
<button type="button" class="sv-attd-face" onclick={() => (previewIndex = i)} tabindex="-1" aria-hidden="true">
|
|
142
|
+
{#if isImage(a) && safeUrl(a.thumbnailUrl ?? a.url, true)}
|
|
143
|
+
<img src={safeUrl(a.thumbnailUrl ?? a.url, true)} alt="" loading="lazy" decoding="async" draggable="false" />
|
|
144
|
+
{:else}
|
|
145
|
+
<span class="sv-attd-ext">{ext(a)}</span>
|
|
146
|
+
{/if}
|
|
147
|
+
</button>
|
|
148
|
+
<span class="sv-attd-name" title={a.name}>{a.name}</span>
|
|
149
|
+
<span class="sv-attd-size">{formatBytes(a.size)}</span>
|
|
150
|
+
<button type="button" class="sv-attd-remove" aria-label={bm('record.removeFile', { name: a.name })} onclick={() => remove(i)}>
|
|
81
151
|
<svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" /></svg>
|
|
82
152
|
</button>
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
153
|
+
</li>
|
|
154
|
+
{/each}
|
|
155
|
+
{#each pending as p (p.key)}
|
|
156
|
+
<li class="sv-attd-tile is-pending" aria-label={p.error ? `${p.name}: ${p.error}` : bm(p.getting ? 'record.gettingFile' : 'record.uploadingFile', { name: p.name })}>
|
|
157
|
+
<span class="sv-attd-face"><span class="sv-attd-ext">{p.error ? '!' : p.getting ? '...' : `${Math.round(p.progress * 100)}%`}</span></span>
|
|
158
|
+
<span class="sv-attd-name" title={p.name}>{p.name}</span>
|
|
159
|
+
{#if p.error}
|
|
160
|
+
<span class="sv-attd-error">{p.error}</span>
|
|
161
|
+
<span class="sv-attd-actions">
|
|
162
|
+
<button type="button" class="sv-attd-link" onclick={() => retry(p)}>{bm('record.retry')}</button>
|
|
163
|
+
<button type="button" class="sv-attd-link" onclick={() => drop(p)}>{bm('record.remove')}</button>
|
|
164
|
+
</span>
|
|
165
|
+
{:else}
|
|
166
|
+
<span class="sv-attd-bar" class:is-getting={p.getting}><span style:width={p.getting ? undefined : `${Math.round(p.progress * 100)}%`}></span></span>
|
|
167
|
+
<button type="button" class="sv-attd-remove" aria-label={bm('record.cancelUpload', { name: p.name })} onclick={() => drop(p)}>
|
|
168
|
+
<svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" /></svg>
|
|
169
|
+
</button>
|
|
170
|
+
{/if}
|
|
171
|
+
</li>
|
|
172
|
+
{/each}
|
|
173
|
+
</ul>
|
|
174
|
+
{/if}
|
|
87
175
|
{#if rejected.length}
|
|
88
176
|
<ul class="sv-attd-rejected" role="alert">
|
|
89
177
|
{#each rejected as r, i (i)}<li>{r}</li>{/each}
|
|
@@ -101,24 +189,14 @@ import{SvModal,announce}from"@svgrid/grid";import AttachmentPreview from"./Attac
|
|
|
101
189
|
hidden
|
|
102
190
|
onchange={onPick}
|
|
103
191
|
/>
|
|
104
|
-
|
|
105
|
-
{#if touch && takesImages(props)}
|
|
192
|
+
{#if camera}
|
|
106
193
|
<input bind:this={cameraInput} type="file" accept="image/*" capture="environment" hidden onchange={onPhoto} />
|
|
107
|
-
<button type="button" class="sv-attd-btn sv-attd-camera" onclick={() => cameraInput?.click()}>{bm('record.takePhoto')}</button>
|
|
108
194
|
{/if}
|
|
109
|
-
|
|
110
|
-
class="sv-attd-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
bind:value={urlText}
|
|
115
|
-
onkeydown={(e) => {
|
|
116
|
-
if (e.key === 'Enter') {
|
|
117
|
-
e.preventDefault()
|
|
118
|
-
addUrls()
|
|
119
|
-
}
|
|
120
|
-
}}
|
|
121
|
-
/>
|
|
195
|
+
{#if view === 'files'}
|
|
196
|
+
<button type="button" class="sv-attd-btn" onclick={() => { rejected = []; view = 'add' }}>{bm('record.addFiles')}</button>
|
|
197
|
+
{:else if items.length || pending.length}
|
|
198
|
+
<button type="button" class="sv-attd-btn" onclick={() => { rejected = []; view = 'files' }}>{bm('record.backToFiles')}</button>
|
|
199
|
+
{/if}
|
|
122
200
|
<span class="sv-attd-spacer"></span>
|
|
123
201
|
<button type="button" class="sv-attd-btn" onclick={cancel}>{bm('record.cancel')}</button>
|
|
124
202
|
<button type="button" class="sv-attd-btn is-primary" onclick={done} disabled={busy}>
|
|
@@ -133,5 +211,5 @@ import{SvModal,announce}from"@svgrid/grid";import AttachmentPreview from"./Attac
|
|
|
133
211
|
{/if}
|
|
134
212
|
|
|
135
213
|
<style>
|
|
136
|
-
.sv-attd{min-height:160px;border:2px dashed transparent;border-radius:8px;padding:4px}.sv-attd.is-dropping{border-color:var(--sg-accent, #2563eb)}.sv-attd-empty{margin:40px 0;text-align:center;color:var(--sg-muted, #64748b);font-size:13px}.sv-attd-tiles{list-style:none;margin:0;padding:0;display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:10px}.sv-attd-tile{position:relative;display:flex;flex-direction:column;gap:3px;padding:6px;border:1px solid var(--sg-border, #e2e8f0);border-radius:8px;background:var(--sg-bg, #fff);cursor:grab;min-width:0}.sv-attd-tile:focus-visible{outline:2px solid var(--sg-accent, #2563eb);outline-offset:1px}.sv-attd-tile.is-dragging{opacity:.4}.sv-attd-tile.is-pending{cursor:default}.sv-attd-face{display:flex;align-items:center;justify-content:center;height:96px;border:0;padding:0;border-radius:6px;overflow:hidden;background:var(--sg-header-bg, #f8fafc);cursor:zoom-in}.sv-attd-face img{width:100%;height:100%;object-fit:cover}.sv-attd-ext{font-size:13px;font-weight:600;color:var(--sg-muted, #64748b)}.sv-attd-name{font-size:12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.sv-attd-size,.sv-attd-error{font-size:11px;color:var(--sg-muted, #64748b)}.sv-attd-error{color:var(--sg-danger, #dc2626)}.sv-attd-actions{display:flex;gap:8px}.sv-attd-link{border:0;padding:0;background:none;color:inherit;text-decoration:underline;font:inherit;font-size:12px;cursor:pointer}.sv-attd-bar{height:4px;border-radius:2px;background:var(--sg-header-bg, #f8fafc);overflow:hidden}.sv-attd-bar>span{display:block;height:100%;background:var(--sg-muted, #64748b);transition:width .12s linear}.sv-attd-remove{position:absolute;top:10px;inset-inline-end:10px;display:inline-flex;padding:3px;border:0;border-radius:999px;background:var(--sg-bg, #fff);color:var(--sg-fg, #0f172a);cursor:pointer;opacity:.85}.sv-attd-remove:hover{opacity:1}.sv-attd-rejected{margin:10px 0 0;padding-inline-start:18px;font-size:12px;color:var(--sg-danger, #dc2626)}.sv-attd-footer{display:flex;align-items:center;gap:8px;width:100%}.sv-attd-spacer{flex:1}.sv-attd-url{width:220px;height:30px;padding:0 8px;font:inherit;font-size:13px;border:1px solid var(--sg-border, #e2e8f0);border-radius:6px;background:var(--sg-bg, #fff);color:var(--sg-fg, #0f172a)}.sv-attd-btn{height:30px;padding:0 12px;font:inherit;font-size:13px;cursor:pointer;border:1px solid var(--sg-border, #e2e8f0);border-radius:6px;background:var(--sg-bg, #fff);color:var(--sg-fg, #0f172a)}.sv-attd-btn.is-primary{background:var(--sg-fg, #0f172a);color:var(--sg-bg, #fff);border-color:transparent}.sv-attd-btn:disabled{opacity:.6;cursor:default}
|
|
214
|
+
.sv-attd{min-height:160px;border:2px dashed transparent;border-radius:8px;padding:4px}.sv-attd.is-dropping{border-color:var(--sg-accent, #2563eb)}.sv-attd-empty{margin:40px 0;text-align:center;color:var(--sg-muted, #64748b);font-size:13px}.sv-attd-tiles{list-style:none;margin:0;padding:0;display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:10px}.sv-attd-tile{position:relative;display:flex;flex-direction:column;gap:3px;padding:6px;border:1px solid var(--sg-border, #e2e8f0);border-radius:8px;background:var(--sg-bg, #fff);cursor:grab;min-width:0}.sv-attd-tile:focus-visible{outline:2px solid var(--sg-accent, #2563eb);outline-offset:1px}.sv-attd-tile.is-dragging{opacity:.4}.sv-attd-tile.is-pending{cursor:default}.sv-attd-face{display:flex;align-items:center;justify-content:center;height:96px;border:0;padding:0;border-radius:6px;overflow:hidden;background:var(--sg-header-bg, #f8fafc);cursor:zoom-in}.sv-attd-face img{width:100%;height:100%;object-fit:cover}.sv-attd-ext{font-size:13px;font-weight:600;color:var(--sg-muted, #64748b)}.sv-attd-name{font-size:12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.sv-attd-size,.sv-attd-error{font-size:11px;color:var(--sg-muted, #64748b)}.sv-attd-error{color:var(--sg-danger, #dc2626)}.sv-attd-actions{display:flex;gap:8px}.sv-attd-link{border:0;padding:0;background:none;color:inherit;text-decoration:underline;font:inherit;font-size:12px;cursor:pointer}.sv-attd-bar{position:relative;height:4px;border-radius:2px;background:var(--sg-header-bg, #f8fafc);overflow:hidden}.sv-attd-bar>span{display:block;height:100%;background:var(--sg-muted, #64748b);transition:width .12s linear}.sv-attd-bar.is-getting>span{width:30%;animation:sv-attd-getting 1.1s ease-in-out infinite}@keyframes sv-attd-getting{0%{transform:translate(-100%)}to{transform:translate(340%)}}@media(prefers-reduced-motion:reduce){.sv-attd-bar.is-getting>span{animation:none;width:100%;opacity:.5}}.sv-attd-remove{position:absolute;top:10px;inset-inline-end:10px;display:inline-flex;padding:3px;border:0;border-radius:999px;background:var(--sg-bg, #fff);color:var(--sg-fg, #0f172a);cursor:pointer;opacity:.85}.sv-attd-remove:hover{opacity:1}.sv-attd-rejected{margin:10px 0 0;padding-inline-start:18px;font-size:12px;color:var(--sg-danger, #dc2626)}.sv-attd.is-adding{padding:0}.sv-attd-add{display:grid;grid-template-columns:180px 1fr;min-height:300px}.sv-attd-rail{list-style:none;margin:0;padding:6px;display:flex;flex-direction:column;gap:2px;border-inline-end:1px solid var(--sg-border, #e2e8f0)}.sv-attd-place{display:flex;align-items:center;gap:10px;width:100%;padding:8px 10px;border:0;border-radius:6px;background:none;color:var(--sg-fg, #0f172a);font:inherit;font-size:13px;text-align:start;cursor:pointer}.sv-attd-place:hover{background:var(--sg-header-bg, #f8fafc)}.sv-attd-place.is-on{background:var(--sg-header-bg, #f1f5f9);font-weight:600;box-shadow:inset 3px 0 0 var(--sg-accent, #2563eb)}.sv-attd-place:focus-visible{outline:2px solid var(--sg-accent, #2563eb);outline-offset:-2px}.sv-attd-place-icon{display:inline-flex;width:20px;justify-content:center;color:var(--sg-muted, #64748b);flex:none}.sv-attd-place-icon img{width:18px;height:18px;object-fit:contain}.sv-attd-place-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.sv-attd-panel{display:flex;padding:14px;min-width:0}.sv-attd-drop,.sv-attd-center{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;text-align:center;color:var(--sg-muted, #64748b)}.sv-attd-drop{border:2px dashed var(--sg-border, #e2e8f0);border-radius:10px;padding:24px}.sv-attd.is-dropping .sv-attd-drop{border-color:var(--sg-accent, #2563eb)}.sv-attd.is-dropping.is-adding{border-color:transparent}.sv-attd-lead{margin:0;font-size:15px;color:var(--sg-fg, #0f172a)}.sv-attd-or{margin:0;font-size:12px}.sv-attd-note{margin:4px 0 0;font-size:12px;max-width:340px}.sv-attd-source-logo{width:40px;height:40px;object-fit:contain}.sv-attd-linkrow{display:flex;gap:8px;width:100%;max-width:420px}.sv-attd-linkrow .sv-attd-url{flex:1;width:auto}.sv-attd-footer{display:flex;align-items:center;gap:8px;width:100%}.sv-attd-spacer{flex:1}.sv-attd-url{width:220px;height:30px;padding:0 8px;font:inherit;font-size:13px;border:1px solid var(--sg-border, #e2e8f0);border-radius:6px;background:var(--sg-bg, #fff);color:var(--sg-fg, #0f172a)}.sv-attd-btn{height:30px;padding:0 12px;font:inherit;font-size:13px;cursor:pointer;border:1px solid var(--sg-border, #e2e8f0);border-radius:6px;background:var(--sg-bg, #fff);color:var(--sg-fg, #0f172a)}.sv-attd-btn.is-primary{background:var(--sg-fg, #0f172a);color:var(--sg-bg, #fff);border-color:transparent}.sv-attd-btn:disabled{opacity:.6;cursor:default}@media(max-width:560px){.sv-attd-add{grid-template-columns:1fr;grid-template-rows:auto 1fr;min-height:260px}.sv-attd-rail{flex-direction:row;overflow-x:auto;border-inline-end:0;border-bottom:1px solid var(--sg-border, #e2e8f0)}.sv-attd-rail>li{flex:none}.sv-attd-place{width:auto}.sv-attd-place.is-on{box-shadow:inset 0 -3px 0 var(--sg-accent, #2563eb)}}
|
|
137
215
|
</style>
|
|
@@ -35,7 +35,55 @@ export type AttachmentFieldProps = {
|
|
|
35
35
|
maxSize?: number;
|
|
36
36
|
/** Uploads a file and returns its attachment. Default: the app-wide uploader. */
|
|
37
37
|
upload?: AttachmentUploader;
|
|
38
|
+
/** More places to add files from (Google Drive, Dropbox...). Default: the app-wide ones. */
|
|
39
|
+
sources?: ReadonlyArray<AttachmentSource>;
|
|
38
40
|
};
|
|
41
|
+
/** What a source is asked for when the person opens it. */
|
|
42
|
+
export type AttachmentSourceContext = {
|
|
43
|
+
/** The field's `accept`, as for `<input accept>`. */
|
|
44
|
+
accept?: string;
|
|
45
|
+
/** Whether more than one file may be chosen. */
|
|
46
|
+
multiple: boolean;
|
|
47
|
+
/** How many more files the cell takes. */
|
|
48
|
+
max: number;
|
|
49
|
+
/** Aborted when the dialog closes before the source answers. */
|
|
50
|
+
signal: AbortSignal;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* A file a source hands over to be fetched afterwards (from Google Drive, say):
|
|
54
|
+
* it shows as a tile at once, `load` brings the file, and the uploader keeps it.
|
|
55
|
+
*/
|
|
56
|
+
export type AttachmentSourceFile = {
|
|
57
|
+
name: string;
|
|
58
|
+
type?: string;
|
|
59
|
+
size?: number;
|
|
60
|
+
load: (signal: AbortSignal) => Promise<File>;
|
|
61
|
+
};
|
|
62
|
+
/** What a source answers: files to upload, files to fetch then upload, or links kept as they are. */
|
|
63
|
+
export type AttachmentSourceItem = File | AttachmentSourceFile | Attachment;
|
|
64
|
+
/**
|
|
65
|
+
* A place the attachment dialog offers to add files from, next to the
|
|
66
|
+
* person's device and a link: Google Drive or Dropbox, through the app's own
|
|
67
|
+
* picker. `pick` is called straight from the click, so a sign-in window it
|
|
68
|
+
* opens is not blocked; `prepare` runs when the dialog opens, to load what
|
|
69
|
+
* `pick` needs before then.
|
|
70
|
+
*/
|
|
71
|
+
export type AttachmentSource = {
|
|
72
|
+
id: string;
|
|
73
|
+
/** The name in the list: 'Google Drive'. */
|
|
74
|
+
label: string;
|
|
75
|
+
/** A picture for the list (an image URL or a data: URL), about 20px. */
|
|
76
|
+
icon?: string;
|
|
77
|
+
/** A line under the button: where the files go, for one. */
|
|
78
|
+
hint?: string;
|
|
79
|
+
prepare?: () => void;
|
|
80
|
+
/** The files chosen; none when the person closed the picker. */
|
|
81
|
+
pick: (ctx: AttachmentSourceContext) => Promise<ReadonlyArray<AttachmentSourceItem>>;
|
|
82
|
+
};
|
|
83
|
+
/** The sources every attachment column offers unless its `fieldProps.sources` sets its own. */
|
|
84
|
+
export declare function setAttachmentSources(sources: ReadonlyArray<AttachmentSource> | null): void;
|
|
85
|
+
/** The sources a field offers: its own, or the app's. */
|
|
86
|
+
export declare function attachmentSources(props: AttachmentFieldProps): ReadonlyArray<AttachmentSource>;
|
|
39
87
|
/**
|
|
40
88
|
* The uploader every attachment column uses unless its `fieldProps.upload`
|
|
41
89
|
* sets one. Without any, files stay in this page as `blob:` URLs: fine for a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
let p=null;export function setAttachmentUploader(t){p=t}let
|
|
1
|
+
let c=[];export function setAttachmentSources(t){c=t??[]}export function attachmentSources(t){return t.sources??c}let p=null;export function setAttachmentUploader(t){p=t}let u=0;export const newAttachmentId=()=>`att-${Date.now().toString(36)}-${(u++).toString(36)}`;export async function uploadAttachment(t,e,o){const n=e.upload??p;return n?n(t,o):(o.onProgress(1),{id:newAttachmentId(),url:URL.createObjectURL(t),name:t.name,type:t.type||guessType(t.name),size:t.size})}export function takesImages(t){return!t.accept||t.accept.split(",").some(e=>/^\s*(image\/|\.(jpe?g|png|webp|heic|gif)\b)/i.test(e))}export async function shrinkPhoto(t,e=2e3,o=.85){if(!/^image\/(jpeg|png|webp)$/.test(t.type)||typeof createImageBitmap!="function"||typeof document>"u")return t;try{const n=await createImageBitmap(t),r=Math.min(1,e/Math.max(n.width,n.height));if(r>=1)return n.close?.(),t;const a=document.createElement("canvas");a.width=Math.round(n.width*r),a.height=Math.round(n.height*r),a.getContext("2d")?.drawImage(n,0,0,a.width,a.height),n.close?.();const i=await new Promise(m=>a.toBlob(m,"image/jpeg",o));if(!i)return t;const s=t.name.replace(/\.[^.]+$/,"")+".jpg";return new File([i],s,{type:"image/jpeg",lastModified:t.lastModified})}catch{return t}}export const tooManyFiles=t=>`At most ${t} ${t===1?"file":"files"}`;export function rejectReason(t,e,o){const n=e.maxFiles??20,r=e.maxSize??25*1024*1024;return o>=n?tooManyFiles(n):t.size!=null&&t.size>r?`Larger than ${formatBytes(r)}`:e.accept&&!accepts(e.accept,t)?"Not an accepted type":null}export function limitAttachments(t,e,o=0){const n=[],r=[];for(const a of t){const i=rejectReason(a,e,o+n.length);i?r.push(`${a.name}: ${i}`):n.push(a)}return{kept:n,rejected:r}}export function parseAttachments(t,e){const o=Array.isArray(t)?toAttachments(t):attachmentsFromText(String(t??""));return limitAttachments(o,e).kept}export function accepts(t,e){const o=e.name.toLowerCase(),n=(e.type||guessType(e.name)).toLowerCase();return t.split(",").map(r=>r.trim().toLowerCase()).filter(Boolean).some(r=>r.startsWith(".")?o.endsWith(r):r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)}const l={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",avif:"image/avif",pdf:"application/pdf",txt:"text/plain",csv:"text/csv",json:"application/json",zip:"application/zip",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",mp4:"video/mp4",webm:"video/webm",mov:"video/quicktime",mp3:"audio/mpeg",wav:"audio/wav"};export function guessType(t){const e=t.split(/[?#]/)[0].split(".").pop()?.toLowerCase()??"";return l[e]??"application/octet-stream"}export const isImage=t=>(t.type||guessType(t.name??"")).startsWith("image/"),isPdf=t=>(t.type||guessType(t.name??""))==="application/pdf";export function formatBytes(t){if(t==null||!Number.isFinite(t))return"";if(t<1024)return`${t} B`;const e=o=>o<10?o.toFixed(1).replace(/\.0$/,""):String(Math.round(o));return t<1024*1024?`${e(t/1024)} KB`:t<1024*1024*1024?`${e(t/1024/1024)} MB`:`${e(t/1024/1024/1024)} GB`}export function toAttachments(t){return Array.isArray(t)?t.filter(e=>!!e&&typeof e=="object"&&typeof e.url=="string"):[]}export function attachmentsText(t){return toAttachments(t).map(e=>e.name).join(", ")}export function attachmentsFromText(t){const e=[];for(const o of t.split(/[\s,]+/)){let n;try{n=new URL(o)}catch{continue}if(n.protocol!=="http:"&&n.protocol!=="https:")continue;const r=decodeURIComponent(n.pathname.split("/").filter(Boolean).pop()??n.hostname);e.push({id:newAttachmentId(),url:n.href,name:r,type:guessType(r)})}return e}export async function pdfFrameUrl(t,e=fetch){try{const o=await e(t);if(!o.ok)return null;const n=new Uint8Array(await o.arrayBuffer());return String.fromCharCode(...n.subarray(0,1024)).includes("%PDF-")?URL.createObjectURL(new Blob([n],{type:"application/pdf"})):null}catch{return null}}export function safeUrl(t,e=!1){if(typeof t!="string")return null;if(e&&/^data:image\/(png|jpeg|gif|webp|avif|svg\+xml)[;,]/i.test(t))return t;try{const o=new URL(t,typeof location<"u"?location.href:"https://x.invalid/");return o.protocol==="http:"||o.protocol==="https:"||o.protocol==="blob:"?o.href:null}catch{return null}}
|
|
@@ -205,6 +205,11 @@ export type BaseSourceChange = {
|
|
|
205
205
|
record?: Row;
|
|
206
206
|
/** For an update that does not send the whole record: the columns that changed. */
|
|
207
207
|
fields?: Row;
|
|
208
|
+
/**
|
|
209
|
+
* The person's own change, made through the app's own request (a button, a panel):
|
|
210
|
+
* put in the page like any change, never marked as made by someone else.
|
|
211
|
+
*/
|
|
212
|
+
mine?: boolean;
|
|
208
213
|
};
|
|
209
214
|
/** A Supabase Realtime event (`createSupabaseRealtime`'s `onChange` argument); `apply` takes it as it is. */
|
|
210
215
|
export type RealtimeEventLike = {
|
|
@@ -220,6 +225,7 @@ export type BasePageChange = {
|
|
|
220
225
|
id: string;
|
|
221
226
|
record?: Row;
|
|
222
227
|
fields?: Row;
|
|
228
|
+
mine?: boolean;
|
|
223
229
|
};
|
|
224
230
|
export type BaseSourceOptions = {
|
|
225
231
|
/**
|