@valbuild/next 0.13.10 → 0.15.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/src/autoTagJSX.ts DELETED
@@ -1,77 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import jsxRuntime from "react/jsx-runtime";
3
- import jsxRuntimeDev from "react/jsx-dev-runtime";
4
- import React from "react";
5
- import {
6
- vercelStegaSplit,
7
- vercelStegaDecode,
8
- VERCEL_STEGA_REGEX,
9
- } from "@vercel/stega";
10
-
11
- const isIntrinsicElement = (type: any) => {
12
- // TODO: think this is not correct, but good enough for now?
13
- return typeof type === "string";
14
- };
15
-
16
- const addValPathIfFound = (type: any, props: any) => {
17
- const valSources = [];
18
-
19
- if (isIntrinsicElement(type) && props && typeof props === "object") {
20
- for (const [key, value] of Object.entries(props)) {
21
- if (typeof value === "string" && value.match(VERCEL_STEGA_REGEX)) {
22
- const encodedBits = vercelStegaDecode(value);
23
- if (!encodedBits || typeof encodedBits !== "object") continue;
24
- if (
25
- "origin" in encodedBits &&
26
- "data" in encodedBits &&
27
- typeof encodedBits.data === "object" &&
28
- encodedBits.data &&
29
- "valPath" in encodedBits.data
30
- ) {
31
- const valPath = encodedBits?.data?.valPath;
32
- if (valPath) {
33
- console.log("Found encoded valPath", valPath);
34
- valSources.push(valPath);
35
- props[key] = vercelStegaSplit(value).cleaned;
36
- }
37
- }
38
- }
39
- }
40
-
41
- if (valSources.length > 0) {
42
- props["data-val-path"] = valSources.join(",");
43
- }
44
- }
45
- };
46
-
47
- function WrapJsx<T>(jsx: T): T {
48
- if (typeof jsx !== "function") return jsx;
49
-
50
- return function (type: any, props: any, ...rest: any[]) {
51
- addValPathIfFound(type, props);
52
- return jsx.call(jsx, type, props, ...rest);
53
- } as any as T;
54
- }
55
-
56
- interface JsxRuntimeModule {
57
- jsx?(type: any, ...rest: any[]): unknown;
58
- jsxs?(type: any, ...rest: any[]): unknown;
59
- jsxDEV?(type: any, ...rest: any[]): unknown;
60
- }
61
- const JsxPro: JsxRuntimeModule = jsxRuntime;
62
- const JsxDev: JsxRuntimeModule = jsxRuntimeDev;
63
-
64
- /**
65
- * createElement _may_ be called by jsx runtime as a fallback in certain cases,
66
- * so we need to wrap it regardless.
67
- *
68
- * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't
69
- * include both, so one of them will be set with `undefined` values.
70
- */
71
- React.createElement = WrapJsx(React.createElement);
72
- JsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));
73
- JsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));
74
- JsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));
75
- JsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));
76
- JsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));
77
- JsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));
package/src/fetchVal.ts DELETED
@@ -1,16 +0,0 @@
1
- import { SelectorSource, SelectorOf, GenericSelector } from "@valbuild/core";
2
- import { stegaEncodeVal, StegaOfSource } from "./stegaEncode";
3
- import { Internal } from "@valbuild/core";
4
-
5
- export function fetchVal<T extends SelectorSource>(
6
- selector: T,
7
- locale?: string
8
- ): SelectorOf<T> extends GenericSelector<infer S>
9
- ? Promise<StegaOfSource<S>>
10
- : never {
11
- return Internal.fetchVal(selector, locale).then((val) =>
12
- stegaEncodeVal(val)
13
- ) as SelectorOf<T> extends GenericSelector<infer S>
14
- ? Promise<StegaOfSource<S>>
15
- : never;
16
- }
@@ -1,14 +0,0 @@
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
- }
@@ -1,76 +0,0 @@
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
- }