@mapomodule/form 2.0.0-beta.10 → 2.0.0-beta.12

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 (56) hide show
  1. package/README.md +37 -119
  2. package/dist/__tests__/repeaterTemplates.test.d.ts +2 -0
  3. package/dist/__tests__/repeaterTemplates.test.d.ts.map +1 -0
  4. package/dist/__tests__/tabVisibility.test.d.ts +2 -0
  5. package/dist/__tests__/tabVisibility.test.d.ts.map +1 -0
  6. package/dist/index.d.mts +1 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/module.json +1 -1
  10. package/dist/runtime/components/MapoForm.vue +12 -3
  11. package/dist/runtime/components/MapoForm.vue.d.ts.map +1 -1
  12. package/dist/runtime/components/MapoFormGroup.vue +2 -2
  13. package/dist/runtime/components/MapoFormGroup.vue.d.ts.map +1 -1
  14. package/dist/runtime/components/MapoFormTabs.vue +19 -7
  15. package/dist/runtime/components/MapoFormTabs.vue.d.ts.map +1 -1
  16. package/dist/runtime/components/fields/MapoMediaField.vue +5 -3
  17. package/dist/runtime/components/fields/MapoMediaField.vue.d.ts.map +1 -1
  18. package/dist/runtime/components/fields/MapoMediaM2mField.vue +3 -2
  19. package/dist/runtime/components/fields/MapoMediaM2mField.vue.d.ts.map +1 -1
  20. package/dist/runtime/components/fields/MapoRepeater.vue +66 -13
  21. package/dist/runtime/components/fields/MapoRepeater.vue.d.ts.map +1 -1
  22. package/dist/runtime/components/fields/MapoRepeaterBlockPicker.vue +156 -0
  23. package/dist/runtime/components/fields/MapoRepeaterBlockPicker.vue.d.ts +20 -0
  24. package/dist/runtime/components/fields/MapoRepeaterBlockPicker.vue.d.ts.map +1 -0
  25. package/dist/runtime/components/fields/MapoRepeaterItem.vue +13 -1
  26. package/dist/runtime/components/fields/MapoRepeaterItem.vue.d.ts +6 -2
  27. package/dist/runtime/components/fields/MapoRepeaterItem.vue.d.ts.map +1 -1
  28. package/dist/runtime/components/fields/MapoWygEditor.vue +18 -12
  29. package/dist/runtime/components/fields/MapoWygEditor.vue.d.ts.map +1 -1
  30. package/dist/runtime/types/descriptor.d.ts +37 -2
  31. package/dist/runtime/types/descriptor.d.ts.map +1 -1
  32. package/dist/runtime/types/index.d.ts +1 -1
  33. package/dist/runtime/types/index.d.ts.map +1 -1
  34. package/dist/runtime/utils/repeaterTemplates.d.ts +18 -0
  35. package/dist/runtime/utils/repeaterTemplates.d.ts.map +1 -0
  36. package/dist/runtime/utils/repeaterTemplates.js +43 -0
  37. package/dist/runtime/utils/tabVisibility.d.ts +18 -0
  38. package/dist/runtime/utils/tabVisibility.d.ts.map +1 -0
  39. package/dist/runtime/utils/tabVisibility.js +18 -0
  40. package/package.json +4 -4
  41. package/src/__tests__/repeaterTemplates.test.ts +134 -0
  42. package/src/__tests__/tabVisibility.test.ts +102 -0
  43. package/src/index.ts +1 -0
  44. package/src/runtime/components/MapoForm.vue +17 -4
  45. package/src/runtime/components/MapoFormGroup.vue +2 -2
  46. package/src/runtime/components/MapoFormTabs.vue +27 -7
  47. package/src/runtime/components/fields/MapoMediaField.vue +5 -3
  48. package/src/runtime/components/fields/MapoMediaM2mField.vue +3 -2
  49. package/src/runtime/components/fields/MapoRepeater.vue +75 -13
  50. package/src/runtime/components/fields/MapoRepeaterBlockPicker.vue +171 -0
  51. package/src/runtime/components/fields/MapoRepeaterItem.vue +14 -0
  52. package/src/runtime/components/fields/MapoWygEditor.vue +18 -12
  53. package/src/runtime/types/descriptor.ts +42 -2
  54. package/src/runtime/types/index.ts +1 -0
  55. package/src/runtime/utils/repeaterTemplates.ts +80 -0
  56. package/src/runtime/utils/tabVisibility.ts +44 -0
package/README.md CHANGED
@@ -1,44 +1,28 @@
1
1
  # @mapomodule/form
2
2
 
3
- Form engine for Mapo v2 — descriptor-driven, typesafe, headless-ready admin forms for Nuxt 4 + Django/DRF.
4
-
5
- ## Features
6
-
7
- - **Descriptor-driven**: define fields as `FieldDescriptor[]` — layout, validation, i18n in one object
8
- - **All field types built-in**: text, select, date/time, FK/M2M autocomplete, WYSIWYG editor, SEO preview, map, repeater, media pickers
9
- - **Headless composable**: `useMapoForm()` for fully custom layouts; `<MapoForm>` for the default shell
10
- - **Registry auto-injection**: `<MapoForm>` and `<MapoDetail>` resolve `$mapoFormRegistry` automatically — no boilerplate
11
- - **Typed extension API**: `defineFormField(type, entry, opts)` to register custom fields with collision detection
12
- - **JSON Schema bridge**: `useFormFromSchema()` generates descriptors from Pydantic v2 / DRF-spectacular schemas
13
- - **Multilingual fields**: `translatable: true` writes to `model.translations[lang].field` automatically
14
- - **Client validation**: `validate(value, ctx)` per descriptor + `required` shorthand
15
- - **Tab/group layout**: declare `tab` and `group` per field — tabs render automatically (incl. nested tabs), groups are collapsible. Tab panels expose `tab.<name>.before/after`, full override, `.label` and `tab-bar-end` slots
16
- - **Consistent repeater items**: `MapoRepeater` drives each item through `useMapoForm`, so nested-path keys, `translatable`, accessors, `descriptor.is` overrides and **client validation** behave identically inside a repeater
17
- - **Draft persistence**: `draftKey` option on `useMapoForm()` auto-saves to localStorage every 2 s; `checkDraft()` / `draftBanner` offer restore/discard; clears on successful `submit()`
18
- - **Fail-soft**: unknown field types render a non-destructive placeholder, never crash the form
19
- - **Media pickers**: `media`, `media-m2m` and `enhanced-media` field types are built in; they drive the Media Manager from [`@mapomodule/uikit`](../uikit/README.md), resolved at runtime — install it to enable them
20
-
21
- ## Install
22
-
23
- `@mapomodule/form` is included automatically when you install `mapomodule` (recommended). No additional module entry is needed.
24
-
25
- ```ts
26
- // nuxt.config.ts
27
- export default defineNuxtConfig({
28
- modules: ["@nuxt/ui", "mapomodule"],
29
- mapo: {
30
- form: {
31
- // optional — global field registry defaults
32
- },
33
- },
34
- });
3
+ The form engine of Mapo. A form is an array of `FieldDescriptor` objects; the engine resolves each descriptor's `type` through a field registry to a lazily loaded component, and renders the result in `MapoDetail` (from `@mapomodule/uikit`), in `MapoForm`, or headless through `useMapoForm()`.
4
+
5
+ ## Installation
6
+
7
+ Installed by the meta-package [`mapomodule`](https://www.npmjs.com/package/mapomodule), which configures it under `mapo.form`. On its own it reads the `mapoForm` key:
8
+
9
+ ```bash
10
+ pnpm add @mapomodule/form@next
35
11
  ```
36
12
 
13
+ | Option | Default | Description |
14
+ | ----------------- | ------- | ---------------------------------------------------------------------------------------- |
15
+ | `fields.attrs` | `{}` | Default `attrs` per field type, merged into the registry defaults |
16
+ | `groups.expanded` | `true` | Whether collapsible field groups start open |
17
+ | `debounce` | `300` | Milliseconds before a field change reaches the model; `descriptor.debounce` overrides it |
18
+
19
+ Mapo v2 is published on the `next` dist-tag while it is in beta.
20
+
37
21
  ## Quick start
38
22
 
39
23
  ```vue
40
24
  <script setup lang="ts">
41
- import type { FieldDescriptor } from "@mapomodule/form";
25
+ import type { FieldDescriptor } from "mapomodule/types";
42
26
 
43
27
  interface Article {
44
28
  title: string;
@@ -61,96 +45,30 @@ const fields: FieldDescriptor<Article>[] = [
61
45
  </template>
62
46
  ```
63
47
 
64
- The `registry` prop is optional — `<MapoForm>` falls back to the global `$mapoFormRegistry` provided by this module's plugin. Pass it explicitly only when you want to swap the registry for a single form.
65
-
66
- ## Field types
67
-
68
- | Type | Component | Notes |
69
- | ---------------------------- | --------------------- | ----------------------------------------------------------- |
70
- | `text` | `UInput` | |
71
- | `textarea` | `UTextarea` | |
72
- | `number` | `UInput[type=number]` | |
73
- | `boolean` | `UCheckbox` | |
74
- | `switch` | `USwitch` | |
75
- | `color` | `UInput[type=color]` | |
76
- | `slider` | `USlider` | |
77
- | `file` | `MapoFileField` | Current-file preview, image thumbnail, remove button |
78
- | `select` | `USelectMenu` | requires `attrs.options` |
79
- | `date` / `datetime` / `time` | `MapoDateField` etc. | ISO string in model; `tz: 'naive' \| 'utc'` for `datetime` |
80
- | `fks` | `MapoFksField` | FK autocomplete; `attrs.endpoint` required |
81
- | `m2m` | `MapoFksField` | Multi-select autocomplete, removable chips |
82
- | `editor` | `MapoWygEditor` | Tiptap v2; sanitized output, safe `Link` validator |
83
- | `seo` | `MapoSeoPreview` | Title / description with live SERP preview |
84
- | `map` | `MapoMapField` | Leaflet, `{ lat, lng }` in model, SSR-safe via `ClientOnly` |
85
- | `repeater` | `MapoRepeater` | Nested fields, drag-and-drop, undo stack, templates |
86
-
87
- ## JSON Schema → Form
88
-
89
- ```ts
90
- const schema = await $fetch("/api/schema/");
91
- const fields = useFormFromSchema(schema, {
92
- exclude: ["id", "created_at"],
93
- overrides: {
94
- body: { type: "editor", translatable: true },
95
- },
96
- });
97
- ```
48
+ The built-in types cover text and numbers, choices, dates and times, files, relations (`fks`, `m2m`), rich text, SEO preview, maps, repeaters and media pickers. The media pickers drive the Media Manager of `@mapomodule/uikit` and show a notice when it is not installed. A `type` the registry does not know renders `MapoUnknownField` instead of breaking the form.
98
49
 
99
- ## Headless
50
+ ## What you get
100
51
 
101
- ```ts
102
- const form = useMapoForm({ model, fields, registry: $mapoFormRegistry });
52
+ Components and composables are auto-imported.
103
53
 
104
- // form.isDirty, form.isLoading, form.getPatch(), form.submit(handler)
105
- ```
106
-
107
- The headless composable still requires the registry explicitly — `useNuxtApp()` is not available in every context where you might want to drive a form (tests, storybook, server-side preview).
108
-
109
- ## Draft persistence (headless)
54
+ | API | Purpose |
55
+ | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
56
+ | `MapoForm` | Renders a `FieldDescriptor[]` on your model, with tabs, collapsible groups, a responsive grid and slots |
57
+ | `useMapoForm(options)` | The same engine headless: dirty state, client validation, `getPatch()`, `submit()`, drafts. Pass `registry` explicitly |
58
+ | `defineFormField(type, component, opts?)` | Registers a custom field type from a plugin: a component or a lazy `import()`, with optional default `attrs` and accessor. Re-registering a type warns unless you pass `{ override: true }` |
59
+ | `useFormFromSchema(schema, opts?)` | Builds descriptors from a JSON Schema, such as a DRF-spectacular or Pydantic schema |
60
+ | `when`, `whenAny`, `whenNot`, `matchesField`, `isOneOf`, … | Build `visible` conditions declaratively |
61
+ | `useFormDraft`, `useFocusMode`, `useCurrentLang` | Draft autosave, focus mode, the language being edited |
62
+ | `$mapoFormRegistry` | The global registry: type → component, default `attrs`, accessor |
110
63
 
111
- ```ts
112
- const form = useMapoForm({
113
- model,
114
- fields,
115
- registry: $mapoFormRegistry,
116
- draftKey: `article:${route.params.id}`,
117
- });
118
-
119
- // After fetch:
120
- form.checkDraft(); // populates form.draftBanner if a draft is found
121
- ```
122
-
123
- `form.draftBanner.value` exposes `{ savedAt, restore(), discard() }`. On `submit()` success the draft is cleared automatically. When using `<MapoDetail :draft="true">`, all of this is handled for you.
124
-
125
- ## Custom fields
126
-
127
- The recommended way to register a custom field is the typed `defineFormField()` helper, called from a Nuxt plugin:
128
-
129
- ```ts
130
- // app/plugins/my-fields.ts
131
- export default defineNuxtPlugin(() => {
132
- defineFormField("rich-text", () => import("~/components/RichText.vue"), {
133
- attrs: { rows: 6 },
134
- });
135
- });
136
- ```
137
-
138
- Plugins in `app/plugins/` run after module plugins, so `$mapoFormRegistry` is always available. Re-registering an existing type prints a development warning unless you pass `{ override: true }` explicitly.
139
-
140
- Any component with `modelValue` + `descriptor` + `errors` + `readonly` props works as a field.
64
+ A custom field is any component that accepts the `modelValue`, `descriptor`, `errors`, `readonly` and `disabled` props and emits `update:modelValue`.
141
65
 
142
66
  ## Documentation
143
67
 
144
- Full docs: [Form Engine — Quickstart](../../../docs/uikit/form/index.md)
145
-
146
- - [All field types](../../../docs/uikit/form/add-fields.md)
147
- - [Validation](../../../docs/uikit/form/validation.md)
148
- - [i18n / multilingual fields](../../../docs/uikit/form/i18n.md)
149
- - [`useMapoForm()` headless](../../../docs/uikit/form/composable.md)
150
- - [Custom fields & registry](../../../docs/uikit/form/custom-fields.md)
151
- - [Slot system](../../../docs/uikit/form/slots.md)
152
- - [JSON Schema bridge](../../../docs/uikit/form/schema-to-form.md)
153
-
154
- ## License
155
-
156
- MIT
68
+ - [Form Engine](https://lotrekagency.github.io/mapo-new/uikit/form/): your first form, tabs and groups, how the engine works
69
+ - [All field types](https://lotrekagency.github.io/mapo-new/uikit/form/add-fields)
70
+ - [Field registry](https://lotrekagency.github.io/mapo-new/uikit/form/registry) and [Custom fields](https://lotrekagency.github.io/mapo-new/uikit/form/custom-fields)
71
+ - [Validation](https://lotrekagency.github.io/mapo-new/uikit/form/validation), [Multilingual fields](https://lotrekagency.github.io/mapo-new/uikit/form/i18n), [Draft autosave](https://lotrekagency.github.io/mapo-new/uikit/form/draft), [Progressive Disclosure](https://lotrekagency.github.io/mapo-new/uikit/form/progressive-disclosure)
72
+ - [`useMapoForm()` reference](https://lotrekagency.github.io/mapo-new/uikit/form/composable)
73
+ - [From JSON Schema to form](https://lotrekagency.github.io/mapo-new/uikit/form/schema-to-form)
74
+ - [Form Engine — Component API Reference](https://lotrekagency.github.io/mapo-new/uikit/form/api)
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=repeaterTemplates.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repeaterTemplates.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/repeaterTemplates.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tabVisibility.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tabVisibility.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/tabVisibility.test.ts"],"names":[],"mappings":""}
package/dist/index.d.mts CHANGED
@@ -5,5 +5,5 @@ export { FocusTarget, useFocusMode } from '../dist/runtime/composables/useFocusM
5
5
  export { UnsavedChangesGuardOptions, useUnsavedChangesGuard } from '../dist/runtime/composables/useUnsavedChangesGuard.js';
6
6
  export { greaterThan, isEmpty, isNoneOf, isNotEmpty, isOneOf, lessThan, matches, matchesField, when, whenAny, whenNot } from '../dist/runtime/composables/useProgressiveDisclosure.js';
7
7
  export { FieldGroupDescriptor, flattenFieldGroups } from '../dist/runtime/utils/flattenFieldGroups.js';
8
- export { AnyFieldDescriptor, BooleanDescriptor, ColorDescriptor, CustomDescriptor, DateDescriptor, EditorDescriptor, EnhancedMediaDescriptor, EnhancedMediaValue, FieldAccessor, FieldComponentEntry, FieldDescriptor, FieldRegistry, FieldType, FileDescriptor, FksDescriptor, KnownFieldType, MapDescriptor, MediaDescriptor, MediaItem, MediaLink, MediaM2mDescriptor, NumberDescriptor, PartialFieldRegistry, RepeaterDescriptor, SelectDescriptor, SeoDescriptor, TextDescriptor } from '../dist/runtime/types/index.js';
8
+ export { AnyFieldDescriptor, BooleanDescriptor, ColorDescriptor, CustomDescriptor, DateDescriptor, EditorDescriptor, EnhancedMediaDescriptor, EnhancedMediaValue, FieldAccessor, FieldComponentEntry, FieldDescriptor, FieldRegistry, FieldType, FileDescriptor, FksDescriptor, KnownFieldType, MapDescriptor, MediaDescriptor, MediaItem, MediaLink, MediaM2mDescriptor, NumberDescriptor, PartialFieldRegistry, RepeaterDescriptor, RepeaterTemplate, SelectDescriptor, SeoDescriptor, TextDescriptor } from '../dist/runtime/types/index.js';
9
9
  import '@nuxt/schema';
package/dist/index.d.ts CHANGED
@@ -11,5 +11,5 @@ export { when, whenAny, whenNot, matchesField, isOneOf, isNoneOf, isNotEmpty, is
11
11
  export { flattenFieldGroups } from "./runtime/utils/flattenFieldGroups.js";
12
12
  export type { FieldGroupDescriptor } from "./runtime/utils/flattenFieldGroups.js";
13
13
  export { KnownFieldType } from "./runtime/types/index.js";
14
- export type { FieldType, FieldAccessor, FieldDescriptor, AnyFieldDescriptor, TextDescriptor, NumberDescriptor, BooleanDescriptor, SelectDescriptor, FksDescriptor, DateDescriptor, ColorDescriptor, FileDescriptor, EditorDescriptor, SeoDescriptor, MapDescriptor, RepeaterDescriptor, MediaDescriptor, MediaM2mDescriptor, EnhancedMediaDescriptor, CustomDescriptor, MediaLink, MediaItem, EnhancedMediaValue, FieldComponentEntry, FieldRegistry, PartialFieldRegistry, } from "./runtime/types/index.js";
14
+ export type { FieldType, FieldAccessor, FieldDescriptor, AnyFieldDescriptor, TextDescriptor, NumberDescriptor, BooleanDescriptor, SelectDescriptor, FksDescriptor, DateDescriptor, ColorDescriptor, FileDescriptor, EditorDescriptor, SeoDescriptor, MapDescriptor, RepeaterDescriptor, RepeaterTemplate, MediaDescriptor, MediaM2mDescriptor, EnhancedMediaDescriptor, CustomDescriptor, MediaLink, MediaItem, EnhancedMediaValue, FieldComponentEntry, FieldRegistry, PartialFieldRegistry, } from "./runtime/types/index.js";
15
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAC/E,YAAY,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AACrE,YAAY,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AACrE,YAAY,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iDAAiD,CAAC;AACzF,YAAY,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAC;AAElG,OAAO,EACL,IAAI,EACJ,OAAO,EACP,OAAO,EACP,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,UAAU,EACV,OAAO,EACP,WAAW,EACX,QAAQ,EACR,OAAO,GACR,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,YAAY,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,YAAY,EACV,SAAS,EACT,aAAa,EACb,eAAe,EACf,kBAA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,EACd,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,oBAAoB,GACrB,MAAM,0BAA0B,CAAC"}
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mapomodule/form",
3
3
  "configKey": "mapoForm",
4
- "version": "2.0.0-beta.10",
4
+ "version": "2.0.0-beta.12",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
@@ -1,6 +1,7 @@
1
1
  <script setup>
2
2
  import { computed, useSlots, watchEffect, inject, onUnmounted } from "vue";
3
3
  import { useNuxtApp, useRuntimeConfig } from "#app";
4
+ import { useI18n } from "vue-i18n";
4
5
  import { useMapoForm, injectMapoForm } from "../composables/useMapoForm.js";
5
6
  import { provideCurrentLang } from "../composables/useCurrentLang.js";
6
7
  import MapoFormGroup from "./MapoFormGroup.vue";
@@ -73,6 +74,8 @@ const fieldSlotNames = computed(
73
74
  )
74
75
  );
75
76
  provideCurrentLang(currentLangRef);
77
+ const { t } = useI18n();
78
+ const DEFAULT_TAB = "__default__";
76
79
  function getOrCreateTab(map, name) {
77
80
  if (!map.has(name)) {
78
81
  map.set(name, { name, groups: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() });
@@ -83,7 +86,7 @@ const grouped = computed(() => {
83
86
  const tabs = /* @__PURE__ */ new Map();
84
87
  for (const field of props.fields) {
85
88
  const rawTab = field.tab;
86
- const tabPath = !rawTab ? ["__default__"] : Array.isArray(rawTab) ? rawTab : rawTab.split("/");
89
+ const tabPath = !rawTab ? [DEFAULT_TAB] : Array.isArray(rawTab) ? rawTab : rawTab.split("/");
87
90
  const groupName = field.group ?? "__flat__";
88
91
  let currentMap = tabs;
89
92
  for (let i = 0; i < tabPath.length - 1; i++) {
@@ -104,14 +107,20 @@ const grouped = computed(() => {
104
107
  grp.fields.push(field);
105
108
  }
106
109
  }
110
+ const defaultTab = tabs.get(DEFAULT_TAB);
111
+ if (defaultTab) defaultTab.label = t("mapo.form.defaultTab");
107
112
  return tabs;
108
113
  });
109
114
  const hasTabs = computed(() => {
110
115
  const keys = [...grouped.value.keys()];
111
- return keys.length > 1 || keys.length === 1 && keys[0] !== "__default__";
116
+ const hasFields = keys.length > 0;
117
+ if (!hasFields) return false;
118
+ const hasSeveralTabs = keys.length > 1;
119
+ const hasNamedTab = keys[0] !== DEFAULT_TAB;
120
+ return hasSeveralTabs || hasNamedTab;
112
121
  });
113
122
  const defaultGroups = computed(
114
- () => grouped.value.get("__default__")?.groups ?? /* @__PURE__ */ new Map()
123
+ () => grouped.value.get(DEFAULT_TAB)?.groups ?? /* @__PURE__ */ new Map()
115
124
  );
116
125
  const tabList = computed(() => [...grouped.value.values()]);
117
126
  </script>
@@ -1 +1 @@
1
- {"version":3,"file":"MapoForm.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoForm.vue"],"names":[],"mappings":"AA2PA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE/B,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EAEd,MAAM,mBAAmB,CAAC;AAQ3B,QAAA,MAAM,YAAY,GAAK,CAAC,SAAS,MAAM,EACtC,aAAa,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,EAC9D,YAAY,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,EAC3G,gBAAgB,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,C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ub-tab bar + content (when subtabs are present) -->
194
194
  <div v-if="subtabs && subtabs.size > 0" class="px-5 pb-5 pt-4">
195
195
  <!-- Sub-tab bar -->
196
- <div class="flex gap-1 border-b border-gray-200 mb-4">
196
+ <div class="mb-4 flex flex-wrap gap-1 border-b border-gray-200">
197
197
  <button
198
198
  v-for="[subtabName] of subtabs"
199
199
  :key="subtabName"
200
200
  type="button"
201
- class="relative px-3 py-1.5 text-sm font-medium transition-colors focus:outline-none"
201
+ class="relative max-w-full px-3 py-1.5 text-sm font-medium transition-colors focus:outline-none"
202
202
  :class="[
203
203
  activeSubtab === subtabName ? 'text-primary-600 border-b-2 border-primary-600 -mb-px' : 'text-gray-500 hover:text-gray-700'
204
204
  ]"
@@ -1 +1 @@
1
- {"version":3,"file":"MapoFormGroup.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoFormGroup.vue"],"names":[],"mappings":"AAuSA,OAAO,KAAK,EACV,kBAAkB,EAEnB,MAAM,mBAAmB,CAAC;AAI3B,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAC7B,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAC5C,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAidF,QAAA,IAAI,QAAQ,mBAAW,EAAE,QAAQ;;;;CAAW,EAAE,QAAQ,QAAW,EAAE,QAAQ,KAAW,EAAE,QAAQ,mBAAW,EAAE,QAAQ;;;;CAAW,EAAE,QAAQ,QAAW,EAAE,QAAQ,KAAW,EAAE,QAAQ,mBAAW,EAAE,QAAQ;;;;CAAW,EAAE,QAAQ,QAAW,EAAE,QAAQ,KAAY,CAAE;AACjQ,KAAK,WAAW,GAAG,EAAE,GACnB;KAAG,CAAC,IAAI,WAAW,CAAC,OAAO,QAAQ,CAAC,CAAC,CAA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AS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -2,14 +2,27 @@
2
2
  import { ref, computed } from "vue";
3
3
  import { useI18n } from "vue-i18n";
4
4
  import { injectMapoForm } from "../composables/useMapoForm.js";
5
+ import { pickActiveTab, tabHasShownFields } from "../utils/tabVisibility.js";
5
6
  import MapoFormGroup from "./MapoFormGroup.vue";
6
7
  import MapoFormFlatSection from "./MapoFormFlatSection.vue";
7
8
  const { t } = useI18n();
8
9
  const props = defineProps({
9
10
  tabs: { type: Array, required: true }
10
11
  });
11
- defineSlots();
12
- const activeTab = ref(props.tabs[0]?.name ?? "");
12
+ const slots = defineSlots();
13
+ const form = injectMapoForm();
14
+ function tabHasContent(tab) {
15
+ const hasPanelSlot = Boolean(slots[`tab.${tab.name}`]);
16
+ const hasBeforeSlot = Boolean(slots[`tab.${tab.name}.before`]);
17
+ const hasAfterSlot = Boolean(slots[`tab.${tab.name}.after`]);
18
+ if (hasPanelSlot || hasBeforeSlot || hasAfterSlot) return true;
19
+ return tabHasShownFields(tab, form.model.value);
20
+ }
21
+ const shownTabs = computed(() => props.tabs.filter(tabHasContent));
22
+ const pickedTab = ref(null);
23
+ const activeTab = computed(
24
+ () => pickActiveTab(shownTabs.value, pickedTab.value)
25
+ );
13
26
  function tabHasErrors(tab, errorKeys) {
14
27
  const directError = [...tab.groups.values()].some(
15
28
  (g) => g.fields.some((f) => errorKeys.has(f.key))
@@ -19,7 +32,6 @@ function tabHasErrors(tab, errorKeys) {
19
32
  (child) => tabHasErrors(child, errorKeys)
20
33
  );
21
34
  }
22
- const form = injectMapoForm();
23
35
  const tabsWithErrors = computed(() => {
24
36
  const errorKeys = new Set(Object.keys(form.errors.value));
25
37
  return new Set(
@@ -31,16 +43,16 @@ const tabsWithErrors = computed(() => {
31
43
  <template>
32
44
  <div class="mapo-form-tabs">
33
45
  <!-- Tab bar -->
34
- <div class="flex gap-1 border-b border-gray-200 pb-px">
46
+ <div class="flex flex-wrap gap-1 border-b border-gray-200 pb-px">
35
47
  <button
36
- v-for="tab in tabs"
48
+ v-for="tab in shownTabs"
37
49
  :key="tab.name"
38
50
  type="button"
39
- class="relative flex items-center gap-1.5 rounded-t px-4 py-2 text-sm font-medium transition-colors"
51
+ class="relative flex max-w-full items-center gap-1.5 rounded-t px-4 py-2 text-sm font-medium transition-colors"
40
52
  :class="[
41
53
  activeTab === tab.name ? 'border-b-2 border-primary-500 text-primary-600' : 'text-gray-500 hover:bg-gray-50 hover:text-gray-700'
42
54
  ]"
43
- @click="activeTab = tab.name"
55
+ @click="pickedTab = tab.name"
44
56
  >
45
57
  <slot :name="`tab.${tab.name}.label`" :tab="tab">
46
58
  {{ tab.label ?? tab.name }}
@@ -1 +1 @@
1
- {"version":3,"file":"MapoFormTabs.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoFormTabs.vue"],"names":[],"mappings":"AA4HA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAOnD,KAAK,WAAW,GAAG;IAAE,IAAI,EAAE,QAAQ,EAAE,CAAA;CAAE,CAAC;AAGxC,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAsO3C,QAAA,MAAM,UAAU,kSAEd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"MapoFormTabs.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoFormTabs.vue"],"names":[],"mappings":"AAgJA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAQnD,KAAK,WAAW,GAAG;IAAE,IAAI,EAAE,QAAQ,EAAE,CAAA;CAAE,CAAC;AAGxC,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AA6P3C,QAAA,MAAM,UAAU,kSAEd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -35,10 +35,12 @@ function clear() {
35
35
  <MapoMediaUnavailable v-if="!available" />
36
36
 
37
37
  <template v-else>
38
- <!-- Selected media preview -->
38
+ <!-- Selected media preview. It and the trigger below paint their own
39
+ surface, like an input: `soft` buttons and transparent cards take
40
+ the page background and vanish on a tinted page. -->
39
41
  <div
40
42
  v-if="current"
41
- class="flex items-center gap-3 rounded-lg border border-default p-2"
43
+ class="flex items-center gap-3 rounded-lg border border-default bg-default p-2"
42
44
  >
43
45
  <MapoMediaPreview :media="current" size="sm" />
44
46
  <div class="flex-1 min-w-0">
@@ -64,7 +66,7 @@ function clear() {
64
66
  v-if="!readonly && !disabled"
65
67
  :icon="current ? 'i-lucide-refresh-cw' : 'i-lucide-image-plus'"
66
68
  size="sm"
67
- variant="soft"
69
+ variant="outline"
68
70
  color="neutral"
69
71
  :block="!current"
70
72
  @click="dialogOpen = true"
@@ -1 +1 @@
1
- {"version":3,"file":"MapoMediaField.vue.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/fields/MapoMediaField.vue"],"names":[],"mappings":"AA6GA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGvE,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAClD,UAAU,EAAE,eAAe,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAgOF,QAAA,MAAM,YAAY;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
1
+ {"version":3,"file":"MapoMediaField.vue.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/fields/MapoMediaField.vue"],"names":[],"mappings":"AA+GA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGvE,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAClD,UAAU,EAAE,eAAe,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAiOF,QAAA,MAAM,YAAY;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
@@ -77,12 +77,13 @@ function onDragEnd() {
77
77
  </div>
78
78
  </div>
79
79
 
80
- <!-- Add button -->
80
+ <!-- Add button: outlined like MapoMediaField's trigger, so it keeps its
81
+ own surface on a tinted page. -->
81
82
  <UButton
82
83
  v-if="!readonly && !disabled"
83
84
  icon="i-lucide-plus"
84
85
  size="sm"
85
- variant="soft"
86
+ variant="outline"
86
87
  color="neutral"
87
88
  @click="dialogOpen = true"
88
89
  >
@@ -1 +1 @@
1
- {"version":3,"file":"MapoMediaM2mField.vue.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/fields/MapoMediaM2mField.vue"],"names":[],"mappings":"AAuIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAG1E,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IACtD,UAAU,EAAE,kBAAkB,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AA+QF,QAAA,MAAM,YAAY;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
1
+ {"version":3,"file":"MapoMediaM2mField.vue.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/fields/MapoMediaM2mField.vue"],"names":[],"mappings":"AAwIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAG1E,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IACtD,UAAU,EAAE,kBAAkB,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AA+QF,QAAA,MAAM,YAAY;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
@@ -3,8 +3,14 @@ import { ref, computed, watchEffect } from "vue";
3
3
  import { useI18n } from "vue-i18n";
4
4
  import { VueDraggable } from "vue-draggable-plus";
5
5
  import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
6
+ import {
7
+ normalizeTemplates,
8
+ reachesMax,
9
+ shouldUseModalPicker
10
+ } from "../../utils/repeaterTemplates.js";
6
11
  import { injectMapoForm } from "../../composables/useMapoForm.js";
7
12
  import MapoRepeaterItem from "./MapoRepeaterItem.vue";
13
+ import MapoRepeaterBlockPicker from "./MapoRepeaterBlockPicker.vue";
8
14
  const props = defineProps({
9
15
  modelValue: { type: null, required: true },
10
16
  descriptor: { type: Object, required: true },
@@ -43,20 +49,42 @@ function undo() {
43
49
  if (prev) emit("update:modelValue", prev);
44
50
  }
45
51
  const templates = computed(() => attrs.value.templates);
46
- const templateKeys = computed(
47
- () => templates.value ? Object.keys(templates.value) : []
52
+ const templateList = computed(() => normalizeTemplates(templates.value));
53
+ const templateByKey = computed(
54
+ () => new Map(templateList.value.map((tpl) => [tpl.key, tpl]))
48
55
  );
56
+ const templateKeys = computed(() => templateList.value.map((tpl) => tpl.key));
49
57
  const hasTemplates = computed(() => templateKeys.value.length > 0);
50
58
  const selectedTemplate = ref("");
59
+ const useModalPicker = computed(
60
+ () => shouldUseModalPicker(attrs.value.picker, templateKeys.value.length)
61
+ );
62
+ const pickerOpen = ref(false);
63
+ const selectItems = computed(
64
+ () => templateList.value.map((tpl) => ({
65
+ label: tpl.label,
66
+ value: tpl.key,
67
+ description: tpl.description,
68
+ icon: tpl.icon
69
+ }))
70
+ );
71
+ function templateLabelFor(item) {
72
+ const key = item._template;
73
+ if (!key) return void 0;
74
+ return templateByKey.value.get(key)?.label ?? key;
75
+ }
76
+ function templateIconFor(item) {
77
+ return templateByKey.value.get(item._template)?.icon;
78
+ }
51
79
  watchEffect(() => {
52
80
  if (!selectedTemplate.value && templateKeys.value[0]) {
53
81
  selectedTemplate.value = templateKeys.value[0];
54
82
  }
55
83
  });
56
84
  function fieldsForItem(item) {
57
- if (!templates.value) return props.descriptor.fields ?? [];
85
+ if (!hasTemplates.value) return props.descriptor.fields ?? [];
58
86
  const key = item._template ?? selectedTemplate.value;
59
- return templates.value[key] ?? props.descriptor.fields ?? [];
87
+ return templateByKey.value.get(key)?.fields ?? props.descriptor.fields ?? [];
60
88
  }
61
89
  const canAdd = computed(
62
90
  () => !props.readonly && (!attrs.value.maxItems || items.value.length < attrs.value.maxItems)
@@ -79,12 +107,22 @@ async function askConfirm(message, title) {
79
107
  return typeof globalThis.confirm === "function" ? globalThis.confirm(message) : false;
80
108
  }
81
109
  }
82
- function addItem() {
110
+ function addItem(templateKey) {
83
111
  if (!canAdd.value) return;
84
112
  pushUndo();
85
- const newItem = hasTemplates.value ? { _template: selectedTemplate.value } : {};
113
+ const newItem = hasTemplates.value ? { _template: templateKey ?? selectedTemplate.value } : {};
86
114
  emitItems([...items.value, newItem]);
87
115
  }
116
+ function onAddClick() {
117
+ if (useModalPicker.value) pickerOpen.value = true;
118
+ else addItem();
119
+ }
120
+ function onPickTemplate(key, keepOpen) {
121
+ const full = reachesMax(items.value.length, attrs.value.maxItems);
122
+ selectedTemplate.value = key;
123
+ addItem(key);
124
+ if (!keepOpen || full) pickerOpen.value = false;
125
+ }
88
126
  async function deleteItem(index) {
89
127
  if (!canDelete.value) return;
90
128
  if (attrs.value.confirmDelete !== false) {
@@ -289,27 +327,38 @@ const errorPrefix = (index) => `${props.descriptor.key}.${index}`;
289
327
  @click="toggleSelectionMode"
290
328
  />
291
329
 
292
- <!-- Template selector -->
330
+ <!-- Template selector (dropdown mode; the modal picker opens from "Add") -->
293
331
  <USelectMenu
294
- v-if="hasTemplates"
332
+ v-if="hasTemplates && !useModalPicker"
295
333
  v-model="selectedTemplate"
296
- :items="templateKeys"
334
+ :items="selectItems"
335
+ value-key="value"
336
+ :search-input="templateKeys.length > 6"
337
+ :aria-label="t('mapo.repeater.blockType')"
297
338
  size="xs"
298
- class="w-32"
339
+ class="w-48"
299
340
  />
300
341
 
301
342
  <UButton
302
343
  size="sm"
303
344
  color="primary"
304
- icon="i-lucide-plus"
345
+ :icon="useModalPicker ? 'i-lucide-layout-grid' : 'i-lucide-plus'"
305
346
  :disabled="!canAdd"
306
- @click="addItem"
347
+ @click="onAddClick"
307
348
  >
308
- {{ t("mapo.add") }}
349
+ {{ useModalPicker ? t("mapo.repeater.addBlock") : t("mapo.add") }}
309
350
  </UButton>
310
351
  </div>
311
352
  </div>
312
353
 
354
+ <MapoRepeaterBlockPicker
355
+ v-if="useModalPicker"
356
+ v-model:open="pickerOpen"
357
+ :templates="templateList"
358
+ :disabled="!canAdd"
359
+ @select="onPickTemplate"
360
+ />
361
+
313
362
  <!-- ── Bulk actions bar (visible when there is a selection) ───────────── -->
314
363
  <Transition name="slide-down">
315
364
  <div
@@ -384,6 +433,8 @@ const errorPrefix = (index) => `${props.descriptor.key}.${index}`;
384
433
  <MapoRepeaterItem
385
434
  v-for="(item, index) in items"
386
435
  :key="`${uidFor(item)}-${collapseVersion}`"
436
+ :template-label="templateLabelFor(item)"
437
+ :template-icon="templateIconFor(item)"
387
438
  :uid="uidFor(item)"
388
439
  :item="item"
389
440
  :fields="fieldsForItem(item)"
@@ -416,6 +467,8 @@ const errorPrefix = (index) => `${props.descriptor.key}.${index}`;
416
467
  <MapoRepeaterItem
417
468
  v-for="(item, index) in items"
418
469
  :key="`${uidFor(item)}-${collapseVersion}`"
470
+ :template-label="templateLabelFor(item)"
471
+ :template-icon="templateIconFor(item)"
419
472
  :uid="uidFor(item)"
420
473
  :item="item"
421
474
  :fields="fieldsForItem(item)"
@@ -1 +1 @@
1
- {"version":3,"file":"MapoRepeater.vue.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/fields/MapoRepeater.vue"],"names":[],"mappings":"AAujBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI/D,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAgjCF,QAAA,MAAM,YAAY;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
1
+ {"version":3,"file":"MapoRepeater.vue.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/fields/MapoRepeater.vue"],"names":[],"mappings":"AAqnBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAU/D,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAqoCF,QAAA,MAAM,YAAY;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}