@bambamboole/pdf-ua-template-builder 0.2.0 → 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/README.md +119 -17
- package/dist/index.js +6327 -5201
- package/dist/index.js.map +1 -1
- package/dist/src/builder/Builder.d.ts +7 -0
- package/dist/{builder → src/builder}/TemplateBuilder.d.ts +10 -13
- package/dist/src/builder/blocks/Palette.d.ts +7 -0
- package/dist/src/builder/canvas/BlockDataPreview.d.ts +7 -0
- package/dist/{builder → src/builder}/canvas/BuilderCanvas.d.ts +8 -4
- package/dist/src/builder/canvas/Canvas.d.ts +4 -0
- package/dist/{builder → src/builder}/canvas/ColumnResizer.d.ts +2 -1
- package/dist/{builder → src/builder}/canvas/PageSheet.d.ts +3 -1
- package/dist/{builder → src/builder}/canvas/SortableBlock.d.ts +7 -5
- package/dist/src/builder/canvas/columns.d.ts +13 -0
- package/dist/src/builder/context/BuilderContext.d.ts +66 -0
- package/dist/src/builder/controls/AlignSelect.d.ts +7 -0
- package/dist/src/builder/controls/BuilderField.d.ts +74 -0
- package/dist/src/builder/controls/Field.d.ts +6 -0
- package/dist/src/builder/controls/fieldConverters.d.ts +4 -0
- package/dist/src/builder/controls/index.d.ts +7 -0
- package/dist/src/builder/controls/inputs.d.ts +5 -0
- package/dist/src/builder/hooks/useBuilderDragDrop.d.ts +24 -0
- package/dist/src/builder/inspector/BlockContentControls.d.ts +9 -0
- package/dist/src/builder/inspector/BlockInspector.d.ts +14 -0
- package/dist/src/builder/inspector/BlockLayoutControls.d.ts +7 -0
- package/dist/src/builder/inspector/DocumentSettings.d.ts +18 -0
- package/dist/src/builder/inspector/Inspector.d.ts +1 -0
- package/dist/src/builder/inspector/InspectorShell.d.ts +17 -0
- package/dist/src/builder/inspector/PageSettings.d.ts +4 -0
- package/dist/src/builder/inspector/SpacingControls.d.ts +15 -0
- package/dist/src/builder/inspector/TypographyControls.d.ts +19 -0
- package/dist/src/builder/inspector/alignOptions.d.ts +10 -0
- package/dist/src/builder/inspector/editors/ImageBlockEditor.d.ts +3 -0
- package/dist/src/builder/inspector/editors/KeyValueBlockEditor.d.ts +11 -0
- package/dist/src/builder/inspector/editors/SortableList.d.ts +7 -0
- package/dist/src/builder/inspector/editors/SortableRow.d.ts +10 -0
- package/dist/src/builder/inspector/editors/TableBlockEditor.d.ts +20 -0
- package/dist/src/builder/inspector/editors/blockEditors.d.ts +7 -0
- package/dist/src/builder/lib/records.d.ts +4 -0
- package/dist/src/builder/lib/sensors.d.ts +1 -0
- package/dist/src/builder/primitives/Button.d.ts +10 -0
- package/dist/src/builder/primitives/Chip.d.ts +7 -0
- package/dist/{builder → src/builder}/schema/schemaAdapter.d.ts +2 -5
- package/dist/src/builder/state/configUpdates.d.ts +23 -0
- package/dist/src/builder/state/dragDrop.d.ts +17 -0
- package/dist/{builder → src/builder}/state/editorModel.d.ts +5 -0
- package/dist/src/builder/state/editorReducer.d.ts +71 -0
- package/dist/src/editor/CodeEditor.d.ts +4 -0
- package/dist/src/editor/TemplateEditor.d.ts +23 -0
- package/dist/src/editor/TemplateEditorContext.d.ts +20 -0
- package/dist/src/editor/editorTheme.d.ts +1 -0
- package/dist/src/editor/parseTemplate.d.ts +6 -0
- package/dist/src/editor/templateSchema.d.ts +1 -0
- package/dist/{index.d.ts → src/index.d.ts} +12 -0
- package/dist/src/render/PdfPane.d.ts +14 -0
- package/dist/src/render/Preview.d.ts +4 -0
- package/dist/src/render/RenderContext.d.ts +17 -0
- package/dist/src/render/usePdfUaApi.d.ts +19 -0
- package/dist/{types → src/types}/template.d.ts +5 -1
- package/dist/style.css +3 -1
- package/package.json +22 -9
- package/dist/builder/canvas/columns.d.ts +0 -4
- package/dist/builder/forms/InlineBlockForm.d.ts +0 -9
- package/dist/builder/pdf/PdfPane.d.ts +0 -11
- package/dist/builder/topbar/BuilderTopbar.d.ts +0 -17
- /package/dist/{api → src/api}/pdfUaApi.d.ts +0 -0
- /package/dist/{builder → src/builder}/blocks/BlockPalette.d.ts +0 -0
- /package/dist/{builder → src/builder}/blocks/blockChrome.d.ts +0 -0
- /package/dist/{builder → src/builder}/canvas/BlockCardPreview.d.ts +0 -0
- /package/dist/{builder → src/builder}/lib/displayScale.d.ts +0 -0
- /package/dist/{builder → src/builder}/lib/pageSizes.d.ts +0 -0
- /package/dist/{builder → src/builder}/schema/invoiceExample.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
# @bambamboole/pdf-ua-template-builder
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[pdf-ua-api](https://github.com/bambamboole/pdf-ua-api) PDF/UA
|
|
3
|
+
Embeddable React components for authoring
|
|
4
|
+
[pdf-ua-api](https://github.com/bambamboole/pdf-ua-api) PDF/UA templates — a
|
|
5
|
+
visual drag-and-drop **builder** and a schema-validated **JSON editor**, each
|
|
6
|
+
with a live rendered-PDF preview.
|
|
5
7
|
|
|
6
|
-
-
|
|
8
|
+
- **Visual builder** — hybrid block cards that expand inline for editing
|
|
9
|
+
- **JSON editor** — CodeMirror with schema-aware autocomplete, validation, and hover
|
|
7
10
|
- Page-format aware canvas (A3/A4/A5/A6/Letter/Legal/Tabloid + orientation)
|
|
8
11
|
- Repeated footer area and page-number controls
|
|
9
12
|
- Animated drag-and-drop with full keyboard accessibility (powered by dnd-kit)
|
|
10
|
-
-
|
|
13
|
+
- Light/dark theming and composable provider + parts, built on CSS custom properties
|
|
11
14
|
|
|
12
15
|
## Install
|
|
13
16
|
|
|
@@ -27,14 +30,11 @@ npm install react react-dom
|
|
|
27
30
|
import { TemplateBuilder, createInvoiceExample } from "@bambamboole/pdf-ua-template-builder";
|
|
28
31
|
import "@bambamboole/pdf-ua-template-builder/style.css";
|
|
29
32
|
|
|
30
|
-
const example = createInvoiceExample();
|
|
31
|
-
|
|
32
33
|
export default function App() {
|
|
33
34
|
return (
|
|
34
35
|
<TemplateBuilder
|
|
35
36
|
apiUrl="http://localhost:8080"
|
|
36
|
-
|
|
37
|
-
initialData={example.data}
|
|
37
|
+
examples={{ Invoice: createInvoiceExample() }}
|
|
38
38
|
onChange={(template, data) => console.log("changed", template, data)}
|
|
39
39
|
onRendered={(pdf) => console.log("rendered pdf blob", pdf)}
|
|
40
40
|
/>
|
|
@@ -44,14 +44,116 @@ export default function App() {
|
|
|
44
44
|
|
|
45
45
|
## Props
|
|
46
46
|
|
|
47
|
-
| Prop | Type
|
|
48
|
-
| ----------------- |
|
|
49
|
-
| `apiUrl` | `string`
|
|
50
|
-
| `initialTemplate` | `Template`
|
|
51
|
-
| `initialData` | `Record<string, unknown>`
|
|
52
|
-
| `
|
|
53
|
-
| `
|
|
54
|
-
| `
|
|
47
|
+
| Prop | Type | Description |
|
|
48
|
+
| ----------------- | ------------------------------------------------------------ | ----------------------------------------------------------------------------- |
|
|
49
|
+
| `apiUrl` | `string` | Base URL of a running `pdf-ua-api`. Defaults to `""` (relative URL / proxy). |
|
|
50
|
+
| `initialTemplate` | `Template` | Template loaded on first render. |
|
|
51
|
+
| `initialData` | `Record<string, unknown>` | Runtime data keyed by block id (table rows, dynamic key-value overrides). |
|
|
52
|
+
| `examples` | `Record<string, { template: Template; data?: TemplateData }>` | Loadable examples keyed by display name. The palette's Load control only appears when this is non-empty. |
|
|
53
|
+
| `onChange` | `(template: Template, data: Record<string, unknown>) => void` | Fires on every edit. |
|
|
54
|
+
| `onRendered` | `(pdf: Blob) => void` | Fires after a successful render. |
|
|
55
|
+
| `className` | `string` | Class appended to the root element. |
|
|
56
|
+
|
|
57
|
+
## Composable layout
|
|
58
|
+
|
|
59
|
+
`<TemplateBuilder />` is a preset that places a `Builder` and a `Preview`
|
|
60
|
+
side-by-side. When you need a different arrangement — for example the PDF
|
|
61
|
+
preview **below** the builder inside a docs page — compose the parts yourself.
|
|
62
|
+
`TemplateBuilderProvider` owns the shared state and drag-and-drop context; place
|
|
63
|
+
`Builder` and `Preview` inside it however you like. Both accept a `className` for
|
|
64
|
+
positioning and sizing:
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import {
|
|
68
|
+
TemplateBuilderProvider,
|
|
69
|
+
Builder,
|
|
70
|
+
Preview,
|
|
71
|
+
createInvoiceExample,
|
|
72
|
+
} from "@bambamboole/pdf-ua-template-builder";
|
|
73
|
+
import "@bambamboole/pdf-ua-template-builder/style.css";
|
|
74
|
+
|
|
75
|
+
export default function StackedBuilder() {
|
|
76
|
+
return (
|
|
77
|
+
<TemplateBuilderProvider apiUrl="http://localhost:8080">
|
|
78
|
+
<div className="flex flex-col gap-3">
|
|
79
|
+
<Builder examples={{ Invoice: createInvoiceExample() }} className="h-[36rem]" />
|
|
80
|
+
<Preview className="h-[40rem]" />
|
|
81
|
+
</div>
|
|
82
|
+
</TemplateBuilderProvider>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`Builder` groups the palette, canvas, and inspector; `Preview` shows the rendered
|
|
88
|
+
PDF and the Render button. `TemplateBuilderProvider` accepts the same props as
|
|
89
|
+
`<TemplateBuilder />` except `examples` and `className` (`apiUrl`,
|
|
90
|
+
`initialTemplate`, `initialData`, `onChange`, `onRendered`). Because the provider
|
|
91
|
+
does not impose a height, give `Builder` and `Preview` explicit sizes when you
|
|
92
|
+
are not filling the viewport. For fully custom parts, the `useTemplateBuilder()`
|
|
93
|
+
hook exposes the underlying state and actions.
|
|
94
|
+
|
|
95
|
+
## JSON editor
|
|
96
|
+
|
|
97
|
+
Prefer raw JSON? `TemplateEditor` is a drop-in alternative to `TemplateBuilder`:
|
|
98
|
+
a CodeMirror editor with schema-aware autocomplete, validation, and hover (driven
|
|
99
|
+
by the bundled template JSON Schema), paired with the same rendered-PDF preview.
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
import { TemplateEditor, createInvoiceExample } from "@bambamboole/pdf-ua-template-builder";
|
|
103
|
+
import "@bambamboole/pdf-ua-template-builder/style.css";
|
|
104
|
+
|
|
105
|
+
const example = createInvoiceExample();
|
|
106
|
+
|
|
107
|
+
export default function App() {
|
|
108
|
+
return (
|
|
109
|
+
<TemplateEditor
|
|
110
|
+
apiUrl="http://localhost:8080"
|
|
111
|
+
initialTemplate={example.template}
|
|
112
|
+
data={example.data}
|
|
113
|
+
onChange={(template, text) => console.log("edited", template, text)}
|
|
114
|
+
onRendered={(pdf) => console.log("rendered pdf blob", pdf)}
|
|
115
|
+
/>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The editor owns the JSON text; `data` is passed straight through to render.
|
|
121
|
+
`onChange(template, text)` fires on every edit — `template` is `null` while the
|
|
122
|
+
JSON is invalid, and Render is disabled until it parses. Schema problems surface
|
|
123
|
+
as inline editor diagnostics.
|
|
124
|
+
|
|
125
|
+
It composes exactly like the builder, and shares the same `Preview`:
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
import { TemplateEditorProvider, CodeEditor, Preview } from "@bambamboole/pdf-ua-template-builder";
|
|
129
|
+
|
|
130
|
+
<TemplateEditorProvider apiUrl="http://localhost:8080" initialTemplate={example.template}>
|
|
131
|
+
<div className="flex flex-col gap-3">
|
|
132
|
+
<CodeEditor className="h-[36rem]" />
|
|
133
|
+
<Preview className="h-[40rem]" />
|
|
134
|
+
</div>
|
|
135
|
+
</TemplateEditorProvider>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`useTemplateEditor()` exposes the text and parsed state (`{ text, setText,
|
|
139
|
+
template, error, data }`) for custom UIs.
|
|
140
|
+
|
|
141
|
+
## Dark mode
|
|
142
|
+
|
|
143
|
+
The builder and editor ship a dark theme built from the same semantic tokens. It
|
|
144
|
+
turns on automatically when the OS prefers dark (`prefers-color-scheme: dark`) and
|
|
145
|
+
whenever an ancestor element carries `data-theme="dark"` (or a `.dark` class) — so
|
|
146
|
+
it syncs with hosts like Starlight out of the box. Force a mode explicitly with
|
|
147
|
+
`data-theme="light"` or `data-theme="dark"` on a wrapper element:
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
<div data-theme="dark">
|
|
151
|
+
<TemplateBuilder apiUrl="http://localhost:8080" />
|
|
152
|
+
</div>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The on-canvas page and the rendered-PDF preview stay light ("paper") in both
|
|
156
|
+
themes, matching the white PDF the backend produces.
|
|
55
157
|
|
|
56
158
|
## Backend
|
|
57
159
|
|
|
@@ -93,7 +195,7 @@ npm run lint # oxlint
|
|
|
93
195
|
```
|
|
94
196
|
|
|
95
197
|
`npm run dev` proxies `/schema` and `/render/*` to a local `pdf-ua-api`
|
|
96
|
-
(default: `http://localhost:
|
|
198
|
+
(default: `http://localhost:9999`, override with `PDF_UA_API_PROXY_URL`).
|
|
97
199
|
|
|
98
200
|
## License
|
|
99
201
|
|