0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-22 14:49:27 -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[]; 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 { export interface PenpotContext {
root: PenpotShape; readonly root: PenpotShape;
currentPage: PenpotPage; readonly currentPage: PenpotPage;
readonly viewport: PenpotViewport;
readonly library: PenpotLibraryContext;
readonly currentUser: PenpotUser;
readonly activeUsers: PenpotActiveUser;
selection: PenpotShape[]; selection: PenpotShape[];
viewport: PenpotViewport;
library: PenpotLibraryContext;
getFile(): PenpotFile | null; getFile(): PenpotFile | null;
getPage(): PenpotPage | null; getPage(): PenpotPage | null;

View file

@ -16,6 +16,8 @@ import type {
PenpotPath, PenpotPath,
PenpotBoolType, PenpotBoolType,
PenpotBool, PenpotBool,
PenpotUser,
PenpotActiveUser,
} from '@penpot/plugin-types'; } from '@penpot/plugin-types';
import { Manifest, Permissions } from '../models/manifest.model.js'; import { Manifest, Permissions } from '../models/manifest.model.js';
@ -194,6 +196,16 @@ export function createApi(context: PenpotContext, manifest: Manifest): Penpot {
return context.library; return context.library;
}, },
get currentUser(): PenpotUser {
// checkPermission('user:read');
return context.currentUser;
},
get activeUsers(): PenpotActiveUser {
// checkPermission('activeUsers:read');
return context.activeUsers;
},
getFile(): PenpotFile | null { getFile(): PenpotFile | null {
checkPermission('file:read'); checkPermission('file:read');
return context.getFile(); return context.getFile();