@wordpress/format-library 4.30.0 → 4.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/default-formats.js +2 -1
  3. package/build/default-formats.js.map +1 -1
  4. package/build/link/index.js +54 -11
  5. package/build/link/index.js.map +1 -1
  6. package/build/link/inline.js +5 -2
  7. package/build/link/inline.js.map +1 -1
  8. package/build/non-breaking-space/index.js +36 -0
  9. package/build/non-breaking-space/index.js.map +1 -0
  10. package/build/text-color/index.native.js +4 -4
  11. package/build/text-color/index.native.js.map +1 -1
  12. package/build/text-color/inline.native.js +17 -38
  13. package/build/text-color/inline.native.js.map +1 -1
  14. package/build/unknown/index.js +12 -7
  15. package/build/unknown/index.js.map +1 -1
  16. package/build-module/default-formats.js +2 -1
  17. package/build-module/default-formats.js.map +1 -1
  18. package/build-module/link/index.js +55 -12
  19. package/build-module/link/index.js.map +1 -1
  20. package/build-module/link/inline.js +5 -2
  21. package/build-module/link/inline.js.map +1 -1
  22. package/build-module/non-breaking-space/index.js +29 -0
  23. package/build-module/non-breaking-space/index.js.map +1 -0
  24. package/build-module/text-color/index.native.js +1 -1
  25. package/build-module/text-color/index.native.js.map +1 -1
  26. package/build-module/text-color/inline.native.js +17 -39
  27. package/build-module/text-color/inline.native.js.map +1 -1
  28. package/build-module/unknown/index.js +13 -8
  29. package/build-module/unknown/index.js.map +1 -1
  30. package/package.json +14 -14
  31. package/src/default-formats.js +2 -0
  32. package/src/link/index.js +55 -11
  33. package/src/link/inline.js +7 -1
  34. package/src/non-breaking-space/index.js +29 -0
  35. package/src/text-color/index.native.js +1 -1
  36. package/src/text-color/inline.native.js +27 -49
  37. package/src/text-color/test/__snapshots__/index.native.js.snap +0 -6
  38. package/src/text-color/test/index.native.js +4 -39
  39. package/src/unknown/index.js +16 -10
@@ -64,45 +64,6 @@ describe( 'Text color', () => {
64
64
  expect( textColorButton ).toBeDefined();
65
65
  } );
66
66
 
67
- it( 'allows toggling the highlight color feature to type new text', async () => {
68
- const screen = await initializeEditor();
69
-
70
- // Wait for the editor placeholder
71
- const paragraphPlaceholder = await screen.findByLabelText(
72
- 'Add paragraph block'
73
- );
74
- expect( paragraphPlaceholder ).toBeDefined();
75
- fireEvent.press( paragraphPlaceholder );
76
-
77
- // Wait for the block to be created
78
- const [ paragraphBlock ] = await screen.findAllByLabelText(
79
- /Paragraph Block\. Row 1/
80
- );
81
- expect( paragraphBlock ).toBeDefined();
82
-
83
- // Look for the highlight text color button
84
- const textColorButton = await screen.findByLabelText( 'Text color' );
85
- expect( textColorButton ).toBeDefined();
86
- fireEvent.press( textColorButton );
87
-
88
- // Wait for Inline color modal to be visible
89
- const inlineTextColorModal = screen.getByTestId(
90
- 'inline-text-color-modal'
91
- );
92
- await waitFor( () => inlineTextColorModal.props.isVisible );
93
-
94
- // Look for the pink color button
95
- const pinkColorButton = await screen.findByA11yHint( COLOR_PINK );
96
- expect( pinkColorButton ).toBeDefined();
97
- fireEvent.press( pinkColorButton );
98
- // TODO(jest-console): Fix the warning and remove the expect below.
99
- expect( console ).toHaveWarnedWith(
100
- `Non-serializable values were found in the navigation state. Check:\n\ntext-color > Palette > params.onColorChange (Function)\n\nThis can break usage such as persisting and restoring state. This might happen if you passed non-serializable values such as function, class instances etc. in params. If you need to use components with callbacks in your options, you can use 'navigation.setOptions' instead. See https://reactnavigation.org/docs/troubleshooting#i-get-the-warning-non-serializable-values-were-found-in-the-navigation-state for more details.`
101
- );
102
-
103
- expect( getEditorHtml() ).toMatchSnapshot();
104
- } );
105
-
106
67
  it( 'allows toggling the highlight color feature to selected text', async () => {
107
68
  const screen = await initializeEditor();
108
69
  const text = 'Hello this is a test';
@@ -145,6 +106,10 @@ describe( 'Text color', () => {
145
106
  const pinkColorButton = await screen.findByA11yHint( COLOR_PINK );
146
107
  expect( pinkColorButton ).toBeDefined();
147
108
  fireEvent.press( pinkColorButton );
109
+ // TODO(jest-console): Fix the warning and remove the expect below.
110
+ expect( console ).toHaveWarnedWith(
111
+ `Non-serializable values were found in the navigation state. Check:\n\ntext-color > Palette > params.onColorChange (Function)\n\nThis can break usage such as persisting and restoring state. This might happen if you passed non-serializable values such as function, class instances etc. in params. If you need to use components with callbacks in your options, you can use 'navigation.setOptions' instead. See https://reactnavigation.org/docs/troubleshooting#i-get-the-warning-non-serializable-values-were-found-in-the-navigation-state for more details.`
112
+ );
148
113
 
149
114
  expect( getEditorHtml() ).toMatchSnapshot();
150
115
  } );
@@ -2,33 +2,39 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
- import { removeFormat, slice } from '@wordpress/rich-text';
5
+ import { removeFormat, slice, isCollapsed } from '@wordpress/rich-text';
6
6
  import { RichTextToolbarButton } from '@wordpress/block-editor';
7
7
  import { help } from '@wordpress/icons';
8
8
 
9
9
  const name = 'core/unknown';
10
10
  const title = __( 'Clear Unknown Formatting' );
11
11
 
12
+ function selectionContainsUnknownFormats( value ) {
13
+ if ( isCollapsed( value ) ) {
14
+ return false;
15
+ }
16
+
17
+ const selectedValue = slice( value );
18
+ return selectedValue.formats.some( ( formats ) => {
19
+ return formats.some( ( format ) => format.type === name );
20
+ } );
21
+ }
22
+
12
23
  export const unknown = {
13
24
  name,
14
25
  title,
15
26
  tagName: '*',
16
27
  className: null,
17
28
  edit( { isActive, value, onChange, onFocus } ) {
29
+ if ( ! isActive && ! selectionContainsUnknownFormats( value ) ) {
30
+ return null;
31
+ }
32
+
18
33
  function onClick() {
19
34
  onChange( removeFormat( value, name ) );
20
35
  onFocus();
21
36
  }
22
37
 
23
- const selectedValue = slice( value );
24
- const hasUnknownFormats = selectedValue.formats.some( ( formats ) => {
25
- return formats.some( ( format ) => format.type === name );
26
- } );
27
-
28
- if ( ! isActive && ! hasUnknownFormats ) {
29
- return null;
30
- }
31
-
32
38
  return (
33
39
  <RichTextToolbarButton
34
40
  name="unknown"