Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hocuspocus/provider

Package Overview
Dependencies
Maintainers
0
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hocuspocus/provider - npm Package Compare versions

Comparing version 2.14.0 to 2.15.0

23

dist/packages/provider/src/TiptapCollabProvider.d.ts

@@ -5,3 +5,3 @@ import type { AbstractType, YArrayEvent } from 'yjs';

import { TiptapCollabProviderWebsocket } from './TiptapCollabProviderWebsocket.js';
import type { DeleteCommentOptions, TCollabComment, TCollabThread, THistoryVersion } from './types.js';
import { type DeleteCommentOptions, type DeleteThreadOptions, type GetThreadsOptions, type TCollabComment, type TCollabThread, type THistoryVersion } from './types.js';
export type TiptapCollabProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & (Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'websocketProvider'>> | Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'appId'>> | Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'baseUrl'>>) & Pick<AdditionalTiptapCollabProviderConfiguration, 'user'> & {

@@ -59,5 +59,6 @@ /**

* Finds all threads in the document and returns them as JSON objects
* @options Options to control the output of the threads (e.g. include deleted threads)
* @returns An array of threads as JSON objects
*/
getThreads<Data, CommentData>(): TCollabThread<Data, CommentData>[];
getThreads<Data, CommentData>(options?: GetThreadsOptions): TCollabThread<Data, CommentData>[];
/**

@@ -86,3 +87,3 @@ * Find the index of a thread by its id

*/
createThread(data: Omit<TCollabThread, 'id' | 'createdAt' | 'updatedAt' | 'comments' | 'deletedComments'>): TCollabThread;
createThread(data: Omit<TCollabThread, 'id' | 'createdAt' | 'updatedAt' | 'deletedAt' | 'comments' | 'deletedComments'>): TCollabThread;
/**

@@ -98,8 +99,18 @@ * Update a specific thread

/**
* Delete a specific thread and all its comments
* Handle the deletion of a thread. By default, the thread and it's comments are not deleted, but marked as deleted
* via the `deletedAt` property. Forceful deletion can be enabled by setting the `force` option to `true`.
*
* If you only want to delete the comments of a thread, you can set the `deleteComments` option to `true`.
* @param id The thread id
* @returns void
* @param options A set of options that control how the thread is deleted
* @returns The deleted thread or null if the thread is not found
*/
deleteThread(id: TCollabThread['id']): void;
deleteThread(id: TCollabThread['id'], options?: DeleteThreadOptions): TCollabThread | null | undefined;
/**
* Tries to restore a deleted thread
* @param id The thread id
* @returns The restored thread or null if the thread is not found
*/
restoreThread(id: TCollabThread['id']): TCollabThread | null;
/**
* Returns comments from a thread, either deleted or not

@@ -106,0 +117,0 @@ * @param threadId The thread id

@@ -91,2 +91,3 @@ import { Encoder } from 'lib0/encoding';

updatedAt: number;
deletedAt: number | null;
resolvedAt?: string;

@@ -160,1 +161,28 @@ comments: TCollabComment<CommentData>[];

};
export type DeleteThreadOptions = {
/**
* If `true`, will remove the comments on the thread,
* otherwise will only mark the thread as deleted
* and keep the comments
* @default false
*/
deleteComments?: boolean;
/**
* If `true`, will forcefully remove the thread and all comments,
* otherwise will only mark the thread as deleted
* and keep the comments
* @default false
*/
force?: boolean;
};
/**
* The type of thread
*/
export type ThreadType = 'archived' | 'unarchived';
export type GetThreadsOptions = {
/**
* The types of threads to get
* @default ['unarchived']
*/
types?: Array<ThreadType>;
};
{
"name": "@hocuspocus/provider",
"version": "2.14.0",
"version": "2.15.0",
"description": "hocuspocus provider",

@@ -32,3 +32,3 @@ "homepage": "https://hocuspocus.dev",

"dependencies": {
"@hocuspocus/common": "^2.14.0",
"@hocuspocus/common": "^2.15.0",
"@lifeomic/attempt": "^3.0.2",

@@ -35,0 +35,0 @@ "lib0": "^0.2.87",

@@ -10,5 +10,7 @@ import type { AbstractType, YArrayEvent } from 'yjs'

import { TiptapCollabProviderWebsocket } from './TiptapCollabProviderWebsocket.js'
import type {
DeleteCommentOptions,
TCollabComment, TCollabThread, THistoryVersion,
import {
type DeleteCommentOptions,
type DeleteThreadOptions,
type GetThreadsOptions,
type TCollabComment, type TCollabThread, type THistoryVersion,
} from './types.js'

@@ -21,2 +23,11 @@

const defaultGetThreadsOptions: GetThreadsOptions = {
types: ['unarchived'],
}
const defaultDeleteThreadOptions: DeleteThreadOptions = {
deleteComments: false,
force: false,
}
export type TiptapCollabProviderConfiguration =

@@ -133,6 +144,25 @@ Required<Pick<HocuspocusProviderConfiguration, 'name'>> &

* Finds all threads in the document and returns them as JSON objects
* @options Options to control the output of the threads (e.g. include deleted threads)
* @returns An array of threads as JSON objects
*/
getThreads<Data, CommentData>(): TCollabThread<Data, CommentData>[] {
return this.getYThreads().toJSON() as TCollabThread<Data, CommentData>[]
getThreads<Data, CommentData>(options?: GetThreadsOptions): TCollabThread<Data, CommentData>[] {
const { types } = { ...defaultGetThreadsOptions, ...options } as GetThreadsOptions
const threads = this.getYThreads().toJSON() as TCollabThread<Data, CommentData>[]
if (types?.includes('archived') && types?.includes('unarchived')) {
return threads
}
return threads.filter(currentThead => {
if (types?.includes('archived') && currentThead.deletedAt) {
return true
}
if (types?.includes('unarchived') && !currentThead.deletedAt) {
return true
}
return false
})
}

@@ -150,3 +180,3 @@

// eslint-disable-next-line no-restricted-syntax
for (const thread of this.getThreads()) {
for (const thread of this.getThreads({ types: ['archived', 'unarchived'] })) {
if (thread.id === id) {

@@ -197,3 +227,3 @@ index = i

*/
createThread(data: Omit<TCollabThread, 'id' | 'createdAt' | 'updatedAt' | 'comments' | 'deletedComments'>) {
createThread(data: Omit<TCollabThread, 'id' | 'createdAt' | 'updatedAt' | 'deletedAt' | 'comments' | 'deletedComments'>) {
let createdThread: TCollabThread = {} as TCollabThread

@@ -207,2 +237,3 @@

thread.set('deletedComments', new Y.Array())
thread.set('deletedAt', null)

@@ -251,17 +282,56 @@ this.getYThreads().push([thread])

/**
* Delete a specific thread and all its comments
* Handle the deletion of a thread. By default, the thread and it's comments are not deleted, but marked as deleted
* via the `deletedAt` property. Forceful deletion can be enabled by setting the `force` option to `true`.
*
* If you only want to delete the comments of a thread, you can set the `deleteComments` option to `true`.
* @param id The thread id
* @returns void
* @param options A set of options that control how the thread is deleted
* @returns The deleted thread or null if the thread is not found
*/
deleteThread(id: TCollabThread['id']) {
deleteThread(id: TCollabThread['id'], options?: DeleteThreadOptions) {
const { deleteComments, force } = { ...defaultDeleteThreadOptions, ...options }
const index = this.getThreadIndex(id)
if (index === null) {
return null
}
if (force) {
this.getYThreads().delete(index, 1)
return
}
this.getYThreads().delete(index, 1)
const thread = this.getYThreads().get(index)
thread.set('deletedAt', (new Date()).toISOString())
if (deleteComments) {
thread.set('comments', new Y.Array())
thread.set('deletedComments', new Y.Array())
}
return thread.toJSON() as TCollabThread
}
/**
* Tries to restore a deleted thread
* @param id The thread id
* @returns The restored thread or null if the thread is not found
*/
restoreThread(id: TCollabThread['id']) {
const index = this.getThreadIndex(id)
if (index === null) {
return null
}
const thread = this.getYThreads().get(index)
thread.set('deletedAt', null)
return thread.toJSON() as TCollabThread
}
/**
* Returns comments from a thread, either deleted or not

@@ -268,0 +338,0 @@ * @param threadId The thread id

@@ -113,2 +113,3 @@ import { Encoder } from 'lib0/encoding'

updatedAt: number;
deletedAt: number | null;
resolvedAt?: string; // (new Date()).toISOString()

@@ -201,1 +202,32 @@ comments: TCollabComment<CommentData>[];

}
export type DeleteThreadOptions = {
/**
* If `true`, will remove the comments on the thread,
* otherwise will only mark the thread as deleted
* and keep the comments
* @default false
*/
deleteComments?: boolean
/**
* If `true`, will forcefully remove the thread and all comments,
* otherwise will only mark the thread as deleted
* and keep the comments
* @default false
*/
force?: boolean,
}
/**
* The type of thread
*/
export type ThreadType = 'archived' | 'unarchived'
export type GetThreadsOptions = {
/**
* The types of threads to get
* @default ['unarchived']
*/
types?: Array<ThreadType>
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc