Skip to content

Commit ab7684d

Browse files
committed
chore: initial commit for 1.0.0-rc1
1 parent 00e9225 commit ab7684d

File tree

138 files changed

+20876
-3612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+20876
-3612
lines changed

.editorconfig

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[{src,scripts,config}/**.{ts,json,js}]
4+
end_of_line = lf
5+
charset = utf-8
6+
quote_type = single
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
indent_style = space
10+
indent_size = 2
11+
12+
[*.md]
13+
insert_final_newline = false
14+
trim_trailing_whitespace = false

.github/PULL_REQUEST_TEMPLATE.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...)
2+
3+
4+
5+
* **What is the current behavior?** (You can also link to an open issue here)
6+
7+
8+
9+
* **What is the new behavior (if this is a feature change)?**
10+
11+
12+
13+
* **Other information**:

.gitignore

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
dist_cdn
21
node_modules
3-
.DS_Store
2+
build
3+
src/**.js
4+
5+
coverage
46
*.log
7+
.env
8+
.nyc_output
9+
.DS_Store
10+
11+
# VS Code
12+
.vscode
13+
!.vscode/tasks.js

.npmignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
config
2+
examples
3+
test
4+
tsconfig.json
5+
tslint.json
6+
.travis.yml
7+
.github
8+
build/temp
9+
build/docs
10+
11+
coverage
12+
.nyc_output
13+
*.log

LICENSE

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
Copyright (c) 2017, Filestack
2-
3-
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4-
5-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1+
/*
2+
* Copyright (c) ${year} by Filestack.
3+
* Some rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/

README.md

+79-642
Large diffs are not rendered by default.

_config.yml

-1
This file was deleted.

config/env_production.js

-10
This file was deleted.

config/s3.json

-10
This file was deleted.

dist/filestack.es2015.js

-3
This file was deleted.

dist/filestack.es2015.js.map

-1
This file was deleted.

dist/filestack.js

-3
This file was deleted.

dist/filestack.js.map

-1
This file was deleted.

examples/assign-file-to-user/demo.css

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: Filestack Demo - Picker
3+
description: How to assign picture to user
4+
normalize_css: no
5+
...
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script src="//static.filestackapi.com/filestack-js/1.x.x/filestack.min.js"></script>

examples/assign-file-to-user/demo.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// sample function to get user id
2+
const getUserId = () => {
3+
return new Promise((resolve) => {
4+
resolve({
5+
userId: 'SAMPLE_USER_ID'
6+
})
7+
});
8+
};
9+
10+
// sample function for saving user data
11+
const saveUserData = (data) => {
12+
return new Promise((resolve) => {
13+
console.log(data);
14+
resolve({
15+
success: true
16+
})
17+
});
18+
};
19+
20+
window.addEventListener('DOMContentLoaded', function () {
21+
// user id taken from external source ie: your database, Facebook etc.
22+
getUserId().then((response) => {
23+
const userId = response.userId;
24+
const apikey = 'YOUR_APIKEY';
25+
const client = filestack.init(apikey);
26+
const options = {
27+
uploadInBackground: false,
28+
onFileUploadFinished: (response) => {
29+
// after file upload, make request with data to your application
30+
saveUserData({
31+
userId,
32+
fileHandle: response.handle
33+
}).then((res) => {
34+
console.log('User data has been saved', res);
35+
})
36+
}
37+
};
38+
const picker = client.picker(options);
39+
picker.open();
40+
});
41+
});
42+

examples/crop/demo.css

Whitespace-only changes.

examples/crop/demo.details

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: Filestack Demo - cropFiles
3+
description: Crop files using client
4+
normalize_css: no
5+
...

examples/crop/demo.html

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<input type="file" multiple />
2+
<script src="//static.filestackapi.com/filestack-js/1.x.x/filestack.min.js"></script>

examples/crop/demo.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
window.addEventListener('DOMContentLoaded', function () {
2+
const apikey = 'YOUR_APIKEY';
3+
const client = filestack.init(apikey);
4+
5+
document.querySelector('input').addEventListener('change', (event) => {
6+
const files = event.target.files;
7+
const pickOptions = {
8+
transformations: {
9+
crop: {
10+
aspectRatio: 16/9,
11+
},
12+
circle: false
13+
},
14+
onUploadDone: res => console.log(res),
15+
};
16+
const picker = client.picker(pickOptions);
17+
picker.crop(files);
18+
});
19+
});

examples/customization/demo.css

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* change picker appearance */
2+
.fsp-picker {
3+
background: rgba(0,0,0,.288)!important;
4+
}
5+
6+
/* update styles for drop area */
7+
.fsp-picker .fsp-drop-area {
8+
background: rgba(0,0,0,.03);
9+
border-radius: 0;
10+
}
11+
12+
/* customize picker modal */
13+
.fsp-picker .fsp-modal {
14+
background: #fff;
15+
border-radius: 0;
16+
border:none;
17+
box-shadow: 0 11px 15px -7px rgba(0,0,0,.2), 0 24px 38px 3px rgba(0,0,0,.14), 0 9px 46px 8px rgba(0,0,0,.12)
18+
}
19+
20+
.fsp-picker .fsp-header {
21+
color: rgba(0,0,0,.54);
22+
}
23+
24+
.fsp-picker .fsp-url-source__input,
25+
.fsp-picker .fsp-url-source__submit-button {
26+
border: none;
27+
border-radius: 0;
28+
height: 30px;
29+
border-bottom: 1px solid #2e68fb;
30+
}
31+
32+
.fsp-picker .fsp-url-source__input:focus {
33+
outline: none;
34+
border: none;
35+
border-bottom: 1px solid #2e68fb;
36+
}
37+
38+
.fsp-picker .fsp-url-source__submit-button {
39+
width: 30px;
40+
border: 1px solid #2e68fb;
41+
padding:0;
42+
}

examples/customization/demo.details

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: Filestack Demo - css customization
3+
description: Easy customization with BEM standard (http://getbem.com/)
4+
normalize_css: no
5+
...

examples/customization/demo.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script src="//static.filestackapi.com/filestack-js/1.x.x/filestack.min.js"></script>

examples/customization/demo.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
window.addEventListener('DOMContentLoaded', function () {
2+
const apikey = 'YOUR_APIKEY';
3+
const client = filestack.init(apikey);
4+
const picker = client.picker({
5+
fromSources: ['local_file_system', 'url', 'imagesearch'],
6+
maxFiles: 20,
7+
uploadInBackground: false,
8+
onOpen: () => console.log('opened!'),
9+
});
10+
picker.open();
11+
});

examples/examples.js

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
const express = require('express');
2+
const util = require('util');
3+
const fs = require('fs');
4+
const path = require('path');
5+
const app = express();
6+
const yaml = require('js-yaml');
7+
const readFile = util.promisify(fs.readFile);
8+
const readDir = util.promisify(fs.readdir);
9+
10+
// hardcoded names because of jsFiddle <== github integration
11+
const files = {
12+
index: 'demo.html',
13+
script: 'demo.js',
14+
config: 'demo.details',
15+
css: 'demo.css',
16+
};
17+
18+
const filesContent = {
19+
script: null,
20+
css: null,
21+
config: null
22+
};
23+
24+
const template = `
25+
<html>
26+
<title>{{title}}</title>
27+
<head>
28+
{{headScript}}
29+
<style>
30+
{{style}}
31+
</style>
32+
</head>
33+
<body>
34+
{{content}}
35+
<script src="http://localhost:4000/index.umd.js"></script>
36+
<script>
37+
{{script}}
38+
</script>
39+
</body>
40+
</html>
41+
`;
42+
43+
const listTemplate = `
44+
<html>
45+
<body>
46+
<ul>{{list}}</ul>
47+
</body>
48+
</html>
49+
`;
50+
51+
let examples;
52+
const getExamples = () => {
53+
examples = [];
54+
return readDir(__dirname).then((results) => {
55+
results.forEach((val) => {
56+
if (fs.statSync(path.join(__dirname, val)).isDirectory()
57+
&& fs.existsSync(path.join(__dirname, val, files.config))) {
58+
examples.push(val);
59+
}
60+
});
61+
});
62+
};
63+
64+
// render examples list
65+
app.get('/', (req, res) => {
66+
getExamples().then(() => {
67+
const list = examples.map(val => `<li><a href="/${val}" alt="val">${val}</a></li>`);
68+
res.send(listTemplate.replace('{{list}}', list.join('\r\n')));
69+
});
70+
});
71+
72+
// render example based on jsFiddle github integration
73+
app.get('/*', (req, res) => {
74+
const requestedPath = req.path;
75+
const promises = [];
76+
if (req.path === '/index.umd.js') {
77+
return readFile(path.join(__dirname, '../build/browser/index.umd.js'))
78+
.then((file) => res.send(file.toString()));
79+
}
80+
81+
const stripped = req.path.substring(1);
82+
if (examples.indexOf(stripped) === -1) {
83+
res.status(404);
84+
res.end();
85+
return;
86+
}
87+
88+
Object.keys(files).forEach((key) => {
89+
const promiseFn = readFile(path.join(__dirname, requestedPath, files[key]));
90+
promiseFn.then((res) => {
91+
filesContent[key] = res.toString();
92+
});
93+
94+
promises.push(promiseFn);
95+
});
96+
97+
Promise.all(promises).then(() => {
98+
if (!filesContent.config) {
99+
res.status(404);
100+
res.end();
101+
return;
102+
}
103+
104+
const config = yaml.safeLoad(filesContent.config);
105+
let tpl = template + '';
106+
tpl = tpl.replace('{{title}}', config.name || '')
107+
.replace('{{content}}', filesContent.index)
108+
.replace('{{script}}', filesContent.script)
109+
.replace('{{style}}', filesContent.css || '');
110+
111+
if (config.resources) {
112+
let resources = [];
113+
114+
config.resources.forEach((val) => {
115+
resources.push(`<script src="${val}"></script>`)
116+
});
117+
118+
tpl = tpl.replace('{{headScript}}', resources.join('\r\n'))
119+
} else {
120+
tpl = tpl.replace('{{headScript}}', '')
121+
}
122+
123+
res.send(tpl);
124+
}).catch((err) => {
125+
console.log(err);
126+
res.status(404);
127+
res.end();
128+
});
129+
});
130+
131+
getExamples().then(() => {
132+
app.listen(4000, () => console.log('Filestack Examples server is listening on http://localhost:4000'))
133+
});

0 commit comments

Comments
 (0)