weifuwu 0.17.2 → 0.17.3
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/dist/index.js +27 -12
- package/dist/react.js +13 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -581,19 +581,20 @@ import chokidar from "chokidar";
|
|
|
581
581
|
import { createContext, useContext } from "react";
|
|
582
582
|
var TsxContext = createContext({ params: {}, query: {} });
|
|
583
583
|
function useCtx() {
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
|
|
584
|
+
const wc = typeof window !== "undefined" ? window.__WEIFUWU_CTX : globalThis.__WEIFUWU_CTX;
|
|
585
|
+
if (wc) {
|
|
586
|
+
const messages2 = typeof window !== "undefined" ? window.__LOCALE_DATA__ : globalThis.__LOCALE_DATA__;
|
|
587
|
+
if (messages2 && typeof wc.t !== "function") {
|
|
588
|
+
wc.t = (key, params) => {
|
|
589
|
+
const msg = key.split(".").reduce((o, k) => o?.[k], messages2);
|
|
590
|
+
if (msg === void 0 || msg === null) return key;
|
|
591
|
+
if (!params) return String(msg);
|
|
592
|
+
let result = String(msg);
|
|
593
|
+
for (const [k, v] of Object.entries(params)) result = result.replace(`{${k}}`, v);
|
|
594
|
+
return result;
|
|
595
|
+
};
|
|
596
596
|
}
|
|
597
|
+
return wc;
|
|
597
598
|
}
|
|
598
599
|
return useContext(TsxContext);
|
|
599
600
|
}
|
|
@@ -898,6 +899,7 @@ var TsxInstance = class {
|
|
|
898
899
|
if (!LMod) continue;
|
|
899
900
|
element = createElement(LMod.default, { children: element });
|
|
900
901
|
}
|
|
902
|
+
setGlobalCtx(ctx);
|
|
901
903
|
const stream = await renderToReadableStream(element);
|
|
902
904
|
return streamResponse(stream, {
|
|
903
905
|
ctx,
|
|
@@ -1096,6 +1098,7 @@ ${src}`;
|
|
|
1096
1098
|
}
|
|
1097
1099
|
}
|
|
1098
1100
|
const bundle = await this.getOrBuildClientBundle(entryPath, layoutPaths, this.pagesDir);
|
|
1101
|
+
setGlobalCtx(ctx);
|
|
1099
1102
|
const stream = await renderToReadableStream(element);
|
|
1100
1103
|
return streamResponse(stream, {
|
|
1101
1104
|
ctx,
|
|
@@ -1269,6 +1272,18 @@ ${src}`;
|
|
|
1269
1272
|
}
|
|
1270
1273
|
}
|
|
1271
1274
|
};
|
|
1275
|
+
function setGlobalCtx(ctx) {
|
|
1276
|
+
;
|
|
1277
|
+
globalThis.__WEIFUWU_CTX = {
|
|
1278
|
+
params: ctx.params,
|
|
1279
|
+
query: ctx.query,
|
|
1280
|
+
user: ctx.user,
|
|
1281
|
+
parsed: ctx.parsed,
|
|
1282
|
+
prefs: ctx.prefs,
|
|
1283
|
+
locale: ctx.locale,
|
|
1284
|
+
theme: ctx.theme
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1272
1287
|
function streamResponse(reactStream, opts) {
|
|
1273
1288
|
const decoder = new TextDecoder();
|
|
1274
1289
|
const encoder2 = new TextEncoder();
|
package/dist/react.js
CHANGED
|
@@ -319,19 +319,20 @@ async function prefetchPage(href) {
|
|
|
319
319
|
import { createContext, useContext } from "react";
|
|
320
320
|
var TsxContext = createContext({ params: {}, query: {} });
|
|
321
321
|
function useCtx() {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
|
|
322
|
+
const wc = typeof window !== "undefined" ? window.__WEIFUWU_CTX : globalThis.__WEIFUWU_CTX;
|
|
323
|
+
if (wc) {
|
|
324
|
+
const messages = typeof window !== "undefined" ? window.__LOCALE_DATA__ : globalThis.__LOCALE_DATA__;
|
|
325
|
+
if (messages && typeof wc.t !== "function") {
|
|
326
|
+
wc.t = (key, params) => {
|
|
327
|
+
const msg = key.split(".").reduce((o, k) => o?.[k], messages);
|
|
328
|
+
if (msg === void 0 || msg === null) return key;
|
|
329
|
+
if (!params) return String(msg);
|
|
330
|
+
let result = String(msg);
|
|
331
|
+
for (const [k, v] of Object.entries(params)) result = result.replace(`{${k}}`, v);
|
|
332
|
+
return result;
|
|
333
|
+
};
|
|
334
334
|
}
|
|
335
|
+
return wc;
|
|
335
336
|
}
|
|
336
337
|
return useContext(TsxContext);
|
|
337
338
|
}
|