eddev 0.1.33-beta-4 → 0.1.35
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/inlineEditing.js +11 -1
- package/blocks/installGutenbergHooks.js +4 -0
- package/build/babel/plugin-name-defined-components.js +2 -1
- package/build/create-codegen-worker.d.ts +1 -2
- package/build/create-codegen-worker.js +8 -11
- package/build/create-webpack-worker.d.ts +1 -2
- package/build/create-webpack-worker.js +8 -4
- package/build/get-webpack-config.d.ts +1 -10
- package/build/state/codegen-state.d.ts +5 -0
- package/build/state/compiler-state.d.ts +11 -0
- package/build/workers/codegen-worker-script.d.ts +1 -4
- package/build/workers/codegen-worker-script.js +27 -3
- package/build/workers/webpack-worker-script.d.ts +1 -1
- package/build/workers/webpack-worker-script.js +1 -0
- package/cli/build.dev.d.ts +2 -0
- package/cli/build.dev.js +39 -26
- package/cli/cli.js +4 -0
- package/package.json +3 -2
- package/routing/routing.d.ts +29 -0
- package/routing/routing.js +5 -1
package/blocks/inlineEditing.js
CHANGED
|
@@ -30,6 +30,8 @@ var ContentBlocks_1 = require("./ContentBlocks");
|
|
|
30
30
|
var react_1 = require("react");
|
|
31
31
|
var blockAttributes_1 = require("./blockAttributes");
|
|
32
32
|
var react_2 = require("@stitches/react");
|
|
33
|
+
var remoteProps_1 = require("../routing/remoteProps");
|
|
34
|
+
var __1 = require("..");
|
|
33
35
|
function EditableText(_a) {
|
|
34
36
|
var id = _a.id, as = _a.as, props = __rest(_a, ["id", "as"]);
|
|
35
37
|
if (process.admin) {
|
|
@@ -52,7 +54,15 @@ function EditableText(_a) {
|
|
|
52
54
|
return null;
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
|
-
|
|
57
|
+
var router_1 = (0, __1.useRouter)();
|
|
58
|
+
return (0, react_1.createElement)(as || "div", __assign({ dangerouslySetInnerHTML: { __html: value }, onClick: function (e) {
|
|
59
|
+
if (e.target && e.target instanceof HTMLAnchorElement) {
|
|
60
|
+
if ((0, remoteProps_1.isSameOrigin)(e.target.href) && router_1) {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
router_1.onNavigate(e.target.href);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} }, otherProps));
|
|
56
66
|
}
|
|
57
67
|
}
|
|
58
68
|
exports.EditableText = EditableText;
|
|
@@ -74,6 +74,10 @@ function installEDGutenbergHooks() {
|
|
|
74
74
|
item.supports.customClassName = false;
|
|
75
75
|
item.edit = function (props) {
|
|
76
76
|
var self = this;
|
|
77
|
+
(0, react_1.useEffect)(function () {
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
window.wp.data.dispatch("core/block-editor").setTemplateValidity(true);
|
|
80
|
+
}, []);
|
|
77
81
|
return ((0, jsx_runtime_1.jsx)(BlockContext.Provider, __assign({ value: { name: name, props: props } }, { children: (0, jsx_runtime_1.jsx)(blockAttributes_1.InlineEditingContextProvider, __assign({ values: props.attributes.inline || {}, innerBlocks: props.innerBlocks, onChange: function (attrs) {
|
|
78
82
|
props.setAttributes(__assign(__assign({}, props.attributes), { inline: attrs }));
|
|
79
83
|
} }, { children: edit_1.call(self, props) }), void 0) }), void 0));
|
|
@@ -11,6 +11,7 @@ function default_1(_a) {
|
|
|
11
11
|
var args = path.node.arguments;
|
|
12
12
|
if (callee.type === "Identifier" && (callee.name === "defineBlock" || callee.name === "defineView")) {
|
|
13
13
|
// First argument a string literal?
|
|
14
|
+
var type = callee.name === "defineBlock" ? "block" : "view";
|
|
14
15
|
var name_1 = "";
|
|
15
16
|
if (args.length > 0 && args[0].type === "StringLiteral") {
|
|
16
17
|
name_1 = args[0].value;
|
|
@@ -34,7 +35,7 @@ function default_1(_a) {
|
|
|
34
35
|
}
|
|
35
36
|
path.replaceWith(t.callExpression(t.identifier(callee.name), [
|
|
36
37
|
t.stringLiteral(name_1),
|
|
37
|
-
t.functionExpression(t.identifier((0, pascal_case_1.pascalCase)(name_1)), args[1].params, body, args[1].generator, args[1].async),
|
|
38
|
+
t.functionExpression(t.identifier((0, pascal_case_1.pascalCase)(type + "-" + name_1)), args[1].params, body, args[1].generator, args[1].async),
|
|
38
39
|
]));
|
|
39
40
|
}
|
|
40
41
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { Observable } from "../utils/Observable";
|
|
2
|
-
import { CodegenOptions } from "./
|
|
3
|
-
import { CodegenState } from "./state/codegen-state";
|
|
2
|
+
import { CodegenOptions, CodegenState } from "./state/codegen-state";
|
|
4
3
|
export declare function createCodegenWorker(opts: CodegenOptions): Observable<CodegenState>;
|
|
@@ -40,35 +40,32 @@ function createCodegenWorker(opts) {
|
|
|
40
40
|
log: "",
|
|
41
41
|
});
|
|
42
42
|
worker.on("error", function (err) {
|
|
43
|
+
console.log(err);
|
|
43
44
|
subject.update(function (state) { return (__assign(__assign({}, state), { status: "error" })); });
|
|
44
45
|
});
|
|
45
46
|
worker.on("message", function (data) {
|
|
46
47
|
if (data.code === "ready") {
|
|
47
|
-
subject.update(function (state) { return (__assign(__assign({}, state), { status: "ready", log: "", duration: 0, errors: [] })); });
|
|
48
|
+
subject.update(function (state) { return (__assign(__assign({}, state), { status: "ready", log: opts.retainLog ? state.log : "", duration: 0, errors: [] })); });
|
|
48
49
|
}
|
|
49
50
|
else if (data.code === "fetching") {
|
|
50
|
-
subject.update(function (state) { return (__assign(__assign({}, state), { status: "fetching", log: "", duration: 0, errors: [] })); });
|
|
51
|
+
subject.update(function (state) { return (__assign(__assign({}, state), { status: "fetching", log: opts.retainLog ? state.log : "", duration: 0, errors: [] })); });
|
|
51
52
|
}
|
|
52
53
|
else if (data.code === "generating") {
|
|
53
|
-
subject.update(function (state) { return (__assign(__assign({}, state), { status: "generating", errors: [], duration: 0, log: "" })); });
|
|
54
|
+
subject.update(function (state) { return (__assign(__assign({}, state), { status: "generating", errors: [], duration: 0, log: opts.retainLog ? state.log : "" })); });
|
|
54
55
|
}
|
|
55
56
|
else if (data.code === "error") {
|
|
56
57
|
subject.update(function (state) { return (__assign(__assign({}, state), { status: "error", statusLabel: "", duration: 0, reason: undefined, errors: data.errors })); });
|
|
57
58
|
}
|
|
58
59
|
else if (data.code === "success") {
|
|
59
|
-
subject.update(function (state) { return (__assign(__assign({}, state), { status: "success", duration: data.duration, reason: data.reason, errors: [], log: "" })); });
|
|
60
|
+
subject.update(function (state) { return (__assign(__assign({}, state), { status: "success", duration: data.duration, reason: data.reason, errors: [], log: opts.retainLog ? state.log : "" })); });
|
|
60
61
|
}
|
|
61
62
|
else if (data.code === "invalidated") {
|
|
62
63
|
subject.update(function (state) { return (__assign(__assign({}, state), { status: "invalidated", reason: data.reason, duration: 0 })); });
|
|
63
64
|
}
|
|
64
65
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// status: "success",
|
|
69
|
-
// log: "",
|
|
70
|
-
// }))
|
|
71
|
-
// })
|
|
66
|
+
worker.on("exit", function () {
|
|
67
|
+
subject.update(function (state) { return (__assign(__assign({}, state), { status: "success", log: opts.retainLog ? state.log : "" })); });
|
|
68
|
+
});
|
|
72
69
|
return subject;
|
|
73
70
|
}
|
|
74
71
|
exports.createCodegenWorker = createCodegenWorker;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { WebpackWorkerOptions } from "./get-webpack-config";
|
|
2
1
|
import { Observable } from "../utils/Observable";
|
|
3
|
-
import { CompilerState } from "./state/compiler-state";
|
|
2
|
+
import { CompilerState, WebpackWorkerOptions } from "./state/compiler-state";
|
|
4
3
|
export declare function createWebpackWorker(opts: WebpackWorkerOptions): Observable<CompilerState>;
|
|
@@ -27,7 +27,11 @@ function createWebpackWorker(opts) {
|
|
|
27
27
|
subject.update(function (state) { return (__assign(__assign({}, state), { log: (state.log || "") + chunk })); });
|
|
28
28
|
});
|
|
29
29
|
worker.stdout.on("data", function (chunk) {
|
|
30
|
-
|
|
30
|
+
var str = chunk.toString();
|
|
31
|
+
if (str.includes("Project is running at") || str.includes("webpack output is served from")) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
subject.update(function (state) { return (__assign(__assign({}, state), { log: (state.log || "") + str })); });
|
|
31
35
|
});
|
|
32
36
|
var subject = new Observable_1.Observable({
|
|
33
37
|
title: opts.title,
|
|
@@ -38,18 +42,18 @@ function createWebpackWorker(opts) {
|
|
|
38
42
|
});
|
|
39
43
|
worker.on("message", function (data) {
|
|
40
44
|
if (data.code === "compiling") {
|
|
41
|
-
subject.update(function (state) { return (__assign(__assign({}, state), { status: "compiling", statusLabel: state.status === "compiling" ? state.statusLabel : "", log: "", duration: 0, errors: [] })); });
|
|
45
|
+
subject.update(function (state) { return (__assign(__assign({}, state), { status: "compiling", statusLabel: state.status === "compiling" ? state.statusLabel : "", log: opts.retainLog ? state.log : "", duration: 0, errors: [] })); });
|
|
42
46
|
}
|
|
43
47
|
else if (data.code === "error") {
|
|
44
48
|
subject.update(function (state) { return (__assign(__assign({}, state), { status: "error", statusLabel: "", duration: 0, errors: data.errors })); });
|
|
45
49
|
}
|
|
46
50
|
else if (data.code === "finished") {
|
|
47
|
-
subject.update(function (state) { return (__assign(__assign({}, state), { status: data.watching ? "waiting" : "success", statusLabel: "", duration: data.duration, log: "", errors: data.errors })); });
|
|
51
|
+
subject.update(function (state) { return (__assign(__assign({}, state), { status: data.watching ? "waiting" : "success", statusLabel: "", duration: data.duration, log: opts.retainLog ? state.log : "", errors: data.errors })); });
|
|
48
52
|
}
|
|
49
53
|
else if (data.code === "invalidated") {
|
|
50
54
|
subject.update(function (state) { return (__assign(__assign({}, state), { status: "compiling", statusLabel: data.changedFile
|
|
51
55
|
? "Rebuilding (".concat(data.changedFile.replace(opts.baseDirectory, ""), ")")
|
|
52
|
-
: "Rebuilding (changes detected)", log: "", duration: 0, errors: [] })); });
|
|
56
|
+
: "Rebuilding (changes detected)", log: opts.retainLog ? state.log : "", duration: 0, errors: [] })); });
|
|
53
57
|
}
|
|
54
58
|
});
|
|
55
59
|
worker.on("exit", function () {
|
|
@@ -1,12 +1,3 @@
|
|
|
1
1
|
import { Configuration } from "webpack";
|
|
2
|
-
|
|
3
|
-
title: string;
|
|
4
|
-
baseDirectory: string;
|
|
5
|
-
themeName: string;
|
|
6
|
-
mode: "development" | "production";
|
|
7
|
-
target: "client" | "ssr";
|
|
8
|
-
isAdmin: boolean;
|
|
9
|
-
serverless: boolean;
|
|
10
|
-
hotPort?: number;
|
|
11
|
-
};
|
|
2
|
+
import { WebpackWorkerOptions } from "./state/compiler-state";
|
|
12
3
|
export default function getWebpackConfig(opts: WebpackWorkerOptions): Promise<Configuration>;
|
|
@@ -36,3 +36,14 @@ export declare type CompilerSignal = {
|
|
|
36
36
|
watching?: boolean;
|
|
37
37
|
errors?: CompilerError[];
|
|
38
38
|
};
|
|
39
|
+
export declare type WebpackWorkerOptions = {
|
|
40
|
+
title: string;
|
|
41
|
+
baseDirectory: string;
|
|
42
|
+
themeName: string;
|
|
43
|
+
mode: "development" | "production";
|
|
44
|
+
target: "client" | "ssr";
|
|
45
|
+
isAdmin: boolean;
|
|
46
|
+
serverless: boolean;
|
|
47
|
+
hotPort?: number;
|
|
48
|
+
retainLog?: boolean;
|
|
49
|
+
};
|
|
@@ -90,12 +90,14 @@ var url_loader_1 = require("@graphql-tools/url-loader");
|
|
|
90
90
|
var core_1 = require("@graphql-codegen/core");
|
|
91
91
|
var glob_promise_1 = __importDefault(require("glob-promise"));
|
|
92
92
|
var promises_1 = require("fs/promises");
|
|
93
|
+
var cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
93
94
|
// Plugins
|
|
94
95
|
var typescriptPlugin = __importStar(require("@graphql-codegen/typescript"));
|
|
95
96
|
var typescriptOperationsPlugin = __importStar(require("@graphql-codegen/typescript-operations"));
|
|
96
97
|
var CodegenNoDuplicates = __importStar(require("../graphql-codegen/graphql-codegen-no-duplicates"));
|
|
97
98
|
var CodegenFiles = __importStar(require("../graphql-codegen/graphql-codegen-files"));
|
|
98
99
|
var CodegenQueries = __importStar(require("../graphql-codegen/graphql-codegen-queries"));
|
|
100
|
+
var https_1 = require("https");
|
|
99
101
|
var sendSignal = function (sig) {
|
|
100
102
|
if (worker_threads_1.parentPort) {
|
|
101
103
|
worker_threads_1.parentPort.postMessage(sig);
|
|
@@ -134,6 +136,12 @@ function beginWork(opts) {
|
|
|
134
136
|
switch (_a.label) {
|
|
135
137
|
case 0: return [4 /*yield*/, (0, load_1.loadSchema)(endpoint, {
|
|
136
138
|
loaders: [new url_loader_1.UrlLoader()],
|
|
139
|
+
customFetch: function (url, opts) {
|
|
140
|
+
var httpsAgent = new https_1.Agent({
|
|
141
|
+
rejectUnauthorized: false,
|
|
142
|
+
});
|
|
143
|
+
return (0, cross_fetch_1.default)(url, __assign(__assign({}, opts), { agent: httpsAgent }));
|
|
144
|
+
},
|
|
137
145
|
})];
|
|
138
146
|
case 1:
|
|
139
147
|
rawSchema = _a.sent();
|
|
@@ -532,6 +540,7 @@ function writeFileIfUnchanged(file, contents) {
|
|
|
532
540
|
(0, fs_1.writeFileSync)(file, contents);
|
|
533
541
|
}
|
|
534
542
|
function debounce(wait, fn) {
|
|
543
|
+
var _this = this;
|
|
535
544
|
var timeout;
|
|
536
545
|
var debounced = function () {
|
|
537
546
|
var args = [];
|
|
@@ -539,9 +548,24 @@ function debounce(wait, fn) {
|
|
|
539
548
|
args[_i] = arguments[_i];
|
|
540
549
|
}
|
|
541
550
|
clearTimeout(timeout);
|
|
542
|
-
timeout = setTimeout(function () {
|
|
543
|
-
|
|
544
|
-
|
|
551
|
+
timeout = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
552
|
+
var err_4;
|
|
553
|
+
return __generator(this, function (_a) {
|
|
554
|
+
switch (_a.label) {
|
|
555
|
+
case 0:
|
|
556
|
+
_a.trys.push([0, 2, , 3]);
|
|
557
|
+
return [4 /*yield*/, fn.apply(void 0, args)];
|
|
558
|
+
case 1:
|
|
559
|
+
_a.sent();
|
|
560
|
+
return [3 /*break*/, 3];
|
|
561
|
+
case 2:
|
|
562
|
+
err_4 = _a.sent();
|
|
563
|
+
console.error(err_4);
|
|
564
|
+
return [3 /*break*/, 3];
|
|
565
|
+
case 3: return [2 /*return*/];
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
}); }, wait);
|
|
545
569
|
};
|
|
546
570
|
return debounced;
|
|
547
571
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { WebpackWorkerOptions } from "../
|
|
1
|
+
import { WebpackWorkerOptions } from "../state/compiler-state";
|
|
2
2
|
export declare function beginWork(opts: WebpackWorkerOptions): Promise<void>;
|
package/cli/build.dev.d.ts
CHANGED
package/cli/build.dev.js
CHANGED
|
@@ -50,40 +50,53 @@ var create_webpack_worker_1 = require("../build/create-webpack-worker");
|
|
|
50
50
|
var create_codegen_worker_1 = require("../build/create-codegen-worker");
|
|
51
51
|
function devCommand(opts) {
|
|
52
52
|
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
-
var themeName, frontendObservable, adminObservable, codegenObservable;
|
|
53
|
+
var themeName, enableFrontend, enableAdmin, enableCodegen, frontendObservable, adminObservable, codegenObservable;
|
|
54
54
|
return __generator(this, function (_a) {
|
|
55
55
|
switch (_a.label) {
|
|
56
56
|
case 0: return [4 /*yield*/, (0, promptIfRepoNameIncorrect_1.promptIfRepoThemeMismatch)()];
|
|
57
57
|
case 1:
|
|
58
58
|
_a.sent();
|
|
59
59
|
themeName = path_1.default.basename(process.cwd());
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
60
|
+
enableFrontend = !opts.mode || opts.mode === "frontend";
|
|
61
|
+
enableAdmin = !opts.mode || opts.mode === "admin";
|
|
62
|
+
enableCodegen = !opts.mode || opts.mode === "codegen";
|
|
63
|
+
console.log(opts);
|
|
64
|
+
frontendObservable = enableFrontend
|
|
65
|
+
? (0, create_webpack_worker_1.createWebpackWorker)({
|
|
66
|
+
title: "Frontend Bundle",
|
|
67
|
+
baseDirectory: process.cwd() + "/",
|
|
68
|
+
mode: "development",
|
|
69
|
+
target: "client",
|
|
70
|
+
serverless: opts.serverless,
|
|
71
|
+
themeName: themeName,
|
|
72
|
+
isAdmin: false,
|
|
73
|
+
hotPort: 8991,
|
|
74
|
+
retainLog: opts.retainLog,
|
|
75
|
+
})
|
|
76
|
+
: undefined;
|
|
77
|
+
adminObservable = enableAdmin
|
|
78
|
+
? (0, create_webpack_worker_1.createWebpackWorker)({
|
|
79
|
+
title: "Admin Client",
|
|
80
|
+
baseDirectory: process.cwd() + "/",
|
|
81
|
+
mode: "development",
|
|
82
|
+
target: "client",
|
|
83
|
+
serverless: false,
|
|
84
|
+
themeName: themeName,
|
|
85
|
+
isAdmin: true,
|
|
86
|
+
hotPort: 8992,
|
|
87
|
+
retainLog: opts.retainLog,
|
|
88
|
+
})
|
|
89
|
+
: undefined;
|
|
90
|
+
codegenObservable = enableCodegen
|
|
91
|
+
? (0, create_codegen_worker_1.createCodegenWorker)({
|
|
92
|
+
baseDirectory: process.cwd() + "/",
|
|
93
|
+
watch: true,
|
|
94
|
+
retainLog: opts.retainLog,
|
|
95
|
+
})
|
|
96
|
+
: undefined;
|
|
84
97
|
// Set up a process which will regenerate schemas, and watch for changes
|
|
85
98
|
// Render output to screen
|
|
86
|
-
(0, ink_1.render)((0, jsx_runtime_1.jsx)(DevCLIDisplay_1.DevCLIDisplay, { bundles: [frontendObservable, adminObservable], codegen: codegenObservable }, void 0));
|
|
99
|
+
(0, ink_1.render)((0, jsx_runtime_1.jsx)(DevCLIDisplay_1.DevCLIDisplay, { bundles: [frontendObservable, adminObservable].filter(Boolean), codegen: codegenObservable }, void 0));
|
|
87
100
|
return [2 /*return*/];
|
|
88
101
|
}
|
|
89
102
|
});
|
package/cli/cli.js
CHANGED
|
@@ -47,9 +47,13 @@ program
|
|
|
47
47
|
.command("dev")
|
|
48
48
|
.description("Build in dev mode")
|
|
49
49
|
.option("-s, --serverless", 'Build in "serverless" mode', false)
|
|
50
|
+
.option("-m, --mode <mode>", 'Defaults to all modes, but use "frontend", "admin" or "codegen" to run in just one mode', undefined)
|
|
51
|
+
.option("--verbose", "Enables log retention", false)
|
|
50
52
|
.action(function (options) {
|
|
51
53
|
(0, build_dev_1.devCommand)({
|
|
52
54
|
serverless: options.serverless,
|
|
55
|
+
mode: options.mode,
|
|
56
|
+
retainLog: options.verbose,
|
|
53
57
|
});
|
|
54
58
|
});
|
|
55
59
|
program
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eddev",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@graphql-codegen/core": "^2.1.0",
|
|
40
40
|
"@graphql-codegen/typescript": "^2.2.1",
|
|
41
41
|
"@graphql-codegen/typescript-operations": "^2.1.3",
|
|
42
|
-
"@graphql-tools/load": "^7.
|
|
42
|
+
"@graphql-tools/load": "^7.4.1",
|
|
43
43
|
"@graphql-tools/url-loader": "^7.1.0",
|
|
44
44
|
"@loadable/babel-plugin": "^5.13.2",
|
|
45
45
|
"@loadable/component": "^5.15.0",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"change-case": "^4.1.2",
|
|
55
55
|
"chokidar": "^3.5.2",
|
|
56
56
|
"commander": "^8.1.0",
|
|
57
|
+
"cross-fetch": "^3.1.4",
|
|
57
58
|
"css-loader": "^6.2.0",
|
|
58
59
|
"dotenv": "^10.0.0",
|
|
59
60
|
"error-overlay-webpack-plugin": "^1.0.0",
|
package/routing/routing.d.ts
CHANGED
|
@@ -14,7 +14,36 @@ declare type RouteContextConfig = {
|
|
|
14
14
|
beforeLeave?(current: RouteItem, next: RouteItem, parentIsLeaving: boolean): AnyPromise | undefined;
|
|
15
15
|
onChange?(route: RouteItem, status: RouteStatus): void;
|
|
16
16
|
};
|
|
17
|
+
declare type ContextSubscriber = (item: RouteItem, status: RouteStatus) => void;
|
|
18
|
+
declare type ForkOptions = {
|
|
19
|
+
isSwitch?: boolean;
|
|
20
|
+
};
|
|
21
|
+
declare type RouteContextType = {
|
|
22
|
+
parent?: RouteContextType;
|
|
23
|
+
status: RouteStatus;
|
|
24
|
+
loading?: {
|
|
25
|
+
progress: number;
|
|
26
|
+
};
|
|
27
|
+
children: RouteContextType[];
|
|
28
|
+
isSwitch: boolean;
|
|
29
|
+
item: RouteItem;
|
|
30
|
+
config: RouteContextConfig;
|
|
31
|
+
currentMatch: MatchResult;
|
|
32
|
+
propagateChange(current: RouteItem, match: MatchResult): void;
|
|
33
|
+
propagateCandidate(next: RouteItem, prev: RouteItem): AnyPromise;
|
|
34
|
+
propagateLeaving(current: RouteItem, next: RouteItem, parentLeaving: boolean): AnyPromise;
|
|
35
|
+
getFirstMatch: (item: RouteItem) => RouteContextType | undefined;
|
|
36
|
+
onNavigate: (path: string) => void;
|
|
37
|
+
onPreload: (path: string) => void;
|
|
38
|
+
dispose: () => void;
|
|
39
|
+
update: () => void;
|
|
40
|
+
match: (next: RouteItem) => MatchResult;
|
|
41
|
+
matchSelf: (next: RouteItem) => MatchResult;
|
|
42
|
+
subscribe: (handler: ContextSubscriber) => () => void;
|
|
43
|
+
fork(config: RouteContextConfig, opts?: ForkOptions): RouteContextType;
|
|
44
|
+
};
|
|
17
45
|
export declare function useRoute(): RouteItem;
|
|
46
|
+
export declare function useRouter(): RouteContextType | undefined;
|
|
18
47
|
export declare type RouteProps = RouteContextConfig & {
|
|
19
48
|
children: ReactNode;
|
|
20
49
|
};
|
package/routing/routing.js
CHANGED
|
@@ -50,7 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.RouteItemContext = exports.Switch = exports.Link = exports.isInternalPageLink = exports.RouterRoot = exports.createRouteItem = exports.Route = exports.useRoute = void 0;
|
|
53
|
+
exports.RouteItemContext = exports.Switch = exports.Link = exports.isInternalPageLink = exports.RouterRoot = exports.createRouteItem = exports.Route = exports.useRouter = exports.useRoute = void 0;
|
|
54
54
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
55
55
|
var react_1 = require("react");
|
|
56
56
|
var react_merge_refs_1 = __importDefault(require("react-merge-refs"));
|
|
@@ -238,6 +238,10 @@ function useRoute() {
|
|
|
238
238
|
return route;
|
|
239
239
|
}
|
|
240
240
|
exports.useRoute = useRoute;
|
|
241
|
+
function useRouter() {
|
|
242
|
+
return (0, react_1.useContext)(RouterContext);
|
|
243
|
+
}
|
|
244
|
+
exports.useRouter = useRouter;
|
|
241
245
|
function Route(props) {
|
|
242
246
|
var ctx = useForkedRouter({
|
|
243
247
|
match: props.match,
|