@wordpress/format-library 5.47.0 → 5.48.1

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 (42) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/image/index.cjs +5 -3
  3. package/build/image/index.cjs.map +3 -3
  4. package/build/language/index.cjs +6 -4
  5. package/build/language/index.cjs.map +3 -3
  6. package/build/link/css-classes-setting.cjs +1 -1
  7. package/build/link/css-classes-setting.cjs.map +3 -3
  8. package/build/math/index.cjs +2 -1
  9. package/build/math/index.cjs.map +3 -3
  10. package/build/text-color/inline.cjs +6 -7
  11. package/build/text-color/inline.cjs.map +3 -3
  12. package/build-module/image/index.mjs +5 -6
  13. package/build-module/image/index.mjs.map +2 -2
  14. package/build-module/language/index.mjs +7 -7
  15. package/build-module/language/index.mjs.map +2 -2
  16. package/build-module/link/css-classes-setting.mjs +3 -4
  17. package/build-module/link/css-classes-setting.mjs.map +2 -2
  18. package/build-module/math/index.mjs +2 -2
  19. package/build-module/math/index.mjs.map +2 -2
  20. package/build-module/text-color/inline.mjs +7 -11
  21. package/build-module/text-color/inline.mjs.map +2 -2
  22. package/package.json +24 -20
  23. package/src/image/index.js +8 -9
  24. package/src/language/index.js +8 -8
  25. package/src/link/css-classes-setting.js +3 -4
  26. package/src/math/index.js +3 -3
  27. package/src/text-color/inline.js +11 -16
  28. package/src/default-formats.native.js +0 -10
  29. package/src/link/index.native.js +0 -176
  30. package/src/link/modal-screens/link-picker-screen.native.js +0 -61
  31. package/src/link/modal-screens/link-settings-screen.native.js +0 -229
  32. package/src/link/modal-screens/screens.native.js +0 -4
  33. package/src/link/modal.native.js +0 -44
  34. package/src/link/modal.native.scss +0 -16
  35. package/src/link/test/__snapshots__/modal.native.js.snap +0 -553
  36. package/src/link/test/index.native.js +0 -145
  37. package/src/link/test/modal.native.js +0 -18
  38. package/src/text-color/index.native.js +0 -172
  39. package/src/text-color/inline.native.js +0 -169
  40. package/src/text-color/style.native.scss +0 -22
  41. package/src/text-color/test/__snapshots__/index.native.js.snap +0 -23
  42. package/src/text-color/test/index.native.js +0 -192
@@ -1,61 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { Keyboard } from 'react-native';
5
- import { useNavigation, useRoute } from '@react-navigation/native';
6
-
7
- /**
8
- * WordPress dependencies
9
- */
10
- import { useEffect, useMemo, useRef } from '@wordpress/element';
11
-
12
- import { LinkPicker } from '@wordpress/components';
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
- import linkSettingsScreens from './screens';
18
-
19
- const LinkPickerScreen = () => {
20
- const navigation = useNavigation();
21
- const route = useRoute();
22
- const navigateToLinkTimeoutRef = useRef( null );
23
- const navigateBackTimeoutRef = useRef( null );
24
-
25
- const onLinkPicked = ( { url, title } ) => {
26
- Keyboard.dismiss();
27
- navigateToLinkTimeoutRef.current = setTimeout( () => {
28
- navigation.navigate( linkSettingsScreens.settings, {
29
- inputValue: url,
30
- text: title,
31
- } );
32
- }, 100 );
33
- };
34
-
35
- const onCancel = () => {
36
- Keyboard.dismiss();
37
- navigateBackTimeoutRef.current = setTimeout( () => {
38
- navigation.goBack();
39
- }, 100 );
40
- };
41
-
42
- useEffect( () => {
43
- return () => {
44
- clearTimeout( navigateToLinkTimeoutRef.current );
45
- clearTimeout( navigateBackTimeoutRef.current );
46
- };
47
- }, [] );
48
-
49
- const { inputValue } = route.params;
50
- return useMemo( () => {
51
- return (
52
- <LinkPicker
53
- value={ inputValue }
54
- onLinkPicked={ onLinkPicked }
55
- onCancel={ onCancel }
56
- />
57
- );
58
- }, [ inputValue ] );
59
- };
60
-
61
- export default LinkPickerScreen;
@@ -1,229 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { useNavigation, useRoute } from '@react-navigation/native';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { __ } from '@wordpress/i18n';
10
- import { useState, useContext, useEffect, useMemo } from '@wordpress/element';
11
- import { prependHTTP } from '@wordpress/url';
12
- import { BottomSheet, BottomSheetContext } from '@wordpress/components';
13
- import {
14
- create,
15
- insert,
16
- isCollapsed,
17
- applyFormat,
18
- getTextContent,
19
- slice,
20
- } from '@wordpress/rich-text';
21
- import { external, textColor } from '@wordpress/icons';
22
-
23
- /**
24
- * Internal dependencies
25
- */
26
- import { createLinkFormat, isValidHref } from '../utils';
27
- import linkSettingsScreens from './screens';
28
-
29
- import styles from '../modal.scss';
30
-
31
- const LinkSettingsScreen = ( {
32
- onRemove,
33
- onClose,
34
- onChange,
35
- speak,
36
- value,
37
- isActive,
38
- activeAttributes,
39
- isVisible,
40
- } ) => {
41
- const [ text, setText ] = useState( getTextContent( slice( value ) ) );
42
- const [ opensInNewWindow, setOpensInNewWindows ] = useState(
43
- activeAttributes.target === '_blank'
44
- );
45
- const [ linkValues, setLinkValues ] = useState( {
46
- isActiveLink: isActive,
47
- isRemovingLink: false,
48
- } );
49
-
50
- const {
51
- shouldEnableBottomSheetMaxHeight,
52
- onHandleClosingBottomSheet,
53
- listProps,
54
- } = useContext( BottomSheetContext );
55
-
56
- const navigation = useNavigation();
57
- const route = useRoute();
58
- const { inputValue = activeAttributes.url || '' } = route.params || {};
59
- const onLinkCellPressed = () => {
60
- shouldEnableBottomSheetMaxHeight( false );
61
- navigation.navigate( linkSettingsScreens.picker, { inputValue } );
62
- };
63
- useEffect( () => {
64
- onHandleClosingBottomSheet( () => {
65
- submit( inputValue, { skipStateUpdates: true } );
66
- } );
67
- }, [ inputValue, opensInNewWindow, text ] );
68
-
69
- useEffect( () => {
70
- const { isActiveLink, isRemovingLink } = linkValues;
71
- if ( !! inputValue && ! isActiveLink && isVisible ) {
72
- submitLink( { shouldCloseBottomSheet: false } );
73
- } else if (
74
- ( ( inputValue === '' && isActiveLink ) || isRemovingLink ) &&
75
- isVisible
76
- ) {
77
- removeLink( { shouldCloseBottomSheet: false } );
78
- }
79
- }, [
80
- inputValue,
81
- isVisible,
82
- linkValues.isActiveLink,
83
- linkValues.isRemovingLink,
84
- ] );
85
-
86
- const clearFormat = ( { skipStateUpdates = false } = {} ) => {
87
- onChange( { ...value, activeFormats: [] } );
88
- if ( ! skipStateUpdates ) {
89
- setLinkValues( { isActiveLink: false, isRemovingLink: true } );
90
- }
91
- };
92
-
93
- const submitLink = ( {
94
- shouldCloseBottomSheet = true,
95
- skipStateUpdates = false,
96
- } = {} ) => {
97
- const url = prependHTTP( inputValue );
98
- const linkText = text || inputValue;
99
- const format = createLinkFormat( {
100
- url,
101
- opensInNewWindow,
102
- text: linkText,
103
- } );
104
- let newAttributes;
105
- if ( isCollapsed( value ) && ! isActive ) {
106
- // Insert link.
107
- const toInsert = applyFormat(
108
- create( { text: linkText } ),
109
- format,
110
- 0,
111
- linkText.length
112
- );
113
- newAttributes = insert( value, toInsert );
114
- } else if ( text !== getTextContent( slice( value ) ) ) {
115
- // Edit text in selected link.
116
- const toInsert = applyFormat(
117
- create( { text } ),
118
- format,
119
- 0,
120
- text.length
121
- );
122
- newAttributes = insert( value, toInsert, value.start, value.end );
123
- } else {
124
- // Transform selected text into link.
125
- newAttributes = applyFormat( value, format );
126
- }
127
- // Move selection to end of link.
128
- const textLength = newAttributes.text.length;
129
- // check for zero width spaces
130
- if ( newAttributes.end > textLength ) {
131
- newAttributes.start = textLength;
132
- newAttributes.end = textLength;
133
- } else {
134
- newAttributes.start = newAttributes.end;
135
- }
136
- newAttributes.activeFormats = [];
137
- onChange( { ...newAttributes, needsSelectionUpdate: true } );
138
- if ( ! skipStateUpdates ) {
139
- setLinkValues( { isActiveLink: true, isRemovingLink: false } );
140
- }
141
-
142
- if ( ! isValidHref( url ) ) {
143
- speak(
144
- __(
145
- 'Warning: the link has been inserted but may have errors. Please test it.'
146
- ),
147
- 'assertive'
148
- );
149
- } else if ( isActive ) {
150
- speak( __( 'Link edited.' ), 'assertive' );
151
- } else {
152
- speak( __( 'Link inserted' ), 'assertive' );
153
- }
154
-
155
- if ( shouldCloseBottomSheet ) {
156
- onClose();
157
- }
158
- };
159
-
160
- const removeLink = ( {
161
- shouldCloseBottomSheet = true,
162
- skipStateUpdates = false,
163
- } = {} ) => {
164
- clearFormat( { skipStateUpdates } );
165
- onRemove();
166
- if ( shouldCloseBottomSheet ) {
167
- onClose();
168
- }
169
- };
170
-
171
- const submit = ( submitValue, { skipStateUpdates = false } = {} ) => {
172
- if ( submitValue === '' ) {
173
- removeLink( { skipStateUpdates } );
174
- } else {
175
- submitLink( { skipStateUpdates } );
176
- }
177
- };
178
-
179
- useEffect( () => {
180
- const unsubscribe = navigation.addListener( 'focus', () => {
181
- const { params = {} } = route;
182
- if ( ! text && params.text ) {
183
- setText( params.text );
184
- }
185
- } );
186
- return unsubscribe;
187
- }, [ navigation, route.params?.text, text ] );
188
-
189
- return useMemo( () => {
190
- const shouldShowLinkOptions = !! inputValue;
191
-
192
- return (
193
- <>
194
- <BottomSheet.LinkCell
195
- value={ inputValue }
196
- onPress={ onLinkCellPressed }
197
- />
198
- <BottomSheet.Cell
199
- icon={ textColor }
200
- label={ __( 'Link text' ) }
201
- value={ text }
202
- placeholder={ __( 'Add link text' ) }
203
- onChangeValue={ setText }
204
- onSubmit={ submit }
205
- separatorType={ shouldShowLinkOptions ? undefined : 'none' }
206
- />
207
- { shouldShowLinkOptions && (
208
- <>
209
- <BottomSheet.SwitchCell
210
- icon={ external }
211
- label={ __( 'Open in new tab' ) }
212
- value={ opensInNewWindow }
213
- onValueChange={ setOpensInNewWindows }
214
- separatorType="fullWidth"
215
- />
216
- <BottomSheet.Cell
217
- label={ __( 'Remove link' ) }
218
- labelStyle={ styles.clearLinkButton }
219
- separatorType="none"
220
- onPress={ removeLink }
221
- />
222
- </>
223
- ) }
224
- </>
225
- );
226
- }, [ inputValue, text, opensInNewWindow, listProps.safeAreaBottomInset ] );
227
- };
228
-
229
- export default LinkSettingsScreen;
@@ -1,4 +0,0 @@
1
- export default {
2
- settings: 'linkSettings',
3
- picker: 'linkPicker',
4
- };
@@ -1,44 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useMemo } from '@wordpress/element';
5
- import { BottomSheet, withSpokenMessages } from '@wordpress/components';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import screens from './modal-screens/screens';
11
- import LinkSettingsScreen from './modal-screens/link-settings-screen';
12
- import LinkPickerScreen from './modal-screens/link-picker-screen';
13
-
14
- const ModalLinkUI = ( { isVisible, ...restProps } ) => {
15
- return useMemo( () => {
16
- return (
17
- <BottomSheet
18
- isVisible={ isVisible }
19
- hideHeader
20
- onClose={ restProps.onClose }
21
- hasNavigation
22
- testID="link-settings-modal"
23
- >
24
- <BottomSheet.NavigationContainer animate main>
25
- <BottomSheet.NavigationScreen name={ screens.settings }>
26
- <LinkSettingsScreen
27
- isVisible={ isVisible }
28
- { ...restProps }
29
- />
30
- </BottomSheet.NavigationScreen>
31
- <BottomSheet.NavigationScreen
32
- name={ screens.picker }
33
- isScrollable
34
- fullScreen
35
- >
36
- <LinkPickerScreen />
37
- </BottomSheet.NavigationScreen>
38
- </BottomSheet.NavigationContainer>
39
- </BottomSheet>
40
- );
41
- }, [ isVisible ] );
42
- };
43
-
44
- export default withSpokenMessages( ModalLinkUI );
@@ -1,16 +0,0 @@
1
- .clearLinkButton {
2
- color: $alert-red;
3
- }
4
-
5
- .container {
6
- padding-bottom: 0;
7
- padding-left: $block-edge-to-content;
8
- padding-right: $block-edge-to-content;
9
- padding-top: $block-edge-to-content*0.5;
10
- }
11
-
12
- .content {
13
- padding-left: $grid-unit-20;
14
- padding-right: $grid-unit-20;
15
- padding-bottom: 0;
16
- }