@dative-gpi/foundation-shared-components 1.0.130 → 1.0.131-kiosk-2

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.
@@ -0,0 +1,188 @@
1
+ <template>
2
+ <FSButton
3
+ prependIcon="mdi-printer-outline"
4
+ :label="$tr('ui.common.print', 'Print')"
5
+ :color="ColorEnum.Light"
6
+ v-bind="$attrs"
7
+ @click="buildPreview()"
8
+ />
9
+ <FSDialog
10
+ v-model="dialog"
11
+ :title="$tr('ui.common.print', 'Print')"
12
+ :width="800"
13
+ >
14
+ <template
15
+ #body
16
+ >
17
+ <FSLoader
18
+ v-if="loading"
19
+ width="100%"
20
+ height="400px"
21
+ />
22
+ <FSCol
23
+ v-show="!loading"
24
+ width="100%"
25
+ height="400px"
26
+ >
27
+ <FSText
28
+ :style="{ minHeight: '16px' }"
29
+ font="text-overline"
30
+ >
31
+ {{$tr('ui.print.preview', 'Preview')}}
32
+ </FSText>
33
+ <div
34
+ :style="{ width: '100%', overflow: 'scroll' }"
35
+ >
36
+ <FSCard
37
+ id="canvas-container"
38
+ :padding="margin"
39
+ >
40
+ </FSCard>
41
+ </div>
42
+ <FSRow
43
+ align="center-center"
44
+ >
45
+ <FSButton
46
+ :prependIcon="'mdi-printer-outline'"
47
+ :label="$tr('ui.common.print', 'Print')"
48
+ :color="ColorEnum.Primary"
49
+ @click="printCanvas()"
50
+ />
51
+ <FSButton
52
+ :prependIcon="'mdi-download'"
53
+ :label="$tr('ui.print.download-image', 'Download image')"
54
+ :color="ColorEnum.Primary"
55
+ @click="downloadCanvasImage()"
56
+ />
57
+ </FSRow>
58
+ </FSCol>
59
+ </template>
60
+ </FSDialog>
61
+ </template>
62
+
63
+ <script lang="ts">
64
+ import { computed, defineComponent, ref } from "vue";
65
+
66
+ import { ColorEnum } from "@dative-gpi/foundation-shared-components/models";
67
+
68
+ import html2canvas from 'html2canvas';
69
+
70
+ import FSButton from "../FSButton.vue";
71
+ import FSText from '@dative-gpi/foundation-shared-components/components/FSText.vue';
72
+ import FSCard from '@dative-gpi/foundation-shared-components/components/FSCard.vue';
73
+ import FSDialog from '@dative-gpi/foundation-shared-components/components/FSDialog.vue';
74
+ import FSLoader from '@dative-gpi/foundation-shared-components/components/FSLoader.vue';
75
+
76
+ export default defineComponent({
77
+ name: "FSButtonPrint",
78
+ components: {
79
+ FSButton,
80
+ FSDialog,
81
+ FSLoader,
82
+ FSText,
83
+ FSCard
84
+ },
85
+ props: {
86
+ elementToPrint: {
87
+ type: Object as () => HTMLElement | null,
88
+ default: null
89
+ },
90
+ disableInputs: {
91
+ type: Boolean,
92
+ default: true
93
+ }
94
+ },
95
+ setup(props) {
96
+ const margin = 16;
97
+
98
+ const dialog = ref(false);
99
+ const loading = ref(false);
100
+ // Set A4 size
101
+ const windowWidth = computed(() => {
102
+ return Math.round((297 / 25.4) * 96);
103
+ });
104
+
105
+ const ignoreElements = (element: Element) => {
106
+ if (props.disableInputs) {
107
+ return element.classList.contains("v-input");
108
+ }
109
+ return false;
110
+ }
111
+
112
+ const buildPreview = async () => {
113
+ loading.value = true;
114
+ const elementToPrint = props.elementToPrint || document.body;
115
+
116
+ const fullCanvas = await html2canvas(elementToPrint, {
117
+ backgroundColor: null,
118
+ windowWidth: windowWidth.value,
119
+ ignoreElements: ignoreElements
120
+ });
121
+
122
+ dialog.value = true;
123
+
124
+ setTimeout(() => {
125
+ setCanvas(fullCanvas);
126
+ }, 100);
127
+ };
128
+
129
+ const setCanvas = async (canvas: HTMLCanvasElement, count = 0) => {
130
+ const canvasContainer = document.getElementById("canvas-container");
131
+ if (!canvasContainer) {
132
+ if(count > 10) {
133
+ return;
134
+ }
135
+ return setCanvas(canvas, count++);
136
+ }
137
+ canvasContainer.innerHTML = "";
138
+ canvasContainer.appendChild(canvas);
139
+ loading.value = false;
140
+ };
141
+
142
+ const printCanvas = () => {
143
+ const canvas = document.getElementById("canvas-container")?.querySelector("canvas");
144
+
145
+ if (!canvas) {
146
+ return;
147
+ }
148
+
149
+ const dataUrl = canvas.toDataURL("image/png");
150
+ const windowContent = `<img width="100%" src="${dataUrl}" />`;
151
+ const printWindow = window.open("", "_blank", "width=600,height=600");
152
+ printWindow?.document.open();
153
+ printWindow?.document.write(windowContent);
154
+ printWindow?.document.close();
155
+
156
+ printWindow?.addEventListener("load", () => {
157
+ printWindow?.focus();
158
+ printWindow?.print();
159
+ printWindow?.close();
160
+ });
161
+ }
162
+
163
+ const downloadCanvasImage = () => {
164
+ const canvas = document.getElementById("canvas-container")?.querySelector("canvas");
165
+
166
+ if (!canvas) {
167
+ return;
168
+ }
169
+
170
+ const dataUrl = canvas.toDataURL("image/png");
171
+ const a = document.createElement("a");
172
+ a.href = dataUrl;
173
+ a.download = "image.png";
174
+ a.click();
175
+ }
176
+
177
+ return {
178
+ printCanvas,
179
+ buildPreview,
180
+ downloadCanvasImage,
181
+ dialog,
182
+ margin,
183
+ loading,
184
+ ColorEnum
185
+ }
186
+ }
187
+ });
188
+ </script>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dative-gpi/foundation-shared-components",
3
3
  "sideEffects": false,
4
- "version": "1.0.130",
4
+ "version": "1.0.131-kiosk-2",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -10,8 +10,8 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "@dative-gpi/foundation-shared-domain": "1.0.130",
14
- "@dative-gpi/foundation-shared-services": "1.0.130"
13
+ "@dative-gpi/foundation-shared-domain": "1.0.131-kiosk-2",
14
+ "@dative-gpi/foundation-shared-services": "1.0.131-kiosk-2"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "@dative-gpi/bones-ui": "^1.0.0",
@@ -35,5 +35,5 @@
35
35
  "sass": "1.71.1",
36
36
  "sass-loader": "13.3.2"
37
37
  },
38
- "gitHead": "fc680c25f1b54df6a7c9195343556c0c93f1454d"
38
+ "gitHead": "27d9fa68cb6522daa568677451418271bae620c5"
39
39
  }