| @@ -1,8 +1,29 @@ | ||
| 1 | +import { BLOCK_ID_SEL } from '@agent/lib/block-el'; | |
| 1 | 2 | import { UpdatePostConfirm } from '@agent/workflows/content/components/UpdatePostConfirm'; |
| 2 | 3 | |
| 3 | 4 | const { context, abilities } = window.extAgentData; |
| 4 | 5 | |
| 6 | +// A wrapper carries its children's text, so counting it repeats every string. | |
| 7 | +const ownText = (el) => { | |
| 8 | + let text = ''; | |
| 9 | + for (const node of el.childNodes) { | |
| 10 | + if (node.nodeType === Node.TEXT_NODE) text += node.nodeValue; | |
| 11 | + } | |
| 12 | + return text.replace(/\s+/g, ' ').trim(); | |
| 13 | +}; | |
| 14 | + | |
| 15 | +// One string is select-block's job; this earns its place on several. | |
| 16 | +const hasSeveralStrings = () => { | |
| 17 | + const strings = new Set(); | |
| 18 | + for (const el of document.querySelectorAll(BLOCK_ID_SEL)) { | |
| 19 | + const text = ownText(el); | |
| 20 | + if (text) strings.add(text); | |
| 21 | + if (strings.size > 1) return true; | |
| 22 | + } | |
| 23 | + return false; | |
| 24 | +}; | |
| 25 | + | |
| 5 | 26 | export default { |
| 6 | 27 | available: () => |
| 7 | 28 | abilities?.canEditPosts && |
| 8 | 29 | !context?.adminPage && |
| @@ -7,8 +28,9 @@ | ||
| 7 | 28 | abilities?.canEditPosts && |
| 8 | 29 | !context?.adminPage && |
| 9 | 30 | context?.postId && |
| 10 | 31 | !context?.isBlogPage && |
| 11 | - context.usingBlockEditor, | |
| 32 | + context.usingBlockEditor && | |
| 33 | + hasSeveralStrings(), | |
| 12 | 34 | id: 'edit-post-strings', |
| 13 | 35 | whenFinished: { component: UpdatePostConfirm }, |
| 14 | 36 | }; |