eddev 2.0.0-beta.26 → 2.0.0-beta.27

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.
@@ -7,7 +7,7 @@ export function EditableText({ id, as, appendOnEnter, store, ...props }) {
7
7
  if (!readOnly) {
8
8
  const [value, setValue] = useValueStore(store ?? id);
9
9
  const appendBlocks = useBlockAppender();
10
- return (_jsx(wp.blockEditor.RichText, { ...props, tagName: as, value: value || "", onChange: setValue, disableLineBreaks: props.disableLineBreaks, onKeyDownCapture: (e) => {
10
+ return (_jsx(wp.blockEditor.RichText, { ...props, tagName: as, value: value || "", onChange: setValue, inlineToolbar: props.inlineToolbar, disableLineBreaks: props.disableLineBreaks, onKeyDownCapture: (e) => {
11
11
  if (e.key === "Enter" && appendOnEnter && appendBlocks) {
12
12
  appendBlocks([
13
13
  wp.blocks.createBlock(typeof appendOnEnter === "string" ? appendOnEnter : "core/paragraph"),
@@ -9,6 +9,7 @@ export class ErrorBoundaryFrontend extends Component {
9
9
  return { hasError: true, error: err };
10
10
  }
11
11
  componentDidCatch(error, errorInfo) {
12
+ console.log("Caught error:", error, errorInfo);
12
13
  console.error("Uncaught error:", error, errorInfo);
13
14
  }
14
15
  render() {
@@ -2,9 +2,19 @@ import { FunctionComponent } from "react";
2
2
  import { ContentBlockLayoutProps } from "./ContentBlocks.js";
3
3
  import { BlockTemplate } from "./editor/block-templates.js";
4
4
  type AppenderConfig = {
5
- type: "default" | "button" | FunctionComponent<any>;
5
+ type: "default" | "button" | CustomBlockAppender;
6
6
  className?: string;
7
7
  };
8
+ export type CustomBlockAppender = FunctionComponent<{
9
+ onToggle: () => void;
10
+ disabled: boolean;
11
+ isOpen: boolean;
12
+ blockTitle: string;
13
+ hasSingleBlockType: boolean;
14
+ }>;
15
+ export declare function createAppender(comp: CustomBlockAppender): {
16
+ type: CustomBlockAppender;
17
+ };
8
18
  type InnerBlocksProps = {
9
19
  /** A list of allowed blocks, and/or block tags. */
10
20
  allowedBlocks?: (ChildBlockTypeName | BlockTagName)[];
@@ -9,7 +9,10 @@ const Appender = (props) => {
9
9
  return _jsx(wp.blockEditor.ButtonBlockAppender, { className: props.className, rootClientId: clientId });
10
10
  }
11
11
  else if (typeof props.type === "function") {
12
- return props.type({});
12
+ const Type = props.type;
13
+ return (_jsx(wp.blockEditor.Inserter, { renderToggle: (p) => {
14
+ return _jsx(Type, { ...p });
15
+ }, rootClientId: clientId }));
13
16
  }
14
17
  else {
15
18
  return (_jsx(wp.blockEditor.DefaultBlockAppender
@@ -19,6 +22,11 @@ const Appender = (props) => {
19
22
  className: props.className, rootClientId: clientId, lastBlockClientId: clientId }));
20
23
  }
21
24
  };
25
+ export function createAppender(comp) {
26
+ return {
27
+ type: comp,
28
+ };
29
+ }
22
30
  /**
23
31
  * Allows child blocks to be added to the current block context.
24
32
  */
@@ -13,6 +13,7 @@ export type APIConfigStore = {
13
13
  /**
14
14
  * Update aspects of the API client
15
15
  */
16
+ onResponse?: (response: Response) => void;
16
17
  set: (config: Partial<APIConfigStore>) => void;
17
18
  };
18
19
  export declare const apiConfig: APIConfigStore;
@@ -30,6 +30,8 @@ const fetchGETQuery = async (name, params, opts) => {
30
30
  options = await apiConfig.customQueryFetchOptions?.("query", name, params, url, options);
31
31
  }
32
32
  const response = await fetch(url, options);
33
+ if (apiConfig.onResponse)
34
+ apiConfig.onResponse(response);
33
35
  const payload = await response.json();
34
36
  if (payload.errors?.length > 0) {
35
37
  throw createQueryError(payload.errors.map((e) => e.message), response.status);
@@ -153,6 +155,8 @@ const fetchMutation = async (name, params, opts) => {
153
155
  options = await apiConfig.customQueryFetchOptions?.("mutation", name, params, url, options);
154
156
  }
155
157
  const response = await fetch(url, options);
158
+ if (apiConfig.onResponse)
159
+ apiConfig.onResponse(response);
156
160
  const payload = await response.json();
157
161
  if (payload.errors?.length > 0) {
158
162
  throw createQueryError(payload.errors.map((e) => e.message), response.status);
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useEffect, useMemo, useRef, useState, useTransition } from "react";
3
- import { isRelative, parseURL, resolveURL } from "ufo";
3
+ import { isEqual, isRelative, parseURL, resolveURL } from "ufo";
4
4
  import { RouterContext, RouterStateContext } from "../context.js";
5
5
  import { RouteLoader } from "../loader.js";
6
6
  import { getLinkHandlerMode, getRouteMeta, normalizeRoute, parseQuery, stringifyRouteLink } from "../utils.js";
@@ -255,6 +255,9 @@ export function BrowserRouter(props) {
255
255
  goingBack: false,
256
256
  });
257
257
  },
258
+ getState() {
259
+ return state;
260
+ },
258
261
  replaceHash(hash) {
259
262
  replaceRoute({
260
263
  ...getActiveRoute(),
@@ -305,7 +308,7 @@ export function BrowserRouter(props) {
305
308
  subscribers.delete(fn);
306
309
  };
307
310
  },
308
- handleClickEvent(e, originalHref) {
311
+ handleClickEvent(e, originalHref, preferBack) {
309
312
  const { mode, href } = getLinkHandlerMode(e, originalHref);
310
313
  if (mode === "ignore") {
311
314
  e.preventDefault();
@@ -316,6 +319,13 @@ export function BrowserRouter(props) {
316
319
  }
317
320
  else if (mode === "navigate" && href) {
318
321
  e.preventDefault();
322
+ if (preferBack) {
323
+ const lastState = state.history.length > 1 && state.history[state.history.length - 2];
324
+ if (lastState && isEqual(href, lastState.uri)) {
325
+ history.back();
326
+ return;
327
+ }
328
+ }
319
329
  api.navigate(href);
320
330
  }
321
331
  },
@@ -3,6 +3,7 @@ type Props<T extends ElementType = "a"> = NoInfer<Omit<ComponentPropsWithRef<T>,
3
3
  href?: string | null;
4
4
  target?: string | null;
5
5
  as?: T;
6
+ preferBack?: boolean;
6
7
  };
7
8
  export declare const Link: <T extends ElementType = "a">(props: Props<T>) => ReactElement;
8
9
  /**
@@ -6,7 +6,7 @@ import { useRouter } from "../hooks/useRouter.js";
6
6
  import { isSameOrigin } from "../utils.js";
7
7
  import { useRoute } from "../hooks/useRoute.js";
8
8
  import { useRouterState } from "../hooks/useRouterState.js";
9
- export const Link = forwardRef((props, ref) => {
9
+ export const Link = forwardRef(({ preferBack, ...props }, ref) => {
10
10
  const Comp = props.as || "a";
11
11
  if (env.admin) {
12
12
  return (_jsx(Comp, { ref: ref, ...props, href: props.href ?? undefined, onClick: (e) => {
@@ -15,17 +15,16 @@ export const Link = forwardRef((props, ref) => {
15
15
  } }));
16
16
  }
17
17
  else {
18
- const preload = useRouter((r) => r.preload);
19
- const handleClickEvent = useRouter((r) => r.handleClickEvent);
18
+ const router = useRouter();
20
19
  const state = useLinkState(props.href ?? "");
21
20
  return (_jsx(Comp, { ref: ref, "data-active": state.active ?? undefined, "data-child-active": state.childActive ?? undefined, "data-pending": state.pending ?? undefined, ...props, href: props.href ?? undefined, onMouseEnter: (e) => {
22
21
  if (props.onMouseEnter) {
23
22
  props.onMouseEnter(e);
24
23
  }
25
- preload(props.href);
24
+ router.preload(props.href);
26
25
  }, onClick: (e) => {
27
26
  props.onClick?.(e);
28
- handleClickEvent(e, props.href ?? undefined);
27
+ router.handleClickEvent(e, props.href ?? undefined, preferBack);
29
28
  } }));
30
29
  }
31
30
  });
@@ -3,6 +3,7 @@ import { memo, useMemo } from "react";
3
3
  import { RouteItemContext } from "../context.js";
4
4
  import { useRouter } from "../hooks/useRouter.js";
5
5
  import { useRouterState } from "../hooks/useRouterState.js";
6
+ import { ErrorBoundaryFrontend } from "../../blocks/ErrorBoundaryFrontend.js";
6
7
  export const AppRenderer = memo(() => {
7
8
  const { appData, appComponent: AppComponent } = useRouter().loader;
8
9
  const { activeRoute } = useRouterState();
@@ -22,7 +23,7 @@ export function RouteDisplay(props) {
22
23
  }
23
24
  return useMemo(() => {
24
25
  let child = !!Component && _jsx(Component, { ...props.route.props });
25
- return _jsx(RouteItemContext.Provider, { value: props.route, children: child });
26
+ return (_jsx(ErrorBoundaryFrontend, { children: _jsx(RouteItemContext.Provider, { value: props.route, children: child }) }));
26
27
  }, [Component, props.route, props.route]);
27
28
  }
28
29
  RouteDisplay.displayName = "RouteDisplay";
@@ -26,6 +26,9 @@ export const RouterContext = createContext({
26
26
  replaceQuery(query) { },
27
27
  handleClickEvent(e, originalHref) { },
28
28
  emitEvent(event) { },
29
+ getState() {
30
+ return null;
31
+ },
29
32
  });
30
33
  export const RouterStateContext = createContext({
31
34
  history: [NOOP_ROUTE],
@@ -1,2 +1,17 @@
1
1
  import type { RouteState } from "../types.js";
2
+ /**
3
+ * Returns the current route object.
4
+ *
5
+ * In most circumstances, this will be the active top-level route.
6
+ *
7
+ * In cases where manual rendering of routes is taking place, such as during page transitions or in some modal cases.
8
+ *
9
+ * @returns The current route
10
+ */
2
11
  export declare function useRoute(): RouteState;
12
+ /**
13
+ * Returns the current route, if it matches the specified view, otherwise null.
14
+ */
15
+ export declare function useViewRoute<V extends keyof ViewProps>(view: V): Extract<RouteState, {
16
+ view: V;
17
+ }> | null;
@@ -1,5 +1,26 @@
1
1
  import { useContext } from "react";
2
2
  import { RouteItemContext } from "../context.js";
3
+ /**
4
+ * Returns the current route object.
5
+ *
6
+ * In most circumstances, this will be the active top-level route.
7
+ *
8
+ * In cases where manual rendering of routes is taking place, such as during page transitions or in some modal cases.
9
+ *
10
+ * @returns The current route
11
+ */
3
12
  export function useRoute() {
4
13
  return useContext(RouteItemContext);
5
14
  }
15
+ /**
16
+ * Returns the current route, if it matches the specified view, otherwise null.
17
+ */
18
+ export function useViewRoute(view) {
19
+ const route = useContext(RouteItemContext);
20
+ if (route.view === view) {
21
+ return route;
22
+ }
23
+ else {
24
+ return null;
25
+ }
26
+ }
@@ -102,13 +102,15 @@ export type RouterAPI = {
102
102
  /** Replace the hash */
103
103
  replaceHash: (hash: string) => void;
104
104
  /** Handle link clicking events */
105
- handleClickEvent(e: PointerOrMouseEvent, href?: string): void;
105
+ handleClickEvent(e: PointerOrMouseEvent, href?: string, preferBack?: boolean): void;
106
106
  /** A reference to the route loader (mostly for internal use) */
107
107
  loader: RouteLoader;
108
108
  /** Subscribe to events */
109
109
  subscribe: (subscribe: RouterSubscriber) => () => void;
110
110
  /** This function is used by the routing system automatically */
111
111
  emitEvent: (event: RouterEvent) => void;
112
+ /** Returns the current RouterState */
113
+ getState: () => RouterAPIState | null;
112
114
  };
113
115
  export type TypedRouteState<T, TProps> = {
114
116
  /** A unique ID, representing this history item. */
@@ -0,0 +1,2 @@
1
+ import { Hono } from "hono";
2
+ export declare function defineRouter(): Hono;
@@ -0,0 +1,4 @@
1
+ import { Hono } from "hono";
2
+ export function defineRouter() {
3
+ return new Hono();
4
+ }
@@ -1,3 +1,4 @@
1
1
  export * from "./render-ssr-page.js";
2
2
  export * from "./server-context.js";
3
3
  export * from "./proxy-wp-admin.js";
4
+ export * from "./defineRouter.js";
@@ -1,3 +1,4 @@
1
1
  export * from "./render-ssr-page.js";
2
2
  export * from "./server-context.js";
3
3
  export * from "./proxy-wp-admin.js";
4
+ export * from "./defineRouter.js";
@@ -1,7 +1,7 @@
1
1
  import { parseURL, stringifyParsedURL, withQuery } from "ufo";
2
2
  import { filterHeader } from "./utils/headers.js";
3
3
  import { createUrlReplacer } from "./utils/replace-host.js";
4
- const PROXY_RESPONSE_HEADERS = ["content-type", "set-cookie", /^x-/, "cache-control"];
4
+ const PROXY_RESPONSE_HEADERS = ["content-type", "set-cookie", /^x-/, "cache-control", /woocommerce/];
5
5
  const PROXY_REQUEST_HEADERS = [
6
6
  "content-type",
7
7
  "accept",
@@ -11,6 +11,7 @@ const PROXY_REQUEST_HEADERS = [
11
11
  "referer",
12
12
  "user-agent",
13
13
  "authorization",
14
+ "woocommerce-session",
14
15
  ];
15
16
  let runtime;
16
17
  export class ServerContext {
@@ -50,12 +51,14 @@ export class ServerContext {
50
51
  if (!response.ok) {
51
52
  return response;
52
53
  }
54
+ // console.log("Response headers", response.headers)
53
55
  const headers = {};
54
56
  response.headers.forEach((value, key) => {
55
57
  if (filterHeader(key, PROXY_RESPONSE_HEADERS)) {
56
58
  headers[key] = value;
57
59
  }
58
60
  });
61
+ // console.log("Returning headers", headers)
59
62
  let text = await response.text();
60
63
  if (opts?.replaceUrls && this.replaceUrls) {
61
64
  text = this.replaceUrls(text);
@@ -116,6 +119,7 @@ export class ServerContext {
116
119
  "Content-Type": "application/json",
117
120
  Accept: "application/json",
118
121
  },
122
+ redirect: "manual",
119
123
  });
120
124
  }
121
125
  async fetchMutation(req) {
@@ -130,6 +134,7 @@ export class ServerContext {
130
134
  Accept: "application/json",
131
135
  },
132
136
  body: JSON.stringify(req.body),
137
+ redirect: "manual",
133
138
  });
134
139
  }
135
140
  }
@@ -1 +1 @@
1
- export declare const VERSION = "2.0.0-beta.26";
1
+ export declare const VERSION = "2.0.0-beta.27";
@@ -1 +1 @@
1
- export const VERSION = "2.0.0-beta.26";
1
+ export const VERSION = "2.0.0-beta.27";
@@ -227,7 +227,7 @@ export function createVinxiCodegen(opts) {
227
227
  return await serverContext.fetchMutation({
228
228
  name: id,
229
229
  body,
230
- headers: {},
230
+ headers: getRequestHeaders(event),
231
231
  })
232
232
  }),
233
233
  )
@@ -227,6 +227,9 @@ export class GraphQLGenerator {
227
227
  documents: getDocuments(["queries", "views", "blocks", "fragments"]),
228
228
  hasDocuments: true,
229
229
  banner: `import { ContentBlock } from "eddev/blocks"`,
230
+ footer: Object.keys(wp.scalarTypes)
231
+ .map((name) => `export type ${name}Scalar = Scalars["${name}"]["output"]`)
232
+ .join("\n"),
230
233
  plugins: {
231
234
  typescript: [typescriptPlugin, {}],
232
235
  typescriptOperations: [typescriptOperationsPlugin, {}],
@@ -400,7 +403,7 @@ export class GraphQLGenerator {
400
403
  errors.push(String(err));
401
404
  }
402
405
  if (args.banner) {
403
- output = args.banner + "\n\n" + output;
406
+ output = args.banner + "\n\n" + output + "\n" + (args.footer ?? "");
404
407
  }
405
408
  if (errors.length === 0) {
406
409
  const didWrite = await fs.writeIfUnchanged(config.filename, output);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eddev",
3
- "version": "2.0.0-beta.26",
3
+ "version": "2.0.0-beta.27",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",