@micromag/data 0.4.69 → 0.4.74

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.
Files changed (2) hide show
  1. package/es/index.js +915 -816
  2. package/package.json +8 -8
package/es/index.js CHANGED
@@ -1,126 +1,100 @@
1
- import React, { useMemo, useContext, useState, useCallback, useEffect, useRef } from 'react';
2
- import _createClass from '@babel/runtime/helpers/createClass';
3
- import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
4
- import _callSuper from '@babel/runtime/helpers/callSuper';
5
- import _inherits from '@babel/runtime/helpers/inherits';
6
- import _objectSpread from '@babel/runtime/helpers/objectSpread2';
1
+ import { c } from 'react/compiler-runtime';
2
+ import React, { useContext, useState, useCallback, useEffect, useRef, useMemo } from 'react';
7
3
  import { getJSON, getCSRFHeaders, postJSON } from '@folklore/fetch';
8
4
  import { generatePath } from '@folklore/routes';
9
5
  import queryString from 'query-string';
10
6
  import { jsx } from 'react/jsx-runtime';
11
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
12
7
  import { useVisitor, useStory } from '@micromag/core/contexts';
13
- import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
14
- import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
15
8
  import isString from 'lodash/isString';
16
9
 
17
- var Base = /*#__PURE__*/function () {
18
- function Base() {
19
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
20
- _classCallCheck(this, Base);
21
- this.options = _objectSpread(_objectSpread({
22
- routes: {}
23
- }, opts), {}, {
10
+ class Base {
11
+ constructor(opts = {}) {
12
+ this.options = {
13
+ routes: {},
14
+ ...opts,
24
15
  baseUrl: opts.baseUrl || 'https://micromag.ca/api'
16
+ };
17
+ }
18
+ requestGet(path, query = null) {
19
+ const finalQueryString = query !== null ? queryString.stringify(query, {
20
+ arrayFormat: 'bracket'
21
+ }) : null;
22
+ return getJSON(`${this.getFullUrl(path)}${finalQueryString !== null && finalQueryString.length > 0 ? `?${finalQueryString}` : ''}`, {
23
+ credentials: 'include',
24
+ headers: getCSRFHeaders()
25
25
  });
26
26
  }
27
- return _createClass(Base, [{
28
- key: "requestGet",
29
- value: function requestGet(path) {
30
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
31
- var finalQueryString = query !== null ? queryString.stringify(query, {
32
- arrayFormat: 'bracket'
33
- }) : null;
34
- return getJSON("".concat(this.getFullUrl(path)).concat(finalQueryString !== null && finalQueryString.length > 0 ? "?".concat(finalQueryString) : ''), {
35
- credentials: 'include',
36
- headers: getCSRFHeaders()
37
- });
38
- }
39
- }, {
40
- key: "requestPost",
41
- value: function requestPost(path, data) {
42
- return postJSON(this.getFullUrl(path), data, {
43
- credentials: 'include',
44
- headers: getCSRFHeaders()
45
- });
46
- }
47
- }, {
48
- key: "requestPut",
49
- value: function requestPut(path, data) {
50
- return postJSON(this.getFullUrl(path), _objectSpread({
51
- _method: 'PUT'
52
- }, data), {
53
- credentials: 'include',
54
- headers: getCSRFHeaders()
55
- });
56
- }
57
- }, {
58
- key: "requestDelete",
59
- value: function requestDelete(path) {
60
- return this.requestPost(path, {
61
- _method: 'DELETE'
62
- });
63
- }
64
- }, {
65
- key: "route",
66
- value: function route(_route, params) {
67
- var routes = this.options.routes;
68
- return generatePath(routes[_route] || _route, params);
69
- }
70
- }, {
71
- key: "getFullUrl",
72
- value: function getFullUrl(path) {
73
- var baseUrl = this.options.baseUrl;
74
- return "".concat(baseUrl.replace(/\/$/, ''), "/").concat(path.replace(/^\//, ''));
75
- }
76
- }]);
77
- }();
27
+ requestPost(path, data) {
28
+ return postJSON(this.getFullUrl(path), data, {
29
+ credentials: 'include',
30
+ headers: getCSRFHeaders()
31
+ });
32
+ }
33
+ requestPut(path, data) {
34
+ return postJSON(this.getFullUrl(path), {
35
+ _method: 'PUT',
36
+ ...data
37
+ }, {
38
+ credentials: 'include',
39
+ headers: getCSRFHeaders()
40
+ });
41
+ }
42
+ requestDelete(path) {
43
+ return this.requestPost(path, {
44
+ _method: 'DELETE'
45
+ });
46
+ }
47
+ route(route, params) {
48
+ const {
49
+ routes
50
+ } = this.options;
51
+ return generatePath(routes[route] || route, params);
52
+ }
53
+ getFullUrl(path) {
54
+ const {
55
+ baseUrl
56
+ } = this.options;
57
+ return `${baseUrl.replace(/\/$/, '')}/${path.replace(/^\//, '')}`;
58
+ }
59
+ }
78
60
 
79
- var ContributionsApi = /*#__PURE__*/function (_Base) {
80
- function ContributionsApi() {
81
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
82
- _classCallCheck(this, ContributionsApi);
83
- return _callSuper(this, ContributionsApi, [_objectSpread(_objectSpread({}, opts), {}, {
84
- routes: _objectSpread({
61
+ class ContributionsApi extends Base {
62
+ constructor(opts = {}) {
63
+ super({
64
+ ...opts,
65
+ routes: {
85
66
  index: '/contributions/:screen',
86
67
  store: '/contributions',
87
68
  update: '/contributions/:contribution',
88
- "delete": '/contributions/:contribution'
89
- }, opts.routes || null)
90
- })]);
91
- }
92
- _inherits(ContributionsApi, _Base);
93
- return _createClass(ContributionsApi, [{
94
- key: "get",
95
- value: function get(id) {
96
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
97
- var page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
98
- var count = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 10;
99
- var finalQuery = _objectSpread({}, query);
100
- if (page !== null) {
101
- finalQuery.page = page;
69
+ delete: '/contributions/:contribution',
70
+ ...(opts.routes || null)
102
71
  }
103
- if (count !== null) {
104
- finalQuery.count = count;
105
- }
106
- return this.requestGet(this.route('index', {
107
- screen: id
108
- }), finalQuery);
72
+ });
73
+ }
74
+ get(id, query = {}, page = 1, count = 10) {
75
+ const finalQuery = {
76
+ ...query
77
+ };
78
+ if (page !== null) {
79
+ finalQuery.page = page;
109
80
  }
110
- }, {
111
- key: "create",
112
- value: function create(data) {
113
- return this.requestPost(this.route('store'), data);
81
+ if (count !== null) {
82
+ finalQuery.count = count;
114
83
  }
115
- }]);
116
- }(Base);
84
+ return this.requestGet(this.route('index', {
85
+ screen: id
86
+ }), finalQuery);
87
+ }
88
+ create(data) {
89
+ return this.requestPost(this.route('store'), data);
90
+ }
91
+ }
117
92
 
118
- var MediasApi = /*#__PURE__*/function (_Base) {
119
- function MediasApi() {
120
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
121
- _classCallCheck(this, MediasApi);
122
- return _callSuper(this, MediasApi, [_objectSpread(_objectSpread({}, opts), {}, {
123
- routes: _objectSpread({
93
+ class MediasApi extends Base {
94
+ constructor(opts = {}) {
95
+ super({
96
+ ...opts,
97
+ routes: {
124
98
  index: 'medias',
125
99
  tags: 'medias/tags',
126
100
  authors: 'medias/authors',
@@ -128,189 +102,171 @@ var MediasApi = /*#__PURE__*/function (_Base) {
128
102
  show: 'medias/:media',
129
103
  store: 'medias',
130
104
  update: 'medias/:media',
131
- "delete": 'medias/:media'
132
- }, opts.routes || null)
133
- })]);
134
- }
135
- _inherits(MediasApi, _Base);
136
- return _createClass(MediasApi, [{
137
- key: "find",
138
- value: function find(id) {
139
- return this.requestGet(this.route('show', {
140
- media: id
141
- }));
142
- }
143
- }, {
144
- key: "get",
145
- value: function get() {
146
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
147
- var page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
148
- var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
149
- var finalQuery = _objectSpread({}, query);
150
- if (page !== null) {
151
- finalQuery.page = page;
152
- }
153
- if (count !== null) {
154
- finalQuery.count = count;
155
- }
156
- return this.requestGet(this.route('index'), finalQuery);
157
- }
158
- }, {
159
- key: "getTags",
160
- value: function getTags() {
161
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
162
- var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
163
- var finalQuery = _objectSpread({}, query);
164
- if (count !== null) {
165
- finalQuery.count = count;
105
+ delete: 'medias/:media',
106
+ ...(opts.routes || null)
166
107
  }
167
- return this.requestGet(this.route('tags'), finalQuery);
168
- }
169
- }, {
170
- key: "getAuthors",
171
- value: function getAuthors() {
172
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
173
- var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
174
- var finalQuery = _objectSpread({}, query);
175
- if (count !== null) {
176
- finalQuery.count = count;
177
- }
178
- return this.requestGet(this.route('authors'), finalQuery);
179
- }
180
- }, {
181
- key: "create",
182
- value: function create(data) {
183
- return this.requestPost(this.route('store'), data);
184
- }
185
- }, {
186
- key: "update",
187
- value: function update(id, data) {
188
- return this.requestPut(this.route('update', {
189
- media: id
190
- }), data);
108
+ });
109
+ }
110
+ find(id) {
111
+ return this.requestGet(this.route('show', {
112
+ media: id
113
+ }));
114
+ }
115
+ get(query = {}, page = 1, count = 10) {
116
+ const finalQuery = {
117
+ ...query
118
+ };
119
+ if (page !== null) {
120
+ finalQuery.page = page;
191
121
  }
192
- }, {
193
- key: "requestDeleteMedia",
194
- value: function requestDeleteMedia(id) {
195
- return this.requestPost(this.route('requestDelete', {
196
- media: id
197
- }));
122
+ if (count !== null) {
123
+ finalQuery.count = count;
198
124
  }
199
- }, {
200
- key: "delete",
201
- value: function _delete(id) {
202
- return this.requestDelete(this.route('delete', {
203
- media: id
204
- }));
125
+ return this.requestGet(this.route('index'), finalQuery);
126
+ }
127
+ getTags(query = {}, count = 10) {
128
+ const finalQuery = {
129
+ ...query
130
+ };
131
+ if (count !== null) {
132
+ finalQuery.count = count;
205
133
  }
206
- }, {
207
- key: "replace",
208
- value: function replace(id, data) {
209
- return this.requestPost(this.route('replace', {
210
- media: id
211
- }), data);
134
+ return this.requestGet(this.route('tags'), finalQuery);
135
+ }
136
+ getAuthors(query = {}, count = 10) {
137
+ const finalQuery = {
138
+ ...query
139
+ };
140
+ if (count !== null) {
141
+ finalQuery.count = count;
212
142
  }
213
- }]);
214
- }(Base);
143
+ return this.requestGet(this.route('authors'), finalQuery);
144
+ }
145
+ create(data) {
146
+ return this.requestPost(this.route('store'), data);
147
+ }
148
+ update(id, data) {
149
+ return this.requestPut(this.route('update', {
150
+ media: id
151
+ }), data);
152
+ }
153
+ requestDeleteMedia(id) {
154
+ return this.requestPost(this.route('requestDelete', {
155
+ media: id
156
+ }));
157
+ }
158
+ delete(id) {
159
+ return this.requestDelete(this.route('delete', {
160
+ media: id
161
+ }));
162
+ }
163
+ replace(id, data) {
164
+ return this.requestPost(this.route('replace', {
165
+ media: id
166
+ }), data);
167
+ }
168
+ }
215
169
 
216
- var QuizApi = /*#__PURE__*/function (_Base) {
217
- function QuizApi() {
218
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
219
- _classCallCheck(this, QuizApi);
220
- return _callSuper(this, QuizApi, [_objectSpread(_objectSpread({}, opts), {}, {
221
- routes: _objectSpread({
170
+ class QuizApi extends Base {
171
+ constructor(opts = {}) {
172
+ super({
173
+ ...opts,
174
+ routes: {
222
175
  results: '/quiz/:screen',
223
176
  store: '/quiz',
224
177
  update: '/quiz/:quiz',
225
- "delete": '/quiz/:quiz'
226
- }, opts.routes || null)
227
- })]);
178
+ delete: '/quiz/:quiz',
179
+ ...(opts.routes || null)
180
+ }
181
+ });
228
182
  }
229
- _inherits(QuizApi, _Base);
230
- return _createClass(QuizApi, [{
231
- key: "results",
232
- value: function results(screenId) {
233
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
234
- return this.requestGet(this.route('results', {
235
- screen: screenId
236
- }), query);
237
- }
238
- }, {
239
- key: "create",
240
- value: function create(data) {
241
- return this.requestPost(this.route('store'), data);
242
- }
243
- }]);
244
- }(Base);
183
+ results(screenId, query = {}) {
184
+ return this.requestGet(this.route('results', {
185
+ screen: screenId
186
+ }), query);
187
+ }
188
+ create(data) {
189
+ return this.requestPost(this.route('store'), data);
190
+ }
191
+ }
245
192
 
246
- var Api = /*#__PURE__*/function (_Base) {
247
- function Api() {
248
- var _this;
249
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
250
- _classCallCheck(this, Api);
251
- _this = _callSuper(this, Api, [opts]);
252
- _this.medias = new MediasApi(opts);
253
- _this.contributions = new ContributionsApi(opts);
254
- _this.quiz = new QuizApi(opts);
255
- return _this;
193
+ class Api extends Base {
194
+ constructor(opts = {}) {
195
+ super(opts);
196
+ this.medias = new MediasApi(opts);
197
+ this.contributions = new ContributionsApi(opts);
198
+ this.quiz = new QuizApi(opts);
256
199
  }
257
- _inherits(Api, _Base);
258
- return _createClass(Api);
259
- }(Base);
200
+ }
260
201
 
261
- /* eslint-disable react/jsx-props-no-spreading */
262
- var ApiContext = /*#__PURE__*/React.createContext(null);
263
- var useApi = function useApi() {
202
+ const ApiContext = /*#__PURE__*/React.createContext(null);
203
+ const useApi = () => {
264
204
  return useContext(ApiContext);
265
205
  };
266
- function ApiProvider(_ref) {
267
- var _ref$api = _ref.api,
268
- initialApi = _ref$api === void 0 ? null : _ref$api,
269
- _ref$baseUrl = _ref.baseUrl,
270
- baseUrl = _ref$baseUrl === void 0 ? undefined : _ref$baseUrl,
271
- children = _ref.children;
272
- var previousApi = useApi();
273
- var api = useMemo(function () {
274
- return initialApi || previousApi || new Api({
275
- baseUrl: baseUrl
276
- // baseUrl: 'https://micromag.studio.test/api',
206
+ function ApiProvider(t0) {
207
+ const $ = c(7);
208
+ const {
209
+ api: t1,
210
+ baseUrl: t2,
211
+ children
212
+ } = t0;
213
+ const initialApi = t1 === undefined ? null : t1;
214
+ const baseUrl = t2 === undefined ? undefined : t2;
215
+ const previousApi = useApi();
216
+ let t3;
217
+ if ($[0] !== baseUrl || $[1] !== initialApi || $[2] !== previousApi) {
218
+ t3 = initialApi || previousApi || new Api({
219
+ baseUrl
277
220
  });
278
- }, [previousApi, initialApi, baseUrl]);
279
- return /*#__PURE__*/jsx(ApiContext.Provider, {
280
- value: api,
281
- children: children
282
- });
221
+ $[0] = baseUrl;
222
+ $[1] = initialApi;
223
+ $[2] = previousApi;
224
+ $[3] = t3;
225
+ } else {
226
+ t3 = $[3];
227
+ }
228
+ const api = t3;
229
+ let t4;
230
+ if ($[4] !== api || $[5] !== children) {
231
+ t4 = /*#__PURE__*/jsx(ApiContext.Provider, {
232
+ value: api,
233
+ children: children
234
+ });
235
+ $[4] = api;
236
+ $[5] = children;
237
+ $[6] = t4;
238
+ } else {
239
+ t4 = $[6];
240
+ }
241
+ return t4;
283
242
  }
284
243
 
285
- var useContributionCreate = function useContributionCreate() {
286
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
287
- screenId = _ref.screenId,
288
- _ref$visitorId = _ref.visitorId,
289
- providedVisitorId = _ref$visitorId === void 0 ? null : _ref$visitorId,
290
- _ref$storyId = _ref.storyId,
291
- providedStoryId = _ref$storyId === void 0 ? null : _ref$storyId,
292
- _ref$onSuccess = _ref.onSuccess,
293
- onSuccess = _ref$onSuccess === void 0 ? null : _ref$onSuccess;
294
- var api = useApi();
295
- var _useState = useState(false),
296
- _useState2 = _slicedToArray(_useState, 2),
297
- creating = _useState2[0],
298
- setCreating = _useState2[1];
299
- var _ref2 = useVisitor() || {},
300
- visitorId = _ref2.id;
301
- var _ref3 = useStory() || {},
302
- storyId = _ref3.id,
303
- documentId = _ref3.document_id;
304
- var create = useCallback(function (data) {
244
+ const useContributionCreate = ({
245
+ screenId,
246
+ visitorId: providedVisitorId = null,
247
+ storyId: providedStoryId = null,
248
+ onSuccess = null
249
+ } = {}) => {
250
+ const api = useApi();
251
+ const [creating, setCreating] = useState(false);
252
+ const {
253
+ id: visitorId
254
+ } = useVisitor() || {};
255
+ const {
256
+ id: storyId,
257
+ document_id: documentId
258
+ } = useStory() || {};
259
+ const create = useCallback(data => {
305
260
  if (api === null) {
306
261
  return null;
307
262
  }
308
263
  setCreating(true);
309
- return api.contributions.create(_objectSpread({
264
+ return api.contributions.create({
310
265
  screen_id: screenId,
311
266
  visitor_id: providedVisitorId || visitorId,
312
- story_id: documentId || providedStoryId || storyId
313
- }, data)).then(function (response) {
267
+ story_id: documentId || providedStoryId || storyId,
268
+ ...data
269
+ }).then(response => {
314
270
  setCreating(false);
315
271
  if (onSuccess !== null) {
316
272
  onSuccess(response);
@@ -319,153 +275,165 @@ var useContributionCreate = function useContributionCreate() {
319
275
  });
320
276
  }, [api, setCreating, onSuccess, screenId, visitorId, storyId, providedVisitorId, providedStoryId]);
321
277
  return {
322
- create: create,
323
- creating: creating
278
+ create,
279
+ creating
324
280
  };
325
281
  };
326
282
 
327
- var useData = function useData(loadData) {
328
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
329
- _ref$initialData = _ref.initialData,
330
- initialData = _ref$initialData === void 0 ? null : _ref$initialData,
331
- _ref$autoload = _ref.autoload,
332
- autoload = _ref$autoload === void 0 ? true : _ref$autoload;
333
- var _useState = useState(false),
334
- _useState2 = _slicedToArray(_useState, 2),
335
- loading = _useState2[0],
336
- setLoading = _useState2[1];
337
- var _useState3 = useState(false),
338
- _useState4 = _slicedToArray(_useState3, 2),
339
- error = _useState4[0],
340
- setError = _useState4[1];
341
- var _useState5 = useState(initialData),
342
- _useState6 = _slicedToArray(_useState5, 2),
343
- data = _useState6[0],
344
- setData = _useState6[1];
345
- var load = useCallback(function () {
346
- var canceled = false;
347
- setLoading(true);
348
- var promise = loadData.apply(void 0, arguments).then(function (newData) {
349
- if (!canceled) {
350
- setData(newData);
283
+ const useData = (loadData, t0) => {
284
+ const $ = c(13);
285
+ let t1;
286
+ if ($[0] !== t0) {
287
+ t1 = t0 === undefined ? {} : t0;
288
+ $[0] = t0;
289
+ $[1] = t1;
290
+ } else {
291
+ t1 = $[1];
292
+ }
293
+ const {
294
+ initialData: t2,
295
+ autoload: t3
296
+ } = t1;
297
+ const initialData = t2 === undefined ? null : t2;
298
+ const autoload = t3 === undefined ? true : t3;
299
+ const [loading, setLoading] = useState(false);
300
+ const [error, setError] = useState(false);
301
+ const [data, setData] = useState(initialData);
302
+ let t4;
303
+ if ($[2] !== loadData) {
304
+ t4 = (...t5) => {
305
+ const args = t5;
306
+ let canceled = false;
307
+ setLoading(true);
308
+ const promise = loadData(...args).then(newData => {
309
+ if (!canceled) {
310
+ setData(newData);
311
+ setLoading(false);
312
+ }
313
+ return newData;
314
+ }).catch(newError => {
315
+ setError(newError);
351
316
  setLoading(false);
352
- }
353
- return newData;
354
- })["catch"](function (newError) {
355
- setError(newError);
356
- setLoading(false);
357
- });
358
- promise.cancel = function () {
359
- canceled = true;
360
- setLoading(false);
317
+ });
318
+ promise.cancel = () => {
319
+ canceled = true;
320
+ setLoading(false);
321
+ };
322
+ return promise;
361
323
  };
362
- return promise;
363
- }, [loadData, setLoading, setData]);
364
- useEffect(function () {
365
- var loader = null;
366
- if (autoload) {
367
- loader = load();
368
- }
369
- return function () {
370
- if (loader !== null) {
371
- loader.cancel();
324
+ $[2] = loadData;
325
+ $[3] = t4;
326
+ } else {
327
+ t4 = $[3];
328
+ }
329
+ const load = t4;
330
+ let t5;
331
+ let t6;
332
+ if ($[4] !== autoload || $[5] !== load) {
333
+ t5 = () => {
334
+ let loader = null;
335
+ if (autoload) {
336
+ loader = load();
372
337
  }
338
+ return () => {
339
+ if (loader !== null) {
340
+ loader.cancel();
341
+ }
342
+ };
343
+ };
344
+ t6 = [autoload, load];
345
+ $[4] = autoload;
346
+ $[5] = load;
347
+ $[6] = t5;
348
+ $[7] = t6;
349
+ } else {
350
+ t5 = $[6];
351
+ t6 = $[7];
352
+ }
353
+ useEffect(t5, t6);
354
+ let t7;
355
+ if ($[8] !== data || $[9] !== error || $[10] !== load || $[11] !== loading) {
356
+ t7 = {
357
+ data,
358
+ load,
359
+ loading,
360
+ error
373
361
  };
374
- }, [autoload, load]);
362
+ $[8] = data;
363
+ $[9] = error;
364
+ $[10] = load;
365
+ $[11] = loading;
366
+ $[12] = t7;
367
+ } else {
368
+ t7 = $[12];
369
+ }
370
+ return t7;
371
+ };
372
+
373
+ const useContributions = (options = null) => {
374
+ const {
375
+ screenId,
376
+ storyId: providedStoryId = null,
377
+ opts = {}
378
+ } = options || {};
379
+ const api = useApi();
380
+ const {
381
+ id: storyId,
382
+ document_id: documentId
383
+ } = useStory() || {};
384
+ const [defaultContributions] = useState([...new Array(10)].map((el, i) => ({
385
+ name: `Nom ${i + 1}`,
386
+ message: `Message ${i + 1}`
387
+ })));
388
+ const loader = useCallback(() => api !== null ? api.contributions.get(screenId, {
389
+ story_id: documentId || providedStoryId || storyId
390
+ }) : null, [api, screenId, documentId, providedStoryId, storyId]);
391
+ const {
392
+ data,
393
+ ...request
394
+ } = api !== null ? useData(loader, opts) : {
395
+ data: null
396
+ };
375
397
  return {
376
- data: data,
377
- load: load,
378
- loading: loading,
379
- error: error
398
+ contributions: data || defaultContributions,
399
+ ...request
380
400
  };
381
401
  };
382
402
 
383
- var _excluded$3 = ["data"];
384
- var useContributions = function useContributions() {
385
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
386
- var _ref = options || {},
387
- screenId = _ref.screenId,
388
- _ref$storyId = _ref.storyId,
389
- providedStoryId = _ref$storyId === void 0 ? null : _ref$storyId,
390
- _ref$opts = _ref.opts,
391
- opts = _ref$opts === void 0 ? {} : _ref$opts;
392
- var api = useApi();
393
- var _ref2 = useStory() || {},
394
- storyId = _ref2.id,
395
- documentId = _ref2.document_id;
396
- var _useState = useState(_toConsumableArray(new Array(10)).map(function (el, i) {
397
- return {
398
- name: "Nom ".concat(i + 1),
399
- message: "Message ".concat(i + 1)
400
- };
401
- })),
402
- _useState2 = _slicedToArray(_useState, 1),
403
- defaultContributions = _useState2[0];
404
- var loader = useCallback(function () {
405
- return api !== null ? api.contributions.get(screenId, {
406
- story_id: documentId || providedStoryId || storyId
407
- }) : null;
408
- }, [api, screenId, documentId, providedStoryId, storyId]);
409
- var _ref3 = api !== null ? useData(loader, opts) : {
410
- data: null
403
+ const useItems$1 = ({
404
+ getPage = null,
405
+ getItems = null,
406
+ page = null,
407
+ count = 10,
408
+ items: providedItems = null,
409
+ pages: initialPages = null,
410
+ getPageFromResponse = ({
411
+ meta: {
412
+ current_page: currentPage,
413
+ last_page: lastPage,
414
+ total
411
415
  },
412
- data = _ref3.data,
413
- request = _objectWithoutProperties(_ref3, _excluded$3);
414
- return _objectSpread({
415
- contributions: data || defaultContributions
416
- }, request);
417
- };
418
-
419
- var useItems$1 = function useItems(_ref) {
420
- var _ref$getPage = _ref.getPage,
421
- getPage = _ref$getPage === void 0 ? null : _ref$getPage,
422
- _ref$getItems = _ref.getItems,
423
- getItems = _ref$getItems === void 0 ? null : _ref$getItems,
424
- _ref$page = _ref.page,
425
- page = _ref$page === void 0 ? null : _ref$page,
426
- _ref$count = _ref.count,
427
- count = _ref$count === void 0 ? 10 : _ref$count,
428
- _ref$items = _ref.items,
429
- providedItems = _ref$items === void 0 ? null : _ref$items,
430
- _ref$pages = _ref.pages,
431
- initialPages = _ref$pages === void 0 ? null : _ref$pages,
432
- _ref$getPageFromRespo = _ref.getPageFromResponse,
433
- getPageFromResponse = _ref$getPageFromRespo === void 0 ? function (_ref2) {
434
- var _ref2$meta = _ref2.meta,
435
- currentPage = _ref2$meta.current_page,
436
- lastPage = _ref2$meta.last_page,
437
- total = _ref2$meta.total,
438
- items = _ref2.data;
439
- return {
440
- page: parseInt(currentPage, 10),
441
- lastPage: parseInt(lastPage, 10),
442
- total: parseInt(total, 10),
443
- items: items
444
- };
445
- } : _ref$getPageFromRespo,
446
- _ref$getItemsFromResp = _ref.getItemsFromResponse,
447
- getItemsFromResponse = _ref$getItemsFromResp === void 0 ? function (data) {
448
- return data;
449
- } : _ref$getItemsFromResp,
450
- _ref$onItemsLoaded = _ref.onItemsLoaded,
451
- onItemsLoaded = _ref$onItemsLoaded === void 0 ? null : _ref$onItemsLoaded,
452
- _ref$onPageLoaded = _ref.onPageLoaded,
453
- onPageLoaded = _ref$onPageLoaded === void 0 ? null : _ref$onPageLoaded,
454
- _ref$onLoaded = _ref.onLoaded,
455
- onLoaded = _ref$onLoaded === void 0 ? null : _ref$onLoaded,
456
- _ref$onError = _ref.onError,
457
- onError = _ref$onError === void 0 ? null : _ref$onError;
458
- var isPaginated = getPage !== null || initialPages !== null;
459
- var lastState = useRef(null);
460
- var initialState = useMemo(function () {
461
- var finalInitialPages = initialPages !== null ? initialPages.map(function (it) {
462
- return getPageFromResponse(it);
463
- }) : null;
416
+ data: items
417
+ }) => ({
418
+ page: parseInt(currentPage, 10),
419
+ lastPage: parseInt(lastPage, 10),
420
+ total: parseInt(total, 10),
421
+ items
422
+ }),
423
+ getItemsFromResponse = data => data,
424
+ onItemsLoaded = null,
425
+ onPageLoaded = null,
426
+ onLoaded = null,
427
+ onError = null
428
+ }) => {
429
+ const isPaginated = getPage !== null || initialPages !== null;
430
+ const lastState = useRef(null);
431
+ const initialState = useMemo(() => {
432
+ const finalInitialPages = initialPages !== null ? initialPages.map(it => getPageFromResponse(it)) : null;
464
433
  return {
465
- lastPage: finalInitialPages !== null ? finalInitialPages.reduce(function (currentLastPage, _ref3) {
466
- var initialLastPage = _ref3.lastPage;
467
- return initialLastPage > currentLastPage ? initialLastPage : currentLastPage;
468
- }, -1) : -1,
434
+ lastPage: finalInitialPages !== null ? finalInitialPages.reduce((currentLastPage, {
435
+ lastPage: initialLastPage
436
+ }) => initialLastPage > currentLastPage ? initialLastPage : currentLastPage, -1) : -1,
469
437
  total: finalInitialPages !== null ? finalInitialPages[0].total : (providedItems || []).length,
470
438
  loaded: providedItems !== null,
471
439
  loading: false,
@@ -473,26 +441,23 @@ var useItems$1 = function useItems(_ref) {
473
441
  items: null
474
442
  };
475
443
  }, [initialPages, providedItems]);
476
- var _useState = useState(initialState),
477
- _useState2 = _slicedToArray(_useState, 2),
478
- state = _useState2[0],
479
- setState = _useState2[1];
480
- var lastPage = state.lastPage,
481
- loaded = state.loaded,
482
- loading = state.loading,
483
- stateItems = state.items,
484
- pages = state.pages,
485
- total = state.total;
486
- var items = providedItems || (isPaginated && pages !== null ? pages.reduce(function (pagesItems, _ref4) {
487
- var pageItems = _ref4.items;
488
- return pagesItems.concat(pageItems);
489
- }, []) : stateItems) || null;
490
- var updateState = function updateState(update) {
491
- return setState(_objectSpread(_objectSpread({}, state), update));
492
- };
493
- var updateFromResponse = function updateFromResponse(response) {
494
- var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
495
- var reset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
444
+ const [state, setState] = useState(initialState);
445
+ const {
446
+ lastPage: lastPage_0,
447
+ loaded,
448
+ loading,
449
+ items: stateItems,
450
+ pages,
451
+ total: total_0
452
+ } = state;
453
+ const items_0 = providedItems || (isPaginated && pages !== null ? pages.reduce((pagesItems, {
454
+ items: pageItems
455
+ }) => pagesItems.concat(pageItems), []) : stateItems) || null;
456
+ const updateState = update => setState({
457
+ ...state,
458
+ ...update
459
+ });
460
+ const updateFromResponse = (response, error = null, reset = false) => {
496
461
  if (error !== null) {
497
462
  updateState({
498
463
  loaded: false,
@@ -501,10 +466,8 @@ var useItems$1 = function useItems(_ref) {
501
466
  throw error;
502
467
  }
503
468
  if (isPaginated) {
504
- var newPage = getPageFromResponse(response);
505
- var newPages = (reset ? [newPage] : [].concat(_toConsumableArray((pages || []).filter(function (it) {
506
- return it.page !== newPage.page;
507
- })), [newPage])).sort(function (a, b) {
469
+ const newPage = getPageFromResponse(response);
470
+ const newPages = (reset ? [newPage] : [...(pages || []).filter(it_0 => it_0.page !== newPage.page), newPage]).sort((a, b) => {
508
471
  if (a === b) {
509
472
  return 0;
510
473
  }
@@ -519,7 +482,7 @@ var useItems$1 = function useItems(_ref) {
519
482
  });
520
483
  return newPage;
521
484
  }
522
- var newItems = _toConsumableArray(getItemsFromResponse(response));
485
+ const newItems = [...getItemsFromResponse(response)];
523
486
  updateState({
524
487
  loaded: true,
525
488
  loading: false,
@@ -528,257 +491,256 @@ var useItems$1 = function useItems(_ref) {
528
491
  });
529
492
  return newItems;
530
493
  };
531
- var getNextPage = function getNextPage() {
532
- var allPages = lastPage !== -1 ? Array.call.apply(Array, [null].concat(_toConsumableArray(Array(lastPage)))).map(function (it, index) {
533
- return index + 1;
534
- }) : [];
535
- var remainingPages = allPages.filter(function (pageNumber) {
536
- return pages.findIndex(function (it) {
537
- return it.page === pageNumber;
538
- }) === -1;
539
- });
540
- var firstItem = remainingPages.length > 0 ? remainingPages.shift() : null;
494
+ const getNextPage = () => {
495
+ const allPages = lastPage_0 !== -1 ? Array.call(null, ...Array(lastPage_0)).map((it_1, index) => index + 1) : [];
496
+ const remainingPages = allPages.filter(pageNumber => pages.findIndex(it_2 => it_2.page === pageNumber) === -1);
497
+ const firstItem = remainingPages.length > 0 ? remainingPages.shift() : null;
541
498
  return firstItem !== null ? firstItem : null;
542
499
  };
543
- var loadItems = function loadItems(requestPage) {
500
+ const loadItems = requestPage => {
544
501
  updateState({
545
502
  loading: true
546
503
  });
547
- var canceled = false;
548
- var request = isPaginated ? getPage(requestPage, count) : getItems();
549
- var promise = request.then(function (response) {
550
- return !canceled ? updateFromResponse(response) : Promise.reject();
551
- })["catch"](function (error) {
552
- return !canceled ? updateFromResponse(null, error) : Promise.reject();
553
- }).then(function (response) {
504
+ let canceled = false;
505
+ const request = isPaginated ? getPage(requestPage, count) : getItems();
506
+ const promise = request.then(response_0 => !canceled ? updateFromResponse(response_0) : Promise.reject()).catch(error_0 => !canceled ? updateFromResponse(null, error_0) : Promise.reject()).then(response_1 => {
554
507
  if (isPaginated && onPageLoaded !== null) {
555
- onPageLoaded(response);
508
+ onPageLoaded(response_1);
556
509
  } else if (!isPaginated && onItemsLoaded !== null) {
557
- onItemsLoaded(response);
510
+ onItemsLoaded(response_1);
558
511
  }
559
512
  if (onLoaded !== null) {
560
- onLoaded(response);
513
+ onLoaded(response_1);
561
514
  }
562
- return response;
563
- })["catch"](function (error) {
515
+ return response_1;
516
+ }).catch(error_1 => {
564
517
  if (!canceled && onError !== null) {
565
- onError(error);
518
+ onError(error_1);
566
519
  }
567
520
  });
568
- promise.cancel = function () {
521
+ promise.cancel = () => {
569
522
  canceled = true;
570
523
  };
571
524
  return promise;
572
525
  };
573
- var loadPage = function loadPage(pageToLoad) {
526
+ const loadPage = pageToLoad => {
574
527
  if (loading) {
575
528
  return Promise.reject();
576
529
  }
577
- if (pages.find(function (it) {
578
- return it.page === pageToLoad;
579
- }) !== -1) {
530
+ if (pages.find(it_3 => it_3.page === pageToLoad) !== -1) {
580
531
  return Promise.reject();
581
532
  }
582
533
  return loadItems(pageToLoad);
583
534
  };
584
- var loadNextPage = function loadNextPage() {
535
+ const loadNextPage = () => {
585
536
  if (loading) {
586
537
  return Promise.reject();
587
538
  }
588
- var nextPage = getNextPage();
539
+ const nextPage = getNextPage();
589
540
  return nextPage !== null ? loadItems(nextPage) : Promise.resolve();
590
541
  };
591
- useEffect(function () {
592
- var hadState = lastState.current !== null;
542
+ useEffect(() => {
543
+ const hadState = lastState.current !== null;
593
544
  lastState.current = initialState;
594
545
  if (hadState) {
595
546
  setState(initialState);
596
547
  }
597
548
  }, [initialState]);
598
- useEffect(function () {
549
+ useEffect(() => {
599
550
  if (getPage === null && getItems === null || providedItems !== null) {
600
- return function () {};
551
+ return () => {};
601
552
  }
602
- var loadPromise = null;
603
- var pageToLoad = isPaginated && initialPages === null && page === null ? 1 : page;
604
- if (!isPaginated || pageToLoad !== null) {
605
- loadPromise = loadItems(pageToLoad);
553
+ let loadPromise = null;
554
+ const pageToLoad_0 = isPaginated && initialPages === null && page === null ? 1 : page;
555
+ if (!isPaginated || pageToLoad_0 !== null) {
556
+ loadPromise = loadItems(pageToLoad_0);
606
557
  }
607
- return function () {
558
+ return () => {
608
559
  if (loadPromise !== null) {
609
560
  loadPromise.cancel();
610
561
  }
611
562
  };
612
563
  }, [getPage, getItems, page]);
613
- var currentPage = isPaginated && pages !== null ? pages.find(function (_ref5) {
614
- var pageNumber = _ref5.page;
615
- return parseInt(pageNumber, 10) === parseInt(page, 10);
616
- }) || null : null;
564
+ const currentPage_0 = isPaginated && pages !== null ? pages.find(({
565
+ page: pageNumber_0
566
+ }) => parseInt(pageNumber_0, 10) === parseInt(page, 10)) || null : null;
617
567
  return {
618
- items: items,
619
- pages: pages,
620
- pageItems: currentPage !== null ? currentPage.items : null,
621
- total: total,
622
- lastPage: lastPage,
623
- loaded: loaded,
624
- allLoaded: !isPaginated && loaded || lastPage !== -1 && isPaginated && pages.length === lastPage,
625
- loading: loading,
626
- loadNextPage: loadNextPage,
627
- loadPage: loadPage
568
+ items: items_0,
569
+ pages,
570
+ pageItems: currentPage_0 !== null ? currentPage_0.items : null,
571
+ total: total_0,
572
+ lastPage: lastPage_0,
573
+ loaded,
574
+ allLoaded: !isPaginated && loaded || lastPage_0 !== -1 && isPaginated && pages.length === lastPage_0,
575
+ loading,
576
+ loadNextPage,
577
+ loadPage
628
578
  };
629
579
  };
630
580
 
631
- var _excluded$2 = ["data"];
632
- var useMedia = function useMedia(id, opts) {
633
- var api = useApi();
634
- var loader = useCallback(function () {
635
- return api.medias.find(id);
636
- }, [api, id]);
637
- var _useData = useData(loader, opts),
638
- data = _useData.data,
639
- request = _objectWithoutProperties(_useData, _excluded$2);
640
- return _objectSpread({
641
- story: data
642
- }, request);
581
+ const useMedia = (id, opts) => {
582
+ const $ = c(9);
583
+ const api = useApi();
584
+ let t0;
585
+ if ($[0] !== api.medias || $[1] !== id) {
586
+ t0 = () => api.medias.find(id);
587
+ $[0] = api.medias;
588
+ $[1] = id;
589
+ $[2] = t0;
590
+ } else {
591
+ t0 = $[2];
592
+ }
593
+ const loader = t0;
594
+ const t1 = useData(loader, opts);
595
+ let data;
596
+ let request;
597
+ if ($[3] !== t1) {
598
+ ({
599
+ data,
600
+ ...request
601
+ } = t1);
602
+ $[3] = t1;
603
+ $[4] = data;
604
+ $[5] = request;
605
+ } else {
606
+ data = $[4];
607
+ request = $[5];
608
+ }
609
+ let t2;
610
+ if ($[6] !== data || $[7] !== request) {
611
+ t2 = {
612
+ story: data,
613
+ ...request
614
+ };
615
+ $[6] = data;
616
+ $[7] = request;
617
+ $[8] = t2;
618
+ } else {
619
+ t2 = $[8];
620
+ }
621
+ return t2;
643
622
  };
644
623
 
645
- // import { useCallback } from 'react';
646
-
647
624
  // import useItems from './useItems';
648
625
 
649
626
  // eslint-disable-next-line
650
- var useMediaAuthors = function useMediaAuthors() {
651
- useApi(); // eslint-disable-line
652
- // console.log('api', api); // eslint-disable-line
653
- // const getItems = useCallback(() => api.medias.getAuthors(query, count), [api, query, count]);
654
- // const { items, pageItems, ...request } = useItems({
655
- // getItems,
656
- // ...opts,
657
- // });
658
- return {
659
- authors: []
660
- // ...request,
661
- };
627
+ const useMediaAuthors = (t0, t1, opts) => {
628
+ const $ = c(1);
629
+ useApi();
630
+ let t2;
631
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
632
+ t2 = {
633
+ authors: []
634
+ };
635
+ $[0] = t2;
636
+ } else {
637
+ t2 = $[0];
638
+ }
639
+ return t2;
662
640
  };
663
641
 
664
- var useMediaCreate = function useMediaCreate() {
665
- var _useState = useState(false),
666
- _useState2 = _slicedToArray(_useState, 2),
667
- creating = _useState2[0],
668
- setCreating = _useState2[1];
669
- var api = useApi();
670
- var create = useCallback(function (data) {
671
- setCreating(true);
672
- return api.medias.create(data).then(function (response) {
673
- setCreating(false);
674
- return response;
675
- });
676
- }, [api, setCreating]);
677
- return {
678
- create: create,
679
- creating: creating
680
- };
642
+ const useMediaCreate = () => {
643
+ const $ = c(5);
644
+ const [creating, setCreating] = useState(false);
645
+ const api = useApi();
646
+ let t0;
647
+ if ($[0] !== api) {
648
+ t0 = data => {
649
+ setCreating(true);
650
+ return api.medias.create(data).then(response => {
651
+ setCreating(false);
652
+ return response;
653
+ });
654
+ };
655
+ $[0] = api;
656
+ $[1] = t0;
657
+ } else {
658
+ t0 = $[1];
659
+ }
660
+ const create = t0;
661
+ let t1;
662
+ if ($[2] !== create || $[3] !== creating) {
663
+ t1 = {
664
+ create,
665
+ creating
666
+ };
667
+ $[2] = create;
668
+ $[3] = creating;
669
+ $[4] = t1;
670
+ } else {
671
+ t1 = $[4];
672
+ }
673
+ return t1;
681
674
  };
682
675
 
683
- var useItems = function useItems(_ref) {
684
- var _ref$getPage = _ref.getPage,
685
- getPage = _ref$getPage === void 0 ? null : _ref$getPage,
686
- _ref$page = _ref.page,
687
- page = _ref$page === void 0 ? 1 : _ref$page,
688
- _ref$count = _ref.count,
689
- count = _ref$count === void 0 ? 10 : _ref$count,
690
- _ref$query = _ref.query,
691
- pageQuery = _ref$query === void 0 ? null : _ref$query,
692
- _ref$pages = _ref.pages,
693
- startingPages = _ref$pages === void 0 ? null : _ref$pages,
694
- _ref$getPageFromRespo = _ref.getPageFromResponse,
695
- getPageFromResponse = _ref$getPageFromRespo === void 0 ? function (newPage) {
696
- return newPage;
697
- } : _ref$getPageFromRespo,
698
- _ref$getPagination = _ref.getPagination,
699
- getPagination = _ref$getPagination === void 0 ? function () {
700
- var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
701
- cp = _ref2.current_page,
702
- pp = _ref2.per_page,
703
- lp = _ref2.last_page,
704
- total = _ref2.total;
705
- return {
706
- pageNumber: cp,
707
- pageCount: pp,
708
- lastPage: lp,
709
- total: total
710
- };
711
- } : _ref$getPagination,
712
- _ref$onLoaded = _ref.onLoaded,
713
- onLoaded = _ref$onLoaded === void 0 ? null : _ref$onLoaded,
714
- _ref$onError = _ref.onError,
715
- onError = _ref$onError === void 0 ? null : _ref$onError;
676
+ const useItems = ({
677
+ getPage = null,
678
+ page = 1,
679
+ count = 10,
680
+ query: pageQuery = null,
681
+ // string or object
682
+ pages: startingPages = null,
683
+ getPageFromResponse = newPage => newPage,
684
+ getPagination = ({
685
+ current_page: cp,
686
+ per_page: pp,
687
+ last_page: lp,
688
+ total
689
+ } = {}) => ({
690
+ pageNumber: cp,
691
+ pageCount: pp,
692
+ lastPage: lp,
693
+ total
694
+ }),
695
+ onLoaded = null,
696
+ onError = null
697
+ }) => {
716
698
  // Pagination
717
- var _useState = useState(page !== null),
718
- _useState2 = _slicedToArray(_useState, 2),
719
- paginated = _useState2[0],
720
- setPaginated = _useState2[1];
721
- var _useState3 = useState(null),
722
- _useState4 = _slicedToArray(_useState3, 2),
723
- pagination = _useState4[0],
724
- setPagination = _useState4[1];
725
- var _getPagination = getPagination(pagination || {}),
726
- _getPagination$pageNu = _getPagination.pageNumber,
727
- pageNumber = _getPagination$pageNu === void 0 ? page : _getPagination$pageNu,
728
- _getPagination$pageCo = _getPagination.pageCount,
729
- pageCount = _getPagination$pageCo === void 0 ? count : _getPagination$pageCo,
730
- _getPagination$lastPa = _getPagination.lastPage,
731
- lastPage = _getPagination$lastPa === void 0 ? null : _getPagination$lastPa,
732
- _getPagination$total = _getPagination.total,
733
- total = _getPagination$total === void 0 ? null : _getPagination$total;
734
- var _useMemo = useMemo(function () {
735
- return (startingPages || []).reduce(function (paginatedData, it) {
736
- var _ref3 = it || {},
737
- items = _ref3.data,
738
- currentPagination = _ref3.pagination;
739
- // eslint-disable-next-line no-param-reassign
740
- paginatedData.data = paginatedData.data.concat(items);
741
- // eslint-disable-next-line no-param-reassign
742
- paginatedData.pagination = currentPagination;
743
- return paginatedData;
744
- }, {
745
- data: [],
746
- pagination: {}
747
- });
748
- }, [startingPages]),
749
- initialPages = _useMemo.data,
750
- initialPagination = _useMemo.pagination;
751
- var _useState5 = useState(startingPages === null),
752
- _useState6 = _slicedToArray(_useState5, 2),
753
- canLoad = _useState6[0],
754
- setCanLoad = _useState6[1];
755
- var _useState7 = useState(false),
756
- _useState8 = _slicedToArray(_useState7, 2),
757
- loading = _useState8[0],
758
- setLoading = _useState8[1];
699
+ const [paginated, setPaginated] = useState(page !== null);
700
+ const [pagination, setPagination] = useState(null);
701
+ const {
702
+ pageNumber = page,
703
+ pageCount = count,
704
+ lastPage = null,
705
+ total: total_0 = null
706
+ } = getPagination(pagination || {});
707
+ const {
708
+ data: initialPages,
709
+ pagination: initialPagination
710
+ } = useMemo(() => (startingPages || []).reduce((paginatedData, it) => {
711
+ const {
712
+ data: items,
713
+ pagination: currentPagination
714
+ } = it || {};
715
+ // eslint-disable-next-line no-param-reassign
716
+ paginatedData.data = paginatedData.data.concat(items);
717
+ // eslint-disable-next-line no-param-reassign
718
+ paginatedData.pagination = currentPagination;
719
+ return paginatedData;
720
+ }, {
721
+ data: [],
722
+ pagination: {}
723
+ }), [startingPages]);
724
+ const [canLoad, setCanLoad] = useState(startingPages === null);
725
+ const [loading, setLoading] = useState(false);
759
726
 
760
727
  // Query
761
- var query = useMemo(function () {
762
- return _objectSpread({}, isString(pageQuery) ? queryString.parse(pageQuery || null, {
728
+ const query = useMemo(() => ({
729
+ ...(isString(pageQuery) ? queryString.parse(pageQuery || null, {
763
730
  arrayFormat: 'bracket'
764
- }) : pageQuery);
765
- }, [pageQuery]);
731
+ }) : pageQuery)
732
+ }), [pageQuery]);
766
733
 
767
734
  // Items
768
- var _useState9 = useState(null),
769
- _useState0 = _slicedToArray(_useState9, 2),
770
- items = _useState0[0],
771
- setItems = _useState0[1];
772
- var getPages = useCallback(function (newQuery, newPageNumber, newPageCount) {
773
- return getPage(newQuery, newPageNumber, newPageCount);
774
- }, [getPage]);
735
+ const [items_0, setItems] = useState(null);
736
+ const getPages = useCallback((newQuery, newPageNumber, newPageCount) => getPage(newQuery, newPageNumber, newPageCount), [getPage]);
775
737
 
776
738
  // Api has changed, reset to beginning
777
- useEffect(function () {
739
+ useEffect(() => {
778
740
  setItems(initialPages);
779
741
  setPagination(initialPagination);
780
742
  }, [getPages, setItems, setPagination]);
781
- useEffect(function () {
743
+ useEffect(() => {
782
744
  // eslint-disable-next-line
783
745
  // console.log('try to load');
784
746
  if (!canLoad || loading || lastPage !== null && pageNumber > lastPage) {
@@ -790,33 +752,28 @@ var useItems = function useItems(_ref) {
790
752
  setLoading(true);
791
753
  setCanLoad(false);
792
754
  // TODO: make this a cancellable promise
793
- getPages(query, pageNumber, pageCount).then(function (response) {
794
- return getPageFromResponse(response);
795
- }).then(function (response) {
796
- var _ref4 = response || {},
797
- _ref4$data = _ref4.data,
798
- data = _ref4$data === void 0 ? null : _ref4$data,
799
- _ref4$meta = _ref4.meta,
800
- meta = _ref4$meta === void 0 ? null : _ref4$meta;
755
+ getPages(query, pageNumber, pageCount).then(response => getPageFromResponse(response)).then(response_0 => {
756
+ const {
757
+ data = null,
758
+ meta = null
759
+ } = response_0 || {};
801
760
  // console.log('response --- ', response);
802
761
  // This is not a paginated list so we dont care anymore
803
762
  if (data === null && meta === null) {
804
- setItems(response);
763
+ setItems(response_0);
805
764
  setPaginated(false);
806
765
  } else {
807
- setItems(function (old) {
808
- return [].concat(_toConsumableArray(old || null), _toConsumableArray(data));
809
- });
766
+ setItems(old => [...(old || null), ...data]);
810
767
  setPagination(meta);
811
768
  setPaginated(true);
812
769
  }
813
- return response;
814
- }).then(function (response) {
770
+ return response_0;
771
+ }).then(response_1 => {
815
772
  setLoading(false);
816
773
  if (onLoaded !== null) {
817
- onLoaded(response);
774
+ onLoaded(response_1);
818
775
  }
819
- })["catch"](function (e) {
776
+ }).catch(e => {
820
777
  // Error is real
821
778
  setLoading(false);
822
779
  if (onError !== null) {
@@ -824,229 +781,358 @@ var useItems = function useItems(_ref) {
824
781
  }
825
782
  });
826
783
  }, [query, pageNumber, canLoad, getPages, setLoading, setItems, setPagination, onLoaded, onError]);
827
- var reset = useCallback(function () {
784
+ const reset = useCallback(() => {
828
785
  setItems([]);
829
786
  setPagination(null);
830
787
  setCanLoad(true);
831
788
  }, [setItems, setPagination, setCanLoad]);
832
789
 
833
790
  // Resets the game, "natural" refresh
834
- var onQueryChange = useEffect(function () {
791
+ const onQueryChange = useEffect(() => {
835
792
  reset();
836
793
  }, [query, page, count, reset]);
837
794
 
838
795
  // Handle to Load next
839
- var loadNextPage = useCallback(function () {
796
+ const loadNextPage = useCallback(() => {
840
797
  if (!loading && pageNumber < lastPage) {
841
- var params = _objectSpread(_objectSpread({}, pagination), {}, {
798
+ const params = {
799
+ ...pagination,
842
800
  current_page: pageNumber + 1,
843
801
  per_page: pageCount
844
- });
802
+ };
845
803
  setPagination(params);
846
804
  setCanLoad(true);
847
805
  }
848
806
  }, [query, pagination, pageNumber, pageCount, loading, lastPage, onQueryChange, setCanLoad]);
849
- var disabled = (items || []).length === 0 || loading || pageNumber >= lastPage || lastPage === null || lastPage === 1;
850
- var regularLoaded = !paginated && items !== null;
851
- var paginatedLoaded = !loading && items !== null && (items.length === total || pageNumber >= lastPage);
807
+ const disabled = (items_0 || []).length === 0 || loading || pageNumber >= lastPage || lastPage === null || lastPage === 1;
808
+ const regularLoaded = !paginated && items_0 !== null;
809
+ const paginatedLoaded = !loading && items_0 !== null && (items_0.length === total_0 || pageNumber >= lastPage);
852
810
  return {
853
- items: items,
854
- total: total,
811
+ items: items_0,
812
+ total: total_0,
855
813
  page: pageNumber,
856
814
  count: pageCount,
857
- lastPage: lastPage,
858
- loading: loading,
815
+ lastPage,
816
+ loading,
859
817
  loaded: !loading,
860
818
  allLoaded: regularLoaded || paginatedLoaded,
861
- disabled: disabled,
862
- loadNextPage: loadNextPage,
863
- reset: reset
819
+ disabled,
820
+ loadNextPage,
821
+ reset
864
822
  };
865
823
  };
866
824
 
867
- var useMedias = function useMedias() {
868
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
869
- var page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
870
- var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
871
- var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
872
- var api = useApi();
873
- var getPage = useCallback(function (newQuery) {
874
- var requestedPage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
875
- var requestedCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
876
- return api.medias.get(newQuery, requestedPage, requestedCount);
877
- }, [api]);
878
- return useItems(_objectSpread({
879
- getPage: getPage,
880
- query: query,
881
- page: page,
882
- count: count
883
- }, opts));
825
+ const useMedias = (t0, t1, t2, t3) => {
826
+ const $ = c(8);
827
+ const query = t0 === undefined ? null : t0;
828
+ const page = t1 === undefined ? 1 : t1;
829
+ const count = t2 === undefined ? 10 : t2;
830
+ const opts = t3 === undefined ? null : t3;
831
+ const api = useApi();
832
+ let t4;
833
+ if ($[0] !== api) {
834
+ t4 = (newQuery, t5, t6) => {
835
+ const requestedPage = t5 === undefined ? null : t5;
836
+ const requestedCount = t6 === undefined ? null : t6;
837
+ return api.medias.get(newQuery, requestedPage, requestedCount);
838
+ };
839
+ $[0] = api;
840
+ $[1] = t4;
841
+ } else {
842
+ t4 = $[1];
843
+ }
844
+ const getPage = t4;
845
+ let t5;
846
+ if ($[2] !== count || $[3] !== getPage || $[4] !== opts || $[5] !== page || $[6] !== query) {
847
+ t5 = {
848
+ getPage,
849
+ query,
850
+ page,
851
+ count,
852
+ ...opts
853
+ };
854
+ $[2] = count;
855
+ $[3] = getPage;
856
+ $[4] = opts;
857
+ $[5] = page;
858
+ $[6] = query;
859
+ $[7] = t5;
860
+ } else {
861
+ t5 = $[7];
862
+ }
863
+ return useItems(t5);
884
864
  };
885
865
 
886
- var useMediasRecent = function useMediasRecent(opts) {
887
- var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'media-gallery-recent-searches';
888
- var createSearch = useCallback(function (value) {
889
- if (typeof window !== 'undefined' && value) {
890
- var recent = window.localStorage.getItem(key) || null;
891
- var current = recent !== null ? JSON.parse(recent || '[]') : [];
892
- var encoded = JSON.stringify([value].concat(_toConsumableArray(current)));
893
- window.localStorage.setItem(key, encoded);
894
- return true;
895
- }
896
- return false;
897
- }, [key]);
898
- var getSearches = useCallback(function () {
899
- var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5;
900
- if (typeof window !== 'undefined') {
901
- var recent = window.localStorage.getItem(key) || null;
902
- var current = recent !== null ? JSON.parse(recent || '[]') : [];
903
- return current.slice(0, count);
904
- }
905
- return [];
906
- }, [key]);
907
- return {
908
- createSearch: createSearch,
909
- getSearches: getSearches
910
- };
866
+ const useMediasRecent = (opts, t0) => {
867
+ const $ = c(7);
868
+ const key = t0 === undefined ? "media-gallery-recent-searches" : t0;
869
+ let t1;
870
+ if ($[0] !== key) {
871
+ t1 = value => {
872
+ if (typeof window !== "undefined" && value) {
873
+ const recent = window.localStorage.getItem(key) || null;
874
+ const current = recent !== null ? JSON.parse(recent || "[]") : [];
875
+ const encoded = JSON.stringify([value, ...current]);
876
+ window.localStorage.setItem(key, encoded);
877
+ return true;
878
+ }
879
+ return false;
880
+ };
881
+ $[0] = key;
882
+ $[1] = t1;
883
+ } else {
884
+ t1 = $[1];
885
+ }
886
+ const createSearch = t1;
887
+ let t2;
888
+ if ($[2] !== key) {
889
+ t2 = t3 => {
890
+ const count = t3 === undefined ? 5 : t3;
891
+ if (typeof window !== "undefined") {
892
+ const recent_0 = window.localStorage.getItem(key) || null;
893
+ const current_0 = recent_0 !== null ? JSON.parse(recent_0 || "[]") : [];
894
+ return current_0.slice(0, count);
895
+ }
896
+ return [];
897
+ };
898
+ $[2] = key;
899
+ $[3] = t2;
900
+ } else {
901
+ t2 = $[3];
902
+ }
903
+ const getSearches = t2;
904
+ let t3;
905
+ if ($[4] !== createSearch || $[5] !== getSearches) {
906
+ t3 = {
907
+ createSearch,
908
+ getSearches
909
+ };
910
+ $[4] = createSearch;
911
+ $[5] = getSearches;
912
+ $[6] = t3;
913
+ } else {
914
+ t3 = $[6];
915
+ }
916
+ return t3;
911
917
  };
912
918
 
913
- var _excluded$1 = ["items", "pageItems"];
914
- var useMediaTags = function useMediaTags() {
915
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
916
- var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
917
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
918
- var api = useApi();
919
- var getItems = useCallback(function () {
920
- return api.medias.getTags(query, count);
921
- }, [api, query, count]);
922
- var _useItems = useItems$1(_objectSpread({
923
- getItems: getItems
924
- }, opts)),
925
- items = _useItems.items;
926
- _useItems.pageItems;
927
- var request = _objectWithoutProperties(_useItems, _excluded$1);
928
- return _objectSpread({
929
- tags: items
930
- }, request);
919
+ const useMediaTags = (t0, t1, t2) => {
920
+ const $ = c(13);
921
+ const query = t0 === undefined ? null : t0;
922
+ const count = t1 === undefined ? 5 : t1;
923
+ const opts = t2 === undefined ? null : t2;
924
+ const api = useApi();
925
+ let t3;
926
+ if ($[0] !== api || $[1] !== count || $[2] !== query) {
927
+ t3 = () => api.medias.getTags(query, count);
928
+ $[0] = api;
929
+ $[1] = count;
930
+ $[2] = query;
931
+ $[3] = t3;
932
+ } else {
933
+ t3 = $[3];
934
+ }
935
+ const getItems = t3;
936
+ let t4;
937
+ if ($[4] !== getItems || $[5] !== opts) {
938
+ t4 = {
939
+ getItems,
940
+ ...opts
941
+ };
942
+ $[4] = getItems;
943
+ $[5] = opts;
944
+ $[6] = t4;
945
+ } else {
946
+ t4 = $[6];
947
+ }
948
+ const t5 = useItems$1(t4);
949
+ let items;
950
+ let request;
951
+ if ($[7] !== t5) {
952
+ const {
953
+ items: t6,
954
+ pageItems,
955
+ ...t7
956
+ } = t5;
957
+ items = t6;
958
+ request = t7;
959
+ $[7] = t5;
960
+ $[8] = items;
961
+ $[9] = request;
962
+ } else {
963
+ items = $[8];
964
+ request = $[9];
965
+ }
966
+ let t6;
967
+ if ($[10] !== items || $[11] !== request) {
968
+ t6 = {
969
+ tags: items,
970
+ ...request
971
+ };
972
+ $[10] = items;
973
+ $[11] = request;
974
+ $[12] = t6;
975
+ } else {
976
+ t6 = $[12];
977
+ }
978
+ return t6;
931
979
  };
932
980
 
933
- var useMediaUpdate = function useMediaUpdate() {
934
- var _useState = useState(false),
935
- _useState2 = _slicedToArray(_useState, 2),
936
- updating = _useState2[0],
937
- setUpdating = _useState2[1];
938
- var api = useApi();
939
- var update = useCallback(function (id, data) {
940
- setUpdating(true);
941
- return api.medias.update(id, data).then(function (response) {
942
- setUpdating(false);
943
- return response;
944
- });
945
- }, [api, setUpdating]);
946
- return {
947
- update: update,
948
- updating: updating
949
- };
981
+ const useMediaUpdate = () => {
982
+ const $ = c(5);
983
+ const [updating, setUpdating] = useState(false);
984
+ const api = useApi();
985
+ let t0;
986
+ if ($[0] !== api) {
987
+ t0 = (id, data) => {
988
+ setUpdating(true);
989
+ return api.medias.update(id, data).then(response => {
990
+ setUpdating(false);
991
+ return response;
992
+ });
993
+ };
994
+ $[0] = api;
995
+ $[1] = t0;
996
+ } else {
997
+ t0 = $[1];
998
+ }
999
+ const update = t0;
1000
+ let t1;
1001
+ if ($[2] !== update || $[3] !== updating) {
1002
+ t1 = {
1003
+ update,
1004
+ updating
1005
+ };
1006
+ $[2] = update;
1007
+ $[3] = updating;
1008
+ $[4] = t1;
1009
+ } else {
1010
+ t1 = $[4];
1011
+ }
1012
+ return t1;
950
1013
  };
951
1014
 
952
- var useMediaRequestDelete = function useMediaRequestDelete() {
953
- var _useState = useState(false),
954
- _useState2 = _slicedToArray(_useState, 2),
955
- requesting = _useState2[0],
956
- setRequesting = _useState2[1];
957
- var api = useApi();
958
- var requestDeleteMedia = useCallback(function (id) {
959
- setRequesting(true);
960
- return api.medias.requestDeleteMedia(id).then(function (response) {
961
- setRequesting(false);
962
- return response;
963
- });
964
- }, [api, setRequesting]);
965
- return {
966
- requestDeleteMedia: requestDeleteMedia,
967
- requesting: requesting
968
- };
1015
+ const useMediaRequestDelete = () => {
1016
+ const $ = c(5);
1017
+ const [requesting, setRequesting] = useState(false);
1018
+ const api = useApi();
1019
+ let t0;
1020
+ if ($[0] !== api) {
1021
+ t0 = id => {
1022
+ setRequesting(true);
1023
+ return api.medias.requestDeleteMedia(id).then(response => {
1024
+ setRequesting(false);
1025
+ return response;
1026
+ });
1027
+ };
1028
+ $[0] = api;
1029
+ $[1] = t0;
1030
+ } else {
1031
+ t0 = $[1];
1032
+ }
1033
+ const requestDeleteMedia = t0;
1034
+ let t1;
1035
+ if ($[2] !== requestDeleteMedia || $[3] !== requesting) {
1036
+ t1 = {
1037
+ requestDeleteMedia,
1038
+ requesting
1039
+ };
1040
+ $[2] = requestDeleteMedia;
1041
+ $[3] = requesting;
1042
+ $[4] = t1;
1043
+ } else {
1044
+ t1 = $[4];
1045
+ }
1046
+ return t1;
969
1047
  };
970
1048
 
971
- var useMediaDelete = function useMediaDelete() {
972
- var _useState = useState(false),
973
- _useState2 = _slicedToArray(_useState, 2),
974
- deleting = _useState2[0],
975
- setDeleting = _useState2[1];
976
- var api = useApi();
977
- var deleteMedia = useCallback(function (id) {
978
- setDeleting(true);
979
- return api.medias["delete"](id).then(function (response) {
980
- setDeleting(false);
981
- return response;
982
- });
983
- }, [api, setDeleting]);
984
- return {
985
- deleteMedia: deleteMedia,
986
- deleting: deleting
987
- };
1049
+ const useMediaDelete = () => {
1050
+ const $ = c(5);
1051
+ const [deleting, setDeleting] = useState(false);
1052
+ const api = useApi();
1053
+ let t0;
1054
+ if ($[0] !== api) {
1055
+ t0 = id => {
1056
+ setDeleting(true);
1057
+ return api.medias.delete(id).then(response => {
1058
+ setDeleting(false);
1059
+ return response;
1060
+ });
1061
+ };
1062
+ $[0] = api;
1063
+ $[1] = t0;
1064
+ } else {
1065
+ t0 = $[1];
1066
+ }
1067
+ const deleteMedia = t0;
1068
+ let t1;
1069
+ if ($[2] !== deleteMedia || $[3] !== deleting) {
1070
+ t1 = {
1071
+ deleteMedia,
1072
+ deleting
1073
+ };
1074
+ $[2] = deleteMedia;
1075
+ $[3] = deleting;
1076
+ $[4] = t1;
1077
+ } else {
1078
+ t1 = $[4];
1079
+ }
1080
+ return t1;
988
1081
  };
989
1082
 
990
- var _excluded = ["data"];
991
- var useQuiz = function useQuiz() {
992
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
993
- var _ref = options || {},
994
- _ref$screenId = _ref.screenId,
995
- screenId = _ref$screenId === void 0 ? null : _ref$screenId,
996
- _ref$storyId = _ref.storyId,
997
- providedStoryId = _ref$storyId === void 0 ? null : _ref$storyId,
998
- _ref$opts = _ref.opts,
999
- opts = _ref$opts === void 0 ? {} : _ref$opts;
1000
- var api = useApi();
1001
- var _ref2 = useStory() || {},
1002
- storyId = _ref2.id,
1003
- documentId = _ref2.document_id;
1004
- var loader = useCallback(function () {
1005
- return api !== null ? api.quiz.results(screenId, {
1006
- story_id: documentId || providedStoryId || storyId
1007
- }) : null;
1008
- }, [api, screenId, documentId, providedStoryId, storyId]);
1009
- var _ref3 = api !== null ? useData(loader, opts) : {
1010
- data: null
1011
- },
1012
- data = _ref3.data,
1013
- request = _objectWithoutProperties(_ref3, _excluded);
1014
- return _objectSpread({
1015
- quiz: data || []
1016
- }, request);
1083
+ const useQuiz = (options = null) => {
1084
+ const {
1085
+ screenId = null,
1086
+ storyId: providedStoryId = null,
1087
+ opts = {}
1088
+ } = options || {};
1089
+ const api = useApi();
1090
+ const {
1091
+ id: storyId,
1092
+ document_id: documentId
1093
+ } = useStory() || {};
1094
+ const loader = useCallback(() => api !== null ? api.quiz.results(screenId, {
1095
+ story_id: documentId || providedStoryId || storyId
1096
+ }) : null, [api, screenId, documentId, providedStoryId, storyId]);
1097
+ const {
1098
+ data,
1099
+ ...request
1100
+ } = api !== null ? useData(loader, opts) : {
1101
+ data: null
1102
+ };
1103
+ return {
1104
+ quiz: data || [],
1105
+ ...request
1106
+ };
1017
1107
  };
1018
1108
 
1019
- var useQuizCreate = function useQuizCreate() {
1020
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1021
- var _ref = options || {},
1022
- _ref$screenId = _ref.screenId,
1023
- screenId = _ref$screenId === void 0 ? null : _ref$screenId,
1024
- _ref$visitorId = _ref.visitorId,
1025
- providedVisitorId = _ref$visitorId === void 0 ? null : _ref$visitorId,
1026
- _ref$storyId = _ref.storyId,
1027
- providedStoryId = _ref$storyId === void 0 ? null : _ref$storyId,
1028
- _ref$onSuccess = _ref.onSuccess,
1029
- onSuccess = _ref$onSuccess === void 0 ? null : _ref$onSuccess;
1030
- var api = useApi();
1031
- var _useState = useState(false),
1032
- _useState2 = _slicedToArray(_useState, 2),
1033
- creating = _useState2[0],
1034
- setCreating = _useState2[1];
1035
- var _ref2 = useVisitor() || {},
1036
- visitorId = _ref2.id;
1037
- var _ref3 = useStory() || {},
1038
- storyId = _ref3.id,
1039
- documentId = _ref3.document_id;
1040
- var create = useCallback(function (data) {
1109
+ const useQuizCreate = (options = null) => {
1110
+ const {
1111
+ screenId = null,
1112
+ visitorId: providedVisitorId = null,
1113
+ storyId: providedStoryId = null,
1114
+ onSuccess = null
1115
+ } = options || {};
1116
+ const api = useApi();
1117
+ const [creating, setCreating] = useState(false);
1118
+ const {
1119
+ id: visitorId
1120
+ } = useVisitor() || {};
1121
+ const {
1122
+ id: storyId,
1123
+ document_id: documentId
1124
+ } = useStory() || {};
1125
+ const create = useCallback(data => {
1041
1126
  if (api === null) {
1042
1127
  return null;
1043
1128
  }
1044
1129
  setCreating(true);
1045
- return api.quiz.create(_objectSpread({
1130
+ return api.quiz.create({
1046
1131
  screen_id: screenId,
1047
1132
  visitor_id: providedVisitorId || visitorId,
1048
- story_id: documentId || providedStoryId || storyId
1049
- }, data)).then(function (response) {
1133
+ story_id: documentId || providedStoryId || storyId,
1134
+ ...data
1135
+ }).then(response => {
1050
1136
  setCreating(false);
1051
1137
  if (onSuccess !== null) {
1052
1138
  onSuccess(response);
@@ -1055,23 +1141,36 @@ var useQuizCreate = function useQuizCreate() {
1055
1141
  });
1056
1142
  }, [api, setCreating, onSuccess, screenId, visitorId, storyId, providedVisitorId, providedStoryId]);
1057
1143
  return {
1058
- create: create,
1059
- creating: creating
1144
+ create,
1145
+ creating
1060
1146
  };
1061
1147
  };
1062
1148
 
1063
- function DataProvider(_ref) {
1064
- var _ref$api = _ref.api,
1065
- api = _ref$api === void 0 ? null : _ref$api,
1066
- _ref$apiBaseUrl = _ref.apiBaseUrl,
1067
- apiBaseUrl = _ref$apiBaseUrl === void 0 ? undefined : _ref$apiBaseUrl,
1068
- _ref$children = _ref.children,
1069
- children = _ref$children === void 0 ? null : _ref$children;
1070
- return /*#__PURE__*/jsx(ApiProvider, {
1071
- api: api,
1072
- baseUrl: apiBaseUrl,
1073
- children: children
1074
- });
1149
+ function DataProvider(t0) {
1150
+ const $ = c(4);
1151
+ const {
1152
+ api: t1,
1153
+ apiBaseUrl: t2,
1154
+ children: t3
1155
+ } = t0;
1156
+ const api = t1 === undefined ? null : t1;
1157
+ const apiBaseUrl = t2 === undefined ? undefined : t2;
1158
+ const children = t3 === undefined ? null : t3;
1159
+ let t4;
1160
+ if ($[0] !== api || $[1] !== apiBaseUrl || $[2] !== children) {
1161
+ t4 = /*#__PURE__*/jsx(ApiProvider, {
1162
+ api: api,
1163
+ baseUrl: apiBaseUrl,
1164
+ children: children
1165
+ });
1166
+ $[0] = api;
1167
+ $[1] = apiBaseUrl;
1168
+ $[2] = children;
1169
+ $[3] = t4;
1170
+ } else {
1171
+ t4 = $[3];
1172
+ }
1173
+ return t4;
1075
1174
  }
1076
1175
 
1077
1176
  export { Api, ApiProvider, Base as BaseApi, DataProvider, useApi, useContributionCreate, useContributions, useData, useItems$1 as useItems, useMedia, useMediaAuthors, useMediaCreate, useMediaDelete, useMediaRequestDelete, useMediaTags, useMediaUpdate, useMedias, useMediasRecent as useMediasRecentSearches, useQuiz, useQuizCreate };