@valbuild/next 0.13.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/.babelrc.json +10 -0
- package/CHANGELOG.md +0 -0
- package/README.md +503 -0
- package/dist/declarations/src/ValRichText.d.ts +5 -0
- package/dist/declarations/src/autoTagJSX.d.ts +1 -0
- package/dist/declarations/src/fetchVal.d.ts +3 -0
- package/dist/declarations/src/hooks/useVal.d.ts +3 -0
- package/dist/declarations/src/index.d.ts +7 -0
- package/dist/declarations/src/stegaEncode.d.ts +24 -0
- package/dist/valbuild-next.cjs.d.ts +2 -0
- package/dist/valbuild-next.cjs.d.ts.map +1 -0
- package/dist/valbuild-next.cjs.dev.js +394 -0
- package/dist/valbuild-next.cjs.js +7 -0
- package/dist/valbuild-next.cjs.prod.js +394 -0
- package/dist/valbuild-next.esm.js +373 -0
- package/jest.config.js +4 -0
- package/package.json +46 -0
- package/src/ValRichText.tsx +179 -0
- package/src/autoTagJSX.ts +77 -0
- package/src/fetchVal.ts +16 -0
- package/src/hooks/useVal.ts +14 -0
- package/src/index.ts +8 -0
- package/src/stegaEncode.ts +76 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GenericSelector, SelectorOf, SelectorSource } from "@valbuild/core";
|
|
2
|
+
import { useVal as useReactVal } from "@valbuild/react";
|
|
3
|
+
import { stegaEncodeVal, StegaOfSource } from "../stegaEncode";
|
|
4
|
+
|
|
5
|
+
export function useVal<T extends SelectorSource>(
|
|
6
|
+
selector: T,
|
|
7
|
+
locale?: string
|
|
8
|
+
): SelectorOf<T> extends GenericSelector<infer S> ? StegaOfSource<S> : never {
|
|
9
|
+
return stegaEncodeVal(
|
|
10
|
+
useReactVal(selector, locale)
|
|
11
|
+
) as SelectorOf<T> extends GenericSelector<infer S>
|
|
12
|
+
? StegaOfSource<S>
|
|
13
|
+
: never;
|
|
14
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "./autoTagJSX";
|
|
2
|
+
|
|
3
|
+
export { ValProvider } from "@valbuild/react";
|
|
4
|
+
export { useVal } from "./hooks/useVal";
|
|
5
|
+
export { type ValEncodedString } from "./stegaEncode";
|
|
6
|
+
export * from "@valbuild/core";
|
|
7
|
+
export { fetchVal } from "./fetchVal";
|
|
8
|
+
export { ValRichText } from "./ValRichText";
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Json, Val, Internal, RichTextSource, RichText } from "@valbuild/core";
|
|
2
|
+
import { vercelStegaCombine } from "@vercel/stega";
|
|
3
|
+
import { FileSource, RemoteSource, Source, SourceObject } from "@valbuild/core";
|
|
4
|
+
import { JsonPrimitive } from "@valbuild/core/src/Json";
|
|
5
|
+
import { SourceArray } from "@valbuild/core/src/source";
|
|
6
|
+
import { I18nSource } from "@valbuild/core/src/source/i18n";
|
|
7
|
+
|
|
8
|
+
declare const brand: unique symbol;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* ValEncodedString is a string that is encoded using steganography.
|
|
12
|
+
*
|
|
13
|
+
* This means that there is a hidden / non-visible object embedded in the string.
|
|
14
|
+
* This object includes a path, which is used to automatically tag
|
|
15
|
+
* where the content comes from for contextual editing.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
export type ValEncodedString = string & {
|
|
19
|
+
[brand]: "ValEncodedString";
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type StegaOfSource<T extends Source> = Json extends T
|
|
23
|
+
? Json
|
|
24
|
+
: T extends I18nSource<readonly string[], infer U>
|
|
25
|
+
? StegaOfSource<U>
|
|
26
|
+
: T extends RemoteSource<infer U>
|
|
27
|
+
? StegaOfSource<U>
|
|
28
|
+
: T extends RichTextSource
|
|
29
|
+
? RichText
|
|
30
|
+
: T extends FileSource
|
|
31
|
+
? { url: ValEncodedString }
|
|
32
|
+
: T extends SourceObject
|
|
33
|
+
? {
|
|
34
|
+
[key in keyof T]: StegaOfSource<T[key]>;
|
|
35
|
+
}
|
|
36
|
+
: T extends SourceArray
|
|
37
|
+
? StegaOfSource<T[number]>[]
|
|
38
|
+
: T extends string
|
|
39
|
+
? ValEncodedString
|
|
40
|
+
: T extends JsonPrimitive
|
|
41
|
+
? T
|
|
42
|
+
: never;
|
|
43
|
+
|
|
44
|
+
export function stegaEncodeVal<T extends Json>(val: Val<T>): T {
|
|
45
|
+
if (typeof val.val === "object") {
|
|
46
|
+
if (Array.isArray(val)) {
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
return val.map(stegaEncodeVal) as any;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (
|
|
52
|
+
typeof val.val === "object" &&
|
|
53
|
+
val.val &&
|
|
54
|
+
"_type" in val.val &&
|
|
55
|
+
val.val["_type"] === "richtext"
|
|
56
|
+
) {
|
|
57
|
+
return {
|
|
58
|
+
...val.val,
|
|
59
|
+
valPath: Internal.getValPath(val),
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
+
} as any;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return Object.fromEntries(
|
|
65
|
+
Object.entries(val).map(([key, value]) => [key, stegaEncodeVal(value)])
|
|
66
|
+
) as T;
|
|
67
|
+
}
|
|
68
|
+
if (typeof val.val === "string") {
|
|
69
|
+
return vercelStegaCombine(val.val, {
|
|
70
|
+
origin: "app.val.build",
|
|
71
|
+
data: { valPath: Internal.getValPath(val) },
|
|
72
|
+
}) as T; // TODO: skip should false at least for URLs? Dates...?
|
|
73
|
+
}
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
return val.val as any;
|
|
76
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"esModuleInterop": true,
|
|
4
|
+
"strict": true,
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"isolatedModules": true,
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"lib": ["es6", "dom"],
|
|
9
|
+
"module": "CommonJS",
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"target": "ES5",
|
|
12
|
+
"outDir": "dist",
|
|
13
|
+
"rootDir": "src"
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*"],
|
|
16
|
+
"exclude": ["dist/**"]
|
|
17
|
+
}
|