jinrai 1.1.3 → 1.1.4
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/front.config.json +2 -1
- package/index.ts +2 -1
- package/lib/bin/bin.js +115 -52
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/src/bin/agent/agent.d.ts +1 -0
- package/lib/src/bin/agent/agent.js +2 -1
- package/lib/src/bin/playwright/pageCollector.d.ts +2 -0
- package/lib/src/bin/playwright/pageTestCollector.d.ts +6 -0
- package/lib/src/bin/playwright/templates.d.ts +6 -1
- package/lib/src/bin/routes/Parser.d.ts +19 -1
- package/lib/src/bin/routes/getRoutes.d.ts +1 -0
- package/lib/src/front/server/useIsServer.d.ts +1 -0
- package/lib/src/front/server/useIsServer.js +7 -0
- package/lib/src/front/server-state/DataProxy.js +3 -0
- package/lib/src/front/server-state/SSR.d.ts +1 -0
- package/lib/src/front/server-state/SSR.js +3 -1
- package/lib/src/front/server-state/orig.d.ts +2 -0
- package/lib/src/front/server-state/{real.js → orig.js} +3 -2
- package/lib/src/front/server-state/serverStates.d.ts +1 -0
- package/lib/src/front/server-state/serverStates.js +6 -2
- package/lib/src/front/server-state/testState.d.ts +3 -0
- package/lib/src/front/server-state/testState.js +14 -0
- package/lib/src/front/server-state/useServerState.js +5 -9
- package/lib/src/front/translate/TranslateConfig.d.ts +21 -0
- package/lib/src/front/translate/TranslateConfig.js +108 -0
- package/lib/src/front/url/JinraiContext.d.ts +1 -0
- package/lib/src/front/url/JinraiContext.js +1 -0
- package/lib/src/front/url/adapter/def.js +1 -1
- package/lib/src/front/url/adapter/rrd6.js +2 -2
- package/lib/src/front/url/adapter/rrd7.js +2 -2
- package/lib/src/front/url/search/useSearch.js +3 -4
- package/lib/src/front/wrapper/Custom.js +5 -1
- package/lib/vite/plugin.js +20 -14
- package/package.json +5 -1
- package/rollup.config.mjs +2 -1
- package/src/bin/agent/agent.ts +1 -0
- package/src/bin/build/build.ts +23 -10
- package/src/bin/playwright/pageCollector.ts +8 -4
- package/src/bin/playwright/pageTestCollector.ts +15 -0
- package/src/bin/playwright/templates.ts +14 -4
- package/src/bin/routes/Parser.ts +88 -27
- package/src/bin/routes/getRoutes.ts +5 -1
- package/src/front/server/useIsServer.ts +5 -0
- package/src/front/server-state/DataProxy.ts +4 -0
- package/src/front/server-state/SSR.ts +5 -1
- package/src/front/server-state/{real.ts → orig.ts} +3 -1
- package/src/front/server-state/serverStates.ts +8 -2
- package/src/front/server-state/testState.ts +15 -0
- package/src/front/server-state/useServerState.ts +6 -11
- package/src/front/translate/TranslateConfig.tsx +153 -0
- package/src/front/url/JinraiContext.tsx +2 -0
- package/src/front/url/adapter/def.tsx +1 -1
- package/src/front/url/adapter/rrd6.tsx +2 -3
- package/src/front/url/adapter/rrd7.tsx +2 -2
- package/src/front/url/search/useSearch.ts +3 -4
- package/src/front/wrapper/Custom.tsx +9 -1
- package/tsconfig.types.json +1 -0
- package/vite/plugin.ts +32 -20
- package/lib/src/front/server-state/real.d.ts +0 -1
package/front.config.json
CHANGED
package/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export type { ServerKey } from "./src/front/server-state/useServerState"
|
|
2
2
|
|
|
3
3
|
export { useServerState } from "./src/front/server-state/useServerState"
|
|
4
|
-
export {
|
|
4
|
+
export { orig, original } from "./src/front/server-state/orig"
|
|
5
5
|
export { useParamsIndex } from "./src/front/url/params/useParamsIndex"
|
|
6
6
|
export { useSearchValue, useSearchArray } from "./src/front/url/search/useSearchValue"
|
|
7
7
|
export { useSearch } from "./src/front/url/search/useSearch"
|
|
8
8
|
export { Custom } from "./src/front/wrapper/Custom"
|
|
9
9
|
|
|
10
10
|
export { stringifyInput } from "./src/front/server-state/SSR"
|
|
11
|
+
export {useIsServer} from "./src/front/server/useIsServer"
|
package/lib/bin/bin.js
CHANGED
|
@@ -33,11 +33,14 @@ class Parser {
|
|
|
33
33
|
options;
|
|
34
34
|
openVar = "{{";
|
|
35
35
|
createVar = "}}";
|
|
36
|
+
openTVar = "{!";
|
|
37
|
+
createTVar = "!}";
|
|
36
38
|
createArray = "</loopwrapper";
|
|
37
39
|
createCustom = "</custom";
|
|
38
40
|
deepUp = "<loopwrapper";
|
|
39
41
|
deepUp2 = "<custom";
|
|
40
42
|
templates = {};
|
|
43
|
+
custom = [];
|
|
41
44
|
constructor(options) {
|
|
42
45
|
this.options = options;
|
|
43
46
|
}
|
|
@@ -50,43 +53,62 @@ class Parser {
|
|
|
50
53
|
let match;
|
|
51
54
|
let deep = 0;
|
|
52
55
|
let lastIndex = 0;
|
|
53
|
-
|
|
56
|
+
let translate = false;
|
|
57
|
+
const tagPattern = new RegExp(`(<loopwrapper(\\s+[^>]*)?>|</loopwrapper>|\{\{|\}\}|\{\!|\!\}|<custom(\\s+[^>]*)?>|</custom>)`, "gi");
|
|
54
58
|
while ((match = tagPattern.exec(content)) !== null) {
|
|
55
59
|
const currentTag = match[0];
|
|
56
60
|
const value = content.substring(lastIndex, match.index);
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
if (translate) {
|
|
62
|
+
if (currentTag.startsWith(this.createTVar)) {
|
|
63
|
+
translate = false;
|
|
64
|
+
this.createTranslate(tree, value);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
60
67
|
continue;
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
else if (currentTag.startsWith(this.deepUp)) {
|
|
64
|
-
deep++;
|
|
65
|
-
if (deep > 1)
|
|
66
|
-
continue;
|
|
67
|
-
this.createElement(tree, value);
|
|
68
|
-
}
|
|
69
|
-
else if (currentTag.startsWith(this.createCustom)) {
|
|
70
|
-
deep--;
|
|
71
|
-
if (deep != 0)
|
|
72
|
-
continue;
|
|
73
|
-
this.createCustomElement(tree, value);
|
|
74
|
-
}
|
|
75
|
-
else if (currentTag.startsWith(this.deepUp2)) {
|
|
76
|
-
deep++;
|
|
77
|
-
if (deep > 1)
|
|
78
|
-
continue;
|
|
79
|
-
this.createElement(tree, value);
|
|
80
|
-
}
|
|
81
|
-
else if (currentTag == this.createVar) {
|
|
82
|
-
if (deep != 0)
|
|
83
|
-
continue;
|
|
84
|
-
this.createElement(tree, value, true);
|
|
68
|
+
}
|
|
85
69
|
}
|
|
86
70
|
else {
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
71
|
+
if (currentTag.startsWith(this.createArray)) {
|
|
72
|
+
deep--;
|
|
73
|
+
if (deep > 0)
|
|
74
|
+
continue;
|
|
75
|
+
this.createElement(tree, value);
|
|
76
|
+
}
|
|
77
|
+
else if (currentTag.startsWith(this.deepUp)) {
|
|
78
|
+
deep++;
|
|
79
|
+
if (deep > 1)
|
|
80
|
+
continue;
|
|
81
|
+
this.createElement(tree, value);
|
|
82
|
+
}
|
|
83
|
+
else if (currentTag.startsWith(this.createCustom)) {
|
|
84
|
+
deep--;
|
|
85
|
+
if (deep != 0)
|
|
86
|
+
continue;
|
|
87
|
+
this.createCustomElement(tree, value);
|
|
88
|
+
}
|
|
89
|
+
else if (currentTag.startsWith(this.deepUp2)) {
|
|
90
|
+
deep++;
|
|
91
|
+
if (deep > 1)
|
|
92
|
+
continue;
|
|
93
|
+
this.createElement(tree, value);
|
|
94
|
+
}
|
|
95
|
+
else if (currentTag.startsWith(this.openTVar)) {
|
|
96
|
+
////////////// >>>>
|
|
97
|
+
if (deep != 0)
|
|
98
|
+
continue;
|
|
99
|
+
translate = true;
|
|
100
|
+
this.createElement(tree, value);
|
|
101
|
+
}
|
|
102
|
+
else if (currentTag == this.createVar) {
|
|
103
|
+
if (deep != 0)
|
|
104
|
+
continue;
|
|
105
|
+
this.createElement(tree, value, true);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
if (deep != 0)
|
|
109
|
+
continue;
|
|
110
|
+
this.createElement(tree, value);
|
|
111
|
+
}
|
|
90
112
|
}
|
|
91
113
|
lastIndex = match.index + currentTag.length;
|
|
92
114
|
}
|
|
@@ -98,18 +120,41 @@ class Parser {
|
|
|
98
120
|
createCustomElement(parent, value) {
|
|
99
121
|
const [customProps, exampleProps, children] = value.split(SPLIT);
|
|
100
122
|
const custom = JSON.parse(customProps);
|
|
123
|
+
if (this.custom.find(itm => itm.name == custom.name) == undefined) {
|
|
124
|
+
this.custom.push({
|
|
125
|
+
name: custom.name,
|
|
126
|
+
html: children,
|
|
127
|
+
props: exampleProps,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
101
130
|
parent.push({
|
|
102
131
|
type: "custom",
|
|
103
132
|
name: custom.name,
|
|
104
133
|
props: custom.props,
|
|
105
134
|
});
|
|
106
135
|
}
|
|
107
|
-
|
|
108
|
-
|
|
136
|
+
createVarible(parent, value) {
|
|
137
|
+
return parent.push({
|
|
138
|
+
type: "value",
|
|
139
|
+
key: value,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
createTranslate(parent, value) {
|
|
143
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
109
144
|
return parent.push({
|
|
110
|
-
type: "
|
|
111
|
-
|
|
145
|
+
type: "tvalue",
|
|
146
|
+
value: value.slice(2, -2),
|
|
112
147
|
});
|
|
148
|
+
}
|
|
149
|
+
return parent.push({
|
|
150
|
+
type: "t",
|
|
151
|
+
text: value,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
createElement(parent, value, isVarible) {
|
|
155
|
+
if (isVarible) {
|
|
156
|
+
return this.createVarible(parent, value);
|
|
157
|
+
}
|
|
113
158
|
if (value.trimStart().startsWith("ArrayDataKey=")) {
|
|
114
159
|
const [key, ...val] = value.trimStart().substring(13).split("|");
|
|
115
160
|
value = val.join("|");
|
|
@@ -140,7 +185,10 @@ const getRoutesAndTemplates = (pages, normalize = true, templates = true) => {
|
|
|
140
185
|
const parser = new Parser({ normalize, templates });
|
|
141
186
|
for (const [id, template] of pages.entries()) {
|
|
142
187
|
const content = parser.parse(template.root);
|
|
143
|
-
const mask = template.mask
|
|
188
|
+
const mask = template.mask
|
|
189
|
+
.replaceAll("/", "\\/")
|
|
190
|
+
.replace(/{(.*?)}/, ".+?")
|
|
191
|
+
.replace("\/*", "\/?.*");
|
|
144
192
|
routes.push({
|
|
145
193
|
id,
|
|
146
194
|
content,
|
|
@@ -151,6 +199,7 @@ const getRoutesAndTemplates = (pages, normalize = true, templates = true) => {
|
|
|
151
199
|
return {
|
|
152
200
|
routes,
|
|
153
201
|
templates: parser.templates,
|
|
202
|
+
customComponents: parser.custom,
|
|
154
203
|
};
|
|
155
204
|
};
|
|
156
205
|
|
|
@@ -194,12 +243,13 @@ class Task {
|
|
|
194
243
|
}
|
|
195
244
|
|
|
196
245
|
const pageCollector = async (page) => {
|
|
197
|
-
const state = await page.evaluate(() => {
|
|
246
|
+
const [state, lang] = await page.evaluate(() => {
|
|
198
247
|
const state = Object.fromEntries(window.$exportServerStates);
|
|
199
|
-
|
|
248
|
+
const lang = window.$langDefaultConfig;
|
|
249
|
+
return [state, lang];
|
|
200
250
|
});
|
|
201
251
|
const root = await page.locator("#root").innerHTML();
|
|
202
|
-
return { root, state };
|
|
252
|
+
return { root, state, lang };
|
|
203
253
|
};
|
|
204
254
|
|
|
205
255
|
const JinraiAgent = "____JINRAI_AGENT____";
|
|
@@ -208,6 +258,7 @@ const getRawPageData = async (url, pages, test = false, debug = false) => {
|
|
|
208
258
|
const task = new Task();
|
|
209
259
|
task.next("Router analysis", "yellow", spinners.dotsCircle);
|
|
210
260
|
const result = [];
|
|
261
|
+
let defaultLang = undefined;
|
|
211
262
|
const browser = await chromium.launch({ headless: !debug, devtools: true, channel: "chrome" });
|
|
212
263
|
// const test_browser = await chromium.launch({ headless: true, channel: "chrome" })
|
|
213
264
|
const context = await browser.newContext({
|
|
@@ -217,11 +268,14 @@ const getRawPageData = async (url, pages, test = false, debug = false) => {
|
|
|
217
268
|
for await (const [id, mask] of pages.entries()) {
|
|
218
269
|
task.next(mask, "yellow", spinners.dotsCircle, 1);
|
|
219
270
|
const page = await context.newPage();
|
|
220
|
-
const path = mask.replaceAll("{", "").replaceAll("}", "");
|
|
271
|
+
const path = mask.replaceAll("{", "").replaceAll("}", "").replace("\/*", "");
|
|
221
272
|
await page.goto(url + path);
|
|
222
273
|
await page.waitForLoadState("networkidle");
|
|
223
274
|
await page.waitForTimeout(1000);
|
|
224
|
-
const { state, root } = await pageCollector(page);
|
|
275
|
+
const { state, root, lang } = await pageCollector(page);
|
|
276
|
+
if (defaultLang == undefined) {
|
|
277
|
+
defaultLang = lang;
|
|
278
|
+
}
|
|
225
279
|
// if (debug) console.log({ input })
|
|
226
280
|
let testRoot = undefined;
|
|
227
281
|
// if (test) {
|
|
@@ -246,7 +300,7 @@ const getRawPageData = async (url, pages, test = false, debug = false) => {
|
|
|
246
300
|
await browser.close();
|
|
247
301
|
// await test_browser.close()
|
|
248
302
|
task.success();
|
|
249
|
-
return result;
|
|
303
|
+
return { pages: result, lang: defaultLang };
|
|
250
304
|
};
|
|
251
305
|
|
|
252
306
|
const vitePreview = async () => {
|
|
@@ -267,15 +321,16 @@ const runBuild = async (options) => {
|
|
|
267
321
|
const config = await getUserConfig(configName);
|
|
268
322
|
task.success();
|
|
269
323
|
const [serverUrl, close] = await vitePreview();
|
|
270
|
-
const pages = await getRawPageData(serverUrl, config.pages, config.test, options.debug);
|
|
324
|
+
const { pages, lang } = await getRawPageData(serverUrl, config.pages, config.test, options.debug);
|
|
325
|
+
console.log({ lang });
|
|
271
326
|
close();
|
|
272
327
|
const outputcashe = path.join(config.dist ?? "dist", ".cached");
|
|
273
328
|
task.do("Format");
|
|
274
|
-
const { routes, templates } = getRoutesAndTemplates(pages);
|
|
329
|
+
const { routes, templates, customComponents } = getRoutesAndTemplates(pages);
|
|
275
330
|
task.next(`Export: (${templates.length})`);
|
|
276
331
|
await mkdir(outputcashe, { recursive: true });
|
|
277
332
|
console.log("dev");
|
|
278
|
-
const exportConfig = { routes, proxy: config.proxy, meta: config.meta };
|
|
333
|
+
const exportConfig = { routes, proxy: config.proxy, meta: config.meta, lang };
|
|
279
334
|
await writeFile(path.join(outputcashe, "config.json"), JSON.stringify(exportConfig, null, 2));
|
|
280
335
|
// await writeFile(
|
|
281
336
|
// path.join(outputcashe, "index.html"),
|
|
@@ -284,15 +339,23 @@ const runBuild = async (options) => {
|
|
|
284
339
|
for await (const [template, name] of Object.entries(templates)) {
|
|
285
340
|
await writeFile(path.join(outputcashe, `${name}.html`), template);
|
|
286
341
|
}
|
|
287
|
-
if (
|
|
288
|
-
task.next(`
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}
|
|
293
|
-
await writeFile(path.join(outputcashe, `test_${page.id}.html`), normalizeHtmlWhitespace(page.test));
|
|
342
|
+
if (customComponents.length) {
|
|
343
|
+
task.next(`Custom`);
|
|
344
|
+
await mkdir(path.join(outputcashe, "custom"), { recursive: true });
|
|
345
|
+
for await (const component of customComponents) {
|
|
346
|
+
await writeFile(path.join(outputcashe, "custom", `${component.name}.html`), component.html);
|
|
347
|
+
await writeFile(path.join(outputcashe, "custom", `${component.name}.json`), component.props);
|
|
294
348
|
}
|
|
295
349
|
}
|
|
350
|
+
// if (config.test) {
|
|
351
|
+
// task.next(`Tests`)
|
|
352
|
+
// for await (const page of pages) {
|
|
353
|
+
// if (!page.test) {
|
|
354
|
+
// continue
|
|
355
|
+
// }
|
|
356
|
+
// await writeFile(path.join(outputcashe, `test_${page.id}.html`), normalizeHtmlWhitespace(page.test))
|
|
357
|
+
// }
|
|
358
|
+
// }
|
|
296
359
|
task.success();
|
|
297
360
|
};
|
|
298
361
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export type { ServerKey } from "./src/front/server-state/useServerState";
|
|
2
2
|
export { useServerState } from "./src/front/server-state/useServerState";
|
|
3
|
-
export {
|
|
3
|
+
export { orig, original } from "./src/front/server-state/orig";
|
|
4
4
|
export { useParamsIndex } from "./src/front/url/params/useParamsIndex";
|
|
5
5
|
export { useSearchValue, useSearchArray } from "./src/front/url/search/useSearchValue";
|
|
6
6
|
export { useSearch } from "./src/front/url/search/useSearch";
|
|
7
7
|
export { Custom } from "./src/front/wrapper/Custom";
|
|
8
8
|
export { stringifyInput } from "./src/front/server-state/SSR";
|
|
9
|
+
export { useIsServer } from "./src/front/server/useIsServer";
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { useServerState } from './src/front/server-state/useServerState.js';
|
|
2
|
-
export {
|
|
2
|
+
export { orig, original } from './src/front/server-state/orig.js';
|
|
3
3
|
export { useParamsIndex } from './src/front/url/params/useParamsIndex.js';
|
|
4
4
|
export { useSearchArray, useSearchValue } from './src/front/url/search/useSearchValue.js';
|
|
5
5
|
export { useSearch } from './src/front/url/search/useSearch.js';
|
|
6
6
|
export { Custom } from './src/front/wrapper/Custom.js';
|
|
7
7
|
export { stringifyInput } from './src/front/server-state/SSR.js';
|
|
8
|
+
export { useIsServer } from './src/front/server/useIsServer.js';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Page } from "playwright";
|
|
2
2
|
import { ServerStateMap } from "../../front/server-state/useServerState";
|
|
3
|
+
import { DefaultLangType } from "../../front/translate/TranslateConfig";
|
|
3
4
|
export declare const pageCollector: (page: Page) => Promise<{
|
|
4
5
|
state: ServerStateMap;
|
|
5
6
|
root: string;
|
|
7
|
+
lang: DefaultLangType;
|
|
6
8
|
}>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ServerValue } from "../../front/server-state/serverStates";
|
|
2
|
+
import { DefaultLangType } from "../../front/translate/TranslateConfig";
|
|
2
3
|
export interface PageData {
|
|
3
4
|
id: number;
|
|
4
5
|
mask: string;
|
|
@@ -6,4 +7,8 @@ export interface PageData {
|
|
|
6
7
|
state: Record<string, ServerValue>;
|
|
7
8
|
test?: string;
|
|
8
9
|
}
|
|
9
|
-
export
|
|
10
|
+
export interface Pages {
|
|
11
|
+
pages: PageData[];
|
|
12
|
+
lang?: DefaultLangType;
|
|
13
|
+
}
|
|
14
|
+
export declare const getRawPageData: (url: string, pages: string[], test?: boolean, debug?: boolean) => Promise<Pages>;
|
|
@@ -7,7 +7,7 @@ interface ParserOptions {
|
|
|
7
7
|
templates?: boolean;
|
|
8
8
|
normalize?: boolean;
|
|
9
9
|
}
|
|
10
|
-
export type Element = ArrayElement | HtmlElement | ValueElement | CustomElement;
|
|
10
|
+
export type Element = ArrayElement | HtmlElement | ValueElement | CustomElement | TranslateText | TValueElement;
|
|
11
11
|
interface ArrayElement {
|
|
12
12
|
type: "array";
|
|
13
13
|
key: string;
|
|
@@ -21,24 +21,42 @@ interface ValueElement {
|
|
|
21
21
|
type: "value";
|
|
22
22
|
key: string;
|
|
23
23
|
}
|
|
24
|
+
interface TValueElement {
|
|
25
|
+
type: "tvalue";
|
|
26
|
+
value: string;
|
|
27
|
+
}
|
|
28
|
+
interface TranslateText {
|
|
29
|
+
type: "t";
|
|
30
|
+
text: string;
|
|
31
|
+
}
|
|
24
32
|
interface CustomElement {
|
|
25
33
|
type: "custom";
|
|
26
34
|
name: string;
|
|
27
35
|
props: object;
|
|
28
36
|
}
|
|
37
|
+
export interface CustomExample {
|
|
38
|
+
name: string;
|
|
39
|
+
html: string;
|
|
40
|
+
props: any;
|
|
41
|
+
}
|
|
29
42
|
export declare class Parser {
|
|
30
43
|
options?: ParserOptions;
|
|
31
44
|
openVar: string;
|
|
32
45
|
createVar: string;
|
|
46
|
+
openTVar: string;
|
|
47
|
+
createTVar: string;
|
|
33
48
|
createArray: string;
|
|
34
49
|
createCustom: string;
|
|
35
50
|
deepUp: string;
|
|
36
51
|
deepUp2: string;
|
|
37
52
|
templates: Record<string, string>;
|
|
53
|
+
custom: CustomExample[];
|
|
38
54
|
constructor(options?: ParserOptions);
|
|
39
55
|
parse(content: string): Element[];
|
|
40
56
|
handle(content: string, tree: Element[]): void;
|
|
41
57
|
createCustomElement(parent: Element[], value: string): void;
|
|
58
|
+
createVarible(parent: Element[], value: string): number;
|
|
59
|
+
createTranslate(parent: Element[], value: string): number;
|
|
42
60
|
createElement(parent: Element[], value: string, isVarible?: boolean): number;
|
|
43
61
|
createTemplate(html: string): string;
|
|
44
62
|
}
|
|
@@ -10,5 +10,6 @@ interface Route {
|
|
|
10
10
|
export declare const getRoutesAndTemplates: (pages: PageData[], normalize?: boolean, templates?: boolean) => {
|
|
11
11
|
routes: Route[];
|
|
12
12
|
templates: Record<string, string>;
|
|
13
|
+
customComponents: import("./Parser").CustomExample[];
|
|
13
14
|
};
|
|
14
15
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useIsServer: () => boolean;
|
|
@@ -135,6 +135,9 @@ function createDataProxy(data, path = "") {
|
|
|
135
135
|
// ---------------------------
|
|
136
136
|
// 8. Nested object
|
|
137
137
|
// ---------------------------
|
|
138
|
+
if (data === null) {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
138
141
|
const value = data[prop];
|
|
139
142
|
if (!ssr.exportParams) {
|
|
140
143
|
return value;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { JinraiAgent } from '../../bin/agent/agent.js';
|
|
1
|
+
import { ViteAgent, JinraiAgent } from '../../bin/agent/agent.js';
|
|
2
2
|
|
|
3
3
|
const ssr = {
|
|
4
4
|
current: navigator.userAgent == JinraiAgent,
|
|
5
|
+
// current: true,
|
|
6
|
+
test: navigator.userAgent == ViteAgent,
|
|
5
7
|
exportParams: true,
|
|
6
8
|
exportToJV: false,
|
|
7
9
|
};
|
|
@@ -2,7 +2,7 @@ import { ssr } from './SSR.js';
|
|
|
2
2
|
import { sources } from './DataProxy.js';
|
|
3
3
|
import { getJinraiValue } from '../url/search/useSearchValue.js';
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function orig(value) {
|
|
6
6
|
if (!ssr.current)
|
|
7
7
|
return value;
|
|
8
8
|
switch (typeof value) {
|
|
@@ -25,6 +25,7 @@ function real(value) {
|
|
|
25
25
|
return value;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
const original = orig;
|
|
28
29
|
const wrapSource = (value, source) => {
|
|
29
30
|
if (typeof value == "string") {
|
|
30
31
|
return value.bindSource(source);
|
|
@@ -44,4 +45,4 @@ const getArrayByPath = (path) => {
|
|
|
44
45
|
return link;
|
|
45
46
|
};
|
|
46
47
|
|
|
47
|
-
export {
|
|
48
|
+
export { orig, original };
|
|
@@ -14,6 +14,7 @@ export type ServerValue = {
|
|
|
14
14
|
key: ServerKey;
|
|
15
15
|
};
|
|
16
16
|
export declare const serverStates: Map<string, ServerValue>;
|
|
17
|
+
export declare const getIdent: (key: ServerKey) => string;
|
|
17
18
|
export declare const getServerValue: (key?: ServerKey, def?: ServerValue["value"], options?: ServerValue["options"]) => any[];
|
|
18
19
|
export declare const setServerValue: (key: ServerKey, value: ServerValue["value"], options?: ServerValue["options"]) => any;
|
|
19
20
|
export {};
|
|
@@ -26,11 +26,15 @@ const getServerValue = (key, def, options) => {
|
|
|
26
26
|
}
|
|
27
27
|
const ident = getIdent(key);
|
|
28
28
|
serverStates.set(ident, { options, value: !options?.source ? def : undefined, key });
|
|
29
|
+
console.log("CHECK", ident);
|
|
29
30
|
if (ident in initialState) {
|
|
30
31
|
const result = initialState[ident];
|
|
31
32
|
// delete initialState[ident]
|
|
32
33
|
console.log("HAS", ident, result);
|
|
33
|
-
|
|
34
|
+
if (result != null && typeof result == 'object' && "data" in result) {
|
|
35
|
+
return [result.data, true];
|
|
36
|
+
}
|
|
37
|
+
return [result, true];
|
|
34
38
|
}
|
|
35
39
|
return [def, false];
|
|
36
40
|
};
|
|
@@ -40,4 +44,4 @@ const setServerValue = (key, value, options) => {
|
|
|
40
44
|
return createDataProxy(value, `${ident}@`);
|
|
41
45
|
};
|
|
42
46
|
|
|
43
|
-
export { getServerValue, serverStates, setServerValue };
|
|
47
|
+
export { getIdent, getServerValue, serverStates, setServerValue };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getIdent } from './serverStates.js';
|
|
2
|
+
import { ssr } from './SSR.js';
|
|
3
|
+
|
|
4
|
+
const test_states = new Map();
|
|
5
|
+
if (window != undefined && ssr.test) {
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
window.$testStates = test_states;
|
|
8
|
+
}
|
|
9
|
+
const setTestState = (key, value, options) => {
|
|
10
|
+
const ident = getIdent(key);
|
|
11
|
+
test_states.set(ident, value);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { setTestState };
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import { useState
|
|
1
|
+
import { useState } from 'react';
|
|
2
2
|
import { ssr } from './SSR.js';
|
|
3
3
|
import { getServerValue, setServerValue } from './serverStates.js';
|
|
4
|
+
import { setTestState } from './testState.js';
|
|
4
5
|
|
|
5
6
|
const useServerState = (serverKey, initialValue, options) => {
|
|
6
7
|
const [serverValue, isInitOnServer] = getServerValue(serverKey, initialValue, options);
|
|
7
8
|
const [value, setStateValue] = useState(serverValue);
|
|
8
|
-
useRef(isInitOnServer);
|
|
9
9
|
const setValue = (value) => {
|
|
10
10
|
setStateValue((prev) => {
|
|
11
11
|
const result = value instanceof Function ? value(prev) : value;
|
|
12
12
|
if (serverKey != undefined && ssr.current) {
|
|
13
13
|
return setServerValue(serverKey, result, options);
|
|
14
14
|
}
|
|
15
|
+
if (serverKey != undefined && ssr.test) {
|
|
16
|
+
setTestState(serverKey, result);
|
|
17
|
+
}
|
|
15
18
|
return result;
|
|
16
19
|
});
|
|
17
20
|
};
|
|
18
|
-
// const initOnServer = () => {
|
|
19
|
-
// if (isInit.current) {
|
|
20
|
-
// isInit.current = false
|
|
21
|
-
// return true
|
|
22
|
-
// }
|
|
23
|
-
// return false
|
|
24
|
-
// }
|
|
25
21
|
return [value, setValue, isInitOnServer];
|
|
26
22
|
};
|
|
27
23
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type DefaultLangType = {
|
|
3
|
+
defaultLang: string;
|
|
4
|
+
langBaseUrl: string;
|
|
5
|
+
source: TranslateSource;
|
|
6
|
+
};
|
|
7
|
+
interface TranslateContextProps {
|
|
8
|
+
translate: (text: string, context?: string) => string;
|
|
9
|
+
changeLang: (lang: string) => void;
|
|
10
|
+
lang: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const useTranslate: () => TranslateContextProps;
|
|
13
|
+
interface TranslateSource {
|
|
14
|
+
from: "cookie" | "url";
|
|
15
|
+
key: string;
|
|
16
|
+
}
|
|
17
|
+
type TranslateConfigProps = DefaultLangType & {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
};
|
|
20
|
+
export declare const TranslateConfig: ({ children, defaultLang, langBaseUrl, source }: TranslateConfigProps) => import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export {};
|