@mercurjs/dashboard-shared 2.4.2-canary.0 → 2.4.2-canary.1

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.ts CHANGED
@@ -1920,6 +1920,11 @@ declare class ExtensionRegistry {
1920
1920
  * and are read through `getFormFieldOverride` instead.
1921
1921
  */
1922
1922
  getFormFields(model: string, zone: string, tab?: string, builtInFieldIds?: string[], exactTab?: boolean): ResolvedFormField[];
1923
+ /**
1924
+ * Custom fields of every tab of a zone, for a tabbed form's schema and
1925
+ * defaults, which cover all its tabs at once.
1926
+ */
1927
+ getZoneFormFields(model: string, zone: string, builtInFieldIds?: string[]): ResolvedFormField[];
1923
1928
  /** Replacement (or removal, `field: null`) of a built-in form field. */
1924
1929
  getFormFieldOverride(model: string, zone: string, id: string, tab?: string, exactTab?: boolean): FormFieldOverride;
1925
1930
  /**
package/dist/index.js CHANGED
@@ -26477,19 +26477,25 @@ var ExtensionRegistry = class {
26477
26477
  getActivity(model, entity) {
26478
26478
  return this.configsFor(model).flatMap((c) => c.activity?.(entity) ?? []);
26479
26479
  }
26480
- // Configs are ordered plugins first, host app last. Entries are keyed so a
26481
- // later config replaces an earlier one in place — including entries another
26482
- // config added — instead of stacking a duplicate.
26480
+ // Configs are ordered plugins first, host app last. Entries are keyed per
26481
+ // zone and tab so a later config replaces an earlier one in place —
26482
+ // including entries another config added — instead of stacking a duplicate,
26483
+ // while one field name can still appear in several zones.
26483
26484
  resolveFormFields(model) {
26484
- const byName = /* @__PURE__ */ new Map();
26485
+ const byKey = /* @__PURE__ */ new Map();
26485
26486
  for (const config3 of this.configsFor(model)) {
26486
26487
  for (const form of config3.forms ?? []) {
26487
26488
  for (const [name, field] of Object.entries(form.fields ?? {})) {
26488
- byName.set(name, { name, field, zone: form.zone, tab: form.tab });
26489
+ byKey.set(`${form.zone}\0${form.tab ?? ""}\0${name}`, {
26490
+ name,
26491
+ field,
26492
+ zone: form.zone,
26493
+ tab: form.tab
26494
+ });
26489
26495
  }
26490
26496
  }
26491
26497
  }
26492
- return [...byName.values()];
26498
+ return [...byKey.values()];
26493
26499
  }
26494
26500
  // An entry without a tab belongs to every tab of its zone, unless the host
26495
26501
  // asks for `exactTab` (a data grid tab only takes fields aimed at it).
@@ -26511,6 +26517,16 @@ var ExtensionRegistry = class {
26511
26517
  ({ name, field }) => field && !builtIns.has(name) ? [{ name, field }] : []
26512
26518
  );
26513
26519
  }
26520
+ /**
26521
+ * Custom fields of every tab of a zone, for a tabbed form's schema and
26522
+ * defaults, which cover all its tabs at once.
26523
+ */
26524
+ getZoneFormFields(model, zone, builtInFieldIds = []) {
26525
+ const builtIns = new Set(builtInFieldIds);
26526
+ return this.resolveFormFields(model).flatMap(
26527
+ ({ name, field, zone: z5 }) => z5 === zone && field && !builtIns.has(name) ? [{ name, field }] : []
26528
+ );
26529
+ }
26514
26530
  /** Replacement (or removal, `field: null`) of a built-in form field. */
26515
26531
  getFormFieldOverride(model, zone, id, tab, exactTab = false) {
26516
26532
  const entry = this.formEntriesFor(model, zone, tab, exactTab).find(
@@ -26941,9 +26957,13 @@ function resolveFormFieldType(field) {
26941
26957
  return "textarea";
26942
26958
  }
26943
26959
  }
26960
+ var resolveScopedFields = (registry, model, zone, tab, builtInFieldIds) => {
26961
+ if (!zone) return registry.getAllFormFields(model);
26962
+ return tab ? registry.getFormFields(model, zone, tab, builtInFieldIds) : registry.getZoneFormFields(model, zone, builtInFieldIds);
26963
+ };
26944
26964
  function buildAdditionalDataSchema(registry, model, zone, tab, builtInFieldIds) {
26945
26965
  const shape = {};
26946
- const fields = zone ? registry.getFormFields(model, zone, tab, builtInFieldIds) : registry.getAllFormFields(model);
26966
+ const fields = resolveScopedFields(registry, model, zone, tab, builtInFieldIds);
26947
26967
  for (const { name, field } of fields) {
26948
26968
  shape[name] = field.validation;
26949
26969
  }
@@ -26951,7 +26971,7 @@ function buildAdditionalDataSchema(registry, model, zone, tab, builtInFieldIds)
26951
26971
  }
26952
26972
  function buildAdditionalDataDefaults(registry, model, data, zone, tab, builtInFieldIds) {
26953
26973
  const defaults = {};
26954
- const fields = zone ? registry.getFormFields(model, zone, tab, builtInFieldIds) : registry.getAllFormFields(model);
26974
+ const fields = resolveScopedFields(registry, model, zone, tab, builtInFieldIds);
26955
26975
  for (const { name, field } of fields) {
26956
26976
  if (typeof field.defaultValue === "function") {
26957
26977
  defaults[name] = field.defaultValue(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mercurjs/dashboard-shared",
3
- "version": "2.4.2-canary.0",
3
+ "version": "2.4.2-canary.1",
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.3",
35
35
  "@medusajs/icons": "2.22.3",
36
36
  "@medusajs/ui": "4.2.3",
37
- "@mercurjs/client": "2.4.2-canary.0",
37
+ "@mercurjs/client": "2.4.2-canary.1",
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.3",
73
- "@mercurjs/core": "2.4.2-canary.0",
74
- "@mercurjs/dashboard-sdk": "2.4.2-canary.0",
75
- "@mercurjs/types": "2.4.2-canary.0",
73
+ "@mercurjs/core": "2.4.2-canary.1",
74
+ "@mercurjs/dashboard-sdk": "2.4.2-canary.1",
75
+ "@mercurjs/types": "2.4.2-canary.1",
76
76
  "@types/lodash.debounce": "^4.0.8",
77
77
  "@types/react": "^18.3.2",
78
78
  "@types/react-dom": "^18.2.22",