@scaleflex/widget-unsplash 0.0.1
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/CHANGELOG.md +6758 -0
- package/LICENSE +22 -0
- package/README.md +31 -0
- package/lib/common.slice.js +35 -0
- package/lib/defaultLocale.js +10 -0
- package/lib/index.js +112 -0
- package/package.json +34 -0
- package/src/common.slice.js +33 -0
- package/src/defaultLocale.js +10 -0
- package/src/index.js +90 -0
- package/types/index.d.ts +15 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2020 Transloadit
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<!-- Variables -->
|
|
2
|
+
|
|
3
|
+
[![Plugins][plugins-image]](#plugins)
|
|
4
|
+
[![Website][filerobot-image]][sfx-url]
|
|
5
|
+
[![Version][filerobot-version]][version-url]
|
|
6
|
+
[![Scaleflex team][made-by-image]][sfx-url]
|
|
7
|
+
[![License][license-image]][license-url]
|
|
8
|
+
[![CodeSandbox][codeSandbox-image]][codeSandbox-url]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
<div align='center'>
|
|
12
|
+
<img title="Scaleflex Widget logo" alt="Scaleflex Widget logo" src="https://cdn.scaleflex.com/plugins/filerobot-widget/assets/filerobot_widget_logo_with_fire.png?vh=b2ff09" width="140"/>
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
The Unsplash plugin for [Scaleflex Media Asset Widget](https://www.npmjs.com/package/@scaleflex/widget-core) lets users import files from Unsplash, the free stock photography resource.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
[npm-url]: https://www.npmjs.com/package/@scaleflex/widget-unsplash
|
|
20
|
+
[license-url]: https://opensource.org/licenses/MIT
|
|
21
|
+
[sfx-url]: https://www.scaleflex.com/
|
|
22
|
+
[version-url]: https://www.npmjs.com/package/@scaleflex/widget-@scaleflex/widget-unsplash
|
|
23
|
+
[codeSandbox-url]: https://codesandbox.io/s/filerobot-widget-v3-c5l9th
|
|
24
|
+
|
|
25
|
+
[npm-image]: https://img.shields.io/npm/v/@telus/remark-config.svg?style=for-the-badge&logo=npm
|
|
26
|
+
[license-image]: https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge
|
|
27
|
+
[made-by-image]: https://img.shields.io/badge/%3C%2F%3E%20with%20%E2%99%A5%20by-the%20Scaleflex%20team-6986fa.svg?style=for-the-badge
|
|
28
|
+
[plugins-image]: https://img.shields.io/static/v1?label=Scaleflex&message=Plugins&color=yellow&style=for-the-badge
|
|
29
|
+
[filerobot-image]: https://img.shields.io/static/v1?label=Scaleflex&message=website&color=orange&style=for-the-badge
|
|
30
|
+
[filerobot-version]: https://img.shields.io/npm/v/@scaleflex/widget-unsplash?label=Version&style=for-the-badge&logo=npm
|
|
31
|
+
[codeSandbox-image]: https://img.shields.io/badge/CodeSandbox-black?style=for-the-badge&logo=CodeSandbox
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import { createSlice } from '@reduxjs/toolkit';
|
|
8
|
+
import { PLUGINS_IDS } from '@scaleflex/widget-utils/lib/constants';
|
|
9
|
+
|
|
10
|
+
// If the plugin instantiates a Provider, then we must have a common slice for it, as it will get updated through the provider.
|
|
11
|
+
var initialState = {
|
|
12
|
+
authenticated: false,
|
|
13
|
+
files: [],
|
|
14
|
+
folders: [],
|
|
15
|
+
openedFolders: [],
|
|
16
|
+
selectedFolders: {},
|
|
17
|
+
activeRow: -1,
|
|
18
|
+
filterInput: '',
|
|
19
|
+
isSearchVisible: false
|
|
20
|
+
};
|
|
21
|
+
var commonSlice = createSlice({
|
|
22
|
+
name: PLUGINS_IDS.UNSPLASH,
|
|
23
|
+
initialState: initialState,
|
|
24
|
+
reducers: {
|
|
25
|
+
unsplashCommonStateUpdated: function unsplashCommonStateUpdated(state, action) {
|
|
26
|
+
return _objectSpread(_objectSpread({}, state), action.payload);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var unsplashCommonStateUpdated = commonSlice.actions.unsplashCommonStateUpdated;
|
|
31
|
+
export { unsplashCommonStateUpdated };
|
|
32
|
+
export var selectUnsplashCommonState = function selectUnsplashCommonState(state) {
|
|
33
|
+
return state[PLUGINS_IDS.UNSPLASH];
|
|
34
|
+
};
|
|
35
|
+
export default commonSlice.reducer;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
unsplashSelectButton: 'Select %{smart_count}',
|
|
3
|
+
unsplashAssetsLabel: 'Assets (%{smart_count})',
|
|
4
|
+
unsplashCancelButton: 'Cancel',
|
|
5
|
+
unsplashNoResultLabel: 'Unfortunately, there are no results for this search',
|
|
6
|
+
searchUnsplachTitle: 'Enter text to search for images',
|
|
7
|
+
searchUnsplachPlaceholder: 'search for images',
|
|
8
|
+
searchUnsplachLabel: 'Search',
|
|
9
|
+
searchUnsplachButton: 'Search for images'
|
|
10
|
+
};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
6
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
7
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
9
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
11
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
12
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
13
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
14
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
15
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
16
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
17
|
+
import { Plugin } from '@scaleflex/widget-core';
|
|
18
|
+
import { SearchProvider, Provider, RequestClient } from '@scaleflex/widget-companion-client';
|
|
19
|
+
import SearchProviderView from '@scaleflex/widget-provider-views/lib/components/SearchProviderView';
|
|
20
|
+
import { UnsplashIcon } from '@scaleflex/widget-icons';
|
|
21
|
+
import Translator from '@scaleflex/widget-utils/lib/Translator';
|
|
22
|
+
import Explorer from '@scaleflex/widget-explorer';
|
|
23
|
+
import defaultLocale from './defaultLocale';
|
|
24
|
+
import unsplashReducer, { unsplashCommonStateUpdated } from './common.slice';
|
|
25
|
+
var Unsplash = /*#__PURE__*/function (_Plugin) {
|
|
26
|
+
// static VERSION = packageJson.version
|
|
27
|
+
|
|
28
|
+
function Unsplash(filerobot, opts) {
|
|
29
|
+
var _this;
|
|
30
|
+
_classCallCheck(this, Unsplash);
|
|
31
|
+
_this = _callSuper(this, Unsplash, [filerobot, opts]);
|
|
32
|
+
_this.id = 'Unsplash';
|
|
33
|
+
Provider.initPlugin(_this, opts);
|
|
34
|
+
_this.title = _this.opts.title || 'Unsplash';
|
|
35
|
+
_this.icon = UnsplashIcon;
|
|
36
|
+
_this.defaultLocale = {
|
|
37
|
+
strings: defaultLocale
|
|
38
|
+
};
|
|
39
|
+
var defaultOptions = {};
|
|
40
|
+
_this.opts = _objectSpread(_objectSpread({}, defaultOptions), opts);
|
|
41
|
+
_this.i18nInit();
|
|
42
|
+
_this.onFirstRender = _this.onFirstRender.bind(_this);
|
|
43
|
+
_this.render = _this.render.bind(_this);
|
|
44
|
+
_this.client = new RequestClient(filerobot, {
|
|
45
|
+
companionHeaders: _this.opts.companionHeaders
|
|
46
|
+
});
|
|
47
|
+
_this.provider = new SearchProvider(filerobot, {
|
|
48
|
+
companionUrl: _this.opts.companionUrl,
|
|
49
|
+
companionHeaders: _this.opts.companionHeaders,
|
|
50
|
+
companionCookiesRule: _this.opts.companionCookiesRule,
|
|
51
|
+
provider: 'unsplash',
|
|
52
|
+
pluginId: _this.id
|
|
53
|
+
});
|
|
54
|
+
_this.hostname = _this.client.companionUrl;
|
|
55
|
+
if (!_this.hostname) {
|
|
56
|
+
throw new Error('Companion hostname is required');
|
|
57
|
+
}
|
|
58
|
+
return _this;
|
|
59
|
+
}
|
|
60
|
+
_inherits(Unsplash, _Plugin);
|
|
61
|
+
return _createClass(Unsplash, [{
|
|
62
|
+
key: "i18nInit",
|
|
63
|
+
value: function i18nInit() {
|
|
64
|
+
this.translator = new Translator([this.defaultLocale, this.filerobot.locale]);
|
|
65
|
+
this.i18n = this.translator.translate.bind(this.translator);
|
|
66
|
+
this.i18nArray = this.translator.translateArray.bind(this.translator);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// eslint-disable-next-line class-methods-use-this
|
|
70
|
+
}, {
|
|
71
|
+
key: "onFirstRender",
|
|
72
|
+
value: function onFirstRender() {
|
|
73
|
+
// do nothing
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
76
|
+
key: "render",
|
|
77
|
+
value: function render(state) {
|
|
78
|
+
return this.view.render({
|
|
79
|
+
state: state
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
key: "setPluginCommonState",
|
|
84
|
+
value: function setPluginCommonState(update) {
|
|
85
|
+
return this.dispatch(unsplashCommonStateUpdated(update));
|
|
86
|
+
}
|
|
87
|
+
}, {
|
|
88
|
+
key: "getPluginReducer",
|
|
89
|
+
value: function getPluginReducer() {
|
|
90
|
+
return unsplashReducer;
|
|
91
|
+
}
|
|
92
|
+
}, {
|
|
93
|
+
key: "install",
|
|
94
|
+
value: function install() {
|
|
95
|
+
if (Explorer) {
|
|
96
|
+
this.view = new SearchProviderView(this, {
|
|
97
|
+
provider: this.provider,
|
|
98
|
+
layoutType: 'unsplash',
|
|
99
|
+
showFilter: false,
|
|
100
|
+
i18n: this.i18n
|
|
101
|
+
});
|
|
102
|
+
this.mount(Explorer, this);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
key: "uninstall",
|
|
107
|
+
value: function uninstall() {
|
|
108
|
+
this.unmount();
|
|
109
|
+
}
|
|
110
|
+
}]);
|
|
111
|
+
}(Plugin);
|
|
112
|
+
export { Unsplash as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@scaleflex/widget-unsplash",
|
|
3
|
+
"description": "Import files from Unsplash, the free stock photography resource",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "types/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"file uploader",
|
|
11
|
+
"uppy",
|
|
12
|
+
"uppy-plugin",
|
|
13
|
+
"unsplash"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@scaleflex/icons": "^3.0.0-beta.11",
|
|
20
|
+
"@scaleflex/ui": "^3.0.0-beta.11",
|
|
21
|
+
"@scaleflex/widget-common": "^0.0.1"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"react": "^19.0.0",
|
|
25
|
+
"react-dom": "^19.0.0"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@scaleflex/widget-core": "^0.0.0",
|
|
29
|
+
"@scaleflex/widget-explorer": "^0.0.0",
|
|
30
|
+
"react": ">=19.0.0",
|
|
31
|
+
"react-dom": ">=19.0.0"
|
|
32
|
+
},
|
|
33
|
+
"gitHead": "64ea82e745b7deda36d6794863350e6671e9010d"
|
|
34
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createSlice } from '@reduxjs/toolkit'
|
|
2
|
+
import { PLUGINS_IDS } from '@scaleflex/widget-utils/lib/constants'
|
|
3
|
+
|
|
4
|
+
// If the plugin instantiates a Provider, then we must have a common slice for it, as it will get updated through the provider.
|
|
5
|
+
const initialState = {
|
|
6
|
+
authenticated: false,
|
|
7
|
+
files: [],
|
|
8
|
+
folders: [],
|
|
9
|
+
openedFolders: [],
|
|
10
|
+
selectedFolders: {},
|
|
11
|
+
activeRow: -1,
|
|
12
|
+
filterInput: '',
|
|
13
|
+
isSearchVisible: false
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const commonSlice = createSlice({
|
|
17
|
+
name: PLUGINS_IDS.UNSPLASH,
|
|
18
|
+
initialState,
|
|
19
|
+
reducers: {
|
|
20
|
+
unsplashCommonStateUpdated (state, action) {
|
|
21
|
+
return {
|
|
22
|
+
...state,
|
|
23
|
+
...action.payload
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
export const { unsplashCommonStateUpdated } = commonSlice.actions
|
|
30
|
+
|
|
31
|
+
export const selectUnsplashCommonState = state => state[PLUGINS_IDS.UNSPLASH]
|
|
32
|
+
|
|
33
|
+
export default commonSlice.reducer
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
unsplashSelectButton: 'Select %{smart_count}',
|
|
3
|
+
unsplashAssetsLabel: 'Assets (%{smart_count})',
|
|
4
|
+
unsplashCancelButton: 'Cancel',
|
|
5
|
+
unsplashNoResultLabel: 'Unfortunately, there are no results for this search',
|
|
6
|
+
searchUnsplachTitle: 'Enter text to search for images',
|
|
7
|
+
searchUnsplachPlaceholder: 'search for images',
|
|
8
|
+
searchUnsplachLabel: 'Search',
|
|
9
|
+
searchUnsplachButton: 'Search for images'
|
|
10
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Plugin } from '@scaleflex/widget-core'
|
|
2
|
+
import { SearchProvider, Provider, RequestClient } from '@scaleflex/widget-companion-client'
|
|
3
|
+
import SearchProviderView from '@scaleflex/widget-provider-views/lib/components/SearchProviderView'
|
|
4
|
+
import { UnsplashIcon } from '@scaleflex/widget-icons'
|
|
5
|
+
import Translator from '@scaleflex/widget-utils/lib/Translator'
|
|
6
|
+
import Explorer from '@scaleflex/widget-explorer'
|
|
7
|
+
|
|
8
|
+
import defaultLocale from './defaultLocale'
|
|
9
|
+
import unsplashReducer, { unsplashCommonStateUpdated } from './common.slice'
|
|
10
|
+
|
|
11
|
+
export default class Unsplash extends Plugin {
|
|
12
|
+
// static VERSION = packageJson.version
|
|
13
|
+
|
|
14
|
+
constructor (filerobot, opts) {
|
|
15
|
+
super(filerobot, opts)
|
|
16
|
+
this.id = 'Unsplash'
|
|
17
|
+
Provider.initPlugin(this, opts)
|
|
18
|
+
this.title = this.opts.title || 'Unsplash'
|
|
19
|
+
this.icon = UnsplashIcon
|
|
20
|
+
|
|
21
|
+
this.defaultLocale = {
|
|
22
|
+
strings: defaultLocale
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const defaultOptions = {}
|
|
26
|
+
|
|
27
|
+
this.opts = { ...defaultOptions, ...opts }
|
|
28
|
+
this.i18nInit()
|
|
29
|
+
|
|
30
|
+
this.onFirstRender = this.onFirstRender.bind(this)
|
|
31
|
+
this.render = this.render.bind(this)
|
|
32
|
+
|
|
33
|
+
this.client = new RequestClient(filerobot, {
|
|
34
|
+
companionHeaders: this.opts.companionHeaders
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
this.provider = new SearchProvider(filerobot, {
|
|
38
|
+
companionUrl: this.opts.companionUrl,
|
|
39
|
+
companionHeaders: this.opts.companionHeaders,
|
|
40
|
+
companionCookiesRule: this.opts.companionCookiesRule,
|
|
41
|
+
provider: 'unsplash',
|
|
42
|
+
pluginId: this.id
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
this.hostname = this.client.companionUrl
|
|
46
|
+
|
|
47
|
+
if (!this.hostname) {
|
|
48
|
+
throw new Error('Companion hostname is required')
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
i18nInit () {
|
|
53
|
+
this.translator = new Translator([this.defaultLocale, this.filerobot.locale])
|
|
54
|
+
this.i18n = this.translator.translate.bind(this.translator)
|
|
55
|
+
this.i18nArray = this.translator.translateArray.bind(this.translator)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// eslint-disable-next-line class-methods-use-this
|
|
59
|
+
onFirstRender () {
|
|
60
|
+
// do nothing
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
render (state) {
|
|
64
|
+
return this.view.render({ state })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setPluginCommonState (update) {
|
|
68
|
+
return this.dispatch(unsplashCommonStateUpdated(update))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getPluginReducer () {
|
|
72
|
+
return unsplashReducer
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
install () {
|
|
76
|
+
if (Explorer) {
|
|
77
|
+
this.view = new SearchProviderView(this, {
|
|
78
|
+
provider: this.provider,
|
|
79
|
+
layoutType: 'unsplash',
|
|
80
|
+
showFilter: false,
|
|
81
|
+
i18n: this.i18n
|
|
82
|
+
})
|
|
83
|
+
this.mount(Explorer, this)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
uninstall () {
|
|
88
|
+
this.unmount()
|
|
89
|
+
}
|
|
90
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Filerobot = require("@scaleflex/widget-core");
|
|
2
|
+
import CompanionClient = require("@scaleflex/widget-companion-client");
|
|
3
|
+
|
|
4
|
+
declare module Unsplash {
|
|
5
|
+
interface UnsplashOptions
|
|
6
|
+
extends Filerobot.PluginOptions,
|
|
7
|
+
CompanionClient.PublicProviderOptions {
|
|
8
|
+
target?: Filerobot.PluginTarget;
|
|
9
|
+
title?: string;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare class Unsplash extends Filerobot.Plugin<Unsplash.UnsplashOptions> {}
|
|
14
|
+
|
|
15
|
+
export default Unsplash;
|