PluginProbe ʕ •ᴥ•ʔ
VK Blocks / 1.124.0
VK Blocks v1.124.0
1.126.4 1.126.3 1.126.1 1.126.2 1.126.0 1.125.0 1.124.0 1.123.0 1.122.0 1.121.0 1.120.0 1.119.2 1.119.1 1.119.0 1.118.7 1.82.0.0 1.82.0.1 1.83.0.0 1.83.0.1 1.84.0.0 1.84.0.1 1.85.0.2 1.85.0.3 1.85.1.0 1.85.1.1 1.86.0.0 1.86.0.1 1.86.1.0 1.87.0.0 1.87.0.1 1.88.0.1 1.88.0.2 1.89.0.0 1.9.2 1.90.0.0 1.90.0.1 1.90.1.1 1.91.0.0 1.91.1.1 1.92.0.0 1.92.0.1 1.92.1.0 1.92.1.1 1.93.0.0 trunk 1.93.0.1 0.1.1 1.93.1.0 0.10.3 1.93.1.1 0.11.0 1.94.0.0 0.12.6 1.94.0.1 0.15.1 1.94.1.0 0.16.2 1.94.2.1 0.17.6 1.94.2.2 0.2.2 1.95.0.3 0.22.4 1.95.0.4 0.26.7 1.96.2.0 0.3.2 1.96.2.1 0.31.0 1.97.0.1 0.35.5 1.97.0.2 0.37.5 1.99.0.0 0.38.8 1.99.0.1 0.39.4 0.4.7 0.41.0 0.42.0 0.44.13 0.45.2 0.46.1 0.47.0 0.48.0 0.49.8 0.5.2 0.50.3 0.51.0 0.52.2 0.53.2 0.54.0 0.55.0 0.56.2 0.56.3 0.57.6 0.58.10 0.59.0 0.6.0 0.60.1 0.61.2 0.7.1 0.8.2 1.0.16 1.10.0 1.100.0.0 1.100.0.1 1.102.0.0 1.102.0.1 1.103.0.0 1.104.0.0 1.104.0.1 1.105.1.0 1.105.1.1 1.106.0.0 1.106.0.1 1.107.0.0 1.107.0.1 1.107.0.2 1.108.0.0 1.108.0.1 1.109.0.0 1.109.0.1 1.11.4 1.110.0.0 1.110.0.1 1.111.0.0 1.111.0.1 1.111.0.2 1.112.0.0 1.112.0.1 1.113.0.0 1.113.0.1 1.114.0.0 1.114.0.1 1.114.2.0 1.114.2.1 1.115.0.0 1.115.0.1 1.115.1.0 1.115.1.1 1.115.2.0 1.115.2.1 1.116.0.0 1.116.0.1 1.116.1.0 1.116.1.1 1.116.2.0 1.117.0.0 1.117.0.1 1.117.1.0 1.118.2 1.118.5 1.12.0 1.13.2 1.14.1 1.15.1 1.16.11 1.17.0 1.18.6 1.19.0 1.19.1 1.2.3 1.20.7 1.21.0 1.22.4 1.23.0 1.24.5 1.25.1 1.26.2 1.27.7.2 1.28.0.1 1.29.2.0 1.3.9 1.30.0.1 1.31.0.1 1.32.0.2 1.33.2.1 1.36.1.5 1.37.0.0 1.39.2.1 1.4.6 1.40.0.1 1.40.1.0 1.40.1.1 1.41.0.0 1.41.0.1 1.41.2.2 1.41.2.3 1.43.0.0 1.43.0.1 1.43.0.2 1.44.0.0 1.44.0.1 1.45.0.0 1.45.0.1 1.46.0.0 1.46.0.1 1.47.0.0 1.47.0.1 1.47.1.0 1.48.0.0 1.48.0.1 1.48.0.2 1.48.1.0 1.48.1.1 1.5.0 1.50.0.0 1.50.0.1 1.51.0.0 1.51.0.1 1.52.0.0 1.52.0.1 1.53.0.0 1.53.0.1 1.54.0.0 1.54.0.1 1.55.0.0 1.55.0.1 1.56.0.0 1.56.0.1 1.57.0.0 1.57.0.2 1.57.0.3 1.57.0.4 1.57.0.5 1.57.1.0 1.57.1.1 1.57.1.2 1.58.0.0 1.58.0.1 1.59.0.0 1.59.0.1 1.6.0 1.60.0.0 1.60.0.1 1.63.0.0 1.63.0.1 1.64.0.0 1.64.0.1 1.64.1.0 1.64.1.2 1.67.0.0 1.67.0.1 1.68.0.0 1.68.0.1 1.69.0.0 1.69.0.1 1.69.1.1 1.69.1.2 1.7.1 1.70.0.0 1.70.0.1 1.71.0.0 1.71.0.1 1.72.0.0 1.72.1.0 1.72.1.1 1.73.0.0 1.73.0.1 1.74.0.0 1.74.0.1 1.75.0.0 1.75.1.0 1.75.1.1 1.76.0.0 1.76.0.1 1.76.1.0 1.76.1.1 1.76.2.0 1.76.2.1 1.77.0.0 1.77.0.1 1.78.0.0 1.78.0.1 1.79.0.0 1.79.0.1 1.79.0.2 1.79.0.3 1.79.1.0 1.79.1.1 1.8.2 1.80.1.0 1.80.1.1 1.80.1.2 1.81.0.1 1.81.0.2
vk-blocks / src / blocks / page-content / edit.js
vk-blocks / src / blocks / page-content Last commit date
block.json 3 months ago class-vk-blocks-check-using-vk-page-content-block.php 3 months ago edit.js 1 month ago icon.svg 3 months ago index.js 3 months ago index.php 1 month ago
edit.js
172 lines
1 import { __ } from '@wordpress/i18n';
2 import {
3 PanelBody,
4 BaseControl,
5 SelectControl,
6 Button,
7 ToolbarGroup,
8 ToolbarButton,
9 } from '@wordpress/components';
10 import {
11 InspectorControls,
12 useBlockProps,
13 BlockControls,
14 } from '@wordpress/block-editor';
15 import ServerSideRender from '@wordpress/server-side-render';
16 import { useSelect } from '@wordpress/data';
17 import { addQueryArgs } from '@wordpress/url';
18 import { pencil } from '@wordpress/icons';
19
20 // usePosts は本ブロック専用のためローカル定義
21 const usePosts = (postType, query) => {
22 return useSelect(
23 (select) => {
24 return (
25 select('core').getEntityRecords(
26 'postType',
27 postType.slug,
28 query
29 ) || []
30 );
31 },
32 [postType, query]
33 );
34 };
35
36 const getPageLabel = (page) => {
37 let label = page.title.rendered;
38 if (page.status === 'private') {
39 label += ` (${__('Private', 'vk-blocks')})`;
40 }
41 if (page.password) {
42 label += ` (${__('Password Protected', 'vk-blocks')})`;
43 }
44 return label;
45 };
46
47 const getPagesSelect = (pages, currentTargetPost) => {
48 const defaultSelect = [
49 {
50 label: __('Unspecified', 'vk-blocks'),
51 value: -1,
52 },
53 ];
54
55 // 選択リストから非�
56 �開・パスワード保護のページを除外する(現在選択中のページは除く)
57 const availablePages = pages.filter(
58 (page) =>
59 (page.status === 'publish' && !page.password) ||
60 page.id === currentTargetPost
61 );
62
63 // 利用可能なページから選択オプションを作成する
64 const pagesSelect = availablePages.map((page) => ({
65 label:
66 page.status === 'private' || page.password
67 ? getPageLabel(page)
68 : page.title.rendered,
69 value: page.id,
70 }));
71
72 return defaultSelect.concat(pagesSelect);
73 };
74
75 export default function PageContentEdit({ attributes, setAttributes }) {
76 const { TargetPost } = attributes;
77 const hasTargetPost = TargetPost !== -1;
78 const editButtonLabel = __('Edit this area', 'vk-blocks');
79 const toolbarEditButtonLabel = hasTargetPost
80 ? editButtonLabel
81 : __('Select a page first to edit this area', 'vk-blocks');
82
83 // 対象固定ページの編集画面を新規タブで開く
84 const openTargetPostEdit = () => {
85 if (!hasTargetPost) {
86 return;
87 }
88
89 const url = addQueryArgs('post.php', {
90 post: TargetPost,
91 action: 'edit',
92 });
93 window.open(url, `vk-page-content-edit-${TargetPost}`);
94 };
95
96 const pages = usePosts(
97 { slug: 'page' },
98 { per_page: -1, status: 'private,publish' }
99 );
100
101 const pagesSelect = getPagesSelect(pages, TargetPost);
102
103 let editContent;
104 if (TargetPost === -1) {
105 editContent = (
106 <div className="alert alert-warning text-center">
107 {__(
108 'Because no post is selected, The block Will not render',
109 'vk-blocks'
110 )}
111 </div>
112 );
113 } else {
114 editContent = (
115 <ServerSideRender
116 block="vk-blocks/page-content"
117 attributes={attributes}
118 />
119 );
120 }
121
122 const blockProps = useBlockProps();
123
124 return (
125 <>
126 <BlockControls>
127 <ToolbarGroup>
128 <ToolbarButton
129 icon={pencil}
130 label={toolbarEditButtonLabel}
131 showTooltip={true}
132 disabled={!hasTargetPost}
133 accessibleWhenDisabled
134 onClick={openTargetPostEdit}
135 />
136 </ToolbarGroup>
137 </BlockControls>
138 <InspectorControls>
139 <PanelBody
140 title={__('Page Setting', 'vk-blocks')}
141 initialOpen={true}
142 >
143 <BaseControl id={'vb-call-01'}>
144 <SelectControl
145 label={__('Select Page', 'vk-blocks')}
146 value={TargetPost}
147 options={pagesSelect}
148 onChange={(value) =>
149 setAttributes({
150 TargetPost: parseInt(value, 10),
151 })
152 }
153 />
154 </BaseControl>
155 <Button
156 className="mt-2"
157 variant="secondary"
158 icon={pencil}
159 aria-label={toolbarEditButtonLabel}
160 disabled={!hasTargetPost}
161 accessibleWhenDisabled
162 onClick={openTargetPostEdit}
163 >
164 {editButtonLabel}
165 </Button>
166 </PanelBody>
167 </InspectorControls>
168 <div {...blockProps}>{editContent}</div>
169 </>
170 );
171 }
172