mobx-route 0.15.0 → 0.16.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 (155) hide show
  1. package/README.md +5 -7
  2. package/core/config/config.cjs +43 -0
  3. package/core/config/config.d.cts +7 -0
  4. package/core/config/config.d.cts.map +1 -0
  5. package/core/config/config.d.ts +1 -1
  6. package/core/config/config.d.ts.map +1 -1
  7. package/core/config/config.types.cjs +2 -0
  8. package/core/config/config.types.d.cts +11 -0
  9. package/core/config/config.types.d.cts.map +1 -0
  10. package/core/config/config.types.d.ts +1 -1
  11. package/core/config/config.types.d.ts.map +1 -1
  12. package/core/config/index.cjs +18 -0
  13. package/core/config/index.d.cts +3 -0
  14. package/core/config/index.d.cts.map +1 -0
  15. package/core/config/index.d.ts +2 -2
  16. package/core/config/index.d.ts.map +1 -1
  17. package/core/config/index.js +2 -2
  18. package/core/index.cjs +21 -0
  19. package/core/index.d.cts +6 -0
  20. package/core/index.d.cts.map +1 -0
  21. package/core/index.d.ts +5 -5
  22. package/core/index.d.ts.map +1 -1
  23. package/core/index.js +5 -5
  24. package/core/route/index.cjs +18 -0
  25. package/core/route/index.d.cts +3 -0
  26. package/core/route/index.d.cts.map +1 -0
  27. package/core/route/index.d.ts +2 -2
  28. package/core/route/index.d.ts.map +1 -1
  29. package/core/route/index.js +2 -2
  30. package/core/route/route.cjs +296 -0
  31. package/core/route/route.d.cts +107 -0
  32. package/core/route/route.d.cts.map +1 -0
  33. package/core/route/route.d.ts +1 -1
  34. package/core/route/route.d.ts.map +1 -1
  35. package/core/route/route.js +1 -1
  36. package/core/route/route.types.cjs +2 -0
  37. package/core/route/route.types.d.cts +142 -0
  38. package/core/route/route.types.d.cts.map +1 -0
  39. package/core/route/route.types.d.ts +4 -4
  40. package/core/route/route.types.d.ts.map +1 -1
  41. package/core/route-group/index.cjs +18 -0
  42. package/core/route-group/index.d.cts +3 -0
  43. package/core/route-group/index.d.cts.map +1 -0
  44. package/core/route-group/index.d.ts +2 -2
  45. package/core/route-group/index.d.ts.map +1 -1
  46. package/core/route-group/index.js +2 -2
  47. package/core/route-group/route-group.cjs +67 -0
  48. package/core/route-group/route-group.d.cts +31 -0
  49. package/core/route-group/route-group.d.cts.map +1 -0
  50. package/core/route-group/route-group.d.ts +1 -1
  51. package/core/route-group/route-group.d.ts.map +1 -1
  52. package/core/route-group/route-group.types.cjs +2 -0
  53. package/core/route-group/route-group.types.d.cts +15 -0
  54. package/core/route-group/route-group.types.d.cts.map +1 -0
  55. package/core/route-group/route-group.types.d.ts +3 -3
  56. package/core/route-group/route-group.types.d.ts.map +1 -1
  57. package/core/router/index.cjs +18 -0
  58. package/core/router/index.d.cts +3 -0
  59. package/core/router/index.d.cts.map +1 -0
  60. package/core/router/index.d.ts +2 -2
  61. package/core/router/index.d.ts.map +1 -1
  62. package/core/router/index.js +2 -2
  63. package/core/router/router.cjs +42 -0
  64. package/core/router/router.d.cts +18 -0
  65. package/core/router/router.d.cts.map +1 -0
  66. package/core/router/router.d.ts +2 -2
  67. package/core/router/router.d.ts.map +1 -1
  68. package/core/router/router.js +1 -1
  69. package/core/router/router.types.cjs +2 -0
  70. package/core/router/router.types.d.cts +13 -0
  71. package/core/router/router.types.d.cts.map +1 -0
  72. package/core/router/router.types.d.ts +3 -3
  73. package/core/router/router.types.d.ts.map +1 -1
  74. package/core/utils/is-route-entity.cjs +5 -0
  75. package/core/utils/is-route-entity.d.cts +3 -0
  76. package/core/utils/is-route-entity.d.cts.map +1 -0
  77. package/core/utils/is-route-entity.d.ts +1 -1
  78. package/core/utils/is-route-entity.d.ts.map +1 -1
  79. package/core/virtual-route/index.cjs +18 -0
  80. package/core/virtual-route/index.d.cts +3 -0
  81. package/core/virtual-route/index.d.cts.map +1 -0
  82. package/core/virtual-route/index.d.ts +2 -2
  83. package/core/virtual-route/index.d.ts.map +1 -1
  84. package/core/virtual-route/index.js +2 -2
  85. package/core/virtual-route/virtual-route.cjs +133 -0
  86. package/core/virtual-route/virtual-route.d.cts +39 -0
  87. package/core/virtual-route/virtual-route.d.cts.map +1 -0
  88. package/core/virtual-route/virtual-route.d.ts +1 -1
  89. package/core/virtual-route/virtual-route.d.ts.map +1 -1
  90. package/core/virtual-route/virtual-route.js +1 -1
  91. package/core/virtual-route/virtual-route.types.cjs +2 -0
  92. package/core/virtual-route/virtual-route.types.d.cts +57 -0
  93. package/core/virtual-route/virtual-route.types.d.cts.map +1 -0
  94. package/core/virtual-route/virtual-route.types.d.ts +2 -2
  95. package/core/virtual-route/virtual-route.types.d.ts.map +1 -1
  96. package/index.cjs +18 -0
  97. package/index.d.cts +3 -0
  98. package/index.d.cts.map +1 -0
  99. package/index.d.ts +1 -1
  100. package/index.d.ts.map +1 -1
  101. package/index.js +1 -1
  102. package/package.json +29 -128
  103. package/react/components/index.cjs +21 -0
  104. package/react/components/index.d.cts +4 -0
  105. package/react/components/index.d.cts.map +1 -0
  106. package/react/components/index.d.ts +3 -3
  107. package/react/components/index.d.ts.map +1 -1
  108. package/react/components/index.js +3 -3
  109. package/react/components/link.cjs +79 -0
  110. package/react/components/link.d.cts +23 -0
  111. package/react/components/link.d.cts.map +1 -0
  112. package/react/components/link.d.ts +1 -1
  113. package/react/components/link.d.ts.map +1 -1
  114. package/react/components/link.js +2 -4
  115. package/react/components/route-view-group.cjs +57 -0
  116. package/react/components/route-view-group.d.cts +26 -0
  117. package/react/components/route-view-group.d.cts.map +1 -0
  118. package/react/components/route-view-group.d.ts +1 -1
  119. package/react/components/route-view-group.d.ts.map +1 -1
  120. package/react/components/route-view-group.js +3 -3
  121. package/react/components/route-view.cjs +43 -0
  122. package/react/components/route-view.d.cts +25 -0
  123. package/react/components/route-view.d.cts.map +1 -0
  124. package/react/components/route-view.d.ts +1 -1
  125. package/react/components/route-view.d.ts.map +1 -1
  126. package/react/index.cjs +17 -0
  127. package/react/index.d.cts +2 -0
  128. package/react/index.d.cts.map +1 -0
  129. package/react/index.d.ts +1 -1
  130. package/react/index.d.ts.map +1 -1
  131. package/react/index.js +1 -1
  132. package/view-model/index.cjs +17 -0
  133. package/view-model/index.d.cts +2 -0
  134. package/view-model/index.d.cts.map +1 -0
  135. package/view-model/index.d.ts +1 -1
  136. package/view-model/index.d.ts.map +1 -1
  137. package/view-model/index.js +1 -1
  138. package/view-model/route-view-model.cjs +37 -0
  139. package/view-model/route-view-model.d.cts +13 -0
  140. package/view-model/route-view-model.d.cts.map +1 -0
  141. package/view-model/route-view-model.d.ts +1 -1
  142. package/view-model/route-view-model.d.ts.map +1 -1
  143. package/view-model/route-view-model.js +1 -1
  144. package/assets/logo.png +0 -0
  145. package/assets/logo.pxz +0 -0
  146. package/assets/new-logo.pxz +0 -0
  147. package/core/route/route.test.d.ts +0 -19
  148. package/core/route/route.test.d.ts.map +0 -1
  149. package/core/route/route.test.js +0 -250
  150. package/core/utils/build-url.d.ts +0 -3
  151. package/core/utils/build-url.d.ts.map +0 -1
  152. package/core/utils/build-url.js +0 -12
  153. package/react/components/route-view-group.test.d.ts +0 -2
  154. package/react/components/route-view-group.test.d.ts.map +0 -1
  155. package/react/components/route-view-group.test.js +0 -101
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx-route",
3
- "version": "0.15.0",
3
+ "version": "0.16.1",
4
4
  "keywords": [
5
5
  "mobx",
6
6
  "react",
@@ -11,7 +11,7 @@
11
11
  ],
12
12
  "author": "js2me",
13
13
  "license": "MIT",
14
- "description": "simple and lightweight typed router",
14
+ "description": "Simple and lightweight typed router",
15
15
  "type": "module",
16
16
  "bugs": {
17
17
  "url": "https://github.com/js2me/mobx-route/issues"
@@ -26,7 +26,7 @@
26
26
  "mobx-location-history": "^8.1.1",
27
27
  "path-to-regexp": "^8.2.0",
28
28
  "react-simple-loadable": "^2.3.8",
29
- "yummies": "^4.12.2"
29
+ "yummies": "^5.4.8"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "mobx": "^6.12.4",
@@ -46,161 +46,62 @@
46
46
  }
47
47
  },
48
48
  "devDependencies": {
49
+ "@biomejs/biome": "2.2.4",
49
50
  "@changesets/changelog-github": "^0.5.1",
50
51
  "@changesets/cli": "^2.29.5",
51
- "@biomejs/biome": "2.1.4",
52
- "@types/react": "^18.0.0 || ^19.0.0",
53
52
  "@testing-library/react": "^16.3.0",
54
53
  "@types/lodash-es": "^4.17.12",
55
54
  "@types/node": "^20.17.30",
55
+ "@types/react": "^18.0.0 || ^19.0.0",
56
56
  "@vitejs/plugin-react-swc": "^3.9.0",
57
57
  "@vitest/coverage-istanbul": "^3.1.2",
58
58
  "commitfmt": "^1.0.4",
59
- "js2me-biome-config": "^1.0.3",
60
- "js2me-exports-post-build-script": "^5.0.1",
59
+ "js2me-biome-config": "^1.0.5",
60
+ "sborshik": "^1.0.8",
61
61
  "jsdom": "^26.1.0",
62
62
  "lefthook": "^1.11.13",
63
63
  "nodemon": "^3.1.10",
64
64
  "rimraf": "^6.0.1",
65
65
  "typescript": "^5.8.3",
66
- "vitest": "^3.1.2"
66
+ "vitest": "^3.1.2",
67
+ "zshy": "^0.4.2"
67
68
  },
69
+ "files": [
70
+ "*"
71
+ ],
72
+ "main": "./index.cjs",
73
+ "module": "./index.js",
74
+ "types": "./index.d.cts",
68
75
  "exports": {
69
- "./core/config/config": {
70
- "import": "./core/config/config.js",
71
- "default": "./core/config/config.js",
72
- "types": "./core/config/config.d.ts"
73
- },
74
- "./core/config": {
75
- "import": "./core/config/index.js",
76
- "default": "./core/config/index.js",
77
- "types": "./core/config/index.d.ts"
78
- },
79
- "./core": {
80
- "import": "./core/index.js",
81
- "default": "./core/index.js",
82
- "types": "./core/index.d.ts"
83
- },
84
- "./core/route": {
85
- "import": "./core/route/index.js",
86
- "default": "./core/route/index.js",
87
- "types": "./core/route/index.d.ts"
88
- },
89
- "./core/route/route.test": {
90
- "import": "./core/route/route.test.js",
91
- "default": "./core/route/route.test.js",
92
- "types": "./core/route/route.test.d.ts"
93
- },
94
- "./core/route/route": {
95
- "import": "./core/route/route.js",
96
- "default": "./core/route/route.js",
97
- "types": "./core/route/route.d.ts"
98
- },
99
- "./core/route-group": {
100
- "import": "./core/route-group/index.js",
101
- "default": "./core/route-group/index.js",
102
- "types": "./core/route-group/index.d.ts"
103
- },
104
- "./core/route-group/route-group": {
105
- "import": "./core/route-group/route-group.js",
106
- "default": "./core/route-group/route-group.js",
107
- "types": "./core/route-group/route-group.d.ts"
108
- },
109
- "./core/router": {
110
- "import": "./core/router/index.js",
111
- "default": "./core/router/index.js",
112
- "types": "./core/router/index.d.ts"
113
- },
114
- "./core/router/router": {
115
- "import": "./core/router/router.js",
116
- "default": "./core/router/router.js",
117
- "types": "./core/router/router.d.ts"
118
- },
119
- "./core/utils/build-url": {
120
- "import": "./core/utils/build-url.js",
121
- "default": "./core/utils/build-url.js",
122
- "types": "./core/utils/build-url.d.ts"
123
- },
124
- "./core/utils/is-route-entity": {
125
- "import": "./core/utils/is-route-entity.js",
126
- "default": "./core/utils/is-route-entity.js",
127
- "types": "./core/utils/is-route-entity.d.ts"
128
- },
129
- "./core/virtual-route": {
130
- "import": "./core/virtual-route/index.js",
131
- "default": "./core/virtual-route/index.js",
132
- "types": "./core/virtual-route/index.d.ts"
133
- },
134
- "./core/virtual-route/virtual-route": {
135
- "import": "./core/virtual-route/virtual-route.js",
136
- "default": "./core/virtual-route/virtual-route.js",
137
- "types": "./core/virtual-route/virtual-route.d.ts"
138
- },
76
+ "./package.json": "./package.json",
139
77
  ".": {
78
+ "types": "./index.d.cts",
140
79
  "import": "./index.js",
141
- "default": "./index.js",
142
- "types": "./index.d.ts"
143
- },
144
- "./react/components": {
145
- "import": "./react/components/index.js",
146
- "default": "./react/components/index.js",
147
- "types": "./react/components/index.d.ts"
148
- },
149
- "./react/components/link": {
150
- "import": "./react/components/link.js",
151
- "default": "./react/components/link.js",
152
- "types": "./react/components/link.d.ts"
153
- },
154
- "./react/components/route-view-group.test": {
155
- "import": "./react/components/route-view-group.test.js",
156
- "default": "./react/components/route-view-group.test.js",
157
- "types": "./react/components/route-view-group.test.d.ts"
158
- },
159
- "./react/components/route-view-group": {
160
- "import": "./react/components/route-view-group.js",
161
- "default": "./react/components/route-view-group.js",
162
- "types": "./react/components/route-view-group.d.ts"
163
- },
164
- "./react/components/route-view": {
165
- "import": "./react/components/route-view.js",
166
- "default": "./react/components/route-view.js",
167
- "types": "./react/components/route-view.d.ts"
80
+ "require": "./index.cjs"
168
81
  },
169
82
  "./react": {
83
+ "types": "./react/index.d.cts",
170
84
  "import": "./react/index.js",
171
- "default": "./react/index.js",
172
- "types": "./react/index.d.ts"
85
+ "require": "./react/index.cjs"
173
86
  },
174
87
  "./view-model": {
88
+ "types": "./view-model/index.d.cts",
175
89
  "import": "./view-model/index.js",
176
- "default": "./view-model/index.js",
177
- "types": "./view-model/index.d.ts"
178
- },
179
- "./view-model/route-view-model": {
180
- "import": "./view-model/route-view-model.js",
181
- "default": "./view-model/route-view-model.js",
182
- "types": "./view-model/route-view-model.d.ts"
183
- },
184
- "./package.json": "./package.json"
90
+ "require": "./view-model/index.cjs"
91
+ }
185
92
  },
186
- "files": [
187
- "*"
188
- ],
189
- "main": "./index.js",
190
- "typings": "./index.d.ts",
191
93
  "scripts": {
192
94
  "clean": "rimraf dist",
193
95
  "lint:check": "pnpm exec biome check --write --no-errors-on-unmatched --files-ignore-unknown=true",
194
96
  "ts:check": "tsc --noEmit",
195
97
  "check": "npm run lint:check && npm run ts:check",
196
98
  "prebuild": "npm run clean && npm run check",
197
- "build:watch": "pnpm build && nodemon --watch src --ext ts,tsx --exec \"pnpm build\"",
198
- "build": "tsc && node ./post-build.mjs",
199
- "pub": "PUBLISH=true pnpm run build",
200
- "pub-ci": "PUBLISH=true CI=true pnpm run build",
201
- "pub:patch": "PUBLISH=true PUBLISH_VERSION=patch pnpm run build",
202
- "pub:minor": "PUBLISH=true PUBLISH_VERSION=minor pnpm run build",
203
- "pub:major": "PUBLISH=true PUBLISH_VERSION=major pnpm run build",
99
+ "build:watch": "pnpm build && nodemon --watch src --ext ts --exec \"pnpm build\"",
100
+ "build": "sborshik build --fillDist",
101
+ "pub": "pnpm build && sborshik publish --useDistDir",
102
+ "pub:patch": "PUBLISH_VERSION=patch pnpm pub",
103
+ "pub:minor": "PUBLISH_VERSION=minor pnpm pub",
104
+ "pub:major": "PUBLISH_VERSION=major pnpm pub",
204
105
  "test": "vitest run --config vitest.config.ts",
205
106
  "test:watch": "vitest watch --config vitest.config.ts",
206
107
  "test:coverage": "vitest run --config vitest.config.ts --coverage",
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./link.cjs"), exports);
18
+ __exportStar(require("./route-view.cjs"), exports);
19
+ // export * from './route-group-view.js';
20
+ // export * from './route-view-map.js';
21
+ __exportStar(require("./route-view-group.cjs"), exports);
@@ -0,0 +1,4 @@
1
+ export * from "./link.cjs";
2
+ export * from "./route-view.cjs";
3
+ export * from "./route-view-group.cjs";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/components/index.ts"],"names":[],"mappings":"AAAA,2BAA0B;AAC1B,iCAAgC;AAGhC,uCAAsC"}
@@ -1,4 +1,4 @@
1
- export * from './link.js';
2
- export * from './route-view.js';
3
- export * from './route-view-group.js';
1
+ export * from "./link.js";
2
+ export * from "./route-view.js";
3
+ export * from "./route-view-group.js";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/components/index.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,gCAAgC;AAGhC,sCAAsC"}
@@ -1,5 +1,5 @@
1
- export * from './link.js';
2
- export * from './route-view.js';
1
+ export * from "./link.js";
2
+ export * from "./route-view.js";
3
3
  // export * from './route-group-view.js';
4
4
  // export * from './route-view-map.js';
5
- export * from './route-view-group.js';
5
+ export * from "./route-view-group.js";
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Link = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const mobx_location_history_1 = require("mobx-location-history");
6
+ const mobx_react_lite_1 = require("mobx-react-lite");
7
+ const react_1 = require("react");
8
+ const data_1 = require("yummies/data");
9
+ const index_js_1 = require("../../core/index.cjs");
10
+ exports.Link = (0, mobx_react_lite_1.observer)((0, react_1.forwardRef)(({ to, href: outerHref, mergeQuery, asChild, children, params,
11
+ // route navigate params
12
+ query, replace, state, ...outerAnchorProps }, ref) => {
13
+ const isExternalNavigation = outerAnchorProps.target === '_blank' ||
14
+ outerAnchorProps.target === 'blank';
15
+ const queryDataRef = (0, react_1.useRef)(query);
16
+ if (!(0, data_1.isShallowEqual)(queryDataRef.current, query)) {
17
+ queryDataRef.current = query;
18
+ }
19
+ const { href, navigateParams } = (0, react_1.useMemo)(() => {
20
+ const navigateParams = {
21
+ mergeQuery,
22
+ query,
23
+ replace,
24
+ state,
25
+ };
26
+ const cfg = index_js_1.routeConfig.get();
27
+ let href;
28
+ if (outerHref) {
29
+ href = outerHref;
30
+ }
31
+ else {
32
+ if (typeof to === 'string') {
33
+ const isNeedToMergeQuery = navigateParams.mergeQuery ?? cfg.mergeQuery;
34
+ const [path, ...querySegments] = to.split('?');
35
+ const existedQuery = (0, mobx_location_history_1.parseSearchString)(querySegments.join('?'));
36
+ const query = {
37
+ ...(isNeedToMergeQuery ? cfg.queryParams.data : {}),
38
+ ...existedQuery,
39
+ ...navigateParams.query,
40
+ };
41
+ href = `${path}${(0, mobx_location_history_1.buildSearchString)(query)}`;
42
+ }
43
+ else {
44
+ href = to.createUrl(params, navigateParams.query, navigateParams.mergeQuery);
45
+ }
46
+ }
47
+ return {
48
+ href: cfg.formatLinkHref?.(href) ?? href,
49
+ navigateParams,
50
+ };
51
+ }, [mergeQuery, replace, state, to, queryDataRef.current]);
52
+ const handleClick = (event) => {
53
+ if (isExternalNavigation ||
54
+ event.ctrlKey ||
55
+ event.metaKey ||
56
+ event.altKey ||
57
+ event.shiftKey ||
58
+ event.button !== 0)
59
+ return;
60
+ outerAnchorProps.onClick?.(event);
61
+ if (!event.defaultPrevented) {
62
+ event.preventDefault();
63
+ if (navigateParams.replace) {
64
+ index_js_1.routeConfig.get().history.replace(href, navigateParams.state);
65
+ }
66
+ else {
67
+ index_js_1.routeConfig.get().history.push(href, navigateParams.state);
68
+ }
69
+ }
70
+ };
71
+ const anchorProps = {
72
+ ...outerAnchorProps,
73
+ href,
74
+ onClick: handleClick,
75
+ rel: outerAnchorProps.rel ??
76
+ (isExternalNavigation ? 'noopener noreferrer' : undefined),
77
+ };
78
+ return asChild && (0, react_1.isValidElement)(children) ? ((0, react_1.cloneElement)(children, anchorProps)) : ((0, jsx_runtime_1.jsx)("a", { ...anchorProps, ref: ref, children: children }));
79
+ }));
@@ -0,0 +1,23 @@
1
+ import { type AnchorHTMLAttributes } from 'react';
2
+ import type { IsPartial } from 'yummies/utils/types';
3
+ import { type AnyRoute, type InputPathParams, type RouteNavigateParams } from "../../core/index.cjs";
4
+ interface LinkAnchorProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> {
5
+ asChild?: boolean;
6
+ }
7
+ type LinkPathRouteProps<TRoute extends AnyRoute> = {
8
+ to: TRoute;
9
+ } & (IsPartial<InputPathParams<TRoute['path']>> extends true ? {
10
+ params?: InputPathParams<TRoute['path']> | null | undefined;
11
+ } : {
12
+ params: InputPathParams<TRoute['path']>;
13
+ });
14
+ type LinkSimpleRouteProps = {
15
+ to: string;
16
+ } | {
17
+ href: string;
18
+ };
19
+ export type LinkProps<TRoute extends AnyRoute> = LinkAnchorProps & RouteNavigateParams & (LinkPathRouteProps<TRoute> | LinkSimpleRouteProps);
20
+ type LinkComponentType = <TRoute extends AnyRoute>(props: LinkProps<TRoute>) => React.ReactNode;
21
+ export declare const Link: LinkComponentType;
22
+ export {};
23
+ //# sourceMappingURL=link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../src/react/components/link.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EAO1B,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,mBAAmB,EAEzB,6BAA4B;AAE7B,UAAU,eACR,SAAQ,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC7D,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,KAAK,kBAAkB,CAAC,MAAM,SAAS,QAAQ,IAAI;IACjD,EAAE,EAAE,MAAM,CAAC;CACZ,GAAG,CAAC,SAAS,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,IAAI,GACxD;IACE,MAAM,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;CAC7D,GACD;IAAE,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC,CAAC;AAEjD,KAAK,oBAAoB,GACrB;IACE,EAAE,EAAE,MAAM,CAAC;CACZ,GACD;IACE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEN,MAAM,MAAM,SAAS,CAAC,MAAM,SAAS,QAAQ,IAAI,eAAe,GAC9D,mBAAmB,GACnB,CAAC,kBAAkB,CAAC,MAAM,CAAC,GAAG,oBAAoB,CAAC,CAAC;AAEtD,KAAK,iBAAiB,GAAG,CAAC,MAAM,SAAS,QAAQ,EAC/C,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,KACrB,KAAK,CAAC,SAAS,CAAC;AAErB,eAAO,MAAM,IAAI,EA0HD,iBAAiB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { type AnchorHTMLAttributes } from 'react';
2
2
  import type { IsPartial } from 'yummies/utils/types';
3
- import { type AnyRoute, type InputPathParams, type RouteNavigateParams } from '../../core/index.js';
3
+ import { type AnyRoute, type InputPathParams, type RouteNavigateParams } from "../../core/index.js";
4
4
  interface LinkAnchorProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> {
5
5
  asChild?: boolean;
6
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../src/react/components/link.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EAO1B,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,mBAAmB,EAEzB,MAAM,qBAAqB,CAAC;AAE7B,UAAU,eACR,SAAQ,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC7D,OAAO,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AAkB,CAAC,MAAM,SAAS,QAAQ,IAAI;IACjD,EAAE,EAAE,MAAM,CAAC;CACZ,GAAG,CAAC,SAAS,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,IAAI,GACxD;IACE,MAAM,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;CAC7D,GACD;IAAE,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC,CAAC;AAEjD,KAAK,oBAAoB,GACrB;IACE,EAAE,EAAE,MAAM,CAAC;CACZ,GACD;IACE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEN,MAAM,MAAM,SAAS,CAAC,MAAM,SAAS,QAAQ,IAAI,eAAe,GAC9D,mBAAmB,GACnB,CAAC,kBAAkB,CAAC,MAAM,CAAC,GAAG,oBAAoB,CAAC,CAAC;AAEtD,KAAK,iBAAiB,GAAG,CAAC,MAAM,SAAS,QAAQ,EAC/C,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,KACrB,KAAK,CAAC,SAAS,CAAC;AAErB,eAAO,MAAM,IAAI,EA0HD,iBAAiB,CAAC"}
@@ -3,7 +3,7 @@ import { buildSearchString, parseSearchString } from 'mobx-location-history';
3
3
  import { observer } from 'mobx-react-lite';
4
4
  import { cloneElement, forwardRef, isValidElement, useMemo, useRef, } from 'react';
5
5
  import { isShallowEqual } from 'yummies/data';
6
- import { routeConfig, } from '../../core/index.js';
6
+ import { routeConfig, } from "../../core/index.js";
7
7
  export const Link = observer(forwardRef(({ to, href: outerHref, mergeQuery, asChild, children, params,
8
8
  // route navigate params
9
9
  query, replace, state, ...outerAnchorProps }, ref) => {
@@ -72,7 +72,5 @@ query, replace, state, ...outerAnchorProps }, ref) => {
72
72
  rel: outerAnchorProps.rel ??
73
73
  (isExternalNavigation ? 'noopener noreferrer' : undefined),
74
74
  };
75
- return asChild && isValidElement(children) ? (
76
- // @ts-ignore
77
- cloneElement(children, anchorProps)) : (_jsx("a", { ...anchorProps, ref: ref, children: children }));
75
+ return asChild && isValidElement(children) ? (cloneElement(children, anchorProps)) : (_jsx("a", { ...anchorProps, ref: ref, children: children }));
78
76
  }));
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RouteViewGroup = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const mobx_location_history_1 = require("mobx-location-history");
6
+ const mobx_react_lite_1 = require("mobx-react-lite");
7
+ const react_1 = require("react");
8
+ const index_js_1 = require("../../core/index.cjs");
9
+ const is_route_entity_js_1 = require("../../core/utils/is-route-entity.cjs");
10
+ exports.RouteViewGroup = (0, mobx_react_lite_1.observer)(({ children, layout: Layout, otherwise: otherwiseNavigation,
11
+ // @ts-expect-error
12
+ params, ...navigateParams }) => {
13
+ let activeChildNode = null;
14
+ let lastInactiveChildNode = null;
15
+ const childNodes = Array.isArray(children)
16
+ ? children
17
+ : [children];
18
+ for (const childNode of childNodes) {
19
+ if ((0, react_1.isValidElement)(childNode) &&
20
+ // @ts-expect-error redundand checks better to wrap in this directive
21
+ (0, is_route_entity_js_1.isRouteEntity)(childNode.props?.route) &&
22
+ // @ts-expect-error redundand checks better to wrap in this directive
23
+ childNode.props.route.isOpened) {
24
+ activeChildNode = childNode;
25
+ break;
26
+ }
27
+ else {
28
+ lastInactiveChildNode = childNode;
29
+ }
30
+ }
31
+ const hasActiveChildNode = !!activeChildNode;
32
+ (0, react_1.useEffect)(() => {
33
+ if (!hasActiveChildNode && otherwiseNavigation) {
34
+ if (typeof otherwiseNavigation === 'string') {
35
+ const history = index_js_1.routeConfig.get().history;
36
+ const url = `${otherwiseNavigation}${(0, mobx_location_history_1.buildSearchString)(navigateParams.query || {})}`;
37
+ if (navigateParams.replace) {
38
+ history.replace(url, navigateParams.state);
39
+ }
40
+ else {
41
+ history.push(url, navigateParams.state);
42
+ }
43
+ }
44
+ else if (!otherwiseNavigation.isOpened) {
45
+ otherwiseNavigation.open(params, navigateParams);
46
+ }
47
+ }
48
+ }, [hasActiveChildNode, otherwiseNavigation]);
49
+ if (otherwiseNavigation && !activeChildNode) {
50
+ return null;
51
+ }
52
+ const resultNodeToRender = activeChildNode ?? lastInactiveChildNode ?? null;
53
+ if (Layout) {
54
+ return (0, jsx_runtime_1.jsx)(Layout, { children: resultNodeToRender });
55
+ }
56
+ return resultNodeToRender;
57
+ });
@@ -0,0 +1,26 @@
1
+ import type { IsPartial, Maybe } from 'yummies/utils/types';
2
+ import { type AnyRouteEntity, type RouteNavigateParams, type RouteParams } from "../../core/index.cjs";
3
+ type LayoutComponent = React.ComponentType<{
4
+ children?: React.ReactNode;
5
+ }> | React.ComponentType<{
6
+ children: React.ReactNode;
7
+ }>;
8
+ interface BaseProps extends RouteNavigateParams {
9
+ children: React.ReactNode;
10
+ layout?: LayoutComponent;
11
+ }
12
+ type PropsWithDefaultRoute<TRoute extends AnyRouteEntity> = BaseProps & {
13
+ otherwise?: TRoute;
14
+ } & (IsPartial<RouteParams<TRoute>> extends true ? {
15
+ params?: Maybe<RouteParams<TRoute>>;
16
+ } : {
17
+ params: RouteParams<TRoute>;
18
+ });
19
+ type PropsWithDefaultUrl = BaseProps & {
20
+ otherwise?: string;
21
+ };
22
+ export type RouteViewGroupProps<TRoute extends AnyRouteEntity> = PropsWithDefaultRoute<TRoute> | PropsWithDefaultUrl;
23
+ type RouteViewGroupComponent = <TRoute extends AnyRouteEntity>(props: RouteViewGroupProps<TRoute>) => React.ReactNode;
24
+ export declare const RouteViewGroup: RouteViewGroupComponent;
25
+ export {};
26
+ //# sourceMappingURL=route-view-group.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-view-group.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-view-group.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAEjB,6BAA4B;AAG7B,KAAK,eAAe,GAChB,KAAK,CAAC,aAAa,CAAC;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CAAC,GACnD,KAAK,CAAC,aAAa,CAAC;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CAAC,CAAC;AAEvD,UAAU,SAAU,SAAQ,mBAAmB;IAC7C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B;AAED,KAAK,qBAAqB,CAAC,MAAM,SAAS,cAAc,IAAI,SAAS,GAAG;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,SAAS,IAAI,GAC1C;IACE,MAAM,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;CACrC,GACD;IACE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC7B,CAAC,CAAC;AAET,KAAK,mBAAmB,GAAG,SAAS,GAAG;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,mBAAmB,CAAC,MAAM,SAAS,cAAc,IACzD,qBAAqB,CAAC,MAAM,CAAC,GAC7B,mBAAmB,CAAC;AAExB,KAAK,uBAAuB,GAAG,CAAC,MAAM,SAAS,cAAc,EAC3D,KAAK,EAAE,mBAAmB,CAAC,MAAM,CAAC,KAC/B,KAAK,CAAC,SAAS,CAAC;AAErB,eAAO,MAAM,cAAc,EA8DX,uBAAuB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { IsPartial, Maybe } from 'yummies/utils/types';
2
- import { type AnyRouteEntity, type RouteNavigateParams, type RouteParams } from '../../core/index.js';
2
+ import { type AnyRouteEntity, type RouteNavigateParams, type RouteParams } from "../../core/index.js";
3
3
  type LayoutComponent = React.ComponentType<{
4
4
  children?: React.ReactNode;
5
5
  }> | React.ComponentType<{
@@ -1 +1 @@
1
- {"version":3,"file":"route-view-group.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-view-group.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAEjB,MAAM,qBAAqB,CAAC;AAG7B,KAAK,eAAe,GAChB,KAAK,CAAC,aAAa,CAAC;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CAAC,GACnD,KAAK,CAAC,aAAa,CAAC;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CAAC,CAAC;AAEvD,UAAU,SAAU,SAAQ,mBAAmB;IAC7C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B;AAED,KAAK,qBAAqB,CAAC,MAAM,SAAS,cAAc,IAAI,SAAS,GAAG;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,SAAS,IAAI,GAC1C;IACE,MAAM,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;CACrC,GACD;IACE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC7B,CAAC,CAAC;AAET,KAAK,mBAAmB,GAAG,SAAS,GAAG;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,mBAAmB,CAAC,MAAM,SAAS,cAAc,IACzD,qBAAqB,CAAC,MAAM,CAAC,GAC7B,mBAAmB,CAAC;AAExB,KAAK,uBAA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AC;AAExB,KAAK,uBAAuB,GAAG,CAAC,MAAM,SAAS,cAAc,EAC3D,KAAK,EAAE,mBAAmB,CAAC,MAAM,CAAC,KAC/B,KAAK,CAAC,SAAS,CAAC;AAErB,eAAO,MAAM,cAAc,EA8DX,uBAAuB,CAAC"}
@@ -2,10 +2,10 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { buildSearchString } from 'mobx-location-history';
3
3
  import { observer } from 'mobx-react-lite';
4
4
  import { isValidElement, useEffect } from 'react';
5
- import { routeConfig, } from '../../core/index.js';
6
- import { isRouteEntity } from '../../core/utils/is-route-entity.js';
5
+ import { routeConfig, } from "../../core/index.js";
6
+ import { isRouteEntity } from "../../core/utils/is-route-entity.js";
7
7
  export const RouteViewGroup = observer(({ children, layout: Layout, otherwise: otherwiseNavigation,
8
- // @ts-ignore
8
+ // @ts-expect-error
9
9
  params, ...navigateParams }) => {
10
10
  let activeChildNode = null;
11
11
  let lastInactiveChildNode = null;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RouteView = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const mobx_react_lite_1 = require("mobx-react-lite");
6
+ const react_1 = require("react");
7
+ const react_simple_loadable_1 = require("react-simple-loadable");
8
+ function RouteViewBase(props) {
9
+ // @ts-expect-error redundand pass first argument
10
+ const lazyViewComponentRef = (0, react_1.useRef)();
11
+ let Component;
12
+ if (!('route' in props)) {
13
+ return typeof props.children === 'function'
14
+ ? props.children()
15
+ : props.children;
16
+ }
17
+ if (!props.route.isOpened) {
18
+ return props.fallback ?? null;
19
+ }
20
+ if (props.loadView) {
21
+ if (!lazyViewComponentRef.current) {
22
+ lazyViewComponentRef.current = (0, react_simple_loadable_1.loadable)({
23
+ load: () => props.loadView(props.route),
24
+ loading: props.loading,
25
+ preload: props.preload,
26
+ throwOnError: props.throwOnError,
27
+ });
28
+ }
29
+ Component = lazyViewComponentRef.current;
30
+ }
31
+ else {
32
+ Component = props.view;
33
+ }
34
+ const params = 'params' in props.route ? props.route.params : {};
35
+ if (Component) {
36
+ return (0, jsx_runtime_1.jsx)(Component, { params: params, children: props.children });
37
+ }
38
+ if (typeof props.children === 'function') {
39
+ return props.children(params, props.route);
40
+ }
41
+ return props.children;
42
+ }
43
+ exports.RouteView = (0, mobx_react_lite_1.observer)(RouteViewBase);
@@ -0,0 +1,25 @@
1
+ import { type LoadableConfig } from 'react-simple-loadable';
2
+ import type { AnyAbstractRouteEntity, AnyRoute, AnyVirtualRoute } from "../../core/index.cjs";
3
+ export type RouteViewComponent<TRoute extends AnyAbstractRouteEntity> = React.ComponentType<RouteViewProps<TRoute>>;
4
+ interface RouteViewConfigWithoutRoute {
5
+ children?: React.ReactNode | (() => React.ReactNode);
6
+ }
7
+ export interface RouteViewConfigWithRoute<TRoute extends AnyAbstractRouteEntity> extends Pick<LoadableConfig, 'loading' | 'preload' | 'throwOnError'> {
8
+ route: TRoute;
9
+ view?: RouteViewComponent<TRoute>;
10
+ loadView?: (route: TRoute) => Promise<RouteViewComponent<TRoute>>;
11
+ /**
12
+ * Case when route is not opened
13
+ */
14
+ fallback?: React.ReactNode;
15
+ children?: React.ReactNode | ((params: RouteViewProps<TRoute>['params'], route: TRoute) => React.ReactNode);
16
+ }
17
+ export type RouteViewConfig<TRoute extends AnyAbstractRouteEntity> = RouteViewConfigWithRoute<TRoute> | RouteViewConfigWithoutRoute;
18
+ export type RouteViewProps<TRoute extends AnyAbstractRouteEntity> = {
19
+ children?: React.ReactNode;
20
+ params: TRoute extends AnyRoute ? Exclude<TRoute['params'], null | undefined> : TRoute extends AnyVirtualRoute ? TRoute['params'] : never;
21
+ };
22
+ type RouteViewBaseComponent = <TRoute extends AnyAbstractRouteEntity>(props: RouteViewConfig<TRoute>) => React.ReactNode;
23
+ export declare const RouteView: RouteViewBaseComponent;
24
+ export {};
25
+ //# sourceMappingURL=route-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3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AS,QAAQ,GAC3B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,GAC3C,MAAM,SAAS,eAAe,GAC5B,MAAM,CAAC,QAAQ,CAAC,GAChB,KAAK,CAAC;CACb,CAAC;AAEF,KAAK,sBAAsB,GAAG,CAAC,MAAM,SAAS,sBAAsB,EAClE,KAAK,EAAE,eAAe,CAAC,MAAM,CAAC,KAC3B,KAAK,CAAC,SAAS,CAAC;AA+CrB,eAAO,MAAM,SAAS,EAA8B,sBAAsB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { type LoadableConfig } from 'react-simple-loadable';
2
- import type { AnyAbstractRouteEntity, AnyRoute, AnyVirtualRoute } from '../../core/index.js';
2
+ import type { AnyAbstractRouteEntity, AnyRoute, AnyVirtualRoute } from "../../core/index.js";
3
3
  export type RouteViewComponent<TRoute extends AnyAbstractRouteEntity> = React.ComponentType<RouteViewProps<TRoute>>;
4
4
  interface RouteViewConfigWithoutRoute {
5
5
  children?: React.ReactNode | (() => React.ReactNode);
@@ -1 +1 @@
1
- {"version":3,"file":"route-view.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-view.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAAY,MAAM,uBAAuB,CAAC;AAEtE,OAAO,KAAK,EACV,sBAAsB,EACtB,QAAQ,EACR,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,MAAM,kBAAkB,CAAC,MAAM,SAAS,sBAAsB,IAClE,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;AAE9C,UAAU,2BAA2B;IACnC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,CAAC,MAAM,KAAK,CAAC,SAAS,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,wBAAwB,CAAC,MAAM,SAAS,sBAAsB,CAC7E,SAAQ,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,S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