21 Commits

Author SHA1 Message Date
roman a22a179eff Added nested blocks support (inner_blocks). ACF Only. 2025-05-12 17:28:39 -06:00
roman 95e0cae3ed Merge with latest. 2025-05-11 17:29:57 -06:00
roman 92e4f1ea2d version upgrade 2025-03-29 20:27:56 -06:00
roman 0062bb4506 1.0.33 2025-03-29 20:21:32 -06:00
roman 5dd326be0f Pass $args parameter to content hook. 2025-03-29 20:20:51 -06:00
roman 00efc1677d 1.0.33 2024-12-08 18:44:15 -07:00
roman 38c49a64ad Make sure all images are updated on Global Blocks. 2024-12-08 18:43:39 -07:00
roman 044f721d34 Updated logic of mobile/tablet sizes & scrollbars. 2024-06-23 20:24:57 -06:00
roman 74f4b11ad6 Updated logic of mobile/tablet sizes & scrollbars. 2024-06-23 20:21:44 -06:00
roman 1b2cf2697f Updated logic of mobile/tablet sizes & scrollbars. 2024-06-23 20:18:16 -06:00
roman bcad45d1e8 Temporary disabled ngrok (share live URL option) 2024-06-23 01:26:14 -06:00
roman 3daa725309 Updated logic of Elementor's build. Support Elementor_Widget Trait. 2024-05-24 15:34:12 -06:00
roman 438619c4d9 Added axeweb-block classNames to blocks in Elementor 2024-05-21 12:50:58 -06:00
roman 1b2795fa40 Merge pull request 'Update path to static files of ACF block.' (#13) from wordpress-build into master
Reviewed-on: #13
2024-05-21 09:44:13 +00:00
roman 31786581bd Update path to static files of ACF block. 2024-05-21 03:38:18 -06:00
roman e25f1aa4f1 Merge pull request '1.0.32' (#12) from wordpress-build into master
Reviewed-on: #12
2024-05-21 09:05:32 +00:00
roman f3cd0e5876 1.0.32 2024-05-21 03:03:24 -06:00
roman d6b0ff866b Merge pull request 'Updated the bundle of WordPress block.' (#11) from wordpress-build into master
Reviewed-on: #11
2024-05-21 09:02:22 +00:00
roman 4a7ddf7d29 Updated the bundle of WordPress block. 2024-05-21 03:01:46 -06:00
roman 03a8833f46 Merge pull request 'fix windows archive issue' (#10) from dev into master
Reviewed-on: #10
2024-04-15 12:20:32 +00:00
roman bf8f0e857d fix windows archive issue 2024-04-15 00:07:18 +03:00
17 changed files with 97 additions and 236 deletions
-9
View File
@@ -9,17 +9,8 @@ const {isDev, developmentBlockName} = getConfigs();
const blockName = !isDev && config.has('blockName') ? config.get('blockName') : developmentBlockName;
export const PLATFORM_OPTIONS = [{
name: 'wordpress-acf-block',
title: 'WordPress AFC Block'
}, {
name: 'wordpress',
title: 'WordPress'
}, {
name: 'wordpress-component-manager',
title: 'WordPress (Component Manager)'
}, {
name: 'wordpress-elementor',
title: 'WordPress Elementor'
}, {
name: 'hubspot',
title: 'Hubspot'
+18 -31
View File
@@ -126,46 +126,33 @@ export function capitalize(str) {
export async function zipProject(srcDir, outputFileName = 'dist.zip') {
// create a file to stream archive data to.
const output = await fsExtra.createWriteStream(outputFileName);
const archive = archiver('zip', {});
// listen for all archive data to be written
// 'close' event is fired only when a file descriptor is involved
output.on('close', function () {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
return new Promise((resolve, reject) => {
// Create a file to write the archive data
const archive = archiver('zip', {
zlib: {level: 9} // Compression level
});
// This event is fired when the data source is drained no matter what was the data source.
// It is not part of this library but rather from the NodeJS Stream API.
// @see: https://nodejs.org/api/stream.html#stream_event_end
output.on('end', function () {
console.log('Data has been drained');
});
// good practice to catch warnings (ie stat failures and other non-blocking errors)
archive.on('warning', function (err) {
if (err.code === 'ENOENT') {
// log warning
} else {
// throw error
throw err;
}
});
// good practice to catch this error explicitly
// Listen for errors on the archiver
archive.on('error', function (err) {
throw err;
reject(err);
});
// pipe archive data to the file
// Handle closure of the output file stream
output.on('close', function () {
console.log(`Archive created successfully and it is ${archive.pointer()} total bytes`);
resolve();
});
// Pipe archive data to the file
archive.pipe(output);
// append files from a subdirectory, putting its contents at the root of archive
// Add files to the archive
archive.directory(srcDir, false);
// finalize the archive (ie we are done appending files but streams have to finish yet)
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
await archive.finalize();
// Finalize the archive - this is very important to ensure the file stream is finished
archive.finalize();
});
}
export async function buildExportFiles(blockName, platform) {
@@ -261,7 +248,7 @@ export async function isFileEmpty(filePath, ignoreComments = false) {
export function replaceNames(content, images, uploadedImages) {
images.forEach((image, index) => {
content = content.replace(image, uploadedImages[index].fileName);
content = content.replaceAll(image, uploadedImages[index].fileName);
});
return content;
+1 -1
View File
@@ -1 +1 @@
let e;window.initBlock=function(e="",n="",r){t=function(){document.querySelectorAll(n).forEach((e=>r(e)))},t()};let t,n={};function r(r={}){r.template&&(e=r.template),r.data&&(n=r.data),e&&function(e,n,r){const a=Handlebars.compile(e);let o;Handlebars.registerHelper("esc_attr",(function(e){return e})),Handlebars.registerHelper("esc_url",(function(e){return e})),Handlebars.registerHelper("esc_html",(function(e){return e})),Handlebars.registerHelper("base_url",(function(){return"/"}));try{o=a(n)}catch(e){o=`<div style="max-width: 1280px; margin: 1rem auto;">\n <h1 style="all: unset; font-size: 1.5rem; font-weight: bold; display: block;">Syntax Error:</h1>\n <pre style="all: unset; padding: 10px 15px; background-color: #ffe6e6; border: 1px solid red; border-radius: 0.25rem; overflow: auto; display: block; white-space: pre;">${e.toString()}</pre>\n </div>`}r.innerHTML=o,t&&t()}(e,n||{},document.getElementById("hbs-container"))}!function(){function e(){const e=new URLSearchParams(window.location.search),t={};for(const[n,r]of e)t[n]=r;return t}!function(){const t=new URLSearchParams({name:e().data||"default"});fetch(`/data?${t}`).then((e=>e.json())).then((e=>{n=e.data,r({data:n})}))}(),window.addEventListener("message",(function(e){const t=e.data,a="dataUpdate:";if("string"==typeof t&&t.startsWith(a))try{n=JSON.parse(t.substring(a.length)),r({data:n})}catch(e){console.log("Error parsing incoming data.",e)}}))}(),function(){const e=window.io.connect();e.on("error",(function(e){console.log(e)})),e.on("templateUpdate",(function(e){r({template:e.template})}))}();
let e;window.initBlock=function(e="",n="",r){t=function(){document.querySelectorAll(n).forEach((e=>r(e)))},t()};let t,n={};function r(r={}){r.template&&(e=r.template),r.data&&(n=r.data),e&&function(e,n,r){const a=Handlebars.compile(e);let o;Handlebars.registerHelper("esc_attr",(function(e){return e})),Handlebars.registerHelper("esc_url",(function(e){return e})),Handlebars.registerHelper("esc_html",(function(e){return e})),Handlebars.registerHelper("base_url",(function(){return"/"})),Handlebars.registerHelper("inner_blocks",(function(e){const t=e.data.root.inner_blocks;return t?new Handlebars.SafeString(t):""}));try{o=a(n)}catch(e){o=`<div style="max-width: 1280px; margin: 1rem auto;">\n <h1 style="all: unset; font-size: 1.5rem; font-weight: bold; display: block;">Syntax Error:</h1>\n <pre style="all: unset; padding: 10px 15px; background-color: #ffe6e6; border: 1px solid red; border-radius: 0.25rem; overflow: auto; display: block; white-space: pre;">${e.toString()}</pre>\n </div>`}r.innerHTML=o,t&&t()}(e,n||{},document.getElementById("hbs-container"))}!function(){function e(){const e=new URLSearchParams(window.location.search),t={};for(const[n,r]of e)t[n]=r;return t}!function(){const t=new URLSearchParams({name:e().data||"default"});fetch(`/data?${t}`).then((e=>e.json())).then((e=>{n=e.data,r({data:n})}))}(),window.addEventListener("message",(function(e){const t=e.data,a="dataUpdate:";if("string"==typeof t&&t.startsWith(a))try{n=JSON.parse(t.substring(a.length)),r({data:n})}catch(e){console.log("Error parsing incoming data.",e)}}))}(),function(){const e=window.io.connect();e.on("error",(function(e){console.log(e)})),e.on("templateUpdate",(function(e){r({template:e.template})}))}();
+2 -2
View File
File diff suppressed because one or more lines are too long
+9
View File
@@ -119,6 +119,15 @@ function renderBlock(templateHbs, jsonData, target) {
return '/';
});
Handlebars.registerHelper('inner_blocks', function (options) {
const content = options.data.root['inner_blocks'];
if (!content) {
return '';
}
return new Handlebars.SafeString(content);
});
let html;
try {
@@ -130,7 +130,8 @@ export function DesignPreview({previewOption = {widthDimension: 0}}) {
return 0;
}
const scrollbarOffset = 7;
// const scrollbarOffset = 7; // Looks like browser scrollbar is not included in the width calculation anymore.
const scrollbarOffset = 0;
return window.innerWidth / 2 - previewOption.widthDimension / 2 - scrollbarOffset;
}
+2 -1
View File
@@ -65,7 +65,8 @@ function Responsive(props = {}) {
function updateController() {
let frameBreakpoint = breakpoint;
if (typeof frameBreakpoint !== 'string') {
const scrollbarWidth = 15;
// const scrollbarWidth = 15; // Looks like browser's logic was changed and now scrollbar is not included in the width.
const scrollbarWidth = 0;
frameBreakpoint = (scrollbarWidth + frameBreakpoint) + 'px';
}
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "@axe-web/block-dev-tool",
"version": "1.0.31",
"version": "1.0.36",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@axe-web/block-dev-tool",
"version": "1.0.31",
"version": "1.0.36",
"license": "ISC",
"dependencies": {
"@axe-web/create-block": "^1.1.30",
+4 -4
View File
@@ -1,15 +1,15 @@
{
"name": "@axe-web/block-dev-tool",
"version": "1.0.31",
"version": "1.0.36",
"author": {
"name": "AXE-WEB",
"email": "office@axe-web.com",
"url": "https://axe-web.com/"
},
"scripts": {
"info": "BLOCK_NAME=swiper-test MODULE_PATH= node debug.js",
"dev": "BLOCK_NAME=swiper-test MODULE_PATH= node server.js",
"build-platform": "BLOCK_NAME=swiper-test MODULE_PATH= node ./build.js",
"info": "BLOCK_NAME=ebooks-resources MODULE_PATH= node debug.js",
"dev": "BLOCK_NAME=ebooks-resources MODULE_PATH= node server.js",
"build-platform": "BLOCK_NAME=ebooks-resources MODULE_PATH= node ./build.js",
"dev-dev-tool": "rollup --config rollup.config.js --watch",
"build-dev-tool": "rollup --config rollup.config.js"
},
+2 -8
View File
@@ -35,14 +35,6 @@ trait Custom_Handlebars {
return $context;
} );
$this->add_handlebar( 'safe_html', function ( $context ) {
if ( function_exists( 'wp_kses_post' ) ) {
return wp_kses_post( $context );
}
return $context;
} );
}
public function add_handlebar( $key, $func ): void {
@@ -91,6 +83,8 @@ class Component_Builder {
private function get_handlebars_template( $path = '' ): string {
$template = file_get_contents( $path );
$template = preg_replace( '/{{inner_blocks}}/', '<InnerBlocks/>', $template );
$phpStr = LightnCandy::compile( $template,
[
'flags' => Flags::FLAG_NOESCAPE | Flags::FLAG_PARENT | Flags::FLAG_SPVARS | Flags::FLAG_ELSE | Flags::FLAG_JSLENGTH | Flags::FLAG_JSTRUE | Flags::FLAG_THIS,
@@ -2,19 +2,13 @@
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>;
class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor) { %>extends \Core\Component <% } %>{
class <%= blockClassModel %>_Component extends \Core\Component {
const VERSION = '<%= version %>';
public $block_project = '<%= ownerFilename %>';
public $block_name = '<%= blockFilename %>';
public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>';
<% if (!isComponentManager && !isElementor) { %>public function __construct() {
parent::__construct();
// add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] );
add_action( 'after_setup_theme', [ $this, 'register_assets' ] );
}
<% } %>function register_assets(): void {
function register_assets(): void {
$base_path = plugin_dir_url( __FILE__ ); // In Plugins
// $base_path = get_template_directory_uri() . '/components/partials/<%= blockFilename %>/'; // In Theme
@@ -22,12 +16,14 @@ class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor)
wp_register_style( 'block-<%= blockFilename %>', $base_path . 'templates/styles/<%= blockFilename %>.min.css', $style_deps, self::VERSION );
$script_deps = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::script_deps', [ 'assets-script' ] );
wp_register_script( 'block-<%= blockFilename %>', $base_path . 'templates/scripts/<%= blockFilename %>.min.js', $script_deps, self::VERSION, true );<% if (!isElementor) { %>
wp_register_script( 'block-<%= blockFilename %>', $base_path . 'templates/scripts/<%= blockFilename %>.min.js', $script_deps, self::VERSION, true );
}
public function prepare_for_print() {
if ( ! is_admin() ) {
wp_enqueue_style( 'block-<%= blockFilename %>' );
wp_enqueue_script( 'block-<%= blockFilename %>' );
}<% } %>
}
}
public function get_content( $args = [] ): string {
@@ -37,8 +33,8 @@ class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor)
$output = ( include( __DIR__ . '/templates/<%= blockFilename %>.template.php' ) )( $args, self::class );
return apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::content', $output );
}<% if (isElementor) { %>
return apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::content', $output, $args );
}
function register_custom_logic(): void {
add_action( 'elementor/widgets/widgets_registered', [ $this, 'register_elementor_widget' ] );
@@ -47,9 +43,25 @@ class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor)
function register_elementor_widget( $widgets_manager ): void {
require_once "helpers/<%= blockClassModel %>_Elementor_Widget.php";
$widgets_manager->register_widget_type( new Helpers\<%= blockClassModel %>_Elementor_Widget() );
}<% } %>
}
function register_acf_block() {
$this->register_block( __DIR__ . "/<%= blockFilename %>.block.json", [
'style_assets' => [
[
'name' => 'block-<%= blockFilename %>',
'url' => $this->get_assets_path_url( 'templates/styles/<%= blockFilename %>.min.css' ),
]
],
'script_assets' => [
[
'name' => 'block-<%= blockFilename %>',
'url' => $this->get_assets_path_url( 'templates/scripts/<%= blockFilename %>.min.js' ),
]
]
] );
}
}
<% if (isComponentManager) { %><%= blockClassModel %>_Component::get_instance();<% } else {
%>new <%= blockClassModel %>_Component();<% } %>
<%= blockClassModel %>_Component::get_instance();
// new <%= blockClassModel %>_Component();
@@ -1,62 +0,0 @@
<?php
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>;
class <%= blockClassModel %>_Component extends \Core\Component {
const VERSION = '<%= version %>';
public $block_project = '<%= ownerFilename %>';
public $block_name = '<%= blockFilename %>';
public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>';
public function get_content( $args = [] ): string {
$default_args = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::default_args', [] ); // Not really practical.
$args = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::prepare_args', array_merge( $default_args, $args ) );
$output = ( include( __DIR__ . '/templates/<%= blockFilename %>.template.php' ) )( $args, self::class );
return apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::content', $output );
}
<% if (!include_acf_block && !include_native_gutenberg_block) { %>function register_assets(): void {
$version = get_plugin_data( __DIR__ . "/../../scytale-custom-blocks.php" )['Version']; // In Plugins
// $version = \Core\Global_Functions::get_current_version_number(); // In Theme
// $base_path = get_template_directory_uri() . '/components/partials/<%= blockFilename %>/';
wp_enqueue_style( 'block-<%= blockFilename %>', $this->get_assets_path_url( 'templates/styles/<%= blockFilename %>.min.css' ), ['assets-style'], self::VERSION );<% if (include_script) { %>
wp_enqueue_script( 'block-<%= blockFilename %>', $this->get_assets_path_url( 'templates/scripts/<%= blockFilename %>.min.js' ), ['assets-script'], self::VERSION, true );<% } %>
wp_enqueue_script( 'script-block-<%= blockFilename %>' );
}<% } %>
<% if (include_acf_block) { %> function register_acf_block() {
$this->register_block( __DIR__ . "/<%= blockFilename %>.block.json", [
'style_assets' => [
[
'name' => '<%= blockFilename %>',
'url' => $this->get_assets_path_url( 'templates/styles/<%= blockFilename %>.min.css' ),
]
],
'script_assets' => [
[
'name' => '<%= blockFilename %>',
'url' => $this->get_assets_path_url( 'templates/scripts/<%= blockFilename %>.min.js' ),
]
]
] );
}
<% } %><% if (include_native_gutenberg_block) { %> function register_native_gutenberg_block() {
register_block_type( __DIR__ . '/templates/gutenberg-block/block.json' );<% if (include_script) { %>
add_action( 'wp_enqueue_scripts', function () {
$asset_file_front = include( plugin_dir_path( __FILE__ ) . '/templates/gutenberg-block/build/front.asset.php' );
wp_enqueue_script(
'gutenberg-<%= blockFilename %>-scripts-front',
$this->get_assets_path_url( 'templates/gutenberg-block/build/front.js' ),
$asset_file_front['dependencies'],
$asset_file_front['version'],
true
);
} );<% } %>
}<% } %>
}
<%= blockClassModel %>_Component::get_instance();
@@ -1,14 +0,0 @@
<?php
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\Helpers;
class <%= blockClassModel %>_API {
static function prepare_args( $args = [] ) {
// $args = array_merge( [], $args );
return $args;
}
}
@@ -1,17 +0,0 @@
<?php
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\Helpers;
/**
* Component's default args.
*/
class <%= blockClassModel %>_Defaults {
public static function default_args(): array {
$args = <%- defaultData %>;
// $args['base_url'] = \Core\Global_Functions::get_file_url( __DIR__ . '/../templates/' );
return $args;
}
}
@@ -3,6 +3,8 @@
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\Helpers;
class <%= blockClassModel %>_Elementor_Widget extends \Elementor\Widget_Base {
use \Core\Traits\Elementor_Widget;
const PLUGIN_NAME = '<%= blockFilename %>';
public function get_name() {
@@ -35,12 +37,8 @@ class <%= blockClassModel %>_Elementor_Widget extends \Elementor\Widget_Base {
$component = new \AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\<%= blockClassModel %>_Component();
$args = self::prepare( $settings );
$args = $this->prepare( $settings );
$component->render( $args );
}
public static function prepare( $args ): array {
// Prepare $args for render function.
return $args;
}
}
-37
View File
@@ -10,10 +10,6 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export async function buildWordPress(blockName, args = {}) {
const isBlock = args.platform === 'wordpress-acf-block';
const isElementor = args.platform === 'wordpress-elementor';
const isComponentManager = args.platform === 'wordpress-component-manager'
const {modulesPath, projectPath} = getConfigs();
const distPath = path.join(projectPath, 'exports', args.platform);
@@ -37,12 +33,7 @@ export async function buildWordPress(blockName, args = {}) {
ownerClass: owner.replace(/ /ig, '_'),
ownerFilename: owner.toLowerCase().replace(/ /ig, '-'),
templateFormat: 'php',
include_acf_block: isBlock,
include_native_gutenberg_block: false,
include_script: true,
include_elementor_widget: isElementor,
isElementor,
isComponentManager,
});
await copyFile(blockFilePath, path.join(distPath, data.blockFilename + '.block.json'));
@@ -84,15 +75,6 @@ export async function buildWordPress(blockName, args = {}) {
json: await readJSONFile(path.join(projectPath, 'data', 'default.json'), "utf8"),
});
// await createFiles(Object.assign({}, data, {defaultData: phpDataObject}), [{
// from: `templates/helpers/Template_Defaults.php`,
// to: `helpers/${data.blockClassModel}_Defaults.php`,
// }], {
// pathDist: distPath,
// generatorsPath: path.join(__dirname),
// });
if (isElementor) {
await createFiles(data, [{
from: `templates/helpers/Template_Elementor_Widget.php`,
to: `helpers/${data.blockClassModel}_Elementor_Widget.php`,
@@ -100,25 +82,7 @@ export async function buildWordPress(blockName, args = {}) {
pathDist: distPath,
generatorsPath: path.join(__dirname)
});
}
if (isBlock) {
await createFiles(data, [{
from: `templates/Template_Component.php`,
to: `${data.blockClassModel}_Component.php`,
}], {
pathDist: distPath,
generatorsPath: path.join(__dirname)
});
// await createFiles(data, [{
// from: `templates/helpers/Template_API.php`,
// to: `helpers/${data.blockClassModel}_API.php`,
// }], {
// pathDist: distPath,
// generatorsPath: path.join(__dirname)
// });
} else {
await createFiles(data, [{
from: `templates/Template_Basic_Component.php`,
to: `${data.blockClassModel}_Component.php`,
@@ -126,7 +90,6 @@ export async function buildWordPress(blockName, args = {}) {
pathDist: distPath,
generatorsPath: path.join(__dirname)
});
}
}
export function execCommand(cmd = '') {
+3 -5
View File
@@ -38,7 +38,7 @@ import {
import PluginError from 'plugin-error';
import {Server} from "socket.io";
import {createServer} from 'http';
import {authtoken, connect} from "ngrok";
// import {authtoken, connect} from "ngrok";
import bodyParser from "body-parser";
/**
@@ -89,8 +89,6 @@ const hbs = create({
}, esc_html(html) {
// TODO: Check if we can remove this helper.
return html;
}, safe_html(html) {
return sanitizeHtml(html);
}
}
});
@@ -569,8 +567,8 @@ async function getShareableUrl() {
let url;
try {
await authtoken(data.ngrokApiToken);
url = await connect(port);
// await authtoken(data.ngrokApiToken);
// url = await connect(port);
} catch (e) {
console.log('Error:', `Can't connect to ngrok, probably wrong token.`);
}