@panneau/app 1.0.1-alpha.0 → 1.0.3-alpha.2
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/assets/css/styles.css +7 -0
- package/es/index.js +1810 -5
- package/lib/index.js +1841 -15
- package/package.json +66 -54
- package/scss/styles.scss +3 -0
- package/es/Panneau.js +0 -318
- package/es/actions/AuthActions.js +0 -16
- package/es/actions/LayoutActions.js +0 -14
- package/es/components/App.js +0 -129
- package/es/components/Layout.js +0 -68
- package/es/components/Panneau.js +0 -79
- package/es/components/index.js +0 -3
- package/es/components/pages/Account.js +0 -38
- package/es/components/pages/Home.js +0 -12
- package/es/components/pages/ResourceCreate.js +0 -44
- package/es/components/pages/ResourceDelete.js +0 -11
- package/es/components/pages/ResourceEdit.js +0 -28
- package/es/components/pages/ResourceForm.js +0 -343
- package/es/components/pages/ResourceIndex.js +0 -261
- package/es/components/pages/ResourceShow.js +0 -15
- package/es/components/partials/ResourceFormHeader.js +0 -111
- package/es/components/partials/ResourceIndexHeader.js +0 -71
- package/es/defaults/routes.json +0 -10
- package/es/lib/createStore.js +0 -30
- package/es/reducers/AuthReducer.js +0 -32
- package/es/reducers/index.js +0 -4
- package/lib/Panneau.js +0 -340
- package/lib/actions/AuthActions.js +0 -25
- package/lib/actions/LayoutActions.js +0 -25
- package/lib/components/App.js +0 -159
- package/lib/components/Layout.js +0 -87
- package/lib/components/Panneau.js +0 -103
- package/lib/components/index.js +0 -23
- package/lib/components/pages/Account.js +0 -54
- package/lib/components/pages/Home.js +0 -23
- package/lib/components/pages/ResourceCreate.js +0 -65
- package/lib/components/pages/ResourceDelete.js +0 -22
- package/lib/components/pages/ResourceEdit.js +0 -44
- package/lib/components/pages/ResourceForm.js +0 -376
- package/lib/components/pages/ResourceIndex.js +0 -289
- package/lib/components/pages/ResourceShow.js +0 -28
- package/lib/components/partials/ResourceFormHeader.js +0 -137
- package/lib/components/partials/ResourceIndexHeader.js +0 -87
- package/lib/defaults/routes.json +0 -10
- package/lib/lib/createStore.js +0 -46
- package/lib/reducers/AuthReducer.js +0 -43
- package/lib/reducers/index.js +0 -15
- package/src/Panneau.js +0 -274
- package/src/actions/AuthActions.js +0 -17
- package/src/actions/LayoutActions.js +0 -12
- package/src/components/App.jsx +0 -121
- package/src/components/Layout.jsx +0 -51
- package/src/components/Panneau.jsx +0 -95
- package/src/components/index.js +0 -7
- package/src/components/pages/Account.jsx +0 -34
- package/src/components/pages/Home.jsx +0 -19
- package/src/components/pages/ResourceCreate.jsx +0 -50
- package/src/components/pages/ResourceDelete.jsx +0 -18
- package/src/components/pages/ResourceEdit.jsx +0 -39
- package/src/components/pages/ResourceForm.jsx +0 -361
- package/src/components/pages/ResourceIndex.jsx +0 -256
- package/src/components/pages/ResourceShow.jsx +0 -23
- package/src/components/partials/ResourceFormHeader.jsx +0 -137
- package/src/components/partials/ResourceIndexHeader.jsx +0 -84
- package/src/defaults/routes.json +0 -10
- package/src/index.js +0 -9
- package/src/lib/createStore.js +0 -21
- package/src/reducers/AuthReducer.js +0 -23
- package/src/reducers/index.js +0 -5
- package/src/styles/layout.scss +0 -5
- package/src/styles/pages/resource-form.scss +0 -42
- package/src/styles/pages/resource-index.scss +0 -43
- package/src/styles/partials/resource-form-header.scss +0 -7
- package/src/styles/partials/resource-index-header.scss +0 -13
- package/src/styles/vendor.global.scss +0 -5
@@ -1,137 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
4
|
-
|
5
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
6
|
-
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
8
|
-
value: true
|
9
|
-
});
|
10
|
-
exports["default"] = void 0;
|
11
|
-
|
12
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
13
|
-
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
15
|
-
|
16
|
-
var _react = _interopRequireWildcard(require("react"));
|
17
|
-
|
18
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
19
|
-
|
20
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
21
|
-
|
22
|
-
var _reactIntl = require("react-intl");
|
23
|
-
|
24
|
-
var _core = require("@panneau/core");
|
25
|
-
|
26
|
-
var _utils = require("@panneau/core/utils");
|
27
|
-
|
28
|
-
var _components = require("@panneau/core/components");
|
29
|
-
|
30
|
-
var _contexts = require("@panneau/core/contexts");
|
31
|
-
|
32
|
-
var styles = {
|
33
|
-
"container": "panneau-app-resource-form-header-container",
|
34
|
-
"isFullscreen": "panneau-app-resource-form-header-isFullscreen"
|
35
|
-
};
|
36
|
-
var messages = (0, _reactIntl.defineMessages)({
|
37
|
-
switchType: {
|
38
|
-
id: 'app.buttons.resources.switch_type',
|
39
|
-
description: 'The label of the select type button',
|
40
|
-
defaultMessage: 'Switch type'
|
41
|
-
},
|
42
|
-
confirmSwitchType: {
|
43
|
-
id: 'app.resources.form.confirm_switch_type',
|
44
|
-
description: 'The confirm message when switching type',
|
45
|
-
defaultMessage: 'Are you sure you want to switch type?'
|
46
|
-
}
|
47
|
-
});
|
48
|
-
var propTypes = {
|
49
|
-
intl: _core.PropTypes.intl.isRequired,
|
50
|
-
action: _propTypes["default"].string,
|
51
|
-
type: _propTypes["default"].definitionFormType,
|
52
|
-
fullscreen: _core.PropTypes.bool,
|
53
|
-
resource: _core.PropTypes.resource.isRequired,
|
54
|
-
title: _core.PropTypes.label.isRequired,
|
55
|
-
titleTyped: _core.PropTypes.label.isRequired,
|
56
|
-
valueHasChanged: _propTypes["default"].bool,
|
57
|
-
confirmSwitchTypeMessage: _core.PropTypes.label
|
58
|
-
};
|
59
|
-
var defaultProps = {
|
60
|
-
action: 'create',
|
61
|
-
type: null,
|
62
|
-
confirmSwitchTypeMessage: messages.confirmSwitchType,
|
63
|
-
fullscreen: false,
|
64
|
-
valueHasChanged: false
|
65
|
-
};
|
66
|
-
|
67
|
-
var ResourceFormHeader = function ResourceFormHeader(_ref) {
|
68
|
-
var intl = _ref.intl,
|
69
|
-
resource = _ref.resource,
|
70
|
-
type = _ref.type,
|
71
|
-
fullscreen = _ref.fullscreen,
|
72
|
-
action = _ref.action,
|
73
|
-
title = _ref.title,
|
74
|
-
titleTyped = _ref.titleTyped,
|
75
|
-
valueHasChanged = _ref.valueHasChanged,
|
76
|
-
confirmSwitchTypeMessage = _ref.confirmSwitchTypeMessage;
|
77
|
-
var urlGenerator = (0, _contexts.useUrlGenerator)();
|
78
|
-
var localizedName = resource.localizedName('a');
|
79
|
-
var resourceTitle = (0, _react.useMemo)(function () {
|
80
|
-
var customTitle = type !== null ? resource.message("titles.resources.".concat(action, "_").concat(type.id)) || resource.message("titles.resources.".concat(action, "_typed")) || resource.message("titles.resources.".concat(action)) || resource.message('titles.resources.default', null) : resource.message("titles.resources.".concat(action)) || resource.message('titles.resources.default', null);
|
81
|
-
var defaultTitle = type !== null ? titleTyped : title;
|
82
|
-
return customTitle || defaultTitle;
|
83
|
-
}, [resource, action, type]);
|
84
|
-
|
85
|
-
var titleElement = _react["default"].createElement("h1", {
|
86
|
-
className: (0, _classnames["default"])(['mb-0', 'mt-0', styles.title])
|
87
|
-
}, _react["default"].createElement(_components.Label, {
|
88
|
-
isHtml: true,
|
89
|
-
values: {
|
90
|
-
name: localizedName,
|
91
|
-
type: type !== null ? (0, _utils.getLocalizedName)(type) : null
|
92
|
-
}
|
93
|
-
}, resourceTitle));
|
94
|
-
|
95
|
-
var onClickSwitchType = function onClickSwitchType(e) {
|
96
|
-
var confirmMessage = (0, _utils.isMessage)(confirmSwitchTypeMessage) ? intl.formatMessage(confirmSwitchTypeMessage, {
|
97
|
-
type: (0, _utils.getLocalizedName)(type)
|
98
|
-
}) : confirmSwitchTypeMessage; // eslint-disable-next-line no-alert
|
99
|
-
|
100
|
-
if (valueHasChanged && !window.confirm(confirmMessage)) {
|
101
|
-
e.preventDefault();
|
102
|
-
}
|
103
|
-
};
|
104
|
-
|
105
|
-
return _react["default"].createElement("div", {
|
106
|
-
className: (0, _classnames["default"])([styles.header, (0, _defineProperty2["default"])({
|
107
|
-
'py-4': !fullscreen,
|
108
|
-
'px-2': fullscreen,
|
109
|
-
'py-3': fullscreen
|
110
|
-
}, styles.isFullscreen, fullscreen)])
|
111
|
-
}, type !== null && action === 'create' ? _react["default"].createElement("div", {
|
112
|
-
className: (0, _classnames["default"])(['row', 'no-gutters', 'align-items-center'])
|
113
|
-
}, _react["default"].createElement("div", {
|
114
|
-
className: "col"
|
115
|
-
}, titleElement), _react["default"].createElement("div", {
|
116
|
-
className: (0, _classnames["default"])(['col', 'col-md-auto', 'text-right'])
|
117
|
-
}, _react["default"].createElement(_components.Button, {
|
118
|
-
size: "sm",
|
119
|
-
dropdown: resource.types().map(function (_ref3) {
|
120
|
-
var id = _ref3.id,
|
121
|
-
typeProps = (0, _objectWithoutProperties2["default"])(_ref3, ["id"]);
|
122
|
-
return {
|
123
|
-
label: (0, _utils.getLocalizedName)(typeProps),
|
124
|
-
href: "".concat(urlGenerator.resource(resource, 'create'), "?type=").concat(id),
|
125
|
-
active: id === type.id,
|
126
|
-
onClick: onClickSwitchType
|
127
|
-
};
|
128
|
-
})
|
129
|
-
}, messages.switchType))) : titleElement);
|
130
|
-
};
|
131
|
-
|
132
|
-
ResourceFormHeader.propTypes = propTypes;
|
133
|
-
ResourceFormHeader.defaultProps = defaultProps;
|
134
|
-
|
135
|
-
var _default = (0, _reactIntl.injectIntl)(ResourceFormHeader);
|
136
|
-
|
137
|
-
exports["default"] = _default;
|
@@ -1,87 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
6
|
-
value: true
|
7
|
-
});
|
8
|
-
exports["default"] = void 0;
|
9
|
-
|
10
|
-
var _react = _interopRequireDefault(require("react"));
|
11
|
-
|
12
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
13
|
-
|
14
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
15
|
-
|
16
|
-
var _core = require("@panneau/core");
|
17
|
-
|
18
|
-
var _utils = require("@panneau/core/utils");
|
19
|
-
|
20
|
-
var _components = require("@panneau/core/components");
|
21
|
-
|
22
|
-
/* eslint-disable jsx-a11y/anchor-is-valid, react/jsx-props-no-spreading */
|
23
|
-
var styles = {
|
24
|
-
"container": "panneau-app-resource-index-header-container",
|
25
|
-
"cols": "panneau-app-resource-index-header-cols",
|
26
|
-
"col": "panneau-app-resource-index-header-col"
|
27
|
-
};
|
28
|
-
var propTypes = {
|
29
|
-
resource: _core.PropTypes.resource.isRequired,
|
30
|
-
title: _core.PropTypes.label,
|
31
|
-
showAddButton: _propTypes["default"].bool,
|
32
|
-
addButtonLabel: _core.PropTypes.label,
|
33
|
-
getResourceActionUrl: _propTypes["default"].func.isRequired
|
34
|
-
};
|
35
|
-
var defaultProps = {
|
36
|
-
title: null,
|
37
|
-
showAddButton: true,
|
38
|
-
addButtonLabel: null
|
39
|
-
};
|
40
|
-
|
41
|
-
var ResourceIndexHeader = function ResourceIndexHeader(_ref) {
|
42
|
-
var resource = _ref.resource,
|
43
|
-
showAddButton = _ref.showAddButton,
|
44
|
-
title = _ref.title,
|
45
|
-
addButtonLabel = _ref.addButtonLabel,
|
46
|
-
getResourceActionUrl = _ref.getResourceActionUrl;
|
47
|
-
var isTyped = resource.type() === 'typed';
|
48
|
-
var resourceName = resource.localizedName('plural'); // Title
|
49
|
-
|
50
|
-
var resourceTitle = resource.message('titles.resources.index', _react["default"].createElement(_components.Label, {
|
51
|
-
values: {
|
52
|
-
name: resourceName
|
53
|
-
}
|
54
|
-
}, title)); // Add button
|
55
|
-
|
56
|
-
var resourceAddButtonLabel = resource.message('buttons.resources.add', _react["default"].createElement(_components.Label, {
|
57
|
-
values: {
|
58
|
-
name: resourceName
|
59
|
-
}
|
60
|
-
}, addButtonLabel));
|
61
|
-
return _react["default"].createElement("div", {
|
62
|
-
className: (0, _classnames["default"])(['py-4', styles.header])
|
63
|
-
}, _react["default"].createElement("div", {
|
64
|
-
className: styles.cols
|
65
|
-
}, _react["default"].createElement("div", {
|
66
|
-
className: styles.col
|
67
|
-
}, _react["default"].createElement("h1", {
|
68
|
-
className: (0, _classnames["default"])([styles.title, 'mb-0', 'mt-0'])
|
69
|
-
}, resourceTitle)), _react["default"].createElement("div", {
|
70
|
-
className: (0, _classnames["default"])([styles.col, 'text-right'])
|
71
|
-
}, showAddButton ? _react["default"].createElement(_components.Button, {
|
72
|
-
href: isTyped ? getResourceActionUrl('create') : null,
|
73
|
-
dropdown: isTyped ? resource.types().map(function (type) {
|
74
|
-
return {
|
75
|
-
href: "".concat(getResourceActionUrl('create'), "?type=").concat(type.id),
|
76
|
-
label: (0, _utils.getLocalizedName)(type)
|
77
|
-
};
|
78
|
-
}) : null
|
79
|
-
}, isTyped ? _react["default"].createElement(_react["default"].Fragment, null, resourceAddButtonLabel, " ", _react["default"].createElement("span", {
|
80
|
-
className: "caret"
|
81
|
-
})) : resourceAddButtonLabel) : null)));
|
82
|
-
};
|
83
|
-
|
84
|
-
ResourceIndexHeader.propTypes = propTypes;
|
85
|
-
ResourceIndexHeader.defaultProps = defaultProps;
|
86
|
-
var _default = ResourceIndexHeader;
|
87
|
-
exports["default"] = _default;
|
package/lib/defaults/routes.json
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"home": "/",
|
3
|
-
"resource.index": "/:resource",
|
4
|
-
"resource.show": "/:resource/:id",
|
5
|
-
"resource.create": "/:resource/create",
|
6
|
-
"resource.edit": "/:resource/:id/edit",
|
7
|
-
"resource.store": "/:resource",
|
8
|
-
"resource.update": "/:resource/:id",
|
9
|
-
"resource.delete": "/:resource/:id"
|
10
|
-
}
|
package/lib/lib/createStore.js
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
6
|
-
value: true
|
7
|
-
});
|
8
|
-
exports["default"] = void 0;
|
9
|
-
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
11
|
-
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
13
|
-
|
14
|
-
var _redux = require("redux");
|
15
|
-
|
16
|
-
var _reduxDevtoolsExtension = require("redux-devtools-extension");
|
17
|
-
|
18
|
-
var _reduxThunk = _interopRequireDefault(require("redux-thunk"));
|
19
|
-
|
20
|
-
var _reduxPromise = _interopRequireDefault(require("redux-promise"));
|
21
|
-
|
22
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
23
|
-
|
24
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
25
|
-
|
26
|
-
var _default = function _default(reducers, initialState) {
|
27
|
-
var middlewares = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
28
|
-
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
29
|
-
|
30
|
-
var options = _objectSpread({}, opts);
|
31
|
-
|
32
|
-
var reducer = (0, _redux.combineReducers)(reducers);
|
33
|
-
|
34
|
-
var enhancer = _redux.applyMiddleware.apply(void 0, (0, _toConsumableArray2["default"])(middlewares).concat([_reduxThunk["default"], _reduxPromise["default"]]));
|
35
|
-
|
36
|
-
if (process.env.NODE_ENV !== 'production') {
|
37
|
-
var _options$devTools = options.devTools,
|
38
|
-
devTools = _options$devTools === void 0 ? {} : _options$devTools;
|
39
|
-
var composeEnhancers = (0, _reduxDevtoolsExtension.composeWithDevTools)(devTools);
|
40
|
-
enhancer = composeEnhancers(enhancer);
|
41
|
-
}
|
42
|
-
|
43
|
-
return (0, _redux.createStore)(reducer, initialState, enhancer);
|
44
|
-
};
|
45
|
-
|
46
|
-
exports["default"] = _default;
|
@@ -1,43 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
6
|
-
value: true
|
7
|
-
});
|
8
|
-
exports["default"] = void 0;
|
9
|
-
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
-
|
12
|
-
var _AuthActions = require("../actions/AuthActions");
|
13
|
-
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
15
|
-
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
17
|
-
|
18
|
-
var initialState = {
|
19
|
-
user: null
|
20
|
-
};
|
21
|
-
|
22
|
-
var AuthReducer = function AuthReducer() {
|
23
|
-
var previousState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
|
24
|
-
var action = arguments.length > 1 ? arguments[1] : undefined;
|
25
|
-
var state = previousState;
|
26
|
-
|
27
|
-
switch (action.type) {
|
28
|
-
case _AuthActions.SET_USER:
|
29
|
-
{
|
30
|
-
return _objectSpread({}, state, {
|
31
|
-
user: action.payload
|
32
|
-
});
|
33
|
-
}
|
34
|
-
|
35
|
-
default:
|
36
|
-
{
|
37
|
-
return state;
|
38
|
-
}
|
39
|
-
}
|
40
|
-
};
|
41
|
-
|
42
|
-
var _default = AuthReducer;
|
43
|
-
exports["default"] = _default;
|
package/lib/reducers/index.js
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
6
|
-
value: true
|
7
|
-
});
|
8
|
-
exports["default"] = void 0;
|
9
|
-
|
10
|
-
var _AuthReducer = _interopRequireDefault(require("./AuthReducer"));
|
11
|
-
|
12
|
-
var _default = {
|
13
|
-
auth: _AuthReducer["default"]
|
14
|
-
};
|
15
|
-
exports["default"] = _default;
|
package/src/Panneau.js
DELETED
@@ -1,274 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { render as renderReact, hydrate as hydrateReact } from 'react-dom';
|
3
|
-
import EventEmitter from 'wolfy87-eventemitter';
|
4
|
-
import isObject from 'lodash/isObject';
|
5
|
-
import moment from 'moment';
|
6
|
-
import { ComponentsCollection } from '@panneau/core';
|
7
|
-
|
8
|
-
import PanneauComponent from './components/Panneau';
|
9
|
-
|
10
|
-
/**
|
11
|
-
* Panneau Application
|
12
|
-
*/
|
13
|
-
class Panneau extends EventEmitter {
|
14
|
-
static setDefaultComponentsCollection(componentsCollection, namespace) {
|
15
|
-
if (typeof namespace !== 'undefined') {
|
16
|
-
Panneau.defaultComponentsCollection.setComponents(componentsCollection, namespace);
|
17
|
-
} else {
|
18
|
-
Panneau.defaultComponentsCollection = componentsCollection;
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
static setDefaultLocaleMessages(locale, messages) {
|
23
|
-
if (isObject(locale)) {
|
24
|
-
Panneau.defaultLocaleMessages = {
|
25
|
-
...locale,
|
26
|
-
};
|
27
|
-
} else {
|
28
|
-
Panneau.defaultLocaleMessages = {
|
29
|
-
...Panneau.defaultLocaleMessages,
|
30
|
-
[locale]: {
|
31
|
-
...messages,
|
32
|
-
},
|
33
|
-
};
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
/**
|
38
|
-
* Create a new panneau environment
|
39
|
-
* @param {object} definition The definition of the Panneau instance
|
40
|
-
* @param {object} options Options for the new Panneau instance
|
41
|
-
*/
|
42
|
-
constructor(definition, options) {
|
43
|
-
super();
|
44
|
-
|
45
|
-
this.options = {};
|
46
|
-
|
47
|
-
this.onRendered = this.onRendered.bind(this);
|
48
|
-
this.onHydrated = this.onHydrated.bind(this);
|
49
|
-
|
50
|
-
this.element = null;
|
51
|
-
this.rendered = false;
|
52
|
-
this.definition = definition;
|
53
|
-
this.user = null;
|
54
|
-
this.locale = 'en';
|
55
|
-
this.messages = {};
|
56
|
-
this.componentsCollection = Panneau.defaultComponentsCollection;
|
57
|
-
this.setOptions(options);
|
58
|
-
}
|
59
|
-
|
60
|
-
onRendered() {
|
61
|
-
this.emit('rendered', this.element);
|
62
|
-
}
|
63
|
-
|
64
|
-
onHydrated() {
|
65
|
-
this.emit('hydrated', this.element);
|
66
|
-
}
|
67
|
-
|
68
|
-
render(element) {
|
69
|
-
this.rendered = true;
|
70
|
-
this.element = element || this.element;
|
71
|
-
const root = this.getRootElement();
|
72
|
-
renderReact(root, this.element, this.onRendered);
|
73
|
-
this.emit('render', this.element);
|
74
|
-
}
|
75
|
-
|
76
|
-
hydrate(element) {
|
77
|
-
this.rendered = false;
|
78
|
-
this.element = element || this.element;
|
79
|
-
const root = this.getRootElement();
|
80
|
-
hydrateReact(root, this.element, this.onHydrated);
|
81
|
-
this.emit('hydrate', this.element);
|
82
|
-
}
|
83
|
-
|
84
|
-
getRootProps() {
|
85
|
-
return {
|
86
|
-
componentsCollection: this.componentsCollection,
|
87
|
-
definition: this.definition,
|
88
|
-
user: this.user,
|
89
|
-
locale: this.locale,
|
90
|
-
messages: {
|
91
|
-
...this.messages,
|
92
|
-
},
|
93
|
-
};
|
94
|
-
}
|
95
|
-
|
96
|
-
getRootElement() {
|
97
|
-
const rootProps = this.getRootProps();
|
98
|
-
const rootElement = React.createElement(PanneauComponent, rootProps);
|
99
|
-
return rootElement;
|
100
|
-
}
|
101
|
-
|
102
|
-
/**
|
103
|
-
* Set the options
|
104
|
-
* @param {object} options The new options
|
105
|
-
* @return {this}
|
106
|
-
*/
|
107
|
-
setOptions(options = {}) {
|
108
|
-
const { user, locale, messages, componentsCollection, ...otherOptions } = options;
|
109
|
-
|
110
|
-
this.options = {
|
111
|
-
...this.options,
|
112
|
-
...otherOptions,
|
113
|
-
};
|
114
|
-
|
115
|
-
if (typeof locale !== 'undefined') {
|
116
|
-
this.setLocale(locale);
|
117
|
-
}
|
118
|
-
|
119
|
-
if (typeof componentsCollection !== 'undefined') {
|
120
|
-
this.setComponentsCollection(componentsCollection);
|
121
|
-
}
|
122
|
-
|
123
|
-
if (typeof messages !== 'undefined') {
|
124
|
-
this.setMessages(messages);
|
125
|
-
}
|
126
|
-
|
127
|
-
if (typeof user !== 'undefined') {
|
128
|
-
this.setUser(user);
|
129
|
-
}
|
130
|
-
|
131
|
-
if (this.rendered) {
|
132
|
-
this.render();
|
133
|
-
}
|
134
|
-
|
135
|
-
return this;
|
136
|
-
}
|
137
|
-
|
138
|
-
/**
|
139
|
-
* Get the options
|
140
|
-
* @return {object} The options
|
141
|
-
*/
|
142
|
-
getOptions() {
|
143
|
-
return this.options;
|
144
|
-
}
|
145
|
-
|
146
|
-
/**
|
147
|
-
* Set the definition
|
148
|
-
* @param {object} definition The new definition
|
149
|
-
* @return {this}
|
150
|
-
*/
|
151
|
-
setDefinition(definition) {
|
152
|
-
this.definition = definition;
|
153
|
-
return this;
|
154
|
-
}
|
155
|
-
|
156
|
-
/**
|
157
|
-
* Get the definition
|
158
|
-
* @return {object} The definition
|
159
|
-
*/
|
160
|
-
getDefinition() {
|
161
|
-
return this.definition;
|
162
|
-
}
|
163
|
-
|
164
|
-
/**
|
165
|
-
* Set the user
|
166
|
-
* @param {object} user The new user
|
167
|
-
* @return {this}
|
168
|
-
*/
|
169
|
-
setUser(user) {
|
170
|
-
this.user = user;
|
171
|
-
return this;
|
172
|
-
}
|
173
|
-
|
174
|
-
/**
|
175
|
-
* Get the user
|
176
|
-
* @return {object} The user
|
177
|
-
*/
|
178
|
-
getUser() {
|
179
|
-
return this.user;
|
180
|
-
}
|
181
|
-
|
182
|
-
/**
|
183
|
-
* Set the locale
|
184
|
-
* @param {string} locale The new locale
|
185
|
-
* @return {this}
|
186
|
-
*/
|
187
|
-
setLocale(locale) {
|
188
|
-
this.locale = locale;
|
189
|
-
moment.locale(locale);
|
190
|
-
return this;
|
191
|
-
}
|
192
|
-
|
193
|
-
/**
|
194
|
-
* Get the locale
|
195
|
-
* @return {string} The locale
|
196
|
-
*/
|
197
|
-
getLocale() {
|
198
|
-
return this.locale;
|
199
|
-
}
|
200
|
-
|
201
|
-
/**
|
202
|
-
* Set the messages
|
203
|
-
* @param {object} messages The new messages
|
204
|
-
* @return {this}
|
205
|
-
*/
|
206
|
-
setMessages(messages) {
|
207
|
-
this.messages = Object.keys(messages || {}).reduce(
|
208
|
-
(allMessages, key) => ({
|
209
|
-
...allMessages,
|
210
|
-
[key]: isObject(messages[key])
|
211
|
-
? {
|
212
|
-
...(isObject(allMessages[key] || null) ? allMessages[key] : null),
|
213
|
-
...messages[key],
|
214
|
-
}
|
215
|
-
: messages[key],
|
216
|
-
}),
|
217
|
-
{
|
218
|
-
...Panneau.defaultLocaleMessages,
|
219
|
-
},
|
220
|
-
);
|
221
|
-
return this;
|
222
|
-
}
|
223
|
-
|
224
|
-
/**
|
225
|
-
* Get the messages
|
226
|
-
* @return {object} The messages
|
227
|
-
*/
|
228
|
-
getMessages() {
|
229
|
-
return this.messages;
|
230
|
-
}
|
231
|
-
|
232
|
-
/**
|
233
|
-
* Alias to work with components collection
|
234
|
-
* @return {ComponentsCollection} The components collection
|
235
|
-
*/
|
236
|
-
components(key, value) {
|
237
|
-
if (typeof value !== 'undefined') {
|
238
|
-
this.componentsCollection.addComponent(key, value);
|
239
|
-
return this;
|
240
|
-
}
|
241
|
-
if (typeof key !== 'undefined') {
|
242
|
-
return this.componentsCollection.getComponent(key);
|
243
|
-
}
|
244
|
-
return this.componentsCollection;
|
245
|
-
}
|
246
|
-
|
247
|
-
/**
|
248
|
-
* Set the components collection
|
249
|
-
* @param {ComponentsCollection} fieldsCollection The new fields collection
|
250
|
-
*/
|
251
|
-
setComponentsCollection(componentsCollection, namespace) {
|
252
|
-
if (typeof namespace !== 'undefined') {
|
253
|
-
this.componentsCollection.setComponents(componentsCollection, namespace);
|
254
|
-
} else {
|
255
|
-
this.componentsCollection = componentsCollection;
|
256
|
-
}
|
257
|
-
return this;
|
258
|
-
}
|
259
|
-
|
260
|
-
/**
|
261
|
-
* Get the components collection
|
262
|
-
* @return {ComponentsCollection} The fields collection used by this instance
|
263
|
-
*/
|
264
|
-
getComponentsCollection(namespace) {
|
265
|
-
return typeof namespace !== 'undefined'
|
266
|
-
? this.componentsCollection.getCollection(namespace)
|
267
|
-
: this.componentsCollection;
|
268
|
-
}
|
269
|
-
}
|
270
|
-
|
271
|
-
Panneau.defaultComponentsCollection = new ComponentsCollection();
|
272
|
-
Panneau.defaultLocaleMessages = {};
|
273
|
-
|
274
|
-
export default Panneau;
|