@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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as Dict, C as CoreProps, a as CoreContext, F as Field, V as VariantKey, L as LabelPlacement, S as SublabelPlacement, b as DescriptionPlacement, H as HelpTextPlacement, E as ErrorTextPlacement, c as SlotPlacement, d as FieldSize, e as FieldDensity, f as ValidateResult, g as ChangeDetail, h as VariantValueFor, i as VariantPropsFor, j as VariantModule } from './variant-DFE9TgIv.mjs';
2
- export { B as BaseProps, p as ButtonRef, w as EffectiveFieldLayout, v as FieldLayoutConfig, u as FieldOrdering, t as FieldRootId, r as FieldRoots, s as FieldSlotId, q as FieldSlots, m as FormProps, k as InferFromSchema, I as InputNumber, o as InputStore, x as LayoutResolveContext, y as LayoutResolver, R as RelativeRootsMap, l as SubmitEvent, T as Textarea, n as ValuesResult, z as VariantEntry, J as VariantLayoutDefaults, K as VariantModuleFor, G as VariantValidateFn, A as Variants } from './variant-DFE9TgIv.mjs';
1
+ import { D as Dict, C as CoreProps, a as CoreContext, F as Field, V as VariantKey, L as LabelPlacement, S as SublabelPlacement, b as DescriptionPlacement, H as HelpTextPlacement, E as ErrorTextPlacement, c as SlotPlacement, d as FieldSize, e as FieldDensity, f as ValidateResult, g as ChangeDetail, h as VariantValueFor, i as VariantPropsFor, j as VariantModule, P as PhoneCountry, k as PasswordDefinitionMap, l as CustomFileLoader } from './variant-aFXJGBXI.mjs';
2
+ export { B as BaseProps, r as ButtonRef, y as EffectiveFieldLayout, x as FieldLayoutConfig, w as FieldOrdering, v as FieldRootId, t as FieldRoots, u as FieldSlotId, s as FieldSlots, o as FormProps, m as InferFromSchema, I as InputNumber, q as InputStore, z as LayoutResolveContext, A as LayoutResolver, R as RelativeRootsMap, n as SubmitEvent, T as Textarea, p as ValuesResult, G as VariantEntry, M as VariantLayoutDefaults, N as VariantModuleFor, K as VariantValidateFn, J as Variants } from './variant-aFXJGBXI.mjs';
3
3
  import { A as AdapterKey } from './adapter-CvjXO9Gi.mjs';
4
4
  export { a as AdapterCallbacks, c as AdapterConfig, h as AdapterError, d as AdapterFactory, g as AdapterOk, f as AdapterProps, b as AdapterResult, i as AdapterSubmit, e as Adapters, M as Method, N as NamedAdapterConfig, j as NamedAdapterFactory } from './adapter-CvjXO9Gi.mjs';
5
5
  export { createAxiosAdapter, createInertiaAdapter, getAdapter, hasAdapter, localAdapter, registerAdapter, registerAllAdapters, registerAxiosAdapter, registerInertiaAdapter, registerKnownAdapter } from './adapters.mjs';
@@ -676,4 +676,26 @@ interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "
676
676
  }
677
677
  declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
678
678
 
679
- export { AdapterKey, CoreContext, CoreProps, CoreProvider, type CoreShellProps, DescriptionPlacement, Dict, type ErrorBag, type ErrorBagMapResult, ErrorStrip, type ErrorStripProps, ErrorTextPlacement, Field, CoreShell as Form, CoreRoot as FormRoot, HelpTextPlacement, Input, InputField, type InputFieldBaseProps, type InputFieldProps, InputMask, LabelPlacement, SlotPlacement, SublabelPlacement, type UseButtonOptions, type UseButtonReturn, type UseFieldOptions, type UseFieldReturn, type UseFieldValidate, ValidateResult, VariantKey, VariantModule, VariantPropsFor, VariantValueFor, type ZodErrorMapResult, getVariant, listVariants, mapErrorBag, mapZodError, registerCoreVariants, registerVariant, useButton, useCore, useCoreContext, useField, useOptionalField };
679
+ interface PaletteRegistry {
680
+ countries: PhoneCountry[];
681
+ ruleDefinition: PasswordDefinitionMap;
682
+ customLoader: CustomFileLoader;
683
+ getCountries: () => Promise<PhoneCountry[]>;
684
+ }
685
+ declare global {
686
+ interface Window {
687
+ "form-palette"?: Partial<PaletteRegistry>;
688
+ }
689
+ }
690
+ /**
691
+ * Registers a value to the global window['form-palette'] object.
692
+ * Safe to call in SSR environments (it will just no-op).
693
+ */
694
+ declare function registerPaletteUtil<K extends keyof PaletteRegistry>(key: K, value: PaletteRegistry[K]): void;
695
+ /**
696
+ * Retrieves a value from the global window['form-palette'] object.
697
+ * Returns the value if found, otherwise returns the optional defaultValue or undefined.
698
+ */
699
+ declare function getPaletteUtil<K extends keyof PaletteRegistry>(key: K, defaultValue?: PaletteRegistry[K]): PaletteRegistry[K] | undefined;
700
+
701
+ export { AdapterKey, CoreContext, CoreProps, CoreProvider, type CoreShellProps, DescriptionPlacement, Dict, type ErrorBag, type ErrorBagMapResult, ErrorStrip, type ErrorStripProps, ErrorTextPlacement, Field, CoreShell as Form, CoreRoot as FormRoot, HelpTextPlacement, Input, InputField, type InputFieldBaseProps, type InputFieldProps, InputMask, LabelPlacement, SlotPlacement, SublabelPlacement, type UseButtonOptions, type UseButtonReturn, type UseFieldOptions, type UseFieldReturn, type UseFieldValidate, ValidateResult, VariantKey, VariantModule, VariantPropsFor, VariantValueFor, type ZodErrorMapResult, getPaletteUtil, getVariant, listVariants, mapErrorBag, mapZodError, registerCoreVariants, registerPaletteUtil, registerVariant, useButton, useCore, useCoreContext, useField, useOptionalField };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as Dict, C as CoreProps, a as CoreContext, F as Field, V as VariantKey, L as LabelPlacement, S as SublabelPlacement, b as DescriptionPlacement, H as HelpTextPlacement, E as ErrorTextPlacement, c as SlotPlacement, d as FieldSize, e as FieldDensity, f as ValidateResult, g as ChangeDetail, h as VariantValueFor, i as VariantPropsFor, j as VariantModule } from './variant-HaGlyCnL.js';
2
- export { B as BaseProps, p as ButtonRef, w as EffectiveFieldLayout, v as FieldLayoutConfig, u as FieldOrdering, t as FieldRootId, r as FieldRoots, s as FieldSlotId, q as FieldSlots, m as FormProps, k as InferFromSchema, I as InputNumber, o as InputStore, x as LayoutResolveContext, y as LayoutResolver, R as RelativeRootsMap, l as SubmitEvent, T as Textarea, n as ValuesResult, z as VariantEntry, J as VariantLayoutDefaults, K as VariantModuleFor, G as VariantValidateFn, A as Variants } from './variant-HaGlyCnL.js';
1
+ import { D as Dict, C as CoreProps, a as CoreContext, F as Field, V as VariantKey, L as LabelPlacement, S as SublabelPlacement, b as DescriptionPlacement, H as HelpTextPlacement, E as ErrorTextPlacement, c as SlotPlacement, d as FieldSize, e as FieldDensity, f as ValidateResult, g as ChangeDetail, h as VariantValueFor, i as VariantPropsFor, j as VariantModule, P as PhoneCountry, k as PasswordDefinitionMap, l as CustomFileLoader } from './variant-Jrd0I0Ey.js';
2
+ export { B as BaseProps, r as ButtonRef, y as EffectiveFieldLayout, x as FieldLayoutConfig, w as FieldOrdering, v as FieldRootId, t as FieldRoots, u as FieldSlotId, s as FieldSlots, o as FormProps, m as InferFromSchema, I as InputNumber, q as InputStore, z as LayoutResolveContext, A as LayoutResolver, R as RelativeRootsMap, n as SubmitEvent, T as Textarea, p as ValuesResult, G as VariantEntry, M as VariantLayoutDefaults, N as VariantModuleFor, K as VariantValidateFn, J as Variants } from './variant-Jrd0I0Ey.js';
3
3
  import { A as AdapterKey } from './adapter-CvjXO9Gi.js';
4
4
  export { a as AdapterCallbacks, c as AdapterConfig, h as AdapterError, d as AdapterFactory, g as AdapterOk, f as AdapterProps, b as AdapterResult, i as AdapterSubmit, e as Adapters, M as Method, N as NamedAdapterConfig, j as NamedAdapterFactory } from './adapter-CvjXO9Gi.js';
5
5
  export { createAxiosAdapter, createInertiaAdapter, getAdapter, hasAdapter, localAdapter, registerAdapter, registerAllAdapters, registerAxiosAdapter, registerInertiaAdapter, registerKnownAdapter } from './adapters.js';
@@ -676,4 +676,26 @@ interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "
676
676
  }
677
677
  declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
678
678
 
679
- export { AdapterKey, CoreContext, CoreProps, CoreProvider, type CoreShellProps, DescriptionPlacement, Dict, type ErrorBag, type ErrorBagMapResult, ErrorStrip, type ErrorStripProps, ErrorTextPlacement, Field, CoreShell as Form, CoreRoot as FormRoot, HelpTextPlacement, Input, InputField, type InputFieldBaseProps, type InputFieldProps, InputMask, LabelPlacement, SlotPlacement, SublabelPlacement, type UseButtonOptions, type UseButtonReturn, type UseFieldOptions, type UseFieldReturn, type UseFieldValidate, ValidateResult, VariantKey, VariantModule, VariantPropsFor, VariantValueFor, type ZodErrorMapResult, getVariant, listVariants, mapErrorBag, mapZodError, registerCoreVariants, registerVariant, useButton, useCore, useCoreContext, useField, useOptionalField };
679
+ interface PaletteRegistry {
680
+ countries: PhoneCountry[];
681
+ ruleDefinition: PasswordDefinitionMap;
682
+ customLoader: CustomFileLoader;
683
+ getCountries: () => Promise<PhoneCountry[]>;
684
+ }
685
+ declare global {
686
+ interface Window {
687
+ "form-palette"?: Partial<PaletteRegistry>;
688
+ }
689
+ }
690
+ /**
691
+ * Registers a value to the global window['form-palette'] object.
692
+ * Safe to call in SSR environments (it will just no-op).
693
+ */
694
+ declare function registerPaletteUtil<K extends keyof PaletteRegistry>(key: K, value: PaletteRegistry[K]): void;
695
+ /**
696
+ * Retrieves a value from the global window['form-palette'] object.
697
+ * Returns the value if found, otherwise returns the optional defaultValue or undefined.
698
+ */
699
+ declare function getPaletteUtil<K extends keyof PaletteRegistry>(key: K, defaultValue?: PaletteRegistry[K]): PaletteRegistry[K] | undefined;
700
+
701
+ export { AdapterKey, CoreContext, CoreProps, CoreProvider, type CoreShellProps, DescriptionPlacement, Dict, type ErrorBag, type ErrorBagMapResult, ErrorStrip, type ErrorStripProps, ErrorTextPlacement, Field, CoreShell as Form, CoreRoot as FormRoot, HelpTextPlacement, Input, InputField, type InputFieldBaseProps, type InputFieldProps, InputMask, LabelPlacement, SlotPlacement, SublabelPlacement, type UseButtonOptions, type UseButtonReturn, type UseFieldOptions, type UseFieldReturn, type UseFieldValidate, ValidateResult, VariantKey, VariantModule, VariantPropsFor, VariantValueFor, type ZodErrorMapResult, getPaletteUtil, getVariant, listVariants, mapErrorBag, mapZodError, registerCoreVariants, registerPaletteUtil, registerVariant, useButton, useCore, useCoreContext, useField, useOptionalField };
package/dist/index.js CHANGED
@@ -8037,7 +8037,6 @@ var DEFAULT_COUNTRIES = [
8037
8037
  }
8038
8038
  ];
8039
8039
  cachedCountries = DEFAULT_COUNTRIES;
8040
- var validatedOnce = false;
8041
8040
  function isPhoneCountry(value) {
8042
8041
  if (!value || typeof value !== "object") return false;
8043
8042
  const v2 = value;
@@ -8047,35 +8046,42 @@ function getGlobalCountryList() {
8047
8046
  var _a;
8048
8047
  if (cachedCountries) return cachedCountries;
8049
8048
  if (typeof window === "undefined") {
8050
- cachedCountries = [];
8051
- return cachedCountries;
8049
+ return DEFAULT_COUNTRIES;
8052
8050
  }
8053
8051
  const raw = (_a = window["form-palette"]) == null ? void 0 : _a.countries;
8054
- if (!Array.isArray(raw)) {
8055
- if (!validatedOnce && true) {
8056
- console.warn(
8057
- "['form-palette'] window.'form-palette'.countries is not an array:",
8058
- raw
8059
- );
8052
+ if (Array.isArray(raw) && raw.length > 0) {
8053
+ const result = [];
8054
+ for (const item of raw) {
8055
+ if (isPhoneCountry(item)) {
8056
+ result.push(item);
8057
+ }
8060
8058
  }
8061
- validatedOnce = true;
8062
- cachedCountries = [];
8063
- return cachedCountries;
8064
- }
8065
- const result = [];
8066
- for (const item of raw) {
8067
- if (isPhoneCountry(item)) {
8068
- result.push(item);
8069
- } else {
8070
- console.warn(
8071
- "['form-palette'] Ignoring invalid PhoneCountry entry:",
8072
- item
8073
- );
8059
+ if (result.length > 0) {
8060
+ cachedCountries = result;
8061
+ return result;
8074
8062
  }
8075
8063
  }
8076
- validatedOnce = true;
8077
- cachedCountries = result;
8078
- return result;
8064
+ cachedCountries = DEFAULT_COUNTRIES;
8065
+ return cachedCountries;
8066
+ }
8067
+
8068
+ // src/lib/register-global.ts
8069
+ function registerPaletteUtil(key, value) {
8070
+ if (typeof window === "undefined") return;
8071
+ if (!window["form-palette"]) {
8072
+ window["form-palette"] = {};
8073
+ }
8074
+ window["form-palette"][key] = value;
8075
+ }
8076
+ function getPaletteUtil(key, defaultValue) {
8077
+ if (typeof window === "undefined") {
8078
+ return defaultValue;
8079
+ }
8080
+ const registry3 = window["form-palette"];
8081
+ if (registry3 && key in registry3) {
8082
+ return registry3[key];
8083
+ }
8084
+ return defaultValue;
8079
8085
  }
8080
8086
  var TOKEN_CHARS = /* @__PURE__ */ new Set(["9", "a", "*"]);
8081
8087
  function compileMask(pattern, placeholderChar = "_") {
@@ -8290,7 +8296,19 @@ var ShadcnPhoneVariant = React68__namespace.forwardRef(function ShadcnPhoneVaria
8290
8296
  ...restTextProps
8291
8297
  } = props;
8292
8298
  let DEFAULT_COUNTRIES2 = getGlobalCountryList();
8293
- const countries = countriesProp && countriesProp.length > 0 ? countriesProp : DEFAULT_COUNTRIES2;
8299
+ const defaultCountries = countriesProp && countriesProp.length > 0 ? countriesProp : DEFAULT_COUNTRIES2;
8300
+ const [loadedCountries, setLoadedCountries] = React68__namespace.useState(defaultCountries);
8301
+ React68__namespace.useEffect(() => {
8302
+ const loader = getPaletteUtil("countries");
8303
+ if (loader) {
8304
+ Promise.resolve(loader).then((list) => {
8305
+ setLoadedCountries(list);
8306
+ });
8307
+ }
8308
+ }, []);
8309
+ const countries = React68__namespace.useMemo(() => {
8310
+ return defaultCountries;
8311
+ }, [loadedCountries, countriesProp]);
8294
8312
  const [country, setCountry] = React68__namespace.useState(() => {
8295
8313
  var _a;
8296
8314
  if (defaultCountry) {
@@ -19820,9 +19838,10 @@ var ShadcnFileVariant = React68__namespace.forwardRef(function ShadcnFileVariant
19820
19838
  const openPicker = React68__namespace.useCallback(async () => {
19821
19839
  var _a;
19822
19840
  if (isDisabled) return;
19823
- if (customLoader) {
19841
+ let resolvedLoader = customLoader != null ? customLoader : getPaletteUtil("customLoader");
19842
+ if (resolvedLoader) {
19824
19843
  try {
19825
- const result = await customLoader({ multiple, current: items });
19844
+ const result = await resolvedLoader({ multiple, current: items, allowedTypes: toArray(accept) });
19826
19845
  if (!result) return;
19827
19846
  const normalized = toArray(result).map(normaliseFileLike);
19828
19847
  if (mergeMode === "replace" || !multiple) {
@@ -27947,6 +27966,7 @@ exports.Textarea = Textarea;
27947
27966
  exports.createAxiosAdapter = createAxiosAdapter;
27948
27967
  exports.createInertiaAdapter = createInertiaAdapter;
27949
27968
  exports.getAdapter = getAdapter;
27969
+ exports.getPaletteUtil = getPaletteUtil;
27950
27970
  exports.getVariant = getVariant;
27951
27971
  exports.hasAdapter = hasAdapter;
27952
27972
  exports.listVariants = listVariants;
@@ -27959,6 +27979,7 @@ exports.registerAxiosAdapter = registerAxiosAdapter;
27959
27979
  exports.registerCoreVariants = registerCoreVariants;
27960
27980
  exports.registerInertiaAdapter = registerInertiaAdapter;
27961
27981
  exports.registerKnownAdapter = registerKnownAdapter;
27982
+ exports.registerPaletteUtil = registerPaletteUtil;
27962
27983
  exports.registerVariant = registerVariant;
27963
27984
  exports.useButton = useButton;
27964
27985
  exports.useCore = useCore;