PluginProbe ʕ •ᴥ•ʔ
FrontBlocks for Gutenberg/GeneratePress / 1.5.2
FrontBlocks for Gutenberg/GeneratePress v1.5.2
1.5.2 1.5.1 1.4.0 1.5.0 trunk 0.2.0 0.2.1 0.2.2 0.2.3 0.2.4 0.2.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 ci-artifacts
frontblocks / assets / faq-schema / frontblocks-faq-schema.js
frontblocks / assets / faq-schema Last commit date
frontblocks-faq-schema-option.jsx 2 months ago frontblocks-faq-schema.js 1 week ago
frontblocks-faq-schema.js
78 lines
1 "use strict";
2
3 var addFilter = wp.hooks.addFilter;
4 var Fragment = wp.element.Fragment;
5 var InspectorControls = wp.blockEditor.InspectorControls;
6 var _wp$components = wp.components,
7 PanelBody = _wp$components.PanelBody,
8 ToggleControl = _wp$components.ToggleControl,
9 SelectControl = _wp$components.SelectControl;
10 var __ = wp.i18n.__;
11 var FAQ_BLOCKS = ['core/accordion', 'generateblocks/container'];
12 var SCHEMA_TYPES = [{
13 label: __('FAQPage (questions & answers)', 'frontblocks'),
14 value: 'FAQPage'
15 }, {
16 label: __('HowTo (steps / how-to guide)', 'frontblocks'),
17 value: 'HowTo'
18 }];
19
20 // Register attributes on supported blocks.
21 addFilter('blocks.registerBlockType', 'frontblocks/faq-schema-attribute', function (settings, name) {
22 if (!FAQ_BLOCKS.includes(name)) {
23 return settings;
24 }
25 settings.attributes = Object.assign({}, settings.attributes, {
26 frblFaqSchema: {
27 type: 'boolean',
28 default: false
29 },
30 frblSchemaType: {
31 type: 'string',
32 default: 'FAQPage'
33 }
34 });
35 return settings;
36 });
37
38 // Add inspector controls to supported blocks.
39 addFilter('editor.BlockEdit', 'frontblocks/faq-schema-controls', function (BlockEdit) {
40 return function (props) {
41 if (!FAQ_BLOCKS.includes(props.name)) {
42 return /*#__PURE__*/React.createElement(BlockEdit, props);
43 }
44
45 // For generateblocks/container, only show on the accordion variant role.
46 if (props.name === 'generateblocks/container' && props.attributes.variantRole !== 'accordion') {
47 return /*#__PURE__*/React.createElement(BlockEdit, props);
48 }
49 var _props$attributes = props.attributes,
50 _props$attributes$frb = _props$attributes.frblFaqSchema,
51 frblFaqSchema = _props$attributes$frb === void 0 ? false : _props$attributes$frb,
52 _props$attributes$frb2 = _props$attributes.frblSchemaType,
53 frblSchemaType = _props$attributes$frb2 === void 0 ? 'FAQPage' : _props$attributes$frb2;
54 return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(BlockEdit, props), /*#__PURE__*/React.createElement(InspectorControls, null, /*#__PURE__*/React.createElement(PanelBody, {
55 title: __('FrontBlocks - Schema', 'frontblocks'),
56 initialOpen: false
57 }, /*#__PURE__*/React.createElement(ToggleControl, {
58 label: __('Add Schema (JSON-LD)', 'frontblocks'),
59 help: __('Include this block\'s content in the page structured data.', 'frontblocks'),
60 checked: frblFaqSchema,
61 onChange: function onChange(value) {
62 return props.setAttributes({
63 frblFaqSchema: value
64 });
65 }
66 }), frblFaqSchema && /*#__PURE__*/React.createElement(SelectControl, {
67 label: __('Schema type', 'frontblocks'),
68 value: frblSchemaType,
69 options: SCHEMA_TYPES,
70 onChange: function onChange(value) {
71 return props.setAttributes({
72 frblSchemaType: value
73 });
74 }
75 }))));
76 };
77 });
78