@timeax/form-palette 0.0.38 → 0.0.39

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.mjs CHANGED
@@ -7999,7 +7999,6 @@ var DEFAULT_COUNTRIES = [
7999
7999
  }
8000
8000
  ];
8001
8001
  cachedCountries = DEFAULT_COUNTRIES;
8002
- var validatedOnce = false;
8003
8002
  function isPhoneCountry(value) {
8004
8003
  if (!value || typeof value !== "object") return false;
8005
8004
  const v2 = value;
@@ -8009,35 +8008,42 @@ function getGlobalCountryList() {
8009
8008
  var _a;
8010
8009
  if (cachedCountries) return cachedCountries;
8011
8010
  if (typeof window === "undefined") {
8012
- cachedCountries = [];
8013
- return cachedCountries;
8011
+ return DEFAULT_COUNTRIES;
8014
8012
  }
8015
8013
  const raw = (_a = window["form-palette"]) == null ? void 0 : _a.countries;
8016
- if (!Array.isArray(raw)) {
8017
- if (!validatedOnce && true) {
8018
- console.warn(
8019
- "['form-palette'] window.'form-palette'.countries is not an array:",
8020
- raw
8021
- );
8014
+ if (Array.isArray(raw) && raw.length > 0) {
8015
+ const result = [];
8016
+ for (const item of raw) {
8017
+ if (isPhoneCountry(item)) {
8018
+ result.push(item);
8019
+ }
8022
8020
  }
8023
- validatedOnce = true;
8024
- cachedCountries = [];
8025
- return cachedCountries;
8026
- }
8027
- const result = [];
8028
- for (const item of raw) {
8029
- if (isPhoneCountry(item)) {
8030
- result.push(item);
8031
- } else {
8032
- console.warn(
8033
- "['form-palette'] Ignoring invalid PhoneCountry entry:",
8034
- item
8035
- );
8021
+ if (result.length > 0) {
8022
+ cachedCountries = result;
8023
+ return result;
8036
8024
  }
8037
8025
  }
8038
- validatedOnce = true;
8039
- cachedCountries = result;
8040
- return result;
8026
+ cachedCountries = DEFAULT_COUNTRIES;
8027
+ return cachedCountries;
8028
+ }
8029
+
8030
+ // src/lib/register-global.ts
8031
+ function registerPaletteUtil(key, value) {
8032
+ if (typeof window === "undefined") return;
8033
+ if (!window["form-palette"]) {
8034
+ window["form-palette"] = {};
8035
+ }
8036
+ window["form-palette"][key] = value;
8037
+ }
8038
+ function getPaletteUtil(key, defaultValue) {
8039
+ if (typeof window === "undefined") {
8040
+ return defaultValue;
8041
+ }
8042
+ const registry3 = window["form-palette"];
8043
+ if (registry3 && key in registry3) {
8044
+ return registry3[key];
8045
+ }
8046
+ return defaultValue;
8041
8047
  }
8042
8048
  var TOKEN_CHARS = /* @__PURE__ */ new Set(["9", "a", "*"]);
8043
8049
  function compileMask(pattern, placeholderChar = "_") {
@@ -8252,7 +8258,19 @@ var ShadcnPhoneVariant = React68.forwardRef(function ShadcnPhoneVariant2(props,
8252
8258
  ...restTextProps
8253
8259
  } = props;
8254
8260
  let DEFAULT_COUNTRIES2 = getGlobalCountryList();
8255
- const countries = countriesProp && countriesProp.length > 0 ? countriesProp : DEFAULT_COUNTRIES2;
8261
+ const defaultCountries = countriesProp && countriesProp.length > 0 ? countriesProp : DEFAULT_COUNTRIES2;
8262
+ const [loadedCountries, setLoadedCountries] = React68.useState(defaultCountries);
8263
+ React68.useEffect(() => {
8264
+ const loader = getPaletteUtil("countries");
8265
+ if (loader) {
8266
+ Promise.resolve(loader).then((list) => {
8267
+ setLoadedCountries(list);
8268
+ });
8269
+ }
8270
+ }, []);
8271
+ const countries = React68.useMemo(() => {
8272
+ return defaultCountries;
8273
+ }, [loadedCountries, countriesProp]);
8256
8274
  const [country, setCountry] = React68.useState(() => {
8257
8275
  var _a;
8258
8276
  if (defaultCountry) {
@@ -19782,9 +19800,10 @@ var ShadcnFileVariant = React68.forwardRef(function ShadcnFileVariant2(props, re
19782
19800
  const openPicker = React68.useCallback(async () => {
19783
19801
  var _a;
19784
19802
  if (isDisabled) return;
19785
- if (customLoader) {
19803
+ let resolvedLoader = customLoader != null ? customLoader : getPaletteUtil("customLoader");
19804
+ if (resolvedLoader) {
19786
19805
  try {
19787
- const result = await customLoader({ multiple, current: items });
19806
+ const result = await resolvedLoader({ multiple, current: items, allowedTypes: toArray(accept) });
19788
19807
  if (!result) return;
19789
19808
  const normalized = toArray(result).map(normaliseFileLike);
19790
19809
  if (mergeMode === "replace" || !multiple) {
@@ -27897,6 +27916,6 @@ lucide-react/dist/esm/lucide-react.js:
27897
27916
  *)
27898
27917
  */
27899
27918
 
27900
- export { CoreProvider, ErrorStrip, CoreShell as Form, CoreRoot as FormRoot, Input, InputField, InputMask, InputNumber, Textarea, createAxiosAdapter, createInertiaAdapter, getAdapter, getVariant, hasAdapter, listVariants, localAdapter, mapErrorBag, mapZodError, registerAdapter, registerAllAdapters, registerAxiosAdapter, registerCoreVariants, registerInertiaAdapter, registerKnownAdapter, registerVariant, useButton, useCore, useCoreContext, useField, useOptionalField };
27919
+ export { CoreProvider, ErrorStrip, CoreShell as Form, CoreRoot as FormRoot, Input, InputField, InputMask, InputNumber, Textarea, createAxiosAdapter, createInertiaAdapter, getAdapter, getPaletteUtil, getVariant, hasAdapter, listVariants, localAdapter, mapErrorBag, mapZodError, registerAdapter, registerAllAdapters, registerAxiosAdapter, registerCoreVariants, registerInertiaAdapter, registerKnownAdapter, registerPaletteUtil, registerVariant, useButton, useCore, useCoreContext, useField, useOptionalField };
27901
27920
  //# sourceMappingURL=index.mjs.map
27902
27921
  //# sourceMappingURL=index.mjs.map