eddev 0.1.39 → 0.1.42

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.
@@ -16,8 +16,7 @@ declare type BlocksContext = {
16
16
  current: ContentBlock;
17
17
  };
18
18
  export declare const BlocksContext: import("react").Context<BlocksContext | undefined>;
19
- declare type Props = {
20
- blocks: ContentBlock[];
19
+ export declare type ContentBlocksSettings = {
21
20
  wrapBlock?: (child: ReactElement, ctx: BlocksContext) => ReactElement;
22
21
  spacer?: (ctx: {
23
22
  ancestors: ContentBlock[];
@@ -26,6 +25,9 @@ declare type Props = {
26
25
  next: ContentBlock | null;
27
26
  }) => ReactElement | null;
28
27
  };
28
+ declare type Props = {
29
+ blocks: ContentBlock[];
30
+ } & ContentBlocksSettings;
29
31
  export declare type GenericBlockProps = {
30
32
  innerHTML?: string;
31
33
  innerContent?: string[];
@@ -1,4 +1,5 @@
1
1
  import { ElementType } from "react";
2
+ import { ContentBlocksSettings } from ".";
2
3
  declare type PropTypes<T extends ElementType> = {
3
4
  /** The 'key' of this editable text value */
4
5
  id: string;
@@ -18,6 +19,6 @@ declare type InnerBlocksProps = {
18
19
  templateLock?: any;
19
20
  template?: any;
20
21
  renderAppender?: any;
21
- };
22
+ } & ContentBlocksSettings;
22
23
  export declare function InnerBlocks(props: InnerBlocksProps): JSX.Element;
23
24
  export {};
@@ -74,7 +74,7 @@ function InnerBlocks(props) {
74
74
  }
75
75
  else {
76
76
  var blocks = (0, blockAttributes_1.useInnerBlocks)();
77
- return (0, jsx_runtime_1.jsx)(ContentBlocks_1.ContentBlocks, { blocks: blocks }, void 0);
77
+ return (0, jsx_runtime_1.jsx)(ContentBlocks_1.ContentBlocks, { blocks: blocks, spacer: props.spacer, wrapBlock: props.wrapBlock }, void 0);
78
78
  }
79
79
  }
80
80
  exports.InnerBlocks = InnerBlocks;
@@ -219,10 +219,10 @@ module.exports = {
219
219
  // Drill down to the path type
220
220
  var finalResultTypeName_1 = resultTypeName;
221
221
  pageInfo_1.nodesPath.forEach(function (key) {
222
- finalResultTypeName_1 = "Exclude<".concat(finalResultTypeName_1, "[").concat(JSON.stringify(key), "], null>");
222
+ finalResultTypeName_1 = "Exclude<".concat(finalResultTypeName_1, "[").concat(JSON.stringify(key), "], undefined | null>");
223
223
  });
224
224
  importUtils["createUseInfiniteQuery"] = true;
225
- hooks[hookName] = "\n createUseInfiniteQuery<Exclude<".concat(finalResultTypeName_1, "[0], null>, Omit<").concat(variablesTypeName || "undefined", ", 'limit' | 'cursor'>>({\n name: ").concat(JSON.stringify(name), ",\n defaultLimit: ").concat(defaultLimit_1, ",\n paths: ").concat(JSON.stringify(pageInfo_1), "\n })\n ");
225
+ hooks[hookName] = "\n createUseInfiniteQuery<Exclude<".concat(finalResultTypeName_1, "[0], undefined | null>, Omit<").concat(variablesTypeName || "undefined", ", 'limit' | 'cursor'>>({\n name: ").concat(JSON.stringify(name), ",\n defaultLimit: ").concat(defaultLimit_1, ",\n paths: ").concat(JSON.stringify(pageInfo_1), "\n })\n ");
226
226
  }
227
227
  });
228
228
  }
@@ -293,12 +293,18 @@ function beginWork(opts) {
293
293
  },
294
294
  config: {
295
295
  // maybeValue: "T",
296
- avoidOptionals: true,
296
+ avoidOptionals: {
297
+ field: true,
298
+ inputValue: false,
299
+ object: true,
300
+ defaultValue: true,
301
+ },
297
302
  // exportFragmentSpreadSubTypes: true,
298
303
  inlineFragmentTypes: "combine",
299
304
  onlyOperationTypes: true,
300
305
  skipTypename: true,
301
306
  preResolveTypes: true,
307
+ maybeValue: "T | null",
302
308
  },
303
309
  },
304
310
  "types.views.ts": {
@@ -87,16 +87,6 @@ function BrowserRouter(props) {
87
87
  if (!pending.popped) {
88
88
  history.replaceState({ scrollPosition: (_b = document.scrollingElement) === null || _b === void 0 ? void 0 : _b.scrollTop }, "", document.location.href);
89
89
  history.pushState({}, "", pending.url);
90
- // if (document.scrollingElement) {
91
- // console.log("Scroll to top")
92
- // document.scrollingElement.scrollTop = 0
93
- // }
94
- }
95
- else {
96
- // if (document.scrollingElement) {
97
- // console.log("Scroll to", pending.scrollPosition)
98
- // document.scrollingElement.scrollTop = pending.scrollPosition || 0
99
- // }
100
90
  }
101
91
  };
102
92
  if (view && view.preload) {
@@ -112,11 +102,10 @@ function BrowserRouter(props) {
112
102
  cancelled = true;
113
103
  };
114
104
  }, [pending]);
115
- console.log("Passing", url, data);
116
- var _c = (0, react_1.useState)(null), scrollPosition = _c[0], setScrollPosition = _c[1];
105
+ var _c = (0, react_1.useState)({ value: null }), scrollPosition = _c[0], setScrollPosition = _c[1];
117
106
  (0, react_1.useEffect)(function () {
118
- if (document.scrollingElement && typeof scrollPosition === "number") {
119
- document.scrollingElement.scrollTop = scrollPosition;
107
+ if (document.scrollingElement && typeof scrollPosition.value === "number") {
108
+ document.scrollingElement.scrollTop = scrollPosition.value;
120
109
  }
121
110
  }, [scrollPosition]);
122
111
  return ((0, jsx_runtime_1.jsx)(routing_1.RouterRoot, __assign({ url: url, data: data, onNavigateRequest: function (url) {
@@ -127,10 +116,10 @@ function BrowserRouter(props) {
127
116
  }
128
117
  }, onNavigated: function () {
129
118
  if (pending && typeof pending.scrollPosition === "number") {
130
- setScrollPosition(pending.scrollPosition);
119
+ setScrollPosition({ value: pending.scrollPosition });
131
120
  }
132
121
  else {
133
- setScrollPosition(0);
122
+ setScrollPosition({ value: 0 });
134
123
  }
135
124
  } }, { children: props.children }), void 0));
136
125
  }
@@ -34,9 +34,9 @@ declare type InfiniteQueryHookReturn<TItem, TVars> = {
34
34
  loadingMore: boolean;
35
35
  errors?: GraphQLError[];
36
36
  items?: TItem[];
37
- hasMore?: boolean;
38
- canLoadMore?: boolean;
39
- refresh: (vars?: TVars) => void;
37
+ cursor?: string;
38
+ hasMore: boolean;
39
+ refresh: () => void;
40
40
  loadMore: () => void;
41
41
  };
42
42
  declare type InfiniteQueryHasAdditionalVars<TVars> = Exclude<keyof TVars, "limit" | "cursor"> extends never ? false : true;
@@ -112,17 +112,25 @@ function createUseInfiniteQuery(init) {
112
112
  var _d = (0, react_1.useState)(false), hasMore = _d[0], setHasMore = _d[1];
113
113
  var _e = (0, react_1.useState)(true), isLoadingMore = _e[0], setIsLoadingMore = _e[1];
114
114
  var _f = (0, react_1.useState)([]), items = _f[0], setItems = _f[1];
115
- var _g = (0, swr_1.default)([
115
+ var _g = (0, react_1.useState)(vars), varPayload = _g[0], setVarPayload = _g[1];
116
+ var _h = (0, swr_1.default)([
116
117
  init.name,
117
- JSON.stringify(__assign(__assign({}, (vars || {})), { cursor: activeCursor })),
118
+ JSON.stringify(__assign(__assign({}, (varPayload || {})), { cursor: activeCursor })),
118
119
  ], fetcherGET, {
119
120
  revalidateIfStale: false,
120
121
  revalidateOnFocus: false,
121
122
  revalidateOnReconnect: false,
122
- }), payload = _g.data, isValidating = _g.isValidating, error = _g.error, mutate = _g.mutate;
123
+ }), payload = _h.data, isValidating = _h.isValidating, error = _h.error, mutate = _h.mutate;
124
+ (0, react_1.useEffect)(function () {
125
+ setItems([]);
126
+ setIsLoadingMore(true);
127
+ setErrors(undefined);
128
+ setHasMore(false);
129
+ setActiveCursor(undefined);
130
+ setVarPayload(vars);
131
+ }, [JSON.stringify(vars)]);
123
132
  (0, react_1.useEffect)(function () {
124
133
  if (payload) {
125
- console.log("Got payload", payload);
126
134
  setIsLoadingMore(false);
127
135
  if (payload.errors) {
128
136
  setErrors(payload.errors);
@@ -143,6 +151,7 @@ function createUseInfiniteQuery(init) {
143
151
  loading: isValidating && !items.length,
144
152
  loadingMore: isLoadingMore,
145
153
  items: items,
154
+ cursor: activeCursor,
146
155
  errors: error ? [error] : errors,
147
156
  refresh: function () {
148
157
  setErrors(undefined);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eddev",
3
- "version": "0.1.39",
3
+ "version": "0.1.42",
4
4
  "main": "./index.js",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -42,6 +42,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.hasCachedProps = exports.fetchProps = exports.isSameOrigin = exports.setInitialProps = exports.parseURL = void 0;
43
43
  var url_parse_1 = __importDefault(require("url-parse"));
44
44
  var qs_1 = __importDefault(require("qs"));
45
+ var pending = {};
45
46
  var cache = {};
46
47
  function parseURL(url) {
47
48
  return (0, url_parse_1.default)(url, qs_1.default.parse);
@@ -63,26 +64,26 @@ function isSameOrigin(url) {
63
64
  exports.isSameOrigin = isSameOrigin;
64
65
  function fetchProps(url) {
65
66
  return __awaiter(this, void 0, void 0, function () {
66
- var parsed, cacheKey, requestUrl, response, data;
67
+ var parsed, cacheKey, requestUrl, promise;
67
68
  return __generator(this, function (_a) {
68
- switch (_a.label) {
69
- case 0:
70
- parsed = parseURL(url);
71
- cacheKey = getRouteCacheKey(url);
72
- // Cached value?
73
- if (cache[cacheKey])
74
- return [2 /*return*/, Promise.resolve(cache[cacheKey])];
75
- parsed.query["_props"] = "1";
76
- requestUrl = parsed.toString();
77
- return [4 /*yield*/, fetch(requestUrl)];
78
- case 1:
79
- response = _a.sent();
80
- return [4 /*yield*/, response.json()];
81
- case 2:
82
- data = _a.sent();
83
- cache[cacheKey] = data;
84
- return [2 /*return*/, data];
85
- }
69
+ parsed = parseURL(url);
70
+ cacheKey = getRouteCacheKey(url);
71
+ // Cached value?
72
+ if (cacheKey in cache)
73
+ return [2 /*return*/, Promise.resolve(cache[cacheKey])];
74
+ if (cacheKey in pending)
75
+ return [2 /*return*/, pending[cacheKey]];
76
+ parsed.query["_props"] = "1";
77
+ requestUrl = parsed.toString();
78
+ promise = fetch(requestUrl)
79
+ .then(function (response) { return response.json(); })
80
+ .then(function (data) {
81
+ delete pending[cacheKey];
82
+ cache[cacheKey] = data;
83
+ return data;
84
+ });
85
+ pending[cacheKey] = promise;
86
+ return [2 /*return*/, promise];
86
87
  });
87
88
  });
88
89
  }
@@ -213,15 +213,7 @@ function useForkedRouter(conf, opts) {
213
213
  var ctx = (0, react_1.useMemo)(function () {
214
214
  return parent.fork(conf, opts);
215
215
  }, [parent]);
216
- // useEffect(() => {
217
- // if (onChange) {
218
- // return ctx.subscribe(onChange);
219
- // }
220
- // }, [ctx, onChange]);
221
216
  Object.assign(ctx.config, conf);
222
- // ctx.config.match = conf.match;
223
- // ctx.config.beforeLeave = conf.beforeLeave;
224
- // ctx.config.beforeLeave = conf.beforeLeave;
225
217
  (0, react_1.useEffect)(function () {
226
218
  return function () { return ctx.dispose(); };
227
219
  }, [ctx]);