@scaleflex/widget-core 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 +7324 -0
- package/LICENSE +21 -0
- package/README.md +1089 -0
- package/dist/style.css +190 -0
- package/dist/style.min.css +1 -0
- package/lib/Client.js +390 -0
- package/lib/Plugin.js +298 -0
- package/lib/Providers.js +112 -0
- package/lib/SassKeyRenewer.js +332 -0
- package/lib/_common.scss +240 -0
- package/lib/_utils.scss +38 -0
- package/lib/_variables.scss +64 -0
- package/lib/createStore.js +45 -0
- package/lib/defaultLocale.js +66 -0
- package/lib/hooks/index.js +7 -0
- package/lib/hooks/useContextMenu.js +42 -0
- package/lib/hooks/useContextMenuData.js +17 -0
- package/lib/hooks/useCore.js +10 -0
- package/lib/hooks/useModal.js +72 -0
- package/lib/hooks/useModalData.js +7 -0
- package/lib/hooks/usePlugin.js +20 -0
- package/lib/hooks/usePluginsType.js +18 -0
- package/lib/index.js +1918 -0
- package/lib/loggers.js +45 -0
- package/lib/slices/common.slice.js +90 -0
- package/lib/slices/index.js +12 -0
- package/lib/slices/info.slice.js +52 -0
- package/lib/slices/uploads.slice.js +294 -0
- package/lib/slices/user.slice.js +256 -0
- package/lib/style.scss +3 -0
- package/lib/supportsUploadProgress.js +42 -0
- package/lib/utils/calculateTotalEta.js +21 -0
- package/package.json +38 -0
- package/types/index.d.ts +301 -0
package/lib/Plugin.js
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
11
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
13
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
14
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
15
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
16
|
+
import { createElement } from 'react';
|
|
17
|
+
import { createRoot } from 'react-dom/client';
|
|
18
|
+
import findDOMElement from '@scaleflex/widget-utils/lib/findDOMElement';
|
|
19
|
+
import Providers from './Providers';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Defer a frequent call to the microtask queue.
|
|
23
|
+
*/
|
|
24
|
+
function debounce(fn) {
|
|
25
|
+
var calling = null;
|
|
26
|
+
var latestArgs = null;
|
|
27
|
+
return function () {
|
|
28
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
29
|
+
args[_key] = arguments[_key];
|
|
30
|
+
}
|
|
31
|
+
latestArgs = args;
|
|
32
|
+
if (!calling) {
|
|
33
|
+
calling = Promise.resolve().then(function () {
|
|
34
|
+
calling = null;
|
|
35
|
+
// At this point `args` may be different from the most
|
|
36
|
+
// recent state, if multiple calls happened since this task
|
|
37
|
+
// was queued. So we use the `latestArgs`, which definitely
|
|
38
|
+
// is the most recent call.
|
|
39
|
+
return fn.apply(void 0, _toConsumableArray(latestArgs));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return calling;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Boilerplate that all Plugins share - and should not be used
|
|
48
|
+
* directly. It also shows which methods final plugins should implement/override,
|
|
49
|
+
* this deciding on structure.
|
|
50
|
+
*
|
|
51
|
+
* @param {object} main Filerobot core object
|
|
52
|
+
* @param {object} object with plugin options
|
|
53
|
+
* @returns {Array|string} files or success/fail message
|
|
54
|
+
*/
|
|
55
|
+
var Plugin = /*#__PURE__*/function () {
|
|
56
|
+
function Plugin(filerobot) {
|
|
57
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
58
|
+
_classCallCheck(this, Plugin);
|
|
59
|
+
this.filerobot = filerobot;
|
|
60
|
+
this.opts = opts || {};
|
|
61
|
+
this.store = filerobot.store;
|
|
62
|
+
this.update = this.update.bind(this);
|
|
63
|
+
this.mount = this.mount.bind(this);
|
|
64
|
+
this.install = this.install.bind(this);
|
|
65
|
+
this.uninstall = this.uninstall.bind(this);
|
|
66
|
+
this.getGlobalState = this.getGlobalState.bind(this);
|
|
67
|
+
this.getPluginReducer = this.getPluginReducer.bind(this);
|
|
68
|
+
this.getPluginCommonState = this.getPluginCommonState.bind(this);
|
|
69
|
+
this.setPluginCommonState = this.setPluginCommonState.bind(this);
|
|
70
|
+
this.dispatch = this.dispatch.bind(this);
|
|
71
|
+
this.checkPluginExistence = this.checkPluginExistence.bind(this);
|
|
72
|
+
this.checkPluginTypeExistence = this.checkPluginTypeExistence.bind(this);
|
|
73
|
+
this.info = this.filerobot.info;
|
|
74
|
+
this.hideInfo = this.filerobot.hideInfo;
|
|
75
|
+
this.log = this.filerobot.log;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Returns current state of whole redux's store, uses the same one of scaleflexWidget's core class,
|
|
80
|
+
* for easier access from the extended plugin class only.
|
|
81
|
+
*
|
|
82
|
+
* @returns {object}
|
|
83
|
+
*/
|
|
84
|
+
return _createClass(Plugin, [{
|
|
85
|
+
key: "getGlobalState",
|
|
86
|
+
value: function getGlobalState() {
|
|
87
|
+
return this.filerobot.getGlobalState();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* returns the plugin's common state/slice from the redux's store
|
|
92
|
+
* @param {string} sliceName - the slice's name (property) to be accessed from the redux's store state.
|
|
93
|
+
* @returns {Object}
|
|
94
|
+
*/
|
|
95
|
+
}, {
|
|
96
|
+
key: "getPluginCommonState",
|
|
97
|
+
value: function getPluginCommonState() {
|
|
98
|
+
var pluginCommonState = this.filerobot.getGlobalState()[this.id];
|
|
99
|
+
if (!pluginCommonState && this.filerobot.opts.dev && !this.noStateWarned) {
|
|
100
|
+
console.warn("Note, No state found in redux's store with this plugin's id: ".concat(this.id, "..."));
|
|
101
|
+
this.noStateWarned = true;
|
|
102
|
+
}
|
|
103
|
+
return pluginCommonState || {};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* To be overriden from the plugin itself with the common state/slice of the plugin getting dispatched to.
|
|
108
|
+
* @param {string} update - object contains the updates.
|
|
109
|
+
* @returns {Object}
|
|
110
|
+
*/
|
|
111
|
+
}, {
|
|
112
|
+
key: "setPluginCommonState",
|
|
113
|
+
value: function setPluginCommonState(update) {}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Same dispatch as core's one but wrapping it in-case of future changes/logs...etc.
|
|
117
|
+
*
|
|
118
|
+
* @param {Function/Object} actionCreator
|
|
119
|
+
*/
|
|
120
|
+
}, {
|
|
121
|
+
key: "dispatch",
|
|
122
|
+
value: function dispatch(actionCreator) {
|
|
123
|
+
return this.filerobot.dispatch(actionCreator);
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
key: "setOptions",
|
|
127
|
+
value: function setOptions() {
|
|
128
|
+
var _this$opts$config, _newOpts$config, _this$opts$config2, _newOpts$config2;
|
|
129
|
+
var newOpts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
130
|
+
this.opts = _objectSpread(_objectSpread(_objectSpread({}, this.opts), newOpts), {}, {
|
|
131
|
+
config: this.opts.config || newOpts.config ? _objectSpread(_objectSpread(_objectSpread({}, this.opts.config), newOpts.config), {}, {
|
|
132
|
+
tagging: _objectSpread(_objectSpread({}, (_this$opts$config = this.opts.config) === null || _this$opts$config === void 0 ? void 0 : _this$opts$config.tagging), (_newOpts$config = newOpts.config) === null || _newOpts$config === void 0 ? void 0 : _newOpts$config.tagging),
|
|
133
|
+
video: _objectSpread(_objectSpread({}, (_this$opts$config2 = this.opts.config) === null || _this$opts$config2 === void 0 ? void 0 : _this$opts$config2.video), (_newOpts$config2 = newOpts.config) === null || _newOpts$config2 === void 0 ? void 0 : _newOpts$config2.video)
|
|
134
|
+
}) : undefined
|
|
135
|
+
});
|
|
136
|
+
if (typeof this.i18nInit === 'function') {
|
|
137
|
+
this.i18nInit();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Already the opts object of the plugin is updated, so we need only to emit a new object's reference
|
|
141
|
+
// and handle rerendering in the plugins' providers so that it causes rerender.
|
|
142
|
+
this.filerobot.emit('opts-updated', {
|
|
143
|
+
filerobot: this.filerobot,
|
|
144
|
+
plugins: this.filerobot.plugins,
|
|
145
|
+
newOpts: newOpts
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}, {
|
|
149
|
+
key: "update",
|
|
150
|
+
value: function update() {
|
|
151
|
+
if (typeof this.el === 'undefined') {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (this._updateUI) {
|
|
155
|
+
this._updateUI();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Called after every state update, after everything's mounted. Debounced.
|
|
160
|
+
}, {
|
|
161
|
+
key: "afterUpdate",
|
|
162
|
+
value: function afterUpdate() {}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Called when plugin is mounted, whether in DOM or into another plugin.
|
|
166
|
+
* Needed because sometimes plugins are mounted separately/after `install`,
|
|
167
|
+
* so this.el and this.parent might not be available in `install`.
|
|
168
|
+
*/
|
|
169
|
+
}, {
|
|
170
|
+
key: "onMount",
|
|
171
|
+
value: function onMount() {}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Check if supplied `target` is a DOM element or an `object`.
|
|
175
|
+
* If it’s an object — target is a plugin, and we search `plugins`
|
|
176
|
+
* for a plugin with same name and return its target.
|
|
177
|
+
*
|
|
178
|
+
* @param {string|object} target
|
|
179
|
+
*
|
|
180
|
+
*/
|
|
181
|
+
}, {
|
|
182
|
+
key: "mount",
|
|
183
|
+
value: function mount(target, plugin) {
|
|
184
|
+
var _this = this;
|
|
185
|
+
var callerPluginName = plugin.id;
|
|
186
|
+
var targetElement = findDOMElement(target);
|
|
187
|
+
if (targetElement) {
|
|
188
|
+
this.root = createRoot(targetElement);
|
|
189
|
+
this.isTargetDomEl = true;
|
|
190
|
+
// API for plugins that require a synchronous rerender.
|
|
191
|
+
this.rerender = function () {
|
|
192
|
+
// plugin could be removed, but this.rerender is debounced below,
|
|
193
|
+
// so it could still be called even after filerobot.removePlugin or filerobot.close
|
|
194
|
+
// hence the check
|
|
195
|
+
if (!_this.filerobot.getPlugin(_this.id)) return;
|
|
196
|
+
var onUiLoad = function onUiLoad() {
|
|
197
|
+
_this.el = targetElement.lastElementChild;
|
|
198
|
+
_this.afterUpdate();
|
|
199
|
+
};
|
|
200
|
+
_this.root.render(/*#__PURE__*/createElement(Providers, {
|
|
201
|
+
filerobot: _this.filerobot,
|
|
202
|
+
onUiLoad: onUiLoad
|
|
203
|
+
}, _this.render()));
|
|
204
|
+
};
|
|
205
|
+
this._updateUI = debounce(this.rerender);
|
|
206
|
+
this.filerobot.log("Installing ".concat(callerPluginName, " to a DOM element '").concat(target, "'"));
|
|
207
|
+
|
|
208
|
+
// clear everything inside the target container
|
|
209
|
+
if (this.opts.replaceTargetContent) {
|
|
210
|
+
targetElement.innerHTML = '';
|
|
211
|
+
}
|
|
212
|
+
var onUiLoad = function onUiLoad() {
|
|
213
|
+
_this.el = targetElement.lastElementChild;
|
|
214
|
+
_this.onMount();
|
|
215
|
+
};
|
|
216
|
+
this.root.render(/*#__PURE__*/createElement(Providers, {
|
|
217
|
+
filerobot: this.filerobot,
|
|
218
|
+
onUiLoad: onUiLoad
|
|
219
|
+
}, this.render()));
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
var targetPlugin;
|
|
223
|
+
if (_typeof(target) === 'object' && target instanceof Plugin) {
|
|
224
|
+
// Targeting a plugin *instance*
|
|
225
|
+
targetPlugin = target;
|
|
226
|
+
} else if (typeof target === 'function') {
|
|
227
|
+
// Targeting a plugin type
|
|
228
|
+
var Target = target;
|
|
229
|
+
// Find the target plugin instance.
|
|
230
|
+
this.filerobot.iteratePlugins(function (plugin) {
|
|
231
|
+
if (plugin instanceof Target) {
|
|
232
|
+
targetPlugin = plugin;
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
if (targetPlugin) {
|
|
238
|
+
this.filerobot.log("Installing ".concat(callerPluginName, " to ").concat(targetPlugin.id));
|
|
239
|
+
this.parent = targetPlugin;
|
|
240
|
+
this.el = targetPlugin.addTarget(plugin);
|
|
241
|
+
this.onMount();
|
|
242
|
+
return this.el;
|
|
243
|
+
}
|
|
244
|
+
this.filerobot.log("Not installing ".concat(callerPluginName));
|
|
245
|
+
var message = "Invalid target option given to ".concat(callerPluginName, ".");
|
|
246
|
+
if (typeof target === 'function') {
|
|
247
|
+
message += ' The given target is not a Plugin class. ' + 'Please check that you\'re not specifying a React Component instead of a plugin. ' + 'If you are using @scaleflex/widget-* packages directly, make sure you have only 1 version of @scaleflex/widget-core installed: ' + 'run `npm ls @scaleflex/widget-core` on the command line and verify that all the versions match and are deduped correctly.';
|
|
248
|
+
} else {
|
|
249
|
+
message += 'If you meant to target an HTML element, please make sure that the element exists. ' + 'Check that the <script> tag initializing Filerobot is right before the closing </body> tag at the end of the page. ' + 'If you meant to target a plugin, please confirm that your `import` statements or `require` calls are correct.';
|
|
250
|
+
}
|
|
251
|
+
throw new Error(message);
|
|
252
|
+
}
|
|
253
|
+
}, {
|
|
254
|
+
key: "render",
|
|
255
|
+
value: function render(state) {
|
|
256
|
+
throw new Error('Extend the render method to add your plugin to a DOM element');
|
|
257
|
+
}
|
|
258
|
+
}, {
|
|
259
|
+
key: "addTarget",
|
|
260
|
+
value: function addTarget(plugin) {
|
|
261
|
+
throw new Error('Extend the addTarget method to add your plugin to another plugin\'s target');
|
|
262
|
+
}
|
|
263
|
+
}, {
|
|
264
|
+
key: "unmount",
|
|
265
|
+
value: function unmount() {
|
|
266
|
+
var _this$root;
|
|
267
|
+
(_this$root = this.root) === null || _this$root === void 0 ? void 0 : _this$root.unmount();
|
|
268
|
+
}
|
|
269
|
+
}, {
|
|
270
|
+
key: "checkPluginTypeExistence",
|
|
271
|
+
value: function checkPluginTypeExistence() {
|
|
272
|
+
var pluginTypeToCheck = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
273
|
+
return this.filerobot.checkPluginTypeExistence(pluginTypeToCheck);
|
|
274
|
+
}
|
|
275
|
+
}, {
|
|
276
|
+
key: "checkPluginExistence",
|
|
277
|
+
value: function checkPluginExistence() {
|
|
278
|
+
var pluginIdToCheck = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
279
|
+
return this.filerobot.checkPluginExistence(pluginIdToCheck);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Called to get the plugin's reducer.
|
|
284
|
+
*/
|
|
285
|
+
}, {
|
|
286
|
+
key: "getPluginReducer",
|
|
287
|
+
value: function getPluginReducer() {}
|
|
288
|
+
}, {
|
|
289
|
+
key: "install",
|
|
290
|
+
value: function install() {}
|
|
291
|
+
}, {
|
|
292
|
+
key: "uninstall",
|
|
293
|
+
value: function uninstall() {
|
|
294
|
+
this.unmount();
|
|
295
|
+
}
|
|
296
|
+
}]);
|
|
297
|
+
}();
|
|
298
|
+
export { Plugin as default };
|
package/lib/Providers.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var _excluded = ["newOpts"];
|
|
2
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
5
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
7
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
8
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
9
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
10
|
+
import { createContext, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
11
|
+
import { Provider as StoreProvider } from 'react-redux';
|
|
12
|
+
import ThemeProvider from '@scaleflex/ui/theme';
|
|
13
|
+
import { StyleSheetManager } from 'styled-components';
|
|
14
|
+
import isPropValid from '@emotion/is-prop-valid';
|
|
15
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
|
+
export var FilerobotPackagesContext = /*#__PURE__*/createContext({});
|
|
17
|
+
export var ModalDispatcherContext = /*#__PURE__*/createContext(function (_state) {});
|
|
18
|
+
export var ModalDataContext = /*#__PURE__*/createContext({});
|
|
19
|
+
export var ContextMenuDispatcherContext = /*#__PURE__*/createContext(function (_state) {});
|
|
20
|
+
export var ContextMenuDataContext = /*#__PURE__*/createContext({});
|
|
21
|
+
export var VirtualListDispatcherContext = /*#__PURE__*/createContext(function (_state) {});
|
|
22
|
+
export var VirtualListDataContext = /*#__PURE__*/createContext({});
|
|
23
|
+
var Providers = function Providers(_ref) {
|
|
24
|
+
var filerobot = _ref.filerobot,
|
|
25
|
+
children = _ref.children,
|
|
26
|
+
onUiLoad = _ref.onUiLoad;
|
|
27
|
+
var _useState = useState({}),
|
|
28
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
29
|
+
modalData = _useState2[0],
|
|
30
|
+
setModalData = _useState2[1];
|
|
31
|
+
var _useState3 = useState({}),
|
|
32
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
33
|
+
contextMenuData = _useState4[0],
|
|
34
|
+
setContextMenuData = _useState4[1];
|
|
35
|
+
var _useState5 = useState({
|
|
36
|
+
apiRef: useRef(),
|
|
37
|
+
parentRef: useRef()
|
|
38
|
+
}),
|
|
39
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
40
|
+
virtualListData = _useState6[0],
|
|
41
|
+
setVirtualListData = _useState6[1];
|
|
42
|
+
var _useState7 = useState(function () {
|
|
43
|
+
return {
|
|
44
|
+
filerobot: filerobot,
|
|
45
|
+
plugins: filerobot.plugins
|
|
46
|
+
};
|
|
47
|
+
}),
|
|
48
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
49
|
+
packages = _useState8[0],
|
|
50
|
+
setPackages = _useState8[1];
|
|
51
|
+
var memoizedChildren = useMemo(function () {
|
|
52
|
+
return children;
|
|
53
|
+
}, [children]);
|
|
54
|
+
var memoizedPackages = useMemo(function () {
|
|
55
|
+
return packages;
|
|
56
|
+
}, [packages]);
|
|
57
|
+
var updatePackages = useCallback(function (newPackages) {
|
|
58
|
+
// Spreading the object for making sure it would cause re-render, although the event emits a new object everytime,
|
|
59
|
+
// but added it for making sure it'll always re-render.
|
|
60
|
+
var newOpts = newPackages.newOpts,
|
|
61
|
+
packages = _objectWithoutProperties(newPackages, _excluded);
|
|
62
|
+
setPackages(packages);
|
|
63
|
+
}, []);
|
|
64
|
+
useEffect(function () {
|
|
65
|
+
// Migrates the sync. react 17 render callback. to react 18
|
|
66
|
+
if (typeof onUiLoad === 'function') {
|
|
67
|
+
onUiLoad();
|
|
68
|
+
}
|
|
69
|
+
}, []);
|
|
70
|
+
useEffect(function () {
|
|
71
|
+
filerobot.on('opts-updated', updatePackages);
|
|
72
|
+
filerobot.on('plugins-updated', updatePackages);
|
|
73
|
+
return function () {
|
|
74
|
+
filerobot.off('opts-updated', updatePackages);
|
|
75
|
+
filerobot.off('plugins-updated', updatePackages);
|
|
76
|
+
};
|
|
77
|
+
}, [filerobot]);
|
|
78
|
+
return /*#__PURE__*/_jsx(StoreProvider, {
|
|
79
|
+
store: filerobot.store,
|
|
80
|
+
children: /*#__PURE__*/_jsx(ThemeProvider, {
|
|
81
|
+
theme: filerobot.opts.theme,
|
|
82
|
+
children: /*#__PURE__*/_jsx(StyleSheetManager, {
|
|
83
|
+
shouldForwardProp: function shouldForwardProp(propName, target) {
|
|
84
|
+
return typeof target === 'string' ? isPropValid(propName) : true;
|
|
85
|
+
},
|
|
86
|
+
children: /*#__PURE__*/_jsx(FilerobotPackagesContext.Provider, {
|
|
87
|
+
value: memoizedPackages,
|
|
88
|
+
children: /*#__PURE__*/_jsx(ModalDispatcherContext.Provider, {
|
|
89
|
+
value: setModalData,
|
|
90
|
+
children: /*#__PURE__*/_jsx(ModalDataContext.Provider, {
|
|
91
|
+
value: modalData,
|
|
92
|
+
children: /*#__PURE__*/_jsx(ContextMenuDispatcherContext.Provider, {
|
|
93
|
+
value: setContextMenuData,
|
|
94
|
+
children: /*#__PURE__*/_jsx(ContextMenuDataContext.Provider, {
|
|
95
|
+
value: contextMenuData,
|
|
96
|
+
children: /*#__PURE__*/_jsx(VirtualListDispatcherContext.Provider, {
|
|
97
|
+
value: setVirtualListData,
|
|
98
|
+
children: /*#__PURE__*/_jsx(VirtualListDataContext.Provider, {
|
|
99
|
+
value: virtualListData,
|
|
100
|
+
children: memoizedChildren
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
export default Providers;
|