@timeax/form-palette 0.0.38 → 0.1.0

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/extra.mjs CHANGED
@@ -7853,7 +7853,6 @@ var DEFAULT_COUNTRIES = [
7853
7853
  }
7854
7854
  ];
7855
7855
  cachedCountries = DEFAULT_COUNTRIES;
7856
- var validatedOnce = false;
7857
7856
  function isPhoneCountry(value) {
7858
7857
  if (!value || typeof value !== "object") return false;
7859
7858
  const v2 = value;
@@ -7863,35 +7862,35 @@ function getGlobalCountryList() {
7863
7862
  var _a;
7864
7863
  if (cachedCountries) return cachedCountries;
7865
7864
  if (typeof window === "undefined") {
7866
- cachedCountries = [];
7867
- return cachedCountries;
7865
+ return DEFAULT_COUNTRIES;
7868
7866
  }
7869
7867
  const raw = (_a = window["form-palette"]) == null ? void 0 : _a.countries;
7870
- if (!Array.isArray(raw)) {
7871
- if (!validatedOnce && true) {
7872
- console.warn(
7873
- "['form-palette'] window.'form-palette'.countries is not an array:",
7874
- raw
7875
- );
7868
+ if (Array.isArray(raw) && raw.length > 0) {
7869
+ const result = [];
7870
+ for (const item of raw) {
7871
+ if (isPhoneCountry(item)) {
7872
+ result.push(item);
7873
+ }
7876
7874
  }
7877
- validatedOnce = true;
7878
- cachedCountries = [];
7879
- return cachedCountries;
7880
- }
7881
- const result = [];
7882
- for (const item of raw) {
7883
- if (isPhoneCountry(item)) {
7884
- result.push(item);
7885
- } else {
7886
- console.warn(
7887
- "['form-palette'] Ignoring invalid PhoneCountry entry:",
7888
- item
7889
- );
7875
+ if (result.length > 0) {
7876
+ cachedCountries = result;
7877
+ return result;
7890
7878
  }
7891
7879
  }
7892
- validatedOnce = true;
7893
- cachedCountries = result;
7894
- return result;
7880
+ cachedCountries = DEFAULT_COUNTRIES;
7881
+ return cachedCountries;
7882
+ }
7883
+
7884
+ // src/lib/register-global.ts
7885
+ function getPaletteUtil(key, defaultValue) {
7886
+ if (typeof window === "undefined") {
7887
+ return defaultValue;
7888
+ }
7889
+ const registry2 = window["form-palette"];
7890
+ if (registry2 && key in registry2) {
7891
+ return registry2[key];
7892
+ }
7893
+ return defaultValue;
7895
7894
  }
7896
7895
  var TOKEN_CHARS = /* @__PURE__ */ new Set(["9", "a", "*"]);
7897
7896
  function compileMask(pattern, placeholderChar = "_") {
@@ -8106,7 +8105,19 @@ var ShadcnPhoneVariant = React.forwardRef(function ShadcnPhoneVariant2(props, re
8106
8105
  ...restTextProps
8107
8106
  } = props;
8108
8107
  let DEFAULT_COUNTRIES2 = getGlobalCountryList();
8109
- const countries = countriesProp && countriesProp.length > 0 ? countriesProp : DEFAULT_COUNTRIES2;
8108
+ const defaultCountries = countriesProp && countriesProp.length > 0 ? countriesProp : DEFAULT_COUNTRIES2;
8109
+ const [loadedCountries, setLoadedCountries] = React.useState(defaultCountries);
8110
+ React.useEffect(() => {
8111
+ const loader = getPaletteUtil("countries");
8112
+ if (loader) {
8113
+ Promise.resolve(loader).then((list) => {
8114
+ setLoadedCountries(list);
8115
+ });
8116
+ }
8117
+ }, []);
8118
+ const countries = React.useMemo(() => {
8119
+ return defaultCountries;
8120
+ }, [loadedCountries, countriesProp]);
8110
8121
  const [country, setCountry] = React.useState(() => {
8111
8122
  var _a;
8112
8123
  if (defaultCountry) {
@@ -19467,9 +19478,10 @@ var ShadcnFileVariant = React.forwardRef(function ShadcnFileVariant2(props, ref)
19467
19478
  const openPicker = React.useCallback(async () => {
19468
19479
  var _a;
19469
19480
  if (isDisabled) return;
19470
- if (customLoader) {
19481
+ let resolvedLoader = customLoader != null ? customLoader : getPaletteUtil("customLoader");
19482
+ if (resolvedLoader) {
19471
19483
  try {
19472
- const result = await customLoader({ multiple, current: items });
19484
+ const result = await resolvedLoader({ multiple, current: items, allowedTypes: toArray2(accept) });
19473
19485
  if (!result) return;
19474
19486
  const normalized = toArray2(result).map(normaliseFileLike);
19475
19487
  if (mergeMode === "replace" || !multiple) {