@topconsultnpm/sdkui-react 6.20.0-dev3.1 → 6.20.0-dev3.10

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.
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import styled from "styled-components";
3
3
  import { TMTooltip } from '../components';
4
4
  import { IconCADossier, IconKey, IconMenuCAWorkingGroups } from './TMIcons';
5
- import { AppModules, DataListCacheService, MetadataDataDomains, PdGs } from '@topconsultnpm/sdk-ts';
5
+ import { AppModules, DataListCacheService, LicenseModuleStatus, MetadataDataDomains, PdGs, SDK_Globals } from '@topconsultnpm/sdk-ts';
6
6
  import { SDKUI_Localizator } from './SDKUI_Localizator';
7
7
  const StyledIconFileContainer = styled.div `
8
8
  height: 22px;
@@ -178,6 +178,15 @@ export const isCreateCertificateEnabled = (widgetsString) => {
178
178
  export const isPdfEditorEnabled = (widgetsString) => {
179
179
  return isWidgetEnabled(PDF_EDITOR_ID, widgetsString);
180
180
  };
181
+ /** Verifica se l'editor PDF è disponibile: richiede file PDF, licenza attiva e widget abilitato sul tipo documento. */
182
+ export const isPdfEditorAvailable = (fromDTD, ext) => {
183
+ if (fromDTD === undefined || !fromDTD.widgets || !ext)
184
+ return false;
185
+ if (ext.toLowerCase() !== "pdf")
186
+ return false;
187
+ const isPdfEditorLicensed = SDK_Globals?.license?.dcmtArchiveLicenses?.[0]?.siX_60007?.status === LicenseModuleStatus.Licensed;
188
+ return isPdfEditorLicensed && isPdfEditorEnabled(fromDTD.widgets);
189
+ };
181
190
  export const StyledTabItem = styled.div `
182
191
  display: flex;
183
192
  align-items: center;
@@ -215,177 +224,79 @@ export const getPdgsIconMap = (fontSize = 20) => {
215
224
  [PdGs.WG, _jsx(IconMenuCAWorkingGroups, { color: PDGS_COLORS.WORKING_GROUP, fontSize: 28 }, "PdGs-WG")],
216
225
  ]);
217
226
  };
218
- /**
219
- * Analizza e configura i parametri delle informazioni di firma per un documento.
220
- *
221
- * @param did - ID del documento
222
- * @param informationSign - Stringa di configurazione della firma
223
- * @param firstName - Nome del firmatario
224
- * @param lastName - Cognome del firmatario
225
- * @param title - Titolo del documento (per messaggi di errore)
226
- *
227
- * @returns Oggetto contenente le configurazioni dei campi della firma
228
- *
229
- * @example
230
- * // Formati supportati:
231
- *
232
- * // 1. Configurazione predefinita (vuoto o undefined): solo data attiva
233
- * parseSignatureConfiguration(1, undefined, "Mario", "Rossi", "Doc1")
234
- *
235
- * // 2. "All" - Tutti i campi attivi con valori di default
236
- * parseSignatureConfiguration(1, "All", "Mario", "Rossi", "Doc1")
237
- *
238
- * // 3. "None" - Nessun campo attivo
239
- * parseSignatureConfiguration(1, "None", "Mario", "Rossi", "Doc1")
240
- *
241
- * // 4. Formato con valori espliciti: Key=Value
242
- * parseSignatureConfiguration(1, "Date=Yes,SignerBy=Mario,Location=Milano,Copyright=TopConsult", ...)
243
- *
244
- * // 5. Formato chiavi semplici (attiva i default): key1,key2,key3
245
- * parseSignatureConfiguration(1, "date,signerby,location", "Mario", "Rossi", "Doc1")
246
- *
247
- * // 6. Formato misto
248
- * parseSignatureConfiguration(1, "date,SignerBy=Yes,Location=Roma", "Mario", "Rossi", "Doc1")
249
- */
250
- export const parseSignatureConfiguration = (did, informationSign, firstName, lastName, title) => {
251
- try {
252
- // Rimuove spazi dalla stringa di input mantenendo il case originale
253
- const signatureSign = informationSign?.trim();
254
- // Definisce i valori di default per ciascun campo
255
- const defaultLocationValue = SDKUI_Localizator.Torino;
256
- const defaultCopyrightValue = "Sign4Top";
257
- const defaultSignerByValue = `${firstName ?? ''} ${lastName ?? ''}`.trim() || '';
258
- // Configurazione di default: solo data attiva
259
- const defaultInfo = {
260
- allowDate: true,
261
- allowSignerBy: false,
262
- signerByValue: defaultSignerByValue,
263
- allowLocation: false,
264
- locationValue: defaultLocationValue,
265
- allowCopyright: false,
266
- copyrightValue: defaultCopyrightValue
267
- };
268
- // Se la stringa è vuota o non definita, ritorna la configurazione di default
269
- if (!signatureSign || signatureSign.length === 0) {
270
- return defaultInfo;
271
- }
272
- // Caso speciale: "all" attiva tutti i campi con valori di default
273
- if (signatureSign.toLowerCase() === "all") {
274
- return {
275
- allowDate: true,
276
- allowSignerBy: true,
277
- signerByValue: defaultSignerByValue,
278
- allowLocation: true,
279
- locationValue: defaultLocationValue,
280
- allowCopyright: true,
281
- copyrightValue: defaultCopyrightValue
282
- };
227
+ export const parseSignatureConfiguration = (did, informationSign, title) => {
228
+ const signatureSign = informationSign?.trim() || "";
229
+ if (!signatureSign)
230
+ return {};
231
+ const infoParts = signatureSign.split(',').map(part => part.trim()).filter(Boolean);
232
+ const allowedKeys = ["copyright", "date", "location"];
233
+ const allowedDateValues = ["no", "yes", "true", "false", ""];
234
+ const invalidKeys = [];
235
+ const invalidDateValues = [];
236
+ for (const part of infoParts) {
237
+ const [key, ...valueParts] = part.split("=");
238
+ const currentKey = key.trim().toLowerCase();
239
+ const rawValue = valueParts.join("=").trim();
240
+ const currentValue = rawValue.replace(/^["']|["']$/g, "").toLowerCase();
241
+ if (!allowedKeys.includes(currentKey)) {
242
+ invalidKeys.push(key.trim());
283
243
  }
284
- // Caso speciale: "none" disattiva tutti i campi
285
- if (signatureSign.toLowerCase() === "none") {
286
- return {
287
- allowDate: false,
288
- allowSignerBy: false,
289
- signerByValue: defaultSignerByValue,
290
- allowLocation: false,
291
- locationValue: defaultLocationValue,
292
- allowCopyright: false,
293
- copyrightValue: defaultCopyrightValue
294
- };
244
+ else if (currentKey === "date" && !allowedDateValues.includes(currentValue)) {
245
+ invalidDateValues.push(rawValue);
295
246
  }
296
- // Chiavi ammesse per la configurazione
297
- const allowedKeys = ["date", "signerby", "location", "copyright"];
298
- // Suddivisione della stringa in parti separate da virgola
299
- const infoParts = signatureSign.split(',').map(part => part.trim()).filter(Boolean);
300
- // Validazione preventiva di tutte le chiavi
301
- const invalidKeys = [];
302
- for (const part of infoParts) {
303
- const [key] = part.split("=");
304
- const currentKey = key.trim().toLowerCase();
305
- if (!allowedKeys.includes(currentKey)) {
306
- invalidKeys.push(key.trim());
247
+ }
248
+ if (invalidKeys.length > 0) {
249
+ throw new Error(`${invalidKeys.length > 1 ? 'I parametri' : 'Il parametro'} "${invalidKeys.join('", "')}" non ${invalidKeys.length > 1 ? 'sono riconosciuti' : 'è riconosciuto'} nel campo "informationSign" per il documento "${title || did}". ` +
250
+ `I parametri ammessi sono: ${allowedKeys.join(", ")}. ` +
251
+ `Il valore attuale del campo è "${informationSign}"`);
252
+ }
253
+ if (invalidDateValues.length > 0) {
254
+ throw new Error(`${invalidDateValues.length > 1 ? 'I valori' : 'Il valore'} "${invalidDateValues.join('", "')}" non ${invalidDateValues.length > 1 ? 'sono validi' : 'è valido'} per il parametro "date" nel campo "informationSign" per il documento "${title || did}". ` +
255
+ `I valori ammessi per "date" sono: ${allowedDateValues.filter(v => v).join(", ")}. ` +
256
+ `Il valore attuale del campo è "${informationSign}"`);
257
+ }
258
+ // DEFAULT
259
+ let result = {
260
+ copyright: "",
261
+ date: false,
262
+ location: ""
263
+ };
264
+ const parseBooleanOrValue = (value) => {
265
+ const valueLower = value.toLowerCase();
266
+ if (valueLower === "no" || valueLower === "false")
267
+ return { enabled: false };
268
+ if (valueLower === "yes" || valueLower === "true" || !value)
269
+ return { enabled: true };
270
+ return { enabled: true, customValue: value };
271
+ };
272
+ for (const part of infoParts) {
273
+ const [key, ...valueParts] = part.split("=");
274
+ const currentKey = key.trim().toLowerCase();
275
+ const rawValue = valueParts.join("=").trim();
276
+ const currentValue = rawValue.replace(/^["']|["']$/g, "");
277
+ switch (currentKey) {
278
+ case "date": {
279
+ const parsed = parseBooleanOrValue(currentValue);
280
+ result.date = parsed.enabled;
281
+ break;
307
282
  }
308
- }
309
- // Se ci sono chiavi non valide, lancia un errore unico
310
- if (invalidKeys.length > 0) {
311
- throw new Error(`${invalidKeys.length > 1 ? 'I parametri' : 'Il parametro'} "${invalidKeys.join('", "')}" non ${invalidKeys.length > 1 ? 'sono riconosciuti' : 'è riconosciuto'} nel campo "informationSign" per il documento "${title || did}". ` +
312
- `I parametri ammessi sono: ${allowedKeys.join(", ")}. ` +
313
- `Il valore attuale del campo è "${informationSign}"`);
314
- }
315
- // Clone della configurazione di default per la modifica
316
- const info = { ...defaultInfo };
317
- // Itera su ogni parte della configurazione
318
- for (const part of infoParts) {
319
- const [key, ...valueParts] = part.split("=");
320
- const currentKey = key.trim().toLowerCase();
321
- // Ricostruisce il valore nel caso contenga "=" al suo interno
322
- const rawValue = valueParts.join("=").trim();
323
- // Rimuove le virgolette dall'inizio e dalla fine del valore
324
- const currentValue = rawValue.replace(/^["']|["']$/g, "");
325
- // Helper per gestire i valori booleani e custom
326
- const parseBooleanOrValue = (value) => {
327
- const valueLower = value.toLowerCase();
328
- if (valueLower === "no" || valueLower === "false")
329
- return { enabled: false };
330
- if (valueLower === "yes" || valueLower === "true" || !value)
331
- return { enabled: true };
332
- return { enabled: true, customValue: value };
333
- };
334
- // Processa ciascuna chiave in base al tipo
335
- if (part.includes("=")) {
336
- // Formato: Key=Value
337
- switch (currentKey) {
338
- case "date":
339
- // Data supporta solo Yes/No/True/False
340
- const dateLower = currentValue.toLowerCase();
341
- info.allowDate = dateLower === "yes" || dateLower === "true";
342
- break;
343
- case "signerby": {
344
- const parsed = parseBooleanOrValue(currentValue);
345
- info.allowSignerBy = parsed.enabled;
346
- info.signerByValue = parsed.customValue || defaultSignerByValue;
347
- break;
348
- }
349
- case "location": {
350
- const parsed = parseBooleanOrValue(currentValue);
351
- info.allowLocation = parsed.enabled;
352
- info.locationValue = parsed.customValue || defaultLocationValue;
353
- break;
354
- }
355
- case "copyright": {
356
- const parsed = parseBooleanOrValue(currentValue);
357
- info.allowCopyright = parsed.enabled;
358
- info.copyrightValue = parsed.customValue || defaultCopyrightValue;
359
- break;
360
- }
361
- }
283
+ case "location": {
284
+ const parsed = parseBooleanOrValue(currentValue);
285
+ result.location = parsed.enabled
286
+ ? parsed.customValue || ""
287
+ : "";
288
+ break;
362
289
  }
363
- else {
364
- // Formato: Key (attiva il campo con valore di default)
365
- switch (currentKey) {
366
- case "date":
367
- info.allowDate = true;
368
- break;
369
- case "signerby":
370
- info.allowSignerBy = true;
371
- info.signerByValue = defaultSignerByValue;
372
- break;
373
- case "location":
374
- info.allowLocation = true;
375
- info.locationValue = defaultLocationValue;
376
- break;
377
- case "copyright":
378
- info.allowCopyright = true;
379
- info.copyrightValue = defaultCopyrightValue;
380
- break;
381
- }
290
+ case "copyright": {
291
+ const parsed = parseBooleanOrValue(currentValue);
292
+ result.copyright = parsed.enabled
293
+ ? parsed.customValue || ""
294
+ : "";
295
+ break;
382
296
  }
383
297
  }
384
- return info;
385
- }
386
- catch (error) {
387
- throw error;
388
298
  }
299
+ return result;
389
300
  };
390
301
  export const convertSearchResultDescriptorToFileItems = (documents) => {
391
302
  const fileItems = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topconsultnpm/sdkui-react",
3
- "version": "6.20.0-dev3.1",
3
+ "version": "6.20.0-dev3.10",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -1,9 +0,0 @@
1
- import { DcmtTypeDescriptor, SearchResultDescriptor } from "@topconsultnpm/sdk-ts";
2
- interface TMSignSettingsFormProps {
3
- fromDTD: DcmtTypeDescriptor;
4
- inputDcmts: any[];
5
- onCloseSignSettingsForm: () => void;
6
- onSavedAsyncCallback: ((tid: number | undefined, did: number | undefined, metadataResult?: SearchResultDescriptor | null) => Promise<void>);
7
- }
8
- declare const TMSignSettingsForm: (props: TMSignSettingsFormProps) => import("react/jsx-runtime").JSX.Element | null;
9
- export default TMSignSettingsForm;