@common-stack/client-react 0.1.21 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/lib/__tests__/fill-register-test.d.ts +1 -0
  2. package/lib/__tests__/fill-register-test.js +66 -0
  3. package/lib/__tests__/fill-register-test.js.map +1 -0
  4. package/lib/__tests__/helpers/sample-menu.d.ts +79 -0
  5. package/lib/__tests__/helpers/sample-menu.js +78 -0
  6. package/lib/__tests__/helpers/sample-menu.js.map +1 -0
  7. package/lib/__tests__/integrated-routes.test.d.ts +1 -0
  8. package/lib/__tests__/integrated-routes.test.js +83 -0
  9. package/lib/__tests__/integrated-routes.test.js.map +1 -0
  10. package/lib/__tests__/render-routes.test.d.ts +3 -0
  11. package/lib/__tests__/render-routes.test.js +89 -0
  12. package/lib/__tests__/render-routes.test.js.map +1 -0
  13. package/lib/connector/base-connector.d.ts +52 -0
  14. package/lib/connector/base-connector.js +148 -0
  15. package/lib/connector/base-connector.js.map +1 -0
  16. package/lib/connector/connector.d.ts +7 -43
  17. package/lib/connector/connector.js +15 -0
  18. package/lib/connector/connector.js.map +1 -0
  19. package/lib/connector/connector.native.d.ts +7 -0
  20. package/lib/connector/connector.native.js +14 -0
  21. package/lib/connector/connector.native.js.map +1 -0
  22. package/lib/connector/connector.test.d.ts +1 -0
  23. package/lib/connector/connector.test.js +32 -0
  24. package/lib/connector/connector.test.js.map +1 -0
  25. package/lib/connector/index.js +14 -0
  26. package/lib/connector/index.js.map +1 -0
  27. package/lib/index.d.ts +1 -2
  28. package/lib/index.js +9 -2147
  29. package/lib/index.js.map +1 -1
  30. package/lib/index.native.d.ts +9 -0
  31. package/lib/index.native.js +24 -0
  32. package/lib/index.native.js.map +1 -0
  33. package/lib/interfaces/extended-feature.js +3 -0
  34. package/lib/interfaces/extended-feature.js.map +1 -0
  35. package/lib/interfaces/index.js +17 -0
  36. package/lib/interfaces/index.js.map +1 -0
  37. package/lib/interfaces/menu.js +12 -0
  38. package/lib/interfaces/menu.js.map +1 -0
  39. package/lib/interfaces/new-router.d.ts +18 -1
  40. package/lib/interfaces/new-router.js +3 -0
  41. package/lib/interfaces/new-router.js.map +1 -0
  42. package/lib/interfaces/router.js +3 -0
  43. package/lib/interfaces/router.js.map +1 -0
  44. package/lib/inversify/InversifyContext.js +37 -0
  45. package/lib/inversify/InversifyContext.js.map +1 -0
  46. package/lib/inversify/index.js +14 -0
  47. package/lib/inversify/index.js.map +1 -0
  48. package/lib/plugin-area/__tests__/higher-order-component-util.test.d.ts +1 -0
  49. package/lib/plugin-area/__tests__/higher-order-component-util.test.js +60 -0
  50. package/lib/plugin-area/__tests__/higher-order-component-util.test.js.map +1 -0
  51. package/lib/plugin-area/__tests__/plugin-api.test.d.ts +1 -0
  52. package/lib/plugin-area/__tests__/plugin-api.test.js +54 -0
  53. package/lib/plugin-area/__tests__/plugin-api.test.js.map +1 -0
  54. package/lib/plugin-area/{plugin-area.d.ts → base-plugin-area.d.ts} +1 -1
  55. package/lib/plugin-area/base-plugin-area.js +68 -0
  56. package/lib/plugin-area/base-plugin-area.js.map +1 -0
  57. package/lib/plugin-area/higher-order-component-util.js +23 -0
  58. package/lib/plugin-area/higher-order-component-util.js.map +1 -0
  59. package/lib/plugin-area/index.d.ts +2 -2
  60. package/lib/plugin-area/index.js +34 -0
  61. package/lib/plugin-area/index.js.map +1 -0
  62. package/lib/plugin-area/index.native.d.ts +2 -0
  63. package/lib/plugin-area/index.native.js +31 -0
  64. package/lib/plugin-area/index.native.js.map +1 -0
  65. package/lib/plugin-area/plugin-api.js +79 -0
  66. package/lib/plugin-area/plugin-api.js.map +1 -0
  67. package/lib/plugin-area/plugin-context.js +44 -0
  68. package/lib/plugin-area/plugin-context.js.map +1 -0
  69. package/lib/route/__tests__/admin-new-routes.test.d.ts +1 -0
  70. package/lib/route/__tests__/admin-new-routes.test.js +175 -0
  71. package/lib/route/__tests__/admin-new-routes.test.js.map +1 -0
  72. package/lib/route/__tests__/config-routes.test.d.ts +0 -0
  73. package/lib/route/__tests__/config-routes.test.js +326 -0
  74. package/lib/route/__tests__/config-routes.test.js.map +1 -0
  75. package/lib/route/__tests__/getFlatMenus.test.d.ts +1 -0
  76. package/lib/route/__tests__/getFlatMenus.test.js +96 -0
  77. package/lib/route/__tests__/getFlatMenus.test.js.map +1 -0
  78. package/lib/route/__tests__/render-routes-config.test.d.ts +2 -0
  79. package/lib/route/__tests__/render-routes-config.test.js +69 -0
  80. package/lib/route/__tests__/render-routes-config.test.js.map +1 -0
  81. package/lib/route/__tests__/route-type.test.d.ts +1 -0
  82. package/lib/route/__tests__/route-type.test.js +9 -0
  83. package/lib/route/__tests__/route-type.test.js.map +1 -0
  84. package/lib/route/get-routes.d.ts +3 -0
  85. package/lib/route/get-routes.js +86 -0
  86. package/lib/route/get-routes.js.map +1 -0
  87. package/lib/route/get-routes.test.d.ts +1 -0
  88. package/lib/route/get-routes.test.js +170 -0
  89. package/lib/route/get-routes.test.js.map +1 -0
  90. package/lib/route/index.js +14 -0
  91. package/lib/route/index.js.map +1 -0
  92. package/lib/route/index.native.d.ts +1 -0
  93. package/lib/route/index.native.js +14 -0
  94. package/lib/route/index.native.js.map +1 -0
  95. package/lib/route/old/__tests__/config-sidebar-menu.test.d.ts +1 -0
  96. package/lib/route/old/__tests__/config-sidebar-menu.test.js +198 -0
  97. package/lib/route/old/__tests__/config-sidebar-menu.test.js.map +1 -0
  98. package/lib/route/old/get-menus.d.ts +2 -0
  99. package/lib/route/old/get-menus.js +63 -0
  100. package/lib/route/old/get-menus.js.map +1 -0
  101. package/lib/route/old/get-routes-notused.d.ts +11 -0
  102. package/lib/route/old/get-routes-notused.js +61 -0
  103. package/lib/route/old/get-routes-notused.js.map +1 -0
  104. package/lib/route/old/render.d.ts +2 -0
  105. package/lib/route/old/render.js +30 -0
  106. package/lib/route/old/render.js.map +1 -0
  107. package/lib/route/render-routes-test.d.ts +1 -0
  108. package/lib/route/render-routes-test.js +40 -0
  109. package/lib/route/render-routes-test.js.map +1 -0
  110. package/lib/route/render-routes.d.ts +2 -14
  111. package/lib/route/render-routes.js +164 -0
  112. package/lib/route/render-routes.js.map +1 -0
  113. package/lib/route/render-routes.native.d.ts +4 -0
  114. package/lib/route/render-routes.native.js +158 -0
  115. package/lib/route/render-routes.native.js.map +1 -0
  116. package/lib/route-based-plugin-area/__tests__/higher-order-component-util.test.d.ts +1 -0
  117. package/lib/route-based-plugin-area/__tests__/higher-order-component-util.test.js +60 -0
  118. package/lib/route-based-plugin-area/__tests__/higher-order-component-util.test.js.map +1 -0
  119. package/lib/route-based-plugin-area/__tests__/plugin-api.test.d.ts +1 -0
  120. package/lib/route-based-plugin-area/__tests__/plugin-api.test.js +54 -0
  121. package/lib/route-based-plugin-area/__tests__/plugin-api.test.js.map +1 -0
  122. package/lib/route-based-plugin-area/higher-order-component-util.js +23 -0
  123. package/lib/route-based-plugin-area/higher-order-component-util.js.map +1 -0
  124. package/lib/route-based-plugin-area/index.js +15 -0
  125. package/lib/route-based-plugin-area/index.js.map +1 -0
  126. package/lib/route-based-plugin-area/plugin-api.js +79 -0
  127. package/lib/route-based-plugin-area/plugin-api.js.map +1 -0
  128. package/lib/route-based-plugin-area/plugin-context.js +44 -0
  129. package/lib/route-based-plugin-area/plugin-context.js.map +1 -0
  130. package/lib/route-based-plugin-area/route-based-plugin-area.js +68 -0
  131. package/lib/route-based-plugin-area/route-based-plugin-area.js.map +1 -0
  132. package/lib/{router/router.d.ts → router-factory/index.d.ts} +0 -0
  133. package/lib/router-factory/index.js +30 -0
  134. package/lib/router-factory/index.js.map +1 -0
  135. package/lib/router-factory/index.native.d.ts +2 -0
  136. package/lib/router-factory/index.native.js +30 -0
  137. package/lib/router-factory/index.native.js.map +1 -0
  138. package/lib/utils/index.d.ts +2 -1
  139. package/lib/utils/index.js +15 -0
  140. package/lib/utils/index.js.map +1 -0
  141. package/lib/utils/sort-keys.d.ts +1 -0
  142. package/lib/utils/sort-keys.js +73 -0
  143. package/lib/utils/sort-keys.js.map +1 -0
  144. package/lib/utils/sort-keys.test.d.ts +1 -0
  145. package/lib/utils/sort-keys.test.js +30 -0
  146. package/lib/utils/sort-keys.test.js.map +1 -0
  147. package/lib/utils/utils.d.ts +4 -0
  148. package/lib/utils/utils.js +13 -0
  149. package/lib/utils/utils.js.map +1 -0
  150. package/package.json +7 -6
  151. package/lib/plugin-area/browser-plugin-area.d.ts +0 -2
  152. package/lib/router/index.d.ts +0 -1
  153. package/lib/slot-fill/context.d.ts +0 -94
  154. package/lib/slot-fill/fill.d.ts +0 -10
  155. package/lib/slot-fill/index.d.ts +0 -4
  156. package/lib/slot-fill/slot.d.ts +0 -8
  157. package/lib/slot-fill/utils/index.d.ts +0 -1
  158. package/lib/slot-fill/utils/isEmptyElement.d.ts +0 -8
  159. package/lib/utils/route-utils.d.ts +0 -17
package/lib/index.js CHANGED
@@ -1,275 +1,4 @@
1
- module.exports =
2
- /******/ (function(modules) { // webpackBootstrap
3
- /******/ // The module cache
4
- /******/ var installedModules = {};
5
- /******/
6
- /******/ // The require function
7
- /******/ function __webpack_require__(moduleId) {
8
- /******/
9
- /******/ // Check if module is in cache
10
- /******/ if(installedModules[moduleId]) {
11
- /******/ return installedModules[moduleId].exports;
12
- /******/ }
13
- /******/ // Create a new module (and put it into the cache)
14
- /******/ var module = installedModules[moduleId] = {
15
- /******/ i: moduleId,
16
- /******/ l: false,
17
- /******/ exports: {}
18
- /******/ };
19
- /******/
20
- /******/ // Execute the module function
21
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
22
- /******/
23
- /******/ // Flag the module as loaded
24
- /******/ module.l = true;
25
- /******/
26
- /******/ // Return the exports of the module
27
- /******/ return module.exports;
28
- /******/ }
29
- /******/
30
- /******/
31
- /******/ // expose the modules object (__webpack_modules__)
32
- /******/ __webpack_require__.m = modules;
33
- /******/
34
- /******/ // expose the module cache
35
- /******/ __webpack_require__.c = installedModules;
36
- /******/
37
- /******/ // define getter function for harmony exports
38
- /******/ __webpack_require__.d = function(exports, name, getter) {
39
- /******/ if(!__webpack_require__.o(exports, name)) {
40
- /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
41
- /******/ }
42
- /******/ };
43
- /******/
44
- /******/ // define __esModule on exports
45
- /******/ __webpack_require__.r = function(exports) {
46
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
47
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
48
- /******/ }
49
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
50
- /******/ };
51
- /******/
52
- /******/ // create a fake namespace object
53
- /******/ // mode & 1: value is a module id, require it
54
- /******/ // mode & 2: merge all properties of value into the ns
55
- /******/ // mode & 4: return value when already ns object
56
- /******/ // mode & 8|1: behave like require
57
- /******/ __webpack_require__.t = function(value, mode) {
58
- /******/ if(mode & 1) value = __webpack_require__(value);
59
- /******/ if(mode & 8) return value;
60
- /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
61
- /******/ var ns = Object.create(null);
62
- /******/ __webpack_require__.r(ns);
63
- /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
64
- /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
65
- /******/ return ns;
66
- /******/ };
67
- /******/
68
- /******/ // getDefaultExport function for compatibility with non-harmony modules
69
- /******/ __webpack_require__.n = function(module) {
70
- /******/ var getter = module && module.__esModule ?
71
- /******/ function getDefault() { return module['default']; } :
72
- /******/ function getModuleExports() { return module; };
73
- /******/ __webpack_require__.d(getter, 'a', getter);
74
- /******/ return getter;
75
- /******/ };
76
- /******/
77
- /******/ // Object.prototype.hasOwnProperty.call
78
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
79
- /******/
80
- /******/ // __webpack_public_path__
81
- /******/ __webpack_require__.p = "";
82
- /******/
83
- /******/
84
- /******/ // Load entry module and return exports
85
- /******/ return __webpack_require__(__webpack_require__.s = "./src/index.ts");
86
- /******/ })
87
- /************************************************************************/
88
- /******/ ({
89
-
90
- /***/ "./src/connector/connector.tsx":
91
- /*!*************************************!*\
92
- !*** ./src/connector/connector.tsx ***!
93
- \*************************************/
94
- /*! no static exports found */
95
- /***/ (function(module, exports, __webpack_require__) {
96
-
97
1
  "use strict";
98
-
99
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
100
- if (k2 === undefined) k2 = k;
101
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
102
- }) : (function(o, m, k, k2) {
103
- if (k2 === undefined) k2 = k;
104
- o[k2] = m[k];
105
- }));
106
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
107
- Object.defineProperty(o, "default", { enumerable: true, value: v });
108
- }) : function(o, v) {
109
- o["default"] = v;
110
- });
111
- var __importStar = (this && this.__importStar) || function (mod) {
112
- if (mod && mod.__esModule) return mod;
113
- var result = {};
114
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
115
- __setModuleDefault(result, mod);
116
- return result;
117
- };
118
- Object.defineProperty(exports, "__esModule", { value: true });
119
- exports.Feature = void 0;
120
- const React = __importStar(__webpack_require__(/*! react */ "react"));
121
- const client_core_1 = __webpack_require__(/*! @common-stack/client-core */ "@common-stack/client-core");
122
- const utils_1 = __webpack_require__(/*! ../utils */ "./src/utils/index.ts");
123
- const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
124
- const plugin_area_1 = __webpack_require__(/*! ../plugin-area */ "./src/plugin-area/index.ts");
125
- const combine = (features, extractor) => lodash_1.without(lodash_1.union(...lodash_1.map(features, res => lodash_1.castArray(extractor(res)))), undefined);
126
- const getFirst = (features, extractor) => extractor(lodash_1.find(features, (res) => extractor(res)) || {});
127
- class Feature extends client_core_1.AbstractFeature {
128
- constructor(feature,
129
- // tslint:disable:trailing-comma
130
- ...features) {
131
- super(feature, ...features);
132
- /* tslint:disable:jsx-no-lambda */
133
- this.renderRoutes = utils_1.renderRoutes;
134
- this.sortMenusByPriority = (menus) => {
135
- return lodash_1.sortBy(menus, (obj) => parseInt(obj.priority, 10));
136
- };
137
- this.sortMenus = (sortByPriority, menus) => {
138
- if (sortByPriority) {
139
- const menuData = this.sortMenusByPriority(menus);
140
- return menuData.map(menu => {
141
- return Object.assign(Object.assign({}, menu), { children: menu.children && this.sortMenus(sortByPriority, menu.children) });
142
- });
143
- }
144
- else {
145
- return menus;
146
- }
147
- };
148
- // this.logger = makeLogger(Feature.name);
149
- // Navigation
150
- this.routerFactory = combine(arguments, (arg) => arg.routerFactory)
151
- .slice(-1)
152
- .pop();
153
- this.route = combine(arguments, (arg) => arg.route);
154
- this.routeConfig = combine(arguments, (arg) => arg.routeConfig);
155
- this.menuConfig = combine(arguments, (arg) => arg.menuConfig);
156
- this.componentFillPlugins = this.registerComponentFillPlugins(combine(arguments, (arg) => arg.componentFillPlugins));
157
- this.authWrapper = getFirst(arguments, (arg) => arg.authWrapper);
158
- }
159
- /**
160
- * Get the routes
161
- */
162
- getRoutes(searchPath) {
163
- const configuredRoutes = this.getConfiguredRoutes(searchPath);
164
- const solidRoutes = this.route.map((component, idx) => React.cloneElement(component, { key: component.props.path }));
165
- return this.renderRoutes(configuredRoutes, solidRoutes);
166
- }
167
- /**
168
- * Get menus
169
- */
170
- getMenus(sortByPriority = true) {
171
- const menus = this.getConfiguredMenus();
172
- return this.sortMenus(sortByPriority, menus);
173
- }
174
- /**
175
- * get configured routes.
176
- * Note: It overwrites the any duplicate key with latest loaded key.
177
- * TODO: Find a way to warn when there are duplicate keys.
178
- */
179
- getConfiguredRoutes(searchPath = '/') {
180
- return utils_1.getSortedRoutes(searchPath, Object.assign({}, ...this.routeConfig), this.authWrapper);
181
- }
182
- /**
183
- * get configured menus.
184
- * Note: It overwrites the any duplicate key with latest loaded key.
185
- * TODO: Find a way to warn when there are duplicate keys.
186
- */
187
- getConfiguredMenus(searchPath = '/') {
188
- const routes = Object.assign({}, ...this.menuConfig);
189
- return utils_1.getMenus(searchPath, Object.assign({}, routes));
190
- }
191
- get navItems() {
192
- return this.navItem.map((component, idx) => React.cloneElement(component, {
193
- key: component.key ? component.key : idx + this.navItem.length,
194
- }));
195
- }
196
- get navItemsRight() {
197
- return this.navItemsRight.map((component, idx) => React.cloneElement(component, {
198
- key: component.key ? component.key : idx + this.navItems.length,
199
- }));
200
- }
201
- getWrappedRoot(root, req) {
202
- let nestedRoot = root;
203
- for (const componentFactory of this.rootComponentFactory) {
204
- nestedRoot = React.cloneElement(componentFactory(req), {}, nestedRoot);
205
- }
206
- return nestedRoot;
207
- }
208
- getDataRoot(root) {
209
- let nestedRoot = root;
210
- for (const component of this.dataRootComponent) {
211
- nestedRoot = React.createElement(component, {}, nestedRoot);
212
- }
213
- return nestedRoot;
214
- }
215
- registerLanguages(monaco) {
216
- for (const func of this.languagesFuncs) {
217
- func(monaco);
218
- }
219
- }
220
- registerComponentFillPlugins(plugins) {
221
- plugins.forEach((i) => {
222
- const { name } = i;
223
- const isFound = !!plugin_area_1.getPlugin(name);
224
- if (!isFound) {
225
- plugin_area_1.registerPlugin(name, i);
226
- }
227
- });
228
- return plugins;
229
- }
230
- getComponentFillPlugins() {
231
- return plugin_area_1.getPlugins();
232
- }
233
- }
234
- exports.Feature = Feature;
235
-
236
-
237
- /***/ }),
238
-
239
- /***/ "./src/connector/index.ts":
240
- /*!********************************!*\
241
- !*** ./src/connector/index.ts ***!
242
- \********************************/
243
- /*! no static exports found */
244
- /***/ (function(module, exports, __webpack_require__) {
245
-
246
- "use strict";
247
-
248
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
249
- if (k2 === undefined) k2 = k;
250
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
251
- }) : (function(o, m, k, k2) {
252
- if (k2 === undefined) k2 = k;
253
- o[k2] = m[k];
254
- }));
255
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
256
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
257
- };
258
- Object.defineProperty(exports, "__esModule", { value: true });
259
- __exportStar(__webpack_require__(/*! ./connector */ "./src/connector/connector.tsx"), exports);
260
-
261
-
262
- /***/ }),
263
-
264
- /***/ "./src/index.ts":
265
- /*!**********************!*\
266
- !*** ./src/index.ts ***!
267
- \**********************/
268
- /*! no static exports found */
269
- /***/ (function(module, exports, __webpack_require__) {
270
-
271
- "use strict";
272
-
273
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
274
3
  if (k2 === undefined) k2 = k;
275
4
  Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
@@ -282,1881 +11,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
282
11
  };
283
12
  Object.defineProperty(exports, "__esModule", { value: true });
284
13
  exports.ClientTypes = void 0;
285
- var client_core_1 = __webpack_require__(/*! @common-stack/client-core */ "@common-stack/client-core");
14
+ var client_core_1 = require("@common-stack/client-core");
286
15
  Object.defineProperty(exports, "ClientTypes", { enumerable: true, get: function () { return client_core_1.ClientTypes; } });
287
- __exportStar(__webpack_require__(/*! ./connector */ "./src/connector/index.ts"), exports);
288
- __exportStar(__webpack_require__(/*! ./router */ "./src/router/index.ts"), exports);
289
- __exportStar(__webpack_require__(/*! ./route */ "./src/route/index.ts"), exports);
290
- __exportStar(__webpack_require__(/*! ./utils */ "./src/utils/index.ts"), exports);
291
- __exportStar(__webpack_require__(/*! ./interfaces */ "./src/interfaces/index.ts"), exports);
292
- __exportStar(__webpack_require__(/*! ./plugin-area */ "./src/plugin-area/index.ts"), exports);
293
- __exportStar(__webpack_require__(/*! ./route-based-plugin-area */ "./src/route-based-plugin-area/index.ts"), exports);
294
- __exportStar(__webpack_require__(/*! ./slot-fill */ "./src/slot-fill/index.ts"), exports);
295
- __exportStar(__webpack_require__(/*! ./inversify */ "./src/inversify/index.ts"), exports);
296
-
297
-
298
- /***/ }),
299
-
300
- /***/ "./src/interfaces/extended-feature.ts":
301
- /*!********************************************!*\
302
- !*** ./src/interfaces/extended-feature.ts ***!
303
- \********************************************/
304
- /*! no static exports found */
305
- /***/ (function(module, exports, __webpack_require__) {
306
-
307
- "use strict";
308
-
309
- Object.defineProperty(exports, "__esModule", { value: true });
310
-
311
-
312
- /***/ }),
313
-
314
- /***/ "./src/interfaces/index.ts":
315
- /*!*********************************!*\
316
- !*** ./src/interfaces/index.ts ***!
317
- \*********************************/
318
- /*! no static exports found */
319
- /***/ (function(module, exports, __webpack_require__) {
320
-
321
- "use strict";
322
-
323
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
324
- if (k2 === undefined) k2 = k;
325
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
326
- }) : (function(o, m, k, k2) {
327
- if (k2 === undefined) k2 = k;
328
- o[k2] = m[k];
329
- }));
330
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
331
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
332
- };
333
- Object.defineProperty(exports, "__esModule", { value: true });
334
- __exportStar(__webpack_require__(/*! ./router */ "./src/interfaces/router.ts"), exports);
335
- __exportStar(__webpack_require__(/*! ./extended-feature */ "./src/interfaces/extended-feature.ts"), exports);
336
- __exportStar(__webpack_require__(/*! ./menu */ "./src/interfaces/menu.tsx"), exports);
337
- __exportStar(__webpack_require__(/*! ./new-router */ "./src/interfaces/new-router.tsx"), exports);
338
-
339
-
340
- /***/ }),
341
-
342
- /***/ "./src/interfaces/menu.tsx":
343
- /*!*********************************!*\
344
- !*** ./src/interfaces/menu.tsx ***!
345
- \*********************************/
346
- /*! no static exports found */
347
- /***/ (function(module, exports, __webpack_require__) {
348
-
349
- "use strict";
350
-
351
- Object.defineProperty(exports, "__esModule", { value: true });
352
- exports.IMenuPosition = void 0;
353
- var IMenuPosition;
354
- (function (IMenuPosition) {
355
- IMenuPosition["LOGO"] = "LOGO";
356
- IMenuPosition["UPPER"] = "UPPER";
357
- IMenuPosition["MIDDLE"] = "MIDDLE";
358
- IMenuPosition["LOWER"] = "LOWER";
359
- IMenuPosition["BOTTOM"] = "BOTTOM";
360
- })(IMenuPosition = exports.IMenuPosition || (exports.IMenuPosition = {}));
361
-
362
-
363
- /***/ }),
364
-
365
- /***/ "./src/interfaces/new-router.tsx":
366
- /*!***************************************!*\
367
- !*** ./src/interfaces/new-router.tsx ***!
368
- \***************************************/
369
- /*! no static exports found */
370
- /***/ (function(module, exports, __webpack_require__) {
371
-
372
- "use strict";
373
-
374
- Object.defineProperty(exports, "__esModule", { value: true });
375
-
376
-
377
- /***/ }),
378
-
379
- /***/ "./src/interfaces/router.ts":
380
- /*!**********************************!*\
381
- !*** ./src/interfaces/router.ts ***!
382
- \**********************************/
383
- /*! no static exports found */
384
- /***/ (function(module, exports, __webpack_require__) {
385
-
386
- "use strict";
387
-
388
- Object.defineProperty(exports, "__esModule", { value: true });
389
-
390
-
391
- /***/ }),
392
-
393
- /***/ "./src/inversify/InversifyContext.tsx":
394
- /*!********************************************!*\
395
- !*** ./src/inversify/InversifyContext.tsx ***!
396
- \********************************************/
397
- /*! no static exports found */
398
- /***/ (function(module, exports, __webpack_require__) {
399
-
400
- "use strict";
401
-
402
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
403
- if (k2 === undefined) k2 = k;
404
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
405
- }) : (function(o, m, k, k2) {
406
- if (k2 === undefined) k2 = k;
407
- o[k2] = m[k];
408
- }));
409
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
410
- Object.defineProperty(o, "default", { enumerable: true, value: v });
411
- }) : function(o, v) {
412
- o["default"] = v;
413
- });
414
- var __importStar = (this && this.__importStar) || function (mod) {
415
- if (mod && mod.__esModule) return mod;
416
- var result = {};
417
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
418
- __setModuleDefault(result, mod);
419
- return result;
420
- };
421
- Object.defineProperty(exports, "__esModule", { value: true });
422
- exports.useInjection = exports.InversifyProvider = exports.InversifyContext = void 0;
423
- const React = __importStar(__webpack_require__(/*! react */ "react"));
424
- exports.InversifyContext = React.createContext({ container: null, modules: null });
425
- const InversifyProvider = (props) => {
426
- return (React.createElement(exports.InversifyContext.Provider, { value: { container: props.container, modules: props.modules } }, props.children));
427
- };
428
- exports.InversifyProvider = InversifyProvider;
429
- function useInjection(identifier) {
430
- const { container } = React.useContext(exports.InversifyContext);
431
- if (!container) {
432
- throw new Error('Container is null');
433
- }
434
- return container.get(identifier);
435
- }
436
- exports.useInjection = useInjection;
437
-
438
-
439
- /***/ }),
440
-
441
- /***/ "./src/inversify/index.ts":
442
- /*!********************************!*\
443
- !*** ./src/inversify/index.ts ***!
444
- \********************************/
445
- /*! no static exports found */
446
- /***/ (function(module, exports, __webpack_require__) {
447
-
448
- "use strict";
449
-
450
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
451
- if (k2 === undefined) k2 = k;
452
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
453
- }) : (function(o, m, k, k2) {
454
- if (k2 === undefined) k2 = k;
455
- o[k2] = m[k];
456
- }));
457
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
458
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
459
- };
460
- Object.defineProperty(exports, "__esModule", { value: true });
461
- __exportStar(__webpack_require__(/*! ./InversifyContext */ "./src/inversify/InversifyContext.tsx"), exports);
462
-
463
-
464
- /***/ }),
465
-
466
- /***/ "./src/plugin-area/browser-plugin-area.tsx":
467
- /*!*************************************************!*\
468
- !*** ./src/plugin-area/browser-plugin-area.tsx ***!
469
- \*************************************************/
470
- /*! no static exports found */
471
- /***/ (function(module, exports, __webpack_require__) {
472
-
473
- "use strict";
474
-
475
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
476
- if (k2 === undefined) k2 = k;
477
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
478
- }) : (function(o, m, k, k2) {
479
- if (k2 === undefined) k2 = k;
480
- o[k2] = m[k];
481
- }));
482
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
483
- Object.defineProperty(o, "default", { enumerable: true, value: v });
484
- }) : function(o, v) {
485
- o["default"] = v;
486
- });
487
- var __importStar = (this && this.__importStar) || function (mod) {
488
- if (mod && mod.__esModule) return mod;
489
- var result = {};
490
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
491
- __setModuleDefault(result, mod);
492
- return result;
493
- };
494
- Object.defineProperty(exports, "__esModule", { value: true });
495
- exports.BrowserPluginArea = void 0;
496
- const React = __importStar(__webpack_require__(/*! react */ "react"));
497
- const plugin_area_1 = __webpack_require__(/*! ./plugin-area */ "./src/plugin-area/plugin-area.tsx");
498
- const BrowserPluginArea = () => {
499
- return React.createElement("div", { style: { display: "none" } },
500
- React.createElement(plugin_area_1.PluginArea, null));
501
- };
502
- exports.BrowserPluginArea = BrowserPluginArea;
503
-
504
-
505
- /***/ }),
506
-
507
- /***/ "./src/plugin-area/higher-order-component-util.ts":
508
- /*!********************************************************!*\
509
- !*** ./src/plugin-area/higher-order-component-util.ts ***!
510
- \********************************************************/
511
- /*! no static exports found */
512
- /***/ (function(module, exports, __webpack_require__) {
513
-
514
- "use strict";
515
-
516
- Object.defineProperty(exports, "__esModule", { value: true });
517
- exports.createHigherOrderComponent = void 0;
518
- const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
519
- /**
520
- * Given a function mapping a component to an enhanced component and modifier
521
- * name, returns the enhanced component augmented with a generated displayName.
522
- *
523
- * @param mapComponentToEnhancedComponent Function mapping component to enhanced component.
524
- * @param modifierName Seed name from which to generated display name.
525
- *
526
- * @return Component class with generated display name assigned.
527
- */
528
- function createHigherOrderComponent(mapComponentToEnhancedComponent, modifierName) {
529
- return (OriginalComponent) => {
530
- const EnhancedComponent = mapComponentToEnhancedComponent(OriginalComponent);
531
- const { displayName = OriginalComponent.name || 'Component', } = OriginalComponent;
532
- EnhancedComponent.displayName = `${lodash_1.upperFirst(lodash_1.camelCase(modifierName))}(${displayName})`;
533
- return EnhancedComponent;
534
- };
535
- }
536
- exports.createHigherOrderComponent = createHigherOrderComponent;
537
-
538
-
539
- /***/ }),
540
-
541
- /***/ "./src/plugin-area/index.ts":
542
- /*!**********************************!*\
543
- !*** ./src/plugin-area/index.ts ***!
544
- \**********************************/
545
- /*! no static exports found */
546
- /***/ (function(module, exports, __webpack_require__) {
547
-
548
- "use strict";
549
-
550
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
551
- if (k2 === undefined) k2 = k;
552
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
553
- }) : (function(o, m, k, k2) {
554
- if (k2 === undefined) k2 = k;
555
- o[k2] = m[k];
556
- }));
557
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
558
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
559
- };
560
- Object.defineProperty(exports, "__esModule", { value: true });
561
- __exportStar(__webpack_require__(/*! ./plugin-area */ "./src/plugin-area/plugin-area.tsx"), exports);
562
- __exportStar(__webpack_require__(/*! ./plugin-api */ "./src/plugin-area/plugin-api.ts"), exports);
563
- __exportStar(__webpack_require__(/*! ./browser-plugin-area */ "./src/plugin-area/browser-plugin-area.tsx"), exports);
564
-
565
-
566
- /***/ }),
567
-
568
- /***/ "./src/plugin-area/plugin-api.ts":
569
- /*!***************************************!*\
570
- !*** ./src/plugin-area/plugin-api.ts ***!
571
- \***************************************/
572
- /*! no static exports found */
573
- /***/ (function(module, exports, __webpack_require__) {
574
-
575
- "use strict";
576
-
577
- Object.defineProperty(exports, "__esModule", { value: true });
578
- exports.getPlugins = exports.getPlugin = exports.unregisterPlugin = exports.registerPlugin = void 0;
579
- const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
580
- const hooks_1 = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks");
581
- /**
582
- * Plugin definitions keyed by plugin name.
583
- */
584
- const plugins = {};
585
- /**
586
- * Registeres a plugin to the App.
587
- *
588
- * @param name A string identifying the plugin. Must be unique across all registered plugins.
589
- * @param settings The settings for this plugin.
590
- */
591
- function registerPlugin(name, settings) {
592
- if (typeof settings !== 'object') {
593
- console.error('No settings object provided!');
594
- return null;
595
- }
596
- if (typeof name !== 'string') {
597
- console.error('Plugin names must be strings.');
598
- return null;
599
- }
600
- if (!/^[a-z][a-z0-9-]*$/.test(name)) {
601
- console.error('Plugin names must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-pluin".');
602
- return null;
603
- }
604
- if (plugins[name]) {
605
- console.error(`Plugin "${name}" is alread registered.`);
606
- }
607
- settings = hooks_1.applyFilters('plugins.registerPlugin', settings, name);
608
- if (!lodash_1.isFunction(settings.render)) {
609
- console.error('The "render" property must be specified and must be a valid function.');
610
- return null;
611
- }
612
- plugins[name] = Object.assign({ name, icon: 'admin-plugins' }, settings);
613
- hooks_1.doAction('plugins.pluginRegistered', settings, name);
614
- return settings;
615
- }
616
- exports.registerPlugin = registerPlugin;
617
- /**
618
- * Unregisteres a plugin by name.
619
- * @param name Plugin name.
620
- *
621
- * @return The previous plugin settings object, if it has been successfully unregistered; otherwise `undefined`.
622
- */
623
- function unregisterPlugin(name) {
624
- if (!plugins[name]) {
625
- console.error('Plugin "' + name + '" is not registered.');
626
- return;
627
- }
628
- const oldPlugin = plugins[name];
629
- delete plugins[name];
630
- hooks_1.doAction('plugin.pluginUnregistered', oldPlugin, name);
631
- return oldPlugin;
632
- }
633
- exports.unregisterPlugin = unregisterPlugin;
634
- /**
635
- * Returns a registered plugin settings.
636
- *
637
- * @param name Plugin name.
638
- *
639
- * @returns Plugin setting.
640
- */
641
- function getPlugin(name) {
642
- return plugins[name];
643
- }
644
- exports.getPlugin = getPlugin;
645
- /**
646
- * Return all registered plugins.
647
- *
648
- * @return Plugin settings.
649
- */
650
- function getPlugins() {
651
- return Object.values(plugins);
652
- }
653
- exports.getPlugins = getPlugins;
654
-
655
-
656
- /***/ }),
657
-
658
- /***/ "./src/plugin-area/plugin-area.tsx":
659
- /*!*****************************************!*\
660
- !*** ./src/plugin-area/plugin-area.tsx ***!
661
- \*****************************************/
662
- /*! no static exports found */
663
- /***/ (function(module, exports, __webpack_require__) {
664
-
665
- "use strict";
666
-
667
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
668
- if (k2 === undefined) k2 = k;
669
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
670
- }) : (function(o, m, k, k2) {
671
- if (k2 === undefined) k2 = k;
672
- o[k2] = m[k];
673
- }));
674
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
675
- Object.defineProperty(o, "default", { enumerable: true, value: v });
676
- }) : function(o, v) {
677
- o["default"] = v;
678
- });
679
- var __importStar = (this && this.__importStar) || function (mod) {
680
- if (mod && mod.__esModule) return mod;
681
- var result = {};
682
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
683
- __setModuleDefault(result, mod);
684
- return result;
685
- };
686
- Object.defineProperty(exports, "__esModule", { value: true });
687
- exports.PluginArea = void 0;
688
- const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
689
- const React = __importStar(__webpack_require__(/*! react */ "react"));
690
- const hooks_1 = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks");
691
- const plugin_context_1 = __webpack_require__(/*! ./plugin-context */ "./src/plugin-area/plugin-context.tsx");
692
- const plugin_api_1 = __webpack_require__(/*! ./plugin-api */ "./src/plugin-area/plugin-api.ts");
693
- /**
694
- * A component that renders all plugin fills in a hidden div.
695
- */
696
- class PluginArea extends React.Component {
697
- constructor(args) {
698
- super(args);
699
- this.setPlugins = this.setPlugins.bind(this);
700
- this.state = { plugins: [] };
701
- }
702
- getCurrentPluginsState() {
703
- return {
704
- plugins: lodash_1.map(plugin_api_1.getPlugins(), ({ icon, name, render }) => {
705
- return {
706
- Plugin: render,
707
- context: {
708
- name,
709
- icon,
710
- },
711
- };
712
- }),
713
- };
714
- }
715
- componentDidMount() {
716
- hooks_1.addAction('plugins.pluginRegistered', 'core/plugins/plugin-area/plugins-registered', this.setPlugins);
717
- hooks_1.addAction('plugins.pluginUnregistered', 'core/plugins/plugin-area/plugins-unregistered', this.setPlugins);
718
- this.setPlugins();
719
- }
720
- componentWillUnMount() {
721
- hooks_1.removeAction('plugins.pluginRegistered', 'core/plugins/plugin-area/plugins-registered');
722
- hooks_1.removeAction('plugins.pluginUnregistered', 'core/plugins/plugin-area/plugins-unregistered');
723
- }
724
- setPlugins() {
725
- this.setState(this.getCurrentPluginsState);
726
- }
727
- render() {
728
- return (React.createElement(React.Fragment, null, lodash_1.map(this.state.plugins, ({ context, Plugin }) => (React.createElement(plugin_context_1.PluginContextProvider, { key: context.name, value: context },
729
- React.createElement(Plugin, null))))));
730
- }
731
- }
732
- exports.PluginArea = PluginArea;
733
-
734
-
735
- /***/ }),
736
-
737
- /***/ "./src/plugin-area/plugin-context.tsx":
738
- /*!********************************************!*\
739
- !*** ./src/plugin-area/plugin-context.tsx ***!
740
- \********************************************/
741
- /*! no static exports found */
742
- /***/ (function(module, exports, __webpack_require__) {
743
-
744
- "use strict";
745
-
746
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
747
- if (k2 === undefined) k2 = k;
748
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
749
- }) : (function(o, m, k, k2) {
750
- if (k2 === undefined) k2 = k;
751
- o[k2] = m[k];
752
- }));
753
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
754
- Object.defineProperty(o, "default", { enumerable: true, value: v });
755
- }) : function(o, v) {
756
- o["default"] = v;
757
- });
758
- var __importStar = (this && this.__importStar) || function (mod) {
759
- if (mod && mod.__esModule) return mod;
760
- var result = {};
761
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
762
- __setModuleDefault(result, mod);
763
- return result;
764
- };
765
- Object.defineProperty(exports, "__esModule", { value: true });
766
- exports.withPluginContext = exports.PluginContextProvider = void 0;
767
- const React = __importStar(__webpack_require__(/*! react */ "react"));
768
- const higher_order_component_util_1 = __webpack_require__(/*! ./higher-order-component-util */ "./src/plugin-area/higher-order-component-util.ts");
769
- const { createContext } = React;
770
- const { Consumer, Provider } = createContext({
771
- name: null,
772
- icon: null,
773
- });
774
- exports.PluginContextProvider = Provider;
775
- /**
776
- * A Higher Order Component used to inject Plugin context to the
777
- * wrapped component.
778
- *
779
- * @param mapContextToProps Function called on every context change, expected to return object of
780
- * props to merge with the component's own props.
781
- *
782
- * @return Enhanced component with injected context as props.
783
- */
784
- const withPluginContext = (mapContextToProps) => higher_order_component_util_1.createHigherOrderComponent((OriginalComponent) => {
785
- return (props) => (React.createElement(Consumer, null, (context) => (React.createElement(OriginalComponent, Object.assign({}, props, mapContextToProps(context, props))))));
786
- }, 'withPluginContext');
787
- exports.withPluginContext = withPluginContext;
788
-
789
-
790
- /***/ }),
791
-
792
- /***/ "./src/route-based-plugin-area/higher-order-component-util.ts":
793
- /*!********************************************************************!*\
794
- !*** ./src/route-based-plugin-area/higher-order-component-util.ts ***!
795
- \********************************************************************/
796
- /*! no static exports found */
797
- /***/ (function(module, exports, __webpack_require__) {
798
-
799
- "use strict";
800
-
801
- Object.defineProperty(exports, "__esModule", { value: true });
802
- exports.createHigherOrderComponent = void 0;
803
- const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
804
- /**
805
- * Given a function mapping a component to an enhanced component and modifier
806
- * name, returns the enhanced component augmented with a generated displayName.
807
- *
808
- * @param mapComponentToEnhancedComponent Function mapping component to enhanced component.
809
- * @param modifierName Seed name from which to generated display name.
810
- *
811
- * @return Component class with generated display name assigned.
812
- */
813
- function createHigherOrderComponent(mapComponentToEnhancedComponent, modifierName) {
814
- return (OriginalComponent) => {
815
- const EnhancedComponent = mapComponentToEnhancedComponent(OriginalComponent);
816
- const { displayName = OriginalComponent.name || 'Component', } = OriginalComponent;
817
- EnhancedComponent.displayName = `${lodash_1.upperFirst(lodash_1.camelCase(modifierName))}(${displayName})`;
818
- return EnhancedComponent;
819
- };
820
- }
821
- exports.createHigherOrderComponent = createHigherOrderComponent;
822
-
823
-
824
- /***/ }),
825
-
826
- /***/ "./src/route-based-plugin-area/index.ts":
827
- /*!**********************************************!*\
828
- !*** ./src/route-based-plugin-area/index.ts ***!
829
- \**********************************************/
830
- /*! no static exports found */
831
- /***/ (function(module, exports, __webpack_require__) {
832
-
833
- "use strict";
834
-
835
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
836
- if (k2 === undefined) k2 = k;
837
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
838
- }) : (function(o, m, k, k2) {
839
- if (k2 === undefined) k2 = k;
840
- o[k2] = m[k];
841
- }));
842
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
843
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
844
- };
845
- Object.defineProperty(exports, "__esModule", { value: true });
846
- __exportStar(__webpack_require__(/*! ./route-based-plugin-area */ "./src/route-based-plugin-area/route-based-plugin-area.tsx"), exports);
847
- __exportStar(__webpack_require__(/*! ./plugin-api */ "./src/route-based-plugin-area/plugin-api.ts"), exports);
848
-
849
-
850
- /***/ }),
851
-
852
- /***/ "./src/route-based-plugin-area/plugin-api.ts":
853
- /*!***************************************************!*\
854
- !*** ./src/route-based-plugin-area/plugin-api.ts ***!
855
- \***************************************************/
856
- /*! no static exports found */
857
- /***/ (function(module, exports, __webpack_require__) {
858
-
859
- "use strict";
860
-
861
- Object.defineProperty(exports, "__esModule", { value: true });
862
- exports.getRouteBasePlugins = exports.getRouteBasePlugin = exports.unregisterRouteBasePlugin = exports.registerRouteBasePlugin = void 0;
863
- const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
864
- const hooks_1 = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks");
865
- /**
866
- * Plugin definitions keyed by plugin name.
867
- */
868
- const plugins = {};
869
- /**
870
- * Registeres a plugin to the App.
871
- *
872
- * @param name A string identifying the plugin. Must be unique across all registered plugins.
873
- * @param settings The settings for this plugin.
874
- */
875
- function registerRouteBasePlugin(name, settings) {
876
- if (typeof settings !== 'object') {
877
- console.error('No settings object provided!');
878
- return null;
879
- }
880
- if (typeof name !== 'string') {
881
- console.error('Plugin names must be strings.');
882
- return null;
883
- }
884
- if (!/^[a-z][a-z0-9-]*$/.test(name)) {
885
- console.error('Plugin names must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-pluin".');
886
- return null;
887
- }
888
- if (plugins[name]) {
889
- console.error(`Plugin "${name}" is alread registered.`);
890
- }
891
- settings = hooks_1.applyFilters('plugins.registerPlugin', settings, name);
892
- if (!lodash_1.isFunction(settings.render)) {
893
- console.error('The "render" property must be specified and must be a valid function.');
894
- return null;
895
- }
896
- plugins[name] = Object.assign({ name, icon: 'admin-plugins' }, settings);
897
- hooks_1.doAction('plugins.pluginRegistered', settings, name);
898
- return settings;
899
- }
900
- exports.registerRouteBasePlugin = registerRouteBasePlugin;
901
- /**
902
- * Unregisteres a plugin by name.
903
- * @param name Plugin name.
904
- *
905
- * @return The previous plugin settings object, if it has been successfully unregistered; otherwise `undefined`.
906
- */
907
- function unregisterRouteBasePlugin(name) {
908
- if (!plugins[name]) {
909
- console.error('Plugin "' + name + '" is not registered.');
910
- return;
911
- }
912
- const oldPlugin = plugins[name];
913
- delete plugins[name];
914
- hooks_1.doAction('plugin.pluginUnregistered', oldPlugin, name);
915
- return oldPlugin;
916
- }
917
- exports.unregisterRouteBasePlugin = unregisterRouteBasePlugin;
918
- /**
919
- * Returns a registered plugin settings.
920
- *
921
- * @param name Plugin name.
922
- *
923
- * @returns Plugin setting.
924
- */
925
- function getRouteBasePlugin(name) {
926
- return plugins[name];
927
- }
928
- exports.getRouteBasePlugin = getRouteBasePlugin;
929
- /**
930
- * Return all registered plugins.
931
- *
932
- * @return Plugin settings.
933
- */
934
- function getRouteBasePlugins() {
935
- return Object.values(plugins);
936
- }
937
- exports.getRouteBasePlugins = getRouteBasePlugins;
938
-
939
-
940
- /***/ }),
941
-
942
- /***/ "./src/route-based-plugin-area/plugin-context.tsx":
943
- /*!********************************************************!*\
944
- !*** ./src/route-based-plugin-area/plugin-context.tsx ***!
945
- \********************************************************/
946
- /*! no static exports found */
947
- /***/ (function(module, exports, __webpack_require__) {
948
-
949
- "use strict";
950
-
951
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
952
- if (k2 === undefined) k2 = k;
953
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
954
- }) : (function(o, m, k, k2) {
955
- if (k2 === undefined) k2 = k;
956
- o[k2] = m[k];
957
- }));
958
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
959
- Object.defineProperty(o, "default", { enumerable: true, value: v });
960
- }) : function(o, v) {
961
- o["default"] = v;
962
- });
963
- var __importStar = (this && this.__importStar) || function (mod) {
964
- if (mod && mod.__esModule) return mod;
965
- var result = {};
966
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
967
- __setModuleDefault(result, mod);
968
- return result;
969
- };
970
- Object.defineProperty(exports, "__esModule", { value: true });
971
- exports.withPluginContext = exports.PluginContextProvider = void 0;
972
- const React = __importStar(__webpack_require__(/*! react */ "react"));
973
- const higher_order_component_util_1 = __webpack_require__(/*! ./higher-order-component-util */ "./src/route-based-plugin-area/higher-order-component-util.ts");
974
- const { createContext } = React;
975
- const { Consumer, Provider } = createContext({
976
- name: null,
977
- icon: null,
978
- });
979
- exports.PluginContextProvider = Provider;
980
- /**
981
- * A Higher Order Component used to inject Plugin context to the
982
- * wrapped component.
983
- *
984
- * @param mapContextToProps Function called on every context change, expected to return object of
985
- * props to merge with the component's own props.
986
- *
987
- * @return Enhanced component with injected context as props.
988
- */
989
- const withPluginContext = (mapContextToProps) => higher_order_component_util_1.createHigherOrderComponent((OriginalComponent) => {
990
- return (props) => (React.createElement(Consumer, null, (context) => (React.createElement(OriginalComponent, Object.assign({}, props, mapContextToProps(context, props))))));
991
- }, 'withPluginContext');
992
- exports.withPluginContext = withPluginContext;
993
-
994
-
995
- /***/ }),
996
-
997
- /***/ "./src/route-based-plugin-area/route-based-plugin-area.tsx":
998
- /*!*****************************************************************!*\
999
- !*** ./src/route-based-plugin-area/route-based-plugin-area.tsx ***!
1000
- \*****************************************************************/
1001
- /*! no static exports found */
1002
- /***/ (function(module, exports, __webpack_require__) {
1003
-
1004
- "use strict";
1005
-
1006
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1007
- if (k2 === undefined) k2 = k;
1008
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1009
- }) : (function(o, m, k, k2) {
1010
- if (k2 === undefined) k2 = k;
1011
- o[k2] = m[k];
1012
- }));
1013
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1014
- Object.defineProperty(o, "default", { enumerable: true, value: v });
1015
- }) : function(o, v) {
1016
- o["default"] = v;
1017
- });
1018
- var __importStar = (this && this.__importStar) || function (mod) {
1019
- if (mod && mod.__esModule) return mod;
1020
- var result = {};
1021
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1022
- __setModuleDefault(result, mod);
1023
- return result;
1024
- };
1025
- Object.defineProperty(exports, "__esModule", { value: true });
1026
- exports.RouteBasedPluginArea = void 0;
1027
- const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
1028
- const React = __importStar(__webpack_require__(/*! react */ "react"));
1029
- const hooks_1 = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks");
1030
- const plugin_context_1 = __webpack_require__(/*! ./plugin-context */ "./src/route-based-plugin-area/plugin-context.tsx");
1031
- const plugin_api_1 = __webpack_require__(/*! ./plugin-api */ "./src/route-based-plugin-area/plugin-api.ts");
1032
- /**
1033
- * A component that renders all plugin fills in a hidden div.
1034
- */
1035
- class RouteBasedPluginArea extends React.Component {
1036
- constructor(args) {
1037
- super(args);
1038
- this.setPlugins = this.setPlugins.bind(this);
1039
- this.state = { plugins: [] };
1040
- }
1041
- getCurrentPluginsState() {
1042
- return {
1043
- plugins: lodash_1.map(plugin_api_1.getRouteBasePlugins(), ({ icon, name, render }) => {
1044
- return {
1045
- Plugin: render,
1046
- context: {
1047
- name,
1048
- icon,
1049
- },
1050
- };
1051
- }),
1052
- };
1053
- }
1054
- componentDidMount() {
1055
- hooks_1.addAction('plugins.pluginRegistered', 'core/plugins/plugin-area/plugins-registered', this.setPlugins);
1056
- hooks_1.addAction('plugins.pluginUnregistered', 'core/plugins/plugin-area/plugins-unregistered', this.setPlugins);
1057
- this.setPlugins();
1058
- }
1059
- componentWillUnMount() {
1060
- hooks_1.removeAction('plugins.pluginRegistered', 'core/plugins/plugin-area/plugins-registered');
1061
- hooks_1.removeAction('plugins.pluginUnregistered', 'core/plugins/plugin-area/plugins-unregistered');
1062
- }
1063
- setPlugins() {
1064
- this.setState(this.getCurrentPluginsState);
1065
- }
1066
- render() {
1067
- return (React.createElement("div", { style: { display: 'none' } }, lodash_1.map(this.state.plugins, ({ context, Plugin }) => (React.createElement(plugin_context_1.PluginContextProvider, { key: context.name, value: context },
1068
- React.createElement(Plugin, null))))));
1069
- }
1070
- }
1071
- exports.RouteBasedPluginArea = RouteBasedPluginArea;
1072
-
1073
-
1074
- /***/ }),
1075
-
1076
- /***/ "./src/route/index.ts":
1077
- /*!****************************!*\
1078
- !*** ./src/route/index.ts ***!
1079
- \****************************/
1080
- /*! no static exports found */
1081
- /***/ (function(module, exports, __webpack_require__) {
1082
-
1083
- "use strict";
1084
-
1085
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1086
- if (k2 === undefined) k2 = k;
1087
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1088
- }) : (function(o, m, k, k2) {
1089
- if (k2 === undefined) k2 = k;
1090
- o[k2] = m[k];
1091
- }));
1092
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
1093
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1094
- };
1095
- Object.defineProperty(exports, "__esModule", { value: true });
1096
- __exportStar(__webpack_require__(/*! ./render-routes */ "./src/route/render-routes.tsx"), exports);
1097
-
1098
-
1099
- /***/ }),
1100
-
1101
- /***/ "./src/route/render-routes.tsx":
1102
- /*!*************************************!*\
1103
- !*** ./src/route/render-routes.tsx ***!
1104
- \*************************************/
1105
- /*! no static exports found */
1106
- /***/ (function(module, exports, __webpack_require__) {
1107
-
1108
- "use strict";
1109
-
1110
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1111
- if (k2 === undefined) k2 = k;
1112
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1113
- }) : (function(o, m, k, k2) {
1114
- if (k2 === undefined) k2 = k;
1115
- o[k2] = m[k];
1116
- }));
1117
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1118
- Object.defineProperty(o, "default", { enumerable: true, value: v });
1119
- }) : function(o, v) {
1120
- o["default"] = v;
1121
- });
1122
- var __importStar = (this && this.__importStar) || function (mod) {
1123
- if (mod && mod.__esModule) return mod;
1124
- var result = {};
1125
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1126
- __setModuleDefault(result, mod);
1127
- return result;
1128
- };
1129
- var __rest = (this && this.__rest) || function (s, e) {
1130
- var t = {};
1131
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
1132
- t[p] = s[p];
1133
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
1134
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
1135
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
1136
- t[p[i]] = s[p[i]];
1137
- }
1138
- return t;
1139
- };
1140
- Object.defineProperty(exports, "__esModule", { value: true });
1141
- exports.renderRoutes2 = void 0;
1142
- const React = __importStar(__webpack_require__(/*! react */ "react"));
1143
- const react_1 = __webpack_require__(/*! react */ "react");
1144
- const react_router_1 = __webpack_require__(/*! react-router */ "react-router");
1145
- function wrapInitialPropsFetch(route, opts) {
1146
- const { component } = route, restRouteParams = __rest(route, ["component"]);
1147
- let Component = route.component;
1148
- function ComponentWithInitialPropsFetch(props) {
1149
- const [initialProps, setInitialProps] = react_1.useState(() => window.g_initialProps);
1150
- react_1.useEffect(() => {
1151
- /**
1152
- * 1. 首次渲染时,此时 window.g_initialProps 变量存在,不需要再走一次 getInitialProps,这样一次 SSR 就走了 2 次 getInitialProps
1153
- * 2. 但是路由切换时,window.getInitialProps 会被赋为 null,这时候就走 getInitialProps 逻辑
1154
- * 3. 如果任何时候都走 2 次,配置 forceInitial: true,这个场景用于静态站点的首屏加载希望走最新数据
1155
- * 4. 开启动态加载后,会在执行 getInitialProps 前预加载下
1156
- */
1157
- const handleGetInitialProps = async () => {
1158
- // preload when enalbe dynamicImport
1159
- if (Component.preload) {
1160
- const preloadComponent = await Component.preload();
1161
- // for test case, really use .default
1162
- Component = preloadComponent.default || preloadComponent;
1163
- }
1164
- //@sri not suppported
1165
- // const defaultCtx = {
1166
- // isServer: false,
1167
- // match: props?.match,
1168
- // route,
1169
- // ...(opts.getInitialPropsCtx || {}),
1170
- // ...restRouteParams,
1171
- // };
1172
- //@sri not suppported
1173
- // if (Component?.getInitialProps) {
1174
- // const ctx = await opts.plugin.applyPlugins({
1175
- // key: 'ssr.modifyGetInitialPropsCtx',
1176
- // type: ApplyPluginsType.modify,
1177
- // initialValue: defaultCtx,
1178
- // async: true,
1179
- // });
1180
- // const initialProps = await Component!.getInitialProps!(
1181
- // ctx || defaultCtx,
1182
- // );
1183
- // setInitialProps(initialProps);
1184
- // }
1185
- };
1186
- // null 时,一定会触发 getInitialProps 执行
1187
- if (!window.g_initialProps) {
1188
- handleGetInitialProps();
1189
- }
1190
- }, [window.location.pathname, window.location.search]);
1191
- return React.createElement(Component, Object.assign({}, props, initialProps));
1192
- }
1193
- // flag for having wrappered
1194
- ComponentWithInitialPropsFetch.wrapInitialPropsLoaded = true;
1195
- ComponentWithInitialPropsFetch.displayName = 'ComponentWithInitialPropsFetch';
1196
- return ComponentWithInitialPropsFetch;
1197
- }
1198
- function render({ route, opts, props, }) {
1199
- const routes = renderRoutes(Object.assign(Object.assign({}, opts), { routes: route.routes || [], rootRoutes: opts.rootRoutes }));
1200
- let { component: Component, wrappers } = route;
1201
- if (Component) {
1202
- const defaultPageInitialProps = opts.isServer
1203
- ? {}
1204
- : window.g_initialProps;
1205
- const newProps = Object.assign(Object.assign(Object.assign(Object.assign({}, props), opts.extraProps), (opts.pageInitialProps || defaultPageInitialProps)), { route, routes: opts.rootRoutes });
1206
- // @ts-ignore
1207
- let ret = React.createElement(Component, Object.assign({}, newProps), routes);
1208
- // route.wrappers
1209
- if (wrappers) {
1210
- let len = wrappers.length - 1;
1211
- while (len >= 0) {
1212
- ret = react_1.createElement(wrappers[len], newProps, ret);
1213
- len -= 1;
1214
- }
1215
- }
1216
- return ret;
1217
- }
1218
- else {
1219
- return routes;
1220
- }
1221
- }
1222
- function getRouteElement({ route, index, opts }) {
1223
- const routeProps = {
1224
- key: route.key || index,
1225
- exact: route.exact,
1226
- strict: route.strict,
1227
- sensitive: route.sensitive,
1228
- path: route.path,
1229
- };
1230
- if (route.redirect) {
1231
- return React.createElement(react_router_1.Redirect, Object.assign({}, routeProps, { from: route.path, to: route.redirect }));
1232
- }
1233
- else {
1234
- // avoid mount and unmount with url hash change
1235
- // @sri not supproted yet
1236
- // if (
1237
- // // only when SSR config enable
1238
- // opts.ssrProps &&
1239
- // !opts.isServer &&
1240
- // // make sure loaded once
1241
- // !(route.component as any)?.wrapInitialPropsLoaded &&
1242
- // (route.component?.getInitialProps || route.component?.preload)
1243
- // ) {
1244
- // // client Render for enable ssr, but not sure SSR success
1245
- // route.component = wrapInitialPropsFetch(route, opts);
1246
- // }
1247
- return (React.createElement(react_router_1.Route, Object.assign({}, routeProps, { render: (props) => {
1248
- return render({ route, opts, props });
1249
- } })));
1250
- }
1251
- }
1252
- function renderRoutes(opts) {
1253
- return opts.routes ? (React.createElement(react_router_1.Switch, null, opts.routes.map((route, index) => {
1254
- const renderedR = getRouteElement({
1255
- route,
1256
- index,
1257
- opts: Object.assign(Object.assign({}, opts), { rootRoutes: opts.rootRoutes || opts.routes }),
1258
- });
1259
- return renderedR;
1260
- }))) : null;
1261
- }
1262
- exports.renderRoutes2 = renderRoutes;
1263
-
1264
-
1265
- /***/ }),
1266
-
1267
- /***/ "./src/router/index.ts":
1268
- /*!*****************************!*\
1269
- !*** ./src/router/index.ts ***!
1270
- \*****************************/
1271
- /*! no static exports found */
1272
- /***/ (function(module, exports, __webpack_require__) {
1273
-
1274
- "use strict";
1275
-
1276
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1277
- if (k2 === undefined) k2 = k;
1278
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1279
- }) : (function(o, m, k, k2) {
1280
- if (k2 === undefined) k2 = k;
1281
- o[k2] = m[k];
1282
- }));
1283
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
1284
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1285
- };
1286
- Object.defineProperty(exports, "__esModule", { value: true });
1287
- __exportStar(__webpack_require__(/*! ./router */ "./src/router/router.tsx"), exports);
1288
-
1289
-
1290
- /***/ }),
1291
-
1292
- /***/ "./src/router/router.tsx":
1293
- /*!*******************************!*\
1294
- !*** ./src/router/router.tsx ***!
1295
- \*******************************/
1296
- /*! no static exports found */
1297
- /***/ (function(module, exports, __webpack_require__) {
1298
-
1299
- "use strict";
1300
-
1301
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1302
- if (k2 === undefined) k2 = k;
1303
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1304
- }) : (function(o, m, k, k2) {
1305
- if (k2 === undefined) k2 = k;
1306
- o[k2] = m[k];
1307
- }));
1308
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1309
- Object.defineProperty(o, "default", { enumerable: true, value: v });
1310
- }) : function(o, v) {
1311
- o["default"] = v;
1312
- });
1313
- var __importStar = (this && this.__importStar) || function (mod) {
1314
- if (mod && mod.__esModule) return mod;
1315
- var result = {};
1316
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1317
- __setModuleDefault(result, mod);
1318
- return result;
1319
- };
1320
- Object.defineProperty(exports, "__esModule", { value: true });
1321
- exports.FeatureWithRouterFactory = void 0;
1322
- const React = __importStar(__webpack_require__(/*! react */ "react"));
1323
- const react_router_dom_1 = __webpack_require__(/*! react-router-dom */ "react-router-dom");
1324
- const connector_1 = __webpack_require__(/*! ../connector */ "./src/connector/index.ts");
1325
- const routerFactory = (routes) => React.createElement(react_router_dom_1.Switch, null, routes);
1326
- exports.FeatureWithRouterFactory = new connector_1.Feature({
1327
- routerFactory,
1328
- });
1329
-
1330
-
1331
- /***/ }),
1332
-
1333
- /***/ "./src/slot-fill/context.tsx":
1334
- /*!***********************************!*\
1335
- !*** ./src/slot-fill/context.tsx ***!
1336
- \***********************************/
1337
- /*! no static exports found */
1338
- /***/ (function(module, exports, __webpack_require__) {
1339
-
1340
- "use strict";
1341
-
1342
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1343
- if (k2 === undefined) k2 = k;
1344
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1345
- }) : (function(o, m, k, k2) {
1346
- if (k2 === undefined) k2 = k;
1347
- o[k2] = m[k];
1348
- }));
1349
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1350
- Object.defineProperty(o, "default", { enumerable: true, value: v });
1351
- }) : function(o, v) {
1352
- o["default"] = v;
1353
- });
1354
- var __importStar = (this && this.__importStar) || function (mod) {
1355
- if (mod && mod.__esModule) return mod;
1356
- var result = {};
1357
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1358
- __setModuleDefault(result, mod);
1359
- return result;
1360
- };
1361
- Object.defineProperty(exports, "__esModule", { value: true });
1362
- exports.Consumer = exports.useSlot = void 0;
1363
- const React = __importStar(__webpack_require__(/*! react */ "react"));
1364
- const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
1365
- const SlotFillContext = React.createContext({
1366
- registerSlot: () => { },
1367
- unregisterSlot: () => { },
1368
- registerFill: () => { },
1369
- unregisterFill: () => { },
1370
- getSlot: () => ({}),
1371
- getFills: () => ([]),
1372
- subscribe: () => { },
1373
- });
1374
- const { Provider, Consumer } = SlotFillContext;
1375
- exports.Consumer = Consumer;
1376
- class SlotFillProvider extends React.Component {
1377
- constructor(props) {
1378
- super(props);
1379
- this.registerSlot = this.registerSlot.bind(this);
1380
- this.registerFill = this.registerFill.bind(this);
1381
- this.unregisterSlot = this.unregisterSlot.bind(this);
1382
- this.unregisterFill = this.unregisterFill.bind(this);
1383
- this.getSlot = this.getSlot.bind(this);
1384
- this.getFills = this.getFills.bind(this);
1385
- this.subscribe = this.subscribe.bind(this);
1386
- this.slots = {};
1387
- this.fills = {};
1388
- this.listeners = [];
1389
- this.contextValue = {
1390
- registerSlot: this.registerSlot,
1391
- unregisterSlot: this.unregisterSlot,
1392
- registerFill: this.registerFill,
1393
- unregisterFill: this.unregisterFill,
1394
- getSlot: this.getSlot,
1395
- getFills: this.getFills,
1396
- subscribe: this.subscribe,
1397
- };
1398
- }
1399
- registerSlot(name, slot) {
1400
- const previousSlot = this.slots[name];
1401
- this.slots[name] = slot;
1402
- this.triggerListeners();
1403
- // Sometimes the fills are registered after the initial render of slot
1404
- // But before the registerSlot call, we need to rerender the slot
1405
- this.forceUpdateSlot(name);
1406
- // If a new instance of a slot is being mounted while another with the
1407
- // same name exists, force its update _after_ the new slot has been
1408
- // assigned into the instance, suich that its own rendering of children
1409
- // will be empty (the new Slot will subsume all fills for this name).
1410
- if (previousSlot) {
1411
- previousSlot.forceUpdate();
1412
- }
1413
- }
1414
- registerFill(name, instance) {
1415
- this.fills[name] = [...(this.fills[name] || []), instance];
1416
- this.forceUpdateSlot(name);
1417
- }
1418
- unregisterSlot(name, instance) {
1419
- // If a previous instance of a Slot by this name unmounts, do nothing,
1420
- // as the slot and its fills should only be removed for the current
1421
- // known instance.
1422
- if (this.slots[name] !== instance) {
1423
- return;
1424
- }
1425
- delete this.slots[name];
1426
- this.triggerListeners();
1427
- }
1428
- unregisterFill(name, instance) {
1429
- this.fills[name] = lodash_1.without(this.fills[name], instance);
1430
- this.resetFillOccurrence(name);
1431
- this.forceUpdateSlot(name);
1432
- }
1433
- getSlot(name) {
1434
- return this.slots[name];
1435
- }
1436
- getFills(name, slotInstance) {
1437
- // Commented following as we need the Slot to render at multiple places
1438
- // Fills should only be returned for the current instance of the slot
1439
- // in which they occupy.
1440
- // if (this.slots[name] !== slotInstance) {
1441
- // return [];
1442
- // }
1443
- return lodash_1.sortBy(this.fills[name], 'occurrence');
1444
- }
1445
- resetFillOccurrence(name) {
1446
- lodash_1.forEach(this.fills[name], instance => {
1447
- instance.occurrence = undefined;
1448
- });
1449
- }
1450
- forceUpdateSlot(name) {
1451
- const slot = this.getSlot(name);
1452
- if (slot) {
1453
- slot.forceUpdate();
1454
- }
1455
- }
1456
- triggerListeners() {
1457
- this.listeners.forEach((listener) => listener());
1458
- }
1459
- subscribe(listener) {
1460
- this.listeners.push(listener);
1461
- return () => {
1462
- this.listeners = lodash_1.without(this.listeners, listener);
1463
- };
1464
- }
1465
- render() {
1466
- return React.createElement(Provider, { value: this.contextValue }, this.props.children);
1467
- }
1468
- }
1469
- /**
1470
- * React hook returning the active slot given a name.
1471
- *
1472
- * @param {string} name Slot name.
1473
- * @return {Object} Slot object.
1474
- */
1475
- const useSlot = (name) => {
1476
- const { getSlot, subscribe } = React.useContext(SlotFillContext);
1477
- const [slot, setSlot] = React.useState(getSlot(name));
1478
- React.useEffect(() => {
1479
- setSlot(getSlot(name));
1480
- const unsubscribe = subscribe(() => {
1481
- setSlot(getSlot(name));
1482
- });
1483
- return unsubscribe;
1484
- }, [name]);
1485
- return slot;
1486
- };
1487
- exports.useSlot = useSlot;
1488
- exports.default = SlotFillProvider;
1489
-
1490
-
1491
- /***/ }),
1492
-
1493
- /***/ "./src/slot-fill/fill.tsx":
1494
- /*!********************************!*\
1495
- !*** ./src/slot-fill/fill.tsx ***!
1496
- \********************************/
1497
- /*! no static exports found */
1498
- /***/ (function(module, exports, __webpack_require__) {
1499
-
1500
- "use strict";
1501
-
1502
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1503
- if (k2 === undefined) k2 = k;
1504
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1505
- }) : (function(o, m, k, k2) {
1506
- if (k2 === undefined) k2 = k;
1507
- o[k2] = m[k];
1508
- }));
1509
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1510
- Object.defineProperty(o, "default", { enumerable: true, value: v });
1511
- }) : function(o, v) {
1512
- o["default"] = v;
1513
- });
1514
- var __importStar = (this && this.__importStar) || function (mod) {
1515
- if (mod && mod.__esModule) return mod;
1516
- var result = {};
1517
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1518
- __setModuleDefault(result, mod);
1519
- return result;
1520
- };
1521
- Object.defineProperty(exports, "__esModule", { value: true });
1522
- exports.Fill = void 0;
1523
- const React = __importStar(__webpack_require__(/*! react */ "react"));
1524
- const react_dom_1 = __webpack_require__(/*! react-dom */ "react-dom");
1525
- const context_1 = __webpack_require__(/*! ./context */ "./src/slot-fill/context.tsx");
1526
- const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
1527
- let occurrences = 0;
1528
- const FillComponent = ({ name, children, registerFill, unregisterFill, }) => {
1529
- const slot = context_1.useSlot(name);
1530
- const ref = React.useRef({
1531
- name,
1532
- children,
1533
- occurrence: 0,
1534
- });
1535
- if (!ref.current.occurrence) {
1536
- ref.current.occurrence = ++occurrences;
1537
- }
1538
- React.useLayoutEffect(() => {
1539
- registerFill(name, ref.current);
1540
- return () => unregisterFill(name, ref.current);
1541
- }, []);
1542
- React.useLayoutEffect(() => {
1543
- ref.current.children = children;
1544
- if (slot && !slot.props.bubblesVirtually) {
1545
- slot.forceUpdate();
1546
- }
1547
- }, [children]);
1548
- React.useLayoutEffect(() => {
1549
- if (name === ref.current.name) {
1550
- // ignore initial effect
1551
- return;
1552
- }
1553
- unregisterFill(ref.current.name, ref.current);
1554
- ref.current.name = name;
1555
- registerFill(name, ref.current);
1556
- }, [name]);
1557
- if (!slot || !slot.node || !slot.props.bubblesVirtually) {
1558
- return null;
1559
- }
1560
- // If a function is passed as a child, provide it with the fillProps.
1561
- if (lodash_1.isFunction(children)) {
1562
- children = children(slot.props.fillProps);
1563
- }
1564
- return react_dom_1.createPortal(children, slot.node);
1565
- };
1566
- const Fill = props => {
1567
- return (React.createElement(context_1.Consumer, null, ({ registerFill, unregisterFill }) => (React.createElement(FillComponent, Object.assign({}, props, { registerFill: registerFill, unregisterFill: unregisterFill })))));
1568
- };
1569
- exports.Fill = Fill;
1570
-
1571
-
1572
- /***/ }),
1573
-
1574
- /***/ "./src/slot-fill/index.ts":
1575
- /*!********************************!*\
1576
- !*** ./src/slot-fill/index.ts ***!
1577
- \********************************/
1578
- /*! no static exports found */
1579
- /***/ (function(module, exports, __webpack_require__) {
1580
-
1581
- "use strict";
1582
-
1583
- var __importDefault = (this && this.__importDefault) || function (mod) {
1584
- return (mod && mod.__esModule) ? mod : { "default": mod };
1585
- };
1586
- Object.defineProperty(exports, "__esModule", { value: true });
1587
- exports.SlotFillProvider = exports.Fill = exports.Slot = void 0;
1588
- const slot_1 = __webpack_require__(/*! ./slot */ "./src/slot-fill/slot.tsx");
1589
- Object.defineProperty(exports, "Slot", { enumerable: true, get: function () { return slot_1.Slot; } });
1590
- const fill_1 = __webpack_require__(/*! ./fill */ "./src/slot-fill/fill.tsx");
1591
- Object.defineProperty(exports, "Fill", { enumerable: true, get: function () { return fill_1.Fill; } });
1592
- const context_1 = __importDefault(__webpack_require__(/*! ./context */ "./src/slot-fill/context.tsx"));
1593
- exports.SlotFillProvider = context_1.default;
1594
-
1595
-
1596
- /***/ }),
1597
-
1598
- /***/ "./src/slot-fill/slot.tsx":
1599
- /*!********************************!*\
1600
- !*** ./src/slot-fill/slot.tsx ***!
1601
- \********************************/
1602
- /*! no static exports found */
1603
- /***/ (function(module, exports, __webpack_require__) {
1604
-
1605
- "use strict";
1606
-
1607
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1608
- if (k2 === undefined) k2 = k;
1609
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1610
- }) : (function(o, m, k, k2) {
1611
- if (k2 === undefined) k2 = k;
1612
- o[k2] = m[k];
1613
- }));
1614
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1615
- Object.defineProperty(o, "default", { enumerable: true, value: v });
1616
- }) : function(o, v) {
1617
- o["default"] = v;
1618
- });
1619
- var __importStar = (this && this.__importStar) || function (mod) {
1620
- if (mod && mod.__esModule) return mod;
1621
- var result = {};
1622
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1623
- __setModuleDefault(result, mod);
1624
- return result;
1625
- };
1626
- Object.defineProperty(exports, "__esModule", { value: true });
1627
- exports.Slot = void 0;
1628
- const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
1629
- const React = __importStar(__webpack_require__(/*! react */ "react"));
1630
- const context_1 = __webpack_require__(/*! ./context */ "./src/slot-fill/context.tsx");
1631
- const utils_1 = __webpack_require__(/*! ./utils */ "./src/slot-fill/utils/index.ts");
1632
- class SlotComponent extends React.Component {
1633
- constructor(props) {
1634
- super(props);
1635
- this.bindNode = this.bindNode.bind(this);
1636
- }
1637
- componentDidMount() {
1638
- const { registerSlot } = this.props;
1639
- registerSlot(this.props.name, this);
1640
- }
1641
- componentWillUnmount() {
1642
- const { unregisterSlot } = this.props;
1643
- unregisterSlot(this.props.name, this);
1644
- }
1645
- componentDidUpdate(prevProps) {
1646
- const { name, unregisterSlot, registerSlot } = this.props;
1647
- // Commented following as we need the Slot to render at multiple places
1648
- // if (prevProps.name !== name) {
1649
- // unregisterSlot(prevProps.name);
1650
- // registerSlot(name, this);
1651
- // }
1652
- }
1653
- bindNode(node) {
1654
- this.node = node;
1655
- }
1656
- render() {
1657
- const { children, name, bubblesVirtually = false, fillProps = {}, getFills, className, } = this.props;
1658
- if (bubblesVirtually) {
1659
- return React.createElement("div", { ref: this.bindNode, className: className });
1660
- }
1661
- const fills = lodash_1.map(getFills(name, this), fill => {
1662
- const fillKey = fill.occurrence;
1663
- const fillChildren = lodash_1.isFunction(fill.children)
1664
- ? fill.children(fillProps)
1665
- : fill.children;
1666
- return React.Children.map(fillChildren, (child, childIndex) => {
1667
- if (!child || lodash_1.isString(child)) {
1668
- return child;
1669
- }
1670
- const childKey = `${fillKey}---${child.key || childIndex}`;
1671
- return React.cloneElement(child, { key: childKey });
1672
- });
1673
- }).filter(
1674
- // In some cases fills are rendered only when some conditions apply.
1675
- // This ensures that we only use non-empty fills when rendering, i.e.,
1676
- // it allows us to render wrappers only when the fills are actually present.
1677
- lodash_1.negate(utils_1.isEmptyElement));
1678
- return React.createElement(React.Fragment, null, lodash_1.isFunction(children) ? children(fills) : fills);
1679
- }
1680
- }
1681
- const Slot = props => {
1682
- return (React.createElement(context_1.Consumer, null, ({ registerSlot, unregisterSlot, getFills }) => (React.createElement(SlotComponent, Object.assign({}, props, { getFills: getFills, registerSlot: registerSlot, unregisterSlot: unregisterSlot })))));
1683
- };
1684
- exports.Slot = Slot;
1685
-
1686
-
1687
- /***/ }),
1688
-
1689
- /***/ "./src/slot-fill/utils/index.ts":
1690
- /*!**************************************!*\
1691
- !*** ./src/slot-fill/utils/index.ts ***!
1692
- \**************************************/
1693
- /*! no static exports found */
1694
- /***/ (function(module, exports, __webpack_require__) {
1695
-
1696
- "use strict";
1697
-
1698
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1699
- if (k2 === undefined) k2 = k;
1700
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1701
- }) : (function(o, m, k, k2) {
1702
- if (k2 === undefined) k2 = k;
1703
- o[k2] = m[k];
1704
- }));
1705
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
1706
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1707
- };
1708
- Object.defineProperty(exports, "__esModule", { value: true });
1709
- __exportStar(__webpack_require__(/*! ./isEmptyElement */ "./src/slot-fill/utils/isEmptyElement.tsx"), exports);
1710
-
1711
-
1712
- /***/ }),
1713
-
1714
- /***/ "./src/slot-fill/utils/isEmptyElement.tsx":
1715
- /*!************************************************!*\
1716
- !*** ./src/slot-fill/utils/isEmptyElement.tsx ***!
1717
- \************************************************/
1718
- /*! no static exports found */
1719
- /***/ (function(module, exports, __webpack_require__) {
1720
-
1721
- "use strict";
1722
-
1723
- Object.defineProperty(exports, "__esModule", { value: true });
1724
- exports.isEmptyElement = void 0;
1725
- const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
1726
- /**
1727
- * Checks if the provided element to check.
1728
- *
1729
- * @param element React Component to check.
1730
- * @returns True when an element is considered empty.
1731
- */
1732
- const isEmptyElement = (element) => {
1733
- if (lodash_1.isNumber(element)) {
1734
- return false;
1735
- }
1736
- if (lodash_1.isString(element) || lodash_1.isArray(element)) {
1737
- return !element.length;
1738
- }
1739
- return !element;
1740
- };
1741
- exports.isEmptyElement = isEmptyElement;
1742
-
1743
-
1744
- /***/ }),
1745
-
1746
- /***/ "./src/utils/index.ts":
1747
- /*!****************************!*\
1748
- !*** ./src/utils/index.ts ***!
1749
- \****************************/
1750
- /*! no static exports found */
1751
- /***/ (function(module, exports, __webpack_require__) {
1752
-
1753
- "use strict";
1754
-
1755
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1756
- if (k2 === undefined) k2 = k;
1757
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1758
- }) : (function(o, m, k, k2) {
1759
- if (k2 === undefined) k2 = k;
1760
- o[k2] = m[k];
1761
- }));
1762
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
1763
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1764
- };
1765
- Object.defineProperty(exports, "__esModule", { value: true });
1766
- __exportStar(__webpack_require__(/*! ./route-utils */ "./src/utils/route-utils.tsx"), exports);
1767
-
1768
-
1769
- /***/ }),
1770
-
1771
- /***/ "./src/utils/route-utils.tsx":
1772
- /*!***********************************!*\
1773
- !*** ./src/utils/route-utils.tsx ***!
1774
- \***********************************/
1775
- /*! no static exports found */
1776
- /***/ (function(module, exports, __webpack_require__) {
1777
-
1778
- "use strict";
1779
-
1780
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1781
- if (k2 === undefined) k2 = k;
1782
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1783
- }) : (function(o, m, k, k2) {
1784
- if (k2 === undefined) k2 = k;
1785
- o[k2] = m[k];
1786
- }));
1787
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1788
- Object.defineProperty(o, "default", { enumerable: true, value: v });
1789
- }) : function(o, v) {
1790
- o["default"] = v;
1791
- });
1792
- var __importStar = (this && this.__importStar) || function (mod) {
1793
- if (mod && mod.__esModule) return mod;
1794
- var result = {};
1795
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1796
- __setModuleDefault(result, mod);
1797
- return result;
1798
- };
1799
- var __rest = (this && this.__rest) || function (s, e) {
1800
- var t = {};
1801
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
1802
- t[p] = s[p];
1803
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
1804
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
1805
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
1806
- t[p[i]] = s[p[i]];
1807
- }
1808
- return t;
1809
- };
1810
- Object.defineProperty(exports, "__esModule", { value: true });
1811
- exports.getSortedRoutes = exports.sortKeys = exports.renderRoutes = exports.getMenus = exports.getRoutes = exports.getRoutes2 = exports.isUrl = void 0;
1812
- const React = __importStar(__webpack_require__(/*! react */ "react"));
1813
- const interfaces_1 = __webpack_require__(/*! ../interfaces */ "./src/interfaces/index.ts");
1814
- const react_router_dom_1 = __webpack_require__(/*! react-router-dom */ "react-router-dom");
1815
- const defaultSortKeys = __webpack_require__(/*! sort-keys */ "sort-keys");
1816
- /* eslint no-useless-escape:0 */
1817
- const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/g;
1818
- function isUrl(path) {
1819
- return reg.test(path);
1820
- }
1821
- exports.isUrl = isUrl;
1822
- /**
1823
- * Generates Routes based on the key value, where key has the path of the route and value
1824
- * has rest of the values for building a `<Router ../>` component.
1825
- *
1826
- * @param path: RegExp
1827
- * @param routerData
1828
- * @deprecated
1829
- */
1830
- function getRoutes2(path, routerData) {
1831
- const routes = Object.keys(routerData).filter(routePath => {
1832
- return routePath.match(path);
1833
- });
1834
- const mappedRoutes = routes.map(paths => {
1835
- return Object.assign({ route: paths }, routerData[paths]);
1836
- });
1837
- const root = {};
1838
- mappedRoutes.forEach(eachRoute => {
1839
- const children = eachRoute.route.split('/');
1840
- children.shift();
1841
- // if the route is `/` then add this correction.
1842
- if (eachRoute.route === '/') {
1843
- children.shift();
1844
- children.push('/');
1845
- }
1846
- const depth = children.length;
1847
- let lastNode = root;
1848
- for (let i = 0; i <= depth; i++) {
1849
- const lastIndex = (lastNode.routes || []).findIndex(item => {
1850
- if (eachRoute.route.startsWith(item.path)) {
1851
- return eachRoute.route[item.path.length] === '/';
1852
- }
1853
- });
1854
- if (lastIndex === -1) {
1855
- break;
1856
- }
1857
- lastNode = lastNode.routes[lastIndex];
1858
- // do not overwrite the route's exact value
1859
- lastNode.exact = routerData[lastNode.path].hasOwnProperty('exact') ? routerData[lastNode.path].exact : false;
1860
- }
1861
- if (!lastNode.routes) {
1862
- lastNode.routes = [];
1863
- }
1864
- const modfiedRoute = formatSlash(eachRoute.route);
1865
- lastNode.routes.push(Object.assign(Object.assign({}, eachRoute), {
1866
- // route: modfiedRoute,
1867
- path: modfiedRoute, exact: routerData[eachRoute.route].hasOwnProperty('exact') ? routerData[eachRoute.route].exact : true, component: eachRoute.component }));
1868
- });
1869
- return root.routes;
1870
- }
1871
- exports.getRoutes2 = getRoutes2;
1872
- const startWithMoreThanOneSlash = /^(\/)\1+/; // for exame `//abc, ///abc, ...`
1873
- const formatSlash = (route) => {
1874
- // replaced `//` with `/` in the routes.
1875
- return {
1876
- path: route.replace(startWithMoreThanOneSlash, '/'),
1877
- _pathPrefix: (route.match(/^\/(\/{1,})/) || ['', ''])[1],
1878
- };
1879
- };
1880
- function getRoutes(path, routeData, authWrapper = null) {
1881
- if (!path.startsWith('/')) {
1882
- throw new Error('Invalid path!');
1883
- }
1884
- let searchPath = path;
1885
- if (path[path.length - 1] !== '/') {
1886
- searchPath = path + '/';
1887
- }
1888
- const routes = Object.keys(routeData).filter(menuPath => {
1889
- return menuPath.indexOf(searchPath) === 0 || menuPath === path;
1890
- });
1891
- const mappedMenuPaths = routes.map(mPath => {
1892
- return Object.assign({ route: mPath, position: interfaces_1.IMenuPosition.MIDDLE }, routeData[mPath]);
1893
- });
1894
- const root = {
1895
- // just to satisfy types added following
1896
- // TOOD need to correct types so we don't have to enter them.
1897
- name: 'root',
1898
- position: interfaces_1.IMenuPosition.LOGO,
1899
- };
1900
- mappedMenuPaths.forEach(routeItem => {
1901
- const children = routeItem.route.split('/');
1902
- children.shift();
1903
- // if the route is `/` then add this correction.
1904
- if (routeItem.path === '/') {
1905
- children.shift();
1906
- children.push('/');
1907
- }
1908
- const depth = children.length;
1909
- let lastNode = root;
1910
- for (let i = 0; i < depth; i++) {
1911
- const lastIndex = (lastNode.routes || []).findIndex(item => {
1912
- const routePath = `${item._pathPrefix}${item.path}`;
1913
- if (routeItem.route.startsWith(routePath)) {
1914
- return routeItem.route[routePath.length] === '/';
1915
- }
1916
- });
1917
- if (lastIndex === -1) {
1918
- break;
1919
- }
1920
- lastNode = lastNode.routes[lastIndex];
1921
- const lastNodePath = `${lastNode._pathPrefix}${lastNode.path}`;
1922
- lastNode.exact = routeData[lastNodePath].hasOwnProperty('exact') ? routeData[lastNodePath].exact : false;
1923
- }
1924
- if (!lastNode.routes) {
1925
- lastNode.routes = [];
1926
- }
1927
- const { route: ignore, auth } = routeItem, rest = __rest(routeItem, ["route", "auth"]);
1928
- const pathParams = formatSlash(routeItem.route);
1929
- lastNode.routes.push(Object.assign(Object.assign(Object.assign({}, rest), pathParams), { exact: routeData[routeItem.route].hasOwnProperty('exact') ? routeData[routeItem.route].exact : true,
1930
- /**
1931
- * Here we are checking whether auth property is being
1932
- * set by this route and if authWrapper is declared
1933
- * which is a high order component that can take a component
1934
- * and its props as argument then perform some
1935
- * computation and return a component
1936
- */
1937
- component: auth && authWrapper
1938
- ? (props) => authWrapper(routeItem.component, props)
1939
- : routeItem.component }));
1940
- });
1941
- return root.routes;
1942
- }
1943
- exports.getRoutes = getRoutes;
1944
- function getMenus(path, menuData) {
1945
- if (!path.startsWith('/')) {
1946
- throw new Error('Invalid path!');
1947
- }
1948
- let searchPath = path;
1949
- if (path[path.length - 1] !== '/') {
1950
- searchPath = path + '/';
1951
- }
1952
- const routes = Object.keys(menuData).filter(menuPath => {
1953
- return menuPath.indexOf(searchPath) === 0 || menuPath === path;
1954
- });
1955
- const mappedMenuPaths = routes.map(mPath => {
1956
- return Object.assign({ route: mPath, position: interfaces_1.IMenuPosition.MIDDLE }, menuData[mPath]);
1957
- });
1958
- const root = {
1959
- // just to satisfy types added following
1960
- // TOOD need to correct types so we don't have to enter them.
1961
- name: 'root',
1962
- position: interfaces_1.IMenuPosition.LOGO,
1963
- };
1964
- mappedMenuPaths.forEach(menutItem => {
1965
- const children = menutItem.route.split('/');
1966
- children.shift();
1967
- const depth = children.length;
1968
- let lastNode = root;
1969
- for (let i = 0; i < depth; i++) {
1970
- const lastIndex = (lastNode.children || []).findIndex(item => {
1971
- if (menutItem.route.startsWith(item.path)) {
1972
- return menutItem.route[item.path.length] === '/';
1973
- }
1974
- });
1975
- if (lastIndex === -1) {
1976
- break;
1977
- }
1978
- lastNode = lastNode.children[lastIndex];
1979
- // do not overwrite the route's exact value
1980
- lastNode.exact = menuData[lastNode.path].hasOwnProperty('exact') ? menuData[lastNode.path].exact : false;
1981
- }
1982
- if (!lastNode.children) {
1983
- lastNode.children = [];
1984
- }
1985
- const { route: ignore } = menutItem, rest = __rest(menutItem, ["route"]);
1986
- lastNode.children.push(Object.assign(Object.assign({ path: menutItem.route }, rest), { exact: menuData[menutItem.route].hasOwnProperty('exact') ? menuData[menutItem.route].exact : true }));
1987
- });
1988
- return root.children;
1989
- }
1990
- exports.getMenus = getMenus;
1991
- const renderRoutes = (routes, solidRoutes, extraProps = {}, switchProps = {}) => routes ? (React.createElement(React.Fragment, null, [
1992
- ...solidRoutes,
1993
- ...routes.map((route, i) => (React.createElement(react_router_dom_1.Route, { key: route.key || i, path: route.path, exact: route.exact, strict: route.strict, render: props => route.render ? (route.render(Object.assign(Object.assign(Object.assign({}, props), extraProps), { route: route }))) : (React.createElement(route.component, Object.assign({}, props, extraProps, { route: route }))) }))),
1994
- ])) : null;
1995
- exports.renderRoutes = renderRoutes;
1996
- function sortKeys(routeData) {
1997
- return defaultSortKeys(routeData, { compare });
1998
- }
1999
- exports.sortKeys = sortKeys;
2000
- const getSortedRoutes = (path, routeData, authWrapper = null) => {
2001
- const sortedRoutes = sortKeys(routeData);
2002
- return getRoutes(path, sortedRoutes, authWrapper);
2003
- };
2004
- exports.getSortedRoutes = getSortedRoutes;
2005
- const compare = ((a, b) => {
2006
- const aStr = String(a).toLowerCase();
2007
- const bStr = String(b).toLowerCase();
2008
- // Alphanumeric elements always come before non-alphanumeric elements
2009
- const aIsAlphanumeric = notStartWithColon(aStr);
2010
- const bIsAlphanumeric = notStartWithColon(bStr);
2011
- if (aIsAlphanumeric + bIsAlphanumeric !== -2) {
2012
- if (aIsAlphanumeric * bIsAlphanumeric > 0) {
2013
- if (aIsAlphanumeric === bIsAlphanumeric) {
2014
- return aStr.localeCompare(bStr);
2015
- }
2016
- return aIsAlphanumeric - bIsAlphanumeric;
2017
- }
2018
- if (aIsAlphanumeric > 0) {
2019
- return -1;
2020
- }
2021
- else if (bIsAlphanumeric > 0) {
2022
- return 1;
2023
- }
2024
- }
2025
- // Numerical elements always come before alphabetic elements
2026
- const aNum = Number(a);
2027
- const bNum = Number(b);
2028
- // If both are numerical, sort in the usual fashion (smaller goes first)
2029
- if (aNum && bNum) {
2030
- return aNum - bNum;
2031
- // If a is numerical but b isn't, put a first.
2032
- }
2033
- else if (aNum) {
2034
- return -1;
2035
- // If b is numerical but a isn't, put b first.
2036
- }
2037
- else if (bNum) {
2038
- return 1;
2039
- }
2040
- // In all other cases, default to usual sort order.
2041
- return aStr.localeCompare(bStr);
2042
- });
2043
- function notStartWithColon(str) {
2044
- const match = (str.match(/^[\/, *, :]{1,}/) || [-1])[0];
2045
- if (match === -1) {
2046
- return -1;
2047
- }
2048
- var i = match.length;
2049
- let count = 0;
2050
- while (i--) {
2051
- const char = match[i];
2052
- if (char === '/') {
2053
- if (str === '/') { // if it is root only we put at the last
2054
- count = count + 6;
2055
- }
2056
- else {
2057
- count = count + 3;
2058
- }
2059
- }
2060
- else if (char === ':') {
2061
- count = count + 1;
2062
- }
2063
- else if (char === '*') {
2064
- count = count + 2;
2065
- }
2066
- }
2067
- return count;
2068
- }
2069
-
2070
-
2071
- /***/ }),
2072
-
2073
- /***/ "@common-stack/client-core":
2074
- /*!********************************************!*\
2075
- !*** external "@common-stack/client-core" ***!
2076
- \********************************************/
2077
- /*! no static exports found */
2078
- /***/ (function(module, exports) {
2079
-
2080
- module.exports = require("@common-stack/client-core");
2081
-
2082
- /***/ }),
2083
-
2084
- /***/ "@wordpress/hooks":
2085
- /*!***********************************!*\
2086
- !*** external "@wordpress/hooks" ***!
2087
- \***********************************/
2088
- /*! no static exports found */
2089
- /***/ (function(module, exports) {
2090
-
2091
- module.exports = require("@wordpress/hooks");
2092
-
2093
- /***/ }),
2094
-
2095
- /***/ "lodash":
2096
- /*!*************************!*\
2097
- !*** external "lodash" ***!
2098
- \*************************/
2099
- /*! no static exports found */
2100
- /***/ (function(module, exports) {
2101
-
2102
- module.exports = require("lodash");
2103
-
2104
- /***/ }),
2105
-
2106
- /***/ "react":
2107
- /*!************************!*\
2108
- !*** external "react" ***!
2109
- \************************/
2110
- /*! no static exports found */
2111
- /***/ (function(module, exports) {
2112
-
2113
- module.exports = require("react");
2114
-
2115
- /***/ }),
2116
-
2117
- /***/ "react-dom":
2118
- /*!****************************!*\
2119
- !*** external "react-dom" ***!
2120
- \****************************/
2121
- /*! no static exports found */
2122
- /***/ (function(module, exports) {
2123
-
2124
- module.exports = require("react-dom");
2125
-
2126
- /***/ }),
2127
-
2128
- /***/ "react-router":
2129
- /*!*******************************!*\
2130
- !*** external "react-router" ***!
2131
- \*******************************/
2132
- /*! no static exports found */
2133
- /***/ (function(module, exports) {
2134
-
2135
- module.exports = require("react-router");
2136
-
2137
- /***/ }),
2138
-
2139
- /***/ "react-router-dom":
2140
- /*!***********************************!*\
2141
- !*** external "react-router-dom" ***!
2142
- \***********************************/
2143
- /*! no static exports found */
2144
- /***/ (function(module, exports) {
2145
-
2146
- module.exports = require("react-router-dom");
2147
-
2148
- /***/ }),
2149
-
2150
- /***/ "sort-keys":
2151
- /*!****************************!*\
2152
- !*** external "sort-keys" ***!
2153
- \****************************/
2154
- /*! no static exports found */
2155
- /***/ (function(module, exports) {
2156
-
2157
- module.exports = require("sort-keys");
2158
-
2159
- /***/ })
2160
-
2161
- /******/ });
16
+ __exportStar(require("./connector"), exports);
17
+ __exportStar(require("./router-factory"), exports);
18
+ __exportStar(require("./route"), exports);
19
+ __exportStar(require("./utils"), exports);
20
+ __exportStar(require("./interfaces"), exports);
21
+ __exportStar(require("./plugin-area"), exports);
22
+ __exportStar(require("./route-based-plugin-area"), exports);
23
+ __exportStar(require("./inversify"), exports);
2162
24
  //# sourceMappingURL=index.js.map