Skip to content

Commit de409ee

Browse files
authored
Merge pull request #78 from a8cteam51/fix/76-stretchy-text-block-not-resizing
Stretchy-type: Fix front-end view
2 parents 621498f + 8a07591 commit de409ee

9 files changed

Lines changed: 65 additions & 57 deletions

File tree

stretchy-type/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.2 (2025-08-02)
2+
3+
- Fixed front-end class not applying.
4+
15
## 0.1.1 (2025-08-02)
26

37
### Added

stretchy-type/classes/class-wpsp-blocks-self-update.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static function get_instance() {
3131
* Initialize WordPress hooks
3232
*/
3333
public function hooks() {
34-
add_filter( 'update_plugins_opsoasis-develop.mystagingwebsite.com', array( $this, 'self_update' ), 10, 3 );
34+
add_filter( 'update_plugins_opsoasis.wpspecialprojects.com', array( $this, 'self_update' ), 10, 3 );
3535
}
3636

3737
/**
@@ -53,7 +53,7 @@ public function self_update( $update, array $plugin_data, string $plugin_file )
5353

5454
// Ask opsoasis.mystagingwebsite.com if there's an update.
5555
$response = wp_remote_get(
56-
'https://opsoasis-develop.mystagingwebsite.com/wp-json/opsoasis-blocks-version-manager/v1/update-check',
56+
'https://opsoasis.wpspecialprojects.com/wp-json/opsoasis-blocks-version-manager/v1/update-check',
5757
array(
5858
'body' => array(
5959
'plugin' => $plugin_filename_parts[0],
@@ -77,4 +77,4 @@ public function self_update( $update, array $plugin_data, string $plugin_file )
7777
'package' => $updated_array['package_url'],
7878
);
7979
}
80-
}
80+
}

stretchy-type/package-lock.json

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

stretchy-type/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stretchy-type",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "A block that expands to fill the width of its container.",
55
"author": "Studio 51",
66
"license": "GPL-2.0-or-later",

stretchy-type/src/block.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
"$schema": "https://schemas.wp.org/trunk/block.json",
33
"apiVersion": 3,
44
"name": "wpsp/stretchy-type",
5-
"version": "0.1.1",
5+
"version": "0.1.2",
66
"title": "Stretchy Type",
77
"category": "theme",
88
"icon": "text",
99
"description": "Text that expands to fill the width of its container.",
10-
"example": {},
1110
"textdomain": "stretchy-type",
1211
"attributes": {
1312
"content": {
@@ -22,6 +21,5 @@
2221
"editorScript": "file:./index.js",
2322
"style": "file:./style-index.css",
2423
"editorStyle": "file:./style-index.css",
25-
"viewScript": "file:./view.js",
26-
"render": "file:./render.php"
24+
"viewScript": "file:./view.js"
2725
}

stretchy-type/src/edit.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
import { RichText, useBlockProps } from "@wordpress/block-editor";
2-
import { useRef, useEffect } from "@wordpress/element";
1+
import { RichText, useBlockProps } from '@wordpress/block-editor';
2+
import { useRef, useEffect } from '@wordpress/element';
33

4-
export default function Edit({ attributes, setAttributes }) {
4+
export default function Edit( { attributes, setAttributes } ) {
55
const { content, viewBox } = attributes;
6-
const blockProps = useBlockProps(viewBox ? { viewBox } : {});
6+
const blockProps = useBlockProps( viewBox ? { viewBox } : {} );
77
const wrapperRef = useRef();
88
const richTextRef = useRef();
99

10-
useEffect(() => {
11-
const observer = new window.ResizeObserver(() => {
10+
useEffect( () => {
11+
const observer = new window.ResizeObserver( () => {
1212
const { offsetWidth, offsetHeight } = wrapperRef.current;
13-
setAttributes({
14-
viewBox: `0 0 ${offsetWidth} ${offsetHeight}`,
15-
});
13+
setAttributes( {
14+
viewBox: `0 0 ${ offsetWidth } ${ offsetHeight }`,
15+
} );
1616
// This hack is required to prevent RichText to overwrite `white-space`.
17-
if (richTextRef.current) {
18-
richTextRef.current.style.whiteSpace = "nowrap";
17+
if ( richTextRef.current ) {
18+
richTextRef.current.style.whiteSpace = 'nowrap';
1919
}
20-
});
21-
observer.observe(wrapperRef.current);
20+
} );
21+
observer.observe( wrapperRef.current );
2222

2323
return () => {
2424
observer.disconnect();
2525
};
26-
}, []);
26+
}, [] );
2727

28-
const onChange = (nextContent) => {
29-
setAttributes({ content: nextContent });
28+
const onChange = ( nextContent ) => {
29+
setAttributes( { content: nextContent } );
3030
};
3131

3232
return (
33-
<svg {...blockProps}>
33+
<svg { ...blockProps }>
3434
<foreignObject x="0" y="0" width="100%" height="100%">
35-
<span ref={wrapperRef}>
35+
<span ref={ wrapperRef }>
3636
<RichText
3737
disableLineBreaks
3838
tagName="span"
3939
identifier="content"
4040
placeholder="Stretchy text goes here"
4141
preserveWhiteSpace
42-
value={content}
43-
onChange={onChange}
44-
ref={richTextRef}
42+
value={ content }
43+
onChange={ onChange }
44+
ref={ richTextRef }
4545
/>
4646
</span>
4747
</foreignObject>

stretchy-type/src/index.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import {
22
createBlock,
33
getBlockType,
44
registerBlockType,
5-
} from "@wordpress/blocks";
6-
import { subscribe } from "@wordpress/data";
7-
import "./style.scss";
8-
import Edit from "./edit";
9-
import save from "./save";
10-
import metadata from "./block.json";
5+
} from '@wordpress/blocks';
6+
import { subscribe } from '@wordpress/data';
7+
import './style.scss';
8+
import Edit from './edit';
9+
import save from './save';
10+
import metadata from './block.json';
1111

1212
// Subscribe is needed to wait for the core/paragraph block to be registered.
13-
const unsubscribe = subscribe(() => {
14-
const paragraphBlockType = getBlockType("core/paragraph");
15-
if (paragraphBlockType) {
13+
const unsubscribe = subscribe( () => {
14+
const paragraphBlockType = getBlockType( 'core/paragraph' );
15+
if ( paragraphBlockType ) {
1616
unsubscribe();
17-
registerBlockType(metadata.name, {
17+
registerBlockType( metadata.name, {
1818
edit: Edit,
1919
save,
2020
supports: {
@@ -27,27 +27,27 @@ const unsubscribe = subscribe(() => {
2727
transforms: {
2828
from: [
2929
{
30-
type: "block",
31-
blocks: ["core/paragraph", "core/heading"],
32-
transform: ({ content }) => {
33-
return createBlock(metadata.name, {
30+
type: 'block',
31+
blocks: [ 'core/paragraph', 'core/heading' ],
32+
transform: ( { content } ) => {
33+
return createBlock( metadata.name, {
3434
content,
35-
});
35+
} );
3636
},
3737
},
3838
],
3939
to: [
4040
{
41-
type: "block",
42-
blocks: ["core/paragraph"],
43-
transform: ({ content }) => {
44-
return createBlock("core/paragraph", {
41+
type: 'block',
42+
blocks: [ 'core/paragraph' ],
43+
transform: ( { content } ) => {
44+
return createBlock( 'core/paragraph', {
4545
content,
46-
});
46+
} );
4747
},
4848
},
4949
],
5050
},
51-
});
51+
} );
5252
}
53-
});
53+
} );

stretchy-type/src/save.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ import { RichText, useBlockProps } from '@wordpress/block-editor';
1919
*/
2020
export default function save( { attributes } ) {
2121
const { content, viewBox } = attributes;
22-
const blockProps = useBlockProps.save( viewBox ? { viewBox } : {} );
22+
const blockProps = useBlockProps.save( {
23+
viewBox: viewBox ? viewBox : null,
24+
className: 'wp-block-wpsp-stretchy-type',
25+
} );
26+
2327
return (
2428
<svg { ...blockProps }>
2529
<foreignObject x="0" y="0" width="100%" height="100%">

stretchy-type/stretchy-type.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
* Description: A block that expands to fill the width of its container.
55
* Requires at least: 6.1
66
* Requires PHP: 7.0
7-
* Version: 0.1.1
7+
* Version: 0.1.2
88
* Author: Studio 51
99
* Author URI: https://wpspecialprojects.wordpress.com/
1010
* Update URI: https://opsoasis.wpspecialprojects.com/stretchy-type/
1111
* License: GPL-2.0-or-later
1212
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
1313
* Text Domain: stretchy-type
14+
* Update URI: https://opsoasis.wpspecialprojects.com/
1415
*
1516
* @package Wpsp
1617
*/

0 commit comments

Comments
 (0)