blue-react 9.12.0 → 10.0.0-rc1

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/README.md CHANGED
@@ -9,11 +9,40 @@
9
9
  [Checkout the docs](https://bruegmann.github.io/blue-react) to find out how to
10
10
  use Blue React.
11
11
 
12
- ## Breaking changes between v8 and v9
12
+ ## Breaking changes between v9 and v10
13
13
 
14
- - Renamed `.caret` ➡️ `.blue-caret`
15
- - Removed `.switch` CSS
16
- - Removed deprecated DocumentView
14
+ ### Removed hash router from Layout
15
+
16
+ The new `Layout` no longer has a hash router. So there is no `pages` prop anymore. The router moved to its own component `HashRouter` for legacy reasons. But it's recommended to use other solutions like [React Router](https://reactrouter.com/) or [TanStack Router](https://tanstack.com/router/latest).
17
+
18
+ ### Move side content to `side` prop
19
+
20
+ It should look like this:
21
+
22
+ ```tsx
23
+ <Layout
24
+ side={
25
+ <SidebarMenu>
26
+ <MenuItem href="." label="Home" />
27
+ </SidebarMenu>
28
+ }
29
+ >
30
+ Your page content
31
+ </Layout>
32
+ ```
33
+
34
+ ### Removed HTML elements for status
35
+
36
+ If you use util functions for status like `showSuccess()` or `setAlertMessage()` you need to embed the `Status` React component like this:
37
+
38
+ ```tsx
39
+ <Status
40
+ dangerIcon={<XCircleFill />}
41
+ infoIcon={<InfoCircleFill />}
42
+ successIcon={<CheckCircleFill />}
43
+ warningIcon={<ExclamationCircleFill />}
44
+ />
45
+ ```
17
46
 
18
47
  ## Developing
19
48
 
@@ -23,6 +23,7 @@ function Chevron(_ref) {
23
23
  mirrored = _ref.mirrored,
24
24
  className = _ref.className,
25
25
  style = _ref.style;
26
+ var prefersReducedMotion = window.matchMedia("(prefers-reduced-motion)").matches;
26
27
  return /*#__PURE__*/_react.default.createElement("svg", {
27
28
  xmlns: "http://www.w3.org/2000/svg",
28
29
  width: "1em",
@@ -33,7 +34,7 @@ function Chevron(_ref) {
33
34
  display: "inline-block",
34
35
  verticalAlign: "-0.125em",
35
36
  transform: "rotate(".concat(open && mirrored ? -90 : open ? 90 : 0, "deg)"),
36
- transition: "transform 0.2s"
37
+ transition: prefersReducedMotion ? "none" : "transform 0.2s"
37
38
  }),
38
39
  viewBox: "0 0 16 16"
39
40
  }, mirrored ? /*#__PURE__*/_react.default.createElement("path", {
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _react = _interopRequireWildcard(require("react"));
11
+
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+
14
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+
16
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
+
18
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
19
+
20
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
21
+
22
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
23
+
24
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
25
+
26
+ 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); }; }
27
+
28
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
29
+
30
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
31
+
32
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
33
+
34
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
35
+
36
+ window.toggleSidebarEvent = new CustomEvent("toggleSidebar");
37
+
38
+ /**
39
+ * Component for simple hash routing. It's recommended to use solutions like `react-router-dom` for more complex routing.
40
+ *
41
+ * As soon this component is mounted, it is globally available under `window.blueHashRouterRef`.
42
+ * You can also append your own event listeners.
43
+ *
44
+ * Allowed events:
45
+ *
46
+ * * **componentDidUpdate** - Component was updated.
47
+ * Example: `window.blueHashRouterRef.addEventListener("componentDidUpdate", (prevProps, prevState) => { })`
48
+ * * **pageDidShowAgain** - Page appeared again with the same old state. In the callback function you can reinitialize things.
49
+ * Example: `window.blueHashRouterRef.addEventListener("pageDidShowAgain", "home", (prevProps, prevState) => { })`
50
+ * * **pageDidHide** - This page disappeared and another page appears instead.
51
+ * Example: `window.blueHashRouterRef.addEventListener("pageDidHide", "home", (prevProps, prevState) => { })`
52
+ *
53
+ * Method to add event listeners:
54
+ * * `window.blueHashRouterRef.`**addEventListener**`(eventName: string, param2: any, param3: any, listenerId?: string)`
55
+ *
56
+ * Methods to remove event listeners:
57
+ * * `window.blueHashRouterRef.`**removeEventListener**`(eventName: string, listenerId: string)`
58
+ * * `window.blueHashRouterRef.`**removeDuplicatedEventListeners**`()` - Will automatically be called when running `addEventListener`
59
+ */
60
+ var HashRouter = /*#__PURE__*/function (_Component) {
61
+ _inherits(HashRouter, _Component);
62
+
63
+ var _super = _createSuper(HashRouter);
64
+
65
+ function HashRouter(props) {
66
+ var _this;
67
+
68
+ _classCallCheck(this, HashRouter);
69
+
70
+ _this = _super.call(this, props);
71
+ window.blueHashRouterRef = _assertThisInitialized(_this);
72
+ _this.defaultMatch = ["home"];
73
+ _this.state = {
74
+ match: null,
75
+ history: [],
76
+ hash: window.location.hash,
77
+ hashHistory: [],
78
+ blockRouting: props.blockRouting || undefined
79
+ };
80
+ _this.eventListeners = [];
81
+ return _this;
82
+ }
83
+
84
+ _createClass(HashRouter, [{
85
+ key: "onHashChange",
86
+ value: function onHashChange() {
87
+ window.blueHashRouterRef.initMatch();
88
+ }
89
+ }, {
90
+ key: "componentDidMount",
91
+ value: function componentDidMount() {
92
+ this.initMatch();
93
+ window.addEventListener("hashchange", this.onHashChange);
94
+ }
95
+ }, {
96
+ key: "componentWillUnmount",
97
+ value: function componentWillUnmount() {
98
+ window.removeEventListener("hashchange", this.onHashChange);
99
+ }
100
+ }, {
101
+ key: "componentDidUpdate",
102
+ value: function componentDidUpdate(prevProps, prevState) {
103
+ var _this2 = this;
104
+
105
+ if (prevProps.blockRouting !== this.props.blockRouting && this.props.blockRouting !== this.state.blockRouting) {
106
+ this.setState({
107
+ blockRouting: this.props.blockRouting
108
+ });
109
+ }
110
+
111
+ this.eventListeners.forEach(function (eventListener) {
112
+ if (eventListener[0] === "componentDidUpdate") {
113
+ eventListener[1](prevProps, prevState);
114
+ }
115
+
116
+ if (eventListener[0] === "pageDidShowAgain") {
117
+ var pageId = eventListener[1];
118
+ var callback = eventListener[2];
119
+
120
+ if (prevState.hash !== _this2.state.hash && _this2.state.match[0] === pageId) {
121
+ callback(prevProps, prevState);
122
+ }
123
+ }
124
+
125
+ if (eventListener[0] === "pageDidHide") {
126
+ var _pageId = eventListener[1];
127
+ var _callback = eventListener[2];
128
+
129
+ if (prevState.hash !== _this2.state.hash && prevState.match[0] === _pageId) {
130
+ _callback(prevProps, prevState);
131
+ }
132
+ }
133
+ });
134
+ }
135
+ }, {
136
+ key: "initMatch",
137
+ value: function initMatch() {
138
+ var newMatch;
139
+
140
+ if (window.location.hash && window.location.hash !== "" && window.location.hash !== "#/") {
141
+ newMatch = window.location.hash.replace("#", "").split("/").filter(function (n) {
142
+ return n !== "";
143
+ });
144
+ } else {
145
+ newMatch = this.defaultMatch;
146
+ }
147
+
148
+ if (this.props.unrouteable) {
149
+ newMatch = this.defaultMatch;
150
+ }
151
+
152
+ if (this.state.blockRouting && this.state.blockRouting(newMatch, this.state.match) === true) {
153
+ window.location.hash = this.state.hash;
154
+ } else {
155
+ if (!(this.state.history.indexOf(newMatch[0]) > -1)) {
156
+ this.state.history.push(newMatch[0]);
157
+ }
158
+
159
+ this.setState({
160
+ match: newMatch,
161
+ history: this.state.history,
162
+ hash: window.location.hash,
163
+ hashHistory: this.state.hashHistory.concat([window.location.hash])
164
+ });
165
+ }
166
+ }
167
+ }, {
168
+ key: "addEventListener",
169
+ value: function addEventListener(param1, param2, param3, listenerId) {
170
+ this.eventListeners.push([param1, param2, param3, listenerId]);
171
+ this.removeDuplicatedEventListeners();
172
+ }
173
+ }, {
174
+ key: "removeEventListener",
175
+ value: function removeEventListener(type, listenerId) {
176
+ this.eventListeners = this.eventListeners.filter(function (param) {
177
+ if (param[0] !== type) {
178
+ return param;
179
+ } else if (param[0] === type && param[3] !== listenerId) {
180
+ return param;
181
+ }
182
+ });
183
+ }
184
+ }, {
185
+ key: "removeDuplicatedEventListeners",
186
+ value: function removeDuplicatedEventListeners() {
187
+ this.eventListeners = this.eventListeners.filter(function (value, index, self) {
188
+ return index === self.findIndex(function (t) {
189
+ return t[3] === value[3] && t[0] === value[0];
190
+ });
191
+ });
192
+ }
193
+ }, {
194
+ key: "render",
195
+ value: function render() {
196
+ var _this$props$pages,
197
+ _this3 = this;
198
+
199
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, (_this$props$pages = this.props.pages) === null || _this$props$pages === void 0 ? void 0 : _this$props$pages.map(function (page) {
200
+ return _this3.state.history.indexOf(page.name) > -1 && /*#__PURE__*/_react.default.createElement("div", {
201
+ key: page.name,
202
+ className: "router-page " + (_this3.state.match[0] === page.name ? "active" : "d-none")
203
+ }, page.component);
204
+ }));
205
+ }
206
+ }], [{
207
+ key: "defaultProps",
208
+ get: function get() {
209
+ return {
210
+ unrouteable: false,
211
+ disableTitleSet: false
212
+ };
213
+ }
214
+ }]);
215
+
216
+ return HashRouter;
217
+ }(_react.Component);
218
+
219
+ exports.default = HashRouter;
@@ -36,7 +36,7 @@ function HeaderTitle(_ref) {
36
36
  var uniqueId = "HeaderTitle-" + (0, _utils.guid)();
37
37
 
38
38
  var setDocumentTitle = function setDocumentTitle() {
39
- if (window.blueLayoutRef && window.blueLayoutRef.props && window.blueLayoutRef.props.disableTitleSet === false) {
39
+ if (window.blueHashRouterRef && window.blueHashRouterRef.props && window.blueHashRouterRef.props.disableTitleSet === false) {
40
40
  var element = document.querySelector("#".concat(uniqueId, " .blue-header-title-labels"));
41
41
  var titleElement = document.querySelector("title");
42
42