Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLANET-4811 Submenu WYSIWYG #328

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e35f805
PLANET-4811 Start WYSIWYG implementation for Submenu block
mleray Jul 13, 2020
28ae842
PLANET-4811 Remove shortcode code for Submenu block
mleray Jul 13, 2020
656b287
PLANET-4811 Turn layout options into styles in the sidebar
mleray Jul 13, 2020
3acd83c
PLANET-4811 Add more destructuring to SubmenuEditor
mleray Jul 13, 2020
de9139d
PLANET-4811 Remove more unnecessary Submenu code
mleray Jul 16, 2020
c393c9f
PLANET-4811 Add frontend implementation for Submenu WYSIWYG
mleray Jul 16, 2020
3fb2303
PLANET-4811 Rename and improve SubmenuLevel
mleray Jul 16, 2020
5ad33ba
PLANET-4811 Add tooltips to Submenu style labels
mleray Jul 16, 2020
0fc6616
PLANET-4811 Retrieve submenu items
mleray Jul 19, 2020
f3ffde5
PLANET-4811 Fix className for SubmenuEditor
mleray Jul 20, 2020
edd329c
PLANET-4811 Add empty message
mleray Jul 20, 2020
2a23d00
PLANET-4811 Hide Submenu block in the frontend if no menu items
mleray Jul 20, 2020
bc237d1
PLANET-4811 Add back submenu_style attribute needed for existing blocks
mleray Jul 24, 2020
118aba3
PLANET-4811 Get postId in SubmenuFrontend and use hooks in SubmenuEditor
mleray Jul 24, 2020
a69e221
PLANET-4811 Add missing translations
mleray Jul 28, 2020
bc6d1e2
PLANET-4811 Add recursive function to get menu items
mleray Jul 28, 2020
8f852bd
PLANET-4811 Remove old conversion code
mleray Jul 28, 2020
4707554
PLANET-4811 Add proper links and back-to-top behavior
mleray Jul 29, 2020
981aeda
PLANET-4811 Fix Submenu title color in the editor
mleray Jul 29, 2020
0a02c67
PLANET-4811 Fix deprecated attributes
mleray Jul 30, 2020
8391c5e
PLANET-4811 Add target links only when needed
mleray Jul 30, 2020
205fdee
PLANET-4811 Fix Submenu rendering
mleray Jul 30, 2020
2e9c884
PLANET-4811 Simplify style registration
mleray Jul 31, 2020
2dee29b
PLANET-4811 Remove jQuery code
mleray Jul 31, 2020
c64389a
PLANET-4811 Use wp.blockEditor instead of wp.editor to fix console wa…
mleray Aug 6, 2020
629d9e7
PLANET-4811 Remove css float in the editor
mleray Aug 6, 2020
fb74aca
PLANET-4811 Create single file for all submenu functions
mleray Aug 6, 2020
db787b8
PLANET-4811 Remove unused SubmenuIcon
mleray Aug 6, 2020
f2f9669
PLANET-4811 Improve code after review
mleray Aug 6, 2020
56c7811
PLANET-4811 Remove endpoint and retrieve content in the frontend instead
mleray Aug 6, 2020
025ef07
PLANET-4811 Remove md5
mleray Aug 7, 2020
73f5cbe
PLANET-4811 Remove now unused postId prop
mleray Aug 7, 2020
701d75b
PLANET-4811 Add children behaviour to loadMenuItems function
mleray Aug 7, 2020
90a26e9
PLANET-4811 Improve code after review
mleray Aug 7, 2020
93cdb56
PLANET-4811 Create SubmenuItems component and useSubmenuItemsLoad hook
mleray Aug 10, 2020
be64e68
PLANET-4811 Fix back to top button positioning
mleray Aug 11, 2020
9af7a0c
PLANET-4811 Make sure ids are unique
mleray Aug 12, 2020
b21b331
PLANET-4811 Fix scrolling animation
mleray Aug 12, 2020
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
57 changes: 0 additions & 57 deletions assets/src/blocks/Submenu/MenuLevel.js

This file was deleted.

118 changes: 0 additions & 118 deletions assets/src/blocks/Submenu/Submenu.js

This file was deleted.

191 changes: 52 additions & 139 deletions assets/src/blocks/Submenu/SubmenuBlock.js
Original file line number Diff line number Diff line change
@@ -1,158 +1,71 @@
import {Submenu} from './Submenu.js';
import { SubmenuEditor } from './SubmenuEditor.js';
import { Tooltip } from '@wordpress/components';

const { __ } = wp.i18n;

const BLOCK_NAME = 'planet4-blocks/submenu';

const getStyleLabel = (label, help) => {
if (help) {
return (
<Tooltip text={__(help, 'planet4-blocks-backend')}>
<span>{__(label, 'planet4-blocks-backend')}</span>
</Tooltip>
);
}
return label;
}

export class SubmenuBlock {
constructor() {
const {registerBlockType} = wp.blocks;
const {withSelect} = wp.data;
const { registerBlockType } = wp.blocks;

registerBlockType('planet4-blocks/submenu', {
registerBlockType(BLOCK_NAME, {
title: 'Submenu',
icon: 'welcome-widgets-menus',
category: 'planet4-blocks',
supports: {
multiple: false, // Use the block just once per post.
},
/**
* Transforms old 'shortcake' shortcode to new gutenberg block.
*
* old block-shortcode:
* [shortcake_submenu submenu_style="3" title="title22" heading1="2"
* link1="true" style1="bullet" heading2="3" link2="true" style2="number"
* heading3="4" link3="false"
* /]
*
* new block-gutenberg:
* <!-- wp:planet4-blocks/submenu {"submenu_style":3,"title":"title22","levels":[{"heading":"2","link":"true","style":"bullet"},
* {"heading":"3","link":"true","style":"number"},{"heading":"4","link":"false","style":"none"}]} /-->
*
*/
transforms: {
from: [
{
type: 'shortcode',
// Shortcode tag can also be an array of shortcode aliases
// This `shortcode` definition will be used as a callback,
// it is a function which expects an object with at least
// a `named` key with `cover_type` property whose default value is 1.
// See: https://simonsmith.io/destructuring-objects-as-function-parameters-in-es6
tag: 'shortcake_submenu',
attributes: {
submenu_style: {
type: 'integer',
shortcode: function (attributes) {
return Number(attributes.named.submenu_style);
}
},
title: {
type: 'string',
shortcode: function (attributes) {
return attributes.named.title;
}
},
levels: {
type: 'array',
shortcode: function (attributes) {
let levels = [];
if (attributes.named.heading1 > 0) {
let level = {
heading: Number(attributes.named.heading1),
link: Boolean(attributes.named.link1) || false,
style: attributes.named.style1 || 'none'
};
levels.push(Object.assign({}, level));

if (attributes.named.heading2 > 0) {
let level = {
heading: Number(attributes.named.heading2),
link: Boolean(attributes.named.link2) || false,
style: attributes.named.style2 || 'none'
};
levels.push(Object.assign({}, level));

if (attributes.named.heading3 > 0) {
let level = {
heading: Number(attributes.named.heading3),
link: Boolean(attributes.named.link3) || false,
style: attributes.named.style3 || 'none'
};
levels.push(Object.assign({}, level));
}
}
}
return levels;
},
}
},
},
]
},
attributes: {
submenu_style: {
type: 'integer',
default: 1
},
title: {
type: 'string',
default: ''
},
submenu_style: { // Needed for old blocks conversion
type: 'integer',
default: 0
},
levels: {
type: 'array',
default: [ {heading: 0, link: false, style: 'none'}]
default: [{ heading: 0, link: false, style: 'none' }]
},
},
edit: withSelect((select) => {

})(({
isSelected,
attributes,
setAttributes
}) => {

function addLevel() {
setAttributes({levels: attributes.levels.concat({heading: 0, link: false, style: 'none'})});
}

function onTitleChange(value) {
setAttributes({title: value});
}

function onHeadingChange(index, value) {
let levels = JSON.parse(JSON.stringify(attributes.levels));
levels[index].heading = Number(value);
setAttributes({levels: levels});
}

function onLayoutChange(value) {
setAttributes({submenu_style: Number(value)});
}

function onLinkChange(index, value) {
let levels = JSON.parse(JSON.stringify(attributes.levels));
levels[index].link = value;
setAttributes({levels: levels});
}

function onStyleChange(index, value) {
let levels = JSON.parse(JSON.stringify(attributes.levels));
levels[index].style = value;
setAttributes({levels: levels});
}

function removeLevel() {
setAttributes({levels: attributes.levels.slice(0, -1)});
supports: {
multiple: false, // Use the block just once per post.
},
styles: [
{
name: 'long',
label: getStyleLabel(
'Long full-width',
'Use: on long pages (more than 5 screens) when list items are long (+ 10 words). No max items recommended.'
),
isDefault: true
},
{
name: 'short',
label: getStyleLabel(
'Short full-width',
'Use: on long pages (more than 5 screens) when list items are short (up to 5 words). No max items recommended.'
)
},
{
name: 'sidebar',
label: getStyleLabel(
'Short sidebar',
'Use: on long pages (more than 5 screens) when list items are short (up to 10 words). Max items recommended: 9'
)
}

return <Submenu
{...attributes}
isSelected={isSelected}
onSelectedLayoutChange={onLayoutChange}
onTitleChange={onTitleChange}
onHeadingChange={onHeadingChange}
onLinkChange={onLinkChange}
onStyleChange={onStyleChange}
addLevel={addLevel}
removeLevel={removeLevel}
/>
}),
],
edit: SubmenuEditor,
save() {
return null;
}
Expand Down
Loading