Skip to content

Commit b6db10f

Browse files
committed
chore: migrate example app
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 4131e08 commit b6db10f

9 files changed

Lines changed: 62 additions & 150 deletions

File tree

examples/basic/App.vue

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ SPDX-License-Identifier: AGPL-3.0-or-later
5656
</div>
5757
</template>
5858

59-
<script>
60-
import Vue from 'vue'
59+
<script lang="ts">
60+
import { defineComponent } from 'vue'
6161
import PDFElements from '../../src'
6262
import AppToolbar from './components/AppToolbar.vue'
6363
import DocumentsList from './components/DocumentsList.vue'
6464
import SignatureBox from './components/SignatureBox.vue'
6565
import DeleteButton from './components/DeleteButton.vue'
6666
import ElementsViewer from './components/ElementsViewer.vue'
6767
68-
export default {
68+
export default defineComponent({
6969
name: 'App',
7070
components: {
7171
PDFElements,
@@ -110,15 +110,18 @@ export default {
110110
},
111111
112112
onFilesChange(event) {
113-
const files = Array.from(event.target.files || [])
113+
const input = event?.target as HTMLInputElement | null
114+
const files = Array.from(input?.files || [])
114115
if (files.length === 0) return
115116
116117
this.loading = true
117118
this.pdfReady = false
118119
this.initFiles = [...this.initFiles, ...files]
119-
this.fileNames = [...this.fileNames, ...files.map(f => f.name)]
120+
this.fileNames = [...this.fileNames, ...files.map((file: File) => file.name)]
120121
this.forceRenderDocuments()
121-
event.target.value = ''
122+
if (input) {
123+
input.value = ''
124+
}
122125
},
123126
124127
removeDocument(index) {
@@ -192,9 +195,7 @@ export default {
192195
this.showElementsViewer = true
193196
},
194197
},
195-
}
196-
197-
Vue.config.productionTip = false
198+
})
198199
</script>
199200

200201
<style scoped>

examples/basic/README.md

Lines changed: 24 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
# Basic Example - @libresign/pdf-elements
22

3-
Basic integration example of the `PDFElements` component with dragging, resizing, and positioning elements in PDFs.
3+
This example shows how to integrate `PDFElements` with custom slots and basic actions.
44

55
## Structure
66

77
```
88
examples/basic/
9-
├── App.vue # Main component: PDFElements integration
9+
├── App.vue
1010
├── components/
11-
│ ├── AppToolbar.vue # Toolbar component
12-
│ ├── DocumentsList.vue # List of loaded documents
13-
│ ├── SignatureBox.vue # Custom visual element
14-
│ └── DeleteButton.vue # Delete button
11+
│ ├── AppToolbar.vue
12+
│ ├── DocumentsList.vue
13+
│ ├── SignatureBox.vue
14+
│ └── DeleteButton.vue
1515
└── README.md
1616
```
1717

18-
## How to Use PDFElements
18+
## Quick start
1919

20-
### 1. Import the component
20+
Import the component:
2121

2222
```vue
2323
import PDFElements from '@libresign/pdf-elements'
2424
```
2525

26-
### 2. Basic template
26+
Basic template:
2727

2828
```vue
2929
<PDFElements
@@ -33,8 +33,8 @@ import PDFElements from '@libresign/pdf-elements'
3333
:initial-scale="1.1"
3434
@pdf-elements:end-init="onReady"
3535
>
36-
<template #custom="{ object, isSelected }">
37-
<!-- Your component here -->
36+
<template #custom="{ object }">
37+
<SignatureBox :object="object" />
3838
</template>
3939
4040
<template #actions="{ onDelete }">
@@ -43,136 +43,40 @@ import PDFElements from '@libresign/pdf-elements'
4343
</PDFElements>
4444
```
4545

46-
### 3. Main props
47-
48-
- **`init-files`**: Array of PDF URLs or File objects
49-
- **`init-file-names`**: Array with document names
50-
- **`initial-scale`**: Initial rendering scale (default: 1)
51-
52-
### 4. Events
46+
## Props and event
5347

54-
- **`pdf-elements:end-init`**: Triggered when PDFs finish loading
48+
- `init-files`: PDF URLs or files.
49+
- `init-file-names`: names shown in the footer.
50+
- `initial-scale`: initial zoom.
51+
- `pdf-elements:end-init`: emitted when the PDF finishes loading.
5552

56-
### 5. Ref methods
53+
## Methods via `ref`
5754

58-
```javascript
55+
```js
5956
const pdf = this.$refs.pdf
6057

61-
// Iniciar modo de adicionar elemento (com preview que segue o mouse)
6258
pdf.startAddingElement({
6359
width: 160,
6460
height: 48,
6561
label: 'Signature',
6662
icon: 'signature',
6763
})
6864

69-
// Obter todos os objetos do documento
7065
const objects = pdf.getAllObjects()
7166
```
7267

73-
### 6. Slots
68+
## Slots
69+
70+
For specific types, use `element-{type}`. Example for signature:
7471

75-
#### Type-specific slots (recommended for multiple element types)
7672
```vue
77-
<!-- Slot for signature elements -->
7873
<template #element-signature="{ object }">
7974
<SignatureBox :object="object" />
8075
</template>
81-
82-
<!-- Slot for text elements -->
83-
<template #element-text="{ object }">
84-
<TextBox :object="object" />
85-
</template>
86-
87-
<!-- Slot for date elements -->
88-
<template #element-date="{ object }">
89-
<DateBox :object="object" />
90-
</template>
91-
```
92-
93-
When an object has `type: 'signature'`, PDFElements looks for `#element-signature`. If not found, uses the `#custom` fallback.
94-
95-
#### `#custom` - Generic rendering (fallback)
96-
Used when:
97-
- The object doesn't have a `type` property
98-
- No specific slot exists for the type
99-
100-
Receives:
101-
- `object`: Element data (x, y, width, height, type, custom props)
102-
- `isSelected`: Boolean indicating if selected
103-
104-
#### `#actions` - Action toolbar
105-
Receives:
106-
- `object`: Element data
107-
- `onDelete`: Function to delete the element
108-
109-
### Multiple types example
110-
111-
```vue
112-
<PDFElements ref="pdf" :init-files="files">
113-
<!-- Signature elements -->
114-
<template #element-signature="{ object }">
115-
<div class="signature-box">
116-
<SignIcon />
117-
{{ object.label }}
118-
</div>
119-
</template>
120-
121-
<!-- Text input elements -->
122-
<template #element-text="{ object }">
123-
<div class="text-box">
124-
<input :value="object.value" />
125-
</div>
126-
</template>
127-
128-
<!-- Date picker elements -->
129-
<template #element-date="{ object }">
130-
<div class="date-box">
131-
<CalendarIcon />
132-
{{ object.date || 'Select date' }}
133-
</div>
134-
</template>
135-
136-
<!-- Checkbox elements -->
137-
<template #element-checkbox="{ object }">
138-
<div class="checkbox-box">
139-
<input type="checkbox" :checked="object.checked" />
140-
</div>
141-
</template>
142-
143-
<!-- Fallback for unknown types -->
144-
<template #custom="{ object }">
145-
<div class="generic-box">
146-
{{ object.type || 'Element' }}
147-
</div>
148-
</template>
149-
150-
<!-- Common actions for all types -->
151-
<template #actions="{ onDelete }">
152-
<button @click="onDelete">Delete</button>
153-
</template>
154-
</PDFElements>
15576
```
15677

157-
**Performance**: Slots dinâmicos são eficientes - Vue compila apenas os slots usados. Muito melhor que condicionais enormes.
158-
159-
## Funcionalidades Implementadas
160-
161-
**Carregar múltiplos PDFs** (URL ou arquivo local)
162-
**Adicionar elementos com preview** (clique no botão → move o mouse → clique para posicionar)
163-
**Arrastar elementos** dentro da mesma página ou entre páginas diferentes
164-
**Redimensionar elementos** (4 cantos, mantém aspect-ratio)
165-
**Validação de bounds** (elementos não podem sair das páginas)
166-
**Elementos responsivos** (texto ajusta tamanho conforme dimensões)
167-
**Toolbar flutuante** com ações (aparece ao selecionar elemento)
168-
**Rolagem durante drag** (atualiza posições automaticamente)
169-
170-
## Componentes Auxiliares
78+
If there is no specific slot, `#custom` is used as a fallback.
17179

172-
Os componentes em `components/` são **apenas para o exemplo**. Você pode:
173-
- Usar seus próprios componentes
174-
- Estilizar da forma que preferir
175-
- Adicionar mais ações no toolbar
176-
- Customizar totalmente o visual dos elementos
80+
## Notes
17781

178-
O importante é entender como usar o `PDFElements` no `App.vue`.
82+
Components under `components/` are just for the example and can be replaced freely.

examples/basic/components/AppToolbar.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
</header>
3232
</template>
3333

34-
<script>
35-
export default {
34+
<script lang="ts">
35+
import { defineComponent } from 'vue'
36+
37+
export default defineComponent({
3638
name: 'AppToolbar',
3739
props: {
3840
loading: {
@@ -48,7 +50,7 @@ export default {
4850
default: false,
4951
},
5052
},
51-
}
53+
})
5254
</script>
5355

5456
<style scoped>

examples/basic/components/DeleteButton.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
</button>
77
</template>
88

9-
<script>
10-
export default {
9+
<script lang="ts">
10+
import { defineComponent } from 'vue'
11+
12+
export default defineComponent({
1113
name: 'DeleteButton',
12-
}
14+
})
1315
</script>
1416

1517
<style scoped>

examples/basic/components/DocumentsList.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010
</section>
1111
</template>
1212

13-
<script>
14-
export default {
13+
<script lang="ts">
14+
import { defineComponent } from 'vue'
15+
16+
export default defineComponent({
1517
name: 'DocumentsList',
1618
props: {
1719
documents: {
1820
type: Array,
1921
default: () => [],
2022
},
2123
},
22-
}
24+
})
2325
</script>
2426

2527
<style scoped>

examples/basic/components/ElementsViewer.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@
5151
</div>
5252
</template>
5353

54-
<script>
55-
export default {
54+
<script lang="ts">
55+
import { defineComponent } from 'vue'
56+
57+
export default defineComponent({
5658
name: 'ElementsViewer',
5759
props: {
5860
isOpen: {
@@ -100,7 +102,7 @@ export default {
100102
this.$emit('close')
101103
},
102104
},
103-
}
105+
})
104106
</script>
105107

106108
<style scoped>

examples/basic/components/SignatureBox.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
</div>
1515
</template>
1616

17-
<script>
18-
export default {
17+
<script lang="ts">
18+
import { defineComponent } from 'vue'
19+
20+
export default defineComponent({
1921
name: 'SignatureBox',
2022
props: {
2123
object: {
@@ -27,7 +29,7 @@ export default {
2729
default: '14px',
2830
},
2931
},
30-
}
32+
})
3133
</script>
3234

3335
<style scoped>

examples/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
<body>
1414
<noscript>This demo requires JavaScript.</noscript>
1515
<div id="app"></div>
16+
<script type="module" src="/main.ts"></script>
1617
</body>
1718
</html>
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
// SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
22
// SPDX-License-Identifier: AGPL-3.0-or-later
33

4-
import Vue from 'vue'
4+
import { createApp } from 'vue'
55
import App from './basic/App.vue'
66

7-
Vue.config.productionTip = false
8-
9-
new Vue({
10-
render: h => h(App),
11-
}).$mount('#app')
7+
createApp(App).mount('#app')

0 commit comments

Comments
 (0)