cozy-bar 8.4.2 → 8.4.3
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/dist/cozy-bar.min.js +4 -4
- package/dist/cozy-bar.min.js.map +1 -1
- package/package.json +2 -2
- package/CHANGELOG.md +0 -493
- package/transpiled/assets/icons/16/icon-storage-16.svg +0 -3
- package/transpiled/assets/icons/24/icon-arrow-left.svg +0 -3
- package/transpiled/assets/icons/32/icon-claudy.svg +0 -1
- package/transpiled/assets/icons/apps/icon-collect.svg +0 -25
- package/transpiled/assets/icons/apps/icon-drive.svg +0 -17
- package/transpiled/assets/icons/apps/icon-market-soon.svg +0 -25
- package/transpiled/assets/icons/apps/icon-photos.svg +0 -19
- package/transpiled/assets/icons/apps/icon-soon.svg +0 -21
- package/transpiled/assets/icons/apps/icon-store.svg +0 -19
- package/transpiled/assets/icons/claudyActions/icon-bills.svg +0 -6
- package/transpiled/assets/icons/claudyActions/icon-laptop.svg +0 -7
- package/transpiled/assets/icons/claudyActions/icon-phone.svg +0 -8
- package/transpiled/assets/icons/claudyActions/icon-question-mark.svg +0 -6
- package/transpiled/assets/icons/comingsoon/icon-bank.svg +0 -12
- package/transpiled/assets/icons/comingsoon/icon-sante.svg +0 -12
- package/transpiled/assets/icons/comingsoon/icon-store.svg +0 -6
- package/transpiled/assets/icons/icon-cozy.svg +0 -3
- package/transpiled/assets/icons/icon-shield.svg +0 -3
- package/transpiled/assets/icons/spinner.svg +0 -4
- package/transpiled/assets/sprites/icon-apps.svg +0 -1
- package/transpiled/assets/sprites/icon-cozy-home.svg +0 -16
- package/transpiled/components/Apps/AppItem.js +0 -134
- package/transpiled/components/Apps/AppItemPlaceholder.js +0 -14
- package/transpiled/components/Apps/AppNavButtons.js +0 -108
- package/transpiled/components/Apps/AppsContent.js +0 -124
- package/transpiled/components/Apps/ButtonCozyHome.js +0 -25
- package/transpiled/components/Apps/ButtonCozyHome.spec.jsx +0 -53
- package/transpiled/components/Apps/IconCozyHome.js +0 -67
- package/transpiled/components/Apps/index.js +0 -102
- package/transpiled/components/Banner.js +0 -76
- package/transpiled/components/Bar.js +0 -329
- package/transpiled/components/Bar.spec.jsx +0 -133
- package/transpiled/components/Claudy.js +0 -123
- package/transpiled/components/ClaudyIcon.js +0 -16
- package/transpiled/components/Drawer.js +0 -367
- package/transpiled/components/Drawer.spec.jsx +0 -98
- package/transpiled/components/SearchBar.js +0 -407
- package/transpiled/components/Settings/SettingsContent.js +0 -128
- package/transpiled/components/Settings/StorageData.js +0 -24
- package/transpiled/components/Settings/helper.js +0 -9
- package/transpiled/components/Settings/index.js +0 -225
- package/transpiled/components/StorageIcon.js +0 -16
- package/transpiled/components/SupportModal.js +0 -86
- package/transpiled/components/__snapshots__/Bar.spec.jsx.snap +0 -302
- package/transpiled/config/claudyActions.json +0 -20
- package/transpiled/config/persistWhitelist.json +0 -4
- package/transpiled/cozy-bar.css +0 -5905
- package/transpiled/dom.js +0 -84
- package/transpiled/index.js +0 -246
- package/transpiled/index.spec.jsx +0 -34
- package/transpiled/lib/api/helpers.js +0 -12
- package/transpiled/lib/api/index.js +0 -175
- package/transpiled/lib/exceptions.js +0 -156
- package/transpiled/lib/expiringMemoize.js +0 -17
- package/transpiled/lib/icon.js +0 -154
- package/transpiled/lib/intents.js +0 -17
- package/transpiled/lib/logger.js +0 -10
- package/transpiled/lib/middlewares/appsI18n.js +0 -64
- package/transpiled/lib/realtime.js +0 -76
- package/transpiled/lib/reducers/apps.js +0 -291
- package/transpiled/lib/reducers/apps.spec.js +0 -59
- package/transpiled/lib/reducers/content.js +0 -68
- package/transpiled/lib/reducers/context.js +0 -138
- package/transpiled/lib/reducers/index.js +0 -59
- package/transpiled/lib/reducers/locale.js +0 -27
- package/transpiled/lib/reducers/settings.js +0 -253
- package/transpiled/lib/reducers/theme.js +0 -64
- package/transpiled/lib/reducers/unserializable.js +0 -31
- package/transpiled/lib/stack-client.js +0 -442
- package/transpiled/lib/stack.js +0 -122
- package/transpiled/lib/store/index.js +0 -42
- package/transpiled/locales/de.json +0 -57
- package/transpiled/locales/en.json +0 -57
- package/transpiled/locales/es.json +0 -57
- package/transpiled/locales/fr.json +0 -57
- package/transpiled/locales/it.json +0 -57
- package/transpiled/locales/ja.json +0 -57
- package/transpiled/locales/nl_NL.json +0 -57
- package/transpiled/locales/pl.json +0 -57
- package/transpiled/locales/ru.json +0 -57
- package/transpiled/locales/sq.json +0 -57
- package/transpiled/locales/zh_CN.json +0 -57
- package/transpiled/proptypes/index.js +0 -11
- package/transpiled/queries/index.js +0 -19
- package/transpiled/styles/apps.css +0 -248
- package/transpiled/styles/banner.css +0 -64
- package/transpiled/styles/bar.css +0 -106
- package/transpiled/styles/base.css +0 -21
- package/transpiled/styles/claudy.css +0 -98
- package/transpiled/styles/drawer.css +0 -126
- package/transpiled/styles/index.styl +0 -33
- package/transpiled/styles/indicators.css +0 -58
- package/transpiled/styles/nav.css +0 -81
- package/transpiled/styles/navigation_item.css +0 -34
- package/transpiled/styles/searchbar.css +0 -156
- package/transpiled/styles/settings.css +0 -34
- package/transpiled/styles/storage.css +0 -22
- package/transpiled/styles/supportModal.css +0 -20
- package/transpiled/styles/theme.styl +0 -25
package/transpiled/dom.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
var APP_SELECTOR = '[role=application]'; // return an empty object by default to avoid checking existance
|
|
2
|
-
|
|
3
|
-
var getAppNodeDataSet = function getAppNodeDataSet() {
|
|
4
|
-
var appNode = document.querySelector(APP_SELECTOR);
|
|
5
|
-
if (!appNode || !appNode.dataset) return {};
|
|
6
|
-
return appNode.dataset;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
var getDefaultStackURL = function getDefaultStackURL(isPublic) {
|
|
10
|
-
var data = getAppNodeDataSet();
|
|
11
|
-
|
|
12
|
-
if (!data.cozyDomain) {
|
|
13
|
-
if (!isPublic) {
|
|
14
|
-
// eslint-disable-next-line no-console
|
|
15
|
-
console.warn("Cozy-bar can't discover the cozy's URL, and will probably fail to initialize the connection with the stack.");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return '';
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
var protocol = window.location.protocol;
|
|
22
|
-
return "".concat(protocol, "//").concat(data.cozyDomain);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
var getDefaultToken = function getDefaultToken(isPublic) {
|
|
26
|
-
var data = getAppNodeDataSet();
|
|
27
|
-
|
|
28
|
-
if (!data.cozyToken) {
|
|
29
|
-
if (!isPublic) {
|
|
30
|
-
// eslint-disable-next-line no-console
|
|
31
|
-
console.warn("Cozy-bar can't discover the app's token, and will probably fail to initialize the connection with the stack.");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return '';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return data.cozyToken;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
var getDefaultIcon = function getDefaultIcon() {
|
|
41
|
-
var linkNode = document.querySelector('link[rel="icon"][sizes^="32"]');
|
|
42
|
-
|
|
43
|
-
if (linkNode !== null) {
|
|
44
|
-
return linkNode.getAttribute('href');
|
|
45
|
-
} else {
|
|
46
|
-
return 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
var getAppNamePrefix = function getAppNamePrefix() {
|
|
51
|
-
var data = getAppNodeDataSet();
|
|
52
|
-
return data.cozyAppNamePrefix || null;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
var getAppSlug = function getAppSlug() {
|
|
56
|
-
var data = getAppNodeDataSet();
|
|
57
|
-
return data.cozyAppSlug || null;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
var getUserActionRequired = function getUserActionRequired() {
|
|
61
|
-
var meta = document.querySelector('meta[name=user-action-required]');
|
|
62
|
-
var data = meta && meta.dataset;
|
|
63
|
-
|
|
64
|
-
if (data) {
|
|
65
|
-
var title = data.title,
|
|
66
|
-
code = data.code,
|
|
67
|
-
detail = data.detail,
|
|
68
|
-
links = data.links;
|
|
69
|
-
|
|
70
|
-
if (code) {
|
|
71
|
-
// we suppose that at least code will always exist
|
|
72
|
-
return {
|
|
73
|
-
title: title,
|
|
74
|
-
code: code,
|
|
75
|
-
detail: detail,
|
|
76
|
-
links: links
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return undefined;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export { getDefaultStackURL, getDefaultToken, getDefaultIcon, getAppNamePrefix, getAppSlug, getUserActionRequired, APP_SELECTOR };
|
package/transpiled/index.js
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
-
|
|
4
|
-
/* global __VERSION__ */
|
|
5
|
-
import { isMobileApp } from 'cozy-device-helper';
|
|
6
|
-
import stack from "./lib/stack";
|
|
7
|
-
import { getLocale, onRealtimeCreate, onRealtimeDelete, setLocale, setInfos } from "./lib/reducers";
|
|
8
|
-
import { createBarAPI, createBarProxiedAPI } from "./lib/api";
|
|
9
|
-
import { getAppNamePrefix, getAppSlug, getDefaultIcon, getDefaultStackURL, getDefaultToken, getUserActionRequired, APP_SELECTOR } from "./dom";
|
|
10
|
-
import enLocale from "./locales/en.json";
|
|
11
|
-
import frLocale from "./locales/fr.json";
|
|
12
|
-
import esLocale from "./locales/es.json";
|
|
13
|
-
var locales = {
|
|
14
|
-
en: enLocale,
|
|
15
|
-
fr: frLocale,
|
|
16
|
-
es: esLocale
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
var createBarElement = function createBarElement() {
|
|
20
|
-
var targetName = isMobileApp() ? 'mobile' : 'browser';
|
|
21
|
-
var barNode = document.createElement('div');
|
|
22
|
-
barNode.setAttribute('id', 'coz-bar');
|
|
23
|
-
barNode.setAttribute('role', 'banner');
|
|
24
|
-
barNode.classList.add("coz-target--".concat(targetName));
|
|
25
|
-
return barNode;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
var injectBarInDOM = function injectBarInDOM(data) {
|
|
29
|
-
if (document.getElementById('coz-bar') !== null) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
var barNode = createBarElement();
|
|
34
|
-
var appNode = document.querySelector(APP_SELECTOR);
|
|
35
|
-
|
|
36
|
-
if (!appNode) {
|
|
37
|
-
// eslint-disable-next-line no-console
|
|
38
|
-
console.warn("Cozy-bar is looking for a \"".concat(APP_SELECTOR, "\" tag that contains your application and can't find it :'(\u2026 The BAR is now disabled"));
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
document.body.insertBefore(barNode, appNode); // method to put cozy-bar z-index on the top when Drawer visible and vice versa
|
|
43
|
-
|
|
44
|
-
data.onDrawer = function (visible) {
|
|
45
|
-
barNode.dataset.drawerVisible = visible;
|
|
46
|
-
}; // specific layout behaviour if banner displayed
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (data.userActionRequired) {
|
|
50
|
-
document.body.classList.add('has-banner');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return barNode;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
var renderBar = function renderBar(barNode, options) {
|
|
57
|
-
// import React related modules on init only
|
|
58
|
-
var React = require('react');
|
|
59
|
-
|
|
60
|
-
var _require = require('react-dom'),
|
|
61
|
-
render = _require.render;
|
|
62
|
-
|
|
63
|
-
var _require2 = require('react-redux'),
|
|
64
|
-
connect = _require2.connect,
|
|
65
|
-
Provider = _require2.Provider;
|
|
66
|
-
|
|
67
|
-
var I18n = require("cozy-ui/transpiled/react/I18n").default;
|
|
68
|
-
|
|
69
|
-
var Bar = require("./components/Bar").default;
|
|
70
|
-
|
|
71
|
-
var CozyProvider = require('cozy-client').CozyProvider;
|
|
72
|
-
|
|
73
|
-
var cozyClient = options.cozyClient; // we connect the I18n component to the store to listen
|
|
74
|
-
// locale change from the api setLocale()
|
|
75
|
-
|
|
76
|
-
var EnhancedI18n = connect(function (state) {
|
|
77
|
-
return {
|
|
78
|
-
lang: getLocale(state)
|
|
79
|
-
};
|
|
80
|
-
})(I18n);
|
|
81
|
-
var barComponent = /*#__PURE__*/React.createElement(Provider, {
|
|
82
|
-
store: options.reduxStore
|
|
83
|
-
}, /*#__PURE__*/React.createElement(EnhancedI18n, {
|
|
84
|
-
dictRequire: function dictRequire(lang) {
|
|
85
|
-
return locales[lang];
|
|
86
|
-
}
|
|
87
|
-
}, cozyClient ? /*#__PURE__*/React.createElement(CozyProvider, {
|
|
88
|
-
client: cozyClient
|
|
89
|
-
}, /*#__PURE__*/React.createElement(Bar, options)) : /*#__PURE__*/React.createElement(Bar, options)));
|
|
90
|
-
render(barComponent, barNode); // for testing only
|
|
91
|
-
|
|
92
|
-
return barComponent;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
var makeCozyClientAutomatically = function makeCozyClientAutomatically(_ref) {
|
|
96
|
-
var cozyURL = _ref.cozyURL,
|
|
97
|
-
token = _ref.token,
|
|
98
|
-
isPublic = _ref.isPublic;
|
|
99
|
-
var ccURI = cozyURL || getDefaultStackURL(isPublic);
|
|
100
|
-
var ccToken = token || getDefaultToken(isPublic);
|
|
101
|
-
var ccOptions = {
|
|
102
|
-
uri: ccURI,
|
|
103
|
-
token: ccToken
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
var CozyClient = require('cozy-client').default; // eslint-disable-next-line no-console
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
console.warn('Automatically made cozyClient. Options: ', ccOptions);
|
|
110
|
-
return new CozyClient(ccOptions);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
var exposedAPI = {};
|
|
114
|
-
/**
|
|
115
|
-
* Initializes the cozy bar
|
|
116
|
-
*
|
|
117
|
-
* It can be initialized either with a cozyClient instance
|
|
118
|
-
* or a { cozyURL, ssl, token } tupple.
|
|
119
|
-
*
|
|
120
|
-
* @function
|
|
121
|
-
* @param {Object} options
|
|
122
|
-
* @param {string} options.appName - App name to be displayed in the bar
|
|
123
|
-
* @param {string} options.appNamePrefix
|
|
124
|
-
* @param {string} options.lang - Language for the bar
|
|
125
|
-
* @param {string} options.iconPath -
|
|
126
|
-
* @param {Object} options.cozyClient - a cozy client instance
|
|
127
|
-
* @param {string} options.cozyURL - URL or domain of the stack
|
|
128
|
-
* @param {boolean} options.ssl - Tells if we should use a secure
|
|
129
|
-
* protocol required if cozyURL does
|
|
130
|
-
* not have a protocol
|
|
131
|
-
* @param {string} arg.token - Access token for the stack
|
|
132
|
-
* @param {boolean} arg.isPublic
|
|
133
|
-
* @param {Function} arg.onLogout
|
|
134
|
-
*/
|
|
135
|
-
|
|
136
|
-
var init = /*#__PURE__*/function () {
|
|
137
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
138
|
-
var _ref3,
|
|
139
|
-
appName,
|
|
140
|
-
_ref3$appNamePrefix,
|
|
141
|
-
appNamePrefix,
|
|
142
|
-
_ref3$appSlug,
|
|
143
|
-
appSlug,
|
|
144
|
-
lang,
|
|
145
|
-
_ref3$iconPath,
|
|
146
|
-
iconPath,
|
|
147
|
-
cozyClient,
|
|
148
|
-
cozyURL,
|
|
149
|
-
token,
|
|
150
|
-
_ref3$replaceTitleOnM,
|
|
151
|
-
replaceTitleOnMobile,
|
|
152
|
-
_ref3$isPublic,
|
|
153
|
-
isPublic,
|
|
154
|
-
onLogOut,
|
|
155
|
-
getOrCreateStore,
|
|
156
|
-
reduxStore,
|
|
157
|
-
apiMethods,
|
|
158
|
-
options,
|
|
159
|
-
barNode,
|
|
160
|
-
_args = arguments;
|
|
161
|
-
|
|
162
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
163
|
-
while (1) {
|
|
164
|
-
switch (_context.prev = _context.next) {
|
|
165
|
-
case 0:
|
|
166
|
-
_ref3 = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}, appName = _ref3.appName, _ref3$appNamePrefix = _ref3.appNamePrefix, appNamePrefix = _ref3$appNamePrefix === void 0 ? getAppNamePrefix() : _ref3$appNamePrefix, _ref3$appSlug = _ref3.appSlug, appSlug = _ref3$appSlug === void 0 ? getAppSlug() : _ref3$appSlug, lang = _ref3.lang, _ref3$iconPath = _ref3.iconPath, iconPath = _ref3$iconPath === void 0 ? getDefaultIcon() : _ref3$iconPath, cozyClient = _ref3.cozyClient, cozyURL = _ref3.cozyURL, token = _ref3.token, _ref3$replaceTitleOnM = _ref3.replaceTitleOnMobile, replaceTitleOnMobile = _ref3$replaceTitleOnM === void 0 ? false : _ref3$replaceTitleOnM, _ref3$isPublic = _ref3.isPublic, isPublic = _ref3$isPublic === void 0 ? false : _ref3$isPublic, onLogOut = _ref3.onLogOut;
|
|
167
|
-
|
|
168
|
-
// Force public mode in `/public` URLs
|
|
169
|
-
if (!isPublic && /^\/public/.test(window.location.pathname)) {
|
|
170
|
-
isPublic = true;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (!cozyClient) {
|
|
174
|
-
cozyClient = makeCozyClientAutomatically({
|
|
175
|
-
cozyURL: cozyURL,
|
|
176
|
-
token: token,
|
|
177
|
-
isPublic: isPublic
|
|
178
|
-
});
|
|
179
|
-
} // store
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
getOrCreateStore = require("./lib/store").default;
|
|
183
|
-
reduxStore = getOrCreateStore();
|
|
184
|
-
reduxStore.dispatch(setInfos(appName, appNamePrefix, appSlug));
|
|
185
|
-
stack.init({
|
|
186
|
-
cozyClient: cozyClient,
|
|
187
|
-
onCreate: function onCreate(data) {
|
|
188
|
-
return reduxStore.dispatch(onRealtimeCreate(data));
|
|
189
|
-
},
|
|
190
|
-
onDelete: function onDelete(data) {
|
|
191
|
-
return reduxStore.dispatch(onRealtimeDelete(data));
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
if (lang) {
|
|
196
|
-
reduxStore.dispatch(setLocale(lang));
|
|
197
|
-
} // Assign all api methods to the bar object
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
apiMethods = createBarAPI(reduxStore);
|
|
201
|
-
Object.assign(exposedAPI, apiMethods);
|
|
202
|
-
options = {
|
|
203
|
-
appName: appName,
|
|
204
|
-
appNamePrefix: appNamePrefix,
|
|
205
|
-
appSlug: appSlug,
|
|
206
|
-
cozyClient: cozyClient,
|
|
207
|
-
iconPath: iconPath,
|
|
208
|
-
replaceTitleOnMobile: replaceTitleOnMobile,
|
|
209
|
-
isPublic: isPublic,
|
|
210
|
-
onLogOut: onLogOut,
|
|
211
|
-
userActionRequired: getUserActionRequired(),
|
|
212
|
-
reduxStore: reduxStore
|
|
213
|
-
};
|
|
214
|
-
barNode = injectBarInDOM(options);
|
|
215
|
-
renderBar(barNode, options);
|
|
216
|
-
|
|
217
|
-
case 13:
|
|
218
|
-
case "end":
|
|
219
|
-
return _context.stop();
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}, _callee);
|
|
223
|
-
}));
|
|
224
|
-
|
|
225
|
-
return function init() {
|
|
226
|
-
return _ref2.apply(this, arguments);
|
|
227
|
-
};
|
|
228
|
-
}();
|
|
229
|
-
|
|
230
|
-
var updateAccessToken = function updateAccessToken(accessToken) {
|
|
231
|
-
stack.updateAccessToken(accessToken);
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
var proxiedAPI = createBarProxiedAPI(exposedAPI);
|
|
235
|
-
var setBarCenter = proxiedAPI.setBarCenter,
|
|
236
|
-
setBarLeft = proxiedAPI.setBarLeft,
|
|
237
|
-
setBarRight = proxiedAPI.setBarRight,
|
|
238
|
-
setBarSearch = proxiedAPI.setBarSearch,
|
|
239
|
-
BarCenter = proxiedAPI.BarCenter,
|
|
240
|
-
BarRight = proxiedAPI.BarRight,
|
|
241
|
-
BarLeft = proxiedAPI.BarLeft,
|
|
242
|
-
BarSearch = proxiedAPI.BarSearch,
|
|
243
|
-
setTheme = proxiedAPI.setTheme,
|
|
244
|
-
setWebviewContext = proxiedAPI.setWebviewContext;
|
|
245
|
-
var version = "\"0.0.0-development\"";
|
|
246
|
-
export { init, version, setBarCenter, setBarLeft, setBarRight, setBarSearch, BarLeft, BarRight, BarCenter, BarSearch, setTheme, setWebviewContext, setLocale, updateAccessToken };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import CozyClient from 'cozy-client'
|
|
2
|
-
import jestFetchMock from 'jest-fetch-mock'
|
|
3
|
-
|
|
4
|
-
import * as cozyBar from './index'
|
|
5
|
-
|
|
6
|
-
describe('init', () => {
|
|
7
|
-
beforeAll(() => {
|
|
8
|
-
global.fetch = jestFetchMock
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
jest.spyOn(console, 'error')
|
|
13
|
-
const div = document.createElement('div')
|
|
14
|
-
div.setAttribute('role', 'application')
|
|
15
|
-
document.body.appendChild(div)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
// eslint-disable-next-line no-console
|
|
20
|
-
console.error.mockRestore()
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('should init the bar', () => {
|
|
24
|
-
const client = new CozyClient({})
|
|
25
|
-
cozyBar.init({
|
|
26
|
-
appName: 'App',
|
|
27
|
-
cozyClient: client,
|
|
28
|
-
lang: 'fr'
|
|
29
|
-
})
|
|
30
|
-
cozyBar.setBarCenter('Page title')
|
|
31
|
-
// eslint-disable-next-line no-console
|
|
32
|
-
expect(console.error).not.toHaveBeenCalled()
|
|
33
|
-
})
|
|
34
|
-
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export var locations = ['left', 'center', 'right', 'search'];
|
|
2
|
-
|
|
3
|
-
var upperFirstLetter = function upperFirstLetter(val) {
|
|
4
|
-
return val[0].toUpperCase() + val.slice(1);
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export var getJsApiName = function getJsApiName(location) {
|
|
8
|
-
return "setBar".concat(upperFirstLetter(location));
|
|
9
|
-
};
|
|
10
|
-
export var getReactApiName = function getReactApiName(location) {
|
|
11
|
-
return "Bar".concat(upperFirstLetter(location));
|
|
12
|
-
};
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
-
|
|
7
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
8
|
-
|
|
9
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
10
|
-
|
|
11
|
-
import React, { Component } from 'react';
|
|
12
|
-
import { setContent as _setContent, unsetContent as _unsetContent, setLocale, setTheme, setWebviewContext } from "../reducers";
|
|
13
|
-
import { locations, getJsApiName, getReactApiName } from "./helpers"; // The React API need unique IDs, so we will increment this variable
|
|
14
|
-
|
|
15
|
-
var idToIncrement = 0;
|
|
16
|
-
/**
|
|
17
|
-
* Wraps argument into a React element if it is a string. Is used
|
|
18
|
-
* for setBar{Left,Right,Center} to be able to pass HTML
|
|
19
|
-
*
|
|
20
|
-
* @param {ReactElement|string} v
|
|
21
|
-
* @return {ReactElement}
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
var wrapInElement = function wrapInElement(v) {
|
|
25
|
-
if (typeof v === 'string') {
|
|
26
|
-
return /*#__PURE__*/React.createElement("span", {
|
|
27
|
-
dangerouslySetInnerHTML: {
|
|
28
|
-
__html: v
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
} else {
|
|
32
|
-
return v;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Creates a React component that enables to access store
|
|
37
|
-
* properties in a declarative way.
|
|
38
|
-
*
|
|
39
|
-
* @param {BarStore} store
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var barContentComponent = function barContentComponent(store, location) {
|
|
44
|
-
return /*#__PURE__*/function (_Component) {
|
|
45
|
-
_inherits(BarContent, _Component);
|
|
46
|
-
|
|
47
|
-
var _super = _createSuper(BarContent);
|
|
48
|
-
|
|
49
|
-
function BarContent() {
|
|
50
|
-
_classCallCheck(this, BarContent);
|
|
51
|
-
|
|
52
|
-
return _super.apply(this, arguments);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
_createClass(BarContent, [{
|
|
56
|
-
key: "componentDidMount",
|
|
57
|
-
value: function componentDidMount() {
|
|
58
|
-
this.componentId = idToIncrement++;
|
|
59
|
-
this.setContent(this.props.children);
|
|
60
|
-
}
|
|
61
|
-
}, {
|
|
62
|
-
key: "setContent",
|
|
63
|
-
value: function setContent(content) {
|
|
64
|
-
try {
|
|
65
|
-
content = React.Children.only(content); // eslint-disable-next-line no-empty
|
|
66
|
-
} catch (e) {}
|
|
67
|
-
|
|
68
|
-
store.dispatch(_setContent(location, content, this.componentId));
|
|
69
|
-
}
|
|
70
|
-
}, {
|
|
71
|
-
key: "unsetContent",
|
|
72
|
-
value: function unsetContent() {
|
|
73
|
-
store.dispatch(_unsetContent(location, this.componentId));
|
|
74
|
-
}
|
|
75
|
-
}, {
|
|
76
|
-
key: "componentWillUnmount",
|
|
77
|
-
value: function componentWillUnmount() {
|
|
78
|
-
this.unsetContent();
|
|
79
|
-
}
|
|
80
|
-
}, {
|
|
81
|
-
key: "componentDidUpdate",
|
|
82
|
-
value: function componentDidUpdate(prevProps) {
|
|
83
|
-
if (this.props.children !== prevProps.children) {
|
|
84
|
-
this.setContent(this.props.children);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}, {
|
|
88
|
-
key: "render",
|
|
89
|
-
value: function render() {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
}]);
|
|
93
|
-
|
|
94
|
-
return BarContent;
|
|
95
|
-
}(Component);
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Creates a public API
|
|
99
|
-
*
|
|
100
|
-
* - getters/setters for public attributes
|
|
101
|
-
* - React components that act as getters/setters
|
|
102
|
-
*
|
|
103
|
-
* @param {ReduxStore} store - Store on which the API will act
|
|
104
|
-
* @return {object} - Methods of the public API
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
export var createBarAPI = function createBarAPI(store) {
|
|
109
|
-
// setBar{Left,Right,Center} and <Bar{Left,Right,Center} />
|
|
110
|
-
var methods = {};
|
|
111
|
-
locations.forEach(function (location) {
|
|
112
|
-
// expose JS API
|
|
113
|
-
methods[getJsApiName(location)] = function (value) {
|
|
114
|
-
return store.dispatch(_setContent(location, wrapInElement(value), 'js'));
|
|
115
|
-
}; // expose React API
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
methods[getReactApiName(location)] = barContentComponent(store, location);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
methods.setLocale = function () {
|
|
122
|
-
store.dispatch(setLocale.apply(void 0, arguments));
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
methods.setTheme = function () {
|
|
126
|
-
store.dispatch(setTheme.apply(void 0, arguments));
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
methods.setWebviewContext = function () {
|
|
130
|
-
store.dispatch(setWebviewContext.apply(void 0, arguments));
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
return methods;
|
|
134
|
-
}; // Handle exceptions for API before init
|
|
135
|
-
|
|
136
|
-
var showAPIError = function showAPIError(name) {
|
|
137
|
-
// eslint-disable-next-line no-console
|
|
138
|
-
console.error("You tried to use the CozyBar API (".concat(name, ") but the CozyBar is not initialised yet via cozy.bar.init(...)."));
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
var makeProxyMethodToAPI = function makeProxyMethodToAPI(exposedAPI, fnName) {
|
|
142
|
-
return function () {
|
|
143
|
-
if (exposedAPI[fnName]) {
|
|
144
|
-
return exposedAPI[fnName].apply(exposedAPI, arguments);
|
|
145
|
-
} else {
|
|
146
|
-
showAPIError(fnName);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
|
-
/** Creates an API that swallows error until bar is correctly initialized */
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
export var createBarProxiedAPI = function createBarProxiedAPI(exposedAPI) {
|
|
154
|
-
var apiReferences = {};
|
|
155
|
-
locations.forEach(function (location) {
|
|
156
|
-
var jsAPIName = getJsApiName(location);
|
|
157
|
-
var reactAPIName = getReactApiName(location);
|
|
158
|
-
apiReferences[jsAPIName] = makeProxyMethodToAPI(exposedAPI, jsAPIName);
|
|
159
|
-
|
|
160
|
-
apiReferences[reactAPIName] = function (props) {
|
|
161
|
-
if (exposedAPI[reactAPIName]) {
|
|
162
|
-
return React.createElement(exposedAPI[reactAPIName], props);
|
|
163
|
-
} else {
|
|
164
|
-
showAPIError(reactAPIName);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
for (var _i = 0, _arr = ['setLocale', 'setTheme', 'setWebviewContext']; _i < _arr.length; _i++) {
|
|
170
|
-
var fnName = _arr[_i];
|
|
171
|
-
apiReferences[fnName] = makeProxyMethodToAPI(exposedAPI, fnName);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return apiReferences;
|
|
175
|
-
};
|