@envisiongroup/porygon 1.0.0-rc.40 → 1.0.0-rc.41

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/dist/index.js CHANGED
@@ -1,17 +1,17 @@
1
- import { formatFileSize as o, getErrorMessage as t, getFileIconUrl as m } from "./react-components/commons/utils.js";
1
+ import { formatFileSize as o, getErrorMessage as t, getFileIconUrl as F } from "./react-components/commons/utils.js";
2
2
  import { EFWMessageBarManager as a } from "./react-components/forms/EFWMessageBarManager/EFWMessageBarManager.js";
3
- import { EFWButton as E } from "./react-components/buttons/EFWButton/EFWButton.js";
4
- import { useEFWButton as f } from "./react-components/buttons/EFWButton/EFWButton.hooks.js";
3
+ import { EFWButton as p } from "./react-components/buttons/EFWButton/EFWButton.js";
4
+ import { useEFWButton as l } from "./react-components/buttons/EFWButton/EFWButton.hooks.js";
5
5
  import { EFWDrawerButton as u } from "./react-components/buttons/EFWDrawerButton/EFWDrawerButton.js";
6
6
  import { EFWGroupButton as i } from "./react-components/buttons/EFWGroupButton/EFWGroupButton.js";
7
- import { EFWField as W } from "./react-components/fields/_shared/EFWField/EFWField.js";
7
+ import { EFWField as L } from "./react-components/fields/_shared/EFWField/EFWField.js";
8
8
  import { EFWAttachment as s } from "./react-components/fields/Attachments/EFWAttachments.js";
9
9
  import { getAttachmentsFormattedValue as g } from "./react-components/fields/Attachments/EFWAttachments.utils.js";
10
10
  import { EFWAttachmentsField as d } from "./react-components/fields/Attachments/EFWAttachmentsField.js";
11
11
  import { EFWDatePicker as O } from "./react-components/fields/DatePicker/EFWDatePicker.js";
12
- import { enLocalizedStrings as D, esLocalizedStrings as B, getDatePickerFormattedValue as S, ptLocalizedStrings as C } from "./react-components/fields/DatePicker/EFWDatePicker.utils.js";
12
+ import { enLocalizedStrings as D, esLocalizedStrings as B, getDatePickerFormattedValue as C, ptLocalizedStrings as S } from "./react-components/fields/DatePicker/EFWDatePicker.utils.js";
13
13
  import { EFWDatePickerField as N } from "./react-components/fields/DatePicker/EFWDatePickerField.js";
14
- import { EFWInput as V } from "./react-components/fields/Input/EFWInput.js";
14
+ import { EFWInput as b } from "./react-components/fields/Input/EFWInput.js";
15
15
  import { getInputFormattedValue as k } from "./react-components/fields/Input/EFWInput.utils.js";
16
16
  import { EFWInputField as R } from "./react-components/fields/Input/EFWInputField.js";
17
17
  import { EFWNumberInput as w } from "./react-components/fields/NumberInput/EFWNumberInput.js";
@@ -24,76 +24,80 @@ import { EFWTagPicker as Q } from "./react-components/fields/TagPicker/EFWTagPic
24
24
  import { getTagPickerFormattedValue as $ } from "./react-components/fields/TagPicker/EFWTagPicker.utils.js";
25
25
  import { EFWTagPickerField as re } from "./react-components/fields/TagPicker/EFWTagPickerField.js";
26
26
  import { EFWTextArea as te } from "./react-components/fields/TextArea/EFWTextArea.js";
27
- import { getTextAreaFormattedValue as Fe } from "./react-components/fields/TextArea/EFWTextArea.utils.js";
28
- import { EFWTextAreaField as pe } from "./react-components/fields/TextArea/EFWTextAreaField.js";
27
+ import { getTextAreaFormattedValue as me } from "./react-components/fields/TextArea/EFWTextArea.utils.js";
28
+ import { EFWTextAreaField as Ee } from "./react-components/fields/TextArea/EFWTextAreaField.js";
29
29
  import { getFormFieldDisplayText as xe } from "./react-components/forms/EFWForm/EFWForm.converter.js";
30
- import { useFormController as le } from "./react-components/forms/EFWForm/EFWForm.hooks.js";
30
+ import { useFormController as fe } from "./react-components/forms/EFWForm/EFWForm.hooks.js";
31
31
  import { EFWForm as Te } from "./react-components/forms/EFWForm/EFWForm.js";
32
- import { EFWFormMessageBarGroup as Le } from "./react-components/forms/EFWFormMessageBarGroup/EFWFormMessageBarGroup.js";
33
- import { useDrawer as ne } from "./react-components/hooks/useDrawer/useDrawer.js";
34
- import { PorygonI18nProvider as _e, useButtonsLocaleText as ge, useFieldsLocaleText as ce, useFormLocaleText as de, usePorygonLocaleText as Ae, useTableLocaleText as Oe } from "./react-components/i18n/PorygonI18nProvider.js";
35
- import { DEFAULT_EFW_BUTTONS_LOCALE_TEXT as De, DEFAULT_EFW_FIELDS_LOCALE_TEXT as Be, DEFAULT_EFW_FORM_LOCALE_TEXT as Se, DEFAULT_EFW_TABLE_LOCALE_TEXT as Ce } from "./react-components/i18n/defaultLocaleText.js";
36
- import { PORYGON_LOCALES as Ne, PORYGON_LOCALE_EN as be, PORYGON_LOCALE_ES as Ve, PORYGON_LOCALE_PT_BR as he } from "./react-components/i18n/localePresets.js";
37
- import { EFWTable as Ge } from "./react-components/tables/EFWTable/EFWTable.js";
38
- import { useTableController as Ue } from "./react-components/tables/EFWTable/hooks/useTableController/useTableController.js";
39
- import { useDefaultFilterButton as ye } from "./react-components/tables/EFWTable/hooks/useDefaultFilterButton/useDefaultFilterButton.js";
40
- import { EFWTableEmpty as ze, EFWTableOverlay as Xe } from "./react-components/tables/EFWTable/components/EFWTableOverlay/EFWTableOverlay.js";
32
+ import { EFWConversionError as We, EFWValuesToFlat as Le, flatToEFWValues as ne } from "./react-components/forms/EFWForm/EFWForm.flatConverter.js";
33
+ import { EFWFormMessageBarGroup as _e } from "./react-components/forms/EFWFormMessageBarGroup/EFWFormMessageBarGroup.js";
34
+ import { useDrawer as ce } from "./react-components/hooks/useDrawer/useDrawer.js";
35
+ import { PorygonI18nProvider as Ae, useButtonsLocaleText as Oe, useFieldsLocaleText as Pe, useFormLocaleText as De, usePorygonLocaleText as Be, useTableLocaleText as Ce } from "./react-components/i18n/PorygonI18nProvider.js";
36
+ import { DEFAULT_EFW_BUTTONS_LOCALE_TEXT as Ie, DEFAULT_EFW_FIELDS_LOCALE_TEXT as Ne, DEFAULT_EFW_FORM_LOCALE_TEXT as Ve, DEFAULT_EFW_TABLE_LOCALE_TEXT as be } from "./react-components/i18n/defaultLocaleText.js";
37
+ import { PORYGON_LOCALES as ke, PORYGON_LOCALE_EN as Ge, PORYGON_LOCALE_ES as Re, PORYGON_LOCALE_PT_BR as Ue } from "./react-components/i18n/localePresets.js";
38
+ import { EFWTable as ye } from "./react-components/tables/EFWTable/EFWTable.js";
39
+ import { useTableController as ze } from "./react-components/tables/EFWTable/hooks/useTableController/useTableController.js";
40
+ import { useDefaultFilterButton as Ye } from "./react-components/tables/EFWTable/hooks/useDefaultFilterButton/useDefaultFilterButton.js";
41
+ import { EFWTableEmpty as je, EFWTableOverlay as qe } from "./react-components/tables/EFWTable/components/EFWTableOverlay/EFWTableOverlay.js";
41
42
  export {
42
- De as DEFAULT_EFW_BUTTONS_LOCALE_TEXT,
43
- Be as DEFAULT_EFW_FIELDS_LOCALE_TEXT,
44
- Se as DEFAULT_EFW_FORM_LOCALE_TEXT,
45
- Ce as DEFAULT_EFW_TABLE_LOCALE_TEXT,
43
+ Ie as DEFAULT_EFW_BUTTONS_LOCALE_TEXT,
44
+ Ne as DEFAULT_EFW_FIELDS_LOCALE_TEXT,
45
+ Ve as DEFAULT_EFW_FORM_LOCALE_TEXT,
46
+ be as DEFAULT_EFW_TABLE_LOCALE_TEXT,
46
47
  s as EFWAttachment,
47
48
  d as EFWAttachmentsField,
48
- E as EFWButton,
49
+ p as EFWButton,
50
+ We as EFWConversionError,
49
51
  O as EFWDatePicker,
50
52
  N as EFWDatePickerField,
51
53
  u as EFWDrawerButton,
52
- W as EFWField,
54
+ L as EFWField,
53
55
  Te as EFWForm,
54
- Le as EFWFormMessageBarGroup,
56
+ _e as EFWFormMessageBarGroup,
55
57
  i as EFWGroupButton,
56
- V as EFWInput,
58
+ b as EFWInput,
57
59
  R as EFWInputField,
58
60
  a as EFWMessageBarManager,
59
61
  w as EFWNumberInput,
60
62
  X as EFWNumberInputField,
61
63
  v as EFWSwitch,
62
64
  J as EFWSwitchField,
63
- Ge as EFWTable,
64
- ze as EFWTableEmpty,
65
- Xe as EFWTableOverlay,
65
+ ye as EFWTable,
66
+ je as EFWTableEmpty,
67
+ qe as EFWTableOverlay,
66
68
  Q as EFWTagPicker,
67
69
  re as EFWTagPickerField,
68
70
  te as EFWTextArea,
69
- pe as EFWTextAreaField,
70
- Ne as PORYGON_LOCALES,
71
- be as PORYGON_LOCALE_EN,
72
- Ve as PORYGON_LOCALE_ES,
73
- he as PORYGON_LOCALE_PT_BR,
74
- _e as PorygonI18nProvider,
71
+ Ee as EFWTextAreaField,
72
+ Le as EFWValuesToFlat,
73
+ ke as PORYGON_LOCALES,
74
+ Ge as PORYGON_LOCALE_EN,
75
+ Re as PORYGON_LOCALE_ES,
76
+ Ue as PORYGON_LOCALE_PT_BR,
77
+ Ae as PorygonI18nProvider,
75
78
  D as enLocalizedStrings,
76
79
  B as esLocalizedStrings,
80
+ ne as flatToEFWValues,
77
81
  o as formatFileSize,
78
82
  g as getAttachmentsFormattedValue,
79
- S as getDatePickerFormattedValue,
83
+ C as getDatePickerFormattedValue,
80
84
  t as getErrorMessage,
81
- m as getFileIconUrl,
85
+ F as getFileIconUrl,
82
86
  xe as getFormFieldDisplayText,
83
87
  k as getInputFormattedValue,
84
88
  M as getNumberInputFormattedValue,
85
89
  q as getSwitchFormattedValue,
86
90
  $ as getTagPickerFormattedValue,
87
- Fe as getTextAreaFormattedValue,
88
- C as ptLocalizedStrings,
89
- ge as useButtonsLocaleText,
90
- ye as useDefaultFilterButton,
91
- ne as useDrawer,
92
- f as useEFWButton,
93
- ce as useFieldsLocaleText,
94
- le as useFormController,
95
- de as useFormLocaleText,
96
- Ae as usePorygonLocaleText,
97
- Ue as useTableController,
98
- Oe as useTableLocaleText
91
+ me as getTextAreaFormattedValue,
92
+ S as ptLocalizedStrings,
93
+ Oe as useButtonsLocaleText,
94
+ Ye as useDefaultFilterButton,
95
+ ce as useDrawer,
96
+ l as useEFWButton,
97
+ Pe as useFieldsLocaleText,
98
+ fe as useFormController,
99
+ De as useFormLocaleText,
100
+ Be as usePorygonLocaleText,
101
+ ze as useTableController,
102
+ Ce as useTableLocaleText
99
103
  };
@@ -0,0 +1,130 @@
1
+ import { EFWAttachmentsValue } from '../../fields/Attachments';
2
+ import { EFWFormFieldProps, EFWFormValues, EFWFormDatePickerFieldProps } from './EFWForm.types';
3
+
4
+ /**
5
+ * Tipo derivado del array de fields que describe el shape "plano" natural
6
+ * para el consumer: primitivos, booleanos o arrays simples por field.
7
+ *
8
+ * Mapping por `typeAsString`:
9
+ * - `Text` / `Note` / `Choice` / `Date` → `string`
10
+ * - `Number` → `number`
11
+ * - `Boolean` → `boolean`
12
+ * - `MultiChoice` → `readonly string[]`
13
+ * - `Attachments` → `readonly EFWAttachmentsValue[]`
14
+ *
15
+ * Para `Choice` plano se usa la `key` del item seleccionado y para `MultiChoice`
16
+ * un array de `key`s, ya que `key` es el identificador estable.
17
+ */
18
+ export type FlatValues<F extends readonly EFWFormFieldProps[] = EFWFormFieldProps[]> = {
19
+ [K in F[number] as K['internalName']]?: FlatValueOfField<K>;
20
+ };
21
+ export type FlatValueOfField<P extends EFWFormFieldProps> = P['typeAsString'] extends 'Text' ? string : P['typeAsString'] extends 'Number' ? number : P['typeAsString'] extends 'Note' ? string : P['typeAsString'] extends 'Boolean' ? boolean : P['typeAsString'] extends 'Choice' ? string : P['typeAsString'] extends 'MultiChoice' ? readonly string[] : P['typeAsString'] extends 'Date' ? string : P['typeAsString'] extends 'Attachments' ? readonly EFWAttachmentsValue[] : never;
22
+ /**
23
+ * Función personalizada para serializar un valor de fecha al ir de EFW → flat.
24
+ */
25
+ export type DateSerializeFunction = (value: Date | string, field: EFWFormDatePickerFieldProps) => string;
26
+ export interface FlatToEFWOptions {
27
+ /**
28
+ * Estrategia para resolver opciones en Choice/MultiChoice cuando se recibe
29
+ * sólo la `key`.
30
+ *
31
+ * - `'lookup'` (default): busca la key en `field.options` y arma `{ key, text, ... }`.
32
+ * Si la key no aparece, ver `unknownChoiceKey`.
33
+ * - `'passthrough'`: no busca; siempre genera `{ key, text: key }` directamente
34
+ * (útil cuando `field.options` es un loader async o el caller ya validó las keys).
35
+ */
36
+ choiceLookup?: 'lookup' | 'passthrough';
37
+ /**
38
+ * Qué hacer cuando una `key` de Choice/MultiChoice no existe en `field.options`.
39
+ *
40
+ * - `'drop'` (default): omitir el item.
41
+ * - `'synthesize'`: generar `{ key, text: key }`.
42
+ * - `'error'`: lanzar `EFWConversionError`.
43
+ */
44
+ unknownChoiceKey?: 'drop' | 'synthesize' | 'error';
45
+ /**
46
+ * Para Date: cómo interpretar el string ISO al construir el `Date[]` que
47
+ * espera el field.
48
+ *
49
+ * - `'as-utc'` (default): `new Date(flat)`. Strings tipo `'YYYY-MM-DD'` o
50
+ * ISO con `Z` se interpretan como UTC.
51
+ * - `'as-local'`: `new Date(flat)` interpretado por el runtime local.
52
+ * - `'string'`: no convierte; coloca el string crudo en el array (válido
53
+ * porque `EFWDatePickerValue = Date | string`).
54
+ */
55
+ dateParse?: 'as-utc' | 'as-local' | 'string';
56
+ }
57
+ export interface EFWToFlatOptions {
58
+ /**
59
+ * Para Date: cómo serializar `Date | string` al string plano.
60
+ *
61
+ * - `'iso-date'` (default): `'YYYY-MM-DD'` UTC.
62
+ * - `'iso-datetime'`: ISO 8601 completo (`Date.prototype.toISOString`).
63
+ * - función custom `(value, field) => string`.
64
+ */
65
+ dateSerialize?: 'iso-date' | 'iso-datetime' | DateSerializeFunction;
66
+ /**
67
+ * Para campos vacíos / null, decide si la clave se omite del output o se
68
+ * incluye como `undefined`. Default: `'omit'`.
69
+ */
70
+ emptyKeys?: 'omit' | 'include';
71
+ }
72
+ /**
73
+ * Códigos de error producidos por las conversiones planas de EFWForm.
74
+ */
75
+ export type EFWConversionErrorCode = 'unknown-choice-key' | 'invalid-date' | 'invalid-number' | 'unsupported-field-type';
76
+ /**
77
+ * Error lanzado por `flatToEFWValues` / `EFWValuesToFlat` cuando una conversión
78
+ * falla de forma fatal o las opciones la fuerzan a fallar.
79
+ */
80
+ export declare class EFWConversionError extends Error {
81
+ readonly code: EFWConversionErrorCode;
82
+ readonly fieldName: string;
83
+ readonly received: unknown;
84
+ constructor(params: {
85
+ code: EFWConversionErrorCode;
86
+ fieldName: string;
87
+ received: unknown;
88
+ message?: string;
89
+ });
90
+ }
91
+ /**
92
+ * Convierte un objeto plano (`{ field: primitive | array }`) al shape que
93
+ * espera `EFWForm` para sus `values` / `defaultValues` (ej. `Date` como
94
+ * `Date[]`, `Choice` como `EFWTagPickerOption[]`).
95
+ *
96
+ * - Las claves del input que no matcheen ningún `field.internalName` se
97
+ * ignoran silenciosamente.
98
+ * - Las claves declaradas en `fields` que no estén presentes en el input se
99
+ * omiten del output (no se completan con default).
100
+ * - Cuando una conversión no es posible (ej. Choice con key desconocida), el
101
+ * field correspondiente se devuelve como vacío salvo que las opciones
102
+ * indiquen lo contrario.
103
+ *
104
+ * @example
105
+ * const fields = [
106
+ * { id: '1', typeAsString: 'Text', internalName: 'name' },
107
+ * { id: '2', typeAsString: 'Choice', internalName: 'category', options: [{ key: 'a', text: 'A' }] },
108
+ * ] as const;
109
+ *
110
+ * flatToEFWValues(fields, { name: 'John', category: 'a' });
111
+ * // → { name: 'John', category: [{ key: 'a', text: 'A' }] }
112
+ */
113
+ export declare function flatToEFWValues<F extends readonly EFWFormFieldProps[]>(fields: F, flat: FlatValues<F> | Partial<FlatValues<F>> | Record<string, unknown>, options?: FlatToEFWOptions): Partial<EFWFormValues<F>>;
114
+ /**
115
+ * Operación inversa de {@link flatToEFWValues}: toma valores en el shape que
116
+ * usa `EFWForm` y los reduce a primitivos / arrays planos según el tipo de
117
+ * cada field.
118
+ *
119
+ * - Las claves del input que no matcheen ningún field se ignoran.
120
+ * - Si un field está ausente o tiene valor vacío equivalente, la clave se
121
+ * omite del output (controlable con `emptyKeys: 'include'`).
122
+ *
123
+ * @example
124
+ * EFWValuesToFlat(fields, {
125
+ * name: 'John',
126
+ * category: [{ key: 'a', text: 'A' }],
127
+ * });
128
+ * // → { name: 'John', category: 'a' }
129
+ */
130
+ export declare function EFWValuesToFlat<F extends readonly EFWFormFieldProps[]>(fields: F, efwValues: Partial<EFWFormValues<F>>, options?: EFWToFlatOptions): Partial<FlatValues<F>>;
@@ -0,0 +1,279 @@
1
+ var T = Object.defineProperty;
2
+ var F = (e, r, n) => r in e ? T(e, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[r] = n;
3
+ var y = (e, r, n) => F(e, typeof r != "symbol" ? r + "" : r, n);
4
+ class o extends Error {
5
+ constructor(n) {
6
+ super(
7
+ n.message ?? `[EFWConversionError:${n.code}] field "${n.fieldName}" received ${a(n.received)}`
8
+ );
9
+ y(this, "code");
10
+ y(this, "fieldName");
11
+ y(this, "received");
12
+ this.name = "EFWConversionError", this.code = n.code, this.fieldName = n.fieldName, this.received = n.received;
13
+ }
14
+ }
15
+ function a(e) {
16
+ if (e === void 0) return "undefined";
17
+ if (e === null) return "null";
18
+ try {
19
+ const r = JSON.stringify(e);
20
+ return typeof r == "string" ? r : String(e);
21
+ } catch {
22
+ return String(e);
23
+ }
24
+ }
25
+ function w(e) {
26
+ const r = /* @__PURE__ */ new Map();
27
+ for (const n of e)
28
+ n && typeof n.internalName == "string" && r.set(n.internalName, n);
29
+ return r;
30
+ }
31
+ function A(e, r) {
32
+ const n = e.options;
33
+ if (Array.isArray(n))
34
+ return n.find((t) => t && t.key === r);
35
+ }
36
+ function m(e) {
37
+ return e < 10 ? `0${e}` : `${e}`;
38
+ }
39
+ function $(e, r) {
40
+ if (e instanceof Date) {
41
+ if (Number.isNaN(e.getTime()))
42
+ throw new o({
43
+ code: "invalid-date",
44
+ fieldName: r,
45
+ received: e
46
+ });
47
+ return `${e.getUTCFullYear()}-${m(e.getUTCMonth() + 1)}-${m(e.getUTCDate())}`;
48
+ }
49
+ if (typeof e == "string") {
50
+ const n = /^(\d{4}-\d{2}-\d{2})/.exec(e);
51
+ if (n) return n[1];
52
+ const t = new Date(e);
53
+ if (Number.isNaN(t.getTime()))
54
+ throw new o({
55
+ code: "invalid-date",
56
+ fieldName: r,
57
+ received: e
58
+ });
59
+ return `${t.getUTCFullYear()}-${m(t.getUTCMonth() + 1)}-${m(t.getUTCDate())}`;
60
+ }
61
+ throw new o({
62
+ code: "invalid-date",
63
+ fieldName: r,
64
+ received: e
65
+ });
66
+ }
67
+ function E(e, r) {
68
+ const n = e instanceof Date ? e : new Date(e);
69
+ if (Number.isNaN(n.getTime()))
70
+ throw new o({
71
+ code: "invalid-date",
72
+ fieldName: r,
73
+ received: e
74
+ });
75
+ return n.toISOString();
76
+ }
77
+ const N = {
78
+ Text: (e) => {
79
+ if (e != null)
80
+ return typeof e != "string" ? String(e) : e;
81
+ },
82
+ Number: (e, r) => {
83
+ if (e != null) {
84
+ if (typeof e != "number")
85
+ throw new o({
86
+ code: "invalid-number",
87
+ fieldName: r.internalName,
88
+ received: e
89
+ });
90
+ if (!Number.isNaN(e))
91
+ return e;
92
+ }
93
+ },
94
+ Note: (e) => {
95
+ if (e !== void 0)
96
+ return e === null ? null : typeof e != "string" ? String(e) : e;
97
+ },
98
+ Boolean: (e) => {
99
+ if (e != null)
100
+ return !!e;
101
+ },
102
+ Choice: (e, r, n) => {
103
+ if (e == null || e === "") return [];
104
+ if (typeof e != "string") {
105
+ if (Array.isArray(e))
106
+ return e.length === 0 ? [] : (e.length > 1 && console.warn(
107
+ `[flatToEFWValues] field "${r.internalName}" is Choice but received an array with ${e.length} items; using the first.`
108
+ ), N.Choice(e[0], r, n));
109
+ throw new o({
110
+ code: "unknown-choice-key",
111
+ fieldName: r.internalName,
112
+ received: e,
113
+ message: `[flatToEFWValues] field "${r.internalName}" expected a string key for Choice but received ${a(e)}`
114
+ });
115
+ }
116
+ const t = l(e, r, n);
117
+ return t ? [t] : [];
118
+ },
119
+ MultiChoice: (e, r, n) => {
120
+ if (e == null) return [];
121
+ if (!Array.isArray(e))
122
+ throw new o({
123
+ code: "unknown-choice-key",
124
+ fieldName: r.internalName,
125
+ received: e,
126
+ message: `[flatToEFWValues] field "${r.internalName}" expected an array of keys for MultiChoice but received ${a(e)}`
127
+ });
128
+ const t = [];
129
+ for (const i of e) {
130
+ if (typeof i != "string")
131
+ throw new o({
132
+ code: "unknown-choice-key",
133
+ fieldName: r.internalName,
134
+ received: i,
135
+ message: `[flatToEFWValues] field "${r.internalName}" MultiChoice array contained a non-string entry: ${a(i)}`
136
+ });
137
+ const c = l(i, r, n);
138
+ c && t.push(c);
139
+ }
140
+ return t;
141
+ },
142
+ Date: (e, r, n) => {
143
+ if (e == null || e === "") return [];
144
+ if (typeof e != "string")
145
+ throw new o({
146
+ code: "invalid-date",
147
+ fieldName: r.internalName,
148
+ received: e,
149
+ message: `[flatToEFWValues] field "${r.internalName}" expected an ISO string for Date but received ${a(e)}`
150
+ });
151
+ switch (n.dateParse) {
152
+ case "string":
153
+ return [e];
154
+ case "as-utc":
155
+ case "as-local": {
156
+ const t = new Date(e);
157
+ if (Number.isNaN(t.getTime()))
158
+ throw new o({
159
+ code: "invalid-date",
160
+ fieldName: r.internalName,
161
+ received: e
162
+ });
163
+ return [t];
164
+ }
165
+ default:
166
+ return [];
167
+ }
168
+ },
169
+ Attachments: (e) => e == null ? [] : Array.isArray(e) ? [...e] : []
170
+ };
171
+ function l(e, r, n) {
172
+ if (n.choiceLookup === "passthrough")
173
+ return { key: e, text: e };
174
+ const t = A(r, e);
175
+ if (t) return t;
176
+ switch (n.unknownChoiceKey) {
177
+ case "synthesize":
178
+ return { key: e, text: e };
179
+ case "error":
180
+ throw new o({
181
+ code: "unknown-choice-key",
182
+ fieldName: r.internalName,
183
+ received: e,
184
+ message: `[flatToEFWValues] field "${r.internalName}" received unknown choice key "${e}"`
185
+ });
186
+ case "drop":
187
+ default:
188
+ return;
189
+ }
190
+ }
191
+ const C = {
192
+ Text: (e) => {
193
+ if (e != null) {
194
+ if (typeof e != "string") return String(e);
195
+ if (e !== "")
196
+ return e;
197
+ }
198
+ },
199
+ Number: (e) => {
200
+ if (e != null && !(typeof e != "number" || Number.isNaN(e)))
201
+ return e;
202
+ },
203
+ Note: (e) => {
204
+ if (e != null && e !== "")
205
+ return e;
206
+ },
207
+ Boolean: (e) => {
208
+ if (e != null)
209
+ return !!e;
210
+ },
211
+ Choice: (e) => {
212
+ if (!Array.isArray(e) || e.length === 0) return;
213
+ const r = e[0];
214
+ if (!(!r || typeof r.key != "string"))
215
+ return r.key;
216
+ },
217
+ MultiChoice: (e) => {
218
+ if (!Array.isArray(e) || e.length === 0) return;
219
+ const r = [];
220
+ for (const n of e)
221
+ n && typeof n.key == "string" && r.push(n.key);
222
+ return r.length > 0 ? r : void 0;
223
+ },
224
+ Date: (e, r, n) => {
225
+ if (!Array.isArray(e) || e.length === 0) return;
226
+ const t = e[0];
227
+ if (t == null) return;
228
+ const i = n.dateSerialize;
229
+ return typeof i == "function" ? i(t, r) : i === "iso-datetime" ? E(t, r.internalName) : $(t, r.internalName);
230
+ },
231
+ Attachments: (e) => {
232
+ if (!(!Array.isArray(e) || e.length === 0))
233
+ return [...e];
234
+ }
235
+ }, b = {
236
+ choiceLookup: "lookup",
237
+ unknownChoiceKey: "drop",
238
+ dateParse: "as-utc"
239
+ }, k = {
240
+ dateSerialize: "iso-date",
241
+ emptyKeys: "omit"
242
+ };
243
+ function v(e) {
244
+ const r = e.typeAsString;
245
+ if (!(r in N))
246
+ throw new o({
247
+ code: "unsupported-field-type",
248
+ fieldName: e.internalName,
249
+ received: r,
250
+ message: `[flatToEFWValues] unsupported field type "${r}" on field "${e.internalName}"`
251
+ });
252
+ }
253
+ function S(e, r, n) {
254
+ const t = { ...b, ...n }, i = w(e), c = {}, u = r ?? {};
255
+ for (const [s, d] of i) {
256
+ if (v(d), !Object.prototype.hasOwnProperty.call(u, s)) continue;
257
+ const f = u[s], g = N[d.typeAsString], h = g(f, d, t);
258
+ h !== void 0 && (c[s] = h);
259
+ }
260
+ return c;
261
+ }
262
+ function W(e, r, n) {
263
+ const t = { ...k, ...n }, i = w(e), c = {}, u = r ?? {};
264
+ for (const [s, d] of i) {
265
+ v(d);
266
+ const f = Object.prototype.hasOwnProperty.call(u, s), g = f ? u[s] : void 0, h = C[d.typeAsString], p = h(g, d, t);
267
+ if (p === void 0) {
268
+ t.emptyKeys === "include" && f && (c[s] = void 0);
269
+ continue;
270
+ }
271
+ c[s] = p;
272
+ }
273
+ return c;
274
+ }
275
+ export {
276
+ o as EFWConversionError,
277
+ W as EFWValuesToFlat,
278
+ S as flatToEFWValues
279
+ };
@@ -3,3 +3,5 @@ export type { EFWFormLocaleText } from '../../i18n';
3
3
  export { getFormFieldDisplayText } from './EFWForm.converter';
4
4
  export { useFormController } from './EFWForm.hooks';
5
5
  export { EFWForm } from './EFWForm';
6
+ export { flatToEFWValues, EFWValuesToFlat, EFWConversionError } from './EFWForm.flatConverter';
7
+ export type { FlatValues, FlatValueOfField, FlatToEFWOptions, EFWToFlatOptions, EFWConversionErrorCode, DateSerializeFunction } from './EFWForm.flatConverter';
@@ -1,8 +1,12 @@
1
1
  import { getFormFieldDisplayText as e } from "./EFWForm.converter.js";
2
- import { useFormController as t } from "./EFWForm.hooks.js";
3
- import { EFWForm as l } from "./EFWForm.js";
2
+ import { useFormController as F } from "./EFWForm.hooks.js";
3
+ import { EFWForm as m } from "./EFWForm.js";
4
+ import { EFWConversionError as f, EFWValuesToFlat as p, flatToEFWValues as s } from "./EFWForm.flatConverter.js";
4
5
  export {
5
- l as EFWForm,
6
+ f as EFWConversionError,
7
+ m as EFWForm,
8
+ p as EFWValuesToFlat,
9
+ s as flatToEFWValues,
6
10
  e as getFormFieldDisplayText,
7
- t as useFormController
11
+ F as useFormController
8
12
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envisiongroup/porygon",
3
- "version": "1.0.0-rc.40",
3
+ "version": "1.0.0-rc.41",
4
4
  "description": "Librerias de componentes de React creados por la empresa Envision",
5
5
  "license": "CC-BY-ND-4.0",
6
6
  "main": "./dist/index.js",