Changes to directory structure

This commit is contained in:
Jeremy Rangel
2024-12-18 02:27:09 -08:00
parent d5a5f4e87b
commit 94d2c7c8a2
135 changed files with 335 additions and 5435 deletions

View File

@ -0,0 +1,18 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
[*.{yml,yaml}]
indent_style = space
indent_size = 2

View File

@ -0,0 +1,30 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Coverage directory used by tools like istanbul
coverage
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Output of `npm pack`
*.tgz
# Output of `wp-scripts plugin-zip`
*.zip
# dotenv environment variables file
.env

View File

@ -0,0 +1,131 @@
<?php /**
* Function to generate random class and add dynamic padding styles
*/
function render_lcp_container( $attributes, $content ) {
// Debugging: Check the passed attributes
//var_dump($attributes);
// Generate a random class name (optional, could be customized)
$random_class = 'lcp-container-' . wp_generate_password( 12, false, false );
// Get the padding and backgroundColor attributes
$padding = isset( $attributes['padding'] ) ? $attributes['padding'] : array();
$background_color = isset( $attributes['backgroundColor'] ) ? $attributes['backgroundColor'] : '#ffffff'; // Default color
// Debugging: Check padding and background color
error_log(print_r($padding, true));
error_log(print_r($background_color, true));
// Check if all padding values are the same across all sizes
$same_padding = true;
$padding_top = $padding['extraLarge']['top'];
$padding_right = $padding['extraLarge']['right'];
$padding_bottom = $padding['extraLarge']['bottom'];
$padding_left = $padding['extraLarge']['left'];
// Compare the padding for all other sizes (large, medium, small)
foreach ( ['large', 'medium', 'small'] as $size ) {
if (
$padding[$size]['top'] !== $padding_top ||
$padding[$size]['right'] !== $padding_right ||
$padding[$size]['bottom'] !== $padding_bottom ||
$padding[$size]['left'] !== $padding_left
) {
$same_padding = false;
break;
}
}
// Prepare the inline style or media queries
$style = '';
// Add background-color to the inline style
$style .= sprintf( 'background-color: %s;', esc_attr( $background_color ) );
if ( $same_padding ) {
// If all padding values are the same, use inline style
$style .= sprintf(
'padding-top: %s; padding-right: %s; padding-bottom: %s; padding-left: %s;',
esc_attr( $padding_top ),
esc_attr( $padding_right ),
esc_attr( $padding_bottom ),
esc_attr( $padding_left )
);
} else {
// If padding is different, generate media queries for different sizes
$style .= sprintf(
'@media (min-width: 1200px) { .%s { padding-top: %s; padding-right: %s; padding-bottom: %s; padding-left: %s; } }',
esc_attr( $random_class ),
esc_attr( $padding['extraLarge']['top'] ),
esc_attr( $padding['extraLarge']['right'] ),
esc_attr( $padding['extraLarge']['bottom'] ),
esc_attr( $padding['extraLarge']['left'] )
);
$style .= sprintf(
'@media (min-width: 1024px) { .%s { padding-top: %s; padding-right: %s; padding-bottom: %s; padding-left: %s; } }',
esc_attr( $random_class ),
esc_attr( $padding['large']['top'] ),
esc_attr( $padding['large']['right'] ),
esc_attr( $padding['large']['bottom'] ),
esc_attr( $padding['large']['left'] )
);
$style .= sprintf(
'@media (min-width: 768px) { .%s { padding-top: %s; padding-right: %s; padding-bottom: %s; padding-left: %s; } }',
esc_attr( $random_class ),
esc_attr( $padding['medium']['top'] ),
esc_attr( $padding['medium']['right'] ),
esc_attr( $padding['medium']['bottom'] ),
esc_attr( $padding['medium']['left'] )
);
$style .= sprintf(
'@media (max-width: 767px) { .%s { padding-top: %s; padding-right: %s; padding-bottom: %s; padding-left: %s; } }',
esc_attr( $random_class ),
esc_attr( $padding['small']['top'] ),
esc_attr( $padding['small']['right'] ),
esc_attr( $padding['small']['bottom'] ),
esc_attr( $padding['small']['left'] )
);
}
// Generate the <style> tag with the final CSS (either inline or media queries)
$style_tag = '';
if ( ! empty( $style ) ) {
$style_tag = sprintf( '<style>.%s { %s }</style>', esc_attr( $random_class ), $style );
}
// Output the content wrapped in the div with the random class and padding styles
return $style_tag . sprintf(
'<div class="lcp-container %s">%s</div>',
esc_attr( $random_class ),
$content
);
}
/**
* Function to return the media query breakpoint based on the size
*/
function get_media_query_breakpoint( $size ) {
// Define breakpoints for each size
$breakpoints = array(
'extraLarge' => '1200px',
'large' => '1024px',
'medium' => '768px',
'small' => '480px',
);
return isset( $breakpoints[$size] ) ? $breakpoints[$size] : '480px';
}
/**
* Function to initialize the block
*/
function lcp_dynamic_container_block_init() {
register_block_type( __DIR__ . '/build', array(
'render_callback' => 'render_lcp_dynamic_container', // Add the render callback here
));
}
add_action( 'init', 'lcp_dynamic_container_block_init' );

View File

@ -0,0 +1,20 @@
{
"name": "lcp-viewport",
"version": "0.1.0",
"description": "Example block scaffolded with Create Block tool.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
"main": "build/index.js",
"scripts": {
"build": "wp-scripts build",
"format": "wp-scripts format",
"lint:css": "wp-scripts lint-style",
"lint:js": "wp-scripts lint-js",
"packages-update": "wp-scripts packages-update",
"plugin-zip": "wp-scripts plugin-zip",
"start": "wp-scripts start"
},
"devDependencies": {
"@wordpress/scripts": "^30.4.0"
}
}

View File

@ -0,0 +1,55 @@
=== Lcp Viewport ===
Contributors: The WordPress Contributors
Tags: block
Tested up to: 6.6
Stable tag: 0.1.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Example block scaffolded with Create Block tool.
== Description ==
This is the long description. No limit, and you can use Markdown (as well as in the following sections).
For backwards compatibility, if this section is missing, the full length of the short description will be used, and
Markdown parsed.
== Installation ==
This section describes how to install the plugin and get it working.
e.g.
1. Upload the plugin files to the `/wp-content/plugins/lcp-viewport` directory, or install the plugin through the WordPress plugins screen directly.
1. Activate the plugin through the 'Plugins' screen in WordPress
== Frequently Asked Questions ==
= A question that someone might have =
An answer to that question.
= What about foo bar? =
Answer to foo bar dilemma.
== Screenshots ==
1. This screen shot description corresponds to screenshot-1.(png|jpg|jpeg|gif). Note that the screenshot is taken from
the /assets directory or the directory that contains the stable readme.txt (tags or trunk). Screenshots in the /assets
directory take precedence. For example, `/assets/screenshot-1.png` would win over `/tags/4.3/screenshot-1.png`
(or jpg, jpeg, gif).
2. This is the second screen shot
== Changelog ==
= 0.1.0 =
* Release
== Arbitrary section ==
You may provide arbitrary sections, in the same format as the ones above. This may be of use for extremely complicated
plugins where more information needs to be conveyed that doesn't fit into the categories of "description" or
"installation." Arbitrary sections will be shown below the built-in sections outlined above.

View File

@ -0,0 +1,136 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "lcp/dynamic-container",
"version": "0.1.0",
"title": "Dynamic Container",
"category": "widgets",
"icon": "smiley",
"description": "A general purpose container that uses dynamic rendering",
"example": {},
"supports": {
"anchor": true,
"align": [ "left", "right", "wide", "full" ],
"background": {
"backgroundImage": true,
"backgroundSize": true,
"__experimentalDefaultControls": {
"backgroundImage": true
}
},
"color": {
"gradients": true,
"background": true,
"link": true,
"__experimentalDefaultControls": {
"background": true,
"text": true
}
}
},
"attributes": {
"maxWidthExtraLarge": {
"type": "string"
},
"maxWidthLarge": {
"type": "string"
},
"maxWidthMedium": {
"type": "string"
},
"maxWidthSmall": {
"type": "string"
},
"minHeightExtraLarge": {
"type": "string"
},
"minHeightLarge": {
"type": "string"
},
"minHeightMedium": {
"type": "string"
},
"minHeightSmall": {
"type": "string"
},
"isBox": {
"type": "boolean",
"default": false
},
"backgroundColor": {
"type": "string"
},
"entranceAnimation": {
"type": "string"
},
"exitAnimation": {
"type": "string"
},
"overflow": {
"type": "string"
},
"padding": {
"type": "object",
"default": {
"extraLarge": {
"top": "0",
"right": "0",
"bottom": "0",
"left": "0"
},
"large": {
"top": "0",
"right": "0",
"bottom": "0",
"left": "0"
},
"medium": {
"top": "0",
"right": "0",
"bottom": "0",
"left": "0"
},
"small": {
"top": "0",
"right": "0",
"bottom": "0",
"left": "0"
}
}
},
"margin": {
"type": "object",
"default": {
"extraLarge": {
"top": "12px",
"right": "0",
"bottom": "12px",
"left": "0"
},
"large": {
"top": "12px",
"right": "0",
"bottom": "12px",
"left": "0"
},
"medium": {
"top": "12px",
"right": "0",
"bottom": "12px",
"left": "0"
},
"small": {
"top": "12px",
"right": "0",
"bottom": "12px",
"left": "0"
}
}
}
},
"textdomain": "lcp",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css",
"viewScript": "file:./view.js"}

View File

@ -0,0 +1,211 @@
import { useBlockProps, InnerBlocks, InspectorControls } from '@wordpress/block-editor';
import { __experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption, __experimentalUnitControl as UnitControl, BaseControl, ToggleControl, ColorPalette, Popover, Button } from '@wordpress/components';
import { useState, useEffect } from 'react';
import { __ } from '@wordpress/i18n';
/**
* The edit function describes the structure of your block in the context of the editor.
* This represents what the editor will render when the block is used.
*
* @param {Object} props - The props for the block.
* @return {Element} Element to render.
*/
export default function Edit({ attributes, setAttributes }) {
const blockProps = useBlockProps();
const { padding, maxWidthLarge, maxWidthMedium, maxWidthSmall, minHeightLarge, minHeightMedium, minHeightSmall, backgroundColor } = attributes; // Destructure necessary attributes
// State for independent padding toggle
const [isIndependentLarge, setIsIndependentLarge] = useState(false);
// Toggle to show or hide the color picker popover
const [showColorPopover, setShowColorPopover] = useState(false);
const [selectedColor, setSelectedColor] = useState(backgroundColor || '#ffffff'); // Default color
// Toggle padding for individual sizes
const handleToggleChange = () => {
setIsIndependentLarge(!isIndependentLarge);
};
// Update padding for all sizes
const updatePaddingForAllSizes = (newValue) => {
const newPadding = {
extraLarge: { top: newValue, right: newValue, bottom: newValue, left: newValue },
large: { top: newValue, right: newValue, bottom: newValue, left: newValue },
medium: { top: newValue, right: newValue, bottom: newValue, left: newValue },
small: { top: newValue, right: newValue, bottom: newValue, left: newValue }
};
setAttributes({ padding: newPadding });
};
// Handle individual padding changes
const handlePaddingChange = (size, position, newValue) => {
const updatedPadding = { ...padding };
updatedPadding[size][position] = newValue;
setAttributes({ padding: updatedPadding });
};
// Handle color change
const handleColorChange = (color) => {
setSelectedColor(color);
setAttributes({ backgroundColor: color }); // Update background color
};
// Handle maxWidth change for different sizes
const handleMaxWidthChange = (value, size) => {
setAttributes({ [`maxWidth${size}`]: value });
};
// Handle minHeight change for different sizes
const handleMinHeightChange = (value, size) => {
setAttributes({ [`minHeight${size}`]: value });
};
useEffect(() => {
console.log("Updated attributes:", attributes);
}, [attributes]);
return (
<>
<InspectorControls>
<ToggleGroupControl
label="my label"
value="vertical"
isBlock
__nextHasNoMarginBottom
__next40pxDefaultSize
>
<ToggleGroupControlOption value="horizontal" label="Horizontal" />
<ToggleGroupControlOption value="vertical" label="Vertical" />
</ToggleGroupControl>
{/* BaseControl for padding */}
<BaseControl label="Padding - Desktop">
<div style={{ display: 'flex', flexDirection: 'row' }}>
<span style={{ marginRight: '10px' }}>Padding</span>
<ToggleControl
label="Use Independent Padding"
checked={isIndependentLarge}
onChange={handleToggleChange}
/>
</div>
{/* Padding controls */}
{isIndependentLarge ? (
<div style={{ display: 'grid', padding: '10px', gridTemplateColumns: '1fr 1fr', gap: '10px', justifyItems: 'center' }}>
{/* Padding controls for top, left, right, bottom */}
<fieldset style={{ gridColumn: 'span 2', width: '116px' }}>
<legend>Top</legend>
<UnitControl
value={padding.extraLarge?.top || '10px'}
onChange={(newValue) => handlePaddingChange('extraLarge', 'top', newValue)}
/>
</fieldset>
<fieldset>
<legend>Left</legend>
<UnitControl
value={padding.extraLarge?.left || '10px'}
onChange={(newValue) => handlePaddingChange('extraLarge', 'left', newValue)}
/>
</fieldset>
<fieldset>
<legend>Right</legend>
<UnitControl
value={padding.extraLarge?.right || '10px'}
onChange={(newValue) => handlePaddingChange('extraLarge', 'right', newValue)}
/>
</fieldset>
<fieldset style={{ gridColumn: 'span 2', width: '116px' }}>
<legend>Bottom</legend>
<UnitControl
value={padding.extraLarge?.bottom || '10px'}
onChange={(newValue) => handlePaddingChange('extraLarge', 'bottom', newValue)}
/>
</fieldset>
</div>
) : (
<UnitControl
label="Padding Value"
value={999} // You can replace this with an attribute value
onChange={updatePaddingForAllSizes}
/>
)}
</BaseControl>
{/* Max Width Controls */}
<BaseControl label="Max Width">
<div style={{ display: 'flex', flexDirection: 'column' }}>
<UnitControl
label="Large"
value={maxWidthLarge}
onChange={(value) => handleMaxWidthChange(value, 'Large')}
defaultUnit="px"
/>
<UnitControl
label="Medium"
value={maxWidthMedium}
onChange={(value) => handleMaxWidthChange(value, 'Medium')}
defaultUnit="px"
/>
<UnitControl
label="Small"
value={maxWidthSmall}
onChange={(value) => handleMaxWidthChange(value, 'Small')}
defaultUnit="px"
/>
</div>
</BaseControl>
{/* Min Height Controls */}
<BaseControl label="Min Height">
<div style={{ display: 'flex', flexDirection: 'column' }}>
<UnitControl
label="Large"
value={minHeightLarge}
onChange={(value) => handleMinHeightChange(value, 'Large')}
defaultUnit="px"
/>
<UnitControl
label="Medium"
value={minHeightMedium}
onChange={(value) => handleMinHeightChange(value, 'Medium')}
defaultUnit="px"
/>
<UnitControl
label="Small"
value={minHeightSmall}
onChange={(value) => handleMinHeightChange(value, 'Small')}
defaultUnit="px"
/>
</div>
</BaseControl>
{/* Background color picker */}
<BaseControl label={__('Background Color')}>
<div>
<Button onClick={() => setShowColorPopover(!showColorPopover)}>
{__('Choose Background Color')}
</Button>
{showColorPopover && (
<Popover position="bottom center">
<ColorPalette
value={selectedColor}
onChange={handleColorChange}
colors={[{ name: "Primary", slug: "primary", color: "#3E5062" }, { name: "Secondary", slug: "secondary", color: "#2B3843" }, { name: "Light Color - 1", slug: "light-color-1", color: "#ECF0F5" }, { name: "Dark Gray", slug: "dark-gray", color: "#333333" }, { name: "Accent", slug: "accent", color: "#61FFB6" }]}
disableCustomColors={false}
/>
</Popover>
)}
{/* Color indicator */}
<div style={{ backgroundColor: selectedColor, width: '30px', height: '30px', marginTop: '10px', borderRadius: '50%' }}></div>
</div>
</BaseControl>
</InspectorControls>
<div {...blockProps} style={{ maxWidth: maxWidthLarge, minHeight: minHeightLarge }}>
<InnerBlocks />
</div>
</>
);
}

View File

@ -0,0 +1,9 @@
/**
* The following styles get applied inside the editor only.
*
* Replace them with your own styles or remove the file completely.
*/
.wp-block-create-block-lcp-viewport {
border: 1px dotted #f00;
}

View File

@ -0,0 +1,39 @@
/**
* Registers a new block provided a unique name and an object defining its behavior.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
import { registerBlockType } from '@wordpress/blocks';
/**
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
* All files containing `style` keyword are bundled together. The code used
* gets applied both to the front of your site and to the editor.
*
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
*/
import './style.scss';
/**
* Internal dependencies
*/
import Edit from './edit';
import save from './save';
import metadata from './block.json';
/**
* Every block starts by registering a new block type definition.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
registerBlockType( metadata.name, {
/**
* @see ./edit.js
*/
edit: Edit,
/**
* @see ./save.js
*/
save,
} );

View File

@ -0,0 +1,12 @@
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor';
export default function Save() {
// Block props
const blockProps = useBlockProps.save();
return (
<div {...blockProps}>
<InnerBlocks.Content />
</div>
);
}

View File

@ -0,0 +1,12 @@
/**
* The following styles get applied both on the front of your site
* and in the editor.
*
* Replace them with your own styles or remove the file completely.
*/
.wp-block-create-block-lcp-viewport {
background-color: #21759b;
color: #fff;
padding: 2px;
}

View File

@ -0,0 +1,25 @@
/**
* Use this file for JavaScript code that you want to run in the front-end
* on posts/pages that contain this block.
*
* When this file is defined as the value of the `viewScript` property
* in `block.json` it will be enqueued on the front end of the site.
*
* Example:
*
* ```js
* {
* "viewScript": "file:./view.js"
* }
* ```
*
* If you're not making any changes to this file because your project doesn't need any
* JavaScript running in the front-end, then you should delete this file and remove
* the `viewScript` property from `block.json`.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#view-script
*/
/* eslint-disable no-console */
console.log( 'Hello World! (from create-block-lcp-viewport block)' );
/* eslint-enable no-console */