@wordpress/patterns 1.4.0 → 1.5.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.
- package/CHANGELOG.md +2 -0
- package/build/components/category-selector.js +16 -31
- package/build/components/category-selector.js.map +1 -1
- package/build/components/create-pattern-modal.js +59 -14
- package/build/components/create-pattern-modal.js.map +1 -1
- package/build/components/duplicate-pattern-modal.js +81 -0
- package/build/components/duplicate-pattern-modal.js.map +1 -0
- package/build/components/rename-pattern-category-modal.js +106 -0
- package/build/components/rename-pattern-category-modal.js.map +1 -0
- package/build/components/rename-pattern-modal.js +97 -0
- package/build/components/rename-pattern-modal.js.map +1 -0
- package/build/lock-unlock.js +1 -1
- package/build/lock-unlock.js.map +1 -1
- package/build/private-apis.js +6 -0
- package/build/private-apis.js.map +1 -1
- package/build-module/components/category-selector.js +17 -32
- package/build-module/components/category-selector.js.map +1 -1
- package/build-module/components/create-pattern-modal.js +61 -16
- package/build-module/components/create-pattern-modal.js.map +1 -1
- package/build-module/components/duplicate-pattern-modal.js +73 -0
- package/build-module/components/duplicate-pattern-modal.js.map +1 -0
- package/build-module/components/rename-pattern-category-modal.js +99 -0
- package/build-module/components/rename-pattern-category-modal.js.map +1 -0
- package/build-module/components/rename-pattern-modal.js +90 -0
- package/build-module/components/rename-pattern-modal.js.map +1 -0
- package/build-module/lock-unlock.js +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/private-apis.js +6 -0
- package/build-module/private-apis.js.map +1 -1
- package/build-style/style-rtl.css +22 -2
- package/build-style/style.css +22 -2
- package/package.json +16 -17
- package/src/components/category-selector.js +28 -42
- package/src/components/create-pattern-modal.js +63 -14
- package/src/components/duplicate-pattern-modal.js +93 -0
- package/src/components/rename-pattern-category-modal.js +121 -0
- package/src/components/rename-pattern-modal.js +115 -0
- package/src/components/style.scss +28 -2
- package/src/lock-unlock.js +1 -1
- package/src/private-apis.js +6 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
Modal,
|
|
6
|
+
Button,
|
|
7
|
+
TextControl,
|
|
8
|
+
__experimentalHStack as HStack,
|
|
9
|
+
__experimentalVStack as VStack,
|
|
10
|
+
} from '@wordpress/components';
|
|
11
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
12
|
+
import { useDispatch } from '@wordpress/data';
|
|
13
|
+
import { useState } from '@wordpress/element';
|
|
14
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
15
|
+
import { __ } from '@wordpress/i18n';
|
|
16
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
import { CATEGORY_SLUG } from './category-selector';
|
|
22
|
+
|
|
23
|
+
export default function RenamePatternCategoryModal( {
|
|
24
|
+
category,
|
|
25
|
+
onClose,
|
|
26
|
+
onError,
|
|
27
|
+
onSuccess,
|
|
28
|
+
...props
|
|
29
|
+
} ) {
|
|
30
|
+
const [ name, setName ] = useState( decodeEntities( category.name ) );
|
|
31
|
+
const [ isSaving, setIsSaving ] = useState( false );
|
|
32
|
+
|
|
33
|
+
const { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );
|
|
34
|
+
|
|
35
|
+
const { createErrorNotice, createSuccessNotice } =
|
|
36
|
+
useDispatch( noticesStore );
|
|
37
|
+
|
|
38
|
+
const onRename = async ( event ) => {
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
|
|
41
|
+
if ( ! name || name === category.name || isSaving ) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
setIsSaving( true );
|
|
47
|
+
|
|
48
|
+
// User pattern category properties may differ as they can be
|
|
49
|
+
// normalized for use alongside template part areas, core pattern
|
|
50
|
+
// categories etc. As a result we won't just destructure the passed
|
|
51
|
+
// category object.
|
|
52
|
+
const savedRecord = await saveEntityRecord(
|
|
53
|
+
'taxonomy',
|
|
54
|
+
CATEGORY_SLUG,
|
|
55
|
+
{
|
|
56
|
+
id: category.id,
|
|
57
|
+
slug: category.slug,
|
|
58
|
+
name,
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
invalidateResolution( 'getUserPatternCategories' );
|
|
63
|
+
onSuccess?.( savedRecord );
|
|
64
|
+
onClose();
|
|
65
|
+
|
|
66
|
+
createSuccessNotice( __( 'Pattern category renamed.' ), {
|
|
67
|
+
type: 'snackbar',
|
|
68
|
+
id: 'pattern-category-update',
|
|
69
|
+
} );
|
|
70
|
+
} catch ( error ) {
|
|
71
|
+
onError?.();
|
|
72
|
+
createErrorNotice( error.message, {
|
|
73
|
+
type: 'snackbar',
|
|
74
|
+
id: 'pattern-category-update',
|
|
75
|
+
} );
|
|
76
|
+
} finally {
|
|
77
|
+
setIsSaving( false );
|
|
78
|
+
setName( '' );
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const onRequestClose = () => {
|
|
83
|
+
onClose();
|
|
84
|
+
setName( '' );
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<Modal
|
|
89
|
+
title={ __( 'Rename' ) }
|
|
90
|
+
onRequestClose={ onRequestClose }
|
|
91
|
+
{ ...props }
|
|
92
|
+
>
|
|
93
|
+
<form onSubmit={ onRename }>
|
|
94
|
+
<VStack spacing="5">
|
|
95
|
+
<TextControl
|
|
96
|
+
__nextHasNoMarginBottom
|
|
97
|
+
label={ __( 'Name' ) }
|
|
98
|
+
value={ name }
|
|
99
|
+
onChange={ setName }
|
|
100
|
+
required
|
|
101
|
+
/>
|
|
102
|
+
<HStack justify="right">
|
|
103
|
+
<Button variant="tertiary" onClick={ onRequestClose }>
|
|
104
|
+
{ __( 'Cancel' ) }
|
|
105
|
+
</Button>
|
|
106
|
+
<Button
|
|
107
|
+
variant="primary"
|
|
108
|
+
type="submit"
|
|
109
|
+
aria-disabled={
|
|
110
|
+
! name || name === category.name || isSaving
|
|
111
|
+
}
|
|
112
|
+
isBusy={ isSaving }
|
|
113
|
+
>
|
|
114
|
+
{ __( 'Save' ) }
|
|
115
|
+
</Button>
|
|
116
|
+
</HStack>
|
|
117
|
+
</VStack>
|
|
118
|
+
</form>
|
|
119
|
+
</Modal>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
Modal,
|
|
7
|
+
TextControl,
|
|
8
|
+
__experimentalHStack as HStack,
|
|
9
|
+
__experimentalVStack as VStack,
|
|
10
|
+
} from '@wordpress/components';
|
|
11
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
12
|
+
import { useDispatch } from '@wordpress/data';
|
|
13
|
+
import { useState } from '@wordpress/element';
|
|
14
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
15
|
+
import { __ } from '@wordpress/i18n';
|
|
16
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
17
|
+
|
|
18
|
+
export default function RenamePatternModal( {
|
|
19
|
+
onClose,
|
|
20
|
+
onError,
|
|
21
|
+
onSuccess,
|
|
22
|
+
pattern,
|
|
23
|
+
...props
|
|
24
|
+
} ) {
|
|
25
|
+
const originalName = decodeEntities( pattern.title );
|
|
26
|
+
const [ name, setName ] = useState( originalName );
|
|
27
|
+
const [ isSaving, setIsSaving ] = useState( false );
|
|
28
|
+
|
|
29
|
+
const {
|
|
30
|
+
editEntityRecord,
|
|
31
|
+
__experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits,
|
|
32
|
+
} = useDispatch( coreStore );
|
|
33
|
+
|
|
34
|
+
const { createSuccessNotice, createErrorNotice } =
|
|
35
|
+
useDispatch( noticesStore );
|
|
36
|
+
|
|
37
|
+
const onRename = async ( event ) => {
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
|
|
40
|
+
if ( ! name || name === pattern.title || isSaving ) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
await editEntityRecord( 'postType', pattern.type, pattern.id, {
|
|
46
|
+
title: name,
|
|
47
|
+
} );
|
|
48
|
+
|
|
49
|
+
setIsSaving( true );
|
|
50
|
+
setName( '' );
|
|
51
|
+
onClose?.();
|
|
52
|
+
|
|
53
|
+
const savedRecord = await saveSpecifiedEntityEdits(
|
|
54
|
+
'postType',
|
|
55
|
+
pattern.type,
|
|
56
|
+
pattern.id,
|
|
57
|
+
[ 'title' ],
|
|
58
|
+
{ throwOnError: true }
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
onSuccess?.( savedRecord );
|
|
62
|
+
|
|
63
|
+
createSuccessNotice( __( 'Pattern renamed' ), {
|
|
64
|
+
type: 'snackbar',
|
|
65
|
+
id: 'pattern-update',
|
|
66
|
+
} );
|
|
67
|
+
} catch ( error ) {
|
|
68
|
+
onError?.();
|
|
69
|
+
|
|
70
|
+
const errorMessage =
|
|
71
|
+
error.message && error.code !== 'unknown_error'
|
|
72
|
+
? error.message
|
|
73
|
+
: __( 'An error occurred while renaming the pattern.' );
|
|
74
|
+
|
|
75
|
+
createErrorNotice( errorMessage, {
|
|
76
|
+
type: 'snackbar',
|
|
77
|
+
id: 'pattern-update',
|
|
78
|
+
} );
|
|
79
|
+
} finally {
|
|
80
|
+
setIsSaving( false );
|
|
81
|
+
setName( '' );
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const onRequestClose = () => {
|
|
86
|
+
onClose?.();
|
|
87
|
+
setName( '' );
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Modal title={ __( 'Rename' ) } { ...props } onRequestClose={ onClose }>
|
|
92
|
+
<form onSubmit={ onRename }>
|
|
93
|
+
<VStack spacing="5">
|
|
94
|
+
<TextControl
|
|
95
|
+
__nextHasNoMarginBottom
|
|
96
|
+
label={ __( 'Name' ) }
|
|
97
|
+
value={ name }
|
|
98
|
+
onChange={ setName }
|
|
99
|
+
required
|
|
100
|
+
/>
|
|
101
|
+
|
|
102
|
+
<HStack justify="right">
|
|
103
|
+
<Button variant="tertiary" onClick={ onRequestClose }>
|
|
104
|
+
{ __( 'Cancel' ) }
|
|
105
|
+
</Button>
|
|
106
|
+
|
|
107
|
+
<Button variant="primary" type="submit">
|
|
108
|
+
{ __( 'Save' ) }
|
|
109
|
+
</Button>
|
|
110
|
+
</HStack>
|
|
111
|
+
</VStack>
|
|
112
|
+
</form>
|
|
113
|
+
</Modal>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
@@ -1,10 +1,36 @@
|
|
|
1
1
|
.patterns-menu-items__convert-modal {
|
|
2
2
|
z-index: z-index(".patterns-menu-items__convert-modal");
|
|
3
|
+
|
|
4
|
+
// Fix the modal width to prevent added categories from stretching the modal.
|
|
5
|
+
[role="dialog"] > [role="document"] {
|
|
6
|
+
width: 350px;
|
|
7
|
+
}
|
|
8
|
+
|
|
3
9
|
.patterns-menu-items__convert-modal-categories {
|
|
4
|
-
|
|
10
|
+
width: 100%;
|
|
11
|
+
position: relative;
|
|
12
|
+
min-height: 40px;
|
|
13
|
+
}
|
|
14
|
+
.components-form-token-field__suggestions-list {
|
|
15
|
+
position: absolute;
|
|
16
|
+
box-sizing: border-box;
|
|
17
|
+
z-index: 1;
|
|
18
|
+
background-color: $white;
|
|
19
|
+
// Account for the border width of the token field.
|
|
20
|
+
width: calc(100% + 2px);
|
|
21
|
+
left: -1px;
|
|
22
|
+
min-width: initial;
|
|
23
|
+
border: 1px solid var(--wp-admin-theme-color);
|
|
24
|
+
border-top: none;
|
|
25
|
+
box-shadow: 0 0 0 0.5px var(--wp-admin-theme-color);
|
|
26
|
+
border-bottom-left-radius: 2px;
|
|
27
|
+
border-bottom-right-radius: 2px;
|
|
5
28
|
}
|
|
6
29
|
}
|
|
7
30
|
|
|
8
31
|
.patterns-create-modal__name-input input[type="text"] {
|
|
9
|
-
|
|
32
|
+
// Match the minimal height of the category selector.
|
|
33
|
+
min-height: 40px;
|
|
34
|
+
// Override the default 1px margin-x.
|
|
35
|
+
margin: 0;
|
|
10
36
|
}
|
package/src/lock-unlock.js
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
|
|
5
5
|
export const { lock, unlock } =
|
|
6
6
|
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
|
|
7
|
-
'I know using unstable features means my
|
|
7
|
+
'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.',
|
|
8
8
|
'@wordpress/patterns'
|
|
9
9
|
);
|
package/src/private-apis.js
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { lock } from './lock-unlock';
|
|
5
5
|
import CreatePatternModal from './components/create-pattern-modal';
|
|
6
|
+
import DuplicatePatternModal from './components/duplicate-pattern-modal';
|
|
7
|
+
import RenamePatternModal from './components/rename-pattern-modal';
|
|
6
8
|
import PatternsMenuItems from './components';
|
|
9
|
+
import RenamePatternCategoryModal from './components/rename-pattern-category-modal';
|
|
7
10
|
import {
|
|
8
11
|
PATTERN_TYPES,
|
|
9
12
|
PATTERN_DEFAULT_CATEGORY,
|
|
@@ -15,7 +18,10 @@ import {
|
|
|
15
18
|
export const privateApis = {};
|
|
16
19
|
lock( privateApis, {
|
|
17
20
|
CreatePatternModal,
|
|
21
|
+
DuplicatePatternModal,
|
|
22
|
+
RenamePatternModal,
|
|
18
23
|
PatternsMenuItems,
|
|
24
|
+
RenamePatternCategoryModal,
|
|
19
25
|
PATTERN_TYPES,
|
|
20
26
|
PATTERN_DEFAULT_CATEGORY,
|
|
21
27
|
PATTERN_USER_CATEGORY,
|