@mapomodule/form 2.0.0-beta.9 → 2.0.0-experimental.2

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 (145) hide show
  1. package/README.md +38 -119
  2. package/dist/index.d.mts +2 -1
  3. package/dist/index.d.ts +3 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.mjs +1 -0
  6. package/dist/module.d.mts +1 -0
  7. package/dist/module.d.ts.map +1 -1
  8. package/dist/module.json +1 -1
  9. package/dist/module.mjs +9 -0
  10. package/dist/runtime/components/MapoFocusPortal.vue +9 -2
  11. package/dist/runtime/components/MapoFocusPortal.vue.d.ts.map +1 -1
  12. package/dist/runtime/components/MapoForm.vue +28 -6
  13. package/dist/runtime/components/MapoForm.vue.d.ts +13 -1
  14. package/dist/runtime/components/MapoForm.vue.d.ts.map +1 -1
  15. package/dist/runtime/components/MapoFormAnnotation.vue +79 -0
  16. package/dist/runtime/components/MapoFormAnnotation.vue.d.ts +27 -0
  17. package/dist/runtime/components/MapoFormAnnotation.vue.d.ts.map +1 -0
  18. package/dist/runtime/components/MapoFormAnnotationBadges.vue +28 -0
  19. package/dist/runtime/components/MapoFormAnnotationBadges.vue.d.ts +13 -0
  20. package/dist/runtime/components/MapoFormAnnotationBadges.vue.d.ts.map +1 -0
  21. package/dist/runtime/components/MapoFormField.vue +47 -11
  22. package/dist/runtime/components/MapoFormField.vue.d.ts +15 -9
  23. package/dist/runtime/components/MapoFormField.vue.d.ts.map +1 -1
  24. package/dist/runtime/components/MapoFormGroup.vue +18 -2
  25. package/dist/runtime/components/MapoFormGroup.vue.d.ts.map +1 -1
  26. package/dist/runtime/components/MapoFormTabs.vue +50 -8
  27. package/dist/runtime/components/MapoFormTabs.vue.d.ts.map +1 -1
  28. package/dist/runtime/components/fields/MapoMediaField.vue +5 -3
  29. package/dist/runtime/components/fields/MapoMediaField.vue.d.ts.map +1 -1
  30. package/dist/runtime/components/fields/MapoMediaM2mField.vue +3 -2
  31. package/dist/runtime/components/fields/MapoMediaM2mField.vue.d.ts.map +1 -1
  32. package/dist/runtime/components/fields/MapoRepeater.vue +73 -14
  33. package/dist/runtime/components/fields/MapoRepeater.vue.d.ts.map +1 -1
  34. package/dist/runtime/components/fields/MapoRepeaterBlockPicker.vue +167 -0
  35. package/dist/runtime/components/fields/MapoRepeaterBlockPicker.vue.d.ts +20 -0
  36. package/dist/runtime/components/fields/MapoRepeaterBlockPicker.vue.d.ts.map +1 -0
  37. package/dist/runtime/components/fields/MapoRepeaterItem.vue +46 -10
  38. package/dist/runtime/components/fields/MapoRepeaterItem.vue.d.ts +6 -2
  39. package/dist/runtime/components/fields/MapoRepeaterItem.vue.d.ts.map +1 -1
  40. package/dist/runtime/components/fields/MapoWygEditor.vue +19 -13
  41. package/dist/runtime/components/fields/MapoWygEditor.vue.d.ts.map +1 -1
  42. package/dist/runtime/composables/useFieldAnnotation.d.ts +18 -0
  43. package/dist/runtime/composables/useFieldAnnotation.d.ts.map +1 -0
  44. package/dist/runtime/composables/useFieldAnnotation.js +16 -0
  45. package/dist/runtime/composables/useFocusMode.d.ts +3 -1
  46. package/dist/runtime/composables/useFocusMode.d.ts.map +1 -1
  47. package/dist/runtime/composables/useFormFromSchema.d.ts +23 -1
  48. package/dist/runtime/composables/useFormFromSchema.d.ts.map +1 -1
  49. package/dist/runtime/composables/useFormFromSchema.js +171 -32
  50. package/dist/runtime/composables/useMapoForm.d.ts +21 -3
  51. package/dist/runtime/composables/useMapoForm.d.ts.map +1 -1
  52. package/dist/runtime/composables/useMapoForm.js +49 -15
  53. package/dist/runtime/types/annotation.d.ts +43 -0
  54. package/dist/runtime/types/annotation.d.ts.map +1 -0
  55. package/dist/runtime/types/annotation.js +0 -0
  56. package/dist/runtime/types/descriptor.d.ts +81 -4
  57. package/dist/runtime/types/descriptor.d.ts.map +1 -1
  58. package/dist/runtime/types/index.d.ts +2 -1
  59. package/dist/runtime/types/index.d.ts.map +1 -1
  60. package/dist/runtime/utils/annotations.d.ts +40 -0
  61. package/dist/runtime/utils/annotations.d.ts.map +1 -0
  62. package/dist/runtime/utils/annotations.js +78 -0
  63. package/dist/runtime/utils/draft.d.ts +21 -0
  64. package/dist/runtime/utils/draft.d.ts.map +1 -0
  65. package/dist/runtime/utils/draft.js +108 -0
  66. package/dist/runtime/utils/fieldComponent.d.ts +9 -0
  67. package/dist/runtime/utils/fieldComponent.d.ts.map +1 -0
  68. package/dist/runtime/utils/fieldComponent.js +12 -0
  69. package/dist/runtime/utils/fieldFocus.d.ts +24 -0
  70. package/dist/runtime/utils/fieldFocus.d.ts.map +1 -0
  71. package/dist/runtime/utils/fieldFocus.js +41 -0
  72. package/dist/runtime/utils/fieldsToJsonSchema.d.ts +38 -0
  73. package/dist/runtime/utils/fieldsToJsonSchema.d.ts.map +1 -0
  74. package/dist/runtime/utils/fieldsToJsonSchema.js +248 -0
  75. package/dist/runtime/utils/repeaterTemplates.d.ts +26 -0
  76. package/dist/runtime/utils/repeaterTemplates.d.ts.map +1 -0
  77. package/dist/runtime/utils/repeaterTemplates.js +51 -0
  78. package/dist/runtime/utils/reveal.d.ts +34 -0
  79. package/dist/runtime/utils/reveal.d.ts.map +1 -0
  80. package/dist/runtime/utils/reveal.js +29 -0
  81. package/dist/runtime/utils/tabVisibility.d.ts +18 -0
  82. package/dist/runtime/utils/tabVisibility.d.ts.map +1 -0
  83. package/dist/runtime/utils/tabVisibility.js +18 -0
  84. package/package.json +5 -5
  85. package/src/__tests__/MapoFocusPortal.component.test.ts +97 -0
  86. package/src/__tests__/MapoForm.component.test.ts +79 -0
  87. package/src/__tests__/MapoFormAnnotation.component.test.ts +244 -0
  88. package/src/__tests__/MapoFormField.component.test.ts +508 -0
  89. package/src/__tests__/MapoFormGroup.component.test.ts +141 -0
  90. package/src/__tests__/MapoFormTabs.component.test.ts +254 -0
  91. package/src/__tests__/MapoRepeaterItem.component.test.ts +286 -0
  92. package/src/__tests__/MapoWygEditor.component.test.ts +95 -0
  93. package/src/__tests__/annotations.test.ts +227 -0
  94. package/src/__tests__/draft.test.ts +221 -0
  95. package/src/__tests__/fieldComponent.test.ts +31 -0
  96. package/src/__tests__/fieldExtensions.test.ts +63 -0
  97. package/src/__tests__/fieldFocus.test.ts +178 -0
  98. package/src/__tests__/fieldsToJsonSchema.test.ts +630 -0
  99. package/src/__tests__/headlessRenderer.ts +85 -0
  100. package/src/__tests__/repeaterTemplates.test.ts +154 -0
  101. package/src/__tests__/reveal.test.ts +89 -0
  102. package/src/__tests__/schemaSources.test.ts +132 -0
  103. package/src/__tests__/tabVisibility.test.ts +102 -0
  104. package/src/__tests__/useFormFromSchema.test.ts +387 -0
  105. package/src/__tests__/useMapoForm.test.ts +213 -2
  106. package/src/index.ts +9 -0
  107. package/src/module.ts +9 -0
  108. package/src/runtime/components/MapoFocusPortal.vue +15 -2
  109. package/src/runtime/components/MapoForm.vue +47 -4
  110. package/src/runtime/components/MapoFormAnnotation.vue +113 -0
  111. package/src/runtime/components/MapoFormAnnotationBadges.vue +41 -0
  112. package/src/runtime/components/MapoFormField.vue +72 -11
  113. package/src/runtime/components/MapoFormGroup.vue +20 -2
  114. package/src/runtime/components/MapoFormTabs.vue +64 -8
  115. package/src/runtime/components/fields/MapoMediaField.vue +5 -3
  116. package/src/runtime/components/fields/MapoMediaM2mField.vue +3 -2
  117. package/src/runtime/components/fields/MapoRepeater.vue +82 -14
  118. package/src/runtime/components/fields/MapoRepeaterBlockPicker.vue +188 -0
  119. package/src/runtime/components/fields/MapoRepeaterItem.vue +56 -8
  120. package/src/runtime/components/fields/MapoWygEditor.vue +22 -14
  121. package/src/runtime/composables/useFieldAnnotation.ts +38 -0
  122. package/src/runtime/composables/useFocusMode.ts +7 -1
  123. package/src/runtime/composables/useFormFromSchema.ts +303 -41
  124. package/src/runtime/composables/useMapoForm.ts +103 -23
  125. package/src/runtime/types/annotation.ts +53 -0
  126. package/src/runtime/types/descriptor.ts +94 -4
  127. package/src/runtime/types/index.ts +10 -0
  128. package/src/runtime/utils/annotations.ts +169 -0
  129. package/src/runtime/utils/draft.ts +158 -0
  130. package/src/runtime/utils/fieldComponent.ts +34 -0
  131. package/src/runtime/utils/fieldFocus.ts +73 -0
  132. package/src/runtime/utils/fieldsToJsonSchema.ts +405 -0
  133. package/src/runtime/utils/repeaterTemplates.ts +103 -0
  134. package/src/runtime/utils/reveal.ts +68 -0
  135. package/src/runtime/utils/tabVisibility.ts +44 -0
  136. package/dist/__tests__/__mocks__/nuxt-imports.d.ts +0 -4
  137. package/dist/__tests__/__mocks__/nuxt-imports.d.ts.map +0 -1
  138. package/dist/__tests__/camomillaRoundTrip.test.d.ts +0 -2
  139. package/dist/__tests__/camomillaRoundTrip.test.d.ts.map +0 -1
  140. package/dist/__tests__/registry.test.d.ts +0 -2
  141. package/dist/__tests__/registry.test.d.ts.map +0 -1
  142. package/dist/__tests__/useFormFromSchema.test.d.ts +0 -2
  143. package/dist/__tests__/useFormFromSchema.test.d.ts.map +0 -1
  144. package/dist/__tests__/useMapoForm.test.d.ts +0 -2
  145. package/dist/__tests__/useMapoForm.test.d.ts.map +0 -1
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,31 @@ 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, slots and field annotations |
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?)`, `fieldsToJsonSchema(fields)` | Builds descriptors from a JSON Schema, such as a DRF-spectacular or Pydantic schema, and describes a form as a JSON Schema that reads back into it |
60
+ | `FieldExtensions` | Declare typed descriptor properties of your own with `declare module "mapomodule/types"` |
61
+ | `when`, `whenAny`, `whenNot`, `matchesField`, `isOneOf`, … | Build `visible` conditions declaratively |
62
+ | `useFormDraft`, `useFocusMode`, `useCurrentLang`, `useFieldAnnotation` | Draft autosave, focus mode, the language being edited, the annotation of a field |
63
+ | `$mapoFormRegistry` | The global registry: type → component, default `attrs`, accessor |
110
64
 
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.
65
+ A custom field is any component that accepts the `modelValue`, `descriptor`, `errors`, `readonly` and `disabled` props and emits `update:modelValue`.
141
66
 
142
67
  ## Documentation
143
68
 
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
69
+ - [Form Engine](https://lotrekagency.github.io/mapo-new/uikit/form/): your first form, tabs and groups, how the engine works
70
+ - [All field types](https://lotrekagency.github.io/mapo-new/uikit/form/add-fields)
71
+ - [Field registry](https://lotrekagency.github.io/mapo-new/uikit/form/registry) and [Custom fields](https://lotrekagency.github.io/mapo-new/uikit/form/custom-fields)
72
+ - [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), [Field annotations](https://lotrekagency.github.io/mapo-new/uikit/form/annotations)
73
+ - [`useMapoForm()` reference](https://lotrekagency.github.io/mapo-new/uikit/form/composable)
74
+ - [JSON Schema and forms](https://lotrekagency.github.io/mapo-new/uikit/form/schema-to-form)
75
+ - [Form Engine — Component API Reference](https://lotrekagency.github.io/mapo-new/uikit/form/api)
package/dist/index.d.mts CHANGED
@@ -5,5 +5,6 @@ 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 { FieldsToJsonSchemaOptions, fieldsToJsonSchema } from '../dist/runtime/utils/fieldsToJsonSchema.js';
9
+ export { AnyFieldDescriptor, BooleanDescriptor, ColorDescriptor, CustomDescriptor, DateDescriptor, EditorDescriptor, EnhancedMediaDescriptor, EnhancedMediaValue, FieldAccessor, FieldAnnotation, FieldAnnotationAction, FieldAnnotationColor, FieldAnnotations, FieldComponentEntry, FieldDescriptor, FieldExtensions, FieldRegistry, FieldType, FileDescriptor, FksDescriptor, KnownFieldType, MapDescriptor, MediaDescriptor, MediaItem, MediaLink, MediaM2mDescriptor, NumberDescriptor, PartialFieldRegistry, RepeaterDescriptor, RepeaterImageFit, RepeaterTemplate, SelectDescriptor, SeoDescriptor, TextDescriptor } from '../dist/runtime/types/index.js';
9
10
  import '@nuxt/schema';
package/dist/index.d.ts CHANGED
@@ -10,6 +10,8 @@ export type { UnsavedChangesGuardOptions } from "./runtime/composables/useUnsave
10
10
  export { when, whenAny, whenNot, matchesField, isOneOf, isNoneOf, isNotEmpty, isEmpty, greaterThan, lessThan, matches, } from "./runtime/composables/useProgressiveDisclosure.js";
11
11
  export { flattenFieldGroups } from "./runtime/utils/flattenFieldGroups.js";
12
12
  export type { FieldGroupDescriptor } from "./runtime/utils/flattenFieldGroups.js";
13
+ export { fieldsToJsonSchema } from "./runtime/utils/fieldsToJsonSchema.js";
14
+ export type { FieldsToJsonSchemaOptions } from "./runtime/utils/fieldsToJsonSchema.js";
13
15
  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";
16
+ export type { FieldType, FieldAccessor, FieldDescriptor, AnyFieldDescriptor, FieldExtensions, TextDescriptor, NumberDescriptor, BooleanDescriptor, SelectDescriptor, FksDescriptor, DateDescriptor, ColorDescriptor, FileDescriptor, EditorDescriptor, SeoDescriptor, MapDescriptor, RepeaterDescriptor, RepeaterTemplate, RepeaterImageFit, MediaDescriptor, MediaM2mDescriptor, EnhancedMediaDescriptor, CustomDescriptor, MediaLink, MediaItem, EnhancedMediaValue, FieldComponentEntry, FieldRegistry, PartialFieldRegistry, FieldAnnotation, FieldAnnotationAction, FieldAnnotationColor, FieldAnnotations, } from "./runtime/types/index.js";
15
17
  //# 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,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,aAAa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AAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC"}
package/dist/index.mjs CHANGED
@@ -4,4 +4,5 @@ export { useFocusMode } from '../dist/runtime/composables/useFocusMode.js';
4
4
  export { useUnsavedChangesGuard } from '../dist/runtime/composables/useUnsavedChangesGuard.js';
5
5
  export { greaterThan, isEmpty, isNoneOf, isNotEmpty, isOneOf, lessThan, matches, matchesField, when, whenAny, whenNot } from '../dist/runtime/composables/useProgressiveDisclosure.js';
6
6
  export { flattenFieldGroups } from '../dist/runtime/utils/flattenFieldGroups.js';
7
+ export { fieldsToJsonSchema } from '../dist/runtime/utils/fieldsToJsonSchema.js';
7
8
  export { KnownFieldType } from '../dist/runtime/types/index.js';
package/dist/module.d.mts CHANGED
@@ -6,6 +6,7 @@ import '../dist/runtime/composables/useFocusMode.js';
6
6
  import '../dist/runtime/composables/useUnsavedChangesGuard.js';
7
7
  import '../dist/runtime/composables/useProgressiveDisclosure.js';
8
8
  import '../dist/runtime/utils/flattenFieldGroups.js';
9
+ import '../dist/runtime/utils/fieldsToJsonSchema.js';
9
10
 
10
11
  interface MapoFormOptions {
11
12
  fields?: PartialFieldRegistry;
@@ -1 +1 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAErE,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;;AAED,wBAkOyC"}
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAErE,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;;AAED,wBA2OyC"}
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.9",
4
+ "version": "2.0.0-experimental.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -68,6 +68,7 @@ export {};
68
68
  "MapoFormField",
69
69
  "MapoFormGroup",
70
70
  "MapoFormTabs",
71
+ "MapoFormAnnotation",
71
72
  "MapoUnknownField",
72
73
  "MapoFocusPortal"
73
74
  ];
@@ -106,10 +107,18 @@ export {};
106
107
  name: "useFormFromSchema",
107
108
  from: resolver.resolve("./runtime/composables/useFormFromSchema")
108
109
  },
110
+ {
111
+ name: "fieldsToJsonSchema",
112
+ from: resolver.resolve("./runtime/utils/fieldsToJsonSchema")
113
+ },
109
114
  {
110
115
  name: "useFormDraft",
111
116
  from: resolver.resolve("./runtime/composables/useFormDraft")
112
117
  },
118
+ {
119
+ name: "useFieldAnnotation",
120
+ from: resolver.resolve("./runtime/composables/useFieldAnnotation")
121
+ },
113
122
  {
114
123
  name: "useFocusMode",
115
124
  from: resolver.resolve("./runtime/composables/useFocusMode")
@@ -1,5 +1,5 @@
1
1
  <script setup>
2
- import { computed, ref, onMounted, onUnmounted } from "vue";
2
+ import { computed, ref, onMounted, onUnmounted, unref } from "vue";
3
3
  import { watch } from "vue";
4
4
  import { useI18n } from "vue-i18n";
5
5
  import { useFocusMode } from "../composables/useFocusMode.js";
@@ -7,6 +7,12 @@ import MapoForm from "./MapoForm.vue";
7
7
  const { t } = useI18n();
8
8
  const { focusTarget, exit } = useFocusMode();
9
9
  const isOpen = computed(() => focusTarget.value !== null);
10
+ const focusErrors = computed(
11
+ () => unref(focusTarget.value?.errors)
12
+ );
13
+ const focusAnnotations = computed(
14
+ () => unref(focusTarget.value?.annotations)
15
+ );
10
16
  const canUseDocument = typeof document !== "undefined";
11
17
  function onKeyDown(e) {
12
18
  if (e.key === "Escape" && isOpen.value) exit();
@@ -80,10 +86,11 @@ function onUpdate(val) {
80
86
  <MapoForm
81
87
  :model-value="localModel"
82
88
  :fields="focusTarget.fields"
83
- :errors="focusTarget.errors.value"
89
+ :errors="focusErrors"
84
90
  :languages="focusTarget.languages"
85
91
  :current-lang="focusTarget.currentLang"
86
92
  :registry="focusTarget.registry"
93
+ :annotations="focusAnnotations"
87
94
  @update:model-value="onUpdate"
88
95
  />
89
96
  </div>
@@ -1 +1 @@
1
- {"version":3,"file":"MapoFocusPortal.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoFocusPortal.vue"],"names":[],"mappings":"AAudA,QAAA,MAAM,YAAY,+QAChB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
1
+ {"version":3,"file":"MapoFocusPortal.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoFocusPortal.vue"],"names":[],"mappings":"AAofA,QAAA,MAAM,YAAY,+QAChB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
@@ -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";
@@ -14,7 +15,9 @@ const props = defineProps({
14
15
  currentLang: { type: String, required: false, default: "" },
15
16
  readonly: { type: Boolean, required: false, default: false },
16
17
  immediate: { type: Boolean, required: false, default: false },
17
- registry: { type: Object, required: false, default: void 0 }
18
+ notifyErrors: { type: Boolean, required: false, default: true },
19
+ registry: { type: Object, required: false, default: void 0 },
20
+ annotations: { type: Object, required: false, default: void 0 }
18
21
  });
19
22
  const injectedRegistry = computed(() => {
20
23
  if (props.registry) return props.registry;
@@ -42,8 +45,10 @@ const form = useMapoForm({
42
45
  languages: props.languages,
43
46
  currentLang: currentLangRef,
44
47
  immediate: props.immediate,
48
+ notifyErrors: props.notifyErrors,
45
49
  debounce: globalDebounce,
46
- registry: injectedRegistry.value
50
+ registry: injectedRegistry.value,
51
+ annotations: computed(() => props.annotations)
47
52
  });
48
53
  const parentCtx = injectMapoForm();
49
54
  watchEffect(() => {
@@ -56,7 +61,8 @@ defineExpose({
56
61
  resetDirty: form.resetDirty,
57
62
  getPatch: form.getPatch,
58
63
  isDirty: form.isDirty,
59
- isLoading: form.isLoading
64
+ isLoading: form.isLoading,
65
+ revealField: form.revealField
60
66
  });
61
67
  const registerValidator = inject(
62
68
  "mapoDetailRegisterValidator",
@@ -66,6 +72,14 @@ if (registerValidator) {
66
72
  const unregister = registerValidator(form.validateClient);
67
73
  onUnmounted(unregister);
68
74
  }
75
+ const registerReveal = inject(
76
+ "mapoDetailRegisterReveal",
77
+ null
78
+ );
79
+ if (registerReveal) {
80
+ const unregister = registerReveal(form.revealField);
81
+ onUnmounted(unregister);
82
+ }
69
83
  const slots = useSlots();
70
84
  const fieldSlotNames = computed(
71
85
  () => Object.keys(slots).filter(
@@ -73,6 +87,8 @@ const fieldSlotNames = computed(
73
87
  )
74
88
  );
75
89
  provideCurrentLang(currentLangRef);
90
+ const { t } = useI18n();
91
+ const DEFAULT_TAB = "__default__";
76
92
  function getOrCreateTab(map, name) {
77
93
  if (!map.has(name)) {
78
94
  map.set(name, { name, groups: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() });
@@ -83,7 +99,7 @@ const grouped = computed(() => {
83
99
  const tabs = /* @__PURE__ */ new Map();
84
100
  for (const field of props.fields) {
85
101
  const rawTab = field.tab;
86
- const tabPath = !rawTab ? ["__default__"] : Array.isArray(rawTab) ? rawTab : rawTab.split("/");
102
+ const tabPath = !rawTab ? [DEFAULT_TAB] : Array.isArray(rawTab) ? rawTab : rawTab.split("/");
87
103
  const groupName = field.group ?? "__flat__";
88
104
  let currentMap = tabs;
89
105
  for (let i = 0; i < tabPath.length - 1; i++) {
@@ -104,14 +120,20 @@ const grouped = computed(() => {
104
120
  grp.fields.push(field);
105
121
  }
106
122
  }
123
+ const defaultTab = tabs.get(DEFAULT_TAB);
124
+ if (defaultTab) defaultTab.label = t("mapo.form.defaultTab");
107
125
  return tabs;
108
126
  });
109
127
  const hasTabs = computed(() => {
110
128
  const keys = [...grouped.value.keys()];
111
- return keys.length > 1 || keys.length === 1 && keys[0] !== "__default__";
129
+ const hasFields = keys.length > 0;
130
+ if (!hasFields) return false;
131
+ const hasSeveralTabs = keys.length > 1;
132
+ const hasNamedTab = keys[0] !== DEFAULT_TAB;
133
+ return hasSeveralTabs || hasNamedTab;
112
134
  });
113
135
  const defaultGroups = computed(
114
- () => grouped.value.get("__default__")?.groups ?? /* @__PURE__ */ new Map()
136
+ () => grouped.value.get(DEFAULT_TAB)?.groups ?? /* @__PURE__ */ new Map()
115
137
  );
116
138
  const tabList = computed(() => [...grouped.value.values()]);
117
139
  </script>
@@ -1,5 +1,5 @@
1
1
  import type { Ref } from "vue";
2
- import type { AnyFieldDescriptor, FieldRegistry } from "../types/index.js";
2
+ import type { AnyFieldDescriptor, FieldAnnotations, FieldRegistry } from "../types/index.js";
3
3
  declare const __VLS_export: <T extends object>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
4
4
  props: import("vue").PublicProps & __VLS_PrettifyLocal<{
5
5
  modelValue: T;
@@ -9,12 +9,23 @@ declare const __VLS_export: <T extends object>(__VLS_props: NonNullable<Awaited<
9
9
  currentLang?: string;
10
10
  readonly?: boolean;
11
11
  immediate?: boolean;
12
+ /**
13
+ * Show a toast for server-side field errors. Set to `false` for secondary
14
+ * forms that share errors with another form. Defaults to `true`.
15
+ */
16
+ notifyErrors?: boolean;
12
17
  /**
13
18
  * Field component registry. When omitted, it is auto-injected from
14
19
  * `$mapoFormRegistry` (provided by the `@mapomodule/form` plugin).
15
20
  * Pass it explicitly only for headless forms or one-off registry swaps.
16
21
  */
17
22
  registry?: FieldRegistry;
23
+ /**
24
+ * Marks shown next to the field labels and counted on the tabs, keyed by
25
+ * the path of the value (`title`, `translations.it.title`, `blocks.0.title`).
26
+ * Changing the map updates the marks without remounting the fields.
27
+ */
28
+ annotations?: FieldAnnotations;
18
29
  } & {
19
30
  "onUpdate:modelValue"?: ((value: T) => any) | undefined;
20
31
  }> & (typeof globalThis extends {
@@ -30,6 +41,7 @@ declare const __VLS_export: <T extends object>(__VLS_props: NonNullable<Awaited<
30
41
  getPatch: () => Partial<T>;
31
42
  isDirty: import("vue").ComputedRef<boolean>;
32
43
  isLoading: Ref<boolean, boolean>;
44
+ revealField: (path: string) => Promise<boolean>;
33
45
  }>) => void;
34
46
  attrs: any;
35
47
  slots: Record<string, (props: Record<string, any>) => unknown>;
@@ -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AAC,GAAG,EAAE,CAAC;YAC5J,CAAC,OAAO,EAAE,OAAO,KAAK,EAAE,gBAAgB;;;;;;;;;;;MAAsB,KAAK,IAAI;WACxE,GAAG;kCAjT+B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO;;EAqTrE,KACQ,OAAO,KAAK,EAAE,KAAK,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,WAAW,CAAC,CAAA;CAAI,CAAC;wBACvD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,CAAC,GAAG,EAAE,CAAC"}
@@ -0,0 +1,79 @@
1
+ <script setup>
2
+ import { computed, nextTick } from "vue";
3
+ import {
4
+ DEFAULT_ANNOTATION_COLOR,
5
+ DEFAULT_ANNOTATION_ICON
6
+ } from "../utils/annotations.js";
7
+ import { refocusField } from "../utils/fieldFocus.js";
8
+ const props = defineProps({
9
+ annotation: { type: Object, required: true },
10
+ field: { type: String, required: false }
11
+ });
12
+ defineSlots();
13
+ const icon = computed(() => props.annotation.icon ?? DEFAULT_ANNOTATION_ICON);
14
+ const color = computed(
15
+ () => props.annotation.color ?? DEFAULT_ANNOTATION_COLOR
16
+ );
17
+ const popoverUi = { content: "z-[10000]" };
18
+ async function run(action) {
19
+ const id = props.field;
20
+ action.onClick();
21
+ if (id === void 0) return;
22
+ await nextTick();
23
+ refocusField(id);
24
+ }
25
+ const popoverContent = computed(() => ({
26
+ side: "bottom",
27
+ align: "start",
28
+ "aria-label": props.annotation.label
29
+ }));
30
+ </script>
31
+
32
+ <template>
33
+ <UPopover :content="popoverContent" :ui="popoverUi">
34
+ <!-- The label text is the accessible name; the dot only repeats it visually. -->
35
+ <UButton
36
+ :icon="icon"
37
+ :color="color"
38
+ :aria-label="annotation.label"
39
+ variant="ghost"
40
+ size="xs"
41
+ square
42
+ class="mapo-form-annotation relative p-0.5"
43
+ >
44
+ <span
45
+ v-if="annotation.dot"
46
+ class="absolute right-0 top-0 size-1.5 rounded-full bg-current"
47
+ aria-hidden="true"
48
+ />
49
+ </UButton>
50
+
51
+ <template #content>
52
+ <div class="max-w-xs space-y-2 p-3 text-sm">
53
+ <p class="font-medium text-highlighted">
54
+ {{ annotation.label }}
55
+ </p>
56
+ <slot name="body" :annotation="annotation">
57
+ <p v-if="annotation.description" class="text-muted">
58
+ {{ annotation.description }}
59
+ </p>
60
+ </slot>
61
+ <div v-if="annotation.actions?.length" class="flex flex-wrap gap-2">
62
+ <!-- Keyed by label: when an action changes the buttons, the one
63
+ under the focus is never reused for another action. The index
64
+ keeps two actions with one label apart. -->
65
+ <UButton
66
+ v-for="(action, index) in annotation.actions"
67
+ :key="`${action.label}-${index}`"
68
+ :label="action.label"
69
+ :icon="action.icon"
70
+ :color="action.color ?? 'neutral'"
71
+ variant="soft"
72
+ size="xs"
73
+ @click="run(action)"
74
+ />
75
+ </div>
76
+ </div>
77
+ </template>
78
+ </UPopover>
79
+ </template>
@@ -0,0 +1,27 @@
1
+ import type { FieldAnnotation } from "../types/index.js";
2
+ type __VLS_Props = {
3
+ /** The mark to show: icon and color on the button, texts and actions in the popover. */
4
+ annotation: FieldAnnotation;
5
+ /**
6
+ * The id of the field's control. After an action, a focus left on nothing
7
+ * goes back to the field: an action that takes the mark away, or changes
8
+ * the buttons, would drop it on the page. `MapoFormField` passes it.
9
+ */
10
+ field?: string;
11
+ };
12
+ type __VLS_Slots = {
13
+ /** Replaces the description, between the popover title and its actions. */
14
+ body?: (props: {
15
+ annotation: FieldAnnotation;
16
+ }) => unknown;
17
+ };
18
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
19
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
20
+ declare const _default: typeof __VLS_export;
21
+ export default _default;
22
+ type __VLS_WithSlots<T, S> = T & {
23
+ new (): {
24
+ $slots: S;
25
+ };
26
+ };
27
+ //# sourceMappingURL=MapoFormAnnotation.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapoFormAnnotation.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoFormAnnotation.vue"],"names":[],"mappings":"AAgIA,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,mBAAmB,CAAC;AAOhF,KAAK,WAAW,GAAG;IACjB,wFAAwF;IACxF,UAAU,EAAE,eAAe,CAAC;IAC5B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAGF,KAAK,WAAW,GAAG;IACjB,2EAA2E;IAC3E,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,UAAU,EAAE,eAAe,CAAA;KAAE,KAAK,OAAO,CAAC;CAC5D,CAAC;AA4LF,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"}
@@ -0,0 +1,28 @@
1
+ <script setup>
2
+ import { useI18n } from "vue-i18n";
3
+ defineProps({
4
+ groups: { type: Array, required: true },
5
+ size: { type: String, required: false, default: "sm" }
6
+ });
7
+ const { t } = useI18n();
8
+ </script>
9
+
10
+ <template>
11
+ <UBadge
12
+ v-for="group in groups"
13
+ :key="`${group.icon}|${group.color}`"
14
+ :icon="group.icon"
15
+ :color="group.color"
16
+ :label="group.count"
17
+ :size="size"
18
+ variant="subtle"
19
+ role="img"
20
+ :aria-label="
21
+ t(
22
+ 'mapo.form.annotationCount',
23
+ { n: group.count, labels: group.labels.join(', ') },
24
+ group.count
25
+ )
26
+ "
27
+ />
28
+ </template>
@@ -0,0 +1,13 @@
1
+ import type { AnnotationGroup } from "../utils/annotations.js";
2
+ type __VLS_Props = {
3
+ /** The groups to show, as `annotationGroups()` returns them. */
4
+ groups: AnnotationGroup[];
5
+ /** Badge size: `sm` on tabs, `xs` on repeater items. */
6
+ size?: "xs" | "sm";
7
+ };
8
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
9
+ size: "xs" | "sm";
10
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
13
+ //# sourceMappingURL=MapoFormAnnotationBadges.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapoFormAnnotationBadges.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoFormAnnotationBadges.vue"],"names":[],"mappings":"AAkDA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,KAAK,WAAW,GAAG;IACf,gEAAgE;IAChE,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,wDAAwD;IACxD,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACpB,CAAC;AAoEJ,QAAA,MAAM,YAAY;UArEP,IAAI,GAAG,IAAI;6EAwEpB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}