jinrai 1.1.2 → 1.1.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.
Files changed (55) hide show
  1. package/index.ts +2 -0
  2. package/lib/bin/bin.js +8 -7
  3. package/lib/index.d.ts +1 -0
  4. package/lib/index.js +1 -0
  5. package/lib/src/bin/agent/agent.d.ts +1 -0
  6. package/lib/src/bin/agent/agent.js +3 -0
  7. package/lib/src/bin/routes/Parser.d.ts +6 -1
  8. package/lib/src/bin/routes/Parser.js +5 -0
  9. package/lib/src/front/server-state/DataProxy.d.ts +2 -1
  10. package/lib/src/front/server-state/DataProxy.js +119 -60
  11. package/lib/src/front/server-state/SSR.d.ts +2 -0
  12. package/lib/src/front/server-state/SSR.js +16 -3
  13. package/lib/src/front/server-state/real.js +15 -1
  14. package/lib/src/front/server-state/serverStates.d.ts +2 -1
  15. package/lib/src/front/server-state/serverStates.js +19 -16
  16. package/lib/src/front/server-state/useServerState.d.ts +1 -1
  17. package/lib/src/front/server-state/useServerState.js +10 -10
  18. package/lib/src/front/url/params/useParamsIndex.js +2 -1
  19. package/lib/src/front/url/search/useSearch.js +2 -1
  20. package/lib/src/front/url/search/useSearchValue.d.ts +11 -5
  21. package/lib/src/front/url/search/useSearchValue.js +13 -8
  22. package/lib/src/front/wrapper/Custom.d.ts +3 -3
  23. package/lib/src/front/wrapper/Custom.js +14 -1
  24. package/lib/vite/plugin.js +15 -149
  25. package/package.json +5 -1
  26. package/src/bin/agent/agent.ts +1 -0
  27. package/src/bin/playwright/pageCollector.ts +0 -2
  28. package/src/bin/playwright/templates.ts +2 -1
  29. package/src/bin/routes/Parser.ts +12 -5
  30. package/src/front/server-state/DataProxy.ts +136 -61
  31. package/src/front/server-state/SSR.ts +18 -2
  32. package/src/front/server-state/real.ts +16 -1
  33. package/src/front/server-state/serverStates.ts +26 -17
  34. package/src/front/server-state/useServerState.ts +10 -10
  35. package/src/front/url/search/useSearch.ts +1 -1
  36. package/src/front/url/search/useSearchValue.ts +25 -13
  37. package/src/front/wrapper/Custom.tsx +20 -4
  38. package/tests/data-proxy/create-dataproxy.test.ts +116 -0
  39. package/tests/{custom.test.ts → parse/custom.test.ts} +2 -2
  40. package/tests/{parse.test.ts → parse/parse.test.ts} +7 -7
  41. package/vite/plugin.ts +21 -15
  42. /package/tests/{content → parse/content}/1.html +0 -0
  43. /package/tests/{content → parse/content}/1_result.json +0 -0
  44. /package/tests/{content → parse/content}/2.html +0 -0
  45. /package/tests/{content → parse/content}/2_result.json +0 -0
  46. /package/tests/{content → parse/content}/3.html +0 -0
  47. /package/tests/{content → parse/content}/3_result.json +0 -0
  48. /package/tests/{content → parse/content}/4.html +0 -0
  49. /package/tests/{content → parse/content}/4_result.json +0 -0
  50. /package/tests/{content → parse/content}/custom.html +0 -0
  51. /package/tests/{content → parse/content}/custom.json +0 -0
  52. /package/tests/{content → parse/content}/index.html +0 -0
  53. /package/tests/{content → parse/content}/index.json +0 -0
  54. /package/tests/{content → parse/content}/index_with_templates.json +0 -0
  55. /package/tests/{content → parse/content}/templates.json +0 -0
package/index.ts CHANGED
@@ -6,3 +6,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
+
10
+ export { stringifyInput } from "./src/front/server-state/SSR"
package/lib/bin/bin.js CHANGED
@@ -28,6 +28,7 @@ const normalizeHtmlWhitespace = (html) => {
28
28
  .trim();
29
29
  };
30
30
 
31
+ const SPLIT = "@#UNIQ_SPLITTER#@";
31
32
  class Parser {
32
33
  options;
33
34
  openVar = "{{";
@@ -95,12 +96,12 @@ class Parser {
95
96
  }
96
97
  }
97
98
  createCustomElement(parent, value) {
98
- const [name, ...props] = value.trimStart().split("|");
99
- value = props.join("|");
99
+ const [customProps, exampleProps, children] = value.split(SPLIT);
100
+ const custom = JSON.parse(customProps);
100
101
  parent.push({
101
102
  type: "custom",
102
- name,
103
- props: value,
103
+ name: custom.name,
104
+ props: custom.props,
104
105
  });
105
106
  }
106
107
  createElement(parent, value, isVarible) {
@@ -195,14 +196,14 @@ class Task {
195
196
  const pageCollector = async (page) => {
196
197
  const state = await page.evaluate(() => {
197
198
  const state = Object.fromEntries(window.$exportServerStates);
198
- console.log("BROWSER", state);
199
199
  return state;
200
200
  });
201
- console.log("CLIENT", state);
202
201
  const root = await page.locator("#root").innerHTML();
203
202
  return { root, state };
204
203
  };
205
204
 
205
+ const JinraiAgent = "____JINRAI_AGENT____";
206
+
206
207
  const getRawPageData = async (url, pages, test = false, debug = false) => {
207
208
  const task = new Task();
208
209
  task.next("Router analysis", "yellow", spinners.dotsCircle);
@@ -210,7 +211,7 @@ const getRawPageData = async (url, pages, test = false, debug = false) => {
210
211
  const browser = await chromium.launch({ headless: !debug, devtools: true, channel: "chrome" });
211
212
  // const test_browser = await chromium.launch({ headless: true, channel: "chrome" })
212
213
  const context = await browser.newContext({
213
- userAgent: "____JINRAI_CLIENT____",
214
+ userAgent: JinraiAgent,
214
215
  locale: "ru-RU",
215
216
  });
216
217
  for await (const [id, mask] of pages.entries()) {
package/lib/index.d.ts CHANGED
@@ -5,3 +5,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
+ export { stringifyInput } from "./src/front/server-state/SSR";
package/lib/index.js CHANGED
@@ -4,3 +4,4 @@ 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
+ export { stringifyInput } from './src/front/server-state/SSR.js';
@@ -0,0 +1 @@
1
+ export declare const JinraiAgent = "____JINRAI_AGENT____";
@@ -0,0 +1,3 @@
1
+ const JinraiAgent = "____JINRAI_AGENT____";
2
+
3
+ export { JinraiAgent };
@@ -1,3 +1,8 @@
1
+ export declare const SPLIT = "@#UNIQ_SPLITTER#@";
2
+ interface CustomElement {
3
+ name: string;
4
+ props: object;
5
+ }
1
6
  interface ParserOptions {
2
7
  templates?: boolean;
3
8
  normalize?: boolean;
@@ -19,7 +24,7 @@ interface ValueElement {
19
24
  interface CustomElement {
20
25
  type: "custom";
21
26
  name: string;
22
- props: string;
27
+ props: object;
23
28
  }
24
29
  export declare class Parser {
25
30
  options?: ParserOptions;
@@ -0,0 +1,5 @@
1
+ import 'node:crypto';
2
+
3
+ const SPLIT = "@#UNIQ_SPLITTER#@";
4
+
5
+ export { SPLIT };
@@ -4,5 +4,6 @@ export interface DataProxy {
4
4
  getValue: () => any;
5
5
  }
6
6
  export declare const sources: Map<string, any>;
7
- declare const createDataProxy: (data: any, path?: string) => DataProxy;
7
+ type WithDataProxy<T> = T & DataProxy;
8
+ declare function createDataProxy<T>(data: T, path?: string): WithDataProxy<T>;
8
9
  export default createDataProxy;
@@ -13,92 +13,151 @@ const getTarget = (data, path) => {
13
13
  case "undefined":
14
14
  case "symbol":
15
15
  // эти типы можно просто завернуть
16
- return { value: data };
16
+ return { $__ROOT__: data };
17
17
  default:
18
18
  return () => `{{${path}}}`;
19
19
  }
20
20
  };
21
- const createDataProxy = (data, path = "") => {
21
+ function createDataProxy(data, path = "") {
22
22
  if (path.endsWith("@"))
23
23
  sources.set(path.slice(0, -1), data);
24
24
  return new Proxy(getTarget(data, path), {
25
- get: (_, prop) => {
26
- // if (typeof prop == "symbol") return data[prop]
27
- if (!(typeof data == "object" && data !== null && prop in data))
28
- // DEV TOOLS
25
+ get: (_target, prop) => {
26
+ if (ssr.exportToJV) {
27
+ return {
28
+ $JV: {
29
+ key: path + "/" + String(prop),
30
+ type: "proxy",
31
+ def: data,
32
+ },
33
+ };
34
+ }
35
+ // ---------------------------
36
+ // 1. Обработка символов
37
+ // ---------------------------
38
+ if (typeof prop === "symbol") {
29
39
  switch (prop) {
30
- // @ts-ignore
31
40
  case Symbol.toPrimitive:
32
41
  return (hint) => {
33
42
  console.log("PROXYDATA", hint);
34
43
  return `{{${path}}}`;
35
44
  };
36
- // @ts-ignore
37
45
  case Symbol.toStringTag:
38
46
  return "Object";
39
- // @ts-ignore
40
47
  case Symbol.iterator:
41
- return data[Symbol.iterator];
42
- case "$$typeof":
43
- case "type":
48
+ if (typeof data === "object" && data !== null && Symbol.iterator in data) {
49
+ return data[Symbol.iterator];
50
+ }
44
51
  return undefined;
45
- case "_debugInfo":
46
- return {
47
- note: `State From Request (${path})`,
48
- kind: typeof data,
49
- timestamp: Date.now(),
50
- preview: data,
51
- };
52
52
  }
53
- // SELF
54
- if (prop.startsWith("$"))
53
+ }
54
+ // ---------------------------
55
+ // 2. DEV tools
56
+ // ---------------------------
57
+ if (!(typeof data === "object" && data !== null && prop in data)) {
58
+ if (prop === "$$typeof" || prop === "type") {
59
+ return undefined;
60
+ }
61
+ if (prop === "_debugInfo") {
62
+ return {
63
+ note: `State From Request (${path})`,
64
+ kind: typeof data,
65
+ timestamp: Date.now(),
66
+ preview: data,
67
+ };
68
+ }
69
+ }
70
+ // ---------------------------
71
+ // 3. SELF: $key → returns function
72
+ // ---------------------------
73
+ if (typeof prop === "string" && prop.startsWith("$")) {
55
74
  return (key) => `{{${path + "/" + key}${"\\" + prop}}}`;
56
- // TYPES
75
+ }
76
+ // ---------------------------
77
+ // 4. Types special cases
78
+ // ---------------------------
57
79
  switch (typeof data) {
58
80
  case "string":
59
- switch (prop) {
60
- case "length":
61
- case "entries":
62
- return undefined;
63
- }
81
+ if (prop === "length" || prop === "entries")
82
+ return undefined;
83
+ break;
64
84
  case "number":
65
- switch (prop) {
66
- case "@@iterator":
67
- return undefined;
68
- }
85
+ if (prop === "@@iterator")
86
+ return undefined;
87
+ break;
69
88
  default:
70
- switch (prop) {
71
- case "then":
72
- return undefined;
73
- }
89
+ if (prop === "then")
90
+ return undefined;
74
91
  }
75
- // OTHER
76
- switch (prop) {
77
- case "find":
78
- return data[prop];
79
- case "map":
80
- case "forEach":
81
- return (callback) => React.createElement("loopwrapper", null, [
82
- `ArrayDataKey=${path}|`,
83
- Object.entries(data)
84
- .slice(0, 1)
85
- .map(([key, itm]) => callback(createDataProxy(itm, `${path}/[ITEM=${key}]`))),
86
- ]);
87
- case "getValue":
88
- return () => data;
89
- case "toJSON":
90
- return () => {
91
- console.log("dataproxy toJSON", path, data);
92
- return ssr.exportParams ? `{{${path}}}` : data;
93
- };
94
- default:
95
- if (data && (typeof data[prop] == "object" || Array.isArray(data[prop]))) {
96
- return createDataProxy(data[prop], path + "/" + prop);
97
- }
98
- return `{{${path + "/" + prop}}}`;
92
+ // ---------------------------
93
+ // 5. Array-like handlers
94
+ // ---------------------------
95
+ if (prop === "find") {
96
+ return data[prop];
97
+ }
98
+ if (prop === "length") {
99
+ if (Array.isArray(data)) {
100
+ return data.length;
101
+ }
102
+ }
103
+ if (prop === "map" || prop === "forEach") {
104
+ return (callback) => React.createElement("loopwrapper", null, [
105
+ `ArrayDataKey=${path}|`,
106
+ Object.entries(data)
107
+ .slice(0, 1)
108
+ .map(([key, itm]) => callback(createDataProxy(itm, `${path}/[ITEM=${key}]`))),
109
+ ]);
110
+ }
111
+ // ---------------------------
112
+ // 6. getValue
113
+ // ---------------------------
114
+ if (prop === "getValue") {
115
+ return () => data;
99
116
  }
117
+ // ---------------------------
118
+ // 7. toJSON
119
+ // ---------------------------
120
+ if (prop === "toJSON") {
121
+ return () => {
122
+ console.log("dataproxy toJSON", path, data);
123
+ return ssr.exportParams
124
+ ? `{{${path}}}`
125
+ : {
126
+ $JV: {
127
+ key: path,
128
+ type: "proxy",
129
+ def: data,
130
+ separator: "",
131
+ },
132
+ };
133
+ };
134
+ }
135
+ // ---------------------------
136
+ // 8. Nested object
137
+ // ---------------------------
138
+ const value = data[prop];
139
+ if (!ssr.exportParams) {
140
+ return value;
141
+ }
142
+ if (value && (typeof value === "object" || Array.isArray(value))) {
143
+ return createDataProxy(value, path + "/" + String(prop));
144
+ }
145
+ // if (ssr.exportParams) {
146
+ // if (typeof value == "string") {
147
+ // const key = `{{${path + "/" + String(prop)}}}`
148
+ // const jv = getJinraiValue(key, "proxyValue", "", value)
149
+ // return value.bindSource(jv)
150
+ // }
151
+ // return key
152
+ // } else {
153
+ // return value
154
+ // }
155
+ // ---------------------------
156
+ // 9. Final primitive fallback
157
+ // ---------------------------
158
+ return `{{${path + "/" + String(prop)}}}`;
100
159
  },
101
160
  });
102
- };
161
+ }
103
162
 
104
163
  export { createDataProxy as default, sources };
@@ -1,4 +1,6 @@
1
1
  export declare const ssr: {
2
2
  current: boolean;
3
3
  exportParams: boolean;
4
+ exportToJV: boolean;
4
5
  };
6
+ export declare const stringifyInput: (input: any) => string;
@@ -1,6 +1,19 @@
1
+ import { JinraiAgent } from '../../bin/agent/agent.js';
2
+
1
3
  const ssr = {
2
- current: true, //navigator.userAgent == "____JINRAI_CLIENT____",
3
- exportParams: false,
4
+ current: navigator.userAgent == JinraiAgent,
5
+ exportParams: true,
6
+ exportToJV: false,
7
+ };
8
+ if (window != undefined) {
9
+ // @ts-ignore
10
+ window.__ssr = ssr;
11
+ }
12
+ const stringifyInput = (input) => {
13
+ ssr.exportParams = false;
14
+ const result = JSON.stringify(input);
15
+ ssr.exportParams = true;
16
+ return result;
4
17
  };
5
18
 
6
- export { ssr };
19
+ export { ssr, stringifyInput };
@@ -1,11 +1,19 @@
1
+ import { ssr } from './SSR.js';
1
2
  import { sources } from './DataProxy.js';
3
+ import { getJinraiValue } from '../url/search/useSearchValue.js';
2
4
 
3
5
  function real(value) {
6
+ if (!ssr.current)
7
+ return value;
4
8
  switch (typeof value) {
5
9
  case "number":
6
10
  return value;
7
11
  case "string":
8
- return value.startsWith("{{") && value.endsWith("}}") ? getArrayByPath(value.slice(2, -2)) : value;
12
+ if (value.startsWith("{{") && value.endsWith("}}")) {
13
+ const result = getArrayByPath(value.slice(2, -2));
14
+ return wrapSource(result, getJinraiValue(value, "proxy", "", result));
15
+ }
16
+ return value;
9
17
  case "object":
10
18
  // @ts-ignore
11
19
  if (value && typeof value.getValue === "function") {
@@ -17,6 +25,12 @@ function real(value) {
17
25
  return value;
18
26
  }
19
27
  }
28
+ const wrapSource = (value, source) => {
29
+ if (typeof value == "string") {
30
+ return value.bindSource(source);
31
+ }
32
+ return value;
33
+ };
20
34
  const getArrayByPath = (path) => {
21
35
  const [sourceIndex, requestPath] = path.split("@", 2);
22
36
  const keys = requestPath.split("/");
@@ -11,8 +11,9 @@ export type ServerValue = {
11
11
  request?: Request;
12
12
  };
13
13
  };
14
+ key: ServerKey;
14
15
  };
15
16
  export declare const serverStates: Map<string, ServerValue>;
16
17
  export declare const getServerValue: (key?: ServerKey, def?: ServerValue["value"], options?: ServerValue["options"]) => any[];
17
- export declare const setServerValue: (key: ServerKey, value: ServerValue["value"], options?: ServerValue["options"]) => import("./DataProxy").DataProxy;
18
+ export declare const setServerValue: (key: ServerKey, value: ServerValue["value"], options?: ServerValue["options"]) => any;
18
19
  export {};
@@ -1,7 +1,16 @@
1
- import { encode } from 'js-base64';
2
1
  import createDataProxy from './DataProxy.js';
3
- import { ssr } from './SSR.js';
4
2
 
3
+ // @ts-ignore
4
+ const initialState = { ...(window?.__appc__?.state ?? {}) };
5
+ // @ts-ignore
6
+ const serverErrors = [...(window?.__appc__?.errors ?? [])];
7
+ if (serverErrors.length) {
8
+ console.error("SERVER:", serverErrors);
9
+ }
10
+ if (window != undefined) {
11
+ // @ts-ignore
12
+ delete window.__appc__;
13
+ }
5
14
  const serverStates = new Map();
6
15
  if (window != undefined) {
7
16
  console.log("init $exportServerStates");
@@ -9,31 +18,25 @@ if (window != undefined) {
9
18
  window.$exportServerStates = serverStates;
10
19
  }
11
20
  const getIdent = (key) => {
12
- {
13
- ssr.exportParams = true;
14
- }
15
- const result = Array.isArray(key) ? JSON.stringify(key) : key.toString();
16
- {
17
- ssr.exportParams = false;
18
- }
19
- return encode(result);
21
+ return Array.isArray(key) ? key.join("-") : key;
20
22
  };
21
23
  const getServerValue = (key, def, options) => {
22
24
  if (key == undefined) {
23
25
  return [def, false];
24
26
  }
25
27
  const ident = getIdent(key);
26
- serverStates.set(ident, { options, value: !options?.source ? def : undefined });
27
- // @ts-ignore
28
- if (window != undefined && window?.__serverInitialStates__ && ident in window.__serverInitialStates__) {
29
- // @ts-ignore
30
- return [window.__serverInitialStates__[ident], true];
28
+ serverStates.set(ident, { options, value: !options?.source ? def : undefined, key });
29
+ if (ident in initialState) {
30
+ const result = initialState[ident];
31
+ // delete initialState[ident]
32
+ console.log("HAS", ident, result);
33
+ return ["data" in result ? result.data : result, true];
31
34
  }
32
35
  return [def, false];
33
36
  };
34
37
  const setServerValue = (key, value, options) => {
35
38
  const ident = getIdent(key);
36
- serverStates.set(ident, { options, value: !options?.source ? value : undefined });
39
+ serverStates.set(ident, { options, value: !options?.source ? value : undefined, key });
37
40
  return createDataProxy(value, `${ident}@`);
38
41
  };
39
42
 
@@ -2,4 +2,4 @@ import { Dispatch, SetStateAction } from "react";
2
2
  import { ServerValue } from "./serverStates";
3
3
  export type ServerStateMap = Record<string, ServerValue>;
4
4
  export type ServerKey = string | string[];
5
- export declare const useServerState: <T extends ServerValue["value"]>(serverKey: ServerKey | undefined, initialValue: T, options?: ServerValue["options"]) => [T, Dispatch<SetStateAction<T>>, () => boolean];
5
+ export declare const useServerState: <T extends ServerValue["value"]>(serverKey: ServerKey | undefined, initialValue: T, options?: ServerValue["options"]) => [T, Dispatch<SetStateAction<T>>, boolean];
@@ -1,11 +1,11 @@
1
- import { useState } from 'react';
1
+ import { useState, useRef } from 'react';
2
2
  import { ssr } from './SSR.js';
3
3
  import { getServerValue, setServerValue } from './serverStates.js';
4
4
 
5
5
  const useServerState = (serverKey, initialValue, options) => {
6
6
  const [serverValue, isInitOnServer] = getServerValue(serverKey, initialValue, options);
7
7
  const [value, setStateValue] = useState(serverValue);
8
- const [isInit, setIsInit] = useState(isInitOnServer);
8
+ useRef(isInitOnServer);
9
9
  const setValue = (value) => {
10
10
  setStateValue((prev) => {
11
11
  const result = value instanceof Function ? value(prev) : value;
@@ -15,14 +15,14 @@ const useServerState = (serverKey, initialValue, options) => {
15
15
  return result;
16
16
  });
17
17
  };
18
- const initOnServer = () => {
19
- if (isInit) {
20
- setIsInit(false);
21
- return true;
22
- }
23
- return false;
24
- };
25
- return [value, setValue, initOnServer];
18
+ // const initOnServer = () => {
19
+ // if (isInit.current) {
20
+ // isInit.current = false
21
+ // return true
22
+ // }
23
+ // return false
24
+ // }
25
+ return [value, setValue, isInitOnServer];
26
26
  };
27
27
 
28
28
  export { useServerState };
@@ -1,12 +1,13 @@
1
1
  import { useContext, useMemo } from 'react';
2
2
  import { getJinraiValue } from '../search/useSearchValue.js';
3
3
  import { JinraiContext } from '../JinraiContext.js';
4
+ import { ssr } from '../../server-state/SSR.js';
4
5
 
5
6
  const useParamsIndex = (index, def = "") => {
6
7
  const { deps } = useContext(JinraiContext);
7
8
  const value = useMemo(() => location.pathname.split("/")[index + 1] ?? def, deps ? deps : []);
8
9
  const stableValue = useMemo(() => {
9
- return value.bindSource(getJinraiValue(index.toString(), "paramsIndex", "", def)) ;
10
+ return ssr.current ? value.bindSource(getJinraiValue(index.toString(), "paramsIndex", "", def)) : value;
10
11
  }, [value]);
11
12
  return stableValue;
12
13
  };
@@ -1,12 +1,13 @@
1
1
  import { useContext, useMemo } from 'react';
2
2
  import { JinraiContext } from '../JinraiContext.js';
3
+ import { ssr } from '../../server-state/SSR.js';
3
4
  import { getJinraiValue } from './useSearchValue.js';
4
5
 
5
6
  const useSearch = () => {
6
7
  const { deps } = useContext(JinraiContext);
7
8
  const value = useMemo(() => location.search.substring(1), deps ? deps : []);
8
9
  const stableValue = useMemo(() => {
9
- return value.bindSource(getJinraiValue("", "search", "", "")) ;
10
+ return ssr.current ? value.bindSource(getJinraiValue("", "searchFull", "", "")) : value;
10
11
  }, [value]);
11
12
  return stableValue;
12
13
  };
@@ -1,16 +1,22 @@
1
1
  import { UseQueryStateReturn } from "nuqs";
2
+ export interface JinraiValue {
3
+ key: string;
4
+ type: "searchArray" | "searchString" | "proxy" | "searchFull" | "paramsIndex";
5
+ separator: string;
6
+ def: any;
7
+ }
2
8
  declare global {
3
9
  interface String {
4
- source?: string;
10
+ $JV?: JinraiValue;
5
11
  toJSON: () => string;
6
- bindSource: (source: string) => string;
12
+ bindSource: (source: JinraiValue) => string;
7
13
  }
8
14
  interface Array<T> {
9
- source?: string;
15
+ $JV?: JinraiValue;
10
16
  toJSON(): any;
11
- bindSource(source: string): T[];
17
+ bindSource(source: JinraiValue): T[];
12
18
  }
13
19
  }
14
20
  export declare const useSearchValue: (key: string, defaultValue: string) => UseQueryStateReturn<string, string>;
15
21
  export declare const useSearchArray: (key: string, defaultValue?: string[], separator?: string) => UseQueryStateReturn<string[], string[]>;
16
- export declare const getJinraiValue: (key: string, type: string, separator: string, def: any) => string;
22
+ export declare const getJinraiValue: (key: string, type: JinraiValue["type"], separator: string, def: any) => JinraiValue;
@@ -5,19 +5,19 @@ import { ssr } from '../../server-state/SSR.js';
5
5
  function toJSON() {
6
6
  if (ssr.exportParams) {
7
7
  // @ts-ignore
8
- const source = this.source;
8
+ const $JV = this.$JV;
9
9
  // @ts-ignore
10
- return source ? source : this;
10
+ return $JV ? { $JV } : this;
11
11
  }
12
12
  // @ts-ignore
13
13
  return this;
14
14
  }
15
15
  {
16
- String.prototype.source = undefined;
16
+ String.prototype.$JV = undefined;
17
17
  String.prototype.toJSON = toJSON;
18
18
  String.prototype.bindSource = function (source) {
19
19
  const result = new String(this);
20
- result.source = source;
20
+ result.$JV = source;
21
21
  return result;
22
22
  };
23
23
  if (!Array.prototype.toJSON) {
@@ -25,7 +25,7 @@ function toJSON() {
25
25
  }
26
26
  if (!Array.prototype.bindSource) {
27
27
  Array.prototype.bindSource = function (source) {
28
- this.source = source;
28
+ this.$JV = source;
29
29
  return this;
30
30
  };
31
31
  }
@@ -33,7 +33,7 @@ function toJSON() {
33
33
  const useSearchValue = (key, defaultValue) => {
34
34
  const [value, setValue] = useQueryState(key, { defaultValue });
35
35
  const stableValue = useMemo(() => {
36
- return value.bindSource(getJinraiValue(key, "searchString", "", defaultValue)) ;
36
+ return ssr.current ? value.bindSource(getJinraiValue(key, "searchString", "", defaultValue)) : value;
37
37
  }, [key, value]);
38
38
  return [stableValue, setValue];
39
39
  };
@@ -41,12 +41,17 @@ const useSearchArray = (key, defaultValue = [], separator = ",") => {
41
41
  const stableDefault = useMemo(() => defaultValue, []);
42
42
  const [value, setValue] = useQueryState(key, parseAsArrayOf(parseAsString, separator).withDefault(stableDefault));
43
43
  const stableValue = useMemo(() => {
44
- return value.bindSource(getJinraiValue(key, "searchArray", separator, defaultValue)) ;
44
+ return ssr.current ? value.bindSource(getJinraiValue(key, "searchArray", separator, defaultValue)) : value;
45
45
  }, [key, value]);
46
46
  return [stableValue, setValue];
47
47
  };
48
48
  const getJinraiValue = (key, type, separator, def) => {
49
- return `@JV[[${JSON.stringify({ key, type, separator, def })}]]`;
49
+ return {
50
+ key,
51
+ type,
52
+ separator,
53
+ def,
54
+ };
50
55
  };
51
56
 
52
57
  export { getJinraiValue, useSearchArray, useSearchValue };
@@ -1,8 +1,8 @@
1
- import type { ReactElement, ReactNode } from "react";
1
+ import { type ReactNode } from "react";
2
2
  interface CustomProps {
3
3
  name: string;
4
- props: object;
4
+ props: () => object;
5
5
  children: ReactNode;
6
6
  }
7
- export declare const Custom: ({ name, props, children }: CustomProps) => string | ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
7
+ export declare const Custom: ({ name, props, children }: CustomProps) => import("react/jsx-runtime").JSX.Element;
8
8
  export {};