Nutrient Web SDK

Class Comment

A text comment made by the user. A comment belongs to a thread by pointing its rootId to the id of a root annotation. The root annotation can be a NutrientViewer.Annotations.CommentMarkerAnnotation or an existing markup annotation with isCommentThreadRoot enabled.

Use NutrientViewer.Instance#create, NutrientViewer.Instance#getComments, NutrientViewer.Instance#update, and NutrientViewer.Instance#delete to create, read, update, and delete comments.

Class

Example

Create a comment thread with a marker annotation.

const rootId = NutrientViewer.generateInstantId();
const marker = new NutrientViewer.Annotations.CommentMarkerAnnotation({
id: rootId,
pageIndex: 0,
boundingBox: new NutrientViewer.Geometry.Rect({
top: 50,
left: 50,
width: 20,
height: 20,
}),
});
const comment = new NutrientViewer.Comment({
pageIndex: 0,
rootId,
text: {
format: "plain",
value: "Please review this area.",
},
});

await instance.create([marker, comment]);

Hierarchy

ReadonlyImmutableRecordComment

Constructors

  • Parameters

    options
    Partial<{ … }>
    Optional

Properties

canSetGroup

OptionalReadonly
boolean

This property defines whether the user has permission to edit the group of this comment. The value of this field depends on the set of collaboration permissions defined in the JWT token.

It is only available when collaboration permissions is enabled on Server-Backed deployments.

createdAt

Readonly

The time when the comment was created.

createdBy

Readonly
string | null

The ID of the user who created the comment, as determined by the authenticated user (the user_id claim of the JWT) that created it.

You cannot change who is recorded as the author: the value is assigned by the backend, and a locally set value is never sent. It is only available on Server-Backed deployments, and is null for comments created without an authenticated user, as well as when the server holds an author it can no longer resolve to an upstream user id.

creatorName

Readonly
string | null

The name of the person who created the comment.

customData

Readonly
Record<string, unknown> | null

Arbitrary JSON-serializable data the user can attach to the comment.

group

OptionalReadonly
string | null

This property is used to define the permission scope for a particular comment.

It is only available when collaboration permissions is enabled on Server-Backed deployments.

id

Readonly
string | null

A unique identifier for the comment. When comment is created in the UI, the viewer has to generate a unique ID.

isDeletable

OptionalReadonly
boolean

This property defines whether this comment can be deleted or not. The value of this field depends on the set of collaboration permissions defined in the JWT token.

It is only available when collaboration permissions is enabled on Server-Backed deployments.

isEditable

OptionalReadonly
boolean

This property defines whether this comment can be edited or not. The value of this field depends on the set of collaboration permissions defined in the JWT token.

It is only available when collaboration permissions is enabled on Server-Backed deployments.

pageIndex

Readonly
number | null

The page index that this comment resides at.

pdfObjectId

Readonly
number | null

If this comment is from the original PDF, then this ID is from that PDF note annotation that defined the comment.

rootId

Readonly
string | null

The ID of the annotation that this comment stems from. In Nutrient Web SDK, this should be either a NutrientViewer.Annotations.MarkupAnnotation or a NutrientViewer.Annotations.CommentMarkerAnnotation.

text

Readonly
{ format: "plain" | "xhtml"; value: string | null }

The text of the comment in xhtml/plain text format.

In case of XHTML, we support the following tags:

  • <b>: Bold
  • <i>: Italic
  • <span>: Font color, background color and underline using the style attribute (e.g. <span style="color: red; background-color: blue; text-decoration: underline">Hello</span>)
  • p: Paragraph. You can use this to add a newline between paragraphs.
  • a: Link. You can use this to add a link to the comment. The href attribute is required.
PropertyDescription
format
value

updatedAt

Readonly

The time when the comment was last updated.

Methods

  • Returns the record's [key, value] pairs, in the order its fields were defined.

    Returns

    IterableIterator<[string, unknown]>

    An iterator over the record's fields.

  • A method that returns a set of user IDs that are mentioned in the comment.

    Returns

    An immutable set of user IDs that are mentioned in the comment.

    Example

    const ids = comment.getMentionedUserIds()
    

Immutable Record API

27
  • Iterates the [key, value] pairs, in the order the fields were defined.

    Returns

    IterableIterator<
    [
    keyof { … },
    | string
    | number
    | boolean
    | Date
    | Record<string, unknown>
    | { format: "plain" | "xhtml"; value: string | null }
    | null
    | undefined
    ]
    >
  • Returns a record with every key reset to the default it was defined with.

    Returns

    this

    A new record holding only default values.

  • Returns a record with key reset to the default it was defined with.

    Type Parameters

    K
    extends keyof { … }

    Parameters

    keyK & (
    | "id"
    | "rootId"
    | "pageIndex"
    | "pdfObjectId"
    | "creatorName"
    | "createdBy"
    | "createdAt"
    | "updatedAt"
    | "text"
    | "customData"
    | "group"
    | "isEditable"
    | "isDeletable"
    | "canSetGroup"
    )

    One of the keys this record was defined with.

    Returns

    this

    A new record, or this one when the value already equals the default.

  • Returns a record with the value at keyPath removed. A field of this record is reset to its default; a key of a nested collection or plain object is deleted.

    Parameters

    keyPathIterable<unknown>

    The keys to follow, outermost first.

    Returns

    this

    A new record, or this one when nothing was removed.

equals

Deprecated
  • Reports whether other is a record holding the same keys with equal values, whatever its class.

    Parameters

    otherunknown

    The value to compare against.

    Returns

    boolean

    true when both hold the same keys and every value matches.

    Deprecated

    Records of different classes with identical values compare equal. Use isEqual(), which also requires both records to be of the same class.

  • Returns the value stored under key.

    Type Parameters

    K
    extends keyof { … }
    N = never

    Parameters

    keyK & (
    | "id"
    | "rootId"
    | "pageIndex"
    | "pdfObjectId"
    | "creatorName"
    | "createdBy"
    | "createdAt"
    | "updatedAt"
    | "text"
    | "customData"
    | "group"
    | "isEditable"
    | "isDeletable"
    | "canSetGroup"
    )

    One of the keys this record was defined with.

    notSetValueN
    Optional

    Returned when the record does not define key.

    Returns

    N | { … }[K]

    The current value for that key.

  • Returns the value at keyPath, walking nested records and collections.

    A literal key path is checked against the record's fields and gives the value's type; a computed one gives unknown.

    Parameters

    keyPathIterable<unknown>

    The keys to follow, outermost first.

    Returns

    unknown

    The value at that path, or undefined when it does not resolve.

  • Returns the value at keyPath, walking nested records and collections.

    A literal key path is checked against the record's fields and gives the value's type; a computed one gives unknown.

    Type Parameters

    N

    Parameters

    keyPathIterable<unknown>

    The keys to follow, outermost first.

    notSetValueN

    Returned when the path does not resolve.

    Returns

    unknown

    The value at that path, or notSetValue.

  • Reports whether key is one of the keys this record was defined with.

    A literal key must name a field; a key typed as string is narrowed to the field names.

    Parameters

    keystring

    The key to look for.

    Returns

    key is
    | "id"
    | "rootId"
    | "pageIndex"
    | "pdfObjectId"
    | "creatorName"
    | "createdBy"
    | "createdAt"
    | "updatedAt"
    | "text"
    | "customData"
    | "group"
    | "isEditable"
    | "isDeletable"
    | "canSetGroup"

    true when the record defines that key, even if its value is null.

  • Computes a hash of this record from its contents, the same way Immutable.js does. Equal records have equal hashes; records with equal hashes are not necessarily equal. Plain objects, functions and symbols hash by identity, so a hash is only meaningful within the page that computed it.

    Returns

    number

    An integer hash.

  • Reports whether keyPath resolves, walking nested records and collections.

    Parameters

    keyPathIterable<unknown>

    The keys to follow, outermost first.

    Returns

    boolean

    true when every key along the path is present.

  • Reports whether other is a record of the same class holding equal values. Only the two records' own classes are compared; nested records compare as equals() does.

    Parameters

    otherunknown

    The value to compare against.

    Returns

    boolean

    true when both are the same class and every value matches.

  • Returns a record with the entries of each collection applied in order.

    Keys the record was not defined with are ignored.

    Parameters

    ...collections
    (Partial<{ … }> | Iterable<readonly [string, unknown]>)[]

    Plain objects or key/value iterables to apply.

    Returns

    this

    A new record, or this one when no value changed.

  • Returns a record with the entries of each collection merged in, recursing into nested collections and plain objects instead of replacing them.

    Keys the record was not defined with are ignored.

    Parameters

    ...collections
    (Partial<{ … }> | Iterable<readonly [string, unknown]>)[]

    Plain objects or key/value iterables to merge in.

    Returns

    this

    A new record, or this one when no value changed.

  • Returns a record with each collection merged deeply into the value at keyPath.

    Parameters

    keyPathIterable<unknown>

    The keys to follow, outermost first.

    ...collectionsunknown[]

    Collections or plain objects to merge into the value there.

    Returns

    this

    A new record, or this one when the value is unchanged.

  • Returns a record with the entries of each collection merged in deeply, calling merger where a nested value is not a collection to decide the value that is kept.

    Keys the record was not defined with are ignored.

    Parameters

    merger(previous: unknown, next: unknown, key: unknown) => unknown

    Receives the current value, the incoming value and the key.

    ...collections
    (Partial<{ … }> | Iterable<readonly [string, unknown]>)[]

    Plain objects or key/value iterables to merge in.

    Returns

    this

    A new record, or this one when no value changed.

  • Returns a record with each collection merged into the value at keyPath, one level at a time.

    Parameters

    keyPathIterable<unknown>

    The keys to follow, outermost first.

    ...collectionsunknown[]

    Collections or plain objects to merge into the value there.

    Returns

    this

    A new record, or this one when the value is unchanged.

  • Returns a record with the entries of each collection merged in, calling merger for each key the record already holds to decide the value that is kept.

    Keys the record was not defined with are ignored.

    Parameters

    merger
    <K extends string | number | symbol>(
    previous: { … }[K],
    next: { … }[K],
    key: K
    ) => { … }[K]

    Receives the current value, the incoming value and the key.

    ...collections
    (Partial<{ … }> | Iterable<readonly [string, unknown]>)[]

    Plain objects or key/value iterables to merge in.

    Returns

    this

    A new record, or this one when no value changed.

  • An alias for delete.

    Type Parameters

    K
    extends keyof { … }

    Parameters

    keyK & (
    | "id"
    | "rootId"
    | "pageIndex"
    | "pdfObjectId"
    | "creatorName"
    | "createdBy"
    | "createdAt"
    | "updatedAt"
    | "text"
    | "customData"
    | "group"
    | "isEditable"
    | "isDeletable"
    | "canSetGroup"
    )

    One of the keys this record was defined with.

    Returns

    this

    A new record, or this one when the value already equals the default.

  • An alias for deleteIn.

    Parameters

    keyPathIterable<unknown>

    The keys to follow, outermost first.

    Returns

    this

    A new record, or this one when nothing was removed.

  • Returns a record with key set to value.

    Setting a key to the value it already holds returns the same instance, so a record can be compared by reference to detect a change.

    Type Parameters

    K
    extends keyof { … }

    Parameters

    keyK & (
    | "id"
    | "rootId"
    | "pageIndex"
    | "pdfObjectId"
    | "creatorName"
    | "createdBy"
    | "createdAt"
    | "updatedAt"
    | "text"
    | "customData"
    | "group"
    | "isEditable"
    | "isDeletable"
    | "canSetGroup"
    )

    One of the keys this record was defined with.

    value
    { … }[K]

    The value to store.

    Returns

    this

    A new record, or this one when the value is unchanged or the key is not defined.

  • Returns a record with value written at keyPath.

    Parameters

    keyPathIterable<unknown>

    The keys to follow, outermost first.

    valueunknown

    The value to store.

    Returns

    this

    A new record, or this one when the value is unchanged.

  • Converts this record and everything nested inside it to plain JavaScript values.

    Returns

    { … }

    A plain object holding this record's values, converted all the way down.

    • id: string | null

      A unique identifier for the comment. When comment is created in the UI, the viewer has to generate a unique ID.

    • rootId: string | null

      The ID of the annotation that this comment stems from. In Nutrient Web SDK, this should be either a NutrientViewer.Annotations.MarkupAnnotation or a NutrientViewer.Annotations.CommentMarkerAnnotation.

    • pageIndex: number | null

      The page index that this comment resides at.

    • pdfObjectId: number | null

      If this comment is from the original PDF, then this ID is from that PDF note annotation that defined the comment.

    • creatorName: string | null

      The name of the person who created the comment.

    • Readonly
      createdBy: string | null

      The ID of the user who created the comment, as determined by the authenticated user (the user_id claim of the JWT) that created it.

      You cannot change who is recorded as the author: the value is assigned by the backend, and a locally set value is never sent. It is only available on Server-Backed deployments, and is null for comments created without an authenticated user, as well as when the server holds an author it can no longer resolve to an upstream user id.

    • createdAt: Date

      The time when the comment was created.

    • updatedAt: Date

      The time when the comment was last updated.

    • text: { format: "plain" | "xhtml"; value: string | null }

      The text of the comment in xhtml/plain text format.

      In case of XHTML, we support the following tags:

      • <b>: Bold
      • <i>: Italic
      • <span>: Font color, background color and underline using the style attribute (e.g. <span style="color: red; background-color: blue; text-decoration: underline">Hello</span>)
      • p: Paragraph. You can use this to add a newline between paragraphs.
      • a: Link. You can use this to add a link to the comment. The href attribute is required.
    • customData: Record<string, unknown> | null

      Arbitrary JSON-serializable data the user can attach to the comment.

    • Optional
      group?: string | null

      This property is used to define the permission scope for a particular comment.

      It is only available when collaboration permissions is enabled on Server-Backed deployments.

    • OptionalReadonly
      isEditable?: boolean

      This property defines whether this comment can be edited or not. The value of this field depends on the set of collaboration permissions defined in the JWT token.

      It is only available when collaboration permissions is enabled on Server-Backed deployments.

    • OptionalReadonly
      isDeletable?: boolean

      This property defines whether this comment can be deleted or not. The value of this field depends on the set of collaboration permissions defined in the JWT token.

      It is only available when collaboration permissions is enabled on Server-Backed deployments.

    • OptionalReadonly
      canSetGroup?: boolean

      This property defines whether the user has permission to edit the group of this comment. The value of this field depends on the set of collaboration permissions defined in the JWT token.

      It is only available when collaboration permissions is enabled on Server-Backed deployments.

  • An alias for toObject, called by JSON.stringify.

    Returns

    { … }

    A plain object holding this record's values.

    • OptionalReadonly
      canSetGroup?: boolean

      This property defines whether the user has permission to edit the group of this comment. The value of this field depends on the set of collaboration permissions defined in the JWT token.

      It is only available when collaboration permissions is enabled on Server-Backed deployments.

    • createdAt: Date

      The time when the comment was created.

    • Readonly
      createdBy: string | null

      The ID of the user who created the comment, as determined by the authenticated user (the user_id claim of the JWT) that created it.

      You cannot change who is recorded as the author: the value is assigned by the backend, and a locally set value is never sent. It is only available on Server-Backed deployments, and is null for comments created without an authenticated user, as well as when the server holds an author it can no longer resolve to an upstream user id.

    • creatorName: string | null

      The name of the person who created the comment.

    • customData: Record<string, unknown> | null

      Arbitrary JSON-serializable data the user can attach to the comment.

    • Optional
      group?: string | null

      This property is used to define the permission scope for a particular comment.

      It is only available when collaboration permissions is enabled on Server-Backed deployments.

    • id: string | null

      A unique identifier for the comment. When comment is created in the UI, the viewer has to generate a unique ID.

    • OptionalReadonly
      isDeletable?: boolean

      This property defines whether this comment can be deleted or not. The value of this field depends on the set of collaboration permissions defined in the JWT token.

      It is only available when collaboration permissions is enabled on Server-Backed deployments.

    • OptionalReadonly
      isEditable?: boolean

      This property defines whether this comment can be edited or not. The value of this field depends on the set of collaboration permissions defined in the JWT token.

      It is only available when collaboration permissions is enabled on Server-Backed deployments.

    • pageIndex: number | null

      The page index that this comment resides at.

    • pdfObjectId: number | null

      If this comment is from the original PDF, then this ID is from that PDF note annotation that defined the comment.

    • rootId: string | null

      The ID of the annotation that this comment stems from. In Nutrient Web SDK, this should be either a NutrientViewer.Annotations.MarkupAnnotation or a NutrientViewer.Annotations.CommentMarkerAnnotation.

    • text: { format: "plain" | "xhtml"; value: string | null }

      The text of the comment in xhtml/plain text format.

      In case of XHTML, we support the following tags:

      • <b>: Bold
      • <i>: Italic
      • <span>: Font color, background color and underline using the style attribute (e.g. <span style="color: red; background-color: blue; text-decoration: underline">Hello</span>)
      • p: Paragraph. You can use this to add a newline between paragraphs.
      • a: Link. You can use this to add a link to the comment. The href attribute is required.
    • updatedAt: Date

      The time when the comment was last updated.

  • Converts this record to a plain object, one level deep. Nested records are left as they are.

    Returns

    { … }

    A plain object holding this record's values.

    • OptionalReadonly
      canSetGroup?: boolean

      This property defines whether the user has permission to edit the group of this comment. The value of this field depends on the set of collaboration permissions defined in the JWT token.

      It is only available when collaboration permissions is enabled on Server-Backed deployments.

    • createdAt: Date

      The time when the comment was created.

    • Readonly
      createdBy: string | null

      The ID of the user who created the comment, as determined by the authenticated user (the user_id claim of the JWT) that created it.

      You cannot change who is recorded as the author: the value is assigned by the backend, and a locally set value is never sent. It is only available on Server-Backed deployments, and is null for comments created without an authenticated user, as well as when the server holds an author it can no longer resolve to an upstream user id.

    • creatorName: string | null

      The name of the person who created the comment.

    • customData: Record<string, unknown> | null

      Arbitrary JSON-serializable data the user can attach to the comment.

    • Optional
      group?: string | null

      This property is used to define the permission scope for a particular comment.

      It is only available when collaboration permissions is enabled on Server-Backed deployments.

    • id: string | null

      A unique identifier for the comment. When comment is created in the UI, the viewer has to generate a unique ID.

    • OptionalReadonly
      isDeletable?: boolean

      This property defines whether this comment can be deleted or not. The value of this field depends on the set of collaboration permissions defined in the JWT token.

      It is only available when collaboration permissions is enabled on Server-Backed deployments.

    • OptionalReadonly
      isEditable?: boolean

      This property defines whether this comment can be edited or not. The value of this field depends on the set of collaboration permissions defined in the JWT token.

      It is only available when collaboration permissions is enabled on Server-Backed deployments.

    • pageIndex: number | null

      The page index that this comment resides at.

    • pdfObjectId: number | null

      If this comment is from the original PDF, then this ID is from that PDF note annotation that defined the comment.

    • rootId: string | null

      The ID of the annotation that this comment stems from. In Nutrient Web SDK, this should be either a NutrientViewer.Annotations.MarkupAnnotation or a NutrientViewer.Annotations.CommentMarkerAnnotation.

    • text: { format: "plain" | "xhtml"; value: string | null }

      The text of the comment in xhtml/plain text format.

      In case of XHTML, we support the following tags:

      • <b>: Bold
      • <i>: Italic
      • <span>: Font color, background color and underline using the style attribute (e.g. <span style="color: red; background-color: blue; text-decoration: underline">Hello</span>)
      • p: Paragraph. You can use this to add a newline between paragraphs.
      • a: Link. You can use this to add a link to the comment. The href attribute is required.
    • updatedAt: Date

      The time when the comment was last updated.

  • Returns a record with key replaced by the result of applying updater to its current value.

    Type Parameters

    K
    extends keyof { … }

    Parameters

    keyK & (
    | "id"
    | "rootId"
    | "pageIndex"
    | "pdfObjectId"
    | "creatorName"
    | "createdBy"
    | "createdAt"
    | "updatedAt"
    | "text"
    | "customData"
    | "group"
    | "isEditable"
    | "isDeletable"
    | "canSetGroup"
    )

    One of the keys this record was defined with.

    updater
    (value: { … }[K]) => { … }[K]

    Receives the current value and returns the new one.

    Returns

    this

    A new record, or this one when the value is unchanged.

  • Returns a record with the value at keyPath replaced by the result of updater.

    Type Parameters

    N

    Parameters

    keyPathIterable<unknown>

    The keys to follow, outermost first.

    notSetValueN
    updater(value: unknown) => unknown

    Receives the current value and returns the new one.

    Returns

    this

    A new record, or this one when the value is unchanged.

  • Returns a record with the value at keyPath replaced by the result of updater.

    Parameters

    keyPathIterable<unknown>

    The keys to follow, outermost first.

    updater(value: unknown) => unknown

    Receives the current value and returns the new one.

    Returns

    this

    A new record, or this one when the value is unchanged.

  • Applies several changes as one, so only a single new record is allocated.

    The record handed to mutator may be written to with set; it is frozen again once mutator returns.

    Parameters

    mutator(mutable: this) => unknown

    Receives a temporarily writable copy of this record.

    Returns

    this

    A new record holding the applied changes, or this one when nothing changed.