@mittwald/flow-remote-vue-components 1.5.40 → 1.5.42
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 +2 -2
- package/dist/js/components-base/src/index.mjs +2 -1
- package/dist/js/components-base/src/overlay/OverlayState.mjs +176 -0
- package/dist/js/components-base/src/overlay/OverlayState.mjs.map +1 -0
- package/dist/js/remote-vue-components/src/components/Action.mjs +1 -1
- package/dist/js/remote-vue-components/src/overlays/Modal.mjs +14 -18
- package/dist/js/remote-vue-components/src/overlays/Modal.mjs.map +1 -1
- package/dist/js/remote-vue-components/src/overlays/overlayController.mjs +57 -63
- package/dist/js/remote-vue-components/src/overlays/overlayController.mjs.map +1 -1
- package/dist/js/remote-vue-components/src/version.mjs +1 -1
- package/dist/types/_bundled/flow-components-base/index.d.ts +1 -0
- package/dist/types/_bundled/flow-components-base/overlay/OverlayState.d.ts +90 -0
- package/dist/types/overlays/Modal.d.ts +2 -2
- package/dist/types/overlays/overlayController.d.ts +28 -18
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -127,10 +127,9 @@ themselves. They cannot be generated, so this package rebuilds them in Vue:
|
|
|
127
127
|
| Component | The rebuild |
|
|
128
128
|
| --------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
|
|
129
129
|
| `Modal`, `Popover`, `LightBox` | render `OverlayContent` / `PopoverContent` with Flow's own classes, and configure their children |
|
|
130
|
-
| `Modal confirmOnClose` | a confirmation modal
|
|
130
|
+
| `Modal confirmOnClose` | a confirmation modal with its own controller, opened while the parent asks; its own copy of the texts |
|
|
131
131
|
| `IconSetProvider` | provide/inject; its `IconSet` is partial, because there is no complete second set to hand it |
|
|
132
132
|
| `ModalTrigger`, `PopoverTrigger`, `LightBoxTrigger` | a `DialogTrigger` whose `Button` (also inside an `Action`) gets the `onPress` that opens it |
|
|
133
|
-
| `useOverlayController`, `useModalController` | a `ref` plus `provide`/`inject`; given a type, the surrounding overlay's controller, as in Flow |
|
|
134
133
|
| `Action`, `ActionBatch` | run, report pending/succeeded/failed on the button, close the overlay |
|
|
135
134
|
| `NotificationProvider`, `useNotificationController` | a reactive list, with the auto-close timer that pauses on hover and focus |
|
|
136
135
|
| `DeprecationWarningProvider`, `useWarnDeprecation` | provide/inject; `RemoteRoot` forwards to the host |
|
|
@@ -138,6 +137,7 @@ themselves. They cannot be generated, so this package rebuilds them in Vue:
|
|
|
138
137
|
| `CountryOptions` | `Option`s from `country-codes-list`, named by `Intl.DisplayNames` |
|
|
139
138
|
| `Wrap`, `BrowserOnly` | the same two-line components |
|
|
140
139
|
| `List`, `ListItemView` | the arrangement around `@mittwald/flow-components-base`, plus the batch loading |
|
|
140
|
+
| `useOverlayController`, `useModalController` | refs over the shared `OverlayState`; given a type, the surrounding overlay's controller, as in Flow |
|
|
141
141
|
| `useIsMounted`, `useOnChange`, `useLanguage` | composables |
|
|
142
142
|
| `useListMetadata` | what the list's loader sent beside its data |
|
|
143
143
|
| `Form` | `flr-form` has no Flow component behind it, so the generator never sees it |
|
|
@@ -14,4 +14,5 @@ import { ListSearch } from "./list/search/ListSearch.mjs";
|
|
|
14
14
|
import { ListSorting, mergeHiddenSorting } from "./list/sorting/ListSorting.mjs";
|
|
15
15
|
import { ListTable } from "./list/table/ListTable.mjs";
|
|
16
16
|
import { ListViewMode } from "./list/viewMode/ListViewMode.mjs";
|
|
17
|
-
|
|
17
|
+
import { OverlayState } from "./overlay/OverlayState.mjs";
|
|
18
|
+
export { ActionState, ListBatchesController, ListDateRangeFilter, ListFilter, ListItemCollection, ListLoaderState, ListSearch, ListSorting, ListTable, ListViewMode, OverlayState, getListDataLoaderOptions, mergeHiddenSorting };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { action, computed, makeObservable, observable, runInAction } from "mobx";
|
|
2
|
+
//#region ../components-base/src/overlay/OverlayState.ts
|
|
3
|
+
/**
|
|
4
|
+
* Whether an overlay is open, and whether closing it has to be confirmed first.
|
|
5
|
+
* Each binding adds its subscription and its lifecycle: React's
|
|
6
|
+
* `OverlayController` subclasses it, Vue's adapter wraps it in refs.
|
|
7
|
+
*
|
|
8
|
+
* `TCloseOptions` lets a binding pass more on a close than the state reads —
|
|
9
|
+
* React's `overlay`, resolved by `Action` before the close arrives here.
|
|
10
|
+
*/
|
|
11
|
+
var OverlayState = class {
|
|
12
|
+
isOpen = false;
|
|
13
|
+
isContentSuspended = false;
|
|
14
|
+
onOpenHandlers = /* @__PURE__ */ new Set();
|
|
15
|
+
onCloseHandlers = /* @__PURE__ */ new Set();
|
|
16
|
+
onOpenChangeHandlers = /* @__PURE__ */ new Set();
|
|
17
|
+
showConfirmationModal = false;
|
|
18
|
+
closeIsConfirmed = false;
|
|
19
|
+
confirmOnCloseFromOptions;
|
|
20
|
+
/**
|
|
21
|
+
* Every mounted component that has an opinion on close confirmation
|
|
22
|
+
* contributes one entry here – e.g. a `Modal` with a `confirmOnClose` prop
|
|
23
|
+
* and a `Form` tracking its dirty state. Combining them instead of assigning
|
|
24
|
+
* a single flag keeps them from overwriting each other.
|
|
25
|
+
*/
|
|
26
|
+
confirmOnCloseSources = observable.map();
|
|
27
|
+
/**
|
|
28
|
+
* Active grants that allow closing without a confirmation. Each entry is
|
|
29
|
+
* scoped to an ongoing operation that legitimately closes the overlay – e.g.
|
|
30
|
+
* a `Form` submit – and is dropped again when that operation has finished, so
|
|
31
|
+
* an operation that does _not_ close the overlay leaves the confirmation
|
|
32
|
+
* armed.
|
|
33
|
+
*/
|
|
34
|
+
closeWithoutConfirmationGrants = /* @__PURE__ */ new Set();
|
|
35
|
+
/**
|
|
36
|
+
* The open state a `setOpen` call is currently applying. Handlers run before
|
|
37
|
+
* `isOpen` is assigned, so a handler that calls `setOpen` again would not be
|
|
38
|
+
* caught by the equality check at the top and would recurse.
|
|
39
|
+
*/
|
|
40
|
+
openStateInFlight;
|
|
41
|
+
constructor(options = {}) {
|
|
42
|
+
makeObservable(this, {
|
|
43
|
+
isOpen: observable,
|
|
44
|
+
isContentSuspended: observable,
|
|
45
|
+
showConfirmationModal: observable,
|
|
46
|
+
confirmOnCloseEnabled: computed,
|
|
47
|
+
open: action.bound,
|
|
48
|
+
close: action.bound,
|
|
49
|
+
toggle: action.bound,
|
|
50
|
+
setOpen: action.bound,
|
|
51
|
+
syncOpen: action.bound,
|
|
52
|
+
setIsContentSuspended: action.bound,
|
|
53
|
+
confirmClose: action.bound,
|
|
54
|
+
cancelConfirmation: action.bound
|
|
55
|
+
});
|
|
56
|
+
const { isDefaultOpen = false, confirmOnClose = false } = options;
|
|
57
|
+
this.isOpen = isDefaultOpen;
|
|
58
|
+
this.confirmOnCloseFromOptions = confirmOnClose;
|
|
59
|
+
}
|
|
60
|
+
/** Whether closing this overlay currently requires a confirmation. */
|
|
61
|
+
get confirmOnCloseEnabled() {
|
|
62
|
+
if (this.confirmOnCloseSources.size === 0) return this.confirmOnCloseFromOptions;
|
|
63
|
+
return Array.from(this.confirmOnCloseSources.values()).some(Boolean);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Sets the opinion of one source – any object the caller keeps – on close
|
|
67
|
+
* confirmation. Remove the source again when its owner goes away.
|
|
68
|
+
*
|
|
69
|
+
* @internal Bindings call it from their lifecycle.
|
|
70
|
+
*/
|
|
71
|
+
setConfirmOnCloseSource(source, confirmOnClose) {
|
|
72
|
+
runInAction(() => this.confirmOnCloseSources.set(source, confirmOnClose));
|
|
73
|
+
}
|
|
74
|
+
/** @internal Bindings call it from their lifecycle. */
|
|
75
|
+
removeConfirmOnCloseSource(source) {
|
|
76
|
+
runInAction(() => this.confirmOnCloseSources.delete(source));
|
|
77
|
+
}
|
|
78
|
+
addOpenStateHandler(handler, handlersSet) {
|
|
79
|
+
handlersSet.add(handler);
|
|
80
|
+
return () => {
|
|
81
|
+
handlersSet.delete(handler);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
executeHandlers(isOpen, handlers) {
|
|
85
|
+
return Array.from(handlers).map((handler) => handler(isOpen)).some((result) => result === false);
|
|
86
|
+
}
|
|
87
|
+
executeOnClose() {
|
|
88
|
+
return this.executeHandlers(false, this.onCloseHandlers);
|
|
89
|
+
}
|
|
90
|
+
executeOnOpen() {
|
|
91
|
+
return this.executeHandlers(true, this.onOpenHandlers);
|
|
92
|
+
}
|
|
93
|
+
executeOnOpenChange(isOpen) {
|
|
94
|
+
return this.executeHandlers(isOpen, this.onOpenChangeHandlers);
|
|
95
|
+
}
|
|
96
|
+
addOnClose(handler) {
|
|
97
|
+
return this.addOpenStateHandler(handler, this.onCloseHandlers);
|
|
98
|
+
}
|
|
99
|
+
addOnOpen(handler) {
|
|
100
|
+
return this.addOpenStateHandler(handler, this.onOpenHandlers);
|
|
101
|
+
}
|
|
102
|
+
addOnOpenChange(handler) {
|
|
103
|
+
return this.addOpenStateHandler(handler, this.onOpenChangeHandlers);
|
|
104
|
+
}
|
|
105
|
+
open() {
|
|
106
|
+
this.setOpen(true);
|
|
107
|
+
}
|
|
108
|
+
close(options) {
|
|
109
|
+
this.setOpen(false, options);
|
|
110
|
+
}
|
|
111
|
+
toggle() {
|
|
112
|
+
this.setOpen(!this.isOpen);
|
|
113
|
+
}
|
|
114
|
+
setOpen(toOpen, options) {
|
|
115
|
+
if (this.isOpen === toOpen || this.openStateInFlight === toOpen) return;
|
|
116
|
+
this.openStateInFlight = toOpen;
|
|
117
|
+
try {
|
|
118
|
+
this.applyOpenState(toOpen, options);
|
|
119
|
+
} finally {
|
|
120
|
+
this.openStateInFlight = void 0;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Sets the open state without running any handler. Use it to mirror a
|
|
125
|
+
* controlled `isOpen` prop, whose change comes from the consumer – notifying
|
|
126
|
+
* them of their own state would echo it back.
|
|
127
|
+
*/
|
|
128
|
+
syncOpen(toOpen) {
|
|
129
|
+
this.isOpen = toOpen;
|
|
130
|
+
}
|
|
131
|
+
applyOpenState(toOpen, options) {
|
|
132
|
+
const { bypassConfirmation = false } = options ?? {};
|
|
133
|
+
if (toOpen === false) {
|
|
134
|
+
const closeIsConfirmed = this.closeIsConfirmed;
|
|
135
|
+
this.closeIsConfirmed = false;
|
|
136
|
+
if (this.confirmOnCloseEnabled && !closeIsConfirmed && this.closeWithoutConfirmationGrants.size === 0 && !bypassConfirmation) {
|
|
137
|
+
this.showConfirmationModal = true;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
let aborted;
|
|
142
|
+
if (toOpen) aborted = this.executeOnOpen();
|
|
143
|
+
else aborted = this.executeOnClose();
|
|
144
|
+
if (!aborted) aborted = this.executeOnOpenChange(toOpen);
|
|
145
|
+
if (!aborted) this.isOpen = toOpen;
|
|
146
|
+
}
|
|
147
|
+
setIsContentSuspended(to) {
|
|
148
|
+
this.isContentSuspended = to;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Allows closing this overlay without a confirmation until the returned
|
|
152
|
+
* disposer is called. Use it around an operation that may legitimately close
|
|
153
|
+
* the overlay – e.g. a `Form` submit, where a "discard unsaved changes?"
|
|
154
|
+
* prompt would be nonsense – and dispose it as soon as that operation has
|
|
155
|
+
* finished. An operation that ends without closing the overlay therefore
|
|
156
|
+
* leaves the confirmation armed (#2775).
|
|
157
|
+
*/
|
|
158
|
+
grantCloseWithoutConfirmation() {
|
|
159
|
+
const grant = {};
|
|
160
|
+
this.closeWithoutConfirmationGrants.add(grant);
|
|
161
|
+
return () => {
|
|
162
|
+
this.closeWithoutConfirmationGrants.delete(grant);
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
confirmClose() {
|
|
166
|
+
this.closeIsConfirmed = true;
|
|
167
|
+
this.showConfirmationModal = false;
|
|
168
|
+
}
|
|
169
|
+
cancelConfirmation() {
|
|
170
|
+
this.showConfirmationModal = false;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
//#endregion
|
|
174
|
+
export { OverlayState };
|
|
175
|
+
|
|
176
|
+
//# sourceMappingURL=OverlayState.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OverlayState.mjs","names":[],"sources":["../../../../../../components-base/src/overlay/OverlayState.ts"],"sourcesContent":["import {\n action,\n computed,\n makeObservable,\n observable,\n runInAction,\n} from \"mobx\";\n\nexport type OverlayOpenHandler = () => unknown;\nexport type OverlayCloseHandler = () => unknown;\nexport type OverlayOpenStateHandler = (isOpen: boolean) => unknown;\nexport type AnyOverlayOpenStateHandler =\n OverlayOpenHandler | OverlayCloseHandler | OverlayOpenStateHandler;\n\nexport type DisposerFn = () => void;\n\nexport interface OverlayCloseOptions {\n /** Close without asking, even when the overlay requires confirmation. */\n bypassConfirmation?: boolean;\n}\n\nexport interface OverlayStateOptions {\n isDefaultOpen?: boolean;\n /**\n * Whether closing the overlay must be confirmed while no source has an\n * opinion (`setConfirmOnCloseSource`).\n */\n confirmOnClose?: boolean;\n}\n\n/**\n * Whether an overlay is open, and whether closing it has to be confirmed first.\n * Each binding adds its subscription and its lifecycle: React's\n * `OverlayController` subclasses it, Vue's adapter wraps it in refs.\n *\n * `TCloseOptions` lets a binding pass more on a close than the state reads —\n * React's `overlay`, resolved by `Action` before the close arrives here.\n */\nexport class OverlayState<\n TCloseOptions extends OverlayCloseOptions = OverlayCloseOptions,\n> {\n public isOpen = false;\n public isContentSuspended = false;\n private onOpenHandlers = new Set<OverlayOpenHandler>();\n private onCloseHandlers = new Set<OverlayCloseHandler>();\n private onOpenChangeHandlers = new Set<OverlayOpenStateHandler>();\n\n public showConfirmationModal = false;\n public closeIsConfirmed = false;\n private readonly confirmOnCloseFromOptions: boolean;\n /**\n * Every mounted component that has an opinion on close confirmation\n * contributes one entry here – e.g. a `Modal` with a `confirmOnClose` prop\n * and a `Form` tracking its dirty state. Combining them instead of assigning\n * a single flag keeps them from overwriting each other.\n */\n private confirmOnCloseSources = observable.map<object, boolean>();\n /**\n * Active grants that allow closing without a confirmation. Each entry is\n * scoped to an ongoing operation that legitimately closes the overlay – e.g.\n * a `Form` submit – and is dropped again when that operation has finished, so\n * an operation that does _not_ close the overlay leaves the confirmation\n * armed.\n */\n private closeWithoutConfirmationGrants = new Set<object>();\n /**\n * The open state a `setOpen` call is currently applying. Handlers run before\n * `isOpen` is assigned, so a handler that calls `setOpen` again would not be\n * caught by the equality check at the top and would recurse.\n */\n private openStateInFlight: boolean | undefined;\n\n public constructor(options: OverlayStateOptions = {}) {\n makeObservable(this, {\n isOpen: observable,\n isContentSuspended: observable,\n showConfirmationModal: observable,\n confirmOnCloseEnabled: computed,\n open: action.bound,\n close: action.bound,\n toggle: action.bound,\n setOpen: action.bound,\n syncOpen: action.bound,\n setIsContentSuspended: action.bound,\n confirmClose: action.bound,\n cancelConfirmation: action.bound,\n });\n const { isDefaultOpen = false, confirmOnClose = false } = options;\n this.isOpen = isDefaultOpen;\n this.confirmOnCloseFromOptions = confirmOnClose;\n }\n\n /** Whether closing this overlay currently requires a confirmation. */\n public get confirmOnCloseEnabled(): boolean {\n if (this.confirmOnCloseSources.size === 0) {\n return this.confirmOnCloseFromOptions;\n }\n return Array.from(this.confirmOnCloseSources.values()).some(Boolean);\n }\n\n /**\n * Sets the opinion of one source – any object the caller keeps – on close\n * confirmation. Remove the source again when its owner goes away.\n *\n * @internal Bindings call it from their lifecycle.\n */\n public setConfirmOnCloseSource(source: object, confirmOnClose: boolean) {\n runInAction(() => this.confirmOnCloseSources.set(source, confirmOnClose));\n }\n\n /** @internal Bindings call it from their lifecycle. */\n public removeConfirmOnCloseSource(source: object) {\n runInAction(() => this.confirmOnCloseSources.delete(source));\n }\n\n private addOpenStateHandler<T extends AnyOverlayOpenStateHandler>(\n handler: T,\n handlersSet: Set<T>,\n ): DisposerFn {\n handlersSet.add(handler);\n return () => {\n handlersSet.delete(handler);\n };\n }\n\n private executeHandlers(\n isOpen: boolean,\n handlers: Set<\n OverlayOpenHandler | OverlayCloseHandler | OverlayOpenStateHandler\n >,\n ): boolean {\n const handlerResult = Array.from(handlers).map((handler) =>\n handler(isOpen),\n );\n return handlerResult.some((result) => result === false);\n }\n\n private executeOnClose(): boolean {\n return this.executeHandlers(false, this.onCloseHandlers);\n }\n\n private executeOnOpen(): boolean {\n return this.executeHandlers(true, this.onOpenHandlers);\n }\n\n private executeOnOpenChange(isOpen: boolean): boolean {\n return this.executeHandlers(isOpen, this.onOpenChangeHandlers);\n }\n\n public addOnClose(handler: OverlayCloseHandler) {\n return this.addOpenStateHandler(handler, this.onCloseHandlers);\n }\n\n public addOnOpen(handler: OverlayOpenHandler) {\n return this.addOpenStateHandler(handler, this.onOpenHandlers);\n }\n\n public addOnOpenChange(handler: OverlayOpenStateHandler) {\n return this.addOpenStateHandler(handler, this.onOpenChangeHandlers);\n }\n\n public open(): void {\n this.setOpen(true);\n }\n\n public close(options?: TCloseOptions): void {\n this.setOpen(false, options);\n }\n\n public toggle(): void {\n this.setOpen(!this.isOpen);\n }\n\n public setOpen(toOpen: boolean, options?: TCloseOptions): void {\n if (this.isOpen === toOpen || this.openStateInFlight === toOpen) {\n return;\n }\n\n this.openStateInFlight = toOpen;\n try {\n this.applyOpenState(toOpen, options);\n } finally {\n this.openStateInFlight = undefined;\n }\n }\n\n /**\n * Sets the open state without running any handler. Use it to mirror a\n * controlled `isOpen` prop, whose change comes from the consumer – notifying\n * them of their own state would echo it back.\n */\n public syncOpen(toOpen: boolean): void {\n this.isOpen = toOpen;\n }\n\n private applyOpenState(toOpen: boolean, options?: TCloseOptions): void {\n const { bypassConfirmation = false } = options ?? {};\n\n if (toOpen === false) {\n // The confirmation is a one-shot permission for exactly this close\n // attempt – consume it here instead of only when a close succeeds, so it\n // cannot survive an aborted close and disarm later attempts.\n const closeIsConfirmed = this.closeIsConfirmed;\n this.closeIsConfirmed = false;\n\n if (\n this.confirmOnCloseEnabled &&\n !closeIsConfirmed &&\n this.closeWithoutConfirmationGrants.size === 0 &&\n !bypassConfirmation\n ) {\n this.showConfirmationModal = true;\n return;\n }\n }\n\n let aborted: boolean;\n if (toOpen) {\n aborted = this.executeOnOpen();\n } else {\n aborted = this.executeOnClose();\n }\n if (!aborted) {\n aborted = this.executeOnOpenChange(toOpen);\n }\n\n if (!aborted) {\n this.isOpen = toOpen;\n }\n }\n\n public setIsContentSuspended(to: boolean): void {\n this.isContentSuspended = to;\n }\n\n /**\n * Allows closing this overlay without a confirmation until the returned\n * disposer is called. Use it around an operation that may legitimately close\n * the overlay – e.g. a `Form` submit, where a \"discard unsaved changes?\"\n * prompt would be nonsense – and dispose it as soon as that operation has\n * finished. An operation that ends without closing the overlay therefore\n * leaves the confirmation armed (#2775).\n */\n public grantCloseWithoutConfirmation(): DisposerFn {\n const grant = {};\n this.closeWithoutConfirmationGrants.add(grant);\n return () => {\n this.closeWithoutConfirmationGrants.delete(grant);\n };\n }\n\n public confirmClose(): void {\n this.closeIsConfirmed = true;\n this.showConfirmationModal = false;\n }\n\n public cancelConfirmation(): void {\n this.showConfirmationModal = false;\n }\n}\n"],"mappings":";;;;;;;;;;AAsCA,IAAa,eAAb,MAEE;CACA,SAAgB;CAChB,qBAA4B;CAC5B,iCAAyB,IAAI,IAAwB;CACrD,kCAA0B,IAAI,IAAyB;CACvD,uCAA+B,IAAI,IAA6B;CAEhE,wBAA+B;CAC/B,mBAA0B;CAC1B;;;;;;;CAOA,wBAAgC,WAAW,IAAqB;;;;;;;;CAQhE,iDAAyC,IAAI,IAAY;;;;;;CAMzD;CAEA,YAAmB,UAA+B,CAAC,GAAG;EACpD,eAAe,MAAM;GACnB,QAAQ;GACR,oBAAoB;GACpB,uBAAuB;GACvB,uBAAuB;GACvB,MAAM,OAAO;GACb,OAAO,OAAO;GACd,QAAQ,OAAO;GACf,SAAS,OAAO;GAChB,UAAU,OAAO;GACjB,uBAAuB,OAAO;GAC9B,cAAc,OAAO;GACrB,oBAAoB,OAAO;EAC7B,CAAC;EACD,MAAM,EAAE,gBAAgB,OAAO,iBAAiB,UAAU;EAC1D,KAAK,SAAS;EACd,KAAK,4BAA4B;CACnC;;CAGA,IAAW,wBA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oB;EACzB,IAAI;GACF,KAAK,eAAe,QAAQ,OAAO;EACrC,UAAU;GACR,KAAK,oBAAoB,KAAA;EAC3B;CACF;;;;;;CAOA,SAAgB,QAAuB;EACrC,KAAK,SAAS;CAChB;CAEA,eAAuB,QAAiB,SAA+B;EACrE,MAAM,EAAE,qBAAqB,UAAU,WAAW,CAAC;EAEnD,IAAI,WAAW,OAAO;GAIpB,MAAM,mBAAmB,KAAK;GAC9B,KAAK,mBAAmB;GAExB,IACE,KAAK,yBACL,CAAC,oBACD,KAAK,+BAA+B,SAAS,KAC7C,CAAC,oBACD;IACA,KAAK,wBAAwB;IAC7B;GACF;EACF;EAEA,IAAI;EACJ,IAAI,QACF,UAAU,KAAK,cAAc;OAE7B,UAAU,KAAK,eAAe;EAEhC,IAAI,CAAC,SACH,UAAU,KAAK,oBAAoB,MAAM;EAG3C,IAAI,CAAC,SACH,KAAK,SAAS;CAElB;CAEA,sBAA6B,IAAmB;EAC9C,KAAK,qBAAqB;CAC5B;;;;;;;;;CAUA,gCAAmD;EACjD,MAAM,QAAQ,CAAC;EACf,KAAK,+BAA+B,IAAI,KAAK;EAC7C,aAAa;GACX,KAAK,+BAA+B,OAAO,KAAK;EAClD;CACF;CAEA,eAA4B;EAC1B,KAAK,mBAAmB;EACxB,KAAK,wBAAwB;CAC/B;CAEA,qBAAkC;EAChC,KAAK,wBAAwB;CAC/B;AACF"}
|
|
@@ -5,9 +5,9 @@ import { Link } from "../auto-generated/Link.mjs";
|
|
|
5
5
|
import { MenuItem } from "../auto-generated/MenuItem.mjs";
|
|
6
6
|
import watchMobxValue from "../lib/mobxSelector.mjs";
|
|
7
7
|
import { dynamic, mapChildren } from "../overlays/childProps.mjs";
|
|
8
|
-
import { injectOverlayContext, isOverlayController } from "../overlays/overlayController.mjs";
|
|
9
8
|
import { ActionState } from "../../../components-base/src/action/ActionState.mjs";
|
|
10
9
|
import "../../../components-base/src/index.mjs";
|
|
10
|
+
import { injectOverlayContext, isOverlayController } from "../overlays/overlayController.mjs";
|
|
11
11
|
import { defineComponent, inject, onMounted, provide } from "vue";
|
|
12
12
|
//#region src/components/Action.ts
|
|
13
13
|
var actionProps = {
|
|
@@ -16,10 +16,10 @@ import { Section } from "../auto-generated/Section.mjs";
|
|
|
16
16
|
import { Text } from "../auto-generated/Text.mjs";
|
|
17
17
|
import { IconClose } from "../icons/components/IconClose.mjs";
|
|
18
18
|
import { applyChildRules, dynamic, withSlotContent } from "./childProps.mjs";
|
|
19
|
-
import {
|
|
19
|
+
import { createOverlayController, isOverlayController, provideOverlayContext, useConfirmOnCloseSource, useOverlayHandlers, useOwnController } from "./overlayController.mjs";
|
|
20
20
|
import { Action } from "../components/Action.mjs";
|
|
21
21
|
import { confirmCloseTexts } from "./locales.mjs";
|
|
22
|
-
import { defineComponent, h,
|
|
22
|
+
import { defineComponent, h, onMounted, useId, watch } from "vue";
|
|
23
23
|
//#region src/overlays/Modal.ts
|
|
24
24
|
var styles = {
|
|
25
25
|
overlay: "flow--overlay",
|
|
@@ -83,11 +83,11 @@ var nestedHeadingRules = (child) => child.type === Heading ? { props: { level: 3
|
|
|
83
83
|
children: (grandChild) => grandChild.type === Header ? { children: headingLevel3 } : headingLevel3(grandChild)
|
|
84
84
|
} : child.type === Header ? { children: headingLevel3 } : void 0;
|
|
85
85
|
/**
|
|
86
|
-
* Asks before a
|
|
86
|
+
* Asks before a modal that requires confirmation closes.
|
|
87
87
|
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
88
|
+
* Flow's `useCloseOverlayConfirmationController`: a controller of its own,
|
|
89
|
+
* opened while the parent asks. A dismiss of this modal answers "keep editing",
|
|
90
|
+
* and an answer from anywhere closes it again.
|
|
91
91
|
*
|
|
92
92
|
* Annotated rather than inferred — it renders a `Modal` and the `Modal` renders
|
|
93
93
|
* it, and without an annotation TypeScript cannot break that cycle (TS7022).
|
|
@@ -100,7 +100,11 @@ var ConfirmCloseModal = defineComponent({
|
|
|
100
100
|
} },
|
|
101
101
|
setup(props) {
|
|
102
102
|
const language = useLanguage();
|
|
103
|
-
const controller =
|
|
103
|
+
const controller = createOverlayController();
|
|
104
|
+
watch(() => props.parent.isConfirmingClose.value, (isConfirming) => isConfirming ? controller.open() : controller.close(), { immediate: true });
|
|
105
|
+
controller.addOnClose(() => {
|
|
106
|
+
if (props.parent.isConfirmingClose.value) props.parent.cancelConfirmation();
|
|
107
|
+
});
|
|
104
108
|
return () => {
|
|
105
109
|
const texts = language.value?.startsWith("de") ? confirmCloseTexts["de-DE"] : confirmCloseTexts["en-US"];
|
|
106
110
|
return h(Modal, { controller }, () => [
|
|
@@ -152,7 +156,7 @@ var Modal = defineComponent({
|
|
|
152
156
|
*/
|
|
153
157
|
confirmOnClose: {
|
|
154
158
|
type: Boolean,
|
|
155
|
-
default:
|
|
159
|
+
default: void 0
|
|
156
160
|
},
|
|
157
161
|
/** A controller to open and close the modal from anywhere. */
|
|
158
162
|
controller: {
|
|
@@ -202,15 +206,7 @@ var Modal = defineComponent({
|
|
|
202
206
|
onClose: () => props.onClose,
|
|
203
207
|
onOpenChange: () => props.onOpenChange
|
|
204
208
|
});
|
|
205
|
-
|
|
206
|
-
controller.value.confirmOnClose.value = props.confirmOnClose;
|
|
207
|
-
});
|
|
208
|
-
const release = (released) => {
|
|
209
|
-
released.confirmOnClose.value = false;
|
|
210
|
-
released.isConfirmingClose.value = false;
|
|
211
|
-
};
|
|
212
|
-
watch(controller, (next, previous) => release(previous));
|
|
213
|
-
onBeforeUnmount(() => release(controller.value));
|
|
209
|
+
useConfirmOnCloseSource(() => controller.value, () => props.confirmOnClose);
|
|
214
210
|
const childRules = (child) => {
|
|
215
211
|
if (child.type === Heading) return { props: {
|
|
216
212
|
class: styles.header,
|
|
@@ -253,7 +249,7 @@ var Modal = defineComponent({
|
|
|
253
249
|
].filter(Boolean).join(" ");
|
|
254
250
|
const texts = language.value?.startsWith("de") ? confirmCloseTexts["de-DE"] : confirmCloseTexts["en-US"];
|
|
255
251
|
const children = applyChildRules(slots.default?.(), childRules).map((child) => child.type === Heading ? withHeaderChrome(child, texts.close, props.showCloseButton) : child);
|
|
256
|
-
if (
|
|
252
|
+
if (controller.value.confirmOnClose.value) children.push(h(ConfirmCloseModal, { parent: controller.value }));
|
|
257
253
|
return h(ClearPropsContext, null, () => h(OverlayContent, {
|
|
258
254
|
class: className,
|
|
259
255
|
isOpen: props.isOpen ?? controller.value.isOpen.value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.mjs","names":[],"sources":["../../../../../src/overlays/Modal.ts"],"sourcesContent":["import {\n AccentBox,\n ActionGroup,\n Button,\n ClearPropsContext,\n ColumnLayout,\n Content,\n Div,\n Header,\n Heading,\n OverlayContent,\n Section,\n Text,\n} from \"@/auto-generated\";\nimport { IconClose } from \"@/icons\";\nimport Action from \"@/components/Action\";\nimport { useLanguage } from \"@/composables/remoteContext\";\nimport { confirmCloseTexts } from \"@/overlays/locales\";\nimport {\n applyChildRules,\n dynamic,\n withSlotContent,\n type ChildRules,\n} from \"@/overlays/childProps\";\nimport { readProp } from \"@/lib/propKeys\";\nimport {\n createOverlayControllerFor,\n isOverlayController,\n provideOverlayContext,\n useOwnController,\n useOverlayHandlers,\n type OverlayCloseHandler,\n type OverlayController,\n type OverlayOpenHandler,\n type OverlayOpenStateHandler,\n} from \"@/overlays/overlayController\";\nimport type { AnyRecord } from \"@/lib/types\";\nimport {\n defineComponent,\n h,\n onBeforeUnmount,\n onMounted,\n useId,\n watch,\n watchEffect,\n type Component,\n type PropType,\n type VNode,\n} from \"vue\";\nimport { composition } from \"@/lib/composition\";\nimport { useComponentUsage } from \"@/composables/useComponentUsage\";\n\nexport type ModalSize = \"s\" | \"m\" | \"l\";\n\n/*\n * Flow's `Modal` is a React composition, not a remote element: it renders an\n * `OverlayContent` and configures the components inside it through a props\n * context — the header, the content padding, the footer spacing. Both halves\n * are rebuilt here, so a Vue app writes `Modal` and not the overlay plumbing.\n *\n * The class names are Flow's own, taken from `Modal.module.scss` by way of the\n * generated `flow--…` names. They are internal, and repeating them is the price\n * of a composition that lives in React: the alternative — marking `Modal`\n * `@flr-generate`, so the host materialises the whole thing from one element —\n * would make this file unnecessary.\n */\nconst styles = {\n overlay: \"flow--overlay\",\n modal: \"flow--modal\",\n offCanvas: \"flow--modal--off-canvas\",\n left: \"flow--modal--left\",\n size: (size: ModalSize) => `flow--modal--size-${size}`,\n header: \"flow--modal--header\",\n headerTitle: \"flow--modal--header-title\",\n closeButton: \"flow--modal--close-button\",\n alwaysVisible: \"flow--modal--always-visible\",\n alwaysHidden: \"flow--modal--always-hidden\",\n content: \"flow--modal--content\",\n columnLayout: \"flow--modal--column-layout\",\n accentBox: \"flow--modal--accent-box\",\n actionGroup: \"flow--modal--action-group\",\n};\n\n/**\n * The chrome Flow puts around a modal's heading: the title in its own\n * container, and the close button beside it.\n *\n * Not props on the heading but a rebuild of what it was handed — the reason\n * `withSlotContent` exists. The close button clears the props context around\n * it, the way Flow's does, so the modal's own rules for `Button` do not reach\n * it, and it closes without asking again: this button _is_ the deliberate way\n * out.\n */\nconst withHeaderChrome = (\n heading: VNode,\n closeLabel: string,\n showCloseButton: boolean | undefined,\n): VNode =>\n withSlotContent(heading, (title) => [\n h(Div, { class: styles.headerTitle }, () => title),\n h(ClearPropsContext, null, () =>\n h(Action, { closeModal: { bypassConfirmation: true } }, () =>\n h(\n Button,\n {\n variant: \"plain\",\n color: \"secondary\",\n \"aria-label\": closeLabel,\n class: [\n styles.closeButton,\n showCloseButton === true\n ? styles.alwaysVisible\n : showCloseButton === false\n ? styles.alwaysHidden\n : undefined,\n ]\n .filter(Boolean)\n .join(\" \"),\n },\n () => h(IconClose),\n ),\n ),\n ),\n ]);\n\n/**\n * Lets an `Action` in the modal's footer close without asking again.\n *\n * Only where the action already closes something: Flow's props context rewrites\n * an existing `closeModal`/`closeOverlay` and adds none, and an `Action` that\n * merely runs something must not be turned into a close button. An explicit\n * `bypassConfirmation` in the object form wins, as in Flow.\n */\nconst withBypassedConfirmation = (child: VNode): AnyRecord | undefined => {\n if (child.type !== Action) {\n return undefined;\n }\n\n const bypassed: AnyRecord = {};\n\n for (const name of [\"closeModal\", \"closeOverlay\"]) {\n const value = readProp(child.props, name);\n\n if (value === undefined || value === null || value === false) {\n continue;\n }\n\n /*\n * A controller names the overlay, like a type name does — spread, it\n * would lose its identity and the action would close the modal instead.\n */\n bypassed[name] = dynamic(\n isOverlayController(value) || (typeof value === \"string\" && value !== \"\")\n ? { bypassConfirmation: true, overlay: value }\n : typeof value === \"object\"\n ? { bypassConfirmation: true, ...value }\n : { bypassConfirmation: true },\n );\n }\n\n return Object.keys(bypassed).length > 0 ? bypassed : undefined;\n};\n\n/*\n * Flow's `nestedHeadingProps`: inside the content, headings are one level\n * down, and a section drops its separator.\n */\nconst headingLevel3: ChildRules = (child) =>\n child.type === Heading ? { props: { level: 3 } } : undefined;\n\nconst nestedHeadingRules: ChildRules = (child) =>\n child.type === Heading\n ? { props: { level: 3 } }\n : child.type === Section\n ? {\n props: { hideSeparator: true },\n children: (grandChild) =>\n grandChild.type === Header\n ? { children: headingLevel3 }\n : headingLevel3(grandChild),\n }\n : child.type === Header\n ? { children: headingLevel3 }\n : undefined;\n\n/**\n * Asks before a `<Modal confirm-on-close>` closes.\n *\n * Bound to the parent's `isConfirmingClose` rather than holding state of its\n * own: a dismiss of this modal is then the same event as answering \"keep\n * editing\", and there is one place that decides whether the parent closes.\n *\n * Annotated rather than inferred — it renders a `Modal` and the `Modal` renders\n * it, and without an annotation TypeScript cannot break that cycle (TS7022).\n */\nconst ConfirmCloseModal: Component = defineComponent({\n name: \"ConfirmCloseModal\",\n\n props: {\n parent: {\n type: Object as PropType<OverlayController>,\n required: true,\n },\n },\n\n setup(props) {\n const language = useLanguage();\n const controller = createOverlayControllerFor(\n props.parent.isConfirmingClose,\n );\n\n return () => {\n const texts = language.value?.startsWith(\"de\")\n ? confirmCloseTexts[\"de-DE\"]\n : confirmCloseTexts[\"en-US\"];\n\n return h(Modal, { controller }, () => [\n h(Heading, null, () => texts.heading),\n h(Content, null, () => h(Text, null, () => texts.text)),\n h(ActionGroup, null, () => [\n h(Action, { onAction: props.parent.confirmClose }, () =>\n h(Button, { color: \"danger\" }, () => texts.close),\n ),\n h(Action, { onAction: props.parent.cancelClose }, () =>\n h(\n Button,\n { color: \"secondary\", variant: \"soft\" },\n () => texts.keepOpen,\n ),\n ),\n ]),\n ]);\n };\n },\n});\n\nexport const Modal = defineComponent({\n name: \"Modal\",\n\n /* Like Flow's, a modal passes on only the props it knows. */\n inheritAttrs: false,\n\n props: {\n /** The size of the modal. @default \"s\" */\n size: { type: String as PropType<ModalSize>, default: \"s\" },\n /** Whether the modal is displayed as an off canvas. */\n offCanvas: { type: Boolean, default: false },\n /** Which side the off canvas comes from. @default \"right\" */\n offCanvasOrientation: {\n type: String as PropType<\"left\" | \"right\">,\n default: \"right\",\n },\n /** Whether a click outside closes the modal. @default true */\n isDismissable: { type: Boolean, default: true },\n /**\n * Whether the close button is always visible (`true`) or always hidden\n * (`false`). By default Flow decides by screen size.\n */\n showCloseButton: { type: Boolean, default: undefined },\n /**\n * Whether closing the modal has to be confirmed — use it to protect unsaved\n * changes.\n */\n confirmOnClose: { type: Boolean, default: false },\n /** A controller to open and close the modal from anywhere. */\n controller: {\n type: Object as PropType<OverlayController>,\n default: undefined,\n },\n /** Whether the modal is open. Use it to control the modal state. */\n isOpen: { type: Boolean, default: undefined },\n /**\n * Whether the modal is open initially, when it has a controller of its own\n * — not one from a trigger or the `controller` prop. @default false\n */\n isDefaultOpen: { type: Boolean, default: undefined },\n /** Called when the modal opens. Returning `false` keeps it closed. */\n onOpen: {\n type: Function as PropType<OverlayOpenHandler>,\n default: undefined,\n },\n /** Called when the modal closes. Returning `false` keeps it open. */\n onClose: {\n type: Function as PropType<OverlayCloseHandler>,\n default: undefined,\n },\n /**\n * Called with the new state whenever the modal opens or closes. Returning\n * `false` aborts the change.\n */\n onOpenChange: {\n type: Function as PropType<OverlayOpenStateHandler>,\n default: undefined,\n },\n },\n\n setup(props, { slots, attrs }) {\n /* Flow's React `Modal` is a `flowComponent` and reports itself. */\n onMounted(useComponentUsage(\"Modal\"));\n\n const language = useLanguage();\n /*\n * The dialog is labelled by its own heading, so the two need an id they\n * agree on. Flow generates one with `useId`; `useId` exists in Vue too,\n * and both sides end up with an id the host rewrites anyway — what has to\n * match is that the heading carries one at all.\n */\n const headingId = useId();\n /*\n * Three ways to own the state, in Flow's order of precedence: a\n * controller the app passes, the controller of a surrounding trigger, or\n * one of its own.\n */\n const controller = useOwnController(\n () => props.controller,\n \"Modal\",\n () => ({ isDefaultOpen: props.isDefaultOpen }),\n );\n\n // So an `Action` inside finds it.\n provideOverlayContext(\"Modal\", () => controller.value);\n\n useOverlayHandlers(() => controller.value, {\n onOpen: () => props.onOpen,\n onClose: () => props.onClose,\n onOpenChange: () => props.onOpenChange,\n });\n\n /*\n * The requirement lives on the controller, not on this component: what\n * asks for the confirmation is a close, and a close arrives at the\n * controller — from an `Action` inside, from the host's dismiss, or from\n * an app holding the controller itself.\n */\n watchEffect(() => {\n controller.value.confirmOnClose.value = props.confirmOnClose;\n });\n\n /*\n * Taken back, because the controller usually outlives the modal: a\n * trigger keeps it, and the next modal it opens would inherit a\n * requirement it never asked for. The same goes for a controller the\n * app swapped for another.\n */\n const release = (released: OverlayController) => {\n released.confirmOnClose.value = false;\n released.isConfirmingClose.value = false;\n };\n watch(controller, (next, previous) => release(previous));\n onBeforeUnmount(() => release(controller.value));\n\n /* Flow's props context for the modal's children, rule for rule. */\n const childRules: ChildRules = (child) => {\n if (child.type === Heading) {\n return { props: { class: styles.header, level: 2, id: headingId } };\n }\n if (child.type === Content) {\n return {\n props: { class: styles.content },\n children: nestedHeadingRules,\n };\n }\n if (child.type === ColumnLayout) {\n return {\n props: { class: styles.columnLayout, l: [2, 1], m: [1] },\n children: (grandChild) =>\n grandChild.type === AccentBox\n ? {\n props: {\n class: styles.accentBox,\n backgroundColor: \"neutral\",\n },\n }\n : nestedHeadingRules(grandChild),\n };\n }\n if (child.type === ActionGroup) {\n /*\n * The footer is the deliberate way out, so its actions close\n * without asking again — the rule Flow's `Modal` writes for\n * `ActionGroup > Action`. An `Action` anywhere else in the modal is\n * an incidental close and is confirmed.\n */\n return {\n props: { class: styles.actionGroup, spacing: \"m\" },\n children: (grandChild) => {\n const props = withBypassedConfirmation(grandChild);\n return props ? { props } : undefined;\n },\n };\n }\n return undefined;\n };\n\n return () => {\n const className = [\n styles.overlay,\n props.offCanvas ? styles.offCanvas : styles.modal,\n styles.size(props.size),\n props.offCanvas && props.offCanvasOrientation === \"left\"\n ? styles.left\n : undefined,\n attrs.class,\n ]\n .filter(Boolean)\n .join(\" \");\n\n const texts = language.value?.startsWith(\"de\")\n ? confirmCloseTexts[\"de-DE\"]\n : confirmCloseTexts[\"en-US\"];\n\n const children: VNode[] = applyChildRules(\n slots.default?.(),\n childRules,\n ).map((child) =>\n child.type === Heading\n ? withHeaderChrome(child, texts.close, props.showCloseButton)\n : child,\n );\n\n if (props.confirmOnClose) {\n children.push(h(ConfirmCloseModal, { parent: controller.value }));\n }\n\n /* A UI component: Flow clears the host's props context around it. */\n return h(ClearPropsContext, null, () =>\n h(\n OverlayContent,\n {\n class: className,\n isOpen: props.isOpen ?? controller.value.isOpen.value,\n isDismissable: props.isDismissable,\n \"aria-labelledby\": headingId,\n onOpenChange: controller.value.setOpen,\n },\n () => children,\n ),\n );\n };\n },\n});\n\ncomposition(ConfirmCloseModal);\ncomposition(Modal);\n\nexport default Modal;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkEA,IAAM,SAAS;CACb,SAAS;CACT,OAAO;CACP,WAAW;CACX,MAAM;CACN,OAAO,SAAoB,qBAAqB;CAChD,QAAQ;CACR,aAAa;CACb,aAAa;CACb,eAAe;CACf,cAAc;CACd,SAAS;CACT,cAAc;CACd,WAAW;CACX,aAAa;AACf;;;;;;;;;;;AAYA,IAAM,oBACJ,SACA,YACA,oBAEA,gBAAg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;KAAa,SAAS;IAAI;IACjD,WAAW,eAAe;KACxB,MAAM,QAAQ,yBAAyB,UAAU;KACjD,OAAO,QAAQ,EAAE,MAAM,IAAI,KAAA;IAC7B;GACF;EAGJ;EAEA,aAAa;GACX,MAAM,YAAY;IAChB,OAAO;IACP,MAAM,YAAY,OAAO,YAAY,OAAO;IAC5C,OAAO,KAAK,MAAM,IAAI;IACtB,MAAM,aAAa,MAAM,yBAAyB,SAC9C,OAAO,OACP,KAAA;IACJ,MAAM;GACR,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;GAEX,MAAM,QAAQ,SAAS,OAAO,WAAW,IAAI,IACzC,kBAAkB,WAClB,kBAAkB;GAEtB,MAAM,WAAoB,gBACxB,MAAM,UAAU,GAChB,UACF,CAAC,CAAC,KAAK,UACL,MAAM,SAAS,UACX,iBAAiB,OAAO,MAAM,OAAO,MAAM,eAAe,IAC1D,KACN;GAEA,IAAI,MAAM,gBACR,SAAS,KAAK,EAAE,mBAAmB,EAAE,QAAQ,WAAW,MAAM,CAAC,CAAC;GAIlE,OAAO,EAAE,mBAAmB,YAC1B,EACE,gBACA;IACE,OAAO;IACP,QAAQ,MAAM,UAAU,WAAW,MAAM,OAAO;IAChD,eAAe,MAAM;IACrB,mBAAmB;IACnB,cAAc,WAAW,MAAM;GACjC,SACM,QACR,CACF;EACF;CACF;AACF,CAAC;AAED,YAAY,iBAAiB;AAC7B,YAAY,KAAK"}
|
|
1
|
+
{"version":3,"file":"Modal.mjs","names":[],"sources":["../../../../../src/overlays/Modal.ts"],"sourcesContent":["import {\n AccentBox,\n ActionGroup,\n Button,\n ClearPropsContext,\n ColumnLayout,\n Content,\n Div,\n Header,\n Heading,\n OverlayContent,\n Section,\n Text,\n} from \"@/auto-generated\";\nimport { IconClose } from \"@/icons\";\nimport Action from \"@/components/Action\";\nimport { useLanguage } from \"@/composables/remoteContext\";\nimport { confirmCloseTexts } from \"@/overlays/locales\";\nimport {\n applyChildRules,\n dynamic,\n withSlotContent,\n type ChildRules,\n} from \"@/overlays/childProps\";\nimport { readProp } from \"@/lib/propKeys\";\nimport {\n createOverlayController,\n isOverlayController,\n provideOverlayContext,\n useConfirmOnCloseSource,\n useOwnController,\n useOverlayHandlers,\n type OverlayCloseHandler,\n type OverlayController,\n type OverlayOpenHandler,\n type OverlayOpenStateHandler,\n} from \"@/overlays/overlayController\";\nimport type { AnyRecord } from \"@/lib/types\";\nimport {\n defineComponent,\n h,\n onMounted,\n useId,\n watch,\n type Component,\n type PropType,\n type VNode,\n} from \"vue\";\nimport { composition } from \"@/lib/composition\";\nimport { useComponentUsage } from \"@/composables/useComponentUsage\";\n\nexport type ModalSize = \"s\" | \"m\" | \"l\";\n\n/*\n * Flow's `Modal` is a React composition, not a remote element: it renders an\n * `OverlayContent` and configures the components inside it through a props\n * context — the header, the content padding, the footer spacing. Both halves\n * are rebuilt here, so a Vue app writes `Modal` and not the overlay plumbing.\n *\n * The class names are Flow's own, taken from `Modal.module.scss` by way of the\n * generated `flow--…` names. They are internal, and repeating them is the price\n * of a composition that lives in React: the alternative — marking `Modal`\n * `@flr-generate`, so the host materialises the whole thing from one element —\n * would make this file unnecessary.\n */\nconst styles = {\n overlay: \"flow--overlay\",\n modal: \"flow--modal\",\n offCanvas: \"flow--modal--off-canvas\",\n left: \"flow--modal--left\",\n size: (size: ModalSize) => `flow--modal--size-${size}`,\n header: \"flow--modal--header\",\n headerTitle: \"flow--modal--header-title\",\n closeButton: \"flow--modal--close-button\",\n alwaysVisible: \"flow--modal--always-visible\",\n alwaysHidden: \"flow--modal--always-hidden\",\n content: \"flow--modal--content\",\n columnLayout: \"flow--modal--column-layout\",\n accentBox: \"flow--modal--accent-box\",\n actionGroup: \"flow--modal--action-group\",\n};\n\n/**\n * The chrome Flow puts around a modal's heading: the title in its own\n * container, and the close button beside it.\n *\n * Not props on the heading but a rebuild of what it was handed — the reason\n * `withSlotContent` exists. The close button clears the props context around\n * it, the way Flow's does, so the modal's own rules for `Button` do not reach\n * it, and it closes without asking again: this button _is_ the deliberate way\n * out.\n */\nconst withHeaderChrome = (\n heading: VNode,\n closeLabel: string,\n showCloseButton: boolean | undefined,\n): VNode =>\n withSlotContent(heading, (title) => [\n h(Div, { class: styles.headerTitle }, () => title),\n h(ClearPropsContext, null, () =>\n h(Action, { closeModal: { bypassConfirmation: true } }, () =>\n h(\n Button,\n {\n variant: \"plain\",\n color: \"secondary\",\n \"aria-label\": closeLabel,\n class: [\n styles.closeButton,\n showCloseButton === true\n ? styles.alwaysVisible\n : showCloseButton === false\n ? styles.alwaysHidden\n : undefined,\n ]\n .filter(Boolean)\n .join(\" \"),\n },\n () => h(IconClose),\n ),\n ),\n ),\n ]);\n\n/**\n * Lets an `Action` in the modal's footer close without asking again.\n *\n * Only where the action already closes something: Flow's props context rewrites\n * an existing `closeModal`/`closeOverlay` and adds none, and an `Action` that\n * merely runs something must not be turned into a close button. An explicit\n * `bypassConfirmation` in the object form wins, as in Flow.\n */\nconst withBypassedConfirmation = (child: VNode): AnyRecord | undefined => {\n if (child.type !== Action) {\n return undefined;\n }\n\n const bypassed: AnyRecord = {};\n\n for (const name of [\"closeModal\", \"closeOverlay\"]) {\n const value = readProp(child.props, name);\n\n if (value === undefined || value === null || value === false) {\n continue;\n }\n\n /*\n * A controller names the overlay, like a type name does — spread, it\n * would lose its identity and the action would close the modal instead.\n */\n bypassed[name] = dynamic(\n isOverlayController(value) || (typeof value === \"string\" && value !== \"\")\n ? { bypassConfirmation: true, overlay: value }\n : typeof value === \"object\"\n ? { bypassConfirmation: true, ...value }\n : { bypassConfirmation: true },\n );\n }\n\n return Object.keys(bypassed).length > 0 ? bypassed : undefined;\n};\n\n/*\n * Flow's `nestedHeadingProps`: inside the content, headings are one level\n * down, and a section drops its separator.\n */\nconst headingLevel3: ChildRules = (child) =>\n child.type === Heading ? { props: { level: 3 } } : undefined;\n\nconst nestedHeadingRules: ChildRules = (child) =>\n child.type === Heading\n ? { props: { level: 3 } }\n : child.type === Section\n ? {\n props: { hideSeparator: true },\n children: (grandChild) =>\n grandChild.type === Header\n ? { children: headingLevel3 }\n : headingLevel3(grandChild),\n }\n : child.type === Header\n ? { children: headingLevel3 }\n : undefined;\n\n/**\n * Asks before a modal that requires confirmation closes.\n *\n * Flow's `useCloseOverlayConfirmationController`: a controller of its own,\n * opened while the parent asks. A dismiss of this modal answers \"keep editing\",\n * and an answer from anywhere closes it again.\n *\n * Annotated rather than inferred — it renders a `Modal` and the `Modal` renders\n * it, and without an annotation TypeScript cannot break that cycle (TS7022).\n */\nconst ConfirmCloseModal: Component = defineComponent({\n name: \"ConfirmCloseModal\",\n\n props: {\n parent: {\n type: Object as PropType<OverlayController>,\n required: true,\n },\n },\n\n setup(props) {\n const language = useLanguage();\n const controller = createOverlayController();\n\n watch(\n () => props.parent.isConfirmingClose.value,\n (isConfirming) => (isConfirming ? controller.open() : controller.close()),\n { immediate: true },\n );\n\n controller.addOnClose(() => {\n if (props.parent.isConfirmingClose.value) {\n props.parent.cancelConfirmation();\n }\n });\n\n return () => {\n const texts = language.value?.startsWith(\"de\")\n ? confirmCloseTexts[\"de-DE\"]\n : confirmCloseTexts[\"en-US\"];\n\n return h(Modal, { controller }, () => [\n h(Heading, null, () => texts.heading),\n h(Content, null, () => h(Text, null, () => texts.text)),\n h(ActionGroup, null, () => [\n h(Action, { onAction: props.parent.confirmClose }, () =>\n h(Button, { color: \"danger\" }, () => texts.close),\n ),\n h(Action, { onAction: props.parent.cancelClose }, () =>\n h(\n Button,\n { color: \"secondary\", variant: \"soft\" },\n () => texts.keepOpen,\n ),\n ),\n ]),\n ]);\n };\n },\n});\n\nexport const Modal = defineComponent({\n name: \"Modal\",\n\n /* Like Flow's, a modal passes on only the props it knows. */\n inheritAttrs: false,\n\n props: {\n /** The size of the modal. @default \"s\" */\n size: { type: String as PropType<ModalSize>, default: \"s\" },\n /** Whether the modal is displayed as an off canvas. */\n offCanvas: { type: Boolean, default: false },\n /** Which side the off canvas comes from. @default \"right\" */\n offCanvasOrientation: {\n type: String as PropType<\"left\" | \"right\">,\n default: \"right\",\n },\n /** Whether a click outside closes the modal. @default true */\n isDismissable: { type: Boolean, default: true },\n /**\n * Whether the close button is always visible (`true`) or always hidden\n * (`false`). By default Flow decides by screen size.\n */\n showCloseButton: { type: Boolean, default: undefined },\n /**\n * Whether closing the modal has to be confirmed — use it to protect unsaved\n * changes.\n */\n confirmOnClose: { type: Boolean, default: undefined },\n /** A controller to open and close the modal from anywhere. */\n controller: {\n type: Object as PropType<OverlayController>,\n default: undefined,\n },\n /** Whether the modal is open. Use it to control the modal state. */\n isOpen: { type: Boolean, default: undefined },\n /**\n * Whether the modal is open initially, when it has a controller of its own\n * — not one from a trigger or the `controller` prop. @default false\n */\n isDefaultOpen: { type: Boolean, default: undefined },\n /** Called when the modal opens. Returning `false` keeps it closed. */\n onOpen: {\n type: Function as PropType<OverlayOpenHandler>,\n default: undefined,\n },\n /** Called when the modal closes. Returning `false` keeps it open. */\n onClose: {\n type: Function as PropType<OverlayCloseHandler>,\n default: undefined,\n },\n /**\n * Called with the new state whenever the modal opens or closes. Returning\n * `false` aborts the change.\n */\n onOpenChange: {\n type: Function as PropType<OverlayOpenStateHandler>,\n default: undefined,\n },\n },\n\n setup(props, { slots, attrs }) {\n /* Flow's React `Modal` is a `flowComponent` and reports itself. */\n onMounted(useComponentUsage(\"Modal\"));\n\n const language = useLanguage();\n /*\n * The dialog is labelled by its own heading, so the two need an id they\n * agree on. Flow generates one with `useId`; `useId` exists in Vue too,\n * and both sides end up with an id the host rewrites anyway — what has to\n * match is that the heading carries one at all.\n */\n const headingId = useId();\n /*\n * Three ways to own the state, in Flow's order of precedence: a\n * controller the app passes, the controller of a surrounding trigger, or\n * one of its own.\n */\n const controller = useOwnController(\n () => props.controller,\n \"Modal\",\n () => ({ isDefaultOpen: props.isDefaultOpen }),\n );\n\n // So an `Action` inside finds it.\n provideOverlayContext(\"Modal\", () => controller.value);\n\n useOverlayHandlers(() => controller.value, {\n onOpen: () => props.onOpen,\n onClose: () => props.onClose,\n onOpenChange: () => props.onOpenChange,\n });\n\n /*\n * The requirement lives on the controller, not on this component: what\n * asks for the confirmation is a close, and a close arrives at the\n * controller — from an `Action` inside, from the host's dismiss, or from\n * an app holding the controller itself. It is one source among others,\n * withdrawn when the modal unmounts or its controller changes, because\n * the controller usually outlives the modal.\n */\n useConfirmOnCloseSource(\n () => controller.value,\n () => props.confirmOnClose,\n );\n\n /* Flow's props context for the modal's children, rule for rule. */\n const childRules: ChildRules = (child) => {\n if (child.type === Heading) {\n return { props: { class: styles.header, level: 2, id: headingId } };\n }\n if (child.type === Content) {\n return {\n props: { class: styles.content },\n children: nestedHeadingRules,\n };\n }\n if (child.type === ColumnLayout) {\n return {\n props: { class: styles.columnLayout, l: [2, 1], m: [1] },\n children: (grandChild) =>\n grandChild.type === AccentBox\n ? {\n props: {\n class: styles.accentBox,\n backgroundColor: \"neutral\",\n },\n }\n : nestedHeadingRules(grandChild),\n };\n }\n if (child.type === ActionGroup) {\n /*\n * The footer is the deliberate way out, so its actions close\n * without asking again — the rule Flow's `Modal` writes for\n * `ActionGroup > Action`. An `Action` anywhere else in the modal is\n * an incidental close and is confirmed.\n */\n return {\n props: { class: styles.actionGroup, spacing: \"m\" },\n children: (grandChild) => {\n const props = withBypassedConfirmation(grandChild);\n return props ? { props } : undefined;\n },\n };\n }\n return undefined;\n };\n\n return () => {\n const className = [\n styles.overlay,\n props.offCanvas ? styles.offCanvas : styles.modal,\n styles.size(props.size),\n props.offCanvas && props.offCanvasOrientation === \"left\"\n ? styles.left\n : undefined,\n attrs.class,\n ]\n .filter(Boolean)\n .join(\" \");\n\n const texts = language.value?.startsWith(\"de\")\n ? confirmCloseTexts[\"de-DE\"]\n : confirmCloseTexts[\"en-US\"];\n\n const children: VNode[] = applyChildRules(\n slots.default?.(),\n childRules,\n ).map((child) =>\n child.type === Heading\n ? withHeaderChrome(child, texts.close, props.showCloseButton)\n : child,\n );\n\n if (controller.value.confirmOnClose.value) {\n children.push(h(ConfirmCloseModal, { parent: controller.value }));\n }\n\n /* A UI component: Flow clears the host's props context around it. */\n return h(ClearPropsContext, null, () =>\n h(\n OverlayContent,\n {\n class: className,\n isOpen: props.isOpen ?? controller.value.isOpen.value,\n isDismissable: props.isDismissable,\n \"aria-labelledby\": headingId,\n onOpenChange: controller.value.setOpen,\n },\n () => children,\n ),\n );\n };\n },\n});\n\ncomposition(ConfirmCloseModal);\ncomposition(Modal);\n\nexport default Modal;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiEA,IAAM,SAAS;CACb,SAAS;CACT,OAAO;CACP,WAAW;CACX,MAAM;CACN,OAAO,SAAoB,qBAAqB;CAChD,QAAQ;CACR,aAAa;CACb,aAAa;CACb,eAAe;CACf,cAAc;CACd,SAAS;CACT,cAAc;CACd,WAAW;CACX,aAAa;AACf;;;;;;;;;;;AAYA,IAAM,oBACJ,SACA,YACA,oBAEA,gBAAgB,UAAU,UAAU,CAClC,EAAE,KAAK,EAAE,OAAO,OAAO,YAAY,SAAS,KAAK,GACjD,EAAE,mBAAmB,YACnB,EAAE,QAAQ,EAAE,YAAY,EAAE,oBAAoB,KAAK,EAAE,SACnD,EACE,QACA;CACE,SAAS;CACT,OAAO;CACP,cAAc;CACd,OAAO,CACL,OAAO,aACP,oBAAoB,OAChB,OAAO,gBACP,oBAAoB,QAClB,OAAO,eACP,KAAA,CACR,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;AACb,SACM,EAAE,SAAS,CACnB,CACF,CACF,CACF,CAAC;;;;;;;;;AAUH,IAAM,4BAA4B,UAAwC;CACxE,IAAI,MAAM,SAAS,QACjB;CAGF,MAAM,WAAsB,CAAC;CAE7B,KAAK,MAAM,QAAQ,CAAC,cAAc,cAAc,GAAG;EACjD,MAAM,QAAQ,SAAS,MAAM,OAAO,IAAI;EAExC,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,UAAU,OACrD;EAOF,SAAS,QAAQ,QACf,oBAAoB,KAAK,K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AAC;GAIlE,OAAO,EAAE,mBAAmB,YAC1B,EACE,gBACA;IACE,OAAO;IACP,QAAQ,MAAM,UAAU,WAAW,MAAM,OAAO;IAChD,eAAe,MAAM;IACrB,mBAAmB;IACnB,cAAc,WAAW,MAAM;GACjC,SACM,QACR,CACF;EACF;CACF;AACF,CAAC;AAED,YAAY,iBAAiB;AAC7B,YAAY,KAAK"}
|
|
@@ -1,72 +1,67 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OverlayState } from "../../../components-base/src/overlay/OverlayState.mjs";
|
|
2
|
+
import "../../../components-base/src/index.mjs";
|
|
3
|
+
import { computed, customRef, inject, markRaw, provide, watchEffect } from "vue";
|
|
4
|
+
import { reaction, runInAction } from "mobx";
|
|
2
5
|
//#region src/overlays/overlayController.ts
|
|
3
|
-
var
|
|
6
|
+
var states = /* @__PURE__ */ new WeakMap();
|
|
4
7
|
/** Whether a value is a controller, rather than options naming one. */
|
|
5
|
-
var isOverlayController = (value) => typeof value === "object" && value !== null &&
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*/
|
|
15
|
-
var createOverlayControllerFor = (isOpen) => {
|
|
16
|
-
const confirmOnClose = ref(false);
|
|
17
|
-
const isConfirmingClose = ref(false);
|
|
18
|
-
const onOpenHandlers = /* @__PURE__ */ new Set();
|
|
19
|
-
const onCloseHandlers = /* @__PURE__ */ new Set();
|
|
20
|
-
const onOpenChangeHandlers = /* @__PURE__ */ new Set();
|
|
21
|
-
let inFlight;
|
|
22
|
-
const apply = (toOpen) => {
|
|
23
|
-
if (isOpen.value === toOpen || inFlight === toOpen) return;
|
|
24
|
-
inFlight = toOpen;
|
|
25
|
-
try {
|
|
26
|
-
const run = (handlers) => [...handlers].map((handler) => handler(toOpen)).includes(false);
|
|
27
|
-
if (!(run(toOpen ? onOpenHandlers : onCloseHandlers) || run(onOpenChangeHandlers))) isOpen.value = toOpen;
|
|
28
|
-
} finally {
|
|
29
|
-
inFlight = void 0;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const open = () => {
|
|
33
|
-
isConfirmingClose.value = false;
|
|
34
|
-
apply(true);
|
|
35
|
-
};
|
|
36
|
-
const closeNow = () => {
|
|
37
|
-
isConfirmingClose.value = false;
|
|
38
|
-
apply(false);
|
|
39
|
-
};
|
|
40
|
-
const close = (options = {}) => {
|
|
41
|
-
if (!options.bypassConfirmation && confirmOnClose.value && isOpen.value) {
|
|
42
|
-
isConfirmingClose.value = true;
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
closeNow();
|
|
8
|
+
var isOverlayController = (value) => typeof value === "object" && value !== null && states.has(value);
|
|
9
|
+
var stateRef = (read, write) => customRef((track, trigger) => {
|
|
10
|
+
reaction(read, trigger);
|
|
11
|
+
return {
|
|
12
|
+
get: () => {
|
|
13
|
+
track();
|
|
14
|
+
return read();
|
|
15
|
+
},
|
|
16
|
+
set: write
|
|
46
17
|
};
|
|
18
|
+
});
|
|
19
|
+
var createOverlayController = (options = {}) => {
|
|
20
|
+
const state = new OverlayState({ isDefaultOpen: options.isDefaultOpen });
|
|
21
|
+
const ownSource = {};
|
|
47
22
|
const controller = {
|
|
48
|
-
isOpen,
|
|
49
|
-
confirmOnClose,
|
|
50
|
-
isConfirmingClose,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
23
|
+
isOpen: stateRef(() => state.isOpen, state.syncOpen),
|
|
24
|
+
confirmOnClose: stateRef(() => state.confirmOnCloseEnabled, (confirmOnClose) => confirmOnClose ? state.setConfirmOnCloseSource(ownSource, true) : state.removeConfirmOnCloseSource(ownSource)),
|
|
25
|
+
isConfirmingClose: stateRef(() => state.showConfirmationModal, (isConfirming) => {
|
|
26
|
+
if (!isConfirming) state.cancelConfirmation();
|
|
27
|
+
}),
|
|
28
|
+
isContentSuspended: stateRef(() => state.isContentSuspended, state.setIsContentSuspended),
|
|
29
|
+
open: state.open,
|
|
30
|
+
close: state.close,
|
|
31
|
+
toggle: state.toggle,
|
|
32
|
+
setOpen: state.setOpen,
|
|
33
|
+
syncOpen: state.syncOpen,
|
|
34
|
+
requestClose: () => state.close(),
|
|
35
|
+
confirmClose: () => runInAction(() => {
|
|
36
|
+
state.confirmClose();
|
|
37
|
+
state.close();
|
|
38
|
+
}),
|
|
39
|
+
cancelClose: state.cancelConfirmation,
|
|
40
|
+
cancelConfirmation: state.cancelConfirmation,
|
|
41
|
+
grantCloseWithoutConfirmation: () => state.grantCloseWithoutConfirmation(),
|
|
42
|
+
addOnOpen: (handler) => state.addOnOpen(handler),
|
|
43
|
+
addOnClose: (handler) => state.addOnClose(handler),
|
|
44
|
+
addOnOpenChange: (handler) => state.addOnOpenChange(handler)
|
|
65
45
|
};
|
|
66
|
-
|
|
46
|
+
states.set(markRaw(controller), state);
|
|
67
47
|
return controller;
|
|
68
48
|
};
|
|
69
49
|
/**
|
|
50
|
+
* Registers a component's opinion on close confirmation for as long as it is
|
|
51
|
+
* mounted — Flow's `useConfirmOnCloseSource`. `undefined` contributes nothing,
|
|
52
|
+
* so the other sources decide.
|
|
53
|
+
*/
|
|
54
|
+
var useConfirmOnCloseSource = (controller, confirmOnClose) => {
|
|
55
|
+
const source = {};
|
|
56
|
+
watchEffect((onCleanup) => {
|
|
57
|
+
const state = states.get(controller());
|
|
58
|
+
const value = confirmOnClose();
|
|
59
|
+
if (!state || value === void 0) return;
|
|
60
|
+
state.setConfirmOnCloseSource(source, value);
|
|
61
|
+
onCleanup(() => state.removeConfirmOnCloseSource(source));
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
70
65
|
* Registers an overlay's `onOpen`/`onClose`/`onOpenChange` props on its
|
|
71
66
|
* controller for as long as it is mounted — Flow's `useUpdateOptions`.
|
|
72
67
|
*/
|
|
@@ -84,7 +79,6 @@ var useOverlayHandlers = (controller, handlers) => {
|
|
|
84
79
|
onCleanup(() => disposers.forEach((dispose) => dispose?.()));
|
|
85
80
|
});
|
|
86
81
|
};
|
|
87
|
-
var createOverlayController = (options = {}) => createOverlayControllerFor(ref(options.isDefaultOpen ?? false));
|
|
88
82
|
function useOverlayController(typeOrOptions, options = {}) {
|
|
89
83
|
if (typeof typeOrOptions !== "string") return createOverlayController(typeOrOptions);
|
|
90
84
|
const { reuseControllerFromContext = true } = options;
|
|
@@ -137,6 +131,6 @@ var injectOverlayController = (type) => {
|
|
|
137
131
|
return type ? context.byType[type] : context.nearest;
|
|
138
132
|
};
|
|
139
133
|
//#endregion
|
|
140
|
-
export { createOverlayController,
|
|
134
|
+
export { createOverlayController, injectOverlayContext, injectOverlayController, isOverlayController, provideOverlayContext, useConfirmOnCloseSource, useModalController, useOverlayController, useOverlayHandlers, useOwnController };
|
|
141
135
|
|
|
142
136
|
//# sourceMappingURL=overlayController.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlayController.mjs","names":[],"sources":["../../../../../src/overlays/overlayController.ts"],"sourcesContent":["import {\n computed,\n inject,\n markRaw,\n provide,\n ref,\n watchEffect,\n type ComputedRef,\n type InjectionKey,\n type Raw,\n type Ref,\n} from \"vue\";\n\n/**\n * The Vue counterpart of Flow's `OverlayController`.\n *\n * Flow's version is a MobX model shared through React context; here the state\n * is a `ref` and the sharing is `provide`/`inject`. Same contract: a trigger\n * opens it, the overlay reads it, and anything inside can close it.\n */\nexport type OverlayOpenHandler = () => unknown;\nexport type OverlayCloseHandler = () => unknown;\nexport type OverlayOpenStateHandler = (isOpen: boolean) => unknown;\n\nexport interface OverlayCloseOptions {\n /** Close without asking, even when the overlay requires confirmation. */\n bypassConfirmation?: boolean;\n}\n\n/*\n * `Raw`, as `markRaw` makes it: reactive state keeps the controller as it is,\n * and its type says so too.\n */\nexport interface OverlayController extends Raw<Record<never, never>> {\n isOpen: Ref<boolean>;\n /**\n * Whether closing has to be confirmed first. Set by a `<Modal\n * confirm-on-close>`, not by the app.\n */\n confirmOnClose: Ref<boolean>;\n /** Whether the confirmation is on screen right now. */\n isConfirmingClose: Ref<boolean>;\n open: () => void;\n /**\n * Closes — or asks first, when the overlay requires confirmation and\n * `bypassConfirmation` is not set. Flow's `close(options)`.\n */\n close: (options?: OverlayCloseOptions) => void;\n toggle: () => void;\n setOpen: (isOpen: boolean, options?: OverlayCloseOptions) => void;\n /**\n * Sets the state without running a handler — to mirror a controlled `isOpen`,\n * whose change came from the app.\n */\n syncOpen: (isOpen: boolean) => void;\n /** `close()` without options: asks first, when the overlay requires it. */\n requestClose: () => void;\n /** Answers a pending confirmation with yes: the overlay closes. */\n confirmClose: () => void;\n /** Answers a pending confirmation with no: the overlay stays open. */\n cancelClose: () => void;\n /** Flow's name for `cancelClose`. */\n cancelConfirmation: () => void;\n /*\n * As in Flow: a handler returning `false` aborts the change. Each returns\n * its disposer.\n */\n addOnOpen: (handler: OverlayOpenHandler) => () => void;\n addOnClose: (handler: OverlayCloseHandler) => () => void;\n addOnOpenChange: (handler: OverlayOpenStateHandler) => () => void;\n}\n\nexport interface CreateOverlayControllerOptions {\n /** Whether the overlay starts open. @default false */\n isDefaultOpen?: boolean;\n}\n\nexport interface UseOverlayControllerOptions extends CreateOverlayControllerOptions {\n /**\n * Hand back the controller of the surrounding overlay of the requested type,\n * when there is one, instead of a new one — as in Flow. @default true\n */\n reuseControllerFromContext?: boolean;\n}\n\nconst controllers = new WeakSet<object>();\n\n/** Whether a value is a controller, rather than options naming one. */\nexport const isOverlayController = (\n value: unknown,\n): value is OverlayController =>\n typeof value === \"object\" && value !== null && controllers.has(value);\n\nconst addTo =\n <T>(handlers: Set<T>) =>\n (handler: T): (() => void) => {\n handlers.add(handler);\n return () => handlers.delete(handler);\n };\n\n/**\n * Builds a controller around an existing `isOpen`, so a second controller can\n * drive the same state — which is how the confirmation modal is bound to its\n * parent's `isConfirmingClose`.\n */\nexport const createOverlayControllerFor = (\n isOpen: Ref<boolean>,\n): OverlayController => {\n const confirmOnClose = ref(false);\n const isConfirmingClose = ref(false);\n const onOpenHandlers = new Set<OverlayOpenHandler>();\n const onCloseHandlers = new Set<OverlayCloseHandler>();\n const onOpenChangeHandlers = new Set<OverlayOpenStateHandler>();\n /* Flow's `openStateInFlight`: a handler setting the state again is a no-op. */\n let inFlight: boolean | undefined;\n\n /* Flow's `applyOpenState`, after the confirmation. */\n const apply = (toOpen: boolean): void => {\n if (isOpen.value === toOpen || inFlight === toOpen) {\n return;\n }\n inFlight = toOpen;\n try {\n const run = (handlers: Set<(isOpen: boolean) => unknown>) =>\n [...handlers].map((handler) => handler(toOpen)).includes(false);\n const aborted =\n run(toOpen ? onOpenHandlers : onCloseHandlers) ||\n run(onOpenChangeHandlers);\n if (!aborted) {\n isOpen.value = toOpen;\n }\n } finally {\n inFlight = undefined;\n }\n };\n\n const open = () => {\n isConfirmingClose.value = false;\n apply(true);\n };\n\n const closeNow = () => {\n isConfirmingClose.value = false;\n apply(false);\n };\n\n /*\n * Every close an app or the host can ask for goes through here, so a dismiss\n * — Escape, a click outside — is confirmed just like a button. The host\n * reports that dismiss as `openChange(false)`, and leaving `isOpen` alone is\n * what puts the overlay back: it is a controlled prop on the host's side.\n */\n const close = (options: OverlayCloseOptions = {}) => {\n if (!options.bypassConfirmation && confirmOnClose.value && isOpen.value) {\n isConfirmingClose.value = true;\n return;\n }\n closeNow();\n };\n\n const controller: OverlayController = {\n isOpen,\n confirmOnClose,\n isConfirmingClose,\n open,\n close,\n toggle: () => (isOpen.value ? close() : open()),\n setOpen: (nextIsOpen: boolean, options?: OverlayCloseOptions) =>\n nextIsOpen ? open() : close(options),\n syncOpen: (nextIsOpen: boolean) => {\n isOpen.value = nextIsOpen;\n },\n requestClose: () => close(),\n confirmClose: closeNow,\n cancelClose: () => (isConfirmingClose.value = false),\n cancelConfirmation: () => (isConfirmingClose.value = false),\n addOnOpen: addTo(onOpenHandlers),\n addOnClose: addTo(onCloseHandlers),\n addOnOpenChange: addTo(onOpenChangeHandlers),\n };\n /*\n * Raw, so `reactive()`, `ref()` or a store hold the controller itself: a\n * proxy would unwrap its refs and miss the `controllers` set.\n */\n controllers.add(markRaw(controller));\n return controller;\n};\n\n/**\n * Registers an overlay's `onOpen`/`onClose`/`onOpenChange` props on its\n * controller for as long as it is mounted — Flow's `useUpdateOptions`.\n */\nexport const useOverlayHandlers = (\n controller: () => OverlayController,\n handlers: {\n onOpen?: () => OverlayOpenHandler | undefined;\n onClose?: () => OverlayCloseHandler | undefined;\n onOpenChange?: () => OverlayOpenStateHandler | undefined;\n },\n): void => {\n watchEffect((onCleanup) => {\n const target = controller();\n const onOpen = handlers.onOpen?.();\n const onClose = handlers.onClose?.();\n const onOpenChange = handlers.onOpenChange?.();\n const disposers = [\n onOpen && target.addOnOpen(onOpen),\n onClose && target.addOnClose(onClose),\n onOpenChange && target.addOnOpenChange(onOpenChange),\n ];\n onCleanup(() => disposers.forEach((dispose) => dispose?.()));\n });\n};\n\nexport const createOverlayController = (\n options: CreateOverlayControllerOptions = {},\n): OverlayController =>\n createOverlayControllerFor(ref(options.isDefaultOpen ?? false));\n\n/**\n * A controller an app can hold itself, to open an overlay from anywhere —\n * Flow's `useOverlayController(type, options)`. Given a type, it hands back the\n * surrounding overlay's controller of that type when there is one, as Flow\n * does; `reuseControllerFromContext: false` asks for a new one regardless.\n *\n * Also takes the options alone, for a controller that belongs to no type. Call\n * it in `setup()`: the surrounding overlay is found through `inject`.\n */\nexport function useOverlayController(\n type: OverlayType,\n options?: UseOverlayControllerOptions,\n): OverlayController;\nexport function useOverlayController(\n options?: CreateOverlayControllerOptions,\n): OverlayController;\nexport function useOverlayController(\n typeOrOptions?: OverlayType | CreateOverlayControllerOptions,\n options: UseOverlayControllerOptions = {},\n): OverlayController {\n if (typeof typeOrOptions !== \"string\") {\n return createOverlayController(typeOrOptions);\n }\n const { reuseControllerFromContext = true } = options;\n const fromContext = reuseControllerFromContext\n ? injectOverlayController(typeOrOptions)\n : undefined;\n return fromContext ?? createOverlayController(options);\n}\n\n/**\n * Flow's `useModalController(options)`: `useOverlayController(\"Modal\",\n * options)`.\n */\nexport const useModalController = (\n options?: UseOverlayControllerOptions,\n): OverlayController => useOverlayController(\"Modal\", options);\n\n/** The overlays a controller can be registered for, by Flow component name. */\nexport type OverlayType = \"Modal\" | \"Popover\" | \"LightBox\";\n\n/**\n * Flow's `OverlayContext`: the surrounding overlays' controllers by component\n * name, and the one whose content this subtree is. A trigger registers its\n * controller by name only — its button is not inside the overlay it opens.\n */\nexport interface OverlayContext {\n byType: Partial<Record<OverlayType, OverlayController>>;\n nearest?: OverlayController;\n}\n\nconst overlayContextKey: InjectionKey<OverlayContext> =\n Symbol(\"flowOverlayContext\");\n\nexport const injectOverlayContext = (): OverlayContext =>\n inject(overlayContextKey, { byType: {} });\n\n/**\n * Provides the context for a subtree. The controller may be a getter: an\n * overlay whose `controller` prop changes hands its subtree the new one, and\n * the context reads it when it is asked rather than when it was provided.\n */\nexport const provideOverlayContext = (\n type: OverlayType,\n controller: OverlayController | (() => OverlayController),\n options: { isOverlayContent?: boolean } = {},\n): void => {\n const { isOverlayContent = true } = options;\n const parent = injectOverlayContext();\n const current =\n typeof controller === \"function\" ? controller : () => controller;\n\n provide(overlayContextKey, {\n get byType() {\n return { ...parent.byType, [type]: current() };\n },\n get nearest() {\n return isOverlayContent ? current() : parent.nearest;\n },\n });\n};\n\n/**\n * The controller an overlay or trigger drives, in Flow's order of precedence:\n * the one the app passes, the one of a surrounding trigger of that type, or one\n * of its own. It follows the prop — Flow reads it on every render.\n */\nexport const useOwnController = (\n fromProp: () => OverlayController | undefined,\n inheritFrom: OverlayType | undefined,\n options: () => CreateOverlayControllerOptions = () => ({}),\n): ComputedRef<OverlayController> => {\n const context = injectOverlayContext();\n let own: OverlayController | undefined;\n\n return computed(\n () =>\n fromProp() ??\n (inheritFrom ? context.byType[inheritFrom] : undefined) ??\n (own ??= createOverlayController(options())),\n );\n};\n\n/**\n * The controller of the surrounding overlay of that type — or, without a type,\n * of the overlay this component is inside.\n */\nexport const injectOverlayController = (\n type?: OverlayType,\n): OverlayController | undefined => {\n const context = injectOverlayContext();\n return type ? context.byType[type] : context.nearest;\n};\n"],"mappings":";;AAqFA,IAAM,8BAAc,IAAI,QAAgB;;AAGxC,IAAa,uBACX,UAEA,OAAO,UAAU,YAAY,UAAU,QAAQ,YAAY,IAAI,KAAK;AAEtE,IAAM,SACA,cACH,YAA6B;CAC5B,SAAS,IAAI,OAAO;CACpB,aAAa,SAAS,OAAO,OAAO;AACtC;;;;;;AAOF,IAAa,8BACX,WACsB;CACtB,MAAM,iBAAiB,IAAI,KAAK;CAChC,MAAM,oBAAoB,IAAI,KAAK;CACnC,MAAM,iCAAiB,IAAI,IAAwB;CACnD,MAAM,kCAAkB,IAAI,IAAyB;CACrD,MAAM,uCAAuB,IAAI,IAA6B;CAE9D,IAAI;CAGJ,MAAM,SAAS,WAA0B;EACvC,IAAI,OAAO,UAAU,UAAU,aAAa,QAC1C;EAEF,WAAW;EACX,IAAI;GACF,MAAM,OAAO,aACX,CAAC,GAAG,QAAQ,CAAC,CAAC,KAAK,YAAY,QAAQ,MAAM,CAAC,CAAC,CAAC,SAAS,KAAK;GAIhE,IAAI,EAFF,IAAI,SAAS,iBAAiB,eAAe,KAC7C,IAAI,oBAAoB,IAExB,OAAO,QAAQ;EAEnB,UAAU;GACR,WAAW,KAAA;EACb;CACF;CAEA,MAAM,aAAa;EACjB,kBAAkB,QAAQ;EAC1B,MAAM,IAAI;CACZ;CAEA,MAAM,iBAAiB;EACrB,kBAAkB,QAAQ;EAC1B,MAAM,KAAK;CACb;CAQA,MAAM,SAAS,UAA+B,CAAC,MAAM;EACnD,IAAI,CAAC,QAAQ,sBAAsB,eAAe,SAAS,OAAO,OAAO;GACvE,kBAAkB,QAAQ;GAC1B;EACF;EACA,SAAS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IAAa,yBACX,MACA,YACA,UAA0C,CAAC,MAClC;CACT,MAAM,EAAE,mBAAmB,SAAS;CACpC,MAAM,SAAS,qBAAqB;CACpC,MAAM,UACJ,OAAO,eAAe,aAAa,mBAAmB;CAExD,QAAQ,mBAAmB;EACzB,IAAI,SAAS;GACX,OAAO;IAAE,GAAG,OAAO;KAAS,OAAO,QAAQ;GAAE;EAC/C;EACA,IAAI,UAAU;GACZ,OAAO,mBAAmB,QAAQ,IAAI,OAAO;EAC/C;CACF,CAAC;AACH;;;;;;AAOA,IAAa,oBACX,UACA,aACA,iBAAuD,CAAC,OACrB;CACnC,MAAM,UAAU,qBAAqB;CACrC,IAAI;CAEJ,OAAO,eAEH,SAAS,MACR,cAAc,QAAQ,OAAO,eAAe,KAAA,OAC5C,QAAQ,wBAAwB,QAAQ,CAAC,EAC9C;AACF;;;;;AAMA,IAAa,2BACX,SACkC;CAClC,MAAM,UAAU,qBAAqB;CACrC,OAAO,OAAO,QAAQ,OAAO,QAAQ,QAAQ;AAC/C"}
|
|
1
|
+
{"version":3,"file":"overlayController.mjs","names":[],"sources":["../../../../../src/overlays/overlayController.ts"],"sourcesContent":["import {\n OverlayState,\n type OverlayCloseHandler,\n type OverlayCloseOptions,\n type OverlayOpenHandler,\n type OverlayOpenStateHandler,\n} from \"@mittwald/flow-components-base\";\nimport { reaction, runInAction } from \"mobx\";\nimport {\n computed,\n customRef,\n inject,\n markRaw,\n provide,\n watchEffect,\n type ComputedRef,\n type InjectionKey,\n type Raw,\n type Ref,\n} from \"vue\";\n\nexport type {\n OverlayCloseHandler,\n OverlayCloseOptions,\n OverlayOpenHandler,\n OverlayOpenStateHandler,\n} from \"@mittwald/flow-components-base\";\n\n/**\n * The Vue counterpart of Flow's `OverlayController`.\n *\n * The state is `OverlayState` from `@mittwald/flow-components-base`, the one\n * React's controller runs on; this wraps it in refs and shares it through\n * `provide`/`inject`. Same contract: a trigger opens it, the overlay reads it,\n * and anything inside can close it.\n *\n * `Raw`, as `markRaw` makes it: reactive state keeps the controller as it is,\n * and its type says so too.\n */\nexport interface OverlayController extends Raw<Record<never, never>> {\n /** Writing it sets the state without running a handler, like `syncOpen`. */\n isOpen: Ref<boolean>;\n /**\n * Whether closing has to be confirmed first — combined from every source: a\n * `<Modal confirm-on-close>` and what the app writes here.\n */\n confirmOnClose: Ref<boolean>;\n /**\n * Whether the confirmation is on screen right now. Writing `false` dismisses\n * it; only a close shows it.\n */\n isConfirmingClose: Ref<boolean>;\n /** Whether the overlay's content is suspended. Not used by this binding yet. */\n isContentSuspended: Ref<boolean>;\n open: () => void;\n /**\n * Closes — or asks first, when the overlay requires confirmation and\n * `bypassConfirmation` is not set. Flow's `close(options)`.\n */\n close: (options?: OverlayCloseOptions) => void;\n toggle: () => void;\n setOpen: (isOpen: boolean, options?: OverlayCloseOptions) => void;\n /**\n * Sets the state without running a handler — to mirror a controlled `isOpen`,\n * whose change came from the app.\n */\n syncOpen: (isOpen: boolean) => void;\n /** `close()` without options: asks first, when the overlay requires it. */\n requestClose: () => void;\n /** Answers a pending confirmation with yes: the overlay closes. */\n confirmClose: () => void;\n /** Answers a pending confirmation with no: the overlay stays open. */\n cancelClose: () => void;\n /** Flow's name for `cancelClose`. */\n cancelConfirmation: () => void;\n /**\n * Closes without a confirmation until the returned disposer is called — as in\n * Flow, around an operation that closes the overlay deliberately.\n */\n grantCloseWithoutConfirmation: () => () => void;\n /*\n * As in Flow: a handler returning `false` aborts the change. Each returns\n * its disposer.\n */\n addOnOpen: (handler: OverlayOpenHandler) => () => void;\n addOnClose: (handler: OverlayCloseHandler) => () => void;\n addOnOpenChange: (handler: OverlayOpenStateHandler) => () => void;\n}\n\nexport interface CreateOverlayControllerOptions {\n /** Whether the overlay starts open. @default false */\n isDefaultOpen?: boolean;\n}\n\nexport interface UseOverlayControllerOptions extends CreateOverlayControllerOptions {\n /**\n * Hand back the controller of the surrounding overlay of the requested type,\n * when there is one, instead of a new one — as in Flow. @default true\n */\n reuseControllerFromContext?: boolean;\n}\n\n/* Each controller's state, which is also how a controller is recognized. */\nconst states = new WeakMap<object, OverlayState>();\n\n/** Whether a value is a controller, rather than options naming one. */\nexport const isOverlayController = (\n value: unknown,\n): value is OverlayController =>\n typeof value === \"object\" && value !== null && states.has(value);\n\n/*\n * A ref over one value of the state: a read subscribes through MobX, a write\n * goes to the state. The reaction lives as long as the controller does — it\n * is held by nothing but the state it observes.\n */\nconst stateRef = <T>(read: () => T, write: (value: T) => void): Ref<T> =>\n customRef((track, trigger) => {\n reaction(read, trigger);\n return {\n get: () => {\n track();\n return read();\n },\n set: write,\n };\n });\n\nexport const createOverlayController = (\n options: CreateOverlayControllerOptions = {},\n): OverlayController => {\n const state = new OverlayState({ isDefaultOpen: options.isDefaultOpen });\n /* The source an app sets through `confirmOnClose.value`. */\n const ownSource = {};\n\n const controller: OverlayController = {\n isOpen: stateRef(() => state.isOpen, state.syncOpen),\n confirmOnClose: stateRef(\n () => state.confirmOnCloseEnabled,\n (confirmOnClose) =>\n confirmOnClose\n ? state.setConfirmOnCloseSource(ownSource, true)\n : state.removeConfirmOnCloseSource(ownSource),\n ),\n isConfirmingClose: stateRef(\n () => state.showConfirmationModal,\n (isConfirming) => {\n if (!isConfirming) {\n state.cancelConfirmation();\n }\n },\n ),\n isContentSuspended: stateRef(\n () => state.isContentSuspended,\n state.setIsContentSuspended,\n ),\n open: state.open,\n close: state.close,\n toggle: state.toggle,\n setOpen: state.setOpen,\n syncOpen: state.syncOpen,\n requestClose: () => state.close(),\n /*\n * React's `useCloseOverlayConfirmationController` confirms the same way.\n * One action, so no observer sees the confirmation gone and the overlay\n * still open.\n */\n confirmClose: () =>\n runInAction(() => {\n state.confirmClose();\n state.close();\n }),\n cancelClose: state.cancelConfirmation,\n cancelConfirmation: state.cancelConfirmation,\n grantCloseWithoutConfirmation: () => state.grantCloseWithoutConfirmation(),\n addOnOpen: (handler) => state.addOnOpen(handler),\n addOnClose: (handler) => state.addOnClose(handler),\n addOnOpenChange: (handler) => state.addOnOpenChange(handler),\n };\n /*\n * Raw, so `reactive()`, `ref()` or a store hold the controller itself: a\n * proxy would unwrap its refs and miss the `states` map.\n */\n states.set(markRaw(controller), state);\n return controller;\n};\n\n/**\n * Registers a component's opinion on close confirmation for as long as it is\n * mounted — Flow's `useConfirmOnCloseSource`. `undefined` contributes nothing,\n * so the other sources decide.\n */\nexport const useConfirmOnCloseSource = (\n controller: () => OverlayController,\n confirmOnClose: () => boolean | undefined,\n): void => {\n const source = {};\n\n watchEffect((onCleanup) => {\n const state = states.get(controller());\n const value = confirmOnClose();\n if (!state || value === undefined) {\n return;\n }\n state.setConfirmOnCloseSource(source, value);\n onCleanup(() => state.removeConfirmOnCloseSource(source));\n });\n};\n\n/**\n * Registers an overlay's `onOpen`/`onClose`/`onOpenChange` props on its\n * controller for as long as it is mounted — Flow's `useUpdateOptions`.\n */\nexport const useOverlayHandlers = (\n controller: () => OverlayController,\n handlers: {\n onOpen?: () => OverlayOpenHandler | undefined;\n onClose?: () => OverlayCloseHandler | undefined;\n onOpenChange?: () => OverlayOpenStateHandler | undefined;\n },\n): void => {\n watchEffect((onCleanup) => {\n const target = controller();\n const onOpen = handlers.onOpen?.();\n const onClose = handlers.onClose?.();\n const onOpenChange = handlers.onOpenChange?.();\n const disposers = [\n onOpen && target.addOnOpen(onOpen),\n onClose && target.addOnClose(onClose),\n onOpenChange && target.addOnOpenChange(onOpenChange),\n ];\n onCleanup(() => disposers.forEach((dispose) => dispose?.()));\n });\n};\n\n/**\n * A controller an app can hold itself, to open an overlay from anywhere —\n * Flow's `useOverlayController(type, options)`. Given a type, it hands back the\n * surrounding overlay's controller of that type when there is one, as Flow\n * does; `reuseControllerFromContext: false` asks for a new one regardless.\n *\n * Also takes the options alone, for a controller that belongs to no type. Call\n * it in `setup()`: the surrounding overlay is found through `inject`.\n */\nexport function useOverlayController(\n type: OverlayType,\n options?: UseOverlayControllerOptions,\n): OverlayController;\nexport function useOverlayController(\n options?: CreateOverlayControllerOptions,\n): OverlayController;\nexport function useOverlayController(\n typeOrOptions?: OverlayType | CreateOverlayControllerOptions,\n options: UseOverlayControllerOptions = {},\n): OverlayController {\n if (typeof typeOrOptions !== \"string\") {\n return createOverlayController(typeOrOptions);\n }\n const { reuseControllerFromContext = true } = options;\n const fromContext = reuseControllerFromContext\n ? injectOverlayController(typeOrOptions)\n : undefined;\n return fromContext ?? createOverlayController(options);\n}\n\n/**\n * Flow's `useModalController(options)`: `useOverlayController(\"Modal\",\n * options)`.\n */\nexport const useModalController = (\n options?: UseOverlayControllerOptions,\n): OverlayController => useOverlayController(\"Modal\", options);\n\n/** The overlays a controller can be registered for, by Flow component name. */\nexport type OverlayType = \"Modal\" | \"Popover\" | \"LightBox\";\n\n/**\n * Flow's `OverlayContext`: the surrounding overlays' controllers by component\n * name, and the one whose content this subtree is. A trigger registers its\n * controller by name only — its button is not inside the overlay it opens.\n */\nexport interface OverlayContext {\n byType: Partial<Record<OverlayType, OverlayController>>;\n nearest?: OverlayController;\n}\n\nconst overlayContextKey: InjectionKey<OverlayContext> =\n Symbol(\"flowOverlayContext\");\n\nexport const injectOverlayContext = (): OverlayContext =>\n inject(overlayContextKey, { byType: {} });\n\n/**\n * Provides the context for a subtree. The controller may be a getter: an\n * overlay whose `controller` prop changes hands its subtree the new one, and\n * the context reads it when it is asked rather than when it was provided.\n */\nexport const provideOverlayContext = (\n type: OverlayType,\n controller: OverlayController | (() => OverlayController),\n options: { isOverlayContent?: boolean } = {},\n): void => {\n const { isOverlayContent = true } = options;\n const parent = injectOverlayContext();\n const current =\n typeof controller === \"function\" ? controller : () => controller;\n\n provide(overlayContextKey, {\n get byType() {\n return { ...parent.byType, [type]: current() };\n },\n get nearest() {\n return isOverlayContent ? current() : parent.nearest;\n },\n });\n};\n\n/**\n * The controller an overlay or trigger drives, in Flow's order of precedence:\n * the one the app passes, the one of a surrounding trigger of that type, or one\n * of its own. It follows the prop — Flow reads it on every render.\n */\nexport const useOwnController = (\n fromProp: () => OverlayController | undefined,\n inheritFrom: OverlayType | undefined,\n options: () => CreateOverlayControllerOptions = () => ({}),\n): ComputedRef<OverlayController> => {\n const context = injectOverlayContext();\n let own: OverlayController | undefined;\n\n return computed(\n () =>\n fromProp() ??\n (inheritFrom ? context.byType[inheritFrom] : undefined) ??\n (own ??= createOverlayController(options())),\n );\n};\n\n/**\n * The controller of the surrounding overlay of that type — or, without a type,\n * of the overlay this component is inside.\n */\nexport const injectOverlayController = (\n type?: OverlayType,\n): OverlayController | undefined => {\n const context = injectOverlayContext();\n return type ? context.byType[type] : context.nearest;\n};\n"],"mappings":";;;;;AAuGA,IAAM,yBAAS,IAAI,QAA8B;;AAGjD,IAAa,uBACX,UAEA,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAO,IAAI,KAAK;AAOjE,IAAM,YAAe,MAAe,UAClC,WAAW,OAAO,YAAY;CAC5B,SAAS,MAAM,OAAO;CACtB,OAAO;EACL,WAAW;GACT,MAAM;GACN,OAAO,KAAK;EACd;EACA,KAAK;CACP;AACF,CAAC;AAEH,IAAa,2BACX,UAA0C,CAAC,MACrB;CACtB,MAAM,QAAQ,IAAI,aAAa,EAAE,eAAe,QAAQ,cAAc,CAAC;CAEvE,MAAM,YAAY,CAAC;CAEnB,MAAM,aAAgC;EACpC,QAAQ,eAAe,MAAM,QAAQ,MAAM,QAAQ;EACnD,gBAAgB,eACR,MAAM,wBACX,mBACC,iBACI,MAAM,wBAAwB,WAAW,IAAI,IAC7C,MAAM,2BAA2B,SAAS,CAClD;EACA,mBAAmB,eACX,MAAM,wBACX,iBAAiB;GAChB,IAAI,CAAC,cACH,MAAM,mBAAmB;EAE7B,CACF;EACA,oBAAoB,eACZ,MAAM,oBACZ,MAAM,qBACR;EACA,MAAM,MAAM;EACZ,OAAO,MAAM;EACb,QAAQ,MAAM;EACd,SAAS,MAAM;EACf,UAAU,MAAM;EAChB,oBAAoB,MAAM,MAAM;EAMhC,oBACE,kBAAkB;GAChB,MAAM,aAAa;GACnB,MAAM,MAAM;EACd,CAAC;EAC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,CAAC;;;;;;AAO1C,IAAa,yBACX,MACA,YACA,UAA0C,CAAC,MAClC;CACT,MAAM,EAAE,mBAAmB,SAAS;CACpC,MAAM,SAAS,qBAAqB;CACpC,MAAM,UACJ,OAAO,eAAe,aAAa,mBAAmB;CAExD,QAAQ,mBAAmB;EACzB,IAAI,SAAS;GACX,OAAO;IAAE,GAAG,OAAO;KAAS,OAAO,QAAQ;GAAE;EAC/C;EACA,IAAI,UAAU;GACZ,OAAO,mBAAmB,QAAQ,IAAI,OAAO;EAC/C;CACF,CAAC;AACH;;;;;;AAOA,IAAa,oBACX,UACA,aACA,iBAAuD,CAAC,OACrB;CACnC,MAAM,UAAU,qBAAqB;CACrC,IAAI;CAEJ,OAAO,eAEH,SAAS,MACR,cAAc,QAAQ,OAAO,eAAe,KAAA,OAC5C,QAAQ,wBAAwB,QAAQ,CAAC,EAC9C;AACF;;;;;AAMA,IAAa,2BACX,SACkC;CAClC,MAAM,UAAU,qBAAqB;CACrC,OAAO,OAAO,QAAQ,OAAO,QAAQ,QAAQ;AAC/C"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Version } from "@mittwald/flow-remote-core";
|
|
2
2
|
//#region src/version.ts
|
|
3
3
|
var communicationVersion = Version.v5;
|
|
4
|
-
var packageVersion = "1.5.
|
|
4
|
+
var packageVersion = "1.5.42";
|
|
5
5
|
var version = communicationVersion;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { communicationVersion, packageVersion, version };
|
|
@@ -21,3 +21,4 @@ export type { ListSortingShape, SortingDefaultMode, SortingFn, } from "./list/so
|
|
|
21
21
|
export { ListViewMode } from "./list/viewMode/ListViewMode";
|
|
22
22
|
export type { ListViewModeOptions, ListViewModeValue, } from "./list/viewMode/types";
|
|
23
23
|
export { customPropertyPrefix, type CustomPropertyName, type PropertyName, type PropertyValue, type PropertyValueRenderMethod, } from "./list/types";
|
|
24
|
+
export { OverlayState, type AnyOverlayOpenStateHandler, type DisposerFn, type OverlayCloseHandler, type OverlayCloseOptions, type OverlayOpenHandler, type OverlayOpenStateHandler, type OverlayStateOptions, } from "./overlay/OverlayState";
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export type OverlayOpenHandler = () => unknown;
|
|
2
|
+
export type OverlayCloseHandler = () => unknown;
|
|
3
|
+
export type OverlayOpenStateHandler = (isOpen: boolean) => unknown;
|
|
4
|
+
export type AnyOverlayOpenStateHandler = OverlayOpenHandler | OverlayCloseHandler | OverlayOpenStateHandler;
|
|
5
|
+
export type DisposerFn = () => void;
|
|
6
|
+
export interface OverlayCloseOptions {
|
|
7
|
+
/** Close without asking, even when the overlay requires confirmation. */
|
|
8
|
+
bypassConfirmation?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface OverlayStateOptions {
|
|
11
|
+
isDefaultOpen?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether closing the overlay must be confirmed while no source has an
|
|
14
|
+
* opinion (`setConfirmOnCloseSource`).
|
|
15
|
+
*/
|
|
16
|
+
confirmOnClose?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Whether an overlay is open, and whether closing it has to be confirmed first.
|
|
20
|
+
* Each binding adds its subscription and its lifecycle: React's
|
|
21
|
+
* `OverlayController` subclasses it, Vue's adapter wraps it in refs.
|
|
22
|
+
*
|
|
23
|
+
* `TCloseOptions` lets a binding pass more on a close than the state reads —
|
|
24
|
+
* React's `overlay`, resolved by `Action` before the close arrives here.
|
|
25
|
+
*/
|
|
26
|
+
export declare class OverlayState<TCloseOptions extends OverlayCloseOptions = OverlayCloseOptions> {
|
|
27
|
+
isOpen: boolean;
|
|
28
|
+
isContentSuspended: boolean;
|
|
29
|
+
private onOpenHandlers;
|
|
30
|
+
private onCloseHandlers;
|
|
31
|
+
private onOpenChangeHandlers;
|
|
32
|
+
showConfirmationModal: boolean;
|
|
33
|
+
closeIsConfirmed: boolean;
|
|
34
|
+
private readonly confirmOnCloseFromOptions;
|
|
35
|
+
/**
|
|
36
|
+
* Every mounted component that has an opinion on close confirmation
|
|
37
|
+
* contributes one entry here – e.g. a `Modal` with a `confirmOnClose` prop
|
|
38
|
+
* and a `Form` tracking its dirty state. Combining them instead of assigning
|
|
39
|
+
* a single flag keeps them from overwriting each other.
|
|
40
|
+
*/
|
|
41
|
+
private confirmOnCloseSources;
|
|
42
|
+
/**
|
|
43
|
+
* Active grants that allow closing without a confirmation. Each entry is
|
|
44
|
+
* scoped to an ongoing operation that legitimately closes the overlay – e.g.
|
|
45
|
+
* a `Form` submit – and is dropped again when that operation has finished, so
|
|
46
|
+
* an operation that does _not_ close the overlay leaves the confirmation
|
|
47
|
+
* armed.
|
|
48
|
+
*/
|
|
49
|
+
private closeWithoutConfirmationGrants;
|
|
50
|
+
/**
|
|
51
|
+
* The open state a `setOpen` call is currently applying. Handlers run before
|
|
52
|
+
* `isOpen` is assigned, so a handler that calls `setOpen` again would not be
|
|
53
|
+
* caught by the equality check at the top and would recurse.
|
|
54
|
+
*/
|
|
55
|
+
private openStateInFlight;
|
|
56
|
+
constructor(options?: OverlayStateOptions);
|
|
57
|
+
/** Whether closing this overlay currently requires a confirmation. */
|
|
58
|
+
get confirmOnCloseEnabled(): boolean;
|
|
59
|
+
private addOpenStateHandler;
|
|
60
|
+
private executeHandlers;
|
|
61
|
+
private executeOnClose;
|
|
62
|
+
private executeOnOpen;
|
|
63
|
+
private executeOnOpenChange;
|
|
64
|
+
addOnClose(handler: OverlayCloseHandler): DisposerFn;
|
|
65
|
+
addOnOpen(handler: OverlayOpenHandler): DisposerFn;
|
|
66
|
+
addOnOpenChange(handler: OverlayOpenStateHandler): DisposerFn;
|
|
67
|
+
open(): void;
|
|
68
|
+
close(options?: TCloseOptions): void;
|
|
69
|
+
toggle(): void;
|
|
70
|
+
setOpen(toOpen: boolean, options?: TCloseOptions): void;
|
|
71
|
+
/**
|
|
72
|
+
* Sets the open state without running any handler. Use it to mirror a
|
|
73
|
+
* controlled `isOpen` prop, whose change comes from the consumer – notifying
|
|
74
|
+
* them of their own state would echo it back.
|
|
75
|
+
*/
|
|
76
|
+
syncOpen(toOpen: boolean): void;
|
|
77
|
+
private applyOpenState;
|
|
78
|
+
setIsContentSuspended(to: boolean): void;
|
|
79
|
+
/**
|
|
80
|
+
* Allows closing this overlay without a confirmation until the returned
|
|
81
|
+
* disposer is called. Use it around an operation that may legitimately close
|
|
82
|
+
* the overlay – e.g. a `Form` submit, where a "discard unsaved changes?"
|
|
83
|
+
* prompt would be nonsense – and dispose it as soon as that operation has
|
|
84
|
+
* finished. An operation that ends without closing the overlay therefore
|
|
85
|
+
* leaves the confirmation armed (#2775).
|
|
86
|
+
*/
|
|
87
|
+
grantCloseWithoutConfirmation(): DisposerFn;
|
|
88
|
+
confirmClose(): void;
|
|
89
|
+
cancelConfirmation(): void;
|
|
90
|
+
}
|
|
@@ -36,7 +36,7 @@ export declare const Modal: import('vue').DefineComponent<import('vue').ExtractP
|
|
|
36
36
|
*/
|
|
37
37
|
confirmOnClose: {
|
|
38
38
|
type: BooleanConstructor;
|
|
39
|
-
default:
|
|
39
|
+
default: undefined;
|
|
40
40
|
};
|
|
41
41
|
/** A controller to open and close the modal from anywhere. */
|
|
42
42
|
controller: {
|
|
@@ -111,7 +111,7 @@ export declare const Modal: import('vue').DefineComponent<import('vue').ExtractP
|
|
|
111
111
|
*/
|
|
112
112
|
confirmOnClose: {
|
|
113
113
|
type: BooleanConstructor;
|
|
114
|
-
default:
|
|
114
|
+
default: undefined;
|
|
115
115
|
};
|
|
116
116
|
/** A controller to open and close the modal from anywhere. */
|
|
117
117
|
controller: {
|
|
@@ -1,27 +1,32 @@
|
|
|
1
|
+
import { OverlayCloseHandler, OverlayCloseOptions, OverlayOpenHandler, OverlayOpenStateHandler } from '../_bundled/flow-components-base/index';
|
|
1
2
|
import { ComputedRef, Raw, Ref } from 'vue';
|
|
3
|
+
export type { OverlayCloseHandler, OverlayCloseOptions, OverlayOpenHandler, OverlayOpenStateHandler, } from '../_bundled/flow-components-base/index';
|
|
2
4
|
/**
|
|
3
5
|
* The Vue counterpart of Flow's `OverlayController`.
|
|
4
6
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* opens it, the overlay reads it,
|
|
7
|
+
* The state is `OverlayState` from `@mittwald/flow-components-base`, the one
|
|
8
|
+
* React's controller runs on; this wraps it in refs and shares it through
|
|
9
|
+
* `provide`/`inject`. Same contract: a trigger opens it, the overlay reads it,
|
|
10
|
+
* and anything inside can close it.
|
|
11
|
+
*
|
|
12
|
+
* `Raw`, as `markRaw` makes it: reactive state keeps the controller as it is,
|
|
13
|
+
* and its type says so too.
|
|
8
14
|
*/
|
|
9
|
-
export type OverlayOpenHandler = () => unknown;
|
|
10
|
-
export type OverlayCloseHandler = () => unknown;
|
|
11
|
-
export type OverlayOpenStateHandler = (isOpen: boolean) => unknown;
|
|
12
|
-
export interface OverlayCloseOptions {
|
|
13
|
-
/** Close without asking, even when the overlay requires confirmation. */
|
|
14
|
-
bypassConfirmation?: boolean;
|
|
15
|
-
}
|
|
16
15
|
export interface OverlayController extends Raw<Record<never, never>> {
|
|
16
|
+
/** Writing it sets the state without running a handler, like `syncOpen`. */
|
|
17
17
|
isOpen: Ref<boolean>;
|
|
18
18
|
/**
|
|
19
|
-
* Whether closing has to be confirmed first
|
|
20
|
-
* confirm-on-close
|
|
19
|
+
* Whether closing has to be confirmed first — combined from every source: a
|
|
20
|
+
* `<Modal confirm-on-close>` and what the app writes here.
|
|
21
21
|
*/
|
|
22
22
|
confirmOnClose: Ref<boolean>;
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Whether the confirmation is on screen right now. Writing `false` dismisses
|
|
25
|
+
* it; only a close shows it.
|
|
26
|
+
*/
|
|
24
27
|
isConfirmingClose: Ref<boolean>;
|
|
28
|
+
/** Whether the overlay's content is suspended. Not used by this binding yet. */
|
|
29
|
+
isContentSuspended: Ref<boolean>;
|
|
25
30
|
open: () => void;
|
|
26
31
|
/**
|
|
27
32
|
* Closes — or asks first, when the overlay requires confirmation and
|
|
@@ -43,6 +48,11 @@ export interface OverlayController extends Raw<Record<never, never>> {
|
|
|
43
48
|
cancelClose: () => void;
|
|
44
49
|
/** Flow's name for `cancelClose`. */
|
|
45
50
|
cancelConfirmation: () => void;
|
|
51
|
+
/**
|
|
52
|
+
* Closes without a confirmation until the returned disposer is called — as in
|
|
53
|
+
* Flow, around an operation that closes the overlay deliberately.
|
|
54
|
+
*/
|
|
55
|
+
grantCloseWithoutConfirmation: () => () => void;
|
|
46
56
|
addOnOpen: (handler: OverlayOpenHandler) => () => void;
|
|
47
57
|
addOnClose: (handler: OverlayCloseHandler) => () => void;
|
|
48
58
|
addOnOpenChange: (handler: OverlayOpenStateHandler) => () => void;
|
|
@@ -60,12 +70,13 @@ export interface UseOverlayControllerOptions extends CreateOverlayControllerOpti
|
|
|
60
70
|
}
|
|
61
71
|
/** Whether a value is a controller, rather than options naming one. */
|
|
62
72
|
export declare const isOverlayController: (value: unknown) => value is OverlayController;
|
|
73
|
+
export declare const createOverlayController: (options?: CreateOverlayControllerOptions) => OverlayController;
|
|
63
74
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
75
|
+
* Registers a component's opinion on close confirmation for as long as it is
|
|
76
|
+
* mounted — Flow's `useConfirmOnCloseSource`. `undefined` contributes nothing,
|
|
77
|
+
* so the other sources decide.
|
|
67
78
|
*/
|
|
68
|
-
export declare const
|
|
79
|
+
export declare const useConfirmOnCloseSource: (controller: () => OverlayController, confirmOnClose: () => boolean | undefined) => void;
|
|
69
80
|
/**
|
|
70
81
|
* Registers an overlay's `onOpen`/`onClose`/`onOpenChange` props on its
|
|
71
82
|
* controller for as long as it is mounted — Flow's `useUpdateOptions`.
|
|
@@ -75,7 +86,6 @@ export declare const useOverlayHandlers: (controller: () => OverlayController, h
|
|
|
75
86
|
onClose?: () => OverlayCloseHandler | undefined;
|
|
76
87
|
onOpenChange?: () => OverlayOpenStateHandler | undefined;
|
|
77
88
|
}) => void;
|
|
78
|
-
export declare const createOverlayController: (options?: CreateOverlayControllerOptions) => OverlayController;
|
|
79
89
|
/**
|
|
80
90
|
* A controller an app can hold itself, to open an overlay from anywhere —
|
|
81
91
|
* Flow's `useOverlayController(type, options)`. Given a type, it hands back the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/flow-remote-vue-components",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.42",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Vue components that can be used in a remote environment",
|
|
6
6
|
"homepage": "https://flow.mittwald.de",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@internationalized/date": "^3.12.3",
|
|
44
|
-
"@mittwald/flow-remote-core": "1.5.
|
|
45
|
-
"@mittwald/flow-remote-elements": "1.5.
|
|
44
|
+
"@mittwald/flow-remote-core": "1.5.42",
|
|
45
|
+
"@mittwald/flow-remote-elements": "1.5.42",
|
|
46
46
|
"@tanstack/table-core": "^8.21.3",
|
|
47
47
|
"country-codes-list": "^2.0.0",
|
|
48
48
|
"dot-prop": "^10.2.0",
|
|
@@ -52,14 +52,14 @@
|
|
|
52
52
|
"remeda": "^2.43.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@mittwald/ext-bridge": "1.5.
|
|
56
|
-
"@mittwald/flow-components-base": "1.5.
|
|
57
|
-
"@mittwald/flow-core": "1.5.
|
|
58
|
-
"@mittwald/flow-icons-base": "1.5.
|
|
59
|
-
"@mittwald/flow-react-components": "1.5.
|
|
60
|
-
"@mittwald/flow-remote-react-components": "1.5.
|
|
61
|
-
"@mittwald/flow-remote-react-renderer": "1.5.
|
|
62
|
-
"@mittwald/typescript-config": "1.5.
|
|
55
|
+
"@mittwald/ext-bridge": "1.5.42",
|
|
56
|
+
"@mittwald/flow-components-base": "1.5.42",
|
|
57
|
+
"@mittwald/flow-core": "1.5.42",
|
|
58
|
+
"@mittwald/flow-icons-base": "1.5.42",
|
|
59
|
+
"@mittwald/flow-react-components": "1.5.42",
|
|
60
|
+
"@mittwald/flow-remote-react-components": "1.5.42",
|
|
61
|
+
"@mittwald/flow-remote-react-renderer": "1.5.42",
|
|
62
|
+
"@mittwald/typescript-config": "1.5.42",
|
|
63
63
|
"@quilted/threads": "^3.3.1",
|
|
64
64
|
"@types/node": "^25.9.3",
|
|
65
65
|
"@types/react": "^19.2",
|
|
@@ -79,10 +79,10 @@
|
|
|
79
79
|
"vue": "~3.5.38"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@mittwald/ext-bridge": "1.5.
|
|
83
|
-
"@mittwald/flow-react-components": "1.5.
|
|
82
|
+
"@mittwald/ext-bridge": "1.5.42",
|
|
83
|
+
"@mittwald/flow-react-components": "1.5.42",
|
|
84
84
|
"vue": "^3.5.0"
|
|
85
85
|
},
|
|
86
86
|
"flowStatus": "beta",
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "2574cebacfcf0441b6a77edd66e3e56095c417fe"
|
|
88
88
|
}
|