Skip to content

Commit 08a7a0f

Browse files
authored
Merge pull request #663 from embedpdf/feature/category-based-hiding-overlays
Enable category-based hiding for overlays
2 parents 9a0605b + 2297d23 commit 08a7a0f

14 files changed

Lines changed: 123 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@embedpdf/snippet": patch
3+
---
4+
5+
Allow hiding the UnlockOwnerOverlay (the read-only notice shown on encrypted, permission-restricted PDFs) via `disabledCategories`. The overlay renderer now emits the `data-epdf-cat` attribute, and the `unlock-owner-overlay` overlay carries the new `security` / `security-unlock-overlay` categories, so viewer-only integrations can remove it with `disabledCategories: ['security-unlock-overlay']` (or the parent `security`).
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@embedpdf/plugin-ui": patch
3+
---
4+
5+
Overlays now participate in the category visibility system. The schema analyzer collects overlay `categories` (and `visibilityDependsOn`), so category visibility CSS is generated for them and they can be hidden via `disabledCategories` like any other UI item.

packages/plugin-ui/src/lib/utils/stylesheet-generator.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,18 @@ function analyzeSchema(schema: UISchema, locale?: string): SchemaAnalysis {
226226
);
227227
}
228228

229+
// Analyze overlays
230+
for (const [overlayId, overlay] of Object.entries(schema.overlays || {})) {
231+
collectCategoriesAndDependency(
232+
overlayId,
233+
overlay.categories,
234+
overlay.visibilityDependsOn,
235+
categories,
236+
itemCategories,
237+
dependencies,
238+
);
239+
}
240+
229241
return { categories, itemCategories, dependencies, menuBreakpoints, responsiveItems };
230242
}
231243

viewers/snippet/src/config/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ export const commands: Record<string, Command<State>> = {
487487
id: 'document:protect',
488488
labelKey: 'document.protect',
489489
icon: 'lock',
490-
categories: ['document', 'document-protect'],
490+
categories: ['document', 'document-protect', 'security'],
491491
action: ({ registry, documentId }) => {
492492
const ui = registry.getPlugin<UIPlugin>('ui')?.provides();
493493
if (!ui) return;

viewers/snippet/src/config/ui-schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ export const viewerUISchema: UISchema = {
13061306
type: 'command',
13071307
id: 'document:protect',
13081308
commandId: 'document:protect',
1309-
categories: ['document', 'document-protect'],
1309+
categories: ['document', 'document-protect', 'security'],
13101310
},
13111311
{
13121312
type: 'command',
@@ -1750,6 +1750,7 @@ export const viewerUISchema: UISchema = {
17501750
type: 'component',
17511751
componentId: 'unlock-owner-overlay',
17521752
},
1753+
categories: ['security', 'security-unlock-overlay'],
17531754
defaultEnabled: true,
17541755
},
17551756
},

viewers/snippet/src/ui/schema-overlay.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { h } from 'preact';
2-
import { OverlaySchema, OverlayAnchor } from '@embedpdf/plugin-ui';
2+
import { OverlaySchema, OverlayAnchor, UI_ATTRIBUTES } from '@embedpdf/plugin-ui';
33
import { useItemRenderer } from '@embedpdf/plugin-ui/preact';
44

55
export interface OverlayRendererProps {
@@ -59,11 +59,17 @@ export function SchemaOverlay({ schema, documentId, className }: OverlayRenderer
5959
const anchorClasses = getAnchorClasses(position.anchor);
6060
const offsetStyles = getOffsetStyles(position.offset);
6161

62+
const categoryAttr = schema.categories?.length
63+
? { [UI_ATTRIBUTES.CATEGORIES]: schema.categories.join(' ') }
64+
: {};
65+
6266
return (
6367
<div
6468
className={`z-3 absolute ${anchorClasses} ${className || ''}`}
6569
style={offsetStyles}
6670
data-overlay-id={schema.id}
71+
{...{ [UI_ATTRIBUTES.ITEM]: schema.id }}
72+
{...categoryAttr}
6773
>
6874
{renderCustomComponent(content.componentId, documentId)}
6975
</div>

website/src/content/docs/react/viewer/customizing-ui.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Categories are hierarchical—disabling a parent category (e.g., `annotation`) d
6262
| **Selection** | `selection`, `selection-copy` |
6363
| **History** | `history`, `history-undo`, `history-redo` |
6464
| **Insert** | `insert`, `insert-rubber-stamp`, `insert-signature`, `insert-image` |
65+
| **Security** | `security`, `security-unlock-overlay` |
6566

6667
## Advanced Customization
6768

website/src/content/docs/react/viewer/security.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,28 @@ The UI automatically adapts to these effective permissions. For example:
7474
- If `copyContents` is denied, text selection is disabled on the canvas.
7575
- If `modifyAnnotations` is denied, annotation tools are disabled.
7676

77+
## Hiding the read-only notice
78+
79+
When a document is encrypted **and** has restricted permissions, the viewer shows a small dismissible overlay informing the user that the document is protected (with a "View permissions" link). This is helpful in a full editor, but for a viewer-only integration you may want to remove it entirely.
80+
81+
The overlay is part of the UI category system, so you can hide it with `disabledCategories`:
82+
83+
```tsx
84+
<PDFViewer
85+
config={{
86+
src: '/document.pdf',
87+
// Remove only the read-only notice overlay...
88+
disabledCategories: ['security-unlock-overlay'],
89+
// ...or remove all security UI with the parent category:
90+
// disabledCategories: ['security'],
91+
}}
92+
/>
93+
```
94+
95+
<Callout>
96+
This only hides the notice from the UI. It does not change or bypass the document's permissions. See [Customizing the UI](./customizing-ui#disabling-features) for the full list of categories.
97+
</Callout>
98+
7799
## Interactive Example
78100

79101
Switch between the tabs to see how different permission configurations affect the viewer. Observe how the **Print** button and **Text Selection** behave in each mode.

website/src/content/docs/snippet/customizing-ui.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Categories are hierarchical—disabling a parent category (e.g., `annotation`) d
5656
| **Selection** | `selection`, `selection-copy` |
5757
| **History** | `history`, `history-undo`, `history-redo` |
5858
| **Insert** | `insert`, `insert-rubber-stamp`, `insert-signature`, `insert-image` |
59+
| **Security** | `security`, `security-unlock-overlay` |
5960

6061
## Quick Start: Replacing a Toolbar Button
6162

website/src/content/docs/snippet/security.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,27 @@ The UI automatically adapts to these effective permissions. For example:
7373
- If `copyContents` is denied, text selection is disabled on the canvas.
7474
- If `modifyAnnotations` is denied, annotation tools are disabled.
7575

76+
## Hiding the read-only notice
77+
78+
When a document is encrypted **and** has restricted permissions, the snippet shows a small dismissible overlay informing the user that the document is protected (with a "View permissions" link). This is helpful in a full editor, but for a viewer-only integration you may want to remove it entirely.
79+
80+
The overlay is part of the UI category system, so you can hide it with `disabledCategories`:
81+
82+
```js
83+
EmbedPDF.init({
84+
target: document.getElementById('pdf-viewer'),
85+
src: 'https://example.com/document.pdf',
86+
// Remove only the read-only notice overlay...
87+
disabledCategories: ['security-unlock-overlay'],
88+
// ...or remove all security UI with the parent category:
89+
// disabledCategories: ['security'],
90+
});
91+
```
92+
93+
<Callout>
94+
This only hides the notice from the UI. It does not change or bypass the document's permissions. See [Customizing the UI](./customizing-ui#disabling-features) for the full list of categories.
95+
</Callout>
96+
7697
## Interactive Example
7798

7899
Switch between the tabs to see how different permission configurations affect the viewer. Observe how the **Print** button and **Text Selection** behave in each mode.

0 commit comments

Comments
 (0)