Skip to content
This repository has been archived by the owner on Jan 29, 2019. It is now read-only.

Commit

Permalink
fix: use named exports and update props in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsasharegan committed Feb 9, 2018
1 parent 313ce74 commit 2150854
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 42 deletions.
85 changes: 49 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,42 +92,55 @@ Vue.use(VueTransmit);

## Props: <code>&lt;vue-transmit&gt;</code>

| 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

Expand Down
5 changes: 3 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { PluginObject } from "vue";
import { VueTransmit } from "./src/index";
import { XHRUploadAdapter } from "./src/upload-adapters/xhr";

const Plugin: PluginObject<undefined> = {
const VueTransitPlugin: PluginObject<undefined> = {
install(Vue) {
Vue.component("VueTransmit", VueTransmit);
},
name: "vue-transmit",
};

export default Plugin;
export { VueTransitPlugin, VueTransmit, XHRUploadAdapter };
72 changes: 72 additions & 0 deletions scripts/component-options.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
8 changes: 4 additions & 4 deletions src/upload-adapters/xhr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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",
Expand All @@ -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;
Expand Down

0 comments on commit 2150854

Please sign in to comment.