@bloklabs/presets 1.16.0 → 2.0.0
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 +1 -1
- package/dist/index.mjs +69 -42
- package/package.json +2 -2
- package/types/index.d.ts +5 -0
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){return new Promise((t,n)=>{var r;let i=new XMLHttpRequest;i.open(e.method,e.url);for(let[t,n]of Object.entries((r=e.headers)==null?{}:r))i.setRequestHeader(t,n);e.onProgress&&(i.upload.onprogress=t=>{var n;t.lengthComputable&&t.total!==0&&((n=e.onProgress)==null||n.call(e,Math.round(t.loaded/t.total*100)))}),i.onload=()=>t({status:i.status,text:i.responseText}),i.onerror=()=>n(Error(`Upload failed: network error`)),i.send(e.body)})}function t(e){"@babel/helpers - typeof";return t=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},t(e)}function n(e,n){if(t(e)!=`object`||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,n||`default`);if(t(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(n===`string`?String:Number)(e)}function r(e){var r=n(e,`string`);return t(r)==`symbol`?r:r+``}function i(e,t,n){return(t=r(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?a(Object(n),!0).forEach(function(t){i(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function s(e){let t=Array.from(e).reduce((e,t)=>t===`/`?e+1:0,0);return e.slice(0,e.length-t)}function c(t){var n;let r=s(t.baseUrl),i=(n=t.field)==null?`file`:n,a=async()=>{var e;return typeof t.headers==`function`?t.headers():(e=t.headers)==null?{}:e};return{async uploadByFile(t,n){let o=new FormData;o.append(i,t);let{status:s,text:c}=await e({method:`POST`,url:`${r}/upload`,body:o,headers:await a(),onProgress:n.onProgress});if(s<200||s>299)throw Error(`Fetch endpoint upload failed with status ${s}`);return l(c,t.name)},async uploadByUrl(e,t){let n=await fetch(`${r}/upload-by-url`,{method:`POST`,headers:o(o({},await a()),{},{"Content-Type":`application/json`}),body:JSON.stringify({url:e})});if(!n.ok)throw Error(`Fetch endpoint upload failed with status ${n.status}`);return d(u(await n.text()))},async delete(e,t){let n=await fetch(`${r}/delete`,{method:`POST`,headers:o(o({},await a()),{},{"Content-Type":`application/json`}),body:JSON.stringify({url:e})});if(!n.ok)throw Error(`Fetch endpoint delete failed with status ${n.status}`)}}}function l(e,t){var n;let r=d(u(e));return{url:r.url,fileName:(n=r.fileName)==null?t:n}}function u(e){try{return JSON.parse(e)}catch(e){throw Error(`Upload failed: the endpoint returned a malformed response`)}}function d(e){if(typeof e!=`object`||!e||typeof e.url!=`string`)throw Error(`Upload failed: the endpoint returned no url`);let t=e;return{url:t.url,fileName:typeof t.fileName==`string`?t.fileName:void 0}}function f(e){return c(e)}function p(e,t={}){let n=e=>{var n;return typeof t.bucket==`function`?t.bucket(e):(n=t.bucket)==null?`blok`:n};return{async uploadByFile(r,i){var a,o;let s=(a=(o=t.path)==null?void 0:o.call(t,r,i))==null?m(r.name):a,{data:c,error:l}=await e.storage.from(n(i.kind)).upload(s,r,{contentType:r.type||void 0,upsert:!1});if(l!==null||c===null){var u;throw Error(`Supabase upload failed: ${(u=l==null?void 0:l.message)==null?`unknown error`:u}`)}let{data:d}=e.storage.from(n(i.kind)).getPublicUrl(c.path);return{url:d.publicUrl,fileName:r.name}}}}function m(e){let t=/\.[a-z0-9]+$/i.exec(e),n=t?t[0].toLowerCase():``;return`${crypto.randomUUID()}${n}`}function h(t){return{async uploadByFile(n,r){let i=await t.sign({fileName:n.name,mimeType:n.type,size:n.size,kind:r.kind}),{status:a}=await e({method:`PUT`,url:i.uploadUrl,body:n,headers:o(o({},i.headers),{},{"Content-Type":n.type||`application/octet-stream`}),onProgress:r.onProgress});if(a<200||a>299)throw Error(`Presigned upload failed with status ${a}`);return{url:i.publicUrl,fileName:n.name}}}}var g={image:`image`,video:`video`,audio:`video`,file:`raw`};function _(t){let n=e=>{var n;return`https://api.cloudinary.com/v1_1/${t.cloudName}/${(n=g[e])==null?`raw`:n}/upload`},r=async(r,i,a)=>{let o=new FormData;o.append(`file`,i),o.append(`upload_preset`,t.uploadPreset),t.folder!==void 0&&o.append(`folder`,t.folder);let{status:s,text:c}=await e({method:`POST`,url:n(r),body:o,onProgress:a});return v(c,s,typeof i==`string`?void 0:i.name)};return{uploadByFile:(e,t)=>r(t.kind,e,t.onProgress),uploadByUrl:(e,t)=>r(t.kind,e,t.onProgress)}}function v(e,t,n){let r=y(e,t);if(typeof r.secure_url!=`string`){var i;let e=r.error;throw Error(`Cloudinary upload failed: ${(i=e==null?void 0:e.message)==null?`status ${t}`:i}`)}return{url:r.secure_url,fileName:n}}function y(e,t){try{return JSON.parse(e)}catch(e){throw Error(`Cloudinary upload failed with status ${t}`)}}var b=`blok-assets`,
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){return new Promise((t,n)=>{var r;let i=new XMLHttpRequest;i.open(e.method,e.url);for(let[t,n]of Object.entries((r=e.headers)==null?{}:r))i.setRequestHeader(t,n);e.onProgress&&(i.upload.onprogress=t=>{var n;t.lengthComputable&&t.total!==0&&((n=e.onProgress)==null||n.call(e,Math.round(t.loaded/t.total*100)))}),i.onload=()=>t({status:i.status,text:i.responseText}),i.onerror=()=>n(Error(`Upload failed: network error`)),i.send(e.body)})}function t(e){"@babel/helpers - typeof";return t=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},t(e)}function n(e,n){if(t(e)!=`object`||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,n||`default`);if(t(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(n===`string`?String:Number)(e)}function r(e){var r=n(e,`string`);return t(r)==`symbol`?r:r+``}function i(e,t,n){return(t=r(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?a(Object(n),!0).forEach(function(t){i(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function s(e){let t=Array.from(e).reduce((e,t)=>t===`/`?e+1:0,0);return e.slice(0,e.length-t)}function c(t){var n;let r=s(t.baseUrl),i=(n=t.field)==null?`file`:n,a=async()=>{var e;return typeof t.headers==`function`?t.headers():(e=t.headers)==null?{}:e};return{async uploadByFile(t,n){let o=new FormData;o.append(i,t);let{status:s,text:c}=await e({method:`POST`,url:`${r}/upload`,body:o,headers:await a(),onProgress:n.onProgress});if(s<200||s>299)throw Error(`Fetch endpoint upload failed with status ${s}`);return l(c,t.name)},async uploadByUrl(e,t){let n=await fetch(`${r}/upload-by-url`,{method:`POST`,headers:o(o({},await a()),{},{"Content-Type":`application/json`}),body:JSON.stringify({url:e})});if(!n.ok)throw Error(`Fetch endpoint upload failed with status ${n.status}`);return d(u(await n.text()))},async delete(e,t){let n=await fetch(`${r}/delete`,{method:`POST`,headers:o(o({},await a()),{},{"Content-Type":`application/json`}),body:JSON.stringify({url:e})});if(!n.ok)throw Error(`Fetch endpoint delete failed with status ${n.status}`)}}}function l(e,t){var n;let r=d(u(e));return{url:r.url,fileName:(n=r.fileName)==null?t:n}}function u(e){try{return JSON.parse(e)}catch(e){throw Error(`Upload failed: the endpoint returned a malformed response`)}}function d(e){if(typeof e!=`object`||!e||typeof e.url!=`string`)throw Error(`Upload failed: the endpoint returned no url`);let t=e;return{url:t.url,fileName:typeof t.fileName==`string`?t.fileName:void 0}}function f(e){return c(e)}function p(e,t={}){let n=e=>{var n;return typeof t.bucket==`function`?t.bucket(e):(n=t.bucket)==null?`blok`:n};return{async uploadByFile(r,i){var a,o;let s=(a=(o=t.path)==null?void 0:o.call(t,r,i))==null?m(r.name):a,{data:c,error:l}=await e.storage.from(n(i.kind)).upload(s,r,{contentType:r.type||void 0,upsert:!1});if(l!==null||c===null){var u;throw Error(`Supabase upload failed: ${(u=l==null?void 0:l.message)==null?`unknown error`:u}`)}let{data:d}=e.storage.from(n(i.kind)).getPublicUrl(c.path);return{url:d.publicUrl,fileName:r.name}}}}function m(e){let t=/\.[a-z0-9]+$/i.exec(e),n=t?t[0].toLowerCase():``;return`${crypto.randomUUID()}${n}`}function h(t){return{async uploadByFile(n,r){let i=await t.sign({fileName:n.name,mimeType:n.type,size:n.size,kind:r.kind}),{status:a}=await e({method:`PUT`,url:i.uploadUrl,body:n,headers:o(o({},i.headers),{},{"Content-Type":n.type||`application/octet-stream`}),onProgress:r.onProgress});if(a<200||a>299)throw Error(`Presigned upload failed with status ${a}`);return{url:i.publicUrl,fileName:n.name}}}}var g={image:`image`,video:`video`,audio:`video`,file:`raw`};function _(t){let n=e=>{var n;return`https://api.cloudinary.com/v1_1/${t.cloudName}/${(n=g[e])==null?`raw`:n}/upload`},r=async(r,i,a)=>{let o=new FormData;o.append(`file`,i),o.append(`upload_preset`,t.uploadPreset),t.folder!==void 0&&o.append(`folder`,t.folder);let{status:s,text:c}=await e({method:`POST`,url:n(r),body:o,onProgress:a});return v(c,s,typeof i==`string`?void 0:i.name)};return{uploadByFile:(e,t)=>r(t.kind,e,t.onProgress),uploadByUrl:(e,t)=>r(t.kind,e,t.onProgress)}}function v(e,t,n){let r=y(e,t);if(typeof r.secure_url!=`string`){var i;let e=r.error;throw Error(`Cloudinary upload failed: ${(i=e==null?void 0:e.message)==null?`status ${t}`:i}`)}return{url:r.secure_url,fileName:n}}function y(e,t){try{return JSON.parse(e)}catch(e){throw Error(`Cloudinary upload failed with status ${t}`)}}var b=new Set([`text/plain`,`text/csv`,`text/markdown`,`text/css`,`text/javascript`,`application/json`,`application/pdf`,`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`image/avif`,`image/bmp`,`image/x-icon`,`video/mp4`,`video/webm`,`video/quicktime`,`audio/mpeg`,`audio/wav`,`audio/ogg`,`audio/webm`,`audio/mp4`,`audio/aac`,`audio/flac`]),x=`image/svg+xml`;function S(e,t={}){let n=e.type.split(`;`)[0].trim(),r=b.has(n)||t.svgImage===!0&&n===x;return URL.createObjectURL(r?e:new Blob([e],{type:`text/plain`}))}var C=e=>{let t=32768,n=Array.from({length:Math.ceil(e.length/t)},(n,r)=>String.fromCharCode(...e.subarray(r*t,(r+1)*t)));return btoa(n.join(``))};async function w(e){return e.type.split(`;`)[0].trim().toLowerCase()!==x||e.size>262144?S(e):`data:${x};base64,${C(new Uint8Array(await e.arrayBuffer()))}`}var T=`blok-assets`,E=`assets`,D=`blok:asset/`;function O(e){return new Promise((t,n)=>{let r=indexedDB.open(e,1);r.onupgradeneeded=()=>{r.result.createObjectStore(E)},r.onsuccess=()=>t(r.result),r.onerror=()=>{var e;return n((e=r.error)==null?Error(`IndexedDB open failed`):e)}})}function k(e,t,n){return new Promise((r,i)=>{let a=n(e.transaction(E,t).objectStore(E));a.onsuccess=()=>r(a.result),a.onerror=()=>{var e;return i((e=a.error)==null?Error(`IndexedDB request failed`):e)}})}function A(e={}){var t;let n=(t=e.dbName)==null?T:t;return{async uploadByFile(e,t){let r=crypto.randomUUID(),i=await O(n);try{await k(i,`readwrite`,n=>n.put({blob:e,name:e.name,type:e.type,kind:t.kind},r))}finally{i.close()}return{url:`${D}${r}`,fileName:e.name}}}}async function j(e,t={}){var n;if(!e.startsWith(D))return e;let r=await M(await O((n=t.dbName)==null?T:n),e.slice(11));return r===void 0?null:r.kind===`image`?w(r.blob):S(r.blob)}function M(e,t){return k(e,`readonly`,e=>e.get(t)).finally(()=>e.close())}exports.cloudinaryStorage=_,exports.fetchStorage=f,exports.indexedDBStorage=A,exports.presignedStorage=h,exports.resolveBlokObjectUrl=j,exports.supabaseStorage=p;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// ../../src/components/utils/upload-xhr.ts
|
|
2
2
|
function e(e) {
|
|
3
3
|
return new Promise((t, n) => {
|
|
4
4
|
var r;
|
|
@@ -14,8 +14,7 @@ function e(e) {
|
|
|
14
14
|
}), i.onerror = () => n(/* @__PURE__ */ Error("Upload failed: network error")), i.send(e.body);
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/typeof.js
|
|
17
|
+
// \0@oxc-project+runtime@0.155.0/helpers/esm/typeof.js
|
|
19
18
|
function t(e) {
|
|
20
19
|
"@babel/helpers - typeof";
|
|
21
20
|
return t = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
|
|
@@ -24,8 +23,7 @@ function t(e) {
|
|
|
24
23
|
return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
|
|
25
24
|
}, t(e);
|
|
26
25
|
}
|
|
27
|
-
|
|
28
|
-
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/toPrimitive.js
|
|
26
|
+
// \0@oxc-project+runtime@0.155.0/helpers/esm/toPrimitive.js
|
|
29
27
|
function n(e, n) {
|
|
30
28
|
if (t(e) != "object" || !e) return e;
|
|
31
29
|
var r = e[Symbol.toPrimitive];
|
|
@@ -36,14 +34,12 @@ function n(e, n) {
|
|
|
36
34
|
}
|
|
37
35
|
return (n === "string" ? String : Number)(e);
|
|
38
36
|
}
|
|
39
|
-
|
|
40
|
-
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/toPropertyKey.js
|
|
37
|
+
// \0@oxc-project+runtime@0.155.0/helpers/esm/toPropertyKey.js
|
|
41
38
|
function r(e) {
|
|
42
39
|
var r = n(e, "string");
|
|
43
40
|
return t(r) == "symbol" ? r : r + "";
|
|
44
41
|
}
|
|
45
|
-
|
|
46
|
-
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/defineProperty.js
|
|
42
|
+
// \0@oxc-project+runtime@0.155.0/helpers/esm/defineProperty.js
|
|
47
43
|
function i(e, t, n) {
|
|
48
44
|
return (t = r(t)) in e ? Object.defineProperty(e, t, {
|
|
49
45
|
value: n,
|
|
@@ -52,8 +48,7 @@ function i(e, t, n) {
|
|
|
52
48
|
writable: !0
|
|
53
49
|
}) : e[t] = n, e;
|
|
54
50
|
}
|
|
55
|
-
|
|
56
|
-
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/objectSpread2.js
|
|
51
|
+
// \0@oxc-project+runtime@0.155.0/helpers/esm/objectSpread2.js
|
|
57
52
|
function a(e, t) {
|
|
58
53
|
var n = Object.keys(e);
|
|
59
54
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -75,8 +70,7 @@ function o(e) {
|
|
|
75
70
|
}
|
|
76
71
|
return e;
|
|
77
72
|
}
|
|
78
|
-
|
|
79
|
-
//#region ../../src/components/utils/fetch-uploader.ts
|
|
73
|
+
// ../../src/components/utils/fetch-uploader.ts
|
|
80
74
|
function s(e) {
|
|
81
75
|
let t = Array.from(e).reduce((e, t) => t === "/" ? e + 1 : 0, 0);
|
|
82
76
|
return e.slice(0, e.length - t);
|
|
@@ -143,13 +137,11 @@ function d(e) {
|
|
|
143
137
|
fileName: typeof t.fileName == "string" ? t.fileName : void 0
|
|
144
138
|
};
|
|
145
139
|
}
|
|
146
|
-
|
|
147
|
-
//#region src/fetch-endpoint.ts
|
|
140
|
+
// src/fetch-endpoint.ts
|
|
148
141
|
function f(e) {
|
|
149
142
|
return c(e);
|
|
150
143
|
}
|
|
151
|
-
|
|
152
|
-
//#region src/supabase.ts
|
|
144
|
+
// src/supabase.ts
|
|
153
145
|
function p(e, t = {}) {
|
|
154
146
|
let n = (e) => {
|
|
155
147
|
var n;
|
|
@@ -176,8 +168,7 @@ function m(e) {
|
|
|
176
168
|
let t = /\.[a-z0-9]+$/i.exec(e), n = t ? t[0].toLowerCase() : "";
|
|
177
169
|
return `${crypto.randomUUID()}${n}`;
|
|
178
170
|
}
|
|
179
|
-
|
|
180
|
-
//#region src/presigned.ts
|
|
171
|
+
// src/presigned.ts
|
|
181
172
|
function h(t) {
|
|
182
173
|
return { async uploadByFile(n, r) {
|
|
183
174
|
let i = await t.sign({
|
|
@@ -199,8 +190,7 @@ function h(t) {
|
|
|
199
190
|
};
|
|
200
191
|
} };
|
|
201
192
|
}
|
|
202
|
-
|
|
203
|
-
//#region src/cloudinary.ts
|
|
193
|
+
// src/cloudinary.ts
|
|
204
194
|
var g = {
|
|
205
195
|
image: "image",
|
|
206
196
|
video: "video",
|
|
@@ -246,57 +236,94 @@ function y(e, t) {
|
|
|
246
236
|
throw Error(`Cloudinary upload failed with status ${t}`);
|
|
247
237
|
}
|
|
248
238
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
239
|
+
// ../../src/shared/safe-object-url.ts
|
|
240
|
+
var b = /* @__PURE__ */ new Set([
|
|
241
|
+
"text/plain",
|
|
242
|
+
"text/csv",
|
|
243
|
+
"text/markdown",
|
|
244
|
+
"text/css",
|
|
245
|
+
"text/javascript",
|
|
246
|
+
"application/json",
|
|
247
|
+
"application/pdf",
|
|
248
|
+
"image/png",
|
|
249
|
+
"image/jpeg",
|
|
250
|
+
"image/gif",
|
|
251
|
+
"image/webp",
|
|
252
|
+
"image/avif",
|
|
253
|
+
"image/bmp",
|
|
254
|
+
"image/x-icon",
|
|
255
|
+
"video/mp4",
|
|
256
|
+
"video/webm",
|
|
257
|
+
"video/quicktime",
|
|
258
|
+
"audio/mpeg",
|
|
259
|
+
"audio/wav",
|
|
260
|
+
"audio/ogg",
|
|
261
|
+
"audio/webm",
|
|
262
|
+
"audio/mp4",
|
|
263
|
+
"audio/aac",
|
|
264
|
+
"audio/flac"
|
|
265
|
+
]), x = "image/svg+xml";
|
|
266
|
+
function S(e, t = {}) {
|
|
267
|
+
let n = e.type.split(";")[0].trim(), r = b.has(n) || t.svgImage === !0 && n === x;
|
|
268
|
+
return URL.createObjectURL(r ? e : new Blob([e], { type: "text/plain" }));
|
|
269
|
+
}
|
|
270
|
+
var C = (e) => {
|
|
271
|
+
let t = 32768, n = Array.from({ length: Math.ceil(e.length / t) }, (n, r) => String.fromCharCode(...e.subarray(r * t, (r + 1) * t)));
|
|
272
|
+
return btoa(n.join(""));
|
|
273
|
+
};
|
|
274
|
+
async function w(e) {
|
|
275
|
+
return e.type.split(";")[0].trim().toLowerCase() !== x || e.size > 262144 ? S(e) : `data:${x};base64,${C(new Uint8Array(await e.arrayBuffer()))}`;
|
|
276
|
+
}
|
|
277
|
+
// src/indexeddb.ts
|
|
278
|
+
var T = "blok-assets", E = "assets", D = "blok:asset/";
|
|
279
|
+
function O(e) {
|
|
253
280
|
return new Promise((t, n) => {
|
|
254
281
|
let r = indexedDB.open(e, 1);
|
|
255
282
|
r.onupgradeneeded = () => {
|
|
256
|
-
r.result.createObjectStore(
|
|
283
|
+
r.result.createObjectStore(E);
|
|
257
284
|
}, r.onsuccess = () => t(r.result), r.onerror = () => {
|
|
258
285
|
var e;
|
|
259
286
|
return n((e = r.error) == null ? /* @__PURE__ */ Error("IndexedDB open failed") : e);
|
|
260
287
|
};
|
|
261
288
|
});
|
|
262
289
|
}
|
|
263
|
-
function
|
|
290
|
+
function k(e, t, n) {
|
|
264
291
|
return new Promise((r, i) => {
|
|
265
|
-
let a = n(e.transaction(
|
|
292
|
+
let a = n(e.transaction(E, t).objectStore(E));
|
|
266
293
|
a.onsuccess = () => r(a.result), a.onerror = () => {
|
|
267
294
|
var e;
|
|
268
295
|
return i((e = a.error) == null ? /* @__PURE__ */ Error("IndexedDB request failed") : e);
|
|
269
296
|
};
|
|
270
297
|
});
|
|
271
298
|
}
|
|
272
|
-
function
|
|
299
|
+
function A(e = {}) {
|
|
273
300
|
var t;
|
|
274
|
-
let n = (t = e.dbName) == null ?
|
|
301
|
+
let n = (t = e.dbName) == null ? T : t;
|
|
275
302
|
return { async uploadByFile(e, t) {
|
|
276
|
-
let r = crypto.randomUUID(), i = await
|
|
303
|
+
let r = crypto.randomUUID(), i = await O(n);
|
|
277
304
|
try {
|
|
278
|
-
await
|
|
305
|
+
await k(i, "readwrite", (n) => n.put({
|
|
279
306
|
blob: e,
|
|
280
307
|
name: e.name,
|
|
281
|
-
type: e.type
|
|
308
|
+
type: e.type,
|
|
309
|
+
kind: t.kind
|
|
282
310
|
}, r));
|
|
283
311
|
} finally {
|
|
284
312
|
i.close();
|
|
285
313
|
}
|
|
286
314
|
return {
|
|
287
|
-
url: `${
|
|
315
|
+
url: `${D}${r}`,
|
|
288
316
|
fileName: e.name
|
|
289
317
|
};
|
|
290
318
|
} };
|
|
291
319
|
}
|
|
292
|
-
async function
|
|
320
|
+
async function j(e, t = {}) {
|
|
293
321
|
var n;
|
|
294
|
-
if (!e.startsWith(
|
|
295
|
-
let r = await
|
|
296
|
-
return r ?
|
|
322
|
+
if (!e.startsWith(D)) return e;
|
|
323
|
+
let r = await M(await O((n = t.dbName) == null ? T : n), e.slice(11));
|
|
324
|
+
return r === void 0 ? null : r.kind === "image" ? w(r.blob) : S(r.blob);
|
|
297
325
|
}
|
|
298
|
-
function
|
|
299
|
-
return
|
|
326
|
+
function M(e, t) {
|
|
327
|
+
return k(e, "readonly", (e) => e.get(t)).finally(() => e.close());
|
|
300
328
|
}
|
|
301
|
-
|
|
302
|
-
export { _ as cloudinaryStorage, f as fetchStorage, T as indexedDBStorage, h as presignedStorage, E as resolveBlokObjectUrl, p as supabaseStorage };
|
|
329
|
+
export { _ as cloudinaryStorage, f as fetchStorage, A as indexedDBStorage, h as presignedStorage, j as resolveBlokObjectUrl, p as supabaseStorage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloklabs/presets",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Storage presets for Blok — ready-made uploaders for Supabase, S3-compatible storage, Cloudinary, and IndexedDB.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "JackUait",
|
|
@@ -49,6 +49,6 @@
|
|
|
49
49
|
"test": "yarn run -T vitest run"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"fake-indexeddb": "^6.2.
|
|
52
|
+
"fake-indexeddb": "^6.2.6"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -191,5 +191,10 @@ export function indexedDBStorage(options?: IndexedDBStorageOptions): BlokUploade
|
|
|
191
191
|
* anything else — is returned unchanged; validating that a URL is safe to
|
|
192
192
|
* render remains the host's job. Resolves `null` when the reference is not
|
|
193
193
|
* (or no longer) stored.
|
|
194
|
+
*
|
|
195
|
+
* The `blob:` URL gets a safe type, like Blok's own blob URLs. HTML, XML and
|
|
196
|
+
* other types that could run as a page become `text/plain`. The bytes stay the
|
|
197
|
+
* same. SVG keeps its type only when it was stored as an image. Read the real
|
|
198
|
+
* type from the block's `mimeType`.
|
|
194
199
|
*/
|
|
195
200
|
export function resolveBlokObjectUrl(url: string, options?: IndexedDBStorageOptions): Promise<string | null>;
|