Skip to content

Commit 35a6266

Browse files
committed
Merge branch 'dev'
2 parents e9dc6bd + 594e096 commit 35a6266

File tree

12 files changed

+2392
-1987
lines changed

12 files changed

+2392
-1987
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@ Laraberg.init('[id_here]', { maxHeight: '500px' })
342342

343343
Laraberg.init('[id_here]', { minHeight: '500px' })
344344
```
345+
346+
## Placeholder
347+
348+
You can change the default Gutenberg placeholder by adding a placeholder attribute to your textarea:
349+
350+
```html
351+
<textarea placeholder="[placeholder_here]" id="[id_here]" name="[name_here]" hidden></textarea>
352+
```
353+
345354
## API Routes
346355

347356
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.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "laraberg",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "A Gutenberg implementation for Laravel",
55
"main": "src/resources/laraberg.js",
66
"directories": {

public/css/laraberg.css

Lines changed: 2350 additions & 1920 deletions
Large diffs are not rendered by default.

public/css/laraberg.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/laraberg.js

Lines changed: 11 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/laraberg.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Helpers/EmbedHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class EmbedHelper
1515
public static function renderEmbeds($html)
1616
{
1717
// Match URL from raw Gutenberg embed content
18-
$regex = '/<!-- wp:core-embed\/.*?-->\s*?<figure class="wp-block-embed.*?".*?<div class="wp-block-embed__wrapper">\s*?(.*?)\s*?<\/div><\/figure>/';
18+
$regex = '/<!-- wp:core-embed\/.*?-->\s*?<figure class="wp-block-embed.*?".*?<div class="wp-block-embed__wrapper">\s*?(.*?)\s*?<\/div>.*?<\/figure>/';
1919
$result = preg_replace_callback($regex, function ($matches) {
2020
$embed = self::create($matches[1]);
2121
$url = preg_replace('/\//', '\/', preg_quote($matches[1]));

src/Models/Content.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ public function render()
5252
*/
5353
public function setContent($html)
5454
{
55-
$this->raw_content = $html;
56-
$this->fixEmptyImages();
55+
$this->raw_content = $this->fixEmptyImages($html);
5756
$this->renderRaw();
5857
}
5958

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

6968
return $this->rendered_content;
7069
}
71-
70+
7271
/**
7372
* TODO: Remove this temporary fix for Image block crashing when no image is selected
7473
*/
75-
private function fixEmptyImages() {
74+
private function fixEmptyImages($html) {
7675
$regex = '/<img(.*)\/>/';
77-
$this->raw_content = preg_replace_callback($regex, function ($matches) {
76+
return preg_replace_callback($regex, function ($matches) {
7877
if (isset($matches[1]) && strpos($matches[1], 'src="') === false) {
7978
return str_replace('<img ', '<img src="/vendor/laraberg/img/placeholder.jpg" ', $matches[0]);
8079
}
8180
return $matches[0];
82-
}, $this->raw_content);
81+
}, $html);
8382
}
8483
}

src/resources/js/gutenberg/init.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ export default function init (target, options = {}) {
1919
toggleFeature('fullscreenMode')
2020

2121
// Disable block patterns
22-
plugins.unregisterPlugin('edit-post');
22+
plugins.unregisterPlugin('edit-post')
2323

2424
window._wpLoadGutenbergEditor = new Promise(function (resolve) {
2525
domReady(async () => {
2626
const larabergEditor = createEditorElement(target)
2727
try {
28-
resolve(editPost.initializeEditor(larabergEditor.id, 'page', 1, editorSettings, overridePost))
28+
resolve(editPost.initializeEditor(larabergEditor.id, 'page', 1, getEditorSettings(), overridePost))
2929
fixReusableBlocks()
3030
} catch (error) {
3131
console.error(error)
@@ -65,3 +65,13 @@ function fixReusableBlocks () {
6565
}
6666
registerBlockType('core/block', coreBlock)
6767
}
68+
69+
function getEditorSettings() {
70+
const targetElement = document.getElementById(editorSettings.target)
71+
72+
if (targetElement && targetElement.placeholder) {
73+
editorSettings.bodyPlaceholder = targetElement.placeholder
74+
}
75+
76+
return editorSettings
77+
}

src/resources/js/gutenberg/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const editorSettings = {
4848
postLock: {
4949
isLocked: false
5050
},
51-
autosaveInterval: 9999,
51+
autosaveInterval: 9999
5252
}
5353

5454
// Post properties to override

src/resources/js/lib/configure-editor.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ function setupSubmit (target) {
127127
if (textarea.form) {
128128
textarea.form.addEventListener('submit', event => {
129129
textarea.value = data.select('core/editor').getEditedPostContent()
130-
// Clear content "dirty" state.
131-
data.dispatch('core/editor').savePost()
132130
return true
133131
})
134132
}
@@ -156,6 +154,4 @@ function removeElements () {
156154
elementRendered('.editor-post-trash', element => { element.remove() })
157155

158156
elementRendered('.editor-post-saved-state', element => { element.style.display = 'none' })
159-
160-
elementRendered('.components-popover__content div .components-menu-group:last-of-type', element => { element.style.display = 'none' })
161157
}

src/resources/js/lib/content.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as MockData from '../api/mock-data'
33
const { data } = window.wp
44

55
export function getContent () {
6-
data.dispatch('core/editor').savePost()
76
return data.select('core/editor').getEditedPostContent()
87
}
98

0 commit comments

Comments
 (0)