webviewer-ui-builder 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +144 -2
- package/dist/index.d.ts +88 -0
- package/dist/index.js +13684 -0
- package/dist/runtime.cjs +19 -0
- package/dist/runtime.d.ts +50 -0
- package/dist/runtime.js +1314 -0
- package/dist/standalone.global.js +72 -0
- package/package.json +59 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 lukepwn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,145 @@
|
|
|
1
|
-
#
|
|
1
|
+
# WebViewer UI Builder (`webviewer-ui-builder`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A drop-in visual studio for designing [Apryse WebViewer](https://apryse.com/docs/core/overview) (v11.8+) **Modular UI** layouts directly on top of your already-initialized viewer — then exporting clean JSON for production.
|
|
4
|
+
|
|
5
|
+
- **1-line attach** to an existing WebViewer `instance` — no need to rewrite your viewer initialization
|
|
6
|
+
- **Both initialization modes supported**: WebComponent (`WebViewer()`, v12+ default) and Iframe (`WebViewer.Iframe()`) — never reparents or reloads the viewer
|
|
7
|
+
- **Zero dependencies & framework-agnostic**: runs in an isolated Shadow DOM (works in Vanilla JS, React, Angular, Vue, Svelte, Next.js, or via `<script>` CDN)
|
|
8
|
+
- **Tiny production helper (`/runtime`)**: apply exported JSON in production (~8 KB gzipped, zero React) without shipping the builder UI
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## What It Can Do
|
|
13
|
+
|
|
14
|
+
- **Headers & Ribbons**: Create/configure `top`, `bottom`, `left`, and `right` headers with stacked or inline ribbon layouts
|
|
15
|
+
- **Components & Tools**: Add, edit, drag-reorder, and duplicate tool buttons, preset buttons, toggle buttons, custom buttons, controls, dividers, spacers, and labels
|
|
16
|
+
- **Flyouts & Multi-Level Submenus**: Build standalone dropdown menus and nested drill-down submenus, with automatic tool-activation wiring via `functionMap`
|
|
17
|
+
- **Panels & Popups**: Configure dockable side panels, tab panels, and contextual popups (`annotationPopup`, `textPopup`, `contextMenuPopup`)
|
|
18
|
+
- **Live Sync & JSON Export**: Real-time debounced updates, click-to-highlight elements inside WebViewer, JSON preview/import/export, and copyable `functionMap` snippets
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Requirements
|
|
23
|
+
|
|
24
|
+
- **Apryse WebViewer v11.8+** using **Modular UI** (default in v11.8+ / v12+)
|
|
25
|
+
- Works with both **`WebViewer(...)`** (WebComponent) and **`WebViewer.Iframe(...)`** (Iframe)
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
### 1. Install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install webviewer-ui-builder
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 2. Attach to Your Existing WebViewer Instance
|
|
38
|
+
|
|
39
|
+
Call `attachUIBuilder(instance)` inside your existing `WebViewer(...).then(...)` callback:
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
import WebViewer from '@pdftron/webviewer';
|
|
43
|
+
import { attachUIBuilder } from 'webviewer-ui-builder';
|
|
44
|
+
|
|
45
|
+
WebViewer({ path: '/lib/webviewer', licenseKey: 'YOUR_KEY' }, viewerEl).then(
|
|
46
|
+
(instance) => {
|
|
47
|
+
const builder = attachUIBuilder(instance);
|
|
48
|
+
|
|
49
|
+
// Toggle anytime with Ctrl+Shift+B or programmatically:
|
|
50
|
+
// builder.open() | builder.close() | builder.toggle() | builder.destroy()
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
> **SPA tip (React / Vue / Angular):** Call `builder?.destroy()` when your viewer component unmounts to remove the overlay and restore container styles cleanly.
|
|
56
|
+
|
|
57
|
+
### CDN / No-Build-Step Usage
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<script src="https://unpkg.com/webviewer-ui-builder/dist/standalone.global.js"></script>
|
|
61
|
+
<script>
|
|
62
|
+
WebViewer({ path: '/lib/webviewer' }, viewerEl).then((instance) => {
|
|
63
|
+
window.WebViewerUIBuilder.attachUIBuilder(instance);
|
|
64
|
+
});
|
|
65
|
+
</script>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Production Usage (`webviewer-ui-builder/runtime`)
|
|
71
|
+
|
|
72
|
+
Once you've exported your JSON config from the studio, remove `attachUIBuilder` from production and apply the config with the zero-React `/runtime` helper (~8 KB gzipped):
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
import { applyModularConfig } from 'webviewer-ui-builder/runtime';
|
|
76
|
+
import customUi from './webviewer-ui-config.json';
|
|
77
|
+
|
|
78
|
+
WebViewer({ path: '/lib/webviewer' }, viewerEl).then((instance) => {
|
|
79
|
+
applyModularConfig(instance, customUi, {
|
|
80
|
+
customHandlers: {
|
|
81
|
+
myCustomAction: () => console.log('Custom button clicked'),
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`applyModularConfig` automatically normalizes schema constraints (`prepareConfigForImport`), wires flyout tool activators (`buildFunctionMap`), merges your `customHandlers`, and calls `instance.UI.importModularComponents(...)`.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## API Reference
|
|
92
|
+
|
|
93
|
+
### `attachUIBuilder(instance, options?)`
|
|
94
|
+
|
|
95
|
+
| Option | Default | Description |
|
|
96
|
+
| :--- | :--- | :--- |
|
|
97
|
+
| `layout` | `'squeeze'` | `'squeeze'` frames the viewer via reversible container padding without reloading it; `'overlay'` floats drawers with zero container style changes; `'container'` renders inside `options.target` |
|
|
98
|
+
| `viewerElement` | auto-detected | Explicit WebViewer container element (auto-detected for both `<apryse-webviewer>` and `<iframe>`) |
|
|
99
|
+
| `target` | `null` | Required `HTMLElement` when `layout: 'container'` |
|
|
100
|
+
| `defaultOpen` | `true` | Set `false` to start minimized as a floating **UI Builder** pill |
|
|
101
|
+
| `showLauncher` | `true` | Show the floating **UI Builder** pill while minimized |
|
|
102
|
+
| `hotkey` | `'Ctrl+Shift+B'` | Keyboard shortcut to toggle open/closed (`null` or `false` to disable) |
|
|
103
|
+
| `zIndex` | `99999` | CSS `z-index` for the Shadow DOM host |
|
|
104
|
+
| `initialConfig` | `null` | Optional Modular UI JSON config to load immediately |
|
|
105
|
+
| `customHandlers` | `null` | Custom `functionMap` handlers merged during live preview |
|
|
106
|
+
| `onChange` | `null` | `(config) => void` — fires on every edit |
|
|
107
|
+
| `onApply` | `null` | `({ config, functionMap, warnings }) => void` — fires after syncing to WebViewer |
|
|
108
|
+
| `onClose` | `null` | `() => void` — fires when minimized |
|
|
109
|
+
|
|
110
|
+
### Returned Handle
|
|
111
|
+
|
|
112
|
+
- `builder.open()` / `builder.close()` / `builder.toggle()` / `builder.isOpen()`
|
|
113
|
+
- `builder.getConfig()` — returns a cloned JSON snapshot of the current layout
|
|
114
|
+
- `builder.applyConfig(config)` — programmatically loads and applies a JSON config
|
|
115
|
+
- `builder.destroy()` — unmounts the studio, removes listeners, and restores original container styles
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## How It Works
|
|
120
|
+
|
|
121
|
+
Instead of mutating WebViewer's internal DOM, the studio uses WebViewer's declarative Modular UI API:
|
|
122
|
+
|
|
123
|
+
1. Snapshots your current UI on attach via `instance.UI.exportModularComponents()`
|
|
124
|
+
2. Applies all edits as pure JSON state changes (debounced 150ms)
|
|
125
|
+
3. Normalizes schema constraints (`prepareConfigForImport`) and generates action handlers (`buildFunctionMap`)
|
|
126
|
+
4. Live-hydrates WebViewer via `instance.UI.importModularComponents(sanitized, functionMap)`
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Local Development
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm install
|
|
134
|
+
npm run setup:webviewer # Copies @pdftron/webviewer assets to public/lib/webviewer (dev only)
|
|
135
|
+
npm run dev # Standalone demo: http://localhost:5173/
|
|
136
|
+
# Drop-in WebComponent demo: http://localhost:5173/examples/attach-demo.html
|
|
137
|
+
# Drop-in Iframe demo: http://localhost:5173/examples/attach-demo.html?mode=iframe
|
|
138
|
+
npm run build:lib # Builds the npm package into dist/
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT — see [LICENSE](./LICENSE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ModularUIConfig,
|
|
3
|
+
FunctionMap,
|
|
4
|
+
ApplyModularConfigOptions,
|
|
5
|
+
ApplyModularConfigResult,
|
|
6
|
+
FunctionMapEntry,
|
|
7
|
+
RequiredFunctionMapInfo,
|
|
8
|
+
applyModularConfig,
|
|
9
|
+
prepareConfigForImport,
|
|
10
|
+
buildFunctionMap,
|
|
11
|
+
getRequiredFunctionMapInfo,
|
|
12
|
+
} from './runtime';
|
|
13
|
+
|
|
14
|
+
export type {
|
|
15
|
+
ModularUIConfig,
|
|
16
|
+
FunctionMap,
|
|
17
|
+
ApplyModularConfigOptions,
|
|
18
|
+
ApplyModularConfigResult,
|
|
19
|
+
FunctionMapEntry,
|
|
20
|
+
RequiredFunctionMapInfo,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
applyModularConfig,
|
|
25
|
+
prepareConfigForImport,
|
|
26
|
+
buildFunctionMap,
|
|
27
|
+
getRequiredFunctionMapInfo,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type BuilderLayoutMode = 'squeeze' | 'overlay' | 'container';
|
|
31
|
+
|
|
32
|
+
export interface AttachUIBuilderOptions {
|
|
33
|
+
/**
|
|
34
|
+
* How the builder mounts around an already-initialized WebViewer:
|
|
35
|
+
* - `'squeeze'` (default): Frames the viewer container via reversible padding without reloading its iframe.
|
|
36
|
+
* - `'overlay'`: Floating side drawers over the viewer with zero style mutations to the host container.
|
|
37
|
+
* - `'container'`: Renders studio panels inside `options.target`.
|
|
38
|
+
*/
|
|
39
|
+
layout?: BuilderLayoutMode;
|
|
40
|
+
/** Target container element (required when `layout: 'container'`). */
|
|
41
|
+
target?: HTMLElement | null;
|
|
42
|
+
/** Explicit WebViewer mount container (auto-detected from the iframe if omitted). */
|
|
43
|
+
viewerElement?: HTMLElement | null;
|
|
44
|
+
/** Start expanded (default: true) or minimized to a floating launcher pill. */
|
|
45
|
+
defaultOpen?: boolean;
|
|
46
|
+
/** Show the floating "UI Builder" pill when minimized (default: true). */
|
|
47
|
+
showLauncher?: boolean;
|
|
48
|
+
/** Keyboard shortcut to toggle visibility (default: `'Ctrl+Shift+B'`). Pass `null` or `false` to disable. */
|
|
49
|
+
hotkey?: string | false | null;
|
|
50
|
+
/** CSS z-index for the Shadow DOM overlay host (default: 99999). */
|
|
51
|
+
zIndex?: number;
|
|
52
|
+
/** Optional starting Modular UI JSON configuration to load immediately. */
|
|
53
|
+
initialConfig?: ModularUIConfig | null;
|
|
54
|
+
/** Optional custom button/panel handlers merged into the live functionMap. */
|
|
55
|
+
customHandlers?: FunctionMap | null;
|
|
56
|
+
/** Called whenever the user modifies the Modular UI configuration. */
|
|
57
|
+
onChange?: (config: ModularUIConfig) => void;
|
|
58
|
+
/** Called each time configuration is applied to the WebViewer instance. */
|
|
59
|
+
onApply?: (result: ApplyModularConfigResult) => void;
|
|
60
|
+
/** Called when the builder is minimized/closed. */
|
|
61
|
+
onClose?: () => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface UIBuilderHandle {
|
|
65
|
+
/** Open/expand the UI Builder studio. */
|
|
66
|
+
open(): void;
|
|
67
|
+
/** Minimize/collapse the UI Builder studio and restore squeeze padding. */
|
|
68
|
+
close(): void;
|
|
69
|
+
/** Toggle open/closed state. */
|
|
70
|
+
toggle(): void;
|
|
71
|
+
/** Returns whether the studio is currently open. */
|
|
72
|
+
isOpen(): boolean;
|
|
73
|
+
/** Returns a cloned snapshot of the current Modular UI JSON configuration. */
|
|
74
|
+
getConfig(): ModularUIConfig | null;
|
|
75
|
+
/** Programmatically loads and applies a Modular UI JSON configuration. */
|
|
76
|
+
applyConfig(config: ModularUIConfig): ApplyModularConfigResult | null;
|
|
77
|
+
/** Unmounts the builder, removes listeners, and restores original container styles. */
|
|
78
|
+
destroy(): void;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Attaches the WebViewer Modular UI Builder to an already-initialized
|
|
83
|
+
* Apryse WebViewer instance without reparenting or reloading its iframe.
|
|
84
|
+
*/
|
|
85
|
+
export declare function attachUIBuilder(
|
|
86
|
+
instance: any,
|
|
87
|
+
options?: AttachUIBuilderOptions,
|
|
88
|
+
): UIBuilderHandle;
|