@wordpress/block-library 3.2.17 → 3.2.20
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/README.md +1 -2
- package/build/button/edit.js +47 -20
- package/build/button/edit.js.map +1 -1
- package/build/post-excerpt/edit.js +15 -30
- package/build/post-excerpt/edit.js.map +1 -1
- package/build/post-excerpt/index.js +0 -4
- package/build/post-excerpt/index.js.map +1 -1
- package/build-module/button/edit.js +48 -21
- package/build-module/button/edit.js.map +1 -1
- package/build-module/post-excerpt/edit.js +16 -32
- package/build-module/post-excerpt/edit.js.map +1 -1
- package/build-module/post-excerpt/index.js +0 -4
- package/build-module/post-excerpt/index.js.map +1 -1
- package/package.json +27 -27
- package/src/button/edit.js +44 -17
- package/src/post-excerpt/block.json +0 -4
- package/src/post-excerpt/edit.js +19 -42
- package/src/post-excerpt/index.php +18 -18
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ apply_filter( 'render_block', 'render_block_my_block' );
|
|
|
72
72
|
|
|
73
73
|
<!-- START TOKEN(Autogenerated API docs) -->
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
### registerCoreBlocks
|
|
76
76
|
|
|
77
77
|
Function to register core blocks provided by the block editor.
|
|
78
78
|
|
|
@@ -88,7 +88,6 @@ _Parameters_
|
|
|
88
88
|
|
|
89
89
|
- _blocks_ `Array`: An optional array of the core blocks being registered.
|
|
90
90
|
|
|
91
|
-
|
|
92
91
|
<!-- END TOKEN(Autogenerated API docs) -->
|
|
93
92
|
|
|
94
93
|
<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
|
package/build/button/edit.js
CHANGED
|
@@ -67,30 +67,42 @@ function URLPicker({
|
|
|
67
67
|
setAttributes,
|
|
68
68
|
opensInNewTab,
|
|
69
69
|
onToggleOpenInNewTab,
|
|
70
|
-
anchorRef
|
|
70
|
+
anchorRef,
|
|
71
|
+
richTextRef
|
|
71
72
|
}) {
|
|
72
|
-
const [
|
|
73
|
-
const
|
|
74
|
-
const urlIsSetandSelected = urlIsSet && isSelected;
|
|
73
|
+
const [isEditingURL, setIsEditingURL] = (0, _element.useState)(false);
|
|
74
|
+
const isURLSet = !!url;
|
|
75
75
|
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
const startEditing = event => {
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
setIsEditingURL(true);
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
-
const
|
|
81
|
+
const unlink = () => {
|
|
82
82
|
setAttributes({
|
|
83
83
|
url: undefined,
|
|
84
84
|
linkTarget: undefined,
|
|
85
85
|
rel: undefined
|
|
86
86
|
});
|
|
87
|
-
|
|
87
|
+
setIsEditingURL(false);
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
(0, _element.useEffect)(() => {
|
|
91
|
+
if (!isSelected) {
|
|
92
|
+
setIsEditingURL(false);
|
|
93
|
+
}
|
|
94
|
+
}, [isSelected]);
|
|
95
|
+
const isLinkControlVisible = isSelected && (isEditingURL || isURLSet);
|
|
96
|
+
const linkControl = isLinkControlVisible && (0, _element.createElement)(_components.Popover, {
|
|
91
97
|
position: "bottom center",
|
|
92
|
-
onClose: () =>
|
|
93
|
-
|
|
98
|
+
onClose: () => {
|
|
99
|
+
var _richTextRef$current;
|
|
100
|
+
|
|
101
|
+
setIsEditingURL(false);
|
|
102
|
+
(_richTextRef$current = richTextRef.current) === null || _richTextRef$current === void 0 ? void 0 : _richTextRef$current.focus();
|
|
103
|
+
},
|
|
104
|
+
anchorRef: anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current,
|
|
105
|
+
focusOnMount: isEditingURL ? 'firstElement' : false
|
|
94
106
|
}, (0, _element.createElement)(_blockEditor.__experimentalLinkControl, {
|
|
95
107
|
className: "wp-block-navigation-link__inline-link-input",
|
|
96
108
|
value: {
|
|
@@ -108,28 +120,40 @@ function URLPicker({
|
|
|
108
120
|
if (opensInNewTab !== newOpensInNewTab) {
|
|
109
121
|
onToggleOpenInNewTab(newOpensInNewTab);
|
|
110
122
|
}
|
|
111
|
-
}
|
|
123
|
+
},
|
|
124
|
+
onRemove: () => {
|
|
125
|
+
var _richTextRef$current2;
|
|
126
|
+
|
|
127
|
+
unlink();
|
|
128
|
+
(_richTextRef$current2 = richTextRef.current) === null || _richTextRef$current2 === void 0 ? void 0 : _richTextRef$current2.focus();
|
|
129
|
+
},
|
|
130
|
+
forceIsEditingLink: isEditingURL
|
|
112
131
|
}));
|
|
113
132
|
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_blockEditor.BlockControls, {
|
|
114
133
|
group: "block"
|
|
115
|
-
}, !
|
|
134
|
+
}, !isURLSet && (0, _element.createElement)(_components.ToolbarButton, {
|
|
116
135
|
name: "link",
|
|
117
136
|
icon: _icons.link,
|
|
118
137
|
title: (0, _i18n.__)('Link'),
|
|
119
138
|
shortcut: _keycodes.displayShortcut.primary('k'),
|
|
120
|
-
onClick:
|
|
121
|
-
}),
|
|
139
|
+
onClick: startEditing
|
|
140
|
+
}), isURLSet && (0, _element.createElement)(_components.ToolbarButton, {
|
|
122
141
|
name: "link",
|
|
123
142
|
icon: _icons.linkOff,
|
|
124
143
|
title: (0, _i18n.__)('Unlink'),
|
|
125
144
|
shortcut: _keycodes.displayShortcut.primaryShift('k'),
|
|
126
|
-
onClick:
|
|
145
|
+
onClick: unlink,
|
|
127
146
|
isActive: true
|
|
128
147
|
})), isSelected && (0, _element.createElement)(_components.KeyboardShortcuts, {
|
|
129
148
|
bindGlobal: true,
|
|
130
149
|
shortcuts: {
|
|
131
|
-
[_keycodes.rawShortcut.primary('k')]:
|
|
132
|
-
[_keycodes.rawShortcut.primaryShift('k')]:
|
|
150
|
+
[_keycodes.rawShortcut.primary('k')]: startEditing,
|
|
151
|
+
[_keycodes.rawShortcut.primaryShift('k')]: () => {
|
|
152
|
+
var _richTextRef$current3;
|
|
153
|
+
|
|
154
|
+
unlink();
|
|
155
|
+
(_richTextRef$current3 = richTextRef.current) === null || _richTextRef$current3 === void 0 ? void 0 : _richTextRef$current3.focus();
|
|
156
|
+
}
|
|
133
157
|
}
|
|
134
158
|
}), linkControl);
|
|
135
159
|
}
|
|
@@ -185,6 +209,7 @@ function ButtonEdit(props) {
|
|
|
185
209
|
const borderRadius = style === null || style === void 0 ? void 0 : (_style$border = style.border) === null || _style$border === void 0 ? void 0 : _style$border.radius;
|
|
186
210
|
const colorProps = (0, _blockEditor.__experimentalUseColorProps)(attributes);
|
|
187
211
|
const ref = (0, _element.useRef)();
|
|
212
|
+
const richTextRef = (0, _element.useRef)();
|
|
188
213
|
const blockProps = (0, _blockEditor.useBlockProps)({
|
|
189
214
|
ref
|
|
190
215
|
});
|
|
@@ -194,6 +219,7 @@ function ButtonEdit(props) {
|
|
|
194
219
|
[`has-custom-font-size`]: blockProps.style.fontSize
|
|
195
220
|
})
|
|
196
221
|
}), (0, _element.createElement)(_blockEditor.RichText, {
|
|
222
|
+
ref: richTextRef,
|
|
197
223
|
"aria-label": (0, _i18n.__)('Button text'),
|
|
198
224
|
placeholder: placeholder || (0, _i18n.__)('Add text…'),
|
|
199
225
|
value: text,
|
|
@@ -218,7 +244,8 @@ function ButtonEdit(props) {
|
|
|
218
244
|
isSelected: isSelected,
|
|
219
245
|
opensInNewTab: linkTarget === '_blank',
|
|
220
246
|
onToggleOpenInNewTab: onToggleOpenInNewTab,
|
|
221
|
-
anchorRef: ref
|
|
247
|
+
anchorRef: ref,
|
|
248
|
+
richTextRef: richTextRef
|
|
222
249
|
}), (0, _element.createElement)(_blockEditor.InspectorControls, null, (0, _element.createElement)(WidthPanel, {
|
|
223
250
|
selectedWidth: width,
|
|
224
251
|
setAttributes: setAttributes
|
package/build/button/edit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/button/edit.js"],"names":["NEW_TAB_REL","WidthPanel","selectedWidth","setAttributes","handleChange","newWidth","width","undefined","map","widthValue","URLPicker","isSelected","url","opensInNewTab","onToggleOpenInNewTab","anchorRef","isURLPickerOpen","setIsURLPickerOpen","urlIsSet","urlIsSetandSelected","openLinkControl","unlinkButton","linkTarget","rel","linkControl","current","newURL","newOpensInNewTab","link","displayShortcut","primary","linkOff","primaryShift","rawShortcut","ButtonEdit","props","attributes","className","onReplace","mergeBlocks","placeholder","style","text","onSetLinkRel","value","newLinkTarget","updatedRel","setButtonText","newText","replace","borderRadius","border","radius","colorProps","ref","blockProps","fontSize"],"mappings":";;;;;;;;;AASA;;;;AANA;;AAKA;;AAEA;;AASA;;AASA;;AACA;;AACA;;AA9BA;AACA;AACA;;AAGA;AACA;AACA;AAyBA,MAAMA,WAAW,GAAG,qBAApB;;AAEA,SAASC,UAAT,CAAqB;AAAEC,EAAAA,aAAF;AAAiBC,EAAAA;AAAjB,CAArB,EAAwD;AACvD,WAASC,YAAT,CAAuBC,QAAvB,EAAkC;AACjC;AACA,UAAMC,KAAK,GAAGJ,aAAa,KAAKG,QAAlB,GAA6BE,SAA7B,GAAyCF,QAAvD,CAFiC,CAIjC;;AACAF,IAAAA,aAAa,CAAE;AAAEG,MAAAA;AAAF,KAAF,CAAb;AACA;;AAED,SACC,4BAAC,qBAAD;AAAW,IAAA,KAAK,EAAG,cAAI,gBAAJ;AAAnB,KACC,4BAAC,uBAAD;AAAa,kBAAa,cAAI,cAAJ;AAA1B,KACG,CAAE,EAAF,EAAM,EAAN,EAAU,EAAV,EAAc,GAAd,EAAoBE,GAApB,CAA2BC,UAAF,IAAkB;AAC5C,WACC,4BAAC,kBAAD;AACC,MAAA,GAAG,EAAGA,UADP;AAEC,MAAA,OAAO,MAFR;AAGC,MAAA,SAAS,EAAGA,UAAU,KAAKP,aAH5B;AAIC,MAAA,OAAO,EAAG,MAAME,YAAY,CAAEK,UAAF;AAJ7B,OAMGA,UANH,MADD;AAUA,GAXC,CADH,CADD,CADD;AAkBA;;AAED,SAASC,SAAT,CAAoB;AACnBC,EA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AAC,uBAAD;AACC,IAAA,KAAK,EAAG,cAAI,UAAJ,CADT;AAEC,IAAA,KAAK,EAAGoB,GAAG,IAAI,EAFhB;AAGC,IAAA,QAAQ,EAAGoB;AAHZ,IADD,CArDD,CADD;AA+DA;;eAEcT,U","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useState, useRef } from '@wordpress/element';\nimport {\n\tButton,\n\tButtonGroup,\n\tKeyboardShortcuts,\n\tPanelBody,\n\tTextControl,\n\tToolbarButton,\n\tPopover,\n} from '@wordpress/components';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tInspectorAdvancedControls,\n\tRichText,\n\tuseBlockProps,\n\t__experimentalUseColorProps as useColorProps,\n\t__experimentalLinkControl as LinkControl,\n} from '@wordpress/block-editor';\nimport { rawShortcut, displayShortcut } from '@wordpress/keycodes';\nimport { link, linkOff } from '@wordpress/icons';\nimport { createBlock } from '@wordpress/blocks';\n\nconst NEW_TAB_REL = 'noreferrer noopener';\n\nfunction WidthPanel( { selectedWidth, setAttributes } ) {\n\tfunction handleChange( newWidth ) {\n\t\t// Check if we are toggling the width off\n\t\tconst width = selectedWidth === newWidth ? undefined : newWidth;\n\n\t\t// Update attributes\n\t\tsetAttributes( { width } );\n\t}\n\n\treturn (\n\t\t<PanelBody title={ __( 'Width settings' ) }>\n\t\t\t<ButtonGroup aria-label={ __( 'Button width' ) }>\n\t\t\t\t{ [ 25, 50, 75, 100 ].map( ( widthValue ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tkey={ widthValue }\n\t\t\t\t\t\t\tisSmall\n\t\t\t\t\t\t\tisPrimary={ widthValue === selectedWidth }\n\t\t\t\t\t\t\tonClick={ () => handleChange( widthValue ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ widthValue }%\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</ButtonGroup>\n\t\t</PanelBody>\n\t);\n}\n\nfunction URLPicker( {\n\tisSelected,\n\turl,\n\tsetAttributes,\n\topensInNewTab,\n\tonToggleOpenInNewTab,\n\tanchorRef,\n} ) {\n\tconst [ isURLPickerOpen, setIsURLPickerOpen ] = useState( false );\n\tconst urlIsSet = !! url;\n\tconst urlIsSetandSelected = urlIsSet && isSelected;\n\tconst openLinkControl = () => {\n\t\tsetIsURLPickerOpen( true );\n\t\treturn false; // prevents default behaviour for event\n\t};\n\tconst unlinkButton = () => {\n\t\tsetAttributes( {\n\t\t\turl: undefined,\n\t\t\tlinkTarget: undefined,\n\t\t\trel: undefined,\n\t\t} );\n\t\tsetIsURLPickerOpen( false );\n\t};\n\tconst linkControl = ( isURLPickerOpen || urlIsSetandSelected ) && (\n\t\t<Popover\n\t\t\tposition=\"bottom center\"\n\t\t\tonClose={ () => setIsURLPickerOpen( false ) }\n\t\t\tanchorRef={ anchorRef?.current }\n\t\t>\n\t\t\t<LinkControl\n\t\t\t\tclassName=\"wp-block-navigation-link__inline-link-input\"\n\t\t\t\tvalue={ { url, opensInNewTab } }\n\t\t\t\tonChange={ ( {\n\t\t\t\t\turl: newURL = '',\n\t\t\t\t\topensInNewTab: newOpensInNewTab,\n\t\t\t\t} ) => {\n\t\t\t\t\tsetAttributes( { url: newURL } );\n\n\t\t\t\t\tif ( opensInNewTab !== newOpensInNewTab ) {\n\t\t\t\t\t\tonToggleOpenInNewTab( newOpensInNewTab );\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t/>\n\t\t</Popover>\n\t);\n\treturn (\n\t\t<>\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t{ ! urlIsSet && (\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\ticon={ link }\n\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\tshortcut={ displayShortcut.primary( 'k' ) }\n\t\t\t\t\t\tonClick={ openLinkControl }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ urlIsSetandSelected && (\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\ticon={ linkOff }\n\t\t\t\t\t\ttitle={ __( 'Unlink' ) }\n\t\t\t\t\t\tshortcut={ displayShortcut.primaryShift( 'k' ) }\n\t\t\t\t\t\tonClick={ unlinkButton }\n\t\t\t\t\t\tisActive={ true }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</BlockControls>\n\t\t\t{ isSelected && (\n\t\t\t\t<KeyboardShortcuts\n\t\t\t\t\tbindGlobal\n\t\t\t\t\tshortcuts={ {\n\t\t\t\t\t\t[ rawShortcut.primary( 'k' ) ]: openLinkControl,\n\t\t\t\t\t\t[ rawShortcut.primaryShift( 'k' ) ]: unlinkButton,\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ linkControl }\n\t\t</>\n\t);\n}\n\nfunction ButtonEdit( props ) {\n\tconst {\n\t\tattributes,\n\t\tsetAttributes,\n\t\tclassName,\n\t\tisSelected,\n\t\tonReplace,\n\t\tmergeBlocks,\n\t} = props;\n\tconst {\n\t\tlinkTarget,\n\t\tplaceholder,\n\t\trel,\n\t\tstyle,\n\t\ttext,\n\t\turl,\n\t\twidth,\n\t} = attributes;\n\tconst onSetLinkRel = useCallback(\n\t\t( value ) => {\n\t\t\tsetAttributes( { rel: value } );\n\t\t},\n\t\t[ setAttributes ]\n\t);\n\n\tconst onToggleOpenInNewTab = useCallback(\n\t\t( value ) => {\n\t\t\tconst newLinkTarget = value ? '_blank' : undefined;\n\n\t\t\tlet updatedRel = rel;\n\t\t\tif ( newLinkTarget && ! rel ) {\n\t\t\t\tupdatedRel = NEW_TAB_REL;\n\t\t\t} else if ( ! newLinkTarget && rel === NEW_TAB_REL ) {\n\t\t\t\tupdatedRel = undefined;\n\t\t\t}\n\n\t\t\tsetAttributes( {\n\t\t\t\tlinkTarget: newLinkTarget,\n\t\t\t\trel: updatedRel,\n\t\t\t} );\n\t\t},\n\t\t[ rel, setAttributes ]\n\t);\n\n\tconst setButtonText = ( newText ) => {\n\t\t// Remove anchor tags from button text content.\n\t\tsetAttributes( { text: newText.replace( /<\\/?a[^>]*>/g, '' ) } );\n\t};\n\n\tconst borderRadius = style?.border?.radius;\n\tconst colorProps = useColorProps( attributes );\n\tconst ref = useRef();\n\tconst blockProps = useBlockProps( { ref } );\n\n\treturn (\n\t\t<>\n\t\t\t<div\n\t\t\t\t{ ...blockProps }\n\t\t\t\tclassName={ classnames( blockProps.className, {\n\t\t\t\t\t[ `has-custom-width wp-block-button__width-${ width }` ]: width,\n\t\t\t\t\t[ `has-custom-font-size` ]: blockProps.style.fontSize,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<RichText\n\t\t\t\t\taria-label={ __( 'Button text' ) }\n\t\t\t\t\tplaceholder={ placeholder || __( 'Add text…' ) }\n\t\t\t\t\tvalue={ text }\n\t\t\t\t\tonChange={ ( value ) => setButtonText( value ) }\n\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\tclassName,\n\t\t\t\t\t\t'wp-block-button__link',\n\t\t\t\t\t\tcolorProps.className,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'no-border-radius': borderRadius === 0,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tborderRadius: borderRadius\n\t\t\t\t\t\t\t? borderRadius + 'px'\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t...colorProps.style,\n\t\t\t\t\t} }\n\t\t\t\t\tonSplit={ ( value ) =>\n\t\t\t\t\t\tcreateBlock( 'core/button', {\n\t\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t\ttext: value,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\tidentifier=\"text\"\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<URLPicker\n\t\t\t\turl={ url }\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\tisSelected={ isSelected }\n\t\t\t\topensInNewTab={ linkTarget === '_blank' }\n\t\t\t\tonToggleOpenInNewTab={ onToggleOpenInNewTab }\n\t\t\t\tanchorRef={ ref }\n\t\t\t/>\n\t\t\t<InspectorControls>\n\t\t\t\t<WidthPanel\n\t\t\t\t\tselectedWidth={ width }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<InspectorAdvancedControls>\n\t\t\t\t<TextControl\n\t\t\t\t\tlabel={ __( 'Link rel' ) }\n\t\t\t\t\tvalue={ rel || '' }\n\t\t\t\t\tonChange={ onSetLinkRel }\n\t\t\t\t/>\n\t\t\t</InspectorAdvancedControls>\n\t\t</>\n\t);\n}\n\nexport default ButtonEdit;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/button/edit.js"],"names":["NEW_TAB_REL","WidthPanel","selectedWidth","setAttributes","handleChange","newWidth","width","undefined","map","widthValue","URLPicker","isSelected","url","opensInNewTab","onToggleOpenInNewTab","anchorRef","richTextRef","isEditingURL","setIsEditingURL","isURLSet","startEditing","event","preventDefault","unlink","linkTarget","rel","isLinkControlVisible","linkControl","current","focus","newURL","newOpensInNewTab","link","displayShortcut","primary","linkOff","primaryShift","rawShortcut","ButtonEdit","props","attributes","className","onReplace","mergeBlocks","placeholder","style","text","onSetLinkRel","value","newLinkTarget","updatedRel","setButtonText","newText","replace","borderRadius","border","radius","colorProps","ref","blockProps","fontSize"],"mappings":";;;;;;;;;AASA;;;;AANA;;AAKA;;AAEA;;AASA;;AASA;;AACA;;AACA;;AA9BA;AACA;AACA;;AAGA;AACA;AACA;AAyBA,MAAMA,WAAW,GAAG,qBAApB;;AAEA,SAASC,UAAT,CAAqB;AA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IAxCD,EAiDC,4BAAC,8BAAD,QACC,4BAAC,UAAD;AACC,IAAA,aAAa,EAAGV,KADjB;AAEC,IAAA,aAAa,EAAGH;AAFjB,IADD,CAjDD,EAuDC,4BAAC,sCAAD,QACC,4BAAC,uBAAD;AACC,IAAA,KAAK,EAAG,cAAI,UAAJ,CADT;AAEC,IAAA,KAAK,EAAGsB,GAAG,IAAI,EAFhB;AAGC,IAAA,QAAQ,EAAGsB;AAHZ,IADD,CAvDD,CADD;AAiEA;;eAEcT,U","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useEffect, useState, useRef } from '@wordpress/element';\nimport {\n\tButton,\n\tButtonGroup,\n\tKeyboardShortcuts,\n\tPanelBody,\n\tTextControl,\n\tToolbarButton,\n\tPopover,\n} from '@wordpress/components';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tInspectorAdvancedControls,\n\tRichText,\n\tuseBlockProps,\n\t__experimentalUseColorProps as useColorProps,\n\t__experimentalLinkControl as LinkControl,\n} from '@wordpress/block-editor';\nimport { rawShortcut, displayShortcut } from '@wordpress/keycodes';\nimport { link, linkOff } from '@wordpress/icons';\nimport { createBlock } from '@wordpress/blocks';\n\nconst NEW_TAB_REL = 'noreferrer noopener';\n\nfunction WidthPanel( { selectedWidth, setAttributes } ) {\n\tfunction handleChange( newWidth ) {\n\t\t// Check if we are toggling the width off\n\t\tconst width = selectedWidth === newWidth ? undefined : newWidth;\n\n\t\t// Update attributes\n\t\tsetAttributes( { width } );\n\t}\n\n\treturn (\n\t\t<PanelBody title={ __( 'Width settings' ) }>\n\t\t\t<ButtonGroup aria-label={ __( 'Button width' ) }>\n\t\t\t\t{ [ 25, 50, 75, 100 ].map( ( widthValue ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tkey={ widthValue }\n\t\t\t\t\t\t\tisSmall\n\t\t\t\t\t\t\tisPrimary={ widthValue === selectedWidth }\n\t\t\t\t\t\t\tonClick={ () => handleChange( widthValue ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ widthValue }%\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</ButtonGroup>\n\t\t</PanelBody>\n\t);\n}\n\nfunction URLPicker( {\n\tisSelected,\n\turl,\n\tsetAttributes,\n\topensInNewTab,\n\tonToggleOpenInNewTab,\n\tanchorRef,\n\trichTextRef,\n} ) {\n\tconst [ isEditingURL, setIsEditingURL ] = useState( false );\n\tconst isURLSet = !! url;\n\n\tconst startEditing = ( event ) => {\n\t\tevent.preventDefault();\n\t\tsetIsEditingURL( true );\n\t};\n\n\tconst unlink = () => {\n\t\tsetAttributes( {\n\t\t\turl: undefined,\n\t\t\tlinkTarget: undefined,\n\t\t\trel: undefined,\n\t\t} );\n\t\tsetIsEditingURL( false );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! isSelected ) {\n\t\t\tsetIsEditingURL( false );\n\t\t}\n\t}, [ isSelected ] );\n\n\tconst isLinkControlVisible = isSelected && ( isEditingURL || isURLSet );\n\n\tconst linkControl = isLinkControlVisible && (\n\t\t<Popover\n\t\t\tposition=\"bottom center\"\n\t\t\tonClose={ () => {\n\t\t\t\tsetIsEditingURL( false );\n\t\t\t\trichTextRef.current?.focus();\n\t\t\t} }\n\t\t\tanchorRef={ anchorRef?.current }\n\t\t\tfocusOnMount={ isEditingURL ? 'firstElement' : false }\n\t\t>\n\t\t\t<LinkControl\n\t\t\t\tclassName=\"wp-block-navigation-link__inline-link-input\"\n\t\t\t\tvalue={ { url, opensInNewTab } }\n\t\t\t\tonChange={ ( {\n\t\t\t\t\turl: newURL = '',\n\t\t\t\t\topensInNewTab: newOpensInNewTab,\n\t\t\t\t} ) => {\n\t\t\t\t\tsetAttributes( { url: newURL } );\n\n\t\t\t\t\tif ( opensInNewTab !== newOpensInNewTab ) {\n\t\t\t\t\t\tonToggleOpenInNewTab( newOpensInNewTab );\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tonRemove={ () => {\n\t\t\t\t\tunlink();\n\t\t\t\t\trichTextRef.current?.focus();\n\t\t\t\t} }\n\t\t\t\tforceIsEditingLink={ isEditingURL }\n\t\t\t/>\n\t\t</Popover>\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t{ ! isURLSet && (\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\ticon={ link }\n\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\tshortcut={ displayShortcut.primary( 'k' ) }\n\t\t\t\t\t\tonClick={ startEditing }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ isURLSet && (\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\ticon={ linkOff }\n\t\t\t\t\t\ttitle={ __( 'Unlink' ) }\n\t\t\t\t\t\tshortcut={ displayShortcut.primaryShift( 'k' ) }\n\t\t\t\t\t\tonClick={ unlink }\n\t\t\t\t\t\tisActive={ true }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</BlockControls>\n\t\t\t{ isSelected && (\n\t\t\t\t<KeyboardShortcuts\n\t\t\t\t\tbindGlobal\n\t\t\t\t\tshortcuts={ {\n\t\t\t\t\t\t[ rawShortcut.primary( 'k' ) ]: startEditing,\n\t\t\t\t\t\t[ rawShortcut.primaryShift( 'k' ) ]: () => {\n\t\t\t\t\t\t\tunlink();\n\t\t\t\t\t\t\trichTextRef.current?.focus();\n\t\t\t\t\t\t},\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ linkControl }\n\t\t</>\n\t);\n}\n\nfunction ButtonEdit( props ) {\n\tconst {\n\t\tattributes,\n\t\tsetAttributes,\n\t\tclassName,\n\t\tisSelected,\n\t\tonReplace,\n\t\tmergeBlocks,\n\t} = props;\n\tconst {\n\t\tlinkTarget,\n\t\tplaceholder,\n\t\trel,\n\t\tstyle,\n\t\ttext,\n\t\turl,\n\t\twidth,\n\t} = attributes;\n\tconst onSetLinkRel = useCallback(\n\t\t( value ) => {\n\t\t\tsetAttributes( { rel: value } );\n\t\t},\n\t\t[ setAttributes ]\n\t);\n\n\tconst onToggleOpenInNewTab = useCallback(\n\t\t( value ) => {\n\t\t\tconst newLinkTarget = value ? '_blank' : undefined;\n\n\t\t\tlet updatedRel = rel;\n\t\t\tif ( newLinkTarget && ! rel ) {\n\t\t\t\tupdatedRel = NEW_TAB_REL;\n\t\t\t} else if ( ! newLinkTarget && rel === NEW_TAB_REL ) {\n\t\t\t\tupdatedRel = undefined;\n\t\t\t}\n\n\t\t\tsetAttributes( {\n\t\t\t\tlinkTarget: newLinkTarget,\n\t\t\t\trel: updatedRel,\n\t\t\t} );\n\t\t},\n\t\t[ rel, setAttributes ]\n\t);\n\n\tconst setButtonText = ( newText ) => {\n\t\t// Remove anchor tags from button text content.\n\t\tsetAttributes( { text: newText.replace( /<\\/?a[^>]*>/g, '' ) } );\n\t};\n\n\tconst borderRadius = style?.border?.radius;\n\tconst colorProps = useColorProps( attributes );\n\tconst ref = useRef();\n\tconst richTextRef = useRef();\n\tconst blockProps = useBlockProps( { ref } );\n\n\treturn (\n\t\t<>\n\t\t\t<div\n\t\t\t\t{ ...blockProps }\n\t\t\t\tclassName={ classnames( blockProps.className, {\n\t\t\t\t\t[ `has-custom-width wp-block-button__width-${ width }` ]: width,\n\t\t\t\t\t[ `has-custom-font-size` ]: blockProps.style.fontSize,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<RichText\n\t\t\t\t\tref={ richTextRef }\n\t\t\t\t\taria-label={ __( 'Button text' ) }\n\t\t\t\t\tplaceholder={ placeholder || __( 'Add text…' ) }\n\t\t\t\t\tvalue={ text }\n\t\t\t\t\tonChange={ ( value ) => setButtonText( value ) }\n\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\tclassName,\n\t\t\t\t\t\t'wp-block-button__link',\n\t\t\t\t\t\tcolorProps.className,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'no-border-radius': borderRadius === 0,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tborderRadius: borderRadius\n\t\t\t\t\t\t\t? borderRadius + 'px'\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t...colorProps.style,\n\t\t\t\t\t} }\n\t\t\t\t\tonSplit={ ( value ) =>\n\t\t\t\t\t\tcreateBlock( 'core/button', {\n\t\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t\ttext: value,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\tidentifier=\"text\"\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<URLPicker\n\t\t\t\turl={ url }\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\tisSelected={ isSelected }\n\t\t\t\topensInNewTab={ linkTarget === '_blank' }\n\t\t\t\tonToggleOpenInNewTab={ onToggleOpenInNewTab }\n\t\t\t\tanchorRef={ ref }\n\t\t\t\trichTextRef={ richTextRef }\n\t\t\t/>\n\t\t\t<InspectorControls>\n\t\t\t\t<WidthPanel\n\t\t\t\t\tselectedWidth={ width }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<InspectorAdvancedControls>\n\t\t\t\t<TextControl\n\t\t\t\t\tlabel={ __( 'Link rel' ) }\n\t\t\t\t\tvalue={ rel || '' }\n\t\t\t\t\tonChange={ onSetLinkRel }\n\t\t\t\t/>\n\t\t\t</InspectorAdvancedControls>\n\t\t</>\n\t);\n}\n\nexport default ButtonEdit;\n"]}
|
|
@@ -32,26 +32,9 @@ var _hooks = require("../utils/hooks");
|
|
|
32
32
|
/**
|
|
33
33
|
* Internal dependencies
|
|
34
34
|
*/
|
|
35
|
-
function usePostContentExcerpt(wordCount, postId, postType) {
|
|
36
|
-
// Don't destrcuture items from content here, it can be undefined.
|
|
37
|
-
const [,, content] = (0, _coreData.useEntityProp)('postType', postType, 'content', postId);
|
|
38
|
-
const renderedPostContent = content === null || content === void 0 ? void 0 : content.rendered;
|
|
39
|
-
return (0, _element.useMemo)(() => {
|
|
40
|
-
if (!renderedPostContent) {
|
|
41
|
-
return '';
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const excerptElement = document.createElement('div');
|
|
45
|
-
excerptElement.innerHTML = renderedPostContent;
|
|
46
|
-
const excerpt = excerptElement.textContent || excerptElement.innerText || '';
|
|
47
|
-
return excerpt.trim().split(' ', wordCount).join(' ');
|
|
48
|
-
}, [renderedPostContent, wordCount]);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
35
|
function PostExcerptEditor({
|
|
52
36
|
attributes: {
|
|
53
37
|
textAlign,
|
|
54
|
-
wordCount,
|
|
55
38
|
moreText,
|
|
56
39
|
showMoreOnNewLine
|
|
57
40
|
},
|
|
@@ -70,12 +53,22 @@ function PostExcerptEditor({
|
|
|
70
53
|
rendered: renderedExcerpt,
|
|
71
54
|
protected: isProtected
|
|
72
55
|
} = {}] = (0, _coreData.useEntityProp)('postType', postType, 'excerpt', postId);
|
|
73
|
-
const postContentExcerpt = usePostContentExcerpt(wordCount, postId, postType);
|
|
74
56
|
const blockProps = (0, _blockEditor.useBlockProps)({
|
|
75
57
|
className: (0, _classnames.default)({
|
|
76
58
|
[`has-text-align-${textAlign}`]: textAlign
|
|
77
59
|
})
|
|
78
60
|
});
|
|
61
|
+
/**
|
|
62
|
+
* When excerpt is editable, strip the html tags from
|
|
63
|
+
* rendered excerpt. This will be used if the entity's
|
|
64
|
+
* excerpt has been produced from the content.
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
const strippedRenderedExcerpt = (0, _element.useMemo)(() => {
|
|
68
|
+
if (!renderedExcerpt) return '';
|
|
69
|
+
const document = new window.DOMParser().parseFromString(renderedExcerpt, 'text/html');
|
|
70
|
+
return document.body.textContent || document.body.innerText || '';
|
|
71
|
+
}, [renderedExcerpt]);
|
|
79
72
|
|
|
80
73
|
if (!postType || !postId) {
|
|
81
74
|
return (0, _element.createElement)("div", blockProps, (0, _element.createElement)(_blockEditor.Warning, null, (0, _i18n.__)('Post excerpt block: no post found.')));
|
|
@@ -98,11 +91,11 @@ function PostExcerptEditor({
|
|
|
98
91
|
const excerptContent = isEditable ? (0, _element.createElement)(_blockEditor.RichText, {
|
|
99
92
|
className: !showMoreOnNewLine && 'wp-block-post-excerpt__excerpt is-inline',
|
|
100
93
|
"aria-label": (0, _i18n.__)('Post excerpt text'),
|
|
101
|
-
value: rawExcerpt ||
|
|
94
|
+
value: rawExcerpt || strippedRenderedExcerpt || (isSelected ? '' : (0, _i18n.__)('No post excerpt found')),
|
|
102
95
|
onChange: setExcerpt
|
|
103
|
-
}) : renderedExcerpt && (0, _element.createElement)(_element.RawHTML, {
|
|
96
|
+
}) : renderedExcerpt && (0, _element.createElement)(_components.Disabled, null, (0, _element.createElement)(_element.RawHTML, {
|
|
104
97
|
key: "html"
|
|
105
|
-
}, renderedExcerpt) ||
|
|
98
|
+
}, renderedExcerpt)) || (0, _i18n.__)('No post excerpt found');
|
|
106
99
|
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_blockEditor.BlockControls, null, (0, _element.createElement)(_blockEditor.AlignmentToolbar, {
|
|
107
100
|
value: textAlign,
|
|
108
101
|
onChange: newAlign => setAttributes({
|
|
@@ -110,15 +103,7 @@ function PostExcerptEditor({
|
|
|
110
103
|
})
|
|
111
104
|
})), (0, _element.createElement)(_blockEditor.InspectorControls, null, (0, _element.createElement)(_components.PanelBody, {
|
|
112
105
|
title: (0, _i18n.__)('Post Excerpt Settings')
|
|
113
|
-
},
|
|
114
|
-
label: (0, _i18n.__)('Max words'),
|
|
115
|
-
value: wordCount,
|
|
116
|
-
onChange: newExcerptLength => setAttributes({
|
|
117
|
-
wordCount: newExcerptLength
|
|
118
|
-
}),
|
|
119
|
-
min: 10,
|
|
120
|
-
max: 100
|
|
121
|
-
}), (0, _element.createElement)(_components.ToggleControl, {
|
|
106
|
+
}, (0, _element.createElement)(_components.ToggleControl, {
|
|
122
107
|
label: (0, _i18n.__)('Show link on new line'),
|
|
123
108
|
checked: showMoreOnNewLine,
|
|
124
109
|
onChange: newShowMoreOnNewLine => setAttributes({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/post-excerpt/edit.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/post-excerpt/edit.js"],"names":["PostExcerptEditor","attributes","textAlign","moreText","showMoreOnNewLine","setAttributes","isSelected","context","postId","postType","queryId","isDescendentOfQueryLoop","userCanEdit","isEditable","rawExcerpt","setExcerpt","rendered","renderedExcerpt","protected","isProtected","blockProps","className","strippedRenderedExcerpt","document","window","DOMParser","parseFromString","body","textContent","innerText","readMoreLink","newMoreText","excerptContent","newAlign","newShowMoreOnNewLine"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AAQA;;AACA;;AAKA;;AAxBA;AACA;AACA;;AAGA;AACA;AACA;;AAcA;AACA;AACA;AAGe,SAASA,iBAAT,CAA4B;AAC1CC,EAAAA,UAAU,EAAE;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,QAAb;AAAuBC,IAAAA;AAAvB,GAD8B;AAE1CC,EAAAA,aAF0C;AAG1CC,EAAAA,UAH0C;AAI1CC,EAAAA,OAAO,EAAE;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,QAAV;AAAoBC,IAAAA;AAApB;AAJiC,CAA5B,EAKX;AACH,QAAMC,uBAAuB,GAAG,CAAC,CAAED,OAAnC;AACA,QAAME,WAAW,GAAG,6BAAkB,UAAlB,EAA8BH,QAA9B,EAAwC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\n/**\n * WordPress dependencies\n */\nimport { useEntityProp } from '@wordpress/core-data';\nimport { useMemo, RawHTML } from '@wordpress/element';\nimport {\n\tAlignmentToolbar,\n\tBlockControls,\n\tInspectorControls,\n\tRichText,\n\tWarning,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { PanelBody, ToggleControl, Disabled } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useCanEditEntity } from '../utils/hooks';\n\nexport default function PostExcerptEditor( {\n\tattributes: { textAlign, moreText, showMoreOnNewLine },\n\tsetAttributes,\n\tisSelected,\n\tcontext: { postId, postType, queryId },\n} ) {\n\tconst isDescendentOfQueryLoop = !! queryId;\n\tconst userCanEdit = useCanEditEntity( 'postType', postType, postId );\n\tconst isEditable = userCanEdit && ! isDescendentOfQueryLoop;\n\tconst [\n\t\trawExcerpt,\n\t\tsetExcerpt,\n\t\t{ rendered: renderedExcerpt, protected: isProtected } = {},\n\t] = useEntityProp( 'postType', postType, 'excerpt', postId );\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t} );\n\t/**\n\t * When excerpt is editable, strip the html tags from\n\t * rendered excerpt. This will be used if the entity's\n\t * excerpt has been produced from the content.\n\t */\n\tconst strippedRenderedExcerpt = useMemo( () => {\n\t\tif ( ! renderedExcerpt ) return '';\n\t\tconst document = new window.DOMParser().parseFromString(\n\t\t\trenderedExcerpt,\n\t\t\t'text/html'\n\t\t);\n\t\treturn document.body.textContent || document.body.innerText || '';\n\t}, [ renderedExcerpt ] );\n\tif ( ! postType || ! postId ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Warning>\n\t\t\t\t\t{ __( 'Post excerpt block: no post found.' ) }\n\t\t\t\t</Warning>\n\t\t\t</div>\n\t\t);\n\t}\n\tif ( isProtected && ! userCanEdit ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Warning>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'There is no excerpt because this is a protected post.'\n\t\t\t\t\t) }\n\t\t\t\t</Warning>\n\t\t\t</div>\n\t\t);\n\t}\n\tconst readMoreLink = (\n\t\t<RichText\n\t\t\tclassName=\"wp-block-post-excerpt__more-link\"\n\t\t\ttagName=\"a\"\n\t\t\taria-label={ __( '\"Read more\" link text' ) }\n\t\t\tplaceholder={ __( 'Add \"read more\" link text' ) }\n\t\t\tvalue={ moreText }\n\t\t\tonChange={ ( newMoreText ) =>\n\t\t\t\tsetAttributes( { moreText: newMoreText } )\n\t\t\t}\n\t\t/>\n\t);\n\tconst excerptContent = isEditable ? (\n\t\t<RichText\n\t\t\tclassName={\n\t\t\t\t! showMoreOnNewLine &&\n\t\t\t\t'wp-block-post-excerpt__excerpt is-inline'\n\t\t\t}\n\t\t\taria-label={ __( 'Post excerpt text' ) }\n\t\t\tvalue={\n\t\t\t\trawExcerpt ||\n\t\t\t\tstrippedRenderedExcerpt ||\n\t\t\t\t( isSelected ? '' : __( 'No post excerpt found' ) )\n\t\t\t}\n\t\t\tonChange={ setExcerpt }\n\t\t/>\n\t) : (\n\t\t( renderedExcerpt && (\n\t\t\t<Disabled>\n\t\t\t\t<RawHTML key=\"html\">{ renderedExcerpt }</RawHTML>\n\t\t\t</Disabled>\n\t\t) ) ||\n\t\t__( 'No post excerpt found' )\n\t);\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<AlignmentToolbar\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( newAlign ) =>\n\t\t\t\t\t\tsetAttributes( { textAlign: newAlign } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Post Excerpt Settings' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show link on new line' ) }\n\t\t\t\t\t\tchecked={ showMoreOnNewLine }\n\t\t\t\t\t\tonChange={ ( newShowMoreOnNewLine ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowMoreOnNewLine: newShowMoreOnNewLine,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ excerptContent }\n\t\t\t\t{ ! showMoreOnNewLine && ' ' }\n\t\t\t\t{ showMoreOnNewLine ? (\n\t\t\t\t\t<p className=\"wp-block-post-excerpt__more-text\">\n\t\t\t\t\t\t{ readMoreLink }\n\t\t\t\t\t</p>\n\t\t\t\t) : (\n\t\t\t\t\treadMoreLink\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/post-excerpt/index.js"],"names":["name","metadata","settings","icon","edit"],"mappings":";;;;;;;;;AAGA;;AAMA;;AATA;AACA;AACA;;AAGA;AACA;AACA
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/post-excerpt/index.js"],"names":["name","metadata","settings","icon","edit"],"mappings":";;;;;;;;;AAGA;;AAMA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM;AAAEA,EAAAA;AAAF,IAAWC,QAAjB;;AAGO,MAAMC,QAAQ,GAAG;AACvBC,EAAAA,IAAI,EAAJA,kBADuB;AAEvBC,EAAAA,IAAI,EAAJA;AAFuB,CAAjB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { postExcerpt as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n};\n"]}
|
|
@@ -10,7 +10,7 @@ import classnames from 'classnames';
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { __ } from '@wordpress/i18n';
|
|
13
|
-
import { useCallback, useState, useRef } from '@wordpress/element';
|
|
13
|
+
import { useCallback, useEffect, useState, useRef } from '@wordpress/element';
|
|
14
14
|
import { Button, ButtonGroup, KeyboardShortcuts, PanelBody, TextControl, ToolbarButton, Popover } from '@wordpress/components';
|
|
15
15
|
import { BlockControls, InspectorControls, InspectorAdvancedControls, RichText, useBlockProps, __experimentalUseColorProps as useColorProps, __experimentalLinkControl as LinkControl } from '@wordpress/block-editor';
|
|
16
16
|
import { rawShortcut, displayShortcut } from '@wordpress/keycodes';
|
|
@@ -51,30 +51,42 @@ function URLPicker({
|
|
|
51
51
|
setAttributes,
|
|
52
52
|
opensInNewTab,
|
|
53
53
|
onToggleOpenInNewTab,
|
|
54
|
-
anchorRef
|
|
54
|
+
anchorRef,
|
|
55
|
+
richTextRef
|
|
55
56
|
}) {
|
|
56
|
-
const [
|
|
57
|
-
const
|
|
58
|
-
const urlIsSetandSelected = urlIsSet && isSelected;
|
|
57
|
+
const [isEditingURL, setIsEditingURL] = useState(false);
|
|
58
|
+
const isURLSet = !!url;
|
|
59
59
|
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
const startEditing = event => {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
setIsEditingURL(true);
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
const
|
|
65
|
+
const unlink = () => {
|
|
66
66
|
setAttributes({
|
|
67
67
|
url: undefined,
|
|
68
68
|
linkTarget: undefined,
|
|
69
69
|
rel: undefined
|
|
70
70
|
});
|
|
71
|
-
|
|
71
|
+
setIsEditingURL(false);
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (!isSelected) {
|
|
76
|
+
setIsEditingURL(false);
|
|
77
|
+
}
|
|
78
|
+
}, [isSelected]);
|
|
79
|
+
const isLinkControlVisible = isSelected && (isEditingURL || isURLSet);
|
|
80
|
+
const linkControl = isLinkControlVisible && createElement(Popover, {
|
|
75
81
|
position: "bottom center",
|
|
76
|
-
onClose: () =>
|
|
77
|
-
|
|
82
|
+
onClose: () => {
|
|
83
|
+
var _richTextRef$current;
|
|
84
|
+
|
|
85
|
+
setIsEditingURL(false);
|
|
86
|
+
(_richTextRef$current = richTextRef.current) === null || _richTextRef$current === void 0 ? void 0 : _richTextRef$current.focus();
|
|
87
|
+
},
|
|
88
|
+
anchorRef: anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current,
|
|
89
|
+
focusOnMount: isEditingURL ? 'firstElement' : false
|
|
78
90
|
}, createElement(LinkControl, {
|
|
79
91
|
className: "wp-block-navigation-link__inline-link-input",
|
|
80
92
|
value: {
|
|
@@ -92,28 +104,40 @@ function URLPicker({
|
|
|
92
104
|
if (opensInNewTab !== newOpensInNewTab) {
|
|
93
105
|
onToggleOpenInNewTab(newOpensInNewTab);
|
|
94
106
|
}
|
|
95
|
-
}
|
|
107
|
+
},
|
|
108
|
+
onRemove: () => {
|
|
109
|
+
var _richTextRef$current2;
|
|
110
|
+
|
|
111
|
+
unlink();
|
|
112
|
+
(_richTextRef$current2 = richTextRef.current) === null || _richTextRef$current2 === void 0 ? void 0 : _richTextRef$current2.focus();
|
|
113
|
+
},
|
|
114
|
+
forceIsEditingLink: isEditingURL
|
|
96
115
|
}));
|
|
97
116
|
return createElement(Fragment, null, createElement(BlockControls, {
|
|
98
117
|
group: "block"
|
|
99
|
-
}, !
|
|
118
|
+
}, !isURLSet && createElement(ToolbarButton, {
|
|
100
119
|
name: "link",
|
|
101
120
|
icon: link,
|
|
102
121
|
title: __('Link'),
|
|
103
122
|
shortcut: displayShortcut.primary('k'),
|
|
104
|
-
onClick:
|
|
105
|
-
}),
|
|
123
|
+
onClick: startEditing
|
|
124
|
+
}), isURLSet && createElement(ToolbarButton, {
|
|
106
125
|
name: "link",
|
|
107
126
|
icon: linkOff,
|
|
108
127
|
title: __('Unlink'),
|
|
109
128
|
shortcut: displayShortcut.primaryShift('k'),
|
|
110
|
-
onClick:
|
|
129
|
+
onClick: unlink,
|
|
111
130
|
isActive: true
|
|
112
131
|
})), isSelected && createElement(KeyboardShortcuts, {
|
|
113
132
|
bindGlobal: true,
|
|
114
133
|
shortcuts: {
|
|
115
|
-
[rawShortcut.primary('k')]:
|
|
116
|
-
[rawShortcut.primaryShift('k')]:
|
|
134
|
+
[rawShortcut.primary('k')]: startEditing,
|
|
135
|
+
[rawShortcut.primaryShift('k')]: () => {
|
|
136
|
+
var _richTextRef$current3;
|
|
137
|
+
|
|
138
|
+
unlink();
|
|
139
|
+
(_richTextRef$current3 = richTextRef.current) === null || _richTextRef$current3 === void 0 ? void 0 : _richTextRef$current3.focus();
|
|
140
|
+
}
|
|
117
141
|
}
|
|
118
142
|
}), linkControl);
|
|
119
143
|
}
|
|
@@ -169,6 +193,7 @@ function ButtonEdit(props) {
|
|
|
169
193
|
const borderRadius = style === null || style === void 0 ? void 0 : (_style$border = style.border) === null || _style$border === void 0 ? void 0 : _style$border.radius;
|
|
170
194
|
const colorProps = useColorProps(attributes);
|
|
171
195
|
const ref = useRef();
|
|
196
|
+
const richTextRef = useRef();
|
|
172
197
|
const blockProps = useBlockProps({
|
|
173
198
|
ref
|
|
174
199
|
});
|
|
@@ -178,6 +203,7 @@ function ButtonEdit(props) {
|
|
|
178
203
|
[`has-custom-font-size`]: blockProps.style.fontSize
|
|
179
204
|
})
|
|
180
205
|
}), createElement(RichText, {
|
|
206
|
+
ref: richTextRef,
|
|
181
207
|
"aria-label": __('Button text'),
|
|
182
208
|
placeholder: placeholder || __('Add text…'),
|
|
183
209
|
value: text,
|
|
@@ -202,7 +228,8 @@ function ButtonEdit(props) {
|
|
|
202
228
|
isSelected: isSelected,
|
|
203
229
|
opensInNewTab: linkTarget === '_blank',
|
|
204
230
|
onToggleOpenInNewTab: onToggleOpenInNewTab,
|
|
205
|
-
anchorRef: ref
|
|
231
|
+
anchorRef: ref,
|
|
232
|
+
richTextRef: richTextRef
|
|
206
233
|
}), createElement(InspectorControls, null, createElement(WidthPanel, {
|
|
207
234
|
selectedWidth: width,
|
|
208
235
|
setAttributes: setAttributes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/button/edit.js"],"names":["classnames","__","useCallback","useState","useRef","Button","ButtonGroup","KeyboardShortcuts","PanelBody","TextControl","ToolbarButton","Popover","BlockControls","InspectorControls","InspectorAdvancedControls","RichText","useBlockProps","__experimentalUseColorProps","useColorProps","__experimentalLinkControl","LinkControl","rawShortcut","displayShortcut","link","linkOff","createBlock","NEW_TAB_REL","WidthPanel","selectedWidth","setAttributes","handleChange","newWidth","width","undefined","map","widthValue","URLPicker","isSelected","url","opensInNewTab","onToggleOpenInNewTab","anchorRef","isURLPickerOpen","setIsURLPickerOpen","urlIsSet","urlIsSetandSelected","openLinkControl","unlinkButton","linkTarget","rel","linkControl","current","newURL","newOpensInNewTab","primary","primaryShift","ButtonEdit","props","attributes","className","onReplace","mergeBlocks","placeholder","style","text","onSetLinkRel","value","newLinkTarget","updatedRel","setButtonText","newText","replace","borderRadius","border","radius","colorProps","ref","blockProps","fontSize"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,WAAT,EAAsBC,QAAtB,EAAgCC,MAAhC,QAA8C,oBAA9C;AACA,SACCC,MADD,EAECC,WAFD,EAGCC,iBAHD,EAICC,SAJD,EAKCC,WALD,EAMCC,aAND,EAOCC,OAPD,QAQO,uBARP;AASA,SACCC,aADD,EAECC,iBAFD,EAGCC,yBAHD,EAICC,QAJD,EAKCC,aALD,EAMCC,2BAA2B,IAAIC,aANhC,EAOCC,yBAAyB,IAAIC,WAP9B,QAQO,yBARP;AASA,SAASC,WAAT,EAAsBC,eAAtB,QAA6C,qBAA7C;AACA,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dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useState, useRef } from '@wordpress/element';\nimport {\n\tButton,\n\tButtonGroup,\n\tKeyboardShortcuts,\n\tPanelBody,\n\tTextControl,\n\tToolbarButton,\n\tPopover,\n} from '@wordpress/components';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tInspectorAdvancedControls,\n\tRichText,\n\tuseBlockProps,\n\t__experimentalUseColorProps as useColorProps,\n\t__experimentalLinkControl as LinkControl,\n} from '@wordpress/block-editor';\nimport { rawShortcut, displayShortcut } from '@wordpress/keycodes';\nimport { link, linkOff } from '@wordpress/icons';\nimport { createBlock } from '@wordpress/blocks';\n\nconst NEW_TAB_REL = 'noreferrer noopener';\n\nfunction WidthPanel( { selectedWidth, setAttributes } ) {\n\tfunction handleChange( newWidth ) {\n\t\t// Check if we are toggling the width off\n\t\tconst width = selectedWidth === newWidth ? undefined : newWidth;\n\n\t\t// Update attributes\n\t\tsetAttributes( { width } );\n\t}\n\n\treturn (\n\t\t<PanelBody title={ __( 'Width settings' ) }>\n\t\t\t<ButtonGroup aria-label={ __( 'Button width' ) }>\n\t\t\t\t{ [ 25, 50, 75, 100 ].map( ( widthValue ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tkey={ widthValue }\n\t\t\t\t\t\t\tisSmall\n\t\t\t\t\t\t\tisPrimary={ widthValue === selectedWidth }\n\t\t\t\t\t\t\tonClick={ () => handleChange( widthValue ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ widthValue }%\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</ButtonGroup>\n\t\t</PanelBody>\n\t);\n}\n\nfunction URLPicker( {\n\tisSelected,\n\turl,\n\tsetAttributes,\n\topensInNewTab,\n\tonToggleOpenInNewTab,\n\tanchorRef,\n} ) {\n\tconst [ isURLPickerOpen, setIsURLPickerOpen ] = useState( false );\n\tconst urlIsSet = !! url;\n\tconst urlIsSetandSelected = urlIsSet && isSelected;\n\tconst openLinkControl = () => {\n\t\tsetIsURLPickerOpen( true );\n\t\treturn false; // prevents default behaviour for event\n\t};\n\tconst unlinkButton = () => {\n\t\tsetAttributes( {\n\t\t\turl: undefined,\n\t\t\tlinkTarget: undefined,\n\t\t\trel: undefined,\n\t\t} );\n\t\tsetIsURLPickerOpen( false );\n\t};\n\tconst linkControl = ( isURLPickerOpen || urlIsSetandSelected ) && (\n\t\t<Popover\n\t\t\tposition=\"bottom center\"\n\t\t\tonClose={ () => setIsURLPickerOpen( false ) }\n\t\t\tanchorRef={ anchorRef?.current }\n\t\t>\n\t\t\t<LinkControl\n\t\t\t\tclassName=\"wp-block-navigation-link__inline-link-input\"\n\t\t\t\tvalue={ { url, opensInNewTab } }\n\t\t\t\tonChange={ ( {\n\t\t\t\t\turl: newURL = '',\n\t\t\t\t\topensInNewTab: newOpensInNewTab,\n\t\t\t\t} ) => {\n\t\t\t\t\tsetAttributes( { url: newURL } );\n\n\t\t\t\t\tif ( opensInNewTab !== newOpensInNewTab ) {\n\t\t\t\t\t\tonToggleOpenInNewTab( newOpensInNewTab );\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t/>\n\t\t</Popover>\n\t);\n\treturn (\n\t\t<>\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t{ ! urlIsSet && (\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\ticon={ link }\n\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\tshortcut={ displayShortcut.primary( 'k' ) }\n\t\t\t\t\t\tonClick={ openLinkControl }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ urlIsSetandSelected && (\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\ticon={ linkOff }\n\t\t\t\t\t\ttitle={ __( 'Unlink' ) }\n\t\t\t\t\t\tshortcut={ displayShortcut.primaryShift( 'k' ) }\n\t\t\t\t\t\tonClick={ unlinkButton }\n\t\t\t\t\t\tisActive={ true }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</BlockControls>\n\t\t\t{ isSelected && (\n\t\t\t\t<KeyboardShortcuts\n\t\t\t\t\tbindGlobal\n\t\t\t\t\tshortcuts={ {\n\t\t\t\t\t\t[ rawShortcut.primary( 'k' ) ]: openLinkControl,\n\t\t\t\t\t\t[ rawShortcut.primaryShift( 'k' ) ]: unlinkButton,\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ linkControl }\n\t\t</>\n\t);\n}\n\nfunction ButtonEdit( props ) {\n\tconst {\n\t\tattributes,\n\t\tsetAttributes,\n\t\tclassName,\n\t\tisSelected,\n\t\tonReplace,\n\t\tmergeBlocks,\n\t} = props;\n\tconst {\n\t\tlinkTarget,\n\t\tplaceholder,\n\t\trel,\n\t\tstyle,\n\t\ttext,\n\t\turl,\n\t\twidth,\n\t} = attributes;\n\tconst onSetLinkRel = useCallback(\n\t\t( value ) => {\n\t\t\tsetAttributes( { rel: value } );\n\t\t},\n\t\t[ setAttributes ]\n\t);\n\n\tconst onToggleOpenInNewTab = useCallback(\n\t\t( value ) => {\n\t\t\tconst newLinkTarget = value ? '_blank' : undefined;\n\n\t\t\tlet updatedRel = rel;\n\t\t\tif ( newLinkTarget && ! rel ) {\n\t\t\t\tupdatedRel = NEW_TAB_REL;\n\t\t\t} else if ( ! newLinkTarget && rel === NEW_TAB_REL ) {\n\t\t\t\tupdatedRel = undefined;\n\t\t\t}\n\n\t\t\tsetAttributes( {\n\t\t\t\tlinkTarget: newLinkTarget,\n\t\t\t\trel: updatedRel,\n\t\t\t} );\n\t\t},\n\t\t[ rel, setAttributes ]\n\t);\n\n\tconst setButtonText = ( newText ) => {\n\t\t// Remove anchor tags from button text content.\n\t\tsetAttributes( { text: newText.replace( /<\\/?a[^>]*>/g, '' ) } );\n\t};\n\n\tconst borderRadius = style?.border?.radius;\n\tconst colorProps = useColorProps( attributes );\n\tconst ref = useRef();\n\tconst blockProps = useBlockProps( { ref } );\n\n\treturn (\n\t\t<>\n\t\t\t<div\n\t\t\t\t{ ...blockProps }\n\t\t\t\tclassName={ classnames( blockProps.className, {\n\t\t\t\t\t[ `has-custom-width wp-block-button__width-${ width }` ]: width,\n\t\t\t\t\t[ `has-custom-font-size` ]: blockProps.style.fontSize,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<RichText\n\t\t\t\t\taria-label={ __( 'Button text' ) }\n\t\t\t\t\tplaceholder={ placeholder || __( 'Add text…' ) }\n\t\t\t\t\tvalue={ text }\n\t\t\t\t\tonChange={ ( value ) => setButtonText( value ) }\n\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\tclassName,\n\t\t\t\t\t\t'wp-block-button__link',\n\t\t\t\t\t\tcolorProps.className,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'no-border-radius': borderRadius === 0,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tborderRadius: borderRadius\n\t\t\t\t\t\t\t? borderRadius + 'px'\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t...colorProps.style,\n\t\t\t\t\t} }\n\t\t\t\t\tonSplit={ ( value ) =>\n\t\t\t\t\t\tcreateBlock( 'core/button', {\n\t\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t\ttext: value,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\tidentifier=\"text\"\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<URLPicker\n\t\t\t\turl={ url }\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\tisSelected={ isSelected }\n\t\t\t\topensInNewTab={ linkTarget === '_blank' }\n\t\t\t\tonToggleOpenInNewTab={ onToggleOpenInNewTab }\n\t\t\t\tanchorRef={ ref }\n\t\t\t/>\n\t\t\t<InspectorControls>\n\t\t\t\t<WidthPanel\n\t\t\t\t\tselectedWidth={ width }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<InspectorAdvancedControls>\n\t\t\t\t<TextControl\n\t\t\t\t\tlabel={ __( 'Link rel' ) }\n\t\t\t\t\tvalue={ rel || '' }\n\t\t\t\t\tonChange={ onSetLinkRel }\n\t\t\t\t/>\n\t\t\t</InspectorAdvancedControls>\n\t\t</>\n\t);\n}\n\nexport default ButtonEdit;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/button/edit.js"],"names":["classnames","__","useCallback","useEffect","useState","useRef","Button","ButtonGroup","KeyboardShortcuts","PanelBody","TextControl","ToolbarButton","Popover","BlockControls","InspectorControls","InspectorAdvancedControls","RichText","useBlockProps","__experimentalUseColorProps","useColorProps","__experimentalLinkControl","LinkControl","rawShortcut","displayShortcut","link","linkOff","createBlock","NEW_TAB_REL","WidthPanel","selectedWidth","setAttributes","handleChange","newWidth","width","undefined","map","widthValue","URLPicker","isSelected","url","opensInNewTab","onToggleOpenInNewTab","anchorRef","richTextRef","isEditingURL","setIsEditingURL","isURLSet","startEditing","event","preventDefault","unlink","linkTarget","rel","isLinkControlVisible","linkControl","current","focus","newURL","newOpensInNewTab","primary","primaryShift","ButtonEdit","props","attributes","className","onReplace","mergeBlocks","placeholder","style","text","onSetLinkRel","value","newLinkTarget","updatedRel","setButtonText","newText","replace","borderRadius","border","radius","colorProps","ref","blockProps","fontSize"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,WAAT,EAAsBC,SAAtB,EAAiCC,QAAjC,EAA2CC,MAA3C,QAAyD,oBAAzD;AACA,SACCC,MADD,EAECC,WAFD,EAG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C,SAHI;AAIP,SAAG8C,UAAU,CAACZ;AAJP,KAfT;AAqBC,IAAA,OAAO,EAAKG,KAAF,IACT7C,WAAW,CAAE,aAAF,EAAiB,EAC3B,GAAGqC,UADwB;AAE3BM,MAAAA,IAAI,EAAEE;AAFqB,KAAjB,CAtBb;AA2BC,IAAA,SAAS,EAAGN,SA3Bb;AA4BC,IAAA,OAAO,EAAGC,WA5BX;AA6BC,IAAA,UAAU,EAAC;AA7BZ,IAPD,CADD,EAwCC,cAAC,SAAD;AACC,IAAA,GAAG,EAAG3B,GADP;AAEC,IAAA,aAAa,EAAGT,aAFjB;AAGC,IAAA,UAAU,EAAGQ,UAHd;AAIC,IAAA,aAAa,EAAGa,UAAU,KAAK,QAJhC;AAKC,IAAA,oBAAoB,EAAGV,oBALxB;AAMC,IAAA,SAAS,EAAGwC,GANb;AAOC,IAAA,WAAW,EAAGtC;AAPf,IAxCD,EAiDC,cAAC,iBAAD,QACC,cAAC,UAAD;AACC,IAAA,aAAa,EAAGV,KADjB;AAEC,IAAA,aAAa,EAAGH;AAFjB,IADD,CAjDD,EAuDC,cAAC,yBAAD,QACC,cAAC,WAAD;AACC,IAAA,KAAK,EAAG7B,EAAE,CAAE,UAAF,CADX;AAEC,IAAA,KAAK,EAAGmD,GAAG,IAAI,EAFhB;AAGC,IAAA,QAAQ,EAAGkB;AAHZ,IADD,CAvDD,CADD;AAiEA;;AAED,eAAeT,UAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useEffect, useState, useRef } from '@wordpress/element';\nimport {\n\tButton,\n\tButtonGroup,\n\tKeyboardShortcuts,\n\tPanelBody,\n\tTextControl,\n\tToolbarButton,\n\tPopover,\n} from '@wordpress/components';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tInspectorAdvancedControls,\n\tRichText,\n\tuseBlockProps,\n\t__experimentalUseColorProps as useColorProps,\n\t__experimentalLinkControl as LinkControl,\n} from '@wordpress/block-editor';\nimport { rawShortcut, displayShortcut } from '@wordpress/keycodes';\nimport { link, linkOff } from '@wordpress/icons';\nimport { createBlock } from '@wordpress/blocks';\n\nconst NEW_TAB_REL = 'noreferrer noopener';\n\nfunction WidthPanel( { selectedWidth, setAttributes } ) {\n\tfunction handleChange( newWidth ) {\n\t\t// Check if we are toggling the width off\n\t\tconst width = selectedWidth === newWidth ? undefined : newWidth;\n\n\t\t// Update attributes\n\t\tsetAttributes( { width } );\n\t}\n\n\treturn (\n\t\t<PanelBody title={ __( 'Width settings' ) }>\n\t\t\t<ButtonGroup aria-label={ __( 'Button width' ) }>\n\t\t\t\t{ [ 25, 50, 75, 100 ].map( ( widthValue ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tkey={ widthValue }\n\t\t\t\t\t\t\tisSmall\n\t\t\t\t\t\t\tisPrimary={ widthValue === selectedWidth }\n\t\t\t\t\t\t\tonClick={ () => handleChange( widthValue ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ widthValue }%\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</ButtonGroup>\n\t\t</PanelBody>\n\t);\n}\n\nfunction URLPicker( {\n\tisSelected,\n\turl,\n\tsetAttributes,\n\topensInNewTab,\n\tonToggleOpenInNewTab,\n\tanchorRef,\n\trichTextRef,\n} ) {\n\tconst [ isEditingURL, setIsEditingURL ] = useState( false );\n\tconst isURLSet = !! url;\n\n\tconst startEditing = ( event ) => {\n\t\tevent.preventDefault();\n\t\tsetIsEditingURL( true );\n\t};\n\n\tconst unlink = () => {\n\t\tsetAttributes( {\n\t\t\turl: undefined,\n\t\t\tlinkTarget: undefined,\n\t\t\trel: undefined,\n\t\t} );\n\t\tsetIsEditingURL( false );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! isSelected ) {\n\t\t\tsetIsEditingURL( false );\n\t\t}\n\t}, [ isSelected ] );\n\n\tconst isLinkControlVisible = isSelected && ( isEditingURL || isURLSet );\n\n\tconst linkControl = isLinkControlVisible && (\n\t\t<Popover\n\t\t\tposition=\"bottom center\"\n\t\t\tonClose={ () => {\n\t\t\t\tsetIsEditingURL( false );\n\t\t\t\trichTextRef.current?.focus();\n\t\t\t} }\n\t\t\tanchorRef={ anchorRef?.current }\n\t\t\tfocusOnMount={ isEditingURL ? 'firstElement' : false }\n\t\t>\n\t\t\t<LinkControl\n\t\t\t\tclassName=\"wp-block-navigation-link__inline-link-input\"\n\t\t\t\tvalue={ { url, opensInNewTab } }\n\t\t\t\tonChange={ ( {\n\t\t\t\t\turl: newURL = '',\n\t\t\t\t\topensInNewTab: newOpensInNewTab,\n\t\t\t\t} ) => {\n\t\t\t\t\tsetAttributes( { url: newURL } );\n\n\t\t\t\t\tif ( opensInNewTab !== newOpensInNewTab ) {\n\t\t\t\t\t\tonToggleOpenInNewTab( newOpensInNewTab );\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tonRemove={ () => {\n\t\t\t\t\tunlink();\n\t\t\t\t\trichTextRef.current?.focus();\n\t\t\t\t} }\n\t\t\t\tforceIsEditingLink={ isEditingURL }\n\t\t\t/>\n\t\t</Popover>\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t{ ! isURLSet && (\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\ticon={ link }\n\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\tshortcut={ displayShortcut.primary( 'k' ) }\n\t\t\t\t\t\tonClick={ startEditing }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ isURLSet && (\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\ticon={ linkOff }\n\t\t\t\t\t\ttitle={ __( 'Unlink' ) }\n\t\t\t\t\t\tshortcut={ displayShortcut.primaryShift( 'k' ) }\n\t\t\t\t\t\tonClick={ unlink }\n\t\t\t\t\t\tisActive={ true }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</BlockControls>\n\t\t\t{ isSelected && (\n\t\t\t\t<KeyboardShortcuts\n\t\t\t\t\tbindGlobal\n\t\t\t\t\tshortcuts={ {\n\t\t\t\t\t\t[ rawShortcut.primary( 'k' ) ]: startEditing,\n\t\t\t\t\t\t[ rawShortcut.primaryShift( 'k' ) ]: () => {\n\t\t\t\t\t\t\tunlink();\n\t\t\t\t\t\t\trichTextRef.current?.focus();\n\t\t\t\t\t\t},\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ linkControl }\n\t\t</>\n\t);\n}\n\nfunction ButtonEdit( props ) {\n\tconst {\n\t\tattributes,\n\t\tsetAttributes,\n\t\tclassName,\n\t\tisSelected,\n\t\tonReplace,\n\t\tmergeBlocks,\n\t} = props;\n\tconst {\n\t\tlinkTarget,\n\t\tplaceholder,\n\t\trel,\n\t\tstyle,\n\t\ttext,\n\t\turl,\n\t\twidth,\n\t} = attributes;\n\tconst onSetLinkRel = useCallback(\n\t\t( value ) => {\n\t\t\tsetAttributes( { rel: value } );\n\t\t},\n\t\t[ setAttributes ]\n\t);\n\n\tconst onToggleOpenInNewTab = useCallback(\n\t\t( value ) => {\n\t\t\tconst newLinkTarget = value ? '_blank' : undefined;\n\n\t\t\tlet updatedRel = rel;\n\t\t\tif ( newLinkTarget && ! rel ) {\n\t\t\t\tupdatedRel = NEW_TAB_REL;\n\t\t\t} else if ( ! newLinkTarget && rel === NEW_TAB_REL ) {\n\t\t\t\tupdatedRel = undefined;\n\t\t\t}\n\n\t\t\tsetAttributes( {\n\t\t\t\tlinkTarget: newLinkTarget,\n\t\t\t\trel: updatedRel,\n\t\t\t} );\n\t\t},\n\t\t[ rel, setAttributes ]\n\t);\n\n\tconst setButtonText = ( newText ) => {\n\t\t// Remove anchor tags from button text content.\n\t\tsetAttributes( { text: newText.replace( /<\\/?a[^>]*>/g, '' ) } );\n\t};\n\n\tconst borderRadius = style?.border?.radius;\n\tconst colorProps = useColorProps( attributes );\n\tconst ref = useRef();\n\tconst richTextRef = useRef();\n\tconst blockProps = useBlockProps( { ref } );\n\n\treturn (\n\t\t<>\n\t\t\t<div\n\t\t\t\t{ ...blockProps }\n\t\t\t\tclassName={ classnames( blockProps.className, {\n\t\t\t\t\t[ `has-custom-width wp-block-button__width-${ width }` ]: width,\n\t\t\t\t\t[ `has-custom-font-size` ]: blockProps.style.fontSize,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<RichText\n\t\t\t\t\tref={ richTextRef }\n\t\t\t\t\taria-label={ __( 'Button text' ) }\n\t\t\t\t\tplaceholder={ placeholder || __( 'Add text…' ) }\n\t\t\t\t\tvalue={ text }\n\t\t\t\t\tonChange={ ( value ) => setButtonText( value ) }\n\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\tclassName,\n\t\t\t\t\t\t'wp-block-button__link',\n\t\t\t\t\t\tcolorProps.className,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'no-border-radius': borderRadius === 0,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tborderRadius: borderRadius\n\t\t\t\t\t\t\t? borderRadius + 'px'\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t...colorProps.style,\n\t\t\t\t\t} }\n\t\t\t\t\tonSplit={ ( value ) =>\n\t\t\t\t\t\tcreateBlock( 'core/button', {\n\t\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t\ttext: value,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\tidentifier=\"text\"\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<URLPicker\n\t\t\t\turl={ url }\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\tisSelected={ isSelected }\n\t\t\t\topensInNewTab={ linkTarget === '_blank' }\n\t\t\t\tonToggleOpenInNewTab={ onToggleOpenInNewTab }\n\t\t\t\tanchorRef={ ref }\n\t\t\t\trichTextRef={ richTextRef }\n\t\t\t/>\n\t\t\t<InspectorControls>\n\t\t\t\t<WidthPanel\n\t\t\t\t\tselectedWidth={ width }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<InspectorAdvancedControls>\n\t\t\t\t<TextControl\n\t\t\t\t\tlabel={ __( 'Link rel' ) }\n\t\t\t\t\tvalue={ rel || '' }\n\t\t\t\t\tonChange={ onSetLinkRel }\n\t\t\t\t/>\n\t\t\t</InspectorAdvancedControls>\n\t\t</>\n\t);\n}\n\nexport default ButtonEdit;\n"]}
|
|
@@ -11,34 +11,16 @@ import classnames from 'classnames';
|
|
|
11
11
|
import { useEntityProp } from '@wordpress/core-data';
|
|
12
12
|
import { useMemo, RawHTML } from '@wordpress/element';
|
|
13
13
|
import { AlignmentToolbar, BlockControls, InspectorControls, RichText, Warning, useBlockProps } from '@wordpress/block-editor';
|
|
14
|
-
import { PanelBody,
|
|
14
|
+
import { PanelBody, ToggleControl, Disabled } from '@wordpress/components';
|
|
15
15
|
import { __ } from '@wordpress/i18n';
|
|
16
16
|
/**
|
|
17
17
|
* Internal dependencies
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import { useCanEditEntity } from '../utils/hooks';
|
|
21
|
-
|
|
22
|
-
function usePostContentExcerpt(wordCount, postId, postType) {
|
|
23
|
-
// Don't destrcuture items from content here, it can be undefined.
|
|
24
|
-
const [,, content] = useEntityProp('postType', postType, 'content', postId);
|
|
25
|
-
const renderedPostContent = content === null || content === void 0 ? void 0 : content.rendered;
|
|
26
|
-
return useMemo(() => {
|
|
27
|
-
if (!renderedPostContent) {
|
|
28
|
-
return '';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const excerptElement = document.createElement('div');
|
|
32
|
-
excerptElement.innerHTML = renderedPostContent;
|
|
33
|
-
const excerpt = excerptElement.textContent || excerptElement.innerText || '';
|
|
34
|
-
return excerpt.trim().split(' ', wordCount).join(' ');
|
|
35
|
-
}, [renderedPostContent, wordCount]);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
21
|
export default function PostExcerptEditor({
|
|
39
22
|
attributes: {
|
|
40
23
|
textAlign,
|
|
41
|
-
wordCount,
|
|
42
24
|
moreText,
|
|
43
25
|
showMoreOnNewLine
|
|
44
26
|
},
|
|
@@ -57,12 +39,22 @@ export default function PostExcerptEditor({
|
|
|
57
39
|
rendered: renderedExcerpt,
|
|
58
40
|
protected: isProtected
|
|
59
41
|
} = {}] = useEntityProp('postType', postType, 'excerpt', postId);
|
|
60
|
-
const postContentExcerpt = usePostContentExcerpt(wordCount, postId, postType);
|
|
61
42
|
const blockProps = useBlockProps({
|
|
62
43
|
className: classnames({
|
|
63
44
|
[`has-text-align-${textAlign}`]: textAlign
|
|
64
45
|
})
|
|
65
46
|
});
|
|
47
|
+
/**
|
|
48
|
+
* When excerpt is editable, strip the html tags from
|
|
49
|
+
* rendered excerpt. This will be used if the entity's
|
|
50
|
+
* excerpt has been produced from the content.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
const strippedRenderedExcerpt = useMemo(() => {
|
|
54
|
+
if (!renderedExcerpt) return '';
|
|
55
|
+
const document = new window.DOMParser().parseFromString(renderedExcerpt, 'text/html');
|
|
56
|
+
return document.body.textContent || document.body.innerText || '';
|
|
57
|
+
}, [renderedExcerpt]);
|
|
66
58
|
|
|
67
59
|
if (!postType || !postId) {
|
|
68
60
|
return createElement("div", blockProps, createElement(Warning, null, __('Post excerpt block: no post found.')));
|
|
@@ -85,11 +77,11 @@ export default function PostExcerptEditor({
|
|
|
85
77
|
const excerptContent = isEditable ? createElement(RichText, {
|
|
86
78
|
className: !showMoreOnNewLine && 'wp-block-post-excerpt__excerpt is-inline',
|
|
87
79
|
"aria-label": __('Post excerpt text'),
|
|
88
|
-
value: rawExcerpt ||
|
|
80
|
+
value: rawExcerpt || strippedRenderedExcerpt || (isSelected ? '' : __('No post excerpt found')),
|
|
89
81
|
onChange: setExcerpt
|
|
90
|
-
}) : renderedExcerpt && createElement(RawHTML, {
|
|
82
|
+
}) : renderedExcerpt && createElement(Disabled, null, createElement(RawHTML, {
|
|
91
83
|
key: "html"
|
|
92
|
-
}, renderedExcerpt) ||
|
|
84
|
+
}, renderedExcerpt)) || __('No post excerpt found');
|
|
93
85
|
return createElement(Fragment, null, createElement(BlockControls, null, createElement(AlignmentToolbar, {
|
|
94
86
|
value: textAlign,
|
|
95
87
|
onChange: newAlign => setAttributes({
|
|
@@ -97,15 +89,7 @@ export default function PostExcerptEditor({
|
|
|
97
89
|
})
|
|
98
90
|
})), createElement(InspectorControls, null, createElement(PanelBody, {
|
|
99
91
|
title: __('Post Excerpt Settings')
|
|
100
|
-
},
|
|
101
|
-
label: __('Max words'),
|
|
102
|
-
value: wordCount,
|
|
103
|
-
onChange: newExcerptLength => setAttributes({
|
|
104
|
-
wordCount: newExcerptLength
|
|
105
|
-
}),
|
|
106
|
-
min: 10,
|
|
107
|
-
max: 100
|
|
108
|
-
}), createElement(ToggleControl, {
|
|
92
|
+
}, createElement(ToggleControl, {
|
|
109
93
|
label: __('Show link on new line'),
|
|
110
94
|
checked: showMoreOnNewLine,
|
|
111
95
|
onChange: newShowMoreOnNewLine => setAttributes({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/post-excerpt/edit.js"],"names":["classnames","useEntityProp","useMemo","RawHTML","AlignmentToolbar","BlockControls","InspectorControls","RichText","Warning","useBlockProps","PanelBody","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/post-excerpt/edit.js"],"names":["classnames","useEntityProp","useMemo","RawHTML","AlignmentToolbar","BlockControls","InspectorControls","RichText","Warning","useBlockProps","PanelBody","ToggleControl","Disabled","__","useCanEditEntity","PostExcerptEditor","attributes","textAlign","moreText","showMoreOnNewLine","setAttributes","isSelected","context","postId","postType","queryId","isDescendentOfQueryLoop","userCanEdit","isEditable","rawExcerpt","setExcerpt","rendered","renderedExcerpt","protected","isProtected","blockProps","className","strippedRenderedExcerpt","document","window","DOMParser","parseFromString","body","textContent","innerText","readMoreLink","newMoreText","excerptContent","newAlign","newShowMoreOnNewLine"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,aAAT,QAA8B,sBAA9B;AACA,SAASC,OAAT,EAAkBC,OAAlB,QAAiC,oBAAjC;AACA,SACCC,gBADD,EAECC,aAFD,EAGCC,iBAHD,EAICC,QAJD,EAKCC,OALD,EAMCC,aAND,QAOO,yBAPP;AAQA,SAASC,SAAT,EAAoBC,aAApB,EAAmCC,QAAnC,QAAmD,uBAAnD;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,QAAiC,gBAAjC;AAEA,eAAe,SAASC,iBAAT,CAA4B;AAC1CC,EAAAA,UAAU,EAAE;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,QAAb;AAAuBC,IAAAA;AAAvB,GAD8B;AAE1CC,EAAAA,aAF0C;AAG1CC,EAAAA,UAH0C;AAI1CC,EAAAA,OAAO,EAAE;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,QAAV;AAAoBC,IAAAA;AAApB;AAJiC,CAA5B,EAKX;AACH,QAAMC,uBAAuB,GAAG,CAAC,CAAED,OAAnC;AACA,QAAME,WAAW,GAAGb,gBAAgB,CAAE,UAAF,EAAcU,QAAd,EAAwBD,MAAxB,CAApC;AACA,QAAMK,UAAU,GAAGD,WAAW,IAAI,CAAED,uBAApC;AACA,QAAM,CACLG,UADK,EAELC,UAFK,EAGL;AAAEC,IAAAA,QAAQ,EAAEC,eAAZ;AAA6BC,IAAAA,SAAS,EAAEC;AAAx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,QAAMC,cAAc,GAAGnB,UAAU,GAChC,cAAC,QAAD;AACC,IAAA,SAAS,EACR,CAAET,iBAAF,IACA,0CAHF;AAKC,kBAAaN,EAAE,CAAE,mBAAF,CALhB;AAMC,IAAA,KAAK,EACJgB,UAAU,IACVQ,uBADA,KAEEhB,UAAU,GAAG,EAAH,GAAQR,EAAE,CAAE,uBAAF,CAFtB,CAPF;AAWC,IAAA,QAAQ,EAAGiB;AAXZ,IADgC,GAe9BE,eAAe,IAChB,cAAC,QAAD,QACC,cAAC,OAAD;AAAS,IAAA,GAAG,EAAC;AAAb,KAAsBA,eAAtB,CADD,CADD,IAKAnB,EAAE,CAAE,uBAAF,CApBH;AAsBA,SACC,8BACC,cAAC,aAAD,QACC,cAAC,gBAAD;AACC,IAAA,KAAK,EAAGI,SADT;AAEC,IAAA,QAAQ,EAAK+B,QAAF,IACV5B,aAAa,CAAE;AAAEH,MAAAA,SAAS,EAAE+B;AAAb,KAAF;AAHf,IADD,CADD,EASC,cAAC,iBAAD,QACC,cAAC,SAAD;AAAW,IAAA,KAAK,EAAGnC,EAAE,CAAE,uBAAF;AAArB,KACC,cAAC,aAAD;AACC,IAAA,KAAK,EAAGA,EAAE,CAAE,uBAAF,CADX;AAEC,IAAA,OAAO,EAAGM,iBAFX;AAGC,IAAA,QAAQ,EAAK8B,oBAAF,IACV7B,aAAa,CAAE;AACdD,MAAAA,iBAAiB,EAAE8B;AADL,KAAF;AAJf,IADD,CADD,CATD,EAsBC,qBAAUd,UAAV,EACGY,cADH,EAEG,CAAE5B,iBAAF,IAAuB,GAF1B,EAGGA,iBAAiB,GAClB;AAAG,IAAA,SAAS,EAAC;AAAb,KACG0B,YADH,CADkB,GAKlBA,YARF,CAtBD,CADD;AAoCA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useEntityProp } from '@wordpress/core-data';\nimport { useMemo, RawHTML } from '@wordpress/element';\nimport {\n\tAlignmentToolbar,\n\tBlockControls,\n\tInspectorControls,\n\tRichText,\n\tWarning,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { PanelBody, ToggleControl, Disabled } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useCanEditEntity } from '../utils/hooks';\n\nexport default function PostExcerptEditor( {\n\tattributes: { textAlign, moreText, showMoreOnNewLine },\n\tsetAttributes,\n\tisSelected,\n\tcontext: { postId, postType, queryId },\n} ) {\n\tconst isDescendentOfQueryLoop = !! queryId;\n\tconst userCanEdit = useCanEditEntity( 'postType', postType, postId );\n\tconst isEditable = userCanEdit && ! isDescendentOfQueryLoop;\n\tconst [\n\t\trawExcerpt,\n\t\tsetExcerpt,\n\t\t{ rendered: renderedExcerpt, protected: isProtected } = {},\n\t] = useEntityProp( 'postType', postType, 'excerpt', postId );\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t} );\n\t/**\n\t * When excerpt is editable, strip the html tags from\n\t * rendered excerpt. This will be used if the entity's\n\t * excerpt has been produced from the content.\n\t */\n\tconst strippedRenderedExcerpt = useMemo( () => {\n\t\tif ( ! renderedExcerpt ) return '';\n\t\tconst document = new window.DOMParser().parseFromString(\n\t\t\trenderedExcerpt,\n\t\t\t'text/html'\n\t\t);\n\t\treturn document.body.textContent || document.body.innerText || '';\n\t}, [ renderedExcerpt ] );\n\tif ( ! postType || ! postId ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Warning>\n\t\t\t\t\t{ __( 'Post excerpt block: no post found.' ) }\n\t\t\t\t</Warning>\n\t\t\t</div>\n\t\t);\n\t}\n\tif ( isProtected && ! userCanEdit ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Warning>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'There is no excerpt because this is a protected post.'\n\t\t\t\t\t) }\n\t\t\t\t</Warning>\n\t\t\t</div>\n\t\t);\n\t}\n\tconst readMoreLink = (\n\t\t<RichText\n\t\t\tclassName=\"wp-block-post-excerpt__more-link\"\n\t\t\ttagName=\"a\"\n\t\t\taria-label={ __( '\"Read more\" link text' ) }\n\t\t\tplaceholder={ __( 'Add \"read more\" link text' ) }\n\t\t\tvalue={ moreText }\n\t\t\tonChange={ ( newMoreText ) =>\n\t\t\t\tsetAttributes( { moreText: newMoreText } )\n\t\t\t}\n\t\t/>\n\t);\n\tconst excerptContent = isEditable ? (\n\t\t<RichText\n\t\t\tclassName={\n\t\t\t\t! showMoreOnNewLine &&\n\t\t\t\t'wp-block-post-excerpt__excerpt is-inline'\n\t\t\t}\n\t\t\taria-label={ __( 'Post excerpt text' ) }\n\t\t\tvalue={\n\t\t\t\trawExcerpt ||\n\t\t\t\tstrippedRenderedExcerpt ||\n\t\t\t\t( isSelected ? '' : __( 'No post excerpt found' ) )\n\t\t\t}\n\t\t\tonChange={ setExcerpt }\n\t\t/>\n\t) : (\n\t\t( renderedExcerpt && (\n\t\t\t<Disabled>\n\t\t\t\t<RawHTML key=\"html\">{ renderedExcerpt }</RawHTML>\n\t\t\t</Disabled>\n\t\t) ) ||\n\t\t__( 'No post excerpt found' )\n\t);\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<AlignmentToolbar\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( newAlign ) =>\n\t\t\t\t\t\tsetAttributes( { textAlign: newAlign } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Post Excerpt Settings' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show link on new line' ) }\n\t\t\t\t\t\tchecked={ showMoreOnNewLine }\n\t\t\t\t\t\tonChange={ ( newShowMoreOnNewLine ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowMoreOnNewLine: newShowMoreOnNewLine,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ excerptContent }\n\t\t\t\t{ ! showMoreOnNewLine && ' ' }\n\t\t\t\t{ showMoreOnNewLine ? (\n\t\t\t\t\t<p className=\"wp-block-post-excerpt__more-text\">\n\t\t\t\t\t\t{ readMoreLink }\n\t\t\t\t\t</p>\n\t\t\t\t) : (\n\t\t\t\t\treadMoreLink\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/post-excerpt/index.js"],"names":["postExcerpt","icon","edit","name","metadata","settings"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,IAAIC,IAAxB,QAAoC,kBAApC;AAEA;AACA;AACA
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/post-excerpt/index.js"],"names":["postExcerpt","icon","edit","name","metadata","settings"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,IAAIC,IAAxB,QAAoC,kBAApC;AAEA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAOC,IAAP,MAAiB,QAAjB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAWC,QAAjB;AACA,SAASA,QAAT,EAAmBD,IAAnB;AAEA,OAAO,MAAME,QAAQ,GAAG;AACvBJ,EAAAA,IADuB;AAEvBC,EAAAA;AAFuB,CAAjB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { postExcerpt as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/block-library",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.20",
|
|
4
4
|
"description": "Block library for the WordPress editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -33,33 +33,33 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/runtime": "^7.13.10",
|
|
36
|
-
"@wordpress/a11y": "^3.1.
|
|
37
|
-
"@wordpress/api-fetch": "^5.1.
|
|
38
|
-
"@wordpress/autop": "^3.1.
|
|
39
|
-
"@wordpress/blob": "^3.1.
|
|
40
|
-
"@wordpress/block-editor": "^6.1.
|
|
41
|
-
"@wordpress/blocks": "^9.1.
|
|
42
|
-
"@wordpress/components": "^14.1.
|
|
43
|
-
"@wordpress/compose": "^4.1.
|
|
44
|
-
"@wordpress/core-data": "^3.1.
|
|
45
|
-
"@wordpress/data": "^5.1.
|
|
46
|
-
"@wordpress/date": "^4.1.
|
|
47
|
-
"@wordpress/deprecated": "^3.1.
|
|
48
|
-
"@wordpress/dom": "^3.1.
|
|
49
|
-
"@wordpress/element": "^3.1.
|
|
50
|
-
"@wordpress/escape-html": "^2.1.
|
|
36
|
+
"@wordpress/a11y": "^3.1.2",
|
|
37
|
+
"@wordpress/api-fetch": "^5.1.3",
|
|
38
|
+
"@wordpress/autop": "^3.1.2",
|
|
39
|
+
"@wordpress/blob": "^3.1.2",
|
|
40
|
+
"@wordpress/block-editor": "^6.1.15",
|
|
41
|
+
"@wordpress/blocks": "^9.1.8",
|
|
42
|
+
"@wordpress/components": "^14.1.11",
|
|
43
|
+
"@wordpress/compose": "^4.1.6",
|
|
44
|
+
"@wordpress/core-data": "^3.1.13",
|
|
45
|
+
"@wordpress/data": "^5.1.6",
|
|
46
|
+
"@wordpress/date": "^4.1.2",
|
|
47
|
+
"@wordpress/deprecated": "^3.1.2",
|
|
48
|
+
"@wordpress/dom": "^3.1.5",
|
|
49
|
+
"@wordpress/element": "^3.1.2",
|
|
50
|
+
"@wordpress/escape-html": "^2.1.2",
|
|
51
51
|
"@wordpress/hooks": "^3.1.1",
|
|
52
|
-
"@wordpress/i18n": "^4.1.
|
|
53
|
-
"@wordpress/icons": "^4.0.
|
|
52
|
+
"@wordpress/i18n": "^4.1.2",
|
|
53
|
+
"@wordpress/icons": "^4.0.3",
|
|
54
54
|
"@wordpress/is-shallow-equal": "^4.1.1",
|
|
55
|
-
"@wordpress/keycodes": "^3.1.
|
|
56
|
-
"@wordpress/notices": "^3.1.
|
|
57
|
-
"@wordpress/primitives": "^2.1.
|
|
58
|
-
"@wordpress/reusable-blocks": "^2.1.
|
|
59
|
-
"@wordpress/rich-text": "^4.1.
|
|
60
|
-
"@wordpress/server-side-render": "^2.1.
|
|
61
|
-
"@wordpress/url": "^3.1.
|
|
62
|
-
"@wordpress/viewport": "^3.1.
|
|
55
|
+
"@wordpress/keycodes": "^3.1.2",
|
|
56
|
+
"@wordpress/notices": "^3.1.6",
|
|
57
|
+
"@wordpress/primitives": "^2.1.2",
|
|
58
|
+
"@wordpress/reusable-blocks": "^2.1.18",
|
|
59
|
+
"@wordpress/rich-text": "^4.1.6",
|
|
60
|
+
"@wordpress/server-side-render": "^2.1.13",
|
|
61
|
+
"@wordpress/url": "^3.1.3",
|
|
62
|
+
"@wordpress/viewport": "^3.1.6",
|
|
63
63
|
"classnames": "^2.2.5",
|
|
64
64
|
"fast-average-color": "4.3.0",
|
|
65
65
|
"lodash": "^4.17.21",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"publishConfig": {
|
|
73
73
|
"access": "public"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "6464883c6c546233543a1ee01428059dee3560fc"
|
|
76
76
|
}
|
package/src/button/edit.js
CHANGED
|
@@ -7,7 +7,7 @@ import classnames from 'classnames';
|
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { __ } from '@wordpress/i18n';
|
|
10
|
-
import { useCallback, useState, useRef } from '@wordpress/element';
|
|
10
|
+
import { useCallback, useEffect, useState, useRef } from '@wordpress/element';
|
|
11
11
|
import {
|
|
12
12
|
Button,
|
|
13
13
|
ButtonGroup,
|
|
@@ -68,27 +68,42 @@ function URLPicker( {
|
|
|
68
68
|
opensInNewTab,
|
|
69
69
|
onToggleOpenInNewTab,
|
|
70
70
|
anchorRef,
|
|
71
|
+
richTextRef,
|
|
71
72
|
} ) {
|
|
72
|
-
const [
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
const [ isEditingURL, setIsEditingURL ] = useState( false );
|
|
74
|
+
const isURLSet = !! url;
|
|
75
|
+
|
|
76
|
+
const startEditing = ( event ) => {
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
setIsEditingURL( true );
|
|
78
79
|
};
|
|
79
|
-
|
|
80
|
+
|
|
81
|
+
const unlink = () => {
|
|
80
82
|
setAttributes( {
|
|
81
83
|
url: undefined,
|
|
82
84
|
linkTarget: undefined,
|
|
83
85
|
rel: undefined,
|
|
84
86
|
} );
|
|
85
|
-
|
|
87
|
+
setIsEditingURL( false );
|
|
86
88
|
};
|
|
87
|
-
|
|
89
|
+
|
|
90
|
+
useEffect( () => {
|
|
91
|
+
if ( ! isSelected ) {
|
|
92
|
+
setIsEditingURL( false );
|
|
93
|
+
}
|
|
94
|
+
}, [ isSelected ] );
|
|
95
|
+
|
|
96
|
+
const isLinkControlVisible = isSelected && ( isEditingURL || isURLSet );
|
|
97
|
+
|
|
98
|
+
const linkControl = isLinkControlVisible && (
|
|
88
99
|
<Popover
|
|
89
100
|
position="bottom center"
|
|
90
|
-
onClose={ () =>
|
|
101
|
+
onClose={ () => {
|
|
102
|
+
setIsEditingURL( false );
|
|
103
|
+
richTextRef.current?.focus();
|
|
104
|
+
} }
|
|
91
105
|
anchorRef={ anchorRef?.current }
|
|
106
|
+
focusOnMount={ isEditingURL ? 'firstElement' : false }
|
|
92
107
|
>
|
|
93
108
|
<LinkControl
|
|
94
109
|
className="wp-block-navigation-link__inline-link-input"
|
|
@@ -103,28 +118,34 @@ function URLPicker( {
|
|
|
103
118
|
onToggleOpenInNewTab( newOpensInNewTab );
|
|
104
119
|
}
|
|
105
120
|
} }
|
|
121
|
+
onRemove={ () => {
|
|
122
|
+
unlink();
|
|
123
|
+
richTextRef.current?.focus();
|
|
124
|
+
} }
|
|
125
|
+
forceIsEditingLink={ isEditingURL }
|
|
106
126
|
/>
|
|
107
127
|
</Popover>
|
|
108
128
|
);
|
|
129
|
+
|
|
109
130
|
return (
|
|
110
131
|
<>
|
|
111
132
|
<BlockControls group="block">
|
|
112
|
-
{ !
|
|
133
|
+
{ ! isURLSet && (
|
|
113
134
|
<ToolbarButton
|
|
114
135
|
name="link"
|
|
115
136
|
icon={ link }
|
|
116
137
|
title={ __( 'Link' ) }
|
|
117
138
|
shortcut={ displayShortcut.primary( 'k' ) }
|
|
118
|
-
onClick={
|
|
139
|
+
onClick={ startEditing }
|
|
119
140
|
/>
|
|
120
141
|
) }
|
|
121
|
-
{
|
|
142
|
+
{ isURLSet && (
|
|
122
143
|
<ToolbarButton
|
|
123
144
|
name="link"
|
|
124
145
|
icon={ linkOff }
|
|
125
146
|
title={ __( 'Unlink' ) }
|
|
126
147
|
shortcut={ displayShortcut.primaryShift( 'k' ) }
|
|
127
|
-
onClick={
|
|
148
|
+
onClick={ unlink }
|
|
128
149
|
isActive={ true }
|
|
129
150
|
/>
|
|
130
151
|
) }
|
|
@@ -133,8 +154,11 @@ function URLPicker( {
|
|
|
133
154
|
<KeyboardShortcuts
|
|
134
155
|
bindGlobal
|
|
135
156
|
shortcuts={ {
|
|
136
|
-
[ rawShortcut.primary( 'k' ) ]:
|
|
137
|
-
[ rawShortcut.primaryShift( 'k' ) ]:
|
|
157
|
+
[ rawShortcut.primary( 'k' ) ]: startEditing,
|
|
158
|
+
[ rawShortcut.primaryShift( 'k' ) ]: () => {
|
|
159
|
+
unlink();
|
|
160
|
+
richTextRef.current?.focus();
|
|
161
|
+
},
|
|
138
162
|
} }
|
|
139
163
|
/>
|
|
140
164
|
) }
|
|
@@ -195,6 +219,7 @@ function ButtonEdit( props ) {
|
|
|
195
219
|
const borderRadius = style?.border?.radius;
|
|
196
220
|
const colorProps = useColorProps( attributes );
|
|
197
221
|
const ref = useRef();
|
|
222
|
+
const richTextRef = useRef();
|
|
198
223
|
const blockProps = useBlockProps( { ref } );
|
|
199
224
|
|
|
200
225
|
return (
|
|
@@ -207,6 +232,7 @@ function ButtonEdit( props ) {
|
|
|
207
232
|
} ) }
|
|
208
233
|
>
|
|
209
234
|
<RichText
|
|
235
|
+
ref={ richTextRef }
|
|
210
236
|
aria-label={ __( 'Button text' ) }
|
|
211
237
|
placeholder={ placeholder || __( 'Add text…' ) }
|
|
212
238
|
value={ text }
|
|
@@ -244,6 +270,7 @@ function ButtonEdit( props ) {
|
|
|
244
270
|
opensInNewTab={ linkTarget === '_blank' }
|
|
245
271
|
onToggleOpenInNewTab={ onToggleOpenInNewTab }
|
|
246
272
|
anchorRef={ ref }
|
|
273
|
+
richTextRef={ richTextRef }
|
|
247
274
|
/>
|
|
248
275
|
<InspectorControls>
|
|
249
276
|
<WidthPanel
|
package/src/post-excerpt/edit.js
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
Warning,
|
|
17
17
|
useBlockProps,
|
|
18
18
|
} from '@wordpress/block-editor';
|
|
19
|
-
import { PanelBody,
|
|
19
|
+
import { PanelBody, ToggleControl, Disabled } from '@wordpress/components';
|
|
20
20
|
import { __ } from '@wordpress/i18n';
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -24,29 +24,8 @@ import { __ } from '@wordpress/i18n';
|
|
|
24
24
|
*/
|
|
25
25
|
import { useCanEditEntity } from '../utils/hooks';
|
|
26
26
|
|
|
27
|
-
function usePostContentExcerpt( wordCount, postId, postType ) {
|
|
28
|
-
// Don't destrcuture items from content here, it can be undefined.
|
|
29
|
-
const [ , , content ] = useEntityProp(
|
|
30
|
-
'postType',
|
|
31
|
-
postType,
|
|
32
|
-
'content',
|
|
33
|
-
postId
|
|
34
|
-
);
|
|
35
|
-
const renderedPostContent = content?.rendered;
|
|
36
|
-
return useMemo( () => {
|
|
37
|
-
if ( ! renderedPostContent ) {
|
|
38
|
-
return '';
|
|
39
|
-
}
|
|
40
|
-
const excerptElement = document.createElement( 'div' );
|
|
41
|
-
excerptElement.innerHTML = renderedPostContent;
|
|
42
|
-
const excerpt =
|
|
43
|
-
excerptElement.textContent || excerptElement.innerText || '';
|
|
44
|
-
return excerpt.trim().split( ' ', wordCount ).join( ' ' );
|
|
45
|
-
}, [ renderedPostContent, wordCount ] );
|
|
46
|
-
}
|
|
47
|
-
|
|
48
27
|
export default function PostExcerptEditor( {
|
|
49
|
-
attributes: { textAlign,
|
|
28
|
+
attributes: { textAlign, moreText, showMoreOnNewLine },
|
|
50
29
|
setAttributes,
|
|
51
30
|
isSelected,
|
|
52
31
|
context: { postId, postType, queryId },
|
|
@@ -59,16 +38,24 @@ export default function PostExcerptEditor( {
|
|
|
59
38
|
setExcerpt,
|
|
60
39
|
{ rendered: renderedExcerpt, protected: isProtected } = {},
|
|
61
40
|
] = useEntityProp( 'postType', postType, 'excerpt', postId );
|
|
62
|
-
const postContentExcerpt = usePostContentExcerpt(
|
|
63
|
-
wordCount,
|
|
64
|
-
postId,
|
|
65
|
-
postType
|
|
66
|
-
);
|
|
67
41
|
const blockProps = useBlockProps( {
|
|
68
42
|
className: classnames( {
|
|
69
43
|
[ `has-text-align-${ textAlign }` ]: textAlign,
|
|
70
44
|
} ),
|
|
71
45
|
} );
|
|
46
|
+
/**
|
|
47
|
+
* When excerpt is editable, strip the html tags from
|
|
48
|
+
* rendered excerpt. This will be used if the entity's
|
|
49
|
+
* excerpt has been produced from the content.
|
|
50
|
+
*/
|
|
51
|
+
const strippedRenderedExcerpt = useMemo( () => {
|
|
52
|
+
if ( ! renderedExcerpt ) return '';
|
|
53
|
+
const document = new window.DOMParser().parseFromString(
|
|
54
|
+
renderedExcerpt,
|
|
55
|
+
'text/html'
|
|
56
|
+
);
|
|
57
|
+
return document.body.textContent || document.body.innerText || '';
|
|
58
|
+
}, [ renderedExcerpt ] );
|
|
72
59
|
if ( ! postType || ! postId ) {
|
|
73
60
|
return (
|
|
74
61
|
<div { ...blockProps }>
|
|
@@ -110,16 +97,17 @@ export default function PostExcerptEditor( {
|
|
|
110
97
|
aria-label={ __( 'Post excerpt text' ) }
|
|
111
98
|
value={
|
|
112
99
|
rawExcerpt ||
|
|
113
|
-
|
|
100
|
+
strippedRenderedExcerpt ||
|
|
114
101
|
( isSelected ? '' : __( 'No post excerpt found' ) )
|
|
115
102
|
}
|
|
116
103
|
onChange={ setExcerpt }
|
|
117
104
|
/>
|
|
118
105
|
) : (
|
|
119
106
|
( renderedExcerpt && (
|
|
120
|
-
<
|
|
107
|
+
<Disabled>
|
|
108
|
+
<RawHTML key="html">{ renderedExcerpt }</RawHTML>
|
|
109
|
+
</Disabled>
|
|
121
110
|
) ) ||
|
|
122
|
-
postContentExcerpt ||
|
|
123
111
|
__( 'No post excerpt found' )
|
|
124
112
|
);
|
|
125
113
|
return (
|
|
@@ -134,17 +122,6 @@ export default function PostExcerptEditor( {
|
|
|
134
122
|
</BlockControls>
|
|
135
123
|
<InspectorControls>
|
|
136
124
|
<PanelBody title={ __( 'Post Excerpt Settings' ) }>
|
|
137
|
-
{ ! renderedExcerpt && (
|
|
138
|
-
<RangeControl
|
|
139
|
-
label={ __( 'Max words' ) }
|
|
140
|
-
value={ wordCount }
|
|
141
|
-
onChange={ ( newExcerptLength ) =>
|
|
142
|
-
setAttributes( { wordCount: newExcerptLength } )
|
|
143
|
-
}
|
|
144
|
-
min={ 10 }
|
|
145
|
-
max={ 100 }
|
|
146
|
-
/>
|
|
147
|
-
) }
|
|
148
125
|
<ToggleControl
|
|
149
126
|
label={ __( 'Show link on new line' ) }
|
|
150
127
|
checked={ showMoreOnNewLine }
|
|
@@ -18,34 +18,34 @@ function render_block_core_post_excerpt( $attributes, $content, $block ) {
|
|
|
18
18
|
return '';
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
$more_text
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return isset( $attributes['wordCount'] ) ? $attributes['wordCount'] : 55;
|
|
21
|
+
$more_text = ! empty( $attributes['moreText'] ) ? '<a class="wp-block-post-excerpt__more-link" href="' . esc_url( get_the_permalink( $block->context['postId'] ) ) . '">' . $attributes['moreText'] . '</a>' : '';
|
|
22
|
+
$filter_excerpt_more = function( $more ) use ( $more_text ) {
|
|
23
|
+
return empty( $more_text ) ? $more : '';
|
|
25
24
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Some themes might use `excerpt_more` filter to handle the
|
|
27
|
+
* `more` link displayed after a trimmed excerpt. Since the
|
|
28
|
+
* block has a `more text` attribute we have to check and
|
|
29
|
+
* override if needed the return value from this filter.
|
|
30
|
+
* So if the block's attribute is not empty override the
|
|
31
|
+
* `excerpt_more` filter and return nothing. This will
|
|
32
|
+
* result in showing only one `read more` link at a time.
|
|
33
|
+
*/
|
|
34
|
+
add_filter( 'excerpt_more', $filter_excerpt_more );
|
|
31
35
|
$classes = '';
|
|
32
36
|
if ( isset( $attributes['textAlign'] ) ) {
|
|
33
|
-
$classes .=
|
|
37
|
+
$classes .= "has-text-align-{$attributes['textAlign']}";
|
|
34
38
|
}
|
|
35
39
|
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
|
|
36
40
|
|
|
37
|
-
$content
|
|
38
|
-
|
|
41
|
+
$content = '<p class="wp-block-post-excerpt__excerpt">' . get_the_excerpt( $block->context['postId'] );
|
|
42
|
+
$show_more_on_new_line = ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'];
|
|
43
|
+
if ( $show_more_on_new_line && ! empty( $more_text ) ) {
|
|
39
44
|
$content .= '</p><p class="wp-block-post-excerpt__more-text">' . $more_text . '</p>';
|
|
40
45
|
} else {
|
|
41
46
|
$content .= " $more_text</p>";
|
|
42
47
|
}
|
|
43
|
-
|
|
44
|
-
remove_filter(
|
|
45
|
-
'excerpt_length',
|
|
46
|
-
$filter_excerpt_length
|
|
47
|
-
);
|
|
48
|
-
|
|
48
|
+
remove_filter( 'excerpt_more', $filter_excerpt_more );
|
|
49
49
|
return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $content );
|
|
50
50
|
}
|
|
51
51
|
|