eddev 0.2.8 → 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,
@@ -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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eddev",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "main": "./index.js",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -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({