@plaudit/gutenberg-api-extensions 2.30.0 → 2.31.1
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Button, FocalPointPicker, Spinner } from "@wordpress/components";
|
|
2
|
-
import { dispatch, select
|
|
3
|
-
import { PostFeaturedImageCheck
|
|
4
|
-
import { useEffect, useState } from "@wordpress/element";
|
|
2
|
+
import { dispatch, select } from "@wordpress/data";
|
|
3
|
+
import { PostFeaturedImageCheck } from "@wordpress/editor";
|
|
4
|
+
import { useEffect, useMemo, useState } from "@wordpress/element";
|
|
5
5
|
import { addFilter, applyFilters } from "@wordpress/hooks";
|
|
6
6
|
import { __ } from "@wordpress/i18n";
|
|
7
7
|
import React from "react";
|
|
@@ -34,6 +34,15 @@ function getMediaDetails(media, postId) {
|
|
|
34
34
|
mediaSourceUrl: media.source_url,
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
function getLivePosition() {
|
|
38
|
+
const { x = 50, y = 50 } = (select('core/editor').getEditedPostAttribute('meta')?.["plaudit_card-image_pos"] ?? {});
|
|
39
|
+
return { x: x / 100, y: y / 100 };
|
|
40
|
+
}
|
|
41
|
+
function setLivePosition({ x, y }) {
|
|
42
|
+
dispatch("core/editor").editPost({
|
|
43
|
+
meta: { "plaudit_card-image_pos": { x: Math.round(x * 100), y: Math.round(y * 100) } }
|
|
44
|
+
});
|
|
45
|
+
}
|
|
37
46
|
export function installPostFeaturedImageCardFocusTargeting() {
|
|
38
47
|
if (window.plauditPostFeaturedImageCardFocusTargeting) {
|
|
39
48
|
return;
|
|
@@ -43,14 +52,13 @@ export function installPostFeaturedImageCardFocusTargeting() {
|
|
|
43
52
|
return (props) => {
|
|
44
53
|
const [inFocusMode, setInFocusMode] = useState(false);
|
|
45
54
|
const { currentPostId, media, noticeUI } = props;
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}, [x, y]);
|
|
55
|
+
const restorablePosition = useMemo(() => getLivePosition(), [inFocusMode]);
|
|
56
|
+
// This assembly makes it so that we both get updates if something else triggers a position change while making the focus picker doesn't reset itself
|
|
57
|
+
const { x, y } = getLivePosition();
|
|
58
|
+
const [position, setPosition] = useState({ x, y });
|
|
59
|
+
useEffect(() => setPosition(getLivePosition()), [x, y]);
|
|
52
60
|
const { mediaSourceUrl } = getMediaDetails(media, currentPostId);
|
|
53
|
-
if (!mediaSourceUrl &&
|
|
61
|
+
if (!mediaSourceUrl && select('core/editor').getEditedPostAttribute('featured_media')) {
|
|
54
62
|
return React.createElement(Spinner, null);
|
|
55
63
|
}
|
|
56
64
|
if (!mediaSourceUrl) {
|
|
@@ -58,24 +66,22 @@ export function installPostFeaturedImageCardFocusTargeting() {
|
|
|
58
66
|
}
|
|
59
67
|
if (!inFocusMode) {
|
|
60
68
|
return React.createElement(PostFeaturedImageCheck, null,
|
|
61
|
-
React.createElement(
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
React.createElement("div", { className: "plauditPostFeaturedImageWithFocalPoint__wrapper" },
|
|
70
|
+
React.createElement("div", { className: "plauditPostFeaturedImageWithFocalPoint__toggle" },
|
|
71
|
+
React.createElement(Button, { onClick: () => setInFocusMode(true), className: "editor-post-featured-image__action", text: __("Change Focal Point", 'plaudit') })),
|
|
72
|
+
React.createElement(OriginalComponent, { ...props })));
|
|
64
73
|
}
|
|
65
74
|
return React.createElement(PostFeaturedImageCheck, null,
|
|
66
75
|
noticeUI,
|
|
67
76
|
React.createElement("div", { className: "editor-post-featured-image" },
|
|
68
|
-
React.createElement(FocalPointPicker, { onChange: pos =>
|
|
77
|
+
React.createElement(FocalPointPicker, { onChange: pos => {
|
|
78
|
+
setPosition(pos);
|
|
79
|
+
setLivePosition(pos);
|
|
80
|
+
}, url: mediaSourceUrl, value: position }),
|
|
69
81
|
React.createElement("div", null,
|
|
70
|
-
React.createElement(Button, { text: __("Done", 'plaudit'), onClick: () =>
|
|
71
|
-
dispatch(editorStore)['editPost']({
|
|
72
|
-
meta: { "plaudit_card-image_pos": { x: Math.round(position.x * 100), y: Math.round(position.y * 100) } }
|
|
73
|
-
});
|
|
74
|
-
setInFocusMode(false);
|
|
75
|
-
}, variant: "primary" }),
|
|
82
|
+
React.createElement(Button, { text: __("Done", 'plaudit'), onClick: () => setInFocusMode(false), variant: "primary" }),
|
|
76
83
|
React.createElement(Button, { text: __('Cancel', 'plaudit'), onClick: () => {
|
|
77
|
-
|
|
78
|
-
setPosition({ x: x / 100, y: y / 100 });
|
|
84
|
+
setLivePosition(restorablePosition);
|
|
79
85
|
setInFocusMode(false);
|
|
80
86
|
}, isDestructive: true }))));
|
|
81
87
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-featured-image.js","sourceRoot":"","sources":["../../src/editor/post-featured-image.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAC,MAAM,uBAAuB,CAAC;AAExE,OAAO,EAAC,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"post-featured-image.js","sourceRoot":"","sources":["../../src/editor/post-featured-image.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAC,MAAM,uBAAuB,CAAC;AAExE,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAC,sBAAsB,EAAC,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAC,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAC,SAAS,EAAE,YAAY,EAAC,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAC,EAAE,EAAC,MAAM,iBAAiB,CAAC;AAEnC,OAAO,KAA2B,MAAM,OAAO,CAAC;AAEhD,SAAS,eAAe,CAAC,KAA6E,EAAE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,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE;gCACpD,eAAe,CAAC,kBAAkB,CAAC,CAAC;gCACpC,cAAc,CAAC,KAAK,CAAC,CAAC;4BACvB,CAAC,EAAE,aAAa,SAAG,CACd,CACD,CACkB,CAAC;QAC3B,CAAC,CAAC;IACH,CAAC;IAED,SAAS,CAAC,0BAA0B,EACnC,kFAAkF,EAClF,qBAAqB,CACrB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/gutenberg-api-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.31.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepublishOnly": "rm -rf build && mkdir build && tsc",
|
|
6
6
|
"build": "tsc",
|
|
7
7
|
"watch": "tsc -w"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
|
-
"./build"
|
|
10
|
+
"./build", "./styles"
|
|
11
11
|
],
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"exports": {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.plauditPostFeaturedImageWithFocalPoint__wrapper {
|
|
2
|
+
position: relative;
|
|
3
|
+
|
|
4
|
+
&:hover .plauditPostFeaturedImageWithFocalPoint__toggle, &:hover .editor-post-featured-image__actions {
|
|
5
|
+
opacity: 1;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
.plauditPostFeaturedImageWithFocalPoint__toggle {
|
|
9
|
+
position: absolute;
|
|
10
|
+
z-index: 10000;
|
|
11
|
+
top: 0;
|
|
12
|
+
right: 0;
|
|
13
|
+
opacity: 0;
|
|
14
|
+
padding: 8px;
|
|
15
|
+
}
|