@ttoss/forms 0.26.6 → 0.26.8

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.
@@ -1,5 +1,5 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import { FormField, FormFieldCNPJ, FormFieldPatternFormat, isCnpjValid } from "../chunk-VFAUAKN6.js";
2
+ import { FormField, FormFieldCNPJ, FormFieldPatternFormat, isCnpjValid } from "../chunk-FCW2VV6O.js";
3
3
 
4
4
  // src/Brazil/FormFieldPhone.tsx
5
5
  import { Input } from "@ttoss/ui";
@@ -1,5 +1,5 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import { Form, useForm, yupResolver } from "../chunk-VFAUAKN6.js";
2
+ import { Form, useForm, yupResolver } from "../chunk-FCW2VV6O.js";
3
3
 
4
4
  // src/MultistepForm/MultistepForm.tsx
5
5
  import * as React3 from "react";
@@ -154,10 +154,10 @@ import { CloseButton, Flex as Flex4, Image as Image2, Text as Text4 } from "@tto
154
154
  // ../react-icons/src/Icon.tsx
155
155
  import * as React2 from "react";
156
156
 
157
- // ../../node_modules/.pnpm/@iconify-icon+react@2.1.0_react@18.3.1/node_modules/@iconify-icon/react/dist/iconify.mjs
157
+ // ../../node_modules/.pnpm/@iconify-icon+react@2.2.0_react@19.0.0/node_modules/@iconify-icon/react/dist/iconify.mjs
158
158
  import React from "react";
159
159
 
160
- // ../../node_modules/.pnpm/iconify-icon@2.1.0/node_modules/iconify-icon/dist/iconify-icon.mjs
160
+ // ../../node_modules/.pnpm/iconify-icon@2.2.0/node_modules/iconify-icon/dist/iconify-icon.mjs
161
161
  var defaultIconDimensions = Object.freeze({
162
162
  left: 0,
163
163
  top: 0,
@@ -304,7 +304,10 @@ var validateIconName = (icon, allowSimpleName) => {
304
304
  if (!icon) {
305
305
  return false;
306
306
  }
307
- return !!((icon.provider === "" || icon.provider.match(matchIconName)) && (allowSimpleName && icon.prefix === "" || icon.prefix.match(matchIconName)) && icon.name.match(matchIconName));
307
+ return !!(
308
+ // Check prefix: cannot be empty, unless allowSimpleName is enabled
309
+ // Check name: cannot be empty
310
+ (allowSimpleName && icon.prefix === "" || !!icon.prefix) && !!icon.name);
308
311
  };
309
312
  function mergeIconTransformations(obj1, obj2) {
310
313
  const result = {};
@@ -353,7 +356,7 @@ function getIconsTree(data, names) {
353
356
  }
354
357
  return resolved[name];
355
358
  }
356
- (names || Object.keys(icons).concat(Object.keys(aliases))).forEach(resolve);
359
+ Object.keys(icons).concat(Object.keys(aliases)).forEach(resolve);
357
360
  return resolved;
358
361
  }
359
362
  function internalGetIconData(data, name, tree) {
@@ -416,7 +419,13 @@ function quicklyValidateIconSet(obj) {
416
419
  const icons = data.icons;
417
420
  for (const name in icons) {
418
421
  const icon = icons[name];
419
- if (!name.match(matchIconName) || typeof icon.body !== "string" || !checkOptionalProps(icon, defaultExtendedIconProps)) {
422
+ if (
423
+ // Name cannot be empty
424
+ !name ||
425
+ // Must have body
426
+ typeof icon.body !== "string" ||
427
+ // Check other props
428
+ !checkOptionalProps(icon, defaultExtendedIconProps)) {
420
429
  return null;
421
430
  }
422
431
  }
@@ -424,7 +433,13 @@ function quicklyValidateIconSet(obj) {
424
433
  for (const name in aliases) {
425
434
  const icon = aliases[name];
426
435
  const parent = icon.parent;
427
- if (!name.match(matchIconName) || typeof parent !== "string" || !icons[parent] && !aliases[parent] || !checkOptionalProps(icon, defaultExtendedIconProps)) {
436
+ if (
437
+ // Name cannot be empty
438
+ !name ||
439
+ // Parent must be set and point to existing icon
440
+ typeof parent !== "string" || !icons[parent] && !aliases[parent] ||
441
+ // Check other props
442
+ !checkOptionalProps(icon, defaultExtendedIconProps)) {
428
443
  return null;
429
444
  }
430
445
  }
@@ -499,7 +514,12 @@ function addIcon$1(name, data) {
499
514
  return false;
500
515
  }
501
516
  const storage2 = getStorage(icon.provider, icon.prefix);
502
- return addIconToStorage(storage2, icon.name, data);
517
+ if (data) {
518
+ return addIconToStorage(storage2, icon.name, data);
519
+ } else {
520
+ storage2.missing.add(icon.name);
521
+ return true;
522
+ }
503
523
  }
504
524
  function addCollection$1(data, provider) {
505
525
  if (typeof data !== "object") {
@@ -513,7 +533,7 @@ function addCollection$1(data, provider) {
513
533
  if (quicklyValidateIconSet(data)) {
514
534
  data.prefix = "";
515
535
  parseIconSet(data, (name, icon) => {
516
- if (icon && addIcon$1(name, icon)) {
536
+ if (addIcon$1(name, icon)) {
517
537
  added = true;
518
538
  }
519
539
  });
@@ -539,7 +559,7 @@ function getIcon$1(name) {
539
559
  return result ? {
540
560
  ...defaultIconProps,
541
561
  ...result
542
- } : null;
562
+ } : result;
543
563
  }
544
564
  function sortIcons(icons) {
545
565
  const result = {
@@ -1172,6 +1192,57 @@ function loadedNewIcons(storage2) {
1172
1192
  });
1173
1193
  }
1174
1194
  }
1195
+ function checkIconNamesForAPI(icons) {
1196
+ const valid = [];
1197
+ const invalid = [];
1198
+ icons.forEach(name => {
1199
+ (name.match(matchIconName) ? valid : invalid).push(name);
1200
+ });
1201
+ return {
1202
+ valid,
1203
+ invalid
1204
+ };
1205
+ }
1206
+ function parseLoaderResponse(storage2, icons, data, isAPIResponse) {
1207
+ function checkMissing() {
1208
+ const pending = storage2.pendingIcons;
1209
+ icons.forEach(name => {
1210
+ if (pending) {
1211
+ pending.delete(name);
1212
+ }
1213
+ if (!storage2.icons[name]) {
1214
+ storage2.missing.add(name);
1215
+ }
1216
+ });
1217
+ }
1218
+ if (data && typeof data === "object") {
1219
+ try {
1220
+ const parsed = addIconSet(storage2, data);
1221
+ if (!parsed.length) {
1222
+ checkMissing();
1223
+ return;
1224
+ }
1225
+ if (isAPIResponse) {
1226
+ storeInBrowserStorage(storage2, data);
1227
+ }
1228
+ } catch (err) {
1229
+ console.error(err);
1230
+ }
1231
+ }
1232
+ checkMissing();
1233
+ loadedNewIcons(storage2);
1234
+ }
1235
+ function parsePossiblyAsyncResponse(response, callback) {
1236
+ if (response instanceof Promise) {
1237
+ response.then(data => {
1238
+ callback(data);
1239
+ }).catch(() => {
1240
+ callback(null);
1241
+ });
1242
+ } else {
1243
+ callback(response);
1244
+ }
1245
+ }
1175
1246
  function loadNewIcons(storage2, icons) {
1176
1247
  if (!storage2.iconsToLoad) {
1177
1248
  storage2.iconsToLoad = icons;
@@ -1188,35 +1259,50 @@ function loadNewIcons(storage2, icons) {
1188
1259
  } = storage2;
1189
1260
  const icons2 = storage2.iconsToLoad;
1190
1261
  delete storage2.iconsToLoad;
1191
- let api;
1192
- if (!icons2 || !(api = getAPIModule(provider))) {
1262
+ if (!icons2 || !icons2.length) {
1263
+ return;
1264
+ }
1265
+ const customIconLoader = storage2.loadIcon;
1266
+ if (storage2.loadIcons && (icons2.length > 1 || !customIconLoader)) {
1267
+ parsePossiblyAsyncResponse(storage2.loadIcons(icons2, prefix, provider), data => {
1268
+ parseLoaderResponse(storage2, icons2, data, false);
1269
+ });
1270
+ return;
1271
+ }
1272
+ if (customIconLoader) {
1273
+ icons2.forEach(name => {
1274
+ const response = customIconLoader(name, prefix, provider);
1275
+ parsePossiblyAsyncResponse(response, data => {
1276
+ const iconSet = data ? {
1277
+ prefix,
1278
+ icons: {
1279
+ [name]: data
1280
+ }
1281
+ } : null;
1282
+ parseLoaderResponse(storage2, [name], iconSet, false);
1283
+ });
1284
+ });
1193
1285
  return;
1194
1286
  }
1195
- const params = api.prepare(provider, prefix, icons2);
1287
+ const {
1288
+ valid,
1289
+ invalid
1290
+ } = checkIconNamesForAPI(icons2);
1291
+ if (invalid.length) {
1292
+ parseLoaderResponse(storage2, invalid, null, false);
1293
+ }
1294
+ if (!valid.length) {
1295
+ return;
1296
+ }
1297
+ const api = prefix.match(matchIconName) ? getAPIModule(provider) : null;
1298
+ if (!api) {
1299
+ parseLoaderResponse(storage2, valid, null, false);
1300
+ return;
1301
+ }
1302
+ const params = api.prepare(provider, prefix, valid);
1196
1303
  params.forEach(item => {
1197
1304
  sendAPIQuery(provider, item, data => {
1198
- if (typeof data !== "object") {
1199
- item.icons.forEach(name => {
1200
- storage2.missing.add(name);
1201
- });
1202
- } else {
1203
- try {
1204
- const parsed = addIconSet(storage2, data);
1205
- if (!parsed.length) {
1206
- return;
1207
- }
1208
- const pending = storage2.pendingIcons;
1209
- if (pending) {
1210
- parsed.forEach(name => {
1211
- pending.delete(name);
1212
- });
1213
- }
1214
- storeInBrowserStorage(storage2, data);
1215
- } catch (err) {
1216
- console.error(err);
1217
- }
1218
- }
1219
- loadedNewIcons(storage2);
1305
+ parseLoaderResponse(storage2, item.icons, data, true);
1220
1306
  });
1221
1307
  });
1222
1308
  });
@@ -1271,12 +1357,9 @@ var loadIcons$1 = (icons, callback) => {
1271
1357
  }
1272
1358
  });
1273
1359
  sources.forEach(storage2 => {
1274
- const {
1275
- provider,
1276
- prefix
1277
- } = storage2;
1278
- if (newIcons[provider][prefix].length) {
1279
- loadNewIcons(storage2, newIcons[provider][prefix]);
1360
+ const list = newIcons[storage2.provider][storage2.prefix];
1361
+ if (list.length) {
1362
+ loadNewIcons(storage2, list);
1280
1363
  }
1281
1364
  });
1282
1365
  return callback ? storeCallback(callback, sortedIcons, sources) : emptyCallback;
@@ -1314,12 +1397,31 @@ function testIconObject(value) {
1314
1397
  } catch (err) {}
1315
1398
  }
1316
1399
  function parseIconValue(value, onload) {
1317
- const name = typeof value === "string" ? stringToIcon(value, true, true) : null;
1318
- if (!name) {
1400
+ if (typeof value === "object") {
1319
1401
  const data2 = testIconObject(value);
1320
1402
  return {
1321
- value,
1322
- data: data2
1403
+ data: data2,
1404
+ value
1405
+ };
1406
+ }
1407
+ if (typeof value !== "string") {
1408
+ return {
1409
+ value
1410
+ };
1411
+ }
1412
+ if (value.includes("{")) {
1413
+ const data2 = testIconObject(value);
1414
+ if (data2) {
1415
+ return {
1416
+ data: data2,
1417
+ value
1418
+ };
1419
+ }
1420
+ }
1421
+ const name = stringToIcon(value, true, true);
1422
+ if (!name) {
1423
+ return {
1424
+ value
1323
1425
  };
1324
1426
  }
1325
1427
  const data = getIconData(name);
@@ -1671,6 +1773,12 @@ var fetchAPIModule = {
1671
1773
  prepare,
1672
1774
  send
1673
1775
  };
1776
+ function setCustomIconsLoader$1(loader, prefix, provider) {
1777
+ getStorage(provider || "", prefix).loadIcons = loader;
1778
+ }
1779
+ function setCustomIconLoader$1(loader, prefix, provider) {
1780
+ getStorage(provider || "", prefix).loadIcon = loader;
1781
+ }
1674
1782
  function toggleBrowserCache(storage2, value) {
1675
1783
  switch (storage2) {
1676
1784
  case "local":
@@ -1696,7 +1804,7 @@ function updateStyle(parent, inline) {
1696
1804
  styleNode.setAttribute(nodeAttr, nodeAttr);
1697
1805
  parent.appendChild(styleNode);
1698
1806
  }
1699
- styleNode.textContent = ":host{display:inline-block;vertical-align:" + (inline ? "-0.125em" : "0") + "}span,svg{display:block}" + customStyle;
1807
+ styleNode.textContent = ":host{display:inline-block;vertical-align:" + (inline ? "-0.125em" : "0") + "}span,svg{display:block;margin:auto}" + customStyle;
1700
1808
  }
1701
1809
  function exportFunctions() {
1702
1810
  setAPIModule("", fetchAPIModule);
@@ -1773,6 +1881,8 @@ function exportFunctions() {
1773
1881
  loadIcons: loadIcons$1,
1774
1882
  loadIcon: loadIcon$1,
1775
1883
  addAPIProvider: addAPIProvider$1,
1884
+ setCustomIconLoader: setCustomIconLoader$1,
1885
+ setCustomIconsLoader: setCustomIconsLoader$1,
1776
1886
  appendCustomStyle,
1777
1887
  _api: _api2
1778
1888
  };
@@ -2264,11 +2374,13 @@ var {
2264
2374
  svgToURL,
2265
2375
  loadIcons,
2266
2376
  loadIcon,
2377
+ setCustomIconLoader,
2378
+ setCustomIconsLoader,
2267
2379
  addAPIProvider,
2268
2380
  _api
2269
2381
  } = IconifyIconComponent;
2270
2382
 
2271
- // ../../node_modules/.pnpm/@iconify-icon+react@2.1.0_react@18.3.1/node_modules/@iconify-icon/react/dist/iconify.mjs
2383
+ // ../../node_modules/.pnpm/@iconify-icon+react@2.2.0_react@19.0.0/node_modules/@iconify-icon/react/dist/iconify.mjs
2272
2384
  var Icon = React.forwardRef((props, ref) => {
2273
2385
  const newProps = {
2274
2386
  ...props,
@@ -2497,6 +2609,6 @@ iconify-icon/dist/iconify-icon.mjs:
2497
2609
  * Licensed under MIT.
2498
2610
  *
2499
2611
  * @license MIT
2500
- * @version 2.1.0
2612
+ * @version 2.2.0
2501
2613
  *)
2502
2614
  */
@@ -243,6 +243,10 @@ var FormField = ({
243
243
  const id = idProp || `form-field-${name}`;
244
244
  const memoizedRender = React.useMemo(() => {
245
245
  return React.Children.map(render(controllerReturn), child => {
246
+ if (!React.isValidElement(child)) {
247
+ return null;
248
+ }
249
+ const childProps = child.props;
246
250
  return /* @__PURE__ */jsxs(Fragment, {
247
251
  children: [label && /* @__PURE__ */jsx4(Label, {
248
252
  "aria-disabled": disabled,
@@ -252,7 +256,7 @@ var FormField = ({
252
256
  children: label
253
257
  }), React.createElement(child.type, {
254
258
  id,
255
- ...child.props
259
+ ...childProps
256
260
  })]
257
261
  });
258
262
  });
package/dist/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver } from "./chunk-VFAUAKN6.js";
2
+ import { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver } from "./chunk-FCW2VV6O.js";
3
3
  export { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/forms",
3
- "version": "0.26.6",
3
+ "version": "0.26.8",
4
4
  "license": "MIT",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -33,29 +33,29 @@
33
33
  "dependencies": {
34
34
  "@hookform/error-message": "^2.0.1",
35
35
  "@hookform/resolvers": "^3.9.1",
36
- "react-hook-form": "^7.53.2",
37
- "react-number-format": "^5.4.2",
38
- "yup": "^1.4.0"
36
+ "react-hook-form": "^7.54.2",
37
+ "react-number-format": "^5.4.3",
38
+ "yup": "^1.6.1"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": ">=16.8.0",
42
- "@ttoss/react-i18n": "^2.0.6",
43
- "@ttoss/ui": "^5.0.12"
42
+ "@ttoss/react-i18n": "^2.0.8",
43
+ "@ttoss/ui": "^5.0.14"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/jest": "^29.5.14",
47
- "@types/react": "^18.3.12",
47
+ "@types/react": "^19.0.2",
48
48
  "jest": "^29.7.0",
49
- "react": "^18.3.1",
50
- "react-error-boundary": "^4.1.2",
49
+ "react": "^19.0.0",
50
+ "react-error-boundary": "^5.0.0",
51
51
  "tsup": "^8.3.5",
52
- "yup": "^1.4.0",
53
- "@ttoss/config": "^1.35.0",
54
- "@ttoss/i18n-cli": "^0.7.24",
55
- "@ttoss/react-i18n": "^2.0.6",
56
- "@ttoss/react-icons": "^0.4.6",
57
- "@ttoss/test-utils": "^2.1.19",
58
- "@ttoss/ui": "^5.0.12"
52
+ "yup": "^1.6.1",
53
+ "@ttoss/config": "^1.35.2",
54
+ "@ttoss/i18n-cli": "^0.7.26",
55
+ "@ttoss/react-i18n": "^2.0.8",
56
+ "@ttoss/react-icons": "^0.4.8",
57
+ "@ttoss/ui": "^5.0.14",
58
+ "@ttoss/test-utils": "^2.1.21"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public",