@dr.pogodin/react-utils 1.53.0 → 1.54.0
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/build/development/client/index.js +2 -0
- package/build/development/client/index.js.map +1 -1
- package/build/development/index.js +2 -2
- package/build/development/index.js.map +1 -1
- package/build/development/shared/components/Button/index.js +149 -71
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +77 -24
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +133 -54
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +168 -45
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +23 -13
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +203 -87
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +16 -7
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +77 -15
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +169 -68
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +51 -13
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +73 -34
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +19 -19
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +66 -23
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +104 -56
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +173 -75
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +86 -36
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/utils/globalState.js +2 -2
- package/build/development/shared/utils/globalState.js.map +1 -1
- package/build/development/shared/utils/index.js +1 -1
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +125 -55
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +55 -20
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/production/client/index.js +2 -2
- package/build/production/client/index.js.map +1 -1
- package/build/production/index.js +1 -1
- package/build/production/index.js.map +1 -1
- package/build/production/shared/components/Button/index.js +2 -13
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +2 -15
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +2 -11
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js +2 -4
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +2 -10
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js +1 -4
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js +2 -2
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js +1 -21
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js +2 -2
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js +2 -7
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js +3 -3
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js +2 -5
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +1 -6
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -7
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/Switch/index.js +1 -1
- package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/production/shared/utils/globalState.js +1 -1
- package/build/production/shared/utils/globalState.js.map +1 -1
- package/build/production/shared/utils/index.js +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +3 -10
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js +2 -2
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/types-code/index.d.ts +2 -2
- package/build/types-code/shared/utils/globalState.d.ts +2 -2
- package/build/types-code/shared/utils/index.d.ts +1 -1
- package/build/types-code/shared/utils/splitComponent.d.ts +1 -0
- package/build/web/client/index.js +2 -2
- package/build/web/client/index.js.map +1 -1
- package/build/web/index.js +1 -1
- package/build/web/index.js.map +1 -1
- package/build/web/shared/components/Button/index.js +2 -13
- package/build/web/shared/components/Button/index.js.map +1 -1
- package/build/web/shared/components/Checkbox/index.js +1 -1
- package/build/web/shared/components/Checkbox/index.js.map +1 -1
- package/build/web/shared/components/GenericLink/index.js +2 -15
- package/build/web/shared/components/GenericLink/index.js.map +1 -1
- package/build/web/shared/components/Input/index.js +2 -11
- package/build/web/shared/components/Input/index.js.map +1 -1
- package/build/web/shared/components/Link.js +2 -4
- package/build/web/shared/components/Link.js.map +1 -1
- package/build/web/shared/components/Modal/index.js +2 -10
- package/build/web/shared/components/Modal/index.js.map +1 -1
- package/build/web/shared/components/NavLink.js +1 -4
- package/build/web/shared/components/NavLink.js.map +1 -1
- package/build/web/shared/components/PageLayout/index.js +2 -2
- package/build/web/shared/components/PageLayout/index.js.map +1 -1
- package/build/web/shared/components/TextArea/index.js +1 -21
- package/build/web/shared/components/TextArea/index.js.map +1 -1
- package/build/web/shared/components/Throbber/index.js +2 -2
- package/build/web/shared/components/Throbber/index.js.map +1 -1
- package/build/web/shared/components/WithTooltip/Tooltip.js +2 -7
- package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/web/shared/components/WithTooltip/index.js +3 -3
- package/build/web/shared/components/WithTooltip/index.js.map +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js +2 -5
- package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +1 -6
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js +1 -7
- package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/Switch/index.js +1 -1
- package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/web/shared/utils/globalState.js +1 -1
- package/build/web/shared/utils/globalState.js.map +1 -1
- package/build/web/shared/utils/index.js +1 -1
- package/build/web/shared/utils/index.js.map +1 -1
- package/build/web/shared/utils/splitComponent.js +3 -10
- package/build/web/shared/utils/splitComponent.js.map +1 -1
- package/build/web/shared/utils/time.js +2 -2
- package/build/web/shared/utils/time.js.map +1 -1
- package/config/babel/webpack.d.ts +1 -0
- package/config/babel/webpack.js +10 -12
- package/package.json +10 -8
- package/tsconfig.json +1 -1
- package/tsconfig.types.json +1 -1
|
@@ -11,21 +11,17 @@ import "core-js/modules/es.set.is-disjoint-from.v2.js";
|
|
|
11
11
|
import "core-js/modules/es.set.is-subset-of.v2.js";
|
|
12
12
|
import "core-js/modules/es.set.is-superset-of.v2.js";
|
|
13
13
|
import "core-js/modules/es.set.symmetric-difference.v2.js";
|
|
14
|
-
import "core-js/modules/es.set.union.v2.js";
|
|
14
|
+
import "core-js/modules/es.set.union.v2.js";
|
|
15
|
+
import { c as _c } from "react/compiler-runtime"; /* global document */
|
|
15
16
|
import { Suspense, lazy, useInsertionEffect } from "react";
|
|
16
17
|
import { Barrier } from "@dr.pogodin/js-utils";
|
|
17
|
-
import {
|
|
18
|
-
import { IS_CLIENT_SIDE, IS_SERVER_SIDE, getBuildInfo } from "./isomorphy/index.js";
|
|
18
|
+
import { useSsrContext } from "./globalState.js";
|
|
19
|
+
import { IS_CLIENT_SIDE, IS_SERVER_SIDE, assertClientSide, getBuildInfo } from "./isomorphy/index.js";
|
|
19
20
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
default: getInj
|
|
25
|
-
} = await import(/* webpackChunkName: "react-utils-client-side-code" */"../../client/getInj");
|
|
26
|
-
const inj = await getInj();
|
|
27
|
-
return inj.CHUNK_GROUPS ?? {};
|
|
28
|
-
})();
|
|
21
|
+
let clientChunkGroups;
|
|
22
|
+
export function setClientChunkGroups(groups) {
|
|
23
|
+
assertClientSide();
|
|
24
|
+
clientChunkGroups = groups;
|
|
29
25
|
}
|
|
30
26
|
const refCounts = {};
|
|
31
27
|
function getPublicPath() {
|
|
@@ -163,11 +159,6 @@ export default function splitComponent({
|
|
|
163
159
|
// throw Error(`Repeated splitComponent() call for the chunk "${chunkName}"`);
|
|
164
160
|
// } else usedChunkNames.add(chunkName);
|
|
165
161
|
const LazyComponent = /*#__PURE__*/lazy(async () => {
|
|
166
|
-
const clientChunkGroups = await getClientChunkGroups(); // On the client side we can check right away if the chunk name is known.
|
|
167
|
-
if (IS_CLIENT_SIDE) {
|
|
168
|
-
if (!clientChunkGroups) throw Error("Internal error");
|
|
169
|
-
assertChunkName(chunkName, clientChunkGroups);
|
|
170
|
-
}
|
|
171
162
|
const resolved = await getComponent();
|
|
172
163
|
const Component = "default" in resolved ? resolved.default : resolved; // This pre-loads necessary stylesheets prior to the first mount of
|
|
173
164
|
// the component (the lazy load function is executed by React one at
|
|
@@ -176,51 +167,130 @@ export default function splitComponent({
|
|
|
176
167
|
if (!clientChunkGroups) throw Error("Internal error");
|
|
177
168
|
await bookStyleSheets(chunkName, clientChunkGroups, false);
|
|
178
169
|
}
|
|
179
|
-
const Wrapper =
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
170
|
+
const Wrapper = t0 => {
|
|
171
|
+
const $ = _c(12);
|
|
172
|
+
let children;
|
|
173
|
+
let chunkGroups;
|
|
174
|
+
let ref;
|
|
175
|
+
let rest;
|
|
176
|
+
if ($[0] !== t0) {
|
|
177
|
+
({
|
|
178
|
+
children,
|
|
188
179
|
chunkGroups,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
180
|
+
ref,
|
|
181
|
+
...rest
|
|
182
|
+
} = t0);
|
|
183
|
+
$[0] = t0;
|
|
184
|
+
$[1] = children;
|
|
185
|
+
$[2] = chunkGroups;
|
|
186
|
+
$[3] = ref;
|
|
187
|
+
$[4] = rest;
|
|
188
|
+
} else {
|
|
189
|
+
children = $[1];
|
|
190
|
+
chunkGroups = $[2];
|
|
191
|
+
ref = $[3];
|
|
192
|
+
rest = $[4];
|
|
193
|
+
}
|
|
194
|
+
let t1;
|
|
195
|
+
let t2;
|
|
196
|
+
if ($[5] !== chunkGroups) {
|
|
197
|
+
t1 = () => {
|
|
198
|
+
if (!clientChunkGroups) {
|
|
199
|
+
throw Error("Internal error");
|
|
200
|
+
}
|
|
201
|
+
bookStyleSheets(chunkName, chunkGroups, true);
|
|
202
|
+
return () => {
|
|
203
|
+
freeStyleSheets(chunkName, chunkGroups);
|
|
204
|
+
};
|
|
200
205
|
};
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
t2 = [chunkGroups];
|
|
207
|
+
$[5] = chunkGroups;
|
|
208
|
+
$[6] = t1;
|
|
209
|
+
$[7] = t2;
|
|
210
|
+
} else {
|
|
211
|
+
t1 = $[6];
|
|
212
|
+
t2 = $[7];
|
|
213
|
+
}
|
|
214
|
+
useInsertionEffect(t1, t2);
|
|
215
|
+
const t3 = rest;
|
|
216
|
+
let t4;
|
|
217
|
+
if ($[8] !== children || $[9] !== ref || $[10] !== t3) {
|
|
218
|
+
t4 = /*#__PURE__*/_jsx(Component, {
|
|
219
|
+
...t3,
|
|
220
|
+
ref: ref,
|
|
221
|
+
children: children
|
|
222
|
+
});
|
|
223
|
+
$[8] = children;
|
|
224
|
+
$[9] = ref;
|
|
225
|
+
$[10] = t3;
|
|
226
|
+
$[11] = t4;
|
|
227
|
+
} else {
|
|
228
|
+
t4 = $[11];
|
|
229
|
+
}
|
|
230
|
+
return t4;
|
|
208
231
|
};
|
|
209
232
|
return {
|
|
210
233
|
default: Wrapper
|
|
211
234
|
};
|
|
212
235
|
});
|
|
213
|
-
const CodeSplit =
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
236
|
+
const CodeSplit = t0 => {
|
|
237
|
+
const $ = _c(7);
|
|
238
|
+
let children;
|
|
239
|
+
let rest;
|
|
240
|
+
if ($[0] !== t0) {
|
|
241
|
+
({
|
|
242
|
+
children,
|
|
243
|
+
...rest
|
|
244
|
+
} = t0);
|
|
245
|
+
$[0] = t0;
|
|
246
|
+
$[1] = children;
|
|
247
|
+
$[2] = rest;
|
|
248
|
+
} else {
|
|
249
|
+
children = $[1];
|
|
250
|
+
rest = $[2];
|
|
251
|
+
}
|
|
252
|
+
let chunkGroups;
|
|
253
|
+
const ssrContext = useSsrContext(false);
|
|
254
|
+
if (IS_SERVER_SIDE) {
|
|
255
|
+
if (!ssrContext) {
|
|
256
|
+
throw Error("Internal error");
|
|
257
|
+
}
|
|
258
|
+
({
|
|
259
|
+
chunkGroups
|
|
260
|
+
} = ssrContext);
|
|
261
|
+
const {
|
|
262
|
+
chunks
|
|
263
|
+
} = ssrContext;
|
|
264
|
+
if (!chunks.includes(chunkName)) {
|
|
265
|
+
chunks.push(chunkName);
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
if (!clientChunkGroups) {
|
|
269
|
+
throw Error("Internal error");
|
|
270
|
+
}
|
|
271
|
+
chunkGroups = clientChunkGroups;
|
|
272
|
+
}
|
|
273
|
+
assertChunkName(chunkName, chunkGroups);
|
|
274
|
+
const t1 = rest;
|
|
275
|
+
let t2;
|
|
276
|
+
if ($[3] !== children || $[4] !== chunkGroups || $[5] !== t1) {
|
|
277
|
+
t2 = /*#__PURE__*/_jsx(Suspense, {
|
|
278
|
+
fallback: placeholder,
|
|
279
|
+
children: /*#__PURE__*/_jsx(LazyComponent, {
|
|
280
|
+
...t1,
|
|
281
|
+
chunkGroups: chunkGroups,
|
|
282
|
+
children: children
|
|
283
|
+
})
|
|
284
|
+
});
|
|
285
|
+
$[3] = children;
|
|
286
|
+
$[4] = chunkGroups;
|
|
287
|
+
$[5] = t1;
|
|
288
|
+
$[6] = t2;
|
|
289
|
+
} else {
|
|
290
|
+
t2 = $[6];
|
|
291
|
+
}
|
|
292
|
+
return t2;
|
|
293
|
+
};
|
|
224
294
|
return CodeSplit;
|
|
225
295
|
}
|
|
226
296
|
//# sourceMappingURL=splitComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splitComponent.js","names":["Suspense","lazy","useInsertionEffect","Barrier","getSsrContext","IS_CLIENT_SIDE","IS_SERVER_SIDE","getBuildInfo","jsx","_jsx","getClientChunkGroups","undefined","default","getInj","inj","CHUNK_GROUPS","refCounts","getPublicPath","publicPath","bookStyleSheet","name","loadedSheets","refCount","res","path","fullPath","document","location","origin","has","link","querySelector","createElement","setAttribute","head","appendChild","addEventListener","Error","resolve","current","getLoadedStyleSheets","Set","styleSheets","href","add","assertChunkName","chunkName","chunkGroups","bookStyleSheets","promises","assets","Promise","asset","endsWith","promise","push","length","allSettled","then","freeStyleSheets","pathRefCount","remove","splitComponent","getComponent","placeholder","LazyComponent","clientChunkGroups","resolved","Component","Wrapper","children","ref","rest","chunks","includes","CodeSplit","fallback"],"sources":["../../../../src/shared/utils/splitComponent.tsx"],"sourcesContent":["/* global document */\n\nimport {\n type ComponentType,\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n Suspense,\n lazy,\n useInsertionEffect,\n} from 'react';\n\nimport { Barrier } from '@dr.pogodin/js-utils';\n\nimport { type ChunkGroupsT, getSsrContext } from './globalState';\n\nimport {\n IS_CLIENT_SIDE,\n IS_SERVER_SIDE,\n getBuildInfo,\n} from './isomorphy';\n\nfunction getClientChunkGroups(): Promise<ChunkGroupsT> | undefined {\n if (!IS_CLIENT_SIDE) return undefined;\n\n return (async () => {\n const { default: getInj } = await import(/* webpackChunkName: \"react-utils-client-side-code\" */ '../../client/getInj');\n\n const inj = await getInj();\n return inj.CHUNK_GROUPS ?? {};\n })();\n}\n\nconst refCounts: Record<string, number> = {};\n\nfunction getPublicPath() {\n return getBuildInfo().publicPath;\n}\n\n/**\n * Client-side only! Ensures the specified CSS stylesheet is loaded into\n * the document; loads if it is missing; and does simple reference counting\n * to facilitate future clean-up.\n * @param name\n * @param loadedSheets\n * @param refCount\n * @return\n */\nfunction bookStyleSheet(\n name: string,\n loadedSheets: Set<string>,\n refCount: boolean,\n): Promise<void> | undefined {\n let res: Barrier<void> | undefined;\n const path = `${getPublicPath()}/${name}`;\n const fullPath = `${document.location.origin}${path}`;\n\n if (!loadedSheets.has(fullPath)) {\n let link = document.querySelector(`link[href=\"${path}\"]`);\n\n if (!link) {\n link = document.createElement('link');\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('href', path);\n document.head.appendChild(link);\n }\n\n res = new Barrier<void>();\n link.addEventListener('load', () => {\n if (!res) throw Error('Internal error');\n void res.resolve();\n });\n link.addEventListener('error', () => {\n if (!res) throw Error('Internal error');\n void res.resolve();\n });\n }\n\n if (refCount) {\n const current = refCounts[path] ?? 0;\n refCounts[path] = 1 + current;\n }\n\n return res;\n}\n\n/**\n * Generates the set of URLs for currently loaded, linked stylesheets.\n * @return\n */\nfunction getLoadedStyleSheets(): Set<string> {\n const res = new Set<string>();\n const { styleSheets } = document;\n for (const { href } of styleSheets) {\n if (href) res.add(href);\n }\n return res;\n}\n\nfunction assertChunkName(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n) {\n if (chunkGroups[chunkName]) return;\n throw Error(`Unknown chunk name \"${chunkName}\"`);\n}\n\n/**\n * Client-side only! Ensures all CSS stylesheets required for the specified\n * code chunk are loaded into the document; loads the missing ones; and does\n * simple reference counting to facilitate future clean-up.\n * @param chunkName Chunk name.\n * @param refCount\n * @return Resolves once all pending stylesheets, necessary for\n * the chunk, are either loaded, or failed to load.\n */\nexport async function bookStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n refCount: boolean,\n): Promise<void> {\n const promises = [];\n const assets = chunkGroups[chunkName];\n if (!assets) return Promise.resolve();\n\n const loadedSheets = getLoadedStyleSheets();\n\n for (const asset of assets) {\n if (asset.endsWith('.css')) {\n const promise = bookStyleSheet(asset, loadedSheets, refCount);\n if (promise) promises.push(promise);\n }\n }\n\n return promises.length\n ? Promise.allSettled(promises).then()\n : Promise.resolve();\n}\n\n/**\n * Client-side only! Frees from the document all CSS stylesheets that are\n * required by the specified chunk, and have reference counter equal to one\n * (for chunks with larger reference counter values, it just decrements\n * the reference counter).\n * @param {string} chunkName\n */\nexport function freeStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n): void {\n const assets = chunkGroups[chunkName];\n if (!assets) return;\n\n for (const asset of assets) {\n if (asset.endsWith('.css')) {\n const path = `${getPublicPath()}/${asset}`;\n\n const pathRefCount = refCounts[path];\n if (pathRefCount) {\n if (pathRefCount <= 1) {\n document.head.querySelector(`link[href=\"${path}\"]`)!.remove();\n delete refCounts[path];\n } else refCounts[path] = pathRefCount - 1;\n }\n }\n }\n}\n\n// Holds the set of chunk names already used for splitComponent() calls.\n// const usedChunkNames = new Set();\n\ntype ComponentOrModule<PropsT> = ComponentType<PropsT> | {\n default: ComponentType<PropsT>;\n};\n\ntype GenericComponentPropsT = {\n children?: ReactNode;\n ref?: RefObject<unknown>;\n\n // NOTE: This is necessary, as without it this type (with only optional\n // fields) will be conisdered as \"weak\" by TypeScript, and it will be\n // a error to assign to it any type that does not use \"children\", or \"ref\".\n [propName: string]: unknown;\n};\n\n/**\n * Given an async component retrieval function `getComponent()` it creates\n * a special \"code split\" component, which uses <Suspense> to asynchronously\n * load on demand the code required by `getComponent()`.\n * @param options\n * @param options.chunkName\n * @param {function} options.getComponent\n * @param {React.Element} [options.placeholder]\n * @return {React.ElementType}\n */\nexport default function splitComponent<\n ComponentPropsT extends GenericComponentPropsT,\n>({\n chunkName,\n getComponent,\n placeholder,\n}: {\n chunkName: string;\n getComponent: () => Promise<ComponentOrModule<ComponentPropsT>>;\n placeholder?: ReactNode;\n}): FunctionComponent<ComponentPropsT> {\n // TODO: For now I commented out this safeguard check, as I am not sure how\n // to easily make it work: it should not be triggered in HMR mode, but if I\n // add the code relying on import.meta, it fails in Jest environment, because\n // Jest does not support ES modules yet, and import.meta is not support in\n // CommonJS modules, and the \"babel-plugin-transform-import-meta\" plugin\n // we use to workaround this issue for import.meta.dirname, etc. does not\n // transform import.meta.webpackHot\n\n // The correct usage of splitComponent() assumes a single call per chunk.\n // if (usedChunkNames.has(chunkName)\n\n // When HMR happens splitComponent() ends up getting called again for some\n // chunks, thus we should not throw this error. Not sure, if we need to do\n // some additional handling in that case, or just not throwing is all we\n // need.\n // && !import.meta.webpackHot\n // ) {\n // throw Error(`Repeated splitComponent() call for the chunk \"${chunkName}\"`);\n // } else usedChunkNames.add(chunkName);\n\n const LazyComponent = lazy(async () => {\n const clientChunkGroups = await getClientChunkGroups();\n\n // On the client side we can check right away if the chunk name is known.\n if (IS_CLIENT_SIDE) {\n if (!clientChunkGroups) throw Error('Internal error');\n assertChunkName(chunkName, clientChunkGroups);\n }\n\n const resolved = await getComponent();\n const Component = 'default' in resolved ? resolved.default : resolved;\n\n // This pre-loads necessary stylesheets prior to the first mount of\n // the component (the lazy load function is executed by React one at\n // the frist mount).\n if (IS_CLIENT_SIDE) {\n if (!clientChunkGroups) throw Error('Internal error');\n await bookStyleSheets(chunkName, clientChunkGroups, false);\n }\n\n const Wrapper: FunctionComponent<ComponentPropsT> = ({\n children,\n ref,\n ...rest\n }) => {\n // On the server side we'll assert the chunk name here,\n // and also push it to the SSR chunks array.\n if (IS_SERVER_SIDE) {\n const { chunkGroups, chunks } = getSsrContext()!;\n assertChunkName(chunkName, chunkGroups);\n if (!chunks.includes(chunkName)) chunks.push(chunkName);\n }\n\n // This takes care about stylesheets management every time an instance of\n // this component is mounted / unmounted.\n useInsertionEffect(() => {\n if (!clientChunkGroups) throw Error('Internal error');\n void bookStyleSheets(chunkName, clientChunkGroups, true);\n return () => {\n freeStyleSheets(chunkName, clientChunkGroups);\n };\n }, []);\n\n return (\n <Component\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...(rest as unknown as ComponentPropsT)}\n ref={ref}\n >\n {children}\n </Component>\n );\n };\n\n return { default: Wrapper };\n });\n\n const CodeSplit: React.FunctionComponent<ComponentPropsT> = ({\n children,\n ...rest\n }: ComponentPropsT) => (\n <Suspense fallback={placeholder}>\n <LazyComponent\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...rest as Parameters<typeof LazyComponent>[0]}\n >\n {children}\n </LazyComponent>\n </Suspense>\n );\n\n return CodeSplit;\n}\n"],"mappings":";;;;;;;;;;;;;4CAAA;AAEA,SAKEA,QAAQ,EACRC,IAAI,EACJC,kBAAkB,QACb,OAAO;AAEd,SAASC,OAAO,QAAQ,sBAAsB;AAE9C,SAA4BC,aAAa;AAAA,SAGvCC,cAAc,EACdC,cAAc,EACdC,YAAY;A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;QACrD,KAAKW,eAAe,CAACF,SAAS,EAAEoB,iBAAiB,EAAE,IAAI,CAAC;QACxD,OAAO,MAAM;UACXP,eAAe,CAACb,SAAS,EAAEoB,iBAAiB,CAAC;QAC/C,CAAC;MACH,CAAC,EAAE,EAAE,CAAC;MAEN,oBACEzD,IAAA,CAAC2D,SACC;MAAA;QAAA,GACKI,IAAI;QACTD,GAAG,EAAEA,GAAI;QAAAD,QAAA,EAERA;MAAQ,CACA,CAAC;IAEhB,CAAC;IAED,OAAO;MAAE1D,OAAO,EAAEyD;IAAQ,CAAC;EAC7B,CAAC,CAAC;EAEF,MAAMM,SAAmD,GAAGA,CAAC;IAC3DL,QAAQ;IACR,GAAGE;EACY,CAAC,kBAChB/D,IAAA,CAACT,QAAQ;IAAC4E,QAAQ,EAAEZ,WAAY;IAAAM,QAAA,eAC9B7D,IAAA,CAACwD,aACC;IAAA;MAAA,GACIO,IAAI;MAAAF,QAAA,EAEPA;IAAQ,CACI;EAAC,CACR,CACX;EAED,OAAOK,SAAS;AAClB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"splitComponent.js","names":["Suspense","lazy","useInsertionEffect","Barrier","useSsrContext","IS_CLIENT_SIDE","IS_SERVER_SIDE","assertClientSide","getBuildInfo","jsx","_jsx","clientChunkGroups","setClientChunkGroups","groups","refCounts","getPublicPath","publicPath","bookStyleSheet","name","loadedSheets","refCount","res","path","fullPath","document","location","origin","has","link","querySelector","createElement","setAttribute","head","appendChild","addEventListener","Error","resolve","current","getLoadedStyleSheets","Set","styleSheets","href","add","assertChunkName","chunkName","chunkGroups","bookStyleSheets","promises","assets","Promise","asset","endsWith","promise","push","length","allSettled","then","freeStyleSheets","pathRefCount","remove","splitComponent","getComponent","placeholder","LazyComponent","resolved","Component","default","Wrapper","t0","$","_c","children","ref","rest","t1","t2","t3","t4","CodeSplit","ssrContext","chunks","includes","fallback"],"sources":["../../../../src/shared/utils/splitComponent.tsx"],"sourcesContent":["/* global document */\n\nimport {\n type ComponentType,\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n Suspense,\n lazy,\n useInsertionEffect,\n} from 'react';\n\nimport { Barrier } from '@dr.pogodin/js-utils';\n\nimport { type ChunkGroupsT, useSsrContext } from './globalState';\n\nimport {\n IS_CLIENT_SIDE,\n IS_SERVER_SIDE,\n assertClientSide,\n getBuildInfo,\n} from './isomorphy';\n\nlet clientChunkGroups: ChunkGroupsT | undefined;\n\nexport function setClientChunkGroups(groups: ChunkGroupsT): void {\n assertClientSide();\n clientChunkGroups = groups;\n}\n\nconst refCounts: Record<string, number> = {};\n\nfunction getPublicPath() {\n return getBuildInfo().publicPath;\n}\n\n/**\n * Client-side only! Ensures the specified CSS stylesheet is loaded into\n * the document; loads if it is missing; and does simple reference counting\n * to facilitate future clean-up.\n * @param name\n * @param loadedSheets\n * @param refCount\n * @return\n */\nfunction bookStyleSheet(\n name: string,\n loadedSheets: Set<string>,\n refCount: boolean,\n): Promise<void> | undefined {\n let res: Barrier<void> | undefined;\n const path = `${getPublicPath()}/${name}`;\n const fullPath = `${document.location.origin}${path}`;\n\n if (!loadedSheets.has(fullPath)) {\n let link = document.querySelector(`link[href=\"${path}\"]`);\n\n if (!link) {\n link = document.createElement('link');\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('href', path);\n document.head.appendChild(link);\n }\n\n res = new Barrier<void>();\n link.addEventListener('load', () => {\n if (!res) throw Error('Internal error');\n void res.resolve();\n });\n link.addEventListener('error', () => {\n if (!res) throw Error('Internal error');\n void res.resolve();\n });\n }\n\n if (refCount) {\n const current = refCounts[path] ?? 0;\n refCounts[path] = 1 + current;\n }\n\n return res;\n}\n\n/**\n * Generates the set of URLs for currently loaded, linked stylesheets.\n * @return\n */\nfunction getLoadedStyleSheets(): Set<string> {\n const res = new Set<string>();\n const { styleSheets } = document;\n for (const { href } of styleSheets) {\n if (href) res.add(href);\n }\n return res;\n}\n\nfunction assertChunkName(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n) {\n if (chunkGroups[chunkName]) return;\n throw Error(`Unknown chunk name \"${chunkName}\"`);\n}\n\n/**\n * Client-side only! Ensures all CSS stylesheets required for the specified\n * code chunk are loaded into the document; loads the missing ones; and does\n * simple reference counting to facilitate future clean-up.\n * @param chunkName Chunk name.\n * @param refCount\n * @return Resolves once all pending stylesheets, necessary for\n * the chunk, are either loaded, or failed to load.\n */\nexport async function bookStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n refCount: boolean,\n): Promise<void> {\n const promises = [];\n const assets = chunkGroups[chunkName];\n if (!assets) return Promise.resolve();\n\n const loadedSheets = getLoadedStyleSheets();\n\n for (const asset of assets) {\n if (asset.endsWith('.css')) {\n const promise = bookStyleSheet(asset, loadedSheets, refCount);\n if (promise) promises.push(promise);\n }\n }\n\n return promises.length\n ? Promise.allSettled(promises).then()\n : Promise.resolve();\n}\n\n/**\n * Client-side only! Frees from the document all CSS stylesheets that are\n * required by the specified chunk, and have reference counter equal to one\n * (for chunks with larger reference counter values, it just decrements\n * the reference counter).\n * @param {string} chunkName\n */\nexport function freeStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n): void {\n const assets = chunkGroups[chunkName];\n if (!assets) return;\n\n for (const asset of assets) {\n if (asset.endsWith('.css')) {\n const path = `${getPublicPath()}/${asset}`;\n\n const pathRefCount = refCounts[path];\n if (pathRefCount) {\n if (pathRefCount <= 1) {\n document.head.querySelector(`link[href=\"${path}\"]`)!.remove();\n delete refCounts[path];\n } else refCounts[path] = pathRefCount - 1;\n }\n }\n }\n}\n\n// Holds the set of chunk names already used for splitComponent() calls.\n// const usedChunkNames = new Set();\n\ntype ComponentOrModule<PropsT> = ComponentType<PropsT> | {\n default: ComponentType<PropsT>;\n};\n\ntype GenericComponentPropsT = {\n children?: ReactNode;\n ref?: RefObject<unknown>;\n\n // NOTE: This is necessary, as without it this type (with only optional\n // fields) will be conisdered as \"weak\" by TypeScript, and it will be\n // a error to assign to it any type that does not use \"children\", or \"ref\".\n [propName: string]: unknown;\n};\n\n/**\n * Given an async component retrieval function `getComponent()` it creates\n * a special \"code split\" component, which uses <Suspense> to asynchronously\n * load on demand the code required by `getComponent()`.\n * @param options\n * @param options.chunkName\n * @param {function} options.getComponent\n * @param {React.Element} [options.placeholder]\n * @return {React.ElementType}\n */\nexport default function splitComponent<\n ComponentPropsT extends GenericComponentPropsT,\n>({\n chunkName,\n getComponent,\n placeholder,\n}: {\n chunkName: string;\n getComponent: () => Promise<ComponentOrModule<ComponentPropsT>>;\n placeholder?: ReactNode;\n}): FunctionComponent<ComponentPropsT> {\n // TODO: For now I commented out this safeguard check, as I am not sure how\n // to easily make it work: it should not be triggered in HMR mode, but if I\n // add the code relying on import.meta, it fails in Jest environment, because\n // Jest does not support ES modules yet, and import.meta is not support in\n // CommonJS modules, and the \"babel-plugin-transform-import-meta\" plugin\n // we use to workaround this issue for import.meta.dirname, etc. does not\n // transform import.meta.webpackHot\n\n // The correct usage of splitComponent() assumes a single call per chunk.\n // if (usedChunkNames.has(chunkName)\n\n // When HMR happens splitComponent() ends up getting called again for some\n // chunks, thus we should not throw this error. Not sure, if we need to do\n // some additional handling in that case, or just not throwing is all we\n // need.\n // && !import.meta.webpackHot\n // ) {\n // throw Error(`Repeated splitComponent() call for the chunk \"${chunkName}\"`);\n // } else usedChunkNames.add(chunkName);\n\n const LazyComponent = lazy(async () => {\n const resolved = await getComponent();\n const Component = 'default' in resolved ? resolved.default : resolved;\n\n // This pre-loads necessary stylesheets prior to the first mount of\n // the component (the lazy load function is executed by React one at\n // the frist mount).\n if (IS_CLIENT_SIDE) {\n if (!clientChunkGroups) throw Error('Internal error');\n await bookStyleSheets(chunkName, clientChunkGroups, false);\n }\n\n const Wrapper: FunctionComponent<ComponentPropsT & {\n chunkGroups: ChunkGroupsT;\n }> = ({\n children,\n chunkGroups,\n ref,\n ...rest\n }) => {\n // This takes care about stylesheets management every time an instance of\n // this component is mounted / unmounted.\n useInsertionEffect(() => {\n if (!clientChunkGroups) throw Error('Internal error');\n void bookStyleSheets(chunkName, chunkGroups, true);\n return () => {\n freeStyleSheets(chunkName, chunkGroups);\n };\n }, [chunkGroups]);\n\n return (\n <Component\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...(rest as unknown as ComponentPropsT)}\n ref={ref}\n >\n {children}\n </Component>\n );\n };\n\n return { default: Wrapper };\n });\n\n const CodeSplit: FunctionComponent<ComponentPropsT> = ({\n children,\n ...rest\n }: ComponentPropsT) => {\n let chunkGroups: ChunkGroupsT;\n\n const ssrContext = useSsrContext(false);\n\n // On the server side we'll assert the chunk name here,\n // and also push it to the SSR chunks array.\n if (IS_SERVER_SIDE) {\n if (!ssrContext) throw Error('Internal error');\n ({ chunkGroups } = ssrContext);\n const { chunks } = ssrContext;\n\n if (!chunks.includes(chunkName)) chunks.push(chunkName);\n } else {\n if (!clientChunkGroups) throw Error('Internal error');\n chunkGroups = clientChunkGroups;\n }\n\n assertChunkName(chunkName, chunkGroups);\n\n return (\n <Suspense fallback={placeholder}>\n <LazyComponent\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...rest as Parameters<typeof LazyComponent>[0]}\n\n chunkGroups={chunkGroups}\n >\n {children}\n </LazyComponent>\n </Suspense>\n );\n };\n\n return CodeSplit;\n}\n"],"mappings":";;;;;;;;;;;;;;iDAAA;AAEA,SAKEA,QAAQ,EACRC,IAAI,EACJC,kBAAkB,QACb,OAAO;AAEd,SAASC,OAAO,QAAQ,sBAAsB;AAE9C,SAA4BC,aAAa;AAAA,SAGvCC,cAAc,EACdC,cAAc,EACdC,gBAAgB,EAChBC,YAAY;AACO,SAAAC,GAAA,IAAAC,IAAA;AAErB,IAAIC,iBAA2C;AAE/C,OAAO,SAASC,oBAAoBA,CAACC,MAAoB,EAAQ;EAC/DN,gBAAgB,CAAC,CAAC;EAClBI,iBAAiB,GAAGE,MAAM;AAC5B;AAEA,MAAMC,SAAiC,GAAG,CAAC,CAAC;AAE5C,SAASC,aAAaA,CAAA,EAAG;EACvB,OAAOP,YAAY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A,GAAclC,iBAAiB;IAApB;IAGbgC,eAAe,CAACC,SAAS,EAAEC,WAAW,CAAC;IAM7B,MAAA6B,EAAA,GAAAD,IAAI;IAAuC,IAAAE,EAAA;IAAA,IAAAN,CAAA,QAAAE,QAAA,IAAAF,CAAA,QAAAxB,WAAA,IAAAwB,CAAA,QAAAK,EAAA;MAHnDC,EAAA,gBAAAjE,IAAA,CAACV,QAAQ;QAAWkF,QAAW,EAAXpB,WAAW;QAAAS,QAAA,eAC7B7D,IAAA,CAACqD,aAAa;UAAA,GAERW,EAA2C;UAElC7B,WAAW,EAAXA,WAAW;UAAA0B,QAAA,EAEvBA;QAAQ,CACI;MAAC,CACR,CAAC;MAAAF,CAAA,MAAAE,QAAA;MAAAF,CAAA,MAAAxB,WAAA;MAAAwB,CAAA,MAAAK,EAAA;MAAAL,CAAA,MAAAM,EAAA;IAAA;MAAAA,EAAA,GAAAN,CAAA;IAAA;IAAA,OATXM,EASW;EAAA,CAEd;EAED,OAAOG,SAAS;AAClB","ignoreList":[]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { c as _c } from "react/compiler-runtime";
|
|
1
2
|
import { serialize } from "cookie";
|
|
2
3
|
import dayjs from "dayjs";
|
|
3
4
|
import { useEffect } from "react";
|
|
4
5
|
import { DAY_MS, HOUR_MS, MIN_MS, SEC_MS, YEAR_MS, timer } from "@dr.pogodin/js-utils";
|
|
5
6
|
import { useGlobalState } from "@dr.pogodin/react-global-state";
|
|
6
|
-
import {
|
|
7
|
+
import { useSsrContext } from "./globalState.js";
|
|
7
8
|
/**
|
|
8
9
|
* This react hook wraps Date.now() function in a SSR friendly way,
|
|
9
10
|
* ensuring that all calls to useCurrent() within the same render return
|
|
@@ -45,25 +46,59 @@ export function useCurrent({
|
|
|
45
46
|
* as the default value.
|
|
46
47
|
*/ // TODO: Should we request the state type as generic parameter, to be able
|
|
47
48
|
// to verify the give globalStatePath is correct?
|
|
48
|
-
export function useTimezoneOffset({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
49
|
+
export function useTimezoneOffset(t0) {
|
|
50
|
+
const $ = _c(9);
|
|
51
|
+
let t1;
|
|
52
|
+
if ($[0] !== t0) {
|
|
53
|
+
t1 = t0 === undefined ? {} : t0;
|
|
54
|
+
$[0] = t0;
|
|
55
|
+
$[1] = t1;
|
|
56
|
+
} else {
|
|
57
|
+
t1 = $[1];
|
|
58
|
+
}
|
|
59
|
+
const {
|
|
60
|
+
cookieName: t2,
|
|
61
|
+
globalStatePath: t3
|
|
62
|
+
} = t1;
|
|
63
|
+
const cookieName = t2 === undefined ? "timezoneOffset" : t2;
|
|
64
|
+
const globalStatePath = t3 === undefined ? "timezoneOffset" : t3;
|
|
65
|
+
const ssrContext = useSsrContext(false);
|
|
66
|
+
let t4;
|
|
67
|
+
if ($[2] !== cookieName || $[3] !== ssrContext?.req) {
|
|
68
|
+
t4 = () => {
|
|
69
|
+
const value = cookieName && ssrContext?.req.cookies[cookieName];
|
|
70
|
+
return value ? parseInt(value) : 0;
|
|
71
|
+
};
|
|
72
|
+
$[2] = cookieName;
|
|
73
|
+
$[3] = ssrContext?.req;
|
|
74
|
+
$[4] = t4;
|
|
75
|
+
} else {
|
|
76
|
+
t4 = $[4];
|
|
77
|
+
}
|
|
78
|
+
const [offset, setOffset] = useGlobalState(globalStatePath, t4);
|
|
79
|
+
let t5;
|
|
80
|
+
let t6;
|
|
81
|
+
if ($[5] !== cookieName || $[6] !== setOffset) {
|
|
82
|
+
t5 = () => {
|
|
83
|
+
const date = new Date();
|
|
84
|
+
const value_0 = date.getTimezoneOffset();
|
|
85
|
+
setOffset(value_0);
|
|
86
|
+
if (cookieName) {
|
|
87
|
+
document.cookie = serialize(cookieName, value_0.toString(), {
|
|
88
|
+
path: "/"
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
t6 = [cookieName, setOffset];
|
|
93
|
+
$[5] = cookieName;
|
|
94
|
+
$[6] = setOffset;
|
|
95
|
+
$[7] = t5;
|
|
96
|
+
$[8] = t6;
|
|
97
|
+
} else {
|
|
98
|
+
t5 = $[7];
|
|
99
|
+
t6 = $[8];
|
|
100
|
+
}
|
|
101
|
+
useEffect(t5, t6);
|
|
67
102
|
return offset;
|
|
68
103
|
}
|
|
69
104
|
const time = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","names":["serialize","dayjs","useEffect","DAY_MS","HOUR_MS","MIN_MS","SEC_MS","YEAR_MS","timer","useGlobalState","
|
|
1
|
+
{"version":3,"file":"time.js","names":["serialize","dayjs","useEffect","DAY_MS","HOUR_MS","MIN_MS","SEC_MS","YEAR_MS","timer","useGlobalState","useSsrContext","useCurrent","autorefresh","globalStatePath","precision","now","setter","Date","timerId","update","old","neu","Math","abs","setTimeout","clearTimeout","useTimezoneOffset","t0","$","_c","t1","undefined","cookieName","t2","t3","ssrContext","t4","req","value","cookies","parseInt","offset","setOffset","t5","t6","date","value_0","getTimezoneOffset","document","cookie","toString","path","time","Object","assign"],"sources":["../../../../src/shared/utils/time.ts"],"sourcesContent":["import { serialize } from 'cookie';\nimport dayjs from 'dayjs';\nimport { useEffect } from 'react';\n\nimport {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n timer,\n} from '@dr.pogodin/js-utils';\n\nimport { type ForceT, useGlobalState } from '@dr.pogodin/react-global-state';\n\nimport { useSsrContext } from './globalState';\n\n/**\n * This react hook wraps Date.now() function in a SSR friendly way,\n * ensuring that all calls to useCurrent() within the same render return\n * exactly the same time (which is retrieved from Date.now() first, and\n * then stored in the global state to be reused in all other calls), which\n * is also passed and used in the first client side render, and then updated\n * with a finite precision to avoid infinite re-rendering loops.\n */\n// TODO: Should we request the state type as generic parameter, to be able\n// to verify the give globalStatePath is correct?\nexport function useCurrent({\n autorefresh = false,\n globalStatePath = 'currentTime',\n precision = 5 * SEC_MS,\n} = {}): number {\n const [now, setter] = useGlobalState<ForceT, number>(\n globalStatePath,\n Date.now,\n );\n useEffect(() => {\n let timerId: NodeJS.Timeout | undefined;\n const update = (): void => {\n setter((old) => {\n const neu = Date.now();\n return Math.abs(neu - old) > precision ? neu : old;\n });\n if (autorefresh) timerId = setTimeout(update, precision);\n };\n update();\n return (): void => {\n if (timerId) clearTimeout(timerId);\n };\n }, [autorefresh, precision, setter]);\n return now;\n}\n\n/**\n * Wraps the standard Date.getTimezoneOffset() method in a SSR-friendly way.\n * This hook retrieves the offset value at the client side and uses a cookie\n * to pass it to the server in subsequent requests from that user. At the server\n * side the value from cookie is used in renders and passed back to the client\n * via the global state. Prior to the value being known (in the very first\n * request from the user, when the cookie is still missing), zero value is used\n * as the default value.\n */\n// TODO: Should we request the state type as generic parameter, to be able\n// to verify the give globalStatePath is correct?\nexport function useTimezoneOffset({\n cookieName = 'timezoneOffset',\n globalStatePath = 'timezoneOffset',\n} = {}): number {\n const ssrContext = useSsrContext(false);\n const [offset, setOffset] = useGlobalState<ForceT, number>(\n globalStatePath,\n () => {\n const value = cookieName\n && ssrContext?.req.cookies[cookieName] as string;\n return value ? parseInt(value) : 0;\n },\n );\n useEffect(() => {\n const date = new Date();\n const value = date.getTimezoneOffset();\n setOffset(value);\n if (cookieName) {\n document.cookie = serialize(cookieName, value.toString(), { path: '/' });\n }\n }, [cookieName, setOffset]);\n return offset;\n}\n\nconst time = {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n now: Date.now,\n timer,\n useCurrent,\n useTimezoneOffset,\n};\n\nexport default Object.assign(dayjs, time);\n"],"mappings":";AAAA,SAASA,SAAS,QAAQ,QAAQ;AAClC,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,SAAS,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Id,UAAU;QACZgB,QAAQ,CAAAC,MAAA,GAAUjD,SAAS,CAACgC,UAAU,EAAEc,OAAK,CAAAI,QAAS,CAAC,CAAC,EAAE;UAAAC,IAAA,EAAQ;QAAI,CAAC,CAAxD;MAAA;IAChB,CACF;IAAEP,EAAA,IAACZ,UAAU,EAAEU,SAAS,CAAC;IAAAd,CAAA,MAAAI,UAAA;IAAAJ,CAAA,MAAAc,SAAA;IAAAd,CAAA,MAAAe,EAAA;IAAAf,CAAA,MAAAgB,EAAA;EAAA;IAAAD,EAAA,GAAAf,CAAA;IAAAgB,EAAA,GAAAhB,CAAA;EAAA;EAP1B1B,SAAS,CAACyC,EAOT,EAAEC,EAAuB,CAAC;EAAA,OACpBH,MAAM;AAAA;AAGf,MAAMW,IAAI,GAAG;EACXjD,MAAM;EACNC,OAAO;EACPC,MAAM;EACNC,MAAM;EACNC,OAAO;EACPQ,GAAG,EAAEE,IAAI,CAACF,GAAG;EACbP,KAAK;EACLG,UAAU;EACVe;AACF,CAAC;AAED,eAAe2B,MAAM,CAACC,MAAM,CAACrD,KAAK,EAAEmD,IAAI,CAAC","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Initialization of client-side code.
|
|
2
|
-
/* global document */import{createRoot,hydrateRoot}from"react-dom/client";import{BrowserRouter}from"react-router";import{GlobalStateProvider}from"@dr.pogodin/react-global-state";import{HelmetProvider}from"@dr.pogodin/react-helmet";import getInj from"./getInj.js";import{jsx as _jsx}from"react/jsx-runtime";/**
|
|
2
|
+
/* global document */import{createRoot,hydrateRoot}from"react-dom/client";import{BrowserRouter}from"react-router";import{GlobalStateProvider}from"@dr.pogodin/react-global-state";import{HelmetProvider}from"@dr.pogodin/react-helmet";import{setClientChunkGroups}from"../shared/utils/splitComponent.js";import getInj from"./getInj.js";import{jsx as _jsx}from"react/jsx-runtime";/**
|
|
3
3
|
* Prepares and launches the app at client side.
|
|
4
4
|
* @param Application Root application component
|
|
5
5
|
* @param [options={}] Optional. Additional settings.
|
|
6
|
-
*/export async function launchClient(Application,options={}){const inj=await getInj();const container=document.getElementById("react-view");if(!container)throw Error("Failed to find container for React app");const scene=/*#__PURE__*/_jsx(GlobalStateProvider,{initialState:inj.ISTATE??options.initialState,children:/*#__PURE__*/_jsx(BrowserRouter,{children:/*#__PURE__*/_jsx(HelmetProvider,{children:/*#__PURE__*/_jsx(Application,{})})})});if(options.dontHydrate){const root=createRoot(container);root.render(scene);}else hydrateRoot(container,scene);}
|
|
6
|
+
*/export async function launchClient(Application,options={}){const inj=await getInj();setClientChunkGroups(inj.CHUNK_GROUPS??{});const container=document.getElementById("react-view");if(!container)throw Error("Failed to find container for React app");const scene=/*#__PURE__*/_jsx(GlobalStateProvider,{initialState:inj.ISTATE??options.initialState,children:/*#__PURE__*/_jsx(BrowserRouter,{children:/*#__PURE__*/_jsx(HelmetProvider,{children:/*#__PURE__*/_jsx(Application,{})})})});if(options.dontHydrate){const root=createRoot(container);root.render(scene);}else hydrateRoot(container,scene);}
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["createRoot","hydrateRoot","BrowserRouter","GlobalStateProvider","HelmetProvider","getInj","jsx","_jsx","launchClient","Application","options","inj","container","document","getElementById","Error","scene","initialState","ISTATE","children","dontHydrate","root","render"],"sources":["../../../src/client/index.tsx"],"sourcesContent":["// Initialization of client-side code.\n/* global document */\n\nimport type { ComponentType } from 'react';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\nimport { BrowserRouter } from 'react-router';\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\nimport { HelmetProvider } from '@dr.pogodin/react-helmet';\n\nimport getInj from './getInj';\n\ntype OptionsT = {\n dontHydrate?: boolean;\n initialState?: unknown;\n};\n\n/**\n * Prepares and launches the app at client side.\n * @param Application Root application component\n * @param [options={}] Optional. Additional settings.\n */\nexport async function launchClient(\n Application: ComponentType,\n options: OptionsT = {},\n): Promise<void> {\n const inj = await getInj();\n\n const container = document.getElementById('react-view');\n if (!container) throw Error('Failed to find container for React app');\n const scene = (\n <GlobalStateProvider initialState={inj.ISTATE ?? options.initialState}>\n <BrowserRouter>\n <HelmetProvider>\n <Application />\n </HelmetProvider>\n </BrowserRouter>\n </GlobalStateProvider>\n );\n\n if (options.dontHydrate) {\n const root = createRoot(container);\n root.render(scene);\n } else hydrateRoot(container, scene);\n}\n"],"mappings":"AAAA;AACA,qBAGA,OAASA,UAAU,CAAEC,WAAW,KAAQ,kBAAkB,CAC1D,OAASC,aAAa,KAAQ,cAAc,CAE5C,OAASC,mBAAmB,KAAQ,gCAAgC,CACpE,OAASC,cAAc,KAAQ,0BAA0B,CAEzD,
|
|
1
|
+
{"version":3,"file":"index.js","names":["createRoot","hydrateRoot","BrowserRouter","GlobalStateProvider","HelmetProvider","setClientChunkGroups","getInj","jsx","_jsx","launchClient","Application","options","inj","CHUNK_GROUPS","container","document","getElementById","Error","scene","initialState","ISTATE","children","dontHydrate","root","render"],"sources":["../../../src/client/index.tsx"],"sourcesContent":["// Initialization of client-side code.\n/* global document */\n\nimport type { ComponentType } from 'react';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\nimport { BrowserRouter } from 'react-router';\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\nimport { HelmetProvider } from '@dr.pogodin/react-helmet';\n\nimport { setClientChunkGroups } from 'utils/splitComponent';\n\nimport getInj from './getInj';\n\ntype OptionsT = {\n dontHydrate?: boolean;\n initialState?: unknown;\n};\n\n/**\n * Prepares and launches the app at client side.\n * @param Application Root application component\n * @param [options={}] Optional. Additional settings.\n */\nexport async function launchClient(\n Application: ComponentType,\n options: OptionsT = {},\n): Promise<void> {\n const inj = await getInj();\n\n setClientChunkGroups(inj.CHUNK_GROUPS ?? {});\n\n const container = document.getElementById('react-view');\n if (!container) throw Error('Failed to find container for React app');\n const scene = (\n <GlobalStateProvider initialState={inj.ISTATE ?? options.initialState}>\n <BrowserRouter>\n <HelmetProvider>\n <Application />\n </HelmetProvider>\n </BrowserRouter>\n </GlobalStateProvider>\n );\n\n if (options.dontHydrate) {\n const root = createRoot(container);\n root.render(scene);\n } else hydrateRoot(container, scene);\n}\n"],"mappings":"AAAA;AACA,qBAGA,OAASA,UAAU,CAAEC,WAAW,KAAQ,kBAAkB,CAC1D,OAASC,aAAa,KAAQ,cAAc,CAE5C,OAASC,mBAAmB,KAAQ,gCAAgC,CACpE,OAASC,cAAc,KAAQ,0BAA0B,CAEzD,OAASC,oBAAoB,+CAEtB,CAAAC,MAAM,mBAAiB,OAAAC,GAAA,IAAAC,IAAA,yBAO9B;AACA;AACA;AACA;AACA,GACA,MAAO,eAAe,CAAAC,YAAYA,CAChCC,WAA0B,CAC1BC,OAAiB,CAAG,CAAC,CAAC,CACP,CACf,KAAM,CAAAC,GAAG,CAAG,KAAM,CAAAN,MAAM,CAAC,CAAC,CAE1BD,oBAAoB,CAACO,GAAG,CAACC,YAAY,EAAI,CAAC,CAAC,CAAC,CAE5C,KAAM,CAAAC,SAAS,CAAGC,QAAQ,CAACC,cAAc,CAAC,YAAY,CAAC,CACvD,GAAI,CAACF,SAAS,CAAE,KAAM,CAAAG,KAAK,CAAC,wCAAwC,CAAC,CACrE,KAAM,CAAAC,KAAK,cACTV,IAAA,CAACL,mBAAmB,EAACgB,YAAY,CAAEP,GAAG,CAACQ,MAAM,EAAIT,OAAO,CAACQ,YAAa,CAAAE,QAAA,cACpEb,IAAA,CAACN,aAAa,EAAAmB,QAAA,cACZb,IAAA,CAACJ,cAAc,EAAAiB,QAAA,cACbb,IAAA,CAACE,WAAW,GAAE,CAAC,CACD,CAAC,CACJ,CAAC,CACG,CACtB,CAED,GAAIC,OAAO,CAACW,WAAW,CAAE,CACvB,KAAM,CAAAC,IAAI,CAAGvB,UAAU,CAACc,SAAS,CAAC,CAClCS,IAAI,CAACC,MAAM,CAACN,KAAK,CAAC,CACpB,CAAC,IAAM,CAAAjB,WAAW,CAACa,SAAS,CAAEI,KAAK,CAAC,CACtC","ignoreList":[]}
|
|
@@ -27,5 +27,5 @@ if (import.meta.webpackHot) {
|
|
|
27
27
|
delete global.REACT_UTILS_LIBRARY_LOADED;
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
-
*/export{GlobalStateProvider,
|
|
30
|
+
*/export{GlobalStateProvider,newAsyncDataEnvelope,useAsyncCollection,useAsyncData,useGlobalState,useGlobalStateObject,withGlobalStateType}from"@dr.pogodin/react-global-state";export*from"./shared/components/index.js";export{Barrier,Cached,Emitter,Semaphore,THEME_COMPOSE,THEME_PRIORITY,ThemeProvider,assertEmptyObject,getConfig,splitComponent,time,useSsrContext,useTheme,webpack,withRetries}from"./shared/utils/index.js";export*from"./shared/utils/isomorphy/index.js";
|
|
31
31
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["GlobalStateProvider","
|
|
1
|
+
{"version":3,"file":"index.js","names":["GlobalStateProvider","newAsyncDataEnvelope","useAsyncCollection","useAsyncData","useGlobalState","useGlobalStateObject","withGlobalStateType","Barrier","Cached","Emitter","Semaphore","THEME_COMPOSE","THEME_PRIORITY","ThemeProvider","assertEmptyObject","getConfig","splitComponent","time","useSsrContext","useTheme","webpack","withRetries"],"sources":["../../src/index.ts"],"sourcesContent":["// TODO: For now I commented out this safeguard check, as I am not sure how\n// to easily make it work: it should not be triggered in HMR mode, but if I\n// add the code relying on import.meta, it fails in Jest environment, because\n// Jest does not support ES modules yet, and import.meta is not support in\n// CommonJS modules, and the \"babel-plugin-transform-import-meta\" plugin\n// we use to workaround this issue for import.meta.dirname, etc. does not\n// transform import.meta.webpackHot\n\n// It is a safeguard against multiple instances / versions of the library\n// being loaded into environment by mistake (e.g. because of different\n// packages pinning down different exact versions of the lib, thus preventing\n// a proper dedupe and using a single common library version).\n// if (global.REACT_UTILS_LIBRARY_LOADED) {\n// throw Error('React utils library is already loaded');\n// } else global.REACT_UTILS_LIBRARY_LOADED = true;\n\n/*\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface ImportMeta {\n webpackHot?: {\n dispose(cb: () => void): void;\n };\n }\n}\n\nif (import.meta.webpackHot) {\n import.meta.webpackHot.dispose(() => {\n delete global.REACT_UTILS_LIBRARY_LOADED;\n });\n}\n*/\n\nexport {\n type AsyncCollectionLoaderT,\n type AsyncCollectionT,\n type AsyncDataEnvelopeT,\n type AsyncDataLoaderT,\n type ForceT,\n GlobalStateProvider,\n type UseAsyncDataOptionsT,\n type UseAsyncDataResT,\n type UseGlobalStateResT,\n type ValueOrInitializerT,\n newAsyncDataEnvelope,\n useAsyncCollection,\n useAsyncData,\n useGlobalState,\n useGlobalStateObject,\n withGlobalStateType,\n} from '@dr.pogodin/react-global-state';\n\nexport * from 'components';\n\nexport {\n type BeforeRenderResT,\n type BeforeRenderT,\n type ConfigT,\n type ServerSsrContext,\n type ServerT,\n} from './server';\n\nexport {\n Barrier,\n Cached,\n Emitter,\n type Listener,\n type ObjectKey,\n Semaphore,\n THEME_COMPOSE,\n THEME_PRIORITY,\n type Theme,\n ThemeProvider,\n assertEmptyObject,\n getConfig,\n splitComponent,\n time,\n useSsrContext,\n useTheme,\n webpack,\n withRetries,\n} from 'utils';\n\nexport * from 'utils/isomorphy';\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAEA,OAMEA,mBAAmB,CAKnBC,oBAAoB,CACpBC,kBAAkB,CAClBC,YAAY,CACZC,cAAc,CACdC,oBAAoB,CACpBC,mBAAmB,KACd,gCAAgC,CAEvC,iDAWEC,OAAO,CACPC,MAAM,CACNC,OAAO,CAGPC,SAAS,CACTC,aAAa,CACbC,cAAc,CAEdC,aAAa,CACbC,iBAAiB,CACjBC,SAAS,CACTC,cAAc,CACdC,IAAI,CACJC,aAAa,CACbC,QAAQ,CACRC,OAAO,CACPC,WAAW","ignoreList":[]}
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import{useTheme}from"@dr.pogodin/react-themes";import Link from"../Link.js";const defaultTheme={"context":"_0S7CYa","ad":"YFXz0-","hoc":"BElFuo","button":"hXiBOw","active":"biX-UA","disabled":"_-6CH9q"};import{jsx as _jsx}from"react/jsx-runtime";export const BaseButton=({active,children,disabled,enforceA,keepScrollPosition,onClick,onKeyDown:onKeyDownProp,onKeyUp,onMouseDown,onMouseUp,onPointerDown,onPointerUp,openNewTab,replace,testId,theme,to}
|
|
3
|
-
// to check if the `to` URL contains an anchor (#), and if it does we should
|
|
4
|
-
// automatically opt to keep the position here; and enforce <a> (as
|
|
5
|
-
// react-router link does not seem to respect the hash tag either,
|
|
6
|
-
// at least not without some additional settings).
|
|
7
|
-
,keepScrollPosition:keepScrollPosition,onClick:onClick// TODO: For now, the `onKeyDown` handler is not passed to the <Link>,
|
|
8
|
-
// as <Link> component does not call it anyway, presumably due to
|
|
9
|
-
// the inner implementation details. We should look into supporting it:
|
|
10
|
-
// https://github.com/birdofpreyru/react-utils/issues/444
|
|
11
|
-
// onKeyDown={onKeyDown}
|
|
12
|
-
,onKeyUp:onKeyUp,onMouseDown:onMouseDown,onMouseUp:onMouseUp,onPointerDown:onPointerDown,onPointerUp:onPointerUp,openNewTab:openNewTab,replace:replace,to:to,children:children});}return/*#__PURE__*/_jsx("div",{className:className,"data-testid":process.env.NODE_ENV==="production"?undefined:testId,onClick:onClick,onKeyDown:onKeyDown,onKeyUp:onKeyUp,onMouseDown:onMouseDown,onMouseUp:onMouseUp,onPointerDown:onPointerDown,onPointerUp:onPointerUp,role:"button",tabIndex:0,children:children});};const Button=({theme,...rest})=>{const composed=useTheme("Button",defaultTheme,theme);// eslint-disable-next-line react/jsx-props-no-spreading
|
|
13
|
-
return/*#__PURE__*/_jsx(BaseButton,{...rest,theme:composed});};export default Button;
|
|
1
|
+
import{c as _c}from"react/compiler-runtime";// The <Button> component implements a standard button / button-like link.
|
|
2
|
+
import{useTheme}from"@dr.pogodin/react-themes";import Link from"../Link.js";const defaultTheme={"context":"_0S7CYa","ad":"YFXz0-","hoc":"BElFuo","button":"hXiBOw","active":"biX-UA","disabled":"_-6CH9q"};import{jsx as _jsx}from"react/jsx-runtime";export const BaseButton=t0=>{const $=_c(32);const{active,children,disabled,enforceA,keepScrollPosition,onClick,onKeyDown:onKeyDownProp,onKeyUp,onMouseDown,onMouseUp,onPointerDown,onPointerUp,openNewTab,replace,testId,theme,to}=t0;let className=theme.button;if(active&&theme.active){className=className+` ${theme.active}`;}if(disabled){if(theme.disabled){className=className+` ${theme.disabled}`;}const t1=process.env.NODE_ENV==="production"?undefined:testId;let t2;if($[0]!==children||$[1]!==className||$[2]!==t1){t2=/*#__PURE__*/_jsx("div",{className:className,"data-testid":t1,children:children});$[0]=children;$[1]=className;$[2]=t1;$[3]=t2;}else{t2=$[3];}return t2;}let onKeyDown=onKeyDownProp;if(!onKeyDown&&onClick){let t1;if($[4]!==onClick){t1=e=>{if(e.key==="Enter"){onClick(e);}};$[4]=onClick;$[5]=t1;}else{t1=$[5];}onKeyDown=t1;}if(to){const t1=process.env.NODE_ENV==="production"?undefined:testId;let t2;if($[6]!==children||$[7]!==className||$[8]!==enforceA||$[9]!==keepScrollPosition||$[10]!==onClick||$[11]!==onKeyUp||$[12]!==onMouseDown||$[13]!==onMouseUp||$[14]!==onPointerDown||$[15]!==onPointerUp||$[16]!==openNewTab||$[17]!==replace||$[18]!==t1||$[19]!==to){t2=/*#__PURE__*/_jsx(Link,{className:className,"data-testid":t1,enforceA:enforceA,keepScrollPosition:keepScrollPosition,onClick:onClick,onKeyUp:onKeyUp,onMouseDown:onMouseDown,onMouseUp:onMouseUp,onPointerDown:onPointerDown,onPointerUp:onPointerUp,openNewTab:openNewTab,replace:replace,to:to,children:children});$[6]=children;$[7]=className;$[8]=enforceA;$[9]=keepScrollPosition;$[10]=onClick;$[11]=onKeyUp;$[12]=onMouseDown;$[13]=onMouseUp;$[14]=onPointerDown;$[15]=onPointerUp;$[16]=openNewTab;$[17]=replace;$[18]=t1;$[19]=to;$[20]=t2;}else{t2=$[20];}return t2;}const t1=process.env.NODE_ENV==="production"?undefined:testId;let t2;if($[21]!==children||$[22]!==className||$[23]!==onClick||$[24]!==onKeyDown||$[25]!==onKeyUp||$[26]!==onMouseDown||$[27]!==onMouseUp||$[28]!==onPointerDown||$[29]!==onPointerUp||$[30]!==t1){t2=/*#__PURE__*/_jsx("div",{className:className,"data-testid":t1,onClick:onClick,onKeyDown:onKeyDown,onKeyUp:onKeyUp,onMouseDown:onMouseDown,onMouseUp:onMouseUp,onPointerDown:onPointerDown,onPointerUp:onPointerUp,role:"button",tabIndex:0,children:children});$[21]=children;$[22]=className;$[23]=onClick;$[24]=onKeyDown;$[25]=onKeyUp;$[26]=onMouseDown;$[27]=onMouseUp;$[28]=onPointerDown;$[29]=onPointerUp;$[30]=t1;$[31]=t2;}else{t2=$[31];}return t2;};const Button=t0=>{const $=_c(6);let rest;let theme;if($[0]!==t0){({theme,...rest}=t0);$[0]=t0;$[1]=rest;$[2]=theme;}else{rest=$[1];theme=$[2];}const composed=useTheme("Button",defaultTheme,theme);let t1;if($[3]!==composed||$[4]!==rest){t1=/*#__PURE__*/_jsx(BaseButton,{...rest,theme:composed});$[3]=composed;$[4]=rest;$[5]=t1;}else{t1=$[5];}return t1;};export default Button;
|
|
14
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useTheme","Link","defaultTheme","jsx","_jsx","BaseButton","active","children","disabled","enforceA","keepScrollPosition","onClick","onKeyDown","onKeyDownProp","onKeyUp","onMouseDown","onMouseUp","onPointerDown","onPointerUp","openNewTab","replace","testId","theme","to","className","button","process","env","NODE_ENV","undefined","e","key","role","tabIndex","Button","rest","composed"],"sources":["../../../../../src/shared/components/Button/index.tsx"],"sourcesContent":["// The <Button> component implements a standard button / button-like link.\n\nimport type {\n FunctionComponent,\n KeyboardEventHandler,\n MouseEventHandler,\n PointerEventHandler,\n ReactNode,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Link from 'components/Link';\n\nimport defaultTheme from './style.scss';\n\ntype ThemeT = Theme<'active' | 'button' | 'disabled'>;\n\ntype PropsT = {\n active?: boolean;\n children?: ReactNode;\n disabled?: boolean;\n enforceA?: boolean;\n keepScrollPosition?: boolean;\n onClick?: KeyboardEventHandler & MouseEventHandler;\n onKeyDown?: KeyboardEventHandler;\n onKeyUp?: KeyboardEventHandler;\n onMouseDown?: MouseEventHandler;\n onMouseUp?: MouseEventHandler;\n onPointerDown?: PointerEventHandler;\n onPointerUp?: PointerEventHandler;\n openNewTab?: boolean;\n replace?: boolean;\n testId?: string;\n theme: ThemeT;\n\n // TODO: It needs a more precise typing of the object option.\n to?: object | string;\n};\n\nexport const BaseButton: FunctionComponent<PropsT> = ({\n active,\n children,\n disabled,\n enforceA,\n keepScrollPosition,\n onClick,\n onKeyDown: onKeyDownProp,\n onKeyUp,\n onMouseDown,\n onMouseUp,\n onPointerDown,\n onPointerUp,\n openNewTab,\n replace,\n testId,\n theme,\n to,\n}) => {\n let className = theme.button;\n if (active && theme.active) className += ` ${theme.active}`;\n if (disabled) {\n if (theme.disabled) className += ` ${theme.disabled}`;\n return (\n <div\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n >\n {children}\n </div>\n );\n }\n\n let onKeyDown = onKeyDownProp;\n if (!onKeyDown && onClick) {\n onKeyDown = (e) => {\n if (e.key === 'Enter') onClick(e);\n };\n }\n\n if (to) {\n return (\n <Link\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n enforceA={enforceA}\n\n // TODO: This was exposed as a hotifx... however, I guess we better want\n // to check if the `to` URL contains an anchor (#), and if it does we should\n // automatically opt to keep the position here; and enforce <a> (as\n // react-router link does not seem to respect the hash tag either,\n // at least not without some additional settings).\n keepScrollPosition={keepScrollPosition}\n\n onClick={onClick}\n\n // TODO: For now, the `onKeyDown` handler is not passed to the <Link>,\n // as <Link> component does not call it anyway, presumably due to\n // the inner implementation details. We should look into supporting it:\n // https://github.com/birdofpreyru/react-utils/issues/444\n // onKeyDown={onKeyDown}\n\n onKeyUp={onKeyUp}\n onMouseDown={onMouseDown}\n onMouseUp={onMouseUp}\n onPointerDown={onPointerDown}\n onPointerUp={onPointerUp}\n openNewTab={openNewTab}\n replace={replace}\n to={to}\n >\n {children}\n </Link>\n );\n }\n\n return (\n <div\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onClick={onClick}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n onMouseDown={onMouseDown}\n onMouseUp={onMouseUp}\n onPointerDown={onPointerDown}\n onPointerUp={onPointerUp}\n role=\"button\"\n tabIndex={0}\n >\n {children}\n </div>\n );\n};\n\nconst Button: FunctionComponent<\n Omit<PropsT, 'theme'> & { theme?: ThemeT }\n> = ({ theme, ...rest }) => {\n const composed = useTheme('Button', defaultTheme, theme);\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <BaseButton {...rest} theme={composed} />;\n};\n\nexport default Button;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["useTheme","Link","defaultTheme","jsx","_jsx","BaseButton","t0","$","_c","active","children","disabled","enforceA","keepScrollPosition","onClick","onKeyDown","onKeyDownProp","onKeyUp","onMouseDown","onMouseUp","onPointerDown","onPointerUp","openNewTab","replace","testId","theme","to","className","button","t1","process","env","NODE_ENV","undefined","t2","e","key","role","tabIndex","Button","rest","composed"],"sources":["../../../../../src/shared/components/Button/index.tsx"],"sourcesContent":["// The <Button> component implements a standard button / button-like link.\n\nimport type {\n FunctionComponent,\n KeyboardEventHandler,\n MouseEventHandler,\n PointerEventHandler,\n ReactNode,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Link from 'components/Link';\n\nimport defaultTheme from './style.scss';\n\ntype ThemeT = Theme<'active' | 'button' | 'disabled'>;\n\ntype PropsT = {\n active?: boolean;\n children?: ReactNode;\n disabled?: boolean;\n enforceA?: boolean;\n keepScrollPosition?: boolean;\n onClick?: KeyboardEventHandler & MouseEventHandler;\n onKeyDown?: KeyboardEventHandler;\n onKeyUp?: KeyboardEventHandler;\n onMouseDown?: MouseEventHandler;\n onMouseUp?: MouseEventHandler;\n onPointerDown?: PointerEventHandler;\n onPointerUp?: PointerEventHandler;\n openNewTab?: boolean;\n replace?: boolean;\n testId?: string;\n theme: ThemeT;\n\n // TODO: It needs a more precise typing of the object option.\n to?: object | string;\n};\n\nexport const BaseButton: FunctionComponent<PropsT> = ({\n active,\n children,\n disabled,\n enforceA,\n keepScrollPosition,\n onClick,\n onKeyDown: onKeyDownProp,\n onKeyUp,\n onMouseDown,\n onMouseUp,\n onPointerDown,\n onPointerUp,\n openNewTab,\n replace,\n testId,\n theme,\n to,\n}) => {\n let className = theme.button;\n if (active && theme.active) className += ` ${theme.active}`;\n if (disabled) {\n if (theme.disabled) className += ` ${theme.disabled}`;\n return (\n <div\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n >\n {children}\n </div>\n );\n }\n\n let onKeyDown = onKeyDownProp;\n if (!onKeyDown && onClick) {\n onKeyDown = (e) => {\n if (e.key === 'Enter') onClick(e);\n };\n }\n\n if (to) {\n return (\n <Link\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n enforceA={enforceA}\n\n // TODO: This was exposed as a hotifx... however, I guess we better want\n // to check if the `to` URL contains an anchor (#), and if it does we should\n // automatically opt to keep the position here; and enforce <a> (as\n // react-router link does not seem to respect the hash tag either,\n // at least not without some additional settings).\n keepScrollPosition={keepScrollPosition}\n\n onClick={onClick}\n\n // TODO: For now, the `onKeyDown` handler is not passed to the <Link>,\n // as <Link> component does not call it anyway, presumably due to\n // the inner implementation details. We should look into supporting it:\n // https://github.com/birdofpreyru/react-utils/issues/444\n // onKeyDown={onKeyDown}\n\n onKeyUp={onKeyUp}\n onMouseDown={onMouseDown}\n onMouseUp={onMouseUp}\n onPointerDown={onPointerDown}\n onPointerUp={onPointerUp}\n openNewTab={openNewTab}\n replace={replace}\n to={to}\n >\n {children}\n </Link>\n );\n }\n\n return (\n <div\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onClick={onClick}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n onMouseDown={onMouseDown}\n onMouseUp={onMouseUp}\n onPointerDown={onPointerDown}\n onPointerUp={onPointerUp}\n role=\"button\"\n tabIndex={0}\n >\n {children}\n </div>\n );\n};\n\nconst Button: FunctionComponent<\n Omit<PropsT, 'theme'> & { theme?: ThemeT }\n> = ({ theme, ...rest }) => {\n const composed = useTheme('Button', defaultTheme, theme);\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <BaseButton {...rest} theme={composed} />;\n};\n\nexport default Button;\n"],"mappings":"4CAAA;AAUA,OAAqBA,QAAQ,KAAQ,0BAA0B,CAE/D,MAAO,CAAAC,IAAI,wBAAAC,YAAA,6GAE6B,OAAAC,GAAA,IAAAC,IAAA,yBA0BxC,MAAO,MAAM,CAAAC,UAAqC,CAAGC,EAAA,SAAAC,CAAA,CAAAC,EAAA,KAAC,MAAAC,MAAA,CAAAC,QAAA,CAAAC,QAAA,CAAAC,QAAA,CAAAC,kBAAA,CAAAC,OAAA,CAAAC,SAAA,CAAAC,aAAA,CAAAC,OAAA,CAAAC,WAAA,CAAAC,SAAA,CAAAC,aAAA,CAAAC,WAAA,CAAAC,UAAA,CAAAC,OAAA,CAAAC,MAAA,CAAAC,KAAA,CAAAC,EAAA,EAAApB,EAkBrD,CACC,IAAAqB,SAAA,CAAgBF,KAAK,CAAAG,MAAO,CAC5B,GAAInB,MAAsB,EAAZgB,KAAK,CAAAhB,MAAO,EAAEkB,SAAA,CAAAA,SAAS,CAAI,IAAIF,KAAK,CAAAhB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CAAAjC,CAAA,IAAAkB,KAAA,CAAAlB,CAAA,KACrB,MAAAkC,QAAA,CAAiBzC,QAAQ,CAAC,QAAQ,CAAEE,YAAY,CAAEuB,KAAK,CAAC,CAAC,IAAAI,EAAA,IAAAtB,CAAA,MAAAkC,QAAA,EAAAlC,CAAA,MAAAiC,IAAA,EAGlDX,EAAA,cAAAzB,IAAA,CAACC,UAAU,KAAKmC,IAAI,CAASf,KAAQ,CAARgB,QAAQ,CAAG,CAAC,CAAAlC,CAAA,IAAAkC,QAAA,CAAAlC,CAAA,IAAAiC,IAAA,CAAAjC,CAAA,IAAAsB,EAAA,OAAAA,EAAA,CAAAtB,CAAA,WAAzC,CAAAsB,EAAyC,EACjD,CAED,cAAe,CAAAU,MAAM","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useTheme}from"@dr.pogodin/react-themes";const defaultTheme={"context":"_08mmmo","ad":"Hc06MV","hoc":"toOtOd","checkbox":"v4DmWM","indeterminate":"ckSC8W","container":"g7wee9","label":"XQ57WS","error":"foaF-C","errorMessage":"WC9mi1","disabled":"baVvQA"};import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const Checkbox=({checked,disabled,error,label,onChange,testId,theme}
|
|
1
|
+
import{c as _c}from"react/compiler-runtime";import{useTheme}from"@dr.pogodin/react-themes";const defaultTheme={"context":"_08mmmo","ad":"Hc06MV","hoc":"toOtOd","checkbox":"v4DmWM","indeterminate":"ckSC8W","container":"g7wee9","label":"XQ57WS","error":"foaF-C","errorMessage":"WC9mi1","disabled":"baVvQA"};import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const Checkbox=t0=>{const $=_c(17);const{checked,disabled,error,label,onChange,testId,theme}=t0;const composed=useTheme("Checkbox",defaultTheme,theme);let containerClassName=composed.container;if(disabled){containerClassName=containerClassName+` ${composed.disabled}`;}let checkboxClassName=composed.checkbox;if(checked==="indeterminate"){checkboxClassName=checkboxClassName+` ${composed.indeterminate}`;}if(error){containerClassName=containerClassName+` ${composed.error}`;}let t1;if($[0]!==composed.label||$[1]!==label){t1=label===undefined?null:/*#__PURE__*/_jsx("div",{className:composed.label,children:label});$[0]=composed.label;$[1]=label;$[2]=t1;}else{t1=$[2];}const t2=checked===undefined?undefined:checked===true;const t3=process.env.NODE_ENV==="production"?undefined:testId;let t4;if($[3]!==checkboxClassName||$[4]!==disabled||$[5]!==onChange||$[6]!==t2||$[7]!==t3){t4=/*#__PURE__*/_jsx("input",{checked:t2,className:checkboxClassName,"data-testid":t3,disabled:disabled,onChange:onChange,onClick:_temp,type:"checkbox"});$[3]=checkboxClassName;$[4]=disabled;$[5]=onChange;$[6]=t2;$[7]=t3;$[8]=t4;}else{t4=$[8];}let t5;if($[9]!==composed.errorMessage||$[10]!==error){t5=error&&error!==true?/*#__PURE__*/_jsx("div",{className:composed.errorMessage,children:error}):null;$[9]=composed.errorMessage;$[10]=error;$[11]=t5;}else{t5=$[11];}let t6;if($[12]!==containerClassName||$[13]!==t1||$[14]!==t4||$[15]!==t5){t6=/*#__PURE__*/_jsxs("div",{className:containerClassName,children:[t1,t4,t5]});$[12]=containerClassName;$[13]=t1;$[14]=t4;$[15]=t5;$[16]=t6;}else{t6=$[16];}return t6;};export default Checkbox;function _temp(e){e.stopPropagation();}
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useTheme","defaultTheme","jsx","_jsx","jsxs","_jsxs","Checkbox","checked","disabled","error","label","onChange","testId","theme","composed","containerClassName","container","checkboxClassName","checkbox","indeterminate","className","children","
|
|
1
|
+
{"version":3,"file":"index.js","names":["useTheme","defaultTheme","jsx","_jsx","jsxs","_jsxs","Checkbox","t0","$","_c","checked","disabled","error","label","onChange","testId","theme","composed","containerClassName","container","checkboxClassName","checkbox","indeterminate","t1","undefined","className","children","t2","t3","process","env","NODE_ENV","t4","onClick","_temp","type","t5","errorMessage","t6","e","stopPropagation"],"sources":["../../../../../src/shared/components/Checkbox/index.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\ntype PropT<ValueT> = {\n checked?: ValueT;\n disabled?: boolean;\n error?: ReactNode;\n label?: React.ReactNode;\n onChange?: React.ChangeEventHandler<HTMLInputElement>;\n testId?: string;\n theme?: Theme<\n | 'checkbox'\n | 'container'\n | 'disabled'\n | 'error'\n | 'errorMessage'\n | 'indeterminate'\n | 'label'\n >;\n};\n\nconst Checkbox = <ValueT extends 'indeterminate' | boolean = boolean>({\n checked,\n disabled,\n error,\n label,\n onChange,\n testId,\n theme,\n}: PropT<ValueT>): ReactNode => {\n const composed = useTheme('Checkbox', defaultTheme, theme);\n\n let containerClassName = composed.container;\n if (disabled) containerClassName += ` ${composed.disabled}`;\n\n let checkboxClassName = composed.checkbox;\n if (checked === 'indeterminate') checkboxClassName += ` ${composed.indeterminate}`;\n\n if (error) containerClassName += ` ${composed.error}`;\n\n return (\n <div className={containerClassName}>\n { label === undefined\n ? null : <div className={composed.label}>{label}</div> }\n <input\n checked={checked === undefined ? undefined : checked === true}\n className={checkboxClassName}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n disabled={disabled}\n onChange={onChange}\n onClick={(e) => {\n e.stopPropagation();\n }}\n type=\"checkbox\"\n />\n {error && error !== true\n ? <div className={composed.errorMessage}>{error}</div>\n : null}\n </div>\n );\n};\n\nexport default Checkbox;\n"],"mappings":"4CAEA,OAAqBA,QAAQ,KAAQ,0BAA0B,CAE/D,MAAAC,YAAA,oMAAwC,OAAAC,GAAA,IAAAC,IAAA,CAAAC,IAAA,IAAAC,KAAA,yBAoBxC,KAAM,CAAAC,QAAQ,CAAGC,EAAA,SAAAC,CAAA,CAAAC,EAAA,KAAqD,MAAAC,OAAA,CAAAC,QAAA,CAAAC,KAAA,CAAAC,KAAA,CAAAC,QAAA,CAAAC,MAAA,CAAAC,KAAA,EAAAT,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