Changeset 2174760
- Timestamp:
- 10/17/2019 09:19:27 AM (6 years ago)
- Location:
- slide/trunk
- Files:
-
- 1 added
- 5 edited
-
index.js (modified) (16 diffs)
-
index.php (modified) (4 diffs)
-
readme.md (modified) (1 diff)
-
register.php (modified) (1 diff)
-
reveal/pdf.min.css (added)
-
template.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
slide/trunk/index.js
r2174452 r2174760 2 2 i18n, 3 3 blocks, 4 editor,5 4 element, 6 5 richText, … … 9 8 data, 10 9 components, 11 blockEditor 10 blockEditor, 11 url 12 12 }) => { 13 13 const { __ } = i18n; 14 14 const { registerBlockType, createBlock } = blocks; 15 const { RichTextToolbarButton } = editor;16 15 const { createElement: e, Fragment } = element; 17 16 const { registerFormatType, toggleFormat } = richText; … … 19 18 const { PluginDocumentSettingPanel } = editPost; 20 19 const { useSelect, useDispatch, subscribe, select, dispatch } = data; 21 const { TextareaControl, ColorPicker, PanelBody, RangeControl, TextControl, SelectControl, ToggleControl, Button, FocalPointPicker } = components; 22 const { MediaUpload, __experimentalGradientPickerControl, InnerBlocks, InspectorControls } = blockEditor; 20 const { TextareaControl, ColorPicker, PanelBody, RangeControl, TextControl, SelectControl, ToggleControl, Button, FocalPointPicker, ExternalLink } = components; 21 const { MediaUpload, __experimentalGradientPickerControl, InnerBlocks, InspectorControls, RichTextToolbarButton } = blockEditor; 22 const { addQueryArgs } = url; 23 23 const colorKey = 'presentation-color'; 24 24 const bgColorKey = 'presentation-background-color'; 25 const backgroundGradientKey = 'presentation-background-gradient'; 26 const backgroundUrlKey = 'presentation-background-url'; 27 const backgroundIdKey = 'presentation-background-id'; 28 const backgroundPositionKey = 'presentation-background-position'; 29 const backgroundOpacityKey = 'presentation-background-opacity'; 25 30 const cssKey = 'presentation-css'; 26 31 const fontSizeKey = 'presentation-font-size'; … … 52 57 select('core/editor').getEditedPostAttribute('meta') 53 58 ); 59 const link = useSelect((select) => 60 select('core/editor').getCurrentPost('meta').link 61 ); 54 62 const { editPost } = useDispatch('core/editor'); 55 63 const updateMeta = (value, key) => editPost({ 56 64 meta: { ...meta, [key]: value } 57 65 }); 66 const rules = { 67 color: meta[colorKey] || '#000', 68 'background-color': meta[bgColorKey] || '#fff', 69 'background-image': meta[backgroundGradientKey] || 'none', 70 'font-size': (meta[fontSizeKey] || '42') + 'px', 71 'font-family': meta[fontFamilyKey] || 'Helvetica, sans-serif' 72 }; 73 74 const backgroundRules = { 75 'background-image': meta[backgroundUrlKey] ? `url("${meta[backgroundUrlKey]}")` : 'none', 76 'background-size': 'cover', 77 'background-position': meta[backgroundPositionKey] ? meta[backgroundPositionKey] : '50% 50%', 78 opacity: meta[backgroundOpacityKey] ? meta[backgroundOpacityKey] / 100 : 1 79 }; 58 80 59 81 return [ 60 e('style', null, 61 ` 62 ${cssPrefix} section { 63 color: ${meta[colorKey]}; 64 background: ${meta[bgColorKey]}; 65 font-size: ${meta[fontSizeKey] || '42'}px; 66 font-family: ${meta[fontFamilyKey] || 'Helvetica, sans-serif'}; 67 } 68 ` 69 ), 82 ...Object.keys(rules).map((key) => { 83 return e( 84 'style', 85 null, 86 `${cssPrefix} section {${key}:${rules[key]}}` 87 ); 88 }), 89 ...Object.keys(backgroundRules).map((key) => { 90 return e( 91 'style', 92 null, 93 `${cssPrefix} section .wp-block-slide-slide__background {${key}:${backgroundRules[key]}}` 94 ); 95 }), 70 96 e('style', null, meta[cssKey]), 71 97 e( … … 78 104 e(RangeControl, { 79 105 label: __('Font Size', 'slide'), 80 value: parseInt(meta[fontSizeKey], 10),106 value: meta[fontSizeKey] ? parseInt(meta[fontSizeKey], 10) : undefined, 81 107 min: 10, 82 108 max: 100, 109 initialPosition: 42, 83 110 onChange: (value) => updateMeta(value + '', fontSizeKey) 84 111 }), … … 103 130 icon: 'art' 104 131 }, 105 e(__experimentalGradientPickerControl, {106 onChange: (value) => updateMeta(value, bgColorKey),107 value: meta[bgColorKey]108 }),109 132 e(ColorPicker, { 110 133 disableAlpha: true, 111 134 label: __('Background Color', 'slide'), 112 135 color: meta[bgColorKey], 113 onChangeComplete: (value) => updateMeta(value.hex, bgColorKey) 136 onChangeComplete: (value) => { 137 editPost({ 138 meta: { 139 ...meta, 140 [bgColorKey]: value.hex, 141 [backgroundGradientKey]: '' 142 } 143 }); 144 } 145 }), 146 __('Experimental:'), 147 e(__experimentalGradientPickerControl, { 148 onChange: (value) => updateMeta(value, backgroundGradientKey), 149 value: meta[backgroundGradientKey] 150 }), 151 !!meta[backgroundUrlKey] && e(RangeControl, { 152 label: __('Opacity', 'slide'), 153 help: __('May be overridden by the block!'), 154 value: meta[backgroundOpacityKey] ? 100 - parseInt(meta[backgroundOpacityKey], 10) : undefined, 155 min: 0, 156 max: 100, 157 initialPosition: 0, 158 onChange: (value) => { 159 editPost({ 160 meta: { 161 ...meta, 162 [backgroundOpacityKey]: 100 - value + '' 163 } 164 }); 165 } 166 }) 167 ), 168 e( 169 PluginDocumentSettingPanel, 170 { 171 name: 'slide-background-image', 172 title: __('Background Image', 'slide'), 173 icon: 'format-image' 174 }, 175 e(MediaUpload, { 176 onSelect: (media) => { 177 if (!media || !media.url) { 178 editPost({ 179 meta: { 180 ...meta, 181 [backgroundUrlKey]: undefined, 182 [backgroundIdKey]: undefined, 183 [backgroundPositionKey]: undefined, 184 [backgroundOpacityKey]: undefined 185 } 186 }); 187 return; 188 } 189 190 editPost({ 191 meta: { 192 ...meta, 193 [backgroundUrlKey]: media.url, 194 [backgroundIdKey]: media.id + '' 195 } 196 }); 197 }, 198 allowedTypes: ALLOWED_MEDIA_TYPES, 199 value: meta[backgroundIdKey] ? parseInt(meta[backgroundIdKey], 10) : undefined, 200 render: ({ open }) => e(Button, { 201 isDefault: true, 202 onClick: open 203 }, meta[backgroundUrlKey] ? __('Change') : __('Add Background Image')) 204 }), 205 ' ', 206 !!meta[backgroundUrlKey] && e(Button, { 207 isDefault: true, 208 onClick: () => { 209 editPost({ 210 meta: { 211 ...meta, 212 [backgroundUrlKey]: undefined, 213 [backgroundIdKey]: undefined, 214 [backgroundPositionKey]: undefined, 215 [backgroundOpacityKey]: undefined 216 } 217 }); 218 } 219 }, __('Remove')), 220 e('br'), e('br'), 221 !!meta[backgroundUrlKey] && e(FocalPointPicker, { 222 label: __('Focal Point Picker'), 223 url: meta[backgroundUrlKey], 224 value: (() => { 225 if (!meta[backgroundPositionKey]) { 226 return; 227 } 228 229 let [x, y] = meta[backgroundPositionKey].split(' '); 230 231 x = parseFloat(x) / 100; 232 y = parseFloat(y) / 100; 233 234 return { x, y }; 235 })(), 236 onChange: (focalPoint) => { 237 editPost({ 238 meta: { 239 ...meta, 240 [backgroundPositionKey]: `${focalPoint.x * 100}% ${focalPoint.y * 100}%` 241 } 242 }); 243 } 244 }), 245 !!meta[backgroundUrlKey] && e(RangeControl, { 246 label: __('Opacity', 'slide'), 247 help: __('May be overridden by the block!'), 248 value: meta[backgroundOpacityKey] ? parseInt(meta[backgroundOpacityKey], 10) : undefined, 249 min: 0, 250 max: 100, 251 initialPosition: 100, 252 onChange: (value) => { 253 editPost({ 254 meta: { 255 ...meta, 256 [backgroundOpacityKey]: value + '' 257 } 258 }); 259 } 114 260 }) 115 261 ), … … 176 322 onChange: (value) => updateMeta(value + '', progressKey) 177 323 }) 324 ), 325 e( 326 PluginDocumentSettingPanel, 327 { 328 name: 'slide-pdf', 329 title: __('PDF (Experimental)', 'slide'), 330 icon: 'page' 331 }, 332 e( 333 'p', 334 {}, 335 e( 336 ExternalLink, 337 { 338 href: addQueryArgs(link, { 'print-pdf': true }), 339 target: '_blank' 340 }, 341 __('Print (Save as PDF).', 'slides') 342 ), 343 e('br'), 344 __('Enable backgrounds and remove margins.', 'slides') 345 ) 178 346 ) 179 347 ]; … … 211 379 } 212 380 }, 213 edit: ({ attributes, setAttributes, className }) => 214 e( 381 edit: ({ attributes, setAttributes, className }) => { 382 const meta = useSelect((select) => 383 select('core/editor').getEditedPostAttribute('meta') 384 ); 385 386 return e( 215 387 Fragment, 216 388 null, … … 244 416 onChangeComplete: ({ hex: color }) => 245 417 setAttributes({ color }) 246 }) 418 }), 419 !!attributes.color && e(Button, { 420 isDefault: true, 421 onClick: () => { 422 setAttributes({ 423 color: undefined 424 }); 425 } 426 }, __('Remove')) 247 427 ), 248 428 e( … … 260 440 setAttributes({ backgroundColor }) 261 441 }), 262 !!attributes.backgroundUrl && e(RangeControl, { 442 (attributes.backgroundUrl || meta[backgroundUrlKey]) && 443 e(RangeControl, { 263 444 label: __('Opacity', 'slide'), 264 value: 100 - parseInt(attributes.backgroundOpacity, 10),445 value: attributes.backgroundOpacity ? 100 - parseInt(attributes.backgroundOpacity, 10) : undefined, 265 446 min: 0, 266 447 max: 100, 267 onChange: (value) => setAttributes({ 268 backgroundOpacity: 100 - value + '' 269 }) 270 }) 448 initialPosition: 0, 449 onChange: (value) => { 450 if (value === undefined) { 451 setAttributes({ 452 backgroundOpacity: undefined 453 }); 454 } else { 455 setAttributes({ 456 backgroundOpacity: 100 - value + '' 457 }); 458 } 459 } 460 }), 461 !!attributes.backgroundColor && e(Button, { 462 isDefault: true, 463 onClick: () => { 464 setAttributes({ 465 backgroundColor: undefined 466 }); 467 } 468 }, __('Remove')) 271 469 ), 272 470 e( … … 283 481 backgroundUrl: undefined, 284 482 backgroundId: undefined, 285 backgroundPosition: undefined, 286 backgroundOpacity: undefined 483 focalPoint: undefined 287 484 }); 288 485 return; … … 308 505 backgroundUrl: undefined, 309 506 backgroundId: undefined, 310 backgroundPosition: undefined, 311 backgroundOpacity: undefined 507 focalPoint: undefined 312 508 }); 313 509 } … … 322 518 !!attributes.backgroundUrl && e(RangeControl, { 323 519 label: __('Opacity', 'slide'), 324 value: parseInt(attributes.backgroundOpacity, 10),520 value: attributes.backgroundOpacity ? parseInt(attributes.backgroundOpacity, 10) : undefined, 325 521 min: 0, 326 522 max: 100, 523 initialPosition: 100, 327 524 onChange: (value) => setAttributes({ 328 525 backgroundOpacity: value + '' … … 337 534 style: { 338 535 color: attributes.color || undefined, 339 backgroundColor: attributes.backgroundColor || undefined 536 backgroundColor: attributes.backgroundColor || undefined, 537 // If a background color is set, disable the global gradient. 538 backgroundImage: attributes.backgroundColor ? 'none' : undefined 340 539 } 341 540 }, … … 346 545 style: { 347 546 backgroundImage: attributes.backgroundUrl ? `url("${attributes.backgroundUrl}")` : undefined, 348 backgroundSize: 'cover', 349 backgroundPosition: attributes.focalPoint ? `${attributes.focalPoint.x * 100}% ${attributes.focalPoint.y * 100}%` : '50% 50%', 547 backgroundPosition: attributes.focalPoint ? `${attributes.focalPoint.x * 100}% ${attributes.focalPoint.y * 100}%` : undefined, 350 548 opacity: attributes.backgroundOpacity ? attributes.backgroundOpacity / 100 : undefined 351 549 } … … 354 552 e(InnerBlocks) 355 553 ) 356 ), 554 ); 555 }, 357 556 save: ({ attributes }) => e( 358 557 'section', -
slide/trunk/index.php
r2174452 r2174760 5 5 * Plugin URI: https://wordpress.org/plugins/slide/ 6 6 * Description: Allows you to create presentations with the block editor. 7 * Version: 0.0. 47 * Version: 0.0.5 8 8 * Author: Ella van Durpe 9 9 * Author URI: https://ellavandurpe.com … … 49 49 'wp-element', 50 50 'wp-i18n', 51 'wp-editor',52 51 'wp-blocks', 53 52 'wp-rich-text', … … 57 56 'wp-components', 58 57 'wp-block-editor', 58 'wp-url', 59 59 ), 60 60 filemtime( dirname( __FILE__ ) . '/index.js' ), … … 118 118 ); 119 119 120 if ( isset( $_GET[ 'print-pdf' ] ) ) { 121 wp_add_inline_script( 122 'slide-reveal', 123 'window.print()' 124 ); 125 126 wp_enqueue_style( 127 'slide-reveal-pdf', 128 plugins_url( 'reveal/pdf.min.css', __FILE__ ), 129 array(), 130 '3.8.0' 131 ); 132 } 133 120 134 wp_enqueue_style( 121 135 'slide-common', -
slide/trunk/readme.md
r2174452 r2174760 6 6 Requires PHP: 5.6 7 7 Tested up to: 5.3 8 Stable tag: 0.0. 48 Stable tag: 0.0.5 9 9 License: GPL-2.0-or-later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
slide/trunk/register.php
r2173048 r2174760 46 46 'color', 47 47 'background-color', 48 'background-gradient', 49 'background-url', 50 'background-id', 51 'background-position', 52 'background-opacity', 48 53 'font-size', 49 54 'font-family', -
slide/trunk/template.php
r2174452 r2174760 8 8 content: '\f211'; 9 9 top: 3px; 10 } 11 12 @media print { 13 .print-pdf #wpadminbar { 14 display: none; 15 } 10 16 } 11 17 … … 29 35 } 30 36 37 /* Remove margin for admin bar. */ 31 38 html { 32 39 margin-top: 0 !important; … … 34 41 35 42 .reveal { 36 background: <?php echo get_post_meta( get_the_ID(), 'presentation-background-color', true ) ?: '#fff'; ?>;37 43 color: <?php echo get_post_meta( get_the_ID(), 'presentation-color', true ) ?: '#000'; ?>; 38 44 font-size: <?php echo get_post_meta( get_the_ID(), 'presentation-font-size', true ) ?: '42'; ?>px; 39 45 font-family: <?php echo get_post_meta( get_the_ID(), 'presentation-font-family', true ) ?: 'Helvetica, sans-serif'; ?>; 46 } 47 48 /* Extra specificity to override reveal background. */ 49 .reveal .slide-background { 50 background-color: <?php echo get_post_meta( get_the_ID(), 'presentation-background-color', true ) ?: '#fff'; ?>; 51 background-image: <?php echo get_post_meta( get_the_ID(), 'presentation-background-gradient', true ) ?: 'none'; ?>; 52 } 53 54 /* If a background color is set, disable the global gradient. */ 55 .reveal .slide-background[style*="background-color"] { 56 background-image: none; 57 } 58 59 .reveal .slide-background .slide-background-content { 60 background-image: url("<?php echo get_post_meta( get_the_ID(), 'presentation-background-url', true ) ?: 'none'; ?>"); 61 background-position: <?php echo get_post_meta( get_the_ID(), 'presentation-background-position', true ) ?: '50% 50%'; ?>; 62 opacity: <?php echo (int) get_post_meta( get_the_ID(), 'presentation-background-opacity', true ) / 100 ?: '1'; ?>; 40 63 } 41 64
Note: See TracChangeset
for help on using the changeset viewer.