@sparkvault/sdk-js 15.0.0 → 15.1.1
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/index.cjs +522 -421
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.mjs +522 -421
- package/dist/index.mjs.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/vaults/upload/renderer.d.ts +73 -6
- package/dist/vaults/upload/styles.d.ts +2 -2
- package/dist/vaults/upload/types.d.ts +18 -21
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -18500,8 +18500,8 @@ function createSecuritySidebar(branding) {
|
|
|
18500
18500
|
*
|
|
18501
18501
|
* SparkVault design system, product register, as the identity modal: slate
|
|
18502
18502
|
* neutrals with Action Blue carrying interactivity, on a light card that turns
|
|
18503
|
-
* to the dark surface
|
|
18504
|
-
*
|
|
18503
|
+
* to the dark surface while the upload runs. Every color is the design
|
|
18504
|
+
* system's (ui/ds-tokens).
|
|
18505
18505
|
*/
|
|
18506
18506
|
const STYLE_ID = 'sparkvault-upload-styles';
|
|
18507
18507
|
/**
|
|
@@ -18527,7 +18527,6 @@ function getUploadStyles() {
|
|
|
18527
18527
|
error: DS.error,
|
|
18528
18528
|
errorLight: DS.errorBg,
|
|
18529
18529
|
errorBorder: withAlpha(DS.error500, 0.35),
|
|
18530
|
-
errorText: DS.errorText,
|
|
18531
18530
|
success: DS.success,
|
|
18532
18531
|
successOnDark: DS.success500,
|
|
18533
18532
|
// Backgrounds
|
|
@@ -18551,6 +18550,7 @@ function getUploadStyles() {
|
|
|
18551
18550
|
// Shadows
|
|
18552
18551
|
shadowSm: DS.shadowSm,
|
|
18553
18552
|
shadowLg: DS.shadowPopover,
|
|
18553
|
+
shadowPress: `inset 0 1px 2px ${withAlpha(DS.slate900, 0.2)}`,
|
|
18554
18554
|
};
|
|
18555
18555
|
return `
|
|
18556
18556
|
/* ========================================
|
|
@@ -18616,7 +18616,7 @@ function getUploadStyles() {
|
|
|
18616
18616
|
min-width: 0;
|
|
18617
18617
|
}
|
|
18618
18618
|
|
|
18619
|
-
/* Dark card variant
|
|
18619
|
+
/* Dark card variant while the upload runs */
|
|
18620
18620
|
.svu-modal.svu-dark {
|
|
18621
18621
|
background: ${tokens.bgDark};
|
|
18622
18622
|
color: ${tokens.textOnDark};
|
|
@@ -18666,10 +18666,13 @@ function getUploadStyles() {
|
|
|
18666
18666
|
text-overflow: ellipsis;
|
|
18667
18667
|
}
|
|
18668
18668
|
|
|
18669
|
+
/* A 44px target around an 18px glyph; the negative margin keeps the
|
|
18670
|
+
header its height and the glyph where it sits. */
|
|
18669
18671
|
.svu-close-btn {
|
|
18670
18672
|
flex-shrink: 0;
|
|
18671
|
-
width:
|
|
18672
|
-
height:
|
|
18673
|
+
width: 44px;
|
|
18674
|
+
height: 44px;
|
|
18675
|
+
margin: -6px -6px -6px 0;
|
|
18673
18676
|
display: flex;
|
|
18674
18677
|
align-items: center;
|
|
18675
18678
|
justify-content: center;
|
|
@@ -18686,6 +18689,23 @@ function getUploadStyles() {
|
|
|
18686
18689
|
color: ${tokens.textPrimary};
|
|
18687
18690
|
}
|
|
18688
18691
|
|
|
18692
|
+
/* One focus ring for every control the widget draws, as the help desk
|
|
18693
|
+
widget's: Action Blue, clear of the control. A view's heading takes
|
|
18694
|
+
focus as the view shows (the renderer's focusView), and the keyboard's
|
|
18695
|
+
ring marks it the same way. */
|
|
18696
|
+
.svu-close-btn:focus-visible,
|
|
18697
|
+
.svu-footer-link:focus-visible,
|
|
18698
|
+
.svu-drop-target:focus-visible,
|
|
18699
|
+
.svu-remove-file:focus-visible,
|
|
18700
|
+
.svu-btn:focus-visible,
|
|
18701
|
+
.svu-copy-btn:focus-visible,
|
|
18702
|
+
.svu-title:focus-visible,
|
|
18703
|
+
.svu-success-title:focus-visible,
|
|
18704
|
+
.svu-error-title:focus-visible {
|
|
18705
|
+
outline: 3px solid ${tokens.primary};
|
|
18706
|
+
outline-offset: 2px;
|
|
18707
|
+
}
|
|
18708
|
+
|
|
18689
18709
|
.svu-dark .svu-close-btn {
|
|
18690
18710
|
color: ${tokens.textMutedOnDark};
|
|
18691
18711
|
}
|
|
@@ -18747,6 +18767,7 @@ function getUploadStyles() {
|
|
|
18747
18767
|
LOADING STATE
|
|
18748
18768
|
======================================== */
|
|
18749
18769
|
|
|
18770
|
+
/* A load that answers within 200ms shows no spinner at all. */
|
|
18750
18771
|
.svu-loading {
|
|
18751
18772
|
display: flex;
|
|
18752
18773
|
flex-direction: column;
|
|
@@ -18754,6 +18775,12 @@ function getUploadStyles() {
|
|
|
18754
18775
|
justify-content: center;
|
|
18755
18776
|
padding: 48px 24px;
|
|
18756
18777
|
gap: 16px;
|
|
18778
|
+
animation: svu-appear 150ms ease-out 200ms both;
|
|
18779
|
+
}
|
|
18780
|
+
|
|
18781
|
+
@keyframes svu-appear {
|
|
18782
|
+
from { opacity: 0; }
|
|
18783
|
+
to { opacity: 1; }
|
|
18757
18784
|
}
|
|
18758
18785
|
|
|
18759
18786
|
.svu-spinner {
|
|
@@ -18813,19 +18840,18 @@ function getUploadStyles() {
|
|
|
18813
18840
|
font-weight: 500;
|
|
18814
18841
|
}
|
|
18815
18842
|
|
|
18816
|
-
/* Drop Zone */
|
|
18843
|
+
/* Drop Zone: takes a dropped file anywhere on it; its button chooses one */
|
|
18817
18844
|
.svu-drop-zone {
|
|
18818
18845
|
width: 100%;
|
|
18846
|
+
box-sizing: border-box;
|
|
18819
18847
|
border: 2px dashed ${tokens.border};
|
|
18820
18848
|
border-radius: 12px;
|
|
18821
|
-
padding: 32px 24px;
|
|
18822
18849
|
text-align: center;
|
|
18823
|
-
cursor: pointer;
|
|
18824
18850
|
transition: border-color 0.15s ease, background 0.15s ease;
|
|
18825
18851
|
margin-bottom: 16px;
|
|
18826
18852
|
}
|
|
18827
18853
|
|
|
18828
|
-
.svu-drop-zone:hover {
|
|
18854
|
+
.svu-drop-zone:not(.svu-has-file):hover {
|
|
18829
18855
|
border-color: ${tokens.borderHover};
|
|
18830
18856
|
background: ${tokens.bgSubtle};
|
|
18831
18857
|
}
|
|
@@ -18839,7 +18865,22 @@ function getUploadStyles() {
|
|
|
18839
18865
|
border-style: solid;
|
|
18840
18866
|
border-color: ${tokens.primary};
|
|
18841
18867
|
background: ${tokens.primaryLight};
|
|
18842
|
-
|
|
18868
|
+
padding: 16px 12px 16px 20px;
|
|
18869
|
+
}
|
|
18870
|
+
|
|
18871
|
+
.svu-drop-target {
|
|
18872
|
+
display: flex;
|
|
18873
|
+
flex-direction: column;
|
|
18874
|
+
align-items: center;
|
|
18875
|
+
width: 100%;
|
|
18876
|
+
padding: 32px 24px;
|
|
18877
|
+
background: transparent;
|
|
18878
|
+
border: 0;
|
|
18879
|
+
border-radius: 10px;
|
|
18880
|
+
color: inherit;
|
|
18881
|
+
font: inherit;
|
|
18882
|
+
text-align: center;
|
|
18883
|
+
cursor: pointer;
|
|
18843
18884
|
}
|
|
18844
18885
|
|
|
18845
18886
|
.svu-drop-icon {
|
|
@@ -18850,22 +18891,36 @@ function getUploadStyles() {
|
|
|
18850
18891
|
}
|
|
18851
18892
|
|
|
18852
18893
|
.svu-drop-text {
|
|
18894
|
+
display: block;
|
|
18853
18895
|
font-size: 14px;
|
|
18854
18896
|
font-weight: 500;
|
|
18855
|
-
color: ${tokens.
|
|
18856
|
-
|
|
18897
|
+
color: ${tokens.primary};
|
|
18898
|
+
}
|
|
18899
|
+
|
|
18900
|
+
/* Dragging and pasting take a fine pointer and a keyboard: a phone or
|
|
18901
|
+
tablet reads the action alone. */
|
|
18902
|
+
.svu-drop-subtext,
|
|
18903
|
+
.svu-drop-hint {
|
|
18904
|
+
display: none;
|
|
18905
|
+
}
|
|
18906
|
+
|
|
18907
|
+
@media (hover: hover) and (pointer: fine) {
|
|
18908
|
+
.svu-drop-subtext,
|
|
18909
|
+
.svu-drop-hint {
|
|
18910
|
+
display: block;
|
|
18911
|
+
}
|
|
18857
18912
|
}
|
|
18858
18913
|
|
|
18859
18914
|
.svu-drop-subtext {
|
|
18860
18915
|
font-size: 13px;
|
|
18861
18916
|
color: ${tokens.textSecondary};
|
|
18862
|
-
margin:
|
|
18917
|
+
margin-top: 4px;
|
|
18863
18918
|
}
|
|
18864
18919
|
|
|
18865
18920
|
.svu-drop-hint {
|
|
18866
18921
|
font-size: 12px;
|
|
18867
18922
|
color: ${tokens.textMuted};
|
|
18868
|
-
margin:
|
|
18923
|
+
margin-top: 8px;
|
|
18869
18924
|
}
|
|
18870
18925
|
|
|
18871
18926
|
/* Selected File */
|
|
@@ -18905,8 +18960,8 @@ function getUploadStyles() {
|
|
|
18905
18960
|
|
|
18906
18961
|
.svu-remove-file {
|
|
18907
18962
|
flex-shrink: 0;
|
|
18908
|
-
width:
|
|
18909
|
-
height:
|
|
18963
|
+
width: 44px;
|
|
18964
|
+
height: 44px;
|
|
18910
18965
|
display: flex;
|
|
18911
18966
|
align-items: center;
|
|
18912
18967
|
justify-content: center;
|
|
@@ -18931,13 +18986,15 @@ function getUploadStyles() {
|
|
|
18931
18986
|
margin: 0 0 16px 0;
|
|
18932
18987
|
}
|
|
18933
18988
|
|
|
18934
|
-
/* Upload Button
|
|
18989
|
+
/* Upload Button: its padding and line come a fraction short of the
|
|
18990
|
+
44px target, which min-height makes up. */
|
|
18935
18991
|
.svu-btn {
|
|
18936
18992
|
display: inline-flex;
|
|
18937
18993
|
align-items: center;
|
|
18938
18994
|
justify-content: center;
|
|
18939
18995
|
gap: 8px;
|
|
18940
18996
|
width: 100%;
|
|
18997
|
+
min-height: 44px;
|
|
18941
18998
|
padding: 12px 20px;
|
|
18942
18999
|
font-size: 14px;
|
|
18943
19000
|
font-weight: 500;
|
|
@@ -18946,7 +19003,7 @@ function getUploadStyles() {
|
|
|
18946
19003
|
border: none;
|
|
18947
19004
|
border-radius: 8px;
|
|
18948
19005
|
cursor: pointer;
|
|
18949
|
-
transition: background 0.15s ease
|
|
19006
|
+
transition: background 0.15s ease;
|
|
18950
19007
|
box-sizing: border-box;
|
|
18951
19008
|
}
|
|
18952
19009
|
|
|
@@ -18955,8 +19012,9 @@ function getUploadStyles() {
|
|
|
18955
19012
|
cursor: not-allowed;
|
|
18956
19013
|
}
|
|
18957
19014
|
|
|
19015
|
+
/* A press compresses the button visually; nothing scales. */
|
|
18958
19016
|
.svu-btn:active:not(:disabled) {
|
|
18959
|
-
|
|
19017
|
+
box-shadow: ${tokens.shadowPress};
|
|
18960
19018
|
}
|
|
18961
19019
|
|
|
18962
19020
|
.svu-btn-primary {
|
|
@@ -18979,6 +19037,16 @@ function getUploadStyles() {
|
|
|
18979
19037
|
background: ${tokens.bgHover};
|
|
18980
19038
|
}
|
|
18981
19039
|
|
|
19040
|
+
.svu-dark .svu-btn-secondary {
|
|
19041
|
+
background: transparent;
|
|
19042
|
+
color: ${tokens.textOnDark};
|
|
19043
|
+
border-color: ${tokens.borderDark};
|
|
19044
|
+
}
|
|
19045
|
+
|
|
19046
|
+
.svu-dark .svu-btn-secondary:hover:not(:disabled) {
|
|
19047
|
+
background: ${tokens.bgDarkSubtle};
|
|
19048
|
+
}
|
|
19049
|
+
|
|
18982
19050
|
/* Error Alert */
|
|
18983
19051
|
.svu-error-alert {
|
|
18984
19052
|
background: ${tokens.errorLight};
|
|
@@ -19000,7 +19068,7 @@ function getUploadStyles() {
|
|
|
19000
19068
|
border-top: 1px solid ${tokens.border};
|
|
19001
19069
|
}
|
|
19002
19070
|
|
|
19003
|
-
.svu-metadata
|
|
19071
|
+
.svu-metadata h3 {
|
|
19004
19072
|
font-size: 12px;
|
|
19005
19073
|
font-weight: 600;
|
|
19006
19074
|
color: ${tokens.textSecondary};
|
|
@@ -19093,15 +19161,17 @@ function getUploadStyles() {
|
|
|
19093
19161
|
position: absolute;
|
|
19094
19162
|
left: 0;
|
|
19095
19163
|
top: 0;
|
|
19164
|
+
width: 100%;
|
|
19096
19165
|
height: 100%;
|
|
19097
19166
|
background: ${tokens.primary};
|
|
19098
|
-
|
|
19167
|
+
transform-origin: left center;
|
|
19168
|
+
animation: svu-arrow-flow 1s ease-out infinite;
|
|
19099
19169
|
}
|
|
19100
19170
|
|
|
19101
19171
|
@keyframes svu-arrow-flow {
|
|
19102
|
-
0% {
|
|
19103
|
-
50% {
|
|
19104
|
-
100% {
|
|
19172
|
+
0% { transform: scaleX(0); }
|
|
19173
|
+
50% { transform: scaleX(1); }
|
|
19174
|
+
100% { transform: scaleX(1); }
|
|
19105
19175
|
}
|
|
19106
19176
|
|
|
19107
19177
|
/* Progress Bar */
|
|
@@ -19155,57 +19225,11 @@ function getUploadStyles() {
|
|
|
19155
19225
|
.svu-mono {
|
|
19156
19226
|
font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Monaco, monospace;
|
|
19157
19227
|
color: ${tokens.textOnDark};
|
|
19228
|
+
overflow-wrap: anywhere;
|
|
19158
19229
|
}
|
|
19159
19230
|
|
|
19160
|
-
|
|
19161
|
-
|
|
19162
|
-
======================================== */
|
|
19163
|
-
|
|
19164
|
-
.svu-ceremony-view {
|
|
19165
|
-
display: flex;
|
|
19166
|
-
flex-direction: column;
|
|
19167
|
-
align-items: center;
|
|
19168
|
-
}
|
|
19169
|
-
|
|
19170
|
-
.svu-ceremony-steps {
|
|
19171
|
-
width: 100%;
|
|
19172
|
-
margin: 20px 0;
|
|
19173
|
-
}
|
|
19174
|
-
|
|
19175
|
-
.svu-ceremony-step {
|
|
19176
|
-
display: flex;
|
|
19177
|
-
align-items: center;
|
|
19178
|
-
gap: 12px;
|
|
19179
|
-
padding: 10px 0;
|
|
19180
|
-
opacity: 0.4;
|
|
19181
|
-
transition: opacity 0.3s ease;
|
|
19182
|
-
}
|
|
19183
|
-
|
|
19184
|
-
.svu-ceremony-step.svu-active {
|
|
19185
|
-
opacity: 1;
|
|
19186
|
-
}
|
|
19187
|
-
|
|
19188
|
-
.svu-ceremony-step.svu-complete {
|
|
19189
|
-
opacity: 0.7;
|
|
19190
|
-
}
|
|
19191
|
-
|
|
19192
|
-
.svu-step-icon {
|
|
19193
|
-
width: 20px;
|
|
19194
|
-
height: 20px;
|
|
19195
|
-
display: flex;
|
|
19196
|
-
align-items: center;
|
|
19197
|
-
justify-content: center;
|
|
19198
|
-
color: ${tokens.primary};
|
|
19199
|
-
}
|
|
19200
|
-
|
|
19201
|
-
.svu-step-text {
|
|
19202
|
-
font-size: 13px;
|
|
19203
|
-
color: ${tokens.textOnDark};
|
|
19204
|
-
}
|
|
19205
|
-
|
|
19206
|
-
/* Spinning loader */
|
|
19207
|
-
.svu-step-icon .svu-spin {
|
|
19208
|
-
animation: svu-spin 0.7s linear infinite;
|
|
19231
|
+
.svu-cancel-upload {
|
|
19232
|
+
margin-top: 20px;
|
|
19209
19233
|
}
|
|
19210
19234
|
|
|
19211
19235
|
/* ========================================
|
|
@@ -19255,6 +19279,7 @@ function getUploadStyles() {
|
|
|
19255
19279
|
display: flex;
|
|
19256
19280
|
justify-content: space-between;
|
|
19257
19281
|
align-items: center;
|
|
19282
|
+
gap: 12px;
|
|
19258
19283
|
padding: 8px 0;
|
|
19259
19284
|
font-size: 13px;
|
|
19260
19285
|
border-bottom: 1px solid ${tokens.border};
|
|
@@ -19269,16 +19294,22 @@ function getUploadStyles() {
|
|
|
19269
19294
|
}
|
|
19270
19295
|
|
|
19271
19296
|
.svu-success-value {
|
|
19297
|
+
min-width: 0;
|
|
19272
19298
|
color: ${tokens.textPrimary};
|
|
19273
19299
|
font-weight: 500;
|
|
19274
19300
|
display: flex;
|
|
19275
19301
|
align-items: center;
|
|
19276
19302
|
gap: 8px;
|
|
19303
|
+
text-align: right;
|
|
19277
19304
|
}
|
|
19278
19305
|
|
|
19306
|
+
/* A 44px target around a 14px glyph; the negative margin keeps the row
|
|
19307
|
+
its text's height. */
|
|
19279
19308
|
.svu-copy-btn {
|
|
19280
|
-
|
|
19281
|
-
|
|
19309
|
+
flex-shrink: 0;
|
|
19310
|
+
width: 44px;
|
|
19311
|
+
height: 44px;
|
|
19312
|
+
margin: -10px -12px -10px 0;
|
|
19282
19313
|
display: flex;
|
|
19283
19314
|
align-items: center;
|
|
19284
19315
|
justify-content: center;
|
|
@@ -19295,6 +19326,13 @@ function getUploadStyles() {
|
|
|
19295
19326
|
color: ${tokens.primary};
|
|
19296
19327
|
}
|
|
19297
19328
|
|
|
19329
|
+
.svu-copy-status {
|
|
19330
|
+
margin: 0;
|
|
19331
|
+
font-size: 12px;
|
|
19332
|
+
color: ${tokens.textSecondary};
|
|
19333
|
+
text-align: right;
|
|
19334
|
+
}
|
|
19335
|
+
|
|
19298
19336
|
.svu-success-guidance {
|
|
19299
19337
|
font-size: 13px;
|
|
19300
19338
|
color: ${tokens.textSecondary};
|
|
@@ -19333,32 +19371,6 @@ function getUploadStyles() {
|
|
|
19333
19371
|
line-height: 1.5;
|
|
19334
19372
|
}
|
|
19335
19373
|
|
|
19336
|
-
.svu-error-code {
|
|
19337
|
-
display: inline-flex;
|
|
19338
|
-
align-items: center;
|
|
19339
|
-
gap: 6px;
|
|
19340
|
-
padding: 6px 10px;
|
|
19341
|
-
background: ${tokens.errorLight};
|
|
19342
|
-
border: 1px solid ${tokens.errorBorder};
|
|
19343
|
-
border-radius: 6px;
|
|
19344
|
-
margin-bottom: 20px;
|
|
19345
|
-
}
|
|
19346
|
-
|
|
19347
|
-
.svu-error-code-label {
|
|
19348
|
-
font-size: 10px;
|
|
19349
|
-
font-weight: 600;
|
|
19350
|
-
color: ${tokens.errorText};
|
|
19351
|
-
text-transform: uppercase;
|
|
19352
|
-
letter-spacing: 0.05em;
|
|
19353
|
-
}
|
|
19354
|
-
|
|
19355
|
-
.svu-error-code-value {
|
|
19356
|
-
font-size: 11px;
|
|
19357
|
-
font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Monaco, monospace;
|
|
19358
|
-
color: ${tokens.error};
|
|
19359
|
-
font-weight: 500;
|
|
19360
|
-
}
|
|
19361
|
-
|
|
19362
19374
|
/* ========================================
|
|
19363
19375
|
SECURITY SIDEBAR
|
|
19364
19376
|
======================================== */
|
|
@@ -19570,6 +19582,35 @@ function getUploadStyles() {
|
|
|
19570
19582
|
ACCESSIBILITY
|
|
19571
19583
|
======================================== */
|
|
19572
19584
|
|
|
19585
|
+
/* Reduced motion shows each view's end state, still. The loading view
|
|
19586
|
+
keeps its 200ms wait, so a fast load still shows nothing, then appears
|
|
19587
|
+
at once. */
|
|
19588
|
+
@media (prefers-reduced-motion: reduce) {
|
|
19589
|
+
.svu-loading {
|
|
19590
|
+
animation: svu-appear 0s linear 200ms both;
|
|
19591
|
+
}
|
|
19592
|
+
|
|
19593
|
+
.svu-spinner {
|
|
19594
|
+
animation: none;
|
|
19595
|
+
}
|
|
19596
|
+
|
|
19597
|
+
.svu-stage-arrow.svu-active::after {
|
|
19598
|
+
animation: none;
|
|
19599
|
+
}
|
|
19600
|
+
|
|
19601
|
+
.svu-stage {
|
|
19602
|
+
transition: none;
|
|
19603
|
+
}
|
|
19604
|
+
|
|
19605
|
+
.svu-progress-fill {
|
|
19606
|
+
transition: none;
|
|
19607
|
+
}
|
|
19608
|
+
|
|
19609
|
+
.svu-complete-view {
|
|
19610
|
+
animation: none;
|
|
19611
|
+
}
|
|
19612
|
+
}
|
|
19613
|
+
|
|
19573
19614
|
.svu-sr-only {
|
|
19574
19615
|
position: absolute;
|
|
19575
19616
|
width: 1px;
|
|
@@ -19788,38 +19829,26 @@ class UploadInlineContainer {
|
|
|
19788
19829
|
* Upload Renderer
|
|
19789
19830
|
*
|
|
19790
19831
|
* Orchestrates view state and rendering for vault upload flows.
|
|
19791
|
-
* Manages the complete upload lifecycle: form, uploading
|
|
19832
|
+
* Manages the complete upload lifecycle: form, uploading (the bytes moving,
|
|
19833
|
+
* then SparkVault securing the file until it confirms the save), completion.
|
|
19792
19834
|
*/
|
|
19793
19835
|
/**
|
|
19794
19836
|
* What an outside uploader reads when the vault is scheduled for deletion:
|
|
19795
19837
|
* the vault takes no files now. Core's own sentence, which tells the vault's
|
|
19796
19838
|
* admin how to cancel the deletion, is the console's, never this page's.
|
|
19797
19839
|
*/
|
|
19798
|
-
const VAULT_NOT_ACCEPTING_MESSAGE = 'This vault isn\'t accepting files right now, so your file was not saved.
|
|
19840
|
+
const VAULT_NOT_ACCEPTING_MESSAGE = 'This vault isn\'t accepting files right now, so your file was not saved. Contact the person who shared this upload page with you.';
|
|
19799
19841
|
/**
|
|
19800
19842
|
* What an uploader reads for a file of no bytes, which Core never stores: said
|
|
19801
19843
|
* on the form, where another file can be chosen, as the size limit is.
|
|
19802
19844
|
*/
|
|
19803
19845
|
const EMPTY_FILE_MESSAGE = 'This file is empty, so there is nothing to upload. Choose another file.';
|
|
19846
|
+
/** How long "Copied" shows beside the Ingot ID once the copy landed. */
|
|
19847
|
+
const COPIED_SHOWS_MS = 2000;
|
|
19848
|
+
/** What the person reads when the browser refused to copy the Ingot ID. */
|
|
19849
|
+
const COPY_REFUSED_MESSAGE = 'Could not copy. Select the ID instead.';
|
|
19804
19850
|
/**
|
|
19805
|
-
*
|
|
19806
|
-
*/
|
|
19807
|
-
const CEREMONY_STEPS = [
|
|
19808
|
-
{ text: 'File received by Forge', duration: 600 },
|
|
19809
|
-
{ text: 'Deriving Triple Zero-Trust encryption keys', duration: 800 },
|
|
19810
|
-
{ text: 'Encrypting with AES-256-GCM', duration: 900 },
|
|
19811
|
-
{ text: 'Generating cryptographic signatures', duration: 700 },
|
|
19812
|
-
{ text: 'Storing in post-quantum protected vault', duration: 600 },
|
|
19813
|
-
{ text: 'Verifying integrity', duration: 400 },
|
|
19814
|
-
];
|
|
19815
|
-
/**
|
|
19816
|
-
* Convert hex string to base64url for display.
|
|
19817
|
-
*/
|
|
19818
|
-
function hexToBase64url(hex) {
|
|
19819
|
-
return bytesToBase64url(new Uint8Array(hex.match(/.{2}/g).map(byte => parseInt(byte, 16))));
|
|
19820
|
-
}
|
|
19821
|
-
/**
|
|
19822
|
-
* The "Secure Transfer Channel" line: the id Core gave the request that opened
|
|
19851
|
+
* The "Secure transfer channel" line: the id Core gave the request that opened
|
|
19823
19852
|
* the upload, shown as text (it arrives from the server and lands on the host
|
|
19824
19853
|
* page, so it is escaped like every server value the widget renders). A
|
|
19825
19854
|
* response that names no id shows no line.
|
|
@@ -19827,7 +19856,7 @@ function hexToBase64url(hex) {
|
|
|
19827
19856
|
function transferChannelLine(requestId) {
|
|
19828
19857
|
return requestId === null
|
|
19829
19858
|
? ''
|
|
19830
|
-
: `<p class="svu-forging-line">Secure
|
|
19859
|
+
: `<p class="svu-forging-line">Secure transfer channel: <span class="svu-mono">${escapeHtml(requestId)}</span></p>`;
|
|
19831
19860
|
}
|
|
19832
19861
|
/**
|
|
19833
19862
|
* Refusals that say the vault takes no upload now, whichever file is chosen:
|
|
@@ -19850,14 +19879,60 @@ function vaultTakesNoUpload(error) {
|
|
|
19850
19879
|
*/
|
|
19851
19880
|
function recoveryAfterUpload(error) {
|
|
19852
19881
|
if (!(error instanceof UploadApiError))
|
|
19853
|
-
return { label: 'Try
|
|
19882
|
+
return { label: 'Try again', keepFile: true };
|
|
19854
19883
|
if (vaultTakesNoUpload(error))
|
|
19855
19884
|
return null;
|
|
19856
19885
|
if (error.code === RECEIVED_STILL_SAVING)
|
|
19857
|
-
return { label: 'Upload
|
|
19886
|
+
return { label: 'Upload another file', keepFile: false };
|
|
19858
19887
|
const status = error.statusCode ?? 0;
|
|
19859
19888
|
const mayPass = status === 0 || status === 429 || status >= 500;
|
|
19860
|
-
return mayPass ? { label: 'Try
|
|
19889
|
+
return mayPass ? { label: 'Try again', keepFile: true } : { label: 'Choose another file', keepFile: false };
|
|
19890
|
+
}
|
|
19891
|
+
/**
|
|
19892
|
+
* What the error view says of a failed upload: a title, and the cause in the
|
|
19893
|
+
* uploader's terms. The error's code is the host's (onError), never shown: an
|
|
19894
|
+
* outside uploader cannot act on it.
|
|
19895
|
+
*/
|
|
19896
|
+
function describeFailure(error) {
|
|
19897
|
+
if (!(error instanceof UploadApiError))
|
|
19898
|
+
return { title: 'Upload failed', message: error.message };
|
|
19899
|
+
if (error.code === 'UPLOAD_SOURCE_DISABLED') {
|
|
19900
|
+
// The vault exists but the embedded widget isn't enabled. This is almost
|
|
19901
|
+
// always a developer or admin oversight, so the message points at the
|
|
19902
|
+
// dashboard rather than the end user.
|
|
19903
|
+
return {
|
|
19904
|
+
title: 'Upload widget not enabled',
|
|
19905
|
+
message: 'This vault has not enabled the embedded upload widget. Enable it on the vault\'s settings page in the SparkVault dashboard to start accepting uploads here.',
|
|
19906
|
+
};
|
|
19907
|
+
}
|
|
19908
|
+
if (error.code === VAULT_DELETION_SCHEDULED || error.details?.coreCode === VAULT_DELETION_SCHEDULED) {
|
|
19909
|
+
// The vault is scheduled for deletion, refused at the upload's start or
|
|
19910
|
+
// while its bytes moved. Core's sentence tells the vault's admin how to
|
|
19911
|
+
// cancel the deletion; the person on this page is an outside uploader,
|
|
19912
|
+
// told only that the vault takes no files now.
|
|
19913
|
+
return { title: 'Uploads paused', message: VAULT_NOT_ACCEPTING_MESSAGE };
|
|
19914
|
+
}
|
|
19915
|
+
if (error.code === 'upload_refused') {
|
|
19916
|
+
// Core refused the upload, in its own words (whom to contact about a full
|
|
19917
|
+
// storage pool, or the later upload that replaced this one): a sentence
|
|
19918
|
+
// that never asks for the file again.
|
|
19919
|
+
return { title: 'Upload not saved', message: error.message };
|
|
19920
|
+
}
|
|
19921
|
+
if (error.statusCode === 404 && error.code !== 'session_gone') {
|
|
19922
|
+
// A vault or upload route that does not exist. A gone upload session can
|
|
19923
|
+
// answer 404 too, and its own sentence says what became of the file.
|
|
19924
|
+
return {
|
|
19925
|
+
title: 'Upload page not found',
|
|
19926
|
+
message: 'This upload page does not exist. The link may have expired or been mistyped.',
|
|
19927
|
+
};
|
|
19928
|
+
}
|
|
19929
|
+
if (error.statusCode === 402) {
|
|
19930
|
+
return {
|
|
19931
|
+
title: 'Upload unavailable',
|
|
19932
|
+
message: 'This upload page is unavailable because of a billing issue on the organization\'s account. Contact the organization that shared it with you.',
|
|
19933
|
+
};
|
|
19934
|
+
}
|
|
19935
|
+
return { title: 'Upload failed', message: error.message };
|
|
19861
19936
|
}
|
|
19862
19937
|
/**
|
|
19863
19938
|
* Whether an error represents a deliberate cancellation (user close,
|
|
@@ -19874,7 +19949,7 @@ class UploadRenderer {
|
|
|
19874
19949
|
this.selectedFile = null;
|
|
19875
19950
|
// File input element for selection
|
|
19876
19951
|
this.fileInputElement = null;
|
|
19877
|
-
// Hybrid mode: modal overlay for
|
|
19952
|
+
// Hybrid mode: modal overlay for the uploading state in inline mode
|
|
19878
19953
|
this.uploadModal = null;
|
|
19879
19954
|
this.isInlineMode = false;
|
|
19880
19955
|
this.hybridModalInitialized = false;
|
|
@@ -19883,6 +19958,29 @@ class UploadRenderer {
|
|
|
19883
19958
|
// onError — see cancel()/handleApiError).
|
|
19884
19959
|
this.closed = false;
|
|
19885
19960
|
this.cancelled = false;
|
|
19961
|
+
// Counts the uploads this renderer started; an upload whose number is no
|
|
19962
|
+
// longer current (one the person cancelled) renders nothing and tells the
|
|
19963
|
+
// host nothing, whatever its transfer still reports.
|
|
19964
|
+
this.uploadGeneration = 0;
|
|
19965
|
+
// An upload runs from its start until it ends or is cancelled, and only
|
|
19966
|
+
// one at a time: each start stages a file Core names, so a second start
|
|
19967
|
+
// for the same file is a second file left pending beside the first. While
|
|
19968
|
+
// one runs, the form takes no other file (formTakesFile).
|
|
19969
|
+
this.uploadInFlight = false;
|
|
19970
|
+
// Set once the widget is ready (onReady). Every view drawn after it answers
|
|
19971
|
+
// the person's action, or the upload they started, so it takes focus
|
|
19972
|
+
// (focusView); the views before it leave focus where the host page has it.
|
|
19973
|
+
this.ready = false;
|
|
19974
|
+
/**
|
|
19975
|
+
* A browser tab closed or reloaded mid-transfer loses the upload, so the
|
|
19976
|
+
* tab asks first while one runs (holdPage). Each renderer holds the page
|
|
19977
|
+
* with its own listener, so one ending never releases another's hold.
|
|
19978
|
+
*/
|
|
19979
|
+
this.warnBeforeLeaving = (event) => {
|
|
19980
|
+
event.preventDefault();
|
|
19981
|
+
// A browser that reads only returnValue asks for it set.
|
|
19982
|
+
event.returnValue = '';
|
|
19983
|
+
};
|
|
19886
19984
|
this.pasteHandler = null;
|
|
19887
19985
|
this.container = container;
|
|
19888
19986
|
this.api = api;
|
|
@@ -19898,11 +19996,7 @@ class UploadRenderer {
|
|
|
19898
19996
|
this.container.createLoading({ backdropBlur: this.options.backdropBlur }, () => this.handleClose());
|
|
19899
19997
|
this.setState({ view: 'loading' });
|
|
19900
19998
|
try {
|
|
19901
|
-
|
|
19902
|
-
const [config] = await Promise.all([
|
|
19903
|
-
this.api.getVaultUploadInfo(this.options.vaultId),
|
|
19904
|
-
new Promise(resolve => setTimeout(resolve, 1000)),
|
|
19905
|
-
]);
|
|
19999
|
+
const config = await this.api.getVaultUploadInfo(this.options.vaultId);
|
|
19906
20000
|
this.config = config;
|
|
19907
20001
|
// Update branding
|
|
19908
20002
|
this.container.updateBranding(config.branding);
|
|
@@ -19911,12 +20005,14 @@ class UploadRenderer {
|
|
|
19911
20005
|
// (its own button, picker, or drop target) and hand the File to the SDK.
|
|
19912
20006
|
if (this.options.file) {
|
|
19913
20007
|
this.selectedFile = this.options.file;
|
|
20008
|
+
this.ready = true;
|
|
19914
20009
|
this.callbacks.onReady?.();
|
|
19915
20010
|
await this.startUpload(config);
|
|
19916
20011
|
return;
|
|
19917
20012
|
}
|
|
19918
20013
|
// Show form
|
|
19919
20014
|
this.setState({ view: 'form', config });
|
|
20015
|
+
this.ready = true;
|
|
19920
20016
|
this.callbacks.onReady?.();
|
|
19921
20017
|
}
|
|
19922
20018
|
catch (error) {
|
|
@@ -19932,6 +20028,7 @@ class UploadRenderer {
|
|
|
19932
20028
|
this.closed = true;
|
|
19933
20029
|
// Cancel all pending API requests and the active TUS transfer
|
|
19934
20030
|
this.api.abort();
|
|
20031
|
+
this.holdPage(false);
|
|
19935
20032
|
this.cleanupFileInput();
|
|
19936
20033
|
this.cleanupPasteHandler();
|
|
19937
20034
|
// Clean up modal if open (hybrid mode)
|
|
@@ -19955,7 +20052,16 @@ class UploadRenderer {
|
|
|
19955
20052
|
this.close();
|
|
19956
20053
|
this.callbacks.onCancel();
|
|
19957
20054
|
}
|
|
20055
|
+
/**
|
|
20056
|
+
* The dialog's dismissals: Escape, a tap on its backdrop, and its close
|
|
20057
|
+
* button, which the uploading view hides. While an upload runs, Escape and
|
|
20058
|
+
* a tap are too easy to do by accident to end it, as in the dialog inline
|
|
20059
|
+
* mode runs the upload in (renderInModal): the view's Cancel upload stops
|
|
20060
|
+
* it, and once SparkVault secures the file nothing does.
|
|
20061
|
+
*/
|
|
19958
20062
|
handleClose() {
|
|
20063
|
+
if (this.viewState.view === 'uploading')
|
|
20064
|
+
return;
|
|
19959
20065
|
this.cancel();
|
|
19960
20066
|
}
|
|
19961
20067
|
setState(state) {
|
|
@@ -19963,15 +20069,18 @@ class UploadRenderer {
|
|
|
19963
20069
|
// teardown must not resurrect the hybrid-mode modal or touch the DOM.
|
|
19964
20070
|
if (this.closed)
|
|
19965
20071
|
return;
|
|
19966
|
-
const
|
|
20072
|
+
const previous = this.viewState;
|
|
19967
20073
|
this.viewState = state;
|
|
19968
20074
|
// Progress events fire many times per second for the whole transfer.
|
|
19969
20075
|
// While the uploading view is already on screen, mutate its progress
|
|
19970
20076
|
// nodes in place instead of tearing down and rebuilding the subtree —
|
|
19971
20077
|
// a full rebuild per event thrashes the DOM and restarts the progress
|
|
19972
|
-
// bar's CSS transition and the stage-arrow animation on every tick.
|
|
19973
|
-
|
|
20078
|
+
// bar's CSS transition and the stage-arrow animation on every tick. The
|
|
20079
|
+
// view re-renders once, when every byte is sent and SparkVault is
|
|
20080
|
+
// securing the file.
|
|
20081
|
+
if (previous.view === 'uploading' &&
|
|
19974
20082
|
state.view === 'uploading' &&
|
|
20083
|
+
previous.securing === state.securing &&
|
|
19975
20084
|
this.updateUploadProgress(state)) {
|
|
19976
20085
|
return;
|
|
19977
20086
|
}
|
|
@@ -20001,14 +20110,15 @@ class UploadRenderer {
|
|
|
20001
20110
|
return true;
|
|
20002
20111
|
}
|
|
20003
20112
|
render() {
|
|
20004
|
-
const isDarkState = this.viewState.view === 'uploading'
|
|
20005
|
-
// Hybrid mode: For inline containers, use a modal popup
|
|
20006
|
-
// This gives the polished full experience, then returns to inline
|
|
20113
|
+
const isDarkState = this.viewState.view === 'uploading';
|
|
20114
|
+
// Hybrid mode: For inline containers, use a modal popup while the upload
|
|
20115
|
+
// runs. This gives the polished full experience, then returns to inline
|
|
20116
|
+
// for its outcome
|
|
20007
20117
|
if (this.isInlineMode && isDarkState) {
|
|
20008
20118
|
this.renderInModal();
|
|
20009
20119
|
return;
|
|
20010
20120
|
}
|
|
20011
|
-
// Close modal if we're leaving
|
|
20121
|
+
// Close modal if we're leaving the uploading state (hybrid mode complete)
|
|
20012
20122
|
if (this.uploadModal) {
|
|
20013
20123
|
this.uploadModal.destroy();
|
|
20014
20124
|
this.uploadModal = null;
|
|
@@ -20040,27 +20150,61 @@ class UploadRenderer {
|
|
|
20040
20150
|
case 'uploading':
|
|
20041
20151
|
body.appendChild(this.renderUploading(this.viewState));
|
|
20042
20152
|
break;
|
|
20043
|
-
case 'ceremony':
|
|
20044
|
-
body.appendChild(this.renderCeremony(this.viewState));
|
|
20045
|
-
break;
|
|
20046
20153
|
case 'complete':
|
|
20047
20154
|
body.appendChild(this.renderComplete(this.viewState.result, this.viewState.config));
|
|
20048
20155
|
break;
|
|
20156
|
+
case 'received':
|
|
20157
|
+
body.appendChild(this.renderReceived(this.viewState.message, this.viewState.action));
|
|
20158
|
+
break;
|
|
20049
20159
|
case 'error':
|
|
20050
20160
|
body.appendChild(this.renderError(this.viewState));
|
|
20051
20161
|
break;
|
|
20052
20162
|
}
|
|
20163
|
+
this.focusView(body);
|
|
20164
|
+
}
|
|
20165
|
+
/**
|
|
20166
|
+
* A redraw replaces the control the person just used, so once the widget is
|
|
20167
|
+
* ready (this.ready) focus never drops to the page: it lands on Upload
|
|
20168
|
+
* securely once a file is chosen, on the drop target before one is, and on
|
|
20169
|
+
* the heading every other view leads with (tabindex -1: it takes focus
|
|
20170
|
+
* without joining the Tab order). The loading view has nothing to focus.
|
|
20171
|
+
*/
|
|
20172
|
+
focusView(body) {
|
|
20173
|
+
if (!this.ready)
|
|
20174
|
+
return;
|
|
20175
|
+
let target = null;
|
|
20176
|
+
switch (this.viewState.view) {
|
|
20177
|
+
case 'form':
|
|
20178
|
+
target = this.selectedFile ? '.svu-upload-btn' : '.svu-drop-target';
|
|
20179
|
+
break;
|
|
20180
|
+
case 'uploading':
|
|
20181
|
+
target = '.svu-title';
|
|
20182
|
+
break;
|
|
20183
|
+
case 'complete':
|
|
20184
|
+
case 'received':
|
|
20185
|
+
target = '.svu-success-title';
|
|
20186
|
+
break;
|
|
20187
|
+
case 'error':
|
|
20188
|
+
target = '.svu-error-title';
|
|
20189
|
+
break;
|
|
20190
|
+
}
|
|
20191
|
+
if (target)
|
|
20192
|
+
body.querySelector(target)?.focus();
|
|
20053
20193
|
}
|
|
20054
20194
|
/**
|
|
20055
|
-
* Render uploading
|
|
20195
|
+
* Render the uploading state in a modal overlay (for inline mode).
|
|
20056
20196
|
* This provides the full polished experience during upload.
|
|
20057
20197
|
*/
|
|
20058
20198
|
renderInModal() {
|
|
20059
20199
|
// Create and initialize modal only once
|
|
20060
20200
|
if (!this.uploadModal) {
|
|
20061
20201
|
this.uploadModal = new UploadModalContainer();
|
|
20062
|
-
this.uploadModal.createLoading({ backdropBlur: this.options.backdropBlur ?? true },
|
|
20063
|
-
)
|
|
20202
|
+
this.uploadModal.createLoading({ backdropBlur: this.options.backdropBlur ?? true },
|
|
20203
|
+
// An embedded widget has no close (UploadInlineContainer), and this
|
|
20204
|
+
// dialog shows only while an upload runs, which Escape and a tap on
|
|
20205
|
+
// the backdrop are too easy to do by accident to end: the view's own
|
|
20206
|
+
// Cancel upload button stops it.
|
|
20207
|
+
() => { });
|
|
20064
20208
|
if (this.config) {
|
|
20065
20209
|
this.uploadModal.updateBranding(this.config.branding);
|
|
20066
20210
|
}
|
|
@@ -20085,9 +20229,7 @@ class UploadRenderer {
|
|
|
20085
20229
|
body.innerHTML = '';
|
|
20086
20230
|
if (this.viewState.view === 'uploading') {
|
|
20087
20231
|
body.appendChild(this.renderUploading(this.viewState));
|
|
20088
|
-
|
|
20089
|
-
else if (this.viewState.view === 'ceremony') {
|
|
20090
|
-
body.appendChild(this.renderCeremony(this.viewState));
|
|
20232
|
+
this.focusView(body);
|
|
20091
20233
|
}
|
|
20092
20234
|
}
|
|
20093
20235
|
renderLoading() {
|
|
@@ -20105,28 +20247,30 @@ class UploadRenderer {
|
|
|
20105
20247
|
// Title
|
|
20106
20248
|
const title = document.createElement('h2');
|
|
20107
20249
|
title.className = 'svu-title';
|
|
20108
|
-
title.textContent = 'Cryptographically
|
|
20250
|
+
title.textContent = 'Cryptographically secure file transfer';
|
|
20109
20251
|
div.appendChild(title);
|
|
20110
20252
|
// Subtitle with vault name
|
|
20111
20253
|
const subtitle = document.createElement('p');
|
|
20112
20254
|
subtitle.className = 'svu-subtitle';
|
|
20113
|
-
subtitle.innerHTML = `Destination
|
|
20255
|
+
subtitle.innerHTML = `Destination vault: <strong>${escapeHtml(config.vaultName)}</strong>`;
|
|
20114
20256
|
div.appendChild(subtitle);
|
|
20115
20257
|
// Error message
|
|
20116
20258
|
if (error) {
|
|
20117
20259
|
const alert = document.createElement('div');
|
|
20118
20260
|
alert.className = 'svu-error-alert';
|
|
20261
|
+
alert.setAttribute('role', 'alert');
|
|
20119
20262
|
alert.textContent = error;
|
|
20120
20263
|
div.appendChild(alert);
|
|
20121
20264
|
}
|
|
20122
|
-
// Drop zone
|
|
20265
|
+
// Drop zone: the whole zone takes a dropped file; choosing one is a
|
|
20266
|
+
// native button, so a keyboard, switch or screen reader reaches it.
|
|
20123
20267
|
const dropZone = document.createElement('div');
|
|
20124
20268
|
dropZone.className = `svu-drop-zone${this.selectedFile ? ' svu-has-file' : ''}`;
|
|
20125
20269
|
if (this.selectedFile) {
|
|
20126
20270
|
dropZone.innerHTML = `
|
|
20127
20271
|
<div class="svu-selected-file">
|
|
20128
20272
|
<div class="svu-file-icon">
|
|
20129
|
-
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
|
|
20273
|
+
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
|
|
20130
20274
|
<path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/>
|
|
20131
20275
|
<path d="M14 2v6h6"/>
|
|
20132
20276
|
</svg>
|
|
@@ -20135,31 +20279,36 @@ class UploadRenderer {
|
|
|
20135
20279
|
<span class="svu-file-name">${escapeHtml(this.selectedFile.name)}</span>
|
|
20136
20280
|
<span class="svu-file-size">${formatBytes(this.selectedFile.size)}</span>
|
|
20137
20281
|
</div>
|
|
20138
|
-
<button class="svu-remove-file" aria-label="Remove file">×</button>
|
|
20282
|
+
<button type="button" class="svu-remove-file" aria-label="Remove file">×</button>
|
|
20139
20283
|
</div>
|
|
20140
20284
|
`;
|
|
20141
|
-
|
|
20142
|
-
|
|
20143
|
-
|
|
20144
|
-
|
|
20145
|
-
|
|
20146
|
-
|
|
20147
|
-
});
|
|
20148
|
-
}
|
|
20285
|
+
dropZone.querySelector('.svu-remove-file')?.addEventListener('click', () => {
|
|
20286
|
+
if (!this.formTakesFile())
|
|
20287
|
+
return;
|
|
20288
|
+
this.selectedFile = null;
|
|
20289
|
+
this.render();
|
|
20290
|
+
});
|
|
20149
20291
|
}
|
|
20150
20292
|
else {
|
|
20293
|
+
// The drag and paste hints show only where a fine pointer can drag
|
|
20294
|
+
// (styles.ts); a phone reads the action alone.
|
|
20151
20295
|
dropZone.innerHTML = `
|
|
20152
|
-
<
|
|
20153
|
-
<
|
|
20154
|
-
<
|
|
20155
|
-
|
|
20156
|
-
|
|
20157
|
-
|
|
20158
|
-
|
|
20159
|
-
|
|
20160
|
-
|
|
20161
|
-
|
|
20296
|
+
<button type="button" class="svu-drop-target">
|
|
20297
|
+
<span class="svu-drop-icon" aria-hidden="true">
|
|
20298
|
+
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
|
|
20299
|
+
<path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/>
|
|
20300
|
+
<path d="M17 8l-5-5-5 5"/>
|
|
20301
|
+
<path d="M12 3v12"/>
|
|
20302
|
+
</svg>
|
|
20303
|
+
</span>
|
|
20304
|
+
<span class="svu-drop-text">Choose a file</span>
|
|
20305
|
+
<span class="svu-drop-subtext">or drag it here</span>
|
|
20306
|
+
<span class="svu-drop-hint">You can also paste a file</span>
|
|
20307
|
+
</button>
|
|
20162
20308
|
`;
|
|
20309
|
+
dropZone.querySelector('.svu-drop-target')?.addEventListener('click', () => {
|
|
20310
|
+
this.openFileSelector(config);
|
|
20311
|
+
});
|
|
20163
20312
|
}
|
|
20164
20313
|
// Drop zone events
|
|
20165
20314
|
dropZone.addEventListener('dragover', (e) => {
|
|
@@ -20178,30 +20327,30 @@ class UploadRenderer {
|
|
|
20178
20327
|
this.handleFileSelect(file, config);
|
|
20179
20328
|
}
|
|
20180
20329
|
});
|
|
20181
|
-
dropZone.addEventListener('click', () => {
|
|
20182
|
-
if (!this.selectedFile) {
|
|
20183
|
-
this.openFileSelector(config);
|
|
20184
|
-
}
|
|
20185
|
-
});
|
|
20186
20330
|
div.appendChild(dropZone);
|
|
20187
20331
|
// Max size
|
|
20188
20332
|
const maxSize = document.createElement('p');
|
|
20189
20333
|
maxSize.className = 'svu-max-size';
|
|
20190
20334
|
maxSize.textContent = `Max upload size: ${formatBytes(config.maxSizeBytes)}`;
|
|
20191
20335
|
div.appendChild(maxSize);
|
|
20192
|
-
// Upload button
|
|
20336
|
+
// Upload button: it goes unavailable on the press that starts the upload,
|
|
20337
|
+
// so a double click starts one.
|
|
20193
20338
|
if (this.selectedFile) {
|
|
20194
20339
|
const uploadBtn = document.createElement('button');
|
|
20195
|
-
uploadBtn.
|
|
20196
|
-
uploadBtn.
|
|
20197
|
-
uploadBtn.
|
|
20340
|
+
uploadBtn.type = 'button';
|
|
20341
|
+
uploadBtn.className = 'svu-btn svu-btn-primary svu-upload-btn';
|
|
20342
|
+
uploadBtn.textContent = 'Upload securely';
|
|
20343
|
+
uploadBtn.addEventListener('click', () => {
|
|
20344
|
+
uploadBtn.disabled = true;
|
|
20345
|
+
void this.startUpload(config);
|
|
20346
|
+
});
|
|
20198
20347
|
div.appendChild(uploadBtn);
|
|
20199
20348
|
}
|
|
20200
20349
|
// Metadata section
|
|
20201
20350
|
const metadata = document.createElement('div');
|
|
20202
20351
|
metadata.className = 'svu-metadata';
|
|
20203
20352
|
metadata.innerHTML = `
|
|
20204
|
-
<
|
|
20353
|
+
<h3>Transfer details</h3>
|
|
20205
20354
|
<div class="svu-metadata-grid">
|
|
20206
20355
|
<div class="svu-metadata-item">
|
|
20207
20356
|
<span class="svu-metadata-label">Recipient</span>
|
|
@@ -20220,15 +20369,15 @@ class UploadRenderer {
|
|
|
20220
20369
|
<span class="svu-metadata-value">${escapeHtml(config.encryption.algorithm)}</span>
|
|
20221
20370
|
</div>
|
|
20222
20371
|
<div class="svu-metadata-item">
|
|
20223
|
-
<span class="svu-metadata-label">Key
|
|
20372
|
+
<span class="svu-metadata-label">Key derivation</span>
|
|
20224
20373
|
<span class="svu-metadata-value">${escapeHtml(config.encryption.keyDerivation)}</span>
|
|
20225
20374
|
</div>
|
|
20226
20375
|
<div class="svu-metadata-item">
|
|
20227
|
-
<span class="svu-metadata-label">Post-
|
|
20376
|
+
<span class="svu-metadata-label">Post-quantum</span>
|
|
20228
20377
|
<span class="svu-metadata-value">${escapeHtml(config.encryption.postQuantum)}</span>
|
|
20229
20378
|
</div>
|
|
20230
20379
|
<div class="svu-metadata-item">
|
|
20231
|
-
<span class="svu-metadata-label">Forge
|
|
20380
|
+
<span class="svu-metadata-label">Forge status</span>
|
|
20232
20381
|
<span class="svu-metadata-value ${config.forgeStatus === 'active' ? 'svu-status-active' : ''}">
|
|
20233
20382
|
${config.forgeStatus === 'active' ? '● Active' : '○ Inactive'}
|
|
20234
20383
|
</span>
|
|
@@ -20243,23 +20392,24 @@ class UploadRenderer {
|
|
|
20243
20392
|
renderUploading(state) {
|
|
20244
20393
|
const div = document.createElement('div');
|
|
20245
20394
|
div.className = 'svu-uploading-view';
|
|
20246
|
-
|
|
20395
|
+
// Once every byte is sent, SparkVault encrypts and stores the last of them
|
|
20396
|
+
// and saves the file; the transfer ends only once it confirms the save.
|
|
20247
20397
|
div.innerHTML = `
|
|
20248
|
-
<h2 class="svu-title"
|
|
20398
|
+
<h2 class="svu-title" tabindex="-1">${state.securing ? 'Securing your file' : 'Streaming and encrypting'}</h2>
|
|
20249
20399
|
|
|
20250
20400
|
<div class="svu-stages">
|
|
20251
20401
|
<div class="svu-stage svu-active">
|
|
20252
|
-
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
|
|
20402
|
+
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
|
|
20253
20403
|
<rect x="2" y="3" width="20" height="18" rx="2"/>
|
|
20254
20404
|
<path d="M2 9h20"/>
|
|
20255
20405
|
<circle cx="6" cy="6" r="1" fill="currentColor"/>
|
|
20256
20406
|
<circle cx="10" cy="6" r="1" fill="currentColor"/>
|
|
20257
20407
|
</svg>
|
|
20258
|
-
<span>Your
|
|
20408
|
+
<span>Your browser</span>
|
|
20259
20409
|
</div>
|
|
20260
20410
|
<div class="svu-stage-arrow svu-active"></div>
|
|
20261
20411
|
<div class="svu-stage svu-active">
|
|
20262
|
-
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
|
|
20412
|
+
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
|
|
20263
20413
|
<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
|
|
20264
20414
|
</svg>
|
|
20265
20415
|
<span>SparkVault</span>
|
|
@@ -20267,7 +20417,7 @@ class UploadRenderer {
|
|
|
20267
20417
|
</div>
|
|
20268
20418
|
<div class="svu-stage-arrow"></div>
|
|
20269
20419
|
<div class="svu-stage">
|
|
20270
|
-
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
|
|
20420
|
+
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
|
|
20271
20421
|
<rect x="3" y="3" width="18" height="18" rx="2"/>
|
|
20272
20422
|
<circle cx="12" cy="12" r="3"/>
|
|
20273
20423
|
<path d="M12 9V6M12 18v-3M9 12H6M18 12h-3"/>
|
|
@@ -20287,73 +20437,50 @@ class UploadRenderer {
|
|
|
20287
20437
|
</div>
|
|
20288
20438
|
|
|
20289
20439
|
<div class="svu-forging-info">
|
|
20290
|
-
<p class="svu-forging-line">Forging Ingot ID: <span class="svu-mono">${
|
|
20291
|
-
${transferChannelLine(state.requestId)}
|
|
20292
|
-
</div>
|
|
20293
|
-
`;
|
|
20294
|
-
return div;
|
|
20295
|
-
}
|
|
20296
|
-
renderCeremony(state) {
|
|
20297
|
-
const div = document.createElement('div');
|
|
20298
|
-
div.className = 'svu-ceremony-view';
|
|
20299
|
-
const displayIngotId = hexToBase64url(state.ingotId.replace('ing_', ''));
|
|
20300
|
-
let stepsHtml = '';
|
|
20301
|
-
CEREMONY_STEPS.forEach((step, index) => {
|
|
20302
|
-
const isComplete = index < state.step;
|
|
20303
|
-
const isActive = index === state.step;
|
|
20304
|
-
stepsHtml += `
|
|
20305
|
-
<div class="svu-ceremony-step ${isComplete ? 'svu-complete' : ''} ${isActive ? 'svu-active' : ''}">
|
|
20306
|
-
<span class="svu-step-icon">
|
|
20307
|
-
${isComplete
|
|
20308
|
-
? '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 6L9 17l-5-5"/></svg>'
|
|
20309
|
-
: isActive
|
|
20310
|
-
? '<svg class="svu-spin" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4M4.93 19.07l2.83-2.83M16.24 7.76l2.83-2.83"/></svg>'
|
|
20311
|
-
: ''}
|
|
20312
|
-
</span>
|
|
20313
|
-
<span class="svu-step-text">${step.text}</span>
|
|
20314
|
-
</div>
|
|
20315
|
-
`;
|
|
20316
|
-
});
|
|
20317
|
-
div.innerHTML = `
|
|
20318
|
-
<h2 class="svu-title">Securing Your File</h2>
|
|
20319
|
-
|
|
20320
|
-
<div class="svu-ceremony-steps">
|
|
20321
|
-
${stepsHtml}
|
|
20322
|
-
</div>
|
|
20323
|
-
|
|
20324
|
-
<div class="svu-forging-info">
|
|
20325
|
-
<p class="svu-forging-line">Forging Ingot ID: <span class="svu-mono">${displayIngotId}</span></p>
|
|
20440
|
+
<p class="svu-forging-line">Forging Ingot ID: <span class="svu-mono">${escapeHtml(state.ingotId)}</span></p>
|
|
20326
20441
|
${transferChannelLine(state.requestId)}
|
|
20327
20442
|
</div>
|
|
20328
20443
|
`;
|
|
20444
|
+
// Stopping is offered while the bytes move. Once every byte is sent the
|
|
20445
|
+
// save is SparkVault's to finish, so a cancel could not promise the file
|
|
20446
|
+
// was not kept.
|
|
20447
|
+
if (!state.securing) {
|
|
20448
|
+
const cancel = document.createElement('button');
|
|
20449
|
+
cancel.type = 'button';
|
|
20450
|
+
cancel.className = 'svu-btn svu-btn-secondary svu-cancel-upload';
|
|
20451
|
+
cancel.textContent = 'Cancel upload';
|
|
20452
|
+
cancel.addEventListener('click', () => this.cancelUpload());
|
|
20453
|
+
div.appendChild(cancel);
|
|
20454
|
+
}
|
|
20329
20455
|
return div;
|
|
20330
20456
|
}
|
|
20331
20457
|
renderComplete(result, config) {
|
|
20332
20458
|
const div = document.createElement('div');
|
|
20333
20459
|
div.className = 'svu-complete-view';
|
|
20334
20460
|
div.innerHTML = `
|
|
20335
|
-
<div class="svu-success-icon">
|
|
20461
|
+
<div class="svu-success-icon" aria-hidden="true">
|
|
20336
20462
|
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
|
|
20337
20463
|
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/>
|
|
20338
20464
|
<path d="M22 4L12 14.01l-3-3"/>
|
|
20339
20465
|
</svg>
|
|
20340
20466
|
</div>
|
|
20341
20467
|
|
|
20342
|
-
<h2 class="svu-success-title">
|
|
20468
|
+
<h2 class="svu-success-title" tabindex="-1">File sent securely</h2>
|
|
20343
20469
|
|
|
20344
20470
|
<div class="svu-success-details">
|
|
20345
20471
|
<div class="svu-success-row">
|
|
20346
20472
|
<span class="svu-success-label">Ingot ID</span>
|
|
20347
20473
|
<span class="svu-success-value svu-mono">
|
|
20348
20474
|
${escapeHtml(result.ingotId)}
|
|
20349
|
-
<button class="svu-copy-btn" aria-label="Copy Ingot ID">
|
|
20350
|
-
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
20475
|
+
<button type="button" class="svu-copy-btn" aria-label="Copy Ingot ID">
|
|
20476
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
|
20351
20477
|
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
|
|
20352
20478
|
<path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/>
|
|
20353
20479
|
</svg>
|
|
20354
20480
|
</button>
|
|
20355
20481
|
</span>
|
|
20356
20482
|
</div>
|
|
20483
|
+
<p class="svu-copy-status" role="status"></p>
|
|
20357
20484
|
<div class="svu-success-row">
|
|
20358
20485
|
<span class="svu-success-label">File</span>
|
|
20359
20486
|
<span class="svu-success-value">${escapeHtml(result.filename)}</span>
|
|
@@ -20373,34 +20500,62 @@ class UploadRenderer {
|
|
|
20373
20500
|
</div>
|
|
20374
20501
|
|
|
20375
20502
|
<p class="svu-success-guidance">
|
|
20376
|
-
${escapeHtml(config.branding.organizationName)}
|
|
20377
|
-
|
|
20503
|
+
${escapeHtml(config.branding.organizationName)} can open this file in SparkVault.
|
|
20504
|
+
Save the Ingot ID above for your records.
|
|
20378
20505
|
</p>
|
|
20379
|
-
|
|
20380
|
-
${this.options.hideUploadAnother ? '' : `
|
|
20381
|
-
<button class="svu-btn svu-btn-secondary">
|
|
20382
|
-
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
20383
|
-
<path d="M1 4v6h6M23 20v-6h-6"/>
|
|
20384
|
-
<path d="M20.49 9A9 9 0 005.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 013.51 15"/>
|
|
20385
|
-
</svg>
|
|
20386
|
-
Upload Another File
|
|
20387
|
-
</button>
|
|
20388
|
-
`}
|
|
20389
20506
|
`;
|
|
20390
|
-
// Copy button handler
|
|
20391
20507
|
const copyBtn = div.querySelector('.svu-copy-btn');
|
|
20392
|
-
|
|
20393
|
-
|
|
20394
|
-
|
|
20395
|
-
});
|
|
20508
|
+
const copyStatus = div.querySelector('.svu-copy-status');
|
|
20509
|
+
if (copyBtn && copyStatus) {
|
|
20510
|
+
copyBtn.addEventListener('click', () => this.copyIngotId(result.ingotId, copyStatus));
|
|
20396
20511
|
}
|
|
20397
|
-
|
|
20398
|
-
|
|
20399
|
-
|
|
20400
|
-
|
|
20401
|
-
|
|
20402
|
-
|
|
20403
|
-
|
|
20512
|
+
if (!this.options.hideUploadAnother) {
|
|
20513
|
+
div.appendChild(this.recoveryButton({ label: 'Upload another file', keepFile: false }, config, 'svu-btn-secondary'));
|
|
20514
|
+
}
|
|
20515
|
+
return div;
|
|
20516
|
+
}
|
|
20517
|
+
/**
|
|
20518
|
+
* Copy the Ingot ID, saying beside it that it landed ("Copied", for
|
|
20519
|
+
* COPIED_SHOWS_MS) or that the browser refused it, and how to take the ID
|
|
20520
|
+
* instead. A browser without the clipboard API refuses like one that denies
|
|
20521
|
+
* it.
|
|
20522
|
+
*/
|
|
20523
|
+
async copyIngotId(ingotId, status) {
|
|
20524
|
+
try {
|
|
20525
|
+
await navigator.clipboard.writeText(ingotId);
|
|
20526
|
+
}
|
|
20527
|
+
catch {
|
|
20528
|
+
status.textContent = COPY_REFUSED_MESSAGE;
|
|
20529
|
+
return;
|
|
20530
|
+
}
|
|
20531
|
+
status.textContent = 'Copied';
|
|
20532
|
+
setTimeout(() => {
|
|
20533
|
+
if (status.textContent === 'Copied')
|
|
20534
|
+
status.textContent = '';
|
|
20535
|
+
}, COPIED_SHOWS_MS);
|
|
20536
|
+
}
|
|
20537
|
+
/**
|
|
20538
|
+
* A file whose every byte reached SparkVault, which is still saving it and
|
|
20539
|
+
* finishes on its own: received, never failed, so it reads as an outcome,
|
|
20540
|
+
* with the way on to another file.
|
|
20541
|
+
*/
|
|
20542
|
+
renderReceived(message, action) {
|
|
20543
|
+
const div = document.createElement('div');
|
|
20544
|
+
div.className = 'svu-complete-view';
|
|
20545
|
+
div.innerHTML = `
|
|
20546
|
+
<div class="svu-success-icon" aria-hidden="true">
|
|
20547
|
+
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
|
|
20548
|
+
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/>
|
|
20549
|
+
<path d="M22 4L12 14.01l-3-3"/>
|
|
20550
|
+
</svg>
|
|
20551
|
+
</div>
|
|
20552
|
+
|
|
20553
|
+
<h2 class="svu-success-title" tabindex="-1">File received</h2>
|
|
20554
|
+
|
|
20555
|
+
<p class="svu-success-guidance">${escapeHtml(message)}</p>
|
|
20556
|
+
`;
|
|
20557
|
+
if (action && this.config && !this.options.hideUploadAnother) {
|
|
20558
|
+
div.appendChild(this.recoveryButton(action, this.config, 'svu-btn-secondary'));
|
|
20404
20559
|
}
|
|
20405
20560
|
return div;
|
|
20406
20561
|
}
|
|
@@ -20408,38 +20563,47 @@ class UploadRenderer {
|
|
|
20408
20563
|
const div = document.createElement('div');
|
|
20409
20564
|
div.className = 'svu-error-view';
|
|
20410
20565
|
div.innerHTML = `
|
|
20411
|
-
<div class="svu-error-icon">
|
|
20566
|
+
<div class="svu-error-icon" aria-hidden="true">
|
|
20412
20567
|
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
|
20413
20568
|
<circle cx="12" cy="12" r="10"/>
|
|
20414
20569
|
<path d="M12 8v4M12 16h.01"/>
|
|
20415
20570
|
</svg>
|
|
20416
20571
|
</div>
|
|
20417
20572
|
|
|
20418
|
-
<h2 class="svu-error-title">${escapeHtml(state.title)}</h2>
|
|
20573
|
+
<h2 class="svu-error-title" tabindex="-1">${escapeHtml(state.title)}</h2>
|
|
20419
20574
|
|
|
20420
20575
|
<p class="svu-error-message">${escapeHtml(state.message)}</p>
|
|
20421
|
-
|
|
20422
|
-
<div class="svu-error-code">
|
|
20423
|
-
<span class="svu-error-code-label">Code</span>
|
|
20424
|
-
<span class="svu-error-code-value">${escapeHtml(state.code)}</span>
|
|
20425
|
-
</div>
|
|
20426
20576
|
`;
|
|
20427
|
-
|
|
20428
|
-
|
|
20429
|
-
const config = this.config;
|
|
20430
|
-
const recover = document.createElement('button');
|
|
20431
|
-
recover.className = 'svu-btn svu-btn-primary';
|
|
20432
|
-
recover.textContent = action.label;
|
|
20433
|
-
recover.addEventListener('click', () => {
|
|
20434
|
-
if (!action.keepFile)
|
|
20435
|
-
this.selectedFile = null;
|
|
20436
|
-
this.setState({ view: 'form', config });
|
|
20437
|
-
});
|
|
20438
|
-
div.appendChild(recover);
|
|
20577
|
+
if (state.action && this.config) {
|
|
20578
|
+
div.appendChild(this.recoveryButton(state.action, this.config, 'svu-btn-primary'));
|
|
20439
20579
|
}
|
|
20440
20580
|
return div;
|
|
20441
20581
|
}
|
|
20582
|
+
/** The button that takes the person back to the form, with or without the chosen file. */
|
|
20583
|
+
recoveryButton(action, config, variant) {
|
|
20584
|
+
const button = document.createElement('button');
|
|
20585
|
+
button.type = 'button';
|
|
20586
|
+
button.className = `svu-btn ${variant}`;
|
|
20587
|
+
button.textContent = action.label;
|
|
20588
|
+
button.addEventListener('click', () => {
|
|
20589
|
+
if (!action.keepFile)
|
|
20590
|
+
this.selectedFile = null;
|
|
20591
|
+
this.setState({ view: 'form', config });
|
|
20592
|
+
});
|
|
20593
|
+
return button;
|
|
20594
|
+
}
|
|
20595
|
+
/**
|
|
20596
|
+
* Whether a file the person drops, picks, pastes or removes counts: only on
|
|
20597
|
+
* the form, and only while no upload runs (uploadInFlight). The paste
|
|
20598
|
+
* listener hears the whole page in every view, and a file it took mid-upload
|
|
20599
|
+
* would start a second upload beside the first.
|
|
20600
|
+
*/
|
|
20601
|
+
formTakesFile() {
|
|
20602
|
+
return this.viewState.view === 'form' && !this.uploadInFlight;
|
|
20603
|
+
}
|
|
20442
20604
|
handleFileSelect(file, config) {
|
|
20605
|
+
if (!this.formTakesFile())
|
|
20606
|
+
return;
|
|
20443
20607
|
if (file.size === 0) {
|
|
20444
20608
|
this.setState({ view: 'form', config, error: EMPTY_FILE_MESSAGE });
|
|
20445
20609
|
return;
|
|
@@ -20479,6 +20643,8 @@ class UploadRenderer {
|
|
|
20479
20643
|
setupPasteHandler(config) {
|
|
20480
20644
|
// Remove any existing handler first
|
|
20481
20645
|
this.cleanupPasteHandler();
|
|
20646
|
+
// It hears the page's every paste, in every view: handleFileSelect takes
|
|
20647
|
+
// the file only where the form does (formTakesFile).
|
|
20482
20648
|
this.pasteHandler = (e) => {
|
|
20483
20649
|
const items = e.clipboardData?.items;
|
|
20484
20650
|
if (!items)
|
|
@@ -20502,12 +20668,18 @@ class UploadRenderer {
|
|
|
20502
20668
|
}
|
|
20503
20669
|
}
|
|
20504
20670
|
async startUpload(config) {
|
|
20505
|
-
if (!this.selectedFile)
|
|
20671
|
+
if (!this.selectedFile || this.uploadInFlight)
|
|
20506
20672
|
return;
|
|
20507
20673
|
const file = this.selectedFile;
|
|
20674
|
+
const generation = ++this.uploadGeneration;
|
|
20675
|
+
const current = () => generation === this.uploadGeneration;
|
|
20676
|
+
this.uploadInFlight = true;
|
|
20677
|
+
this.holdPage(true);
|
|
20508
20678
|
try {
|
|
20509
20679
|
// Initiate upload. Its Core request id names the transfer channel shown.
|
|
20510
20680
|
const { forgeUrl, ingotId, requestId } = await this.api.initiateUpload(config.vaultId, file.name, file.size, file.type || 'application/octet-stream', this.options.token, this.options.folder);
|
|
20681
|
+
if (!current())
|
|
20682
|
+
return;
|
|
20511
20683
|
// Show uploading state
|
|
20512
20684
|
this.setState({
|
|
20513
20685
|
view: 'uploading',
|
|
@@ -20516,12 +20688,20 @@ class UploadRenderer {
|
|
|
20516
20688
|
requestId,
|
|
20517
20689
|
progress: 0,
|
|
20518
20690
|
bytesUploaded: 0,
|
|
20691
|
+
securing: false,
|
|
20519
20692
|
});
|
|
20520
20693
|
// Upload file over the canonical TUS transfer path. It resolves only
|
|
20521
20694
|
// once the server has confirmed finalization, so a non-finalized upload
|
|
20522
|
-
// throws here and never reaches the success
|
|
20695
|
+
// throws here and never reaches the success view.
|
|
20523
20696
|
await this.api.uploadFileToForge(file, forgeUrl, (bytesUploaded, bytesTotal) => {
|
|
20697
|
+
if (!current())
|
|
20698
|
+
return;
|
|
20524
20699
|
const progress = Math.round((bytesUploaded / bytesTotal) * 100);
|
|
20700
|
+
// Every byte sent: the server may hold, and publish, the whole file
|
|
20701
|
+
// now, so a cancel could no longer promise it was not kept. The count
|
|
20702
|
+
// is the transfer's high-water mark, which never runs backwards, so a
|
|
20703
|
+
// last chunk resent after its answer was lost still reads as sent.
|
|
20704
|
+
const securing = bytesUploaded >= bytesTotal;
|
|
20525
20705
|
this.setState({
|
|
20526
20706
|
view: 'uploading',
|
|
20527
20707
|
file,
|
|
@@ -20529,7 +20709,9 @@ class UploadRenderer {
|
|
|
20529
20709
|
requestId,
|
|
20530
20710
|
progress,
|
|
20531
20711
|
bytesUploaded,
|
|
20712
|
+
securing,
|
|
20532
20713
|
});
|
|
20714
|
+
// The phase stays 'uploading' until SparkVault confirms the save.
|
|
20533
20715
|
this.callbacks.onProgress?.({
|
|
20534
20716
|
bytesUploaded,
|
|
20535
20717
|
bytesTotal,
|
|
@@ -20537,8 +20719,9 @@ class UploadRenderer {
|
|
|
20537
20719
|
phase: 'uploading',
|
|
20538
20720
|
});
|
|
20539
20721
|
});
|
|
20540
|
-
|
|
20541
|
-
|
|
20722
|
+
if (!current())
|
|
20723
|
+
return;
|
|
20724
|
+
this.holdPage(false);
|
|
20542
20725
|
// Complete
|
|
20543
20726
|
const now = new Date();
|
|
20544
20727
|
const uploadTime = `${now.getUTCFullYear()}-${String(now.getUTCMonth() + 1).padStart(2, '0')}-${String(now.getUTCDate()).padStart(2, '0')} ${String(now.getUTCHours()).padStart(2, '0')}:${String(now.getUTCMinutes()).padStart(2, '0')}:${String(now.getUTCSeconds()).padStart(2, '0')} UTC`;
|
|
@@ -20549,13 +20732,11 @@ class UploadRenderer {
|
|
|
20549
20732
|
sizeBytes: file.size,
|
|
20550
20733
|
uploadTime,
|
|
20551
20734
|
};
|
|
20552
|
-
//
|
|
20553
|
-
|
|
20554
|
-
|
|
20555
|
-
|
|
20556
|
-
|
|
20557
|
-
phase: 'complete',
|
|
20558
|
-
});
|
|
20735
|
+
// SparkVault confirmed the save: a host reads 'ceremony' as that
|
|
20736
|
+
// confirmation, then 'complete' as the upload's end (UploadProgress).
|
|
20737
|
+
const sent = { bytesUploaded: file.size, bytesTotal: file.size, percentage: 100 };
|
|
20738
|
+
this.callbacks.onProgress?.({ ...sent, phase: 'ceremony' });
|
|
20739
|
+
this.callbacks.onProgress?.({ ...sent, phase: 'complete' });
|
|
20559
20740
|
// Silent mode: skip the success screen — fire onSuccess and close so
|
|
20560
20741
|
// the host site can render its own post-upload UI.
|
|
20561
20742
|
if (this.options.hideSuccessScreen) {
|
|
@@ -20568,43 +20749,65 @@ class UploadRenderer {
|
|
|
20568
20749
|
this.callbacks.onSuccess(result);
|
|
20569
20750
|
}
|
|
20570
20751
|
catch (error) {
|
|
20752
|
+
if (!current())
|
|
20753
|
+
return;
|
|
20754
|
+
this.holdPage(false);
|
|
20571
20755
|
// A host that chose the file itself offers its own way on; the
|
|
20572
20756
|
// widget's form is the way on only for a file chosen on it.
|
|
20573
20757
|
this.handleApiError(error, this.options.file ? null : recoveryAfterUpload(error));
|
|
20574
20758
|
}
|
|
20759
|
+
finally {
|
|
20760
|
+
// A cancelled upload's number is no longer current: cancelUpload ended
|
|
20761
|
+
// it, and another may already run.
|
|
20762
|
+
if (current())
|
|
20763
|
+
this.uploadInFlight = false;
|
|
20764
|
+
}
|
|
20575
20765
|
}
|
|
20576
|
-
|
|
20577
|
-
|
|
20578
|
-
|
|
20579
|
-
|
|
20580
|
-
|
|
20581
|
-
|
|
20582
|
-
|
|
20583
|
-
|
|
20584
|
-
|
|
20585
|
-
|
|
20586
|
-
|
|
20587
|
-
|
|
20588
|
-
|
|
20589
|
-
|
|
20590
|
-
|
|
20591
|
-
|
|
20592
|
-
|
|
20766
|
+
/**
|
|
20767
|
+
* Stop the upload whose bytes are moving. The stopped upload's late events
|
|
20768
|
+
* render nothing and tell the host nothing (uploadGeneration).
|
|
20769
|
+
*
|
|
20770
|
+
* A file the host chose itself skipped the form, so its upload ends the
|
|
20771
|
+
* widget through the cancel contract (cancel(): the transfer aborted with
|
|
20772
|
+
* the session, onCancel, UserCancelledError), and the host offers its own
|
|
20773
|
+
* way on. A file chosen on the widget returns to the form, still chosen, so
|
|
20774
|
+
* a wrong or slow pick costs one tap: the transfer is aborted with the
|
|
20775
|
+
* session's signal, a fresh session serves the next upload, and neither
|
|
20776
|
+
* callback fires, since the widget stays open and the host hears of the
|
|
20777
|
+
* next upload.
|
|
20778
|
+
*/
|
|
20779
|
+
cancelUpload() {
|
|
20780
|
+
if (this.viewState.view !== 'uploading' || this.viewState.securing || !this.config)
|
|
20781
|
+
return;
|
|
20782
|
+
this.uploadGeneration += 1;
|
|
20783
|
+
this.uploadInFlight = false;
|
|
20784
|
+
if (this.options.file) {
|
|
20785
|
+
this.cancel();
|
|
20786
|
+
return;
|
|
20593
20787
|
}
|
|
20594
|
-
|
|
20595
|
-
this.
|
|
20596
|
-
|
|
20597
|
-
|
|
20598
|
-
ingotId,
|
|
20599
|
-
requestId,
|
|
20600
|
-
step: CEREMONY_STEPS.length,
|
|
20601
|
-
complete: true,
|
|
20602
|
-
});
|
|
20603
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
20788
|
+
this.api.abort();
|
|
20789
|
+
this.api.resetSession();
|
|
20790
|
+
this.holdPage(false);
|
|
20791
|
+
this.setState({ view: 'form', config: this.config });
|
|
20604
20792
|
}
|
|
20605
20793
|
/**
|
|
20606
|
-
*
|
|
20607
|
-
*
|
|
20794
|
+
* Ask before the page is closed or reloaded while an upload runs
|
|
20795
|
+
* (this.warnBeforeLeaving), or stop asking.
|
|
20796
|
+
*/
|
|
20797
|
+
holdPage(hold) {
|
|
20798
|
+
if (hold) {
|
|
20799
|
+
window.addEventListener('beforeunload', this.warnBeforeLeaving);
|
|
20800
|
+
}
|
|
20801
|
+
else {
|
|
20802
|
+
window.removeEventListener('beforeunload', this.warnBeforeLeaving);
|
|
20803
|
+
}
|
|
20804
|
+
}
|
|
20805
|
+
/**
|
|
20806
|
+
* Show a failure (`action`: the way on it offers, none for a page that
|
|
20807
|
+
* could not load), and tell the host through onError. A file received whole
|
|
20808
|
+
* and still being saved reads as received, never as a failure; the host
|
|
20809
|
+
* still hears it through onError, with its code, which tells it never to
|
|
20810
|
+
* upload the file again.
|
|
20608
20811
|
*/
|
|
20609
20812
|
handleApiError(error, action = null) {
|
|
20610
20813
|
// A closed renderer must not surface errors: cancelling mid-transfer
|
|
@@ -20615,116 +20818,14 @@ class UploadRenderer {
|
|
|
20615
20818
|
if (this.closed || isCancellationError(error)) {
|
|
20616
20819
|
return;
|
|
20617
20820
|
}
|
|
20618
|
-
|
|
20619
|
-
|
|
20620
|
-
|
|
20621
|
-
// This is almost always a developer/admin oversight, so the message
|
|
20622
|
-
// points at the dashboard rather than the end user.
|
|
20623
|
-
this.setState({
|
|
20624
|
-
view: 'error',
|
|
20625
|
-
action,
|
|
20626
|
-
title: 'Upload Widget Not Enabled',
|
|
20627
|
-
message: 'This vault has not enabled the embedded upload widget. Enable it on the vault\'s settings page in the SparkVault dashboard to start accepting uploads here.',
|
|
20628
|
-
code: 'UPLOAD_SOURCE_DISABLED',
|
|
20629
|
-
statusCode: error.statusCode,
|
|
20630
|
-
});
|
|
20631
|
-
}
|
|
20632
|
-
else if (error.code === RECEIVED_STILL_SAVING) {
|
|
20633
|
-
// Every byte reached the server, which is still saving the file and
|
|
20634
|
-
// finishes it on its own: nothing failed, and nothing is left to do.
|
|
20635
|
-
// The host still hears it through onError, with this code, which
|
|
20636
|
-
// tells it never to upload the file again.
|
|
20637
|
-
this.setState({
|
|
20638
|
-
view: 'error',
|
|
20639
|
-
action,
|
|
20640
|
-
title: 'Upload Received',
|
|
20641
|
-
message: error.message,
|
|
20642
|
-
code: error.code,
|
|
20643
|
-
statusCode: error.statusCode,
|
|
20644
|
-
});
|
|
20645
|
-
}
|
|
20646
|
-
else if (error.code === VAULT_DELETION_SCHEDULED || error.details?.coreCode === VAULT_DELETION_SCHEDULED) {
|
|
20647
|
-
// The vault is scheduled for deletion, refused at the upload's start
|
|
20648
|
-
// or while its bytes moved. Core's sentence tells the vault's admin
|
|
20649
|
-
// how to cancel the deletion; the person on this page is an outside
|
|
20650
|
-
// uploader, told only that the vault takes no files now.
|
|
20651
|
-
this.setState({
|
|
20652
|
-
view: 'error',
|
|
20653
|
-
action,
|
|
20654
|
-
title: 'Uploads Paused',
|
|
20655
|
-
message: VAULT_NOT_ACCEPTING_MESSAGE,
|
|
20656
|
-
code: error.code,
|
|
20657
|
-
statusCode: error.statusCode,
|
|
20658
|
-
});
|
|
20659
|
-
}
|
|
20660
|
-
else if (error.code === 'upload_refused') {
|
|
20661
|
-
// Core refused the upload, in its own words (whom to contact about a
|
|
20662
|
-
// full storage pool, or the later upload that replaced this one): a
|
|
20663
|
-
// sentence that never asks for the file again.
|
|
20664
|
-
this.setState({
|
|
20665
|
-
view: 'error',
|
|
20666
|
-
action,
|
|
20667
|
-
title: 'Upload Not Saved',
|
|
20668
|
-
message: error.message,
|
|
20669
|
-
code: error.code,
|
|
20670
|
-
statusCode: error.statusCode,
|
|
20671
|
-
});
|
|
20672
|
-
}
|
|
20673
|
-
else if (error.statusCode === 404 && error.code !== 'session_gone') {
|
|
20674
|
-
// A vault or upload route that does not exist. A gone upload session
|
|
20675
|
-
// can answer 404 too, and its own sentence says what became of the file.
|
|
20676
|
-
this.setState({
|
|
20677
|
-
view: 'error',
|
|
20678
|
-
action,
|
|
20679
|
-
title: 'Upload Page Not Found',
|
|
20680
|
-
message: 'The requested upload endpoint could not be located. This may occur if the upload link has expired or was entered incorrectly.',
|
|
20681
|
-
code: 'NOT_FOUND',
|
|
20682
|
-
statusCode: 404,
|
|
20683
|
-
});
|
|
20684
|
-
}
|
|
20685
|
-
else if (error.statusCode === 402) {
|
|
20686
|
-
this.setState({
|
|
20687
|
-
view: 'error',
|
|
20688
|
-
action,
|
|
20689
|
-
title: 'Service Unavailable',
|
|
20690
|
-
message: 'This upload endpoint has been temporarily disabled due to an account billing issue. Please contact the organization\'s administrator.',
|
|
20691
|
-
code: 'PAYMENT_REQUIRED',
|
|
20692
|
-
statusCode: 402,
|
|
20693
|
-
});
|
|
20694
|
-
}
|
|
20695
|
-
else {
|
|
20696
|
-
this.setState({
|
|
20697
|
-
view: 'error',
|
|
20698
|
-
action,
|
|
20699
|
-
title: 'Upload Failed',
|
|
20700
|
-
message: error.message,
|
|
20701
|
-
code: error.code,
|
|
20702
|
-
statusCode: error.statusCode,
|
|
20703
|
-
});
|
|
20704
|
-
}
|
|
20705
|
-
this.callbacks.onError(error);
|
|
20706
|
-
}
|
|
20707
|
-
else if (error instanceof Error) {
|
|
20708
|
-
this.setState({
|
|
20709
|
-
view: 'error',
|
|
20710
|
-
action,
|
|
20711
|
-
title: 'Upload Failed',
|
|
20712
|
-
message: error.message,
|
|
20713
|
-
code: 'UNKNOWN_ERROR',
|
|
20714
|
-
});
|
|
20715
|
-
this.callbacks.onError(error);
|
|
20821
|
+
const failure = error instanceof Error ? error : new Error('An unexpected error occurred');
|
|
20822
|
+
if (failure instanceof UploadApiError && failure.code === RECEIVED_STILL_SAVING) {
|
|
20823
|
+
this.setState({ view: 'received', message: failure.message, action });
|
|
20716
20824
|
}
|
|
20717
20825
|
else {
|
|
20718
|
-
|
|
20719
|
-
this.setState({
|
|
20720
|
-
view: 'error',
|
|
20721
|
-
action,
|
|
20722
|
-
title: 'Upload Failed',
|
|
20723
|
-
message: err.message,
|
|
20724
|
-
code: 'UNKNOWN_ERROR',
|
|
20725
|
-
});
|
|
20726
|
-
this.callbacks.onError(err);
|
|
20826
|
+
this.setState({ view: 'error', action, ...describeFailure(failure) });
|
|
20727
20827
|
}
|
|
20828
|
+
this.callbacks.onError(failure);
|
|
20728
20829
|
}
|
|
20729
20830
|
}
|
|
20730
20831
|
|
|
@@ -22101,7 +22202,7 @@ class SparkVault {
|
|
|
22101
22202
|
}
|
|
22102
22203
|
/** Get the SDK version */
|
|
22103
22204
|
static get version() {
|
|
22104
|
-
return '15.
|
|
22205
|
+
return '15.1.1';
|
|
22105
22206
|
}
|
|
22106
22207
|
}
|
|
22107
22208
|
if (typeof window !== 'undefined') {
|