@antcde/vue-utils 0.0.4

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.
@@ -0,0 +1,5 @@
1
+ export { useAntColorMode, type UseAntColorModeOptions, type UseAntColorModeReturn } from './useAntColorMode';
2
+ export { useAntI18n, type UseAntI18nReturn } from './useAntI18n';
3
+ export { type UseCommsClient, useCommsClient } from './useCommsClient';
4
+ export { type CommsHostArgs, type UseCommsHost, useCommsHost } from './useCommsHost';
5
+ export { type AnyUseApiReturn, type CommsToolbar, useApi, type UseApiReturn, useCommsInjection, useSingleton } from './utils';
@@ -0,0 +1,17 @@
1
+ import { UseCommsClient } from './useCommsClient';
2
+ import { BasicColorSchema, UseColorModeOptions, UseColorModeReturn } from '@vueuse/core';
3
+ import { Ref } from 'vue';
4
+
5
+ export type UseAntColorModeOptions = UseColorModeOptions<BasicColorSchema>;
6
+ export type UseAntColorModeReturn = UseColorModeReturn<BasicColorSchema> & {
7
+ host: Ref<boolean | null | undefined>;
8
+ isDark: Ref<boolean>;
9
+ };
10
+ /**
11
+ * A mixture of @vueuse color mode and the dark mode coming from ANT OS.
12
+ *
13
+ * It also exposes the value of the ANT OS through the `host` prop and a simple boolean through `isDark`.
14
+ * @param comms
15
+ * @param options
16
+ */
17
+ export declare function useAntColorMode(comms: UseCommsClient, options?: UseAntColorModeOptions): UseAntColorModeReturn;
@@ -0,0 +1,10 @@
1
+ import { UseI18nOptions, useI18n } from 'vue-i18n';
2
+ import { UseCommsClient } from './useCommsClient';
3
+
4
+ export type UseAntI18nReturn<Options extends UseI18nOptions = UseI18nOptions> = ReturnType<typeof useI18n<Options>>;
5
+ /**
6
+ * Listens to the changing locale received from comms and translations will automatically refresh due to internal watcher.
7
+ * @param comms
8
+ * @param options
9
+ */
10
+ export declare function useAntI18n<Options extends UseI18nOptions = UseI18nOptions>(comms: UseCommsClient, options?: Options): UseAntI18nReturn<Options>;
@@ -0,0 +1,26 @@
1
+ import { AntConnect, Client, Context, LocaleData, Signal } from '@antcde/connect-ts';
2
+ import { ObservableInput } from 'rxjs';
3
+ import { CommsToolbar } from './utils';
4
+ import { Ref } from 'vue';
5
+
6
+ export interface UseCommsClient extends Omit<Client, 'context' | 'toolbar' | 'appState' | 'locales'> {
7
+ context: Ref<Context>;
8
+ toolbar: CommsToolbar;
9
+ appState: Ref<string>;
10
+ locales: Ref<LocaleData>;
11
+ }
12
+ type KeyboardShortcutsHook = (signal: Signal) => ObservableInput<Signal>;
13
+ /**
14
+ *
15
+ * If you want to override the shortucts behaviour, you can add a callback to do so. The example only accepts showing an overlay. All other keyboard invoked actions are disabled.
16
+ *
17
+ * ```
18
+ * keyboardsShortcuts: (signal) => signal.overlay?.action === 'show' ? Promise.resolve(signal) : []
19
+ * ```
20
+ *
21
+ * @param connect default instance for network calls
22
+ * @param keyboardsShortcuts By default it will process keyboards from the client and send them to the host.
23
+ *
24
+ */
25
+ export declare function useCommsClient(connect?: AntConnect, keyboardsShortcuts?: KeyboardShortcutsHook): UseCommsClient;
26
+ export {};
@@ -0,0 +1,35 @@
1
+ import { AntConnect, License, Notepad, Notification, ProjectShort, SignalReceiver, SignalSender, Task, User } from '@antcde/connect-ts';
2
+ import { SubscriptionLike } from 'rxjs';
3
+ import { Ref } from 'vue';
4
+ import { CommsToolbar } from './utils';
5
+
6
+ type Nullable<T> = NonNullable<T> | null | undefined;
7
+ export interface CommsHostArgs {
8
+ connect: AntConnect;
9
+ addNotification: (notification: Notification) => void;
10
+ toolbar: CommsToolbar;
11
+ notepad: Notepad;
12
+ context: {
13
+ license: Ref<Nullable<License>>;
14
+ user: Ref<Nullable<User>>;
15
+ /**
16
+ * @Deprecated - use `selectedTask` or `notepadTask` instead
17
+ */
18
+ task: Ref<Nullable<Task>>;
19
+ notepadTask: Ref<Nullable<Task>>;
20
+ selectedTask: Ref<Nullable<Task>>;
21
+ project: Ref<Nullable<ProjectShort>>;
22
+ sbs: Ref<Nullable<{
23
+ code: string;
24
+ }>>;
25
+ darkMode: Ref<Nullable<boolean>>;
26
+ };
27
+ }
28
+ export interface UseCommsHost extends CommsHostArgs, SubscriptionLike {
29
+ client: Ref<HTMLIFrameElement | null | undefined>;
30
+ appState: Ref<string>;
31
+ isConnectionInitialized: Ref<boolean>;
32
+ signal: SignalReceiver & SignalSender;
33
+ }
34
+ export declare function useCommsHost(args: CommsHostArgs): UseCommsHost;
35
+ export {};
@@ -0,0 +1,33 @@
1
+ import { ToolbarItem } from '@antcde/connect-ts';
2
+ import { UseAsyncStateOptions, UseAsyncStateReturn } from '@vueuse/core';
3
+ import { FunctionPlugin, Ref, UnwrapRef } from 'vue';
4
+ import { UseCommsClient } from './useCommsClient';
5
+
6
+ type RefObject<T> = {
7
+ [K in keyof T]: T[K];
8
+ };
9
+ export declare function unrefObject<T extends object>(obj: RefObject<T>): UnwrapRef<T>;
10
+ export interface CommsToolbar {
11
+ start: Ref<ToolbarItem | undefined>;
12
+ title: Ref<string | undefined>;
13
+ searchEnabled: Ref<boolean>;
14
+ search: Ref<string>;
15
+ menu: Ref<ToolbarItem[]>;
16
+ isLoading: Ref<boolean>;
17
+ }
18
+ interface UseCommsFactoryResult {
19
+ provideComms: FunctionPlugin;
20
+ injectComms: () => UseCommsClient;
21
+ }
22
+ export declare function useCommsInjection(name?: string): UseCommsFactoryResult;
23
+ export declare function useSingleton<T extends object>(name: string, factory: () => T, dispose?: (value: T) => void): [provide: FunctionPlugin, inject: () => T];
24
+ export declare function useApi<Data, Params extends any[] = [], Shallow extends boolean = true>(promise: Promise<Data> | ((...args: Params) => Promise<Data>), initialState: Data, options?: UseAsyncStateOptions<Shallow, Data>): UseApiReturn<Data, Params, Shallow>;
25
+ export interface UseApiReturn<Data, Params extends any[], Shallow extends boolean> extends Omit<UseAsyncStateReturn<Data, Params, Shallow>, 'execute'> {
26
+ execute: (...args: Params) => Promise<Data>;
27
+ executeDelayed: (delay: number, ...args: Params) => void;
28
+ }
29
+ /**
30
+ * A shorthand that implies all the generics to be any
31
+ */
32
+ export type AnyUseApiReturn = UseApiReturn<any, any, any>;
33
+ export {};
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@antcde/vue-utils",
3
+ "type": "module",
4
+ "version": "0.0.4",
5
+ "description": "Helper to use ANT Comms in Vue 3",
6
+ "author": "CollaborAll",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://npm.antcde.io"
10
+ },
11
+ "publishConfig": {
12
+ "registry": "https://npm.antcde.io"
13
+ },
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/types/index.d.ts",
17
+ "import": "./dist/index.js",
18
+ "require": "./dist/index.cjs.js"
19
+ }
20
+ },
21
+ "main": "./dist/index.cjs.js",
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/types/index.d.ts",
24
+ "files": [
25
+ "README.md",
26
+ "dist"
27
+ ],
28
+ "peerDependencies": {
29
+ "@vueuse/core": "^12.0.0",
30
+ "vue": "^3.5.10",
31
+ "vue-i18n": "^9.8.0"
32
+ },
33
+ "dependencies": {
34
+ "rxjs": "^7.8.1",
35
+ "@antcde/connect-ts": "0.0.58"
36
+ },
37
+ "devDependencies": {
38
+ "@vitejs/plugin-vue": "^5.0.3",
39
+ "@vue/tsconfig": "^0.5.1",
40
+ "typescript": "~5.3.3",
41
+ "vite": "^5.0.11",
42
+ "vite-plugin-dts": "^3.7.0",
43
+ "vue-tsc": "^1.8.27"
44
+ },
45
+ "scripts": {
46
+ "build": "vite build",
47
+ "type-check": "vue-tsc --noEmit",
48
+ "clean": "pnpm dlx rimraf dist"
49
+ }
50
+ }