@plumile/backoffice-react 0.1.116 → 0.1.120
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/components/backoffice/billing/BackofficeBillingUsageChart.js +60 -0
- package/lib/esm/components/backoffice/billing/BackofficeBillingUsageChart.js.map +1 -0
- package/lib/esm/components/backoffice/billing/backofficeBillingUsageChart.css.js +7 -0
- package/lib/esm/components/backoffice/billing/backofficeBillingUsageChart.css.js.map +1 -0
- package/lib/esm/components/backoffice/columns/buildDataTableColumns.js +6 -6
- package/lib/esm/components/backoffice/layout/buildSidebarSections.js +167 -151
- package/lib/esm/components/backoffice/layout/buildSidebarSections.js.map +1 -1
- package/lib/esm/components/backoffice/layout/sidebarUtils.js +24 -21
- package/lib/esm/components/backoffice/layout/sidebarUtils.js.map +1 -1
- package/lib/esm/components/backoffice/links/resolveBackofficeLink.js +62 -54
- package/lib/esm/components/backoffice/links/resolveBackofficeLink.js.map +1 -1
- package/lib/esm/components/backoffice/links/resolveBackofficeTargetIcon.js +1 -1
- package/lib/esm/components/backoffice/links/resolveBackofficeTargetIcon.js.map +1 -1
- package/lib/esm/hooks/useBackofficeSidebarPins.js +44 -42
- package/lib/esm/hooks/useBackofficeSidebarPins.js.map +1 -1
- package/lib/esm/index.js +75 -74
- package/lib/esm/pages/BackofficeDashboardPage.helpers.js +1 -0
- package/lib/esm/pages/BackofficeDashboardPage.helpers.js.map +1 -1
- package/lib/esm/pages/BackofficeDashboardPage.js +181 -154
- package/lib/esm/pages/BackofficeDashboardPage.js.map +1 -1
- package/lib/esm/pages/BackofficeEntityDetailPage.js +12 -12
- package/lib/esm/pages/BackofficeLayoutPage.js +133 -129
- package/lib/esm/pages/BackofficeLayoutPage.js.map +1 -1
- package/lib/esm/provider/BackofficeConfigContext.js.map +1 -1
- package/lib/esm/provider/BackofficeProvider.js +126 -121
- package/lib/esm/provider/BackofficeProvider.js.map +1 -1
- package/lib/esm/provider/dashboardRegistrations.js +17 -0
- package/lib/esm/provider/dashboardRegistrations.js.map +1 -0
- package/lib/esm/router/createBackofficeRoutes.js +148 -131
- package/lib/esm/router/createBackofficeRoutes.js.map +1 -1
- package/lib/types/components/backoffice/billing/BackofficeBillingUsageChart.d.ts +25 -0
- package/lib/types/components/backoffice/billing/BackofficeBillingUsageChart.d.ts.map +1 -0
- package/lib/types/components/backoffice/billing/BackofficeBillingUsageChart.stories.d.ts +41 -0
- package/lib/types/components/backoffice/billing/BackofficeBillingUsageChart.stories.d.ts.map +1 -0
- package/lib/types/components/backoffice/billing/backofficeBillingUsageChart.css.d.ts +4 -0
- package/lib/types/components/backoffice/billing/backofficeBillingUsageChart.css.d.ts.map +1 -0
- package/lib/types/components/backoffice/layout/buildSidebarSections.d.ts +2 -1
- package/lib/types/components/backoffice/layout/buildSidebarSections.d.ts.map +1 -1
- package/lib/types/components/backoffice/layout/sidebarUtils.d.ts +1 -0
- package/lib/types/components/backoffice/layout/sidebarUtils.d.ts.map +1 -1
- package/lib/types/components/backoffice/links/resolveBackofficeLink.d.ts.map +1 -1
- package/lib/types/components/backoffice/links/types.d.ts +1 -0
- package/lib/types/components/backoffice/links/types.d.ts.map +1 -1
- package/lib/types/hooks/useBackofficeSidebarPins.d.ts +1 -0
- package/lib/types/hooks/useBackofficeSidebarPins.d.ts.map +1 -1
- package/lib/types/index.d.ts +2 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/pages/BackofficeDashboardPage.d.ts +5 -1
- package/lib/types/pages/BackofficeDashboardPage.d.ts.map +1 -1
- package/lib/types/pages/BackofficeDashboardPage.helpers.d.ts.map +1 -1
- package/lib/types/pages/BackofficeDashboardPage.stories.d.ts +9 -0
- package/lib/types/pages/BackofficeDashboardPage.stories.d.ts.map +1 -0
- package/lib/types/pages/BackofficeLayoutPage.d.ts.map +1 -1
- package/lib/types/provider/BackofficeConfigContext.d.ts +2 -1
- package/lib/types/provider/BackofficeConfigContext.d.ts.map +1 -1
- package/lib/types/provider/BackofficeProvider.d.ts.map +1 -1
- package/lib/types/provider/dashboardRegistrations.d.ts +4 -0
- package/lib/types/provider/dashboardRegistrations.d.ts.map +1 -0
- package/lib/types/provider/types.d.ts +8 -1
- package/lib/types/provider/types.d.ts.map +1 -1
- package/lib/types/router/createBackofficeRoutes.d.ts +8 -2
- package/lib/types/router/createBackofficeRoutes.d.ts.map +1 -1
- package/package.json +13 -13
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
import { BackofficeConfigProvider as e } from "./BackofficeConfigContext.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import v from "
|
|
15
|
-
import
|
|
16
|
-
import b from "
|
|
17
|
-
import x from "@plumile/router/routing/
|
|
18
|
-
import
|
|
2
|
+
import { validateBackofficeDashboardRegistrations as t } from "./dashboardRegistrations.js";
|
|
3
|
+
import { BackofficeRouteFallback as n, BackofficeStaticRouteFallback as r } from "../components/backoffice/routing/BackofficeRouteFallback.js";
|
|
4
|
+
import { BackofficeRoutePendingBar as i } from "../components/backoffice/routing/BackofficeRoutePendingBar.js";
|
|
5
|
+
import { configureRelayEnvironment as a } from "../relay/environment.js";
|
|
6
|
+
import { useRelayEnvironment as o } from "../relay/useRelayEnvironment.js";
|
|
7
|
+
import { createI18nInstance as s } from "../i18n/createI18nInstance.js";
|
|
8
|
+
import { withBackofficeReactI18nResources as c } from "../i18n/resources.js";
|
|
9
|
+
import { RelayProvider as l } from "../relay/RelayProvider.js";
|
|
10
|
+
import { createBackofficeRoutes as u } from "../router/createBackofficeRoutes.js";
|
|
11
|
+
import { createBackofficeEntityRegistry as d } from "./entityRegistry.js";
|
|
12
|
+
import { StrictMode as f, useEffect as p, useMemo as m, useState as h } from "react";
|
|
13
|
+
import { jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
14
|
+
import { I18nextProvider as v } from "react-i18next";
|
|
15
|
+
import y from "@plumile/router/routing/RoutingContext.js";
|
|
16
|
+
import { createInstance as b } from "i18next";
|
|
17
|
+
import x from "@plumile/router/routing/createRouter.js";
|
|
18
|
+
import S from "@plumile/router/routing/RouterRenderer.js";
|
|
19
|
+
import { ThemeProvider as C } from "@plumile/ui/theme/ThemeProvider.js";
|
|
19
20
|
//#region src/provider/BackofficeProvider.tsx
|
|
20
|
-
var
|
|
21
|
-
let n =
|
|
21
|
+
var w = (e) => e.trim() === "" || e === "/" ? "/" : e.startsWith("/") ? e.endsWith("/") ? e.slice(0, -1) : e : `/${e}`, T = (e, t) => {
|
|
22
|
+
let n = w(t), r = w(e);
|
|
22
23
|
return r === "/" || n === r || n.startsWith(`${r}/`) ? n : n === "/" ? r : `${r}${n}`;
|
|
23
|
-
},
|
|
24
|
+
}, E = (e, t) => Object.fromEntries(Object.entries(e).map(([e, n]) => [e, {
|
|
24
25
|
...n,
|
|
25
26
|
routes: {
|
|
26
|
-
list:
|
|
27
|
-
detail: (e) =>
|
|
28
|
-
detailPage: (e, r) =>
|
|
27
|
+
list: T(t, n.routes.list),
|
|
28
|
+
detail: (e) => T(t, n.routes.detail(e)),
|
|
29
|
+
detailPage: (e, r) => T(t, n.routes.detailPage(e, r))
|
|
29
30
|
}
|
|
30
|
-
}])),
|
|
31
|
-
let [r, i] =
|
|
32
|
-
return
|
|
33
|
-
let r =
|
|
31
|
+
}])), D = ({ routes: e, context: t, instrumentations: n }) => {
|
|
32
|
+
let [r, i] = h(null);
|
|
33
|
+
return p(() => {
|
|
34
|
+
let r = x(e, {
|
|
34
35
|
context: t,
|
|
35
36
|
instrumentations: n
|
|
36
37
|
});
|
|
@@ -42,132 +43,136 @@ var C = (e) => e.trim() === "" || e === "/" ? "/" : e.startsWith("/") ? e.endsWi
|
|
|
42
43
|
n,
|
|
43
44
|
e
|
|
44
45
|
]), r;
|
|
45
|
-
},
|
|
46
|
-
let
|
|
46
|
+
}, O = ({ routes: e, instrumentations: t }) => {
|
|
47
|
+
let r = o(), a = D({
|
|
47
48
|
routes: e,
|
|
48
|
-
context:
|
|
49
|
-
instrumentations:
|
|
49
|
+
context: m(() => ({ relayEnvironment: r }), [r]),
|
|
50
|
+
instrumentations: t
|
|
50
51
|
});
|
|
51
|
-
return
|
|
52
|
-
value:
|
|
53
|
-
children: /* @__PURE__ */
|
|
52
|
+
return a == null ? /* @__PURE__ */ g(n, {}) : /* @__PURE__ */ g(y.Provider, {
|
|
53
|
+
value: a.context,
|
|
54
|
+
children: /* @__PURE__ */ g(S, {
|
|
54
55
|
enableTransition: !0,
|
|
55
|
-
fallback: /* @__PURE__ */
|
|
56
|
-
pending: /* @__PURE__ */
|
|
56
|
+
fallback: /* @__PURE__ */ g(n, {}),
|
|
57
|
+
pending: /* @__PURE__ */ g(i, {})
|
|
57
58
|
})
|
|
58
59
|
});
|
|
59
|
-
},
|
|
60
|
-
let
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
httpUrl:
|
|
64
|
-
wsUrl:
|
|
65
|
-
getDataId:
|
|
66
|
-
logEvents:
|
|
67
|
-
getAuthHeaders:
|
|
60
|
+
}, k = (n) => {
|
|
61
|
+
let i = w(n.basePath ?? "/"), o = m(() => E(n.entityManifest, i), [i, n.entityManifest]), y = m(() => d(o, { basePath: i }), [i, o]), x = n.graphql, S = m(() => t(n.dashboards), [n.dashboards]);
|
|
62
|
+
p(() => {
|
|
63
|
+
a({
|
|
64
|
+
httpUrl: x.httpUrl ?? x.endpoint,
|
|
65
|
+
wsUrl: x.wsUrl ?? x.wsEndpoint,
|
|
66
|
+
getDataId: x.getDataId,
|
|
67
|
+
logEvents: x.logEvents,
|
|
68
|
+
getAuthHeaders: x.getAuthHeaders
|
|
68
69
|
});
|
|
69
70
|
}, [
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
x.endpoint,
|
|
72
|
+
x.getAuthHeaders,
|
|
73
|
+
x.getDataId,
|
|
74
|
+
x.httpUrl,
|
|
75
|
+
x.logEvents,
|
|
76
|
+
x.wsEndpoint,
|
|
77
|
+
x.wsUrl
|
|
77
78
|
]);
|
|
78
|
-
let
|
|
79
|
-
|
|
80
|
-
let e = !0,
|
|
81
|
-
e &&
|
|
79
|
+
let T = m(() => c(n.i18n?.resources ?? {}), [n.i18n?.resources]), D = m(() => n.i18n?.instance ?? b(), [n.i18n?.instance]), [k, A] = h(D.isInitialized);
|
|
80
|
+
p(() => {
|
|
81
|
+
let e = !0, t = () => {
|
|
82
|
+
e && A(!0);
|
|
82
83
|
};
|
|
83
|
-
if (
|
|
84
|
-
e = !1,
|
|
84
|
+
if (D.on("initialized", t), D.isInitialized) return t(), () => {
|
|
85
|
+
e = !1, D.off("initialized", t);
|
|
85
86
|
};
|
|
86
87
|
let r = globalThis.setTimeout(() => {
|
|
87
|
-
|
|
88
|
-
}, 0), i =
|
|
88
|
+
D.isInitialized && t();
|
|
89
|
+
}, 0), i = n.i18n?.initOptions ?? {}, a = i.defaultNS ?? "translations", o = i.ns ?? [
|
|
89
90
|
"backofficeReact",
|
|
90
91
|
"translations",
|
|
91
92
|
"ui"
|
|
92
93
|
];
|
|
93
|
-
return
|
|
94
|
-
resources:
|
|
95
|
-
lng:
|
|
96
|
-
fallbackLng:
|
|
94
|
+
return s({
|
|
95
|
+
resources: T,
|
|
96
|
+
lng: n.i18n?.lng,
|
|
97
|
+
fallbackLng: n.i18n?.fallbackLng,
|
|
97
98
|
initOptions: {
|
|
98
99
|
...i,
|
|
99
100
|
defaultNS: a,
|
|
100
|
-
ns:
|
|
101
|
+
ns: o,
|
|
101
102
|
react: {
|
|
102
103
|
useSuspense: !1,
|
|
103
104
|
...i.react
|
|
104
105
|
}
|
|
105
106
|
},
|
|
106
|
-
instance:
|
|
107
|
-
useLanguageDetector:
|
|
108
|
-
detection:
|
|
109
|
-
}).then(
|
|
110
|
-
|
|
107
|
+
instance: D,
|
|
108
|
+
useLanguageDetector: n.i18n?.useLanguageDetector,
|
|
109
|
+
detection: n.i18n?.detection
|
|
110
|
+
}).then(t).catch((e) => {
|
|
111
|
+
t(), console.error(e);
|
|
111
112
|
}), () => {
|
|
112
|
-
e = !1, globalThis.clearTimeout(r),
|
|
113
|
+
e = !1, globalThis.clearTimeout(r), D.off("initialized", t);
|
|
113
114
|
};
|
|
114
115
|
}, [
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
D,
|
|
117
|
+
T,
|
|
118
|
+
n.i18n?.initOptions,
|
|
119
|
+
n.i18n?.detection,
|
|
120
|
+
n.i18n?.fallbackLng,
|
|
121
|
+
n.i18n?.lng,
|
|
122
|
+
n.i18n?.useLanguageDetector
|
|
122
123
|
]);
|
|
123
|
-
let
|
|
124
|
-
basePath:
|
|
125
|
-
entities:
|
|
126
|
-
entityManifest:
|
|
127
|
-
entityRegistry:
|
|
128
|
-
filterColumnAliases:
|
|
129
|
-
sidebar:
|
|
130
|
-
dashboard:
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
let j = m(() => ({
|
|
125
|
+
basePath: i,
|
|
126
|
+
entities: o,
|
|
127
|
+
entityManifest: o,
|
|
128
|
+
entityRegistry: y,
|
|
129
|
+
filterColumnAliases: n.filterColumnAliases,
|
|
130
|
+
sidebar: n.sidebar,
|
|
131
|
+
dashboard: n.dashboard,
|
|
132
|
+
dashboards: S,
|
|
133
|
+
auth: n.auth,
|
|
134
|
+
graphql: n.graphql
|
|
133
135
|
}), [
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
136
|
+
i,
|
|
137
|
+
n.auth,
|
|
138
|
+
n.dashboard,
|
|
139
|
+
S,
|
|
140
|
+
o,
|
|
141
|
+
y,
|
|
142
|
+
n.filterColumnAliases,
|
|
143
|
+
n.graphql,
|
|
144
|
+
n.sidebar
|
|
145
|
+
]), M = m(() => u({
|
|
146
|
+
basePath: i,
|
|
147
|
+
entityManifest: o,
|
|
148
|
+
entityRegistry: y,
|
|
149
|
+
sidebar: n.sidebar,
|
|
150
|
+
auth: n.auth,
|
|
151
|
+
dashboard: n.dashboard,
|
|
152
|
+
dashboards: S,
|
|
153
|
+
toolsOperationPage: n.toolsOperationPage
|
|
150
154
|
}), [
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
155
|
+
i,
|
|
156
|
+
o,
|
|
157
|
+
y,
|
|
158
|
+
n.auth,
|
|
159
|
+
n.dashboard,
|
|
160
|
+
S,
|
|
161
|
+
n.toolsOperationPage,
|
|
162
|
+
n.sidebar
|
|
163
|
+
]), N = /* @__PURE__ */ g(r, { label: "Loading..." });
|
|
164
|
+
return k && (N = /* @__PURE__ */ g(C, { children: /* @__PURE__ */ g(l, { children: /* @__PURE__ */ _(e, {
|
|
165
|
+
value: j,
|
|
166
|
+
children: [n.overlay, /* @__PURE__ */ g(O, {
|
|
167
|
+
routes: M,
|
|
168
|
+
instrumentations: n.instrumentations
|
|
164
169
|
})]
|
|
165
|
-
}) }) })), /* @__PURE__ */
|
|
166
|
-
i18n:
|
|
167
|
-
children:
|
|
170
|
+
}) }) })), /* @__PURE__ */ g(f, { children: /* @__PURE__ */ g(v, {
|
|
171
|
+
i18n: D,
|
|
172
|
+
children: N
|
|
168
173
|
}) });
|
|
169
174
|
};
|
|
170
175
|
//#endregion
|
|
171
|
-
export {
|
|
176
|
+
export { k as BackofficeProvider, k as default };
|
|
172
177
|
|
|
173
178
|
//# sourceMappingURL=BackofficeProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackofficeProvider.js","names":[],"sources":["../../../src/provider/BackofficeProvider.tsx"],"sourcesContent":["import {\n StrictMode,\n useEffect,\n useMemo,\n useState,\n type ContextType,\n type JSX,\n} from 'react';\nimport { createInstance } from 'i18next';\nimport { I18nextProvider } from 'react-i18next';\nimport createRouter from '@plumile/router/routing/createRouter.js';\nimport RouterRenderer from '@plumile/router/routing/RouterRenderer.js';\nimport RoutingContext from '@plumile/router/routing/RoutingContext.js';\nimport { ThemeProvider } from '@plumile/ui/theme/ThemeProvider.js';\n\nimport { type BackofficeEntityManifestMap } from '@plumile/backoffice-core/types.js';\n\nimport { createI18nInstance } from '../i18n/createI18nInstance.js';\nimport { withBackofficeReactI18nResources } from '../i18n/resources.js';\nimport { RelayProvider } from '../relay/RelayProvider.js';\nimport { useRelayEnvironment } from '../relay/useRelayEnvironment.js';\nimport { configureRelayEnvironment } from '../relay/environment.js';\nimport { BackofficeConfigProvider } from './BackofficeConfigContext.js';\nimport {\n createBackofficeRoutes,\n type BackofficeRouterContext,\n} from '../router/createBackofficeRoutes.js';\nimport type { BackofficeProviderProps } from './types.js';\nimport {\n BackofficeRouteFallback,\n BackofficeStaticRouteFallback,\n} from '../components/backoffice/routing/BackofficeRouteFallback.js';\nimport { BackofficeRoutePendingBar } from '../components/backoffice/routing/BackofficeRoutePendingBar.js';\nimport { createBackofficeEntityRegistry } from './entityRegistry.js';\n\nconst normalizeAbsolutePath = (value: string): string => {\n if (value.trim() === '' || value === '/') {\n return '/';\n }\n if (!value.startsWith('/')) {\n return `/${value}`;\n }\n if (value.endsWith('/')) {\n return value.slice(0, -1);\n }\n return value;\n};\n\nconst prefixRoutePath = (basePath: string, value: string): string => {\n const normalizedPath = normalizeAbsolutePath(value);\n const normalizedBasePath = normalizeAbsolutePath(basePath);\n if (normalizedBasePath === '/') {\n return normalizedPath;\n }\n if (\n normalizedPath === normalizedBasePath ||\n normalizedPath.startsWith(`${normalizedBasePath}/`)\n ) {\n return normalizedPath;\n }\n if (normalizedPath === '/') {\n return normalizedBasePath;\n }\n return `${normalizedBasePath}${normalizedPath}`;\n};\n\nconst resolveEntityManifest = (\n manifest: BackofficeEntityManifestMap,\n basePath: string,\n): BackofficeEntityManifestMap => {\n return Object.fromEntries(\n Object.entries(manifest).map(([entityId, item]) => {\n return [\n entityId,\n {\n ...item,\n routes: {\n list: prefixRoutePath(basePath, item.routes.list),\n detail: (id: string) => {\n return prefixRoutePath(basePath, item.routes.detail(id));\n },\n detailPage: (id: string, pageId: string) => {\n return prefixRoutePath(\n basePath,\n item.routes.detailPage(id, pageId),\n );\n },\n },\n } satisfies BackofficeEntityManifestMap[string],\n ] as const;\n }),\n );\n};\n\ntype RouterShellProps = {\n routes: ReturnType<typeof createBackofficeRoutes>;\n instrumentations?: BackofficeProviderProps['instrumentations'];\n};\n\ntype BackofficeRouterInstance = {\n context: NonNullable<ContextType<typeof RoutingContext>>;\n cleanup: () => void;\n};\n\nconst useBackofficeRouterInstance = ({\n routes,\n context,\n instrumentations,\n}: {\n routes: ReturnType<typeof createBackofficeRoutes>;\n context: BackofficeRouterContext;\n instrumentations?: BackofficeProviderProps['instrumentations'];\n}): BackofficeRouterInstance | null => {\n const [router, setRouter] = useState<BackofficeRouterInstance | null>(null);\n\n useEffect(() => {\n const nextRouter = createRouter(routes, {\n context,\n instrumentations,\n });\n setRouter(nextRouter);\n\n return () => {\n nextRouter.cleanup();\n };\n }, [context, instrumentations, routes]);\n\n return router;\n};\n\nconst RouterShell = ({\n routes,\n instrumentations,\n}: RouterShellProps): JSX.Element => {\n const relayEnvironment = useRelayEnvironment();\n\n const routerContext = useMemo(() => {\n return { relayEnvironment };\n }, [relayEnvironment]);\n\n const router = useBackofficeRouterInstance({\n routes,\n context: routerContext,\n instrumentations,\n });\n\n if (router == null) {\n return <BackofficeRouteFallback />;\n }\n\n return (\n <RoutingContext.Provider value={router.context}>\n <RouterRenderer\n enableTransition\n fallback={<BackofficeRouteFallback />}\n pending={<BackofficeRoutePendingBar />}\n />\n </RoutingContext.Provider>\n );\n};\n\nexport const BackofficeProvider = (\n props: BackofficeProviderProps,\n): JSX.Element => {\n const basePath = normalizeAbsolutePath(props.basePath ?? '/');\n\n const entityManifest = useMemo(() => {\n return resolveEntityManifest(props.entityManifest, basePath);\n }, [basePath, props.entityManifest]);\n const entityRegistry = useMemo(() => {\n return createBackofficeEntityRegistry(entityManifest, { basePath });\n }, [basePath, entityManifest]);\n\n const graphQLConfig = props.graphql;\n\n useEffect(() => {\n const httpUrl = graphQLConfig.httpUrl ?? graphQLConfig.endpoint;\n const wsUrl = graphQLConfig.wsUrl ?? graphQLConfig.wsEndpoint;\n configureRelayEnvironment({\n httpUrl,\n wsUrl,\n getDataId: graphQLConfig.getDataId,\n logEvents: graphQLConfig.logEvents,\n getAuthHeaders: graphQLConfig.getAuthHeaders,\n });\n }, [\n graphQLConfig.endpoint,\n graphQLConfig.getAuthHeaders,\n graphQLConfig.getDataId,\n graphQLConfig.httpUrl,\n graphQLConfig.logEvents,\n graphQLConfig.wsEndpoint,\n graphQLConfig.wsUrl,\n ]);\n\n const mergedResources = useMemo(() => {\n return withBackofficeReactI18nResources(props.i18n?.resources ?? {});\n }, [props.i18n?.resources]);\n\n const i18nInstance = useMemo(() => {\n return props.i18n?.instance ?? createInstance();\n }, [props.i18n?.instance]);\n const [isI18nReady, setIsI18nReady] = useState(i18nInstance.isInitialized);\n\n useEffect(() => {\n let isCurrent = true;\n const markI18nReady = (): void => {\n if (isCurrent) {\n setIsI18nReady(true);\n }\n };\n\n i18nInstance.on('initialized', markI18nReady);\n if (i18nInstance.isInitialized) {\n markI18nReady();\n return () => {\n isCurrent = false;\n i18nInstance.off('initialized', markI18nReady);\n };\n }\n\n const readyCheck = globalThis.setTimeout(() => {\n if (i18nInstance.isInitialized) {\n markI18nReady();\n }\n }, 0);\n\n const initOptions = props.i18n?.initOptions ?? {};\n const defaultNs = initOptions.defaultNS ?? 'translations';\n const ns = initOptions.ns ?? ['backofficeReact', 'translations', 'ui'];\n createI18nInstance({\n resources: mergedResources,\n lng: props.i18n?.lng,\n fallbackLng: props.i18n?.fallbackLng,\n initOptions: {\n ...initOptions,\n defaultNS: defaultNs,\n ns,\n react: {\n useSuspense: false,\n ...initOptions.react,\n },\n },\n instance: i18nInstance,\n useLanguageDetector: props.i18n?.useLanguageDetector,\n detection: props.i18n?.detection,\n })\n .then(markI18nReady)\n .catch((error: unknown) => {\n markI18nReady();\n // eslint-disable-next-line no-console\n console.error(error);\n });\n\n return () => {\n isCurrent = false;\n globalThis.clearTimeout(readyCheck);\n i18nInstance.off('initialized', markI18nReady);\n };\n }, [\n i18nInstance,\n mergedResources,\n props.i18n?.initOptions,\n props.i18n?.detection,\n props.i18n?.fallbackLng,\n props.i18n?.lng,\n props.i18n?.useLanguageDetector,\n ]);\n\n const configValue = useMemo(() => {\n return {\n basePath,\n entities: entityManifest,\n entityManifest,\n entityRegistry,\n filterColumnAliases: props.filterColumnAliases,\n sidebar: props.sidebar,\n dashboard: props.dashboard,\n auth: props.auth,\n graphql: props.graphql,\n };\n }, [\n basePath,\n props.auth,\n props.dashboard,\n entityManifest,\n entityRegistry,\n props.filterColumnAliases,\n props.graphql,\n props.sidebar,\n ]);\n\n const routes = useMemo(() => {\n return createBackofficeRoutes({\n basePath,\n entityManifest,\n entityRegistry,\n sidebar: props.sidebar,\n auth: props.auth,\n dashboard: props.dashboard,\n toolsOperationPage: props.toolsOperationPage,\n });\n }, [\n basePath,\n entityManifest,\n entityRegistry,\n props.auth,\n props.dashboard,\n props.toolsOperationPage,\n props.sidebar,\n ]);\n\n let contentNode = <BackofficeStaticRouteFallback label=\"Loading...\" />;\n if (isI18nReady) {\n contentNode = (\n <ThemeProvider>\n <RelayProvider>\n <BackofficeConfigProvider value={configValue}>\n {props.overlay}\n <RouterShell\n routes={routes}\n instrumentations={props.instrumentations}\n />\n </BackofficeConfigProvider>\n </RelayProvider>\n </ThemeProvider>\n );\n }\n\n return (\n <StrictMode>\n <I18nextProvider i18n={i18nInstance}>{contentNode}</I18nextProvider>\n </StrictMode>\n );\n};\n\nexport default BackofficeProvider;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmCA,IAAM,KAAyB,MACzB,EAAM,MAAM,KAAK,MAAM,MAAU,MAC5B,MAEJ,EAAM,WAAW,IAAI,GAGtB,EAAM,SAAS,IAAI,GACd,EAAM,MAAM,GAAG,GAAG,GAEpB,IALE,IAAI,KAQT,KAAmB,GAAkB,MAA0B;CACnE,IAAM,IAAiB,EAAsB,EAAM,EAC7C,IAAqB,EAAsB,EAAS;CAa1D,OAZI,MAAuB,OAIzB,MAAmB,KACnB,EAAe,WAAW,GAAG,EAAmB,GAAG,GAE5C,IAEL,MAAmB,MACd,IAEF,GAAG,IAAqB;GAG3B,KACJ,GACA,MAEO,OAAO,YACZ,OAAO,QAAQ,EAAS,CAAC,KAAK,CAAC,GAAU,OAChC,CACL,GACA;CACE,GAAG;CACH,QAAQ;EACN,MAAM,EAAgB,GAAU,EAAK,OAAO,KAAK;EACjD,SAAS,MACA,EAAgB,GAAU,EAAK,OAAO,OAAO,EAAG,CAAC;EAE1D,aAAa,GAAY,MAChB,EACL,GACA,EAAK,OAAO,WAAW,GAAI,EAAO,CACnC;EAEJ;CACF,CACF,CACD,CACH,EAaG,KAA+B,EACnC,WACA,YACA,0BAKqC;CACrC,IAAM,CAAC,GAAQ,KAAa,EAA0C,KAAK;CAc3E,OAZA,QAAgB;EACd,IAAM,IAAa,EAAa,GAAQ;GACtC;GACA;GACD,CAAC;EAGF,OAFA,EAAU,EAAW,QAER;GACX,EAAW,SAAS;;IAErB;EAAC;EAAS;EAAkB;EAAO,CAAC,EAEhC;GAGH,KAAe,EACnB,WACA,0BACmC;CACnC,IAAM,IAAmB,GAAqB,EAMxC,IAAS,EAA4B;EACzC;EACA,SANoB,SACb,EAAE,qBAAkB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AA0B,OAAO;YAAjC,CACG,EAAM,SACP,kBAAC,GAAD;GACU;GACR,kBAAkB,EAAM;GACxB,CAAA,CACuB;KACb,CAAA,EACF,CAAA,GAKlB,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD;EAAiB,MAAM;YAAe;EAA8B,CAAA,EACzD,CAAA"}
|
|
1
|
+
{"version":3,"file":"BackofficeProvider.js","names":[],"sources":["../../../src/provider/BackofficeProvider.tsx"],"sourcesContent":["import {\n StrictMode,\n useEffect,\n useMemo,\n useState,\n type ContextType,\n type JSX,\n} from 'react';\nimport { createInstance } from 'i18next';\nimport { I18nextProvider } from 'react-i18next';\nimport createRouter from '@plumile/router/routing/createRouter.js';\nimport RouterRenderer from '@plumile/router/routing/RouterRenderer.js';\nimport RoutingContext from '@plumile/router/routing/RoutingContext.js';\nimport { ThemeProvider } from '@plumile/ui/theme/ThemeProvider.js';\n\nimport { type BackofficeEntityManifestMap } from '@plumile/backoffice-core/types.js';\n\nimport { createI18nInstance } from '../i18n/createI18nInstance.js';\nimport { withBackofficeReactI18nResources } from '../i18n/resources.js';\nimport { RelayProvider } from '../relay/RelayProvider.js';\nimport { useRelayEnvironment } from '../relay/useRelayEnvironment.js';\nimport { configureRelayEnvironment } from '../relay/environment.js';\nimport { BackofficeConfigProvider } from './BackofficeConfigContext.js';\nimport {\n createBackofficeRoutes,\n type BackofficeRouterContext,\n} from '../router/createBackofficeRoutes.js';\nimport type { BackofficeProviderProps } from './types.js';\nimport { validateBackofficeDashboardRegistrations } from './dashboardRegistrations.js';\nimport {\n BackofficeRouteFallback,\n BackofficeStaticRouteFallback,\n} from '../components/backoffice/routing/BackofficeRouteFallback.js';\nimport { BackofficeRoutePendingBar } from '../components/backoffice/routing/BackofficeRoutePendingBar.js';\nimport { createBackofficeEntityRegistry } from './entityRegistry.js';\n\nconst normalizeAbsolutePath = (value: string): string => {\n if (value.trim() === '' || value === '/') {\n return '/';\n }\n if (!value.startsWith('/')) {\n return `/${value}`;\n }\n if (value.endsWith('/')) {\n return value.slice(0, -1);\n }\n return value;\n};\n\nconst prefixRoutePath = (basePath: string, value: string): string => {\n const normalizedPath = normalizeAbsolutePath(value);\n const normalizedBasePath = normalizeAbsolutePath(basePath);\n if (normalizedBasePath === '/') {\n return normalizedPath;\n }\n if (\n normalizedPath === normalizedBasePath ||\n normalizedPath.startsWith(`${normalizedBasePath}/`)\n ) {\n return normalizedPath;\n }\n if (normalizedPath === '/') {\n return normalizedBasePath;\n }\n return `${normalizedBasePath}${normalizedPath}`;\n};\n\nconst resolveEntityManifest = (\n manifest: BackofficeEntityManifestMap,\n basePath: string,\n): BackofficeEntityManifestMap => {\n return Object.fromEntries(\n Object.entries(manifest).map(([entityId, item]) => {\n return [\n entityId,\n {\n ...item,\n routes: {\n list: prefixRoutePath(basePath, item.routes.list),\n detail: (id: string) => {\n return prefixRoutePath(basePath, item.routes.detail(id));\n },\n detailPage: (id: string, pageId: string) => {\n return prefixRoutePath(\n basePath,\n item.routes.detailPage(id, pageId),\n );\n },\n },\n } satisfies BackofficeEntityManifestMap[string],\n ] as const;\n }),\n );\n};\n\ntype RouterShellProps = {\n routes: ReturnType<typeof createBackofficeRoutes>;\n instrumentations?: BackofficeProviderProps['instrumentations'];\n};\n\ntype BackofficeRouterInstance = {\n context: NonNullable<ContextType<typeof RoutingContext>>;\n cleanup: () => void;\n};\n\nconst useBackofficeRouterInstance = ({\n routes,\n context,\n instrumentations,\n}: {\n routes: ReturnType<typeof createBackofficeRoutes>;\n context: BackofficeRouterContext;\n instrumentations?: BackofficeProviderProps['instrumentations'];\n}): BackofficeRouterInstance | null => {\n const [router, setRouter] = useState<BackofficeRouterInstance | null>(null);\n\n useEffect(() => {\n const nextRouter = createRouter(routes, {\n context,\n instrumentations,\n });\n setRouter(nextRouter);\n\n return () => {\n nextRouter.cleanup();\n };\n }, [context, instrumentations, routes]);\n\n return router;\n};\n\nconst RouterShell = ({\n routes,\n instrumentations,\n}: RouterShellProps): JSX.Element => {\n const relayEnvironment = useRelayEnvironment();\n\n const routerContext = useMemo(() => {\n return { relayEnvironment };\n }, [relayEnvironment]);\n\n const router = useBackofficeRouterInstance({\n routes,\n context: routerContext,\n instrumentations,\n });\n\n if (router == null) {\n return <BackofficeRouteFallback />;\n }\n\n return (\n <RoutingContext.Provider value={router.context}>\n <RouterRenderer\n enableTransition\n fallback={<BackofficeRouteFallback />}\n pending={<BackofficeRoutePendingBar />}\n />\n </RoutingContext.Provider>\n );\n};\n\nexport const BackofficeProvider = (\n props: BackofficeProviderProps,\n): JSX.Element => {\n const basePath = normalizeAbsolutePath(props.basePath ?? '/');\n\n const entityManifest = useMemo(() => {\n return resolveEntityManifest(props.entityManifest, basePath);\n }, [basePath, props.entityManifest]);\n const entityRegistry = useMemo(() => {\n return createBackofficeEntityRegistry(entityManifest, { basePath });\n }, [basePath, entityManifest]);\n\n const graphQLConfig = props.graphql;\n const dashboards = useMemo(() => {\n return validateBackofficeDashboardRegistrations(props.dashboards);\n }, [props.dashboards]);\n\n useEffect(() => {\n const httpUrl = graphQLConfig.httpUrl ?? graphQLConfig.endpoint;\n const wsUrl = graphQLConfig.wsUrl ?? graphQLConfig.wsEndpoint;\n configureRelayEnvironment({\n httpUrl,\n wsUrl,\n getDataId: graphQLConfig.getDataId,\n logEvents: graphQLConfig.logEvents,\n getAuthHeaders: graphQLConfig.getAuthHeaders,\n });\n }, [\n graphQLConfig.endpoint,\n graphQLConfig.getAuthHeaders,\n graphQLConfig.getDataId,\n graphQLConfig.httpUrl,\n graphQLConfig.logEvents,\n graphQLConfig.wsEndpoint,\n graphQLConfig.wsUrl,\n ]);\n\n const mergedResources = useMemo(() => {\n return withBackofficeReactI18nResources(props.i18n?.resources ?? {});\n }, [props.i18n?.resources]);\n\n const i18nInstance = useMemo(() => {\n return props.i18n?.instance ?? createInstance();\n }, [props.i18n?.instance]);\n const [isI18nReady, setIsI18nReady] = useState(i18nInstance.isInitialized);\n\n useEffect(() => {\n let isCurrent = true;\n const markI18nReady = (): void => {\n if (isCurrent) {\n setIsI18nReady(true);\n }\n };\n\n i18nInstance.on('initialized', markI18nReady);\n if (i18nInstance.isInitialized) {\n markI18nReady();\n return () => {\n isCurrent = false;\n i18nInstance.off('initialized', markI18nReady);\n };\n }\n\n const readyCheck = globalThis.setTimeout(() => {\n if (i18nInstance.isInitialized) {\n markI18nReady();\n }\n }, 0);\n\n const initOptions = props.i18n?.initOptions ?? {};\n const defaultNs = initOptions.defaultNS ?? 'translations';\n const ns = initOptions.ns ?? ['backofficeReact', 'translations', 'ui'];\n createI18nInstance({\n resources: mergedResources,\n lng: props.i18n?.lng,\n fallbackLng: props.i18n?.fallbackLng,\n initOptions: {\n ...initOptions,\n defaultNS: defaultNs,\n ns,\n react: {\n useSuspense: false,\n ...initOptions.react,\n },\n },\n instance: i18nInstance,\n useLanguageDetector: props.i18n?.useLanguageDetector,\n detection: props.i18n?.detection,\n })\n .then(markI18nReady)\n .catch((error: unknown) => {\n markI18nReady();\n // eslint-disable-next-line no-console\n console.error(error);\n });\n\n return () => {\n isCurrent = false;\n globalThis.clearTimeout(readyCheck);\n i18nInstance.off('initialized', markI18nReady);\n };\n }, [\n i18nInstance,\n mergedResources,\n props.i18n?.initOptions,\n props.i18n?.detection,\n props.i18n?.fallbackLng,\n props.i18n?.lng,\n props.i18n?.useLanguageDetector,\n ]);\n\n const configValue = useMemo(() => {\n return {\n basePath,\n entities: entityManifest,\n entityManifest,\n entityRegistry,\n filterColumnAliases: props.filterColumnAliases,\n sidebar: props.sidebar,\n dashboard: props.dashboard,\n dashboards,\n auth: props.auth,\n graphql: props.graphql,\n };\n }, [\n basePath,\n props.auth,\n props.dashboard,\n dashboards,\n entityManifest,\n entityRegistry,\n props.filterColumnAliases,\n props.graphql,\n props.sidebar,\n ]);\n\n const routes = useMemo(() => {\n return createBackofficeRoutes({\n basePath,\n entityManifest,\n entityRegistry,\n sidebar: props.sidebar,\n auth: props.auth,\n dashboard: props.dashboard,\n dashboards,\n toolsOperationPage: props.toolsOperationPage,\n });\n }, [\n basePath,\n entityManifest,\n entityRegistry,\n props.auth,\n props.dashboard,\n dashboards,\n props.toolsOperationPage,\n props.sidebar,\n ]);\n\n let contentNode = <BackofficeStaticRouteFallback label=\"Loading...\" />;\n if (isI18nReady) {\n contentNode = (\n <ThemeProvider>\n <RelayProvider>\n <BackofficeConfigProvider value={configValue}>\n {props.overlay}\n <RouterShell\n routes={routes}\n instrumentations={props.instrumentations}\n />\n </BackofficeConfigProvider>\n </RelayProvider>\n </ThemeProvider>\n );\n }\n\n return (\n <StrictMode>\n <I18nextProvider i18n={i18nInstance}>{contentNode}</I18nextProvider>\n </StrictMode>\n );\n};\n\nexport default BackofficeProvider;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoCA,IAAM,KAAyB,MACzB,EAAM,MAAM,KAAK,MAAM,MAAU,MAC5B,MAEJ,EAAM,WAAW,IAAI,GAGtB,EAAM,SAAS,IAAI,GACd,EAAM,MAAM,GAAG,GAAG,GAEpB,IALE,IAAI,KAQT,KAAmB,GAAkB,MAA0B;CACnE,IAAM,IAAiB,EAAsB,EAAM,EAC7C,IAAqB,EAAsB,EAAS;CAa1D,OAZI,MAAuB,OAIzB,MAAmB,KACnB,EAAe,WAAW,GAAG,EAAmB,GAAG,GAE5C,IAEL,MAAmB,MACd,IAEF,GAAG,IAAqB;GAG3B,KACJ,GACA,MAEO,OAAO,YACZ,OAAO,QAAQ,EAAS,CAAC,KAAK,CAAC,GAAU,OAChC,CACL,GACA;CACE,GAAG;CACH,QAAQ;EACN,MAAM,EAAgB,GAAU,EAAK,OAAO,KAAK;EACjD,SAAS,MACA,EAAgB,GAAU,EAAK,OAAO,OAAO,EAAG,CAAC;EAE1D,aAAa,GAAY,MAChB,EACL,GACA,EAAK,OAAO,WAAW,GAAI,EAAO,CACnC;EAEJ;CACF,CACF,CACD,CACH,EAaG,KAA+B,EACnC,WACA,YACA,0BAKqC;CACrC,IAAM,CAAC,GAAQ,KAAa,EAA0C,KAAK;CAc3E,OAZ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C,EAEI,IAAS,QACN,EAAuB;EAC5B;EACA;EACA;EACA,SAAS,EAAM;EACf,MAAM,EAAM;EACZ,WAAW,EAAM;EACjB;EACA,oBAAoB,EAAM;EAC3B,CAAC,EACD;EACD;EACA;EACA;EACA,EAAM;EACN,EAAM;EACN;EACA,EAAM;EACN,EAAM;EACP,CAAC,EAEE,IAAc,kBAAC,GAAD,EAA+B,OAAM,cAAe,CAAA;CAiBtE,OAhBI,MACF,IACE,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD;EAA0B,OAAO;YAAjC,CACG,EAAM,SACP,kBAAC,GAAD;GACU;GACR,kBAAkB,EAAM;GACxB,CAAA,CACuB;KACb,CAAA,EACF,CAAA,GAKlB,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD;EAAiB,MAAM;YAAe;EAA8B,CAAA,EACzD,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/provider/dashboardRegistrations.ts
|
|
2
|
+
var e = /^[a-z0-9][a-z0-9-]*$/, t = (t) => {
|
|
3
|
+
if (t == null) return [];
|
|
4
|
+
let n = /* @__PURE__ */ new Set();
|
|
5
|
+
return t.forEach((t) => {
|
|
6
|
+
let r = t.id.trim();
|
|
7
|
+
if (r === "") throw Error("Backoffice dashboard id must not be empty.");
|
|
8
|
+
if (r === "dashboard") throw Error("Backoffice dashboard id \"dashboard\" is reserved for the root dashboard.");
|
|
9
|
+
if (!e.test(r)) throw Error(`Invalid backoffice dashboard id "${t.id}". Use a stable URL segment matching ${e.source}.`);
|
|
10
|
+
if (n.has(r)) throw Error(`Duplicate backoffice dashboard id "${r}".`);
|
|
11
|
+
n.add(r);
|
|
12
|
+
}), t;
|
|
13
|
+
}, n = (e, t) => t == null || t === "" || t === "dashboard" ? null : e.find((e) => e.id === t) ?? null;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { n as findBackofficeDashboardRegistration, t as validateBackofficeDashboardRegistrations };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=dashboardRegistrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dashboardRegistrations.js","names":[],"sources":["../../../src/provider/dashboardRegistrations.ts"],"sourcesContent":["import type { BackofficeDashboardRegistration } from './types.js';\n\nconst DASHBOARD_ID_PATTERN = /^[a-z0-9][a-z0-9-]*$/;\n\nexport const validateBackofficeDashboardRegistrations = (\n dashboards: readonly BackofficeDashboardRegistration[] | undefined,\n): readonly BackofficeDashboardRegistration[] => {\n if (dashboards == null) {\n return [];\n }\n\n const seen = new Set<string>();\n dashboards.forEach((dashboard) => {\n const id = dashboard.id.trim();\n if (id === '') {\n throw new Error('Backoffice dashboard id must not be empty.');\n }\n if (id === 'dashboard') {\n throw new Error(\n 'Backoffice dashboard id \"dashboard\" is reserved for the root dashboard.',\n );\n }\n if (!DASHBOARD_ID_PATTERN.test(id)) {\n throw new Error(\n `Invalid backoffice dashboard id \"${dashboard.id}\". Use a stable URL segment matching ${DASHBOARD_ID_PATTERN.source}.`,\n );\n }\n if (seen.has(id)) {\n throw new Error(`Duplicate backoffice dashboard id \"${id}\".`);\n }\n seen.add(id);\n });\n\n return dashboards;\n};\n\nexport const findBackofficeDashboardRegistration = (\n dashboards: readonly BackofficeDashboardRegistration[],\n id: string | undefined,\n): BackofficeDashboardRegistration | null => {\n if (id == null || id === '' || id === 'dashboard') {\n return null;\n }\n return (\n dashboards.find((dashboard) => {\n return dashboard.id === id;\n }) ?? null\n );\n};\n"],"mappings":";AAEA,IAAM,IAAuB,wBAEhB,KACX,MAC+C;CAC/C,IAAI,KAAc,MAChB,OAAO,EAAE;CAGX,IAAM,oBAAO,IAAI,KAAa;CAsB9B,OArBA,EAAW,SAAS,MAAc;EAChC,IAAM,IAAK,EAAU,GAAG,MAAM;EAC9B,IAAI,MAAO,IACT,MAAU,MAAM,6CAA6C;EAE/D,IAAI,MAAO,aACT,MAAU,MACR,4EACD;EAEH,IAAI,CAAC,EAAqB,KAAK,EAAG,EAChC,MAAU,MACR,oCAAoC,EAAU,GAAG,uCAAuC,EAAqB,OAAO,GACrH;EAEH,IAAI,EAAK,IAAI,EAAG,EACd,MAAU,MAAM,sCAAsC,EAAG,IAAI;EAE/D,EAAK,IAAI,EAAG;GACZ,EAEK;GAGI,KACX,GACA,MAEI,KAAM,QAAQ,MAAO,MAAM,MAAO,cAC7B,OAGP,EAAW,MAAM,MACR,EAAU,OAAO,EACxB,IAAI"}
|