Skip to content

Commit

Permalink
link to divider feature in toc
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan-shafi committed Jul 29, 2024
1 parent 88688a6 commit a91978a
Show file tree
Hide file tree
Showing 16 changed files with 134,931 additions and 382 deletions.
2 changes: 1 addition & 1 deletion dist/blocks.build.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-api', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wp-notices', 'wp-primitives', 'wp-url'), 'version' => 'e60c4b256c76fe2e040f');
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-api', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wp-notices', 'wp-primitives', 'wp-url'), 'version' => '7b8ca8a736f05c6440d9');
134,524 changes: 134,523 additions & 1 deletion dist/blocks.build.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/blocks.build.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/blocks.style.build.css

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dist/blocks/table-of-contents/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"type": "string",
"default": ""
},
"linkToDivider": {
"type": "boolean",
"default": false
},
"title": {
"type": "string",
"default": ""
Expand Down
2 changes: 1 addition & 1 deletion dist/priority.build.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '31d6cfe0d16ae931b73c');
<?php return array('dependencies' => array(), 'version' => 'bf4427955793c56378a0');
9 changes: 9 additions & 0 deletions dist/priority.build.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ That's it. You're done!

== Changelog ==

= 3.2.2 =

* NEW: Link to Divider Feature in Table of content block.

= 3.2.1 =

* FIX: On Split not working on WP 6.6.
Expand Down
6 changes: 5 additions & 1 deletion src/blocks/table-of-contents/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"type": "string",
"default": ""
},
"linkToDivider": {
"type": "boolean",
"default": false
},
"title": {
"type": "string",
"default": ""
Expand Down Expand Up @@ -133,4 +137,4 @@
"full"
]
}
}
}
12 changes: 8 additions & 4 deletions src/blocks/table-of-contents/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ function ub_render_table_of_contents_block($attributes){
extract($attributes);
$linkArray = json_decode($links, true);
$linkArray = is_null($linkArray) ? [] : $linkArray;
$is_link_to_divider = isset($linkToDivider) && $linkToDivider;

$filteredHeaders = $linkArray ? (array_values(array_filter($linkArray, function ($header) use ($allowedHeaders){
$filteredHeaders = $linkArray ? (array_values(array_filter($linkArray, function ($header) use ($allowedHeaders){
return $allowedHeaders[$header['level'] - 1] &&
(!array_key_exists("disabled", $header) || (array_key_exists("disabled", $header) && !$header['disabled']));
}))) : [];
Expand Down Expand Up @@ -115,11 +116,14 @@ function ub_makeListItem($num, $item, $listStyle, $blockID, $currentGaps){
array(
'class' => implode( ' ', $classes ),
'id' => $blockID === '' ? '' : 'ub_table-of-contents-' . $blockID . '',
'data-linktodivider' => $is_link_to_divider ? "true" : "false",
'data-showtext' => $showText ?: __('show', 'ultimate-blocks'),
'data-hidetext' => $hideText ?: __('hide', 'ultimate-blocks'),
'data-scrolltype' => $scrollOption,
)
);
return '<div ' . $block_wrapper_attributes .
'" data-showtext="' . ($showText ?: __('show', 'ultimate-blocks') ) . '" data-hidetext="' . ($hideText ?: __('hide', 'ultimate-blocks'))
. '" data-scrolltype="' . esc_attr($scrollOption) . '"' . ($scrollOption === 'fixedamount' ? ' data-scrollamount="' . esc_attr($scrollOffset) . '"' : '')
return '<div ' . $block_wrapper_attributes
. ($scrollOption === 'fixedamount' ? ' data-scrollamount="' . esc_attr($scrollOffset) . '"' : '')
. ($scrollOption === 'namedelement' ? ' data-scrolltarget="' . $targetType . esc_attr($scrollTarget) . '"' : '') . ' data-initiallyhideonmobile="' . json_encode($hideOnMobile) . '"
data-initiallyshow="' . json_encode($showList) . '">'.
(('<div class="ub_table-of-contents-header-container"><div class="ub_table-of-contents-header">
Expand Down
154 changes: 66 additions & 88 deletions src/blocks/table-of-contents/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ export const inspectorControls = (props) => {
numColumns,
showText,
hideText,
linkToDivider,
} = attributes;

const { updateBlockAttributes } =
Expand Down Expand Up @@ -818,56 +819,42 @@ export const inspectorControls = (props) => {
</PanelRow>
</PanelBody>
<PanelBody title={__("Collapsible")} initialOpen={false}>
<PanelRow>
<label htmlFor="ub_toc_toggle_display">{__("Collapsible")}</label>
<ToggleControl
id="ub_toc_toggle_display"
checked={allowToCHiding}
onChange={(allowToCHiding) =>
setAttributes({
allowToCHiding,
showList: allowToCHiding ? showList : true,
hideOnMobile: false,
})
}
/>
</PanelRow>
<ToggleControl
label={__("Collapsible", "ultimate-blocks")}
id="ub_toc_toggle_display"
checked={allowToCHiding}
onChange={(allowToCHiding) =>
setAttributes({
allowToCHiding,
showList: allowToCHiding ? showList : true,
hideOnMobile: false,
})
}
/>
{allowToCHiding && (
<>
<PanelRow>
<TextControl
label={__("Show text")}
value={showText}
onChange={(showText) => setAttributes({ showText })}
/>
</PanelRow>
<PanelRow>
<TextControl
label={__("Hide text")}
value={hideText}
onChange={(hideText) => setAttributes({ hideText })}
/>
</PanelRow>
<PanelRow>
<label htmlFor="ub_show_toc">{__("Initial Show")}</label>
<ToggleControl
id="ub_show_toc"
checked={showList}
onChange={() => setAttributes({ showList: !showList })}
/>
</PanelRow>
<PanelRow>
<label htmlFor="ub_hide_on_mobile">
{__("Initial Hide on Mobile")}
</label>
<ToggleControl
id="ub_hide_on_mobile"
checked={hideOnMobile}
onChange={() =>
setAttributes({ hideOnMobile: !hideOnMobile })
}
/>
</PanelRow>
<TextControl
label={__("Show text", "ultimate-blocks")}
value={showText}
onChange={(showText) => setAttributes({ showText })}
/>
<TextControl
label={__("Hide text", "ultimate-blocks")}
value={hideText}
onChange={(hideText) => setAttributes({ hideText })}
/>
<ToggleControl
label={__("Initial Show", "ultimate-blocks")}
id="ub_show_toc"
checked={showList}
onChange={() => setAttributes({ showList: !showList })}
/>
<ToggleControl
label={__("Initial Hide on Mobile", "ultimate-blocks")}
id="ub_hide_on_mobile"
checked={hideOnMobile}
onChange={() => setAttributes({ hideOnMobile: !hideOnMobile })}
/>
</>
)}
</PanelBody>
Expand Down Expand Up @@ -919,49 +906,40 @@ export const inspectorControls = (props) => {
allowReset
/>
)}
<PanelRow>
<label htmlFor="ub_toc_scroll">
{__("Enable smooth scrolling")}
</label>
<ToggleControl
id="ub_toc_scroll"
checked={enableSmoothScroll}
onChange={() => {
const tocInstances = getBlocks().filter(
(block) => block.name === "ub/table-of-contents-block",
);
tocInstances.forEach((instance) => {
updateBlockAttributes(instance.clientId, {
enableSmoothScroll: !enableSmoothScroll,
});
<ToggleControl
label={__("Enable smooth scrolling", "ultimate-blocks")}
id="ub_toc_scroll"
checked={enableSmoothScroll}
onChange={() => {
const tocInstances = getBlocks().filter(
(block) => block.name === "ub/table-of-contents-block",
);
tocInstances.forEach((instance) => {
updateBlockAttributes(instance.clientId, {
enableSmoothScroll: !enableSmoothScroll,
});
}}
/>
</PanelRow>
});
}}
/>
</PanelBody>
<PanelBody title={__("Additional")} initialOpen={false}>
<PanelRow>
<label htmlFor="ub_toc_enable_latin_conversion">
{__("Romanize anchor links")}
</label>
<ToggleControl
id="ub_toc_enable_latin_conversion"
checked={allowToLatin}
onChange={(e) => setAttributes({ allowToLatin: e })}
/>
</PanelRow>
<PanelRow>
<label htmlFor="ub_toc_toggle_diacritics">
{__("Remove diacritics from anchor links")}
</label>
<ToggleControl
id="ub_toc_toggle_diacritics"
checked={removeDiacritics}
onChange={(removeDiacritics) =>
setAttributes({ removeDiacritics })
}
/>
</PanelRow>
<ToggleControl
label={__("Link to divider", "ultimate-blocks")}
checked={linkToDivider}
onChange={() => setAttributes({ linkToDivider: !linkToDivider })}
/>
<ToggleControl
label={__("Romanize anchor links", "ultimate-blocks")}
id="ub_toc_enable_latin_conversion"
checked={allowToLatin}
onChange={(e) => setAttributes({ allowToLatin: e })}
/>
<ToggleControl
label={__("Remove diacritics from anchor links", "ultimate-blocks")}
id="ub_toc_toggle_diacritics"
checked={removeDiacritics}
onChange={(removeDiacritics) => setAttributes({ removeDiacritics })}
/>
</PanelBody>
</InspectorControls>
<InspectorControls group="styles">
Expand Down
Loading

0 comments on commit a91978a

Please sign in to comment.