diff --git a/README.md b/README.md index ce9d470..519aa65 100644 --- a/README.md +++ b/README.md @@ -92,42 +92,55 @@ Vue.use(VueTransmit); ## Props: <vue-transmit> -| Property | Type | Default | -| --------------------- | --------------------- | --------------------------------------------------------------------------- | -| tag | String | "div" | -| uploadAreaClasses | Array, Object, String | null | -| uploadAreaAttrs | Object | {} | -| uploadAreaListeners | Object | {} | -| url | String | undefined | -| method | String | "post" | -| withCredentials | Boolean | false | -| timeout | Number | 0 | -| maxConcurrentUploads | Number | 2 | -| uploadMultiple | Boolean | false | -| maxFileSize | Number | 256 _(in MiB)_ | -| paramName | String | "file" | -| createImageThumbnails | Boolean | true | -| maxThumbnailFileSize | Number | 10 | -| thumbnailWidth | Number | 120 | -| thumbnailHeight | Number | 120 | -| fileSizeBase | Number | 1000 | -| maxFiles | Number | null | -| params | Object | default | -| headers | Object | default | -| responseType | String | "" | -| clickable | Boolean | true | -| ignoreHiddenFiles | Boolean | true | -| acceptedFileTypes | Array | default | -| autoProcessQueue | Boolean | true | -| autoQueue | Boolean | true | -| capture | String | null | -| renameFile | Function | identity | -| dictFileTooBig | String | "File is too big ({{ fileSize }}MiB). Max file size: {{ maxFileSize }}MiB." | -| dictInvalidFileType | String | "You can't upload files of this type." | -| dictResponseError | String | "Server responded with {{ statusCode }} code." | -| dictMaxFilesExceeded | String | "You can not upload any more files." | -| accept | Function | default | -| resize | Function | default | +[**View Source**](./src/components/VueTransmit.vue#L85-L272) + +| Property | Type | Default | +| ---------------------- | --------------------- | ------------------------------ | +| tag | String | `"div"` | +| uploadAreaClasses | Array, Object, String | `null` | +| uploadAreaAttrs | Object | `[Function: objFactory]` | +| uploadAreaListeners | Object | `[Function: objFactory]` | +| dragClass | String | `null` | +| maxConcurrentUploads | Number | `2` | +| uploadMultiple | Boolean | `false` | +| maxFileSize | Number | `256` | +| fileSizeBaseInBinary | Boolean | `false` | +| createImageThumbnails | Boolean | `true` | +| maxThumbnailFileSize | Number | `10` | +| thumbnailWidth | Number | `120` | +| thumbnailHeight | Number | `120` | +| maxFiles | Number | `null` | +| clickable | Boolean | `true` | +| ignoreHiddenFiles | Boolean | `true` | +| acceptedFileTypes | Array | `[Function: default]` | +| autoProcessQueue | Boolean | `true` | +| autoQueue | Boolean | `true` | +| capture | String | `null` | +| errMaxFileSizeExceeded | Function | `[Function: default]` | +| errInvalidFileType | Function | `[Function: default]` | +| errMaxFilesExceeded | Function | `[Function: default]` | +| accept | Function | `[Function: default]` | +| resize | Function | `[Function: resizeImg]` | +| adapterOptions | Object | `[Function: objFactory]` | +| uploadAdapter | Function | `[Function: XHRUploadAdapter]` | + +## Adapter Options: XHRUploadAdapter + +[**View Source**](./src/upload-adapters/xhr.ts#L24-L79) + +| Property | Type | Default | +| ---------------- | -------- | ------------------------------------------------- | +| url | string | _(required)_ | +| method | string | `"post"` | +| withCredentials | boolean | `false` | +| timeout | number | `0` | +| paramName | string | `"file"` | +| params | object | `{}` | +| headers | object | `{ Accept, 'Cache-Control', 'X-Requested-With' }` | +| responseType | string | `"json"` | +| errUploadError | function | `[Function]` | +| errUploadTimeout | function | `[Function]` | +| renameFile | function | `[Function]` | ## Events diff --git a/index.ts b/index.ts index 328a742..29f45fe 100644 --- a/index.ts +++ b/index.ts @@ -1,11 +1,12 @@ import { PluginObject } from "vue"; import { VueTransmit } from "./src/index"; +import { XHRUploadAdapter } from "./src/upload-adapters/xhr"; -const Plugin: PluginObject = { +const VueTransitPlugin: PluginObject = { install(Vue) { Vue.component("VueTransmit", VueTransmit); }, name: "vue-transmit", }; -export default Plugin; +export { VueTransitPlugin, VueTransmit, XHRUploadAdapter }; diff --git a/scripts/component-options.js b/scripts/component-options.js new file mode 100644 index 0000000..6356221 --- /dev/null +++ b/scripts/component-options.js @@ -0,0 +1,72 @@ +const { VueTransmit, XHRUploadAdapter } = require("../dist/vue-transmit"); +const { format } = require("util"); + +let { props } = VueTransmit.options; +let data = Object.keys(props) + .map(k => new_comp_desc(k, props[k])) + .map(d => `|${d.Property}|${d.Type}|${(d.Default || "").toString()}|`) + .join("\n"); + +console.log(data); + +props = new XHRUploadAdapter({}, { url: "" }); +data = Object.keys(props) + .map(k => new_class_desc(k, props)) + .map(d => `|${d.Property}|${d.Type}|${(d.Default || "").toString()}|`) + .join("\n"); + +console.log(data); + +function new_comp_desc(prop, descriptor) { + let desc = Object.create(null); + + desc.Property = prop; + desc.Type = resolve_type(descriptor.type); + desc.Default = fmt(descriptor.default); + if (descriptor.required) { + desc.Required = "✓"; + } + + return desc; +} + +function new_class_desc(prop, instance) { + let desc = Object.create(null); + + desc.Property = prop; + desc.Type = typeof instance[prop]; + desc.Default = fmt(instance[prop]); + + return desc; +} + +function resolve_type(t) { + if (Array.isArray(t)) { + return t.map(resolve_type).join(", "); + } + + if (typeof t !== "function") { + throw new TypeError(); + } + + return t.name; +} + +function fmt(x) { + if (x === null) { + return "null"; + } + switch (typeof x) { + case "number": + return format("%d", x); + case "object": + case "symbol": + case "function": + return format("%O", x); + case "string": + case "boolean": + case "undefined": + default: + return format("%s", x); + } +} diff --git a/src/upload-adapters/xhr.ts b/src/upload-adapters/xhr.ts index 1baa1e4..4e973f5 100644 --- a/src/upload-adapters/xhr.ts +++ b/src/upload-adapters/xhr.ts @@ -87,6 +87,7 @@ export type UploadGroup = { let GroupID = 0; export class XHRUploadAdapter implements UploaderInterface { + public context: VTransmitUploadContext; public url: string; public method: string; public withCredentials: boolean; @@ -101,10 +102,7 @@ export class XHRUploadAdapter implements UploaderInterface { public responseParseFunc?: (xhr: XMLHttpRequest) => UploadResolve; private uploadGroups: { [key: number]: UploadGroup } = Object.create(null); - constructor( - public context: VTransmitUploadContext, - options: XHRUploadOptions - ) { + constructor(context: VTransmitUploadContext, options: XHRUploadOptions) { let { url, method = "post", @@ -125,6 +123,8 @@ export class XHRUploadAdapter implements UploaderInterface { renameFile = (name: string) => name, } = options; + this.context = context; + this.url = url; this.method = method; this.withCredentials = withCredentials;