eddev 0.1.33-beta-3 → 0.1.34
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 +12 -22
- package/blocks/installGutenbergHooks.d.ts +1 -0
- package/blocks/installGutenbergHooks.js +31 -6
- package/build/babel/plugin-name-defined-components.d.ts +7 -0
- package/build/babel/plugin-name-defined-components.js +47 -0
- package/build/create-codegen-worker.d.ts +2 -3
- package/build/create-codegen-worker.js +9 -12
- package/build/create-webpack-worker.d.ts +2 -3
- package/build/create-webpack-worker.js +9 -5
- package/build/get-webpack-config.d.ts +1 -10
- package/build/get-webpack-config.js +23 -14
- 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 +2 -0
- package/cli/build.dev.d.ts +2 -0
- package/cli/build.dev.js +39 -26
- package/cli/cli.js +4 -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 +3 -2
- package/{utils → routing}/remoteProps.d.ts +8 -0
- package/{utils → routing}/remoteProps.js +1 -1
- package/routing/routing.d.ts +30 -1
- package/routing/routing.js +5 -1
- 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
package/blocks/ContentBlocks.js
CHANGED
|
@@ -29,6 +29,7 @@ var jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
29
29
|
var blocks_1 = __importDefault(require("@manifest/blocks"));
|
|
30
30
|
var blockAttributes_1 = require("./blockAttributes");
|
|
31
31
|
var react_1 = require("react");
|
|
32
|
+
var ErrorBoundaryFrontend_1 = require("./ErrorBoundaryFrontend");
|
|
32
33
|
exports.BlocksContext = (0, react_1.createContext)(undefined);
|
|
33
34
|
function ContentBlocks(props) {
|
|
34
35
|
if (!Array.isArray(props.blocks))
|
|
@@ -81,7 +82,7 @@ function ContentBlocks(props) {
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
// Attempt to wrap the block
|
|
84
|
-
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [spaceBefore, blockNode, spaceAfter] }, index));
|
|
85
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [spaceBefore, (0, jsx_runtime_1.jsx)(ErrorBoundaryFrontend_1.ErrorBoundaryFrontend, { children: blockNode }, void 0), spaceAfter] }, index));
|
|
85
86
|
});
|
|
86
87
|
}, [blocks, props.wrapBlock, props.spacer]);
|
|
87
88
|
return (0, jsx_runtime_1.jsx)(react_1.Fragment, { children: layout }, void 0);
|
|
@@ -6,7 +6,7 @@ interface State {
|
|
|
6
6
|
hasError: boolean;
|
|
7
7
|
error?: Error;
|
|
8
8
|
}
|
|
9
|
-
export declare class
|
|
9
|
+
export declare class ErrorBoundaryEditor extends Component<Props, State> {
|
|
10
10
|
state: State;
|
|
11
11
|
static getDerivedStateFromError(err: Error): State;
|
|
12
12
|
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
@@ -26,26 +26,26 @@ var __assign = (this && this.__assign) || function () {
|
|
|
26
26
|
return __assign.apply(this, arguments);
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.ErrorBoundaryEditor = void 0;
|
|
30
30
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
31
31
|
var react_1 = require("react");
|
|
32
|
-
var
|
|
33
|
-
__extends(
|
|
34
|
-
function
|
|
32
|
+
var ErrorBoundaryEditor = /** @class */ (function (_super) {
|
|
33
|
+
__extends(ErrorBoundaryEditor, _super);
|
|
34
|
+
function ErrorBoundaryEditor() {
|
|
35
35
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
36
36
|
_this.state = {
|
|
37
37
|
hasError: false,
|
|
38
38
|
};
|
|
39
39
|
return _this;
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
ErrorBoundaryEditor.getDerivedStateFromError = function (err) {
|
|
42
42
|
// Update state so the next render will show the fallback UI.
|
|
43
43
|
return { hasError: true, error: err };
|
|
44
44
|
};
|
|
45
|
-
|
|
45
|
+
ErrorBoundaryEditor.prototype.componentDidCatch = function (error, errorInfo) {
|
|
46
46
|
console.error("Uncaught error:", error, errorInfo);
|
|
47
47
|
};
|
|
48
|
-
|
|
48
|
+
ErrorBoundaryEditor.prototype.render = function () {
|
|
49
49
|
if (this.state.hasError) {
|
|
50
50
|
var err = this.state.error;
|
|
51
51
|
return ((0, jsx_runtime_1.jsx)("pre", __assign({ style: {
|
|
@@ -59,6 +59,6 @@ var EditorErrorBoundary = /** @class */ (function (_super) {
|
|
|
59
59
|
}
|
|
60
60
|
return this.props.children;
|
|
61
61
|
};
|
|
62
|
-
return
|
|
62
|
+
return ErrorBoundaryEditor;
|
|
63
63
|
}(react_1.Component));
|
|
64
|
-
exports.
|
|
64
|
+
exports.ErrorBoundaryEditor = ErrorBoundaryEditor;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { Component, ErrorInfo, ReactNode } from "react";
|
|
2
|
+
interface Props {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
}
|
|
5
|
+
interface State {
|
|
6
|
+
hasError: boolean;
|
|
7
|
+
error?: Error;
|
|
8
|
+
}
|
|
9
|
+
export declare class ErrorBoundaryFrontend extends Component<Props, State> {
|
|
10
|
+
state: State;
|
|
11
|
+
static getDerivedStateFromError(err: Error): State;
|
|
12
|
+
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
13
|
+
render(): React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.ErrorBoundaryFrontend = void 0;
|
|
30
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
31
|
+
var react_1 = require("react");
|
|
32
|
+
var ErrorBoundaryFrontend = /** @class */ (function (_super) {
|
|
33
|
+
__extends(ErrorBoundaryFrontend, _super);
|
|
34
|
+
function ErrorBoundaryFrontend() {
|
|
35
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
36
|
+
_this.state = {
|
|
37
|
+
hasError: false,
|
|
38
|
+
};
|
|
39
|
+
return _this;
|
|
40
|
+
}
|
|
41
|
+
ErrorBoundaryFrontend.getDerivedStateFromError = function (err) {
|
|
42
|
+
// Update state so the next render will show the fallback UI.
|
|
43
|
+
return { hasError: true, error: err };
|
|
44
|
+
};
|
|
45
|
+
ErrorBoundaryFrontend.prototype.componentDidCatch = function (error, errorInfo) {
|
|
46
|
+
console.error("Uncaught error:", error, errorInfo);
|
|
47
|
+
};
|
|
48
|
+
ErrorBoundaryFrontend.prototype.render = function () {
|
|
49
|
+
if (this.state.hasError) {
|
|
50
|
+
var err = this.state.error;
|
|
51
|
+
if (process.dev) {
|
|
52
|
+
return ((0, jsx_runtime_1.jsx)("pre", __assign({ style: {
|
|
53
|
+
fontSize: "12px",
|
|
54
|
+
color: "red",
|
|
55
|
+
border: "1px solid red",
|
|
56
|
+
borderRadius: "4px",
|
|
57
|
+
padding: "4px",
|
|
58
|
+
overflowX: "auto",
|
|
59
|
+
} }, { children: err.stack }), void 0));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return this.props.children;
|
|
66
|
+
};
|
|
67
|
+
return ErrorBoundaryFrontend;
|
|
68
|
+
}(react_1.Component));
|
|
69
|
+
exports.ErrorBoundaryFrontend = ErrorBoundaryFrontend;
|
package/blocks/index.d.ts
CHANGED
package/blocks/index.js
CHANGED
|
@@ -11,7 +11,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.useInnerBlocks = exports.useInlineEditableValue = void 0;
|
|
14
|
-
__exportStar(require("./installGutenbergHooks"), exports);
|
|
15
14
|
__exportStar(require("./defineBlock"), exports);
|
|
16
15
|
__exportStar(require("./inlineEditing"), exports);
|
|
17
16
|
__exportStar(require("./ContentBlocks"), exports);
|
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,35 +54,23 @@ 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;
|
|
59
|
-
function getTaggedBlocks(tag) {
|
|
60
|
-
// @ts-ignore
|
|
61
|
-
return wp.blocks
|
|
62
|
-
.getBlockTypes()
|
|
63
|
-
.filter(function (block) {
|
|
64
|
-
if (!Array.isArray(block.tags))
|
|
65
|
-
return false;
|
|
66
|
-
if (typeof tag === "string") {
|
|
67
|
-
return block.tags.includes(tag);
|
|
68
|
-
}
|
|
69
|
-
else if (Array.isArray(tag)) {
|
|
70
|
-
return !!block.tags.find(function (t) { return tag.includes(t); });
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
.map(function (block) { return block.name; });
|
|
74
|
-
}
|
|
75
69
|
function InnerBlocks(props) {
|
|
76
70
|
if (process.admin) {
|
|
77
71
|
var allowedBlocks = props.allowedBlocks;
|
|
78
72
|
// console.log("ALLOWED BLOCKS", props.allowTaggedBlocks, allowedBlocks)
|
|
79
|
-
return ((0, jsx_runtime_1.jsx)(InnerBlocksAdminWrapper, __assign({ orientation: props.orientation || "vertical" }, { children: (0, jsx_runtime_1.jsx)(block_editor_1.InnerBlocks
|
|
80
|
-
// @ts-ignore
|
|
81
|
-
, {
|
|
82
|
-
// @ts-ignore
|
|
83
|
-
orientation: props.orientation, allowedBlocks: allowedBlocks, renderAppender: props.renderAppender, templateLock: props.templateLock, template: props.template }, void 0) }), void 0));
|
|
73
|
+
return ((0, jsx_runtime_1.jsx)(InnerBlocksAdminWrapper, __assign({ orientation: props.orientation || "vertical" }, { children: (0, jsx_runtime_1.jsx)(block_editor_1.InnerBlocks, { orientation: props.orientation, allowedBlocks: allowedBlocks, renderAppender: props.renderAppender, templateLock: props.templateLock, template: props.template }, void 0) }), void 0));
|
|
84
74
|
}
|
|
85
75
|
else {
|
|
86
76
|
var blocks = (0, blockAttributes_1.useInnerBlocks)();
|
|
@@ -23,18 +23,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.installEDGutenbergHooks = void 0;
|
|
26
|
+
exports.setBlockManifest = exports.installEDGutenbergHooks = void 0;
|
|
27
27
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
28
28
|
// @ts-ignore
|
|
29
29
|
var hooks_1 = require("@wordpress/hooks");
|
|
30
30
|
var react_1 = require("react");
|
|
31
31
|
// @ts-ignore
|
|
32
|
-
var blocks_1 = __importDefault(require("@manifest/blocks"));
|
|
33
|
-
// @ts-ignore
|
|
34
32
|
var blockAttributes_1 = require("./blockAttributes");
|
|
35
|
-
var
|
|
33
|
+
var ErrorBoundaryEditor_1 = require("./ErrorBoundaryEditor");
|
|
36
34
|
var react_2 = require("@stitches/react");
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
var blocks_1 = __importDefault(require("@manifest/blocks"));
|
|
37
|
+
var Observable_1 = require("../utils/Observable");
|
|
38
|
+
var useObservable_1 = require("../utils/useObservable");
|
|
37
39
|
var BlockContext = (0, react_1.createContext)(undefined);
|
|
40
|
+
// Store the block manifest as a local variable
|
|
41
|
+
var blocksManifest = new Observable_1.Observable(blocks_1.default);
|
|
38
42
|
function installEDGutenbergHooks() {
|
|
39
43
|
(0, react_2.globalCss)({
|
|
40
44
|
".block-editor-block-list__block:hover": {
|
|
@@ -70,6 +74,10 @@ function installEDGutenbergHooks() {
|
|
|
70
74
|
item.supports.customClassName = false;
|
|
71
75
|
item.edit = function (props) {
|
|
72
76
|
var self = this;
|
|
77
|
+
(0, react_1.useEffect)(function () {
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
window.wp.data.dispatch("core/block-editor").setTemplateValidity(true);
|
|
80
|
+
}, []);
|
|
73
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) {
|
|
74
82
|
props.setAttributes(__assign(__assign({}, props.attributes), { inline: attrs }));
|
|
75
83
|
} }, { children: edit_1.call(self, props) }), void 0) }), void 0));
|
|
@@ -129,8 +137,13 @@ function installEDGutenbergHooks() {
|
|
|
129
137
|
function BlockRenderer(_a) {
|
|
130
138
|
var payload = _a.payload;
|
|
131
139
|
var block = (0, react_1.useContext)(BlockContext);
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
if (!block)
|
|
141
|
+
return null;
|
|
142
|
+
var manifest = (0, useObservable_1.useObservable)(blocksManifest);
|
|
143
|
+
var BlockComponent = manifest[block.name];
|
|
144
|
+
if (!BlockComponent)
|
|
145
|
+
return (0, jsx_runtime_1.jsx)("div", { children: "Unable to load block component" }, void 0);
|
|
146
|
+
return ((0, jsx_runtime_1.jsx)(ErrorBoundaryEditor_1.ErrorBoundaryEditor, { children: (0, jsx_runtime_1.jsx)(BlockComponent, __assign({}, payload), void 0) }, void 0));
|
|
134
147
|
}
|
|
135
148
|
// @ts-ignore
|
|
136
149
|
var parseJSX = acf.parseJSX;
|
|
@@ -141,3 +154,15 @@ function installEDGutenbergHooks() {
|
|
|
141
154
|
};
|
|
142
155
|
}
|
|
143
156
|
exports.installEDGutenbergHooks = installEDGutenbergHooks;
|
|
157
|
+
function setBlockManifest(manifest) {
|
|
158
|
+
blocksManifest.update(manifest);
|
|
159
|
+
}
|
|
160
|
+
exports.setBlockManifest = setBlockManifest;
|
|
161
|
+
// @ts-ignore
|
|
162
|
+
if (import.meta.webpackHot) {
|
|
163
|
+
// @ts-ignore
|
|
164
|
+
import.meta.webpackHot.accept([require.resolve("@manifest/blocks")], function () {
|
|
165
|
+
var updatedManifest = require("@manifest/blocks").default;
|
|
166
|
+
setBlockManifest(updatedManifest);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var pascal_case_1 = require("pascal-case");
|
|
4
|
+
function default_1(_a) {
|
|
5
|
+
var t = _a.types;
|
|
6
|
+
return {
|
|
7
|
+
visitor: {
|
|
8
|
+
CallExpression: function (path, state) {
|
|
9
|
+
// Does the call expression name match defineBlock or defineView?
|
|
10
|
+
var callee = path.node.callee;
|
|
11
|
+
var args = path.node.arguments;
|
|
12
|
+
if (callee.type === "Identifier" && (callee.name === "defineBlock" || callee.name === "defineView")) {
|
|
13
|
+
// First argument a string literal?
|
|
14
|
+
var type = callee.name === "defineBlock" ? "block" : "view";
|
|
15
|
+
var name_1 = "";
|
|
16
|
+
if (args.length > 0 && args[0].type === "StringLiteral") {
|
|
17
|
+
name_1 = args[0].value;
|
|
18
|
+
// While we're here, make sure that the name matches the filename
|
|
19
|
+
var filename = state.file.opts.filename;
|
|
20
|
+
var expectedName = filename
|
|
21
|
+
.replace(state.opts.baseDirectory, "")
|
|
22
|
+
.replace(/\.tsx?$/, "")
|
|
23
|
+
.replace(/^\/?(blocks|views)\//, "");
|
|
24
|
+
if (name_1 !== expectedName) {
|
|
25
|
+
throw path.buildCodeFrameError("The name in your ".concat(callee.name, " didn't match the filename!\n\nDid you mean ").concat(callee.name, "(\"").concat(expectedName, "\")?"));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// Second argument an arrow function?
|
|
29
|
+
if (args.length === 2) {
|
|
30
|
+
if (args[1].type === "ArrowFunctionExpression") {
|
|
31
|
+
// Great! Replace the arrow function with a normal function
|
|
32
|
+
var body = args[1].body;
|
|
33
|
+
if (t.isExpression(body)) {
|
|
34
|
+
body = t.blockStatement([t.returnStatement(body)]);
|
|
35
|
+
}
|
|
36
|
+
path.replaceWith(t.callExpression(t.identifier(callee.name), [
|
|
37
|
+
t.stringLiteral(name_1),
|
|
38
|
+
t.functionExpression(t.identifier((0, pascal_case_1.pascalCase)(type + "-" + name_1)), args[1].params, body, args[1].generator, args[1].async),
|
|
39
|
+
]));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
exports.default = default_1;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Observable } from "../
|
|
2
|
-
import { CodegenOptions } from "./
|
|
3
|
-
import { CodegenState } from "./state/codegen-state";
|
|
1
|
+
import { Observable } from "../utils/Observable";
|
|
2
|
+
import { CodegenOptions, CodegenState } from "./state/codegen-state";
|
|
4
3
|
export declare function createCodegenWorker(opts: CodegenOptions): Observable<CodegenState>;
|
|
@@ -14,7 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.createCodegenWorker = void 0;
|
|
15
15
|
var worker_threads_1 = require("worker_threads");
|
|
16
16
|
var path_1 = require("path");
|
|
17
|
-
var Observable_1 = require("../
|
|
17
|
+
var Observable_1 = require("../utils/Observable");
|
|
18
18
|
function createCodegenWorker(opts) {
|
|
19
19
|
var worker = new worker_threads_1.Worker((0, path_1.join)(__dirname, "workers/codegen-worker-script.js"), {
|
|
20
20
|
workerData: opts,
|
|
@@ -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 {
|
|
2
|
-
import {
|
|
3
|
-
import { CompilerState } from "./state/compiler-state";
|
|
1
|
+
import { Observable } from "../utils/Observable";
|
|
2
|
+
import { CompilerState, WebpackWorkerOptions } from "./state/compiler-state";
|
|
4
3
|
export declare function createWebpackWorker(opts: WebpackWorkerOptions): Observable<CompilerState>;
|
|
@@ -14,7 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.createWebpackWorker = void 0;
|
|
15
15
|
var worker_threads_1 = require("worker_threads");
|
|
16
16
|
var path_1 = require("path");
|
|
17
|
-
var Observable_1 = require("../
|
|
17
|
+
var Observable_1 = require("../utils/Observable");
|
|
18
18
|
function createWebpackWorker(opts) {
|
|
19
19
|
var worker = new worker_threads_1.Worker((0, path_1.join)(__dirname, "workers/webpack-worker-script.js"), {
|
|
20
20
|
workerData: opts,
|
|
@@ -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>;
|
|
@@ -74,6 +74,8 @@ var webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
|
|
|
74
74
|
// @ts-ignore
|
|
75
75
|
var mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
|
|
76
76
|
var autoprefixer_1 = __importDefault(require("autoprefixer"));
|
|
77
|
+
// Custom Babel plugins
|
|
78
|
+
var plugin_name_defined_components_1 = __importDefault(require("./babel/plugin-name-defined-components"));
|
|
77
79
|
function getWebpackConfig(opts) {
|
|
78
80
|
return __awaiter(this, void 0, void 0, function () {
|
|
79
81
|
var compiling, ALIAS, ENTRY, PLUGINS, RULES, DEFINES, VIRTUAL_MODULES, EXTERNALS, virtualModules, isServerless, isBrowser, isSSR, isDev, entryDir, distSuffix, outputFolder, loadableManifestFile, writeVirtualModule, updateTemplateRouter, templateLookupPattern, _a, updateBlocksManifest, blockLookupManifest, _b, buildID;
|
|
@@ -150,7 +152,8 @@ function getWebpackConfig(opts) {
|
|
|
150
152
|
require.resolve("@babel/preset-typescript"),
|
|
151
153
|
],
|
|
152
154
|
plugins: [
|
|
153
|
-
|
|
155
|
+
[plugin_name_defined_components_1.default, { baseDirectory: opts.baseDirectory, cool: true }],
|
|
156
|
+
isBrowser && isDev && !opts.isAdmin && [require.resolve("react-refresh/babel"), { skipEnvCheck: true }],
|
|
154
157
|
require.resolve("@loadable/babel-plugin"),
|
|
155
158
|
].filter(Boolean),
|
|
156
159
|
},
|
|
@@ -191,17 +194,6 @@ function getWebpackConfig(opts) {
|
|
|
191
194
|
},
|
|
192
195
|
],
|
|
193
196
|
});
|
|
194
|
-
// Define some values
|
|
195
|
-
DEFINES["process.browser"] = JSON.stringify(isBrowser);
|
|
196
|
-
DEFINES["process.ssr"] = JSON.stringify(isServerless && !isBrowser);
|
|
197
|
-
DEFINES["process.LOADABLE_STATS_FILE"] = JSON.stringify(loadableManifestFile);
|
|
198
|
-
DEFINES["process.dev"] = isDev ? "true" : "false";
|
|
199
|
-
DEFINES["process.admin"] = opts.isAdmin ? "true" : "false";
|
|
200
|
-
DEFINES["process.env.themePath"] = JSON.stringify("/wp-content/themes/".concat(opts.themeName));
|
|
201
|
-
DEFINES["process.themePath"] = JSON.stringify("/wp-content/themes/".concat(opts.themeName));
|
|
202
|
-
if (isBrowser) {
|
|
203
|
-
DEFINES["process.env.themePath"] = "window.THEME_PATH || ".concat(DEFINES["process.env.themePath"]);
|
|
204
|
-
}
|
|
205
197
|
// Bundle analyser
|
|
206
198
|
if (!opts.isAdmin && !isDev) {
|
|
207
199
|
PLUGINS.push(new webpack_bundle_analyzer_1.BundleAnalyzerPlugin({
|
|
@@ -211,10 +203,12 @@ function getWebpackConfig(opts) {
|
|
|
211
203
|
}));
|
|
212
204
|
}
|
|
213
205
|
// React Refresh
|
|
214
|
-
if (isBrowser && isDev) {
|
|
206
|
+
if (isBrowser && isDev && !opts.isAdmin) {
|
|
215
207
|
PLUGINS.push(new react_refresh_webpack_plugin_1.default({
|
|
216
208
|
overlay: {
|
|
217
209
|
// module: require.resolve("../utils/refreshOverlayInterop"),
|
|
210
|
+
// @ts-ignore
|
|
211
|
+
// sockProtocol: "http",
|
|
218
212
|
sockHost: "127.0.0.1",
|
|
219
213
|
sockPort: opts.hotPort,
|
|
220
214
|
sockIntegration: "wds",
|
|
@@ -308,7 +302,8 @@ function getWebpackConfig(opts) {
|
|
|
308
302
|
var componentName = (0, change_case_1.pascalCase)(name);
|
|
309
303
|
return { relative: relative, name: name, module: module, componentName: componentName };
|
|
310
304
|
});
|
|
311
|
-
|
|
305
|
+
var useLoadableBlocks = opts.isAdmin && !isDev;
|
|
306
|
+
if (useLoadableBlocks) {
|
|
312
307
|
writeVirtualModule(ALIAS["@manifest/blocks"], "\n import coreBlocks from './blocks/_core.tsx'\n ".concat(!isServerless && "import loadable from '".concat(require.resolve("@loadable/component"), "';"), "\n\n export default {\n ...coreBlocks,\n ").concat(files
|
|
313
308
|
.map(function (_a) {
|
|
314
309
|
var relative = _a.relative, componentName = _a.componentName, module = _a.module;
|
|
@@ -360,6 +355,20 @@ function getWebpackConfig(opts) {
|
|
|
360
355
|
if (opts.isAdmin) {
|
|
361
356
|
EXTERNALS["react"] = "React";
|
|
362
357
|
}
|
|
358
|
+
// Define some values
|
|
359
|
+
DEFINES["process.browser"] = JSON.stringify(isBrowser);
|
|
360
|
+
DEFINES["process.ssr"] = JSON.stringify(isServerless && !isBrowser);
|
|
361
|
+
DEFINES["process.LOADABLE_STATS_FILE"] = JSON.stringify(loadableManifestFile);
|
|
362
|
+
DEFINES["process.dev"] = isDev ? "true" : "false";
|
|
363
|
+
DEFINES["process.admin"] = opts.isAdmin ? "true" : "false";
|
|
364
|
+
DEFINES["process.env.themePath"] = JSON.stringify("/wp-content/themes/".concat(opts.themeName));
|
|
365
|
+
DEFINES["process.themePath"] = JSON.stringify("/wp-content/themes/".concat(opts.themeName));
|
|
366
|
+
if (isDev && opts.isAdmin) {
|
|
367
|
+
DEFINES["process.BLOCK_MANIFEST_FILE"] = JSON.stringify(ALIAS["@manifest/blocks"]);
|
|
368
|
+
}
|
|
369
|
+
if (isBrowser) {
|
|
370
|
+
DEFINES["process.env.themePath"] = "window.THEME_PATH || ".concat(DEFINES["process.env.themePath"]);
|
|
371
|
+
}
|
|
363
372
|
buildID = Date.now();
|
|
364
373
|
return [2 /*return*/, {
|
|
365
374
|
mode: opts.mode,
|
|
@@ -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
|
+
};
|