# pie-api-author

A Custom Element that integrates with `pie-api` to load, render and save content items.

## Creating a new Content Item

To create a new content item, create a `contentConfig` object and set it as a property on the element.

In the `contentConfig` property you can specify the `pie` interactions to use as shown in this example:

```html
<pie-api-author id="author"></pie-api-author>
<script>
      const author = document.getElementById('author');

      author.addEventListener('modelUpdated', event => {
        // hadndle update, e.g
        author.save().then((itemId, version) => {
          // handle
        });
      });

      author.contentConfig = {
        id: "1",
        elements: {"pie-multiple-choice": "@pie-element/multiple-choice@latest"},
        models: [
          { 
            id: "1",
            element: "pie-multiple-choice",
          }],
        markup: "<pie-multiple-choice id='1'></pie-multiple-choice>"
      };
</script>
```

<!-- Auto Generated Below -->


## Properties

| Property               | Attribute                | Description                                                                                                                                                                                                                                                                                                                                  | Type                                   | Default     |
| ---------------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------- | ----------- |
| `addPreview`           | `add-preview`            | Adds a preview view which will render the content in another tab as it may appear to a student or instructor.                                                                                                                                                                                                                                | `boolean`                              | `false`     |
| `collectionId`         | `collection-id`          | Optional. The unique identifier for the Collection in which the content item will be stored in the PIE Service CMS.                                                                                                                                                                                                                          | `string`                               | `undefined` |
| `configSettings`       | --                       | To customize the standard behaviour provided by interaction configuration views you can provide settings key-ed by the package name.  e.g.  `{ '@pie-element/inline-choice': { promptLabel: 'Item Stem' } }`  The settings that are configurable for each authoring view are documented in the `@package-name/docs` folder for each package. | `{ [packageName: string]: Object; }`   | `undefined` |
| `contentConfig`        | --                       | The model for the content. If set, the view will update to render the provided config.                                                                                                                                                                                                                                                       | `PieContent`                           | `undefined` |
| `contentId`            | `content-id`             | The unique versioned identifier `id@semver-version` for the Pie Content Item stored in the PIE Service CMS.                                                                                                                                                                                                                                  | `string`                               | `undefined` |
| `exceptions`           | `exceptions`             | Enable exception tracking.                                                                                                                                                                                                                                                                                                                   | `boolean`                              | `true`      |
| `host`                 | `host`                   | Choose 'dev' , 'stage' or 'prod' environments for back end.                                                                                                                                                                                                                                                                                  | `"dev" \| "prod" \| "qa" \| "stage"`   | `"prod"`    |
| `lockVersions`         | `lock-versions`          | If true, the `@version` tag for elements in the configuration will be ignored and a static version for that interaction type determined by the current release of this pie-api-author component will be used.                                                                                                                                | `boolean`                              | `true`      |
| `overrides`            | `overrides`              | Override element versions. Requires the 'overrides' scope in the token in pie-api matches the key against the element names and if matching uses the overridden version if a string it's parsed as a json string                                                                                                                             | `string \| { [key: string]: string; }` | `undefined` |
| `recordScreen`         | `record-screen`          | Enable screen recording with logrocket. Note: not to be used in production unless for temporary use to track down a specific user problem.                                                                                                                                                                                                   | `boolean`                              | `false`     |
| `recordScreenIdentity` | `record-screen-identity` | If screen recording enabled for debug purposes, use this property to provide a unique identifer for the user whose session is being recorded.                                                                                                                                                                                                | `string`                               | `undefined` |
| `token`                | `token`                  | The api token for `pie-api` access.                                                                                                                                                                                                                                                                                                          | `string`                               | `undefined` |


## Events

| Event                | Description                                                                                                                                                                                                                                            | Type               |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ |
| `contentIdValidated` | When the `contentId` property is set, it will be parsed to ensure it is a valid identifier and to determine if the version is released or pre-release.  the `event.detail` value will be `{valid: true \| false, status: 'released' \| 'pre-release'}` | `CustomEvent<any>` |
| `contentLoaded`      | Content has been loaded from server                                                                                                                                                                                                                    | `CustomEvent<any>` |
| `recordingStarted`   | If `recordScreen` property is set to true this event will be emitted with the url for recorded screen session in `detail` property.                                                                                                                    | `CustomEvent<any>` |


## Methods

### `addRubricToConfig(config: ItemConfig, rubricModel?: any) => Promise<ItemConfig>`

<span style="color:red">**[DEPRECATED]**</span> this method is for temporary use, will be removed at next major release<br/><br/>Utility method to add a `@pie-element/rubric` section to an item config when creating an item should be used before setting the config.

#### Returns

Type: `Promise<ItemConfig>`



### `create(preReleaseType?: string) => Promise<string>`

Creates a new content item from the currently loaded contents.

#### Returns

Type: `Promise<string>`



### `getVersions() => Promise<string[]>`

TODO
Gets a list of all versions that exist for this Content Item.

#### Returns

Type: `Promise<string[]>`



### `load(contentId?: any) => Promise<void>`

Loads a content item from `pie-api` host into the view.

#### Returns

Type: `Promise<void>`



### `release() => Promise<string>`

Release a pre-release version of the content currently loaded in the authoring view.

Throws an exception if the version of the current Content Item does not have a pre-release tag e.g.`1.0.1-draft`

  example:
(`contentId = 'abc@1.0.1-draft`)

  `this.release() => 'abc@1.0.1`'

#### Returns

Type: `Promise<string>`



### `save(preReleaseType?: PreReleaseType) => Promise<string>`

Saves an update to an existing pre-released content item.
The content item version must be in pre-release state.

the `preReleaseType` param determines what kind of version update, if any, will be performed.

`null` - (default) writes over existing pre-release content, , e.g.`1.0.0-draft.0 -> 1.0.0-draft.0`\n
`prerelease` - writes in increment to the prerelease version, e.g. `1.0.0-draft.0 -> 1.0.0-draft.1`\n
`premajor` - creates a new major release from version, e.g. `1.0.0-draft.1 -> 2.0.0-draft.0`\n
`preminor` - creates a new minor release from version, e.g. `1.0.0-draft.1 -> 1.1.0-draft.0`\n
`prepatch` - creates a new patch release from version, e.g. `1.0.0-draft.1 -> 1.0.1-draft.0`\m

#### Returns

Type: `Promise<string>`



### `version() => Promise<string>`



#### Returns

Type: `Promise<string>`




## Dependencies

### Depends on

- pie-author

### Graph
```mermaid
graph TD;
  pie-api-author --> pie-author
  pie-author --> pie-preview-layout
  pie-author --> pie-spinner
  pie-preview-layout --> pie-preview-control
  pie-preview-layout --> pie-player
  pie-player --> pie-stimulus-layout
  pie-player --> pie-player
  pie-player --> pie-spinner
  style pie-api-author fill:#f9f,stroke:#333,stroke-width:4px
```

----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
