@mercurjs/dashboard-shared 2.3.9-canary.2 → 2.3.9-canary.4

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +149 -12
  2. package/dist/index.js +340 -106
  3. package/package.json +5 -5
package/dist/index.d.ts CHANGED
@@ -1816,6 +1816,14 @@ type ResolvedFormField = {
1816
1816
  name: string;
1817
1817
  field: CustomFormField;
1818
1818
  };
1819
+ /**
1820
+ * A config entry keyed by a built-in field id. `field: null` removes the
1821
+ * built-in; a field replaces it.
1822
+ */
1823
+ type FormFieldOverride = {
1824
+ overridden: boolean;
1825
+ field: CustomFormField | null;
1826
+ };
1819
1827
  type OnboardingStep = {
1820
1828
  id: string;
1821
1829
  label?: string;
@@ -1896,8 +1904,15 @@ declare class ExtensionRegistry {
1896
1904
  getActionLock(model: string, action: string, entity: unknown): string | undefined;
1897
1905
  getActivity(model: string, entity: unknown): ActivityEntry[];
1898
1906
  private resolveFormFields;
1899
- /** Custom form fields for a model's form zone (and optional tab). */
1900
- getFormFields(model: string, zone: string, tab?: string): ResolvedFormField[];
1907
+ private formEntriesFor;
1908
+ /**
1909
+ * Custom form fields added to a model's form zone (and optional tab). Entries
1910
+ * keyed by one of the host's `builtInFieldIds` are overrides, not additions,
1911
+ * and are read through `getFormFieldOverride` instead.
1912
+ */
1913
+ getFormFields(model: string, zone: string, tab?: string, builtInFieldIds?: string[], exactTab?: boolean): ResolvedFormField[];
1914
+ /** Replacement (or removal, `field: null`) of a built-in form field. */
1915
+ getFormFieldOverride(model: string, zone: string, id: string, tab?: string, exactTab?: boolean): FormFieldOverride;
1901
1916
  /**
1902
1917
  * Resolves the onboarding wizard steps: built-ins merged with every
1903
1918
  * `zone: "onboarding"` form entry for the model. Later configs win per tab.
@@ -1907,8 +1922,11 @@ declare class ExtensionRegistry {
1907
1922
  getAllFormFields(model: string): ResolvedFormField[];
1908
1923
  /** Section display contributions (field add/replace/remove + actions). */
1909
1924
  getDisplays(model: string, zone: string): ResolvedDisplays;
1910
- /** Merged list-table extension for a model. */
1911
- getListExtension(model: string): CustomListExtension;
1925
+ /**
1926
+ * Merged table extension for a model. `zone` picks the table: `"list"` is the
1927
+ * model's list page, and also matches `list` blocks that omit a zone.
1928
+ */
1929
+ getListExtension(model: string, zone?: string): CustomListExtension;
1912
1930
  }
1913
1931
 
1914
1932
  type RenderDefaultProps = {
@@ -2054,19 +2072,43 @@ declare function groupNavItems<T extends {
2054
2072
  groups: NavItemGroup<T>[];
2055
2073
  };
2056
2074
 
2057
- type FormExtensionZoneProps = {
2075
+ type AnyControl<TFieldValues extends FieldValues, TContext, TTransformed> = Control<TFieldValues, TContext, TTransformed>;
2076
+ type FormExtensionZoneProps<TFieldValues extends FieldValues = FieldValues, TContext = unknown, TTransformed = TFieldValues> = {
2058
2077
  model: string;
2059
2078
  zone: string;
2060
2079
  tab?: string;
2061
- control: Control<any>;
2080
+ control: AnyControl<TFieldValues, TContext, TTransformed>;
2062
2081
  data?: unknown;
2082
+ /** The form's own field ids; config entries for them are overrides. */
2083
+ builtInFieldIds?: string[];
2084
+ /**
2085
+ * Render only fields aimed at `tab`. A tabbed form sets it on every tab but
2086
+ * the first, so untabbed fields render once.
2087
+ */
2088
+ exactTab?: boolean;
2063
2089
  };
2064
2090
  /**
2065
2091
  * Renders a model's custom form fields for a given zone/tab under the
2066
2092
  * `additional_data.<field>` RHF namespace (Medusa's convention), through the
2067
2093
  * mandated `Form.Field → Form.Item` primitive chain.
2068
2094
  */
2069
- declare const FormExtensionZone: ({ model, zone, tab, control, data, }: FormExtensionZoneProps) => react_jsx_runtime.JSX.Element | null;
2095
+ declare const FormExtensionZone: <TFieldValues extends FieldValues, TContext, TTransformed>({ model, zone, tab, control, data, builtInFieldIds, exactTab, }: FormExtensionZoneProps<TFieldValues, TContext, TTransformed>) => react_jsx_runtime.JSX.Element | null;
2096
+ type ExtendableFormFieldProps<TFieldValues extends FieldValues = FieldValues, TContext = unknown, TTransformed = TFieldValues> = {
2097
+ model: string;
2098
+ zone: string;
2099
+ tab?: string;
2100
+ /** The built-in field's form key, which is also its override id. */
2101
+ id: string;
2102
+ control: AnyControl<TFieldValues, TContext, TTransformed>;
2103
+ data?: unknown;
2104
+ children: ReactNode;
2105
+ };
2106
+ /**
2107
+ * Wraps one of a form's own fields so `forms[].fields[id]` can replace it (the
2108
+ * replacement binds to the same form key; validation stays the base schema's)
2109
+ * or remove it (`null`, the field keeps its default value).
2110
+ */
2111
+ declare const ExtendableFormField: <TFieldValues extends FieldValues, TContext, TTransformed>({ model, zone, tab, id, control, data, children, }: ExtendableFormFieldProps<TFieldValues, TContext, TTransformed>) => react_jsx_runtime.JSX.Element | null;
2070
2112
 
2071
2113
  type DisplayExtensionZoneProps = {
2072
2114
  model: string;
@@ -2136,6 +2178,11 @@ declare function useDisplayFieldOverride(model: string, zone: string, id: string
2136
2178
  type UseExtendableTableProps<TData> = {
2137
2179
  /** Model whose custom-fields `list` block extends this table (e.g. `product`). */
2138
2180
  model: string;
2181
+ /**
2182
+ * Which of the model's tables this is. Defaults to `"list"` (the list page);
2183
+ * embedded tables pass their own zone so `list` blocks can target them.
2184
+ */
2185
+ zone?: string;
2139
2186
  /** Base columns to extend. */
2140
2187
  columns: ColumnDef<TData, unknown>[];
2141
2188
  };
@@ -2156,7 +2203,52 @@ type ExtendableTable<TData> = {
2156
2203
  * (merge them into the base filters with `mergeListFilters`) and `bulkActions`
2157
2204
  * for the caller to render.
2158
2205
  */
2159
- declare function useExtendableTable<TData>({ model, columns: baseColumns, }: UseExtendableTableProps<TData>): ExtendableTable<TData>;
2206
+ declare function useExtendableTable<TData>({ model, zone, columns: baseColumns, }: UseExtendableTableProps<TData>): ExtendableTable<TData>;
2207
+
2208
+ type GridFieldName<TData> = (context: {
2209
+ row: {
2210
+ original: TData;
2211
+ };
2212
+ }) => string | null;
2213
+ type ExtensionGridColumnArgs<TData> = {
2214
+ id: string;
2215
+ field: CustomFormField;
2216
+ /** Form path the cell edits; `null` renders it read-only. */
2217
+ getFieldName: GridFieldName<TData>;
2218
+ };
2219
+ type UseExtendableGridProps<TData> = {
2220
+ model: string;
2221
+ zone: string;
2222
+ tab?: string;
2223
+ /** Base data-grid columns (built with the panel's `createDataGridHelper`). */
2224
+ columns: ColumnDef<TData, unknown>[];
2225
+ /** Base column ids that can't be removed or replaced (e.g. the row title). */
2226
+ lockedColumnIds?: string[];
2227
+ /**
2228
+ * Whether config fields the grid doesn't ship become columns. Off for grids
2229
+ * whose rows have nowhere to save `additional_data`.
2230
+ */
2231
+ allowAdd?: boolean;
2232
+ /**
2233
+ * Form path of a row's entry (e.g. `variants.3`); added fields bind to
2234
+ * `<path>.additional_data.<id>`. `null` keeps the row read-only. Omit it
2235
+ * together with `allowAdd: false`.
2236
+ */
2237
+ getRowPath?: (row: TData) => string | null;
2238
+ /**
2239
+ * Builds a grid column for a config field. Panels ship their own DataGrid
2240
+ * cells, so the cell rendering stays on the panel side.
2241
+ */
2242
+ createColumn: (args: ExtensionGridColumnArgs<TData>) => ColumnDef<TData, unknown>;
2243
+ };
2244
+ /**
2245
+ * Applies a form tab's `forms[].fields` to a data grid, the way
2246
+ * `<ExtendableFormField>` does for a regular form: a base column id + `null`
2247
+ * removes the column, a base id + field replaces how it renders (it keeps
2248
+ * editing the base column's form path), and any other key appends an editable
2249
+ * column bound to the row's `additional_data`.
2250
+ */
2251
+ declare function useExtendableGrid<TData>(props: UseExtendableGridProps<TData>): ColumnDef<TData, unknown>[];
2160
2252
 
2161
2253
  type Keyed = {
2162
2254
  key: string;
@@ -2211,14 +2303,54 @@ declare function createFormHelper<TData>(): {
2211
2303
  nullable: typeof z.nullable;
2212
2304
  coerce: typeof z.coerce;
2213
2305
  };
2306
+ type FormFieldInputType = "text" | "number" | "boolean" | "select" | "textarea";
2307
+ /** Input kind for a custom field: its explicit `type`, else its zod type. */
2308
+ declare function resolveFormFieldType(field: CustomFormField): FormFieldInputType;
2214
2309
  /**
2215
2310
  * Build the `additional_data` zod object for a model's custom fields, to merge
2216
2311
  * into a form's base schema. Custom-field values live under `additional_data`
2217
2312
  * so the built-in create/edit validators never see them.
2218
2313
  */
2219
- declare function buildAdditionalDataSchema(registry: ExtensionRegistry, model: string, zone?: string, tab?: string): z.ZodObject<Record<string, z.ZodTypeAny>>;
2314
+ declare function buildAdditionalDataSchema(registry: ExtensionRegistry, model: string, zone?: string, tab?: string, builtInFieldIds?: string[]): z.ZodObject<Record<string, z.ZodTypeAny>>;
2220
2315
  /** Resolve default values for a model's custom fields from the loaded entity. */
2221
- declare function buildAdditionalDataDefaults(registry: ExtensionRegistry, model: string, data?: unknown, zone?: string, tab?: string): Record<string, unknown>;
2316
+ declare function buildAdditionalDataDefaults(registry: ExtensionRegistry, model: string, data?: unknown, zone?: string, tab?: string, builtInFieldIds?: string[]): Record<string, unknown>;
2317
+ type AdditionalDataScope = {
2318
+ model: string;
2319
+ zone: string;
2320
+ /**
2321
+ * Tabs whose fields land in this form state. Untabbed fields of the zone are
2322
+ * included unless `exactTab` is set.
2323
+ */
2324
+ tabs?: string[];
2325
+ exactTab?: boolean;
2326
+ builtInFieldIds?: string[];
2327
+ };
2328
+ /**
2329
+ * `additional_data` schema and defaults for the fields of a zone's tabs. A
2330
+ * tabbed form passes its regular tabs; a data-grid tab passes `[tab]` with
2331
+ * `exactTab`, so the result describes one row.
2332
+ */
2333
+ declare function buildScopedAdditionalData(registry: ExtensionRegistry, { model, zone, tabs, exactTab, builtInFieldIds }: AdditionalDataScope, data?: unknown): {
2334
+ schema: z.ZodObject<Record<string, z.ZodTypeAny>>;
2335
+ defaults: Record<string, unknown>;
2336
+ };
2337
+ type AdditionalDataRows = {
2338
+ /** Form key of the row array (e.g. `variants`). */
2339
+ path: string;
2340
+ schema: z.ZodObject<Record<string, z.ZodTypeAny>>;
2341
+ /** Rows that are submitted; others skip validation. */
2342
+ include?: (row: Record<string, unknown>) => boolean;
2343
+ };
2344
+ /**
2345
+ * Validates custom fields on top of a base schema that can't be extended (a
2346
+ * refined object). Errors land on `additional_data.<field>` and
2347
+ * `<rows.path>.<i>.additional_data.<field>`, so form fields and grid cells
2348
+ * show them in place.
2349
+ */
2350
+ declare function refineAdditionalData<TSchema extends z.ZodTypeAny>(schema: TSchema, { additionalData, rows, }: {
2351
+ additionalData?: z.ZodObject<Record<string, z.ZodTypeAny>>;
2352
+ rows?: AdditionalDataRows;
2353
+ }): TSchema;
2222
2354
 
2223
2355
  type WithAdditionalData<T> = T & {
2224
2356
  additional_data?: Record<string, unknown>;
@@ -2240,6 +2372,11 @@ interface UseExtendableFormProps<TSchema extends ZodObject<Record<string, z.ZodT
2240
2372
  */
2241
2373
  zone?: string;
2242
2374
  tab?: string;
2375
+ /**
2376
+ * Ids of the form's own fields. Config entries keyed by one of them replace
2377
+ * or remove that field (`<ExtendableFormField>`) instead of adding one.
2378
+ */
2379
+ builtInFieldIds?: string[];
2243
2380
  }
2244
2381
  /**
2245
2382
  * `useForm` that merges a model's registered custom fields into the base
@@ -2248,7 +2385,7 @@ interface UseExtendableFormProps<TSchema extends ZodObject<Record<string, z.ZodT
2248
2385
  * built-in validators never see them; the extension registry provides the
2249
2386
  * per-field zod validation and default values.
2250
2387
  */
2251
- declare const useExtendableForm: <TSchema extends ZodObject<Record<string, z.ZodTypeAny>>, TContext = unknown, TTransformedValues extends FieldValues = WithAdditionalData<z.infer<TSchema>>>({ schema: baseSchema, defaultValues: baseDefaultValues, model, data, zone, tab, ...props }: UseExtendableFormProps<TSchema, TContext, unknown, TTransformedValues>) => react_hook_form.UseFormReturn<WithAdditionalData<z.core.output<TSchema>>, TContext, TTransformedValues>;
2388
+ declare const useExtendableForm: <TSchema extends ZodObject<Record<string, z.ZodTypeAny>>, TContext = unknown, TTransformedValues extends FieldValues = WithAdditionalData<z.infer<TSchema>>>({ schema: baseSchema, defaultValues: baseDefaultValues, model, data, zone, tab, builtInFieldIds, ...props }: UseExtendableFormProps<TSchema, TContext, unknown, TTransformedValues>) => react_hook_form.UseFormReturn<WithAdditionalData<z.core.output<TSchema>>, TContext, TTransformedValues>;
2252
2389
 
2253
2390
  /** Returns a lookup for the lock reason plugins declare on an entity's action. */
2254
2391
  declare const useActionLocks: (model: string, entity: unknown) => (action: string) => string | undefined;
@@ -2431,4 +2568,4 @@ declare const RICH_TEXT_ALLOWED_ATTRIBUTES: string[];
2431
2568
  declare const isHtml: (value?: string | null) => boolean;
2432
2569
  declare const plainTextToHtml: (value?: string | null) => string;
2433
2570
 
2434
- export { type Action, type ActionGroup, ActionMenu, AddressForm, AddressSchema, type AttributeChange, type AttributeChangeKind, AttributeValueInput, BadgeListSummary, CORE_ENTRY_PREFIX, CORE_LAYOUTS, ChipGroup, ChipInput, CodeCell, CodeHeader, Combobox, type Command, ConditionalTooltip, ConfirmPrompt, type ConfirmPromptProps, type CoreNavItem, CountrySelect, CreatedAtCell, CreatedAtHeader, type CurrencyInfo, type CustomFieldsModule, CustomerInfo, DataGrid, DataTable, DateCell, DateHeader, DateRangeDisplay, DeprecatedPercentageInput, type DetailPageDefaultsOptions, type DisplayEntry, DisplayExtensionZone, type DisplayExtensionZoneProps, DisplayField, type DisplayFieldProps, DisplaySection, type DisplaySectionField, type DisplaySectionProps, type EditAttributeAttribute, EditAttributeForm, type EditAttributeFormProps, EmailCell, EmailForm, EmailHeader, EmailSchema, type EntryRenderer, ErrorBoundary, type ExtendableTable, ExtensionProvider, type ExtensionProviderProps, ExtensionRegistry, type ExtractableOffer, type ExtractableOffers, type FieldDiff, FilePreview, type FileType, FileUpload, type FileUploadProps, type Filter, FilterGroup, Form, FormExtensionZone, type FormExtensionZoneProps, GeneralSectionSkeleton, HandleInput, HeadingSkeleton, IconAvatar, IconButtonSkeleton, ImageAvatar, type ImageRef, IncludesTaxTooltip, InfiniteList, JsonViewSection, JsonViewSectionSkeleton, KeyboundForm, LayoutComposer, type LayoutComposerProps, LayoutEntry, type LayoutEntryProps, type LayoutModule, LinkButton, ListBadge, ListSummary, Listicle, type ListicleProps, LocalizedTablePagination, type MediaDiff, MetadataForm, MetadataSection, MoneyAmountCell, NameCell, NameHeader, type NavGroup, type NavGroupItem, type NavItemGroup, type NavigationModule, NoRecords, type NoRecordsProps, NoResults, type NoResultsProps, type OnboardingStep, type OnboardingStepDefault, OrderBy, PercentageInput, PermissionAction, type PermissionActionProps, PermissionGuard, type PermissionGuardProps, type PermissionedCommand, PermissionsContext, PermissionsProvider, type PermissionsProviderProps, PlaceholderCell, type PreferenceModule, PriceListDateStatus, type PriceListGridGroupRow, type PriceListGridOfferRow, type PriceListGridRow, PriceListStatus, PriceListType, type ProductAttributeBatchPayload, ProductAttributeSection, type ProductAttributeSectionProps, type ProductChangeAttribute, ProductChangePanel, type ProductChangePanelProps, type ProductChangeProduct, type ProductChangeResolvers, type ProductChangeVariant, type ProductChangeView, ProgressBar, ProvinceSelect, Query, REFERENCE_FIELDS, RICH_TEXT_ALLOWED_ATTRIBUTES, RICH_TEXT_ALLOWED_TAGS, type RawEntry, type ReferenceField, type RenderDefaultProps, type ResolvedAttribute, type ResolvedDisplays, type ResolvedFormField, RichText, RichTextEditor, type RichTextEditorProps, RouteDrawer, RouteFocusModal, RoutePermissionGuard, SIDEBAR_MENU_CONTENT, SIDEBAR_RAIL_FADE, SectionNoAccess, SectionRow, type SectionRowProps, type SectionWidget, type SectionWidgetMap, SegmentedControl, type SegmentedControlOption, SidebarContext, type SidebarContextValue, SidebarLink, type SidebarLinkProps, SidebarProvider, type SidebarState, SingleColumnLayoutComponent, SingleColumnPage, SingleColumnPageSkeleton, Skeleton, SortableList, SortableTree, StackedDrawer, StackedFocusModal, type StaticCountry, StatusCell, SwitchBox, type TQueryKey, type TabDefinition, TabbedForm, TableFooterSkeleton, TableSectionSkeleton, TableSkeleton, TextCell, TextHeader, TextSkeleton, Thumbnail, TransferOwnershipSchema, TwoColumnLayoutComponent, TwoColumnPage, TwoColumnPageSkeleton, type UseExtendableFormProps, type UseExtendableTableProps, type UseQueryOptionsWrapper, type VariantGroup, VisuallyHidden, type Widget, type WidgetModule, type WidgetPlacement, type WidgetTab, type WidgetTabs, WidgetZone, type WidgetZoneProps, type ZoneWidgets, _DataTable, applyActionPermissions, applyNavGroups, applyNavOverrides, applyReplacements, buildAdditionalDataDefaults, buildAdditionalDataSchema, buildCoreEntries, buildDisplayEntries, buildOfferGridData, buildProductChangeView, buildWidgetEntries, countries, createDataGridHelper, createDataGridPriceColumns, createFormHelper, createWithPermission, currencies, detailPageDefaultEntries, extractPricesFromOffers, extractReferenceIds, extractSectionElements, filterCommandsByPermission, formatFieldValue, genericForwardRef, getCountryByIso2, getCurrencySymbol, getDecimalDigits, getExtensionRegistry, getFormattedAddress, getFormattedCountry, getLinkQuery, getLocaleAmount, getNativeSymbol, getPriceListStatus, getStylizedAmount, groupNavItems, humanizeFieldName, isAmountLessThenRoundingError, isForbidden, isHtml, isImageList, isOrderActionable, isOrderAwaitingAction, isPermitted, isPriceListGroupRow, isProductRow, isReferenceField, isSameAddress, linkFields, mergeLayoutPreferences, mergeListFilters, navOverridesFromPreferences, permissionMapAllows, plainTextToHtml, productChangeViewHasContent, queryClient, queryKeysFactory, resolveRouteOverrides, richTextContentClasses, sanitizeRichText, toPermissionList, useActionLocks, useCan, useCollapsedSidebar, useCombinedRefs, useCommandHistory, useDataTable, useDate, useDisplayFieldOverride, useDocumentDirection, useExpandedSidebar, useExtendableForm, useExtendableTable, useExtension, useExtensionActivity, useLinkQuery, usePermissionGate, usePermissions, usePermittedCommands, useQueryParams, useResourcePermissions, useRouteModal, useSidebar, useSidebarMenuPlacement, useStackedModal, useTabManagement, useTabbedForm, useWidgetTabs, withLinkFields };
2571
+ export { type Action, type ActionGroup, ActionMenu, type AdditionalDataScope, AddressForm, AddressSchema, type AttributeChange, type AttributeChangeKind, AttributeValueInput, BadgeListSummary, CORE_ENTRY_PREFIX, CORE_LAYOUTS, ChipGroup, ChipInput, CodeCell, CodeHeader, Combobox, type Command, ConditionalTooltip, ConfirmPrompt, type ConfirmPromptProps, type CoreNavItem, CountrySelect, CreatedAtCell, CreatedAtHeader, type CurrencyInfo, type CustomFieldsModule, CustomerInfo, DataGrid, DataTable, DateCell, DateHeader, DateRangeDisplay, DeprecatedPercentageInput, type DetailPageDefaultsOptions, type DisplayEntry, DisplayExtensionZone, type DisplayExtensionZoneProps, DisplayField, type DisplayFieldProps, DisplaySection, type DisplaySectionField, type DisplaySectionProps, type EditAttributeAttribute, EditAttributeForm, type EditAttributeFormProps, EmailCell, EmailForm, EmailHeader, EmailSchema, type EntryRenderer, ErrorBoundary, ExtendableFormField, type ExtendableFormFieldProps, type ExtendableTable, type ExtensionGridColumnArgs, ExtensionProvider, type ExtensionProviderProps, ExtensionRegistry, type ExtractableOffer, type ExtractableOffers, type FieldDiff, FilePreview, type FileType, FileUpload, type FileUploadProps, type Filter, FilterGroup, Form, FormExtensionZone, type FormExtensionZoneProps, type FormFieldInputType, type FormFieldOverride, GeneralSectionSkeleton, type GridFieldName, HandleInput, HeadingSkeleton, IconAvatar, IconButtonSkeleton, ImageAvatar, type ImageRef, IncludesTaxTooltip, InfiniteList, JsonViewSection, JsonViewSectionSkeleton, KeyboundForm, LayoutComposer, type LayoutComposerProps, LayoutEntry, type LayoutEntryProps, type LayoutModule, LinkButton, ListBadge, ListSummary, Listicle, type ListicleProps, LocalizedTablePagination, type MediaDiff, MetadataForm, MetadataSection, MoneyAmountCell, NameCell, NameHeader, type NavGroup, type NavGroupItem, type NavItemGroup, type NavigationModule, NoRecords, type NoRecordsProps, NoResults, type NoResultsProps, type OnboardingStep, type OnboardingStepDefault, OrderBy, PercentageInput, PermissionAction, type PermissionActionProps, PermissionGuard, type PermissionGuardProps, type PermissionedCommand, PermissionsContext, PermissionsProvider, type PermissionsProviderProps, PlaceholderCell, type PreferenceModule, PriceListDateStatus, type PriceListGridGroupRow, type PriceListGridOfferRow, type PriceListGridRow, PriceListStatus, PriceListType, type ProductAttributeBatchPayload, ProductAttributeSection, type ProductAttributeSectionProps, type ProductChangeAttribute, ProductChangePanel, type ProductChangePanelProps, type ProductChangeProduct, type ProductChangeResolvers, type ProductChangeVariant, type ProductChangeView, ProgressBar, ProvinceSelect, Query, REFERENCE_FIELDS, RICH_TEXT_ALLOWED_ATTRIBUTES, RICH_TEXT_ALLOWED_TAGS, type RawEntry, type ReferenceField, type RenderDefaultProps, type ResolvedAttribute, type ResolvedDisplays, type ResolvedFormField, RichText, RichTextEditor, type RichTextEditorProps, RouteDrawer, RouteFocusModal, RoutePermissionGuard, SIDEBAR_MENU_CONTENT, SIDEBAR_RAIL_FADE, SectionNoAccess, SectionRow, type SectionRowProps, type SectionWidget, type SectionWidgetMap, SegmentedControl, type SegmentedControlOption, SidebarContext, type SidebarContextValue, SidebarLink, type SidebarLinkProps, SidebarProvider, type SidebarState, SingleColumnLayoutComponent, SingleColumnPage, SingleColumnPageSkeleton, Skeleton, SortableList, SortableTree, StackedDrawer, StackedFocusModal, type StaticCountry, StatusCell, SwitchBox, type TQueryKey, type TabDefinition, TabbedForm, TableFooterSkeleton, TableSectionSkeleton, TableSkeleton, TextCell, TextHeader, TextSkeleton, Thumbnail, TransferOwnershipSchema, TwoColumnLayoutComponent, TwoColumnPage, TwoColumnPageSkeleton, type UseExtendableFormProps, type UseExtendableGridProps, type UseExtendableTableProps, type UseQueryOptionsWrapper, type VariantGroup, VisuallyHidden, type Widget, type WidgetModule, type WidgetPlacement, type WidgetTab, type WidgetTabs, WidgetZone, type WidgetZoneProps, type ZoneWidgets, _DataTable, applyActionPermissions, applyNavGroups, applyNavOverrides, applyReplacements, buildAdditionalDataDefaults, buildAdditionalDataSchema, buildCoreEntries, buildDisplayEntries, buildOfferGridData, buildProductChangeView, buildScopedAdditionalData, buildWidgetEntries, countries, createDataGridHelper, createDataGridPriceColumns, createFormHelper, createWithPermission, currencies, detailPageDefaultEntries, extractPricesFromOffers, extractReferenceIds, extractSectionElements, filterCommandsByPermission, formatFieldValue, genericForwardRef, getCountryByIso2, getCurrencySymbol, getDecimalDigits, getExtensionRegistry, getFormattedAddress, getFormattedCountry, getLinkQuery, getLocaleAmount, getNativeSymbol, getPriceListStatus, getStylizedAmount, groupNavItems, humanizeFieldName, isAmountLessThenRoundingError, isForbidden, isHtml, isImageList, isOrderActionable, isOrderAwaitingAction, isPermitted, isPriceListGroupRow, isProductRow, isReferenceField, isSameAddress, linkFields, mergeLayoutPreferences, mergeListFilters, navOverridesFromPreferences, permissionMapAllows, plainTextToHtml, productChangeViewHasContent, queryClient, queryKeysFactory, refineAdditionalData, resolveFormFieldType, resolveRouteOverrides, richTextContentClasses, sanitizeRichText, toPermissionList, useActionLocks, useCan, useCollapsedSidebar, useCombinedRefs, useCommandHistory, useDataTable, useDate, useDisplayFieldOverride, useDocumentDirection, useExpandedSidebar, useExtendableForm, useExtendableGrid, useExtendableTable, useExtension, useExtensionActivity, useLinkQuery, usePermissionGate, usePermissions, usePermittedCommands, useQueryParams, useResourcePermissions, useRouteModal, useSidebar, useSidebarMenuPlacement, useStackedModal, useTabManagement, useTabbedForm, useWidgetTabs, withLinkFields };
package/dist/index.js CHANGED
@@ -26223,13 +26223,32 @@ var ExtensionRegistry = class {
26223
26223
  }
26224
26224
  return [...byName.values()];
26225
26225
  }
26226
- /** Custom form fields for a model's form zone (and optional tab). */
26227
- getFormFields(model, zone, tab) {
26226
+ // An entry without a tab belongs to every tab of its zone, unless the host
26227
+ // asks for `exactTab` (a data grid tab only takes fields aimed at it).
26228
+ formEntriesFor(model, zone, tab, exactTab = false) {
26228
26229
  return this.resolveFormFields(model).filter((entry) => {
26229
26230
  if (entry.zone !== zone) return false;
26230
- if (!entry.tab) return true;
26231
+ if (!entry.tab) return !exactTab;
26231
26232
  return !!tab && entry.tab === tab;
26232
- }).map(({ name, field }) => ({ name, field }));
26233
+ });
26234
+ }
26235
+ /**
26236
+ * Custom form fields added to a model's form zone (and optional tab). Entries
26237
+ * keyed by one of the host's `builtInFieldIds` are overrides, not additions,
26238
+ * and are read through `getFormFieldOverride` instead.
26239
+ */
26240
+ getFormFields(model, zone, tab, builtInFieldIds = [], exactTab = false) {
26241
+ const builtIns = new Set(builtInFieldIds);
26242
+ return this.formEntriesFor(model, zone, tab, exactTab).flatMap(
26243
+ ({ name, field }) => field && !builtIns.has(name) ? [{ name, field }] : []
26244
+ );
26245
+ }
26246
+ /** Replacement (or removal, `field: null`) of a built-in form field. */
26247
+ getFormFieldOverride(model, zone, id, tab, exactTab = false) {
26248
+ const entry = this.formEntriesFor(model, zone, tab, exactTab).find(
26249
+ (e) => e.name === id
26250
+ );
26251
+ return entry ? { overridden: true, field: entry.field } : { overridden: false, field: null };
26233
26252
  }
26234
26253
  /**
26235
26254
  * Resolves the onboarding wizard steps: built-ins merged with every
@@ -26280,7 +26299,9 @@ var ExtensionRegistry = class {
26280
26299
  }
26281
26300
  /** All custom form fields for a model, keyed for schema/default building. */
26282
26301
  getAllFormFields(model) {
26283
- return this.resolveFormFields(model).map(({ name, field }) => ({ name, field }));
26302
+ return this.resolveFormFields(model).flatMap(
26303
+ ({ name, field }) => field ? [{ name, field }] : []
26304
+ );
26284
26305
  }
26285
26306
  /** Section display contributions (field add/replace/remove + actions). */
26286
26307
  getDisplays(model, zone) {
@@ -26296,16 +26317,21 @@ var ExtensionRegistry = class {
26296
26317
  actions.sort((a, b) => (a.rank ?? 0) - (b.rank ?? 0));
26297
26318
  return { fields: [...fields.values()], actions };
26298
26319
  }
26299
- /** Merged list-table extension for a model. */
26300
- getListExtension(model) {
26320
+ /**
26321
+ * Merged table extension for a model. `zone` picks the table: `"list"` is the
26322
+ * model's list page, and also matches `list` blocks that omit a zone.
26323
+ */
26324
+ getListExtension(model, zone = "list") {
26301
26325
  const columns = /* @__PURE__ */ new Map();
26302
26326
  const filters = /* @__PURE__ */ new Map();
26303
26327
  const bulkActions = [];
26304
26328
  const columnVisibility = {};
26305
26329
  let columnOrder = [];
26306
- for (const config3 of this.configsFor(model)) {
26307
- const list = config3.list;
26308
- if (!list) continue;
26330
+ const lists = this.configsFor(model).flatMap(
26331
+ (config3) => config3.list ? [config3.list].flat() : []
26332
+ );
26333
+ for (const list of lists) {
26334
+ if ((list.zone ?? "list") !== zone) continue;
26309
26335
  for (const column of list.columns ?? []) columns.set(column.id, column);
26310
26336
  for (const filter of list.filters ?? []) filters.set(filter.key, filter);
26311
26337
  if (list.bulkActions) bulkActions.push(...list.bulkActions);
@@ -26590,8 +26616,24 @@ function groupNavItems(items, groups = []) {
26590
26616
  }
26591
26617
 
26592
26618
  // src/extensions/form-extension-zone.tsx
26593
- import { Input as Input10, Switch as Switch2, Textarea as Textarea4 } from "@medusajs/ui";
26594
- import { jsx as jsx82, jsxs as jsxs58 } from "react/jsx-runtime";
26619
+ import { Input as Input10, Select as Select5, Switch as Switch2, Textarea as Textarea4 } from "@medusajs/ui";
26620
+
26621
+ // src/extensions/custom-fields-form.ts
26622
+ import { z as z3 } from "zod";
26623
+ function createFormHelper() {
26624
+ return {
26625
+ define: (field) => field,
26626
+ string: () => z3.string(),
26627
+ number: () => z3.number(),
26628
+ boolean: () => z3.boolean(),
26629
+ date: () => z3.date(),
26630
+ array: z3.array,
26631
+ object: z3.object,
26632
+ null: () => z3.null(),
26633
+ nullable: z3.nullable,
26634
+ coerce: z3.coerce
26635
+ };
26636
+ }
26595
26637
  var ZOD_WRAPPER_TYPES = /* @__PURE__ */ new Set([
26596
26638
  "optional",
26597
26639
  "nullable",
@@ -26601,7 +26643,8 @@ var ZOD_WRAPPER_TYPES = /* @__PURE__ */ new Set([
26601
26643
  "readonly",
26602
26644
  "catch"
26603
26645
  ]);
26604
- function zodType(field) {
26646
+ function resolveFormFieldType(field) {
26647
+ if (field.type) return field.type;
26605
26648
  let def = field.validation?.def;
26606
26649
  while (def && ZOD_WRAPPER_TYPES.has(def.type ?? "")) {
26607
26650
  def = def.innerType?.def;
@@ -26609,29 +26652,123 @@ function zodType(field) {
26609
26652
  switch (def?.type) {
26610
26653
  case "boolean":
26611
26654
  case "number":
26612
- case "string":
26613
26655
  return def.type;
26656
+ case "string":
26657
+ return "text";
26614
26658
  default:
26615
26659
  return "textarea";
26616
26660
  }
26617
26661
  }
26618
- var ExtensionField = ({ name, field, control }) => {
26619
- const type = zodType(field);
26662
+ function buildAdditionalDataSchema(registry, model, zone, tab, builtInFieldIds) {
26663
+ const shape = {};
26664
+ const fields = zone ? registry.getFormFields(model, zone, tab, builtInFieldIds) : registry.getAllFormFields(model);
26665
+ for (const { name, field } of fields) {
26666
+ shape[name] = field.validation;
26667
+ }
26668
+ return z3.object(shape);
26669
+ }
26670
+ function buildAdditionalDataDefaults(registry, model, data, zone, tab, builtInFieldIds) {
26671
+ const defaults = {};
26672
+ const fields = zone ? registry.getFormFields(model, zone, tab, builtInFieldIds) : registry.getAllFormFields(model);
26673
+ for (const { name, field } of fields) {
26674
+ if (typeof field.defaultValue === "function") {
26675
+ defaults[name] = field.defaultValue(data);
26676
+ } else if (field.defaultValue !== void 0) {
26677
+ defaults[name] = field.defaultValue;
26678
+ }
26679
+ }
26680
+ return defaults;
26681
+ }
26682
+ function buildScopedAdditionalData(registry, { model, zone, tabs, exactTab, builtInFieldIds }, data) {
26683
+ const fields = /* @__PURE__ */ new Map();
26684
+ for (const tab of tabs?.length ? tabs : [void 0]) {
26685
+ for (const { name, field } of registry.getFormFields(
26686
+ model,
26687
+ zone,
26688
+ tab,
26689
+ builtInFieldIds,
26690
+ exactTab
26691
+ )) {
26692
+ fields.set(name, field);
26693
+ }
26694
+ }
26695
+ const shape = {};
26696
+ const defaults = {};
26697
+ for (const [name, field] of fields) {
26698
+ shape[name] = field.validation;
26699
+ if (typeof field.defaultValue === "function") {
26700
+ defaults[name] = field.defaultValue(data);
26701
+ } else if (field.defaultValue !== void 0) {
26702
+ defaults[name] = field.defaultValue;
26703
+ }
26704
+ }
26705
+ return { schema: z3.object(shape), defaults };
26706
+ }
26707
+ function refineAdditionalData(schema, {
26708
+ additionalData,
26709
+ rows
26710
+ }) {
26711
+ const hasFields = (s) => !!s && Object.keys(s.shape).length > 0;
26712
+ if (!hasFields(additionalData) && !hasFields(rows?.schema)) return schema;
26713
+ return schema.superRefine((value, ctx) => {
26714
+ const report = (target, data, prefix) => {
26715
+ const result = target.safeParse(data ?? {});
26716
+ if (result.success) return;
26717
+ for (const issue of result.error.issues) {
26718
+ ctx.addIssue({
26719
+ code: "custom",
26720
+ message: issue.message,
26721
+ path: [...prefix, ...issue.path.map((p) => p)]
26722
+ });
26723
+ }
26724
+ };
26725
+ const values = value;
26726
+ if (additionalData && hasFields(additionalData)) {
26727
+ report(additionalData, values.additional_data, ["additional_data"]);
26728
+ }
26729
+ if (rows && hasFields(rows.schema)) {
26730
+ const list = values[rows.path] ?? [];
26731
+ list.forEach((row, index) => {
26732
+ if (rows.include && !rows.include(row)) return;
26733
+ report(rows.schema, row.additional_data, [
26734
+ rows.path,
26735
+ index,
26736
+ "additional_data"
26737
+ ]);
26738
+ });
26739
+ }
26740
+ });
26741
+ }
26742
+
26743
+ // src/extensions/form-extension-zone.tsx
26744
+ import { Fragment as Fragment9, jsx as jsx82, jsxs as jsxs58 } from "react/jsx-runtime";
26745
+ var ExtensionField = ({ name, path, field, control, data }) => {
26746
+ const type = resolveFormFieldType(field);
26620
26747
  const Component = field.component;
26621
26748
  return /* @__PURE__ */ jsx82(
26622
26749
  Form.Field,
26623
26750
  {
26624
26751
  control,
26625
- name: `additional_data.${name}`,
26752
+ name: path,
26626
26753
  render: ({ field: rhf }) => /* @__PURE__ */ jsxs58(Form.Item, { children: [
26627
26754
  /* @__PURE__ */ jsx82(Form.Label, { children: field.label ?? name }),
26628
26755
  field.description && /* @__PURE__ */ jsx82(Form.Hint, { children: field.description }),
26629
- /* @__PURE__ */ jsx82(Form.Control, { children: Component ? /* @__PURE__ */ jsx82(Component, {}) : type === "boolean" ? /* @__PURE__ */ jsx82(
26756
+ /* @__PURE__ */ jsx82(Form.Control, { children: Component ? /* @__PURE__ */ jsx82(Component, { field: rhf, data }) : type === "boolean" ? /* @__PURE__ */ jsx82(
26630
26757
  Switch2,
26631
26758
  {
26632
26759
  checked: !!rhf.value,
26633
26760
  onCheckedChange: rhf.onChange
26634
26761
  }
26762
+ ) : type === "select" ? /* @__PURE__ */ jsxs58(
26763
+ Select5,
26764
+ {
26765
+ value: rhf.value ?? "",
26766
+ onValueChange: rhf.onChange,
26767
+ children: [
26768
+ /* @__PURE__ */ jsx82(Select5.Trigger, { ref: rhf.ref, children: /* @__PURE__ */ jsx82(Select5.Value, { placeholder: field.placeholder }) }),
26769
+ /* @__PURE__ */ jsx82(Select5.Content, { children: (field.options ?? []).map((option) => /* @__PURE__ */ jsx82(Select5.Item, { value: option.value, children: option.label }, option.value)) })
26770
+ ]
26771
+ }
26635
26772
  ) : type === "number" ? /* @__PURE__ */ jsx82(
26636
26773
  Input10,
26637
26774
  {
@@ -26640,7 +26777,7 @@ var ExtensionField = ({ name, field, control }) => {
26640
26777
  ...rhf,
26641
26778
  value: rhf.value ?? ""
26642
26779
  }
26643
- ) : type === "string" ? /* @__PURE__ */ jsx82(
26780
+ ) : type === "text" ? /* @__PURE__ */ jsx82(
26644
26781
  Input10,
26645
26782
  {
26646
26783
  placeholder: field.placeholder,
@@ -26660,30 +26797,68 @@ var ExtensionField = ({ name, field, control }) => {
26660
26797
  }
26661
26798
  );
26662
26799
  };
26800
+ var widen = (control) => control;
26663
26801
  var FormExtensionZone = ({
26664
26802
  model,
26665
26803
  zone,
26666
26804
  tab,
26667
26805
  control,
26668
- data
26806
+ data,
26807
+ builtInFieldIds,
26808
+ exactTab
26669
26809
  }) => {
26670
- const fields = useExtension().getFormFields(model, zone, tab);
26810
+ const fields = useExtension().getFormFields(
26811
+ model,
26812
+ zone,
26813
+ tab,
26814
+ builtInFieldIds,
26815
+ exactTab
26816
+ );
26671
26817
  if (fields.length === 0) return null;
26672
26818
  return /* @__PURE__ */ jsx82("div", { className: "flex flex-col gap-y-4", children: fields.map(({ name, field }) => /* @__PURE__ */ jsx82(
26673
26819
  ExtensionField,
26674
26820
  {
26675
26821
  name,
26822
+ path: `additional_data.${name}`,
26676
26823
  field,
26677
- control,
26824
+ control: widen(control),
26678
26825
  data
26679
26826
  },
26680
26827
  name
26681
26828
  )) });
26682
26829
  };
26830
+ var ExtendableFormField = ({
26831
+ model,
26832
+ zone,
26833
+ tab,
26834
+ id,
26835
+ control,
26836
+ data,
26837
+ children
26838
+ }) => {
26839
+ const { overridden, field } = useExtension().getFormFieldOverride(
26840
+ model,
26841
+ zone,
26842
+ id,
26843
+ tab
26844
+ );
26845
+ if (!overridden) return /* @__PURE__ */ jsx82(Fragment9, { children });
26846
+ if (!field) return null;
26847
+ return /* @__PURE__ */ jsx82(
26848
+ ExtensionField,
26849
+ {
26850
+ name: id,
26851
+ path: id,
26852
+ field,
26853
+ control: widen(control),
26854
+ data
26855
+ }
26856
+ );
26857
+ };
26683
26858
 
26684
26859
  // src/extensions/display-extension-zone.tsx
26685
- import { Fragment as Fragment9 } from "react";
26686
- import { Fragment as Fragment10, jsx as jsx83, jsxs as jsxs59 } from "react/jsx-runtime";
26860
+ import { Fragment as Fragment10 } from "react";
26861
+ import { Fragment as Fragment11, jsx as jsx83, jsxs as jsxs59 } from "react/jsx-runtime";
26687
26862
  var DisplayExtensionZone = ({
26688
26863
  model,
26689
26864
  zone,
@@ -26694,7 +26869,7 @@ var DisplayExtensionZone = ({
26694
26869
  const builtIn = new Set(builtInFieldIds);
26695
26870
  const added = fields.filter((f) => f.component && !builtIn.has(f.id));
26696
26871
  if (added.length === 0 && actions.length === 0) return null;
26697
- return /* @__PURE__ */ jsxs59(Fragment10, { children: [
26872
+ return /* @__PURE__ */ jsxs59(Fragment11, { children: [
26698
26873
  added.map(({ id, component: Component }) => {
26699
26874
  const C = Component;
26700
26875
  return /* @__PURE__ */ jsx83(C, { data }, id);
@@ -26716,14 +26891,14 @@ var DisplayField = ({
26716
26891
  if (overridden) {
26717
26892
  return Component ? /* @__PURE__ */ jsx83(Component, { data }) : null;
26718
26893
  }
26719
- return /* @__PURE__ */ jsx83(Fragment9, { children });
26894
+ return /* @__PURE__ */ jsx83(Fragment10, { children });
26720
26895
  };
26721
26896
  var DisplaySection = ({
26722
26897
  model,
26723
26898
  zone,
26724
26899
  data,
26725
26900
  fields
26726
- }) => /* @__PURE__ */ jsxs59(Fragment10, { children: [
26901
+ }) => /* @__PURE__ */ jsxs59(Fragment11, { children: [
26727
26902
  fields.map(({ id, render }) => /* @__PURE__ */ jsx83(DisplayField, { model, zone, id, data, children: render }, id)),
26728
26903
  /* @__PURE__ */ jsx83(
26729
26904
  DisplayExtensionZone,
@@ -26754,9 +26929,10 @@ function columnId(col) {
26754
26929
  }
26755
26930
  function useExtendableTable({
26756
26931
  model,
26932
+ zone = "list",
26757
26933
  columns: baseColumns
26758
26934
  }) {
26759
- const ext = useExtension().getListExtension(model);
26935
+ const ext = useExtension().getListExtension(model, zone);
26760
26936
  return useMemo18(() => {
26761
26937
  const helper = createColumnHelper2();
26762
26938
  const build = (c) => helper.display({
@@ -26798,6 +26974,88 @@ function useExtendableTable({
26798
26974
  }, [baseColumns, ext]);
26799
26975
  }
26800
26976
 
26977
+ // src/extensions/use-extendable-grid.ts
26978
+ import { useMemo as useMemo19 } from "react";
26979
+ var columnId2 = (col) => col.id;
26980
+ var baseFieldName = (col) => col.meta?.field ?? (() => null);
26981
+ function applyGridExtension(extension, {
26982
+ model,
26983
+ zone,
26984
+ tab,
26985
+ columns: baseColumns,
26986
+ lockedColumnIds,
26987
+ allowAdd = true,
26988
+ getRowPath,
26989
+ createColumn
26990
+ }) {
26991
+ const locked = new Set(lockedColumnIds);
26992
+ const builtInIds = baseColumns.flatMap((c) => columnId2(c) ?? []);
26993
+ const columns = baseColumns.flatMap((col) => {
26994
+ const id = columnId2(col);
26995
+ if (!id || locked.has(id)) return [col];
26996
+ const { overridden, field } = extension.getFormFieldOverride(
26997
+ model,
26998
+ zone,
26999
+ id,
27000
+ tab,
27001
+ true
27002
+ );
27003
+ if (!overridden) return [col];
27004
+ if (!field) return [];
27005
+ return [createColumn({ id, field, getFieldName: baseFieldName(col) })];
27006
+ });
27007
+ const added = allowAdd ? extension.getFormFields(model, zone, tab, builtInIds, true) : [];
27008
+ for (const { name, field } of added) {
27009
+ columns.push(
27010
+ createColumn({
27011
+ id: name,
27012
+ field,
27013
+ getFieldName: (context) => {
27014
+ const path = getRowPath?.(context.row.original) ?? null;
27015
+ return path ? `${path}.additional_data.${name}` : null;
27016
+ }
27017
+ })
27018
+ );
27019
+ }
27020
+ return columns;
27021
+ }
27022
+ function useExtendableGrid(props) {
27023
+ const extension = useExtension();
27024
+ const {
27025
+ model,
27026
+ zone,
27027
+ tab,
27028
+ columns,
27029
+ lockedColumnIds,
27030
+ allowAdd,
27031
+ getRowPath,
27032
+ createColumn
27033
+ } = props;
27034
+ return useMemo19(
27035
+ () => applyGridExtension(extension, {
27036
+ model,
27037
+ zone,
27038
+ tab,
27039
+ columns,
27040
+ lockedColumnIds,
27041
+ allowAdd,
27042
+ getRowPath,
27043
+ createColumn
27044
+ }),
27045
+ [
27046
+ extension,
27047
+ model,
27048
+ zone,
27049
+ tab,
27050
+ columns,
27051
+ lockedColumnIds,
27052
+ allowAdd,
27053
+ getRowPath,
27054
+ createColumn
27055
+ ]
27056
+ );
27057
+ }
27058
+
26801
27059
  // src/extensions/list-filters.ts
26802
27060
  var isRemoval = (filter) => "remove" in filter && filter.remove === true;
26803
27061
  function mergeListFilters(base, extensions) {
@@ -26841,46 +27099,9 @@ var useLinkQuery = (model, base) => {
26841
27099
  return { fields: base ? withLinkFields(base, links) : linkFields(links) };
26842
27100
  };
26843
27101
 
26844
- // src/extensions/custom-fields-form.ts
26845
- import { z as z3 } from "zod";
26846
- function createFormHelper() {
26847
- return {
26848
- define: (field) => field,
26849
- string: () => z3.string(),
26850
- number: () => z3.number(),
26851
- boolean: () => z3.boolean(),
26852
- date: () => z3.date(),
26853
- array: z3.array,
26854
- object: z3.object,
26855
- null: () => z3.null(),
26856
- nullable: z3.nullable,
26857
- coerce: z3.coerce
26858
- };
26859
- }
26860
- function buildAdditionalDataSchema(registry, model, zone, tab) {
26861
- const shape = {};
26862
- const fields = zone ? registry.getFormFields(model, zone, tab) : registry.getAllFormFields(model);
26863
- for (const { name, field } of fields) {
26864
- shape[name] = field.validation;
26865
- }
26866
- return z3.object(shape);
26867
- }
26868
- function buildAdditionalDataDefaults(registry, model, data, zone, tab) {
26869
- const defaults = {};
26870
- const fields = zone ? registry.getFormFields(model, zone, tab) : registry.getAllFormFields(model);
26871
- for (const { name, field } of fields) {
26872
- if (typeof field.defaultValue === "function") {
26873
- defaults[name] = field.defaultValue(data);
26874
- } else if (field.defaultValue !== void 0) {
26875
- defaults[name] = field.defaultValue;
26876
- }
26877
- }
26878
- return defaults;
26879
- }
26880
-
26881
27102
  // src/extensions/use-extendable-form.ts
26882
27103
  import { zodResolver as zodResolver3 } from "@hookform/resolvers/zod";
26883
- import { useMemo as useMemo19 } from "react";
27104
+ import { useMemo as useMemo20 } from "react";
26884
27105
  import { useForm as useForm3 } from "react-hook-form";
26885
27106
  import { z as z4 } from "zod";
26886
27107
  var useExtendableForm = ({
@@ -26890,14 +27111,21 @@ var useExtendableForm = ({
26890
27111
  data,
26891
27112
  zone,
26892
27113
  tab,
27114
+ builtInFieldIds,
26893
27115
  ...props
26894
27116
  }) => {
26895
27117
  const extension = useExtension();
26896
- const schema = useMemo19(() => {
26897
- const additionalData = buildAdditionalDataSchema(extension, model, zone, tab).partial().optional();
27118
+ const schema = useMemo20(() => {
27119
+ const additionalData = buildAdditionalDataSchema(
27120
+ extension,
27121
+ model,
27122
+ zone,
27123
+ tab,
27124
+ builtInFieldIds
27125
+ ).partial().optional();
26898
27126
  return typeof baseSchema.extend === "function" ? baseSchema.extend({ additional_data: additionalData }) : baseSchema.and(z4.object({ additional_data: additionalData }));
26899
- }, [baseSchema, extension, model, zone, tab]);
26900
- const defaultValues = useMemo19(
27127
+ }, [baseSchema, extension, model, zone, tab, builtInFieldIds]);
27128
+ const defaultValues = useMemo20(
26901
27129
  () => ({
26902
27130
  ...baseDefaultValues,
26903
27131
  additional_data: buildAdditionalDataDefaults(
@@ -26905,10 +27133,11 @@ var useExtendableForm = ({
26905
27133
  model,
26906
27134
  data,
26907
27135
  zone,
26908
- tab
27136
+ tab,
27137
+ builtInFieldIds
26909
27138
  )
26910
27139
  }),
26911
- [baseDefaultValues, extension, model, data, zone, tab]
27140
+ [baseDefaultValues, extension, model, data, zone, tab, builtInFieldIds]
26912
27141
  );
26913
27142
  return useForm3({
26914
27143
  ...props,
@@ -26918,7 +27147,7 @@ var useExtendableForm = ({
26918
27147
  };
26919
27148
 
26920
27149
  // src/extensions/action-locks.ts
26921
- import { useCallback as useCallback22, useMemo as useMemo20 } from "react";
27150
+ import { useCallback as useCallback22, useMemo as useMemo21 } from "react";
26922
27151
  var useActionLocks = (model, entity) => {
26923
27152
  const registry = useExtension();
26924
27153
  return useCallback22(
@@ -26928,7 +27157,7 @@ var useActionLocks = (model, entity) => {
26928
27157
  };
26929
27158
  var useExtensionActivity = (model, entity) => {
26930
27159
  const registry = useExtension();
26931
- return useMemo20(
27160
+ return useMemo21(
26932
27161
  () => registry.getActivity(model, entity),
26933
27162
  [registry, model, entity]
26934
27163
  );
@@ -27166,17 +27395,17 @@ import {
27166
27395
  Children as Children3,
27167
27396
  createContext as createContext9,
27168
27397
  useContext as useContext13,
27169
- useMemo as useMemo22
27398
+ useMemo as useMemo23
27170
27399
  } from "react";
27171
27400
  import { useTranslation as useTranslation36 } from "react-i18next";
27172
27401
 
27173
27402
  // src/components/tabbed-form/use-tab-management.ts
27174
- import { useCallback as useCallback23, useEffect as useEffect20, useMemo as useMemo21, useState as useState31 } from "react";
27403
+ import { useCallback as useCallback23, useEffect as useEffect20, useMemo as useMemo22, useState as useState31 } from "react";
27175
27404
  var useTabManagement = ({
27176
27405
  tabs,
27177
27406
  form
27178
27407
  }) => {
27179
- const visibleTabs = useMemo21(
27408
+ const visibleTabs = useMemo22(
27180
27409
  () => tabs.filter((t2) => !t2.isVisible || t2.isVisible(form)),
27181
27410
  [tabs, form]
27182
27411
  );
@@ -27285,11 +27514,11 @@ function Root6({
27285
27514
  transformTabs
27286
27515
  }) {
27287
27516
  const { t: t2 } = useTranslation36();
27288
- const { tabs: rawTabs, elements } = useMemo22(
27517
+ const { tabs: rawTabs, elements } = useMemo23(
27289
27518
  () => collectTabs(children),
27290
27519
  [children]
27291
27520
  );
27292
- const tabs = useMemo22(
27521
+ const tabs = useMemo23(
27293
27522
  () => transformTabs ? transformTabs(rawTabs) : rawTabs,
27294
27523
  [transformTabs, rawTabs]
27295
27524
  );
@@ -27420,7 +27649,7 @@ import { memo } from "react";
27420
27649
  // src/components/table/data-table/data-table-filter/data-table-filter.tsx
27421
27650
  import { Button as Button13, clx as clx48 } from "@medusajs/ui";
27422
27651
  import { Popover as RadixPopover8 } from "radix-ui";
27423
- import { useCallback as useCallback26, useEffect as useEffect23, useMemo as useMemo24, useRef as useRef18, useState as useState36 } from "react";
27652
+ import { useCallback as useCallback26, useEffect as useEffect23, useMemo as useMemo25, useRef as useRef18, useState as useState36 } from "react";
27424
27653
  import { useSearchParams as useSearchParams7 } from "react-router-dom";
27425
27654
  import { useTranslation as useTranslation41 } from "react-i18next";
27426
27655
 
@@ -27442,7 +27671,7 @@ import { EllipseMiniSolid as EllipseMiniSolid2 } from "@medusajs/icons";
27442
27671
  import { DatePicker, Text as Text20, clx as clx44 } from "@medusajs/ui";
27443
27672
  import isEqual from "lodash.isequal";
27444
27673
  import { Popover as RadixPopover4 } from "radix-ui";
27445
- import { useMemo as useMemo23, useState as useState32 } from "react";
27674
+ import { useMemo as useMemo24, useState as useState32 } from "react";
27446
27675
  import { t } from "i18next";
27447
27676
  import { useTranslation as useTranslation38 } from "react-i18next";
27448
27677
 
@@ -27800,7 +28029,7 @@ var today = /* @__PURE__ */ new Date();
27800
28029
  today.setHours(0, 0, 0, 0);
27801
28030
  var usePresets = () => {
27802
28031
  const { t: t2 } = useTranslation38();
27803
- return useMemo23(
28032
+ return useMemo24(
27804
28033
  () => [
27805
28034
  {
27806
28035
  label: t2("filters.date.today"),
@@ -28419,7 +28648,7 @@ var DataTableFilter2 = ({
28419
28648
  return /* @__PURE__ */ jsx92(
28420
28649
  DataTableFilterContext.Provider,
28421
28650
  {
28422
- value: useMemo24(
28651
+ value: useMemo25(
28423
28652
  () => ({
28424
28653
  removeFilter,
28425
28654
  removeAllFilters
@@ -28782,7 +29011,7 @@ import {
28782
29011
  flexRender as flexRender2
28783
29012
  } from "@tanstack/react-table";
28784
29013
  import {
28785
- Fragment as Fragment11,
29014
+ Fragment as Fragment12,
28786
29015
  useEffect as useEffect25,
28787
29016
  useRef as useRef19,
28788
29017
  useState as useState38,
@@ -28988,7 +29217,7 @@ var DataTableRoot = ({
28988
29217
  }) }),
28989
29218
  /* @__PURE__ */ jsx96(CommandBar.Seperator, {}),
28990
29219
  commands?.map((command, index) => {
28991
- return /* @__PURE__ */ jsxs70(Fragment11, { children: [
29220
+ return /* @__PURE__ */ jsxs70(Fragment12, { children: [
28992
29221
  /* @__PURE__ */ jsx96(
28993
29222
  CommandBar.Command,
28994
29223
  {
@@ -29382,7 +29611,7 @@ import {
29382
29611
  getPaginationRowModel,
29383
29612
  useReactTable as useReactTable2
29384
29613
  } from "@tanstack/react-table";
29385
- import { useEffect as useEffect26, useMemo as useMemo25, useState as useState39 } from "react";
29614
+ import { useEffect as useEffect26, useMemo as useMemo26, useState as useState39 } from "react";
29386
29615
  import { useSearchParams as useSearchParams9 } from "react-router-dom";
29387
29616
  var useDataTable2 = ({
29388
29617
  data = [],
@@ -29405,7 +29634,7 @@ var useDataTable2 = ({
29405
29634
  pageIndex: offset ? Math.ceil(Number(offset) / _pageSize) : 0,
29406
29635
  pageSize: _pageSize
29407
29636
  });
29408
- const pagination = useMemo25(
29637
+ const pagination = useMemo26(
29409
29638
  () => ({
29410
29639
  pageIndex,
29411
29640
  pageSize
@@ -29467,7 +29696,7 @@ var useDataTable2 = ({
29467
29696
  };
29468
29697
 
29469
29698
  // src/permissions/permissions-provider.tsx
29470
- import { useCallback as useCallback28, useMemo as useMemo26 } from "react";
29699
+ import { useCallback as useCallback28, useMemo as useMemo27 } from "react";
29471
29700
  import { jsx as jsx109 } from "react/jsx-runtime";
29472
29701
  var PermissionsProvider = ({
29473
29702
  permissions = null,
@@ -29497,7 +29726,7 @@ var PermissionsProvider = ({
29497
29726
  (list) => !permissions || list.every(hasPermission),
29498
29727
  [permissions, hasPermission]
29499
29728
  );
29500
- const value = useMemo26(
29729
+ const value = useMemo27(
29501
29730
  () => ({
29502
29731
  permissions,
29503
29732
  isLoading,
@@ -29523,7 +29752,7 @@ var usePermissions = () => {
29523
29752
  };
29524
29753
 
29525
29754
  // src/permissions/permission-guard.tsx
29526
- import { Fragment as Fragment12, jsx as jsx110 } from "react/jsx-runtime";
29755
+ import { Fragment as Fragment13, jsx as jsx110 } from "react/jsx-runtime";
29527
29756
  var PermissionGuard = ({
29528
29757
  children,
29529
29758
  permission,
@@ -29533,13 +29762,13 @@ var PermissionGuard = ({
29533
29762
  const { hasAnyPermission, hasAllPermissions } = usePermissions();
29534
29763
  const list = Array.isArray(permission) ? permission : [permission];
29535
29764
  const allowed = requireAll ? hasAllPermissions(list) : hasAnyPermission(list);
29536
- return /* @__PURE__ */ jsx110(Fragment12, { children: allowed ? children : fallback });
29765
+ return /* @__PURE__ */ jsx110(Fragment13, { children: allowed ? children : fallback });
29537
29766
  };
29538
29767
 
29539
29768
  // src/permissions/route-permission-guard.tsx
29540
29769
  import { ExclamationCircle as ExclamationCircle5 } from "@medusajs/icons";
29541
29770
  import { Container as Container6, Heading as Heading10, Text as Text22 } from "@medusajs/ui";
29542
- import { useMemo as useMemo27 } from "react";
29771
+ import { useMemo as useMemo28 } from "react";
29543
29772
  import { useTranslation as useTranslation50 } from "react-i18next";
29544
29773
  import { Navigate as Navigate2, Outlet as Outlet3, useMatches } from "react-router-dom";
29545
29774
  import { jsx as jsx111, jsxs as jsxs74 } from "react/jsx-runtime";
@@ -29572,7 +29801,7 @@ var readRequirementFromHandle = (handle) => {
29572
29801
  var RoutePermissionGuard = () => {
29573
29802
  const matches = useMatches();
29574
29803
  const { hasAnyPermission, hasAllPermissions, isLoading } = usePermissions();
29575
- const requirement = useMemo27(() => {
29804
+ const requirement = useMemo28(() => {
29576
29805
  for (let i = matches.length - 1; i >= 0; i--) {
29577
29806
  const found = readRequirementFromHandle(matches[i].handle);
29578
29807
  if (found) {
@@ -29610,10 +29839,10 @@ var AccessDenied = ({
29610
29839
  };
29611
29840
 
29612
29841
  // src/permissions/use-resource-permissions.tsx
29613
- import { useMemo as useMemo28 } from "react";
29842
+ import { useMemo as useMemo29 } from "react";
29614
29843
  var useResourcePermissions = (key) => {
29615
29844
  const { can, isLoading } = usePermissions();
29616
- return useMemo28(
29845
+ return useMemo29(
29617
29846
  () => ({
29618
29847
  canView: can(key, "view"),
29619
29848
  canEdit: can(key, "edit"),
@@ -29680,7 +29909,7 @@ import { createContext as createContext11 } from "react";
29680
29909
  var SidebarContext = createContext11(null);
29681
29910
 
29682
29911
  // src/providers/sidebar-provider/sidebar-provider.tsx
29683
- import { useCallback as useCallback29, useEffect as useEffect27, useMemo as useMemo29, useState as useState40 } from "react";
29912
+ import { useCallback as useCallback29, useEffect as useEffect27, useMemo as useMemo30, useState as useState40 } from "react";
29684
29913
  import { useLocation as useLocation4 } from "react-router-dom";
29685
29914
  import { jsx as jsx114 } from "react/jsx-runtime";
29686
29915
  var SidebarProvider = ({ children }) => {
@@ -29697,7 +29926,7 @@ var SidebarProvider = ({ children }) => {
29697
29926
  setMobile((open) => !open);
29698
29927
  }
29699
29928
  }, []);
29700
- const value = useMemo29(
29929
+ const value = useMemo30(
29701
29930
  () => ({
29702
29931
  state: desktop ? "expanded" : "collapsed",
29703
29932
  desktop,
@@ -29752,22 +29981,22 @@ var useSidebarMenuPlacement = (align) => {
29752
29981
  };
29753
29982
 
29754
29983
  // src/layout-composer/layout-composer.tsx
29755
- import { Fragment as Fragment15, useContext as useContext18, useMemo as useMemo30 } from "react";
29984
+ import { Fragment as Fragment16, useContext as useContext18, useMemo as useMemo31 } from "react";
29756
29985
  import { Outlet as Outlet4 } from "react-router-dom";
29757
29986
 
29758
29987
  // src/layout-composer/entries.ts
29759
29988
  import {
29760
29989
  Children as Children4,
29761
- Fragment as Fragment14,
29990
+ Fragment as Fragment15,
29762
29991
  createElement as createElement3,
29763
29992
  isValidElement as isValidElement2
29764
29993
  } from "react";
29765
29994
 
29766
29995
  // src/layout-composer/entry.tsx
29767
- import { Fragment as Fragment13 } from "react";
29996
+ import { Fragment as Fragment14 } from "react";
29768
29997
  import { jsx as jsx115 } from "react/jsx-runtime";
29769
29998
  function LayoutEntry({ children }) {
29770
- return /* @__PURE__ */ jsx115(Fragment13, { children });
29999
+ return /* @__PURE__ */ jsx115(Fragment14, { children });
29771
30000
  }
29772
30001
  LayoutEntry.displayName = "LayoutEntry";
29773
30002
 
@@ -29788,7 +30017,7 @@ function collectElements(node) {
29788
30017
  const elements = [];
29789
30018
  Children4.forEach(node, (child) => {
29790
30019
  if (!isValidElement2(child)) return;
29791
- if (child.type === Fragment14) {
30020
+ if (child.type === Fragment15) {
29792
30021
  elements.push(...collectElements(child.props.children));
29793
30022
  return;
29794
30023
  }
@@ -29897,7 +30126,7 @@ var LayoutComposerRoot = ({
29897
30126
  const registry = useExtension();
29898
30127
  const permissions = useContext18(PermissionsContext);
29899
30128
  const layout = registry.getLayout(preferredLayoutId);
29900
- const entriesBySection = useMemo30(() => {
30129
+ const entriesBySection = useMemo31(() => {
29901
30130
  const sectionIds = layout?.sections.map((section) => section.id) ?? [];
29902
30131
  const validSections = new Set(sectionIds);
29903
30132
  const core = buildCoreEntries(extractSectionElements(sections));
@@ -29921,7 +30150,7 @@ var LayoutComposerRoot = ({
29921
30150
  }
29922
30151
  const rendered = {};
29923
30152
  for (const section of layout.sections) {
29924
- rendered[section.id] = (entriesBySection[section.id] ?? []).filter((entry) => !entry.hidden).map((entry) => /* @__PURE__ */ jsx116(Fragment15, { children: entry.render(data) }, entry.entryId));
30153
+ rendered[section.id] = (entriesBySection[section.id] ?? []).filter((entry) => !entry.hidden).map((entry) => /* @__PURE__ */ jsx116(Fragment16, { children: entry.render(data) }, entry.entryId));
29925
30154
  }
29926
30155
  const LayoutComponent = layout.Component;
29927
30156
  return /* @__PURE__ */ jsxs75("div", { className: "flex w-full flex-col gap-y-3", "data-testid": testId, children: [
@@ -29934,9 +30163,9 @@ var LayoutComposer = Object.assign(LayoutComposerRoot, {
29934
30163
  });
29935
30164
 
29936
30165
  // src/layout-composer/detail-page-defaults.tsx
29937
- import { Fragment as Fragment16, jsx as jsx117, jsxs as jsxs76 } from "react/jsx-runtime";
30166
+ import { Fragment as Fragment17, jsx as jsx117, jsxs as jsxs76 } from "react/jsx-runtime";
29938
30167
  function detailPageDefaultEntries(data, { metadata = true, jsonView = true } = {}) {
29939
- return /* @__PURE__ */ jsxs76(Fragment16, { children: [
30168
+ return /* @__PURE__ */ jsxs76(Fragment17, { children: [
29940
30169
  metadata && /* @__PURE__ */ jsx117(LayoutEntry, { id: "MetadataSection", children: /* @__PURE__ */ jsx117(MetadataSection, { data }) }),
29941
30170
  jsonView && /* @__PURE__ */ jsx117(LayoutEntry, { id: "JsonViewSection", children: /* @__PURE__ */ jsx117(JsonViewSection, { data }) })
29942
30171
  ] });
@@ -30132,6 +30361,7 @@ export {
30132
30361
  EmailHeader,
30133
30362
  EmailSchema,
30134
30363
  ErrorBoundary,
30364
+ ExtendableFormField,
30135
30365
  ExtensionProvider,
30136
30366
  ExtensionRegistry,
30137
30367
  FilePreview,
@@ -30230,6 +30460,7 @@ export {
30230
30460
  buildDisplayEntries,
30231
30461
  buildOfferGridData,
30232
30462
  buildProductChangeView,
30463
+ buildScopedAdditionalData,
30233
30464
  buildWidgetEntries,
30234
30465
  countries,
30235
30466
  createDataGridHelper,
@@ -30277,6 +30508,8 @@ export {
30277
30508
  productChangeViewHasContent,
30278
30509
  queryClient,
30279
30510
  queryKeysFactory,
30511
+ refineAdditionalData,
30512
+ resolveFormFieldType,
30280
30513
  resolveRouteOverrides,
30281
30514
  richTextContentClasses,
30282
30515
  sanitizeRichText,
@@ -30292,6 +30525,7 @@ export {
30292
30525
  useDocumentDirection,
30293
30526
  useExpandedSidebar,
30294
30527
  useExtendableForm,
30528
+ useExtendableGrid,
30295
30529
  useExtendableTable,
30296
30530
  useExtension,
30297
30531
  useExtensionActivity,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mercurjs/dashboard-shared",
3
- "version": "2.3.9-canary.2",
3
+ "version": "2.3.9-canary.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/mercurjs/mercur",
@@ -34,7 +34,7 @@
34
34
  "@medusajs/dashboard": "2.22.0",
35
35
  "@medusajs/icons": "2.22.0",
36
36
  "@medusajs/ui": "4.2.3",
37
- "@mercurjs/client": "2.3.9-canary.2",
37
+ "@mercurjs/client": "2.3.9-canary.4",
38
38
  "@radix-ui/react-dialog": "1.1.19",
39
39
  "@radix-ui/react-dismissable-layer": "1.1.4",
40
40
  "@tanstack/react-query": "5.64.2",
@@ -70,9 +70,9 @@
70
70
  },
71
71
  "devDependencies": {
72
72
  "@medusajs/types": "2.22.0",
73
- "@mercurjs/core": "2.3.9-canary.2",
74
- "@mercurjs/dashboard-sdk": "2.3.9-canary.2",
75
- "@mercurjs/types": "2.3.9-canary.2",
73
+ "@mercurjs/core": "2.3.9-canary.4",
74
+ "@mercurjs/dashboard-sdk": "2.3.9-canary.4",
75
+ "@mercurjs/types": "2.3.9-canary.4",
76
76
  "@types/lodash.debounce": "^4.0.8",
77
77
  "@types/react": "^18.3.2",
78
78
  "@types/react-dom": "^18.2.22",