@runic-artifex/vue 0.10.0 → 0.12.0
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 +129 -8
- package/dist/index.d.ts +28 -3
- package/dist/index.js +33 -4
- package/dist/menu-bar.d.ts +31 -0
- package/dist/menu-bar.js +37 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -89,8 +89,8 @@ const step = computed({ get: () => state.value?.step ?? 1, set: value => void se
|
|
|
89
89
|
|
|
90
90
|
Renders the component registered for a generated reference's `kind` and
|
|
91
91
|
passes the reference as its `page` prop. A different reference remounts the
|
|
92
|
-
component, a kind without a component renders an
|
|
93
|
-
renders while `content` is empty:
|
|
92
|
+
component, a kind without a component renders an English `<p role="alert">`
|
|
93
|
+
(or the `missing` slot), and the default slot renders while `content` is empty:
|
|
94
94
|
|
|
95
95
|
```vue
|
|
96
96
|
<script setup lang="ts">
|
|
@@ -111,6 +111,16 @@ const { state } = useView({ connect: connectWorkspace });
|
|
|
111
111
|
`satisfies ViewRegistry<…>` checks that every kind has a component whose `page`
|
|
112
112
|
prop accepts that reference.
|
|
113
113
|
|
|
114
|
+
The `missing` slot replaces the English alert, for example with localized text.
|
|
115
|
+
It receives `{ content }`, the reference whose kind has no component, and its
|
|
116
|
+
markup (including any `role`) is yours:
|
|
117
|
+
|
|
118
|
+
```vue
|
|
119
|
+
<ViewOutlet :content="state?.main" :registry="pages">
|
|
120
|
+
<template #missing="{ content }"><p role="alert">{{ t("missingView", { kind: content.kind }) }}</p></template>
|
|
121
|
+
</ViewOutlet>
|
|
122
|
+
```
|
|
123
|
+
|
|
114
124
|
## `useCommand(command)`
|
|
115
125
|
|
|
116
126
|
Returns `{ run, pending, error, failure, reset }`, with `pending`, `error` and
|
|
@@ -124,6 +134,11 @@ const { run: navigate } = useCommand((name: "showWelcome" | "showCounter") => cl
|
|
|
124
134
|
// <button @click="navigate('showWelcome')">Welcome</button>
|
|
125
135
|
```
|
|
126
136
|
|
|
137
|
+
`pending` covers only this component's run. Whether .NET can run the command is
|
|
138
|
+
the View's state: a command without an argument publishes `can<Name>` (such as
|
|
139
|
+
`state.canSave`), so disable a button while either says no. A command with an
|
|
140
|
+
argument has the `can<Name>(input)` query on the client instead.
|
|
141
|
+
|
|
127
142
|
For a command that declares a failure (`[RunicFailure]` in .NET), `run` resolves the
|
|
128
143
|
`BridgeOutcome`, and `failure` holds the declared failure of the latest run, typed
|
|
129
144
|
from the outcome, while `error` keeps unexpected failures. Starting a run and
|
|
@@ -133,7 +148,7 @@ neither.
|
|
|
133
148
|
## `useOperation(start, options?)`
|
|
134
149
|
|
|
135
150
|
Observes a generated `start<Command>()` operation through the framework-neutral
|
|
136
|
-
[operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
151
|
+
[operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.12.0/packages/web/views#operation-feedback-and-latest-selection)
|
|
137
152
|
and returns each state field as a shallow ref, with `run`, `cancel` and `reset`:
|
|
138
153
|
|
|
139
154
|
```vue
|
|
@@ -162,7 +177,7 @@ Disposing the effect scope settles run promises without cancelling accepted work
|
|
|
162
177
|
|
|
163
178
|
Admits only the newest of several reads, for example loading the item the user
|
|
164
179
|
selected last, through the framework-neutral
|
|
165
|
-
[latest-operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
180
|
+
[latest-operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.12.0/packages/web/views#operation-feedback-and-latest-selection),
|
|
166
181
|
and returns each state field as a shallow ref, with `run` and `clear`. Each
|
|
167
182
|
`run(intent)` replaces the queued intent and cancels the active read; the next read
|
|
168
183
|
starts only after the previous one reaches its terminal status and the intent's
|
|
@@ -192,6 +207,112 @@ established a fresh session, clears it. `clear()` drops the queued intent and ca
|
|
|
192
207
|
the active read. Disposing the effect scope settles run promises without cancelling
|
|
193
208
|
accepted work.
|
|
194
209
|
|
|
210
|
+
## `useBridgeConnection(options?)`
|
|
211
|
+
|
|
212
|
+
Follows the page's connection to its .NET host. It wraps `onBridgeConnection`
|
|
213
|
+
from `@runic-artifex/views` (re-exported here since 0.11, with the
|
|
214
|
+
`BridgeConnectionState` and `BridgeConnectionOptions` types) and returns `{ state }`, a shallow ref holding a
|
|
215
|
+
`BridgeConnectionState`: `connecting`, `connected`, `reconnecting` or `lost` (a
|
|
216
|
+
closed set, see
|
|
217
|
+
[Connection state](https://github.com/Runic-Artifex/runic-sdk/tree/v0.12.0/packages/web/views#connection-state)):
|
|
218
|
+
|
|
219
|
+
```vue
|
|
220
|
+
<script setup lang="ts">
|
|
221
|
+
import { useBridgeConnection } from "@runic-artifex/vue";
|
|
222
|
+
|
|
223
|
+
const { state: connection } = useBridgeConnection({ lostAfter: 5_000 });
|
|
224
|
+
</script>
|
|
225
|
+
|
|
226
|
+
<template>
|
|
227
|
+
<p v-if="connection === 'lost'" role="alert">The application stopped responding.</p>
|
|
228
|
+
</template>
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Disposing the effect scope (unmounting the component) unsubscribes. Call it in
|
|
232
|
+
`setup()` or `effectScope().run()`: outside an effect scope nothing stops it, and
|
|
233
|
+
development builds warn. An invalid `lostAfter` throws a `RangeError`.
|
|
234
|
+
|
|
235
|
+
## `useMenuBar(options?)`
|
|
236
|
+
|
|
237
|
+
Follows the declared menu bar of a Runic Desktop window that leaves it to the
|
|
238
|
+
page (`DesktopMenuBarPresentation.Page`) until the current effect scope is
|
|
239
|
+
disposed. It wraps `createMenuBarController` from `@runic-artifex/views` (see
|
|
240
|
+
[In-page menu bar](https://github.com/Runic-Artifex/runic-sdk/tree/v0.12.0/packages/web/views#in-page-menu-bar)) and returns `{ state, invoke, handleKeyDown }`: `state` is a shallow ref
|
|
241
|
+
of a `MenuBarState`, and the bar is rendered by the menubar component of the
|
|
242
|
+
application's own UI library. Runic ships no menubar component.
|
|
243
|
+
|
|
244
|
+
```vue
|
|
245
|
+
<script setup lang="ts">
|
|
246
|
+
import { ref } from "vue";
|
|
247
|
+
import { useMenuBar } from "@runic-artifex/vue";
|
|
248
|
+
|
|
249
|
+
const open = ref("");
|
|
250
|
+
const { state: menuBar, invoke } = useMenuBar({
|
|
251
|
+
onRequest: request => { if (request.kind === "open") open.value = request.menu.key; else focusFirstTrigger(); },
|
|
252
|
+
});
|
|
253
|
+
</script>
|
|
254
|
+
|
|
255
|
+
<template>
|
|
256
|
+
<!-- On macOS the application menu bar keeps the menus ("global"): render nothing. -->
|
|
257
|
+
<nav v-if="menuBar.placement === 'page'"><!-- the menubar component; an item's select handler calls invoke(item) --></nav>
|
|
258
|
+
</template>
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Options are those of `createMenuBarController` (`shortcuts`, `keyboard`)
|
|
262
|
+
without `signal`, plus `onRequest`, which receives the `focus` and `open`
|
|
263
|
+
requests. Stopping the scope disposes the controller, which also returns the
|
|
264
|
+
`shortcuts: "app"` lease. Call it in `setup()` or `effectScope().run()`;
|
|
265
|
+
outside an effect scope it is never released (development builds warn). Server
|
|
266
|
+
rendering creates no controller: `state` stays `connecting`.
|
|
267
|
+
|
|
268
|
+
### With Reka UI
|
|
269
|
+
|
|
270
|
+
Reka UI's `MenubarRoot` with `v-model` of the open menu; the
|
|
271
|
+
[Notes example](https://github.com/Runic-Artifex/runic-sdk/tree/v0.12.0/examples/notes-view-first#in-page-menu-bar) adds submenus, check and radio
|
|
272
|
+
items and is tested with real keys:
|
|
273
|
+
|
|
274
|
+
```vue
|
|
275
|
+
<script setup lang="ts">
|
|
276
|
+
import { ref } from "vue";
|
|
277
|
+
import { MenubarContent, MenubarItem, MenubarMenu, MenubarPortal, MenubarRoot, MenubarSeparator, MenubarTrigger } from "reka-ui";
|
|
278
|
+
import { splitAccessKey } from "@runic-artifex/views";
|
|
279
|
+
import { useMenuBar } from "@runic-artifex/vue";
|
|
280
|
+
|
|
281
|
+
const bar = ref<{ $el: HTMLElement }>();
|
|
282
|
+
const open = ref("");
|
|
283
|
+
const { state: menuBar, invoke } = useMenuBar({
|
|
284
|
+
onRequest: request => {
|
|
285
|
+
if (request.kind === "open") open.value = request.menu.key;
|
|
286
|
+
else bar.value?.$el.querySelector<HTMLElement>("[role=menuitem]")?.focus();
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
</script>
|
|
290
|
+
|
|
291
|
+
<template>
|
|
292
|
+
<MenubarRoot v-if="menuBar.placement === 'page'" ref="bar" v-model="open" aria-label="Application">
|
|
293
|
+
<MenubarMenu v-for="menu in menuBar.menus" :key="menu.key" :value="menu.key">
|
|
294
|
+
<MenubarTrigger :disabled="!menu.enabled">
|
|
295
|
+
<template v-for="(part, index) in splitAccessKey(menu)" :key="index">
|
|
296
|
+
<u v-if="index === 1 && menuBar.accessKeyHints">{{ part }}</u><template v-else>{{ part }}</template>
|
|
297
|
+
</template>
|
|
298
|
+
</MenubarTrigger>
|
|
299
|
+
<MenubarPortal>
|
|
300
|
+
<MenubarContent align="start">
|
|
301
|
+
<template v-for="entry in menu.entries" :key="entry.key">
|
|
302
|
+
<MenubarSeparator v-if="entry.kind === 'separator'" />
|
|
303
|
+
<MenubarItem v-else-if="entry.kind === 'item'" :disabled="!entry.enabled"
|
|
304
|
+
:aria-keyshortcuts="entry.ariaKeyShortcuts" @select="invoke(entry)">
|
|
305
|
+
{{ entry.label }} <kbd aria-hidden="true">{{ entry.shortcutText }}</kbd>
|
|
306
|
+
</MenubarItem>
|
|
307
|
+
<!-- a submenu: MenubarSub; check and radio items: MenubarCheckboxItem, MenubarRadioGroup -->
|
|
308
|
+
</template>
|
|
309
|
+
</MenubarContent>
|
|
310
|
+
</MenubarPortal>
|
|
311
|
+
</MenubarMenu>
|
|
312
|
+
</MenubarRoot>
|
|
313
|
+
</template>
|
|
314
|
+
```
|
|
315
|
+
|
|
195
316
|
## Errors
|
|
196
317
|
|
|
197
318
|
The `error` of `useView` and of a command or operation handle is typed
|
|
@@ -206,7 +327,7 @@ const offline = error.value instanceof BridgeError && error.value.kind === "disc
|
|
|
206
327
|
```
|
|
207
328
|
|
|
208
329
|
`instanceof` holds for errors from every copy of the package on the page.
|
|
209
|
-
[Errors and diagnostics](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
330
|
+
[Errors and diagnostics](https://github.com/Runic-Artifex/runic-sdk/tree/v0.12.0/packages/web/views#errors-and-diagnostics)
|
|
210
331
|
lists the kinds. Any other value, such as an exception that your own connect
|
|
211
332
|
function or command callback throws, arrives unchanged.
|
|
212
333
|
|
|
@@ -253,15 +374,15 @@ application's own dialog.
|
|
|
253
374
|
departure before that is answered by the ViewModel's .NET fallback handler, or
|
|
254
375
|
fails closed without one.
|
|
255
376
|
|
|
256
|
-
The [ReactiveUI leave confirmation](https://github.com/Runic-Artifex/runic-sdk/blob/v0.
|
|
377
|
+
The [ReactiveUI leave confirmation](https://github.com/Runic-Artifex/runic-sdk/blob/v0.12.0/packages/dotnet/Runic.Application.Views.ReactiveUI/README.md#leave-confirmation-in-a-web-view)
|
|
257
378
|
has the .NET side and which View answers which departure. In a frontend test,
|
|
258
379
|
the generated mock's `interactions.<name>.request(input)` resolves with the
|
|
259
|
-
registered handler's answer; see the [Testing guide](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
380
|
+
registered handler's answer; see the [Testing guide](https://github.com/Runic-Artifex/runic-sdk/tree/v0.12.0/packages/web/views#testing).
|
|
260
381
|
|
|
261
382
|
## `useCollectionViewport(options)`
|
|
262
383
|
|
|
263
384
|
Follows a fixed-row-height scroll container and returns `{ viewport, attach }`.
|
|
264
|
-
`viewport` is a shallow ref with the [`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
385
|
+
`viewport` is a shallow ref with the [`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.12.0/packages/web/views#collectionviewportoptions)
|
|
265
386
|
range; `attach` is a function ref for the container. Bind it to a native element
|
|
266
387
|
such as a `<div>`: a component instance (`:ref="attach"` on a component) or a
|
|
267
388
|
non-HTML element detaches the viewport, and development builds warn. Pass a getter for the
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Component, type MaybeRefOrGetter, type Ref } from "vue";
|
|
2
|
-
import { type BridgeOperation, type BridgeOutcomeFailure, type LatestOperationController, type LatestOperationState, type OperationController, type OperationControllerOptions, type OperationState, type PageReference, type ViewClient, type ViewSource } from "@runic-artifex/views";
|
|
2
|
+
import { type BridgeConnectionOptions, type BridgeConnectionState, type BridgeOperation, type BridgeOutcomeFailure, type LatestOperationController, type LatestOperationState, type OperationController, type OperationControllerOptions, type OperationState, type PageReference, type ViewClient, type ViewSource } from "@runic-artifex/views";
|
|
3
3
|
export interface ViewHandle<TClient extends ViewClient> {
|
|
4
4
|
/** The latest state, or undefined until the client connects. */
|
|
5
5
|
readonly state: Readonly<Ref<TClient["snapshot"] | undefined>>;
|
|
@@ -47,8 +47,15 @@ export interface ViewOutletProps<R extends PageReference> {
|
|
|
47
47
|
/**
|
|
48
48
|
* Renders the registered component for a generated View reference and passes
|
|
49
49
|
* the reference as its `page` prop. A different reference remounts the
|
|
50
|
-
* component.
|
|
51
|
-
* renders
|
|
50
|
+
* component. The default slot renders while there is no content. A kind without
|
|
51
|
+
* a component renders the `missing` slot, which receives `{ content }`, for example
|
|
52
|
+
* for localized text, or an English alert without it:
|
|
53
|
+
*
|
|
54
|
+
* ```vue
|
|
55
|
+
* <ViewOutlet :content="state?.main" :registry="pages">
|
|
56
|
+
* <template #missing="{ content }"><p role="alert">{{ t("missingView", content.kind) }}</p></template>
|
|
57
|
+
* </ViewOutlet>
|
|
58
|
+
* ```
|
|
52
59
|
*/
|
|
53
60
|
export declare const ViewOutlet: new <R extends PageReference>(props: (ViewOutletProps<R> & ({
|
|
54
61
|
[x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
|
|
@@ -140,4 +147,22 @@ export type LatestOperationHandle<TResult, TFailure = never> = {
|
|
|
140
147
|
* ```
|
|
141
148
|
*/
|
|
142
149
|
export declare function useLatestOperation<TResult = void, TFailure = never>(): LatestOperationHandle<TResult, TFailure>;
|
|
150
|
+
export interface BridgeConnectionHandle {
|
|
151
|
+
/** The connection to the .NET host, as `onBridgeConnection` reports it. */
|
|
152
|
+
readonly state: Readonly<Ref<BridgeConnectionState>>;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Follows the page's connection to its .NET host (`connecting`, `connected`, `reconnecting`
|
|
156
|
+
* or `lost`) as a shallow ref through `onBridgeConnection`, until the current effect scope is
|
|
157
|
+
* disposed. Call it in `setup()` or `effectScope().run()`: outside an effect scope it is never
|
|
158
|
+
* released (development builds warn).
|
|
159
|
+
*
|
|
160
|
+
* ```vue
|
|
161
|
+
* const { state: connection } = useBridgeConnection();
|
|
162
|
+
* <p v-if="connection === 'lost'" role="alert">The application stopped responding.</p>
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export declare function useBridgeConnection(options?: BridgeConnectionOptions): BridgeConnectionHandle;
|
|
143
166
|
export { useCollectionViewport, type CollectionViewportHandle } from "./viewport.js";
|
|
167
|
+
export { onBridgeConnection, type BridgeConnectionOptions, type BridgeConnectionState } from "@runic-artifex/views";
|
|
168
|
+
export { useMenuBar, type MenuBarEntry, type MenuBarHandle, type MenuBarInvokeResult, type MenuBarItem, type MenuBarMenu, type MenuBarRequest, type MenuBarSeparator, type MenuBarState, type UseMenuBarOptions, } from "./menu-bar.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineComponent, h, shallowRef, toValue, watch, } from "vue";
|
|
2
|
-
import { createCommandController, createLatestOperationController, createOperationController, createViewController, } from "@runic-artifex/views";
|
|
2
|
+
import { createCommandController, createLatestOperationController, createOperationController, createViewController, onBridgeConnection, } from "@runic-artifex/views";
|
|
3
3
|
import { viewSourceIdentity } from "@runic-artifex/views/bindings";
|
|
4
4
|
import { releaseWithScope } from "./scope.js";
|
|
5
5
|
export function useView(source, options = {}) {
|
|
@@ -34,16 +34,26 @@ function referenceKey(reference) {
|
|
|
34
34
|
/**
|
|
35
35
|
* Renders the registered component for a generated View reference and passes
|
|
36
36
|
* the reference as its `page` prop. A different reference remounts the
|
|
37
|
-
* component.
|
|
38
|
-
* renders
|
|
37
|
+
* component. The default slot renders while there is no content. A kind without
|
|
38
|
+
* a component renders the `missing` slot, which receives `{ content }`, for example
|
|
39
|
+
* for localized text, or an English alert without it:
|
|
40
|
+
*
|
|
41
|
+
* ```vue
|
|
42
|
+
* <ViewOutlet :content="state?.main" :registry="pages">
|
|
43
|
+
* <template #missing="{ content }"><p role="alert">{{ t("missingView", content.kind) }}</p></template>
|
|
44
|
+
* </ViewOutlet>
|
|
45
|
+
* ```
|
|
39
46
|
*/
|
|
40
47
|
export const ViewOutlet = defineComponent((props, { slots }) => () => {
|
|
41
48
|
const content = props.content;
|
|
42
49
|
if (!content)
|
|
43
50
|
return slots.default?.();
|
|
44
51
|
const component = props.registry[content.kind];
|
|
45
|
-
if (!component)
|
|
52
|
+
if (!component) {
|
|
53
|
+
if (slots["missing"])
|
|
54
|
+
return slots["missing"]({ content });
|
|
46
55
|
return h("p", { role: "alert" }, `No web component is registered for ${content.kind}.`);
|
|
56
|
+
}
|
|
47
57
|
return h(component, { key: referenceKey(content), page: content });
|
|
48
58
|
}, { name: "ViewOutlet", props: ["content", "registry"] });
|
|
49
59
|
/**
|
|
@@ -128,4 +138,23 @@ export function useLatestOperation() {
|
|
|
128
138
|
releaseWithScope("useLatestOperation", () => controller.dispose());
|
|
129
139
|
return { ...refs, run: controller.run, clear: controller.clear };
|
|
130
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Follows the page's connection to its .NET host (`connecting`, `connected`, `reconnecting`
|
|
143
|
+
* or `lost`) as a shallow ref through `onBridgeConnection`, until the current effect scope is
|
|
144
|
+
* disposed. Call it in `setup()` or `effectScope().run()`: outside an effect scope it is never
|
|
145
|
+
* released (development builds warn).
|
|
146
|
+
*
|
|
147
|
+
* ```vue
|
|
148
|
+
* const { state: connection } = useBridgeConnection();
|
|
149
|
+
* <p v-if="connection === 'lost'" role="alert">The application stopped responding.</p>
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export function useBridgeConnection(options = {}) {
|
|
153
|
+
const state = shallowRef("connecting");
|
|
154
|
+
const stop = onBridgeConnection(next => { state.value = next; }, options);
|
|
155
|
+
releaseWithScope("useBridgeConnection", stop);
|
|
156
|
+
return { state };
|
|
157
|
+
}
|
|
131
158
|
export { useCollectionViewport } from "./viewport.js";
|
|
159
|
+
export { onBridgeConnection } from "@runic-artifex/views";
|
|
160
|
+
export { useMenuBar, } from "./menu-bar.js";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ShallowRef } from "vue";
|
|
2
|
+
import { type MenuBarController, type MenuBarControllerOptions, type MenuBarRequest, type MenuBarState } from "@runic-artifex/views";
|
|
3
|
+
export type { MenuBarEntry, MenuBarInvokeResult, MenuBarItem, MenuBarMenu, MenuBarRequest, MenuBarSeparator, MenuBarState, } from "@runic-artifex/views";
|
|
4
|
+
export interface UseMenuBarOptions extends Omit<MenuBarControllerOptions, "signal"> {
|
|
5
|
+
/**
|
|
6
|
+
* Receives the `focus` (Alt tap, F10) and `open` (Alt plus a menu's access key) requests: focus the first trigger
|
|
7
|
+
* or set the menubar component's open menu.
|
|
8
|
+
*/
|
|
9
|
+
readonly onRequest?: (request: MenuBarRequest) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface MenuBarHandle {
|
|
12
|
+
/** The menu bar as the page renders it; render a bar only when `placement` is `"page"`. */
|
|
13
|
+
readonly state: Readonly<ShallowRef<MenuBarState>>;
|
|
14
|
+
/** Runs an item through the native bar's command path. */
|
|
15
|
+
readonly invoke: MenuBarController["invoke"];
|
|
16
|
+
/** Matches a `keydown` event against the items' shortcuts, for the `shortcuts: "app"` option. */
|
|
17
|
+
readonly handleKeyDown: MenuBarController["handleKeyDown"];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Follows the window's declared menu bar (Runic Desktop's `DesktopMenuBarPresentation.Page`) as a shallow ref, as
|
|
21
|
+
* headless state for the application's own menubar component, through `createMenuBarController`, until the current
|
|
22
|
+
* effect scope is disposed. Call it in `setup()` or `effectScope().run()`: outside an effect scope it is never
|
|
23
|
+
* released (development builds warn). Server rendering creates no controller and stays `connecting`.
|
|
24
|
+
*
|
|
25
|
+
* ```vue
|
|
26
|
+
* const open = ref("");
|
|
27
|
+
* const { state: menuBar, invoke } = useMenuBar({ onRequest: request => { if (request.kind === "open") open.value = request.menu.key; } });
|
|
28
|
+
* <MenubarRoot v-if="menuBar.placement === 'page'" v-model="open">…<MenubarItem @select="invoke(item)">
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function useMenuBar(options?: UseMenuBarOptions): MenuBarHandle;
|
package/dist/menu-bar.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { hasInjectionContext, inject, shallowRef, ssrContextKey } from "vue";
|
|
2
|
+
import { BridgeError, createMenuBarController, } from "@runic-artifex/views";
|
|
3
|
+
import { releaseWithScope } from "./scope.js";
|
|
4
|
+
/**
|
|
5
|
+
* Follows the window's declared menu bar (Runic Desktop's `DesktopMenuBarPresentation.Page`) as a shallow ref, as
|
|
6
|
+
* headless state for the application's own menubar component, through `createMenuBarController`, until the current
|
|
7
|
+
* effect scope is disposed. Call it in `setup()` or `effectScope().run()`: outside an effect scope it is never
|
|
8
|
+
* released (development builds warn). Server rendering creates no controller and stays `connecting`.
|
|
9
|
+
*
|
|
10
|
+
* ```vue
|
|
11
|
+
* const open = ref("");
|
|
12
|
+
* const { state: menuBar, invoke } = useMenuBar({ onRequest: request => { if (request.kind === "open") open.value = request.menu.key; } });
|
|
13
|
+
* <MenubarRoot v-if="menuBar.placement === 'page'" v-model="open">…<MenubarItem @select="invoke(item)">
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function useMenuBar(options = {}) {
|
|
17
|
+
const { onRequest, ...controllerOptions } = options;
|
|
18
|
+
// Server rendering never stops a component's scope, so it would never release a controller.
|
|
19
|
+
if (hasInjectionContext() && inject(ssrContextKey, null) !== null) {
|
|
20
|
+
const state = shallowRef(Object.freeze({
|
|
21
|
+
status: "connecting", placement: "none", shortcuts: controllerOptions.shortcuts === "app" ? "app" : "host",
|
|
22
|
+
accessKeyHints: false, revision: 0, menus: Object.freeze([]),
|
|
23
|
+
}));
|
|
24
|
+
return {
|
|
25
|
+
state,
|
|
26
|
+
invoke: () => Promise.reject(new BridgeError("unavailable", "The menu bar is not followed during server rendering.", { route: "__runicMenuBarInvoke" })),
|
|
27
|
+
handleKeyDown: () => false,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const controller = createMenuBarController(controllerOptions);
|
|
31
|
+
const state = shallowRef(controller.current);
|
|
32
|
+
controller.subscribe(() => { state.value = controller.current; });
|
|
33
|
+
if (onRequest)
|
|
34
|
+
controller.onRequest(onRequest);
|
|
35
|
+
releaseWithScope("useMenuBar", () => controller.dispose());
|
|
36
|
+
return { state, invoke: controller.invoke, handleKeyDown: controller.handleKeyDown };
|
|
37
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runic-artifex/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Vue composables for generated Runic Views clients",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"vue": ">=3.5.30 <4",
|
|
33
|
-
"@runic-artifex/views": "0.
|
|
33
|
+
"@runic-artifex/views": "0.12.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@runic-artifex/views": "0.
|
|
37
|
-
"happy-dom": "
|
|
36
|
+
"@runic-artifex/views": "0.12.0",
|
|
37
|
+
"happy-dom": "21.0.4",
|
|
38
38
|
"typescript": "6.0.3",
|
|
39
39
|
"vitest": "5.0.3",
|
|
40
40
|
"vue": "3.5.43"
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"url": "git+https://github.com/Runic-Artifex/runic-sdk.git",
|
|
49
49
|
"directory": "packages/web/vue"
|
|
50
50
|
},
|
|
51
|
-
"homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
51
|
+
"homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/v0.12.0/packages/web/vue#readme",
|
|
52
52
|
"bugs": {
|
|
53
53
|
"url": "https://github.com/Runic-Artifex/runic-sdk/issues"
|
|
54
54
|
},
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"views",
|
|
59
59
|
"vue"
|
|
60
60
|
],
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "cb95ea2838ba61c7a24b9cda05bf5f0bd6fcc2d7"
|
|
62
62
|
}
|