Changeset 2230008
- Timestamp:
- 01/19/2020 11:23:35 PM (6 years ago)
- Location:
- magic-block/trunk
- Files:
-
- 5 edited
-
css/magicblock.css (modified) (1 diff)
-
js/magicblock-jsx.js (modified) (8 diffs)
-
js/magicblock.build.js (modified) (10 diffs)
-
magicblock.php (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
magic-block/trunk/css/magicblock.css
r2229988 r2230008 57 57 } 58 58 59 .magicblock-custom-attr-pair {60 margin-bottom: 10px;61 padding: 1em;62 border-radius: 5px;63 border: solid 1px grey;64 }65 66 .magicblock-custom-attr-pair > div {67 margin-bottom: 1em;68 }69 70 .magicblock-custom-attr-key-field {71 display: flex;72 align-items: center;73 }74 75 .magicblock-custom-attr-key-field-prefix {76 margin-right: .5em;77 }78 79 .magicblock-custom-attr-label {80 font-weight: 600;81 margin-bottom: .5em;82 }83 84 .magic-block-right-align {85 text-align: right;86 } -
magic-block/trunk/js/magicblock-jsx.js
r2229988 r2230008 4 4 const { InspectorControls, InnerBlocks, PlainText} = wp.editor; 5 5 const { Fragment } = wp.element; 6 const { PanelBody, SelectControl, CheckboxControl, Button} = wp.components; 6 const { PanelBody, SelectControl, CheckboxControl } = wp.components; 7 7 8 8 9 const icon = () => { … … 35 36 attribute: 'href', 36 37 }, 37 customAttrs: {38 type: 'array'39 },40 38 newTab: { 41 39 type: 'boolean' … … 56 54 57 55 edit: props => { 58 59 const { 60 inlineSytle, 61 elemTag, 62 elemId, 63 elemClass, 64 href, 65 newTab, 66 customAttrs 67 } = props.attributes; 56 let inlineSytle = props.attributes.inlineStyle, 57 elemTag = props.attributes.elemTag, 58 elemId = props.attributes.elemId, 59 elemClass = props.attributes.elemClass, 60 href = props.attributes.href, 61 newTab = props.attributes.newTab; 68 62 69 63 70 function convertClassString ( input) {64 function convertClassString(input) { 71 65 return input.replace(/\s+$/g, '').replace(/[ ]+/g, "."); 72 66 } 73 67 74 function onChangeElem ( newElem ) {68 function onChangeElem( newElem ) { 75 69 props.setAttributes( { elemTag: newElem } ); 76 70 } … … 95 89 props.setAttributes( { newTab: newNewTab } ); 96 90 } 97 98 function addNewCustomAttr () { 99 let newCustomAttrArray; 100 if(customAttrs){ 101 newCustomAttrArray = [ 102 ...customAttrs, 103 { 104 key: '', 105 value: '' 106 } 107 ]; 108 } 109 else { 110 newCustomAttrArray = [{ 111 key: '', 112 value: '' 113 }]; 114 } 115 props.setAttributes({customAttrs: newCustomAttrArray}); 116 } 117 118 function deleteCustomAttr (index) { 119 const newCustomAttrArray = [...customAttrs]; 120 newCustomAttrArray.splice(index, 1); 121 props.setAttributes({customAttrs: newCustomAttrArray}); 122 } 123 124 function setKeyForCustomAttrs ( index, newKey ) { 125 const newCustomAttrArray = [...customAttrs]; 126 newCustomAttrArray[index].key = newKey.replace(/" *"|^-|^_|^[0-9]|[^\w-]/g, ''); 127 props.setAttributes({customAttrs: newCustomAttrArray}); 128 } 129 130 function setValueForCustomAttrs ( index, newValue, ) { 131 const newCustomAttrArray = [...customAttrs]; 132 newCustomAttrArray[index].value = newValue.replace(/"/, ''); 133 props.setAttributes({customAttrs: newCustomAttrArray}); 134 } 135 91 136 92 137 93 const linkPanels = ( … … 152 108 <InspectorControls> 153 109 <PanelBody title="Element Type"> 154 <SelectControl value={elemTag} onChange={onChangeElem} options={[110 <SelectControl label="Tag" value={elemTag} onChange={onChangeElem} options={[ 155 111 { label: "div", value: "div"}, 156 112 { label: "section", value: 'section'}, … … 182 138 <PlainText onChange={onChangeInlineStyle} value={inlineSytle} className="magicblock-plaintext"/> 183 139 </PanelBody> 184 <PanelBody title="Custom Attributes">185 {customAttrs && customAttrs.map((attr, index) => (186 <div className="magicblock-custom-attr-pair">187 <div>188 <div className="magicblock-custom-attr-label">Name</div>189 <div className="magicblock-custom-attr-key-field">190 <PlainText onChange={newKey => setKeyForCustomAttrs(index, newKey)} value={attr.key} className="magicblock-plaintext"/>191 </div>192 </div>193 <div>194 <div className="magicblock-custom-attr-label">Value</div>195 <PlainText onChange={newValue => setValueForCustomAttrs(index, newValue)} value={attr.value} className="magicblock-plaintext"/>196 </div>197 <Button isSmall={true} onClick={() => deleteCustomAttr(index)}>Delete</Button>198 </div>199 ))}200 <div class="magic-block-right-align"><Button isSmall={true} onClick={addNewCustomAttr}>New Attribute</Button></div>201 </PanelBody>202 140 </InspectorControls> 203 141 <div className="magicblock-editor"> … … 213 151 }, 214 152 save: props => { 215 216 const { inlineSytle, elemId, elemClass, newTab, customAttrs } = props.attributes; 217 const ElemTag = props.attributes.elemTag || "div"; 218 const href = props.attributes.href || ""; 153 let inlineSytle = props.attributes.inlineStyle, 154 elemId = props.attributes.elemId, 155 elemClass = props.attributes.elemClass, 156 ElemTag = props.attributes.elemTag || "div", 157 href = props.attributes.href || "", 158 newTab = props.attributes.newTab; 219 159 220 160 const aProps = {}; … … 227 167 } 228 168 229 const preparedCustomAttrs = {};230 if(customAttrs){231 customAttrs.forEach(pair => {232 if(pair.key.length > 0){233 preparedCustomAttrs[pair.key.replace(/" *"|^-|^_|^[0-9]|[^\w-]/g, '')] = pair.value.replace(/"/, '');234 }235 })236 }237 238 169 return (<ElemTag 239 className={elemClass} 240 style={inlineSytle} 241 id={elemId} 242 {...aProps} 243 {...preparedCustomAttrs} 170 className={elemClass} 171 style={inlineSytle} 172 id={elemId} 173 {...aProps} 244 174 > 245 175 <InnerBlocks.Content/> -
magic-block/trunk/js/magicblock.build.js
r2229988 r2230008 70 70 var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; 71 71 72 function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }73 74 72 console.log('magicblock is up and running'); 75 73 … … 83 81 PanelBody = _wp$components.PanelBody, 84 82 SelectControl = _wp$components.SelectControl, 85 CheckboxControl = _wp$components.CheckboxControl, 86 Button = _wp$components.Button; 83 CheckboxControl = _wp$components.CheckboxControl; 87 84 88 85 … … 118 115 attribute: 'href' 119 116 }, 120 customAttrs: {121 type: 'array'122 },123 117 newTab: { 124 118 type: 'boolean' … … 139 133 140 134 edit: function edit(props) { 141 var _props$attributes = props.attributes, 142 inlineSytle = _props$attributes.inlineSytle, 143 elemTag = _props$attributes.elemTag, 144 elemId = _props$attributes.elemId, 145 elemClass = _props$attributes.elemClass, 146 href = _props$attributes.href, 147 newTab = _props$attributes.newTab, 148 customAttrs = _props$attributes.customAttrs; 149 135 var inlineSytle = props.attributes.inlineStyle, 136 elemTag = props.attributes.elemTag, 137 elemId = props.attributes.elemId, 138 elemClass = props.attributes.elemClass, 139 href = props.attributes.href, 140 newTab = props.attributes.newTab; 150 141 151 142 function convertClassString(input) { … … 175 166 function onChangeNewTab(newNewTab) { 176 167 props.setAttributes({ newTab: newNewTab }); 177 }178 179 function addNewCustomAttr() {180 var newCustomAttrArray = void 0;181 if (customAttrs) {182 newCustomAttrArray = [].concat(_toConsumableArray(customAttrs), [{183 key: '',184 value: ''185 }]);186 } else {187 newCustomAttrArray = [{188 key: '',189 value: ''190 }];191 }192 props.setAttributes({ customAttrs: newCustomAttrArray });193 }194 195 function deleteCustomAttr(index) {196 var newCustomAttrArray = [].concat(_toConsumableArray(customAttrs));197 newCustomAttrArray.splice(index, 1);198 props.setAttributes({ customAttrs: newCustomAttrArray });199 }200 201 function setKeyForCustomAttrs(index, newKey) {202 var newCustomAttrArray = [].concat(_toConsumableArray(customAttrs));203 newCustomAttrArray[index].key = newKey.replace(/" *"|^-|^_|^[0-9]|[^\w-]/g, '');204 props.setAttributes({ customAttrs: newCustomAttrArray });205 }206 207 function setValueForCustomAttrs(index, newValue) {208 var newCustomAttrArray = [].concat(_toConsumableArray(customAttrs));209 newCustomAttrArray[index].value = newValue.replace(/"/, '');210 props.setAttributes({ customAttrs: newCustomAttrArray });211 168 } 212 169 … … 235 192 PanelBody, 236 193 { title: "Element Type" }, 237 wp.element.createElement(SelectControl, { value: elemTag, onChange: onChangeElem, options: [{ label: "div", value: "div" }, { label: "section", value: 'section' }, { label: "main", value: 'main' }, { label: "aside", value: 'aside' }, { label: "article", value: 'article' }, { label: "header", value: 'header' }, { label: "footer", value: 'footer' }, { label: "nav", value: 'nav' }, { label: "dl", value: 'dl' }, { label: "dd", value: 'dd' }, { label: "dt", value: 'dt' }, { label: "a", value: "a" }]194 wp.element.createElement(SelectControl, { label: "Tag", value: elemTag, onChange: onChangeElem, options: [{ label: "div", value: "div" }, { label: "section", value: 'section' }, { label: "main", value: 'main' }, { label: "aside", value: 'aside' }, { label: "article", value: 'article' }, { label: "header", value: 'header' }, { label: "footer", value: 'footer' }, { label: "nav", value: 'nav' }, { label: "dl", value: 'dl' }, { label: "dd", value: 'dd' }, { label: "dt", value: 'dt' }, { label: "a", value: "a" }] 238 195 }), 239 196 elemTag === "a" ? wp.element.createElement( … … 269 226 { title: "Inline CSS" }, 270 227 wp.element.createElement(PlainText, { onChange: onChangeInlineStyle, value: inlineSytle, className: "magicblock-plaintext" }) 271 ),272 wp.element.createElement(273 PanelBody,274 { title: "Custom Attributes" },275 customAttrs && customAttrs.map(function (attr, index) {276 return wp.element.createElement(277 "div",278 { className: "magicblock-custom-attr-pair" },279 wp.element.createElement(280 "div",281 null,282 wp.element.createElement(283 "div",284 { className: "magicblock-custom-attr-label" },285 "Name"286 ),287 wp.element.createElement(288 "div",289 { className: "magicblock-custom-attr-key-field" },290 wp.element.createElement(PlainText, { onChange: function onChange(newKey) {291 return setKeyForCustomAttrs(index, newKey);292 }, value: attr.key, className: "magicblock-plaintext" })293 )294 ),295 wp.element.createElement(296 "div",297 null,298 wp.element.createElement(299 "div",300 { className: "magicblock-custom-attr-label" },301 "Value"302 ),303 wp.element.createElement(PlainText, { onChange: function onChange(newValue) {304 return setValueForCustomAttrs(index, newValue);305 }, value: attr.value, className: "magicblock-plaintext" })306 ),307 wp.element.createElement(308 Button,309 { isSmall: true, onClick: function onClick() {310 return deleteCustomAttr(index);311 } },312 "Delete"313 )314 );315 }),316 wp.element.createElement(317 "div",318 { "class": "magic-block-right-align" },319 wp.element.createElement(320 Button,321 { isSmall: true, onClick: addNewCustomAttr },322 "New Attribute"323 )324 )325 228 ) 326 229 ), … … 354 257 }, 355 258 save: function save(props) { 356 var _props$attributes2 = props.attributes, 357 inlineSytle = _props$attributes2.inlineSytle, 358 elemId = _props$attributes2.elemId, 359 elemClass = _props$attributes2.elemClass, 360 newTab = _props$attributes2.newTab, 361 customAttrs = _props$attributes2.customAttrs; 362 363 var ElemTag = props.attributes.elemTag || "div"; 364 var href = props.attributes.href || ""; 259 var inlineSytle = props.attributes.inlineStyle, 260 elemId = props.attributes.elemId, 261 elemClass = props.attributes.elemClass, 262 ElemTag = props.attributes.elemTag || "div", 263 href = props.attributes.href || "", 264 newTab = props.attributes.newTab; 365 265 366 266 var aProps = {}; … … 373 273 } 374 274 375 var preparedCustomAttrs = {};376 if (customAttrs) {377 customAttrs.forEach(function (pair) {378 if (pair.key.length > 0) {379 preparedCustomAttrs[pair.key.replace(/" *"|^-|^_|^[0-9]|[^\w-]/g, '')] = pair.value.replace(/"/, '');380 }381 });382 }383 384 275 return wp.element.createElement( 385 276 ElemTag, … … 388 279 style: inlineSytle, 389 280 id: elemId 390 }, aProps , preparedCustomAttrs),281 }, aProps), 391 282 wp.element.createElement(InnerBlocks.Content, null) 392 283 ); -
magic-block/trunk/magicblock.php
r2229988 r2230008 2 2 /* 3 3 Plugin Name: Magic Block 4 Description: Registers a container block . It has settings for element, ID, classname, style, and any other attribute.5 Version: 1.2 4 Description: Registers a container block with the WP5+ (Gutenberg) editor. This block has settings for element type (div, section, etc), id, classname, and style (inline css). 5 Version: 1.2.1 6 6 Author: Will Delphia 7 7 License: GPL2 -
magic-block/trunk/readme.txt
r2229988 r2230008 1 1 === Magic Block === 2 2 Contributors: willdelphia 3 Tags: block, container block, html element, data attributes, div, section, flexbox, css grid, tag, nesting, child blocks, parent blocks3 Tags: gutenberg, block, container block, html element, html5, div, section, flexbox, css grid, tag, nesting, child blocks, parent blocks 4 4 Requires at least: 5.0 5 Tested up to: 5. 3.25 Tested up to: 5.1 6 6 Requires PHP: 5.2.4 7 7 License: GPL2 … … 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 Registers a container block . It has settings for element, ID, classname, style, and any other attribute.11 Registers a container block with the block editor. It has settings for tag (div, section, etc), ID, classname, and inline style. 12 12 13 13 == Description == 14 14 15 Magic Block registers a container block with the block editor . This block has settings for element (div, section, etc), ID, classname, inline style, and any other attribute (including data-*, and aria-*) via a custom attributes section.15 Magic Block registers a container block with the block editor (Wordpress 5+). This block has settings for tag (div, section, etc), ID, classname, and inline style. 16 16 17 17 Magic Block is designed for people who want full control over post HTML structure, or wish to use the editor to create complex layouts such as Flexbox, CSS Grid, Bootstrap, etc... … … 21 21 In the editor view, each Magic Block has a thin grey outline so you can easily see which child elements belong to it. It also provides a display of element type, ID, and classes so you can keep track of how to target them with your CSS. 22 22 23 As of Wordpress 5.3 you might not need this plugin since the core now ships with a "Group Block" which is similar in purpose, although it has fewer options.24 25 23 == Screenshots == 26 24 1. You can nest magic blocks inside each other to build complex layouts. 27 2. Custom attributes supported
Note: See TracChangeset
for help on using the changeset viewer.