From 34593a3af39a1c226d6b50ac0fd821a3e346a085 Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Thu, 3 Aug 2023 21:41:53 +0900 Subject: [PATCH 1/8] List Block: Fix numbering style to be applied correctly --- packages/block-library/src/editor.scss | 1 + packages/block-library/src/list/edit.js | 10 +++++++++- packages/block-library/src/list/editor.scss | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 packages/block-library/src/list/editor.scss diff --git a/packages/block-library/src/editor.scss b/packages/block-library/src/editor.scss index 07c58599c50980..20b7035a304616 100644 --- a/packages/block-library/src/editor.scss +++ b/packages/block-library/src/editor.scss @@ -20,6 +20,7 @@ @import "./gallery/editor.scss"; @import "./group/editor.scss"; @import "./html/editor.scss"; +@import "./list/editor.scss"; @import "./image/editor.scss"; @import "./latest-posts/editor.scss"; @import "./media-text/editor.scss"; diff --git a/packages/block-library/src/list/edit.js b/packages/block-library/src/list/edit.js index 7c8c15e05fe875..97ffc0a141953e 100644 --- a/packages/block-library/src/list/edit.js +++ b/packages/block-library/src/list/edit.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + /** * WordPress dependencies */ @@ -124,8 +129,12 @@ function IndentUI( { clientId } ) { } export default function Edit( { attributes, setAttributes, clientId, style } ) { + const { ordered, type, reversed, start } = attributes; const blockProps = useBlockProps( { ...( Platform.isNative && { style } ), + className: classnames( { + [ `is-type-${ type }` ]: type && type !== '1', + } ), } ); const innerBlocksProps = useInnerBlocksProps( blockProps, { allowedBlocks: [ 'core/list-item' ], @@ -139,7 +148,6 @@ export default function Edit( { attributes, setAttributes, clientId, style } ) { } ), } ); useMigrateOnLoad( attributes, clientId ); - const { ordered, type, reversed, start } = attributes; const controls = ( diff --git a/packages/block-library/src/list/editor.scss b/packages/block-library/src/list/editor.scss new file mode 100644 index 00000000000000..bf9173749e1ae4 --- /dev/null +++ b/packages/block-library/src/list/editor.scss @@ -0,0 +1,18 @@ +ol { + // Override WP Admin reset style applied when the editor is not an iframe. + &.is-type-A { + list-style-type: upper-alpha; + } + + &.is-type-a { + list-style-type: lower-alpha; + } + + &.is-type-I { + list-style-type: upper-roman; + } + + &.is-type-i { + list-style-type: lower-roman; + } +} From 974ef4e2f1d614b99fc3edde40953aeea7431fa2 Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Sat, 5 Aug 2023 11:39:56 +0900 Subject: [PATCH 2/8] Use inline style instead of type attributes --- packages/block-library/src/editor.scss | 1 - packages/block-library/src/list/block.json | 3 ++- packages/block-library/src/list/edit.js | 15 +++++---------- packages/block-library/src/list/editor.scss | 18 ------------------ .../src/list/ordered-list-settings.js | 16 +++++++++++----- packages/block-library/src/list/save.js | 11 ++++++++++- 6 files changed, 28 insertions(+), 36 deletions(-) delete mode 100644 packages/block-library/src/list/editor.scss diff --git a/packages/block-library/src/editor.scss b/packages/block-library/src/editor.scss index 20b7035a304616..07c58599c50980 100644 --- a/packages/block-library/src/editor.scss +++ b/packages/block-library/src/editor.scss @@ -20,7 +20,6 @@ @import "./gallery/editor.scss"; @import "./group/editor.scss"; @import "./html/editor.scss"; -@import "./list/editor.scss"; @import "./image/editor.scss"; @import "./latest-posts/editor.scss"; @import "./media-text/editor.scss"; diff --git a/packages/block-library/src/list/block.json b/packages/block-library/src/list/block.json index 9c4c1ef4f27848..b96ea94af5f846 100644 --- a/packages/block-library/src/list/block.json +++ b/packages/block-library/src/list/block.json @@ -23,7 +23,8 @@ "__experimentalRole": "content" }, "type": { - "type": "string" + "type": "string", + "default": "decimal" }, "start": { "type": "number" diff --git a/packages/block-library/src/list/edit.js b/packages/block-library/src/list/edit.js index 97ffc0a141953e..ee8f4b560cb7f0 100644 --- a/packages/block-library/src/list/edit.js +++ b/packages/block-library/src/list/edit.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import classnames from 'classnames'; - /** * WordPress dependencies */ @@ -131,11 +126,12 @@ function IndentUI( { clientId } ) { export default function Edit( { attributes, setAttributes, clientId, style } ) { const { ordered, type, reversed, start } = attributes; const blockProps = useBlockProps( { - ...( Platform.isNative && { style } ), - className: classnames( { - [ `is-type-${ type }` ]: type && type !== '1', - } ), + style: { + ...( Platform.isNative && style ), + listStyleType: ordered && type !== 'decimal' ? type : undefined, + }, } ); + const innerBlocksProps = useInnerBlocksProps( blockProps, { allowedBlocks: [ 'core/list-item' ], template: TEMPLATE, @@ -179,7 +175,6 @@ export default function Edit( { attributes, setAttributes, clientId, style } ) { ordered={ ordered } reversed={ reversed } start={ start } - type={ type } { ...innerBlocksProps } /> { controls } diff --git a/packages/block-library/src/list/editor.scss b/packages/block-library/src/list/editor.scss deleted file mode 100644 index bf9173749e1ae4..00000000000000 --- a/packages/block-library/src/list/editor.scss +++ /dev/null @@ -1,18 +0,0 @@ -ol { - // Override WP Admin reset style applied when the editor is not an iframe. - &.is-type-A { - list-style-type: upper-alpha; - } - - &.is-type-a { - list-style-type: lower-alpha; - } - - &.is-type-I { - list-style-type: upper-roman; - } - - &.is-type-i { - list-style-type: lower-roman; - } -} diff --git a/packages/block-library/src/list/ordered-list-settings.js b/packages/block-library/src/list/ordered-list-settings.js index 60e7e33d0ad51f..2f0df726c8cde7 100644 --- a/packages/block-library/src/list/ordered-list-settings.js +++ b/packages/block-library/src/list/ordered-list-settings.js @@ -33,11 +33,17 @@ const OrderedListSettings = ( { setAttributes, reversed, start, type } ) => ( __nextHasNoMarginBottom label={ __( 'Numbering style' ) } options={ [ - { value: '1', label: __( 'Numbers' ) }, - { value: 'A', label: __( 'Uppercase letters' ) }, - { value: 'a', label: __( 'Lowercase letters' ) }, - { value: 'I', label: __( 'Uppercase Roman numerals' ) }, - { value: 'i', label: __( 'Lowercase Roman numerals' ) }, + { value: 'decimal', label: __( 'Numbers' ) }, + { value: 'upper-alpha', label: __( 'Uppercase letters' ) }, + { value: 'lower-alpha', label: __( 'Lowercase letters' ) }, + { + value: 'upper-roman', + label: __( 'Uppercase Roman numerals' ), + }, + { + value: 'lower-roman', + label: __( 'Lowercase Roman numerals' ), + }, ] } value={ type } onChange={ ( newValue ) => setAttributes( { type: newValue } ) } diff --git a/packages/block-library/src/list/save.js b/packages/block-library/src/list/save.js index c74893f38b67b2..d090f0faf4e883 100644 --- a/packages/block-library/src/list/save.js +++ b/packages/block-library/src/list/save.js @@ -7,7 +7,16 @@ export default function save( { attributes } ) { const { ordered, type, reversed, start } = attributes; const TagName = ordered ? 'ol' : 'ul'; return ( - + ); From 8e2c68add1a9a682d9e766a0258c1314b57f298a Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Sat, 5 Aug 2023 11:51:32 +0900 Subject: [PATCH 3/8] Add deprecation --- packages/block-library/src/list/deprecated.js | 87 ++++++++++++++++++- packages/block-library/src/list/utils.js | 20 +++++ 2 files changed, 104 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/list/deprecated.js b/packages/block-library/src/list/deprecated.js index cfd7e3039cee87..5888ad078a3116 100644 --- a/packages/block-library/src/list/deprecated.js +++ b/packages/block-library/src/list/deprecated.js @@ -1,13 +1,13 @@ /** * WordPress dependencies */ -import { RichText, useBlockProps } from '@wordpress/block-editor'; +import { RichText, InnerBlocks, useBlockProps } from '@wordpress/block-editor'; /** * Internal dependencies */ import migrateFontFamily from '../utils/migrate-font-family'; -import { migrateToListV2 } from './utils'; +import { migrateToListV2, migrateTypeToInlineStyle } from './utils'; const v0 = { attributes: { @@ -138,6 +138,87 @@ const v1 = { migrate: migrateToListV2, }; +// In #53301 changed to use the inline style instead of type attribute. +const v2 = { + attributes: { + ordered: { + type: 'boolean', + default: false, + __experimentalRole: 'content', + }, + values: { + type: 'string', + source: 'html', + selector: 'ol,ul', + multiline: 'li', + __unstableMultilineWrapperTags: [ 'ol', 'ul' ], + default: '', + __experimentalRole: 'content', + }, + type: { + type: 'string', + }, + start: { + type: 'number', + }, + reversed: { + type: 'boolean', + }, + placeholder: { + type: 'string', + }, + }, + supports: { + anchor: true, + className: false, + typography: { + fontSize: true, + lineHeight: true, + __experimentalFontFamily: true, + __experimentalFontWeight: true, + __experimentalFontStyle: true, + __experimentalTextTransform: true, + __experimentalTextDecoration: true, + __experimentalLetterSpacing: true, + __experimentalDefaultControls: { + fontSize: true, + }, + }, + color: { + gradients: true, + link: true, + __experimentalDefaultControls: { + background: true, + text: true, + }, + }, + spacing: { + margin: true, + padding: true, + __experimentalDefaultControls: { + margin: false, + padding: false, + }, + }, + __unstablePasteTextInline: true, + __experimentalSelector: 'ol,ul', + __experimentalSlashInserter: true, + }, + isEligible( { type } ) { + return type && type !== '1'; + }, + save( { attributes } ) { + const { ordered, type, reversed, start } = attributes; + const TagName = ordered ? 'ol' : 'ul'; + return ( + + + + ); + }, + migrate: migrateTypeToInlineStyle, +}; + /** * New deprecations need to be placed first * for them to have higher priority. @@ -146,4 +227,4 @@ const v1 = { * * See block-deprecation.md */ -export default [ v1, v0 ]; +export default [ v2, v1, v0 ]; diff --git a/packages/block-library/src/list/utils.js b/packages/block-library/src/list/utils.js index 4fa2a0e0aed949..e4a8815d483dd6 100644 --- a/packages/block-library/src/list/utils.js +++ b/packages/block-library/src/list/utils.js @@ -78,3 +78,23 @@ export function migrateToListV2( attributes ) { listBlock.innerBlocks, ]; } + +export function migrateTypeToInlineStyle( attributes ) { + const typeStyles = { + A: 'upper-alpha', + a: 'lower-alpha', + I: 'upper-roman', + i: 'lower-roman', + }; + + const { type } = attributes; + + if ( typeStyles[ type ] ) { + return { + ...attributes, + type: typeStyles[ type ], + }; + } + + return attributes; +} From 5be90bcb12ba5227e621ea5a62bca9d4e9445b79 Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Sat, 5 Aug 2023 20:31:19 +0900 Subject: [PATCH 4/8] Try to fix unit test --- packages/block-library/src/list/block.json | 3 +-- packages/block-library/src/list/deprecated.js | 2 +- .../core__list__deprecated-v1-nested.json | 15 ++++++++----- .../blocks/core__list__deprecated-v1.json | 3 ++- .../blocks/core__list__ol-with-type.html | 7 ------- .../blocks/core__list__ol-with-type.json | 21 ------------------- .../core__list__ol-with-type.parsed.json | 20 ------------------ .../core__list__ol-with-type.serialized.html | 5 ----- .../fixtures/blocks/core__list__ul.json | 3 ++- 9 files changed, 16 insertions(+), 63 deletions(-) delete mode 100644 test/integration/fixtures/blocks/core__list__ol-with-type.html delete mode 100644 test/integration/fixtures/blocks/core__list__ol-with-type.json delete mode 100644 test/integration/fixtures/blocks/core__list__ol-with-type.parsed.json delete mode 100644 test/integration/fixtures/blocks/core__list__ol-with-type.serialized.html diff --git a/packages/block-library/src/list/block.json b/packages/block-library/src/list/block.json index b96ea94af5f846..9c4c1ef4f27848 100644 --- a/packages/block-library/src/list/block.json +++ b/packages/block-library/src/list/block.json @@ -23,8 +23,7 @@ "__experimentalRole": "content" }, "type": { - "type": "string", - "default": "decimal" + "type": "string" }, "start": { "type": "number" diff --git a/packages/block-library/src/list/deprecated.js b/packages/block-library/src/list/deprecated.js index 5888ad078a3116..cecc17430f65e5 100644 --- a/packages/block-library/src/list/deprecated.js +++ b/packages/block-library/src/list/deprecated.js @@ -205,7 +205,7 @@ const v2 = { __experimentalSlashInserter: true, }, isEligible( { type } ) { - return type && type !== '1'; + return !! type; }, save( { attributes } ) { const { ordered, type, reversed, start } = attributes; diff --git a/test/integration/fixtures/blocks/core__list__deprecated-v1-nested.json b/test/integration/fixtures/blocks/core__list__deprecated-v1-nested.json index 0e5c001e4e0367..8b01b23e87904d 100644 --- a/test/integration/fixtures/blocks/core__list__deprecated-v1-nested.json +++ b/test/integration/fixtures/blocks/core__list__deprecated-v1-nested.json @@ -4,7 +4,8 @@ "isValid": true, "attributes": { "ordered": false, - "values": "" + "values": "", + "type": "decimal" }, "innerBlocks": [ { @@ -19,7 +20,8 @@ "isValid": true, "attributes": { "ordered": false, - "values": "" + "values": "", + "type": "decimal" }, "innerBlocks": [ { @@ -34,7 +36,8 @@ "isValid": true, "attributes": { "ordered": false, - "values": "" + "values": "", + "type": "decimal" }, "innerBlocks": [ { @@ -61,7 +64,8 @@ "isValid": true, "attributes": { "ordered": false, - "values": "" + "values": "", + "type": "decimal" }, "innerBlocks": [ { @@ -88,7 +92,8 @@ "isValid": true, "attributes": { "ordered": false, - "values": "" + "values": "", + "type": "decimal" }, "innerBlocks": [ { diff --git a/test/integration/fixtures/blocks/core__list__deprecated-v1.json b/test/integration/fixtures/blocks/core__list__deprecated-v1.json index 80cd87e4eb69e8..d65a959f7aaa01 100644 --- a/test/integration/fixtures/blocks/core__list__deprecated-v1.json +++ b/test/integration/fixtures/blocks/core__list__deprecated-v1.json @@ -4,7 +4,8 @@ "isValid": true, "attributes": { "ordered": false, - "values": "" + "values": "", + "type": "decimal" }, "innerBlocks": [ { diff --git a/test/integration/fixtures/blocks/core__list__ol-with-type.html b/test/integration/fixtures/blocks/core__list__ol-with-type.html deleted file mode 100644 index 9969965e5a56ce..00000000000000 --- a/test/integration/fixtures/blocks/core__list__ol-with-type.html +++ /dev/null @@ -1,7 +0,0 @@ - -
    - -
  1. Item 1
  2. - -
- diff --git a/test/integration/fixtures/blocks/core__list__ol-with-type.json b/test/integration/fixtures/blocks/core__list__ol-with-type.json deleted file mode 100644 index a15b1546b0ed4c..00000000000000 --- a/test/integration/fixtures/blocks/core__list__ol-with-type.json +++ /dev/null @@ -1,21 +0,0 @@ -[ - { - "name": "core/list", - "isValid": true, - "attributes": { - "ordered": true, - "values": "", - "type": "A" - }, - "innerBlocks": [ - { - "name": "core/list-item", - "isValid": true, - "attributes": { - "content": "Item 1" - }, - "innerBlocks": [] - } - ] - } -] diff --git a/test/integration/fixtures/blocks/core__list__ol-with-type.parsed.json b/test/integration/fixtures/blocks/core__list__ol-with-type.parsed.json deleted file mode 100644 index 7ddda9e08da5ab..00000000000000 --- a/test/integration/fixtures/blocks/core__list__ol-with-type.parsed.json +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "blockName": "core/list", - "attrs": { - "ordered": true, - "type": "A" - }, - "innerBlocks": [ - { - "blockName": "core/list-item", - "attrs": {}, - "innerBlocks": [], - "innerHTML": "\n\t
  • Item 1
  • \n\t", - "innerContent": [ "\n\t
  • Item 1
  • \n\t" ] - } - ], - "innerHTML": "\n
      \n\t\n
    \n", - "innerContent": [ "\n
      \n\t", null, "\n
    \n" ] - } -] diff --git a/test/integration/fixtures/blocks/core__list__ol-with-type.serialized.html b/test/integration/fixtures/blocks/core__list__ol-with-type.serialized.html deleted file mode 100644 index a785d55d92bcee..00000000000000 --- a/test/integration/fixtures/blocks/core__list__ol-with-type.serialized.html +++ /dev/null @@ -1,5 +0,0 @@ - -
      -
    1. Item 1
    2. -
    - diff --git a/test/integration/fixtures/blocks/core__list__ul.json b/test/integration/fixtures/blocks/core__list__ul.json index 80cd87e4eb69e8..d65a959f7aaa01 100644 --- a/test/integration/fixtures/blocks/core__list__ul.json +++ b/test/integration/fixtures/blocks/core__list__ul.json @@ -4,7 +4,8 @@ "isValid": true, "attributes": { "ordered": false, - "values": "" + "values": "", + "type": "decimal" }, "innerBlocks": [ { From bcfd32553c16670e546f4464cc629ffc4c28dd5f Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Sun, 6 Aug 2023 11:33:17 +0900 Subject: [PATCH 5/8] Try to fix unit test --- .../core__list__deprecated-v1-nested.json | 15 +++++-------- .../blocks/core__list__deprecated-v1.json | 3 +-- .../blocks/core__list__ol-with-type.html | 7 +++++++ .../blocks/core__list__ol-with-type.json | 21 +++++++++++++++++++ .../core__list__ol-with-type.parsed.json | 20 ++++++++++++++++++ .../core__list__ol-with-type.serialized.html | 5 +++++ .../fixtures/blocks/core__list__ul.json | 3 +-- 7 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 test/integration/fixtures/blocks/core__list__ol-with-type.html create mode 100644 test/integration/fixtures/blocks/core__list__ol-with-type.json create mode 100644 test/integration/fixtures/blocks/core__list__ol-with-type.parsed.json create mode 100644 test/integration/fixtures/blocks/core__list__ol-with-type.serialized.html diff --git a/test/integration/fixtures/blocks/core__list__deprecated-v1-nested.json b/test/integration/fixtures/blocks/core__list__deprecated-v1-nested.json index 8b01b23e87904d..0e5c001e4e0367 100644 --- a/test/integration/fixtures/blocks/core__list__deprecated-v1-nested.json +++ b/test/integration/fixtures/blocks/core__list__deprecated-v1-nested.json @@ -4,8 +4,7 @@ "isValid": true, "attributes": { "ordered": false, - "values": "", - "type": "decimal" + "values": "" }, "innerBlocks": [ { @@ -20,8 +19,7 @@ "isValid": true, "attributes": { "ordered": false, - "values": "", - "type": "decimal" + "values": "" }, "innerBlocks": [ { @@ -36,8 +34,7 @@ "isValid": true, "attributes": { "ordered": false, - "values": "", - "type": "decimal" + "values": "" }, "innerBlocks": [ { @@ -64,8 +61,7 @@ "isValid": true, "attributes": { "ordered": false, - "values": "", - "type": "decimal" + "values": "" }, "innerBlocks": [ { @@ -92,8 +88,7 @@ "isValid": true, "attributes": { "ordered": false, - "values": "", - "type": "decimal" + "values": "" }, "innerBlocks": [ { diff --git a/test/integration/fixtures/blocks/core__list__deprecated-v1.json b/test/integration/fixtures/blocks/core__list__deprecated-v1.json index d65a959f7aaa01..80cd87e4eb69e8 100644 --- a/test/integration/fixtures/blocks/core__list__deprecated-v1.json +++ b/test/integration/fixtures/blocks/core__list__deprecated-v1.json @@ -4,8 +4,7 @@ "isValid": true, "attributes": { "ordered": false, - "values": "", - "type": "decimal" + "values": "" }, "innerBlocks": [ { diff --git a/test/integration/fixtures/blocks/core__list__ol-with-type.html b/test/integration/fixtures/blocks/core__list__ol-with-type.html new file mode 100644 index 00000000000000..9969965e5a56ce --- /dev/null +++ b/test/integration/fixtures/blocks/core__list__ol-with-type.html @@ -0,0 +1,7 @@ + +
      + +
    1. Item 1
    2. + +
    + diff --git a/test/integration/fixtures/blocks/core__list__ol-with-type.json b/test/integration/fixtures/blocks/core__list__ol-with-type.json new file mode 100644 index 00000000000000..be078f2f8208e4 --- /dev/null +++ b/test/integration/fixtures/blocks/core__list__ol-with-type.json @@ -0,0 +1,21 @@ +[ + { + "name": "core/list", + "isValid": true, + "attributes": { + "ordered": true, + "values": "", + "type": "upper-alpha" + }, + "innerBlocks": [ + { + "name": "core/list-item", + "isValid": true, + "attributes": { + "content": "Item 1" + }, + "innerBlocks": [] + } + ] + } +] diff --git a/test/integration/fixtures/blocks/core__list__ol-with-type.parsed.json b/test/integration/fixtures/blocks/core__list__ol-with-type.parsed.json new file mode 100644 index 00000000000000..7ddda9e08da5ab --- /dev/null +++ b/test/integration/fixtures/blocks/core__list__ol-with-type.parsed.json @@ -0,0 +1,20 @@ +[ + { + "blockName": "core/list", + "attrs": { + "ordered": true, + "type": "A" + }, + "innerBlocks": [ + { + "blockName": "core/list-item", + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n\t
  • Item 1
  • \n\t", + "innerContent": [ "\n\t
  • Item 1
  • \n\t" ] + } + ], + "innerHTML": "\n
      \n\t\n
    \n", + "innerContent": [ "\n
      \n\t", null, "\n
    \n" ] + } +] diff --git a/test/integration/fixtures/blocks/core__list__ol-with-type.serialized.html b/test/integration/fixtures/blocks/core__list__ol-with-type.serialized.html new file mode 100644 index 00000000000000..44c97ca29209cf --- /dev/null +++ b/test/integration/fixtures/blocks/core__list__ol-with-type.serialized.html @@ -0,0 +1,5 @@ + +
      +
    1. Item 1
    2. +
    + diff --git a/test/integration/fixtures/blocks/core__list__ul.json b/test/integration/fixtures/blocks/core__list__ul.json index d65a959f7aaa01..80cd87e4eb69e8 100644 --- a/test/integration/fixtures/blocks/core__list__ul.json +++ b/test/integration/fixtures/blocks/core__list__ul.json @@ -4,8 +4,7 @@ "isValid": true, "attributes": { "ordered": false, - "values": "", - "type": "decimal" + "values": "" }, "innerBlocks": [ { From 188595951b2f83871553d340288e3615b2a5d1fa Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Sun, 6 Aug 2023 12:38:01 +0900 Subject: [PATCH 6/8] Try to fix raw-handling test --- .../src/list/ordered-list-settings.js | 24 ++++---- packages/block-library/src/list/utils.js | 61 ++++++++++++++++--- .../blocks-raw-handling.test.js.snap | 12 ++-- .../fixtures/documents/ms-word-out.html | 4 +- 4 files changed, 70 insertions(+), 31 deletions(-) diff --git a/packages/block-library/src/list/ordered-list-settings.js b/packages/block-library/src/list/ordered-list-settings.js index 2f0df726c8cde7..f11985ad13a519 100644 --- a/packages/block-library/src/list/ordered-list-settings.js +++ b/packages/block-library/src/list/ordered-list-settings.js @@ -10,6 +10,11 @@ import { SelectControl, } from '@wordpress/components'; +/** + * Internal dependencies + */ +import { LIST_STYLE_TYPES } from './utils'; + const OrderedListSettings = ( { setAttributes, reversed, start, type } ) => ( @@ -32,19 +37,12 @@ const OrderedListSettings = ( { setAttributes, reversed, start, type } ) => ( { + return { + label, + value, + }; + } ) } value={ type } onChange={ ( newValue ) => setAttributes( { type: newValue } ) } /> diff --git a/packages/block-library/src/list/utils.js b/packages/block-library/src/list/utils.js index e4a8815d483dd6..30b83f5a95ac89 100644 --- a/packages/block-library/src/list/utils.js +++ b/packages/block-library/src/list/utils.js @@ -1,9 +1,52 @@ /** * WordPress dependencies */ +import { __ } from '@wordpress/i18n'; import { createBlock, rawHandler } from '@wordpress/blocks'; +export const LIST_STYLE_TYPES = [ + { + label: __( 'Numbers' ), + value: 'decimal', + type: '1', + }, + { + label: __( 'Uppercase letters' ), + value: 'upper-alpha', + type: 'A', + }, + { + label: __( 'Lowercase letters' ), + value: 'lower-alpha', + type: 'a', + }, + { + label: __( 'Uppercase Roman numerals' ), + value: 'upper-roman', + type: 'I', + }, + { + label: __( 'Lowercase Roman numerals' ), + value: 'lower-roman', + type: 'i', + }, +]; + +function getListStyleTypeValue( type ) { + if ( ! type ) { + return undefined; + } + + const listStyleType = LIST_STYLE_TYPES.find( + ( item ) => item.type === type + ); + + return listStyleType ? listStyleType.value : undefined; +} + export function createListBlockFromDOMElement( listElement ) { + const type = listElement.getAttribute( 'type' ); + const listStyleType = getListStyleTypeValue( type ); const listAttributes = { ordered: 'OL' === listElement.tagName, anchor: listElement.id === '' ? undefined : listElement.id, @@ -11,7 +54,10 @@ export function createListBlockFromDOMElement( listElement ) { ? parseInt( listElement.getAttribute( 'start' ), 10 ) : undefined, reversed: listElement.hasAttribute( 'reversed' ) ? true : undefined, - type: listElement.getAttribute( 'type' ) ?? undefined, + type: + listStyleType && listStyleType !== 'decimal' + ? listStyleType + : undefined, }; const innerBlocks = Array.from( listElement.children ).map( @@ -80,19 +126,14 @@ export function migrateToListV2( attributes ) { } export function migrateTypeToInlineStyle( attributes ) { - const typeStyles = { - A: 'upper-alpha', - a: 'lower-alpha', - I: 'upper-roman', - i: 'lower-roman', - }; - const { type } = attributes; - if ( typeStyles[ type ] ) { + const listStyleType = getListStyleTypeValue( type ); + + if ( listStyleType && listStyleType !== 'decimal' ) { return { ...attributes, - type: typeStyles[ type ], + type: listStyleType || undefined, }; } diff --git a/test/integration/__snapshots__/blocks-raw-handling.test.js.snap b/test/integration/__snapshots__/blocks-raw-handling.test.js.snap index 7ae0dc9b886893..178a57b8755535 100644 --- a/test/integration/__snapshots__/blocks-raw-handling.test.js.snap +++ b/test/integration/__snapshots__/blocks-raw-handling.test.js.snap @@ -14,10 +14,10 @@ exports[`Blocks raw handling pasteHandler google-docs-table 1`] = `"


    exports[`Blocks raw handling pasteHandler google-docs-table-with-colspan 1`] = `"

    Test colspan

    "`; -exports[`Blocks raw handling pasteHandler google-docs-table-with-rowspan 1`] = `"

    Test rowspan

    "`; - exports[`Blocks raw handling pasteHandler google-docs-table-with-comments 1`] = `"



    One
    Two
    Three
    1
    2
    3
    I
    II
    III"`; +exports[`Blocks raw handling pasteHandler google-docs-table-with-rowspan 1`] = `"

    Test rowspan

    "`; + exports[`Blocks raw handling pasteHandler google-docs-with-comments 1`] = `"This is a title

    This is a heading

    Formatting test: bold, italic, link, strikethrough, superscript, subscript, nested.

    A
    Bulleted
    Indented
    List

    One
    Two
    Three




    One
    Two
    Three
    1
    2
    3
    I
    II
    III





    An image:



    "`; exports[`Blocks raw handling pasteHandler gutenberg 1`] = `"Test"`; @@ -174,10 +174,10 @@ exports[`rawHandler should convert a caption shortcode with link 1`] = ` `; exports[`rawHandler should convert a list with attributes 1`] = ` -" -
      -
    1. 1 -
        +" +
          +
        1. 1 +
          1. 1
        2. diff --git a/test/integration/fixtures/documents/ms-word-out.html b/test/integration/fixtures/documents/ms-word-out.html index 0b1a3e00fe84de..98992494032b3e 100644 --- a/test/integration/fixtures/documents/ms-word-out.html +++ b/test/integration/fixtures/documents/ms-word-out.html @@ -36,8 +36,8 @@

          This is a heading level 2

          - -
            + +
            1. One
            2. From 3e66d7d05c36e8d0678b60c41cd1e1cdc409c09d Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Sun, 6 Aug 2023 13:26:17 +0900 Subject: [PATCH 7/8] Fix fixture files --- ...re__list__ol-with-type.html => core__list__deprecated-v2.html} | 0 ...re__list__ol-with-type.json => core__list__deprecated-v2.json} | 0 ...ith-type.parsed.json => core__list__deprecated-v2.parsed.json} | 0 ....serialized.html => core__list__deprecated-v2.serialized.html} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename test/integration/fixtures/blocks/{core__list__ol-with-type.html => core__list__deprecated-v2.html} (100%) rename test/integration/fixtures/blocks/{core__list__ol-with-type.json => core__list__deprecated-v2.json} (100%) rename test/integration/fixtures/blocks/{core__list__ol-with-type.parsed.json => core__list__deprecated-v2.parsed.json} (100%) rename test/integration/fixtures/blocks/{core__list__ol-with-type.serialized.html => core__list__deprecated-v2.serialized.html} (100%) diff --git a/test/integration/fixtures/blocks/core__list__ol-with-type.html b/test/integration/fixtures/blocks/core__list__deprecated-v2.html similarity index 100% rename from test/integration/fixtures/blocks/core__list__ol-with-type.html rename to test/integration/fixtures/blocks/core__list__deprecated-v2.html diff --git a/test/integration/fixtures/blocks/core__list__ol-with-type.json b/test/integration/fixtures/blocks/core__list__deprecated-v2.json similarity index 100% rename from test/integration/fixtures/blocks/core__list__ol-with-type.json rename to test/integration/fixtures/blocks/core__list__deprecated-v2.json diff --git a/test/integration/fixtures/blocks/core__list__ol-with-type.parsed.json b/test/integration/fixtures/blocks/core__list__deprecated-v2.parsed.json similarity index 100% rename from test/integration/fixtures/blocks/core__list__ol-with-type.parsed.json rename to test/integration/fixtures/blocks/core__list__deprecated-v2.parsed.json diff --git a/test/integration/fixtures/blocks/core__list__ol-with-type.serialized.html b/test/integration/fixtures/blocks/core__list__deprecated-v2.serialized.html similarity index 100% rename from test/integration/fixtures/blocks/core__list__ol-with-type.serialized.html rename to test/integration/fixtures/blocks/core__list__deprecated-v2.serialized.html From b57f19a3ddc2a06ca15b86d7958288a4584f858c Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Sun, 6 Aug 2023 15:46:57 +0900 Subject: [PATCH 8/8] refactoring --- .../src/list/ordered-list-settings.js | 33 +++++++---- packages/block-library/src/list/utils.js | 58 +++---------------- 2 files changed, 31 insertions(+), 60 deletions(-) diff --git a/packages/block-library/src/list/ordered-list-settings.js b/packages/block-library/src/list/ordered-list-settings.js index f11985ad13a519..5d5d9936c73a0a 100644 --- a/packages/block-library/src/list/ordered-list-settings.js +++ b/packages/block-library/src/list/ordered-list-settings.js @@ -10,11 +10,6 @@ import { SelectControl, } from '@wordpress/components'; -/** - * Internal dependencies - */ -import { LIST_STYLE_TYPES } from './utils'; - const OrderedListSettings = ( { setAttributes, reversed, start, type } ) => ( @@ -37,12 +32,28 @@ const OrderedListSettings = ( { setAttributes, reversed, start, type } ) => ( { - return { - label, - value, - }; - } ) } + options={ [ + { + label: __( 'Numbers' ), + value: 'decimal', + }, + { + label: __( 'Uppercase letters' ), + value: 'upper-alpha', + }, + { + label: __( 'Lowercase letters' ), + value: 'lower-alpha', + }, + { + label: __( 'Uppercase Roman numerals' ), + value: 'upper-roman', + }, + { + label: __( 'Lowercase Roman numerals' ), + value: 'lower-roman', + }, + ] } value={ type } onChange={ ( newValue ) => setAttributes( { type: newValue } ) } /> diff --git a/packages/block-library/src/list/utils.js b/packages/block-library/src/list/utils.js index 30b83f5a95ac89..60f3354cea426f 100644 --- a/packages/block-library/src/list/utils.js +++ b/packages/block-library/src/list/utils.js @@ -1,52 +1,17 @@ /** * WordPress dependencies */ -import { __ } from '@wordpress/i18n'; import { createBlock, rawHandler } from '@wordpress/blocks'; -export const LIST_STYLE_TYPES = [ - { - label: __( 'Numbers' ), - value: 'decimal', - type: '1', - }, - { - label: __( 'Uppercase letters' ), - value: 'upper-alpha', - type: 'A', - }, - { - label: __( 'Lowercase letters' ), - value: 'lower-alpha', - type: 'a', - }, - { - label: __( 'Uppercase Roman numerals' ), - value: 'upper-roman', - type: 'I', - }, - { - label: __( 'Lowercase Roman numerals' ), - value: 'lower-roman', - type: 'i', - }, -]; - -function getListStyleTypeValue( type ) { - if ( ! type ) { - return undefined; - } - - const listStyleType = LIST_STYLE_TYPES.find( - ( item ) => item.type === type - ); - - return listStyleType ? listStyleType.value : undefined; -} +const LIST_STYLES = { + A: 'upper-alpha', + a: 'lower-alpha', + I: 'upper-roman', + i: 'lower-roman', +}; export function createListBlockFromDOMElement( listElement ) { const type = listElement.getAttribute( 'type' ); - const listStyleType = getListStyleTypeValue( type ); const listAttributes = { ordered: 'OL' === listElement.tagName, anchor: listElement.id === '' ? undefined : listElement.id, @@ -54,10 +19,7 @@ export function createListBlockFromDOMElement( listElement ) { ? parseInt( listElement.getAttribute( 'start' ), 10 ) : undefined, reversed: listElement.hasAttribute( 'reversed' ) ? true : undefined, - type: - listStyleType && listStyleType !== 'decimal' - ? listStyleType - : undefined, + type: type && LIST_STYLES[ type ] ? LIST_STYLES[ type ] : undefined, }; const innerBlocks = Array.from( listElement.children ).map( @@ -128,12 +90,10 @@ export function migrateToListV2( attributes ) { export function migrateTypeToInlineStyle( attributes ) { const { type } = attributes; - const listStyleType = getListStyleTypeValue( type ); - - if ( listStyleType && listStyleType !== 'decimal' ) { + if ( type && LIST_STYLES[ type ] ) { return { ...attributes, - type: listStyleType || undefined, + type: LIST_STYLES[ type ], }; }