PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.5
4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 All 203 releases
betterdocs / react-src / gutenberg / blocks / faq / src / inspector.js

inspector.js in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.5, at react-src/gutenberg/blocks/faq/src/inspector.js

609 lines 19.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress dependencies
3 */
4
5 import { __ } from '@wordpress/i18n';
6 import { InspectorControls } from '@wordpress/block-editor';
7 import {
8 PanelBody,
9 TextControl,
10 Button,
11 ButtonGroup,
12 BaseControl,
13 ToggleControl,
14 SelectControl,
15 TabPanel,
16 Notice,
17 } from '@wordpress/components';
18 import { useEffect } from '@wordpress/element';
19 import { select, useSelect } from '@wordpress/data';
20
21 /**
22 * Internal depencencies
23 */
24
25 import objAttributes from "./attributes";
26 import Select from "react-select";
27 import FontIconPicker from "@fonticonpicker/react-fonticonpicker";
28 import faIcons from "../../../util/faIcons";
29
30 import {
31 mimmikCssForResBtns,
32 mimmikCssOnPreviewBtnClickWhileBlockSelected,
33 } from "../../../util/helpers";
34
35 import {
36 ORDER_BY,
37 ORDER,
38 FAQ_LAYOUT,
39 getFaqTaxonomyOptions,
40 FAQ_LIST_BACKGROUND,
41 FAQ_CONTENT_BACKGROUND,
42 FAQ_LIST_MARGIN,
43 FAQ_LIST_PADDING,
44 FAQ_BORDER,
45 FAQ_CONTENT_BORDER,
46 FAQ_CONTENT_MARGIN,
47 FAQ_CONTENT_PADDING,
48 POSTS_ORDER_BY,
49 ICON_MARGIN,
50 BTN_MARGIN,
51 BTN_PADDING,
52 BTN_BACKGROUND,
53 BTN_BORDER,
54 BUTTON_POSITION,
55 WRAPPER_MARGIN,
56 ICON_SIZE,
57 SECTION_TITLE_MARGIN,
58 SECTION_TITLE_PADDING,
59 GROUP_TITLE_MARGIN,
60 GROUP_TITLE_PADDING,
61 CONTAINER_SECTION_PADDING,
62 CONTAINER_SECTION_MARGIN,
63 CONTAINER_SECTION_BACKGROUND,
64 FAQ_LIST_BACKGROUND_LAYOUT_3,
65 GROUP_TITLE_PADDING_LAYOUT_4,
66 GROUP_TITLE_MARGIN_LAYOUT_4,
67 FAQ_LIST_PADDING_LAYOUT_4,
68 FAQ_LIST_MARGIN_LAYOUT_4,
69 FAQ_LIST_BACKGROUND_LAYOUT_4,
70 FAQ_BORDER_LAYOUT_4,
71 FAQ_CONTENT_PADDING_LAYOUT_4,
72 FAQ_CONTENT_MARGIN_LAYOUT_4,
73 FAQ_CONTENT_BACKGROUND_LAYOUT_4,
74 FAQ_CONTENT_BORDER_LAYOUT_4,
75 HTML_TAGS
76 } from "./constants";
77
78
79 import {
80 typoPrefix_section_titele,
81 typoPrefix_group_title,
82 typoPrefix_faq_title,
83 typoPrefix_faq_content,
84 typoPrefix_section_title_layout_3,
85 typoPrefix_group_title_layout_4,
86 typoPrefix_faq_title_layout_4,
87 typoPrefix_faq_content_layout_4
88 } from "./typographyPrefixConstants";
89 // util
90 import ResponsiveRangeController from "../../../util/responsive-range-control";
91 import ResponsiveDimensionsControl from "../../../util/dimensions-control-v2";
92 import TypographyDropdown from "../../../util/typography-control-v2";
93 import BackgroundControl from "../../../util/background-control";
94 import BorderShadowControl from "../../../util/border-shadow-control";
95 import ColorControl from "../../../util/color-control";
96 import { htmlToElem } from '../../../helpers/helper';
97
98 const Inspector = ({
99 faqs,
100 attributes,
101 setAttributes,
102 }) => {
103 const {
104 resOption,
105 faqLayout,
106 faqTaxonomy,
107 faqOrder,
108 faqSectionText,
109 faqSectionTitleTag,
110 faqGroupTitleTag,
111 includeFaqGroup,
112 excludeFaqGroup,
113 faqSectionTitleColor,
114 faqSectionTitleHoverColor,
115 faqGroupTitleColor,
116 faqGroupTitleLayout4Color,
117 faqGroupTitleLayout4HoverColor,
118 faqListLayout4Color,
119 faqContentLayout4Color,
120 faqGroupTitleHoverColor,
121 faqListColor,
122 faqContentColor,
123 faqIconColor,
124 faqGroupTitleTypography,
125
126 postCategories,
127 faqPerPage,
128 orderBy,
129 order,
130 postsPerPage,
131 postsOrderBy,
132 postsOrder,
133 enableNestedSubcategory,
134 postPerSubcategory,
135 layout,
136 layoutMode,
137 showHeader,
138 showIcon,
139 showTitle,
140 showThumbnail,
141 showDescription,
142 titleTag,
143 showCount,
144 showList,
145 listIcon,
146 showButton,
147 buttonText,
148 titleColor,
149 titleHoverColor,
150 descriptionColor,
151 descriptionHoverColor,
152 countColor,
153 countHoverColor,
154 listColor,
155 listHoverColor,
156 iconColor,
157 showButtonIcon,
158 buttonIcon,
159 buttonColor,
160 buttonColorLayout4,
161 buttonHoverColor,
162 buttonPosition,
163 } = attributes;
164
165
166
167 const docFaqs = useSelect( ( sel ) => {
168 return sel( 'core' ).getEntityRecords( 'taxonomy', faqTaxonomy || 'betterdocs_faq_category', { per_page: -1 } );
169 }, [ faqTaxonomy ] );
170
171 const editorStoreForGettingPreivew =
172 betterdocs_style_handler.editor_type === "edit-site"
173 ? "core/edit-site"
174 : "core/edit-post";
175
176 // this useEffect is for setting the resOption attribute to desktop/tab/mobile depending on the added 'eb-res-option-' class only the first time once
177 useEffect(() => {
178 setAttributes({
179 resOption: select(
180 editorStoreForGettingPreivew
181 ).__experimentalGetPreviewDeviceType(),
182 });
183 }, []);
184
185 const resRequiredProps = {
186 setAttributes,
187 resOption,
188 attributes,
189 objAttributes,
190 };
191
192 // handle include faqs
193 const handleIncludeCategories = (faqs) => {
194 setAttributes({
195 includeFaqGroup: faqs ? JSON.stringify(faqs) : null,
196 });
197 };
198 // handle exclude faqs
199 const handleExcludeCategories = (faqs) => {
200 setAttributes({
201 excludeFaqGroup: faqs ? JSON.stringify(faqs) : null,
202 });
203 };
204
205 // Define a function to generate options
206 const faqOptions = (docFaqs) => {
207 if (!docFaqs) return [];
208
209 return docFaqs.map((faq) => ({
210 value: faq.id,
211 label: faq.name,
212 }));
213 };
214
215
216
217 // control POSTS_ORDER_BY for pro plugin
218 let posts_order_by =
219 Boolean(betterDocsBlocksHelper.is_pro_active) === true
220 ? [
221 ...POSTS_ORDER_BY,
222 {
223 label: __("BetterDocs Order", "betterdocs-pro"),
224 value: "betterdocs_order",
225 },
226 ]
227 : [...POSTS_ORDER_BY];
228
229 return (
230 <InspectorControls key="controls">
231 <div className="eb-panel-control">
232 <TabPanel
233 className="eb-parent-tab-panel"
234 activeClass="active-tab"
235 tabs={[
236 {
237 name: "general",
238 title: __("General", "betterdocs-pro"),
239 className: "eb-tab general",
240 },
241 {
242 name: "styles",
243 title: __("Style", "betterdocs-pro"),
244 className: "eb-tab styles",
245 }
246 ]}
247 >
248 {(tab) => (
249 <div key={tab.name} className={"eb-tab-controls " + tab.name}>
250 {tab.name === "general" && (
251 <>
252 <PanelBody title={__("Layout Options", "betterdocs-pro")} initialOpen={true}>
253 <>
254 <SelectControl
255 label={__("FAQ Type", "betterdocs")}
256 value={faqTaxonomy}
257 options={getFaqTaxonomyOptions()}
258 onChange={(faqTaxonomy) => setAttributes({ faqTaxonomy, includeFaqGroup: null, excludeFaqGroup: null })}
259 />
260 <SelectControl
261 label={__("Select Layout", "betterdocs-pro")}
262 value={faqLayout}
263 options={FAQ_LAYOUT}
264 onChange={(faqLayout) => setAttributes({ faqLayout })}
265 />
266 <SelectControl
267 label={__("FAQ Order", "betterdocs")}
268 value={faqOrder}
269 help={__("Overrides the global FAQ Builder order for this block only.", "betterdocs")}
270 options={[
271 { label: __("Default (global)", "betterdocs"), value: "" },
272 { label: __("Manual (drag & drop)", "betterdocs"), value: "default" },
273 { label: __("Newest first", "betterdocs"), value: "most_recent" },
274 { label: __("Oldest first", "betterdocs"), value: "least_recent" },
275 { label: __("Title A → Z", "betterdocs"), value: "a_to_z" },
276 { label: __("Title Z → A", "betterdocs"), value: "z_to_a" },
277 { label: __("Most questions", "betterdocs"), value: "most_questions" },
278 ]}
279 onChange={(faqOrder) => setAttributes({ faqOrder })}
280 />
281 <TextControl
282 label={__("FAQ Section", "betterdocs-pro")}
283 type="text"
284 value={faqSectionText}
285 onChange={(faqSectionText) => setAttributes({ faqSectionText })}
286 />
287 <SelectControl
288 label={__("Section Title Tag", "betterdocs")}
289 value={faqSectionTitleTag}
290 options={HTML_TAGS}
291 onChange={(faqSectionTitleTag) =>
292 setAttributes({
293 faqSectionTitleTag: faqSectionTitleTag,
294 })
295 }
296 />
297 <SelectControl
298 label={__("Group Title Tag", "betterdocs")}
299 value={faqGroupTitleTag}
300 options={HTML_TAGS}
301 onChange={(faqGroupTitleTag) =>
302 setAttributes({
303 faqGroupTitleTag: faqGroupTitleTag,
304 })
305 }
306 />
307
308 { faqTaxonomy === 'product_assignments' ? (
309 <Notice
310 status="info"
311 isDismissible={ false }
312 style={ { marginTop: '8px' } }
313 >
314 { __( 'Groups are resolved automatically per product: a per-product assignment is shown if set, otherwise the groups assigned to the product’s categories. Manage assignments on each group in FAQ Builder → WooCommerce → Product FAQ Groups.', 'betterdocs' ) }
315 </Notice>
316 ) : (
317 <>
318 <BaseControl>
319 <label class="components-base-control__label" for="inspector-text-control-2">{__("Include FAQ Groups", "betterdocs-pro")}</label>
320 <Select
321 name="include_faqs"
322 value={
323 includeFaqGroup && JSON.parse(includeFaqGroup)
324 }
325 onChange={handleIncludeCategories}
326 options={faqOptions(docFaqs)}
327 isMulti="true"
328 />
329 </BaseControl>
330
331 <BaseControl>
332 <label class="components-base-control__label" for="inspector-text-control-2">{__("Exclude FAQ Groups", "betterdocs-pro")}</label>
333 <Select
334 name="exclude_faqs"
335 value={
336 excludeFaqGroup && JSON.parse(excludeFaqGroup)
337 }
338 onChange={handleExcludeCategories}
339 options={faqOptions(docFaqs)}
340 isMulti="true"
341 />
342 </BaseControl>
343 </>
344 ) }
345
346
347 </>
348 </PanelBody>
349
350 </>
351 )}
352 {tab.name === "styles" && (
353 <>
354 <PanelBody title={__("Container Section", "betterdocs-pro")} initialOpen={true}>
355 <BackgroundControl
356 controlName={CONTAINER_SECTION_BACKGROUND}
357 resRequiredProps={resRequiredProps}
358 noOverlay={true}
359 />
360 <ResponsiveDimensionsControl
361 baseLabel={__("Padding", "betterdocs-pro")}
362 resRequiredProps={resRequiredProps}
363 controlName={CONTAINER_SECTION_PADDING}
364 />
365 <ResponsiveDimensionsControl
366 baseLabel={__("Margin", "betterdocs-pro")}
367 resRequiredProps={resRequiredProps}
368 controlName={CONTAINER_SECTION_MARGIN}
369 />
370 </PanelBody>
371 <PanelBody title={__("FAQ Section Title", "betterdocs-pro")} initialOpen={true}>
372 <ColorControl
373 label={__("Color", "betterdocs-pro")}
374 color={faqSectionTitleColor}
375 onChange={(faqSectionTitleColor) => setAttributes({ faqSectionTitleColor })}
376 />
377
378 <TypographyDropdown
379 baseLabel={__("Typography", "betterdocs-pro")}
380 typographyPrefixConstant={faqLayout == 'layout-3' ? typoPrefix_section_title_layout_3 : typoPrefix_section_titele}
381 resRequiredProps={resRequiredProps}
382 defaultFontSize={30}
383 />
384 <ResponsiveDimensionsControl
385 baseLabel={__("Padding", "betterdocs-pro")}
386 resRequiredProps={resRequiredProps}
387 controlName={SECTION_TITLE_PADDING}
388 />
389 <ResponsiveDimensionsControl
390 baseLabel={__("Margin", "betterdocs-pro")}
391 resRequiredProps={resRequiredProps}
392 controlName={SECTION_TITLE_MARGIN}
393 />
394 </PanelBody>
395 <PanelBody title={__("FAQ Group Title", "betterdocs-pro")} initialOpen={false}>
396 <ColorControl
397 label={__("Color", "betterdocs-pro")}
398 color={faqLayout == 'layout-4' ? faqGroupTitleLayout4Color : faqGroupTitleColor}
399 onChange={(faqGroupTitleColor) => {
400 if( faqLayout == 'layout-4' ) {
401 setAttributes({ faqGroupTitleLayout4Color: faqGroupTitleColor });
402 } else {
403 setAttributes({ faqGroupTitleColor: faqGroupTitleColor });
404 }
405 }}
406 />
407
408 <ColorControl
409 label={__("Hover Color", "betterdocs-pro")}
410 color={faqLayout == 'layout-4' ? faqGroupTitleLayout4HoverColor : faqGroupTitleHoverColor}
411 onChange={(faqGroupTitleHoverColor) => {
412 if( faqLayout == 'layout-4' ) {
413 setAttributes({ faqGroupTitleLayout4HoverColor: faqGroupTitleHoverColor })
414 } else {
415 setAttributes({ faqGroupTitleHoverColor: faqGroupTitleHoverColor })
416 }
417 }}
418 />
419
420 <TypographyDropdown
421 baseLabel={__("Typography", "betterdocs-pro")}
422 typographyPrefixConstant={faqLayout == 'layout-4' ? typoPrefix_group_title_layout_4 : typoPrefix_group_title}
423 resRequiredProps={resRequiredProps}
424 defaultFontSize={25}
425 />
426 <ResponsiveDimensionsControl
427 baseLabel={__("Padding", "betterdocs-pro")}
428 resRequiredProps={resRequiredProps}
429 controlName={faqLayout == 'layout-4' ? GROUP_TITLE_PADDING_LAYOUT_4 : GROUP_TITLE_PADDING}
430 />
431 <ResponsiveDimensionsControl
432 baseLabel={__("Margin", "betterdocs-pro")}
433 resRequiredProps={resRequiredProps}
434 controlName={faqLayout == 'layout-4' ? GROUP_TITLE_MARGIN_LAYOUT_4 : GROUP_TITLE_MARGIN}
435 />
436 </PanelBody>
437 <PanelBody title={__("FAQ List", "betterdocs-pro")} initialOpen={false}>
438 <ResponsiveDimensionsControl
439 baseLabel={__("Padding", "betterdocs-pro")}
440 resRequiredProps={resRequiredProps}
441 controlName={faqLayout == 'layout-4' ? FAQ_LIST_PADDING_LAYOUT_4 : FAQ_LIST_PADDING}
442 />
443 <ResponsiveDimensionsControl
444 baseLabel={__("Margin", "betterdocs-pro")}
445 resRequiredProps={resRequiredProps}
446 controlName={faqLayout == 'layout-4' ? FAQ_LIST_MARGIN_LAYOUT_4 : FAQ_LIST_MARGIN}
447 />
448 <hr />
449 <BaseControl>
450 <h3 className="eb-control-title">
451 {__("Background", "betterdocs-pro")}
452 </h3>
453 </BaseControl>
454 <BackgroundControl
455 controlName={faqLayout == 'layout-3' ? FAQ_LIST_BACKGROUND_LAYOUT_3 : ( faqLayout == 'layout-4' ? FAQ_LIST_BACKGROUND_LAYOUT_4 : FAQ_LIST_BACKGROUND )}
456 resRequiredProps={resRequiredProps}
457 noOverlay={true}
458 />
459
460 <TypographyDropdown
461 baseLabel={__("Typography", "betterdocs-pro")}
462 typographyPrefixConstant={faqLayout == 'layout-4' ? typoPrefix_faq_title_layout_4 : typoPrefix_faq_title}
463 resRequiredProps={resRequiredProps}
464 defaultFontSize={17}
465 />
466 <ColorControl
467 label={__("Color", "betterdocs-pro")}
468 color={faqLayout == 'layout-4' ? faqListLayout4Color : faqListColor}
469 onChange={(faqListColor) => {
470 if(faqLayout == 'layout-4'){
471 setAttributes({ faqListLayout4Color:faqListColor })
472 } else {
473 setAttributes({ faqListColor:faqListColor })
474 }
475 }}
476 />
477
478 <BaseControl>
479 <h3 className="eb-control-title">
480 {__("Border", "betterdocs-pro")}
481 </h3>
482 </BaseControl>
483 <BorderShadowControl
484 controlName={faqLayout == 'layout-4' ? FAQ_BORDER_LAYOUT_4 : FAQ_BORDER}
485 resRequiredProps={resRequiredProps}
486 />
487
488 </PanelBody>
489 <PanelBody title={__("FAQ Content", "betterdocs-pro")} initialOpen={false}>
490 <ResponsiveDimensionsControl
491 baseLabel={__("Padding", "betterdocs-pro")}
492 resRequiredProps={resRequiredProps}
493 controlName={faqLayout == 'layout-4' ? FAQ_CONTENT_PADDING_LAYOUT_4 : FAQ_CONTENT_PADDING}
494 />
495 <ResponsiveDimensionsControl
496 baseLabel={__("Margin", "betterdocs-pro")}
497 resRequiredProps={resRequiredProps}
498 controlName={faqLayout == 'layout-4' ? FAQ_CONTENT_MARGIN_LAYOUT_4 : FAQ_CONTENT_MARGIN}
499 />
500 <hr />
501 <BaseControl>
502 <h3 className="eb-control-title">
503 {__("Background", "betterdocs-pro")}
504 </h3>
505 </BaseControl>
506 <BackgroundControl
507 controlName={faqLayout == 'layout-4' ? FAQ_CONTENT_BACKGROUND_LAYOUT_4 : FAQ_CONTENT_BACKGROUND}
508 resRequiredProps={resRequiredProps}
509 noOverlay={true}
510 />
511
512 <TypographyDropdown
513 baseLabel={__("Typography", "betterdocs-pro")}
514 typographyPrefixConstant={faqLayout == 'layout-4' ? typoPrefix_faq_content_layout_4: typoPrefix_faq_content}
515 resRequiredProps={resRequiredProps}
516 defaultFontSize={16}
517 />
518 <ColorControl
519 label={__("Color", "betterdocs-pro")}
520 color={faqLayout == 'layout-4' ? faqContentLayout4Color : faqContentColor}
521 onChange={(faqContentColor) => {
522 if( faqLayout == 'layout-4' ) {
523 setAttributes({ faqContentLayout4Color:faqContentColor });
524 }else {
525 setAttributes({ faqContentColor:faqContentColor });
526 }
527 }}
528 />
529
530 <BaseControl>
531 <h3 className="eb-control-title">
532 {__("Border", "betterdocs-pro")}
533 </h3>
534 </BaseControl>
535 <BorderShadowControl
536 controlName={faqLayout == 'layout-4' ? FAQ_CONTENT_BORDER_LAYOUT_4 : FAQ_CONTENT_BORDER}
537 resRequiredProps={resRequiredProps}
538 noShadow={true}
539 />
540
541 </PanelBody>
542
543 <PanelBody
544 title={__("FAQ List Icon", "betterdocs-pro")}
545 initialOpen={false}
546 >
547 <ToggleControl
548 label={__("Show/Hide", "betterdocs-pro")}
549 checked={showButtonIcon}
550 onChange={() => {
551 setAttributes({
552 showButtonIcon: !showButtonIcon,
553 });
554 }}
555 />
556 {showButtonIcon && (
557 <>
558 <ResponsiveRangeController
559 baseLabel={__("Icon Size", "betterdocs")}
560 controlName={ICON_SIZE}
561 resRequiredProps={resRequiredProps}
562 min={1}
563 max={200}
564 step={1}
565 noUnits
566 />
567 <ResponsiveDimensionsControl
568 baseLabel={__("Margin", "betterdocs-pro")}
569 resRequiredProps={resRequiredProps}
570 controlName={ICON_MARGIN}
571 />
572 </>
573 )}
574
575 <ColorControl
576 label={__("Color", "betterdocs-pro")}
577 color={faqLayout == 'layout-4' ? buttonColorLayout4 : buttonColor}
578 onChange={(buttonColor) => {
579 if( faqLayout == 'layout-4' ) {
580 setAttributes({ buttonColorLayout4:buttonColor });
581 } else {
582 setAttributes({ buttonColor:buttonColor });
583 }
584 }}
585 />
586
587
588 </PanelBody>
589 </>
590 )}
591 {/* {tab.name === "advance" && (
592 <PanelBody title={__("Wrapper", "betterdocs-pro")}>
593 <ResponsiveDimensionsControl
594 baseLabel={__("Margin", "betterdocs-pro")}
595 resRequiredProps={resRequiredProps}
596 controlName={WRAPPER_MARGIN}
597 />
598 </PanelBody>
599 )} */}
600 </div>
601 )}
602 </TabPanel>
603 </div>
604 </InspectorControls>
605 );
606 };
607
608 export default Inspector;
609