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 / categorybox / 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/categorybox/src/inspector.js

626 lines 35.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress dependencies
3 */
4 import { __ } from '@wordpress/i18n';
5 import { applyFilters } from "@wordpress/hooks";
6 import { InspectorControls } from '@wordpress/block-editor';
7 import { PanelBody, TextControl, BaseControl, ToggleControl, SelectControl, TabPanel } from '@wordpress/components';
8 import { useEffect } from '@wordpress/element';
9 import { select, withSelect } from '@wordpress/data';
10
11 /**
12 * Internal depencencies
13 */
14
15 import objAttributes from "./attributes";
16 import { ORDER_BY, ORDER, LAYOUT, BOX_BACKGROUND, LAST_UPDATED_BACKGROUND_COLOR_LAYOUT_4, LAST_UPDATED_PADDING, LAST_UPDATED_MARGIN, WRAPPER_PADDING, ICON_IMAGE_WIDTH_LAYOUT_4, ICON_IMAGE_HEIGHT_LAYOUT_4 } from "./constants";
17 import Select from "react-select";
18
19 import {
20 COLUMNS,
21 HTML_TAGS,
22 BOX_MARGIN,
23 BOX_PADDING,
24 BOX_BORDER,
25 TITLE_MARGIN,
26 COUNT_MARGIN,
27 ICON_AREA,
28 ICON_SIZE,
29 ICON_BACKGROUND,
30 ICON_BORDER,
31 ICON_PADDING,
32 ICON_MARGIN,
33 WRAPPER_MARGIN,
34 COLUMNS_LAYOUT_4,
35 BOX_MARGIN_LAYOUT_4,
36 BOX_PADDING_LAYOUT_4,
37 BOX_BORDER_LAYOUT_4,
38 TITLE_MARGIN_LAYOUT_4,
39 COUNT_MARGIN_LAYOUT_4,
40 ICON_AREA_LAYOUT_4,
41 ICON_SIZE_LAYOUT_4,
42 ICON_BACKGROUND_LAYOUT_4,
43 BOX_BACKGROUND_LAYOUT_4,
44 ICON_BORDER_LAYOUT_4,
45 ICON_PADDING_LAYOUT_4,
46 ICON_MARGIN_LAYOUT_4,
47 WRAPPER_MARGIN_LAYOUT_4,
48 CONTAINER_SECTION_MARGIN_LAYOUT_4,
49 CONTAINER_SECTION_PADDING_LAYOUT_4,
50 CONTAINER_SECTION_BACKGROUND_LAYOUT_4
51 } from "./constants";
52 import {
53 typoPrefix_title,
54 typoPrefix_count,
55 typoPrefix_title_layout_4,
56 typoPrefix_count_layout_4,
57 typoPrefix_last_updated_time
58 } from "./typographyPrefixConstants";
59
60 import ResponsiveRangeController from "../../../util/responsive-range-control";
61 import ResponsiveDimensionsControl from "../../../util/dimensions-control-v2";
62 import TypographyDropdown from "../../../util/typography-control-v2";
63 import BackgroundControl from "../../../util/background-control";
64 import BorderShadowControl from "../../../util/border-shadow-control";
65 import ColorControl from "../../../util/color-control";
66 import { RangeControl } from '@wordpress/components';
67
68 const Inspector = ({ docCategories, attributes, setAttributes }) => {
69 const {
70 resOption,
71 includeCategories,
72 excludeCategories,
73 boxPerPage,
74 orderBy,
75 order,
76 layout,
77 showIcon,
78 showTitle,
79 titleTag,
80 showCount,
81 showLastUpdatedTime,
82 prefix,
83 suffix,
84 suffixSingular,
85 titleColor,
86 titleColorLayout4,
87 titleHoverColor,
88 titleHoverColorLayout4,
89 countColor,
90 countColorLayout4,
91 countHoverColor,
92 countHoverColorLayout4,
93 lastUpdatedTimeColor,
94 lastUpdatedTimeHoverColor,
95 layout4Col
96 } = attributes;
97
98 const editorStoreForGettingPreivew =
99 betterdocs_style_handler.editor_type === "edit-site"
100 ? "core/edit-site"
101 : "core/edit-post";
102
103 useEffect(() => {
104 // this is for setting the resOption attribute to desktop/tab/mobile depending on the added 'eb-res-option-' class only the first time once
105 setAttributes({
106 resOption: select(
107 editorStoreForGettingPreivew
108 ).__experimentalGetPreviewDeviceType(),
109 });
110 }, []);
111
112 const resRequiredProps = {
113 setAttributes,
114 resOption,
115 attributes,
116 objAttributes,
117 };
118
119 // handle include categories
120 const handleIncludeCategories = (categories) => {
121 setAttributes({
122 includeCategories: categories ? JSON.stringify(categories) : null,
123 });
124 };
125 // handle exclude categories
126 const handleExcludeCategories = (categories) => {
127 setAttributes({
128 excludeCategories: categories ? JSON.stringify(categories) : null,
129 });
130 };
131
132 return (
133 <InspectorControls key="controls">
134 <div className="eb-panel-control">
135 <TabPanel
136 className="eb-parent-tab-panel"
137 activeClass="active-tab"
138 tabs={[
139 {
140 name: "general",
141 title: __("General", "betterdocs"),
142 className: "eb-tab general",
143 },
144 {
145 name: "styles",
146 title: __("Style", "betterdocs"),
147 className: "eb-tab styles",
148 }
149 ]}
150 >
151 {(tab) => (
152 <div className={"eb-tab-controls " + tab.name}>
153 {tab.name === "general" && (
154 <>
155 <PanelBody title={__("Query", "better-docs")}>
156 <>
157 {applyFilters("selectKnowledgeBase", '', attributes, setAttributes)}
158 <BaseControl>
159 <h3 className="eb-control-title">
160 {__("Include", "better-docs")}
161 </h3>
162 </BaseControl>
163 <Select
164 name="include_categories"
165 value={
166 includeCategories && JSON.parse(includeCategories)
167 }
168 onChange={handleIncludeCategories}
169 options={
170 docCategories &&
171 docCategories.map((category) => ({
172 value: category.id,
173 label: category.name,
174 }))
175 }
176 isMulti="true"
177 />
178 <BaseControl>
179 <h3 className="eb-control-title">
180 {__("Exclude", "betterdocs")}
181 </h3>
182 </BaseControl>
183 <Select
184 name="exclude_categories"
185 value={
186 excludeCategories && JSON.parse(excludeCategories)
187 }
188 onChange={handleExcludeCategories}
189 options={
190 docCategories &&
191 docCategories.map((category) => ({
192 value: category.id,
193 label: category.name,
194 }))
195 }
196 isMulti="true"
197 />
198 <TextControl
199 label={__("Box Per Page", "betterdocs")}
200 type="number"
201 value={boxPerPage}
202 onChange={(value) => {
203 setAttributes({
204 boxPerPage: parseInt(value),
205 });
206 }}
207 />
208 <SelectControl
209 label={__("Order By", "betterdocs")}
210 value={orderBy}
211 options={ORDER_BY}
212 onChange={(newOrderby) =>
213 setAttributes({
214 orderBy: newOrderby,
215 })
216 }
217 __next40pxDefaultSize
218 __nextHasNoMarginBottom
219 />
220 {orderBy != 'doc_category_order' && <SelectControl
221 label={__("Order", "betterdocs")}
222 value={order}
223 options={ORDER}
224 onChange={(newOrder) =>
225 setAttributes({
226 order: newOrder,
227 })
228 }
229 __next40pxDefaultSize
230 __nextHasNoMarginBottom
231 />}
232 </>
233 </PanelBody>
234 <PanelBody title={__("Settings", "betterdocs")}>
235 <>
236 <SelectControl
237 label={__("Select layout", "betterdocs")}
238 value={layout}
239 options={LAYOUT}
240 onChange={(newLayout) =>
241 setAttributes({
242 layout: newLayout,
243 })
244 }
245 __next40pxDefaultSize
246 __nextHasNoMarginBottom
247 />
248 {layout != 'layout-4' && <ResponsiveRangeController
249 baseLabel={__("Box Column", "betterdocs")}
250 controlName={COLUMNS}
251 resRequiredProps={resRequiredProps}
252 min={1}
253 max={6}
254 step={1}
255 noUnits
256 />}
257 {
258 layout == 'layout-4' && <RangeControl
259 label="Columns"
260 value={ layout4Col }
261 onChange={ ( layout4Col ) => {
262 setAttributes( {layout4Col} )
263 }}
264 min={ 2 }
265 max={ 5 }
266 />
267 }
268 <ToggleControl
269 label={__("Show Icon", "betterdocs")}
270 checked={showIcon}
271 onChange={() => {
272 setAttributes({
273 showIcon: !showIcon,
274 });
275 }}
276 />
277 <ToggleControl
278 label={__("Show Title", "betterdocs")}
279 checked={showTitle}
280 onChange={() => {
281 setAttributes({
282 showTitle: !showTitle,
283 });
284 }}
285 />
286 <SelectControl
287 label={__("Select Tag", "betterdocs")}
288 value={titleTag}
289 options={HTML_TAGS}
290 onChange={(newTitleTag) =>
291 setAttributes({
292 titleTag: newTitleTag,
293 })
294 }
295 __next40pxDefaultSize
296 __nextHasNoMarginBottom
297 />
298 {layout == 'layout-4' &&
299 <ToggleControl
300 label={__("Show Last Updated Time", "betterdocs")}
301 checked={showLastUpdatedTime}
302 onChange={() => {
303 setAttributes({
304 showLastUpdatedTime: !showLastUpdatedTime,
305 });
306 }}
307 />
308 }
309 <ToggleControl
310 label={__("Show Count", "betterdocs")}
311 checked={showCount}
312 onChange={() => {
313 setAttributes({
314 showCount: !showCount,
315 });
316 }}
317 />
318 {layout === "default" && showCount && (
319 <>
320 <TextControl
321 label={__("Prefix", "betterdocs")}
322 value={prefix}
323 onChange={(prefix) =>
324 setAttributes({
325 prefix,
326 })
327 }
328 />
329 <TextControl
330 label={__("Suffix", "betterdocs")}
331 value={suffix}
332 onChange={(suffix) =>
333 setAttributes({
334 suffix,
335 })
336 }
337 />
338 <TextControl
339 label={__("Suffix Singular", "betterdocs")}
340 value={suffixSingular}
341 onChange={(suffixSingular) =>
342 setAttributes({
343 suffixSingular,
344 })
345 }
346 />
347 </>
348 )}
349 </>
350 </PanelBody>
351 </>
352 )}
353 {tab.name === "styles" && (
354 <>
355 <PanelBody
356 title={__("Wrapper", "betterdocs")}
357 initialOpen={true}
358 >
359 <ResponsiveDimensionsControl
360 baseLabel={__("Margin", "betterdocs")}
361 resRequiredProps={resRequiredProps}
362 controlName={WRAPPER_MARGIN}
363 />
364 <ResponsiveDimensionsControl
365 baseLabel={__("Padding", "betterdocs")}
366 resRequiredProps={resRequiredProps}
367 controlName={WRAPPER_PADDING}
368 />
369 </PanelBody>
370 <PanelBody title={__("Box", "betterdocs")} initialOpen={false}>
371 <ResponsiveDimensionsControl
372 baseLabel={__("Margin", "betterdocs")}
373 resRequiredProps={resRequiredProps}
374 controlName={layout != 'layout-4' ? BOX_MARGIN : BOX_MARGIN_LAYOUT_4}
375 />
376 <ResponsiveDimensionsControl
377 baseLabel={__("Padding", "betterdocs")}
378 resRequiredProps={resRequiredProps}
379 controlName={layout != 'layout-4' ? BOX_PADDING : BOX_PADDING_LAYOUT_4}
380 />
381 <BaseControl>
382 <h3 className="eb-control-title">
383 {__("Background", "betterdocs")}
384 </h3>
385 </BaseControl>
386 <BackgroundControl
387 controlName={layout != 'layout-4' ? BOX_BACKGROUND : BOX_BACKGROUND_LAYOUT_4}
388 resRequiredProps={resRequiredProps}
389 noOverlay={true}
390 />
391 <BaseControl>
392 <h3 className="eb-control-title">
393 {__("Border", "betterdocs")}
394 </h3>
395 </BaseControl>
396 <BorderShadowControl
397 controlName={layout != 'layout-4' ? BOX_BORDER : BOX_BORDER_LAYOUT_4}
398 resRequiredProps={resRequiredProps}
399 />
400 </PanelBody>
401 <PanelBody
402 title={__("Icon", "betterdocs")}
403 initialOpen={false}
404 >
405 <>
406 <ResponsiveRangeController
407 baseLabel={__("Icon Area", "betterdocs")}
408 controlName={layout != 'layout-4' ? ICON_AREA : ICON_AREA_LAYOUT_4}
409 resRequiredProps={resRequiredProps}
410 min={1}
411 max={500}
412 step={1}
413 />
414 <ResponsiveRangeController
415 baseLabel={__("Icon Size", "betterdocs")}
416 controlName={layout != 'layout-4' ? ICON_SIZE : ICON_SIZE_LAYOUT_4}
417 resRequiredProps={resRequiredProps}
418 min={1}
419 max={500}
420 step={1}
421 />
422 {layout == 'layout-4' && <><ResponsiveRangeController
423 baseLabel={__("Icon Image Width", "betterdocs")}
424 controlName={ICON_IMAGE_WIDTH_LAYOUT_4}
425 resRequiredProps={resRequiredProps}
426 min={1}
427 max={500}
428 step={1}
429 />
430 <ResponsiveRangeController
431 baseLabel={__("Icon Image Height", "betterdocs")}
432 controlName={ICON_IMAGE_HEIGHT_LAYOUT_4}
433 resRequiredProps={resRequiredProps}
434 min={1}
435 max={500}
436 step={1}
437 /></>}
438 <BaseControl>
439 <h3 className="eb-control-title">
440 {__("Background", "betterdocs")}
441 </h3>
442 </BaseControl>
443 <BackgroundControl
444 controlName={layout != 'layout-4' ? ICON_BACKGROUND : ICON_BACKGROUND_LAYOUT_4}
445 resRequiredProps={resRequiredProps}
446 noOverlay={true}
447 noMainBgi={true}
448 />
449 <BaseControl>
450 <h3 className="eb-control-title">
451 {__("Border", "betterdocs")}
452 </h3>
453 </BaseControl>
454 <BorderShadowControl
455 controlName={layout != 'layout-4' ? ICON_BORDER : ICON_BORDER_LAYOUT_4}
456 resRequiredProps={resRequiredProps}
457 noShadow={true}
458 />
459 <ResponsiveDimensionsControl
460 baseLabel={__("Padding", "betterdocs")}
461 resRequiredProps={resRequiredProps}
462 controlName={layout != 'layout-4' ? ICON_PADDING : ICON_PADDING_LAYOUT_4}
463 />
464 <ResponsiveDimensionsControl
465 baseLabel={__("Margin", "betterdocs")}
466 resRequiredProps={resRequiredProps}
467 controlName={layout != 'layout-4' ? ICON_MARGIN : ICON_MARGIN_LAYOUT_4}
468 />
469 </>
470 </PanelBody>
471 <PanelBody
472 title={__("Title", "betterdocs")}
473 initialOpen={false}
474 >
475 <TypographyDropdown
476 baseLabel={__("Typography", "betterdocs")}
477 typographyPrefixConstant={layout != 'layout-4' ? typoPrefix_title : typoPrefix_title_layout_4}
478 resRequiredProps={resRequiredProps}
479 defaultFontSize={20}
480 />
481 <ColorControl
482 label={__("Color", "betterdocs")}
483 color={layout != 'layout-4' ? titleColor : titleColorLayout4}
484 onChange={(titleColor) => {
485 if( layout != 'layout-4' ) {
486 setAttributes({ titleColor:titleColor });
487 } else {
488 setAttributes({ titleColorLayout4:titleColor });
489 }
490 }
491 }
492 />
493 <ColorControl
494 label={__("Hover Color", "betterdocs")}
495 color={layout != 'layout-4' ? titleHoverColor : titleHoverColorLayout4}
496 onChange={(titleHoverColor) => {
497 if( layout != 'layout-4' ) {
498 setAttributes({
499 titleHoverColor:titleHoverColor,
500 })
501 } else {
502 setAttributes({
503 titleHoverColorLayout4:titleHoverColor,
504 })
505 }
506 }}
507 />
508 <ResponsiveDimensionsControl
509 baseLabel={__("Spacing", "betterdocs")}
510 resRequiredProps={resRequiredProps}
511 controlName={layout != 'layout-4' ? TITLE_MARGIN : TITLE_MARGIN_LAYOUT_4}
512 />
513 </PanelBody>
514 <PanelBody
515 title={__("Count", "betterdocs")}
516 initialOpen={false}
517 >
518 <TypographyDropdown
519 baseLabel={__("Typography", "betterdocs")}
520 typographyPrefixConstant={layout != 'layout-4' ? typoPrefix_count : typoPrefix_count_layout_4}
521 resRequiredProps={resRequiredProps}
522 defaultFontSize={15}
523 />
524 <ColorControl
525 label={__("Color", "betterdocs")}
526 color={layout != 'layout-4' ? countColor : countColorLayout4}
527 onChange={(countColor) => {
528 if( layout != 'layout-4' ) {
529 setAttributes({ countColor:countColor });
530 } else {
531 setAttributes({ countColorLayout4:countColor });
532 }
533 }}
534 />
535 <ColorControl
536 label={__("Hover Color", "betterdocs")}
537 color={layout != 'layout-4' ? countHoverColor : countHoverColorLayout4}
538 onChange={(countHoverColor) => {
539 if( layout != 'layout-4' ){
540 setAttributes({
541 countHoverColor:countHoverColor,
542 });
543 } else {
544 setAttributes({
545 countHoverColorLayout4:countHoverColor,
546 });
547 }
548 }}
549 />
550 <ResponsiveDimensionsControl
551 baseLabel={__("Spacing", "betterdocs")}
552 resRequiredProps={resRequiredProps}
553 controlName={layout != 'layout-4' ? COUNT_MARGIN : COUNT_MARGIN_LAYOUT_4}
554 />
555 </PanelBody>
556 {layout == 'layout-4' &&
557 <PanelBody
558 title={__("Last Updated Time", "betterdocs")}
559 initialOpen={false}
560 >
561 <TypographyDropdown
562 baseLabel={__("Typography", "betterdocs")}
563 typographyPrefixConstant={typoPrefix_last_updated_time}
564 resRequiredProps={resRequiredProps}
565 defaultFontSize={12}
566 />
567 <ColorControl
568 label={__("Color", "betterdocs")}
569 color={lastUpdatedTimeColor}
570 onChange={(lastUpdatedTimeColor) => {
571 setAttributes({ lastUpdatedTimeColor:lastUpdatedTimeColor });
572 }}
573 />
574 <ColorControl
575 label={__("Hover Color", "betterdocs")}
576 color={lastUpdatedTimeHoverColor}
577 onChange={(lastUpdatedTimeHoverColor) => {
578 setAttributes({
579 lastUpdatedTimeHoverColor:lastUpdatedTimeHoverColor,
580 });
581 }}
582 />
583 <BaseControl>
584 <h3 className="eb-control-title">
585 {__("Background", "betterdocs")}
586 </h3>
587 </BaseControl>
588 <BackgroundControl
589 controlName={LAST_UPDATED_BACKGROUND_COLOR_LAYOUT_4}
590 resRequiredProps={resRequiredProps}
591 noOverlay={true}
592 />
593 <ResponsiveDimensionsControl
594 baseLabel={__("Padding", "betterdocs")}
595 resRequiredProps={resRequiredProps}
596 controlName={LAST_UPDATED_PADDING}
597 />
598 <ResponsiveDimensionsControl
599 baseLabel={__("Margin", "betterdocs")}
600 resRequiredProps={resRequiredProps}
601 controlName={LAST_UPDATED_MARGIN}
602 />
603 </PanelBody>
604 }
605 </>
606 )}
607 {/* {tab.name === "advance" && (
608
609 </PanelBody>
610 )} */}
611 </div>
612 )}
613 </TabPanel>
614 </div>
615 </InspectorControls>
616 );
617 };
618
619 export default withSelect((select) => {
620 return {
621 docCategories: select("core").getEntityRecords("taxonomy", "doc_category", {
622 per_page: -1,
623 }),
624 };
625 })(Inspector);
626