Skip to content

Commit

Permalink
fix empty color option in table of content
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan-shafi committed Jan 24, 2024
1 parent fb78917 commit 52bbc99
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 100 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' => '91710aab9379134097bf');
<?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' => '27d415abe1414667e2d9');
59 changes: 18 additions & 41 deletions dist/blocks.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -57763,6 +57763,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
var _excluded = ["blockID", "title"];
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
Expand Down Expand Up @@ -58364,6 +58365,22 @@ var inspectorControls = function inspectorControls(props) {
updateBlockAttributes = _ref4.updateBlockAttributes;
var _ref5 = select("core/block-editor") || select("core/editor"),
getBlocks = _ref5.getBlocks;
var createColorSetting = function createColorSetting(value, label) {
var onChange = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (newValue) {
return setAttributes(_defineProperty({}, label, newValue));
};
return {
value: value,
onChange: onChange,
label: __(label)
};
};
var getColorSettings = function getColorSettings() {
var settings = [createColorSetting(titleColor, "Title Color"), createColorSetting(titleBackgroundColor, "Title Background Color"), createColorSetting(listColor, "List Color"), createColorSetting(listBackgroundColor, "List Background Color")].concat(_toConsumableArray(listStyle !== "plain" ? [createColorSetting(listIconColor, listStyle === "numbered" ? "Item number color" : "List icon color")] : []));
return settings.filter(function (setting) {
return Object.keys(setting).length > 0;
});
};
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(InspectorControls, {
group: "settings"
}, /*#__PURE__*/React.createElement(PanelBody, {
Expand Down Expand Up @@ -58609,47 +58626,7 @@ var inspectorControls = function inspectorControls(props) {
}, /*#__PURE__*/React.createElement(PanelColorSettings, {
title: __("Color Settings"),
initialOpen: false,
colorSettings: [{
value: titleColor,
onChange: function onChange(titleColor) {
return setAttributes({
titleColor: titleColor
});
},
label: __("Title Color")
}, {
value: titleBackgroundColor,
onChange: function onChange(titleBackgroundColor) {
return setAttributes({
titleBackgroundColor: titleBackgroundColor
});
},
label: __("Title Background Color")
}, {
value: listColor,
onChange: function onChange(listColor) {
return setAttributes({
listColor: listColor
});
},
label: __("List Color")
}, {
value: listBackgroundColor,
onChange: function onChange(listBackgroundColor) {
return setAttributes({
listBackgroundColor: listBackgroundColor
});
},
label: __("List Background Color")
}].concat([listStyle !== "plain" ? {
value: listIconColor,
onChange: function onChange(listIconColor) {
return setAttributes({
listIconColor: listIconColor
});
},
label: listStyle === "numbered" ? __("Item number color") : __("List icon color")
} : []])
colorSettings: getColorSettings()
})), /*#__PURE__*/React.createElement(PanelBody, {
title: __("Dimension Settings", "ultimate-blocks"),
initialOpen: false
Expand Down
2 changes: 1 addition & 1 deletion dist/blocks.build.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ That's it. You're done!

= 3.1.2 =

* FIX: Empty color option in table of content block.
* FIX: PHP errors and warning for WP 5.7.3 and PHP 7.4.33.
* FIX: Video uploading in advanced video block.
* IMPROVE: Add upsell for post grid pagination.
Expand Down
107 changes: 50 additions & 57 deletions src/blocks/table-of-contents/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class TableOfContents extends Component {
} else if (block.name === "themeisle-blocks/advanced-heading") {
if (
["h1", "h2", "h3", "h4", "h5", "h6"].includes(
block.attributes.tag
block.attributes.tag,
)
) {
newBlock.attributes = Object.assign(blockAttributes, {
Expand All @@ -123,7 +123,7 @@ class TableOfContents extends Component {
} else if (block.name === "generateblocks/headline") {
if (
["h1", "h2", "h3", "h4", "h5", "h6"].includes(
newBlock.attributes.element
newBlock.attributes.element,
)
) {
newBlock.attributes = Object.assign(
Expand All @@ -134,7 +134,7 @@ class TableOfContents extends Component {
: blockAttributes.content,
level: Number(blockAttributes.element.charAt(1)),
anchor: blockAttributes.elementId,
}
},
);
//also set elementID to generated anchor value
headings.push(newBlock);
Expand All @@ -147,7 +147,7 @@ class TableOfContents extends Component {
content: blockAttributes.panelTitle,
level: Number(blockAttributes.titleTag.charAt(1)),
anchor: blockAttributes.toggleID,
}
},
);

headings.push(newBlock);
Expand All @@ -168,7 +168,7 @@ class TableOfContents extends Component {
"ub/advanced-heading",
].includes(block.name) ||
(block.name === "ub/content-toggle-panel-block" &&
block.attributes.useToggleInToC)
block.attributes.useToggleInToC),
);

if (internalHeadings.length > 0) {
Expand Down Expand Up @@ -205,14 +205,14 @@ class TableOfContents extends Component {
: 0;
if (Array.isArray(h.attributes.content)) {
h.attributes.content = mergeRichTextArray(
h.attributes.content
h.attributes.content,
);
}
break;
case "ub/content-toggle-panel-block":
h.attributes.content = h.attributes.panelTitle;
h.attributes.level = Number(
blockAttributes.titleTag.charAt(1)
blockAttributes.titleTag.charAt(1),
);
h.attributes.anchor = h.attributes.toggleID;

Expand Down Expand Up @@ -246,7 +246,7 @@ class TableOfContents extends Component {
Object.assign(header.attributes, {
clientId: header.clientId,
blockName: header.name,
})
}),
);

headers.forEach((heading, key) => {
Expand All @@ -260,7 +260,7 @@ class TableOfContents extends Component {
: (this.props.allowToLatin
? toLatin("all", heading.content.toString())
: heading.content.toString()
)
)
.toLowerCase()
.replace(/( |<.+?>|&nbsp;)/g, "-")
}`;
Expand All @@ -272,7 +272,7 @@ class TableOfContents extends Component {
if (removeDiacritics) {
heading.anchor = filterDiacritics(heading.anchor).replace(
/[\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF]/g,
""
"",
);
}

Expand Down Expand Up @@ -350,7 +350,7 @@ class TableOfContents extends Component {
let hasMismatch = false;

this.state.headers.some(
(h, i) => h.clientId !== newHeaders[i].clientId
(h, i) => h.clientId !== newHeaders[i].clientId,
);

if (checkIDs && hasMismatch) {
Expand Down Expand Up @@ -439,7 +439,7 @@ class TableOfContents extends Component {
}
let replacements = JSON.parse(JSON.stringify(replacementHeaders)).sort(
(a, b) =>
newIDs.indexOf(a.clientId) > newIDs.indexOf(b.clientId) ? 1 : -1
newIDs.indexOf(a.clientId) > newIDs.indexOf(b.clientId) ? 1 : -1,
);

if (mismatchLocs.length < 1) {
Expand All @@ -448,7 +448,7 @@ class TableOfContents extends Component {
disabled: headers[newIDs.indexOf(headers[i].clientId)].disabled,
customContent:
headers[newIDs.indexOf(headers[i].clientId)].customContent,
})
}),
);
}

Expand All @@ -467,7 +467,7 @@ class TableOfContents extends Component {

insertionSpots.forEach((index, i) => {
const currentHeader = replacementHeaders.filter(
(nh) => nh.clientId === diff[i]
(nh) => nh.clientId === diff[i],
)[0];
currentHeaders.splice(index, 0, currentHeader);
});
Expand Down Expand Up @@ -545,7 +545,7 @@ class TableOfContents extends Component {
const revisedHeaders = JSON.parse(JSON.stringify(this.state.headers));

const currentlyEditedHeader = revisedHeaders.filter(
(h) => h.clientId === currentlyEditedItem
(h) => h.clientId === currentlyEditedItem,
)[0];

if (
Expand Down Expand Up @@ -575,7 +575,7 @@ class TableOfContents extends Component {
value={item.customContent}
onChange={(e) => {
const revisedHeaders = JSON.parse(
JSON.stringify(this.state.headers)
JSON.stringify(this.state.headers),
);
revisedHeaders[item.index].customContent = e.target.value;
this.setState({ headers: revisedHeaders });
Expand All @@ -601,14 +601,14 @@ class TableOfContents extends Component {
<button
onClick={() => {
const revisedHeaders = JSON.parse(
JSON.stringify(this.state.headers)
JSON.stringify(this.state.headers),
);

if (!revisedHeaders[item.index].customContent) {
revisedHeaders[item.index].customContent =
revisedHeaders[item.index].content.replace(
/<.+?>/g,
""
"",
);
this.setState({ headers: revisedHeaders });
}
Expand All @@ -621,7 +621,7 @@ class TableOfContents extends Component {
<button
onClick={() => {
const revisedHeaders = JSON.parse(
JSON.stringify(this.state.headers)
JSON.stringify(this.state.headers),
);
revisedHeaders[item.index].disabled =
!revisedHeaders[item.index].disabled;
Expand Down Expand Up @@ -716,6 +716,35 @@ export const inspectorControls = (props) => {
const { updateBlockAttributes } =
dispatch("core/block-editor") || dispatch("core/editor");
const { getBlocks } = select("core/block-editor") || select("core/editor");
const createColorSetting = (
value,
label,
onChange = (newValue) => setAttributes({ [label]: newValue }),
) => ({
value,
onChange,
label: __(label),
});

const getColorSettings = () => {
const settings = [
createColorSetting(titleColor, "Title Color"),
createColorSetting(titleBackgroundColor, "Title Background Color"),
createColorSetting(listColor, "List Color"),
createColorSetting(listBackgroundColor, "List Background Color"),
...(listStyle !== "plain"
? [
createColorSetting(
listIconColor,
listStyle === "numbered"
? "Item number color"
: "List icon color",
),
]
: []),
];
return settings.filter((setting) => Object.keys(setting).length > 0);
};

return (
<>
Expand Down Expand Up @@ -902,7 +931,7 @@ export const inspectorControls = (props) => {
checked={enableSmoothScroll}
onChange={() => {
const tocInstances = getBlocks().filter(
(block) => block.name === "ub/table-of-contents-block"
(block) => block.name === "ub/table-of-contents-block",
);
tocInstances.forEach((instance) => {
updateBlockAttributes(instance.clientId, {
Expand Down Expand Up @@ -955,43 +984,7 @@ export const inspectorControls = (props) => {
<PanelColorSettings
title={__("Color Settings")}
initialOpen={false}
colorSettings={[
{
value: titleColor,
onChange: (titleColor) => setAttributes({ titleColor }),
label: __("Title Color"),
},
{
value: titleBackgroundColor,
onChange: (titleBackgroundColor) =>
setAttributes({ titleBackgroundColor }),
label: __("Title Background Color"),
},
{
value: listColor,
onChange: (listColor) => setAttributes({ listColor }),
label: __("List Color"),
},
{
value: listBackgroundColor,
onChange: (listBackgroundColor) =>
setAttributes({ listBackgroundColor }),
label: __("List Background Color"),
},
...[
listStyle !== "plain"
? {
value: listIconColor,
onChange: (listIconColor) =>
setAttributes({ listIconColor }),
label:
listStyle === "numbered"
? __("Item number color")
: __("List icon color"),
}
: [],
],
]}
colorSettings={getColorSettings()}
/>
</PanelBody>
<PanelBody
Expand Down

0 comments on commit 52bbc99

Please sign in to comment.