Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricewijnia committed May 27, 2020
2 parents e9dc6bd + 594e096 commit 35a6266
Show file tree
Hide file tree
Showing 12 changed files with 2,392 additions and 1,987 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ Laraberg.init('[id_here]', { maxHeight: '500px' })

Laraberg.init('[id_here]', { minHeight: '500px' })
```

## Placeholder

You can change the default Gutenberg placeholder by adding a placeholder attribute to your textarea:

```html
<textarea placeholder="[placeholder_here]" id="[id_here]" name="[name_here]" hidden></textarea>
```

## API Routes

After publishing the vendor files you can find the 'laraberg.php' file in your config folder. This file allows you to configure the API Routes. Here you can change the URL prefix and the middleware for the routes.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "laraberg",
"version": "1.1.0",
"version": "1.1.1",
"description": "A Gutenberg implementation for Laravel",
"main": "src/resources/laraberg.js",
"directories": {
Expand Down
4,270 changes: 2,350 additions & 1,920 deletions public/css/laraberg.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/css/laraberg.css.map

Large diffs are not rendered by default.

60 changes: 11 additions & 49 deletions public/js/laraberg.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/laraberg.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Helpers/EmbedHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class EmbedHelper
public static function renderEmbeds($html)
{
// Match URL from raw Gutenberg embed content
$regex = '/<!-- wp:core-embed\/.*?-->\s*?<figure class="wp-block-embed.*?".*?<div class="wp-block-embed__wrapper">\s*?(.*?)\s*?<\/div><\/figure>/';
$regex = '/<!-- wp:core-embed\/.*?-->\s*?<figure class="wp-block-embed.*?".*?<div class="wp-block-embed__wrapper">\s*?(.*?)\s*?<\/div>.*?<\/figure>/';
$result = preg_replace_callback($regex, function ($matches) {
$embed = self::create($matches[1]);
$url = preg_replace('/\//', '\/', preg_quote($matches[1]));
Expand Down
11 changes: 5 additions & 6 deletions src/Models/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public function render()
*/
public function setContent($html)
{
$this->raw_content = $html;
$this->fixEmptyImages();
$this->raw_content = $this->fixEmptyImages($html);
$this->renderRaw();
}

Expand All @@ -68,17 +67,17 @@ public function renderRaw()

return $this->rendered_content;
}

/**
* TODO: Remove this temporary fix for Image block crashing when no image is selected
*/
private function fixEmptyImages() {
private function fixEmptyImages($html) {
$regex = '/<img(.*)\/>/';
$this->raw_content = preg_replace_callback($regex, function ($matches) {
return preg_replace_callback($regex, function ($matches) {
if (isset($matches[1]) && strpos($matches[1], 'src="') === false) {
return str_replace('<img ', '<img src="/vendor/laraberg/img/placeholder.jpg" ', $matches[0]);
}
return $matches[0];
}, $this->raw_content);
}, $html);
}
}
14 changes: 12 additions & 2 deletions src/resources/js/gutenberg/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export default function init (target, options = {}) {
toggleFeature('fullscreenMode')

// Disable block patterns
plugins.unregisterPlugin('edit-post');
plugins.unregisterPlugin('edit-post')

window._wpLoadGutenbergEditor = new Promise(function (resolve) {
domReady(async () => {
const larabergEditor = createEditorElement(target)
try {
resolve(editPost.initializeEditor(larabergEditor.id, 'page', 1, editorSettings, overridePost))
resolve(editPost.initializeEditor(larabergEditor.id, 'page', 1, getEditorSettings(), overridePost))
fixReusableBlocks()
} catch (error) {
console.error(error)
Expand Down Expand Up @@ -65,3 +65,13 @@ function fixReusableBlocks () {
}
registerBlockType('core/block', coreBlock)
}

function getEditorSettings() {
const targetElement = document.getElementById(editorSettings.target)

if (targetElement && targetElement.placeholder) {
editorSettings.bodyPlaceholder = targetElement.placeholder
}

return editorSettings
}
2 changes: 1 addition & 1 deletion src/resources/js/gutenberg/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const editorSettings = {
postLock: {
isLocked: false
},
autosaveInterval: 9999,
autosaveInterval: 9999
}

// Post properties to override
Expand Down
4 changes: 0 additions & 4 deletions src/resources/js/lib/configure-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ function setupSubmit (target) {
if (textarea.form) {
textarea.form.addEventListener('submit', event => {
textarea.value = data.select('core/editor').getEditedPostContent()
// Clear content "dirty" state.
data.dispatch('core/editor').savePost()
return true
})
}
Expand Down Expand Up @@ -156,6 +154,4 @@ function removeElements () {
elementRendered('.editor-post-trash', element => { element.remove() })

elementRendered('.editor-post-saved-state', element => { element.style.display = 'none' })

elementRendered('.components-popover__content div .components-menu-group:last-of-type', element => { element.style.display = 'none' })
}
1 change: 0 additions & 1 deletion src/resources/js/lib/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as MockData from '../api/mock-data'
const { data } = window.wp

export function getContent () {
data.dispatch('core/editor').savePost()
return data.select('core/editor').getEditedPostContent()
}

Expand Down

0 comments on commit 35a6266

Please sign in to comment.