@runic-artifex/vue 0.6.0-preview.1 → 0.7.0-preview.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -7
- package/dist/index.d.ts +86 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +89 -45
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# `@runic-artifex/vue`
|
|
2
2
|
|
|
3
|
-
Vue
|
|
4
|
-
import `@runic-artifex/views`,
|
|
3
|
+
Vue composables and outlet for clients generated by Runic Views. The generated
|
|
4
|
+
modules import `@runic-artifex/views`, which this package also builds on, so
|
|
5
|
+
install both:
|
|
5
6
|
|
|
6
7
|
```sh
|
|
7
8
|
npm install @runic-artifex/vue@preview @runic-artifex/views@preview
|
|
@@ -14,20 +15,23 @@ match your Runic SDK packages. Vue 3.5 or later is supported.
|
|
|
14
15
|
|
|
15
16
|
```vue
|
|
16
17
|
<script setup lang="ts">
|
|
17
|
-
import { useView } from "@runic-artifex/vue";
|
|
18
|
+
import { useCommand, useView } from "@runic-artifex/vue";
|
|
18
19
|
import type { CounterPageReference } from "./generated/counter.js";
|
|
19
20
|
|
|
20
21
|
const props = defineProps<{ page: CounterPageReference }>();
|
|
21
22
|
const { state, client, error } = useView(() => props.page);
|
|
23
|
+
const increment = useCommand(() => client.value?.increment());
|
|
22
24
|
</script>
|
|
23
25
|
|
|
24
26
|
<template>
|
|
25
|
-
<button :disabled="!client" @click="
|
|
26
|
-
<p v-if="error" role="alert">{{ error }}</p>
|
|
27
|
+
<button :disabled="!client || increment.pending" @click="increment.run()">{{ state?.count ?? "…" }}</button>
|
|
28
|
+
<p v-if="(increment.error ?? error) !== undefined" role="alert">{{ String(increment.error ?? error) }}</p>
|
|
27
29
|
</template>
|
|
28
30
|
```
|
|
29
31
|
|
|
30
|
-
`useView(source)`
|
|
32
|
+
## `useView(source)`
|
|
33
|
+
|
|
34
|
+
Returns shallow refs `{ state, client, error, pending }` and `retry()`:
|
|
31
35
|
|
|
32
36
|
- A generated page reference, or `{ connect: connect<Name> }` for a root
|
|
33
37
|
ViewModel, is connected while the current effect scope (normally the
|
|
@@ -36,4 +40,73 @@ const { state, client, error } = useView(() => props.page);
|
|
|
36
40
|
that returns a new `{ connect: connectWorkspace }` object does not reconnect.
|
|
37
41
|
- An already connected client is observed and left to its owner.
|
|
38
42
|
- The source can be a value, a ref or a getter such as `() => props.page`.
|
|
39
|
-
- `
|
|
43
|
+
- `pending` is true while a reference connects. `error` holds a failed
|
|
44
|
+
connection; `retry()` connects again.
|
|
45
|
+
|
|
46
|
+
## `ViewOutlet`
|
|
47
|
+
|
|
48
|
+
Renders the component registered for a generated reference's `kind` and
|
|
49
|
+
passes the reference as its `page` prop. A different reference remounts the
|
|
50
|
+
component, a kind without a component renders an alert, and the default slot
|
|
51
|
+
renders while `content` is empty:
|
|
52
|
+
|
|
53
|
+
```vue
|
|
54
|
+
<script setup lang="ts">
|
|
55
|
+
import { useView, ViewOutlet, type ViewRegistry } from "@runic-artifex/vue";
|
|
56
|
+
import { connectWorkspace, type WorkspaceState } from "./generated/workspace.js";
|
|
57
|
+
import CounterPage from "./pages/CounterPage.vue";
|
|
58
|
+
import WelcomePage from "./pages/WelcomePage.vue";
|
|
59
|
+
|
|
60
|
+
const pages = { counter: CounterPage, welcome: WelcomePage } satisfies ViewRegistry<WorkspaceState["main"]>;
|
|
61
|
+
const { state } = useView({ connect: connectWorkspace });
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<template>
|
|
65
|
+
<ViewOutlet :content="state?.main" :registry="pages"><p>Connecting…</p></ViewOutlet>
|
|
66
|
+
</template>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`satisfies ViewRegistry<…>` checks that every kind has a component whose `page`
|
|
70
|
+
prop accepts that reference.
|
|
71
|
+
|
|
72
|
+
## `useCommand(command)`
|
|
73
|
+
|
|
74
|
+
Returns a reactive `{ run, pending, error, failure, reset }`. Read `increment.pending`,
|
|
75
|
+
`increment.error` and `increment.failure` from the object rather than destructuring them.
|
|
76
|
+
`run(...args)` resolves to the command's result, or to `undefined` after a
|
|
77
|
+
failure, which `error` then holds until the next run. It never rejects, so
|
|
78
|
+
handlers need no `try`/`catch`. One command can serve several buttons:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const navigate = useCommand((name: "showWelcome" | "showCounter") => client.value?.[name]());
|
|
82
|
+
// <button @click="navigate.run('showWelcome')">Welcome</button>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
For a command that declares a failure (`[RunicFailure]` in .NET), `run` resolves the
|
|
86
|
+
`BridgeOutcome`, and `failure` holds the declared failure of the latest run, typed
|
|
87
|
+
from the outcome, while `error` keeps unexpected failures. Starting a run and
|
|
88
|
+
`reset()` clear both, and a run superseded by a later run or by `reset()` sets
|
|
89
|
+
neither.
|
|
90
|
+
|
|
91
|
+
## `useCollectionViewport(options)`
|
|
92
|
+
|
|
93
|
+
Follows a fixed-row-height scroll container and returns `{ viewport, attach }`.
|
|
94
|
+
`viewport` is a shallow ref with the [`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/main/packages/web/views#collectionviewportoptions)
|
|
95
|
+
range; `attach` is a function ref for the container. Pass a getter for the
|
|
96
|
+
options and watch the range to send it to the ViewModel:
|
|
97
|
+
|
|
98
|
+
```vue
|
|
99
|
+
<script setup lang="ts">
|
|
100
|
+
const { state, client } = useView(() => props.page);
|
|
101
|
+
const { viewport, attach } = useCollectionViewport(() => ({ totalCount: state.value?.totalCount ?? 0, rowHeight: 32 }));
|
|
102
|
+
watch(() => [viewport.value.start, viewport.value.size] as const, ([start, size]) => {
|
|
103
|
+
if (size !== 0) void client.value?.setViewport({ start, size });
|
|
104
|
+
});
|
|
105
|
+
</script>
|
|
106
|
+
|
|
107
|
+
<template>
|
|
108
|
+
<div :ref="attach" style="height: 480px; overflow: auto">
|
|
109
|
+
<div :style="{ height: `${viewport.totalSize}px` }"><!-- state.rows --></div>
|
|
110
|
+
</div>
|
|
111
|
+
</template>
|
|
112
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
import { type MaybeRefOrGetter, type Ref } from "vue";
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
readonly snapshot: TState;
|
|
5
|
-
subscribe(listener: (state: TState) => void): () => void;
|
|
6
|
-
dispose(): void;
|
|
7
|
-
}
|
|
8
|
-
/** A generated content reference, or `{ connect: connect<Name> }` for a root ViewModel. */
|
|
9
|
-
export interface ViewReference<TClient extends ViewClient = ViewClient> {
|
|
10
|
-
connect(): Promise<TClient>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* A reference is connected and disposed by the composable. An already
|
|
14
|
-
* connected client is only observed; its owner disposes it.
|
|
15
|
-
*/
|
|
16
|
-
export type ViewSource<TClient extends ViewClient> = ViewReference<TClient> | TClient | null | undefined;
|
|
1
|
+
import { type Component, type ComponentPublicInstance, type MaybeRefOrGetter, type Ref } from "vue";
|
|
2
|
+
import { type BridgeOutcomeFailure, type CollectionViewport, type CollectionViewportOptions, type ViewClient, type ViewReference, type ViewSource } from "@runic-artifex/views";
|
|
3
|
+
export type { CollectionViewport, CollectionViewportOptions, ViewClient, ViewConnector, ViewReference, ViewSource } from "@runic-artifex/views";
|
|
17
4
|
export interface ViewHandle<TClient extends ViewClient> {
|
|
18
5
|
/** The latest state, or undefined until the client connects. */
|
|
19
6
|
readonly state: Readonly<Ref<TClient["snapshot"] | undefined>>;
|
|
@@ -21,6 +8,8 @@ export interface ViewHandle<TClient extends ViewClient> {
|
|
|
21
8
|
readonly client: Readonly<Ref<TClient | undefined>>;
|
|
22
9
|
/** The connection failure, if any. */
|
|
23
10
|
readonly error: Readonly<Ref<unknown>>;
|
|
11
|
+
/** True while a reference is connecting. */
|
|
12
|
+
readonly pending: Readonly<Ref<boolean>>;
|
|
24
13
|
/** Connects a reference again after a failure. */
|
|
25
14
|
retry(): void;
|
|
26
15
|
}
|
|
@@ -35,4 +24,85 @@ export interface ViewHandle<TClient extends ViewClient> {
|
|
|
35
24
|
* `{ connect: connectWorkspace }` object does not reconnect.
|
|
36
25
|
*/
|
|
37
26
|
export declare function useView<TClient extends ViewClient>(source: MaybeRefOrGetter<ViewSource<TClient>>): ViewHandle<TClient>;
|
|
27
|
+
/** A build-known map checks each generated reference kind against its component's `page` prop. */
|
|
28
|
+
export type ViewRegistry<R extends ViewReference> = {
|
|
29
|
+
readonly [K in R["kind"]]: Component<{
|
|
30
|
+
page: Extract<R, {
|
|
31
|
+
readonly kind: K;
|
|
32
|
+
}>;
|
|
33
|
+
}>;
|
|
34
|
+
};
|
|
35
|
+
export interface ViewOutletProps<R extends ViewReference> {
|
|
36
|
+
/** The presented reference, such as `state.main`. */
|
|
37
|
+
content: R | null | undefined;
|
|
38
|
+
registry: ViewRegistry<R>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Renders the registered component for a generated View reference and passes
|
|
42
|
+
* the reference as its `page` prop. A different reference remounts the
|
|
43
|
+
* component. A kind without a component renders an alert; the default slot
|
|
44
|
+
* renders while there is no content.
|
|
45
|
+
*/
|
|
46
|
+
export declare const ViewOutlet: new <R extends ViewReference>(props: (ViewOutletProps<R> & ({
|
|
47
|
+
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
|
48
|
+
} | {
|
|
49
|
+
[x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
|
|
50
|
+
})) & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps) => import("vue").CreateComponentPublicInstanceWithMixins<ViewOutletProps<R> & ({
|
|
51
|
+
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
|
52
|
+
} | {
|
|
53
|
+
[x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
|
|
54
|
+
}), {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, import("vue").PublicProps, {}, false, {}, {}, {}, {}, string, {}, any, import("vue").ComponentProvideOptions, {
|
|
55
|
+
P: {};
|
|
56
|
+
B: {};
|
|
57
|
+
D: {};
|
|
58
|
+
C: {};
|
|
59
|
+
M: {};
|
|
60
|
+
Defaults: {};
|
|
61
|
+
}, (ViewOutletProps<R> & {
|
|
62
|
+
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
|
63
|
+
}) | (ViewOutletProps<R> & {
|
|
64
|
+
[x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
|
|
65
|
+
}), {}, {}, {}, {}, {}>;
|
|
66
|
+
export interface CommandHandle<TArgs extends readonly unknown[], TResult, TFailure = BridgeOutcomeFailure<TResult>> {
|
|
67
|
+
/**
|
|
68
|
+
* Runs the command. Resolves to its result, including a `BridgeOutcome` with a
|
|
69
|
+
* declared failure, which `failure` then holds, or to undefined after an
|
|
70
|
+
* unexpected failure, which `error` then holds. Never rejects.
|
|
71
|
+
*/
|
|
72
|
+
run(...args: TArgs): Promise<TResult | undefined>;
|
|
73
|
+
/** True while a run is in flight. */
|
|
74
|
+
readonly pending: boolean;
|
|
75
|
+
/** Why the latest run failed unexpectedly, until the next run starts. */
|
|
76
|
+
readonly error: unknown;
|
|
77
|
+
/**
|
|
78
|
+
* The declared failure of the latest run, for a command that resolves a
|
|
79
|
+
* `BridgeOutcome`, until the next run starts. A superseded run sets neither.
|
|
80
|
+
*/
|
|
81
|
+
readonly failure: TFailure | undefined;
|
|
82
|
+
/** Clears `error` and `failure`. */
|
|
83
|
+
reset(): void;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Tracks a command's pending state and failure. The result is a reactive
|
|
87
|
+
* object, so templates read `increment.pending` directly; do not destructure
|
|
88
|
+
* `pending`, `error` or `failure`.
|
|
89
|
+
*
|
|
90
|
+
* ```vue
|
|
91
|
+
* const increment = useCommand(() => client.value?.increment());
|
|
92
|
+
* <button :disabled="!client || increment.pending" @click="increment.run()">…</button>
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function useCommand<TArgs extends readonly unknown[], TReturn>(command: (...args: TArgs) => TReturn): CommandHandle<TArgs, Awaited<TReturn>>;
|
|
96
|
+
export interface CollectionViewportHandle {
|
|
97
|
+
/** The rows to request and the sizes to render. */
|
|
98
|
+
readonly viewport: Readonly<Ref<CollectionViewport>>;
|
|
99
|
+
/** A function ref for the scroll container: `<div :ref="attach">`. */
|
|
100
|
+
attach(element: Element | ComponentPublicInstance | null): void;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Follows a fixed-row-height scroll container and returns the rows to request
|
|
104
|
+
* from .NET. Pass a getter such as `() => ({ totalCount: state.value?.totalCount ?? 0, rowHeight: 32 })`
|
|
105
|
+
* and watch `viewport` to send `start` and `size` to the ViewModel.
|
|
106
|
+
*/
|
|
107
|
+
export declare function useCollectionViewport(options: MaybeRefOrGetter<CollectionViewportOptions>): CollectionViewportHandle;
|
|
38
108
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,SAAS,EACd,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,GAAG,EAGT,MAAM,KAAK,CAAC;AACb,OAAO,EAKL,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,UAAU,EAChB,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,UAAU,EAAE,aAAa,EA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SAAS,aAAa;;;;;;;;;;;;;;;;;;;uBAMR,CAAC;AAE3D,MAAM,WAAW,aAAa,CAAC,KAAK,SAAS,SAAS,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,GAAG,oBAAoB,CAAC,OAAO,CAAC;IAChH;;;;OAIG;IACH,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;IAClD,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,yEAAyE;IACzE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,SAAS,CAAC;IACvC,oCAAoC;IACpC,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,KAAK,SAAS,SAAS,OAAO,EAAE,EAAE,OAAO,EAClE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,GACnC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAaxC;AAED,MAAM,WAAW,wBAAwB;IACvC,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC;IACrD,sEAAsE;IACtE,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,uBAAuB,GAAG,IAAI,GAAG,IAAI,CAAC;CACjE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,CAAC,yBAAyB,CAAC,GAAG,wBAAwB,CAiBpH"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { getCurrentScope, onScopeDispose, shallowRef, toValue, watch } from "vue";
|
|
2
|
-
|
|
3
|
-
return typeof source.subscribe === "function";
|
|
4
|
-
}
|
|
1
|
+
import { defineComponent, getCurrentScope, h, onScopeDispose, shallowReactive, shallowRef, toValue, watch, } from "vue";
|
|
2
|
+
import { createCollectionViewportController, createCommandController, createViewController, viewSourceIdentity, } from "@runic-artifex/views";
|
|
5
3
|
/**
|
|
6
4
|
* Connects a generated View reference while the current effect scope (for
|
|
7
5
|
* example a component) is active and exposes its state as shallow refs. A
|
|
@@ -13,51 +11,97 @@ function isClient(source) {
|
|
|
13
11
|
* `{ connect: connectWorkspace }` object does not reconnect.
|
|
14
12
|
*/
|
|
15
13
|
export function useView(source) {
|
|
14
|
+
const controller = createViewController();
|
|
16
15
|
const state = shallowRef();
|
|
17
16
|
const client = shallowRef();
|
|
18
17
|
const error = shallowRef();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
18
|
+
const pending = shallowRef(false);
|
|
19
|
+
const sync = () => {
|
|
20
|
+
const current = controller.current;
|
|
21
|
+
state.value = current.state;
|
|
22
|
+
client.value = current.client;
|
|
23
|
+
error.value = current.error;
|
|
24
|
+
pending.value = current.pending;
|
|
25
|
+
};
|
|
26
|
+
controller.subscribe(sync);
|
|
27
|
+
watch(() => viewSourceIdentity(toValue(source)), () => {
|
|
28
|
+
controller.setSource(toValue(source));
|
|
29
|
+
sync();
|
|
30
|
+
}, { immediate: true });
|
|
31
|
+
if (getCurrentScope())
|
|
32
|
+
onScopeDispose(() => controller.dispose());
|
|
33
|
+
return { state, client, error, pending, retry: () => controller.retry() };
|
|
34
|
+
}
|
|
35
|
+
const referenceKeys = new WeakMap();
|
|
36
|
+
let nextReferenceKey = 0;
|
|
37
|
+
function referenceKey(reference) {
|
|
38
|
+
let key = referenceKeys.get(reference);
|
|
39
|
+
if (key === undefined)
|
|
40
|
+
referenceKeys.set(reference, key = ++nextReferenceKey);
|
|
41
|
+
return key;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Renders the registered component for a generated View reference and passes
|
|
45
|
+
* the reference as its `page` prop. A different reference remounts the
|
|
46
|
+
* component. A kind without a component renders an alert; the default slot
|
|
47
|
+
* renders while there is no content.
|
|
48
|
+
*/
|
|
49
|
+
export const ViewOutlet = defineComponent((props, { slots }) => () => {
|
|
50
|
+
const content = props.content;
|
|
51
|
+
if (!content)
|
|
52
|
+
return slots.default?.();
|
|
53
|
+
const component = props.registry[content.kind];
|
|
54
|
+
if (!component)
|
|
55
|
+
return h("p", { role: "alert" }, `No web component is registered for ${content.kind}.`);
|
|
56
|
+
return h(component, { key: referenceKey(content), page: content });
|
|
57
|
+
}, { name: "ViewOutlet", props: ["content", "registry"] });
|
|
58
|
+
/**
|
|
59
|
+
* Tracks a command's pending state and failure. The result is a reactive
|
|
60
|
+
* object, so templates read `increment.pending` directly; do not destructure
|
|
61
|
+
* `pending`, `error` or `failure`.
|
|
62
|
+
*
|
|
63
|
+
* ```vue
|
|
64
|
+
* const increment = useCommand(() => client.value?.increment());
|
|
65
|
+
* <button :disabled="!client || increment.pending" @click="increment.run()">…</button>
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function useCommand(command) {
|
|
69
|
+
const controller = createCommandController(command);
|
|
70
|
+
const handle = shallowReactive({
|
|
71
|
+
run: controller.run, pending: false, error: undefined, failure: undefined, reset: controller.reset,
|
|
72
|
+
});
|
|
73
|
+
controller.subscribe(() => {
|
|
74
|
+
const writable = handle;
|
|
75
|
+
writable.pending = controller.current.pending;
|
|
76
|
+
writable.error = controller.current.error;
|
|
77
|
+
writable.failure = controller.current.failure;
|
|
78
|
+
});
|
|
79
|
+
if (getCurrentScope())
|
|
80
|
+
onScopeDispose(() => controller.dispose());
|
|
81
|
+
return handle;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Follows a fixed-row-height scroll container and returns the rows to request
|
|
85
|
+
* from .NET. Pass a getter such as `() => ({ totalCount: state.value?.totalCount ?? 0, rowHeight: 32 })`
|
|
86
|
+
* and watch `viewport` to send `start` and `size` to the ViewModel.
|
|
87
|
+
*/
|
|
88
|
+
export function useCollectionViewport(options) {
|
|
89
|
+
const controller = createCollectionViewportController(toValue(options));
|
|
90
|
+
const viewport = shallowRef(controller.current);
|
|
91
|
+
controller.subscribe(() => { viewport.value = controller.current; });
|
|
55
92
|
watch(() => {
|
|
56
|
-
const
|
|
57
|
-
return
|
|
58
|
-
},
|
|
93
|
+
const { totalCount, rowHeight, overscan } = toValue(options);
|
|
94
|
+
return [totalCount, rowHeight, overscan];
|
|
95
|
+
}, ([totalCount, rowHeight, overscan]) => {
|
|
96
|
+
controller.update({ totalCount, rowHeight, ...(overscan === undefined ? {} : { overscan }) });
|
|
97
|
+
});
|
|
59
98
|
if (getCurrentScope())
|
|
60
|
-
onScopeDispose(() =>
|
|
61
|
-
return {
|
|
99
|
+
onScopeDispose(() => controller.dispose());
|
|
100
|
+
return {
|
|
101
|
+
viewport,
|
|
102
|
+
attach(element) {
|
|
103
|
+
controller.attach(typeof HTMLElement !== "undefined" && element instanceof HTMLElement ? element : null);
|
|
104
|
+
},
|
|
105
|
+
};
|
|
62
106
|
}
|
|
63
107
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names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CAAC,UAAU,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,EAAE;QACvC,UAAU,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;IAChG,CAAC,CAAC,CAAC;IACH,IAAI,eAAe,EAAE;QAAE,cAAc,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;IAClE,OAAO;QACL,QAAQ;QACR,MAAM,CAAC,OAAO;YACZ,UAAU,CAAC,MAAM,CAAC,OAAO,WAAW,KAAK,WAAW,IAAI,OAAO,YAAY,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC3G,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runic-artifex/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-preview.2",
|
|
4
4
|
"description": "Vue composables for generated Runic Views clients",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,13 +24,16 @@
|
|
|
24
24
|
"clean": "bun -e \"import('node:fs').then(({rmSync}) => rmSync('dist', { recursive: true, force: true }))\"",
|
|
25
25
|
"build": "bun run --bun clean && tsc -p tsconfig.build.json",
|
|
26
26
|
"check": "tsc -p tsconfig.json --noEmit",
|
|
27
|
-
"test": "bun run --bun build && vitest run",
|
|
27
|
+
"test": "bun run --bun build && tsc -p tsconfig.json --noEmit && vitest run",
|
|
28
28
|
"pack:check": "bun pm pack --dry-run"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"vue": ">=3.5.0 <4"
|
|
31
|
+
"vue": ">=3.5.0 <4",
|
|
32
|
+
"@runic-artifex/views": "0.7.0-preview.2"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
35
|
+
"@runic-artifex/views": "0.7.0-preview.2",
|
|
36
|
+
"happy-dom": "20.14.5",
|
|
34
37
|
"typescript": "6.0.3",
|
|
35
38
|
"vitest": "5.0.3",
|
|
36
39
|
"vue": "3.5.43"
|
|
@@ -57,5 +60,5 @@
|
|
|
57
60
|
"views",
|
|
58
61
|
"vue"
|
|
59
62
|
],
|
|
60
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "0e915be4f0618af6260b9d8b416c9afc1826b80d"
|
|
61
64
|
}
|