@runic-artifex/vue 0.0.0-stage → 0.7.0-preview.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +111 -2
- package/dist/index.d.ts +108 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Runic Artifex contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -1,3 +1,112 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@runic-artifex/vue`
|
|
2
2
|
|
|
3
|
-
|
|
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:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @runic-artifex/vue@preview @runic-artifex/views@preview
|
|
9
|
+
pnpm add @runic-artifex/vue@preview @runic-artifex/views@preview
|
|
10
|
+
bun add @runic-artifex/vue@preview @runic-artifex/views@preview
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Previews are published under the `preview` dist-tag. Install the versions that
|
|
14
|
+
match your Runic SDK packages. Vue 3.5 or later is supported.
|
|
15
|
+
|
|
16
|
+
```vue
|
|
17
|
+
<script setup lang="ts">
|
|
18
|
+
import { useCommand, useView } from "@runic-artifex/vue";
|
|
19
|
+
import type { CounterPageReference } from "./generated/counter.js";
|
|
20
|
+
|
|
21
|
+
const props = defineProps<{ page: CounterPageReference }>();
|
|
22
|
+
const { state, client, error } = useView(() => props.page);
|
|
23
|
+
const increment = useCommand(() => client.value?.increment());
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
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>
|
|
29
|
+
</template>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## `useView(source)`
|
|
33
|
+
|
|
34
|
+
Returns shallow refs `{ state, client, error, pending }` and `retry()`:
|
|
35
|
+
|
|
36
|
+
- A generated page reference, or `{ connect: connect<Name> }` for a root
|
|
37
|
+
ViewModel, is connected while the current effect scope (normally the
|
|
38
|
+
component) is active. Disposing the scope or changing the reference disposes
|
|
39
|
+
the client. A reference is identified by its `connect` function, so a getter
|
|
40
|
+
that returns a new `{ connect: connectWorkspace }` object does not reconnect.
|
|
41
|
+
- An already connected client is observed and left to its owner.
|
|
42
|
+
- The source can be a value, a ref or a getter such as `() => props.page`.
|
|
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
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
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";
|
|
4
|
+
export interface ViewHandle<TClient extends ViewClient> {
|
|
5
|
+
/** The latest state, or undefined until the client connects. */
|
|
6
|
+
readonly state: Readonly<Ref<TClient["snapshot"] | undefined>>;
|
|
7
|
+
/** The connected client for commands, or undefined until it connects. */
|
|
8
|
+
readonly client: Readonly<Ref<TClient | undefined>>;
|
|
9
|
+
/** The connection failure, if any. */
|
|
10
|
+
readonly error: Readonly<Ref<unknown>>;
|
|
11
|
+
/** True while a reference is connecting. */
|
|
12
|
+
readonly pending: Readonly<Ref<boolean>>;
|
|
13
|
+
/** Connects a reference again after a failure. */
|
|
14
|
+
retry(): void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Connects a generated View reference while the current effect scope (for
|
|
18
|
+
* example a component) is active and exposes its state as shallow refs. A
|
|
19
|
+
* changed reference disposes the previous client; disposing the scope
|
|
20
|
+
* disposes the current one.
|
|
21
|
+
*
|
|
22
|
+
* Pass a getter such as `() => props.page` to follow a prop. A reference is
|
|
23
|
+
* identified by its `connect` function, so a getter returning a new
|
|
24
|
+
* `{ connect: connectWorkspace }` object does not reconnect.
|
|
25
|
+
*/
|
|
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;
|
|
108
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEhJ,MAAM,WAAW,UAAU,CAAC,OAAO,SAAS,UAAU;IACpD,gEAAgE;IAChE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAC/D,yEAAyE;IACzE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC;IACpD,sCAAsC;IACtC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IACvC,4CAA4C;IAC5C,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IACzC,kDAAkD;IAClD,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,OAAO,SAAS,UAAU,EAAE,MAAM,EAAE,gBAAgB,CAAC,UAAU,CAAC,OAAO,CAAC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AAC,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
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { defineComponent, getCurrentScope, h, onScopeDispose, shallowReactive, shallowRef, toValue, watch, } from "vue";
|
|
2
|
+
import { createCollectionViewportController, createCommandController, createViewController, viewSourceIdentity, } from "@runic-artifex/views";
|
|
3
|
+
/**
|
|
4
|
+
* Connects a generated View reference while the current effect scope (for
|
|
5
|
+
* example a component) is active and exposes its state as shallow refs. A
|
|
6
|
+
* changed reference disposes the previous client; disposing the scope
|
|
7
|
+
* disposes the current one.
|
|
8
|
+
*
|
|
9
|
+
* Pass a getter such as `() => props.page` to follow a prop. A reference is
|
|
10
|
+
* identified by its `connect` function, so a getter returning a new
|
|
11
|
+
* `{ connect: connectWorkspace }` object does not reconnect.
|
|
12
|
+
*/
|
|
13
|
+
export function useView(source) {
|
|
14
|
+
const controller = createViewController();
|
|
15
|
+
const state = shallowRef();
|
|
16
|
+
const client = shallowRef();
|
|
17
|
+
const error = shallowRef();
|
|
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; });
|
|
92
|
+
watch(() => {
|
|
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
|
+
});
|
|
98
|
+
if (getCurrentScope())
|
|
99
|
+
onScopeDispose(() => controller.dispose());
|
|
100
|
+
return {
|
|
101
|
+
viewport,
|
|
102
|
+
attach(element) {
|
|
103
|
+
controller.attach(typeof HTMLElement !== "undefined" && element instanceof HTMLElement ? element : null);
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,CAAC,EACD,cAAc,EACd,eA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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,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runic-artifex/vue",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.7.0-preview.1",
|
|
4
|
+
"description": "Vue composables for generated Runic Views clients",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"packageManager": "bun@1.4.2",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"clean": "bun -e \"import('node:fs').then(({rmSync}) => rmSync('dist', { recursive: true, force: true }))\"",
|
|
25
|
+
"build": "bun run --bun clean && tsc -p tsconfig.build.json",
|
|
26
|
+
"check": "tsc -p tsconfig.json --noEmit",
|
|
27
|
+
"test": "bun run --bun build && tsc -p tsconfig.json --noEmit && vitest run",
|
|
28
|
+
"pack:check": "bun pm pack --dry-run"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"vue": ">=3.5.0 <4",
|
|
32
|
+
"@runic-artifex/views": "0.7.0-preview.1"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@runic-artifex/views": "0.7.0-preview.1",
|
|
36
|
+
"happy-dom": "20.14.5",
|
|
37
|
+
"typescript": "6.0.3",
|
|
38
|
+
"vitest": "5.0.3",
|
|
39
|
+
"vue": "3.5.43"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=24.18.0 <25"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"tag": "preview"
|
|
47
|
+
},
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/Runic-Artifex/runic-sdk.git",
|
|
51
|
+
"directory": "packages/web/vue"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/main/packages/web/vue#readme",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/Runic-Artifex/runic-sdk/issues"
|
|
56
|
+
},
|
|
57
|
+
"keywords": [
|
|
58
|
+
"runic-artifex",
|
|
59
|
+
"runic",
|
|
60
|
+
"views",
|
|
61
|
+
"vue"
|
|
62
|
+
],
|
|
63
|
+
"gitHead": "7bc41a71c8a4d22ff5855e56b51067d6c02699c1"
|
|
64
|
+
}
|