PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Agent / components / PageDocument.jsx

PageDocument.jsx in Extendify 3.2.1, at src/Agent/components/PageDocument.jsx

61 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { findBlockEl, scopeOf } from '@agent/lib/block-el';
2 import { buildSubtreeManifest } from '@agent/lib/subtree-manifest';
3 import { useQuickEditStore } from '@quick-edit/state/store';
4 import { useMemo } from '@wordpress/element';
5 import { __, _n, sprintf } from '@wordpress/i18n';
6 import { close, Icon } from '@wordpress/icons';
7 import classNames from 'classnames';
8
9 export const PageDocument = ({ busy }) => {
10 const setBlock = useQuickEditStore((s) => s.setAgentBlock);
11 const block = useQuickEditStore((s) => s.agentBlock);
12
13 // The same manifest the agent works from, so the count matches what it
14 // can actually address — not every node in the subtree.
15 const count = useMemo(() => {
16 if (!block?.id) return 1;
17 const node = findBlockEl(block.id, document, scopeOf(block));
18 return Math.max(node ? buildSubtreeManifest(node).length : 1, 1);
19 }, [block]);
20
21 return (
22 // The input darkens to gray-300 while disabled; a gray-200 chip vanishes into it.
23 <div
24 className={classNames(
25 'flex w-fit max-w-full items-center gap-1 whitespace-nowrap rounded-sm py-1.5 pe-1.5 ps-2.5 text-xs leading-tight',
26 {
27 'bg-gray-100 text-gray-600': busy,
28 'bg-gray-200 text-gray-900': !busy,
29 },
30 )}
31 >
32 <span className="truncate">
33 {sprintf(
34 // translators: %d is the number of blocks the user selected on the page.
35 _n(
36 '%d block selected',
37 '%d blocks selected',
38 count,
39 'extendify-local',
40 ),
41 count,
42 )}
43 </span>
44 {/* Stays mounted while disabled: dropping it reflows the chip mid-run. */}
45 <button
46 type="button"
47 disabled={busy}
48 className="flex shrink-0 items-center rounded-none border-0 bg-transparent p-0 outline-hidden ring-design-main focus:shadow-none focus:outline-hidden focus-visible:outline-design-main disabled:cursor-not-allowed disabled:opacity-40"
49 onClick={() => setBlock(null)}
50 >
51 <Icon
52 className="pointer-events-none fill-current leading-none"
53 icon={close}
54 size={16}
55 />
56 <span className="sr-only">{__('Remove', 'extendify-local')}</span>
57 </button>
58 </div>
59 );
60 };
61