eddev 0.1.32 → 0.1.33-beta-4
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/blocks/ContentBlocks.js +2 -1
- package/blocks/{EditorErrorBoundary.d.ts → ErrorBoundaryEditor.d.ts} +1 -1
- package/blocks/{EditorErrorBoundary.js → ErrorBoundaryEditor.js} +9 -9
- package/blocks/ErrorBoundaryFrontend.d.ts +15 -0
- package/blocks/ErrorBoundaryFrontend.js +69 -0
- package/blocks/index.d.ts +0 -1
- package/blocks/index.js +0 -1
- package/blocks/inlineEditing.js +1 -21
- package/blocks/installGutenbergHooks.d.ts +1 -0
- package/blocks/installGutenbergHooks.js +27 -6
- package/build/babel/plugin-name-defined-components.d.ts +7 -0
- package/build/babel/plugin-name-defined-components.js +46 -0
- package/build/create-codegen-worker.d.ts +1 -1
- package/build/create-codegen-worker.js +1 -1
- package/build/create-webpack-worker.d.ts +1 -1
- package/build/create-webpack-worker.js +1 -1
- package/build/get-webpack-config.js +29 -17
- package/build/workers/codegen-worker-script.js +5 -1
- package/build/workers/webpack-worker-script.js +1 -0
- package/cli/display/components/BundleDisplay.d.ts +1 -1
- package/cli/display/components/BundleDisplay.js +1 -1
- package/cli/display/components/CodegenDisplay.d.ts +1 -1
- package/cli/display/components/CodegenDisplay.js +1 -1
- package/cli/display/components/DevCLIDisplay.d.ts +1 -1
- package/components/BrowserRouter.js +11 -2
- package/components/InlinePage.js +1 -1
- package/entry/entry.admin.dev.js +2 -2
- package/entry/entry.admin.prod.js +2 -2
- package/package.json +1 -1
- package/{utils → routing}/remoteProps.d.ts +8 -0
- package/{utils → routing}/remoteProps.js +1 -1
- package/routing/routing.d.ts +1 -1
- package/routing/routing.js +2 -2
- package/routing/updateEditLink.d.ts +1 -0
- package/routing/updateEditLink.js +12 -0
- package/routing/updateHeadTags.d.ts +2 -0
- package/routing/updateHeadTags.js +11 -0
- package/{cli/display/lib → utils}/Observable.d.ts +0 -0
- package/{cli/display/lib → utils}/Observable.js +0 -0
- package/{cli/display/lib → utils}/useObservable.d.ts +0 -0
- package/{cli/display/lib → utils}/useObservable.js +0 -0
- package/components/ContentBlocks.d.ts +0 -36
- package/components/ContentBlocks.js +0 -92
- package/components/routing.d.ts +0 -44
- package/components/routing.js +0 -363
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import URLParse from "url-parse";
|
|
2
|
+
export declare type ParsedRouteTags = Record<"title" | "meta" | "script" | "style" | "link", {
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
}[]>;
|
|
2
5
|
export interface RouteData {
|
|
3
6
|
view: string;
|
|
7
|
+
editLink?: string;
|
|
4
8
|
viewType: "react" | "html";
|
|
5
9
|
viewData: any;
|
|
6
10
|
appData: any;
|
|
11
|
+
meta?: {
|
|
12
|
+
head: ParsedRouteTags;
|
|
13
|
+
footer: ParsedRouteTags;
|
|
14
|
+
};
|
|
7
15
|
}
|
|
8
16
|
export declare function parseURL(url: string): URLParse<string>;
|
|
9
17
|
export declare function setInitialProps(url: string, data: RouteData): void;
|
|
@@ -58,7 +58,7 @@ function setInitialProps(url, data) {
|
|
|
58
58
|
exports.setInitialProps = setInitialProps;
|
|
59
59
|
function isSameOrigin(url) {
|
|
60
60
|
var parsed = parseURL(url);
|
|
61
|
-
return parsed.origin === document.location.origin;
|
|
61
|
+
return parsed.origin === document.location.origin && !parsed.pathname.match(/\.[a-z0-9]$/i);
|
|
62
62
|
}
|
|
63
63
|
exports.isSameOrigin = isSameOrigin;
|
|
64
64
|
function fetchProps(url) {
|
package/routing/routing.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode, PropsWithChildren } from "react";
|
|
2
2
|
import { APropsWithoutRef } from "react-html-props";
|
|
3
3
|
import URLParse from "url-parse";
|
|
4
|
-
import { RouteData } from "
|
|
4
|
+
import { RouteData } from "./remoteProps";
|
|
5
5
|
declare type RouteItem = URLParse<any> & {
|
|
6
6
|
data?: RouteData;
|
|
7
7
|
};
|
package/routing/routing.js
CHANGED
|
@@ -326,8 +326,8 @@ exports.Link = (0, react_1.forwardRef)(function (props, ref) {
|
|
|
326
326
|
}
|
|
327
327
|
}, [props.preload]);
|
|
328
328
|
return ((0, jsx_runtime_1.jsx)("a", __assign({ ref: (0, react_merge_refs_1.default)([localRef, ref]) }, props, { onMouseEnter: function (e) {
|
|
329
|
-
if (props.
|
|
330
|
-
props.
|
|
329
|
+
if (props.onMouseEnter) {
|
|
330
|
+
props.onMouseEnter(e);
|
|
331
331
|
}
|
|
332
332
|
router === null || router === void 0 ? void 0 : router.onPreload(e.currentTarget.href);
|
|
333
333
|
}, onClick: function (e) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function updateEditLink(link?: string): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateEditLink = void 0;
|
|
4
|
+
function updateEditLink(link) {
|
|
5
|
+
if (link) {
|
|
6
|
+
var editLink = document.querySelector("#wp-admin-bar-edit a");
|
|
7
|
+
if (editLink) {
|
|
8
|
+
editLink.setAttribute("href", link);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.updateEditLink = updateEditLink;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateHeadTags = void 0;
|
|
4
|
+
function updateHeadTags(tags) {
|
|
5
|
+
// Update the document title
|
|
6
|
+
if (tags.title && tags.title.length > 0 && typeof tags.title[0].__code === "string") {
|
|
7
|
+
document.title = tags.title[0].__code;
|
|
8
|
+
}
|
|
9
|
+
// TODO: Add any missing script/link/style tags too!
|
|
10
|
+
}
|
|
11
|
+
exports.updateHeadTags = updateHeadTags;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ReactElement } from "react";
|
|
2
|
-
export declare type ContentBlock<T extends keyof BlockProps | string = any> = {
|
|
3
|
-
blockName: T;
|
|
4
|
-
props: BlockProps extends keyof BlockProps ? BlockProps[T] : any;
|
|
5
|
-
innerBlocks: ContentBlock[];
|
|
6
|
-
innerHTML?: string;
|
|
7
|
-
innerContent?: string[];
|
|
8
|
-
rule: string;
|
|
9
|
-
inline: any;
|
|
10
|
-
};
|
|
11
|
-
declare type BlocksContext = {
|
|
12
|
-
ancestors: ContentBlock[];
|
|
13
|
-
parent?: ContentBlock;
|
|
14
|
-
prev?: ContentBlock;
|
|
15
|
-
next?: ContentBlock;
|
|
16
|
-
current: ContentBlock;
|
|
17
|
-
};
|
|
18
|
-
export declare const BlocksContext: import("react").Context<BlocksContext | undefined>;
|
|
19
|
-
declare type Props = {
|
|
20
|
-
blocks: ContentBlock[];
|
|
21
|
-
wrapBlock?: (child: ReactElement, ctx: BlocksContext) => ReactElement;
|
|
22
|
-
spacer?: (ctx: {
|
|
23
|
-
ancestors: ContentBlock[];
|
|
24
|
-
parent?: ContentBlock;
|
|
25
|
-
prev: ContentBlock | null;
|
|
26
|
-
next: ContentBlock | null;
|
|
27
|
-
}) => ReactElement | null;
|
|
28
|
-
};
|
|
29
|
-
export declare type GenericBlockProps = {
|
|
30
|
-
innerHTML?: string;
|
|
31
|
-
innerContent?: string[];
|
|
32
|
-
innerBlocks?: ContentBlock[];
|
|
33
|
-
children: ReactElement | null;
|
|
34
|
-
};
|
|
35
|
-
export declare function ContentBlocks(props: Props): JSX.Element | null;
|
|
36
|
-
export {};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
-
if (ar || !(i in from)) {
|
|
16
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
-
ar[i] = from[i];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
-
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ContentBlocks = exports.BlocksContext = void 0;
|
|
27
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
var blocks_1 = __importDefault(require("@manifest/blocks"));
|
|
30
|
-
var blockAttributes_1 = require("../blocks/blockAttributes");
|
|
31
|
-
var react_1 = require("react");
|
|
32
|
-
exports.BlocksContext = (0, react_1.createContext)(undefined);
|
|
33
|
-
function ContentBlocks(props) {
|
|
34
|
-
if (!Array.isArray(props.blocks))
|
|
35
|
-
return null;
|
|
36
|
-
var parentContext = (0, react_1.useContext)(exports.BlocksContext);
|
|
37
|
-
var blocks = (0, react_1.useMemo)(function () {
|
|
38
|
-
return props.blocks.map(function (block, index) {
|
|
39
|
-
// Create a context object for the current block
|
|
40
|
-
var ctx = __assign(__assign({}, parentContext), { ancestors: __spreadArray(__spreadArray([], ((parentContext === null || parentContext === void 0 ? void 0 : parentContext.ancestors) || []), true), [
|
|
41
|
-
parentContext === null || parentContext === void 0 ? void 0 : parentContext.current,
|
|
42
|
-
], 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] });
|
|
43
|
-
// Figure out the
|
|
44
|
-
var blockNode;
|
|
45
|
-
if (block.blockName in blocks_1.default) {
|
|
46
|
-
var Component = blocks_1.default[block.blockName];
|
|
47
|
-
if (!Component)
|
|
48
|
-
return (0, jsx_runtime_1.jsx)(react_1.Fragment, {}, void 0);
|
|
49
|
-
blockNode = ((0, jsx_runtime_1.jsx)(blockAttributes_1.InlineEditingContextProvider, __assign({ values: block.inline, innerBlocks: block.innerBlocks }, { children: (0, jsx_runtime_1.jsx)(Component, __assign({}, block.props, { innerHTML: block.innerHTML,
|
|
50
|
-
// innerBlocks={block.innerBlocks}
|
|
51
|
-
children: Array.isArray(block.innerBlocks) &&
|
|
52
|
-
block.innerBlocks.length ? ((0, jsx_runtime_1.jsx)(ContentBlocks, { blocks: block.innerBlocks }, void 0)) : null }), void 0) }), void 0));
|
|
53
|
-
}
|
|
54
|
-
else if (block.innerHTML) {
|
|
55
|
-
blockNode = ((0, jsx_runtime_1.jsx)("div", { dangerouslySetInnerHTML: { __html: block.innerHTML } }, void 0));
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
blockNode = null;
|
|
59
|
-
}
|
|
60
|
-
return [ctx, block, blockNode];
|
|
61
|
-
});
|
|
62
|
-
}, [props.blocks]);
|
|
63
|
-
var layout = (0, react_1.useMemo)(function () {
|
|
64
|
-
return blocks.filter(Boolean).map(function (_a, index) {
|
|
65
|
-
var ctx = _a[0], block = _a[1], blockNode = _a[2];
|
|
66
|
-
// Exit early if the block is null
|
|
67
|
-
if (blockNode === null)
|
|
68
|
-
return (0, jsx_runtime_1.jsx)(react_1.Fragment, {}, index);
|
|
69
|
-
// Custom wrap function?
|
|
70
|
-
if (props.wrapBlock) {
|
|
71
|
-
blockNode = props.wrapBlock(blockNode, ctx);
|
|
72
|
-
}
|
|
73
|
-
// Wrap the block in a context provider
|
|
74
|
-
blockNode = ((0, jsx_runtime_1.jsx)(exports.BlocksContext.Provider, __assign({ value: ctx }, { children: blockNode }), void 0));
|
|
75
|
-
// Custom spacer function?
|
|
76
|
-
var spaceBefore = null;
|
|
77
|
-
var spaceAfter = null;
|
|
78
|
-
if (props.spacer) {
|
|
79
|
-
// Before block
|
|
80
|
-
spaceBefore = props.spacer(__assign(__assign({}, ctx), { prev: ctx.prev || null, next: ctx.current || null }));
|
|
81
|
-
// After block (last block only)
|
|
82
|
-
if (index === props.blocks.length - 1) {
|
|
83
|
-
spaceAfter = props.spacer(__assign(__assign({}, ctx), { prev: block, next: null }));
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
// Attempt to wrap the block
|
|
87
|
-
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [spaceBefore, blockNode, spaceAfter] }, index));
|
|
88
|
-
});
|
|
89
|
-
}, [blocks, props.wrapBlock, props.spacer]);
|
|
90
|
-
return (0, jsx_runtime_1.jsx)(react_1.Fragment, { children: layout }, void 0);
|
|
91
|
-
}
|
|
92
|
-
exports.ContentBlocks = ContentBlocks;
|
package/components/routing.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ReactNode, PropsWithChildren } from "react";
|
|
2
|
-
import { APropsWithoutRef } from "react-html-props";
|
|
3
|
-
import URLParse from "url-parse";
|
|
4
|
-
import { RouteData } from "../utils/remoteProps";
|
|
5
|
-
declare type RouteItem = URLParse<any> & {
|
|
6
|
-
data?: RouteData;
|
|
7
|
-
};
|
|
8
|
-
declare type AnyPromise = Promise<any>;
|
|
9
|
-
declare type MatchResult = boolean | string;
|
|
10
|
-
declare type RouteStatus = "leaving" | "parent-leaving" | "active" | "inactive";
|
|
11
|
-
declare type RouteContextConfig = {
|
|
12
|
-
debugName?: string;
|
|
13
|
-
match?(next: RouteItem): MatchResult;
|
|
14
|
-
beforeLeave?(current: RouteItem, next: RouteItem, parentIsLeaving: boolean): AnyPromise | undefined;
|
|
15
|
-
onChange?(route: RouteItem, status: RouteStatus): void;
|
|
16
|
-
};
|
|
17
|
-
export declare function useRoute(): RouteItem;
|
|
18
|
-
export declare type RouteProps = RouteContextConfig & {
|
|
19
|
-
children: ReactNode;
|
|
20
|
-
};
|
|
21
|
-
export declare function Route(props: RouteProps): JSX.Element | null;
|
|
22
|
-
export declare function createRouteItem(url: string, data: RouteData): RouteItem;
|
|
23
|
-
declare type RouterRootProps = {
|
|
24
|
-
url: string;
|
|
25
|
-
data: RouteData;
|
|
26
|
-
children: ReactNode;
|
|
27
|
-
onNavigateRequest?: (url: string) => void;
|
|
28
|
-
onPreload?: (url: string) => void;
|
|
29
|
-
onNavigated?: (url: string) => void;
|
|
30
|
-
};
|
|
31
|
-
export declare function RouterRoot(props: RouterRootProps): JSX.Element;
|
|
32
|
-
declare type SwitchProps = {
|
|
33
|
-
children: ReactNode | ReactNode[];
|
|
34
|
-
};
|
|
35
|
-
export declare const Link: import("react").ForwardRefExoticComponent<APropsWithoutRef & {
|
|
36
|
-
preload?: boolean | undefined;
|
|
37
|
-
} & {
|
|
38
|
-
className?: string | undefined;
|
|
39
|
-
} & import("react").RefAttributes<HTMLAnchorElement>>;
|
|
40
|
-
export declare function Switch({ children }: SwitchProps): JSX.Element;
|
|
41
|
-
export declare function RouteItemContext(props: PropsWithChildren<{
|
|
42
|
-
route: RouteItem;
|
|
43
|
-
}>): JSX.Element;
|
|
44
|
-
export {};
|
package/components/routing.js
DELETED
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.RouteItemContext = exports.Switch = exports.Link = exports.RouterRoot = exports.createRouteItem = exports.Route = exports.useRoute = void 0;
|
|
54
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
55
|
-
var react_1 = require("react");
|
|
56
|
-
var react_merge_refs_1 = __importDefault(require("react-merge-refs"));
|
|
57
|
-
var url_parse_1 = __importDefault(require("url-parse"));
|
|
58
|
-
// const logger = (...args: any[]) => console.log(...args)
|
|
59
|
-
var logger = function () {
|
|
60
|
-
var args = [];
|
|
61
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
62
|
-
args[_i] = arguments[_i];
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
function createRouteContext(opts) {
|
|
66
|
-
var _a, _b;
|
|
67
|
-
var subscribers = [];
|
|
68
|
-
var notify = function (item, status) {
|
|
69
|
-
subscribers.forEach(function (handler) { return handler(item, status); });
|
|
70
|
-
};
|
|
71
|
-
var parentIsSwitch = opts.parent && opts.parent.isSwitch;
|
|
72
|
-
var ctx = {
|
|
73
|
-
item: opts.initial,
|
|
74
|
-
config: opts.config || {},
|
|
75
|
-
parent: opts.parent,
|
|
76
|
-
children: [],
|
|
77
|
-
status: "inactive",
|
|
78
|
-
currentMatch: false,
|
|
79
|
-
isSwitch: !!opts.isSwitch,
|
|
80
|
-
onNavigate: opts.onNavigate,
|
|
81
|
-
onPreload: opts.onPreload,
|
|
82
|
-
propagateChange: function (item, matches) {
|
|
83
|
-
ctx.item = item;
|
|
84
|
-
ctx.currentMatch = matches;
|
|
85
|
-
ctx.status = matches ? "active" : "inactive";
|
|
86
|
-
ctx.children.forEach(function (child) {
|
|
87
|
-
child.propagateChange(item, child.match(item));
|
|
88
|
-
});
|
|
89
|
-
notify(item, ctx.status);
|
|
90
|
-
},
|
|
91
|
-
propagateCandidate: function (next, prev) {
|
|
92
|
-
// if (ctx.status === "leaving") return Promise.resolve();
|
|
93
|
-
var promises = [Promise.resolve()];
|
|
94
|
-
var matches = ctx.match(next);
|
|
95
|
-
logger(ctx.config.debugName, "was", ctx.status, matches);
|
|
96
|
-
if (ctx.status === "active" && (!matches || matches !== ctx.currentMatch)) {
|
|
97
|
-
logger(ctx.config.debugName, "is leaving because ", matches, "!=", ctx.currentMatch);
|
|
98
|
-
ctx.status = "leaving";
|
|
99
|
-
}
|
|
100
|
-
logger(ctx.config.debugName, "is now", ctx.status);
|
|
101
|
-
if (ctx.status === "leaving") {
|
|
102
|
-
promises.push(this.propagateLeaving(prev, next, false));
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
ctx.children.forEach(function (child) {
|
|
106
|
-
promises.push(child.propagateCandidate(next, prev));
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
notify(prev, ctx.status);
|
|
110
|
-
return Promise.all(promises);
|
|
111
|
-
},
|
|
112
|
-
propagateLeaving: function (current, next, parentIsLeaving) {
|
|
113
|
-
ctx.status = parentIsLeaving ? "parent-leaving" : "leaving";
|
|
114
|
-
logger(ctx.status);
|
|
115
|
-
var promises = [Promise.resolve()];
|
|
116
|
-
if (ctx.config.beforeLeave) {
|
|
117
|
-
var result = ctx.config.beforeLeave(current, next, parentIsLeaving);
|
|
118
|
-
if (result)
|
|
119
|
-
promises.push(result);
|
|
120
|
-
}
|
|
121
|
-
ctx.children.forEach(function (child) {
|
|
122
|
-
var result = child.propagateLeaving(current, next, true);
|
|
123
|
-
if (result) {
|
|
124
|
-
promises.push(result);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
notify(current, ctx.status);
|
|
128
|
-
return Promise.all(promises);
|
|
129
|
-
},
|
|
130
|
-
subscribe: function (handler) {
|
|
131
|
-
subscribers.push(handler);
|
|
132
|
-
handler(ctx.item, ctx.status);
|
|
133
|
-
return function () {
|
|
134
|
-
var i = subscribers.indexOf(handler);
|
|
135
|
-
if (i !== -1) {
|
|
136
|
-
subscribers.splice(i, 1);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
},
|
|
140
|
-
getFirstMatch: function (item) {
|
|
141
|
-
logger("Checking items", this.children, item);
|
|
142
|
-
for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
|
|
143
|
-
var child = _a[_i];
|
|
144
|
-
if (child.matchSelf(item)) {
|
|
145
|
-
logger("Matched", child.config.debugName);
|
|
146
|
-
return child;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
match: function (item) {
|
|
151
|
-
if (parentIsSwitch) {
|
|
152
|
-
var parent_1 = ctx.parent;
|
|
153
|
-
return parent_1.getFirstMatch(item) === ctx && this.matchSelf(item);
|
|
154
|
-
}
|
|
155
|
-
return this.matchSelf(item);
|
|
156
|
-
},
|
|
157
|
-
matchSelf: function (item) {
|
|
158
|
-
var _a, _b;
|
|
159
|
-
if ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.config) === null || _a === void 0 ? void 0 : _a.match) {
|
|
160
|
-
return (_b = ctx === null || ctx === void 0 ? void 0 : ctx.config) === null || _b === void 0 ? void 0 : _b.match(item);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
update: function () { },
|
|
167
|
-
dispose: (_a = opts.dispose) !== null && _a !== void 0 ? _a : (function () { }),
|
|
168
|
-
fork: function (config, opts) {
|
|
169
|
-
if (opts === void 0) { opts = {}; }
|
|
170
|
-
var child = createRouteContext({
|
|
171
|
-
initial: ctx.item,
|
|
172
|
-
config: config,
|
|
173
|
-
parent: ctx,
|
|
174
|
-
isSwitch: opts.isSwitch,
|
|
175
|
-
onNavigate: ctx.onNavigate,
|
|
176
|
-
onPreload: ctx.onPreload,
|
|
177
|
-
dispose: function () {
|
|
178
|
-
var i = ctx.children.indexOf(child);
|
|
179
|
-
if (i !== -1)
|
|
180
|
-
ctx.children.splice(i, 1);
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
ctx.children.push(child);
|
|
184
|
-
if (ctx.isSwitch) {
|
|
185
|
-
}
|
|
186
|
-
return child;
|
|
187
|
-
},
|
|
188
|
-
};
|
|
189
|
-
logger("Initting", ctx.config.debugName, opts.initial);
|
|
190
|
-
if (parentIsSwitch) {
|
|
191
|
-
logger("Parent is switch");
|
|
192
|
-
if (!((_b = opts.parent) === null || _b === void 0 ? void 0 : _b.getFirstMatch(opts.initial))) {
|
|
193
|
-
logger("FFFF", ctx.config.match, ctx.match(opts.initial));
|
|
194
|
-
ctx.currentMatch = ctx.matchSelf(opts.initial);
|
|
195
|
-
ctx.status = ctx.currentMatch ? "active" : "inactive";
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
ctx.currentMatch = ctx.matchSelf(opts.initial);
|
|
200
|
-
ctx.status = ctx.currentMatch ? "active" : "inactive";
|
|
201
|
-
}
|
|
202
|
-
subscribers.push(function (item, status) {
|
|
203
|
-
if (ctx.config.onChange) {
|
|
204
|
-
ctx.config.onChange(item, status);
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
// notify(ctx.item, ctx.status);
|
|
208
|
-
return ctx;
|
|
209
|
-
}
|
|
210
|
-
var RouterContext = (0, react_1.createContext)(undefined);
|
|
211
|
-
function useForkedRouter(conf, opts) {
|
|
212
|
-
var parent = (0, react_1.useContext)(RouterContext);
|
|
213
|
-
var ctx = (0, react_1.useMemo)(function () {
|
|
214
|
-
return parent.fork(conf, opts);
|
|
215
|
-
}, [parent]);
|
|
216
|
-
// useEffect(() => {
|
|
217
|
-
// if (onChange) {
|
|
218
|
-
// return ctx.subscribe(onChange);
|
|
219
|
-
// }
|
|
220
|
-
// }, [ctx, onChange]);
|
|
221
|
-
Object.assign(ctx.config, conf);
|
|
222
|
-
// ctx.config.match = conf.match;
|
|
223
|
-
// ctx.config.beforeLeave = conf.beforeLeave;
|
|
224
|
-
// ctx.config.beforeLeave = conf.beforeLeave;
|
|
225
|
-
(0, react_1.useEffect)(function () {
|
|
226
|
-
return function () { return ctx.dispose(); };
|
|
227
|
-
}, [ctx]);
|
|
228
|
-
return ctx;
|
|
229
|
-
}
|
|
230
|
-
function useRoute() {
|
|
231
|
-
var router = (0, react_1.useContext)(RouterContext);
|
|
232
|
-
var _a = (0, react_1.useState)(router.item), route = _a[0], setRoute = _a[1];
|
|
233
|
-
(0, react_1.useEffect)(function () {
|
|
234
|
-
return router.subscribe(function (item, status) {
|
|
235
|
-
setRoute(item);
|
|
236
|
-
});
|
|
237
|
-
}, [router]);
|
|
238
|
-
return route;
|
|
239
|
-
}
|
|
240
|
-
exports.useRoute = useRoute;
|
|
241
|
-
function Route(props) {
|
|
242
|
-
var ctx = useForkedRouter({
|
|
243
|
-
match: props.match,
|
|
244
|
-
beforeLeave: props.beforeLeave,
|
|
245
|
-
debugName: props.debugName,
|
|
246
|
-
onChange: props.onChange,
|
|
247
|
-
});
|
|
248
|
-
logger("Intial route for", props.debugName, ctx.status, ctx.currentMatch);
|
|
249
|
-
var _a = (0, react_1.useState)(ctx.status), status = _a[0], setStatus = _a[1];
|
|
250
|
-
(0, react_1.useEffect)(function () {
|
|
251
|
-
return ctx.subscribe(function (item, status) {
|
|
252
|
-
setStatus(status);
|
|
253
|
-
});
|
|
254
|
-
}, [ctx]);
|
|
255
|
-
if (status === "inactive")
|
|
256
|
-
return null;
|
|
257
|
-
return (0, jsx_runtime_1.jsx)(RouterContext.Provider, __assign({ value: ctx }, { children: props.children }), void 0);
|
|
258
|
-
}
|
|
259
|
-
exports.Route = Route;
|
|
260
|
-
function createRouteItem(url, data) {
|
|
261
|
-
var parsed = (0, url_parse_1.default)(url, true);
|
|
262
|
-
return __assign(__assign({}, parsed), { data: data });
|
|
263
|
-
}
|
|
264
|
-
exports.createRouteItem = createRouteItem;
|
|
265
|
-
function RouterRoot(props) {
|
|
266
|
-
var _this = this;
|
|
267
|
-
var onNavigateRef = (0, react_1.useRef)(props.onNavigateRequest);
|
|
268
|
-
var onPreNavigateRef = (0, react_1.useRef)(props.onPreload);
|
|
269
|
-
var ctx = (0, react_1.useMemo)(function () {
|
|
270
|
-
return createRouteContext({
|
|
271
|
-
initial: createRouteItem(props.url, props.data),
|
|
272
|
-
config: {
|
|
273
|
-
debugName: "ROOT",
|
|
274
|
-
},
|
|
275
|
-
onNavigate: function (path) { return __awaiter(_this, void 0, void 0, function () {
|
|
276
|
-
return __generator(this, function (_a) {
|
|
277
|
-
// User has clicked a link
|
|
278
|
-
if (onNavigateRef.current) {
|
|
279
|
-
onNavigateRef.current(path);
|
|
280
|
-
}
|
|
281
|
-
return [2 /*return*/];
|
|
282
|
-
});
|
|
283
|
-
}); },
|
|
284
|
-
onPreload: function (path) {
|
|
285
|
-
if (onPreNavigateRef.current) {
|
|
286
|
-
onPreNavigateRef.current(path);
|
|
287
|
-
}
|
|
288
|
-
},
|
|
289
|
-
});
|
|
290
|
-
}, []);
|
|
291
|
-
onNavigateRef.current = props.onNavigateRequest;
|
|
292
|
-
onPreNavigateRef.current = props.onPreload;
|
|
293
|
-
(0, react_1.useEffect)(function () {
|
|
294
|
-
var cancelled = false;
|
|
295
|
-
var item = createRouteItem(props.url, props.data);
|
|
296
|
-
if (item.href !== ctx.item.href || item.data !== ctx.item.data) {
|
|
297
|
-
ctx.propagateCandidate(item, ctx.item).then(function () {
|
|
298
|
-
if (!cancelled) {
|
|
299
|
-
ctx.propagateChange(item, true);
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
return function () {
|
|
303
|
-
cancelled = true;
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
}, [props.url, props.data]);
|
|
307
|
-
return (0, jsx_runtime_1.jsx)(RouterContext.Provider, __assign({ value: ctx }, { children: props.children }), void 0);
|
|
308
|
-
}
|
|
309
|
-
exports.RouterRoot = RouterRoot;
|
|
310
|
-
exports.Link = (0, react_1.forwardRef)(function (props, ref) {
|
|
311
|
-
var localRef = (0, react_1.useRef)();
|
|
312
|
-
var router = (0, react_1.useContext)(RouterContext);
|
|
313
|
-
(0, react_1.useEffect)(function () {
|
|
314
|
-
if (props.preload && localRef.current) {
|
|
315
|
-
router === null || router === void 0 ? void 0 : router.onPreload(localRef.current.href);
|
|
316
|
-
}
|
|
317
|
-
}, [props.preload]);
|
|
318
|
-
return ((0, jsx_runtime_1.jsx)("a", __assign({ ref: (0, react_merge_refs_1.default)([localRef, ref]) }, props, { onMouseEnter: function (e) {
|
|
319
|
-
if (props.onMouseOver) {
|
|
320
|
-
props.onMouseOver(e);
|
|
321
|
-
}
|
|
322
|
-
router === null || router === void 0 ? void 0 : router.onPreload(e.currentTarget.href);
|
|
323
|
-
}, onClick: function (e) {
|
|
324
|
-
if (process.admin) {
|
|
325
|
-
e.preventDefault();
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
if (props.onClick) {
|
|
329
|
-
props.onClick(e);
|
|
330
|
-
}
|
|
331
|
-
if (!e.isDefaultPrevented() && router && !e.ctrlKey && !e.metaKey) {
|
|
332
|
-
var url = (0, url_parse_1.default)(e.currentTarget.href, true);
|
|
333
|
-
if (url.origin === document.location.origin) {
|
|
334
|
-
router.onNavigate(e.currentTarget.href);
|
|
335
|
-
e.preventDefault();
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
} }), void 0));
|
|
339
|
-
});
|
|
340
|
-
function Switch(_a) {
|
|
341
|
-
var children = _a.children;
|
|
342
|
-
var ctx = useForkedRouter({
|
|
343
|
-
debugName: "SWITCH",
|
|
344
|
-
match: function () {
|
|
345
|
-
return true;
|
|
346
|
-
},
|
|
347
|
-
beforeLeave: function () {
|
|
348
|
-
return undefined;
|
|
349
|
-
},
|
|
350
|
-
}, { isSwitch: true });
|
|
351
|
-
return (0, jsx_runtime_1.jsx)(RouterContext.Provider, __assign({ value: ctx }, { children: children }), void 0);
|
|
352
|
-
}
|
|
353
|
-
exports.Switch = Switch;
|
|
354
|
-
function RouteItemContext(props) {
|
|
355
|
-
var ctx = useForkedRouter({
|
|
356
|
-
match: function () { return true; },
|
|
357
|
-
beforeLeave: undefined,
|
|
358
|
-
debugName: undefined,
|
|
359
|
-
onChange: undefined,
|
|
360
|
-
});
|
|
361
|
-
return (0, jsx_runtime_1.jsx)(RouterContext.Provider, __assign({ value: ctx }, { children: props.children }), void 0);
|
|
362
|
-
}
|
|
363
|
-
exports.RouteItemContext = RouteItemContext;
|