@field-studio/vue 0.0.0-stage → 0.1.3
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 +21 -0
- package/README.md +43 -2
- package/dist/index.d.ts +13 -0
- package/dist/index.js +39 -0
- package/package.json +42 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrew Lyu
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @field-studio/vue
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Vue 3 client injection and task subscriptions for Field Studio. The package uses
|
|
4
|
+
ESM and is licensed under MIT.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm install @field-studio/sdk @field-studio/vue 'vue@^3.5.0'
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Create a workspace client for the authenticated host and install the plugin on
|
|
11
|
+
your Vue app.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createWorkspaceClient } from '@field-studio/sdk';
|
|
15
|
+
import { createFieldStudio } from '@field-studio/vue';
|
|
16
|
+
|
|
17
|
+
const client = createWorkspaceClient({ fetch: authenticatedFetch });
|
|
18
|
+
app.use(createFieldStudio(client));
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The host provides the same-origin `/api/platform` routes and a fetch function
|
|
22
|
+
that attaches the CSRF token to writes and handles session expiry. Create the
|
|
23
|
+
client for the current authenticated host.
|
|
24
|
+
|
|
25
|
+
Use `usePlatform()` in component setup to access the injected client.
|
|
26
|
+
`useTaskSubscription()` accepts a task ID, ref, or getter. It returns readonly
|
|
27
|
+
`data` and `error` refs and begins polling after the component mounts.
|
|
28
|
+
|
|
29
|
+
```vue
|
|
30
|
+
<script setup lang="ts">
|
|
31
|
+
import { useTaskSubscription } from '@field-studio/vue';
|
|
32
|
+
|
|
33
|
+
const props = defineProps<{ taskId: string | null }>();
|
|
34
|
+
const { data, error } = useTaskSubscription(() => props.taskId);
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<template>
|
|
38
|
+
<p v-if="error" role="alert">{{ error.message }}</p>
|
|
39
|
+
<p v-else-if="data">{{ data.status }}</p>
|
|
40
|
+
</template>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Polling stops at a terminal task status or a read error. Changing the task ID or
|
|
44
|
+
unmounting the component cancels pending reads and timers.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type WorkspaceClient } from '@field-studio/sdk';
|
|
2
|
+
import { type MaybeRefOrGetter, type Plugin, type Ref } from 'vue';
|
|
3
|
+
/** Install a host-provided workspace client in one Vue application. */
|
|
4
|
+
export declare function createFieldStudio(client: WorkspaceClient): Plugin;
|
|
5
|
+
/** Access the workspace client for the current application. */
|
|
6
|
+
export declare function usePlatform(): WorkspaceClient;
|
|
7
|
+
/** Poll task state after mounting and cancel pending reads when the task changes or unmounts. */
|
|
8
|
+
export declare function useTaskSubscription<T extends {
|
|
9
|
+
status: string;
|
|
10
|
+
}>(id: MaybeRefOrGetter<string | null>, interval?: number): {
|
|
11
|
+
data: Readonly<Ref<T | null>>;
|
|
12
|
+
error: Readonly<Ref<Error | null>>;
|
|
13
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { subscribeToTask } from '@field-studio/sdk';
|
|
2
|
+
import { inject, onMounted, shallowReadonly, shallowRef, toValue, watch, } from 'vue';
|
|
3
|
+
const platformKey = Symbol('Field Studio workspace client');
|
|
4
|
+
/** Install a host-provided workspace client in one Vue application. */
|
|
5
|
+
export function createFieldStudio(client) {
|
|
6
|
+
return {
|
|
7
|
+
install(app) {
|
|
8
|
+
app.provide(platformKey, client);
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/** Access the workspace client for the current application. */
|
|
13
|
+
export function usePlatform() {
|
|
14
|
+
const client = inject(platformKey);
|
|
15
|
+
if (!client)
|
|
16
|
+
throw new Error('Install the Field Studio plugin before using usePlatform');
|
|
17
|
+
return client;
|
|
18
|
+
}
|
|
19
|
+
/** Poll task state after mounting and cancel pending reads when the task changes or unmounts. */
|
|
20
|
+
export function useTaskSubscription(id, interval = 1500) {
|
|
21
|
+
const client = usePlatform();
|
|
22
|
+
const data = shallowRef(null);
|
|
23
|
+
const error = shallowRef(null);
|
|
24
|
+
onMounted(() => {
|
|
25
|
+
watch(() => toValue(id), (taskId, _previous, onCleanup) => {
|
|
26
|
+
data.value = null;
|
|
27
|
+
error.value = null;
|
|
28
|
+
if (!taskId)
|
|
29
|
+
return;
|
|
30
|
+
const stop = subscribeToTask(client, taskId, {
|
|
31
|
+
interval,
|
|
32
|
+
onData: (task) => { data.value = task; },
|
|
33
|
+
onError: (failure) => { error.value = failure; },
|
|
34
|
+
});
|
|
35
|
+
onCleanup(stop);
|
|
36
|
+
}, { immediate: true });
|
|
37
|
+
});
|
|
38
|
+
return { data: shallowReadonly(data), error: shallowReadonly(error) };
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@field-studio/vue",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Vue composables for Field Studio",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/apemost/field-studio.git",
|
|
9
|
+
"directory": "sdk/typescript/packages/vue"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=24"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"registry": "https://registry.npmjs.org/"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@field-studio/sdk": "^0.1.3",
|
|
30
|
+
"vue": "^3.5.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@field-studio/sdk": "0.1.3",
|
|
34
|
+
"jsdom": "^27.0.0",
|
|
35
|
+
"typescript": "^5.9.0",
|
|
36
|
+
"vite": "^7.0.0",
|
|
37
|
+
"vitest": "^3.2.0",
|
|
38
|
+
"vue": "^3.5.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc -p tsconfig.build.json",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"test": "vitest run"
|
|
44
|
+
}
|
|
6
45
|
}
|