diff --git a/libs/plugin-types/index.d.ts b/libs/plugin-types/index.d.ts index 44828e9..f796922 100644 --- a/libs/plugin-types/index.d.ts +++ b/libs/plugin-types/index.d.ts @@ -507,12 +507,28 @@ export type PenpotLibraryContext = { connected: PenpotLibrary[]; }; +export interface PenpotUser { + readonly id: string; + readonly name?: string; + readonly avatarUrl?: string; + readonly color: string; + readonly sessionId?: string; +} + +export interface PenpotActiveUser extends PenpotUser { + readonly position?: { x: number; y: number }; + readonly zoom?: number; +} + export interface PenpotContext { - root: PenpotShape; - currentPage: PenpotPage; + readonly root: PenpotShape; + readonly currentPage: PenpotPage; + readonly viewport: PenpotViewport; + readonly library: PenpotLibraryContext; + readonly currentUser: PenpotUser; + readonly activeUsers: PenpotActiveUser; + selection: PenpotShape[]; - viewport: PenpotViewport; - library: PenpotLibraryContext; getFile(): PenpotFile | null; getPage(): PenpotPage | null; diff --git a/libs/plugins-runtime/src/lib/api/index.ts b/libs/plugins-runtime/src/lib/api/index.ts index 771bb37..c067492 100644 --- a/libs/plugins-runtime/src/lib/api/index.ts +++ b/libs/plugins-runtime/src/lib/api/index.ts @@ -16,6 +16,8 @@ import type { PenpotPath, PenpotBoolType, PenpotBool, + PenpotUser, + PenpotActiveUser, } from '@penpot/plugin-types'; import { Manifest, Permissions } from '../models/manifest.model.js'; @@ -194,6 +196,16 @@ export function createApi(context: PenpotContext, manifest: Manifest): Penpot { return context.library; }, + get currentUser(): PenpotUser { + // checkPermission('user:read'); + return context.currentUser; + }, + + get activeUsers(): PenpotActiveUser { + // checkPermission('activeUsers:read'); + return context.activeUsers; + }, + getFile(): PenpotFile | null { checkPermission('file:read'); return context.getFile();