H5P NodeJS Library
    Preparing search index...

    Hierarchy

    • HTMLElement
      • H5PEditorComponent
    Index

    Constructors

    Properties

    saveContentCallback: (
        contentId: string,
        requestBody: { library: string; params: any },
    ) => Promise<{ contentId: string; metadata: IContentMetadata }>

    Called when the component needs to save data about content. The endpoint called here should call H5PEditor.saveOrUpdateContentReturnMetaData(...). Note that it makes sense to use PATCH requests for updates and POST requests for new content, but it's up to you how you implement this. See defaultSaveContentCallback for an example.

    Should throw an error with a message in the message property if something goes wrong.

    Type declaration

      • (
            contentId: string,
            requestBody: { library: string; params: any },
        ): Promise<{ contentId: string; metadata: IContentMetadata }>
      • Parameters

        • contentId: string

          the contentId which needs to be saved; can be undefined for new content, which hasn't been saved before

        • requestBody: { library: string; params: any }

          the data needed by the server; usually encoded as JSON string and sent to the server

        Returns Promise<{ contentId: string; metadata: IContentMetadata }>

        the newly assigned content id and metadata

    Accessors

    • get contentId(): string

      Returns string

    • set contentId(contentId: string): void

      Parameters

      • contentId: string

      Returns void

    • get loadContentCallback(): (
          contentId: string,
      ) => Promise<
          IEditorModel & {
              library?: string;
              metadata?: IContentMetadata;
              params?: any;
          },
      >

      Called when the component needs to load data about content. The endpoint called in here combines the results of H5PEditor.render(...) and H5PEditor.getContent(...) to avoid too many requests.

      Note that the library, metadata and params property of the returned object must only be defined if contentId is defined.

      Should throw an error with a message in the message property if something goes wrong.

      Returns (
          contentId: string,
      ) => Promise<
          IEditorModel & {
              library?: string;
              metadata?: IContentMetadata;
              params?: any;
          },
      >

    • set loadContentCallback(
          callback: (
              contentId: string,
          ) => Promise<
              IEditorModel & {
                  library?: string;
                  metadata?: IContentMetadata;
                  params?: any;
              },
          >,
      ): void

      Parameters

      • callback: (
            contentId: string,
        ) => Promise<
            IEditorModel & {
                library?: string;
                metadata?: IContentMetadata;
                params?: any;
            },
        >

      Returns void

    • get observedAttributes(): string[]

      Indicates changes to which attributes should trigger calls to attributeChangedCallback.

      Returns string[]

    Methods

    • Called when one of the attributes in observedAttributes changes.

      Parameters

      • name: string
      • oldVal: any
      • newVal: any

      Returns Promise<void>

    • Called when the component is added to the DOM.

      Returns Promise<void>

    • Called when the component is removed from the DOM.

      Returns void

    • Call this method when the iframe containing the editor needs to be resized, e.g. because the some

      Returns void

    • Call save() to get data from the H5P editor and send it to the server. You can use the saveContentCallback hook to customize server requests. The component emits 'saved', 'save-error' and 'validation-error' events, depending on success of the function. You can subscribe to those or use the promise's return value and catch the errors in a try-catch block.

      Returns Promise<{ contentId: string; metadata: IContentMetadata }>

      the contentId and metadata of the saved content

      an error if something went wrong