eddev 0.2.1 → 0.2.2-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 +3 -0
- package/blocks/blockAttributes.d.ts +2 -0
- package/blocks/blockAttributes.js +7 -1
- package/blocks/inlineEditing.d.ts +2 -0
- package/blocks/inlineEditing.js +10 -2
- package/blocks/installGutenbergHooks.js +24 -3
- package/build/graphql-codegen/graphql-codegen-blocks.js +0 -1
- package/build/serverless/create-next-app.js +0 -4
- package/package.json +1 -1
package/blocks/ContentBlocks.js
CHANGED
|
@@ -32,6 +32,9 @@ var react_1 = require("react");
|
|
|
32
32
|
var ErrorBoundaryFrontend_1 = require("./ErrorBoundaryFrontend");
|
|
33
33
|
exports.BlocksContext = (0, react_1.createContext)(undefined);
|
|
34
34
|
function ContentBlocks(props) {
|
|
35
|
+
if (process.admin) {
|
|
36
|
+
throw new Error("ContentBlocks should only be used on the frontend.");
|
|
37
|
+
}
|
|
35
38
|
if (!Array.isArray(props.blocks))
|
|
36
39
|
return null;
|
|
37
40
|
var parentContext = (0, react_1.useContext)(exports.BlocksContext);
|
|
@@ -7,8 +7,10 @@ declare type ProviderProps = PropsWithChildren<{
|
|
|
7
7
|
values: Attributes;
|
|
8
8
|
innerBlocks: ContentBlock[];
|
|
9
9
|
onChange?: (attrs: Attributes) => void;
|
|
10
|
+
insertBlocksAfter?: (block: any) => void;
|
|
10
11
|
}>;
|
|
11
12
|
export declare function InlineEditingContextProvider(props: ProviderProps): JSX.Element;
|
|
12
13
|
export declare function useInlineEditableValue<T>(key: string, defaultValue?: T): [T, (value: T) => void];
|
|
14
|
+
export declare function useBlockAppender(): ((block: any) => void) | undefined;
|
|
13
15
|
export declare function useInnerBlocks(): ContentBlock[];
|
|
14
16
|
export {};
|
|
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.useInnerBlocks = exports.useInlineEditableValue = exports.InlineEditingContextProvider = void 0;
|
|
14
|
+
exports.useInnerBlocks = exports.useBlockAppender = exports.useInlineEditableValue = exports.InlineEditingContextProvider = void 0;
|
|
15
15
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
16
|
var react_1 = require("react");
|
|
17
17
|
var InlineEditingContext = (0, react_1.createContext)(undefined);
|
|
@@ -29,6 +29,7 @@ function InlineEditingContextProvider(props) {
|
|
|
29
29
|
props.onChange(__assign(__assign({}, (props.values || {})), (_a = {}, _a[key] = value, _a)));
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
|
+
insertBlocksAfter: props.insertBlocksAfter,
|
|
32
33
|
} }, { children: props.children }), void 0));
|
|
33
34
|
}
|
|
34
35
|
exports.InlineEditingContextProvider = InlineEditingContextProvider;
|
|
@@ -43,6 +44,11 @@ function useInlineEditableValue(key, defaultValue) {
|
|
|
43
44
|
];
|
|
44
45
|
}
|
|
45
46
|
exports.useInlineEditableValue = useInlineEditableValue;
|
|
47
|
+
function useBlockAppender() {
|
|
48
|
+
var ctx = (0, react_1.useContext)(InlineEditingContext);
|
|
49
|
+
return ctx === null || ctx === void 0 ? void 0 : ctx.insertBlocksAfter;
|
|
50
|
+
}
|
|
51
|
+
exports.useBlockAppender = useBlockAppender;
|
|
46
52
|
function useInnerBlocks() {
|
|
47
53
|
var ctx = (0, react_1.useContext)(InlineEditingContext);
|
|
48
54
|
return (ctx === null || ctx === void 0 ? void 0 : ctx.innerBlocks) || [];
|
|
@@ -11,6 +11,8 @@ declare type PropTypes<T extends ElementType> = {
|
|
|
11
11
|
inlineToolbar?: boolean;
|
|
12
12
|
/** Specify default content to use on the frontend if nothing has been entered */
|
|
13
13
|
defaultValue?: string;
|
|
14
|
+
/** Append a new block when the user hits 'Enter' */
|
|
15
|
+
appendOnEnter?: boolean;
|
|
14
16
|
} & React.ComponentPropsWithoutRef<T>;
|
|
15
17
|
export declare function EditableText<T extends ElementType>({ id, as, ...props }: PropTypes<T>): JSX.Element | null;
|
|
16
18
|
declare type InnerBlocksProps = {
|
package/blocks/inlineEditing.js
CHANGED
|
@@ -26,6 +26,8 @@ exports.InnerBlocks = exports.EditableText = void 0;
|
|
|
26
26
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
27
27
|
// @ts-ignore
|
|
28
28
|
var block_editor_1 = require("@wordpress/block-editor");
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
var blocks_1 = require("@wordpress/blocks");
|
|
29
31
|
var ContentBlocks_1 = require("./ContentBlocks");
|
|
30
32
|
var react_1 = require("react");
|
|
31
33
|
var blockAttributes_1 = require("./blockAttributes");
|
|
@@ -36,7 +38,14 @@ function EditableText(_a) {
|
|
|
36
38
|
var id = _a.id, as = _a.as, props = __rest(_a, ["id", "as"]);
|
|
37
39
|
if (process.admin) {
|
|
38
40
|
var _b = (0, blockAttributes_1.useInlineEditableValue)(id), value = _b[0], setValue = _b[1];
|
|
39
|
-
|
|
41
|
+
var appendBlocks_1 = (0, blockAttributes_1.useBlockAppender)();
|
|
42
|
+
return ((0, jsx_runtime_1.jsx)(block_editor_1.RichText, __assign({}, props, { tagName: as, value: value || "", onChange: setValue, disableLineBreaks: props.disableLineBreaks, onKeyDownCapture: function (e) {
|
|
43
|
+
if (e.key === "Enter" && props.appendOnEnter && appendBlocks_1) {
|
|
44
|
+
appendBlocks_1([(0, blocks_1.createBlock)("core/paragraph")]);
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
e.stopPropagation();
|
|
47
|
+
}
|
|
48
|
+
} }), void 0));
|
|
40
49
|
}
|
|
41
50
|
else {
|
|
42
51
|
var value = (0, blockAttributes_1.useInlineEditableValue)(id)[0];
|
|
@@ -69,7 +78,6 @@ exports.EditableText = EditableText;
|
|
|
69
78
|
function InnerBlocks(props) {
|
|
70
79
|
if (process.admin) {
|
|
71
80
|
var allowedBlocks = props.allowedBlocks;
|
|
72
|
-
// console.log("ALLOWED BLOCKS", props.allowTaggedBlocks, allowedBlocks)
|
|
73
81
|
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));
|
|
74
82
|
}
|
|
75
83
|
else {
|
|
@@ -27,6 +27,8 @@ 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
|
+
// @ts-ignore
|
|
31
|
+
var data_1 = require("@wordpress/data");
|
|
30
32
|
var react_1 = require("react");
|
|
31
33
|
// @ts-ignore
|
|
32
34
|
var blockAttributes_1 = require("./blockAttributes");
|
|
@@ -45,6 +47,11 @@ function installEDGutenbergHooks() {
|
|
|
45
47
|
if (!window.wp.blockEditor)
|
|
46
48
|
return;
|
|
47
49
|
(0, react_2.globalCss)({
|
|
50
|
+
".edit-post-visual-editor__post-title-wrapper": {
|
|
51
|
+
width: "var(--grid-inner-width)",
|
|
52
|
+
marginLeft: "auto",
|
|
53
|
+
marginRight: "auto",
|
|
54
|
+
},
|
|
48
55
|
".block-editor-block-list__block:hover": {
|
|
49
56
|
outline: "1px solid #e1e1e1",
|
|
50
57
|
},
|
|
@@ -82,9 +89,17 @@ function installEDGutenbergHooks() {
|
|
|
82
89
|
// @ts-ignore
|
|
83
90
|
window.wp.data.dispatch("core/block-editor").setTemplateValidity(true);
|
|
84
91
|
}, []);
|
|
85
|
-
|
|
92
|
+
var children = (0, data_1.useSelect)(function (select) {
|
|
93
|
+
var _a = select("core/block-editor"), getBlock = _a.getBlock, getBlockOrder = _a.getBlockOrder;
|
|
94
|
+
var innerBlockIDs = getBlockOrder(props.clientId);
|
|
95
|
+
var children = innerBlockIDs.map(function (id) {
|
|
96
|
+
return getBlock(id);
|
|
97
|
+
});
|
|
98
|
+
return children;
|
|
99
|
+
}, []);
|
|
100
|
+
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: children, onChange: function (attrs) {
|
|
86
101
|
props.setAttributes(__assign(__assign({}, props.attributes), { inline: attrs }));
|
|
87
|
-
} }, { children: edit_1.call(self, props) }), void 0) }), void 0));
|
|
102
|
+
}, insertBlocksAfter: props.insertBlocksAfter }, { children: edit_1.call(self, props) }), void 0) }), void 0));
|
|
88
103
|
};
|
|
89
104
|
}
|
|
90
105
|
// Remember the block type name
|
|
@@ -154,7 +169,13 @@ function installEDGutenbergHooks() {
|
|
|
154
169
|
var parseJSX = acf.parseJSX;
|
|
155
170
|
// @ts-ignore
|
|
156
171
|
acf.parseJSX = function (html) {
|
|
157
|
-
var payload
|
|
172
|
+
var payload;
|
|
173
|
+
try {
|
|
174
|
+
payload = JSON.parse(html.replace(/(^[^>]+>|<[^>]+>$)/g, ""));
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
throw new Error("eddev: Error parsing block data from: \n" + html);
|
|
178
|
+
}
|
|
158
179
|
return (0, jsx_runtime_1.jsx)(BlockRenderer, { payload: payload }, void 0);
|
|
159
180
|
};
|
|
160
181
|
}
|
|
@@ -185,10 +185,6 @@ function createNextApp(opts) {
|
|
|
185
185
|
// Write APIs proxy code
|
|
186
186
|
_b.sent();
|
|
187
187
|
// Remove pages/api/trpc directory if no _rpc is found
|
|
188
|
-
console.log({
|
|
189
|
-
index: (0, path_1.join)(opts.baseDirectory, "apis/_rpc/index.ts"),
|
|
190
|
-
rpc: (0, path_1.join)(opts.baseDirectory, "apis/_rpc.ts"),
|
|
191
|
-
});
|
|
192
188
|
if (!(0, fs_1.existsSync)((0, path_1.join)(opts.baseDirectory, "apis/_rpc/index.ts")) &&
|
|
193
189
|
!(0, fs_1.existsSync)((0, path_1.join)(opts.baseDirectory, "apis/_rpc.ts"))) {
|
|
194
190
|
// removeSync(join(serverlessDirectory, "pages/api/trpc"))
|