@yoopta/file 6.0.0-beta.1 → 6.0.0-beta.11
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/commands/index.d.ts +3 -3
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/hooks/use-upload.d.ts +4 -0
- package/dist/hooks/use-upload.d.ts.map +1 -0
- package/dist/hooks/use-xhr.d.ts +11 -0
- package/dist/hooks/use-xhr.d.ts.map +1 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/plugin/{index.d.ts → file-plugin.d.ts} +1 -1
- package/dist/plugin/file-plugin.d.ts.map +1 -0
- package/dist/types.d.ts +90 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/file-type.d.ts +23 -0
- package/dist/utils/file-type.d.ts.map +1 -0
- package/dist/utils/format-size.d.ts +9 -0
- package/dist/utils/format-size.d.ts.map +1 -0
- package/package.json +3 -3
- package/dist/plugin/index.d.ts.map +0 -1
package/dist/commands/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { YooEditor, YooptaPathIndex } from '@yoopta/editor';
|
|
2
2
|
import type { FileElement, FileElementProps } from '../types';
|
|
3
3
|
type FileElementOptions = {
|
|
4
|
-
props?:
|
|
4
|
+
props?: Partial<FileElementProps>;
|
|
5
5
|
};
|
|
6
6
|
type InsertFileOptions = FileElementOptions & {
|
|
7
7
|
at?: YooptaPathIndex;
|
|
8
8
|
focus?: boolean;
|
|
9
9
|
};
|
|
10
|
-
export type
|
|
10
|
+
export type FileCommandsType = {
|
|
11
11
|
buildFileElements: (editor: YooEditor, options?: Partial<FileElementOptions>) => FileElement;
|
|
12
12
|
insertFile: (editor: YooEditor, options?: Partial<InsertFileOptions>) => void;
|
|
13
13
|
deleteFile: (editor: YooEditor, blockId: string) => void;
|
|
14
14
|
updateFile: (editor: YooEditor, blockId: string, props: Partial<FileElementProps>) => void;
|
|
15
15
|
};
|
|
16
|
-
export declare const FileCommands:
|
|
16
|
+
export declare const FileCommands: FileCommandsType;
|
|
17
17
|
export {};
|
|
18
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjE,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE9D,KAAK,kBAAkB,GAAG;IACxB,KAAK,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjE,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE9D,KAAK,kBAAkB,GAAG;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACnC,CAAC;AAEF,KAAK,iBAAiB,GAAG,kBAAkB,GAAG;IAC5C,EAAE,CAAC,EAAE,eAAe,CAAC;IACrB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iBAAiB,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,KAAK,WAAW,CAAC;IAC7F,UAAU,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;IAC9E,UAAU,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACzD,UAAU,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;CAC5F,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,gBA6B1B,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FileDeleteOptions, FileUploadOptions, UseFileDeleteReturn, UseFileUploadReturn } from '../types';
|
|
2
|
+
export declare const useFileDelete: (options: FileDeleteOptions | undefined) => UseFileDeleteReturn;
|
|
3
|
+
export declare const useFileUpload: (options: FileUploadOptions | undefined) => UseFileUploadReturn;
|
|
4
|
+
//# sourceMappingURL=use-upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-upload.d.ts","sourceRoot":"","sources":["../../src/hooks/use-upload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,iBAAiB,EAKjB,iBAAiB,EAKjB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,UAAU,CAAC;AA2FlB,eAAO,MAAM,aAAa,YAAa,iBAAiB,GAAG,SAAS,KAAG,mBAgHtE,CAAC;AAEF,eAAO,MAAM,aAAa,YAAa,iBAAiB,GAAG,SAAS,KAAG,mBAmHtE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FileUploadProgress, FileUploadError, FileUploadResult, XHRRequestOptions } from '../types';
|
|
2
|
+
export declare const useXHRRequest: ({ onError, onSuccess, onProgress, accept, maxSize, method, endpoint, headers, }: XHRRequestOptions) => {
|
|
3
|
+
xhrFetch: (body: XMLHttpRequestBodyInit) => Promise<FileUploadResult>;
|
|
4
|
+
cancel: () => void;
|
|
5
|
+
reset: () => void;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
progress: FileUploadProgress | null;
|
|
8
|
+
error: FileUploadError | null;
|
|
9
|
+
result: FileUploadResult | null;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=use-xhr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-xhr.d.ts","sourceRoot":"","sources":["../../src/hooks/use-xhr.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAEhB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAsClB,eAAO,MAAM,aAAa,oFASvB,iBAAiB;qBAUM,sBAAsB,KAAG,QAAQ,gBAAgB,CAAC;;;;;;;CA2K3E,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { File } from './plugin';
|
|
2
|
-
|
|
1
|
+
import { File } from './plugin/file-plugin';
|
|
2
|
+
export type { FileElement, FileElementMap, FileElementProps, FilePluginElements, FilePluginOptions, FileUploadResponse, FileUploadFn, FileDeleteFn, FileUploadEndpointOptions, FileDeleteEndpointOptions, FileUploadOptions, FileDeleteOptions, FileUploadProgress, FileUploadError, FileUploadResult, FileUploadState, UseFileUploadReturn, UseFileDeleteReturn, FileType, FileTypeConfig, } from './types';
|
|
3
3
|
export { FileCommands } from './commands';
|
|
4
|
+
export type { FileCommandsType } from './commands';
|
|
5
|
+
export { useFileUpload, useFileDelete } from './hooks/use-upload';
|
|
6
|
+
export { getFileType, getFileTypeConfig, getFileTypeLabel, getFileExtension, isFileType, FILE_TYPE_CONFIGS, } from './utils/file-type';
|
|
7
|
+
export { formatFileSize, parseFileSize } from './utils/format-size';
|
|
4
8
|
export default File;
|
|
5
|
-
export { FileElement, FileElementProps, FileUploadResponse };
|
|
6
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAG5C,YAAY,EACV,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,yBAAyB,EACzB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,QAAQ,EACR,cAAc,GACf,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGlE,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpE,eAAe,IAAI,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import{generateId as t,buildBlockData as r,Blocks as n,Elements as a,YooptaPlugin as o}from"@yoopta/editor";const s={buildFileElements:(e,r={})=>{const n=Object.assign(Object.assign({},r.props),{nodeType:"void"});return{id:t(),type:"file",children:[{text:""}],props:n}},insertFile:(e,t={})=>{const{at:a,focus:o,props:p}=t,l=s.buildFileElements(e,{props:p}),i=r({value:[l],type:"File"});n.insertBlock(e,i.type,{focus:o,at:a,blockData:i})},deleteFile:(e,t)=>{n.deleteBlock(e,{blockId:t})},updateFile:(e,t,r)=>{a.updateElement(e,{blockId:t,type:"file",props:r})}},p={left:"flex-start",center:"center",right:"flex-end"},l=new o({type:"File",elements:e("file",{render:t=>e("div",Object.assign({},t.attributes,{children:e("a",Object.assign({href:t.element.props.src,download:t.element.props.name,target:"_blank",rel:"noopener noreferrer"},{children:t.element.props.name}))})),nodeType:"void",props:{size:0,name:null,src:null,format:null}}),commands:s,options:{display:{title:"File",description:"For files and more"},accept:""},parsers:{html:{serialize:(e,t,r)=>{const{align:n="left",depth:a=0}=r||{};return`<div style="margin-left: ${20*a}px; display: flex; width: 100%; justify-content: ${p[n]||"left"}"><a data-meta-align="${n}" data-meta-depth="${a}" href="${e.props.src}" data-size="${e.props.size}" download="${e.props.name}" target="_blank" rel="noopener noreferrer">${e.props.format?`${e.props.name}.${e.props.format}`:`${e.props.name}`}</a></div>`},deserialize:{nodeNames:["A"],parse:e=>{if("A"===e.nodeName){const r=!!e.getAttribute("download"),n=e.getAttribute("href");if(!r)return;if(!n)return;const a=new URL(n),o=e.textContent||"",s=o.split(".").pop(),p=a.href,l=Number(e.dataset.size||0);return{id:t(),type:"file",children:[{text:""}],props:{name:o,format:s,src:p,size:l}}}}}},markdown:{serialize:e=>`[${e.props.name}](${e.props.src})`},email:{serialize:(e,t,r)=>{const{align:n="left",depth:a=0}=r||{};return`\n <table style="width:100%;">\n <tbody style="width:100%;">\n <tr>\n <td>\n <div style="margin-left: ${20*a}px; display: flex; width: 100%; justify-content: ${p[n]||"left"}"><a data-meta-align="${n}" data-meta-depth="${a}" href="${e.props.src}" data-size="${e.props.size}" download="${e.props.name}" target="_blank" rel="noopener noreferrer">${e.props.format?`${e.props.name}.${e.props.format}`:`${e.props.name}`}</a></div>\n </td>\n </tr>\n </tbody>\n </table> \n `}}}});export{s as FileCommands,l as default};
|
|
1
|
+
import{jsx as e,jsxs as n}from"react/jsx-runtime";import{generateId as t,buildBlockData as o,Blocks as i,Elements as r,YooptaPlugin as s}from"@yoopta/editor";import{useState as l,useRef as a,useCallback as p}from"react";const d={buildFileElements:(e,n={})=>{var o,i,r,s,l,a,p,d,c,u;const m={id:null!==(i=null===(o=n.props)||void 0===o?void 0:o.id)&&void 0!==i?i:null,src:null!==(s=null===(r=n.props)||void 0===r?void 0:r.src)&&void 0!==s?s:null,name:null!==(a=null===(l=n.props)||void 0===l?void 0:l.name)&&void 0!==a?a:null,size:null!==(d=null===(p=n.props)||void 0===p?void 0:p.size)&&void 0!==d?d:null,format:null!==(u=null===(c=n.props)||void 0===c?void 0:c.format)&&void 0!==u?u:null};return{id:t(),type:"file",children:[{text:""}],props:m}},insertFile:(e,n={})=>{const{at:t,focus:r,props:s}=n,l=d.buildFileElements(e,{props:s}),a=o({value:[l],type:"File"});i.insertBlock(e,a.type,{focus:r,at:t,blockData:a})},deleteFile:(e,n)=>{i.deleteBlock(e,{blockId:n})},updateFile:(e,n,t)=>{r.updateElement(e,{blockId:n,type:"file",props:t})}},c=e=>{if(null==e||0===e)return"0 B";const n=["B","KB","MB","GB","TB"],t=Math.floor(Math.log(Math.abs(e))/Math.log(1024));if(0===t)return`${e} ${n[0]}`;const o=e/Math.pow(1024,t),i=o<10?2:o<100?1:0;return`${o.toFixed(i)} ${n[t]}`},u=e=>{var n,t;const o=e.match(/^([\d.]+)\s*(B|KB|MB|GB|TB)?$/i);if(!o)return null;const i=parseFloat(o[1]),r=(null!==(n=o[2])&&void 0!==n?n:"B").toUpperCase();return Math.round(i*(null!==(t={B:1,KB:1024,MB:1048576,GB:1073741824,TB:1099511627776}[r])&&void 0!==t?t:1))},m={left:"flex-start",center:"center",right:"flex-end"},f=new s({type:"File",elements:e("file",{render:e=>{const{name:t,src:o,size:i,format:r}=e.element.props,s=r?`${t}.${r}`:t;return n("div",Object.assign({},e.attributes,{children:[n("a",Object.assign({href:null!=o?o:void 0,download:null!=t?t:void 0,target:"_blank",rel:"noopener noreferrer"},{children:[null!=s?s:"Untitled file",i?` (${c(i)})`:""]})),e.children]}))},nodeType:"void",props:{id:null,src:null,name:null,size:null,format:null}}),commands:d,options:{display:{title:"File",description:"Upload and attach files"},accept:""},parsers:{html:{serialize:(e,n,t)=>{var o,i,r,s;const{align:l="left",depth:a=0}=null!=t?t:{},p=null!==(o=m[l])&&void 0!==o?o:"left",d=e.props.format?`${e.props.name}.${e.props.format}`:e.props.name,u=e.props.size?` (${c(e.props.size)})`:"";return`<div style="margin-left: ${20*a}px; display: flex; width: 100%; justify-content: ${p}">\n <a \n data-yoopta-file\n data-meta-align="${l}" \n data-meta-depth="${a}" \n href="${e.props.src}" \n data-size="${null!==(i=e.props.size)&&void 0!==i?i:0}" \n data-format="${null!==(r=e.props.format)&&void 0!==r?r:""}"\n data-id="${null!==(s=e.props.id)&&void 0!==s?s:""}"\n download="${e.props.name}" \n target="_blank" \n rel="noopener noreferrer"\n >${d}${u}</a>\n </div>`},deserialize:{nodeNames:["A"],parse:e=>{var n,o,i;if("A"===e.nodeName){const r=!!e.getAttribute("download"),s=!!e.getAttribute("data-yoopta-file"),l=e.getAttribute("href");if(!r&&!s)return;if(!l)return;try{const r=new URL(l,window.location.origin),s=null!==(n=e.textContent)&&void 0!==n?n:"";let a=(null!==(o=e.getAttribute("download"))&&void 0!==o?o:"")||s.split(" (")[0]||"",p=null;const d=a.lastIndexOf(".");d>0&&(p=a.slice(d+1),a=a.slice(0,d));const c=e.getAttribute("data-size"),u=c?Number(c):null,m=null!==(i=e.getAttribute("data-id"))&&void 0!==i?i:null,f=e.getAttribute("data-format");return f&&(p=f),{id:t(),type:"file",children:[{text:""}],props:{id:m,name:a||null,format:p,src:r.href,size:u}}}catch(e){}}}}},markdown:{serialize:e=>`[${e.props.format?`${e.props.name}.${e.props.format}`:e.props.name}](${e.props.src})\n`},email:{serialize:(e,n,t)=>{var o;const{align:i="left",depth:r=0}=null!=t?t:{},s=null!==(o=m[i])&&void 0!==o?o:"left",l=e.props.format?`${e.props.name}.${e.props.format}`:e.props.name,a=e.props.size?` (${c(e.props.size)})`:"";return`\n <table style="width:100%;">\n <tbody style="width:100%;">\n <tr>\n <td style="margin-left: ${20*r}px; display: flex; width: 100%; justify-content: ${s}; padding: 8px 0;">\n <a \n href="${e.props.src}" \n download="${e.props.name}" \n target="_blank" \n rel="noopener noreferrer"\n style="\n display: inline-flex;\n align-items: center;\n gap: 8px;\n padding: 12px 16px;\n background-color: #f5f5f5;\n border-radius: 8px;\n text-decoration: none;\n color: #333;\n font-size: 14px;\n "\n >\n <span style="font-size: 20px;">📎</span>\n <span>${l}${a}</span>\n </a>\n </td>\n </tr>\n </tbody>\n </table> \n `}}}});function g(e,n,t,o){return new(t||(t=Promise))(function(i,r){function s(e){try{a(o.next(e))}catch(e){r(e)}}function l(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(s,l)}a((o=o.apply(e,n||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const v=({onError:e,onSuccess:n,onProgress:t,accept:o,maxSize:i,method:r="POST",endpoint:s,headers:d})=>{const[c,u]=l({loading:!1,progress:null,error:null,result:null}),m=a(null),f=p(()=>{m.current&&(m.current.abort(),m.current=null)},[]),g=p(()=>{u({loading:!1,progress:null,error:null,result:null})},[]);return Object.assign(Object.assign({},c),{xhrFetch:l=>new Promise((a,p)=>{if(l instanceof File){const n=((e,n,t)=>{if(n&&!n.split(",").map(e=>e.trim()).some(n=>{if(n.startsWith("."))return e.name.toLowerCase().endsWith(n.toLowerCase());if(n.endsWith("/*")){const t=n.replace("/*","");return e.type.startsWith(t)}return e.type===n}))return{message:`Invalid file type. Allowed types: ${n}`,code:"INVALID_TYPE"};if(t&&e.size>t)return{message:`File size exceeds ${(t/1024/1024).toFixed(2)}MB`,code:"FILE_TOO_LARGE"};return null})(l,o,i);if(n)return u(e=>Object.assign(Object.assign({},e),{error:n})),null==e||e(n),void p(n)}u({loading:!0,progress:{loaded:0,total:l instanceof File?l.size:0,percentage:0},error:null,result:null});const c=new XMLHttpRequest;m.current=c,c.upload.addEventListener("progress",e=>{if(e.lengthComputable){const n={loaded:e.loaded,total:e.total,percentage:Math.round(e.loaded/e.total*100)};u(e=>Object.assign(Object.assign({},e),{progress:n})),null==t||t(n)}}),c.addEventListener("load",()=>{if(c.status>=200&&c.status<300)try{const e=JSON.parse(c.responseText);u(n=>Object.assign(Object.assign({},n),{loading:!1,result:e})),null==n||n(e),a(e)}catch(n){const t={message:"Failed to parse server response",code:"PARSE_ERROR",status:c.status};u(e=>Object.assign(Object.assign({},e),{loading:!1,error:t})),null==e||e(t),p(t)}else{const n={message:`Upload failed with status ${c.status}`,code:"HTTP_ERROR",status:c.status};u(e=>Object.assign(Object.assign({},e),{loading:!1,error:n})),null==e||e(n),p(n)}}),c.addEventListener("error",()=>{const n={message:"Network error occurred",code:"NETWORK_ERROR"};u(e=>Object.assign(Object.assign({},e),{loading:!1,error:n})),null==e||e(n),p(n)}),c.addEventListener("abort",()=>{const e={message:"Upload cancelled",code:"ABORT"};u(n=>Object.assign(Object.assign({},n),{loading:!1,error:e})),p(e)}),c.addEventListener("timeout",()=>{const n={message:"Upload timeout",code:"TIMEOUT"};u(e=>Object.assign(Object.assign({},e),{loading:!1,error:n})),null==e||e(n),p(n)}),c.open(r,s),d&&Object.entries(d).forEach(([e,n])=>{c.setRequestHeader(e,n)}),c.timeout=3e5,c.send(l)}),cancel:f,reset:g})},b="https://docs.yoopta.dev/plugins/file",x=e=>{var n,t,o;const i=(e=>{if(null==e)return!1;if("function"!=typeof e&&"object"!=typeof e)throw new Error(`[Yoopta File] Invalid delete options. Expected a function or endpoint configuration object.\n\nSee documentation: ${b}`);if("object"==typeof e&&!e.endpoint)throw new Error(`[Yoopta File] Missing 'endpoint' in delete options. When using endpoint-based delete, you must provide an 'endpoint' URL.\n\nExample:\nFile.extend({\n options: {\n delete: {\n endpoint: '/api/delete-file',\n },\n },\n})\n\nSee documentation: ${b}`);return!0})(e),r=i?e:null,s=!!r&&(e=>"function"==typeof e)(r),[a,d]=l({loading:!1,progress:null,error:null,result:null}),c=!r||s?{endpoint:""}:r,u=v({endpoint:c.endpoint,method:null!==(n=c.method)&&void 0!==n?n:"DELETE",headers:null!==(t=c.headers)&&void 0!==t?t:{},fieldName:null!==(o=c.fieldName)&&void 0!==o?o:"file",onSuccess:c.onSuccess,onError:c.onError,onProgress:c.onProgress}),m=p(e=>g(void 0,void 0,void 0,function*(){var n,t,o,i,l,a,p;if(!r){const r=null!==(t=null===(n=e.props)||void 0===n?void 0:n.src)&&void 0!==t?t:"";return{id:null!==(i=null===(o=e.props)||void 0===o?void 0:o.id)&&void 0!==i?i:"",url:r}}if(!s)throw new Error("Custom delete called but options is not a function");const c=null===(l=e.props)||void 0===l?void 0:l.src;if(!c)throw new Error("File src is required");d(e=>Object.assign(Object.assign({},e),{loading:!0,error:null}));try{yield r(e);const n={id:null!==(p=null===(a=e.props)||void 0===a?void 0:a.id)&&void 0!==p?p:"",url:c};return d(e=>Object.assign(Object.assign({},e),{loading:!1,result:n})),n}catch(e){const n={message:e instanceof Error?e.message:"Delete failed",code:"CUSTOM_DELETE_ERROR"};throw d(e=>Object.assign(Object.assign({},e),{loading:!1,error:n})),n}}),[r,s]),f=p(()=>{d({loading:!1,progress:null,error:null,result:null})},[]),x=p(e=>{var n;const t=null===(n=e.props)||void 0===n?void 0:n.id;if(!t)throw new Error("File id is required");return u.xhrFetch(JSON.stringify({fileId:t}))},[u]);return i?s?Object.assign(Object.assign({},a),{deleteFile:m,cancel:()=>{},reset:f}):{loading:u.loading,progress:u.progress,error:u.error,result:u.result,deleteFile:x,cancel:u.cancel,reset:u.reset}:Object.assign(Object.assign({},a),{deleteFile:m,cancel:()=>{},reset:f})},h=e=>{var n,t,o;(e=>{if(null==e)throw new Error(`[Yoopta File] Upload options are not configured. Please provide 'upload' option when extending the File plugin.\n\nExample:\nFile.extend({\n options: {\n upload: async (file) => {\n // Upload file to your storage and return file props\n return { src: '...', name: file.name, size: file.size };\n },\n },\n})\n\nSee documentation: ${b}`);if("function"!=typeof e&&"object"!=typeof e)throw new Error(`[Yoopta File] Invalid upload options. Expected a function or endpoint configuration object.\n\nSee documentation: ${b}`);if("object"==typeof e&&!e.endpoint)throw new Error(`[Yoopta File] Missing 'endpoint' in upload options. When using endpoint-based upload, you must provide an 'endpoint' URL.\n\nExample:\nFile.extend({\n options: {\n upload: {\n endpoint: '/api/upload-file',\n },\n },\n})\n\nSee documentation: ${b}`)})(e);const i=e,r=(e=>"function"==typeof e)(i),[s,a]=l({loading:!1,progress:null,error:null,result:null}),d=r?{endpoint:""}:i,c=v({endpoint:d.endpoint,method:null!==(n=d.method)&&void 0!==n?n:"POST",headers:null!==(t=d.headers)&&void 0!==t?t:{},fieldName:null!==(o=d.fieldName)&&void 0!==o?o:"file",maxSize:d.maxSize,accept:d.accept,onSuccess:d.onSuccess,onError:d.onError,onProgress:d.onProgress}),u=p(e=>g(void 0,void 0,void 0,function*(){var n,t,o,s;if(!r)throw new Error("Custom upload called but options is not a function");a(n=>Object.assign(Object.assign({},n),{loading:!0,progress:{loaded:0,total:e.size,percentage:0},error:null}));try{const r=e=>{a(n=>Object.assign(Object.assign({},n),{progress:e}))},l=yield i(e,r),p={id:null!==(n=l.id)&&void 0!==n?n:"",url:null!==(t=l.src)&&void 0!==t?t:"",name:null!==(o=l.name)&&void 0!==o?o:e.name,size:null!==(s=l.size)&&void 0!==s?s:e.size,format:l.format};return a(n=>Object.assign(Object.assign({},n),{loading:!1,progress:{loaded:e.size,total:e.size,percentage:100},result:p})),p}catch(e){const n={message:e instanceof Error?e.message:"Upload failed",code:"CUSTOM_UPLOAD_ERROR"};throw a(e=>Object.assign(Object.assign({},e),{loading:!1,error:n})),n}}),[i,r]),m=p(()=>{a({loading:!1,progress:null,error:null,result:null})},[]),f=p(e=>{var n;const t=new FormData;return t.append(null!==(n=d.fieldName)&&void 0!==n?n:"yoopta-file",e),c.xhrFetch(t)},[d.fieldName,c]);return r?Object.assign(Object.assign({},s),{upload:u,cancel:()=>{},reset:m}):{loading:c.loading,progress:c.progress,error:c.error,result:c.result,upload:f,cancel:c.cancel,reset:c.reset}},y=[{type:"pdf",extensions:[".pdf"],mimeTypes:["application/pdf"],label:"PDF"},{type:"document",extensions:[".doc",".docx",".odt",".rtf",".pages"],mimeTypes:["application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.oasis.opendocument.text","application/rtf","application/x-iwork-pages-sffpages"],label:"Document"},{type:"spreadsheet",extensions:[".xls",".xlsx",".csv",".ods",".numbers"],mimeTypes:["application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","text/csv","application/vnd.oasis.opendocument.spreadsheet","application/x-iwork-numbers-sffnumbers"],label:"Spreadsheet"},{type:"presentation",extensions:[".ppt",".pptx",".odp",".key"],mimeTypes:["application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.oasis.opendocument.presentation","application/x-iwork-keynote-sffkey"],label:"Presentation"},{type:"image",extensions:[".jpg",".jpeg",".png",".gif",".webp",".svg",".bmp",".ico",".tiff"],mimeTypes:["image/jpeg","image/png","image/gif","image/webp","image/svg+xml","image/bmp","image/x-icon","image/tiff"],label:"Image"},{type:"video",extensions:[".mp4",".webm",".mov",".avi",".mkv",".wmv",".flv"],mimeTypes:["video/mp4","video/webm","video/quicktime","video/x-msvideo","video/x-matroska","video/x-ms-wmv","video/x-flv"],label:"Video"},{type:"audio",extensions:[".mp3",".wav",".ogg",".flac",".aac",".m4a",".wma"],mimeTypes:["audio/mpeg","audio/wav","audio/ogg","audio/flac","audio/aac","audio/mp4","audio/x-ms-wma"],label:"Audio"},{type:"archive",extensions:[".zip",".rar",".7z",".tar",".gz",".bz2"],mimeTypes:["application/zip","application/x-rar-compressed","application/x-7z-compressed","application/x-tar","application/gzip","application/x-bzip2"],label:"Archive"},{type:"code",extensions:[".js",".ts",".jsx",".tsx",".html",".css",".json",".xml",".py",".java",".c",".cpp",".h",".rb",".php",".go",".rs",".swift",".kt"],mimeTypes:["text/javascript","application/javascript","text/typescript","text/html","text/css","application/json","application/xml","text/x-python","text/x-java-source","text/x-c","text/x-c++"],label:"Code"},{type:"text",extensions:[".txt",".md",".log",".ini",".cfg"],mimeTypes:["text/plain","text/markdown"],label:"Text"}],w=(e,n)=>{var t;if(!e&&!n)return"unknown";const o=e?`.${null===(t=e.split(".").pop())||void 0===t?void 0:t.toLowerCase()}`:null;for(const e of y){if(o&&e.extensions.includes(o))return e.type;if(n&&e.mimeTypes.includes(n))return e.type}return"unknown"},j=e=>y.find(n=>n.type===e),O=(e,n)=>{var t;const o=w(e,n),i=j(o);return null!==(t=null==i?void 0:i.label)&&void 0!==t?t:"File"},E=e=>{var n,t;if(!e)return null;const o=e.split(".");return o.length<2?null:null!==(t=null===(n=o.pop())||void 0===n?void 0:n.toLowerCase())&&void 0!==t?t:null},$=(e,n,t)=>w(n,t)===e;export{y as FILE_TYPE_CONFIGS,d as FileCommands,f as default,c as formatFileSize,E as getFileExtension,w as getFileType,j as getFileTypeConfig,O as getFileTypeLabel,$ as isFileType,u as parseFileSize,x as useFileDelete,h as useFileUpload};
|
|
@@ -2,4 +2,4 @@ import { YooptaPlugin } from '@yoopta/editor';
|
|
|
2
2
|
import type { FileElementMap, FilePluginOptions } from '../types';
|
|
3
3
|
declare const File: YooptaPlugin<FileElementMap, FilePluginOptions>;
|
|
4
4
|
export { File };
|
|
5
|
-
//# sourceMappingURL=
|
|
5
|
+
//# sourceMappingURL=file-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-plugin.d.ts","sourceRoot":"","sources":["../../src/plugin/file-plugin.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAc,MAAM,gBAAgB,CAAC;AAG1D,OAAO,KAAK,EAAE,cAAc,EAAoB,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAiBpF,QAAA,MAAM,IAAI,iDAiKR,CAAC;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,21 +1,104 @@
|
|
|
1
1
|
import { type SlateElement } from '@yoopta/editor';
|
|
2
2
|
export type FileElementProps = {
|
|
3
|
-
|
|
4
|
-
name: string | null;
|
|
3
|
+
id?: string | null;
|
|
5
4
|
src: string | null;
|
|
5
|
+
name: string | null;
|
|
6
|
+
size: number | null;
|
|
6
7
|
format?: string | null;
|
|
7
8
|
};
|
|
8
9
|
export type FilePluginElements = 'file';
|
|
9
10
|
export type FileElement = SlateElement<'file', FileElementProps>;
|
|
10
|
-
export type
|
|
11
|
+
export type FileElementMap = {
|
|
12
|
+
file: FileElement;
|
|
13
|
+
};
|
|
14
|
+
export type FileUploadResponse = {
|
|
15
|
+
id?: string;
|
|
11
16
|
src: string;
|
|
17
|
+
name?: string;
|
|
18
|
+
size?: number;
|
|
19
|
+
format?: string;
|
|
20
|
+
};
|
|
21
|
+
export type FileUploadProgress = {
|
|
22
|
+
loaded: number;
|
|
23
|
+
total: number;
|
|
24
|
+
percentage: number;
|
|
25
|
+
};
|
|
26
|
+
export type FileUploadError = {
|
|
27
|
+
message: string;
|
|
28
|
+
code?: string;
|
|
29
|
+
status?: number;
|
|
30
|
+
};
|
|
31
|
+
export type FileUploadResult = {
|
|
32
|
+
id: string;
|
|
33
|
+
url: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
size?: number;
|
|
36
|
+
format?: string;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
};
|
|
39
|
+
export type FileUploadState = {
|
|
40
|
+
loading: boolean;
|
|
41
|
+
progress: FileUploadProgress | null;
|
|
42
|
+
error: FileUploadError | null;
|
|
43
|
+
result: FileUploadResult | null;
|
|
44
|
+
};
|
|
45
|
+
export type FileUploadFn = (file: File, onProgress?: (progress: FileUploadProgress) => void) => Promise<FileUploadResponse>;
|
|
46
|
+
export type FileDeleteFn = (element: FileElement) => Promise<unknown>;
|
|
47
|
+
export type FileUploadEndpointOptions = {
|
|
48
|
+
endpoint: string;
|
|
49
|
+
method?: 'POST' | 'PUT' | 'PATCH';
|
|
50
|
+
headers?: Record<string, string>;
|
|
51
|
+
fieldName?: string;
|
|
52
|
+
maxSize?: number;
|
|
53
|
+
accept?: string;
|
|
54
|
+
onProgress?: (progress: FileUploadProgress) => void;
|
|
55
|
+
onSuccess?: (result: FileUploadResult) => void;
|
|
56
|
+
onError?: (error: FileUploadError) => void;
|
|
57
|
+
};
|
|
58
|
+
export type FileDeleteEndpointOptions = {
|
|
59
|
+
endpoint: string;
|
|
60
|
+
method?: 'DELETE' | 'PATCH';
|
|
61
|
+
headers?: Record<string, string>;
|
|
62
|
+
fieldName?: string;
|
|
63
|
+
onProgress?: (progress: FileUploadProgress) => void;
|
|
64
|
+
onSuccess?: (result: FileUploadResult) => void;
|
|
65
|
+
onError?: (error: FileUploadError) => void;
|
|
66
|
+
};
|
|
67
|
+
export type FileUploadOptions = FileUploadEndpointOptions | FileUploadFn;
|
|
68
|
+
export type FileDeleteOptions = FileDeleteEndpointOptions | FileDeleteFn;
|
|
69
|
+
export type UseFileUploadReturn = {
|
|
70
|
+
upload: (file: File) => Promise<FileUploadResult>;
|
|
71
|
+
cancel: () => void;
|
|
72
|
+
reset: () => void;
|
|
73
|
+
} & FileUploadState;
|
|
74
|
+
export type UseFileDeleteReturn = {
|
|
75
|
+
deleteFile: (element: FileElement) => Promise<unknown>;
|
|
76
|
+
cancel: () => void;
|
|
77
|
+
reset: () => void;
|
|
78
|
+
} & FileUploadState;
|
|
79
|
+
export type FileType = 'pdf' | 'document' | 'spreadsheet' | 'presentation' | 'image' | 'video' | 'audio' | 'archive' | 'code' | 'text' | 'unknown';
|
|
80
|
+
export type FileTypeConfig = {
|
|
81
|
+
type: FileType;
|
|
82
|
+
extensions: string[];
|
|
83
|
+
mimeTypes: string[];
|
|
84
|
+
label: string;
|
|
12
85
|
};
|
|
13
86
|
export type FilePluginOptions = {
|
|
14
|
-
|
|
15
|
-
|
|
87
|
+
upload?: FileUploadOptions;
|
|
88
|
+
delete?: FileDeleteOptions;
|
|
89
|
+
onError?: (error: FileUploadError) => void;
|
|
16
90
|
accept?: string;
|
|
91
|
+
maxFileSize?: number;
|
|
17
92
|
};
|
|
18
|
-
export type
|
|
19
|
-
|
|
93
|
+
export type XHRRequestOptions = {
|
|
94
|
+
endpoint: string;
|
|
95
|
+
method?: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
96
|
+
headers?: Record<string, string>;
|
|
97
|
+
fieldName?: string;
|
|
98
|
+
maxSize?: number;
|
|
99
|
+
accept?: string;
|
|
100
|
+
onProgress?: (progress: FileUploadProgress) => void;
|
|
101
|
+
onSuccess?: (result: FileUploadResult) => void;
|
|
102
|
+
onError?: (error: FileUploadError) => void;
|
|
20
103
|
};
|
|
21
104
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAMnD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC;AACxC,MAAM,MAAM,WAAW,GAAG,YAAY,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAEjE,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC;AAOF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,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AI,CAAC;CAC5C,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { FileType, FileTypeConfig } from '../types';
|
|
2
|
+
export declare const FILE_TYPE_CONFIGS: FileTypeConfig[];
|
|
3
|
+
/**
|
|
4
|
+
* Detect file type from filename or MIME type
|
|
5
|
+
*/
|
|
6
|
+
export declare const getFileType: (filename?: string | null, mimeType?: string | null) => FileType;
|
|
7
|
+
/**
|
|
8
|
+
* Get file type configuration
|
|
9
|
+
*/
|
|
10
|
+
export declare const getFileTypeConfig: (fileType: FileType) => FileTypeConfig | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Get file type label
|
|
13
|
+
*/
|
|
14
|
+
export declare const getFileTypeLabel: (filename?: string | null, mimeType?: string | null) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Get file extension from filename
|
|
17
|
+
*/
|
|
18
|
+
export declare const getFileExtension: (filename?: string | null) => string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Check if file is of a specific type
|
|
21
|
+
*/
|
|
22
|
+
export declare const isFileType: (fileType: FileType, filename?: string | null, mimeType?: string | null) => boolean;
|
|
23
|
+
//# sourceMappingURL=file-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-type.d.ts","sourceRoot":"","sources":["../../src/utils/file-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAGzD,eAAO,MAAM,iBAAiB,EAAE,cAAc,EA8I7C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,cAAe,MAAM,GAAG,IAAI,aAAa,MAAM,GAAG,IAAI,KAAG,QAiBhF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,aAAc,QAAQ,KAAG,cAAc,GAAG,SACV,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,gBAAgB,cAAe,MAAM,GAAG,IAAI,aAAa,MAAM,GAAG,IAAI,KAAG,MAIrF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,cAAe,MAAM,GAAG,IAAI,KAAG,MAAM,GAAG,IAKpE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,aACX,QAAQ,aACP,MAAM,GAAG,IAAI,aACb,MAAM,GAAG,IAAI,KACvB,OAAuD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format file size to human-readable string
|
|
3
|
+
*/
|
|
4
|
+
export declare const formatFileSize: (bytes: number | null | undefined) => string;
|
|
5
|
+
/**
|
|
6
|
+
* Parse file size string to bytes
|
|
7
|
+
*/
|
|
8
|
+
export declare const parseFileSize: (sizeString: string) => number | null;
|
|
9
|
+
//# sourceMappingURL=format-size.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-size.d.ts","sourceRoot":"","sources":["../../src/utils/format-size.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,cAAc,UAAW,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,MAajE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,eAAgB,MAAM,KAAG,MAAM,GAAG,IAgB3D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yoopta/file",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.11",
|
|
4
4
|
"description": "File plugin for Yoopta Editor",
|
|
5
5
|
"author": "Darginec05 <devopsbanda@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/Darginec05/Yoopta-Editor#readme",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dist/"
|
|
15
15
|
],
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@yoopta/editor": "
|
|
17
|
+
"@yoopta/editor": "6.0.0-beta.4",
|
|
18
18
|
"react": ">=18.2.0",
|
|
19
19
|
"react-dom": ">=18.2.0"
|
|
20
20
|
},
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"bugs": {
|
|
36
36
|
"url": "https://github.com/Darginec05/Yoopta-Editor/issues"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "328b04fa6481a487b434708338f56057792aafa4"
|
|
39
39
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAc,MAAM,gBAAgB,CAAC;AAG1D,OAAO,KAAK,EAAE,cAAc,EAAoB,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAepF,QAAA,MAAM,IAAI,iDA8GR,CAAC;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC"}
|