From 46c3655b4773ebe0d2b57834ca3d089fa65ce0b4 Mon Sep 17 00:00:00 2001 From: Michael Auteri Date: Sat, 31 Dec 2022 14:42:08 -0500 Subject: [PATCH 1/7] Update core-blocks.md with preview as attribute for HTML Block. --- docs/reference-guides/core-blocks.md | 2 +- packages/block-library/src/html/block.json | 4 ++++ packages/block-library/src/html/edit.js | 13 ++++++------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index 25fe5746a04122..c8d82ff827f0bd 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -303,7 +303,7 @@ Add custom HTML code and preview it as you edit. ([Source](https://github.com/Wo - **Name:** core/html - **Category:** widgets - **Supports:** ~~className~~, ~~customClassName~~, ~~html~~ -- **Attributes:** content +- **Attributes:** content, preview ## Image diff --git a/packages/block-library/src/html/block.json b/packages/block-library/src/html/block.json index c1e1e94b87496b..e64b0565f091ae 100644 --- a/packages/block-library/src/html/block.json +++ b/packages/block-library/src/html/block.json @@ -11,6 +11,10 @@ "content": { "type": "string", "source": "raw" + }, + "preview": { + "type": "boolean", + "default": false } }, "supports": { diff --git a/packages/block-library/src/html/edit.js b/packages/block-library/src/html/edit.js index 5cb2b457633b13..0f0f3aeed5dad7 100644 --- a/packages/block-library/src/html/edit.js +++ b/packages/block-library/src/html/edit.js @@ -2,7 +2,7 @@ * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { useContext, useState } from '@wordpress/element'; +import { useContext } from '@wordpress/element'; import { BlockControls, PlainText, @@ -16,15 +16,14 @@ import { ToolbarButton, Disabled, ToolbarGroup } from '@wordpress/components'; import Preview from './preview'; export default function HTMLEdit( { attributes, setAttributes, isSelected } ) { - const [ isPreview, setIsPreview ] = useState(); const isDisabled = useContext( Disabled.Context ); function switchToPreview() { - setIsPreview( true ); + setAttributes( { preview: true } ); } function switchToHTML() { - setIsPreview( false ); + setAttributes( { preview: false } ); } return ( @@ -33,21 +32,21 @@ export default function HTMLEdit( { attributes, setAttributes, isSelected } ) { HTML { __( 'Preview' ) } - { isPreview || isDisabled ? ( + { attributes.preview || isDisabled ? ( Date: Sat, 31 Dec 2022 15:07:18 -0500 Subject: [PATCH 2/7] Update unit test. --- test/integration/fixtures/blocks/core__html.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/integration/fixtures/blocks/core__html.json b/test/integration/fixtures/blocks/core__html.json index faa0024b94df43..6028692a1e8bbd 100644 --- a/test/integration/fixtures/blocks/core__html.json +++ b/test/integration/fixtures/blocks/core__html.json @@ -3,7 +3,8 @@ "name": "core/html", "isValid": true, "attributes": { - "content": "

Some HTML code

\n
This is a div
" + "content": "

Some HTML code

\n
This is a div
", + "preview": false }, "innerBlocks": [] } From 5f7540603d00716c07c88325580fdf552cfe7487 Mon Sep 17 00:00:00 2001 From: Michael Auteri Date: Fri, 6 Jan 2023 13:33:57 -0500 Subject: [PATCH 3/7] Change preview to isPreview; Small cleanup. --- docs/reference-guides/core-blocks.md | 2 +- packages/block-library/src/html/block.json | 2 +- packages/block-library/src/html/edit.js | 20 ++++++------------- .../fixtures/blocks/core__html.json | 2 +- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index c8d82ff827f0bd..418edfd19a21e8 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -303,7 +303,7 @@ Add custom HTML code and preview it as you edit. ([Source](https://github.com/Wo - **Name:** core/html - **Category:** widgets - **Supports:** ~~className~~, ~~customClassName~~, ~~html~~ -- **Attributes:** content, preview +- **Attributes:** content, isPreview ## Image diff --git a/packages/block-library/src/html/block.json b/packages/block-library/src/html/block.json index e64b0565f091ae..37a0a1ae9173d8 100644 --- a/packages/block-library/src/html/block.json +++ b/packages/block-library/src/html/block.json @@ -12,7 +12,7 @@ "type": "string", "source": "raw" }, - "preview": { + "isPreview": { "type": "boolean", "default": false } diff --git a/packages/block-library/src/html/edit.js b/packages/block-library/src/html/edit.js index 0f0f3aeed5dad7..527b557f277d25 100644 --- a/packages/block-library/src/html/edit.js +++ b/packages/block-library/src/html/edit.js @@ -18,35 +18,27 @@ import Preview from './preview'; export default function HTMLEdit( { attributes, setAttributes, isSelected } ) { const isDisabled = useContext( Disabled.Context ); - function switchToPreview() { - setAttributes( { preview: true } ); - } - - function switchToHTML() { - setAttributes( { preview: false } ); - } - return (
setAttributes( { isPreview: false } ) } > - HTML + { __( 'HTML' ) } setAttributes( { isPreview: true } ) } > { __( 'Preview' ) } - { attributes.preview || isDisabled ? ( + { attributes.isPreview || isDisabled ? ( Some HTML code\n
This is a div
", - "preview": false + "isPreview": false }, "innerBlocks": [] } From d1aff8816d4973426c27ba01cd0b129cf578628b Mon Sep 17 00:00:00 2001 From: Mike Auteri Date: Sun, 11 Feb 2024 17:25:35 -0500 Subject: [PATCH 4/7] This file should not have changed. --- packages/edit-site/lib/unbrotli.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/edit-site/lib/unbrotli.js b/packages/edit-site/lib/unbrotli.js index 54eb9930737d57..a56c85cbec4846 100644 --- a/packages/edit-site/lib/unbrotli.js +++ b/packages/edit-site/lib/unbrotli.js @@ -336,7 +336,7 @@ 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, - 3, 2, 3, 2, 3 /* CONTEXT_UTF8 second last byte. */, + 3, 2, 3, 2, 3, /* CONTEXT_UTF8 second last byte. */ /* ASCII range. */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, @@ -353,7 +353,7 @@ 0, 0, 0, 0 /* UTF8 lead byte range. */, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2 /* CONTEXT_SIGNED, second last byte. */, + 2, 2, 2, 2, 2, /* CONTEXT_SIGNED, second last byte. */ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, From 0788829b6be116c7d7962ab0f6d75b28a1f5c5ba Mon Sep 17 00:00:00 2001 From: Mike Auteri Date: Sun, 11 Feb 2024 23:09:52 -0500 Subject: [PATCH 5/7] Remove extra line break. --- packages/block-library/src/html/editor.scss | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/block-library/src/html/editor.scss b/packages/block-library/src/html/editor.scss index bd8426c91012c4..13ca8c91dfde38 100644 --- a/packages/block-library/src/html/editor.scss +++ b/packages/block-library/src/html/editor.scss @@ -6,7 +6,6 @@ top: 0; left: 0; - &:hover { background: rgba(var(--wp-block-synced-color--rgb), 0.04); box-shadow: 0 0 0 1px var(--wp-block-synced-color) inset; From bf269b96313232131993b0882ee973f3a7803db2 Mon Sep 17 00:00:00 2001 From: Mike Auteri Date: Mon, 6 May 2024 09:47:22 -0400 Subject: [PATCH 6/7] Removed hover CSS; removed Disabled per Alex Stine. --- packages/block-library/src/html/edit.js | 5 +---- packages/block-library/src/html/editor.scss | 5 ----- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/block-library/src/html/edit.js b/packages/block-library/src/html/edit.js index edfd2fb843876f..31391811c8312f 100644 --- a/packages/block-library/src/html/edit.js +++ b/packages/block-library/src/html/edit.js @@ -2,7 +2,6 @@ * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { useContext } from '@wordpress/element'; import { BlockControls, PlainText, @@ -10,7 +9,6 @@ import { } from '@wordpress/block-editor'; import { ToolbarButton, - Disabled, ToolbarGroup, VisuallyHidden, } from '@wordpress/components'; @@ -22,7 +20,6 @@ import { useInstanceId } from '@wordpress/compose'; import Preview from './preview'; export default function HTMLEdit( { attributes, setAttributes, isSelected } ) { - const isDisabled = useContext( Disabled.Context ); const instanceId = useInstanceId( HTMLEdit, 'html-edit-desc' ); const blockProps = useBlockProps( { className: 'block-library-html__edit', @@ -47,7 +44,7 @@ export default function HTMLEdit( { attributes, setAttributes, isSelected } ) { - { attributes.isPreview || isDisabled ? ( + { attributes.isPreview ? ( <> Date: Tue, 7 May 2024 08:58:44 -0400 Subject: [PATCH 7/7] Revert package.json in attempt to fix commit issue. --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7bcd9df66991e4..ff76bff3cf07d2 100644 --- a/package.json +++ b/package.json @@ -375,7 +375,8 @@ "npm run docs:api-ref", "npm run docs:blocks", "npm run docs:theme-ref", - "node ./bin/api-docs/are-api-docs-unstaged.js" + "node ./bin/api-docs/are-api-docs-unstaged.js", + "node ./bin/packages/lint-staged-typecheck.js" ], "**/tsconfig.json": [ "npm run lint:tsconfig"