0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-06 14:50:21 -05:00

feat: typing for new features

This commit is contained in:
alonso.torres 2024-06-04 17:35:39 +02:00 committed by Alonso Torres
parent 64016f8255
commit 27c851b439
2 changed files with 32 additions and 4 deletions

View file

@ -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;

View file

@ -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();