@mapomodule/uikit 2.0.0-beta.8 → 2.0.0-experimental.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/README.md +47 -174
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts +2 -0
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts +2 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts.map +1 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts +9 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts.map +1 -0
- package/dist/__tests__/formValues.test.d.ts +2 -0
- package/dist/__tests__/formValues.test.d.ts.map +1 -0
- package/dist/__tests__/langInfo.test.d.ts +2 -0
- package/dist/__tests__/langInfo.test.d.ts.map +1 -0
- package/dist/__tests__/listTable.test.d.ts +2 -0
- package/dist/__tests__/listTable.test.d.ts.map +1 -0
- package/dist/__tests__/mediaLanguages.test.d.ts +2 -0
- package/dist/__tests__/mediaLanguages.test.d.ts.map +1 -0
- package/dist/__tests__/runtimePages.test.d.ts +2 -0
- package/dist/__tests__/runtimePages.test.d.ts.map +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/module.d.mts +1 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +10 -0
- package/dist/runtime/assets/main.css +1 -1
- package/dist/runtime/components/MapoConfirmDialog.vue +18 -1
- package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetail.vue +263 -33
- package/dist/runtime/components/MapoDetail.vue.d.ts +191 -9
- package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetailExtensions.vue +24 -0
- package/dist/runtime/components/MapoDetailExtensions.vue.d.ts +15 -0
- package/dist/runtime/components/MapoDetailExtensions.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoDetailLangSwitch.vue +21 -25
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +4 -3
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDropArea.vue.d.ts +1 -1
- package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoList.vue +7 -3
- package/dist/runtime/components/MapoList.vue.d.ts +14 -4
- package/dist/runtime/components/MapoList.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListActions.vue +12 -5
- package/dist/runtime/components/MapoListActions.vue.d.ts +4 -0
- package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListQuickEdit.vue +1 -1
- package/dist/runtime/components/MapoListTable.vue +99 -33
- package/dist/runtime/components/MapoListTable.vue.d.ts +11 -6
- package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaEditor.vue +10 -4
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts +1 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaFileChanger.vue +1 -1
- package/dist/runtime/components/MapoMediaManager.vue +1 -1
- package/dist/runtime/components/MapoMediaManagerDialog.vue +1 -1
- package/dist/runtime/components/MapoMediaPreview.vue +1 -1
- package/dist/runtime/components/MapoMediaUploader.vue +21 -21
- package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMenuManager.vue +23 -3
- package/dist/runtime/components/MapoMenuManager.vue.d.ts +2 -2
- package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +1 -1
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +2 -2
- package/dist/runtime/components/MapoSnackBar.vue +11 -0
- package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -1
- package/dist/runtime/composables/defineDetailExtension.d.ts +32 -0
- package/dist/runtime/composables/defineDetailExtension.d.ts.map +1 -0
- package/dist/runtime/composables/defineDetailExtension.js +34 -0
- package/dist/runtime/composables/useMapoDetail.d.ts +18 -0
- package/dist/runtime/composables/useMapoDetail.d.ts.map +1 -0
- package/dist/runtime/composables/useMapoDetail.js +5 -0
- package/dist/runtime/page-meta.nuxt.d.ts +4 -0
- package/dist/runtime/stores/media.d.ts +8 -2
- package/dist/runtime/stores/media.d.ts.map +1 -1
- package/dist/runtime/stores/media.js +16 -0
- package/dist/runtime/types/detail.d.ts +167 -0
- package/dist/runtime/types/detail.d.ts.map +1 -0
- package/dist/runtime/types/detail.js +0 -0
- package/dist/runtime/types/list.d.ts +10 -2
- package/dist/runtime/types/list.d.ts.map +1 -1
- package/dist/runtime/utils/formValues.d.ts +8 -0
- package/dist/runtime/utils/formValues.d.ts.map +1 -0
- package/dist/runtime/utils/formValues.js +19 -0
- package/dist/runtime/utils/langInfo.d.ts +30 -0
- package/dist/runtime/utils/langInfo.d.ts.map +1 -0
- package/dist/runtime/utils/langInfo.js +8 -0
- package/dist/runtime/utils/listTable.d.ts +29 -0
- package/dist/runtime/utils/listTable.d.ts.map +1 -0
- package/dist/runtime/utils/listTable.js +21 -0
- package/package.json +7 -8
- package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
- package/src/__tests__/MapoDetail.component.test.ts +1107 -0
- package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
- package/src/__tests__/MapoListActions.component.test.ts +175 -0
- package/src/__tests__/MapoListTable.component.test.ts +504 -0
- package/src/__tests__/MapoSnackBar.component.test.ts +79 -0
- package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
- package/src/__tests__/formValues.test.ts +31 -0
- package/src/__tests__/langInfo.test.ts +48 -0
- package/src/__tests__/listTable.test.ts +82 -0
- package/src/__tests__/mediaLanguages.test.ts +66 -0
- package/src/__tests__/runtimePages.test.ts +17 -0
- package/src/index.ts +8 -0
- package/src/module.ts +12 -0
- package/src/runtime/assets/main.css +13 -0
- package/src/runtime/components/MapoConfirmDialog.vue +28 -1
- package/src/runtime/components/MapoDetail.vue +481 -53
- package/src/runtime/components/MapoDetailExtensions.vue +39 -0
- package/src/runtime/components/MapoDetailLangSwitch.vue +26 -27
- package/src/runtime/components/MapoList.vue +20 -5
- package/src/runtime/components/MapoListActions.vue +16 -4
- package/src/runtime/components/MapoListTable.vue +128 -41
- package/src/runtime/components/MapoMediaEditor.vue +17 -4
- package/src/runtime/components/MapoMediaUploader.vue +25 -21
- package/src/runtime/components/MapoMenuManager.vue +38 -3
- package/src/runtime/components/MapoSnackBar.vue +12 -0
- package/src/runtime/composables/defineDetailExtension.ts +78 -0
- package/src/runtime/composables/useMapoDetail.ts +24 -0
- package/src/runtime/page-meta.nuxt.d.ts +4 -0
- package/src/runtime/stores/media.ts +32 -0
- package/src/runtime/types/detail.ts +178 -0
- package/src/runtime/types/list.ts +10 -2
- package/src/runtime/utils/formValues.ts +28 -0
- package/src/runtime/utils/langInfo.ts +38 -0
- package/src/runtime/utils/listTable.ts +54 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { Component, ComputedRef, Ref } from "vue";
|
|
2
|
+
import type { AnyFieldDescriptor, FieldAnnotations, FieldRegistry } from "@mapomodule/form/types";
|
|
3
|
+
import type { JSONSchema } from "@mapomodule/utils";
|
|
4
|
+
/**
|
|
5
|
+
* What `MapoDetail` shares with the components inside it: its slots, its forms
|
|
6
|
+
* and the extensions it renders. Read it with `useMapoDetail()`.
|
|
7
|
+
*/
|
|
8
|
+
export interface MapoDetailContext<T extends object = Record<string, unknown>> {
|
|
9
|
+
/** The REST endpoint of the record. */
|
|
10
|
+
endpoint: ComputedRef<string>;
|
|
11
|
+
/** The record id; `"new"` for a record not created yet. */
|
|
12
|
+
id: ComputedRef<string | number>;
|
|
13
|
+
isNew: ComputedRef<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* The name of the record's model for people, as the page titles it
|
|
16
|
+
* (`modelName`): "Article"; `null` without one. `MapoDetail` always gives
|
|
17
|
+
* it; optional, so a context built elsewhere, as a test's, still compiles.
|
|
18
|
+
*/
|
|
19
|
+
modelName?: ComputedRef<string | null>;
|
|
20
|
+
/**
|
|
21
|
+
* The backend model the page checks the permissions of (`permissionModel`):
|
|
22
|
+
* `article`; `undefined` without one. `MapoDetail` always gives it;
|
|
23
|
+
* optional, as `modelName`.
|
|
24
|
+
*/
|
|
25
|
+
permissionModel?: ComputedRef<string | undefined>;
|
|
26
|
+
/** The record being edited: write to it to change the values of the form. */
|
|
27
|
+
model: Ref<T>;
|
|
28
|
+
/** The body fields rendered: the `fields` prop, or the ones derived from the schema. */
|
|
29
|
+
fields: ComputedRef<AnyFieldDescriptor<T>[]>;
|
|
30
|
+
/** The sidebar fields rendered. */
|
|
31
|
+
sidebarFields: ComputedRef<AnyFieldDescriptor<T>[]>;
|
|
32
|
+
/** The languages of the record; empty when it is not translated. */
|
|
33
|
+
languages: ComputedRef<string[]>;
|
|
34
|
+
/** The language being edited: write to it to switch. */
|
|
35
|
+
currentLang: Ref<string>;
|
|
36
|
+
/** The field registry the forms use. */
|
|
37
|
+
registry: ComputedRef<FieldRegistry>;
|
|
38
|
+
/** Server errors by field path, as the last save returned them. */
|
|
39
|
+
errors: Readonly<Ref<Record<string, string[]>>>;
|
|
40
|
+
/** Whether the record is read-only for this user. */
|
|
41
|
+
readonly: ComputedRef<boolean>;
|
|
42
|
+
/** While the record loads. */
|
|
43
|
+
isLoading: Readonly<Ref<boolean>>;
|
|
44
|
+
/** From a save until it is done; after `save(true)`, until the page has gone back. */
|
|
45
|
+
isSaving: ComputedRef<boolean>;
|
|
46
|
+
/** While a save, a delete or a navigation back is under way. */
|
|
47
|
+
isBusy: ComputedRef<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the model differs from the record as loaded or last saved; for
|
|
50
|
+
* a new record, whether it holds a value it did not hold when the page
|
|
51
|
+
* opened (a blank text, an empty list or an empty object is none).
|
|
52
|
+
*/
|
|
53
|
+
isDirty: ComputedRef<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* Marks set from inside the detail, shown with those of the `annotations`
|
|
56
|
+
* prop; on the same path the prop wins. Replace the map to change them.
|
|
57
|
+
*/
|
|
58
|
+
annotations: Ref<FieldAnnotations>;
|
|
59
|
+
/** Which extensions the page allows: all, none, or the listed keys. */
|
|
60
|
+
extensions: ComputedRef<boolean | readonly string[]>;
|
|
61
|
+
/** Saves the record, as the Save buttons do; ignored while busy. */
|
|
62
|
+
save: (andBack?: boolean) => Promise<void>;
|
|
63
|
+
/** Goes back, as the Back button does; ignored while busy. */
|
|
64
|
+
back: () => void;
|
|
65
|
+
/**
|
|
66
|
+
* The endpoint's `OPTIONS` response, requested once per page and shared
|
|
67
|
+
* with `MapoDetail`, or `undefined` when the endpoint has none.
|
|
68
|
+
*/
|
|
69
|
+
metadata: () => Promise<Record<string, unknown> | undefined>;
|
|
70
|
+
/**
|
|
71
|
+
* How the page turns the `OPTIONS` response into a JSON Schema
|
|
72
|
+
* (`schemaFromMetadata`), when it has its own way; `undefined`: Mapo's
|
|
73
|
+
* `metadataToJsonSchema`. `MapoDetail` always gives it; optional, as
|
|
74
|
+
* `modelName`.
|
|
75
|
+
*/
|
|
76
|
+
schemaFromMetadata?: ComputedRef<((metadata: Record<string, unknown>) => JSONSchema | undefined) | undefined>;
|
|
77
|
+
/**
|
|
78
|
+
* Calls `handler` after each save that succeeds, with the record as the
|
|
79
|
+
* backend returned it, before the page moves to a new record's address
|
|
80
|
+
* or goes back. Returns the function that removes it; one registered in
|
|
81
|
+
* a component's setup goes with the component. A handler that throws
|
|
82
|
+
* leaves the save done. `MapoDetail` always gives it; optional, as
|
|
83
|
+
* `modelName`.
|
|
84
|
+
*/
|
|
85
|
+
onSaved?: (handler: (record: T) => void) => () => void;
|
|
86
|
+
/**
|
|
87
|
+
* The detail's draft, for a component that keeps a state of its own
|
|
88
|
+
* beside the record's values: it is saved, restored, discarded and
|
|
89
|
+
* cleared with them. With drafts off nothing is kept. `MapoDetail` always
|
|
90
|
+
* gives it; optional, as `modelName`.
|
|
91
|
+
*/
|
|
92
|
+
draft?: MapoDetailDraft;
|
|
93
|
+
/**
|
|
94
|
+
* Takes the operator to a field: the form that holds it, the body's or
|
|
95
|
+
* the sidebar's, opens its tab, group or sub-tab and repeater item,
|
|
96
|
+
* scrolls the field into view and puts the focus on its control. The
|
|
97
|
+
* path is the one of its mark: `title`, `translations.it.title`,
|
|
98
|
+
* `blocks.0.title`. Resolves whether the control took the focus: `false`
|
|
99
|
+
* for a field no form has or shows. `MapoDetail` always gives it;
|
|
100
|
+
* optional, as `modelName`.
|
|
101
|
+
*/
|
|
102
|
+
revealField?: (path: string) => Promise<boolean>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A part of the detail's draft: the state of a component inside it, saved
|
|
106
|
+
* and restored with the record's values.
|
|
107
|
+
*/
|
|
108
|
+
export interface MapoDetailDraftPart {
|
|
109
|
+
/**
|
|
110
|
+
* What to keep, as data `JSON.stringify()` can write; `undefined` when
|
|
111
|
+
* there is nothing. Called each time the draft is saved; a part that
|
|
112
|
+
* throws is left out of that save.
|
|
113
|
+
*/
|
|
114
|
+
save: () => unknown;
|
|
115
|
+
/**
|
|
116
|
+
* Puts back what `save()` returned, when the operator restores the
|
|
117
|
+
* draft, after the record's values; `undefined` when the draft holds
|
|
118
|
+
* nothing for the part, which then starts again from nothing. It comes
|
|
119
|
+
* from the browser's storage: read it as outside data.
|
|
120
|
+
*/
|
|
121
|
+
restore: (data: unknown) => void;
|
|
122
|
+
}
|
|
123
|
+
/** The draft of a `MapoDetail`, for the components inside it. */
|
|
124
|
+
export interface MapoDetailDraft {
|
|
125
|
+
/**
|
|
126
|
+
* Keeps a part of the draft under `key`, one per detail: registering the
|
|
127
|
+
* key again replaces the part. The draft is saved when the record changed
|
|
128
|
+
* or a part has something to keep. A part registered after the draft was
|
|
129
|
+
* restored gets its data then. Returns the function that removes it; one
|
|
130
|
+
* registered in a component's setup goes with the component.
|
|
131
|
+
*/
|
|
132
|
+
part: (key: string, part: MapoDetailDraftPart) => () => void;
|
|
133
|
+
/**
|
|
134
|
+
* Saves the draft soon, after a change of a part's state: a change of
|
|
135
|
+
* the record's values saves it by itself.
|
|
136
|
+
*/
|
|
137
|
+
touch: () => void;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Where `MapoDetail` renders an extension: `actions`, the sidebar card above
|
|
141
|
+
* Save; `body-top`, above the body form.
|
|
142
|
+
*/
|
|
143
|
+
export type DetailExtensionPlacement = "actions" | "body-top";
|
|
144
|
+
/** A component that loads another: `() => import("./MyAction.vue")`. */
|
|
145
|
+
export type DetailExtensionLoader = () => Promise<Component | {
|
|
146
|
+
default: Component;
|
|
147
|
+
}>;
|
|
148
|
+
/** A component added to every `MapoDetail`, registered with `defineDetailExtension()`. */
|
|
149
|
+
export interface DetailExtension {
|
|
150
|
+
/**
|
|
151
|
+
* Names the extension. A page picks extensions by key with the `extensions`
|
|
152
|
+
* prop, and registering a key again replaces the extension.
|
|
153
|
+
*/
|
|
154
|
+
key: string;
|
|
155
|
+
/** Where the detail renders it. */
|
|
156
|
+
placement: DetailExtensionPlacement;
|
|
157
|
+
/**
|
|
158
|
+
* The component, or a loader of it. It reads the detail with
|
|
159
|
+
* `useMapoDetail()`. A function is always taken as a loader.
|
|
160
|
+
*/
|
|
161
|
+
component: Component | DetailExtensionLoader;
|
|
162
|
+
/** Whether a detail page shows it. Default: always. */
|
|
163
|
+
visible?: (detail: MapoDetailContext) => boolean;
|
|
164
|
+
/** Order among the extensions of a placement, lower first. Default: `0`. */
|
|
165
|
+
order?: number;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=detail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detail.d.ts","sourceRoot":"","sources":["../../../src/runtime/types/detail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AACvD,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;GAGG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC3E,uCAAuC;IACvC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC9B,2DAA2D;IAC3D,EAAE,EAAE,WAAW,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IACjC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5B;;;;OAIG;IACH,SAAS,CAAC,EAAE,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACvC;;;;OAIG;IACH,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAClD,6EAA6E;IAC7E,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IACd,wFAAwF;IACxF,MAAM,EAAE,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7C,mCAAmC;IACnC,aAAa,EAAE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AM,CAAC;CAChB"}
|
|
File without changes
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
/** Defines a single column in the list table. */
|
|
2
2
|
export interface ListColumn<T = Record<string, unknown>> {
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Property of the row to show, a key of `T`. A dotted path (`category.name`)
|
|
5
|
+
* reads a field of a related object; it starts with a key of `T`.
|
|
6
|
+
*/
|
|
7
|
+
key: (keyof T & string) | `${keyof T & string}.${string}`;
|
|
5
8
|
label: string;
|
|
9
|
+
/**
|
|
10
|
+
* Turns the header into a button that cycles ascending, descending and
|
|
11
|
+
* unsorted. The list sends the order to the backend as `ordering`, or sorts
|
|
12
|
+
* in memory in offline and hybrid mode.
|
|
13
|
+
*/
|
|
6
14
|
sortable?: boolean;
|
|
7
15
|
/** CSS class applied to the `<td>` cell. */
|
|
8
16
|
class?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/runtime/types/list.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACrD
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/runtime/types/list.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACrD;;;OAGG;IACH,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,2DAA2D;AAC3D,MAAM,WAAW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7E,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a form's value holds something: not `undefined` or `null`, not a
|
|
3
|
+
* blank text (the empty paragraphs and line breaks of a rich text editor
|
|
4
|
+
* included), not an empty list, not an object whose values all hold
|
|
5
|
+
* nothing. `false`, `0` and any other object, such as a file, are values.
|
|
6
|
+
*/
|
|
7
|
+
export declare function holdsFormValue(value: unknown): boolean;
|
|
8
|
+
//# sourceMappingURL=formValues.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formValues.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils/formValues.ts"],"names":[],"mappings":"AAYA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAStD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const BLANK_MARKUP = /<\/?p>|<br\s*\/?>| /gi;
|
|
2
|
+
function isPlainObject(value) {
|
|
3
|
+
if (typeof value !== "object") return false;
|
|
4
|
+
if (value === null) return false;
|
|
5
|
+
const prototype = Object.getPrototypeOf(value);
|
|
6
|
+
const isLiteral = prototype === Object.prototype;
|
|
7
|
+
const isBare = prototype === null;
|
|
8
|
+
return isLiteral || isBare;
|
|
9
|
+
}
|
|
10
|
+
export function holdsFormValue(value) {
|
|
11
|
+
if (value === void 0) return false;
|
|
12
|
+
if (value === null) return false;
|
|
13
|
+
if (typeof value === "string") {
|
|
14
|
+
return value.replace(BLANK_MARKUP, " ").trim() !== "";
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
17
|
+
if (isPlainObject(value)) return Object.values(value).some(holdsFormValue);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `lang_info`, as served by Camomilla on an endpoint's OPTIONS response.
|
|
3
|
+
*
|
|
4
|
+
* It describes the MODEL, not the site and not a record: a multilingual site can
|
|
5
|
+
* still expose models nobody registered for translation, and rendering a
|
|
6
|
+
* language switcher for those invites the user to type values the backend will
|
|
7
|
+
* drop on save.
|
|
8
|
+
*
|
|
9
|
+
* OPTIONS rather than the record payload because it is metadata, and because a
|
|
10
|
+
* "create new" form has no record to read it from.
|
|
11
|
+
*/
|
|
12
|
+
export interface LangInfo {
|
|
13
|
+
/** Whether this model is registered for translation at all. */
|
|
14
|
+
translatable?: boolean;
|
|
15
|
+
/** Codes usable for THIS model. Empty when it is not translatable. */
|
|
16
|
+
languages?: string[];
|
|
17
|
+
/** What the site supports. Present for context; not model-specific. */
|
|
18
|
+
site_languages?: string[];
|
|
19
|
+
default?: string;
|
|
20
|
+
active?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Language codes a model can be translated into, read from its OPTIONS metadata.
|
|
24
|
+
*
|
|
25
|
+
* Returns `[]` — meaning "render no language switcher" — when the model is not
|
|
26
|
+
* translatable and when `lang_info` is absent entirely. A backend that does not
|
|
27
|
+
* publish the field cannot be assumed multilingual.
|
|
28
|
+
*/
|
|
29
|
+
export declare function languagesFromMetadata(metadata: unknown): string[];
|
|
30
|
+
//# sourceMappingURL=langInfo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langInfo.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils/langInfo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,QAAQ;IACvB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,uEAAuE;IACvE,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,EAAE,CAQjE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function languagesFromMetadata(metadata) {
|
|
2
|
+
const info = metadata?.lang_info;
|
|
3
|
+
if (!info || info.translatable === false) return [];
|
|
4
|
+
if (!Array.isArray(info.languages)) return [];
|
|
5
|
+
return info.languages.filter(
|
|
6
|
+
(code) => typeof code === "string"
|
|
7
|
+
);
|
|
8
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** One sort key as `UTable` holds it: the column id and the direction. */
|
|
2
|
+
export interface TableSort {
|
|
3
|
+
id: string;
|
|
4
|
+
desc: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The page size that stands for "all rows". A plain number, so the paging
|
|
8
|
+
* arithmetic and the in-memory slicing keep working unchanged.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ALL_ROWS: number;
|
|
11
|
+
/** A `pageSizeOptions` entry as the table stores it: `"all"` → {@link ALL_ROWS}. */
|
|
12
|
+
export declare function toPageSize(option: number | "all"): number;
|
|
13
|
+
/** Reads `page_size` from the URL: `all`, or a positive number, else `fallback`. */
|
|
14
|
+
export declare function parsePageSize(value: unknown, fallback: number): number;
|
|
15
|
+
/** Writes a page size to the URL: {@link ALL_ROWS} as `all`. */
|
|
16
|
+
export declare function formatPageSize(size: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* The sorting after a click on a sortable header. The column goes from
|
|
19
|
+
* unsorted to ascending, to descending, and back to unsorted, so the natural
|
|
20
|
+
* order (needed by drag reorder) is one click away. It replaces any other key.
|
|
21
|
+
*/
|
|
22
|
+
export declare function nextSorting(sorting: TableSort[], columnId: string): TableSort[];
|
|
23
|
+
/**
|
|
24
|
+
* The `ordering` param for a sorting: comma-separated keys, `-` for descending.
|
|
25
|
+
* A dotted key becomes a Django lookup (`category.name` → `category__name`),
|
|
26
|
+
* the way DRF's OrderingFilter reaches a field of a related object.
|
|
27
|
+
*/
|
|
28
|
+
export declare function orderingParam(sorting: TableSort[]): string;
|
|
29
|
+
//# sourceMappingURL=listTable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listTable.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils/listTable.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,QAA0B,CAAC;AAEhD,oFAAoF;AACpF,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,CAEzD;AAED,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAItE;AAED,gEAAgE;AAChE,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,SAAS,EAAE,EACpB,QAAQ,EAAE,MAAM,GACf,SAAS,EAAE,CAKb;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,CAI1D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const ALL_ROWS = Number.MAX_SAFE_INTEGER;
|
|
2
|
+
export function toPageSize(option) {
|
|
3
|
+
return option === "all" ? ALL_ROWS : option;
|
|
4
|
+
}
|
|
5
|
+
export function parsePageSize(value, fallback) {
|
|
6
|
+
if (value === "all") return ALL_ROWS;
|
|
7
|
+
const size = Number(value);
|
|
8
|
+
return Number.isFinite(size) && size > 0 ? size : fallback;
|
|
9
|
+
}
|
|
10
|
+
export function formatPageSize(size) {
|
|
11
|
+
return size === ALL_ROWS ? "all" : String(size);
|
|
12
|
+
}
|
|
13
|
+
export function nextSorting(sorting, columnId) {
|
|
14
|
+
const current = sorting.find((sort) => sort.id === columnId);
|
|
15
|
+
if (!current) return [{ id: columnId, desc: false }];
|
|
16
|
+
if (!current.desc) return [{ id: columnId, desc: true }];
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
export function orderingParam(sorting) {
|
|
20
|
+
return sorting.map((sort) => `${sort.desc ? "-" : ""}${sort.id.split(".").join("__")}`).join(",");
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapomodule/uikit",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-experimental.1",
|
|
4
4
|
"description": "Mapo UI components: Sidebar, Topbar, Login, SnackBar, ConfirmDialog, List, Detail, Media",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,20 +40,19 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "nuxt-module-build build && vue-tsc -p tsconfig.build-types.json && node ../../../scripts/clean-empty-vue-dts.mjs dist",
|
|
42
42
|
"dev": "nuxt-module-build build --stub --watch",
|
|
43
|
-
"prepack": "pnpm build",
|
|
44
43
|
"dev:prepare": "nuxt-module-build build --stub",
|
|
45
44
|
"typecheck": "vue-tsc --noEmit",
|
|
46
45
|
"lint": "eslint src"
|
|
47
46
|
},
|
|
48
47
|
"dependencies": {
|
|
49
|
-
"@mapomodule/form": "2.0.0-
|
|
50
|
-
"@mapomodule/i18n": "
|
|
51
|
-
"@mapomodule/store": "2.0.0-
|
|
52
|
-
"@mapomodule/utils": "2.0.0-
|
|
53
|
-
"@mapomodule/core": "2.0.0-
|
|
48
|
+
"@mapomodule/form": "2.0.0-experimental.1",
|
|
49
|
+
"@mapomodule/i18n": "2.0.0-experimental.1",
|
|
50
|
+
"@mapomodule/store": "2.0.0-experimental.1",
|
|
51
|
+
"@mapomodule/utils": "2.0.0-experimental.1",
|
|
52
|
+
"@mapomodule/core": "2.0.0-experimental.1",
|
|
54
53
|
"tailwindcss": "^4.0.0",
|
|
55
54
|
"vue-draggable-plus": "^0.6.0",
|
|
56
|
-
"vue-i18n": "^11.4.
|
|
55
|
+
"vue-i18n": "^11.4.8"
|
|
57
56
|
},
|
|
58
57
|
"peerDependencies": {
|
|
59
58
|
"@nuxt/ui": ">=4.0.0",
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { createRenderer, h, nextTick, onUnmounted, ref } from "vue";
|
|
3
|
+
import type { App, Component, SetupContext } from "vue";
|
|
4
|
+
import { createPinia, setActivePinia } from "pinia";
|
|
5
|
+
import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
|
|
6
|
+
|
|
7
|
+
import MapoConfirmDialog from "../runtime/components/MapoConfirmDialog.vue";
|
|
8
|
+
|
|
9
|
+
vi.mock("vue-i18n", () => ({ useI18n: () => ({ t: (key: string) => key }) }));
|
|
10
|
+
|
|
11
|
+
// Tests run in Node without a DOM. A renderer whose nodes are plain objects is
|
|
12
|
+
// enough to mount the component with real reactivity, watchers and events.
|
|
13
|
+
interface HeadlessNode {
|
|
14
|
+
parent: HeadlessNode | null;
|
|
15
|
+
children: HeadlessNode[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const headlessNode = (): HeadlessNode => ({ parent: null, children: [] });
|
|
19
|
+
|
|
20
|
+
const { createApp } = createRenderer<HeadlessNode, HeadlessNode>({
|
|
21
|
+
createElement: headlessNode,
|
|
22
|
+
createText: headlessNode,
|
|
23
|
+
createComment: headlessNode,
|
|
24
|
+
setText: () => {},
|
|
25
|
+
setElementText: () => {},
|
|
26
|
+
patchProp: () => {},
|
|
27
|
+
insert(child, parent, anchor) {
|
|
28
|
+
child.parent = parent;
|
|
29
|
+
const at = anchor ? parent.children.indexOf(anchor) : -1;
|
|
30
|
+
parent.children.splice(at < 0 ? parent.children.length : at, 0, child);
|
|
31
|
+
},
|
|
32
|
+
remove(child) {
|
|
33
|
+
child.parent?.children.splice(child.parent.children.indexOf(child), 1);
|
|
34
|
+
child.parent = null;
|
|
35
|
+
},
|
|
36
|
+
parentNode: (node) => node.parent,
|
|
37
|
+
nextSibling: (node) =>
|
|
38
|
+
node.parent?.children[node.parent.children.indexOf(node) + 1] ?? null,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const passthrough = (name: string): Component => ({
|
|
42
|
+
name,
|
|
43
|
+
inheritAttrs: false,
|
|
44
|
+
setup(_props: unknown, { slots }: SetupContext) {
|
|
45
|
+
return () => h("div", null, slots.default?.());
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Nuxt UI overlays have no z-index: they stack in the order their portals enter
|
|
50
|
+
// <body>, which is the order the overlays mount. The stubs record that order.
|
|
51
|
+
const mountOrder: string[] = [];
|
|
52
|
+
|
|
53
|
+
// `UModal` declares what the dialog binds: `open` in, and `after:leave` out once
|
|
54
|
+
// the close animation has ended.
|
|
55
|
+
let modal: { readonly open: boolean | undefined; finishLeave(): void } | null =
|
|
56
|
+
null;
|
|
57
|
+
|
|
58
|
+
const UModal: Component = {
|
|
59
|
+
name: "UModal",
|
|
60
|
+
props: { open: Boolean, dismissible: Boolean },
|
|
61
|
+
emits: ["after:leave"],
|
|
62
|
+
setup(props: { open?: boolean }, { emit }: SetupContext<["after:leave"]>) {
|
|
63
|
+
mountOrder.push("confirm");
|
|
64
|
+
modal = {
|
|
65
|
+
get open() {
|
|
66
|
+
return props.open;
|
|
67
|
+
},
|
|
68
|
+
finishLeave: () => emit("after:leave"),
|
|
69
|
+
};
|
|
70
|
+
onUnmounted(() => {
|
|
71
|
+
modal = null;
|
|
72
|
+
});
|
|
73
|
+
return () => h("div");
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// An overlay that a page opens once the layout is already there, like the media
|
|
78
|
+
// editor drawer.
|
|
79
|
+
const Drawer: Component = {
|
|
80
|
+
name: "Drawer",
|
|
81
|
+
setup() {
|
|
82
|
+
mountOrder.push("drawer");
|
|
83
|
+
return () => h("div");
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const drawerOpen = ref(false);
|
|
88
|
+
|
|
89
|
+
let app: App<HeadlessNode> | undefined;
|
|
90
|
+
|
|
91
|
+
/** Mounts the dialog the way the layout does; returns the store that drives it. */
|
|
92
|
+
function mountLayout() {
|
|
93
|
+
const pinia = createPinia();
|
|
94
|
+
setActivePinia(pinia);
|
|
95
|
+
const root: Component = {
|
|
96
|
+
// The page comes first, then the root components, as in `mapo-default`.
|
|
97
|
+
render: () => [
|
|
98
|
+
drawerOpen.value ? h(Drawer) : null,
|
|
99
|
+
h(MapoConfirmDialog as Component),
|
|
100
|
+
],
|
|
101
|
+
};
|
|
102
|
+
app = createApp(root);
|
|
103
|
+
app.use(pinia);
|
|
104
|
+
app.component("UModal", UModal);
|
|
105
|
+
app.component("UButton", passthrough("UButton"));
|
|
106
|
+
app.mount(headlessNode());
|
|
107
|
+
return useConfirmStore();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
beforeEach(() => {
|
|
111
|
+
mountOrder.length = 0;
|
|
112
|
+
drawerOpen.value = false;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
afterEach(() => {
|
|
116
|
+
app?.unmount();
|
|
117
|
+
app = undefined;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("MapoConfirmDialog", () => {
|
|
121
|
+
it("opens above an overlay the page opened after the layout", async () => {
|
|
122
|
+
const confirm = mountLayout();
|
|
123
|
+
drawerOpen.value = true;
|
|
124
|
+
await nextTick();
|
|
125
|
+
|
|
126
|
+
void confirm.ask({ message: "Delete?" });
|
|
127
|
+
await nextTick();
|
|
128
|
+
|
|
129
|
+
expect(modal?.open).toBe(true);
|
|
130
|
+
expect(mountOrder).toEqual(["drawer", "confirm"]);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("stays mounted until its close animation has ended", async () => {
|
|
134
|
+
const confirm = mountLayout();
|
|
135
|
+
const answer = confirm.ask({ message: "Delete?" });
|
|
136
|
+
await nextTick();
|
|
137
|
+
|
|
138
|
+
confirm.confirm();
|
|
139
|
+
await nextTick();
|
|
140
|
+
|
|
141
|
+
expect(modal?.open).toBe(false);
|
|
142
|
+
modal?.finishLeave();
|
|
143
|
+
await nextTick();
|
|
144
|
+
|
|
145
|
+
expect(modal).toBeNull();
|
|
146
|
+
await expect(answer).resolves.toBe(true);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("stays open when asked again while it was closing", async () => {
|
|
150
|
+
const confirm = mountLayout();
|
|
151
|
+
void confirm.ask({ message: "First?" });
|
|
152
|
+
await nextTick();
|
|
153
|
+
confirm.cancel();
|
|
154
|
+
await nextTick();
|
|
155
|
+
const closing = modal;
|
|
156
|
+
|
|
157
|
+
void confirm.ask({ message: "Second?" });
|
|
158
|
+
await nextTick();
|
|
159
|
+
// The first close animation reports its end after the second question.
|
|
160
|
+
closing?.finishLeave();
|
|
161
|
+
await nextTick();
|
|
162
|
+
|
|
163
|
+
expect(modal?.open).toBe(true);
|
|
164
|
+
});
|
|
165
|
+
});
|