gemi 0.4.40 → 0.4.42

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 (149) hide show
  1. package/dist/app/App.d.ts +1 -0
  2. package/dist/app/App.d.ts.map +1 -1
  3. package/dist/app/createFlatApiRoutes.d.ts +6 -4
  4. package/dist/app/createFlatApiRoutes.d.ts.map +1 -1
  5. package/dist/app/createFlatViewRoutes.d.ts +6 -4
  6. package/dist/app/createFlatViewRoutes.d.ts.map +1 -1
  7. package/dist/app/index.js +65 -65
  8. package/dist/chunk-00935722c776a294.js +2 -0
  9. package/dist/chunk-030b4fb955329860.js +16 -0
  10. package/dist/chunk-05fa767ab29abb0f.js +2 -0
  11. package/dist/chunk-08539d08fa7362f7.js +2 -0
  12. package/dist/chunk-09dd89e1046786a5.js +2 -0
  13. package/dist/chunk-187a09f46e2b36e5.js +2 -0
  14. package/dist/chunk-21fe96d1a3bb5a27.js +2 -0
  15. package/dist/chunk-26a5c9db5d17f5e7.js +3 -0
  16. package/dist/chunk-29c46abebbc0f09b.js +2 -0
  17. package/dist/chunk-2b3eabd01b2ae3f8.js +2 -0
  18. package/dist/chunk-2f6867d08b95f2d2.js +2 -0
  19. package/dist/chunk-3567e8e424a60c99.js +18 -0
  20. package/dist/chunk-3a3092db69408490.js +2 -0
  21. package/dist/chunk-3aecba8553e036bf.js +6 -0
  22. package/dist/chunk-40c21fe243675250.js +2 -0
  23. package/dist/chunk-488b4db0c522d44a.js +1 -0
  24. package/dist/chunk-4960e27e19bbe42a.js +2 -0
  25. package/dist/chunk-4d19e16340534ed0.js +1 -1
  26. package/dist/chunk-4eeee2f82b1fa8bb.js +2 -0
  27. package/dist/chunk-51bad63147c3be4e.js +6 -0
  28. package/dist/chunk-584e33c96b1a78e4.js +2 -0
  29. package/dist/chunk-60f3b8242209ac3e.js +18 -0
  30. package/dist/chunk-61abf77c3eee8698.js +2 -0
  31. package/dist/chunk-625025af819f55f5.js +2 -0
  32. package/dist/chunk-6259cd13f53334df.js +2 -0
  33. package/dist/chunk-66ab377654806d08.js +2 -0
  34. package/dist/chunk-68af0a6f6be163ce.js +2 -0
  35. package/dist/chunk-6a28d299b5726bba.js +2 -0
  36. package/dist/chunk-6e415d0e12fc9539.js +1 -0
  37. package/dist/chunk-722f2aeae58daaa3.js +18 -0
  38. package/dist/chunk-76a525af0575486d.js +5 -0
  39. package/dist/chunk-798f550643937b6d.js +2 -0
  40. package/dist/chunk-7ce930fe69575c87.js +2 -0
  41. package/dist/chunk-7e9d5eea3aa359ad.js +2 -0
  42. package/dist/chunk-7ea1baca4032004f.js +2 -0
  43. package/dist/chunk-7ffe2ce59a054e35.js +2 -0
  44. package/dist/chunk-8133ed564834cff3.js +2 -0
  45. package/dist/chunk-81ce9b491b290639.js +1 -0
  46. package/dist/chunk-8a993922ea970923.js +2 -0
  47. package/dist/chunk-8af626a703659719.js +18 -0
  48. package/dist/chunk-901e700a2c2d43f3.js +18 -0
  49. package/dist/chunk-9326224d1e4c1a64.js +2 -0
  50. package/dist/chunk-9501e589e3e86a96.js +2 -0
  51. package/dist/chunk-955e2bfcdb7a7e71.js +2 -0
  52. package/dist/chunk-a2fcc46e344ae7ae.js +2 -0
  53. package/dist/chunk-a3f85d0d3261ae44.js +9 -0
  54. package/dist/chunk-a693f8ec2e8af8ca.js +2 -0
  55. package/dist/chunk-a719a1f305964521.js +1 -1
  56. package/dist/chunk-b05e4833f4bb2f8f.js +9 -0
  57. package/dist/chunk-b3bfe533d66f6a17.js +2 -0
  58. package/dist/chunk-b5d6eb761760b2a7.js +6 -0
  59. package/dist/chunk-b66a9e50afbac035.js +1 -1
  60. package/dist/chunk-b7b365f7e6038104.js +2 -0
  61. package/dist/chunk-b9e4546aaa58319c.js +2 -0
  62. package/dist/chunk-bd2888a454e50cfd.js +1 -0
  63. package/dist/chunk-be095501304df604.js +9 -0
  64. package/dist/chunk-bee6075c5738d87a.js +1 -1
  65. package/dist/chunk-bfccfb070c1630e9.js +2 -0
  66. package/dist/chunk-c041f058dc3d571b.js +1 -0
  67. package/dist/chunk-c0bd8e19395d722b.js +2 -0
  68. package/dist/chunk-c124bf801cec12d9.js +2 -0
  69. package/dist/chunk-c153b192112b0d44.js +2 -0
  70. package/dist/chunk-c72bfaa252a03f6f.js +2 -0
  71. package/dist/chunk-c85fc7168a708cb6.js +3 -0
  72. package/dist/chunk-cb65fe402653c65e.js +1 -1
  73. package/dist/chunk-d0806df6defd9dce.js +2 -0
  74. package/dist/chunk-d2e057b6f3f9d500.js +2 -0
  75. package/dist/chunk-d33a0e61ccf1bab5.js +2 -0
  76. package/dist/chunk-da1c673d9685624e.js +2 -0
  77. package/dist/chunk-dcc432bd72fb7e46.js +3 -0
  78. package/dist/chunk-ddef8961cbf08a05.js +6 -0
  79. package/dist/chunk-dfc390f0bbdf5a81.js +1 -0
  80. package/dist/chunk-e53fdd0a1888c5e8.js +2 -0
  81. package/dist/chunk-e9695f3cdafee20b.js +2 -0
  82. package/dist/chunk-edeefd833c30a5ed.js +2 -0
  83. package/dist/chunk-ee4ff285d7f4ccdf.js +1 -1
  84. package/dist/chunk-f08ca4bd263b132b.js +2 -0
  85. package/dist/chunk-f2dca6305fcba70b.js +1 -1
  86. package/dist/chunk-f99bdfc336b2ac57.js +1 -1
  87. package/dist/chunk-ffe161a589b4c44b.js +1 -0
  88. package/dist/client/ClientRouter.d.ts.map +1 -1
  89. package/dist/client/ClientRouterContext.d.ts +3 -11
  90. package/dist/client/ClientRouterContext.d.ts.map +1 -1
  91. package/dist/client/Link.d.ts +13 -0
  92. package/dist/client/Link.d.ts.map +1 -0
  93. package/dist/client/QueryManager.d.ts.map +1 -1
  94. package/dist/client/ServerDataProvider.d.ts +2 -0
  95. package/dist/client/ServerDataProvider.d.ts.map +1 -1
  96. package/dist/client/auth/useForgotPassword.d.ts.map +1 -1
  97. package/dist/client/auth/useResetPassword.d.ts.map +1 -1
  98. package/dist/client/auth/useSignIn.d.ts.map +1 -1
  99. package/dist/client/auth/useSignOut.d.ts.map +1 -1
  100. package/dist/client/auth/useUser.d.ts.map +1 -1
  101. package/dist/client/i18n/I18nContext.d.ts +18 -0
  102. package/dist/client/i18n/I18nContext.d.ts.map +1 -0
  103. package/dist/client/i18n/useLocale.d.ts +2 -0
  104. package/dist/client/i18n/useLocale.d.ts.map +1 -0
  105. package/dist/client/i18n/useScopedTranslator.d.ts +8 -0
  106. package/dist/client/i18n/useScopedTranslator.d.ts.map +1 -0
  107. package/dist/client/i18n/useTranslator.d.ts +2 -0
  108. package/dist/client/i18n/useTranslator.d.ts.map +1 -0
  109. package/dist/client/index.d.ts +7 -2
  110. package/dist/client/index.d.ts.map +1 -1
  111. package/dist/client/index.js +305 -141
  112. package/dist/client/rpc.d.ts +6 -5
  113. package/dist/client/rpc.d.ts.map +1 -1
  114. package/dist/client/types.d.ts +9 -0
  115. package/dist/client/types.d.ts.map +1 -1
  116. package/dist/client/useRouter.d.ts +15 -0
  117. package/dist/client/useRouter.d.ts.map +1 -0
  118. package/dist/client/useSearchParams.d.ts +21 -0
  119. package/dist/client/useSearchParams.d.ts.map +1 -0
  120. package/dist/email/index.js +1 -1
  121. package/dist/facades/I18n.d.ts +5 -0
  122. package/dist/facades/I18n.d.ts.map +1 -0
  123. package/dist/facades/index.d.ts +1 -0
  124. package/dist/facades/index.d.ts.map +1 -1
  125. package/dist/facades/index.js +1 -1
  126. package/dist/http/HttpRequest.d.ts +2 -0
  127. package/dist/http/HttpRequest.d.ts.map +1 -1
  128. package/dist/http/I18nServiceContainer.d.ts +31 -0
  129. package/dist/http/I18nServiceContainer.d.ts.map +1 -0
  130. package/dist/http/I18nServiceProvider.d.ts +10 -0
  131. package/dist/http/I18nServiceProvider.d.ts.map +1 -0
  132. package/dist/http/index.d.ts +1 -0
  133. package/dist/http/index.d.ts.map +1 -1
  134. package/dist/http/index.js +1 -1
  135. package/dist/http/requestContext.d.ts +2 -0
  136. package/dist/http/requestContext.d.ts.map +1 -1
  137. package/dist/kernel/Kernel.d.ts +5 -0
  138. package/dist/kernel/Kernel.d.ts.map +1 -1
  139. package/dist/kernel/context.d.ts +6 -2
  140. package/dist/kernel/context.d.ts.map +1 -1
  141. package/dist/kernel/index.js +2 -2
  142. package/dist/server/index.js +1 -1
  143. package/dist/storage/index.js +4 -4
  144. package/dist/utils/applyParams.d.ts +2 -0
  145. package/dist/utils/applyParams.d.ts.map +1 -0
  146. package/dist/utils/type.d.ts +1 -0
  147. package/dist/utils/type.d.ts.map +1 -1
  148. package/dist/vite/index.js +1 -1
  149. package/package.json +1 -1
@@ -10,7 +10,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
10
10
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
11
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
12
12
  var _i, _n, _t, _e, _s, _l, _o, _d, _p, _g, _H_instances, r_fn, R_fn, b_fn, u_fn, m_fn, a_fn, P_fn, E_fn, S_fn, O_fn, k_fn, x_fn, h_fn, f_fn, T_fn, A_fn, y_fn, w_fn, c_fn, C_fn, _a, _i2, _n2, _t2, _e2, _s2, _l2, _b;
13
- import require$$1, { createContext, useState, useEffect, useContext, useSyncExternalStore, useRef, lazy, startTransition, StrictMode, Suspense } from "react";
13
+ import require$$1, { createContext, useState, useEffect, useContext, useSyncExternalStore, useRef, lazy, StrictMode, Suspense } from "react";
14
14
  import { jsx, Fragment, jsxs } from "react/jsx-runtime";
15
15
  import require$$2 from "react-dom";
16
16
  class Subject {
@@ -33,15 +33,19 @@ class Subject {
33
33
  return this.value;
34
34
  }
35
35
  }
36
- function applyParams$1(url, params = {}) {
37
- let out = url;
38
- for (const segment of url.split("/")) {
39
- if (segment.includes(":")) {
40
- const key = segment.split(":")[1];
41
- out = out.replace(`:${key}`, params[key]);
36
+ function applyParams$2(url, params) {
37
+ return url.replace(/:([^/]+)/g, (_2, key) => {
38
+ const isOptional = key.endsWith("?");
39
+ const paramName = isOptional ? key.slice(0, -1) : key;
40
+ const value = params[paramName];
41
+ if (value === void 0) {
42
+ if (isOptional) {
43
+ return "";
44
+ }
45
+ throw new Error(`Missing parameter: ${paramName}`);
42
46
  }
43
- }
44
- return out;
47
+ return value;
48
+ }).replace(/\/\//g, "/");
45
49
  }
46
50
  class Resource {
47
51
  constructor(key, fallbackData = null) {
@@ -89,7 +93,7 @@ class Resource {
89
93
  const { query, params } = options;
90
94
  const url = key.split("GET:")[1];
91
95
  const searchParams = new URLSearchParams(query);
92
- const finalUrl = [applyParams$1(url, params), searchParams.toString()].filter((s) => s.length > 0).join("?");
96
+ const finalUrl = [applyParams$2(url, params), searchParams.toString()].filter((s) => s.length > 0).join("?");
93
97
  const { data, error } = this.state.getValue();
94
98
  this.state.next({
95
99
  data,
@@ -183,7 +187,7 @@ function useQuery(url, ...args) {
183
187
  mutate: resource.mutate.bind(resource)
184
188
  };
185
189
  }
186
- function applyParams(url, params = {}) {
190
+ function applyParams$1(url, params = {}) {
187
191
  let out = url;
188
192
  for (const [key, value] of Object.entries(params)) {
189
193
  out = out.replace(`:${key}?`, value).replace(`:${key}`, value);
@@ -218,7 +222,7 @@ function useMutation(url, ...args) {
218
222
  const params = "params" in inputs ? inputs.params : {};
219
223
  const [method] = String(url).split(":");
220
224
  const finalUrl = [
221
- applyParams(String(url).replace(`${method}:`, ""), params),
225
+ applyParams$1(String(url).replace(`${method}:`, ""), params),
222
226
  new URLSearchParams(query).toString()
223
227
  ].join("?");
224
228
  let body = null;
@@ -600,31 +604,6 @@ function parsePath(path) {
600
604
  }
601
605
  return parsedPath;
602
606
  }
603
- function flattenComponentTree(componentTree) {
604
- let out = [];
605
- for (const [root, branches] of componentTree) {
606
- out.push(root, ...flattenComponentTree(branches).flat());
607
- }
608
- return Array.from(new Set(out));
609
- }
610
- let viewImportMap = null;
611
- if (typeof window !== "undefined" && process.env.NODE_ENV !== "test") {
612
- viewImportMap = {};
613
- const { componentTree } = window.__GEMI_DATA__;
614
- for (const viewName of flattenComponentTree(componentTree)) {
615
- viewImportMap[viewName] = lazy(window.loaders[viewName]);
616
- }
617
- }
618
- const ComponentsContext = createContext({ viewImportMap });
619
- const ComponentsProvider = (props) => {
620
- return /* @__PURE__ */ jsx(
621
- ComponentsContext.Provider,
622
- {
623
- value: { viewImportMap: props.viewImportMap ?? viewImportMap },
624
- children: props.children
625
- }
626
- );
627
- };
628
607
  var R = class {
629
608
  constructor(t, r, n, o, c, l) {
630
609
  __publicField(this, "type", 3);
@@ -1368,24 +1347,35 @@ const ClientRouterProvider = (props) => {
1368
1347
  window.scrollY
1369
1348
  );
1370
1349
  };
1371
- const getViewPathsFromPathname = (pathname2) => {
1372
- for (const [route, views] of Object.entries(routeManifest)) {
1373
- const urlPattern = new me({ pathname: route });
1350
+ const findMatchingRouteFromParams = (pathname2) => {
1351
+ const candidates = [];
1352
+ for (const route2 of Object.keys(routeManifest)) {
1353
+ const urlPattern = new me({ pathname: route2 });
1374
1354
  if (urlPattern.test({ pathname: pathname2 })) {
1375
- return views;
1355
+ candidates.push(route2);
1376
1356
  }
1377
1357
  }
1378
- return [];
1358
+ const sortedCandidates = candidates.sort((a, b2) => {
1359
+ const x2 = a.split("/").length + a.split(":").length;
1360
+ const y2 = b2.split("/").length + b2.split(":").length;
1361
+ return x2 - y2;
1362
+ });
1363
+ const [route] = sortedCandidates ?? [];
1364
+ return route;
1365
+ };
1366
+ const getViewPathsFromPathname = (pathname2) => {
1367
+ const route = findMatchingRouteFromParams(pathname2);
1368
+ return routeManifest[route] ?? [];
1369
+ };
1370
+ const getRoutePathnameFromHref = (href) => {
1371
+ const route = findMatchingRouteFromParams(href);
1372
+ return route;
1379
1373
  };
1380
1374
  const getParams = (pathname2) => {
1381
1375
  var _a2;
1382
- for (const route of Object.keys(routeManifest)) {
1383
- const urlPattern = new me({ pathname: route });
1384
- if (urlPattern.test({ pathname: pathname2 })) {
1385
- return (_a2 = urlPattern.exec({ pathname: pathname2 })) == null ? void 0 : _a2.pathname.groups;
1386
- }
1387
- }
1388
- return {};
1376
+ const route = findMatchingRouteFromParams(pathname2);
1377
+ const urlPattern = new me({ pathname: route });
1378
+ return (_a2 = urlPattern.exec({ pathname: pathname2 })) == null ? void 0 : _a2.pathname.groups;
1389
1379
  };
1390
1380
  useEffect(() => {
1391
1381
  history == null ? void 0 : history.listen(({ location }) => {
@@ -1430,7 +1420,8 @@ const ClientRouterProvider = (props) => {
1430
1420
  },
1431
1421
  viewEntriesSubject: viewEntriesSubject.current,
1432
1422
  updatePageData,
1433
- getPageData
1423
+ getPageData,
1424
+ getRoutePathnameFromHref
1434
1425
  },
1435
1426
  children
1436
1427
  }
@@ -1456,84 +1447,221 @@ function useParams() {
1456
1447
  const { params } = useContext(ClientRouterContext);
1457
1448
  return params;
1458
1449
  }
1459
- function useSearchParams() {
1460
- const { locationSubject, history } = useContext(ClientRouterContext);
1461
- const location = useLocation();
1462
- const searchParams = new URLSearchParams(location.search);
1463
- const setSearchParams = (newSearchParams) => {
1464
- let nextSearchParams = newSearchParams;
1465
- if (typeof newSearchParams === "function") {
1466
- nextSearchParams = newSearchParams(searchParams);
1467
- }
1468
- locationSubject.next({
1469
- ...locationSubject.getValue(),
1470
- search: nextSearchParams.toString()
1471
- });
1472
- history == null ? void 0 : history.push({
1473
- search: nextSearchParams.toString()
1474
- });
1450
+ const ServerDataContext = createContext({});
1451
+ const ServerDataProvider = (props) => {
1452
+ let _value = props.value;
1453
+ if (props.value) {
1454
+ _value = props.value;
1455
+ } else {
1456
+ _value = window.__GEMI_DATA__;
1457
+ }
1458
+ return /* @__PURE__ */ jsx(ServerDataContext.Provider, { value: _value, children: props.children });
1459
+ };
1460
+ const I18nContext = createContext({});
1461
+ const I18nProvider = (props) => {
1462
+ const { i18n } = useContext(ServerDataContext);
1463
+ const locale = Object.keys(i18n)[0];
1464
+ const [currentLocale, setCurrentLocale] = useState(locale);
1465
+ const [dictionary] = useState(() => {
1466
+ const dictionary2 = /* @__PURE__ */ new Map();
1467
+ for (const [locale2, value] of Object.entries(i18n)) {
1468
+ const scopes = /* @__PURE__ */ new Map();
1469
+ for (const [scope, translations] of Object.entries(value)) {
1470
+ scopes.set(scope, translations);
1471
+ }
1472
+ dictionary2.set(locale2, scopes);
1473
+ }
1474
+ return dictionary2;
1475
+ });
1476
+ const [currentTranslations, setCurrentTranslations] = useState(() => {
1477
+ if (!dictionary.has(currentLocale)) {
1478
+ return {};
1479
+ }
1480
+ return Object.fromEntries(dictionary.get(currentLocale).entries());
1481
+ });
1482
+ function updateDictionary(translations) {
1483
+ for (const [locale2, value] of Object.entries(translations)) {
1484
+ if (!dictionary.has(locale2)) {
1485
+ dictionary.set(locale2, /* @__PURE__ */ new Map());
1486
+ }
1487
+ const scopes = dictionary.get(locale2);
1488
+ for (const [scope, translations2] of Object.entries(value)) {
1489
+ if (!scopes.has(scope)) {
1490
+ scopes.set(scope, {});
1491
+ }
1492
+ scopes.set(scope, translations2);
1493
+ }
1494
+ }
1495
+ setCurrentTranslations(
1496
+ Object.fromEntries(dictionary.get(currentLocale).entries())
1497
+ );
1498
+ }
1499
+ const changeLocale = (locale2) => {
1500
+ if (dictionary.has(locale2)) {
1501
+ setCurrentLocale(locale2);
1502
+ setCurrentTranslations(
1503
+ Object.fromEntries(dictionary.get(locale2).entries())
1504
+ );
1505
+ }
1475
1506
  };
1476
- return [searchParams, setSearchParams];
1477
- }
1507
+ const fetchTranslations = async (pathname, locale2) => {
1508
+ const response = await fetch(
1509
+ `/api/__gemi__/services/i18n/translations?scope=${pathname}&locale=${locale2 || currentLocale}`
1510
+ );
1511
+ const translations = await response.json();
1512
+ updateDictionary(translations);
1513
+ };
1514
+ return /* @__PURE__ */ jsx(
1515
+ I18nContext.Provider,
1516
+ {
1517
+ value: {
1518
+ locale: currentLocale,
1519
+ translations: currentTranslations,
1520
+ changeLocale,
1521
+ updateDictionary,
1522
+ fetchTranslations
1523
+ },
1524
+ children: props.children
1525
+ }
1526
+ );
1527
+ };
1478
1528
  function useRouter() {
1479
- const { updatePageData, history, getViewPathsFromPathname } = useContext(ClientRouterContext);
1480
- useContext(ComponentsContext);
1481
- return {
1482
- push: async (to, state) => {
1483
- let path = "";
1484
- let urlSearchParams;
1485
- let hash = "";
1486
- if (typeof to === "string") {
1487
- const [_path, search = ""] = to.split("?");
1488
- path = _path;
1489
- urlSearchParams = new URLSearchParams(search);
1490
- urlSearchParams.set("json", "true");
1491
- } else {
1492
- const { hash: _hash, pathname, search } = to;
1493
- urlSearchParams = new URLSearchParams(search);
1494
- urlSearchParams.set("json", "true");
1495
- path = pathname;
1496
- hash = _hash;
1497
- }
1529
+ const {
1530
+ updatePageData,
1531
+ history,
1532
+ getViewPathsFromPathname,
1533
+ getRoutePathnameFromHref
1534
+ } = useContext(ClientRouterContext);
1535
+ const { fetchTranslations } = useContext(I18nContext);
1536
+ function action(pushOrReplace) {
1537
+ return async (path, ...args) => {
1538
+ const [options = {}] = args;
1539
+ const {
1540
+ search = {},
1541
+ params = {},
1542
+ shallow
1543
+ } = {
1544
+ params: {},
1545
+ shallow: false,
1546
+ ...options
1547
+ };
1548
+ const urlSearchParams = new URLSearchParams(search);
1549
+ const basePath = applyParams$2(path, params);
1550
+ const navigationPath = [
1551
+ applyParams$2(path, params),
1552
+ urlSearchParams.toString()
1553
+ ].join("?");
1498
1554
  const components = getViewPathsFromPathname(path);
1499
- const fetchPath = `${path}?${urlSearchParams.toString()}${hash}`;
1555
+ const fetchUrlSearchParams = new URLSearchParams(urlSearchParams);
1556
+ fetchUrlSearchParams.set("json", "true");
1557
+ const fetchPath = [basePath, fetchUrlSearchParams.toString()].join("?");
1558
+ urlSearchParams.set("json", "true");
1559
+ if (shallow) {
1560
+ history == null ? void 0 : history[pushOrReplace](navigationPath);
1561
+ return;
1562
+ }
1563
+ const routePathname = getRoutePathnameFromHref(path);
1500
1564
  const [res] = await Promise.all([
1501
1565
  fetch(fetchPath),
1566
+ fetchTranslations(routePathname),
1502
1567
  ...components.map((component) => window.loaders[component]())
1503
1568
  ]);
1504
1569
  if (res.ok) {
1505
1570
  const { data, is404 = false } = await res.json();
1506
1571
  updatePageData(data);
1507
- history == null ? void 0 : history.push(to, is404 ? { status: 404 } : state);
1572
+ history == null ? void 0 : history[pushOrReplace](navigationPath, is404 ? { status: 404 } : {});
1508
1573
  window.scrollTo(0, 0);
1509
1574
  }
1510
- }
1575
+ };
1576
+ }
1577
+ return {
1578
+ push: action("push"),
1579
+ replace: action("replace")
1511
1580
  };
1512
1581
  }
1582
+ class SearchParams {
1583
+ constructor(searchParams, callback) {
1584
+ this.searchParams = searchParams;
1585
+ this.callback = callback;
1586
+ }
1587
+ get(key) {
1588
+ return this.searchParams.get(key);
1589
+ }
1590
+ set(key, value) {
1591
+ let entries = {};
1592
+ if (typeof key === "string") {
1593
+ entries[key] = value;
1594
+ } else {
1595
+ entries = key ?? {};
1596
+ }
1597
+ for (const [key2, value2] of Object.entries(entries)) {
1598
+ this.searchParams.set(key2, value2);
1599
+ }
1600
+ return this;
1601
+ }
1602
+ append(key, value) {
1603
+ this.searchParams.append(key, value);
1604
+ return this;
1605
+ }
1606
+ sort() {
1607
+ this.searchParams.sort();
1608
+ return this;
1609
+ }
1610
+ clear() {
1611
+ this.searchParams = new URLSearchParams();
1612
+ return this;
1613
+ }
1614
+ delete(key) {
1615
+ const keys = Array.isArray(key) ? key : [key];
1616
+ for (const key2 of keys) {
1617
+ this.searchParams.delete(key2);
1618
+ }
1619
+ return this;
1620
+ }
1621
+ toJSON() {
1622
+ return Object.fromEntries(this.searchParams.entries());
1623
+ }
1624
+ toString() {
1625
+ return this.searchParams.toString();
1626
+ }
1627
+ push(mode = "hard") {
1628
+ this.callback(this.toJSON(), mode === "soft");
1629
+ }
1630
+ }
1631
+ function useSearchParams() {
1632
+ const { push } = useRouter();
1633
+ const location = useLocation();
1634
+ const callback = (search, shallow) => push(location.pathname, {
1635
+ search,
1636
+ shallow
1637
+ });
1638
+ const searchParams = new SearchParams(
1639
+ new URLSearchParams(location.search),
1640
+ callback
1641
+ );
1642
+ return searchParams;
1643
+ }
1513
1644
  const Link = (props) => {
1514
- const { href, onClick, active = false, ...rest } = props;
1645
+ const {
1646
+ href,
1647
+ onClick,
1648
+ active = false,
1649
+ params = {},
1650
+ search = {},
1651
+ ...rest
1652
+ } = { params: {}, ...props };
1515
1653
  const { push } = useRouter();
1516
1654
  const { pathname } = useLocation();
1517
- let path = "";
1518
- if (typeof href === "string") {
1519
- path = `${href}`;
1520
- } else {
1521
- const { hash, pathname: pathname2, search } = href;
1522
- const urlSearchParams = new URLSearchParams(search);
1523
- path = `${pathname2}${urlSearchParams.toString()}${hash}`;
1524
- }
1525
- const p = typeof href === "string" ? href : href.pathname;
1655
+ const path = applyParams$2(href, params);
1526
1656
  return /* @__PURE__ */ jsx(
1527
1657
  "a",
1528
1658
  {
1529
- "data-active": active || pathname === p,
1659
+ "data-active": active || pathname === path,
1530
1660
  href: path,
1531
1661
  onClick: (e) => {
1532
1662
  e.preventDefault();
1533
1663
  onClick == null ? void 0 : onClick(e);
1534
- startTransition(() => {
1535
- push(href);
1536
- });
1664
+ push(href, { search, params });
1537
1665
  },
1538
1666
  ...rest
1539
1667
  }
@@ -5262,7 +5390,7 @@ function requireReactDomClient_production() {
5262
5390
  workInProgressRootSkippedLanes |= hook;
5263
5391
  return prevValue;
5264
5392
  }
5265
- function startTransition2(fiber, queue, pendingState, finishedState, callback) {
5393
+ function startTransition(fiber, queue, pendingState, finishedState, callback) {
5266
5394
  var previousPriority = ReactDOMSharedInternals.p;
5267
5395
  ReactDOMSharedInternals.p = 0 !== previousPriority && 8 > previousPriority ? previousPriority : 8;
5268
5396
  var prevTransition = ReactSharedInternals.T, currentTransition = {};
@@ -5294,7 +5422,7 @@ function requireReactDomClient_production() {
5294
5422
  function startHostTransition(formFiber, pendingState, action, formData) {
5295
5423
  if (5 !== formFiber.tag) throw Error(formatProdErrorMessage(476));
5296
5424
  var queue = ensureFormComponentIsStateful(formFiber).queue;
5297
- startTransition2(
5425
+ startTransition(
5298
5426
  formFiber,
5299
5427
  queue,
5300
5428
  pendingState,
@@ -5549,7 +5677,7 @@ function requireReactDomClient_production() {
5549
5677
  },
5550
5678
  useTransition: function() {
5551
5679
  var stateHook = mountStateImpl(false);
5552
- stateHook = startTransition2.bind(
5680
+ stateHook = startTransition.bind(
5553
5681
  null,
5554
5682
  currentlyRenderingFiber$1,
5555
5683
  stateHook.queue,
@@ -17706,7 +17834,7 @@ function requireReactDomClient_development() {
17706
17834
  workInProgressRootSkippedLanes |= hook;
17707
17835
  return prevValue;
17708
17836
  }
17709
- function startTransition2(fiber, queue, pendingState, finishedState, callback) {
17837
+ function startTransition(fiber, queue, pendingState, finishedState, callback) {
17710
17838
  var previousPriority = ReactDOMSharedInternals.p;
17711
17839
  ReactDOMSharedInternals.p = 0 !== previousPriority && previousPriority < ContinuousEventPriority ? previousPriority : ContinuousEventPriority;
17712
17840
  var prevTransition = ReactSharedInternals.T, currentTransition = {};
@@ -17742,7 +17870,7 @@ function requireReactDomClient_development() {
17742
17870
  "Expected the form instance to be a HostComponent. This is a bug in React."
17743
17871
  );
17744
17872
  var queue = ensureFormComponentIsStateful(formFiber).queue;
17745
- startTransition2(
17873
+ startTransition(
17746
17874
  formFiber,
17747
17875
  queue,
17748
17876
  pendingState,
@@ -17797,7 +17925,7 @@ function requireReactDomClient_development() {
17797
17925
  }
17798
17926
  function mountTransition() {
17799
17927
  var stateHook = mountStateImpl(false);
17800
- stateHook = startTransition2.bind(
17928
+ stateHook = startTransition.bind(
17801
17929
  null,
17802
17930
  currentlyRenderingFiber$1,
17803
17931
  stateHook.queue,
@@ -30174,15 +30302,30 @@ if (process.env.NODE_ENV === "production") {
30174
30302
  client.exports = requireReactDomClient_development();
30175
30303
  }
30176
30304
  var clientExports = client.exports;
30177
- const ServerDataContext = createContext({});
30178
- const ServerDataProvider = (props) => {
30179
- let _value = props.value;
30180
- if (props.value) {
30181
- _value = props.value;
30182
- } else {
30183
- _value = window.__GEMI_DATA__;
30305
+ function flattenComponentTree(componentTree) {
30306
+ let out = [];
30307
+ for (const [root, branches] of componentTree) {
30308
+ out.push(root, ...flattenComponentTree(branches).flat());
30184
30309
  }
30185
- return /* @__PURE__ */ jsx(ServerDataContext.Provider, { value: _value, children: props.children });
30310
+ return Array.from(new Set(out));
30311
+ }
30312
+ let viewImportMap = null;
30313
+ if (typeof window !== "undefined" && process.env.NODE_ENV !== "test") {
30314
+ viewImportMap = {};
30315
+ const { componentTree } = window.__GEMI_DATA__;
30316
+ for (const viewName of flattenComponentTree(componentTree)) {
30317
+ viewImportMap[viewName] = lazy(window.loaders[viewName]);
30318
+ }
30319
+ }
30320
+ const ComponentsContext = createContext({ viewImportMap });
30321
+ const ComponentsProvider = (props) => {
30322
+ return /* @__PURE__ */ jsx(
30323
+ ComponentsContext.Provider,
30324
+ {
30325
+ value: { viewImportMap: props.viewImportMap ?? viewImportMap },
30326
+ children: props.children
30327
+ }
30328
+ );
30186
30329
  };
30187
30330
  const Route = (props) => {
30188
30331
  const { componentPath } = props;
@@ -30223,7 +30366,7 @@ const Routes = (props) => {
30223
30366
  const ClientRouter = (props) => {
30224
30367
  const { RootLayout } = props;
30225
30368
  const { routeManifest, router, componentTree, pageData, auth } = useContext(ServerDataContext);
30226
- return /* @__PURE__ */ jsx(QueryManagerProvider, { children: /* @__PURE__ */ jsx(ComponentsProvider, { viewImportMap: props.viewImportMap, children: /* @__PURE__ */ jsx(
30369
+ return /* @__PURE__ */ jsx(I18nProvider, { children: /* @__PURE__ */ jsx(QueryManagerProvider, { children: /* @__PURE__ */ jsx(ComponentsProvider, { viewImportMap: props.viewImportMap, children: /* @__PURE__ */ jsx(
30227
30370
  ClientRouterProvider,
30228
30371
  {
30229
30372
  searchParams: router.searchParams,
@@ -30235,7 +30378,7 @@ const ClientRouter = (props) => {
30235
30378
  routeManifest,
30236
30379
  children: /* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(RootLayout, { children: /* @__PURE__ */ jsx(Routes, { componentTree }) }) })
30237
30380
  }
30238
- ) }) });
30381
+ ) }) }) });
30239
30382
  };
30240
30383
  function init(RootLayout) {
30241
30384
  clientExports.hydrateRoot(
@@ -30311,10 +30454,9 @@ const defaultArgs$3 = {
30311
30454
  };
30312
30455
  function useForgotPassword(args = defaultArgs$3) {
30313
30456
  return useMutation(
30314
- "POST:/forgot-password",
30457
+ "POST:/auth/forgot-password",
30315
30458
  {},
30316
30459
  {
30317
- pathPrefix: "/auth",
30318
30460
  onSuccess: () => {
30319
30461
  args.onSuccess();
30320
30462
  }
@@ -30326,16 +30468,11 @@ const defaultArgs$2 = {
30326
30468
  }
30327
30469
  };
30328
30470
  function useSignIn(args = defaultArgs$2) {
30329
- const { mutate } = useQuery(
30330
- "GET:/me",
30331
- { params: {}, query: {} },
30332
- { pathPrefix: "/auth" }
30333
- );
30471
+ const { mutate } = useQuery("GET:/auth/me", { params: {}, query: {} });
30334
30472
  return useMutation(
30335
- "POST:/sign-in",
30473
+ "POST:/auth/sign-in",
30336
30474
  {},
30337
30475
  {
30338
- pathPrefix: "/auth",
30339
30476
  onSuccess: ({ user }) => {
30340
30477
  args.onSuccess(user);
30341
30478
  mutate(user);
@@ -30344,23 +30481,18 @@ function useSignIn(args = defaultArgs$2) {
30344
30481
  );
30345
30482
  }
30346
30483
  function useSignUp() {
30347
- return useMutation("POST:/sign-up", {}, { pathPrefix: "/auth" });
30484
+ return useMutation("POST:/auth/sign-up", {});
30348
30485
  }
30349
30486
  const defaultArgs$1 = {
30350
30487
  onSuccess: () => {
30351
30488
  }
30352
30489
  };
30353
30490
  function useSignOut(args = defaultArgs$1) {
30354
- const { mutate } = useQuery(
30355
- "GET:/me",
30356
- { params: {}, query: {} },
30357
- { pathPrefix: "/auth" }
30358
- );
30491
+ const { mutate } = useQuery("GET:/auth/me", { params: {}, query: {} });
30359
30492
  return useMutation(
30360
- "POST:/sign-out",
30493
+ "POST:/auth/sign-out",
30361
30494
  {},
30362
30495
  {
30363
- pathPrefix: "/auth",
30364
30496
  onSuccess: () => {
30365
30497
  args.onSuccess();
30366
30498
  mutate(null);
@@ -30374,10 +30506,9 @@ const defaultArgs = {
30374
30506
  };
30375
30507
  function useResetPassword(args = defaultArgs) {
30376
30508
  return useMutation(
30377
- "POST:/reset-password",
30509
+ "POST:/auth/reset-password",
30378
30510
  {},
30379
30511
  {
30380
- pathPrefix: "/auth",
30381
30512
  onSuccess: () => {
30382
30513
  args.onSuccess();
30383
30514
  }
@@ -30387,10 +30518,9 @@ function useResetPassword(args = defaultArgs) {
30387
30518
  function useUser() {
30388
30519
  const { auth } = useContext(ServerDataContext);
30389
30520
  const { data, loading, error } = useQuery(
30390
- "GET:/me",
30521
+ "GET:/auth/me",
30391
30522
  { params: {}, query: {} },
30392
30523
  {
30393
- pathPrefix: "/auth",
30394
30524
  fallbackData: auth.user ? { user: auth == null ? void 0 : auth.user } : null
30395
30525
  }
30396
30526
  );
@@ -30399,6 +30529,38 @@ function useUser() {
30399
30529
  }
30400
30530
  return { user: data == null ? void 0 : data.user, loading, error };
30401
30531
  }
30532
+ function useScopedTranslator(scope) {
30533
+ const { translations } = useContext(I18nContext);
30534
+ return (key, ...args) => {
30535
+ const [params = {}] = args;
30536
+ const _scope = translations[scope];
30537
+ const translation = _scope == null ? void 0 : _scope[key];
30538
+ if (!translation) {
30539
+ return key;
30540
+ }
30541
+ return applyParams(translation, params);
30542
+ };
30543
+ }
30544
+ function applyParams(str, params) {
30545
+ return str.replace(/{([^}]+)}/g, (_2, key) => {
30546
+ const value = params[key];
30547
+ if (value === void 0) {
30548
+ throw new Error(`Missing parameter: ${key}`);
30549
+ }
30550
+ return value;
30551
+ });
30552
+ }
30553
+ function useLocale() {
30554
+ const { changeLocale, locale, fetchTranslations } = useContext(I18nContext);
30555
+ const { getRoutePathnameFromHref } = useContext(ClientRouterContext);
30556
+ const { pathname } = useLocation();
30557
+ const setLocale = async (locale2) => {
30558
+ const x2 = getRoutePathnameFromHref(pathname);
30559
+ await fetchTranslations(x2, locale2);
30560
+ changeLocale(locale2);
30561
+ };
30562
+ return [locale, setLocale];
30563
+ }
30402
30564
  export {
30403
30565
  Form,
30404
30566
  FormError,
@@ -30409,6 +30571,7 @@ export {
30409
30571
  createRoot,
30410
30572
  init,
30411
30573
  useForgotPassword,
30574
+ useLocale,
30412
30575
  useLocation,
30413
30576
  useMutation,
30414
30577
  useMutationStatus,
@@ -30416,6 +30579,7 @@ export {
30416
30579
  useQuery,
30417
30580
  useResetPassword,
30418
30581
  useRouter,
30582
+ useScopedTranslator,
30419
30583
  useSearchParams,
30420
30584
  useSignIn,
30421
30585
  useSignOut,
@@ -1,9 +1,10 @@
1
- import { type AuthApiRouter } from "../auth/AuthenticationServiceProvider";
2
- import { type ViewHandler } from "../http/ViewRouter";
1
+ import { type AuthApiRouter, type AuthViewRouter } from "../auth/AuthenticationServiceProvider";
3
2
  import type { CreateRPC } from "../http/ApiRouter";
4
- export interface RPC extends CreateRPC<AuthApiRouter> {
3
+ import type { CreateViewRPC } from "../http/ViewRouter";
4
+ export interface RPC extends CreateRPC<AuthApiRouter, "/auth"> {
5
5
  }
6
- export interface ViewRPC {
6
+ export interface ViewRPC extends CreateViewRPC<AuthViewRouter, "/auth"> {
7
+ }
8
+ export interface I18nDictionary {
7
9
  }
8
- export type ViewProps<T extends keyof ViewRPC> = ViewRPC[T] extends ViewHandler<infer I, infer O, infer P> ? O : never;
9
10
  //# sourceMappingURL=rpc.d.ts.map