Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions packages/gutenberg/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ window.coreframework = {

const removeDuplicates = <T extends unknown>(arr: T[]): T[] => [...new Set(arr)];

const parseClassNames = (className?: string): string[] =>
className ? className.replace(/\s\s+/g, " ").trim().split(" ").filter(Boolean) : [];

const stylesGroupsIconsMap: Record<string, React.ComponentType<any>> = {
colorStyles: ColorPalette,
typographyStyles: Typography,
Expand Down Expand Up @@ -200,38 +203,27 @@ const withInspectorControls = createHigherOrderComponent((BlockEdit: React.Compo

const [searchValue, setSearchValue] = useState("");

// Seed from the saved className so the first render already matches the block.
const [classNames, setClassNames] = useState<{
active: string[];
dynamic: string[];
}>({
active: [],
}>(() => ({
active: parseClassNames(props.attributes.className),
dynamic: [],
});
}));

const [selectedSearchResult, setSelectedSearchResult] = useState(-1);

useEffect(() => {
if (!props.attributes.className) {
const className = [...classNames.active, ...classNames.dynamic].join(" ");

// Any differing write, even "" over no className or a whitespace-only change, marks a clean post, template or template part as modified.
if (className === parseClassNames(props.attributes.className).join(" ")) {
return;
}

const regExpToRemoveMultipleSpaces = /\s\s+/g;
const parsedClassNames = props.attributes.className.replace(regExpToRemoveMultipleSpaces, " ").trim();
const initialClassNames = parsedClassNames.split(" ");
setClassNames((prev) => ({
...prev,
active: initialClassNames,
}));
}, []);

useEffect(
() => {
props.setAttributes({
className: [...classNames.active, ...classNames.dynamic].join(" "),
});
},
[classNames],
);
props.setAttributes({ className });
}, [classNames]);

useEffect(() => {
setSearchValue("");
Expand Down
2 changes: 1 addition & 1 deletion packages/wp/gutenberg/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-jsx-runtime', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-plugins'), 'version' => '22d01165d701dd03054a');
<?php return array('dependencies' => array('react', 'react-jsx-runtime', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-plugins'), 'version' => '2acb1b0b908a40c3b7a8');
Loading
Loading