@movalib/movalib-commons 1.55.5 → 1.55.7

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/PV_README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # 2. publish this movalib commons lib (public)
6
6
 
7
- ### `npm login`
7
+ ### `npm login` // if you have token in .npmrc this commande is useless
8
8
  ### `npm publish --access=public`
9
9
 
10
10
  # 3. publish this movalib commons lib (private)
@@ -13,4 +13,7 @@ type PLVComponentProps = {
13
13
  export declare class PLVComponent extends React.Component<PLVComponentProps> {
14
14
  render(): import("react/jsx-runtime").JSX.Element;
15
15
  }
16
+ export declare class PLVComponentV2 extends React.Component<PLVComponentProps> {
17
+ render(): import("react/jsx-runtime").JSX.Element;
18
+ }
16
19
  export {};
@@ -29,7 +29,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.PLVComponent = exports.PrintSize = void 0;
32
+ exports.PLVComponentV2 = exports.PLVComponent = exports.PrintSize = void 0;
33
33
  var jsx_runtime_1 = require("react/jsx-runtime");
34
34
  var material_1 = require("@mui/material");
35
35
  var react_1 = __importDefault(require("react"));
@@ -138,8 +138,22 @@ var PLVComponent = /** @class */ (function (_super) {
138
138
  return PLVComponent;
139
139
  }(react_1.default.Component));
140
140
  exports.PLVComponent = PLVComponent;
141
+ var PLVComponentV2 = /** @class */ (function (_super) {
142
+ __extends(PLVComponentV2, _super);
143
+ function PLVComponentV2() {
144
+ return _super !== null && _super.apply(this, arguments) || this;
145
+ }
146
+ PLVComponentV2.prototype.render = function () {
147
+ return ((0, jsx_runtime_1.jsx)("div", __assign({ className: 'printable-content', style: {
148
+ width: this.props.printSize === PrintSize.A4 ? '210mm' : this.props.printSize === PrintSize.A3 ? '297mm' : '0mm',
149
+ height: this.props.printSize === PrintSize.A4 ? '297mm' : this.props.printSize === PrintSize.A3 ? '420mm' : '0mm',
150
+ } }, { children: (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ container: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12 }, { children: (0, jsx_runtime_1.jsx)("img", { src: this.props.url, style: { display: 'block', width: '100%', height: '100%', objectFit: 'cover' } }) })) })) })));
151
+ };
152
+ return PLVComponentV2;
153
+ }(react_1.default.Component));
154
+ exports.PLVComponentV2 = PLVComponentV2;
141
155
  // CSS pour cacher le contenu à l'écran mais le rendre imprimable
142
- var css = "\n .highlight {\n background-color: #BCD46C; /* Couleur de surlignage */\n margin: 4px 4px; /* Espacement autour du texte surlign\u00E9 */\n padding-left : 8px;\n padding-right: 8px;\n font-weight: 500;\n color: white;\n }\n .not-highlight {\n margin: 4px 4px; /* Espacement autour du texte surlign\u00E9 */\n padding-left : 8px;\n padding-right: 8px;\n color: #BCD46C;\n }\n\n .printable-content {\n visibility: hidden;\n position: absolute;\n left: -10000px;\n top: -10000px;\n }\n @media print {\n .printable-content {\n visibility: visible;\n position: static;\n }\n }\n";
156
+ var css = "\nbody {\n margin: 0;\n }\n .highlight {\n background-color: #BCD46C; /* Couleur de surlignage */\n margin: 4px 4px; /* Espacement autour du texte surlign\u00E9 */\n padding-left : 8px;\n padding-right: 8px;\n font-weight: 500;\n color: white;\n }\n .not-highlight {\n margin: 4px 4px; /* Espacement autour du texte surlign\u00E9 */\n padding-left : 8px;\n padding-right: 8px;\n color: #BCD46C;\n }\n\n .printable-content {\n margin: 0;\n padding: 0;\n visibility: hidden;\n position: absolute;\n left: -10000px;\n top: -10000px;\n\n }\n @media print {\n body {\n margin: 0;\n }\n .printable-content {\n margin: 0;\n padding: 0;\n visibility: visible;\n position: static;\n }\n }\n";
143
157
  var styleSheet = document.createElement('style');
144
158
  styleSheet.innerText = css;
145
159
  document.head.appendChild(styleSheet);
@@ -10,6 +10,29 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
13
36
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
37
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
38
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -58,19 +81,26 @@ require("../../style/QRCode.css");
58
81
  var html2canvas_1 = __importDefault(require("html2canvas"));
59
82
  var qr_code_styling_1 = __importDefault(require("qr-code-styling"));
60
83
  var react_1 = require("react");
84
+ var react_to_print_1 = require("react-to-print");
61
85
  var DownloadedQRCode_1 = require("../../DownloadedQRCode");
62
86
  var leaf_yellow_small_png_1 = __importDefault(require("../../assets/images/leaf_yellow_small.png"));
63
87
  var Tools_1 = require("../../helpers/Tools");
64
88
  var pdf_lib_1 = require("pdf-lib");
65
- var DialogPrint_1 = require("../../utils/DialogPrint");
89
+ var PLVComponent_1 = require("./PLVComponent");
90
+ var pdfjsLib = __importStar(require("pdfjs-dist"));
91
+ pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdf.worker.mjs';
66
92
  var QrCodePLVContainer = function (_a) {
67
93
  var data = _a.data;
68
94
  var _b = (0, react_1.useState)(null), selectedChoice = _b[0], setSelectedChoice = _b[1];
95
+ var _c = (0, react_1.useState)(''), urlA4 = _c[0], setUrlA4 = _c[1];
96
+ var _d = (0, react_1.useState)(''), urlA3 = _d[0], setUrlA3 = _d[1];
97
+ var _e = (0, react_1.useState)(false), isReady = _e[0], setIsReady = _e[1];
69
98
  var qrCodeRef = (0, react_1.useRef)(null);
70
99
  var theme = (0, material_1.useTheme)();
100
+ var PLVrefA4 = (0, react_1.useRef)(null);
101
+ var PLVrefA3 = (0, react_1.useRef)(null);
71
102
  //si sur l'impression des PLV en A4 ou A3 le Qrcode est flou,
72
103
  //il faut modifier la width et height, imageSize du qrCodeOptions et mettre les mêmes valeurs que dans le optionQrcode de la fonction printPLV
73
- //
74
104
  var qrCodeOptions = (0, react_1.useMemo)(function () { return ({
75
105
  width: 300,
76
106
  height: 300,
@@ -110,9 +140,25 @@ var QrCodePLVContainer = function (_a) {
110
140
  qrCode.append(qrCodeRef.current);
111
141
  }
112
142
  }, [qrCode]);
143
+ (0, react_1.useEffect)(function () {
144
+ var urlA4 = printPLV('A4').then(function (url) {
145
+ setUrlA4(url);
146
+ });
147
+ var urlA3 = printPLV('A3').then(function (url) {
148
+ setUrlA3(url);
149
+ });
150
+ }, [data]);
151
+ (0, react_1.useEffect)(function () {
152
+ if (PLVrefA4.current || PLVrefA3.current) {
153
+ setIsReady(true);
154
+ }
155
+ else {
156
+ setIsReady(false);
157
+ }
158
+ }, [PLVrefA4.current, PLVrefA3.current]);
113
159
  function printPLV(format) {
114
160
  return __awaiter(this, void 0, void 0, function () {
115
- var pdfUrl, response, existingPdfBytes, pdfDoc, qrCodeBlob, qrImageBytes, qrImage, pages, firstPage, _a, width, height, optionQrcode, modifiedPdfBytes, blob, url;
161
+ var pdfUrl, response, existingPdfBytes, pdfDoc, qrCodeBlob, qrImageBytes, qrImage, pages, firstPage, _a, width, height, optionQrcode, modifiedPdfBytes, blob, url, loadingTask, pdf, page, canvas, context, viewport, renderContext, imageUrl;
116
162
  return __generator(this, function (_b) {
117
163
  switch (_b.label) {
118
164
  case 0:
@@ -162,9 +208,27 @@ var QrCodePLVContainer = function (_a) {
162
208
  modifiedPdfBytes = _b.sent();
163
209
  blob = new Blob([modifiedPdfBytes], { type: 'application/pdf' });
164
210
  url = URL.createObjectURL(blob);
165
- // Ouvrir la page d'impression
166
- (0, DialogPrint_1.openDialogPrint)(url);
167
- return [2 /*return*/];
211
+ loadingTask = pdfjsLib.getDocument(url);
212
+ return [4 /*yield*/, loadingTask.promise];
213
+ case 8:
214
+ pdf = _b.sent();
215
+ return [4 /*yield*/, pdf.getPage(1)];
216
+ case 9:
217
+ page = _b.sent();
218
+ canvas = document.createElement('canvas');
219
+ context = canvas.getContext('2d');
220
+ viewport = page.getViewport({ scale: 4 });
221
+ canvas.width = viewport.width;
222
+ canvas.height = viewport.height;
223
+ renderContext = {
224
+ canvasContext: context,
225
+ viewport: viewport,
226
+ };
227
+ return [4 /*yield*/, page.render(renderContext).promise];
228
+ case 10:
229
+ _b.sent();
230
+ imageUrl = canvas.toDataURL('image/png');
231
+ return [2 /*return*/, imageUrl];
168
232
  }
169
233
  });
170
234
  });
@@ -206,12 +270,20 @@ var QrCodePLVContainer = function (_a) {
206
270
  var onChangeSelectedChoice = function (e) {
207
271
  setSelectedChoice(e.target.value);
208
272
  };
273
+ var printA3PLV = (0, react_to_print_1.useReactToPrint)({
274
+ content: function () { return PLVrefA3.current; },
275
+ documentTitle: 'Movalib_PLV_A3',
276
+ });
277
+ var printA4PLV = (0, react_to_print_1.useReactToPrint)({
278
+ content: function () { return PLVrefA4.current; },
279
+ documentTitle: 'Movalib_PLV_A4',
280
+ });
209
281
  var onClickDownload = (0, react_1.useMemo)(function () {
210
282
  switch (selectedChoice) {
211
283
  case 'A3':
212
- return function () { printPLV('A3'); };
284
+ return printA3PLV;
213
285
  case 'A4':
214
- return function () { printPLV('A4'); };
286
+ return printA4PLV;
215
287
  case 'QR_Headless':
216
288
  return downloadQRCodeHeadless;
217
289
  case 'QR_Google':
@@ -219,8 +291,8 @@ var QrCodePLVContainer = function (_a) {
219
291
  default:
220
292
  return function () { };
221
293
  }
222
- }, [selectedChoice, downloadQRCodeHeadless, downloadQrCodeWithCTA]);
223
- return ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '24px' }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, justifyContent: 'center', alignItems: 'center' }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 7 }, { children: (0, jsx_runtime_1.jsxs)(material_1.FormControl, __assign({ fullWidth: true, size: 'small' }, { children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, __assign({ id: 'qrcode-plv-select' }, { children: "Choisissez votre support" })), (0, jsx_runtime_1.jsxs)(material_1.Select, __assign({ labelId: 'qrcode-plv-select', label: 'Choisissez votre support', id: 'qrcode-plv-select', onChange: onChangeSelectedChoice, value: selectedChoice }, { children: [(0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: 'A4' }, { children: "\uD83E\uDDFE\u00A0\u00A0PLV format A4" })), (0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: 'A3' }, { children: "\uD83E\uDDFE\u00A0\u00A0PLV format A3" })), (0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: 'QR_Google' }, { children: "QR Code format GoogleMyBusiness" })), (0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: 'QR_Headless' }, { children: "QR Code seul" }))] }))] })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 4, marginLeft: 3 }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, __assign({ startIcon: selectedChoice === 'A3' || selectedChoice === 'A4' ? (0, jsx_runtime_1.jsx)(icons_material_1.DocumentScanner, {}) : (0, jsx_runtime_1.jsx)(icons_material_1.QrCode2, {}), onClick: onClickDownload, variant: 'outlined', disabled: !selectedChoice, sx: { color: (0, material_1.darken)(theme.palette.primary.main, 0.2), borderRadius: '10rem' } }, { children: selectedChoice === 'A3' || selectedChoice === 'A4' ? 'Imprimer' : 'Télécharger' })) }))] })), (0, jsx_runtime_1.jsx)("div", __assign({ id: 'qr-code-container', style: Tools_1.flexCenter }, { children: (0, jsx_runtime_1.jsx)("div", { ref: qrCodeRef, style: {
294
+ }, [selectedChoice, downloadQRCodeHeadless, downloadQrCodeWithCTA, printA3PLV, printA4PLV]);
295
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '24px' }, { children: [urlA4 && (0, jsx_runtime_1.jsx)(PLVComponent_1.PLVComponentV2, { ref: PLVrefA4, url: urlA4, printSize: PLVComponent_1.PrintSize.A4 }), urlA3 && (0, jsx_runtime_1.jsx)(PLVComponent_1.PLVComponentV2, { ref: PLVrefA3, url: urlA3, printSize: PLVComponent_1.PrintSize.A3 }), (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, justifyContent: 'center', alignItems: 'center' }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 7 }, { children: (0, jsx_runtime_1.jsxs)(material_1.FormControl, __assign({ fullWidth: true, size: 'small' }, { children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, __assign({ id: 'qrcode-plv-select' }, { children: "Choisissez votre support" })), (0, jsx_runtime_1.jsxs)(material_1.Select, __assign({ labelId: 'qrcode-plv-select', label: 'Choisissez votre support', id: 'qrcode-plv-select', onChange: onChangeSelectedChoice, value: selectedChoice }, { children: [(0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: 'A4' }, { children: "\uD83E\uDDFE\u00A0\u00A0PLV format A4" })), (0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: 'A3' }, { children: "\uD83E\uDDFE\u00A0\u00A0PLV format A3" })), (0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: 'QR_Google' }, { children: "QR Code format GoogleMyBusiness" })), (0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: 'QR_Headless' }, { children: "QR Code seul" }))] }))] })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 4, marginLeft: 3 }, { children: (selectedChoice === 'A3' || selectedChoice === 'A4') && !isReady ? ((0, jsx_runtime_1.jsx)(material_1.CircularProgress, {})) : ((0, jsx_runtime_1.jsx)(material_1.Button, __assign({ startIcon: selectedChoice === 'A3' || selectedChoice === 'A4' ? (0, jsx_runtime_1.jsx)(icons_material_1.DocumentScanner, {}) : (0, jsx_runtime_1.jsx)(icons_material_1.QrCode2, {}), onClick: onClickDownload, variant: 'outlined', disabled: !selectedChoice || ((selectedChoice === 'A3' || selectedChoice === 'A4') && !isReady), sx: { color: (0, material_1.darken)(theme.palette.primary.main, 0.2), borderRadius: '10rem' } }, { children: selectedChoice === 'A3' || selectedChoice === 'A4' ? 'Imprimer' : 'Télécharger' }))) }))] })), (0, jsx_runtime_1.jsx)("div", __assign({ id: 'qr-code-container', style: Tools_1.flexCenter }, { children: (0, jsx_runtime_1.jsx)("div", { ref: qrCodeRef, style: {
224
296
  height: '300px',
225
297
  width: '300px',
226
298
  maxWidth: '300px !important',
@@ -4,7 +4,6 @@ export type APIResponse<T> = {
4
4
  success: boolean;
5
5
  data?: T;
6
6
  error?: string;
7
- location?: string | null;
8
7
  };
9
8
  export type APIRequest = {
10
9
  url: string;
@@ -12,14 +12,13 @@ function handleError(error) {
12
12
  var msg = error.message.includes('fetch') ? "Connexion impossible" : error.message;
13
13
  return {
14
14
  success: false,
15
- error: msg,
15
+ error: msg
16
16
  };
17
17
  }
18
18
  function handleResponse(response) {
19
19
  var contentType = response.headers.get("content-type");
20
20
  var isJson = contentType && contentType.includes("application/json");
21
21
  var dataPromise = isJson ? response.json() : response.text();
22
- var location = response.headers.get('Location');
23
22
  return dataPromise.then(function (data) {
24
23
  if (!response.ok) {
25
24
  Logger_1.default.error(data);
@@ -40,7 +39,7 @@ function handleResponse(response) {
40
39
  }
41
40
  return { success: false, error: errorMsg };
42
41
  }
43
- return { success: true, data: data, location: location };
42
+ return { success: true, data: data };
44
43
  });
45
44
  }
46
45
  /**
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.openDialogPrint = void 0;
4
4
  function openDialogPrint(url) {
5
+ // Créer un iframe pour charger le document Blob => url
5
6
  var iframe = document.createElement('iframe');
6
7
  iframe.style.position = 'absolute';
7
8
  iframe.style.width = '0px';
@@ -13,7 +14,7 @@ function openDialogPrint(url) {
13
14
  var _a;
14
15
  (_a = iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.print();
15
16
  };
16
- // Supprimer l'iframe une fois l'impression terminée
17
+ // Supprimer l'iframe une fois lque la dialog est fermer
17
18
  iframe.onclose = function () {
18
19
  document.body.removeChild(iframe);
19
20
  URL.revokeObjectURL(url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.55.5",
3
+ "version": "1.55.7",
4
4
  "description": "Bibliothèque d'objets communs à l'ensemble des projets React de Movalib",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "@emotion/react": "^11.11.1",
20
20
  "@emotion/styled": "^11.11.0",
21
- "@mui/icons-material": "^5.11.16",
21
+ "@mui/icons-material": "^5.11.17",
22
22
  "@mui/lab": "^5.0.0-alpha.134",
23
23
  "@mui/material": "^5.13.5",
24
24
  "@mui/x-date-pickers": "^6.9.1",
@@ -31,6 +31,7 @@
31
31
  "html2canvas": "^1.4.1",
32
32
  "js-cookie": "^3.0.5",
33
33
  "pdf-lib": "^1.17.1",
34
+ "pdfjs-dist": "^4.6.82",
34
35
  "qr-code-styling": "^1.4.4",
35
36
  "react": "^18.2.0",
36
37
  "react-dom": "^18.2.0",
@@ -47,6 +48,7 @@
47
48
  },
48
49
  "devDependencies": {
49
50
  "@types/js-cookie": "^3.0.4",
51
+ "@types/pdfjs-dist": "^2.10.377",
50
52
  "@types/react-input-mask": "^3.0.5",
51
53
  "html-webpack-plugin": "^5.5.3",
52
54
  "ts-loader": "^9.4.4",