eddev 0.2.6 → 0.2.9

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.
@@ -31,7 +31,39 @@ var blockAttributes_1 = require("./blockAttributes");
31
31
  var react_1 = require("react");
32
32
  var ErrorBoundaryFrontend_1 = require("./ErrorBoundaryFrontend");
33
33
  exports.BlocksContext = (0, react_1.createContext)(undefined);
34
+ function wrapPromise(promise) {
35
+ var status = "pending";
36
+ var result;
37
+ var suspender = promise.then(function (r) {
38
+ status = "success";
39
+ result = r;
40
+ }, function (e) {
41
+ status = "error";
42
+ result = e;
43
+ });
44
+ return {
45
+ read: function () {
46
+ //console.log(status);
47
+ if (status === "pending") {
48
+ throw suspender;
49
+ }
50
+ else if (status === "error") {
51
+ throw result;
52
+ }
53
+ else if (status === "success") {
54
+ return result;
55
+ }
56
+ },
57
+ };
58
+ }
59
+ var blockManifestResource = null;
34
60
  function ContentBlocks(props) {
61
+ var blockTypes = blocks_1.default;
62
+ if (blocks_1.default.then && process.serverless && !blocks_1.default.default) {
63
+ if (!blockManifestResource)
64
+ blockManifestResource = wrapPromise(blocks_1.default);
65
+ blockTypes = blockManifestResource.read().default;
66
+ }
35
67
  if (process.admin) {
36
68
  throw new Error("ContentBlocks should only be used on the frontend.");
37
69
  }
@@ -44,8 +76,8 @@ function ContentBlocks(props) {
44
76
  var ctx = __assign(__assign({}, parentContext), { ancestors: __spreadArray(__spreadArray([], ((parentContext === null || parentContext === void 0 ? void 0 : parentContext.ancestors) || []), true), [parentContext === null || parentContext === void 0 ? void 0 : parentContext.current], false).filter(Boolean), parent: parentContext === null || parentContext === void 0 ? void 0 : parentContext.current, current: block, prev: props.blocks[index - 1], next: props.blocks[index + 1] });
45
77
  // Figure out the
46
78
  var blockNode;
47
- if (block.blockName in blocks_1.default) {
48
- var Component = blocks_1.default[block.blockName];
79
+ if (block.blockName in blockTypes) {
80
+ var Component = blockTypes[block.blockName];
49
81
  if (!Component)
50
82
  return (0, jsx_runtime_1.jsx)(react_1.Fragment, {}, void 0);
51
83
  blockNode = ((0, jsx_runtime_1.jsx)(blockAttributes_1.InlineEditingContextProvider, __assign({ block: [block.blockName, block.props], values: block.inline, innerBlocks: block.innerBlocks }, { children: (0, jsx_runtime_1.jsx)(Component, __assign({}, block.props, { innerHTML: block.innerHTML,
@@ -32,7 +32,7 @@ var react_1 = require("react");
32
32
  var blockAttributes_1 = require("./blockAttributes");
33
33
  var react_2 = require("@stitches/react");
34
34
  var remoteProps_1 = require("../routing/remoteProps");
35
- var __1 = require("..");
35
+ var routing_1 = require("../routing");
36
36
  function EditableText(_a) {
37
37
  var id = _a.id, as = _a.as, appendOnEnter = _a.appendOnEnter, props = __rest(_a, ["id", "as", "appendOnEnter"]);
38
38
  if (process.admin) {
@@ -48,7 +48,7 @@ function EditableText(_a) {
48
48
  }
49
49
  else {
50
50
  var value = (0, blockAttributes_1.useInlineEditableValue)(id)[0];
51
- var router_1 = (0, __1.useRouter)();
51
+ var router_1 = (0, routing_1.useRouter)();
52
52
  var otherProps = __assign({}, props);
53
53
  delete otherProps.inlineToolbar;
54
54
  delete otherProps.disableLineBreaks;
package/cli/preinstall.js CHANGED
@@ -9,7 +9,7 @@ function main() {
9
9
  // const pkg = JSON.parse(readFileSync(pkgFile).toString()) as any
10
10
  // pkg.devDependencies["next"] = "^12.1.0"
11
11
  // writeFile(pkgFile, JSON.stringify(pkg, null, " "), () => {})
12
- var proc = (0, child_process_1.spawn)("yarn", ["add", "--dev", "next@^12.1.0"], {
12
+ var proc = (0, child_process_1.spawn)("yarn", ["add", "--dev", "next@^12.1.6"], {
13
13
  cwd: process.cwd(),
14
14
  });
15
15
  (_a = proc.stdout) === null || _a === void 0 ? void 0 : _a.pipe(process.stdout);
@@ -68,7 +68,6 @@ function BrowserRouter(props) {
68
68
  setIsLoading(true);
69
69
  }
70
70
  (0, remoteProps_1.fetchProps)(pending.url).then(function (data) {
71
- console.log("FETCHED", data);
72
71
  var view = views_1.default[data.view];
73
72
  var nextUrl = data.canonical || pending.url;
74
73
  var finish = function () {
@@ -15,10 +15,21 @@ exports.NextRouter = void 0;
15
15
  var jsx_runtime_1 = require("react/jsx-runtime");
16
16
  var routing_1 = require("../routing");
17
17
  var router_1 = require("next/router");
18
+ var react_1 = require("react");
19
+ var hooks_1 = require("../hooks");
18
20
  function NextRouter(_a) {
19
21
  var children = _a.children, path = _a.path, data = _a.data;
20
22
  var nextRoute = (0, router_1.useRouter)();
23
+ var setIsLoading = (0, hooks_1.usePageLoad)(function (s) { return s.setIsLoading; });
21
24
  var route = __assign(__assign({}, nextRoute), { pathname: nextRoute.asPath });
25
+ (0, react_1.useEffect)(function () {
26
+ router_1.Router.events.on("routeChangeStart", function () {
27
+ console.log("Loading");
28
+ setIsLoading(true);
29
+ });
30
+ router_1.Router.events.on("routeChangeStart", function () { return setIsLoading(false); });
31
+ router_1.Router.events.on("routeChangeError", function () { return setIsLoading(false); });
32
+ }, []);
22
33
  return ((0, jsx_runtime_1.jsx)(routing_1.RouterRoot, __assign({ url: nextRoute.asPath, data: data, onNavigateRequest: function (url) {
23
34
  route.push(url);
24
35
  // setPendingUrl({ popped: false, url })
@@ -9,9 +9,11 @@ export declare const EDConfigSchema: z.ZodObject<{
9
9
  themeAssets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
10
10
  apiOnly: z.ZodOptional<z.ZodBoolean>;
11
11
  endpoints: z.ZodRecord<z.ZodString, z.ZodString>;
12
+ defaultRevalidate: z.ZodOptional<z.ZodNumber>;
12
13
  }, "strip", z.ZodTypeAny, {
13
14
  themeAssets?: string[] | undefined;
14
15
  apiOnly?: boolean | undefined;
16
+ defaultRevalidate?: number | undefined;
15
17
  enabled: boolean;
16
18
  uploads: "proxy" | "remote";
17
19
  plugins: "proxy" | "remote";
@@ -20,6 +22,7 @@ export declare const EDConfigSchema: z.ZodObject<{
20
22
  }, {
21
23
  themeAssets?: string[] | undefined;
22
24
  apiOnly?: boolean | undefined;
25
+ defaultRevalidate?: number | undefined;
23
26
  enabled: boolean;
24
27
  uploads: "proxy" | "remote";
25
28
  plugins: "proxy" | "remote";
@@ -32,6 +35,7 @@ export declare const EDConfigSchema: z.ZodObject<{
32
35
  serverless?: {
33
36
  themeAssets?: string[] | undefined;
34
37
  apiOnly?: boolean | undefined;
38
+ defaultRevalidate?: number | undefined;
35
39
  enabled: boolean;
36
40
  uploads: "proxy" | "remote";
37
41
  plugins: "proxy" | "remote";
@@ -44,6 +48,7 @@ export declare const EDConfigSchema: z.ZodObject<{
44
48
  serverless?: {
45
49
  themeAssets?: string[] | undefined;
46
50
  apiOnly?: boolean | undefined;
51
+ defaultRevalidate?: number | undefined;
47
52
  enabled: boolean;
48
53
  uploads: "proxy" | "remote";
49
54
  plugins: "proxy" | "remote";
@@ -13,6 +13,7 @@ exports.EDConfigSchema = zod_1.z.object({
13
13
  themeAssets: zod_1.z.array(zod_1.z.string()).optional(),
14
14
  apiOnly: zod_1.z.boolean().optional(),
15
15
  endpoints: zod_1.z.record(zod_1.z.string(), zod_1.z.string()),
16
+ defaultRevalidate: zod_1.z.number().optional(),
16
17
  })
17
18
  .optional(),
18
19
  devUI: zod_1.z.enum(["disabled", "enabled"]),
@@ -3,6 +3,7 @@ export declare function getEDConfig(dir?: string): import("zod").SafeParseReturn
3
3
  serverless?: {
4
4
  themeAssets?: string[] | undefined;
5
5
  apiOnly?: boolean | undefined;
6
+ defaultRevalidate?: number | undefined;
6
7
  enabled: boolean;
7
8
  uploads: "proxy" | "remote";
8
9
  plugins: "proxy" | "remote";
@@ -15,6 +16,7 @@ export declare function getEDConfig(dir?: string): import("zod").SafeParseReturn
15
16
  serverless?: {
16
17
  themeAssets?: string[] | undefined;
17
18
  apiOnly?: boolean | undefined;
19
+ defaultRevalidate?: number | undefined;
18
20
  enabled: boolean;
19
21
  uploads: "proxy" | "remote";
20
22
  plugins: "proxy" | "remote";
@@ -28,6 +30,7 @@ export declare function getEDConfigUnwrapped(dir?: string): {
28
30
  serverless?: {
29
31
  themeAssets?: string[] | undefined;
30
32
  apiOnly?: boolean | undefined;
33
+ defaultRevalidate?: number | undefined;
31
34
  enabled: boolean;
32
35
  uploads: "proxy" | "remote";
33
36
  plugins: "proxy" | "remote";
@@ -3,6 +3,7 @@ export declare function parseConfig(config: any): import("zod").SafeParseReturnT
3
3
  serverless?: {
4
4
  themeAssets?: string[] | undefined;
5
5
  apiOnly?: boolean | undefined;
6
+ defaultRevalidate?: number | undefined;
6
7
  enabled: boolean;
7
8
  uploads: "proxy" | "remote";
8
9
  plugins: "proxy" | "remote";
@@ -15,6 +16,7 @@ export declare function parseConfig(config: any): import("zod").SafeParseReturnT
15
16
  serverless?: {
16
17
  themeAssets?: string[] | undefined;
17
18
  apiOnly?: boolean | undefined;
19
+ defaultRevalidate?: number | undefined;
18
20
  enabled: boolean;
19
21
  uploads: "proxy" | "remote";
20
22
  plugins: "proxy" | "remote";
@@ -6,7 +6,10 @@ declare type GraphQLError = {
6
6
  declare type CreateUseQueryOptions = {
7
7
  name: string;
8
8
  };
9
- declare type QueryOptions = {};
9
+ declare type QueryOptions = {
10
+ revalidateIfStale?: boolean;
11
+ revalidateOnFocus?: boolean;
12
+ };
10
13
  declare type MaybeVars = {
11
14
  [key: string]: any;
12
15
  } | undefined;
@@ -83,9 +83,11 @@ var fetcherGET = function (name, params) { return __awaiter(void 0, void 0, void
83
83
  }); };
84
84
  function createUseQuery(init) {
85
85
  var hook = function (vars, opts) {
86
- var _a = (0, swr_1.default)([init.name, JSON.stringify(vars)], fetcherGET, {
87
- revalidateIfStale: false,
88
- }), payload = _a.data, isValidating = _a.isValidating, error = _a.error, mutate = _a.mutate;
86
+ var _a, _b;
87
+ var _c = (0, swr_1.default)([init.name, JSON.stringify(vars)], fetcherGET, {
88
+ revalidateIfStale: (_a = opts === null || opts === void 0 ? void 0 : opts.revalidateIfStale) !== null && _a !== void 0 ? _a : false,
89
+ revalidateOnFocus: (_b = opts === null || opts === void 0 ? void 0 : opts.revalidateOnFocus) !== null && _b !== void 0 ? _b : false,
90
+ }), payload = _c.data, isValidating = _c.isValidating, error = _c.error, mutate = _c.mutate;
89
91
  return {
90
92
  loading: isValidating && !payload,
91
93
  data: payload === null || payload === void 0 ? void 0 : payload.data,
package/hooks/useRPC.d.ts CHANGED
@@ -1,25 +1,5 @@
1
- /// <reference types="react" />
2
1
  import { TRPCClientError } from "@trpc/client";
3
- declare const trpc: {
4
- Provider: ({ client, queryClient, children, isPrepass, ssrContext, }: {
5
- queryClient: import("react-query").QueryClient;
6
- client: import("@trpc/react").TRPCClient<import("@trpc/server").AnyRouter<any>>;
7
- children: import("react").ReactNode;
8
- isPrepass?: boolean | undefined;
9
- ssrContext?: unknown;
10
- }) => JSX.Element;
11
- createClient: (opts: import("@trpc/react").CreateTRPCClientOptions<import("@trpc/server").AnyRouter<any>>) => import("@trpc/react").TRPCClient<import("@trpc/server").AnyRouter<any>>;
12
- useContext: () => import("@trpc/react/dist/declarations/src/internals/context").TRPCContextState<import("@trpc/server").AnyRouter<any>, unknown>;
13
- useQuery: <TPath extends string>(pathAndInput: [TPath, (null | undefined)?], opts?: import("@trpc/react").UseTRPCQueryOptions<TPath, unknown, any, import("@trpc/react").TRPCClientErrorLike<import("@trpc/server").AnyRouter<any>>> | undefined) => import("react-query").UseQueryResult<any, import("@trpc/react").TRPCClientErrorLike<import("@trpc/server").AnyRouter<any>>>;
14
- useMutation: <TPath_1 extends string>(path: TPath_1 | [TPath_1], opts?: import("@trpc/react").UseTRPCMutationOptions<unknown, import("@trpc/react").TRPCClientErrorLike<import("@trpc/server").AnyRouter<any>>, any> | undefined) => import("react-query").UseMutationResult<any, import("@trpc/react").TRPCClientErrorLike<import("@trpc/server").AnyRouter<any>>, unknown, unknown>;
15
- useSubscription: <TPath_2 extends string, TOutput extends any>(pathAndInput: [TPath_2, (null | undefined)?], opts: {
16
- enabled?: boolean | undefined;
17
- onError?: ((err: import("@trpc/react").TRPCClientErrorLike<import("@trpc/server").AnyRouter<any>>) => void) | undefined;
18
- onNext: (data: TOutput) => void;
19
- }) => void;
20
- useDehydratedState: (client: import("@trpc/react").TRPCClient<import("@trpc/server").AnyRouter<any>>, trpcState: import("react-query").DehydratedState | undefined) => import("react-query").DehydratedState | undefined;
21
- useInfiniteQuery: <TPath_3 extends never>(pathAndInput: [path: TPath_3, input: Omit<unknown, "cursor">], opts?: import("@trpc/react").UseTRPCInfiniteQueryOptions<TPath_3, Omit<unknown, "cursor">, any, import("@trpc/react").TRPCClientErrorLike<import("@trpc/server").AnyRouter<any>>> | undefined) => import("react-query").UseInfiniteQueryResult<any, import("@trpc/react").TRPCClientErrorLike<import("@trpc/server").AnyRouter<any>>>;
22
- };
2
+ declare const trpc: any;
23
3
  export declare const useRPCQuery: RPCUseQuery;
24
4
  export declare const useRPCMutation: RPCUseMutation;
25
5
  export declare const useRPCInfiniteQuery: RPCUseInfiniteQuery;
package/index.d.ts CHANGED
@@ -1,3 +1 @@
1
- export * from "./components";
2
- export * from "./hooks";
3
- export * from "./routing";
1
+ export {};
package/index.js CHANGED
@@ -1,15 +1,5 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
2
+ // export * from "./components"
3
+ // export * from "./hooks"
4
+ // export * from "./routing"
12
5
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./components"), exports);
14
- __exportStar(require("./hooks"), exports);
15
- __exportStar(require("./routing"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eddev",
3
- "version": "0.2.6",
3
+ "version": "0.2.9",
4
4
  "main": "./index.js",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -27,7 +27,7 @@
27
27
  "@types/url-parse": "^1.4.4",
28
28
  "@types/webpack-dev-server": "^3.11.2",
29
29
  "csstype": "^3.0.9",
30
- "next": "^12.1.0",
30
+ "next": "^12.1.6",
31
31
  "react-html-props": "^1.0.32"
32
32
  },
33
33
  "dependencies": {
@@ -48,8 +48,8 @@
48
48
  "@loadable/webpack-plugin": "^5.15.2",
49
49
  "@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
50
50
  "@soda/friendly-errors-webpack-plugin": "^1.8.0",
51
- "@stitches/core": "^1.2.7",
52
- "@stitches/react": "^1.2.7",
51
+ "@stitches/core": "^1.2.8",
52
+ "@stitches/react": "^1.2.8",
53
53
  "@trpc/client": "^9.19.0",
54
54
  "@trpc/next": "^9.19.0",
55
55
  "@trpc/react": "^9.19.0",
@@ -329,7 +329,7 @@ exports.Link = (0, react_1.forwardRef)(function (props, ref) {
329
329
  // @ts-ignore
330
330
  if (process.serverless) {
331
331
  var NextLink = require("next/link").default;
332
- return ((0, jsx_runtime_1.jsx)(NextLink, __assign({ href: props.href, passHref: true }, { children: (0, jsx_runtime_1.jsx)("a", __assign({ ref: ref }, props, { href: undefined }), void 0) }), void 0));
332
+ return ((0, jsx_runtime_1.jsx)(NextLink, __assign({ href: props.href, passHref: true, prefetch: false }, { children: (0, jsx_runtime_1.jsx)("a", __assign({ ref: ref }, props, { href: undefined }), void 0) }), void 0));
333
333
  }
334
334
  var localRef = (0, react_1.useRef)();
335
335
  var router = (0, react_1.useContext)(RouterContext);
@@ -8,6 +8,7 @@ export async function fetchWordpressProps(pathname: string) {
8
8
  const origin = (process.env.SITE_URL as string).replace(/\/$/, "")
9
9
  pathname = pathname.replace(/(^\/|\/$)/g, "")
10
10
  const propsURL = origin + ("/" + pathname + "/?_props=all").replace(/\/+/, "/")
11
+ console.log("Fetching from", propsURL)
11
12
 
12
13
  // Make the request
13
14
  let response = await fetchWP(propsURL, {})
@@ -16,6 +16,6 @@
16
16
  "devDependencies": {
17
17
  "@types/react": "17.0.39",
18
18
  "typescript": "4.5.5",
19
- "next": "^12.1.0"
19
+ "next": "^12.1.6"
20
20
  }
21
21
  }
@@ -1,4 +1,5 @@
1
1
  import { GetStaticPathsResult, GetStaticPropsContext, GetStaticPropsResult } from "next"
2
+ import settings from "_utils/ed-config"
2
3
  import { fetchWordpressProps } from "../_utils/fetch-wordpress-props"
3
4
 
4
5
  export default function Home(props: any) {
@@ -8,7 +9,7 @@ export default function Home(props: any) {
8
9
  export async function getStaticPaths(): Promise<GetStaticPathsResult> {
9
10
  return {
10
11
  paths: [],
11
- fallback: true,
12
+ fallback: "blocking",
12
13
  }
13
14
  }
14
15
 
@@ -27,7 +28,10 @@ export async function getStaticProps({ params }: GetStaticPropsContext): Promise
27
28
  },
28
29
  }
29
30
  }
31
+ const revalidate = result.data.revalidate || settings.serverless?.defaultRevalidate || false
32
+ console.log("REVALIDATE", revalidate)
30
33
  return {
31
34
  props: result.data,
35
+ revalidate: revalidate,
32
36
  }
33
37
  }
@@ -8,6 +8,7 @@ import { useRouter } from "next/router"
8
8
  import { DevUILoader } from "eddev/dev-ui/loader"
9
9
  import { PageMeta } from "../_utils/PageMeta"
10
10
  import { withTRPC } from "@trpc/next"
11
+ import { Suspense } from "react"
11
12
 
12
13
  let appData: any
13
14
 
@@ -16,10 +17,6 @@ function Root({ Component, pageProps }: AppProps) {
16
17
 
17
18
  if (!appData) appData = pageProps?.appData?.data
18
19
 
19
- // const appData = useMemo(() => {
20
- // return pageProps?.appData?.data
21
- // }, [])
22
-
23
20
  const viewProps = pageProps?.viewData?.data
24
21
 
25
22
  const View = manifest[pageProps.view || "404"]
@@ -36,7 +33,9 @@ function Root({ Component, pageProps }: AppProps) {
36
33
  {pageProps?.meta?.head && <PageMeta {...pageProps?.meta?.head} />}
37
34
  {pageProps?.meta?.footer && <PageMeta {...pageProps?.meta?.footer} />}
38
35
  {process.devUI ? <DevUILoader /> : null}
39
- <App>{View && <View {...viewProps} />}</App>
36
+ <App>
37
+ <Suspense fallback={null}>{View && <View {...viewProps} />}</Suspense>
38
+ </App>
40
39
  </NextRouter>
41
40
  </ServerlessAppDataProvider>
42
41
  )
@@ -17,7 +17,8 @@ const validProxyPaths = {
17
17
 
18
18
  export default async function (req: any, res: any) {
19
19
  // Ensure that the request is for a proxy path
20
- const proxyPath = validProxyPaths[req.query.method as keyof typeof validProxyPaths]!
20
+ console.log("METHOD", req.query.method)
21
+ const proxyPath = validProxyPaths[req.query.method[0] as keyof typeof validProxyPaths]!
21
22
 
22
23
  if (!proxyPath) {
23
24
  return res.status(404).json({